cinergyT2-core.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * TerraTec Cinergy T2/qanu USB2 DVB-T adapter.
  3. *
  4. * Copyright (C) 2007 Tomi Orava (tomimo@ncircle.nullnet.fi)
  5. *
  6. * Based on the dvb-usb-framework code and the
  7. * original Terratec Cinergy T2 driver by:
  8. *
  9. * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and
  10. * Holger Waechtler <holger@qanu.de>
  11. *
  12. * Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. *
  28. */
  29. #include "cinergyT2.h"
  30. /* debug */
  31. int dvb_usb_cinergyt2_debug;
  32. int disable_remote;
  33. module_param_named(debug, dvb_usb_cinergyt2_debug, int, 0644);
  34. MODULE_PARM_DESC(debug, "set debugging level (1=info, xfer=2, rc=4 "
  35. "(or-able)).");
  36. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  37. /* We are missing a release hook with usb_device data */
  38. struct dvb_usb_device *cinergyt2_usb_device;
  39. static struct dvb_usb_device_properties cinergyt2_properties;
  40. static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
  41. {
  42. char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
  43. char result[64];
  44. return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
  45. sizeof(result), 0);
  46. }
  47. static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
  48. {
  49. char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
  50. char state[3];
  51. return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
  52. }
  53. static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
  54. {
  55. char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
  56. char state[3];
  57. int ret;
  58. adap->fe = cinergyt2_fe_attach(adap->dev);
  59. ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
  60. sizeof(state), 0);
  61. if (ret < 0) {
  62. deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
  63. "state info\n");
  64. }
  65. /* Copy this pointer as we are gonna need it in the release phase */
  66. cinergyt2_usb_device = adap->dev;
  67. return 0;
  68. }
  69. static struct dvb_usb_rc_key cinergyt2_rc_keys[] = {
  70. { 0x04, 0x01, KEY_POWER },
  71. { 0x04, 0x02, KEY_1 },
  72. { 0x04, 0x03, KEY_2 },
  73. { 0x04, 0x04, KEY_3 },
  74. { 0x04, 0x05, KEY_4 },
  75. { 0x04, 0x06, KEY_5 },
  76. { 0x04, 0x07, KEY_6 },
  77. { 0x04, 0x08, KEY_7 },
  78. { 0x04, 0x09, KEY_8 },
  79. { 0x04, 0x0a, KEY_9 },
  80. { 0x04, 0x0c, KEY_0 },
  81. { 0x04, 0x0b, KEY_VIDEO },
  82. { 0x04, 0x0d, KEY_REFRESH },
  83. { 0x04, 0x0e, KEY_SELECT },
  84. { 0x04, 0x0f, KEY_EPG },
  85. { 0x04, 0x10, KEY_UP },
  86. { 0x04, 0x14, KEY_DOWN },
  87. { 0x04, 0x11, KEY_LEFT },
  88. { 0x04, 0x13, KEY_RIGHT },
  89. { 0x04, 0x12, KEY_OK },
  90. { 0x04, 0x15, KEY_TEXT },
  91. { 0x04, 0x16, KEY_INFO },
  92. { 0x04, 0x17, KEY_RED },
  93. { 0x04, 0x18, KEY_GREEN },
  94. { 0x04, 0x19, KEY_YELLOW },
  95. { 0x04, 0x1a, KEY_BLUE },
  96. { 0x04, 0x1c, KEY_VOLUMEUP },
  97. { 0x04, 0x1e, KEY_VOLUMEDOWN },
  98. { 0x04, 0x1d, KEY_MUTE },
  99. { 0x04, 0x1b, KEY_CHANNELUP },
  100. { 0x04, 0x1f, KEY_CHANNELDOWN },
  101. { 0x04, 0x40, KEY_PAUSE },
  102. { 0x04, 0x4c, KEY_PLAY },
  103. { 0x04, 0x58, KEY_RECORD },
  104. { 0x04, 0x54, KEY_PREVIOUS },
  105. { 0x04, 0x48, KEY_STOP },
  106. { 0x04, 0x5c, KEY_NEXT }
  107. };
  108. static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
  109. {
  110. u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
  111. *state = REMOTE_NO_KEY_PRESSED;
  112. dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
  113. if (key[4] == 0xff)
  114. return 0;
  115. /* hack to pass checksum on the custom field (is set to 0xeb) */
  116. key[2] = ~0x04;
  117. dvb_usb_nec_rc_key_to_event(d, key, event, state);
  118. if (key[0] != 0)
  119. deb_info("key: %x %x %x %x %x\n",
  120. key[0], key[1], key[2], key[3], key[4]);
  121. return 0;
  122. }
  123. static int cinergyt2_usb_probe(struct usb_interface *intf,
  124. const struct usb_device_id *id)
  125. {
  126. return dvb_usb_device_init(intf, &cinergyt2_properties,
  127. THIS_MODULE, NULL, adapter_nr);
  128. }
  129. static struct usb_device_id cinergyt2_usb_table[] = {
  130. { USB_DEVICE(USB_VID_TERRATEC, 0x0038) },
  131. { 0 }
  132. };
  133. MODULE_DEVICE_TABLE(usb, cinergyt2_usb_table);
  134. static struct dvb_usb_device_properties cinergyt2_properties = {
  135. .num_adapters = 1,
  136. .adapter = {
  137. {
  138. .streaming_ctrl = cinergyt2_streaming_ctrl,
  139. .frontend_attach = cinergyt2_frontend_attach,
  140. /* parameter for the MPEG2-data transfer */
  141. .stream = {
  142. .type = USB_BULK,
  143. .count = 5,
  144. .endpoint = 0x02,
  145. .u = {
  146. .bulk = {
  147. .buffersize = 512,
  148. }
  149. }
  150. },
  151. }
  152. },
  153. .power_ctrl = cinergyt2_power_ctrl,
  154. .rc_interval = 50,
  155. .rc_key_map = cinergyt2_rc_keys,
  156. .rc_key_map_size = ARRAY_SIZE(cinergyt2_rc_keys),
  157. .rc_query = cinergyt2_rc_query,
  158. .generic_bulk_ctrl_endpoint = 1,
  159. .num_device_descs = 1,
  160. .devices = {
  161. { .name = "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver",
  162. .cold_ids = {NULL},
  163. .warm_ids = { &cinergyt2_usb_table[0], NULL },
  164. },
  165. { NULL },
  166. }
  167. };
  168. static struct usb_driver cinergyt2_driver = {
  169. .name = "cinergyT2",
  170. .probe = cinergyt2_usb_probe,
  171. .disconnect = dvb_usb_device_exit,
  172. .id_table = cinergyt2_usb_table
  173. };
  174. static int __init cinergyt2_usb_init(void)
  175. {
  176. int err;
  177. err = usb_register(&cinergyt2_driver);
  178. if (err) {
  179. err("usb_register() failed! (err %i)\n", err);
  180. return err;
  181. }
  182. return 0;
  183. }
  184. static void __exit cinergyt2_usb_exit(void)
  185. {
  186. usb_deregister(&cinergyt2_driver);
  187. }
  188. module_init(cinergyt2_usb_init);
  189. module_exit(cinergyt2_usb_exit);
  190. MODULE_DESCRIPTION("Terratec Cinergy T2 DVB-T driver");
  191. MODULE_LICENSE("GPL");
  192. MODULE_AUTHOR("Tomi Orava");