ttusb2.c 9.5 KB

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