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 | |
| 24 | #include "af9015.h" |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 25 | |
Antti Palosaari | 349d042 | 2008-11-05 16:31:24 -0300 | [diff] [blame] | 26 | static int dvb_usb_af9015_debug; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 27 | module_param_named(debug, dvb_usb_af9015_debug, int, 0644); |
| 28 | MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS); |
Antti Palosaari | 349d042 | 2008-11-05 16:31:24 -0300 | [diff] [blame] | 29 | static int dvb_usb_af9015_remote; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 30 | module_param_named(remote, dvb_usb_af9015_remote, int, 0644); |
| 31 | MODULE_PARM_DESC(remote, "select remote"); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 32 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 33 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 34 | static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 35 | { |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 36 | #define BUF_LEN 63 |
| 37 | #define REQ_HDR_LEN 8 /* send header size */ |
| 38 | #define ACK_HDR_LEN 2 /* rece header size */ |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 39 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 40 | int ret, wlen, rlen; |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 41 | u8 buf[BUF_LEN]; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 42 | u8 write = 1; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 43 | |
| 44 | buf[0] = req->cmd; |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 45 | buf[1] = state->seq++; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 46 | buf[2] = req->i2c_addr; |
| 47 | buf[3] = req->addr >> 8; |
| 48 | buf[4] = req->addr & 0xff; |
| 49 | buf[5] = req->mbox; |
| 50 | buf[6] = req->addr_len; |
| 51 | buf[7] = req->data_len; |
| 52 | |
| 53 | switch (req->cmd) { |
| 54 | case GET_CONFIG: |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 55 | case READ_MEMORY: |
| 56 | case RECONNECT_USB: |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 57 | write = 0; |
| 58 | break; |
| 59 | case READ_I2C: |
| 60 | write = 0; |
| 61 | buf[2] |= 0x01; /* set I2C direction */ |
| 62 | case WRITE_I2C: |
| 63 | buf[0] = READ_WRITE_I2C; |
| 64 | break; |
| 65 | case WRITE_MEMORY: |
| 66 | if (((req->addr & 0xff00) == 0xff00) || |
Antti Palosaari | f4e96de | 2009-09-12 21:25:59 -0300 | [diff] [blame] | 67 | ((req->addr & 0xff00) == 0xae00)) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 68 | buf[0] = WRITE_VIRTUAL_MEMORY; |
| 69 | case WRITE_VIRTUAL_MEMORY: |
| 70 | case COPY_FIRMWARE: |
| 71 | case DOWNLOAD_FIRMWARE: |
Nils Kassube | ba1bc64 | 2009-07-28 11:54:52 -0300 | [diff] [blame] | 72 | case BOOT: |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 73 | break; |
| 74 | default: |
| 75 | err("unknown command:%d", req->cmd); |
| 76 | ret = -1; |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 77 | goto error; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 78 | } |
| 79 | |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 80 | /* buffer overflow check */ |
| 81 | if ((write && (req->data_len > BUF_LEN - REQ_HDR_LEN)) || |
| 82 | (!write && (req->data_len > BUF_LEN - ACK_HDR_LEN))) { |
| 83 | err("too much data; cmd:%d len:%d", req->cmd, req->data_len); |
| 84 | ret = -EINVAL; |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 85 | goto error; |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 86 | } |
| 87 | |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 88 | /* write receives seq + status = 2 bytes |
| 89 | read receives seq + status + data = 2 + N bytes */ |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 90 | wlen = REQ_HDR_LEN; |
| 91 | rlen = ACK_HDR_LEN; |
| 92 | if (write) { |
| 93 | wlen += req->data_len; |
| 94 | memcpy(&buf[REQ_HDR_LEN], req->data, req->data_len); |
| 95 | } else { |
| 96 | rlen += req->data_len; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 97 | } |
| 98 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 99 | /* no ack for these packets */ |
| 100 | if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB) |
| 101 | rlen = 0; |
| 102 | |
Antti Palosaari | 1162c7b | 2012-06-20 20:27:42 -0300 | [diff] [blame] | 103 | ret = dvb_usbv2_generic_rw(d, buf, wlen, buf, rlen); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 104 | if (ret) |
| 105 | goto error; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 106 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 107 | /* check status */ |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 108 | if (rlen && buf[1]) { |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 109 | err("command failed:%d", buf[1]); |
| 110 | ret = -1; |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 111 | goto error; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /* read request, copy returned data to return buf */ |
| 115 | if (!write) |
Antti Palosaari | 06565d7 | 2009-09-12 20:46:30 -0300 | [diff] [blame] | 116 | memcpy(req->data, &buf[ACK_HDR_LEN], req->data_len); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 117 | error: |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 118 | return ret; |
| 119 | } |
| 120 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 121 | static int af9015_write_regs(struct dvb_usb_device *d, u16 addr, u8 *val, |
| 122 | u8 len) |
| 123 | { |
| 124 | struct req_t req = {WRITE_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len, |
| 125 | val}; |
| 126 | return af9015_ctrl_msg(d, &req); |
| 127 | } |
| 128 | |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 129 | static int af9015_read_regs(struct dvb_usb_device *d, u16 addr, u8 *val, u8 len) |
| 130 | { |
| 131 | struct req_t req = {READ_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len, |
| 132 | val}; |
| 133 | return af9015_ctrl_msg(d, &req); |
| 134 | } |
| 135 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 136 | static int af9015_write_reg(struct dvb_usb_device *d, u16 addr, u8 val) |
| 137 | { |
| 138 | return af9015_write_regs(d, addr, &val, 1); |
| 139 | } |
| 140 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 141 | static int af9015_read_reg(struct dvb_usb_device *d, u16 addr, u8 *val) |
| 142 | { |
Antti Palosaari | 74c8e3a | 2010-10-22 18:45:18 -0300 | [diff] [blame] | 143 | return af9015_read_regs(d, addr, val, 1); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg, |
| 147 | u8 val) |
| 148 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 149 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 150 | struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val}; |
| 151 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 152 | if (addr == state->af9013_config[0].i2c_addr || |
| 153 | addr == state->af9013_config[1].i2c_addr) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 154 | req.addr_len = 3; |
| 155 | |
| 156 | return af9015_ctrl_msg(d, &req); |
| 157 | } |
| 158 | |
| 159 | static int af9015_read_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg, |
| 160 | u8 *val) |
| 161 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 162 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 163 | struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val}; |
| 164 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 165 | if (addr == state->af9013_config[0].i2c_addr || |
| 166 | addr == state->af9013_config[1].i2c_addr) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 167 | req.addr_len = 3; |
| 168 | |
| 169 | return af9015_ctrl_msg(d, &req); |
| 170 | } |
| 171 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 172 | static int af9015_do_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit, u8 op) |
| 173 | { |
| 174 | int ret; |
| 175 | u8 val, mask = 0x01; |
| 176 | |
| 177 | ret = af9015_read_reg(d, addr, &val); |
| 178 | if (ret) |
| 179 | return ret; |
| 180 | |
| 181 | mask <<= bit; |
| 182 | if (op) { |
| 183 | /* set bit */ |
| 184 | val |= mask; |
| 185 | } else { |
| 186 | /* clear bit */ |
| 187 | mask ^= 0xff; |
| 188 | val &= mask; |
| 189 | } |
| 190 | |
| 191 | return af9015_write_reg(d, addr, val); |
| 192 | } |
| 193 | |
| 194 | static int af9015_set_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit) |
| 195 | { |
| 196 | return af9015_do_reg_bit(d, addr, bit, 1); |
| 197 | } |
| 198 | |
| 199 | static int af9015_clear_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit) |
| 200 | { |
| 201 | return af9015_do_reg_bit(d, addr, bit, 0); |
| 202 | } |
| 203 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 204 | static int af9015_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
| 205 | int num) |
| 206 | { |
| 207 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 208 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 209 | int ret = 0, i = 0; |
| 210 | u16 addr; |
Antti Palosaari | 675375d | 2010-10-07 21:46:41 -0300 | [diff] [blame] | 211 | u8 uninitialized_var(mbox), addr_len; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 212 | struct req_t req; |
| 213 | |
Antti Palosaari | bc050e6 | 2012-05-08 06:04:24 -0300 | [diff] [blame] | 214 | /* |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 215 | The bus lock is needed because there is two tuners both using same I2C-address. |
| 216 | Due to that the only way to select correct tuner is use demodulator I2C-gate. |
| 217 | |
| 218 | ................................................ |
| 219 | . AF9015 includes integrated AF9013 demodulator. |
| 220 | . ____________ ____________ . ____________ |
| 221 | .| uC | | demod | . | tuner | |
| 222 | .|------------| |------------| . |------------| |
| 223 | .| AF9015 | | AF9013/5 | . | MXL5003 | |
| 224 | .| |--+----I2C-------|-----/ -----|-.-----I2C-------| | |
| 225 | .| | | | addr 0x38 | . | addr 0xc6 | |
| 226 | .|____________| | |____________| . |____________| |
| 227 | .................|.............................. |
| 228 | | ____________ ____________ |
| 229 | | | demod | | tuner | |
| 230 | | |------------| |------------| |
| 231 | | | AF9013 | | MXL5003 | |
| 232 | +----I2C-------|-----/ -----|-------I2C-------| | |
| 233 | | addr 0x3a | | addr 0xc6 | |
| 234 | |____________| |____________| |
| 235 | */ |
| 236 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 237 | return -EAGAIN; |
| 238 | |
| 239 | while (i < num) { |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 240 | if (msg[i].addr == state->af9013_config[0].i2c_addr || |
| 241 | msg[i].addr == state->af9013_config[1].i2c_addr) { |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 242 | addr = msg[i].buf[0] << 8; |
| 243 | addr += msg[i].buf[1]; |
| 244 | mbox = msg[i].buf[2]; |
| 245 | addr_len = 3; |
| 246 | } else { |
| 247 | addr = msg[i].buf[0]; |
| 248 | addr_len = 1; |
Antti Palosaari | 675375d | 2010-10-07 21:46:41 -0300 | [diff] [blame] | 249 | /* mbox is don't care in that case */ |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) { |
Antti Palosaari | 709d920 | 2011-06-17 21:16:38 -0300 | [diff] [blame] | 253 | if (msg[i].len > 3 || msg[i+1].len > 61) { |
| 254 | ret = -EOPNOTSUPP; |
| 255 | goto error; |
| 256 | } |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 257 | if (msg[i].addr == state->af9013_config[0].i2c_addr) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 258 | req.cmd = READ_MEMORY; |
| 259 | else |
| 260 | req.cmd = READ_I2C; |
| 261 | req.i2c_addr = msg[i].addr; |
| 262 | req.addr = addr; |
| 263 | req.mbox = mbox; |
| 264 | req.addr_len = addr_len; |
| 265 | req.data_len = msg[i+1].len; |
| 266 | req.data = &msg[i+1].buf[0]; |
| 267 | ret = af9015_ctrl_msg(d, &req); |
| 268 | i += 2; |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 269 | } else if (msg[i].flags & I2C_M_RD) { |
Antti Palosaari | 709d920 | 2011-06-17 21:16:38 -0300 | [diff] [blame] | 270 | if (msg[i].len > 61) { |
| 271 | ret = -EOPNOTSUPP; |
| 272 | goto error; |
| 273 | } |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 274 | if (msg[i].addr == state->af9013_config[0].i2c_addr) { |
Antti Palosaari | 16b2dc2 | 2011-06-16 20:02:41 -0300 | [diff] [blame] | 275 | ret = -EINVAL; |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 276 | goto error; |
Antti Palosaari | 16b2dc2 | 2011-06-16 20:02:41 -0300 | [diff] [blame] | 277 | } |
| 278 | req.cmd = READ_I2C; |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 279 | req.i2c_addr = msg[i].addr; |
| 280 | req.addr = addr; |
| 281 | req.mbox = mbox; |
| 282 | req.addr_len = addr_len; |
| 283 | req.data_len = msg[i].len; |
| 284 | req.data = &msg[i].buf[0]; |
| 285 | ret = af9015_ctrl_msg(d, &req); |
| 286 | i += 1; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 287 | } else { |
Antti Palosaari | 709d920 | 2011-06-17 21:16:38 -0300 | [diff] [blame] | 288 | if (msg[i].len > 21) { |
| 289 | ret = -EOPNOTSUPP; |
| 290 | goto error; |
| 291 | } |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 292 | if (msg[i].addr == state->af9013_config[0].i2c_addr) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 293 | req.cmd = WRITE_MEMORY; |
| 294 | else |
| 295 | req.cmd = WRITE_I2C; |
| 296 | req.i2c_addr = msg[i].addr; |
| 297 | req.addr = addr; |
| 298 | req.mbox = mbox; |
| 299 | req.addr_len = addr_len; |
| 300 | req.data_len = msg[i].len-addr_len; |
| 301 | req.data = &msg[i].buf[addr_len]; |
| 302 | ret = af9015_ctrl_msg(d, &req); |
| 303 | i += 1; |
| 304 | } |
| 305 | if (ret) |
| 306 | goto error; |
| 307 | |
| 308 | } |
| 309 | ret = i; |
| 310 | |
| 311 | error: |
| 312 | mutex_unlock(&d->i2c_mutex); |
| 313 | |
| 314 | return ret; |
| 315 | } |
| 316 | |
| 317 | static u32 af9015_i2c_func(struct i2c_adapter *adapter) |
| 318 | { |
| 319 | return I2C_FUNC_I2C; |
| 320 | } |
| 321 | |
| 322 | static struct i2c_algorithm af9015_i2c_algo = { |
| 323 | .master_xfer = af9015_i2c_xfer, |
| 324 | .functionality = af9015_i2c_func, |
| 325 | }; |
| 326 | |
Antti Palosaari | a0921af | 2012-06-18 23:42:53 -0300 | [diff] [blame] | 327 | static int af9015_identify_state(struct dvb_usb_device *d, const char **name) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 328 | { |
| 329 | int ret; |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 330 | u8 reply; |
| 331 | struct req_t req = {GET_CONFIG, 0, 0, 0, 0, 1, &reply}; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 332 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 333 | ret = af9015_ctrl_msg(d, &req); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 334 | if (ret) |
| 335 | return ret; |
| 336 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 337 | deb_info("%s: reply:%02x\n", __func__, reply); |
| 338 | if (reply == 0x02) |
| 339 | ret = WARM; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 340 | else |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 341 | ret = COLD; |
| 342 | |
| 343 | return ret; |
| 344 | } |
| 345 | |
| 346 | static int af9015_download_firmware(struct dvb_usb_device *d, |
| 347 | const struct firmware *fw) |
| 348 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 349 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 350 | int i, len, remaining, ret; |
| 351 | struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL}; |
| 352 | u16 checksum = 0; |
| 353 | |
| 354 | deb_info("%s:\n", __func__); |
| 355 | |
| 356 | /* calc checksum */ |
| 357 | for (i = 0; i < fw->size; i++) |
| 358 | checksum += fw->data[i]; |
| 359 | |
| 360 | state->firmware_size = fw->size; |
| 361 | state->firmware_checksum = checksum; |
| 362 | |
| 363 | #define FW_ADDR 0x5100 /* firmware start address */ |
| 364 | #define LEN_MAX 55 /* max packet size */ |
| 365 | for (remaining = fw->size; remaining > 0; remaining -= LEN_MAX) { |
| 366 | len = remaining; |
| 367 | if (len > LEN_MAX) |
| 368 | len = LEN_MAX; |
| 369 | |
| 370 | req.data_len = len; |
| 371 | req.data = (u8 *) &fw->data[fw->size - remaining]; |
| 372 | req.addr = FW_ADDR + fw->size - remaining; |
| 373 | |
| 374 | ret = af9015_ctrl_msg(d, &req); |
| 375 | if (ret) { |
| 376 | err("firmware download failed:%d", ret); |
| 377 | goto error; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | /* firmware loaded, request boot */ |
| 382 | req.cmd = BOOT; |
| 383 | req.data_len = 0; |
| 384 | ret = af9015_ctrl_msg(d, &req); |
| 385 | if (ret) { |
| 386 | err("firmware boot failed:%d", ret); |
| 387 | goto error; |
| 388 | } |
| 389 | |
| 390 | error: |
| 391 | return ret; |
| 392 | } |
| 393 | |
| 394 | /* hash (and dump) eeprom */ |
| 395 | static int af9015_eeprom_hash(struct dvb_usb_device *d) |
| 396 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 397 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 398 | int ret; |
| 399 | static const unsigned int eeprom_size = 256; |
| 400 | unsigned int reg; |
| 401 | u8 val, *eeprom; |
| 402 | struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val}; |
| 403 | |
| 404 | eeprom = kmalloc(eeprom_size, GFP_KERNEL); |
| 405 | if (eeprom == NULL) |
| 406 | return -ENOMEM; |
| 407 | |
| 408 | for (reg = 0; reg < eeprom_size; reg++) { |
| 409 | req.addr = reg; |
| 410 | ret = af9015_ctrl_msg(d, &req); |
| 411 | if (ret) |
| 412 | goto free; |
| 413 | |
| 414 | eeprom[reg] = val; |
| 415 | } |
| 416 | |
| 417 | if (dvb_usb_af9015_debug & 0x01) |
| 418 | print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, eeprom, |
| 419 | eeprom_size); |
| 420 | |
| 421 | BUG_ON(eeprom_size % 4); |
| 422 | |
| 423 | state->eeprom_sum = 0; |
| 424 | for (reg = 0; reg < eeprom_size / sizeof(u32); reg++) { |
| 425 | state->eeprom_sum *= GOLDEN_RATIO_PRIME_32; |
| 426 | state->eeprom_sum += le32_to_cpu(((u32 *)eeprom)[reg]); |
| 427 | } |
| 428 | |
| 429 | deb_info("%s: eeprom sum=%.8x\n", __func__, state->eeprom_sum); |
| 430 | |
| 431 | ret = 0; |
| 432 | free: |
| 433 | kfree(eeprom); |
| 434 | return ret; |
| 435 | } |
| 436 | |
| 437 | static int af9015_read_config(struct dvb_usb_device *d) |
| 438 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 439 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 440 | int ret; |
| 441 | u8 val, i, offset = 0; |
| 442 | struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val}; |
| 443 | |
| 444 | deb_info("%s:\n", __func__); |
| 445 | |
| 446 | /* IR remote controller */ |
| 447 | req.addr = AF9015_EEPROM_IR_MODE; |
| 448 | /* first message will timeout often due to possible hw bug */ |
| 449 | for (i = 0; i < 4; i++) { |
| 450 | ret = af9015_ctrl_msg(d, &req); |
| 451 | if (!ret) |
| 452 | break; |
| 453 | } |
| 454 | if (ret) |
| 455 | goto error; |
| 456 | |
| 457 | ret = af9015_eeprom_hash(d); |
| 458 | if (ret) |
| 459 | goto error; |
| 460 | |
| 461 | deb_info("%s: IR mode=%d\n", __func__, val); |
| 462 | state->ir_mode = val; |
| 463 | |
| 464 | /* TS mode - one or two receivers */ |
| 465 | req.addr = AF9015_EEPROM_TS_MODE; |
| 466 | ret = af9015_ctrl_msg(d, &req); |
| 467 | if (ret) |
| 468 | goto error; |
| 469 | |
| 470 | state->dual_mode = val; |
| 471 | deb_info("%s: TS mode=%d\n", __func__, state->dual_mode); |
| 472 | |
| 473 | /* disable 2nd adapter because we don't have PID-filters */ |
| 474 | if (d->udev->speed == USB_SPEED_FULL) |
| 475 | state->dual_mode = 0; |
| 476 | |
| 477 | if (state->dual_mode) { |
| 478 | /* read 2nd demodulator I2C address */ |
| 479 | req.addr = AF9015_EEPROM_DEMOD2_I2C; |
| 480 | ret = af9015_ctrl_msg(d, &req); |
| 481 | if (ret) |
| 482 | goto error; |
| 483 | |
| 484 | state->af9013_config[1].i2c_addr = val; |
| 485 | } |
| 486 | |
| 487 | for (i = 0; i < state->dual_mode + 1; i++) { |
| 488 | if (i == 1) |
| 489 | offset = AF9015_EEPROM_OFFSET; |
| 490 | /* xtal */ |
| 491 | req.addr = AF9015_EEPROM_XTAL_TYPE1 + offset; |
| 492 | ret = af9015_ctrl_msg(d, &req); |
| 493 | if (ret) |
| 494 | goto error; |
| 495 | switch (val) { |
| 496 | case 0: |
| 497 | state->af9013_config[i].clock = 28800000; |
| 498 | break; |
| 499 | case 1: |
| 500 | state->af9013_config[i].clock = 20480000; |
| 501 | break; |
| 502 | case 2: |
| 503 | state->af9013_config[i].clock = 28000000; |
| 504 | break; |
| 505 | case 3: |
| 506 | state->af9013_config[i].clock = 25000000; |
| 507 | break; |
| 508 | }; |
| 509 | deb_info("%s: [%d] xtal=%d set clock=%d\n", __func__, i, |
| 510 | val, state->af9013_config[i].clock); |
| 511 | |
| 512 | /* IF frequency */ |
| 513 | req.addr = AF9015_EEPROM_IF1H + offset; |
| 514 | ret = af9015_ctrl_msg(d, &req); |
| 515 | if (ret) |
| 516 | goto error; |
| 517 | |
| 518 | state->af9013_config[i].if_frequency = val << 8; |
| 519 | |
| 520 | req.addr = AF9015_EEPROM_IF1L + offset; |
| 521 | ret = af9015_ctrl_msg(d, &req); |
| 522 | if (ret) |
| 523 | goto error; |
| 524 | |
| 525 | state->af9013_config[i].if_frequency += val; |
| 526 | state->af9013_config[i].if_frequency *= 1000; |
| 527 | deb_info("%s: [%d] IF frequency=%d\n", __func__, i, |
| 528 | state->af9013_config[i].if_frequency); |
| 529 | |
| 530 | /* MT2060 IF1 */ |
| 531 | req.addr = AF9015_EEPROM_MT2060_IF1H + offset; |
| 532 | ret = af9015_ctrl_msg(d, &req); |
| 533 | if (ret) |
| 534 | goto error; |
| 535 | state->mt2060_if1[i] = val << 8; |
| 536 | req.addr = AF9015_EEPROM_MT2060_IF1L + offset; |
| 537 | ret = af9015_ctrl_msg(d, &req); |
| 538 | if (ret) |
| 539 | goto error; |
| 540 | state->mt2060_if1[i] += val; |
| 541 | deb_info("%s: [%d] MT2060 IF1=%d\n", __func__, i, |
| 542 | state->mt2060_if1[i]); |
| 543 | |
| 544 | /* tuner */ |
| 545 | req.addr = AF9015_EEPROM_TUNER_ID1 + offset; |
| 546 | ret = af9015_ctrl_msg(d, &req); |
| 547 | if (ret) |
| 548 | goto error; |
| 549 | switch (val) { |
| 550 | case AF9013_TUNER_ENV77H11D5: |
| 551 | case AF9013_TUNER_MT2060: |
| 552 | case AF9013_TUNER_QT1010: |
| 553 | case AF9013_TUNER_UNKNOWN: |
| 554 | case AF9013_TUNER_MT2060_2: |
| 555 | case AF9013_TUNER_TDA18271: |
| 556 | case AF9013_TUNER_QT1010A: |
| 557 | case AF9013_TUNER_TDA18218: |
| 558 | state->af9013_config[i].spec_inv = 1; |
| 559 | break; |
| 560 | case AF9013_TUNER_MXL5003D: |
| 561 | case AF9013_TUNER_MXL5005D: |
| 562 | case AF9013_TUNER_MXL5005R: |
| 563 | case AF9013_TUNER_MXL5007T: |
| 564 | state->af9013_config[i].spec_inv = 0; |
| 565 | break; |
| 566 | case AF9013_TUNER_MC44S803: |
| 567 | state->af9013_config[i].gpio[1] = AF9013_GPIO_LO; |
| 568 | state->af9013_config[i].spec_inv = 1; |
| 569 | break; |
| 570 | default: |
| 571 | warn("tuner id=%d not supported, please report!", val); |
| 572 | return -ENODEV; |
| 573 | }; |
| 574 | |
| 575 | state->af9013_config[i].tuner = val; |
| 576 | deb_info("%s: [%d] tuner id=%d\n", __func__, i, val); |
| 577 | } |
Antti Palosaari | 1e8750c | 2011-03-18 19:36:42 -0300 | [diff] [blame] | 578 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 579 | error: |
| 580 | if (ret) |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 581 | err("eeprom read failed=%d", ret); |
| 582 | |
| 583 | /* AverMedia AVerTV Volar Black HD (A850) device have bad EEPROM |
| 584 | content :-( Override some wrong values here. Ditto for the |
| 585 | AVerTV Red HD+ (A850T) device. */ |
| 586 | if (le16_to_cpu(d->udev->descriptor.idVendor) == USB_VID_AVERMEDIA && |
| 587 | ((le16_to_cpu(d->udev->descriptor.idProduct) == |
| 588 | USB_PID_AVERMEDIA_A850) || |
| 589 | (le16_to_cpu(d->udev->descriptor.idProduct) == |
| 590 | USB_PID_AVERMEDIA_A850T))) { |
| 591 | deb_info("%s: AverMedia A850: overriding config\n", __func__); |
| 592 | /* disable dual mode */ |
| 593 | state->dual_mode = 0; |
| 594 | |
| 595 | /* set correct IF */ |
| 596 | state->af9013_config[0].if_frequency = 4570000; |
| 597 | } |
| 598 | |
| 599 | return ret; |
| 600 | } |
| 601 | |
Antti Palosaari | b905a2a | 2012-06-18 22:54:16 -0300 | [diff] [blame] | 602 | static int af9015_get_stream_config(struct dvb_frontend *fe, u8 *ts_type, |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 603 | struct usb_data_stream_properties *stream) |
| 604 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 605 | deb_info("%s: adap=%d\n", __func__, fe_to_adap(fe)->id); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 606 | |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 607 | if (fe_to_d(fe)->udev->speed == USB_SPEED_FULL) |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 608 | stream->u.bulk.buffersize = TS_USB11_FRAME_SIZE; |
| 609 | |
| 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | static int af9015_get_adapter_count(struct dvb_usb_device *d) |
| 614 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 615 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 616 | return state->dual_mode + 1; |
| 617 | } |
| 618 | |
| 619 | /* override demod callbacks for resource locking */ |
| 620 | static int af9015_af9013_set_frontend(struct dvb_frontend *fe) |
| 621 | { |
| 622 | int ret; |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 623 | struct af9015_state *state = fe_to_priv(fe); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 624 | |
| 625 | if (mutex_lock_interruptible(&state->fe_mutex)) |
| 626 | return -EAGAIN; |
| 627 | |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 628 | ret = state->set_frontend[fe_to_adap(fe)->id](fe); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 629 | |
| 630 | mutex_unlock(&state->fe_mutex); |
| 631 | |
| 632 | return ret; |
| 633 | } |
| 634 | |
| 635 | /* override demod callbacks for resource locking */ |
| 636 | static int af9015_af9013_read_status(struct dvb_frontend *fe, |
| 637 | fe_status_t *status) |
| 638 | { |
| 639 | int ret; |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 640 | struct af9015_state *state = fe_to_priv(fe); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 641 | |
| 642 | if (mutex_lock_interruptible(&state->fe_mutex)) |
| 643 | return -EAGAIN; |
| 644 | |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 645 | ret = state->read_status[fe_to_adap(fe)->id](fe, status); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 646 | |
| 647 | mutex_unlock(&state->fe_mutex); |
| 648 | |
| 649 | return ret; |
| 650 | } |
| 651 | |
| 652 | /* override demod callbacks for resource locking */ |
| 653 | static int af9015_af9013_init(struct dvb_frontend *fe) |
| 654 | { |
| 655 | int ret; |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 656 | struct af9015_state *state = fe_to_priv(fe); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 657 | |
| 658 | if (mutex_lock_interruptible(&state->fe_mutex)) |
| 659 | return -EAGAIN; |
| 660 | |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 661 | ret = state->init[fe_to_adap(fe)->id](fe); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 662 | |
| 663 | mutex_unlock(&state->fe_mutex); |
| 664 | |
| 665 | return ret; |
| 666 | } |
| 667 | |
| 668 | /* override demod callbacks for resource locking */ |
| 669 | static int af9015_af9013_sleep(struct dvb_frontend *fe) |
| 670 | { |
| 671 | int ret; |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 672 | struct af9015_state *state = fe_to_priv(fe); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 673 | |
| 674 | if (mutex_lock_interruptible(&state->fe_mutex)) |
| 675 | return -EAGAIN; |
| 676 | |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 677 | ret = state->sleep[fe_to_adap(fe)->id](fe); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 678 | |
| 679 | mutex_unlock(&state->fe_mutex); |
| 680 | |
| 681 | return ret; |
| 682 | } |
| 683 | |
| 684 | /* override tuner callbacks for resource locking */ |
| 685 | static int af9015_tuner_init(struct dvb_frontend *fe) |
| 686 | { |
| 687 | int ret; |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 688 | struct af9015_state *state = fe_to_priv(fe); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 689 | |
| 690 | if (mutex_lock_interruptible(&state->fe_mutex)) |
| 691 | return -EAGAIN; |
| 692 | |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 693 | ret = state->tuner_init[fe_to_adap(fe)->id](fe); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 694 | |
| 695 | mutex_unlock(&state->fe_mutex); |
| 696 | |
| 697 | return ret; |
| 698 | } |
| 699 | |
| 700 | /* override tuner callbacks for resource locking */ |
| 701 | static int af9015_tuner_sleep(struct dvb_frontend *fe) |
| 702 | { |
| 703 | int ret; |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 704 | struct af9015_state *state = fe_to_priv(fe); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 705 | |
| 706 | if (mutex_lock_interruptible(&state->fe_mutex)) |
| 707 | return -EAGAIN; |
| 708 | |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 709 | ret = state->tuner_sleep[fe_to_adap(fe)->id](fe); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 710 | |
| 711 | mutex_unlock(&state->fe_mutex); |
| 712 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 713 | return ret; |
| 714 | } |
| 715 | |
| 716 | static int af9015_copy_firmware(struct dvb_usb_device *d) |
| 717 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 718 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 719 | int ret; |
| 720 | u8 fw_params[4]; |
| 721 | u8 val, i; |
| 722 | struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params), |
| 723 | fw_params }; |
| 724 | deb_info("%s:\n", __func__); |
| 725 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 726 | fw_params[0] = state->firmware_size >> 8; |
| 727 | fw_params[1] = state->firmware_size & 0xff; |
| 728 | fw_params[2] = state->firmware_checksum >> 8; |
| 729 | fw_params[3] = state->firmware_checksum & 0xff; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 730 | |
| 731 | /* wait 2nd demodulator ready */ |
| 732 | msleep(100); |
| 733 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 734 | ret = af9015_read_reg_i2c(d, state->af9013_config[1].i2c_addr, |
| 735 | 0x98be, &val); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 736 | if (ret) |
| 737 | goto error; |
| 738 | else |
| 739 | deb_info("%s: firmware status:%02x\n", __func__, val); |
| 740 | |
| 741 | if (val == 0x0c) /* fw is running, no need for download */ |
| 742 | goto exit; |
| 743 | |
| 744 | /* set I2C master clock to fast (to speed up firmware copy) */ |
| 745 | ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */ |
| 746 | if (ret) |
| 747 | goto error; |
| 748 | |
| 749 | msleep(50); |
| 750 | |
| 751 | /* copy firmware */ |
| 752 | ret = af9015_ctrl_msg(d, &req); |
| 753 | if (ret) |
| 754 | err("firmware copy cmd failed:%d", ret); |
| 755 | deb_info("%s: firmware copy done\n", __func__); |
| 756 | |
| 757 | /* set I2C master clock back to normal */ |
| 758 | ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */ |
| 759 | if (ret) |
| 760 | goto error; |
| 761 | |
| 762 | /* request boot firmware */ |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 763 | ret = af9015_write_reg_i2c(d, state->af9013_config[1].i2c_addr, |
| 764 | 0xe205, 1); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 765 | deb_info("%s: firmware boot cmd status:%d\n", __func__, ret); |
| 766 | if (ret) |
| 767 | goto error; |
| 768 | |
| 769 | for (i = 0; i < 15; i++) { |
| 770 | msleep(100); |
| 771 | |
| 772 | /* check firmware status */ |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 773 | ret = af9015_read_reg_i2c(d, state->af9013_config[1].i2c_addr, |
| 774 | 0x98be, &val); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 775 | deb_info("%s: firmware status cmd status:%d fw status:%02x\n", |
| 776 | __func__, ret, val); |
| 777 | if (ret) |
| 778 | goto error; |
| 779 | |
| 780 | if (val == 0x0c || val == 0x04) /* success or fail */ |
| 781 | break; |
| 782 | } |
| 783 | |
| 784 | if (val == 0x04) { |
| 785 | err("firmware did not run"); |
| 786 | ret = -1; |
| 787 | } else if (val != 0x0c) { |
| 788 | err("firmware boot timeout"); |
| 789 | ret = -1; |
| 790 | } |
| 791 | |
| 792 | error: |
| 793 | exit: |
| 794 | return ret; |
| 795 | } |
| 796 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 797 | static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap) |
| 798 | { |
| 799 | int ret; |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 800 | struct af9015_state *state = adap_to_priv(adap); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 801 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 802 | if (adap->id == 0) { |
| 803 | state->af9013_config[0].ts_mode = AF9013_TS_USB; |
| 804 | memcpy(state->af9013_config[0].api_version, "\x0\x1\x9\x0", 4); |
| 805 | state->af9013_config[0].gpio[0] = AF9013_GPIO_HI; |
| 806 | state->af9013_config[0].gpio[3] = AF9013_GPIO_TUNER_ON; |
| 807 | } else if (adap->id == 1) { |
| 808 | state->af9013_config[1].ts_mode = AF9013_TS_SERIAL; |
| 809 | memcpy(state->af9013_config[1].api_version, "\x0\x1\x9\x0", 4); |
| 810 | state->af9013_config[1].gpio[0] = AF9013_GPIO_TUNER_ON; |
| 811 | state->af9013_config[1].gpio[1] = AF9013_GPIO_LO; |
| 812 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 813 | /* copy firmware to 2nd demodulator */ |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 814 | if (state->dual_mode) { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 815 | ret = af9015_copy_firmware(adap_to_d(adap)); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 816 | if (ret) { |
| 817 | err("firmware copy to 2nd frontend " \ |
| 818 | "failed, will disable it"); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 819 | state->dual_mode = 0; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 820 | return -ENODEV; |
| 821 | } |
| 822 | } else { |
| 823 | return -ENODEV; |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | /* attach demodulator */ |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 828 | adap->fe[0] = dvb_attach(af9013_attach, |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 829 | &state->af9013_config[adap->id], &adap_to_d(adap)->i2c_adap); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 830 | |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 831 | /* |
| 832 | * AF9015 firmware does not like if it gets interrupted by I2C adapter |
| 833 | * request on some critical phases. During normal operation I2C adapter |
| 834 | * is used only 2nd demodulator and tuner on dual tuner devices. |
| 835 | * Override demodulator callbacks and use mutex for limit access to |
| 836 | * those "critical" paths to keep AF9015 happy. |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 837 | */ |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 838 | if (adap->fe[0]) { |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 839 | state->set_frontend[adap->id] = |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 840 | adap->fe[0]->ops.set_frontend; |
| 841 | adap->fe[0]->ops.set_frontend = |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 842 | af9015_af9013_set_frontend; |
| 843 | |
| 844 | state->read_status[adap->id] = |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 845 | adap->fe[0]->ops.read_status; |
| 846 | adap->fe[0]->ops.read_status = |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 847 | af9015_af9013_read_status; |
| 848 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 849 | state->init[adap->id] = adap->fe[0]->ops.init; |
| 850 | adap->fe[0]->ops.init = af9015_af9013_init; |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 851 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 852 | state->sleep[adap->id] = adap->fe[0]->ops.sleep; |
| 853 | adap->fe[0]->ops.sleep = af9015_af9013_sleep; |
Antti Palosaari | e90ab84 | 2011-11-12 22:33:30 -0300 | [diff] [blame] | 854 | } |
| 855 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 856 | return adap->fe[0] == NULL ? -ENODEV : 0; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | static struct mt2060_config af9015_mt2060_config = { |
| 860 | .i2c_address = 0xc0, |
| 861 | .clock_out = 0, |
| 862 | }; |
| 863 | |
| 864 | static struct qt1010_config af9015_qt1010_config = { |
| 865 | .i2c_address = 0xc4, |
| 866 | }; |
| 867 | |
| 868 | static struct tda18271_config af9015_tda18271_config = { |
| 869 | .gate = TDA18271_GATE_DIGITAL, |
Mauro Carvalho Chehab | 7655e59 | 2010-10-27 14:55:34 -0200 | [diff] [blame] | 870 | .small_i2c = TDA18271_16_BYTE_CHUNK_INIT, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 871 | }; |
| 872 | |
| 873 | static struct mxl5005s_config af9015_mxl5003_config = { |
| 874 | .i2c_address = 0xc6, |
| 875 | .if_freq = IF_FREQ_4570000HZ, |
| 876 | .xtal_freq = CRYSTAL_FREQ_16000000HZ, |
| 877 | .agc_mode = MXL_SINGLE_AGC, |
| 878 | .tracking_filter = MXL_TF_DEFAULT, |
Antti Palosaari | a131077 | 2008-09-22 13:59:25 -0300 | [diff] [blame] | 879 | .rssi_enable = MXL_RSSI_ENABLE, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 880 | .cap_select = MXL_CAP_SEL_ENABLE, |
| 881 | .div_out = MXL_DIV_OUT_4, |
| 882 | .clock_out = MXL_CLOCK_OUT_DISABLE, |
| 883 | .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM, |
| 884 | .top = MXL5005S_TOP_25P2, |
| 885 | .mod_mode = MXL_DIGITAL_MODE, |
| 886 | .if_mode = MXL_ZERO_IF, |
| 887 | .AgcMasterByte = 0x00, |
| 888 | }; |
| 889 | |
| 890 | static struct mxl5005s_config af9015_mxl5005_config = { |
| 891 | .i2c_address = 0xc6, |
| 892 | .if_freq = IF_FREQ_4570000HZ, |
| 893 | .xtal_freq = CRYSTAL_FREQ_16000000HZ, |
| 894 | .agc_mode = MXL_SINGLE_AGC, |
| 895 | .tracking_filter = MXL_TF_OFF, |
Antti Palosaari | a131077 | 2008-09-22 13:59:25 -0300 | [diff] [blame] | 896 | .rssi_enable = MXL_RSSI_ENABLE, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 897 | .cap_select = MXL_CAP_SEL_ENABLE, |
| 898 | .div_out = MXL_DIV_OUT_4, |
| 899 | .clock_out = MXL_CLOCK_OUT_DISABLE, |
| 900 | .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM, |
| 901 | .top = MXL5005S_TOP_25P2, |
| 902 | .mod_mode = MXL_DIGITAL_MODE, |
| 903 | .if_mode = MXL_ZERO_IF, |
| 904 | .AgcMasterByte = 0x00, |
| 905 | }; |
| 906 | |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 907 | static struct mc44s803_config af9015_mc44s803_config = { |
| 908 | .i2c_address = 0xc0, |
| 909 | .dig_out = 1, |
| 910 | }; |
| 911 | |
Antti Palosaari | ee3d440 | 2010-08-13 03:51:26 -0300 | [diff] [blame] | 912 | static struct tda18218_config af9015_tda18218_config = { |
| 913 | .i2c_address = 0xc0, |
| 914 | .i2c_wr_max = 21, /* max wr bytes AF9015 I2C adap can handle at once */ |
| 915 | }; |
| 916 | |
Antti Palosaari | ab07fdd | 2010-09-09 14:59:10 -0300 | [diff] [blame] | 917 | static struct mxl5007t_config af9015_mxl5007t_config = { |
| 918 | .xtal_freq_hz = MxL_XTAL_24_MHZ, |
| 919 | .if_freq_hz = MxL_IF_4_57_MHZ, |
| 920 | }; |
| 921 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 922 | static int af9015_tuner_attach(struct dvb_usb_adapter *adap) |
| 923 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 924 | struct af9015_state *state = adap_to_priv(adap); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 925 | int ret; |
Antti Palosaari | 9a3ecc7 | 2010-10-07 21:37:06 -0300 | [diff] [blame] | 926 | deb_info("%s:\n", __func__); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 927 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 928 | switch (state->af9013_config[adap->id].tuner) { |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 929 | case AF9013_TUNER_MT2060: |
| 930 | case AF9013_TUNER_MT2060_2: |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 931 | ret = dvb_attach(mt2060_attach, adap->fe[0], |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 932 | &adap_to_d(adap)->i2c_adap, &af9015_mt2060_config, |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 933 | state->mt2060_if1[adap->id]) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 934 | == NULL ? -ENODEV : 0; |
| 935 | break; |
| 936 | case AF9013_TUNER_QT1010: |
| 937 | case AF9013_TUNER_QT1010A: |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 938 | ret = dvb_attach(qt1010_attach, adap->fe[0], |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 939 | &adap_to_d(adap)->i2c_adap, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 940 | &af9015_qt1010_config) == NULL ? -ENODEV : 0; |
| 941 | break; |
| 942 | case AF9013_TUNER_TDA18271: |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 943 | ret = dvb_attach(tda18271_attach, adap->fe[0], 0xc0, |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 944 | &adap_to_d(adap)->i2c_adap, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 945 | &af9015_tda18271_config) == NULL ? -ENODEV : 0; |
| 946 | break; |
Antti Palosaari | ee3d440 | 2010-08-13 03:51:26 -0300 | [diff] [blame] | 947 | case AF9013_TUNER_TDA18218: |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 948 | ret = dvb_attach(tda18218_attach, adap->fe[0], |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 949 | &adap_to_d(adap)->i2c_adap, |
Antti Palosaari | ee3d440 | 2010-08-13 03:51:26 -0300 | [diff] [blame] | 950 | &af9015_tda18218_config) == NULL ? -ENODEV : 0; |
| 951 | break; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 952 | case AF9013_TUNER_MXL5003D: |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 953 | ret = dvb_attach(mxl5005s_attach, adap->fe[0], |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 954 | &adap_to_d(adap)->i2c_adap, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 955 | &af9015_mxl5003_config) == NULL ? -ENODEV : 0; |
| 956 | break; |
| 957 | case AF9013_TUNER_MXL5005D: |
| 958 | case AF9013_TUNER_MXL5005R: |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 959 | ret = dvb_attach(mxl5005s_attach, adap->fe[0], |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 960 | &adap_to_d(adap)->i2c_adap, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 961 | &af9015_mxl5005_config) == NULL ? -ENODEV : 0; |
| 962 | break; |
| 963 | case AF9013_TUNER_ENV77H11D5: |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 964 | ret = dvb_attach(dvb_pll_attach, adap->fe[0], 0xc0, |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 965 | &adap_to_d(adap)->i2c_adap, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 966 | DVB_PLL_TDA665X) == NULL ? -ENODEV : 0; |
| 967 | break; |
| 968 | case AF9013_TUNER_MC44S803: |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 969 | ret = dvb_attach(mc44s803_attach, adap->fe[0], |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 970 | &adap_to_d(adap)->i2c_adap, |
Jochen Friedrich | d563399 | 2009-02-02 14:59:50 -0300 | [diff] [blame] | 971 | &af9015_mc44s803_config) == NULL ? -ENODEV : 0; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 972 | break; |
Antti Palosaari | ab07fdd | 2010-09-09 14:59:10 -0300 | [diff] [blame] | 973 | case AF9013_TUNER_MXL5007T: |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 974 | ret = dvb_attach(mxl5007t_attach, adap->fe[0], |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 975 | &adap_to_d(adap)->i2c_adap, |
Antti Palosaari | ab07fdd | 2010-09-09 14:59:10 -0300 | [diff] [blame] | 976 | 0xc0, &af9015_mxl5007t_config) == NULL ? -ENODEV : 0; |
| 977 | break; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 978 | case AF9013_TUNER_UNKNOWN: |
| 979 | default: |
| 980 | ret = -ENODEV; |
| 981 | err("Unknown tuner id:%d", |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 982 | state->af9013_config[adap->id].tuner); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 983 | } |
Gordon Hecker | be4a5e7 | 2012-03-14 10:27:30 -0300 | [diff] [blame] | 984 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 985 | if (adap->fe[0]->ops.tuner_ops.init) { |
Antti Palosaari | 6d535bd | 2012-03-14 10:27:31 -0300 | [diff] [blame] | 986 | state->tuner_init[adap->id] = |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 987 | adap->fe[0]->ops.tuner_ops.init; |
| 988 | adap->fe[0]->ops.tuner_ops.init = af9015_tuner_init; |
Antti Palosaari | 6d535bd | 2012-03-14 10:27:31 -0300 | [diff] [blame] | 989 | } |
Gordon Hecker | be4a5e7 | 2012-03-14 10:27:30 -0300 | [diff] [blame] | 990 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 991 | if (adap->fe[0]->ops.tuner_ops.sleep) { |
Antti Palosaari | 6d535bd | 2012-03-14 10:27:31 -0300 | [diff] [blame] | 992 | state->tuner_sleep[adap->id] = |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 993 | adap->fe[0]->ops.tuner_ops.sleep; |
| 994 | adap->fe[0]->ops.tuner_ops.sleep = af9015_tuner_sleep; |
Antti Palosaari | 6d535bd | 2012-03-14 10:27:31 -0300 | [diff] [blame] | 995 | } |
| 996 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 997 | return ret; |
| 998 | } |
| 999 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1000 | static int af9015_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 1001 | { |
| 1002 | int ret; |
| 1003 | deb_info("%s: onoff:%d\n", __func__, onoff); |
| 1004 | |
| 1005 | if (onoff) |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 1006 | ret = af9015_set_reg_bit(adap_to_d(adap), 0xd503, 0); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1007 | else |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 1008 | ret = af9015_clear_reg_bit(adap_to_d(adap), 0xd503, 0); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1009 | |
| 1010 | return ret; |
| 1011 | } |
| 1012 | |
| 1013 | static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, |
| 1014 | int onoff) |
| 1015 | { |
| 1016 | int ret; |
| 1017 | u8 idx; |
| 1018 | |
| 1019 | deb_info("%s: set pid filter, index %d, pid %x, onoff %d\n", |
| 1020 | __func__, index, pid, onoff); |
| 1021 | |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 1022 | ret = af9015_write_reg(adap_to_d(adap), 0xd505, (pid & 0xff)); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1023 | if (ret) |
| 1024 | goto error; |
| 1025 | |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 1026 | ret = af9015_write_reg(adap_to_d(adap), 0xd506, (pid >> 8)); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1027 | if (ret) |
| 1028 | goto error; |
| 1029 | |
| 1030 | idx = ((index & 0x1f) | (1 << 5)); |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 1031 | ret = af9015_write_reg(adap_to_d(adap), 0xd504, idx); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1032 | |
| 1033 | error: |
| 1034 | return ret; |
| 1035 | } |
| 1036 | |
| 1037 | static int af9015_init_endpoint(struct dvb_usb_device *d) |
| 1038 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 1039 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1040 | int ret; |
| 1041 | u16 frame_size; |
| 1042 | u8 packet_size; |
| 1043 | deb_info("%s: USB speed:%d\n", __func__, d->udev->speed); |
| 1044 | |
| 1045 | if (d->udev->speed == USB_SPEED_FULL) { |
| 1046 | frame_size = TS_USB11_FRAME_SIZE/4; |
| 1047 | packet_size = TS_USB11_MAX_PACKET_SIZE/4; |
| 1048 | } else { |
| 1049 | frame_size = TS_USB20_FRAME_SIZE/4; |
| 1050 | packet_size = TS_USB20_MAX_PACKET_SIZE/4; |
| 1051 | } |
| 1052 | |
| 1053 | ret = af9015_set_reg_bit(d, 0xd507, 2); /* assert EP4 reset */ |
| 1054 | if (ret) |
| 1055 | goto error; |
| 1056 | ret = af9015_set_reg_bit(d, 0xd50b, 1); /* assert EP5 reset */ |
| 1057 | if (ret) |
| 1058 | goto error; |
| 1059 | ret = af9015_clear_reg_bit(d, 0xdd11, 5); /* disable EP4 */ |
| 1060 | if (ret) |
| 1061 | goto error; |
| 1062 | ret = af9015_clear_reg_bit(d, 0xdd11, 6); /* disable EP5 */ |
| 1063 | if (ret) |
| 1064 | goto error; |
| 1065 | ret = af9015_set_reg_bit(d, 0xdd11, 5); /* enable EP4 */ |
| 1066 | if (ret) |
| 1067 | goto error; |
| 1068 | if (state->dual_mode) { |
| 1069 | ret = af9015_set_reg_bit(d, 0xdd11, 6); /* enable EP5 */ |
| 1070 | if (ret) |
| 1071 | goto error; |
| 1072 | } |
| 1073 | ret = af9015_clear_reg_bit(d, 0xdd13, 5); /* disable EP4 NAK */ |
| 1074 | if (ret) |
| 1075 | goto error; |
| 1076 | if (state->dual_mode) { |
| 1077 | ret = af9015_clear_reg_bit(d, 0xdd13, 6); /* disable EP5 NAK */ |
| 1078 | if (ret) |
| 1079 | goto error; |
| 1080 | } |
| 1081 | /* EP4 xfer length */ |
| 1082 | ret = af9015_write_reg(d, 0xdd88, frame_size & 0xff); |
| 1083 | if (ret) |
| 1084 | goto error; |
| 1085 | ret = af9015_write_reg(d, 0xdd89, frame_size >> 8); |
| 1086 | if (ret) |
| 1087 | goto error; |
| 1088 | /* EP5 xfer length */ |
| 1089 | ret = af9015_write_reg(d, 0xdd8a, frame_size & 0xff); |
| 1090 | if (ret) |
| 1091 | goto error; |
| 1092 | ret = af9015_write_reg(d, 0xdd8b, frame_size >> 8); |
| 1093 | if (ret) |
| 1094 | goto error; |
| 1095 | ret = af9015_write_reg(d, 0xdd0c, packet_size); /* EP4 packet size */ |
| 1096 | if (ret) |
| 1097 | goto error; |
| 1098 | ret = af9015_write_reg(d, 0xdd0d, packet_size); /* EP5 packet size */ |
| 1099 | if (ret) |
| 1100 | goto error; |
| 1101 | ret = af9015_clear_reg_bit(d, 0xd507, 2); /* negate EP4 reset */ |
| 1102 | if (ret) |
| 1103 | goto error; |
| 1104 | if (state->dual_mode) { |
| 1105 | ret = af9015_clear_reg_bit(d, 0xd50b, 1); /* negate EP5 reset */ |
| 1106 | if (ret) |
| 1107 | goto error; |
| 1108 | } |
| 1109 | |
| 1110 | /* enable / disable mp2if2 */ |
| 1111 | if (state->dual_mode) |
| 1112 | ret = af9015_set_reg_bit(d, 0xd50b, 0); |
| 1113 | else |
| 1114 | ret = af9015_clear_reg_bit(d, 0xd50b, 0); |
| 1115 | |
| 1116 | error: |
| 1117 | if (ret) |
| 1118 | err("endpoint init failed:%d", ret); |
| 1119 | return ret; |
| 1120 | } |
| 1121 | |
| 1122 | static int af9015_init(struct dvb_usb_device *d) |
| 1123 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 1124 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1125 | int ret; |
| 1126 | deb_info("%s:\n", __func__); |
| 1127 | |
| 1128 | mutex_init(&state->fe_mutex); |
| 1129 | |
| 1130 | /* init RC canary */ |
| 1131 | ret = af9015_write_reg(d, 0x98e9, 0xff); |
| 1132 | if (ret) |
| 1133 | goto error; |
| 1134 | |
| 1135 | ret = af9015_init_endpoint(d); |
| 1136 | if (ret) |
| 1137 | goto error; |
| 1138 | |
| 1139 | error: |
| 1140 | return ret; |
| 1141 | } |
| 1142 | |
| 1143 | struct af9015_rc_setup { |
| 1144 | unsigned int id; |
| 1145 | char *rc_codes; |
Jonathan Nieder | d07b901 | 2012-01-07 04:11:27 -0300 | [diff] [blame] | 1146 | }; |
| 1147 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1148 | static char *af9015_rc_setup_match(unsigned int id, |
| 1149 | const struct af9015_rc_setup *table) |
| 1150 | { |
| 1151 | for (; table->rc_codes; table++) |
| 1152 | if (table->id == id) |
| 1153 | return table->rc_codes; |
| 1154 | return NULL; |
| 1155 | } |
| 1156 | |
| 1157 | static const struct af9015_rc_setup af9015_rc_setup_modparam[] = { |
| 1158 | { AF9015_REMOTE_A_LINK_DTU_M, RC_MAP_ALINK_DTU_M }, |
| 1159 | { AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, RC_MAP_MSI_DIGIVOX_II }, |
| 1160 | { AF9015_REMOTE_MYGICTV_U718, RC_MAP_TOTAL_MEDIA_IN_HAND }, |
| 1161 | { AF9015_REMOTE_DIGITTRADE_DVB_T, RC_MAP_DIGITTRADE }, |
| 1162 | { AF9015_REMOTE_AVERMEDIA_KS, RC_MAP_AVERMEDIA_RM_KS }, |
Jonathan Nieder | d07b901 | 2012-01-07 04:11:27 -0300 | [diff] [blame] | 1163 | { } |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1164 | }; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1165 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1166 | static const struct af9015_rc_setup af9015_rc_setup_hashes[] = { |
| 1167 | { 0xb8feb708, RC_MAP_MSI_DIGIVOX_II }, |
| 1168 | { 0xa3703d00, RC_MAP_ALINK_DTU_M }, |
| 1169 | { 0x9b7dc64e, RC_MAP_TOTAL_MEDIA_IN_HAND }, /* MYGICTV U718 */ |
| 1170 | { 0x5d49e3db, RC_MAP_DIGITTRADE }, /* LC-Power LC-USB-DVBT */ |
| 1171 | { } |
| 1172 | }; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1173 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1174 | static int af9015_rc_query(struct dvb_usb_device *d) |
| 1175 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 1176 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1177 | int ret; |
| 1178 | u8 buf[17]; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1179 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1180 | deb_info("%s:\n", __func__); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1181 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1182 | /* read registers needed to detect remote controller code */ |
| 1183 | ret = af9015_read_regs(d, 0x98d9, buf, sizeof(buf)); |
| 1184 | if (ret) |
| 1185 | goto error; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1186 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1187 | /* If any of these are non-zero, assume invalid data */ |
| 1188 | if (buf[1] || buf[2] || buf[3]) |
| 1189 | return ret; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1190 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1191 | /* Check for repeat of previous code */ |
| 1192 | if ((state->rc_repeat != buf[6] || buf[0]) && |
| 1193 | !memcmp(&buf[12], state->rc_last, 4)) { |
| 1194 | deb_rc("%s: key repeated\n", __func__); |
| 1195 | rc_keydown(d->rc_dev, state->rc_keycode, 0); |
| 1196 | state->rc_repeat = buf[6]; |
| 1197 | return ret; |
| 1198 | } |
| 1199 | |
| 1200 | /* Only process key if canary killed */ |
| 1201 | if (buf[16] != 0xff && buf[0] != 0x01) { |
| 1202 | deb_rc("%s: key pressed %02x %02x %02x %02x\n", __func__, |
| 1203 | buf[12], buf[13], buf[14], buf[15]); |
| 1204 | |
| 1205 | /* Reset the canary */ |
| 1206 | ret = af9015_write_reg(d, 0x98e9, 0xff); |
| 1207 | if (ret) |
| 1208 | goto error; |
| 1209 | |
| 1210 | /* Remember this key */ |
| 1211 | memcpy(state->rc_last, &buf[12], 4); |
| 1212 | if (buf[14] == (u8) ~buf[15]) { |
| 1213 | if (buf[12] == (u8) ~buf[13]) { |
| 1214 | /* NEC */ |
| 1215 | state->rc_keycode = buf[12] << 8 | buf[14]; |
| 1216 | } else { |
| 1217 | /* NEC extended*/ |
| 1218 | state->rc_keycode = buf[12] << 16 | |
| 1219 | buf[13] << 8 | buf[14]; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1220 | } |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1221 | } else { |
| 1222 | /* 32 bit NEC */ |
| 1223 | state->rc_keycode = buf[12] << 24 | buf[13] << 16 | |
| 1224 | buf[14] << 8 | buf[15]; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1225 | } |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1226 | rc_keydown(d->rc_dev, state->rc_keycode, 0); |
| 1227 | } else { |
| 1228 | deb_rc("%s: no key press\n", __func__); |
| 1229 | /* Invalidate last keypress */ |
| 1230 | /* Not really needed, but helps with debug */ |
| 1231 | state->rc_last[2] = state->rc_last[3]; |
| 1232 | } |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1233 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1234 | state->rc_repeat = buf[6]; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1235 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1236 | error: |
| 1237 | if (ret) |
| 1238 | err("%s: failed:%d", __func__, ret); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1239 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1240 | return ret; |
| 1241 | } |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1242 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1243 | static int af9015_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc) |
| 1244 | { |
Antti Palosaari | e808966 | 2012-06-16 18:13:06 -0300 | [diff] [blame] | 1245 | struct af9015_state *state = d_to_priv(d); |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1246 | u16 vid = le16_to_cpu(d->udev->descriptor.idVendor); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1247 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1248 | if (state->ir_mode == AF9015_IR_MODE_DISABLED) |
| 1249 | return 0; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1250 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1251 | /* try to load remote based module param */ |
| 1252 | rc->map_name = af9015_rc_setup_match(dvb_usb_af9015_remote, |
| 1253 | af9015_rc_setup_modparam); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1254 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1255 | /* try to load remote based eeprom hash */ |
| 1256 | if (!rc->map_name) |
| 1257 | rc->map_name = af9015_rc_setup_match(state->eeprom_sum, |
| 1258 | af9015_rc_setup_hashes); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1259 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1260 | /* try to load remote based USB iManufacturer string */ |
| 1261 | if (!rc->map_name && vid == USB_VID_AFATECH) { |
| 1262 | /* Check USB manufacturer and product strings and try |
| 1263 | to determine correct remote in case of chip vendor |
| 1264 | reference IDs are used. |
| 1265 | DO NOT ADD ANYTHING NEW HERE. Use hashes instead. */ |
| 1266 | char manufacturer[10]; |
| 1267 | memset(manufacturer, 0, sizeof(manufacturer)); |
| 1268 | usb_string(d->udev, d->udev->descriptor.iManufacturer, |
| 1269 | manufacturer, sizeof(manufacturer)); |
| 1270 | if (!strcmp("MSI", manufacturer)) { |
| 1271 | /* iManufacturer 1 MSI |
| 1272 | iProduct 2 MSI K-VOX */ |
| 1273 | rc->map_name = af9015_rc_setup_match( |
| 1274 | AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, |
| 1275 | af9015_rc_setup_modparam); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1276 | } |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1277 | } |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1278 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1279 | rc->allowed_protos = RC_TYPE_NEC; |
| 1280 | rc->query = af9015_rc_query; |
| 1281 | rc->interval = 500; |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1282 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1283 | return 0; |
| 1284 | } |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1285 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1286 | /* interface 0 is used by DVB-T receiver and |
| 1287 | interface 1 is for remote controller (HID) */ |
| 1288 | static struct dvb_usb_device_properties af9015_props = { |
| 1289 | .driver_name = KBUILD_MODNAME, |
| 1290 | .owner = THIS_MODULE, |
| 1291 | .adapter_nr = adapter_nr, |
| 1292 | .size_of_priv = sizeof(struct af9015_state), |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1293 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1294 | .generic_bulk_ctrl_endpoint = 0x02, |
| 1295 | .generic_bulk_ctrl_endpoint_response = 0x81, |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1296 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1297 | .identify_state = af9015_identify_state, |
| 1298 | .firmware = "dvb-usb-af9015.fw", |
| 1299 | .download_firmware = af9015_download_firmware, |
| 1300 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1301 | .i2c_algo = &af9015_i2c_algo, |
Antti Palosaari | 2d2b37c7 | 2012-06-12 01:05:20 -0300 | [diff] [blame] | 1302 | .read_config = af9015_read_config, |
| 1303 | .frontend_attach = af9015_af9013_frontend_attach, |
| 1304 | .tuner_attach = af9015_tuner_attach, |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1305 | .init = af9015_init, |
| 1306 | .get_rc_config = af9015_get_rc_config, |
Antti Palosaari | b905a2a | 2012-06-18 22:54:16 -0300 | [diff] [blame] | 1307 | .get_stream_config = af9015_get_stream_config, |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1308 | |
| 1309 | .get_adapter_count = af9015_get_adapter_count, |
| 1310 | .adapter = { |
| 1311 | { |
| 1312 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | |
| 1313 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, |
| 1314 | .pid_filter_count = 32, |
| 1315 | .pid_filter = af9015_pid_filter, |
| 1316 | .pid_filter_ctrl = af9015_pid_filter_ctrl, |
Antti Palosaari | 1a59001 | 2012-06-16 16:25:22 -0300 | [diff] [blame] | 1317 | |
| 1318 | .stream = DVB_USB_STREAM_BULK(0x84, 8, TS_USB20_FRAME_SIZE), |
| 1319 | }, { |
| 1320 | .stream = DVB_USB_STREAM_BULK(0x85, 8, TS_USB20_FRAME_SIZE), |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1321 | }, |
Antti Palosaari | 85d7d7c | 2009-04-09 09:16:12 -0300 | [diff] [blame] | 1322 | }, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1323 | }; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1324 | |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1325 | static const struct usb_device_id af9015_id_table[] = { |
| 1326 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9015, |
| 1327 | &af9015_props, "Afatech AF9015 reference design", NULL) }, |
| 1328 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9016, |
| 1329 | &af9015_props, "Afatech AF9015 reference design", NULL) }, |
| 1330 | { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_GOLD, |
| 1331 | &af9015_props, "Leadtek WinFast DTV Dongle Gold", RC_MAP_LEADTEK_Y04G0051) }, |
| 1332 | { DVB_USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV71E, |
| 1333 | &af9015_props, "Pinnacle PCTV 71e", NULL) }, |
| 1334 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U, |
| 1335 | &af9015_props, "KWorld PlusTV Dual DVB-T Stick (DVB-T 399U)", NULL) }, |
| 1336 | { DVB_USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_TINYTWIN, |
| 1337 | &af9015_props, "DigitalNow TinyTwin", RC_MAP_AZUREWAVE_AD_TU700) }, |
| 1338 | { DVB_USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_AZUREWAVE_AD_TU700, |
| 1339 | &af9015_props, "TwinHan AzureWave AD-TU700(704J)", RC_MAP_AZUREWAVE_AD_TU700) }, |
| 1340 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2, |
| 1341 | &af9015_props, "TerraTec Cinergy T USB XE", NULL) }, |
| 1342 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_2T, |
| 1343 | &af9015_props, "KWorld PlusTV Dual DVB-T PCI (DVB-T PC160-2T)", NULL) }, |
| 1344 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X, |
| 1345 | &af9015_props, "AVerMedia AVerTV DVB-T Volar X", RC_MAP_AVERMEDIA_M135A) }, |
| 1346 | { DVB_USB_DEVICE(USB_VID_XTENSIONS, USB_PID_XTENSIONS_XD_380, |
| 1347 | &af9015_props, "Xtensions XD-380", NULL) }, |
| 1348 | { DVB_USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGIVOX_DUO, |
| 1349 | &af9015_props, "MSI DIGIVOX Duo", RC_MAP_MSI_DIGIVOX_III) }, |
| 1350 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X_2, |
| 1351 | &af9015_props, "Fujitsu-Siemens Slim Mobile USB DVB-T", NULL) }, |
| 1352 | { DVB_USB_DEVICE(USB_VID_TELESTAR, USB_PID_TELESTAR_STARSTICK_2, |
| 1353 | &af9015_props, "Telestar Starstick 2", NULL) }, |
| 1354 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A309, |
| 1355 | &af9015_props, "AVerMedia A309", NULL) }, |
| 1356 | { DVB_USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGI_VOX_MINI_III, |
| 1357 | &af9015_props, "MSI Digi VOX mini III", RC_MAP_MSI_DIGIVOX_III) }, |
| 1358 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U, |
| 1359 | &af9015_props, "KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)", NULL) }, |
| 1360 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_2, |
| 1361 | &af9015_props, "KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)", NULL) }, |
| 1362 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_3, |
| 1363 | &af9015_props, "KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)", NULL) }, |
| 1364 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_TREKSTOR_DVBT, |
| 1365 | &af9015_props, "TrekStor DVB-T USB Stick", RC_MAP_TREKSTOR) }, |
| 1366 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850, |
| 1367 | &af9015_props, "AverMedia AVerTV Volar Black HD (A850)", NULL) }, |
| 1368 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A805, |
| 1369 | &af9015_props, "AverMedia AVerTV Volar GPS 805 (A805)", NULL) }, |
| 1370 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CONCEPTRONIC_CTVDIGRCU, |
| 1371 | &af9015_props, "Conceptronic USB2.0 DVB-T CTVDIGRCU V3.0", NULL) }, |
| 1372 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_MC810, |
| 1373 | &af9015_props, "KWorld Digial MC-810", NULL) }, |
| 1374 | { DVB_USB_DEVICE(USB_VID_KYE, USB_PID_GENIUS_TVGO_DVB_T03, |
| 1375 | &af9015_props, "Genius TVGo DVB-T03", NULL) }, |
| 1376 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U_2, |
| 1377 | &af9015_props, "KWorld PlusTV Dual DVB-T Stick (DVB-T 399U)", NULL) }, |
| 1378 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_T, |
| 1379 | &af9015_props, "KWorld PlusTV DVB-T PCI Pro Card (DVB-T PC160-T)", NULL) }, |
| 1380 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20, |
| 1381 | &af9015_props, "Sveon STV20 Tuner USB DVB-T HDTV", NULL) }, |
| 1382 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TINYTWIN_2, |
| 1383 | &af9015_props, "DigitalNow TinyTwin v2", RC_MAP_DIGITALNOW_TINYTWIN) }, |
| 1384 | { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS, |
| 1385 | &af9015_props, "Leadtek WinFast DTV2000DS", RC_MAP_LEADTEK_Y04G0051) }, |
| 1386 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB383_T, |
| 1387 | &af9015_props, "KWorld USB DVB-T Stick Mobile (UB383-T)", NULL) }, |
| 1388 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_4, |
| 1389 | &af9015_props, "KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)", NULL) }, |
| 1390 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A815M, |
| 1391 | &af9015_props, "AverMedia AVerTV Volar M (A815Mac)", NULL) }, |
| 1392 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_RC, |
| 1393 | &af9015_props, "TerraTec Cinergy T Stick RC", RC_MAP_TERRATEC_SLIM_2) }, |
| 1394 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_DUAL_RC, |
| 1395 | &af9015_props, "TerraTec Cinergy T Stick Dual RC", RC_MAP_TERRATEC_SLIM) }, |
| 1396 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A850T, |
| 1397 | &af9015_props, "AverMedia AVerTV Red HD+ (A850T)", NULL) }, |
| 1398 | { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TINYTWIN_3, |
| 1399 | &af9015_props, "DigitalNow TinyTwin v3", RC_MAP_DIGITALNOW_TINYTWIN) }, |
| 1400 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV22, |
| 1401 | &af9015_props, "Sveon STV22 Dual USB DVB-T Tuner HDTV", RC_MAP_MSI_DIGIVOX_III) }, |
| 1402 | { } |
| 1403 | }; |
| 1404 | MODULE_DEVICE_TABLE(usb, af9015_id_table); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1405 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1406 | /* usb specific object needed to register this driver with the usb subsystem */ |
| 1407 | static struct usb_driver af9015_usb_driver = { |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1408 | .name = KBUILD_MODNAME, |
Antti Palosaari | 2d2b37c7 | 2012-06-12 01:05:20 -0300 | [diff] [blame] | 1409 | .id_table = af9015_id_table, |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1410 | .probe = dvb_usbv2_probe, |
| 1411 | .disconnect = dvb_usbv2_disconnect, |
Antti Palosaari | 53dc194 | 2012-06-12 02:20:01 -0300 | [diff] [blame] | 1412 | .suspend = dvb_usbv2_suspend, |
| 1413 | .resume = dvb_usbv2_resume, |
Antti Palosaari | a3645e5 | 2012-06-07 20:36:35 -0300 | [diff] [blame] | 1414 | .no_dynamic_id = 1, |
Antti Palosaari | 77f5451 | 2012-06-09 21:22:06 -0300 | [diff] [blame] | 1415 | .soft_unbind = 1, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1416 | }; |
| 1417 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 1418 | module_usb_driver(af9015_usb_driver); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1419 | |
| 1420 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
Antti Palosaari | bc050e6 | 2012-05-08 06:04:24 -0300 | [diff] [blame] | 1421 | MODULE_DESCRIPTION("Afatech AF9015 driver"); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1422 | MODULE_LICENSE("GPL"); |