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