Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Afatech AF9035 DVB USB driver |
| 3 | * |
| 4 | * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> |
| 5 | * Copyright (C) 2012 Antti Palosaari <crope@iki.fi> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | */ |
| 21 | |
| 22 | #include "af9035.h" |
| 23 | #include "af9033.h" |
| 24 | #include "tua9001.h" |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 25 | #include "fc0011.h" |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame^] | 26 | #include "mxl5007t.h" |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 27 | |
| 28 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 29 | static DEFINE_MUTEX(af9035_usb_mutex); |
| 30 | static struct config af9035_config; |
| 31 | static struct dvb_usb_device_properties af9035_properties[1]; |
| 32 | static int af9035_properties_count = ARRAY_SIZE(af9035_properties); |
| 33 | static struct af9033_config af9035_af9033_config[] = { |
| 34 | { |
| 35 | .ts_mode = AF9033_TS_MODE_USB, |
| 36 | }, { |
| 37 | .ts_mode = AF9033_TS_MODE_SERIAL, |
| 38 | } |
| 39 | }; |
| 40 | |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 41 | static u16 af9035_checksum(const u8 *buf, size_t len) |
| 42 | { |
| 43 | size_t i; |
| 44 | u16 checksum = 0; |
| 45 | |
| 46 | for (i = 1; i < len; i++) { |
| 47 | if (i % 2) |
| 48 | checksum += buf[i] << 8; |
| 49 | else |
| 50 | checksum += buf[i]; |
| 51 | } |
| 52 | checksum = ~checksum; |
| 53 | |
| 54 | return checksum; |
| 55 | } |
| 56 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 57 | static int af9035_ctrl_msg(struct usb_device *udev, struct usb_req *req) |
| 58 | { |
| 59 | #define BUF_LEN 63 |
| 60 | #define REQ_HDR_LEN 4 /* send header size */ |
| 61 | #define ACK_HDR_LEN 3 /* rece header size */ |
| 62 | #define CHECKSUM_LEN 2 |
| 63 | #define USB_TIMEOUT 2000 |
| 64 | |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 65 | int ret, act_len; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 66 | u8 buf[BUF_LEN]; |
| 67 | u32 msg_len; |
| 68 | static u8 seq; /* packet sequence number */ |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 69 | u16 checksum, tmpsum; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 70 | |
| 71 | /* buffer overflow check */ |
| 72 | if (req->wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) || |
| 73 | req->rlen > (BUF_LEN - ACK_HDR_LEN - CHECKSUM_LEN)) { |
| 74 | pr_debug("%s: too much data wlen=%d rlen=%d\n", __func__, |
| 75 | req->wlen, req->rlen); |
| 76 | return -EINVAL; |
| 77 | } |
| 78 | |
| 79 | if (mutex_lock_interruptible(&af9035_usb_mutex) < 0) |
| 80 | return -EAGAIN; |
| 81 | |
| 82 | buf[0] = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN - 1; |
| 83 | buf[1] = req->mbox; |
| 84 | buf[2] = req->cmd; |
| 85 | buf[3] = seq++; |
| 86 | if (req->wlen) |
| 87 | memcpy(&buf[4], req->wbuf, req->wlen); |
| 88 | |
| 89 | /* calc and add checksum */ |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 90 | checksum = af9035_checksum(buf, buf[0] - 1); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 91 | buf[buf[0]-1] = (checksum >> 8); |
| 92 | buf[buf[0]-0] = (checksum & 0xff); |
| 93 | |
| 94 | msg_len = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN ; |
| 95 | |
| 96 | /* send req */ |
| 97 | ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x02), buf, msg_len, |
| 98 | &act_len, USB_TIMEOUT); |
| 99 | if (ret < 0) |
| 100 | err("bulk message failed=%d (%d/%d)", ret, msg_len, act_len); |
| 101 | else |
| 102 | if (act_len != msg_len) |
| 103 | ret = -EIO; /* all data is not send */ |
| 104 | if (ret < 0) |
| 105 | goto err_mutex_unlock; |
| 106 | |
| 107 | /* no ack for those packets */ |
| 108 | if (req->cmd == CMD_FW_DL) |
| 109 | goto exit_mutex_unlock; |
| 110 | |
| 111 | /* receive ack and data if read req */ |
| 112 | msg_len = ACK_HDR_LEN + req->rlen + CHECKSUM_LEN; |
| 113 | ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, 0x81), buf, msg_len, |
| 114 | &act_len, USB_TIMEOUT); |
| 115 | if (ret < 0) { |
| 116 | err("recv bulk message failed=%d", ret); |
| 117 | ret = -EIO; |
| 118 | goto err_mutex_unlock; |
| 119 | } |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 120 | if (act_len != msg_len) { |
| 121 | err("recv bulk message truncated (%d != %u)\n", |
| 122 | act_len, (unsigned int)msg_len); |
| 123 | ret = -EIO; |
| 124 | goto err_mutex_unlock; |
| 125 | } |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 126 | |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 127 | /* verify checksum */ |
| 128 | checksum = af9035_checksum(buf, act_len - 2); |
| 129 | tmpsum = (buf[act_len - 2] << 8) | buf[act_len - 1]; |
| 130 | if (tmpsum != checksum) { |
| 131 | err("%s: command=%02X checksum mismatch (%04X != %04X)\n", |
| 132 | __func__, req->cmd, |
| 133 | (unsigned int)tmpsum, (unsigned int)checksum); |
| 134 | ret = -EIO; |
| 135 | goto err_mutex_unlock; |
| 136 | } |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 137 | /* check status */ |
| 138 | if (buf[2]) { |
| 139 | pr_debug("%s: command=%02x failed fw error=%d\n", __func__, |
| 140 | req->cmd, buf[2]); |
| 141 | ret = -EIO; |
| 142 | goto err_mutex_unlock; |
| 143 | } |
| 144 | |
| 145 | /* read request, copy returned data to return buf */ |
| 146 | if (req->rlen) |
| 147 | memcpy(req->rbuf, &buf[ACK_HDR_LEN], req->rlen); |
| 148 | |
| 149 | err_mutex_unlock: |
| 150 | exit_mutex_unlock: |
| 151 | mutex_unlock(&af9035_usb_mutex); |
| 152 | |
| 153 | return ret; |
| 154 | } |
| 155 | |
| 156 | /* write multiple registers */ |
| 157 | static int af9035_wr_regs(struct dvb_usb_device *d, u32 reg, u8 *val, int len) |
| 158 | { |
| 159 | u8 wbuf[6 + len]; |
| 160 | u8 mbox = (reg >> 16) & 0xff; |
| 161 | struct usb_req req = { CMD_MEM_WR, mbox, sizeof(wbuf), wbuf, 0, NULL }; |
| 162 | |
| 163 | wbuf[0] = len; |
| 164 | wbuf[1] = 2; |
| 165 | wbuf[2] = 0; |
| 166 | wbuf[3] = 0; |
| 167 | wbuf[4] = (reg >> 8) & 0xff; |
| 168 | wbuf[5] = (reg >> 0) & 0xff; |
| 169 | memcpy(&wbuf[6], val, len); |
| 170 | |
| 171 | return af9035_ctrl_msg(d->udev, &req); |
| 172 | } |
| 173 | |
| 174 | /* read multiple registers */ |
| 175 | static int af9035_rd_regs(struct dvb_usb_device *d, u32 reg, u8 *val, int len) |
| 176 | { |
| 177 | u8 wbuf[] = { len, 2, 0, 0, (reg >> 8) & 0xff, reg & 0xff }; |
| 178 | u8 mbox = (reg >> 16) & 0xff; |
| 179 | struct usb_req req = { CMD_MEM_RD, mbox, sizeof(wbuf), wbuf, len, val }; |
| 180 | |
| 181 | return af9035_ctrl_msg(d->udev, &req); |
| 182 | } |
| 183 | |
| 184 | /* write single register */ |
| 185 | static int af9035_wr_reg(struct dvb_usb_device *d, u32 reg, u8 val) |
| 186 | { |
| 187 | return af9035_wr_regs(d, reg, &val, 1); |
| 188 | } |
| 189 | |
| 190 | /* read single register */ |
| 191 | static int af9035_rd_reg(struct dvb_usb_device *d, u32 reg, u8 *val) |
| 192 | { |
| 193 | return af9035_rd_regs(d, reg, val, 1); |
| 194 | } |
| 195 | |
| 196 | /* write single register with mask */ |
| 197 | static int af9035_wr_reg_mask(struct dvb_usb_device *d, u32 reg, u8 val, |
| 198 | u8 mask) |
| 199 | { |
| 200 | int ret; |
| 201 | u8 tmp; |
| 202 | |
| 203 | /* no need for read if whole reg is written */ |
| 204 | if (mask != 0xff) { |
| 205 | ret = af9035_rd_regs(d, reg, &tmp, 1); |
| 206 | if (ret) |
| 207 | return ret; |
| 208 | |
| 209 | val &= mask; |
| 210 | tmp &= ~mask; |
| 211 | val |= tmp; |
| 212 | } |
| 213 | |
| 214 | return af9035_wr_regs(d, reg, &val, 1); |
| 215 | } |
| 216 | |
| 217 | static int af9035_i2c_master_xfer(struct i2c_adapter *adap, |
| 218 | struct i2c_msg msg[], int num) |
| 219 | { |
| 220 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 221 | int ret; |
| 222 | |
| 223 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 224 | return -EAGAIN; |
| 225 | |
| 226 | if (num == 2 && !(msg[0].flags & I2C_M_RD) && |
| 227 | (msg[1].flags & I2C_M_RD)) { |
| 228 | if (msg[0].len > 40 || msg[1].len > 40) { |
| 229 | /* TODO: correct limits > 40 */ |
| 230 | ret = -EOPNOTSUPP; |
| 231 | } else if (msg[0].addr == af9035_af9033_config[0].i2c_addr) { |
| 232 | /* integrated demod */ |
| 233 | u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | |
| 234 | msg[0].buf[2]; |
| 235 | ret = af9035_rd_regs(d, reg, &msg[1].buf[0], |
| 236 | msg[1].len); |
| 237 | } else { |
| 238 | /* I2C */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 239 | u8 buf[4 + msg[0].len]; |
| 240 | struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf), |
| 241 | buf, msg[1].len, msg[1].buf }; |
Hans-Frieder Vogt | 812fe6d | 2012-04-01 14:11:29 -0300 | [diff] [blame] | 242 | buf[0] = msg[1].len; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 243 | buf[1] = msg[0].addr << 1; |
| 244 | buf[2] = 0x01; |
| 245 | buf[3] = 0x00; |
| 246 | memcpy(&buf[4], msg[0].buf, msg[0].len); |
| 247 | ret = af9035_ctrl_msg(d->udev, &req); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 248 | } |
| 249 | } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) { |
| 250 | if (msg[0].len > 40) { |
| 251 | /* TODO: correct limits > 40 */ |
| 252 | ret = -EOPNOTSUPP; |
| 253 | } else if (msg[0].addr == af9035_af9033_config[0].i2c_addr) { |
| 254 | /* integrated demod */ |
| 255 | u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | |
| 256 | msg[0].buf[2]; |
| 257 | ret = af9035_wr_regs(d, reg, &msg[0].buf[3], |
| 258 | msg[0].len - 3); |
| 259 | } else { |
| 260 | /* I2C */ |
| 261 | u8 buf[4 + msg[0].len]; |
| 262 | struct usb_req req = { CMD_I2C_WR, 0, sizeof(buf), buf, |
| 263 | 0, NULL }; |
| 264 | buf[0] = msg[0].len; |
| 265 | buf[1] = msg[0].addr << 1; |
| 266 | buf[2] = 0x01; |
| 267 | buf[3] = 0x00; |
| 268 | memcpy(&buf[4], msg[0].buf, msg[0].len); |
| 269 | ret = af9035_ctrl_msg(d->udev, &req); |
| 270 | } |
| 271 | } else { |
| 272 | /* |
| 273 | * We support only two kind of I2C transactions: |
| 274 | * 1) 1 x read + 1 x write |
| 275 | * 2) 1 x write |
| 276 | */ |
| 277 | ret = -EOPNOTSUPP; |
| 278 | } |
| 279 | |
| 280 | mutex_unlock(&d->i2c_mutex); |
| 281 | |
| 282 | if (ret < 0) |
| 283 | return ret; |
| 284 | else |
| 285 | return num; |
| 286 | } |
| 287 | |
| 288 | static u32 af9035_i2c_functionality(struct i2c_adapter *adapter) |
| 289 | { |
| 290 | return I2C_FUNC_I2C; |
| 291 | } |
| 292 | |
| 293 | static struct i2c_algorithm af9035_i2c_algo = { |
| 294 | .master_xfer = af9035_i2c_master_xfer, |
| 295 | .functionality = af9035_i2c_functionality, |
| 296 | }; |
| 297 | |
| 298 | static int af9035_init(struct dvb_usb_device *d) |
| 299 | { |
| 300 | int ret, i; |
| 301 | u16 frame_size = 87 * 188 / 4; |
| 302 | u8 packet_size = 512 / 4; |
| 303 | struct reg_val_mask tab[] = { |
| 304 | { 0x80f99d, 0x01, 0x01 }, |
| 305 | { 0x80f9a4, 0x01, 0x01 }, |
| 306 | { 0x00dd11, 0x00, 0x20 }, |
| 307 | { 0x00dd11, 0x00, 0x40 }, |
| 308 | { 0x00dd13, 0x00, 0x20 }, |
| 309 | { 0x00dd13, 0x00, 0x40 }, |
| 310 | { 0x00dd11, 0x20, 0x20 }, |
| 311 | { 0x00dd88, (frame_size >> 0) & 0xff, 0xff}, |
| 312 | { 0x00dd89, (frame_size >> 8) & 0xff, 0xff}, |
| 313 | { 0x00dd0c, packet_size, 0xff}, |
| 314 | { 0x00dd11, af9035_config.dual_mode << 6, 0x40 }, |
| 315 | { 0x00dd8a, (frame_size >> 0) & 0xff, 0xff}, |
| 316 | { 0x00dd8b, (frame_size >> 8) & 0xff, 0xff}, |
| 317 | { 0x00dd0d, packet_size, 0xff }, |
| 318 | { 0x80f9a3, 0x00, 0x01 }, |
| 319 | { 0x80f9cd, 0x00, 0x01 }, |
| 320 | { 0x80f99d, 0x00, 0x01 }, |
| 321 | { 0x80f9a4, 0x00, 0x01 }, |
| 322 | }; |
| 323 | |
| 324 | pr_debug("%s: USB speed=%d frame_size=%04x packet_size=%02x\n", |
| 325 | __func__, d->udev->speed, frame_size, packet_size); |
| 326 | |
| 327 | /* init endpoints */ |
| 328 | for (i = 0; i < ARRAY_SIZE(tab); i++) { |
| 329 | ret = af9035_wr_reg_mask(d, tab[i].reg, tab[i].val, |
| 330 | tab[i].mask); |
| 331 | if (ret < 0) |
| 332 | goto err; |
| 333 | } |
| 334 | |
| 335 | return 0; |
| 336 | |
| 337 | err: |
| 338 | pr_debug("%s: failed=%d\n", __func__, ret); |
| 339 | |
| 340 | return ret; |
| 341 | } |
| 342 | |
| 343 | static int af9035_identify_state(struct usb_device *udev, |
| 344 | struct dvb_usb_device_properties *props, |
| 345 | struct dvb_usb_device_description **desc, |
| 346 | int *cold) |
| 347 | { |
| 348 | int ret; |
| 349 | u8 wbuf[1] = { 1 }; |
| 350 | u8 rbuf[4]; |
| 351 | struct usb_req req = { CMD_FW_QUERYINFO, 0, sizeof(wbuf), wbuf, |
| 352 | sizeof(rbuf), rbuf }; |
| 353 | |
| 354 | ret = af9035_ctrl_msg(udev, &req); |
| 355 | if (ret < 0) |
| 356 | goto err; |
| 357 | |
| 358 | pr_debug("%s: reply=%02x %02x %02x %02x\n", __func__, |
| 359 | rbuf[0], rbuf[1], rbuf[2], rbuf[3]); |
| 360 | if (rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3]) |
| 361 | *cold = 0; |
| 362 | else |
| 363 | *cold = 1; |
| 364 | |
| 365 | return 0; |
| 366 | |
| 367 | err: |
| 368 | pr_debug("%s: failed=%d\n", __func__, ret); |
| 369 | |
| 370 | return ret; |
| 371 | } |
| 372 | |
| 373 | static int af9035_download_firmware(struct usb_device *udev, |
| 374 | const struct firmware *fw) |
| 375 | { |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 376 | int ret, i, j, len; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 377 | u8 wbuf[1]; |
| 378 | u8 rbuf[4]; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 379 | struct usb_req req = { 0, 0, 0, NULL, 0, NULL }; |
| 380 | struct usb_req req_fw_dl = { CMD_FW_DL, 0, 0, wbuf, 0, NULL }; |
| 381 | struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ; |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 382 | u8 hdr_core; |
| 383 | u16 hdr_addr, hdr_data_len, hdr_checksum; |
| 384 | #define MAX_DATA 57 |
| 385 | #define HDR_SIZE 7 |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 386 | |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 387 | /* |
| 388 | * Thanks to Daniel Glöckner <daniel-gl@gmx.net> about that info! |
| 389 | * |
| 390 | * byte 0: MCS 51 core |
| 391 | * There are two inside the AF9035 (1=Link and 2=OFDM) with separate |
| 392 | * address spaces |
| 393 | * byte 1-2: Big endian destination address |
| 394 | * byte 3-4: Big endian number of data bytes following the header |
| 395 | * byte 5-6: Big endian header checksum, apparently ignored by the chip |
| 396 | * Calculated as ~(h[0]*256+h[1]+h[2]*256+h[3]+h[4]*256) |
| 397 | */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 398 | |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 399 | for (i = fw->size; i > HDR_SIZE;) { |
| 400 | hdr_core = fw->data[fw->size - i + 0]; |
| 401 | hdr_addr = fw->data[fw->size - i + 1] << 8; |
| 402 | hdr_addr |= fw->data[fw->size - i + 2] << 0; |
| 403 | hdr_data_len = fw->data[fw->size - i + 3] << 8; |
| 404 | hdr_data_len |= fw->data[fw->size - i + 4] << 0; |
| 405 | hdr_checksum = fw->data[fw->size - i + 5] << 8; |
| 406 | hdr_checksum |= fw->data[fw->size - i + 6] << 0; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 407 | |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 408 | pr_debug("%s: core=%d addr=%04x data_len=%d checksum=%04x\n", |
| 409 | __func__, hdr_core, hdr_addr, hdr_data_len, |
| 410 | hdr_checksum); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 411 | |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 412 | if (((hdr_core != 1) && (hdr_core != 2)) || |
| 413 | (hdr_data_len > i)) { |
| 414 | pr_debug("%s: bad firmware\n", __func__); |
| 415 | break; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 416 | } |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 417 | |
| 418 | /* download begin packet */ |
| 419 | req.cmd = CMD_FW_DL_BEGIN; |
| 420 | ret = af9035_ctrl_msg(udev, &req); |
Antti Palosaari | 41d44a8 | 2012-04-01 11:06:23 -0300 | [diff] [blame] | 421 | if (ret < 0) |
| 422 | goto err; |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 423 | |
| 424 | /* download firmware packet(s) */ |
| 425 | for (j = HDR_SIZE + hdr_data_len; j > 0; j -= MAX_DATA) { |
| 426 | len = j; |
| 427 | if (len > MAX_DATA) |
| 428 | len = MAX_DATA; |
| 429 | req_fw_dl.wlen = len; |
| 430 | req_fw_dl.wbuf = (u8 *) &fw->data[fw->size - i + |
| 431 | HDR_SIZE + hdr_data_len - j]; |
| 432 | ret = af9035_ctrl_msg(udev, &req_fw_dl); |
| 433 | if (ret < 0) |
| 434 | goto err; |
| 435 | } |
| 436 | |
| 437 | /* download end packet */ |
| 438 | req.cmd = CMD_FW_DL_END; |
| 439 | ret = af9035_ctrl_msg(udev, &req); |
| 440 | if (ret < 0) |
| 441 | goto err; |
| 442 | |
| 443 | i -= hdr_data_len + HDR_SIZE; |
| 444 | |
Gianluca Gennari | 6ec12988 | 2012-04-02 20:32:58 -0300 | [diff] [blame] | 445 | pr_debug("%s: data uploaded=%zu\n", __func__, fw->size - i); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /* firmware loaded, request boot */ |
| 449 | req.cmd = CMD_FW_BOOT; |
| 450 | ret = af9035_ctrl_msg(udev, &req); |
| 451 | if (ret < 0) |
| 452 | goto err; |
| 453 | |
| 454 | /* ensure firmware starts */ |
| 455 | wbuf[0] = 1; |
| 456 | ret = af9035_ctrl_msg(udev, &req_fw_ver); |
| 457 | if (ret < 0) |
| 458 | goto err; |
| 459 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 460 | if (!(rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3])) { |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 461 | info("firmware did not run"); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 462 | ret = -ENODEV; |
| 463 | goto err; |
| 464 | } |
| 465 | |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 466 | info("firmware version=%d.%d.%d.%d", rbuf[0], rbuf[1], rbuf[2], |
| 467 | rbuf[3]); |
| 468 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 469 | return 0; |
| 470 | |
| 471 | err: |
| 472 | pr_debug("%s: failed=%d\n", __func__, ret); |
| 473 | |
| 474 | return ret; |
| 475 | } |
| 476 | |
| 477 | /* abuse that callback as there is no better one for reading eeprom */ |
| 478 | static int af9035_read_mac_address(struct dvb_usb_device *d, u8 mac[6]) |
| 479 | { |
| 480 | int ret, i, eeprom_shift = 0; |
| 481 | u8 tmp; |
| 482 | u16 tmp16; |
| 483 | |
| 484 | /* check if there is dual tuners */ |
| 485 | ret = af9035_rd_reg(d, EEPROM_DUAL_MODE, &tmp); |
| 486 | if (ret < 0) |
| 487 | goto err; |
| 488 | |
| 489 | af9035_config.dual_mode = tmp; |
| 490 | pr_debug("%s: dual mode=%d\n", __func__, af9035_config.dual_mode); |
| 491 | |
| 492 | for (i = 0; i < af9035_properties[0].num_adapters; i++) { |
| 493 | /* tuner */ |
| 494 | ret = af9035_rd_reg(d, EEPROM_1_TUNER_ID + eeprom_shift, &tmp); |
| 495 | if (ret < 0) |
| 496 | goto err; |
| 497 | |
| 498 | af9035_af9033_config[i].tuner = tmp; |
| 499 | pr_debug("%s: [%d]tuner=%02x\n", __func__, i, tmp); |
| 500 | |
| 501 | switch (tmp) { |
| 502 | case AF9033_TUNER_TUA9001: |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 503 | case AF9033_TUNER_FC0011: |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame^] | 504 | case AF9033_TUNER_MXL5007T: |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 505 | af9035_af9033_config[i].spec_inv = 1; |
| 506 | break; |
| 507 | default: |
Antti Palosaari | 5a9abae | 2012-03-30 17:15:16 -0300 | [diff] [blame] | 508 | af9035_config.hw_not_supported = true; |
| 509 | warn("tuner ID=%02x not supported, please report!", |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 510 | tmp); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 511 | }; |
| 512 | |
| 513 | /* tuner IF frequency */ |
| 514 | ret = af9035_rd_reg(d, EEPROM_1_IFFREQ_L + eeprom_shift, &tmp); |
| 515 | if (ret < 0) |
| 516 | goto err; |
| 517 | |
| 518 | tmp16 = tmp; |
| 519 | |
| 520 | ret = af9035_rd_reg(d, EEPROM_1_IFFREQ_H + eeprom_shift, &tmp); |
| 521 | if (ret < 0) |
| 522 | goto err; |
| 523 | |
| 524 | tmp16 |= tmp << 8; |
| 525 | |
| 526 | pr_debug("%s: [%d]IF=%d\n", __func__, i, tmp16); |
| 527 | |
| 528 | eeprom_shift = 0x10; /* shift for the 2nd tuner params */ |
| 529 | } |
| 530 | |
| 531 | /* get demod clock */ |
| 532 | ret = af9035_rd_reg(d, 0x00d800, &tmp); |
| 533 | if (ret < 0) |
| 534 | goto err; |
| 535 | |
| 536 | tmp = (tmp >> 0) & 0x0f; |
| 537 | |
| 538 | for (i = 0; i < af9035_properties[0].num_adapters; i++) |
| 539 | af9035_af9033_config[i].clock = clock_lut[tmp]; |
| 540 | |
| 541 | return 0; |
| 542 | |
| 543 | err: |
| 544 | pr_debug("%s: failed=%d\n", __func__, ret); |
| 545 | |
| 546 | return ret; |
| 547 | } |
| 548 | |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 549 | static int af9035_fc0011_tuner_callback(struct dvb_usb_device *d, |
| 550 | int cmd, int arg) |
| 551 | { |
| 552 | int err; |
| 553 | |
| 554 | switch (cmd) { |
| 555 | case FC0011_FE_CALLBACK_POWER: |
| 556 | /* Tuner enable */ |
| 557 | err = af9035_wr_reg_mask(d, 0xd8eb, 1, 1); |
| 558 | if (err) |
| 559 | return err; |
| 560 | err = af9035_wr_reg_mask(d, 0xd8ec, 1, 1); |
| 561 | if (err) |
| 562 | return err; |
| 563 | err = af9035_wr_reg_mask(d, 0xd8ed, 1, 1); |
| 564 | if (err) |
| 565 | return err; |
| 566 | /* LED */ |
| 567 | err = af9035_wr_reg_mask(d, 0xd8d0, 1, 1); |
| 568 | if (err) |
| 569 | return err; |
| 570 | err = af9035_wr_reg_mask(d, 0xd8d1, 1, 1); |
| 571 | if (err) |
| 572 | return err; |
| 573 | msleep(10); |
| 574 | break; |
| 575 | case FC0011_FE_CALLBACK_RESET: |
| 576 | err = af9035_wr_reg(d, 0xd8e9, 1); |
| 577 | if (err) |
| 578 | return err; |
| 579 | err = af9035_wr_reg(d, 0xd8e8, 1); |
| 580 | if (err) |
| 581 | return err; |
| 582 | err = af9035_wr_reg(d, 0xd8e7, 1); |
| 583 | if (err) |
| 584 | return err; |
| 585 | msleep(10); |
| 586 | err = af9035_wr_reg(d, 0xd8e7, 0); |
| 587 | if (err) |
| 588 | return err; |
| 589 | msleep(10); |
| 590 | break; |
| 591 | default: |
| 592 | return -EINVAL; |
| 593 | } |
| 594 | |
| 595 | return 0; |
| 596 | } |
| 597 | |
| 598 | static int af9035_tuner_callback(struct dvb_usb_device *d, int cmd, int arg) |
| 599 | { |
| 600 | switch (af9035_af9033_config[0].tuner) { |
| 601 | case AF9033_TUNER_FC0011: |
| 602 | return af9035_fc0011_tuner_callback(d, cmd, arg); |
| 603 | default: |
| 604 | break; |
| 605 | } |
| 606 | |
| 607 | return -ENODEV; |
| 608 | } |
| 609 | |
| 610 | static int af9035_frontend_callback(void *adapter_priv, int component, |
| 611 | int cmd, int arg) |
| 612 | { |
| 613 | struct i2c_adapter *adap = adapter_priv; |
| 614 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 615 | |
| 616 | switch (component) { |
| 617 | case DVB_FRONTEND_COMPONENT_TUNER: |
| 618 | return af9035_tuner_callback(d, cmd, arg); |
| 619 | default: |
| 620 | break; |
| 621 | } |
| 622 | |
| 623 | return -EINVAL; |
| 624 | } |
| 625 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 626 | static int af9035_frontend_attach(struct dvb_usb_adapter *adap) |
| 627 | { |
| 628 | int ret; |
| 629 | |
Antti Palosaari | 5a9abae | 2012-03-30 17:15:16 -0300 | [diff] [blame] | 630 | if (af9035_config.hw_not_supported) { |
| 631 | ret = -ENODEV; |
| 632 | goto err; |
| 633 | } |
| 634 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 635 | if (adap->id == 0) { |
| 636 | ret = af9035_wr_reg(adap->dev, 0x00417f, |
| 637 | af9035_af9033_config[1].i2c_addr); |
| 638 | if (ret < 0) |
| 639 | goto err; |
| 640 | |
| 641 | ret = af9035_wr_reg(adap->dev, 0x00d81a, |
| 642 | af9035_config.dual_mode); |
| 643 | if (ret < 0) |
| 644 | goto err; |
| 645 | } |
| 646 | |
| 647 | /* attach demodulator */ |
| 648 | adap->fe_adap[0].fe = dvb_attach(af9033_attach, |
| 649 | &af9035_af9033_config[adap->id], &adap->dev->i2c_adap); |
| 650 | if (adap->fe_adap[0].fe == NULL) { |
| 651 | ret = -ENODEV; |
| 652 | goto err; |
| 653 | } |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 654 | adap->fe_adap[0].fe->callback = af9035_frontend_callback; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 655 | |
| 656 | return 0; |
| 657 | |
| 658 | err: |
| 659 | pr_debug("%s: failed=%d\n", __func__, ret); |
| 660 | |
| 661 | return ret; |
| 662 | } |
| 663 | |
| 664 | static struct tua9001_config af9035_tua9001_config = { |
| 665 | .i2c_addr = 0x60, |
| 666 | }; |
| 667 | |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 668 | static const struct fc0011_config af9035_fc0011_config = { |
| 669 | .i2c_address = 0x60, |
| 670 | }; |
| 671 | |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame^] | 672 | static struct mxl5007t_config af9035_mxl5007t_config = { |
| 673 | .xtal_freq_hz = MxL_XTAL_24_MHZ, |
| 674 | .if_freq_hz = MxL_IF_4_57_MHZ, |
| 675 | .invert_if = 0, |
| 676 | .loop_thru_enable = 0, |
| 677 | .clk_out_enable = 0, |
| 678 | .clk_out_amp = MxL_CLKOUT_AMP_0_94V, |
| 679 | }; |
| 680 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 681 | static int af9035_tuner_attach(struct dvb_usb_adapter *adap) |
| 682 | { |
| 683 | int ret; |
| 684 | struct dvb_frontend *fe; |
| 685 | |
| 686 | switch (af9035_af9033_config[adap->id].tuner) { |
| 687 | case AF9033_TUNER_TUA9001: |
| 688 | /* AF9035 gpiot3 = TUA9001 RESETN |
| 689 | AF9035 gpiot2 = TUA9001 RXEN */ |
| 690 | |
| 691 | /* configure gpiot2 and gpiot2 as output */ |
| 692 | ret = af9035_wr_reg_mask(adap->dev, 0x00d8ec, 0x01, 0x01); |
| 693 | if (ret < 0) |
| 694 | goto err; |
| 695 | |
| 696 | ret = af9035_wr_reg_mask(adap->dev, 0x00d8ed, 0x01, 0x01); |
| 697 | if (ret < 0) |
| 698 | goto err; |
| 699 | |
| 700 | ret = af9035_wr_reg_mask(adap->dev, 0x00d8e8, 0x01, 0x01); |
| 701 | if (ret < 0) |
| 702 | goto err; |
| 703 | |
| 704 | ret = af9035_wr_reg_mask(adap->dev, 0x00d8e9, 0x01, 0x01); |
| 705 | if (ret < 0) |
| 706 | goto err; |
| 707 | |
| 708 | /* reset tuner */ |
| 709 | ret = af9035_wr_reg_mask(adap->dev, 0x00d8e7, 0x00, 0x01); |
| 710 | if (ret < 0) |
| 711 | goto err; |
| 712 | |
| 713 | usleep_range(2000, 20000); |
| 714 | |
| 715 | ret = af9035_wr_reg_mask(adap->dev, 0x00d8e7, 0x01, 0x01); |
| 716 | if (ret < 0) |
| 717 | goto err; |
| 718 | |
| 719 | /* activate tuner RX */ |
| 720 | /* TODO: use callback for TUA9001 RXEN */ |
| 721 | ret = af9035_wr_reg_mask(adap->dev, 0x00d8eb, 0x01, 0x01); |
| 722 | if (ret < 0) |
| 723 | goto err; |
| 724 | |
| 725 | /* attach tuner */ |
| 726 | fe = dvb_attach(tua9001_attach, adap->fe_adap[0].fe, |
| 727 | &adap->dev->i2c_adap, &af9035_tua9001_config); |
| 728 | break; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 729 | case AF9033_TUNER_FC0011: |
| 730 | fe = dvb_attach(fc0011_attach, adap->fe_adap[0].fe, |
| 731 | &adap->dev->i2c_adap, &af9035_fc0011_config); |
| 732 | break; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame^] | 733 | case AF9033_TUNER_MXL5007T: |
| 734 | ret = af9035_wr_reg(adap->dev, 0x00d8e0, 1); |
| 735 | if (ret < 0) |
| 736 | goto err; |
| 737 | ret = af9035_wr_reg(adap->dev, 0x00d8e1, 1); |
| 738 | if (ret < 0) |
| 739 | goto err; |
| 740 | ret = af9035_wr_reg(adap->dev, 0x00d8df, 0); |
| 741 | if (ret < 0) |
| 742 | goto err; |
| 743 | |
| 744 | msleep(30); |
| 745 | |
| 746 | ret = af9035_wr_reg(adap->dev, 0x00d8df, 1); |
| 747 | if (ret < 0) |
| 748 | goto err; |
| 749 | |
| 750 | msleep(300); |
| 751 | |
| 752 | ret = af9035_wr_reg(adap->dev, 0x00d8c0, 1); |
| 753 | if (ret < 0) |
| 754 | goto err; |
| 755 | ret = af9035_wr_reg(adap->dev, 0x00d8c1, 1); |
| 756 | if (ret < 0) |
| 757 | goto err; |
| 758 | ret = af9035_wr_reg(adap->dev, 0x00d8bf, 0); |
| 759 | if (ret < 0) |
| 760 | goto err; |
| 761 | ret = af9035_wr_reg(adap->dev, 0x00d8b4, 1); |
| 762 | if (ret < 0) |
| 763 | goto err; |
| 764 | ret = af9035_wr_reg(adap->dev, 0x00d8b5, 1); |
| 765 | if (ret < 0) |
| 766 | goto err; |
| 767 | ret = af9035_wr_reg(adap->dev, 0x00d8b3, 1); |
| 768 | if (ret < 0) |
| 769 | goto err; |
| 770 | |
| 771 | /* attach tuner */ |
| 772 | fe = dvb_attach(mxl5007t_attach, adap->fe_adap[0].fe, |
| 773 | &adap->dev->i2c_adap, 0x60, &af9035_mxl5007t_config); |
| 774 | break; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 775 | default: |
| 776 | fe = NULL; |
| 777 | } |
| 778 | |
| 779 | if (fe == NULL) { |
| 780 | ret = -ENODEV; |
| 781 | goto err; |
| 782 | } |
| 783 | |
| 784 | return 0; |
| 785 | |
| 786 | err: |
| 787 | pr_debug("%s: failed=%d\n", __func__, ret); |
| 788 | |
| 789 | return ret; |
| 790 | } |
| 791 | |
| 792 | enum af9035_id_entry { |
| 793 | AF9035_0CCD_0093, |
Michael Büsch | 1083a0f | 2012-04-02 12:34:52 -0300 | [diff] [blame] | 794 | AF9035_15A4_9035, |
| 795 | AF9035_15A4_1001, |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame^] | 796 | AF9035_07CA_1867, |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 797 | }; |
| 798 | |
| 799 | static struct usb_device_id af9035_id[] = { |
| 800 | [AF9035_0CCD_0093] = { |
| 801 | USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK)}, |
Michael Büsch | 1083a0f | 2012-04-02 12:34:52 -0300 | [diff] [blame] | 802 | [AF9035_15A4_9035] = { |
| 803 | USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035)}, |
| 804 | [AF9035_15A4_1001] = { |
| 805 | USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_2)}, |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame^] | 806 | [AF9035_07CA_1867] = { |
| 807 | USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_1867)}, |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 808 | {}, |
| 809 | }; |
| 810 | |
| 811 | MODULE_DEVICE_TABLE(usb, af9035_id); |
| 812 | |
| 813 | static struct dvb_usb_device_properties af9035_properties[] = { |
| 814 | { |
| 815 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
| 816 | |
| 817 | .usb_ctrl = DEVICE_SPECIFIC, |
| 818 | .download_firmware = af9035_download_firmware, |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 819 | .firmware = "dvb-usb-af9035-02.fw", |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 820 | .no_reconnect = 1, |
| 821 | |
| 822 | .num_adapters = 1, |
| 823 | .adapter = { |
| 824 | { |
| 825 | .num_frontends = 1, |
| 826 | .fe = { |
| 827 | { |
| 828 | .frontend_attach = af9035_frontend_attach, |
| 829 | .tuner_attach = af9035_tuner_attach, |
| 830 | .stream = { |
| 831 | .type = USB_BULK, |
| 832 | .count = 6, |
| 833 | .endpoint = 0x84, |
| 834 | .u = { |
| 835 | .bulk = { |
| 836 | .buffersize = (87 * 188), |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 | } |
| 841 | } |
| 842 | } |
| 843 | }, |
| 844 | |
| 845 | .identify_state = af9035_identify_state, |
| 846 | .read_mac_address = af9035_read_mac_address, |
| 847 | |
| 848 | .i2c_algo = &af9035_i2c_algo, |
| 849 | |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame^] | 850 | .num_device_descs = 3, |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 851 | .devices = { |
| 852 | { |
| 853 | .name = "TerraTec Cinergy T Stick", |
| 854 | .cold_ids = { |
| 855 | &af9035_id[AF9035_0CCD_0093], |
| 856 | }, |
Michael Büsch | 1083a0f | 2012-04-02 12:34:52 -0300 | [diff] [blame] | 857 | }, { |
| 858 | .name = "Afatech Technologies DVB-T stick", |
| 859 | .cold_ids = { |
| 860 | &af9035_id[AF9035_15A4_9035], |
| 861 | &af9035_id[AF9035_15A4_1001], |
| 862 | }, |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame^] | 863 | }, { |
| 864 | .name = "AVerMedia HD Volar", |
| 865 | .cold_ids = { |
| 866 | &af9035_id[AF9035_07CA_1867], |
| 867 | }, |
| 868 | }, |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 869 | } |
| 870 | }, |
| 871 | }; |
| 872 | |
| 873 | static int af9035_usb_probe(struct usb_interface *intf, |
| 874 | const struct usb_device_id *id) |
| 875 | { |
| 876 | int ret, i; |
| 877 | struct dvb_usb_device *d = NULL; |
| 878 | struct usb_device *udev; |
| 879 | bool found; |
| 880 | |
| 881 | pr_debug("%s: interface=%d\n", __func__, |
| 882 | intf->cur_altsetting->desc.bInterfaceNumber); |
| 883 | |
| 884 | /* interface 0 is used by DVB-T receiver and |
| 885 | interface 1 is for remote controller (HID) */ |
| 886 | if (intf->cur_altsetting->desc.bInterfaceNumber != 0) |
| 887 | return 0; |
| 888 | |
| 889 | /* Dynamic USB ID support. Replaces first device ID with current one. */ |
| 890 | udev = interface_to_usbdev(intf); |
| 891 | |
| 892 | for (i = 0, found = false; i < ARRAY_SIZE(af9035_id) - 1; i++) { |
| 893 | if (af9035_id[i].idVendor == |
| 894 | le16_to_cpu(udev->descriptor.idVendor) && |
| 895 | af9035_id[i].idProduct == |
| 896 | le16_to_cpu(udev->descriptor.idProduct)) { |
| 897 | found = true; |
| 898 | break; |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | if (!found) { |
| 903 | pr_debug("%s: using dynamic ID %04x:%04x\n", __func__, |
| 904 | le16_to_cpu(udev->descriptor.idVendor), |
| 905 | le16_to_cpu(udev->descriptor.idProduct)); |
| 906 | af9035_properties[0].devices[0].cold_ids[0]->idVendor = |
| 907 | le16_to_cpu(udev->descriptor.idVendor); |
| 908 | af9035_properties[0].devices[0].cold_ids[0]->idProduct = |
| 909 | le16_to_cpu(udev->descriptor.idProduct); |
| 910 | } |
| 911 | |
| 912 | |
| 913 | for (i = 0; i < af9035_properties_count; i++) { |
| 914 | ret = dvb_usb_device_init(intf, &af9035_properties[i], |
| 915 | THIS_MODULE, &d, adapter_nr); |
| 916 | |
| 917 | if (ret == -ENODEV) |
| 918 | continue; |
| 919 | else |
| 920 | break; |
| 921 | } |
| 922 | |
| 923 | if (ret < 0) |
| 924 | goto err; |
| 925 | |
| 926 | if (d) { |
| 927 | ret = af9035_init(d); |
| 928 | if (ret < 0) |
| 929 | goto err; |
| 930 | } |
| 931 | |
| 932 | return 0; |
| 933 | |
| 934 | err: |
| 935 | pr_debug("%s: failed=%d\n", __func__, ret); |
| 936 | |
| 937 | return ret; |
| 938 | } |
| 939 | |
| 940 | /* usb specific object needed to register this driver with the usb subsystem */ |
| 941 | static struct usb_driver af9035_usb_driver = { |
| 942 | .name = "dvb_usb_af9035", |
| 943 | .probe = af9035_usb_probe, |
| 944 | .disconnect = dvb_usb_device_exit, |
| 945 | .id_table = af9035_id, |
| 946 | }; |
| 947 | |
| 948 | /* module stuff */ |
| 949 | static int __init af9035_usb_module_init(void) |
| 950 | { |
| 951 | int ret; |
| 952 | |
| 953 | ret = usb_register(&af9035_usb_driver); |
| 954 | if (ret < 0) |
| 955 | goto err; |
| 956 | |
| 957 | return 0; |
| 958 | |
| 959 | err: |
| 960 | pr_debug("%s: failed=%d\n", __func__, ret); |
| 961 | |
| 962 | return ret; |
| 963 | } |
| 964 | |
| 965 | static void __exit af9035_usb_module_exit(void) |
| 966 | { |
| 967 | /* deregister this driver from the USB subsystem */ |
| 968 | usb_deregister(&af9035_usb_driver); |
| 969 | } |
| 970 | |
| 971 | module_init(af9035_usb_module_init); |
| 972 | module_exit(af9035_usb_module_exit); |
| 973 | |
| 974 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 975 | MODULE_DESCRIPTION("Afatech AF9035 driver"); |
| 976 | MODULE_LICENSE("GPL"); |