blob: 0638d907c73e4162b1f0608a63b45b26cc220554 [file] [log] [blame]
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001/* DVB USB compliant Linux driver for the Afatech 9005
2 * USB1.1 DVB-T receiver.
3 *
4 * Copyright (C) 2007 Luca Olivetti (luca@ventoso.org)
5 *
6 * Thanks to Afatech who kindly provided information.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
Mauro Carvalho Chehab670d7adb2018-05-08 18:29:30 -030018 * see Documentation/media/dvb-drivers/dvb-usb.rst for more information
Luca Olivettiaf4e0672007-05-07 15:19:32 -030019 */
20#include "af9005.h"
21
22/* debug */
23int dvb_usb_af9005_debug;
24module_param_named(debug, dvb_usb_af9005_debug, int, 0644);
25MODULE_PARM_DESC(debug,
26 "set debugging level (1=info,xfer=2,rc=4,reg=8,i2c=16,fw=32 (or-able))."
27 DVB_USB_DEBUG_STATUS);
28/* enable obnoxious led */
Mauro Carvalho Chehab61f6a052014-09-03 16:18:48 -030029bool dvb_usb_af9005_led = true;
Luca Olivettiaf4e0672007-05-07 15:19:32 -030030module_param_named(led, dvb_usb_af9005_led, bool, 0644);
31MODULE_PARM_DESC(led, "enable led (default: 1).");
32
33/* eeprom dump */
Hans Verkuild45b9b82008-09-04 03:33:43 -030034static int dvb_usb_af9005_dump_eeprom;
Luca Olivettiaf4e0672007-05-07 15:19:32 -030035module_param_named(dump_eeprom, dvb_usb_af9005_dump_eeprom, int, 0);
36MODULE_PARM_DESC(dump_eeprom, "dump contents of the eeprom.");
37
Janne Grunau78e920062008-04-09 19:13:13 -030038DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
39
Luca Olivettiaf4e0672007-05-07 15:19:32 -030040/* remote control decoder */
Hans Verkuild45b9b82008-09-04 03:33:43 -030041static int (*rc_decode) (struct dvb_usb_device *d, u8 *data, int len,
42 u32 *event, int *state);
43static void *rc_keys;
44static int *rc_keys_size;
Luca Olivettiaf4e0672007-05-07 15:19:32 -030045
46u8 regmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
47
48struct af9005_device_state {
49 u8 sequence;
50 int led_state;
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -030051 unsigned char data[256];
Luca Olivettiaf4e0672007-05-07 15:19:32 -030052};
53
Hans Verkuild45b9b82008-09-04 03:33:43 -030054static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
Luca Olivettiaf4e0672007-05-07 15:19:32 -030055 int readwrite, int type, u8 * values, int len)
56{
57 struct af9005_device_state *st = d->priv;
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -030058 u8 command, seq;
59 int i, ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -030060
61 if (len < 1) {
62 err("generic read/write, less than 1 byte. Makes no sense.");
63 return -EINVAL;
64 }
65 if (len > 8) {
66 err("generic read/write, more than 8 bytes. Not supported.");
67 return -EINVAL;
68 }
69
Mauro Carvalho Chehab77243252016-11-12 12:46:26 -020070 mutex_lock(&d->data_mutex);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -030071 st->data[0] = 14; /* rest of buffer length low */
72 st->data[1] = 0; /* rest of buffer length high */
Luca Olivettiaf4e0672007-05-07 15:19:32 -030073
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -030074 st->data[2] = AF9005_REGISTER_RW; /* register operation */
75 st->data[3] = 12; /* rest of buffer length */
Luca Olivettiaf4e0672007-05-07 15:19:32 -030076
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -030077 st->data[4] = seq = st->sequence++; /* sequence number */
Luca Olivettiaf4e0672007-05-07 15:19:32 -030078
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -030079 st->data[5] = (u8) (reg >> 8); /* register address */
80 st->data[6] = (u8) (reg & 0xff);
Luca Olivettiaf4e0672007-05-07 15:19:32 -030081
82 if (type == AF9005_OFDM_REG) {
83 command = AF9005_CMD_OFDM_REG;
84 } else {
85 command = AF9005_CMD_TUNER;
86 }
87
88 if (len > 1)
89 command |=
90 AF9005_CMD_BURST | AF9005_CMD_AUTOINC | (len - 1) << 3;
91 command |= readwrite;
92 if (readwrite == AF9005_CMD_WRITE)
93 for (i = 0; i < len; i++)
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -030094 st->data[8 + i] = values[i];
Luca Olivettiaf4e0672007-05-07 15:19:32 -030095 else if (type == AF9005_TUNER_REG)
96 /* read command for tuner, the first byte contains the i2c address */
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -030097 st->data[8] = values[0];
98 st->data[7] = command;
Luca Olivettiaf4e0672007-05-07 15:19:32 -030099
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300100 ret = dvb_usb_generic_rw(d, st->data, 16, st->data, 17, 0);
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300101 if (ret)
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300102 goto ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300103
104 /* sanity check */
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300105 if (st->data[2] != AF9005_REGISTER_RW_ACK) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300106 err("generic read/write, wrong reply code.");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300107 ret = -EIO;
108 goto ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300109 }
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300110 if (st->data[3] != 0x0d) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300111 err("generic read/write, wrong length in reply.");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300112 ret = -EIO;
113 goto ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300114 }
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300115 if (st->data[4] != seq) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300116 err("generic read/write, wrong sequence in reply.");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300117 ret = -EIO;
118 goto ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300119 }
120 /*
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300121 * In thesis, both input and output buffers should have
122 * identical values for st->data[5] to st->data[8].
123 * However, windows driver doesn't check these fields, in fact
124 * sometimes the register in the reply is different that what
125 * has been sent
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300126 */
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300127 if (st->data[16] != 0x01) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300128 err("generic read/write wrong status code in reply.");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300129 ret = -EIO;
130 goto ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300131 }
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300132
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300133 if (readwrite == AF9005_CMD_READ)
134 for (i = 0; i < len; i++)
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300135 values[i] = st->data[8 + i];
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300136
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300137ret:
Mauro Carvalho Chehab77243252016-11-12 12:46:26 -0200138 mutex_unlock(&d->data_mutex);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300139 return ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300140
141}
142
143int af9005_read_ofdm_register(struct dvb_usb_device *d, u16 reg, u8 * value)
144{
145 int ret;
146 deb_reg("read register %x ", reg);
147 ret = af9005_generic_read_write(d, reg,
148 AF9005_CMD_READ, AF9005_OFDM_REG,
149 value, 1);
150 if (ret)
151 deb_reg("failed\n");
152 else
153 deb_reg("value %x\n", *value);
154 return ret;
155}
156
157int af9005_read_ofdm_registers(struct dvb_usb_device *d, u16 reg,
158 u8 * values, int len)
159{
160 int ret;
161 deb_reg("read %d registers %x ", len, reg);
162 ret = af9005_generic_read_write(d, reg,
163 AF9005_CMD_READ, AF9005_OFDM_REG,
164 values, len);
165 if (ret)
166 deb_reg("failed\n");
167 else
168 debug_dump(values, len, deb_reg);
169 return ret;
170}
171
172int af9005_write_ofdm_register(struct dvb_usb_device *d, u16 reg, u8 value)
173{
174 int ret;
175 u8 temp = value;
176 deb_reg("write register %x value %x ", reg, value);
177 ret = af9005_generic_read_write(d, reg,
178 AF9005_CMD_WRITE, AF9005_OFDM_REG,
179 &temp, 1);
180 if (ret)
181 deb_reg("failed\n");
182 else
183 deb_reg("ok\n");
184 return ret;
185}
186
187int af9005_write_ofdm_registers(struct dvb_usb_device *d, u16 reg,
188 u8 * values, int len)
189{
190 int ret;
191 deb_reg("write %d registers %x values ", len, reg);
192 debug_dump(values, len, deb_reg);
193
194 ret = af9005_generic_read_write(d, reg,
195 AF9005_CMD_WRITE, AF9005_OFDM_REG,
196 values, len);
197 if (ret)
198 deb_reg("failed\n");
199 else
200 deb_reg("ok\n");
201 return ret;
202}
203
204int af9005_read_register_bits(struct dvb_usb_device *d, u16 reg, u8 pos,
205 u8 len, u8 * value)
206{
207 u8 temp;
208 int ret;
209 deb_reg("read bits %x %x %x", reg, pos, len);
210 ret = af9005_read_ofdm_register(d, reg, &temp);
211 if (ret) {
212 deb_reg(" failed\n");
213 return ret;
214 }
215 *value = (temp >> pos) & regmask[len - 1];
216 deb_reg(" value %x\n", *value);
217 return 0;
218
219}
220
221int af9005_write_register_bits(struct dvb_usb_device *d, u16 reg, u8 pos,
222 u8 len, u8 value)
223{
224 u8 temp, mask;
225 int ret;
226 deb_reg("write bits %x %x %x value %x\n", reg, pos, len, value);
227 if (pos == 0 && len == 8)
228 return af9005_write_ofdm_register(d, reg, value);
229 ret = af9005_read_ofdm_register(d, reg, &temp);
230 if (ret)
231 return ret;
232 mask = regmask[len - 1] << pos;
233 temp = (temp & ~mask) | ((value << pos) & mask);
234 return af9005_write_ofdm_register(d, reg, temp);
235
236}
237
238static int af9005_usb_read_tuner_registers(struct dvb_usb_device *d,
239 u16 reg, u8 * values, int len)
240{
241 return af9005_generic_read_write(d, reg,
242 AF9005_CMD_READ, AF9005_TUNER_REG,
243 values, len);
244}
245
246static int af9005_usb_write_tuner_registers(struct dvb_usb_device *d,
247 u16 reg, u8 * values, int len)
248{
249 return af9005_generic_read_write(d, reg,
250 AF9005_CMD_WRITE,
251 AF9005_TUNER_REG, values, len);
252}
253
254int af9005_write_tuner_registers(struct dvb_usb_device *d, u16 reg,
255 u8 * values, int len)
256{
257 /* don't let the name of this function mislead you: it's just used
258 as an interface from the firmware to the i2c bus. The actual
259 i2c addresses are contained in the data */
260 int ret, i, done = 0, fail = 0;
261 u8 temp;
262 ret = af9005_usb_write_tuner_registers(d, reg, values, len);
263 if (ret)
264 return ret;
265 if (reg != 0xffff) {
266 /* check if write done (0xa40d bit 1) or fail (0xa40d bit 2) */
267 for (i = 0; i < 200; i++) {
268 ret =
269 af9005_read_ofdm_register(d,
270 xd_I2C_i2c_m_status_wdat_done,
271 &temp);
272 if (ret)
273 return ret;
274 done = temp & (regmask[i2c_m_status_wdat_done_len - 1]
275 << i2c_m_status_wdat_done_pos);
276 if (done)
277 break;
278 fail = temp & (regmask[i2c_m_status_wdat_fail_len - 1]
279 << i2c_m_status_wdat_fail_pos);
280 if (fail)
281 break;
282 msleep(50);
283 }
284 if (i == 200)
285 return -ETIMEDOUT;
286 if (fail) {
287 /* clear write fail bit */
288 af9005_write_register_bits(d,
289 xd_I2C_i2c_m_status_wdat_fail,
290 i2c_m_status_wdat_fail_pos,
291 i2c_m_status_wdat_fail_len,
292 1);
293 return -EIO;
294 }
295 /* clear write done bit */
296 ret =
297 af9005_write_register_bits(d,
298 xd_I2C_i2c_m_status_wdat_fail,
299 i2c_m_status_wdat_done_pos,
300 i2c_m_status_wdat_done_len, 1);
301 if (ret)
302 return ret;
303 }
304 return 0;
305}
306
307int af9005_read_tuner_registers(struct dvb_usb_device *d, u16 reg, u8 addr,
308 u8 * values, int len)
309{
310 /* don't let the name of this function mislead you: it's just used
311 as an interface from the firmware to the i2c bus. The actual
312 i2c addresses are contained in the data */
313 int ret, i;
314 u8 temp, buf[2];
315
316 buf[0] = addr; /* tuner i2c address */
317 buf[1] = values[0]; /* tuner register */
318
319 values[0] = addr + 0x01; /* i2c read address */
320
321 if (reg == APO_REG_I2C_RW_SILICON_TUNER) {
322 /* write tuner i2c address to tuner, 0c00c0 undocumented, found by sniffing */
323 ret = af9005_write_tuner_registers(d, 0x00c0, buf, 2);
324 if (ret)
325 return ret;
326 }
327
328 /* send read command to ofsm */
329 ret = af9005_usb_read_tuner_registers(d, reg, values, 1);
330 if (ret)
331 return ret;
332
333 /* check if read done */
334 for (i = 0; i < 200; i++) {
335 ret = af9005_read_ofdm_register(d, 0xa408, &temp);
336 if (ret)
337 return ret;
338 if (temp & 0x01)
339 break;
340 msleep(50);
341 }
342 if (i == 200)
343 return -ETIMEDOUT;
344
345 /* clear read done bit (by writing 1) */
346 ret = af9005_write_ofdm_register(d, xd_I2C_i2c_m_data8, 1);
347 if (ret)
348 return ret;
349
350 /* get read data (available from 0xa400) */
351 for (i = 0; i < len; i++) {
352 ret = af9005_read_ofdm_register(d, 0xa400 + i, &temp);
353 if (ret)
354 return ret;
355 values[i] = temp;
356 }
357 return 0;
358}
359
360static int af9005_i2c_write(struct dvb_usb_device *d, u8 i2caddr, u8 reg,
361 u8 * data, int len)
362{
363 int ret, i;
364 u8 buf[3];
365 deb_i2c("i2c_write i2caddr %x, reg %x, len %d data ", i2caddr,
366 reg, len);
367 debug_dump(data, len, deb_i2c);
368
369 for (i = 0; i < len; i++) {
370 buf[0] = i2caddr;
371 buf[1] = reg + (u8) i;
372 buf[2] = data[i];
373 ret =
374 af9005_write_tuner_registers(d,
375 APO_REG_I2C_RW_SILICON_TUNER,
376 buf, 3);
377 if (ret) {
378 deb_i2c("i2c_write failed\n");
379 return ret;
380 }
381 }
382 deb_i2c("i2c_write ok\n");
383 return 0;
384}
385
386static int af9005_i2c_read(struct dvb_usb_device *d, u8 i2caddr, u8 reg,
387 u8 * data, int len)
388{
389 int ret, i;
390 u8 temp;
391 deb_i2c("i2c_read i2caddr %x, reg %x, len %d\n ", i2caddr, reg, len);
392 for (i = 0; i < len; i++) {
393 temp = reg + i;
394 ret =
395 af9005_read_tuner_registers(d,
396 APO_REG_I2C_RW_SILICON_TUNER,
397 i2caddr, &temp, 1);
398 if (ret) {
399 deb_i2c("i2c_read failed\n");
400 return ret;
401 }
402 data[i] = temp;
403 }
404 deb_i2c("i2c data read: ");
405 debug_dump(data, len, deb_i2c);
406 return 0;
407}
408
409static int af9005_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
410 int num)
411{
412 /* only implements what the mt2060 module does, don't know how
413 to make it really generic */
414 struct dvb_usb_device *d = i2c_get_adapdata(adap);
415 int ret;
416 u8 reg, addr;
417 u8 *value;
418
419 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
420 return -EAGAIN;
421
422 if (num > 2)
423 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
424
425 if (num == 2) {
426 /* reads a single register */
427 reg = *msg[0].buf;
428 addr = msg[0].addr;
429 value = msg[1].buf;
430 ret = af9005_i2c_read(d, addr, reg, value, 1);
431 if (ret == 0)
432 ret = 2;
433 } else {
434 /* write one or more registers */
435 reg = msg[0].buf[0];
436 addr = msg[0].addr;
437 value = &msg[0].buf[1];
438 ret = af9005_i2c_write(d, addr, reg, value, msg[0].len - 1);
439 if (ret == 0)
440 ret = 1;
441 }
442
443 mutex_unlock(&d->i2c_mutex);
444 return ret;
445}
446
447static u32 af9005_i2c_func(struct i2c_adapter *adapter)
448{
449 return I2C_FUNC_I2C;
450}
451
452static struct i2c_algorithm af9005_i2c_algo = {
453 .master_xfer = af9005_i2c_xfer,
454 .functionality = af9005_i2c_func,
455};
456
457int af9005_send_command(struct dvb_usb_device *d, u8 command, u8 * wbuf,
458 int wlen, u8 * rbuf, int rlen)
459{
460 struct af9005_device_state *st = d->priv;
461
462 int ret, i, packet_len;
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300463 u8 seq;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300464
465 if (wlen < 0) {
466 err("send command, wlen less than 0 bytes. Makes no sense.");
467 return -EINVAL;
468 }
469 if (wlen > 54) {
470 err("send command, wlen more than 54 bytes. Not supported.");
471 return -EINVAL;
472 }
473 if (rlen > 54) {
474 err("send command, rlen more than 54 bytes. Not supported.");
475 return -EINVAL;
476 }
477 packet_len = wlen + 5;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300478
Mauro Carvalho Chehab77243252016-11-12 12:46:26 -0200479 mutex_lock(&d->data_mutex);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300480
481 st->data[0] = (u8) (packet_len & 0xff);
482 st->data[1] = (u8) ((packet_len & 0xff00) >> 8);
483
484 st->data[2] = 0x26; /* packet type */
485 st->data[3] = wlen + 3;
486 st->data[4] = seq = st->sequence++;
487 st->data[5] = command;
488 st->data[6] = wlen;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300489 for (i = 0; i < wlen; i++)
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300490 st->data[7 + i] = wbuf[i];
491 ret = dvb_usb_generic_rw(d, st->data, wlen + 7, st->data, rlen + 7, 0);
492 if (st->data[2] != 0x27) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300493 err("send command, wrong reply code.");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300494 ret = -EIO;
495 } else if (st->data[4] != seq) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300496 err("send command, wrong sequence in reply.");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300497 ret = -EIO;
498 } else if (st->data[5] != 0x01) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300499 err("send command, wrong status code in reply.");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300500 ret = -EIO;
501 } else if (st->data[6] != rlen) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300502 err("send command, invalid data length in reply.");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300503 ret = -EIO;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300504 }
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300505 if (!ret) {
506 for (i = 0; i < rlen; i++)
507 rbuf[i] = st->data[i + 7];
508 }
509
Mauro Carvalho Chehab77243252016-11-12 12:46:26 -0200510 mutex_unlock(&d->data_mutex);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300511 return ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300512}
513
514int af9005_read_eeprom(struct dvb_usb_device *d, u8 address, u8 * values,
515 int len)
516{
517 struct af9005_device_state *st = d->priv;
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300518 u8 seq;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300519 int ret, i;
520
Mauro Carvalho Chehab77243252016-11-12 12:46:26 -0200521 mutex_lock(&d->data_mutex);
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300522
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300523 memset(st->data, 0, sizeof(st->data));
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300524
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300525 st->data[0] = 14; /* length of rest of packet low */
526 st->data[1] = 0; /* length of rest of packer high */
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300527
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300528 st->data[2] = 0x2a; /* read/write eeprom */
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300529
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300530 st->data[3] = 12; /* size */
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300531
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300532 st->data[4] = seq = st->sequence++;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300533
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300534 st->data[5] = 0; /* read */
535
536 st->data[6] = len;
537 st->data[7] = address;
538 ret = dvb_usb_generic_rw(d, st->data, 16, st->data, 14, 0);
539 if (st->data[2] != 0x2b) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300540 err("Read eeprom, invalid reply code");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300541 ret = -EIO;
542 } else if (st->data[3] != 10) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300543 err("Read eeprom, invalid reply length");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300544 ret = -EIO;
545 } else if (st->data[4] != seq) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300546 err("Read eeprom, wrong sequence in reply ");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300547 ret = -EIO;
548 } else if (st->data[5] != 1) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300549 err("Read eeprom, wrong status in reply ");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300550 ret = -EIO;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300551 }
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300552
553 if (!ret) {
554 for (i = 0; i < len; i++)
555 values[i] = st->data[6 + i];
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300556 }
Mauro Carvalho Chehab77243252016-11-12 12:46:26 -0200557 mutex_unlock(&d->data_mutex);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300558
559 return ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300560}
561
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300562static int af9005_boot_packet(struct usb_device *udev, int type, u8 *reply,
563 u8 *buf, int size)
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300564{
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300565 u16 checksum;
566 int act_len, i, ret;
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300567
568 memset(buf, 0, size);
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300569 buf[0] = (u8) (FW_BULKOUT_SIZE & 0xff);
570 buf[1] = (u8) ((FW_BULKOUT_SIZE >> 8) & 0xff);
571 switch (type) {
572 case FW_CONFIG:
573 buf[2] = 0x11;
574 buf[3] = 0x04;
575 buf[4] = 0x00; /* sequence number, original driver doesn't increment it here */
576 buf[5] = 0x03;
577 checksum = buf[4] + buf[5];
578 buf[6] = (u8) ((checksum >> 8) & 0xff);
579 buf[7] = (u8) (checksum & 0xff);
580 break;
581 case FW_CONFIRM:
582 buf[2] = 0x11;
583 buf[3] = 0x04;
584 buf[4] = 0x00; /* sequence number, original driver doesn't increment it here */
585 buf[5] = 0x01;
586 checksum = buf[4] + buf[5];
587 buf[6] = (u8) ((checksum >> 8) & 0xff);
588 buf[7] = (u8) (checksum & 0xff);
589 break;
590 case FW_BOOT:
591 buf[2] = 0x10;
592 buf[3] = 0x08;
593 buf[4] = 0x00; /* sequence number, original driver doesn't increment it here */
594 buf[5] = 0x97;
595 buf[6] = 0xaa;
596 buf[7] = 0x55;
597 buf[8] = 0xa5;
598 buf[9] = 0x5a;
599 checksum = 0;
600 for (i = 4; i <= 9; i++)
601 checksum += buf[i];
602 buf[10] = (u8) ((checksum >> 8) & 0xff);
603 buf[11] = (u8) (checksum & 0xff);
604 break;
605 default:
606 err("boot packet invalid boot packet type");
607 return -EINVAL;
608 }
609 deb_fw(">>> ");
610 debug_dump(buf, FW_BULKOUT_SIZE + 2, deb_fw);
611
612 ret = usb_bulk_msg(udev,
613 usb_sndbulkpipe(udev, 0x02),
614 buf, FW_BULKOUT_SIZE + 2, &act_len, 2000);
615 if (ret)
616 err("boot packet bulk message failed: %d (%d/%d)", ret,
617 FW_BULKOUT_SIZE + 2, act_len);
618 else
619 ret = act_len != FW_BULKOUT_SIZE + 2 ? -1 : 0;
620 if (ret)
621 return ret;
622 memset(buf, 0, 9);
623 ret = usb_bulk_msg(udev,
624 usb_rcvbulkpipe(udev, 0x01), buf, 9, &act_len, 2000);
625 if (ret) {
626 err("boot packet recv bulk message failed: %d", ret);
627 return ret;
628 }
629 deb_fw("<<< ");
630 debug_dump(buf, act_len, deb_fw);
631 checksum = 0;
632 switch (type) {
633 case FW_CONFIG:
634 if (buf[2] != 0x11) {
635 err("boot bad config header.");
636 return -EIO;
637 }
638 if (buf[3] != 0x05) {
639 err("boot bad config size.");
640 return -EIO;
641 }
642 if (buf[4] != 0x00) {
643 err("boot bad config sequence.");
644 return -EIO;
645 }
646 if (buf[5] != 0x04) {
647 err("boot bad config subtype.");
648 return -EIO;
649 }
650 for (i = 4; i <= 6; i++)
651 checksum += buf[i];
652 if (buf[7] * 256 + buf[8] != checksum) {
653 err("boot bad config checksum.");
654 return -EIO;
655 }
656 *reply = buf[6];
657 break;
658 case FW_CONFIRM:
659 if (buf[2] != 0x11) {
660 err("boot bad confirm header.");
661 return -EIO;
662 }
663 if (buf[3] != 0x05) {
664 err("boot bad confirm size.");
665 return -EIO;
666 }
667 if (buf[4] != 0x00) {
668 err("boot bad confirm sequence.");
669 return -EIO;
670 }
671 if (buf[5] != 0x02) {
672 err("boot bad confirm subtype.");
673 return -EIO;
674 }
675 for (i = 4; i <= 6; i++)
676 checksum += buf[i];
677 if (buf[7] * 256 + buf[8] != checksum) {
678 err("boot bad confirm checksum.");
679 return -EIO;
680 }
681 *reply = buf[6];
682 break;
683 case FW_BOOT:
684 if (buf[2] != 0x10) {
685 err("boot bad boot header.");
686 return -EIO;
687 }
688 if (buf[3] != 0x05) {
689 err("boot bad boot size.");
690 return -EIO;
691 }
692 if (buf[4] != 0x00) {
693 err("boot bad boot sequence.");
694 return -EIO;
695 }
696 if (buf[5] != 0x01) {
697 err("boot bad boot pattern 01.");
698 return -EIO;
699 }
700 if (buf[6] != 0x10) {
701 err("boot bad boot pattern 10.");
702 return -EIO;
703 }
704 for (i = 4; i <= 6; i++)
705 checksum += buf[i];
706 if (buf[7] * 256 + buf[8] != checksum) {
707 err("boot bad boot checksum.");
708 return -EIO;
709 }
710 break;
711
712 }
713
714 return 0;
715}
716
Hans Verkuild45b9b82008-09-04 03:33:43 -0300717static int af9005_download_firmware(struct usb_device *udev, const struct firmware *fw)
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300718{
719 int i, packets, ret, act_len;
720
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300721 u8 *buf;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300722 u8 reply;
723
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300724 buf = kmalloc(FW_BULKOUT_SIZE + 2, GFP_KERNEL);
725 if (!buf)
726 return -ENOMEM;
727
728 ret = af9005_boot_packet(udev, FW_CONFIG, &reply, buf,
729 FW_BULKOUT_SIZE + 2);
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300730 if (ret)
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300731 goto err;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300732 if (reply != 0x01) {
733 err("before downloading firmware, FW_CONFIG expected 0x01, received 0x%x", reply);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300734 ret = -EIO;
735 goto err;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300736 }
737 packets = fw->size / FW_BULKOUT_SIZE;
738 buf[0] = (u8) (FW_BULKOUT_SIZE & 0xff);
739 buf[1] = (u8) ((FW_BULKOUT_SIZE >> 8) & 0xff);
740 for (i = 0; i < packets; i++) {
741 memcpy(&buf[2], fw->data + i * FW_BULKOUT_SIZE,
742 FW_BULKOUT_SIZE);
743 deb_fw(">>> ");
744 debug_dump(buf, FW_BULKOUT_SIZE + 2, deb_fw);
745 ret = usb_bulk_msg(udev,
746 usb_sndbulkpipe(udev, 0x02),
747 buf, FW_BULKOUT_SIZE + 2, &act_len, 1000);
748 if (ret) {
749 err("firmware download failed at packet %d with code %d", i, ret);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300750 goto err;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300751 }
752 }
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300753 ret = af9005_boot_packet(udev, FW_CONFIRM, &reply,
754 buf, FW_BULKOUT_SIZE + 2);
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300755 if (ret)
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300756 goto err;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300757 if (reply != (u8) (packets & 0xff)) {
758 err("after downloading firmware, FW_CONFIRM expected 0x%x, received 0x%x", packets & 0xff, reply);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300759 ret = -EIO;
760 goto err;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300761 }
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300762 ret = af9005_boot_packet(udev, FW_BOOT, &reply, buf,
763 FW_BULKOUT_SIZE + 2);
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300764 if (ret)
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300765 goto err;
766 ret = af9005_boot_packet(udev, FW_CONFIG, &reply, buf,
767 FW_BULKOUT_SIZE + 2);
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300768 if (ret)
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300769 goto err;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300770 if (reply != 0x02) {
771 err("after downloading firmware, FW_CONFIG expected 0x02, received 0x%x", reply);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300772 ret = -EIO;
773 goto err;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300774 }
775
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300776err:
777 kfree(buf);
778 return ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300779
780}
781
782int af9005_led_control(struct dvb_usb_device *d, int onoff)
783{
784 struct af9005_device_state *st = d->priv;
785 int temp, ret;
786
787 if (onoff && dvb_usb_af9005_led)
788 temp = 1;
789 else
790 temp = 0;
791 if (st->led_state != temp) {
792 ret =
793 af9005_write_register_bits(d, xd_p_reg_top_locken1,
794 reg_top_locken1_pos,
795 reg_top_locken1_len, temp);
796 if (ret)
797 return ret;
798 ret =
799 af9005_write_register_bits(d, xd_p_reg_top_lock1,
800 reg_top_lock1_pos,
801 reg_top_lock1_len, temp);
802 if (ret)
803 return ret;
804 st->led_state = temp;
805 }
806 return 0;
807}
808
809static int af9005_frontend_attach(struct dvb_usb_adapter *adap)
810{
811 u8 buf[8];
812 int i;
813
814 /* without these calls the first commands after downloading
815 the firmware fail. I put these calls here to simulate
816 what it is done in dvb-usb-init.c.
817 */
818 struct usb_device *udev = adap->dev->udev;
819 usb_clear_halt(udev, usb_sndbulkpipe(udev, 2));
820 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 1));
821 if (dvb_usb_af9005_dump_eeprom) {
822 printk("EEPROM DUMP\n");
823 for (i = 0; i < 255; i += 8) {
824 af9005_read_eeprom(adap->dev, i, buf, 8);
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300825 debug_dump(buf, 8, printk);
826 }
827 }
Michael Krufky77eed212011-09-06 09:31:57 -0300828 adap->fe_adap[0].fe = af9005_fe_attach(adap->dev);
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300829 return 0;
830}
831
832static int af9005_rc_query(struct dvb_usb_device *d, u32 * event, int *state)
833{
834 struct af9005_device_state *st = d->priv;
835 int ret, len;
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300836 u8 seq;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300837
838 *state = REMOTE_NO_KEY_PRESSED;
839 if (rc_decode == NULL) {
840 /* it shouldn't never come here */
841 return 0;
842 }
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300843
Mauro Carvalho Chehab77243252016-11-12 12:46:26 -0200844 mutex_lock(&d->data_mutex);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300845
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300846 /* deb_info("rc_query\n"); */
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300847 st->data[0] = 3; /* rest of packet length low */
Mauro Carvalho Chehab3e4d8f42019-02-18 14:29:03 -0500848 st->data[1] = 0; /* rest of packet length high */
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300849 st->data[2] = 0x40; /* read remote */
850 st->data[3] = 1; /* rest of packet length */
851 st->data[4] = seq = st->sequence++; /* sequence number */
852 ret = dvb_usb_generic_rw(d, st->data, 5, st->data, 256, 0);
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300853 if (ret) {
854 err("rc query failed");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300855 goto ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300856 }
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300857 if (st->data[2] != 0x41) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300858 err("rc query bad header.");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300859 ret = -EIO;
860 goto ret;
861 } else if (st->data[4] != seq) {
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300862 err("rc query bad sequence.");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300863 ret = -EIO;
864 goto ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300865 }
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300866 len = st->data[5];
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300867 if (len > 246) {
868 err("rc query invalid length");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300869 ret = -EIO;
870 goto ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300871 }
872 if (len > 0) {
873 deb_rc("rc data (%d) ", len);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300874 debug_dump((st->data + 6), len, deb_rc);
875 ret = rc_decode(d, &st->data[6], len, event, state);
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300876 if (ret) {
877 err("rc_decode failed");
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300878 goto ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300879 } else {
880 deb_rc("rc_decode state %x event %x\n", *state, *event);
881 if (*state == REMOTE_KEY_REPEAT)
882 *event = d->last_event;
883 }
884 }
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300885
886ret:
Mauro Carvalho Chehab77243252016-11-12 12:46:26 -0200887 mutex_unlock(&d->data_mutex);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300888 return ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300889}
890
891static int af9005_power_ctrl(struct dvb_usb_device *d, int onoff)
892{
893
894 return 0;
895}
896
897static int af9005_pid_filter_control(struct dvb_usb_adapter *adap, int onoff)
898{
899 int ret;
900 deb_info("pid filter control onoff %d\n", onoff);
901 if (onoff) {
902 ret =
903 af9005_write_ofdm_register(adap->dev, XD_MP2IF_DMX_CTRL, 1);
904 if (ret)
905 return ret;
906 ret =
907 af9005_write_register_bits(adap->dev,
908 XD_MP2IF_DMX_CTRL, 1, 1, 1);
909 if (ret)
910 return ret;
911 ret =
912 af9005_write_ofdm_register(adap->dev, XD_MP2IF_DMX_CTRL, 1);
913 } else
914 ret =
915 af9005_write_ofdm_register(adap->dev, XD_MP2IF_DMX_CTRL, 0);
916 if (ret)
917 return ret;
918 deb_info("pid filter control ok\n");
919 return 0;
920}
921
922static int af9005_pid_filter(struct dvb_usb_adapter *adap, int index,
923 u16 pid, int onoff)
924{
925 u8 cmd = index & 0x1f;
926 int ret;
927 deb_info("set pid filter, index %d, pid %x, onoff %d\n", index,
928 pid, onoff);
929 if (onoff) {
930 /* cannot use it as pid_filter_ctrl since it has to be done
931 before setting the first pid */
932 if (adap->feedcount == 1) {
933 deb_info("first pid set, enable pid table\n");
934 ret = af9005_pid_filter_control(adap, onoff);
935 if (ret)
936 return ret;
937 }
938 ret =
939 af9005_write_ofdm_register(adap->dev,
940 XD_MP2IF_PID_DATA_L,
941 (u8) (pid & 0xff));
942 if (ret)
943 return ret;
944 ret =
945 af9005_write_ofdm_register(adap->dev,
946 XD_MP2IF_PID_DATA_H,
947 (u8) (pid >> 8));
948 if (ret)
949 return ret;
950 cmd |= 0x20 | 0x40;
951 } else {
952 if (adap->feedcount == 0) {
953 deb_info("last pid unset, disable pid table\n");
954 ret = af9005_pid_filter_control(adap, onoff);
955 if (ret)
956 return ret;
957 }
958 }
959 ret = af9005_write_ofdm_register(adap->dev, XD_MP2IF_PID_IDX, cmd);
960 if (ret)
961 return ret;
962 deb_info("set pid ok\n");
963 return 0;
964}
965
966static int af9005_identify_state(struct usb_device *udev,
967 struct dvb_usb_device_properties *props,
968 struct dvb_usb_device_description **desc,
969 int *cold)
970{
971 int ret;
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300972 u8 reply, *buf;
973
974 buf = kmalloc(FW_BULKOUT_SIZE + 2, GFP_KERNEL);
975 if (!buf)
976 return -ENOMEM;
977
978 ret = af9005_boot_packet(udev, FW_CONFIG, &reply,
979 buf, FW_BULKOUT_SIZE + 2);
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300980 if (ret)
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300981 goto err;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300982 deb_info("result of FW_CONFIG in identify state %d\n", reply);
983 if (reply == 0x01)
984 *cold = 1;
985 else if (reply == 0x02)
986 *cold = 0;
987 else
988 return -EIO;
989 deb_info("Identify state cold = %d\n", *cold);
Mauro Carvalho Chehabc58b84e2016-10-05 06:46:49 -0300990
991err:
992 kfree(buf);
993 return ret;
Luca Olivettiaf4e0672007-05-07 15:19:32 -0300994}
995
996static struct dvb_usb_device_properties af9005_properties;
997
998static int af9005_usb_probe(struct usb_interface *intf,
999 const struct usb_device_id *id)
1000{
Mauro Carvalho Chehab77243252016-11-12 12:46:26 -02001001 return dvb_usb_device_init(intf, &af9005_properties,
1002 THIS_MODULE, NULL, adapter_nr);
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001003}
1004
Jonathan Niederd07b9012012-01-07 04:11:27 -03001005enum af9005_usb_table_entry {
1006 AFATECH_AF9005,
1007 TERRATEC_AF9005,
1008 ANSONIC_AF9005,
1009};
1010
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001011static struct usb_device_id af9005_usb_table[] = {
Jonathan Niederd07b9012012-01-07 04:11:27 -03001012 [AFATECH_AF9005] = {USB_DEVICE(USB_VID_AFATECH,
1013 USB_PID_AFATECH_AF9005)},
1014 [TERRATEC_AF9005] = {USB_DEVICE(USB_VID_TERRATEC,
1015 USB_PID_TERRATEC_CINERGY_T_USB_XE)},
1016 [ANSONIC_AF9005] = {USB_DEVICE(USB_VID_ANSONIC,
1017 USB_PID_ANSONIC_DVBT_USB)},
1018 { }
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001019};
1020
1021MODULE_DEVICE_TABLE(usb, af9005_usb_table);
1022
1023static struct dvb_usb_device_properties af9005_properties = {
1024 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1025
1026 .usb_ctrl = DEVICE_SPECIFIC,
1027 .firmware = "af9005.fw",
1028 .download_firmware = af9005_download_firmware,
1029 .no_reconnect = 1,
1030
1031 .size_of_priv = sizeof(struct af9005_device_state),
1032
1033 .num_adapters = 1,
1034 .adapter = {
1035 {
Michael Krufky77eed212011-09-06 09:31:57 -03001036 .num_frontends = 1,
1037 .fe = {{
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001038 .caps =
1039 DVB_USB_ADAP_HAS_PID_FILTER |
1040 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1041 .pid_filter_count = 32,
1042 .pid_filter = af9005_pid_filter,
1043 /* .pid_filter_ctrl = af9005_pid_filter_control, */
1044 .frontend_attach = af9005_frontend_attach,
1045 /* .tuner_attach = af9005_tuner_attach, */
1046 /* parameter for the MPEG2-data transfer */
1047 .stream = {
1048 .type = USB_BULK,
1049 .count = 10,
1050 .endpoint = 0x04,
1051 .u = {
1052 .bulk = {
1053 .buffersize = 4096, /* actual size seen is 3948 */
1054 }
1055 }
1056 },
Michael Krufky77eed212011-09-06 09:31:57 -03001057 }},
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001058 }
1059 },
1060 .power_ctrl = af9005_power_ctrl,
1061 .identify_state = af9005_identify_state,
1062
1063 .i2c_algo = &af9005_i2c_algo,
1064
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001065 .rc.legacy = {
1066 .rc_interval = 200,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001067 .rc_map_table = NULL,
1068 .rc_map_size = 0,
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001069 .rc_query = af9005_rc_query,
1070 },
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001071
Michael Krufky17f93e12010-06-21 01:49:42 -03001072 .generic_bulk_ctrl_endpoint = 2,
1073 .generic_bulk_ctrl_endpoint_response = 1,
1074
Luca Olivetti8cb93292008-01-20 17:56:43 -03001075 .num_device_descs = 3,
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001076 .devices = {
1077 {.name = "Afatech DVB-T USB1.1 stick",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001078 .cold_ids = {&af9005_usb_table[AFATECH_AF9005], NULL},
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001079 .warm_ids = {NULL},
1080 },
1081 {.name = "TerraTec Cinergy T USB XE",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001082 .cold_ids = {&af9005_usb_table[TERRATEC_AF9005], NULL},
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001083 .warm_ids = {NULL},
1084 },
Luca Olivetti8cb93292008-01-20 17:56:43 -03001085 {.name = "Ansonic DVB-T USB1.1 stick",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001086 .cold_ids = {&af9005_usb_table[ANSONIC_AF9005], NULL},
Luca Olivetti8cb93292008-01-20 17:56:43 -03001087 .warm_ids = {NULL},
1088 },
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001089 {NULL},
1090 }
1091};
1092
1093/* usb specific object needed to register this driver with the usb subsystem */
1094static struct usb_driver af9005_usb_driver = {
1095 .name = "dvb_usb_af9005",
1096 .probe = af9005_usb_probe,
1097 .disconnect = dvb_usb_device_exit,
1098 .id_table = af9005_usb_table,
1099};
1100
1101/* module stuff */
1102static int __init af9005_usb_module_init(void)
1103{
1104 int result;
1105 if ((result = usb_register(&af9005_usb_driver))) {
1106 err("usb_register failed. (%d)", result);
1107 return result;
1108 }
Frank Schaefer22799482014-09-29 15:17:35 -03001109#if IS_MODULE(CONFIG_DVB_USB_AF9005) || defined(CONFIG_DVB_USB_AF9005_REMOTE)
1110 /* FIXME: convert to todays kernel IR infrastructure */
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001111 rc_decode = symbol_request(af9005_rc_decode);
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001112 rc_keys = symbol_request(rc_map_af9005_table);
1113 rc_keys_size = symbol_request(rc_map_af9005_table_size);
Frank Schaefer22799482014-09-29 15:17:35 -03001114#endif
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001115 if (rc_decode == NULL || rc_keys == NULL || rc_keys_size == NULL) {
1116 err("af9005_rc_decode function not found, disabling remote");
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001117 af9005_properties.rc.legacy.rc_query = NULL;
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001118 } else {
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001119 af9005_properties.rc.legacy.rc_map_table = rc_keys;
1120 af9005_properties.rc.legacy.rc_map_size = *rc_keys_size;
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001121 }
1122
1123 return 0;
1124}
1125
1126static void __exit af9005_usb_module_exit(void)
1127{
1128 /* release rc decode symbols */
1129 if (rc_decode != NULL)
1130 symbol_put(af9005_rc_decode);
1131 if (rc_keys != NULL)
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001132 symbol_put(rc_map_af9005_table);
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001133 if (rc_keys_size != NULL)
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001134 symbol_put(rc_map_af9005_table_size);
Luca Olivettiaf4e0672007-05-07 15:19:32 -03001135 /* deregister this driver from the USB subsystem */
1136 usb_deregister(&af9005_usb_driver);
1137}
1138
1139module_init(af9005_usb_module_init);
1140module_exit(af9005_usb_module_exit);
1141
1142MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
1143MODULE_DESCRIPTION("Driver for Afatech 9005 DVB-T USB1.1 stick");
1144MODULE_VERSION("1.0");
1145MODULE_LICENSE("GPL");