Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1 | /* |
| 2 | * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver |
| 3 | * |
| 4 | * Copyright (C) 2007 Antti Palosaari <crope@iki.fi> |
| 5 | * |
| 6 | * Thanks to Afatech who kindly provided information. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | * |
| 22 | */ |
| 23 | |
Jiri Slaby | 6c61404 | 2010-01-22 12:10:52 -0300 | [diff] [blame] | 24 | #include <linux/hash.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Jiri Slaby | 6c61404 | 2010-01-22 12:10:52 -0300 | [diff] [blame] | 26 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 27 | #include "af9015.h" |
| 28 | #include "af9013.h" |
| 29 | #include "mt2060.h" |
| 30 | #include "qt1010.h" |
| 31 | #include "tda18271.h" |
| 32 | #include "mxl5005s.h" |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 33 | #include "mc44s803.h" |
Antti Palosaari | ee3d440 | 2010-08-13 03:51:26 -0300 | [diff] [blame] | 34 | #include "tda18218.h" |
Antti Palosaari | ab07fdd | 2010-09-09 14:59:10 -0300 | [diff] [blame] | 35 | #include "mxl5007t.h" |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 36 | |
Antti Palosaari | 349d042 | 2008-11-05 16:31:24 -0300 | [diff] [blame] | 37 | static int dvb_usb_af9015_debug; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 38 | module_param_named(debug, dvb_usb_af9015_debug, int, 0644); |
| 39 | MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS); |
Antti Palosaari | 349d042 | 2008-11-05 16:31:24 -0300 | [diff] [blame] | 40 | static int dvb_usb_af9015_remote; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 41 | module_param_named(remote, dvb_usb_af9015_remote, int, 0644); |
| 42 | MODULE_PARM_DESC(remote, "select remote"); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 43 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 44 | |
| 45 | static DEFINE_MUTEX(af9015_usb_mutex); |
| 46 | |
| 47 | static struct af9015_config af9015_config; |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 48 | static struct dvb_usb_device_properties af9015_properties[3]; |
Antti Palosaari | 349d042 | 2008-11-05 16:31:24 -0300 | [diff] [blame] | 49 | static int af9015_properties_count = ARRAY_SIZE(af9015_properties); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 50 | |
| 51 | static struct af9013_config af9015_af9013_config[] = { |
| 52 | { |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 53 | .i2c_addr = AF9015_I2C_DEMOD, |
| 54 | .ts_mode = AF9013_TS_USB, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 55 | .api_version = { 0, 1, 9, 0 }, |
| 56 | .gpio[0] = AF9013_GPIO_HI, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 57 | .gpio[3] = AF9013_GPIO_TUNER_ON, |
| 58 | |
| 59 | }, { |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 60 | .ts_mode = AF9013_TS_SERIAL, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 61 | .api_version = { 0, 1, 9, 0 }, |
| 62 | .gpio[0] = AF9013_GPIO_TUNER_ON, |
| 63 | .gpio[1] = AF9013_GPIO_LO, |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | static int af9015_rw_udev(struct usb_device *udev, struct req_t *req) |
| 68 | { |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 69 | #define BUF_LEN 63 |
| 70 | #define REQ_HDR_LEN 8 /* send header size */ |
| 71 | #define ACK_HDR_LEN 2 /* rece header size */ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 72 | int act_len, ret; |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 73 | u8 buf[BUF_LEN]; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 74 | u8 write = 1; |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 75 | u8 msg_len = REQ_HDR_LEN; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 76 | static u8 seq; /* packet sequence number */ |
| 77 | |
| 78 | if (mutex_lock_interruptible(&af9015_usb_mutex) < 0) |
| 79 | return -EAGAIN; |
| 80 | |
| 81 | buf[0] = req->cmd; |
| 82 | buf[1] = seq++; |
| 83 | buf[2] = req->i2c_addr; |
| 84 | buf[3] = req->addr >> 8; |
| 85 | buf[4] = req->addr & 0xff; |
| 86 | buf[5] = req->mbox; |
| 87 | buf[6] = req->addr_len; |
| 88 | buf[7] = req->data_len; |
| 89 | |
| 90 | switch (req->cmd) { |
| 91 | case GET_CONFIG: |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 92 | case READ_MEMORY: |
| 93 | case RECONNECT_USB: |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 94 | write = 0; |
| 95 | break; |
| 96 | case READ_I2C: |
| 97 | write = 0; |
| 98 | buf[2] |= 0x01; /* set I2C direction */ |
| 99 | case WRITE_I2C: |
| 100 | buf[0] = READ_WRITE_I2C; |
| 101 | break; |
| 102 | case WRITE_MEMORY: |
| 103 | if (((req->addr & 0xff00) == 0xff00) || |
Antti Palosaari | f4e96de | 2009-09-12 21:25:59 -0300 | [diff] [blame] | 104 | ((req->addr & 0xff00) == 0xae00)) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 105 | buf[0] = WRITE_VIRTUAL_MEMORY; |
| 106 | case WRITE_VIRTUAL_MEMORY: |
| 107 | case COPY_FIRMWARE: |
| 108 | case DOWNLOAD_FIRMWARE: |
Nils Kassube | ba1bc64 | 2009-07-28 11:54:52 -0300 | [diff] [blame] | 109 | case BOOT: |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 110 | break; |
| 111 | default: |
| 112 | err("unknown command:%d", req->cmd); |
| 113 | ret = -1; |
| 114 | goto error_unlock; |
| 115 | } |
| 116 | |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 117 | /* buffer overflow check */ |
| 118 | if ((write && (req->data_len > BUF_LEN - REQ_HDR_LEN)) || |
| 119 | (!write && (req->data_len > BUF_LEN - ACK_HDR_LEN))) { |
| 120 | err("too much data; cmd:%d len:%d", req->cmd, req->data_len); |
| 121 | ret = -EINVAL; |
| 122 | goto error_unlock; |
| 123 | } |
| 124 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 125 | /* write requested */ |
| 126 | if (write) { |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 127 | memcpy(&buf[REQ_HDR_LEN], req->data, req->data_len); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 128 | msg_len += req->data_len; |
| 129 | } |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 130 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 131 | deb_xfer(">>> "); |
| 132 | debug_dump(buf, msg_len, deb_xfer); |
| 133 | |
| 134 | /* send req */ |
| 135 | ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x02), buf, msg_len, |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 136 | &act_len, AF9015_USB_TIMEOUT); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 137 | if (ret) |
| 138 | err("bulk message failed:%d (%d/%d)", ret, msg_len, act_len); |
| 139 | else |
| 140 | if (act_len != msg_len) |
| 141 | ret = -1; /* all data is not send */ |
| 142 | if (ret) |
| 143 | goto error_unlock; |
| 144 | |
| 145 | /* no ack for those packets */ |
| 146 | if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB) |
| 147 | goto exit_unlock; |
| 148 | |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 149 | /* write receives seq + status = 2 bytes |
| 150 | read receives seq + status + data = 2 + N bytes */ |
| 151 | msg_len = ACK_HDR_LEN; |
| 152 | if (!write) |
| 153 | msg_len += req->data_len; |
| 154 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 155 | ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, 0x81), buf, msg_len, |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 156 | &act_len, AF9015_USB_TIMEOUT); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 157 | if (ret) { |
| 158 | err("recv bulk message failed:%d", ret); |
| 159 | ret = -1; |
| 160 | goto error_unlock; |
| 161 | } |
| 162 | |
| 163 | deb_xfer("<<< "); |
| 164 | debug_dump(buf, act_len, deb_xfer); |
| 165 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 166 | /* check status */ |
| 167 | if (buf[1]) { |
| 168 | err("command failed:%d", buf[1]); |
| 169 | ret = -1; |
| 170 | goto error_unlock; |
| 171 | } |
| 172 | |
| 173 | /* read request, copy returned data to return buf */ |
| 174 | if (!write) |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 175 | memcpy(req->data, &buf[ACK_HDR_LEN], req->data_len); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 176 | |
| 177 | error_unlock: |
| 178 | exit_unlock: |
| 179 | mutex_unlock(&af9015_usb_mutex); |
| 180 | |
| 181 | return ret; |
| 182 | } |
| 183 | |
| 184 | static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req) |
| 185 | { |
| 186 | return af9015_rw_udev(d->udev, req); |
| 187 | } |
| 188 | |
| 189 | static int af9015_write_regs(struct dvb_usb_device *d, u16 addr, u8 *val, |
| 190 | u8 len) |
| 191 | { |
| 192 | struct req_t req = {WRITE_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len, |
| 193 | val}; |
| 194 | return af9015_ctrl_msg(d, &req); |
| 195 | } |
| 196 | |
| 197 | static int af9015_write_reg(struct dvb_usb_device *d, u16 addr, u8 val) |
| 198 | { |
| 199 | return af9015_write_regs(d, addr, &val, 1); |
| 200 | } |
| 201 | |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 202 | static int af9015_read_regs(struct dvb_usb_device *d, u16 addr, u8 *val, u8 len) |
| 203 | { |
| 204 | struct req_t req = {READ_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len, |
| 205 | val}; |
| 206 | return af9015_ctrl_msg(d, &req); |
| 207 | } |
| 208 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 209 | static int af9015_read_reg(struct dvb_usb_device *d, u16 addr, u8 *val) |
| 210 | { |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 211 | return af9015_read_regs(d, addr, val, 1); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg, |
| 215 | u8 val) |
| 216 | { |
| 217 | struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val}; |
| 218 | |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 219 | if (addr == af9015_af9013_config[0].i2c_addr || |
| 220 | addr == af9015_af9013_config[1].i2c_addr) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 221 | req.addr_len = 3; |
| 222 | |
| 223 | return af9015_ctrl_msg(d, &req); |
| 224 | } |
| 225 | |
| 226 | static int af9015_read_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg, |
| 227 | u8 *val) |
| 228 | { |
| 229 | struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val}; |
| 230 | |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 231 | if (addr == af9015_af9013_config[0].i2c_addr || |
| 232 | addr == af9015_af9013_config[1].i2c_addr) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 233 | req.addr_len = 3; |
| 234 | |
| 235 | return af9015_ctrl_msg(d, &req); |
| 236 | } |
| 237 | |
| 238 | static int af9015_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
| 239 | int num) |
| 240 | { |
| 241 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 242 | int ret = 0, i = 0; |
| 243 | u16 addr; |
Antti Palosaari | 675375d | 2010-10-07 21:46:41 -0300 | [diff] [blame] | 244 | u8 uninitialized_var(mbox), addr_len; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 245 | struct req_t req; |
| 246 | |
| 247 | /* TODO: implement bus lock |
| 248 | |
| 249 | The bus lock is needed because there is two tuners both using same I2C-address. |
| 250 | Due to that the only way to select correct tuner is use demodulator I2C-gate. |
| 251 | |
| 252 | ................................................ |
| 253 | . AF9015 includes integrated AF9013 demodulator. |
| 254 | . ____________ ____________ . ____________ |
| 255 | .| uC | | demod | . | tuner | |
| 256 | .|------------| |------------| . |------------| |
| 257 | .| AF9015 | | AF9013/5 | . | MXL5003 | |
| 258 | .| |--+----I2C-------|-----/ -----|-.-----I2C-------| | |
| 259 | .| | | | addr 0x38 | . | addr 0xc6 | |
| 260 | .|____________| | |____________| . |____________| |
| 261 | .................|.............................. |
| 262 | | ____________ ____________ |
| 263 | | | demod | | tuner | |
| 264 | | |------------| |------------| |
| 265 | | | AF9013 | | MXL5003 | |
| 266 | +----I2C-------|-----/ -----|-------I2C-------| | |
| 267 | | addr 0x3a | | addr 0xc6 | |
| 268 | |____________| |____________| |
| 269 | */ |
| 270 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 271 | return -EAGAIN; |
| 272 | |
| 273 | while (i < num) { |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 274 | if (msg[i].addr == af9015_af9013_config[0].i2c_addr || |
| 275 | msg[i].addr == af9015_af9013_config[1].i2c_addr) { |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 276 | addr = msg[i].buf[0] << 8; |
| 277 | addr += msg[i].buf[1]; |
| 278 | mbox = msg[i].buf[2]; |
| 279 | addr_len = 3; |
| 280 | } else { |
| 281 | addr = msg[i].buf[0]; |
| 282 | addr_len = 1; |
Antti Palosaari | 675375d | 2010-10-07 21:46:41 -0300 | [diff] [blame] | 283 | /* mbox is don't care in that case */ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) { |
Antti Palosaari | 709d920 | 2011-06-17 21:16:38 -0300 | [diff] [blame] | 287 | if (msg[i].len > 3 || msg[i+1].len > 61) { |
| 288 | ret = -EOPNOTSUPP; |
| 289 | goto error; |
| 290 | } |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 291 | if (msg[i].addr == af9015_af9013_config[0].i2c_addr) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 292 | req.cmd = READ_MEMORY; |
| 293 | else |
| 294 | req.cmd = READ_I2C; |
| 295 | req.i2c_addr = msg[i].addr; |
| 296 | req.addr = addr; |
| 297 | req.mbox = mbox; |
| 298 | req.addr_len = addr_len; |
| 299 | req.data_len = msg[i+1].len; |
| 300 | req.data = &msg[i+1].buf[0]; |
| 301 | ret = af9015_ctrl_msg(d, &req); |
| 302 | i += 2; |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 303 | } else if (msg[i].flags & I2C_M_RD) { |
Antti Palosaari | 709d920 | 2011-06-17 21:16:38 -0300 | [diff] [blame] | 304 | if (msg[i].len > 61) { |
| 305 | ret = -EOPNOTSUPP; |
| 306 | goto error; |
| 307 | } |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 308 | if (msg[i].addr == |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 309 | af9015_af9013_config[0].i2c_addr) { |
Antti Palosaari | 16b2dc2 | 2011-06-16 20:02:41 -0300 | [diff] [blame] | 310 | ret = -EINVAL; |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 311 | goto error; |
Antti Palosaari | 16b2dc2 | 2011-06-16 20:02:41 -0300 | [diff] [blame] | 312 | } |
| 313 | req.cmd = READ_I2C; |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 314 | req.i2c_addr = msg[i].addr; |
| 315 | req.addr = addr; |
| 316 | req.mbox = mbox; |
| 317 | req.addr_len = addr_len; |
| 318 | req.data_len = msg[i].len; |
| 319 | req.data = &msg[i].buf[0]; |
| 320 | ret = af9015_ctrl_msg(d, &req); |
| 321 | i += 1; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 322 | } else { |
Antti Palosaari | 709d920 | 2011-06-17 21:16:38 -0300 | [diff] [blame] | 323 | if (msg[i].len > 21) { |
| 324 | ret = -EOPNOTSUPP; |
| 325 | goto error; |
| 326 | } |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 327 | if (msg[i].addr == af9015_af9013_config[0].i2c_addr) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 328 | req.cmd = WRITE_MEMORY; |
| 329 | else |
| 330 | req.cmd = WRITE_I2C; |
| 331 | req.i2c_addr = msg[i].addr; |
| 332 | req.addr = addr; |
| 333 | req.mbox = mbox; |
| 334 | req.addr_len = addr_len; |
| 335 | req.data_len = msg[i].len-addr_len; |
| 336 | req.data = &msg[i].buf[addr_len]; |
| 337 | ret = af9015_ctrl_msg(d, &req); |
| 338 | i += 1; |
| 339 | } |
| 340 | if (ret) |
| 341 | goto error; |
| 342 | |
| 343 | } |
| 344 | ret = i; |
| 345 | |
| 346 | error: |
| 347 | mutex_unlock(&d->i2c_mutex); |
| 348 | |
| 349 | return ret; |
| 350 | } |
| 351 | |
| 352 | static u32 af9015_i2c_func(struct i2c_adapter *adapter) |
| 353 | { |
| 354 | return I2C_FUNC_I2C; |
| 355 | } |
| 356 | |
| 357 | static struct i2c_algorithm af9015_i2c_algo = { |
| 358 | .master_xfer = af9015_i2c_xfer, |
| 359 | .functionality = af9015_i2c_func, |
| 360 | }; |
| 361 | |
| 362 | static int af9015_do_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit, u8 op) |
| 363 | { |
| 364 | int ret; |
| 365 | u8 val, mask = 0x01; |
| 366 | |
| 367 | ret = af9015_read_reg(d, addr, &val); |
| 368 | if (ret) |
| 369 | return ret; |
| 370 | |
| 371 | mask <<= bit; |
| 372 | if (op) { |
| 373 | /* set bit */ |
| 374 | val |= mask; |
| 375 | } else { |
| 376 | /* clear bit */ |
| 377 | mask ^= 0xff; |
| 378 | val &= mask; |
| 379 | } |
| 380 | |
| 381 | return af9015_write_reg(d, addr, val); |
| 382 | } |
| 383 | |
| 384 | static int af9015_set_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit) |
| 385 | { |
| 386 | return af9015_do_reg_bit(d, addr, bit, 1); |
| 387 | } |
| 388 | |
| 389 | static int af9015_clear_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit) |
| 390 | { |
| 391 | return af9015_do_reg_bit(d, addr, bit, 0); |
| 392 | } |
| 393 | |
| 394 | static int af9015_init_endpoint(struct dvb_usb_device *d) |
| 395 | { |
| 396 | int ret; |
| 397 | u16 frame_size; |
| 398 | u8 packet_size; |
| 399 | deb_info("%s: USB speed:%d\n", __func__, d->udev->speed); |
| 400 | |
Antti Palosaari | 9c86327 | 2009-09-12 13:35:29 -0300 | [diff] [blame] | 401 | /* Windows driver uses packet count 21 for USB1.1 and 348 for USB2.0. |
| 402 | We use smaller - about 1/4 from the original, 5 and 87. */ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 403 | #define TS_PACKET_SIZE 188 |
| 404 | |
Antti Palosaari | 9c86327 | 2009-09-12 13:35:29 -0300 | [diff] [blame] | 405 | #define TS_USB20_PACKET_COUNT 87 |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 406 | #define TS_USB20_FRAME_SIZE (TS_PACKET_SIZE*TS_USB20_PACKET_COUNT) |
| 407 | |
Antti Palosaari | 9c86327 | 2009-09-12 13:35:29 -0300 | [diff] [blame] | 408 | #define TS_USB11_PACKET_COUNT 5 |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 409 | #define TS_USB11_FRAME_SIZE (TS_PACKET_SIZE*TS_USB11_PACKET_COUNT) |
| 410 | |
| 411 | #define TS_USB20_MAX_PACKET_SIZE 512 |
| 412 | #define TS_USB11_MAX_PACKET_SIZE 64 |
| 413 | |
| 414 | if (d->udev->speed == USB_SPEED_FULL) { |
| 415 | frame_size = TS_USB11_FRAME_SIZE/4; |
| 416 | packet_size = TS_USB11_MAX_PACKET_SIZE/4; |
| 417 | } else { |
| 418 | frame_size = TS_USB20_FRAME_SIZE/4; |
| 419 | packet_size = TS_USB20_MAX_PACKET_SIZE/4; |
| 420 | } |
| 421 | |
| 422 | ret = af9015_set_reg_bit(d, 0xd507, 2); /* assert EP4 reset */ |
| 423 | if (ret) |
| 424 | goto error; |
| 425 | ret = af9015_set_reg_bit(d, 0xd50b, 1); /* assert EP5 reset */ |
| 426 | if (ret) |
| 427 | goto error; |
| 428 | ret = af9015_clear_reg_bit(d, 0xdd11, 5); /* disable EP4 */ |
| 429 | if (ret) |
| 430 | goto error; |
| 431 | ret = af9015_clear_reg_bit(d, 0xdd11, 6); /* disable EP5 */ |
| 432 | if (ret) |
| 433 | goto error; |
| 434 | ret = af9015_set_reg_bit(d, 0xdd11, 5); /* enable EP4 */ |
| 435 | if (ret) |
| 436 | goto error; |
| 437 | if (af9015_config.dual_mode) { |
| 438 | ret = af9015_set_reg_bit(d, 0xdd11, 6); /* enable EP5 */ |
| 439 | if (ret) |
| 440 | goto error; |
| 441 | } |
| 442 | ret = af9015_clear_reg_bit(d, 0xdd13, 5); /* disable EP4 NAK */ |
| 443 | if (ret) |
| 444 | goto error; |
| 445 | if (af9015_config.dual_mode) { |
| 446 | ret = af9015_clear_reg_bit(d, 0xdd13, 6); /* disable EP5 NAK */ |
| 447 | if (ret) |
| 448 | goto error; |
| 449 | } |
| 450 | /* EP4 xfer length */ |
| 451 | ret = af9015_write_reg(d, 0xdd88, frame_size & 0xff); |
| 452 | if (ret) |
| 453 | goto error; |
| 454 | ret = af9015_write_reg(d, 0xdd89, frame_size >> 8); |
| 455 | if (ret) |
| 456 | goto error; |
| 457 | /* EP5 xfer length */ |
| 458 | ret = af9015_write_reg(d, 0xdd8a, frame_size & 0xff); |
| 459 | if (ret) |
| 460 | goto error; |
| 461 | ret = af9015_write_reg(d, 0xdd8b, frame_size >> 8); |
| 462 | if (ret) |
| 463 | goto error; |
| 464 | ret = af9015_write_reg(d, 0xdd0c, packet_size); /* EP4 packet size */ |
| 465 | if (ret) |
| 466 | goto error; |
| 467 | ret = af9015_write_reg(d, 0xdd0d, packet_size); /* EP5 packet size */ |
| 468 | if (ret) |
| 469 | goto error; |
| 470 | ret = af9015_clear_reg_bit(d, 0xd507, 2); /* negate EP4 reset */ |
| 471 | if (ret) |
| 472 | goto error; |
| 473 | if (af9015_config.dual_mode) { |
| 474 | ret = af9015_clear_reg_bit(d, 0xd50b, 1); /* negate EP5 reset */ |
| 475 | if (ret) |
| 476 | goto error; |
| 477 | } |
| 478 | |
| 479 | /* enable / disable mp2if2 */ |
| 480 | if (af9015_config.dual_mode) |
| 481 | ret = af9015_set_reg_bit(d, 0xd50b, 0); |
| 482 | else |
| 483 | ret = af9015_clear_reg_bit(d, 0xd50b, 0); |
Antti Palosaari | 1e8750c | 2011-03-18 19:36:42 -0300 | [diff] [blame] | 484 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 485 | error: |
| 486 | if (ret) |
| 487 | err("endpoint init failed:%d", ret); |
| 488 | return ret; |
| 489 | } |
| 490 | |
| 491 | static int af9015_copy_firmware(struct dvb_usb_device *d) |
| 492 | { |
| 493 | int ret; |
| 494 | u8 fw_params[4]; |
| 495 | u8 val, i; |
| 496 | struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params), |
| 497 | fw_params }; |
| 498 | deb_info("%s:\n", __func__); |
| 499 | |
| 500 | fw_params[0] = af9015_config.firmware_size >> 8; |
| 501 | fw_params[1] = af9015_config.firmware_size & 0xff; |
| 502 | fw_params[2] = af9015_config.firmware_checksum >> 8; |
| 503 | fw_params[3] = af9015_config.firmware_checksum & 0xff; |
| 504 | |
| 505 | /* wait 2nd demodulator ready */ |
| 506 | msleep(100); |
| 507 | |
Antti Palosaari | ed19a5d | 2010-09-12 21:02:55 -0300 | [diff] [blame] | 508 | ret = af9015_read_reg_i2c(d, |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 509 | af9015_af9013_config[1].i2c_addr, 0x98be, &val); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 510 | if (ret) |
| 511 | goto error; |
| 512 | else |
| 513 | deb_info("%s: firmware status:%02x\n", __func__, val); |
| 514 | |
| 515 | if (val == 0x0c) /* fw is running, no need for download */ |
| 516 | goto exit; |
| 517 | |
| 518 | /* set I2C master clock to fast (to speed up firmware copy) */ |
| 519 | ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */ |
| 520 | if (ret) |
| 521 | goto error; |
| 522 | |
| 523 | msleep(50); |
| 524 | |
| 525 | /* copy firmware */ |
| 526 | ret = af9015_ctrl_msg(d, &req); |
| 527 | if (ret) |
| 528 | err("firmware copy cmd failed:%d", ret); |
| 529 | deb_info("%s: firmware copy done\n", __func__); |
| 530 | |
| 531 | /* set I2C master clock back to normal */ |
| 532 | ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */ |
| 533 | if (ret) |
| 534 | goto error; |
| 535 | |
| 536 | /* request boot firmware */ |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 537 | ret = af9015_write_reg_i2c(d, af9015_af9013_config[1].i2c_addr, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 538 | 0xe205, 1); |
| 539 | deb_info("%s: firmware boot cmd status:%d\n", __func__, ret); |
| 540 | if (ret) |
| 541 | goto error; |
| 542 | |
| 543 | for (i = 0; i < 15; i++) { |
| 544 | msleep(100); |
| 545 | |
| 546 | /* check firmware status */ |
| 547 | ret = af9015_read_reg_i2c(d, |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 548 | af9015_af9013_config[1].i2c_addr, 0x98be, &val); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 549 | deb_info("%s: firmware status cmd status:%d fw status:%02x\n", |
| 550 | __func__, ret, val); |
| 551 | if (ret) |
| 552 | goto error; |
| 553 | |
| 554 | if (val == 0x0c || val == 0x04) /* success or fail */ |
| 555 | break; |
| 556 | } |
| 557 | |
| 558 | if (val == 0x04) { |
| 559 | err("firmware did not run"); |
| 560 | ret = -1; |
| 561 | } else if (val != 0x0c) { |
| 562 | err("firmware boot timeout"); |
| 563 | ret = -1; |
| 564 | } |
| 565 | |
| 566 | error: |
| 567 | exit: |
| 568 | return ret; |
| 569 | } |
| 570 | |
Jiri Slaby | 6c61404 | 2010-01-22 12:10:52 -0300 | [diff] [blame] | 571 | /* hash (and dump) eeprom */ |
| 572 | static int af9015_eeprom_hash(struct usb_device *udev) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 573 | { |
Jiri Slaby | 6c61404 | 2010-01-22 12:10:52 -0300 | [diff] [blame] | 574 | static const unsigned int eeprom_size = 256; |
| 575 | unsigned int reg; |
| 576 | int ret; |
| 577 | u8 val, *eeprom; |
| 578 | struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val}; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 579 | |
Jiri Slaby | 6c61404 | 2010-01-22 12:10:52 -0300 | [diff] [blame] | 580 | eeprom = kmalloc(eeprom_size, GFP_KERNEL); |
| 581 | if (eeprom == NULL) |
| 582 | return -ENOMEM; |
| 583 | |
| 584 | for (reg = 0; reg < eeprom_size; reg++) { |
| 585 | req.addr = reg; |
| 586 | ret = af9015_rw_udev(udev, &req); |
| 587 | if (ret) |
| 588 | goto free; |
| 589 | eeprom[reg] = val; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 590 | } |
Jiri Slaby | 6c61404 | 2010-01-22 12:10:52 -0300 | [diff] [blame] | 591 | |
| 592 | if (dvb_usb_af9015_debug & 0x01) |
| 593 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, eeprom, |
| 594 | eeprom_size); |
| 595 | |
| 596 | BUG_ON(eeprom_size % 4); |
| 597 | |
| 598 | af9015_config.eeprom_sum = 0; |
| 599 | for (reg = 0; reg < eeprom_size / sizeof(u32); reg++) { |
| 600 | af9015_config.eeprom_sum *= GOLDEN_RATIO_PRIME_32; |
| 601 | af9015_config.eeprom_sum += le32_to_cpu(((u32 *)eeprom)[reg]); |
| 602 | } |
| 603 | |
| 604 | deb_info("%s: eeprom sum=%.8x\n", __func__, af9015_config.eeprom_sum); |
| 605 | |
| 606 | ret = 0; |
| 607 | free: |
| 608 | kfree(eeprom); |
| 609 | return ret; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 610 | } |
| 611 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 612 | static int af9015_init(struct dvb_usb_device *d) |
| 613 | { |
| 614 | int ret; |
| 615 | deb_info("%s:\n", __func__); |
| 616 | |
Antti Palosaari | 1e8750c | 2011-03-18 19:36:42 -0300 | [diff] [blame] | 617 | /* init RC canary */ |
| 618 | ret = af9015_write_reg(d, 0x98e9, 0xff); |
| 619 | if (ret) |
| 620 | goto error; |
| 621 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 622 | ret = af9015_init_endpoint(d); |
| 623 | if (ret) |
| 624 | goto error; |
| 625 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 626 | error: |
| 627 | return ret; |
| 628 | } |
| 629 | |
| 630 | static int af9015_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 631 | { |
| 632 | int ret; |
| 633 | deb_info("%s: onoff:%d\n", __func__, onoff); |
| 634 | |
| 635 | if (onoff) |
| 636 | ret = af9015_set_reg_bit(adap->dev, 0xd503, 0); |
| 637 | else |
| 638 | ret = af9015_clear_reg_bit(adap->dev, 0xd503, 0); |
| 639 | |
| 640 | return ret; |
| 641 | } |
| 642 | |
| 643 | static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, |
| 644 | int onoff) |
| 645 | { |
| 646 | int ret; |
| 647 | u8 idx; |
| 648 | |
| 649 | deb_info("%s: set pid filter, index %d, pid %x, onoff %d\n", |
| 650 | __func__, index, pid, onoff); |
| 651 | |
| 652 | ret = af9015_write_reg(adap->dev, 0xd505, (pid & 0xff)); |
| 653 | if (ret) |
| 654 | goto error; |
| 655 | |
| 656 | ret = af9015_write_reg(adap->dev, 0xd506, (pid >> 8)); |
| 657 | if (ret) |
| 658 | goto error; |
| 659 | |
| 660 | idx = ((index & 0x1f) | (1 << 5)); |
| 661 | ret = af9015_write_reg(adap->dev, 0xd504, idx); |
| 662 | |
| 663 | error: |
| 664 | return ret; |
| 665 | } |
| 666 | |
| 667 | static int af9015_download_firmware(struct usb_device *udev, |
| 668 | const struct firmware *fw) |
| 669 | { |
Antti Palosaari | 582e565 | 2011-03-19 16:51:43 -0300 | [diff] [blame] | 670 | int i, len, remaining, ret; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 671 | struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL}; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 672 | u16 checksum = 0; |
| 673 | |
| 674 | deb_info("%s:\n", __func__); |
| 675 | |
| 676 | /* calc checksum */ |
| 677 | for (i = 0; i < fw->size; i++) |
| 678 | checksum += fw->data[i]; |
| 679 | |
| 680 | af9015_config.firmware_size = fw->size; |
| 681 | af9015_config.firmware_checksum = checksum; |
| 682 | |
Antti Palosaari | 582e565 | 2011-03-19 16:51:43 -0300 | [diff] [blame] | 683 | #define FW_ADDR 0x5100 /* firmware start address */ |
| 684 | #define LEN_MAX 55 /* max packet size */ |
| 685 | for (remaining = fw->size; remaining > 0; remaining -= LEN_MAX) { |
| 686 | len = remaining; |
| 687 | if (len > LEN_MAX) |
| 688 | len = LEN_MAX; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 689 | |
| 690 | req.data_len = len; |
Antti Palosaari | 582e565 | 2011-03-19 16:51:43 -0300 | [diff] [blame] | 691 | req.data = (u8 *) &fw->data[fw->size - remaining]; |
| 692 | req.addr = FW_ADDR + fw->size - remaining; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 693 | |
| 694 | ret = af9015_rw_udev(udev, &req); |
| 695 | if (ret) { |
Antti Palosaari | 582e565 | 2011-03-19 16:51:43 -0300 | [diff] [blame] | 696 | err("firmware download failed:%d", ret); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 697 | goto error; |
| 698 | } |
| 699 | } |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 700 | |
| 701 | /* firmware loaded, request boot */ |
| 702 | req.cmd = BOOT; |
| 703 | ret = af9015_rw_udev(udev, &req); |
| 704 | if (ret) { |
| 705 | err("firmware boot failed:%d", ret); |
| 706 | goto error; |
| 707 | } |
| 708 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 709 | error: |
| 710 | return ret; |
| 711 | } |
| 712 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 713 | struct af9015_rc_setup { |
Jiri Slaby | 26c3b8b | 2010-01-22 12:10:54 -0300 | [diff] [blame] | 714 | unsigned int id; |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 715 | char *rc_codes; |
Jiri Slaby | 26c3b8b | 2010-01-22 12:10:54 -0300 | [diff] [blame] | 716 | }; |
| 717 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 718 | static char *af9015_rc_setup_match(unsigned int id, |
| 719 | const struct af9015_rc_setup *table) |
Jiri Slaby | 26c3b8b | 2010-01-22 12:10:54 -0300 | [diff] [blame] | 720 | { |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 721 | for (; table->rc_codes; table++) |
Jiri Slaby | 26c3b8b | 2010-01-22 12:10:54 -0300 | [diff] [blame] | 722 | if (table->id == id) |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 723 | return table->rc_codes; |
Jiri Slaby | 26c3b8b | 2010-01-22 12:10:54 -0300 | [diff] [blame] | 724 | return NULL; |
| 725 | } |
| 726 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 727 | static const struct af9015_rc_setup af9015_rc_setup_modparam[] = { |
| 728 | { AF9015_REMOTE_A_LINK_DTU_M, RC_MAP_ALINK_DTU_M }, |
| 729 | { AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, RC_MAP_MSI_DIGIVOX_II }, |
| 730 | { AF9015_REMOTE_MYGICTV_U718, RC_MAP_TOTAL_MEDIA_IN_HAND }, |
| 731 | { AF9015_REMOTE_DIGITTRADE_DVB_T, RC_MAP_DIGITTRADE }, |
| 732 | { AF9015_REMOTE_AVERMEDIA_KS, RC_MAP_AVERMEDIA_RM_KS }, |
Jiri Slaby | 26c3b8b | 2010-01-22 12:10:54 -0300 | [diff] [blame] | 733 | { } |
| 734 | }; |
| 735 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 736 | static const struct af9015_rc_setup af9015_rc_setup_hashes[] = { |
| 737 | { 0xb8feb708, RC_MAP_MSI_DIGIVOX_II }, |
| 738 | { 0xa3703d00, RC_MAP_ALINK_DTU_M }, |
| 739 | { 0x9b7dc64e, RC_MAP_TOTAL_MEDIA_IN_HAND }, /* MYGICTV U718 */ |
Juergen Lock | 879b0d7 | 2011-06-12 17:25:12 -0300 | [diff] [blame] | 740 | { 0x5d49e3db, RC_MAP_DIGITTRADE }, /* LC-Power LC-USB-DVBT */ |
Jiri Slaby | 26c3b8b | 2010-01-22 12:10:54 -0300 | [diff] [blame] | 741 | { } |
| 742 | }; |
| 743 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 744 | static const struct af9015_rc_setup af9015_rc_setup_usbids[] = { |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 745 | { (USB_VID_TERRATEC << 16) | USB_PID_TERRATEC_CINERGY_T_STICK_RC, |
Antti Palosaari | 04599c2 | 2011-03-19 14:25:36 -0300 | [diff] [blame] | 746 | RC_MAP_TERRATEC_SLIM_2 }, |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 747 | { (USB_VID_TERRATEC << 16) | USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC, |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 748 | RC_MAP_TERRATEC_SLIM }, |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 749 | { (USB_VID_VISIONPLUS << 16) | USB_PID_AZUREWAVE_AD_TU700, |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 750 | RC_MAP_AZUREWAVE_AD_TU700 }, |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 751 | { (USB_VID_VISIONPLUS << 16) | USB_PID_TINYTWIN, |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 752 | RC_MAP_AZUREWAVE_AD_TU700 }, |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 753 | { (USB_VID_MSI_2 << 16) | USB_PID_MSI_DIGI_VOX_MINI_III, |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 754 | RC_MAP_MSI_DIGIVOX_III }, |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 755 | { (USB_VID_MSI_2 << 16) | USB_PID_MSI_DIGIVOX_DUO, |
Antti Palosaari | ae81aab | 2011-06-15 11:29:47 -0300 | [diff] [blame] | 756 | RC_MAP_MSI_DIGIVOX_III }, |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 757 | { (USB_VID_LEADTEK << 16) | USB_PID_WINFAST_DTV_DONGLE_GOLD, |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 758 | RC_MAP_LEADTEK_Y04G0051 }, |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 759 | { (USB_VID_LEADTEK << 16) | USB_PID_WINFAST_DTV2000DS, |
Antti Palosaari | 4c0cfa2 | 2011-07-28 19:15:38 -0300 | [diff] [blame] | 760 | RC_MAP_LEADTEK_Y04G0051 }, |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 761 | { (USB_VID_AVERMEDIA << 16) | USB_PID_AVERMEDIA_VOLAR_X, |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 762 | RC_MAP_AVERMEDIA_M135A }, |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 763 | { (USB_VID_AFATECH << 16) | USB_PID_TREKSTOR_DVBT, |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 764 | RC_MAP_TREKSTOR }, |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 765 | { (USB_VID_KWORLD_2 << 16) | USB_PID_TINYTWIN_2, |
Antti Palosaari | bd864ce | 2010-10-22 20:37:11 -0300 | [diff] [blame] | 766 | RC_MAP_DIGITALNOW_TINYTWIN }, |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 767 | { (USB_VID_GTEK << 16) | USB_PID_TINYTWIN_3, |
Antti Palosaari | f8c6127 | 2010-10-23 07:35:31 -0300 | [diff] [blame] | 768 | RC_MAP_DIGITALNOW_TINYTWIN }, |
Antti Palosaari | f68baef | 2011-07-28 19:17:59 -0300 | [diff] [blame] | 769 | { (USB_VID_KWORLD_2 << 16) | USB_PID_SVEON_STV22, |
Emilio David Diaus Lopez | a062d04 | 2011-07-12 19:53:39 -0300 | [diff] [blame] | 770 | RC_MAP_MSI_DIGIVOX_III }, |
Jiri Slaby | e3a0cc6 | 2010-01-22 12:10:55 -0300 | [diff] [blame] | 771 | { } |
| 772 | }; |
| 773 | |
Jiri Slaby | 634d2d7 | 2010-01-22 12:10:53 -0300 | [diff] [blame] | 774 | static void af9015_set_remote_config(struct usb_device *udev, |
| 775 | struct dvb_usb_device_properties *props) |
| 776 | { |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 777 | u16 vid = le16_to_cpu(udev->descriptor.idVendor); |
| 778 | u16 pid = le16_to_cpu(udev->descriptor.idProduct); |
Jiri Slaby | 26c3b8b | 2010-01-22 12:10:54 -0300 | [diff] [blame] | 779 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 780 | /* try to load remote based module param */ |
| 781 | props->rc.core.rc_codes = af9015_rc_setup_match( |
| 782 | dvb_usb_af9015_remote, af9015_rc_setup_modparam); |
Jiri Slaby | 26c3b8b | 2010-01-22 12:10:54 -0300 | [diff] [blame] | 783 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 784 | /* try to load remote based eeprom hash */ |
| 785 | if (!props->rc.core.rc_codes) |
| 786 | props->rc.core.rc_codes = af9015_rc_setup_match( |
| 787 | af9015_config.eeprom_sum, af9015_rc_setup_hashes); |
Jiri Slaby | e3a0cc6 | 2010-01-22 12:10:55 -0300 | [diff] [blame] | 788 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 789 | /* try to load remote based USB ID */ |
| 790 | if (!props->rc.core.rc_codes) |
| 791 | props->rc.core.rc_codes = af9015_rc_setup_match( |
| 792 | (vid << 16) + pid, af9015_rc_setup_usbids); |
| 793 | |
| 794 | /* try to load remote based USB iManufacturer string */ |
| 795 | if (!props->rc.core.rc_codes && vid == USB_VID_AFATECH) { |
| 796 | /* Check USB manufacturer and product strings and try |
| 797 | to determine correct remote in case of chip vendor |
| 798 | reference IDs are used. |
| 799 | DO NOT ADD ANYTHING NEW HERE. Use hashes instead. */ |
| 800 | char manufacturer[10]; |
| 801 | memset(manufacturer, 0, sizeof(manufacturer)); |
| 802 | usb_string(udev, udev->descriptor.iManufacturer, |
| 803 | manufacturer, sizeof(manufacturer)); |
| 804 | if (!strcmp("MSI", manufacturer)) { |
| 805 | /* iManufacturer 1 MSI |
| 806 | iProduct 2 MSI K-VOX */ |
| 807 | props->rc.core.rc_codes = af9015_rc_setup_match( |
| 808 | AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, |
| 809 | af9015_rc_setup_modparam); |
| 810 | } |
Jiri Slaby | 26c3b8b | 2010-01-22 12:10:54 -0300 | [diff] [blame] | 811 | } |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 812 | |
| 813 | /* finally load "empty" just for leaving IR receiver enabled */ |
| 814 | if (!props->rc.core.rc_codes) |
| 815 | props->rc.core.rc_codes = RC_MAP_EMPTY; |
| 816 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 817 | return; |
Jiri Slaby | 634d2d7 | 2010-01-22 12:10:53 -0300 | [diff] [blame] | 818 | } |
| 819 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 820 | static int af9015_read_config(struct usb_device *udev) |
| 821 | { |
| 822 | int ret; |
| 823 | u8 val, i, offset = 0; |
| 824 | struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val}; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 825 | |
| 826 | /* IR remote controller */ |
| 827 | req.addr = AF9015_EEPROM_IR_MODE; |
Antti Palosaari | d1a470f | 2009-01-20 14:56:20 -0300 | [diff] [blame] | 828 | /* first message will timeout often due to possible hw bug */ |
| 829 | for (i = 0; i < 4; i++) { |
| 830 | ret = af9015_rw_udev(udev, &req); |
| 831 | if (!ret) |
| 832 | break; |
| 833 | } |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 834 | if (ret) |
| 835 | goto error; |
Jiri Slaby | 6c61404 | 2010-01-22 12:10:52 -0300 | [diff] [blame] | 836 | |
| 837 | ret = af9015_eeprom_hash(udev); |
| 838 | if (ret) |
| 839 | goto error; |
| 840 | |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 841 | deb_info("%s: IR mode=%d\n", __func__, val); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 842 | for (i = 0; i < af9015_properties_count; i++) { |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 843 | if (val == AF9015_IR_MODE_DISABLED) |
| 844 | af9015_properties[i].rc.core.rc_codes = NULL; |
| 845 | else |
Jiri Slaby | 634d2d7 | 2010-01-22 12:10:53 -0300 | [diff] [blame] | 846 | af9015_set_remote_config(udev, &af9015_properties[i]); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | /* TS mode - one or two receivers */ |
| 850 | req.addr = AF9015_EEPROM_TS_MODE; |
| 851 | ret = af9015_rw_udev(udev, &req); |
| 852 | if (ret) |
| 853 | goto error; |
| 854 | af9015_config.dual_mode = val; |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 855 | deb_info("%s: TS mode=%d\n", __func__, af9015_config.dual_mode); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 856 | |
Antti Palosaari | f0830eb | 2009-01-13 13:08:29 -0300 | [diff] [blame] | 857 | /* Set adapter0 buffer size according to USB port speed, adapter1 buffer |
| 858 | size can be static because it is enabled only USB2.0 */ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 859 | for (i = 0; i < af9015_properties_count; i++) { |
| 860 | /* USB1.1 set smaller buffersize and disable 2nd adapter */ |
| 861 | if (udev->speed == USB_SPEED_FULL) { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 862 | af9015_properties[i].adapter[0].fe[0].stream.u.bulk.buffersize |
Antti Palosaari | 9c86327 | 2009-09-12 13:35:29 -0300 | [diff] [blame] | 863 | = TS_USB11_FRAME_SIZE; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 864 | /* disable 2nd adapter because we don't have |
| 865 | PID-filters */ |
| 866 | af9015_config.dual_mode = 0; |
| 867 | } else { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 868 | af9015_properties[i].adapter[0].fe[0].stream.u.bulk.buffersize |
Jose Alberto Reguero | 353330c | 2009-09-12 09:51:36 -0300 | [diff] [blame] | 869 | = TS_USB20_FRAME_SIZE; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | |
| 873 | if (af9015_config.dual_mode) { |
| 874 | /* read 2nd demodulator I2C address */ |
| 875 | req.addr = AF9015_EEPROM_DEMOD2_I2C; |
| 876 | ret = af9015_rw_udev(udev, &req); |
| 877 | if (ret) |
| 878 | goto error; |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 879 | af9015_af9013_config[1].i2c_addr = val; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 880 | |
| 881 | /* enable 2nd adapter */ |
| 882 | for (i = 0; i < af9015_properties_count; i++) |
| 883 | af9015_properties[i].num_adapters = 2; |
| 884 | |
| 885 | } else { |
| 886 | /* disable 2nd adapter */ |
| 887 | for (i = 0; i < af9015_properties_count; i++) |
| 888 | af9015_properties[i].num_adapters = 1; |
| 889 | } |
| 890 | |
| 891 | for (i = 0; i < af9015_properties[0].num_adapters; i++) { |
| 892 | if (i == 1) |
| 893 | offset = AF9015_EEPROM_OFFSET; |
| 894 | /* xtal */ |
| 895 | req.addr = AF9015_EEPROM_XTAL_TYPE1 + offset; |
| 896 | ret = af9015_rw_udev(udev, &req); |
| 897 | if (ret) |
| 898 | goto error; |
| 899 | switch (val) { |
| 900 | case 0: |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 901 | af9015_af9013_config[i].clock = 28800000; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 902 | break; |
| 903 | case 1: |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 904 | af9015_af9013_config[i].clock = 20480000; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 905 | break; |
| 906 | case 2: |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 907 | af9015_af9013_config[i].clock = 28000000; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 908 | break; |
| 909 | case 3: |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 910 | af9015_af9013_config[i].clock = 25000000; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 911 | break; |
| 912 | }; |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 913 | deb_info("%s: [%d] xtal=%d set clock=%d\n", __func__, i, |
| 914 | val, af9015_af9013_config[i].clock); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 915 | |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 916 | /* IF frequency */ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 917 | req.addr = AF9015_EEPROM_IF1H + offset; |
| 918 | ret = af9015_rw_udev(udev, &req); |
| 919 | if (ret) |
| 920 | goto error; |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 921 | |
| 922 | af9015_af9013_config[i].if_frequency = val << 8; |
| 923 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 924 | req.addr = AF9015_EEPROM_IF1L + offset; |
| 925 | ret = af9015_rw_udev(udev, &req); |
| 926 | if (ret) |
| 927 | goto error; |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 928 | |
| 929 | af9015_af9013_config[i].if_frequency += val; |
| 930 | af9015_af9013_config[i].if_frequency *= 1000; |
| 931 | deb_info("%s: [%d] IF frequency=%d\n", __func__, i, |
| 932 | af9015_af9013_config[0].if_frequency); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 933 | |
| 934 | /* MT2060 IF1 */ |
| 935 | req.addr = AF9015_EEPROM_MT2060_IF1H + offset; |
| 936 | ret = af9015_rw_udev(udev, &req); |
| 937 | if (ret) |
| 938 | goto error; |
| 939 | af9015_config.mt2060_if1[i] = val << 8; |
| 940 | req.addr = AF9015_EEPROM_MT2060_IF1L + offset; |
| 941 | ret = af9015_rw_udev(udev, &req); |
| 942 | if (ret) |
| 943 | goto error; |
| 944 | af9015_config.mt2060_if1[i] += val; |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 945 | deb_info("%s: [%d] MT2060 IF1=%d\n", __func__, i, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 946 | af9015_config.mt2060_if1[i]); |
| 947 | |
| 948 | /* tuner */ |
| 949 | req.addr = AF9015_EEPROM_TUNER_ID1 + offset; |
| 950 | ret = af9015_rw_udev(udev, &req); |
| 951 | if (ret) |
| 952 | goto error; |
| 953 | switch (val) { |
| 954 | case AF9013_TUNER_ENV77H11D5: |
| 955 | case AF9013_TUNER_MT2060: |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 956 | case AF9013_TUNER_QT1010: |
| 957 | case AF9013_TUNER_UNKNOWN: |
| 958 | case AF9013_TUNER_MT2060_2: |
| 959 | case AF9013_TUNER_TDA18271: |
| 960 | case AF9013_TUNER_QT1010A: |
Antti Palosaari | ee3d440 | 2010-08-13 03:51:26 -0300 | [diff] [blame] | 961 | case AF9013_TUNER_TDA18218: |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 962 | af9015_af9013_config[i].spec_inv = 1; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 963 | break; |
| 964 | case AF9013_TUNER_MXL5003D: |
| 965 | case AF9013_TUNER_MXL5005D: |
| 966 | case AF9013_TUNER_MXL5005R: |
Antti Palosaari | ab07fdd | 2010-09-09 14:59:10 -0300 | [diff] [blame] | 967 | case AF9013_TUNER_MXL5007T: |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 968 | af9015_af9013_config[i].spec_inv = 0; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 969 | break; |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 970 | case AF9013_TUNER_MC44S803: |
| 971 | af9015_af9013_config[i].gpio[1] = AF9013_GPIO_LO; |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 972 | af9015_af9013_config[i].spec_inv = 1; |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 973 | break; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 974 | default: |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 975 | warn("tuner id=%d not supported, please report!", val); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 976 | return -ENODEV; |
| 977 | }; |
| 978 | |
| 979 | af9015_af9013_config[i].tuner = val; |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 980 | deb_info("%s: [%d] tuner id=%d\n", __func__, i, val); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | error: |
| 984 | if (ret) |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 985 | err("eeprom read failed=%d", ret); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 986 | |
Antti Palosaari | 3956fef | 2009-03-31 17:01:02 -0300 | [diff] [blame] | 987 | /* AverMedia AVerTV Volar Black HD (A850) device have bad EEPROM |
Yann E. MORIN | 8ccdf1a | 2010-10-01 16:55:43 -0300 | [diff] [blame] | 988 | content :-( Override some wrong values here. Ditto for the |
| 989 | AVerTV Red HD+ (A850T) device. */ |
Antti Palosaari | 3956fef | 2009-03-31 17:01:02 -0300 | [diff] [blame] | 990 | if (le16_to_cpu(udev->descriptor.idVendor) == USB_VID_AVERMEDIA && |
Antti Palosaari | 9a3ecc7 | 2010-10-07 21:37:06 -0300 | [diff] [blame] | 991 | ((le16_to_cpu(udev->descriptor.idProduct) == |
| 992 | USB_PID_AVERMEDIA_A850) || |
| 993 | (le16_to_cpu(udev->descriptor.idProduct) == |
| 994 | USB_PID_AVERMEDIA_A850T))) { |
Antti Palosaari | 3956fef | 2009-03-31 17:01:02 -0300 | [diff] [blame] | 995 | deb_info("%s: AverMedia A850: overriding config\n", __func__); |
| 996 | /* disable dual mode */ |
| 997 | af9015_config.dual_mode = 0; |
| 998 | /* disable 2nd adapter */ |
| 999 | for (i = 0; i < af9015_properties_count; i++) |
| 1000 | af9015_properties[i].num_adapters = 1; |
| 1001 | |
| 1002 | /* set correct IF */ |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 1003 | af9015_af9013_config[0].if_frequency = 4570000; |
Antti Palosaari | 3956fef | 2009-03-31 17:01:02 -0300 | [diff] [blame] | 1004 | } |
| 1005 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1006 | return ret; |
| 1007 | } |
| 1008 | |
| 1009 | static int af9015_identify_state(struct usb_device *udev, |
| 1010 | struct dvb_usb_device_properties *props, |
| 1011 | struct dvb_usb_device_description **desc, |
| 1012 | int *cold) |
| 1013 | { |
| 1014 | int ret; |
| 1015 | u8 reply; |
| 1016 | struct req_t req = {GET_CONFIG, 0, 0, 0, 0, 1, &reply}; |
| 1017 | |
| 1018 | ret = af9015_rw_udev(udev, &req); |
| 1019 | if (ret) |
| 1020 | return ret; |
| 1021 | |
| 1022 | deb_info("%s: reply:%02x\n", __func__, reply); |
| 1023 | if (reply == 0x02) |
| 1024 | *cold = 0; |
| 1025 | else |
| 1026 | *cold = 1; |
| 1027 | |
| 1028 | return ret; |
| 1029 | } |
| 1030 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 1031 | static int af9015_rc_query(struct dvb_usb_device *d) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1032 | { |
Antti Palosaari | d3bb73d | 2010-09-12 13:31:56 -0300 | [diff] [blame] | 1033 | struct af9015_state *priv = d->priv; |
| 1034 | int ret; |
Ian Armstrong | c1e1397 | 2011-03-18 19:23:05 -0300 | [diff] [blame] | 1035 | u8 buf[17]; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1036 | |
Antti Palosaari | d3bb73d | 2010-09-12 13:31:56 -0300 | [diff] [blame] | 1037 | /* read registers needed to detect remote controller code */ |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 1038 | ret = af9015_read_regs(d, 0x98d9, buf, sizeof(buf)); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1039 | if (ret) |
Antti Palosaari | d3bb73d | 2010-09-12 13:31:56 -0300 | [diff] [blame] | 1040 | goto error; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1041 | |
Ian Armstrong | c1e1397 | 2011-03-18 19:23:05 -0300 | [diff] [blame] | 1042 | /* If any of these are non-zero, assume invalid data */ |
| 1043 | if (buf[1] || buf[2] || buf[3]) |
| 1044 | return ret; |
| 1045 | |
| 1046 | /* Check for repeat of previous code */ |
| 1047 | if ((priv->rc_repeat != buf[6] || buf[0]) && |
| 1048 | !memcmp(&buf[12], priv->rc_last, 4)) { |
| 1049 | deb_rc("%s: key repeated\n", __func__); |
| 1050 | rc_keydown(d->rc_dev, priv->rc_keycode, 0); |
| 1051 | priv->rc_repeat = buf[6]; |
| 1052 | return ret; |
| 1053 | } |
| 1054 | |
| 1055 | /* Only process key if canary killed */ |
| 1056 | if (buf[16] != 0xff && buf[0] != 0x01) { |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 1057 | deb_rc("%s: key pressed %02x %02x %02x %02x\n", __func__, |
| 1058 | buf[12], buf[13], buf[14], buf[15]); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1059 | |
Antti Palosaari | 1e8750c | 2011-03-18 19:36:42 -0300 | [diff] [blame] | 1060 | /* Reset the canary */ |
| 1061 | ret = af9015_write_reg(d, 0x98e9, 0xff); |
| 1062 | if (ret) |
| 1063 | goto error; |
| 1064 | |
Ian Armstrong | c1e1397 | 2011-03-18 19:23:05 -0300 | [diff] [blame] | 1065 | /* Remember this key */ |
| 1066 | memcpy(priv->rc_last, &buf[12], 4); |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 1067 | if (buf[14] == (u8) ~buf[15]) { |
| 1068 | if (buf[12] == (u8) ~buf[13]) { |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 1069 | /* NEC */ |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 1070 | priv->rc_keycode = buf[12] << 8 | buf[14]; |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 1071 | } else { |
| 1072 | /* NEC extended*/ |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 1073 | priv->rc_keycode = buf[12] << 16 | |
| 1074 | buf[13] << 8 | buf[14]; |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 1075 | } |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 1076 | } else { |
Antti Palosaari | 1e8750c | 2011-03-18 19:36:42 -0300 | [diff] [blame] | 1077 | /* 32 bit NEC */ |
Ian Armstrong | c1e1397 | 2011-03-18 19:23:05 -0300 | [diff] [blame] | 1078 | priv->rc_keycode = buf[12] << 24 | buf[13] << 16 | |
| 1079 | buf[14] << 8 | buf[15]; |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 1080 | } |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 1081 | rc_keydown(d->rc_dev, priv->rc_keycode, 0); |
Antti Palosaari | d3bb73d | 2010-09-12 13:31:56 -0300 | [diff] [blame] | 1082 | } else { |
| 1083 | deb_rc("%s: no key press\n", __func__); |
Ian Armstrong | c1e1397 | 2011-03-18 19:23:05 -0300 | [diff] [blame] | 1084 | /* Invalidate last keypress */ |
| 1085 | /* Not really needed, but helps with debug */ |
| 1086 | priv->rc_last[2] = priv->rc_last[3]; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1087 | } |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1088 | |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 1089 | priv->rc_repeat = buf[6]; |
Antti Palosaari | d3bb73d | 2010-09-12 13:31:56 -0300 | [diff] [blame] | 1090 | |
Antti Palosaari | d3bb73d | 2010-09-12 13:31:56 -0300 | [diff] [blame] | 1091 | error: |
| 1092 | if (ret) |
| 1093 | err("%s: failed:%d", __func__, ret); |
| 1094 | |
| 1095 | return ret; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1096 | } |
| 1097 | |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 1098 | /* override demod callbacks for resource locking */ |
Mauro Carvalho Chehab | 0009e0e | 2011-12-31 07:03:36 -0300 | [diff] [blame^] | 1099 | static int af9015_af9013_set_frontend(struct dvb_frontend *fe) |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 1100 | { |
| 1101 | int ret; |
| 1102 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
| 1103 | struct af9015_state *priv = adap->dev->priv; |
| 1104 | |
| 1105 | if (mutex_lock_interruptible(&adap->dev->usb_mutex)) |
| 1106 | return -EAGAIN; |
| 1107 | |
Mauro Carvalho Chehab | 0009e0e | 2011-12-31 07:03:36 -0300 | [diff] [blame^] | 1108 | ret = priv->set_frontend[adap->id](fe); |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 1109 | |
| 1110 | mutex_unlock(&adap->dev->usb_mutex); |
| 1111 | |
| 1112 | return ret; |
| 1113 | } |
| 1114 | |
| 1115 | /* override demod callbacks for resource locking */ |
| 1116 | static int af9015_af9013_read_status(struct dvb_frontend *fe, |
| 1117 | fe_status_t *status) |
| 1118 | { |
| 1119 | int ret; |
| 1120 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
| 1121 | struct af9015_state *priv = adap->dev->priv; |
| 1122 | |
| 1123 | if (mutex_lock_interruptible(&adap->dev->usb_mutex)) |
| 1124 | return -EAGAIN; |
| 1125 | |
| 1126 | ret = priv->read_status[adap->id](fe, status); |
| 1127 | |
| 1128 | mutex_unlock(&adap->dev->usb_mutex); |
| 1129 | |
| 1130 | return ret; |
| 1131 | } |
| 1132 | |
| 1133 | /* override demod callbacks for resource locking */ |
| 1134 | static int af9015_af9013_init(struct dvb_frontend *fe) |
| 1135 | { |
| 1136 | int ret; |
| 1137 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
| 1138 | struct af9015_state *priv = adap->dev->priv; |
| 1139 | |
| 1140 | if (mutex_lock_interruptible(&adap->dev->usb_mutex)) |
| 1141 | return -EAGAIN; |
| 1142 | |
| 1143 | ret = priv->init[adap->id](fe); |
| 1144 | |
| 1145 | mutex_unlock(&adap->dev->usb_mutex); |
| 1146 | |
| 1147 | return ret; |
| 1148 | } |
| 1149 | |
| 1150 | /* override demod callbacks for resource locking */ |
| 1151 | static int af9015_af9013_sleep(struct dvb_frontend *fe) |
| 1152 | { |
| 1153 | int ret; |
| 1154 | struct dvb_usb_adapter *adap = fe->dvb->priv; |
| 1155 | struct af9015_state *priv = adap->dev->priv; |
| 1156 | |
| 1157 | if (mutex_lock_interruptible(&adap->dev->usb_mutex)) |
| 1158 | return -EAGAIN; |
| 1159 | |
Antti Palosaari | f571e00 | 2011-11-28 20:58:11 -0300 | [diff] [blame] | 1160 | ret = priv->sleep[adap->id](fe); |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 1161 | |
| 1162 | mutex_unlock(&adap->dev->usb_mutex); |
| 1163 | |
| 1164 | return ret; |
| 1165 | } |
| 1166 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1167 | static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap) |
| 1168 | { |
| 1169 | int ret; |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 1170 | struct af9015_state *state = adap->dev->priv; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1171 | |
Antti Palosaari | 713d9b5 | 2011-06-18 10:24:53 -0300 | [diff] [blame] | 1172 | if (adap->id == 1) { |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1173 | /* copy firmware to 2nd demodulator */ |
| 1174 | if (af9015_config.dual_mode) { |
| 1175 | ret = af9015_copy_firmware(adap->dev); |
| 1176 | if (ret) { |
| 1177 | err("firmware copy to 2nd frontend " \ |
| 1178 | "failed, will disable it"); |
| 1179 | af9015_config.dual_mode = 0; |
| 1180 | return -ENODEV; |
| 1181 | } |
| 1182 | } else { |
| 1183 | return -ENODEV; |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | /* attach demodulator */ |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1188 | adap->fe_adap[0].fe = dvb_attach(af9013_attach, &af9015_af9013_config[adap->id], |
Antti Palosaari | 713d9b5 | 2011-06-18 10:24:53 -0300 | [diff] [blame] | 1189 | &adap->dev->i2c_adap); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1190 | |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 1191 | /* |
| 1192 | * AF9015 firmware does not like if it gets interrupted by I2C adapter |
| 1193 | * request on some critical phases. During normal operation I2C adapter |
| 1194 | * is used only 2nd demodulator and tuner on dual tuner devices. |
| 1195 | * Override demodulator callbacks and use mutex for limit access to |
| 1196 | * those "critical" paths to keep AF9015 happy. |
| 1197 | * Note: we abuse unused usb_mutex here. |
| 1198 | */ |
| 1199 | if (adap->fe_adap[0].fe) { |
| 1200 | state->set_frontend[adap->id] = |
| 1201 | adap->fe_adap[0].fe->ops.set_frontend; |
| 1202 | adap->fe_adap[0].fe->ops.set_frontend = |
| 1203 | af9015_af9013_set_frontend; |
| 1204 | |
| 1205 | state->read_status[adap->id] = |
| 1206 | adap->fe_adap[0].fe->ops.read_status; |
| 1207 | adap->fe_adap[0].fe->ops.read_status = |
| 1208 | af9015_af9013_read_status; |
| 1209 | |
| 1210 | state->init[adap->id] = adap->fe_adap[0].fe->ops.init; |
| 1211 | adap->fe_adap[0].fe->ops.init = af9015_af9013_init; |
| 1212 | |
| 1213 | state->sleep[adap->id] = adap->fe_adap[0].fe->ops.sleep; |
| 1214 | adap->fe_adap[0].fe->ops.sleep = af9015_af9013_sleep; |
| 1215 | } |
| 1216 | |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1217 | return adap->fe_adap[0].fe == NULL ? -ENODEV : 0; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | static struct mt2060_config af9015_mt2060_config = { |
| 1221 | .i2c_address = 0xc0, |
| 1222 | .clock_out = 0, |
| 1223 | }; |
| 1224 | |
| 1225 | static struct qt1010_config af9015_qt1010_config = { |
| 1226 | .i2c_address = 0xc4, |
| 1227 | }; |
| 1228 | |
| 1229 | static struct tda18271_config af9015_tda18271_config = { |
| 1230 | .gate = TDA18271_GATE_DIGITAL, |
Mauro Carvalho Chehab | 7655e59 | 2010-10-27 14:55:34 -0200 | [diff] [blame] | 1231 | .small_i2c = TDA18271_16_BYTE_CHUNK_INIT, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1232 | }; |
| 1233 | |
| 1234 | static struct mxl5005s_config af9015_mxl5003_config = { |
| 1235 | .i2c_address = 0xc6, |
| 1236 | .if_freq = IF_FREQ_4570000HZ, |
| 1237 | .xtal_freq = CRYSTAL_FREQ_16000000HZ, |
| 1238 | .agc_mode = MXL_SINGLE_AGC, |
| 1239 | .tracking_filter = MXL_TF_DEFAULT, |
Antti Palosaari | a131077 | 2008-09-22 13:59:25 -0300 | [diff] [blame] | 1240 | .rssi_enable = MXL_RSSI_ENABLE, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1241 | .cap_select = MXL_CAP_SEL_ENABLE, |
| 1242 | .div_out = MXL_DIV_OUT_4, |
| 1243 | .clock_out = MXL_CLOCK_OUT_DISABLE, |
| 1244 | .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM, |
| 1245 | .top = MXL5005S_TOP_25P2, |
| 1246 | .mod_mode = MXL_DIGITAL_MODE, |
| 1247 | .if_mode = MXL_ZERO_IF, |
| 1248 | .AgcMasterByte = 0x00, |
| 1249 | }; |
| 1250 | |
| 1251 | static struct mxl5005s_config af9015_mxl5005_config = { |
| 1252 | .i2c_address = 0xc6, |
| 1253 | .if_freq = IF_FREQ_4570000HZ, |
| 1254 | .xtal_freq = CRYSTAL_FREQ_16000000HZ, |
| 1255 | .agc_mode = MXL_SINGLE_AGC, |
| 1256 | .tracking_filter = MXL_TF_OFF, |
Antti Palosaari | a131077 | 2008-09-22 13:59:25 -0300 | [diff] [blame] | 1257 | .rssi_enable = MXL_RSSI_ENABLE, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1258 | .cap_select = MXL_CAP_SEL_ENABLE, |
| 1259 | .div_out = MXL_DIV_OUT_4, |
| 1260 | .clock_out = MXL_CLOCK_OUT_DISABLE, |
| 1261 | .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM, |
| 1262 | .top = MXL5005S_TOP_25P2, |
| 1263 | .mod_mode = MXL_DIGITAL_MODE, |
| 1264 | .if_mode = MXL_ZERO_IF, |
| 1265 | .AgcMasterByte = 0x00, |
| 1266 | }; |
| 1267 | |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 1268 | static struct mc44s803_config af9015_mc44s803_config = { |
| 1269 | .i2c_address = 0xc0, |
| 1270 | .dig_out = 1, |
| 1271 | }; |
| 1272 | |
Antti Palosaari | ee3d440 | 2010-08-13 03:51:26 -0300 | [diff] [blame] | 1273 | static struct tda18218_config af9015_tda18218_config = { |
| 1274 | .i2c_address = 0xc0, |
| 1275 | .i2c_wr_max = 21, /* max wr bytes AF9015 I2C adap can handle at once */ |
| 1276 | }; |
| 1277 | |
Antti Palosaari | ab07fdd | 2010-09-09 14:59:10 -0300 | [diff] [blame] | 1278 | static struct mxl5007t_config af9015_mxl5007t_config = { |
| 1279 | .xtal_freq_hz = MxL_XTAL_24_MHZ, |
| 1280 | .if_freq_hz = MxL_IF_4_57_MHZ, |
| 1281 | }; |
| 1282 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1283 | static int af9015_tuner_attach(struct dvb_usb_adapter *adap) |
| 1284 | { |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1285 | int ret; |
Antti Palosaari | 9a3ecc7 | 2010-10-07 21:37:06 -0300 | [diff] [blame] | 1286 | deb_info("%s:\n", __func__); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1287 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1288 | switch (af9015_af9013_config[adap->id].tuner) { |
| 1289 | case AF9013_TUNER_MT2060: |
| 1290 | case AF9013_TUNER_MT2060_2: |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1291 | ret = dvb_attach(mt2060_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1292 | &af9015_mt2060_config, |
| 1293 | af9015_config.mt2060_if1[adap->id]) |
| 1294 | == NULL ? -ENODEV : 0; |
| 1295 | break; |
| 1296 | case AF9013_TUNER_QT1010: |
| 1297 | case AF9013_TUNER_QT1010A: |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1298 | ret = dvb_attach(qt1010_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1299 | &af9015_qt1010_config) == NULL ? -ENODEV : 0; |
| 1300 | break; |
| 1301 | case AF9013_TUNER_TDA18271: |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1302 | ret = dvb_attach(tda18271_attach, adap->fe_adap[0].fe, 0xc0, |
Antti Palosaari | 713d9b5 | 2011-06-18 10:24:53 -0300 | [diff] [blame] | 1303 | &adap->dev->i2c_adap, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1304 | &af9015_tda18271_config) == NULL ? -ENODEV : 0; |
| 1305 | break; |
Antti Palosaari | ee3d440 | 2010-08-13 03:51:26 -0300 | [diff] [blame] | 1306 | case AF9013_TUNER_TDA18218: |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1307 | ret = dvb_attach(tda18218_attach, adap->fe_adap[0].fe, |
Antti Palosaari | 713d9b5 | 2011-06-18 10:24:53 -0300 | [diff] [blame] | 1308 | &adap->dev->i2c_adap, |
Antti Palosaari | ee3d440 | 2010-08-13 03:51:26 -0300 | [diff] [blame] | 1309 | &af9015_tda18218_config) == NULL ? -ENODEV : 0; |
| 1310 | break; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1311 | case AF9013_TUNER_MXL5003D: |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1312 | ret = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe, |
Antti Palosaari | 713d9b5 | 2011-06-18 10:24:53 -0300 | [diff] [blame] | 1313 | &adap->dev->i2c_adap, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1314 | &af9015_mxl5003_config) == NULL ? -ENODEV : 0; |
| 1315 | break; |
| 1316 | case AF9013_TUNER_MXL5005D: |
| 1317 | case AF9013_TUNER_MXL5005R: |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1318 | ret = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe, |
Antti Palosaari | 713d9b5 | 2011-06-18 10:24:53 -0300 | [diff] [blame] | 1319 | &adap->dev->i2c_adap, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1320 | &af9015_mxl5005_config) == NULL ? -ENODEV : 0; |
| 1321 | break; |
| 1322 | case AF9013_TUNER_ENV77H11D5: |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1323 | ret = dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0xc0, |
Antti Palosaari | 713d9b5 | 2011-06-18 10:24:53 -0300 | [diff] [blame] | 1324 | &adap->dev->i2c_adap, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1325 | DVB_PLL_TDA665X) == NULL ? -ENODEV : 0; |
| 1326 | break; |
| 1327 | case AF9013_TUNER_MC44S803: |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1328 | ret = dvb_attach(mc44s803_attach, adap->fe_adap[0].fe, |
Antti Palosaari | 713d9b5 | 2011-06-18 10:24:53 -0300 | [diff] [blame] | 1329 | &adap->dev->i2c_adap, |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 1330 | &af9015_mc44s803_config) == NULL ? -ENODEV : 0; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1331 | break; |
Antti Palosaari | ab07fdd | 2010-09-09 14:59:10 -0300 | [diff] [blame] | 1332 | case AF9013_TUNER_MXL5007T: |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1333 | ret = dvb_attach(mxl5007t_attach, adap->fe_adap[0].fe, |
Antti Palosaari | 713d9b5 | 2011-06-18 10:24:53 -0300 | [diff] [blame] | 1334 | &adap->dev->i2c_adap, |
Antti Palosaari | ab07fdd | 2010-09-09 14:59:10 -0300 | [diff] [blame] | 1335 | 0xc0, &af9015_mxl5007t_config) == NULL ? -ENODEV : 0; |
| 1336 | break; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1337 | case AF9013_TUNER_UNKNOWN: |
| 1338 | default: |
| 1339 | ret = -ENODEV; |
| 1340 | err("Unknown tuner id:%d", |
| 1341 | af9015_af9013_config[adap->id].tuner); |
| 1342 | } |
| 1343 | return ret; |
| 1344 | } |
| 1345 | |
| 1346 | static struct usb_device_id af9015_usb_table[] = { |
| 1347 | /* 0 */{USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9015)}, |
| 1348 | {USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9016)}, |
| 1349 | {USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_GOLD)}, |
| 1350 | {USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV71E)}, |
| 1351 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U)}, |
| 1352 | /* 5 */{USB_DEVICE(USB_VID_VISIONPLUS, |
| 1353 | USB_PID_TINYTWIN)}, |
| 1354 | {USB_DEVICE(USB_VID_VISIONPLUS, |
| 1355 | USB_PID_AZUREWAVE_AD_TU700)}, |
| 1356 | {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2)}, |
| 1357 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_2T)}, |
| 1358 | {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X)}, |
| 1359 | /* 10 */{USB_DEVICE(USB_VID_XTENSIONS, USB_PID_XTENSIONS_XD_380)}, |
| 1360 | {USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGIVOX_DUO)}, |
| 1361 | {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X_2)}, |
Antti Palosaari | a376588 | 2008-09-19 18:34:06 -0300 | [diff] [blame] | 1362 | {USB_DEVICE(USB_VID_TELESTAR, USB_PID_TELESTAR_STARSTICK_2)}, |
Antti Palosaari | 05c1cab | 2008-09-22 12:32:37 -0300 | [diff] [blame] | 1363 | {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A309)}, |
Herbert Graeber | 641015a | 2008-10-07 10:06:36 -0300 | [diff] [blame] | 1364 | /* 15 */{USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGI_VOX_MINI_III)}, |
Antti Palosaari | 163e9cd | 2008-11-04 12:57:47 -0300 | [diff] [blame] | 1365 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U)}, |
Antti Palosaari | 71bf2e0 | 2009-01-13 12:47:28 -0300 | [diff] [blame] | 1366 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_2)}, |
Antti Palosaari | 58fe159 | 2009-03-26 20:41:05 -0300 | [diff] [blame] | 1367 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_3)}, |
Marc Schneider | 2614484 | 2009-03-26 21:07:18 -0300 | [diff] [blame] | 1368 | {USB_DEVICE(USB_VID_AFATECH, USB_PID_TREKSTOR_DVBT)}, |
Antti Palosaari | 1ed5fad | 2009-04-09 15:14:18 -0300 | [diff] [blame] | 1369 | /* 20 */{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850)}, |
| 1370 | {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A805)}, |
Marcel Jueling | 734dd23 | 2009-04-09 17:16:41 -0300 | [diff] [blame] | 1371 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CONCEPTRONIC_CTVDIGRCU)}, |
Wen-chien Jesse Sung | 6e9c1a2 | 2009-04-28 01:11:22 -0300 | [diff] [blame] | 1372 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_MC810)}, |
Antti Palosaari | 22d4645 | 2009-05-31 17:07:01 -0300 | [diff] [blame] | 1373 | {USB_DEVICE(USB_VID_KYE, USB_PID_GENIUS_TVGO_DVB_T03)}, |
Mart Raudsepp | c92f056 | 2009-07-24 13:45:41 -0300 | [diff] [blame] | 1374 | /* 25 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U_2)}, |
Antti Palosaari | 486ba12 | 2009-09-18 13:37:57 -0300 | [diff] [blame] | 1375 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_T)}, |
Ignacio de Miguel Diaz | 5232263 | 2009-11-13 23:13:34 -0300 | [diff] [blame] | 1376 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20)}, |
Antti Palosaari | fa1df55 | 2010-02-10 20:05:48 -0300 | [diff] [blame] | 1377 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TINYTWIN_2)}, |
Antti Palosaari | 809c1e8 | 2010-02-10 20:07:30 -0300 | [diff] [blame] | 1378 | {USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS)}, |
Antti Palosaari | ab9b4f2 | 2010-03-01 13:50:40 -0300 | [diff] [blame] | 1379 | /* 30 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB383_T)}, |
Antti Palosaari | 7fc8709 | 2010-03-01 14:06:52 -0300 | [diff] [blame] | 1380 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_4)}, |
Antti Palosaari | 2606cfa | 2010-05-23 18:26:37 -0300 | [diff] [blame] | 1381 | {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A815M)}, |
Stefan Lippers-Hollmann | d7ef485 | 2010-08-25 10:08:48 -0300 | [diff] [blame] | 1382 | {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_RC)}, |
Antti Palosaari | ab07fdd | 2010-09-09 14:59:10 -0300 | [diff] [blame] | 1383 | {USB_DEVICE(USB_VID_TERRATEC, |
| 1384 | USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC)}, |
Yann E. MORIN | 8ccdf1a | 2010-10-01 16:55:43 -0300 | [diff] [blame] | 1385 | /* 35 */{USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850T)}, |
Antti Palosaari | f8c6127 | 2010-10-23 07:35:31 -0300 | [diff] [blame] | 1386 | {USB_DEVICE(USB_VID_GTEK, USB_PID_TINYTWIN_3)}, |
Emilio David Diaus Lopez | a062d04 | 2011-07-12 19:53:39 -0300 | [diff] [blame] | 1387 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV22)}, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1388 | {0}, |
| 1389 | }; |
| 1390 | MODULE_DEVICE_TABLE(usb, af9015_usb_table); |
| 1391 | |
Antti Palosaari | d3bb73d | 2010-09-12 13:31:56 -0300 | [diff] [blame] | 1392 | #define AF9015_RC_INTERVAL 500 |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1393 | static struct dvb_usb_device_properties af9015_properties[] = { |
| 1394 | { |
| 1395 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 1396 | |
| 1397 | .usb_ctrl = DEVICE_SPECIFIC, |
| 1398 | .download_firmware = af9015_download_firmware, |
| 1399 | .firmware = "dvb-usb-af9015.fw", |
Jose Alberto Reguero | cce2571 | 2008-11-13 14:14:18 -0300 | [diff] [blame] | 1400 | .no_reconnect = 1, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1401 | |
Antti Palosaari | 0254294 | 2009-09-16 20:33:03 -0300 | [diff] [blame] | 1402 | .size_of_priv = sizeof(struct af9015_state), |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1403 | |
| 1404 | .num_adapters = 2, |
| 1405 | .adapter = { |
| 1406 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1407 | .num_frontends = 1, |
| 1408 | .fe = {{ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1409 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | |
| 1410 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, |
| 1411 | |
| 1412 | .pid_filter_count = 32, |
| 1413 | .pid_filter = af9015_pid_filter, |
| 1414 | .pid_filter_ctrl = af9015_pid_filter_ctrl, |
| 1415 | |
| 1416 | .frontend_attach = |
| 1417 | af9015_af9013_frontend_attach, |
| 1418 | .tuner_attach = af9015_tuner_attach, |
| 1419 | .stream = { |
| 1420 | .type = USB_BULK, |
| 1421 | .count = 6, |
| 1422 | .endpoint = 0x84, |
| 1423 | }, |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1424 | }}, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1425 | }, |
| 1426 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1427 | .num_frontends = 1, |
| 1428 | .fe = {{ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1429 | .frontend_attach = |
| 1430 | af9015_af9013_frontend_attach, |
| 1431 | .tuner_attach = af9015_tuner_attach, |
| 1432 | .stream = { |
| 1433 | .type = USB_BULK, |
| 1434 | .count = 6, |
| 1435 | .endpoint = 0x85, |
Antti Palosaari | f0830eb | 2009-01-13 13:08:29 -0300 | [diff] [blame] | 1436 | .u = { |
| 1437 | .bulk = { |
| 1438 | .buffersize = |
Jose Alberto Reguero | 353330c | 2009-09-12 09:51:36 -0300 | [diff] [blame] | 1439 | TS_USB20_FRAME_SIZE, |
Antti Palosaari | f0830eb | 2009-01-13 13:08:29 -0300 | [diff] [blame] | 1440 | } |
| 1441 | } |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1442 | }, |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1443 | }}, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1444 | } |
| 1445 | }, |
| 1446 | |
| 1447 | .identify_state = af9015_identify_state, |
| 1448 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 1449 | .rc.core = { |
Mauro Carvalho Chehab | 52b6614 | 2010-11-17 14:20:52 -0300 | [diff] [blame] | 1450 | .protocol = RC_TYPE_NEC, |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 1451 | .module_name = "af9015", |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 1452 | .rc_query = af9015_rc_query, |
Antti Palosaari | d3bb73d | 2010-09-12 13:31:56 -0300 | [diff] [blame] | 1453 | .rc_interval = AF9015_RC_INTERVAL, |
Mauro Carvalho Chehab | 52b6614 | 2010-11-17 14:20:52 -0300 | [diff] [blame] | 1454 | .allowed_protos = RC_TYPE_NEC, |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 1455 | }, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1456 | |
| 1457 | .i2c_algo = &af9015_i2c_algo, |
| 1458 | |
Yann E. MORIN | 8ccdf1a | 2010-10-01 16:55:43 -0300 | [diff] [blame] | 1459 | .num_device_descs = 12, /* check max from dvb-usb.h */ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1460 | .devices = { |
| 1461 | { |
| 1462 | .name = "Afatech AF9015 DVB-T USB2.0 stick", |
| 1463 | .cold_ids = {&af9015_usb_table[0], |
| 1464 | &af9015_usb_table[1], NULL}, |
| 1465 | .warm_ids = {NULL}, |
| 1466 | }, |
| 1467 | { |
| 1468 | .name = "Leadtek WinFast DTV Dongle Gold", |
| 1469 | .cold_ids = {&af9015_usb_table[2], NULL}, |
| 1470 | .warm_ids = {NULL}, |
| 1471 | }, |
| 1472 | { |
| 1473 | .name = "Pinnacle PCTV 71e", |
| 1474 | .cold_ids = {&af9015_usb_table[3], NULL}, |
| 1475 | .warm_ids = {NULL}, |
| 1476 | }, |
| 1477 | { |
| 1478 | .name = "KWorld PlusTV Dual DVB-T Stick " \ |
| 1479 | "(DVB-T 399U)", |
Mart Raudsepp | c92f056 | 2009-07-24 13:45:41 -0300 | [diff] [blame] | 1480 | .cold_ids = {&af9015_usb_table[4], |
| 1481 | &af9015_usb_table[25], NULL}, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1482 | .warm_ids = {NULL}, |
| 1483 | }, |
| 1484 | { |
| 1485 | .name = "DigitalNow TinyTwin DVB-T Receiver", |
Antti Palosaari | fa1df55 | 2010-02-10 20:05:48 -0300 | [diff] [blame] | 1486 | .cold_ids = {&af9015_usb_table[5], |
Antti Palosaari | f8c6127 | 2010-10-23 07:35:31 -0300 | [diff] [blame] | 1487 | &af9015_usb_table[28], |
| 1488 | &af9015_usb_table[36], NULL}, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1489 | .warm_ids = {NULL}, |
| 1490 | }, |
| 1491 | { |
| 1492 | .name = "TwinHan AzureWave AD-TU700(704J)", |
| 1493 | .cold_ids = {&af9015_usb_table[6], NULL}, |
| 1494 | .warm_ids = {NULL}, |
| 1495 | }, |
| 1496 | { |
| 1497 | .name = "TerraTec Cinergy T USB XE", |
| 1498 | .cold_ids = {&af9015_usb_table[7], NULL}, |
| 1499 | .warm_ids = {NULL}, |
| 1500 | }, |
| 1501 | { |
| 1502 | .name = "KWorld PlusTV Dual DVB-T PCI " \ |
| 1503 | "(DVB-T PC160-2T)", |
| 1504 | .cold_ids = {&af9015_usb_table[8], NULL}, |
| 1505 | .warm_ids = {NULL}, |
| 1506 | }, |
| 1507 | { |
| 1508 | .name = "AVerMedia AVerTV DVB-T Volar X", |
| 1509 | .cold_ids = {&af9015_usb_table[9], NULL}, |
| 1510 | .warm_ids = {NULL}, |
| 1511 | }, |
Antti Palosaari | 76391a7 | 2010-09-09 12:10:50 -0300 | [diff] [blame] | 1512 | { |
| 1513 | .name = "TerraTec Cinergy T Stick RC", |
| 1514 | .cold_ids = {&af9015_usb_table[33], NULL}, |
| 1515 | .warm_ids = {NULL}, |
| 1516 | }, |
Antti Palosaari | ab07fdd | 2010-09-09 14:59:10 -0300 | [diff] [blame] | 1517 | { |
| 1518 | .name = "TerraTec Cinergy T Stick Dual RC", |
| 1519 | .cold_ids = {&af9015_usb_table[34], NULL}, |
| 1520 | .warm_ids = {NULL}, |
| 1521 | }, |
Yann E. MORIN | 8ccdf1a | 2010-10-01 16:55:43 -0300 | [diff] [blame] | 1522 | { |
| 1523 | .name = "AverMedia AVerTV Red HD+ (A850T)", |
| 1524 | .cold_ids = {&af9015_usb_table[35], NULL}, |
| 1525 | .warm_ids = {NULL}, |
| 1526 | }, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1527 | } |
| 1528 | }, { |
| 1529 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 1530 | |
| 1531 | .usb_ctrl = DEVICE_SPECIFIC, |
| 1532 | .download_firmware = af9015_download_firmware, |
| 1533 | .firmware = "dvb-usb-af9015.fw", |
Jose Alberto Reguero | cce2571 | 2008-11-13 14:14:18 -0300 | [diff] [blame] | 1534 | .no_reconnect = 1, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1535 | |
Antti Palosaari | 0254294 | 2009-09-16 20:33:03 -0300 | [diff] [blame] | 1536 | .size_of_priv = sizeof(struct af9015_state), |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1537 | |
| 1538 | .num_adapters = 2, |
| 1539 | .adapter = { |
| 1540 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1541 | .num_frontends = 1, |
| 1542 | .fe = {{ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1543 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | |
| 1544 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, |
| 1545 | |
| 1546 | .pid_filter_count = 32, |
| 1547 | .pid_filter = af9015_pid_filter, |
| 1548 | .pid_filter_ctrl = af9015_pid_filter_ctrl, |
| 1549 | |
| 1550 | .frontend_attach = |
| 1551 | af9015_af9013_frontend_attach, |
| 1552 | .tuner_attach = af9015_tuner_attach, |
| 1553 | .stream = { |
| 1554 | .type = USB_BULK, |
| 1555 | .count = 6, |
| 1556 | .endpoint = 0x84, |
| 1557 | }, |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1558 | }}, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1559 | }, |
| 1560 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1561 | .num_frontends = 1, |
| 1562 | .fe = {{ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1563 | .frontend_attach = |
| 1564 | af9015_af9013_frontend_attach, |
| 1565 | .tuner_attach = af9015_tuner_attach, |
| 1566 | .stream = { |
| 1567 | .type = USB_BULK, |
| 1568 | .count = 6, |
| 1569 | .endpoint = 0x85, |
Antti Palosaari | f0830eb | 2009-01-13 13:08:29 -0300 | [diff] [blame] | 1570 | .u = { |
| 1571 | .bulk = { |
| 1572 | .buffersize = |
Jose Alberto Reguero | 353330c | 2009-09-12 09:51:36 -0300 | [diff] [blame] | 1573 | TS_USB20_FRAME_SIZE, |
Antti Palosaari | f0830eb | 2009-01-13 13:08:29 -0300 | [diff] [blame] | 1574 | } |
| 1575 | } |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1576 | }, |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1577 | }}, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1578 | } |
| 1579 | }, |
| 1580 | |
| 1581 | .identify_state = af9015_identify_state, |
| 1582 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 1583 | .rc.core = { |
Mauro Carvalho Chehab | 52b6614 | 2010-11-17 14:20:52 -0300 | [diff] [blame] | 1584 | .protocol = RC_TYPE_NEC, |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 1585 | .module_name = "af9015", |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 1586 | .rc_query = af9015_rc_query, |
Antti Palosaari | d3bb73d | 2010-09-12 13:31:56 -0300 | [diff] [blame] | 1587 | .rc_interval = AF9015_RC_INTERVAL, |
Mauro Carvalho Chehab | 52b6614 | 2010-11-17 14:20:52 -0300 | [diff] [blame] | 1588 | .allowed_protos = RC_TYPE_NEC, |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 1589 | }, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1590 | |
| 1591 | .i2c_algo = &af9015_i2c_algo, |
| 1592 | |
Emilio David Diaus Lopez | a062d04 | 2011-07-12 19:53:39 -0300 | [diff] [blame] | 1593 | .num_device_descs = 10, /* check max from dvb-usb.h */ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1594 | .devices = { |
| 1595 | { |
| 1596 | .name = "Xtensions XD-380", |
| 1597 | .cold_ids = {&af9015_usb_table[10], NULL}, |
| 1598 | .warm_ids = {NULL}, |
| 1599 | }, |
| 1600 | { |
| 1601 | .name = "MSI DIGIVOX Duo", |
| 1602 | .cold_ids = {&af9015_usb_table[11], NULL}, |
| 1603 | .warm_ids = {NULL}, |
| 1604 | }, |
| 1605 | { |
| 1606 | .name = "Fujitsu-Siemens Slim Mobile USB DVB-T", |
| 1607 | .cold_ids = {&af9015_usb_table[12], NULL}, |
| 1608 | .warm_ids = {NULL}, |
| 1609 | }, |
Mikko Ohtamaa | 111f9ec | 2008-09-19 18:26:05 -0300 | [diff] [blame] | 1610 | { |
Antti Palosaari | a376588 | 2008-09-19 18:34:06 -0300 | [diff] [blame] | 1611 | .name = "Telestar Starstick 2", |
Mikko Ohtamaa | 111f9ec | 2008-09-19 18:26:05 -0300 | [diff] [blame] | 1612 | .cold_ids = {&af9015_usb_table[13], NULL}, |
| 1613 | .warm_ids = {NULL}, |
| 1614 | }, |
Antti Palosaari | 05c1cab | 2008-09-22 12:32:37 -0300 | [diff] [blame] | 1615 | { |
| 1616 | .name = "AVerMedia A309", |
| 1617 | .cold_ids = {&af9015_usb_table[14], NULL}, |
| 1618 | .warm_ids = {NULL}, |
| 1619 | }, |
Herbert Graeber | 641015a | 2008-10-07 10:06:36 -0300 | [diff] [blame] | 1620 | { |
| 1621 | .name = "MSI Digi VOX mini III", |
| 1622 | .cold_ids = {&af9015_usb_table[15], NULL}, |
| 1623 | .warm_ids = {NULL}, |
| 1624 | }, |
Antti Palosaari | 163e9cd | 2008-11-04 12:57:47 -0300 | [diff] [blame] | 1625 | { |
| 1626 | .name = "KWorld USB DVB-T TV Stick II " \ |
| 1627 | "(VS-DVB-T 395U)", |
Antti Palosaari | 71bf2e0 | 2009-01-13 12:47:28 -0300 | [diff] [blame] | 1628 | .cold_ids = {&af9015_usb_table[16], |
Antti Palosaari | 58fe159 | 2009-03-26 20:41:05 -0300 | [diff] [blame] | 1629 | &af9015_usb_table[17], |
Antti Palosaari | 7fc8709 | 2010-03-01 14:06:52 -0300 | [diff] [blame] | 1630 | &af9015_usb_table[18], |
| 1631 | &af9015_usb_table[31], NULL}, |
Antti Palosaari | 163e9cd | 2008-11-04 12:57:47 -0300 | [diff] [blame] | 1632 | .warm_ids = {NULL}, |
| 1633 | }, |
Marc Schneider | 2614484 | 2009-03-26 21:07:18 -0300 | [diff] [blame] | 1634 | { |
| 1635 | .name = "TrekStor DVB-T USB Stick", |
| 1636 | .cold_ids = {&af9015_usb_table[19], NULL}, |
| 1637 | .warm_ids = {NULL}, |
| 1638 | }, |
Antti Palosaari | 3956fef | 2009-03-31 17:01:02 -0300 | [diff] [blame] | 1639 | { |
| 1640 | .name = "AverMedia AVerTV Volar Black HD " \ |
| 1641 | "(A850)", |
| 1642 | .cold_ids = {&af9015_usb_table[20], NULL}, |
| 1643 | .warm_ids = {NULL}, |
| 1644 | }, |
Emilio David Diaus Lopez | a062d04 | 2011-07-12 19:53:39 -0300 | [diff] [blame] | 1645 | { |
| 1646 | .name = "Sveon STV22 Dual USB DVB-T Tuner HDTV", |
| 1647 | .cold_ids = {&af9015_usb_table[37], NULL}, |
| 1648 | .warm_ids = {NULL}, |
| 1649 | }, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1650 | } |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1651 | }, { |
| 1652 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 1653 | |
| 1654 | .usb_ctrl = DEVICE_SPECIFIC, |
| 1655 | .download_firmware = af9015_download_firmware, |
| 1656 | .firmware = "dvb-usb-af9015.fw", |
| 1657 | .no_reconnect = 1, |
| 1658 | |
Antti Palosaari | 0254294 | 2009-09-16 20:33:03 -0300 | [diff] [blame] | 1659 | .size_of_priv = sizeof(struct af9015_state), |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1660 | |
| 1661 | .num_adapters = 2, |
| 1662 | .adapter = { |
| 1663 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1664 | .num_frontends = 1, |
| 1665 | .fe = {{ |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1666 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | |
| 1667 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, |
| 1668 | |
| 1669 | .pid_filter_count = 32, |
| 1670 | .pid_filter = af9015_pid_filter, |
| 1671 | .pid_filter_ctrl = af9015_pid_filter_ctrl, |
| 1672 | |
| 1673 | .frontend_attach = |
| 1674 | af9015_af9013_frontend_attach, |
| 1675 | .tuner_attach = af9015_tuner_attach, |
| 1676 | .stream = { |
| 1677 | .type = USB_BULK, |
| 1678 | .count = 6, |
| 1679 | .endpoint = 0x84, |
| 1680 | }, |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1681 | }}, |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1682 | }, |
| 1683 | { |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1684 | .num_frontends = 1, |
| 1685 | .fe = {{ |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1686 | .frontend_attach = |
| 1687 | af9015_af9013_frontend_attach, |
| 1688 | .tuner_attach = af9015_tuner_attach, |
| 1689 | .stream = { |
| 1690 | .type = USB_BULK, |
| 1691 | .count = 6, |
| 1692 | .endpoint = 0x85, |
| 1693 | .u = { |
| 1694 | .bulk = { |
| 1695 | .buffersize = |
Jose Alberto Reguero | 353330c | 2009-09-12 09:51:36 -0300 | [diff] [blame] | 1696 | TS_USB20_FRAME_SIZE, |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1697 | } |
| 1698 | } |
| 1699 | }, |
Michael Krufky | 77eed21 | 2011-09-06 09:31:57 -0300 | [diff] [blame] | 1700 | }}, |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1701 | } |
| 1702 | }, |
| 1703 | |
| 1704 | .identify_state = af9015_identify_state, |
| 1705 | |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 1706 | .rc.core = { |
Mauro Carvalho Chehab | 52b6614 | 2010-11-17 14:20:52 -0300 | [diff] [blame] | 1707 | .protocol = RC_TYPE_NEC, |
Antti Palosaari | 1cd7278 | 2010-10-12 17:22:32 -0300 | [diff] [blame] | 1708 | .module_name = "af9015", |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 1709 | .rc_query = af9015_rc_query, |
Antti Palosaari | d3bb73d | 2010-09-12 13:31:56 -0300 | [diff] [blame] | 1710 | .rc_interval = AF9015_RC_INTERVAL, |
Mauro Carvalho Chehab | 52b6614 | 2010-11-17 14:20:52 -0300 | [diff] [blame] | 1711 | .allowed_protos = RC_TYPE_NEC, |
Mauro Carvalho Chehab | f72a27b | 2010-07-31 18:04:09 -0300 | [diff] [blame] | 1712 | }, |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1713 | |
| 1714 | .i2c_algo = &af9015_i2c_algo, |
| 1715 | |
Antti Palosaari | a44b91d | 2010-09-09 12:05:31 -0300 | [diff] [blame] | 1716 | .num_device_descs = 9, /* check max from dvb-usb.h */ |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1717 | .devices = { |
Antti Palosaari | 1ed5fad | 2009-04-09 15:14:18 -0300 | [diff] [blame] | 1718 | { |
| 1719 | .name = "AverMedia AVerTV Volar GPS 805 (A805)", |
| 1720 | .cold_ids = {&af9015_usb_table[21], NULL}, |
| 1721 | .warm_ids = {NULL}, |
| 1722 | }, |
Marcel Jueling | 734dd23 | 2009-04-09 17:16:41 -0300 | [diff] [blame] | 1723 | { |
| 1724 | .name = "Conceptronic USB2.0 DVB-T CTVDIGRCU " \ |
| 1725 | "V3.0", |
| 1726 | .cold_ids = {&af9015_usb_table[22], NULL}, |
| 1727 | .warm_ids = {NULL}, |
| 1728 | }, |
Wen-chien Jesse Sung | 6e9c1a2 | 2009-04-28 01:11:22 -0300 | [diff] [blame] | 1729 | { |
| 1730 | .name = "KWorld Digial MC-810", |
| 1731 | .cold_ids = {&af9015_usb_table[23], NULL}, |
| 1732 | .warm_ids = {NULL}, |
| 1733 | }, |
Antti Palosaari | 22d4645 | 2009-05-31 17:07:01 -0300 | [diff] [blame] | 1734 | { |
| 1735 | .name = "Genius TVGo DVB-T03", |
| 1736 | .cold_ids = {&af9015_usb_table[24], NULL}, |
| 1737 | .warm_ids = {NULL}, |
| 1738 | }, |
Antti Palosaari | 486ba12 | 2009-09-18 13:37:57 -0300 | [diff] [blame] | 1739 | { |
| 1740 | .name = "KWorld PlusTV DVB-T PCI Pro Card " \ |
| 1741 | "(DVB-T PC160-T)", |
| 1742 | .cold_ids = {&af9015_usb_table[26], NULL}, |
| 1743 | .warm_ids = {NULL}, |
| 1744 | }, |
Ignacio de Miguel Diaz | 5232263 | 2009-11-13 23:13:34 -0300 | [diff] [blame] | 1745 | { |
| 1746 | .name = "Sveon STV20 Tuner USB DVB-T HDTV", |
| 1747 | .cold_ids = {&af9015_usb_table[27], NULL}, |
| 1748 | .warm_ids = {NULL}, |
| 1749 | }, |
Antti Palosaari | 809c1e8 | 2010-02-10 20:07:30 -0300 | [diff] [blame] | 1750 | { |
| 1751 | .name = "Leadtek WinFast DTV2000DS", |
| 1752 | .cold_ids = {&af9015_usb_table[29], NULL}, |
| 1753 | .warm_ids = {NULL}, |
| 1754 | }, |
Antti Palosaari | ab9b4f2 | 2010-03-01 13:50:40 -0300 | [diff] [blame] | 1755 | { |
| 1756 | .name = "KWorld USB DVB-T Stick Mobile " \ |
| 1757 | "(UB383-T)", |
| 1758 | .cold_ids = {&af9015_usb_table[30], NULL}, |
| 1759 | .warm_ids = {NULL}, |
| 1760 | }, |
Antti Palosaari | 2606cfa | 2010-05-23 18:26:37 -0300 | [diff] [blame] | 1761 | { |
| 1762 | .name = "AverMedia AVerTV Volar M (A815Mac)", |
| 1763 | .cold_ids = {&af9015_usb_table[32], NULL}, |
| 1764 | .warm_ids = {NULL}, |
| 1765 | }, |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1766 | } |
| 1767 | }, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1768 | }; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1769 | |
| 1770 | static int af9015_usb_probe(struct usb_interface *intf, |
| 1771 | const struct usb_device_id *id) |
| 1772 | { |
| 1773 | int ret = 0; |
| 1774 | struct dvb_usb_device *d = NULL; |
| 1775 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1776 | u8 i; |
| 1777 | |
| 1778 | deb_info("%s: interface:%d\n", __func__, |
| 1779 | intf->cur_altsetting->desc.bInterfaceNumber); |
| 1780 | |
| 1781 | /* interface 0 is used by DVB-T receiver and |
| 1782 | interface 1 is for remote controller (HID) */ |
| 1783 | if (intf->cur_altsetting->desc.bInterfaceNumber == 0) { |
| 1784 | ret = af9015_read_config(udev); |
| 1785 | if (ret) |
| 1786 | return ret; |
| 1787 | |
| 1788 | for (i = 0; i < af9015_properties_count; i++) { |
| 1789 | ret = dvb_usb_device_init(intf, &af9015_properties[i], |
| 1790 | THIS_MODULE, &d, adapter_nr); |
| 1791 | if (!ret) |
| 1792 | break; |
| 1793 | if (ret != -ENODEV) |
| 1794 | return ret; |
| 1795 | } |
| 1796 | if (ret) |
| 1797 | return ret; |
| 1798 | |
| 1799 | if (d) |
| 1800 | ret = af9015_init(d); |
| 1801 | } |
| 1802 | |
| 1803 | return ret; |
| 1804 | } |
| 1805 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1806 | /* usb specific object needed to register this driver with the usb subsystem */ |
| 1807 | static struct usb_driver af9015_usb_driver = { |
| 1808 | .name = "dvb_usb_af9015", |
| 1809 | .probe = af9015_usb_probe, |
Antti Palosaari | 713d9b5 | 2011-06-18 10:24:53 -0300 | [diff] [blame] | 1810 | .disconnect = dvb_usb_device_exit, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1811 | .id_table = af9015_usb_table, |
| 1812 | }; |
| 1813 | |
| 1814 | /* module stuff */ |
| 1815 | static int __init af9015_usb_module_init(void) |
| 1816 | { |
| 1817 | int ret; |
| 1818 | ret = usb_register(&af9015_usb_driver); |
| 1819 | if (ret) |
| 1820 | err("module init failed:%d", ret); |
| 1821 | |
| 1822 | return ret; |
| 1823 | } |
| 1824 | |
| 1825 | static void __exit af9015_usb_module_exit(void) |
| 1826 | { |
| 1827 | /* deregister this driver from the USB subsystem */ |
| 1828 | usb_deregister(&af9015_usb_driver); |
| 1829 | } |
| 1830 | |
| 1831 | module_init(af9015_usb_module_init); |
| 1832 | module_exit(af9015_usb_module_exit); |
| 1833 | |
| 1834 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 1835 | MODULE_DESCRIPTION("Driver for Afatech AF9015 DVB-T"); |
| 1836 | MODULE_LICENSE("GPL"); |