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