blob: 0a8ac64a4e33a6a345cd6eea538b7397a33c6536 [file] [log] [blame]
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -03001/* DVB USB compliant linux driver for GL861 USB2.0 devices.
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation, version 2.
6 *
7 * see Documentation/dvb/README.dvb-usb for more information
8 */
9#include "gl861.h"
10
11#include "zl10353.h"
12#include "qt1010.h"
13
14/* debug */
Adrian Bunk37219292007-04-27 12:31:05 -030015static int dvb_usb_gl861_debug;
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030016module_param_named(debug,dvb_usb_gl861_debug, int, 0644);
17MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
18
Janne Grunau78e92002008-04-09 19:13:13 -030019DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
20
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030021static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr,
Michael Krufky1f788672006-10-03 17:21:13 -030022 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030023{
24 u16 index;
Aapo Tahkola26a154c2007-03-05 18:25:36 -030025 u16 value = addr << (8 + 1);
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030026 int wo = (rbuf == NULL || rlen == 0); /* write-only */
27 u8 req, type;
28
29 if (wo) {
30 req = GL861_REQ_I2C_WRITE;
31 type = GL861_WRITE;
32 } else { /* rw */
33 req = GL861_REQ_I2C_READ;
34 type = GL861_READ;
35 }
36
37 switch (wlen) {
Michael Krufky1f788672006-10-03 17:21:13 -030038 case 1:
39 index = wbuf[0];
40 break;
41 case 2:
42 index = wbuf[0];
43 value = value + wbuf[1];
44 break;
45 default:
46 warn("wlen = %x, aborting.", wlen);
47 return -EINVAL;
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030048 }
49
50 return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
Michael Krufky1f788672006-10-03 17:21:13 -030051 value, index, rbuf, rlen, 2000);
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030052}
53
54/* I2C */
55static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
Michael Krufky1f788672006-10-03 17:21:13 -030056 int num)
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030057{
58 struct dvb_usb_device *d = i2c_get_adapdata(adap);
59 int i;
60
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030061 if (num > 2)
62 return -EINVAL;
63
Roel Kluinc80296d2007-11-06 10:25:16 -030064 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
65 return -EAGAIN;
66
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030067 for (i = 0; i < num; i++) {
68 /* write/read request */
69 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
70 if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf,
Michael Krufky1f788672006-10-03 17:21:13 -030071 msg[i].len, msg[i+1].buf, msg[i+1].len) < 0)
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030072 break;
73 i++;
74 } else
75 if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf,
Michael Krufky1f788672006-10-03 17:21:13 -030076 msg[i].len, NULL, 0) < 0)
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030077 break;
78 }
79
80 mutex_unlock(&d->i2c_mutex);
81 return i;
82}
83
84static u32 gl861_i2c_func(struct i2c_adapter *adapter)
85{
86 return I2C_FUNC_I2C;
87}
88
89static struct i2c_algorithm gl861_i2c_algo = {
90 .master_xfer = gl861_i2c_xfer,
91 .functionality = gl861_i2c_func,
92};
93
94/* Callbacks for DVB USB */
95static int gl861_identify_state(struct usb_device *udev,
96 struct dvb_usb_device_properties *props,
97 struct dvb_usb_device_description **desc,
98 int *cold)
99{
100 *cold = 0;
101
102 return 0;
103}
104
105static struct zl10353_config gl861_zl10353_config = {
Aapo Tahkola26a154c2007-03-05 18:25:36 -0300106 .demod_address = 0x0f,
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300107 .no_tuner = 1,
Carl Lundqvist4131fd42006-10-09 12:49:17 -0300108 .parallel_ts = 1,
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300109};
110
111static int gl861_frontend_attach(struct dvb_usb_adapter *adap)
112{
113 if ((adap->fe = dvb_attach(zl10353_attach, &gl861_zl10353_config,
Michael Krufky1f788672006-10-03 17:21:13 -0300114 &adap->dev->i2c_adap)) != NULL) {
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300115 return 0;
116 }
117
118 return -EIO;
119}
120
Antti Palosaari4c7e3ea2007-01-21 15:56:10 -0300121static struct qt1010_config gl861_qt1010_config = {
Aapo Tahkola26a154c2007-03-05 18:25:36 -0300122 .i2c_address = 0x62
Antti Palosaari4c7e3ea2007-01-21 15:56:10 -0300123};
124
125static int gl861_tuner_attach(struct dvb_usb_adapter *adap)
126{
Antti Palosaari4c7e3ea2007-01-21 15:56:10 -0300127 return dvb_attach(qt1010_attach,
128 adap->fe, &adap->dev->i2c_adap,
129 &gl861_qt1010_config) == NULL ? -ENODEV : 0;
130}
131
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300132/* DVB USB Driver stuff */
133static struct dvb_usb_device_properties gl861_properties;
134
135static int gl861_probe(struct usb_interface *intf,
Michael Krufky1f788672006-10-03 17:21:13 -0300136 const struct usb_device_id *id)
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300137{
138 struct dvb_usb_device *d;
139 struct usb_host_interface *alt;
140 int ret;
141
142 if (intf->num_altsetting < 2)
143 return -ENODEV;
144
Janne Grunau78e92002008-04-09 19:13:13 -0300145 ret = dvb_usb_device_init(intf, &gl861_properties, THIS_MODULE, &d,
146 adapter_nr);
147 if (ret == 0) {
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300148 alt = usb_altnum_to_altsetting(intf, 0);
149
150 if (alt == NULL) {
151 deb_rc("not alt found!\n");
152 return -ENODEV;
153 }
154
155 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
Michael Krufky1f788672006-10-03 17:21:13 -0300156 alt->desc.bAlternateSetting);
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300157 }
158
159 return ret;
160}
161
162static struct usb_device_id gl861_table [] = {
Michael Krufky6f7880f2006-10-03 17:12:14 -0300163 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580_55801) },
Aapo Tahkola4919c492007-05-08 17:36:40 -0300164 { USB_DEVICE(USB_VID_ALINK, USB_VID_ALINK_DTU) },
Michael Krufky1f788672006-10-03 17:21:13 -0300165 { } /* Terminating entry */
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300166};
167MODULE_DEVICE_TABLE (usb, gl861_table);
168
169static struct dvb_usb_device_properties gl861_properties = {
Jan Nijsb3b2b8b2006-10-07 01:25:53 -0300170 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300171 .usb_ctrl = DEVICE_SPECIFIC,
172
173 .size_of_priv = 0,
174
175 .identify_state = gl861_identify_state,
176 .num_adapters = 1,
177 .adapter = {{
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300178
179 .frontend_attach = gl861_frontend_attach,
Antti Palosaari4c7e3ea2007-01-21 15:56:10 -0300180 .tuner_attach = gl861_tuner_attach,
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300181
182 .stream = {
183 .type = USB_BULK,
184 .count = 7,
185 .endpoint = 0x81,
186 .u = {
187 .bulk = {
188 .buffersize = 512,
189 }
190 }
191 },
192 }},
193 .i2c_algo = &gl861_i2c_algo,
194
Aapo Tahkola4919c492007-05-08 17:36:40 -0300195 .num_device_descs = 2,
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300196 .devices = {
197 { "MSI Mega Sky 55801 DVB-T USB2.0",
198 { &gl861_table[0], NULL },
199 { NULL },
200 },
Aapo Tahkola4919c492007-05-08 17:36:40 -0300201 { "A-LINK DTU DVB-T USB2.0",
202 { &gl861_table[1], NULL },
203 { NULL },
204 },
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300205 }
206};
207
208static struct usb_driver gl861_driver = {
Michael Krufky05ec6cc2006-10-03 17:15:26 -0300209 .name = "dvb_usb_gl861",
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300210 .probe = gl861_probe,
211 .disconnect = dvb_usb_device_exit,
212 .id_table = gl861_table,
213};
214
215/* module stuff */
216static int __init gl861_module_init(void)
217{
218 int ret;
219
220 if ((ret = usb_register(&gl861_driver))) {
221 err("usb_register failed. Error number %d", ret);
222 return ret;
223 }
224
225 return 0;
226}
227
228static void __exit gl861_module_exit(void)
229{
230 /* deregister this driver from the USB subsystem */
231 usb_deregister(&gl861_driver);
232}
233
234module_init (gl861_module_init);
235module_exit (gl861_module_exit);
236
Michael Krufky947af8f2006-10-03 17:14:07 -0300237MODULE_AUTHOR("Carl Lundqvist <comabug@gmail.com>");
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300238MODULE_DESCRIPTION("Driver MSI Mega Sky 580 DVB-T USB2.0 / GL861");
Carl Lundqvist4131fd42006-10-09 12:49:17 -0300239MODULE_VERSION("0.1");
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300240MODULE_LICENSE("GPL");