Commit | Line | Data |
---|---|---|
53af158a AP |
1 | /* |
2 | * DVB USB Linux driver for Alcor Micro AU6610 DVB-T USB2.0. | |
5decdd27 | 3 | * |
4c7e3ea9 | 4 | * Copyright (C) 2006 Antti Palosaari <crope@iki.fi> |
5decdd27 | 5 | * |
53af158a AP |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
5decdd27 | 10 | * |
53af158a AP |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
5decdd27 AP |
19 | */ |
20 | ||
21 | #include "au6610.h" | |
5decdd27 AP |
22 | #include "zl10353.h" |
23 | #include "qt1010.h" | |
24 | ||
25 | /* debug */ | |
26 | static int dvb_usb_au6610_debug; | |
27 | module_param_named(debug, dvb_usb_au6610_debug, int, 0644); | |
53af158a | 28 | MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS); |
78e92006 JG |
29 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
30 | ||
5decdd27 AP |
31 | static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr, |
32 | u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) | |
33 | { | |
34 | int ret; | |
35 | u16 index; | |
2a596f84 FM |
36 | u8 *usb_buf; |
37 | ||
38 | /* | |
39 | * allocate enough for all known requests, | |
40 | * read returns 5 and write 6 bytes | |
41 | */ | |
42 | usb_buf = kmalloc(6, GFP_KERNEL); | |
43 | if (!usb_buf) | |
44 | return -ENOMEM; | |
45 | ||
5decdd27 AP |
46 | switch (wlen) { |
47 | case 1: | |
48 | index = wbuf[0] << 8; | |
49 | break; | |
50 | case 2: | |
51 | index = wbuf[0] << 8; | |
52 | index += wbuf[1]; | |
53 | break; | |
54 | default: | |
55 | warn("wlen = %x, aborting.", wlen); | |
2a596f84 FM |
56 | ret = -EINVAL; |
57 | goto error; | |
5decdd27 AP |
58 | } |
59 | ||
60 | ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), operation, | |
b6b2d268 | 61 | USB_TYPE_VENDOR|USB_DIR_IN, addr << 1, index, |
2a596f84 | 62 | usb_buf, 6, AU6610_USB_TIMEOUT); |
5decdd27 | 63 | if (ret < 0) |
2a596f84 | 64 | goto error; |
5decdd27 AP |
65 | |
66 | switch (operation) { | |
67 | case AU6610_REQ_I2C_READ: | |
68 | case AU6610_REQ_USB_READ: | |
69 | /* requested value is always 5th byte in buffer */ | |
70 | rbuf[0] = usb_buf[4]; | |
71 | } | |
2a596f84 FM |
72 | error: |
73 | kfree(usb_buf); | |
5decdd27 AP |
74 | return ret; |
75 | } | |
76 | ||
38d0629f MK |
77 | static int au6610_i2c_msg(struct dvb_usb_device *d, u8 addr, |
78 | u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) | |
5decdd27 AP |
79 | { |
80 | u8 request; | |
81 | u8 wo = (rbuf == NULL || rlen == 0); /* write-only */ | |
82 | ||
83 | if (wo) { | |
84 | request = AU6610_REQ_I2C_WRITE; | |
85 | } else { /* rw */ | |
86 | request = AU6610_REQ_I2C_READ; | |
87 | } | |
88 | ||
89 | return au6610_usb_msg(d, request, addr, wbuf, wlen, rbuf, rlen); | |
90 | } | |
91 | ||
92 | ||
93 | /* I2C */ | |
38d0629f MK |
94 | static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
95 | int num) | |
5decdd27 AP |
96 | { |
97 | struct dvb_usb_device *d = i2c_get_adapdata(adap); | |
98 | int i; | |
99 | ||
5decdd27 AP |
100 | if (num > 2) |
101 | return -EINVAL; | |
102 | ||
c80296d7 RK |
103 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
104 | return -EAGAIN; | |
105 | ||
5decdd27 AP |
106 | for (i = 0; i < num; i++) { |
107 | /* write/read request */ | |
108 | if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { | |
109 | if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf, | |
38d0629f MK |
110 | msg[i].len, msg[i+1].buf, |
111 | msg[i+1].len) < 0) | |
5decdd27 AP |
112 | break; |
113 | i++; | |
114 | } else if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf, | |
115 | msg[i].len, NULL, 0) < 0) | |
116 | break; | |
117 | } | |
118 | ||
119 | mutex_unlock(&d->i2c_mutex); | |
120 | return i; | |
121 | } | |
122 | ||
123 | ||
124 | static u32 au6610_i2c_func(struct i2c_adapter *adapter) | |
125 | { | |
126 | return I2C_FUNC_I2C; | |
127 | } | |
128 | ||
129 | static struct i2c_algorithm au6610_i2c_algo = { | |
130 | .master_xfer = au6610_i2c_xfer, | |
131 | .functionality = au6610_i2c_func, | |
132 | }; | |
133 | ||
134 | /* Callbacks for DVB USB */ | |
5decdd27 | 135 | static struct zl10353_config au6610_zl10353_config = { |
26a154c3 | 136 | .demod_address = 0x0f, |
5decdd27 AP |
137 | .no_tuner = 1, |
138 | .parallel_ts = 1, | |
139 | }; | |
140 | ||
5decdd27 AP |
141 | static int au6610_zl10353_frontend_attach(struct dvb_usb_adapter *adap) |
142 | { | |
b6b2d268 AP |
143 | adap->fe = dvb_attach(zl10353_attach, &au6610_zl10353_config, |
144 | &adap->dev->i2c_adap); | |
145 | if (adap->fe == NULL) | |
53af158a | 146 | return -ENODEV; |
5decdd27 | 147 | |
b6b2d268 | 148 | return 0; |
5decdd27 AP |
149 | } |
150 | ||
4c7e3ea9 | 151 | static struct qt1010_config au6610_qt1010_config = { |
26a154c3 | 152 | .i2c_address = 0x62 |
4c7e3ea9 AP |
153 | }; |
154 | ||
155 | static int au6610_qt1010_tuner_attach(struct dvb_usb_adapter *adap) | |
156 | { | |
4c7e3ea9 AP |
157 | return dvb_attach(qt1010_attach, |
158 | adap->fe, &adap->dev->i2c_adap, | |
159 | &au6610_qt1010_config) == NULL ? -ENODEV : 0; | |
160 | } | |
161 | ||
5decdd27 AP |
162 | /* DVB USB Driver stuff */ |
163 | static struct dvb_usb_device_properties au6610_properties; | |
164 | ||
38d0629f MK |
165 | static int au6610_probe(struct usb_interface *intf, |
166 | const struct usb_device_id *id) | |
5decdd27 AP |
167 | { |
168 | struct dvb_usb_device *d; | |
169 | struct usb_host_interface *alt; | |
170 | int ret; | |
171 | ||
172 | if (intf->num_altsetting < AU6610_ALTSETTING_COUNT) | |
173 | return -ENODEV; | |
174 | ||
78e92006 JG |
175 | ret = dvb_usb_device_init(intf, &au6610_properties, THIS_MODULE, &d, |
176 | adapter_nr); | |
177 | if (ret == 0) { | |
5decdd27 AP |
178 | alt = usb_altnum_to_altsetting(intf, AU6610_ALTSETTING); |
179 | ||
180 | if (alt == NULL) { | |
53af158a | 181 | deb_info("%s: no alt found!\n", __func__); |
5decdd27 AP |
182 | return -ENODEV; |
183 | } | |
184 | ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber, | |
185 | alt->desc.bAlternateSetting); | |
186 | } | |
187 | ||
188 | return ret; | |
189 | } | |
190 | ||
5decdd27 AP |
191 | static struct usb_device_id au6610_table [] = { |
192 | { USB_DEVICE(USB_VID_ALCOR_MICRO, USB_PID_SIGMATEK_DVB_110) }, | |
193 | { } /* Terminating entry */ | |
194 | }; | |
b6b2d268 | 195 | MODULE_DEVICE_TABLE(usb, au6610_table); |
5decdd27 AP |
196 | |
197 | static struct dvb_usb_device_properties au6610_properties = { | |
198 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, | |
53af158a | 199 | |
5decdd27 | 200 | .usb_ctrl = DEVICE_SPECIFIC, |
53af158a AP |
201 | |
202 | .size_of_priv = 0, | |
203 | ||
5decdd27 AP |
204 | .num_adapters = 1, |
205 | .adapter = { | |
206 | { | |
207 | .frontend_attach = au6610_zl10353_frontend_attach, | |
4c7e3ea9 | 208 | .tuner_attach = au6610_qt1010_tuner_attach, |
5decdd27 AP |
209 | |
210 | .stream = { | |
211 | .type = USB_ISOC, | |
212 | .count = 5, | |
213 | .endpoint = 0x82, | |
214 | .u = { | |
215 | .isoc = { | |
216 | .framesperurb = 40, | |
b6b2d268 | 217 | .framesize = 942, |
53af158a | 218 | .interval = 1, |
5decdd27 AP |
219 | } |
220 | } | |
221 | }, | |
222 | } | |
223 | }, | |
53af158a | 224 | |
5decdd27 | 225 | .i2c_algo = &au6610_i2c_algo, |
bbf23af2 | 226 | |
5decdd27 AP |
227 | .num_device_descs = 1, |
228 | .devices = { | |
229 | { | |
bbf23af2 AP |
230 | .name = "Sigmatek DVB-110 DVB-T USB2.0", |
231 | .cold_ids = {NULL}, | |
232 | .warm_ids = {&au6610_table[0], NULL}, | |
5decdd27 AP |
233 | }, |
234 | } | |
235 | }; | |
236 | ||
237 | static struct usb_driver au6610_driver = { | |
238 | .name = "dvb_usb_au6610", | |
239 | .probe = au6610_probe, | |
240 | .disconnect = dvb_usb_device_exit, | |
241 | .id_table = au6610_table, | |
242 | }; | |
243 | ||
244 | /* module stuff */ | |
245 | static int __init au6610_module_init(void) | |
246 | { | |
247 | int ret; | |
248 | ||
b6b2d268 AP |
249 | ret = usb_register(&au6610_driver); |
250 | if (ret) | |
5decdd27 | 251 | err("usb_register failed. Error number %d", ret); |
5decdd27 | 252 | |
b6b2d268 | 253 | return ret; |
5decdd27 AP |
254 | } |
255 | ||
256 | static void __exit au6610_module_exit(void) | |
257 | { | |
258 | /* deregister this driver from the USB subsystem */ | |
259 | usb_deregister(&au6610_driver); | |
260 | } | |
261 | ||
b6b2d268 AP |
262 | module_init(au6610_module_init); |
263 | module_exit(au6610_module_exit); | |
5decdd27 AP |
264 | |
265 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); | |
53af158a | 266 | MODULE_DESCRIPTION("Driver for Alcor Micro AU6610 DVB-T USB2.0"); |
5decdd27 AP |
267 | MODULE_VERSION("0.1"); |
268 | MODULE_LICENSE("GPL"); |