digitv.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /* DVB USB compliant linux driver for Nebula Electronics uDigiTV DVB-T USB2.0
  2. * receiver
  3. *
  4. * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de) and
  5. * Allan Third (allan.third@cs.man.ac.uk)
  6. *
  7. * partly based on the SDK published by Nebula Electronics (TODO do we want this line ?)
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation, version 2.
  12. *
  13. * see Documentation/dvb/README.dvb-usb for more information
  14. */
  15. #include "digitv.h"
  16. #include "mt352.h"
  17. #include "nxt6000.h"
  18. /* debug */
  19. int dvb_usb_digitv_debug;
  20. module_param_named(debug,dvb_usb_digitv_debug, int, 0644);
  21. MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
  22. static int digitv_ctrl_msg(struct dvb_usb_device *d,
  23. u8 cmd, u8 vv, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
  24. {
  25. int wo = (rbuf == NULL || rlen == 0); /* write-only */
  26. u8 sndbuf[7],rcvbuf[7];
  27. memset(sndbuf,0,7); memset(rcvbuf,0,7);
  28. sndbuf[0] = cmd;
  29. sndbuf[1] = vv;
  30. sndbuf[2] = wo ? wlen : rlen;
  31. if (!wo) {
  32. memcpy(&sndbuf[3],wbuf,wlen);
  33. dvb_usb_generic_write(d,sndbuf,7);
  34. } else {
  35. dvb_usb_generic_rw(d,sndbuf,7,rcvbuf,7,10);
  36. memcpy(&rbuf,&rcvbuf[3],rlen);
  37. }
  38. return 0;
  39. }
  40. /* I2C */
  41. static int digitv_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
  42. {
  43. struct dvb_usb_device *d = i2c_get_adapdata(adap);
  44. int i;
  45. if (down_interruptible(&d->i2c_sem) < 0)
  46. return -EAGAIN;
  47. if (num > 2)
  48. warn("more than 2 i2c messages at a time is not handled yet. TODO.");
  49. for (i = 0; i < num; i++) {
  50. /* write/read request */
  51. if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
  52. if (digitv_ctrl_msg(d, USB_READ_COFDM, msg[i].buf[0], NULL, 0,
  53. msg[i+1].buf,msg[i+1].len) < 0)
  54. break;
  55. i++;
  56. } else
  57. if (digitv_ctrl_msg(d,USB_WRITE_COFDM, msg[i].buf[0],
  58. &msg[i].buf[1],msg[i].len-1,NULL,0) < 0)
  59. break;
  60. }
  61. up(&d->i2c_sem);
  62. return i;
  63. }
  64. static u32 digitv_i2c_func(struct i2c_adapter *adapter)
  65. {
  66. return I2C_FUNC_I2C;
  67. }
  68. static struct i2c_algorithm digitv_i2c_algo = {
  69. .name = "Nebula DigiTV USB I2C algorithm",
  70. .id = I2C_ALGO_BIT,
  71. .master_xfer = digitv_i2c_xfer,
  72. .functionality = digitv_i2c_func,
  73. };
  74. /* Callbacks for DVB USB */
  75. static int digitv_identify_state (struct usb_device *udev, struct
  76. dvb_usb_properties *props, struct dvb_usb_device_description **desc,
  77. int *cold)
  78. {
  79. *cold = udev->descriptor.iManufacturer == 0 && udev->descriptor.iProduct == 0;
  80. return 0;
  81. }
  82. static int digitv_mt352_demod_init(struct dvb_frontend *fe)
  83. {
  84. static u8 mt352_clock_config[] = { 0x89, 0x38, 0x2d };
  85. static u8 mt352_reset[] = { 0x50, 0x80 };
  86. static u8 mt352_mclk_ratio[] = { 0x8b, 0x00 };
  87. static u8 mt352_agc_cfg[] = { 0x68, 0xa0 };
  88. static u8 mt352_adc_ctl_1_cfg[] = { 0x8E, 0xa0 };
  89. static u8 mt352_acq_ctl[] = { 0x53, 0x50 };
  90. static u8 mt352_agc_target[] = { 0x67, 0x20 };
  91. static u8 mt352_rs_err_per[] = { 0x7c, 0x00, 0x01 };
  92. static u8 mt352_snr_select[] = { 0x79, 0x00, 0x20 };
  93. static u8 mt352_input_freq_1[] = { 0x56, 0x31, 0x05 };
  94. static u8 mt352_scan_ctl[] = { 0x88, 0x0f };
  95. static u8 mt352_capt_range[] = { 0x75, 0x32 };
  96. mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config));
  97. mt352_write(fe, mt352_reset, sizeof(mt352_reset));
  98. msleep(1);
  99. mt352_write(fe, mt352_mclk_ratio, sizeof(mt352_mclk_ratio));
  100. mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg));
  101. mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg));
  102. mt352_write(fe, mt352_acq_ctl, sizeof(mt352_acq_ctl));
  103. mt352_write(fe, mt352_agc_target, sizeof(mt352_agc_target));
  104. mt352_write(fe, mt352_rs_err_per, sizeof(mt352_rs_err_per));
  105. mt352_write(fe, mt352_snr_select, sizeof(mt352_snr_select));
  106. mt352_write(fe, mt352_input_freq_1, sizeof(mt352_input_freq_1));
  107. mt352_write(fe, mt352_scan_ctl, sizeof(mt352_scan_ctl));
  108. mt352_write(fe, mt352_capt_range, sizeof(mt352_capt_range));
  109. return 0;
  110. }
  111. static struct mt352_config digitv_mt352_config = {
  112. .demod_address = 0x0, /* ignored by the digitv anyway */
  113. .demod_init = digitv_mt352_demod_init,
  114. .pll_set = NULL, /* TODO */
  115. };
  116. static struct nxt6000_config digitv_nxt6000_config = {
  117. .demod_address = 0x0, /* ignored by the digitv anyway */
  118. .clock_inversion = 0x0,
  119. .pll_init = NULL,
  120. .pll_set = NULL,
  121. };
  122. static int digitv_frontend_attach(struct dvb_usb_device *d)
  123. {
  124. if ((d->fe = mt352_attach(&digitv_mt352_config, &d->i2c_adap)) == NULL)
  125. return 0;
  126. if ((d->fe = nxt6000_attach(&digitv_nxt6000_config, &d->i2c_adap)) == NULL) {
  127. warn("nxt6000 support is not done yet, in fact you are one of the first "
  128. "person who wants to use this device in Linux. Please report to "
  129. "linux-dvb@linuxtv.org");
  130. return 0;
  131. }
  132. return -EIO;
  133. }
  134. static struct dvb_usb_rc_key digitv_rc_keys[] = {
  135. { 0x00, 0x16, KEY_POWER }, /* dummy key */
  136. };
  137. /* TODO is it really the NEC protocol ? */
  138. int digitv_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
  139. {
  140. u8 key[5];
  141. digitv_ctrl_msg(d,USB_READ_REMOTE,0,NULL,0,&key[1],4);
  142. /* TODO state, maybe it is VV ? */
  143. if (key[1] != 0)
  144. key[0] = 0x01; /* if something is inside the buffer, simulate key press */
  145. /* call the universal NEC remote processor, to find out the key's state and event */
  146. dvb_usb_nec_rc_key_to_event(d,key,event,state);
  147. if (key[0] != 0)
  148. deb_rc("key: %x %x %x %x %x\n",key[0],key[1],key[2],key[3],key[4]);
  149. return 0;
  150. }
  151. /* DVB USB Driver stuff */
  152. static struct dvb_usb_properties digitv_properties;
  153. static int digitv_probe(struct usb_interface *intf,
  154. const struct usb_device_id *id)
  155. {
  156. return dvb_usb_device_init(intf,&digitv_properties,THIS_MODULE);
  157. }
  158. static struct usb_device_id digitv_table [] = {
  159. { USB_DEVICE(USB_VID_ANCHOR, USB_PID_NEBULA_DIGITV) },
  160. { } /* Terminating entry */
  161. };
  162. MODULE_DEVICE_TABLE (usb, digitv_table);
  163. static struct dvb_usb_properties digitv_properties = {
  164. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  165. .usb_ctrl = CYPRESS_FX2,
  166. .firmware = "dvb-usb-digitv-01.fw",
  167. .size_of_priv = 0,
  168. .streaming_ctrl = NULL,
  169. .pid_filter = NULL,
  170. .pid_filter_ctrl = NULL,
  171. .power_ctrl = NULL,
  172. .frontend_attach = digitv_frontend_attach,
  173. .tuner_attach = NULL, // digitv_tuner_attach,
  174. .read_mac_address = NULL,
  175. .rc_interval = 1000,
  176. .rc_key_map = digitv_rc_keys,
  177. .rc_key_map_size = ARRAY_SIZE(digitv_rc_keys),
  178. .rc_query = digitv_rc_query,
  179. .identify_state = digitv_identify_state,
  180. .i2c_algo = &digitv_i2c_algo,
  181. .generic_bulk_ctrl_endpoint = 0x01,
  182. /* parameter for the MPEG2-data transfer */
  183. .urb = {
  184. .type = DVB_USB_BULK,
  185. .count = 7,
  186. .endpoint = 0x02,
  187. .u = {
  188. .bulk = {
  189. .buffersize = 4096,
  190. }
  191. }
  192. },
  193. .num_device_descs = 2,
  194. .devices = {
  195. { "Nebula Electronics uDigiTV DVB-T USB2.0)",
  196. { &digitv_table[0], NULL },
  197. { NULL },
  198. },
  199. }
  200. };
  201. static struct usb_driver digitv_driver = {
  202. .owner = THIS_MODULE,
  203. .name = "Nebula Electronics uDigiTV DVB-T USB2.0 device",
  204. .probe = digitv_probe,
  205. .disconnect = dvb_usb_device_exit,
  206. .id_table = digitv_table,
  207. };
  208. /* module stuff */
  209. static int __init digitv_module_init(void)
  210. {
  211. int result;
  212. if ((result = usb_register(&digitv_driver))) {
  213. err("usb_register failed. Error number %d",result);
  214. return result;
  215. }
  216. return 0;
  217. }
  218. static void __exit digitv_module_exit(void)
  219. {
  220. /* deregister this driver from the USB subsystem */
  221. usb_deregister(&digitv_driver);
  222. }
  223. module_init (digitv_module_init);
  224. module_exit (digitv_module_exit);
  225. MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
  226. MODULE_DESCRIPTION("Driver for Nebula Electronics uDigiTV DVB-T USB2.0");
  227. MODULE_VERSION("1.0-alpha");
  228. MODULE_LICENSE("GPL");