Use dentry_path() to create full path to inode object
[pohmelfs.git] / drivers / media / dvb / dvb-usb / it913x.c
blob9f01cd7a6e3fbd6d67bf8be402b23b0413ee7ffc
1 /* DVB USB compliant linux driver for IT9137
3 * Copyright (C) 2011 Malcolm Priestley (tvboxspy@gmail.com)
4 * IT9137 (C) ITE Tech Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License Version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * see Documentation/dvb/README.dvb-usb for more information
21 * see Documentation/dvb/it9137.txt for firmware information
24 #define DVB_USB_LOG_PREFIX "it913x"
26 #include <linux/usb.h>
27 #include <linux/usb/input.h>
28 #include <media/rc-core.h>
30 #include "dvb-usb.h"
31 #include "it913x-fe.h"
33 /* debug */
34 static int dvb_usb_it913x_debug;
35 #define l_dprintk(var, level, args...) do { \
36 if ((var >= level)) \
37 printk(KERN_DEBUG DVB_USB_LOG_PREFIX ": " args); \
38 } while (0)
40 #define deb_info(level, args...) l_dprintk(dvb_usb_it913x_debug, level, args)
41 #define debug_data_snipet(level, name, p) \
42 deb_info(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \
43 *p, *(p+1), *(p+2), *(p+3), *(p+4), \
44 *(p+5), *(p+6), *(p+7));
47 module_param_named(debug, dvb_usb_it913x_debug, int, 0644);
48 MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))."
49 DVB_USB_DEBUG_STATUS);
51 static int pid_filter;
52 module_param_named(pid, pid_filter, int, 0644);
53 MODULE_PARM_DESC(pid, "set default 0=on 1=off");
55 static int dvb_usb_it913x_firmware;
56 module_param_named(firmware, dvb_usb_it913x_firmware, int, 0644);
57 MODULE_PARM_DESC(firmware, "set firmware 0=auto 1=IT9137 2=IT9135V1");
60 int cmd_counter;
62 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
64 struct it913x_state {
65 u8 id;
66 struct ite_config it913x_config;
69 struct ite_config it913x_config;
71 #define IT913X_RETRY 10
72 #define IT913X_SND_TIMEOUT 100
73 #define IT913X_RCV_TIMEOUT 200
75 static int it913x_bulk_write(struct usb_device *dev,
76 u8 *snd, int len, u8 pipe)
78 int ret, actual_l, i;
80 for (i = 0; i < IT913X_RETRY; i++) {
81 ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe),
82 snd, len , &actual_l, IT913X_SND_TIMEOUT);
83 if (ret == 0 || ret != -EBUSY || ret != -ETIMEDOUT)
84 break;
87 if (len != actual_l && ret == 0)
88 ret = -EAGAIN;
90 return ret;
93 static int it913x_bulk_read(struct usb_device *dev,
94 u8 *rev, int len, u8 pipe)
96 int ret, actual_l, i;
98 for (i = 0; i < IT913X_RETRY; i++) {
99 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe),
100 rev, len , &actual_l, IT913X_RCV_TIMEOUT);
101 if (ret == 0 || ret != -EBUSY || ret != -ETIMEDOUT)
102 break;
105 if (len != actual_l && ret == 0)
106 ret = -EAGAIN;
108 return ret;
111 static u16 check_sum(u8 *p, u8 len)
113 u16 sum = 0;
114 u8 i = 1;
115 while (i < len)
116 sum += (i++ & 1) ? (*p++) << 8 : *p++;
117 return ~sum;
120 static int it913x_usb_talk(struct usb_device *udev, u8 mode, u8 pro,
121 u8 cmd, u32 reg, u8 addr, u8 *data, u8 len)
123 int ret = 0, i, buf_size = 1;
124 u8 *buff;
125 u8 rlen;
126 u16 chk_sum;
128 buff = kzalloc(256, GFP_KERNEL);
129 if (!buff) {
130 info("USB Buffer Failed");
131 return -ENOMEM;
134 buff[buf_size++] = pro;
135 buff[buf_size++] = cmd;
136 buff[buf_size++] = cmd_counter;
138 switch (mode) {
139 case READ_LONG:
140 case WRITE_LONG:
141 buff[buf_size++] = len;
142 buff[buf_size++] = 2;
143 buff[buf_size++] = (reg >> 24);
144 buff[buf_size++] = (reg >> 16) & 0xff;
145 buff[buf_size++] = (reg >> 8) & 0xff;
146 buff[buf_size++] = reg & 0xff;
147 break;
148 case READ_SHORT:
149 buff[buf_size++] = addr;
150 break;
151 case WRITE_SHORT:
152 buff[buf_size++] = len;
153 buff[buf_size++] = addr;
154 buff[buf_size++] = (reg >> 8) & 0xff;
155 buff[buf_size++] = reg & 0xff;
156 break;
157 case READ_DATA:
158 case WRITE_DATA:
159 break;
160 case WRITE_CMD:
161 mode = 7;
162 break;
163 default:
164 kfree(buff);
165 return -EINVAL;
168 if (mode & 1) {
169 for (i = 0; i < len ; i++)
170 buff[buf_size++] = data[i];
172 chk_sum = check_sum(&buff[1], buf_size);
174 buff[buf_size++] = chk_sum >> 8;
175 buff[0] = buf_size;
176 buff[buf_size++] = (chk_sum & 0xff);
178 ret = it913x_bulk_write(udev, buff, buf_size , 0x02);
179 if (ret < 0)
180 goto error;
182 ret = it913x_bulk_read(udev, buff, (mode & 1) ?
183 5 : len + 5 , 0x01);
184 if (ret < 0)
185 goto error;
187 rlen = (mode & 0x1) ? 0x1 : len;
189 if (mode & 1)
190 ret = buff[2];
191 else
192 memcpy(data, &buff[3], rlen);
194 cmd_counter++;
196 error: kfree(buff);
198 return ret;
201 static int it913x_io(struct usb_device *udev, u8 mode, u8 pro,
202 u8 cmd, u32 reg, u8 addr, u8 *data, u8 len)
204 int ret, i;
206 for (i = 0; i < IT913X_RETRY; i++) {
207 ret = it913x_usb_talk(udev, mode, pro,
208 cmd, reg, addr, data, len);
209 if (ret != -EAGAIN)
210 break;
213 return ret;
216 static int it913x_wr_reg(struct usb_device *udev, u8 pro, u32 reg , u8 data)
218 int ret;
219 u8 b[1];
220 b[0] = data;
221 ret = it913x_io(udev, WRITE_LONG, pro,
222 CMD_DEMOD_WRITE, reg, 0, b, sizeof(b));
224 return ret;
227 static int it913x_read_reg(struct usb_device *udev, u32 reg)
229 int ret;
230 u8 data[1];
232 ret = it913x_io(udev, READ_LONG, DEV_0,
233 CMD_DEMOD_READ, reg, 0, &data[0], 1);
235 return (ret < 0) ? ret : data[0];
238 static u32 it913x_query(struct usb_device *udev, u8 pro)
240 int ret;
241 u8 data[4];
242 ret = it913x_io(udev, READ_LONG, pro, CMD_DEMOD_READ,
243 0x1222, 0, &data[0], 3);
245 it913x_config.chip_ver = data[0];
246 it913x_config.chip_type = (u16)(data[2] << 8) + data[1];
248 info("Chip Version=%02x Chip Type=%04x", it913x_config.chip_ver,
249 it913x_config.chip_type);
251 ret |= it913x_io(udev, READ_SHORT, pro,
252 CMD_QUERYINFO, 0, 0x1, &data[0], 4);
254 it913x_config.firmware = (data[0] << 24) + (data[1] << 16) +
255 (data[2] << 8) + data[3];
257 return (ret < 0) ? 0 : it913x_config.firmware;
260 static int it913x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
262 struct usb_device *udev = adap->dev->udev;
263 int ret;
264 u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
266 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
267 return -EAGAIN;
268 deb_info(1, "PID_C (%02x)", onoff);
270 ret = it913x_wr_reg(udev, pro, PID_EN, onoff);
272 mutex_unlock(&adap->dev->i2c_mutex);
273 return ret;
276 static int it913x_pid_filter(struct dvb_usb_adapter *adap,
277 int index, u16 pid, int onoff)
279 struct usb_device *udev = adap->dev->udev;
280 int ret;
281 u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
283 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
284 return -EAGAIN;
285 deb_info(1, "PID_F (%02x)", onoff);
287 ret = it913x_wr_reg(udev, pro, PID_LSB, (u8)(pid & 0xff));
289 ret |= it913x_wr_reg(udev, pro, PID_MSB, (u8)(pid >> 8));
291 ret |= it913x_wr_reg(udev, pro, PID_INX_EN, (u8)onoff);
293 ret |= it913x_wr_reg(udev, pro, PID_INX, (u8)(index & 0x1f));
295 mutex_unlock(&adap->dev->i2c_mutex);
296 return 0;
300 static int it913x_return_status(struct usb_device *udev)
302 u32 firm = 0;
304 firm = it913x_query(udev, DEV_0);
305 if (firm > 0)
306 info("Firmware Version %d", firm);
308 return (firm > 0) ? firm : 0;
311 static int it913x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
312 int num)
314 struct dvb_usb_device *d = i2c_get_adapdata(adap);
315 static u8 data[256];
316 int ret;
317 u32 reg;
318 u8 pro;
319 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
320 return -EAGAIN;
322 debug_data_snipet(1, "Message out", msg[0].buf);
323 deb_info(2, "num of messages %d address %02x", num, msg[0].addr);
325 pro = (msg[0].addr & 0x2) ? DEV_0_DMOD : 0x0;
326 pro |= (msg[0].addr & 0x20) ? DEV_1 : DEV_0;
327 memcpy(data, msg[0].buf, msg[0].len);
328 reg = (data[0] << 24) + (data[1] << 16) +
329 (data[2] << 8) + data[3];
330 if (num == 2) {
331 ret = it913x_io(d->udev, READ_LONG, pro,
332 CMD_DEMOD_READ, reg, 0, data, msg[1].len);
333 memcpy(msg[1].buf, data, msg[1].len);
334 } else
335 ret = it913x_io(d->udev, WRITE_LONG, pro, CMD_DEMOD_WRITE,
336 reg, 0, &data[4], msg[0].len - 4);
338 mutex_unlock(&d->i2c_mutex);
340 return ret;
343 static u32 it913x_i2c_func(struct i2c_adapter *adapter)
345 return I2C_FUNC_I2C;
348 static struct i2c_algorithm it913x_i2c_algo = {
349 .master_xfer = it913x_i2c_xfer,
350 .functionality = it913x_i2c_func,
353 /* Callbacks for DVB USB */
354 #define IT913X_POLL 250
355 static int it913x_rc_query(struct dvb_usb_device *d)
357 u8 ibuf[4];
358 int ret;
359 u32 key;
360 /* Avoid conflict with frontends*/
361 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
362 return -EAGAIN;
364 ret = it913x_io(d->udev, READ_LONG, PRO_LINK, CMD_IR_GET,
365 0, 0, &ibuf[0], sizeof(ibuf));
367 if ((ibuf[2] + ibuf[3]) == 0xff) {
368 key = ibuf[2];
369 key += ibuf[0] << 16;
370 key += ibuf[1] << 8;
371 deb_info(1, "NEC Extended Key =%08x", key);
372 if (d->rc_dev != NULL)
373 rc_keydown(d->rc_dev, key, 0);
376 mutex_unlock(&d->i2c_mutex);
378 return ret;
381 /* Firmware sets raw */
382 const char fw_it9135_v1[] = "dvb-usb-it9135-01.fw";
383 const char fw_it9135_v2[] = "dvb-usb-it9135-02.fw";
384 const char fw_it9137[] = "dvb-usb-it9137-01.fw";
386 static int ite_firmware_select(struct usb_device *udev,
387 struct dvb_usb_device_properties *props)
389 int sw;
390 /* auto switch */
391 if (le16_to_cpu(udev->descriptor.idProduct) ==
392 USB_PID_ITETECH_IT9135)
393 sw = IT9135_V1_FW;
394 else if (le16_to_cpu(udev->descriptor.idProduct) ==
395 USB_PID_ITETECH_IT9135_9005)
396 sw = IT9135_V1_FW;
397 else if (le16_to_cpu(udev->descriptor.idProduct) ==
398 USB_PID_ITETECH_IT9135_9006) {
399 sw = IT9135_V2_FW;
400 if (it913x_config.tuner_id_0 == 0)
401 it913x_config.tuner_id_0 = IT9135_60;
402 } else
403 sw = IT9137_FW;
405 /* force switch */
406 if (dvb_usb_it913x_firmware != IT9135_AUTO)
407 sw = dvb_usb_it913x_firmware;
409 switch (sw) {
410 case IT9135_V1_FW:
411 it913x_config.firmware_ver = 1;
412 it913x_config.adc_x2 = 1;
413 props->firmware = fw_it9135_v1;
414 break;
415 case IT9135_V2_FW:
416 it913x_config.firmware_ver = 1;
417 it913x_config.adc_x2 = 1;
418 props->firmware = fw_it9135_v2;
419 break;
420 case IT9137_FW:
421 default:
422 it913x_config.firmware_ver = 0;
423 it913x_config.adc_x2 = 0;
424 props->firmware = fw_it9137;
427 return 0;
430 #define TS_MPEG_PKT_SIZE 188
431 #define EP_LOW 21
432 #define TS_BUFFER_SIZE_PID (EP_LOW*TS_MPEG_PKT_SIZE)
433 #define EP_HIGH 348
434 #define TS_BUFFER_SIZE_MAX (EP_HIGH*TS_MPEG_PKT_SIZE)
436 static int it913x_identify_state(struct usb_device *udev,
437 struct dvb_usb_device_properties *props,
438 struct dvb_usb_device_description **desc,
439 int *cold)
441 int ret = 0, firm_no;
442 u8 reg, remote;
444 firm_no = it913x_return_status(udev);
446 /* checnk for dual mode */
447 it913x_config.dual_mode = it913x_read_reg(udev, 0x49c5);
449 if (udev->speed != USB_SPEED_HIGH) {
450 props->adapter[0].fe[0].pid_filter_count = 5;
451 info("USB 1 low speed mode - connect to USB 2 port");
452 if (pid_filter > 0)
453 pid_filter = 0;
454 if (it913x_config.dual_mode) {
455 it913x_config.dual_mode = 0;
456 info("Dual mode not supported in USB 1");
458 } else /* For replugging */
459 if(props->adapter[0].fe[0].pid_filter_count == 5)
460 props->adapter[0].fe[0].pid_filter_count = 31;
462 /* TODO different remotes */
463 remote = it913x_read_reg(udev, 0x49ac); /* Remote */
464 if (remote == 0)
465 props->rc.core.rc_codes = NULL;
467 /* TODO at the moment tuner_id is always assigned to 0x38 */
468 it913x_config.tuner_id_0 = it913x_read_reg(udev, 0x49d0);
470 info("Dual mode=%x Remote=%x Tuner Type=%x", it913x_config.dual_mode
471 , remote, it913x_config.tuner_id_0);
473 /* Select Stream Buffer Size and pid filter option*/
474 if (pid_filter) {
475 props->adapter[0].fe[0].stream.u.bulk.buffersize =
476 TS_BUFFER_SIZE_MAX;
477 props->adapter[0].fe[0].caps &=
478 ~DVB_USB_ADAP_NEED_PID_FILTERING;
479 } else
480 props->adapter[0].fe[0].stream.u.bulk.buffersize =
481 TS_BUFFER_SIZE_PID;
483 if (it913x_config.dual_mode) {
484 props->adapter[1].fe[0].stream.u.bulk.buffersize =
485 props->adapter[0].fe[0].stream.u.bulk.buffersize;
486 props->num_adapters = 2;
487 if (pid_filter)
488 props->adapter[1].fe[0].caps =
489 props->adapter[0].fe[0].caps;
490 } else
491 props->num_adapters = 1;
493 ret = ite_firmware_select(udev, props);
495 if (firm_no > 0) {
496 *cold = 0;
497 return 0;
500 if (it913x_config.dual_mode) {
501 it913x_config.tuner_id_1 = it913x_read_reg(udev, 0x49e0);
502 ret = it913x_wr_reg(udev, DEV_0, GPIOH1_EN, 0x1);
503 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_ON, 0x1);
504 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x1);
505 msleep(50);
506 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x0);
507 msleep(50);
508 reg = it913x_read_reg(udev, GPIOH1_O);
509 if (reg == 0) {
510 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x1);
511 ret |= it913x_return_status(udev);
512 if (ret != 0)
513 ret = it913x_wr_reg(udev, DEV_0,
514 GPIOH1_O, 0x0);
518 reg = it913x_read_reg(udev, IO_MUX_POWER_CLK);
520 if (it913x_config.dual_mode) {
521 ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, CHIP2_I2C_ADDR);
522 if (it913x_config.firmware_ver == 1)
523 ret |= it913x_wr_reg(udev, DEV_0, 0xcfff, 0x1);
524 else
525 ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x1);
526 } else {
527 ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, 0x0);
528 if (it913x_config.firmware_ver == 1)
529 ret |= it913x_wr_reg(udev, DEV_0, 0xcfff, 0x0);
530 else
531 ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x0);
534 *cold = 1;
536 return (ret < 0) ? -ENODEV : 0;
539 static int it913x_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
541 int ret = 0;
542 u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
544 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
545 return -EAGAIN;
546 deb_info(1, "STM (%02x)", onoff);
548 if (!onoff)
549 ret = it913x_wr_reg(adap->dev->udev, pro, PID_RST, 0x1);
552 mutex_unlock(&adap->dev->i2c_mutex);
554 return ret;
557 static int it913x_download_firmware(struct usb_device *udev,
558 const struct firmware *fw)
560 int ret = 0, i = 0, pos = 0;
561 u8 packet_size, min_pkt;
562 u8 *fw_data;
564 ret = it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_100);
566 info("FRM Starting Firmware Download");
568 /* Multi firmware loader */
569 /* This uses scatter write firmware headers */
570 /* The firmware must start with 03 XX 00 */
571 /* and be the extact firmware length */
573 if (it913x_config.chip_ver == 2)
574 min_pkt = 0x11;
575 else
576 min_pkt = 0x19;
578 while (i <= fw->size) {
579 if (((fw->data[i] == 0x3) && (fw->data[i + 2] == 0x0))
580 || (i == fw->size)) {
581 packet_size = i - pos;
582 if ((packet_size > min_pkt) || (i == fw->size)) {
583 fw_data = (u8 *)(fw->data + pos);
584 pos += packet_size;
585 if (packet_size > 0)
586 ret |= it913x_io(udev, WRITE_DATA,
587 DEV_0, CMD_SCATTER_WRITE, 0,
588 0, fw_data, packet_size);
589 udelay(1000);
592 i++;
595 ret |= it913x_io(udev, WRITE_CMD, DEV_0, CMD_BOOT, 0, 0, NULL, 0);
597 msleep(100);
599 if (ret < 0)
600 info("FRM Firmware Download Failed (%04x)" , ret);
601 else
602 info("FRM Firmware Download Completed - Resetting Device");
604 ret |= it913x_return_status(udev);
606 msleep(30);
608 ret |= it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_400);
610 /* Tuner function */
611 if (it913x_config.dual_mode)
612 ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0xa0);
613 else
614 ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0x68);
616 if ((it913x_config.chip_ver == 1) &&
617 (it913x_config.chip_type == 0x9135)) {
618 ret |= it913x_wr_reg(udev, DEV_0, PADODPU, 0x0);
619 ret |= it913x_wr_reg(udev, DEV_0, AGC_O_D, 0x0);
620 if (it913x_config.dual_mode) {
621 ret |= it913x_wr_reg(udev, DEV_1, PADODPU, 0x0);
622 ret |= it913x_wr_reg(udev, DEV_1, AGC_O_D, 0x0);
626 return (ret < 0) ? -ENODEV : 0;
629 static int it913x_name(struct dvb_usb_adapter *adap)
631 const char *desc = adap->dev->desc->name;
632 char *fe_name[] = {"_1", "_2", "_3", "_4"};
633 char *name = adap->fe_adap[0].fe->ops.info.name;
635 strlcpy(name, desc, 128);
636 strlcat(name, fe_name[adap->id], 128);
638 return 0;
641 static int it913x_frontend_attach(struct dvb_usb_adapter *adap)
643 struct usb_device *udev = adap->dev->udev;
644 struct it913x_state *st = adap->dev->priv;
645 int ret = 0;
646 u8 adap_addr = I2C_BASE_ADDR + (adap->id << 5);
647 u16 ep_size = adap->props.fe[0].stream.u.bulk.buffersize / 4;
648 u8 pkt_size = 0x80;
650 if (adap->dev->udev->speed != USB_SPEED_HIGH)
651 pkt_size = 0x10;
653 it913x_config.adf = it913x_read_reg(udev, IO_MUX_POWER_CLK);
655 if (adap->id == 0)
656 memcpy(&st->it913x_config, &it913x_config,
657 sizeof(struct ite_config));
659 adap->fe_adap[0].fe = dvb_attach(it913x_fe_attach,
660 &adap->dev->i2c_adap, adap_addr, &st->it913x_config);
662 if (adap->id == 0 && adap->fe_adap[0].fe) {
663 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x1);
664 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_SW_RST, 0x1);
665 ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x0f);
666 ret = it913x_wr_reg(udev, DEV_0, EP0_TX_NAK, 0x1b);
667 ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x2f);
668 ret = it913x_wr_reg(udev, DEV_0, EP4_TX_LEN_LSB,
669 ep_size & 0xff);
670 ret = it913x_wr_reg(udev, DEV_0, EP4_TX_LEN_MSB, ep_size >> 8);
671 ret = it913x_wr_reg(udev, DEV_0, EP4_MAX_PKT, pkt_size);
672 } else if (adap->id == 1 && adap->fe_adap[0].fe) {
673 ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x6f);
674 ret = it913x_wr_reg(udev, DEV_0, EP5_TX_LEN_LSB,
675 ep_size & 0xff);
676 ret = it913x_wr_reg(udev, DEV_0, EP5_TX_LEN_MSB, ep_size >> 8);
677 ret = it913x_wr_reg(udev, DEV_0, EP5_MAX_PKT, pkt_size);
678 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_EN, 0x1);
679 ret = it913x_wr_reg(udev, DEV_1_DMOD, MP2IF_SERIAL, 0x1);
680 ret = it913x_wr_reg(udev, DEV_1, TOP_HOSTB_SER_MODE, 0x1);
681 ret = it913x_wr_reg(udev, DEV_0_DMOD, TSIS_ENABLE, 0x1);
682 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x0);
683 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_SW_RST, 0x0);
684 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_HALF_PSB, 0x0);
685 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF_STOP_EN, 0x1);
686 ret = it913x_wr_reg(udev, DEV_1_DMOD, MPEG_FULL_SPEED, 0x0);
687 ret = it913x_wr_reg(udev, DEV_1_DMOD, MP2IF_STOP_EN, 0x0);
688 } else
689 return -ENODEV;
691 ret = it913x_name(adap);
693 return ret;
696 /* DVB USB Driver */
697 static struct dvb_usb_device_properties it913x_properties;
699 static int it913x_probe(struct usb_interface *intf,
700 const struct usb_device_id *id)
702 cmd_counter = 0;
703 if (0 == dvb_usb_device_init(intf, &it913x_properties,
704 THIS_MODULE, NULL, adapter_nr)) {
705 info("DEV registering device driver");
706 return 0;
709 info("DEV it913x Error");
710 return -ENODEV;
714 static struct usb_device_id it913x_table[] = {
715 { USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB499_2T_T09) },
716 { USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135) },
717 { USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV22_IT9137) },
718 { USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9005) },
719 { USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9006) },
720 {} /* Terminating entry */
723 MODULE_DEVICE_TABLE(usb, it913x_table);
725 static struct dvb_usb_device_properties it913x_properties = {
726 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
727 .usb_ctrl = DEVICE_SPECIFIC,
728 .download_firmware = it913x_download_firmware,
729 .firmware = "dvb-usb-it9137-01.fw",
730 .no_reconnect = 1,
731 .size_of_priv = sizeof(struct it913x_state),
732 .num_adapters = 2,
733 .adapter = {
735 .num_frontends = 1,
736 .fe = {{
737 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
738 DVB_USB_ADAP_NEED_PID_FILTERING|
739 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
740 .streaming_ctrl = it913x_streaming_ctrl,
741 .pid_filter_count = 31,
742 .pid_filter = it913x_pid_filter,
743 .pid_filter_ctrl = it913x_pid_filter_ctrl,
744 .frontend_attach = it913x_frontend_attach,
745 /* parameter for the MPEG2-data transfer */
746 .stream = {
747 .type = USB_BULK,
748 .count = 10,
749 .endpoint = 0x04,
750 .u = {/* Keep Low if PID filter on */
751 .bulk = {
752 .buffersize =
753 TS_BUFFER_SIZE_PID,
760 .num_frontends = 1,
761 .fe = {{
762 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
763 DVB_USB_ADAP_NEED_PID_FILTERING|
764 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
765 .streaming_ctrl = it913x_streaming_ctrl,
766 .pid_filter_count = 31,
767 .pid_filter = it913x_pid_filter,
768 .pid_filter_ctrl = it913x_pid_filter_ctrl,
769 .frontend_attach = it913x_frontend_attach,
770 /* parameter for the MPEG2-data transfer */
771 .stream = {
772 .type = USB_BULK,
773 .count = 5,
774 .endpoint = 0x05,
775 .u = {
776 .bulk = {
777 .buffersize =
778 TS_BUFFER_SIZE_PID,
785 .identify_state = it913x_identify_state,
786 .rc.core = {
787 .protocol = RC_TYPE_NEC,
788 .module_name = "it913x",
789 .rc_query = it913x_rc_query,
790 .rc_interval = IT913X_POLL,
791 .allowed_protos = RC_TYPE_NEC,
792 .rc_codes = RC_MAP_MSI_DIGIVOX_III,
794 .i2c_algo = &it913x_i2c_algo,
795 .num_device_descs = 5,
796 .devices = {
797 { "Kworld UB499-2T T09(IT9137)",
798 { &it913x_table[0], NULL },
800 { "ITE 9135 Generic",
801 { &it913x_table[1], NULL },
803 { "Sveon STV22 Dual DVB-T HDTV(IT9137)",
804 { &it913x_table[2], NULL },
806 { "ITE 9135(9005) Generic",
807 { &it913x_table[3], NULL },
809 { "ITE 9135(9006) Generic",
810 { &it913x_table[4], NULL },
815 static struct usb_driver it913x_driver = {
816 .name = "it913x",
817 .probe = it913x_probe,
818 .disconnect = dvb_usb_device_exit,
819 .id_table = it913x_table,
822 module_usb_driver(it913x_driver);
824 MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
825 MODULE_DESCRIPTION("it913x USB 2 Driver");
826 MODULE_VERSION("1.22");
827 MODULE_LICENSE("GPL");