Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 1 | /* |
| 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 Palosaari | 9fdd9ca | 2008-06-11 11:43:19 -0300 | [diff] [blame] | 26 | * for ISO 7816 card reader, like dvb_ca_en50221 is implemented. This |
| 27 | * module registers serial interface that can be used to communicate |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 28 | * with any ISO 7816 smart card. |
| 29 | * |
| 30 | * Any help according to implement serial smart card reader support |
| 31 | * is highly welcome! |
| 32 | */ |
| 33 | |
| 34 | #include "anysee.h" |
| 35 | #include "tda1002x.h" |
| 36 | #include "mt352.h" |
| 37 | #include "mt352_priv.h" |
| 38 | #include "zl10353.h" |
| 39 | |
| 40 | /* debug */ |
| 41 | static int dvb_usb_anysee_debug; |
| 42 | module_param_named(debug, dvb_usb_anysee_debug, int, 0644); |
| 43 | MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS); |
Mauro Carvalho Chehab | ffbc5f8 | 2009-01-05 01:34:20 -0300 | [diff] [blame] | 44 | static int dvb_usb_anysee_delsys; |
Antti Palosaari | 0f77c3a | 2008-08-11 10:54:16 -0300 | [diff] [blame] | 45 | module_param_named(delsys, dvb_usb_anysee_delsys, int, 0644); |
| 46 | MODULE_PARM_DESC(delsys, "select delivery mode (0=DVB-C, 1=DVB-T)"); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 47 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 48 | |
Akinobu Mita | dec0c46 | 2008-10-29 21:16:04 -0300 | [diff] [blame] | 49 | static DEFINE_MUTEX(anysee_usb_mutex); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 50 | |
| 51 | static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen, |
| 52 | u8 *rbuf, u8 rlen) |
| 53 | { |
| 54 | struct anysee_state *state = d->priv; |
| 55 | int act_len, ret; |
| 56 | u8 buf[64]; |
| 57 | |
| 58 | if (slen > sizeof(buf)) |
| 59 | slen = sizeof(buf); |
| 60 | memcpy(&buf[0], sbuf, slen); |
| 61 | buf[60] = state->seq++; |
| 62 | |
| 63 | if (mutex_lock_interruptible(&anysee_usb_mutex) < 0) |
| 64 | return -EAGAIN; |
| 65 | |
| 66 | /* We need receive one message more after dvb_usb_generic_rw due |
| 67 | to weird transaction flow, which is 1 x send + 2 x receive. */ |
| 68 | ret = dvb_usb_generic_rw(d, buf, sizeof(buf), buf, sizeof(buf), 0); |
| 69 | |
| 70 | if (!ret) { |
| 71 | /* receive 2nd answer */ |
| 72 | ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev, |
| 73 | d->props.generic_bulk_ctrl_endpoint), buf, sizeof(buf), |
| 74 | &act_len, 2000); |
| 75 | if (ret) |
| 76 | err("%s: recv bulk message failed: %d", __func__, ret); |
| 77 | else { |
| 78 | deb_xfer("<<< "); |
| 79 | debug_dump(buf, act_len, deb_xfer); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /* read request, copy returned data to return buf */ |
| 84 | if (!ret && rbuf && rlen) |
| 85 | memcpy(rbuf, buf, rlen); |
| 86 | |
| 87 | mutex_unlock(&anysee_usb_mutex); |
| 88 | |
| 89 | return ret; |
| 90 | } |
| 91 | |
| 92 | static int anysee_read_reg(struct dvb_usb_device *d, u16 reg, u8 *val) |
| 93 | { |
| 94 | u8 buf[] = {CMD_REG_READ, reg >> 8, reg & 0xff, 0x01}; |
| 95 | int ret; |
| 96 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), val, 1); |
| 97 | deb_info("%s: reg:%04x val:%02x\n", __func__, reg, *val); |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | static int anysee_write_reg(struct dvb_usb_device *d, u16 reg, u8 val) |
| 102 | { |
| 103 | u8 buf[] = {CMD_REG_WRITE, reg >> 8, reg & 0xff, 0x01, val}; |
| 104 | deb_info("%s: reg:%04x val:%02x\n", __func__, reg, val); |
| 105 | return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); |
| 106 | } |
| 107 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 108 | /* write single register with mask */ |
| 109 | static int anysee_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val, |
| 110 | u8 mask) |
| 111 | { |
| 112 | int ret; |
| 113 | u8 tmp; |
| 114 | |
| 115 | /* no need for read if whole reg is written */ |
| 116 | if (mask != 0xff) { |
| 117 | ret = anysee_read_reg(d, reg, &tmp); |
| 118 | if (ret) |
| 119 | return ret; |
| 120 | |
| 121 | val &= mask; |
| 122 | tmp &= ~mask; |
| 123 | val |= tmp; |
| 124 | } |
| 125 | |
| 126 | return anysee_write_reg(d, reg, val); |
| 127 | } |
| 128 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 129 | static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id) |
| 130 | { |
| 131 | u8 buf[] = {CMD_GET_HW_INFO}; |
| 132 | return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3); |
| 133 | } |
| 134 | |
| 135 | static int anysee_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 136 | { |
| 137 | u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00}; |
| 138 | deb_info("%s: onoff:%02x\n", __func__, onoff); |
| 139 | return anysee_ctrl_msg(adap->dev, buf, sizeof(buf), NULL, 0); |
| 140 | } |
| 141 | |
| 142 | static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval) |
| 143 | { |
| 144 | u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval}; |
| 145 | deb_info("%s: state:%02x interval:%02x\n", __func__, mode, interval); |
| 146 | return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); |
| 147 | } |
| 148 | |
| 149 | static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff) |
| 150 | { |
| 151 | u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff}; |
| 152 | deb_info("%s: onoff:%02x\n", __func__, onoff); |
| 153 | return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); |
| 154 | } |
| 155 | |
| 156 | static int anysee_init(struct dvb_usb_device *d) |
| 157 | { |
| 158 | int ret; |
| 159 | /* LED light */ |
| 160 | ret = anysee_led_ctrl(d, 0x01, 0x03); |
| 161 | if (ret) |
| 162 | return ret; |
| 163 | |
| 164 | /* enable IR */ |
| 165 | ret = anysee_ir_ctrl(d, 1); |
| 166 | if (ret) |
| 167 | return ret; |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | /* I2C */ |
| 173 | static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, |
| 174 | int num) |
| 175 | { |
| 176 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
Mauro Carvalho Chehab | 902571a | 2008-12-29 19:02:24 -0300 | [diff] [blame] | 177 | int ret = 0, inc, i = 0; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 178 | |
| 179 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 180 | return -EAGAIN; |
| 181 | |
| 182 | while (i < num) { |
| 183 | if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) { |
| 184 | u8 buf[6]; |
| 185 | buf[0] = CMD_I2C_READ; |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame] | 186 | buf[1] = (msg[i].addr << 1) | 0x01; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 187 | buf[2] = msg[i].buf[0]; |
| 188 | buf[3] = 0x00; |
| 189 | buf[4] = 0x00; |
Antti Palosaari | b3e6a5a | 2011-04-09 21:00:51 -0300 | [diff] [blame] | 190 | buf[5] = msg[i+1].len; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 191 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), msg[i+1].buf, |
| 192 | msg[i+1].len); |
| 193 | inc = 2; |
| 194 | } else { |
| 195 | u8 buf[4+msg[i].len]; |
| 196 | buf[0] = CMD_I2C_WRITE; |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame] | 197 | buf[1] = (msg[i].addr << 1); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 198 | buf[2] = msg[i].len; |
| 199 | buf[3] = 0x01; |
| 200 | memcpy(&buf[4], msg[i].buf, msg[i].len); |
| 201 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); |
| 202 | inc = 1; |
| 203 | } |
| 204 | if (ret) |
Antti Palosaari | e613f8f | 2008-08-11 10:36:43 -0300 | [diff] [blame] | 205 | break; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 206 | |
| 207 | i += inc; |
| 208 | } |
| 209 | |
| 210 | mutex_unlock(&d->i2c_mutex); |
| 211 | |
Antti Palosaari | e613f8f | 2008-08-11 10:36:43 -0300 | [diff] [blame] | 212 | return ret ? ret : i; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | static u32 anysee_i2c_func(struct i2c_adapter *adapter) |
| 216 | { |
| 217 | return I2C_FUNC_I2C; |
| 218 | } |
| 219 | |
| 220 | static struct i2c_algorithm anysee_i2c_algo = { |
| 221 | .master_xfer = anysee_master_xfer, |
| 222 | .functionality = anysee_i2c_func, |
| 223 | }; |
| 224 | |
| 225 | static int anysee_mt352_demod_init(struct dvb_frontend *fe) |
| 226 | { |
Antti Palosaari | ae3745f | 2009-09-16 19:50:25 -0300 | [diff] [blame] | 227 | static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 }; |
| 228 | static u8 reset[] = { RESET, 0x80 }; |
| 229 | static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 }; |
| 230 | static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 }; |
| 231 | static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 }; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 232 | static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 }; |
| 233 | |
| 234 | mt352_write(fe, clock_config, sizeof(clock_config)); |
| 235 | udelay(200); |
| 236 | mt352_write(fe, reset, sizeof(reset)); |
| 237 | mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg)); |
| 238 | |
| 239 | mt352_write(fe, agc_cfg, sizeof(agc_cfg)); |
| 240 | mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg)); |
| 241 | mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg)); |
| 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | /* Callbacks for DVB USB */ |
| 247 | static struct tda10023_config anysee_tda10023_config = { |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame] | 248 | .demod_address = (0x1a >> 1), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 249 | .invert = 0, |
| 250 | .xtal = 16000000, |
| 251 | .pll_m = 11, |
| 252 | .pll_p = 3, |
| 253 | .pll_n = 1, |
Antti Palosaari | 5ae2fca | 2008-06-09 22:58:22 -0300 | [diff] [blame] | 254 | .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C, |
| 255 | .deltaf = 0xfeeb, |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 256 | }; |
| 257 | |
| 258 | static struct mt352_config anysee_mt352_config = { |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame] | 259 | .demod_address = (0x1e >> 1), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 260 | .demod_init = anysee_mt352_demod_init, |
| 261 | }; |
| 262 | |
| 263 | static struct zl10353_config anysee_zl10353_config = { |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame] | 264 | .demod_address = (0x1e >> 1), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 265 | .parallel_ts = 1, |
| 266 | }; |
| 267 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 268 | /* |
| 269 | * New USB device strings: Mfr=1, Product=2, SerialNumber=0 |
| 270 | * Manufacturer: AMT.CO.KR |
| 271 | * |
| 272 | * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=???????? |
| 273 | * PCB: ? |
| 274 | * parts: MT352, DTT7579(?), DNOS404ZH102A NIM |
| 275 | * |
| 276 | * E30 VID=04b4 PID=861f HW=2 FW=2.1 Product=???????? |
| 277 | * PCB: ? |
| 278 | * parts: ZL10353, DTT7579(?), DNOS404ZH103A NIM |
| 279 | * |
| 280 | * E30 Plus VID=04b4 PID=861f HW=6 FW=1.0 "anysee" |
| 281 | * PCB: 507CD (rev1.1) |
| 282 | * parts: ZL10353, DTT7579(?), CST56I01, DNOS404ZH103A NIM |
| 283 | * OEA=80 OEB=00 OEC=00 OED=ff OEF=fe |
| 284 | * IOD[0] ZL10353 1=enabled |
| 285 | * IOA[7] TS 0=enabled |
| 286 | * tuner is not behind ZL10353 I2C-gate (no care if gate disabled or not) |
| 287 | * |
| 288 | * E30 C Plus VID=04b4 PID=861f HW=10 FW=1.0 "anysee-DC(LP)" |
| 289 | * PCB: 507DC (rev0.2) |
| 290 | * parts: TDA10023, CST56I01, DTOS403IH102B TM |
| 291 | * OEA=80 OEB=00 OEC=00 OED=ff OEF=fe |
| 292 | * IOD[0] TDA10023 1=enabled |
| 293 | * |
| 294 | * E30 C Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)" |
| 295 | * PCB: 507FA (rev0.4) |
| 296 | * parts: TDA10023, TDA8024, DTOS403IH102B TM |
| 297 | * OEA=80 OEB=00 OEC=ff OED=ff OEF=ff |
| 298 | * IOD[5] TDA10023 1=enabled |
| 299 | * IOE[0] tuner 1=enabled |
| 300 | * |
| 301 | * E30 Combo Plus VID=1c73 PID=861f HW=15 FW=1.2 "anysee-FA(LP)" |
| 302 | * PCB: 507FA (rev1.1) |
| 303 | * parts: ZL10353, TDA10023, TDA8024, DTOS403IH102B TM |
| 304 | * OEA=80 OEB=00 OEC=ff OED=ff OEF=ff |
| 305 | * DVB-C: |
| 306 | * IOD[5] TDA10023 1=enabled |
| 307 | * IOE[0] tuner 1=enabled |
| 308 | * DVB-T: |
| 309 | * IOD[0] ZL10353 1=enabled |
| 310 | * IOE[0] tuner 0=enabled |
| 311 | * tuner is behind ZL10353 I2C-gate |
| 312 | */ |
| 313 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 314 | static int anysee_frontend_attach(struct dvb_usb_adapter *adap) |
| 315 | { |
| 316 | int ret; |
| 317 | struct anysee_state *state = adap->dev->priv; |
| 318 | u8 hw_info[3]; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 319 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 320 | /* Check which hardware we have. |
| 321 | * We must do this call two times to get reliable values (hw bug). |
| 322 | */ |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 323 | ret = anysee_get_hw_info(adap->dev, hw_info); |
| 324 | if (ret) |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 325 | goto error; |
| 326 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 327 | ret = anysee_get_hw_info(adap->dev, hw_info); |
| 328 | if (ret) |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 329 | goto error; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 330 | |
| 331 | /* Meaning of these info bytes are guessed. */ |
Antti Palosaari | 592d9e2 | 2011-04-09 21:13:33 -0300 | [diff] [blame] | 332 | info("firmware version:%d.%d hardware id:%d", |
| 333 | hw_info[1], hw_info[2], hw_info[0]); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 334 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 335 | state->hw = hw_info[0]; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 336 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 337 | switch (state->hw) { |
| 338 | case ANYSEE_HW_02: /* 2 */ |
| 339 | /* E30 */ |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 340 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 341 | /* attach demod */ |
| 342 | adap->fe = dvb_attach(mt352_attach, &anysee_mt352_config, |
| 343 | &adap->dev->i2c_adap); |
| 344 | if (adap->fe) |
| 345 | break; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 346 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 347 | /* attach demod */ |
Antti Palosaari | 0f77c3a | 2008-08-11 10:54:16 -0300 | [diff] [blame] | 348 | adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config, |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 349 | &adap->dev->i2c_adap); |
| 350 | if (adap->fe) |
| 351 | break; |
| 352 | |
| 353 | break; |
| 354 | case ANYSEE_HW_507CD: /* 6 */ |
| 355 | /* E30 Plus */ |
| 356 | |
| 357 | /* enable DVB-T demod on IOD[0] */ |
| 358 | ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01); |
| 359 | if (ret) |
| 360 | goto error; |
| 361 | |
| 362 | /* enable transport stream on IOA[7] */ |
| 363 | ret = anysee_wr_reg_mask(adap->dev, REG_IOA, (0 << 7), 0x80); |
| 364 | if (ret) |
| 365 | goto error; |
| 366 | |
| 367 | /* attach demod */ |
| 368 | adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config, |
| 369 | &adap->dev->i2c_adap); |
| 370 | if (adap->fe) |
| 371 | break; |
| 372 | |
| 373 | break; |
| 374 | case ANYSEE_HW_507DC: /* 10 */ |
| 375 | /* E30 C Plus */ |
| 376 | |
| 377 | /* enable DVB-C demod on IOD[0] */ |
| 378 | ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), 0x01); |
| 379 | if (ret) |
| 380 | goto error; |
| 381 | |
| 382 | /* attach demod */ |
| 383 | adap->fe = dvb_attach(tda10023_attach, &anysee_tda10023_config, |
| 384 | &adap->dev->i2c_adap, 0x48); |
| 385 | if (adap->fe) |
| 386 | break; |
| 387 | |
| 388 | break; |
| 389 | case ANYSEE_HW_507FA: /* 15 */ |
| 390 | /* E30 Combo Plus */ |
| 391 | /* E30 C Plus */ |
| 392 | |
| 393 | if (dvb_usb_anysee_delsys) { |
| 394 | /* disable DVB-C demod on IOD[5] */ |
| 395 | ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 5), |
| 396 | 0x20); |
| 397 | if (ret) |
| 398 | goto error; |
| 399 | |
| 400 | /* enable DVB-T demod on IOD[0] */ |
| 401 | ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 0), |
| 402 | 0x01); |
| 403 | if (ret) |
| 404 | goto error; |
| 405 | |
| 406 | /* attach demod */ |
| 407 | adap->fe = dvb_attach(zl10353_attach, |
| 408 | &anysee_zl10353_config, &adap->dev->i2c_adap); |
| 409 | if (adap->fe) |
| 410 | break; |
| 411 | } else { |
| 412 | /* disable DVB-T demod on IOD[0] */ |
| 413 | ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (0 << 0), |
| 414 | 0x01); |
| 415 | if (ret) |
| 416 | goto error; |
| 417 | |
| 418 | /* enable DVB-C demod on IOD[5] */ |
| 419 | ret = anysee_wr_reg_mask(adap->dev, REG_IOD, (1 << 5), |
| 420 | 0x20); |
| 421 | if (ret) |
| 422 | goto error; |
| 423 | |
| 424 | /* attach demod */ |
| 425 | adap->fe = dvb_attach(tda10023_attach, |
| 426 | &anysee_tda10023_config, &adap->dev->i2c_adap, |
| 427 | 0x48); |
| 428 | if (adap->fe) |
| 429 | break; |
Antti Palosaari | 0f77c3a | 2008-08-11 10:54:16 -0300 | [diff] [blame] | 430 | } |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 431 | break; |
Antti Palosaari | 0f77c3a | 2008-08-11 10:54:16 -0300 | [diff] [blame] | 432 | } |
| 433 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 434 | if (!adap->fe) { |
| 435 | /* we have no frontend :-( */ |
| 436 | ret = -ENODEV; |
| 437 | err("Unknown Anysee version: %02x %02x %02x. " \ |
| 438 | "Please report the <linux-media@vger.kernel.org>.", |
| 439 | hw_info[0], hw_info[1], hw_info[2]); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 440 | } |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 441 | error: |
| 442 | return ret; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static int anysee_tuner_attach(struct dvb_usb_adapter *adap) |
| 446 | { |
| 447 | struct anysee_state *state = adap->dev->priv; |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 448 | int ret = 0; |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 449 | deb_info("%s:\n", __func__); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 450 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 451 | switch (state->hw) { |
| 452 | case ANYSEE_HW_02: /* 2 */ |
| 453 | /* E30 */ |
| 454 | |
| 455 | /* attach tuner */ |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame] | 456 | dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1), |
| 457 | NULL, DVB_PLL_THOMSON_DTT7579); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 458 | break; |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 459 | case ANYSEE_HW_507CD: /* 6 */ |
| 460 | /* E30 Plus */ |
| 461 | |
| 462 | /* attach tuner */ |
| 463 | dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1), |
| 464 | &adap->dev->i2c_adap, DVB_PLL_THOMSON_DTT7579); |
| 465 | |
| 466 | break; |
| 467 | case ANYSEE_HW_507DC: /* 10 */ |
| 468 | /* E30 C Plus */ |
| 469 | |
| 470 | /* attach tuner */ |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame] | 471 | dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1), |
| 472 | &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 473 | break; |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 474 | case ANYSEE_HW_507FA: /* 15 */ |
| 475 | /* E30 Combo Plus */ |
| 476 | /* E30 C Plus */ |
| 477 | |
| 478 | if (dvb_usb_anysee_delsys) { |
| 479 | /* enable DVB-T tuner on IOE[0] */ |
| 480 | ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (0 << 0), |
| 481 | 0x01); |
| 482 | if (ret) |
| 483 | goto error; |
| 484 | } else { |
| 485 | /* enable DVB-C tuner on IOE[0] */ |
| 486 | ret = anysee_wr_reg_mask(adap->dev, REG_IOE, (1 << 0), |
| 487 | 0x01); |
| 488 | if (ret) |
| 489 | goto error; |
| 490 | } |
| 491 | |
| 492 | /* attach tuner */ |
| 493 | dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1), |
| 494 | &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A); |
| 495 | |
| 496 | break; |
| 497 | default: |
| 498 | ret = -ENODEV; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 499 | } |
| 500 | |
Antti Palosaari | 41f81f6 | 2011-04-10 17:53:52 -0300 | [diff] [blame^] | 501 | error: |
| 502 | return ret; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 503 | } |
| 504 | |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 505 | static int anysee_rc_query(struct dvb_usb_device *d) |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 506 | { |
| 507 | u8 buf[] = {CMD_GET_IR_CODE}; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 508 | u8 ircode[2]; |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 509 | int ret; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 510 | |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 511 | /* Remote controller is basic NEC using address byte 0x08. |
| 512 | Anysee device RC query returns only two bytes, status and code, |
| 513 | address byte is dropped. Also it does not return any value for |
| 514 | NEC RCs having address byte other than 0x08. Due to that, we |
| 515 | cannot use that device as standard NEC receiver. |
| 516 | It could be possible make hack which reads whole code directly |
| 517 | from device memory... */ |
| 518 | |
| 519 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode)); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 520 | if (ret) |
| 521 | return ret; |
| 522 | |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 523 | if (ircode[0]) { |
| 524 | deb_rc("%s: key pressed %02x\n", __func__, ircode[1]); |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 525 | rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 526 | } |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 527 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 528 | return 0; |
| 529 | } |
| 530 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 531 | /* DVB USB Driver stuff */ |
| 532 | static struct dvb_usb_device_properties anysee_properties; |
| 533 | |
| 534 | static int anysee_probe(struct usb_interface *intf, |
| 535 | const struct usb_device_id *id) |
| 536 | { |
| 537 | struct dvb_usb_device *d; |
| 538 | struct usb_host_interface *alt; |
| 539 | int ret; |
| 540 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 541 | /* There is one interface with two alternate settings. |
| 542 | Alternate setting 0 is for bulk transfer. |
| 543 | Alternate setting 1 is for isochronous transfer. |
| 544 | We use bulk transfer (alternate setting 0). */ |
| 545 | if (intf->num_altsetting < 1) |
| 546 | return -ENODEV; |
| 547 | |
Dan Carpenter | 8b0d704 | 2010-05-31 16:27:39 -0300 | [diff] [blame] | 548 | /* |
| 549 | * Anysee is always warm (its USB-bridge, Cypress FX2, uploads |
| 550 | * firmware from eeprom). If dvb_usb_device_init() succeeds that |
| 551 | * means d is a valid pointer. |
| 552 | */ |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 553 | ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d, |
| 554 | adapter_nr); |
| 555 | if (ret) |
| 556 | return ret; |
| 557 | |
| 558 | alt = usb_altnum_to_altsetting(intf, 0); |
| 559 | if (alt == NULL) { |
| 560 | deb_info("%s: no alt found!\n", __func__); |
| 561 | return -ENODEV; |
| 562 | } |
| 563 | |
| 564 | ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber, |
| 565 | alt->desc.bAlternateSetting); |
| 566 | if (ret) |
| 567 | return ret; |
| 568 | |
Dan Carpenter | 8b0d704 | 2010-05-31 16:27:39 -0300 | [diff] [blame] | 569 | return anysee_init(d); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 570 | } |
| 571 | |
Antti Palosaari | ae3745f | 2009-09-16 19:50:25 -0300 | [diff] [blame] | 572 | static struct usb_device_id anysee_table[] = { |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 573 | { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) }, |
| 574 | { USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) }, |
| 575 | { } /* Terminating entry */ |
| 576 | }; |
| 577 | MODULE_DEVICE_TABLE(usb, anysee_table); |
| 578 | |
| 579 | static struct dvb_usb_device_properties anysee_properties = { |
| 580 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 581 | |
| 582 | .usb_ctrl = DEVICE_SPECIFIC, |
| 583 | |
| 584 | .size_of_priv = sizeof(struct anysee_state), |
| 585 | |
| 586 | .num_adapters = 1, |
| 587 | .adapter = { |
| 588 | { |
| 589 | .streaming_ctrl = anysee_streaming_ctrl, |
| 590 | .frontend_attach = anysee_frontend_attach, |
| 591 | .tuner_attach = anysee_tuner_attach, |
| 592 | .stream = { |
| 593 | .type = USB_BULK, |
| 594 | .count = 8, |
| 595 | .endpoint = 0x82, |
| 596 | .u = { |
| 597 | .bulk = { |
Antti Palosaari | ab69333 | 2009-09-16 19:47:01 -0300 | [diff] [blame] | 598 | .buffersize = (16*512), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | }, |
| 602 | } |
| 603 | }, |
| 604 | |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 605 | .rc.core = { |
| 606 | .rc_codes = RC_MAP_ANYSEE, |
Mauro Carvalho Chehab | 52b6614 | 2010-11-17 14:20:52 -0300 | [diff] [blame] | 607 | .protocol = RC_TYPE_OTHER, |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 608 | .module_name = "anysee", |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 609 | .rc_query = anysee_rc_query, |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 610 | .rc_interval = 250, /* windows driver uses 500ms */ |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 611 | }, |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 612 | |
| 613 | .i2c_algo = &anysee_i2c_algo, |
| 614 | |
| 615 | .generic_bulk_ctrl_endpoint = 1, |
| 616 | |
| 617 | .num_device_descs = 1, |
| 618 | .devices = { |
| 619 | { |
| 620 | .name = "Anysee DVB USB2.0", |
| 621 | .cold_ids = {NULL}, |
| 622 | .warm_ids = {&anysee_table[0], |
| 623 | &anysee_table[1], NULL}, |
| 624 | }, |
| 625 | } |
| 626 | }; |
| 627 | |
| 628 | static struct usb_driver anysee_driver = { |
| 629 | .name = "dvb_usb_anysee", |
| 630 | .probe = anysee_probe, |
| 631 | .disconnect = dvb_usb_device_exit, |
| 632 | .id_table = anysee_table, |
| 633 | }; |
| 634 | |
| 635 | /* module stuff */ |
| 636 | static int __init anysee_module_init(void) |
| 637 | { |
| 638 | int ret; |
| 639 | |
| 640 | ret = usb_register(&anysee_driver); |
| 641 | if (ret) |
| 642 | err("%s: usb_register failed. Error number %d", __func__, ret); |
| 643 | |
| 644 | return ret; |
| 645 | } |
| 646 | |
| 647 | static void __exit anysee_module_exit(void) |
| 648 | { |
| 649 | /* deregister this driver from the USB subsystem */ |
| 650 | usb_deregister(&anysee_driver); |
| 651 | } |
| 652 | |
| 653 | module_init(anysee_module_init); |
| 654 | module_exit(anysee_module_exit); |
| 655 | |
| 656 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 657 | MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0"); |
| 658 | MODULE_LICENSE("GPL"); |