]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/media/dvb/dvb-usb/au6610.c
V4L/DVB (7950): AU6610: coding style fixes
[mv-sheeva.git] / 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 int au6610_identify_state(struct usb_device *udev,
119                                  struct dvb_usb_device_properties *props,
120                                  struct dvb_usb_device_description **desc,
121                                  int *cold)
122 {
123         *cold = 0;
124         return 0;
125 }
126
127 static struct zl10353_config au6610_zl10353_config = {
128         .demod_address = 0x0f,
129         .no_tuner = 1,
130         .parallel_ts = 1,
131 };
132
133 static int au6610_zl10353_frontend_attach(struct dvb_usb_adapter *adap)
134 {
135         adap->fe = dvb_attach(zl10353_attach, &au6610_zl10353_config,
136                 &adap->dev->i2c_adap);
137         if (adap->fe == NULL)
138                 return -EIO;
139
140         return 0;
141 }
142
143 static struct qt1010_config au6610_qt1010_config = {
144         .i2c_address = 0x62
145 };
146
147 static int au6610_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
148 {
149         return dvb_attach(qt1010_attach,
150                           adap->fe, &adap->dev->i2c_adap,
151                           &au6610_qt1010_config) == NULL ? -ENODEV : 0;
152 }
153
154 /* DVB USB Driver stuff */
155 static struct dvb_usb_device_properties au6610_properties;
156
157 static int au6610_probe(struct usb_interface *intf,
158                         const struct usb_device_id *id)
159 {
160         struct dvb_usb_device *d;
161         struct usb_host_interface *alt;
162         int ret;
163
164         if (intf->num_altsetting < AU6610_ALTSETTING_COUNT)
165                 return -ENODEV;
166
167         ret = dvb_usb_device_init(intf, &au6610_properties, THIS_MODULE, &d,
168                                   adapter_nr);
169         if (ret == 0) {
170                 alt = usb_altnum_to_altsetting(intf, AU6610_ALTSETTING);
171
172                 if (alt == NULL) {
173                         deb_rc("no alt found!\n");
174                         return -ENODEV;
175                 }
176                 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
177                                         alt->desc.bAlternateSetting);
178         }
179
180         return ret;
181 }
182
183
184 static struct usb_device_id au6610_table [] = {
185         { USB_DEVICE(USB_VID_ALCOR_MICRO, USB_PID_SIGMATEK_DVB_110) },
186         { }             /* Terminating entry */
187 };
188 MODULE_DEVICE_TABLE(usb, au6610_table);
189
190 static struct dvb_usb_device_properties au6610_properties = {
191         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
192         .usb_ctrl = DEVICE_SPECIFIC,
193         .size_of_priv     = 0,
194         .identify_state   = au6610_identify_state,
195         .num_adapters = 1,
196         .adapter = {
197                 {
198                         .frontend_attach  = au6610_zl10353_frontend_attach,
199                         .tuner_attach     = au6610_qt1010_tuner_attach,
200
201                         .stream = {
202                                 .type = USB_ISOC,
203                                 .count = 5,
204                                 .endpoint = 0x82,
205                                 .u = {
206                                         .isoc = {
207                                                 .framesperurb = 40,
208                                                 .framesize = 942,
209                                                 .interval = 1.25,   /* 125 us */
210                                         }
211                                 }
212                         },
213                 }
214         },
215         .i2c_algo = &au6610_i2c_algo,
216         .num_device_descs = 1,
217         .devices = {
218                 {
219                         "Sigmatek DVB-110 DVB-T USB2.0",
220                         { &au6610_table[0], NULL },
221                         { NULL },
222                 },
223         }
224 };
225
226 static struct usb_driver au6610_driver = {
227         .name       = "dvb_usb_au6610",
228         .probe      = au6610_probe,
229         .disconnect = dvb_usb_device_exit,
230         .id_table   = au6610_table,
231 };
232
233 /* module stuff */
234 static int __init au6610_module_init(void)
235 {
236         int ret;
237
238         ret = usb_register(&au6610_driver);
239         if (ret)
240                 err("usb_register failed. Error number %d", ret);
241
242         return ret;
243 }
244
245 static void __exit au6610_module_exit(void)
246 {
247         /* deregister this driver from the USB subsystem */
248         usb_deregister(&au6610_driver);
249 }
250
251 module_init(au6610_module_init);
252 module_exit(au6610_module_exit);
253
254 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
255 MODULE_DESCRIPTION("Driver Sigmatek DVB-110 DVB-T USB2.0 / AU6610");
256 MODULE_VERSION("0.1");
257 MODULE_LICENSE("GPL");