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