blob: 2a0798cfb3656d8862f14311898632420024e178 [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"
Antti Palosaaria4e7c512012-06-14 04:56:09 -030035#include "dvb-pll.h"
Antti Palosaaria51e34d2008-05-17 23:05:48 -030036#include "tda1002x.h"
37#include "mt352.h"
38#include "mt352_priv.h"
39#include "zl10353.h"
Antti Palosaari72ffd2b2011-04-10 20:14:50 -030040#include "tda18212.h"
Antti Palosaarif0a53102011-04-27 21:11:59 -030041#include "cx24116.h"
Antti Palosaaribedbf3d2011-04-29 13:55:02 -030042#include "stv0900.h"
43#include "stv6110.h"
Antti Palosaarif0a53102011-04-27 21:11:59 -030044#include "isl6423.h"
Antti Palosaari608add82011-08-12 18:29:46 -030045#include "cxd2820r.h"
Antti Palosaaria51e34d2008-05-17 23:05:48 -030046
47/* debug */
48static int dvb_usb_anysee_debug;
49module_param_named(debug, dvb_usb_anysee_debug, int, 0644);
50MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
51DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
52
Akinobu Mitadec0c462008-10-29 21:16:04 -030053static DEFINE_MUTEX(anysee_usb_mutex);
Antti Palosaaria51e34d2008-05-17 23:05:48 -030054
55static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
56 u8 *rbuf, u8 rlen)
57{
58 struct anysee_state *state = d->priv;
Antti Palosaaricf427952012-01-21 11:19:29 -030059 int act_len, ret, i;
Antti Palosaaria51e34d2008-05-17 23:05:48 -030060 u8 buf[64];
61
Antti Palosaaria51e34d2008-05-17 23:05:48 -030062 memcpy(&buf[0], sbuf, slen);
63 buf[60] = state->seq++;
64
Antti Palosaaria4e7c512012-06-14 04:56:09 -030065 mutex_lock(&anysee_usb_mutex);
Antti Palosaaria51e34d2008-05-17 23:05:48 -030066
Antti Palosaari4048da22011-09-29 20:28:53 -030067 deb_xfer(">>> ");
68 debug_dump(buf, slen, deb_xfer);
69
Antti Palosaaria51e34d2008-05-17 23:05:48 -030070 /* 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. */
Antti Palosaaria4e7c512012-06-14 04:56:09 -030072 ret = dvb_usbv2_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf), 0);
Antti Palosaaricf427952012-01-21 11:19:29 -030073 if (ret)
74 goto error_unlock;
75
76 /* TODO FIXME: dvb_usb_generic_rw() fails rarely with error code -32
77 * (EPIPE, Broken pipe). Function supports currently msleep() as a
78 * parameter but I would not like to use it, since according to
79 * Documentation/timers/timers-howto.txt it should not be used such
80 * short, under < 20ms, sleeps. Repeating failed message would be
81 * better choice as not to add unwanted delays...
82 * Fixing that correctly is one of those or both;
83 * 1) use repeat if possible
84 * 2) add suitable delay
85 */
86
87 /* get answer, retry few times if error returned */
88 for (i = 0; i < 3; i++) {
Antti Palosaaria51e34d2008-05-17 23:05:48 -030089 /* receive 2nd answer */
90 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
Antti Palosaaria4e7c512012-06-14 04:56:09 -030091 d->props->generic_bulk_ctrl_endpoint), buf, sizeof(buf),
Antti Palosaaria51e34d2008-05-17 23:05:48 -030092 &act_len, 2000);
Antti Palosaaricf427952012-01-21 11:19:29 -030093
94 if (ret) {
95 deb_info("%s: recv bulk message failed: %d",
96 __func__, ret);
97 } else {
Antti Palosaaria51e34d2008-05-17 23:05:48 -030098 deb_xfer("<<< ");
Antti Palosaari4048da22011-09-29 20:28:53 -030099 debug_dump(buf, rlen, deb_xfer);
100
101 if (buf[63] != 0x4f)
102 deb_info("%s: cmd failed\n", __func__);
Antti Palosaaricf427952012-01-21 11:19:29 -0300103
104 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300105 }
106 }
107
Antti Palosaaricf427952012-01-21 11:19:29 -0300108 if (ret) {
109 /* all retries failed, it is fatal */
110 err("%s: recv bulk message failed: %d", __func__, ret);
111 goto error_unlock;
112 }
113
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300114 /* read request, copy returned data to return buf */
Antti Palosaaricf427952012-01-21 11:19:29 -0300115 if (rbuf && rlen)
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300116 memcpy(rbuf, buf, rlen);
117
Antti Palosaaricf427952012-01-21 11:19:29 -0300118error_unlock:
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300119 mutex_unlock(&anysee_usb_mutex);
120
121 return ret;
122}
123
124static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
125{
126 u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};
127 int ret;
128 ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);
129 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, *val);
130 return ret;
131}
132
133static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
134{
135 u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};
136 deb_info("%s: reg:%04x val:%02x\n", __func__, reg, val);
137 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
138}
139
Antti Palosaari41f81f62011-04-10 17:53:52 -0300140/* write single register with mask */
141static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
142 u8 mask)
143{
144 int ret;
145 u8 tmp;
146
147 /* no need for read if whole reg is written */
148 if (mask != 0xff) {
149 ret = anysee_read_reg(d, reg, &tmp);
150 if (ret)
151 return ret;
152
153 val &= mask;
154 tmp &= ~mask;
155 val |= tmp;
156 }
157
158 return anysee_write_reg(d, reg, val);
159}
160
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300161/* read single register with mask */
162static int anysee_rd_reg_mask(struct dvb_usb_device *d, u16 reg, u8 *val,
163 u8 mask)
164{
165 int ret, i;
166 u8 tmp;
167
168 ret = anysee_read_reg(d, reg, &tmp);
169 if (ret)
170 return ret;
171
172 tmp &= mask;
173
174 /* find position of the first bit */
175 for (i = 0; i < 8; i++) {
176 if ((mask >> i) & 0x01)
177 break;
178 }
179 *val = tmp >> i;
180
181 return 0;
182}
183
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300184static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
185{
186 u8 buf[] = {CMD_GET_HW_INFO};
187 return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);
188}
189
190static int anysee_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
191{
192 u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};
193 deb_info("%s: onoff:%02x\n", __func__, onoff);
194 return anysee_ctrl_msg(adap->dev, buf, sizeof(buf), NULL, 0);
195}
196
197static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)
198{
199 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};
200 deb_info("%s: state:%02x interval:%02x\n", __func__, mode, interval);
201 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
202}
203
204static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
205{
206 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};
207 deb_info("%s: onoff:%02x\n", __func__, onoff);
208 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
209}
210
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300211/* I2C */
212static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
213 int num)
214{
215 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Mauro Carvalho Chehab902571a2008-12-29 19:02:24 -0300216 int ret = 0, inc, i = 0;
Antti Palosaari21d2e932011-05-24 06:04:08 -0300217 u8 buf[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300218
219 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
220 return -EAGAIN;
221
222 while (i < num) {
223 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
Antti Palosaari21d2e932011-05-24 06:04:08 -0300224 if (msg[i].len > 2 || msg[i+1].len > 60) {
225 ret = -EOPNOTSUPP;
226 break;
227 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300228 buf[0] = CMD_I2C_READ;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300229 buf[1] = (msg[i].addr << 1) | 0x01;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300230 buf[2] = msg[i].buf[0];
Antti Palosaari882b82c2011-04-12 19:49:25 -0300231 buf[3] = msg[i].buf[1];
232 buf[4] = msg[i].len-1;
Antti Palosaarib3e6a5a2011-04-09 21:00:51 -0300233 buf[5] = msg[i+1].len;
Antti Palosaari21d2e932011-05-24 06:04:08 -0300234 ret = anysee_ctrl_msg(d, buf, 6, msg[i+1].buf,
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300235 msg[i+1].len);
236 inc = 2;
237 } else {
Antti Palosaari21d2e932011-05-24 06:04:08 -0300238 if (msg[i].len > 48) {
239 ret = -EOPNOTSUPP;
240 break;
241 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300242 buf[0] = CMD_I2C_WRITE;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300243 buf[1] = (msg[i].addr << 1);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300244 buf[2] = msg[i].len;
245 buf[3] = 0x01;
246 memcpy(&buf[4], msg[i].buf, msg[i].len);
Antti Palosaari21d2e932011-05-24 06:04:08 -0300247 ret = anysee_ctrl_msg(d, buf, 4 + msg[i].len, NULL, 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300248 inc = 1;
249 }
250 if (ret)
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300251 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300252
253 i += inc;
254 }
255
256 mutex_unlock(&d->i2c_mutex);
257
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300258 return ret ? ret : i;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300259}
260
261static u32 anysee_i2c_func(struct i2c_adapter *adapter)
262{
263 return I2C_FUNC_I2C;
264}
265
266static struct i2c_algorithm anysee_i2c_algo = {
267 .master_xfer = anysee_master_xfer,
268 .functionality = anysee_i2c_func,
269};
270
271static int anysee_mt352_demod_init(struct dvb_frontend *fe)
272{
Antti Palosaariae3745f2009-09-16 19:50:25 -0300273 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
274 static u8 reset[] = { RESET, 0x80 };
275 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
276 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
277 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300278 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
279
280 mt352_write(fe, clock_config, sizeof(clock_config));
281 udelay(200);
282 mt352_write(fe, reset, sizeof(reset));
283 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
284
285 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
286 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
287 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
288
289 return 0;
290}
291
292/* Callbacks for DVB USB */
293static struct tda10023_config anysee_tda10023_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300294 .demod_address = (0x1a >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300295 .invert = 0,
296 .xtal = 16000000,
297 .pll_m = 11,
298 .pll_p = 3,
299 .pll_n = 1,
Antti Palosaari5ae2fca2008-06-09 22:58:22 -0300300 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
301 .deltaf = 0xfeeb,
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300302};
303
304static struct mt352_config anysee_mt352_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300305 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300306 .demod_init = anysee_mt352_demod_init,
307};
308
309static struct zl10353_config anysee_zl10353_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300310 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300311 .parallel_ts = 1,
312};
313
Antti Palosaari1fd80702011-04-12 17:34:08 -0300314static struct zl10353_config anysee_zl10353_tda18212_config2 = {
315 .demod_address = (0x1e >> 1),
316 .parallel_ts = 1,
317 .disable_i2c_gate_ctrl = 1,
318 .no_tuner = 1,
319 .if2 = 41500,
320};
321
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300322static struct zl10353_config anysee_zl10353_tda18212_config = {
323 .demod_address = (0x18 >> 1),
324 .parallel_ts = 1,
325 .disable_i2c_gate_ctrl = 1,
326 .no_tuner = 1,
327 .if2 = 41500,
328};
329
330static struct tda10023_config anysee_tda10023_tda18212_config = {
331 .demod_address = (0x1a >> 1),
332 .xtal = 16000000,
333 .pll_m = 12,
334 .pll_p = 3,
335 .pll_n = 1,
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300336 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_B,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300337 .deltaf = 0xba02,
338};
339
340static struct tda18212_config anysee_tda18212_config = {
341 .i2c_address = (0xc0 >> 1),
342 .if_dvbt_6 = 4150,
343 .if_dvbt_7 = 4150,
344 .if_dvbt_8 = 4150,
345 .if_dvbc = 5000,
346};
347
Antti Palosaari608add82011-08-12 18:29:46 -0300348static struct tda18212_config anysee_tda18212_config2 = {
349 .i2c_address = 0x60 /* (0xc0 >> 1) */,
350 .if_dvbt_6 = 3550,
351 .if_dvbt_7 = 3700,
352 .if_dvbt_8 = 4150,
353 .if_dvbt2_6 = 3250,
354 .if_dvbt2_7 = 4000,
355 .if_dvbt2_8 = 4000,
356 .if_dvbc = 5000,
357};
358
Antti Palosaarif0a53102011-04-27 21:11:59 -0300359static struct cx24116_config anysee_cx24116_config = {
360 .demod_address = (0xaa >> 1),
361 .mpg_clk_pos_pol = 0x00,
362 .i2c_wr_max = 48,
363};
364
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300365static struct stv0900_config anysee_stv0900_config = {
366 .demod_address = (0xd0 >> 1),
367 .demod_mode = 0,
368 .xtal = 8000000,
369 .clkmode = 3,
370 .diseqc_mode = 2,
371 .tun1_maddress = 0,
372 .tun1_adc = 1, /* 1 Vpp */
373 .path1_mode = 3,
374};
375
376static struct stv6110_config anysee_stv6110_config = {
377 .i2c_address = (0xc0 >> 1),
378 .mclk = 16000000,
379 .clk_div = 1,
380};
381
Antti Palosaarif0a53102011-04-27 21:11:59 -0300382static struct isl6423_config anysee_isl6423_config = {
383 .current_max = SEC_CURRENT_800m,
384 .curlim = SEC_CURRENT_LIM_OFF,
385 .mod_extern = 1,
386 .addr = (0x10 >> 1),
387};
388
Antti Palosaari608add82011-08-12 18:29:46 -0300389static struct cxd2820r_config anysee_cxd2820r_config = {
390 .i2c_address = 0x6d, /* (0xda >> 1) */
391 .ts_mode = 0x38,
Antti Palosaari608add82011-08-12 18:29:46 -0300392};
393
Antti Palosaari41f81f62011-04-10 17:53:52 -0300394/*
395 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
396 * Manufacturer: AMT.CO.KR
397 *
398 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
399 * PCB: ?
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300400 * parts: DNOS404ZH102A(MT352, DTT7579(?))
Antti Palosaari41f81f62011-04-10 17:53:52 -0300401 *
Antti Palosaari05c46c02011-05-25 18:30:09 -0300402 * E30 VID=04b4 PID=861f HW=2 FW=2.1 "anysee-T(LP)"
403 * PCB: PCB 507T (rev1.61)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300404 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
Antti Palosaari05c46c02011-05-25 18:30:09 -0300405 * OEA=0a OEB=00 OEC=00 OED=ff OEE=00
406 * IOA=45 IOB=ff IOC=00 IOD=ff IOE=00
Antti Palosaari41f81f62011-04-10 17:53:52 -0300407 *
408 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
409 * PCB: 507CD (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300410 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
Antti Palosaari05c46c02011-05-25 18:30:09 -0300411 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
412 * IOA=4f IOB=ff IOC=00 IOD=06 IOE=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300413 * IOD[0] ZL10353 1=enabled
414 * IOA[7] TS 0=enabled
415 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
416 *
417 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
418 * PCB: 507DC (rev0.2)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300419 * parts: TDA10023, DTOS403IH102B TM, CST56I01
Antti Palosaari05c46c02011-05-25 18:30:09 -0300420 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
421 * IOA=4f IOB=ff IOC=00 IOD=26 IOE=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300422 * IOD[0] TDA10023 1=enabled
423 *
Antti Palosaarif0a53102011-04-27 21:11:59 -0300424 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
425 * PCB: 507SI (rev2.1)
426 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300427 * OEA=80 OEB=00 OEC=ff OED=ff OEE=fe
428 * IOA=4d IOB=ff IOC=00 IOD=26 IOE=01
Antti Palosaarif0a53102011-04-27 21:11:59 -0300429 * IOD[0] CX24116 1=enabled
430 *
Antti Palosaari41f81f62011-04-10 17:53:52 -0300431 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
432 * PCB: 507FA (rev0.4)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300433 * parts: TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300434 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
435 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300436 * IOD[5] TDA10023 1=enabled
437 * IOE[0] tuner 1=enabled
438 *
439 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
440 * PCB: 507FA (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300441 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300442 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
443 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300444 * DVB-C:
445 * IOD[5] TDA10023 1=enabled
446 * IOE[0] tuner 1=enabled
447 * DVB-T:
448 * IOD[0] ZL10353 1=enabled
449 * IOE[0] tuner 0=enabled
450 * tuner is behind ZL10353 I2C-gate
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300451 *
452 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
453 * PCB: 508TC (rev0.6)
454 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
Antti Palosaari05c46c02011-05-25 18:30:09 -0300455 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
456 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300457 * IOA[7] TS 1=enabled
458 * IOE[4] TDA18212 1=enabled
459 * DVB-C:
460 * IOD[6] ZL10353 0=disabled
461 * IOD[5] TDA10023 1=enabled
462 * IOE[0] IF 1=enabled
463 * DVB-T:
464 * IOD[5] TDA10023 0=disabled
465 * IOD[6] ZL10353 1=enabled
466 * IOE[0] IF 0=enabled
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300467 *
468 * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
469 * PCB: 508S2 (rev0.7)
470 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
Antti Palosaari05c46c02011-05-25 18:30:09 -0300471 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
472 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300473 * IOA[7] TS 1=enabled
474 * IOE[5] STV0903 1=enabled
475 *
Antti Palosaari608add82011-08-12 18:29:46 -0300476 * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)"
477 * PCB: 508T2C (rev0.3)
478 * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024
479 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
480 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
481 * IOA[7] TS 1=enabled
482 * IOE[5] CXD2820R 1=enabled
483 *
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300484 * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)"
485 * PCB: 508PTC (rev0.5)
486 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
487 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
488 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
489 * IOA[7] TS 1=enabled
490 * IOE[4] TDA18212 1=enabled
491 * DVB-C:
492 * IOD[6] ZL10353 0=disabled
493 * IOD[5] TDA10023 1=enabled
494 * IOE[0] IF 1=enabled
495 * DVB-T:
496 * IOD[5] TDA10023 0=disabled
497 * IOD[6] ZL10353 1=enabled
498 * IOE[0] IF 0=enabled
Antti Palosaarifea3c392011-05-25 18:21:43 -0300499 *
Antti Palosaari608add82011-08-12 18:29:46 -0300500 * E7 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)"
Antti Palosaarifea3c392011-05-25 18:21:43 -0300501 * PCB: 508PS2 (rev0.4)
502 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
503 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
504 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
505 * IOA[7] TS 1=enabled
506 * IOE[5] STV0903 1=enabled
Antti Palosaari41f81f62011-04-10 17:53:52 -0300507 */
508
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300509static int anysee_read_config(struct dvb_usb_device *d)
510{
511 struct anysee_state *state = d->priv;
512 int ret;
513 u8 hw_info[3];
514
515 /*
516 * Check which hardware we have.
517 * We must do this call two times to get reliable values (hw/fw bug).
518 */
519 ret = anysee_get_hw_info(d, hw_info);
520 if (ret)
521 goto error;
522
523 ret = anysee_get_hw_info(d, hw_info);
524 if (ret)
525 goto error;
526
527 /* Meaning of these info bytes are guessed. */
528 info("firmware version:%d.%d hardware id:%d",
529 hw_info[1], hw_info[2], hw_info[0]);
530
531 state->hw = hw_info[0];
532error:
533 return ret;
534}
Antti Palosaaribe943512011-09-05 22:10:05 -0300535
536/* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */
537static int anysee_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
538{
539 struct dvb_usb_adapter *adap = fe->dvb->priv;
540
541 /* enable / disable tuner access on IOE[4] */
542 return anysee_wr_reg_mask(adap->dev, REG_IOE, (enable << 4), 0x10);
543}
544
Antti Palosaari449d1a02011-07-25 20:25:21 -0300545static int anysee_frontend_ctrl(struct dvb_frontend *fe, int onoff)
546{
547 struct dvb_usb_adapter *adap = fe->dvb->priv;
548 struct anysee_state *state = adap->dev->priv;
549 int ret;
550
551 deb_info("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
552
553 /* no frontend sleep control */
554 if (onoff == 0)
555 return 0;
556
557 switch (state->hw) {
558 case ANYSEE_HW_507FA: /* 15 */
559 /* E30 Combo Plus */
560 /* E30 C Plus */
561
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300562 if (fe->id == 0) {
Antti Palosaari449d1a02011-07-25 20:25:21 -0300563 /* 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 /* enable DVB-C tuner on IOE[0] */
576 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
577 0x01);
578 if (ret)
579 goto error;
580 } else {
581 /* disable DVB-C demod on IOD[5] */
582 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
583 0x20);
584 if (ret)
585 goto error;
586
587 /* enable DVB-T demod on IOD[0] */
588 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0),
589 0x01);
590 if (ret)
591 goto error;
592
593 /* enable DVB-T tuner on IOE[0] */
594 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
595 0x01);
596 if (ret)
597 goto error;
598 }
599
600 break;
601 case ANYSEE_HW_508TC: /* 18 */
602 case ANYSEE_HW_508PTC: /* 21 */
603 /* E7 TC */
604 /* E7 PTC */
605
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300606 if (fe->id == 0) {
Antti Palosaari449d1a02011-07-25 20:25:21 -0300607 /* disable DVB-T demod on IOD[6] */
608 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6),
609 0x40);
610 if (ret)
611 goto error;
612
613 /* enable DVB-C demod on IOD[5] */
614 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5),
615 0x20);
616 if (ret)
617 goto error;
618
619 /* enable IF route on IOE[0] */
620 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0),
621 0x01);
622 if (ret)
623 goto error;
624 } else {
625 /* disable DVB-C demod on IOD[5] */
626 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5),
627 0x20);
628 if (ret)
629 goto error;
630
631 /* enable DVB-T demod on IOD[6] */
632 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6),
633 0x40);
634 if (ret)
635 goto error;
636
637 /* enable IF route on IOE[0] */
638 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0),
639 0x01);
640 if (ret)
641 goto error;
642 }
643
644 break;
645 default:
646 ret = 0;
647 }
648
649error:
650 return ret;
651}
652
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300653static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
654{
655 int ret;
656 struct anysee_state *state = adap->dev->priv;
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300657 u8 tmp;
658 struct i2c_msg msg[2] = {
659 {
660 .addr = anysee_tda18212_config.i2c_address,
661 .flags = 0,
662 .len = 1,
663 .buf = "\x00",
664 }, {
665 .addr = anysee_tda18212_config.i2c_address,
666 .flags = I2C_M_RD,
667 .len = 1,
668 .buf = &tmp,
669 }
670 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300671
Antti Palosaari41f81f62011-04-10 17:53:52 -0300672 switch (state->hw) {
Antti Palosaari05c46c02011-05-25 18:30:09 -0300673 case ANYSEE_HW_507T: /* 2 */
Antti Palosaari41f81f62011-04-10 17:53:52 -0300674 /* E30 */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300675
Antti Palosaari41f81f62011-04-10 17:53:52 -0300676 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300677 adap->fe[0] = dvb_attach(mt352_attach,
Antti Palosaari8f4ffb12011-09-29 20:36:33 -0300678 &anysee_mt352_config, &adap->dev->i2c_adap);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300679 if (adap->fe[0])
Antti Palosaari41f81f62011-04-10 17:53:52 -0300680 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300681
Antti Palosaari41f81f62011-04-10 17:53:52 -0300682 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300683 adap->fe[0] = dvb_attach(zl10353_attach,
Antti Palosaari8f4ffb12011-09-29 20:36:33 -0300684 &anysee_zl10353_config, &adap->dev->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300685
686 break;
687 case ANYSEE_HW_507CD: /* 6 */
688 /* E30 Plus */
689
690 /* enable DVB-T demod on IOD[0] */
691 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
692 if (ret)
693 goto error;
694
695 /* enable transport stream on IOA[7] */
696 ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (0 << 7), 0x80);
697 if (ret)
698 goto error;
699
700 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300701 adap->fe[0] = dvb_attach(zl10353_attach,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300702 &anysee_zl10353_config, &adap->dev->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300703
704 break;
705 case ANYSEE_HW_507DC: /* 10 */
706 /* E30 C Plus */
707
708 /* enable DVB-C demod on IOD[0] */
709 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
710 if (ret)
711 goto error;
712
713 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300714 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300715 &anysee_tda10023_config, &adap->dev->i2c_adap, 0x48);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300716
717 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300718 case ANYSEE_HW_507SI: /* 11 */
719 /* E30 S2 Plus */
720
721 /* enable DVB-S/S2 demod on IOD[0] */
722 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
723 if (ret)
724 goto error;
725
726 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300727 adap->fe[0] = dvb_attach(cx24116_attach,
Antti Palosaari8f4ffb12011-09-29 20:36:33 -0300728 &anysee_cx24116_config, &adap->dev->i2c_adap);
Antti Palosaarif0a53102011-04-27 21:11:59 -0300729
730 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300731 case ANYSEE_HW_507FA: /* 15 */
732 /* E30 Combo Plus */
733 /* E30 C Plus */
734
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300735 /* enable tuner on IOE[4] */
736 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 4), 0x10);
737 if (ret)
738 goto error;
739
740 /* probe TDA18212 */
741 tmp = 0;
742 ret = i2c_transfer(&adap->dev->i2c_adap, msg, 2);
743 if (ret == 2 && tmp == 0xc7)
744 deb_info("%s: TDA18212 found\n", __func__);
745 else
746 tmp = 0;
747
748 /* disable tuner on IOE[4] */
749 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 4), 0x10);
750 if (ret)
751 goto error;
752
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300753 /* disable DVB-T demod on IOD[0] */
754 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0), 0x01);
755 if (ret)
756 goto error;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300757
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300758 /* enable DVB-C demod on IOD[5] */
759 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5), 0x20);
760 if (ret)
761 goto error;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300762
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300763 /* attach demod */
764 if (tmp == 0xc7) {
765 /* TDA18212 config */
766 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300767 &anysee_tda10023_tda18212_config,
768 &adap->dev->i2c_adap, 0x48);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300769
770 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
771 if (adap->fe[0])
772 adap->fe[0]->ops.i2c_gate_ctrl =
773 anysee_i2c_gate_ctrl;
774 } else {
775 /* PLL config */
776 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300777 &anysee_tda10023_config,
778 &adap->dev->i2c_adap, 0x48);
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300779 }
Antti Palosaarie82eea72011-04-12 19:43:30 -0300780
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300781 /* break out if first frontend attaching fails */
782 if (!adap->fe[0])
783 break;
784
785 /* disable DVB-C demod on IOD[5] */
786 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5), 0x20);
787 if (ret)
788 goto error;
789
790 /* enable DVB-T demod on IOD[0] */
791 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01);
792 if (ret)
793 goto error;
794
795 /* attach demod */
Antti Palosaaribe943512011-09-05 22:10:05 -0300796 if (tmp == 0xc7) {
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300797 /* TDA18212 config */
798 adap->fe[1] = dvb_attach(zl10353_attach,
799 &anysee_zl10353_tda18212_config2,
800 &adap->dev->i2c_adap);
801
802 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
803 if (adap->fe[1])
804 adap->fe[1]->ops.i2c_gate_ctrl =
805 anysee_i2c_gate_ctrl;
806 } else {
807 /* PLL config */
808 adap->fe[1] = dvb_attach(zl10353_attach,
809 &anysee_zl10353_config,
810 &adap->dev->i2c_adap);
Antti Palosaaribe943512011-09-05 22:10:05 -0300811 }
812
Antti Palosaari41f81f62011-04-10 17:53:52 -0300813 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300814 case ANYSEE_HW_508TC: /* 18 */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300815 case ANYSEE_HW_508PTC: /* 21 */
Antti Palosaaria43be982011-04-10 20:23:02 -0300816 /* E7 TC */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300817 /* E7 PTC */
Antti Palosaaria43be982011-04-10 20:23:02 -0300818
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300819 /* disable DVB-T demod on IOD[6] */
820 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 6), 0x40);
821 if (ret)
822 goto error;
Antti Palosaaria43be982011-04-10 20:23:02 -0300823
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300824 /* enable DVB-C demod on IOD[5] */
825 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5), 0x20);
826 if (ret)
827 goto error;
Antti Palosaaria43be982011-04-10 20:23:02 -0300828
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300829 /* attach demod */
830 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300831 &anysee_tda10023_tda18212_config,
832 &adap->dev->i2c_adap, 0x48);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300833
Antti Palosaaribe943512011-09-05 22:10:05 -0300834 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300835 if (adap->fe[0])
836 adap->fe[0]->ops.i2c_gate_ctrl = anysee_i2c_gate_ctrl;
837
838 /* break out if first frontend attaching fails */
839 if (!adap->fe[0])
840 break;
841
842 /* disable DVB-C demod on IOD[5] */
843 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5), 0x20);
844 if (ret)
845 goto error;
846
847 /* enable DVB-T demod on IOD[6] */
848 ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 6), 0x40);
849 if (ret)
850 goto error;
851
852 /* attach demod */
853 adap->fe[1] = dvb_attach(zl10353_attach,
854 &anysee_zl10353_tda18212_config,
855 &adap->dev->i2c_adap);
856
857 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
858 if (adap->fe[1])
859 adap->fe[1]->ops.i2c_gate_ctrl = anysee_i2c_gate_ctrl;
Antti Palosaaribe943512011-09-05 22:10:05 -0300860
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300861 state->has_ci = true;
862
Antti Palosaaria43be982011-04-10 20:23:02 -0300863 break;
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300864 case ANYSEE_HW_508S2: /* 19 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300865 case ANYSEE_HW_508PS2: /* 22 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300866 /* E7 S2 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300867 /* E7 PS2 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300868
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300869 /* enable DVB-S/S2 demod on IOE[5] */
870 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20);
871 if (ret)
872 goto error;
873
874 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300875 adap->fe[0] = dvb_attach(stv0900_attach,
Antti Palosaari8f4ffb12011-09-29 20:36:33 -0300876 &anysee_stv0900_config, &adap->dev->i2c_adap, 0);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300877
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300878 state->has_ci = true;
879
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300880 break;
Antti Palosaari608add82011-08-12 18:29:46 -0300881 case ANYSEE_HW_508T2C: /* 20 */
882 /* E7 T2C */
883
Antti Palosaari608add82011-08-12 18:29:46 -0300884 /* enable DVB-T/T2/C demod on IOE[5] */
885 ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 5), 0x20);
886 if (ret)
887 goto error;
888
Antti Palosaarifaf27972012-01-15 14:20:50 -0300889 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300890 adap->fe[0] = dvb_attach(cxd2820r_attach,
Antti Palosaaric2bbbe72012-01-19 14:46:43 -0300891 &anysee_cxd2820r_config, &adap->dev->i2c_adap);
Antti Palosaari608add82011-08-12 18:29:46 -0300892
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300893 state->has_ci = true;
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300894
895 break;
896 }
897
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300898 if (!adap->fe[0]) {
Antti Palosaari41f81f62011-04-10 17:53:52 -0300899 /* we have no frontend :-( */
900 ret = -ENODEV;
Antti Palosaarie82eea72011-04-12 19:43:30 -0300901 err("Unsupported Anysee version. " \
902 "Please report the <linux-media@vger.kernel.org>.");
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300903 }
Antti Palosaari41f81f62011-04-10 17:53:52 -0300904error:
905 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300906}
907
908static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
909{
910 struct anysee_state *state = adap->dev->priv;
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300911 struct dvb_frontend *fe;
Antti Palosaarie82eea72011-04-12 19:43:30 -0300912 int ret;
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300913 deb_info("%s: adap=%d\n", __func__, adap->id);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300914
Antti Palosaari41f81f62011-04-10 17:53:52 -0300915 switch (state->hw) {
Antti Palosaari05c46c02011-05-25 18:30:09 -0300916 case ANYSEE_HW_507T: /* 2 */
Antti Palosaari41f81f62011-04-10 17:53:52 -0300917 /* E30 */
918
919 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300920 fe = dvb_attach(dvb_pll_attach, adap->fe[0],
Antti Palosaari8f4ffb12011-09-29 20:36:33 -0300921 (0xc2 >> 1), NULL, DVB_PLL_THOMSON_DTT7579);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300922
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300923 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300924 case ANYSEE_HW_507CD: /* 6 */
925 /* E30 Plus */
926
927 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300928 fe = dvb_attach(dvb_pll_attach, adap->fe[0],
Antti Palosaari8f4ffb12011-09-29 20:36:33 -0300929 (0xc2 >> 1), &adap->dev->i2c_adap,
930 DVB_PLL_THOMSON_DTT7579);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300931
932 break;
933 case ANYSEE_HW_507DC: /* 10 */
934 /* E30 C Plus */
935
936 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300937 fe = dvb_attach(dvb_pll_attach, adap->fe[0],
Antti Palosaari8f4ffb12011-09-29 20:36:33 -0300938 (0xc0 >> 1), &adap->dev->i2c_adap,
939 DVB_PLL_SAMSUNG_DTOS403IH102A);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300940
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300941 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300942 case ANYSEE_HW_507SI: /* 11 */
943 /* E30 S2 Plus */
944
945 /* attach LNB controller */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300946 fe = dvb_attach(isl6423_attach, adap->fe[0],
Antti Palosaari449d1a02011-07-25 20:25:21 -0300947 &adap->dev->i2c_adap, &anysee_isl6423_config);
Antti Palosaarif0a53102011-04-27 21:11:59 -0300948
949 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300950 case ANYSEE_HW_507FA: /* 15 */
951 /* E30 Combo Plus */
952 /* E30 C Plus */
953
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300954 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
955 * fails attach old simple PLL. */
956
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300957 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300958 fe = dvb_attach(tda18212_attach, adap->fe[0],
959 &adap->dev->i2c_adap, &anysee_tda18212_config);
960
961 if (fe && adap->fe[1]) {
962 /* attach tuner for 2nd FE */
963 fe = dvb_attach(tda18212_attach, adap->fe[1],
964 &adap->dev->i2c_adap,
965 &anysee_tda18212_config);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300966 break;
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300967 } else if (fe) {
968 break;
969 }
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300970
Antti Palosaari41f81f62011-04-10 17:53:52 -0300971 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300972 fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc0 >> 1),
973 &adap->dev->i2c_adap,
974 DVB_PLL_SAMSUNG_DTOS403IH102A);
975
976 if (fe && adap->fe[1]) {
977 /* attach tuner for 2nd FE */
978 fe = dvb_attach(dvb_pll_attach, adap->fe[0],
979 (0xc0 >> 1), &adap->dev->i2c_adap,
980 DVB_PLL_SAMSUNG_DTOS403IH102A);
981 }
Antti Palosaari41f81f62011-04-10 17:53:52 -0300982
983 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300984 case ANYSEE_HW_508TC: /* 18 */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300985 case ANYSEE_HW_508PTC: /* 21 */
Antti Palosaaria43be982011-04-10 20:23:02 -0300986 /* E7 TC */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300987 /* E7 PTC */
Antti Palosaaria43be982011-04-10 20:23:02 -0300988
Antti Palosaaria43be982011-04-10 20:23:02 -0300989 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300990 fe = dvb_attach(tda18212_attach, adap->fe[0],
Antti Palosaari449d1a02011-07-25 20:25:21 -0300991 &adap->dev->i2c_adap, &anysee_tda18212_config);
Antti Palosaaria43be982011-04-10 20:23:02 -0300992
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300993 if (fe) {
994 /* attach tuner for 2nd FE */
995 fe = dvb_attach(tda18212_attach, adap->fe[1],
996 &adap->dev->i2c_adap, &anysee_tda18212_config);
997 }
998
Antti Palosaaria43be982011-04-10 20:23:02 -0300999 break;
Antti Palosaaribedbf3d2011-04-29 13:55:02 -03001000 case ANYSEE_HW_508S2: /* 19 */
Antti Palosaarifea3c392011-05-25 18:21:43 -03001001 case ANYSEE_HW_508PS2: /* 22 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -03001002 /* E7 S2 */
Antti Palosaarifea3c392011-05-25 18:21:43 -03001003 /* E7 PS2 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -03001004
1005 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001006 fe = dvb_attach(stv6110_attach, adap->fe[0],
Antti Palosaaribedbf3d2011-04-29 13:55:02 -03001007 &anysee_stv6110_config, &adap->dev->i2c_adap);
1008
1009 if (fe) {
1010 /* attach LNB controller */
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001011 fe = dvb_attach(isl6423_attach, adap->fe[0],
Antti Palosaaribedbf3d2011-04-29 13:55:02 -03001012 &adap->dev->i2c_adap, &anysee_isl6423_config);
1013 }
1014
1015 break;
Antti Palosaari608add82011-08-12 18:29:46 -03001016
1017 case ANYSEE_HW_508T2C: /* 20 */
1018 /* E7 T2C */
1019
1020 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001021 fe = dvb_attach(tda18212_attach, adap->fe[0],
Antti Palosaari608add82011-08-12 18:29:46 -03001022 &adap->dev->i2c_adap, &anysee_tda18212_config2);
1023
1024 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -03001025 default:
Antti Palosaarie82eea72011-04-12 19:43:30 -03001026 fe = NULL;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001027 }
1028
Antti Palosaarie82eea72011-04-12 19:43:30 -03001029 if (fe)
1030 ret = 0;
1031 else
1032 ret = -ENODEV;
1033
Antti Palosaari41f81f62011-04-10 17:53:52 -03001034 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001035}
1036
Antti Palosaaria8494682010-10-17 18:25:10 -03001037static int anysee_rc_query(struct dvb_usb_device *d)
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001038{
1039 u8 buf[] = {CMD_GET_IR_CODE};
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001040 u8 ircode[2];
Antti Palosaaria8494682010-10-17 18:25:10 -03001041 int ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001042
Antti Palosaaria8494682010-10-17 18:25:10 -03001043 /* Remote controller is basic NEC using address byte 0x08.
1044 Anysee device RC query returns only two bytes, status and code,
1045 address byte is dropped. Also it does not return any value for
1046 NEC RCs having address byte other than 0x08. Due to that, we
1047 cannot use that device as standard NEC receiver.
1048 It could be possible make hack which reads whole code directly
1049 from device memory... */
1050
1051 ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode));
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001052 if (ret)
1053 return ret;
1054
Antti Palosaaria8494682010-10-17 18:25:10 -03001055 if (ircode[0]) {
1056 deb_rc("%s: key pressed %02x\n", __func__, ircode[1]);
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -03001057 rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001058 }
Antti Palosaaria8494682010-10-17 18:25:10 -03001059
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001060 return 0;
1061}
1062
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001063static int anysee_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
1064{
1065 rc->allowed_protos = RC_TYPE_NEC;
1066 rc->query = anysee_rc_query;
1067 rc->interval = 250; /* windows driver uses 500ms */
1068
1069 return 0;
1070}
1071
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001072static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1073 int addr)
1074{
1075 struct dvb_usb_device *d = ci->data;
1076 int ret;
1077 u8 buf[] = {CMD_CI, 0x02, 0x40 | addr >> 8, addr & 0xff, 0x00, 1};
1078 u8 val;
1079
1080 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
1081 if (ret)
1082 return ret;
1083
1084 return val;
1085}
1086
1087static int anysee_ci_write_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1088 int addr, u8 val)
1089{
1090 struct dvb_usb_device *d = ci->data;
1091 int ret;
1092 u8 buf[] = {CMD_CI, 0x03, 0x40 | addr >> 8, addr & 0xff, 0x00, 1, val};
1093
1094 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
1095 if (ret)
1096 return ret;
1097
1098 return 0;
1099}
1100
1101static int anysee_ci_read_cam_control(struct dvb_ca_en50221 *ci, int slot,
1102 u8 addr)
1103{
1104 struct dvb_usb_device *d = ci->data;
1105 int ret;
1106 u8 buf[] = {CMD_CI, 0x04, 0x40, addr, 0x00, 1};
1107 u8 val;
1108
1109 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
1110 if (ret)
1111 return ret;
1112
1113 return val;
1114}
1115
1116static int anysee_ci_write_cam_control(struct dvb_ca_en50221 *ci, int slot,
1117 u8 addr, u8 val)
1118{
1119 struct dvb_usb_device *d = ci->data;
1120 int ret;
1121 u8 buf[] = {CMD_CI, 0x05, 0x40, addr, 0x00, 1, val};
1122
1123 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
1124 if (ret)
1125 return ret;
1126
1127 return 0;
1128}
1129
1130static int anysee_ci_slot_reset(struct dvb_ca_en50221 *ci, int slot)
1131{
1132 struct dvb_usb_device *d = ci->data;
1133 int ret;
1134 struct anysee_state *state = d->priv;
1135
1136 state->ci_cam_ready = jiffies + msecs_to_jiffies(1000);
1137
1138 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
1139 if (ret)
1140 return ret;
1141
1142 msleep(300);
1143
1144 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1145 if (ret)
1146 return ret;
1147
1148 return 0;
1149}
1150
1151static int anysee_ci_slot_shutdown(struct dvb_ca_en50221 *ci, int slot)
1152{
1153 struct dvb_usb_device *d = ci->data;
1154 int ret;
1155
1156 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
1157 if (ret)
1158 return ret;
1159
1160 msleep(30);
1161
1162 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1163 if (ret)
1164 return ret;
1165
1166 return 0;
1167}
1168
1169static int anysee_ci_slot_ts_enable(struct dvb_ca_en50221 *ci, int slot)
1170{
1171 struct dvb_usb_device *d = ci->data;
1172 int ret;
1173
1174 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 1), 0x02);
1175 if (ret)
1176 return ret;
1177
1178 return 0;
1179}
1180
1181static int anysee_ci_poll_slot_status(struct dvb_ca_en50221 *ci, int slot,
1182 int open)
1183{
1184 struct dvb_usb_device *d = ci->data;
1185 struct anysee_state *state = d->priv;
1186 int ret;
1187 u8 tmp;
1188
1189 ret = anysee_rd_reg_mask(d, REG_IOC, &tmp, 0x40);
1190 if (ret)
1191 return ret;
1192
1193 if (tmp == 0) {
1194 ret = DVB_CA_EN50221_POLL_CAM_PRESENT;
1195 if (time_after(jiffies, state->ci_cam_ready))
1196 ret |= DVB_CA_EN50221_POLL_CAM_READY;
1197 }
1198
1199 return ret;
1200}
1201
1202static int anysee_ci_init(struct dvb_usb_device *d)
1203{
1204 struct anysee_state *state = d->priv;
1205 int ret;
1206
1207 state->ci.owner = THIS_MODULE;
1208 state->ci.read_attribute_mem = anysee_ci_read_attribute_mem;
1209 state->ci.write_attribute_mem = anysee_ci_write_attribute_mem;
1210 state->ci.read_cam_control = anysee_ci_read_cam_control;
1211 state->ci.write_cam_control = anysee_ci_write_cam_control;
1212 state->ci.slot_reset = anysee_ci_slot_reset;
1213 state->ci.slot_shutdown = anysee_ci_slot_shutdown;
1214 state->ci.slot_ts_enable = anysee_ci_slot_ts_enable;
1215 state->ci.poll_slot_status = anysee_ci_poll_slot_status;
1216 state->ci.data = d;
1217
1218 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1219 if (ret)
1220 return ret;
1221
Antti Palosaari46de20a2012-01-20 17:39:17 -03001222 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 2)|(0 << 1)|(0 << 0), 0x07);
1223 if (ret)
1224 return ret;
1225
1226 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 2)|(1 << 1)|(1 << 0), 0x07);
1227 if (ret)
1228 return ret;
1229
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001230 ret = dvb_ca_en50221_init(&d->adapter[0].dvb_adap, &state->ci, 0, 1);
1231 if (ret)
1232 return ret;
1233
1234 return 0;
1235}
1236
1237static void anysee_ci_release(struct dvb_usb_device *d)
1238{
1239 struct anysee_state *state = d->priv;
1240
1241 /* detach CI */
1242 if (state->has_ci)
1243 dvb_ca_en50221_release(&state->ci);
1244
1245 return;
1246}
1247
1248static int anysee_init(struct dvb_usb_device *d)
1249{
1250 struct anysee_state *state = d->priv;
1251 int ret;
1252
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001253 /* There is one interface with two alternate settings.
1254 Alternate setting 0 is for bulk transfer.
1255 Alternate setting 1 is for isochronous transfer.
1256 We use bulk transfer (alternate setting 0). */
1257 ret = usb_set_interface(d->udev, 0, 0);
1258 if (ret)
1259 return ret;
1260
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001261 /* LED light */
1262 ret = anysee_led_ctrl(d, 0x01, 0x03);
1263 if (ret)
1264 return ret;
1265
1266 /* enable IR */
1267 ret = anysee_ir_ctrl(d, 1);
1268 if (ret)
1269 return ret;
1270
1271 /* attach CI */
1272 if (state->has_ci) {
1273 ret = anysee_ci_init(d);
1274 if (ret) {
1275 state->has_ci = false;
1276 return ret;
1277 }
1278 }
1279
1280 return 0;
1281}
1282
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001283static void anysee_disconnect(struct dvb_usb_device *d)
1284{
1285 return anysee_ci_release(d);
1286}
1287
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001288/* DVB USB Driver stuff */
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001289static struct dvb_usb_device_properties anysee_props = {
1290 .driver_name = KBUILD_MODNAME,
1291 .owner = THIS_MODULE,
1292 .adapter_nr = adapter_nr,
1293 .size_of_priv = sizeof(struct anysee_state),
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001294
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001295 .generic_bulk_ctrl_endpoint = 0x01,
1296 .generic_bulk_ctrl_endpoint_response = 0x81,
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001297
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001298 .i2c_algo = &anysee_i2c_algo,
1299 .read_config = anysee_read_config,
1300 .frontend_attach = anysee_frontend_attach,
1301 .tuner_attach = anysee_tuner_attach,
1302 .init = anysee_init,
1303 .get_rc_config = anysee_get_rc_config,
1304 .frontend_ctrl = anysee_frontend_ctrl,
1305 .streaming_ctrl = anysee_streaming_ctrl,
1306 .disconnect = anysee_disconnect,
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001307
1308 .num_adapters = 1,
1309 .adapter = {
1310 {
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001311 .stream = {
1312 .type = USB_BULK,
1313 .count = 8,
1314 .endpoint = 0x82,
1315 .u = {
1316 .bulk = {
Antti Palosaariab693332009-09-16 19:47:01 -03001317 .buffersize = (16*512),
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001318 }
1319 }
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001320 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001321 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001322 }
1323};
1324
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001325static const struct usb_device_id anysee_id_table[] = {
1326 { DVB_USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE,
1327 &anysee_props, "Anysee", RC_MAP_ANYSEE) },
1328 { DVB_USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE,
1329 &anysee_props, "Anysee", RC_MAP_ANYSEE) },
1330 { }
1331};
1332MODULE_DEVICE_TABLE(usb, anysee_id_table);
1333
1334static struct usb_driver anysee_usb_driver = {
1335 .name = KBUILD_MODNAME,
1336 .id_table = anysee_id_table,
1337 .probe = dvb_usbv2_probe,
1338 .disconnect = dvb_usbv2_disconnect,
1339 .suspend = dvb_usbv2_suspend,
1340 .resume = dvb_usbv2_resume,
1341 .no_dynamic_id = 1,
1342 .soft_unbind = 1,
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001343};
1344
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001345module_usb_driver(anysee_usb_driver);
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001346
1347MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1348MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
1349MODULE_LICENSE("GPL");