blob: a70c5eaf0600be1d208259e41e2e3a879d9eebd0 [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
Mauro Carvalho Chehab9d5394c2012-12-27 16:32:58 -0200194 ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE,
195 rc_state, 1);
196 if (ret != 0)
Florian Mickler513ea352011-03-21 15:33:45 -0300197 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300198
Mauro Carvalho Chehab9d5394c2012-12-27 16:32:58 -0200199 ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY,
200 rc_state + 1, 1);
201 if (ret != 0)
Florian Mickler513ea352011-03-21 15:33:45 -0300202 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300203
Antonio Ospite7a7ef462012-12-10 17:37:13 -0300204 m920x_parse_rc_state(d, rc_state[0], state);
205
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300206 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
207 if (rc5_data(&d->props.rc.legacy.rc_map_table[i]) == rc_state[1]) {
208 *event = d->props.rc.legacy.rc_map_table[i].keycode;
Antonio Ospitef526e9e2012-12-10 17:37:12 -0300209 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300210 }
211
212 if (rc_state[1] != 0)
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300213 deb("Unknown rc key %02x\n", rc_state[1]);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300214
215 *state = REMOTE_NO_KEY_PRESSED;
216
Florian Mickler513ea352011-03-21 15:33:45 -0300217 out:
218 kfree(rc_state);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300219 return ret;
220}
221
Antonio Ospiteb6777572012-12-10 17:37:14 -0300222static int m920x_rc_core_query(struct dvb_usb_device *d)
223{
224 int ret = 0;
225 u8 *rc_state;
226 int state;
227
228 rc_state = kmalloc(2, GFP_KERNEL);
229 if (!rc_state)
230 return -ENOMEM;
231
232 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, &rc_state[0], 1)) != 0)
233 goto out;
234
235 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, &rc_state[1], 1)) != 0)
236 goto out;
237
238 deb("state=0x%02x keycode=0x%02x\n", rc_state[0], rc_state[1]);
239
240 m920x_parse_rc_state(d, rc_state[0], &state);
241
242 if (state == REMOTE_NO_KEY_PRESSED)
243 rc_keyup(d->rc_dev);
244 else if (state == REMOTE_KEY_REPEAT)
245 rc_repeat(d->rc_dev);
246 else
247 rc_keydown(d->rc_dev, rc_state[1], 0);
248
249out:
250 kfree(rc_state);
251 return ret;
252}
253
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300254/* I2C */
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300255static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300256{
257 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Aapo Tahkola26247012007-03-05 18:23:19 -0300258 int i, j;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300259 int ret = 0;
260
Trent Piephod40860f2007-03-05 23:55:00 -0300261 if (!num)
262 return -EINVAL;
263
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300264 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
265 return -EAGAIN;
266
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300267 for (i = 0; i < num; i++) {
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300268 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 -0300269 /* For a 0 byte message, I think sending the address
270 * to index 0x80|0x40 would be the correct thing to
271 * do. However, zero byte messages are only used for
272 * probing, and since we don't know how to get the
273 * slave's ack, we can't probe. */
Trent Piephod40860f2007-03-05 23:55:00 -0300274 ret = -ENOTSUPP;
275 goto unlock;
276 }
277 /* Send START & address/RW bit */
278 if (!(msg[i].flags & I2C_M_NOSTART)) {
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300279 if ((ret = m920x_write(d->udev, M9206_I2C,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300280 (msg[i].addr << 1) |
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300281 (msg[i].flags & I2C_M_RD ? 0x01 : 0), 0x80)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300282 goto unlock;
283 /* Should check for ack here, if we knew how. */
284 }
Aapo Tahkola26247012007-03-05 18:23:19 -0300285 if (msg[i].flags & I2C_M_RD) {
Trent Piephod40860f2007-03-05 23:55:00 -0300286 for (j = 0; j < msg[i].len; j++) {
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300287 /* Last byte of transaction?
288 * Send STOP, otherwise send ACK. */
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300289 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x01;
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300290
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300291 if ((ret = m920x_read(d->udev, M9206_I2C, 0x0,
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300292 0x20 | stop,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300293 &msg[i].buf[j], 1)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300294 goto unlock;
Aapo Tahkola84ad7572007-01-21 15:57:20 -0300295 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300296 } else {
Trent Piephod40860f2007-03-05 23:55:00 -0300297 for (j = 0; j < msg[i].len; j++) {
298 /* Last byte of transaction? Then send STOP. */
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300299 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x00;
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300300
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300301 if ((ret = m920x_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300302 goto unlock;
303 /* Should check for ack here too. */
Aapo Tahkola26247012007-03-05 18:23:19 -0300304 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300305 }
306 }
Aapo Tahkola26247012007-03-05 18:23:19 -0300307 ret = num;
Trent Piephod40860f2007-03-05 23:55:00 -0300308
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300309 unlock:
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300310 mutex_unlock(&d->i2c_mutex);
311
312 return ret;
313}
314
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300315static u32 m920x_i2c_func(struct i2c_adapter *adapter)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300316{
317 return I2C_FUNC_I2C;
318}
319
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300320static struct i2c_algorithm m920x_i2c_algo = {
321 .master_xfer = m920x_i2c_xfer,
322 .functionality = m920x_i2c_func,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300323};
324
Michael Krufky5afb7072007-03-26 16:35:29 -0300325/* pid filter */
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300326static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300327{
328 int ret = 0;
329
330 if (pid >= 0x8000)
331 return -EINVAL;
332
333 pid |= 0x8000;
334
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300335 if ((ret = m920x_write(d->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300336 return ret;
337
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300338 if ((ret = m920x_write(d->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300339 return ret;
340
341 return ret;
342}
343
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300344static int m920x_update_filters(struct dvb_usb_adapter *adap)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300345{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300346 struct m920x_state *m = adap->dev->priv;
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300347 int enabled = m->filtering_enabled[adap->id];
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300348 int i, ret = 0, filter = 0;
Michael Krufky77eed212011-09-06 09:31:57 -0300349 int ep = adap->props.fe[0].stream.endpoint;
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300350
351 for (i = 0; i < M9206_MAX_FILTERS; i++)
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300352 if (m->filters[adap->id][i] == 8192)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300353 enabled = 0;
354
355 /* Disable all filters */
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300356 if ((ret = m920x_set_filter(adap->dev, ep, 1, enabled)) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300357 return ret;
358
359 for (i = 0; i < M9206_MAX_FILTERS; i++)
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300360 if ((ret = m920x_set_filter(adap->dev, ep, i + 2, 0)) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300361 return ret;
362
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300363 /* Set */
364 if (enabled) {
365 for (i = 0; i < M9206_MAX_FILTERS; i++) {
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300366 if (m->filters[adap->id][i] == 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300367 continue;
368
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300369 if ((ret = m920x_set_filter(adap->dev, ep, filter + 2, m->filters[adap->id][i])) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300370 return ret;
371
372 filter++;
373 }
374 }
375
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300376 return ret;
377}
378
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300379static int m920x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300380{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300381 struct m920x_state *m = adap->dev->priv;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300382
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300383 m->filtering_enabled[adap->id] = onoff ? 1 : 0;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300384
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300385 return m920x_update_filters(adap);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300386}
387
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300388static int m920x_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300389{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300390 struct m920x_state *m = adap->dev->priv;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300391
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300392 m->filters[adap->id][index] = onoff ? pid : 0;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300393
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300394 return m920x_update_filters(adap);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300395}
396
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300397static int m920x_firmware_download(struct usb_device *udev, const struct firmware *fw)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300398{
399 u16 value, index, size;
Florian Mickler513ea352011-03-21 15:33:45 -0300400 u8 *read, *buff;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300401 int i, pass, ret = 0;
402
403 buff = kmalloc(65536, GFP_KERNEL);
Roel Kluin1601fb12009-09-18 20:09:52 -0300404 if (buff == NULL)
405 return -ENOMEM;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300406
Florian Mickler513ea352011-03-21 15:33:45 -0300407 read = kmalloc(4, GFP_KERNEL);
408 if (!read) {
409 kfree(buff);
410 return -ENOMEM;
411 }
412
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300413 if ((ret = m920x_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300414 goto done;
Andy Shevchenko5bdb7872012-09-26 09:55:14 -0300415 deb("%*ph\n", 4, read);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300416
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300417 if ((ret = m920x_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300418 goto done;
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300419 deb("%x\n", read[0]);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300420
421 for (pass = 0; pass < 2; pass++) {
422 for (i = 0; i + (sizeof(u16) * 3) < fw->size;) {
Al Virofa9c13a2008-05-21 00:32:41 -0300423 value = get_unaligned_le16(fw->data + i);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300424 i += sizeof(u16);
425
Al Virofa9c13a2008-05-21 00:32:41 -0300426 index = get_unaligned_le16(fw->data + i);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300427 i += sizeof(u16);
428
Al Virofa9c13a2008-05-21 00:32:41 -0300429 size = get_unaligned_le16(fw->data + i);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300430 i += sizeof(u16);
431
432 if (pass == 1) {
433 /* Will stall if using fw->data ... */
434 memcpy(buff, fw->data + i, size);
435
436 ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0),
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300437 M9206_FW,
438 USB_TYPE_VENDOR | USB_DIR_OUT,
439 value, index, buff, size, 20);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300440 if (ret != size) {
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300441 deb("error while uploading fw!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300442 ret = -EIO;
443 goto done;
444 }
445 msleep(3);
446 }
447 i += size;
448 }
449 if (i != fw->size) {
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300450 deb("bad firmware file!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300451 ret = -EINVAL;
452 goto done;
453 }
454 }
455
456 msleep(36);
457
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300458 /* m920x will disconnect itself from the bus after this. */
459 (void) m920x_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300460 deb("firmware uploaded!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300461
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300462 done:
Florian Mickler513ea352011-03-21 15:33:45 -0300463 kfree(read);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300464 kfree(buff);
465
466 return ret;
467}
468
Michael Krufkye16c1f52007-01-23 15:00:42 -0300469/* Callbacks for DVB USB */
Aapo Tahkola7d1d4e62007-03-15 13:01:46 -0300470static int m920x_identify_state(struct usb_device *udev,
471 struct dvb_usb_device_properties *props,
472 struct dvb_usb_device_description **desc,
473 int *cold)
Michael Krufkye16c1f52007-01-23 15:00:42 -0300474{
475 struct usb_host_interface *alt;
476
477 alt = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 1);
478 *cold = (alt == NULL) ? 1 : 0;
479
480 return 0;
481}
482
Michael Krufky5afb7072007-03-26 16:35:29 -0300483/* demod configurations */
Michael Krufkye7b419b2007-03-26 16:39:20 -0300484static int m920x_mt352_demod_init(struct dvb_frontend *fe)
Michael Krufkye16c1f52007-01-23 15:00:42 -0300485{
Aapo Tahkolad577ee02007-05-08 18:33:52 -0300486 int ret;
Michael Krufkye16c1f52007-01-23 15:00:42 -0300487 u8 config[] = { CONFIG, 0x3d };
488 u8 clock[] = { CLOCK_CTL, 0x30 };
489 u8 reset[] = { RESET, 0x80 };
490 u8 adc_ctl[] = { ADC_CTL_1, 0x40 };
491 u8 agc[] = { AGC_TARGET, 0x1c, 0x20 };
492 u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 };
493 u8 unk1[] = { 0x93, 0x1a };
494 u8 unk2[] = { 0xb5, 0x7a };
495
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300496 deb("Demod init!\n");
Michael Krufkye16c1f52007-01-23 15:00:42 -0300497
Aapo Tahkolad577ee02007-05-08 18:33:52 -0300498 if ((ret = mt352_write(fe, config, ARRAY_SIZE(config))) != 0)
499 return ret;
500 if ((ret = mt352_write(fe, clock, ARRAY_SIZE(clock))) != 0)
501 return ret;
502 if ((ret = mt352_write(fe, reset, ARRAY_SIZE(reset))) != 0)
503 return ret;
504 if ((ret = mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl))) != 0)
505 return ret;
506 if ((ret = mt352_write(fe, agc, ARRAY_SIZE(agc))) != 0)
507 return ret;
508 if ((ret = mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc))) != 0)
509 return ret;
510 if ((ret = mt352_write(fe, unk1, ARRAY_SIZE(unk1))) != 0)
511 return ret;
512 if ((ret = mt352_write(fe, unk2, ARRAY_SIZE(unk2))) != 0)
513 return ret;
514
Michael Krufkye16c1f52007-01-23 15:00:42 -0300515 return 0;
516}
517
Michael Krufkye7b419b2007-03-26 16:39:20 -0300518static struct mt352_config m920x_mt352_config = {
Aapo Tahkola26247012007-03-05 18:23:19 -0300519 .demod_address = 0x0f,
Michael Krufkye16c1f52007-01-23 15:00:42 -0300520 .no_tuner = 1,
Michael Krufkye7b419b2007-03-26 16:39:20 -0300521 .demod_init = m920x_mt352_demod_init,
Michael Krufkye16c1f52007-01-23 15:00:42 -0300522};
523
Michael Krufkye7b419b2007-03-26 16:39:20 -0300524static struct tda1004x_config m920x_tda10046_08_config = {
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300525 .demod_address = 0x08,
526 .invert = 0,
527 .invert_oclk = 0,
528 .ts_mode = TDA10046_TS_SERIAL,
529 .xtal_freq = TDA10046_XTAL_16M,
530 .if_freq = TDA10046_FREQ_045,
531 .agc_config = TDA10046_AGC_TDA827X,
532 .gpio_config = TDA10046_GPTRI,
533 .request_firmware = NULL,
534};
535
Michael Krufkye7b419b2007-03-26 16:39:20 -0300536static struct tda1004x_config m920x_tda10046_0b_config = {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300537 .demod_address = 0x0b,
538 .invert = 0,
539 .invert_oclk = 0,
540 .ts_mode = TDA10046_TS_SERIAL,
541 .xtal_freq = TDA10046_XTAL_16M,
542 .if_freq = TDA10046_FREQ_045,
543 .agc_config = TDA10046_AGC_TDA827X,
544 .gpio_config = TDA10046_GPTRI,
545 .request_firmware = NULL, /* uses firmware EEPROM */
546};
547
Michael Krufky5afb7072007-03-26 16:35:29 -0300548/* tuner configurations */
Michael Krufkye7b419b2007-03-26 16:39:20 -0300549static struct qt1010_config m920x_qt1010_config = {
Michael Krufky5afb7072007-03-26 16:35:29 -0300550 .i2c_address = 0x62
551};
552
553/* Callbacks for DVB USB */
Michael Krufkye7b419b2007-03-26 16:39:20 -0300554static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300555{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300556 deb("%s\n",__func__);
Michael Krufky5afb7072007-03-26 16:35:29 -0300557
Michael Krufkyd12f51a2011-09-17 14:59:54 -0300558 adap->fe_adap[0].fe = dvb_attach(mt352_attach,
559 &m920x_mt352_config,
560 &adap->dev->i2c_adap);
561 if ((adap->fe_adap[0].fe) == NULL)
Michael Krufky5afb7072007-03-26 16:35:29 -0300562 return -EIO;
563
564 return 0;
565}
566
Michael Krufkye7b419b2007-03-26 16:39:20 -0300567static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300568{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300569 deb("%s\n",__func__);
Nick Andrewaa50ec22007-03-22 17:09:35 -0300570
Michael Krufkyd12f51a2011-09-17 14:59:54 -0300571 adap->fe_adap[0].fe = dvb_attach(tda10046_attach,
572 &m920x_tda10046_08_config,
573 &adap->dev->i2c_adap);
574 if ((adap->fe_adap[0].fe) == NULL)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300575 return -EIO;
576
Nick Andrewaa50ec22007-03-22 17:09:35 -0300577 return 0;
578}
579
Michael Krufkye7b419b2007-03-26 16:39:20 -0300580static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300581{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300582 deb("%s\n",__func__);
Nick Andrewaa50ec22007-03-22 17:09:35 -0300583
Michael Krufkyd12f51a2011-09-17 14:59:54 -0300584 adap->fe_adap[0].fe = dvb_attach(tda10046_attach,
585 &m920x_tda10046_0b_config,
586 &adap->dev->i2c_adap);
587 if ((adap->fe_adap[0].fe) == NULL)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300588 return -EIO;
589
Nick Andrewaa50ec22007-03-22 17:09:35 -0300590 return 0;
591}
592
Michael Krufkye7b419b2007-03-26 16:39:20 -0300593static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300594{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300595 deb("%s\n",__func__);
Michael Krufkye7b419b2007-03-26 16:39:20 -0300596
Michael Krufky77eed212011-09-06 09:31:57 -0300597 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 -0300598 return -ENODEV;
599
600 return 0;
601}
602
Michael Krufkye7b419b2007-03-26 16:39:20 -0300603static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300604{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300605 deb("%s\n",__func__);
Michael Krufkye7b419b2007-03-26 16:39:20 -0300606
Michael Krufky77eed212011-09-06 09:31:57 -0300607 if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL)
Michael Krufky5afb7072007-03-26 16:35:29 -0300608 return -ENODEV;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300609
610 return 0;
611}
612
Michael Krufkye7b419b2007-03-26 16:39:20 -0300613static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300614{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300615 deb("%s\n",__func__);
Nick Andrewaa50ec22007-03-22 17:09:35 -0300616
Michael Krufky77eed212011-09-06 09:31:57 -0300617 if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300618 return -ENODEV;
619
Nick Andrewaa50ec22007-03-22 17:09:35 -0300620 return 0;
621}
622
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300623static int m920x_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
624{
Michael Krufky77eed212011-09-06 09:31:57 -0300625 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300626 &adap->dev->i2c_adap, 0x61,
627 TUNER_PHILIPS_FMD1216ME_MK3);
628 return 0;
629}
630
Michael Krufky5afb7072007-03-26 16:35:29 -0300631/* device-specific initialization */
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300632static struct m920x_inits megasky_rc_init [] = {
Michael Krufky5afb7072007-03-26 16:35:29 -0300633 { M9206_RC_INIT2, 0xa8 },
634 { M9206_RC_INIT1, 0x51 },
635 { } /* terminating entry */
636};
637
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300638static struct m920x_inits tvwalkertwin_rc_init [] = {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300639 { M9206_RC_INIT2, 0x00 },
640 { M9206_RC_INIT1, 0xef },
641 { 0xff28, 0x00 },
642 { 0xff23, 0x00 },
643 { 0xff21, 0x30 },
644 { } /* terminating entry */
645};
646
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300647static struct m920x_inits pinnacle310e_init[] = {
Antonio Ospite90849832012-12-10 17:37:10 -0300648 /* without these the tuner doesn't work */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300649 { 0xff20, 0x9b },
650 { 0xff22, 0x70 },
651
652 /* rc settings */
653 { 0xff50, 0x80 },
654 { M9206_RC_INIT1, 0x00 },
655 { M9206_RC_INIT2, 0xff },
656 { } /* terminating entry */
657};
658
Michael Krufky5afb7072007-03-26 16:35:29 -0300659/* ir keymaps */
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300660static struct rc_map_table rc_map_megasky_table[] = {
Mauro Carvalho Chehab2e365882009-08-29 15:19:31 -0300661 { 0x0012, KEY_POWER },
662 { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */
663 { 0x0002, KEY_CHANNELUP },
664 { 0x0005, KEY_CHANNELDOWN },
665 { 0x0003, KEY_VOLUMEUP },
666 { 0x0006, KEY_VOLUMEDOWN },
667 { 0x0004, KEY_MUTE },
668 { 0x0007, KEY_OK }, /* TS */
669 { 0x0008, KEY_STOP },
670 { 0x0009, KEY_MENU }, /* swap */
671 { 0x000a, KEY_REWIND },
672 { 0x001b, KEY_PAUSE },
673 { 0x001f, KEY_FASTFORWARD },
674 { 0x000c, KEY_RECORD },
675 { 0x000d, KEY_CAMERA }, /* screenshot */
676 { 0x000e, KEY_COFFEE }, /* "MTS" */
Michael Krufky5afb7072007-03-26 16:35:29 -0300677};
678
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300679static struct rc_map_table rc_map_tvwalkertwin_table[] = {
Mauro Carvalho Chehab2e365882009-08-29 15:19:31 -0300680 { 0x0001, KEY_ZOOM }, /* Full Screen */
681 { 0x0002, KEY_CAMERA }, /* snapshot */
682 { 0x0003, KEY_MUTE },
683 { 0x0004, KEY_REWIND },
684 { 0x0005, KEY_PLAYPAUSE }, /* Play/Pause */
685 { 0x0006, KEY_FASTFORWARD },
686 { 0x0007, KEY_RECORD },
687 { 0x0008, KEY_STOP },
688 { 0x0009, KEY_TIME }, /* Timeshift */
689 { 0x000c, KEY_COFFEE }, /* Recall */
690 { 0x000e, KEY_CHANNELUP },
691 { 0x0012, KEY_POWER },
692 { 0x0015, KEY_MENU }, /* source */
693 { 0x0018, KEY_CYCLEWINDOWS }, /* TWIN PIP */
694 { 0x001a, KEY_CHANNELDOWN },
695 { 0x001b, KEY_VOLUMEDOWN },
696 { 0x001e, KEY_VOLUMEUP },
Michael Krufky5afb7072007-03-26 16:35:29 -0300697};
698
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300699static struct rc_map_table rc_map_pinnacle310e_table[] = {
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300700 { 0x16, KEY_POWER },
701 { 0x17, KEY_FAVORITES },
702 { 0x0f, KEY_TEXT },
Jarod Wilson56c08932011-04-05 18:42:30 -0300703 { 0x48, KEY_PROGRAM }, /* preview */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300704 { 0x1c, KEY_EPG },
Jarod Wilson56c08932011-04-05 18:42:30 -0300705 { 0x04, KEY_LIST }, /* record list */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300706 { 0x03, KEY_1 },
707 { 0x01, KEY_2 },
708 { 0x06, KEY_3 },
709 { 0x09, KEY_4 },
710 { 0x1d, KEY_5 },
711 { 0x1f, KEY_6 },
712 { 0x0d, KEY_7 },
713 { 0x19, KEY_8 },
714 { 0x1b, KEY_9 },
715 { 0x15, KEY_0 },
716 { 0x0c, KEY_CANCEL },
717 { 0x4a, KEY_CLEAR },
718 { 0x13, KEY_BACK },
719 { 0x00, KEY_TAB },
720 { 0x4b, KEY_UP },
721 { 0x4e, KEY_LEFT },
722 { 0x52, KEY_RIGHT },
723 { 0x51, KEY_DOWN },
724 { 0x4f, KEY_ENTER }, /* could also be KEY_OK */
725 { 0x1e, KEY_VOLUMEUP },
726 { 0x0a, KEY_VOLUMEDOWN },
727 { 0x05, KEY_CHANNELUP },
728 { 0x02, KEY_CHANNELDOWN },
729 { 0x11, KEY_RECORD },
730 { 0x14, KEY_PLAY },
731 { 0x4c, KEY_PAUSE },
732 { 0x1a, KEY_STOP },
733 { 0x40, KEY_REWIND },
734 { 0x12, KEY_FASTFORWARD },
735 { 0x41, KEY_PREVIOUSSONG }, /* Replay */
736 { 0x42, KEY_NEXTSONG }, /* Skip */
737 { 0x54, KEY_CAMERA }, /* Capture */
738/* { 0x50, KEY_SAP }, */ /* Sap */
739 { 0x47, KEY_CYCLEWINDOWS }, /* Pip */
740 { 0x4d, KEY_SCREEN }, /* FullScreen */
741 { 0x08, KEY_SUBTITLE },
742 { 0x0e, KEY_MUTE },
743/* { 0x49, KEY_LR }, */ /* L/R */
744 { 0x07, KEY_SLEEP }, /* Hibernate */
Jarod Wilson56c08932011-04-05 18:42:30 -0300745 { 0x08, KEY_VIDEO }, /* A/V */
746 { 0x0e, KEY_MENU }, /* Recall */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300747 { 0x45, KEY_ZOOMIN },
748 { 0x46, KEY_ZOOMOUT },
Jarod Wilson56c08932011-04-05 18:42:30 -0300749 { 0x18, KEY_RED }, /* Red */
750 { 0x53, KEY_GREEN }, /* Green */
751 { 0x5e, KEY_YELLOW }, /* Yellow */
752 { 0x5f, KEY_BLUE }, /* Blue */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300753};
754
Michael Krufky26f48ea2006-09-28 01:46:49 -0300755/* DVB USB Driver stuff */
756static struct dvb_usb_device_properties megasky_properties;
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300757static struct dvb_usb_device_properties digivox_mini_ii_properties;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300758static struct dvb_usb_device_properties tvwalkertwin_properties;
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300759static struct dvb_usb_device_properties dposh_properties;
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300760static struct dvb_usb_device_properties pinnacle_pctv310e_properties;
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300761
Michael Krufkyfa948052007-01-21 15:57:48 -0300762static int m920x_probe(struct usb_interface *intf,
763 const struct usb_device_id *id)
Michael Krufky26f48ea2006-09-28 01:46:49 -0300764{
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300765 struct dvb_usb_device *d = NULL;
Michael Krufky26f48ea2006-09-28 01:46:49 -0300766 int ret;
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300767 struct m920x_inits *rc_init_seq = NULL;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300768 int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
Michael Krufky26f48ea2006-09-28 01:46:49 -0300769
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300770 deb("Probing for m920x device at interface %d\n", bInterfaceNumber);
Michael Krufky26f48ea2006-09-28 01:46:49 -0300771
Nick Andrewaa50ec22007-03-22 17:09:35 -0300772 if (bInterfaceNumber == 0) {
773 /* Single-tuner device, or first interface on
774 * multi-tuner device
775 */
Michael Krufky26f48ea2006-09-28 01:46:49 -0300776
Janne Grunau78e92002008-04-09 19:13:13 -0300777 ret = dvb_usb_device_init(intf, &megasky_properties,
778 THIS_MODULE, &d, adapter_nr);
779 if (ret == 0) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300780 rc_init_seq = megasky_rc_init;
781 goto found;
782 }
783
Janne Grunau78e92002008-04-09 19:13:13 -0300784 ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties,
785 THIS_MODULE, &d, adapter_nr);
786 if (ret == 0) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300787 /* No remote control, so no rc_init_seq */
788 goto found;
789 }
790
791 /* This configures both tuners on the TV Walker Twin */
Janne Grunau78e92002008-04-09 19:13:13 -0300792 ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
793 THIS_MODULE, &d, adapter_nr);
794 if (ret == 0) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300795 rc_init_seq = tvwalkertwin_rc_init;
796 goto found;
797 }
798
Janne Grunau78e92002008-04-09 19:13:13 -0300799 ret = dvb_usb_device_init(intf, &dposh_properties,
800 THIS_MODULE, &d, adapter_nr);
801 if (ret == 0) {
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300802 /* Remote controller not supported yet. */
803 goto found;
804 }
805
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300806 ret = dvb_usb_device_init(intf, &pinnacle_pctv310e_properties,
807 THIS_MODULE, &d, adapter_nr);
808 if (ret == 0) {
809 rc_init_seq = pinnacle310e_init;
810 goto found;
811 }
812
Nick Andrewaa50ec22007-03-22 17:09:35 -0300813 return ret;
814 } else {
815 /* Another interface on a multi-tuner device */
816
817 /* The LifeView TV Walker Twin gets here, but struct
818 * tvwalkertwin_properties already configured both
819 * tuners, so there is nothing for us to do here
820 */
Nick Andrewaa50ec22007-03-22 17:09:35 -0300821 }
Michael Krufky26f48ea2006-09-28 01:46:49 -0300822
Michael Krufkye7b419b2007-03-26 16:39:20 -0300823 found:
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300824 if ((ret = m920x_init_ep(intf)) < 0)
Aapo Tahkola480ac762007-03-05 18:54:27 -0300825 return ret;
826
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300827 if (d && (ret = m920x_init(d, rc_init_seq)) != 0)
Aapo Tahkola480ac762007-03-05 18:54:27 -0300828 return ret;
829
Michael Krufky26f48ea2006-09-28 01:46:49 -0300830 return ret;
831}
832
833static struct usb_device_id m920x_table [] = {
834 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300835 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
836 USB_PID_MSI_DIGI_VOX_MINI_II) },
Nick Andrewaa50ec22007-03-22 17:09:35 -0300837 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
838 USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD) },
839 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
840 USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) },
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300841 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
842 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300843 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_PINNACLE_PCTV310E) },
Michael Krufky26f48ea2006-09-28 01:46:49 -0300844 { } /* Terminating entry */
845};
846MODULE_DEVICE_TABLE (usb, m920x_table);
847
Michael Krufky01cb34d2006-09-23 20:01:29 -0300848static struct dvb_usb_device_properties megasky_properties = {
Michael Krufky758117c2007-01-23 15:34:10 -0300849 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
Michael Krufky1f61f3b2006-10-07 15:03:04 -0300850
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300851 .usb_ctrl = DEVICE_SPECIFIC,
852 .firmware = "dvb-usb-megasky-02.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300853 .download_firmware = m920x_firmware_download,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300854
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300855 .rc.legacy = {
856 .rc_interval = 100,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300857 .rc_map_table = rc_map_megasky_table,
858 .rc_map_size = ARRAY_SIZE(rc_map_megasky_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300859 .rc_query = m920x_rc_query,
860 },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300861
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300862 .size_of_priv = sizeof(struct m920x_state),
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300863
Aapo Tahkola7d1d4e62007-03-15 13:01:46 -0300864 .identify_state = m920x_identify_state,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300865 .num_adapters = 1,
866 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -0300867 .num_frontends = 1,
868 .fe = {{
869
Michael Krufky758117c2007-01-23 15:34:10 -0300870 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
871 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
872
Michael Krufky01cb34d2006-09-23 20:01:29 -0300873 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300874 .pid_filter = m920x_pid_filter,
875 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300876
Michael Krufkye7b419b2007-03-26 16:39:20 -0300877 .frontend_attach = m920x_mt352_frontend_attach,
878 .tuner_attach = m920x_qt1010_tuner_attach,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300879
880 .stream = {
881 .type = USB_BULK,
882 .count = 8,
883 .endpoint = 0x81,
884 .u = {
885 .bulk = {
886 .buffersize = 512,
887 }
888 }
889 },
Michael Krufky77eed212011-09-06 09:31:57 -0300890 }},
Michael Krufky01cb34d2006-09-23 20:01:29 -0300891 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300892 .i2c_algo = &m920x_i2c_algo,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300893
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300894 .num_device_descs = 1,
895 .devices = {
896 { "MSI Mega Sky 580 DVB-T USB2.0",
Michael Krufkybaa2ed02006-09-23 20:01:29 -0300897 { &m920x_table[0], NULL },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300898 { NULL },
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300899 }
900 }
901};
902
903static struct dvb_usb_device_properties digivox_mini_ii_properties = {
904 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
905
906 .usb_ctrl = DEVICE_SPECIFIC,
907 .firmware = "dvb-usb-digivox-02.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300908 .download_firmware = m920x_firmware_download,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300909
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300910 .size_of_priv = sizeof(struct m920x_state),
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300911
912 .identify_state = m920x_identify_state,
913 .num_adapters = 1,
914 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -0300915 .num_frontends = 1,
916 .fe = {{
917
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300918 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300919 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300920
921 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300922 .pid_filter = m920x_pid_filter,
923 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300924
Michael Krufkye7b419b2007-03-26 16:39:20 -0300925 .frontend_attach = m920x_tda10046_08_frontend_attach,
926 .tuner_attach = m920x_tda8275_60_tuner_attach,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300927
928 .stream = {
929 .type = USB_BULK,
930 .count = 8,
931 .endpoint = 0x81,
932 .u = {
933 .bulk = {
934 .buffersize = 0x4000,
935 }
936 }
937 },
Michael Krufky77eed212011-09-06 09:31:57 -0300938 }},
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300939 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300940 .i2c_algo = &m920x_i2c_algo,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300941
942 .num_device_descs = 1,
943 .devices = {
944 { "MSI DIGI VOX mini II DVB-T USB2.0",
945 { &m920x_table[1], NULL },
946 { NULL },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300947 },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300948 }
949};
950
Michael Krufkye7b419b2007-03-26 16:39:20 -0300951/* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net>
952 *
953 * LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A
954 * TDA10046 #0 is located at i2c address 0x08
Aapo Tahkola3ab3b692007-05-08 18:23:38 -0300955 * TDA10046 #1 is located at i2c address 0x0b
Michael Krufkye7b419b2007-03-26 16:39:20 -0300956 * TDA8275A #0 is located at i2c address 0x60
Aapo Tahkola3ab3b692007-05-08 18:23:38 -0300957 * TDA8275A #1 is located at i2c address 0x61
Michael Krufkye7b419b2007-03-26 16:39:20 -0300958 */
Nick Andrewaa50ec22007-03-22 17:09:35 -0300959static struct dvb_usb_device_properties tvwalkertwin_properties = {
960 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
961
962 .usb_ctrl = DEVICE_SPECIFIC,
963 .firmware = "dvb-usb-tvwalkert.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300964 .download_firmware = m920x_firmware_download,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300965
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300966 .rc.legacy = {
967 .rc_interval = 100,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300968 .rc_map_table = rc_map_tvwalkertwin_table,
969 .rc_map_size = ARRAY_SIZE(rc_map_tvwalkertwin_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300970 .rc_query = m920x_rc_query,
971 },
Nick Andrewaa50ec22007-03-22 17:09:35 -0300972
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300973 .size_of_priv = sizeof(struct m920x_state),
Nick Andrewaa50ec22007-03-22 17:09:35 -0300974
975 .identify_state = m920x_identify_state,
Aapo Tahkola3ab3b692007-05-08 18:23:38 -0300976 .num_adapters = 2,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300977 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -0300978 .num_frontends = 1,
979 .fe = {{
980
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300981 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
982 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300983
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300984 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300985 .pid_filter = m920x_pid_filter,
986 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300987
Michael Krufkye7b419b2007-03-26 16:39:20 -0300988 .frontend_attach = m920x_tda10046_08_frontend_attach,
989 .tuner_attach = m920x_tda8275_60_tuner_attach,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300990
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300991 .stream = {
992 .type = USB_BULK,
993 .count = 8,
994 .endpoint = 0x81,
995 .u = {
996 .bulk = {
997 .buffersize = 512,
998 }
999 }
Michael Krufky77eed212011-09-06 09:31:57 -03001000 }},
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001001 }},{
Michael Krufky77eed212011-09-06 09:31:57 -03001002 .num_frontends = 1,
1003 .fe = {{
1004
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001005 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1006 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1007
1008 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001009 .pid_filter = m920x_pid_filter,
1010 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001011
Michael Krufkye7b419b2007-03-26 16:39:20 -03001012 .frontend_attach = m920x_tda10046_0b_frontend_attach,
1013 .tuner_attach = m920x_tda8275_61_tuner_attach,
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001014
1015 .stream = {
1016 .type = USB_BULK,
1017 .count = 8,
1018 .endpoint = 0x82,
1019 .u = {
1020 .bulk = {
1021 .buffersize = 512,
1022 }
1023 }
Michael Krufky77eed212011-09-06 09:31:57 -03001024 }},
Nick Andrewaa50ec22007-03-22 17:09:35 -03001025 },
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001026 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001027 .i2c_algo = &m920x_i2c_algo,
Nick Andrewaa50ec22007-03-22 17:09:35 -03001028
1029 .num_device_descs = 1,
1030 .devices = {
1031 { .name = "LifeView TV Walker Twin DVB-T USB2.0",
1032 .cold_ids = { &m920x_table[2], NULL },
1033 .warm_ids = { &m920x_table[3], NULL },
1034 },
1035 }
1036};
1037
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001038static struct dvb_usb_device_properties dposh_properties = {
1039 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1040
1041 .usb_ctrl = DEVICE_SPECIFIC,
1042 .firmware = "dvb-usb-dposh-01.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001043 .download_firmware = m920x_firmware_download,
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001044
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001045 .size_of_priv = sizeof(struct m920x_state),
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001046
1047 .identify_state = m920x_identify_state,
1048 .num_adapters = 1,
1049 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -03001050 .num_frontends = 1,
1051 .fe = {{
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001052 /* Hardware pid filters don't work with this device/firmware */
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001053
Michael Krufkye7b419b2007-03-26 16:39:20 -03001054 .frontend_attach = m920x_mt352_frontend_attach,
1055 .tuner_attach = m920x_qt1010_tuner_attach,
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001056
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001057 .stream = {
1058 .type = USB_BULK,
1059 .count = 8,
1060 .endpoint = 0x81,
1061 .u = {
1062 .bulk = {
1063 .buffersize = 512,
1064 }
1065 }
1066 },
Michael Krufky77eed212011-09-06 09:31:57 -03001067 }},
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001068 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001069 .i2c_algo = &m920x_i2c_algo,
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001070
1071 .num_device_descs = 1,
1072 .devices = {
1073 { .name = "Dposh DVB-T USB2.0",
1074 .cold_ids = { &m920x_table[4], NULL },
1075 .warm_ids = { &m920x_table[5], NULL },
1076 },
1077 }
1078};
1079
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001080static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
1081 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1082
1083 .usb_ctrl = DEVICE_SPECIFIC,
1084 .download_firmware = NULL,
1085
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001086 .rc.legacy = {
1087 .rc_interval = 100,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001088 .rc_map_table = rc_map_pinnacle310e_table,
1089 .rc_map_size = ARRAY_SIZE(rc_map_pinnacle310e_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001090 .rc_query = m920x_rc_query,
1091 },
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001092
1093 .size_of_priv = sizeof(struct m920x_state),
1094
1095 .identify_state = m920x_identify_state,
1096 .num_adapters = 1,
1097 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -03001098 .num_frontends = 1,
1099 .fe = {{
1100
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001101 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1102 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1103
1104 .pid_filter_count = 8,
1105 .pid_filter = m920x_pid_filter,
1106 .pid_filter_ctrl = m920x_pid_filter_ctrl,
1107
1108 .frontend_attach = m920x_mt352_frontend_attach,
1109 .tuner_attach = m920x_fmd1216me_tuner_attach,
1110
1111 .stream = {
1112 .type = USB_ISOC,
1113 .count = 5,
1114 .endpoint = 0x84,
1115 .u = {
1116 .isoc = {
1117 .framesperurb = 128,
1118 .framesize = 564,
1119 .interval = 1,
1120 }
1121 }
1122 },
Michael Krufky77eed212011-09-06 09:31:57 -03001123 }},
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001124 } },
1125 .i2c_algo = &m920x_i2c_algo,
1126
1127 .num_device_descs = 1,
1128 .devices = {
1129 { "Pinnacle PCTV 310e",
1130 { &m920x_table[6], NULL },
1131 { NULL },
1132 }
1133 }
1134};
1135
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001136static struct usb_driver m920x_driver = {
1137 .name = "dvb_usb_m920x",
Michael Krufky2a2bfa72006-09-23 20:13:12 -03001138 .probe = m920x_probe,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001139 .disconnect = dvb_usb_device_exit,
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001140 .id_table = m920x_table,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001141};
1142
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -08001143module_usb_driver(m920x_driver);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001144
1145MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
Nick Andrewaa50ec22007-03-22 17:09:35 -03001146MODULE_DESCRIPTION("DVB Driver for ULI M920x");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001147MODULE_VERSION("0.1");
1148MODULE_LICENSE("GPL");
Michael Krufkyce9c2752007-03-22 17:18:26 -03001149
1150/*
1151 * Local variables:
1152 * c-basic-offset: 8
1153 */