blob: 4008b9c50fbdfa3a9b61853d2a1a7bf86be90ae6 [file] [log] [blame]
Mauro Carvalho Chehab25c16462011-07-23 10:59:25 -03001/*
2 * Driver for AzureWave 6007 DVB-C/T USB2.0 and clones
3 *
4 * Copyright (c) Henry Wang <Henry.wang@AzureWave.com>
5 *
6 * This driver was made publicly available by Terratec, at:
7 * http://linux.terratec.de/files/TERRATEC_H7/20110323_TERRATEC_H7_Linux.tar.gz
8 * The original driver's license is GPL, as declared with MODULE_LICENSE()
9 *
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -030010 * Copyright (c) 2010-2011 Mauro Carvalho Chehab <mchehab@redhat.com>
11 * Driver modified by in order to work with upstream drxk driver, and
12 * tons of bugs got fixed.
Mauro Carvalho Chehab25c16462011-07-23 10:59:25 -030013 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation under version 2 of the License.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030022 */
23
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030024#include "drxk.h"
25#include "mt2063.h"
26#include "dvb_ca_en50221.h"
Mauro Carvalho Chehab70fa4442011-07-23 10:55:10 -030027
28#define DVB_USB_LOG_PREFIX "az6007"
Mauro Carvalho Chehabc108a5a2011-07-25 10:38:20 -030029#include "dvb-usb.h"
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030030
31/* debug */
32int dvb_usb_az6007_debug;
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -030033module_param_named(debug, dvb_usb_az6007_debug, int, 0644);
34MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))."
35 DVB_USB_DEBUG_STATUS);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030036
Mauro Carvalho Chehab70fa4442011-07-23 10:55:10 -030037#define deb_info(args...) dprintk(dvb_usb_az6007_debug, 0x01, args)
38#define deb_xfer(args...) dprintk(dvb_usb_az6007_debug, 0x02, args)
39#define deb_rc(args...) dprintk(dvb_usb_az6007_debug, 0x04, args)
40#define deb_fe(args...) dprintk(dvb_usb_az6007_debug, 0x08, args)
41
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030042DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
43
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -030044/* Known requests (Cypress FX2 firmware + az6007 "private" ones*/
45
46#define FX2_OED 0xb5
47#define AZ6007_READ_DATA 0xb7
48#define AZ6007_I2C_RD 0xb9
49#define AZ6007_POWER 0xbc
50#define AZ6007_I2C_WR 0xbd
51#define FX2_SCON1 0xc0
52#define AZ6007_TS_THROUGH 0xc7
Mauro Carvalho Chehab2d5161b2011-07-29 11:31:13 -030053#define AZ6007_READ_IR 0xb4
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -030054
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030055struct az6007_device_state {
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -030056 struct mutex mutex;
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -030057 struct mutex ca_mutex;
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -030058 struct dvb_ca_en50221 ca;
59 unsigned warm:1;
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -030060 int (*gate_ctrl) (struct dvb_frontend *, int);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -030061 unsigned char data[4096];
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030062};
63
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -030064static struct drxk_config terratec_h7_drxk = {
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030065 .adr = 0x29,
Mauro Carvalho Chehab6e5caf842012-01-20 18:36:26 -030066 .parallel_ts = true,
67 .dynamic_clk = true,
68 .single_master = true,
Mauro Carvalho Chehabd5856812012-01-21 07:57:06 -030069 .enable_merr_cfg = true,
Mauro Carvalho Chehab6e5caf842012-01-20 18:36:26 -030070 .no_i2c_bridge = false,
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -030071 .chunk_size = 64,
Mauro Carvalho Chehab6fb65a62012-01-20 19:13:07 -030072 .mpeg_out_clk_strength = 0x02,
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -030073 .microcode_name = "dvb-usb-terratec-h7-drxk.fw",
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030074};
75
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030076static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
77{
78 struct dvb_usb_adapter *adap = fe->sec_priv;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -030079 struct az6007_device_state *st;
Mauro Carvalho Chehabf2ba9e52011-07-23 11:54:40 -030080 int status = 0;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030081
Mauro Carvalho Chehabf2ba9e52011-07-23 11:54:40 -030082 deb_info("%s: %s\n", __func__, enable ? "enable" : "disable");
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -030083
84 if (!adap)
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030085 return -EINVAL;
86
Mauro Carvalho Chehab978c26c2012-01-16 20:37:13 -030087 st = adap->dev->priv;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -030088
89 if (!st)
90 return -EINVAL;
91
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -030092 if (enable)
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030093 status = st->gate_ctrl(fe, 1);
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -030094 else
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030095 status = st->gate_ctrl(fe, 0);
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -030096
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030097 return status;
98}
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030099
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300100static struct mt2063_config az6007_mt2063_config = {
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300101 .tuner_address = 0x60,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300102 .refclock = 36125000,
103};
104
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300105static int __az6007_read(struct usb_device *udev, u8 req, u16 value,
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300106 u16 index, u8 *b, int blen)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300107{
Mauro Carvalho Chehab9b01f3d2011-07-29 11:40:40 -0300108 int ret;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300109
Mauro Carvalho Chehab3af2f4f2011-07-25 11:17:41 -0300110 ret = usb_control_msg(udev,
111 usb_rcvctrlpipe(udev, 0),
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300112 req,
113 USB_TYPE_VENDOR | USB_DIR_IN,
114 value, index, b, blen, 5000);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300115 if (ret < 0) {
Mauro Carvalho Chehab9b01f3d2011-07-29 11:40:40 -0300116 warn("usb read operation failed. (%d)", ret);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300117 return -EIO;
118 }
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300119
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300120 deb_xfer("in: req. %02x, val: %04x, ind: %04x, buffer: ", req, value,
121 index);
122 debug_dump(b, blen, deb_xfer);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300123
124 return ret;
125}
126
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300127static int az6007_read(struct dvb_usb_device *d, u8 req, u16 value,
128 u16 index, u8 *b, int blen)
129{
130 struct az6007_device_state *st = d->priv;
131 int ret;
132
133 if (mutex_lock_interruptible(&st->mutex) < 0)
134 return -EAGAIN;
135
136 ret = __az6007_read(d->udev, req, value, index, b, blen);
137
138 mutex_unlock(&st->mutex);
139
140 return ret;
141}
142
143static int __az6007_write(struct usb_device *udev, u8 req, u16 value,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300144 u16 index, u8 *b, int blen)
145{
146 int ret;
147
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300148 deb_xfer("out: req. %02x, val: %04x, ind: %04x, buffer: ", req, value,
149 index);
150 debug_dump(b, blen, deb_xfer);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300151
Mauro Carvalho Chehab35753582011-07-23 10:12:12 -0300152 if (blen > 64) {
Mauro Carvalho Chehabda989e02011-07-24 09:25:39 -0300153 err("az6007: tried to write %d bytes, but I2C max size is 64 bytes\n",
154 blen);
Mauro Carvalho Chehab35753582011-07-23 10:12:12 -0300155 return -EOPNOTSUPP;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300156 }
Mauro Carvalho Chehab35753582011-07-23 10:12:12 -0300157
Mauro Carvalho Chehab3af2f4f2011-07-25 11:17:41 -0300158 ret = usb_control_msg(udev,
159 usb_sndctrlpipe(udev, 0),
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300160 req,
161 USB_TYPE_VENDOR | USB_DIR_OUT,
162 value, index, b, blen, 5000);
163 if (ret != blen) {
Mauro Carvalho Chehab9b01f3d2011-07-29 11:40:40 -0300164 err("usb write operation failed. (%d)", ret);
Mauro Carvalho Chehab35753582011-07-23 10:12:12 -0300165 return -EIO;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300166 }
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300167
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300168 return 0;
169}
170
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300171static int az6007_write(struct dvb_usb_device *d, u8 req, u16 value,
172 u16 index, u8 *b, int blen)
173{
174 struct az6007_device_state *st = d->priv;
175 int ret;
176
177 if (mutex_lock_interruptible(&st->mutex) < 0)
178 return -EAGAIN;
179
180 ret = __az6007_write(d->udev, req, value, index, b, blen);
181
182 mutex_unlock(&st->mutex);
183
184 return ret;
185}
186
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300187static int az6007_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
188{
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300189 struct dvb_usb_device *d = adap->dev;
190
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300191 deb_info("%s: %s", __func__, onoff ? "enable" : "disable");
192
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300193 return az6007_write(d, 0xbc, onoff, 0, NULL, 0);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300194}
195
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300196/* remote control stuff (does not work with my box) */
Mauro Carvalho Chehabd3d076a2012-01-21 12:20:30 -0300197static int az6007_rc_query(struct dvb_usb_device *d)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300198{
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300199 struct az6007_device_state *st = d->priv;
Mauro Carvalho Chehab91651442012-01-21 12:14:13 -0300200 unsigned code = 0;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300201
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300202 az6007_read(d, AZ6007_READ_IR, 0, 0, st->data, 10);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300203
Mauro Carvalho Chehabd3d076a2012-01-21 12:20:30 -0300204 if (st->data[1] == 0x44)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300205 return 0;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300206
Mauro Carvalho Chehab91651442012-01-21 12:14:13 -0300207 if ((st->data[1] ^ st->data[2]) == 0xff)
208 code = st->data[1];
209 else
210 code = st->data[1] << 8 | st->data[2];
211
212 if ((st->data[3] ^ st->data[4]) == 0xff)
213 code = code << 8 | st->data[3];
214 else
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200215 code = code << 16 | st->data[3] << 8 | st->data[4];
Mauro Carvalho Chehab2d5161b2011-07-29 11:31:13 -0300216
Mauro Carvalho Chehabd3d076a2012-01-21 12:20:30 -0300217 rc_keydown(d->rc_dev, code, st->data[5]);
Mauro Carvalho Chehab2d5161b2011-07-29 11:31:13 -0300218
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300219 return 0;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300220}
221
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300222static int az6007_ci_read_attribute_mem(struct dvb_ca_en50221 *ca,
223 int slot,
224 int address)
225{
226 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
227 struct az6007_device_state *state = (struct az6007_device_state *)d->priv;
228
229 int ret;
230 u8 req;
231 u16 value;
232 u16 index;
233 int blen;
234 u8 *b;
235
236 if (slot != 0)
237 return -EINVAL;
238
239 b = kmalloc(12, GFP_KERNEL);
240 if (!b)
241 return -ENOMEM;
242
243 mutex_lock(&state->ca_mutex);
244
245 req = 0xC1;
246 value = address;
247 index = 0;
248 blen = 1;
249
250 ret = az6007_read(d, req, value, index, b, blen);
251 if (ret < 0) {
252 warn("usb in operation failed. (%d)", ret);
253 ret = -EINVAL;
254 } else {
255 ret = b[0];
256 }
257
258 mutex_unlock(&state->ca_mutex);
259 kfree(b);
260 return ret;
261}
262
263static int az6007_ci_write_attribute_mem(struct dvb_ca_en50221 *ca,
264 int slot,
265 int address,
266 u8 value)
267{
268 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
269 struct az6007_device_state *state = (struct az6007_device_state *)d->priv;
270
271 int ret;
272 u8 req;
273 u16 value1;
274 u16 index;
275 int blen;
276
277 deb_info("%s %d", __func__, slot);
278 if (slot != 0)
279 return -EINVAL;
280
281 mutex_lock(&state->ca_mutex);
282 req = 0xC2;
283 value1 = address;
284 index = value;
285 blen = 0;
286
287 ret = az6007_write(d, req, value1, index, NULL, blen);
288 if (ret != 0)
289 warn("usb out operation failed. (%d)", ret);
290
291 mutex_unlock(&state->ca_mutex);
292 return ret;
293}
294
295static int az6007_ci_read_cam_control(struct dvb_ca_en50221 *ca,
296 int slot,
297 u8 address)
298{
299 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
300 struct az6007_device_state *state = (struct az6007_device_state *)d->priv;
301
302 int ret;
303 u8 req;
304 u16 value;
305 u16 index;
306 int blen;
307 u8 *b;
308
309 if (slot != 0)
310 return -EINVAL;
311
312 b = kmalloc(12, GFP_KERNEL);
313 if (!b)
314 return -ENOMEM;
315
316 mutex_lock(&state->ca_mutex);
317
318 req = 0xC3;
319 value = address;
320 index = 0;
321 blen = 2;
322
323 ret = az6007_read(d, req, value, index, b, blen);
324 if (ret < 0) {
325 warn("usb in operation failed. (%d)", ret);
326 ret = -EINVAL;
327 } else {
328 if (b[0] == 0)
329 warn("Read CI IO error");
330
331 ret = b[1];
332 deb_info("read cam data = %x from 0x%x", b[1], value);
333 }
334
335 mutex_unlock(&state->ca_mutex);
336 kfree(b);
337 return ret;
338}
339
340static int az6007_ci_write_cam_control(struct dvb_ca_en50221 *ca,
341 int slot,
342 u8 address,
343 u8 value)
344{
345 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
346 struct az6007_device_state *state = (struct az6007_device_state *)d->priv;
347
348 int ret;
349 u8 req;
350 u16 value1;
351 u16 index;
352 int blen;
353
354 if (slot != 0)
355 return -EINVAL;
356
357 mutex_lock(&state->ca_mutex);
358 req = 0xC4;
359 value1 = address;
360 index = value;
361 blen = 0;
362
363 ret = az6007_write(d, req, value1, index, NULL, blen);
364 if (ret != 0) {
365 warn("usb out operation failed. (%d)", ret);
366 goto failed;
367 }
368
369failed:
370 mutex_unlock(&state->ca_mutex);
371 return ret;
372}
373
374static int CI_CamReady(struct dvb_ca_en50221 *ca, int slot)
375{
376 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
377
378 int ret;
379 u8 req;
380 u16 value;
381 u16 index;
382 int blen;
383 u8 *b;
384
385 b = kmalloc(12, GFP_KERNEL);
386 if (!b)
387 return -ENOMEM;
388
389 req = 0xC8;
390 value = 0;
391 index = 0;
392 blen = 1;
393
394 ret = az6007_read(d, req, value, index, b, blen);
395 if (ret < 0) {
396 warn("usb in operation failed. (%d)", ret);
397 ret = -EIO;
398 } else{
399 ret = b[0];
400 }
401 kfree(b);
402 return ret;
403}
404
405static int az6007_ci_slot_reset(struct dvb_ca_en50221 *ca, int slot)
406{
407 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
408 struct az6007_device_state *state = (struct az6007_device_state *)d->priv;
409
410 int ret, i;
411 u8 req;
412 u16 value;
413 u16 index;
414 int blen;
415
416 mutex_lock(&state->ca_mutex);
417
418 req = 0xC6;
419 value = 1;
420 index = 0;
421 blen = 0;
422
423 ret = az6007_write(d, req, value, index, NULL, blen);
424 if (ret != 0) {
425 warn("usb out operation failed. (%d)", ret);
426 goto failed;
427 }
428
429 msleep(500);
430 req = 0xC6;
431 value = 0;
432 index = 0;
433 blen = 0;
434
435 ret = az6007_write(d, req, value, index, NULL, blen);
436 if (ret != 0) {
437 warn("usb out operation failed. (%d)", ret);
438 goto failed;
439 }
440
441 for (i = 0; i < 15; i++) {
442 msleep(100);
443
444 if (CI_CamReady(ca, slot)) {
445 deb_info("CAM Ready");
446 break;
447 }
448 }
449 msleep(5000);
450
451failed:
452 mutex_unlock(&state->ca_mutex);
453 return ret;
454}
455
456static int az6007_ci_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
457{
458 return 0;
459}
460
461static int az6007_ci_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
462{
463 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
464 struct az6007_device_state *state = (struct az6007_device_state *)d->priv;
465
466 int ret;
467 u8 req;
468 u16 value;
469 u16 index;
470 int blen;
471
472 deb_info("%s", __func__);
473 mutex_lock(&state->ca_mutex);
474 req = 0xC7;
475 value = 1;
476 index = 0;
477 blen = 0;
478
479 ret = az6007_write(d, req, value, index, NULL, blen);
480 if (ret != 0) {
481 warn("usb out operation failed. (%d)", ret);
482 goto failed;
483 }
484
485failed:
486 mutex_unlock(&state->ca_mutex);
487 return ret;
488}
489
490static int az6007_ci_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
491{
492 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
493 struct az6007_device_state *state = (struct az6007_device_state *)d->priv;
494 int ret;
495 u8 req;
496 u16 value;
497 u16 index;
498 int blen;
499 u8 *b;
500
501 b = kmalloc(12, GFP_KERNEL);
502 if (!b)
503 return -ENOMEM;
504 mutex_lock(&state->ca_mutex);
505
506 req = 0xC5;
507 value = 0;
508 index = 0;
509 blen = 1;
510
511 ret = az6007_read(d, req, value, index, b, blen);
512 if (ret < 0) {
513 warn("usb in operation failed. (%d)", ret);
514 ret = -EIO;
515 } else
516 ret = 0;
517
518 if (!ret && b[0] == 1) {
519 ret = DVB_CA_EN50221_POLL_CAM_PRESENT |
520 DVB_CA_EN50221_POLL_CAM_READY;
521 }
522
523 mutex_unlock(&state->ca_mutex);
524 kfree(b);
525 return ret;
526}
527
528
529static void az6007_ci_uninit(struct dvb_usb_device *d)
530{
531 struct az6007_device_state *state;
532
533 deb_info("%s", __func__);
534
535 if (NULL == d)
536 return;
537
538 state = (struct az6007_device_state *)d->priv;
539 if (NULL == state)
540 return;
541
542 if (NULL == state->ca.data)
543 return;
544
545 dvb_ca_en50221_release(&state->ca);
546
547 memset(&state->ca, 0, sizeof(state->ca));
548}
549
550
551static int az6007_ci_init(struct dvb_usb_adapter *a)
552{
553 struct dvb_usb_device *d = a->dev;
554 struct az6007_device_state *state = (struct az6007_device_state *)d->priv;
555 int ret;
556
557 deb_info("%s", __func__);
558
559 mutex_init(&state->ca_mutex);
560
561 state->ca.owner = THIS_MODULE;
562 state->ca.read_attribute_mem = az6007_ci_read_attribute_mem;
563 state->ca.write_attribute_mem = az6007_ci_write_attribute_mem;
564 state->ca.read_cam_control = az6007_ci_read_cam_control;
565 state->ca.write_cam_control = az6007_ci_write_cam_control;
566 state->ca.slot_reset = az6007_ci_slot_reset;
567 state->ca.slot_shutdown = az6007_ci_slot_shutdown;
568 state->ca.slot_ts_enable = az6007_ci_slot_ts_enable;
569 state->ca.poll_slot_status = az6007_ci_poll_slot_status;
570 state->ca.data = d;
571
572 ret = dvb_ca_en50221_init(&a->dvb_adap,
573 &state->ca,
574 0, /* flags */
575 1);/* n_slots */
576 if (ret != 0) {
577 err("Cannot initialize CI: Error %d.", ret);
578 memset(&state->ca, 0, sizeof(state->ca));
579 return ret;
580 }
581
582 deb_info("CI initialized.");
583
584 return 0;
585}
586
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300587static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300588{
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300589 struct az6007_device_state *st = d->priv;
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300590 int ret;
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300591
592 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
593 memcpy(mac, st->data, sizeof(mac));
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300594
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300595 if (ret > 0)
596 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
597 __func__, mac[0], mac[1], mac[2],
598 mac[3], mac[4], mac[5]);
599
600 return ret;
601}
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300602
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300603static int az6007_frontend_attach(struct dvb_usb_adapter *adap)
604{
Mauro Carvalho Chehab978c26c2012-01-16 20:37:13 -0300605 struct az6007_device_state *st = adap->dev->priv;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300606
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300607 deb_info("attaching demod drxk");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300608
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300609 adap->fe_adap[0].fe = dvb_attach(drxk_attach, &terratec_h7_drxk,
610 &adap->dev->i2c_adap);
611 if (!adap->fe_adap[0].fe)
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300612 return -EINVAL;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300613
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300614 adap->fe_adap[0].fe->sec_priv = adap;
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300615 st->gate_ctrl = adap->fe_adap[0].fe->ops.i2c_gate_ctrl;
616 adap->fe_adap[0].fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Mauro Carvalho Chehabda989e02011-07-24 09:25:39 -0300617
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300618 az6007_ci_init(adap);
619
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300620 return 0;
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300621}
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300622
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300623static int az6007_tuner_attach(struct dvb_usb_adapter *adap)
624{
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300625 deb_info("attaching tuner mt2063");
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -0300626
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300627 /* Attach mt2063 to DVB-C frontend */
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300628 if (adap->fe_adap[0].fe->ops.i2c_gate_ctrl)
629 adap->fe_adap[0].fe->ops.i2c_gate_ctrl(adap->fe_adap[0].fe, 1);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300630 if (!dvb_attach(mt2063_attach, adap->fe_adap[0].fe,
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300631 &az6007_mt2063_config,
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300632 &adap->dev->i2c_adap))
633 return -EINVAL;
634
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300635 if (adap->fe_adap[0].fe->ops.i2c_gate_ctrl)
636 adap->fe_adap[0].fe->ops.i2c_gate_ctrl(adap->fe_adap[0].fe, 0);
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300637
638 return 0;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300639}
640
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300641int az6007_power_ctrl(struct dvb_usb_device *d, int onoff)
642{
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300643 struct az6007_device_state *st = d->priv;
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300644 int ret;
645
646 deb_info("%s()\n", __func__);
647
648 if (!st->warm) {
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300649 mutex_init(&st->mutex);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300650
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300651 ret = az6007_write(d, AZ6007_POWER, 0, 2, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300652 if (ret < 0)
653 return ret;
654 msleep(60);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300655 ret = az6007_write(d, AZ6007_POWER, 1, 4, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300656 if (ret < 0)
657 return ret;
658 msleep(100);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300659 ret = az6007_write(d, AZ6007_POWER, 1, 3, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300660 if (ret < 0)
661 return ret;
662 msleep(20);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300663 ret = az6007_write(d, AZ6007_POWER, 1, 4, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300664 if (ret < 0)
665 return ret;
666
667 msleep(400);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300668 ret = az6007_write(d, FX2_SCON1, 0, 3, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300669 if (ret < 0)
670 return ret;
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200671 msleep(150);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300672 ret = az6007_write(d, FX2_SCON1, 1, 3, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300673 if (ret < 0)
674 return ret;
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200675 msleep(430);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300676 ret = az6007_write(d, AZ6007_POWER, 0, 0, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300677 if (ret < 0)
678 return ret;
679
680 st->warm = true;
681
682 return 0;
683 }
684
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300685 if (!onoff)
686 return 0;
687
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300688 az6007_write(d, AZ6007_POWER, 0, 0, NULL, 0);
689 az6007_write(d, AZ6007_TS_THROUGH, 0, 0, NULL, 0);
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300690
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300691 return 0;
692}
693
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300694/* I2C */
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300695static int az6007_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
696 int num)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300697{
698 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300699 struct az6007_device_state *st = d->priv;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300700 int i, j, len;
701 int ret = 0;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300702 u16 index;
703 u16 value;
704 int length;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300705 u8 req, addr;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300706
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300707 if (mutex_lock_interruptible(&st->mutex) < 0)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300708 return -EAGAIN;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300709
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300710 for (i = 0; i < num; i++) {
711 addr = msgs[i].addr << 1;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300712 if (((i + 1) < num)
713 && (msgs[i].len == 1)
714 && (!msgs[i].flags & I2C_M_RD)
715 && (msgs[i + 1].flags & I2C_M_RD)
716 && (msgs[i].addr == msgs[i + 1].addr)) {
717 /*
718 * A write + read xfer for the same address, where
719 * the first xfer has just 1 byte length.
720 * Need to join both into one operation
721 */
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300722 if (dvb_usb_az6007_debug & 2)
723 printk(KERN_DEBUG
724 "az6007 I2C xfer write+read addr=0x%x len=%d/%d: ",
725 addr, msgs[i].len, msgs[i + 1].len);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300726 req = AZ6007_I2C_RD;
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300727 index = msgs[i].buf[0];
728 value = addr | (1 << 8);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300729 length = 6 + msgs[i + 1].len;
730 len = msgs[i + 1].len;
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200731 ret = __az6007_read(d->udev, req, value, index,
732 st->data, length);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300733 if (ret >= len) {
734 for (j = 0; j < len; j++) {
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300735 msgs[i + 1].buf[j] = st->data[j + 5];
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300736 if (dvb_usb_az6007_debug & 2)
737 printk(KERN_CONT
738 "0x%02x ",
739 msgs[i + 1].buf[j]);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300740 }
741 } else
742 ret = -EIO;
743 i++;
744 } else if (!(msgs[i].flags & I2C_M_RD)) {
745 /* write bytes */
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300746 if (dvb_usb_az6007_debug & 2)
747 printk(KERN_DEBUG
748 "az6007 I2C xfer write addr=0x%x len=%d: ",
749 addr, msgs[i].len);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300750 req = AZ6007_I2C_WR;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300751 index = msgs[i].buf[0];
752 value = addr | (1 << 8);
753 length = msgs[i].len - 1;
754 len = msgs[i].len - 1;
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300755 if (dvb_usb_az6007_debug & 2)
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300756 printk(KERN_CONT "(0x%02x) ", msgs[i].buf[0]);
757 for (j = 0; j < len; j++) {
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300758 st->data[j] = msgs[i].buf[j + 1];
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300759 if (dvb_usb_az6007_debug & 2)
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200760 printk(KERN_CONT "0x%02x ",
761 st->data[j]);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300762 }
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200763 ret = __az6007_write(d->udev, req, value, index,
764 st->data, length);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300765 } else {
766 /* read bytes */
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300767 if (dvb_usb_az6007_debug & 2)
768 printk(KERN_DEBUG
769 "az6007 I2C xfer read addr=0x%x len=%d: ",
770 addr, msgs[i].len);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300771 req = AZ6007_I2C_RD;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300772 index = msgs[i].buf[0];
773 value = addr;
774 length = msgs[i].len + 6;
775 len = msgs[i].len;
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200776 ret = __az6007_read(d->udev, req, value, index,
777 st->data, length);
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300778 for (j = 0; j < len; j++) {
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300779 msgs[i].buf[j] = st->data[j + 5];
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300780 if (dvb_usb_az6007_debug & 2)
781 printk(KERN_CONT
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300782 "0x%02x ", st->data[j + 5]);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300783 }
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300784 }
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300785 if (dvb_usb_az6007_debug & 2)
786 printk(KERN_CONT "\n");
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300787 if (ret < 0)
788 goto err;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300789 }
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300790err:
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300791 mutex_unlock(&st->mutex);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300792
793 if (ret < 0) {
Mauro Carvalho Chehabf2ba9e52011-07-23 11:54:40 -0300794 info("%s ERROR: %i", __func__, ret);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300795 return ret;
796 }
797 return num;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300798}
799
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300800static u32 az6007_i2c_func(struct i2c_adapter *adapter)
801{
802 return I2C_FUNC_I2C;
803}
804
805static struct i2c_algorithm az6007_i2c_algo = {
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300806 .master_xfer = az6007_i2c_xfer,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300807 .functionality = az6007_i2c_func,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300808};
809
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300810int az6007_identify_state(struct usb_device *udev,
811 struct dvb_usb_device_properties *props,
812 struct dvb_usb_device_description **desc, int *cold)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300813{
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300814 int ret;
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300815 u8 *mac;
816
817 mac = kmalloc(6, GFP_ATOMIC);
818 if (!mac)
819 return -ENOMEM;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300820
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300821 /* Try to read the mac address */
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300822 ret = __az6007_read(udev, AZ6007_READ_DATA, 6, 0, mac, 6);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300823 if (ret == 6)
824 *cold = 0;
825 else
826 *cold = 1;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300827
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300828 kfree(mac);
829
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300830 if (*cold) {
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300831 __az6007_write(udev, 0x09, 1, 0, NULL, 0);
832 __az6007_write(udev, 0x00, 0, 0, NULL, 0);
833 __az6007_write(udev, 0x00, 0, 0, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300834 }
835
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200836 deb_info("Device is on %s state\n", *cold ? "warm" : "cold");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300837 return 0;
838}
839
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -0300840static struct dvb_usb_device_properties az6007_properties;
841
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300842static void az6007_usb_disconnect(struct usb_interface *intf)
843{
844 struct dvb_usb_device *d = usb_get_intfdata(intf);
845 az6007_ci_uninit(d);
846 dvb_usb_device_exit(intf);
847}
848
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300849static int az6007_usb_probe(struct usb_interface *intf,
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300850 const struct usb_device_id *id)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300851{
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300852 return dvb_usb_device_init(intf, &az6007_properties,
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300853 THIS_MODULE, NULL, adapter_nr);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300854}
855
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300856static struct usb_device_id az6007_usb_table[] = {
857 {USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_6007)},
858 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_H7)},
Jose Alberto Reguero260a8f72012-01-26 20:02:52 -0300859 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_H7_2)},
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300860 {0},
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300861};
862
863MODULE_DEVICE_TABLE(usb, az6007_usb_table);
864
865static struct dvb_usb_device_properties az6007_properties = {
866 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
867 .usb_ctrl = CYPRESS_FX2,
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300868 .firmware = "dvb-usb-terratec-h7-az6007.fw",
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300869 .no_reconnect = 1,
Mauro Carvalho Chehab978c26c2012-01-16 20:37:13 -0300870 .size_of_priv = sizeof(struct az6007_device_state),
871 .identify_state = az6007_identify_state,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300872 .num_adapters = 1,
873 .adapter = {
874 {
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300875 .num_frontends = 1,
876 .fe = {{
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300877 .streaming_ctrl = az6007_streaming_ctrl,
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300878 .tuner_attach = az6007_tuner_attach,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300879 .frontend_attach = az6007_frontend_attach,
880
881 /* parameter for the MPEG2-data transfer */
882 .stream = {
883 .type = USB_BULK,
884 .count = 10,
885 .endpoint = 0x02,
886 .u = {
887 .bulk = {
888 .buffersize = 4096,
889 }
890 }
891 },
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200892 } }
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300893 } },
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300894 .power_ctrl = az6007_power_ctrl,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300895 .read_mac_address = az6007_read_mac_addr,
896
Mauro Carvalho Chehabd3d076a2012-01-21 12:20:30 -0300897 .rc.core = {
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300898 .rc_interval = 400,
Mauro Carvalho Chehab083995472012-01-21 12:41:21 -0300899 .rc_codes = RC_MAP_NEC_TERRATEC_CINERGY_XS,
Mauro Carvalho Chehabd3d076a2012-01-21 12:20:30 -0300900 .module_name = "az6007",
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300901 .rc_query = az6007_rc_query,
Mauro Carvalho Chehabd3d076a2012-01-21 12:20:30 -0300902 .allowed_protos = RC_TYPE_NEC,
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300903 },
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300904 .i2c_algo = &az6007_i2c_algo,
905
906 .num_device_descs = 2,
907 .devices = {
908 { .name = "AzureWave DTV StarBox DVB-T/C USB2.0 (az6007)",
909 .cold_ids = { &az6007_usb_table[0], NULL },
910 .warm_ids = { NULL },
911 },
912 { .name = "TerraTec DTV StarBox DVB-T/C USB2.0 (az6007)",
Jose Alberto Reguero260a8f72012-01-26 20:02:52 -0300913 .cold_ids = { &az6007_usb_table[1], &az6007_usb_table[2], NULL },
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300914 .warm_ids = { NULL },
915 },
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300916 { NULL },
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300917 }
918};
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300919
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300920/* usb specific object needed to register this driver with the usb subsystem */
921static struct usb_driver az6007_usb_driver = {
922 .name = "dvb_usb_az6007",
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300923 .probe = az6007_usb_probe,
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300924 .disconnect = az6007_usb_disconnect,
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300925 .id_table = az6007_usb_table,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300926};
927
928/* module stuff */
929static int __init az6007_usb_module_init(void)
930{
931 int result;
Mauro Carvalho Chehabf2ba9e52011-07-23 11:54:40 -0300932 deb_info("az6007 usb module init\n");
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300933
934 result = usb_register(&az6007_usb_driver);
935 if (result) {
936 err("usb_register failed. (%d)", result);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300937 return result;
938 }
939
940 return 0;
941}
942
943static void __exit az6007_usb_module_exit(void)
944{
945 /* deregister this driver from the USB subsystem */
Mauro Carvalho Chehabf2ba9e52011-07-23 11:54:40 -0300946 deb_info("az6007 usb module exit\n");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300947 usb_deregister(&az6007_usb_driver);
948}
949
950module_init(az6007_usb_module_init);
951module_exit(az6007_usb_module_exit);
952
953MODULE_AUTHOR("Henry Wang <Henry.wang@AzureWave.com>");
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -0300954MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300955MODULE_DESCRIPTION("Driver for AzureWave 6007 DVB-C/T USB2.0 and clones");
Mauro Carvalho Chehab35753582011-07-23 10:12:12 -0300956MODULE_VERSION("1.1");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300957MODULE_LICENSE("GPL");