| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Copyright (C) 2016 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 |
# This small script parses register dumps generated by parse_cx231xx.pl |
| 15 |
# for tda18271 tuner, like: |
| 16 |
# OUT i2c channel#2 daddr 0x60 100kbps addr_len 1 sync len 1 = (saddr)25 37 02 |
| 17 |
|
| 18 |
use strict; |
| 19 |
|
| 20 |
my %tda18271_reg = ( |
| 21 |
0x00 => "ID byte (R_ID)", |
| 22 |
0x01 => "Thermo byte (R_TM)", |
| 23 |
0x02 => "Power level byte (R_PL)", |
| 24 |
0x03 => "Easy Prog byte 1 (R_EP1)", |
| 25 |
0x04 => "Easy Prog byte 2 (R_EP2)", |
| 26 |
0x05 => "Easy Prog byte 3 (R_EP3)", |
| 27 |
0x06 => "Easy Prog byte 4 (R_EP4)", |
| 28 |
0x07 => "Easy Prog byte 5 (R_EP5)", |
| 29 |
0x08 => "Cal Post-Divider byte (R_CPD)", |
| 30 |
0x09 => "Cal Divider byte 1 (R_CD1)", |
| 31 |
0x0a => "Cal Divider byte 2 (R_CD2)", |
| 32 |
0x0b => "Cal Divider byte 3 (R_CD3)", |
| 33 |
0x0c => "Main Post-Divider byte (R_MPD)", |
| 34 |
0x0d => "Main Divider byte 1 (R_MD1)", |
| 35 |
0x0e => "Main Divider byte 2 (R_MD2)", |
| 36 |
0x0f => "Main Divider byte 3 (R_MD3)", |
| 37 |
0x10 => "Extended byte 1 (R_EB1)", |
| 38 |
0x11 => "Extended byte 2 (R_EB2)", |
| 39 |
0x12 => "Extended byte 3 (R_EB3)", |
| 40 |
0x13 => "Extended byte 4 (R_EB4)", |
| 41 |
0x14 => "Extended byte 5 (R_EB5)", |
| 42 |
0x15 => "Extended byte 6 (R_EB6)", |
| 43 |
0x16 => "Extended byte 7 (R_EB7)", |
| 44 |
0x17 => "Extended byte 8 (R_EB8)", |
| 45 |
0x18 => "Extended byte 9 (R_EB9)", |
| 46 |
0x19 => "Extended byte 10 (R_EB10)", |
| 47 |
0x1a => "Extended byte 11 (R_EB11)", |
| 48 |
0x1b => "Extended byte 12 (R_EB12)", |
| 49 |
0x1c => "Extended byte 13 (R_EB13)", |
| 50 |
0x1d => "Extended byte 14 (R_EB14)", |
| 51 |
0x1e => "Extended byte 15 (R_EB15)", |
| 52 |
0x1f => "Extended byte 16 (R_EB16)", |
| 53 |
0x20 => "Extended byte 17 (R_EB17)", |
| 54 |
0x21 => "Extended byte 18 (R_EB18)", |
| 55 |
0x22 => "Extended byte 19 (R_EB19)", |
| 56 |
0x23 => "Extended byte 20 (R_EB20)", |
| 57 |
0x24 => "Extended byte 21 (R_EB21)", |
| 58 |
0x25 => "Extended byte 22 (R_EB22)", |
| 59 |
0x26 => "Extended byte 23 (R_EB23)", |
| 60 |
); |
| 61 |
|
| 62 |
|
| 63 |
# OUT i2c channel#2 daddr 0x60 100kbps addr_len 1 sync len 1 = (saddr)25 37 02 |
| 64 |
|
| 65 |
my $mb86a20s_cont; |
| 66 |
|
| 67 |
while (<>) { |
| 68 |
my $org_line = $_; |
| 69 |
|
| 70 |
if (m/(IN|OUT)\s+i2c\s+channel#\d\s+daddr\s+0x10.*\=\s*\(saddr\)([\da-f].)\s+(.*)/) { |
| 71 |
my $type = $1; |
| 72 |
my $reg = $2; |
| 73 |
my $val = $3; |
| 74 |
my $err = ""; |
| 75 |
|
| 76 |
if ($val =~ s/eRROR (.*)//) { |
| 77 |
$err = "\t// ERROR $1"; |
| 78 |
} |
| 79 |
|
| 80 |
if ($reg eq "08" && $val eq "01") { |
| 81 |
print "\t// INCOMPLETE!!!\n" if ($mb86a20s_cont); |
| 82 |
printf "\n"; |
| 83 |
$mb86a20s_cont = 0; |
| 84 |
} |
| 85 |
|
| 86 |
printf "(%-3s)mb86a20s:\t", $type if (!$mb86a20s_cont); |
| 87 |
|
| 88 |
if ($type eq "OUT") { |
| 89 |
printf "{ 0x%s, 0x%s },", $reg, $val; |
| 90 |
} else { |
| 91 |
printf "{ 0x%s } = 0x%s,", $reg, $val; |
| 92 |
} |
| 93 |
|
| 94 |
if ($reg eq "04" || $reg eq "50" || |
| 95 |
$reg eq "28" || $reg eq "29" || $reg eq "2a") { |
| 96 |
print " "; |
| 97 |
$mb86a20s_cont = 1; |
| 98 |
} else { |
| 99 |
$mb86a20s_cont = 0; |
| 100 |
print "$err\n"; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
if (m/(IN|OUT)\s+i2c\s+channel#\d\s+daddr\s+0x60.*\=\s*\(saddr\)([\da-f].)\s+(.*)/) { |
| 105 |
my $type = $1; |
| 106 |
my $vals = $3; |
| 107 |
my $regval = hex($2); |
| 108 |
my $err = ""; |
| 109 |
|
| 110 |
if ($vals =~ s/eRROR (.*)//) { |
| 111 |
$err = "\t// ERROR $1"; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
print "\t// INCOMPLETE!!!\n" if ($mb86a20s_cont); |
| 116 |
|
| 117 |
my $j = 0; |
| 118 |
while ($j + 2 <= length($vals)) { |
| 119 |
my $reg; |
| 120 |
my $val = hex(substr($vals, $j, 2)); |
| 121 |
|
| 122 |
if (defined($tda18271_reg{$regval})) { |
| 123 |
$reg = $tda18271_reg{$regval}; |
| 124 |
} else { |
| 125 |
$reg = sprintf "REG 0x%02x", $regval; |
| 126 |
} |
| 127 |
printf "(%-3s)tda18271_dump_regs: %s = 0x%02x$err\n", $type, $reg, $val; |
| 128 |
$regval++; |
| 129 |
$j += 3; |
| 130 |
} |
| 131 |
} |
| 132 |
print $_ if (m/cx231xx/); |
| 133 |
} |