30 "set debugging level (1=info,xfer=2,rc=4,reg=8,i2c=16,fw=32 (or-able))."
38 static int dvb_usb_af9005_dump_eeprom;
48 static int *rc_keys_size;
50 u8 regmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
68 err(
"generic read/write, less than 1 byte. Makes no sense.");
72 err(
"generic read/write, more than 8 bytes. Not supported.");
84 obuf[5] = (
u8) (reg >> 8);
85 obuf[6] = (
u8) (reg & 0xff);
98 for (i = 0; i < len; i++)
99 obuf[8 + i] = values[i];
111 err(
"generic read/write, wrong reply code.");
114 if (ibuf[3] != 0x0d) {
115 err(
"generic read/write, wrong length in reply.");
118 if (ibuf[4] != obuf[4]) {
119 err(
"generic read/write, wrong sequence in reply.");
135 if (ibuf[16] != 0x01) {
136 err(
"generic read/write wrong status code in reply.");
140 for (i = 0; i < len; i++)
141 values[i] = ibuf[8 + i];
150 deb_reg(
"read register %x ", reg);
151 ret = af9005_generic_read_write(d, reg,
162 u8 * values,
int len)
165 deb_reg(
"read %d registers %x ", len, reg);
166 ret = af9005_generic_read_write(d, reg,
180 deb_reg(
"write register %x value %x ", reg, value);
181 ret = af9005_generic_read_write(d, reg,
192 u8 * values,
int len)
195 deb_reg(
"write %d registers %x values ", len, reg);
198 ret = af9005_generic_read_write(d, reg,
213 deb_reg(
"read bits %x %x %x", reg, pos, len);
220 deb_reg(
" value %x\n", *value);
230 deb_reg(
"write bits %x %x %x value %x\n", reg, pos, len, value);
231 if (pos == 0 && len == 8)
237 temp = (temp & ~mask) | ((value << pos) &
mask);
242 static int af9005_usb_read_tuner_registers(
struct dvb_usb_device *d,
243 u16 reg,
u8 * values,
int len)
245 return af9005_generic_read_write(d, reg,
250 static int af9005_usb_write_tuner_registers(
struct dvb_usb_device *d,
251 u16 reg,
u8 * values,
int len)
253 return af9005_generic_read_write(d, reg,
259 u8 * values,
int len)
266 ret = af9005_usb_write_tuner_registers(d, reg, values, len);
271 for (i = 0; i < 200; i++) {
312 u8 * values,
int len)
323 values[0] = addr + 0x01;
333 ret = af9005_usb_read_tuner_registers(d, reg, values, 1);
338 for (i = 0; i < 200; i++) {
355 for (i = 0; i < len; i++) {
369 deb_i2c(
"i2c_write i2caddr %x, reg %x, len %d data ", i2caddr,
373 for (i = 0; i < len; i++) {
375 buf[1] = reg + (
u8) i;
395 deb_i2c(
"i2c_read i2caddr %x, reg %x, len %d\n ", i2caddr, reg, len);
396 for (i = 0; i < len; i++) {
427 warn(
"more than 2 i2c messages at a time is not handled yet. TODO.");
434 ret = af9005_i2c_read(d, addr, reg, value, 1);
441 value = &msg[0].
buf[1];
442 ret = af9005_i2c_write(d, addr, reg, value, msg[0].len - 1);
457 .master_xfer = af9005_i2c_xfer,
458 .functionality = af9005_i2c_func,
462 int wlen,
u8 * rbuf,
int rlen)
466 int ret,
i, packet_len;
471 err(
"send command, wlen less than 0 bytes. Makes no sense.");
475 err(
"send command, wlen more than 54 bytes. Not supported.");
479 err(
"send command, rlen more than 54 bytes. Not supported.");
482 packet_len = wlen + 5;
483 buf[0] = (
u8) (packet_len & 0xff);
484 buf[1] = (
u8) ((packet_len & 0xff00) >> 8);
491 for (i = 0; i < wlen; i++)
492 buf[7 + i] = wbuf[i];
496 if (ibuf[2] != 0x27) {
497 err(
"send command, wrong reply code.");
500 if (ibuf[4] != buf[4]) {
501 err(
"send command, wrong sequence in reply.");
504 if (ibuf[5] != 0x01) {
505 err(
"send command, wrong status code in reply.");
508 if (ibuf[6] != rlen) {
509 err(
"send command, invalid data length in reply.");
512 for (i = 0; i < rlen; i++)
513 rbuf[i] = ibuf[i + 7];
521 u8 obuf[16], ibuf[14];
524 memset(obuf, 0,
sizeof(obuf));
525 memset(ibuf, 0,
sizeof(ibuf));
543 if (ibuf[2] != 0x2b) {
544 err(
"Read eeprom, invalid reply code");
548 err(
"Read eeprom, invalid reply length");
551 if (ibuf[4] != obuf[4]) {
552 err(
"Read eeprom, wrong sequence in reply ");
556 err(
"Read eeprom, wrong status in reply ");
559 for (i = 0; i < len; i++) {
560 values[
i] = ibuf[6 +
i];
565 static int af9005_boot_packet(
struct usb_device *
udev,
int type,
u8 * reply)
570 memset(buf, 0,
sizeof(buf));
579 checksum = buf[4] + buf[5];
580 buf[6] = (
u8) ((checksum >> 8) & 0xff);
581 buf[7] = (
u8) (checksum & 0xff);
588 checksum = buf[4] + buf[5];
589 buf[6] = (
u8) ((checksum >> 8) & 0xff);
590 buf[7] = (
u8) (checksum & 0xff);
602 for (i = 4; i <= 9; i++)
604 buf[10] = (
u8) ((checksum >> 8) & 0xff);
605 buf[11] = (
u8) (checksum & 0xff);
608 err(
"boot packet invalid boot packet type");
615 usb_sndbulkpipe(udev, 0x02),
618 err(
"boot packet bulk message failed: %d (%d/%d)", ret,
626 usb_rcvbulkpipe(udev, 0x01), buf, 9, &act_len, 2000);
628 err(
"boot packet recv bulk message failed: %d", ret);
636 if (buf[2] != 0x11) {
637 err(
"boot bad config header.");
640 if (buf[3] != 0x05) {
641 err(
"boot bad config size.");
644 if (buf[4] != 0x00) {
645 err(
"boot bad config sequence.");
648 if (buf[5] != 0x04) {
649 err(
"boot bad config subtype.");
652 for (i = 4; i <= 6; i++)
654 if (buf[7] * 256 + buf[8] != checksum) {
655 err(
"boot bad config checksum.");
661 if (buf[2] != 0x11) {
662 err(
"boot bad confirm header.");
665 if (buf[3] != 0x05) {
666 err(
"boot bad confirm size.");
669 if (buf[4] != 0x00) {
670 err(
"boot bad confirm sequence.");
673 if (buf[5] != 0x02) {
674 err(
"boot bad confirm subtype.");
677 for (i = 4; i <= 6; i++)
679 if (buf[7] * 256 + buf[8] != checksum) {
680 err(
"boot bad confirm checksum.");
686 if (buf[2] != 0x10) {
687 err(
"boot bad boot header.");
690 if (buf[3] != 0x05) {
691 err(
"boot bad boot size.");
694 if (buf[4] != 0x00) {
695 err(
"boot bad boot sequence.");
698 if (buf[5] != 0x01) {
699 err(
"boot bad boot pattern 01.");
702 if (buf[6] != 0x10) {
703 err(
"boot bad boot pattern 10.");
706 for (i = 4; i <= 6; i++)
708 if (buf[7] * 256 + buf[8] != checksum) {
709 err(
"boot bad boot checksum.");
719 static int af9005_download_firmware(
struct usb_device *udev,
const struct firmware *
fw)
726 ret = af9005_boot_packet(udev,
FW_CONFIG, &reply);
730 err(
"before downloading firmware, FW_CONFIG expected 0x01, received 0x%x", reply);
736 for (i = 0; i <
packets; i++) {
742 usb_sndbulkpipe(udev, 0x02),
745 err(
"firmware download failed at packet %d with code %d", i, ret);
749 ret = af9005_boot_packet(udev,
FW_CONFIRM, &reply);
752 if (reply != (
u8) (packets & 0xff)) {
753 err(
"after downloading firmware, FW_CONFIRM expected 0x%x, received 0x%x", packets & 0xff, reply);
756 ret = af9005_boot_packet(udev,
FW_BOOT, &reply);
759 ret = af9005_boot_packet(udev,
FW_CONFIG, &reply);
763 err(
"after downloading firmware, FW_CONFIG expected 0x02, received 0x%x", reply);
807 struct usb_device *udev = adap->
dev->udev;
810 if (dvb_usb_af9005_dump_eeprom) {
812 for (i = 0; i < 255; i += 8) {
831 if (rc_decode ==
NULL) {
843 err(
"rc query failed");
846 if (ibuf[2] != 0x41) {
847 err(
"rc query bad header.");
850 if (ibuf[4] != obuf[4]) {
851 err(
"rc query bad sequence.");
856 err(
"rc query invalid length");
860 deb_rc(
"rc data (%d) ", len);
862 ret = rc_decode(d, &ibuf[6], len, event, state);
864 err(
"rc_decode failed");
867 deb_rc(
"rc_decode state %x event %x\n", *state, *event);
884 deb_info(
"pid filter control onoff %d\n", onoff);
902 deb_info(
"pid filter control ok\n");
909 u8 cmd = index & 0x1f;
911 deb_info(
"set pid filter, index %d, pid %x, onoff %d\n", index,
917 deb_info(
"first pid set, enable pid table\n");
918 ret = af9005_pid_filter_control(adap, onoff);
937 deb_info(
"last pid unset, disable pid table\n");
938 ret = af9005_pid_filter_control(adap, onoff);
950 static int af9005_identify_state(
struct usb_device *udev,
957 ret = af9005_boot_packet(udev,
FW_CONFIG, &reply);
960 deb_info(
"result of FW_CONFIG in identify state %d\n", reply);
963 else if (reply == 0x02)
967 deb_info(
"Identify state cold = %d\n", *cold);
1002 .firmware =
"af9005.fw",
1003 .download_firmware = af9005_download_firmware,
1016 .pid_filter_count = 32,
1017 .pid_filter = af9005_pid_filter,
1019 .frontend_attach = af9005_frontend_attach,
1035 .power_ctrl = af9005_power_ctrl,
1036 .identify_state = af9005_identify_state,
1038 .i2c_algo = &af9005_i2c_algo,
1042 .rc_map_table =
NULL,
1044 .rc_query = af9005_rc_query,
1047 .generic_bulk_ctrl_endpoint = 2,
1048 .generic_bulk_ctrl_endpoint_response = 1,
1050 .num_device_descs = 3,
1052 {.name =
"Afatech DVB-T USB1.1 stick",
1056 {.name =
"TerraTec Cinergy T USB XE",
1060 {.name =
"Ansonic DVB-T USB1.1 stick",
1069 static struct usb_driver af9005_usb_driver = {
1070 .name =
"dvb_usb_af9005",
1071 .probe = af9005_usb_probe,
1073 .id_table = af9005_usb_table,
1077 static int __init af9005_usb_module_init(
void)
1080 if ((result = usb_register(&af9005_usb_driver))) {
1081 err(
"usb_register failed. (%d)", result);
1087 if (rc_decode ==
NULL || rc_keys ==
NULL || rc_keys_size ==
NULL) {
1088 err(
"af9005_rc_decode function not found, disabling remote");
1089 af9005_properties.
rc.legacy.rc_query =
NULL;
1091 af9005_properties.
rc.legacy.rc_map_table = rc_keys;
1092 af9005_properties.
rc.legacy.rc_map_size = *rc_keys_size;
1098 static void __exit af9005_usb_module_exit(
void)
1101 if (rc_decode !=
NULL)
1103 if (rc_keys !=
NULL)
1105 if (rc_keys_size !=
NULL)