blob: a541904851f594d106dcf0029d18faf494e3dd96 [file] [log] [blame]
Malcolm Priestleyf6d87352011-07-25 15:35:03 -03001/* DVB USB compliant linux driver for IT9137
2 *
3 * Copyright (C) 2011 Malcolm Priestley (tvboxspy@gmail.com)
4 * IT9137 (C) ITE Tech Inc.
5 *
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.
9 *
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.
14 *
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.
18 *
19 *
20 * see Documentation/dvb/README.dvb-usb for more information
21 * see Documentation/dvb/it9137.txt for firmware information
22 *
23 */
24#define DVB_USB_LOG_PREFIX "it913x"
25
26#include <linux/usb.h>
27#include <linux/usb/input.h>
28#include <media/rc-core.h>
29
30#include "dvb-usb.h"
31#include "it913x-fe.h"
32
33/* debug */
34static 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)
39
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));
45
46
47module_param_named(debug, dvb_usb_it913x_debug, int, 0644);
48MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))."
49 DVB_USB_DEBUG_STATUS);
50
51static int pid_filter;
52module_param_named(pid, pid_filter, int, 0644);
53MODULE_PARM_DESC(pid, "set default 0=on 1=off");
54
55int cmd_counter;
56
57DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
58
59struct it913x_state {
60 u8 id;
61};
62
Malcolm Priestleybc549192011-10-14 19:54:11 -030063struct ite_config it913x_config;
64
Malcolm Priestleyf6d87352011-07-25 15:35:03 -030065static int it913x_bulk_write(struct usb_device *dev,
66 u8 *snd, int len, u8 pipe)
67{
68 int ret, actual_l;
69
70 ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe),
71 snd, len , &actual_l, 100);
72 return ret;
73}
74
75static int it913x_bulk_read(struct usb_device *dev,
76 u8 *rev, int len, u8 pipe)
77{
78 int ret, actual_l;
79
80 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe),
81 rev, len , &actual_l, 200);
82 return ret;
83}
84
85static u16 check_sum(u8 *p, u8 len)
86{
87 u16 sum = 0;
88 u8 i = 1;
89 while (i < len)
90 sum += (i++ & 1) ? (*p++) << 8 : *p++;
91 return ~sum;
92}
93
94static int it913x_io(struct usb_device *udev, u8 mode, u8 pro,
95 u8 cmd, u32 reg, u8 addr, u8 *data, u8 len)
96{
97 int ret = 0, i, buf_size = 1;
98 u8 *buff;
99 u8 rlen;
100 u16 chk_sum;
101
102 buff = kzalloc(256, GFP_KERNEL);
103 if (!buff) {
104 info("USB Buffer Failed");
105 return -ENOMEM;
106 }
107
108 buff[buf_size++] = pro;
109 buff[buf_size++] = cmd;
110 buff[buf_size++] = cmd_counter;
111
112 switch (mode) {
113 case READ_LONG:
114 case WRITE_LONG:
115 buff[buf_size++] = len;
116 buff[buf_size++] = 2;
117 buff[buf_size++] = (reg >> 24);
118 buff[buf_size++] = (reg >> 16) & 0xff;
119 buff[buf_size++] = (reg >> 8) & 0xff;
120 buff[buf_size++] = reg & 0xff;
121 break;
122 case READ_SHORT:
123 buff[buf_size++] = addr;
124 break;
125 case WRITE_SHORT:
126 buff[buf_size++] = len;
127 buff[buf_size++] = addr;
128 buff[buf_size++] = (reg >> 8) & 0xff;
129 buff[buf_size++] = reg & 0xff;
130 break;
131 case READ_DATA:
132 case WRITE_DATA:
133 break;
134 case WRITE_CMD:
135 mode = 7;
136 break;
137 default:
138 kfree(buff);
139 return -EINVAL;
140 }
141
142 if (mode & 1) {
143 for (i = 0; i < len ; i++)
144 buff[buf_size++] = data[i];
145 }
146 chk_sum = check_sum(&buff[1], buf_size);
147
148 buff[buf_size++] = chk_sum >> 8;
149 buff[0] = buf_size;
150 buff[buf_size++] = (chk_sum & 0xff);
151
152 ret = it913x_bulk_write(udev, buff, buf_size , 0x02);
153
154 ret |= it913x_bulk_read(udev, buff, (mode & 1) ?
155 5 : len + 5 , 0x01);
156
157 rlen = (mode & 0x1) ? 0x1 : len;
158
159 if (mode & 1)
160 ret |= buff[2];
161 else
162 memcpy(data, &buff[3], rlen);
163
164 cmd_counter++;
165
166 kfree(buff);
167
168 return (ret < 0) ? -ENODEV : 0;
169}
170
171static int it913x_wr_reg(struct usb_device *udev, u8 pro, u32 reg , u8 data)
172{
173 int ret;
174 u8 b[1];
175 b[0] = data;
176 ret = it913x_io(udev, WRITE_LONG, pro,
177 CMD_DEMOD_WRITE, reg, 0, b, sizeof(b));
178
179 return ret;
180}
181
182static int it913x_read_reg(struct usb_device *udev, u32 reg)
183{
184 int ret;
185 u8 data[1];
186
187 ret = it913x_io(udev, READ_LONG, DEV_0,
188 CMD_DEMOD_READ, reg, 0, &data[0], 1);
189
190 return (ret < 0) ? ret : data[0];
191}
192
193static u32 it913x_query(struct usb_device *udev, u8 pro)
194{
195 int ret;
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300196 u8 data[4];
197 ret = it913x_io(udev, READ_LONG, pro, CMD_DEMOD_READ,
Malcolm Priestleybc549192011-10-14 19:54:11 -0300198 0x1222, 0, &data[0], 3);
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300199
Malcolm Priestleybc549192011-10-14 19:54:11 -0300200 it913x_config.chip_ver = data[0];
201 it913x_config.chip_type = (u16)(data[2] << 8) + data[1];
202
203 info("Chip Version=%02x Chip Type=%04x", it913x_config.chip_ver,
204 it913x_config.chip_type);
205
206 ret |= it913x_io(udev, READ_SHORT, pro,
207 CMD_QUERYINFO, 0, 0x1, &data[0], 4);
208
209 it913x_config.firmware = (data[0] << 24) + (data[1] << 16) +
210 (data[2] << 8) + data[3];
211
212 return (ret < 0) ? 0 : it913x_config.firmware;
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300213}
214
215static int it913x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
216{
217 int ret = 0;
218 u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
219
220 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
221 return -EAGAIN;
222 deb_info(1, "PID_C (%02x)", onoff);
223
224 if (!onoff)
225 ret = it913x_wr_reg(adap->dev->udev, pro, PID_RST, 0x1);
226
227 mutex_unlock(&adap->dev->i2c_mutex);
228 return ret;
229}
230
231static int it913x_pid_filter(struct dvb_usb_adapter *adap,
232 int index, u16 pid, int onoff)
233{
234 struct usb_device *udev = adap->dev->udev;
235 int ret = 0;
236 u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
237
238 if (pid_filter > 0)
239 return 0;
240
241 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
242 return -EAGAIN;
243 deb_info(1, "PID_F (%02x)", onoff);
244 if (onoff) {
245 ret = it913x_wr_reg(udev, pro, PID_EN, 0x1);
246
247 ret |= it913x_wr_reg(udev, pro, PID_LSB, (u8)(pid & 0xff));
248
249 ret |= it913x_wr_reg(udev, pro, PID_MSB, (u8)(pid >> 8));
250
251 ret |= it913x_wr_reg(udev, pro, PID_INX_EN, (u8)onoff);
252
253 ret |= it913x_wr_reg(udev, pro, PID_INX, (u8)(index & 0x1f));
254
255 }
256
257 mutex_unlock(&adap->dev->i2c_mutex);
258 return 0;
259}
260
261
262static int it913x_return_status(struct usb_device *udev)
263{
264 u32 firm = 0;
265
266 firm = it913x_query(udev, DEV_0);
267 if (firm > 0)
268 info("Firmware Version %d", firm);
269
270 return (firm > 0) ? firm : 0;
271}
272
273static int it913x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
274 int num)
275{
276 struct dvb_usb_device *d = i2c_get_adapdata(adap);
277 static u8 data[256];
278 int ret;
279 u32 reg;
280 u8 pro;
281 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
282 return -EAGAIN;
283
284 debug_data_snipet(1, "Message out", msg[0].buf);
285 deb_info(2, "num of messages %d address %02x", num, msg[0].addr);
286
287 pro = (msg[0].addr & 0x2) ? DEV_0_DMOD : 0x0;
288 pro |= (msg[0].addr & 0x20) ? DEV_1 : DEV_0;
289 memcpy(data, msg[0].buf, msg[0].len);
290 reg = (data[0] << 24) + (data[1] << 16) +
291 (data[2] << 8) + data[3];
292 if (num == 2) {
293 ret = it913x_io(d->udev, READ_LONG, pro,
294 CMD_DEMOD_READ, reg, 0, data, msg[1].len);
295 memcpy(msg[1].buf, data, msg[1].len);
296 } else
297 ret = it913x_io(d->udev, WRITE_LONG, pro, CMD_DEMOD_WRITE,
298 reg, 0, &data[4], msg[0].len - 4);
299
300 mutex_unlock(&d->i2c_mutex);
301
302 return ret;
303}
304
305static u32 it913x_i2c_func(struct i2c_adapter *adapter)
306{
307 return I2C_FUNC_I2C;
308}
309
310static struct i2c_algorithm it913x_i2c_algo = {
311 .master_xfer = it913x_i2c_xfer,
312 .functionality = it913x_i2c_func,
313};
314
315/* Callbacks for DVB USB */
tvboxspy2ba0f942011-09-21 18:57:41 -0300316#define IT913X_POLL 250
317static int it913x_rc_query(struct dvb_usb_device *d)
318{
319 u8 ibuf[4];
320 int ret;
321 u32 key;
322 /* Avoid conflict with frontends*/
323 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
324 return -EAGAIN;
325
326 ret = it913x_io(d->udev, READ_LONG, PRO_LINK, CMD_IR_GET,
327 0, 0, &ibuf[0], sizeof(ibuf));
328
329 if ((ibuf[2] + ibuf[3]) == 0xff) {
330 key = ibuf[2];
331 key += ibuf[0] << 8;
332 deb_info(1, "INT Key =%08x", key);
333 if (d->rc_dev != NULL)
334 rc_keydown(d->rc_dev, key, 0);
335 }
336 mutex_unlock(&d->i2c_mutex);
337
338 return ret;
339}
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300340static int it913x_identify_state(struct usb_device *udev,
341 struct dvb_usb_device_properties *props,
342 struct dvb_usb_device_description **desc,
343 int *cold)
344{
345 int ret = 0, firm_no;
Malcolm Priestleybc549192011-10-14 19:54:11 -0300346 u8 reg, remote;
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300347
348 firm_no = it913x_return_status(udev);
349
Malcolm Priestleybc549192011-10-14 19:54:11 -0300350 /* checnk for dual mode */
351 it913x_config.dual_mode = it913x_read_reg(udev, 0x49c5);
352
353 /* TODO different remotes */
354 remote = it913x_read_reg(udev, 0x49ac); /* Remote */
355 if (remote == 0)
356 props->rc.core.rc_codes = NULL;
357
358 /* TODO at the moment tuner_id is always assigned to 0x38 */
359 it913x_config.tuner_id_0 = it913x_read_reg(udev, 0x49d0);
360
361 info("Dual mode=%x Remote=%x Tuner Type=%x", it913x_config.dual_mode
362 , remote, it913x_config.tuner_id_0);
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300363
364 if (firm_no > 0) {
365 *cold = 0;
366 return 0;
367 }
368
Malcolm Priestleybc549192011-10-14 19:54:11 -0300369 if (it913x_config.dual_mode) {
370 it913x_config.tuner_id_1 = it913x_read_reg(udev, 0x49e0);
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300371 ret = it913x_wr_reg(udev, DEV_0, GPIOH1_EN, 0x1);
372 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_ON, 0x1);
373 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x1);
Malcolm Priestleybc549192011-10-14 19:54:11 -0300374 msleep(50);
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300375 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x0);
376 msleep(50);
377 reg = it913x_read_reg(udev, GPIOH1_O);
378 if (reg == 0) {
379 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x1);
380 ret |= it913x_return_status(udev);
381 if (ret != 0)
382 ret = it913x_wr_reg(udev, DEV_0,
383 GPIOH1_O, 0x0);
Malcolm Priestleyb7d425d392011-10-31 12:02:08 -0300384 props->num_adapters = 2;
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300385 }
386 } else
387 props->num_adapters = 1;
388
389 reg = it913x_read_reg(udev, IO_MUX_POWER_CLK);
390
Malcolm Priestleybc549192011-10-14 19:54:11 -0300391 if (it913x_config.dual_mode) {
392 ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, CHIP2_I2C_ADDR);
393 ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x1);
394 } else {
395 ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, 0x0);
396 ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x0);
397 }
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300398
399 *cold = 1;
400
401 return (ret < 0) ? -ENODEV : 0;
402}
403
404static int it913x_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
405{
406 int ret = 0;
407 u8 pro = (adap->id == 0) ? DEV_0_DMOD : DEV_1_DMOD;
408
409 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
410 return -EAGAIN;
411 deb_info(1, "STM (%02x)", onoff);
412
413 if (!onoff)
414 ret = it913x_wr_reg(adap->dev->udev, pro, PID_RST, 0x1);
415
416
417 mutex_unlock(&adap->dev->i2c_mutex);
418
419 return ret;
420}
421
422
423static int it913x_download_firmware(struct usb_device *udev,
424 const struct firmware *fw)
425{
426 int ret = 0, i;
Malcolm Priestleybc549192011-10-14 19:54:11 -0300427 u8 packet_size, dlen;
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300428 u8 *fw_data;
429
430 packet_size = 0x29;
431
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300432 ret = it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_100);
433
434 info("FRM Starting Firmware Download");
435 /* This uses scatter write firmware headers follow */
436 /* 03 XX 00 XX = chip number? */
437
438 for (i = 0; i < fw->size; i += packet_size) {
439 if (i > 0)
440 packet_size = 0x39;
441 fw_data = (u8 *)(fw->data + i);
442 dlen = ((i + packet_size) > fw->size)
443 ? (fw->size - i) : packet_size;
444 ret |= it913x_io(udev, WRITE_DATA, DEV_0,
445 CMD_SCATTER_WRITE, 0, 0, fw_data, dlen);
446 udelay(1000);
447 }
448
449 ret |= it913x_io(udev, WRITE_CMD, DEV_0,
450 CMD_BOOT, 0, 0, NULL, 0);
451
452 msleep(100);
453
454 if (ret < 0)
455 info("FRM Firmware Download Failed (%04x)" , ret);
456 else
457 info("FRM Firmware Download Completed - Resetting Device");
458
459 ret |= it913x_return_status(udev);
460
461 msleep(30);
462
463 ret |= it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_400);
464
465 /* Tuner function */
Malcolm Priestleybc549192011-10-14 19:54:11 -0300466 if (it913x_config.dual_mode)
467 ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0xa0);
Malcolm Priestleyb7d425d392011-10-31 12:02:08 -0300468 else
469 ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0x68);
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300470
Malcolm Priestleyb7d425d392011-10-31 12:02:08 -0300471 if ((it913x_config.chip_ver == 1) &&
472 (it913x_config.chip_type == 0x9135)) {
473 ret |= it913x_wr_reg(udev, DEV_0, PADODPU, 0x0);
474 ret |= it913x_wr_reg(udev, DEV_0, AGC_O_D, 0x0);
475 if (it913x_config.dual_mode) {
476 ret |= it913x_wr_reg(udev, DEV_1, PADODPU, 0x0);
477 ret |= it913x_wr_reg(udev, DEV_1, AGC_O_D, 0x0);
478 }
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300479 }
480
481 return (ret < 0) ? -ENODEV : 0;
482}
483
484static int it913x_name(struct dvb_usb_adapter *adap)
485{
486 const char *desc = adap->dev->desc->name;
487 char *fe_name[] = {"_1", "_2", "_3", "_4"};
Michael Krufky77eed212011-09-06 09:31:57 -0300488 char *name = adap->fe_adap[0].fe->ops.info.name;
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300489
490 strlcpy(name, desc, 128);
491 strlcat(name, fe_name[adap->id], 128);
492
493 return 0;
494}
495
496static int it913x_frontend_attach(struct dvb_usb_adapter *adap)
497{
498 struct usb_device *udev = adap->dev->udev;
499 int ret = 0;
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300500 u8 adap_addr = I2C_BASE_ADDR + (adap->id << 5);
Michael Krufky77eed212011-09-06 09:31:57 -0300501 u16 ep_size = adap->props.fe[0].stream.u.bulk.buffersize;
Malcolm Priestleybc549192011-10-14 19:54:11 -0300502
Malcolm Priestleyb7d425d392011-10-31 12:02:08 -0300503 it913x_config.adf = it913x_read_reg(udev, IO_MUX_POWER_CLK);
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300504
Michael Krufky77eed212011-09-06 09:31:57 -0300505 adap->fe_adap[0].fe = dvb_attach(it913x_fe_attach,
Malcolm Priestleyb7d425d392011-10-31 12:02:08 -0300506 &adap->dev->i2c_adap, adap_addr, &it913x_config);
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300507
Michael Krufky77eed212011-09-06 09:31:57 -0300508 if (adap->id == 0 && adap->fe_adap[0].fe) {
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300509 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x1);
510 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_SW_RST, 0x1);
511 ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x0f);
512 ret = it913x_wr_reg(udev, DEV_0, EP0_TX_NAK, 0x1b);
513 ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x2f);
514 ret = it913x_wr_reg(udev, DEV_0, EP4_TX_LEN_LSB,
515 ep_size & 0xff);
516 ret = it913x_wr_reg(udev, DEV_0, EP4_TX_LEN_MSB, ep_size >> 8);
517 ret = it913x_wr_reg(udev, DEV_0, EP4_MAX_PKT, 0x80);
Michael Krufky77eed212011-09-06 09:31:57 -0300518 } else if (adap->id == 1 && adap->fe_adap[0].fe) {
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300519 ret = it913x_wr_reg(udev, DEV_0, EP0_TX_EN, 0x6f);
520 ret = it913x_wr_reg(udev, DEV_0, EP5_TX_LEN_LSB,
521 ep_size & 0xff);
522 ret = it913x_wr_reg(udev, DEV_0, EP5_TX_LEN_MSB, ep_size >> 8);
523 ret = it913x_wr_reg(udev, DEV_0, EP5_MAX_PKT, 0x80);
524 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_EN, 0x1);
525 ret = it913x_wr_reg(udev, DEV_1_DMOD, MP2IF_SERIAL, 0x1);
526 ret = it913x_wr_reg(udev, DEV_1, TOP_HOSTB_SER_MODE, 0x1);
527 ret = it913x_wr_reg(udev, DEV_0_DMOD, TSIS_ENABLE, 0x1);
528 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x0);
529 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_SW_RST, 0x0);
530 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF2_HALF_PSB, 0x0);
531 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2IF_STOP_EN, 0x1);
532 ret = it913x_wr_reg(udev, DEV_1_DMOD, MPEG_FULL_SPEED, 0x0);
533 ret = it913x_wr_reg(udev, DEV_1_DMOD, MP2IF_STOP_EN, 0x0);
534 } else
535 return -ENODEV;
536
537 ret = it913x_name(adap);
538
539 return ret;
540}
541
542/* DVB USB Driver */
543static struct dvb_usb_device_properties it913x_properties;
544
545static int it913x_probe(struct usb_interface *intf,
546 const struct usb_device_id *id)
547{
548 cmd_counter = 0;
549 if (0 == dvb_usb_device_init(intf, &it913x_properties,
550 THIS_MODULE, NULL, adapter_nr)) {
551 info("DEV registering device driver");
552 return 0;
553 }
554
555 info("DEV it913x Error");
556 return -ENODEV;
557
558}
559
560static struct usb_device_id it913x_table[] = {
561 { USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB499_2T_T09) },
Malcolm Priestleybc549192011-10-14 19:54:11 -0300562 { USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135) },
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300563 {} /* Terminating entry */
564};
565
566MODULE_DEVICE_TABLE(usb, it913x_table);
567
568static struct dvb_usb_device_properties it913x_properties = {
569 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
570 .usb_ctrl = DEVICE_SPECIFIC,
571 .download_firmware = it913x_download_firmware,
572 .firmware = "dvb-usb-it9137-01.fw",
573 .no_reconnect = 1,
574 .size_of_priv = sizeof(struct it913x_state),
575 .num_adapters = 2,
576 .adapter = {
577 {
Michael Krufky77eed212011-09-06 09:31:57 -0300578 .num_frontends = 1,
579 .fe = {{
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300580 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
581 DVB_USB_ADAP_NEED_PID_FILTERING|
582 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
583 .streaming_ctrl = it913x_streaming_ctrl,
584 .pid_filter_count = 31,
585 .pid_filter = it913x_pid_filter,
586 .pid_filter_ctrl = it913x_pid_filter_ctrl,
587 .frontend_attach = it913x_frontend_attach,
588 /* parameter for the MPEG2-data transfer */
589 .stream = {
590 .type = USB_BULK,
591 .count = 10,
592 .endpoint = 0x04,
593 .u = {/* Keep Low if PID filter on */
594 .bulk = {
595 .buffersize = 3584,
596
597 }
598 }
599 }
Michael Krufky77eed212011-09-06 09:31:57 -0300600 }},
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300601 },
602 {
Michael Krufky77eed212011-09-06 09:31:57 -0300603 .num_frontends = 1,
604 .fe = {{
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300605 .caps = DVB_USB_ADAP_HAS_PID_FILTER|
606 DVB_USB_ADAP_NEED_PID_FILTERING|
607 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
608 .streaming_ctrl = it913x_streaming_ctrl,
609 .pid_filter_count = 31,
610 .pid_filter = it913x_pid_filter,
611 .pid_filter_ctrl = it913x_pid_filter_ctrl,
612 .frontend_attach = it913x_frontend_attach,
613 /* parameter for the MPEG2-data transfer */
614 .stream = {
615 .type = USB_BULK,
616 .count = 5,
617 .endpoint = 0x05,
618 .u = {
619 .bulk = {
620 .buffersize = 3584,
621
622 }
623 }
624 }
Michael Krufky77eed212011-09-06 09:31:57 -0300625 }},
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300626 }
627 },
628 .identify_state = it913x_identify_state,
tvboxspy2ba0f942011-09-21 18:57:41 -0300629 .rc.core = {
630 .protocol = RC_TYPE_NEC,
631 .module_name = "it913x",
632 .rc_query = it913x_rc_query,
633 .rc_interval = IT913X_POLL,
634 .allowed_protos = RC_TYPE_NEC,
635 .rc_codes = RC_MAP_KWORLD_315U,
636 },
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300637 .i2c_algo = &it913x_i2c_algo,
Malcolm Priestleybc549192011-10-14 19:54:11 -0300638 .num_device_descs = 2,
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300639 .devices = {
640 { "Kworld UB499-2T T09(IT9137)",
641 { &it913x_table[0], NULL },
642 },
Malcolm Priestleybc549192011-10-14 19:54:11 -0300643 { "ITE 9135 Generic",
644 { &it913x_table[1], NULL },
645 },
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300646 }
647};
648
649static struct usb_driver it913x_driver = {
650 .name = "it913x",
651 .probe = it913x_probe,
652 .disconnect = dvb_usb_device_exit,
653 .id_table = it913x_table,
654};
655
656/* module stuff */
657static int __init it913x_module_init(void)
658{
659 int result = usb_register(&it913x_driver);
660 if (result) {
661 err("usb_register failed. Error number %d", result);
662 return result;
663 }
664
665 return 0;
666}
667
668static void __exit it913x_module_exit(void)
669{
670 /* deregister this driver from the USB subsystem */
671 usb_deregister(&it913x_driver);
672}
673
674module_init(it913x_module_init);
675module_exit(it913x_module_exit);
676
677MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
678MODULE_DESCRIPTION("it913x USB 2 Driver");
Malcolm Priestleyb7d425d392011-10-31 12:02:08 -0300679MODULE_VERSION("1.08");
Malcolm Priestleyf6d87352011-07-25 15:35:03 -0300680MODULE_LICENSE("GPL");