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" |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 23 | |
| 24 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 25 | |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 26 | static u16 af9035_checksum(const u8 *buf, size_t len) |
| 27 | { |
| 28 | size_t i; |
| 29 | u16 checksum = 0; |
| 30 | |
| 31 | for (i = 1; i < len; i++) { |
| 32 | if (i % 2) |
| 33 | checksum += buf[i] << 8; |
| 34 | else |
| 35 | checksum += buf[i]; |
| 36 | } |
| 37 | checksum = ~checksum; |
| 38 | |
| 39 | return checksum; |
| 40 | } |
| 41 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 42 | static int af9035_ctrl_msg(struct dvb_usb_device *d, struct usb_req *req) |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 43 | { |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 44 | #define REQ_HDR_LEN 4 /* send header size */ |
| 45 | #define ACK_HDR_LEN 3 /* rece header size */ |
| 46 | #define CHECKSUM_LEN 2 |
| 47 | #define USB_TIMEOUT 2000 |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 48 | struct state *state = d_to_priv(d); |
| 49 | int ret, wlen, rlen; |
Antti Palosaari | 6fb39c5 | 2012-04-06 16:32:30 -0300 | [diff] [blame] | 50 | u16 checksum, tmp_checksum; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 51 | |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 52 | mutex_lock(&d->usb_mutex); |
| 53 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 54 | /* buffer overflow check */ |
| 55 | if (req->wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) || |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 56 | req->rlen > (BUF_LEN - ACK_HDR_LEN - CHECKSUM_LEN)) { |
| 57 | dev_err(&d->udev->dev, "%s: too much data wlen=%d rlen=%d\n", |
Antti Palosaari | e8292e2 | 2013-06-03 18:50:43 -0300 | [diff] [blame] | 58 | KBUILD_MODNAME, req->wlen, req->rlen); |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 59 | ret = -EINVAL; |
Wei Yongjun | 0170a39 | 2013-03-26 01:32:19 -0300 | [diff] [blame] | 60 | goto exit; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 61 | } |
| 62 | |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 63 | state->buf[0] = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN - 1; |
| 64 | state->buf[1] = req->mbox; |
| 65 | state->buf[2] = req->cmd; |
| 66 | state->buf[3] = state->seq++; |
| 67 | memcpy(&state->buf[REQ_HDR_LEN], req->wbuf, req->wlen); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 68 | |
| 69 | wlen = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN; |
| 70 | rlen = ACK_HDR_LEN + req->rlen + CHECKSUM_LEN; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 71 | |
| 72 | /* calc and add checksum */ |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 73 | checksum = af9035_checksum(state->buf, state->buf[0] - 1); |
| 74 | state->buf[state->buf[0] - 1] = (checksum >> 8); |
| 75 | state->buf[state->buf[0] - 0] = (checksum & 0xff); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 76 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 77 | /* no ack for these packets */ |
| 78 | if (req->cmd == CMD_FW_DL) |
| 79 | rlen = 0; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 80 | |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 81 | ret = dvb_usbv2_generic_rw_locked(d, |
| 82 | state->buf, wlen, state->buf, rlen); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 83 | if (ret) |
Wei Yongjun | 0170a39 | 2013-03-26 01:32:19 -0300 | [diff] [blame] | 84 | goto exit; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 85 | |
| 86 | /* no ack for those packets */ |
| 87 | if (req->cmd == CMD_FW_DL) |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 88 | goto exit; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 89 | |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 90 | /* verify checksum */ |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 91 | checksum = af9035_checksum(state->buf, rlen - 2); |
| 92 | tmp_checksum = (state->buf[rlen - 2] << 8) | state->buf[rlen - 1]; |
Antti Palosaari | 6fb39c5 | 2012-04-06 16:32:30 -0300 | [diff] [blame] | 93 | if (tmp_checksum != checksum) { |
Antti Palosaari | cb9114e | 2013-06-03 18:42:14 -0300 | [diff] [blame] | 94 | dev_err(&d->udev->dev, |
| 95 | "%s: command=%02x checksum mismatch (%04x != %04x)\n", |
| 96 | KBUILD_MODNAME, req->cmd, tmp_checksum, |
| 97 | checksum); |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 98 | ret = -EIO; |
Wei Yongjun | 0170a39 | 2013-03-26 01:32:19 -0300 | [diff] [blame] | 99 | goto exit; |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 100 | } |
Antti Palosaari | 6fb39c5 | 2012-04-06 16:32:30 -0300 | [diff] [blame] | 101 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 102 | /* check status */ |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 103 | if (state->buf[2]) { |
Antti Palosaari | 1bfd529 | 2013-03-08 17:39:12 -0300 | [diff] [blame] | 104 | /* fw returns status 1 when IR code was not received */ |
Wei Yongjun | 0170a39 | 2013-03-26 01:32:19 -0300 | [diff] [blame] | 105 | if (req->cmd == CMD_IR_GET || state->buf[2] == 1) { |
| 106 | ret = 1; |
| 107 | goto exit; |
| 108 | } |
Antti Palosaari | 1bfd529 | 2013-03-08 17:39:12 -0300 | [diff] [blame] | 109 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 110 | dev_dbg(&d->udev->dev, "%s: command=%02x failed fw error=%d\n", |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 111 | __func__, req->cmd, state->buf[2]); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 112 | ret = -EIO; |
Wei Yongjun | 0170a39 | 2013-03-26 01:32:19 -0300 | [diff] [blame] | 113 | goto exit; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* read request, copy returned data to return buf */ |
| 117 | if (req->rlen) |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 118 | memcpy(req->rbuf, &state->buf[ACK_HDR_LEN], req->rlen); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 119 | exit: |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 120 | mutex_unlock(&d->usb_mutex); |
Wei Yongjun | 0170a39 | 2013-03-26 01:32:19 -0300 | [diff] [blame] | 121 | if (ret < 0) |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 122 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | /* write multiple registers */ |
| 127 | static int af9035_wr_regs(struct dvb_usb_device *d, u32 reg, u8 *val, int len) |
| 128 | { |
| 129 | u8 wbuf[6 + len]; |
| 130 | u8 mbox = (reg >> 16) & 0xff; |
| 131 | struct usb_req req = { CMD_MEM_WR, mbox, sizeof(wbuf), wbuf, 0, NULL }; |
| 132 | |
| 133 | wbuf[0] = len; |
| 134 | wbuf[1] = 2; |
| 135 | wbuf[2] = 0; |
| 136 | wbuf[3] = 0; |
| 137 | wbuf[4] = (reg >> 8) & 0xff; |
| 138 | wbuf[5] = (reg >> 0) & 0xff; |
| 139 | memcpy(&wbuf[6], val, len); |
| 140 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 141 | return af9035_ctrl_msg(d, &req); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* read multiple registers */ |
| 145 | static int af9035_rd_regs(struct dvb_usb_device *d, u32 reg, u8 *val, int len) |
| 146 | { |
| 147 | u8 wbuf[] = { len, 2, 0, 0, (reg >> 8) & 0xff, reg & 0xff }; |
| 148 | u8 mbox = (reg >> 16) & 0xff; |
| 149 | struct usb_req req = { CMD_MEM_RD, mbox, sizeof(wbuf), wbuf, len, val }; |
| 150 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 151 | return af9035_ctrl_msg(d, &req); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /* write single register */ |
| 155 | static int af9035_wr_reg(struct dvb_usb_device *d, u32 reg, u8 val) |
| 156 | { |
| 157 | return af9035_wr_regs(d, reg, &val, 1); |
| 158 | } |
| 159 | |
| 160 | /* read single register */ |
| 161 | static int af9035_rd_reg(struct dvb_usb_device *d, u32 reg, u8 *val) |
| 162 | { |
| 163 | return af9035_rd_regs(d, reg, val, 1); |
| 164 | } |
| 165 | |
| 166 | /* write single register with mask */ |
| 167 | static int af9035_wr_reg_mask(struct dvb_usb_device *d, u32 reg, u8 val, |
| 168 | u8 mask) |
| 169 | { |
| 170 | int ret; |
| 171 | u8 tmp; |
| 172 | |
| 173 | /* no need for read if whole reg is written */ |
| 174 | if (mask != 0xff) { |
| 175 | ret = af9035_rd_regs(d, reg, &tmp, 1); |
| 176 | if (ret) |
| 177 | return ret; |
| 178 | |
| 179 | val &= mask; |
| 180 | tmp &= ~mask; |
| 181 | val |= tmp; |
| 182 | } |
| 183 | |
| 184 | return af9035_wr_regs(d, reg, &val, 1); |
| 185 | } |
| 186 | |
| 187 | static int af9035_i2c_master_xfer(struct i2c_adapter *adap, |
| 188 | struct i2c_msg msg[], int num) |
| 189 | { |
| 190 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 191 | struct state *state = d_to_priv(d); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 192 | int ret; |
| 193 | |
| 194 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 195 | return -EAGAIN; |
| 196 | |
Antti Palosaari | ad30e91 | 2012-04-02 20:18:59 -0300 | [diff] [blame] | 197 | /* |
| 198 | * I2C sub header is 5 bytes long. Meaning of those bytes are: |
| 199 | * 0: data len |
| 200 | * 1: I2C addr << 1 |
| 201 | * 2: reg addr len |
| 202 | * byte 3 and 4 can be used as reg addr |
| 203 | * 3: reg addr MSB |
| 204 | * used when reg addr len is set to 2 |
| 205 | * 4: reg addr LSB |
| 206 | * used when reg addr len is set to 1 or 2 |
| 207 | * |
| 208 | * For the simplify we do not use register addr at all. |
| 209 | * NOTE: As a firmware knows tuner type there is very small possibility |
| 210 | * there could be some tuner I2C hacks done by firmware and this may |
| 211 | * lead problems if firmware expects those bytes are used. |
| 212 | */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 213 | if (num == 2 && !(msg[0].flags & I2C_M_RD) && |
| 214 | (msg[1].flags & I2C_M_RD)) { |
| 215 | if (msg[0].len > 40 || msg[1].len > 40) { |
| 216 | /* TODO: correct limits > 40 */ |
| 217 | ret = -EOPNOTSUPP; |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 218 | } else if ((msg[0].addr == state->af9033_config[0].i2c_addr) || |
| 219 | (msg[0].addr == state->af9033_config[1].i2c_addr)) { |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 220 | /* demod access via firmware interface */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 221 | u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | |
| 222 | msg[0].buf[2]; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 223 | |
| 224 | if (msg[0].addr == state->af9033_config[1].i2c_addr) |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 225 | reg |= 0x100000; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 226 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 227 | ret = af9035_rd_regs(d, reg, &msg[1].buf[0], |
| 228 | msg[1].len); |
| 229 | } else { |
| 230 | /* I2C */ |
Antti Palosaari | ad30e91 | 2012-04-02 20:18:59 -0300 | [diff] [blame] | 231 | u8 buf[5 + msg[0].len]; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 232 | struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf), |
| 233 | buf, msg[1].len, msg[1].buf }; |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 234 | req.mbox |= ((msg[0].addr & 0x80) >> 3); |
Hans-Frieder Vogt | 812fe6d | 2012-04-01 14:11:29 -0300 | [diff] [blame] | 235 | buf[0] = msg[1].len; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 236 | buf[1] = msg[0].addr << 1; |
Antti Palosaari | ad30e91 | 2012-04-02 20:18:59 -0300 | [diff] [blame] | 237 | buf[2] = 0x00; /* reg addr len */ |
| 238 | buf[3] = 0x00; /* reg addr MSB */ |
| 239 | buf[4] = 0x00; /* reg addr LSB */ |
| 240 | memcpy(&buf[5], msg[0].buf, msg[0].len); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 241 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 242 | } |
| 243 | } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) { |
| 244 | if (msg[0].len > 40) { |
| 245 | /* TODO: correct limits > 40 */ |
| 246 | ret = -EOPNOTSUPP; |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 247 | } else if ((msg[0].addr == state->af9033_config[0].i2c_addr) || |
| 248 | (msg[0].addr == state->af9033_config[1].i2c_addr)) { |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 249 | /* demod access via firmware interface */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 250 | u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | |
| 251 | msg[0].buf[2]; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 252 | |
| 253 | if (msg[0].addr == state->af9033_config[1].i2c_addr) |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 254 | reg |= 0x100000; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 255 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 256 | ret = af9035_wr_regs(d, reg, &msg[0].buf[3], |
| 257 | msg[0].len - 3); |
| 258 | } else { |
| 259 | /* I2C */ |
Antti Palosaari | ad30e91 | 2012-04-02 20:18:59 -0300 | [diff] [blame] | 260 | u8 buf[5 + msg[0].len]; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 261 | struct usb_req req = { CMD_I2C_WR, 0, sizeof(buf), buf, |
| 262 | 0, NULL }; |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 263 | req.mbox |= ((msg[0].addr & 0x80) >> 3); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 264 | buf[0] = msg[0].len; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 265 | buf[1] = msg[0].addr << 1; |
Antti Palosaari | ad30e91 | 2012-04-02 20:18:59 -0300 | [diff] [blame] | 266 | buf[2] = 0x00; /* reg addr len */ |
| 267 | buf[3] = 0x00; /* reg addr MSB */ |
| 268 | buf[4] = 0x00; /* reg addr LSB */ |
| 269 | memcpy(&buf[5], msg[0].buf, msg[0].len); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 270 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 271 | } |
Antti Palosaari | 3b98c34 | 2013-03-11 19:05:39 -0300 | [diff] [blame] | 272 | } else if (num == 1 && (msg[0].flags & I2C_M_RD)) { |
| 273 | if (msg[0].len > 40) { |
| 274 | /* TODO: correct limits > 40 */ |
| 275 | ret = -EOPNOTSUPP; |
| 276 | } else { |
| 277 | /* I2C */ |
| 278 | u8 buf[5]; |
| 279 | struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf), |
| 280 | buf, msg[0].len, msg[0].buf }; |
| 281 | req.mbox |= ((msg[0].addr & 0x80) >> 3); |
| 282 | buf[0] = msg[0].len; |
| 283 | buf[1] = msg[0].addr << 1; |
| 284 | buf[2] = 0x00; /* reg addr len */ |
| 285 | buf[3] = 0x00; /* reg addr MSB */ |
| 286 | buf[4] = 0x00; /* reg addr LSB */ |
| 287 | ret = af9035_ctrl_msg(d, &req); |
| 288 | } |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 289 | } else { |
| 290 | /* |
Antti Palosaari | 3b98c34 | 2013-03-11 19:05:39 -0300 | [diff] [blame] | 291 | * We support only three kind of I2C transactions: |
| 292 | * 1) 1 x read + 1 x write (repeated start) |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 293 | * 2) 1 x write |
Antti Palosaari | 3b98c34 | 2013-03-11 19:05:39 -0300 | [diff] [blame] | 294 | * 3) 1 x read |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 295 | */ |
| 296 | ret = -EOPNOTSUPP; |
| 297 | } |
| 298 | |
| 299 | mutex_unlock(&d->i2c_mutex); |
| 300 | |
| 301 | if (ret < 0) |
| 302 | return ret; |
| 303 | else |
| 304 | return num; |
| 305 | } |
| 306 | |
| 307 | static u32 af9035_i2c_functionality(struct i2c_adapter *adapter) |
| 308 | { |
| 309 | return I2C_FUNC_I2C; |
| 310 | } |
| 311 | |
| 312 | static struct i2c_algorithm af9035_i2c_algo = { |
| 313 | .master_xfer = af9035_i2c_master_xfer, |
| 314 | .functionality = af9035_i2c_functionality, |
| 315 | }; |
| 316 | |
Antti Palosaari | a0921af | 2012-06-18 23:42:53 -0300 | [diff] [blame] | 317 | static int af9035_identify_state(struct dvb_usb_device *d, const char **name) |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 318 | { |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 319 | struct state *state = d_to_priv(d); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 320 | int ret; |
| 321 | u8 wbuf[1] = { 1 }; |
| 322 | u8 rbuf[4]; |
| 323 | struct usb_req req = { CMD_FW_QUERYINFO, 0, sizeof(wbuf), wbuf, |
| 324 | sizeof(rbuf), rbuf }; |
| 325 | |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 326 | ret = af9035_rd_regs(d, 0x1222, rbuf, 3); |
| 327 | if (ret < 0) |
| 328 | goto err; |
| 329 | |
| 330 | state->chip_version = rbuf[0]; |
| 331 | state->chip_type = rbuf[2] << 8 | rbuf[1] << 0; |
| 332 | |
| 333 | ret = af9035_rd_reg(d, 0x384f, &state->prechip_version); |
| 334 | if (ret < 0) |
| 335 | goto err; |
| 336 | |
| 337 | dev_info(&d->udev->dev, |
| 338 | "%s: prechip_version=%02x chip_version=%02x chip_type=%04x\n", |
Antti Palosaari | e8292e2 | 2013-06-03 18:50:43 -0300 | [diff] [blame] | 339 | KBUILD_MODNAME, state->prechip_version, |
| 340 | state->chip_version, state->chip_type); |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 341 | |
| 342 | if (state->chip_type == 0x9135) { |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 343 | if (state->chip_version == 0x02) |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 344 | *name = AF9035_FIRMWARE_IT9135_V2; |
| 345 | else |
| 346 | *name = AF9035_FIRMWARE_IT9135_V1; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 347 | state->eeprom_addr = EEPROM_BASE_IT9135; |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 348 | } else { |
| 349 | *name = AF9035_FIRMWARE_AF9035; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 350 | state->eeprom_addr = EEPROM_BASE_AF9035; |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 351 | } |
| 352 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 353 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 354 | if (ret < 0) |
| 355 | goto err; |
| 356 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 357 | dev_dbg(&d->udev->dev, "%s: reply=%*ph\n", __func__, 4, rbuf); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 358 | if (rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3]) |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 359 | ret = WARM; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 360 | else |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 361 | ret = COLD; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 362 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 363 | return ret; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 364 | |
| 365 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 366 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 367 | |
| 368 | return ret; |
| 369 | } |
| 370 | |
Antti Palosaari | 8229da5 | 2013-03-07 17:59:55 -0300 | [diff] [blame] | 371 | static int af9035_download_firmware_old(struct dvb_usb_device *d, |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 372 | const struct firmware *fw) |
| 373 | { |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 374 | int ret, i, j, len; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 375 | u8 wbuf[1]; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 376 | struct usb_req req = { 0, 0, 0, NULL, 0, NULL }; |
| 377 | struct usb_req req_fw_dl = { CMD_FW_DL, 0, 0, wbuf, 0, NULL }; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 378 | u8 hdr_core; |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 379 | u16 hdr_addr, hdr_data_len, hdr_checksum; |
Antti Palosaari | 6fb39c5 | 2012-04-06 16:32:30 -0300 | [diff] [blame] | 380 | #define MAX_DATA 58 |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 381 | #define HDR_SIZE 7 |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 382 | |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 383 | /* |
| 384 | * Thanks to Daniel Glöckner <daniel-gl@gmx.net> about that info! |
| 385 | * |
| 386 | * byte 0: MCS 51 core |
| 387 | * There are two inside the AF9035 (1=Link and 2=OFDM) with separate |
| 388 | * address spaces |
| 389 | * byte 1-2: Big endian destination address |
| 390 | * byte 3-4: Big endian number of data bytes following the header |
| 391 | * byte 5-6: Big endian header checksum, apparently ignored by the chip |
| 392 | * Calculated as ~(h[0]*256+h[1]+h[2]*256+h[3]+h[4]*256) |
| 393 | */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 394 | |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 395 | for (i = fw->size; i > HDR_SIZE;) { |
| 396 | hdr_core = fw->data[fw->size - i + 0]; |
| 397 | hdr_addr = fw->data[fw->size - i + 1] << 8; |
| 398 | hdr_addr |= fw->data[fw->size - i + 2] << 0; |
| 399 | hdr_data_len = fw->data[fw->size - i + 3] << 8; |
| 400 | hdr_data_len |= fw->data[fw->size - i + 4] << 0; |
| 401 | hdr_checksum = fw->data[fw->size - i + 5] << 8; |
| 402 | hdr_checksum |= fw->data[fw->size - i + 6] << 0; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 403 | |
Antti Palosaari | cb9114e | 2013-06-03 18:42:14 -0300 | [diff] [blame] | 404 | dev_dbg(&d->udev->dev, |
| 405 | "%s: core=%d addr=%04x data_len=%d checksum=%04x\n", |
| 406 | __func__, hdr_core, hdr_addr, hdr_data_len, |
| 407 | hdr_checksum); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 408 | |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 409 | if (((hdr_core != 1) && (hdr_core != 2)) || |
| 410 | (hdr_data_len > i)) { |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 411 | dev_dbg(&d->udev->dev, "%s: bad firmware\n", __func__); |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 412 | break; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 413 | } |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 414 | |
| 415 | /* download begin packet */ |
| 416 | req.cmd = CMD_FW_DL_BEGIN; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 417 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | 41d44a8 | 2012-04-01 11:06:23 -0300 | [diff] [blame] | 418 | if (ret < 0) |
| 419 | goto err; |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 420 | |
| 421 | /* download firmware packet(s) */ |
| 422 | for (j = HDR_SIZE + hdr_data_len; j > 0; j -= MAX_DATA) { |
| 423 | len = j; |
| 424 | if (len > MAX_DATA) |
| 425 | len = MAX_DATA; |
| 426 | req_fw_dl.wlen = len; |
| 427 | req_fw_dl.wbuf = (u8 *) &fw->data[fw->size - i + |
| 428 | HDR_SIZE + hdr_data_len - j]; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 429 | ret = af9035_ctrl_msg(d, &req_fw_dl); |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 430 | if (ret < 0) |
| 431 | goto err; |
| 432 | } |
| 433 | |
| 434 | /* download end packet */ |
| 435 | req.cmd = CMD_FW_DL_END; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 436 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 437 | if (ret < 0) |
| 438 | goto err; |
| 439 | |
| 440 | i -= hdr_data_len + HDR_SIZE; |
| 441 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 442 | dev_dbg(&d->udev->dev, "%s: data uploaded=%zu\n", |
| 443 | __func__, fw->size - i); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 444 | } |
| 445 | |
Antti Palosaari | ff4e3fe | 2012-12-09 16:25:08 -0300 | [diff] [blame] | 446 | /* print warn if firmware is bad, continue and see what happens */ |
| 447 | if (i) |
| 448 | dev_warn(&d->udev->dev, "%s: bad firmware\n", KBUILD_MODNAME); |
| 449 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 450 | return 0; |
| 451 | |
| 452 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 453 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 454 | |
| 455 | return ret; |
| 456 | } |
| 457 | |
Antti Palosaari | 8229da5 | 2013-03-07 17:59:55 -0300 | [diff] [blame] | 458 | static int af9035_download_firmware_new(struct dvb_usb_device *d, |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 459 | const struct firmware *fw) |
| 460 | { |
| 461 | int ret, i, i_prev; |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 462 | struct usb_req req_fw_dl = { CMD_FW_SCATTER_WR, 0, 0, NULL, 0, NULL }; |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 463 | #define HDR_SIZE 7 |
| 464 | |
| 465 | /* |
| 466 | * There seems to be following firmware header. Meaning of bytes 0-3 |
| 467 | * is unknown. |
| 468 | * |
| 469 | * 0: 3 |
| 470 | * 1: 0, 1 |
| 471 | * 2: 0 |
| 472 | * 3: 1, 2, 3 |
| 473 | * 4: addr MSB |
| 474 | * 5: addr LSB |
| 475 | * 6: count of data bytes ? |
| 476 | */ |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 477 | for (i = HDR_SIZE, i_prev = 0; i <= fw->size; i++) { |
| 478 | if (i == fw->size || |
| 479 | (fw->data[i + 0] == 0x03 && |
| 480 | (fw->data[i + 1] == 0x00 || |
| 481 | fw->data[i + 1] == 0x01) && |
| 482 | fw->data[i + 2] == 0x00)) { |
| 483 | req_fw_dl.wlen = i - i_prev; |
| 484 | req_fw_dl.wbuf = (u8 *) &fw->data[i_prev]; |
| 485 | i_prev = i; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 486 | ret = af9035_ctrl_msg(d, &req_fw_dl); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 487 | if (ret < 0) |
| 488 | goto err; |
| 489 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 490 | dev_dbg(&d->udev->dev, "%s: data uploaded=%d\n", |
| 491 | __func__, i); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 495 | return 0; |
| 496 | |
| 497 | err: |
| 498 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 499 | |
| 500 | return ret; |
| 501 | } |
| 502 | |
| 503 | static int af9035_download_firmware(struct dvb_usb_device *d, |
| 504 | const struct firmware *fw) |
| 505 | { |
| 506 | struct state *state = d_to_priv(d); |
| 507 | int ret; |
| 508 | u8 wbuf[1]; |
| 509 | u8 rbuf[4]; |
| 510 | u8 tmp; |
| 511 | struct usb_req req = { 0, 0, 0, NULL, 0, NULL }; |
Antti Palosaari | cb9114e | 2013-06-03 18:42:14 -0300 | [diff] [blame] | 512 | struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf }; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 513 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
| 514 | |
| 515 | /* |
| 516 | * In case of dual tuner configuration we need to do some extra |
| 517 | * initialization in order to download firmware to slave demod too, |
| 518 | * which is done by master demod. |
| 519 | * Master feeds also clock and controls power via GPIO. |
| 520 | */ |
Antti Palosaari | d716ef4 | 2013-06-03 19:39:51 -0300 | [diff] [blame^] | 521 | ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_TS_MODE, &tmp); |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 522 | if (ret < 0) |
| 523 | goto err; |
| 524 | |
Antti Palosaari | d716ef4 | 2013-06-03 19:39:51 -0300 | [diff] [blame^] | 525 | if (tmp == 1 || tmp == 3) { |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 526 | /* configure gpioh1, reset & power slave demod */ |
| 527 | ret = af9035_wr_reg_mask(d, 0x00d8b0, 0x01, 0x01); |
| 528 | if (ret < 0) |
| 529 | goto err; |
| 530 | |
| 531 | ret = af9035_wr_reg_mask(d, 0x00d8b1, 0x01, 0x01); |
| 532 | if (ret < 0) |
| 533 | goto err; |
| 534 | |
| 535 | ret = af9035_wr_reg_mask(d, 0x00d8af, 0x00, 0x01); |
| 536 | if (ret < 0) |
| 537 | goto err; |
| 538 | |
| 539 | usleep_range(10000, 50000); |
| 540 | |
| 541 | ret = af9035_wr_reg_mask(d, 0x00d8af, 0x01, 0x01); |
| 542 | if (ret < 0) |
| 543 | goto err; |
| 544 | |
| 545 | /* tell the slave I2C address */ |
| 546 | ret = af9035_rd_reg(d, |
| 547 | state->eeprom_addr + EEPROM_2ND_DEMOD_ADDR, |
| 548 | &tmp); |
| 549 | if (ret < 0) |
| 550 | goto err; |
| 551 | |
| 552 | if (state->chip_type == 0x9135) { |
| 553 | ret = af9035_wr_reg(d, 0x004bfb, tmp); |
| 554 | if (ret < 0) |
| 555 | goto err; |
| 556 | } else { |
| 557 | ret = af9035_wr_reg(d, 0x00417f, tmp); |
| 558 | if (ret < 0) |
| 559 | goto err; |
| 560 | |
| 561 | /* enable clock out */ |
| 562 | ret = af9035_wr_reg_mask(d, 0x00d81a, 0x01, 0x01); |
| 563 | if (ret < 0) |
| 564 | goto err; |
| 565 | } |
| 566 | } |
| 567 | |
Antti Palosaari | 8229da5 | 2013-03-07 17:59:55 -0300 | [diff] [blame] | 568 | if (fw->data[0] == 0x01) |
| 569 | ret = af9035_download_firmware_old(d, fw); |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 570 | else |
Antti Palosaari | 8229da5 | 2013-03-07 17:59:55 -0300 | [diff] [blame] | 571 | ret = af9035_download_firmware_new(d, fw); |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 572 | if (ret < 0) |
| 573 | goto err; |
| 574 | |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 575 | /* firmware loaded, request boot */ |
| 576 | req.cmd = CMD_FW_BOOT; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 577 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 578 | if (ret < 0) |
| 579 | goto err; |
| 580 | |
| 581 | /* ensure firmware starts */ |
| 582 | wbuf[0] = 1; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 583 | ret = af9035_ctrl_msg(d, &req_fw_ver); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 584 | if (ret < 0) |
| 585 | goto err; |
| 586 | |
| 587 | if (!(rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3])) { |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 588 | dev_err(&d->udev->dev, "%s: firmware did not run\n", |
| 589 | KBUILD_MODNAME); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 590 | ret = -ENODEV; |
| 591 | goto err; |
| 592 | } |
| 593 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 594 | dev_info(&d->udev->dev, "%s: firmware version=%d.%d.%d.%d", |
| 595 | KBUILD_MODNAME, rbuf[0], rbuf[1], rbuf[2], rbuf[3]); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 596 | |
| 597 | return 0; |
| 598 | |
| 599 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 600 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 601 | |
| 602 | return ret; |
| 603 | } |
| 604 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 605 | static int af9035_read_config(struct dvb_usb_device *d) |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 606 | { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 607 | struct state *state = d_to_priv(d); |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 608 | int ret, i; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 609 | u8 tmp; |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 610 | u16 tmp16, addr; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 611 | |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 612 | /* demod I2C "address" */ |
| 613 | state->af9033_config[0].i2c_addr = 0x38; |
Antti Palosaari | 0d94d6a | 2013-01-07 15:26:05 -0300 | [diff] [blame] | 614 | state->af9033_config[0].adc_multiplier = AF9033_ADC_MULTIPLIER_2X; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 615 | state->af9033_config[1].adc_multiplier = AF9033_ADC_MULTIPLIER_2X; |
Antti Palosaari | ab56ad6 | 2013-03-07 18:43:51 -0300 | [diff] [blame] | 616 | state->af9033_config[0].ts_mode = AF9033_TS_MODE_USB; |
| 617 | state->af9033_config[1].ts_mode = AF9033_TS_MODE_SERIAL; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 618 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 619 | /* eeprom memory mapped location */ |
| 620 | if (state->chip_type == 0x9135) { |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 621 | if (state->chip_version == 0x02) { |
| 622 | state->af9033_config[0].tuner = AF9033_TUNER_IT9135_60; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 623 | state->af9033_config[1].tuner = AF9033_TUNER_IT9135_60; |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 624 | tmp16 = 0x00461d; |
| 625 | } else { |
| 626 | state->af9033_config[0].tuner = AF9033_TUNER_IT9135_38; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 627 | state->af9033_config[1].tuner = AF9033_TUNER_IT9135_38; |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 628 | tmp16 = 0x00461b; |
| 629 | } |
| 630 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 631 | /* check if eeprom exists */ |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 632 | ret = af9035_rd_reg(d, tmp16, &tmp); |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 633 | if (ret < 0) |
| 634 | goto err; |
| 635 | |
Antti Palosaari | 431a6d4 | 2013-03-07 18:28:25 -0300 | [diff] [blame] | 636 | if (tmp == 0x00) { |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 637 | dev_dbg(&d->udev->dev, "%s: no eeprom\n", __func__); |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 638 | goto skip_eeprom; |
| 639 | } |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 640 | } |
| 641 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 642 | /* check if there is dual tuners */ |
Antti Palosaari | d716ef4 | 2013-06-03 19:39:51 -0300 | [diff] [blame^] | 643 | ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_TS_MODE, &tmp); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 644 | if (ret < 0) |
| 645 | goto err; |
| 646 | |
Antti Palosaari | d716ef4 | 2013-06-03 19:39:51 -0300 | [diff] [blame^] | 647 | if (tmp == 1 || tmp == 3) |
| 648 | state->dual_mode = true; |
| 649 | |
| 650 | dev_dbg(&d->udev->dev, "%s: ts mode=%d dual mode=%d\n", __func__, |
| 651 | tmp, state->dual_mode); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 652 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 653 | if (state->dual_mode) { |
| 654 | /* read 2nd demodulator I2C address */ |
Antti Palosaari | 431a6d4 | 2013-03-07 18:28:25 -0300 | [diff] [blame] | 655 | ret = af9035_rd_reg(d, |
| 656 | state->eeprom_addr + EEPROM_2ND_DEMOD_ADDR, |
| 657 | &tmp); |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 658 | if (ret < 0) |
| 659 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 660 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 661 | state->af9033_config[1].i2c_addr = tmp; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 662 | dev_dbg(&d->udev->dev, "%s: 2nd demod I2C addr=%02x\n", |
| 663 | __func__, tmp); |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 664 | } |
| 665 | |
Antti Palosaari | 431a6d4 | 2013-03-07 18:28:25 -0300 | [diff] [blame] | 666 | addr = state->eeprom_addr; |
| 667 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 668 | for (i = 0; i < state->dual_mode + 1; i++) { |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 669 | /* tuner */ |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 670 | ret = af9035_rd_reg(d, addr + EEPROM_1_TUNER_ID, &tmp); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 671 | if (ret < 0) |
| 672 | goto err; |
| 673 | |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 674 | if (tmp == 0x00) |
| 675 | dev_dbg(&d->udev->dev, |
| 676 | "%s: [%d]tuner not set, using default\n", |
| 677 | __func__, i); |
| 678 | else |
| 679 | state->af9033_config[i].tuner = tmp; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 680 | |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 681 | dev_dbg(&d->udev->dev, "%s: [%d]tuner=%02x\n", |
| 682 | __func__, i, state->af9033_config[i].tuner); |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 683 | |
| 684 | switch (state->af9033_config[i].tuner) { |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 685 | case AF9033_TUNER_TUA9001: |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 686 | case AF9033_TUNER_FC0011: |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 687 | case AF9033_TUNER_MXL5007T: |
Gianluca Gennari | ce1fe37 | 2012-04-02 17:25:14 -0300 | [diff] [blame] | 688 | case AF9033_TUNER_TDA18218: |
Oliver Schinagl | d67ceb3 | 2012-09-20 14:57:17 -0300 | [diff] [blame] | 689 | case AF9033_TUNER_FC2580: |
Antti Palosaari | 7e0bc29 | 2012-12-02 20:12:29 -0300 | [diff] [blame] | 690 | case AF9033_TUNER_FC0012: |
Antti Palosaari | 2a79eef | 2012-05-07 14:50:40 -0300 | [diff] [blame] | 691 | state->af9033_config[i].spec_inv = 1; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 692 | break; |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 693 | case AF9033_TUNER_IT9135_38: |
| 694 | case AF9033_TUNER_IT9135_51: |
| 695 | case AF9033_TUNER_IT9135_52: |
| 696 | case AF9033_TUNER_IT9135_60: |
| 697 | case AF9033_TUNER_IT9135_61: |
| 698 | case AF9033_TUNER_IT9135_62: |
| 699 | break; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 700 | default: |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 701 | dev_warn(&d->udev->dev, |
| 702 | "%s: tuner id=%02x not supported, please report!", |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 703 | KBUILD_MODNAME, tmp); |
Peter Senna Tschudin | c2c1b41 | 2012-09-28 05:37:22 -0300 | [diff] [blame] | 704 | } |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 705 | |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 706 | /* disable dual mode if driver does not support it */ |
| 707 | if (i == 1) |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 708 | switch (state->af9033_config[i].tuner) { |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 709 | case AF9033_TUNER_FC0012: |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 710 | case AF9033_TUNER_IT9135_38: |
| 711 | case AF9033_TUNER_IT9135_51: |
| 712 | case AF9033_TUNER_IT9135_52: |
| 713 | case AF9033_TUNER_IT9135_60: |
| 714 | case AF9033_TUNER_IT9135_61: |
| 715 | case AF9033_TUNER_IT9135_62: |
Jose Alberto Reguero | 78c7bc4 | 2013-02-10 15:43:03 -0300 | [diff] [blame] | 716 | case AF9033_TUNER_MXL5007T: |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 717 | break; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 718 | default: |
| 719 | state->dual_mode = false; |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 720 | dev_info(&d->udev->dev, |
| 721 | "%s: driver does not support 2nd tuner and will disable it", |
| 722 | KBUILD_MODNAME); |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 723 | } |
| 724 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 725 | /* tuner IF frequency */ |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 726 | ret = af9035_rd_reg(d, addr + EEPROM_1_IF_L, &tmp); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 727 | if (ret < 0) |
| 728 | goto err; |
| 729 | |
| 730 | tmp16 = tmp; |
| 731 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 732 | ret = af9035_rd_reg(d, addr + EEPROM_1_IF_H, &tmp); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 733 | if (ret < 0) |
| 734 | goto err; |
| 735 | |
| 736 | tmp16 |= tmp << 8; |
| 737 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 738 | dev_dbg(&d->udev->dev, "%s: [%d]IF=%d\n", __func__, i, tmp16); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 739 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 740 | addr += 0x10; /* shift for the 2nd tuner params */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 741 | } |
| 742 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 743 | skip_eeprom: |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 744 | /* get demod clock */ |
| 745 | ret = af9035_rd_reg(d, 0x00d800, &tmp); |
| 746 | if (ret < 0) |
| 747 | goto err; |
| 748 | |
| 749 | tmp = (tmp >> 0) & 0x0f; |
| 750 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 751 | for (i = 0; i < ARRAY_SIZE(state->af9033_config); i++) { |
| 752 | if (state->chip_type == 0x9135) |
| 753 | state->af9033_config[i].clock = clock_lut_it9135[tmp]; |
| 754 | else |
| 755 | state->af9033_config[i].clock = clock_lut_af9035[tmp]; |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 756 | } |
| 757 | |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 758 | return 0; |
| 759 | |
| 760 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 761 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 762 | |
| 763 | return ret; |
| 764 | } |
| 765 | |
Antti Palosaari | 51639be | 2012-09-16 22:26:56 -0300 | [diff] [blame] | 766 | static int af9035_tua9001_tuner_callback(struct dvb_usb_device *d, |
| 767 | int cmd, int arg) |
| 768 | { |
| 769 | int ret; |
| 770 | u8 val; |
| 771 | |
| 772 | dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg); |
| 773 | |
| 774 | /* |
| 775 | * CEN always enabled by hardware wiring |
| 776 | * RESETN GPIOT3 |
| 777 | * RXEN GPIOT2 |
| 778 | */ |
| 779 | |
| 780 | switch (cmd) { |
| 781 | case TUA9001_CMD_RESETN: |
| 782 | if (arg) |
| 783 | val = 0x00; |
| 784 | else |
| 785 | val = 0x01; |
| 786 | |
| 787 | ret = af9035_wr_reg_mask(d, 0x00d8e7, val, 0x01); |
| 788 | if (ret < 0) |
| 789 | goto err; |
| 790 | break; |
| 791 | case TUA9001_CMD_RXEN: |
| 792 | if (arg) |
| 793 | val = 0x01; |
| 794 | else |
| 795 | val = 0x00; |
| 796 | |
| 797 | ret = af9035_wr_reg_mask(d, 0x00d8eb, val, 0x01); |
| 798 | if (ret < 0) |
| 799 | goto err; |
| 800 | break; |
| 801 | } |
| 802 | |
| 803 | return 0; |
| 804 | |
| 805 | err: |
| 806 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 807 | |
| 808 | return ret; |
| 809 | } |
| 810 | |
| 811 | |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 812 | static int af9035_fc0011_tuner_callback(struct dvb_usb_device *d, |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 813 | int cmd, int arg) |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 814 | { |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 815 | int ret; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 816 | |
| 817 | switch (cmd) { |
| 818 | case FC0011_FE_CALLBACK_POWER: |
| 819 | /* Tuner enable */ |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 820 | ret = af9035_wr_reg_mask(d, 0xd8eb, 1, 1); |
| 821 | if (ret < 0) |
| 822 | goto err; |
| 823 | |
| 824 | ret = af9035_wr_reg_mask(d, 0xd8ec, 1, 1); |
| 825 | if (ret < 0) |
| 826 | goto err; |
| 827 | |
| 828 | ret = af9035_wr_reg_mask(d, 0xd8ed, 1, 1); |
| 829 | if (ret < 0) |
| 830 | goto err; |
| 831 | |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 832 | /* LED */ |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 833 | ret = af9035_wr_reg_mask(d, 0xd8d0, 1, 1); |
| 834 | if (ret < 0) |
| 835 | goto err; |
| 836 | |
| 837 | ret = af9035_wr_reg_mask(d, 0xd8d1, 1, 1); |
| 838 | if (ret < 0) |
| 839 | goto err; |
| 840 | |
Michael Büsch | de2bec5 | 2012-04-03 05:11:30 -0300 | [diff] [blame] | 841 | usleep_range(10000, 50000); |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 842 | break; |
| 843 | case FC0011_FE_CALLBACK_RESET: |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 844 | ret = af9035_wr_reg(d, 0xd8e9, 1); |
| 845 | if (ret < 0) |
| 846 | goto err; |
| 847 | |
| 848 | ret = af9035_wr_reg(d, 0xd8e8, 1); |
| 849 | if (ret < 0) |
| 850 | goto err; |
| 851 | |
| 852 | ret = af9035_wr_reg(d, 0xd8e7, 1); |
| 853 | if (ret < 0) |
| 854 | goto err; |
| 855 | |
Michael Büsch | de2bec5 | 2012-04-03 05:11:30 -0300 | [diff] [blame] | 856 | usleep_range(10000, 20000); |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 857 | |
| 858 | ret = af9035_wr_reg(d, 0xd8e7, 0); |
| 859 | if (ret < 0) |
| 860 | goto err; |
| 861 | |
Michael Büsch | de2bec5 | 2012-04-03 05:11:30 -0300 | [diff] [blame] | 862 | usleep_range(10000, 20000); |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 863 | break; |
| 864 | default: |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 865 | ret = -EINVAL; |
| 866 | goto err; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | return 0; |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 870 | |
| 871 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 872 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 873 | |
| 874 | return ret; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | static int af9035_tuner_callback(struct dvb_usb_device *d, int cmd, int arg) |
| 878 | { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 879 | struct state *state = d_to_priv(d); |
Antti Palosaari | 2a79eef | 2012-05-07 14:50:40 -0300 | [diff] [blame] | 880 | |
| 881 | switch (state->af9033_config[0].tuner) { |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 882 | case AF9033_TUNER_FC0011: |
| 883 | return af9035_fc0011_tuner_callback(d, cmd, arg); |
Antti Palosaari | 51639be | 2012-09-16 22:26:56 -0300 | [diff] [blame] | 884 | case AF9033_TUNER_TUA9001: |
| 885 | return af9035_tua9001_tuner_callback(d, cmd, arg); |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 886 | default: |
| 887 | break; |
| 888 | } |
| 889 | |
Antti Palosaari | 1835af1 | 2012-09-11 22:27:06 -0300 | [diff] [blame] | 890 | return 0; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | static int af9035_frontend_callback(void *adapter_priv, int component, |
| 894 | int cmd, int arg) |
| 895 | { |
| 896 | struct i2c_adapter *adap = adapter_priv; |
| 897 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 898 | |
Antti Palosaari | 1835af1 | 2012-09-11 22:27:06 -0300 | [diff] [blame] | 899 | dev_dbg(&d->udev->dev, "%s: component=%d cmd=%d arg=%d\n", |
| 900 | __func__, component, cmd, arg); |
| 901 | |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 902 | switch (component) { |
| 903 | case DVB_FRONTEND_COMPONENT_TUNER: |
| 904 | return af9035_tuner_callback(d, cmd, arg); |
| 905 | default: |
| 906 | break; |
| 907 | } |
| 908 | |
Antti Palosaari | 1835af1 | 2012-09-11 22:27:06 -0300 | [diff] [blame] | 909 | return 0; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 910 | } |
| 911 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 912 | static int af9035_get_adapter_count(struct dvb_usb_device *d) |
| 913 | { |
| 914 | struct state *state = d_to_priv(d); |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 915 | |
| 916 | /* disable 2nd adapter as we don't have PID filters implemented */ |
| 917 | if (d->udev->speed == USB_SPEED_FULL) |
| 918 | return 1; |
| 919 | else |
| 920 | return state->dual_mode + 1; |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 921 | } |
| 922 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 923 | static int af9035_frontend_attach(struct dvb_usb_adapter *adap) |
| 924 | { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 925 | struct state *state = adap_to_priv(adap); |
| 926 | struct dvb_usb_device *d = adap_to_d(adap); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 927 | int ret; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 928 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 929 | |
Antti Palosaari | 1cbabf9 | 2012-05-07 14:59:55 -0300 | [diff] [blame] | 930 | if (!state->af9033_config[adap->id].tuner) { |
| 931 | /* unsupported tuner */ |
Antti Palosaari | 5a9abae | 2012-03-30 17:15:16 -0300 | [diff] [blame] | 932 | ret = -ENODEV; |
| 933 | goto err; |
| 934 | } |
| 935 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 936 | /* attach demodulator */ |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 937 | adap->fe[0] = dvb_attach(af9033_attach, &state->af9033_config[adap->id], |
| 938 | &d->i2c_adap); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 939 | if (adap->fe[0] == NULL) { |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 940 | ret = -ENODEV; |
| 941 | goto err; |
| 942 | } |
Antti Palosaari | 852f0d9 | 2012-04-06 07:09:23 -0300 | [diff] [blame] | 943 | |
| 944 | /* disable I2C-gate */ |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 945 | adap->fe[0]->ops.i2c_gate_ctrl = NULL; |
| 946 | adap->fe[0]->callback = af9035_frontend_callback; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 947 | |
| 948 | return 0; |
| 949 | |
| 950 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 951 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 952 | |
| 953 | return ret; |
| 954 | } |
| 955 | |
| 956 | static struct tua9001_config af9035_tua9001_config = { |
| 957 | .i2c_addr = 0x60, |
| 958 | }; |
| 959 | |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 960 | static const struct fc0011_config af9035_fc0011_config = { |
| 961 | .i2c_address = 0x60, |
| 962 | }; |
| 963 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 964 | static struct mxl5007t_config af9035_mxl5007t_config[] = { |
| 965 | { |
| 966 | .xtal_freq_hz = MxL_XTAL_24_MHZ, |
| 967 | .if_freq_hz = MxL_IF_4_57_MHZ, |
| 968 | .invert_if = 0, |
| 969 | .loop_thru_enable = 0, |
| 970 | .clk_out_enable = 0, |
| 971 | .clk_out_amp = MxL_CLKOUT_AMP_0_94V, |
| 972 | }, { |
| 973 | .xtal_freq_hz = MxL_XTAL_24_MHZ, |
| 974 | .if_freq_hz = MxL_IF_4_57_MHZ, |
| 975 | .invert_if = 0, |
| 976 | .loop_thru_enable = 1, |
| 977 | .clk_out_enable = 1, |
| 978 | .clk_out_amp = MxL_CLKOUT_AMP_0_94V, |
| 979 | } |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 980 | }; |
| 981 | |
Gianluca Gennari | ce1fe37 | 2012-04-02 17:25:14 -0300 | [diff] [blame] | 982 | static struct tda18218_config af9035_tda18218_config = { |
| 983 | .i2c_address = 0x60, |
| 984 | .i2c_wr_max = 21, |
| 985 | }; |
| 986 | |
Oliver Schinagl | d67ceb3 | 2012-09-20 14:57:17 -0300 | [diff] [blame] | 987 | static const struct fc2580_config af9035_fc2580_config = { |
| 988 | .i2c_addr = 0x56, |
| 989 | .clock = 16384000, |
| 990 | }; |
| 991 | |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 992 | static const struct fc0012_config af9035_fc0012_config[] = { |
| 993 | { |
| 994 | .i2c_address = 0x63, |
| 995 | .xtal_freq = FC_XTAL_36_MHZ, |
Antti Palosaari | 3a98477 | 2012-12-09 12:33:04 -0300 | [diff] [blame] | 996 | .dual_master = true, |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 997 | .loop_through = true, |
| 998 | .clock_out = true, |
| 999 | }, { |
| 1000 | .i2c_address = 0x63 | 0x80, /* I2C bus select hack */ |
| 1001 | .xtal_freq = FC_XTAL_36_MHZ, |
Antti Palosaari | 3a98477 | 2012-12-09 12:33:04 -0300 | [diff] [blame] | 1002 | .dual_master = true, |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1003 | } |
Antti Palosaari | ad3a758 | 2012-12-08 23:27:49 -0300 | [diff] [blame] | 1004 | }; |
| 1005 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1006 | static int af9035_tuner_attach(struct dvb_usb_adapter *adap) |
| 1007 | { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1008 | struct state *state = adap_to_priv(adap); |
| 1009 | struct dvb_usb_device *d = adap_to_d(adap); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1010 | int ret; |
| 1011 | struct dvb_frontend *fe; |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1012 | struct i2c_msg msg[1]; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1013 | u8 tuner_addr; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 1014 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
| 1015 | |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1016 | /* |
| 1017 | * XXX: Hack used in that function: we abuse unused I2C address bit [7] |
| 1018 | * to carry info about used I2C bus for dual tuner configuration. |
| 1019 | */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1020 | |
Antti Palosaari | 2a79eef | 2012-05-07 14:50:40 -0300 | [diff] [blame] | 1021 | switch (state->af9033_config[adap->id].tuner) { |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1022 | case AF9033_TUNER_TUA9001: |
| 1023 | /* AF9035 gpiot3 = TUA9001 RESETN |
| 1024 | AF9035 gpiot2 = TUA9001 RXEN */ |
| 1025 | |
| 1026 | /* configure gpiot2 and gpiot2 as output */ |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1027 | ret = af9035_wr_reg_mask(d, 0x00d8ec, 0x01, 0x01); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1028 | if (ret < 0) |
| 1029 | goto err; |
| 1030 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1031 | ret = af9035_wr_reg_mask(d, 0x00d8ed, 0x01, 0x01); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1032 | if (ret < 0) |
| 1033 | goto err; |
| 1034 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1035 | ret = af9035_wr_reg_mask(d, 0x00d8e8, 0x01, 0x01); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1036 | if (ret < 0) |
| 1037 | goto err; |
| 1038 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1039 | ret = af9035_wr_reg_mask(d, 0x00d8e9, 0x01, 0x01); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1040 | if (ret < 0) |
| 1041 | goto err; |
| 1042 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1043 | /* attach tuner */ |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1044 | fe = dvb_attach(tua9001_attach, adap->fe[0], |
| 1045 | &d->i2c_adap, &af9035_tua9001_config); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1046 | break; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1047 | case AF9033_TUNER_FC0011: |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1048 | fe = dvb_attach(fc0011_attach, adap->fe[0], |
| 1049 | &d->i2c_adap, &af9035_fc0011_config); |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1050 | break; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1051 | case AF9033_TUNER_MXL5007T: |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1052 | if (adap->id == 0) { |
| 1053 | ret = af9035_wr_reg(d, 0x00d8e0, 1); |
| 1054 | if (ret < 0) |
| 1055 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1056 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1057 | ret = af9035_wr_reg(d, 0x00d8e1, 1); |
| 1058 | if (ret < 0) |
| 1059 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1060 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1061 | ret = af9035_wr_reg(d, 0x00d8df, 0); |
| 1062 | if (ret < 0) |
| 1063 | goto err; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1064 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1065 | msleep(30); |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1066 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1067 | ret = af9035_wr_reg(d, 0x00d8df, 1); |
| 1068 | if (ret < 0) |
| 1069 | goto err; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1070 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1071 | msleep(300); |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1072 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1073 | ret = af9035_wr_reg(d, 0x00d8c0, 1); |
| 1074 | if (ret < 0) |
| 1075 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1076 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1077 | ret = af9035_wr_reg(d, 0x00d8c1, 1); |
| 1078 | if (ret < 0) |
| 1079 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1080 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1081 | ret = af9035_wr_reg(d, 0x00d8bf, 0); |
| 1082 | if (ret < 0) |
| 1083 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1084 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1085 | ret = af9035_wr_reg(d, 0x00d8b4, 1); |
| 1086 | if (ret < 0) |
| 1087 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1088 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1089 | ret = af9035_wr_reg(d, 0x00d8b5, 1); |
| 1090 | if (ret < 0) |
| 1091 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1092 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1093 | ret = af9035_wr_reg(d, 0x00d8b3, 1); |
| 1094 | if (ret < 0) |
| 1095 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1096 | |
| 1097 | tuner_addr = 0x60; |
| 1098 | } else { |
| 1099 | tuner_addr = 0x60 | 0x80; /* I2C bus hack */ |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1100 | } |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1101 | |
| 1102 | /* attach tuner */ |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1103 | fe = dvb_attach(mxl5007t_attach, adap->fe[0], &d->i2c_adap, |
| 1104 | tuner_addr, &af9035_mxl5007t_config[adap->id]); |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1105 | break; |
Gianluca Gennari | ce1fe37 | 2012-04-02 17:25:14 -0300 | [diff] [blame] | 1106 | case AF9033_TUNER_TDA18218: |
| 1107 | /* attach tuner */ |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1108 | fe = dvb_attach(tda18218_attach, adap->fe[0], |
| 1109 | &d->i2c_adap, &af9035_tda18218_config); |
Gianluca Gennari | ce1fe37 | 2012-04-02 17:25:14 -0300 | [diff] [blame] | 1110 | break; |
Oliver Schinagl | d67ceb3 | 2012-09-20 14:57:17 -0300 | [diff] [blame] | 1111 | case AF9033_TUNER_FC2580: |
| 1112 | /* Tuner enable using gpiot2_o, gpiot2_en and gpiot2_on */ |
| 1113 | ret = af9035_wr_reg_mask(d, 0xd8eb, 0x01, 0x01); |
| 1114 | if (ret < 0) |
| 1115 | goto err; |
| 1116 | |
| 1117 | ret = af9035_wr_reg_mask(d, 0xd8ec, 0x01, 0x01); |
| 1118 | if (ret < 0) |
| 1119 | goto err; |
| 1120 | |
| 1121 | ret = af9035_wr_reg_mask(d, 0xd8ed, 0x01, 0x01); |
| 1122 | if (ret < 0) |
| 1123 | goto err; |
| 1124 | |
| 1125 | usleep_range(10000, 50000); |
| 1126 | /* attach tuner */ |
| 1127 | fe = dvb_attach(fc2580_attach, adap->fe[0], |
| 1128 | &d->i2c_adap, &af9035_fc2580_config); |
| 1129 | break; |
Antti Palosaari | 7e0bc29 | 2012-12-02 20:12:29 -0300 | [diff] [blame] | 1130 | case AF9033_TUNER_FC0012: |
| 1131 | /* |
| 1132 | * AF9035 gpiot2 = FC0012 enable |
| 1133 | * XXX: there seems to be something on gpioh8 too, but on my |
| 1134 | * my test I didn't find any difference. |
| 1135 | */ |
| 1136 | |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1137 | if (adap->id == 0) { |
| 1138 | /* configure gpiot2 as output and high */ |
| 1139 | ret = af9035_wr_reg_mask(d, 0xd8eb, 0x01, 0x01); |
| 1140 | if (ret < 0) |
| 1141 | goto err; |
Antti Palosaari | 7e0bc29 | 2012-12-02 20:12:29 -0300 | [diff] [blame] | 1142 | |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1143 | ret = af9035_wr_reg_mask(d, 0xd8ec, 0x01, 0x01); |
| 1144 | if (ret < 0) |
| 1145 | goto err; |
Antti Palosaari | 7e0bc29 | 2012-12-02 20:12:29 -0300 | [diff] [blame] | 1146 | |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1147 | ret = af9035_wr_reg_mask(d, 0xd8ed, 0x01, 0x01); |
| 1148 | if (ret < 0) |
| 1149 | goto err; |
| 1150 | } else { |
| 1151 | /* |
| 1152 | * FIXME: That belongs for the FC0012 driver. |
| 1153 | * Write 02 to FC0012 master tuner register 0d directly |
| 1154 | * in order to make slave tuner working. |
| 1155 | */ |
| 1156 | msg[0].addr = 0x63; |
| 1157 | msg[0].flags = 0; |
| 1158 | msg[0].len = 2; |
| 1159 | msg[0].buf = "\x0d\x02"; |
| 1160 | ret = i2c_transfer(&d->i2c_adap, msg, 1); |
| 1161 | if (ret < 0) |
| 1162 | goto err; |
| 1163 | } |
Antti Palosaari | 7e0bc29 | 2012-12-02 20:12:29 -0300 | [diff] [blame] | 1164 | |
| 1165 | usleep_range(10000, 50000); |
| 1166 | |
Antti Palosaari | ad3a758 | 2012-12-08 23:27:49 -0300 | [diff] [blame] | 1167 | fe = dvb_attach(fc0012_attach, adap->fe[0], &d->i2c_adap, |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1168 | &af9035_fc0012_config[adap->id]); |
Antti Palosaari | 7e0bc29 | 2012-12-02 20:12:29 -0300 | [diff] [blame] | 1169 | break; |
Antti Palosaari | ac77fb0 | 2013-01-07 09:51:13 -0300 | [diff] [blame] | 1170 | case AF9033_TUNER_IT9135_38: |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 1171 | case AF9033_TUNER_IT9135_51: |
| 1172 | case AF9033_TUNER_IT9135_52: |
| 1173 | case AF9033_TUNER_IT9135_60: |
| 1174 | case AF9033_TUNER_IT9135_61: |
| 1175 | case AF9033_TUNER_IT9135_62: |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 1176 | /* attach tuner */ |
| 1177 | fe = dvb_attach(it913x_attach, adap->fe[0], &d->i2c_adap, |
| 1178 | state->af9033_config[adap->id].i2c_addr, |
Antti Palosaari | 44af747 | 2013-02-28 00:14:06 -0300 | [diff] [blame] | 1179 | state->af9033_config[0].tuner); |
Antti Palosaari | ac77fb0 | 2013-01-07 09:51:13 -0300 | [diff] [blame] | 1180 | break; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1181 | default: |
| 1182 | fe = NULL; |
| 1183 | } |
| 1184 | |
| 1185 | if (fe == NULL) { |
| 1186 | ret = -ENODEV; |
| 1187 | goto err; |
| 1188 | } |
| 1189 | |
| 1190 | return 0; |
| 1191 | |
| 1192 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 1193 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1194 | |
| 1195 | return ret; |
| 1196 | } |
| 1197 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1198 | static int af9035_init(struct dvb_usb_device *d) |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1199 | { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1200 | struct state *state = d_to_priv(d); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1201 | int ret, i; |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 1202 | u16 frame_size = (d->udev->speed == USB_SPEED_FULL ? 5 : 87) * 188 / 4; |
| 1203 | u8 packet_size = (d->udev->speed == USB_SPEED_FULL ? 64 : 512) / 4; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1204 | struct reg_val_mask tab[] = { |
| 1205 | { 0x80f99d, 0x01, 0x01 }, |
| 1206 | { 0x80f9a4, 0x01, 0x01 }, |
| 1207 | { 0x00dd11, 0x00, 0x20 }, |
| 1208 | { 0x00dd11, 0x00, 0x40 }, |
| 1209 | { 0x00dd13, 0x00, 0x20 }, |
| 1210 | { 0x00dd13, 0x00, 0x40 }, |
| 1211 | { 0x00dd11, 0x20, 0x20 }, |
| 1212 | { 0x00dd88, (frame_size >> 0) & 0xff, 0xff}, |
| 1213 | { 0x00dd89, (frame_size >> 8) & 0xff, 0xff}, |
| 1214 | { 0x00dd0c, packet_size, 0xff}, |
| 1215 | { 0x00dd11, state->dual_mode << 6, 0x40 }, |
| 1216 | { 0x00dd8a, (frame_size >> 0) & 0xff, 0xff}, |
| 1217 | { 0x00dd8b, (frame_size >> 8) & 0xff, 0xff}, |
| 1218 | { 0x00dd0d, packet_size, 0xff }, |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1219 | { 0x80f9a3, state->dual_mode, 0x01 }, |
| 1220 | { 0x80f9cd, state->dual_mode, 0x01 }, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1221 | { 0x80f99d, 0x00, 0x01 }, |
| 1222 | { 0x80f9a4, 0x00, 0x01 }, |
| 1223 | }; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1224 | |
Antti Palosaari | cb9114e | 2013-06-03 18:42:14 -0300 | [diff] [blame] | 1225 | dev_dbg(&d->udev->dev, |
| 1226 | "%s: USB speed=%d frame_size=%04x packet_size=%02x\n", |
| 1227 | __func__, d->udev->speed, frame_size, packet_size); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1228 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1229 | /* init endpoints */ |
| 1230 | for (i = 0; i < ARRAY_SIZE(tab); i++) { |
| 1231 | ret = af9035_wr_reg_mask(d, tab[i].reg, tab[i].val, |
| 1232 | tab[i].mask); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1233 | if (ret < 0) |
| 1234 | goto err; |
| 1235 | } |
| 1236 | |
| 1237 | return 0; |
| 1238 | |
| 1239 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 1240 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1241 | |
| 1242 | return ret; |
| 1243 | } |
| 1244 | |
Antti Palosaari | 37b44a0 | 2013-01-04 15:21:26 -0300 | [diff] [blame] | 1245 | #if IS_ENABLED(CONFIG_RC_CORE) |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1246 | static int af9035_rc_query(struct dvb_usb_device *d) |
| 1247 | { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1248 | int ret; |
Antti Palosaari | 75cd588 | 2013-03-08 17:50:21 -0300 | [diff] [blame] | 1249 | u32 key; |
| 1250 | u8 buf[4]; |
| 1251 | struct usb_req req = { CMD_IR_GET, 0, 0, NULL, 4, buf }; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1252 | |
| 1253 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | 1bfd529 | 2013-03-08 17:39:12 -0300 | [diff] [blame] | 1254 | if (ret == 1) |
| 1255 | return 0; |
| 1256 | else if (ret < 0) |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1257 | goto err; |
| 1258 | |
Antti Palosaari | 75cd588 | 2013-03-08 17:50:21 -0300 | [diff] [blame] | 1259 | if ((buf[2] + buf[3]) == 0xff) { |
| 1260 | if ((buf[0] + buf[1]) == 0xff) { |
| 1261 | /* NEC standard 16bit */ |
| 1262 | key = buf[0] << 8 | buf[2]; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1263 | } else { |
Antti Palosaari | 75cd588 | 2013-03-08 17:50:21 -0300 | [diff] [blame] | 1264 | /* NEC extended 24bit */ |
| 1265 | key = buf[0] << 16 | buf[1] << 8 | buf[2]; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1266 | } |
| 1267 | } else { |
Antti Palosaari | 75cd588 | 2013-03-08 17:50:21 -0300 | [diff] [blame] | 1268 | /* NEC full code 32bit */ |
| 1269 | key = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1270 | } |
| 1271 | |
Antti Palosaari | 75cd588 | 2013-03-08 17:50:21 -0300 | [diff] [blame] | 1272 | dev_dbg(&d->udev->dev, "%s: %*ph\n", __func__, 4, buf); |
| 1273 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1274 | rc_keydown(d->rc_dev, key, 0); |
| 1275 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1276 | return 0; |
Antti Palosaari | 1bfd529 | 2013-03-08 17:39:12 -0300 | [diff] [blame] | 1277 | |
| 1278 | err: |
| 1279 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 1280 | |
| 1281 | return ret; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | static int af9035_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc) |
| 1285 | { |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 1286 | struct state *state = d_to_priv(d); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1287 | int ret; |
| 1288 | u8 tmp; |
| 1289 | |
Antti Palosaari | 431a6d4 | 2013-03-07 18:28:25 -0300 | [diff] [blame] | 1290 | ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_IR_MODE, &tmp); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1291 | if (ret < 0) |
| 1292 | goto err; |
| 1293 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 1294 | dev_dbg(&d->udev->dev, "%s: ir_mode=%02x\n", __func__, tmp); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1295 | |
| 1296 | /* don't activate rc if in HID mode or if not available */ |
| 1297 | if (tmp == 5) { |
Antti Palosaari | 431a6d4 | 2013-03-07 18:28:25 -0300 | [diff] [blame] | 1298 | ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_IR_TYPE, |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 1299 | &tmp); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1300 | if (ret < 0) |
| 1301 | goto err; |
| 1302 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 1303 | dev_dbg(&d->udev->dev, "%s: ir_type=%02x\n", __func__, tmp); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1304 | |
| 1305 | switch (tmp) { |
| 1306 | case 0: /* NEC */ |
| 1307 | default: |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1308 | rc->allowed_protos = RC_BIT_NEC; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1309 | break; |
| 1310 | case 1: /* RC6 */ |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1311 | rc->allowed_protos = RC_BIT_RC6_MCE; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1312 | break; |
| 1313 | } |
| 1314 | |
| 1315 | rc->query = af9035_rc_query; |
| 1316 | rc->interval = 500; |
Antti Palosaari | de73bee | 2012-07-05 19:57:07 -0300 | [diff] [blame] | 1317 | |
| 1318 | /* load empty to enable rc */ |
| 1319 | if (!rc->map_name) |
| 1320 | rc->map_name = RC_MAP_EMPTY; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | return 0; |
| 1324 | |
| 1325 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 1326 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1327 | |
| 1328 | return ret; |
| 1329 | } |
Antti Palosaari | eed5670 | 2012-12-09 20:18:31 -0300 | [diff] [blame] | 1330 | #else |
| 1331 | #define af9035_get_rc_config NULL |
| 1332 | #endif |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1333 | |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 1334 | static int af9035_get_stream_config(struct dvb_frontend *fe, u8 *ts_type, |
| 1335 | struct usb_data_stream_properties *stream) |
| 1336 | { |
| 1337 | struct dvb_usb_device *d = fe_to_d(fe); |
| 1338 | dev_dbg(&d->udev->dev, "%s: adap=%d\n", __func__, fe_to_adap(fe)->id); |
| 1339 | |
| 1340 | if (d->udev->speed == USB_SPEED_FULL) |
| 1341 | stream->u.bulk.buffersize = 5 * 188; |
| 1342 | |
| 1343 | return 0; |
| 1344 | } |
| 1345 | |
| 1346 | /* |
| 1347 | * FIXME: PID filter is property of demodulator and should be moved to the |
| 1348 | * correct driver. Also we support only adapter #0 PID filter and will |
| 1349 | * disable adapter #1 if USB1.1 is used. |
| 1350 | */ |
| 1351 | static int af9035_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 1352 | { |
| 1353 | struct dvb_usb_device *d = adap_to_d(adap); |
| 1354 | int ret; |
| 1355 | |
| 1356 | dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff); |
| 1357 | |
| 1358 | ret = af9035_wr_reg_mask(d, 0x80f993, onoff, 0x01); |
| 1359 | if (ret < 0) |
| 1360 | goto err; |
| 1361 | |
| 1362 | return 0; |
| 1363 | |
| 1364 | err: |
| 1365 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 1366 | |
| 1367 | return ret; |
| 1368 | } |
| 1369 | |
| 1370 | static int af9035_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, |
| 1371 | int onoff) |
| 1372 | { |
| 1373 | struct dvb_usb_device *d = adap_to_d(adap); |
| 1374 | int ret; |
| 1375 | u8 wbuf[2] = {(pid >> 0) & 0xff, (pid >> 8) & 0xff}; |
| 1376 | |
| 1377 | dev_dbg(&d->udev->dev, "%s: index=%d pid=%04x onoff=%d\n", |
| 1378 | __func__, index, pid, onoff); |
| 1379 | |
| 1380 | ret = af9035_wr_regs(d, 0x80f996, wbuf, 2); |
| 1381 | if (ret < 0) |
| 1382 | goto err; |
| 1383 | |
| 1384 | ret = af9035_wr_reg(d, 0x80f994, onoff); |
| 1385 | if (ret < 0) |
| 1386 | goto err; |
| 1387 | |
| 1388 | ret = af9035_wr_reg(d, 0x80f995, index); |
| 1389 | if (ret < 0) |
| 1390 | goto err; |
| 1391 | |
| 1392 | return 0; |
| 1393 | |
| 1394 | err: |
| 1395 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 1396 | |
| 1397 | return ret; |
| 1398 | } |
| 1399 | |
Antti Palosaari | b799b81 | 2013-01-11 16:22:07 -0300 | [diff] [blame] | 1400 | static int af9035_probe(struct usb_interface *intf, |
| 1401 | const struct usb_device_id *id) |
| 1402 | { |
| 1403 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1404 | char manufacturer[sizeof("Afatech")]; |
| 1405 | |
| 1406 | memset(manufacturer, 0, sizeof(manufacturer)); |
| 1407 | usb_string(udev, udev->descriptor.iManufacturer, |
| 1408 | manufacturer, sizeof(manufacturer)); |
| 1409 | /* |
| 1410 | * There is two devices having same ID but different chipset. One uses |
| 1411 | * AF9015 and the other IT9135 chipset. Only difference seen on lsusb |
| 1412 | * is iManufacturer string. |
| 1413 | * |
| 1414 | * idVendor 0x0ccd TerraTec Electronic GmbH |
| 1415 | * idProduct 0x0099 |
| 1416 | * bcdDevice 2.00 |
| 1417 | * iManufacturer 1 Afatech |
| 1418 | * iProduct 2 DVB-T 2 |
| 1419 | * |
| 1420 | * idVendor 0x0ccd TerraTec Electronic GmbH |
| 1421 | * idProduct 0x0099 |
| 1422 | * bcdDevice 2.00 |
| 1423 | * iManufacturer 1 ITE Technologies, Inc. |
| 1424 | * iProduct 2 DVB-T TV Stick |
| 1425 | */ |
| 1426 | if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VID_TERRATEC) && |
| 1427 | (le16_to_cpu(udev->descriptor.idProduct) == 0x0099)) { |
| 1428 | if (!strcmp("Afatech", manufacturer)) { |
| 1429 | dev_dbg(&udev->dev, "%s: rejecting device\n", __func__); |
| 1430 | return -ENODEV; |
| 1431 | } |
| 1432 | } |
| 1433 | |
| 1434 | return dvb_usbv2_probe(intf, id); |
| 1435 | } |
| 1436 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1437 | /* interface 0 is used by DVB-T receiver and |
| 1438 | interface 1 is for remote controller (HID) */ |
| 1439 | static const struct dvb_usb_device_properties af9035_props = { |
| 1440 | .driver_name = KBUILD_MODNAME, |
| 1441 | .owner = THIS_MODULE, |
| 1442 | .adapter_nr = adapter_nr, |
| 1443 | .size_of_priv = sizeof(struct state), |
| 1444 | |
| 1445 | .generic_bulk_ctrl_endpoint = 0x02, |
| 1446 | .generic_bulk_ctrl_endpoint_response = 0x81, |
| 1447 | |
| 1448 | .identify_state = af9035_identify_state, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1449 | .download_firmware = af9035_download_firmware, |
| 1450 | |
| 1451 | .i2c_algo = &af9035_i2c_algo, |
| 1452 | .read_config = af9035_read_config, |
| 1453 | .frontend_attach = af9035_frontend_attach, |
| 1454 | .tuner_attach = af9035_tuner_attach, |
| 1455 | .init = af9035_init, |
| 1456 | .get_rc_config = af9035_get_rc_config, |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 1457 | .get_stream_config = af9035_get_stream_config, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1458 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1459 | .get_adapter_count = af9035_get_adapter_count, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1460 | .adapter = { |
| 1461 | { |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 1462 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | |
| 1463 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, |
| 1464 | |
| 1465 | .pid_filter_count = 32, |
| 1466 | .pid_filter_ctrl = af9035_pid_filter_ctrl, |
| 1467 | .pid_filter = af9035_pid_filter, |
| 1468 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1469 | .stream = DVB_USB_STREAM_BULK(0x84, 6, 87 * 188), |
| 1470 | }, { |
| 1471 | .stream = DVB_USB_STREAM_BULK(0x85, 6, 87 * 188), |
| 1472 | }, |
| 1473 | }, |
| 1474 | }; |
| 1475 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1476 | static const struct usb_device_id af9035_id_table[] = { |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 1477 | /* AF9035 devices */ |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1478 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_9035, |
| 1479 | &af9035_props, "Afatech AF9035 reference design", NULL) }, |
| 1480 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1000, |
| 1481 | &af9035_props, "Afatech AF9035 reference design", NULL) }, |
| 1482 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1001, |
| 1483 | &af9035_props, "Afatech AF9035 reference design", NULL) }, |
| 1484 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1002, |
| 1485 | &af9035_props, "Afatech AF9035 reference design", NULL) }, |
| 1486 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1003, |
| 1487 | &af9035_props, "Afatech AF9035 reference design", NULL) }, |
| 1488 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK, |
| 1489 | &af9035_props, "TerraTec Cinergy T Stick", NULL) }, |
| 1490 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835, |
| 1491 | &af9035_props, "AVerMedia AVerTV Volar HD/PRO (A835)", NULL) }, |
| 1492 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_B835, |
| 1493 | &af9035_props, "AVerMedia AVerTV Volar HD/PRO (A835)", NULL) }, |
| 1494 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_1867, |
| 1495 | &af9035_props, "AVerMedia HD Volar (A867)", NULL) }, |
| 1496 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A867, |
| 1497 | &af9035_props, "AVerMedia HD Volar (A867)", NULL) }, |
| 1498 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_TWINSTAR, |
| 1499 | &af9035_props, "AVerMedia Twinstar (A825)", NULL) }, |
Oliver Schinagl | d67ceb3 | 2012-09-20 14:57:17 -0300 | [diff] [blame] | 1500 | { DVB_USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3100MINI_PLUS, |
| 1501 | &af9035_props, "Asus U3100Mini Plus", NULL) }, |
Antti Palosaari | cb9114e | 2013-06-03 18:42:14 -0300 | [diff] [blame] | 1502 | { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00aa, |
Fabrizio Gazzato | d9b7595 | 2013-02-17 18:25:34 -0300 | [diff] [blame] | 1503 | &af9035_props, "TerraTec Cinergy T Stick (rev. 2)", NULL) }, |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 1504 | /* IT9135 devices */ |
| 1505 | #if 0 |
| 1506 | { DVB_USB_DEVICE(0x048d, 0x9135, |
| 1507 | &af9035_props, "IT9135 reference design", NULL) }, |
| 1508 | { DVB_USB_DEVICE(0x048d, 0x9006, |
| 1509 | &af9035_props, "IT9135 reference design", NULL) }, |
| 1510 | #endif |
Antti Palosaari | b799b81 | 2013-01-11 16:22:07 -0300 | [diff] [blame] | 1511 | /* XXX: that same ID [0ccd:0099] is used by af9015 driver too */ |
| 1512 | { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x0099, |
| 1513 | &af9035_props, "TerraTec Cinergy T Stick Dual RC (rev. 2)", NULL) }, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1514 | { } |
| 1515 | }; |
| 1516 | MODULE_DEVICE_TABLE(usb, af9035_id_table); |
| 1517 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1518 | static struct usb_driver af9035_usb_driver = { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1519 | .name = KBUILD_MODNAME, |
| 1520 | .id_table = af9035_id_table, |
Antti Palosaari | b799b81 | 2013-01-11 16:22:07 -0300 | [diff] [blame] | 1521 | .probe = af9035_probe, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1522 | .disconnect = dvb_usbv2_disconnect, |
| 1523 | .suspend = dvb_usbv2_suspend, |
| 1524 | .resume = dvb_usbv2_resume, |
Antti Palosaari | 04966aa | 2012-08-14 22:21:08 -0300 | [diff] [blame] | 1525 | .reset_resume = dvb_usbv2_reset_resume, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1526 | .no_dynamic_id = 1, |
| 1527 | .soft_unbind = 1, |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1528 | }; |
| 1529 | |
Gianluca Gennari | 48bf7e1 | 2012-04-02 17:25:17 -0300 | [diff] [blame] | 1530 | module_usb_driver(af9035_usb_driver); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1531 | |
| 1532 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 1533 | MODULE_DESCRIPTION("Afatech AF9035 driver"); |
| 1534 | MODULE_LICENSE("GPL"); |
Antti Palosaari | 4395e4b | 2012-09-12 12:19:06 -0300 | [diff] [blame] | 1535 | MODULE_FIRMWARE(AF9035_FIRMWARE_AF9035); |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 1536 | MODULE_FIRMWARE(AF9035_FIRMWARE_IT9135_V1); |
| 1537 | MODULE_FIRMWARE(AF9035_FIRMWARE_IT9135_V2); |