blob: 28c7b232c4a8370a0bc9f728647de307c9b680a1 [file] [log] [blame]
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001/*
2 * DVB USB Linux driver for Anysee E30 DVB-C & DVB-T USB2.0 receiver
3 *
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * TODO:
21 * - add smart card reader support for Conditional Access (CA)
22 *
23 * Card reader in Anysee is nothing more than ISO 7816 card reader.
24 * There is no hardware CAM in any Anysee device sold.
25 * In my understanding it should be implemented by making own module
Antti Palosaari9fdd9ca2008-06-11 11:43:19 -030026 * for ISO 7816 card reader, like dvb_ca_en50221 is implemented. This
27 * module registers serial interface that can be used to communicate
Antti Palosaaria51e34d2008-05-17 23:05:48 -030028 * with any ISO 7816 smart card.
29 *
30 * Any help according to implement serial smart card reader support
31 * is highly welcome!
32 */
33
34#include "anysee.h"
35#include "tda1002x.h"
36#include "mt352.h"
37#include "mt352_priv.h"
38#include "zl10353.h"
Antti Palosaari72ffd2b2011-04-10 20:14:50 -030039#include "tda18212.h"
Antti Palosaarif0a53102011-04-27 21:11:59 -030040#include "cx24116.h"
Antti Palosaaribedbf3d2011-04-29 13:55:02 -030041#include "stv0900.h"
42#include "stv6110.h"
Antti Palosaarif0a53102011-04-27 21:11:59 -030043#include "isl6423.h"
Antti Palosaari608add82011-08-12 18:29:46 -030044#include "cxd2820r.h"
Antti Palosaaria51e34d2008-05-17 23:05:48 -030045
46/* debug */
47static int dvb_usb_anysee_debug;
48module_param_named(debug, dvb_usb_anysee_debug, int, 0644);
49MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
Mauro Carvalho Chehabffbc5f82009-01-05 01:34:20 -030050static int dvb_usb_anysee_delsys;
Antti Palosaari0f77c3a2008-08-11 10:54:16 -030051module_param_named(delsys, dvb_usb_anysee_delsys, int, 0644);
52MODULE_PARM_DESC(delsys, "select delivery mode (0=DVB-C, 1=DVB-T)");
Antti Palosaaria51e34d2008-05-17 23:05:48 -030053DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
54
Akinobu Mitadec0c462008-10-29 21:16:04 -030055static DEFINE_MUTEX(anysee_usb_mutex);
Antti Palosaaria51e34d2008-05-17 23:05:48 -030056
57static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
58 u8 *rbuf, u8 rlen)
59{
60 struct anysee_state *state = d->priv;
61 int act_len, ret;
62 u8 buf[64];
63
Antti Palosaaria51e34d2008-05-17 23:05:48 -030064 memcpy(&buf[0], sbuf, slen);
65 buf[60] = state->seq++;
66
67 if (mutex_lock_interruptible(&anysee_usb_mutex) < 0)
68 return -EAGAIN;
69
70 /* We need receive one message more after dvb_usb_generic_rw due
71 to weird transaction flow, which is 1 x send + 2 x receive. */
72 ret = dvb_usb_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf), 0);
73
74 if (!ret) {
75 /* receive 2nd answer */
76 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
77 d->props.generic_bulk_ctrl_endpoint), buf, sizeof(buf),
78 &act_len, 2000);
79 if (ret)
80 err("%s: recv bulk message failed: %d", __func__, ret);
81 else {
82 deb_xfer("<<< ");
83 debug_dump(buf, act_len, deb_xfer);
84 }
85 }
86
87 /* read request, copy returned data to return buf */
88 if (!ret && rbuf && rlen)
89 memcpy(rbuf, buf, rlen);
90
91 mutex_unlock(&anysee_usb_mutex);
92
93 return ret;
94}
95
96static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
97{
98 u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};
99 int ret;
100 ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);
101 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, *val);
102 return ret;
103}
104
105static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
106{
107 u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};
108 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, val);
109 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
110}
111
Antti Palosaari41f81f62011-04-10 17:53:52 -0300112/* write single register with mask */
113static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
114 u8 mask)
115{
116 int ret;
117 u8 tmp;
118
119 /* no need for read if whole reg is written */
120 if (mask != 0xff) {
121 ret = anysee_read_reg(d, reg, &tmp);
122 if (ret)
123 return ret;
124
125 val &= mask;
126 tmp &= ~mask;
127 val |= tmp;
128 }
129
130 return anysee_write_reg(d, reg, val);
131}
132
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300133static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
134{
135 u8 buf[] = {CMD_GET_HW_INFO};
136 return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);
137}
138
139static int anysee_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
140{
141 u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};
142 deb_info("%s: onoff:%02x\n", __func__, onoff);
143 return anysee_ctrl_msg(adap->dev, buf, sizeof(buf), NULL, 0);
144}
145
146static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)
147{
148 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};
149 deb_info("%s: state:%02x interval:%02x\n", __func__, mode, interval);
150 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
151}
152
153static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
154{
155 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};
156 deb_info("%s: onoff:%02x\n", __func__, onoff);
157 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
158}
159
160static int anysee_init(struct dvb_usb_device *d)
161{
162 int ret;
163 /* LED light */
164 ret = anysee_led_ctrl(d, 0x01, 0x03);
165 if (ret)
166 return ret;
167
168 /* enable IR */
169 ret = anysee_ir_ctrl(d, 1);
170 if (ret)
171 return ret;
172
173 return 0;
174}
175
176/* I2C */
177static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
178 int num)
179{
180 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Mauro Carvalho Chehab902571a2008-12-29 19:02:24 -0300181 int ret = 0, inc, i = 0;
Antti Palosaari21d2e932011-05-24 06:04:08 -0300182 u8 buf[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300183
184 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
185 return -EAGAIN;
186
187 while (i < num) {
188 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
Antti Palosaari21d2e932011-05-24 06:04:08 -0300189 if (msg[i].len > 2 || msg[i+1].len > 60) {
190 ret = -EOPNOTSUPP;
191 break;
192 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300193 buf[0] = CMD_I2C_READ;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300194 buf[1] = (msg[i].addr << 1) | 0x01;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300195 buf[2] = msg[i].buf[0];
Antti Palosaari882b82c2011-04-12 19:49:25 -0300196 buf[3] = msg[i].buf[1];
197 buf[4] = msg[i].len-1;
Antti Palosaarib3e6a5a2011-04-09 21:00:51 -0300198 buf[5] = msg[i+1].len;
Antti Palosaari21d2e932011-05-24 06:04:08 -0300199 ret = anysee_ctrl_msg(d, buf, 6, msg[i+1].buf,
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300200 msg[i+1].len);
201 inc = 2;
202 } else {
Antti Palosaari21d2e932011-05-24 06:04:08 -0300203 if (msg[i].len > 48) {
204 ret = -EOPNOTSUPP;
205 break;
206 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300207 buf[0] = CMD_I2C_WRITE;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300208 buf[1] = (msg[i].addr << 1);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300209 buf[2] = msg[i].len;
210 buf[3] = 0x01;
211 memcpy(&buf[4], msg[i].buf, msg[i].len);
Antti Palosaari21d2e932011-05-24 06:04:08 -0300212 ret = anysee_ctrl_msg(d, buf, 4 + msg[i].len, NULL, 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300213 inc = 1;
214 }
215 if (ret)
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300216 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300217
218 i += inc;
219 }
220
221 mutex_unlock(&d->i2c_mutex);
222
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300223 return ret ? ret : i;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300224}
225
226static u32 anysee_i2c_func(struct i2c_adapter *adapter)
227{
228 return I2C_FUNC_I2C;
229}
230
231static struct i2c_algorithm anysee_i2c_algo = {
232 .master_xfer = anysee_master_xfer,
233 .functionality = anysee_i2c_func,
234};
235
236static int anysee_mt352_demod_init(struct dvb_frontend *fe)
237{
Antti Palosaariae3745f2009-09-16 19:50:25 -0300238 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
239 static u8 reset[] = { RESET, 0x80 };
240 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
241 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
242 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300243 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
244
245 mt352_write(fe, clock_config, sizeof(clock_config));
246 udelay(200);
247 mt352_write(fe, reset, sizeof(reset));
248 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
249
250 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
251 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
252 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
253
254 return 0;
255}
256
257/* Callbacks for DVB USB */
258static struct tda10023_config anysee_tda10023_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300259 .demod_address = (0x1a >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300260 .invert = 0,
261 .xtal = 16000000,
262 .pll_m = 11,
263 .pll_p = 3,
264 .pll_n = 1,
Antti Palosaari5ae2fca2008-06-09 22:58:22 -0300265 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
266 .deltaf = 0xfeeb,
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300267};
268
269static struct mt352_config anysee_mt352_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300270 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300271 .demod_init = anysee_mt352_demod_init,
272};
273
274static struct zl10353_config anysee_zl10353_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300275 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300276 .parallel_ts = 1,
277};
278
Antti Palosaari1fd80702011-04-12 17:34:08 -0300279static struct zl10353_config anysee_zl10353_tda18212_config2 = {
280 .demod_address = (0x1e >> 1),
281 .parallel_ts = 1,
282 .disable_i2c_gate_ctrl = 1,
283 .no_tuner = 1,
284 .if2 = 41500,
285};
286
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300287static struct zl10353_config anysee_zl10353_tda18212_config = {
288 .demod_address = (0x18 >> 1),
289 .parallel_ts = 1,
290 .disable_i2c_gate_ctrl = 1,
291 .no_tuner = 1,
292 .if2 = 41500,
293};
294
295static struct tda10023_config anysee_tda10023_tda18212_config = {
296 .demod_address = (0x1a >> 1),
297 .xtal = 16000000,
298 .pll_m = 12,
299 .pll_p = 3,
300 .pll_n = 1,
301 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
302 .deltaf = 0xba02,
303};
304
305static struct tda18212_config anysee_tda18212_config = {
306 .i2c_address = (0xc0 >> 1),
307 .if_dvbt_6 = 4150,
308 .if_dvbt_7 = 4150,
309 .if_dvbt_8 = 4150,
310 .if_dvbc = 5000,
311};
312
Antti Palosaari608add82011-08-12 18:29:46 -0300313static struct tda18212_config anysee_tda18212_config2 = {
314 .i2c_address = 0x60 /* (0xc0 >> 1) */,
315 .if_dvbt_6 = 3550,
316 .if_dvbt_7 = 3700,
317 .if_dvbt_8 = 4150,
318 .if_dvbt2_6 = 3250,
319 .if_dvbt2_7 = 4000,
320 .if_dvbt2_8 = 4000,
321 .if_dvbc = 5000,
322};
323
Antti Palosaarif0a53102011-04-27 21:11:59 -0300324static struct cx24116_config anysee_cx24116_config = {
325 .demod_address = (0xaa >> 1),
326 .mpg_clk_pos_pol = 0x00,
327 .i2c_wr_max = 48,
328};
329
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300330static struct stv0900_config anysee_stv0900_config = {
331 .demod_address = (0xd0 >> 1),
332 .demod_mode = 0,
333 .xtal = 8000000,
334 .clkmode = 3,
335 .diseqc_mode = 2,
336 .tun1_maddress = 0,
337 .tun1_adc = 1, /* 1 Vpp */
338 .path1_mode = 3,
339};
340
341static struct stv6110_config anysee_stv6110_config = {
342 .i2c_address = (0xc0 >> 1),
343 .mclk = 16000000,
344 .clk_div = 1,
345};
346
Antti Palosaarif0a53102011-04-27 21:11:59 -0300347static struct isl6423_config anysee_isl6423_config = {
348 .current_max = SEC_CURRENT_800m,
349 .curlim = SEC_CURRENT_LIM_OFF,
350 .mod_extern = 1,
351 .addr = (0x10 >> 1),
352};
353
Antti Palosaari608add82011-08-12 18:29:46 -0300354static struct cxd2820r_config anysee_cxd2820r_config = {
355 .i2c_address = 0x6d, /* (0xda >> 1) */
356 .ts_mode = 0x38,
357 .if_dvbt_6 = 3550,
358 .if_dvbt_7 = 3700,
359 .if_dvbt_8 = 4150,
360 .if_dvbt2_6 = 3250,
361 .if_dvbt2_7 = 4000,
362 .if_dvbt2_8 = 4000,
363 .if_dvbc = 5000,
364};
365
Antti Palosaari41f81f62011-04-10 17:53:52 -0300366/*
367 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
368 * Manufacturer: AMT.CO.KR
369 *
370 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
371 * PCB: ?
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300372 * parts: DNOS404ZH102A(MT352, DTT7579(?))
Antti Palosaari41f81f62011-04-10 17:53:52 -0300373 *
Antti Palosaari05c46c02011-05-25 18:30:09 -0300374 * E30 VID=04b4 PID=861f HW=2 FW=2.1 "anysee-T(LP)"
375 * PCB: PCB 507T (rev1.61)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300376 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
Antti Palosaari05c46c02011-05-25 18:30:09 -0300377 * OEA=0a OEB=00 OEC=00 OED=ff OEE=00
378 * IOA=45 IOB=ff IOC=00 IOD=ff IOE=00
Antti Palosaari41f81f62011-04-10 17:53:52 -0300379 *
380 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
381 * PCB: 507CD (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300382 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
Antti Palosaari05c46c02011-05-25 18:30:09 -0300383 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
384 * IOA=4f IOB=ff IOC=00 IOD=06 IOE=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300385 * IOD[0] ZL10353 1=enabled
386 * IOA[7] TS 0=enabled
387 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
388 *
389 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
390 * PCB: 507DC (rev0.2)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300391 * parts: TDA10023, DTOS403IH102B TM, CST56I01
Antti Palosaari05c46c02011-05-25 18:30:09 -0300392 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
393 * IOA=4f IOB=ff IOC=00 IOD=26 IOE=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300394 * IOD[0] TDA10023 1=enabled
395 *
Antti Palosaarif0a53102011-04-27 21:11:59 -0300396 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
397 * PCB: 507SI (rev2.1)
398 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300399 * OEA=80 OEB=00 OEC=ff OED=ff OEE=fe
400 * IOA=4d IOB=ff IOC=00 IOD=26 IOE=01
Antti Palosaarif0a53102011-04-27 21:11:59 -0300401 * IOD[0] CX24116 1=enabled
402 *
Antti Palosaari41f81f62011-04-10 17:53:52 -0300403 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
404 * PCB: 507FA (rev0.4)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300405 * parts: TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300406 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
407 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300408 * IOD[5] TDA10023 1=enabled
409 * IOE[0] tuner 1=enabled
410 *
411 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
412 * PCB: 507FA (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300413 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300414 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
415 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300416 * DVB-C:
417 * IOD[5] TDA10023 1=enabled
418 * IOE[0] tuner 1=enabled
419 * DVB-T:
420 * IOD[0] ZL10353 1=enabled
421 * IOE[0] tuner 0=enabled
422 * tuner is behind ZL10353 I2C-gate
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300423 *
424 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
425 * PCB: 508TC (rev0.6)
426 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
Antti Palosaari05c46c02011-05-25 18:30:09 -0300427 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
428 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300429 * IOA[7] TS 1=enabled
430 * IOE[4] TDA18212 1=enabled
431 * DVB-C:
432 * IOD[6] ZL10353 0=disabled
433 * IOD[5] TDA10023 1=enabled
434 * IOE[0] IF 1=enabled
435 * DVB-T:
436 * IOD[5] TDA10023 0=disabled
437 * IOD[6] ZL10353 1=enabled
438 * IOE[0] IF 0=enabled
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300439 *
440 * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
441 * PCB: 508S2 (rev0.7)
442 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
Antti Palosaari05c46c02011-05-25 18:30:09 -0300443 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
444 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300445 * IOA[7] TS 1=enabled
446 * IOE[5] STV0903 1=enabled
447 *
Antti Palosaari608add82011-08-12 18:29:46 -0300448 * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)"
449 * PCB: 508T2C (rev0.3)
450 * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024
451 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
452 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
453 * IOA[7] TS 1=enabled
454 * IOE[5] CXD2820R 1=enabled
455 *
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300456 * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)"
457 * PCB: 508PTC (rev0.5)
458 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
459 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
460 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
461 * IOA[7] TS 1=enabled
462 * IOE[4] TDA18212 1=enabled
463 * DVB-C:
464 * IOD[6] ZL10353 0=disabled
465 * IOD[5] TDA10023 1=enabled
466 * IOE[0] IF 1=enabled
467 * DVB-T:
468 * IOD[5] TDA10023 0=disabled
469 * IOD[6] ZL10353 1=enabled
470 * IOE[0] IF 0=enabled
Antti Palosaarifea3c392011-05-25 18:21:43 -0300471 *
Antti Palosaari608add82011-08-12 18:29:46 -0300472 * E7 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)"
Antti Palosaarifea3c392011-05-25 18:21:43 -0300473 * PCB: 508PS2 (rev0.4)
474 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
475 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
476 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
477 * IOA[7] TS 1=enabled
478 * IOE[5] STV0903 1=enabled
Antti Palosaari41f81f62011-04-10 17:53:52 -0300479 */
480
Antti Palosaaribe943512011-09-05 22:10:05 -0300481
482/* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */
483static int anysee_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
484{
485 struct dvb_usb_adapter *adap = fe->dvb->priv;
486
487 /* enable / disable tuner access on IOE[4] */
488 return anysee_wr_reg_mask(adap->dev, REG_IOE, (enable << 4), 0x10);
489}
490
Antti Palosaari449d1a02011-07-25 20:25:21 -0300491static int anysee_frontend_ctrl(struct dvb_frontend *fe, int onoff)
492{
493 struct dvb_usb_adapter *adap = fe->dvb->priv;
494 struct anysee_state *state = adap->dev->priv;
495 int ret;
496
497 deb_info("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
498
499 /* no frontend sleep control */
500 if (onoff == 0)
501 return 0;
502
503 switch (state->hw) {
504 case ANYSEE_HW_507FA: /* 15 */
505 /* E30 Combo Plus */
506 /* E30 C Plus */
507
508 if ((fe->id ^ dvb_usb_anysee_delsys) == 0) {
509 /* disable DVB-T demod on IOD[0] */
510 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0),
511 0x01);
512 if (ret)
513 goto error;
514
515 /* enable DVB-C demod on IOD[5] */
516 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
517 0x20);
518 if (ret)
519 goto error;
520
521 /* enable DVB-C tuner on IOE[0] */
522 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
523 0x01);
524 if (ret)
525 goto error;
526 } else {
527 /* disable DVB-C demod on IOD[5] */
528 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
529 0x20);
530 if (ret)
531 goto error;
532
533 /* enable DVB-T demod on IOD[0] */
534 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),
535 0x01);
536 if (ret)
537 goto error;
538
539 /* enable DVB-T tuner on IOE[0] */
540 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
541 0x01);
542 if (ret)
543 goto error;
544 }
545
546 break;
547 case ANYSEE_HW_508TC: /* 18 */
548 case ANYSEE_HW_508PTC: /* 21 */
549 /* E7 TC */
550 /* E7 PTC */
551
552 if ((fe->id ^ dvb_usb_anysee_delsys) == 0) {
553 /* disable DVB-T demod on IOD[6] */
554 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
555 0x40);
556 if (ret)
557 goto error;
558
559 /* enable DVB-C demod on IOD[5] */
560 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
561 0x20);
562 if (ret)
563 goto error;
564
565 /* enable IF route on IOE[0] */
566 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
567 0x01);
568 if (ret)
569 goto error;
570 } else {
571 /* disable DVB-C demod on IOD[5] */
572 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
573 0x20);
574 if (ret)
575 goto error;
576
577 /* enable DVB-T demod on IOD[6] */
578 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6),
579 0x40);
580 if (ret)
581 goto error;
582
583 /* enable IF route on IOE[0] */
584 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
585 0x01);
586 if (ret)
587 goto error;
588 }
589
590 break;
591 default:
592 ret = 0;
593 }
594
595error:
596 return ret;
597}
598
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300599static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
600{
601 int ret;
602 struct anysee_state *state = adap->dev->priv;
603 u8 hw_info[3];
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300604 u8 tmp;
605 struct i2c_msg msg[2] = {
606 {
607 .addr = anysee_tda18212_config.i2c_address,
608 .flags = 0,
609 .len = 1,
610 .buf = "\x00",
611 }, {
612 .addr = anysee_tda18212_config.i2c_address,
613 .flags = I2C_M_RD,
614 .len = 1,
615 .buf = &tmp,
616 }
617 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300618
Antti Palosaari449d1a02011-07-25 20:25:21 -0300619 /* detect hardware only once */
Michael Krufky77eed212011-09-06 09:31:57 -0300620 if (adap->fe_adap[0].fe == NULL) {
Antti Palosaari449d1a02011-07-25 20:25:21 -0300621 /* Check which hardware we have.
622 * We must do this call two times to get reliable values (hw bug).
623 */
624 ret = anysee_get_hw_info(adap->dev, hw_info);
625 if (ret)
626 goto error;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300627
Antti Palosaari449d1a02011-07-25 20:25:21 -0300628 ret = anysee_get_hw_info(adap->dev, hw_info);
629 if (ret)
630 goto error;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300631
Antti Palosaari449d1a02011-07-25 20:25:21 -0300632 /* Meaning of these info bytes are guessed. */
633 info("firmware version:%d.%d hardware id:%d",
634 hw_info[1], hw_info[2], hw_info[0]);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300635
Antti Palosaari449d1a02011-07-25 20:25:21 -0300636 state->hw = hw_info[0];
637 }
638
639 /* set current frondend ID for devices having two frondends */
Michael Krufky77eed212011-09-06 09:31:57 -0300640 if (adap->fe_adap[0].fe)
Antti Palosaari449d1a02011-07-25 20:25:21 -0300641 state->fe_id++;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300642
Antti Palosaari41f81f62011-04-10 17:53:52 -0300643 switch (state->hw) {
Antti Palosaari05c46c02011-05-25 18:30:09 -0300644 case ANYSEE_HW_507T: /* 2 */
Antti Palosaari41f81f62011-04-10 17:53:52 -0300645 /* E30 */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300646
Antti Palosaari449d1a02011-07-25 20:25:21 -0300647 if (state->fe_id)
648 break;
649
Antti Palosaari41f81f62011-04-10 17:53:52 -0300650 /* attach demod */
Michael Krufky77eed212011-09-06 09:31:57 -0300651 adap->fe_adap[0].fe = dvb_attach(mt352_attach, &anysee_mt352_config,
Antti Palosaari41f81f62011-04-10 17:53:52 -0300652 &adap->dev->i2c_adap);
Michael Krufky77eed212011-09-06 09:31:57 -0300653 if (adap->fe_adap[0].fe)
Antti Palosaari41f81f62011-04-10 17:53:52 -0300654 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300655
Antti Palosaari41f81f62011-04-10 17:53:52 -0300656 /* attach demod */
Michael Krufky77eed212011-09-06 09:31:57 -0300657 adap->fe_adap[0].fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
Antti Palosaari41f81f62011-04-10 17:53:52 -0300658 &adap->dev->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300659
660 break;
661 case ANYSEE_HW_507CD: /* 6 */
662 /* E30 Plus */
663
Antti Palosaari449d1a02011-07-25 20:25:21 -0300664 if (state->fe_id)
665 break;
666
Antti Palosaari41f81f62011-04-10 17:53:52 -0300667 /* enable DVB-T demod on IOD[0] */
668 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
669 if (ret)
670 goto error;
671
672 /* enable transport stream on IOA[7] */
673 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (0 << 7), 0x80);
674 if (ret)
675 goto error;
676
677 /* attach demod */
Michael Krufky77eed212011-09-06 09:31:57 -0300678 adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300679 &anysee_zl10353_config, &adap->dev->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300680
681 break;
682 case ANYSEE_HW_507DC: /* 10 */
683 /* E30 C Plus */
684
Antti Palosaari449d1a02011-07-25 20:25:21 -0300685 if (state->fe_id)
686 break;
687
Antti Palosaari41f81f62011-04-10 17:53:52 -0300688 /* enable DVB-C demod on IOD[0] */
689 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
690 if (ret)
691 goto error;
692
693 /* attach demod */
Michael Krufky77eed212011-09-06 09:31:57 -0300694 adap->fe_adap[0].fe = dvb_attach(tda10023_attach,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300695 &anysee_tda10023_config, &adap->dev->i2c_adap, 0x48);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300696
697 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300698 case ANYSEE_HW_507SI: /* 11 */
699 /* E30 S2 Plus */
700
Antti Palosaari449d1a02011-07-25 20:25:21 -0300701 if (state->fe_id)
702 break;
703
Antti Palosaarif0a53102011-04-27 21:11:59 -0300704 /* enable DVB-S/S2 demod on IOD[0] */
705 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
706 if (ret)
707 goto error;
708
709 /* attach demod */
Michael Krufky77eed212011-09-06 09:31:57 -0300710 adap->fe_adap[0].fe = dvb_attach(cx24116_attach, &anysee_cx24116_config,
Antti Palosaarif0a53102011-04-27 21:11:59 -0300711 &adap->dev->i2c_adap);
712
713 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300714 case ANYSEE_HW_507FA: /* 15 */
715 /* E30 Combo Plus */
716 /* E30 C Plus */
717
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300718 /* enable tuner on IOE[4] */
719 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
720 if (ret)
721 goto error;
722
723 /* probe TDA18212 */
724 tmp = 0;
725 ret = i2c_transfer(&adap->dev->i2c_adap, msg, 2);
726 if (ret == 2 && tmp == 0xc7)
727 deb_info("%s: TDA18212 found\n", __func__);
728 else
729 tmp = 0;
730
731 /* disable tuner on IOE[4] */
732 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);
733 if (ret)
734 goto error;
735
Antti Palosaari449d1a02011-07-25 20:25:21 -0300736 if ((state->fe_id ^ dvb_usb_anysee_delsys) == 0) {
Antti Palosaari41f81f62011-04-10 17:53:52 -0300737 /* disable DVB-T demod on IOD[0] */
738 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0),
739 0x01);
740 if (ret)
741 goto error;
742
743 /* enable DVB-C demod on IOD[5] */
744 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
745 0x20);
746 if (ret)
747 goto error;
748
749 /* attach demod */
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300750 if (tmp == 0xc7) {
751 /* TDA18212 config */
Michael Krufky77eed212011-09-06 09:31:57 -0300752 adap->fe_adap[state->fe_id].fe = dvb_attach(
Antti Palosaari449d1a02011-07-25 20:25:21 -0300753 tda10023_attach,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300754 &anysee_tda10023_tda18212_config,
755 &adap->dev->i2c_adap, 0x48);
756 } else {
757 /* PLL config */
Michael Krufky77eed212011-09-06 09:31:57 -0300758 adap->fe_adap[state->fe_id].fe = dvb_attach(
Antti Palosaari449d1a02011-07-25 20:25:21 -0300759 tda10023_attach,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300760 &anysee_tda10023_config,
761 &adap->dev->i2c_adap, 0x48);
762 }
Antti Palosaari449d1a02011-07-25 20:25:21 -0300763 } else {
764 /* disable DVB-C demod on IOD[5] */
765 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
766 0x20);
767 if (ret)
768 goto error;
769
770 /* enable DVB-T demod on IOD[0] */
771 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),
772 0x01);
773 if (ret)
774 goto error;
775
776 /* attach demod */
777 if (tmp == 0xc7) {
778 /* TDA18212 config */
Michael Krufky77eed212011-09-06 09:31:57 -0300779 adap->fe_adap[state->fe_id].fe = dvb_attach(
Antti Palosaari449d1a02011-07-25 20:25:21 -0300780 zl10353_attach,
781 &anysee_zl10353_tda18212_config2,
782 &adap->dev->i2c_adap);
783 } else {
784 /* PLL config */
Michael Krufky77eed212011-09-06 09:31:57 -0300785 adap->fe_adap[state->fe_id].fe = dvb_attach(
Antti Palosaari449d1a02011-07-25 20:25:21 -0300786 zl10353_attach,
787 &anysee_zl10353_config,
788 &adap->dev->i2c_adap);
789 }
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300790 }
Antti Palosaarie82eea72011-04-12 19:43:30 -0300791
Antti Palosaaribe943512011-09-05 22:10:05 -0300792 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
793 if (tmp == 0xc7) {
794 if (adap->fe_adap[state->fe_id].fe)
795 adap->fe_adap[state->fe_id].fe->ops.i2c_gate_ctrl =
796 anysee_i2c_gate_ctrl;
797 }
798
Antti Palosaari41f81f62011-04-10 17:53:52 -0300799 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300800 case ANYSEE_HW_508TC: /* 18 */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300801 case ANYSEE_HW_508PTC: /* 21 */
Antti Palosaaria43be982011-04-10 20:23:02 -0300802 /* E7 TC */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300803 /* E7 PTC */
Antti Palosaaria43be982011-04-10 20:23:02 -0300804
805 /* enable transport stream on IOA[7] */
806 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);
807 if (ret)
808 goto error;
809
Antti Palosaari449d1a02011-07-25 20:25:21 -0300810 if ((state->fe_id ^ dvb_usb_anysee_delsys) == 0) {
Antti Palosaaria43be982011-04-10 20:23:02 -0300811 /* disable DVB-T demod on IOD[6] */
812 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
813 0x40);
814 if (ret)
815 goto error;
816
817 /* enable DVB-C demod on IOD[5] */
818 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
819 0x20);
820 if (ret)
821 goto error;
822
Antti Palosaari449d1a02011-07-25 20:25:21 -0300823 /* attach demod */
Michael Krufky77eed212011-09-06 09:31:57 -0300824 adap->fe_adap[state->fe_id].fe = dvb_attach(tda10023_attach,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300825 &anysee_tda10023_tda18212_config,
826 &adap->dev->i2c_adap, 0x48);
827 } else {
828 /* disable DVB-C demod on IOD[5] */
829 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
830 0x20);
831 if (ret)
832 goto error;
833
834 /* enable DVB-T demod on IOD[6] */
835 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6),
836 0x40);
Antti Palosaaria43be982011-04-10 20:23:02 -0300837 if (ret)
838 goto error;
839
840 /* attach demod */
Michael Krufky77eed212011-09-06 09:31:57 -0300841 adap->fe_adap[state->fe_id].fe = dvb_attach(zl10353_attach,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300842 &anysee_zl10353_tda18212_config,
843 &adap->dev->i2c_adap);
Antti Palosaaria43be982011-04-10 20:23:02 -0300844 }
Antti Palosaarie82eea72011-04-12 19:43:30 -0300845
Antti Palosaaribe943512011-09-05 22:10:05 -0300846 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
847 if (adap->fe_adap[state->fe_id].fe)
848 adap->fe_adap[state->fe_id].fe->ops.i2c_gate_ctrl =
849 anysee_i2c_gate_ctrl;
850
Antti Palosaaria43be982011-04-10 20:23:02 -0300851 break;
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300852 case ANYSEE_HW_508S2: /* 19 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300853 case ANYSEE_HW_508PS2: /* 22 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300854 /* E7 S2 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300855 /* E7 PS2 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300856
Antti Palosaari449d1a02011-07-25 20:25:21 -0300857 if (state->fe_id)
858 break;
859
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300860 /* enable transport stream on IOA[7] */
861 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);
862 if (ret)
863 goto error;
864
865 /* enable DVB-S/S2 demod on IOE[5] */
866 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20);
867 if (ret)
868 goto error;
869
870 /* attach demod */
Michael Krufky77eed212011-09-06 09:31:57 -0300871 adap->fe_adap[0].fe = dvb_attach(stv0900_attach, &anysee_stv0900_config,
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300872 &adap->dev->i2c_adap, 0);
873
874 break;
Antti Palosaari608add82011-08-12 18:29:46 -0300875 case ANYSEE_HW_508T2C: /* 20 */
876 /* E7 T2C */
877
878 /* enable transport stream on IOA[7] */
879 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);
880 if (ret)
881 goto error;
882
883 /* enable DVB-T/T2/C demod on IOE[5] */
884 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20);
885 if (ret)
886 goto error;
887
888 if (state->fe_id == 0) {
889 /* DVB-T/T2 */
Antti Palosaaribe943512011-09-05 22:10:05 -0300890 adap->fe_adap[state->fe_id].fe = dvb_attach(cxd2820r_attach,
Antti Palosaari608add82011-08-12 18:29:46 -0300891 &anysee_cxd2820r_config,
892 &adap->dev->i2c_adap, NULL);
893 } else {
894 /* DVB-C */
Antti Palosaaribe943512011-09-05 22:10:05 -0300895 adap->fe_adap[state->fe_id].fe = dvb_attach(cxd2820r_attach,
Antti Palosaari608add82011-08-12 18:29:46 -0300896 &anysee_cxd2820r_config,
Antti Palosaaribe943512011-09-05 22:10:05 -0300897 &adap->dev->i2c_adap, adap->fe_adap[0].fe);
Antti Palosaari608add82011-08-12 18:29:46 -0300898 }
899
900 break;
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300901 }
902
Michael Krufky77eed212011-09-06 09:31:57 -0300903 if (!adap->fe_adap[0].fe) {
Antti Palosaari41f81f62011-04-10 17:53:52 -0300904 /* we have no frontend :-( */
905 ret = -ENODEV;
Antti Palosaarie82eea72011-04-12 19:43:30 -0300906 err("Unsupported Anysee version. " \
907 "Please report the <linux-media@vger.kernel.org>.");
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300908 }
Antti Palosaari41f81f62011-04-10 17:53:52 -0300909error:
910 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300911}
912
913static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
914{
915 struct anysee_state *state = adap->dev->priv;
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300916 struct dvb_frontend *fe;
Antti Palosaarie82eea72011-04-12 19:43:30 -0300917 int ret;
Antti Palosaari449d1a02011-07-25 20:25:21 -0300918 deb_info("%s: fe=%d\n", __func__, state->fe_id);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300919
Antti Palosaari41f81f62011-04-10 17:53:52 -0300920 switch (state->hw) {
Antti Palosaari05c46c02011-05-25 18:30:09 -0300921 case ANYSEE_HW_507T: /* 2 */
Antti Palosaari41f81f62011-04-10 17:53:52 -0300922 /* E30 */
923
924 /* attach tuner */
Michael Krufky77eed212011-09-06 09:31:57 -0300925 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, (0xc2 >> 1),
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300926 NULL, DVB_PLL_THOMSON_DTT7579);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300927
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300928 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300929 case ANYSEE_HW_507CD: /* 6 */
930 /* E30 Plus */
931
932 /* attach tuner */
Michael Krufky77eed212011-09-06 09:31:57 -0300933 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, (0xc2 >> 1),
Antti Palosaari41f81f62011-04-10 17:53:52 -0300934 &adap->dev->i2c_adap, DVB_PLL_THOMSON_DTT7579);
935
936 break;
937 case ANYSEE_HW_507DC: /* 10 */
938 /* E30 C Plus */
939
940 /* attach tuner */
Michael Krufky77eed212011-09-06 09:31:57 -0300941 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, (0xc0 >> 1),
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300942 &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300943
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300944 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300945 case ANYSEE_HW_507SI: /* 11 */
946 /* E30 S2 Plus */
947
948 /* attach LNB controller */
Michael Krufky77eed212011-09-06 09:31:57 -0300949 fe = dvb_attach(isl6423_attach, adap->fe_adap[0].fe,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300950 &adap->dev->i2c_adap, &anysee_isl6423_config);
Antti Palosaarif0a53102011-04-27 21:11:59 -0300951
952 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300953 case ANYSEE_HW_507FA: /* 15 */
954 /* E30 Combo Plus */
955 /* E30 C Plus */
956
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300957 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
958 * fails attach old simple PLL. */
959
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300960 /* attach tuner */
Michael Krufky77eed212011-09-06 09:31:57 -0300961 fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300962 &adap->dev->i2c_adap, &anysee_tda18212_config);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300963 if (fe)
964 break;
965
Antti Palosaari41f81f62011-04-10 17:53:52 -0300966 /* attach tuner */
Michael Krufky77eed212011-09-06 09:31:57 -0300967 fe = dvb_attach(dvb_pll_attach, adap->fe_adap[state->fe_id].fe,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300968 (0xc0 >> 1), &adap->dev->i2c_adap,
969 DVB_PLL_SAMSUNG_DTOS403IH102A);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300970
971 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300972 case ANYSEE_HW_508TC: /* 18 */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300973 case ANYSEE_HW_508PTC: /* 21 */
Antti Palosaaria43be982011-04-10 20:23:02 -0300974 /* E7 TC */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300975 /* E7 PTC */
Antti Palosaaria43be982011-04-10 20:23:02 -0300976
Antti Palosaaria43be982011-04-10 20:23:02 -0300977 /* attach tuner */
Michael Krufky77eed212011-09-06 09:31:57 -0300978 fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300979 &adap->dev->i2c_adap, &anysee_tda18212_config);
Antti Palosaaria43be982011-04-10 20:23:02 -0300980
981 break;
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300982 case ANYSEE_HW_508S2: /* 19 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300983 case ANYSEE_HW_508PS2: /* 22 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300984 /* E7 S2 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300985 /* E7 PS2 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300986
987 /* attach tuner */
Michael Krufky77eed212011-09-06 09:31:57 -0300988 fe = dvb_attach(stv6110_attach, adap->fe_adap[0].fe,
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300989 &anysee_stv6110_config, &adap->dev->i2c_adap);
990
991 if (fe) {
992 /* attach LNB controller */
Michael Krufky77eed212011-09-06 09:31:57 -0300993 fe = dvb_attach(isl6423_attach, adap->fe_adap[0].fe,
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300994 &adap->dev->i2c_adap, &anysee_isl6423_config);
995 }
996
997 break;
Antti Palosaari608add82011-08-12 18:29:46 -0300998
999 case ANYSEE_HW_508T2C: /* 20 */
1000 /* E7 T2C */
1001
1002 /* attach tuner */
Antti Palosaaribe943512011-09-05 22:10:05 -03001003 fe = dvb_attach(tda18212_attach, adap->fe_adap[state->fe_id].fe,
Antti Palosaari608add82011-08-12 18:29:46 -03001004 &adap->dev->i2c_adap, &anysee_tda18212_config2);
1005
1006 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -03001007 default:
Antti Palosaarie82eea72011-04-12 19:43:30 -03001008 fe = NULL;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001009 }
1010
Antti Palosaarie82eea72011-04-12 19:43:30 -03001011 if (fe)
1012 ret = 0;
1013 else
1014 ret = -ENODEV;
1015
Antti Palosaari41f81f62011-04-10 17:53:52 -03001016 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001017}
1018
Antti Palosaaria8494682010-10-17 18:25:10 -03001019static int anysee_rc_query(struct dvb_usb_device *d)
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001020{
1021 u8 buf[] = {CMD_GET_IR_CODE};
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001022 u8 ircode[2];
Antti Palosaaria8494682010-10-17 18:25:10 -03001023 int ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001024
Antti Palosaaria8494682010-10-17 18:25:10 -03001025 /* Remote controller is basic NEC using address byte 0x08.
1026 Anysee device RC query returns only two bytes, status and code,
1027 address byte is dropped. Also it does not return any value for
1028 NEC RCs having address byte other than 0x08. Due to that, we
1029 cannot use that device as standard NEC receiver.
1030 It could be possible make hack which reads whole code directly
1031 from device memory... */
1032
1033 ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode));
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001034 if (ret)
1035 return ret;
1036
Antti Palosaaria8494682010-10-17 18:25:10 -03001037 if (ircode[0]) {
1038 deb_rc("%s: key pressed %02x\n", __func__, ircode[1]);
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -03001039 rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001040 }
Antti Palosaaria8494682010-10-17 18:25:10 -03001041
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001042 return 0;
1043}
1044
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001045/* DVB USB Driver stuff */
1046static struct dvb_usb_device_properties anysee_properties;
1047
1048static int anysee_probe(struct usb_interface *intf,
1049 const struct usb_device_id *id)
1050{
1051 struct dvb_usb_device *d;
1052 struct usb_host_interface *alt;
1053 int ret;
1054
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001055 /* There is one interface with two alternate settings.
1056 Alternate setting 0 is for bulk transfer.
1057 Alternate setting 1 is for isochronous transfer.
1058 We use bulk transfer (alternate setting 0). */
1059 if (intf->num_altsetting < 1)
1060 return -ENODEV;
1061
Dan Carpenter8b0d7042010-05-31 16:27:39 -03001062 /*
1063 * Anysee is always warm (its USB-bridge, Cypress FX2, uploads
1064 * firmware from eeprom). If dvb_usb_device_init() succeeds that
1065 * means d is a valid pointer.
1066 */
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001067 ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d,
1068 adapter_nr);
1069 if (ret)
1070 return ret;
1071
1072 alt = usb_altnum_to_altsetting(intf, 0);
1073 if (alt == NULL) {
1074 deb_info("%s: no alt found!\n", __func__);
1075 return -ENODEV;
1076 }
1077
1078 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
1079 alt->desc.bAlternateSetting);
1080 if (ret)
1081 return ret;
1082
Dan Carpenter8b0d7042010-05-31 16:27:39 -03001083 return anysee_init(d);
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001084}
1085
Antti Palosaariae3745f2009-09-16 19:50:25 -03001086static struct usb_device_id anysee_table[] = {
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001087 { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) },
1088 { USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) },
1089 { } /* Terminating entry */
1090};
1091MODULE_DEVICE_TABLE(usb, anysee_table);
1092
1093static struct dvb_usb_device_properties anysee_properties = {
1094 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1095
1096 .usb_ctrl = DEVICE_SPECIFIC,
1097
1098 .size_of_priv = sizeof(struct anysee_state),
1099
1100 .num_adapters = 1,
1101 .adapter = {
1102 {
Michael Krufky77eed212011-09-06 09:31:57 -03001103 .num_frontends = 2,
1104 .frontend_ctrl = anysee_frontend_ctrl,
1105 .fe = {{
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001106 .streaming_ctrl = anysee_streaming_ctrl,
1107 .frontend_attach = anysee_frontend_attach,
1108 .tuner_attach = anysee_tuner_attach,
1109 .stream = {
1110 .type = USB_BULK,
1111 .count = 8,
1112 .endpoint = 0x82,
1113 .u = {
1114 .bulk = {
Antti Palosaariab693332009-09-16 19:47:01 -03001115 .buffersize = (16*512),
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001116 }
1117 }
1118 },
Michael Krufky77eed212011-09-06 09:31:57 -03001119 }, {
1120 .streaming_ctrl = anysee_streaming_ctrl,
1121 .frontend_attach = anysee_frontend_attach,
1122 .tuner_attach = anysee_tuner_attach,
1123 .stream = {
1124 .type = USB_BULK,
1125 .count = 8,
1126 .endpoint = 0x82,
1127 .u = {
1128 .bulk = {
1129 .buffersize = (16*512),
1130 }
1131 }
1132 },
1133 }},
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001134 }
1135 },
1136
Antti Palosaaria8494682010-10-17 18:25:10 -03001137 .rc.core = {
1138 .rc_codes = RC_MAP_ANYSEE,
Mauro Carvalho Chehab52b66142010-11-17 14:20:52 -03001139 .protocol = RC_TYPE_OTHER,
Antti Palosaaria8494682010-10-17 18:25:10 -03001140 .module_name = "anysee",
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001141 .rc_query = anysee_rc_query,
Antti Palosaaria8494682010-10-17 18:25:10 -03001142 .rc_interval = 250, /* windows driver uses 500ms */
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -03001143 },
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001144
1145 .i2c_algo = &anysee_i2c_algo,
1146
1147 .generic_bulk_ctrl_endpoint = 1,
1148
1149 .num_device_descs = 1,
1150 .devices = {
1151 {
1152 .name = "Anysee DVB USB2.0",
1153 .cold_ids = {NULL},
1154 .warm_ids = {&anysee_table[0],
1155 &anysee_table[1], NULL},
1156 },
1157 }
1158};
1159
1160static struct usb_driver anysee_driver = {
1161 .name = "dvb_usb_anysee",
1162 .probe = anysee_probe,
1163 .disconnect = dvb_usb_device_exit,
1164 .id_table = anysee_table,
1165};
1166
1167/* module stuff */
1168static int __init anysee_module_init(void)
1169{
1170 int ret;
1171
1172 ret = usb_register(&anysee_driver);
1173 if (ret)
1174 err("%s: usb_register failed. Error number %d", __func__, ret);
1175
1176 return ret;
1177}
1178
1179static void __exit anysee_module_exit(void)
1180{
1181 /* deregister this driver from the USB subsystem */
1182 usb_deregister(&anysee_driver);
1183}
1184
1185module_init(anysee_module_init);
1186module_exit(anysee_module_exit);
1187
1188MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1189MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
1190MODULE_LICENSE("GPL");