ttusb2.c 10 KB

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