blob: 677fed79b01e7227c2cc47fe72b9bbf48190495b [file] [log] [blame]
Antti Palosaari80619de2008-09-15 17:18:09 -03001/*
2 * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
3 *
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
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 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
Jiri Slaby6c614042010-01-22 12:10:52 -030024#include <linux/hash.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Jiri Slaby6c614042010-01-22 12:10:52 -030026
Antti Palosaari80619de2008-09-15 17:18:09 -030027#include "af9015.h"
28#include "af9013.h"
29#include "mt2060.h"
30#include "qt1010.h"
31#include "tda18271.h"
32#include "mxl5005s.h"
Jochen Friedrichd5633992009-02-02 14:59:50 -030033#include "mc44s803.h"
Antti Palosaariee3d4402010-08-13 03:51:26 -030034#include "tda18218.h"
Antti Palosaariab07fdd2010-09-09 14:59:10 -030035#include "mxl5007t.h"
Antti Palosaari80619de2008-09-15 17:18:09 -030036
Antti Palosaari349d0422008-11-05 16:31:24 -030037static int dvb_usb_af9015_debug;
Antti Palosaari80619de2008-09-15 17:18:09 -030038module_param_named(debug, dvb_usb_af9015_debug, int, 0644);
39MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
Antti Palosaari349d0422008-11-05 16:31:24 -030040static int dvb_usb_af9015_remote;
Antti Palosaari80619de2008-09-15 17:18:09 -030041module_param_named(remote, dvb_usb_af9015_remote, int, 0644);
42MODULE_PARM_DESC(remote, "select remote");
Antti Palosaari80619de2008-09-15 17:18:09 -030043DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
44
45static DEFINE_MUTEX(af9015_usb_mutex);
46
47static struct af9015_config af9015_config;
Antti Palosaari85d7d7c2009-04-09 09:16:12 -030048static struct dvb_usb_device_properties af9015_properties[3];
Antti Palosaari349d0422008-11-05 16:31:24 -030049static int af9015_properties_count = ARRAY_SIZE(af9015_properties);
Antti Palosaari80619de2008-09-15 17:18:09 -030050
51static struct af9013_config af9015_af9013_config[] = {
52 {
Antti Palosaarif571e002011-11-28 20:58:11 -030053 .i2c_addr = AF9015_I2C_DEMOD,
54 .ts_mode = AF9013_TS_USB,
Antti Palosaari80619de2008-09-15 17:18:09 -030055 .api_version = { 0, 1, 9, 0 },
56 .gpio[0] = AF9013_GPIO_HI,
Antti Palosaari80619de2008-09-15 17:18:09 -030057 .gpio[3] = AF9013_GPIO_TUNER_ON,
58
59 }, {
Antti Palosaarif571e002011-11-28 20:58:11 -030060 .ts_mode = AF9013_TS_SERIAL,
Antti Palosaari80619de2008-09-15 17:18:09 -030061 .api_version = { 0, 1, 9, 0 },
62 .gpio[0] = AF9013_GPIO_TUNER_ON,
63 .gpio[1] = AF9013_GPIO_LO,
64 }
65};
66
67static int af9015_rw_udev(struct usb_device *udev, struct req_t *req)
68{
Antti Palosaari06565d72009-09-12 20:46:30 -030069#define BUF_LEN 63
70#define REQ_HDR_LEN 8 /* send header size */
71#define ACK_HDR_LEN 2 /* rece header size */
Antti Palosaari80619de2008-09-15 17:18:09 -030072 int act_len, ret;
Antti Palosaari06565d72009-09-12 20:46:30 -030073 u8 buf[BUF_LEN];
Antti Palosaari80619de2008-09-15 17:18:09 -030074 u8 write = 1;
Antti Palosaari06565d72009-09-12 20:46:30 -030075 u8 msg_len = REQ_HDR_LEN;
Antti Palosaari80619de2008-09-15 17:18:09 -030076 static u8 seq; /* packet sequence number */
77
78 if (mutex_lock_interruptible(&af9015_usb_mutex) < 0)
79 return -EAGAIN;
80
81 buf[0] = req->cmd;
82 buf[1] = seq++;
83 buf[2] = req->i2c_addr;
84 buf[3] = req->addr >> 8;
85 buf[4] = req->addr & 0xff;
86 buf[5] = req->mbox;
87 buf[6] = req->addr_len;
88 buf[7] = req->data_len;
89
90 switch (req->cmd) {
91 case GET_CONFIG:
Antti Palosaari80619de2008-09-15 17:18:09 -030092 case READ_MEMORY:
93 case RECONNECT_USB:
Antti Palosaari80619de2008-09-15 17:18:09 -030094 write = 0;
95 break;
96 case READ_I2C:
97 write = 0;
98 buf[2] |= 0x01; /* set I2C direction */
99 case WRITE_I2C:
100 buf[0] = READ_WRITE_I2C;
101 break;
102 case WRITE_MEMORY:
103 if (((req->addr & 0xff00) == 0xff00) ||
Antti Palosaarif4e96de2009-09-12 21:25:59 -0300104 ((req->addr & 0xff00) == 0xae00))
Antti Palosaari80619de2008-09-15 17:18:09 -0300105 buf[0] = WRITE_VIRTUAL_MEMORY;
106 case WRITE_VIRTUAL_MEMORY:
107 case COPY_FIRMWARE:
108 case DOWNLOAD_FIRMWARE:
Nils Kassubeba1bc642009-07-28 11:54:52 -0300109 case BOOT:
Antti Palosaari80619de2008-09-15 17:18:09 -0300110 break;
111 default:
112 err("unknown command:%d", req->cmd);
113 ret = -1;
114 goto error_unlock;
115 }
116
Antti Palosaari06565d72009-09-12 20:46:30 -0300117 /* buffer overflow check */
118 if ((write && (req->data_len > BUF_LEN - REQ_HDR_LEN)) ||
119 (!write && (req->data_len > BUF_LEN - ACK_HDR_LEN))) {
120 err("too much data; cmd:%d len:%d", req->cmd, req->data_len);
121 ret = -EINVAL;
122 goto error_unlock;
123 }
124
Antti Palosaari80619de2008-09-15 17:18:09 -0300125 /* write requested */
126 if (write) {
Antti Palosaari06565d72009-09-12 20:46:30 -0300127 memcpy(&buf[REQ_HDR_LEN], req->data, req->data_len);
Antti Palosaari80619de2008-09-15 17:18:09 -0300128 msg_len += req->data_len;
129 }
Antti Palosaari06565d72009-09-12 20:46:30 -0300130
Antti Palosaari80619de2008-09-15 17:18:09 -0300131 deb_xfer(">>> ");
132 debug_dump(buf, msg_len, deb_xfer);
133
134 /* send req */
135 ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x02), buf, msg_len,
Antti Palosaari06565d72009-09-12 20:46:30 -0300136 &act_len, AF9015_USB_TIMEOUT);
Antti Palosaari80619de2008-09-15 17:18:09 -0300137 if (ret)
138 err("bulk message failed:%d (%d/%d)", ret, msg_len, act_len);
139 else
140 if (act_len != msg_len)
141 ret = -1; /* all data is not send */
142 if (ret)
143 goto error_unlock;
144
145 /* no ack for those packets */
146 if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB)
147 goto exit_unlock;
148
Antti Palosaari06565d72009-09-12 20:46:30 -0300149 /* write receives seq + status = 2 bytes
150 read receives seq + status + data = 2 + N bytes */
151 msg_len = ACK_HDR_LEN;
152 if (!write)
153 msg_len += req->data_len;
154
Antti Palosaari80619de2008-09-15 17:18:09 -0300155 ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, 0x81), buf, msg_len,
Antti Palosaari06565d72009-09-12 20:46:30 -0300156 &act_len, AF9015_USB_TIMEOUT);
Antti Palosaari80619de2008-09-15 17:18:09 -0300157 if (ret) {
158 err("recv bulk message failed:%d", ret);
159 ret = -1;
160 goto error_unlock;
161 }
162
163 deb_xfer("<<< ");
164 debug_dump(buf, act_len, deb_xfer);
165
Antti Palosaari80619de2008-09-15 17:18:09 -0300166 /* check status */
167 if (buf[1]) {
168 err("command failed:%d", buf[1]);
169 ret = -1;
170 goto error_unlock;
171 }
172
173 /* read request, copy returned data to return buf */
174 if (!write)
Antti Palosaari06565d72009-09-12 20:46:30 -0300175 memcpy(req->data, &buf[ACK_HDR_LEN], req->data_len);
Antti Palosaari80619de2008-09-15 17:18:09 -0300176
177error_unlock:
178exit_unlock:
179 mutex_unlock(&af9015_usb_mutex);
180
181 return ret;
182}
183
184static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)
185{
186 return af9015_rw_udev(d->udev, req);
187}
188
189static int af9015_write_regs(struct dvb_usb_device *d, u16 addr, u8 *val,
190 u8 len)
191{
192 struct req_t req = {WRITE_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len,
193 val};
194 return af9015_ctrl_msg(d, &req);
195}
196
197static int af9015_write_reg(struct dvb_usb_device *d, u16 addr, u8 val)
198{
199 return af9015_write_regs(d, addr, &val, 1);
200}
201
Antti Palosaari74c8e3a2010-10-22 18:45:18 -0300202static int af9015_read_regs(struct dvb_usb_device *d, u16 addr, u8 *val, u8 len)
203{
204 struct req_t req = {READ_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len,
205 val};
206 return af9015_ctrl_msg(d, &req);
207}
208
Antti Palosaari80619de2008-09-15 17:18:09 -0300209static int af9015_read_reg(struct dvb_usb_device *d, u16 addr, u8 *val)
210{
Antti Palosaari74c8e3a2010-10-22 18:45:18 -0300211 return af9015_read_regs(d, addr, val, 1);
Antti Palosaari80619de2008-09-15 17:18:09 -0300212}
213
214static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
215 u8 val)
216{
217 struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val};
218
Antti Palosaarif571e002011-11-28 20:58:11 -0300219 if (addr == af9015_af9013_config[0].i2c_addr ||
220 addr == af9015_af9013_config[1].i2c_addr)
Antti Palosaari80619de2008-09-15 17:18:09 -0300221 req.addr_len = 3;
222
223 return af9015_ctrl_msg(d, &req);
224}
225
226static int af9015_read_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
227 u8 *val)
228{
229 struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val};
230
Antti Palosaarif571e002011-11-28 20:58:11 -0300231 if (addr == af9015_af9013_config[0].i2c_addr ||
232 addr == af9015_af9013_config[1].i2c_addr)
Antti Palosaari80619de2008-09-15 17:18:09 -0300233 req.addr_len = 3;
234
235 return af9015_ctrl_msg(d, &req);
236}
237
238static int af9015_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
239 int num)
240{
241 struct dvb_usb_device *d = i2c_get_adapdata(adap);
242 int ret = 0, i = 0;
243 u16 addr;
Antti Palosaari675375d2010-10-07 21:46:41 -0300244 u8 uninitialized_var(mbox), addr_len;
Antti Palosaari80619de2008-09-15 17:18:09 -0300245 struct req_t req;
246
Antti Palosaaribc050e62012-05-08 06:04:24 -0300247/*
Antti Palosaari80619de2008-09-15 17:18:09 -0300248The bus lock is needed because there is two tuners both using same I2C-address.
249Due to that the only way to select correct tuner is use demodulator I2C-gate.
250
251................................................
252. AF9015 includes integrated AF9013 demodulator.
253. ____________ ____________ . ____________
254.| uC | | demod | . | tuner |
255.|------------| |------------| . |------------|
256.| AF9015 | | AF9013/5 | . | MXL5003 |
257.| |--+----I2C-------|-----/ -----|-.-----I2C-------| |
258.| | | | addr 0x38 | . | addr 0xc6 |
259.|____________| | |____________| . |____________|
260.................|..............................
261 | ____________ ____________
262 | | demod | | tuner |
263 | |------------| |------------|
264 | | AF9013 | | MXL5003 |
265 +----I2C-------|-----/ -----|-------I2C-------| |
266 | addr 0x3a | | addr 0xc6 |
267 |____________| |____________|
268*/
269 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
270 return -EAGAIN;
271
272 while (i < num) {
Antti Palosaarif571e002011-11-28 20:58:11 -0300273 if (msg[i].addr == af9015_af9013_config[0].i2c_addr ||
274 msg[i].addr == af9015_af9013_config[1].i2c_addr) {
Antti Palosaari80619de2008-09-15 17:18:09 -0300275 addr = msg[i].buf[0] << 8;
276 addr += msg[i].buf[1];
277 mbox = msg[i].buf[2];
278 addr_len = 3;
279 } else {
280 addr = msg[i].buf[0];
281 addr_len = 1;
Antti Palosaari675375d2010-10-07 21:46:41 -0300282 /* mbox is don't care in that case */
Antti Palosaari80619de2008-09-15 17:18:09 -0300283 }
284
285 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
Antti Palosaari709d9202011-06-17 21:16:38 -0300286 if (msg[i].len > 3 || msg[i+1].len > 61) {
287 ret = -EOPNOTSUPP;
288 goto error;
289 }
Antti Palosaarif571e002011-11-28 20:58:11 -0300290 if (msg[i].addr == af9015_af9013_config[0].i2c_addr)
Antti Palosaari80619de2008-09-15 17:18:09 -0300291 req.cmd = READ_MEMORY;
292 else
293 req.cmd = READ_I2C;
294 req.i2c_addr = msg[i].addr;
295 req.addr = addr;
296 req.mbox = mbox;
297 req.addr_len = addr_len;
298 req.data_len = msg[i+1].len;
299 req.data = &msg[i+1].buf[0];
300 ret = af9015_ctrl_msg(d, &req);
301 i += 2;
Jochen Friedrichd5633992009-02-02 14:59:50 -0300302 } else if (msg[i].flags & I2C_M_RD) {
Antti Palosaari709d9202011-06-17 21:16:38 -0300303 if (msg[i].len > 61) {
304 ret = -EOPNOTSUPP;
305 goto error;
306 }
Jochen Friedrichd5633992009-02-02 14:59:50 -0300307 if (msg[i].addr ==
Antti Palosaarif571e002011-11-28 20:58:11 -0300308 af9015_af9013_config[0].i2c_addr) {
Antti Palosaari16b2dc22011-06-16 20:02:41 -0300309 ret = -EINVAL;
Jochen Friedrichd5633992009-02-02 14:59:50 -0300310 goto error;
Antti Palosaari16b2dc22011-06-16 20:02:41 -0300311 }
312 req.cmd = READ_I2C;
Jochen Friedrichd5633992009-02-02 14:59:50 -0300313 req.i2c_addr = msg[i].addr;
314 req.addr = addr;
315 req.mbox = mbox;
316 req.addr_len = addr_len;
317 req.data_len = msg[i].len;
318 req.data = &msg[i].buf[0];
319 ret = af9015_ctrl_msg(d, &req);
320 i += 1;
Antti Palosaari80619de2008-09-15 17:18:09 -0300321 } else {
Antti Palosaari709d9202011-06-17 21:16:38 -0300322 if (msg[i].len > 21) {
323 ret = -EOPNOTSUPP;
324 goto error;
325 }
Antti Palosaarif571e002011-11-28 20:58:11 -0300326 if (msg[i].addr == af9015_af9013_config[0].i2c_addr)
Antti Palosaari80619de2008-09-15 17:18:09 -0300327 req.cmd = WRITE_MEMORY;
328 else
329 req.cmd = WRITE_I2C;
330 req.i2c_addr = msg[i].addr;
331 req.addr = addr;
332 req.mbox = mbox;
333 req.addr_len = addr_len;
334 req.data_len = msg[i].len-addr_len;
335 req.data = &msg[i].buf[addr_len];
336 ret = af9015_ctrl_msg(d, &req);
337 i += 1;
338 }
339 if (ret)
340 goto error;
341
342 }
343 ret = i;
344
345error:
346 mutex_unlock(&d->i2c_mutex);
347
348 return ret;
349}
350
351static u32 af9015_i2c_func(struct i2c_adapter *adapter)
352{
353 return I2C_FUNC_I2C;
354}
355
356static struct i2c_algorithm af9015_i2c_algo = {
357 .master_xfer = af9015_i2c_xfer,
358 .functionality = af9015_i2c_func,
359};
360
361static int af9015_do_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit, u8 op)
362{
363 int ret;
364 u8 val, mask = 0x01;
365
366 ret = af9015_read_reg(d, addr, &val);
367 if (ret)
368 return ret;
369
370 mask <<= bit;
371 if (op) {
372 /* set bit */
373 val |= mask;
374 } else {
375 /* clear bit */
376 mask ^= 0xff;
377 val &= mask;
378 }
379
380 return af9015_write_reg(d, addr, val);
381}
382
383static int af9015_set_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)
384{
385 return af9015_do_reg_bit(d, addr, bit, 1);
386}
387
388static int af9015_clear_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)
389{
390 return af9015_do_reg_bit(d, addr, bit, 0);
391}
392
393static int af9015_init_endpoint(struct dvb_usb_device *d)
394{
395 int ret;
396 u16 frame_size;
397 u8 packet_size;
398 deb_info("%s: USB speed:%d\n", __func__, d->udev->speed);
399
Antti Palosaari9c863272009-09-12 13:35:29 -0300400 /* Windows driver uses packet count 21 for USB1.1 and 348 for USB2.0.
401 We use smaller - about 1/4 from the original, 5 and 87. */
Antti Palosaari80619de2008-09-15 17:18:09 -0300402#define TS_PACKET_SIZE 188
403
Antti Palosaari9c863272009-09-12 13:35:29 -0300404#define TS_USB20_PACKET_COUNT 87
Antti Palosaari80619de2008-09-15 17:18:09 -0300405#define TS_USB20_FRAME_SIZE (TS_PACKET_SIZE*TS_USB20_PACKET_COUNT)
406
Antti Palosaari9c863272009-09-12 13:35:29 -0300407#define TS_USB11_PACKET_COUNT 5
Antti Palosaari80619de2008-09-15 17:18:09 -0300408#define TS_USB11_FRAME_SIZE (TS_PACKET_SIZE*TS_USB11_PACKET_COUNT)
409
410#define TS_USB20_MAX_PACKET_SIZE 512
411#define TS_USB11_MAX_PACKET_SIZE 64
412
413 if (d->udev->speed == USB_SPEED_FULL) {
414 frame_size = TS_USB11_FRAME_SIZE/4;
415 packet_size = TS_USB11_MAX_PACKET_SIZE/4;
416 } else {
417 frame_size = TS_USB20_FRAME_SIZE/4;
418 packet_size = TS_USB20_MAX_PACKET_SIZE/4;
419 }
420
421 ret = af9015_set_reg_bit(d, 0xd507, 2); /* assert EP4 reset */
422 if (ret)
423 goto error;
424 ret = af9015_set_reg_bit(d, 0xd50b, 1); /* assert EP5 reset */
425 if (ret)
426 goto error;
427 ret = af9015_clear_reg_bit(d, 0xdd11, 5); /* disable EP4 */
428 if (ret)
429 goto error;
430 ret = af9015_clear_reg_bit(d, 0xdd11, 6); /* disable EP5 */
431 if (ret)
432 goto error;
433 ret = af9015_set_reg_bit(d, 0xdd11, 5); /* enable EP4 */
434 if (ret)
435 goto error;
436 if (af9015_config.dual_mode) {
437 ret = af9015_set_reg_bit(d, 0xdd11, 6); /* enable EP5 */
438 if (ret)
439 goto error;
440 }
441 ret = af9015_clear_reg_bit(d, 0xdd13, 5); /* disable EP4 NAK */
442 if (ret)
443 goto error;
444 if (af9015_config.dual_mode) {
445 ret = af9015_clear_reg_bit(d, 0xdd13, 6); /* disable EP5 NAK */
446 if (ret)
447 goto error;
448 }
449 /* EP4 xfer length */
450 ret = af9015_write_reg(d, 0xdd88, frame_size & 0xff);
451 if (ret)
452 goto error;
453 ret = af9015_write_reg(d, 0xdd89, frame_size >> 8);
454 if (ret)
455 goto error;
456 /* EP5 xfer length */
457 ret = af9015_write_reg(d, 0xdd8a, frame_size & 0xff);
458 if (ret)
459 goto error;
460 ret = af9015_write_reg(d, 0xdd8b, frame_size >> 8);
461 if (ret)
462 goto error;
463 ret = af9015_write_reg(d, 0xdd0c, packet_size); /* EP4 packet size */
464 if (ret)
465 goto error;
466 ret = af9015_write_reg(d, 0xdd0d, packet_size); /* EP5 packet size */
467 if (ret)
468 goto error;
469 ret = af9015_clear_reg_bit(d, 0xd507, 2); /* negate EP4 reset */
470 if (ret)
471 goto error;
472 if (af9015_config.dual_mode) {
473 ret = af9015_clear_reg_bit(d, 0xd50b, 1); /* negate EP5 reset */
474 if (ret)
475 goto error;
476 }
477
478 /* enable / disable mp2if2 */
479 if (af9015_config.dual_mode)
480 ret = af9015_set_reg_bit(d, 0xd50b, 0);
481 else
482 ret = af9015_clear_reg_bit(d, 0xd50b, 0);
Antti Palosaari1e8750c2011-03-18 19:36:42 -0300483
Antti Palosaari80619de2008-09-15 17:18:09 -0300484error:
485 if (ret)
486 err("endpoint init failed:%d", ret);
487 return ret;
488}
489
490static int af9015_copy_firmware(struct dvb_usb_device *d)
491{
492 int ret;
493 u8 fw_params[4];
494 u8 val, i;
495 struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params),
496 fw_params };
497 deb_info("%s:\n", __func__);
498
499 fw_params[0] = af9015_config.firmware_size >> 8;
500 fw_params[1] = af9015_config.firmware_size & 0xff;
501 fw_params[2] = af9015_config.firmware_checksum >> 8;
502 fw_params[3] = af9015_config.firmware_checksum & 0xff;
503
504 /* wait 2nd demodulator ready */
505 msleep(100);
506
Antti Palosaaried19a5d2010-09-12 21:02:55 -0300507 ret = af9015_read_reg_i2c(d,
Antti Palosaarif571e002011-11-28 20:58:11 -0300508 af9015_af9013_config[1].i2c_addr, 0x98be, &val);
Antti Palosaari80619de2008-09-15 17:18:09 -0300509 if (ret)
510 goto error;
511 else
512 deb_info("%s: firmware status:%02x\n", __func__, val);
513
514 if (val == 0x0c) /* fw is running, no need for download */
515 goto exit;
516
517 /* set I2C master clock to fast (to speed up firmware copy) */
518 ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */
519 if (ret)
520 goto error;
521
522 msleep(50);
523
524 /* copy firmware */
525 ret = af9015_ctrl_msg(d, &req);
526 if (ret)
527 err("firmware copy cmd failed:%d", ret);
528 deb_info("%s: firmware copy done\n", __func__);
529
530 /* set I2C master clock back to normal */
531 ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */
532 if (ret)
533 goto error;
534
535 /* request boot firmware */
Antti Palosaarif571e002011-11-28 20:58:11 -0300536 ret = af9015_write_reg_i2c(d, af9015_af9013_config[1].i2c_addr,
Antti Palosaari80619de2008-09-15 17:18:09 -0300537 0xe205, 1);
538 deb_info("%s: firmware boot cmd status:%d\n", __func__, ret);
539 if (ret)
540 goto error;
541
542 for (i = 0; i < 15; i++) {
543 msleep(100);
544
545 /* check firmware status */
546 ret = af9015_read_reg_i2c(d,
Antti Palosaarif571e002011-11-28 20:58:11 -0300547 af9015_af9013_config[1].i2c_addr, 0x98be, &val);
Antti Palosaari80619de2008-09-15 17:18:09 -0300548 deb_info("%s: firmware status cmd status:%d fw status:%02x\n",
549 __func__, ret, val);
550 if (ret)
551 goto error;
552
553 if (val == 0x0c || val == 0x04) /* success or fail */
554 break;
555 }
556
557 if (val == 0x04) {
558 err("firmware did not run");
559 ret = -1;
560 } else if (val != 0x0c) {
561 err("firmware boot timeout");
562 ret = -1;
563 }
564
565error:
566exit:
567 return ret;
568}
569
Jiri Slaby6c614042010-01-22 12:10:52 -0300570/* hash (and dump) eeprom */
571static int af9015_eeprom_hash(struct usb_device *udev)
Antti Palosaari80619de2008-09-15 17:18:09 -0300572{
Jiri Slaby6c614042010-01-22 12:10:52 -0300573 static const unsigned int eeprom_size = 256;
574 unsigned int reg;
575 int ret;
576 u8 val, *eeprom;
577 struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
Antti Palosaari80619de2008-09-15 17:18:09 -0300578
Jiri Slaby6c614042010-01-22 12:10:52 -0300579 eeprom = kmalloc(eeprom_size, GFP_KERNEL);
580 if (eeprom == NULL)
581 return -ENOMEM;
582
583 for (reg = 0; reg < eeprom_size; reg++) {
584 req.addr = reg;
585 ret = af9015_rw_udev(udev, &req);
586 if (ret)
587 goto free;
588 eeprom[reg] = val;
Antti Palosaari80619de2008-09-15 17:18:09 -0300589 }
Jiri Slaby6c614042010-01-22 12:10:52 -0300590
591 if (dvb_usb_af9015_debug & 0x01)
592 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, eeprom,
593 eeprom_size);
594
595 BUG_ON(eeprom_size % 4);
596
597 af9015_config.eeprom_sum = 0;
598 for (reg = 0; reg < eeprom_size / sizeof(u32); reg++) {
599 af9015_config.eeprom_sum *= GOLDEN_RATIO_PRIME_32;
600 af9015_config.eeprom_sum += le32_to_cpu(((u32 *)eeprom)[reg]);
601 }
602
603 deb_info("%s: eeprom sum=%.8x\n", __func__, af9015_config.eeprom_sum);
604
605 ret = 0;
606free:
607 kfree(eeprom);
608 return ret;
Antti Palosaari80619de2008-09-15 17:18:09 -0300609}
610
Antti Palosaari80619de2008-09-15 17:18:09 -0300611static int af9015_init(struct dvb_usb_device *d)
612{
613 int ret;
614 deb_info("%s:\n", __func__);
615
Antti Palosaari1e8750c2011-03-18 19:36:42 -0300616 /* init RC canary */
617 ret = af9015_write_reg(d, 0x98e9, 0xff);
618 if (ret)
619 goto error;
620
Antti Palosaari80619de2008-09-15 17:18:09 -0300621 ret = af9015_init_endpoint(d);
622 if (ret)
623 goto error;
624
Antti Palosaari80619de2008-09-15 17:18:09 -0300625error:
626 return ret;
627}
628
629static int af9015_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
630{
631 int ret;
632 deb_info("%s: onoff:%d\n", __func__, onoff);
633
634 if (onoff)
635 ret = af9015_set_reg_bit(adap->dev, 0xd503, 0);
636 else
637 ret = af9015_clear_reg_bit(adap->dev, 0xd503, 0);
638
639 return ret;
640}
641
642static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
643 int onoff)
644{
645 int ret;
646 u8 idx;
647
648 deb_info("%s: set pid filter, index %d, pid %x, onoff %d\n",
649 __func__, index, pid, onoff);
650
651 ret = af9015_write_reg(adap->dev, 0xd505, (pid & 0xff));
652 if (ret)
653 goto error;
654
655 ret = af9015_write_reg(adap->dev, 0xd506, (pid >> 8));
656 if (ret)
657 goto error;
658
659 idx = ((index & 0x1f) | (1 << 5));
660 ret = af9015_write_reg(adap->dev, 0xd504, idx);
661
662error:
663 return ret;
664}
665
666static int af9015_download_firmware(struct usb_device *udev,
667 const struct firmware *fw)
668{
Antti Palosaari582e5652011-03-19 16:51:43 -0300669 int i, len, remaining, ret;
Antti Palosaari80619de2008-09-15 17:18:09 -0300670 struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL};
Antti Palosaari80619de2008-09-15 17:18:09 -0300671 u16 checksum = 0;
672
673 deb_info("%s:\n", __func__);
674
675 /* calc checksum */
676 for (i = 0; i < fw->size; i++)
677 checksum += fw->data[i];
678
679 af9015_config.firmware_size = fw->size;
680 af9015_config.firmware_checksum = checksum;
681
Antti Palosaari582e5652011-03-19 16:51:43 -0300682 #define FW_ADDR 0x5100 /* firmware start address */
683 #define LEN_MAX 55 /* max packet size */
684 for (remaining = fw->size; remaining > 0; remaining -= LEN_MAX) {
685 len = remaining;
686 if (len > LEN_MAX)
687 len = LEN_MAX;
Antti Palosaari80619de2008-09-15 17:18:09 -0300688
689 req.data_len = len;
Antti Palosaari582e5652011-03-19 16:51:43 -0300690 req.data = (u8 *) &fw->data[fw->size - remaining];
691 req.addr = FW_ADDR + fw->size - remaining;
Antti Palosaari80619de2008-09-15 17:18:09 -0300692
693 ret = af9015_rw_udev(udev, &req);
694 if (ret) {
Antti Palosaari582e5652011-03-19 16:51:43 -0300695 err("firmware download failed:%d", ret);
Antti Palosaari80619de2008-09-15 17:18:09 -0300696 goto error;
697 }
698 }
Antti Palosaari80619de2008-09-15 17:18:09 -0300699
700 /* firmware loaded, request boot */
701 req.cmd = BOOT;
702 ret = af9015_rw_udev(udev, &req);
703 if (ret) {
704 err("firmware boot failed:%d", ret);
705 goto error;
706 }
707
Antti Palosaari80619de2008-09-15 17:18:09 -0300708error:
709 return ret;
710}
711
Antti Palosaari1cd72782010-10-12 17:22:32 -0300712struct af9015_rc_setup {
Jiri Slaby26c3b8b2010-01-22 12:10:54 -0300713 unsigned int id;
Antti Palosaari1cd72782010-10-12 17:22:32 -0300714 char *rc_codes;
Jiri Slaby26c3b8b2010-01-22 12:10:54 -0300715};
716
Antti Palosaari1cd72782010-10-12 17:22:32 -0300717static char *af9015_rc_setup_match(unsigned int id,
718 const struct af9015_rc_setup *table)
Jiri Slaby26c3b8b2010-01-22 12:10:54 -0300719{
Antti Palosaari1cd72782010-10-12 17:22:32 -0300720 for (; table->rc_codes; table++)
Jiri Slaby26c3b8b2010-01-22 12:10:54 -0300721 if (table->id == id)
Antti Palosaari1cd72782010-10-12 17:22:32 -0300722 return table->rc_codes;
Jiri Slaby26c3b8b2010-01-22 12:10:54 -0300723 return NULL;
724}
725
Antti Palosaari1cd72782010-10-12 17:22:32 -0300726static const struct af9015_rc_setup af9015_rc_setup_modparam[] = {
727 { AF9015_REMOTE_A_LINK_DTU_M, RC_MAP_ALINK_DTU_M },
728 { AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, RC_MAP_MSI_DIGIVOX_II },
729 { AF9015_REMOTE_MYGICTV_U718, RC_MAP_TOTAL_MEDIA_IN_HAND },
730 { AF9015_REMOTE_DIGITTRADE_DVB_T, RC_MAP_DIGITTRADE },
731 { AF9015_REMOTE_AVERMEDIA_KS, RC_MAP_AVERMEDIA_RM_KS },
Jiri Slaby26c3b8b2010-01-22 12:10:54 -0300732 { }
733};
734
Antti Palosaari1cd72782010-10-12 17:22:32 -0300735static const struct af9015_rc_setup af9015_rc_setup_hashes[] = {
736 { 0xb8feb708, RC_MAP_MSI_DIGIVOX_II },
737 { 0xa3703d00, RC_MAP_ALINK_DTU_M },
738 { 0x9b7dc64e, RC_MAP_TOTAL_MEDIA_IN_HAND }, /* MYGICTV U718 */
Juergen Lock879b0d72011-06-12 17:25:12 -0300739 { 0x5d49e3db, RC_MAP_DIGITTRADE }, /* LC-Power LC-USB-DVBT */
Jiri Slaby26c3b8b2010-01-22 12:10:54 -0300740 { }
741};
742
Antti Palosaari1cd72782010-10-12 17:22:32 -0300743static const struct af9015_rc_setup af9015_rc_setup_usbids[] = {
Antti Palosaarif68baef2011-07-28 19:17:59 -0300744 { (USB_VID_TERRATEC << 16) | USB_PID_TERRATEC_CINERGY_T_STICK_RC,
Antti Palosaari04599c22011-03-19 14:25:36 -0300745 RC_MAP_TERRATEC_SLIM_2 },
Antti Palosaarif68baef2011-07-28 19:17:59 -0300746 { (USB_VID_TERRATEC << 16) | USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC,
Antti Palosaari1cd72782010-10-12 17:22:32 -0300747 RC_MAP_TERRATEC_SLIM },
Antti Palosaarif68baef2011-07-28 19:17:59 -0300748 { (USB_VID_VISIONPLUS << 16) | USB_PID_AZUREWAVE_AD_TU700,
Antti Palosaari1cd72782010-10-12 17:22:32 -0300749 RC_MAP_AZUREWAVE_AD_TU700 },
Antti Palosaarif68baef2011-07-28 19:17:59 -0300750 { (USB_VID_VISIONPLUS << 16) | USB_PID_TINYTWIN,
Antti Palosaari1cd72782010-10-12 17:22:32 -0300751 RC_MAP_AZUREWAVE_AD_TU700 },
Antti Palosaarif68baef2011-07-28 19:17:59 -0300752 { (USB_VID_MSI_2 << 16) | USB_PID_MSI_DIGI_VOX_MINI_III,
Antti Palosaari1cd72782010-10-12 17:22:32 -0300753 RC_MAP_MSI_DIGIVOX_III },
Antti Palosaarif68baef2011-07-28 19:17:59 -0300754 { (USB_VID_MSI_2 << 16) | USB_PID_MSI_DIGIVOX_DUO,
Antti Palosaariae81aab2011-06-15 11:29:47 -0300755 RC_MAP_MSI_DIGIVOX_III },
Antti Palosaarif68baef2011-07-28 19:17:59 -0300756 { (USB_VID_LEADTEK << 16) | USB_PID_WINFAST_DTV_DONGLE_GOLD,
Antti Palosaari1cd72782010-10-12 17:22:32 -0300757 RC_MAP_LEADTEK_Y04G0051 },
Antti Palosaarif68baef2011-07-28 19:17:59 -0300758 { (USB_VID_LEADTEK << 16) | USB_PID_WINFAST_DTV2000DS,
Antti Palosaari4c0cfa22011-07-28 19:15:38 -0300759 RC_MAP_LEADTEK_Y04G0051 },
Antti Palosaarif68baef2011-07-28 19:17:59 -0300760 { (USB_VID_AVERMEDIA << 16) | USB_PID_AVERMEDIA_VOLAR_X,
Antti Palosaari1cd72782010-10-12 17:22:32 -0300761 RC_MAP_AVERMEDIA_M135A },
Antti Palosaarif68baef2011-07-28 19:17:59 -0300762 { (USB_VID_AFATECH << 16) | USB_PID_TREKSTOR_DVBT,
Antti Palosaari1cd72782010-10-12 17:22:32 -0300763 RC_MAP_TREKSTOR },
Antti Palosaarif68baef2011-07-28 19:17:59 -0300764 { (USB_VID_KWORLD_2 << 16) | USB_PID_TINYTWIN_2,
Antti Palosaaribd864ce2010-10-22 20:37:11 -0300765 RC_MAP_DIGITALNOW_TINYTWIN },
Antti Palosaarif68baef2011-07-28 19:17:59 -0300766 { (USB_VID_GTEK << 16) | USB_PID_TINYTWIN_3,
Antti Palosaarif8c61272010-10-23 07:35:31 -0300767 RC_MAP_DIGITALNOW_TINYTWIN },
Antti Palosaarif68baef2011-07-28 19:17:59 -0300768 { (USB_VID_KWORLD_2 << 16) | USB_PID_SVEON_STV22,
Emilio David Diaus Lopeza062d042011-07-12 19:53:39 -0300769 RC_MAP_MSI_DIGIVOX_III },
Jiri Slabye3a0cc62010-01-22 12:10:55 -0300770 { }
771};
772
Jiri Slaby634d2d72010-01-22 12:10:53 -0300773static void af9015_set_remote_config(struct usb_device *udev,
774 struct dvb_usb_device_properties *props)
775{
Antti Palosaari1cd72782010-10-12 17:22:32 -0300776 u16 vid = le16_to_cpu(udev->descriptor.idVendor);
777 u16 pid = le16_to_cpu(udev->descriptor.idProduct);
Jiri Slaby26c3b8b2010-01-22 12:10:54 -0300778
Antti Palosaari1cd72782010-10-12 17:22:32 -0300779 /* try to load remote based module param */
780 props->rc.core.rc_codes = af9015_rc_setup_match(
781 dvb_usb_af9015_remote, af9015_rc_setup_modparam);
Jiri Slaby26c3b8b2010-01-22 12:10:54 -0300782
Antti Palosaari1cd72782010-10-12 17:22:32 -0300783 /* try to load remote based eeprom hash */
784 if (!props->rc.core.rc_codes)
785 props->rc.core.rc_codes = af9015_rc_setup_match(
786 af9015_config.eeprom_sum, af9015_rc_setup_hashes);
Jiri Slabye3a0cc62010-01-22 12:10:55 -0300787
Antti Palosaari1cd72782010-10-12 17:22:32 -0300788 /* try to load remote based USB ID */
789 if (!props->rc.core.rc_codes)
790 props->rc.core.rc_codes = af9015_rc_setup_match(
Antti Palosaaribc050e62012-05-08 06:04:24 -0300791 (vid << 16) | pid, af9015_rc_setup_usbids);
Antti Palosaari1cd72782010-10-12 17:22:32 -0300792
793 /* try to load remote based USB iManufacturer string */
794 if (!props->rc.core.rc_codes && vid == USB_VID_AFATECH) {
795 /* Check USB manufacturer and product strings and try
796 to determine correct remote in case of chip vendor
797 reference IDs are used.
798 DO NOT ADD ANYTHING NEW HERE. Use hashes instead. */
799 char manufacturer[10];
800 memset(manufacturer, 0, sizeof(manufacturer));
801 usb_string(udev, udev->descriptor.iManufacturer,
802 manufacturer, sizeof(manufacturer));
803 if (!strcmp("MSI", manufacturer)) {
804 /* iManufacturer 1 MSI
805 iProduct 2 MSI K-VOX */
806 props->rc.core.rc_codes = af9015_rc_setup_match(
807 AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
808 af9015_rc_setup_modparam);
809 }
Jiri Slaby26c3b8b2010-01-22 12:10:54 -0300810 }
Antti Palosaari74c8e3a2010-10-22 18:45:18 -0300811
812 /* finally load "empty" just for leaving IR receiver enabled */
813 if (!props->rc.core.rc_codes)
814 props->rc.core.rc_codes = RC_MAP_EMPTY;
815
Antti Palosaari1cd72782010-10-12 17:22:32 -0300816 return;
Jiri Slaby634d2d72010-01-22 12:10:53 -0300817}
818
Antti Palosaari80619de2008-09-15 17:18:09 -0300819static int af9015_read_config(struct usb_device *udev)
820{
821 int ret;
822 u8 val, i, offset = 0;
823 struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
Antti Palosaari80619de2008-09-15 17:18:09 -0300824
825 /* IR remote controller */
826 req.addr = AF9015_EEPROM_IR_MODE;
Antti Palosaarid1a470f2009-01-20 14:56:20 -0300827 /* first message will timeout often due to possible hw bug */
828 for (i = 0; i < 4; i++) {
829 ret = af9015_rw_udev(udev, &req);
830 if (!ret)
831 break;
832 }
Antti Palosaari80619de2008-09-15 17:18:09 -0300833 if (ret)
834 goto error;
Jiri Slaby6c614042010-01-22 12:10:52 -0300835
836 ret = af9015_eeprom_hash(udev);
837 if (ret)
838 goto error;
839
Antti Palosaarif571e002011-11-28 20:58:11 -0300840 deb_info("%s: IR mode=%d\n", __func__, val);
Antti Palosaari80619de2008-09-15 17:18:09 -0300841 for (i = 0; i < af9015_properties_count; i++) {
Antti Palosaari74c8e3a2010-10-22 18:45:18 -0300842 if (val == AF9015_IR_MODE_DISABLED)
843 af9015_properties[i].rc.core.rc_codes = NULL;
844 else
Jiri Slaby634d2d72010-01-22 12:10:53 -0300845 af9015_set_remote_config(udev, &af9015_properties[i]);
Antti Palosaari80619de2008-09-15 17:18:09 -0300846 }
847
848 /* TS mode - one or two receivers */
849 req.addr = AF9015_EEPROM_TS_MODE;
850 ret = af9015_rw_udev(udev, &req);
851 if (ret)
852 goto error;
853 af9015_config.dual_mode = val;
Antti Palosaarif571e002011-11-28 20:58:11 -0300854 deb_info("%s: TS mode=%d\n", __func__, af9015_config.dual_mode);
Antti Palosaari80619de2008-09-15 17:18:09 -0300855
Antti Palosaarif0830eb2009-01-13 13:08:29 -0300856 /* Set adapter0 buffer size according to USB port speed, adapter1 buffer
857 size can be static because it is enabled only USB2.0 */
Antti Palosaari80619de2008-09-15 17:18:09 -0300858 for (i = 0; i < af9015_properties_count; i++) {
859 /* USB1.1 set smaller buffersize and disable 2nd adapter */
860 if (udev->speed == USB_SPEED_FULL) {
Michael Krufky77eed212011-09-06 09:31:57 -0300861 af9015_properties[i].adapter[0].fe[0].stream.u.bulk.buffersize
Antti Palosaari9c863272009-09-12 13:35:29 -0300862 = TS_USB11_FRAME_SIZE;
Antti Palosaari80619de2008-09-15 17:18:09 -0300863 /* disable 2nd adapter because we don't have
864 PID-filters */
865 af9015_config.dual_mode = 0;
866 } else {
Michael Krufky77eed212011-09-06 09:31:57 -0300867 af9015_properties[i].adapter[0].fe[0].stream.u.bulk.buffersize
Jose Alberto Reguero353330c2009-09-12 09:51:36 -0300868 = TS_USB20_FRAME_SIZE;
Antti Palosaari80619de2008-09-15 17:18:09 -0300869 }
870 }
871
872 if (af9015_config.dual_mode) {
873 /* read 2nd demodulator I2C address */
874 req.addr = AF9015_EEPROM_DEMOD2_I2C;
875 ret = af9015_rw_udev(udev, &req);
876 if (ret)
877 goto error;
Antti Palosaarif571e002011-11-28 20:58:11 -0300878 af9015_af9013_config[1].i2c_addr = val;
Antti Palosaari80619de2008-09-15 17:18:09 -0300879
880 /* enable 2nd adapter */
881 for (i = 0; i < af9015_properties_count; i++)
882 af9015_properties[i].num_adapters = 2;
883
884 } else {
885 /* disable 2nd adapter */
886 for (i = 0; i < af9015_properties_count; i++)
887 af9015_properties[i].num_adapters = 1;
888 }
889
890 for (i = 0; i < af9015_properties[0].num_adapters; i++) {
891 if (i == 1)
892 offset = AF9015_EEPROM_OFFSET;
893 /* xtal */
894 req.addr = AF9015_EEPROM_XTAL_TYPE1 + offset;
895 ret = af9015_rw_udev(udev, &req);
896 if (ret)
897 goto error;
898 switch (val) {
899 case 0:
Antti Palosaarif571e002011-11-28 20:58:11 -0300900 af9015_af9013_config[i].clock = 28800000;
Antti Palosaari80619de2008-09-15 17:18:09 -0300901 break;
902 case 1:
Antti Palosaarif571e002011-11-28 20:58:11 -0300903 af9015_af9013_config[i].clock = 20480000;
Antti Palosaari80619de2008-09-15 17:18:09 -0300904 break;
905 case 2:
Antti Palosaarif571e002011-11-28 20:58:11 -0300906 af9015_af9013_config[i].clock = 28000000;
Antti Palosaari80619de2008-09-15 17:18:09 -0300907 break;
908 case 3:
Antti Palosaarif571e002011-11-28 20:58:11 -0300909 af9015_af9013_config[i].clock = 25000000;
Antti Palosaari80619de2008-09-15 17:18:09 -0300910 break;
911 };
Antti Palosaarif571e002011-11-28 20:58:11 -0300912 deb_info("%s: [%d] xtal=%d set clock=%d\n", __func__, i,
913 val, af9015_af9013_config[i].clock);
Antti Palosaari80619de2008-09-15 17:18:09 -0300914
Antti Palosaarif571e002011-11-28 20:58:11 -0300915 /* IF frequency */
Antti Palosaari80619de2008-09-15 17:18:09 -0300916 req.addr = AF9015_EEPROM_IF1H + offset;
917 ret = af9015_rw_udev(udev, &req);
918 if (ret)
919 goto error;
Antti Palosaarif571e002011-11-28 20:58:11 -0300920
921 af9015_af9013_config[i].if_frequency = val << 8;
922
Antti Palosaari80619de2008-09-15 17:18:09 -0300923 req.addr = AF9015_EEPROM_IF1L + offset;
924 ret = af9015_rw_udev(udev, &req);
925 if (ret)
926 goto error;
Antti Palosaarif571e002011-11-28 20:58:11 -0300927
928 af9015_af9013_config[i].if_frequency += val;
929 af9015_af9013_config[i].if_frequency *= 1000;
930 deb_info("%s: [%d] IF frequency=%d\n", __func__, i,
931 af9015_af9013_config[0].if_frequency);
Antti Palosaari80619de2008-09-15 17:18:09 -0300932
933 /* MT2060 IF1 */
934 req.addr = AF9015_EEPROM_MT2060_IF1H + offset;
935 ret = af9015_rw_udev(udev, &req);
936 if (ret)
937 goto error;
938 af9015_config.mt2060_if1[i] = val << 8;
939 req.addr = AF9015_EEPROM_MT2060_IF1L + offset;
940 ret = af9015_rw_udev(udev, &req);
941 if (ret)
942 goto error;
943 af9015_config.mt2060_if1[i] += val;
Antti Palosaarif571e002011-11-28 20:58:11 -0300944 deb_info("%s: [%d] MT2060 IF1=%d\n", __func__, i,
Antti Palosaari80619de2008-09-15 17:18:09 -0300945 af9015_config.mt2060_if1[i]);
946
947 /* tuner */
948 req.addr = AF9015_EEPROM_TUNER_ID1 + offset;
949 ret = af9015_rw_udev(udev, &req);
950 if (ret)
951 goto error;
952 switch (val) {
953 case AF9013_TUNER_ENV77H11D5:
954 case AF9013_TUNER_MT2060:
Antti Palosaari80619de2008-09-15 17:18:09 -0300955 case AF9013_TUNER_QT1010:
956 case AF9013_TUNER_UNKNOWN:
957 case AF9013_TUNER_MT2060_2:
958 case AF9013_TUNER_TDA18271:
959 case AF9013_TUNER_QT1010A:
Antti Palosaariee3d4402010-08-13 03:51:26 -0300960 case AF9013_TUNER_TDA18218:
Antti Palosaarif571e002011-11-28 20:58:11 -0300961 af9015_af9013_config[i].spec_inv = 1;
Antti Palosaari80619de2008-09-15 17:18:09 -0300962 break;
963 case AF9013_TUNER_MXL5003D:
964 case AF9013_TUNER_MXL5005D:
965 case AF9013_TUNER_MXL5005R:
Antti Palosaariab07fdd2010-09-09 14:59:10 -0300966 case AF9013_TUNER_MXL5007T:
Antti Palosaarif571e002011-11-28 20:58:11 -0300967 af9015_af9013_config[i].spec_inv = 0;
Antti Palosaari80619de2008-09-15 17:18:09 -0300968 break;
Jochen Friedrichd5633992009-02-02 14:59:50 -0300969 case AF9013_TUNER_MC44S803:
970 af9015_af9013_config[i].gpio[1] = AF9013_GPIO_LO;
Antti Palosaarif571e002011-11-28 20:58:11 -0300971 af9015_af9013_config[i].spec_inv = 1;
Jochen Friedrichd5633992009-02-02 14:59:50 -0300972 break;
Antti Palosaari80619de2008-09-15 17:18:09 -0300973 default:
Antti Palosaarif571e002011-11-28 20:58:11 -0300974 warn("tuner id=%d not supported, please report!", val);
Antti Palosaari80619de2008-09-15 17:18:09 -0300975 return -ENODEV;
976 };
977
978 af9015_af9013_config[i].tuner = val;
Antti Palosaarif571e002011-11-28 20:58:11 -0300979 deb_info("%s: [%d] tuner id=%d\n", __func__, i, val);
Antti Palosaari80619de2008-09-15 17:18:09 -0300980 }
981
982error:
983 if (ret)
Antti Palosaarif571e002011-11-28 20:58:11 -0300984 err("eeprom read failed=%d", ret);
Antti Palosaari80619de2008-09-15 17:18:09 -0300985
Antti Palosaari3956fef2009-03-31 17:01:02 -0300986 /* AverMedia AVerTV Volar Black HD (A850) device have bad EEPROM
Yann E. MORIN8ccdf1a2010-10-01 16:55:43 -0300987 content :-( Override some wrong values here. Ditto for the
988 AVerTV Red HD+ (A850T) device. */
Antti Palosaari3956fef2009-03-31 17:01:02 -0300989 if (le16_to_cpu(udev->descriptor.idVendor) == USB_VID_AVERMEDIA &&
Antti Palosaari9a3ecc72010-10-07 21:37:06 -0300990 ((le16_to_cpu(udev->descriptor.idProduct) ==
991 USB_PID_AVERMEDIA_A850) ||
992 (le16_to_cpu(udev->descriptor.idProduct) ==
993 USB_PID_AVERMEDIA_A850T))) {
Antti Palosaari3956fef2009-03-31 17:01:02 -0300994 deb_info("%s: AverMedia A850: overriding config\n", __func__);
995 /* disable dual mode */
996 af9015_config.dual_mode = 0;
997 /* disable 2nd adapter */
998 for (i = 0; i < af9015_properties_count; i++)
999 af9015_properties[i].num_adapters = 1;
1000
1001 /* set correct IF */
Antti Palosaarif571e002011-11-28 20:58:11 -03001002 af9015_af9013_config[0].if_frequency = 4570000;
Antti Palosaari3956fef2009-03-31 17:01:02 -03001003 }
1004
Antti Palosaari80619de2008-09-15 17:18:09 -03001005 return ret;
1006}
1007
1008static int af9015_identify_state(struct usb_device *udev,
1009 struct dvb_usb_device_properties *props,
1010 struct dvb_usb_device_description **desc,
1011 int *cold)
1012{
1013 int ret;
1014 u8 reply;
1015 struct req_t req = {GET_CONFIG, 0, 0, 0, 0, 1, &reply};
1016
1017 ret = af9015_rw_udev(udev, &req);
1018 if (ret)
1019 return ret;
1020
1021 deb_info("%s: reply:%02x\n", __func__, reply);
1022 if (reply == 0x02)
1023 *cold = 0;
1024 else
1025 *cold = 1;
1026
1027 return ret;
1028}
1029
Antti Palosaari1cd72782010-10-12 17:22:32 -03001030static int af9015_rc_query(struct dvb_usb_device *d)
Antti Palosaari80619de2008-09-15 17:18:09 -03001031{
Antti Palosaarid3bb73d2010-09-12 13:31:56 -03001032 struct af9015_state *priv = d->priv;
1033 int ret;
Ian Armstrongc1e13972011-03-18 19:23:05 -03001034 u8 buf[17];
Antti Palosaari80619de2008-09-15 17:18:09 -03001035
Antti Palosaarid3bb73d2010-09-12 13:31:56 -03001036 /* read registers needed to detect remote controller code */
Antti Palosaari74c8e3a2010-10-22 18:45:18 -03001037 ret = af9015_read_regs(d, 0x98d9, buf, sizeof(buf));
Antti Palosaari80619de2008-09-15 17:18:09 -03001038 if (ret)
Antti Palosaarid3bb73d2010-09-12 13:31:56 -03001039 goto error;
Antti Palosaari80619de2008-09-15 17:18:09 -03001040
Ian Armstrongc1e13972011-03-18 19:23:05 -03001041 /* If any of these are non-zero, assume invalid data */
1042 if (buf[1] || buf[2] || buf[3])
1043 return ret;
1044
1045 /* Check for repeat of previous code */
1046 if ((priv->rc_repeat != buf[6] || buf[0]) &&
1047 !memcmp(&buf[12], priv->rc_last, 4)) {
1048 deb_rc("%s: key repeated\n", __func__);
1049 rc_keydown(d->rc_dev, priv->rc_keycode, 0);
1050 priv->rc_repeat = buf[6];
1051 return ret;
1052 }
1053
1054 /* Only process key if canary killed */
1055 if (buf[16] != 0xff && buf[0] != 0x01) {
Antti Palosaari74c8e3a2010-10-22 18:45:18 -03001056 deb_rc("%s: key pressed %02x %02x %02x %02x\n", __func__,
1057 buf[12], buf[13], buf[14], buf[15]);
Antti Palosaari80619de2008-09-15 17:18:09 -03001058
Antti Palosaari1e8750c2011-03-18 19:36:42 -03001059 /* Reset the canary */
1060 ret = af9015_write_reg(d, 0x98e9, 0xff);
1061 if (ret)
1062 goto error;
1063
Ian Armstrongc1e13972011-03-18 19:23:05 -03001064 /* Remember this key */
1065 memcpy(priv->rc_last, &buf[12], 4);
Antti Palosaari74c8e3a2010-10-22 18:45:18 -03001066 if (buf[14] == (u8) ~buf[15]) {
1067 if (buf[12] == (u8) ~buf[13]) {
Antti Palosaari1cd72782010-10-12 17:22:32 -03001068 /* NEC */
Antti Palosaari74c8e3a2010-10-22 18:45:18 -03001069 priv->rc_keycode = buf[12] << 8 | buf[14];
Antti Palosaari1cd72782010-10-12 17:22:32 -03001070 } else {
1071 /* NEC extended*/
Antti Palosaari74c8e3a2010-10-22 18:45:18 -03001072 priv->rc_keycode = buf[12] << 16 |
1073 buf[13] << 8 | buf[14];
Antti Palosaari1cd72782010-10-12 17:22:32 -03001074 }
Antti Palosaari1cd72782010-10-12 17:22:32 -03001075 } else {
Antti Palosaari1e8750c2011-03-18 19:36:42 -03001076 /* 32 bit NEC */
Ian Armstrongc1e13972011-03-18 19:23:05 -03001077 priv->rc_keycode = buf[12] << 24 | buf[13] << 16 |
1078 buf[14] << 8 | buf[15];
Antti Palosaari1cd72782010-10-12 17:22:32 -03001079 }
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -03001080 rc_keydown(d->rc_dev, priv->rc_keycode, 0);
Antti Palosaarid3bb73d2010-09-12 13:31:56 -03001081 } else {
1082 deb_rc("%s: no key press\n", __func__);
Ian Armstrongc1e13972011-03-18 19:23:05 -03001083 /* Invalidate last keypress */
1084 /* Not really needed, but helps with debug */
1085 priv->rc_last[2] = priv->rc_last[3];
Antti Palosaari80619de2008-09-15 17:18:09 -03001086 }
Antti Palosaari80619de2008-09-15 17:18:09 -03001087
Antti Palosaari74c8e3a2010-10-22 18:45:18 -03001088 priv->rc_repeat = buf[6];
Antti Palosaarid3bb73d2010-09-12 13:31:56 -03001089
Antti Palosaarid3bb73d2010-09-12 13:31:56 -03001090error:
1091 if (ret)
1092 err("%s: failed:%d", __func__, ret);
1093
1094 return ret;
Antti Palosaari80619de2008-09-15 17:18:09 -03001095}
1096
Antti Palosaarie90ab842011-11-12 22:33:30 -03001097/* override demod callbacks for resource locking */
Mauro Carvalho Chehab0009e0e2011-12-31 07:03:36 -03001098static int af9015_af9013_set_frontend(struct dvb_frontend *fe)
Antti Palosaarie90ab842011-11-12 22:33:30 -03001099{
1100 int ret;
1101 struct dvb_usb_adapter *adap = fe->dvb->priv;
1102 struct af9015_state *priv = adap->dev->priv;
1103
1104 if (mutex_lock_interruptible(&adap->dev->usb_mutex))
1105 return -EAGAIN;
1106
Mauro Carvalho Chehab0009e0e2011-12-31 07:03:36 -03001107 ret = priv->set_frontend[adap->id](fe);
Antti Palosaarie90ab842011-11-12 22:33:30 -03001108
1109 mutex_unlock(&adap->dev->usb_mutex);
1110
1111 return ret;
1112}
1113
1114/* override demod callbacks for resource locking */
1115static int af9015_af9013_read_status(struct dvb_frontend *fe,
1116 fe_status_t *status)
1117{
1118 int ret;
1119 struct dvb_usb_adapter *adap = fe->dvb->priv;
1120 struct af9015_state *priv = adap->dev->priv;
1121
1122 if (mutex_lock_interruptible(&adap->dev->usb_mutex))
1123 return -EAGAIN;
1124
1125 ret = priv->read_status[adap->id](fe, status);
1126
1127 mutex_unlock(&adap->dev->usb_mutex);
1128
1129 return ret;
1130}
1131
1132/* override demod callbacks for resource locking */
1133static int af9015_af9013_init(struct dvb_frontend *fe)
1134{
1135 int ret;
1136 struct dvb_usb_adapter *adap = fe->dvb->priv;
1137 struct af9015_state *priv = adap->dev->priv;
1138
1139 if (mutex_lock_interruptible(&adap->dev->usb_mutex))
1140 return -EAGAIN;
1141
1142 ret = priv->init[adap->id](fe);
1143
1144 mutex_unlock(&adap->dev->usb_mutex);
1145
1146 return ret;
1147}
1148
1149/* override demod callbacks for resource locking */
1150static int af9015_af9013_sleep(struct dvb_frontend *fe)
1151{
1152 int ret;
1153 struct dvb_usb_adapter *adap = fe->dvb->priv;
1154 struct af9015_state *priv = adap->dev->priv;
1155
1156 if (mutex_lock_interruptible(&adap->dev->usb_mutex))
1157 return -EAGAIN;
1158
Antti Palosaarif571e002011-11-28 20:58:11 -03001159 ret = priv->sleep[adap->id](fe);
Antti Palosaarie90ab842011-11-12 22:33:30 -03001160
1161 mutex_unlock(&adap->dev->usb_mutex);
1162
1163 return ret;
1164}
1165
Antti Palosaari6d535bd2012-03-14 10:27:31 -03001166/* override tuner callbacks for resource locking */
1167static int af9015_tuner_init(struct dvb_frontend *fe)
1168{
1169 int ret;
1170 struct dvb_usb_adapter *adap = fe->dvb->priv;
1171 struct af9015_state *priv = adap->dev->priv;
1172
1173 if (mutex_lock_interruptible(&adap->dev->usb_mutex))
1174 return -EAGAIN;
1175
1176 ret = priv->tuner_init[adap->id](fe);
1177
1178 mutex_unlock(&adap->dev->usb_mutex);
1179
1180 return ret;
1181}
1182
1183/* override tuner callbacks for resource locking */
1184static int af9015_tuner_sleep(struct dvb_frontend *fe)
1185{
1186 int ret;
1187 struct dvb_usb_adapter *adap = fe->dvb->priv;
1188 struct af9015_state *priv = adap->dev->priv;
1189
1190 if (mutex_lock_interruptible(&adap->dev->usb_mutex))
1191 return -EAGAIN;
1192
1193 ret = priv->tuner_sleep[adap->id](fe);
1194
1195 mutex_unlock(&adap->dev->usb_mutex);
1196
1197 return ret;
1198}
1199
1200
Antti Palosaari80619de2008-09-15 17:18:09 -03001201static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap)
1202{
1203 int ret;
Antti Palosaarie90ab842011-11-12 22:33:30 -03001204 struct af9015_state *state = adap->dev->priv;
Antti Palosaari80619de2008-09-15 17:18:09 -03001205
Antti Palosaari713d9b52011-06-18 10:24:53 -03001206 if (adap->id == 1) {
Antti Palosaari80619de2008-09-15 17:18:09 -03001207 /* copy firmware to 2nd demodulator */
1208 if (af9015_config.dual_mode) {
1209 ret = af9015_copy_firmware(adap->dev);
1210 if (ret) {
1211 err("firmware copy to 2nd frontend " \
1212 "failed, will disable it");
1213 af9015_config.dual_mode = 0;
1214 return -ENODEV;
1215 }
1216 } else {
1217 return -ENODEV;
1218 }
1219 }
1220
1221 /* attach demodulator */
Antti Palosaaribc050e62012-05-08 06:04:24 -03001222 adap->fe_adap[0].fe = dvb_attach(af9013_attach,
1223 &af9015_af9013_config[adap->id], &adap->dev->i2c_adap);
Antti Palosaari80619de2008-09-15 17:18:09 -03001224
Antti Palosaarie90ab842011-11-12 22:33:30 -03001225 /*
1226 * AF9015 firmware does not like if it gets interrupted by I2C adapter
1227 * request on some critical phases. During normal operation I2C adapter
1228 * is used only 2nd demodulator and tuner on dual tuner devices.
1229 * Override demodulator callbacks and use mutex for limit access to
1230 * those "critical" paths to keep AF9015 happy.
1231 * Note: we abuse unused usb_mutex here.
1232 */
1233 if (adap->fe_adap[0].fe) {
1234 state->set_frontend[adap->id] =
1235 adap->fe_adap[0].fe->ops.set_frontend;
1236 adap->fe_adap[0].fe->ops.set_frontend =
1237 af9015_af9013_set_frontend;
1238
1239 state->read_status[adap->id] =
1240 adap->fe_adap[0].fe->ops.read_status;
1241 adap->fe_adap[0].fe->ops.read_status =
1242 af9015_af9013_read_status;
1243
1244 state->init[adap->id] = adap->fe_adap[0].fe->ops.init;
1245 adap->fe_adap[0].fe->ops.init = af9015_af9013_init;
1246
1247 state->sleep[adap->id] = adap->fe_adap[0].fe->ops.sleep;
1248 adap->fe_adap[0].fe->ops.sleep = af9015_af9013_sleep;
1249 }
1250
Michael Krufky77eed212011-09-06 09:31:57 -03001251 return adap->fe_adap[0].fe == NULL ? -ENODEV : 0;
Antti Palosaari80619de2008-09-15 17:18:09 -03001252}
1253
1254static struct mt2060_config af9015_mt2060_config = {
1255 .i2c_address = 0xc0,
1256 .clock_out = 0,
1257};
1258
1259static struct qt1010_config af9015_qt1010_config = {
1260 .i2c_address = 0xc4,
1261};
1262
1263static struct tda18271_config af9015_tda18271_config = {
1264 .gate = TDA18271_GATE_DIGITAL,
Mauro Carvalho Chehab7655e592010-10-27 14:55:34 -02001265 .small_i2c = TDA18271_16_BYTE_CHUNK_INIT,
Antti Palosaari80619de2008-09-15 17:18:09 -03001266};
1267
1268static struct mxl5005s_config af9015_mxl5003_config = {
1269 .i2c_address = 0xc6,
1270 .if_freq = IF_FREQ_4570000HZ,
1271 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
1272 .agc_mode = MXL_SINGLE_AGC,
1273 .tracking_filter = MXL_TF_DEFAULT,
Antti Palosaaria1310772008-09-22 13:59:25 -03001274 .rssi_enable = MXL_RSSI_ENABLE,
Antti Palosaari80619de2008-09-15 17:18:09 -03001275 .cap_select = MXL_CAP_SEL_ENABLE,
1276 .div_out = MXL_DIV_OUT_4,
1277 .clock_out = MXL_CLOCK_OUT_DISABLE,
1278 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
1279 .top = MXL5005S_TOP_25P2,
1280 .mod_mode = MXL_DIGITAL_MODE,
1281 .if_mode = MXL_ZERO_IF,
1282 .AgcMasterByte = 0x00,
1283};
1284
1285static struct mxl5005s_config af9015_mxl5005_config = {
1286 .i2c_address = 0xc6,
1287 .if_freq = IF_FREQ_4570000HZ,
1288 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
1289 .agc_mode = MXL_SINGLE_AGC,
1290 .tracking_filter = MXL_TF_OFF,
Antti Palosaaria1310772008-09-22 13:59:25 -03001291 .rssi_enable = MXL_RSSI_ENABLE,
Antti Palosaari80619de2008-09-15 17:18:09 -03001292 .cap_select = MXL_CAP_SEL_ENABLE,
1293 .div_out = MXL_DIV_OUT_4,
1294 .clock_out = MXL_CLOCK_OUT_DISABLE,
1295 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
1296 .top = MXL5005S_TOP_25P2,
1297 .mod_mode = MXL_DIGITAL_MODE,
1298 .if_mode = MXL_ZERO_IF,
1299 .AgcMasterByte = 0x00,
1300};
1301
Jochen Friedrichd5633992009-02-02 14:59:50 -03001302static struct mc44s803_config af9015_mc44s803_config = {
1303 .i2c_address = 0xc0,
1304 .dig_out = 1,
1305};
1306
Antti Palosaariee3d4402010-08-13 03:51:26 -03001307static struct tda18218_config af9015_tda18218_config = {
1308 .i2c_address = 0xc0,
1309 .i2c_wr_max = 21, /* max wr bytes AF9015 I2C adap can handle at once */
1310};
1311
Antti Palosaariab07fdd2010-09-09 14:59:10 -03001312static struct mxl5007t_config af9015_mxl5007t_config = {
1313 .xtal_freq_hz = MxL_XTAL_24_MHZ,
1314 .if_freq_hz = MxL_IF_4_57_MHZ,
1315};
1316
Antti Palosaari80619de2008-09-15 17:18:09 -03001317static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
1318{
Antti Palosaari80619de2008-09-15 17:18:09 -03001319 int ret;
Gordon Heckerbe4a5e72012-03-14 10:27:30 -03001320 struct af9015_state *state = adap->dev->priv;
Antti Palosaari9a3ecc72010-10-07 21:37:06 -03001321 deb_info("%s:\n", __func__);
Antti Palosaari80619de2008-09-15 17:18:09 -03001322
Antti Palosaari80619de2008-09-15 17:18:09 -03001323 switch (af9015_af9013_config[adap->id].tuner) {
1324 case AF9013_TUNER_MT2060:
1325 case AF9013_TUNER_MT2060_2:
Antti Palosaaribc050e62012-05-08 06:04:24 -03001326 ret = dvb_attach(mt2060_attach, adap->fe_adap[0].fe,
1327 &adap->dev->i2c_adap, &af9015_mt2060_config,
Antti Palosaari80619de2008-09-15 17:18:09 -03001328 af9015_config.mt2060_if1[adap->id])
1329 == NULL ? -ENODEV : 0;
1330 break;
1331 case AF9013_TUNER_QT1010:
1332 case AF9013_TUNER_QT1010A:
Antti Palosaaribc050e62012-05-08 06:04:24 -03001333 ret = dvb_attach(qt1010_attach, adap->fe_adap[0].fe,
1334 &adap->dev->i2c_adap,
Antti Palosaari80619de2008-09-15 17:18:09 -03001335 &af9015_qt1010_config) == NULL ? -ENODEV : 0;
1336 break;
1337 case AF9013_TUNER_TDA18271:
Michael Krufky77eed212011-09-06 09:31:57 -03001338 ret = dvb_attach(tda18271_attach, adap->fe_adap[0].fe, 0xc0,
Antti Palosaari713d9b52011-06-18 10:24:53 -03001339 &adap->dev->i2c_adap,
Antti Palosaari80619de2008-09-15 17:18:09 -03001340 &af9015_tda18271_config) == NULL ? -ENODEV : 0;
1341 break;
Antti Palosaariee3d4402010-08-13 03:51:26 -03001342 case AF9013_TUNER_TDA18218:
Michael Krufky77eed212011-09-06 09:31:57 -03001343 ret = dvb_attach(tda18218_attach, adap->fe_adap[0].fe,
Antti Palosaari713d9b52011-06-18 10:24:53 -03001344 &adap->dev->i2c_adap,
Antti Palosaariee3d4402010-08-13 03:51:26 -03001345 &af9015_tda18218_config) == NULL ? -ENODEV : 0;
1346 break;
Antti Palosaari80619de2008-09-15 17:18:09 -03001347 case AF9013_TUNER_MXL5003D:
Michael Krufky77eed212011-09-06 09:31:57 -03001348 ret = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
Antti Palosaari713d9b52011-06-18 10:24:53 -03001349 &adap->dev->i2c_adap,
Antti Palosaari80619de2008-09-15 17:18:09 -03001350 &af9015_mxl5003_config) == NULL ? -ENODEV : 0;
1351 break;
1352 case AF9013_TUNER_MXL5005D:
1353 case AF9013_TUNER_MXL5005R:
Michael Krufky77eed212011-09-06 09:31:57 -03001354 ret = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
Antti Palosaari713d9b52011-06-18 10:24:53 -03001355 &adap->dev->i2c_adap,
Antti Palosaari80619de2008-09-15 17:18:09 -03001356 &af9015_mxl5005_config) == NULL ? -ENODEV : 0;
1357 break;
1358 case AF9013_TUNER_ENV77H11D5:
Michael Krufky77eed212011-09-06 09:31:57 -03001359 ret = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0xc0,
Antti Palosaari713d9b52011-06-18 10:24:53 -03001360 &adap->dev->i2c_adap,
Antti Palosaari80619de2008-09-15 17:18:09 -03001361 DVB_PLL_TDA665X) == NULL ? -ENODEV : 0;
1362 break;
1363 case AF9013_TUNER_MC44S803:
Michael Krufky77eed212011-09-06 09:31:57 -03001364 ret = dvb_attach(mc44s803_attach, adap->fe_adap[0].fe,
Antti Palosaari713d9b52011-06-18 10:24:53 -03001365 &adap->dev->i2c_adap,
Jochen Friedrichd5633992009-02-02 14:59:50 -03001366 &af9015_mc44s803_config) == NULL ? -ENODEV : 0;
Antti Palosaari80619de2008-09-15 17:18:09 -03001367 break;
Antti Palosaariab07fdd2010-09-09 14:59:10 -03001368 case AF9013_TUNER_MXL5007T:
Michael Krufky77eed212011-09-06 09:31:57 -03001369 ret = dvb_attach(mxl5007t_attach, adap->fe_adap[0].fe,
Antti Palosaari713d9b52011-06-18 10:24:53 -03001370 &adap->dev->i2c_adap,
Antti Palosaariab07fdd2010-09-09 14:59:10 -03001371 0xc0, &af9015_mxl5007t_config) == NULL ? -ENODEV : 0;
1372 break;
Antti Palosaari80619de2008-09-15 17:18:09 -03001373 case AF9013_TUNER_UNKNOWN:
1374 default:
1375 ret = -ENODEV;
1376 err("Unknown tuner id:%d",
1377 af9015_af9013_config[adap->id].tuner);
1378 }
Gordon Heckerbe4a5e72012-03-14 10:27:30 -03001379
Antti Palosaari6d535bd2012-03-14 10:27:31 -03001380 if (adap->fe_adap[0].fe->ops.tuner_ops.init) {
1381 state->tuner_init[adap->id] =
1382 adap->fe_adap[0].fe->ops.tuner_ops.init;
1383 adap->fe_adap[0].fe->ops.tuner_ops.init = af9015_tuner_init;
1384 }
Gordon Heckerbe4a5e72012-03-14 10:27:30 -03001385
Antti Palosaari6d535bd2012-03-14 10:27:31 -03001386 if (adap->fe_adap[0].fe->ops.tuner_ops.sleep) {
1387 state->tuner_sleep[adap->id] =
1388 adap->fe_adap[0].fe->ops.tuner_ops.sleep;
1389 adap->fe_adap[0].fe->ops.tuner_ops.sleep = af9015_tuner_sleep;
1390 }
1391
Antti Palosaari80619de2008-09-15 17:18:09 -03001392 return ret;
1393}
1394
Jonathan Niederd07b9012012-01-07 04:11:27 -03001395enum af9015_usb_table_entry {
1396 AFATECH_9015,
1397 AFATECH_9016,
1398 WINFAST_DTV_GOLD,
1399 PINNACLE_PCTV_71E,
1400 KWORLD_PLUSTV_399U,
1401 TINYTWIN,
1402 AZUREWAVE_TU700,
1403 TERRATEC_AF9015,
1404 KWORLD_PLUSTV_PC160,
1405 AVERTV_VOLAR_X,
1406 XTENSIONS_380U,
1407 MSI_DIGIVOX_DUO,
1408 AVERTV_VOLAR_X_REV2,
1409 TELESTAR_STARSTICK_2,
1410 AVERMEDIA_A309_USB,
1411 MSI_DIGIVOX_MINI_III,
1412 KWORLD_E396,
1413 KWORLD_E39B,
1414 KWORLD_E395,
1415 TREKSTOR_DVBT,
1416 AVERTV_A850,
1417 AVERTV_A805,
1418 CONCEPTRONIC_CTVDIGRCU,
1419 KWORLD_MC810,
1420 GENIUS_TVGO_DVB_T03,
1421 KWORLD_399U_2,
1422 KWORLD_PC160_T,
1423 SVEON_STV20,
1424 TINYTWIN_2,
1425 WINFAST_DTV2000DS,
1426 KWORLD_UB383_T,
1427 KWORLD_E39A,
1428 AVERMEDIA_A815M,
1429 CINERGY_T_STICK_RC,
1430 CINERGY_T_DUAL_RC,
1431 AVERTV_A850T,
1432 TINYTWIN_3,
1433 SVEON_STV22,
1434};
1435
Antti Palosaari80619de2008-09-15 17:18:09 -03001436static struct usb_device_id af9015_usb_table[] = {
Antti Palosaaribc050e62012-05-08 06:04:24 -03001437 [AFATECH_9015] = {
1438 USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9015)},
1439 [AFATECH_9016] = {
1440 USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9016)},
1441 [WINFAST_DTV_GOLD] = {
1442 USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_GOLD)},
1443 [PINNACLE_PCTV_71E] = {
1444 USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV71E)},
1445 [KWORLD_PLUSTV_399U] = {
1446 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U)},
1447 [TINYTWIN] = {
1448 USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TINYTWIN)},
1449 [AZUREWAVE_TU700] = {
1450 USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_AZUREWAVE_AD_TU700)},
1451 [TERRATEC_AF9015] = {
1452 USB_DEVICE(USB_VID_TERRATEC,
Jonathan Niederd07b9012012-01-07 04:11:27 -03001453 USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2)},
Antti Palosaaribc050e62012-05-08 06:04:24 -03001454 [KWORLD_PLUSTV_PC160] = {
1455 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_2T)},
1456 [AVERTV_VOLAR_X] = {
1457 USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X)},
1458 [XTENSIONS_380U] = {
1459 USB_DEVICE(USB_VID_XTENSIONS, USB_PID_XTENSIONS_XD_380)},
1460 [MSI_DIGIVOX_DUO] = {
1461 USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGIVOX_DUO)},
1462 [AVERTV_VOLAR_X_REV2] = {
1463 USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X_2)},
1464 [TELESTAR_STARSTICK_2] = {
1465 USB_DEVICE(USB_VID_TELESTAR, USB_PID_TELESTAR_STARSTICK_2)},
1466 [AVERMEDIA_A309_USB] = {
1467 USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A309)},
1468 [MSI_DIGIVOX_MINI_III] = {
1469 USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGI_VOX_MINI_III)},
1470 [KWORLD_E396] = {
1471 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U)},
1472 [KWORLD_E39B] = {
1473 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_2)},
1474 [KWORLD_E395] = {
1475 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_3)},
1476 [TREKSTOR_DVBT] = {
1477 USB_DEVICE(USB_VID_AFATECH, USB_PID_TREKSTOR_DVBT)},
1478 [AVERTV_A850] = {
1479 USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850)},
1480 [AVERTV_A805] = {
1481 USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A805)},
1482 [CONCEPTRONIC_CTVDIGRCU] = {
1483 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CONCEPTRONIC_CTVDIGRCU)},
1484 [KWORLD_MC810] = {
1485 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_MC810)},
1486 [GENIUS_TVGO_DVB_T03] = {
1487 USB_DEVICE(USB_VID_KYE, USB_PID_GENIUS_TVGO_DVB_T03)},
1488 [KWORLD_399U_2] = {
1489 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U_2)},
1490 [KWORLD_PC160_T] = {
1491 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_T)},
1492 [SVEON_STV20] = {
1493 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20)},
1494 [TINYTWIN_2] = {
1495 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TINYTWIN_2)},
1496 [WINFAST_DTV2000DS] = {
1497 USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS)},
1498 [KWORLD_UB383_T] = {
1499 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB383_T)},
1500 [KWORLD_E39A] = {
1501 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_4)},
1502 [AVERMEDIA_A815M] = {
1503 USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A815M)},
1504 [CINERGY_T_STICK_RC] = {
1505 USB_DEVICE(USB_VID_TERRATEC,
Jonathan Niederd07b9012012-01-07 04:11:27 -03001506 USB_PID_TERRATEC_CINERGY_T_STICK_RC)},
Antti Palosaaribc050e62012-05-08 06:04:24 -03001507 [CINERGY_T_DUAL_RC] = {
1508 USB_DEVICE(USB_VID_TERRATEC,
Jonathan Niederd07b9012012-01-07 04:11:27 -03001509 USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC)},
Antti Palosaaribc050e62012-05-08 06:04:24 -03001510 [AVERTV_A850T] = {
1511 USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850T)},
1512 [TINYTWIN_3] = {
1513 USB_DEVICE(USB_VID_GTEK, USB_PID_TINYTWIN_3)},
1514 [SVEON_STV22] = {
1515 USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV22)},
Jonathan Niederd07b9012012-01-07 04:11:27 -03001516 { }
Antti Palosaari80619de2008-09-15 17:18:09 -03001517};
1518MODULE_DEVICE_TABLE(usb, af9015_usb_table);
1519
Antti Palosaarid3bb73d2010-09-12 13:31:56 -03001520#define AF9015_RC_INTERVAL 500
Antti Palosaari80619de2008-09-15 17:18:09 -03001521static struct dvb_usb_device_properties af9015_properties[] = {
1522 {
1523 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1524
1525 .usb_ctrl = DEVICE_SPECIFIC,
1526 .download_firmware = af9015_download_firmware,
1527 .firmware = "dvb-usb-af9015.fw",
Jose Alberto Reguerocce25712008-11-13 14:14:18 -03001528 .no_reconnect = 1,
Antti Palosaari80619de2008-09-15 17:18:09 -03001529
Antti Palosaari02542942009-09-16 20:33:03 -03001530 .size_of_priv = sizeof(struct af9015_state),
Antti Palosaari80619de2008-09-15 17:18:09 -03001531
1532 .num_adapters = 2,
1533 .adapter = {
1534 {
Antti Palosaaribc050e62012-05-08 06:04:24 -03001535 .num_frontends = 1,
1536 .fe = {
1537 {
1538 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1539 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
Antti Palosaari80619de2008-09-15 17:18:09 -03001540
Antti Palosaaribc050e62012-05-08 06:04:24 -03001541 .pid_filter_count = 32,
1542 .pid_filter = af9015_pid_filter,
1543 .pid_filter_ctrl = af9015_pid_filter_ctrl,
Antti Palosaari80619de2008-09-15 17:18:09 -03001544
Antti Palosaaribc050e62012-05-08 06:04:24 -03001545 .frontend_attach = af9015_af9013_frontend_attach,
1546 .tuner_attach = af9015_tuner_attach,
1547 .stream = {
1548 .type = USB_BULK,
1549 .count = 6,
1550 .endpoint = 0x84,
1551 },
Antti Palosaarif0830eb2009-01-13 13:08:29 -03001552 }
Antti Palosaari80619de2008-09-15 17:18:09 -03001553 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001554 },
1555 {
1556 .num_frontends = 1,
1557 .fe = {
1558 {
1559 .frontend_attach = af9015_af9013_frontend_attach,
1560 .tuner_attach = af9015_tuner_attach,
1561 .stream = {
1562 .type = USB_BULK,
1563 .count = 6,
1564 .endpoint = 0x85,
1565 .u = {
1566 .bulk = {
1567 .buffersize = TS_USB20_FRAME_SIZE,
1568 }
1569 }
1570 },
1571 }
1572 },
Antti Palosaari80619de2008-09-15 17:18:09 -03001573 }
1574 },
1575
1576 .identify_state = af9015_identify_state,
1577
Antti Palosaari1cd72782010-10-12 17:22:32 -03001578 .rc.core = {
Mauro Carvalho Chehab52b66142010-11-17 14:20:52 -03001579 .protocol = RC_TYPE_NEC,
Antti Palosaari1cd72782010-10-12 17:22:32 -03001580 .module_name = "af9015",
Antti Palosaari74c8e3a2010-10-22 18:45:18 -03001581 .rc_query = af9015_rc_query,
Antti Palosaarid3bb73d2010-09-12 13:31:56 -03001582 .rc_interval = AF9015_RC_INTERVAL,
Mauro Carvalho Chehab52b66142010-11-17 14:20:52 -03001583 .allowed_protos = RC_TYPE_NEC,
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001584 },
Antti Palosaari80619de2008-09-15 17:18:09 -03001585
1586 .i2c_algo = &af9015_i2c_algo,
1587
Yann E. MORIN8ccdf1a2010-10-01 16:55:43 -03001588 .num_device_descs = 12, /* check max from dvb-usb.h */
Antti Palosaari80619de2008-09-15 17:18:09 -03001589 .devices = {
1590 {
1591 .name = "Afatech AF9015 DVB-T USB2.0 stick",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001592 .cold_ids = {
1593 &af9015_usb_table[AFATECH_9015],
1594 &af9015_usb_table[AFATECH_9016],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001595 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001596 }, {
Antti Palosaari80619de2008-09-15 17:18:09 -03001597 .name = "Leadtek WinFast DTV Dongle Gold",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001598 .cold_ids = {
1599 &af9015_usb_table[WINFAST_DTV_GOLD],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001600 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001601 }, {
Antti Palosaari80619de2008-09-15 17:18:09 -03001602 .name = "Pinnacle PCTV 71e",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001603 .cold_ids = {
1604 &af9015_usb_table[PINNACLE_PCTV_71E],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001605 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001606 }, {
Antti Palosaari80619de2008-09-15 17:18:09 -03001607 .name = "KWorld PlusTV Dual DVB-T Stick " \
1608 "(DVB-T 399U)",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001609 .cold_ids = {
1610 &af9015_usb_table[KWORLD_PLUSTV_399U],
1611 &af9015_usb_table[KWORLD_399U_2],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001612 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001613 }, {
Antti Palosaari80619de2008-09-15 17:18:09 -03001614 .name = "DigitalNow TinyTwin DVB-T Receiver",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001615 .cold_ids = {
1616 &af9015_usb_table[TINYTWIN],
1617 &af9015_usb_table[TINYTWIN_2],
1618 &af9015_usb_table[TINYTWIN_3],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001619 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001620 }, {
Antti Palosaari80619de2008-09-15 17:18:09 -03001621 .name = "TwinHan AzureWave AD-TU700(704J)",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001622 .cold_ids = {
1623 &af9015_usb_table[AZUREWAVE_TU700],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001624 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001625 }, {
Antti Palosaari80619de2008-09-15 17:18:09 -03001626 .name = "TerraTec Cinergy T USB XE",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001627 .cold_ids = {
1628 &af9015_usb_table[TERRATEC_AF9015],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001629 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001630 }, {
Antti Palosaari80619de2008-09-15 17:18:09 -03001631 .name = "KWorld PlusTV Dual DVB-T PCI " \
1632 "(DVB-T PC160-2T)",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001633 .cold_ids = {
1634 &af9015_usb_table[KWORLD_PLUSTV_PC160],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001635 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001636 }, {
Antti Palosaari80619de2008-09-15 17:18:09 -03001637 .name = "AVerMedia AVerTV DVB-T Volar X",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001638 .cold_ids = {
1639 &af9015_usb_table[AVERTV_VOLAR_X],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001640 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001641 }, {
Antti Palosaari76391a72010-09-09 12:10:50 -03001642 .name = "TerraTec Cinergy T Stick RC",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001643 .cold_ids = {
1644 &af9015_usb_table[CINERGY_T_STICK_RC],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001645 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001646 }, {
Antti Palosaariab07fdd2010-09-09 14:59:10 -03001647 .name = "TerraTec Cinergy T Stick Dual RC",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001648 .cold_ids = {
1649 &af9015_usb_table[CINERGY_T_DUAL_RC],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001650 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001651 }, {
Yann E. MORIN8ccdf1a2010-10-01 16:55:43 -03001652 .name = "AverMedia AVerTV Red HD+ (A850T)",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001653 .cold_ids = {
1654 &af9015_usb_table[AVERTV_A850T],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001655 },
Yann E. MORIN8ccdf1a2010-10-01 16:55:43 -03001656 },
Antti Palosaari80619de2008-09-15 17:18:09 -03001657 }
1658 }, {
1659 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1660
1661 .usb_ctrl = DEVICE_SPECIFIC,
1662 .download_firmware = af9015_download_firmware,
1663 .firmware = "dvb-usb-af9015.fw",
Jose Alberto Reguerocce25712008-11-13 14:14:18 -03001664 .no_reconnect = 1,
Antti Palosaari80619de2008-09-15 17:18:09 -03001665
Antti Palosaari02542942009-09-16 20:33:03 -03001666 .size_of_priv = sizeof(struct af9015_state),
Antti Palosaari80619de2008-09-15 17:18:09 -03001667
1668 .num_adapters = 2,
1669 .adapter = {
1670 {
Antti Palosaaribc050e62012-05-08 06:04:24 -03001671 .num_frontends = 1,
1672 .fe = {
1673 {
1674 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1675 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
Antti Palosaari80619de2008-09-15 17:18:09 -03001676
Antti Palosaaribc050e62012-05-08 06:04:24 -03001677 .pid_filter_count = 32,
1678 .pid_filter = af9015_pid_filter,
1679 .pid_filter_ctrl = af9015_pid_filter_ctrl,
Antti Palosaari80619de2008-09-15 17:18:09 -03001680
Antti Palosaaribc050e62012-05-08 06:04:24 -03001681 .frontend_attach = af9015_af9013_frontend_attach,
1682 .tuner_attach = af9015_tuner_attach,
1683 .stream = {
1684 .type = USB_BULK,
1685 .count = 6,
1686 .endpoint = 0x84,
1687 },
Antti Palosaarif0830eb2009-01-13 13:08:29 -03001688 }
Antti Palosaari80619de2008-09-15 17:18:09 -03001689 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001690 },
1691 {
1692 .num_frontends = 1,
1693 .fe = {
1694 {
1695 .frontend_attach = af9015_af9013_frontend_attach,
1696 .tuner_attach = af9015_tuner_attach,
1697 .stream = {
1698 .type = USB_BULK,
1699 .count = 6,
1700 .endpoint = 0x85,
1701 .u = {
1702 .bulk = {
1703 .buffersize = TS_USB20_FRAME_SIZE,
1704 }
1705 }
1706 },
1707 }
1708 },
Antti Palosaari80619de2008-09-15 17:18:09 -03001709 }
1710 },
1711
1712 .identify_state = af9015_identify_state,
1713
Antti Palosaari1cd72782010-10-12 17:22:32 -03001714 .rc.core = {
Mauro Carvalho Chehab52b66142010-11-17 14:20:52 -03001715 .protocol = RC_TYPE_NEC,
Antti Palosaari1cd72782010-10-12 17:22:32 -03001716 .module_name = "af9015",
Antti Palosaari74c8e3a2010-10-22 18:45:18 -03001717 .rc_query = af9015_rc_query,
Antti Palosaarid3bb73d2010-09-12 13:31:56 -03001718 .rc_interval = AF9015_RC_INTERVAL,
Mauro Carvalho Chehab52b66142010-11-17 14:20:52 -03001719 .allowed_protos = RC_TYPE_NEC,
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001720 },
Antti Palosaari80619de2008-09-15 17:18:09 -03001721
1722 .i2c_algo = &af9015_i2c_algo,
1723
Emilio David Diaus Lopeza062d042011-07-12 19:53:39 -03001724 .num_device_descs = 10, /* check max from dvb-usb.h */
Antti Palosaari80619de2008-09-15 17:18:09 -03001725 .devices = {
1726 {
1727 .name = "Xtensions XD-380",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001728 .cold_ids = {
1729 &af9015_usb_table[XTENSIONS_380U],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001730 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001731 }, {
Antti Palosaari80619de2008-09-15 17:18:09 -03001732 .name = "MSI DIGIVOX Duo",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001733 .cold_ids = {
1734 &af9015_usb_table[MSI_DIGIVOX_DUO],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001735 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001736 }, {
Antti Palosaari80619de2008-09-15 17:18:09 -03001737 .name = "Fujitsu-Siemens Slim Mobile USB DVB-T",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001738 .cold_ids = {
1739 &af9015_usb_table[AVERTV_VOLAR_X_REV2],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001740 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001741 }, {
Antti Palosaaria3765882008-09-19 18:34:06 -03001742 .name = "Telestar Starstick 2",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001743 .cold_ids = {
1744 &af9015_usb_table[TELESTAR_STARSTICK_2],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001745 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001746 }, {
Antti Palosaari05c1cab2008-09-22 12:32:37 -03001747 .name = "AVerMedia A309",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001748 .cold_ids = {
1749 &af9015_usb_table[AVERMEDIA_A309_USB],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001750 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001751 }, {
Herbert Graeber641015a2008-10-07 10:06:36 -03001752 .name = "MSI Digi VOX mini III",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001753 .cold_ids = {
1754 &af9015_usb_table[MSI_DIGIVOX_MINI_III],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001755 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001756 }, {
Antti Palosaari163e9cd2008-11-04 12:57:47 -03001757 .name = "KWorld USB DVB-T TV Stick II " \
1758 "(VS-DVB-T 395U)",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001759 .cold_ids = {
1760 &af9015_usb_table[KWORLD_E396],
1761 &af9015_usb_table[KWORLD_E39B],
1762 &af9015_usb_table[KWORLD_E395],
1763 &af9015_usb_table[KWORLD_E39A],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001764 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001765 }, {
Marc Schneider26144842009-03-26 21:07:18 -03001766 .name = "TrekStor DVB-T USB Stick",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001767 .cold_ids = {
1768 &af9015_usb_table[TREKSTOR_DVBT],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001769 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001770 }, {
Antti Palosaari3956fef2009-03-31 17:01:02 -03001771 .name = "AverMedia AVerTV Volar Black HD " \
1772 "(A850)",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001773 .cold_ids = {
1774 &af9015_usb_table[AVERTV_A850],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001775 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001776 }, {
Emilio David Diaus Lopeza062d042011-07-12 19:53:39 -03001777 .name = "Sveon STV22 Dual USB DVB-T Tuner HDTV",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001778 .cold_ids = {
1779 &af9015_usb_table[SVEON_STV22],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001780 },
Emilio David Diaus Lopeza062d042011-07-12 19:53:39 -03001781 },
Antti Palosaari80619de2008-09-15 17:18:09 -03001782 }
Antti Palosaari85d7d7c2009-04-09 09:16:12 -03001783 }, {
1784 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1785
1786 .usb_ctrl = DEVICE_SPECIFIC,
1787 .download_firmware = af9015_download_firmware,
1788 .firmware = "dvb-usb-af9015.fw",
1789 .no_reconnect = 1,
1790
Antti Palosaari02542942009-09-16 20:33:03 -03001791 .size_of_priv = sizeof(struct af9015_state),
Antti Palosaari85d7d7c2009-04-09 09:16:12 -03001792
1793 .num_adapters = 2,
1794 .adapter = {
1795 {
Antti Palosaaribc050e62012-05-08 06:04:24 -03001796 .num_frontends = 1,
1797 .fe = {
1798 {
1799 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1800 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
Antti Palosaari85d7d7c2009-04-09 09:16:12 -03001801
Antti Palosaaribc050e62012-05-08 06:04:24 -03001802 .pid_filter_count = 32,
1803 .pid_filter = af9015_pid_filter,
1804 .pid_filter_ctrl = af9015_pid_filter_ctrl,
Antti Palosaari85d7d7c2009-04-09 09:16:12 -03001805
Antti Palosaaribc050e62012-05-08 06:04:24 -03001806 .frontend_attach = af9015_af9013_frontend_attach,
1807 .tuner_attach = af9015_tuner_attach,
1808 .stream = {
1809 .type = USB_BULK,
1810 .count = 6,
1811 .endpoint = 0x84,
1812 },
Antti Palosaari85d7d7c2009-04-09 09:16:12 -03001813 }
1814 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001815 },
1816 {
1817 .num_frontends = 1,
1818 .fe = {
1819 {
1820 .frontend_attach = af9015_af9013_frontend_attach,
1821 .tuner_attach = af9015_tuner_attach,
1822 .stream = {
1823 .type = USB_BULK,
1824 .count = 6,
1825 .endpoint = 0x85,
1826 .u = {
1827 .bulk = {
1828 .buffersize = TS_USB20_FRAME_SIZE,
1829 }
1830 }
1831 },
1832 }
1833 },
Antti Palosaari85d7d7c2009-04-09 09:16:12 -03001834 }
1835 },
1836
1837 .identify_state = af9015_identify_state,
1838
Antti Palosaari1cd72782010-10-12 17:22:32 -03001839 .rc.core = {
Mauro Carvalho Chehab52b66142010-11-17 14:20:52 -03001840 .protocol = RC_TYPE_NEC,
Antti Palosaari1cd72782010-10-12 17:22:32 -03001841 .module_name = "af9015",
Antti Palosaari74c8e3a2010-10-22 18:45:18 -03001842 .rc_query = af9015_rc_query,
Antti Palosaarid3bb73d2010-09-12 13:31:56 -03001843 .rc_interval = AF9015_RC_INTERVAL,
Mauro Carvalho Chehab52b66142010-11-17 14:20:52 -03001844 .allowed_protos = RC_TYPE_NEC,
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001845 },
Antti Palosaari85d7d7c2009-04-09 09:16:12 -03001846
1847 .i2c_algo = &af9015_i2c_algo,
1848
Antti Palosaaria44b91d2010-09-09 12:05:31 -03001849 .num_device_descs = 9, /* check max from dvb-usb.h */
Antti Palosaari85d7d7c2009-04-09 09:16:12 -03001850 .devices = {
Antti Palosaari1ed5fad2009-04-09 15:14:18 -03001851 {
1852 .name = "AverMedia AVerTV Volar GPS 805 (A805)",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001853 .cold_ids = {
1854 &af9015_usb_table[AVERTV_A805],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001855 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001856 }, {
Marcel Jueling734dd232009-04-09 17:16:41 -03001857 .name = "Conceptronic USB2.0 DVB-T CTVDIGRCU " \
1858 "V3.0",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001859 .cold_ids = {
1860 &af9015_usb_table[CONCEPTRONIC_CTVDIGRCU],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001861 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001862 }, {
Wen-chien Jesse Sung6e9c1a22009-04-28 01:11:22 -03001863 .name = "KWorld Digial MC-810",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001864 .cold_ids = {
1865 &af9015_usb_table[KWORLD_MC810],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001866 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001867 }, {
Antti Palosaari22d46452009-05-31 17:07:01 -03001868 .name = "Genius TVGo DVB-T03",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001869 .cold_ids = {
1870 &af9015_usb_table[GENIUS_TVGO_DVB_T03],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001871 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001872 }, {
Antti Palosaari486ba122009-09-18 13:37:57 -03001873 .name = "KWorld PlusTV DVB-T PCI Pro Card " \
1874 "(DVB-T PC160-T)",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001875 .cold_ids = {
1876 &af9015_usb_table[KWORLD_PC160_T],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001877 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001878 }, {
Ignacio de Miguel Diaz52322632009-11-13 23:13:34 -03001879 .name = "Sveon STV20 Tuner USB DVB-T HDTV",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001880 .cold_ids = {
1881 &af9015_usb_table[SVEON_STV20],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001882 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001883 }, {
Antti Palosaari809c1e82010-02-10 20:07:30 -03001884 .name = "Leadtek WinFast DTV2000DS",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001885 .cold_ids = {
1886 &af9015_usb_table[WINFAST_DTV2000DS],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001887 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001888 }, {
Antti Palosaariab9b4f22010-03-01 13:50:40 -03001889 .name = "KWorld USB DVB-T Stick Mobile " \
1890 "(UB383-T)",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001891 .cold_ids = {
1892 &af9015_usb_table[KWORLD_UB383_T],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001893 },
Antti Palosaaribc050e62012-05-08 06:04:24 -03001894 }, {
Antti Palosaari2606cfa2010-05-23 18:26:37 -03001895 .name = "AverMedia AVerTV Volar M (A815Mac)",
Jonathan Niederd07b9012012-01-07 04:11:27 -03001896 .cold_ids = {
1897 &af9015_usb_table[AVERMEDIA_A815M],
Jonathan Niederd07b9012012-01-07 04:11:27 -03001898 },
Antti Palosaari2606cfa2010-05-23 18:26:37 -03001899 },
Antti Palosaari85d7d7c2009-04-09 09:16:12 -03001900 }
1901 },
Antti Palosaari80619de2008-09-15 17:18:09 -03001902};
Antti Palosaari80619de2008-09-15 17:18:09 -03001903
1904static int af9015_usb_probe(struct usb_interface *intf,
1905 const struct usb_device_id *id)
1906{
1907 int ret = 0;
1908 struct dvb_usb_device *d = NULL;
1909 struct usb_device *udev = interface_to_usbdev(intf);
1910 u8 i;
1911
1912 deb_info("%s: interface:%d\n", __func__,
1913 intf->cur_altsetting->desc.bInterfaceNumber);
1914
1915 /* interface 0 is used by DVB-T receiver and
1916 interface 1 is for remote controller (HID) */
1917 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
1918 ret = af9015_read_config(udev);
1919 if (ret)
1920 return ret;
1921
1922 for (i = 0; i < af9015_properties_count; i++) {
1923 ret = dvb_usb_device_init(intf, &af9015_properties[i],
1924 THIS_MODULE, &d, adapter_nr);
1925 if (!ret)
1926 break;
1927 if (ret != -ENODEV)
1928 return ret;
1929 }
1930 if (ret)
1931 return ret;
1932
1933 if (d)
1934 ret = af9015_init(d);
1935 }
1936
1937 return ret;
1938}
1939
Antti Palosaari80619de2008-09-15 17:18:09 -03001940/* usb specific object needed to register this driver with the usb subsystem */
1941static struct usb_driver af9015_usb_driver = {
1942 .name = "dvb_usb_af9015",
1943 .probe = af9015_usb_probe,
Antti Palosaari713d9b52011-06-18 10:24:53 -03001944 .disconnect = dvb_usb_device_exit,
Antti Palosaari80619de2008-09-15 17:18:09 -03001945 .id_table = af9015_usb_table,
1946};
1947
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -08001948module_usb_driver(af9015_usb_driver);
Antti Palosaari80619de2008-09-15 17:18:09 -03001949
1950MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
Antti Palosaaribc050e62012-05-08 06:04:24 -03001951MODULE_DESCRIPTION("Afatech AF9015 driver");
Antti Palosaari80619de2008-09-15 17:18:09 -03001952MODULE_LICENSE("GPL");