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 |
Antti Palosaari | fb49558 | 2008-05-28 22:16:31 -0300 | [diff] [blame] | 4 | * under the terms of the GNU General Public License as published by the |
| 5 | * Free Software Foundation, version 2. |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 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 | |
Janne Grunau | 78e9200 | 2008-04-09 19:13:13 -0300 | [diff] [blame] | 14 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 15 | |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 16 | static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr, |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 17 | u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 18 | { |
| 19 | u16 index; |
Aapo Tahkola | 26a154c | 2007-03-05 18:25:36 -0300 | [diff] [blame] | 20 | u16 value = addr << (8 + 1); |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 21 | int wo = (rbuf == NULL || rlen == 0); /* write-only */ |
| 22 | u8 req, type; |
| 23 | |
| 24 | if (wo) { |
| 25 | req = GL861_REQ_I2C_WRITE; |
| 26 | type = GL861_WRITE; |
| 27 | } else { /* rw */ |
| 28 | req = GL861_REQ_I2C_READ; |
| 29 | type = GL861_READ; |
| 30 | } |
| 31 | |
| 32 | switch (wlen) { |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 33 | case 1: |
| 34 | index = wbuf[0]; |
| 35 | break; |
| 36 | case 2: |
| 37 | index = wbuf[0]; |
| 38 | value = value + wbuf[1]; |
| 39 | break; |
| 40 | default: |
Antti Palosaari | 8152768 | 2012-09-12 20:23:55 -0300 | [diff] [blame] | 41 | dev_err(&d->udev->dev, "%s: wlen=%d, aborting\n", |
| 42 | KBUILD_MODNAME, wlen); |
Michael Krufky | 1f78867 | 2006-10-03 17:21:13 -0300 | [diff] [blame] | 43 | return -EINVAL; |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 44 | } |
| 45 | |
Antti Palosaari | 1a78db8 | 2008-06-10 11:41:58 -0300 | [diff] [blame] | 46 | msleep(1); /* avoid I2C errors */ |
Antti Palosaari | f56ebe1 | 2008-05-28 21:55:06 -0300 | [diff] [blame] | 47 | |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 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 | |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 59 | if (num > 2) |
| 60 | return -EINVAL; |
| 61 | |
Roel Kluin | c80296d | 2007-11-06 10:25:16 -0300 | [diff] [blame] | 62 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 63 | return -EAGAIN; |
| 64 | |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 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, |
Antti Palosaari | fb49558 | 2008-05-28 22:16:31 -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 */ |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 93 | static struct zl10353_config gl861_zl10353_config = { |
Aapo Tahkola | 26a154c | 2007-03-05 18:25:36 -0300 | [diff] [blame] | 94 | .demod_address = 0x0f, |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 95 | .no_tuner = 1, |
Carl Lundqvist | 4131fd4 | 2006-10-09 12:49:17 -0300 | [diff] [blame] | 96 | .parallel_ts = 1, |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | static int gl861_frontend_attach(struct dvb_usb_adapter *adap) |
| 100 | { |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 101 | |
Antti Palosaari | 4d2e596 | 2012-06-26 18:25:51 -0300 | [diff] [blame] | 102 | adap->fe[0] = dvb_attach(zl10353_attach, &gl861_zl10353_config, |
| 103 | &adap_to_d(adap)->i2c_adap); |
| 104 | if (adap->fe[0] == NULL) |
Antti Palosaari | fb49558 | 2008-05-28 22:16:31 -0300 | [diff] [blame] | 105 | return -EIO; |
| 106 | |
| 107 | return 0; |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 108 | } |
| 109 | |
Antti Palosaari | 4c7e3ea | 2007-01-21 15:56:10 -0300 | [diff] [blame] | 110 | static struct qt1010_config gl861_qt1010_config = { |
Aapo Tahkola | 26a154c | 2007-03-05 18:25:36 -0300 | [diff] [blame] | 111 | .i2c_address = 0x62 |
Antti Palosaari | 4c7e3ea | 2007-01-21 15:56:10 -0300 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | static int gl861_tuner_attach(struct dvb_usb_adapter *adap) |
| 115 | { |
Antti Palosaari | 4c7e3ea | 2007-01-21 15:56:10 -0300 | [diff] [blame] | 116 | return dvb_attach(qt1010_attach, |
Antti Palosaari | 4d2e596 | 2012-06-26 18:25:51 -0300 | [diff] [blame] | 117 | adap->fe[0], &adap_to_d(adap)->i2c_adap, |
Antti Palosaari | 4c7e3ea | 2007-01-21 15:56:10 -0300 | [diff] [blame] | 118 | &gl861_qt1010_config) == NULL ? -ENODEV : 0; |
| 119 | } |
| 120 | |
Antti Palosaari | 4d2e596 | 2012-06-26 18:25:51 -0300 | [diff] [blame] | 121 | static int gl861_init(struct dvb_usb_device *d) |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 122 | { |
Antti Palosaari | 4d2e596 | 2012-06-26 18:25:51 -0300 | [diff] [blame] | 123 | /* |
| 124 | * There is 2 interfaces. Interface 0 is for TV and interface 1 is |
| 125 | * for HID remote controller. Interface 0 has 2 alternate settings. |
| 126 | * For some reason we need to set interface explicitly, defaulted |
| 127 | * as alternate setting 1? |
| 128 | */ |
| 129 | return usb_set_interface(d->udev, 0, 0); |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 130 | } |
| 131 | |
Antti Palosaari | 4d2e596 | 2012-06-26 18:25:51 -0300 | [diff] [blame] | 132 | /* DVB USB Driver stuff */ |
| 133 | static struct dvb_usb_device_properties gl861_props = { |
| 134 | .driver_name = KBUILD_MODNAME, |
| 135 | .owner = THIS_MODULE, |
| 136 | .adapter_nr = adapter_nr, |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 137 | |
Antti Palosaari | 4d2e596 | 2012-06-26 18:25:51 -0300 | [diff] [blame] | 138 | .i2c_algo = &gl861_i2c_algo, |
| 139 | .frontend_attach = gl861_frontend_attach, |
| 140 | .tuner_attach = gl861_tuner_attach, |
| 141 | .init = gl861_init, |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 142 | |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 143 | .num_adapters = 1, |
Antti Palosaari | 4d2e596 | 2012-06-26 18:25:51 -0300 | [diff] [blame] | 144 | .adapter = { |
Antti Palosaari | ea3a13b7 | 2008-05-28 22:04:12 -0300 | [diff] [blame] | 145 | { |
Antti Palosaari | 4d2e596 | 2012-06-26 18:25:51 -0300 | [diff] [blame] | 146 | .stream = DVB_USB_STREAM_BULK(0x81, 7, 512), |
| 147 | } |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 148 | } |
| 149 | }; |
| 150 | |
Antti Palosaari | 4d2e596 | 2012-06-26 18:25:51 -0300 | [diff] [blame] | 151 | static const struct usb_device_id gl861_id_table[] = { |
| 152 | { DVB_USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580_55801, |
| 153 | &gl861_props, "MSI Mega Sky 55801 DVB-T USB2.0", NULL) }, |
| 154 | { DVB_USB_DEVICE(USB_VID_ALINK, USB_VID_ALINK_DTU, |
| 155 | &gl861_props, "A-LINK DTU DVB-T USB2.0", NULL) }, |
| 156 | { } |
| 157 | }; |
| 158 | MODULE_DEVICE_TABLE(usb, gl861_id_table); |
| 159 | |
| 160 | static struct usb_driver gl861_usb_driver = { |
| 161 | .name = KBUILD_MODNAME, |
| 162 | .id_table = gl861_id_table, |
| 163 | .probe = dvb_usbv2_probe, |
| 164 | .disconnect = dvb_usbv2_disconnect, |
| 165 | .suspend = dvb_usbv2_suspend, |
| 166 | .resume = dvb_usbv2_resume, |
Antti Palosaari | 0b8623c | 2012-08-21 09:08:51 -0300 | [diff] [blame] | 167 | .reset_resume = dvb_usbv2_reset_resume, |
Antti Palosaari | 4d2e596 | 2012-06-26 18:25:51 -0300 | [diff] [blame] | 168 | .no_dynamic_id = 1, |
| 169 | .soft_unbind = 1, |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 170 | }; |
| 171 | |
Antti Palosaari | 4d2e596 | 2012-06-26 18:25:51 -0300 | [diff] [blame] | 172 | module_usb_driver(gl861_usb_driver); |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 173 | |
Michael Krufky | 947af8f | 2006-10-03 17:14:07 -0300 | [diff] [blame] | 174 | MODULE_AUTHOR("Carl Lundqvist <comabug@gmail.com>"); |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 175 | MODULE_DESCRIPTION("Driver MSI Mega Sky 580 DVB-T USB2.0 / GL861"); |
Carl Lundqvist | 4131fd4 | 2006-10-09 12:49:17 -0300 | [diff] [blame] | 176 | MODULE_VERSION("0.1"); |
Carl Lundqvist | f0c3a2c | 2006-10-03 17:09:30 -0300 | [diff] [blame] | 177 | MODULE_LICENSE("GPL"); |