aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/saa7134/parse_saa7134.pl
blob: 58002a4b5768ebfe737dcdf40f6a94c609a1c506 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/perl

#   Copyright (C) 2008 Mauro Carvalho Chehab <mchehab@redhat.com>
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, version 2 of the License.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
# FIXME: need to properly map 32 bites aligned read/writes also.
#

use strict;

my $debug = 0;

my %reg_map = (
	0x101 => "SAA7134_INCR_DELAY",
	0x102 => "SAA7134_ANALOG_IN_CTRL1",
	0x103 => "SAA7134_ANALOG_IN_CTRL2",
	0x104 => "SAA7134_ANALOG_IN_CTRL3",
	0x105 => "SAA7134_ANALOG_IN_CTRL4",
	0x106 => "SAA7134_HSYNC_START",
	0x107 => "SAA7134_HSYNC_STOP",
	0x108 => "SAA7134_SYNC_CTRL",
	0x109 => "SAA7134_LUMA_CTRL",
	0x10a => "SAA7134_DEC_LUMA_BRIGHT",
	0x10b => "SAA7134_DEC_LUMA_CONTRAST",
	0x10c => "SAA7134_DEC_CHROMA_SATURATION",
	0x10d => "SAA7134_DEC_CHROMA_HUE",
	0x10e => "SAA7134_CHROMA_CTRL1",
	0x10f => "SAA7134_CHROMA_GAIN",
	0x110 => "SAA7134_CHROMA_CTRL2",
	0x111 => "SAA7134_MODE_DELAY_CTRL",
	0x114 => "SAA7134_ANALOG_ADC",
	0x115 => "SAA7134_VGATE_START",
	0x116 => "SAA7134_VGATE_STOP",
	0x117 => "SAA7134_MISC_VGATE_MSB",
	0x118 => "SAA7134_RAW_DATA_GAIN",
	0x119 => "SAA7134_RAW_DATA_OFFSET",
	0x11e => "SAA7134_STATUS_VIDEO1",
	0x11f => "SAA7134_STATUS_VIDEO2",
	0x300 => "SAA7134_OFMT_VIDEO_A",
	0x301 => "SAA7134_OFMT_DATA_A",
	0x302 => "SAA7134_OFMT_VIDEO_B",
	0x303 => "SAA7134_OFMT_DATA_B",
	0x304 => "SAA7134_ALPHA_NOCLIP",
	0x305 => "SAA7134_ALPHA_CLIP",
	0x308 => "SAA7134_UV_PIXEL",
	0x309 => "SAA7134_CLIP_RED",
	0x30a => "SAA7134_CLIP_GREEN",
	0x30b => "SAA7134_CLIP_BLUE",
	0x180 => "SAA7134_I2C_ATTR_STATUS",
	0x181 => "SAA7134_I2C_DATA",
	0x182 => "SAA7134_I2C_CLOCK_SELECT",
	0x183 => "SAA7134_I2C_TIMER",
	0x140 => "SAA7134_NICAM_ADD_DATA1",
	0x141 => "SAA7134_NICAM_ADD_DATA2",
	0x142 => "SAA7134_NICAM_STATUS",
	0x143 => "SAA7134_AUDIO_STATUS",
	0x144 => "SAA7134_NICAM_ERROR_COUNT",
	0x145 => "SAA7134_IDENT_SIF",
	0x146 => "SAA7134_LEVEL_READOUT1",
	0x147 => "SAA7134_LEVEL_READOUT2",
	0x148 => "SAA7134_NICAM_ERROR_LOW",
	0x149 => "SAA7134_NICAM_ERROR_HIGH",
	0x14a => "SAA7134_DCXO_IDENT_CTRL",
	0x14b => "SAA7134_DEMODULATOR",
	0x14c => "SAA7134_AGC_GAIN_SELECT",
	0x150 => "SAA7134_CARRIER1_FREQ0",
	0x151 => "SAA7134_CARRIER1_FREQ1",
	0x152 => "SAA7134_CARRIER1_FREQ2",
	0x154 => "SAA7134_CARRIER2_FREQ0",
	0x155 => "SAA7134_CARRIER2_FREQ1",
	0x156 => "SAA7134_CARRIER2_FREQ2",
	0x158 => "SAA7134_NUM_SAMPLES0",
	0x159 => "SAA7134_NUM_SAMPLES1",
	0x15a => "SAA7134_NUM_SAMPLES2",
	0x15b => "SAA7134_AUDIO_FORMAT_CTRL",
	0x160 => "SAA7134_MONITOR_SELECT",
	0x161 => "SAA7134_FM_DEEMPHASIS",
	0x162 => "SAA7134_FM_DEMATRIX",
	0x163 => "SAA7134_CHANNEL1_LEVEL",
	0x164 => "SAA7134_CHANNEL2_LEVEL",
	0x165 => "SAA7134_NICAM_CONFIG",
	0x166 => "SAA7134_NICAM_LEVEL_ADJUST",
	0x167 => "SAA7134_STEREO_DAC_OUTPUT_SELECT",
	0x168 => "SAA7134_I2S_OUTPUT_FORMAT",
	0x169 => "SAA7134_I2S_OUTPUT_SELECT",
	0x16a => "SAA7134_I2S_OUTPUT_LEVEL",
	0x16b => "SAA7134_DSP_OUTPUT_SELECT",
	0x16c => "SAA7134_AUDIO_MUTE_CTRL",
	0x16d => "SAA7134_SIF_SAMPLE_FREQ",
	0x16e => "SAA7134_ANALOG_IO_SELECT",
	0x170 => "SAA7134_AUDIO_CLOCK0",
	0x171 => "SAA7134_AUDIO_CLOCK1",
	0x172 => "SAA7134_AUDIO_CLOCK2",
	0x173 => "SAA7134_AUDIO_PLL_CTRL",
	0x174 => "SAA7134_AUDIO_CLOCKS_PER_FIELD0",
	0x175 => "SAA7134_AUDIO_CLOCKS_PER_FIELD1",
	0x176 => "SAA7134_AUDIO_CLOCKS_PER_FIELD2",
	0x190 => "SAA7134_VIDEO_PORT_CTRL0",
	0x191 => "SAA7134_VIDEO_PORT_CTRL1",
	0x192 => "SAA7134_VIDEO_PORT_CTRL2",
	0x193 => "SAA7134_VIDEO_PORT_CTRL3",
	0x194 => "SAA7134_VIDEO_PORT_CTRL4",
	0x195 => "SAA7134_VIDEO_PORT_CTRL5",
	0x196 => "SAA7134_VIDEO_PORT_CTRL6",
	0x197 => "SAA7134_VIDEO_PORT_CTRL7",
	0x198 => "SAA7134_VIDEO_PORT_CTRL8",
	0x1a0 => "SAA7134_TS_PARALLEL",
	0x1a1 => "SAA7134_TS_PARALLEL_SERIAL",
	0x1a2 => "SAA7134_TS_SERIAL0",
	0x1a3 => "SAA7134_TS_SERIAL1",
	0x1a4 => "SAA7134_TS_DMA0",
	0x1a5 => "SAA7134_TS_DMA1",
	0x1a6 => "SAA7134_TS_DMA2",
	0x1B0 => "SAA7134_GPIO_GPMODE0",
	0x1B1 => "SAA7134_GPIO_GPMODE1",
	0x1B2 => "SAA7134_GPIO_GPMODE2",
	0x1B3 => "SAA7134_GPIO_GPMODE3",
	0x1B4 => "SAA7134_GPIO_GPSTATUS0",
	0x1B5 => "SAA7134_GPIO_GPSTATUS1",
	0x1B6 => "SAA7134_GPIO_GPSTATUS2",
	0x1B7 => "SAA7134_GPIO_GPSTATUS3",
	0x1c0 => "SAA7134_I2S_AUDIO_OUTPUT",
	0x1d0 => "SAA7134_SPECIAL_MODE",
	0x1d1 => "SAA7134_PRODUCTION_TEST_MODE",
	0x580 => "SAA7135_DSP_RWSTATE",
	0x586 => "SAA7135_DSP_RWCLEAR",
	0x591 => "SAA7133_I2S_AUDIO_CONTROL",
);

