blob: 6a21f928550a944774aca82bde4ada47ba4ff5cb [file] [log] [blame]
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -03001/* DVB USB compliant Linux driver for the AzureWave 6017 USB2.0 DVB-S
2 * receiver.
3 * see Documentation/dvb/README.dvb-usb for more information
4 */
5
6#include "az6007.h"
7#include "drxk.h"
8#include "mt2063.h"
9#include "dvb_ca_en50221.h"
10
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030011/* HACK: Should be moved to the right place */
12#define USB_PID_AZUREWAVE_6007 0xccd
13#define USB_PID_TERRATEC_H7 0x10b4
14
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030015/* debug */
16int dvb_usb_az6007_debug;
17module_param_named(debug,dvb_usb_az6007_debug, int, 0644);
18MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
19
20
21static int az6007_type =0;
22module_param(az6007_type, int, 0644);
23MODULE_PARM_DESC(az6007_type, "select delivery mode (0=DVB-T, 1=DVB-T");
24
25//module_param_named(type, 6007_type, int, 0644);
26//MODULE_PARM_DESC(type, "select delivery mode (0=DVB-T, 1=DVB-C)");
27
28DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
29
30
31struct az6007_device_state {
32 struct dvb_ca_en50221 ca;
33 struct mutex ca_mutex;
34 u8 power_state;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030035
36 /* Due to DRX-K - probably need changes */
37 int (*gate_ctrl)(struct dvb_frontend *, int);
38 struct semaphore pll_mutex;
39 bool dont_attach_fe1;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030040};
41
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030042struct drxk_config terratec_h7_drxk = {
43 .adr = 0x29,
44 .single_master = 1,
45 .no_i2c_bridge = 1,
46 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030047};
48
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030049static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
50{
51 struct dvb_usb_adapter *adap = fe->sec_priv;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -030052 struct az6007_device_state *st;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030053 int status;
54
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -030055 info("%s", __func__);
56
57 if (!adap)
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030058 return -EINVAL;
59
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -030060 st = adap->priv;
61
62 if (!st)
63 return -EINVAL;
64
65
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030066 if (enable) {
67 down(&st->pll_mutex);
68 status = st->gate_ctrl(fe, 1);
69 } else {
70 status = st->gate_ctrl(fe, 0);
71 up(&st->pll_mutex);
72 }
73 return status;
74}
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030075
76struct mt2063_config az6007_mt2063_config = {
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -030077 .tuner_address = 0x60,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030078 .refclock = 36125000,
79};
80
81/* check for mutex FIXME */
82int az6007_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen)
83{
84 int ret = -1;
85
86 ret = usb_control_msg(d->udev,
87 usb_rcvctrlpipe(d->udev,0),
88 req,
89 USB_TYPE_VENDOR | USB_DIR_IN,
90 value,index,b,blen,
91 5000);
92
93 if (ret < 0) {
94 warn("usb in operation failed. (%d)", ret);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -030095 return -EIO;
96 }
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030097
98 deb_xfer("in: req. %02x, val: %04x, ind: %04x, buffer: ",req,value,index);
99 debug_dump(b,blen,deb_xfer);
100
101 return ret;
102}
103
104static int az6007_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
105 u16 index, u8 *b, int blen)
106{
107 int ret;
108
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300109#if 0
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300110 int i=0, cyc=0, rem=0;
111 cyc = blen/64;
112 rem = blen%64;
113#endif
114
115 deb_xfer("out: req. %02x, val: %04x, ind: %04x, buffer: ",req,value,index);
116 debug_dump(b,blen,deb_xfer);
117
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300118
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300119#if 0
120 if (blen>64)
121 {
122 for (i=0; i<cyc; i++)
123 {
124 if ((ret = usb_control_msg(d->udev,
125 usb_sndctrlpipe(d->udev,0),
126 req,
127 USB_TYPE_VENDOR | USB_DIR_OUT,
128 value,index+i*64,b+i*64,64,
129 5000)) != 64) {
130 warn("usb out operation failed. (%d)",ret);
131 return -EIO;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300132 }
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300133 }
134
135 if (rem>0)
136 {
137 if ((ret = usb_control_msg(d->udev,
138 usb_sndctrlpipe(d->udev,0),
139 req,
140 USB_TYPE_VENDOR | USB_DIR_OUT,
141 value,index+cyc*64,b+cyc*64,rem,
142 5000)) != rem) {
143 warn("usb out operation failed. (%d)",ret);
144 return -EIO;
145 }
146 }
147 }
148 else
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300149#endif
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300150 {
151 if ((ret = usb_control_msg(d->udev,
152 usb_sndctrlpipe(d->udev,0),
153 req,
154 USB_TYPE_VENDOR | USB_DIR_OUT,
155 value,index,b,blen,
156 5000)) != blen) {
157 warn("usb out operation failed. (%d)",ret);
158 return -EIO;
159 }
160 }
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300161
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300162 return 0;
163}
164
165static int az6007_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
166{
167 return 0;
168}
169
170/* keys for the enclosed remote control */
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300171struct rc_map_table rc_map_az6007_table[] = {
172 { 0x0001, KEY_1 },
173 { 0x0002, KEY_2 },
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300174};
175
176/* remote control stuff (does not work with my box) */
177static int az6007_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
178{
179 return 0;
180#if 0
181 u8 key[10];
182 int i;
183
184/* remove the following return to enabled remote querying */
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300185
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300186
187 az6007_usb_in_op(d,READ_REMOTE_REQ,0,0,key,10);
188
189 deb_rc("remote query key: %x %d\n",key[1],key[1]);
190
191 if (key[1] == 0x44) {
192 *state = REMOTE_NO_KEY_PRESSED;
193 return 0;
194 }
195
196 for (i = 0; i < ARRAY_SIZE(az6007_rc_keys); i++)
197 if (az6007_rc_keys[i].custom == key[1]) {
198 *state = REMOTE_KEY_PRESSED;
199 *event = az6007_rc_keys[i].event;
200 break;
201 }
202 return 0;
203#endif
204}
205
206/*
207int az6007_power_ctrl(struct dvb_usb_device *d, int onoff)
208{
209 u8 v = onoff;
210 return az6007_usb_out_op(d,0xBC,v,3,NULL,1);
211}
212*/
213
214static int az6007_read_mac_addr(struct dvb_usb_device *d,u8 mac[6])
215{
216 az6007_usb_in_op(d, 0xb7, 6, 0, &mac[0], 6);
217 return 0;
218}
219
220static int az6007_frontend_poweron(struct dvb_usb_adapter *adap)
221{
222 int ret;
223 u8 req;
224 u16 value;
225 u16 index;
226 int blen;
227
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300228 info("az6007_frontend_poweron adap=%p adap->dev=%p", adap, adap->dev);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300229
230 req = 0xBC;
231 value = 1;//power on
232 index = 3;
233 blen =0;
234
235 if((ret = az6007_usb_out_op(adap->dev,req,value,index,NULL,blen)) != 0)
236 {
237 err("az6007_frontend_poweron failed!!!");
238 return -EIO;
239 }
240
241 msleep_interruptible(200);
242
243 req = 0xBC;
244 value = 0;//power on
245 index = 3;
246 blen =0;
247
248 if((ret = az6007_usb_out_op(adap->dev,req,value,index,NULL,blen)) != 0)
249 {
250 err("az6007_frontend_poweron failed!!!");
251 return -EIO;
252 }
253
254 msleep_interruptible(200);
255
256 req = 0xBC;
257 value = 1;//power on
258 index = 3;
259 blen =0;
260
261 if((ret = az6007_usb_out_op(adap->dev,req,value,index,NULL,blen)) != 0)
262 {
263 err("az6007_frontend_poweron failed!!!");
264 return -EIO;
265 }
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300266 info("az6007_frontend_poweron: OK");
267
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300268 return 0;
269}
270
271static int az6007_frontend_reset(struct dvb_usb_adapter *adap)
272{
273 int ret;
274 u8 req;
275 u16 value;
276 u16 index;
277 int blen;
278
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300279 info("az6007_frontend_reset adap=%p adap->dev=%p", adap, adap->dev);
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300280
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300281 //reset demodulator
282 req = 0xC0;
283 value = 1;//high
284 index = 3;
285 blen =0;
286 if((ret = az6007_usb_out_op(adap->dev,req,value,index,NULL,blen)) != 0)
287 {
288 err("az6007_frontend_reset failed 1 !!!");
289 return -EIO;
290 }
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300291
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300292 req = 0xC0;
293 value = 0;//low
294 index = 3;
295 blen =0;
296 msleep_interruptible(200);
297 if((ret = az6007_usb_out_op(adap->dev,req,value,index,NULL,blen)) != 0)
298 {
299 err("az6007_frontend_reset failed 2 !!!");
300 return -EIO;
301 }
302 msleep_interruptible(200);
303 req = 0xC0;
304 value = 1;//high
305 index = 3;
306 blen =0;
307
308 if((ret = az6007_usb_out_op(adap->dev,req,value,index,NULL,blen)) != 0)
309 {
310 err("az6007_frontend_reset failed 3 !!!");
311 return -EIO;
312 }
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300313
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300314 msleep_interruptible(200);
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300315
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300316 info("reset az6007 frontend");
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300317
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300318 return 0;
319}
320
321static int az6007_led_on_off(struct usb_interface *intf, int onoff)
322{
323 int ret = -1;
324 u8 req;
325 u16 value;
326 u16 index;
327 int blen;
328 //TS through
329 req = 0xBC;
330 value = onoff;
331 index = 0;
332 blen =0;
333
334 ret = usb_control_msg(interface_to_usbdev(intf),
335 usb_rcvctrlpipe(interface_to_usbdev(intf),0),
336 req,
337 USB_TYPE_VENDOR | USB_DIR_OUT,
338 value,index,NULL,blen,
339 2000);
340
341 if (ret < 0) {
342 warn("usb in operation failed. (%d)", ret);
343 ret = -EIO;
344 } else
345 ret = 0;
346
347
348 deb_xfer("in: req. %02x, val: %04x, ind: %04x, buffer: ",req,value,index);
349
350 return ret;
351}
352
353static int az6007_frontend_tsbypass(struct dvb_usb_adapter *adap,int onoff)
354{
355 int ret;
356 u8 req;
357 u16 value;
358 u16 index;
359 int blen;
360 //TS through
361 req = 0xC7;
362 value = onoff;
363 index = 0;
364 blen =0;
365
366 if((ret = az6007_usb_out_op(adap->dev,req,value,index,NULL,blen)) != 0)
367 return -EIO;
368 return 0;
369}
370
371static int az6007_frontend_attach(struct dvb_usb_adapter *adap)
372{
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300373 struct az6007_device_state *st = adap->priv;
374
375 int result;
376
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300377 BUG_ON(!st);
378
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300379 az6007_frontend_poweron(adap);
380 az6007_frontend_reset(adap);
381
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300382 info("az6007_frontend_attach: drxk");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300383
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300384 adap->fe = dvb_attach(drxk_attach, &terratec_h7_drxk,
385 &adap->dev->i2c_adap, &adap->fe2);
386 if (!adap->fe) {
387 result = -EINVAL;
388 goto out_free;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300389 }
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300390
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300391 info("Setting hacks");
392
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300393 /* FIXME: do we need a pll semaphore? */
394 adap->fe->sec_priv = adap;
395 sema_init(&st->pll_mutex, 1);
396 st->gate_ctrl = adap->fe->ops.i2c_gate_ctrl;
397 adap->fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
398 adap->fe2->id = 1;
399
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300400 info("az6007_frontend_attach: mt2063");
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300401 /* Attach mt2063 to DVB-C frontend */
402 if (adap->fe->ops.i2c_gate_ctrl)
403 adap->fe->ops.i2c_gate_ctrl(adap->fe, 1);
404 if (!dvb_attach(mt2063_attach, adap->fe, &az6007_mt2063_config,
405 &adap->dev->i2c_adap)) {
406 result = -EINVAL;
407
408 goto out_free;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300409 }
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300410 if (adap->fe->ops.i2c_gate_ctrl)
411 adap->fe->ops.i2c_gate_ctrl(adap->fe, 0);
412
413 /* Hack - needed due to drxk */
414 adap->fe2->tuner_priv = adap->fe->tuner_priv;
415 memcpy(&adap->fe2->ops.tuner_ops,
416 &adap->fe->ops.tuner_ops,
417 sizeof(adap->fe->ops.tuner_ops));
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300418 return 0;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300419
420out_free:
421 if (adap->fe)
422 dvb_frontend_detach(adap->fe);
423 adap->fe = NULL;
424 adap->fe2 = NULL;
425
426 return result;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300427}
428
429static struct dvb_usb_device_properties az6007_properties;
430
431static void
432az6007_usb_disconnect(struct usb_interface *intf)
433{
434 dvb_usb_device_exit (intf);
435}
436
437/* I2C */
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300438static int az6007_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msgs[],int num)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300439{
440 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300441 int i, j, len;
442 int ret = 0;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300443 u16 index;
444 u16 value;
445 int length;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300446 u8 req, addr;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300447 u8 data[512];
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300448
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300449 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
450 return -EAGAIN;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300451
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300452 for (i = 0; i < num; i++) {
453 addr = msgs[i].addr << 1;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300454
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300455 if (((i + 1) < num)
456 && (msgs[i].len == 1)
457 && (!msgs[i].flags & I2C_M_RD)
458 && (msgs[i + 1].flags & I2C_M_RD)
459 && (msgs[i].addr == msgs[i + 1].addr)) {
460 /*
461 * A write + read xfer for the same address, where
462 * the first xfer has just 1 byte length.
463 * Need to join both into one operation
464 */
465 printk("az6007 I2C xfer write+read addr=0x%x len=%d/%d: ",
466 addr, msgs[i].len, msgs[i + 1].len);
467 req = 0xb9;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300468 index = 0;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300469 value = addr;
470 for (j = 0; j < msgs[i].len; j++)
471 data[j] = msgs[i].buf[j];
472 length = 6 + msgs[i + 1].len;
473 len = msgs[i + 1].len;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300474 ret = az6007_usb_in_op(d,req,value,index,data,length);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300475 if (ret >= len) {
476 for (j = 0; j < len; j++) {
477 msgs[i + 1].buf[j] = data[j + 5];
478 printk("0x%02x ", msgs[i + 1].buf[j]);
479 }
480 } else
481 ret = -EIO;
482 i++;
483 } else if (!(msgs[i].flags & I2C_M_RD)) {
484 /* write bytes */
485// printk("az6007 I2C xfer write addr=0x%x len=%d: ",
486// addr, msgs[i].len);
487 req = 0xbd;
488 index = msgs[i].buf[0];
489 value = addr | (1 << 8);
490 length = msgs[i].len - 1;
491 len = msgs[i].len - 1;
492// printk("(0x%02x) ", msgs[i].buf[0]);
493 for (j = 0; j < len; j++)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300494 {
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300495 data[j] = msgs[i].buf[j + 1];
496// printk("0x%02x ", data[j]);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300497 }
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300498 ret = az6007_usb_out_op(d,req,value,index,data,length);
499 } else {
500 /* read bytes */
501// printk("az6007 I2C xfer read addr=0x%x len=%d: ",
502// addr, msgs[i].len);
503 req = 0xb9;
504 index = msgs[i].buf[0];
505 value = addr;
506 length = msgs[i].len + 6;
507 len = msgs[i].len;
508 ret = az6007_usb_in_op(d,req,value,index,data,length);
509 for (j = 0; j < len; j++)
510 {
511 msgs[i].buf[j] = data[j + 5];
512// printk("0x%02x ", data[j + 5]);
513 }
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300514 }
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300515// printk("\n");
516 if (ret < 0)
517 goto err;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300518 }
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300519err:
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300520 mutex_unlock(&d->i2c_mutex);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300521
522 if (ret < 0) {
523 info("%s ERROR: %i\n", __func__, ret);
524 return ret;
525 }
526 return num;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300527}
528
529
530static u32 az6007_i2c_func(struct i2c_adapter *adapter)
531{
532 return I2C_FUNC_I2C;
533}
534
535static struct i2c_algorithm az6007_i2c_algo = {
536 .master_xfer = az6007_i2c_xfer,
537 .functionality = az6007_i2c_func,
538#ifdef NEED_ALGO_CONTROL
539 .algo_control = dummy_algo_control,
540#endif
541};
542
543int az6007_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props,
544 struct dvb_usb_device_description **desc, int *cold)
545{
546 u8 b[16];
547 s16 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev,0),
548 0xb7, USB_TYPE_VENDOR | USB_DIR_IN, 6, 0, b, 6, USB_CTRL_GET_TIMEOUT);
549
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300550 info("FW GET_VERSION length: %d",ret);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300551
552 *cold = ret <= 0;
553
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300554 info("cold: %d", *cold);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300555 return 0;
556}
557
558static int az6007_usb_probe(struct usb_interface *intf,
559 const struct usb_device_id *id)
560{
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300561 az6007_led_on_off(intf, 0);
562
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300563 return dvb_usb_device_init(intf, &az6007_properties,
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300564 THIS_MODULE, NULL, adapter_nr);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300565}
566
567static struct usb_device_id az6007_usb_table [] = {
568 { USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_6007) },
569 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_H7) },
570 { 0 },
571};
572
573MODULE_DEVICE_TABLE(usb, az6007_usb_table);
574
575static struct dvb_usb_device_properties az6007_properties = {
576 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
577 .usb_ctrl = CYPRESS_FX2,
578 //.download_firmware = az6007_download_firmware,
579 .firmware = "dvb-usb-az6007-03.fw",
580 .no_reconnect = 1,
581
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300582 .identify_state = az6007_identify_state,
583 .num_adapters = 1,
584 .adapter = {
585 {
586 //.caps = DVB_USB_ADAP_RECEIVES_204_BYTE_TS,
587
588 .streaming_ctrl = az6007_streaming_ctrl,
589 .frontend_attach = az6007_frontend_attach,
590
591 /* parameter for the MPEG2-data transfer */
592 .stream = {
593 .type = USB_BULK,
594 .count = 10,
595 .endpoint = 0x02,
596 .u = {
597 .bulk = {
598 .buffersize = 4096,
599 }
600 }
601 },
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300602 .size_of_priv = sizeof(struct az6007_device_state),
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300603 }
604 },
605 //.power_ctrl = az6007_power_ctrl,
606 .read_mac_address = az6007_read_mac_addr,
607
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300608 .rc.legacy = {
609 .rc_map_table = rc_map_az6007_table,
610 .rc_map_size = ARRAY_SIZE(rc_map_az6007_table),
611 .rc_interval = 400,
612 .rc_query = az6007_rc_query,
613 },
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300614 .i2c_algo = &az6007_i2c_algo,
615
616 .num_device_descs = 2,
617 .devices = {
618 { .name = "AzureWave DTV StarBox DVB-T/C USB2.0 (az6007)",
619 .cold_ids = { &az6007_usb_table[0], NULL },
620 .warm_ids = { NULL },
621 },
622 { .name = "TerraTec DTV StarBox DVB-T/C USB2.0 (az6007)",
623 .cold_ids = { &az6007_usb_table[1], NULL },
624 .warm_ids = { NULL },
625 },
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300626 { NULL },
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300627 }
628};
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300629
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300630/* usb specific object needed to register this driver with the usb subsystem */
631static struct usb_driver az6007_usb_driver = {
632 .name = "dvb_usb_az6007",
633 .probe = az6007_usb_probe,
634 .disconnect = dvb_usb_device_exit,
635 //.disconnect = az6007_usb_disconnect,
636 .id_table = az6007_usb_table,
637};
638
639/* module stuff */
640static int __init az6007_usb_module_init(void)
641{
642 int result;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300643 info("az6007 usb module init");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300644 if ((result = usb_register(&az6007_usb_driver))) {
645 err("usb_register failed. (%d)",result);
646 return result;
647 }
648
649 return 0;
650}
651
652static void __exit az6007_usb_module_exit(void)
653{
654 /* deregister this driver from the USB subsystem */
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300655 info("az6007 usb module exit");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300656 usb_deregister(&az6007_usb_driver);
657}
658
659module_init(az6007_usb_module_init);
660module_exit(az6007_usb_module_exit);
661
662MODULE_AUTHOR("Henry Wang <Henry.wang@AzureWave.com>");
663MODULE_DESCRIPTION("Driver for AzureWave 6007 DVB-C/T USB2.0 and clones");
664MODULE_VERSION("1.0");
665MODULE_LICENSE("GPL");