blob: bddd7637fdaa6d01a68783b0daf7d4815ff79cc8 [file] [log] [blame]
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001/* DVB USB compliant linux driver for MSI Mega Sky 580 DVB-T USB2.0 receiver
2 *
3 * Copyright (C) 2006 Aapo Tahkola (aet@rasterburn.org)
4 *
5 * This program is free software; you can redistribute it and/or modify it
Michael Krufkyd3911ea2007-03-22 19:03:37 -03006 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation, version 2.
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03008 *
9 * see Documentation/dvb/README.dvb-usb for more information
10 */
Michael Krufkybaa2ed02006-09-23 20:01:29 -030011
Michael Krufky2aef7d02006-09-23 20:00:42 -030012#include "m920x.h"
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030013
14#include "mt352.h"
15#include "mt352_priv.h"
Michael Krufky017cf012006-09-23 20:40:20 -030016#include "qt1010.h"
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -030017#include "tda1004x.h"
18#include "tda827x.h"
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -030019
20#include <media/tuner.h>
21#include "tuner-simple.h"
Al Virofa9c13a2008-05-21 00:32:41 -030022#include <asm/unaligned.h>
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030023
24/* debug */
Michael Krufky26f48ea2006-09-28 01:46:49 -030025static int dvb_usb_m920x_debug;
Michael Krufkybaa2ed02006-09-23 20:01:29 -030026module_param_named(debug,dvb_usb_m920x_debug, int, 0644);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030027MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
28
Janne Grunau78e92002008-04-09 19:13:13 -030029DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
30
Aapo Tahkola47f8df02007-05-08 12:03:55 -030031static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid);
32
Aapo Tahkola4fd74a72007-03-26 17:05:59 -030033static inline int m920x_read(struct usb_device *udev, u8 request, u16 value,
Michael Krufkyfa948052007-01-21 15:57:48 -030034 u16 index, void *data, int size)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030035{
36 int ret;
37
38 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
39 request, USB_TYPE_VENDOR | USB_DIR_IN,
40 value, index, data, size, 2000);
Pierre Willenbrock59069e52007-03-15 13:24:29 -030041 if (ret < 0) {
42 printk(KERN_INFO "m920x_read = error: %d\n", ret);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030043 return ret;
Pierre Willenbrock59069e52007-03-15 13:24:29 -030044 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030045
Pierre Willenbrock59069e52007-03-15 13:24:29 -030046 if (ret != size) {
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -030047 deb("m920x_read = no data\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030048 return -EIO;
Pierre Willenbrock59069e52007-03-15 13:24:29 -030049 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030050
51 return 0;
52}
53
Aapo Tahkola4fd74a72007-03-26 17:05:59 -030054static inline int m920x_write(struct usb_device *udev, u8 request,
Michael Krufkyfa948052007-01-21 15:57:48 -030055 u16 value, u16 index)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030056{
57 int ret;
58
59 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
60 request, USB_TYPE_VENDOR | USB_DIR_OUT,
61 value, index, NULL, 0, 2000);
Pierre Willenbrock59069e52007-03-15 13:24:29 -030062
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -030063 return ret;
64}
65
Antonio Ospite7543f342012-12-10 17:37:11 -030066static inline int m920x_write_seq(struct usb_device *udev, u8 request,
67 struct m920x_inits *seq)
68{
69 int ret;
70 while (seq->address) {
71 ret = m920x_write(udev, request, seq->data, seq->address);
72 if (ret != 0)
73 return ret;
74
75 seq++;
76 }
77
78 return ret;
79}
80
Aapo Tahkola4fd74a72007-03-26 17:05:59 -030081static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -030082{
Aapo Tahkola3847b222007-05-08 18:21:47 -030083 int ret = 0, i, epi, flags = 0;
Aapo Tahkola47f8df02007-05-08 12:03:55 -030084 int adap_enabled[M9206_MAX_ADAPTERS] = { 0 };
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -030085
86 /* Remote controller init. */
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -030087 if (d->props.rc.legacy.rc_query) {
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -030088 deb("Initialising remote control\n");
Antonio Ospite7543f342012-12-10 17:37:11 -030089 ret = m920x_write_seq(d->udev, M9206_CORE, rc_seq);
90 if (ret != 0) {
91 deb("Initialising remote control failed\n");
92 return ret;
Nick Andrewaa50ec22007-03-22 17:09:35 -030093 }
94
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -030095 deb("Initialising remote control success\n");
Aapo Tahkola480ac762007-03-05 18:54:27 -030096 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030097
Aapo Tahkola3847b222007-05-08 18:21:47 -030098 for (i = 0; i < d->props.num_adapters; i++)
Michael Krufky77eed212011-09-06 09:31:57 -030099 flags |= d->adapter[i].props.fe[0].caps;
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300100
Aapo Tahkola3847b222007-05-08 18:21:47 -0300101 /* Some devices(Dposh) might crash if we attempt touch at all. */
102 if (flags & DVB_USB_ADAP_HAS_PID_FILTER) {
103 for (i = 0; i < d->props.num_adapters; i++) {
Michael Krufky77eed212011-09-06 09:31:57 -0300104 epi = d->adapter[i].props.fe[0].stream.endpoint - 0x81;
Aapo Tahkola3847b222007-05-08 18:21:47 -0300105
106 if (epi < 0 || epi >= M9206_MAX_ADAPTERS) {
107 printk(KERN_INFO "m920x: Unexpected adapter endpoint!\n");
108 return -EINVAL;
109 }
110
111 adap_enabled[epi] = 1;
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300112 }
113
Aapo Tahkola3847b222007-05-08 18:21:47 -0300114 for (i = 0; i < M9206_MAX_ADAPTERS; i++) {
115 if (adap_enabled[i])
116 continue;
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300117
Aapo Tahkola3847b222007-05-08 18:21:47 -0300118 if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x0)) != 0)
119 return ret;
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300120
Aapo Tahkola3847b222007-05-08 18:21:47 -0300121 if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x02f5)) != 0)
122 return ret;
123 }
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300124 }
125
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300126 return ret;
127}
128
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300129static int m920x_init_ep(struct usb_interface *intf)
130{
131 struct usb_device *udev = interface_to_usbdev(intf);
132 struct usb_host_interface *alt;
133
134 if ((alt = usb_altnum_to_altsetting(intf, 1)) == NULL) {
135 deb("No alt found!\n");
136 return -ENODEV;
137 }
138
139 return usb_set_interface(udev, alt->desc.bInterfaceNumber,
140 alt->desc.bAlternateSetting);
141}
142
Antonio Ospitef526e9e2012-12-10 17:37:12 -0300143static inline void m920x_parse_rc_state(struct dvb_usb_device *d, u8 rc_state,
144 int *state)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300145{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300146 struct m920x_state *m = d->priv;
Antonio Ospitef526e9e2012-12-10 17:37:12 -0300147
148 switch (rc_state) {
149 case 0x80:
150 *state = REMOTE_NO_KEY_PRESSED;
151 break;
152
153 case 0x88: /* framing error or "invalid code" */
154 case 0x99:
155 case 0xc0:
156 case 0xd8:
157 *state = REMOTE_NO_KEY_PRESSED;
158 m->rep_count = 0;
159 break;
160
161 case 0x93:
162 case 0x92:
163 case 0x83: /* pinnacle PCTV310e */
164 case 0x82:
165 m->rep_count = 0;
166 *state = REMOTE_KEY_PRESSED;
167 break;
168
169 case 0x91:
170 case 0x81: /* pinnacle PCTV310e */
171 /* prevent immediate auto-repeat */
172 if (++m->rep_count > 2)
173 *state = REMOTE_KEY_REPEAT;
174 else
175 *state = REMOTE_NO_KEY_PRESSED;
176 break;
177
178 default:
179 deb("Unexpected rc state %02x\n", rc_state);
180 *state = REMOTE_NO_KEY_PRESSED;
181 break;
182 }
183}
184
185static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
186{
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300187 int i, ret = 0;
Florian Mickler513ea352011-03-21 15:33:45 -0300188 u8 *rc_state;
189
190 rc_state = kmalloc(2, GFP_KERNEL);
191 if (!rc_state)
192 return -ENOMEM;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300193
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300194 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0)
Florian Mickler513ea352011-03-21 15:33:45 -0300195 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300196
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300197 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0)
Florian Mickler513ea352011-03-21 15:33:45 -0300198 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300199
Antonio Ospite7a7ef462012-12-10 17:37:13 -0300200 m920x_parse_rc_state(d, rc_state[0], state);
201
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300202 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
203 if (rc5_data(&d->props.rc.legacy.rc_map_table[i]) == rc_state[1]) {
204 *event = d->props.rc.legacy.rc_map_table[i].keycode;
Antonio Ospitef526e9e2012-12-10 17:37:12 -0300205 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300206 }
207
208 if (rc_state[1] != 0)
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300209 deb("Unknown rc key %02x\n", rc_state[1]);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300210
211 *state = REMOTE_NO_KEY_PRESSED;
212
Florian Mickler513ea352011-03-21 15:33:45 -0300213 out:
214 kfree(rc_state);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300215 return ret;
216}
217
Antonio Ospiteb6777572012-12-10 17:37:14 -0300218static int m920x_rc_core_query(struct dvb_usb_device *d)
219{
220 int ret = 0;
221 u8 *rc_state;
222 int state;
223
224 rc_state = kmalloc(2, GFP_KERNEL);
225 if (!rc_state)
226 return -ENOMEM;
227
228 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, &rc_state[0], 1)) != 0)
229 goto out;
230
231 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, &rc_state[1], 1)) != 0)
232 goto out;
233
234 deb("state=0x%02x keycode=0x%02x\n", rc_state[0], rc_state[1]);
235
236 m920x_parse_rc_state(d, rc_state[0], &state);
237
238 if (state == REMOTE_NO_KEY_PRESSED)
239 rc_keyup(d->rc_dev);
240 else if (state == REMOTE_KEY_REPEAT)
241 rc_repeat(d->rc_dev);
242 else
243 rc_keydown(d->rc_dev, rc_state[1], 0);
244
245out:
246 kfree(rc_state);
247 return ret;
248}
249
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300250/* I2C */
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300251static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300252{
253 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Aapo Tahkola26247012007-03-05 18:23:19 -0300254 int i, j;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300255 int ret = 0;
256
Trent Piephod40860f2007-03-05 23:55:00 -0300257 if (!num)
258 return -EINVAL;
259
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300260 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
261 return -EAGAIN;
262
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300263 for (i = 0; i < num; i++) {
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300264 if (msg[i].flags & (I2C_M_NO_RD_ACK | I2C_M_IGNORE_NAK | I2C_M_TEN) || msg[i].len == 0) {
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300265 /* For a 0 byte message, I think sending the address
266 * to index 0x80|0x40 would be the correct thing to
267 * do. However, zero byte messages are only used for
268 * probing, and since we don't know how to get the
269 * slave's ack, we can't probe. */
Trent Piephod40860f2007-03-05 23:55:00 -0300270 ret = -ENOTSUPP;
271 goto unlock;
272 }
273 /* Send START & address/RW bit */
274 if (!(msg[i].flags & I2C_M_NOSTART)) {
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300275 if ((ret = m920x_write(d->udev, M9206_I2C,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300276 (msg[i].addr << 1) |
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300277 (msg[i].flags & I2C_M_RD ? 0x01 : 0), 0x80)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300278 goto unlock;
279 /* Should check for ack here, if we knew how. */
280 }
Aapo Tahkola26247012007-03-05 18:23:19 -0300281 if (msg[i].flags & I2C_M_RD) {
Trent Piephod40860f2007-03-05 23:55:00 -0300282 for (j = 0; j < msg[i].len; j++) {
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300283 /* Last byte of transaction?
284 * Send STOP, otherwise send ACK. */
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300285 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x01;
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300286
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300287 if ((ret = m920x_read(d->udev, M9206_I2C, 0x0,
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300288 0x20 | stop,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300289 &msg[i].buf[j], 1)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300290 goto unlock;
Aapo Tahkola84ad7572007-01-21 15:57:20 -0300291 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300292 } else {
Trent Piephod40860f2007-03-05 23:55:00 -0300293 for (j = 0; j < msg[i].len; j++) {
294 /* Last byte of transaction? Then send STOP. */
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300295 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x00;
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300296
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300297 if ((ret = m920x_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300298 goto unlock;
299 /* Should check for ack here too. */
Aapo Tahkola26247012007-03-05 18:23:19 -0300300 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300301 }
302 }
Aapo Tahkola26247012007-03-05 18:23:19 -0300303 ret = num;
Trent Piephod40860f2007-03-05 23:55:00 -0300304
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300305 unlock:
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300306 mutex_unlock(&d->i2c_mutex);
307
308 return ret;
309}
310
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300311static u32 m920x_i2c_func(struct i2c_adapter *adapter)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300312{
313 return I2C_FUNC_I2C;
314}
315
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300316static struct i2c_algorithm m920x_i2c_algo = {
317 .master_xfer = m920x_i2c_xfer,
318 .functionality = m920x_i2c_func,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300319};
320
Michael Krufky5afb7072007-03-26 16:35:29 -0300321/* pid filter */
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300322static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300323{
324 int ret = 0;
325
326 if (pid >= 0x8000)
327 return -EINVAL;
328
329 pid |= 0x8000;
330
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300331 if ((ret = m920x_write(d->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300332 return ret;
333
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300334 if ((ret = m920x_write(d->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300335 return ret;
336
337 return ret;
338}
339
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300340static int m920x_update_filters(struct dvb_usb_adapter *adap)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300341{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300342 struct m920x_state *m = adap->dev->priv;
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300343 int enabled = m->filtering_enabled[adap->id];
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300344 int i, ret = 0, filter = 0;
Michael Krufky77eed212011-09-06 09:31:57 -0300345 int ep = adap->props.fe[0].stream.endpoint;
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300346
347 for (i = 0; i < M9206_MAX_FILTERS; i++)
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300348 if (m->filters[adap->id][i] == 8192)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300349 enabled = 0;
350
351 /* Disable all filters */
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300352 if ((ret = m920x_set_filter(adap->dev, ep, 1, enabled)) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300353 return ret;
354
355 for (i = 0; i < M9206_MAX_FILTERS; i++)
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300356 if ((ret = m920x_set_filter(adap->dev, ep, i + 2, 0)) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300357 return ret;
358
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300359 /* Set */
360 if (enabled) {
361 for (i = 0; i < M9206_MAX_FILTERS; i++) {
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300362 if (m->filters[adap->id][i] == 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300363 continue;
364
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300365 if ((ret = m920x_set_filter(adap->dev, ep, filter + 2, m->filters[adap->id][i])) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300366 return ret;
367
368 filter++;
369 }
370 }
371
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300372 return ret;
373}
374
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300375static int m920x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300376{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300377 struct m920x_state *m = adap->dev->priv;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300378
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300379 m->filtering_enabled[adap->id] = onoff ? 1 : 0;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300380
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300381 return m920x_update_filters(adap);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300382}
383
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300384static int m920x_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300385{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300386 struct m920x_state *m = adap->dev->priv;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300387
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300388 m->filters[adap->id][index] = onoff ? pid : 0;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300389
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300390 return m920x_update_filters(adap);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300391}
392
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300393static int m920x_firmware_download(struct usb_device *udev, const struct firmware *fw)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300394{
395 u16 value, index, size;
Florian Mickler513ea352011-03-21 15:33:45 -0300396 u8 *read, *buff;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300397 int i, pass, ret = 0;
398
399 buff = kmalloc(65536, GFP_KERNEL);
Roel Kluin1601fb12009-09-18 20:09:52 -0300400 if (buff == NULL)
401 return -ENOMEM;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300402
Florian Mickler513ea352011-03-21 15:33:45 -0300403 read = kmalloc(4, GFP_KERNEL);
404 if (!read) {
405 kfree(buff);
406 return -ENOMEM;
407 }
408
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300409 if ((ret = m920x_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300410 goto done;
Andy Shevchenko5bdb7872012-09-26 09:55:14 -0300411 deb("%*ph\n", 4, read);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300412
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300413 if ((ret = m920x_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300414 goto done;
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300415 deb("%x\n", read[0]);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300416
417 for (pass = 0; pass < 2; pass++) {
418 for (i = 0; i + (sizeof(u16) * 3) < fw->size;) {
Al Virofa9c13a2008-05-21 00:32:41 -0300419 value = get_unaligned_le16(fw->data + i);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300420 i += sizeof(u16);
421
Al Virofa9c13a2008-05-21 00:32:41 -0300422 index = get_unaligned_le16(fw->data + i);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300423 i += sizeof(u16);
424
Al Virofa9c13a2008-05-21 00:32:41 -0300425 size = get_unaligned_le16(fw->data + i);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300426 i += sizeof(u16);
427
428 if (pass == 1) {
429 /* Will stall if using fw->data ... */
430 memcpy(buff, fw->data + i, size);
431
432 ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0),
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300433 M9206_FW,
434 USB_TYPE_VENDOR | USB_DIR_OUT,
435 value, index, buff, size, 20);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300436 if (ret != size) {
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300437 deb("error while uploading fw!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300438 ret = -EIO;
439 goto done;
440 }
441 msleep(3);
442 }
443 i += size;
444 }
445 if (i != fw->size) {
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300446 deb("bad firmware file!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300447 ret = -EINVAL;
448 goto done;
449 }
450 }
451
452 msleep(36);
453
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300454 /* m920x will disconnect itself from the bus after this. */
455 (void) m920x_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300456 deb("firmware uploaded!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300457
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300458 done:
Florian Mickler513ea352011-03-21 15:33:45 -0300459 kfree(read);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300460 kfree(buff);
461
462 return ret;
463}
464
Michael Krufkye16c1f52007-01-23 15:00:42 -0300465/* Callbacks for DVB USB */
Aapo Tahkola7d1d4e62007-03-15 13:01:46 -0300466static int m920x_identify_state(struct usb_device *udev,
467 struct dvb_usb_device_properties *props,
468 struct dvb_usb_device_description **desc,
469 int *cold)
Michael Krufkye16c1f52007-01-23 15:00:42 -0300470{
471 struct usb_host_interface *alt;
472
473 alt = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 1);
474 *cold = (alt == NULL) ? 1 : 0;
475
476 return 0;
477}
478
Michael Krufky5afb7072007-03-26 16:35:29 -0300479/* demod configurations */
Michael Krufkye7b419b2007-03-26 16:39:20 -0300480static int m920x_mt352_demod_init(struct dvb_frontend *fe)
Michael Krufkye16c1f52007-01-23 15:00:42 -0300481{
Aapo Tahkolad577ee02007-05-08 18:33:52 -0300482 int ret;
Michael Krufkye16c1f52007-01-23 15:00:42 -0300483 u8 config[] = { CONFIG, 0x3d };
484 u8 clock[] = { CLOCK_CTL, 0x30 };
485 u8 reset[] = { RESET, 0x80 };
486 u8 adc_ctl[] = { ADC_CTL_1, 0x40 };
487 u8 agc[] = { AGC_TARGET, 0x1c, 0x20 };
488 u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 };
489 u8 unk1[] = { 0x93, 0x1a };
490 u8 unk2[] = { 0xb5, 0x7a };
491
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300492 deb("Demod init!\n");
Michael Krufkye16c1f52007-01-23 15:00:42 -0300493
Aapo Tahkolad577ee02007-05-08 18:33:52 -0300494 if ((ret = mt352_write(fe, config, ARRAY_SIZE(config))) != 0)
495 return ret;
496 if ((ret = mt352_write(fe, clock, ARRAY_SIZE(clock))) != 0)
497 return ret;
498 if ((ret = mt352_write(fe, reset, ARRAY_SIZE(reset))) != 0)
499 return ret;
500 if ((ret = mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl))) != 0)
501 return ret;
502 if ((ret = mt352_write(fe, agc, ARRAY_SIZE(agc))) != 0)
503 return ret;
504 if ((ret = mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc))) != 0)
505 return ret;
506 if ((ret = mt352_write(fe, unk1, ARRAY_SIZE(unk1))) != 0)
507 return ret;
508 if ((ret = mt352_write(fe, unk2, ARRAY_SIZE(unk2))) != 0)
509 return ret;
510
Michael Krufkye16c1f52007-01-23 15:00:42 -0300511 return 0;
512}
513
Michael Krufkye7b419b2007-03-26 16:39:20 -0300514static struct mt352_config m920x_mt352_config = {
Aapo Tahkola26247012007-03-05 18:23:19 -0300515 .demod_address = 0x0f,
Michael Krufkye16c1f52007-01-23 15:00:42 -0300516 .no_tuner = 1,
Michael Krufkye7b419b2007-03-26 16:39:20 -0300517 .demod_init = m920x_mt352_demod_init,
Michael Krufkye16c1f52007-01-23 15:00:42 -0300518};
519
Michael Krufkye7b419b2007-03-26 16:39:20 -0300520static struct tda1004x_config m920x_tda10046_08_config = {
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300521 .demod_address = 0x08,
522 .invert = 0,
523 .invert_oclk = 0,
524 .ts_mode = TDA10046_TS_SERIAL,
525 .xtal_freq = TDA10046_XTAL_16M,
526 .if_freq = TDA10046_FREQ_045,
527 .agc_config = TDA10046_AGC_TDA827X,
528 .gpio_config = TDA10046_GPTRI,
529 .request_firmware = NULL,
530};
531
Michael Krufkye7b419b2007-03-26 16:39:20 -0300532static struct tda1004x_config m920x_tda10046_0b_config = {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300533 .demod_address = 0x0b,
534 .invert = 0,
535 .invert_oclk = 0,
536 .ts_mode = TDA10046_TS_SERIAL,
537 .xtal_freq = TDA10046_XTAL_16M,
538 .if_freq = TDA10046_FREQ_045,
539 .agc_config = TDA10046_AGC_TDA827X,
540 .gpio_config = TDA10046_GPTRI,
541 .request_firmware = NULL, /* uses firmware EEPROM */
542};
543
Michael Krufky5afb7072007-03-26 16:35:29 -0300544/* tuner configurations */
Michael Krufkye7b419b2007-03-26 16:39:20 -0300545static struct qt1010_config m920x_qt1010_config = {
Michael Krufky5afb7072007-03-26 16:35:29 -0300546 .i2c_address = 0x62
547};
548
549/* Callbacks for DVB USB */
Michael Krufkye7b419b2007-03-26 16:39:20 -0300550static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300551{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300552 deb("%s\n",__func__);
Michael Krufky5afb7072007-03-26 16:35:29 -0300553
Michael Krufkyd12f51a2011-09-17 14:59:54 -0300554 adap->fe_adap[0].fe = dvb_attach(mt352_attach,
555 &m920x_mt352_config,
556 &adap->dev->i2c_adap);
557 if ((adap->fe_adap[0].fe) == NULL)
Michael Krufky5afb7072007-03-26 16:35:29 -0300558 return -EIO;
559
560 return 0;
561}
562
Michael Krufkye7b419b2007-03-26 16:39:20 -0300563static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300564{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300565 deb("%s\n",__func__);
Nick Andrewaa50ec22007-03-22 17:09:35 -0300566
Michael Krufkyd12f51a2011-09-17 14:59:54 -0300567 adap->fe_adap[0].fe = dvb_attach(tda10046_attach,
568 &m920x_tda10046_08_config,
569 &adap->dev->i2c_adap);
570 if ((adap->fe_adap[0].fe) == NULL)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300571 return -EIO;
572
Nick Andrewaa50ec22007-03-22 17:09:35 -0300573 return 0;
574}
575
Michael Krufkye7b419b2007-03-26 16:39:20 -0300576static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300577{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300578 deb("%s\n",__func__);
Nick Andrewaa50ec22007-03-22 17:09:35 -0300579
Michael Krufkyd12f51a2011-09-17 14:59:54 -0300580 adap->fe_adap[0].fe = dvb_attach(tda10046_attach,
581 &m920x_tda10046_0b_config,
582 &adap->dev->i2c_adap);
583 if ((adap->fe_adap[0].fe) == NULL)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300584 return -EIO;
585
Nick Andrewaa50ec22007-03-22 17:09:35 -0300586 return 0;
587}
588
Michael Krufkye7b419b2007-03-26 16:39:20 -0300589static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300590{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300591 deb("%s\n",__func__);
Michael Krufkye7b419b2007-03-26 16:39:20 -0300592
Michael Krufky77eed212011-09-06 09:31:57 -0300593 if (dvb_attach(qt1010_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL)
Michael Krufky5afb7072007-03-26 16:35:29 -0300594 return -ENODEV;
595
596 return 0;
597}
598
Michael Krufkye7b419b2007-03-26 16:39:20 -0300599static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300600{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300601 deb("%s\n",__func__);
Michael Krufkye7b419b2007-03-26 16:39:20 -0300602
Michael Krufky77eed212011-09-06 09:31:57 -0300603 if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL)
Michael Krufky5afb7072007-03-26 16:35:29 -0300604 return -ENODEV;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300605
606 return 0;
607}
608
Michael Krufkye7b419b2007-03-26 16:39:20 -0300609static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300610{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300611 deb("%s\n",__func__);
Nick Andrewaa50ec22007-03-22 17:09:35 -0300612
Michael Krufky77eed212011-09-06 09:31:57 -0300613 if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300614 return -ENODEV;
615
Nick Andrewaa50ec22007-03-22 17:09:35 -0300616 return 0;
617}
618
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300619static int m920x_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
620{
Michael Krufky77eed212011-09-06 09:31:57 -0300621 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300622 &adap->dev->i2c_adap, 0x61,
623 TUNER_PHILIPS_FMD1216ME_MK3);
624 return 0;
625}
626
Michael Krufky5afb7072007-03-26 16:35:29 -0300627/* device-specific initialization */
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300628static struct m920x_inits megasky_rc_init [] = {
Michael Krufky5afb7072007-03-26 16:35:29 -0300629 { M9206_RC_INIT2, 0xa8 },
630 { M9206_RC_INIT1, 0x51 },
631 { } /* terminating entry */
632};
633
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300634static struct m920x_inits tvwalkertwin_rc_init [] = {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300635 { M9206_RC_INIT2, 0x00 },
636 { M9206_RC_INIT1, 0xef },
637 { 0xff28, 0x00 },
638 { 0xff23, 0x00 },
639 { 0xff21, 0x30 },
640 { } /* terminating entry */
641};
642
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300643static struct m920x_inits pinnacle310e_init[] = {
Antonio Ospite90849832012-12-10 17:37:10 -0300644 /* without these the tuner doesn't work */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300645 { 0xff20, 0x9b },
646 { 0xff22, 0x70 },
647
648 /* rc settings */
649 { 0xff50, 0x80 },
650 { M9206_RC_INIT1, 0x00 },
651 { M9206_RC_INIT2, 0xff },
652 { } /* terminating entry */
653};
654
Michael Krufky5afb7072007-03-26 16:35:29 -0300655/* ir keymaps */
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300656static struct rc_map_table rc_map_megasky_table[] = {
Mauro Carvalho Chehab2e365882009-08-29 15:19:31 -0300657 { 0x0012, KEY_POWER },
658 { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */
659 { 0x0002, KEY_CHANNELUP },
660 { 0x0005, KEY_CHANNELDOWN },
661 { 0x0003, KEY_VOLUMEUP },
662 { 0x0006, KEY_VOLUMEDOWN },
663 { 0x0004, KEY_MUTE },
664 { 0x0007, KEY_OK }, /* TS */
665 { 0x0008, KEY_STOP },
666 { 0x0009, KEY_MENU }, /* swap */
667 { 0x000a, KEY_REWIND },
668 { 0x001b, KEY_PAUSE },
669 { 0x001f, KEY_FASTFORWARD },
670 { 0x000c, KEY_RECORD },
671 { 0x000d, KEY_CAMERA }, /* screenshot */
672 { 0x000e, KEY_COFFEE }, /* "MTS" */
Michael Krufky5afb7072007-03-26 16:35:29 -0300673};
674
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300675static struct rc_map_table rc_map_tvwalkertwin_table[] = {
Mauro Carvalho Chehab2e365882009-08-29 15:19:31 -0300676 { 0x0001, KEY_ZOOM }, /* Full Screen */
677 { 0x0002, KEY_CAMERA }, /* snapshot */
678 { 0x0003, KEY_MUTE },
679 { 0x0004, KEY_REWIND },
680 { 0x0005, KEY_PLAYPAUSE }, /* Play/Pause */
681 { 0x0006, KEY_FASTFORWARD },
682 { 0x0007, KEY_RECORD },
683 { 0x0008, KEY_STOP },
684 { 0x0009, KEY_TIME }, /* Timeshift */
685 { 0x000c, KEY_COFFEE }, /* Recall */
686 { 0x000e, KEY_CHANNELUP },
687 { 0x0012, KEY_POWER },
688 { 0x0015, KEY_MENU }, /* source */
689 { 0x0018, KEY_CYCLEWINDOWS }, /* TWIN PIP */
690 { 0x001a, KEY_CHANNELDOWN },
691 { 0x001b, KEY_VOLUMEDOWN },
692 { 0x001e, KEY_VOLUMEUP },
Michael Krufky5afb7072007-03-26 16:35:29 -0300693};
694
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300695static struct rc_map_table rc_map_pinnacle310e_table[] = {
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300696 { 0x16, KEY_POWER },
697 { 0x17, KEY_FAVORITES },
698 { 0x0f, KEY_TEXT },
Jarod Wilson56c08932011-04-05 18:42:30 -0300699 { 0x48, KEY_PROGRAM }, /* preview */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300700 { 0x1c, KEY_EPG },
Jarod Wilson56c08932011-04-05 18:42:30 -0300701 { 0x04, KEY_LIST }, /* record list */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300702 { 0x03, KEY_1 },
703 { 0x01, KEY_2 },
704 { 0x06, KEY_3 },
705 { 0x09, KEY_4 },
706 { 0x1d, KEY_5 },
707 { 0x1f, KEY_6 },
708 { 0x0d, KEY_7 },
709 { 0x19, KEY_8 },
710 { 0x1b, KEY_9 },
711 { 0x15, KEY_0 },
712 { 0x0c, KEY_CANCEL },
713 { 0x4a, KEY_CLEAR },
714 { 0x13, KEY_BACK },
715 { 0x00, KEY_TAB },
716 { 0x4b, KEY_UP },
717 { 0x4e, KEY_LEFT },
718 { 0x52, KEY_RIGHT },
719 { 0x51, KEY_DOWN },
720 { 0x4f, KEY_ENTER }, /* could also be KEY_OK */
721 { 0x1e, KEY_VOLUMEUP },
722 { 0x0a, KEY_VOLUMEDOWN },
723 { 0x05, KEY_CHANNELUP },
724 { 0x02, KEY_CHANNELDOWN },
725 { 0x11, KEY_RECORD },
726 { 0x14, KEY_PLAY },
727 { 0x4c, KEY_PAUSE },
728 { 0x1a, KEY_STOP },
729 { 0x40, KEY_REWIND },
730 { 0x12, KEY_FASTFORWARD },
731 { 0x41, KEY_PREVIOUSSONG }, /* Replay */
732 { 0x42, KEY_NEXTSONG }, /* Skip */
733 { 0x54, KEY_CAMERA }, /* Capture */
734/* { 0x50, KEY_SAP }, */ /* Sap */
735 { 0x47, KEY_CYCLEWINDOWS }, /* Pip */
736 { 0x4d, KEY_SCREEN }, /* FullScreen */
737 { 0x08, KEY_SUBTITLE },
738 { 0x0e, KEY_MUTE },
739/* { 0x49, KEY_LR }, */ /* L/R */
740 { 0x07, KEY_SLEEP }, /* Hibernate */
Jarod Wilson56c08932011-04-05 18:42:30 -0300741 { 0x08, KEY_VIDEO }, /* A/V */
742 { 0x0e, KEY_MENU }, /* Recall */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300743 { 0x45, KEY_ZOOMIN },
744 { 0x46, KEY_ZOOMOUT },
Jarod Wilson56c08932011-04-05 18:42:30 -0300745 { 0x18, KEY_RED }, /* Red */
746 { 0x53, KEY_GREEN }, /* Green */
747 { 0x5e, KEY_YELLOW }, /* Yellow */
748 { 0x5f, KEY_BLUE }, /* Blue */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300749};
750
Michael Krufky26f48ea2006-09-28 01:46:49 -0300751/* DVB USB Driver stuff */
752static struct dvb_usb_device_properties megasky_properties;
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300753static struct dvb_usb_device_properties digivox_mini_ii_properties;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300754static struct dvb_usb_device_properties tvwalkertwin_properties;
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300755static struct dvb_usb_device_properties dposh_properties;
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300756static struct dvb_usb_device_properties pinnacle_pctv310e_properties;
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300757
Michael Krufkyfa948052007-01-21 15:57:48 -0300758static int m920x_probe(struct usb_interface *intf,
759 const struct usb_device_id *id)
Michael Krufky26f48ea2006-09-28 01:46:49 -0300760{
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300761 struct dvb_usb_device *d = NULL;
Michael Krufky26f48ea2006-09-28 01:46:49 -0300762 int ret;
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300763 struct m920x_inits *rc_init_seq = NULL;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300764 int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
Michael Krufky26f48ea2006-09-28 01:46:49 -0300765
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300766 deb("Probing for m920x device at interface %d\n", bInterfaceNumber);
Michael Krufky26f48ea2006-09-28 01:46:49 -0300767
Nick Andrewaa50ec22007-03-22 17:09:35 -0300768 if (bInterfaceNumber == 0) {
769 /* Single-tuner device, or first interface on
770 * multi-tuner device
771 */
Michael Krufky26f48ea2006-09-28 01:46:49 -0300772
Janne Grunau78e92002008-04-09 19:13:13 -0300773 ret = dvb_usb_device_init(intf, &megasky_properties,
774 THIS_MODULE, &d, adapter_nr);
775 if (ret == 0) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300776 rc_init_seq = megasky_rc_init;
777 goto found;
778 }
779
Janne Grunau78e92002008-04-09 19:13:13 -0300780 ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties,
781 THIS_MODULE, &d, adapter_nr);
782 if (ret == 0) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300783 /* No remote control, so no rc_init_seq */
784 goto found;
785 }
786
787 /* This configures both tuners on the TV Walker Twin */
Janne Grunau78e92002008-04-09 19:13:13 -0300788 ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
789 THIS_MODULE, &d, adapter_nr);
790 if (ret == 0) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300791 rc_init_seq = tvwalkertwin_rc_init;
792 goto found;
793 }
794
Janne Grunau78e92002008-04-09 19:13:13 -0300795 ret = dvb_usb_device_init(intf, &dposh_properties,
796 THIS_MODULE, &d, adapter_nr);
797 if (ret == 0) {
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300798 /* Remote controller not supported yet. */
799 goto found;
800 }
801
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300802 ret = dvb_usb_device_init(intf, &pinnacle_pctv310e_properties,
803 THIS_MODULE, &d, adapter_nr);
804 if (ret == 0) {
805 rc_init_seq = pinnacle310e_init;
806 goto found;
807 }
808
Nick Andrewaa50ec22007-03-22 17:09:35 -0300809 return ret;
810 } else {
811 /* Another interface on a multi-tuner device */
812
813 /* The LifeView TV Walker Twin gets here, but struct
814 * tvwalkertwin_properties already configured both
815 * tuners, so there is nothing for us to do here
816 */
Nick Andrewaa50ec22007-03-22 17:09:35 -0300817 }
Michael Krufky26f48ea2006-09-28 01:46:49 -0300818
Michael Krufkye7b419b2007-03-26 16:39:20 -0300819 found:
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300820 if ((ret = m920x_init_ep(intf)) < 0)
Aapo Tahkola480ac762007-03-05 18:54:27 -0300821 return ret;
822
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300823 if (d && (ret = m920x_init(d, rc_init_seq)) != 0)
Aapo Tahkola480ac762007-03-05 18:54:27 -0300824 return ret;
825
Michael Krufky26f48ea2006-09-28 01:46:49 -0300826 return ret;
827}
828
829static struct usb_device_id m920x_table [] = {
830 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300831 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
832 USB_PID_MSI_DIGI_VOX_MINI_II) },
Nick Andrewaa50ec22007-03-22 17:09:35 -0300833 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
834 USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD) },
835 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
836 USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) },
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300837 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
838 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300839 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_PINNACLE_PCTV310E) },
Michael Krufky26f48ea2006-09-28 01:46:49 -0300840 { } /* Terminating entry */
841};
842MODULE_DEVICE_TABLE (usb, m920x_table);
843
Michael Krufky01cb34d2006-09-23 20:01:29 -0300844static struct dvb_usb_device_properties megasky_properties = {
Michael Krufky758117c2007-01-23 15:34:10 -0300845 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
Michael Krufky1f61f3b2006-10-07 15:03:04 -0300846
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300847 .usb_ctrl = DEVICE_SPECIFIC,
848 .firmware = "dvb-usb-megasky-02.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300849 .download_firmware = m920x_firmware_download,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300850
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300851 .rc.legacy = {
852 .rc_interval = 100,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300853 .rc_map_table = rc_map_megasky_table,
854 .rc_map_size = ARRAY_SIZE(rc_map_megasky_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300855 .rc_query = m920x_rc_query,
856 },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300857
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300858 .size_of_priv = sizeof(struct m920x_state),
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300859
Aapo Tahkola7d1d4e62007-03-15 13:01:46 -0300860 .identify_state = m920x_identify_state,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300861 .num_adapters = 1,
862 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -0300863 .num_frontends = 1,
864 .fe = {{
865
Michael Krufky758117c2007-01-23 15:34:10 -0300866 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
867 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
868
Michael Krufky01cb34d2006-09-23 20:01:29 -0300869 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300870 .pid_filter = m920x_pid_filter,
871 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300872
Michael Krufkye7b419b2007-03-26 16:39:20 -0300873 .frontend_attach = m920x_mt352_frontend_attach,
874 .tuner_attach = m920x_qt1010_tuner_attach,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300875
876 .stream = {
877 .type = USB_BULK,
878 .count = 8,
879 .endpoint = 0x81,
880 .u = {
881 .bulk = {
882 .buffersize = 512,
883 }
884 }
885 },
Michael Krufky77eed212011-09-06 09:31:57 -0300886 }},
Michael Krufky01cb34d2006-09-23 20:01:29 -0300887 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300888 .i2c_algo = &m920x_i2c_algo,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300889
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300890 .num_device_descs = 1,
891 .devices = {
892 { "MSI Mega Sky 580 DVB-T USB2.0",
Michael Krufkybaa2ed02006-09-23 20:01:29 -0300893 { &m920x_table[0], NULL },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300894 { NULL },
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300895 }
896 }
897};
898
899static struct dvb_usb_device_properties digivox_mini_ii_properties = {
900 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
901
902 .usb_ctrl = DEVICE_SPECIFIC,
903 .firmware = "dvb-usb-digivox-02.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300904 .download_firmware = m920x_firmware_download,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300905
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300906 .size_of_priv = sizeof(struct m920x_state),
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300907
908 .identify_state = m920x_identify_state,
909 .num_adapters = 1,
910 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -0300911 .num_frontends = 1,
912 .fe = {{
913
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300914 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300915 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300916
917 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300918 .pid_filter = m920x_pid_filter,
919 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300920
Michael Krufkye7b419b2007-03-26 16:39:20 -0300921 .frontend_attach = m920x_tda10046_08_frontend_attach,
922 .tuner_attach = m920x_tda8275_60_tuner_attach,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300923
924 .stream = {
925 .type = USB_BULK,
926 .count = 8,
927 .endpoint = 0x81,
928 .u = {
929 .bulk = {
930 .buffersize = 0x4000,
931 }
932 }
933 },
Michael Krufky77eed212011-09-06 09:31:57 -0300934 }},
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300935 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300936 .i2c_algo = &m920x_i2c_algo,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300937
938 .num_device_descs = 1,
939 .devices = {
940 { "MSI DIGI VOX mini II DVB-T USB2.0",
941 { &m920x_table[1], NULL },
942 { NULL },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300943 },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300944 }
945};
946
Michael Krufkye7b419b2007-03-26 16:39:20 -0300947/* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net>
948 *
949 * LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A
950 * TDA10046 #0 is located at i2c address 0x08
Aapo Tahkola3ab3b692007-05-08 18:23:38 -0300951 * TDA10046 #1 is located at i2c address 0x0b
Michael Krufkye7b419b2007-03-26 16:39:20 -0300952 * TDA8275A #0 is located at i2c address 0x60
Aapo Tahkola3ab3b692007-05-08 18:23:38 -0300953 * TDA8275A #1 is located at i2c address 0x61
Michael Krufkye7b419b2007-03-26 16:39:20 -0300954 */
Nick Andrewaa50ec22007-03-22 17:09:35 -0300955static struct dvb_usb_device_properties tvwalkertwin_properties = {
956 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
957
958 .usb_ctrl = DEVICE_SPECIFIC,
959 .firmware = "dvb-usb-tvwalkert.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300960 .download_firmware = m920x_firmware_download,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300961
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300962 .rc.legacy = {
963 .rc_interval = 100,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300964 .rc_map_table = rc_map_tvwalkertwin_table,
965 .rc_map_size = ARRAY_SIZE(rc_map_tvwalkertwin_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300966 .rc_query = m920x_rc_query,
967 },
Nick Andrewaa50ec22007-03-22 17:09:35 -0300968
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300969 .size_of_priv = sizeof(struct m920x_state),
Nick Andrewaa50ec22007-03-22 17:09:35 -0300970
971 .identify_state = m920x_identify_state,
Aapo Tahkola3ab3b692007-05-08 18:23:38 -0300972 .num_adapters = 2,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300973 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -0300974 .num_frontends = 1,
975 .fe = {{
976
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300977 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
978 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300979
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300980 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300981 .pid_filter = m920x_pid_filter,
982 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300983
Michael Krufkye7b419b2007-03-26 16:39:20 -0300984 .frontend_attach = m920x_tda10046_08_frontend_attach,
985 .tuner_attach = m920x_tda8275_60_tuner_attach,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300986
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300987 .stream = {
988 .type = USB_BULK,
989 .count = 8,
990 .endpoint = 0x81,
991 .u = {
992 .bulk = {
993 .buffersize = 512,
994 }
995 }
Michael Krufky77eed212011-09-06 09:31:57 -0300996 }},
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300997 }},{
Michael Krufky77eed212011-09-06 09:31:57 -0300998 .num_frontends = 1,
999 .fe = {{
1000
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001001 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1002 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1003
1004 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001005 .pid_filter = m920x_pid_filter,
1006 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001007
Michael Krufkye7b419b2007-03-26 16:39:20 -03001008 .frontend_attach = m920x_tda10046_0b_frontend_attach,
1009 .tuner_attach = m920x_tda8275_61_tuner_attach,
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001010
1011 .stream = {
1012 .type = USB_BULK,
1013 .count = 8,
1014 .endpoint = 0x82,
1015 .u = {
1016 .bulk = {
1017 .buffersize = 512,
1018 }
1019 }
Michael Krufky77eed212011-09-06 09:31:57 -03001020 }},
Nick Andrewaa50ec22007-03-22 17:09:35 -03001021 },
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001022 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001023 .i2c_algo = &m920x_i2c_algo,
Nick Andrewaa50ec22007-03-22 17:09:35 -03001024
1025 .num_device_descs = 1,
1026 .devices = {
1027 { .name = "LifeView TV Walker Twin DVB-T USB2.0",
1028 .cold_ids = { &m920x_table[2], NULL },
1029 .warm_ids = { &m920x_table[3], NULL },
1030 },
1031 }
1032};
1033
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001034static struct dvb_usb_device_properties dposh_properties = {
1035 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1036
1037 .usb_ctrl = DEVICE_SPECIFIC,
1038 .firmware = "dvb-usb-dposh-01.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001039 .download_firmware = m920x_firmware_download,
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001040
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001041 .size_of_priv = sizeof(struct m920x_state),
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001042
1043 .identify_state = m920x_identify_state,
1044 .num_adapters = 1,
1045 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -03001046 .num_frontends = 1,
1047 .fe = {{
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001048 /* Hardware pid filters don't work with this device/firmware */
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001049
Michael Krufkye7b419b2007-03-26 16:39:20 -03001050 .frontend_attach = m920x_mt352_frontend_attach,
1051 .tuner_attach = m920x_qt1010_tuner_attach,
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001052
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001053 .stream = {
1054 .type = USB_BULK,
1055 .count = 8,
1056 .endpoint = 0x81,
1057 .u = {
1058 .bulk = {
1059 .buffersize = 512,
1060 }
1061 }
1062 },
Michael Krufky77eed212011-09-06 09:31:57 -03001063 }},
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001064 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001065 .i2c_algo = &m920x_i2c_algo,
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001066
1067 .num_device_descs = 1,
1068 .devices = {
1069 { .name = "Dposh DVB-T USB2.0",
1070 .cold_ids = { &m920x_table[4], NULL },
1071 .warm_ids = { &m920x_table[5], NULL },
1072 },
1073 }
1074};
1075
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001076static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
1077 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1078
1079 .usb_ctrl = DEVICE_SPECIFIC,
1080 .download_firmware = NULL,
1081
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001082 .rc.legacy = {
1083 .rc_interval = 100,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001084 .rc_map_table = rc_map_pinnacle310e_table,
1085 .rc_map_size = ARRAY_SIZE(rc_map_pinnacle310e_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001086 .rc_query = m920x_rc_query,
1087 },
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001088
1089 .size_of_priv = sizeof(struct m920x_state),
1090
1091 .identify_state = m920x_identify_state,
1092 .num_adapters = 1,
1093 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -03001094 .num_frontends = 1,
1095 .fe = {{
1096
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001097 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1098 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1099
1100 .pid_filter_count = 8,
1101 .pid_filter = m920x_pid_filter,
1102 .pid_filter_ctrl = m920x_pid_filter_ctrl,
1103
1104 .frontend_attach = m920x_mt352_frontend_attach,
1105 .tuner_attach = m920x_fmd1216me_tuner_attach,
1106
1107 .stream = {
1108 .type = USB_ISOC,
1109 .count = 5,
1110 .endpoint = 0x84,
1111 .u = {
1112 .isoc = {
1113 .framesperurb = 128,
1114 .framesize = 564,
1115 .interval = 1,
1116 }
1117 }
1118 },
Michael Krufky77eed212011-09-06 09:31:57 -03001119 }},
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001120 } },
1121 .i2c_algo = &m920x_i2c_algo,
1122
1123 .num_device_descs = 1,
1124 .devices = {
1125 { "Pinnacle PCTV 310e",
1126 { &m920x_table[6], NULL },
1127 { NULL },
1128 }
1129 }
1130};
1131
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001132static struct usb_driver m920x_driver = {
1133 .name = "dvb_usb_m920x",
Michael Krufky2a2bfa72006-09-23 20:13:12 -03001134 .probe = m920x_probe,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001135 .disconnect = dvb_usb_device_exit,
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001136 .id_table = m920x_table,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001137};
1138
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -08001139module_usb_driver(m920x_driver);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001140
1141MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
Nick Andrewaa50ec22007-03-22 17:09:35 -03001142MODULE_DESCRIPTION("DVB Driver for ULI M920x");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001143MODULE_VERSION("0.1");
1144MODULE_LICENSE("GPL");
Michael Krufkyce9c2752007-03-22 17:18:26 -03001145
1146/*
1147 * Local variables:
1148 * c-basic-offset: 8
1149 */