blob: df78811f5234fc821e81baa62ee266de79a08654 [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
Antti Palosaarifb495582008-05-28 22:16:31 -03004 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation, version 2.
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -03006 *
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
Janne Grunau78e92002008-04-09 19:13:13 -030014DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
15
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030016static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr,
Michael Krufky1f788672006-10-03 17:21:13 -030017 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030018{
19 u16 index;
Aapo Tahkola26a154c2007-03-05 18:25:36 -030020 u16 value = addr << (8 + 1);
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030021 int wo = (rbuf == NULL || rlen == 0); /* write-only */
22 u8 req, type;
23
24 if (wo) {
25 req = GL861_REQ_I2C_WRITE;
26 type = GL861_WRITE;
27 } else { /* rw */
28 req = GL861_REQ_I2C_READ;
29 type = GL861_READ;
30 }
31
32 switch (wlen) {
Michael Krufky1f788672006-10-03 17:21:13 -030033 case 1:
34 index = wbuf[0];
35 break;
36 case 2:
37 index = wbuf[0];
38 value = value + wbuf[1];
39 break;
40 default:
Antti Palosaari4d2e5962012-06-26 18:25:51 -030041 pr_err("%s: wlen=%d, aborting\n", KBUILD_MODNAME, wlen);
Michael Krufky1f788672006-10-03 17:21:13 -030042 return -EINVAL;
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030043 }
44
Antti Palosaari1a78db82008-06-10 11:41:58 -030045 msleep(1); /* avoid I2C errors */
Antti Palosaarif56ebe12008-05-28 21:55:06 -030046
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030047 return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type,
Michael Krufky1f788672006-10-03 17:21:13 -030048 value, index, rbuf, rlen, 2000);
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030049}
50
51/* I2C */
52static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
Michael Krufky1f788672006-10-03 17:21:13 -030053 int num)
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030054{
55 struct dvb_usb_device *d = i2c_get_adapdata(adap);
56 int i;
57
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030058 if (num > 2)
59 return -EINVAL;
60
Roel Kluinc80296d2007-11-06 10:25:16 -030061 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
62 return -EAGAIN;
63
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030064 for (i = 0; i < num; i++) {
65 /* write/read request */
66 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
67 if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf,
Antti Palosaarifb495582008-05-28 22:16:31 -030068 msg[i].len, msg[i+1].buf, msg[i+1].len) < 0)
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030069 break;
70 i++;
71 } else
72 if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf,
Michael Krufky1f788672006-10-03 17:21:13 -030073 msg[i].len, NULL, 0) < 0)
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030074 break;
75 }
76
77 mutex_unlock(&d->i2c_mutex);
78 return i;
79}
80
81static u32 gl861_i2c_func(struct i2c_adapter *adapter)
82{
83 return I2C_FUNC_I2C;
84}
85
86static struct i2c_algorithm gl861_i2c_algo = {
87 .master_xfer = gl861_i2c_xfer,
88 .functionality = gl861_i2c_func,
89};
90
91/* Callbacks for DVB USB */
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030092static struct zl10353_config gl861_zl10353_config = {
Aapo Tahkola26a154c2007-03-05 18:25:36 -030093 .demod_address = 0x0f,
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030094 .no_tuner = 1,
Carl Lundqvist4131fd42006-10-09 12:49:17 -030095 .parallel_ts = 1,
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -030096};
97
98static int gl861_frontend_attach(struct dvb_usb_adapter *adap)
99{
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300100
Antti Palosaari4d2e5962012-06-26 18:25:51 -0300101 adap->fe[0] = dvb_attach(zl10353_attach, &gl861_zl10353_config,
102 &adap_to_d(adap)->i2c_adap);
103 if (adap->fe[0] == NULL)
Antti Palosaarifb495582008-05-28 22:16:31 -0300104 return -EIO;
105
106 return 0;
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300107}
108
Antti Palosaari4c7e3ea2007-01-21 15:56:10 -0300109static struct qt1010_config gl861_qt1010_config = {
Aapo Tahkola26a154c2007-03-05 18:25:36 -0300110 .i2c_address = 0x62
Antti Palosaari4c7e3ea2007-01-21 15:56:10 -0300111};
112
113static int gl861_tuner_attach(struct dvb_usb_adapter *adap)
114{
Antti Palosaari4c7e3ea2007-01-21 15:56:10 -0300115 return dvb_attach(qt1010_attach,
Antti Palosaari4d2e5962012-06-26 18:25:51 -0300116 adap->fe[0], &adap_to_d(adap)->i2c_adap,
Antti Palosaari4c7e3ea2007-01-21 15:56:10 -0300117 &gl861_qt1010_config) == NULL ? -ENODEV : 0;
118}
119
Antti Palosaari4d2e5962012-06-26 18:25:51 -0300120static int gl861_init(struct dvb_usb_device *d)
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300121{
Antti Palosaari4d2e5962012-06-26 18:25:51 -0300122 /*
123 * There is 2 interfaces. Interface 0 is for TV and interface 1 is
124 * for HID remote controller. Interface 0 has 2 alternate settings.
125 * For some reason we need to set interface explicitly, defaulted
126 * as alternate setting 1?
127 */
128 return usb_set_interface(d->udev, 0, 0);
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300129}
130
Antti Palosaari4d2e5962012-06-26 18:25:51 -0300131/* DVB USB Driver stuff */
132static struct dvb_usb_device_properties gl861_props = {
133 .driver_name = KBUILD_MODNAME,
134 .owner = THIS_MODULE,
135 .adapter_nr = adapter_nr,
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300136
Antti Palosaari4d2e5962012-06-26 18:25:51 -0300137 .i2c_algo = &gl861_i2c_algo,
138 .frontend_attach = gl861_frontend_attach,
139 .tuner_attach = gl861_tuner_attach,
140 .init = gl861_init,
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300141
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300142 .num_adapters = 1,
Antti Palosaari4d2e5962012-06-26 18:25:51 -0300143 .adapter = {
Antti Palosaariea3a13b2008-05-28 22:04:12 -0300144 {
Antti Palosaari4d2e5962012-06-26 18:25:51 -0300145 .stream = DVB_USB_STREAM_BULK(0x81, 7, 512),
146 }
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300147 }
148};
149
Antti Palosaari4d2e5962012-06-26 18:25:51 -0300150static const struct usb_device_id gl861_id_table[] = {
151 { DVB_USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580_55801,
152 &gl861_props, "MSI Mega Sky 55801 DVB-T USB2.0", NULL) },
153 { DVB_USB_DEVICE(USB_VID_ALINK, USB_VID_ALINK_DTU,
154 &gl861_props, "A-LINK DTU DVB-T USB2.0", NULL) },
155 { }
156};
157MODULE_DEVICE_TABLE(usb, gl861_id_table);
158
159static struct usb_driver gl861_usb_driver = {
160 .name = KBUILD_MODNAME,
161 .id_table = gl861_id_table,
162 .probe = dvb_usbv2_probe,
163 .disconnect = dvb_usbv2_disconnect,
164 .suspend = dvb_usbv2_suspend,
165 .resume = dvb_usbv2_resume,
Antti Palosaari0b8623c2012-08-21 09:08:51 -0300166 .reset_resume = dvb_usbv2_reset_resume,
Antti Palosaari4d2e5962012-06-26 18:25:51 -0300167 .no_dynamic_id = 1,
168 .soft_unbind = 1,
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300169};
170
Antti Palosaari4d2e5962012-06-26 18:25:51 -0300171module_usb_driver(gl861_usb_driver);
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300172
Michael Krufky947af8f2006-10-03 17:14:07 -0300173MODULE_AUTHOR("Carl Lundqvist <comabug@gmail.com>");
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300174MODULE_DESCRIPTION("Driver MSI Mega Sky 580 DVB-T USB2.0 / GL861");
Carl Lundqvist4131fd42006-10-09 12:49:17 -0300175MODULE_VERSION("0.1");
Carl Lundqvistf0c3a2c2006-10-03 17:09:30 -0300176MODULE_LICENSE("GPL");