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" |
| 25 | #include "af9013.h" |
| 26 | #include "mt2060.h" |
| 27 | #include "qt1010.h" |
| 28 | #include "tda18271.h" |
| 29 | #include "mxl5005s.h" |
| 30 | #if 0 |
| 31 | #include "mc44s80x.h" |
| 32 | #endif |
| 33 | |
Antti Palosaari | 349d042 | 2008-11-05 16:31:24 -0300 | [diff] [blame] | 34 | static int dvb_usb_af9015_debug; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 35 | module_param_named(debug, dvb_usb_af9015_debug, int, 0644); |
| 36 | MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS); |
Antti Palosaari | 349d042 | 2008-11-05 16:31:24 -0300 | [diff] [blame] | 37 | static int dvb_usb_af9015_remote; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 38 | module_param_named(remote, dvb_usb_af9015_remote, int, 0644); |
| 39 | MODULE_PARM_DESC(remote, "select remote"); |
Antti Palosaari | 349d042 | 2008-11-05 16:31:24 -0300 | [diff] [blame] | 40 | static int dvb_usb_af9015_dual_mode; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 41 | module_param_named(dual_mode, dvb_usb_af9015_dual_mode, int, 0644); |
| 42 | MODULE_PARM_DESC(dual_mode, "enable dual mode"); |
| 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; |
| 48 | static struct dvb_usb_device_properties af9015_properties[2]; |
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 | { |
| 69 | int act_len, ret; |
| 70 | u8 buf[64]; |
| 71 | u8 write = 1; |
| 72 | u8 msg_len = 8; |
| 73 | static u8 seq; /* packet sequence number */ |
| 74 | |
| 75 | if (mutex_lock_interruptible(&af9015_usb_mutex) < 0) |
| 76 | return -EAGAIN; |
| 77 | |
| 78 | buf[0] = req->cmd; |
| 79 | buf[1] = seq++; |
| 80 | buf[2] = req->i2c_addr; |
| 81 | buf[3] = req->addr >> 8; |
| 82 | buf[4] = req->addr & 0xff; |
| 83 | buf[5] = req->mbox; |
| 84 | buf[6] = req->addr_len; |
| 85 | buf[7] = req->data_len; |
| 86 | |
| 87 | switch (req->cmd) { |
| 88 | case GET_CONFIG: |
| 89 | case BOOT: |
| 90 | case READ_MEMORY: |
| 91 | case RECONNECT_USB: |
| 92 | case GET_IR_CODE: |
| 93 | write = 0; |
| 94 | break; |
| 95 | case READ_I2C: |
| 96 | write = 0; |
| 97 | buf[2] |= 0x01; /* set I2C direction */ |
| 98 | case WRITE_I2C: |
| 99 | buf[0] = READ_WRITE_I2C; |
| 100 | break; |
| 101 | case WRITE_MEMORY: |
| 102 | if (((req->addr & 0xff00) == 0xff00) || |
| 103 | ((req->addr & 0xae00) == 0xae00)) |
| 104 | buf[0] = WRITE_VIRTUAL_MEMORY; |
| 105 | case WRITE_VIRTUAL_MEMORY: |
| 106 | case COPY_FIRMWARE: |
| 107 | case DOWNLOAD_FIRMWARE: |
| 108 | break; |
| 109 | default: |
| 110 | err("unknown command:%d", req->cmd); |
| 111 | ret = -1; |
| 112 | goto error_unlock; |
| 113 | } |
| 114 | |
| 115 | /* write requested */ |
| 116 | if (write) { |
| 117 | memcpy(&buf[8], req->data, req->data_len); |
| 118 | msg_len += req->data_len; |
| 119 | } |
| 120 | deb_xfer(">>> "); |
| 121 | debug_dump(buf, msg_len, deb_xfer); |
| 122 | |
| 123 | /* send req */ |
| 124 | ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x02), buf, msg_len, |
| 125 | &act_len, AF9015_USB_TIMEOUT); |
| 126 | if (ret) |
| 127 | err("bulk message failed:%d (%d/%d)", ret, msg_len, act_len); |
| 128 | else |
| 129 | if (act_len != msg_len) |
| 130 | ret = -1; /* all data is not send */ |
| 131 | if (ret) |
| 132 | goto error_unlock; |
| 133 | |
| 134 | /* no ack for those packets */ |
| 135 | if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB) |
| 136 | goto exit_unlock; |
| 137 | |
| 138 | /* receive ack and data if read req */ |
| 139 | msg_len = 1 + 1 + req->data_len; /* seq + status + data len */ |
| 140 | ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, 0x81), buf, msg_len, |
| 141 | &act_len, AF9015_USB_TIMEOUT); |
| 142 | if (ret) { |
| 143 | err("recv bulk message failed:%d", ret); |
| 144 | ret = -1; |
| 145 | goto error_unlock; |
| 146 | } |
| 147 | |
| 148 | deb_xfer("<<< "); |
| 149 | debug_dump(buf, act_len, deb_xfer); |
| 150 | |
| 151 | /* remote controller query status is 1 if remote code is not received */ |
| 152 | if (req->cmd == GET_IR_CODE && buf[1] == 1) { |
| 153 | buf[1] = 0; /* clear command "error" status */ |
| 154 | memset(&buf[2], 0, req->data_len); |
| 155 | buf[3] = 1; /* no remote code received mark */ |
| 156 | } |
| 157 | |
| 158 | /* check status */ |
| 159 | if (buf[1]) { |
| 160 | err("command failed:%d", buf[1]); |
| 161 | ret = -1; |
| 162 | goto error_unlock; |
| 163 | } |
| 164 | |
| 165 | /* read request, copy returned data to return buf */ |
| 166 | if (!write) |
| 167 | memcpy(req->data, &buf[2], req->data_len); |
| 168 | |
| 169 | error_unlock: |
| 170 | exit_unlock: |
| 171 | mutex_unlock(&af9015_usb_mutex); |
| 172 | |
| 173 | return ret; |
| 174 | } |
| 175 | |
| 176 | static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req) |
| 177 | { |
| 178 | return af9015_rw_udev(d->udev, req); |
| 179 | } |
| 180 | |
| 181 | static int af9015_write_regs(struct dvb_usb_device *d, u16 addr, u8 *val, |
| 182 | u8 len) |
| 183 | { |
| 184 | struct req_t req = {WRITE_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len, |
| 185 | val}; |
| 186 | return af9015_ctrl_msg(d, &req); |
| 187 | } |
| 188 | |
| 189 | static int af9015_write_reg(struct dvb_usb_device *d, u16 addr, u8 val) |
| 190 | { |
| 191 | return af9015_write_regs(d, addr, &val, 1); |
| 192 | } |
| 193 | |
| 194 | static int af9015_read_reg(struct dvb_usb_device *d, u16 addr, u8 *val) |
| 195 | { |
| 196 | struct req_t req = {READ_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, 1, val}; |
| 197 | return af9015_ctrl_msg(d, &req); |
| 198 | } |
| 199 | |
| 200 | static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg, |
| 201 | u8 val) |
| 202 | { |
| 203 | struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val}; |
| 204 | |
| 205 | if (addr == af9015_af9013_config[0].demod_address || |
| 206 | addr == af9015_af9013_config[1].demod_address) |
| 207 | req.addr_len = 3; |
| 208 | |
| 209 | return af9015_ctrl_msg(d, &req); |
| 210 | } |
| 211 | |
| 212 | static int af9015_read_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg, |
| 213 | u8 *val) |
| 214 | { |
| 215 | struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val}; |
| 216 | |
| 217 | if (addr == af9015_af9013_config[0].demod_address || |
| 218 | addr == af9015_af9013_config[1].demod_address) |
| 219 | req.addr_len = 3; |
| 220 | |
| 221 | return af9015_ctrl_msg(d, &req); |
| 222 | } |
| 223 | |
| 224 | static int af9015_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
| 225 | int num) |
| 226 | { |
| 227 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 228 | int ret = 0, i = 0; |
| 229 | u16 addr; |
| 230 | u8 mbox, addr_len; |
| 231 | struct req_t req; |
| 232 | |
| 233 | /* TODO: implement bus lock |
| 234 | |
| 235 | The bus lock is needed because there is two tuners both using same I2C-address. |
| 236 | Due to that the only way to select correct tuner is use demodulator I2C-gate. |
| 237 | |
| 238 | ................................................ |
| 239 | . AF9015 includes integrated AF9013 demodulator. |
| 240 | . ____________ ____________ . ____________ |
| 241 | .| uC | | demod | . | tuner | |
| 242 | .|------------| |------------| . |------------| |
| 243 | .| AF9015 | | AF9013/5 | . | MXL5003 | |
| 244 | .| |--+----I2C-------|-----/ -----|-.-----I2C-------| | |
| 245 | .| | | | addr 0x38 | . | addr 0xc6 | |
| 246 | .|____________| | |____________| . |____________| |
| 247 | .................|.............................. |
| 248 | | ____________ ____________ |
| 249 | | | demod | | tuner | |
| 250 | | |------------| |------------| |
| 251 | | | AF9013 | | MXL5003 | |
| 252 | +----I2C-------|-----/ -----|-------I2C-------| | |
| 253 | | addr 0x3a | | addr 0xc6 | |
| 254 | |____________| |____________| |
| 255 | */ |
| 256 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 257 | return -EAGAIN; |
| 258 | |
| 259 | while (i < num) { |
| 260 | if (msg[i].addr == af9015_af9013_config[0].demod_address || |
| 261 | msg[i].addr == af9015_af9013_config[1].demod_address) { |
| 262 | addr = msg[i].buf[0] << 8; |
| 263 | addr += msg[i].buf[1]; |
| 264 | mbox = msg[i].buf[2]; |
| 265 | addr_len = 3; |
| 266 | } else { |
| 267 | addr = msg[i].buf[0]; |
| 268 | addr_len = 1; |
| 269 | mbox = 0; |
| 270 | } |
| 271 | |
| 272 | if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) { |
| 273 | if (msg[i].addr == |
| 274 | af9015_af9013_config[0].demod_address) |
| 275 | req.cmd = READ_MEMORY; |
| 276 | else |
| 277 | req.cmd = READ_I2C; |
| 278 | req.i2c_addr = msg[i].addr; |
| 279 | req.addr = addr; |
| 280 | req.mbox = mbox; |
| 281 | req.addr_len = addr_len; |
| 282 | req.data_len = msg[i+1].len; |
| 283 | req.data = &msg[i+1].buf[0]; |
| 284 | ret = af9015_ctrl_msg(d, &req); |
| 285 | i += 2; |
| 286 | } else { |
| 287 | if (msg[i].addr == |
| 288 | af9015_af9013_config[0].demod_address) |
| 289 | req.cmd = WRITE_MEMORY; |
| 290 | else |
| 291 | req.cmd = WRITE_I2C; |
| 292 | req.i2c_addr = msg[i].addr; |
| 293 | req.addr = addr; |
| 294 | req.mbox = mbox; |
| 295 | req.addr_len = addr_len; |
| 296 | req.data_len = msg[i].len-addr_len; |
| 297 | req.data = &msg[i].buf[addr_len]; |
| 298 | ret = af9015_ctrl_msg(d, &req); |
| 299 | i += 1; |
| 300 | } |
| 301 | if (ret) |
| 302 | goto error; |
| 303 | |
| 304 | } |
| 305 | ret = i; |
| 306 | |
| 307 | error: |
| 308 | mutex_unlock(&d->i2c_mutex); |
| 309 | |
| 310 | return ret; |
| 311 | } |
| 312 | |
| 313 | static u32 af9015_i2c_func(struct i2c_adapter *adapter) |
| 314 | { |
| 315 | return I2C_FUNC_I2C; |
| 316 | } |
| 317 | |
| 318 | static struct i2c_algorithm af9015_i2c_algo = { |
| 319 | .master_xfer = af9015_i2c_xfer, |
| 320 | .functionality = af9015_i2c_func, |
| 321 | }; |
| 322 | |
| 323 | static int af9015_do_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit, u8 op) |
| 324 | { |
| 325 | int ret; |
| 326 | u8 val, mask = 0x01; |
| 327 | |
| 328 | ret = af9015_read_reg(d, addr, &val); |
| 329 | if (ret) |
| 330 | return ret; |
| 331 | |
| 332 | mask <<= bit; |
| 333 | if (op) { |
| 334 | /* set bit */ |
| 335 | val |= mask; |
| 336 | } else { |
| 337 | /* clear bit */ |
| 338 | mask ^= 0xff; |
| 339 | val &= mask; |
| 340 | } |
| 341 | |
| 342 | return af9015_write_reg(d, addr, val); |
| 343 | } |
| 344 | |
| 345 | static int af9015_set_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit) |
| 346 | { |
| 347 | return af9015_do_reg_bit(d, addr, bit, 1); |
| 348 | } |
| 349 | |
| 350 | static int af9015_clear_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit) |
| 351 | { |
| 352 | return af9015_do_reg_bit(d, addr, bit, 0); |
| 353 | } |
| 354 | |
| 355 | static int af9015_init_endpoint(struct dvb_usb_device *d) |
| 356 | { |
| 357 | int ret; |
| 358 | u16 frame_size; |
| 359 | u8 packet_size; |
| 360 | deb_info("%s: USB speed:%d\n", __func__, d->udev->speed); |
| 361 | |
| 362 | #define TS_PACKET_SIZE 188 |
| 363 | |
| 364 | #define TS_USB20_PACKET_COUNT 348 |
| 365 | #define TS_USB20_FRAME_SIZE (TS_PACKET_SIZE*TS_USB20_PACKET_COUNT) |
| 366 | |
| 367 | #define TS_USB11_PACKET_COUNT 21 |
| 368 | #define TS_USB11_FRAME_SIZE (TS_PACKET_SIZE*TS_USB11_PACKET_COUNT) |
| 369 | |
| 370 | #define TS_USB20_MAX_PACKET_SIZE 512 |
| 371 | #define TS_USB11_MAX_PACKET_SIZE 64 |
| 372 | |
| 373 | if (d->udev->speed == USB_SPEED_FULL) { |
| 374 | frame_size = TS_USB11_FRAME_SIZE/4; |
| 375 | packet_size = TS_USB11_MAX_PACKET_SIZE/4; |
| 376 | } else { |
| 377 | frame_size = TS_USB20_FRAME_SIZE/4; |
| 378 | packet_size = TS_USB20_MAX_PACKET_SIZE/4; |
| 379 | } |
| 380 | |
| 381 | ret = af9015_set_reg_bit(d, 0xd507, 2); /* assert EP4 reset */ |
| 382 | if (ret) |
| 383 | goto error; |
| 384 | ret = af9015_set_reg_bit(d, 0xd50b, 1); /* assert EP5 reset */ |
| 385 | if (ret) |
| 386 | goto error; |
| 387 | ret = af9015_clear_reg_bit(d, 0xdd11, 5); /* disable EP4 */ |
| 388 | if (ret) |
| 389 | goto error; |
| 390 | ret = af9015_clear_reg_bit(d, 0xdd11, 6); /* disable EP5 */ |
| 391 | if (ret) |
| 392 | goto error; |
| 393 | ret = af9015_set_reg_bit(d, 0xdd11, 5); /* enable EP4 */ |
| 394 | if (ret) |
| 395 | goto error; |
| 396 | if (af9015_config.dual_mode) { |
| 397 | ret = af9015_set_reg_bit(d, 0xdd11, 6); /* enable EP5 */ |
| 398 | if (ret) |
| 399 | goto error; |
| 400 | } |
| 401 | ret = af9015_clear_reg_bit(d, 0xdd13, 5); /* disable EP4 NAK */ |
| 402 | if (ret) |
| 403 | goto error; |
| 404 | if (af9015_config.dual_mode) { |
| 405 | ret = af9015_clear_reg_bit(d, 0xdd13, 6); /* disable EP5 NAK */ |
| 406 | if (ret) |
| 407 | goto error; |
| 408 | } |
| 409 | /* EP4 xfer length */ |
| 410 | ret = af9015_write_reg(d, 0xdd88, frame_size & 0xff); |
| 411 | if (ret) |
| 412 | goto error; |
| 413 | ret = af9015_write_reg(d, 0xdd89, frame_size >> 8); |
| 414 | if (ret) |
| 415 | goto error; |
| 416 | /* EP5 xfer length */ |
| 417 | ret = af9015_write_reg(d, 0xdd8a, frame_size & 0xff); |
| 418 | if (ret) |
| 419 | goto error; |
| 420 | ret = af9015_write_reg(d, 0xdd8b, frame_size >> 8); |
| 421 | if (ret) |
| 422 | goto error; |
| 423 | ret = af9015_write_reg(d, 0xdd0c, packet_size); /* EP4 packet size */ |
| 424 | if (ret) |
| 425 | goto error; |
| 426 | ret = af9015_write_reg(d, 0xdd0d, packet_size); /* EP5 packet size */ |
| 427 | if (ret) |
| 428 | goto error; |
| 429 | ret = af9015_clear_reg_bit(d, 0xd507, 2); /* negate EP4 reset */ |
| 430 | if (ret) |
| 431 | goto error; |
| 432 | if (af9015_config.dual_mode) { |
| 433 | ret = af9015_clear_reg_bit(d, 0xd50b, 1); /* negate EP5 reset */ |
| 434 | if (ret) |
| 435 | goto error; |
| 436 | } |
| 437 | |
| 438 | /* enable / disable mp2if2 */ |
| 439 | if (af9015_config.dual_mode) |
| 440 | ret = af9015_set_reg_bit(d, 0xd50b, 0); |
| 441 | else |
| 442 | ret = af9015_clear_reg_bit(d, 0xd50b, 0); |
| 443 | error: |
| 444 | if (ret) |
| 445 | err("endpoint init failed:%d", ret); |
| 446 | return ret; |
| 447 | } |
| 448 | |
| 449 | static int af9015_copy_firmware(struct dvb_usb_device *d) |
| 450 | { |
| 451 | int ret; |
| 452 | u8 fw_params[4]; |
| 453 | u8 val, i; |
| 454 | struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params), |
| 455 | fw_params }; |
| 456 | deb_info("%s:\n", __func__); |
| 457 | |
| 458 | fw_params[0] = af9015_config.firmware_size >> 8; |
| 459 | fw_params[1] = af9015_config.firmware_size & 0xff; |
| 460 | fw_params[2] = af9015_config.firmware_checksum >> 8; |
| 461 | fw_params[3] = af9015_config.firmware_checksum & 0xff; |
| 462 | |
| 463 | /* wait 2nd demodulator ready */ |
| 464 | msleep(100); |
| 465 | |
| 466 | ret = af9015_read_reg_i2c(d, 0x3a, 0x98be, &val); |
| 467 | if (ret) |
| 468 | goto error; |
| 469 | else |
| 470 | deb_info("%s: firmware status:%02x\n", __func__, val); |
| 471 | |
| 472 | if (val == 0x0c) /* fw is running, no need for download */ |
| 473 | goto exit; |
| 474 | |
| 475 | /* set I2C master clock to fast (to speed up firmware copy) */ |
| 476 | ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */ |
| 477 | if (ret) |
| 478 | goto error; |
| 479 | |
| 480 | msleep(50); |
| 481 | |
| 482 | /* copy firmware */ |
| 483 | ret = af9015_ctrl_msg(d, &req); |
| 484 | if (ret) |
| 485 | err("firmware copy cmd failed:%d", ret); |
| 486 | deb_info("%s: firmware copy done\n", __func__); |
| 487 | |
| 488 | /* set I2C master clock back to normal */ |
| 489 | ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */ |
| 490 | if (ret) |
| 491 | goto error; |
| 492 | |
| 493 | /* request boot firmware */ |
| 494 | ret = af9015_write_reg_i2c(d, af9015_af9013_config[1].demod_address, |
| 495 | 0xe205, 1); |
| 496 | deb_info("%s: firmware boot cmd status:%d\n", __func__, ret); |
| 497 | if (ret) |
| 498 | goto error; |
| 499 | |
| 500 | for (i = 0; i < 15; i++) { |
| 501 | msleep(100); |
| 502 | |
| 503 | /* check firmware status */ |
| 504 | ret = af9015_read_reg_i2c(d, |
| 505 | af9015_af9013_config[1].demod_address, 0x98be, &val); |
| 506 | deb_info("%s: firmware status cmd status:%d fw status:%02x\n", |
| 507 | __func__, ret, val); |
| 508 | if (ret) |
| 509 | goto error; |
| 510 | |
| 511 | if (val == 0x0c || val == 0x04) /* success or fail */ |
| 512 | break; |
| 513 | } |
| 514 | |
| 515 | if (val == 0x04) { |
| 516 | err("firmware did not run"); |
| 517 | ret = -1; |
| 518 | } else if (val != 0x0c) { |
| 519 | err("firmware boot timeout"); |
| 520 | ret = -1; |
| 521 | } |
| 522 | |
| 523 | error: |
| 524 | exit: |
| 525 | return ret; |
| 526 | } |
| 527 | |
| 528 | /* dump eeprom */ |
| 529 | static int af9015_eeprom_dump(struct dvb_usb_device *d) |
| 530 | { |
| 531 | char buf[52], buf2[4]; |
| 532 | u8 reg, val; |
| 533 | |
| 534 | for (reg = 0; ; reg++) { |
| 535 | if (reg % 16 == 0) { |
| 536 | if (reg) |
| 537 | deb_info("%s\n", buf); |
| 538 | sprintf(buf, "%02x: ", reg); |
| 539 | } |
| 540 | if (af9015_read_reg_i2c(d, AF9015_I2C_EEPROM, reg, &val) == 0) |
| 541 | sprintf(buf2, "%02x ", val); |
| 542 | else |
| 543 | strcpy(buf2, "-- "); |
| 544 | strcat(buf, buf2); |
| 545 | if (reg == 0xff) |
| 546 | break; |
| 547 | } |
| 548 | deb_info("%s\n", buf); |
| 549 | return 0; |
| 550 | } |
| 551 | |
Antti Palosaari | 349d042 | 2008-11-05 16:31:24 -0300 | [diff] [blame] | 552 | static int af9015_download_ir_table(struct dvb_usb_device *d) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 553 | { |
| 554 | int i, packets = 0, ret; |
| 555 | u16 addr = 0x9a56; /* ir-table start address */ |
| 556 | struct req_t req = {WRITE_MEMORY, 0, 0, 0, 0, 1, NULL}; |
| 557 | u8 *data = NULL; |
| 558 | deb_info("%s:\n", __func__); |
| 559 | |
| 560 | data = af9015_config.ir_table; |
| 561 | packets = af9015_config.ir_table_size; |
| 562 | |
| 563 | /* no remote */ |
| 564 | if (!packets) |
| 565 | goto exit; |
| 566 | |
| 567 | /* load remote ir-table */ |
| 568 | for (i = 0; i < packets; i++) { |
| 569 | req.addr = addr + i; |
| 570 | req.data = &data[i]; |
| 571 | ret = af9015_ctrl_msg(d, &req); |
| 572 | if (ret) { |
| 573 | err("ir-table download failed at packet %d with " \ |
| 574 | "code %d", i, ret); |
| 575 | return ret; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | exit: |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | static int af9015_init(struct dvb_usb_device *d) |
| 584 | { |
| 585 | int ret; |
| 586 | deb_info("%s:\n", __func__); |
| 587 | |
| 588 | ret = af9015_init_endpoint(d); |
| 589 | if (ret) |
| 590 | goto error; |
| 591 | |
| 592 | ret = af9015_download_ir_table(d); |
| 593 | if (ret) |
| 594 | goto error; |
| 595 | |
| 596 | error: |
| 597 | return ret; |
| 598 | } |
| 599 | |
| 600 | static int af9015_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 601 | { |
| 602 | int ret; |
| 603 | deb_info("%s: onoff:%d\n", __func__, onoff); |
| 604 | |
| 605 | if (onoff) |
| 606 | ret = af9015_set_reg_bit(adap->dev, 0xd503, 0); |
| 607 | else |
| 608 | ret = af9015_clear_reg_bit(adap->dev, 0xd503, 0); |
| 609 | |
| 610 | return ret; |
| 611 | } |
| 612 | |
| 613 | static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, |
| 614 | int onoff) |
| 615 | { |
| 616 | int ret; |
| 617 | u8 idx; |
| 618 | |
| 619 | deb_info("%s: set pid filter, index %d, pid %x, onoff %d\n", |
| 620 | __func__, index, pid, onoff); |
| 621 | |
| 622 | ret = af9015_write_reg(adap->dev, 0xd505, (pid & 0xff)); |
| 623 | if (ret) |
| 624 | goto error; |
| 625 | |
| 626 | ret = af9015_write_reg(adap->dev, 0xd506, (pid >> 8)); |
| 627 | if (ret) |
| 628 | goto error; |
| 629 | |
| 630 | idx = ((index & 0x1f) | (1 << 5)); |
| 631 | ret = af9015_write_reg(adap->dev, 0xd504, idx); |
| 632 | |
| 633 | error: |
| 634 | return ret; |
| 635 | } |
| 636 | |
| 637 | static int af9015_download_firmware(struct usb_device *udev, |
| 638 | const struct firmware *fw) |
| 639 | { |
| 640 | int i, len, packets, remainder, ret; |
| 641 | struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL}; |
| 642 | u16 addr = 0x5100; /* firmware start address */ |
| 643 | u16 checksum = 0; |
| 644 | |
| 645 | deb_info("%s:\n", __func__); |
| 646 | |
| 647 | /* calc checksum */ |
| 648 | for (i = 0; i < fw->size; i++) |
| 649 | checksum += fw->data[i]; |
| 650 | |
| 651 | af9015_config.firmware_size = fw->size; |
| 652 | af9015_config.firmware_checksum = checksum; |
| 653 | |
| 654 | #define FW_PACKET_MAX_DATA 55 |
| 655 | |
| 656 | packets = fw->size / FW_PACKET_MAX_DATA; |
| 657 | remainder = fw->size % FW_PACKET_MAX_DATA; |
| 658 | len = FW_PACKET_MAX_DATA; |
| 659 | for (i = 0; i <= packets; i++) { |
| 660 | if (i == packets) /* set size of the last packet */ |
| 661 | len = remainder; |
| 662 | |
| 663 | req.data_len = len; |
Antti Palosaari | 541dfa8 | 2008-10-06 13:57:45 -0300 | [diff] [blame] | 664 | req.data = (u8 *)(fw->data + i * FW_PACKET_MAX_DATA); |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 665 | req.addr = addr; |
| 666 | addr += FW_PACKET_MAX_DATA; |
| 667 | |
| 668 | ret = af9015_rw_udev(udev, &req); |
| 669 | if (ret) { |
| 670 | err("firmware download failed at packet %d with " \ |
| 671 | "code %d", i, ret); |
| 672 | goto error; |
| 673 | } |
| 674 | } |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 675 | |
| 676 | /* firmware loaded, request boot */ |
| 677 | req.cmd = BOOT; |
| 678 | ret = af9015_rw_udev(udev, &req); |
| 679 | if (ret) { |
| 680 | err("firmware boot failed:%d", ret); |
| 681 | goto error; |
| 682 | } |
| 683 | |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 684 | error: |
| 685 | return ret; |
| 686 | } |
| 687 | |
| 688 | static int af9015_read_config(struct usb_device *udev) |
| 689 | { |
| 690 | int ret; |
| 691 | u8 val, i, offset = 0; |
| 692 | struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val}; |
| 693 | char manufacturer[10]; |
| 694 | |
| 695 | /* IR remote controller */ |
| 696 | req.addr = AF9015_EEPROM_IR_MODE; |
| 697 | ret = af9015_rw_udev(udev, &req); |
| 698 | if (ret) |
| 699 | goto error; |
| 700 | deb_info("%s: IR mode:%d\n", __func__, val); |
| 701 | for (i = 0; i < af9015_properties_count; i++) { |
| 702 | if (val == AF9015_IR_MODE_DISABLED || val == 0x04) { |
| 703 | af9015_properties[i].rc_key_map = NULL; |
| 704 | af9015_properties[i].rc_key_map_size = 0; |
| 705 | } else if (dvb_usb_af9015_remote) { |
| 706 | /* load remote defined as module param */ |
| 707 | switch (dvb_usb_af9015_remote) { |
| 708 | case AF9015_REMOTE_A_LINK_DTU_M: |
| 709 | af9015_properties[i].rc_key_map = |
| 710 | af9015_rc_keys_a_link; |
| 711 | af9015_properties[i].rc_key_map_size = |
| 712 | ARRAY_SIZE(af9015_rc_keys_a_link); |
| 713 | af9015_config.ir_table = af9015_ir_table_a_link; |
| 714 | af9015_config.ir_table_size = |
| 715 | ARRAY_SIZE(af9015_ir_table_a_link); |
| 716 | break; |
| 717 | case AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3: |
| 718 | af9015_properties[i].rc_key_map = |
| 719 | af9015_rc_keys_msi; |
| 720 | af9015_properties[i].rc_key_map_size = |
| 721 | ARRAY_SIZE(af9015_rc_keys_msi); |
| 722 | af9015_config.ir_table = af9015_ir_table_msi; |
| 723 | af9015_config.ir_table_size = |
| 724 | ARRAY_SIZE(af9015_ir_table_msi); |
| 725 | break; |
| 726 | case AF9015_REMOTE_MYGICTV_U718: |
| 727 | af9015_properties[i].rc_key_map = |
| 728 | af9015_rc_keys_mygictv; |
| 729 | af9015_properties[i].rc_key_map_size = |
| 730 | ARRAY_SIZE(af9015_rc_keys_mygictv); |
| 731 | af9015_config.ir_table = |
| 732 | af9015_ir_table_mygictv; |
| 733 | af9015_config.ir_table_size = |
| 734 | ARRAY_SIZE(af9015_ir_table_mygictv); |
| 735 | break; |
| 736 | } |
| 737 | } else { |
| 738 | switch (udev->descriptor.idVendor) { |
Harvey Harrison | 292ee46 | 2008-11-14 18:19:56 -0300 | [diff] [blame^] | 739 | case cpu_to_le16(USB_VID_LEADTEK): |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 740 | af9015_properties[i].rc_key_map = |
| 741 | af9015_rc_keys_leadtek; |
| 742 | af9015_properties[i].rc_key_map_size = |
| 743 | ARRAY_SIZE(af9015_rc_keys_leadtek); |
| 744 | af9015_config.ir_table = |
| 745 | af9015_ir_table_leadtek; |
| 746 | af9015_config.ir_table_size = |
| 747 | ARRAY_SIZE(af9015_ir_table_leadtek); |
| 748 | break; |
Harvey Harrison | 292ee46 | 2008-11-14 18:19:56 -0300 | [diff] [blame^] | 749 | case cpu_to_le16(USB_VID_VISIONPLUS): |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 750 | if (udev->descriptor.idProduct == |
Harvey Harrison | 292ee46 | 2008-11-14 18:19:56 -0300 | [diff] [blame^] | 751 | cpu_to_le16(USB_PID_AZUREWAVE_AD_TU700)) { |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 752 | af9015_properties[i].rc_key_map = |
| 753 | af9015_rc_keys_twinhan; |
| 754 | af9015_properties[i].rc_key_map_size = |
| 755 | ARRAY_SIZE(af9015_rc_keys_twinhan); |
| 756 | af9015_config.ir_table = |
| 757 | af9015_ir_table_twinhan; |
| 758 | af9015_config.ir_table_size = |
| 759 | ARRAY_SIZE(af9015_ir_table_twinhan); |
| 760 | } |
| 761 | break; |
Harvey Harrison | 292ee46 | 2008-11-14 18:19:56 -0300 | [diff] [blame^] | 762 | case cpu_to_le16(USB_VID_KWORLD_2): |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 763 | /* TODO: use correct rc keys */ |
| 764 | af9015_properties[i].rc_key_map = |
| 765 | af9015_rc_keys_twinhan; |
| 766 | af9015_properties[i].rc_key_map_size = |
| 767 | ARRAY_SIZE(af9015_rc_keys_twinhan); |
| 768 | af9015_config.ir_table = af9015_ir_table_kworld; |
| 769 | af9015_config.ir_table_size = |
| 770 | ARRAY_SIZE(af9015_ir_table_kworld); |
| 771 | break; |
| 772 | /* Check USB manufacturer and product strings and try |
| 773 | to determine correct remote in case of chip vendor |
| 774 | reference IDs are used. */ |
Harvey Harrison | 292ee46 | 2008-11-14 18:19:56 -0300 | [diff] [blame^] | 775 | case cpu_to_le16(USB_VID_AFATECH): |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 776 | memset(manufacturer, 0, sizeof(manufacturer)); |
| 777 | usb_string(udev, udev->descriptor.iManufacturer, |
| 778 | manufacturer, sizeof(manufacturer)); |
| 779 | if (!strcmp("Geniatech", manufacturer)) { |
| 780 | /* iManufacturer 1 Geniatech |
| 781 | iProduct 2 AF9015 */ |
| 782 | af9015_properties[i].rc_key_map = |
| 783 | af9015_rc_keys_mygictv; |
| 784 | af9015_properties[i].rc_key_map_size = |
| 785 | ARRAY_SIZE(af9015_rc_keys_mygictv); |
| 786 | af9015_config.ir_table = |
| 787 | af9015_ir_table_mygictv; |
| 788 | af9015_config.ir_table_size = |
| 789 | ARRAY_SIZE(af9015_ir_table_mygictv); |
| 790 | } else if (!strcmp("MSI", manufacturer)) { |
| 791 | /* iManufacturer 1 MSI |
| 792 | iProduct 2 MSI K-VOX */ |
| 793 | af9015_properties[i].rc_key_map = |
| 794 | af9015_rc_keys_msi; |
| 795 | af9015_properties[i].rc_key_map_size = |
| 796 | ARRAY_SIZE(af9015_rc_keys_msi); |
| 797 | af9015_config.ir_table = |
| 798 | af9015_ir_table_msi; |
| 799 | af9015_config.ir_table_size = |
| 800 | ARRAY_SIZE(af9015_ir_table_msi); |
| 801 | } |
| 802 | break; |
Harvey Harrison | 292ee46 | 2008-11-14 18:19:56 -0300 | [diff] [blame^] | 803 | case cpu_to_le16(USB_VID_AVERMEDIA): |
Jose Alberto Reguero | c78de71 | 2008-11-04 11:38:01 -0300 | [diff] [blame] | 804 | af9015_properties[i].rc_key_map = |
| 805 | af9015_rc_keys_avermedia; |
| 806 | af9015_properties[i].rc_key_map_size = |
| 807 | ARRAY_SIZE(af9015_rc_keys_avermedia); |
| 808 | af9015_config.ir_table = |
| 809 | af9015_ir_table_avermedia; |
| 810 | af9015_config.ir_table_size = |
| 811 | ARRAY_SIZE(af9015_ir_table_avermedia); |
| 812 | break; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | /* TS mode - one or two receivers */ |
| 818 | req.addr = AF9015_EEPROM_TS_MODE; |
| 819 | ret = af9015_rw_udev(udev, &req); |
| 820 | if (ret) |
| 821 | goto error; |
| 822 | af9015_config.dual_mode = val; |
| 823 | deb_info("%s: TS mode:%d\n", __func__, af9015_config.dual_mode); |
| 824 | /* disable dual mode by default because it is buggy */ |
| 825 | if (!dvb_usb_af9015_dual_mode) |
| 826 | af9015_config.dual_mode = 0; |
| 827 | |
| 828 | /* set buffer size according to USB port speed */ |
| 829 | for (i = 0; i < af9015_properties_count; i++) { |
| 830 | /* USB1.1 set smaller buffersize and disable 2nd adapter */ |
| 831 | if (udev->speed == USB_SPEED_FULL) { |
| 832 | af9015_properties[i].adapter->stream.u.bulk.buffersize = |
| 833 | TS_USB11_MAX_PACKET_SIZE; |
| 834 | /* disable 2nd adapter because we don't have |
| 835 | PID-filters */ |
| 836 | af9015_config.dual_mode = 0; |
| 837 | } else { |
| 838 | af9015_properties[i].adapter->stream.u.bulk.buffersize = |
| 839 | TS_USB20_MAX_PACKET_SIZE; |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | if (af9015_config.dual_mode) { |
| 844 | /* read 2nd demodulator I2C address */ |
| 845 | req.addr = AF9015_EEPROM_DEMOD2_I2C; |
| 846 | ret = af9015_rw_udev(udev, &req); |
| 847 | if (ret) |
| 848 | goto error; |
| 849 | af9015_af9013_config[1].demod_address = val; |
| 850 | |
| 851 | /* enable 2nd adapter */ |
| 852 | for (i = 0; i < af9015_properties_count; i++) |
| 853 | af9015_properties[i].num_adapters = 2; |
| 854 | |
| 855 | } else { |
| 856 | /* disable 2nd adapter */ |
| 857 | for (i = 0; i < af9015_properties_count; i++) |
| 858 | af9015_properties[i].num_adapters = 1; |
| 859 | } |
| 860 | |
| 861 | for (i = 0; i < af9015_properties[0].num_adapters; i++) { |
| 862 | if (i == 1) |
| 863 | offset = AF9015_EEPROM_OFFSET; |
| 864 | /* xtal */ |
| 865 | req.addr = AF9015_EEPROM_XTAL_TYPE1 + offset; |
| 866 | ret = af9015_rw_udev(udev, &req); |
| 867 | if (ret) |
| 868 | goto error; |
| 869 | switch (val) { |
| 870 | case 0: |
| 871 | af9015_af9013_config[i].adc_clock = 28800; |
| 872 | break; |
| 873 | case 1: |
| 874 | af9015_af9013_config[i].adc_clock = 20480; |
| 875 | break; |
| 876 | case 2: |
| 877 | af9015_af9013_config[i].adc_clock = 28000; |
| 878 | break; |
| 879 | case 3: |
| 880 | af9015_af9013_config[i].adc_clock = 25000; |
| 881 | break; |
| 882 | }; |
| 883 | deb_info("%s: [%d] xtal:%d set adc_clock:%d\n", __func__, i, |
| 884 | val, af9015_af9013_config[i].adc_clock); |
| 885 | |
| 886 | /* tuner IF */ |
| 887 | req.addr = AF9015_EEPROM_IF1H + offset; |
| 888 | ret = af9015_rw_udev(udev, &req); |
| 889 | if (ret) |
| 890 | goto error; |
| 891 | af9015_af9013_config[i].tuner_if = val << 8; |
| 892 | req.addr = AF9015_EEPROM_IF1L + offset; |
| 893 | ret = af9015_rw_udev(udev, &req); |
| 894 | if (ret) |
| 895 | goto error; |
| 896 | af9015_af9013_config[i].tuner_if += val; |
| 897 | deb_info("%s: [%d] IF1:%d\n", __func__, i, |
| 898 | af9015_af9013_config[0].tuner_if); |
| 899 | |
| 900 | /* MT2060 IF1 */ |
| 901 | req.addr = AF9015_EEPROM_MT2060_IF1H + offset; |
| 902 | ret = af9015_rw_udev(udev, &req); |
| 903 | if (ret) |
| 904 | goto error; |
| 905 | af9015_config.mt2060_if1[i] = val << 8; |
| 906 | req.addr = AF9015_EEPROM_MT2060_IF1L + offset; |
| 907 | ret = af9015_rw_udev(udev, &req); |
| 908 | if (ret) |
| 909 | goto error; |
| 910 | af9015_config.mt2060_if1[i] += val; |
| 911 | deb_info("%s: [%d] MT2060 IF1:%d\n", __func__, i, |
| 912 | af9015_config.mt2060_if1[i]); |
| 913 | |
| 914 | /* tuner */ |
| 915 | req.addr = AF9015_EEPROM_TUNER_ID1 + offset; |
| 916 | ret = af9015_rw_udev(udev, &req); |
| 917 | if (ret) |
| 918 | goto error; |
| 919 | switch (val) { |
| 920 | case AF9013_TUNER_ENV77H11D5: |
| 921 | case AF9013_TUNER_MT2060: |
| 922 | case AF9013_TUNER_MC44S803: |
| 923 | case AF9013_TUNER_QT1010: |
| 924 | case AF9013_TUNER_UNKNOWN: |
| 925 | case AF9013_TUNER_MT2060_2: |
| 926 | case AF9013_TUNER_TDA18271: |
| 927 | case AF9013_TUNER_QT1010A: |
| 928 | af9015_af9013_config[i].rf_spec_inv = 1; |
| 929 | break; |
| 930 | case AF9013_TUNER_MXL5003D: |
| 931 | case AF9013_TUNER_MXL5005D: |
| 932 | case AF9013_TUNER_MXL5005R: |
| 933 | af9015_af9013_config[i].rf_spec_inv = 0; |
| 934 | break; |
| 935 | default: |
| 936 | warn("tuner id:%d not supported, please report!", val); |
| 937 | return -ENODEV; |
| 938 | }; |
| 939 | |
| 940 | af9015_af9013_config[i].tuner = val; |
| 941 | deb_info("%s: [%d] tuner id:%d\n", __func__, i, val); |
| 942 | } |
| 943 | |
| 944 | error: |
| 945 | if (ret) |
| 946 | err("eeprom read failed:%d", ret); |
| 947 | |
| 948 | return ret; |
| 949 | } |
| 950 | |
| 951 | static int af9015_identify_state(struct usb_device *udev, |
| 952 | struct dvb_usb_device_properties *props, |
| 953 | struct dvb_usb_device_description **desc, |
| 954 | int *cold) |
| 955 | { |
| 956 | int ret; |
| 957 | u8 reply; |
| 958 | struct req_t req = {GET_CONFIG, 0, 0, 0, 0, 1, &reply}; |
| 959 | |
| 960 | ret = af9015_rw_udev(udev, &req); |
| 961 | if (ret) |
| 962 | return ret; |
| 963 | |
| 964 | deb_info("%s: reply:%02x\n", __func__, reply); |
| 965 | if (reply == 0x02) |
| 966 | *cold = 0; |
| 967 | else |
| 968 | *cold = 1; |
| 969 | |
| 970 | return ret; |
| 971 | } |
| 972 | |
| 973 | static int af9015_rc_query(struct dvb_usb_device *d, u32 *event, int *state) |
| 974 | { |
| 975 | u8 buf[8]; |
| 976 | struct req_t req = {GET_IR_CODE, 0, 0, 0, 0, sizeof(buf), buf}; |
| 977 | struct dvb_usb_rc_key *keymap = d->props.rc_key_map; |
| 978 | int i, ret; |
| 979 | |
| 980 | memset(buf, 0, sizeof(buf)); |
| 981 | |
| 982 | ret = af9015_ctrl_msg(d, &req); |
| 983 | if (ret) |
| 984 | return ret; |
| 985 | |
| 986 | *event = 0; |
| 987 | *state = REMOTE_NO_KEY_PRESSED; |
| 988 | |
| 989 | for (i = 0; i < d->props.rc_key_map_size; i++) { |
| 990 | if (!buf[1] && keymap[i].custom == buf[0] && |
| 991 | keymap[i].data == buf[2]) { |
| 992 | *event = keymap[i].event; |
| 993 | *state = REMOTE_KEY_PRESSED; |
| 994 | break; |
| 995 | } |
| 996 | } |
| 997 | if (!buf[1]) |
| 998 | deb_rc("%s: %02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 999 | __func__, buf[0], buf[1], buf[2], buf[3], buf[4], |
| 1000 | buf[5], buf[6], buf[7]); |
| 1001 | |
| 1002 | return 0; |
| 1003 | } |
| 1004 | |
| 1005 | /* init 2nd I2C adapter */ |
Antti Palosaari | 349d042 | 2008-11-05 16:31:24 -0300 | [diff] [blame] | 1006 | static int af9015_i2c_init(struct dvb_usb_device *d) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1007 | { |
| 1008 | int ret; |
| 1009 | struct af9015_state *state = d->priv; |
| 1010 | deb_info("%s:\n", __func__); |
| 1011 | |
| 1012 | strncpy(state->i2c_adap.name, d->desc->name, |
| 1013 | sizeof(state->i2c_adap.name)); |
| 1014 | #ifdef I2C_ADAP_CLASS_TV_DIGITAL |
| 1015 | state->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL, |
| 1016 | #else |
| 1017 | state->i2c_adap.class = I2C_CLASS_TV_DIGITAL, |
| 1018 | #endif |
| 1019 | state->i2c_adap.algo = d->props.i2c_algo; |
| 1020 | state->i2c_adap.algo_data = NULL; |
| 1021 | state->i2c_adap.dev.parent = &d->udev->dev; |
| 1022 | |
| 1023 | i2c_set_adapdata(&state->i2c_adap, d); |
| 1024 | |
| 1025 | ret = i2c_add_adapter(&state->i2c_adap); |
| 1026 | if (ret < 0) |
| 1027 | err("could not add i2c adapter"); |
| 1028 | |
| 1029 | return ret; |
| 1030 | } |
| 1031 | |
| 1032 | static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap) |
| 1033 | { |
| 1034 | int ret; |
| 1035 | struct af9015_state *state = adap->dev->priv; |
| 1036 | struct i2c_adapter *i2c_adap; |
| 1037 | |
| 1038 | if (adap->id == 0) { |
| 1039 | /* select I2C adapter */ |
| 1040 | i2c_adap = &adap->dev->i2c_adap; |
| 1041 | |
| 1042 | deb_info("%s: init I2C\n", __func__); |
| 1043 | ret = af9015_i2c_init(adap->dev); |
| 1044 | |
| 1045 | /* dump eeprom (debug) */ |
| 1046 | ret = af9015_eeprom_dump(adap->dev); |
| 1047 | if (ret) |
| 1048 | return ret; |
| 1049 | } else { |
| 1050 | /* select I2C adapter */ |
| 1051 | i2c_adap = &state->i2c_adap; |
| 1052 | |
| 1053 | /* copy firmware to 2nd demodulator */ |
| 1054 | if (af9015_config.dual_mode) { |
| 1055 | ret = af9015_copy_firmware(adap->dev); |
| 1056 | if (ret) { |
| 1057 | err("firmware copy to 2nd frontend " \ |
| 1058 | "failed, will disable it"); |
| 1059 | af9015_config.dual_mode = 0; |
| 1060 | return -ENODEV; |
| 1061 | } |
| 1062 | } else { |
| 1063 | return -ENODEV; |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | /* attach demodulator */ |
| 1068 | adap->fe = dvb_attach(af9013_attach, &af9015_af9013_config[adap->id], |
| 1069 | i2c_adap); |
| 1070 | |
| 1071 | return adap->fe == NULL ? -ENODEV : 0; |
| 1072 | } |
| 1073 | |
| 1074 | static struct mt2060_config af9015_mt2060_config = { |
| 1075 | .i2c_address = 0xc0, |
| 1076 | .clock_out = 0, |
| 1077 | }; |
| 1078 | |
| 1079 | static struct qt1010_config af9015_qt1010_config = { |
| 1080 | .i2c_address = 0xc4, |
| 1081 | }; |
| 1082 | |
| 1083 | static struct tda18271_config af9015_tda18271_config = { |
| 1084 | .gate = TDA18271_GATE_DIGITAL, |
| 1085 | .small_i2c = 1, |
| 1086 | }; |
| 1087 | |
| 1088 | static struct mxl5005s_config af9015_mxl5003_config = { |
| 1089 | .i2c_address = 0xc6, |
| 1090 | .if_freq = IF_FREQ_4570000HZ, |
| 1091 | .xtal_freq = CRYSTAL_FREQ_16000000HZ, |
| 1092 | .agc_mode = MXL_SINGLE_AGC, |
| 1093 | .tracking_filter = MXL_TF_DEFAULT, |
Antti Palosaari | a131077 | 2008-09-22 13:59:25 -0300 | [diff] [blame] | 1094 | .rssi_enable = MXL_RSSI_ENABLE, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1095 | .cap_select = MXL_CAP_SEL_ENABLE, |
| 1096 | .div_out = MXL_DIV_OUT_4, |
| 1097 | .clock_out = MXL_CLOCK_OUT_DISABLE, |
| 1098 | .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM, |
| 1099 | .top = MXL5005S_TOP_25P2, |
| 1100 | .mod_mode = MXL_DIGITAL_MODE, |
| 1101 | .if_mode = MXL_ZERO_IF, |
| 1102 | .AgcMasterByte = 0x00, |
| 1103 | }; |
| 1104 | |
| 1105 | static struct mxl5005s_config af9015_mxl5005_config = { |
| 1106 | .i2c_address = 0xc6, |
| 1107 | .if_freq = IF_FREQ_4570000HZ, |
| 1108 | .xtal_freq = CRYSTAL_FREQ_16000000HZ, |
| 1109 | .agc_mode = MXL_SINGLE_AGC, |
| 1110 | .tracking_filter = MXL_TF_OFF, |
Antti Palosaari | a131077 | 2008-09-22 13:59:25 -0300 | [diff] [blame] | 1111 | .rssi_enable = MXL_RSSI_ENABLE, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1112 | .cap_select = MXL_CAP_SEL_ENABLE, |
| 1113 | .div_out = MXL_DIV_OUT_4, |
| 1114 | .clock_out = MXL_CLOCK_OUT_DISABLE, |
| 1115 | .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM, |
| 1116 | .top = MXL5005S_TOP_25P2, |
| 1117 | .mod_mode = MXL_DIGITAL_MODE, |
| 1118 | .if_mode = MXL_ZERO_IF, |
| 1119 | .AgcMasterByte = 0x00, |
| 1120 | }; |
| 1121 | |
| 1122 | static int af9015_tuner_attach(struct dvb_usb_adapter *adap) |
| 1123 | { |
| 1124 | struct af9015_state *state = adap->dev->priv; |
| 1125 | struct i2c_adapter *i2c_adap; |
| 1126 | int ret; |
| 1127 | deb_info("%s: \n", __func__); |
| 1128 | |
| 1129 | /* select I2C adapter */ |
| 1130 | if (adap->id == 0) |
| 1131 | i2c_adap = &adap->dev->i2c_adap; |
| 1132 | else |
| 1133 | i2c_adap = &state->i2c_adap; |
| 1134 | |
| 1135 | switch (af9015_af9013_config[adap->id].tuner) { |
| 1136 | case AF9013_TUNER_MT2060: |
| 1137 | case AF9013_TUNER_MT2060_2: |
| 1138 | ret = dvb_attach(mt2060_attach, adap->fe, i2c_adap, |
| 1139 | &af9015_mt2060_config, |
| 1140 | af9015_config.mt2060_if1[adap->id]) |
| 1141 | == NULL ? -ENODEV : 0; |
| 1142 | break; |
| 1143 | case AF9013_TUNER_QT1010: |
| 1144 | case AF9013_TUNER_QT1010A: |
| 1145 | ret = dvb_attach(qt1010_attach, adap->fe, i2c_adap, |
| 1146 | &af9015_qt1010_config) == NULL ? -ENODEV : 0; |
| 1147 | break; |
| 1148 | case AF9013_TUNER_TDA18271: |
| 1149 | ret = dvb_attach(tda18271_attach, adap->fe, 0xc0, i2c_adap, |
| 1150 | &af9015_tda18271_config) == NULL ? -ENODEV : 0; |
| 1151 | break; |
| 1152 | case AF9013_TUNER_MXL5003D: |
| 1153 | ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap, |
| 1154 | &af9015_mxl5003_config) == NULL ? -ENODEV : 0; |
| 1155 | break; |
| 1156 | case AF9013_TUNER_MXL5005D: |
| 1157 | case AF9013_TUNER_MXL5005R: |
| 1158 | ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap, |
| 1159 | &af9015_mxl5005_config) == NULL ? -ENODEV : 0; |
| 1160 | break; |
| 1161 | case AF9013_TUNER_ENV77H11D5: |
| 1162 | ret = dvb_attach(dvb_pll_attach, adap->fe, 0xc0, i2c_adap, |
| 1163 | DVB_PLL_TDA665X) == NULL ? -ENODEV : 0; |
| 1164 | break; |
| 1165 | case AF9013_TUNER_MC44S803: |
| 1166 | #if 0 |
| 1167 | ret = dvb_attach(mc44s80x_attach, adap->fe, i2c_adap) |
| 1168 | == NULL ? -ENODEV : 0; |
| 1169 | #else |
| 1170 | ret = -ENODEV; |
| 1171 | info("Freescale MC44S803 tuner found but no driver for that" \ |
| 1172 | "tuner. Look at the Linuxtv.org for tuner driver" \ |
| 1173 | "status."); |
| 1174 | #endif |
| 1175 | break; |
| 1176 | case AF9013_TUNER_UNKNOWN: |
| 1177 | default: |
| 1178 | ret = -ENODEV; |
| 1179 | err("Unknown tuner id:%d", |
| 1180 | af9015_af9013_config[adap->id].tuner); |
| 1181 | } |
| 1182 | return ret; |
| 1183 | } |
| 1184 | |
| 1185 | static struct usb_device_id af9015_usb_table[] = { |
| 1186 | /* 0 */{USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9015)}, |
| 1187 | {USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9016)}, |
| 1188 | {USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_GOLD)}, |
| 1189 | {USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV71E)}, |
| 1190 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U)}, |
| 1191 | /* 5 */{USB_DEVICE(USB_VID_VISIONPLUS, |
| 1192 | USB_PID_TINYTWIN)}, |
| 1193 | {USB_DEVICE(USB_VID_VISIONPLUS, |
| 1194 | USB_PID_AZUREWAVE_AD_TU700)}, |
| 1195 | {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2)}, |
| 1196 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_2T)}, |
| 1197 | {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X)}, |
| 1198 | /* 10 */{USB_DEVICE(USB_VID_XTENSIONS, USB_PID_XTENSIONS_XD_380)}, |
| 1199 | {USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGIVOX_DUO)}, |
| 1200 | {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X_2)}, |
Antti Palosaari | a376588 | 2008-09-19 18:34:06 -0300 | [diff] [blame] | 1201 | {USB_DEVICE(USB_VID_TELESTAR, USB_PID_TELESTAR_STARSTICK_2)}, |
Antti Palosaari | 05c1cab | 2008-09-22 12:32:37 -0300 | [diff] [blame] | 1202 | {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A309)}, |
Herbert Graeber | 641015a | 2008-10-07 10:06:36 -0300 | [diff] [blame] | 1203 | /* 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] | 1204 | {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U)}, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1205 | {0}, |
| 1206 | }; |
| 1207 | MODULE_DEVICE_TABLE(usb, af9015_usb_table); |
| 1208 | |
| 1209 | static struct dvb_usb_device_properties af9015_properties[] = { |
| 1210 | { |
| 1211 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 1212 | |
| 1213 | .usb_ctrl = DEVICE_SPECIFIC, |
| 1214 | .download_firmware = af9015_download_firmware, |
| 1215 | .firmware = "dvb-usb-af9015.fw", |
Jose Alberto Reguero | cce2571 | 2008-11-13 14:14:18 -0300 | [diff] [blame] | 1216 | .no_reconnect = 1, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1217 | |
| 1218 | .size_of_priv = sizeof(struct af9015_state), \ |
| 1219 | |
| 1220 | .num_adapters = 2, |
| 1221 | .adapter = { |
| 1222 | { |
| 1223 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | |
| 1224 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, |
| 1225 | |
| 1226 | .pid_filter_count = 32, |
| 1227 | .pid_filter = af9015_pid_filter, |
| 1228 | .pid_filter_ctrl = af9015_pid_filter_ctrl, |
| 1229 | |
| 1230 | .frontend_attach = |
| 1231 | af9015_af9013_frontend_attach, |
| 1232 | .tuner_attach = af9015_tuner_attach, |
| 1233 | .stream = { |
| 1234 | .type = USB_BULK, |
| 1235 | .count = 6, |
| 1236 | .endpoint = 0x84, |
| 1237 | }, |
| 1238 | }, |
| 1239 | { |
| 1240 | .frontend_attach = |
| 1241 | af9015_af9013_frontend_attach, |
| 1242 | .tuner_attach = af9015_tuner_attach, |
| 1243 | .stream = { |
| 1244 | .type = USB_BULK, |
| 1245 | .count = 6, |
| 1246 | .endpoint = 0x85, |
| 1247 | }, |
| 1248 | } |
| 1249 | }, |
| 1250 | |
| 1251 | .identify_state = af9015_identify_state, |
| 1252 | |
| 1253 | .rc_query = af9015_rc_query, |
| 1254 | .rc_interval = 150, |
| 1255 | |
| 1256 | .i2c_algo = &af9015_i2c_algo, |
| 1257 | |
| 1258 | .num_device_descs = 9, |
| 1259 | .devices = { |
| 1260 | { |
| 1261 | .name = "Afatech AF9015 DVB-T USB2.0 stick", |
| 1262 | .cold_ids = {&af9015_usb_table[0], |
| 1263 | &af9015_usb_table[1], NULL}, |
| 1264 | .warm_ids = {NULL}, |
| 1265 | }, |
| 1266 | { |
| 1267 | .name = "Leadtek WinFast DTV Dongle Gold", |
| 1268 | .cold_ids = {&af9015_usb_table[2], NULL}, |
| 1269 | .warm_ids = {NULL}, |
| 1270 | }, |
| 1271 | { |
| 1272 | .name = "Pinnacle PCTV 71e", |
| 1273 | .cold_ids = {&af9015_usb_table[3], NULL}, |
| 1274 | .warm_ids = {NULL}, |
| 1275 | }, |
| 1276 | { |
| 1277 | .name = "KWorld PlusTV Dual DVB-T Stick " \ |
| 1278 | "(DVB-T 399U)", |
| 1279 | .cold_ids = {&af9015_usb_table[4], NULL}, |
| 1280 | .warm_ids = {NULL}, |
| 1281 | }, |
| 1282 | { |
| 1283 | .name = "DigitalNow TinyTwin DVB-T Receiver", |
| 1284 | .cold_ids = {&af9015_usb_table[5], NULL}, |
| 1285 | .warm_ids = {NULL}, |
| 1286 | }, |
| 1287 | { |
| 1288 | .name = "TwinHan AzureWave AD-TU700(704J)", |
| 1289 | .cold_ids = {&af9015_usb_table[6], NULL}, |
| 1290 | .warm_ids = {NULL}, |
| 1291 | }, |
| 1292 | { |
| 1293 | .name = "TerraTec Cinergy T USB XE", |
| 1294 | .cold_ids = {&af9015_usb_table[7], NULL}, |
| 1295 | .warm_ids = {NULL}, |
| 1296 | }, |
| 1297 | { |
| 1298 | .name = "KWorld PlusTV Dual DVB-T PCI " \ |
| 1299 | "(DVB-T PC160-2T)", |
| 1300 | .cold_ids = {&af9015_usb_table[8], NULL}, |
| 1301 | .warm_ids = {NULL}, |
| 1302 | }, |
| 1303 | { |
| 1304 | .name = "AVerMedia AVerTV DVB-T Volar X", |
| 1305 | .cold_ids = {&af9015_usb_table[9], NULL}, |
| 1306 | .warm_ids = {NULL}, |
| 1307 | }, |
| 1308 | } |
| 1309 | }, { |
| 1310 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 1311 | |
| 1312 | .usb_ctrl = DEVICE_SPECIFIC, |
| 1313 | .download_firmware = af9015_download_firmware, |
| 1314 | .firmware = "dvb-usb-af9015.fw", |
Jose Alberto Reguero | cce2571 | 2008-11-13 14:14:18 -0300 | [diff] [blame] | 1315 | .no_reconnect = 1, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1316 | |
| 1317 | .size_of_priv = sizeof(struct af9015_state), \ |
| 1318 | |
| 1319 | .num_adapters = 2, |
| 1320 | .adapter = { |
| 1321 | { |
| 1322 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | |
| 1323 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, |
| 1324 | |
| 1325 | .pid_filter_count = 32, |
| 1326 | .pid_filter = af9015_pid_filter, |
| 1327 | .pid_filter_ctrl = af9015_pid_filter_ctrl, |
| 1328 | |
| 1329 | .frontend_attach = |
| 1330 | af9015_af9013_frontend_attach, |
| 1331 | .tuner_attach = af9015_tuner_attach, |
| 1332 | .stream = { |
| 1333 | .type = USB_BULK, |
| 1334 | .count = 6, |
| 1335 | .endpoint = 0x84, |
| 1336 | }, |
| 1337 | }, |
| 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 = 0x85, |
| 1346 | }, |
| 1347 | } |
| 1348 | }, |
| 1349 | |
| 1350 | .identify_state = af9015_identify_state, |
| 1351 | |
| 1352 | .rc_query = af9015_rc_query, |
| 1353 | .rc_interval = 150, |
| 1354 | |
| 1355 | .i2c_algo = &af9015_i2c_algo, |
| 1356 | |
Antti Palosaari | 163e9cd | 2008-11-04 12:57:47 -0300 | [diff] [blame] | 1357 | .num_device_descs = 7, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1358 | .devices = { |
| 1359 | { |
| 1360 | .name = "Xtensions XD-380", |
| 1361 | .cold_ids = {&af9015_usb_table[10], NULL}, |
| 1362 | .warm_ids = {NULL}, |
| 1363 | }, |
| 1364 | { |
| 1365 | .name = "MSI DIGIVOX Duo", |
| 1366 | .cold_ids = {&af9015_usb_table[11], NULL}, |
| 1367 | .warm_ids = {NULL}, |
| 1368 | }, |
| 1369 | { |
| 1370 | .name = "Fujitsu-Siemens Slim Mobile USB DVB-T", |
| 1371 | .cold_ids = {&af9015_usb_table[12], NULL}, |
| 1372 | .warm_ids = {NULL}, |
| 1373 | }, |
Mikko Ohtamaa | 111f9ec | 2008-09-19 18:26:05 -0300 | [diff] [blame] | 1374 | { |
Antti Palosaari | a376588 | 2008-09-19 18:34:06 -0300 | [diff] [blame] | 1375 | .name = "Telestar Starstick 2", |
Mikko Ohtamaa | 111f9ec | 2008-09-19 18:26:05 -0300 | [diff] [blame] | 1376 | .cold_ids = {&af9015_usb_table[13], NULL}, |
| 1377 | .warm_ids = {NULL}, |
| 1378 | }, |
Antti Palosaari | 05c1cab | 2008-09-22 12:32:37 -0300 | [diff] [blame] | 1379 | { |
| 1380 | .name = "AVerMedia A309", |
| 1381 | .cold_ids = {&af9015_usb_table[14], NULL}, |
| 1382 | .warm_ids = {NULL}, |
| 1383 | }, |
Herbert Graeber | 641015a | 2008-10-07 10:06:36 -0300 | [diff] [blame] | 1384 | { |
| 1385 | .name = "MSI Digi VOX mini III", |
| 1386 | .cold_ids = {&af9015_usb_table[15], NULL}, |
| 1387 | .warm_ids = {NULL}, |
| 1388 | }, |
Antti Palosaari | 163e9cd | 2008-11-04 12:57:47 -0300 | [diff] [blame] | 1389 | { |
| 1390 | .name = "KWorld USB DVB-T TV Stick II " \ |
| 1391 | "(VS-DVB-T 395U)", |
| 1392 | .cold_ids = {&af9015_usb_table[16], NULL}, |
| 1393 | .warm_ids = {NULL}, |
| 1394 | }, |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | }; |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1398 | |
| 1399 | static int af9015_usb_probe(struct usb_interface *intf, |
| 1400 | const struct usb_device_id *id) |
| 1401 | { |
| 1402 | int ret = 0; |
| 1403 | struct dvb_usb_device *d = NULL; |
| 1404 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1405 | u8 i; |
| 1406 | |
| 1407 | deb_info("%s: interface:%d\n", __func__, |
| 1408 | intf->cur_altsetting->desc.bInterfaceNumber); |
| 1409 | |
| 1410 | /* interface 0 is used by DVB-T receiver and |
| 1411 | interface 1 is for remote controller (HID) */ |
| 1412 | if (intf->cur_altsetting->desc.bInterfaceNumber == 0) { |
| 1413 | ret = af9015_read_config(udev); |
| 1414 | if (ret) |
| 1415 | return ret; |
| 1416 | |
| 1417 | for (i = 0; i < af9015_properties_count; i++) { |
| 1418 | ret = dvb_usb_device_init(intf, &af9015_properties[i], |
| 1419 | THIS_MODULE, &d, adapter_nr); |
| 1420 | if (!ret) |
| 1421 | break; |
| 1422 | if (ret != -ENODEV) |
| 1423 | return ret; |
| 1424 | } |
| 1425 | if (ret) |
| 1426 | return ret; |
| 1427 | |
| 1428 | if (d) |
| 1429 | ret = af9015_init(d); |
| 1430 | } |
| 1431 | |
| 1432 | return ret; |
| 1433 | } |
| 1434 | |
Antti Palosaari | 349d042 | 2008-11-05 16:31:24 -0300 | [diff] [blame] | 1435 | static void af9015_i2c_exit(struct dvb_usb_device *d) |
Antti Palosaari | 80619de | 2008-09-15 17:18:09 -0300 | [diff] [blame] | 1436 | { |
| 1437 | struct af9015_state *state = d->priv; |
| 1438 | deb_info("%s: \n", __func__); |
| 1439 | |
| 1440 | /* remove 2nd I2C adapter */ |
| 1441 | if (d->state & DVB_USB_STATE_I2C) |
| 1442 | i2c_del_adapter(&state->i2c_adap); |
| 1443 | } |
| 1444 | |
| 1445 | static void af9015_usb_device_exit(struct usb_interface *intf) |
| 1446 | { |
| 1447 | struct dvb_usb_device *d = usb_get_intfdata(intf); |
| 1448 | deb_info("%s: \n", __func__); |
| 1449 | |
| 1450 | /* remove 2nd I2C adapter */ |
| 1451 | if (d != NULL && d->desc != NULL) |
| 1452 | af9015_i2c_exit(d); |
| 1453 | |
| 1454 | dvb_usb_device_exit(intf); |
| 1455 | } |
| 1456 | |
| 1457 | /* usb specific object needed to register this driver with the usb subsystem */ |
| 1458 | static struct usb_driver af9015_usb_driver = { |
| 1459 | .name = "dvb_usb_af9015", |
| 1460 | .probe = af9015_usb_probe, |
| 1461 | .disconnect = af9015_usb_device_exit, |
| 1462 | .id_table = af9015_usb_table, |
| 1463 | }; |
| 1464 | |
| 1465 | /* module stuff */ |
| 1466 | static int __init af9015_usb_module_init(void) |
| 1467 | { |
| 1468 | int ret; |
| 1469 | ret = usb_register(&af9015_usb_driver); |
| 1470 | if (ret) |
| 1471 | err("module init failed:%d", ret); |
| 1472 | |
| 1473 | return ret; |
| 1474 | } |
| 1475 | |
| 1476 | static void __exit af9015_usb_module_exit(void) |
| 1477 | { |
| 1478 | /* deregister this driver from the USB subsystem */ |
| 1479 | usb_deregister(&af9015_usb_driver); |
| 1480 | } |
| 1481 | |
| 1482 | module_init(af9015_usb_module_init); |
| 1483 | module_exit(af9015_usb_module_exit); |
| 1484 | |
| 1485 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 1486 | MODULE_DESCRIPTION("Driver for Afatech AF9015 DVB-T"); |
| 1487 | MODULE_LICENSE("GPL"); |