Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* DVB USB framework compliant Linux driver for the Hauppauge WinTV-NOVA-T usb2
0003  * DVB-T receiver.
0004  *
0005  * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@posteo.de)
0006  *
0007  * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
0008  */
0009 #include "dibusb.h"
0010 
0011 static int debug;
0012 module_param(debug, int, 0644);
0013 MODULE_PARM_DESC(debug, "set debugging level (1=rc,2=eeprom (|-able))." DVB_USB_DEBUG_STATUS);
0014 
0015 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
0016 
0017 #define deb_rc(args...) dprintk(debug,0x01,args)
0018 #define deb_ee(args...) dprintk(debug,0x02,args)
0019 
0020 /* Hauppauge NOVA-T USB2 keys */
0021 static struct rc_map_table rc_map_haupp_table[] = {
0022     { 0x1e00, KEY_0 },
0023     { 0x1e01, KEY_1 },
0024     { 0x1e02, KEY_2 },
0025     { 0x1e03, KEY_3 },
0026     { 0x1e04, KEY_4 },
0027     { 0x1e05, KEY_5 },
0028     { 0x1e06, KEY_6 },
0029     { 0x1e07, KEY_7 },
0030     { 0x1e08, KEY_8 },
0031     { 0x1e09, KEY_9 },
0032     { 0x1e0a, KEY_KPASTERISK },
0033     { 0x1e0b, KEY_RED },
0034     { 0x1e0c, KEY_RADIO },
0035     { 0x1e0d, KEY_MENU },
0036     { 0x1e0e, KEY_GRAVE }, /* # */
0037     { 0x1e0f, KEY_MUTE },
0038     { 0x1e10, KEY_VOLUMEUP },
0039     { 0x1e11, KEY_VOLUMEDOWN },
0040     { 0x1e12, KEY_CHANNEL },
0041     { 0x1e14, KEY_UP },
0042     { 0x1e15, KEY_DOWN },
0043     { 0x1e16, KEY_LEFT },
0044     { 0x1e17, KEY_RIGHT },
0045     { 0x1e18, KEY_VIDEO },
0046     { 0x1e19, KEY_AUDIO },
0047     { 0x1e1a, KEY_IMAGES },
0048     { 0x1e1b, KEY_EPG },
0049     { 0x1e1c, KEY_TV },
0050     { 0x1e1e, KEY_NEXT },
0051     { 0x1e1f, KEY_BACK },
0052     { 0x1e20, KEY_CHANNELUP },
0053     { 0x1e21, KEY_CHANNELDOWN },
0054     { 0x1e24, KEY_LAST }, /* Skip backwards */
0055     { 0x1e25, KEY_OK },
0056     { 0x1e29, KEY_BLUE},
0057     { 0x1e2e, KEY_GREEN },
0058     { 0x1e30, KEY_PAUSE },
0059     { 0x1e32, KEY_REWIND },
0060     { 0x1e34, KEY_FASTFORWARD },
0061     { 0x1e35, KEY_PLAY },
0062     { 0x1e36, KEY_STOP },
0063     { 0x1e37, KEY_RECORD },
0064     { 0x1e38, KEY_YELLOW },
0065     { 0x1e3b, KEY_GOTO },
0066     { 0x1e3d, KEY_POWER },
0067 };
0068 
0069 /* Firmware bug? sometimes, when a new key is pressed, the previous pressed key
0070  * is delivered. No workaround yet, maybe a new firmware.
0071  */
0072 static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
0073 {
0074     u8 *buf, data, toggle, custom;
0075     u16 raw;
0076     int i, ret;
0077     struct dibusb_device_state *st = d->priv;
0078 
0079     buf = kmalloc(5, GFP_KERNEL);
0080     if (!buf)
0081         return -ENOMEM;
0082 
0083     buf[0] = DIBUSB_REQ_POLL_REMOTE;
0084     buf[1] = 0x35;
0085     ret = dvb_usb_generic_rw(d, buf, 2, buf, 5, 0);
0086     if (ret < 0)
0087         goto ret;
0088 
0089     *state = REMOTE_NO_KEY_PRESSED;
0090     switch (buf[0]) {
0091         case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED:
0092             raw = ((buf[1] << 8) | buf[2]) >> 3;
0093             toggle = !!(raw & 0x800);
0094             data = raw & 0x3f;
0095             custom = (raw >> 6) & 0x1f;
0096 
0097             deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",
0098                    buf[1], buf[2], buf[3], custom, data, toggle);
0099 
0100             for (i = 0; i < ARRAY_SIZE(rc_map_haupp_table); i++) {
0101                 if (rc5_data(&rc_map_haupp_table[i]) == data &&
0102                     rc5_custom(&rc_map_haupp_table[i]) == custom) {
0103 
0104                     deb_rc("c: %x, d: %x\n", rc5_data(&rc_map_haupp_table[i]),
0105                                  rc5_custom(&rc_map_haupp_table[i]));
0106 
0107                     *event = rc_map_haupp_table[i].keycode;
0108                     *state = REMOTE_KEY_PRESSED;
0109                     if (st->old_toggle == toggle) {
0110                         if (st->last_repeat_count++ < 2)
0111                             *state = REMOTE_NO_KEY_PRESSED;
0112                     } else {
0113                         st->last_repeat_count = 0;
0114                         st->old_toggle = toggle;
0115                     }
0116                     break;
0117                 }
0118             }
0119 
0120             break;
0121         case DIBUSB_RC_HAUPPAUGE_KEY_EMPTY:
0122         default:
0123             break;
0124     }
0125 
0126 ret:
0127     kfree(buf);
0128     return ret;
0129 }
0130 
0131 static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6])
0132 {
0133     int i, ret;
0134     u8 b;
0135 
0136     mac[0] = 0x00;
0137     mac[1] = 0x0d;
0138     mac[2] = 0xfe;
0139 
0140     /* this is a complete guess, but works for my box */
0141     for (i = 136; i < 139; i++) {
0142         ret = dibusb_read_eeprom_byte(d, i, &b);
0143         if (ret)
0144             return ret;
0145 
0146         mac[5 - (i - 136)] = b;
0147     }
0148 
0149     return 0;
0150 }
0151 
0152 /* USB Driver stuff */
0153 static struct dvb_usb_device_properties nova_t_properties;
0154 
0155 static int nova_t_probe(struct usb_interface *intf,
0156         const struct usb_device_id *id)
0157 {
0158     return dvb_usb_device_init(intf, &nova_t_properties,
0159                    THIS_MODULE, NULL, adapter_nr);
0160 }
0161 
0162 /* do not change the order of the ID table */
0163 enum {
0164     HAUPPAUGE_WINTV_NOVA_T_USB2_COLD,
0165     HAUPPAUGE_WINTV_NOVA_T_USB2_WARM,
0166 };
0167 
0168 static struct usb_device_id nova_t_table[] = {
0169     DVB_USB_DEV(HAUPPAUGE, HAUPPAUGE_WINTV_NOVA_T_USB2_COLD),
0170     DVB_USB_DEV(HAUPPAUGE, HAUPPAUGE_WINTV_NOVA_T_USB2_WARM),
0171     { }
0172 };
0173 
0174 MODULE_DEVICE_TABLE(usb, nova_t_table);
0175 
0176 static struct dvb_usb_device_properties nova_t_properties = {
0177     .caps = DVB_USB_IS_AN_I2C_ADAPTER,
0178 
0179     .usb_ctrl = CYPRESS_FX2,
0180     .firmware = "dvb-usb-nova-t-usb2-02.fw",
0181 
0182     .num_adapters     = 1,
0183     .adapter          = {
0184         {
0185         .num_frontends = 1,
0186         .fe = {{
0187             .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
0188             .pid_filter_count = 32,
0189 
0190             .streaming_ctrl   = dibusb2_0_streaming_ctrl,
0191             .pid_filter       = dibusb_pid_filter,
0192             .pid_filter_ctrl  = dibusb_pid_filter_ctrl,
0193             .frontend_attach  = dibusb_dib3000mc_frontend_attach,
0194             .tuner_attach     = dibusb_dib3000mc_tuner_attach,
0195 
0196             /* parameter for the MPEG2-data transfer */
0197                     .stream = {
0198                         .type = USB_BULK,
0199                 .count = 7,
0200                 .endpoint = 0x06,
0201                 .u = {
0202                     .bulk = {
0203                         .buffersize = 4096,
0204                     }
0205                 }
0206             },
0207         }},
0208             .size_of_priv     = sizeof(struct dibusb_state),
0209         }
0210     },
0211     .size_of_priv     = sizeof(struct dibusb_device_state),
0212 
0213     .power_ctrl       = dibusb2_0_power_ctrl,
0214     .read_mac_address = nova_t_read_mac_address,
0215 
0216     .rc.legacy = {
0217         .rc_interval      = 100,
0218         .rc_map_table     = rc_map_haupp_table,
0219         .rc_map_size      = ARRAY_SIZE(rc_map_haupp_table),
0220         .rc_query         = nova_t_rc_query,
0221     },
0222 
0223     .i2c_algo         = &dibusb_i2c_algo,
0224 
0225     .generic_bulk_ctrl_endpoint = 0x01,
0226 
0227     .num_device_descs = 1,
0228     .devices = {
0229         {   "Hauppauge WinTV-NOVA-T usb2",
0230             { &nova_t_table[HAUPPAUGE_WINTV_NOVA_T_USB2_COLD], NULL },
0231             { &nova_t_table[HAUPPAUGE_WINTV_NOVA_T_USB2_WARM], NULL },
0232         },
0233         { NULL },
0234     }
0235 };
0236 
0237 static struct usb_driver nova_t_driver = {
0238     .name       = "dvb_usb_nova_t_usb2",
0239     .probe      = nova_t_probe,
0240     .disconnect = dvb_usb_device_exit,
0241     .id_table   = nova_t_table,
0242 };
0243 
0244 module_usb_driver(nova_t_driver);
0245 
0246 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@posteo.de>");
0247 MODULE_DESCRIPTION("Hauppauge WinTV-NOVA-T usb2");
0248 MODULE_VERSION("1.0");
0249 MODULE_LICENSE("GPL");