Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[pandora-kernel.git] / drivers / media / dvb / dvb-usb / nova-t-usb2.c
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
18 #define deb_rc(args...) dprintk(debug,0x01,args)
19 #define deb_ee(args...) dprintk(debug,0x02,args)
20
21 /* Hauppauge NOVA-T USB2 keys */
22 static struct dvb_usb_rc_key haupp_rc_keys [] = {
23         { 0x1e, 0x00, KEY_0 },
24         { 0x1e, 0x01, KEY_1 },
25         { 0x1e, 0x02, KEY_2 },
26         { 0x1e, 0x03, KEY_3 },
27         { 0x1e, 0x04, KEY_4 },
28         { 0x1e, 0x05, KEY_5 },
29         { 0x1e, 0x06, KEY_6 },
30         { 0x1e, 0x07, KEY_7 },
31         { 0x1e, 0x08, KEY_8 },
32         { 0x1e, 0x09, KEY_9 },
33         { 0x1e, 0x0a, KEY_KPASTERISK },
34         { 0x1e, 0x0b, KEY_RED },
35         { 0x1e, 0x0c, KEY_RADIO },
36         { 0x1e, 0x0d, KEY_MENU },
37         { 0x1e, 0x0e, KEY_GRAVE }, /* # */
38         { 0x1e, 0x0f, KEY_MUTE },
39         { 0x1e, 0x10, KEY_VOLUMEUP },
40         { 0x1e, 0x11, KEY_VOLUMEDOWN },
41         { 0x1e, 0x12, KEY_CHANNEL },
42         { 0x1e, 0x14, KEY_UP },
43         { 0x1e, 0x15, KEY_DOWN },
44         { 0x1e, 0x16, KEY_LEFT },
45         { 0x1e, 0x17, KEY_RIGHT },
46         { 0x1e, 0x18, KEY_VIDEO },
47         { 0x1e, 0x19, KEY_AUDIO },
48         { 0x1e, 0x1a, KEY_MEDIA },
49         { 0x1e, 0x1b, KEY_EPG },
50         { 0x1e, 0x1c, KEY_TV },
51         { 0x1e, 0x1e, KEY_NEXT },
52         { 0x1e, 0x1f, KEY_BACK },
53         { 0x1e, 0x20, KEY_CHANNELUP },
54         { 0x1e, 0x21, KEY_CHANNELDOWN },
55         { 0x1e, 0x24, KEY_LAST }, /* Skip backwards */
56         { 0x1e, 0x25, KEY_OK },
57         { 0x1e, 0x29, KEY_BLUE},
58         { 0x1e, 0x2e, KEY_GREEN },
59         { 0x1e, 0x30, KEY_PAUSE },
60         { 0x1e, 0x32, KEY_REWIND },
61         { 0x1e, 0x34, KEY_FASTFORWARD },
62         { 0x1e, 0x35, KEY_PLAY },
63         { 0x1e, 0x36, KEY_STOP },
64         { 0x1e, 0x37, KEY_RECORD },
65         { 0x1e, 0x38, KEY_YELLOW },
66         { 0x1e, 0x3b, KEY_GOTO },
67         { 0x1e, 0x3d, KEY_POWER },
68 };
69
70 /* Firmware bug? sometimes, when a new key is pressed, the previous pressed key
71  * is delivered. No workaround yet, maybe a new firmware.
72  */
73 static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
74 {
75         u8 key[5],cmd[2] = { DIBUSB_REQ_POLL_REMOTE, 0x35 }, data,toggle,custom;
76         u16 raw;
77         int i;
78         struct dibusb_device_state *st = d->priv;
79
80         dvb_usb_generic_rw(d,cmd,2,key,5,0);
81
82         *state = REMOTE_NO_KEY_PRESSED;
83         switch (key[0]) {
84                 case DIBUSB_RC_HAUPPAUGE_KEY_PRESSED:
85                         raw = ((key[1] << 8) | key[2]) >> 3;
86                         toggle = !!(raw & 0x800);
87                         data = raw & 0x3f;
88                         custom = (raw >> 6) & 0x1f;
89
90                         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);
91
92                         for (i = 0; i < ARRAY_SIZE(haupp_rc_keys); i++) {
93                                 if (haupp_rc_keys[i].data == data &&
94                                         haupp_rc_keys[i].custom == custom) {
95
96                                         deb_rc("c: %x, d: %x\n",haupp_rc_keys[i].data,haupp_rc_keys[i].custom);
97
98                                         *event = haupp_rc_keys[i].event;
99                                         *state = REMOTE_KEY_PRESSED;
100                                         if (st->old_toggle == toggle) {
101                                                 if (st->last_repeat_count++ < 2)
102                                                         *state = REMOTE_NO_KEY_PRESSED;
103                                         } else {
104                                                 st->last_repeat_count = 0;
105                                                 st->old_toggle = toggle;
106                                         }
107                                         break;
108                                 }
109                         }
110
111                         break;
112                 case DIBUSB_RC_HAUPPAUGE_KEY_EMPTY:
113                 default:
114                         break;
115         }
116
117         return 0;
118 }
119
120 static int nova_t_read_mac_address (struct dvb_usb_device *d, u8 mac[6])
121 {
122         int i;
123         u8 b;
124
125         mac[0] = 0x00;
126         mac[1] = 0x0d;
127         mac[2] = 0xfe;
128
129         /* this is a complete guess, but works for my box */
130         for (i = 136; i < 139; i++) {
131                 dibusb_read_eeprom_byte(d,i, &b);
132
133                 mac[5 - (i - 136)] = b;
134         }
135
136         return 0;
137 }
138
139 /* USB Driver stuff */
140 static struct dvb_usb_device_properties nova_t_properties;
141
142 static int nova_t_probe(struct usb_interface *intf,
143                 const struct usb_device_id *id)
144 {
145         return dvb_usb_device_init(intf,&nova_t_properties,THIS_MODULE,NULL);
146 }
147
148 /* do not change the order of the ID table */
149 static struct usb_device_id nova_t_table [] = {
150 /* 00 */        { USB_DEVICE(USB_VID_HAUPPAUGE,     USB_PID_WINTV_NOVA_T_USB2_COLD) },
151 /* 01 */        { USB_DEVICE(USB_VID_HAUPPAUGE,     USB_PID_WINTV_NOVA_T_USB2_WARM) },
152                         { }             /* Terminating entry */
153 };
154 MODULE_DEVICE_TABLE(usb, nova_t_table);
155
156 static struct dvb_usb_device_properties nova_t_properties = {
157         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
158
159         .usb_ctrl = CYPRESS_FX2,
160         .firmware = "dvb-usb-nova-t-usb2-02.fw",
161
162         .num_adapters     = 1,
163         .adapter          = {
164                 {
165                         .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
166                         .pid_filter_count = 32,
167
168                         .streaming_ctrl   = dibusb2_0_streaming_ctrl,
169                         .pid_filter       = dibusb_pid_filter,
170                         .pid_filter_ctrl  = dibusb_pid_filter_ctrl,
171                         .frontend_attach  = dibusb_dib3000mc_frontend_attach,
172                         .tuner_attach     = dibusb_dib3000mc_tuner_attach,
173
174                         /* parameter for the MPEG2-data transfer */
175                                         .stream = {
176                                                 .type = USB_BULK,
177                                 .count = 7,
178                                 .endpoint = 0x06,
179                                 .u = {
180                                         .bulk = {
181                                                 .buffersize = 4096,
182                                         }
183                                 }
184                         },
185
186                         .size_of_priv     = sizeof(struct dibusb_state),
187                 }
188         },
189         .size_of_priv     = sizeof(struct dibusb_device_state),
190
191         .power_ctrl       = dibusb2_0_power_ctrl,
192         .read_mac_address = nova_t_read_mac_address,
193
194         .rc_interval      = 100,
195         .rc_key_map       = haupp_rc_keys,
196         .rc_key_map_size  = ARRAY_SIZE(haupp_rc_keys),
197         .rc_query         = nova_t_rc_query,
198
199         .i2c_algo         = &dibusb_i2c_algo,
200
201         .generic_bulk_ctrl_endpoint = 0x01,
202
203         .num_device_descs = 1,
204         .devices = {
205                 {   "Hauppauge WinTV-NOVA-T usb2",
206                         { &nova_t_table[0], NULL },
207                         { &nova_t_table[1], NULL },
208                 },
209                 { NULL },
210         }
211 };
212
213 static struct usb_driver nova_t_driver = {
214         .name           = "dvb_usb_nova_t_usb2",
215         .probe          = nova_t_probe,
216         .disconnect = dvb_usb_device_exit,
217         .id_table       = nova_t_table,
218 };
219
220 /* module stuff */
221 static int __init nova_t_module_init(void)
222 {
223         int result;
224         if ((result = usb_register(&nova_t_driver))) {
225                 err("usb_register failed. Error number %d",result);
226                 return result;
227         }
228
229         return 0;
230 }
231
232 static void __exit nova_t_module_exit(void)
233 {
234         /* deregister this driver from the USB subsystem */
235         usb_deregister(&nova_t_driver);
236 }
237
238 module_init (nova_t_module_init);
239 module_exit (nova_t_module_exit);
240
241 MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
242 MODULE_DESCRIPTION("Hauppauge WinTV-NOVA-T usb2");
243 MODULE_VERSION("1.0");
244 MODULE_LICENSE("GPL");