blob: 9456792f219be5530baf9830257a8f3efb28737f [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
Aapo Tahkola4fd74a72007-03-26 17:05:59 -030066static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -030067{
Aapo Tahkola3847b222007-05-08 18:21:47 -030068 int ret = 0, i, epi, flags = 0;
Aapo Tahkola47f8df02007-05-08 12:03:55 -030069 int adap_enabled[M9206_MAX_ADAPTERS] = { 0 };
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -030070
71 /* Remote controller init. */
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -030072 if (d->props.rc.legacy.rc_query) {
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -030073 deb("Initialising remote control\n");
Nick Andrewaa50ec22007-03-22 17:09:35 -030074 while (rc_seq->address) {
Aapo Tahkola4fd74a72007-03-26 17:05:59 -030075 if ((ret = m920x_write(d->udev, M9206_CORE,
Michael Krufkyd3911ea2007-03-22 19:03:37 -030076 rc_seq->data,
77 rc_seq->address)) != 0) {
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -030078 deb("Initialising remote control failed\n");
Nick Andrewaa50ec22007-03-22 17:09:35 -030079 return ret;
80 }
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -030081
Nick Andrewaa50ec22007-03-22 17:09:35 -030082 rc_seq++;
83 }
84
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -030085 deb("Initialising remote control success\n");
Aapo Tahkola480ac762007-03-05 18:54:27 -030086 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030087
Aapo Tahkola3847b222007-05-08 18:21:47 -030088 for (i = 0; i < d->props.num_adapters; i++)
89 flags |= d->adapter[i].props.caps;
Aapo Tahkola47f8df02007-05-08 12:03:55 -030090
Aapo Tahkola3847b222007-05-08 18:21:47 -030091 /* Some devices(Dposh) might crash if we attempt touch at all. */
92 if (flags & DVB_USB_ADAP_HAS_PID_FILTER) {
93 for (i = 0; i < d->props.num_adapters; i++) {
94 epi = d->adapter[i].props.stream.endpoint - 0x81;
95
96 if (epi < 0 || epi >= M9206_MAX_ADAPTERS) {
97 printk(KERN_INFO "m920x: Unexpected adapter endpoint!\n");
98 return -EINVAL;
99 }
100
101 adap_enabled[epi] = 1;
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300102 }
103
Aapo Tahkola3847b222007-05-08 18:21:47 -0300104 for (i = 0; i < M9206_MAX_ADAPTERS; i++) {
105 if (adap_enabled[i])
106 continue;
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300107
Aapo Tahkola3847b222007-05-08 18:21:47 -0300108 if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x0)) != 0)
109 return ret;
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300110
Aapo Tahkola3847b222007-05-08 18:21:47 -0300111 if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x02f5)) != 0)
112 return ret;
113 }
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300114 }
115
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300116 return ret;
117}
118
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300119static int m920x_init_ep(struct usb_interface *intf)
120{
121 struct usb_device *udev = interface_to_usbdev(intf);
122 struct usb_host_interface *alt;
123
124 if ((alt = usb_altnum_to_altsetting(intf, 1)) == NULL) {
125 deb("No alt found!\n");
126 return -ENODEV;
127 }
128
129 return usb_set_interface(udev, alt->desc.bInterfaceNumber,
130 alt->desc.bAlternateSetting);
131}
132
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300133static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300134{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300135 struct m920x_state *m = d->priv;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300136 int i, ret = 0;
Florian Mickler513ea352011-03-21 15:33:45 -0300137 u8 *rc_state;
138
139 rc_state = kmalloc(2, GFP_KERNEL);
140 if (!rc_state)
141 return -ENOMEM;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300142
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300143 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0)
Florian Mickler513ea352011-03-21 15:33:45 -0300144 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300145
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300146 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0)
Florian Mickler513ea352011-03-21 15:33:45 -0300147 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300148
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300149 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
150 if (rc5_data(&d->props.rc.legacy.rc_map_table[i]) == rc_state[1]) {
151 *event = d->props.rc.legacy.rc_map_table[i].keycode;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300152
153 switch(rc_state[0]) {
154 case 0x80:
155 *state = REMOTE_NO_KEY_PRESSED;
Florian Mickler513ea352011-03-21 15:33:45 -0300156 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300157
Nick Andrewaa50ec22007-03-22 17:09:35 -0300158 case 0x88: /* framing error or "invalid code" */
159 case 0x99:
160 case 0xc0:
161 case 0xd8:
162 *state = REMOTE_NO_KEY_PRESSED;
163 m->rep_count = 0;
Florian Mickler513ea352011-03-21 15:33:45 -0300164 goto out;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300165
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300166 case 0x93:
167 case 0x92:
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300168 case 0x83: /* pinnacle PCTV310e */
169 case 0x82:
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300170 m->rep_count = 0;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300171 *state = REMOTE_KEY_PRESSED;
Florian Mickler513ea352011-03-21 15:33:45 -0300172 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300173
174 case 0x91:
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300175 case 0x81: /* pinnacle PCTV310e */
Nick Andrewaa50ec22007-03-22 17:09:35 -0300176 /* prevent immediate auto-repeat */
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300177 if (++m->rep_count > 2)
178 *state = REMOTE_KEY_REPEAT;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300179 else
180 *state = REMOTE_NO_KEY_PRESSED;
Florian Mickler513ea352011-03-21 15:33:45 -0300181 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300182
183 default:
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300184 deb("Unexpected rc state %02x\n", rc_state[0]);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300185 *state = REMOTE_NO_KEY_PRESSED;
Florian Mickler513ea352011-03-21 15:33:45 -0300186 goto out;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300187 }
188 }
189
190 if (rc_state[1] != 0)
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300191 deb("Unknown rc key %02x\n", rc_state[1]);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300192
193 *state = REMOTE_NO_KEY_PRESSED;
194
Florian Mickler513ea352011-03-21 15:33:45 -0300195 out:
196 kfree(rc_state);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300197 return ret;
198}
199
200/* I2C */
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300201static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300202{
203 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Aapo Tahkola26247012007-03-05 18:23:19 -0300204 int i, j;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300205 int ret = 0;
206
Trent Piephod40860f2007-03-05 23:55:00 -0300207 if (!num)
208 return -EINVAL;
209
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300210 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
211 return -EAGAIN;
212
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300213 for (i = 0; i < num; i++) {
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300214 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 -0300215 /* For a 0 byte message, I think sending the address
216 * to index 0x80|0x40 would be the correct thing to
217 * do. However, zero byte messages are only used for
218 * probing, and since we don't know how to get the
219 * slave's ack, we can't probe. */
Trent Piephod40860f2007-03-05 23:55:00 -0300220 ret = -ENOTSUPP;
221 goto unlock;
222 }
223 /* Send START & address/RW bit */
224 if (!(msg[i].flags & I2C_M_NOSTART)) {
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300225 if ((ret = m920x_write(d->udev, M9206_I2C,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300226 (msg[i].addr << 1) |
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300227 (msg[i].flags & I2C_M_RD ? 0x01 : 0), 0x80)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300228 goto unlock;
229 /* Should check for ack here, if we knew how. */
230 }
Aapo Tahkola26247012007-03-05 18:23:19 -0300231 if (msg[i].flags & I2C_M_RD) {
Trent Piephod40860f2007-03-05 23:55:00 -0300232 for (j = 0; j < msg[i].len; j++) {
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300233 /* Last byte of transaction?
234 * Send STOP, otherwise send ACK. */
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300235 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x01;
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300236
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300237 if ((ret = m920x_read(d->udev, M9206_I2C, 0x0,
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300238 0x20 | stop,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300239 &msg[i].buf[j], 1)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300240 goto unlock;
Aapo Tahkola84ad7572007-01-21 15:57:20 -0300241 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300242 } else {
Trent Piephod40860f2007-03-05 23:55:00 -0300243 for (j = 0; j < msg[i].len; j++) {
244 /* Last byte of transaction? Then send STOP. */
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300245 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x00;
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300246
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300247 if ((ret = m920x_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300248 goto unlock;
249 /* Should check for ack here too. */
Aapo Tahkola26247012007-03-05 18:23:19 -0300250 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300251 }
252 }
Aapo Tahkola26247012007-03-05 18:23:19 -0300253 ret = num;
Trent Piephod40860f2007-03-05 23:55:00 -0300254
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300255 unlock:
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300256 mutex_unlock(&d->i2c_mutex);
257
258 return ret;
259}
260
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300261static u32 m920x_i2c_func(struct i2c_adapter *adapter)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300262{
263 return I2C_FUNC_I2C;
264}
265
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300266static struct i2c_algorithm m920x_i2c_algo = {
267 .master_xfer = m920x_i2c_xfer,
268 .functionality = m920x_i2c_func,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300269};
270
Michael Krufky5afb7072007-03-26 16:35:29 -0300271/* pid filter */
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300272static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300273{
274 int ret = 0;
275
276 if (pid >= 0x8000)
277 return -EINVAL;
278
279 pid |= 0x8000;
280
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300281 if ((ret = m920x_write(d->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300282 return ret;
283
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300284 if ((ret = m920x_write(d->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300285 return ret;
286
287 return ret;
288}
289
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300290static int m920x_update_filters(struct dvb_usb_adapter *adap)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300291{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300292 struct m920x_state *m = adap->dev->priv;
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300293 int enabled = m->filtering_enabled[adap->id];
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300294 int i, ret = 0, filter = 0;
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300295 int ep = adap->props.stream.endpoint;
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300296
297 for (i = 0; i < M9206_MAX_FILTERS; i++)
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300298 if (m->filters[adap->id][i] == 8192)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300299 enabled = 0;
300
301 /* Disable all filters */
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300302 if ((ret = m920x_set_filter(adap->dev, ep, 1, enabled)) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300303 return ret;
304
305 for (i = 0; i < M9206_MAX_FILTERS; i++)
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300306 if ((ret = m920x_set_filter(adap->dev, ep, i + 2, 0)) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300307 return ret;
308
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300309 /* Set */
310 if (enabled) {
311 for (i = 0; i < M9206_MAX_FILTERS; i++) {
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300312 if (m->filters[adap->id][i] == 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300313 continue;
314
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300315 if ((ret = m920x_set_filter(adap->dev, ep, filter + 2, m->filters[adap->id][i])) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300316 return ret;
317
318 filter++;
319 }
320 }
321
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300322 return ret;
323}
324
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300325static int m920x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300326{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300327 struct m920x_state *m = adap->dev->priv;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300328
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300329 m->filtering_enabled[adap->id] = onoff ? 1 : 0;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300330
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300331 return m920x_update_filters(adap);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300332}
333
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300334static int m920x_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300335{
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300336 struct m920x_state *m = adap->dev->priv;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300337
Aapo Tahkola47f8df02007-05-08 12:03:55 -0300338 m->filters[adap->id][index] = onoff ? pid : 0;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300339
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300340 return m920x_update_filters(adap);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300341}
342
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300343static int m920x_firmware_download(struct usb_device *udev, const struct firmware *fw)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300344{
345 u16 value, index, size;
Florian Mickler513ea352011-03-21 15:33:45 -0300346 u8 *read, *buff;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300347 int i, pass, ret = 0;
348
349 buff = kmalloc(65536, GFP_KERNEL);
Roel Kluin1601fb12009-09-18 20:09:52 -0300350 if (buff == NULL)
351 return -ENOMEM;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300352
Florian Mickler513ea352011-03-21 15:33:45 -0300353 read = kmalloc(4, GFP_KERNEL);
354 if (!read) {
355 kfree(buff);
356 return -ENOMEM;
357 }
358
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300359 if ((ret = m920x_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300360 goto done;
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300361 deb("%x %x %x %x\n", read[0], read[1], read[2], read[3]);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300362
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300363 if ((ret = m920x_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300364 goto done;
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300365 deb("%x\n", read[0]);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300366
367 for (pass = 0; pass < 2; pass++) {
368 for (i = 0; i + (sizeof(u16) * 3) < fw->size;) {
Al Virofa9c13a2008-05-21 00:32:41 -0300369 value = get_unaligned_le16(fw->data + i);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300370 i += sizeof(u16);
371
Al Virofa9c13a2008-05-21 00:32:41 -0300372 index = get_unaligned_le16(fw->data + i);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300373 i += sizeof(u16);
374
Al Virofa9c13a2008-05-21 00:32:41 -0300375 size = get_unaligned_le16(fw->data + i);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300376 i += sizeof(u16);
377
378 if (pass == 1) {
379 /* Will stall if using fw->data ... */
380 memcpy(buff, fw->data + i, size);
381
382 ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0),
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300383 M9206_FW,
384 USB_TYPE_VENDOR | USB_DIR_OUT,
385 value, index, buff, size, 20);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300386 if (ret != size) {
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300387 deb("error while uploading fw!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300388 ret = -EIO;
389 goto done;
390 }
391 msleep(3);
392 }
393 i += size;
394 }
395 if (i != fw->size) {
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300396 deb("bad firmware file!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300397 ret = -EINVAL;
398 goto done;
399 }
400 }
401
402 msleep(36);
403
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300404 /* m920x will disconnect itself from the bus after this. */
405 (void) m920x_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300406 deb("firmware uploaded!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300407
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300408 done:
Florian Mickler513ea352011-03-21 15:33:45 -0300409 kfree(read);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300410 kfree(buff);
411
412 return ret;
413}
414
Michael Krufkye16c1f52007-01-23 15:00:42 -0300415/* Callbacks for DVB USB */
Aapo Tahkola7d1d4e62007-03-15 13:01:46 -0300416static int m920x_identify_state(struct usb_device *udev,
417 struct dvb_usb_device_properties *props,
418 struct dvb_usb_device_description **desc,
419 int *cold)
Michael Krufkye16c1f52007-01-23 15:00:42 -0300420{
421 struct usb_host_interface *alt;
422
423 alt = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 1);
424 *cold = (alt == NULL) ? 1 : 0;
425
426 return 0;
427}
428
Michael Krufky5afb7072007-03-26 16:35:29 -0300429/* demod configurations */
Michael Krufkye7b419b2007-03-26 16:39:20 -0300430static int m920x_mt352_demod_init(struct dvb_frontend *fe)
Michael Krufkye16c1f52007-01-23 15:00:42 -0300431{
Aapo Tahkolad577ee02007-05-08 18:33:52 -0300432 int ret;
Michael Krufkye16c1f52007-01-23 15:00:42 -0300433 u8 config[] = { CONFIG, 0x3d };
434 u8 clock[] = { CLOCK_CTL, 0x30 };
435 u8 reset[] = { RESET, 0x80 };
436 u8 adc_ctl[] = { ADC_CTL_1, 0x40 };
437 u8 agc[] = { AGC_TARGET, 0x1c, 0x20 };
438 u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 };
439 u8 unk1[] = { 0x93, 0x1a };
440 u8 unk2[] = { 0xb5, 0x7a };
441
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300442 deb("Demod init!\n");
Michael Krufkye16c1f52007-01-23 15:00:42 -0300443
Aapo Tahkolad577ee02007-05-08 18:33:52 -0300444 if ((ret = mt352_write(fe, config, ARRAY_SIZE(config))) != 0)
445 return ret;
446 if ((ret = mt352_write(fe, clock, ARRAY_SIZE(clock))) != 0)
447 return ret;
448 if ((ret = mt352_write(fe, reset, ARRAY_SIZE(reset))) != 0)
449 return ret;
450 if ((ret = mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl))) != 0)
451 return ret;
452 if ((ret = mt352_write(fe, agc, ARRAY_SIZE(agc))) != 0)
453 return ret;
454 if ((ret = mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc))) != 0)
455 return ret;
456 if ((ret = mt352_write(fe, unk1, ARRAY_SIZE(unk1))) != 0)
457 return ret;
458 if ((ret = mt352_write(fe, unk2, ARRAY_SIZE(unk2))) != 0)
459 return ret;
460
Michael Krufkye16c1f52007-01-23 15:00:42 -0300461 return 0;
462}
463
Michael Krufkye7b419b2007-03-26 16:39:20 -0300464static struct mt352_config m920x_mt352_config = {
Aapo Tahkola26247012007-03-05 18:23:19 -0300465 .demod_address = 0x0f,
Michael Krufkye16c1f52007-01-23 15:00:42 -0300466 .no_tuner = 1,
Michael Krufkye7b419b2007-03-26 16:39:20 -0300467 .demod_init = m920x_mt352_demod_init,
Michael Krufkye16c1f52007-01-23 15:00:42 -0300468};
469
Michael Krufkye7b419b2007-03-26 16:39:20 -0300470static struct tda1004x_config m920x_tda10046_08_config = {
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300471 .demod_address = 0x08,
472 .invert = 0,
473 .invert_oclk = 0,
474 .ts_mode = TDA10046_TS_SERIAL,
475 .xtal_freq = TDA10046_XTAL_16M,
476 .if_freq = TDA10046_FREQ_045,
477 .agc_config = TDA10046_AGC_TDA827X,
478 .gpio_config = TDA10046_GPTRI,
479 .request_firmware = NULL,
480};
481
Michael Krufkye7b419b2007-03-26 16:39:20 -0300482static struct tda1004x_config m920x_tda10046_0b_config = {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300483 .demod_address = 0x0b,
484 .invert = 0,
485 .invert_oclk = 0,
486 .ts_mode = TDA10046_TS_SERIAL,
487 .xtal_freq = TDA10046_XTAL_16M,
488 .if_freq = TDA10046_FREQ_045,
489 .agc_config = TDA10046_AGC_TDA827X,
490 .gpio_config = TDA10046_GPTRI,
491 .request_firmware = NULL, /* uses firmware EEPROM */
492};
493
Michael Krufky5afb7072007-03-26 16:35:29 -0300494/* tuner configurations */
Michael Krufkye7b419b2007-03-26 16:39:20 -0300495static struct qt1010_config m920x_qt1010_config = {
Michael Krufky5afb7072007-03-26 16:35:29 -0300496 .i2c_address = 0x62
497};
498
499/* Callbacks for DVB USB */
Michael Krufkye7b419b2007-03-26 16:39:20 -0300500static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300501{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300502 deb("%s\n",__func__);
Michael Krufky5afb7072007-03-26 16:35:29 -0300503
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300504 if ((adap->fe = dvb_attach(mt352_attach,
505 &m920x_mt352_config,
Michael Krufky5afb7072007-03-26 16:35:29 -0300506 &adap->dev->i2c_adap)) == NULL)
507 return -EIO;
508
509 return 0;
510}
511
Michael Krufkye7b419b2007-03-26 16:39:20 -0300512static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300513{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300514 deb("%s\n",__func__);
Nick Andrewaa50ec22007-03-22 17:09:35 -0300515
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300516 if ((adap->fe = dvb_attach(tda10046_attach,
Michael Krufkye7b419b2007-03-26 16:39:20 -0300517 &m920x_tda10046_08_config,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300518 &adap->dev->i2c_adap)) == NULL)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300519 return -EIO;
520
Nick Andrewaa50ec22007-03-22 17:09:35 -0300521 return 0;
522}
523
Michael Krufkye7b419b2007-03-26 16:39:20 -0300524static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300525{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300526 deb("%s\n",__func__);
Nick Andrewaa50ec22007-03-22 17:09:35 -0300527
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300528 if ((adap->fe = dvb_attach(tda10046_attach,
Michael Krufkye7b419b2007-03-26 16:39:20 -0300529 &m920x_tda10046_0b_config,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300530 &adap->dev->i2c_adap)) == NULL)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300531 return -EIO;
532
Nick Andrewaa50ec22007-03-22 17:09:35 -0300533 return 0;
534}
535
Michael Krufkye7b419b2007-03-26 16:39:20 -0300536static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300537{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300538 deb("%s\n",__func__);
Michael Krufkye7b419b2007-03-26 16:39:20 -0300539
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300540 if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL)
Michael Krufky5afb7072007-03-26 16:35:29 -0300541 return -ENODEV;
542
543 return 0;
544}
545
Michael Krufkye7b419b2007-03-26 16:39:20 -0300546static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap)
Michael Krufky5afb7072007-03-26 16:35:29 -0300547{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300548 deb("%s\n",__func__);
Michael Krufkye7b419b2007-03-26 16:39:20 -0300549
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300550 if (dvb_attach(tda827x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL)
Michael Krufky5afb7072007-03-26 16:35:29 -0300551 return -ENODEV;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300552
553 return 0;
554}
555
Michael Krufkye7b419b2007-03-26 16:39:20 -0300556static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300557{
Harvey Harrison708bebd2008-04-08 23:20:00 -0300558 deb("%s\n",__func__);
Nick Andrewaa50ec22007-03-22 17:09:35 -0300559
Aapo Tahkola9ad4eef2007-04-20 13:34:25 -0300560 if (dvb_attach(tda827x_attach, adap->fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300561 return -ENODEV;
562
Nick Andrewaa50ec22007-03-22 17:09:35 -0300563 return 0;
564}
565
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300566static int m920x_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
567{
568 dvb_attach(simple_tuner_attach, adap->fe,
569 &adap->dev->i2c_adap, 0x61,
570 TUNER_PHILIPS_FMD1216ME_MK3);
571 return 0;
572}
573
Michael Krufky5afb7072007-03-26 16:35:29 -0300574/* device-specific initialization */
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300575static struct m920x_inits megasky_rc_init [] = {
Michael Krufky5afb7072007-03-26 16:35:29 -0300576 { M9206_RC_INIT2, 0xa8 },
577 { M9206_RC_INIT1, 0x51 },
578 { } /* terminating entry */
579};
580
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300581static struct m920x_inits tvwalkertwin_rc_init [] = {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300582 { M9206_RC_INIT2, 0x00 },
583 { M9206_RC_INIT1, 0xef },
584 { 0xff28, 0x00 },
585 { 0xff23, 0x00 },
586 { 0xff21, 0x30 },
587 { } /* terminating entry */
588};
589
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300590static struct m920x_inits pinnacle310e_init[] = {
591 /* without these the tuner don't work */
592 { 0xff20, 0x9b },
593 { 0xff22, 0x70 },
594
595 /* rc settings */
596 { 0xff50, 0x80 },
597 { M9206_RC_INIT1, 0x00 },
598 { M9206_RC_INIT2, 0xff },
599 { } /* terminating entry */
600};
601
Michael Krufky5afb7072007-03-26 16:35:29 -0300602/* ir keymaps */
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300603static struct rc_map_table rc_map_megasky_table[] = {
Mauro Carvalho Chehab2e365882009-08-29 15:19:31 -0300604 { 0x0012, KEY_POWER },
605 { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */
606 { 0x0002, KEY_CHANNELUP },
607 { 0x0005, KEY_CHANNELDOWN },
608 { 0x0003, KEY_VOLUMEUP },
609 { 0x0006, KEY_VOLUMEDOWN },
610 { 0x0004, KEY_MUTE },
611 { 0x0007, KEY_OK }, /* TS */
612 { 0x0008, KEY_STOP },
613 { 0x0009, KEY_MENU }, /* swap */
614 { 0x000a, KEY_REWIND },
615 { 0x001b, KEY_PAUSE },
616 { 0x001f, KEY_FASTFORWARD },
617 { 0x000c, KEY_RECORD },
618 { 0x000d, KEY_CAMERA }, /* screenshot */
619 { 0x000e, KEY_COFFEE }, /* "MTS" */
Michael Krufky5afb7072007-03-26 16:35:29 -0300620};
621
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300622static struct rc_map_table rc_map_tvwalkertwin_table[] = {
Mauro Carvalho Chehab2e365882009-08-29 15:19:31 -0300623 { 0x0001, KEY_ZOOM }, /* Full Screen */
624 { 0x0002, KEY_CAMERA }, /* snapshot */
625 { 0x0003, KEY_MUTE },
626 { 0x0004, KEY_REWIND },
627 { 0x0005, KEY_PLAYPAUSE }, /* Play/Pause */
628 { 0x0006, KEY_FASTFORWARD },
629 { 0x0007, KEY_RECORD },
630 { 0x0008, KEY_STOP },
631 { 0x0009, KEY_TIME }, /* Timeshift */
632 { 0x000c, KEY_COFFEE }, /* Recall */
633 { 0x000e, KEY_CHANNELUP },
634 { 0x0012, KEY_POWER },
635 { 0x0015, KEY_MENU }, /* source */
636 { 0x0018, KEY_CYCLEWINDOWS }, /* TWIN PIP */
637 { 0x001a, KEY_CHANNELDOWN },
638 { 0x001b, KEY_VOLUMEDOWN },
639 { 0x001e, KEY_VOLUMEUP },
Michael Krufky5afb7072007-03-26 16:35:29 -0300640};
641
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300642static struct rc_map_table rc_map_pinnacle310e_table[] = {
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300643 { 0x16, KEY_POWER },
644 { 0x17, KEY_FAVORITES },
645 { 0x0f, KEY_TEXT },
Jarod Wilson56c08932011-04-05 18:42:30 -0300646 { 0x48, KEY_PROGRAM }, /* preview */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300647 { 0x1c, KEY_EPG },
Jarod Wilson56c08932011-04-05 18:42:30 -0300648 { 0x04, KEY_LIST }, /* record list */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300649 { 0x03, KEY_1 },
650 { 0x01, KEY_2 },
651 { 0x06, KEY_3 },
652 { 0x09, KEY_4 },
653 { 0x1d, KEY_5 },
654 { 0x1f, KEY_6 },
655 { 0x0d, KEY_7 },
656 { 0x19, KEY_8 },
657 { 0x1b, KEY_9 },
658 { 0x15, KEY_0 },
659 { 0x0c, KEY_CANCEL },
660 { 0x4a, KEY_CLEAR },
661 { 0x13, KEY_BACK },
662 { 0x00, KEY_TAB },
663 { 0x4b, KEY_UP },
664 { 0x4e, KEY_LEFT },
665 { 0x52, KEY_RIGHT },
666 { 0x51, KEY_DOWN },
667 { 0x4f, KEY_ENTER }, /* could also be KEY_OK */
668 { 0x1e, KEY_VOLUMEUP },
669 { 0x0a, KEY_VOLUMEDOWN },
670 { 0x05, KEY_CHANNELUP },
671 { 0x02, KEY_CHANNELDOWN },
672 { 0x11, KEY_RECORD },
673 { 0x14, KEY_PLAY },
674 { 0x4c, KEY_PAUSE },
675 { 0x1a, KEY_STOP },
676 { 0x40, KEY_REWIND },
677 { 0x12, KEY_FASTFORWARD },
678 { 0x41, KEY_PREVIOUSSONG }, /* Replay */
679 { 0x42, KEY_NEXTSONG }, /* Skip */
680 { 0x54, KEY_CAMERA }, /* Capture */
681/* { 0x50, KEY_SAP }, */ /* Sap */
682 { 0x47, KEY_CYCLEWINDOWS }, /* Pip */
683 { 0x4d, KEY_SCREEN }, /* FullScreen */
684 { 0x08, KEY_SUBTITLE },
685 { 0x0e, KEY_MUTE },
686/* { 0x49, KEY_LR }, */ /* L/R */
687 { 0x07, KEY_SLEEP }, /* Hibernate */
Jarod Wilson56c08932011-04-05 18:42:30 -0300688 { 0x08, KEY_VIDEO }, /* A/V */
689 { 0x0e, KEY_MENU }, /* Recall */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300690 { 0x45, KEY_ZOOMIN },
691 { 0x46, KEY_ZOOMOUT },
Jarod Wilson56c08932011-04-05 18:42:30 -0300692 { 0x18, KEY_RED }, /* Red */
693 { 0x53, KEY_GREEN }, /* Green */
694 { 0x5e, KEY_YELLOW }, /* Yellow */
695 { 0x5f, KEY_BLUE }, /* Blue */
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300696};
697
Michael Krufky26f48ea2006-09-28 01:46:49 -0300698/* DVB USB Driver stuff */
699static struct dvb_usb_device_properties megasky_properties;
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300700static struct dvb_usb_device_properties digivox_mini_ii_properties;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300701static struct dvb_usb_device_properties tvwalkertwin_properties;
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300702static struct dvb_usb_device_properties dposh_properties;
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300703static struct dvb_usb_device_properties pinnacle_pctv310e_properties;
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300704
Michael Krufkyfa948052007-01-21 15:57:48 -0300705static int m920x_probe(struct usb_interface *intf,
706 const struct usb_device_id *id)
Michael Krufky26f48ea2006-09-28 01:46:49 -0300707{
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300708 struct dvb_usb_device *d = NULL;
Michael Krufky26f48ea2006-09-28 01:46:49 -0300709 int ret;
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300710 struct m920x_inits *rc_init_seq = NULL;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300711 int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
Michael Krufky26f48ea2006-09-28 01:46:49 -0300712
Aapo Tahkolabf2b4f62007-03-26 16:59:16 -0300713 deb("Probing for m920x device at interface %d\n", bInterfaceNumber);
Michael Krufky26f48ea2006-09-28 01:46:49 -0300714
Nick Andrewaa50ec22007-03-22 17:09:35 -0300715 if (bInterfaceNumber == 0) {
716 /* Single-tuner device, or first interface on
717 * multi-tuner device
718 */
Michael Krufky26f48ea2006-09-28 01:46:49 -0300719
Janne Grunau78e92002008-04-09 19:13:13 -0300720 ret = dvb_usb_device_init(intf, &megasky_properties,
721 THIS_MODULE, &d, adapter_nr);
722 if (ret == 0) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300723 rc_init_seq = megasky_rc_init;
724 goto found;
725 }
726
Janne Grunau78e92002008-04-09 19:13:13 -0300727 ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties,
728 THIS_MODULE, &d, adapter_nr);
729 if (ret == 0) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300730 /* No remote control, so no rc_init_seq */
731 goto found;
732 }
733
734 /* This configures both tuners on the TV Walker Twin */
Janne Grunau78e92002008-04-09 19:13:13 -0300735 ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
736 THIS_MODULE, &d, adapter_nr);
737 if (ret == 0) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300738 rc_init_seq = tvwalkertwin_rc_init;
739 goto found;
740 }
741
Janne Grunau78e92002008-04-09 19:13:13 -0300742 ret = dvb_usb_device_init(intf, &dposh_properties,
743 THIS_MODULE, &d, adapter_nr);
744 if (ret == 0) {
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300745 /* Remote controller not supported yet. */
746 goto found;
747 }
748
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300749 ret = dvb_usb_device_init(intf, &pinnacle_pctv310e_properties,
750 THIS_MODULE, &d, adapter_nr);
751 if (ret == 0) {
752 rc_init_seq = pinnacle310e_init;
753 goto found;
754 }
755
Nick Andrewaa50ec22007-03-22 17:09:35 -0300756 return ret;
757 } else {
758 /* Another interface on a multi-tuner device */
759
760 /* The LifeView TV Walker Twin gets here, but struct
761 * tvwalkertwin_properties already configured both
762 * tuners, so there is nothing for us to do here
763 */
Nick Andrewaa50ec22007-03-22 17:09:35 -0300764 }
Michael Krufky26f48ea2006-09-28 01:46:49 -0300765
Michael Krufkye7b419b2007-03-26 16:39:20 -0300766 found:
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300767 if ((ret = m920x_init_ep(intf)) < 0)
Aapo Tahkola480ac762007-03-05 18:54:27 -0300768 return ret;
769
Aapo Tahkola55bbe5e2007-05-08 12:56:54 -0300770 if (d && (ret = m920x_init(d, rc_init_seq)) != 0)
Aapo Tahkola480ac762007-03-05 18:54:27 -0300771 return ret;
772
Michael Krufky26f48ea2006-09-28 01:46:49 -0300773 return ret;
774}
775
776static struct usb_device_id m920x_table [] = {
777 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300778 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
779 USB_PID_MSI_DIGI_VOX_MINI_II) },
Nick Andrewaa50ec22007-03-22 17:09:35 -0300780 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
781 USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD) },
782 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
783 USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) },
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300784 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
785 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -0300786 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_PINNACLE_PCTV310E) },
Michael Krufky26f48ea2006-09-28 01:46:49 -0300787 { } /* Terminating entry */
788};
789MODULE_DEVICE_TABLE (usb, m920x_table);
790
Michael Krufky01cb34d2006-09-23 20:01:29 -0300791static struct dvb_usb_device_properties megasky_properties = {
Michael Krufky758117c2007-01-23 15:34:10 -0300792 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
Michael Krufky1f61f3b2006-10-07 15:03:04 -0300793
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300794 .usb_ctrl = DEVICE_SPECIFIC,
795 .firmware = "dvb-usb-megasky-02.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300796 .download_firmware = m920x_firmware_download,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300797
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300798 .rc.legacy = {
799 .rc_interval = 100,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300800 .rc_map_table = rc_map_megasky_table,
801 .rc_map_size = ARRAY_SIZE(rc_map_megasky_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300802 .rc_query = m920x_rc_query,
803 },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300804
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300805 .size_of_priv = sizeof(struct m920x_state),
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300806
Aapo Tahkola7d1d4e62007-03-15 13:01:46 -0300807 .identify_state = m920x_identify_state,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300808 .num_adapters = 1,
809 .adapter = {{
Michael Krufky758117c2007-01-23 15:34:10 -0300810 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
811 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
812
Michael Krufky01cb34d2006-09-23 20:01:29 -0300813 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300814 .pid_filter = m920x_pid_filter,
815 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300816
Michael Krufkye7b419b2007-03-26 16:39:20 -0300817 .frontend_attach = m920x_mt352_frontend_attach,
818 .tuner_attach = m920x_qt1010_tuner_attach,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300819
820 .stream = {
821 .type = USB_BULK,
822 .count = 8,
823 .endpoint = 0x81,
824 .u = {
825 .bulk = {
826 .buffersize = 512,
827 }
828 }
829 },
830 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300831 .i2c_algo = &m920x_i2c_algo,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300832
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300833 .num_device_descs = 1,
834 .devices = {
835 { "MSI Mega Sky 580 DVB-T USB2.0",
Michael Krufkybaa2ed02006-09-23 20:01:29 -0300836 { &m920x_table[0], NULL },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300837 { NULL },
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300838 }
839 }
840};
841
842static struct dvb_usb_device_properties digivox_mini_ii_properties = {
843 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
844
845 .usb_ctrl = DEVICE_SPECIFIC,
846 .firmware = "dvb-usb-digivox-02.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300847 .download_firmware = m920x_firmware_download,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300848
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300849 .size_of_priv = sizeof(struct m920x_state),
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300850
851 .identify_state = m920x_identify_state,
852 .num_adapters = 1,
853 .adapter = {{
854 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300855 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300856
857 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300858 .pid_filter = m920x_pid_filter,
859 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300860
Michael Krufkye7b419b2007-03-26 16:39:20 -0300861 .frontend_attach = m920x_tda10046_08_frontend_attach,
862 .tuner_attach = m920x_tda8275_60_tuner_attach,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300863
864 .stream = {
865 .type = USB_BULK,
866 .count = 8,
867 .endpoint = 0x81,
868 .u = {
869 .bulk = {
870 .buffersize = 0x4000,
871 }
872 }
873 },
874 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300875 .i2c_algo = &m920x_i2c_algo,
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300876
877 .num_device_descs = 1,
878 .devices = {
879 { "MSI DIGI VOX mini II DVB-T USB2.0",
880 { &m920x_table[1], NULL },
881 { NULL },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300882 },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300883 }
884};
885
Michael Krufkye7b419b2007-03-26 16:39:20 -0300886/* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net>
887 *
888 * LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A
889 * TDA10046 #0 is located at i2c address 0x08
Aapo Tahkola3ab3b692007-05-08 18:23:38 -0300890 * TDA10046 #1 is located at i2c address 0x0b
Michael Krufkye7b419b2007-03-26 16:39:20 -0300891 * TDA8275A #0 is located at i2c address 0x60
Aapo Tahkola3ab3b692007-05-08 18:23:38 -0300892 * TDA8275A #1 is located at i2c address 0x61
Michael Krufkye7b419b2007-03-26 16:39:20 -0300893 */
Nick Andrewaa50ec22007-03-22 17:09:35 -0300894static struct dvb_usb_device_properties tvwalkertwin_properties = {
895 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
896
897 .usb_ctrl = DEVICE_SPECIFIC,
898 .firmware = "dvb-usb-tvwalkert.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300899 .download_firmware = m920x_firmware_download,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300900
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300901 .rc.legacy = {
902 .rc_interval = 100,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -0300903 .rc_map_table = rc_map_tvwalkertwin_table,
904 .rc_map_size = ARRAY_SIZE(rc_map_tvwalkertwin_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300905 .rc_query = m920x_rc_query,
906 },
Nick Andrewaa50ec22007-03-22 17:09:35 -0300907
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300908 .size_of_priv = sizeof(struct m920x_state),
Nick Andrewaa50ec22007-03-22 17:09:35 -0300909
910 .identify_state = m920x_identify_state,
Aapo Tahkola3ab3b692007-05-08 18:23:38 -0300911 .num_adapters = 2,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300912 .adapter = {{
913 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
914 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300915
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300916 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300917 .pid_filter = m920x_pid_filter,
918 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300919
Michael Krufkye7b419b2007-03-26 16:39:20 -0300920 .frontend_attach = m920x_tda10046_08_frontend_attach,
921 .tuner_attach = m920x_tda8275_60_tuner_attach,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300922
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300923 .stream = {
924 .type = USB_BULK,
925 .count = 8,
926 .endpoint = 0x81,
927 .u = {
928 .bulk = {
929 .buffersize = 512,
930 }
931 }
932 }},{
933 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
934 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
935
936 .pid_filter_count = 8,
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300937 .pid_filter = m920x_pid_filter,
938 .pid_filter_ctrl = m920x_pid_filter_ctrl,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300939
Michael Krufkye7b419b2007-03-26 16:39:20 -0300940 .frontend_attach = m920x_tda10046_0b_frontend_attach,
941 .tuner_attach = m920x_tda8275_61_tuner_attach,
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300942
943 .stream = {
944 .type = USB_BULK,
945 .count = 8,
946 .endpoint = 0x82,
947 .u = {
948 .bulk = {
949 .buffersize = 512,
950 }
951 }
Nick Andrewaa50ec22007-03-22 17:09:35 -0300952 },
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300953 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300954 .i2c_algo = &m920x_i2c_algo,
Nick Andrewaa50ec22007-03-22 17:09:35 -0300955
956 .num_device_descs = 1,
957 .devices = {
958 { .name = "LifeView TV Walker Twin DVB-T USB2.0",
959 .cold_ids = { &m920x_table[2], NULL },
960 .warm_ids = { &m920x_table[3], NULL },
961 },
962 }
963};
964
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300965static struct dvb_usb_device_properties dposh_properties = {
966 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
967
968 .usb_ctrl = DEVICE_SPECIFIC,
969 .firmware = "dvb-usb-dposh-01.fw",
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300970 .download_firmware = m920x_firmware_download,
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300971
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300972 .size_of_priv = sizeof(struct m920x_state),
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300973
974 .identify_state = m920x_identify_state,
975 .num_adapters = 1,
976 .adapter = {{
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300977 /* Hardware pid filters don't work with this device/firmware */
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300978
Michael Krufkye7b419b2007-03-26 16:39:20 -0300979 .frontend_attach = m920x_mt352_frontend_attach,
980 .tuner_attach = m920x_qt1010_tuner_attach,
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300981
Michael Krufkyd3911ea2007-03-22 19:03:37 -0300982 .stream = {
983 .type = USB_BULK,
984 .count = 8,
985 .endpoint = 0x81,
986 .u = {
987 .bulk = {
988 .buffersize = 512,
989 }
990 }
991 },
992 }},
Aapo Tahkola4fd74a72007-03-26 17:05:59 -0300993 .i2c_algo = &m920x_i2c_algo,
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300994
995 .num_device_descs = 1,
996 .devices = {
997 { .name = "Dposh DVB-T USB2.0",
998 .cold_ids = { &m920x_table[4], NULL },
999 .warm_ids = { &m920x_table[5], NULL },
1000 },
1001 }
1002};
1003
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001004static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
1005 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1006
1007 .usb_ctrl = DEVICE_SPECIFIC,
1008 .download_firmware = NULL,
1009
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001010 .rc.legacy = {
1011 .rc_interval = 100,
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001012 .rc_map_table = rc_map_pinnacle310e_table,
1013 .rc_map_size = ARRAY_SIZE(rc_map_pinnacle310e_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001014 .rc_query = m920x_rc_query,
1015 },
Massimo Del Fedele3d36f5c2009-10-24 13:12:37 -03001016
1017 .size_of_priv = sizeof(struct m920x_state),
1018
1019 .identify_state = m920x_identify_state,
1020 .num_adapters = 1,
1021 .adapter = {{
1022 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1023 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1024
1025 .pid_filter_count = 8,
1026 .pid_filter = m920x_pid_filter,
1027 .pid_filter_ctrl = m920x_pid_filter_ctrl,
1028
1029 .frontend_attach = m920x_mt352_frontend_attach,
1030 .tuner_attach = m920x_fmd1216me_tuner_attach,
1031
1032 .stream = {
1033 .type = USB_ISOC,
1034 .count = 5,
1035 .endpoint = 0x84,
1036 .u = {
1037 .isoc = {
1038 .framesperurb = 128,
1039 .framesize = 564,
1040 .interval = 1,
1041 }
1042 }
1043 },
1044 } },
1045 .i2c_algo = &m920x_i2c_algo,
1046
1047 .num_device_descs = 1,
1048 .devices = {
1049 { "Pinnacle PCTV 310e",
1050 { &m920x_table[6], NULL },
1051 { NULL },
1052 }
1053 }
1054};
1055
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001056static struct usb_driver m920x_driver = {
1057 .name = "dvb_usb_m920x",
Michael Krufky2a2bfa72006-09-23 20:13:12 -03001058 .probe = m920x_probe,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001059 .disconnect = dvb_usb_device_exit,
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001060 .id_table = m920x_table,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001061};
1062
1063/* module stuff */
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001064static int __init m920x_module_init(void)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001065{
1066 int ret;
1067
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001068 if ((ret = usb_register(&m920x_driver))) {
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001069 err("usb_register failed. Error number %d", ret);
1070 return ret;
1071 }
1072
1073 return 0;
1074}
1075
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001076static void __exit m920x_module_exit(void)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001077{
1078 /* deregister this driver from the USB subsystem */
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001079 usb_deregister(&m920x_driver);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001080}
1081
Michael Krufkybaa2ed02006-09-23 20:01:29 -03001082module_init (m920x_module_init);
1083module_exit (m920x_module_exit);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001084
1085MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
Nick Andrewaa50ec22007-03-22 17:09:35 -03001086MODULE_DESCRIPTION("DVB Driver for ULI M920x");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001087MODULE_VERSION("0.1");
1088MODULE_LICENSE("GPL");
Michael Krufkyce9c2752007-03-22 17:18:26 -03001089
1090/*
1091 * Local variables:
1092 * c-basic-offset: 8
1093 */