blob: 20ba3f12900121f96f902a427d263d0421b3200c [file] [log] [blame]
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -03001/* DVB USB framework compliant Linux driver for the
2* DVBWorld DVB-S 2101, 2102, DVB-S2 2104 Card
Igor M Liplianin7fd48282008-07-20 08:05:50 -03003*
4* Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
5*
6* This program is free software; you can redistribute it and/or modify it
7* under the terms of the GNU General Public License as published by the
8* Free Software Foundation, version 2.
9*
10* see Documentation/dvb/README.dvb-usb for more information
11*/
12#include <linux/version.h>
13#include "dw2102.h"
Igor M. Liplianin21b007b2008-09-17 19:19:19 -030014#include "si21xx.h"
Igor M Liplianin7fd48282008-07-20 08:05:50 -030015#include "stv0299.h"
16#include "z0194a.h"
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -030017#include "cx24116.h"
Igor M Liplianin7fd48282008-07-20 08:05:50 -030018
19#ifndef USB_PID_DW2102
20#define USB_PID_DW2102 0x2102
21#endif
22
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -030023#ifndef USB_PID_DW2104
24#define USB_PID_DW2104 0x2104
25#endif
26
Igor M. Liplianin21b007b2008-09-17 19:19:19 -030027#define DW210X_READ_MSG 0
28#define DW210X_WRITE_MSG 1
Igor M Liplianin7fd48282008-07-20 08:05:50 -030029
30#define REG_1F_SYMBOLRATE_BYTE0 0x1f
31#define REG_20_SYMBOLRATE_BYTE1 0x20
32#define REG_21_SYMBOLRATE_BYTE2 0x21
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -030033/* on my own*/
Igor M Liplianin7fd48282008-07-20 08:05:50 -030034#define DW2102_VOLTAGE_CTRL (0x1800)
35#define DW2102_RC_QUERY (0x1a00)
36
Igor M. Liplianin21b007b2008-09-17 19:19:19 -030037struct dw210x_state {
Igor M Liplianin7fd48282008-07-20 08:05:50 -030038 u32 last_key_pressed;
39};
Igor M. Liplianin21b007b2008-09-17 19:19:19 -030040struct dw210x_rc_keys {
Igor M Liplianin7fd48282008-07-20 08:05:50 -030041 u32 keycode;
42 u32 event;
43};
44
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -030045/* debug */
46static int dvb_usb_dw2102_debug;
47module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
48MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer (or-able))." DVB_USB_DEBUG_STATUS);
49
Igor M Liplianin7fd48282008-07-20 08:05:50 -030050DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
51
Igor M. Liplianin21b007b2008-09-17 19:19:19 -030052static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -030053 u16 index, u8 * data, u16 len, int flags)
Igor M Liplianin7fd48282008-07-20 08:05:50 -030054{
55 int ret;
56 u8 u8buf[len];
57
Igor M. Liplianin21b007b2008-09-17 19:19:19 -030058 unsigned int pipe = (flags == DW210X_READ_MSG) ?
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -030059 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
Igor M. Liplianin21b007b2008-09-17 19:19:19 -030060 u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
Igor M Liplianin7fd48282008-07-20 08:05:50 -030061
Igor M. Liplianin21b007b2008-09-17 19:19:19 -030062 if (flags == DW210X_WRITE_MSG)
Igor M Liplianin7fd48282008-07-20 08:05:50 -030063 memcpy(u8buf, data, len);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -030064 ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
65 value, index , u8buf, len, 2000);
Igor M Liplianin7fd48282008-07-20 08:05:50 -030066
Igor M. Liplianin21b007b2008-09-17 19:19:19 -030067 if (flags == DW210X_READ_MSG)
Igor M Liplianin7fd48282008-07-20 08:05:50 -030068 memcpy(data, u8buf, len);
69 return ret;
70}
71
72/* I2C */
Igor M Liplianin7fd48282008-07-20 08:05:50 -030073static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
74 int num)
75{
76struct dvb_usb_device *d = i2c_get_adapdata(adap);
77 int i = 0, ret = 0;
78 u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
Igor M Liplianin7fd48282008-07-20 08:05:50 -030079 u16 value;
80
81 if (!d)
82 return -ENODEV;
83 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
84 return -EAGAIN;
85
86 switch (num) {
87 case 2:
88 /* read stv0299 register */
Igor M Liplianin7fd48282008-07-20 08:05:50 -030089 value = msg[0].buf[0];/* register */
90 for (i = 0; i < msg[1].len; i++) {
91 value = value + i;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -030092 ret = dw210x_op_rw(d->udev, 0xb5, value, 0,
93 buf6, 2, DW210X_READ_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -030094 msg[1].buf[i] = buf6[0];
Igor M Liplianin7fd48282008-07-20 08:05:50 -030095 }
96 break;
97 case 1:
98 switch (msg[0].addr) {
99 case 0x68:
100 /* write to stv0299 register */
101 buf6[0] = 0x2a;
102 buf6[1] = msg[0].buf[0];
103 buf6[2] = msg[0].buf[1];
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300104 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
105 buf6, 3, DW210X_WRITE_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300106 break;
107 case 0x60:
108 if (msg[0].flags == 0) {
109 /* write to tuner pll */
110 buf6[0] = 0x2c;
111 buf6[1] = 5;
112 buf6[2] = 0xc0;
113 buf6[3] = msg[0].buf[0];
114 buf6[4] = msg[0].buf[1];
115 buf6[5] = msg[0].buf[2];
116 buf6[6] = msg[0].buf[3];
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300117 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
118 buf6, 7, DW210X_WRITE_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300119 } else {
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300120 /* read from tuner */
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300121 ret = dw210x_op_rw(d->udev, 0xb5, 0, 0,
122 buf6, 1, DW210X_READ_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300123 msg[0].buf[0] = buf6[0];
124 }
125 break;
126 case (DW2102_RC_QUERY):
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300127 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
128 buf6, 2, DW210X_READ_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300129 msg[0].buf[0] = buf6[0];
130 msg[0].buf[1] = buf6[1];
131 break;
132 case (DW2102_VOLTAGE_CTRL):
133 buf6[0] = 0x30;
134 buf6[1] = msg[0].buf[0];
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300135 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
136 buf6, 2, DW210X_WRITE_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300137 break;
138 }
139
140 break;
141 }
142
143 mutex_unlock(&d->i2c_mutex);
144 return num;
145}
146
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300147static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
148 struct i2c_msg msg[], int num)
149{
150 struct dvb_usb_device *d = i2c_get_adapdata(adap);
151 int ret = 0;
152 u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
153
154 if (!d)
155 return -ENODEV;
156 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
157 return -EAGAIN;
158
159 switch (num) {
160 case 2:
161 /* read si2109 register by number */
162 buf6[0] = 0xd0;
163 buf6[1] = msg[0].len;
164 buf6[2] = msg[0].buf[0];
165 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
166 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
167 /* read si2109 register */
168 ret = dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
169 buf6, msg[1].len + 2, DW210X_READ_MSG);
170 memcpy(msg[1].buf, buf6 + 2, msg[1].len);
171
172 break;
173 case 1:
174 switch (msg[0].addr) {
175 case 0x68:
176 /* write to si2109 register */
177 buf6[0] = 0xd0;
178 buf6[1] = msg[0].len;
179 memcpy(buf6 + 2, msg[0].buf, msg[0].len);
180 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
181 msg[0].len + 2, DW210X_WRITE_MSG);
182 break;
183 case(DW2102_RC_QUERY):
184 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
185 buf6, 2, DW210X_READ_MSG);
186 msg[0].buf[0] = buf6[0];
187 msg[0].buf[1] = buf6[1];
188 break;
189 case(DW2102_VOLTAGE_CTRL):
190 buf6[0] = 0x30;
191 buf6[1] = msg[0].buf[0];
192 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
193 buf6, 2, DW210X_WRITE_MSG);
194 break;
195 }
196 break;
197 }
198
199 mutex_unlock(&d->i2c_mutex);
200 return num;
201}
202
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300203static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
204{
205 struct dvb_usb_device *d = i2c_get_adapdata(adap);
206 int ret = 0;
207 int len, i;
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 */
217 /* first write first register number */
218 u8 ibuf [msg[1].len + 2], obuf[3];
219 obuf[0] = 0xaa;
220 obuf[1] = msg[0].len;
221 obuf[2] = msg[0].buf[0];
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300222 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
223 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300224 /* second read registers */
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300225 ret = dw210x_op_rw(d->udev, 0xc3, 0xab , 0,
226 ibuf, msg[1].len + 2, DW210X_READ_MSG);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300227 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
228
229 break;
230 }
231 case 1:
232 switch (msg[0].addr) {
233 case 0x55: {
234 if (msg[0].buf[0] == 0xf7) {
235 /* firmware */
236 /* Write in small blocks */
237 u8 obuf[19];
238 obuf[0] = 0xaa;
239 obuf[1] = 0x11;
240 obuf[2] = 0xf7;
241 len = msg[0].len - 1;
242 i = 1;
243 do {
244 memcpy(obuf + 3, msg[0].buf + i, (len > 16 ? 16 : len));
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300245 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
246 obuf, (len > 16 ? 16 : len) + 3, DW210X_WRITE_MSG);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300247 i += 16;
248 len -= 16;
249 } while (len > 0);
250 } else {
251 /* write to register */
252 u8 obuf[msg[0].len + 2];
253 obuf[0] = 0xaa;
254 obuf[1] = msg[0].len;
255 memcpy(obuf + 2, msg[0].buf, msg[0].len);
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300256 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
257 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300258 }
259 break;
260 }
261 case(DW2102_RC_QUERY): {
262 u8 ibuf[2];
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300263 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
264 ibuf, 2, DW210X_READ_MSG);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300265 memcpy(msg[0].buf, ibuf , 2);
266 break;
267 }
268 case(DW2102_VOLTAGE_CTRL): {
269 u8 obuf[2];
270 obuf[0] = 0x30;
271 obuf[1] = msg[0].buf[0];
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300272 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
273 obuf, 2, DW210X_WRITE_MSG);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300274 break;
275 }
276 }
277
278 break;
279 }
280
281 mutex_unlock(&d->i2c_mutex);
282 return num;
283}
284
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300285static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300286{
287 return I2C_FUNC_I2C;
288}
289
290static struct i2c_algorithm dw2102_i2c_algo = {
291 .master_xfer = dw2102_i2c_transfer,
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300292 .functionality = dw210x_i2c_func,
293};
294
295static struct i2c_algorithm dw2102_serit_i2c_algo = {
296 .master_xfer = dw2102_serit_i2c_transfer,
297 .functionality = dw210x_i2c_func,
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300298};
299
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300300static struct i2c_algorithm dw2104_i2c_algo = {
301 .master_xfer = dw2104_i2c_transfer,
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300302 .functionality = dw210x_i2c_func,
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300303};
304
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300305static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300306{
307 int i;
308 u8 ibuf[] = {0, 0};
309 u8 eeprom[256], eepromline[16];
310
311 for (i = 0; i < 256; i++) {
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300312 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300313 err("read eeprom failed.");
314 return -1;
315 } else {
316 eepromline[i%16] = ibuf[0];
317 eeprom[i] = ibuf[0];
318 }
319 if ((i % 16) == 15) {
320 deb_xfer("%02x: ", i - 15);
321 debug_dump(eepromline, 16, deb_xfer);
322 }
323 }
324 memcpy(mac, eeprom + 8, 6);
325 return 0;
326};
327
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300328static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300329{
330 static u8 command_13v[1] = {0x00};
331 static u8 command_18v[1] = {0x01};
332 struct i2c_msg msg[] = {
333 {.addr = DW2102_VOLTAGE_CTRL, .flags = 0,
334 .buf = command_13v, .len = 1},
335 };
336
337 struct dvb_usb_adapter *udev_adap =
338 (struct dvb_usb_adapter *)(fe->dvb->priv);
339 if (voltage == SEC_VOLTAGE_18)
340 msg[0].buf = command_18v;
341 i2c_transfer(&udev_adap->dev->i2c_adap, msg, 1);
342 return 0;
343}
344
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300345static struct cx24116_config dw2104_config = {
346 .demod_address = 0x55,
Igor M. Liplianincc8c4f32008-09-09 13:57:47 -0300347 .mpg_clk_pos_pol = 0x01,
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300348};
349
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300350static struct si21xx_config serit_sp1511lhb_config = {
351 .demod_address = 0x68,
352 .min_delay_ms = 100,
353
354};
355
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300356static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
357{
358 if ((d->fe = dvb_attach(cx24116_attach, &dw2104_config,
359 &d->dev->i2c_adap)) != NULL) {
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300360 d->fe->ops.set_voltage = dw210x_set_voltage;
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300361 info("Attached cx24116!\n");
362 return 0;
363 }
364 return -EIO;
365}
366
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300367static struct dvb_usb_device_properties dw2102_properties;
368
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300369static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
370{
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300371 if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
372 /*dw2102_properties.adapter->tuner_attach = NULL;*/
373 d->fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
374 &d->dev->i2c_adap);
375 if (d->fe != NULL) {
376 d->fe->ops.set_voltage = dw210x_set_voltage;
377 info("Attached si21xx!\n");
378 return 0;
379 }
380 }
381 if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
382 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
383 d->fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
384 &d->dev->i2c_adap);
385 if (d->fe != NULL) {
386 d->fe->ops.set_voltage = dw210x_set_voltage;
387 info("Attached stv0299!\n");
388 return 0;
389 }
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300390 }
391 return -EIO;
392}
393
394static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
395{
396 dvb_attach(dvb_pll_attach, adap->fe, 0x60,
397 &adap->dev->i2c_adap, DVB_PLL_OPERA1);
398 return 0;
399}
400
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300401static struct dvb_usb_rc_key dw210x_rc_keys[] = {
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300402 { 0xf8, 0x0a, KEY_Q }, /*power*/
403 { 0xf8, 0x0c, KEY_M }, /*mute*/
404 { 0xf8, 0x11, KEY_1 },
405 { 0xf8, 0x12, KEY_2 },
406 { 0xf8, 0x13, KEY_3 },
407 { 0xf8, 0x14, KEY_4 },
408 { 0xf8, 0x15, KEY_5 },
409 { 0xf8, 0x16, KEY_6 },
410 { 0xf8, 0x17, KEY_7 },
411 { 0xf8, 0x18, KEY_8 },
412 { 0xf8, 0x19, KEY_9 },
413 { 0xf8, 0x10, KEY_0 },
414 { 0xf8, 0x1c, KEY_PAGEUP }, /*ch+*/
415 { 0xf8, 0x0f, KEY_PAGEDOWN }, /*ch-*/
416 { 0xf8, 0x1a, KEY_O }, /*vol+*/
417 { 0xf8, 0x0e, KEY_Z }, /*vol-*/
418 { 0xf8, 0x04, KEY_R }, /*rec*/
419 { 0xf8, 0x09, KEY_D }, /*fav*/
420 { 0xf8, 0x08, KEY_BACKSPACE }, /*rewind*/
421 { 0xf8, 0x07, KEY_A }, /*fast*/
422 { 0xf8, 0x0b, KEY_P }, /*pause*/
423 { 0xf8, 0x02, KEY_ESC }, /*cancel*/
424 { 0xf8, 0x03, KEY_G }, /*tab*/
425 { 0xf8, 0x00, KEY_UP }, /*up*/
426 { 0xf8, 0x1f, KEY_ENTER }, /*ok*/
427 { 0xf8, 0x01, KEY_DOWN }, /*down*/
428 { 0xf8, 0x05, KEY_C }, /*cap*/
429 { 0xf8, 0x06, KEY_S }, /*stop*/
430 { 0xf8, 0x40, KEY_F }, /*full*/
431 { 0xf8, 0x1e, KEY_W }, /*tvmode*/
432 { 0xf8, 0x1b, KEY_B }, /*recall*/
433
434};
435
436
437
438static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
439{
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300440 struct dw210x_state *st = d->priv;
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300441 u8 key[2];
442 struct i2c_msg msg[] = {
443 {.addr = DW2102_RC_QUERY, .flags = I2C_M_RD, .buf = key,
444 .len = 2},
445 };
446 int i;
447
448 *state = REMOTE_NO_KEY_PRESSED;
449 if (dw2102_i2c_transfer(&d->i2c_adap, msg, 1) == 1) {
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300450 for (i = 0; i < ARRAY_SIZE(dw210x_rc_keys); i++) {
451 if (dw210x_rc_keys[i].data == msg[0].buf[0]) {
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300452 *state = REMOTE_KEY_PRESSED;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300453 *event = dw210x_rc_keys[i].event;
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300454 st->last_key_pressed =
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300455 dw210x_rc_keys[i].event;
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300456 break;
457 }
458 st->last_key_pressed = 0;
459 }
460 }
461 /* info("key: %x %x\n",key[0],key[1]); */
462 return 0;
463}
464
465static struct usb_device_id dw2102_table[] = {
466 {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
467 {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300468 {USB_DEVICE(USB_VID_CYPRESS, 0x2104)},
469 {USB_DEVICE(0x9022, 0xd650)},
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300470 { }
471};
472
473MODULE_DEVICE_TABLE(usb, dw2102_table);
474
475static int dw2102_load_firmware(struct usb_device *dev,
476 const struct firmware *frmwr)
477{
478 u8 *b, *p;
479 int ret = 0, i;
480 u8 reset;
481 u8 reset16 [] = {0, 0, 0, 0, 0, 0, 0};
482 const struct firmware *fw;
483 const char *filename = "dvb-usb-dw2101.fw";
484 switch (dev->descriptor.idProduct) {
485 case 0x2101:
486 ret = request_firmware(&fw, filename, &dev->dev);
487 if (ret != 0) {
488 err("did not find the firmware file. (%s) "
489 "Please see linux/Documentation/dvb/ for more details "
490 "on firmware-problems.", filename);
491 return ret;
492 }
493 break;
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300494 default:
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300495 fw = frmwr;
496 break;
497 }
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300498 info("start downloading DW210X firmware");
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300499 p = kmalloc(fw->size, GFP_KERNEL);
500 reset = 1;
501 /*stop the CPU*/
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300502 dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
503 dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300504
505 if (p != NULL) {
506 memcpy(p, fw->data, fw->size);
507 for (i = 0; i < fw->size; i += 0x40) {
508 b = (u8 *) p + i;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300509 if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
510 DW210X_WRITE_MSG) != 0x40) {
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300511 err("error while transferring firmware");
512 ret = -EINVAL;
513 break;
514 }
515 }
516 /* restart the CPU */
517 reset = 0;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300518 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
519 DW210X_WRITE_MSG) != 1) {
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300520 err("could not restart the USB controller CPU.");
521 ret = -EINVAL;
522 }
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300523 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
524 DW210X_WRITE_MSG) != 1) {
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300525 err("could not restart the USB controller CPU.");
526 ret = -EINVAL;
527 }
528 /* init registers */
529 switch (dev->descriptor.idProduct) {
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300530 case USB_PID_DW2104:
531 case 0xd650:
532 reset = 1;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300533 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
534 DW210X_WRITE_MSG);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300535 reset = 0;
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300536 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
537 DW210X_WRITE_MSG);
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300538 break;
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300539 case USB_PID_DW2102:
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300540 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
541 DW210X_WRITE_MSG);
542 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
543 DW210X_READ_MSG);
544 /* check STV0299 frontend */
545 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
546 DW210X_READ_MSG);
547 if (reset16[0] == 0xa1)
548 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300549 break;
550 case 0x2101:
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300551 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
552 DW210X_READ_MSG);
553 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
554 DW210X_READ_MSG);
555 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
556 DW210X_READ_MSG);
557 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
558 DW210X_READ_MSG);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300559 break;
560 }
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300561 msleep(100);
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300562 kfree(p);
563 }
564 return ret;
565}
566
567static struct dvb_usb_device_properties dw2102_properties = {
568 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
569 .usb_ctrl = DEVICE_SPECIFIC,
570 .firmware = "dvb-usb-dw2102.fw",
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300571 .size_of_priv = sizeof(struct dw210x_state),
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300572 .no_reconnect = 1,
573
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300574 .i2c_algo = &dw2102_serit_i2c_algo,
575 .rc_key_map = dw210x_rc_keys,
576 .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300577 .rc_interval = 150,
578 .rc_query = dw2102_rc_query,
579
580 .generic_bulk_ctrl_endpoint = 0x81,
581 /* parameter for the MPEG2-data transfer */
582 .num_adapters = 1,
583 .download_firmware = dw2102_load_firmware,
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300584 .read_mac_address = dw210x_read_mac_address,
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300585 .adapter = {
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300586 {
587 .frontend_attach = dw2102_frontend_attach,
588 .streaming_ctrl = NULL,
589 .tuner_attach = dw2102_tuner_attach,
590 .stream = {
591 .type = USB_BULK,
592 .count = 8,
593 .endpoint = 0x82,
594 .u = {
595 .bulk = {
596 .buffersize = 4096,
597 }
598 }
599 },
600 }
601 },
602 .num_device_descs = 2,
603 .devices = {
604 {"DVBWorld DVB-S 2102 USB2.0",
605 {&dw2102_table[0], NULL},
606 {NULL},
607 },
608 {"DVBWorld DVB-S 2101 USB2.0",
609 {&dw2102_table[1], NULL},
610 {NULL},
611 },
612 }
613};
614
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300615static struct dvb_usb_device_properties dw2104_properties = {
616 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
617 .usb_ctrl = DEVICE_SPECIFIC,
618 .firmware = "dvb-usb-dw2104.fw",
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300619 .size_of_priv = sizeof(struct dw210x_state),
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300620 .no_reconnect = 1,
621
622 .i2c_algo = &dw2104_i2c_algo,
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300623 .rc_key_map = dw210x_rc_keys,
624 .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300625 .rc_interval = 150,
626 .rc_query = dw2102_rc_query,
627
628 .generic_bulk_ctrl_endpoint = 0x81,
629 /* parameter for the MPEG2-data transfer */
630 .num_adapters = 1,
631 .download_firmware = dw2102_load_firmware,
Igor M. Liplianin21b007b2008-09-17 19:19:19 -0300632 .read_mac_address = dw210x_read_mac_address,
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300633 .adapter = {
634 {
635 .frontend_attach = dw2104_frontend_attach,
636 .streaming_ctrl = NULL,
637 /*.tuner_attach = dw2104_tuner_attach,*/
638 .stream = {
639 .type = USB_BULK,
640 .count = 8,
641 .endpoint = 0x82,
642 .u = {
643 .bulk = {
644 .buffersize = 4096,
645 }
646 }
647 },
648 }
649 },
650 .num_device_descs = 2,
651 .devices = {
652 { "DVBWorld DW2104 USB2.0",
653 {&dw2102_table[2], NULL},
654 {NULL},
655 },
656 { "TeVii S650 USB2.0",
657 {&dw2102_table[3], NULL},
658 {NULL},
659 },
660 }
661};
662
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300663static int dw2102_probe(struct usb_interface *intf,
664 const struct usb_device_id *id)
665{
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300666 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
667 THIS_MODULE, NULL, adapter_nr) ||
668 0 == dvb_usb_device_init(intf, &dw2104_properties,
669 THIS_MODULE, NULL, adapter_nr)) {
670 return 0;
671 }
672 return -ENODEV;
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300673}
674
675static struct usb_driver dw2102_driver = {
676 .name = "dw2102",
677 .probe = dw2102_probe,
678 .disconnect = dvb_usb_device_exit,
679 .id_table = dw2102_table,
680};
681
682static int __init dw2102_module_init(void)
683{
684 int ret = usb_register(&dw2102_driver);
685 if (ret)
686 err("usb_register failed. Error number %d", ret);
687
688 return ret;
689}
690
691static void __exit dw2102_module_exit(void)
692{
693 usb_deregister(&dw2102_driver);
694}
695
696module_init(dw2102_module_init);
697module_exit(dw2102_module_exit);
698
699MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
Igor M. Liplianinfe03d5e2008-09-08 17:16:40 -0300700MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104 USB2.0 device");
Igor M Liplianin7fd48282008-07-20 08:05:50 -0300701MODULE_VERSION("0.1");
702MODULE_LICENSE("GPL");