| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Copyright (C) 2008-2011 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 |
|
| 15 |
use strict; |
| 16 |
|
| 17 |
# Enable autoflush |
| 18 |
BEGIN { $| = 1 } |
| 19 |
|
| 20 |
my $min_delay = 10; |
| 21 |
|
| 22 |
my %req_map = ( |
| 23 |
0x0 => "REQUEST_SET_USB_XFER_LEN", |
| 24 |
0x2 => "REQUEST_I2C_READ", |
| 25 |
0x3 => "REQUEST_I2C_WRITE", |
| 26 |
0x4 => "REQUEST_POLL_RC", |
| 27 |
0x8 => "REQUEST_JUMPRAM", |
| 28 |
0xB => "REQUEST_SET_CLOCK", |
| 29 |
0xC => "REQUEST_SET_GPIO", |
| 30 |
0xF => "REQUEST_ENABLE_VIDEO", |
| 31 |
0x10 => "REQUEST_SET_I2C_PARAM", |
| 32 |
0x11 => "REQUEST_SET_RC", |
| 33 |
0x12 => "REQUEST_NEW_I2C_READ", |
| 34 |
0x13 => "REQUEST_NEW_I2C_WRITE", |
| 35 |
0x15 => "REQUEST_GET_VERSION", |
| 36 |
); |
| 37 |
|
| 38 |
my %gpio_map = ( |
| 39 |
0 => "GPIO0", |
| 40 |
2 => "GPIO1", |
| 41 |
3 => "GPIO2", |
| 42 |
4 => "GPIO3", |
| 43 |
5 => "GPIO4", |
| 44 |
6 => "GPIO5", |
| 45 |
8 => "GPIO6", |
| 46 |
10 => "GPIO7", |
| 47 |
11 => "GPIO8", |
| 48 |
14 => "GPIO9", |
| 49 |
15 => "GPIO10", |
| 50 |
); |
| 51 |
|
| 52 |
sub type_req($) |
| 53 |
{ |
| 54 |
my $reqtype = shift; |
| 55 |
my $s; |
| 56 |
|
| 57 |
if ($reqtype & 0x80) { |
| 58 |
$s = "RD "; |
| 59 |
} else { |
| 60 |
$s = "WR "; |
| 61 |
} |
| 62 |
if (($reqtype & 0x60) == 0x20) { |
| 63 |
$s .= "CLAS "; |
| 64 |
} elsif (($reqtype & 0x60) == 0x40) { |
| 65 |
$s .= "VEND "; |
| 66 |
} elsif (($reqtype & 0x60) == 0x60) { |
| 67 |
$s .= "RSVD "; |
| 68 |
} |
| 69 |
|
| 70 |
if (($reqtype & 0x1f) == 0x00) { |
| 71 |
$s .= "DEV "; |
| 72 |
} elsif (($reqtype & 0x1f) == 0x01) { |
| 73 |
$s .= "INT "; |
| 74 |
} elsif (($reqtype & 0x1f) == 0x02) { |
| 75 |
$s .= "EP "; |
| 76 |
} elsif (($reqtype & 0x1f) == 0x03) { |
| 77 |
$s .= "OTHER "; |
| 78 |
} elsif (($reqtype & 0x1f) == 0x04) { |
| 79 |
$s .= "PORT "; |
| 80 |
} elsif (($reqtype & 0x1f) == 0x05) { |
| 81 |
$s .= "RPIPE "; |
| 82 |
} else { |
| 83 |
$s .= sprintf "RECIP 0x%02x ", $reqtype & 0x1f; |
| 84 |
} |
| 85 |
|
| 86 |
$s =~ s/\s+$//; |
| 87 |
return $s; |
| 88 |
} |
| 89 |
|
| 90 |
my $delay = 0; |
| 91 |
|
| 92 |
while (<>) { |
| 93 |
tr/A-F/a-f/; |
| 94 |
|
| 95 |
if (m/(.*)([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].) ([0-9a-f].)\s*[\<\>]+\s*(.*)/) { |
| 96 |
my $prev = $1; |
| 97 |
my $reqtype = hex($2); |
| 98 |
my $req = hex($3); |
| 99 |
my $wvalue = hex("$5$4"); |
| 100 |
my $windex = hex("$7$6"); |
| 101 |
my $wlen = hex("$9$8"); |
| 102 |
my $payload = $10; |
| 103 |
my @bytes = split(/ /, $payload); |
| 104 |
for (my $i = 0; $i < scalar(@bytes); $i++) { |
| 105 |
$bytes[$i] = hex($bytes[$i]); |
| 106 |
} |
| 107 |
|
| 108 |
if (defined($req_map{$req})) { |
| 109 |
$req = $req_map{$req}; |
| 110 |
} else { |
| 111 |
$req = sprintf "0x%02x", $req; |
| 112 |
} |
| 113 |
|
| 114 |
printf "msleep(%d);\n", $delay if ($delay); |
| 115 |
$delay = 0; |
| 116 |
|
| 117 |
if (m/(IN|OUT): (\d+) ms \d+ ms/) { |
| 118 |
$delay = $min_delay * int(($2 + $min_delay / 2) / $min_delay); |
| 119 |
} |
| 120 |
|
| 121 |
if ($req eq "REQUEST_I2C_READ") { |
| 122 |
my $txlen = ($wvalue >> 8) + 2; |
| 123 |
my $addr = sprintf "0x%02x >> 1", $wvalue & 0xfe; |
| 124 |
my $val; |
| 125 |
|
| 126 |
if ($txlen == 2) { |
| 127 |
printf("dib0700_i2c_read($addr); /* $payload */\n"); |
| 128 |
next; |
| 129 |
} elsif ($txlen == 3) { |
| 130 |
$val = $windex >> 8; |
| 131 |
printf("dib0700_i2c_read($addr, %d); /* $payload */\n", $val); |
| 132 |
next; |
| 133 |
} elsif ($txlen == 4) { |
| 134 |
$val = $windex; |
| 135 |
printf("dib0700_i2c_read($addr, %d); /* $payload */\n", $val); |
| 136 |
next; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
if ($req eq "REQUEST_I2C_WRITE") { |
| 141 |
if ($wlen == 5 || $wlen == 6) { |
| 142 |
my $addr = sprintf "0x%02x >> 1", $bytes[1]; |
| 143 |
my $reg = sprintf "0x%04x", $bytes[2] << 8 | $bytes[3]; |
| 144 |
my $val; |
| 145 |
if ($wlen == 6) { |
| 146 |
$val = sprintf "%d", $bytes[4] << 8 | $bytes[5]; |
| 147 |
} else { |
| 148 |
$val = sprintf "%d", $bytes[4]; |
| 149 |
} |
| 150 |
printf("dib0700_i2c_write($addr, $reg, $val);\n"); |
| 151 |
next; |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
if ($req eq "REQUEST_SET_I2C_PARAM") { |
| 156 |
my $divider1 = $bytes[2] << 8 | $bytes[3]; |
| 157 |
my $divider2 = $bytes[4] << 8 | $bytes[5]; |
| 158 |
my $divider3 = $bytes[6] << 8 | $bytes[7]; |
| 159 |
|
| 160 |
my $xclk1 = 30000/$divider1; |
| 161 |
my $xclk2 = 72000/$divider2; |
| 162 |
my $xclk3 = 72000/$divider3; |
| 163 |
|
| 164 |
if ($xclk1 == $xclk2 && $xclk2 == $xclk3) { |
| 165 |
printf("dib0700_set_i2c_speed(adap->dev, $xclk1 /* kHz */);\n"); |
| 166 |
next; |
| 167 |
} |
| 168 |
printf("dib0700_set_i2c_speed: $divider1 ($xclk1 kHz), $divider2 ($xclk2 kHz), $divider3 ($xclk3 kHz)\n"); |
| 169 |
next; |
| 170 |
} |
| 171 |
|
| 172 |
if ($req eq "REQUEST_GET_VERSION") { |
| 173 |
my $hwversion = $bytes[0] << 24 | $bytes[1] << 16 | $bytes[2] << 8 | $bytes[3]; |
| 174 |
my $romversion = $bytes[4] << 24 | $bytes[5] << 16 | $bytes[6] << 8 | $bytes[7]; |
| 175 |
my $fw_version = $bytes[8] << 24 | $bytes[9] << 16 | $bytes[10] << 8 | $bytes[11]; |
| 176 |
my $fwtype = $bytes[12] << 24 | $bytes[13] << 16 | $bytes[14] << 8 | $bytes[15]; |
| 177 |
|
| 178 |
printf("dib0700_get_version(adap->dev, NULL, NULL, NULL, NULL); /* hw: 0x%x rom: 0x%0x fw version: 0x%x, fw type: 0x%x */\n", |
| 179 |
$hwversion, $romversion, $fw_version, $fwtype); |
| 180 |
next; |
| 181 |
} |
| 182 |
|
| 183 |
if ($req eq "REQUEST_SET_GPIO") { |
| 184 |
my $gpio = $bytes[1]; |
| 185 |
my $v = $bytes[2]; |
| 186 |
|
| 187 |
my $dir = "GPIO_IN"; |
| 188 |
my $val = 0; |
| 189 |
|
| 190 |
$dir = "GPIO_OUT" if ($v & 0x80); |
| 191 |
$val = 1 if ($v & 0x40); |
| 192 |
|
| 193 |
if (!($v & 0x3f)) { |
| 194 |
$gpio = $gpio_map{$gpio} if (defined($gpio_map{$gpio})); |
| 195 |
printf("dib0700_set_gpio(adap->dev, $gpio, $dir, $val);\n"); |
| 196 |
next; |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
if (($reqtype & 0xf0) == 0xc0) { |
| 201 |
my $txlen = ($wvalue >> 8) + 2; |
| 202 |
my $addr = $req; |
| 203 |
my $val; |
| 204 |
|
| 205 |
if ($txlen == 2) { |
| 206 |
printf("dib0700_ctrl_rd(adap->dev, $txlen, { cmd, $addr }, &buf, $wlen); /* $payload */\n"); |
| 207 |
next; |
| 208 |
} elsif ($txlen == 3) { |
| 209 |
$val = $windex >> 8; |
| 210 |
printf("dib0700_ctrl_rd(adap->dev, $txlen, { cmd, $addr, $val }, &buf, $wlen); /* $payload */\n"); |
| 211 |
next; |
| 212 |
} elsif ($txlen == 4) { |
| 213 |
$val = $windex; |
| 214 |
printf("dib0700_ctrl_rd(adap->dev, $txlen, { cmd, $addr, $val }, &buf, $wlen); /* $payload */\n"); |
| 215 |
next; |
| 216 |
} |
| 217 |
} |
| 218 |
if ($wvalue == 0 && $windex == 0 && (($reqtype & 0xf0) == 0x40)) { |
| 219 |
my $cmd = $req; |
| 220 |
for (my $i = 0; $i < scalar(@bytes); $i++) { |
| 221 |
$cmd .= sprintf ", 0x%02x", $bytes[$i]; |
| 222 |
} |
| 223 |
|
| 224 |
printf("dib0700_ctrl_wr(adap->dev, { $cmd }, %d);\n", $wlen + 1); |
| 225 |
next; |
| 226 |
} |
| 227 |
|
| 228 |
printf("%s(0x%02x), Req %s, wValue: 0x%04x, wIndex 0x%04x, wlen %d: %s\n", |
| 229 |
type_req($reqtype), $reqtype, $req, $wvalue, $windex, $wlen, $payload); |
| 230 |
} |
| 231 |
} |