blob: 07fb843c7c2b22d35b4a977dd405e2b6d5e97ab7 [file] [log] [blame]
Johannes Stezenbach776338e2005-06-23 22:02:35 -07001/* 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
14static int debug;
15module_param(debug, int, 0644);
16MODULE_PARM_DESC(debug, "set debugging level (1=rc,2=eeprom (|-able))." DVB_USB_DEBUG_STATUS);
17
Janne Grunau78e92002008-04-09 19:13:13 -030018DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
19
Johannes Stezenbach776338e2005-06-23 22:02:35 -070020#define deb_rc(args...) dprintk(debug,0x01,args)
21#define deb_ee(args...) dprintk(debug,0x02,args)
22
23/* Hauppauge NOVA-T USB2 keys */
24static struct dvb_usb_rc_key haupp_rc_keys [] = {
25 { 0x1e, 0x00, KEY_0 },
26 { 0x1e, 0x01, KEY_1 },
27 { 0x1e, 0x02, KEY_2 },
28 { 0x1e, 0x03, KEY_3 },
29 { 0x1e, 0x04, KEY_4 },
30 { 0x1e, 0x05, KEY_5 },
31 { 0x1e, 0x06, KEY_6 },
32 { 0x1e, 0x07, KEY_7 },
33 { 0x1e, 0x08, KEY_8 },
34 { 0x1e, 0x09, KEY_9 },
35 { 0x1e, 0x0a, KEY_KPASTERISK },
36 { 0x1e, 0x0b, KEY_RED },
37 { 0x1e, 0x0c, KEY_RADIO },
38 { 0x1e, 0x0d, KEY_MENU },
39 { 0x1e, 0x0e, KEY_GRAVE }, /* # */
40 { 0x1e, 0x0f, KEY_MUTE },
41 { 0x1e, 0x10, KEY_VOLUMEUP },
42 { 0x1e, 0x11, KEY_VOLUMEDOWN },
43 { 0x1e, 0x12, KEY_CHANNEL },
44 { 0x1e, 0x14, KEY_UP },
45 { 0x1e, 0x15, KEY_DOWN },
46 { 0x1e, 0x16, KEY_LEFT },
47 { 0x1e, 0x17, KEY_RIGHT },
48 { 0x1e, 0x18, KEY_VIDEO },
49 { 0x1e, 0x19, KEY_AUDIO },
50 { 0x1e, 0x1a, KEY_MEDIA },
51 { 0x1e, 0x1b, KEY_EPG },
52 { 0x1e, 0x1c, KEY_TV },
53 { 0x1e, 0x1e, KEY_NEXT },
54 { 0x1e, 0x1f, KEY_BACK },
55 { 0x1e, 0x20, KEY_CHANNELUP },
56 { 0x1e, 0x21, KEY_CHANNELDOWN },
57 { 0x1e, 0x24, KEY_LAST }, /* Skip backwards */
58 { 0x1e, 0x25, KEY_OK },
59 { 0x1e, 0x29, KEY_BLUE},
60 { 0x1e, 0x2e, KEY_GREEN },
61 { 0x1e, 0x30, KEY_PAUSE },
62 { 0x1e, 0x32, KEY_REWIND },
63 { 0x1e, 0x34, KEY_FASTFORWARD },
64 { 0x1e, 0x35, KEY_PLAY },
65 { 0x1e, 0x36, KEY_STOP },
66 { 0x1e, 0x37, KEY_RECORD },
67 { 0x1e, 0x38, KEY_YELLOW },
68 { 0x1e, 0x3b, KEY_GOTO },
69 { 0x1e, 0x3d, KEY_POWER },
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 */
75static 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 Boettcher6a742162006-10-13 11:33:26 -030080 struct dibusb_device_state *st = d->priv;
Johannes Stezenbach776338e2005-06-23 22:02:35 -070081
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
94 for (i = 0; i < ARRAY_SIZE(haupp_rc_keys); i++) {
Johannes Stezenbach776338e2005-06-23 22:02:35 -070095 if (haupp_rc_keys[i].data == data &&
96 haupp_rc_keys[i].custom == custom) {
Mario Rossi6ccd6012006-12-11 05:42:36 -030097
98 deb_rc("c: %x, d: %x\n",haupp_rc_keys[i].data,haupp_rc_keys[i].custom);
99
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700100 *event = haupp_rc_keys[i].event;
101 *state = REMOTE_KEY_PRESSED;
102 if (st->old_toggle == toggle) {
103 if (st->last_repeat_count++ < 2)
104 *state = REMOTE_NO_KEY_PRESSED;
105 } else {
106 st->last_repeat_count = 0;
107 st->old_toggle = toggle;
108 }
109 break;
110 }
111 }
112
113 break;
114 case DIBUSB_RC_HAUPPAUGE_KEY_EMPTY:
115 default:
116 break;
117 }
118
119 return 0;
120}
121
122static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6])
123{
124 int i;
125 u8 b;
126
127 mac[0] = 0x00;
128 mac[1] = 0x0d;
129 mac[2] = 0xfe;
130
131 /* this is a complete guess, but works for my box */
132 for (i = 136; i < 139; i++) {
133 dibusb_read_eeprom_byte(d,i, &b);
134
135 mac[5 - (i - 136)] = b;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700136 }
137
138 return 0;
139}
140
141/* USB Driver stuff */
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300142static struct dvb_usb_device_properties nova_t_properties;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700143
144static int nova_t_probe(struct usb_interface *intf,
145 const struct usb_device_id *id)
146{
Janne Grunau78e92002008-04-09 19:13:13 -0300147 return dvb_usb_device_init(intf, &nova_t_properties,
148 THIS_MODULE, NULL, adapter_nr);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700149}
150
151/* do not change the order of the ID table */
152static struct usb_device_id nova_t_table [] = {
153/* 00 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_WINTV_NOVA_T_USB2_COLD) },
154/* 01 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_WINTV_NOVA_T_USB2_WARM) },
155 { } /* Terminating entry */
156};
Marc Koschewski00e34572006-01-09 18:21:35 -0200157MODULE_DEVICE_TABLE(usb, nova_t_table);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700158
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300159static struct dvb_usb_device_properties nova_t_properties = {
160 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700161
162 .usb_ctrl = CYPRESS_FX2,
Patrick Boettcher6c95f612006-07-29 18:24:21 -0300163 .firmware = "dvb-usb-nova-t-usb2-02.fw",
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700164
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300165 .num_adapters = 1,
166 .adapter = {
167 {
168 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
169 .pid_filter_count = 32,
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700170
Patrick Boettcher01451e72006-10-13 11:34:46 -0300171 .streaming_ctrl = dibusb2_0_streaming_ctrl,
172 .pid_filter = dibusb_pid_filter,
173 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
174 .frontend_attach = dibusb_dib3000mc_frontend_attach,
175 .tuner_attach = dibusb_dib3000mc_tuner_attach,
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300176
Patrick Boettcher01451e72006-10-13 11:34:46 -0300177 /* parameter for the MPEG2-data transfer */
178 .stream = {
179 .type = USB_BULK,
180 .count = 7,
181 .endpoint = 0x06,
182 .u = {
183 .bulk = {
184 .buffersize = 4096,
185 }
186 }
187 },
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300188
189 .size_of_priv = sizeof(struct dibusb_state),
190 }
191 },
Patrick Boettcher6a742162006-10-13 11:33:26 -0300192 .size_of_priv = sizeof(struct dibusb_device_state),
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300193
194 .power_ctrl = dibusb2_0_power_ctrl,
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700195 .read_mac_address = nova_t_read_mac_address,
196
197 .rc_interval = 100,
198 .rc_key_map = haupp_rc_keys,
199 .rc_key_map_size = ARRAY_SIZE(haupp_rc_keys),
200 .rc_query = nova_t_rc_query,
201
202 .i2c_algo = &dibusb_i2c_algo,
203
204 .generic_bulk_ctrl_endpoint = 0x01,
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700205
206 .num_device_descs = 1,
207 .devices = {
208 { "Hauppauge WinTV-NOVA-T usb2",
209 { &nova_t_table[0], NULL },
210 { &nova_t_table[1], NULL },
211 },
Marc Koschewski00e34572006-01-09 18:21:35 -0200212 { NULL },
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700213 }
214};
215
216static struct usb_driver nova_t_driver = {
Patrick Boettcher63b5c1c2005-07-07 17:58:30 -0700217 .name = "dvb_usb_nova_t_usb2",
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700218 .probe = nova_t_probe,
219 .disconnect = dvb_usb_device_exit,
220 .id_table = nova_t_table,
221};
222
223/* module stuff */
224static int __init nova_t_module_init(void)
225{
226 int result;
227 if ((result = usb_register(&nova_t_driver))) {
228 err("usb_register failed. Error number %d",result);
229 return result;
230 }
231
232 return 0;
233}
234
235static void __exit nova_t_module_exit(void)
236{
237 /* deregister this driver from the USB subsystem */
238 usb_deregister(&nova_t_driver);
239}
240
241module_init (nova_t_module_init);
242module_exit (nova_t_module_exit);
243
244MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
245MODULE_DESCRIPTION("Hauppauge WinTV-NOVA-T usb2");
246MODULE_VERSION("1.0");
247MODULE_LICENSE("GPL");