blob: 57af4c17d54f423d6e63bce054d7d293e89ffb4b [file] [log] [blame]
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001/* DVB USB framework compliant Linux driver for the
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03002* DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101,
Igor M. Liplianincd79d332009-12-14 20:24:56 -03003* TeVii S600, S630, S650,
Igor M. Liplianind2ffc442011-02-25 18:41:22 -03004* Prof 1100, 7500,
5 * Geniatech SU3000 Cards
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03006* Copyright (C) 2008,2009 Igor M. Liplianin (liplianin@me.by)
Igor M Liplianin7fd48282008-07-20 08:05:50 -03007*
8* This program is free software; you can redistribute it and/or modify it
9* under the terms of the GNU General Public License as published by the
10* Free Software Foundation, version 2.
11*
12* see Documentation/dvb/README.dvb-usb for more information
13*/
Igor M Liplianin7fd48282008-07-20 08:05:50 -030014#include "dw2102.h"
Igor M. Liplianin21b007b2008-09-17 19:19:19 -030015#include "si21xx.h"
Igor M Liplianin7fd48282008-07-20 08:05:50 -030016#include "stv0299.h"
17#include "z0194a.h"
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -030018#include "stv0288.h"
19#include "stb6000.h"
20#include "eds1547.h"
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -030021#include "cx24116.h"
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -030022#include "tda1002x.h"
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -030023#include "mt312.h"
24#include "zl10039.h"
Igor M. Liplianin141cc352009-11-27 14:37:35 -030025#include "ds3000.h"
26#include "stv0900.h"
27#include "stv6110.h"
28#include "stb6100.h"
29#include "stb6100_proc.h"
Igor M Liplianin7fd48282008-07-20 08:05:50 -030030
31#ifndef USB_PID_DW2102
32#define USB_PID_DW2102 0x2102
33#endif
34
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -030035#ifndef USB_PID_DW2104
36#define USB_PID_DW2104 0x2104
37#endif
38
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -030039#ifndef USB_PID_DW3101
40#define USB_PID_DW3101 0x3101
41#endif
42
Igor M. Liplianin4cc0edf2008-11-05 22:12:56 -030043#ifndef USB_PID_CINERGY_S
44#define USB_PID_CINERGY_S 0x0064
45#endif
46
Igor M. Liplianin141cc352009-11-27 14:37:35 -030047#ifndef USB_PID_TEVII_S630
48#define USB_PID_TEVII_S630 0xd630
49#endif
50
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -030051#ifndef USB_PID_TEVII_S650
52#define USB_PID_TEVII_S650 0xd650
53#endif
54
Igor M. Liplianin141cc352009-11-27 14:37:35 -030055#ifndef USB_PID_TEVII_S660
56#define USB_PID_TEVII_S660 0xd660
57#endif
58
59#ifndef USB_PID_PROF_1100
60#define USB_PID_PROF_1100 0xb012
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -030061#endif
62
Igor M. Liplianin21b007b2008-09-17 19:19:19 -030063#define DW210X_READ_MSG 0
64#define DW210X_WRITE_MSG 1
Igor M Liplianin7fd48282008-07-20 08:05:50 -030065
66#define REG_1F_SYMBOLRATE_BYTE0 0x1f
67#define REG_20_SYMBOLRATE_BYTE1 0x20
68#define REG_21_SYMBOLRATE_BYTE2 0x21
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -030069/* on my own*/
Igor M Liplianin7fd48282008-07-20 08:05:50 -030070#define DW2102_VOLTAGE_CTRL (0x1800)
Igor M. Liplianind2ffc442011-02-25 18:41:22 -030071#define SU3000_STREAM_CTRL (0x1900)
Igor M Liplianin7fd48282008-07-20 08:05:50 -030072#define DW2102_RC_QUERY (0x1a00)
73
Igor M. Liplianin141cc352009-11-27 14:37:35 -030074#define err_str "did not find the firmware file. (%s) " \
75 "Please see linux/Documentation/dvb/ for more details " \
76 "on firmware-problems."
77
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -030078struct rc_map_dvb_usb_table_table {
79 struct rc_map_table *rc_keys;
Igor M. Liplianinb42e1d72009-06-14 19:41:22 -030080 int rc_keys_size;
Igor M Liplianin7fd48282008-07-20 08:05:50 -030081};
82
Igor M. Liplianind2ffc442011-02-25 18:41:22 -030083struct su3000_state {
84 u8 initialized;
85};
86
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -030087/* debug */
88static int dvb_usb_dw2102_debug;
89module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
Igor M. Liplianin8a8dad72009-06-13 08:10:24 -030090MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
91 DVB_USB_DEBUG_STATUS);
92
Igor M. Liplianinb42e1d72009-06-14 19:41:22 -030093/* keymaps */
94static int ir_keymap;
95module_param_named(keymap, ir_keymap, int, 0644);
Igor M. Liplianinfeb16e92011-02-25 18:41:22 -030096MODULE_PARM_DESC(keymap, "set keymap 0=default 1=dvbworld 2=tevii 3=tbs ..."
97 " 256=none");
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -030098
Igor M. Liplianin141cc352009-11-27 14:37:35 -030099/* demod probe */
100static int demod_probe = 1;
101module_param_named(demod, demod_probe, int, 0644);
102MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 "
103 "4=stv0903+stb6100(or-able)).");
104
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300105DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
106
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300107static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300108 u16 index, u8 * data, u16 len, int flags)
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300109{
110 int ret;
111 u8 u8buf[len];
112
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300113 unsigned int pipe = (flags == DW210X_READ_MSG) ?
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300114 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300115 u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300116
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300117 if (flags == DW210X_WRITE_MSG)
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300118 memcpy(u8buf, data, len);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300119 ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
120 value, index , u8buf, len, 2000);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300121
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300122 if (flags == DW210X_READ_MSG)
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300123 memcpy(data, u8buf, len);
124 return ret;
125}
126
127/* I2C */
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300128static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
129 int num)
130{
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -0300131 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300132 int i = 0, ret = 0;
133 u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300134 u16 value;
135
136 if (!d)
137 return -ENODEV;
138 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
139 return -EAGAIN;
140
141 switch (num) {
142 case 2:
143 /* read stv0299 register */
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300144 value = msg[0].buf[0];/* register */
145 for (i = 0; i < msg[1].len; i++) {
146 value = value + i;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300147 ret = dw210x_op_rw(d->udev, 0xb5, value, 0,
148 buf6, 2, DW210X_READ_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300149 msg[1].buf[i] = buf6[0];
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300150 }
151 break;
152 case 1:
153 switch (msg[0].addr) {
154 case 0x68:
155 /* write to stv0299 register */
156 buf6[0] = 0x2a;
157 buf6[1] = msg[0].buf[0];
158 buf6[2] = msg[0].buf[1];
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300159 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
160 buf6, 3, DW210X_WRITE_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300161 break;
162 case 0x60:
163 if (msg[0].flags == 0) {
164 /* write to tuner pll */
165 buf6[0] = 0x2c;
166 buf6[1] = 5;
167 buf6[2] = 0xc0;
168 buf6[3] = msg[0].buf[0];
169 buf6[4] = msg[0].buf[1];
170 buf6[5] = msg[0].buf[2];
171 buf6[6] = msg[0].buf[3];
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300172 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
173 buf6, 7, DW210X_WRITE_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300174 } else {
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300175 /* read from tuner */
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300176 ret = dw210x_op_rw(d->udev, 0xb5, 0, 0,
177 buf6, 1, DW210X_READ_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300178 msg[0].buf[0] = buf6[0];
179 }
180 break;
181 case (DW2102_RC_QUERY):
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300182 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
183 buf6, 2, DW210X_READ_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300184 msg[0].buf[0] = buf6[0];
185 msg[0].buf[1] = buf6[1];
186 break;
187 case (DW2102_VOLTAGE_CTRL):
188 buf6[0] = 0x30;
189 buf6[1] = msg[0].buf[0];
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300190 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
191 buf6, 2, DW210X_WRITE_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300192 break;
193 }
194
195 break;
196 }
197
198 mutex_unlock(&d->i2c_mutex);
199 return num;
200}
201
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300202static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
203 struct i2c_msg msg[], int num)
204{
205 struct dvb_usb_device *d = i2c_get_adapdata(adap);
206 int ret = 0;
207 u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
208
209 if (!d)
210 return -ENODEV;
211 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
212 return -EAGAIN;
213
214 switch (num) {
215 case 2:
216 /* read si2109 register by number */
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300217 buf6[0] = msg[0].addr << 1;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300218 buf6[1] = msg[0].len;
219 buf6[2] = msg[0].buf[0];
220 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
221 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
222 /* read si2109 register */
223 ret = dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
224 buf6, msg[1].len + 2, DW210X_READ_MSG);
225 memcpy(msg[1].buf, buf6 + 2, msg[1].len);
226
227 break;
228 case 1:
229 switch (msg[0].addr) {
230 case 0x68:
231 /* write to si2109 register */
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300232 buf6[0] = msg[0].addr << 1;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300233 buf6[1] = msg[0].len;
234 memcpy(buf6 + 2, msg[0].buf, msg[0].len);
235 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
236 msg[0].len + 2, DW210X_WRITE_MSG);
237 break;
238 case(DW2102_RC_QUERY):
239 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
240 buf6, 2, DW210X_READ_MSG);
241 msg[0].buf[0] = buf6[0];
242 msg[0].buf[1] = buf6[1];
243 break;
244 case(DW2102_VOLTAGE_CTRL):
245 buf6[0] = 0x30;
246 buf6[1] = msg[0].buf[0];
247 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
248 buf6, 2, DW210X_WRITE_MSG);
249 break;
250 }
251 break;
252 }
253
254 mutex_unlock(&d->i2c_mutex);
255 return num;
256}
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -0300257
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -0300258static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
259{
260 struct dvb_usb_device *d = i2c_get_adapdata(adap);
261 int ret = 0;
262
263 if (!d)
264 return -ENODEV;
265 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
266 return -EAGAIN;
267
268 switch (num) {
269 case 2: {
270 /* read */
271 /* first write first register number */
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -0300272 u8 ibuf[msg[1].len + 2], obuf[3];
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300273 obuf[0] = msg[0].addr << 1;
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -0300274 obuf[1] = msg[0].len;
275 obuf[2] = msg[0].buf[0];
276 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
277 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
278 /* second read registers */
279 ret = dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
280 ibuf, msg[1].len + 2, DW210X_READ_MSG);
281 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
282
283 break;
284 }
285 case 1:
286 switch (msg[0].addr) {
287 case 0x68: {
288 /* write to register */
289 u8 obuf[msg[0].len + 2];
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300290 obuf[0] = msg[0].addr << 1;
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -0300291 obuf[1] = msg[0].len;
292 memcpy(obuf + 2, msg[0].buf, msg[0].len);
293 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
294 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
295 break;
296 }
297 case 0x61: {
298 /* write to tuner */
299 u8 obuf[msg[0].len + 2];
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300300 obuf[0] = msg[0].addr << 1;
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -0300301 obuf[1] = msg[0].len;
302 memcpy(obuf + 2, msg[0].buf, msg[0].len);
303 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
304 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
305 break;
306 }
307 case(DW2102_RC_QUERY): {
308 u8 ibuf[2];
309 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
310 ibuf, 2, DW210X_READ_MSG);
311 memcpy(msg[0].buf, ibuf , 2);
312 break;
313 }
314 case(DW2102_VOLTAGE_CTRL): {
315 u8 obuf[2];
316 obuf[0] = 0x30;
317 obuf[1] = msg[0].buf[0];
318 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
319 obuf, 2, DW210X_WRITE_MSG);
320 break;
321 }
322 }
323
324 break;
325 }
326
327 mutex_unlock(&d->i2c_mutex);
328 return num;
329}
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300330
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300331static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
332{
333 struct dvb_usb_device *d = i2c_get_adapdata(adap);
334 int ret = 0;
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300335 int len, i, j;
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300336
337 if (!d)
338 return -ENODEV;
339 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
340 return -EAGAIN;
341
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300342 for (j = 0; j < num; j++) {
343 switch (msg[j].addr) {
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300344 case(DW2102_RC_QUERY): {
345 u8 ibuf[2];
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300346 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
347 ibuf, 2, DW210X_READ_MSG);
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300348 memcpy(msg[j].buf, ibuf , 2);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300349 break;
350 }
351 case(DW2102_VOLTAGE_CTRL): {
352 u8 obuf[2];
353 obuf[0] = 0x30;
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300354 obuf[1] = msg[j].buf[0];
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300355 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
356 obuf, 2, DW210X_WRITE_MSG);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300357 break;
358 }
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300359 /*case 0x55: cx24116
360 case 0x6a: stv0903
361 case 0x68: ds3000, stv0903
362 case 0x60: ts2020, stv6110, stb6100 */
363 default: {
364 if (msg[j].flags == I2C_M_RD) {
365 /* read registers */
366 u8 ibuf[msg[j].len + 2];
367 ret = dw210x_op_rw(d->udev, 0xc3,
368 (msg[j].addr << 1) + 1, 0,
369 ibuf, msg[j].len + 2,
370 DW210X_READ_MSG);
371 memcpy(msg[j].buf, ibuf + 2, msg[j].len);
372 mdelay(10);
373 } else if (((msg[j].buf[0] == 0xb0) &&
374 (msg[j].addr == 0x68)) ||
375 ((msg[j].buf[0] == 0xf7) &&
376 (msg[j].addr == 0x55))) {
377 /* write firmware */
378 u8 obuf[19];
379 obuf[0] = msg[j].addr << 1;
380 obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
381 obuf[2] = msg[j].buf[0];
382 len = msg[j].len - 1;
383 i = 1;
384 do {
385 memcpy(obuf + 3, msg[j].buf + i,
386 (len > 16 ? 16 : len));
387 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
388 obuf, (len > 16 ? 16 : len) + 3,
389 DW210X_WRITE_MSG);
390 i += 16;
391 len -= 16;
392 } while (len > 0);
393 } else {
394 /* write registers */
395 u8 obuf[msg[j].len + 2];
396 obuf[0] = msg[j].addr << 1;
397 obuf[1] = msg[j].len;
398 memcpy(obuf + 2, msg[j].buf, msg[j].len);
399 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
400 obuf, msg[j].len + 2,
401 DW210X_WRITE_MSG);
402 }
403 break;
404 }
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300405 }
406
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300407 }
408
409 mutex_unlock(&d->i2c_mutex);
410 return num;
411}
412
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -0300413static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
414 int num)
415{
416 struct dvb_usb_device *d = i2c_get_adapdata(adap);
417 int ret = 0, i;
418
419 if (!d)
420 return -ENODEV;
421 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
422 return -EAGAIN;
423
424 switch (num) {
425 case 2: {
426 /* read */
427 /* first write first register number */
428 u8 ibuf[msg[1].len + 2], obuf[3];
429 obuf[0] = msg[0].addr << 1;
430 obuf[1] = msg[0].len;
431 obuf[2] = msg[0].buf[0];
432 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
433 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
434 /* second read registers */
435 ret = dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
436 ibuf, msg[1].len + 2, DW210X_READ_MSG);
437 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
438
439 break;
440 }
441 case 1:
442 switch (msg[0].addr) {
443 case 0x60:
444 case 0x0c: {
445 /* write to register */
446 u8 obuf[msg[0].len + 2];
447 obuf[0] = msg[0].addr << 1;
448 obuf[1] = msg[0].len;
449 memcpy(obuf + 2, msg[0].buf, msg[0].len);
450 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
451 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
452 break;
453 }
454 case(DW2102_RC_QUERY): {
455 u8 ibuf[2];
456 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
457 ibuf, 2, DW210X_READ_MSG);
458 memcpy(msg[0].buf, ibuf , 2);
459 break;
460 }
461 }
462
463 break;
464 }
465
466 for (i = 0; i < num; i++) {
467 deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
468 msg[i].flags == 0 ? ">>>" : "<<<");
469 debug_dump(msg[i].buf, msg[i].len, deb_xfer);
470 }
471
472 mutex_unlock(&d->i2c_mutex);
473 return num;
474}
475
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300476static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300477 int num)
478{
479 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Julia Lawall21ead032009-12-22 18:00:07 -0300480 struct usb_device *udev;
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300481 int ret = 0;
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300482 int len, i, j;
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300483
484 if (!d)
485 return -ENODEV;
Julia Lawall21ead032009-12-22 18:00:07 -0300486 udev = d->udev;
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300487 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
488 return -EAGAIN;
489
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300490 for (j = 0; j < num; j++) {
491 switch (msg[j].addr) {
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300492 case (DW2102_RC_QUERY): {
493 u8 ibuf[4];
494 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
495 ibuf, 4, DW210X_READ_MSG);
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300496 memcpy(msg[j].buf, ibuf + 1, 2);
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300497 break;
498 }
499 case (DW2102_VOLTAGE_CTRL): {
500 u8 obuf[2];
Igor M. Liplianincd79d332009-12-14 20:24:56 -0300501
502 obuf[0] = 1;
503 obuf[1] = msg[j].buf[1];/* off-on */
504 ret = dw210x_op_rw(d->udev, 0x8a, 0, 0,
505 obuf, 2, DW210X_WRITE_MSG);
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300506 obuf[0] = 3;
Igor M. Liplianincd79d332009-12-14 20:24:56 -0300507 obuf[1] = msg[j].buf[0];/* 13v-18v */
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300508 ret = dw210x_op_rw(d->udev, 0x8a, 0, 0,
509 obuf, 2, DW210X_WRITE_MSG);
510 break;
511 }
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300512 /*case 0x55: cx24116
513 case 0x6a: stv0903
514 case 0x68: ds3000, stv0903
515 case 0x60: ts2020, stv6110, stb6100
516 case 0xa0: eeprom */
517 default: {
518 if (msg[j].flags == I2C_M_RD) {
519 /* read registers */
520 u8 ibuf[msg[j].len];
521 ret = dw210x_op_rw(d->udev, 0x91, 0, 0,
522 ibuf, msg[j].len,
523 DW210X_READ_MSG);
524 memcpy(msg[j].buf, ibuf, msg[j].len);
525 break;
526 } else if ((msg[j].buf[0] == 0xb0) &&
527 (msg[j].addr == 0x68)) {
528 /* write firmware */
529 u8 obuf[19];
530 obuf[0] = (msg[j].len > 16 ?
531 18 : msg[j].len + 1);
532 obuf[1] = msg[j].addr << 1;
533 obuf[2] = msg[j].buf[0];
534 len = msg[j].len - 1;
535 i = 1;
536 do {
537 memcpy(obuf + 3, msg[j].buf + i,
538 (len > 16 ? 16 : len));
539 ret = dw210x_op_rw(d->udev, 0x80, 0, 0,
540 obuf, (len > 16 ? 16 : len) + 3,
541 DW210X_WRITE_MSG);
542 i += 16;
543 len -= 16;
544 } while (len > 0);
Igor M. Liplianincd79d332009-12-14 20:24:56 -0300545 } else if ((udev->descriptor.idProduct == 0x7500)
546 && (j < (num - 1))) {
547 /* write register addr before read */
548 u8 obuf[msg[j].len + 2];
549 obuf[0] = msg[j + 1].len;
550 obuf[1] = (msg[j].addr << 1);
551 memcpy(obuf + 2, msg[j].buf, msg[j].len);
552 ret = dw210x_op_rw(d->udev, 0x92, 0, 0,
553 obuf, msg[j].len + 2,
554 DW210X_WRITE_MSG);
555 break;
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300556 } else {
557 /* write registers */
558 u8 obuf[msg[j].len + 2];
559 obuf[0] = msg[j].len + 1;
560 obuf[1] = (msg[j].addr << 1);
561 memcpy(obuf + 2, msg[j].buf, msg[j].len);
562 ret = dw210x_op_rw(d->udev,
563 (num > 1 ? 0x90 : 0x80), 0, 0,
564 obuf, msg[j].len + 2,
565 DW210X_WRITE_MSG);
566 break;
567 }
568 break;
569 }
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300570 }
571
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300572 msleep(3);
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300573 }
574
575 mutex_unlock(&d->i2c_mutex);
576 return num;
577}
578
Igor M. Liplianind2ffc442011-02-25 18:41:22 -0300579static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
580 int num)
581{
582 struct dvb_usb_device *d = i2c_get_adapdata(adap);
583 u8 obuf[0x40], ibuf[0x40];
584
585 if (!d)
586 return -ENODEV;
587 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
588 return -EAGAIN;
589
590 switch (num) {
591 case 1:
592 switch (msg[0].addr) {
593 case SU3000_STREAM_CTRL:
594 obuf[0] = msg[0].buf[0] + 0x36;
595 obuf[1] = 3;
596 obuf[2] = 0;
597 if (dvb_usb_generic_rw(d, obuf, 3, ibuf, 0, 0) < 0)
598 err("i2c transfer failed.");
599 break;
600 case DW2102_RC_QUERY:
601 obuf[0] = 0x10;
602 if (dvb_usb_generic_rw(d, obuf, 1, ibuf, 2, 0) < 0)
603 err("i2c transfer failed.");
604 msg[0].buf[1] = ibuf[0];
605 msg[0].buf[0] = ibuf[1];
606 break;
607 default:
608 /* always i2c write*/
609 obuf[0] = 0x08;
610 obuf[1] = msg[0].addr;
611 obuf[2] = msg[0].len;
612
613 memcpy(&obuf[3], msg[0].buf, msg[0].len);
614
615 if (dvb_usb_generic_rw(d, obuf, msg[0].len + 3,
616 ibuf, 1, 0) < 0)
617 err("i2c transfer failed.");
618
619 }
620 break;
621 case 2:
622 /* always i2c read */
623 obuf[0] = 0x09;
624 obuf[1] = msg[0].len;
625 obuf[2] = msg[1].len;
626 obuf[3] = msg[0].addr;
627 memcpy(&obuf[4], msg[0].buf, msg[0].len);
628
629 if (dvb_usb_generic_rw(d, obuf, msg[0].len + 4,
630 ibuf, msg[1].len + 1, 0) < 0)
631 err("i2c transfer failed.");
632
633 memcpy(msg[1].buf, &ibuf[1], msg[1].len);
634 break;
635 default:
636 warn("more than 2 i2c messages at a time is not handled yet.");
637 break;
638 }
639 mutex_unlock(&d->i2c_mutex);
640 return num;
641}
642
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300643static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300644{
645 return I2C_FUNC_I2C;
646}
647
648static struct i2c_algorithm dw2102_i2c_algo = {
649 .master_xfer = dw2102_i2c_transfer,
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300650 .functionality = dw210x_i2c_func,
651};
652
653static struct i2c_algorithm dw2102_serit_i2c_algo = {
654 .master_xfer = dw2102_serit_i2c_transfer,
655 .functionality = dw210x_i2c_func,
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300656};
657
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -0300658static struct i2c_algorithm dw2102_earda_i2c_algo = {
659 .master_xfer = dw2102_earda_i2c_transfer,
660 .functionality = dw210x_i2c_func,
661};
662
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300663static struct i2c_algorithm dw2104_i2c_algo = {
664 .master_xfer = dw2104_i2c_transfer,
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300665 .functionality = dw210x_i2c_func,
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300666};
667
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -0300668static struct i2c_algorithm dw3101_i2c_algo = {
669 .master_xfer = dw3101_i2c_transfer,
670 .functionality = dw210x_i2c_func,
671};
672
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300673static struct i2c_algorithm s6x0_i2c_algo = {
674 .master_xfer = s6x0_i2c_transfer,
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300675 .functionality = dw210x_i2c_func,
676};
677
Igor M. Liplianind2ffc442011-02-25 18:41:22 -0300678static struct i2c_algorithm su3000_i2c_algo = {
679 .master_xfer = su3000_i2c_transfer,
680 .functionality = dw210x_i2c_func,
681};
682
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300683static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300684{
685 int i;
686 u8 ibuf[] = {0, 0};
687 u8 eeprom[256], eepromline[16];
688
689 for (i = 0; i < 256; i++) {
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300690 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300691 err("read eeprom failed.");
692 return -1;
693 } else {
694 eepromline[i%16] = ibuf[0];
695 eeprom[i] = ibuf[0];
696 }
697 if ((i % 16) == 15) {
698 deb_xfer("%02x: ", i - 15);
699 debug_dump(eepromline, 16, deb_xfer);
700 }
701 }
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -0300702
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300703 memcpy(mac, eeprom + 8, 6);
704 return 0;
705};
706
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300707static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300708{
709 int i, ret;
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300710 u8 ibuf[] = { 0 }, obuf[] = { 0 };
711 u8 eeprom[256], eepromline[16];
712 struct i2c_msg msg[] = {
713 {
714 .addr = 0xa0 >> 1,
715 .flags = 0,
716 .buf = obuf,
717 .len = 1,
718 }, {
719 .addr = 0xa0 >> 1,
720 .flags = I2C_M_RD,
721 .buf = ibuf,
722 .len = 1,
723 }
724 };
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300725
726 for (i = 0; i < 256; i++) {
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300727 obuf[0] = i;
728 ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
729 if (ret != 2) {
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300730 err("read eeprom failed.");
731 return -1;
732 } else {
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300733 eepromline[i % 16] = ibuf[0];
734 eeprom[i] = ibuf[0];
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300735 }
736
737 if ((i % 16) == 15) {
738 deb_xfer("%02x: ", i - 15);
739 debug_dump(eepromline, 16, deb_xfer);
740 }
741 }
742
743 memcpy(mac, eeprom + 16, 6);
744 return 0;
745};
746
Igor M. Liplianind2ffc442011-02-25 18:41:22 -0300747static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
748{
749 static u8 command_start[] = {0x00};
750 static u8 command_stop[] = {0x01};
751 struct i2c_msg msg = {
752 .addr = SU3000_STREAM_CTRL,
753 .flags = 0,
754 .buf = onoff ? command_start : command_stop,
755 .len = 1
756 };
757
758 i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
759
760 return 0;
761}
762
763static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
764{
765 struct su3000_state *state = (struct su3000_state *)d->priv;
766 u8 obuf[] = {0xde, 0};
767
768 info("%s: %d, initialized %d\n", __func__, i, state->initialized);
769
770 if (i && !state->initialized) {
771 state->initialized = 1;
772 /* reset board */
773 dvb_usb_generic_rw(d, obuf, 2, NULL, 0, 0);
774 }
775
776 return 0;
777}
778
779static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
780{
781 int i;
782 u8 obuf[] = { 0x1f, 0xf0 };
783 u8 ibuf[] = { 0 };
784 struct i2c_msg msg[] = {
785 {
786 .addr = 0x51,
787 .flags = 0,
788 .buf = obuf,
789 .len = 2,
790 }, {
791 .addr = 0x51,
792 .flags = I2C_M_RD,
793 .buf = ibuf,
794 .len = 1,
795
796 }
797 };
798
799 for (i = 0; i < 6; i++) {
800 obuf[1] = 0xf0 + i;
801 if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
802 break;
803 else
804 mac[i] = ibuf[0];
805
806 debug_dump(mac, 6, printk);
807 }
808
809 return 0;
810}
811
812static int su3000_identify_state(struct usb_device *udev,
813 struct dvb_usb_device_properties *props,
814 struct dvb_usb_device_description **desc,
815 int *cold)
816{
817 info("%s\n", __func__);
818
819 *cold = 0;
820 return 0;
821}
822
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300823static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300824{
Igor M. Liplianincd79d332009-12-14 20:24:56 -0300825 static u8 command_13v[] = {0x00, 0x01};
826 static u8 command_18v[] = {0x01, 0x01};
827 static u8 command_off[] = {0x00, 0x00};
828 struct i2c_msg msg = {
829 .addr = DW2102_VOLTAGE_CTRL,
830 .flags = 0,
831 .buf = command_off,
832 .len = 2,
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300833 };
834
835 struct dvb_usb_adapter *udev_adap =
836 (struct dvb_usb_adapter *)(fe->dvb->priv);
837 if (voltage == SEC_VOLTAGE_18)
Igor M. Liplianincd79d332009-12-14 20:24:56 -0300838 msg.buf = command_18v;
839 else if (voltage == SEC_VOLTAGE_13)
840 msg.buf = command_13v;
841
842 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
843
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300844 return 0;
845}
846
Igor M. Liplianind4305c62008-10-17 13:45:55 -0300847static struct stv0299_config sharp_z0194a_config = {
848 .demod_address = 0x68,
849 .inittab = sharp_z0194a_inittab,
850 .mclk = 88000000UL,
851 .invert = 1,
852 .skip_reinit = 0,
853 .lock_output = STV0299_LOCKOUTPUT_1,
854 .volt13_op0_op1 = STV0299_VOLT13_OP1,
855 .min_delay_ms = 100,
856 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
857};
858
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300859static struct cx24116_config dw2104_config = {
860 .demod_address = 0x55,
Igor M. Liplianincc8c4f32008-09-09 13:57:47 -0300861 .mpg_clk_pos_pol = 0x01,
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300862};
863
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300864static struct si21xx_config serit_sp1511lhb_config = {
865 .demod_address = 0x68,
866 .min_delay_ms = 100,
867
868};
869
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -0300870static struct tda10023_config dw3101_tda10023_config = {
871 .demod_address = 0x0c,
872 .invert = 1,
873};
874
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -0300875static struct mt312_config zl313_config = {
876 .demod_address = 0x0e,
877};
878
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300879static struct ds3000_config dw2104_ds3000_config = {
880 .demod_address = 0x68,
881};
882
883static struct stv0900_config dw2104a_stv0900_config = {
884 .demod_address = 0x6a,
885 .demod_mode = 0,
886 .xtal = 27000000,
887 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
888 .diseqc_mode = 2,/* 2/3 PWM */
889 .tun1_maddress = 0,/* 0x60 */
890 .tun1_adc = 0,/* 2 Vpp */
891 .path1_mode = 3,
892};
893
894static struct stb6100_config dw2104a_stb6100_config = {
895 .tuner_address = 0x60,
896 .refclock = 27000000,
897};
898
899static struct stv0900_config dw2104_stv0900_config = {
900 .demod_address = 0x68,
901 .demod_mode = 0,
902 .xtal = 8000000,
903 .clkmode = 3,
904 .diseqc_mode = 2,
905 .tun1_maddress = 0,
906 .tun1_adc = 1,/* 1 Vpp */
907 .path1_mode = 3,
908};
909
910static struct stv6110_config dw2104_stv6110_config = {
911 .i2c_address = 0x60,
912 .mclk = 16000000,
913 .clk_div = 1,
914};
915
Igor M. Liplianincd79d332009-12-14 20:24:56 -0300916static struct stv0900_config prof_7500_stv0900_config = {
917 .demod_address = 0x6a,
918 .demod_mode = 0,
919 .xtal = 27000000,
920 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
921 .diseqc_mode = 2,/* 2/3 PWM */
922 .tun1_maddress = 0,/* 0x60 */
923 .tun1_adc = 0,/* 2 Vpp */
924 .path1_mode = 3,
925 .tun1_type = 3,
926};
927
Igor M. Liplianind2ffc442011-02-25 18:41:22 -0300928static struct ds3000_config su3000_ds3000_config = {
929 .demod_address = 0x68,
930 .ci_mode = 1,
931};
932
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300933static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
934{
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300935 struct dvb_tuner_ops *tuner_ops = NULL;
936
937 if (demod_probe & 4) {
938 d->fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
939 &d->dev->i2c_adap, 0);
940 if (d->fe != NULL) {
941 if (dvb_attach(stb6100_attach, d->fe,
942 &dw2104a_stb6100_config,
943 &d->dev->i2c_adap)) {
944 tuner_ops = &d->fe->ops.tuner_ops;
945 tuner_ops->set_frequency = stb6100_set_freq;
946 tuner_ops->get_frequency = stb6100_get_freq;
947 tuner_ops->set_bandwidth = stb6100_set_bandw;
948 tuner_ops->get_bandwidth = stb6100_get_bandw;
949 d->fe->ops.set_voltage = dw210x_set_voltage;
950 info("Attached STV0900+STB6100!\n");
951 return 0;
952 }
953 }
954 }
955
956 if (demod_probe & 2) {
957 d->fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
958 &d->dev->i2c_adap, 0);
959 if (d->fe != NULL) {
960 if (dvb_attach(stv6110_attach, d->fe,
961 &dw2104_stv6110_config,
962 &d->dev->i2c_adap)) {
963 d->fe->ops.set_voltage = dw210x_set_voltage;
964 info("Attached STV0900+STV6110A!\n");
965 return 0;
966 }
967 }
968 }
969
970 if (demod_probe & 1) {
971 d->fe = dvb_attach(cx24116_attach, &dw2104_config,
972 &d->dev->i2c_adap);
973 if (d->fe != NULL) {
974 d->fe->ops.set_voltage = dw210x_set_voltage;
975 info("Attached cx24116!\n");
976 return 0;
977 }
978 }
979
980 d->fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
981 &d->dev->i2c_adap);
982 if (d->fe != NULL) {
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300983 d->fe->ops.set_voltage = dw210x_set_voltage;
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300984 info("Attached DS3000!\n");
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300985 return 0;
986 }
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300987
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300988 return -EIO;
989}
990
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300991static struct dvb_usb_device_properties dw2102_properties;
Igor M. Liplianinb42e1d72009-06-14 19:41:22 -0300992static struct dvb_usb_device_properties dw2104_properties;
Igor M. Liplianin141cc352009-11-27 14:37:35 -0300993static struct dvb_usb_device_properties s6x0_properties;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300994
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300995static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
996{
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300997 if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
998 /*dw2102_properties.adapter->tuner_attach = NULL;*/
999 d->fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1000 &d->dev->i2c_adap);
1001 if (d->fe != NULL) {
1002 d->fe->ops.set_voltage = dw210x_set_voltage;
1003 info("Attached si21xx!\n");
1004 return 0;
1005 }
1006 }
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001007
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -03001008 if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -03001009 d->fe = dvb_attach(stv0288_attach, &earda_config,
1010 &d->dev->i2c_adap);
1011 if (d->fe != NULL) {
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001012 if (dvb_attach(stb6000_attach, d->fe, 0x61,
1013 &d->dev->i2c_adap)) {
1014 d->fe->ops.set_voltage = dw210x_set_voltage;
1015 info("Attached stv0288!\n");
1016 return 0;
1017 }
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -03001018 }
1019 }
1020
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001021 if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1022 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1023 d->fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1024 &d->dev->i2c_adap);
1025 if (d->fe != NULL) {
1026 d->fe->ops.set_voltage = dw210x_set_voltage;
1027 info("Attached stv0299!\n");
1028 return 0;
1029 }
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001030 }
1031 return -EIO;
1032}
1033
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03001034static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1035{
1036 d->fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1037 &d->dev->i2c_adap, 0x48);
1038 if (d->fe != NULL) {
1039 info("Attached tda10023!\n");
1040 return 0;
1041 }
1042 return -EIO;
1043}
1044
Igor M. Liplianin195288d2011-02-25 18:41:22 -03001045static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001046{
1047 d->fe = dvb_attach(mt312_attach, &zl313_config,
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001048 &d->dev->i2c_adap);
1049 if (d->fe != NULL) {
1050 if (dvb_attach(zl10039_attach, d->fe, 0x60,
1051 &d->dev->i2c_adap)) {
1052 d->fe->ops.set_voltage = dw210x_set_voltage;
1053 info("Attached zl100313+zl10039!\n");
1054 return 0;
1055 }
1056 }
1057
Igor M. Liplianin195288d2011-02-25 18:41:22 -03001058 return -EIO;
1059}
1060
1061static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1062{
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001063 d->fe = dvb_attach(stv0288_attach, &earda_config,
1064 &d->dev->i2c_adap);
1065 if (d->fe != NULL) {
1066 if (dvb_attach(stb6000_attach, d->fe, 0x61,
1067 &d->dev->i2c_adap)) {
1068 d->fe->ops.set_voltage = dw210x_set_voltage;
1069 info("Attached stv0288+stb6000!\n");
1070 return 0;
1071 }
1072 }
1073
Igor M. Liplianin195288d2011-02-25 18:41:22 -03001074 return -EIO;
1075}
1076
1077static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1078{
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001079 d->fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1080 &d->dev->i2c_adap);
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001081 if (d->fe != NULL) {
1082 d->fe->ops.set_voltage = dw210x_set_voltage;
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001083 info("Attached ds3000+ds2020!\n");
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001084 return 0;
1085 }
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001086
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001087 return -EIO;
1088}
1089
Igor M. Liplianincd79d332009-12-14 20:24:56 -03001090static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1091{
1092 d->fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1093 &d->dev->i2c_adap, 0);
1094 if (d->fe == NULL)
1095 return -EIO;
1096 d->fe->ops.set_voltage = dw210x_set_voltage;
1097
1098 info("Attached STV0900+STB6100A!\n");
1099
1100 return 0;
1101}
1102
Igor M. Liplianind2ffc442011-02-25 18:41:22 -03001103static int su3000_frontend_attach(struct dvb_usb_adapter *d)
1104{
1105 u8 obuf[3] = { 0xe, 0x80, 0 };
1106 u8 ibuf[] = { 0 };
1107
1108 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1109 err("command 0x0e transfer failed.");
1110
1111 obuf[0] = 0xe;
1112 obuf[1] = 0x83;
1113 obuf[2] = 0;
1114
1115 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1116 err("command 0x0e transfer failed.");
1117
1118 obuf[0] = 0xe;
1119 obuf[1] = 0x83;
1120 obuf[2] = 1;
1121
1122 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1123 err("command 0x0e transfer failed.");
1124
1125 obuf[0] = 0x51;
1126
1127 if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
1128 err("command 0x51 transfer failed.");
1129
1130 d->fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1131 &d->dev->i2c_adap);
1132 if (d->fe == NULL)
1133 return -EIO;
1134
1135 info("Attached DS3000!\n");
1136
1137 return 0;
1138}
1139
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001140static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1141{
1142 dvb_attach(dvb_pll_attach, adap->fe, 0x60,
1143 &adap->dev->i2c_adap, DVB_PLL_OPERA1);
1144 return 0;
1145}
1146
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03001147static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1148{
1149 dvb_attach(dvb_pll_attach, adap->fe, 0x60,
1150 &adap->dev->i2c_adap, DVB_PLL_TUA6034);
1151
1152 return 0;
1153}
1154
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001155static struct rc_map_table rc_map_dw210x_table[] = {
Mauro Carvalho Chehab2e365882009-08-29 15:19:31 -03001156 { 0xf80a, KEY_Q }, /*power*/
1157 { 0xf80c, KEY_M }, /*mute*/
1158 { 0xf811, KEY_1 },
1159 { 0xf812, KEY_2 },
1160 { 0xf813, KEY_3 },
1161 { 0xf814, KEY_4 },
1162 { 0xf815, KEY_5 },
1163 { 0xf816, KEY_6 },
1164 { 0xf817, KEY_7 },
1165 { 0xf818, KEY_8 },
1166 { 0xf819, KEY_9 },
1167 { 0xf810, KEY_0 },
1168 { 0xf81c, KEY_PAGEUP }, /*ch+*/
1169 { 0xf80f, KEY_PAGEDOWN }, /*ch-*/
1170 { 0xf81a, KEY_O }, /*vol+*/
1171 { 0xf80e, KEY_Z }, /*vol-*/
1172 { 0xf804, KEY_R }, /*rec*/
1173 { 0xf809, KEY_D }, /*fav*/
1174 { 0xf808, KEY_BACKSPACE }, /*rewind*/
1175 { 0xf807, KEY_A }, /*fast*/
1176 { 0xf80b, KEY_P }, /*pause*/
1177 { 0xf802, KEY_ESC }, /*cancel*/
1178 { 0xf803, KEY_G }, /*tab*/
1179 { 0xf800, KEY_UP }, /*up*/
1180 { 0xf81f, KEY_ENTER }, /*ok*/
1181 { 0xf801, KEY_DOWN }, /*down*/
1182 { 0xf805, KEY_C }, /*cap*/
1183 { 0xf806, KEY_S }, /*stop*/
1184 { 0xf840, KEY_F }, /*full*/
1185 { 0xf81e, KEY_W }, /*tvmode*/
1186 { 0xf81b, KEY_B }, /*recall*/
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001187};
1188
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001189static struct rc_map_table rc_map_tevii_table[] = {
Mauro Carvalho Chehab2e365882009-08-29 15:19:31 -03001190 { 0xf80a, KEY_POWER },
1191 { 0xf80c, KEY_MUTE },
1192 { 0xf811, KEY_1 },
1193 { 0xf812, KEY_2 },
1194 { 0xf813, KEY_3 },
1195 { 0xf814, KEY_4 },
1196 { 0xf815, KEY_5 },
1197 { 0xf816, KEY_6 },
1198 { 0xf817, KEY_7 },
1199 { 0xf818, KEY_8 },
1200 { 0xf819, KEY_9 },
1201 { 0xf810, KEY_0 },
1202 { 0xf81c, KEY_MENU },
1203 { 0xf80f, KEY_VOLUMEDOWN },
1204 { 0xf81a, KEY_LAST },
1205 { 0xf80e, KEY_OPEN },
1206 { 0xf804, KEY_RECORD },
1207 { 0xf809, KEY_VOLUMEUP },
1208 { 0xf808, KEY_CHANNELUP },
1209 { 0xf807, KEY_PVR },
1210 { 0xf80b, KEY_TIME },
1211 { 0xf802, KEY_RIGHT },
1212 { 0xf803, KEY_LEFT },
1213 { 0xf800, KEY_UP },
1214 { 0xf81f, KEY_OK },
1215 { 0xf801, KEY_DOWN },
1216 { 0xf805, KEY_TUNER },
1217 { 0xf806, KEY_CHANNELDOWN },
1218 { 0xf840, KEY_PLAYPAUSE },
1219 { 0xf81e, KEY_REWIND },
1220 { 0xf81b, KEY_FAVORITES },
1221 { 0xf81d, KEY_BACK },
1222 { 0xf84d, KEY_FASTFORWARD },
1223 { 0xf844, KEY_EPG },
1224 { 0xf84c, KEY_INFO },
1225 { 0xf841, KEY_AB },
1226 { 0xf843, KEY_AUDIO },
1227 { 0xf845, KEY_SUBTITLE },
1228 { 0xf84a, KEY_LIST },
1229 { 0xf846, KEY_F1 },
1230 { 0xf847, KEY_F2 },
1231 { 0xf85e, KEY_F3 },
1232 { 0xf85c, KEY_F4 },
1233 { 0xf852, KEY_F5 },
1234 { 0xf85a, KEY_F6 },
1235 { 0xf856, KEY_MODE },
1236 { 0xf858, KEY_SWITCHVIDEOMODE },
Igor M. Liplianinb42e1d72009-06-14 19:41:22 -03001237};
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001238
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001239static struct rc_map_table rc_map_tbs_table[] = {
Mauro Carvalho Chehab2e365882009-08-29 15:19:31 -03001240 { 0xf884, KEY_POWER },
1241 { 0xf894, KEY_MUTE },
1242 { 0xf887, KEY_1 },
1243 { 0xf886, KEY_2 },
1244 { 0xf885, KEY_3 },
1245 { 0xf88b, KEY_4 },
1246 { 0xf88a, KEY_5 },
1247 { 0xf889, KEY_6 },
1248 { 0xf88f, KEY_7 },
1249 { 0xf88e, KEY_8 },
1250 { 0xf88d, KEY_9 },
1251 { 0xf892, KEY_0 },
1252 { 0xf896, KEY_CHANNELUP },
1253 { 0xf891, KEY_CHANNELDOWN },
1254 { 0xf893, KEY_VOLUMEUP },
1255 { 0xf88c, KEY_VOLUMEDOWN },
1256 { 0xf883, KEY_RECORD },
1257 { 0xf898, KEY_PAUSE },
1258 { 0xf899, KEY_OK },
1259 { 0xf89a, KEY_SHUFFLE },
1260 { 0xf881, KEY_UP },
1261 { 0xf890, KEY_LEFT },
1262 { 0xf882, KEY_RIGHT },
1263 { 0xf888, KEY_DOWN },
1264 { 0xf895, KEY_FAVORITES },
1265 { 0xf897, KEY_SUBTITLE },
1266 { 0xf89d, KEY_ZOOM },
1267 { 0xf89f, KEY_EXIT },
1268 { 0xf89e, KEY_MENU },
1269 { 0xf89c, KEY_EPG },
1270 { 0xf880, KEY_PREVIOUS },
1271 { 0xf89b, KEY_MODE }
Igor M. Liplianinb42e1d72009-06-14 19:41:22 -03001272};
1273
Igor M. Liplianind2ffc442011-02-25 18:41:22 -03001274static struct rc_map_table rc_map_su3000_table[] = {
1275 { 0x25, KEY_POWER }, /* right-bottom Red */
1276 { 0x0a, KEY_MUTE }, /* -/-- */
1277 { 0x01, KEY_1 },
1278 { 0x02, KEY_2 },
1279 { 0x03, KEY_3 },
1280 { 0x04, KEY_4 },
1281 { 0x05, KEY_5 },
1282 { 0x06, KEY_6 },
1283 { 0x07, KEY_7 },
1284 { 0x08, KEY_8 },
1285 { 0x09, KEY_9 },
1286 { 0x00, KEY_0 },
1287 { 0x20, KEY_UP }, /* CH+ */
1288 { 0x21, KEY_DOWN }, /* CH+ */
1289 { 0x12, KEY_VOLUMEUP }, /* Brightness Up */
1290 { 0x13, KEY_VOLUMEDOWN },/* Brightness Down */
1291 { 0x1f, KEY_RECORD },
1292 { 0x17, KEY_PLAY },
1293 { 0x16, KEY_PAUSE },
1294 { 0x0b, KEY_STOP },
1295 { 0x27, KEY_FASTFORWARD },/* >> */
1296 { 0x26, KEY_REWIND }, /* << */
1297 { 0x0d, KEY_OK }, /* Mute */
1298 { 0x11, KEY_LEFT }, /* VOL- */
1299 { 0x10, KEY_RIGHT }, /* VOL+ */
1300 { 0x29, KEY_BACK }, /* button under 9 */
1301 { 0x2c, KEY_MENU }, /* TTX */
1302 { 0x2b, KEY_EPG }, /* EPG */
1303 { 0x1e, KEY_RED }, /* OSD */
1304 { 0x0e, KEY_GREEN }, /* Window */
1305 { 0x2d, KEY_YELLOW }, /* button under << */
1306 { 0x0f, KEY_BLUE }, /* bottom yellow button */
1307 { 0x14, KEY_AUDIO }, /* Snapshot */
1308 { 0x38, KEY_TV }, /* TV/Radio */
1309 { 0x0c, KEY_ESC } /* upper Red buttton */
1310};
1311
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001312static struct rc_map_dvb_usb_table_table keys_tables[] = {
1313 { rc_map_dw210x_table, ARRAY_SIZE(rc_map_dw210x_table) },
1314 { rc_map_tevii_table, ARRAY_SIZE(rc_map_tevii_table) },
1315 { rc_map_tbs_table, ARRAY_SIZE(rc_map_tbs_table) },
Igor M. Liplianind2ffc442011-02-25 18:41:22 -03001316 { rc_map_su3000_table, ARRAY_SIZE(rc_map_su3000_table) },
Igor M. Liplianinb42e1d72009-06-14 19:41:22 -03001317};
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001318
1319static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
1320{
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001321 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
1322 int keymap_size = d->props.rc.legacy.rc_map_size;
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001323 u8 key[2];
Igor M. Liplianin8a8dad72009-06-13 08:10:24 -03001324 struct i2c_msg msg = {
1325 .addr = DW2102_RC_QUERY,
1326 .flags = I2C_M_RD,
1327 .buf = key,
1328 .len = 2
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001329 };
1330 int i;
Igor M. Liplianinb42e1d72009-06-14 19:41:22 -03001331 /* override keymap */
1332 if ((ir_keymap > 0) && (ir_keymap <= ARRAY_SIZE(keys_tables))) {
1333 keymap = keys_tables[ir_keymap - 1].rc_keys ;
1334 keymap_size = keys_tables[ir_keymap - 1].rc_keys_size;
Igor M. Liplianinfeb16e92011-02-25 18:41:22 -03001335 } else if (ir_keymap > ARRAY_SIZE(keys_tables))
1336 return 0; /* none */
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001337
1338 *state = REMOTE_NO_KEY_PRESSED;
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001339 if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
Igor M. Liplianinb42e1d72009-06-14 19:41:22 -03001340 for (i = 0; i < keymap_size ; i++) {
Mauro Carvalho Chehab2e365882009-08-29 15:19:31 -03001341 if (rc5_data(&keymap[i]) == msg.buf[0]) {
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001342 *state = REMOTE_KEY_PRESSED;
Mauro Carvalho Chehab34abf212010-07-31 11:24:57 -03001343 *event = keymap[i].keycode;
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001344 break;
1345 }
Igor M. Liplianin8a8dad72009-06-13 08:10:24 -03001346
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001347 }
Igor M. Liplianin8a8dad72009-06-13 08:10:24 -03001348
1349 if ((*state) == REMOTE_KEY_PRESSED)
1350 deb_rc("%s: found rc key: %x, %x, event: %x\n",
1351 __func__, key[0], key[1], (*event));
1352 else if (key[0] != 0xff)
1353 deb_rc("%s: unknown rc key: %x, %x\n",
1354 __func__, key[0], key[1]);
1355
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001356 }
Igor M. Liplianin8a8dad72009-06-13 08:10:24 -03001357
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001358 return 0;
1359}
1360
1361static struct usb_device_id dw2102_table[] = {
1362 {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
1363 {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03001364 {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2104)},
1365 {USB_DEVICE(0x9022, USB_PID_TEVII_S650)},
Igor M. Liplianin4cc0edf2008-11-05 22:12:56 -03001366 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_CINERGY_S)},
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03001367 {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW3101)},
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001368 {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001369 {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1370 {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
Igor M. Liplianincd79d332009-12-14 20:24:56 -03001371 {USB_DEVICE(0x3034, 0x7500)},
Igor M. Liplianind2ffc442011-02-25 18:41:22 -03001372 {USB_DEVICE(0x1f4d, 0x3000)},
Igor M. Liplianin2adc5912011-02-25 18:41:22 -03001373 {USB_DEVICE(USB_VID_TERRATEC, 0x00a8)},
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001374 { }
1375};
1376
1377MODULE_DEVICE_TABLE(usb, dw2102_table);
1378
1379static int dw2102_load_firmware(struct usb_device *dev,
1380 const struct firmware *frmwr)
1381{
1382 u8 *b, *p;
1383 int ret = 0, i;
1384 u8 reset;
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -03001385 u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001386 const struct firmware *fw;
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001387 const char *fw_2101 = "dvb-usb-dw2101.fw";
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001388
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001389 switch (dev->descriptor.idProduct) {
1390 case 0x2101:
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001391 ret = request_firmware(&fw, fw_2101, &dev->dev);
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001392 if (ret != 0) {
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001393 err(err_str, fw_2101);
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001394 return ret;
1395 }
1396 break;
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001397 default:
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001398 fw = frmwr;
1399 break;
1400 }
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001401 info("start downloading DW210X firmware");
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001402 p = kmalloc(fw->size, GFP_KERNEL);
1403 reset = 1;
1404 /*stop the CPU*/
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001405 dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1406 dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001407
1408 if (p != NULL) {
1409 memcpy(p, fw->data, fw->size);
1410 for (i = 0; i < fw->size; i += 0x40) {
1411 b = (u8 *) p + i;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001412 if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
1413 DW210X_WRITE_MSG) != 0x40) {
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001414 err("error while transferring firmware");
1415 ret = -EINVAL;
1416 break;
1417 }
1418 }
1419 /* restart the CPU */
1420 reset = 0;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001421 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1422 DW210X_WRITE_MSG) != 1) {
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001423 err("could not restart the USB controller CPU.");
1424 ret = -EINVAL;
1425 }
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001426 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1427 DW210X_WRITE_MSG) != 1) {
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001428 err("could not restart the USB controller CPU.");
1429 ret = -EINVAL;
1430 }
1431 /* init registers */
1432 switch (dev->descriptor.idProduct) {
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001433 case USB_PID_PROF_1100:
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001434 s6x0_properties.rc.legacy.rc_map_table = rc_map_tbs_table;
1435 s6x0_properties.rc.legacy.rc_map_size =
1436 ARRAY_SIZE(rc_map_tbs_table);
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001437 break;
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03001438 case USB_PID_TEVII_S650:
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001439 dw2104_properties.rc.legacy.rc_map_table = rc_map_tevii_table;
1440 dw2104_properties.rc.legacy.rc_map_size =
1441 ARRAY_SIZE(rc_map_tevii_table);
Igor M. Liplianinb42e1d72009-06-14 19:41:22 -03001442 case USB_PID_DW2104:
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001443 reset = 1;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001444 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1445 DW210X_WRITE_MSG);
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03001446 /* break omitted intentionally */
1447 case USB_PID_DW3101:
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001448 reset = 0;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001449 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1450 DW210X_WRITE_MSG);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001451 break;
Igor M. Liplianin4cc0edf2008-11-05 22:12:56 -03001452 case USB_PID_CINERGY_S:
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001453 case USB_PID_DW2102:
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001454 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1455 DW210X_WRITE_MSG);
1456 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1457 DW210X_READ_MSG);
1458 /* check STV0299 frontend */
1459 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1460 DW210X_READ_MSG);
Igor M. Liplianinea023df2008-12-04 12:49:23 -03001461 if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001462 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -03001463 dw2102_properties.adapter->tuner_attach = &dw2102_tuner_attach;
1464 break;
1465 } else {
1466 /* check STV0288 frontend */
1467 reset16[0] = 0xd0;
1468 reset16[1] = 1;
1469 reset16[2] = 0;
1470 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1471 DW210X_WRITE_MSG);
1472 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1473 DW210X_READ_MSG);
1474 if (reset16[2] == 0x11) {
1475 dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -03001476 break;
1477 }
1478 }
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001479 case 0x2101:
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001480 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1481 DW210X_READ_MSG);
1482 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1483 DW210X_READ_MSG);
1484 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1485 DW210X_READ_MSG);
1486 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1487 DW210X_READ_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001488 break;
1489 }
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03001490
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001491 msleep(100);
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001492 kfree(p);
1493 }
1494 return ret;
1495}
1496
1497static struct dvb_usb_device_properties dw2102_properties = {
1498 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1499 .usb_ctrl = DEVICE_SPECIFIC,
1500 .firmware = "dvb-usb-dw2102.fw",
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001501 .no_reconnect = 1,
1502
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001503 .i2c_algo = &dw2102_serit_i2c_algo,
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001504
1505 .rc.legacy = {
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001506 .rc_map_table = rc_map_dw210x_table,
1507 .rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001508 .rc_interval = 150,
1509 .rc_query = dw2102_rc_query,
1510 },
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001511
1512 .generic_bulk_ctrl_endpoint = 0x81,
1513 /* parameter for the MPEG2-data transfer */
1514 .num_adapters = 1,
1515 .download_firmware = dw2102_load_firmware,
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001516 .read_mac_address = dw210x_read_mac_address,
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03001517 .adapter = {
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001518 {
1519 .frontend_attach = dw2102_frontend_attach,
1520 .streaming_ctrl = NULL,
Igor M. Liplianin8a4949b2008-10-05 09:11:21 -03001521 .tuner_attach = NULL,
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001522 .stream = {
1523 .type = USB_BULK,
1524 .count = 8,
1525 .endpoint = 0x82,
1526 .u = {
1527 .bulk = {
1528 .buffersize = 4096,
1529 }
1530 }
1531 },
1532 }
1533 },
Igor M. Liplianin4cc0edf2008-11-05 22:12:56 -03001534 .num_device_descs = 3,
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001535 .devices = {
1536 {"DVBWorld DVB-S 2102 USB2.0",
1537 {&dw2102_table[0], NULL},
1538 {NULL},
1539 },
1540 {"DVBWorld DVB-S 2101 USB2.0",
1541 {&dw2102_table[1], NULL},
1542 {NULL},
1543 },
Igor M. Liplianin4cc0edf2008-11-05 22:12:56 -03001544 {"TerraTec Cinergy S USB",
1545 {&dw2102_table[4], NULL},
1546 {NULL},
1547 },
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001548 }
1549};
1550
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001551static struct dvb_usb_device_properties dw2104_properties = {
1552 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1553 .usb_ctrl = DEVICE_SPECIFIC,
1554 .firmware = "dvb-usb-dw2104.fw",
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001555 .no_reconnect = 1,
1556
1557 .i2c_algo = &dw2104_i2c_algo,
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001558 .rc.legacy = {
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001559 .rc_map_table = rc_map_dw210x_table,
1560 .rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001561 .rc_interval = 150,
1562 .rc_query = dw2102_rc_query,
1563 },
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001564
1565 .generic_bulk_ctrl_endpoint = 0x81,
1566 /* parameter for the MPEG2-data transfer */
1567 .num_adapters = 1,
1568 .download_firmware = dw2102_load_firmware,
Igor M. Liplianin21b007b2008-09-17 19:19:19 -03001569 .read_mac_address = dw210x_read_mac_address,
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001570 .adapter = {
1571 {
1572 .frontend_attach = dw2104_frontend_attach,
1573 .streaming_ctrl = NULL,
1574 /*.tuner_attach = dw2104_tuner_attach,*/
1575 .stream = {
1576 .type = USB_BULK,
1577 .count = 8,
1578 .endpoint = 0x82,
1579 .u = {
1580 .bulk = {
1581 .buffersize = 4096,
1582 }
1583 }
1584 },
1585 }
1586 },
1587 .num_device_descs = 2,
1588 .devices = {
1589 { "DVBWorld DW2104 USB2.0",
1590 {&dw2102_table[2], NULL},
1591 {NULL},
1592 },
1593 { "TeVii S650 USB2.0",
1594 {&dw2102_table[3], NULL},
1595 {NULL},
1596 },
1597 }
1598};
1599
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03001600static struct dvb_usb_device_properties dw3101_properties = {
1601 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1602 .usb_ctrl = DEVICE_SPECIFIC,
1603 .firmware = "dvb-usb-dw3101.fw",
1604 .no_reconnect = 1,
1605
1606 .i2c_algo = &dw3101_i2c_algo,
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001607 .rc.legacy = {
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001608 .rc_map_table = rc_map_dw210x_table,
1609 .rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001610 .rc_interval = 150,
1611 .rc_query = dw2102_rc_query,
1612 },
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03001613
1614 .generic_bulk_ctrl_endpoint = 0x81,
1615 /* parameter for the MPEG2-data transfer */
1616 .num_adapters = 1,
1617 .download_firmware = dw2102_load_firmware,
1618 .read_mac_address = dw210x_read_mac_address,
1619 .adapter = {
1620 {
1621 .frontend_attach = dw3101_frontend_attach,
1622 .streaming_ctrl = NULL,
1623 .tuner_attach = dw3101_tuner_attach,
1624 .stream = {
1625 .type = USB_BULK,
1626 .count = 8,
1627 .endpoint = 0x82,
1628 .u = {
1629 .bulk = {
1630 .buffersize = 4096,
1631 }
1632 }
1633 },
1634 }
1635 },
1636 .num_device_descs = 1,
1637 .devices = {
1638 { "DVBWorld DVB-C 3101 USB2.0",
1639 {&dw2102_table[5], NULL},
1640 {NULL},
1641 },
1642 }
1643};
1644
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001645static struct dvb_usb_device_properties s6x0_properties = {
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001646 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1647 .usb_ctrl = DEVICE_SPECIFIC,
1648 .firmware = "dvb-usb-s630.fw",
1649 .no_reconnect = 1,
1650
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001651 .i2c_algo = &s6x0_i2c_algo,
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001652 .rc.legacy = {
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001653 .rc_map_table = rc_map_tevii_table,
1654 .rc_map_size = ARRAY_SIZE(rc_map_tevii_table),
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001655 .rc_interval = 150,
1656 .rc_query = dw2102_rc_query,
1657 },
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001658
1659 .generic_bulk_ctrl_endpoint = 0x81,
1660 .num_adapters = 1,
1661 .download_firmware = dw2102_load_firmware,
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001662 .read_mac_address = s6x0_read_mac_address,
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001663 .adapter = {
1664 {
Igor M. Liplianin195288d2011-02-25 18:41:22 -03001665 .frontend_attach = zl100313_frontend_attach,
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001666 .streaming_ctrl = NULL,
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001667 .tuner_attach = NULL,
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001668 .stream = {
1669 .type = USB_BULK,
1670 .count = 8,
1671 .endpoint = 0x82,
1672 .u = {
1673 .bulk = {
1674 .buffersize = 4096,
1675 }
1676 }
1677 },
1678 }
1679 },
Igor M. Liplianin195288d2011-02-25 18:41:22 -03001680 .num_device_descs = 1,
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001681 .devices = {
1682 {"TeVii S630 USB",
1683 {&dw2102_table[6], NULL},
1684 {NULL},
1685 },
1686 }
1687};
1688
Igor M. Liplianin195288d2011-02-25 18:41:22 -03001689struct dvb_usb_device_properties *p1100;
1690static struct dvb_usb_device_description d1100 = {
1691 "Prof 1100 USB ",
1692 {&dw2102_table[7], NULL},
1693 {NULL},
1694};
1695
1696struct dvb_usb_device_properties *s660;
1697static struct dvb_usb_device_description d660 = {
1698 "TeVii S660 USB",
1699 {&dw2102_table[8], NULL},
1700 {NULL},
1701};
1702
Igor M. Liplianincd79d332009-12-14 20:24:56 -03001703struct dvb_usb_device_properties *p7500;
1704static struct dvb_usb_device_description d7500 = {
1705 "Prof 7500 USB DVB-S2",
1706 {&dw2102_table[9], NULL},
1707 {NULL},
1708};
1709
Igor M. Liplianind2ffc442011-02-25 18:41:22 -03001710static struct dvb_usb_device_properties su3000_properties = {
1711 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1712 .usb_ctrl = DEVICE_SPECIFIC,
1713 .size_of_priv = sizeof(struct su3000_state),
1714 .power_ctrl = su3000_power_ctrl,
1715 .num_adapters = 1,
1716 .identify_state = su3000_identify_state,
1717 .i2c_algo = &su3000_i2c_algo,
1718
1719 .rc.legacy = {
1720 .rc_map_table = rc_map_su3000_table,
1721 .rc_map_size = ARRAY_SIZE(rc_map_su3000_table),
1722 .rc_interval = 150,
1723 .rc_query = dw2102_rc_query,
1724 },
1725
1726 .read_mac_address = su3000_read_mac_address,
1727
1728 .generic_bulk_ctrl_endpoint = 0x01,
1729
1730 .adapter = {
1731 {
1732 .streaming_ctrl = su3000_streaming_ctrl,
1733 .frontend_attach = su3000_frontend_attach,
1734 .stream = {
1735 .type = USB_BULK,
1736 .count = 8,
1737 .endpoint = 0x82,
1738 .u = {
1739 .bulk = {
1740 .buffersize = 4096,
1741 }
1742 }
1743 }
1744 }
1745 },
Igor M. Liplianin2adc5912011-02-25 18:41:22 -03001746 .num_device_descs = 2,
Igor M. Liplianind2ffc442011-02-25 18:41:22 -03001747 .devices = {
1748 { "SU3000HD DVB-S USB2.0",
1749 { &dw2102_table[10], NULL },
1750 { NULL },
1751 },
Igor M. Liplianin2adc5912011-02-25 18:41:22 -03001752 { "Terratec Cinergy S2 USB HD",
1753 { &dw2102_table[11], NULL },
1754 { NULL },
1755 },
Igor M. Liplianind2ffc442011-02-25 18:41:22 -03001756 }
1757};
1758
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001759static int dw2102_probe(struct usb_interface *intf,
1760 const struct usb_device_id *id)
1761{
Igor M. Liplianin195288d2011-02-25 18:41:22 -03001762 p1100 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
1763 if (!p1100)
Igor M. Liplianincd79d332009-12-14 20:24:56 -03001764 return -ENOMEM;
1765 /* copy default structure */
Igor M. Liplianin195288d2011-02-25 18:41:22 -03001766 memcpy(p1100, &s6x0_properties,
Igor M. Liplianincd79d332009-12-14 20:24:56 -03001767 sizeof(struct dvb_usb_device_properties));
1768 /* fill only different fields */
Igor M. Liplianin195288d2011-02-25 18:41:22 -03001769 p1100->firmware = "dvb-usb-p1100.fw";
1770 p1100->devices[0] = d1100;
1771 p1100->rc.legacy.rc_map_table = rc_map_tbs_table;
1772 p1100->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
1773 p1100->adapter->frontend_attach = stv0288_frontend_attach;
1774
1775 s660 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
1776 if (!s660) {
1777 kfree(p1100);
1778 return -ENOMEM;
1779 }
1780 memcpy(s660, &s6x0_properties,
1781 sizeof(struct dvb_usb_device_properties));
1782 s660->firmware = "dvb-usb-s660.fw";
1783 s660->devices[0] = d660;
1784 s660->adapter->frontend_attach = ds3000_frontend_attach;
1785
1786 p7500 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
1787 if (!p7500) {
1788 kfree(p1100);
1789 kfree(s660);
1790 return -ENOMEM;
1791 }
1792 memcpy(p7500, &s6x0_properties,
1793 sizeof(struct dvb_usb_device_properties));
Igor M. Liplianincd79d332009-12-14 20:24:56 -03001794 p7500->firmware = "dvb-usb-p7500.fw";
1795 p7500->devices[0] = d7500;
Mauro Carvalho Chehab2f4f58d2010-11-17 15:46:09 -03001796 p7500->rc.legacy.rc_map_table = rc_map_tbs_table;
1797 p7500->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
Igor M. Liplianincd79d332009-12-14 20:24:56 -03001798 p7500->adapter->frontend_attach = prof_7500_frontend_attach;
1799
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001800 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
1801 THIS_MODULE, NULL, adapter_nr) ||
1802 0 == dvb_usb_device_init(intf, &dw2104_properties,
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03001803 THIS_MODULE, NULL, adapter_nr) ||
1804 0 == dvb_usb_device_init(intf, &dw3101_properties,
Igor M. Liplianind0a1dda2009-06-20 09:54:18 -03001805 THIS_MODULE, NULL, adapter_nr) ||
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001806 0 == dvb_usb_device_init(intf, &s6x0_properties,
Igor M. Liplianincd79d332009-12-14 20:24:56 -03001807 THIS_MODULE, NULL, adapter_nr) ||
Igor M. Liplianin195288d2011-02-25 18:41:22 -03001808 0 == dvb_usb_device_init(intf, p1100,
1809 THIS_MODULE, NULL, adapter_nr) ||
1810 0 == dvb_usb_device_init(intf, s660,
1811 THIS_MODULE, NULL, adapter_nr) ||
Igor M. Liplianincd79d332009-12-14 20:24:56 -03001812 0 == dvb_usb_device_init(intf, p7500,
Igor M. Liplianind2ffc442011-02-25 18:41:22 -03001813 THIS_MODULE, NULL, adapter_nr) ||
1814 0 == dvb_usb_device_init(intf, &su3000_properties,
1815 THIS_MODULE, NULL, adapter_nr))
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001816 return 0;
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001817
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001818 return -ENODEV;
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001819}
1820
1821static struct usb_driver dw2102_driver = {
1822 .name = "dw2102",
1823 .probe = dw2102_probe,
1824 .disconnect = dvb_usb_device_exit,
1825 .id_table = dw2102_table,
1826};
1827
1828static int __init dw2102_module_init(void)
1829{
1830 int ret = usb_register(&dw2102_driver);
1831 if (ret)
1832 err("usb_register failed. Error number %d", ret);
1833
1834 return ret;
1835}
1836
1837static void __exit dw2102_module_exit(void)
1838{
1839 usb_deregister(&dw2102_driver);
1840}
1841
1842module_init(dw2102_module_init);
1843module_exit(dw2102_module_exit);
1844
1845MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
Igor M. Liplianin1dac77c2009-06-14 20:51:45 -03001846MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104,"
1847 " DVB-C 3101 USB2.0,"
Igor M. Liplianin141cc352009-11-27 14:37:35 -03001848 " TeVii S600, S630, S650, S660 USB2.0,"
Igor M. Liplianind2ffc442011-02-25 18:41:22 -03001849 " Prof 1100, 7500 USB2.0,"
1850 " Geniatech SU3000 devices");
Igor M Liplianin7fd48282008-07-20 08:05:50 -03001851MODULE_VERSION("0.1");
1852MODULE_LICENSE("GPL");