blob: 56126d41a604343c9847158d5f26decf5f36dd9d [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,
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -030045 .no_i2c_bridge = 0,
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030046 .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 Chehabcaa1a702011-07-22 10:31:25 -0300454 if (((i + 1) < num)
455 && (msgs[i].len == 1)
456 && (!msgs[i].flags & I2C_M_RD)
457 && (msgs[i + 1].flags & I2C_M_RD)
458 && (msgs[i].addr == msgs[i + 1].addr)) {
459 /*
460 * A write + read xfer for the same address, where
461 * the first xfer has just 1 byte length.
462 * Need to join both into one operation
463 */
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300464 if (dvb_usb_az6007_debug & 2)
465 printk(KERN_DEBUG
466 "az6007 I2C xfer write+read addr=0x%x len=%d/%d: ",
467 addr, msgs[i].len, msgs[i + 1].len);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300468 req = 0xb9;
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300469 index = msgs[i].buf[0];
470 value = addr | (1 << 8);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300471 length = 6 + msgs[i + 1].len;
472 len = msgs[i + 1].len;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300473 ret = az6007_usb_in_op(d,req,value,index,data,length);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300474 if (ret >= len) {
475 for (j = 0; j < len; j++) {
476 msgs[i + 1].buf[j] = data[j + 5];
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300477 if (dvb_usb_az6007_debug & 2)
478 printk(KERN_CONT
479 "0x%02x ",
480 msgs[i + 1].buf[j]);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300481 }
482 } else
483 ret = -EIO;
484 i++;
485 } else if (!(msgs[i].flags & I2C_M_RD)) {
486 /* write bytes */
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300487 if (dvb_usb_az6007_debug & 2)
488 printk(KERN_DEBUG
489 "az6007 I2C xfer write addr=0x%x len=%d: ",
490 addr, msgs[i].len);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300491 req = 0xbd;
492 index = msgs[i].buf[0];
493 value = addr | (1 << 8);
494 length = msgs[i].len - 1;
495 len = msgs[i].len - 1;
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300496 if (dvb_usb_az6007_debug & 2)
497 printk(KERN_CONT
498 "(0x%02x) ", msgs[i].buf[0]);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300499 for (j = 0; j < len; j++)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300500 {
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300501 data[j] = msgs[i].buf[j + 1];
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300502 if (dvb_usb_az6007_debug & 2)
503 printk(KERN_CONT
504 "0x%02x ", data[j]);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300505 }
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300506 ret = az6007_usb_out_op(d,req,value,index,data,length);
507 } else {
508 /* read bytes */
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300509 if (dvb_usb_az6007_debug & 2)
510 printk(KERN_DEBUG
511 "az6007 I2C xfer read addr=0x%x len=%d: ",
512 addr, msgs[i].len);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300513 req = 0xb9;
514 index = msgs[i].buf[0];
515 value = addr;
516 length = msgs[i].len + 6;
517 len = msgs[i].len;
518 ret = az6007_usb_in_op(d,req,value,index,data,length);
519 for (j = 0; j < len; j++)
520 {
521 msgs[i].buf[j] = data[j + 5];
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300522 if (dvb_usb_az6007_debug & 2)
523 printk(KERN_CONT
524 "0x%02x ", data[j + 5]);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300525 }
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300526 }
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300527 if (dvb_usb_az6007_debug & 2)
528 printk(KERN_CONT "\n");
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300529 if (ret < 0)
530 goto err;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300531 }
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300532err:
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300533 mutex_unlock(&d->i2c_mutex);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300534
535 if (ret < 0) {
536 info("%s ERROR: %i\n", __func__, ret);
537 return ret;
538 }
539 return num;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300540}
541
542
543static u32 az6007_i2c_func(struct i2c_adapter *adapter)
544{
545 return I2C_FUNC_I2C;
546}
547
548static struct i2c_algorithm az6007_i2c_algo = {
549 .master_xfer = az6007_i2c_xfer,
550 .functionality = az6007_i2c_func,
551#ifdef NEED_ALGO_CONTROL
552 .algo_control = dummy_algo_control,
553#endif
554};
555
556int az6007_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props,
557 struct dvb_usb_device_description **desc, int *cold)
558{
559 u8 b[16];
560 s16 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev,0),
561 0xb7, USB_TYPE_VENDOR | USB_DIR_IN, 6, 0, b, 6, USB_CTRL_GET_TIMEOUT);
562
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300563 info("FW GET_VERSION length: %d",ret);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300564
565 *cold = ret <= 0;
566
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300567 info("cold: %d", *cold);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300568 return 0;
569}
570
571static int az6007_usb_probe(struct usb_interface *intf,
572 const struct usb_device_id *id)
573{
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300574 az6007_led_on_off(intf, 0);
575
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300576 return dvb_usb_device_init(intf, &az6007_properties,
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300577 THIS_MODULE, NULL, adapter_nr);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300578}
579
580static struct usb_device_id az6007_usb_table [] = {
581 { USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_6007) },
582 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_H7) },
583 { 0 },
584};
585
586MODULE_DEVICE_TABLE(usb, az6007_usb_table);
587
588static struct dvb_usb_device_properties az6007_properties = {
589 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
590 .usb_ctrl = CYPRESS_FX2,
591 //.download_firmware = az6007_download_firmware,
592 .firmware = "dvb-usb-az6007-03.fw",
593 .no_reconnect = 1,
594
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300595 .identify_state = az6007_identify_state,
596 .num_adapters = 1,
597 .adapter = {
598 {
599 //.caps = DVB_USB_ADAP_RECEIVES_204_BYTE_TS,
600
601 .streaming_ctrl = az6007_streaming_ctrl,
602 .frontend_attach = az6007_frontend_attach,
603
604 /* parameter for the MPEG2-data transfer */
605 .stream = {
606 .type = USB_BULK,
607 .count = 10,
608 .endpoint = 0x02,
609 .u = {
610 .bulk = {
611 .buffersize = 4096,
612 }
613 }
614 },
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300615 .size_of_priv = sizeof(struct az6007_device_state),
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300616 }
617 },
618 //.power_ctrl = az6007_power_ctrl,
619 .read_mac_address = az6007_read_mac_addr,
620
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300621 .rc.legacy = {
622 .rc_map_table = rc_map_az6007_table,
623 .rc_map_size = ARRAY_SIZE(rc_map_az6007_table),
624 .rc_interval = 400,
625 .rc_query = az6007_rc_query,
626 },
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300627 .i2c_algo = &az6007_i2c_algo,
628
629 .num_device_descs = 2,
630 .devices = {
631 { .name = "AzureWave DTV StarBox DVB-T/C USB2.0 (az6007)",
632 .cold_ids = { &az6007_usb_table[0], NULL },
633 .warm_ids = { NULL },
634 },
635 { .name = "TerraTec DTV StarBox DVB-T/C USB2.0 (az6007)",
636 .cold_ids = { &az6007_usb_table[1], NULL },
637 .warm_ids = { NULL },
638 },
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300639 { NULL },
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300640 }
641};
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300642
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300643/* usb specific object needed to register this driver with the usb subsystem */
644static struct usb_driver az6007_usb_driver = {
645 .name = "dvb_usb_az6007",
646 .probe = az6007_usb_probe,
647 .disconnect = dvb_usb_device_exit,
648 //.disconnect = az6007_usb_disconnect,
649 .id_table = az6007_usb_table,
650};
651
652/* module stuff */
653static int __init az6007_usb_module_init(void)
654{
655 int result;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300656 info("az6007 usb module init");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300657 if ((result = usb_register(&az6007_usb_driver))) {
658 err("usb_register failed. (%d)",result);
659 return result;
660 }
661
662 return 0;
663}
664
665static void __exit az6007_usb_module_exit(void)
666{
667 /* deregister this driver from the USB subsystem */
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300668 info("az6007 usb module exit");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300669 usb_deregister(&az6007_usb_driver);
670}
671
672module_init(az6007_usb_module_init);
673module_exit(az6007_usb_module_exit);
674
675MODULE_AUTHOR("Henry Wang <Henry.wang@AzureWave.com>");
676MODULE_DESCRIPTION("Driver for AzureWave 6007 DVB-C/T USB2.0 and clones");
677MODULE_VERSION("1.0");
678MODULE_LICENSE("GPL");