ttusb2.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 "lnbp21.h"
  31. /* debug */
  32. static int dvb_usb_ttusb2_debug;
  33. #define deb_info(args...) dprintk(dvb_usb_ttusb2_debug,0x01,args)
  34. module_param_named(debug,dvb_usb_ttusb2_debug, int, 0644);
  35. MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." DVB_USB_DEBUG_STATUS);
  36. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  37. struct ttusb2_state {
  38. u8 id;
  39. };
  40. static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd,
  41. u8 *wbuf, int wlen, u8 *rbuf, int rlen)
  42. {
  43. struct ttusb2_state *st = d->priv;
  44. u8 s[wlen+4],r[64] = { 0 };
  45. int ret = 0;
  46. memset(s,0,wlen+4);
  47. s[0] = 0xaa;
  48. s[1] = ++st->id;
  49. s[2] = cmd;
  50. s[3] = wlen;
  51. memcpy(&s[4],wbuf,wlen);
  52. ret = dvb_usb_generic_rw(d, s, wlen+4, r, 64, 0);
  53. if (ret != 0 ||
  54. r[0] != 0x55 ||
  55. r[1] != s[1] ||
  56. r[2] != cmd ||
  57. (rlen > 0 && r[3] != rlen)) {
  58. warn("there might have been an error during control message transfer. (rlen = %d, was %d)",rlen,r[3]);
  59. return -EIO;
  60. }
  61. if (rlen > 0)
  62. memcpy(rbuf, &r[4], rlen);
  63. return 0;
  64. }
  65. static int ttusb2_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
  66. {
  67. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  68. static u8 obuf[60], ibuf[60];
  69. int i,read;
  70. if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
  71. return -EAGAIN;
  72. if (num > 2)
  73. warn("more than 2 i2c messages at a time is not handled yet. TODO.");
  74. for (i = 0; i < num; i++) {
  75. read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
  76. obuf[0] = (msg[i].addr << 1) | read;
  77. obuf[1] = msg[i].len;
  78. /* read request */
  79. if (read)
  80. obuf[2] = msg[i+1].len;
  81. else
  82. obuf[2] = 0;
  83. memcpy(&obuf[3],msg[i].buf,msg[i].len);
  84. if (ttusb2_msg(d, CMD_I2C_XFER, obuf, msg[i].len+3, ibuf, obuf[2] + 3) < 0) {
  85. err("i2c transfer failed.");
  86. break;
  87. }
  88. if (read) {
  89. memcpy(msg[i+1].buf,&ibuf[3],msg[i+1].len);
  90. i++;
  91. }
  92. }
  93. mutex_unlock(&d->i2c_mutex);
  94. return i;
  95. }
  96. static u32 ttusb2_i2c_func(struct i2c_adapter *adapter)
  97. {
  98. return I2C_FUNC_I2C;
  99. }
  100. static struct i2c_algorithm ttusb2_i2c_algo = {
  101. .master_xfer = ttusb2_i2c_xfer,
  102. .functionality = ttusb2_i2c_func,
  103. };
  104. /* Callbacks for DVB USB */
  105. static int ttusb2_identify_state (struct usb_device *udev, struct
  106. dvb_usb_device_properties *props, struct dvb_usb_device_description **desc,
  107. int *cold)
  108. {
  109. *cold = udev->descriptor.iManufacturer == 0 && udev->descriptor.iProduct == 0;
  110. return 0;
  111. }
  112. static int ttusb2_power_ctrl(struct dvb_usb_device *d, int onoff)
  113. {
  114. u8 b = onoff;
  115. ttusb2_msg(d, CMD_POWER, &b, 0, NULL, 0);
  116. return ttusb2_msg(d, CMD_POWER, &b, 1, NULL, 0);
  117. }
  118. static struct tda10086_config tda10086_config = {
  119. .demod_address = 0x0e,
  120. .invert = 0,
  121. .diseqc_tone = 1,
  122. .xtal_freq = TDA10086_XTAL_16M,
  123. };
  124. static int ttusb2_frontend_attach(struct dvb_usb_adapter *adap)
  125. {
  126. if (usb_set_interface(adap->dev->udev,0,3) < 0)
  127. err("set interface to alts=3 failed");
  128. if ((adap->fe = dvb_attach(tda10086_attach, &tda10086_config, &adap->dev->i2c_adap)) == NULL) {
  129. deb_info("TDA10086 attach failed\n");
  130. return -ENODEV;
  131. }
  132. return 0;
  133. }
  134. static int ttusb2_tuner_attach(struct dvb_usb_adapter *adap)
  135. {
  136. if (dvb_attach(tda826x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, 0) == NULL) {
  137. deb_info("TDA8263 attach failed\n");
  138. return -ENODEV;
  139. }
  140. if (dvb_attach(lnbp21_attach, adap->fe, &adap->dev->i2c_adap, 0, 0) == NULL) {
  141. deb_info("LNBP21 attach failed\n");
  142. return -ENODEV;
  143. }
  144. return 0;
  145. }
  146. /* DVB USB Driver stuff */
  147. static struct dvb_usb_device_properties ttusb2_properties;
  148. static struct dvb_usb_device_properties ttusb2_properties_s2400;
  149. static int ttusb2_probe(struct usb_interface *intf,
  150. const struct usb_device_id *id)
  151. {
  152. if (0 == dvb_usb_device_init(intf, &ttusb2_properties,
  153. THIS_MODULE, NULL, adapter_nr) ||
  154. 0 == dvb_usb_device_init(intf, &ttusb2_properties_s2400,
  155. THIS_MODULE, NULL, adapter_nr))
  156. return 0;
  157. return -ENODEV;
  158. }
  159. static struct usb_device_id ttusb2_table [] = {
  160. { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_400E) },
  161. { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_450E) },
  162. { USB_DEVICE(USB_VID_TECHNOTREND,
  163. USB_PID_TECHNOTREND_CONNECT_S2400) },
  164. {} /* Terminating entry */
  165. };
  166. MODULE_DEVICE_TABLE (usb, ttusb2_table);
  167. static struct dvb_usb_device_properties ttusb2_properties = {
  168. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  169. .usb_ctrl = CYPRESS_FX2,
  170. .firmware = "dvb-usb-pctv-400e-01.fw",
  171. .size_of_priv = sizeof(struct ttusb2_state),
  172. .num_adapters = 1,
  173. .adapter = {
  174. {
  175. .streaming_ctrl = NULL, // ttusb2_streaming_ctrl,
  176. .frontend_attach = ttusb2_frontend_attach,
  177. .tuner_attach = ttusb2_tuner_attach,
  178. /* parameter for the MPEG2-data transfer */
  179. .stream = {
  180. .type = USB_ISOC,
  181. .count = 5,
  182. .endpoint = 0x02,
  183. .u = {
  184. .isoc = {
  185. .framesperurb = 4,
  186. .framesize = 940,
  187. .interval = 1,
  188. }
  189. }
  190. }
  191. }
  192. },
  193. .power_ctrl = ttusb2_power_ctrl,
  194. .identify_state = ttusb2_identify_state,
  195. .i2c_algo = &ttusb2_i2c_algo,
  196. .generic_bulk_ctrl_endpoint = 0x01,
  197. .num_device_descs = 2,
  198. .devices = {
  199. { "Pinnacle 400e DVB-S USB2.0",
  200. { &ttusb2_table[0], NULL },
  201. { NULL },
  202. },
  203. { "Pinnacle 450e DVB-S USB2.0",
  204. { &ttusb2_table[1], NULL },
  205. { NULL },
  206. },
  207. }
  208. };
  209. static struct dvb_usb_device_properties ttusb2_properties_s2400 = {
  210. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  211. .usb_ctrl = CYPRESS_FX2,
  212. .firmware = "dvb-usb-tt-s2400-01.fw",
  213. .size_of_priv = sizeof(struct ttusb2_state),
  214. .num_adapters = 1,
  215. .adapter = {
  216. {
  217. .streaming_ctrl = NULL,
  218. .frontend_attach = ttusb2_frontend_attach,
  219. .tuner_attach = ttusb2_tuner_attach,
  220. /* parameter for the MPEG2-data transfer */
  221. .stream = {
  222. .type = USB_ISOC,
  223. .count = 5,
  224. .endpoint = 0x02,
  225. .u = {
  226. .isoc = {
  227. .framesperurb = 4,
  228. .framesize = 940,
  229. .interval = 1,
  230. }
  231. }
  232. }
  233. }
  234. },
  235. .power_ctrl = ttusb2_power_ctrl,
  236. .identify_state = ttusb2_identify_state,
  237. .i2c_algo = &ttusb2_i2c_algo,
  238. .generic_bulk_ctrl_endpoint = 0x01,
  239. .num_device_descs = 1,
  240. .devices = {
  241. { "Technotrend TT-connect S-2400",
  242. { &ttusb2_table[2], NULL },
  243. { NULL },
  244. },
  245. }
  246. };
  247. static struct usb_driver ttusb2_driver = {
  248. .name = "dvb_usb_ttusb2",
  249. .probe = ttusb2_probe,
  250. .disconnect = dvb_usb_device_exit,
  251. .id_table = ttusb2_table,
  252. };
  253. /* module stuff */
  254. static int __init ttusb2_module_init(void)
  255. {
  256. int result;
  257. if ((result = usb_register(&ttusb2_driver))) {
  258. err("usb_register failed. Error number %d",result);
  259. return result;
  260. }
  261. return 0;
  262. }
  263. static void __exit ttusb2_module_exit(void)
  264. {
  265. /* deregister this driver from the USB subsystem */
  266. usb_deregister(&ttusb2_driver);
  267. }
  268. module_init (ttusb2_module_init);
  269. module_exit (ttusb2_module_exit);
  270. MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
  271. MODULE_DESCRIPTION("Driver for Pinnacle PCTV 400e DVB-S USB2.0");
  272. MODULE_VERSION("1.0");
  273. MODULE_LICENSE("GPL");