blob: 581c5deffb6e54355a1e9f2b3ae9867697e357ea [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
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300200 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
201 if (rc5_data(&d->props.rc.legacy.rc_map_table[i]) == rc_state[1]) {
202 *event = d->props.rc.legacy.rc_map_table[i].keycode;
Antonio Ospitef526e9e2012-12-10 17:37:12 -0300203 m920x_parse_rc_state(d, rc_state[0], state);
204 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300205 }
206
207 if (rc_state[1] != 0)
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300208 deb("Unknown rc key %02x\n", rc_state[1]);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300209
210 *state = REMOTE_NO_KEY_PRESSED;
211
Florian Mickler513ea352011-03-21 15:33:45 -0300212 out:
213 kfree(rc_state);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300214 return ret;
215}
216
217/* I2C */
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300218static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300219{
220 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Aapo Tahkola26247012007-03-05 18:23:19 -0300221 int i, j;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300222 int ret = 0;
223
Trent Piephod40860f2007-03-05 23:55:00 -0300224 if (!num)
225 return -EINVAL;
226
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300227 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
228 return -EAGAIN;
229
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300230 for (i = 0; i < num; i++) {
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300231 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 -0300232 /* For a 0 byte message, I think sending the address
233 * to index 0x80|0x40 would be the correct thing to
234 * do. However, zero byte messages are only used for
235 * probing, and since we don't know how to get the
236 * slave's ack, we can't probe. */
Trent Piephod40860f2007-03-05 23:55:00 -0300237 ret = -ENOTSUPP;
238 goto unlock;
239 }
240 /* Send START & address/RW bit */
241 if (!(msg[i].flags & I2C_M_NOSTART)) {
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300242 if ((ret = m920x_write(d->udev, M9206_I2C,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300243 (msg[i].addr << 1) |
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300244 (msg[i].flags & I2C_M_RD ? 0x01 : 0), 0x80)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300245 goto unlock;
246 /* Should check for ack here, if we knew how. */
247 }
Aapo Tahkola26247012007-03-05 18:23:19 -0300248 if (msg[i].flags & I2C_M_RD) {
Trent Piephod40860f2007-03-05 23:55:00 -0300249 for (j = 0; j < msg[i].len; j++) {
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300250 /* Last byte of transaction?
251 * Send STOP, otherwise send ACK. */
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300252 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x01;
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300253
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300254 if ((ret = m920x_read(d->udev, M9206_I2C, 0x0,
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300255 0x20 | stop,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300256 &msg[i].buf[j], 1)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300257 goto unlock;
Aapo Tahkola84ad7572007-01-21 15:57:20 -0300258 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300259 } else {
Trent Piephod40860f2007-03-05 23:55:00 -0300260 for (j = 0; j < msg[i].len; j++) {
261 /* Last byte of transaction? Then send STOP. */
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300262 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x00;
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300263
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300264 if ((ret = m920x_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300265 goto unlock;
266 /* Should check for ack here too. */
Aapo Tahkola26247012007-03-05 18:23:19 -0300267 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300268 }
269 }
Aapo Tahkola26247012007-03-05 18:23:19 -0300270 ret = num;
Trent Piephod40860f2007-03-05 23:55:00 -0300271
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300272 unlock:
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300273 mutex_unlock(&d->i2c_mutex);
274
275 return ret;
276}
277
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300278static u32 m920x_i2c_func(struct i2c_adapter *adapter)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300279{
280 return I2C_FUNC_I2C;
281}
282
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300283static struct i2c_algorithm m920x_i2c_algo = {
284 .master_xfer = m920x_i2c_xfer,
285 .functionality = m920x_i2c_func,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300286};
287
Michael Krufky5afb7072007-03-26 16:35:29 -0300288/* pid filter */
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300289static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300290{
291 int ret = 0;
292
293 if (pid >= 0x8000)
294 return -EINVAL;
295
296 pid |= 0x8000;
297
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300298 if ((ret = m920x_write(d->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300299 return ret;
300
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300301 if ((ret = m920x_write(d->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300302 return ret;
303
304 return ret;
305}
306
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300307static int m920x_update_filters(struct dvb_usb_adapter *adap)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300308{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300309 struct m920x_state *m = adap->dev->priv;
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300310 int enabled = m->filtering_enabled[adap->id];
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300311 int i, ret = 0, filter = 0;
Michael Krufky77eed212011-09-06 09:31:57 -0300312 int ep = adap->props.fe[0].stream.endpoint;
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300313
314 for (i = 0; i < M9206_MAX_FILTERS; i++)
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300315 if (m->filters[adap->id][i] == 8192)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300316 enabled = 0;
317
318 /* Disable all filters */
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300319 if ((ret = m920x_set_filter(adap->dev, ep, 1, enabled)) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300320 return ret;
321
322 for (i = 0; i < M9206_MAX_FILTERS; i++)
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300323 if ((ret = m920x_set_filter(adap->dev, ep, i + 2, 0)) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300324 return ret;
325
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300326 /* Set */
327 if (enabled) {
328 for (i = 0; i < M9206_MAX_FILTERS; i++) {
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300329 if (m->filters[adap->id][i] == 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300330 continue;
331
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300332 if ((ret = m920x_set_filter(adap->dev, ep, filter + 2, m->filters[adap->id][i])) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300333 return ret;
334
335 filter++;
336 }
337 }
338
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300339 return ret;
340}
341
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300342static int m920x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300343{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300344 struct m920x_state *m = adap->dev->priv;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300345
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300346 m->filtering_enabled[adap->id] = onoff ? 1 : 0;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300347
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300348 return m920x_update_filters(adap);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300349}
350
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300351static int m920x_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300352{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300353 struct m920x_state *m = adap->dev->priv;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300354
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300355 m->filters[adap->id][index] = onoff ? pid : 0;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300356
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300357 return m920x_update_filters(adap);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300358}
359
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300360static int m920x_firmware_download(struct usb_device *udev, const struct firmware *fw)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300361{
362 u16 value, index, size;
Florian Mickler513ea352011-03-21 15:33:45 -0300363 u8 *read, *buff;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300364 int i, pass, ret = 0;
365
366 buff = kmalloc(65536, GFP_KERNEL);
Roel Kluin1601fb12009-09-18 20:09:52 -0300367 if (buff == NULL)
368 return -ENOMEM;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300369
Florian Mickler513ea352011-03-21 15:33:45 -0300370 read = kmalloc(4, GFP_KERNEL);
371 if (!read) {
372 kfree(buff);
373 return -ENOMEM;
374 }
375
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300376 if ((ret = m920x_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300377 goto done;
Andy Shevchenko5bdb7872012-09-26 09:55:14 -0300378 deb("%*ph\n", 4, read);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300379
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300380 if ((ret = m920x_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300381 goto done;
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300382 deb("%x\n", read[0]);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300383
384 for (pass = 0; pass < 2; pass++) {
385 for (i = 0; i + (sizeof(u16) * 3) < fw->size;) {
Al Virofa9c13a2008-05-21 00:32:41 -0300386 value = get_unaligned_le16(fw->data + i);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300387 i += sizeof(u16);
388
Al Virofa9c13a2008-05-21 00:32:41 -0300389 index = get_unaligned_le16(fw->data + i);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300390 i += sizeof(u16);
391
Al Virofa9c13a2008-05-21 00:32:41 -0300392 size = get_unaligned_le16(fw->data + i);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300393 i += sizeof(u16);
394
395 if (pass == 1) {
396 /* Will stall if using fw->data ... */
397 memcpy(buff, fw->data + i, size);
398
399 ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0),
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300400 M9206_FW,
401 USB_TYPE_VENDOR | USB_DIR_OUT,
402 value, index, buff, size, 20);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300403 if (ret != size) {
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300404 deb("error while uploading fw!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300405 ret = -EIO;
406 goto done;
407 }
408 msleep(3);
409 }
410 i += size;
411 }
412 if (i != fw->size) {
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300413 deb("bad firmware file!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300414 ret = -EINVAL;
415 goto done;
416 }
417 }
418
419 msleep(36);
420
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300421 /* m920x will disconnect itself from the bus after this. */
422 (void) m920x_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300423 deb("firmware uploaded!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300424
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300425 done:
Florian Mickler513ea352011-03-21 15:33:45 -0300426 kfree(read);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300427 kfree(buff);
428
429 return ret;
430}
431
Michael Krufkye16c1f52007-01-23 15:00:42 -0300432/* Callbacks for DVB USB */
Aapo Tahkola7d1d4e62007-03-15 13:01:46 -0300433static int m920x_identify_state(struct usb_device *udev,
434 struct dvb_usb_device_properties *props,
435 struct dvb_usb_device_description **desc,
436 int *cold)
Michael Krufkye16c1f52007-01-23 15:00:42 -0300437{
438 struct usb_host_interface *alt;
439
440 alt = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 1);
441 *cold = (alt == NULL) ? 1 : 0;
442
443 return 0;
444}
445
Michael Krufky5afb7072007-03-26 16:35:29 -0300446/* demod configurations */
Michael Krufkye7b419b2007-03-26 16:39:20 -0300447static int m920x_mt352_demod_init(struct dvb_frontend *fe)
Michael Krufkye16c1f52007-01-23 15:00:42 -0300448{
Aapo Tahkolad577ee02007-05-08 18:33:52 -0300449 int ret;
Michael Krufkye16c1f52007-01-23 15:00:42 -0300450 u8 config[] = { CONFIG, 0x3d };
451 u8 clock[] = { CLOCK_CTL, 0x30 };
452 u8 reset[] = { RESET, 0x80 };
453 u8 adc_ctl[] = { ADC_CTL_1, 0x40 };
454 u8 agc[] = { AGC_TARGET, 0x1c, 0x20 };
455 u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 };
456 u8 unk1[] = { 0x93, 0x1a };
457 u8 unk2[] = { 0xb5, 0x7a };
458
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300459 deb("Demod init!\n");
Michael Krufkye16c1f52007-01-23 15:00:42 -0300460
Aapo Tahkolad577ee02007-05-08 18:33:52 -0300461 if ((ret = mt352_write(fe, config, ARRAY_SIZE(config))) != 0)
462 return ret;
463 if ((ret = mt352_write(fe, clock, ARRAY_SIZE(clock))) != 0)
464 return ret;
465 if ((ret = mt352_write(fe, reset, ARRAY_SIZE(reset))) != 0)
466 return ret;
467 if ((ret = mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl))) != 0)
468 return ret;
469 if ((ret = mt352_write(fe, agc, ARRAY_SIZE(agc))) != 0)
470 return ret;
471 if ((ret = mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc))) != 0)
472 return ret;
473 if ((ret = mt352_write(fe, unk1, ARRAY_SIZE(unk1))) != 0)
474 return ret;
475 if ((ret = mt352_write(fe, unk2, ARRAY_SIZE(unk2))) != 0)
476 return ret;
477
Michael Krufkye16c1f52007-01-23 15:00:42 -0300478 return 0;
479}
480
Michael Krufkye7b419b2007-03-26 16:39:20 -0300481static struct mt352_config m920x_mt352_config = {
Aapo Tahkola26247012007-03-05 18:23:19 -0300482 .demod_address = 0x0f,
Michael Krufkye16c1f52007-01-23 15:00:42 -0300483 .no_tuner = 1,
Michael Krufkye7b419b2007-03-26 16:39:20 -0300484 .demod_init = m920x_mt352_demod_init,
Michael Krufkye16c1f52007-01-23 15:00:42 -0300485};
486
Michael Krufkye7b419b2007-03-26 16:39:20 -0300487static struct tda1004x_config m920x_tda10046_08_config = {
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300488 .demod_address = 0x08,
489 .invert = 0,
490 .invert_oclk = 0,
491 .ts_mode = TDA10046_TS_SERIAL,
492 .xtal_freq = TDA10046_XTAL_16M,
493 .if_freq = TDA10046_FREQ_045,
494 .agc_config = TDA10046_AGC_TDA827X,
495 .gpio_config = TDA10046_GPTRI,
496 .request_firmware = NULL,
497};
498
Michael Krufkye7b419b2007-03-26 16:39:20 -0300499static struct tda1004x_config m920x_tda10046_0b_config = {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300500 .demod_address = 0x0b,
501 .invert = 0,
502 .invert_oclk = 0,
503 .ts_mode = TDA10046_TS_SERIAL,
504 .xtal_freq = TDA10046_XTAL_16M,
505 .if_freq = TDA10046_FREQ_045,
506 .agc_config = TDA10046_AGC_TDA827X,
507 .gpio_config = TDA10046_GPTRI,
508 .request_firmware = NULL, /* uses firmware EEPROM */
509};
510
Michael Krufky5afb7072007-03-26 16:35:29 -0300511/* tuner configurations */
Michael Krufkye7b419b2007-03-26 16:39:20 -0300512static struct qt1010_config m920x_qt1010_config = {
Michael Krufky5afb7072007-03-26 16:35:29 -0300513 .i2c_address = 0x62
514};
515
516/* Callbacks for DVB USB */
Michael Krufkye7b419b2007-03-26 16:39:20 -0300517static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300518{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300519 deb("%s\n",__func__);
Michael Krufky5afb7072007-03-26 16:35:29 -0300520
Michael Krufkyd12f51a2011-09-17 14:59:54 -0300521 adap->fe_adap[0].fe = dvb_attach(mt352_attach,
522 &m920x_mt352_config,
523 &adap->dev->i2c_adap);
524 if ((adap->fe_adap[0].fe) == NULL)
Michael Krufky5afb7072007-03-26 16:35:29 -0300525 return -EIO;
526
527 return 0;
528}
529
Michael Krufkye7b419b2007-03-26 16:39:20 -0300530static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300531{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300532 deb("%s\n",__func__);
Nick Andrewaa50ec22007-03-22 17:09:35 -0300533
Michael Krufkyd12f51a2011-09-17 14:59:54 -0300534 adap->fe_adap[0].fe = dvb_attach(tda10046_attach,
535 &m920x_tda10046_08_config,
536 &adap->dev->i2c_adap);
537 if ((adap->fe_adap[0].fe) == NULL)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300538 return -EIO;
539
Nick Andrewaa50ec22007-03-22 17:09:35 -0300540 return 0;
541}
542
Michael Krufkye7b419b2007-03-26 16:39:20 -0300543static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300544{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300545 deb("%s\n",__func__);
Nick Andrewaa50ec22007-03-22 17:09:35 -0300546
Michael Krufkyd12f51a2011-09-17 14:59:54 -0300547 adap->fe_adap[0].fe = dvb_attach(tda10046_attach,
548 &m920x_tda10046_0b_config,
549 &adap->dev->i2c_adap);
550 if ((adap->fe_adap[0].fe) == NULL)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300551 return -EIO;
552
Nick Andrewaa50ec22007-03-22 17:09:35 -0300553 return 0;
554}
555
Michael Krufkye7b419b2007-03-26 16:39:20 -0300556static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300557{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300558 deb("%s\n",__func__);
Michael Krufkye7b419b2007-03-26 16:39:20 -0300559
Michael Krufky77eed212011-09-06 09:31:57 -0300560 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 -0300561 return -ENODEV;
562
563 return 0;
564}
565
Michael Krufkye7b419b2007-03-26 16:39:20 -0300566static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300567{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300568 deb("%s\n",__func__);
Michael Krufkye7b419b2007-03-26 16:39:20 -0300569
Michael Krufky77eed212011-09-06 09:31:57 -0300570 if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL)
Michael Krufky5afb7072007-03-26 16:35:29 -0300571 return -ENODEV;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300572
573 return 0;
574}
575
Michael Krufkye7b419b2007-03-26 16:39:20 -0300576static int m920x_tda8275_61_tuner_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 Krufky77eed212011-09-06 09:31:57 -0300580 if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300581 return -ENODEV;
582
Nick Andrewaa50ec22007-03-22 17:09:35 -0300583 return 0;
584}
585
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300586static int m920x_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
587{
Michael Krufky77eed212011-09-06 09:31:57 -0300588 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300589 &adap->dev->i2c_adap, 0x61,
590 TUNER_PHILIPS_FMD1216ME_MK3);
591 return 0;
592}
593
Michael Krufky5afb7072007-03-26 16:35:29 -0300594/* device-specific initialization */
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300595static struct m920x_inits megasky_rc_init [] = {
Michael Krufky5afb7072007-03-26 16:35:29 -0300596 { M9206_RC_INIT2, 0xa8 },
597 { M9206_RC_INIT1, 0x51 },
598 { } /* terminating entry */
599};
600
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300601static struct m920x_inits tvwalkertwin_rc_init [] = {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300602 { M9206_RC_INIT2, 0x00 },
603 { M9206_RC_INIT1, 0xef },
604 { 0xff28, 0x00 },
605 { 0xff23, 0x00 },
606 { 0xff21, 0x30 },
607 { } /* terminating entry */
608};
609
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300610static struct m920x_inits pinnacle310e_init[] = {
Antonio Ospite90849832012-12-10 17:37:10 -0300611 /* without these the tuner doesn't work */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300612 { 0xff20, 0x9b },
613 { 0xff22, 0x70 },
614
615 /* rc settings */
616 { 0xff50, 0x80 },
617 { M9206_RC_INIT1, 0x00 },
618 { M9206_RC_INIT2, 0xff },
619 { } /* terminating entry */
620};
621
Michael Krufky5afb7072007-03-26 16:35:29 -0300622/* ir keymaps */
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300623static struct rc_map_table rc_map_megasky_table[] = {
Mauro Carvalho Chehab2e365882009-08-29 15:19:31 -0300624 { 0x0012, KEY_POWER },
625 { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */
626 { 0x0002, KEY_CHANNELUP },
627 { 0x0005, KEY_CHANNELDOWN },
628 { 0x0003, KEY_VOLUMEUP },
629 { 0x0006, KEY_VOLUMEDOWN },
630 { 0x0004, KEY_MUTE },
631 { 0x0007, KEY_OK }, /* TS */
632 { 0x0008, KEY_STOP },
633 { 0x0009, KEY_MENU }, /* swap */
634 { 0x000a, KEY_REWIND },
635 { 0x001b, KEY_PAUSE },
636 { 0x001f, KEY_FASTFORWARD },
637 { 0x000c, KEY_RECORD },
638 { 0x000d, KEY_CAMERA }, /* screenshot */
639 { 0x000e, KEY_COFFEE }, /* "MTS" */
Michael Krufky5afb7072007-03-26 16:35:29 -0300640};
641
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300642static struct rc_map_table rc_map_tvwalkertwin_table[] = {
Mauro Carvalho Chehab2e365882009-08-29 15:19:31 -0300643 { 0x0001, KEY_ZOOM }, /* Full Screen */
644 { 0x0002, KEY_CAMERA }, /* snapshot */
645 { 0x0003, KEY_MUTE },
646 { 0x0004, KEY_REWIND },
647 { 0x0005, KEY_PLAYPAUSE }, /* Play/Pause */
648 { 0x0006, KEY_FASTFORWARD },
649 { 0x0007, KEY_RECORD },
650 { 0x0008, KEY_STOP },
651 { 0x0009, KEY_TIME }, /* Timeshift */
652 { 0x000c, KEY_COFFEE }, /* Recall */
653 { 0x000e, KEY_CHANNELUP },
654 { 0x0012, KEY_POWER },
655 { 0x0015, KEY_MENU }, /* source */
656 { 0x0018, KEY_CYCLEWINDOWS }, /* TWIN PIP */
657 { 0x001a, KEY_CHANNELDOWN },
658 { 0x001b, KEY_VOLUMEDOWN },
659 { 0x001e, KEY_VOLUMEUP },
Michael Krufky5afb7072007-03-26 16:35:29 -0300660};
661
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300662static struct rc_map_table rc_map_pinnacle310e_table[] = {
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300663 { 0x16, KEY_POWER },
664 { 0x17, KEY_FAVORITES },
665 { 0x0f, KEY_TEXT },
Jarod Wilson56c08932011-04-05 18:42:30 -0300666 { 0x48, KEY_PROGRAM }, /* preview */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300667 { 0x1c, KEY_EPG },
Jarod Wilson56c08932011-04-05 18:42:30 -0300668 { 0x04, KEY_LIST }, /* record list */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300669 { 0x03, KEY_1 },
670 { 0x01, KEY_2 },
671 { 0x06, KEY_3 },
672 { 0x09, KEY_4 },
673 { 0x1d, KEY_5 },
674 { 0x1f, KEY_6 },
675 { 0x0d, KEY_7 },
676 { 0x19, KEY_8 },
677 { 0x1b, KEY_9 },
678 { 0x15, KEY_0 },
679 { 0x0c, KEY_CANCEL },
680 { 0x4a, KEY_CLEAR },
681 { 0x13, KEY_BACK },
682 { 0x00, KEY_TAB },
683 { 0x4b, KEY_UP },
684 { 0x4e, KEY_LEFT },
685 { 0x52, KEY_RIGHT },
686 { 0x51, KEY_DOWN },
687 { 0x4f, KEY_ENTER }, /* could also be KEY_OK */
688 { 0x1e, KEY_VOLUMEUP },
689 { 0x0a, KEY_VOLUMEDOWN },
690 { 0x05, KEY_CHANNELUP },
691 { 0x02, KEY_CHANNELDOWN },
692 { 0x11, KEY_RECORD },
693 { 0x14, KEY_PLAY },
694 { 0x4c, KEY_PAUSE },
695 { 0x1a, KEY_STOP },
696 { 0x40, KEY_REWIND },
697 { 0x12, KEY_FASTFORWARD },
698 { 0x41, KEY_PREVIOUSSONG }, /* Replay */
699 { 0x42, KEY_NEXTSONG }, /* Skip */
700 { 0x54, KEY_CAMERA }, /* Capture */
701/* { 0x50, KEY_SAP }, */ /* Sap */
702 { 0x47, KEY_CYCLEWINDOWS }, /* Pip */
703 { 0x4d, KEY_SCREEN }, /* FullScreen */
704 { 0x08, KEY_SUBTITLE },
705 { 0x0e, KEY_MUTE },
706/* { 0x49, KEY_LR }, */ /* L/R */
707 { 0x07, KEY_SLEEP }, /* Hibernate */
Jarod Wilson56c08932011-04-05 18:42:30 -0300708 { 0x08, KEY_VIDEO }, /* A/V */
709 { 0x0e, KEY_MENU }, /* Recall */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300710 { 0x45, KEY_ZOOMIN },
711 { 0x46, KEY_ZOOMOUT },
Jarod Wilson56c08932011-04-05 18:42:30 -0300712 { 0x18, KEY_RED }, /* Red */
713 { 0x53, KEY_GREEN }, /* Green */
714 { 0x5e, KEY_YELLOW }, /* Yellow */
715 { 0x5f, KEY_BLUE }, /* Blue */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300716};
717
Michael Krufky26f48ea2006-09-28 01:46:49 -0300718/* DVB USB Driver stuff */
719static struct dvb_usb_device_properties megasky_properties;
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300720static struct dvb_usb_device_properties digivox_mini_ii_properties;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300721static struct dvb_usb_device_properties tvwalkertwin_properties;
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300722static struct dvb_usb_device_properties dposh_properties;
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300723static struct dvb_usb_device_properties pinnacle_pctv310e_properties;
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300724
Michael Krufkyfa948052007-01-21 15:57:48 -0300725static int m920x_probe(struct usb_interface *intf,
726 const struct usb_device_id *id)
Michael Krufky26f48ea2006-09-28 01:46:49 -0300727{
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300728 struct dvb_usb_device *d = NULL;
Michael Krufky26f48ea2006-09-28 01:46:49 -0300729 int ret;
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300730 struct m920x_inits *rc_init_seq = NULL;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300731 int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
Michael Krufky26f48ea2006-09-28 01:46:49 -0300732
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300733 deb("Probing for m920x device at interface %d\n", bInterfaceNumber);
Michael Krufky26f48ea2006-09-28 01:46:49 -0300734
Nick Andrewaa50ec22007-03-22 17:09:35 -0300735 if (bInterfaceNumber == 0) {
736 /* Single-tuner device, or first interface on
737 * multi-tuner device
738 */
Michael Krufky26f48ea2006-09-28 01:46:49 -0300739
Janne Grunau78e92002008-04-09 19:13:13 -0300740 ret = dvb_usb_device_init(intf, &megasky_properties,
741 THIS_MODULE, &d, adapter_nr);
742 if (ret == 0) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300743 rc_init_seq = megasky_rc_init;
744 goto found;
745 }
746
Janne Grunau78e92002008-04-09 19:13:13 -0300747 ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties,
748 THIS_MODULE, &d, adapter_nr);
749 if (ret == 0) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300750 /* No remote control, so no rc_init_seq */
751 goto found;
752 }
753
754 /* This configures both tuners on the TV Walker Twin */
Janne Grunau78e92002008-04-09 19:13:13 -0300755 ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
756 THIS_MODULE, &d, adapter_nr);
757 if (ret == 0) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300758 rc_init_seq = tvwalkertwin_rc_init;
759 goto found;
760 }
761
Janne Grunau78e92002008-04-09 19:13:13 -0300762 ret = dvb_usb_device_init(intf, &dposh_properties,
763 THIS_MODULE, &d, adapter_nr);
764 if (ret == 0) {
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300765 /* Remote controller not supported yet. */
766 goto found;
767 }
768
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300769 ret = dvb_usb_device_init(intf, &pinnacle_pctv310e_properties,
770 THIS_MODULE, &d, adapter_nr);
771 if (ret == 0) {
772 rc_init_seq = pinnacle310e_init;
773 goto found;
774 }
775
Nick Andrewaa50ec22007-03-22 17:09:35 -0300776 return ret;
777 } else {
778 /* Another interface on a multi-tuner device */
779
780 /* The LifeView TV Walker Twin gets here, but struct
781 * tvwalkertwin_properties already configured both
782 * tuners, so there is nothing for us to do here
783 */
Nick Andrewaa50ec22007-03-22 17:09:35 -0300784 }
Michael Krufky26f48ea2006-09-28 01:46:49 -0300785
Michael Krufkye7b419b2007-03-26 16:39:20 -0300786 found:
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300787 if ((ret = m920x_init_ep(intf)) < 0)
Aapo Tahkola480ac762007-03-05 18:54:27 -0300788 return ret;
789
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300790 if (d && (ret = m920x_init(d, rc_init_seq)) != 0)
Aapo Tahkola480ac762007-03-05 18:54:27 -0300791 return ret;
792
Michael Krufky26f48ea2006-09-28 01:46:49 -0300793 return ret;
794}
795
796static struct usb_device_id m920x_table [] = {
797 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300798 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
799 USB_PID_MSI_DIGI_VOX_MINI_II) },
Nick Andrewaa50ec22007-03-22 17:09:35 -0300800 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
801 USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD) },
802 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
803 USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) },
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300804 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
805 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300806 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_PINNACLE_PCTV310E) },
Michael Krufky26f48ea2006-09-28 01:46:49 -0300807 { } /* Terminating entry */
808};
809MODULE_DEVICE_TABLE (usb, m920x_table);
810
Michael Krufky01cb34d2006-09-23 20:01:29 -0300811static struct dvb_usb_device_properties megasky_properties = {
Michael Krufky758117c2007-01-23 15:34:10 -0300812 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
Michael Krufky1f61f3b2006-10-07 15:03:04 -0300813
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300814 .usb_ctrl = DEVICE_SPECIFIC,
815 .firmware = "dvb-usb-megasky-02.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300816 .download_firmware = m920x_firmware_download,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300817
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300818 .rc.legacy = {
819 .rc_interval = 100,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300820 .rc_map_table = rc_map_megasky_table,
821 .rc_map_size = ARRAY_SIZE(rc_map_megasky_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300822 .rc_query = m920x_rc_query,
823 },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300824
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300825 .size_of_priv = sizeof(struct m920x_state),
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300826
Aapo Tahkola7d1d4e62007-03-15 13:01:46 -0300827 .identify_state = m920x_identify_state,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300828 .num_adapters = 1,
829 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -0300830 .num_frontends = 1,
831 .fe = {{
832
Michael Krufky758117c2007-01-23 15:34:10 -0300833 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
834 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
835
Michael Krufky01cb34d2006-09-23 20:01:29 -0300836 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300837 .pid_filter = m920x_pid_filter,
838 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300839
Michael Krufkye7b419b2007-03-26 16:39:20 -0300840 .frontend_attach = m920x_mt352_frontend_attach,
841 .tuner_attach = m920x_qt1010_tuner_attach,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300842
843 .stream = {
844 .type = USB_BULK,
845 .count = 8,
846 .endpoint = 0x81,
847 .u = {
848 .bulk = {
849 .buffersize = 512,
850 }
851 }
852 },
Michael Krufky77eed212011-09-06 09:31:57 -0300853 }},
Michael Krufky01cb34d2006-09-23 20:01:29 -0300854 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300855 .i2c_algo = &m920x_i2c_algo,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300856
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300857 .num_device_descs = 1,
858 .devices = {
859 { "MSI Mega Sky 580 DVB-T USB2.0",
Michael Krufkybaa2ed02006-09-23 20:01:29 -0300860 { &m920x_table[0], NULL },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300861 { NULL },
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300862 }
863 }
864};
865
866static struct dvb_usb_device_properties digivox_mini_ii_properties = {
867 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
868
869 .usb_ctrl = DEVICE_SPECIFIC,
870 .firmware = "dvb-usb-digivox-02.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300871 .download_firmware = m920x_firmware_download,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300872
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300873 .size_of_priv = sizeof(struct m920x_state),
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300874
875 .identify_state = m920x_identify_state,
876 .num_adapters = 1,
877 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -0300878 .num_frontends = 1,
879 .fe = {{
880
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300881 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300882 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300883
884 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300885 .pid_filter = m920x_pid_filter,
886 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300887
Michael Krufkye7b419b2007-03-26 16:39:20 -0300888 .frontend_attach = m920x_tda10046_08_frontend_attach,
889 .tuner_attach = m920x_tda8275_60_tuner_attach,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300890
891 .stream = {
892 .type = USB_BULK,
893 .count = 8,
894 .endpoint = 0x81,
895 .u = {
896 .bulk = {
897 .buffersize = 0x4000,
898 }
899 }
900 },
Michael Krufky77eed212011-09-06 09:31:57 -0300901 }},
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300902 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300903 .i2c_algo = &m920x_i2c_algo,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300904
905 .num_device_descs = 1,
906 .devices = {
907 { "MSI DIGI VOX mini II DVB-T USB2.0",
908 { &m920x_table[1], NULL },
909 { NULL },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300910 },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300911 }
912};
913
Michael Krufkye7b419b2007-03-26 16:39:20 -0300914/* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net>
915 *
916 * LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A
917 * TDA10046 #0 is located at i2c address 0x08
Aapo Tahkola3ab3b692007-05-08 18:23:38 -0300918 * TDA10046 #1 is located at i2c address 0x0b
Michael Krufkye7b419b2007-03-26 16:39:20 -0300919 * TDA8275A #0 is located at i2c address 0x60
Aapo Tahkola3ab3b692007-05-08 18:23:38 -0300920 * TDA8275A #1 is located at i2c address 0x61
Michael Krufkye7b419b2007-03-26 16:39:20 -0300921 */
Nick Andrewaa50ec22007-03-22 17:09:35 -0300922static struct dvb_usb_device_properties tvwalkertwin_properties = {
923 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
924
925 .usb_ctrl = DEVICE_SPECIFIC,
926 .firmware = "dvb-usb-tvwalkert.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300927 .download_firmware = m920x_firmware_download,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300928
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300929 .rc.legacy = {
930 .rc_interval = 100,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300931 .rc_map_table = rc_map_tvwalkertwin_table,
932 .rc_map_size = ARRAY_SIZE(rc_map_tvwalkertwin_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300933 .rc_query = m920x_rc_query,
934 },
Nick Andrewaa50ec22007-03-22 17:09:35 -0300935
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300936 .size_of_priv = sizeof(struct m920x_state),
Nick Andrewaa50ec22007-03-22 17:09:35 -0300937
938 .identify_state = m920x_identify_state,
Aapo Tahkola3ab3b692007-05-08 18:23:38 -0300939 .num_adapters = 2,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300940 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -0300941 .num_frontends = 1,
942 .fe = {{
943
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300944 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
945 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300946
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300947 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300948 .pid_filter = m920x_pid_filter,
949 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300950
Michael Krufkye7b419b2007-03-26 16:39:20 -0300951 .frontend_attach = m920x_tda10046_08_frontend_attach,
952 .tuner_attach = m920x_tda8275_60_tuner_attach,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300953
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300954 .stream = {
955 .type = USB_BULK,
956 .count = 8,
957 .endpoint = 0x81,
958 .u = {
959 .bulk = {
960 .buffersize = 512,
961 }
962 }
Michael Krufky77eed212011-09-06 09:31:57 -0300963 }},
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300964 }},{
Michael Krufky77eed212011-09-06 09:31:57 -0300965 .num_frontends = 1,
966 .fe = {{
967
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300968 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
969 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
970
971 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300972 .pid_filter = m920x_pid_filter,
973 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300974
Michael Krufkye7b419b2007-03-26 16:39:20 -0300975 .frontend_attach = m920x_tda10046_0b_frontend_attach,
976 .tuner_attach = m920x_tda8275_61_tuner_attach,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300977
978 .stream = {
979 .type = USB_BULK,
980 .count = 8,
981 .endpoint = 0x82,
982 .u = {
983 .bulk = {
984 .buffersize = 512,
985 }
986 }
Michael Krufky77eed212011-09-06 09:31:57 -0300987 }},
Nick Andrewaa50ec22007-03-22 17:09:35 -0300988 },
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300989 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300990 .i2c_algo = &m920x_i2c_algo,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300991
992 .num_device_descs = 1,
993 .devices = {
994 { .name = "LifeView TV Walker Twin DVB-T USB2.0",
995 .cold_ids = { &m920x_table[2], NULL },
996 .warm_ids = { &m920x_table[3], NULL },
997 },
998 }
999};
1000
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001001static struct dvb_usb_device_properties dposh_properties = {
1002 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1003
1004 .usb_ctrl = DEVICE_SPECIFIC,
1005 .firmware = "dvb-usb-dposh-01.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001006 .download_firmware = m920x_firmware_download,
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001007
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001008 .size_of_priv = sizeof(struct m920x_state),
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001009
1010 .identify_state = m920x_identify_state,
1011 .num_adapters = 1,
1012 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -03001013 .num_frontends = 1,
1014 .fe = {{
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001015 /* Hardware pid filters don't work with this device/firmware */
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001016
Michael Krufkye7b419b2007-03-26 16:39:20 -03001017 .frontend_attach = m920x_mt352_frontend_attach,
1018 .tuner_attach = m920x_qt1010_tuner_attach,
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001019
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001020 .stream = {
1021 .type = USB_BULK,
1022 .count = 8,
1023 .endpoint = 0x81,
1024 .u = {
1025 .bulk = {
1026 .buffersize = 512,
1027 }
1028 }
1029 },
Michael Krufky77eed212011-09-06 09:31:57 -03001030 }},
Michael Krufkyd3911ea2007-03-22 19:03:37 -03001031 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -03001032 .i2c_algo = &m920x_i2c_algo,
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -03001033
1034 .num_device_descs = 1,
1035 .devices = {
1036 { .name = "Dposh DVB-T USB2.0",
1037 .cold_ids = { &m920x_table[4], NULL },
1038 .warm_ids = { &m920x_table[5], NULL },
1039 },
1040 }
1041};
1042
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001043static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
1044 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1045
1046 .usb_ctrl = DEVICE_SPECIFIC,
1047 .download_firmware = NULL,
1048
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001049 .rc.legacy = {
1050 .rc_interval = 100,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001051 .rc_map_table = rc_map_pinnacle310e_table,
1052 .rc_map_size = ARRAY_SIZE(rc_map_pinnacle310e_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001053 .rc_query = m920x_rc_query,
1054 },
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001055
1056 .size_of_priv = sizeof(struct m920x_state),
1057
1058 .identify_state = m920x_identify_state,
1059 .num_adapters = 1,
1060 .adapter = {{
Michael Krufky77eed212011-09-06 09:31:57 -03001061 .num_frontends = 1,
1062 .fe = {{
1063
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001064 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1065 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1066
1067 .pid_filter_count = 8,
1068 .pid_filter = m920x_pid_filter,
1069 .pid_filter_ctrl = m920x_pid_filter_ctrl,
1070
1071 .frontend_attach = m920x_mt352_frontend_attach,
1072 .tuner_attach = m920x_fmd1216me_tuner_attach,
1073
1074 .stream = {
1075 .type = USB_ISOC,
1076 .count = 5,
1077 .endpoint = 0x84,
1078 .u = {
1079 .isoc = {
1080 .framesperurb = 128,
1081 .framesize = 564,
1082 .interval = 1,
1083 }
1084 }
1085 },
Michael Krufky77eed212011-09-06 09:31:57 -03001086 }},
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001087 } },
1088 .i2c_algo = &m920x_i2c_algo,
1089
1090 .num_device_descs = 1,
1091 .devices = {
1092 { "Pinnacle PCTV 310e",
1093 { &m920x_table[6], NULL },
1094 { NULL },
1095 }
1096 }
1097};
1098
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001099static struct usb_driver m920x_driver = {
1100 .name = "dvb_usb_m920x",
Michael Krufky2a2bfa72006-09-23 20:13:12 -03001101 .probe = m920x_probe,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001102 .disconnect = dvb_usb_device_exit,
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001103 .id_table = m920x_table,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001104};
1105
Greg Kroah-Hartmanecb3b2b2011-11-18 09:46:12 -08001106module_usb_driver(m920x_driver);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001107
1108MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
Nick Andrewaa50ec22007-03-22 17:09:35 -03001109MODULE_DESCRIPTION("DVB Driver for ULI M920x");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001110MODULE_VERSION("0.1");
1111MODULE_LICENSE("GPL");
Michael Krufkyce9c2752007-03-22 17:18:26 -03001112
1113/*
1114 * Local variables:
1115 * c-basic-offset: 8
1116 */