26 #define DVB_USB_LOG_PREFIX "it913x"
36 static int dvb_usb_it913x_debug;
37 #define it_debug(var, level, args...) \
38 do { if ((var & level)) pr_debug(DVB_USB_LOG_PREFIX": " args); \
40 #define deb_info(level, args...) it_debug(dvb_usb_it913x_debug, level, args)
41 #define info(args...) pr_info(DVB_USB_LOG_PREFIX": " args)
46 static int dvb_usb_it913x_firmware;
49 "1=IT9137 2=IT9135 V1 3=IT9135 V2");
50 #define FW_IT9137 "dvb-usb-it9137-01.fw"
51 #define FW_IT9135_V1 "dvb-usb-it9135-01.fw"
52 #define FW_IT9135_V2 "dvb-usb-it9135-02.fw"
68 sum += (i++ & 1) ? (*p++) << 8 : *p++;
83 info(
"USB Buffer Failed");
87 buff[buf_size++] = pro;
88 buff[buf_size++] =
cmd;
94 buff[buf_size++] = len;
96 buff[buf_size++] = (reg >> 24);
97 buff[buf_size++] = (reg >> 16) & 0xff;
98 buff[buf_size++] = (reg >> 8) & 0xff;
99 buff[buf_size++] = reg & 0xff;
102 buff[buf_size++] =
addr;
105 buff[buf_size++] = len;
106 buff[buf_size++] =
addr;
107 buff[buf_size++] = (reg >> 8) & 0xff;
108 buff[buf_size++] = reg & 0xff;
122 for (
i = 0;
i < len ;
i++)
123 buff[buf_size++] = data[
i];
125 chk_sum = check_sum(&buff[1], buf_size);
127 buff[buf_size++] = chk_sum >> 8;
129 buff[buf_size++] = (chk_sum & 0xff);
136 rlen = (mode & 0x1) ? 0x1 : len;
141 memcpy(data, &buff[3], rlen);
169 return (ret < 0) ? ret : data[0];
179 for (i = 0; i < 5; i++) {
181 0x1222, 0, &data[0], 3);
183 if (ver > 0 && ver < 3)
188 if (ver < 1 || ver > 2) {
189 info(
"Failed to identify chip version applying 1");
204 st->
it913x_config.firmware = (data[0] << 24) | (data[1] << 16) |
205 (data[2] << 8) | data[3];
239 ret = it913x_wr_reg(d, pro,
PID_LSB, (
u8)(pid & 0xff));
241 ret |= it913x_wr_reg(d, pro,
PID_MSB, (
u8)(pid >> 8));
245 ret |= it913x_wr_reg(d, pro,
PID_INX, (
u8)(index & 0x1f));
248 ret |= it913x_wr_reg(d , pro,
PID_EN, !onoff);
262 int ret = it913x_query(d,
DEV_0);
280 deb_info(2,
"num of messages %d address %02x", num, msg[0].addr);
285 reg = (data[0] << 24) + (data[1] << 16) +
286 (data[2] << 8) + data[3];
293 reg, 0, &data[4], msg[0].len - 4);
306 .master_xfer = it913x_i2c_xfer,
307 .functionality = it913x_i2c_func,
311 #define IT913X_POLL 250
321 0, 0, &ibuf[0],
sizeof(ibuf));
323 if ((ibuf[2] + ibuf[3]) == 0xff) {
325 key += ibuf[0] << 16;
327 deb_info(1,
"NEC Extended Key =%08x", key);
340 static const char fw_it9137[] =
FW_IT9137;
357 sw = dvb_usb_it913x_firmware;
364 *name = fw_it9135_v1;
370 *name = fw_it9135_v2;
376 info(
"Unknown tuner ID applying default 0x60");
392 #define TS_MPEG_PKT_SIZE 188
394 #define TS_BUFFER_SIZE_PID (EP_LOW*TS_MPEG_PKT_SIZE)
396 #define TS_BUFFER_SIZE_MAX (EP_HIGH*TS_MPEG_PKT_SIZE)
398 static int it913x_get_stream_config(
struct dvb_frontend *fe,
u8 *ts_type,
415 ret = it913x_return_status(d);
421 reg = it913x_read_reg(d, 0x461d);
423 reg = it913x_read_reg(d, 0x461b);
434 reg = it913x_read_reg(d, 0x49c5);
440 reg = it913x_read_reg(d, 0x49ac);
444 info(
"Remote propriety (raw) mode");
446 }
else if (reg == 1) {
447 info(
"Remote HID mode NOT SUPPORTED");
452 reg = it913x_read_reg(d, 0x49d0);
464 static int it913x_streaming_ctrl(
struct dvb_frontend *fe,
int onoff)
477 ret = it913x_wr_reg(d, pro,
PID_RST, 0x1);
488 static int it913x_identify_state(
struct dvb_usb_device *d,
const char **name)
495 ret = it913x_select_config(d);
499 ite_get_firmware_name(d, name);
515 ret |= it913x_return_status(d);
517 ret = it913x_wr_reg(d,
DEV_0,
527 ret |= it913x_wr_reg(d,
DEV_0, 0xcfff, 0x1);
531 ret |= it913x_wr_reg(d,
DEV_0, 0x4bfb, 0x0);
533 ret |= it913x_wr_reg(d,
DEV_0, 0xcfff, 0x0);
540 return (ret < 0) ? ret :
COLD;
547 int ret = 0, i = 0,
pos = 0;
548 u8 packet_size, min_pkt;
553 info(
"FRM Starting Firmware Download");
565 while (i <= fw->
size) {
566 if (((fw->
data[i] == 0x3) && (fw->
data[i + 2] == 0x0))
567 || (i == fw->
size)) {
568 packet_size = i -
pos;
569 if ((packet_size > min_pkt) || (i == fw->
size)) {
570 fw_data = (
u8 *)(fw->
data + pos);
572 if (packet_size > 0) {
575 0, fw_data, packet_size);
586 info(
"FRM Firmware Download Failed (%d)" , ret);
588 info(
"FRM Firmware Download Completed - Resetting Device");
594 info(
"FRM Device not responding to reboot");
596 ret = it913x_return_status(d);
598 info(
"FRM Failed to reboot device");
610 ret |= it913x_wr_reg(d,
DEV_0_DMOD , 0xec4c, 0xa0);
612 ret |= it913x_wr_reg(d,
DEV_0_DMOD , 0xec4c, 0x68);
624 return (ret < 0) ? -
ENODEV : 0;
631 char *fe_name[] = {
"_1",
"_2",
"_3",
"_4"};
632 char *name = adap->
fe[0]->ops.info.name;
657 if (adap->
id == 0 && adap->
fe[0]) {
667 }
else if (adap->
id == 1 && adap->
fe[0]) {
686 ret |= it913x_name(adap);
702 rc->
query = it913x_rc_query;
717 .driver_name = KBUILD_MODNAME,
719 .bInterfaceNumber = 0,
720 .generic_bulk_ctrl_endpoint = 0x02,
721 .generic_bulk_ctrl_endpoint_response = 0x81,
726 .identify_state = it913x_identify_state,
727 .i2c_algo = &it913x_i2c_algo,
729 .download_firmware = it913x_download_firmware,
731 .frontend_attach = it913x_frontend_attach,
732 .get_rc_config = it913x_get_rc_config,
733 .get_stream_config = it913x_get_stream_config,
734 .get_adapter_count = it913x_get_adapter_count,
735 .streaming_ctrl = it913x_streaming_ctrl,
742 .pid_filter_count = 32,
743 .pid_filter = it913x_pid_filter,
744 .pid_filter_ctrl = it913x_pid_filter_ctrl,
751 .pid_filter_count = 32,
752 .pid_filter = it913x_pid_filter,
753 .pid_filter_ctrl = it913x_pid_filter_ctrl,
762 &it913x_properties,
"Kworld UB499-2T T09(IT9137)",
765 &it913x_properties,
"ITE 9135 Generic",
768 &it913x_properties,
"Sveon STV22 Dual DVB-T HDTV(IT9137)",
771 &it913x_properties,
"ITE 9135(9005) Generic",
774 &it913x_properties,
"ITE 9135(9006) Generic",
781 static struct usb_driver it913x_driver = {
782 .name = KBUILD_MODNAME,
787 .id_table = it913x_id_table,