blob: 85ba24650f0104b538c48bd5ad8387e1a53ccb7b [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);
Antti Palosaaria51e34d2008-05-17 23:05:48 -030048
49static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
50 u8 *rbuf, u8 rlen)
51{
Antti Palosaari05cd62e2012-06-18 19:39:02 -030052 struct anysee_state *state = d_to_priv(d);
Antti Palosaaricf427952012-01-21 11:19:29 -030053 int act_len, ret, i;
Antti Palosaaria51e34d2008-05-17 23:05:48 -030054
Antti Palosaari6c604e82013-02-26 14:13:41 -030055 mutex_lock(&d->usb_mutex);
Antti Palosaaria51e34d2008-05-17 23:05:48 -030056
Antti Palosaari6c604e82013-02-26 14:13:41 -030057 memcpy(&state->buf[0], sbuf, slen);
58 state->buf[60] = state->seq++;
Antti Palosaaria51e34d2008-05-17 23:05:48 -030059
Antti Palosaari6c604e82013-02-26 14:13:41 -030060 dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, slen, state->buf);
Antti Palosaari4048da22011-09-29 20:28:53 -030061
Antti Palosaaria51e34d2008-05-17 23:05:48 -030062 /* We need receive one message more after dvb_usb_generic_rw due
63 to weird transaction flow, which is 1 x send + 2 x receive. */
Antti Palosaari6c604e82013-02-26 14:13:41 -030064 ret = dvb_usbv2_generic_rw_locked(d, state->buf, sizeof(state->buf),
65 state->buf, sizeof(state->buf));
Antti Palosaaricf427952012-01-21 11:19:29 -030066 if (ret)
67 goto error_unlock;
68
69 /* TODO FIXME: dvb_usb_generic_rw() fails rarely with error code -32
70 * (EPIPE, Broken pipe). Function supports currently msleep() as a
71 * parameter but I would not like to use it, since according to
72 * Documentation/timers/timers-howto.txt it should not be used such
73 * short, under < 20ms, sleeps. Repeating failed message would be
74 * better choice as not to add unwanted delays...
75 * Fixing that correctly is one of those or both;
76 * 1) use repeat if possible
77 * 2) add suitable delay
78 */
79
80 /* get answer, retry few times if error returned */
81 for (i = 0; i < 3; i++) {
Antti Palosaaria51e34d2008-05-17 23:05:48 -030082 /* receive 2nd answer */
83 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
Antti Palosaari6c604e82013-02-26 14:13:41 -030084 d->props->generic_bulk_ctrl_endpoint),
85 state->buf, sizeof(state->buf), &act_len, 2000);
Antti Palosaaricf427952012-01-21 11:19:29 -030086 if (ret) {
Antti Palosaari82026f92012-08-14 15:56:20 -030087 dev_dbg(&d->udev->dev, "%s: recv bulk message " \
88 "failed=%d\n", __func__, ret);
Antti Palosaaricf427952012-01-21 11:19:29 -030089 } else {
Antti Palosaari82026f92012-08-14 15:56:20 -030090 dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__,
Antti Palosaari6c604e82013-02-26 14:13:41 -030091 rlen, state->buf);
Antti Palosaari4048da22011-09-29 20:28:53 -030092
Antti Palosaari6c604e82013-02-26 14:13:41 -030093 if (state->buf[63] != 0x4f)
Antti Palosaari82026f92012-08-14 15:56:20 -030094 dev_dbg(&d->udev->dev, "%s: cmd failed\n",
95 __func__);
Antti Palosaaricf427952012-01-21 11:19:29 -030096
97 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -030098 }
99 }
100
Antti Palosaaricf427952012-01-21 11:19:29 -0300101 if (ret) {
102 /* all retries failed, it is fatal */
Antti Palosaari82026f92012-08-14 15:56:20 -0300103 dev_err(&d->udev->dev, "%s: recv bulk message failed=%d\n",
104 KBUILD_MODNAME, ret);
Antti Palosaaricf427952012-01-21 11:19:29 -0300105 goto error_unlock;
106 }
107
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300108 /* read request, copy returned data to return buf */
Antti Palosaaricf427952012-01-21 11:19:29 -0300109 if (rbuf && rlen)
Antti Palosaari6c604e82013-02-26 14:13:41 -0300110 memcpy(rbuf, state->buf, rlen);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300111
Antti Palosaaricf427952012-01-21 11:19:29 -0300112error_unlock:
Antti Palosaari6c604e82013-02-26 14:13:41 -0300113 mutex_unlock(&d->usb_mutex);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300114 return ret;
115}
116
117static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
118{
119 u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};
120 int ret;
121 ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);
Antti Palosaari82026f92012-08-14 15:56:20 -0300122 dev_dbg(&d->udev->dev, "%s: reg=%04x val=%02x\n", __func__, reg, *val);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300123 return ret;
124}
125
126static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
127{
128 u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};
Antti Palosaari82026f92012-08-14 15:56:20 -0300129 dev_dbg(&d->udev->dev, "%s: reg=%04x val=%02x\n", __func__, reg, val);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300130 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
131}
132
Antti Palosaari41f81f62011-04-10 17:53:52 -0300133/* write single register with mask */
134static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
135 u8 mask)
136{
137 int ret;
138 u8 tmp;
139
140 /* no need for read if whole reg is written */
141 if (mask != 0xff) {
142 ret = anysee_read_reg(d, reg, &tmp);
143 if (ret)
144 return ret;
145
146 val &= mask;
147 tmp &= ~mask;
148 val |= tmp;
149 }
150
151 return anysee_write_reg(d, reg, val);
152}
153
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300154/* read single register with mask */
155static int anysee_rd_reg_mask(struct dvb_usb_device *d, u16 reg, u8 *val,
156 u8 mask)
157{
158 int ret, i;
159 u8 tmp;
160
161 ret = anysee_read_reg(d, reg, &tmp);
162 if (ret)
163 return ret;
164
165 tmp &= mask;
166
167 /* find position of the first bit */
168 for (i = 0; i < 8; i++) {
169 if ((mask >> i) & 0x01)
170 break;
171 }
172 *val = tmp >> i;
173
174 return 0;
175}
176
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300177static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
178{
179 u8 buf[] = {CMD_GET_HW_INFO};
180 return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);
181}
182
Antti Palosaaria13a6e12012-06-26 00:04:33 -0300183static int anysee_streaming_ctrl(struct dvb_frontend *fe, int onoff)
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300184{
185 u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};
Antti Palosaari82026f92012-08-14 15:56:20 -0300186 dev_dbg(&fe_to_d(fe)->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Antti Palosaaria13a6e12012-06-26 00:04:33 -0300187 return anysee_ctrl_msg(fe_to_d(fe), buf, sizeof(buf), NULL, 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300188}
189
190static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)
191{
192 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};
Antti Palosaari82026f92012-08-14 15:56:20 -0300193 dev_dbg(&d->udev->dev, "%s: state=%d interval=%d\n", __func__,
194 mode, interval);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300195 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
196}
197
198static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
199{
200 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};
Antti Palosaari82026f92012-08-14 15:56:20 -0300201 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300202 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
203}
204
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300205/* I2C */
206static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
207 int num)
208{
209 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Mauro Carvalho Chehab902571a2008-12-29 19:02:24 -0300210 int ret = 0, inc, i = 0;
Antti Palosaari21d2e932011-05-24 06:04:08 -0300211 u8 buf[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300212
213 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
214 return -EAGAIN;
215
216 while (i < num) {
217 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
Antti Palosaari21d2e932011-05-24 06:04:08 -0300218 if (msg[i].len > 2 || msg[i+1].len > 60) {
219 ret = -EOPNOTSUPP;
220 break;
221 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300222 buf[0] = CMD_I2C_READ;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300223 buf[1] = (msg[i].addr << 1) | 0x01;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300224 buf[2] = msg[i].buf[0];
Antti Palosaari882b82c2011-04-12 19:49:25 -0300225 buf[3] = msg[i].buf[1];
226 buf[4] = msg[i].len-1;
Antti Palosaarib3e6a5a2011-04-09 21:00:51 -0300227 buf[5] = msg[i+1].len;
Antti Palosaari21d2e932011-05-24 06:04:08 -0300228 ret = anysee_ctrl_msg(d, buf, 6, msg[i+1].buf,
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300229 msg[i+1].len);
230 inc = 2;
231 } else {
Antti Palosaari21d2e932011-05-24 06:04:08 -0300232 if (msg[i].len > 48) {
233 ret = -EOPNOTSUPP;
234 break;
235 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300236 buf[0] = CMD_I2C_WRITE;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300237 buf[1] = (msg[i].addr << 1);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300238 buf[2] = msg[i].len;
239 buf[3] = 0x01;
240 memcpy(&buf[4], msg[i].buf, msg[i].len);
Antti Palosaari21d2e932011-05-24 06:04:08 -0300241 ret = anysee_ctrl_msg(d, buf, 4 + msg[i].len, NULL, 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300242 inc = 1;
243 }
244 if (ret)
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300245 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300246
247 i += inc;
248 }
249
250 mutex_unlock(&d->i2c_mutex);
251
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300252 return ret ? ret : i;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300253}
254
255static u32 anysee_i2c_func(struct i2c_adapter *adapter)
256{
257 return I2C_FUNC_I2C;
258}
259
260static struct i2c_algorithm anysee_i2c_algo = {
261 .master_xfer = anysee_master_xfer,
262 .functionality = anysee_i2c_func,
263};
264
265static int anysee_mt352_demod_init(struct dvb_frontend *fe)
266{
Antti Palosaariae3745f2009-09-16 19:50:25 -0300267 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
268 static u8 reset[] = { RESET, 0x80 };
269 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
270 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
271 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300272 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
273
274 mt352_write(fe, clock_config, sizeof(clock_config));
275 udelay(200);
276 mt352_write(fe, reset, sizeof(reset));
277 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
278
279 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
280 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
281 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
282
283 return 0;
284}
285
286/* Callbacks for DVB USB */
287static struct tda10023_config anysee_tda10023_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300288 .demod_address = (0x1a >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300289 .invert = 0,
290 .xtal = 16000000,
291 .pll_m = 11,
292 .pll_p = 3,
293 .pll_n = 1,
Antti Palosaari5ae2fca2008-06-09 22:58:22 -0300294 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
295 .deltaf = 0xfeeb,
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300296};
297
298static struct mt352_config anysee_mt352_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300299 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300300 .demod_init = anysee_mt352_demod_init,
301};
302
303static struct zl10353_config anysee_zl10353_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300304 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300305 .parallel_ts = 1,
306};
307
Antti Palosaari1fd80702011-04-12 17:34:08 -0300308static struct zl10353_config anysee_zl10353_tda18212_config2 = {
309 .demod_address = (0x1e >> 1),
310 .parallel_ts = 1,
311 .disable_i2c_gate_ctrl = 1,
312 .no_tuner = 1,
313 .if2 = 41500,
314};
315
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300316static struct zl10353_config anysee_zl10353_tda18212_config = {
317 .demod_address = (0x18 >> 1),
318 .parallel_ts = 1,
319 .disable_i2c_gate_ctrl = 1,
320 .no_tuner = 1,
321 .if2 = 41500,
322};
323
324static struct tda10023_config anysee_tda10023_tda18212_config = {
325 .demod_address = (0x1a >> 1),
326 .xtal = 16000000,
327 .pll_m = 12,
328 .pll_p = 3,
329 .pll_n = 1,
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300330 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_B,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300331 .deltaf = 0xba02,
332};
333
334static struct tda18212_config anysee_tda18212_config = {
335 .i2c_address = (0xc0 >> 1),
336 .if_dvbt_6 = 4150,
337 .if_dvbt_7 = 4150,
338 .if_dvbt_8 = 4150,
339 .if_dvbc = 5000,
340};
341
Antti Palosaari608add82011-08-12 18:29:46 -0300342static struct tda18212_config anysee_tda18212_config2 = {
343 .i2c_address = 0x60 /* (0xc0 >> 1) */,
344 .if_dvbt_6 = 3550,
345 .if_dvbt_7 = 3700,
346 .if_dvbt_8 = 4150,
347 .if_dvbt2_6 = 3250,
348 .if_dvbt2_7 = 4000,
349 .if_dvbt2_8 = 4000,
350 .if_dvbc = 5000,
351};
352
Antti Palosaarif0a53102011-04-27 21:11:59 -0300353static struct cx24116_config anysee_cx24116_config = {
354 .demod_address = (0xaa >> 1),
355 .mpg_clk_pos_pol = 0x00,
356 .i2c_wr_max = 48,
357};
358
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300359static struct stv0900_config anysee_stv0900_config = {
360 .demod_address = (0xd0 >> 1),
361 .demod_mode = 0,
362 .xtal = 8000000,
363 .clkmode = 3,
364 .diseqc_mode = 2,
365 .tun1_maddress = 0,
366 .tun1_adc = 1, /* 1 Vpp */
367 .path1_mode = 3,
368};
369
370static struct stv6110_config anysee_stv6110_config = {
371 .i2c_address = (0xc0 >> 1),
372 .mclk = 16000000,
373 .clk_div = 1,
374};
375
Antti Palosaarif0a53102011-04-27 21:11:59 -0300376static struct isl6423_config anysee_isl6423_config = {
377 .current_max = SEC_CURRENT_800m,
378 .curlim = SEC_CURRENT_LIM_OFF,
379 .mod_extern = 1,
380 .addr = (0x10 >> 1),
381};
382
Antti Palosaari608add82011-08-12 18:29:46 -0300383static struct cxd2820r_config anysee_cxd2820r_config = {
384 .i2c_address = 0x6d, /* (0xda >> 1) */
385 .ts_mode = 0x38,
Antti Palosaari608add82011-08-12 18:29:46 -0300386};
387
Antti Palosaari41f81f62011-04-10 17:53:52 -0300388/*
389 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
390 * Manufacturer: AMT.CO.KR
391 *
392 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
393 * PCB: ?
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300394 * parts: DNOS404ZH102A(MT352, DTT7579(?))
Antti Palosaari41f81f62011-04-10 17:53:52 -0300395 *
Antti Palosaari05c46c02011-05-25 18:30:09 -0300396 * E30 VID=04b4 PID=861f HW=2 FW=2.1 "anysee-T(LP)"
397 * PCB: PCB 507T (rev1.61)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300398 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
Antti Palosaari05c46c02011-05-25 18:30:09 -0300399 * OEA=0a OEB=00 OEC=00 OED=ff OEE=00
400 * IOA=45 IOB=ff IOC=00 IOD=ff IOE=00
Antti Palosaari41f81f62011-04-10 17:53:52 -0300401 *
402 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
403 * PCB: 507CD (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300404 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
Antti Palosaari05c46c02011-05-25 18:30:09 -0300405 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
406 * IOA=4f IOB=ff IOC=00 IOD=06 IOE=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300407 * IOD[0] ZL10353 1=enabled
408 * IOA[7] TS 0=enabled
409 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
410 *
411 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
412 * PCB: 507DC (rev0.2)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300413 * parts: TDA10023, DTOS403IH102B TM, CST56I01
Antti Palosaari05c46c02011-05-25 18:30:09 -0300414 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
415 * IOA=4f IOB=ff IOC=00 IOD=26 IOE=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300416 * IOD[0] TDA10023 1=enabled
417 *
Antti Palosaarif0a53102011-04-27 21:11:59 -0300418 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
419 * PCB: 507SI (rev2.1)
420 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300421 * OEA=80 OEB=00 OEC=ff OED=ff OEE=fe
422 * IOA=4d IOB=ff IOC=00 IOD=26 IOE=01
Antti Palosaarif0a53102011-04-27 21:11:59 -0300423 * IOD[0] CX24116 1=enabled
424 *
Antti Palosaari41f81f62011-04-10 17:53:52 -0300425 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
426 * PCB: 507FA (rev0.4)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300427 * parts: TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300428 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
429 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300430 * IOD[5] TDA10023 1=enabled
431 * IOE[0] tuner 1=enabled
432 *
433 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
434 * PCB: 507FA (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300435 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300436 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
437 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300438 * DVB-C:
439 * IOD[5] TDA10023 1=enabled
440 * IOE[0] tuner 1=enabled
441 * DVB-T:
442 * IOD[0] ZL10353 1=enabled
443 * IOE[0] tuner 0=enabled
444 * tuner is behind ZL10353 I2C-gate
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300445 *
446 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
447 * PCB: 508TC (rev0.6)
448 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
Antti Palosaari05c46c02011-05-25 18:30:09 -0300449 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
450 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300451 * IOA[7] TS 1=enabled
452 * IOE[4] TDA18212 1=enabled
453 * DVB-C:
454 * IOD[6] ZL10353 0=disabled
455 * IOD[5] TDA10023 1=enabled
456 * IOE[0] IF 1=enabled
457 * DVB-T:
458 * IOD[5] TDA10023 0=disabled
459 * IOD[6] ZL10353 1=enabled
460 * IOE[0] IF 0=enabled
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300461 *
462 * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
463 * PCB: 508S2 (rev0.7)
464 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
Antti Palosaari05c46c02011-05-25 18:30:09 -0300465 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
466 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300467 * IOA[7] TS 1=enabled
468 * IOE[5] STV0903 1=enabled
469 *
Antti Palosaari608add82011-08-12 18:29:46 -0300470 * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)"
471 * PCB: 508T2C (rev0.3)
472 * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024
473 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
474 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
475 * IOA[7] TS 1=enabled
476 * IOE[5] CXD2820R 1=enabled
477 *
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300478 * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)"
479 * PCB: 508PTC (rev0.5)
480 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
481 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
482 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
483 * IOA[7] TS 1=enabled
484 * IOE[4] TDA18212 1=enabled
485 * DVB-C:
486 * IOD[6] ZL10353 0=disabled
487 * IOD[5] TDA10023 1=enabled
488 * IOE[0] IF 1=enabled
489 * DVB-T:
490 * IOD[5] TDA10023 0=disabled
491 * IOD[6] ZL10353 1=enabled
492 * IOE[0] IF 0=enabled
Antti Palosaarifea3c392011-05-25 18:21:43 -0300493 *
Antti Palosaari608add82011-08-12 18:29:46 -0300494 * E7 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)"
Antti Palosaarifea3c392011-05-25 18:21:43 -0300495 * PCB: 508PS2 (rev0.4)
496 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
497 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
498 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
499 * IOA[7] TS 1=enabled
500 * IOE[5] STV0903 1=enabled
Antti Palosaari41f81f62011-04-10 17:53:52 -0300501 */
502
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300503static int anysee_read_config(struct dvb_usb_device *d)
504{
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300505 struct anysee_state *state = d_to_priv(d);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300506 int ret;
507 u8 hw_info[3];
508
509 /*
510 * Check which hardware we have.
511 * We must do this call two times to get reliable values (hw/fw bug).
512 */
513 ret = anysee_get_hw_info(d, hw_info);
514 if (ret)
515 goto error;
516
517 ret = anysee_get_hw_info(d, hw_info);
518 if (ret)
519 goto error;
520
Antti Palosaari82026f92012-08-14 15:56:20 -0300521 /*
522 * Meaning of these info bytes are guessed.
523 */
524 dev_info(&d->udev->dev, "%s: firmware version %d.%d hardware id %d\n",
525 KBUILD_MODNAME, hw_info[1], hw_info[2], hw_info[0]);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300526
527 state->hw = hw_info[0];
528error:
529 return ret;
530}
Antti Palosaaribe943512011-09-05 22:10:05 -0300531
532/* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */
533static int anysee_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
534{
Antti Palosaaribe943512011-09-05 22:10:05 -0300535 /* enable / disable tuner access on IOE[4] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300536 return anysee_wr_reg_mask(fe_to_d(fe), REG_IOE, (enable << 4), 0x10);
Antti Palosaaribe943512011-09-05 22:10:05 -0300537}
538
Antti Palosaari449d1a02011-07-25 20:25:21 -0300539static int anysee_frontend_ctrl(struct dvb_frontend *fe, int onoff)
540{
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300541 struct anysee_state *state = fe_to_priv(fe);
542 struct dvb_usb_device *d = fe_to_d(fe);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300543 int ret;
Antti Palosaari82026f92012-08-14 15:56:20 -0300544 dev_dbg(&d->udev->dev, "%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300545
546 /* no frontend sleep control */
547 if (onoff == 0)
548 return 0;
549
550 switch (state->hw) {
551 case ANYSEE_HW_507FA: /* 15 */
552 /* E30 Combo Plus */
553 /* E30 C Plus */
554
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300555 if (fe->id == 0) {
Antti Palosaari449d1a02011-07-25 20:25:21 -0300556 /* disable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300557 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300558 if (ret)
559 goto error;
560
561 /* enable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300562 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300563 if (ret)
564 goto error;
565
566 /* enable DVB-C tuner on IOE[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300567 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300568 if (ret)
569 goto error;
570 } else {
571 /* disable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300572 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300573 if (ret)
574 goto error;
575
576 /* enable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300577 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300578 if (ret)
579 goto error;
580
581 /* enable DVB-T tuner on IOE[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300582 ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300583 if (ret)
584 goto error;
585 }
586
587 break;
588 case ANYSEE_HW_508TC: /* 18 */
589 case ANYSEE_HW_508PTC: /* 21 */
590 /* E7 TC */
591 /* E7 PTC */
592
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300593 if (fe->id == 0) {
Antti Palosaari449d1a02011-07-25 20:25:21 -0300594 /* disable DVB-T demod on IOD[6] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300595 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 6), 0x40);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300596 if (ret)
597 goto error;
598
599 /* enable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300600 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300601 if (ret)
602 goto error;
603
604 /* enable IF route on IOE[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300605 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300606 if (ret)
607 goto error;
608 } else {
609 /* disable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300610 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300611 if (ret)
612 goto error;
613
614 /* enable DVB-T demod on IOD[6] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300615 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 6), 0x40);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300616 if (ret)
617 goto error;
618
619 /* enable IF route on IOE[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300620 ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300621 if (ret)
622 goto error;
623 }
624
625 break;
626 default:
627 ret = 0;
628 }
629
630error:
631 return ret;
632}
633
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300634static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
635{
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300636 struct anysee_state *state = adap_to_priv(adap);
637 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300638 int ret;
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300639 u8 tmp;
640 struct i2c_msg msg[2] = {
641 {
642 .addr = anysee_tda18212_config.i2c_address,
643 .flags = 0,
644 .len = 1,
645 .buf = "\x00",
646 }, {
647 .addr = anysee_tda18212_config.i2c_address,
648 .flags = I2C_M_RD,
649 .len = 1,
650 .buf = &tmp,
651 }
652 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300653
Antti Palosaari41f81f62011-04-10 17:53:52 -0300654 switch (state->hw) {
Antti Palosaari05c46c02011-05-25 18:30:09 -0300655 case ANYSEE_HW_507T: /* 2 */
Antti Palosaari41f81f62011-04-10 17:53:52 -0300656 /* E30 */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300657
Antti Palosaari41f81f62011-04-10 17:53:52 -0300658 /* attach demod */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300659 adap->fe[0] = dvb_attach(mt352_attach, &anysee_mt352_config,
660 &d->i2c_adap);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300661 if (adap->fe[0])
Antti Palosaari41f81f62011-04-10 17:53:52 -0300662 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300663
Antti Palosaari41f81f62011-04-10 17:53:52 -0300664 /* attach demod */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300665 adap->fe[0] = dvb_attach(zl10353_attach, &anysee_zl10353_config,
666 &d->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300667
668 break;
669 case ANYSEE_HW_507CD: /* 6 */
670 /* E30 Plus */
671
672 /* enable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300673 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300674 if (ret)
675 goto error;
676
677 /* enable transport stream on IOA[7] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300678 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300679 if (ret)
680 goto error;
681
682 /* attach demod */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300683 adap->fe[0] = dvb_attach(zl10353_attach, &anysee_zl10353_config,
684 &d->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300685
686 break;
687 case ANYSEE_HW_507DC: /* 10 */
688 /* E30 C Plus */
689
690 /* enable DVB-C demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300691 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300692 if (ret)
693 goto error;
694
695 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300696 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300697 &anysee_tda10023_config, &d->i2c_adap, 0x48);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300698
699 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300700 case ANYSEE_HW_507SI: /* 11 */
701 /* E30 S2 Plus */
702
703 /* enable DVB-S/S2 demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300704 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaarif0a53102011-04-27 21:11:59 -0300705 if (ret)
706 goto error;
707
708 /* attach demod */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300709 adap->fe[0] = dvb_attach(cx24116_attach, &anysee_cx24116_config,
710 &d->i2c_adap);
Antti Palosaarif0a53102011-04-27 21:11:59 -0300711
712 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300713 case ANYSEE_HW_507FA: /* 15 */
714 /* E30 Combo Plus */
715 /* E30 C Plus */
716
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300717 /* enable tuner on IOE[4] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300718 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 4), 0x10);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300719 if (ret)
720 goto error;
721
722 /* probe TDA18212 */
723 tmp = 0;
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300724 ret = i2c_transfer(&d->i2c_adap, msg, 2);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300725 if (ret == 2 && tmp == 0xc7)
Antti Palosaari82026f92012-08-14 15:56:20 -0300726 dev_dbg(&d->udev->dev, "%s: TDA18212 found\n",
727 __func__);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300728 else
729 tmp = 0;
730
731 /* disable tuner on IOE[4] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300732 ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 4), 0x10);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300733 if (ret)
734 goto error;
735
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300736 /* disable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300737 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 0), 0x01);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300738 if (ret)
739 goto error;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300740
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300741 /* enable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300742 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300743 if (ret)
744 goto error;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300745
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300746 /* attach demod */
747 if (tmp == 0xc7) {
748 /* TDA18212 config */
749 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300750 &anysee_tda10023_tda18212_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300751 &d->i2c_adap, 0x48);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300752
753 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
754 if (adap->fe[0])
755 adap->fe[0]->ops.i2c_gate_ctrl =
756 anysee_i2c_gate_ctrl;
757 } else {
758 /* PLL config */
759 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300760 &anysee_tda10023_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300761 &d->i2c_adap, 0x48);
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300762 }
Antti Palosaarie82eea72011-04-12 19:43:30 -0300763
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300764 /* break out if first frontend attaching fails */
765 if (!adap->fe[0])
766 break;
767
768 /* disable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300769 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300770 if (ret)
771 goto error;
772
773 /* enable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300774 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300775 if (ret)
776 goto error;
777
778 /* attach demod */
Antti Palosaaribe943512011-09-05 22:10:05 -0300779 if (tmp == 0xc7) {
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300780 /* TDA18212 config */
781 adap->fe[1] = dvb_attach(zl10353_attach,
782 &anysee_zl10353_tda18212_config2,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300783 &d->i2c_adap);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300784
785 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
786 if (adap->fe[1])
787 adap->fe[1]->ops.i2c_gate_ctrl =
788 anysee_i2c_gate_ctrl;
789 } else {
790 /* PLL config */
791 adap->fe[1] = dvb_attach(zl10353_attach,
792 &anysee_zl10353_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300793 &d->i2c_adap);
Antti Palosaaribe943512011-09-05 22:10:05 -0300794 }
795
Antti Palosaari41f81f62011-04-10 17:53:52 -0300796 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300797 case ANYSEE_HW_508TC: /* 18 */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300798 case ANYSEE_HW_508PTC: /* 21 */
Antti Palosaaria43be982011-04-10 20:23:02 -0300799 /* E7 TC */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300800 /* E7 PTC */
Antti Palosaaria43be982011-04-10 20:23:02 -0300801
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300802 /* disable DVB-T demod on IOD[6] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300803 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 6), 0x40);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300804 if (ret)
805 goto error;
Antti Palosaaria43be982011-04-10 20:23:02 -0300806
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300807 /* enable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300808 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300809 if (ret)
810 goto error;
Antti Palosaaria43be982011-04-10 20:23:02 -0300811
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300812 /* attach demod */
813 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300814 &anysee_tda10023_tda18212_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300815 &d->i2c_adap, 0x48);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300816
Antti Palosaaribe943512011-09-05 22:10:05 -0300817 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300818 if (adap->fe[0])
819 adap->fe[0]->ops.i2c_gate_ctrl = anysee_i2c_gate_ctrl;
820
821 /* break out if first frontend attaching fails */
822 if (!adap->fe[0])
823 break;
824
825 /* disable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300826 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300827 if (ret)
828 goto error;
829
830 /* enable DVB-T demod on IOD[6] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300831 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 6), 0x40);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300832 if (ret)
833 goto error;
834
835 /* attach demod */
836 adap->fe[1] = dvb_attach(zl10353_attach,
837 &anysee_zl10353_tda18212_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300838 &d->i2c_adap);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300839
840 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
841 if (adap->fe[1])
842 adap->fe[1]->ops.i2c_gate_ctrl = anysee_i2c_gate_ctrl;
Antti Palosaaribe943512011-09-05 22:10:05 -0300843
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300844 state->has_ci = true;
845
Antti Palosaaria43be982011-04-10 20:23:02 -0300846 break;
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300847 case ANYSEE_HW_508S2: /* 19 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300848 case ANYSEE_HW_508PS2: /* 22 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300849 /* E7 S2 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300850 /* E7 PS2 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300851
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300852 /* enable DVB-S/S2 demod on IOE[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300853 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 5), 0x20);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300854 if (ret)
855 goto error;
856
857 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300858 adap->fe[0] = dvb_attach(stv0900_attach,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300859 &anysee_stv0900_config, &d->i2c_adap, 0);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300860
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300861 state->has_ci = true;
862
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300863 break;
Antti Palosaari608add82011-08-12 18:29:46 -0300864 case ANYSEE_HW_508T2C: /* 20 */
865 /* E7 T2C */
866
Antti Palosaari608add82011-08-12 18:29:46 -0300867 /* enable DVB-T/T2/C demod on IOE[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300868 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 5), 0x20);
Antti Palosaari608add82011-08-12 18:29:46 -0300869 if (ret)
870 goto error;
871
Antti Palosaarifaf27972012-01-15 14:20:50 -0300872 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300873 adap->fe[0] = dvb_attach(cxd2820r_attach,
Antti Palosaari1e8f31f2012-07-19 21:10:36 -0300874 &anysee_cxd2820r_config, &d->i2c_adap, NULL);
Antti Palosaari608add82011-08-12 18:29:46 -0300875
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300876 state->has_ci = true;
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300877
878 break;
879 }
880
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300881 if (!adap->fe[0]) {
Antti Palosaari41f81f62011-04-10 17:53:52 -0300882 /* we have no frontend :-( */
883 ret = -ENODEV;
Antti Palosaari82026f92012-08-14 15:56:20 -0300884 dev_err(&d->udev->dev, "%s: Unsupported Anysee version. " \
885 "Please report the " \
886 "<linux-media@vger.kernel.org>.\n",
887 KBUILD_MODNAME);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300888 }
Antti Palosaari41f81f62011-04-10 17:53:52 -0300889error:
890 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300891}
892
893static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
894{
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300895 struct anysee_state *state = adap_to_priv(adap);
896 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300897 struct dvb_frontend *fe;
Antti Palosaarie82eea72011-04-12 19:43:30 -0300898 int ret;
Antti Palosaari82026f92012-08-14 15:56:20 -0300899 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300900
Antti Palosaari41f81f62011-04-10 17:53:52 -0300901 switch (state->hw) {
Antti Palosaari05c46c02011-05-25 18:30:09 -0300902 case ANYSEE_HW_507T: /* 2 */
Antti Palosaari41f81f62011-04-10 17:53:52 -0300903 /* E30 */
904
905 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300906 fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc2 >> 1), NULL,
907 DVB_PLL_THOMSON_DTT7579);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300908
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300909 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300910 case ANYSEE_HW_507CD: /* 6 */
911 /* E30 Plus */
912
913 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300914 fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc2 >> 1),
915 &d->i2c_adap, DVB_PLL_THOMSON_DTT7579);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300916
917 break;
918 case ANYSEE_HW_507DC: /* 10 */
919 /* E30 C Plus */
920
921 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300922 fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc0 >> 1),
923 &d->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300924
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300925 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300926 case ANYSEE_HW_507SI: /* 11 */
927 /* E30 S2 Plus */
928
929 /* attach LNB controller */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300930 fe = dvb_attach(isl6423_attach, adap->fe[0], &d->i2c_adap,
931 &anysee_isl6423_config);
Antti Palosaarif0a53102011-04-27 21:11:59 -0300932
933 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300934 case ANYSEE_HW_507FA: /* 15 */
935 /* E30 Combo Plus */
936 /* E30 C Plus */
937
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300938 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
939 * fails attach old simple PLL. */
940
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300941 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300942 fe = dvb_attach(tda18212_attach, adap->fe[0], &d->i2c_adap,
943 &anysee_tda18212_config);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300944
945 if (fe && adap->fe[1]) {
946 /* attach tuner for 2nd FE */
947 fe = dvb_attach(tda18212_attach, adap->fe[1],
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300948 &d->i2c_adap, &anysee_tda18212_config);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300949 break;
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300950 } else if (fe) {
951 break;
952 }
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300953
Antti Palosaari41f81f62011-04-10 17:53:52 -0300954 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300955 fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc0 >> 1),
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300956 &d->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300957
958 if (fe && adap->fe[1]) {
959 /* attach tuner for 2nd FE */
960 fe = dvb_attach(dvb_pll_attach, adap->fe[0],
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300961 (0xc0 >> 1), &d->i2c_adap,
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300962 DVB_PLL_SAMSUNG_DTOS403IH102A);
963 }
Antti Palosaari41f81f62011-04-10 17:53:52 -0300964
965 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300966 case ANYSEE_HW_508TC: /* 18 */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300967 case ANYSEE_HW_508PTC: /* 21 */
Antti Palosaaria43be982011-04-10 20:23:02 -0300968 /* E7 TC */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300969 /* E7 PTC */
Antti Palosaaria43be982011-04-10 20:23:02 -0300970
Antti Palosaaria43be982011-04-10 20:23:02 -0300971 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300972 fe = dvb_attach(tda18212_attach, adap->fe[0], &d->i2c_adap,
973 &anysee_tda18212_config);
Antti Palosaaria43be982011-04-10 20:23:02 -0300974
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300975 if (fe) {
976 /* attach tuner for 2nd FE */
977 fe = dvb_attach(tda18212_attach, adap->fe[1],
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300978 &d->i2c_adap, &anysee_tda18212_config);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300979 }
980
Antti Palosaaria43be982011-04-10 20:23:02 -0300981 break;
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300982 case ANYSEE_HW_508S2: /* 19 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300983 case ANYSEE_HW_508PS2: /* 22 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300984 /* E7 S2 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300985 /* E7 PS2 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300986
987 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300988 fe = dvb_attach(stv6110_attach, adap->fe[0],
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300989 &anysee_stv6110_config, &d->i2c_adap);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300990
991 if (fe) {
992 /* attach LNB controller */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300993 fe = dvb_attach(isl6423_attach, adap->fe[0],
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300994 &d->i2c_adap, &anysee_isl6423_config);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300995 }
996
997 break;
Antti Palosaari608add82011-08-12 18:29:46 -0300998
999 case ANYSEE_HW_508T2C: /* 20 */
1000 /* E7 T2C */
1001
1002 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001003 fe = dvb_attach(tda18212_attach, adap->fe[0], &d->i2c_adap,
1004 &anysee_tda18212_config2);
Antti Palosaari608add82011-08-12 18:29:46 -03001005
1006 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -03001007 default:
Antti Palosaarie82eea72011-04-12 19:43:30 -03001008 fe = NULL;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001009 }
1010
Antti Palosaarie82eea72011-04-12 19:43:30 -03001011 if (fe)
1012 ret = 0;
1013 else
1014 ret = -ENODEV;
1015
Antti Palosaari41f81f62011-04-10 17:53:52 -03001016 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001017}
1018
Antti Palosaari37b44a02013-01-04 15:21:26 -03001019#if IS_ENABLED(CONFIG_RC_CORE)
Antti Palosaaria8494682010-10-17 18:25:10 -03001020static int anysee_rc_query(struct dvb_usb_device *d)
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001021{
1022 u8 buf[] = {CMD_GET_IR_CODE};
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001023 u8 ircode[2];
Antti Palosaaria8494682010-10-17 18:25:10 -03001024 int ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001025
Antti Palosaaria8494682010-10-17 18:25:10 -03001026 /* Remote controller is basic NEC using address byte 0x08.
1027 Anysee device RC query returns only two bytes, status and code,
1028 address byte is dropped. Also it does not return any value for
1029 NEC RCs having address byte other than 0x08. Due to that, we
1030 cannot use that device as standard NEC receiver.
1031 It could be possible make hack which reads whole code directly
1032 from device memory... */
1033
1034 ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode));
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001035 if (ret)
1036 return ret;
1037
Antti Palosaaria8494682010-10-17 18:25:10 -03001038 if (ircode[0]) {
Antti Palosaari82026f92012-08-14 15:56:20 -03001039 dev_dbg(&d->udev->dev, "%s: key pressed %02x\n", __func__,
1040 ircode[1]);
Mauro Carvalho Chehabca866742010-11-17 13:53:11 -03001041 rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001042 }
Antti Palosaaria8494682010-10-17 18:25:10 -03001043
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001044 return 0;
1045}
1046
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001047static int anysee_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
1048{
David Härdemanc003ab12012-10-11 19:11:54 -03001049 rc->allowed_protos = RC_BIT_NEC;
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001050 rc->query = anysee_rc_query;
1051 rc->interval = 250; /* windows driver uses 500ms */
1052
1053 return 0;
1054}
Antti Palosaarid5c62092012-12-09 20:12:07 -03001055#else
1056 #define anysee_get_rc_config NULL
1057#endif
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001058
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001059static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1060 int addr)
1061{
1062 struct dvb_usb_device *d = ci->data;
1063 int ret;
1064 u8 buf[] = {CMD_CI, 0x02, 0x40 | addr >> 8, addr & 0xff, 0x00, 1};
1065 u8 val;
1066
1067 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
1068 if (ret)
1069 return ret;
1070
1071 return val;
1072}
1073
1074static int anysee_ci_write_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1075 int addr, u8 val)
1076{
1077 struct dvb_usb_device *d = ci->data;
1078 int ret;
1079 u8 buf[] = {CMD_CI, 0x03, 0x40 | addr >> 8, addr & 0xff, 0x00, 1, val};
1080
1081 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
1082 if (ret)
1083 return ret;
1084
1085 return 0;
1086}
1087
1088static int anysee_ci_read_cam_control(struct dvb_ca_en50221 *ci, int slot,
1089 u8 addr)
1090{
1091 struct dvb_usb_device *d = ci->data;
1092 int ret;
1093 u8 buf[] = {CMD_CI, 0x04, 0x40, addr, 0x00, 1};
1094 u8 val;
1095
1096 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
1097 if (ret)
1098 return ret;
1099
1100 return val;
1101}
1102
1103static int anysee_ci_write_cam_control(struct dvb_ca_en50221 *ci, int slot,
1104 u8 addr, u8 val)
1105{
1106 struct dvb_usb_device *d = ci->data;
1107 int ret;
1108 u8 buf[] = {CMD_CI, 0x05, 0x40, addr, 0x00, 1, val};
1109
1110 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
1111 if (ret)
1112 return ret;
1113
1114 return 0;
1115}
1116
1117static int anysee_ci_slot_reset(struct dvb_ca_en50221 *ci, int slot)
1118{
1119 struct dvb_usb_device *d = ci->data;
1120 int ret;
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001121 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001122
1123 state->ci_cam_ready = jiffies + msecs_to_jiffies(1000);
1124
1125 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
1126 if (ret)
1127 return ret;
1128
1129 msleep(300);
1130
1131 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1132 if (ret)
1133 return ret;
1134
1135 return 0;
1136}
1137
1138static int anysee_ci_slot_shutdown(struct dvb_ca_en50221 *ci, int slot)
1139{
1140 struct dvb_usb_device *d = ci->data;
1141 int ret;
1142
1143 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
1144 if (ret)
1145 return ret;
1146
1147 msleep(30);
1148
1149 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1150 if (ret)
1151 return ret;
1152
1153 return 0;
1154}
1155
1156static int anysee_ci_slot_ts_enable(struct dvb_ca_en50221 *ci, int slot)
1157{
1158 struct dvb_usb_device *d = ci->data;
1159 int ret;
1160
1161 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 1), 0x02);
1162 if (ret)
1163 return ret;
1164
1165 return 0;
1166}
1167
1168static int anysee_ci_poll_slot_status(struct dvb_ca_en50221 *ci, int slot,
1169 int open)
1170{
1171 struct dvb_usb_device *d = ci->data;
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001172 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001173 int ret;
Mauro Carvalho Chehab03ad9fe2012-10-27 16:28:00 -03001174 u8 tmp = 0;
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001175
1176 ret = anysee_rd_reg_mask(d, REG_IOC, &tmp, 0x40);
1177 if (ret)
1178 return ret;
1179
1180 if (tmp == 0) {
1181 ret = DVB_CA_EN50221_POLL_CAM_PRESENT;
1182 if (time_after(jiffies, state->ci_cam_ready))
1183 ret |= DVB_CA_EN50221_POLL_CAM_READY;
1184 }
1185
1186 return ret;
1187}
1188
1189static int anysee_ci_init(struct dvb_usb_device *d)
1190{
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001191 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001192 int ret;
1193
1194 state->ci.owner = THIS_MODULE;
1195 state->ci.read_attribute_mem = anysee_ci_read_attribute_mem;
1196 state->ci.write_attribute_mem = anysee_ci_write_attribute_mem;
1197 state->ci.read_cam_control = anysee_ci_read_cam_control;
1198 state->ci.write_cam_control = anysee_ci_write_cam_control;
1199 state->ci.slot_reset = anysee_ci_slot_reset;
1200 state->ci.slot_shutdown = anysee_ci_slot_shutdown;
1201 state->ci.slot_ts_enable = anysee_ci_slot_ts_enable;
1202 state->ci.poll_slot_status = anysee_ci_poll_slot_status;
1203 state->ci.data = d;
1204
1205 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1206 if (ret)
1207 return ret;
1208
Antti Palosaari46de20a2012-01-20 17:39:17 -03001209 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 2)|(0 << 1)|(0 << 0), 0x07);
1210 if (ret)
1211 return ret;
1212
1213 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 2)|(1 << 1)|(1 << 0), 0x07);
1214 if (ret)
1215 return ret;
1216
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001217 ret = dvb_ca_en50221_init(&d->adapter[0].dvb_adap, &state->ci, 0, 1);
1218 if (ret)
1219 return ret;
1220
Antti Palosaarif6068762012-09-22 13:46:24 -03001221 state->ci_attached = true;
1222
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001223 return 0;
1224}
1225
1226static void anysee_ci_release(struct dvb_usb_device *d)
1227{
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001228 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001229
1230 /* detach CI */
Antti Palosaarif6068762012-09-22 13:46:24 -03001231 if (state->ci_attached)
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001232 dvb_ca_en50221_release(&state->ci);
1233
1234 return;
1235}
1236
1237static int anysee_init(struct dvb_usb_device *d)
1238{
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001239 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001240 int ret;
1241
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001242 /* There is one interface with two alternate settings.
1243 Alternate setting 0 is for bulk transfer.
1244 Alternate setting 1 is for isochronous transfer.
1245 We use bulk transfer (alternate setting 0). */
1246 ret = usb_set_interface(d->udev, 0, 0);
1247 if (ret)
1248 return ret;
1249
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001250 /* LED light */
1251 ret = anysee_led_ctrl(d, 0x01, 0x03);
1252 if (ret)
1253 return ret;
1254
1255 /* enable IR */
1256 ret = anysee_ir_ctrl(d, 1);
1257 if (ret)
1258 return ret;
1259
1260 /* attach CI */
1261 if (state->has_ci) {
1262 ret = anysee_ci_init(d);
Antti Palosaarif6068762012-09-22 13:46:24 -03001263 if (ret)
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001264 return ret;
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001265 }
1266
1267 return 0;
1268}
1269
Antti Palosaari831511b2012-06-20 00:32:53 -03001270static void anysee_exit(struct dvb_usb_device *d)
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001271{
1272 return anysee_ci_release(d);
1273}
1274
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001275/* DVB USB Driver stuff */
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001276static struct dvb_usb_device_properties anysee_props = {
1277 .driver_name = KBUILD_MODNAME,
1278 .owner = THIS_MODULE,
1279 .adapter_nr = adapter_nr,
1280 .size_of_priv = sizeof(struct anysee_state),
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001281
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001282 .generic_bulk_ctrl_endpoint = 0x01,
1283 .generic_bulk_ctrl_endpoint_response = 0x81,
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001284
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001285 .i2c_algo = &anysee_i2c_algo,
1286 .read_config = anysee_read_config,
1287 .frontend_attach = anysee_frontend_attach,
1288 .tuner_attach = anysee_tuner_attach,
1289 .init = anysee_init,
1290 .get_rc_config = anysee_get_rc_config,
1291 .frontend_ctrl = anysee_frontend_ctrl,
1292 .streaming_ctrl = anysee_streaming_ctrl,
Antti Palosaari831511b2012-06-20 00:32:53 -03001293 .exit = anysee_exit,
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001294
1295 .num_adapters = 1,
1296 .adapter = {
1297 {
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001298 .stream = DVB_USB_STREAM_BULK(0x82, 8, 16 * 512),
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001299 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001300 }
1301};
1302
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001303static const struct usb_device_id anysee_id_table[] = {
1304 { DVB_USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE,
1305 &anysee_props, "Anysee", RC_MAP_ANYSEE) },
1306 { DVB_USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE,
1307 &anysee_props, "Anysee", RC_MAP_ANYSEE) },
1308 { }
1309};
1310MODULE_DEVICE_TABLE(usb, anysee_id_table);
1311
1312static struct usb_driver anysee_usb_driver = {
1313 .name = KBUILD_MODNAME,
1314 .id_table = anysee_id_table,
1315 .probe = dvb_usbv2_probe,
1316 .disconnect = dvb_usbv2_disconnect,
1317 .suspend = dvb_usbv2_suspend,
1318 .resume = dvb_usbv2_resume,
Antti Palosaari04966aa2012-08-14 22:21:08 -03001319 .reset_resume = dvb_usbv2_reset_resume,
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001320 .no_dynamic_id = 1,
1321 .soft_unbind = 1,
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001322};
1323
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001324module_usb_driver(anysee_usb_driver);
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001325
1326MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1327MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
1328MODULE_LICENSE("GPL");