blob: 6705d81f0cb2f174f6417e8ef1c20d2ed71e1442 [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
Antti Palosaaria51e34d2008-05-17 23:05:48 -030047DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
Akinobu Mitadec0c462008-10-29 21:16:04 -030048static DEFINE_MUTEX(anysee_usb_mutex);
Antti Palosaaria51e34d2008-05-17 23:05:48 -030049
50static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
51 u8 *rbuf, u8 rlen)
52{
Antti Palosaari05cd62e2012-06-18 19:39:02 -030053 struct anysee_state *state = d_to_priv(d);
Antti Palosaaricf427952012-01-21 11:19:29 -030054 int act_len, ret, i;
Antti Palosaaria51e34d2008-05-17 23:05:48 -030055 u8 buf[64];
56
Antti Palosaaria51e34d2008-05-17 23:05:48 -030057 memcpy(&buf[0], sbuf, slen);
58 buf[60] = state->seq++;
59
Antti Palosaaria4e7c512012-06-14 04:56:09 -030060 mutex_lock(&anysee_usb_mutex);
Antti Palosaaria51e34d2008-05-17 23:05:48 -030061
Antti Palosaari82026f92012-08-14 15:56:20 -030062 dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, slen, buf);
Antti Palosaari4048da22011-09-29 20:28:53 -030063
Antti Palosaaria51e34d2008-05-17 23:05:48 -030064 /* We need receive one message more after dvb_usb_generic_rw due
65 to weird transaction flow, which is 1 x send + 2 x receive. */
Antti Palosaari1162c7b2012-06-20 20:27:42 -030066 ret = dvb_usbv2_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf));
Antti Palosaaricf427952012-01-21 11:19:29 -030067 if (ret)
68 goto error_unlock;
69
70 /* TODO FIXME: dvb_usb_generic_rw() fails rarely with error code -32
71 * (EPIPE, Broken pipe). Function supports currently msleep() as a
72 * parameter but I would not like to use it, since according to
73 * Documentation/timers/timers-howto.txt it should not be used such
74 * short, under < 20ms, sleeps. Repeating failed message would be
75 * better choice as not to add unwanted delays...
76 * Fixing that correctly is one of those or both;
77 * 1) use repeat if possible
78 * 2) add suitable delay
79 */
80
81 /* get answer, retry few times if error returned */
82 for (i = 0; i < 3; i++) {
Antti Palosaaria51e34d2008-05-17 23:05:48 -030083 /* receive 2nd answer */
84 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
Antti Palosaaria4e7c512012-06-14 04:56:09 -030085 d->props->generic_bulk_ctrl_endpoint), buf, sizeof(buf),
Antti Palosaaria51e34d2008-05-17 23:05:48 -030086 &act_len, 2000);
Antti Palosaaricf427952012-01-21 11:19:29 -030087
88 if (ret) {
Antti Palosaari82026f92012-08-14 15:56:20 -030089 dev_dbg(&d->udev->dev, "%s: recv bulk message " \
90 "failed=%d\n", __func__, ret);
Antti Palosaaricf427952012-01-21 11:19:29 -030091 } else {
Antti Palosaari82026f92012-08-14 15:56:20 -030092 dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__,
93 rlen, buf);
Antti Palosaari4048da22011-09-29 20:28:53 -030094
95 if (buf[63] != 0x4f)
Antti Palosaari82026f92012-08-14 15:56:20 -030096 dev_dbg(&d->udev->dev, "%s: cmd failed\n",
97 __func__);
Antti Palosaaricf427952012-01-21 11:19:29 -030098
99 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300100 }
101 }
102
Antti Palosaaricf427952012-01-21 11:19:29 -0300103 if (ret) {
104 /* all retries failed, it is fatal */
Antti Palosaari82026f92012-08-14 15:56:20 -0300105 dev_err(&d->udev->dev, "%s: recv bulk message failed=%d\n",
106 KBUILD_MODNAME, ret);
Antti Palosaaricf427952012-01-21 11:19:29 -0300107 goto error_unlock;
108 }
109
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300110 /* read request, copy returned data to return buf */
Antti Palosaaricf427952012-01-21 11:19:29 -0300111 if (rbuf && rlen)
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300112 memcpy(rbuf, buf, rlen);
113
Antti Palosaaricf427952012-01-21 11:19:29 -0300114error_unlock:
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300115 mutex_unlock(&anysee_usb_mutex);
116
117 return ret;
118}
119
120static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
121{
122 u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};
123 int ret;
124 ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);
Antti Palosaari82026f92012-08-14 15:56:20 -0300125 dev_dbg(&d->udev->dev, "%s: reg=%04x val=%02x\n", __func__, reg, *val);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300126 return ret;
127}
128
129static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
130{
131 u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};
Antti Palosaari82026f92012-08-14 15:56:20 -0300132 dev_dbg(&d->udev->dev, "%s: reg=%04x val=%02x\n", __func__, reg, val);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300133 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
134}
135
Antti Palosaari41f81f62011-04-10 17:53:52 -0300136/* write single register with mask */
137static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
138 u8 mask)
139{
140 int ret;
141 u8 tmp;
142
143 /* no need for read if whole reg is written */
144 if (mask != 0xff) {
145 ret = anysee_read_reg(d, reg, &tmp);
146 if (ret)
147 return ret;
148
149 val &= mask;
150 tmp &= ~mask;
151 val |= tmp;
152 }
153
154 return anysee_write_reg(d, reg, val);
155}
156
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300157/* read single register with mask */
158static int anysee_rd_reg_mask(struct dvb_usb_device *d, u16 reg, u8 *val,
159 u8 mask)
160{
161 int ret, i;
162 u8 tmp;
163
164 ret = anysee_read_reg(d, reg, &tmp);
165 if (ret)
166 return ret;
167
168 tmp &= mask;
169
170 /* find position of the first bit */
171 for (i = 0; i < 8; i++) {
172 if ((mask >> i) & 0x01)
173 break;
174 }
175 *val = tmp >> i;
176
177 return 0;
178}
179
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300180static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
181{
182 u8 buf[] = {CMD_GET_HW_INFO};
183 return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);
184}
185
Antti Palosaaria13a6e12012-06-26 00:04:33 -0300186static int anysee_streaming_ctrl(struct dvb_frontend *fe, int onoff)
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300187{
188 u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};
Antti Palosaari82026f92012-08-14 15:56:20 -0300189 dev_dbg(&fe_to_d(fe)->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Antti Palosaaria13a6e12012-06-26 00:04:33 -0300190 return anysee_ctrl_msg(fe_to_d(fe), buf, sizeof(buf), NULL, 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300191}
192
193static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)
194{
195 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};
Antti Palosaari82026f92012-08-14 15:56:20 -0300196 dev_dbg(&d->udev->dev, "%s: state=%d interval=%d\n", __func__,
197 mode, interval);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300198 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
199}
200
201static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
202{
203 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};
Antti Palosaari82026f92012-08-14 15:56:20 -0300204 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300205 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
206}
207
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300208/* I2C */
209static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
210 int num)
211{
212 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Mauro Carvalho Chehab902571a2008-12-29 19:02:24 -0300213 int ret = 0, inc, i = 0;
Antti Palosaari21d2e932011-05-24 06:04:08 -0300214 u8 buf[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300215
216 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
217 return -EAGAIN;
218
219 while (i < num) {
220 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
Antti Palosaari21d2e932011-05-24 06:04:08 -0300221 if (msg[i].len > 2 || msg[i+1].len > 60) {
222 ret = -EOPNOTSUPP;
223 break;
224 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300225 buf[0] = CMD_I2C_READ;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300226 buf[1] = (msg[i].addr << 1) | 0x01;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300227 buf[2] = msg[i].buf[0];
Antti Palosaari882b82c2011-04-12 19:49:25 -0300228 buf[3] = msg[i].buf[1];
229 buf[4] = msg[i].len-1;
Antti Palosaarib3e6a5a2011-04-09 21:00:51 -0300230 buf[5] = msg[i+1].len;
Antti Palosaari21d2e932011-05-24 06:04:08 -0300231 ret = anysee_ctrl_msg(d, buf, 6, msg[i+1].buf,
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300232 msg[i+1].len);
233 inc = 2;
234 } else {
Antti Palosaari21d2e932011-05-24 06:04:08 -0300235 if (msg[i].len > 48) {
236 ret = -EOPNOTSUPP;
237 break;
238 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300239 buf[0] = CMD_I2C_WRITE;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300240 buf[1] = (msg[i].addr << 1);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300241 buf[2] = msg[i].len;
242 buf[3] = 0x01;
243 memcpy(&buf[4], msg[i].buf, msg[i].len);
Antti Palosaari21d2e932011-05-24 06:04:08 -0300244 ret = anysee_ctrl_msg(d, buf, 4 + msg[i].len, NULL, 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300245 inc = 1;
246 }
247 if (ret)
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300248 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300249
250 i += inc;
251 }
252
253 mutex_unlock(&d->i2c_mutex);
254
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300255 return ret ? ret : i;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300256}
257
258static u32 anysee_i2c_func(struct i2c_adapter *adapter)
259{
260 return I2C_FUNC_I2C;
261}
262
263static struct i2c_algorithm anysee_i2c_algo = {
264 .master_xfer = anysee_master_xfer,
265 .functionality = anysee_i2c_func,
266};
267
268static int anysee_mt352_demod_init(struct dvb_frontend *fe)
269{
Antti Palosaariae3745f2009-09-16 19:50:25 -0300270 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
271 static u8 reset[] = { RESET, 0x80 };
272 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
273 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
274 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300275 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
276
277 mt352_write(fe, clock_config, sizeof(clock_config));
278 udelay(200);
279 mt352_write(fe, reset, sizeof(reset));
280 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
281
282 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
283 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
284 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
285
286 return 0;
287}
288
289/* Callbacks for DVB USB */
290static struct tda10023_config anysee_tda10023_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300291 .demod_address = (0x1a >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300292 .invert = 0,
293 .xtal = 16000000,
294 .pll_m = 11,
295 .pll_p = 3,
296 .pll_n = 1,
Antti Palosaari5ae2fca2008-06-09 22:58:22 -0300297 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
298 .deltaf = 0xfeeb,
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300299};
300
301static struct mt352_config anysee_mt352_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300302 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300303 .demod_init = anysee_mt352_demod_init,
304};
305
306static struct zl10353_config anysee_zl10353_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300307 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300308 .parallel_ts = 1,
309};
310
Antti Palosaari1fd80702011-04-12 17:34:08 -0300311static struct zl10353_config anysee_zl10353_tda18212_config2 = {
312 .demod_address = (0x1e >> 1),
313 .parallel_ts = 1,
314 .disable_i2c_gate_ctrl = 1,
315 .no_tuner = 1,
316 .if2 = 41500,
317};
318
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300319static struct zl10353_config anysee_zl10353_tda18212_config = {
320 .demod_address = (0x18 >> 1),
321 .parallel_ts = 1,
322 .disable_i2c_gate_ctrl = 1,
323 .no_tuner = 1,
324 .if2 = 41500,
325};
326
327static struct tda10023_config anysee_tda10023_tda18212_config = {
328 .demod_address = (0x1a >> 1),
329 .xtal = 16000000,
330 .pll_m = 12,
331 .pll_p = 3,
332 .pll_n = 1,
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300333 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_B,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300334 .deltaf = 0xba02,
335};
336
337static struct tda18212_config anysee_tda18212_config = {
338 .i2c_address = (0xc0 >> 1),
339 .if_dvbt_6 = 4150,
340 .if_dvbt_7 = 4150,
341 .if_dvbt_8 = 4150,
342 .if_dvbc = 5000,
343};
344
Antti Palosaari608add82011-08-12 18:29:46 -0300345static struct tda18212_config anysee_tda18212_config2 = {
346 .i2c_address = 0x60 /* (0xc0 >> 1) */,
347 .if_dvbt_6 = 3550,
348 .if_dvbt_7 = 3700,
349 .if_dvbt_8 = 4150,
350 .if_dvbt2_6 = 3250,
351 .if_dvbt2_7 = 4000,
352 .if_dvbt2_8 = 4000,
353 .if_dvbc = 5000,
354};
355
Antti Palosaarif0a53102011-04-27 21:11:59 -0300356static struct cx24116_config anysee_cx24116_config = {
357 .demod_address = (0xaa >> 1),
358 .mpg_clk_pos_pol = 0x00,
359 .i2c_wr_max = 48,
360};
361
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300362static struct stv0900_config anysee_stv0900_config = {
363 .demod_address = (0xd0 >> 1),
364 .demod_mode = 0,
365 .xtal = 8000000,
366 .clkmode = 3,
367 .diseqc_mode = 2,
368 .tun1_maddress = 0,
369 .tun1_adc = 1, /* 1 Vpp */
370 .path1_mode = 3,
371};
372
373static struct stv6110_config anysee_stv6110_config = {
374 .i2c_address = (0xc0 >> 1),
375 .mclk = 16000000,
376 .clk_div = 1,
377};
378
Antti Palosaarif0a53102011-04-27 21:11:59 -0300379static struct isl6423_config anysee_isl6423_config = {
380 .current_max = SEC_CURRENT_800m,
381 .curlim = SEC_CURRENT_LIM_OFF,
382 .mod_extern = 1,
383 .addr = (0x10 >> 1),
384};
385
Antti Palosaari608add82011-08-12 18:29:46 -0300386static struct cxd2820r_config anysee_cxd2820r_config = {
387 .i2c_address = 0x6d, /* (0xda >> 1) */
388 .ts_mode = 0x38,
Antti Palosaari608add82011-08-12 18:29:46 -0300389};
390
Antti Palosaari41f81f62011-04-10 17:53:52 -0300391/*
392 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
393 * Manufacturer: AMT.CO.KR
394 *
395 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
396 * PCB: ?
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300397 * parts: DNOS404ZH102A(MT352, DTT7579(?))
Antti Palosaari41f81f62011-04-10 17:53:52 -0300398 *
Antti Palosaari05c46c02011-05-25 18:30:09 -0300399 * E30 VID=04b4 PID=861f HW=2 FW=2.1 "anysee-T(LP)"
400 * PCB: PCB 507T (rev1.61)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300401 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
Antti Palosaari05c46c02011-05-25 18:30:09 -0300402 * OEA=0a OEB=00 OEC=00 OED=ff OEE=00
403 * IOA=45 IOB=ff IOC=00 IOD=ff IOE=00
Antti Palosaari41f81f62011-04-10 17:53:52 -0300404 *
405 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
406 * PCB: 507CD (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300407 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
Antti Palosaari05c46c02011-05-25 18:30:09 -0300408 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
409 * IOA=4f IOB=ff IOC=00 IOD=06 IOE=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300410 * IOD[0] ZL10353 1=enabled
411 * IOA[7] TS 0=enabled
412 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
413 *
414 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
415 * PCB: 507DC (rev0.2)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300416 * parts: TDA10023, DTOS403IH102B TM, CST56I01
Antti Palosaari05c46c02011-05-25 18:30:09 -0300417 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
418 * IOA=4f IOB=ff IOC=00 IOD=26 IOE=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300419 * IOD[0] TDA10023 1=enabled
420 *
Antti Palosaarif0a53102011-04-27 21:11:59 -0300421 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
422 * PCB: 507SI (rev2.1)
423 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300424 * OEA=80 OEB=00 OEC=ff OED=ff OEE=fe
425 * IOA=4d IOB=ff IOC=00 IOD=26 IOE=01
Antti Palosaarif0a53102011-04-27 21:11:59 -0300426 * IOD[0] CX24116 1=enabled
427 *
Antti Palosaari41f81f62011-04-10 17:53:52 -0300428 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
429 * PCB: 507FA (rev0.4)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300430 * parts: TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300431 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
432 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300433 * IOD[5] TDA10023 1=enabled
434 * IOE[0] tuner 1=enabled
435 *
436 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
437 * PCB: 507FA (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300438 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300439 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
440 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300441 * DVB-C:
442 * IOD[5] TDA10023 1=enabled
443 * IOE[0] tuner 1=enabled
444 * DVB-T:
445 * IOD[0] ZL10353 1=enabled
446 * IOE[0] tuner 0=enabled
447 * tuner is behind ZL10353 I2C-gate
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300448 *
449 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
450 * PCB: 508TC (rev0.6)
451 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
Antti Palosaari05c46c02011-05-25 18:30:09 -0300452 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
453 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300454 * IOA[7] TS 1=enabled
455 * IOE[4] TDA18212 1=enabled
456 * DVB-C:
457 * IOD[6] ZL10353 0=disabled
458 * IOD[5] TDA10023 1=enabled
459 * IOE[0] IF 1=enabled
460 * DVB-T:
461 * IOD[5] TDA10023 0=disabled
462 * IOD[6] ZL10353 1=enabled
463 * IOE[0] IF 0=enabled
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300464 *
465 * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
466 * PCB: 508S2 (rev0.7)
467 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
Antti Palosaari05c46c02011-05-25 18:30:09 -0300468 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
469 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300470 * IOA[7] TS 1=enabled
471 * IOE[5] STV0903 1=enabled
472 *
Antti Palosaari608add82011-08-12 18:29:46 -0300473 * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)"
474 * PCB: 508T2C (rev0.3)
475 * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024
476 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
477 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
478 * IOA[7] TS 1=enabled
479 * IOE[5] CXD2820R 1=enabled
480 *
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300481 * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)"
482 * PCB: 508PTC (rev0.5)
483 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
484 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
485 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
486 * IOA[7] TS 1=enabled
487 * IOE[4] TDA18212 1=enabled
488 * DVB-C:
489 * IOD[6] ZL10353 0=disabled
490 * IOD[5] TDA10023 1=enabled
491 * IOE[0] IF 1=enabled
492 * DVB-T:
493 * IOD[5] TDA10023 0=disabled
494 * IOD[6] ZL10353 1=enabled
495 * IOE[0] IF 0=enabled
Antti Palosaarifea3c392011-05-25 18:21:43 -0300496 *
Antti Palosaari608add82011-08-12 18:29:46 -0300497 * E7 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)"
Antti Palosaarifea3c392011-05-25 18:21:43 -0300498 * PCB: 508PS2 (rev0.4)
499 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
500 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
501 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
502 * IOA[7] TS 1=enabled
503 * IOE[5] STV0903 1=enabled
Antti Palosaari41f81f62011-04-10 17:53:52 -0300504 */
505
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300506static int anysee_read_config(struct dvb_usb_device *d)
507{
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300508 struct anysee_state *state = d_to_priv(d);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300509 int ret;
510 u8 hw_info[3];
511
512 /*
513 * Check which hardware we have.
514 * We must do this call two times to get reliable values (hw/fw bug).
515 */
516 ret = anysee_get_hw_info(d, hw_info);
517 if (ret)
518 goto error;
519
520 ret = anysee_get_hw_info(d, hw_info);
521 if (ret)
522 goto error;
523
Antti Palosaari82026f92012-08-14 15:56:20 -0300524 /*
525 * Meaning of these info bytes are guessed.
526 */
527 dev_info(&d->udev->dev, "%s: firmware version %d.%d hardware id %d\n",
528 KBUILD_MODNAME, hw_info[1], hw_info[2], hw_info[0]);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300529
530 state->hw = hw_info[0];
531error:
532 return ret;
533}
Antti Palosaaribe943512011-09-05 22:10:05 -0300534
535/* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */
536static int anysee_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
537{
Antti Palosaaribe943512011-09-05 22:10:05 -0300538 /* enable / disable tuner access on IOE[4] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300539 return anysee_wr_reg_mask(fe_to_d(fe), REG_IOE, (enable << 4), 0x10);
Antti Palosaaribe943512011-09-05 22:10:05 -0300540}
541
Antti Palosaari449d1a02011-07-25 20:25:21 -0300542static int anysee_frontend_ctrl(struct dvb_frontend *fe, int onoff)
543{
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300544 struct anysee_state *state = fe_to_priv(fe);
545 struct dvb_usb_device *d = fe_to_d(fe);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300546 int ret;
Antti Palosaari82026f92012-08-14 15:56:20 -0300547 dev_dbg(&d->udev->dev, "%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300548
549 /* no frontend sleep control */
550 if (onoff == 0)
551 return 0;
552
553 switch (state->hw) {
554 case ANYSEE_HW_507FA: /* 15 */
555 /* E30 Combo Plus */
556 /* E30 C Plus */
557
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300558 if (fe->id == 0) {
Antti Palosaari449d1a02011-07-25 20:25:21 -0300559 /* disable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300560 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300561 if (ret)
562 goto error;
563
564 /* enable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300565 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300566 if (ret)
567 goto error;
568
569 /* enable DVB-C tuner on IOE[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300570 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300571 if (ret)
572 goto error;
573 } else {
574 /* disable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300575 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300576 if (ret)
577 goto error;
578
579 /* enable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300580 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300581 if (ret)
582 goto error;
583
584 /* enable DVB-T tuner on IOE[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300585 ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300586 if (ret)
587 goto error;
588 }
589
590 break;
591 case ANYSEE_HW_508TC: /* 18 */
592 case ANYSEE_HW_508PTC: /* 21 */
593 /* E7 TC */
594 /* E7 PTC */
595
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300596 if (fe->id == 0) {
Antti Palosaari449d1a02011-07-25 20:25:21 -0300597 /* disable DVB-T demod on IOD[6] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300598 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 6), 0x40);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300599 if (ret)
600 goto error;
601
602 /* enable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300603 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300604 if (ret)
605 goto error;
606
607 /* enable IF route on IOE[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300608 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300609 if (ret)
610 goto error;
611 } else {
612 /* disable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300613 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300614 if (ret)
615 goto error;
616
617 /* enable DVB-T demod on IOD[6] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300618 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 6), 0x40);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300619 if (ret)
620 goto error;
621
622 /* enable IF route on IOE[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300623 ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300624 if (ret)
625 goto error;
626 }
627
628 break;
629 default:
630 ret = 0;
631 }
632
633error:
634 return ret;
635}
636
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300637static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
638{
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300639 struct anysee_state *state = adap_to_priv(adap);
640 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300641 int ret;
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300642 u8 tmp;
643 struct i2c_msg msg[2] = {
644 {
645 .addr = anysee_tda18212_config.i2c_address,
646 .flags = 0,
647 .len = 1,
648 .buf = "\x00",
649 }, {
650 .addr = anysee_tda18212_config.i2c_address,
651 .flags = I2C_M_RD,
652 .len = 1,
653 .buf = &tmp,
654 }
655 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300656
Antti Palosaari41f81f62011-04-10 17:53:52 -0300657 switch (state->hw) {
Antti Palosaari05c46c02011-05-25 18:30:09 -0300658 case ANYSEE_HW_507T: /* 2 */
Antti Palosaari41f81f62011-04-10 17:53:52 -0300659 /* E30 */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300660
Antti Palosaari41f81f62011-04-10 17:53:52 -0300661 /* attach demod */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300662 adap->fe[0] = dvb_attach(mt352_attach, &anysee_mt352_config,
663 &d->i2c_adap);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300664 if (adap->fe[0])
Antti Palosaari41f81f62011-04-10 17:53:52 -0300665 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300666
Antti Palosaari41f81f62011-04-10 17:53:52 -0300667 /* attach demod */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300668 adap->fe[0] = dvb_attach(zl10353_attach, &anysee_zl10353_config,
669 &d->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300670
671 break;
672 case ANYSEE_HW_507CD: /* 6 */
673 /* E30 Plus */
674
675 /* enable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300676 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300677 if (ret)
678 goto error;
679
680 /* enable transport stream on IOA[7] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300681 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300682 if (ret)
683 goto error;
684
685 /* attach demod */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300686 adap->fe[0] = dvb_attach(zl10353_attach, &anysee_zl10353_config,
687 &d->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300688
689 break;
690 case ANYSEE_HW_507DC: /* 10 */
691 /* E30 C Plus */
692
693 /* enable DVB-C demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300694 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300695 if (ret)
696 goto error;
697
698 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300699 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300700 &anysee_tda10023_config, &d->i2c_adap, 0x48);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300701
702 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300703 case ANYSEE_HW_507SI: /* 11 */
704 /* E30 S2 Plus */
705
706 /* enable DVB-S/S2 demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300707 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaarif0a53102011-04-27 21:11:59 -0300708 if (ret)
709 goto error;
710
711 /* attach demod */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300712 adap->fe[0] = dvb_attach(cx24116_attach, &anysee_cx24116_config,
713 &d->i2c_adap);
Antti Palosaarif0a53102011-04-27 21:11:59 -0300714
715 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300716 case ANYSEE_HW_507FA: /* 15 */
717 /* E30 Combo Plus */
718 /* E30 C Plus */
719
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300720 /* enable tuner on IOE[4] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300721 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 4), 0x10);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300722 if (ret)
723 goto error;
724
725 /* probe TDA18212 */
726 tmp = 0;
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300727 ret = i2c_transfer(&d->i2c_adap, msg, 2);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300728 if (ret == 2 && tmp == 0xc7)
Antti Palosaari82026f92012-08-14 15:56:20 -0300729 dev_dbg(&d->udev->dev, "%s: TDA18212 found\n",
730 __func__);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300731 else
732 tmp = 0;
733
734 /* disable tuner on IOE[4] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300735 ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 4), 0x10);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300736 if (ret)
737 goto error;
738
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300739 /* disable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300740 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 0), 0x01);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300741 if (ret)
742 goto error;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300743
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300744 /* enable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300745 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300746 if (ret)
747 goto error;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300748
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300749 /* attach demod */
750 if (tmp == 0xc7) {
751 /* TDA18212 config */
752 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300753 &anysee_tda10023_tda18212_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300754 &d->i2c_adap, 0x48);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300755
756 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
757 if (adap->fe[0])
758 adap->fe[0]->ops.i2c_gate_ctrl =
759 anysee_i2c_gate_ctrl;
760 } else {
761 /* PLL config */
762 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300763 &anysee_tda10023_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300764 &d->i2c_adap, 0x48);
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300765 }
Antti Palosaarie82eea72011-04-12 19:43:30 -0300766
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300767 /* break out if first frontend attaching fails */
768 if (!adap->fe[0])
769 break;
770
771 /* disable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300772 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300773 if (ret)
774 goto error;
775
776 /* enable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300777 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300778 if (ret)
779 goto error;
780
781 /* attach demod */
Antti Palosaaribe943512011-09-05 22:10:05 -0300782 if (tmp == 0xc7) {
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300783 /* TDA18212 config */
784 adap->fe[1] = dvb_attach(zl10353_attach,
785 &anysee_zl10353_tda18212_config2,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300786 &d->i2c_adap);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300787
788 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
789 if (adap->fe[1])
790 adap->fe[1]->ops.i2c_gate_ctrl =
791 anysee_i2c_gate_ctrl;
792 } else {
793 /* PLL config */
794 adap->fe[1] = dvb_attach(zl10353_attach,
795 &anysee_zl10353_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300796 &d->i2c_adap);
Antti Palosaaribe943512011-09-05 22:10:05 -0300797 }
798
Antti Palosaari41f81f62011-04-10 17:53:52 -0300799 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300800 case ANYSEE_HW_508TC: /* 18 */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300801 case ANYSEE_HW_508PTC: /* 21 */
Antti Palosaaria43be982011-04-10 20:23:02 -0300802 /* E7 TC */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300803 /* E7 PTC */
Antti Palosaaria43be982011-04-10 20:23:02 -0300804
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300805 /* disable DVB-T demod on IOD[6] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300806 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 6), 0x40);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300807 if (ret)
808 goto error;
Antti Palosaaria43be982011-04-10 20:23:02 -0300809
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300810 /* enable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300811 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300812 if (ret)
813 goto error;
Antti Palosaaria43be982011-04-10 20:23:02 -0300814
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300815 /* attach demod */
816 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300817 &anysee_tda10023_tda18212_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300818 &d->i2c_adap, 0x48);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300819
Antti Palosaaribe943512011-09-05 22:10:05 -0300820 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300821 if (adap->fe[0])
822 adap->fe[0]->ops.i2c_gate_ctrl = anysee_i2c_gate_ctrl;
823
824 /* break out if first frontend attaching fails */
825 if (!adap->fe[0])
826 break;
827
828 /* disable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300829 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300830 if (ret)
831 goto error;
832
833 /* enable DVB-T demod on IOD[6] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300834 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 6), 0x40);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300835 if (ret)
836 goto error;
837
838 /* attach demod */
839 adap->fe[1] = dvb_attach(zl10353_attach,
840 &anysee_zl10353_tda18212_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300841 &d->i2c_adap);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300842
843 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
844 if (adap->fe[1])
845 adap->fe[1]->ops.i2c_gate_ctrl = anysee_i2c_gate_ctrl;
Antti Palosaaribe943512011-09-05 22:10:05 -0300846
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300847 state->has_ci = true;
848
Antti Palosaaria43be982011-04-10 20:23:02 -0300849 break;
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300850 case ANYSEE_HW_508S2: /* 19 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300851 case ANYSEE_HW_508PS2: /* 22 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300852 /* E7 S2 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300853 /* E7 PS2 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300854
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300855 /* enable DVB-S/S2 demod on IOE[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300856 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 5), 0x20);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300857 if (ret)
858 goto error;
859
860 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300861 adap->fe[0] = dvb_attach(stv0900_attach,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300862 &anysee_stv0900_config, &d->i2c_adap, 0);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300863
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300864 state->has_ci = true;
865
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300866 break;
Antti Palosaari608add82011-08-12 18:29:46 -0300867 case ANYSEE_HW_508T2C: /* 20 */
868 /* E7 T2C */
869
Antti Palosaari608add82011-08-12 18:29:46 -0300870 /* enable DVB-T/T2/C demod on IOE[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300871 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 5), 0x20);
Antti Palosaari608add82011-08-12 18:29:46 -0300872 if (ret)
873 goto error;
874
Antti Palosaarifaf27972012-01-15 14:20:50 -0300875 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300876 adap->fe[0] = dvb_attach(cxd2820r_attach,
Antti Palosaari1e8f31f2012-07-19 21:10:36 -0300877 &anysee_cxd2820r_config, &d->i2c_adap, NULL);
Antti Palosaari608add82011-08-12 18:29:46 -0300878
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300879 state->has_ci = true;
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300880
881 break;
882 }
883
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300884 if (!adap->fe[0]) {
Antti Palosaari41f81f62011-04-10 17:53:52 -0300885 /* we have no frontend :-( */
886 ret = -ENODEV;
Antti Palosaari82026f92012-08-14 15:56:20 -0300887 dev_err(&d->udev->dev, "%s: Unsupported Anysee version. " \
888 "Please report the " \
889 "<linux-media@vger.kernel.org>.\n",
890 KBUILD_MODNAME);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300891 }
Antti Palosaari41f81f62011-04-10 17:53:52 -0300892error:
893 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300894}
895
896static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
897{
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300898 struct anysee_state *state = adap_to_priv(adap);
899 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300900 struct dvb_frontend *fe;
Antti Palosaarie82eea72011-04-12 19:43:30 -0300901 int ret;
Antti Palosaari82026f92012-08-14 15:56:20 -0300902 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300903
Antti Palosaari41f81f62011-04-10 17:53:52 -0300904 switch (state->hw) {
Antti Palosaari05c46c02011-05-25 18:30:09 -0300905 case ANYSEE_HW_507T: /* 2 */
Antti Palosaari41f81f62011-04-10 17:53:52 -0300906 /* E30 */
907
908 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300909 fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc2 >> 1), NULL,
910 DVB_PLL_THOMSON_DTT7579);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300911
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300912 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300913 case ANYSEE_HW_507CD: /* 6 */
914 /* E30 Plus */
915
916 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300917 fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc2 >> 1),
918 &d->i2c_adap, DVB_PLL_THOMSON_DTT7579);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300919
920 break;
921 case ANYSEE_HW_507DC: /* 10 */
922 /* E30 C Plus */
923
924 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300925 fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc0 >> 1),
926 &d->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300927
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300928 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300929 case ANYSEE_HW_507SI: /* 11 */
930 /* E30 S2 Plus */
931
932 /* attach LNB controller */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300933 fe = dvb_attach(isl6423_attach, adap->fe[0], &d->i2c_adap,
934 &anysee_isl6423_config);
Antti Palosaarif0a53102011-04-27 21:11:59 -0300935
936 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300937 case ANYSEE_HW_507FA: /* 15 */
938 /* E30 Combo Plus */
939 /* E30 C Plus */
940
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300941 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
942 * fails attach old simple PLL. */
943
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300944 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300945 fe = dvb_attach(tda18212_attach, adap->fe[0], &d->i2c_adap,
946 &anysee_tda18212_config);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300947
948 if (fe && adap->fe[1]) {
949 /* attach tuner for 2nd FE */
950 fe = dvb_attach(tda18212_attach, adap->fe[1],
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300951 &d->i2c_adap, &anysee_tda18212_config);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300952 break;
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300953 } else if (fe) {
954 break;
955 }
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300956
Antti Palosaari41f81f62011-04-10 17:53:52 -0300957 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300958 fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc0 >> 1),
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300959 &d->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300960
961 if (fe && adap->fe[1]) {
962 /* attach tuner for 2nd FE */
963 fe = dvb_attach(dvb_pll_attach, adap->fe[0],
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300964 (0xc0 >> 1), &d->i2c_adap,
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300965 DVB_PLL_SAMSUNG_DTOS403IH102A);
966 }
Antti Palosaari41f81f62011-04-10 17:53:52 -0300967
968 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300969 case ANYSEE_HW_508TC: /* 18 */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300970 case ANYSEE_HW_508PTC: /* 21 */
Antti Palosaaria43be982011-04-10 20:23:02 -0300971 /* E7 TC */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300972 /* E7 PTC */
Antti Palosaaria43be982011-04-10 20:23:02 -0300973
Antti Palosaaria43be982011-04-10 20:23:02 -0300974 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300975 fe = dvb_attach(tda18212_attach, adap->fe[0], &d->i2c_adap,
976 &anysee_tda18212_config);
Antti Palosaaria43be982011-04-10 20:23:02 -0300977
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300978 if (fe) {
979 /* attach tuner for 2nd FE */
980 fe = dvb_attach(tda18212_attach, adap->fe[1],
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300981 &d->i2c_adap, &anysee_tda18212_config);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300982 }
983
Antti Palosaaria43be982011-04-10 20:23:02 -0300984 break;
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300985 case ANYSEE_HW_508S2: /* 19 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300986 case ANYSEE_HW_508PS2: /* 22 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300987 /* E7 S2 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300988 /* E7 PS2 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300989
990 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300991 fe = dvb_attach(stv6110_attach, adap->fe[0],
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300992 &anysee_stv6110_config, &d->i2c_adap);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300993
994 if (fe) {
995 /* attach LNB controller */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300996 fe = dvb_attach(isl6423_attach, adap->fe[0],
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300997 &d->i2c_adap, &anysee_isl6423_config);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300998 }
999
1000 break;
Antti Palosaari608add82011-08-12 18:29:46 -03001001
1002 case ANYSEE_HW_508T2C: /* 20 */
1003 /* E7 T2C */
1004
1005 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001006 fe = dvb_attach(tda18212_attach, adap->fe[0], &d->i2c_adap,
1007 &anysee_tda18212_config2);
Antti Palosaari608add82011-08-12 18:29:46 -03001008
1009 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -03001010 default:
Antti Palosaarie82eea72011-04-12 19:43:30 -03001011 fe = NULL;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001012 }
1013
Antti Palosaarie82eea72011-04-12 19:43:30 -03001014 if (fe)
1015 ret = 0;
1016 else
1017 ret = -ENODEV;
1018
Antti Palosaari41f81f62011-04-10 17:53:52 -03001019 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001020}
1021
Antti Palosaaria8494682010-10-17 18:25:10 -03001022static int anysee_rc_query(struct dvb_usb_device *d)
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001023{
1024 u8 buf[] = {CMD_GET_IR_CODE};
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001025 u8 ircode[2];
Antti Palosaaria8494682010-10-17 18:25:10 -03001026 int ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001027
Antti Palosaaria8494682010-10-17 18:25:10 -03001028 /* Remote controller is basic NEC using address byte 0x08.
1029 Anysee device RC query returns only two bytes, status and code,
1030 address byte is dropped. Also it does not return any value for
1031 NEC RCs having address byte other than 0x08. Due to that, we
1032 cannot use that device as standard NEC receiver.
1033 It could be possible make hack which reads whole code directly
1034 from device memory... */
1035
1036 ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode));
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001037 if (ret)
1038 return ret;
1039
Antti Palosaaria8494682010-10-17 18:25:10 -03001040 if (ircode[0]) {
Antti Palosaari82026f92012-08-14 15:56:20 -03001041 dev_dbg(&d->udev->dev, "%s: key pressed %02x\n", __func__,
1042 ircode[1]);
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -03001043 rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001044 }
Antti Palosaaria8494682010-10-17 18:25:10 -03001045
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001046 return 0;
1047}
1048
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001049static int anysee_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
1050{
1051 rc->allowed_protos = RC_TYPE_NEC;
1052 rc->query = anysee_rc_query;
1053 rc->interval = 250; /* windows driver uses 500ms */
1054
1055 return 0;
1056}
1057
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001058static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1059 int addr)
1060{
1061 struct dvb_usb_device *d = ci->data;
1062 int ret;
1063 u8 buf[] = {CMD_CI, 0x02, 0x40 | addr >> 8, addr & 0xff, 0x00, 1};
1064 u8 val;
1065
1066 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
1067 if (ret)
1068 return ret;
1069
1070 return val;
1071}
1072
1073static int anysee_ci_write_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1074 int addr, u8 val)
1075{
1076 struct dvb_usb_device *d = ci->data;
1077 int ret;
1078 u8 buf[] = {CMD_CI, 0x03, 0x40 | addr >> 8, addr & 0xff, 0x00, 1, val};
1079
1080 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
1081 if (ret)
1082 return ret;
1083
1084 return 0;
1085}
1086
1087static int anysee_ci_read_cam_control(struct dvb_ca_en50221 *ci, int slot,
1088 u8 addr)
1089{
1090 struct dvb_usb_device *d = ci->data;
1091 int ret;
1092 u8 buf[] = {CMD_CI, 0x04, 0x40, addr, 0x00, 1};
1093 u8 val;
1094
1095 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
1096 if (ret)
1097 return ret;
1098
1099 return val;
1100}
1101
1102static int anysee_ci_write_cam_control(struct dvb_ca_en50221 *ci, int slot,
1103 u8 addr, u8 val)
1104{
1105 struct dvb_usb_device *d = ci->data;
1106 int ret;
1107 u8 buf[] = {CMD_CI, 0x05, 0x40, addr, 0x00, 1, val};
1108
1109 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
1110 if (ret)
1111 return ret;
1112
1113 return 0;
1114}
1115
1116static int anysee_ci_slot_reset(struct dvb_ca_en50221 *ci, int slot)
1117{
1118 struct dvb_usb_device *d = ci->data;
1119 int ret;
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001120 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001121
1122 state->ci_cam_ready = jiffies + msecs_to_jiffies(1000);
1123
1124 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
1125 if (ret)
1126 return ret;
1127
1128 msleep(300);
1129
1130 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1131 if (ret)
1132 return ret;
1133
1134 return 0;
1135}
1136
1137static int anysee_ci_slot_shutdown(struct dvb_ca_en50221 *ci, int slot)
1138{
1139 struct dvb_usb_device *d = ci->data;
1140 int ret;
1141
1142 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
1143 if (ret)
1144 return ret;
1145
1146 msleep(30);
1147
1148 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1149 if (ret)
1150 return ret;
1151
1152 return 0;
1153}
1154
1155static int anysee_ci_slot_ts_enable(struct dvb_ca_en50221 *ci, int slot)
1156{
1157 struct dvb_usb_device *d = ci->data;
1158 int ret;
1159
1160 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 1), 0x02);
1161 if (ret)
1162 return ret;
1163
1164 return 0;
1165}
1166
1167static int anysee_ci_poll_slot_status(struct dvb_ca_en50221 *ci, int slot,
1168 int open)
1169{
1170 struct dvb_usb_device *d = ci->data;
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001171 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001172 int ret;
1173 u8 tmp;
1174
1175 ret = anysee_rd_reg_mask(d, REG_IOC, &tmp, 0x40);
1176 if (ret)
1177 return ret;
1178
1179 if (tmp == 0) {
1180 ret = DVB_CA_EN50221_POLL_CAM_PRESENT;
1181 if (time_after(jiffies, state->ci_cam_ready))
1182 ret |= DVB_CA_EN50221_POLL_CAM_READY;
1183 }
1184
1185 return ret;
1186}
1187
1188static int anysee_ci_init(struct dvb_usb_device *d)
1189{
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001190 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001191 int ret;
1192
1193 state->ci.owner = THIS_MODULE;
1194 state->ci.read_attribute_mem = anysee_ci_read_attribute_mem;
1195 state->ci.write_attribute_mem = anysee_ci_write_attribute_mem;
1196 state->ci.read_cam_control = anysee_ci_read_cam_control;
1197 state->ci.write_cam_control = anysee_ci_write_cam_control;
1198 state->ci.slot_reset = anysee_ci_slot_reset;
1199 state->ci.slot_shutdown = anysee_ci_slot_shutdown;
1200 state->ci.slot_ts_enable = anysee_ci_slot_ts_enable;
1201 state->ci.poll_slot_status = anysee_ci_poll_slot_status;
1202 state->ci.data = d;
1203
1204 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1205 if (ret)
1206 return ret;
1207
Antti Palosaari46de20a2012-01-20 17:39:17 -03001208 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 2)|(0 << 1)|(0 << 0), 0x07);
1209 if (ret)
1210 return ret;
1211
1212 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 2)|(1 << 1)|(1 << 0), 0x07);
1213 if (ret)
1214 return ret;
1215
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001216 ret = dvb_ca_en50221_init(&d->adapter[0].dvb_adap, &state->ci, 0, 1);
1217 if (ret)
1218 return ret;
1219
1220 return 0;
1221}
1222
1223static void anysee_ci_release(struct dvb_usb_device *d)
1224{
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001225 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001226
1227 /* detach CI */
1228 if (state->has_ci)
1229 dvb_ca_en50221_release(&state->ci);
1230
1231 return;
1232}
1233
1234static int anysee_init(struct dvb_usb_device *d)
1235{
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001236 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001237 int ret;
1238
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001239 /* There is one interface with two alternate settings.
1240 Alternate setting 0 is for bulk transfer.
1241 Alternate setting 1 is for isochronous transfer.
1242 We use bulk transfer (alternate setting 0). */
1243 ret = usb_set_interface(d->udev, 0, 0);
1244 if (ret)
1245 return ret;
1246
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001247 /* LED light */
1248 ret = anysee_led_ctrl(d, 0x01, 0x03);
1249 if (ret)
1250 return ret;
1251
1252 /* enable IR */
1253 ret = anysee_ir_ctrl(d, 1);
1254 if (ret)
1255 return ret;
1256
1257 /* attach CI */
1258 if (state->has_ci) {
1259 ret = anysee_ci_init(d);
1260 if (ret) {
1261 state->has_ci = false;
1262 return ret;
1263 }
1264 }
1265
1266 return 0;
1267}
1268
Antti Palosaari831511b2012-06-20 00:32:53 -03001269static void anysee_exit(struct dvb_usb_device *d)
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001270{
1271 return anysee_ci_release(d);
1272}
1273
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001274/* DVB USB Driver stuff */
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001275static struct dvb_usb_device_properties anysee_props = {
1276 .driver_name = KBUILD_MODNAME,
1277 .owner = THIS_MODULE,
1278 .adapter_nr = adapter_nr,
1279 .size_of_priv = sizeof(struct anysee_state),
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001280
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001281 .generic_bulk_ctrl_endpoint = 0x01,
1282 .generic_bulk_ctrl_endpoint_response = 0x81,
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001283
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001284 .i2c_algo = &anysee_i2c_algo,
1285 .read_config = anysee_read_config,
1286 .frontend_attach = anysee_frontend_attach,
1287 .tuner_attach = anysee_tuner_attach,
1288 .init = anysee_init,
1289 .get_rc_config = anysee_get_rc_config,
1290 .frontend_ctrl = anysee_frontend_ctrl,
1291 .streaming_ctrl = anysee_streaming_ctrl,
Antti Palosaari831511b2012-06-20 00:32:53 -03001292 .exit = anysee_exit,
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001293
1294 .num_adapters = 1,
1295 .adapter = {
1296 {
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001297 .stream = DVB_USB_STREAM_BULK(0x82, 8, 16 * 512),
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001298 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001299 }
1300};
1301
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001302static const struct usb_device_id anysee_id_table[] = {
1303 { DVB_USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE,
1304 &anysee_props, "Anysee", RC_MAP_ANYSEE) },
1305 { DVB_USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE,
1306 &anysee_props, "Anysee", RC_MAP_ANYSEE) },
1307 { }
1308};
1309MODULE_DEVICE_TABLE(usb, anysee_id_table);
1310
1311static struct usb_driver anysee_usb_driver = {
1312 .name = KBUILD_MODNAME,
1313 .id_table = anysee_id_table,
1314 .probe = dvb_usbv2_probe,
1315 .disconnect = dvb_usbv2_disconnect,
1316 .suspend = dvb_usbv2_suspend,
1317 .resume = dvb_usbv2_resume,
Antti Palosaari04966aa2012-08-14 22:21:08 -03001318 .reset_resume = dvb_usbv2_reset_resume,
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001319 .no_dynamic_id = 1,
1320 .soft_unbind = 1,
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001321};
1322
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001323module_usb_driver(anysee_usb_driver);
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001324
1325MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1326MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
1327MODULE_LICENSE("GPL");