ttusb2.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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. #include "ttusb2.h"
  28. #include "tda826x.h"
  29. #include "tda10086.h"
  30. #include "tda1002x.h"
  31. #include "tda10048.h"
  32. #include "tda827x.h"
  33. #include "lnbp21.h"
  34. /* debug */
  35. static int dvb_usb_ttusb2_debug;
  36. #define deb_info(args...) dprintk(dvb_usb_ttusb2_debug,0x01,args)
  37. module_param_named(debug,dvb_usb_ttusb2_debug, int, 0644);
  38. MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." DVB_USB_DEBUG_STATUS);
  39. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  40. struct ttusb2_state {
  41. u8 id;
  42. u16 last_rc_key;
  43. };
  44. static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd,
  45. u8 *wbuf, int wlen, u8 *rbuf, int rlen)
  46. {
  47. struct ttusb2_state *st = d->priv;
  48. u8 s[wlen+4],r[64] = { 0 };
  49. int ret = 0;
  50. memset(s,0,wlen+4);
  51. s[0] = 0xaa;
  52. s[1] = ++st->id;
  53. s[2] = cmd;
  54. s[3] = wlen;
  55. memcpy(&s[4],wbuf,wlen);
  56. ret = dvb_usb_generic_rw(d, s, wlen+4, r, 64, 0);
  57. if (ret != 0 ||
  58. r[0] != 0x55 ||
  59. r[1] != s[1] ||
  60. r[2] != cmd ||
  61. (rlen > 0 && r[3] != rlen)) {
  62. warn("there might have been an error during control message transfer. (rlen = %d, was %d)",rlen,r[3]);
  63. return -EIO;
  64. }
  65. if (rlen > 0)
  66. memcpy(rbuf, &r[4], rlen);
  67. return 0;
  68. }
  69. static int ttusb2_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
  70. {
  71. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  72. static u8 obuf[60], ibuf[60];
  73. int i, write_read, read;
  74. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  75. return -EAGAIN;
  76. if (num > 2)
  77. warn("more than 2 i2c messages at a time is not handled yet. TODO.");
  78. for (i = 0; i < num; i++) {
  79. write_read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
  80. read = msg[i].flags & I2C_M_RD;
  81. obuf[0] = (msg[i].addr << 1) | (write_read | read);
  82. if (read)
  83. obuf[1] = 0;
  84. else
  85. obuf[1] = msg[i].len;
  86. /* read request */
  87. if (write_read)
  88. obuf[2] = msg[i+1].len;
  89. else if (read)
  90. obuf[2] = msg[i].len;
  91. else
  92. obuf[2] = 0;
  93. memcpy(&obuf[3], msg[i].buf, msg[i].len);
  94. if (ttusb2_msg(d, CMD_I2C_XFER, obuf, msg[i].len+3, ibuf, obuf[2] + 3) < 0) {
  95. err("i2c transfer failed.");
  96. break;
  97. }
  98. if (write_read) {
  99. memcpy(msg[i+1].buf, &ibuf[3], msg[i+1].len);
  100. i++;
  101. } else if (read)
  102. memcpy(msg[i].buf, &ibuf[3], msg[i].len);
  103. }
  104. mutex_unlock(&d->i2c_mutex);
  105. return i;
  106. }
  107. static u32 ttusb2_i2c_func(struct i2c_adapter *adapter)
  108. {
  109. return I2C_FUNC_I2C;
  110. }
  111. static struct i2c_algorithm ttusb2_i2c_algo = {
  112. .master_xfer = ttusb2_i2c_xfer,
  113. .functionality = ttusb2_i2c_func,
  114. };
  115. /* command to poll IR receiver (copied from pctv452e.c) */
  116. #define CMD_GET_IR_CODE 0x1b
  117. /* IR */
  118. static int tt3650_rc_query(struct dvb_usb_device *d)
  119. {
  120. int ret;
  121. u8 rx[9]; /* A CMD_GET_IR_CODE reply is 9 bytes long */
  122. struct ttusb2_state *st = d->priv;
  123. ret = ttusb2_msg(d, CMD_GET_IR_CODE, NULL, 0, rx, sizeof(rx));
  124. if (ret != 0)
  125. return ret;
  126. if (rx[8] & 0x01) {
  127. /* got a "press" event */
  128. st->last_rc_key = (rx[3] << 8) | rx[2];
  129. deb_info("%s: cmd=0x%02x sys=0x%02x\n", __func__, rx[2], rx[3]);
  130. rc_keydown(d->rc_dev, st->last_rc_key, 0);
  131. } else if (st->last_rc_key) {
  132. rc_keyup(d->rc_dev);
  133. st->last_rc_key = 0;
  134. }
  135. return 0;
  136. }
  137. /* Callbacks for DVB USB */
  138. static int ttusb2_identify_state (struct usb_device *udev, struct
  139. dvb_usb_device_properties *props, struct dvb_usb_device_description **desc,
  140. int *cold)
  141. {
  142. *cold = udev->descriptor.iManufacturer == 0 && udev->descriptor.iProduct == 0;
  143. return 0;
  144. }
  145. static int ttusb2_power_ctrl(struct dvb_usb_device *d, int onoff)
  146. {
  147. u8 b = onoff;
  148. ttusb2_msg(d, CMD_POWER, &b, 0, NULL, 0);
  149. return ttusb2_msg(d, CMD_POWER, &b, 1, NULL, 0);
  150. }
  151. static struct tda10086_config tda10086_config = {
  152. .demod_address = 0x0e,
  153. .invert = 0,
  154. .diseqc_tone = 1,
  155. .xtal_freq = TDA10086_XTAL_16M,
  156. };
  157. static struct tda10023_config tda10023_config = {
  158. .demod_address = 0x0c,
  159. .invert = 0,
  160. .xtal = 16000000,
  161. .pll_m = 11,
  162. .pll_p = 3,
  163. .pll_n = 1,
  164. .deltaf = 0xa511,
  165. };
  166. static struct tda10048_config tda10048_config = {
  167. .demod_address = 0x10 >> 1,
  168. .output_mode = TDA10048_PARALLEL_OUTPUT,
  169. .inversion = TDA10048_INVERSION_ON,
  170. .dtv6_if_freq_khz = TDA10048_IF_4000,
  171. .dtv7_if_freq_khz = TDA10048_IF_4500,
  172. .dtv8_if_freq_khz = TDA10048_IF_5000,
  173. .clk_freq_khz = TDA10048_CLK_16000,
  174. .no_firmware = 1,
  175. .set_pll = true ,
  176. .pll_m = 5,
  177. .pll_n = 3,
  178. .pll_p = 0,
  179. };
  180. static struct tda827x_config tda827x_config = {
  181. .config = 0,
  182. };
  183. static int ttusb2_frontend_tda10086_attach(struct dvb_usb_adapter *adap)
  184. {
  185. if (usb_set_interface(adap->dev->udev,0,3) < 0)
  186. err("set interface to alts=3 failed");
  187. if ((adap->fe[0] = dvb_attach(tda10086_attach, &tda10086_config, &adap->dev->i2c_adap)) == NULL) {
  188. deb_info("TDA10086 attach failed\n");
  189. return -ENODEV;
  190. }
  191. return 0;
  192. }
  193. static int ttusb2_ct3650_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
  194. {
  195. struct dvb_usb_adapter *adap = fe->dvb->priv;
  196. return adap->fe[0]->ops.i2c_gate_ctrl(adap->fe[0], enable);
  197. }
  198. static int ttusb2_frontend_tda10023_attach(struct dvb_usb_adapter *adap)
  199. {
  200. if (usb_set_interface(adap->dev->udev, 0, 3) < 0)
  201. err("set interface to alts=3 failed");
  202. if (adap->fe[0] == NULL) {
  203. /* FE 0 DVB-C */
  204. adap->fe[0] = dvb_attach(tda10023_attach,
  205. &tda10023_config, &adap->dev->i2c_adap, 0x48);
  206. if (adap->fe[0] == NULL) {
  207. deb_info("TDA10023 attach failed\n");
  208. return -ENODEV;
  209. }
  210. } else {
  211. adap->fe[1] = dvb_attach(tda10048_attach,
  212. &tda10048_config, &adap->dev->i2c_adap);
  213. if (adap->fe[1] == NULL) {
  214. deb_info("TDA10048 attach failed\n");
  215. return -ENODEV;
  216. }
  217. /* tuner is behind TDA10023 I2C-gate */
  218. adap->fe[1]->ops.i2c_gate_ctrl = ttusb2_ct3650_i2c_gate_ctrl;
  219. }
  220. return 0;
  221. }
  222. static int ttusb2_tuner_tda827x_attach(struct dvb_usb_adapter *adap)
  223. {
  224. struct dvb_frontend *fe;
  225. /* MFE: select correct FE to attach tuner since that's called twice */
  226. if (adap->fe[1] == NULL)
  227. fe = adap->fe[0];
  228. else
  229. fe = adap->fe[1];
  230. /* attach tuner */
  231. if (dvb_attach(tda827x_attach, fe, 0x61, &adap->dev->i2c_adap, &tda827x_config) == NULL) {
  232. printk(KERN_ERR "%s: No tda827x found!\n", __func__);
  233. return -ENODEV;
  234. }
  235. return 0;
  236. }
  237. static int ttusb2_tuner_tda826x_attach(struct dvb_usb_adapter *adap)
  238. {
  239. if (dvb_attach(tda826x_attach, adap->fe[0], 0x60, &adap->dev->i2c_adap, 0) == NULL) {
  240. deb_info("TDA8263 attach failed\n");
  241. return -ENODEV;
  242. }
  243. if (dvb_attach(lnbp21_attach, adap->fe[0], &adap->dev->i2c_adap, 0, 0) == NULL) {
  244. deb_info("LNBP21 attach failed\n");
  245. return -ENODEV;
  246. }
  247. return 0;
  248. }
  249. /* DVB USB Driver stuff */
  250. static struct dvb_usb_device_properties ttusb2_properties;
  251. static struct dvb_usb_device_properties ttusb2_properties_s2400;
  252. static struct dvb_usb_device_properties ttusb2_properties_ct3650;
  253. static int ttusb2_probe(struct usb_interface *intf,
  254. const struct usb_device_id *id)
  255. {
  256. if (0 == dvb_usb_device_init(intf, &ttusb2_properties,
  257. THIS_MODULE, NULL, adapter_nr) ||
  258. 0 == dvb_usb_device_init(intf, &ttusb2_properties_s2400,
  259. THIS_MODULE, NULL, adapter_nr) ||
  260. 0 == dvb_usb_device_init(intf, &ttusb2_properties_ct3650,
  261. THIS_MODULE, NULL, adapter_nr))
  262. return 0;
  263. return -ENODEV;
  264. }
  265. static struct usb_device_id ttusb2_table [] = {
  266. { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_400E) },
  267. { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_450E) },
  268. { USB_DEVICE(USB_VID_TECHNOTREND,
  269. USB_PID_TECHNOTREND_CONNECT_S2400) },
  270. { USB_DEVICE(USB_VID_TECHNOTREND,
  271. USB_PID_TECHNOTREND_CONNECT_CT3650) },
  272. {} /* Terminating entry */
  273. };
  274. MODULE_DEVICE_TABLE (usb, ttusb2_table);
  275. static struct dvb_usb_device_properties ttusb2_properties = {
  276. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  277. .usb_ctrl = CYPRESS_FX2,
  278. .firmware = "dvb-usb-pctv-400e-01.fw",
  279. .size_of_priv = sizeof(struct ttusb2_state),
  280. .num_adapters = 1,
  281. .adapter = {
  282. {
  283. .streaming_ctrl = NULL, // ttusb2_streaming_ctrl,
  284. .frontend_attach = ttusb2_frontend_tda10086_attach,
  285. .tuner_attach = ttusb2_tuner_tda826x_attach,
  286. /* parameter for the MPEG2-data transfer */
  287. .stream = {
  288. .type = USB_ISOC,
  289. .count = 5,
  290. .endpoint = 0x02,
  291. .u = {
  292. .isoc = {
  293. .framesperurb = 4,
  294. .framesize = 940,
  295. .interval = 1,
  296. }
  297. }
  298. }
  299. }
  300. },
  301. .power_ctrl = ttusb2_power_ctrl,
  302. .identify_state = ttusb2_identify_state,
  303. .i2c_algo = &ttusb2_i2c_algo,
  304. .generic_bulk_ctrl_endpoint = 0x01,
  305. .num_device_descs = 2,
  306. .devices = {
  307. { "Pinnacle 400e DVB-S USB2.0",
  308. { &ttusb2_table[0], NULL },
  309. { NULL },
  310. },
  311. { "Pinnacle 450e DVB-S USB2.0",
  312. { &ttusb2_table[1], NULL },
  313. { NULL },
  314. },
  315. }
  316. };
  317. static struct dvb_usb_device_properties ttusb2_properties_s2400 = {
  318. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  319. .usb_ctrl = CYPRESS_FX2,
  320. .firmware = "dvb-usb-tt-s2400-01.fw",
  321. .size_of_priv = sizeof(struct ttusb2_state),
  322. .num_adapters = 1,
  323. .adapter = {
  324. {
  325. .streaming_ctrl = NULL,
  326. .frontend_attach = ttusb2_frontend_tda10086_attach,
  327. .tuner_attach = ttusb2_tuner_tda826x_attach,
  328. /* parameter for the MPEG2-data transfer */
  329. .stream = {
  330. .type = USB_ISOC,
  331. .count = 5,
  332. .endpoint = 0x02,
  333. .u = {
  334. .isoc = {
  335. .framesperurb = 4,
  336. .framesize = 940,
  337. .interval = 1,
  338. }
  339. }
  340. }
  341. }
  342. },
  343. .power_ctrl = ttusb2_power_ctrl,
  344. .identify_state = ttusb2_identify_state,
  345. .i2c_algo = &ttusb2_i2c_algo,
  346. .generic_bulk_ctrl_endpoint = 0x01,
  347. .num_device_descs = 1,
  348. .devices = {
  349. { "Technotrend TT-connect S-2400",
  350. { &ttusb2_table[2], NULL },
  351. { NULL },
  352. },
  353. }
  354. };
  355. static struct dvb_usb_device_properties ttusb2_properties_ct3650 = {
  356. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  357. .usb_ctrl = CYPRESS_FX2,
  358. .size_of_priv = sizeof(struct ttusb2_state),
  359. .rc.core = {
  360. .rc_interval = 150, /* Less than IR_KEYPRESS_TIMEOUT */
  361. .rc_codes = RC_MAP_TT_1500,
  362. .rc_query = tt3650_rc_query,
  363. .allowed_protos = RC_TYPE_UNKNOWN,
  364. },
  365. .num_adapters = 1,
  366. .adapter = {
  367. {
  368. .streaming_ctrl = NULL,
  369. .num_frontends = 2,
  370. .frontend_attach = ttusb2_frontend_tda10023_attach,
  371. .tuner_attach = ttusb2_tuner_tda827x_attach,
  372. /* parameter for the MPEG2-data transfer */
  373. .stream = {
  374. .type = USB_ISOC,
  375. .count = 5,
  376. .endpoint = 0x02,
  377. .u = {
  378. .isoc = {
  379. .framesperurb = 4,
  380. .framesize = 940,
  381. .interval = 1,
  382. }
  383. }
  384. }
  385. },
  386. },
  387. .power_ctrl = ttusb2_power_ctrl,
  388. .identify_state = ttusb2_identify_state,
  389. .i2c_algo = &ttusb2_i2c_algo,
  390. .generic_bulk_ctrl_endpoint = 0x01,
  391. .num_device_descs = 1,
  392. .devices = {
  393. { "Technotrend TT-connect CT-3650",
  394. .warm_ids = { &ttusb2_table[3], NULL },
  395. },
  396. }
  397. };
  398. static struct usb_driver ttusb2_driver = {
  399. .name = "dvb_usb_ttusb2",
  400. .probe = ttusb2_probe,
  401. .disconnect = dvb_usb_device_exit,
  402. .id_table = ttusb2_table,
  403. };
  404. /* module stuff */
  405. static int __init ttusb2_module_init(void)
  406. {
  407. int result;
  408. if ((result = usb_register(&ttusb2_driver))) {
  409. err("usb_register failed. Error number %d",result);
  410. return result;
  411. }
  412. return 0;
  413. }
  414. static void __exit ttusb2_module_exit(void)
  415. {
  416. /* deregister this driver from the USB subsystem */
  417. usb_deregister(&ttusb2_driver);
  418. }
  419. module_init (ttusb2_module_init);
  420. module_exit (ttusb2_module_exit);
  421. MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
  422. MODULE_DESCRIPTION("Driver for Pinnacle PCTV 400e DVB-S USB2.0");
  423. MODULE_VERSION("1.0");
  424. MODULE_LICENSE("GPL");