a800.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* DVB USB framework compliant Linux driver for the AVerMedia AverTV DVB-T
  3. * USB2.0 (A800) DVB-T receiver.
  4. *
  5. * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@posteo.de)
  6. *
  7. * Thanks to
  8. * - AVerMedia who kindly provided information and
  9. * - Glen Harris who suffered from my mistakes during development.
  10. *
  11. * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
  12. */
  13. #include "dibusb.h"
  14. static int debug;
  15. module_param(debug, int, 0644);
  16. MODULE_PARM_DESC(debug, "set debugging level (rc=1 (or-able))." DVB_USB_DEBUG_STATUS);
  17. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  18. #define deb_rc(args...) dprintk(debug,0x01,args)
  19. static int a800_power_ctrl(struct dvb_usb_device *d, int onoff)
  20. {
  21. /* do nothing for the AVerMedia */
  22. return 0;
  23. }
  24. /* assure to put cold to 0 for iManufacturer == 1 */
  25. static int a800_identify_state(struct usb_device *udev,
  26. const struct dvb_usb_device_properties *props,
  27. const struct dvb_usb_device_description **desc,
  28. int *cold)
  29. {
  30. *cold = udev->descriptor.iManufacturer != 1;
  31. return 0;
  32. }
  33. static int a800_rc_query(struct dvb_usb_device *d)
  34. {
  35. int ret = 0;
  36. u8 *key = kmalloc(5, GFP_KERNEL);
  37. if (!key)
  38. return -ENOMEM;
  39. if (usb_control_msg(d->udev,usb_rcvctrlpipe(d->udev,0),
  40. 0x04, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, key, 5,
  41. 2000) != 5) {
  42. ret = -ENODEV;
  43. goto out;
  44. }
  45. /* Note that extended nec and nec32 are dropped */
  46. if (key[0] == 1)
  47. rc_keydown(d->rc_dev, RC_PROTO_NEC,
  48. RC_SCANCODE_NEC(key[1], key[3]), 0);
  49. else if (key[0] == 2)
  50. rc_repeat(d->rc_dev);
  51. out:
  52. kfree(key);
  53. return ret;
  54. }
  55. /* USB Driver stuff */
  56. static struct dvb_usb_device_properties a800_properties;
  57. static int a800_probe(struct usb_interface *intf,
  58. const struct usb_device_id *id)
  59. {
  60. return dvb_usb_device_init(intf, &a800_properties,
  61. THIS_MODULE, NULL, adapter_nr);
  62. }
  63. /* do not change the order of the ID table */
  64. enum {
  65. AVERMEDIA_DVBT_USB2_COLD,
  66. AVERMEDIA_DVBT_USB2_WARM,
  67. };
  68. static const struct usb_device_id a800_table[] = {
  69. DVB_USB_DEV(AVERMEDIA, AVERMEDIA_DVBT_USB2_COLD),
  70. DVB_USB_DEV(AVERMEDIA, AVERMEDIA_DVBT_USB2_WARM),
  71. { }
  72. };
  73. MODULE_DEVICE_TABLE (usb, a800_table);
  74. static struct dvb_usb_device_properties a800_properties = {
  75. .caps = DVB_USB_IS_AN_I2C_ADAPTER,
  76. .usb_ctrl = CYPRESS_FX2,
  77. .firmware = "dvb-usb-avertv-a800-02.fw",
  78. .num_adapters = 1,
  79. .adapter = {
  80. {
  81. .num_frontends = 1,
  82. .fe = {{
  83. .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
  84. .pid_filter_count = 32,
  85. .streaming_ctrl = dibusb2_0_streaming_ctrl,
  86. .pid_filter = dibusb_pid_filter,
  87. .pid_filter_ctrl = dibusb_pid_filter_ctrl,
  88. .frontend_attach = dibusb_dib3000mc_frontend_attach,
  89. .tuner_attach = dibusb_dib3000mc_tuner_attach,
  90. /* parameter for the MPEG2-data transfer */
  91. .stream = {
  92. .type = USB_BULK,
  93. .count = 7,
  94. .endpoint = 0x06,
  95. .u = {
  96. .bulk = {
  97. .buffersize = 4096,
  98. }
  99. }
  100. },
  101. }},
  102. .size_of_priv = sizeof(struct dibusb_state),
  103. },
  104. },
  105. .power_ctrl = a800_power_ctrl,
  106. .identify_state = a800_identify_state,
  107. .rc.core = {
  108. .rc_interval = DEFAULT_RC_INTERVAL,
  109. .rc_codes = RC_MAP_AVERMEDIA_M135A,
  110. .module_name = KBUILD_MODNAME,
  111. .rc_query = a800_rc_query,
  112. .allowed_protos = RC_PROTO_BIT_NEC,
  113. },
  114. .i2c_algo = &dibusb_i2c_algo,
  115. .generic_bulk_ctrl_endpoint = 0x01,
  116. .num_device_descs = 1,
  117. .devices = {
  118. { "AVerMedia AverTV DVB-T USB 2.0 (A800)",
  119. { &a800_table[AVERMEDIA_DVBT_USB2_COLD], NULL },
  120. { &a800_table[AVERMEDIA_DVBT_USB2_WARM], NULL },
  121. },
  122. }
  123. };
  124. static struct usb_driver a800_driver = {
  125. .name = "dvb_usb_a800",
  126. .probe = a800_probe,
  127. .disconnect = dvb_usb_device_exit,
  128. .id_table = a800_table,
  129. };
  130. module_usb_driver(a800_driver);
  131. MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>");
  132. MODULE_DESCRIPTION("AVerMedia AverTV DVB-T USB 2.0 (A800)");
  133. MODULE_VERSION("1.0");
  134. MODULE_LICENSE("GPL");