Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 1 | /* 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 |
| 4 | * under the terms of the GNU General Public License as published by the Free |
| 5 | * Software Foundation, version 2. |
| 6 | * |
| 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 | |
| 14 | /* debug */ |
| 15 | int dvb_usb_gl861_debug; |
| 16 | module_param_named(debug,dvb_usb_gl861_debug, int, 0644); |
| 17 | MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS); |
| 18 | |
| 19 | static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr, |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 20 | u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 21 | { |
| 22 | u16 index; |
| 23 | u16 value = addr << 8; |
| 24 | int wo = (rbuf == NULL || rlen == 0); /* write-only */ |
| 25 | u8 req, type; |
| 26 | |
| 27 | if (wo) { |
| 28 | req = GL861_REQ_I2C_WRITE; |
| 29 | type = GL861_WRITE; |
| 30 | } else { /* rw */ |
| 31 | req = GL861_REQ_I2C_READ; |
| 32 | type = GL861_READ; |
| 33 | } |
| 34 | |
| 35 | switch (wlen) { |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 36 | case 1: |
| 37 | index = wbuf[0]; |
| 38 | break; |
| 39 | case 2: |
| 40 | index = wbuf[0]; |
| 41 | value = value + wbuf[1]; |
| 42 | break; |
| 43 | default: |
| 44 | warn("wlen = %x, aborting.", wlen); |
| 45 | return -EINVAL; |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), req, type, |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 49 | value, index, rbuf, rlen, 2000); |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /* I2C */ |
| 53 | static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 54 | int num) |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 55 | { |
| 56 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 57 | int i; |
| 58 | |
| 59 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 60 | return -EAGAIN; |
| 61 | |
| 62 | if (num > 2) |
| 63 | return -EINVAL; |
| 64 | |
| 65 | for (i = 0; i < num; i++) { |
| 66 | /* write/read request */ |
| 67 | if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) { |
| 68 | if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf, |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 69 | msg[i].len, msg[i+1].buf, msg[i+1].len) < 0) |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 70 | break; |
| 71 | i++; |
| 72 | } else |
| 73 | if (gl861_i2c_msg(d, msg[i].addr, msg[i].buf, |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 74 | msg[i].len, NULL, 0) < 0) |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 75 | break; |
| 76 | } |
| 77 | |
| 78 | mutex_unlock(&d->i2c_mutex); |
| 79 | return i; |
| 80 | } |
| 81 | |
| 82 | static u32 gl861_i2c_func(struct i2c_adapter *adapter) |
| 83 | { |
| 84 | return I2C_FUNC_I2C; |
| 85 | } |
| 86 | |
| 87 | static struct i2c_algorithm gl861_i2c_algo = { |
| 88 | .master_xfer = gl861_i2c_xfer, |
| 89 | .functionality = gl861_i2c_func, |
| 90 | }; |
| 91 | |
| 92 | /* Callbacks for DVB USB */ |
| 93 | static int gl861_identify_state(struct usb_device *udev, |
| 94 | struct dvb_usb_device_properties *props, |
| 95 | struct dvb_usb_device_description **desc, |
| 96 | int *cold) |
| 97 | { |
| 98 | *cold = 0; |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | static struct zl10353_config gl861_zl10353_config = { |
| 104 | .demod_address = 0x1e, |
| 105 | .no_tuner = 1, |
Carl Lundqvist | 4131fd4 | 2006-10-09 12:49:17 -0300 | [diff] [blame^] | 106 | .parallel_ts = 1, |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | static int gl861_frontend_attach(struct dvb_usb_adapter *adap) |
| 110 | { |
| 111 | if ((adap->fe = dvb_attach(zl10353_attach, &gl861_zl10353_config, |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 112 | &adap->dev->i2c_adap)) != NULL) { |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | return -EIO; |
| 117 | } |
| 118 | |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 119 | /* DVB USB Driver stuff */ |
| 120 | static struct dvb_usb_device_properties gl861_properties; |
| 121 | |
| 122 | static int gl861_probe(struct usb_interface *intf, |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 123 | const struct usb_device_id *id) |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 124 | { |
| 125 | struct dvb_usb_device *d; |
| 126 | struct usb_host_interface *alt; |
| 127 | int ret; |
| 128 | |
| 129 | if (intf->num_altsetting < 2) |
| 130 | return -ENODEV; |
| 131 | |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 132 | if ((ret = dvb_usb_device_init(intf, &gl861_properties, THIS_MODULE, &d)) == 0) { |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 133 | alt = usb_altnum_to_altsetting(intf, 0); |
| 134 | |
| 135 | if (alt == NULL) { |
| 136 | deb_rc("not alt found!\n"); |
| 137 | return -ENODEV; |
| 138 | } |
| 139 | |
| 140 | ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber, |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 141 | alt->desc.bAlternateSetting); |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | return ret; |
| 145 | } |
| 146 | |
| 147 | static struct usb_device_id gl861_table [] = { |
Michael Krufky | 6f7880f | 2006-10-03 17:12:14 -0300 | [diff] [blame] | 148 | { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580_55801) }, |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 149 | { } /* Terminating entry */ |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 150 | }; |
| 151 | MODULE_DEVICE_TABLE (usb, gl861_table); |
| 152 | |
| 153 | static struct dvb_usb_device_properties gl861_properties = { |
Jan Nijs | b3b2b8b | 2006-10-07 01:25:53 -0300 | [diff] [blame] | 154 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 155 | .usb_ctrl = DEVICE_SPECIFIC, |
| 156 | |
| 157 | .size_of_priv = 0, |
| 158 | |
| 159 | .identify_state = gl861_identify_state, |
| 160 | .num_adapters = 1, |
| 161 | .adapter = {{ |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 162 | |
| 163 | .frontend_attach = gl861_frontend_attach, |
Michael Krufky | 6ae7232 | 2006-10-03 17:19:30 -0300 | [diff] [blame] | 164 | .tuner_attach = qt1010_tuner_attach, |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 165 | |
| 166 | .stream = { |
| 167 | .type = USB_BULK, |
| 168 | .count = 7, |
| 169 | .endpoint = 0x81, |
| 170 | .u = { |
| 171 | .bulk = { |
| 172 | .buffersize = 512, |
| 173 | } |
| 174 | } |
| 175 | }, |
| 176 | }}, |
| 177 | .i2c_algo = &gl861_i2c_algo, |
| 178 | |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 179 | .num_device_descs = 1, |
| 180 | .devices = { |
| 181 | { "MSI Mega Sky 55801 DVB-T USB2.0", |
| 182 | { &gl861_table[0], NULL }, |
| 183 | { NULL }, |
| 184 | }, |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 185 | } |
| 186 | }; |
| 187 | |
| 188 | static struct usb_driver gl861_driver = { |
Michael Krufky | 05ec6cc | 2006-10-03 17:15:26 -0300 | [diff] [blame] | 189 | .name = "dvb_usb_gl861", |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 190 | .probe = gl861_probe, |
| 191 | .disconnect = dvb_usb_device_exit, |
| 192 | .id_table = gl861_table, |
| 193 | }; |
| 194 | |
| 195 | /* module stuff */ |
| 196 | static int __init gl861_module_init(void) |
| 197 | { |
| 198 | int ret; |
| 199 | |
| 200 | if ((ret = usb_register(&gl861_driver))) { |
| 201 | err("usb_register failed. Error number %d", ret); |
| 202 | return ret; |
| 203 | } |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | static void __exit gl861_module_exit(void) |
| 209 | { |
| 210 | /* deregister this driver from the USB subsystem */ |
| 211 | usb_deregister(&gl861_driver); |
| 212 | } |
| 213 | |
| 214 | module_init (gl861_module_init); |
| 215 | module_exit (gl861_module_exit); |
| 216 | |
Michael Krufky | 947af8f | 2006-10-03 17:14:07 -0300 | [diff] [blame] | 217 | MODULE_AUTHOR("Carl Lundqvist <comabug@gmail.com>"); |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 218 | MODULE_DESCRIPTION("Driver MSI Mega Sky 580 DVB-T USB2.0 / GL861"); |
Carl Lundqvist | 4131fd4 | 2006-10-09 12:49:17 -0300 | [diff] [blame^] | 219 | MODULE_VERSION("0.1"); |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 220 | MODULE_LICENSE("GPL"); |