blob: 48fb0d41e03bbe2a99033b536342654925f9d237 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Antti Palosaaria51e34d2008-05-17 23:05:48 -03002/*
3 * DVB USB Linux driver for Anysee E30 DVB-C & DVB-T USB2.0 receiver
4 *
5 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
6 *
Antti Palosaaria51e34d2008-05-17 23:05:48 -03007 * TODO:
8 * - add smart card reader support for Conditional Access (CA)
9 *
10 * Card reader in Anysee is nothing more than ISO 7816 card reader.
11 * There is no hardware CAM in any Anysee device sold.
12 * In my understanding it should be implemented by making own module
Antti Palosaari9fdd9ca2008-06-11 11:43:19 -030013 * for ISO 7816 card reader, like dvb_ca_en50221 is implemented. This
14 * module registers serial interface that can be used to communicate
Antti Palosaaria51e34d2008-05-17 23:05:48 -030015 * with any ISO 7816 smart card.
16 *
17 * Any help according to implement serial smart card reader support
18 * is highly welcome!
19 */
20
21#include "anysee.h"
Antti Palosaaria4e7c512012-06-14 04:56:09 -030022#include "dvb-pll.h"
Antti Palosaaria51e34d2008-05-17 23:05:48 -030023#include "tda1002x.h"
24#include "mt352.h"
25#include "mt352_priv.h"
26#include "zl10353.h"
Antti Palosaari72ffd2b2011-04-10 20:14:50 -030027#include "tda18212.h"
Antti Palosaarif0a53102011-04-27 21:11:59 -030028#include "cx24116.h"
Antti Palosaaribedbf3d2011-04-29 13:55:02 -030029#include "stv0900.h"
30#include "stv6110.h"
Antti Palosaarif0a53102011-04-27 21:11:59 -030031#include "isl6423.h"
Antti Palosaari608add82011-08-12 18:29:46 -030032#include "cxd2820r.h"
Antti Palosaaria51e34d2008-05-17 23:05:48 -030033
Antti Palosaaria51e34d2008-05-17 23:05:48 -030034DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
Antti Palosaaria51e34d2008-05-17 23:05:48 -030035
Antti Palosaari4458a54c2013-02-26 14:18:13 -030036static int anysee_ctrl_msg(struct dvb_usb_device *d,
37 u8 *sbuf, u8 slen, u8 *rbuf, u8 rlen)
Antti Palosaaria51e34d2008-05-17 23:05:48 -030038{
Antti Palosaari05cd62e2012-06-18 19:39:02 -030039 struct anysee_state *state = d_to_priv(d);
Antti Palosaaricf427952012-01-21 11:19:29 -030040 int act_len, ret, i;
Antti Palosaaria51e34d2008-05-17 23:05:48 -030041
Antti Palosaari6c604e82013-02-26 14:13:41 -030042 mutex_lock(&d->usb_mutex);
Antti Palosaaria51e34d2008-05-17 23:05:48 -030043
Antti Palosaari6c604e82013-02-26 14:13:41 -030044 memcpy(&state->buf[0], sbuf, slen);
45 state->buf[60] = state->seq++;
Antti Palosaaria51e34d2008-05-17 23:05:48 -030046
Antti Palosaari6c604e82013-02-26 14:13:41 -030047 dev_dbg(&d->udev->dev, "%s: >>> %*ph\n", __func__, slen, state->buf);
Antti Palosaari4048da22011-09-29 20:28:53 -030048
Antti Palosaaria51e34d2008-05-17 23:05:48 -030049 /* We need receive one message more after dvb_usb_generic_rw due
50 to weird transaction flow, which is 1 x send + 2 x receive. */
Antti Palosaari6c604e82013-02-26 14:13:41 -030051 ret = dvb_usbv2_generic_rw_locked(d, state->buf, sizeof(state->buf),
52 state->buf, sizeof(state->buf));
Antti Palosaaricf427952012-01-21 11:19:29 -030053 if (ret)
54 goto error_unlock;
55
56 /* TODO FIXME: dvb_usb_generic_rw() fails rarely with error code -32
57 * (EPIPE, Broken pipe). Function supports currently msleep() as a
58 * parameter but I would not like to use it, since according to
59 * Documentation/timers/timers-howto.txt it should not be used such
60 * short, under < 20ms, sleeps. Repeating failed message would be
61 * better choice as not to add unwanted delays...
62 * Fixing that correctly is one of those or both;
63 * 1) use repeat if possible
64 * 2) add suitable delay
65 */
66
67 /* get answer, retry few times if error returned */
68 for (i = 0; i < 3; i++) {
Antti Palosaaria51e34d2008-05-17 23:05:48 -030069 /* receive 2nd answer */
70 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
Antti Palosaari6c604e82013-02-26 14:13:41 -030071 d->props->generic_bulk_ctrl_endpoint),
72 state->buf, sizeof(state->buf), &act_len, 2000);
Antti Palosaaricf427952012-01-21 11:19:29 -030073 if (ret) {
Antti Palosaari4458a54c2013-02-26 14:18:13 -030074 dev_dbg(&d->udev->dev,
75 "%s: recv bulk message failed=%d\n",
76 __func__, ret);
Antti Palosaaricf427952012-01-21 11:19:29 -030077 } else {
Antti Palosaari82026f92012-08-14 15:56:20 -030078 dev_dbg(&d->udev->dev, "%s: <<< %*ph\n", __func__,
Antti Palosaari6c604e82013-02-26 14:13:41 -030079 rlen, state->buf);
Antti Palosaari4048da22011-09-29 20:28:53 -030080
Antti Palosaari6c604e82013-02-26 14:13:41 -030081 if (state->buf[63] != 0x4f)
Antti Palosaari4458a54c2013-02-26 14:18:13 -030082 dev_dbg(&d->udev->dev,
83 "%s: cmd failed\n", __func__);
Antti Palosaaricf427952012-01-21 11:19:29 -030084 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -030085 }
86 }
87
Antti Palosaaricf427952012-01-21 11:19:29 -030088 if (ret) {
89 /* all retries failed, it is fatal */
Antti Palosaari82026f92012-08-14 15:56:20 -030090 dev_err(&d->udev->dev, "%s: recv bulk message failed=%d\n",
91 KBUILD_MODNAME, ret);
Antti Palosaaricf427952012-01-21 11:19:29 -030092 goto error_unlock;
93 }
94
Antti Palosaaria51e34d2008-05-17 23:05:48 -030095 /* read request, copy returned data to return buf */
Antti Palosaaricf427952012-01-21 11:19:29 -030096 if (rbuf && rlen)
Antti Palosaari6c604e82013-02-26 14:13:41 -030097 memcpy(rbuf, state->buf, rlen);
Antti Palosaaria51e34d2008-05-17 23:05:48 -030098
Antti Palosaaricf427952012-01-21 11:19:29 -030099error_unlock:
Antti Palosaari6c604e82013-02-26 14:13:41 -0300100 mutex_unlock(&d->usb_mutex);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300101 return ret;
102}
103
104static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
105{
106 u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01};
107 int ret;
108 ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1);
Antti Palosaari82026f92012-08-14 15:56:20 -0300109 dev_dbg(&d->udev->dev, "%s: reg=%04x val=%02x\n", __func__, reg, *val);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300110 return ret;
111}
112
113static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val)
114{
115 u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val};
Antti Palosaari82026f92012-08-14 15:56:20 -0300116 dev_dbg(&d->udev->dev, "%s: reg=%04x val=%02x\n", __func__, reg, val);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300117 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
118}
119
Antti Palosaari41f81f62011-04-10 17:53:52 -0300120/* write single register with mask */
121static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
122 u8 mask)
123{
124 int ret;
125 u8 tmp;
126
127 /* no need for read if whole reg is written */
128 if (mask != 0xff) {
129 ret = anysee_read_reg(d, reg, &tmp);
130 if (ret)
131 return ret;
132
133 val &= mask;
134 tmp &= ~mask;
135 val |= tmp;
136 }
137
138 return anysee_write_reg(d, reg, val);
139}
140
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300141/* read single register with mask */
142static int anysee_rd_reg_mask(struct dvb_usb_device *d, u16 reg, u8 *val,
143 u8 mask)
144{
145 int ret, i;
146 u8 tmp;
147
148 ret = anysee_read_reg(d, reg, &tmp);
149 if (ret)
150 return ret;
151
152 tmp &= mask;
153
154 /* find position of the first bit */
155 for (i = 0; i < 8; i++) {
156 if ((mask >> i) & 0x01)
157 break;
158 }
159 *val = tmp >> i;
160
161 return 0;
162}
163
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300164static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id)
165{
166 u8 buf[] = {CMD_GET_HW_INFO};
167 return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3);
168}
169
Antti Palosaaria13a6e12012-06-26 00:04:33 -0300170static int anysee_streaming_ctrl(struct dvb_frontend *fe, int onoff)
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300171{
172 u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00};
Antti Palosaari82026f92012-08-14 15:56:20 -0300173 dev_dbg(&fe_to_d(fe)->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Antti Palosaaria13a6e12012-06-26 00:04:33 -0300174 return anysee_ctrl_msg(fe_to_d(fe), buf, sizeof(buf), NULL, 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300175}
176
177static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval)
178{
179 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval};
Antti Palosaari82026f92012-08-14 15:56:20 -0300180 dev_dbg(&d->udev->dev, "%s: state=%d interval=%d\n", __func__,
181 mode, interval);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300182 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
183}
184
185static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff)
186{
187 u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff};
Antti Palosaari82026f92012-08-14 15:56:20 -0300188 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300189 return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
190}
191
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300192/* I2C */
193static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
194 int num)
195{
196 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Mauro Carvalho Chehab902571a2008-12-29 19:02:24 -0300197 int ret = 0, inc, i = 0;
Antti Palosaari21d2e932011-05-24 06:04:08 -0300198 u8 buf[52]; /* 4 + 48 (I2C WR USB command header + I2C WR max) */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300199
200 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
201 return -EAGAIN;
202
203 while (i < num) {
204 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
Antti Palosaari21d2e932011-05-24 06:04:08 -0300205 if (msg[i].len > 2 || msg[i+1].len > 60) {
206 ret = -EOPNOTSUPP;
207 break;
208 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300209 buf[0] = CMD_I2C_READ;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300210 buf[1] = (msg[i].addr << 1) | 0x01;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300211 buf[2] = msg[i].buf[0];
Antti Palosaari882b82c2011-04-12 19:49:25 -0300212 buf[3] = msg[i].buf[1];
213 buf[4] = msg[i].len-1;
Antti Palosaarib3e6a5a2011-04-09 21:00:51 -0300214 buf[5] = msg[i+1].len;
Antti Palosaari21d2e932011-05-24 06:04:08 -0300215 ret = anysee_ctrl_msg(d, buf, 6, msg[i+1].buf,
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300216 msg[i+1].len);
217 inc = 2;
218 } else {
Antti Palosaari21d2e932011-05-24 06:04:08 -0300219 if (msg[i].len > 48) {
220 ret = -EOPNOTSUPP;
221 break;
222 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300223 buf[0] = CMD_I2C_WRITE;
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300224 buf[1] = (msg[i].addr << 1);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300225 buf[2] = msg[i].len;
226 buf[3] = 0x01;
227 memcpy(&buf[4], msg[i].buf, msg[i].len);
Antti Palosaari21d2e932011-05-24 06:04:08 -0300228 ret = anysee_ctrl_msg(d, buf, 4 + msg[i].len, NULL, 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300229 inc = 1;
230 }
231 if (ret)
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300232 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300233
234 i += inc;
235 }
236
237 mutex_unlock(&d->i2c_mutex);
238
Antti Palosaarie613f8f2008-08-11 10:36:43 -0300239 return ret ? ret : i;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300240}
241
242static u32 anysee_i2c_func(struct i2c_adapter *adapter)
243{
244 return I2C_FUNC_I2C;
245}
246
247static struct i2c_algorithm anysee_i2c_algo = {
248 .master_xfer = anysee_master_xfer,
249 .functionality = anysee_i2c_func,
250};
251
252static int anysee_mt352_demod_init(struct dvb_frontend *fe)
253{
Antti Palosaariae3745f2009-09-16 19:50:25 -0300254 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 };
255 static u8 reset[] = { RESET, 0x80 };
256 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
257 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 };
258 static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300259 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
260
261 mt352_write(fe, clock_config, sizeof(clock_config));
262 udelay(200);
263 mt352_write(fe, reset, sizeof(reset));
264 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
265
266 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
267 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
268 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
269
270 return 0;
271}
272
273/* Callbacks for DVB USB */
274static struct tda10023_config anysee_tda10023_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300275 .demod_address = (0x1a >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300276 .invert = 0,
277 .xtal = 16000000,
278 .pll_m = 11,
279 .pll_p = 3,
280 .pll_n = 1,
Antti Palosaari5ae2fca2008-06-09 22:58:22 -0300281 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C,
282 .deltaf = 0xfeeb,
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300283};
284
285static struct mt352_config anysee_mt352_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300286 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300287 .demod_init = anysee_mt352_demod_init,
288};
289
290static struct zl10353_config anysee_zl10353_config = {
Antti Palosaari7ea03d22011-04-09 20:50:07 -0300291 .demod_address = (0x1e >> 1),
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300292 .parallel_ts = 1,
293};
294
Antti Palosaari1fd80702011-04-12 17:34:08 -0300295static struct zl10353_config anysee_zl10353_tda18212_config2 = {
296 .demod_address = (0x1e >> 1),
297 .parallel_ts = 1,
298 .disable_i2c_gate_ctrl = 1,
299 .no_tuner = 1,
300 .if2 = 41500,
301};
302
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300303static struct zl10353_config anysee_zl10353_tda18212_config = {
304 .demod_address = (0x18 >> 1),
305 .parallel_ts = 1,
306 .disable_i2c_gate_ctrl = 1,
307 .no_tuner = 1,
308 .if2 = 41500,
309};
310
311static struct tda10023_config anysee_tda10023_tda18212_config = {
312 .demod_address = (0x1a >> 1),
313 .xtal = 16000000,
314 .pll_m = 12,
315 .pll_p = 3,
316 .pll_n = 1,
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300317 .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_B,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300318 .deltaf = 0xba02,
319};
320
321static struct tda18212_config anysee_tda18212_config = {
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300322 .if_dvbt_6 = 4150,
323 .if_dvbt_7 = 4150,
324 .if_dvbt_8 = 4150,
325 .if_dvbc = 5000,
326};
327
Antti Palosaari608add82011-08-12 18:29:46 -0300328static struct tda18212_config anysee_tda18212_config2 = {
Antti Palosaari608add82011-08-12 18:29:46 -0300329 .if_dvbt_6 = 3550,
330 .if_dvbt_7 = 3700,
331 .if_dvbt_8 = 4150,
332 .if_dvbt2_6 = 3250,
333 .if_dvbt2_7 = 4000,
334 .if_dvbt2_8 = 4000,
335 .if_dvbc = 5000,
336};
337
Antti Palosaarif0a53102011-04-27 21:11:59 -0300338static struct cx24116_config anysee_cx24116_config = {
339 .demod_address = (0xaa >> 1),
340 .mpg_clk_pos_pol = 0x00,
341 .i2c_wr_max = 48,
342};
343
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300344static struct stv0900_config anysee_stv0900_config = {
345 .demod_address = (0xd0 >> 1),
346 .demod_mode = 0,
347 .xtal = 8000000,
348 .clkmode = 3,
349 .diseqc_mode = 2,
350 .tun1_maddress = 0,
351 .tun1_adc = 1, /* 1 Vpp */
352 .path1_mode = 3,
353};
354
355static struct stv6110_config anysee_stv6110_config = {
356 .i2c_address = (0xc0 >> 1),
357 .mclk = 16000000,
358 .clk_div = 1,
359};
360
Antti Palosaarif0a53102011-04-27 21:11:59 -0300361static struct isl6423_config anysee_isl6423_config = {
362 .current_max = SEC_CURRENT_800m,
363 .curlim = SEC_CURRENT_LIM_OFF,
364 .mod_extern = 1,
365 .addr = (0x10 >> 1),
366};
367
Antti Palosaari608add82011-08-12 18:29:46 -0300368static struct cxd2820r_config anysee_cxd2820r_config = {
369 .i2c_address = 0x6d, /* (0xda >> 1) */
370 .ts_mode = 0x38,
Antti Palosaari608add82011-08-12 18:29:46 -0300371};
372
Antti Palosaari41f81f62011-04-10 17:53:52 -0300373/*
374 * New USB device strings: Mfr=1, Product=2, SerialNumber=0
375 * Manufacturer: AMT.CO.KR
376 *
377 * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=????????
378 * PCB: ?
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300379 * parts: DNOS404ZH102A(MT352, DTT7579(?))
Antti Palosaari41f81f62011-04-10 17:53:52 -0300380 *
Antti Palosaari05c46c02011-05-25 18:30:09 -0300381 * E30 VID=04b4 PID=861f HW=2 FW=2.1 "anysee-T(LP)"
382 * PCB: PCB 507T (rev1.61)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300383 * parts: DNOS404ZH103A(ZL10353, DTT7579(?))
Antti Palosaari05c46c02011-05-25 18:30:09 -0300384 * OEA=0a OEB=00 OEC=00 OED=ff OEE=00
385 * IOA=45 IOB=ff IOC=00 IOD=ff IOE=00
Antti Palosaari41f81f62011-04-10 17:53:52 -0300386 *
387 * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee"
388 * PCB: 507CD (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300389 * parts: DNOS404ZH103A(ZL10353, DTT7579(?)), CST56I01
Antti Palosaari05c46c02011-05-25 18:30:09 -0300390 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
391 * IOA=4f IOB=ff IOC=00 IOD=06 IOE=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300392 * IOD[0] ZL10353 1=enabled
393 * IOA[7] TS 0=enabled
394 * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not)
395 *
396 * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)"
397 * PCB: 507DC (rev0.2)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300398 * parts: TDA10023, DTOS403IH102B TM, CST56I01
Antti Palosaari05c46c02011-05-25 18:30:09 -0300399 * OEA=80 OEB=00 OEC=00 OED=ff OEE=fe
400 * IOA=4f IOB=ff IOC=00 IOD=26 IOE=01
Antti Palosaari41f81f62011-04-10 17:53:52 -0300401 * IOD[0] TDA10023 1=enabled
402 *
Antti Palosaarif0a53102011-04-27 21:11:59 -0300403 * E30 S2 Plus VID=04b4 PID=861f HW=11 FW=0.1 "anysee-S2(LP)"
404 * PCB: 507SI (rev2.1)
405 * parts: BS2N10WCC01(CX24116, CX24118), ISL6423, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300406 * OEA=80 OEB=00 OEC=ff OED=ff OEE=fe
407 * IOA=4d IOB=ff IOC=00 IOD=26 IOE=01
Antti Palosaarif0a53102011-04-27 21:11:59 -0300408 * IOD[0] CX24116 1=enabled
409 *
Antti Palosaari41f81f62011-04-10 17:53:52 -0300410 * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
411 * PCB: 507FA (rev0.4)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300412 * parts: TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300413 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
414 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300415 * IOD[5] TDA10023 1=enabled
416 * IOE[0] tuner 1=enabled
417 *
418 * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)"
419 * PCB: 507FA (rev1.1)
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300420 * parts: ZL10353, TDA10023, DTOS403IH102B TM, TDA8024
Antti Palosaari05c46c02011-05-25 18:30:09 -0300421 * OEA=80 OEB=00 OEC=ff OED=ff OEE=ff
422 * IOA=4d IOB=ff IOC=00 IOD=00 IOE=c0
Antti Palosaari41f81f62011-04-10 17:53:52 -0300423 * DVB-C:
424 * IOD[5] TDA10023 1=enabled
425 * IOE[0] tuner 1=enabled
426 * DVB-T:
427 * IOD[0] ZL10353 1=enabled
428 * IOE[0] tuner 0=enabled
429 * tuner is behind ZL10353 I2C-gate
Antti Palosaaric57f87e2013-12-16 21:08:04 -0300430 * tuner is behind TDA10023 I2C-gate
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300431 *
432 * E7 TC VID=1c73 PID=861f HW=18 FW=0.7 AMTCI=0.5 "anysee-E7TC(LP)"
433 * PCB: 508TC (rev0.6)
434 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
Antti Palosaari05c46c02011-05-25 18:30:09 -0300435 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
436 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
Antti Palosaari70fc26f2011-04-12 20:17:11 -0300437 * IOA[7] TS 1=enabled
438 * IOE[4] TDA18212 1=enabled
439 * DVB-C:
440 * IOD[6] ZL10353 0=disabled
441 * IOD[5] TDA10023 1=enabled
442 * IOE[0] IF 1=enabled
443 * DVB-T:
444 * IOD[5] TDA10023 0=disabled
445 * IOD[6] ZL10353 1=enabled
446 * IOE[0] IF 0=enabled
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300447 *
448 * E7 S2 VID=1c73 PID=861f HW=19 FW=0.4 AMTCI=0.5 "anysee-E7S2(LP)"
449 * PCB: 508S2 (rev0.7)
450 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
Antti Palosaari05c46c02011-05-25 18:30:09 -0300451 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
452 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300453 * IOA[7] TS 1=enabled
454 * IOE[5] STV0903 1=enabled
455 *
Antti Palosaari608add82011-08-12 18:29:46 -0300456 * E7 T2C VID=1c73 PID=861f HW=20 FW=0.1 AMTCI=0.5 "anysee-E7T2C(LP)"
457 * PCB: 508T2C (rev0.3)
458 * parts: DNOQ44QCH106A(CXD2820R, TDA18212), TDA8024
459 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
460 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
461 * IOA[7] TS 1=enabled
462 * IOE[5] CXD2820R 1=enabled
463 *
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300464 * E7 PTC VID=1c73 PID=861f HW=21 FW=0.1 AMTCI=?? "anysee-E7PTC(LP)"
465 * PCB: 508PTC (rev0.5)
466 * parts: ZL10353, TDA10023, DNOD44CDH086A(TDA18212)
467 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
468 * IOA=4d IOB=00 IOC=cc IOD=48 IOE=e4
469 * IOA[7] TS 1=enabled
470 * IOE[4] TDA18212 1=enabled
471 * DVB-C:
472 * IOD[6] ZL10353 0=disabled
473 * IOD[5] TDA10023 1=enabled
474 * IOE[0] IF 1=enabled
475 * DVB-T:
476 * IOD[5] TDA10023 0=disabled
477 * IOD[6] ZL10353 1=enabled
478 * IOE[0] IF 0=enabled
Antti Palosaarifea3c392011-05-25 18:21:43 -0300479 *
Antti Palosaari608add82011-08-12 18:29:46 -0300480 * E7 PS2 VID=1c73 PID=861f HW=22 FW=0.1 AMTCI=?? "anysee-E7PS2(LP)"
Antti Palosaarifea3c392011-05-25 18:21:43 -0300481 * PCB: 508PS2 (rev0.4)
482 * parts: DNBU10512IST(STV0903, STV6110), ISL6423
483 * OEA=80 OEB=00 OEC=03 OED=f7 OEE=ff
484 * IOA=4d IOB=00 IOC=c4 IOD=08 IOE=e4
485 * IOA[7] TS 1=enabled
486 * IOE[5] STV0903 1=enabled
Antti Palosaari41f81f62011-04-10 17:53:52 -0300487 */
488
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300489static int anysee_read_config(struct dvb_usb_device *d)
490{
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300491 struct anysee_state *state = d_to_priv(d);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300492 int ret;
493 u8 hw_info[3];
494
495 /*
496 * Check which hardware we have.
497 * We must do this call two times to get reliable values (hw/fw bug).
498 */
499 ret = anysee_get_hw_info(d, hw_info);
500 if (ret)
501 goto error;
502
503 ret = anysee_get_hw_info(d, hw_info);
504 if (ret)
505 goto error;
506
Antti Palosaari82026f92012-08-14 15:56:20 -0300507 /*
508 * Meaning of these info bytes are guessed.
509 */
510 dev_info(&d->udev->dev, "%s: firmware version %d.%d hardware id %d\n",
511 KBUILD_MODNAME, hw_info[1], hw_info[2], hw_info[0]);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300512
513 state->hw = hw_info[0];
514error:
515 return ret;
516}
Antti Palosaaribe943512011-09-05 22:10:05 -0300517
518/* external I2C gate used for DNOD44CDH086A(TDA18212) tuner module */
519static int anysee_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
520{
Antti Palosaaribe943512011-09-05 22:10:05 -0300521 /* enable / disable tuner access on IOE[4] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300522 return anysee_wr_reg_mask(fe_to_d(fe), REG_IOE, (enable << 4), 0x10);
Antti Palosaaribe943512011-09-05 22:10:05 -0300523}
524
Antti Palosaari449d1a02011-07-25 20:25:21 -0300525static int anysee_frontend_ctrl(struct dvb_frontend *fe, int onoff)
526{
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300527 struct anysee_state *state = fe_to_priv(fe);
528 struct dvb_usb_device *d = fe_to_d(fe);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300529 int ret;
Antti Palosaari82026f92012-08-14 15:56:20 -0300530 dev_dbg(&d->udev->dev, "%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300531
532 /* no frontend sleep control */
533 if (onoff == 0)
534 return 0;
535
536 switch (state->hw) {
537 case ANYSEE_HW_507FA: /* 15 */
538 /* E30 Combo Plus */
539 /* E30 C Plus */
540
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300541 if (fe->id == 0) {
Antti Palosaari449d1a02011-07-25 20:25:21 -0300542 /* disable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300543 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300544 if (ret)
545 goto error;
546
547 /* enable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300548 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300549 if (ret)
550 goto error;
551
552 /* enable DVB-C tuner on IOE[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300553 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300554 if (ret)
555 goto error;
556 } else {
557 /* disable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300558 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300559 if (ret)
560 goto error;
561
562 /* enable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300563 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300564 if (ret)
565 goto error;
566
567 /* enable DVB-T tuner on IOE[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300568 ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300569 if (ret)
570 goto error;
571 }
572
573 break;
574 case ANYSEE_HW_508TC: /* 18 */
575 case ANYSEE_HW_508PTC: /* 21 */
576 /* E7 TC */
577 /* E7 PTC */
578
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300579 if (fe->id == 0) {
Antti Palosaari449d1a02011-07-25 20:25:21 -0300580 /* disable DVB-T demod on IOD[6] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300581 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 6), 0x40);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300582 if (ret)
583 goto error;
584
585 /* enable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300586 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300587 if (ret)
588 goto error;
589
590 /* enable IF route on IOE[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300591 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300592 if (ret)
593 goto error;
594 } else {
595 /* disable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300596 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300597 if (ret)
598 goto error;
599
600 /* enable DVB-T demod on IOD[6] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300601 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 6), 0x40);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300602 if (ret)
603 goto error;
604
605 /* enable IF route on IOE[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300606 ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 0), 0x01);
Antti Palosaari449d1a02011-07-25 20:25:21 -0300607 if (ret)
608 goto error;
609 }
610
611 break;
612 default:
613 ret = 0;
614 }
615
616error:
617 return ret;
618}
619
Kees Cook73831592014-10-20 18:49:04 -0300620static int anysee_add_i2c_dev(struct dvb_usb_device *d, const char *type,
621 u8 addr, void *platform_data)
Antti Palosaarif80f2ae2014-08-03 21:47:10 -0300622{
623 int ret, num;
624 struct anysee_state *state = d_to_priv(d);
625 struct i2c_client *client;
626 struct i2c_adapter *adapter = &d->i2c_adap;
627 struct i2c_board_info board_info = {
628 .addr = addr,
629 .platform_data = platform_data,
630 };
631
Mauro Carvalho Chehabc0decac2018-09-10 08:19:14 -0400632 strscpy(board_info.type, type, I2C_NAME_SIZE);
Antti Palosaarif80f2ae2014-08-03 21:47:10 -0300633
634 /* find first free client */
635 for (num = 0; num < ANYSEE_I2C_CLIENT_MAX; num++) {
636 if (state->i2c_client[num] == NULL)
637 break;
638 }
639
640 dev_dbg(&d->udev->dev, "%s: num=%d\n", __func__, num);
641
642 if (num == ANYSEE_I2C_CLIENT_MAX) {
643 dev_err(&d->udev->dev, "%s: I2C client out of index\n",
644 KBUILD_MODNAME);
645 ret = -ENODEV;
646 goto err;
647 }
648
Kees Cook73831592014-10-20 18:49:04 -0300649 request_module("%s", board_info.type);
Antti Palosaarif80f2ae2014-08-03 21:47:10 -0300650
651 /* register I2C device */
652 client = i2c_new_device(adapter, &board_info);
653 if (client == NULL || client->dev.driver == NULL) {
654 ret = -ENODEV;
655 goto err;
656 }
657
658 /* increase I2C driver usage count */
659 if (!try_module_get(client->dev.driver->owner)) {
660 i2c_unregister_device(client);
661 ret = -ENODEV;
662 goto err;
663 }
664
665 state->i2c_client[num] = client;
666 return 0;
667err:
668 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
669 return ret;
670}
671
672static void anysee_del_i2c_dev(struct dvb_usb_device *d)
673{
674 int num;
675 struct anysee_state *state = d_to_priv(d);
676 struct i2c_client *client;
677
678 /* find last used client */
679 num = ANYSEE_I2C_CLIENT_MAX;
680 while (num--) {
681 if (state->i2c_client[num] != NULL)
682 break;
683 }
684
685 dev_dbg(&d->udev->dev, "%s: num=%d\n", __func__, num);
686
687 if (num == -1) {
688 dev_err(&d->udev->dev, "%s: I2C client out of index\n",
689 KBUILD_MODNAME);
690 goto err;
691 }
692
693 client = state->i2c_client[num];
694
695 /* decrease I2C driver usage count */
696 module_put(client->dev.driver->owner);
697
698 /* unregister I2C device */
699 i2c_unregister_device(client);
700
701 state->i2c_client[num] = NULL;
702err:
703 dev_dbg(&d->udev->dev, "%s: failed\n", __func__);
704}
705
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300706static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
707{
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300708 struct anysee_state *state = adap_to_priv(adap);
709 struct dvb_usb_device *d = adap_to_d(adap);
Geert Uytterhoevenecb52ab2013-04-24 07:36:45 -0300710 int ret = 0;
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300711 u8 tmp;
712 struct i2c_msg msg[2] = {
713 {
Antti Palosaarif80f2ae2014-08-03 21:47:10 -0300714 .addr = 0x60,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300715 .flags = 0,
716 .len = 1,
717 .buf = "\x00",
718 }, {
Antti Palosaarif80f2ae2014-08-03 21:47:10 -0300719 .addr = 0x60,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300720 .flags = I2C_M_RD,
721 .len = 1,
722 .buf = &tmp,
723 }
724 };
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300725
Antti Palosaari41f81f62011-04-10 17:53:52 -0300726 switch (state->hw) {
Antti Palosaari05c46c02011-05-25 18:30:09 -0300727 case ANYSEE_HW_507T: /* 2 */
Antti Palosaari41f81f62011-04-10 17:53:52 -0300728 /* E30 */
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300729
Antti Palosaari41f81f62011-04-10 17:53:52 -0300730 /* attach demod */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300731 adap->fe[0] = dvb_attach(mt352_attach, &anysee_mt352_config,
732 &d->i2c_adap);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300733 if (adap->fe[0])
Antti Palosaari41f81f62011-04-10 17:53:52 -0300734 break;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300735
Antti Palosaari41f81f62011-04-10 17:53:52 -0300736 /* attach demod */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300737 adap->fe[0] = dvb_attach(zl10353_attach, &anysee_zl10353_config,
738 &d->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300739
740 break;
741 case ANYSEE_HW_507CD: /* 6 */
742 /* E30 Plus */
743
744 /* enable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300745 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300746 if (ret)
747 goto error;
748
749 /* enable transport stream on IOA[7] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300750 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300751 if (ret)
752 goto error;
753
754 /* attach demod */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300755 adap->fe[0] = dvb_attach(zl10353_attach, &anysee_zl10353_config,
756 &d->i2c_adap);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300757
758 break;
759 case ANYSEE_HW_507DC: /* 10 */
760 /* E30 C Plus */
761
762 /* enable DVB-C demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300763 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300764 if (ret)
765 goto error;
766
767 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300768 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300769 &anysee_tda10023_config, &d->i2c_adap, 0x48);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300770
771 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300772 case ANYSEE_HW_507SI: /* 11 */
773 /* E30 S2 Plus */
774
775 /* enable DVB-S/S2 demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300776 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaarif0a53102011-04-27 21:11:59 -0300777 if (ret)
778 goto error;
779
780 /* attach demod */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300781 adap->fe[0] = dvb_attach(cx24116_attach, &anysee_cx24116_config,
782 &d->i2c_adap);
Antti Palosaarif0a53102011-04-27 21:11:59 -0300783
784 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300785 case ANYSEE_HW_507FA: /* 15 */
786 /* E30 Combo Plus */
787 /* E30 C Plus */
788
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300789 /* enable tuner on IOE[4] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300790 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 4), 0x10);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300791 if (ret)
792 goto error;
793
794 /* probe TDA18212 */
795 tmp = 0;
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300796 ret = i2c_transfer(&d->i2c_adap, msg, 2);
Antti Palosaarif80f2ae2014-08-03 21:47:10 -0300797 if (ret == 2 && tmp == 0xc7) {
Antti Palosaari82026f92012-08-14 15:56:20 -0300798 dev_dbg(&d->udev->dev, "%s: TDA18212 found\n",
799 __func__);
Antti Palosaarif80f2ae2014-08-03 21:47:10 -0300800 state->has_tda18212 = true;
801 }
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300802 else
803 tmp = 0;
804
805 /* disable tuner on IOE[4] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300806 ret = anysee_wr_reg_mask(d, REG_IOE, (0 << 4), 0x10);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300807 if (ret)
808 goto error;
809
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300810 /* disable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300811 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 0), 0x01);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300812 if (ret)
813 goto error;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300814
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300815 /* enable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300816 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300817 if (ret)
818 goto error;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300819
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300820 /* attach demod */
821 if (tmp == 0xc7) {
822 /* TDA18212 config */
823 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300824 &anysee_tda10023_tda18212_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300825 &d->i2c_adap, 0x48);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300826
827 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
828 if (adap->fe[0])
829 adap->fe[0]->ops.i2c_gate_ctrl =
830 anysee_i2c_gate_ctrl;
831 } else {
832 /* PLL config */
833 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300834 &anysee_tda10023_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300835 &d->i2c_adap, 0x48);
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300836 }
Antti Palosaarie82eea72011-04-12 19:43:30 -0300837
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300838 /* break out if first frontend attaching fails */
839 if (!adap->fe[0])
840 break;
841
842 /* disable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300843 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300844 if (ret)
845 goto error;
846
847 /* enable DVB-T demod on IOD[0] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300848 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 0), 0x01);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300849 if (ret)
850 goto error;
851
852 /* attach demod */
Antti Palosaaribe943512011-09-05 22:10:05 -0300853 if (tmp == 0xc7) {
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300854 /* TDA18212 config */
855 adap->fe[1] = dvb_attach(zl10353_attach,
856 &anysee_zl10353_tda18212_config2,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300857 &d->i2c_adap);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300858
859 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
860 if (adap->fe[1])
861 adap->fe[1]->ops.i2c_gate_ctrl =
862 anysee_i2c_gate_ctrl;
863 } else {
864 /* PLL config */
865 adap->fe[1] = dvb_attach(zl10353_attach,
866 &anysee_zl10353_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300867 &d->i2c_adap);
Antti Palosaaribe943512011-09-05 22:10:05 -0300868 }
869
Antti Palosaari41f81f62011-04-10 17:53:52 -0300870 break;
Antti Palosaaria43be982011-04-10 20:23:02 -0300871 case ANYSEE_HW_508TC: /* 18 */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300872 case ANYSEE_HW_508PTC: /* 21 */
Antti Palosaaria43be982011-04-10 20:23:02 -0300873 /* E7 TC */
Antti Palosaari8439e0d2011-05-24 07:57:34 -0300874 /* E7 PTC */
Antti Palosaaria43be982011-04-10 20:23:02 -0300875
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300876 /* disable DVB-T demod on IOD[6] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300877 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 6), 0x40);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300878 if (ret)
879 goto error;
Antti Palosaaria43be982011-04-10 20:23:02 -0300880
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300881 /* enable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300882 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 5), 0x20);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300883 if (ret)
884 goto error;
Antti Palosaaria43be982011-04-10 20:23:02 -0300885
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300886 /* attach demod */
887 adap->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari449d1a02011-07-25 20:25:21 -0300888 &anysee_tda10023_tda18212_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300889 &d->i2c_adap, 0x48);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300890
Antti Palosaaribe943512011-09-05 22:10:05 -0300891 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300892 if (adap->fe[0])
893 adap->fe[0]->ops.i2c_gate_ctrl = anysee_i2c_gate_ctrl;
894
895 /* break out if first frontend attaching fails */
896 if (!adap->fe[0])
897 break;
898
899 /* disable DVB-C demod on IOD[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300900 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 5), 0x20);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300901 if (ret)
902 goto error;
903
904 /* enable DVB-T demod on IOD[6] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300905 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 6), 0x40);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300906 if (ret)
907 goto error;
908
909 /* attach demod */
910 adap->fe[1] = dvb_attach(zl10353_attach,
911 &anysee_zl10353_tda18212_config,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300912 &d->i2c_adap);
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300913
914 /* I2C gate for DNOD44CDH086A(TDA18212) tuner module */
915 if (adap->fe[1])
916 adap->fe[1]->ops.i2c_gate_ctrl = anysee_i2c_gate_ctrl;
Antti Palosaaribe943512011-09-05 22:10:05 -0300917
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300918 state->has_ci = true;
919
Antti Palosaaria43be982011-04-10 20:23:02 -0300920 break;
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300921 case ANYSEE_HW_508S2: /* 19 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300922 case ANYSEE_HW_508PS2: /* 22 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300923 /* E7 S2 */
Antti Palosaarifea3c392011-05-25 18:21:43 -0300924 /* E7 PS2 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300925
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300926 /* enable DVB-S/S2 demod on IOE[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300927 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 5), 0x20);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300928 if (ret)
929 goto error;
930
931 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300932 adap->fe[0] = dvb_attach(stv0900_attach,
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300933 &anysee_stv0900_config, &d->i2c_adap, 0);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300934
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300935 state->has_ci = true;
936
Antti Palosaaribedbf3d2011-04-29 13:55:02 -0300937 break;
Antti Palosaari608add82011-08-12 18:29:46 -0300938 case ANYSEE_HW_508T2C: /* 20 */
939 /* E7 T2C */
940
Antti Palosaari608add82011-08-12 18:29:46 -0300941 /* enable DVB-T/T2/C demod on IOE[5] */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300942 ret = anysee_wr_reg_mask(d, REG_IOE, (1 << 5), 0x20);
Antti Palosaari608add82011-08-12 18:29:46 -0300943 if (ret)
944 goto error;
945
Antti Palosaarifaf27972012-01-15 14:20:50 -0300946 /* attach demod */
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300947 adap->fe[0] = dvb_attach(cxd2820r_attach,
Antti Palosaari1e8f31f2012-07-19 21:10:36 -0300948 &anysee_cxd2820r_config, &d->i2c_adap, NULL);
Antti Palosaari608add82011-08-12 18:29:46 -0300949
Antti Palosaari05cd37d2011-09-05 23:33:04 -0300950 state->has_ci = true;
Antti Palosaari0f77c3a2008-08-11 10:54:16 -0300951
952 break;
953 }
954
Antti Palosaaria4e7c512012-06-14 04:56:09 -0300955 if (!adap->fe[0]) {
Antti Palosaari41f81f62011-04-10 17:53:52 -0300956 /* we have no frontend :-( */
957 ret = -ENODEV;
Antti Palosaari4458a54c2013-02-26 14:18:13 -0300958 dev_err(&d->udev->dev,
Geert Uytterhoeven542b3292013-04-24 07:36:46 -0300959 "%s: Unsupported Anysee version. Please report to <linux-media@vger.kernel.org>.\n",
Antti Palosaari82026f92012-08-14 15:56:20 -0300960 KBUILD_MODNAME);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300961 }
Antti Palosaari41f81f62011-04-10 17:53:52 -0300962error:
963 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300964}
965
966static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
967{
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300968 struct anysee_state *state = adap_to_priv(adap);
969 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari72ffd2b2011-04-10 20:14:50 -0300970 struct dvb_frontend *fe;
Antti Palosaarie82eea72011-04-12 19:43:30 -0300971 int ret;
Antti Palosaari82026f92012-08-14 15:56:20 -0300972 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300973
Antti Palosaari41f81f62011-04-10 17:53:52 -0300974 switch (state->hw) {
Antti Palosaari05c46c02011-05-25 18:30:09 -0300975 case ANYSEE_HW_507T: /* 2 */
Antti Palosaari41f81f62011-04-10 17:53:52 -0300976 /* E30 */
977
978 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300979 fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc2 >> 1), NULL,
980 DVB_PLL_THOMSON_DTT7579);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300981
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300982 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -0300983 case ANYSEE_HW_507CD: /* 6 */
984 /* E30 Plus */
985
986 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300987 fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc2 >> 1),
988 &d->i2c_adap, DVB_PLL_THOMSON_DTT7579);
Antti Palosaari41f81f62011-04-10 17:53:52 -0300989
990 break;
991 case ANYSEE_HW_507DC: /* 10 */
992 /* E30 C Plus */
993
994 /* attach tuner */
Antti Palosaari05cd62e2012-06-18 19:39:02 -0300995 fe = dvb_attach(dvb_pll_attach, adap->fe[0], (0xc0 >> 1),
996 &d->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A);
Antti Palosaarie82eea72011-04-12 19:43:30 -0300997
Antti Palosaaria51e34d2008-05-17 23:05:48 -0300998 break;
Antti Palosaarif0a53102011-04-27 21:11:59 -0300999 case ANYSEE_HW_507SI: /* 11 */
1000 /* E30 S2 Plus */
1001
1002 /* attach LNB controller */
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001003 fe = dvb_attach(isl6423_attach, adap->fe[0], &d->i2c_adap,
1004 &anysee_isl6423_config);
Antti Palosaarif0a53102011-04-27 21:11:59 -03001005
1006 break;
Antti Palosaari41f81f62011-04-10 17:53:52 -03001007 case ANYSEE_HW_507FA: /* 15 */
1008 /* E30 Combo Plus */
1009 /* E30 C Plus */
1010
Antti Palosaari72ffd2b2011-04-10 20:14:50 -03001011 /* Try first attach TDA18212 silicon tuner on IOE[4], if that
1012 * fails attach old simple PLL. */
1013
Antti Palosaari72ffd2b2011-04-10 20:14:50 -03001014 /* attach tuner */
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001015 if (state->has_tda18212) {
1016 struct tda18212_config tda18212_config =
1017 anysee_tda18212_config;
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001018
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001019 tda18212_config.fe = adap->fe[0];
1020 ret = anysee_add_i2c_dev(d, "tda18212", 0x60,
1021 &tda18212_config);
1022 if (ret)
1023 goto err;
Antti Palosaari72ffd2b2011-04-10 20:14:50 -03001024
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001025 /* copy tuner ops for 2nd FE as tuner is shared */
1026 if (adap->fe[1]) {
1027 adap->fe[1]->tuner_priv =
1028 adap->fe[0]->tuner_priv;
1029 memcpy(&adap->fe[1]->ops.tuner_ops,
1030 &adap->fe[0]->ops.tuner_ops,
1031 sizeof(struct dvb_tuner_ops));
1032 }
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001033
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001034 return 0;
1035 } else {
1036 /* attach tuner */
1037 fe = dvb_attach(dvb_pll_attach, adap->fe[0],
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001038 (0xc0 >> 1), &d->i2c_adap,
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001039 DVB_PLL_SAMSUNG_DTOS403IH102A);
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001040
1041 if (fe && adap->fe[1]) {
1042 /* attach tuner for 2nd FE */
1043 fe = dvb_attach(dvb_pll_attach, adap->fe[1],
1044 (0xc0 >> 1), &d->i2c_adap,
1045 DVB_PLL_SAMSUNG_DTOS403IH102A);
1046 }
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001047 }
Antti Palosaari41f81f62011-04-10 17:53:52 -03001048
1049 break;
Antti Palosaaria43be982011-04-10 20:23:02 -03001050 case ANYSEE_HW_508TC: /* 18 */
Antti Palosaari8439e0d2011-05-24 07:57:34 -03001051 case ANYSEE_HW_508PTC: /* 21 */
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001052 {
Antti Palosaaria43be982011-04-10 20:23:02 -03001053 /* E7 TC */
Antti Palosaari8439e0d2011-05-24 07:57:34 -03001054 /* E7 PTC */
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001055 struct tda18212_config tda18212_config = anysee_tda18212_config;
Antti Palosaaria43be982011-04-10 20:23:02 -03001056
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001057 tda18212_config.fe = adap->fe[0];
1058 ret = anysee_add_i2c_dev(d, "tda18212", 0x60, &tda18212_config);
1059 if (ret)
1060 goto err;
Antti Palosaaria43be982011-04-10 20:23:02 -03001061
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001062 /* copy tuner ops for 2nd FE as tuner is shared */
1063 if (adap->fe[1]) {
1064 adap->fe[1]->tuner_priv = adap->fe[0]->tuner_priv;
1065 memcpy(&adap->fe[1]->ops.tuner_ops,
1066 &adap->fe[0]->ops.tuner_ops,
1067 sizeof(struct dvb_tuner_ops));
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001068 }
1069
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001070 return 0;
1071 }
Antti Palosaaribedbf3d2011-04-29 13:55:02 -03001072 case ANYSEE_HW_508S2: /* 19 */
Antti Palosaarifea3c392011-05-25 18:21:43 -03001073 case ANYSEE_HW_508PS2: /* 22 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -03001074 /* E7 S2 */
Antti Palosaarifea3c392011-05-25 18:21:43 -03001075 /* E7 PS2 */
Antti Palosaaribedbf3d2011-04-29 13:55:02 -03001076
1077 /* attach tuner */
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001078 fe = dvb_attach(stv6110_attach, adap->fe[0],
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001079 &anysee_stv6110_config, &d->i2c_adap);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -03001080
1081 if (fe) {
1082 /* attach LNB controller */
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001083 fe = dvb_attach(isl6423_attach, adap->fe[0],
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001084 &d->i2c_adap, &anysee_isl6423_config);
Antti Palosaaribedbf3d2011-04-29 13:55:02 -03001085 }
1086
1087 break;
Antti Palosaari608add82011-08-12 18:29:46 -03001088
1089 case ANYSEE_HW_508T2C: /* 20 */
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001090 {
Antti Palosaari608add82011-08-12 18:29:46 -03001091 /* E7 T2C */
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001092 struct tda18212_config tda18212_config =
1093 anysee_tda18212_config2;
Antti Palosaari608add82011-08-12 18:29:46 -03001094
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001095 tda18212_config.fe = adap->fe[0];
1096 ret = anysee_add_i2c_dev(d, "tda18212", 0x60, &tda18212_config);
1097 if (ret)
1098 goto err;
Antti Palosaari608add82011-08-12 18:29:46 -03001099
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001100 return 0;
1101 }
Antti Palosaari41f81f62011-04-10 17:53:52 -03001102 default:
Antti Palosaarie82eea72011-04-12 19:43:30 -03001103 fe = NULL;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001104 }
1105
Antti Palosaarie82eea72011-04-12 19:43:30 -03001106 if (fe)
1107 ret = 0;
1108 else
1109 ret = -ENODEV;
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001110err:
Antti Palosaari41f81f62011-04-10 17:53:52 -03001111 return ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001112}
1113
Antti Palosaari37b44a02013-01-04 15:21:26 -03001114#if IS_ENABLED(CONFIG_RC_CORE)
Antti Palosaaria8494682010-10-17 18:25:10 -03001115static int anysee_rc_query(struct dvb_usb_device *d)
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001116{
1117 u8 buf[] = {CMD_GET_IR_CODE};
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001118 u8 ircode[2];
Antti Palosaaria8494682010-10-17 18:25:10 -03001119 int ret;
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001120
Antti Palosaaria8494682010-10-17 18:25:10 -03001121 /* Remote controller is basic NEC using address byte 0x08.
1122 Anysee device RC query returns only two bytes, status and code,
1123 address byte is dropped. Also it does not return any value for
1124 NEC RCs having address byte other than 0x08. Due to that, we
1125 cannot use that device as standard NEC receiver.
1126 It could be possible make hack which reads whole code directly
1127 from device memory... */
1128
1129 ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode));
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001130 if (ret)
1131 return ret;
1132
Antti Palosaaria8494682010-10-17 18:25:10 -03001133 if (ircode[0]) {
Antti Palosaari82026f92012-08-14 15:56:20 -03001134 dev_dbg(&d->udev->dev, "%s: key pressed %02x\n", __func__,
1135 ircode[1]);
Sean Young6d741bf2017-08-07 16:20:58 -04001136 rc_keydown(d->rc_dev, RC_PROTO_NEC,
David Härdeman120703f2014-04-03 20:31:30 -03001137 RC_SCANCODE_NEC(0x08, ircode[1]), 0);
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001138 }
Antti Palosaaria8494682010-10-17 18:25:10 -03001139
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001140 return 0;
1141}
1142
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001143static int anysee_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
1144{
Sean Young6d741bf2017-08-07 16:20:58 -04001145 rc->allowed_protos = RC_PROTO_BIT_NEC;
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001146 rc->query = anysee_rc_query;
1147 rc->interval = 250; /* windows driver uses 500ms */
1148
1149 return 0;
1150}
Antti Palosaarid5c62092012-12-09 20:12:07 -03001151#else
1152 #define anysee_get_rc_config NULL
1153#endif
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001154
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001155static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1156 int addr)
1157{
1158 struct dvb_usb_device *d = ci->data;
1159 int ret;
1160 u8 buf[] = {CMD_CI, 0x02, 0x40 | addr >> 8, addr & 0xff, 0x00, 1};
1161 u8 val;
1162
1163 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
1164 if (ret)
1165 return ret;
1166
1167 return val;
1168}
1169
1170static int anysee_ci_write_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1171 int addr, u8 val)
1172{
1173 struct dvb_usb_device *d = ci->data;
1174 int ret;
1175 u8 buf[] = {CMD_CI, 0x03, 0x40 | addr >> 8, addr & 0xff, 0x00, 1, val};
1176
1177 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
1178 if (ret)
1179 return ret;
1180
1181 return 0;
1182}
1183
1184static int anysee_ci_read_cam_control(struct dvb_ca_en50221 *ci, int slot,
1185 u8 addr)
1186{
1187 struct dvb_usb_device *d = ci->data;
1188 int ret;
1189 u8 buf[] = {CMD_CI, 0x04, 0x40, addr, 0x00, 1};
1190 u8 val;
1191
1192 ret = anysee_ctrl_msg(d, buf, sizeof(buf), &val, 1);
1193 if (ret)
1194 return ret;
1195
1196 return val;
1197}
1198
1199static int anysee_ci_write_cam_control(struct dvb_ca_en50221 *ci, int slot,
1200 u8 addr, u8 val)
1201{
1202 struct dvb_usb_device *d = ci->data;
1203 int ret;
1204 u8 buf[] = {CMD_CI, 0x05, 0x40, addr, 0x00, 1, val};
1205
1206 ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0);
1207 if (ret)
1208 return ret;
1209
1210 return 0;
1211}
1212
1213static int anysee_ci_slot_reset(struct dvb_ca_en50221 *ci, int slot)
1214{
1215 struct dvb_usb_device *d = ci->data;
1216 int ret;
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001217 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001218
1219 state->ci_cam_ready = jiffies + msecs_to_jiffies(1000);
1220
1221 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
1222 if (ret)
1223 return ret;
1224
1225 msleep(300);
1226
1227 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1228 if (ret)
1229 return ret;
1230
1231 return 0;
1232}
1233
1234static int anysee_ci_slot_shutdown(struct dvb_ca_en50221 *ci, int slot)
1235{
1236 struct dvb_usb_device *d = ci->data;
1237 int ret;
1238
1239 ret = anysee_wr_reg_mask(d, REG_IOA, (0 << 7), 0x80);
1240 if (ret)
1241 return ret;
1242
1243 msleep(30);
1244
1245 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1246 if (ret)
1247 return ret;
1248
1249 return 0;
1250}
1251
1252static int anysee_ci_slot_ts_enable(struct dvb_ca_en50221 *ci, int slot)
1253{
1254 struct dvb_usb_device *d = ci->data;
1255 int ret;
1256
1257 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 1), 0x02);
1258 if (ret)
1259 return ret;
1260
1261 return 0;
1262}
1263
1264static int anysee_ci_poll_slot_status(struct dvb_ca_en50221 *ci, int slot,
1265 int open)
1266{
1267 struct dvb_usb_device *d = ci->data;
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001268 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001269 int ret;
Mauro Carvalho Chehab03ad9fe2012-10-27 16:28:00 -03001270 u8 tmp = 0;
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001271
1272 ret = anysee_rd_reg_mask(d, REG_IOC, &tmp, 0x40);
1273 if (ret)
1274 return ret;
1275
1276 if (tmp == 0) {
1277 ret = DVB_CA_EN50221_POLL_CAM_PRESENT;
1278 if (time_after(jiffies, state->ci_cam_ready))
1279 ret |= DVB_CA_EN50221_POLL_CAM_READY;
1280 }
1281
1282 return ret;
1283}
1284
1285static int anysee_ci_init(struct dvb_usb_device *d)
1286{
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001287 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001288 int ret;
1289
1290 state->ci.owner = THIS_MODULE;
1291 state->ci.read_attribute_mem = anysee_ci_read_attribute_mem;
1292 state->ci.write_attribute_mem = anysee_ci_write_attribute_mem;
1293 state->ci.read_cam_control = anysee_ci_read_cam_control;
1294 state->ci.write_cam_control = anysee_ci_write_cam_control;
1295 state->ci.slot_reset = anysee_ci_slot_reset;
1296 state->ci.slot_shutdown = anysee_ci_slot_shutdown;
1297 state->ci.slot_ts_enable = anysee_ci_slot_ts_enable;
1298 state->ci.poll_slot_status = anysee_ci_poll_slot_status;
1299 state->ci.data = d;
1300
1301 ret = anysee_wr_reg_mask(d, REG_IOA, (1 << 7), 0x80);
1302 if (ret)
1303 return ret;
1304
Antti Palosaari46de20a2012-01-20 17:39:17 -03001305 ret = anysee_wr_reg_mask(d, REG_IOD, (0 << 2)|(0 << 1)|(0 << 0), 0x07);
1306 if (ret)
1307 return ret;
1308
1309 ret = anysee_wr_reg_mask(d, REG_IOD, (1 << 2)|(1 << 1)|(1 << 0), 0x07);
1310 if (ret)
1311 return ret;
1312
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001313 ret = dvb_ca_en50221_init(&d->adapter[0].dvb_adap, &state->ci, 0, 1);
1314 if (ret)
1315 return ret;
1316
Antti Palosaarif6068762012-09-22 13:46:24 -03001317 state->ci_attached = true;
1318
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001319 return 0;
1320}
1321
1322static void anysee_ci_release(struct dvb_usb_device *d)
1323{
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001324 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001325
1326 /* detach CI */
Antti Palosaarif6068762012-09-22 13:46:24 -03001327 if (state->ci_attached)
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001328 dvb_ca_en50221_release(&state->ci);
1329
1330 return;
1331}
1332
1333static int anysee_init(struct dvb_usb_device *d)
1334{
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001335 struct anysee_state *state = d_to_priv(d);
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001336 int ret;
1337
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001338 /* There is one interface with two alternate settings.
1339 Alternate setting 0 is for bulk transfer.
1340 Alternate setting 1 is for isochronous transfer.
1341 We use bulk transfer (alternate setting 0). */
1342 ret = usb_set_interface(d->udev, 0, 0);
1343 if (ret)
1344 return ret;
1345
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001346 /* LED light */
1347 ret = anysee_led_ctrl(d, 0x01, 0x03);
1348 if (ret)
1349 return ret;
1350
1351 /* enable IR */
1352 ret = anysee_ir_ctrl(d, 1);
1353 if (ret)
1354 return ret;
1355
1356 /* attach CI */
1357 if (state->has_ci) {
1358 ret = anysee_ci_init(d);
Antti Palosaarif6068762012-09-22 13:46:24 -03001359 if (ret)
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001360 return ret;
Antti Palosaari05cd37d2011-09-05 23:33:04 -03001361 }
1362
1363 return 0;
1364}
1365
Antti Palosaari831511b2012-06-20 00:32:53 -03001366static void anysee_exit(struct dvb_usb_device *d)
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001367{
Antti Palosaarif80f2ae2014-08-03 21:47:10 -03001368 struct anysee_state *state = d_to_priv(d);
1369
1370 if (state->i2c_client[0])
1371 anysee_del_i2c_dev(d);
1372
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001373 return anysee_ci_release(d);
1374}
1375
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001376/* DVB USB Driver stuff */
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001377static struct dvb_usb_device_properties anysee_props = {
1378 .driver_name = KBUILD_MODNAME,
1379 .owner = THIS_MODULE,
1380 .adapter_nr = adapter_nr,
1381 .size_of_priv = sizeof(struct anysee_state),
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001382
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001383 .generic_bulk_ctrl_endpoint = 0x01,
1384 .generic_bulk_ctrl_endpoint_response = 0x81,
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001385
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001386 .i2c_algo = &anysee_i2c_algo,
1387 .read_config = anysee_read_config,
1388 .frontend_attach = anysee_frontend_attach,
1389 .tuner_attach = anysee_tuner_attach,
1390 .init = anysee_init,
1391 .get_rc_config = anysee_get_rc_config,
1392 .frontend_ctrl = anysee_frontend_ctrl,
1393 .streaming_ctrl = anysee_streaming_ctrl,
Antti Palosaari831511b2012-06-20 00:32:53 -03001394 .exit = anysee_exit,
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001395
1396 .num_adapters = 1,
1397 .adapter = {
1398 {
Antti Palosaari05cd62e2012-06-18 19:39:02 -03001399 .stream = DVB_USB_STREAM_BULK(0x82, 8, 16 * 512),
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001400 }
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001401 }
1402};
1403
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001404static const struct usb_device_id anysee_id_table[] = {
1405 { DVB_USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE,
1406 &anysee_props, "Anysee", RC_MAP_ANYSEE) },
1407 { DVB_USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE,
1408 &anysee_props, "Anysee", RC_MAP_ANYSEE) },
1409 { }
1410};
1411MODULE_DEVICE_TABLE(usb, anysee_id_table);
1412
1413static struct usb_driver anysee_usb_driver = {
1414 .name = KBUILD_MODNAME,
1415 .id_table = anysee_id_table,
1416 .probe = dvb_usbv2_probe,
1417 .disconnect = dvb_usbv2_disconnect,
1418 .suspend = dvb_usbv2_suspend,
1419 .resume = dvb_usbv2_resume,
Antti Palosaari04966aa2012-08-14 22:21:08 -03001420 .reset_resume = dvb_usbv2_reset_resume,
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001421 .no_dynamic_id = 1,
1422 .soft_unbind = 1,
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001423};
1424
Antti Palosaaria4e7c512012-06-14 04:56:09 -03001425module_usb_driver(anysee_usb_driver);
Antti Palosaaria51e34d2008-05-17 23:05:48 -03001426
1427MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1428MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0");
1429MODULE_LICENSE("GPL");