blob: 4dc1ca3332363e7569f34e08a034f13186f677fd [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 Palosaaria51e34d2008-05-17 23:05:48 -030044
45/* debug */
46static int dvb_usb_anysee_debug;
47module_param_named(debug, dvb_usb_anysee_debug, int, 0644);
48MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
Mauro Carvalho Chehabffbc5f82009-01-05 01:34:20 -030049static int dvb_usb_anysee_delsys;
Antti Palosaari0f77c3a2008-08-11 10:54:16 -030050module_param_named(delsys, dvb_usb_anysee_delsys, int, 0644);
51MODULE_PARM_DESC(delsys, "select delivery mode (0=DVB-C, 1=DVB-T)");
Antti Palosaaria51e34d2008-05-17 23:05:48 -030052DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
53
Akinobu Mitadec0c462008-10-29 21:16:04 -030054static DEFINE_MUTEX(anysee_usb_mutex);
Antti Palosaaria51e34d2008-05-17 23:05:48 -030055
56static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
57 u8 *rbuf, u8 rlen)
58{
59 struct anysee_state *state = d->priv;
60 int act_len, ret;
61 u8 buf[64];
62
63 if (slen > sizeof(buf))
64 slen = sizeof(buf);
65 memcpy(&buf[0], sbuf, slen);
66 buf[60] = state->seq++;
67
68 if (mutex_lock_interruptible(&anysee_usb_mutex) < 0)
69 return -EAGAIN;
70
71 /* We need receive one message more after dvb_usb_generic_rw due
72 to weird transaction flow, which is 1 x send + 2 x receive. */
73 ret = dvb_usb_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf), 0);
74
75 if (!ret) {
76 /* receive 2nd answer */
77 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
78 d->props.generic_bulk_ctrl_endpoint), buf, sizeof(buf),
79 &act_len, 2000);
80 if (ret)
81 err("%s: recv bulk message failed: %d", __func__, ret);
82 else {
83 deb_xfer("<<< ");
84 debug_dump(buf, act_len, deb_xfer);
85 }
86 }
87
88 /* read request, copy returned data to return buf */
89 if (!ret && rbuf && rlen)
90 memcpy(rbuf, buf, rlen);
91
92 mutex_unlock(&anysee_usb_mutex);
93
94 return ret;
95}
96
97static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
98{
99 u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};
100 int ret;
101 ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);
102 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, *val);
103 return ret;
104}
105
106static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
107{
108 u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};
109 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, val);
110 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
111}
112
Antti Palosaari41f81f62011-04-10 17:53:52 -0300113/* write single register with mask */
114static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
115 u8 mask)
116{
117 int ret;
118 u8 tmp;
119
120 /* no need for read if whole reg is written */
121 if (mask != 0xff) {
122 ret = anysee_read_reg(d, reg, &tmp);
123 if (ret)
124 return ret;
125
126 val &= mask;
127 tmp &= ~mask;
128 val |= tmp;
129 }
130
131 return anysee_write_reg(d, reg, val);
132}
133
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300134static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
135{
136 u8 buf[] = {CMD_GET_HW_INFO};
137 return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);
138}
139
140static int anysee_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
141{
142 u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};
143 deb_info("%s: onoff:%02x\n", __func__, onoff);
144 return anysee_ctrl_msg(adap->dev, buf, sizeof(buf), NULL, 0);
145}
146
147static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)
148{
149 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};
150 deb_info("%s: state:%02x interval:%02x\n", __func__, mode, interval);
151 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
152}
153
154static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
155{
156 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};
157 deb_info("%s: onoff:%02x\n", __func__, onoff);
158 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
159}
160
161static int anysee_init(struct dvb_usb_device *d)
162{
163 int ret;
164 /* LED light */
165 ret = anysee_led_ctrl(d, 0x01, 0x03);
166 if (ret)
167 return ret;
168
169 /* enable IR */
170 ret = anysee_ir_ctrl(d, 1);
171 if (ret)
172 return ret;
173
174 return 0;
175}
176
177/* I2C */
178static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
179 int num)
180{
181 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Mauro Carvalho Chehab902571a2008-12-29 19:02:24 -0300182 int ret = 0, inc, i = 0;
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)) {
189 u8 buf[6];
190 buf[0] = CMD_I2C_READ;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300191 buf[1] = (msg[i].addr << 1) | 0x01;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300192 buf[2] = msg[i].buf[0];
Antti Palosaari882b82c2011-04-12 19:49:25 -0300193 buf[3] = msg[i].buf[1];
194 buf[4] = msg[i].len-1;
Antti Palosaarib3e6a5a2011-04-09 21:00:51 -0300195 buf[5] = msg[i+1].len;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300196 ret = anysee_ctrl_msg(d, buf, sizeof(buf), msg[i+1].buf,
197 msg[i+1].len);
198 inc = 2;
199 } else {
200 u8 buf[4+msg[i].len];
201 buf[0] = CMD_I2C_WRITE;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300202 buf[1] = (msg[i].addr << 1);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300203 buf[2] = msg[i].len;
204 buf[3] = 0x01;
205 memcpy(&buf[4], msg[i].buf, msg[i].len);
206 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
207 inc = 1;
208 }
209 if (ret)
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300210 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300211
212 i += inc;
213 }
214
215 mutex_unlock(&d->i2c_mutex);
216
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300217 return ret ? ret : i;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300218}
219
220static u32 anysee_i2c_func(struct i2c_adapter *adapter)
221{
222 return I2C_FUNC_I2C;
223}
224
225static struct i2c_algorithm anysee_i2c_algo = {
226 .master_xfer = anysee_master_xfer,
227 .functionality = anysee_i2c_func,
228};
229
230static int anysee_mt352_demod_init(struct dvb_frontend *fe)
231{
Antti Palosaariae3745f2009-09-16 19:50:25 -0300232 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
233 static u8 reset[] = { RESET, 0x80 };
234 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
235 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
236 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300237 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
238
239 mt352_write(fe, clock_config, sizeof(clock_config));
240 udelay(200);
241 mt352_write(fe, reset, sizeof(reset));
242 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
243
244 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
245 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
246 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
247
248 return 0;
249}
250
251/* Callbacks for DVB USB */
252static struct tda10023_config anysee_tda10023_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300253 .demod_address = (0x1a >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300254 .invert = 0,
255 .xtal = 16000000,
256 .pll_m = 11,
257 .pll_p = 3,
258 .pll_n = 1,
Antti Palosaari5ae2fca2008-06-09 22:58:22 -0300259 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
260 .deltaf = 0xfeeb,
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300261};
262
263static struct mt352_config anysee_mt352_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300264 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300265 .demod_init = anysee_mt352_demod_init,
266};
267
268static struct zl10353_config anysee_zl10353_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300269 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300270 .parallel_ts = 1,
271};
272
Antti Palosaari1fd80702011-04-12 17:34:08 -0300273static struct zl10353_config anysee_zl10353_tda18212_config2 = {
274 .demod_address = (0x1e >> 1),
275 .parallel_ts = 1,
276 .disable_i2c_gate_ctrl = 1,
277 .no_tuner = 1,
278 .if2 = 41500,
279};
280
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300281static struct zl10353_config anysee_zl10353_tda18212_config = {
282 .demod_address = (0x18 >> 1),
283 .parallel_ts = 1,
284 .disable_i2c_gate_ctrl = 1,
285 .no_tuner = 1,
286 .if2 = 41500,
287};
288
289static struct tda10023_config anysee_tda10023_tda18212_config = {
290 .demod_address = (0x1a >> 1),
291 .xtal = 16000000,
292 .pll_m = 12,
293 .pll_p = 3,
294 .pll_n = 1,
295 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
296 .deltaf = 0xba02,
297};
298
299static struct tda18212_config anysee_tda18212_config = {
300 .i2c_address = (0xc0 >> 1),
301 .if_dvbt_6 = 4150,
302 .if_dvbt_7 = 4150,
303 .if_dvbt_8 = 4150,
304 .if_dvbc = 5000,
305};
306
Antti Palosaarif0a53102011-04-27 21:11:59 -0300307static struct cx24116_config anysee_cx24116_config = {
308 .demod_address = (0xaa >> 1),
309 .mpg_clk_pos_pol = 0x00,
310 .i2c_wr_max = 48,
311};
312
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300313static struct stv0900_config anysee_stv0900_config = {
314 .demod_address = (0xd0 >> 1),
315 .demod_mode = 0,
316 .xtal = 8000000,
317 .clkmode = 3,
318 .diseqc_mode = 2,
319 .tun1_maddress = 0,
320 .tun1_adc = 1, /* 1 Vpp */
321 .path1_mode = 3,
322};
323
324static struct stv6110_config anysee_stv6110_config = {
325 .i2c_address = (0xc0 >> 1),
326 .mclk = 16000000,
327 .clk_div = 1,
328};
329
Antti Palosaarif0a53102011-04-27 21:11:59 -0300330static struct isl6423_config anysee_isl6423_config = {
331 .current_max = SEC_CURRENT_800m,
332 .curlim = SEC_CURRENT_LIM_OFF,
333 .mod_extern = 1,
334 .addr = (0x10 >> 1),
335};
336
Antti Palosaari41f81f62011-04-10 17:53:52 -0300337/*
338 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
339 * Manufacturer: AMT.CO.KR
340 *
341 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
342 * PCB: ?
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300343 * parts: DNOS404ZH102A(MT352, DTT7579(?))
Antti Palosaari41f81f62011-04-10 17:53:52 -0300344 *
345 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
346 * PCB: ?
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300347 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
Antti Palosaari41f81f62011-04-10 17:53:52 -0300348 *
349 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
350 * PCB: 507CD (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300351 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300352 * OEA=80 OEB=00 OEC=00 OED=ff OEF=fe
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300353 * IOA=4f IOB=ff IOC=00 IOD=06 IOF=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300354 * IOD[0] ZL10353 1=enabled
355 * IOA[7] TS 0=enabled
356 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
357 *
358 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
359 * PCB: 507DC (rev0.2)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300360 * parts: TDA10023, DTOS403IH102B TM, CST56I01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300361 * OEA=80 OEB=00 OEC=00 OED=ff OEF=fe
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300362 * IOA=4f IOB=ff IOC=00 IOD=26 IOF=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300363 * IOD[0] TDA10023 1=enabled
364 *
Antti Palosaarif0a53102011-04-27 21:11:59 -0300365 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
366 * PCB: 507SI (rev2.1)
367 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
368 * OEA=80 OEB=00 OEC=ff OED=ff OEF=fe
369 * IOA=4d IOB=ff IOC=00 IOD=26 IOF=01
370 * IOD[0] CX24116 1=enabled
371 *
Antti Palosaari41f81f62011-04-10 17:53:52 -0300372 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
373 * PCB: 507FA (rev0.4)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300374 * parts: TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari41f81f62011-04-10 17:53:52 -0300375 * OEA=80 OEB=00 OEC=ff OED=ff OEF=ff
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300376 * IOA=4d IOB=ff IOC=00 IOD=00 IOF=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300377 * IOD[5] TDA10023 1=enabled
378 * IOE[0] tuner 1=enabled
379 *
380 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
381 * PCB: 507FA (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300382 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari41f81f62011-04-10 17:53:52 -0300383 * OEA=80 OEB=00 OEC=ff OED=ff OEF=ff
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300384 * IOA=4d IOB=ff IOC=00 IOD=00 IOF=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300385 * DVB-C:
386 * IOD[5] TDA10023 1=enabled
387 * IOE[0] tuner 1=enabled
388 * DVB-T:
389 * IOD[0] ZL10353 1=enabled
390 * IOE[0] tuner 0=enabled
391 * tuner is behind ZL10353 I2C-gate
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300392 *
393 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
394 * PCB: 508TC (rev0.6)
395 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
396 * OEA=80 OEB=00 OEC=03 OED=f7 OEF=ff
397 * IOA=4d IOB=00 IOC=cc IOD=48 IOF=e4
398 * IOA[7] TS 1=enabled
399 * IOE[4] TDA18212 1=enabled
400 * DVB-C:
401 * IOD[6] ZL10353 0=disabled
402 * IOD[5] TDA10023 1=enabled
403 * IOE[0] IF 1=enabled
404 * DVB-T:
405 * IOD[5] TDA10023 0=disabled
406 * IOD[6] ZL10353 1=enabled
407 * IOE[0] IF 0=enabled
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300408 *
409 * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
410 * PCB: 508S2 (rev0.7)
411 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
412 * OEA=80 OEB=00 OEC=03 OED=f7 OEF=ff
413 * IOA=4d IOB=00 IOC=c4 IOD=08 IOF=e4
414 * IOA[7] TS 1=enabled
415 * IOE[5] STV0903 1=enabled
416 *
Antti Palosaari41f81f62011-04-10 17:53:52 -0300417 */
418
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300419static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
420{
421 int ret;
422 struct anysee_state *state = adap->dev->priv;
423 u8 hw_info[3];
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300424 u8 tmp;
425 struct i2c_msg msg[2] = {
426 {
427 .addr = anysee_tda18212_config.i2c_address,
428 .flags = 0,
429 .len = 1,
430 .buf = "\x00",
431 }, {
432 .addr = anysee_tda18212_config.i2c_address,
433 .flags = I2C_M_RD,
434 .len = 1,
435 .buf = &tmp,
436 }
437 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300438
Antti Palosaari41f81f62011-04-10 17:53:52 -0300439 /* Check which hardware we have.
440 * We must do this call two times to get reliable values (hw bug).
441 */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300442 ret = anysee_get_hw_info(adap->dev, hw_info);
443 if (ret)
Antti Palosaari41f81f62011-04-10 17:53:52 -0300444 goto error;
445
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300446 ret = anysee_get_hw_info(adap->dev, hw_info);
447 if (ret)
Antti Palosaari41f81f62011-04-10 17:53:52 -0300448 goto error;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300449
450 /* Meaning of these info bytes are guessed. */
Antti Palosaari592d9e22011-04-09 21:13:33 -0300451 info("firmware version:%d.%d hardware id:%d",
452 hw_info[1], hw_info[2], hw_info[0]);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300453
Antti Palosaari41f81f62011-04-10 17:53:52 -0300454 state->hw = hw_info[0];
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300455
Antti Palosaari41f81f62011-04-10 17:53:52 -0300456 switch (state->hw) {
457 case ANYSEE_HW_02: /* 2 */
458 /* E30 */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300459
Antti Palosaari41f81f62011-04-10 17:53:52 -0300460 /* attach demod */
461 adap->fe = dvb_attach(mt352_attach, &anysee_mt352_config,
462 &adap->dev->i2c_adap);
463 if (adap->fe)
464 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300465
Antti Palosaari41f81f62011-04-10 17:53:52 -0300466 /* attach demod */
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300467 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
Antti Palosaari41f81f62011-04-10 17:53:52 -0300468 &adap->dev->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300469
470 break;
471 case ANYSEE_HW_507CD: /* 6 */
472 /* E30 Plus */
473
474 /* enable DVB-T demod on IOD[0] */
475 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
476 if (ret)
477 goto error;
478
479 /* enable transport stream on IOA[7] */
480 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (0 << 7), 0x80);
481 if (ret)
482 goto error;
483
484 /* attach demod */
485 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
486 &adap->dev->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300487
488 break;
489 case ANYSEE_HW_507DC: /* 10 */
490 /* E30 C Plus */
491
492 /* enable DVB-C demod on IOD[0] */
493 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
494 if (ret)
495 goto error;
496
497 /* attach demod */
498 adap->fe = dvb_attach(tda10023_attach, &anysee_tda10023_config,
499 &adap->dev->i2c_adap, 0x48);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300500
501 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300502 case ANYSEE_HW_507SI: /* 11 */
503 /* E30 S2 Plus */
504
505 /* enable DVB-S/S2 demod on IOD[0] */
506 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
507 if (ret)
508 goto error;
509
510 /* attach demod */
511 adap->fe = dvb_attach(cx24116_attach, &anysee_cx24116_config,
512 &adap->dev->i2c_adap);
513
514 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300515 case ANYSEE_HW_507FA: /* 15 */
516 /* E30 Combo Plus */
517 /* E30 C Plus */
518
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300519 /* enable tuner on IOE[4] */
520 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
521 if (ret)
522 goto error;
523
524 /* probe TDA18212 */
525 tmp = 0;
526 ret = i2c_transfer(&adap->dev->i2c_adap, msg, 2);
527 if (ret == 2 && tmp == 0xc7)
528 deb_info("%s: TDA18212 found\n", __func__);
529 else
530 tmp = 0;
531
532 /* disable tuner on IOE[4] */
533 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);
534 if (ret)
535 goto error;
536
Antti Palosaari41f81f62011-04-10 17:53:52 -0300537 if (dvb_usb_anysee_delsys) {
538 /* disable DVB-C demod on IOD[5] */
539 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
540 0x20);
541 if (ret)
542 goto error;
543
544 /* enable DVB-T demod on IOD[0] */
545 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),
546 0x01);
547 if (ret)
548 goto error;
549
550 /* attach demod */
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300551 if (tmp == 0xc7) {
552 /* TDA18212 config */
553 adap->fe = dvb_attach(zl10353_attach,
Antti Palosaari1fd80702011-04-12 17:34:08 -0300554 &anysee_zl10353_tda18212_config2,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300555 &adap->dev->i2c_adap);
556 } else {
557 /* PLL config */
558 adap->fe = dvb_attach(zl10353_attach,
559 &anysee_zl10353_config,
560 &adap->dev->i2c_adap);
561 }
Antti Palosaari41f81f62011-04-10 17:53:52 -0300562 } else {
563 /* disable DVB-T demod on IOD[0] */
564 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0),
565 0x01);
566 if (ret)
567 goto error;
568
569 /* enable DVB-C demod on IOD[5] */
570 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
571 0x20);
572 if (ret)
573 goto error;
574
575 /* attach demod */
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300576 if (tmp == 0xc7) {
577 /* TDA18212 config */
578 adap->fe = dvb_attach(tda10023_attach,
579 &anysee_tda10023_tda18212_config,
580 &adap->dev->i2c_adap, 0x48);
581 } else {
582 /* PLL config */
583 adap->fe = dvb_attach(tda10023_attach,
584 &anysee_tda10023_config,
585 &adap->dev->i2c_adap, 0x48);
586 }
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300587 }
Antti Palosaarie82eea72011-04-12 19:43:30 -0300588
Antti Palosaari41f81f62011-04-10 17:53:52 -0300589 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300590 case ANYSEE_HW_508TC: /* 18 */
591 /* E7 TC */
592
593 /* enable transport stream on IOA[7] */
594 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);
595 if (ret)
596 goto error;
597
598 if (dvb_usb_anysee_delsys) {
599 /* disable DVB-C demod on IOD[5] */
600 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
601 0x20);
602 if (ret)
603 goto error;
604
605 /* enable DVB-T demod on IOD[6] */
606 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6),
607 0x40);
608 if (ret)
609 goto error;
610
611 /* enable IF route on IOE[0] */
612 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
613 0x01);
614 if (ret)
615 goto error;
616
617 /* attach demod */
618 adap->fe = dvb_attach(zl10353_attach,
619 &anysee_zl10353_tda18212_config,
620 &adap->dev->i2c_adap);
Antti Palosaaria43be982011-04-10 20:23:02 -0300621 } else {
622 /* disable DVB-T demod on IOD[6] */
623 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
624 0x40);
625 if (ret)
626 goto error;
627
628 /* enable DVB-C demod on IOD[5] */
629 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
630 0x20);
631 if (ret)
632 goto error;
633
634 /* enable IF route on IOE[0] */
635 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
636 0x01);
637 if (ret)
638 goto error;
639
640 /* attach demod */
641 adap->fe = dvb_attach(tda10023_attach,
642 &anysee_tda10023_tda18212_config,
643 &adap->dev->i2c_adap, 0x48);
Antti Palosaaria43be982011-04-10 20:23:02 -0300644 }
Antti Palosaarie82eea72011-04-12 19:43:30 -0300645
Antti Palosaaria43be982011-04-10 20:23:02 -0300646 break;
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300647 case ANYSEE_HW_508S2: /* 19 */
648 /* E7 S2 */
649
650 /* enable transport stream on IOA[7] */
651 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);
652 if (ret)
653 goto error;
654
655 /* enable DVB-S/S2 demod on IOE[5] */
656 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20);
657 if (ret)
658 goto error;
659
660 /* attach demod */
661 adap->fe = dvb_attach(stv0900_attach, &anysee_stv0900_config,
662 &adap->dev->i2c_adap, 0);
663
664 break;
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300665 }
666
Antti Palosaari41f81f62011-04-10 17:53:52 -0300667 if (!adap->fe) {
668 /* we have no frontend :-( */
669 ret = -ENODEV;
Antti Palosaarie82eea72011-04-12 19:43:30 -0300670 err("Unsupported Anysee version. " \
671 "Please report the <linux-media@vger.kernel.org>.");
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300672 }
Antti Palosaari41f81f62011-04-10 17:53:52 -0300673error:
674 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300675}
676
677static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
678{
679 struct anysee_state *state = adap->dev->priv;
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300680 struct dvb_frontend *fe;
Antti Palosaarie82eea72011-04-12 19:43:30 -0300681 int ret;
Antti Palosaaria8494682010-10-17 18:25:10 -0300682 deb_info("%s:\n", __func__);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300683
Antti Palosaari41f81f62011-04-10 17:53:52 -0300684 switch (state->hw) {
685 case ANYSEE_HW_02: /* 2 */
686 /* E30 */
687
688 /* attach tuner */
Antti Palosaarie82eea72011-04-12 19:43:30 -0300689 fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1),
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300690 NULL, DVB_PLL_THOMSON_DTT7579);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300691
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300692 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300693 case ANYSEE_HW_507CD: /* 6 */
694 /* E30 Plus */
695
696 /* attach tuner */
Antti Palosaarie82eea72011-04-12 19:43:30 -0300697 fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1),
Antti Palosaari41f81f62011-04-10 17:53:52 -0300698 &adap->dev->i2c_adap, DVB_PLL_THOMSON_DTT7579);
699
700 break;
701 case ANYSEE_HW_507DC: /* 10 */
702 /* E30 C Plus */
703
704 /* attach tuner */
Antti Palosaarie82eea72011-04-12 19:43:30 -0300705 fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1),
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300706 &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300707
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300708 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300709 case ANYSEE_HW_507SI: /* 11 */
710 /* E30 S2 Plus */
711
712 /* attach LNB controller */
713 fe = dvb_attach(isl6423_attach, adap->fe, &adap->dev->i2c_adap,
714 &anysee_isl6423_config);
715
716 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300717 case ANYSEE_HW_507FA: /* 15 */
718 /* E30 Combo Plus */
719 /* E30 C Plus */
720
Antti Palosaari59fb4142011-04-12 10:22:47 -0300721 if (dvb_usb_anysee_delsys) {
722 /* enable DVB-T tuner on IOE[0] */
723 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
724 0x01);
725 if (ret)
726 goto error;
727 } else {
728 /* enable DVB-C tuner on IOE[0] */
729 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
730 0x01);
731 if (ret)
732 goto error;
733 }
734
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300735 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
736 * fails attach old simple PLL. */
737
738 /* enable tuner on IOE[4] */
739 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
740 if (ret)
741 goto error;
742
743 /* attach tuner */
744 fe = dvb_attach(tda18212_attach, adap->fe, &adap->dev->i2c_adap,
745 &anysee_tda18212_config);
746 if (fe)
747 break;
748
749 /* disable tuner on IOE[4] */
750 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);
751 if (ret)
752 goto error;
753
Antti Palosaari41f81f62011-04-10 17:53:52 -0300754 /* attach tuner */
Antti Palosaarie82eea72011-04-12 19:43:30 -0300755 fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1),
Antti Palosaari41f81f62011-04-10 17:53:52 -0300756 &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
757
758 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300759 case ANYSEE_HW_508TC: /* 18 */
760 /* E7 TC */
761
762 /* enable tuner on IOE[4] */
763 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
764 if (ret)
765 goto error;
766
767 /* attach tuner */
768 fe = dvb_attach(tda18212_attach, adap->fe, &adap->dev->i2c_adap,
769 &anysee_tda18212_config);
Antti Palosaaria43be982011-04-10 20:23:02 -0300770
771 break;
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300772 case ANYSEE_HW_508S2: /* 19 */
773 /* E7 S2 */
774
775 /* attach tuner */
776 fe = dvb_attach(stv6110_attach, adap->fe,
777 &anysee_stv6110_config, &adap->dev->i2c_adap);
778
779 if (fe) {
780 /* attach LNB controller */
781 fe = dvb_attach(isl6423_attach, adap->fe,
782 &adap->dev->i2c_adap, &anysee_isl6423_config);
783 }
784
785 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300786 default:
Antti Palosaarie82eea72011-04-12 19:43:30 -0300787 fe = NULL;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300788 }
789
Antti Palosaarie82eea72011-04-12 19:43:30 -0300790 if (fe)
791 ret = 0;
792 else
793 ret = -ENODEV;
794
Antti Palosaari41f81f62011-04-10 17:53:52 -0300795error:
796 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300797}
798
Antti Palosaaria8494682010-10-17 18:25:10 -0300799static int anysee_rc_query(struct dvb_usb_device *d)
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300800{
801 u8 buf[] = {CMD_GET_IR_CODE};
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300802 u8 ircode[2];
Antti Palosaaria8494682010-10-17 18:25:10 -0300803 int ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300804
Antti Palosaaria8494682010-10-17 18:25:10 -0300805 /* Remote controller is basic NEC using address byte 0x08.
806 Anysee device RC query returns only two bytes, status and code,
807 address byte is dropped. Also it does not return any value for
808 NEC RCs having address byte other than 0x08. Due to that, we
809 cannot use that device as standard NEC receiver.
810 It could be possible make hack which reads whole code directly
811 from device memory... */
812
813 ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode));
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300814 if (ret)
815 return ret;
816
Antti Palosaaria8494682010-10-17 18:25:10 -0300817 if (ircode[0]) {
818 deb_rc("%s: key pressed %02x\n", __func__, ircode[1]);
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -0300819 rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300820 }
Antti Palosaaria8494682010-10-17 18:25:10 -0300821
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300822 return 0;
823}
824
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300825/* DVB USB Driver stuff */
826static struct dvb_usb_device_properties anysee_properties;
827
828static int anysee_probe(struct usb_interface *intf,
829 const struct usb_device_id *id)
830{
831 struct dvb_usb_device *d;
832 struct usb_host_interface *alt;
833 int ret;
834
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300835 /* There is one interface with two alternate settings.
836 Alternate setting 0 is for bulk transfer.
837 Alternate setting 1 is for isochronous transfer.
838 We use bulk transfer (alternate setting 0). */
839 if (intf->num_altsetting < 1)
840 return -ENODEV;
841
Dan Carpenter8b0d7042010-05-31 16:27:39 -0300842 /*
843 * Anysee is always warm (its USB-bridge, Cypress FX2, uploads
844 * firmware from eeprom). If dvb_usb_device_init() succeeds that
845 * means d is a valid pointer.
846 */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300847 ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d,
848 adapter_nr);
849 if (ret)
850 return ret;
851
852 alt = usb_altnum_to_altsetting(intf, 0);
853 if (alt == NULL) {
854 deb_info("%s: no alt found!\n", __func__);
855 return -ENODEV;
856 }
857
858 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
859 alt->desc.bAlternateSetting);
860 if (ret)
861 return ret;
862
Dan Carpenter8b0d7042010-05-31 16:27:39 -0300863 return anysee_init(d);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300864}
865
Antti Palosaariae3745f2009-09-16 19:50:25 -0300866static struct usb_device_id anysee_table[] = {
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300867 { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) },
868 { USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) },
869 { } /* Terminating entry */
870};
871MODULE_DEVICE_TABLE(usb, anysee_table);
872
873static struct dvb_usb_device_properties anysee_properties = {
874 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
875
876 .usb_ctrl = DEVICE_SPECIFIC,
877
878 .size_of_priv = sizeof(struct anysee_state),
879
880 .num_adapters = 1,
881 .adapter = {
882 {
883 .streaming_ctrl = anysee_streaming_ctrl,
884 .frontend_attach = anysee_frontend_attach,
885 .tuner_attach = anysee_tuner_attach,
886 .stream = {
887 .type = USB_BULK,
888 .count = 8,
889 .endpoint = 0x82,
890 .u = {
891 .bulk = {
Antti Palosaariab693332009-09-16 19:47:01 -0300892 .buffersize = (16*512),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300893 }
894 }
895 },
896 }
897 },
898
Antti Palosaaria8494682010-10-17 18:25:10 -0300899 .rc.core = {
900 .rc_codes = RC_MAP_ANYSEE,
Mauro Carvalho Chehab52b66142010-11-17 14:20:52 -0300901 .protocol = RC_TYPE_OTHER,
Antti Palosaaria8494682010-10-17 18:25:10 -0300902 .module_name = "anysee",
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300903 .rc_query = anysee_rc_query,
Antti Palosaaria8494682010-10-17 18:25:10 -0300904 .rc_interval = 250, /* windows driver uses 500ms */
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300905 },
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300906
907 .i2c_algo = &anysee_i2c_algo,
908
909 .generic_bulk_ctrl_endpoint = 1,
910
911 .num_device_descs = 1,
912 .devices = {
913 {
914 .name = "Anysee DVB USB2.0",
915 .cold_ids = {NULL},
916 .warm_ids = {&anysee_table[0],
917 &anysee_table[1], NULL},
918 },
919 }
920};
921
922static struct usb_driver anysee_driver = {
923 .name = "dvb_usb_anysee",
924 .probe = anysee_probe,
925 .disconnect = dvb_usb_device_exit,
926 .id_table = anysee_table,
927};
928
929/* module stuff */
930static int __init anysee_module_init(void)
931{
932 int ret;
933
934 ret = usb_register(&anysee_driver);
935 if (ret)
936 err("%s: usb_register failed. Error number %d", __func__, ret);
937
938 return ret;
939}
940
941static void __exit anysee_module_exit(void)
942{
943 /* deregister this driver from the USB subsystem */
944 usb_deregister(&anysee_driver);
945}
946
947module_init(anysee_module_init);
948module_exit(anysee_module_exit);
949
950MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
951MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
952MODULE_LICENSE("GPL");