blob: 86861e6f86d23053ebe990aa58b24e7d377d7d45 [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);
Alan Cox5a7a5702012-07-24 12:02:46 -0300593 memcpy(mac, st->data, 6);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300594
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300595 if (ret > 0)
Andy Shevchenko936148a2012-07-06 11:31:51 -0300596 deb_info("%s: mac is %pM\n", __func__, mac);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300597
598 return ret;
599}
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300600
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300601static int az6007_frontend_attach(struct dvb_usb_adapter *adap)
602{
Mauro Carvalho Chehab978c26c2012-01-16 20:37:13 -0300603 struct az6007_device_state *st = adap->dev->priv;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300604
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300605 deb_info("attaching demod drxk");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300606
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300607 adap->fe_adap[0].fe = dvb_attach(drxk_attach, &terratec_h7_drxk,
608 &adap->dev->i2c_adap);
609 if (!adap->fe_adap[0].fe)
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300610 return -EINVAL;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300611
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300612 adap->fe_adap[0].fe->sec_priv = adap;
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300613 st->gate_ctrl = adap->fe_adap[0].fe->ops.i2c_gate_ctrl;
614 adap->fe_adap[0].fe->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Mauro Carvalho Chehabda989e02011-07-24 09:25:39 -0300615
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300616 az6007_ci_init(adap);
617
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300618 return 0;
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300619}
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300620
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300621static int az6007_tuner_attach(struct dvb_usb_adapter *adap)
622{
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300623 deb_info("attaching tuner mt2063");
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -0300624
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300625 /* Attach mt2063 to DVB-C frontend */
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300626 if (adap->fe_adap[0].fe->ops.i2c_gate_ctrl)
627 adap->fe_adap[0].fe->ops.i2c_gate_ctrl(adap->fe_adap[0].fe, 1);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300628 if (!dvb_attach(mt2063_attach, adap->fe_adap[0].fe,
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300629 &az6007_mt2063_config,
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300630 &adap->dev->i2c_adap))
631 return -EINVAL;
632
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300633 if (adap->fe_adap[0].fe->ops.i2c_gate_ctrl)
634 adap->fe_adap[0].fe->ops.i2c_gate_ctrl(adap->fe_adap[0].fe, 0);
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300635
636 return 0;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300637}
638
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300639int az6007_power_ctrl(struct dvb_usb_device *d, int onoff)
640{
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300641 struct az6007_device_state *st = d->priv;
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300642 int ret;
643
644 deb_info("%s()\n", __func__);
645
646 if (!st->warm) {
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300647 mutex_init(&st->mutex);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300648
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300649 ret = az6007_write(d, AZ6007_POWER, 0, 2, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300650 if (ret < 0)
651 return ret;
652 msleep(60);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300653 ret = az6007_write(d, AZ6007_POWER, 1, 4, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300654 if (ret < 0)
655 return ret;
656 msleep(100);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300657 ret = az6007_write(d, AZ6007_POWER, 1, 3, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300658 if (ret < 0)
659 return ret;
660 msleep(20);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300661 ret = az6007_write(d, AZ6007_POWER, 1, 4, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300662 if (ret < 0)
663 return ret;
664
665 msleep(400);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300666 ret = az6007_write(d, FX2_SCON1, 0, 3, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300667 if (ret < 0)
668 return ret;
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200669 msleep(150);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300670 ret = az6007_write(d, FX2_SCON1, 1, 3, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300671 if (ret < 0)
672 return ret;
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200673 msleep(430);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300674 ret = az6007_write(d, AZ6007_POWER, 0, 0, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300675 if (ret < 0)
676 return ret;
677
678 st->warm = true;
679
680 return 0;
681 }
682
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300683 if (!onoff)
684 return 0;
685
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300686 az6007_write(d, AZ6007_POWER, 0, 0, NULL, 0);
687 az6007_write(d, AZ6007_TS_THROUGH, 0, 0, NULL, 0);
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300688
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300689 return 0;
690}
691
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300692/* I2C */
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300693static int az6007_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
694 int num)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300695{
696 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300697 struct az6007_device_state *st = d->priv;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300698 int i, j, len;
699 int ret = 0;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300700 u16 index;
701 u16 value;
702 int length;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300703 u8 req, addr;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300704
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300705 if (mutex_lock_interruptible(&st->mutex) < 0)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300706 return -EAGAIN;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300707
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300708 for (i = 0; i < num; i++) {
709 addr = msgs[i].addr << 1;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300710 if (((i + 1) < num)
711 && (msgs[i].len == 1)
712 && (!msgs[i].flags & I2C_M_RD)
713 && (msgs[i + 1].flags & I2C_M_RD)
714 && (msgs[i].addr == msgs[i + 1].addr)) {
715 /*
716 * A write + read xfer for the same address, where
717 * the first xfer has just 1 byte length.
718 * Need to join both into one operation
719 */
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300720 if (dvb_usb_az6007_debug & 2)
721 printk(KERN_DEBUG
722 "az6007 I2C xfer write+read addr=0x%x len=%d/%d: ",
723 addr, msgs[i].len, msgs[i + 1].len);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300724 req = AZ6007_I2C_RD;
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300725 index = msgs[i].buf[0];
726 value = addr | (1 << 8);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300727 length = 6 + msgs[i + 1].len;
728 len = msgs[i + 1].len;
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200729 ret = __az6007_read(d->udev, req, value, index,
730 st->data, length);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300731 if (ret >= len) {
732 for (j = 0; j < len; j++) {
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300733 msgs[i + 1].buf[j] = st->data[j + 5];
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300734 if (dvb_usb_az6007_debug & 2)
735 printk(KERN_CONT
736 "0x%02x ",
737 msgs[i + 1].buf[j]);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300738 }
739 } else
740 ret = -EIO;
741 i++;
742 } else if (!(msgs[i].flags & I2C_M_RD)) {
743 /* write bytes */
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300744 if (dvb_usb_az6007_debug & 2)
745 printk(KERN_DEBUG
746 "az6007 I2C xfer write addr=0x%x len=%d: ",
747 addr, msgs[i].len);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300748 req = AZ6007_I2C_WR;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300749 index = msgs[i].buf[0];
750 value = addr | (1 << 8);
751 length = msgs[i].len - 1;
752 len = msgs[i].len - 1;
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300753 if (dvb_usb_az6007_debug & 2)
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300754 printk(KERN_CONT "(0x%02x) ", msgs[i].buf[0]);
755 for (j = 0; j < len; j++) {
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300756 st->data[j] = msgs[i].buf[j + 1];
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300757 if (dvb_usb_az6007_debug & 2)
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200758 printk(KERN_CONT "0x%02x ",
759 st->data[j]);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300760 }
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200761 ret = __az6007_write(d->udev, req, value, index,
762 st->data, length);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300763 } else {
764 /* read bytes */
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300765 if (dvb_usb_az6007_debug & 2)
766 printk(KERN_DEBUG
767 "az6007 I2C xfer read addr=0x%x len=%d: ",
768 addr, msgs[i].len);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300769 req = AZ6007_I2C_RD;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300770 index = msgs[i].buf[0];
771 value = addr;
772 length = msgs[i].len + 6;
773 len = msgs[i].len;
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200774 ret = __az6007_read(d->udev, req, value, index,
775 st->data, length);
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300776 for (j = 0; j < len; j++) {
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300777 msgs[i].buf[j] = st->data[j + 5];
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300778 if (dvb_usb_az6007_debug & 2)
779 printk(KERN_CONT
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300780 "0x%02x ", st->data[j + 5]);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300781 }
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300782 }
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300783 if (dvb_usb_az6007_debug & 2)
784 printk(KERN_CONT "\n");
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300785 if (ret < 0)
786 goto err;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300787 }
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300788err:
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300789 mutex_unlock(&st->mutex);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300790
791 if (ret < 0) {
Mauro Carvalho Chehabf2ba9e52011-07-23 11:54:40 -0300792 info("%s ERROR: %i", __func__, ret);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300793 return ret;
794 }
795 return num;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300796}
797
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300798static u32 az6007_i2c_func(struct i2c_adapter *adapter)
799{
800 return I2C_FUNC_I2C;
801}
802
803static struct i2c_algorithm az6007_i2c_algo = {
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300804 .master_xfer = az6007_i2c_xfer,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300805 .functionality = az6007_i2c_func,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300806};
807
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300808int az6007_identify_state(struct usb_device *udev,
809 struct dvb_usb_device_properties *props,
810 struct dvb_usb_device_description **desc, int *cold)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300811{
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300812 int ret;
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300813 u8 *mac;
814
815 mac = kmalloc(6, GFP_ATOMIC);
816 if (!mac)
817 return -ENOMEM;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300818
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300819 /* Try to read the mac address */
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300820 ret = __az6007_read(udev, AZ6007_READ_DATA, 6, 0, mac, 6);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300821 if (ret == 6)
822 *cold = 0;
823 else
824 *cold = 1;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300825
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300826 kfree(mac);
827
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300828 if (*cold) {
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300829 __az6007_write(udev, 0x09, 1, 0, NULL, 0);
830 __az6007_write(udev, 0x00, 0, 0, NULL, 0);
831 __az6007_write(udev, 0x00, 0, 0, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300832 }
833
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200834 deb_info("Device is on %s state\n", *cold ? "warm" : "cold");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300835 return 0;
836}
837
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -0300838static struct dvb_usb_device_properties az6007_properties;
839
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300840static void az6007_usb_disconnect(struct usb_interface *intf)
841{
842 struct dvb_usb_device *d = usb_get_intfdata(intf);
843 az6007_ci_uninit(d);
844 dvb_usb_device_exit(intf);
845}
846
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300847static int az6007_usb_probe(struct usb_interface *intf,
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300848 const struct usb_device_id *id)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300849{
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300850 return dvb_usb_device_init(intf, &az6007_properties,
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300851 THIS_MODULE, NULL, adapter_nr);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300852}
853
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300854static struct usb_device_id az6007_usb_table[] = {
855 {USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_6007)},
856 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_H7)},
Jose Alberto Reguero260a8f72012-01-26 20:02:52 -0300857 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_H7_2)},
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300858 {0},
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300859};
860
861MODULE_DEVICE_TABLE(usb, az6007_usb_table);
862
863static struct dvb_usb_device_properties az6007_properties = {
864 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
865 .usb_ctrl = CYPRESS_FX2,
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300866 .firmware = "dvb-usb-terratec-h7-az6007.fw",
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300867 .no_reconnect = 1,
Mauro Carvalho Chehab978c26c2012-01-16 20:37:13 -0300868 .size_of_priv = sizeof(struct az6007_device_state),
869 .identify_state = az6007_identify_state,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300870 .num_adapters = 1,
871 .adapter = {
872 {
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300873 .num_frontends = 1,
874 .fe = {{
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300875 .streaming_ctrl = az6007_streaming_ctrl,
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300876 .tuner_attach = az6007_tuner_attach,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300877 .frontend_attach = az6007_frontend_attach,
878
879 /* parameter for the MPEG2-data transfer */
880 .stream = {
881 .type = USB_BULK,
882 .count = 10,
883 .endpoint = 0x02,
884 .u = {
885 .bulk = {
886 .buffersize = 4096,
887 }
888 }
889 },
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200890 } }
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300891 } },
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300892 .power_ctrl = az6007_power_ctrl,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300893 .read_mac_address = az6007_read_mac_addr,
894
Mauro Carvalho Chehabd3d076a2012-01-21 12:20:30 -0300895 .rc.core = {
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300896 .rc_interval = 400,
Mauro Carvalho Chehab083995472012-01-21 12:41:21 -0300897 .rc_codes = RC_MAP_NEC_TERRATEC_CINERGY_XS,
Mauro Carvalho Chehabd3d076a2012-01-21 12:20:30 -0300898 .module_name = "az6007",
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300899 .rc_query = az6007_rc_query,
Mauro Carvalho Chehabd3d076a2012-01-21 12:20:30 -0300900 .allowed_protos = RC_TYPE_NEC,
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300901 },
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300902 .i2c_algo = &az6007_i2c_algo,
903
904 .num_device_descs = 2,
905 .devices = {
906 { .name = "AzureWave DTV StarBox DVB-T/C USB2.0 (az6007)",
907 .cold_ids = { &az6007_usb_table[0], NULL },
908 .warm_ids = { NULL },
909 },
910 { .name = "TerraTec DTV StarBox DVB-T/C USB2.0 (az6007)",
Jose Alberto Reguero260a8f72012-01-26 20:02:52 -0300911 .cold_ids = { &az6007_usb_table[1], &az6007_usb_table[2], NULL },
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300912 .warm_ids = { NULL },
913 },
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300914 { NULL },
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300915 }
916};
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300917
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300918/* usb specific object needed to register this driver with the usb subsystem */
919static struct usb_driver az6007_usb_driver = {
920 .name = "dvb_usb_az6007",
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300921 .probe = az6007_usb_probe,
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300922 .disconnect = az6007_usb_disconnect,
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300923 .id_table = az6007_usb_table,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300924};
925
926/* module stuff */
927static int __init az6007_usb_module_init(void)
928{
929 int result;
Mauro Carvalho Chehabf2ba9e52011-07-23 11:54:40 -0300930 deb_info("az6007 usb module init\n");
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300931
932 result = usb_register(&az6007_usb_driver);
933 if (result) {
934 err("usb_register failed. (%d)", result);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300935 return result;
936 }
937
938 return 0;
939}
940
941static void __exit az6007_usb_module_exit(void)
942{
943 /* deregister this driver from the USB subsystem */
Mauro Carvalho Chehabf2ba9e52011-07-23 11:54:40 -0300944 deb_info("az6007 usb module exit\n");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300945 usb_deregister(&az6007_usb_driver);
946}
947
948module_init(az6007_usb_module_init);
949module_exit(az6007_usb_module_exit);
950
951MODULE_AUTHOR("Henry Wang <Henry.wang@AzureWave.com>");
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -0300952MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300953MODULE_DESCRIPTION("Driver for AzureWave 6007 DVB-C/T USB2.0 and clones");
Mauro Carvalho Chehab35753582011-07-23 10:12:12 -0300954MODULE_VERSION("1.1");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300955MODULE_LICENSE("GPL");