]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/media/dvb/dvb-usb/au6610.c
[media] gl861: convert to new DVB USB
[mirror_ubuntu-hirsute-kernel.git] / drivers / media / dvb / dvb-usb / au6610.c
1 /*
2 * DVB USB Linux driver for Alcor Micro AU6610 DVB-T USB2.0.
3 *
4 * Copyright (C) 2006 Antti Palosaari <crope@iki.fi>
5 *
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.
10 *
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.
19 */
20
21 #include "au6610.h"
22 #include "zl10353.h"
23 #include "qt1010.h"
24
25 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
26
27 static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr,
28 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
29 {
30 int ret;
31 u16 index;
32 u8 *usb_buf;
33
34 /*
35 * allocate enough for all known requests,
36 * read returns 5 and write 6 bytes
37 */
38 usb_buf = kmalloc(6, GFP_KERNEL);
39 if (!usb_buf)
40 return -ENOMEM;
41
42 switch (wlen) {
43 case 1:
44 index = wbuf[0] << 8;
45 break;
46 case 2:
47 index = wbuf[0] << 8;
48 index += wbuf[1];
49 break;
50 default:
51 pr_err("%s: wlen = %d, aborting\n", KBUILD_MODNAME, wlen);
52 ret = -EINVAL;
53 goto error;
54 }
55
56 ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), operation,
57 USB_TYPE_VENDOR|USB_DIR_IN, addr << 1, index,
58 usb_buf, 6, AU6610_USB_TIMEOUT);
59 if (ret < 0)
60 goto error;
61
62 switch (operation) {
63 case AU6610_REQ_I2C_READ:
64 case AU6610_REQ_USB_READ:
65 /* requested value is always 5th byte in buffer */
66 rbuf[0] = usb_buf[4];
67 }
68 error:
69 kfree(usb_buf);
70 return ret;
71 }
72
73 static int au6610_i2c_msg(struct dvb_usb_device *d, u8 addr,
74 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
75 {
76 u8 request;
77 u8 wo = (rbuf == NULL || rlen == 0); /* write-only */
78
79 if (wo) {
80 request = AU6610_REQ_I2C_WRITE;
81 } else { /* rw */
82 request = AU6610_REQ_I2C_READ;
83 }
84
85 return au6610_usb_msg(d, request, addr, wbuf, wlen, rbuf, rlen);
86 }
87
88
89 /* I2C */
90 static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
91 int num)
92 {
93 struct dvb_usb_device *d = i2c_get_adapdata(adap);
94 int i;
95
96 if (num > 2)
97 return -EINVAL;
98
99 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
100 return -EAGAIN;
101
102 for (i = 0; i < num; i++) {
103 /* write/read request */
104 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
105 if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
106 msg[i].len, msg[i+1].buf,
107 msg[i+1].len) < 0)
108 break;
109 i++;
110 } else if (au6610_i2c_msg(d, msg[i].addr, msg[i].buf,
111 msg[i].len, NULL, 0) < 0)
112 break;
113 }
114
115 mutex_unlock(&d->i2c_mutex);
116 return i;
117 }
118
119
120 static u32 au6610_i2c_func(struct i2c_adapter *adapter)
121 {
122 return I2C_FUNC_I2C;
123 }
124
125 static struct i2c_algorithm au6610_i2c_algo = {
126 .master_xfer = au6610_i2c_xfer,
127 .functionality = au6610_i2c_func,
128 };
129
130 /* Callbacks for DVB USB */
131 static struct zl10353_config au6610_zl10353_config = {
132 .demod_address = 0x0f,
133 .no_tuner = 1,
134 .parallel_ts = 1,
135 };
136
137 static int au6610_zl10353_frontend_attach(struct dvb_usb_adapter *adap)
138 {
139 adap->fe[0] = dvb_attach(zl10353_attach, &au6610_zl10353_config,
140 &adap_to_d(adap)->i2c_adap);
141 if (adap->fe[0] == NULL)
142 return -ENODEV;
143
144 return 0;
145 }
146
147 static struct qt1010_config au6610_qt1010_config = {
148 .i2c_address = 0x62
149 };
150
151 static int au6610_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
152 {
153 return dvb_attach(qt1010_attach, adap->fe[0],
154 &adap_to_d(adap)->i2c_adap,
155 &au6610_qt1010_config) == NULL ? -ENODEV : 0;
156 }
157
158 static int au6610_init(struct dvb_usb_device *d)
159 {
160 /* TODO: this functionality belongs likely to the streaming control */
161 /* bInterfaceNumber 0, bAlternateSetting 5 */
162 return usb_set_interface(d->udev, 0, 5);
163 }
164
165 static struct dvb_usb_device_properties au6610_props = {
166 .driver_name = KBUILD_MODNAME,
167 .owner = THIS_MODULE,
168 .adapter_nr = adapter_nr,
169
170 .i2c_algo = &au6610_i2c_algo,
171 .frontend_attach = au6610_zl10353_frontend_attach,
172 .tuner_attach = au6610_qt1010_tuner_attach,
173 .init = au6610_init,
174
175 .num_adapters = 1,
176 .adapter = {
177 {
178 .stream = DVB_USB_STREAM_ISOC(0x82, 5, 40, 942, 1),
179 },
180 },
181 };
182
183 static const struct usb_device_id au6610_id_table[] = {
184 { DVB_USB_DEVICE(USB_VID_ALCOR_MICRO, USB_PID_SIGMATEK_DVB_110,
185 &au6610_props, "Sigmatek DVB-110", NULL) },
186 { }
187 };
188 MODULE_DEVICE_TABLE(usb, au6610_id_table);
189
190 static struct usb_driver au6610_driver = {
191 .name = KBUILD_MODNAME,
192 .id_table = au6610_id_table,
193 .probe = dvb_usbv2_probe,
194 .disconnect = dvb_usbv2_disconnect,
195 .suspend = dvb_usbv2_suspend,
196 .resume = dvb_usbv2_resume,
197 .no_dynamic_id = 1,
198 .soft_unbind = 1,
199 };
200
201 module_usb_driver(au6610_driver);
202
203 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
204 MODULE_DESCRIPTION("Driver for Alcor Micro AU6610 DVB-T USB2.0");
205 MODULE_VERSION("0.1");
206 MODULE_LICENSE("GPL");