blob: ebcc05b73c7f4702148aa14031f9611012aebc4d [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"
41#include "isl6423.h"
Antti Palosaaria51e34d2008-05-17 23:05:48 -030042
43/* debug */
44static int dvb_usb_anysee_debug;
45module_param_named(debug, dvb_usb_anysee_debug, int, 0644);
46MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
Mauro Carvalho Chehabffbc5f82009-01-05 01:34:20 -030047static int dvb_usb_anysee_delsys;
Antti Palosaari0f77c3a2008-08-11 10:54:16 -030048module_param_named(delsys, dvb_usb_anysee_delsys, int, 0644);
49MODULE_PARM_DESC(delsys, "select delivery mode (0=DVB-C, 1=DVB-T)");
Antti Palosaaria51e34d2008-05-17 23:05:48 -030050DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
51
Akinobu Mitadec0c462008-10-29 21:16:04 -030052static DEFINE_MUTEX(anysee_usb_mutex);
Antti Palosaaria51e34d2008-05-17 23:05:48 -030053
54static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
55 u8 *rbuf, u8 rlen)
56{
57 struct anysee_state *state = d->priv;
58 int act_len, ret;
59 u8 buf[64];
60
61 if (slen > sizeof(buf))
62 slen = sizeof(buf);
63 memcpy(&buf[0], sbuf, slen);
64 buf[60] = state->seq++;
65
66 if (mutex_lock_interruptible(&anysee_usb_mutex) < 0)
67 return -EAGAIN;
68
69 /* We need receive one message more after dvb_usb_generic_rw due
70 to weird transaction flow, which is 1 x send + 2 x receive. */
71 ret = dvb_usb_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf), 0);
72
73 if (!ret) {
74 /* receive 2nd answer */
75 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
76 d->props.generic_bulk_ctrl_endpoint), buf, sizeof(buf),
77 &act_len, 2000);
78 if (ret)
79 err("%s: recv bulk message failed: %d", __func__, ret);
80 else {
81 deb_xfer("<<< ");
82 debug_dump(buf, act_len, deb_xfer);
83 }
84 }
85
86 /* read request, copy returned data to return buf */
87 if (!ret && rbuf && rlen)
88 memcpy(rbuf, buf, rlen);
89
90 mutex_unlock(&anysee_usb_mutex);
91
92 return ret;
93}
94
95static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
96{
97 u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};
98 int ret;
99 ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);
100 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, *val);
101 return ret;
102}
103
104static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
105{
106 u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};
107 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, val);
108 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
109}
110
Antti Palosaari41f81f62011-04-10 17:53:52 -0300111/* write single register with mask */
112static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
113 u8 mask)
114{
115 int ret;
116 u8 tmp;
117
118 /* no need for read if whole reg is written */
119 if (mask != 0xff) {
120 ret = anysee_read_reg(d, reg, &tmp);
121 if (ret)
122 return ret;
123
124 val &= mask;
125 tmp &= ~mask;
126 val |= tmp;
127 }
128
129 return anysee_write_reg(d, reg, val);
130}
131
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300132static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
133{
134 u8 buf[] = {CMD_GET_HW_INFO};
135 return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);
136}
137
138static int anysee_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
139{
140 u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};
141 deb_info("%s: onoff:%02x\n", __func__, onoff);
142 return anysee_ctrl_msg(adap->dev, buf, sizeof(buf), NULL, 0);
143}
144
145static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)
146{
147 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};
148 deb_info("%s: state:%02x interval:%02x\n", __func__, mode, interval);
149 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
150}
151
152static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
153{
154 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};
155 deb_info("%s: onoff:%02x\n", __func__, onoff);
156 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
157}
158
159static int anysee_init(struct dvb_usb_device *d)
160{
161 int ret;
162 /* LED light */
163 ret = anysee_led_ctrl(d, 0x01, 0x03);
164 if (ret)
165 return ret;
166
167 /* enable IR */
168 ret = anysee_ir_ctrl(d, 1);
169 if (ret)
170 return ret;
171
172 return 0;
173}
174
175/* I2C */
176static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
177 int num)
178{
179 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Mauro Carvalho Chehab902571a2008-12-29 19:02:24 -0300180 int ret = 0, inc, i = 0;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300181
182 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
183 return -EAGAIN;
184
185 while (i < num) {
186 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
187 u8 buf[6];
188 buf[0] = CMD_I2C_READ;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300189 buf[1] = (msg[i].addr << 1) | 0x01;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300190 buf[2] = msg[i].buf[0];
Antti Palosaari882b82c2011-04-12 19:49:25 -0300191 buf[3] = msg[i].buf[1];
192 buf[4] = msg[i].len-1;
Antti Palosaarib3e6a5a2011-04-09 21:00:51 -0300193 buf[5] = msg[i+1].len;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300194 ret = anysee_ctrl_msg(d, buf, sizeof(buf), msg[i+1].buf,
195 msg[i+1].len);
196 inc = 2;
197 } else {
198 u8 buf[4+msg[i].len];
199 buf[0] = CMD_I2C_WRITE;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300200 buf[1] = (msg[i].addr << 1);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300201 buf[2] = msg[i].len;
202 buf[3] = 0x01;
203 memcpy(&buf[4], msg[i].buf, msg[i].len);
204 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
205 inc = 1;
206 }
207 if (ret)
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300208 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300209
210 i += inc;
211 }
212
213 mutex_unlock(&d->i2c_mutex);
214
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300215 return ret ? ret : i;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300216}
217
218static u32 anysee_i2c_func(struct i2c_adapter *adapter)
219{
220 return I2C_FUNC_I2C;
221}
222
223static struct i2c_algorithm anysee_i2c_algo = {
224 .master_xfer = anysee_master_xfer,
225 .functionality = anysee_i2c_func,
226};
227
228static int anysee_mt352_demod_init(struct dvb_frontend *fe)
229{
Antti Palosaariae3745f2009-09-16 19:50:25 -0300230 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
231 static u8 reset[] = { RESET, 0x80 };
232 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
233 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
234 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300235 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
236
237 mt352_write(fe, clock_config, sizeof(clock_config));
238 udelay(200);
239 mt352_write(fe, reset, sizeof(reset));
240 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
241
242 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
243 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
244 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
245
246 return 0;
247}
248
249/* Callbacks for DVB USB */
250static struct tda10023_config anysee_tda10023_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300251 .demod_address = (0x1a >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300252 .invert = 0,
253 .xtal = 16000000,
254 .pll_m = 11,
255 .pll_p = 3,
256 .pll_n = 1,
Antti Palosaari5ae2fca2008-06-09 22:58:22 -0300257 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
258 .deltaf = 0xfeeb,
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300259};
260
261static struct mt352_config anysee_mt352_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300262 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300263 .demod_init = anysee_mt352_demod_init,
264};
265
266static struct zl10353_config anysee_zl10353_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300267 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300268 .parallel_ts = 1,
269};
270
Antti Palosaari1fd80702011-04-12 17:34:08 -0300271static struct zl10353_config anysee_zl10353_tda18212_config2 = {
272 .demod_address = (0x1e >> 1),
273 .parallel_ts = 1,
274 .disable_i2c_gate_ctrl = 1,
275 .no_tuner = 1,
276 .if2 = 41500,
277};
278
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300279static struct zl10353_config anysee_zl10353_tda18212_config = {
280 .demod_address = (0x18 >> 1),
281 .parallel_ts = 1,
282 .disable_i2c_gate_ctrl = 1,
283 .no_tuner = 1,
284 .if2 = 41500,
285};
286
287static struct tda10023_config anysee_tda10023_tda18212_config = {
288 .demod_address = (0x1a >> 1),
289 .xtal = 16000000,
290 .pll_m = 12,
291 .pll_p = 3,
292 .pll_n = 1,
293 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
294 .deltaf = 0xba02,
295};
296
297static struct tda18212_config anysee_tda18212_config = {
298 .i2c_address = (0xc0 >> 1),
299 .if_dvbt_6 = 4150,
300 .if_dvbt_7 = 4150,
301 .if_dvbt_8 = 4150,
302 .if_dvbc = 5000,
303};
304
Antti Palosaarif0a53102011-04-27 21:11:59 -0300305static struct cx24116_config anysee_cx24116_config = {
306 .demod_address = (0xaa >> 1),
307 .mpg_clk_pos_pol = 0x00,
308 .i2c_wr_max = 48,
309};
310
311static struct isl6423_config anysee_isl6423_config = {
312 .current_max = SEC_CURRENT_800m,
313 .curlim = SEC_CURRENT_LIM_OFF,
314 .mod_extern = 1,
315 .addr = (0x10 >> 1),
316};
317
Antti Palosaari41f81f62011-04-10 17:53:52 -0300318/*
319 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
320 * Manufacturer: AMT.CO.KR
321 *
322 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
323 * PCB: ?
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300324 * parts: DNOS404ZH102A(MT352, DTT7579(?))
Antti Palosaari41f81f62011-04-10 17:53:52 -0300325 *
326 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
327 * PCB: ?
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300328 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
Antti Palosaari41f81f62011-04-10 17:53:52 -0300329 *
330 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
331 * PCB: 507CD (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300332 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300333 * OEA=80 OEB=00 OEC=00 OED=ff OEF=fe
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300334 * IOA=4f IOB=ff IOC=00 IOD=06 IOF=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300335 * IOD[0] ZL10353 1=enabled
336 * IOA[7] TS 0=enabled
337 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
338 *
339 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
340 * PCB: 507DC (rev0.2)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300341 * parts: TDA10023, DTOS403IH102B TM, CST56I01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300342 * OEA=80 OEB=00 OEC=00 OED=ff OEF=fe
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300343 * IOA=4f IOB=ff IOC=00 IOD=26 IOF=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300344 * IOD[0] TDA10023 1=enabled
345 *
Antti Palosaarif0a53102011-04-27 21:11:59 -0300346 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
347 * PCB: 507SI (rev2.1)
348 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
349 * OEA=80 OEB=00 OEC=ff OED=ff OEF=fe
350 * IOA=4d IOB=ff IOC=00 IOD=26 IOF=01
351 * IOD[0] CX24116 1=enabled
352 *
Antti Palosaari41f81f62011-04-10 17:53:52 -0300353 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
354 * PCB: 507FA (rev0.4)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300355 * parts: TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari41f81f62011-04-10 17:53:52 -0300356 * OEA=80 OEB=00 OEC=ff OED=ff OEF=ff
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300357 * IOA=4d IOB=ff IOC=00 IOD=00 IOF=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300358 * IOD[5] TDA10023 1=enabled
359 * IOE[0] tuner 1=enabled
360 *
361 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
362 * PCB: 507FA (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300363 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari41f81f62011-04-10 17:53:52 -0300364 * OEA=80 OEB=00 OEC=ff OED=ff OEF=ff
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300365 * IOA=4d IOB=ff IOC=00 IOD=00 IOF=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300366 * DVB-C:
367 * IOD[5] TDA10023 1=enabled
368 * IOE[0] tuner 1=enabled
369 * DVB-T:
370 * IOD[0] ZL10353 1=enabled
371 * IOE[0] tuner 0=enabled
372 * tuner is behind ZL10353 I2C-gate
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300373 *
374 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
375 * PCB: 508TC (rev0.6)
376 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
377 * OEA=80 OEB=00 OEC=03 OED=f7 OEF=ff
378 * IOA=4d IOB=00 IOC=cc IOD=48 IOF=e4
379 * IOA[7] TS 1=enabled
380 * IOE[4] TDA18212 1=enabled
381 * DVB-C:
382 * IOD[6] ZL10353 0=disabled
383 * IOD[5] TDA10023 1=enabled
384 * IOE[0] IF 1=enabled
385 * DVB-T:
386 * IOD[5] TDA10023 0=disabled
387 * IOD[6] ZL10353 1=enabled
388 * IOE[0] IF 0=enabled
Antti Palosaari41f81f62011-04-10 17:53:52 -0300389 */
390
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300391static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
392{
393 int ret;
394 struct anysee_state *state = adap->dev->priv;
395 u8 hw_info[3];
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300396 u8 tmp;
397 struct i2c_msg msg[2] = {
398 {
399 .addr = anysee_tda18212_config.i2c_address,
400 .flags = 0,
401 .len = 1,
402 .buf = "\x00",
403 }, {
404 .addr = anysee_tda18212_config.i2c_address,
405 .flags = I2C_M_RD,
406 .len = 1,
407 .buf = &tmp,
408 }
409 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300410
Antti Palosaari41f81f62011-04-10 17:53:52 -0300411 /* Check which hardware we have.
412 * We must do this call two times to get reliable values (hw bug).
413 */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300414 ret = anysee_get_hw_info(adap->dev, hw_info);
415 if (ret)
Antti Palosaari41f81f62011-04-10 17:53:52 -0300416 goto error;
417
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300418 ret = anysee_get_hw_info(adap->dev, hw_info);
419 if (ret)
Antti Palosaari41f81f62011-04-10 17:53:52 -0300420 goto error;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300421
422 /* Meaning of these info bytes are guessed. */
Antti Palosaari592d9e22011-04-09 21:13:33 -0300423 info("firmware version:%d.%d hardware id:%d",
424 hw_info[1], hw_info[2], hw_info[0]);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300425
Antti Palosaari41f81f62011-04-10 17:53:52 -0300426 state->hw = hw_info[0];
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300427
Antti Palosaari41f81f62011-04-10 17:53:52 -0300428 switch (state->hw) {
429 case ANYSEE_HW_02: /* 2 */
430 /* E30 */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300431
Antti Palosaari41f81f62011-04-10 17:53:52 -0300432 /* attach demod */
433 adap->fe = dvb_attach(mt352_attach, &anysee_mt352_config,
434 &adap->dev->i2c_adap);
435 if (adap->fe)
436 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300437
Antti Palosaari41f81f62011-04-10 17:53:52 -0300438 /* attach demod */
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300439 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
Antti Palosaari41f81f62011-04-10 17:53:52 -0300440 &adap->dev->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300441
442 break;
443 case ANYSEE_HW_507CD: /* 6 */
444 /* E30 Plus */
445
446 /* enable DVB-T demod on IOD[0] */
447 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
448 if (ret)
449 goto error;
450
451 /* enable transport stream on IOA[7] */
452 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (0 << 7), 0x80);
453 if (ret)
454 goto error;
455
456 /* attach demod */
457 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
458 &adap->dev->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300459
460 break;
461 case ANYSEE_HW_507DC: /* 10 */
462 /* E30 C Plus */
463
464 /* enable DVB-C demod on IOD[0] */
465 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
466 if (ret)
467 goto error;
468
469 /* attach demod */
470 adap->fe = dvb_attach(tda10023_attach, &anysee_tda10023_config,
471 &adap->dev->i2c_adap, 0x48);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300472
473 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300474 case ANYSEE_HW_507SI: /* 11 */
475 /* E30 S2 Plus */
476
477 /* enable DVB-S/S2 demod on IOD[0] */
478 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
479 if (ret)
480 goto error;
481
482 /* attach demod */
483 adap->fe = dvb_attach(cx24116_attach, &anysee_cx24116_config,
484 &adap->dev->i2c_adap);
485
486 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300487 case ANYSEE_HW_507FA: /* 15 */
488 /* E30 Combo Plus */
489 /* E30 C Plus */
490
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300491 /* enable tuner on IOE[4] */
492 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
493 if (ret)
494 goto error;
495
496 /* probe TDA18212 */
497 tmp = 0;
498 ret = i2c_transfer(&adap->dev->i2c_adap, msg, 2);
499 if (ret == 2 && tmp == 0xc7)
500 deb_info("%s: TDA18212 found\n", __func__);
501 else
502 tmp = 0;
503
504 /* disable tuner on IOE[4] */
505 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);
506 if (ret)
507 goto error;
508
Antti Palosaari41f81f62011-04-10 17:53:52 -0300509 if (dvb_usb_anysee_delsys) {
510 /* disable DVB-C demod on IOD[5] */
511 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
512 0x20);
513 if (ret)
514 goto error;
515
516 /* enable DVB-T demod on IOD[0] */
517 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),
518 0x01);
519 if (ret)
520 goto error;
521
522 /* attach demod */
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300523 if (tmp == 0xc7) {
524 /* TDA18212 config */
525 adap->fe = dvb_attach(zl10353_attach,
Antti Palosaari1fd80702011-04-12 17:34:08 -0300526 &anysee_zl10353_tda18212_config2,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300527 &adap->dev->i2c_adap);
528 } else {
529 /* PLL config */
530 adap->fe = dvb_attach(zl10353_attach,
531 &anysee_zl10353_config,
532 &adap->dev->i2c_adap);
533 }
Antti Palosaari41f81f62011-04-10 17:53:52 -0300534 } else {
535 /* disable DVB-T demod on IOD[0] */
536 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0),
537 0x01);
538 if (ret)
539 goto error;
540
541 /* enable DVB-C demod on IOD[5] */
542 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
543 0x20);
544 if (ret)
545 goto error;
546
547 /* attach demod */
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300548 if (tmp == 0xc7) {
549 /* TDA18212 config */
550 adap->fe = dvb_attach(tda10023_attach,
551 &anysee_tda10023_tda18212_config,
552 &adap->dev->i2c_adap, 0x48);
553 } else {
554 /* PLL config */
555 adap->fe = dvb_attach(tda10023_attach,
556 &anysee_tda10023_config,
557 &adap->dev->i2c_adap, 0x48);
558 }
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300559 }
Antti Palosaarie82eea72011-04-12 19:43:30 -0300560
Antti Palosaari41f81f62011-04-10 17:53:52 -0300561 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300562 case ANYSEE_HW_508TC: /* 18 */
563 /* E7 TC */
564
565 /* enable transport stream on IOA[7] */
566 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (1 << 7), 0x80);
567 if (ret)
568 goto error;
569
570 if (dvb_usb_anysee_delsys) {
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 /* attach demod */
590 adap->fe = dvb_attach(zl10353_attach,
591 &anysee_zl10353_tda18212_config,
592 &adap->dev->i2c_adap);
Antti Palosaaria43be982011-04-10 20:23:02 -0300593 } else {
594 /* disable DVB-T demod on IOD[6] */
595 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
596 0x40);
597 if (ret)
598 goto error;
599
600 /* enable DVB-C demod on IOD[5] */
601 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
602 0x20);
603 if (ret)
604 goto error;
605
606 /* enable IF route on IOE[0] */
607 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
608 0x01);
609 if (ret)
610 goto error;
611
612 /* attach demod */
613 adap->fe = dvb_attach(tda10023_attach,
614 &anysee_tda10023_tda18212_config,
615 &adap->dev->i2c_adap, 0x48);
Antti Palosaaria43be982011-04-10 20:23:02 -0300616 }
Antti Palosaarie82eea72011-04-12 19:43:30 -0300617
Antti Palosaaria43be982011-04-10 20:23:02 -0300618 break;
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300619 }
620
Antti Palosaari41f81f62011-04-10 17:53:52 -0300621 if (!adap->fe) {
622 /* we have no frontend :-( */
623 ret = -ENODEV;
Antti Palosaarie82eea72011-04-12 19:43:30 -0300624 err("Unsupported Anysee version. " \
625 "Please report the <linux-media@vger.kernel.org>.");
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300626 }
Antti Palosaari41f81f62011-04-10 17:53:52 -0300627error:
628 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300629}
630
631static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
632{
633 struct anysee_state *state = adap->dev->priv;
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300634 struct dvb_frontend *fe;
Antti Palosaarie82eea72011-04-12 19:43:30 -0300635 int ret;
Antti Palosaaria8494682010-10-17 18:25:10 -0300636 deb_info("%s:\n", __func__);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300637
Antti Palosaari41f81f62011-04-10 17:53:52 -0300638 switch (state->hw) {
639 case ANYSEE_HW_02: /* 2 */
640 /* E30 */
641
642 /* attach tuner */
Antti Palosaarie82eea72011-04-12 19:43:30 -0300643 fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1),
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300644 NULL, DVB_PLL_THOMSON_DTT7579);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300645
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300646 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300647 case ANYSEE_HW_507CD: /* 6 */
648 /* E30 Plus */
649
650 /* attach tuner */
Antti Palosaarie82eea72011-04-12 19:43:30 -0300651 fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1),
Antti Palosaari41f81f62011-04-10 17:53:52 -0300652 &adap->dev->i2c_adap, DVB_PLL_THOMSON_DTT7579);
653
654 break;
655 case ANYSEE_HW_507DC: /* 10 */
656 /* E30 C Plus */
657
658 /* attach tuner */
Antti Palosaarie82eea72011-04-12 19:43:30 -0300659 fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1),
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300660 &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300661
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300662 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300663 case ANYSEE_HW_507SI: /* 11 */
664 /* E30 S2 Plus */
665
666 /* attach LNB controller */
667 fe = dvb_attach(isl6423_attach, adap->fe, &adap->dev->i2c_adap,
668 &anysee_isl6423_config);
669
670 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300671 case ANYSEE_HW_507FA: /* 15 */
672 /* E30 Combo Plus */
673 /* E30 C Plus */
674
Antti Palosaari59fb4142011-04-12 10:22:47 -0300675 if (dvb_usb_anysee_delsys) {
676 /* enable DVB-T tuner on IOE[0] */
677 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
678 0x01);
679 if (ret)
680 goto error;
681 } else {
682 /* enable DVB-C tuner on IOE[0] */
683 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
684 0x01);
685 if (ret)
686 goto error;
687 }
688
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300689 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
690 * fails attach old simple PLL. */
691
692 /* enable tuner on IOE[4] */
693 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
694 if (ret)
695 goto error;
696
697 /* attach tuner */
698 fe = dvb_attach(tda18212_attach, adap->fe, &adap->dev->i2c_adap,
699 &anysee_tda18212_config);
700 if (fe)
701 break;
702
703 /* disable tuner on IOE[4] */
704 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);
705 if (ret)
706 goto error;
707
Antti Palosaari41f81f62011-04-10 17:53:52 -0300708 /* attach tuner */
Antti Palosaarie82eea72011-04-12 19:43:30 -0300709 fe = dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1),
Antti Palosaari41f81f62011-04-10 17:53:52 -0300710 &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
711
712 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300713 case ANYSEE_HW_508TC: /* 18 */
714 /* E7 TC */
715
716 /* enable tuner on IOE[4] */
717 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
718 if (ret)
719 goto error;
720
721 /* attach tuner */
722 fe = dvb_attach(tda18212_attach, adap->fe, &adap->dev->i2c_adap,
723 &anysee_tda18212_config);
Antti Palosaaria43be982011-04-10 20:23:02 -0300724
725 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300726 default:
Antti Palosaarie82eea72011-04-12 19:43:30 -0300727 fe = NULL;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300728 }
729
Antti Palosaarie82eea72011-04-12 19:43:30 -0300730 if (fe)
731 ret = 0;
732 else
733 ret = -ENODEV;
734
Antti Palosaari41f81f62011-04-10 17:53:52 -0300735error:
736 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300737}
738
Antti Palosaaria8494682010-10-17 18:25:10 -0300739static int anysee_rc_query(struct dvb_usb_device *d)
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300740{
741 u8 buf[] = {CMD_GET_IR_CODE};
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300742 u8 ircode[2];
Antti Palosaaria8494682010-10-17 18:25:10 -0300743 int ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300744
Antti Palosaaria8494682010-10-17 18:25:10 -0300745 /* Remote controller is basic NEC using address byte 0x08.
746 Anysee device RC query returns only two bytes, status and code,
747 address byte is dropped. Also it does not return any value for
748 NEC RCs having address byte other than 0x08. Due to that, we
749 cannot use that device as standard NEC receiver.
750 It could be possible make hack which reads whole code directly
751 from device memory... */
752
753 ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode));
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300754 if (ret)
755 return ret;
756
Antti Palosaaria8494682010-10-17 18:25:10 -0300757 if (ircode[0]) {
758 deb_rc("%s: key pressed %02x\n", __func__, ircode[1]);
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -0300759 rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300760 }
Antti Palosaaria8494682010-10-17 18:25:10 -0300761
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300762 return 0;
763}
764
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300765/* DVB USB Driver stuff */
766static struct dvb_usb_device_properties anysee_properties;
767
768static int anysee_probe(struct usb_interface *intf,
769 const struct usb_device_id *id)
770{
771 struct dvb_usb_device *d;
772 struct usb_host_interface *alt;
773 int ret;
774
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300775 /* There is one interface with two alternate settings.
776 Alternate setting 0 is for bulk transfer.
777 Alternate setting 1 is for isochronous transfer.
778 We use bulk transfer (alternate setting 0). */
779 if (intf->num_altsetting < 1)
780 return -ENODEV;
781
Dan Carpenter8b0d7042010-05-31 16:27:39 -0300782 /*
783 * Anysee is always warm (its USB-bridge, Cypress FX2, uploads
784 * firmware from eeprom). If dvb_usb_device_init() succeeds that
785 * means d is a valid pointer.
786 */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300787 ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d,
788 adapter_nr);
789 if (ret)
790 return ret;
791
792 alt = usb_altnum_to_altsetting(intf, 0);
793 if (alt == NULL) {
794 deb_info("%s: no alt found!\n", __func__);
795 return -ENODEV;
796 }
797
798 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
799 alt->desc.bAlternateSetting);
800 if (ret)
801 return ret;
802
Dan Carpenter8b0d7042010-05-31 16:27:39 -0300803 return anysee_init(d);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300804}
805
Antti Palosaariae3745f2009-09-16 19:50:25 -0300806static struct usb_device_id anysee_table[] = {
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300807 { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) },
808 { USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) },
809 { } /* Terminating entry */
810};
811MODULE_DEVICE_TABLE(usb, anysee_table);
812
813static struct dvb_usb_device_properties anysee_properties = {
814 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
815
816 .usb_ctrl = DEVICE_SPECIFIC,
817
818 .size_of_priv = sizeof(struct anysee_state),
819
820 .num_adapters = 1,
821 .adapter = {
822 {
823 .streaming_ctrl = anysee_streaming_ctrl,
824 .frontend_attach = anysee_frontend_attach,
825 .tuner_attach = anysee_tuner_attach,
826 .stream = {
827 .type = USB_BULK,
828 .count = 8,
829 .endpoint = 0x82,
830 .u = {
831 .bulk = {
Antti Palosaariab693332009-09-16 19:47:01 -0300832 .buffersize = (16*512),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300833 }
834 }
835 },
836 }
837 },
838
Antti Palosaaria8494682010-10-17 18:25:10 -0300839 .rc.core = {
840 .rc_codes = RC_MAP_ANYSEE,
Mauro Carvalho Chehab52b66142010-11-17 14:20:52 -0300841 .protocol = RC_TYPE_OTHER,
Antti Palosaaria8494682010-10-17 18:25:10 -0300842 .module_name = "anysee",
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300843 .rc_query = anysee_rc_query,
Antti Palosaaria8494682010-10-17 18:25:10 -0300844 .rc_interval = 250, /* windows driver uses 500ms */
Mauro Carvalho Chehabf72a27b2010-07-31 18:04:09 -0300845 },
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300846
847 .i2c_algo = &anysee_i2c_algo,
848
849 .generic_bulk_ctrl_endpoint = 1,
850
851 .num_device_descs = 1,
852 .devices = {
853 {
854 .name = "Anysee DVB USB2.0",
855 .cold_ids = {NULL},
856 .warm_ids = {&anysee_table[0],
857 &anysee_table[1], NULL},
858 },
859 }
860};
861
862static struct usb_driver anysee_driver = {
863 .name = "dvb_usb_anysee",
864 .probe = anysee_probe,
865 .disconnect = dvb_usb_device_exit,
866 .id_table = anysee_table,
867};
868
869/* module stuff */
870static int __init anysee_module_init(void)
871{
872 int ret;
873
874 ret = usb_register(&anysee_driver);
875 if (ret)
876 err("%s: usb_register failed. Error number %d", __func__, ret);
877
878 return ret;
879}
880
881static void __exit anysee_module_exit(void)
882{
883 /* deregister this driver from the USB subsystem */
884 usb_deregister(&anysee_driver);
885}
886
887module_init(anysee_module_init);
888module_exit(anysee_module_exit);
889
890MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
891MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
892MODULE_LICENSE("GPL");