blob: 69a46b3607a2a1d63e42dc2daacb2983896039c8 [file] [log] [blame]
Johannes Stezenbach776338e2005-06-23 22:02:35 -07001/* DVB USB compliant Linux driver for the
2 * - TwinhanDTV Alpha/MagicBoxII USB2.0 DVB-T receiver
3 * - DigitalNow TinyUSB2 DVB-t receiver
4 *
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
6 *
7 * Thanks to Twinhan who kindly provided hardware and information.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation, version 2.
12 *
13 * see Documentation/dvb/README.dvb-usb for more information
14 */
15#include "vp7045.h"
16
17/* debug */
18int dvb_usb_vp7045_debug;
19module_param_named(debug,dvb_usb_vp7045_debug, int, 0644);
20MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
21
22int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in, int inlen, int msec)
23{
24 int ret = 0;
25 u8 inbuf[12] = { 0 }, outbuf[20] = { 0 };
26
27 outbuf[0] = cmd;
28
29 if (outlen > 19)
30 outlen = 19;
31
32 if (inlen > 11)
33 inlen = 11;
34
35 if (out != NULL && outlen > 0)
36 memcpy(&outbuf[1], out, outlen);
37
38 deb_xfer("out buffer: ");
39 debug_dump(outbuf,outlen+1,deb_xfer);
40
Ingo Molnar3593cab2006-02-07 06:49:14 -020041 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
Johannes Stezenbach776338e2005-06-23 22:02:35 -070042 return ret;
43
44 if (usb_control_msg(d->udev,
45 usb_sndctrlpipe(d->udev,0),
46 TH_COMMAND_OUT, USB_TYPE_VENDOR | USB_DIR_OUT, 0, 0,
Patrick Boettcher63b5c1c2005-07-07 17:58:30 -070047 outbuf, 20, 2000) != 20) {
Johannes Stezenbach776338e2005-06-23 22:02:35 -070048 err("USB control message 'out' went wrong.");
49 ret = -EIO;
50 goto unlock;
51 }
52
53 msleep(msec);
54
55 if (usb_control_msg(d->udev,
56 usb_rcvctrlpipe(d->udev,0),
57 TH_COMMAND_IN, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
Patrick Boettcher63b5c1c2005-07-07 17:58:30 -070058 inbuf, 12, 2000) != 12) {
Johannes Stezenbach776338e2005-06-23 22:02:35 -070059 err("USB control message 'in' went wrong.");
60 ret = -EIO;
61 goto unlock;
62 }
63
64 deb_xfer("in buffer: ");
65 debug_dump(inbuf,12,deb_xfer);
66
67 if (in != NULL && inlen > 0)
68 memcpy(in,&inbuf[1],inlen);
69
70unlock:
Ingo Molnar3593cab2006-02-07 06:49:14 -020071 mutex_unlock(&d->usb_mutex);
Johannes Stezenbach776338e2005-06-23 22:02:35 -070072
73 return ret;
74}
75
76u8 vp7045_read_reg(struct dvb_usb_device *d, u8 reg)
77{
78 u8 obuf[2] = { 0 },v;
79 obuf[1] = reg;
80
81 vp7045_usb_op(d,TUNER_REG_READ,obuf,2,&v,1,30);
82
83 return v;
84}
85
86static int vp7045_power_ctrl(struct dvb_usb_device *d, int onoff)
87{
88 u8 v = onoff;
89 return vp7045_usb_op(d,SET_TUNER_POWER,&v,1,NULL,0,150);
90}
91
92/* remote control stuff */
93
94/* The keymapping struct. Somehow this should be loaded to the driver, but
95 * currently it is hardcoded. */
96static struct dvb_usb_rc_key vp7045_rc_keys[] = {
Patrick Boettcher2d188c62005-07-07 17:58:21 -070097 { 0x00, 0x16, KEY_POWER },
98 { 0x00, 0x10, KEY_MUTE },
99 { 0x00, 0x03, KEY_1 },
100 { 0x00, 0x01, KEY_2 },
101 { 0x00, 0x06, KEY_3 },
102 { 0x00, 0x09, KEY_4 },
103 { 0x00, 0x1d, KEY_5 },
104 { 0x00, 0x1f, KEY_6 },
105 { 0x00, 0x0d, KEY_7 },
106 { 0x00, 0x19, KEY_8 },
107 { 0x00, 0x1b, KEY_9 },
108 { 0x00, 0x15, KEY_0 },
109 { 0x00, 0x05, KEY_CHANNELUP },
110 { 0x00, 0x02, KEY_CHANNELDOWN },
111 { 0x00, 0x1e, KEY_VOLUMEUP },
112 { 0x00, 0x0a, KEY_VOLUMEDOWN },
113 { 0x00, 0x11, KEY_RECORD },
114 { 0x00, 0x17, KEY_FAVORITES }, /* Heart symbol - Channel list. */
115 { 0x00, 0x14, KEY_PLAY },
116 { 0x00, 0x1a, KEY_STOP },
117 { 0x00, 0x40, KEY_REWIND },
118 { 0x00, 0x12, KEY_FASTFORWARD },
119 { 0x00, 0x0e, KEY_PREVIOUS }, /* Recall - Previous channel. */
120 { 0x00, 0x4c, KEY_PAUSE },
121 { 0x00, 0x4d, KEY_SCREEN }, /* Full screen mode. */
122 { 0x00, 0x54, KEY_AUDIO }, /* MTS - Switch to secondary audio. */
Michael Paxton04f3e5e2005-07-07 17:58:24 -0700123 { 0x00, 0x0c, KEY_CANCEL }, /* Cancel */
Patrick Boettcher2d188c62005-07-07 17:58:21 -0700124 { 0x00, 0x1c, KEY_EPG }, /* EPG */
Michael Paxton04f3e5e2005-07-07 17:58:24 -0700125 { 0x00, 0x00, KEY_TAB }, /* Tab */
Patrick Boettcher2d188c62005-07-07 17:58:21 -0700126 { 0x00, 0x48, KEY_INFO }, /* Preview */
127 { 0x00, 0x04, KEY_LIST }, /* RecordList */
Luke Deller3cc2e4c2006-10-17 18:28:10 -0300128 { 0x00, 0x0f, KEY_TEXT }, /* Teletext */
129 { 0x00, 0x41, KEY_PREVIOUSSONG },
130 { 0x00, 0x42, KEY_NEXTSONG },
131 { 0x00, 0x4b, KEY_UP },
132 { 0x00, 0x51, KEY_DOWN },
133 { 0x00, 0x4e, KEY_LEFT },
134 { 0x00, 0x52, KEY_RIGHT },
135 { 0x00, 0x4f, KEY_ENTER },
136 { 0x00, 0x13, KEY_CANCEL },
137 { 0x00, 0x4a, KEY_CLEAR },
138 { 0x00, 0x54, KEY_PRINT }, /* Capture */
139 { 0x00, 0x43, KEY_SUBTITLE }, /* Subtitle/CC */
140 { 0x00, 0x08, KEY_VIDEO }, /* A/V */
141 { 0x00, 0x07, KEY_SLEEP }, /* Hibernate */
142 { 0x00, 0x45, KEY_ZOOM }, /* Zoom+ */
143 { 0x00, 0x18, KEY_RED},
144 { 0x00, 0x53, KEY_GREEN},
145 { 0x00, 0x5e, KEY_YELLOW},
146 { 0x00, 0x5f, KEY_BLUE}
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700147};
148
Patrick Boettcher8df3d462005-07-12 13:58:38 -0700149static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700150{
151 u8 key;
152 int i;
153 vp7045_usb_op(d,RC_VAL_READ,NULL,0,&key,1,20);
154
155 deb_rc("remote query key: %x %d\n",key,key);
156
157 if (key == 0x44) {
158 *state = REMOTE_NO_KEY_PRESSED;
159 return 0;
160 }
161
162 for (i = 0; i < sizeof(vp7045_rc_keys)/sizeof(struct dvb_usb_rc_key); i++)
163 if (vp7045_rc_keys[i].data == key) {
164 *state = REMOTE_KEY_PRESSED;
Patrick Boettcher8df3d462005-07-12 13:58:38 -0700165 *event = vp7045_rc_keys[i].event;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700166 break;
167 }
168 return 0;
169}
170
171static int vp7045_read_eeprom(struct dvb_usb_device *d,u8 *buf, int len, int offset)
172{
173 int i = 0;
174 u8 v,br[2];
175 for (i=0; i < len; i++) {
176 v = offset + i;
177 vp7045_usb_op(d,GET_EE_VALUE,&v,1,br,2,5);
178 buf[i] = br[1];
179 }
180 deb_info("VP7045 EEPROM read (offs: %d, len: %d) : ",offset, i);
181 debug_dump(buf,i,deb_info);
182 return 0;
183}
184
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700185static int vp7045_read_mac_addr(struct dvb_usb_device *d,u8 mac[6])
186{
187 return vp7045_read_eeprom(d,mac, 6, MAC_0_ADDR);
188}
189
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300190static int vp7045_frontend_attach(struct dvb_usb_adapter *adap)
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700191{
192 u8 buf[255] = { 0 };
193
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300194 vp7045_usb_op(adap->dev,VENDOR_STRING_READ,NULL,0,buf,20,0);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700195 buf[10] = '\0';
196 deb_info("firmware says: %s ",buf);
197
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300198 vp7045_usb_op(adap->dev,PRODUCT_STRING_READ,NULL,0,buf,20,0);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700199 buf[10] = '\0';
200 deb_info("%s ",buf);
201
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300202 vp7045_usb_op(adap->dev,FW_VERSION_READ,NULL,0,buf,20,0);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700203 buf[10] = '\0';
204 deb_info("v%s\n",buf);
205
206/* Dump the EEPROM */
207/* vp7045_read_eeprom(d,buf, 255, FX2_ID_ADDR); */
208
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300209 adap->fe = vp7045_fe_attach(adap->dev);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700210
211 return 0;
212}
213
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300214static struct dvb_usb_device_properties vp7045_properties;
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700215
216static int vp7045_usb_probe(struct usb_interface *intf,
217 const struct usb_device_id *id)
218{
Patrick Boettcher47dc3d62005-09-09 13:02:47 -0700219 return dvb_usb_device_init(intf,&vp7045_properties,THIS_MODULE,NULL);
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700220}
221
222static struct usb_device_id vp7045_usb_table [] = {
223 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7045_COLD) },
224 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TWINHAN_VP7045_WARM) },
225 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_DNTV_TINYUSB2_COLD) },
226 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_DNTV_TINYUSB2_WARM) },
227 { 0 },
228};
229MODULE_DEVICE_TABLE(usb, vp7045_usb_table);
230
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300231static struct dvb_usb_device_properties vp7045_properties = {
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700232 .usb_ctrl = CYPRESS_FX2,
233 .firmware = "dvb-usb-vp7045-01.fw",
234
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300235 .num_adapters = 1,
236 .adapter = {
237 {
Patrick Boettcher01451e72006-10-13 11:34:46 -0300238 .frontend_attach = vp7045_frontend_attach,
239 /* parameter for the MPEG2-data transfer */
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300240 .stream = {
241 .type = USB_BULK,
Patrick Boettcher01451e72006-10-13 11:34:46 -0300242 .count = 7,
243 .endpoint = 0x02,
244 .u = {
245 .bulk = {
246 .buffersize = 4096,
247 }
248 }
249 },
Patrick Boettcher4d43e132006-09-30 06:53:48 -0300250 }
251 },
252 .power_ctrl = vp7045_power_ctrl,
253 .read_mac_address = vp7045_read_mac_addr,
254
255 .rc_interval = 400,
256 .rc_key_map = vp7045_rc_keys,
257 .rc_key_map_size = ARRAY_SIZE(vp7045_rc_keys),
258 .rc_query = vp7045_rc_query,
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700259
260 .num_device_descs = 2,
261 .devices = {
262 { .name = "Twinhan USB2.0 DVB-T receiver (TwinhanDTV Alpha/MagicBox II)",
263 .cold_ids = { &vp7045_usb_table[0], NULL },
264 .warm_ids = { &vp7045_usb_table[1], NULL },
265 },
266 { .name = "DigitalNow TinyUSB 2 DVB-t Receiver",
267 .cold_ids = { &vp7045_usb_table[2], NULL },
268 .warm_ids = { &vp7045_usb_table[3], NULL },
269 },
Al Virodad08df2006-02-01 06:02:50 -0500270 { NULL },
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700271 }
272};
273
274/* usb specific object needed to register this driver with the usb subsystem */
275static struct usb_driver vp7045_usb_driver = {
Patrick Boettcher63b5c1c2005-07-07 17:58:30 -0700276 .name = "dvb_usb_vp7045",
Patrick Boettcher3beab782005-09-09 13:02:50 -0700277 .probe = vp7045_usb_probe,
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700278 .disconnect = dvb_usb_device_exit,
Patrick Boettcher3beab782005-09-09 13:02:50 -0700279 .id_table = vp7045_usb_table,
Johannes Stezenbach776338e2005-06-23 22:02:35 -0700280};
281
282/* module stuff */
283static int __init vp7045_usb_module_init(void)
284{
285 int result;
286 if ((result = usb_register(&vp7045_usb_driver))) {
287 err("usb_register failed. (%d)",result);
288 return result;
289 }
290
291 return 0;
292}
293
294static void __exit vp7045_usb_module_exit(void)
295{
296 /* deregister this driver from the USB subsystem */
297 usb_deregister(&vp7045_usb_driver);
298}
299
300module_init(vp7045_usb_module_init);
301module_exit(vp7045_usb_module_exit);
302
303MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
304MODULE_DESCRIPTION("Driver for Twinhan MagicBox/Alpha and DNTV tinyUSB2 DVB-T USB2.0");
305MODULE_VERSION("1.0");
306MODULE_LICENSE("GPL");