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 | |
| 108 | static int anysee_get_hw_info(struct dvb_usb_device *d, u8 *id) |
| 109 | { |
| 110 | u8 buf[] = {CMD_GET_HW_INFO}; |
| 111 | return anysee_ctrl_msg(d, buf, sizeof(buf), id, 3); |
| 112 | } |
| 113 | |
| 114 | static int anysee_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 115 | { |
| 116 | u8 buf[] = {CMD_STREAMING_CTRL, (u8)onoff, 0x00}; |
| 117 | deb_info("%s: onoff:%02x\n", __func__, onoff); |
| 118 | return anysee_ctrl_msg(adap->dev, buf, sizeof(buf), NULL, 0); |
| 119 | } |
| 120 | |
| 121 | static int anysee_led_ctrl(struct dvb_usb_device *d, u8 mode, u8 interval) |
| 122 | { |
| 123 | u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x01, mode, interval}; |
| 124 | deb_info("%s: state:%02x interval:%02x\n", __func__, mode, interval); |
| 125 | return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); |
| 126 | } |
| 127 | |
| 128 | static int anysee_ir_ctrl(struct dvb_usb_device *d, u8 onoff) |
| 129 | { |
| 130 | u8 buf[] = {CMD_LED_AND_IR_CTRL, 0x02, onoff}; |
| 131 | deb_info("%s: onoff:%02x\n", __func__, onoff); |
| 132 | return anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); |
| 133 | } |
| 134 | |
| 135 | static int anysee_init(struct dvb_usb_device *d) |
| 136 | { |
| 137 | int ret; |
| 138 | /* LED light */ |
| 139 | ret = anysee_led_ctrl(d, 0x01, 0x03); |
| 140 | if (ret) |
| 141 | return ret; |
| 142 | |
| 143 | /* enable IR */ |
| 144 | ret = anysee_ir_ctrl(d, 1); |
| 145 | if (ret) |
| 146 | return ret; |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | /* I2C */ |
| 152 | static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, |
| 153 | int num) |
| 154 | { |
| 155 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
Mauro Carvalho Chehab | 902571a | 2008-12-29 19:02:24 -0300 | [diff] [blame] | 156 | int ret = 0, inc, i = 0; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 157 | |
| 158 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 159 | return -EAGAIN; |
| 160 | |
| 161 | while (i < num) { |
| 162 | if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) { |
| 163 | u8 buf[6]; |
| 164 | buf[0] = CMD_I2C_READ; |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame^] | 165 | buf[1] = (msg[i].addr << 1) | 0x01; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 166 | buf[2] = msg[i].buf[0]; |
| 167 | buf[3] = 0x00; |
| 168 | buf[4] = 0x00; |
| 169 | buf[5] = 0x01; |
| 170 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), msg[i+1].buf, |
| 171 | msg[i+1].len); |
| 172 | inc = 2; |
| 173 | } else { |
| 174 | u8 buf[4+msg[i].len]; |
| 175 | buf[0] = CMD_I2C_WRITE; |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame^] | 176 | buf[1] = (msg[i].addr << 1); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 177 | buf[2] = msg[i].len; |
| 178 | buf[3] = 0x01; |
| 179 | memcpy(&buf[4], msg[i].buf, msg[i].len); |
| 180 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), NULL, 0); |
| 181 | inc = 1; |
| 182 | } |
| 183 | if (ret) |
Antti Palosaari | e613f8f | 2008-08-11 10:36:43 -0300 | [diff] [blame] | 184 | break; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 185 | |
| 186 | i += inc; |
| 187 | } |
| 188 | |
| 189 | mutex_unlock(&d->i2c_mutex); |
| 190 | |
Antti Palosaari | e613f8f | 2008-08-11 10:36:43 -0300 | [diff] [blame] | 191 | return ret ? ret : i; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static u32 anysee_i2c_func(struct i2c_adapter *adapter) |
| 195 | { |
| 196 | return I2C_FUNC_I2C; |
| 197 | } |
| 198 | |
| 199 | static struct i2c_algorithm anysee_i2c_algo = { |
| 200 | .master_xfer = anysee_master_xfer, |
| 201 | .functionality = anysee_i2c_func, |
| 202 | }; |
| 203 | |
| 204 | static int anysee_mt352_demod_init(struct dvb_frontend *fe) |
| 205 | { |
Antti Palosaari | ae3745f | 2009-09-16 19:50:25 -0300 | [diff] [blame] | 206 | static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x28 }; |
| 207 | static u8 reset[] = { RESET, 0x80 }; |
| 208 | static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 }; |
| 209 | static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0x20 }; |
| 210 | static u8 gpp_ctl_cfg[] = { GPP_CTL, 0x33 }; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 211 | static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 }; |
| 212 | |
| 213 | mt352_write(fe, clock_config, sizeof(clock_config)); |
| 214 | udelay(200); |
| 215 | mt352_write(fe, reset, sizeof(reset)); |
| 216 | mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg)); |
| 217 | |
| 218 | mt352_write(fe, agc_cfg, sizeof(agc_cfg)); |
| 219 | mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg)); |
| 220 | mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg)); |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | /* Callbacks for DVB USB */ |
| 226 | static struct tda10023_config anysee_tda10023_config = { |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame^] | 227 | .demod_address = (0x1a >> 1), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 228 | .invert = 0, |
| 229 | .xtal = 16000000, |
| 230 | .pll_m = 11, |
| 231 | .pll_p = 3, |
| 232 | .pll_n = 1, |
Antti Palosaari | 5ae2fca | 2008-06-09 22:58:22 -0300 | [diff] [blame] | 233 | .output_mode = TDA10023_OUTPUT_MODE_PARALLEL_C, |
| 234 | .deltaf = 0xfeeb, |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | static struct mt352_config anysee_mt352_config = { |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame^] | 238 | .demod_address = (0x1e >> 1), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 239 | .demod_init = anysee_mt352_demod_init, |
| 240 | }; |
| 241 | |
| 242 | static struct zl10353_config anysee_zl10353_config = { |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame^] | 243 | .demod_address = (0x1e >> 1), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 244 | .parallel_ts = 1, |
| 245 | }; |
| 246 | |
| 247 | static int anysee_frontend_attach(struct dvb_usb_adapter *adap) |
| 248 | { |
| 249 | int ret; |
| 250 | struct anysee_state *state = adap->dev->priv; |
| 251 | u8 hw_info[3]; |
| 252 | u8 io_d; /* IO port D */ |
| 253 | |
| 254 | /* check which hardware we have |
| 255 | We must do this call two times to get reliable values (hw bug). */ |
| 256 | ret = anysee_get_hw_info(adap->dev, hw_info); |
| 257 | if (ret) |
| 258 | return ret; |
| 259 | ret = anysee_get_hw_info(adap->dev, hw_info); |
| 260 | if (ret) |
| 261 | return ret; |
| 262 | |
| 263 | /* Meaning of these info bytes are guessed. */ |
| 264 | info("firmware version:%d.%d.%d hardware id:%d", |
| 265 | 0, hw_info[1], hw_info[2], hw_info[0]); |
| 266 | |
| 267 | ret = anysee_read_reg(adap->dev, 0xb0, &io_d); /* IO port D */ |
| 268 | if (ret) |
| 269 | return ret; |
| 270 | deb_info("%s: IO port D:%02x\n", __func__, io_d); |
| 271 | |
| 272 | /* Select demod using trial and error method. */ |
| 273 | |
| 274 | /* Try to attach demodulator in following order: |
| 275 | model demod hw firmware |
| 276 | 1. E30 MT352 02 0.2.1 |
| 277 | 2. E30 ZL10353 02 0.2.1 |
Antti Palosaari | 0f77c3a | 2008-08-11 10:54:16 -0300 | [diff] [blame] | 278 | 3. E30 Combo ZL10353 0f 0.1.2 DVB-T/C combo |
| 279 | 4. E30 Plus ZL10353 06 0.1.0 |
| 280 | 5. E30C Plus TDA10023 0a 0.1.0 rev 0.2 |
| 281 | E30C Plus TDA10023 0f 0.1.2 rev 0.4 |
| 282 | E30 Combo TDA10023 0f 0.1.2 DVB-T/C combo |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 283 | */ |
| 284 | |
| 285 | /* Zarlink MT352 DVB-T demod inside of Samsung DNOS404ZH102A NIM */ |
| 286 | adap->fe = dvb_attach(mt352_attach, &anysee_mt352_config, |
| 287 | &adap->dev->i2c_adap); |
| 288 | if (adap->fe != NULL) { |
| 289 | state->tuner = DVB_PLL_THOMSON_DTT7579; |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | /* Zarlink ZL10353 DVB-T demod inside of Samsung DNOS404ZH103A NIM */ |
| 294 | adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config, |
| 295 | &adap->dev->i2c_adap); |
| 296 | if (adap->fe != NULL) { |
| 297 | state->tuner = DVB_PLL_THOMSON_DTT7579; |
| 298 | return 0; |
| 299 | } |
| 300 | |
Antti Palosaari | 0f77c3a | 2008-08-11 10:54:16 -0300 | [diff] [blame] | 301 | /* for E30 Combo Plus DVB-T demodulator */ |
| 302 | if (dvb_usb_anysee_delsys) { |
| 303 | ret = anysee_write_reg(adap->dev, 0xb0, 0x01); |
| 304 | if (ret) |
| 305 | return ret; |
| 306 | |
| 307 | /* Zarlink ZL10353 DVB-T demod */ |
| 308 | adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config, |
| 309 | &adap->dev->i2c_adap); |
| 310 | if (adap->fe != NULL) { |
| 311 | state->tuner = DVB_PLL_SAMSUNG_DTOS403IH102A; |
| 312 | return 0; |
| 313 | } |
| 314 | } |
| 315 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 316 | /* connect demod on IO port D for TDA10023 & ZL10353 */ |
| 317 | ret = anysee_write_reg(adap->dev, 0xb0, 0x25); |
| 318 | if (ret) |
| 319 | return ret; |
| 320 | |
| 321 | /* Zarlink ZL10353 DVB-T demod inside of Samsung DNOS404ZH103A NIM */ |
| 322 | adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config, |
| 323 | &adap->dev->i2c_adap); |
| 324 | if (adap->fe != NULL) { |
| 325 | state->tuner = DVB_PLL_THOMSON_DTT7579; |
| 326 | return 0; |
| 327 | } |
| 328 | |
Antti Palosaari | 5ae2fca | 2008-06-09 22:58:22 -0300 | [diff] [blame] | 329 | /* IO port E - E30C rev 0.4 board requires this */ |
| 330 | ret = anysee_write_reg(adap->dev, 0xb1, 0xa7); |
| 331 | if (ret) |
| 332 | return ret; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 333 | |
| 334 | /* Philips TDA10023 DVB-C demod */ |
| 335 | adap->fe = dvb_attach(tda10023_attach, &anysee_tda10023_config, |
| 336 | &adap->dev->i2c_adap, 0x48); |
| 337 | if (adap->fe != NULL) { |
| 338 | state->tuner = DVB_PLL_SAMSUNG_DTOS403IH102A; |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | /* return IO port D to init value for safe */ |
| 343 | ret = anysee_write_reg(adap->dev, 0xb0, io_d); |
| 344 | if (ret) |
| 345 | return ret; |
| 346 | |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 347 | err("Unknown Anysee version: %02x %02x %02x. "\ |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 348 | "Please report the <linux-dvb@linuxtv.org>.", |
| 349 | hw_info[0], hw_info[1], hw_info[2]); |
| 350 | |
| 351 | return -ENODEV; |
| 352 | } |
| 353 | |
| 354 | static int anysee_tuner_attach(struct dvb_usb_adapter *adap) |
| 355 | { |
| 356 | struct anysee_state *state = adap->dev->priv; |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 357 | deb_info("%s:\n", __func__); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 358 | |
| 359 | switch (state->tuner) { |
| 360 | case DVB_PLL_THOMSON_DTT7579: |
| 361 | /* Thomson dtt7579 (not sure) PLL inside of: |
| 362 | Samsung DNOS404ZH102A NIM |
| 363 | Samsung DNOS404ZH103A NIM */ |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame^] | 364 | dvb_attach(dvb_pll_attach, adap->fe, (0xc2 >> 1), |
| 365 | NULL, DVB_PLL_THOMSON_DTT7579); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 366 | break; |
| 367 | case DVB_PLL_SAMSUNG_DTOS403IH102A: |
| 368 | /* Unknown PLL inside of Samsung DTOS403IH102A tuner module */ |
Antti Palosaari | 7ea03d2 | 2011-04-09 20:50:07 -0300 | [diff] [blame^] | 369 | dvb_attach(dvb_pll_attach, adap->fe, (0xc0 >> 1), |
| 370 | &adap->dev->i2c_adap, DVB_PLL_SAMSUNG_DTOS403IH102A); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 371 | break; |
| 372 | } |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 377 | static int anysee_rc_query(struct dvb_usb_device *d) |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 378 | { |
| 379 | u8 buf[] = {CMD_GET_IR_CODE}; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 380 | u8 ircode[2]; |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 381 | int ret; |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 382 | |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 383 | /* Remote controller is basic NEC using address byte 0x08. |
| 384 | Anysee device RC query returns only two bytes, status and code, |
| 385 | address byte is dropped. Also it does not return any value for |
| 386 | NEC RCs having address byte other than 0x08. Due to that, we |
| 387 | cannot use that device as standard NEC receiver. |
| 388 | It could be possible make hack which reads whole code directly |
| 389 | from device memory... */ |
| 390 | |
| 391 | ret = anysee_ctrl_msg(d, buf, sizeof(buf), ircode, sizeof(ircode)); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 392 | if (ret) |
| 393 | return ret; |
| 394 | |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 395 | if (ircode[0]) { |
| 396 | deb_rc("%s: key pressed %02x\n", __func__, ircode[1]); |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 397 | rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 398 | } |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 399 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 400 | return 0; |
| 401 | } |
| 402 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 403 | /* DVB USB Driver stuff */ |
| 404 | static struct dvb_usb_device_properties anysee_properties; |
| 405 | |
| 406 | static int anysee_probe(struct usb_interface *intf, |
| 407 | const struct usb_device_id *id) |
| 408 | { |
| 409 | struct dvb_usb_device *d; |
| 410 | struct usb_host_interface *alt; |
| 411 | int ret; |
| 412 | |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 413 | /* There is one interface with two alternate settings. |
| 414 | Alternate setting 0 is for bulk transfer. |
| 415 | Alternate setting 1 is for isochronous transfer. |
| 416 | We use bulk transfer (alternate setting 0). */ |
| 417 | if (intf->num_altsetting < 1) |
| 418 | return -ENODEV; |
| 419 | |
Dan Carpenter | 8b0d704 | 2010-05-31 16:27:39 -0300 | [diff] [blame] | 420 | /* |
| 421 | * Anysee is always warm (its USB-bridge, Cypress FX2, uploads |
| 422 | * firmware from eeprom). If dvb_usb_device_init() succeeds that |
| 423 | * means d is a valid pointer. |
| 424 | */ |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 425 | ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d, |
| 426 | adapter_nr); |
| 427 | if (ret) |
| 428 | return ret; |
| 429 | |
| 430 | alt = usb_altnum_to_altsetting(intf, 0); |
| 431 | if (alt == NULL) { |
| 432 | deb_info("%s: no alt found!\n", __func__); |
| 433 | return -ENODEV; |
| 434 | } |
| 435 | |
| 436 | ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber, |
| 437 | alt->desc.bAlternateSetting); |
| 438 | if (ret) |
| 439 | return ret; |
| 440 | |
Dan Carpenter | 8b0d704 | 2010-05-31 16:27:39 -0300 | [diff] [blame] | 441 | return anysee_init(d); |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 442 | } |
| 443 | |
Antti Palosaari | ae3745f | 2009-09-16 19:50:25 -0300 | [diff] [blame] | 444 | static struct usb_device_id anysee_table[] = { |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 445 | { USB_DEVICE(USB_VID_CYPRESS, USB_PID_ANYSEE) }, |
| 446 | { USB_DEVICE(USB_VID_AMT, USB_PID_ANYSEE) }, |
| 447 | { } /* Terminating entry */ |
| 448 | }; |
| 449 | MODULE_DEVICE_TABLE(usb, anysee_table); |
| 450 | |
| 451 | static struct dvb_usb_device_properties anysee_properties = { |
| 452 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 453 | |
| 454 | .usb_ctrl = DEVICE_SPECIFIC, |
| 455 | |
| 456 | .size_of_priv = sizeof(struct anysee_state), |
| 457 | |
| 458 | .num_adapters = 1, |
| 459 | .adapter = { |
| 460 | { |
| 461 | .streaming_ctrl = anysee_streaming_ctrl, |
| 462 | .frontend_attach = anysee_frontend_attach, |
| 463 | .tuner_attach = anysee_tuner_attach, |
| 464 | .stream = { |
| 465 | .type = USB_BULK, |
| 466 | .count = 8, |
| 467 | .endpoint = 0x82, |
| 468 | .u = { |
| 469 | .bulk = { |
Antti Palosaari | ab69333 | 2009-09-16 19:47:01 -0300 | [diff] [blame] | 470 | .buffersize = (16*512), |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | }, |
| 474 | } |
| 475 | }, |
| 476 | |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 477 | .rc.core = { |
| 478 | .rc_codes = RC_MAP_ANYSEE, |
Mauro Carvalho Chehab | 52b6614 | 2010-11-17 14:20:52 -0300 | [diff] [blame] | 479 | .protocol = RC_TYPE_OTHER, |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 480 | .module_name = "anysee", |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 481 | .rc_query = anysee_rc_query, |
Antti Palosaari | a849468 | 2010-10-17 18:25:10 -0300 | [diff] [blame] | 482 | .rc_interval = 250, /* windows driver uses 500ms */ |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 483 | }, |
Antti Palosaari | a51e34d | 2008-05-17 23:05:48 -0300 | [diff] [blame] | 484 | |
| 485 | .i2c_algo = &anysee_i2c_algo, |
| 486 | |
| 487 | .generic_bulk_ctrl_endpoint = 1, |
| 488 | |
| 489 | .num_device_descs = 1, |
| 490 | .devices = { |
| 491 | { |
| 492 | .name = "Anysee DVB USB2.0", |
| 493 | .cold_ids = {NULL}, |
| 494 | .warm_ids = {&anysee_table[0], |
| 495 | &anysee_table[1], NULL}, |
| 496 | }, |
| 497 | } |
| 498 | }; |
| 499 | |
| 500 | static struct usb_driver anysee_driver = { |
| 501 | .name = "dvb_usb_anysee", |
| 502 | .probe = anysee_probe, |
| 503 | .disconnect = dvb_usb_device_exit, |
| 504 | .id_table = anysee_table, |
| 505 | }; |
| 506 | |
| 507 | /* module stuff */ |
| 508 | static int __init anysee_module_init(void) |
| 509 | { |
| 510 | int ret; |
| 511 | |
| 512 | ret = usb_register(&anysee_driver); |
| 513 | if (ret) |
| 514 | err("%s: usb_register failed. Error number %d", __func__, ret); |
| 515 | |
| 516 | return ret; |
| 517 | } |
| 518 | |
| 519 | static void __exit anysee_module_exit(void) |
| 520 | { |
| 521 | /* deregister this driver from the USB subsystem */ |
| 522 | usb_deregister(&anysee_driver); |
| 523 | } |
| 524 | |
| 525 | module_init(anysee_module_init); |
| 526 | module_exit(anysee_module_exit); |
| 527 | |
| 528 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 529 | MODULE_DESCRIPTION("Driver Anysee E30 DVB-C & DVB-T USB2.0"); |
| 530 | MODULE_LICENSE("GPL"); |