my %i2c_status = (
	0  => "IDLE",
	1  => "DONE_STOP",
	2  => "BUSY",
	3  => "TO_SCL",
	4  => "TO_ARB",
	5  => "DONE_WRITE",
	6  => "DONE_READ",
	7  => "DONE_WRITE_TO",
	8  => "DONE_READ_TO",
	9  => "NO_DEVICE",
	10 => "NO_ACKN",
	11 => "BUS_ERR",
	12 => "ARB_LOST",
	13 => "SEQ_ERR",
	14 => "ST_ERR",
	15 => "SW_ERR",
);

my %i2c_attr = (
	0 => "NOP",
	1 => "STOP",
	2 => "CONTINUE",
	3 => "START",
);

sub parse_i2c($$$$$)
{
	my $time = shift;
	my $optype = shift;
	my $align = shift;
	my $reg = shift;
	my $val = shift;

	if ($align ne 'l') {
		print("FIXME: currently, parser work only with 32 bits i2c reg $optype\n");
		return;
	}

	my $status = $i2c_status{$val & 0x0f};
	my $attr = $i2c_attr{($val >> 6) & 0x03};

	if ($debug < 1) {
		# Avoid poluting the logs with busy msgs
		return if ($status eq "BUSY" | $status eq "TO_SCL" | $status eq "TO_ARB");

		# Avoid poluting the logs with read msgs during write
		return if ($optype eq "read" && $status eq "DONE_WRITE");

		# Avoid poluting the logs with NOP operations
		return if ($attr eq "NOP");
	}

	# Prints I2C transaction
	if ($optype eq "write") {
		printf("write_i2c(%s, %s, 0x%02x)\t/* %s */\n", $status, $attr, $val >> 8, $time);
	} else {
		printf("val = read_i2c()\t/* %s: read %s, %s, val=0x%02x */\n", $time, $status, $attr, $val >> 8);
	}
}

while (<>) {
	# 1286074716 slow_bar_read.: slow_bar_readl addr=0x0000000000000180 val=0x00008182
	if (m/^(\d+)\s+slow_bar_(read|write)(.).*addr=([^\s]+)\s+val=([^\s]+)/) {
		my $time = $1;
		my $optype = $2;
		my $align = $3;
		my $op = "$2$3";
		my $reg = hex($4);
		my $val = hex($5);
		if (defined($reg_map{$reg})) {
			$reg = $reg_map{$reg};
		} else {
			$reg = sprintf("0x%04x", $reg);
		}
		if ($reg =~ m/SAA7134_I2C_ATTR_STATUS/) {
			parse_i2c($time, $optype, $align, $reg, $val);
		} elsif ($optype eq "read") {
			printf ("reg = saa_%s(%s);	/* %s: read 0x%04x */\n", $op, $reg, $time, $val);
		} else {
			printf ("saa_%s(%s, 0x%04x);	/* %s */\n", $op, $reg, $val, $time);
		}
	}
}

Privacy Policy