blob: 9d2ad4965dee14e4a7360b4a2d76115deb0aa0fc [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 Chehab255d52f2012-08-04 16:05:34 -030027#include "dvb_usb.h"
28#include "cypress_firmware.h"
Mauro Carvalho Chehab70fa4442011-07-23 10:55:10 -030029
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -030030#define AZ6007_FIRMWARE "dvb-usb-terratec-h7-az6007.fw"
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030031
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -030032static int az6007_xfer_debug;
33module_param_named(xfer_debug, az6007_xfer_debug, int, 0644);
34MODULE_PARM_DESC(xfer_debug, "Enable xfer debug");
Mauro Carvalho Chehab70fa4442011-07-23 10:55:10 -030035
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030036DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
37
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -030038/* Known requests (Cypress FX2 firmware + az6007 "private" ones*/
39
40#define FX2_OED 0xb5
41#define AZ6007_READ_DATA 0xb7
42#define AZ6007_I2C_RD 0xb9
43#define AZ6007_POWER 0xbc
44#define AZ6007_I2C_WR 0xbd
45#define FX2_SCON1 0xc0
46#define AZ6007_TS_THROUGH 0xc7
Mauro Carvalho Chehab2d5161b2011-07-29 11:31:13 -030047#define AZ6007_READ_IR 0xb4
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -030048
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030049struct az6007_device_state {
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -030050 struct mutex mutex;
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -030051 struct mutex ca_mutex;
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -030052 struct dvb_ca_en50221 ca;
53 unsigned warm:1;
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -030054 int (*gate_ctrl) (struct dvb_frontend *, int);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -030055 unsigned char data[4096];
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030056};
57
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -030058static struct drxk_config terratec_h7_drxk = {
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030059 .adr = 0x29,
Mauro Carvalho Chehab6e5caf842012-01-20 18:36:26 -030060 .parallel_ts = true,
61 .dynamic_clk = true,
62 .single_master = true,
Mauro Carvalho Chehabd5856812012-01-21 07:57:06 -030063 .enable_merr_cfg = true,
Mauro Carvalho Chehab6e5caf842012-01-20 18:36:26 -030064 .no_i2c_bridge = false,
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -030065 .chunk_size = 64,
Mauro Carvalho Chehab6fb65a62012-01-20 19:13:07 -030066 .mpeg_out_clk_strength = 0x02,
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -030067 .microcode_name = "dvb-usb-terratec-h7-drxk.fw",
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030068};
69
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030070static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
71{
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -030072 struct az6007_device_state *st = fe_to_priv(fe);
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030073 struct dvb_usb_adapter *adap = fe->sec_priv;
Mauro Carvalho Chehabf2ba9e52011-07-23 11:54:40 -030074 int status = 0;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030075
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -030076 pr_debug("%s: %s\n", __func__, enable ? "enable" : "disable");
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -030077
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -030078 if (!adap || !st)
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -030079 return -EINVAL;
80
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -030081 if (enable)
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030082 status = st->gate_ctrl(fe, 1);
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -030083 else
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030084 status = st->gate_ctrl(fe, 0);
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -030085
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -030086 return status;
87}
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030088
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -030089static struct mt2063_config az6007_mt2063_config = {
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -030090 .tuner_address = 0x60,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030091 .refclock = 36125000,
92};
93
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -030094static int __az6007_read(struct usb_device *udev, u8 req, u16 value,
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -030095 u16 index, u8 *b, int blen)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030096{
Mauro Carvalho Chehab9b01f3d2011-07-29 11:40:40 -030097 int ret;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -030098
Mauro Carvalho Chehab3af2f4f2011-07-25 11:17:41 -030099 ret = usb_control_msg(udev,
100 usb_rcvctrlpipe(udev, 0),
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300101 req,
102 USB_TYPE_VENDOR | USB_DIR_IN,
103 value, index, b, blen, 5000);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300104 if (ret < 0) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300105 pr_warn("usb read operation failed. (%d)\n", ret);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300106 return -EIO;
107 }
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300108
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300109 if (az6007_xfer_debug) {
110 printk(KERN_DEBUG "az6007: IN req: %02x, value: %04x, index: %04x\n",
111 req, value, index);
112 print_hex_dump_bytes("az6007: payload: ",
113 DUMP_PREFIX_NONE, b, blen);
114 }
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300115
116 return ret;
117}
118
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300119static int az6007_read(struct dvb_usb_device *d, u8 req, u16 value,
120 u16 index, u8 *b, int blen)
121{
122 struct az6007_device_state *st = d->priv;
123 int ret;
124
125 if (mutex_lock_interruptible(&st->mutex) < 0)
126 return -EAGAIN;
127
128 ret = __az6007_read(d->udev, req, value, index, b, blen);
129
130 mutex_unlock(&st->mutex);
131
132 return ret;
133}
134
135static int __az6007_write(struct usb_device *udev, u8 req, u16 value,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300136 u16 index, u8 *b, int blen)
137{
138 int ret;
139
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300140 if (az6007_xfer_debug) {
141 printk(KERN_DEBUG "az6007: OUT req: %02x, value: %04x, index: %04x\n",
142 req, value, index);
143 print_hex_dump_bytes("az6007: payload: ",
144 DUMP_PREFIX_NONE, b, blen);
145 }
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300146
Mauro Carvalho Chehab35753582011-07-23 10:12:12 -0300147 if (blen > 64) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300148 pr_err("az6007: tried to write %d bytes, but I2C max size is 64 bytes\n",
149 blen);
Mauro Carvalho Chehab35753582011-07-23 10:12:12 -0300150 return -EOPNOTSUPP;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300151 }
Mauro Carvalho Chehab35753582011-07-23 10:12:12 -0300152
Mauro Carvalho Chehab3af2f4f2011-07-25 11:17:41 -0300153 ret = usb_control_msg(udev,
154 usb_sndctrlpipe(udev, 0),
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300155 req,
156 USB_TYPE_VENDOR | USB_DIR_OUT,
157 value, index, b, blen, 5000);
158 if (ret != blen) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300159 pr_err("usb write operation failed. (%d)\n", ret);
Mauro Carvalho Chehab35753582011-07-23 10:12:12 -0300160 return -EIO;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300161 }
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300162
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300163 return 0;
164}
165
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300166static int az6007_write(struct dvb_usb_device *d, u8 req, u16 value,
167 u16 index, u8 *b, int blen)
168{
169 struct az6007_device_state *st = d->priv;
170 int ret;
171
172 if (mutex_lock_interruptible(&st->mutex) < 0)
173 return -EAGAIN;
174
175 ret = __az6007_write(d->udev, req, value, index, b, blen);
176
177 mutex_unlock(&st->mutex);
178
179 return ret;
180}
181
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300182static int az6007_streaming_ctrl(struct dvb_frontend *fe, int onoff)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300183{
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300184 struct dvb_usb_device *d = fe_to_d(fe);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300185
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300186 pr_debug("%s: %s\n", __func__, onoff ? "enable" : "disable");
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300187
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300188 return az6007_write(d, 0xbc, onoff, 0, NULL, 0);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300189}
190
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300191/* remote control stuff (does not work with my box) */
Mauro Carvalho Chehabd3d076a2012-01-21 12:20:30 -0300192static int az6007_rc_query(struct dvb_usb_device *d)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300193{
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300194 struct az6007_device_state *st = d_to_priv(d);
Mauro Carvalho Chehab91651442012-01-21 12:14:13 -0300195 unsigned code = 0;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300196
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300197 az6007_read(d, AZ6007_READ_IR, 0, 0, st->data, 10);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300198
Mauro Carvalho Chehabd3d076a2012-01-21 12:20:30 -0300199 if (st->data[1] == 0x44)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300200 return 0;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300201
Mauro Carvalho Chehab91651442012-01-21 12:14:13 -0300202 if ((st->data[1] ^ st->data[2]) == 0xff)
203 code = st->data[1];
204 else
205 code = st->data[1] << 8 | st->data[2];
206
207 if ((st->data[3] ^ st->data[4]) == 0xff)
208 code = code << 8 | st->data[3];
209 else
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200210 code = code << 16 | st->data[3] << 8 | st->data[4];
Mauro Carvalho Chehab2d5161b2011-07-29 11:31:13 -0300211
Mauro Carvalho Chehabd3d076a2012-01-21 12:20:30 -0300212 rc_keydown(d->rc_dev, code, st->data[5]);
Mauro Carvalho Chehab2d5161b2011-07-29 11:31:13 -0300213
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300214 return 0;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300215}
216
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300217static int az6007_ci_read_attribute_mem(struct dvb_ca_en50221 *ca,
218 int slot,
219 int address)
220{
221 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300222 struct az6007_device_state *state = d_to_priv(d);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300223
224 int ret;
225 u8 req;
226 u16 value;
227 u16 index;
228 int blen;
229 u8 *b;
230
231 if (slot != 0)
232 return -EINVAL;
233
234 b = kmalloc(12, GFP_KERNEL);
235 if (!b)
236 return -ENOMEM;
237
238 mutex_lock(&state->ca_mutex);
239
240 req = 0xC1;
241 value = address;
242 index = 0;
243 blen = 1;
244
245 ret = az6007_read(d, req, value, index, b, blen);
246 if (ret < 0) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300247 pr_warn("usb in operation failed. (%d)\n", ret);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300248 ret = -EINVAL;
249 } else {
250 ret = b[0];
251 }
252
253 mutex_unlock(&state->ca_mutex);
254 kfree(b);
255 return ret;
256}
257
258static int az6007_ci_write_attribute_mem(struct dvb_ca_en50221 *ca,
259 int slot,
260 int address,
261 u8 value)
262{
263 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300264 struct az6007_device_state *state = d_to_priv(d);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300265
266 int ret;
267 u8 req;
268 u16 value1;
269 u16 index;
270 int blen;
271
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300272 pr_debug("%s(), slot %d\n", __func__, slot);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300273 if (slot != 0)
274 return -EINVAL;
275
276 mutex_lock(&state->ca_mutex);
277 req = 0xC2;
278 value1 = address;
279 index = value;
280 blen = 0;
281
282 ret = az6007_write(d, req, value1, index, NULL, blen);
283 if (ret != 0)
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300284 pr_warn("usb out operation failed. (%d)\n", ret);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300285
286 mutex_unlock(&state->ca_mutex);
287 return ret;
288}
289
290static int az6007_ci_read_cam_control(struct dvb_ca_en50221 *ca,
291 int slot,
292 u8 address)
293{
294 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300295 struct az6007_device_state *state = d_to_priv(d);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300296
297 int ret;
298 u8 req;
299 u16 value;
300 u16 index;
301 int blen;
302 u8 *b;
303
304 if (slot != 0)
305 return -EINVAL;
306
307 b = kmalloc(12, GFP_KERNEL);
308 if (!b)
309 return -ENOMEM;
310
311 mutex_lock(&state->ca_mutex);
312
313 req = 0xC3;
314 value = address;
315 index = 0;
316 blen = 2;
317
318 ret = az6007_read(d, req, value, index, b, blen);
319 if (ret < 0) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300320 pr_warn("usb in operation failed. (%d)\n", ret);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300321 ret = -EINVAL;
322 } else {
323 if (b[0] == 0)
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300324 pr_warn("Read CI IO error\n");
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300325
326 ret = b[1];
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300327 pr_debug("read cam data = %x from 0x%x\n", b[1], value);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300328 }
329
330 mutex_unlock(&state->ca_mutex);
331 kfree(b);
332 return ret;
333}
334
335static int az6007_ci_write_cam_control(struct dvb_ca_en50221 *ca,
336 int slot,
337 u8 address,
338 u8 value)
339{
340 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300341 struct az6007_device_state *state = d_to_priv(d);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300342
343 int ret;
344 u8 req;
345 u16 value1;
346 u16 index;
347 int blen;
348
349 if (slot != 0)
350 return -EINVAL;
351
352 mutex_lock(&state->ca_mutex);
353 req = 0xC4;
354 value1 = address;
355 index = value;
356 blen = 0;
357
358 ret = az6007_write(d, req, value1, index, NULL, blen);
359 if (ret != 0) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300360 pr_warn("usb out operation failed. (%d)\n", ret);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300361 goto failed;
362 }
363
364failed:
365 mutex_unlock(&state->ca_mutex);
366 return ret;
367}
368
369static int CI_CamReady(struct dvb_ca_en50221 *ca, int slot)
370{
371 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
372
373 int ret;
374 u8 req;
375 u16 value;
376 u16 index;
377 int blen;
378 u8 *b;
379
380 b = kmalloc(12, GFP_KERNEL);
381 if (!b)
382 return -ENOMEM;
383
384 req = 0xC8;
385 value = 0;
386 index = 0;
387 blen = 1;
388
389 ret = az6007_read(d, req, value, index, b, blen);
390 if (ret < 0) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300391 pr_warn("usb in operation failed. (%d)\n", ret);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300392 ret = -EIO;
393 } else{
394 ret = b[0];
395 }
396 kfree(b);
397 return ret;
398}
399
400static int az6007_ci_slot_reset(struct dvb_ca_en50221 *ca, int slot)
401{
402 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300403 struct az6007_device_state *state = d_to_priv(d);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300404
405 int ret, i;
406 u8 req;
407 u16 value;
408 u16 index;
409 int blen;
410
411 mutex_lock(&state->ca_mutex);
412
413 req = 0xC6;
414 value = 1;
415 index = 0;
416 blen = 0;
417
418 ret = az6007_write(d, req, value, index, NULL, blen);
419 if (ret != 0) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300420 pr_warn("usb out operation failed. (%d)\n", ret);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300421 goto failed;
422 }
423
424 msleep(500);
425 req = 0xC6;
426 value = 0;
427 index = 0;
428 blen = 0;
429
430 ret = az6007_write(d, req, value, index, NULL, blen);
431 if (ret != 0) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300432 pr_warn("usb out operation failed. (%d)\n", ret);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300433 goto failed;
434 }
435
436 for (i = 0; i < 15; i++) {
437 msleep(100);
438
439 if (CI_CamReady(ca, slot)) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300440 pr_debug("CAM Ready\n");
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300441 break;
442 }
443 }
444 msleep(5000);
445
446failed:
447 mutex_unlock(&state->ca_mutex);
448 return ret;
449}
450
451static int az6007_ci_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
452{
453 return 0;
454}
455
456static int az6007_ci_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
457{
458 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300459 struct az6007_device_state *state = d_to_priv(d);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300460
461 int ret;
462 u8 req;
463 u16 value;
464 u16 index;
465 int blen;
466
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300467 pr_debug("%s()\n", __func__);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300468 mutex_lock(&state->ca_mutex);
469 req = 0xC7;
470 value = 1;
471 index = 0;
472 blen = 0;
473
474 ret = az6007_write(d, req, value, index, NULL, blen);
475 if (ret != 0) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300476 pr_warn("usb out operation failed. (%d)\n", ret);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300477 goto failed;
478 }
479
480failed:
481 mutex_unlock(&state->ca_mutex);
482 return ret;
483}
484
485static int az6007_ci_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
486{
487 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300488 struct az6007_device_state *state = d_to_priv(d);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300489 int ret;
490 u8 req;
491 u16 value;
492 u16 index;
493 int blen;
494 u8 *b;
495
496 b = kmalloc(12, GFP_KERNEL);
497 if (!b)
498 return -ENOMEM;
499 mutex_lock(&state->ca_mutex);
500
501 req = 0xC5;
502 value = 0;
503 index = 0;
504 blen = 1;
505
506 ret = az6007_read(d, req, value, index, b, blen);
507 if (ret < 0) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300508 pr_warn("usb in operation failed. (%d)\n", ret);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300509 ret = -EIO;
510 } else
511 ret = 0;
512
513 if (!ret && b[0] == 1) {
514 ret = DVB_CA_EN50221_POLL_CAM_PRESENT |
515 DVB_CA_EN50221_POLL_CAM_READY;
516 }
517
518 mutex_unlock(&state->ca_mutex);
519 kfree(b);
520 return ret;
521}
522
523
524static void az6007_ci_uninit(struct dvb_usb_device *d)
525{
526 struct az6007_device_state *state;
527
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300528 pr_debug("%s()\n", __func__);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300529
530 if (NULL == d)
531 return;
532
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300533 state = d_to_priv(d);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300534 if (NULL == state)
535 return;
536
537 if (NULL == state->ca.data)
538 return;
539
540 dvb_ca_en50221_release(&state->ca);
541
542 memset(&state->ca, 0, sizeof(state->ca));
543}
544
545
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300546static int az6007_ci_init(struct dvb_usb_adapter *adap)
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300547{
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300548 struct dvb_usb_device *d = adap_to_d(adap);
549 struct az6007_device_state *state = adap_to_priv(adap);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300550 int ret;
551
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300552 pr_debug("%s()\n", __func__);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300553
554 mutex_init(&state->ca_mutex);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300555 state->ca.owner = THIS_MODULE;
556 state->ca.read_attribute_mem = az6007_ci_read_attribute_mem;
557 state->ca.write_attribute_mem = az6007_ci_write_attribute_mem;
558 state->ca.read_cam_control = az6007_ci_read_cam_control;
559 state->ca.write_cam_control = az6007_ci_write_cam_control;
560 state->ca.slot_reset = az6007_ci_slot_reset;
561 state->ca.slot_shutdown = az6007_ci_slot_shutdown;
562 state->ca.slot_ts_enable = az6007_ci_slot_ts_enable;
563 state->ca.poll_slot_status = az6007_ci_poll_slot_status;
564 state->ca.data = d;
565
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300566 ret = dvb_ca_en50221_init(&adap->dvb_adap,
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300567 &state->ca,
568 0, /* flags */
569 1);/* n_slots */
570 if (ret != 0) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300571 pr_err("Cannot initialize CI: Error %d.\n", ret);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300572 memset(&state->ca, 0, sizeof(state->ca));
573 return ret;
574 }
575
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300576 pr_debug("CI initialized.\n");
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300577
578 return 0;
579}
580
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300581static int az6007_read_mac_addr(struct dvb_usb_adapter *adap, u8 mac[6])
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300582{
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300583 struct dvb_usb_device *d = adap_to_d(adap);
584 struct az6007_device_state *st = adap_to_priv(adap);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300585 int ret;
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300586
587 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
Alan Cox5a7a5702012-07-24 12:02:46 -0300588 memcpy(mac, st->data, 6);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300589
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300590 if (ret > 0)
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300591 pr_debug("%s: mac is %pM\n", __func__, mac);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300592
593 return ret;
594}
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300595
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300596static int az6007_frontend_attach(struct dvb_usb_adapter *adap)
597{
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300598 struct az6007_device_state *st = adap_to_priv(adap);
599 struct dvb_usb_device *d = adap_to_d(adap);
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300600
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300601 pr_debug("attaching demod drxk\n");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300602
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300603 adap->fe[0] = dvb_attach(drxk_attach, &terratec_h7_drxk,
604 &d->i2c_adap);
605 if (!adap->fe[0])
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300606 return -EINVAL;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300607
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300608 adap->fe[0]->sec_priv = adap;
609 st->gate_ctrl = adap->fe[0]->ops.i2c_gate_ctrl;
610 adap->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Mauro Carvalho Chehabda989e02011-07-24 09:25:39 -0300611
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300612 az6007_ci_init(adap);
613
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300614 return 0;
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300615}
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300616
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300617static int az6007_tuner_attach(struct dvb_usb_adapter *adap)
618{
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300619 struct dvb_usb_device *d = adap_to_d(adap);
620
621 pr_debug("attaching tuner mt2063\n");
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -0300622
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300623 /* Attach mt2063 to DVB-C frontend */
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300624 if (adap->fe[0]->ops.i2c_gate_ctrl)
625 adap->fe[0]->ops.i2c_gate_ctrl(adap->fe[0], 1);
626 if (!dvb_attach(mt2063_attach, adap->fe[0],
Mauro Carvalho Chehab781dacc2012-01-16 18:57:51 -0300627 &az6007_mt2063_config,
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300628 &d->i2c_adap))
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300629 return -EINVAL;
630
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300631 if (adap->fe[0]->ops.i2c_gate_ctrl)
632 adap->fe[0]->ops.i2c_gate_ctrl(adap->fe[0], 0);
Mauro Carvalho Chehab1c9a2842011-07-31 10:11:32 -0300633
634 return 0;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300635}
636
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300637int az6007_power_ctrl(struct dvb_usb_device *d, int onoff)
638{
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300639 struct az6007_device_state *st = d_to_priv(d);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300640 int ret;
641
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300642 pr_debug("%s()\n", __func__);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300643
644 if (!st->warm) {
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300645 mutex_init(&st->mutex);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300646
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300647 ret = az6007_write(d, AZ6007_POWER, 0, 2, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300648 if (ret < 0)
649 return ret;
650 msleep(60);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300651 ret = az6007_write(d, AZ6007_POWER, 1, 4, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300652 if (ret < 0)
653 return ret;
654 msleep(100);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300655 ret = az6007_write(d, AZ6007_POWER, 1, 3, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300656 if (ret < 0)
657 return ret;
658 msleep(20);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300659 ret = az6007_write(d, AZ6007_POWER, 1, 4, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300660 if (ret < 0)
661 return ret;
662
663 msleep(400);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300664 ret = az6007_write(d, FX2_SCON1, 0, 3, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300665 if (ret < 0)
666 return ret;
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200667 msleep(150);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300668 ret = az6007_write(d, FX2_SCON1, 1, 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(430);
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300672 ret = az6007_write(d, AZ6007_POWER, 0, 0, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300673 if (ret < 0)
674 return ret;
675
676 st->warm = true;
677
678 return 0;
679 }
680
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300681 if (!onoff)
682 return 0;
683
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300684 az6007_write(d, AZ6007_POWER, 0, 0, NULL, 0);
685 az6007_write(d, AZ6007_TS_THROUGH, 0, 0, NULL, 0);
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300686
Mauro Carvalho Chehab81091142011-07-25 11:07:20 -0300687 return 0;
688}
689
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300690/* I2C */
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300691static int az6007_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
692 int num)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300693{
694 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300695 struct az6007_device_state *st = d_to_priv(d);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300696 int i, j, len;
697 int ret = 0;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300698 u16 index;
699 u16 value;
700 int length;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300701 u8 req, addr;
Mauro Carvalho Chehab6da34702011-07-21 18:31:14 -0300702
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300703 if (mutex_lock_interruptible(&st->mutex) < 0)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300704 return -EAGAIN;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300705
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300706 for (i = 0; i < num; i++) {
707 addr = msgs[i].addr << 1;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300708 if (((i + 1) < num)
709 && (msgs[i].len == 1)
710 && (!msgs[i].flags & I2C_M_RD)
711 && (msgs[i + 1].flags & I2C_M_RD)
712 && (msgs[i].addr == msgs[i + 1].addr)) {
713 /*
714 * A write + read xfer for the same address, where
715 * the first xfer has just 1 byte length.
716 * Need to join both into one operation
717 */
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300718 if (az6007_xfer_debug)
719 printk(KERN_DEBUG "az6007: I2C W/R addr=0x%x len=%d/%d\n",
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300720 addr, msgs[i].len, msgs[i + 1].len);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300721 req = AZ6007_I2C_RD;
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300722 index = msgs[i].buf[0];
723 value = addr | (1 << 8);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300724 length = 6 + msgs[i + 1].len;
725 len = msgs[i + 1].len;
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200726 ret = __az6007_read(d->udev, req, value, index,
727 st->data, length);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300728 if (ret >= len) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300729 for (j = 0; j < len; j++)
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300730 msgs[i + 1].buf[j] = st->data[j + 5];
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300731 } else
732 ret = -EIO;
733 i++;
734 } else if (!(msgs[i].flags & I2C_M_RD)) {
735 /* write bytes */
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300736 if (az6007_xfer_debug)
737 printk(KERN_DEBUG "az6007: I2C W addr=0x%x len=%d\n",
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300738 addr, msgs[i].len);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300739 req = AZ6007_I2C_WR;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300740 index = msgs[i].buf[0];
741 value = addr | (1 << 8);
742 length = msgs[i].len - 1;
743 len = msgs[i].len - 1;
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300744 for (j = 0; j < len; j++)
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300745 st->data[j] = msgs[i].buf[j + 1];
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200746 ret = __az6007_write(d->udev, req, value, index,
747 st->data, length);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300748 } else {
749 /* read bytes */
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300750 if (az6007_xfer_debug)
751 printk(KERN_DEBUG "az6007: I2C R addr=0x%x len=%d\n",
Mauro Carvalho Chehabd20a7f72011-07-23 09:51:12 -0300752 addr, msgs[i].len);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300753 req = AZ6007_I2C_RD;
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300754 index = msgs[i].buf[0];
755 value = addr;
756 length = msgs[i].len + 6;
757 len = msgs[i].len;
Mauro Carvalho Chehab9e5e3092012-01-21 13:52:39 -0200758 ret = __az6007_read(d->udev, req, value, index,
759 st->data, length);
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300760 for (j = 0; j < len; j++)
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300761 msgs[i].buf[j] = st->data[j + 5];
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300762 }
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300763 if (ret < 0)
764 goto err;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300765 }
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300766err:
Mauro Carvalho Chehaba2c35d32012-01-21 11:19:16 -0300767 mutex_unlock(&st->mutex);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300768
769 if (ret < 0) {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300770 pr_info("%s ERROR: %i\n", __func__, ret);
Mauro Carvalho Chehabcaa1a702011-07-22 10:31:25 -0300771 return ret;
772 }
773 return num;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300774}
775
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300776static u32 az6007_i2c_func(struct i2c_adapter *adapter)
777{
778 return I2C_FUNC_I2C;
779}
780
781static struct i2c_algorithm az6007_i2c_algo = {
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300782 .master_xfer = az6007_i2c_xfer,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300783 .functionality = az6007_i2c_func,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300784};
785
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300786int az6007_identify_state(struct dvb_usb_device *d, const char **name)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300787{
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300788 int ret;
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300789 u8 *mac;
790
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300791 pr_debug("Identifying az6007 state\n");
792
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300793 mac = kmalloc(6, GFP_ATOMIC);
794 if (!mac)
795 return -ENOMEM;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300796
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300797 /* Try to read the mac address */
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300798 ret = __az6007_read(d->udev, AZ6007_READ_DATA, 6, 0, mac, 6);
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300799 if (ret == 6)
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300800 ret = WARM;
Mauro Carvalho Chehab3aecf2c2011-07-25 12:45:16 -0300801 else
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300802 ret = COLD;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300803
Mauro Carvalho Chehab711e1392012-01-21 11:53:18 -0300804 kfree(mac);
805
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300806 if (ret == COLD) {
807 __az6007_write(d->udev, 0x09, 1, 0, NULL, 0);
808 __az6007_write(d->udev, 0x00, 0, 0, NULL, 0);
809 __az6007_write(d->udev, 0x00, 0, 0, NULL, 0);
Mauro Carvalho Chehabb19280c2012-01-20 18:37:01 -0300810 }
811
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300812 pr_debug("Device is on %s state\n",
813 ret == WARM ? "warm" : "cold");
814 return ret;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300815}
816
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300817static void az6007_usb_disconnect(struct usb_interface *intf)
818{
819 struct dvb_usb_device *d = usb_get_intfdata(intf);
820 az6007_ci_uninit(d);
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300821 dvb_usbv2_disconnect(intf);
Jose Alberto Reguero962f8f62012-03-04 19:22:05 -0300822}
823
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300824static int az6007_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300825{
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300826 pr_debug("Getting az6007 Remote Control properties\n");
827
828 rc->allowed_protos = RC_TYPE_NEC;
829 rc->query = az6007_rc_query;
830 rc->interval = 400;
831
832 return 0;
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300833}
834
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300835static int az6007_download_firmware(struct dvb_usb_device *d,
836 const struct firmware *fw)
837{
838 pr_debug("Loading az6007 firmware\n");
839
840 return usbv2_cypress_load_firmware(d->udev, fw, CYPRESS_FX2);
841}
842
843/* DVB USB Driver stuff */
844static struct dvb_usb_device_properties az6007_props = {
845 .driver_name = KBUILD_MODNAME,
846 .owner = THIS_MODULE,
847 .firmware = AZ6007_FIRMWARE,
848
849 .adapter_nr = adapter_nr,
850 .size_of_priv = sizeof(struct az6007_device_state),
851 .i2c_algo = &az6007_i2c_algo,
852 .tuner_attach = az6007_tuner_attach,
853 .frontend_attach = az6007_frontend_attach,
854 .streaming_ctrl = az6007_streaming_ctrl,
855 .get_rc_config = az6007_get_rc_config,
856 .read_mac_address = az6007_read_mac_addr,
857 .download_firmware = az6007_download_firmware,
858 .identify_state = az6007_identify_state,
859 .power_ctrl = az6007_power_ctrl,
860 .num_adapters = 1,
861 .adapter = {
862 { .stream = DVB_USB_STREAM_BULK(0x02, 10, 4096), }
863 }
864};
865
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300866static struct usb_device_id az6007_usb_table[] = {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300867 {DVB_USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_6007,
868 &az6007_props, "Azurewave 6007", RC_MAP_EMPTY)},
869 {DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_H7,
870 &az6007_props, "Terratec H7", RC_MAP_NEC_TERRATEC_CINERGY_XS)},
871 {DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_H7_2,
872 &az6007_props, "Terratec H7", RC_MAP_NEC_TERRATEC_CINERGY_XS)},
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300873 {0},
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300874};
875
876MODULE_DEVICE_TABLE(usb, az6007_usb_table);
877
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300878/* usb specific object needed to register this driver with the usb subsystem */
879static struct usb_driver az6007_usb_driver = {
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300880 .name = KBUILD_MODNAME,
Mauro Carvalho Chehab93b32122011-07-23 10:40:08 -0300881 .id_table = az6007_usb_table,
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300882 .probe = dvb_usbv2_probe,
883 .disconnect = az6007_usb_disconnect,
884 .suspend = dvb_usbv2_suspend,
885 .resume = dvb_usbv2_resume,
886 .no_dynamic_id = 1,
887 .soft_unbind = 1,
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300888};
889
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300890module_usb_driver(az6007_usb_driver);
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300891
892MODULE_AUTHOR("Henry Wang <Henry.wang@AzureWave.com>");
Mauro Carvalho Chehab04e3ece2012-01-21 10:35:12 -0300893MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300894MODULE_DESCRIPTION("Driver for AzureWave 6007 DVB-C/T USB2.0 and clones");
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300895MODULE_VERSION("2.0");
Mauro Carvalho Chehab71d67632011-07-21 17:46:41 -0300896MODULE_LICENSE("GPL");
Mauro Carvalho Chehab255d52f2012-08-04 16:05:34 -0300897MODULE_FIRMWARE(AZ6007_FIRMWARE);