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