| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Copyright (C) 2008 Mauro Carvalho Chehab |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation, version 2 of the License. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# FIXME: need to properly map 32 bites aligned read/writes also. |
| 15 |
# |
| 16 |
|
| 17 |
use strict; |
| 18 |
|
| 19 |
my $debug = 0; |
| 20 |
|
| 21 |
my %reg_map = ( |
| 22 |
0x101 => "SAA7134_INCR_DELAY", |
| 23 |
0x102 => "SAA7134_ANALOG_IN_CTRL1", |
| 24 |
0x103 => "SAA7134_ANALOG_IN_CTRL2", |
| 25 |
0x104 => "SAA7134_ANALOG_IN_CTRL3", |
| 26 |
0x105 => "SAA7134_ANALOG_IN_CTRL4", |
| 27 |
0x106 => "SAA7134_HSYNC_START", |
| 28 |
0x107 => "SAA7134_HSYNC_STOP", |
| 29 |
0x108 => "SAA7134_SYNC_CTRL", |
| 30 |
0x109 => "SAA7134_LUMA_CTRL", |
| 31 |
0x10a => "SAA7134_DEC_LUMA_BRIGHT", |
| 32 |
0x10b => "SAA7134_DEC_LUMA_CONTRAST", |
| 33 |
0x10c => "SAA7134_DEC_CHROMA_SATURATION", |
| 34 |
0x10d => "SAA7134_DEC_CHROMA_HUE", |
| 35 |
0x10e => "SAA7134_CHROMA_CTRL1", |
| 36 |
0x10f => "SAA7134_CHROMA_GAIN", |
| 37 |
0x110 => "SAA7134_CHROMA_CTRL2", |
| 38 |
0x111 => "SAA7134_MODE_DELAY_CTRL", |
| 39 |
0x114 => "SAA7134_ANALOG_ADC", |
| 40 |
0x115 => "SAA7134_VGATE_START", |
| 41 |
0x116 => "SAA7134_VGATE_STOP", |
| 42 |
0x117 => "SAA7134_MISC_VGATE_MSB", |
| 43 |
0x118 => "SAA7134_RAW_DATA_GAIN", |
| 44 |
0x119 => "SAA7134_RAW_DATA_OFFSET", |
| 45 |
0x11e => "SAA7134_STATUS_VIDEO1", |
| 46 |
0x11f => "SAA7134_STATUS_VIDEO2", |
| 47 |
0x300 => "SAA7134_OFMT_VIDEO_A", |
| 48 |
0x301 => "SAA7134_OFMT_DATA_A", |
| 49 |
0x302 => "SAA7134_OFMT_VIDEO_B", |
| 50 |
0x303 => "SAA7134_OFMT_DATA_B", |
| 51 |
0x304 => "SAA7134_ALPHA_NOCLIP", |
| 52 |
0x305 => "SAA7134_ALPHA_CLIP", |
| 53 |
0x308 => "SAA7134_UV_PIXEL", |
| 54 |
0x309 => "SAA7134_CLIP_RED", |
| 55 |
0x30a => "SAA7134_CLIP_GREEN", |
| 56 |
0x30b => "SAA7134_CLIP_BLUE", |
| 57 |
0x180 => "SAA7134_I2C_ATTR_STATUS", |
| 58 |
0x181 => "SAA7134_I2C_DATA", |
| 59 |
0x182 => "SAA7134_I2C_CLOCK_SELECT", |
| 60 |
0x183 => "SAA7134_I2C_TIMER", |
| 61 |
0x140 => "SAA7134_NICAM_ADD_DATA1", |
| 62 |
0x141 => "SAA7134_NICAM_ADD_DATA2", |
| 63 |
0x142 => "SAA7134_NICAM_STATUS", |
| 64 |
0x143 => "SAA7134_AUDIO_STATUS", |
| 65 |
0x144 => "SAA7134_NICAM_ERROR_COUNT", |
| 66 |
0x145 => "SAA7134_IDENT_SIF", |
| 67 |
0x146 => "SAA7134_LEVEL_READOUT1", |
| 68 |
0x147 => "SAA7134_LEVEL_READOUT2", |
| 69 |
0x148 => "SAA7134_NICAM_ERROR_LOW", |
| 70 |
0x149 => "SAA7134_NICAM_ERROR_HIGH", |
| 71 |
0x14a => "SAA7134_DCXO_IDENT_CTRL", |
| 72 |
0x14b => "SAA7134_DEMODULATOR", |
| 73 |
0x14c => "SAA7134_AGC_GAIN_SELECT", |
| 74 |
0x150 => "SAA7134_CARRIER1_FREQ0", |
| 75 |
0x151 => "SAA7134_CARRIER1_FREQ1", |
| 76 |
0x152 => "SAA7134_CARRIER1_FREQ2", |
| 77 |
0x154 => "SAA7134_CARRIER2_FREQ0", |
| 78 |
0x155 => "SAA7134_CARRIER2_FREQ1", |
| 79 |
0x156 => "SAA7134_CARRIER2_FREQ2", |
| 80 |
0x158 => "SAA7134_NUM_SAMPLES0", |
| 81 |
0x159 => "SAA7134_NUM_SAMPLES1", |
| 82 |
0x15a => "SAA7134_NUM_SAMPLES2", |
| 83 |
0x15b => "SAA7134_AUDIO_FORMAT_CTRL", |
| 84 |
0x160 => "SAA7134_MONITOR_SELECT", |
| 85 |
0x161 => "SAA7134_FM_DEEMPHASIS", |
| 86 |
0x162 => "SAA7134_FM_DEMATRIX", |
| 87 |
0x163 => "SAA7134_CHANNEL1_LEVEL", |
| 88 |
0x164 => "SAA7134_CHANNEL2_LEVEL", |
| 89 |
0x165 => "SAA7134_NICAM_CONFIG", |
| 90 |
0x166 => "SAA7134_NICAM_LEVEL_ADJUST", |
| 91 |
0x167 => "SAA7134_STEREO_DAC_OUTPUT_SELECT", |
| 92 |
0x168 => "SAA7134_I2S_OUTPUT_FORMAT", |
| 93 |
0x169 => "SAA7134_I2S_OUTPUT_SELECT", |
| 94 |
0x16a => "SAA7134_I2S_OUTPUT_LEVEL", |
| 95 |
0x16b => "SAA7134_DSP_OUTPUT_SELECT", |
| 96 |
0x16c => "SAA7134_AUDIO_MUTE_CTRL", |
| 97 |
0x16d => "SAA7134_SIF_SAMPLE_FREQ", |
| 98 |
0x16e => "SAA7134_ANALOG_IO_SELECT", |
| 99 |
0x170 => "SAA7134_AUDIO_CLOCK0", |
| 100 |
0x171 => "SAA7134_AUDIO_CLOCK1", |
| 101 |
0x172 => "SAA7134_AUDIO_CLOCK2", |
| 102 |
0x173 => "SAA7134_AUDIO_PLL_CTRL", |
| 103 |
0x174 => "SAA7134_AUDIO_CLOCKS_PER_FIELD0", |
| 104 |
0x175 => "SAA7134_AUDIO_CLOCKS_PER_FIELD1", |
| 105 |
0x176 => "SAA7134_AUDIO_CLOCKS_PER_FIELD2", |
| 106 |
0x190 => "SAA7134_VIDEO_PORT_CTRL0", |
| 107 |
0x191 => "SAA7134_VIDEO_PORT_CTRL1", |
| 108 |
0x192 => "SAA7134_VIDEO_PORT_CTRL2", |
| 109 |
0x193 => "SAA7134_VIDEO_PORT_CTRL3", |
| 110 |
0x194 => "SAA7134_VIDEO_PORT_CTRL4", |
| 111 |
0x195 => "SAA7134_VIDEO_PORT_CTRL5", |
| 112 |
0x196 => "SAA7134_VIDEO_PORT_CTRL6", |
| 113 |
0x197 => "SAA7134_VIDEO_PORT_CTRL7", |
| 114 |
0x198 => "SAA7134_VIDEO_PORT_CTRL8", |
| 115 |
0x1a0 => "SAA7134_TS_PARALLEL", |
| 116 |
0x1a1 => "SAA7134_TS_PARALLEL_SERIAL", |
| 117 |
0x1a2 => "SAA7134_TS_SERIAL0", |
| 118 |
0x1a3 => "SAA7134_TS_SERIAL1", |
| 119 |
0x1a4 => "SAA7134_TS_DMA0", |
| 120 |
0x1a5 => "SAA7134_TS_DMA1", |
| 121 |
0x1a6 => "SAA7134_TS_DMA2", |
| 122 |
0x1B0 => "SAA7134_GPIO_GPMODE0", |
| 123 |
0x1B1 => "SAA7134_GPIO_GPMODE1", |
| 124 |
0x1B2 => "SAA7134_GPIO_GPMODE2", |
| 125 |
0x1B3 => "SAA7134_GPIO_GPMODE3", |
| 126 |
0x1B4 => "SAA7134_GPIO_GPSTATUS0", |
| 127 |
0x1B5 => "SAA7134_GPIO_GPSTATUS1", |
| 128 |
0x1B6 => "SAA7134_GPIO_GPSTATUS2", |
| 129 |
0x1B7 => "SAA7134_GPIO_GPSTATUS3", |
| 130 |
0x1c0 => "SAA7134_I2S_AUDIO_OUTPUT", |
| 131 |
0x1d0 => "SAA7134_SPECIAL_MODE", |
| 132 |
0x1d1 => "SAA7134_PRODUCTION_TEST_MODE", |
| 133 |
0x580 => "SAA7135_DSP_RWSTATE", |
| 134 |
0x586 => "SAA7135_DSP_RWCLEAR", |
| 135 |
0x591 => "SAA7133_I2S_AUDIO_CONTROL", |
| 136 |
); |
| 137 |
|
| 138 |
my %i2c_status = ( |
| 139 |
0 => "IDLE", |
| 140 |
1 => "DONE_STOP", |
| 141 |
2 => "BUSY", |
| 142 |
3 => "TO_SCL", |
| 143 |
4 => "TO_ARB", |
| 144 |
5 => "DONE_WRITE", |
| 145 |
6 => "DONE_READ", |
| 146 |
7 => "DONE_WRITE_TO", |
| 147 |
8 => "DONE_READ_TO", |
| 148 |
9 => "NO_DEVICE", |
| 149 |
10 => "NO_ACKN", |
| 150 |
11 => "BUS_ERR", |
| 151 |
12 => "ARB_LOST", |
| 152 |
13 => "SEQ_ERR", |
| 153 |
14 => "ST_ERR", |
| 154 |
15 => "SW_ERR", |
| 155 |
); |
| 156 |
|
| 157 |
my %i2c_attr = ( |
| 158 |
0 => "NOP", |
| 159 |
1 => "STOP", |
| 160 |
2 => "CONTINUE", |
| 161 |
3 => "START", |
| 162 |
); |
| 163 |
|
| 164 |
my $addr = -1; |
| 165 |
my $write = 0; |
| 166 |
my $direction; |
| 167 |
my @buf; |
| 168 |
|
| 169 |
sub flush_i2c_transaction($$) |
| 170 |
{ |
| 171 |
my $direction = shift; |
| 172 |
my $is_complete = shift; |
| 173 |
|
| 174 |
my $size = scalar(@buf); |
| 175 |
|
| 176 |
if ($direction == 0) { |
| 177 |
my $v = shift @buf; |
| 178 |
printf("write_i2c_addr(0x%02x, %d, { 0x%02x", |
| 179 |
$addr, $size, $v); |
| 180 |
while (scalar(@buf)) { |
| 181 |
my $v = shift @buf; |
| 182 |
printf(", 0x%02x", $v); |
| 183 |
} |
| 184 |
printf("});"); |
| 185 |
} else { |
| 186 |
my $size = scalar(@buf); |
| 187 |
my $v = shift @buf; |
| 188 |
printf("read_i2c_addr(0x%02x, %d) /* 0x%02x", |
| 189 |
$addr, $size, $v); |
| 190 |
while (scalar(@buf)) { |
| 191 |
my $v = shift @buf; |
| 192 |
printf(", 0x%02x", $v); |
| 193 |
} |
| 194 |
printf(" */;"); |
| 195 |
} |
| 196 |
@buf = (); |
| 197 |
$addr = -1; |
| 198 |
|
| 199 |
printf (" /* INCOMPLETE */") if (!$is_complete); |
| 200 |
printf "\n"; |
| 201 |
} |
| 202 |
sub parse_i2c($$$$$) |
| 203 |
{ |
| 204 |
my $time = shift; |
| 205 |
my $optype = shift; |
| 206 |
my $align = shift; |
| 207 |
my $reg = shift; |
| 208 |
my $val = shift; |
| 209 |
my $discard = 0; |
| 210 |
|
| 211 |
if ($align ne 'l') { |
| 212 |
print("FIXME: currently, parser work only with 32 bits i2c reg $optype\n"); |
| 213 |
return; |
| 214 |
} |
| 215 |
|
| 216 |
my $status = $i2c_status{$val & 0x0f}; |
| 217 |
my $attr = $i2c_attr{($val >> 6) & 0x03}; |
| 218 |
|
| 219 |
# Avoid poluting the logs with busy msgs |
| 220 |
$discard = 1 if ($status eq "BUSY" | $status eq "TO_SCL" | $status eq "TO_ARB"); |
| 221 |
|
| 222 |
# Avoid poluting the logs with read msgs during write |
| 223 |
$discard = 1 if ($optype eq "read" && $status eq "DONE_WRITE"); |
| 224 |
|
| 225 |
# Avoid poluting the logs with NOP operations |
| 226 |
$discard = 1 if ($attr eq "NOP"); |
| 227 |
|
| 228 |
# Prints I2C raw transaction |
| 229 |
if ($debug >= 1) { |
| 230 |
return if ($debug == 1 && $discard); |
| 231 |
if ($optype eq "write") { |
| 232 |
printf("write_i2c(%s, %s, 0x%02x)\t/* %s */\n", $status, $attr, $val >> 8, $time); |
| 233 |
} else { |
| 234 |
printf("val = read_i2c()\t/* %s: read %s, %s, val=0x%02x */\n", $time, $status, $attr, $val >> 8); |
| 235 |
} |
| 236 |
} |
| 237 |
return if ($discard); |
| 238 |
$val >>= 8; |
| 239 |
|
| 240 |
if (($attr eq "START") && ($optype eq "write")) { |
| 241 |
flush_i2c_transaction(0, 0) if (scalar(@buf) && $addr >= 0); |
| 242 |
|
| 243 |
$direction = $val & 1; |
| 244 |
$addr = $val >> 1; |
| 245 |
} |
| 246 |
# Prints I2C transaction. This state machine is not 100% |
| 247 |
# it is known to fail with eeprom access |
| 248 |
if (($direction == 0) && ($optype eq "write")) { |
| 249 |
if ($attr eq "CONTINUE") { |
| 250 |
# Discard transactions on the wrong direction |
| 251 |
push @buf, $val; |
| 252 |
} elsif ($attr eq "STOP" && $addr >= 0) { |
| 253 |
flush_i2c_transaction(0, 1); |
| 254 |
} |
| 255 |
} elsif ($direction == 1) { |
| 256 |
if ($optype eq "write") { |
| 257 |
$write = 1; |
| 258 |
return; |
| 259 |
} |
| 260 |
return if (!$write); |
| 261 |
$write = 0; |
| 262 |
|
| 263 |
if ($attr eq "CONTINUE") { |
| 264 |
push @buf, $val; |
| 265 |
} elsif ($attr eq "STOP" && $addr >= 0) { |
| 266 |
flush_i2c_transaction(1, 1); |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
while (<>) { |
| 272 |
# 1286074716 slow_bar_read.: slow_bar_readl addr=0x0000000000000180 val=0x00008182 |
| 273 |
if (m/^(\d+)\s+slow_bar_(read|write)(.).*addr=([^\s]+)\s+val=([^\s]+)/) { |
| 274 |
my $time = $1; |
| 275 |
my $optype = $2; |
| 276 |
my $align = $3; |
| 277 |
my $op = "$2$3"; |
| 278 |
my $reg = hex($4); |
| 279 |
my $val = hex($5); |
| 280 |
if (defined($reg_map{$reg})) { |
| 281 |
$reg = $reg_map{$reg}; |
| 282 |
} else { |
| 283 |
$reg = sprintf("0x%04x", $reg); |
| 284 |
} |
| 285 |
if ($reg =~ m/SAA7134_I2C_ATTR_STATUS/) { |
| 286 |
parse_i2c($time, $optype, $align, $reg, $val); |
| 287 |
} elsif ($optype eq "read") { |
| 288 |
printf ("reg = saa_%s(%s); /* %s: read 0x%04x */\n", $op, $reg, $time, $val); |
| 289 |
} else { |
| 290 |
printf ("saa_%s(%s, 0x%04x); /* %s */\n", $op, $reg, $val, $time); |
| 291 |
} |
| 292 |
} |
| 293 |
} |