| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 1 | /* DVB USB framework compliant Linux driver for the Hauppauge WinTV-NOVA-T usb2 | 
|  | 2 | * DVB-T receiver. | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de) | 
|  | 5 | * | 
|  | 6 | *	This program is free software; you can redistribute it and/or modify it | 
|  | 7 | *	under the terms of the GNU General Public License as published by the Free | 
|  | 8 | *	Software Foundation, version 2. | 
|  | 9 | * | 
|  | 10 | * see Documentation/dvb/README.dvb-usb for more information | 
|  | 11 | */ | 
|  | 12 | #include "dibusb.h" | 
|  | 13 |  | 
|  | 14 | static int debug; | 
|  | 15 | module_param(debug, int, 0644); | 
|  | 16 | MODULE_PARM_DESC(debug, "set debugging level (1=rc,2=eeprom (|-able))." DVB_USB_DEBUG_STATUS); | 
|  | 17 |  | 
| Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 18 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | 
|  | 19 |  | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 20 | #define deb_rc(args...) dprintk(debug,0x01,args) | 
|  | 21 | #define deb_ee(args...) dprintk(debug,0x02,args) | 
|  | 22 |  | 
|  | 23 | /* Hauppauge NOVA-T USB2 keys */ | 
| Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 24 | static struct rc_map_table rc_map_haupp_table[] = { | 
| Mauro Carvalho Chehab | 2e36588 | 2009-08-29 15:19:31 -0300 | [diff] [blame] | 25 | { 0x1e00, KEY_0 }, | 
|  | 26 | { 0x1e01, KEY_1 }, | 
|  | 27 | { 0x1e02, KEY_2 }, | 
|  | 28 | { 0x1e03, KEY_3 }, | 
|  | 29 | { 0x1e04, KEY_4 }, | 
|  | 30 | { 0x1e05, KEY_5 }, | 
|  | 31 | { 0x1e06, KEY_6 }, | 
|  | 32 | { 0x1e07, KEY_7 }, | 
|  | 33 | { 0x1e08, KEY_8 }, | 
|  | 34 | { 0x1e09, KEY_9 }, | 
|  | 35 | { 0x1e0a, KEY_KPASTERISK }, | 
|  | 36 | { 0x1e0b, KEY_RED }, | 
|  | 37 | { 0x1e0c, KEY_RADIO }, | 
|  | 38 | { 0x1e0d, KEY_MENU }, | 
|  | 39 | { 0x1e0e, KEY_GRAVE }, /* # */ | 
|  | 40 | { 0x1e0f, KEY_MUTE }, | 
|  | 41 | { 0x1e10, KEY_VOLUMEUP }, | 
|  | 42 | { 0x1e11, KEY_VOLUMEDOWN }, | 
|  | 43 | { 0x1e12, KEY_CHANNEL }, | 
|  | 44 | { 0x1e14, KEY_UP }, | 
|  | 45 | { 0x1e15, KEY_DOWN }, | 
|  | 46 | { 0x1e16, KEY_LEFT }, | 
|  | 47 | { 0x1e17, KEY_RIGHT }, | 
|  | 48 | { 0x1e18, KEY_VIDEO }, | 
|  | 49 | { 0x1e19, KEY_AUDIO }, | 
| Jarod Wilson | 56c0893 | 2011-04-05 18:42:30 -0300 | [diff] [blame] | 50 | { 0x1e1a, KEY_IMAGES }, | 
| Mauro Carvalho Chehab | 2e36588 | 2009-08-29 15:19:31 -0300 | [diff] [blame] | 51 | { 0x1e1b, KEY_EPG }, | 
|  | 52 | { 0x1e1c, KEY_TV }, | 
|  | 53 | { 0x1e1e, KEY_NEXT }, | 
|  | 54 | { 0x1e1f, KEY_BACK }, | 
|  | 55 | { 0x1e20, KEY_CHANNELUP }, | 
|  | 56 | { 0x1e21, KEY_CHANNELDOWN }, | 
|  | 57 | { 0x1e24, KEY_LAST }, /* Skip backwards */ | 
|  | 58 | { 0x1e25, KEY_OK }, | 
|  | 59 | { 0x1e29, KEY_BLUE}, | 
|  | 60 | { 0x1e2e, KEY_GREEN }, | 
|  | 61 | { 0x1e30, KEY_PAUSE }, | 
|  | 62 | { 0x1e32, KEY_REWIND }, | 
|  | 63 | { 0x1e34, KEY_FASTFORWARD }, | 
|  | 64 | { 0x1e35, KEY_PLAY }, | 
|  | 65 | { 0x1e36, KEY_STOP }, | 
|  | 66 | { 0x1e37, KEY_RECORD }, | 
|  | 67 | { 0x1e38, KEY_YELLOW }, | 
|  | 68 | { 0x1e3b, KEY_GOTO }, | 
|  | 69 | { 0x1e3d, KEY_POWER }, | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 70 | }; | 
|  | 71 |  | 
|  | 72 | /* Firmware bug? sometimes, when a new key is pressed, the previous pressed key | 
|  | 73 | * is delivered. No workaround yet, maybe a new firmware. | 
|  | 74 | */ | 
|  | 75 | static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state) | 
|  | 76 | { | 
|  | 77 | u8 key[5],cmd[2] = { DIBUSB_REQ_POLL_REMOTE, 0x35 }, data,toggle,custom; | 
|  | 78 | u16 raw; | 
|  | 79 | int i; | 
| Patrick Boettcher | 6a74216 | 2006-10-13 11:33:26 -0300 | [diff] [blame] | 80 | struct dibusb_device_state *st = d->priv; | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 81 |  | 
|  | 82 | dvb_usb_generic_rw(d,cmd,2,key,5,0); | 
|  | 83 |  | 
|  | 84 | *state = REMOTE_NO_KEY_PRESSED; | 
|  | 85 | switch (key[0]) { | 
|  | 86 | case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED: | 
|  | 87 | raw = ((key[1] << 8) | key[2]) >> 3; | 
|  | 88 | toggle = !!(raw & 0x800); | 
|  | 89 | data = raw & 0x3f; | 
|  | 90 | custom = (raw >> 6) & 0x1f; | 
|  | 91 |  | 
|  | 92 | deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle); | 
|  | 93 |  | 
| Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 94 | for (i = 0; i < ARRAY_SIZE(rc_map_haupp_table); i++) { | 
|  | 95 | if (rc5_data(&rc_map_haupp_table[i]) == data && | 
|  | 96 | rc5_custom(&rc_map_haupp_table[i]) == custom) { | 
| Mario Rossi | 6ccd601 | 2006-12-11 05:42:36 -0300 | [diff] [blame] | 97 |  | 
| Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 98 | deb_rc("c: %x, d: %x\n", rc5_data(&rc_map_haupp_table[i]), | 
|  | 99 | rc5_custom(&rc_map_haupp_table[i])); | 
| Mario Rossi | 6ccd601 | 2006-12-11 05:42:36 -0300 | [diff] [blame] | 100 |  | 
| Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 101 | *event = rc_map_haupp_table[i].keycode; | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 102 | *state = REMOTE_KEY_PRESSED; | 
|  | 103 | if (st->old_toggle == toggle) { | 
|  | 104 | if (st->last_repeat_count++ < 2) | 
|  | 105 | *state = REMOTE_NO_KEY_PRESSED; | 
|  | 106 | } else { | 
|  | 107 | st->last_repeat_count = 0; | 
|  | 108 | st->old_toggle = toggle; | 
|  | 109 | } | 
|  | 110 | break; | 
|  | 111 | } | 
|  | 112 | } | 
|  | 113 |  | 
|  | 114 | break; | 
|  | 115 | case DIBUSB_RC_HAUPPAUGE_KEY_EMPTY: | 
|  | 116 | default: | 
|  | 117 | break; | 
|  | 118 | } | 
|  | 119 |  | 
|  | 120 | return 0; | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 | static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6]) | 
|  | 124 | { | 
|  | 125 | int i; | 
|  | 126 | u8 b; | 
|  | 127 |  | 
|  | 128 | mac[0] = 0x00; | 
|  | 129 | mac[1] = 0x0d; | 
|  | 130 | mac[2] = 0xfe; | 
|  | 131 |  | 
|  | 132 | /* this is a complete guess, but works for my box */ | 
|  | 133 | for (i = 136; i < 139; i++) { | 
|  | 134 | dibusb_read_eeprom_byte(d,i, &b); | 
|  | 135 |  | 
|  | 136 | mac[5 - (i - 136)] = b; | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 137 | } | 
|  | 138 |  | 
|  | 139 | return 0; | 
|  | 140 | } | 
|  | 141 |  | 
|  | 142 | /* USB Driver stuff */ | 
| Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 143 | static struct dvb_usb_device_properties nova_t_properties; | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 144 |  | 
|  | 145 | static int nova_t_probe(struct usb_interface *intf, | 
|  | 146 | const struct usb_device_id *id) | 
|  | 147 | { | 
| Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 148 | return dvb_usb_device_init(intf, &nova_t_properties, | 
|  | 149 | THIS_MODULE, NULL, adapter_nr); | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 150 | } | 
|  | 151 |  | 
|  | 152 | /* do not change the order of the ID table */ | 
|  | 153 | static struct usb_device_id nova_t_table [] = { | 
|  | 154 | /* 00 */	{ USB_DEVICE(USB_VID_HAUPPAUGE,     USB_PID_WINTV_NOVA_T_USB2_COLD) }, | 
|  | 155 | /* 01 */	{ USB_DEVICE(USB_VID_HAUPPAUGE,     USB_PID_WINTV_NOVA_T_USB2_WARM) }, | 
|  | 156 | { }		/* Terminating entry */ | 
|  | 157 | }; | 
| Marc Koschewski | 00e3457 | 2006-01-09 18:21:35 -0200 | [diff] [blame] | 158 | MODULE_DEVICE_TABLE(usb, nova_t_table); | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 159 |  | 
| Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 160 | static struct dvb_usb_device_properties nova_t_properties = { | 
|  | 161 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 162 |  | 
|  | 163 | .usb_ctrl = CYPRESS_FX2, | 
| Patrick Boettcher | 6c95f61 | 2006-07-29 18:24:21 -0300 | [diff] [blame] | 164 | .firmware = "dvb-usb-nova-t-usb2-02.fw", | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 165 |  | 
| Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 166 | .num_adapters     = 1, | 
|  | 167 | .adapter          = { | 
|  | 168 | { | 
|  | 169 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, | 
|  | 170 | .pid_filter_count = 32, | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 171 |  | 
| Patrick Boettcher | 01451e7 | 2006-10-13 11:34:46 -0300 | [diff] [blame] | 172 | .streaming_ctrl   = dibusb2_0_streaming_ctrl, | 
|  | 173 | .pid_filter       = dibusb_pid_filter, | 
|  | 174 | .pid_filter_ctrl  = dibusb_pid_filter_ctrl, | 
|  | 175 | .frontend_attach  = dibusb_dib3000mc_frontend_attach, | 
|  | 176 | .tuner_attach     = dibusb_dib3000mc_tuner_attach, | 
| Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 177 |  | 
| Patrick Boettcher | 01451e7 | 2006-10-13 11:34:46 -0300 | [diff] [blame] | 178 | /* parameter for the MPEG2-data transfer */ | 
|  | 179 | .stream = { | 
|  | 180 | .type = USB_BULK, | 
|  | 181 | .count = 7, | 
|  | 182 | .endpoint = 0x06, | 
|  | 183 | .u = { | 
|  | 184 | .bulk = { | 
|  | 185 | .buffersize = 4096, | 
|  | 186 | } | 
|  | 187 | } | 
|  | 188 | }, | 
| Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 189 |  | 
|  | 190 | .size_of_priv     = sizeof(struct dibusb_state), | 
|  | 191 | } | 
|  | 192 | }, | 
| Patrick Boettcher | 6a74216 | 2006-10-13 11:33:26 -0300 | [diff] [blame] | 193 | .size_of_priv     = sizeof(struct dibusb_device_state), | 
| Patrick Boettcher | 4d43e13 | 2006-09-30 06:53:48 -0300 | [diff] [blame] | 194 |  | 
|  | 195 | .power_ctrl       = dibusb2_0_power_ctrl, | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 196 | .read_mac_address = nova_t_read_mac_address, | 
|  | 197 |  | 
| Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 198 | .rc.legacy = { | 
|  | 199 | .rc_interval      = 100, | 
| Mauro Carvalho Chehab | 2f4f58d | 2010-11-17 15:46:09 -0300 | [diff] [blame] | 200 | .rc_map_table     = rc_map_haupp_table, | 
|  | 201 | .rc_map_size      = ARRAY_SIZE(rc_map_haupp_table), | 
| Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 202 | .rc_query         = nova_t_rc_query, | 
|  | 203 | }, | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 204 |  | 
|  | 205 | .i2c_algo         = &dibusb_i2c_algo, | 
|  | 206 |  | 
|  | 207 | .generic_bulk_ctrl_endpoint = 0x01, | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 208 |  | 
|  | 209 | .num_device_descs = 1, | 
|  | 210 | .devices = { | 
|  | 211 | {   "Hauppauge WinTV-NOVA-T usb2", | 
|  | 212 | { &nova_t_table[0], NULL }, | 
|  | 213 | { &nova_t_table[1], NULL }, | 
|  | 214 | }, | 
| Marc Koschewski | 00e3457 | 2006-01-09 18:21:35 -0200 | [diff] [blame] | 215 | { NULL }, | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 216 | } | 
|  | 217 | }; | 
|  | 218 |  | 
|  | 219 | static struct usb_driver nova_t_driver = { | 
| Patrick Boettcher | 63b5c1c | 2005-07-07 17:58:30 -0700 | [diff] [blame] | 220 | .name		= "dvb_usb_nova_t_usb2", | 
| Johannes Stezenbach | 776338e | 2005-06-23 22:02:35 -0700 | [diff] [blame] | 221 | .probe		= nova_t_probe, | 
|  | 222 | .disconnect = dvb_usb_device_exit, | 
|  | 223 | .id_table	= nova_t_table, | 
|  | 224 | }; | 
|  | 225 |  | 
|  | 226 | /* module stuff */ | 
|  | 227 | static int __init nova_t_module_init(void) | 
|  | 228 | { | 
|  | 229 | int result; | 
|  | 230 | if ((result = usb_register(&nova_t_driver))) { | 
|  | 231 | err("usb_register failed. Error number %d",result); | 
|  | 232 | return result; | 
|  | 233 | } | 
|  | 234 |  | 
|  | 235 | return 0; | 
|  | 236 | } | 
|  | 237 |  | 
|  | 238 | static void __exit nova_t_module_exit(void) | 
|  | 239 | { | 
|  | 240 | /* deregister this driver from the USB subsystem */ | 
|  | 241 | usb_deregister(&nova_t_driver); | 
|  | 242 | } | 
|  | 243 |  | 
|  | 244 | module_init (nova_t_module_init); | 
|  | 245 | module_exit (nova_t_module_exit); | 
|  | 246 |  | 
|  | 247 | MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>"); | 
|  | 248 | MODULE_DESCRIPTION("Hauppauge WinTV-NOVA-T usb2"); | 
|  | 249 | MODULE_VERSION("1.0"); | 
|  | 250 | MODULE_LICENSE("GPL"); |