Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 1 | /* DVB USB compliant linux driver for Technotrend DVB USB boxes and clones |
| 2 | * (e.g. Pinnacle 400e DVB-S USB2.0). |
| 3 | * |
| 4 | * The Pinnacle 400e uses the same protocol as the Technotrend USB1.1 boxes. |
| 5 | * |
| 6 | * TDA8263 + TDA10086 |
| 7 | * |
| 8 | * I2C addresses: |
| 9 | * 0x08 - LNBP21PD - LNB power supply |
| 10 | * 0x0e - TDA10086 - Demodulator |
| 11 | * 0x50 - FX2 eeprom |
| 12 | * 0x60 - TDA8263 - Tuner |
| 13 | * 0x78 ??? |
| 14 | * |
| 15 | * Copyright (c) 2002 Holger Waechtler <holger@convergence.de> |
| 16 | * Copyright (c) 2003 Felix Domke <tmbinc@elitedvb.net> |
| 17 | * Copyright (C) 2005-6 Patrick Boettcher <pb@linuxtv.org> |
| 18 | * |
| 19 | * This program is free software; you can redistribute it and/or modify it |
| 20 | * under the terms of the GNU General Public License as published by the Free |
| 21 | * Software Foundation, version 2. |
| 22 | * |
| 23 | * see Documentation/dvb/README.dvb-usb for more information |
| 24 | */ |
| 25 | #define DVB_USB_LOG_PREFIX "ttusb2" |
| 26 | #include "dvb-usb.h" |
| 27 | |
| 28 | #include "ttusb2.h" |
| 29 | |
| 30 | #include "tda826x.h" |
| 31 | #include "tda10086.h" |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 32 | #include "tda1002x.h" |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 33 | #include "tda10048.h" |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 34 | #include "tda827x.h" |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 35 | #include "lnbp21.h" |
Jose Alberto Reguero | 8c0bc03 | 2011-09-18 07:59:05 -0300 | [diff] [blame] | 36 | /* CA */ |
| 37 | #include "dvb_ca_en50221.h" |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 38 | |
| 39 | /* debug */ |
| 40 | static int dvb_usb_ttusb2_debug; |
| 41 | #define deb_info(args...) dprintk(dvb_usb_ttusb2_debug,0x01,args) |
| 42 | module_param_named(debug,dvb_usb_ttusb2_debug, int, 0644); |
| 43 | MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." DVB_USB_DEBUG_STATUS); |
Jose Alberto Reguero | 8c0bc03 | 2011-09-18 07:59:05 -0300 | [diff] [blame] | 44 | static int dvb_usb_ttusb2_debug_ci; |
| 45 | module_param_named(debug_ci,dvb_usb_ttusb2_debug_ci, int, 0644); |
| 46 | MODULE_PARM_DESC(debug_ci, "set debugging ci." DVB_USB_DEBUG_STATUS); |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 47 | |
Janne Grunau | 78e92006 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 48 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 49 | |
Jose Alberto Reguero | 8c0bc03 | 2011-09-18 07:59:05 -0300 | [diff] [blame] | 50 | #define ci_dbg(format, arg...) \ |
| 51 | do { \ |
| 52 | if (dvb_usb_ttusb2_debug_ci) \ |
| 53 | printk(KERN_DEBUG DVB_USB_LOG_PREFIX \ |
| 54 | ": %s " format "\n" , __func__, ## arg); \ |
| 55 | } while (0) |
| 56 | |
| 57 | enum { |
| 58 | TT3650_CMD_CI_TEST = 0x40, |
| 59 | TT3650_CMD_CI_RD_CTRL, |
| 60 | TT3650_CMD_CI_WR_CTRL, |
| 61 | TT3650_CMD_CI_RD_ATTR, |
| 62 | TT3650_CMD_CI_WR_ATTR, |
| 63 | TT3650_CMD_CI_RESET, |
| 64 | TT3650_CMD_CI_SET_VIDEO_PORT |
| 65 | }; |
| 66 | |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 67 | struct ttusb2_state { |
Jose Alberto Reguero | 8c0bc03 | 2011-09-18 07:59:05 -0300 | [diff] [blame] | 68 | struct dvb_ca_en50221 ca; |
| 69 | struct mutex ca_mutex; |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 70 | u8 id; |
David Henningsson | 9d1da73 | 2010-12-26 10:23:58 -0300 | [diff] [blame] | 71 | u16 last_rc_key; |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd, |
| 75 | u8 *wbuf, int wlen, u8 *rbuf, int rlen) |
| 76 | { |
| 77 | struct ttusb2_state *st = d->priv; |
| 78 | u8 s[wlen+4],r[64] = { 0 }; |
| 79 | int ret = 0; |
| 80 | |
| 81 | memset(s,0,wlen+4); |
| 82 | |
| 83 | s[0] = 0xaa; |
| 84 | s[1] = ++st->id; |
| 85 | s[2] = cmd; |
| 86 | s[3] = wlen; |
| 87 | memcpy(&s[4],wbuf,wlen); |
| 88 | |
| 89 | ret = dvb_usb_generic_rw(d, s, wlen+4, r, 64, 0); |
| 90 | |
| 91 | if (ret != 0 || |
| 92 | r[0] != 0x55 || |
| 93 | r[1] != s[1] || |
| 94 | r[2] != cmd || |
| 95 | (rlen > 0 && r[3] != rlen)) { |
| 96 | warn("there might have been an error during control message transfer. (rlen = %d, was %d)",rlen,r[3]); |
| 97 | return -EIO; |
| 98 | } |
| 99 | |
| 100 | if (rlen > 0) |
| 101 | memcpy(rbuf, &r[4], rlen); |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Jose Alberto Reguero | 8c0bc03 | 2011-09-18 07:59:05 -0300 | [diff] [blame] | 106 | /* ci */ |
| 107 | static int tt3650_ci_msg(struct dvb_usb_device *d, u8 cmd, u8 *data, unsigned int write_len, unsigned int read_len) |
| 108 | { |
| 109 | int ret; |
| 110 | u8 rx[60];/* (64 -4) */ |
| 111 | ret = ttusb2_msg(d, cmd, data, write_len, rx, read_len); |
| 112 | if (!ret) |
| 113 | memcpy(data, rx, read_len); |
| 114 | return ret; |
| 115 | } |
| 116 | |
| 117 | static int tt3650_ci_msg_locked(struct dvb_ca_en50221 *ca, u8 cmd, u8 *data, unsigned int write_len, unsigned int read_len) |
| 118 | { |
| 119 | struct dvb_usb_device *d = ca->data; |
| 120 | struct ttusb2_state *state = d->priv; |
| 121 | int ret; |
| 122 | |
| 123 | mutex_lock(&state->ca_mutex); |
| 124 | ret = tt3650_ci_msg(d, cmd, data, write_len, read_len); |
| 125 | mutex_unlock(&state->ca_mutex); |
| 126 | |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | static int tt3650_ci_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address) |
| 131 | { |
| 132 | u8 buf[3]; |
| 133 | int ret = 0; |
| 134 | |
| 135 | if (slot) |
| 136 | return -EINVAL; |
| 137 | |
| 138 | buf[0] = (address >> 8) & 0x0F; |
| 139 | buf[1] = address; |
| 140 | |
| 141 | |
| 142 | ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_RD_ATTR, buf, 2, 3); |
| 143 | |
| 144 | ci_dbg("%04x -> %d 0x%02x", address, ret, buf[2]); |
| 145 | |
| 146 | if (ret < 0) |
| 147 | return ret; |
| 148 | |
| 149 | return buf[2]; |
| 150 | } |
| 151 | |
| 152 | static int tt3650_ci_write_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address, u8 value) |
| 153 | { |
| 154 | u8 buf[3]; |
| 155 | |
| 156 | ci_dbg("%d 0x%04x 0x%02x", slot, address, value); |
| 157 | |
| 158 | if (slot) |
| 159 | return -EINVAL; |
| 160 | |
| 161 | buf[0] = (address >> 8) & 0x0F; |
| 162 | buf[1] = address; |
| 163 | buf[2] = value; |
| 164 | |
| 165 | return tt3650_ci_msg_locked(ca, TT3650_CMD_CI_WR_ATTR, buf, 3, 3); |
| 166 | } |
| 167 | |
| 168 | static int tt3650_ci_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address) |
| 169 | { |
| 170 | u8 buf[2]; |
| 171 | int ret; |
| 172 | |
| 173 | if (slot) |
| 174 | return -EINVAL; |
| 175 | |
| 176 | buf[0] = address & 3; |
| 177 | |
| 178 | ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_RD_CTRL, buf, 1, 2); |
| 179 | |
| 180 | ci_dbg("0x%02x -> %d 0x%02x", address, ret, buf[1]); |
| 181 | |
| 182 | if (ret < 0) |
| 183 | return ret; |
| 184 | |
| 185 | return buf[1]; |
| 186 | } |
| 187 | |
| 188 | static int tt3650_ci_write_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 address, u8 value) |
| 189 | { |
| 190 | u8 buf[2]; |
| 191 | |
| 192 | ci_dbg("%d 0x%02x 0x%02x", slot, address, value); |
| 193 | |
| 194 | if (slot) |
| 195 | return -EINVAL; |
| 196 | |
| 197 | buf[0] = address; |
| 198 | buf[1] = value; |
| 199 | |
| 200 | return tt3650_ci_msg_locked(ca, TT3650_CMD_CI_WR_CTRL, buf, 2, 2); |
| 201 | } |
| 202 | |
| 203 | static int tt3650_ci_set_video_port(struct dvb_ca_en50221 *ca, int slot, int enable) |
| 204 | { |
| 205 | u8 buf[1]; |
| 206 | int ret; |
| 207 | |
| 208 | ci_dbg("%d %d", slot, enable); |
| 209 | |
| 210 | if (slot) |
| 211 | return -EINVAL; |
| 212 | |
| 213 | buf[0] = enable; |
| 214 | |
| 215 | ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_SET_VIDEO_PORT, buf, 1, 1); |
| 216 | if (ret < 0) |
| 217 | return ret; |
| 218 | |
| 219 | if (enable != buf[0]) { |
| 220 | err("CI not %sabled.", enable ? "en" : "dis"); |
| 221 | return -EIO; |
| 222 | } |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | static int tt3650_ci_slot_shutdown(struct dvb_ca_en50221 *ca, int slot) |
| 228 | { |
| 229 | return tt3650_ci_set_video_port(ca, slot, 0); |
| 230 | } |
| 231 | |
| 232 | static int tt3650_ci_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot) |
| 233 | { |
| 234 | return tt3650_ci_set_video_port(ca, slot, 1); |
| 235 | } |
| 236 | |
| 237 | static int tt3650_ci_slot_reset(struct dvb_ca_en50221 *ca, int slot) |
| 238 | { |
| 239 | struct dvb_usb_device *d = ca->data; |
| 240 | struct ttusb2_state *state = d->priv; |
| 241 | u8 buf[1]; |
| 242 | int ret; |
| 243 | |
| 244 | ci_dbg("%d", slot); |
| 245 | |
| 246 | if (slot) |
| 247 | return -EINVAL; |
| 248 | |
| 249 | buf[0] = 0; |
| 250 | |
| 251 | mutex_lock(&state->ca_mutex); |
| 252 | |
| 253 | ret = tt3650_ci_msg(d, TT3650_CMD_CI_RESET, buf, 1, 1); |
| 254 | if (ret) |
| 255 | goto failed; |
| 256 | |
| 257 | msleep(500); |
| 258 | |
| 259 | buf[0] = 1; |
| 260 | |
| 261 | ret = tt3650_ci_msg(d, TT3650_CMD_CI_RESET, buf, 1, 1); |
| 262 | if (ret) |
| 263 | goto failed; |
| 264 | |
| 265 | msleep(500); |
| 266 | |
| 267 | buf[0] = 0; /* FTA */ |
| 268 | |
| 269 | ret = tt3650_ci_msg(d, TT3650_CMD_CI_SET_VIDEO_PORT, buf, 1, 1); |
| 270 | |
| 271 | msleep(1100); |
| 272 | |
| 273 | failed: |
| 274 | mutex_unlock(&state->ca_mutex); |
| 275 | |
| 276 | return ret; |
| 277 | } |
| 278 | |
| 279 | static int tt3650_ci_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open) |
| 280 | { |
| 281 | u8 buf[1]; |
| 282 | int ret; |
| 283 | |
| 284 | if (slot) |
| 285 | return -EINVAL; |
| 286 | |
| 287 | ret = tt3650_ci_msg_locked(ca, TT3650_CMD_CI_TEST, buf, 0, 1); |
| 288 | if (ret) |
| 289 | return ret; |
| 290 | |
| 291 | if (1 == buf[0]) { |
| 292 | return DVB_CA_EN50221_POLL_CAM_PRESENT | |
| 293 | DVB_CA_EN50221_POLL_CAM_READY; |
| 294 | } |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static void tt3650_ci_uninit(struct dvb_usb_device *d) |
| 299 | { |
| 300 | struct ttusb2_state *state; |
| 301 | |
| 302 | ci_dbg(""); |
| 303 | |
| 304 | if (NULL == d) |
| 305 | return; |
| 306 | |
| 307 | state = d->priv; |
| 308 | if (NULL == state) |
| 309 | return; |
| 310 | |
| 311 | if (NULL == state->ca.data) |
| 312 | return; |
| 313 | |
| 314 | dvb_ca_en50221_release(&state->ca); |
| 315 | |
| 316 | memset(&state->ca, 0, sizeof(state->ca)); |
| 317 | } |
| 318 | |
| 319 | static int tt3650_ci_init(struct dvb_usb_adapter *a) |
| 320 | { |
| 321 | struct dvb_usb_device *d = a->dev; |
| 322 | struct ttusb2_state *state = d->priv; |
| 323 | int ret; |
| 324 | |
| 325 | ci_dbg(""); |
| 326 | |
| 327 | mutex_init(&state->ca_mutex); |
| 328 | |
| 329 | state->ca.owner = THIS_MODULE; |
| 330 | state->ca.read_attribute_mem = tt3650_ci_read_attribute_mem; |
| 331 | state->ca.write_attribute_mem = tt3650_ci_write_attribute_mem; |
| 332 | state->ca.read_cam_control = tt3650_ci_read_cam_control; |
| 333 | state->ca.write_cam_control = tt3650_ci_write_cam_control; |
| 334 | state->ca.slot_reset = tt3650_ci_slot_reset; |
| 335 | state->ca.slot_shutdown = tt3650_ci_slot_shutdown; |
| 336 | state->ca.slot_ts_enable = tt3650_ci_slot_ts_enable; |
| 337 | state->ca.poll_slot_status = tt3650_ci_poll_slot_status; |
| 338 | state->ca.data = d; |
| 339 | |
| 340 | ret = dvb_ca_en50221_init(&a->dvb_adap, |
| 341 | &state->ca, |
| 342 | /* flags */ 0, |
| 343 | /* n_slots */ 1); |
| 344 | if (ret) { |
| 345 | err("Cannot initialize CI: Error %d.", ret); |
| 346 | memset(&state->ca, 0, sizeof(state->ca)); |
| 347 | return ret; |
| 348 | } |
| 349 | |
| 350 | info("CI initialized."); |
| 351 | |
| 352 | return 0; |
| 353 | } |
| 354 | |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 355 | static int ttusb2_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num) |
| 356 | { |
| 357 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 358 | static u8 obuf[60], ibuf[60]; |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 359 | int i, write_read, read; |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 360 | |
| 361 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 362 | return -EAGAIN; |
| 363 | |
| 364 | if (num > 2) |
| 365 | warn("more than 2 i2c messages at a time is not handled yet. TODO."); |
| 366 | |
| 367 | for (i = 0; i < num; i++) { |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 368 | write_read = i+1 < num && (msg[i+1].flags & I2C_M_RD); |
| 369 | read = msg[i].flags & I2C_M_RD; |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 370 | |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 371 | obuf[0] = (msg[i].addr << 1) | (write_read | read); |
| 372 | if (read) |
| 373 | obuf[1] = 0; |
| 374 | else |
| 375 | obuf[1] = msg[i].len; |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 376 | |
| 377 | /* read request */ |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 378 | if (write_read) |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 379 | obuf[2] = msg[i+1].len; |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 380 | else if (read) |
| 381 | obuf[2] = msg[i].len; |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 382 | else |
| 383 | obuf[2] = 0; |
| 384 | |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 385 | memcpy(&obuf[3], msg[i].buf, msg[i].len); |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 386 | |
| 387 | if (ttusb2_msg(d, CMD_I2C_XFER, obuf, msg[i].len+3, ibuf, obuf[2] + 3) < 0) { |
| 388 | err("i2c transfer failed."); |
| 389 | break; |
| 390 | } |
| 391 | |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 392 | if (write_read) { |
| 393 | memcpy(msg[i+1].buf, &ibuf[3], msg[i+1].len); |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 394 | i++; |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 395 | } else if (read) |
| 396 | memcpy(msg[i].buf, &ibuf[3], msg[i].len); |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | mutex_unlock(&d->i2c_mutex); |
| 400 | return i; |
| 401 | } |
| 402 | |
| 403 | static u32 ttusb2_i2c_func(struct i2c_adapter *adapter) |
| 404 | { |
| 405 | return I2C_FUNC_I2C; |
| 406 | } |
| 407 | |
| 408 | static struct i2c_algorithm ttusb2_i2c_algo = { |
| 409 | .master_xfer = ttusb2_i2c_xfer, |
| 410 | .functionality = ttusb2_i2c_func, |
| 411 | }; |
| 412 | |
David Henningsson | 9d1da73 | 2010-12-26 10:23:58 -0300 | [diff] [blame] | 413 | /* command to poll IR receiver (copied from pctv452e.c) */ |
| 414 | #define CMD_GET_IR_CODE 0x1b |
| 415 | |
| 416 | /* IR */ |
| 417 | static int tt3650_rc_query(struct dvb_usb_device *d) |
| 418 | { |
| 419 | int ret; |
| 420 | u8 rx[9]; /* A CMD_GET_IR_CODE reply is 9 bytes long */ |
| 421 | struct ttusb2_state *st = d->priv; |
| 422 | ret = ttusb2_msg(d, CMD_GET_IR_CODE, NULL, 0, rx, sizeof(rx)); |
| 423 | if (ret != 0) |
| 424 | return ret; |
| 425 | |
| 426 | if (rx[8] & 0x01) { |
| 427 | /* got a "press" event */ |
| 428 | st->last_rc_key = (rx[3] << 8) | rx[2]; |
| 429 | deb_info("%s: cmd=0x%02x sys=0x%02x\n", __func__, rx[2], rx[3]); |
| 430 | rc_keydown(d->rc_dev, st->last_rc_key, 0); |
| 431 | } else if (st->last_rc_key) { |
| 432 | rc_keyup(d->rc_dev); |
| 433 | st->last_rc_key = 0; |
| 434 | } |
| 435 | |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 440 | /* Callbacks for DVB USB */ |
| 441 | static int ttusb2_identify_state (struct usb_device *udev, struct |
| 442 | dvb_usb_device_properties *props, struct dvb_usb_device_description **desc, |
| 443 | int *cold) |
| 444 | { |
| 445 | *cold = udev->descriptor.iManufacturer == 0 && udev->descriptor.iProduct == 0; |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | static int ttusb2_power_ctrl(struct dvb_usb_device *d, int onoff) |
| 450 | { |
| 451 | u8 b = onoff; |
| 452 | ttusb2_msg(d, CMD_POWER, &b, 0, NULL, 0); |
| 453 | return ttusb2_msg(d, CMD_POWER, &b, 1, NULL, 0); |
| 454 | } |
| 455 | |
| 456 | |
| 457 | static struct tda10086_config tda10086_config = { |
| 458 | .demod_address = 0x0e, |
| 459 | .invert = 0, |
Hartmut Hackmann | ea75baf | 2008-02-09 23:54:24 -0300 | [diff] [blame] | 460 | .diseqc_tone = 1, |
Hartmut Hackmann | 9a1b04e | 2008-04-09 23:07:11 -0300 | [diff] [blame] | 461 | .xtal_freq = TDA10086_XTAL_16M, |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 462 | }; |
| 463 | |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 464 | static struct tda10023_config tda10023_config = { |
| 465 | .demod_address = 0x0c, |
| 466 | .invert = 0, |
| 467 | .xtal = 16000000, |
| 468 | .pll_m = 11, |
| 469 | .pll_p = 3, |
| 470 | .pll_n = 1, |
| 471 | .deltaf = 0xa511, |
| 472 | }; |
| 473 | |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 474 | static struct tda10048_config tda10048_config = { |
| 475 | .demod_address = 0x10 >> 1, |
| 476 | .output_mode = TDA10048_PARALLEL_OUTPUT, |
| 477 | .inversion = TDA10048_INVERSION_ON, |
| 478 | .dtv6_if_freq_khz = TDA10048_IF_4000, |
| 479 | .dtv7_if_freq_khz = TDA10048_IF_4500, |
| 480 | .dtv8_if_freq_khz = TDA10048_IF_5000, |
| 481 | .clk_freq_khz = TDA10048_CLK_16000, |
| 482 | .no_firmware = 1, |
| 483 | .set_pll = true , |
| 484 | .pll_m = 5, |
| 485 | .pll_n = 3, |
| 486 | .pll_p = 0, |
| 487 | }; |
| 488 | |
| 489 | static struct tda827x_config tda827x_config = { |
| 490 | .config = 0, |
| 491 | }; |
| 492 | |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 493 | static int ttusb2_frontend_tda10086_attach(struct dvb_usb_adapter *adap) |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 494 | { |
| 495 | if (usb_set_interface(adap->dev->udev,0,3) < 0) |
| 496 | err("set interface to alts=3 failed"); |
| 497 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 498 | if ((adap->fe_adap[0].fe = dvb_attach(tda10086_attach, &tda10086_config, &adap->dev->i2c_adap)) == NULL) { |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 499 | deb_info("TDA10086 attach failed\n"); |
| 500 | return -ENODEV; |
| 501 | } |
| 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 506 | static int ttusb2_ct3650_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
| 507 | { |
| 508 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
| 509 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 510 | return adap->fe_adap[0].fe->ops.i2c_gate_ctrl(adap->fe_adap[0].fe, enable); |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 511 | } |
| 512 | |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 513 | static int ttusb2_frontend_tda10023_attach(struct dvb_usb_adapter *adap) |
| 514 | { |
| 515 | if (usb_set_interface(adap->dev->udev, 0, 3) < 0) |
| 516 | err("set interface to alts=3 failed"); |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 517 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 518 | if (adap->fe_adap[0].fe == NULL) { |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 519 | /* FE 0 DVB-C */ |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 520 | adap->fe_adap[0].fe = dvb_attach(tda10023_attach, |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 521 | &tda10023_config, &adap->dev->i2c_adap, 0x48); |
| 522 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 523 | if (adap->fe_adap[0].fe == NULL) { |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 524 | deb_info("TDA10023 attach failed\n"); |
| 525 | return -ENODEV; |
| 526 | } |
Jose Alberto Reguero | 8c0bc03 | 2011-09-18 07:59:05 -0300 | [diff] [blame] | 527 | tt3650_ci_init(adap); |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 528 | } else { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 529 | adap->fe_adap[1].fe = dvb_attach(tda10048_attach, |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 530 | &tda10048_config, &adap->dev->i2c_adap); |
| 531 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 532 | if (adap->fe_adap[1].fe == NULL) { |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 533 | deb_info("TDA10048 attach failed\n"); |
| 534 | return -ENODEV; |
| 535 | } |
| 536 | |
| 537 | /* tuner is behind TDA10023 I2C-gate */ |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 538 | adap->fe_adap[1].fe->ops.i2c_gate_ctrl = ttusb2_ct3650_i2c_gate_ctrl; |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 539 | |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 540 | } |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 541 | |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static int ttusb2_tuner_tda827x_attach(struct dvb_usb_adapter *adap) |
| 546 | { |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 547 | struct dvb_frontend *fe; |
| 548 | |
| 549 | /* MFE: select correct FE to attach tuner since that's called twice */ |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 550 | if (adap->fe_adap[1].fe == NULL) |
| 551 | fe = adap->fe_adap[0].fe; |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 552 | else |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 553 | fe = adap->fe_adap[1].fe; |
Jose Alberto Reguero | c9f88aa | 2011-08-08 07:35:35 -0300 | [diff] [blame] | 554 | |
| 555 | /* attach tuner */ |
| 556 | if (dvb_attach(tda827x_attach, fe, 0x61, &adap->dev->i2c_adap, &tda827x_config) == NULL) { |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 557 | printk(KERN_ERR "%s: No tda827x found!\n", __func__); |
| 558 | return -ENODEV; |
| 559 | } |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | static int ttusb2_tuner_tda826x_attach(struct dvb_usb_adapter *adap) |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 564 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 565 | if (dvb_attach(tda826x_attach, adap->fe_adap[0].fe, 0x60, &adap->dev->i2c_adap, 0) == NULL) { |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 566 | deb_info("TDA8263 attach failed\n"); |
| 567 | return -ENODEV; |
| 568 | } |
| 569 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 570 | if (dvb_attach(lnbp21_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap, 0, 0) == NULL) { |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 571 | deb_info("LNBP21 attach failed\n"); |
| 572 | return -ENODEV; |
| 573 | } |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | /* DVB USB Driver stuff */ |
| 578 | static struct dvb_usb_device_properties ttusb2_properties; |
Andre Weidemann | 8c899bc | 2008-03-29 21:30:49 -0300 | [diff] [blame] | 579 | static struct dvb_usb_device_properties ttusb2_properties_s2400; |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 580 | static struct dvb_usb_device_properties ttusb2_properties_ct3650; |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 581 | |
Jose Alberto Reguero | 8c0bc03 | 2011-09-18 07:59:05 -0300 | [diff] [blame] | 582 | static void ttusb2_usb_disconnect(struct usb_interface *intf) |
| 583 | { |
| 584 | struct dvb_usb_device *d = usb_get_intfdata(intf); |
| 585 | |
| 586 | tt3650_ci_uninit(d); |
| 587 | dvb_usb_device_exit(intf); |
| 588 | } |
| 589 | |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 590 | static int ttusb2_probe(struct usb_interface *intf, |
| 591 | const struct usb_device_id *id) |
| 592 | { |
Janne Grunau | 78e92006 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 593 | if (0 == dvb_usb_device_init(intf, &ttusb2_properties, |
| 594 | THIS_MODULE, NULL, adapter_nr) || |
| 595 | 0 == dvb_usb_device_init(intf, &ttusb2_properties_s2400, |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 596 | THIS_MODULE, NULL, adapter_nr) || |
| 597 | 0 == dvb_usb_device_init(intf, &ttusb2_properties_ct3650, |
Janne Grunau | 78e92006 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 598 | THIS_MODULE, NULL, adapter_nr)) |
Andre Weidemann | 8c899bc | 2008-03-29 21:30:49 -0300 | [diff] [blame] | 599 | return 0; |
| 600 | return -ENODEV; |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static struct usb_device_id ttusb2_table [] = { |
Andre Weidemann | 8c899bc | 2008-03-29 21:30:49 -0300 | [diff] [blame] | 604 | { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_400E) }, |
| 605 | { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_450E) }, |
| 606 | { USB_DEVICE(USB_VID_TECHNOTREND, |
| 607 | USB_PID_TECHNOTREND_CONNECT_S2400) }, |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 608 | { USB_DEVICE(USB_VID_TECHNOTREND, |
| 609 | USB_PID_TECHNOTREND_CONNECT_CT3650) }, |
Andre Weidemann | 8c899bc | 2008-03-29 21:30:49 -0300 | [diff] [blame] | 610 | {} /* Terminating entry */ |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 611 | }; |
| 612 | MODULE_DEVICE_TABLE (usb, ttusb2_table); |
| 613 | |
| 614 | static struct dvb_usb_device_properties ttusb2_properties = { |
| 615 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 616 | |
| 617 | .usb_ctrl = CYPRESS_FX2, |
| 618 | .firmware = "dvb-usb-pctv-400e-01.fw", |
| 619 | |
| 620 | .size_of_priv = sizeof(struct ttusb2_state), |
| 621 | |
| 622 | .num_adapters = 1, |
| 623 | .adapter = { |
| 624 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 625 | .num_frontends = 1, |
| 626 | .fe = {{ |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 627 | .streaming_ctrl = NULL, // ttusb2_streaming_ctrl, |
| 628 | |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 629 | .frontend_attach = ttusb2_frontend_tda10086_attach, |
| 630 | .tuner_attach = ttusb2_tuner_tda826x_attach, |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 631 | |
| 632 | /* parameter for the MPEG2-data transfer */ |
| 633 | .stream = { |
| 634 | .type = USB_ISOC, |
| 635 | .count = 5, |
| 636 | .endpoint = 0x02, |
| 637 | .u = { |
| 638 | .isoc = { |
| 639 | .framesperurb = 4, |
| 640 | .framesize = 940, |
| 641 | .interval = 1, |
| 642 | } |
| 643 | } |
| 644 | } |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 645 | }}, |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 646 | } |
| 647 | }, |
| 648 | |
| 649 | .power_ctrl = ttusb2_power_ctrl, |
| 650 | .identify_state = ttusb2_identify_state, |
| 651 | |
| 652 | .i2c_algo = &ttusb2_i2c_algo, |
| 653 | |
| 654 | .generic_bulk_ctrl_endpoint = 0x01, |
| 655 | |
Christophe Cattelain | ddc9ece | 2007-04-27 12:31:32 -0300 | [diff] [blame] | 656 | .num_device_descs = 2, |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 657 | .devices = { |
| 658 | { "Pinnacle 400e DVB-S USB2.0", |
| 659 | { &ttusb2_table[0], NULL }, |
| 660 | { NULL }, |
| 661 | }, |
Christophe Cattelain | ddc9ece | 2007-04-27 12:31:32 -0300 | [diff] [blame] | 662 | { "Pinnacle 450e DVB-S USB2.0", |
| 663 | { &ttusb2_table[1], NULL }, |
| 664 | { NULL }, |
| 665 | }, |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 666 | } |
| 667 | }; |
| 668 | |
Andre Weidemann | 8c899bc | 2008-03-29 21:30:49 -0300 | [diff] [blame] | 669 | static struct dvb_usb_device_properties ttusb2_properties_s2400 = { |
| 670 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 671 | |
| 672 | .usb_ctrl = CYPRESS_FX2, |
| 673 | .firmware = "dvb-usb-tt-s2400-01.fw", |
| 674 | |
| 675 | .size_of_priv = sizeof(struct ttusb2_state), |
| 676 | |
| 677 | .num_adapters = 1, |
| 678 | .adapter = { |
| 679 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 680 | .num_frontends = 1, |
| 681 | .fe = {{ |
Andre Weidemann | 8c899bc | 2008-03-29 21:30:49 -0300 | [diff] [blame] | 682 | .streaming_ctrl = NULL, |
| 683 | |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 684 | .frontend_attach = ttusb2_frontend_tda10086_attach, |
| 685 | .tuner_attach = ttusb2_tuner_tda826x_attach, |
Andre Weidemann | 8c899bc | 2008-03-29 21:30:49 -0300 | [diff] [blame] | 686 | |
| 687 | /* parameter for the MPEG2-data transfer */ |
| 688 | .stream = { |
| 689 | .type = USB_ISOC, |
| 690 | .count = 5, |
| 691 | .endpoint = 0x02, |
| 692 | .u = { |
| 693 | .isoc = { |
| 694 | .framesperurb = 4, |
| 695 | .framesize = 940, |
| 696 | .interval = 1, |
| 697 | } |
| 698 | } |
| 699 | } |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 700 | }}, |
Andre Weidemann | 8c899bc | 2008-03-29 21:30:49 -0300 | [diff] [blame] | 701 | } |
| 702 | }, |
| 703 | |
| 704 | .power_ctrl = ttusb2_power_ctrl, |
| 705 | .identify_state = ttusb2_identify_state, |
| 706 | |
| 707 | .i2c_algo = &ttusb2_i2c_algo, |
| 708 | |
| 709 | .generic_bulk_ctrl_endpoint = 0x01, |
| 710 | |
| 711 | .num_device_descs = 1, |
| 712 | .devices = { |
| 713 | { "Technotrend TT-connect S-2400", |
| 714 | { &ttusb2_table[2], NULL }, |
| 715 | { NULL }, |
| 716 | }, |
| 717 | } |
| 718 | }; |
| 719 | |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 720 | static struct dvb_usb_device_properties ttusb2_properties_ct3650 = { |
| 721 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 722 | |
| 723 | .usb_ctrl = CYPRESS_FX2, |
| 724 | |
| 725 | .size_of_priv = sizeof(struct ttusb2_state), |
| 726 | |
David Henningsson | 9d1da73 | 2010-12-26 10:23:58 -0300 | [diff] [blame] | 727 | .rc.core = { |
| 728 | .rc_interval = 150, /* Less than IR_KEYPRESS_TIMEOUT */ |
| 729 | .rc_codes = RC_MAP_TT_1500, |
| 730 | .rc_query = tt3650_rc_query, |
| 731 | .allowed_protos = RC_TYPE_UNKNOWN, |
| 732 | }, |
| 733 | |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 734 | .num_adapters = 1, |
| 735 | .adapter = { |
| 736 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 737 | .num_frontends = 2, |
| 738 | .fe = {{ |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 739 | .streaming_ctrl = NULL, |
| 740 | |
| 741 | .frontend_attach = ttusb2_frontend_tda10023_attach, |
| 742 | .tuner_attach = ttusb2_tuner_tda827x_attach, |
| 743 | |
| 744 | /* parameter for the MPEG2-data transfer */ |
| 745 | .stream = { |
| 746 | .type = USB_ISOC, |
| 747 | .count = 5, |
| 748 | .endpoint = 0x02, |
| 749 | .u = { |
| 750 | .isoc = { |
| 751 | .framesperurb = 4, |
| 752 | .framesize = 940, |
| 753 | .interval = 1, |
| 754 | } |
| 755 | } |
| 756 | } |
Michael Krufky | 1645c87 | 2011-09-16 09:36:56 -0300 | [diff] [blame] | 757 | }, { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 758 | .streaming_ctrl = NULL, |
| 759 | |
| 760 | .frontend_attach = ttusb2_frontend_tda10023_attach, |
| 761 | .tuner_attach = ttusb2_tuner_tda827x_attach, |
| 762 | |
| 763 | /* parameter for the MPEG2-data transfer */ |
| 764 | .stream = { |
| 765 | .type = USB_ISOC, |
| 766 | .count = 5, |
| 767 | .endpoint = 0x02, |
| 768 | .u = { |
| 769 | .isoc = { |
| 770 | .framesperurb = 4, |
| 771 | .framesize = 940, |
| 772 | .interval = 1, |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | }}, |
Guy Martin | 76952c7 | 2010-05-07 04:09:25 -0300 | [diff] [blame] | 777 | }, |
| 778 | }, |
| 779 | |
| 780 | .power_ctrl = ttusb2_power_ctrl, |
| 781 | .identify_state = ttusb2_identify_state, |
| 782 | |
| 783 | .i2c_algo = &ttusb2_i2c_algo, |
| 784 | |
| 785 | .generic_bulk_ctrl_endpoint = 0x01, |
| 786 | |
| 787 | .num_device_descs = 1, |
| 788 | .devices = { |
| 789 | { "Technotrend TT-connect CT-3650", |
| 790 | .warm_ids = { &ttusb2_table[3], NULL }, |
| 791 | }, |
| 792 | } |
| 793 | }; |
| 794 | |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 795 | static struct usb_driver ttusb2_driver = { |
| 796 | .name = "dvb_usb_ttusb2", |
| 797 | .probe = ttusb2_probe, |
Jose Alberto Reguero | 8c0bc03 | 2011-09-18 07:59:05 -0300 | [diff] [blame] | 798 | .disconnect = ttusb2_usb_disconnect, |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 799 | .id_table = ttusb2_table, |
| 800 | }; |
| 801 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 802 | module_usb_driver(ttusb2_driver); |
Patrick Boettcher | bc2e391 | 2006-12-02 21:16:04 -0200 | [diff] [blame] | 803 | |
| 804 | MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>"); |
| 805 | MODULE_DESCRIPTION("Driver for Pinnacle PCTV 400e DVB-S USB2.0"); |
| 806 | MODULE_VERSION("1.0"); |
| 807 | MODULE_LICENSE("GPL"); |