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 | |
Mauro Carvalho Chehab | 7760e14 | 2013-11-02 08:07:12 -0300 | [diff] [blame] | 24 | /* Max transfer size done by I2C transfer functions */ |
| 25 | #define MAX_XFER_SIZE 64 |
| 26 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 27 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 28 | |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 29 | static u16 af9035_checksum(const u8 *buf, size_t len) |
| 30 | { |
| 31 | size_t i; |
| 32 | u16 checksum = 0; |
| 33 | |
| 34 | for (i = 1; i < len; i++) { |
| 35 | if (i % 2) |
| 36 | checksum += buf[i] << 8; |
| 37 | else |
| 38 | checksum += buf[i]; |
| 39 | } |
| 40 | checksum = ~checksum; |
| 41 | |
| 42 | return checksum; |
| 43 | } |
| 44 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 45 | 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] | 46 | { |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 47 | #define REQ_HDR_LEN 4 /* send header size */ |
| 48 | #define ACK_HDR_LEN 3 /* rece header size */ |
| 49 | #define CHECKSUM_LEN 2 |
| 50 | #define USB_TIMEOUT 2000 |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 51 | struct state *state = d_to_priv(d); |
| 52 | int ret, wlen, rlen; |
Antti Palosaari | 6fb39c5 | 2012-04-06 16:32:30 -0300 | [diff] [blame] | 53 | u16 checksum, tmp_checksum; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 54 | |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 55 | mutex_lock(&d->usb_mutex); |
| 56 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 57 | /* buffer overflow check */ |
| 58 | if (req->wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) || |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 59 | req->rlen > (BUF_LEN - ACK_HDR_LEN - CHECKSUM_LEN)) { |
| 60 | 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] | 61 | KBUILD_MODNAME, req->wlen, req->rlen); |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 62 | ret = -EINVAL; |
Wei Yongjun | 0170a39 | 2013-03-26 01:32:19 -0300 | [diff] [blame] | 63 | goto exit; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 64 | } |
| 65 | |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 66 | state->buf[0] = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN - 1; |
| 67 | state->buf[1] = req->mbox; |
| 68 | state->buf[2] = req->cmd; |
| 69 | state->buf[3] = state->seq++; |
| 70 | memcpy(&state->buf[REQ_HDR_LEN], req->wbuf, req->wlen); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 71 | |
| 72 | wlen = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN; |
| 73 | rlen = ACK_HDR_LEN + req->rlen + CHECKSUM_LEN; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 74 | |
| 75 | /* calc and add checksum */ |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 76 | checksum = af9035_checksum(state->buf, state->buf[0] - 1); |
| 77 | state->buf[state->buf[0] - 1] = (checksum >> 8); |
| 78 | state->buf[state->buf[0] - 0] = (checksum & 0xff); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 79 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 80 | /* no ack for these packets */ |
| 81 | if (req->cmd == CMD_FW_DL) |
| 82 | rlen = 0; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 83 | |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 84 | ret = dvb_usbv2_generic_rw_locked(d, |
| 85 | state->buf, wlen, state->buf, rlen); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 86 | if (ret) |
Wei Yongjun | 0170a39 | 2013-03-26 01:32:19 -0300 | [diff] [blame] | 87 | goto exit; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 88 | |
| 89 | /* no ack for those packets */ |
| 90 | if (req->cmd == CMD_FW_DL) |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 91 | goto exit; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 92 | |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 93 | /* verify checksum */ |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 94 | checksum = af9035_checksum(state->buf, rlen - 2); |
| 95 | tmp_checksum = (state->buf[rlen - 2] << 8) | state->buf[rlen - 1]; |
Antti Palosaari | 6fb39c5 | 2012-04-06 16:32:30 -0300 | [diff] [blame] | 96 | if (tmp_checksum != checksum) { |
Antti Palosaari | cb9114e | 2013-06-03 18:42:14 -0300 | [diff] [blame] | 97 | dev_err(&d->udev->dev, |
| 98 | "%s: command=%02x checksum mismatch (%04x != %04x)\n", |
| 99 | KBUILD_MODNAME, req->cmd, tmp_checksum, |
| 100 | checksum); |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 101 | ret = -EIO; |
Wei Yongjun | 0170a39 | 2013-03-26 01:32:19 -0300 | [diff] [blame] | 102 | goto exit; |
Michael Büsch | b1a9599 | 2012-04-01 16:33:48 -0300 | [diff] [blame] | 103 | } |
Antti Palosaari | 6fb39c5 | 2012-04-06 16:32:30 -0300 | [diff] [blame] | 104 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 105 | /* check status */ |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 106 | if (state->buf[2]) { |
Antti Palosaari | 1bfd529 | 2013-03-08 17:39:12 -0300 | [diff] [blame] | 107 | /* fw returns status 1 when IR code was not received */ |
Wei Yongjun | 0170a39 | 2013-03-26 01:32:19 -0300 | [diff] [blame] | 108 | if (req->cmd == CMD_IR_GET || state->buf[2] == 1) { |
| 109 | ret = 1; |
| 110 | goto exit; |
| 111 | } |
Antti Palosaari | 1bfd529 | 2013-03-08 17:39:12 -0300 | [diff] [blame] | 112 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 113 | 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] | 114 | __func__, req->cmd, state->buf[2]); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 115 | ret = -EIO; |
Wei Yongjun | 0170a39 | 2013-03-26 01:32:19 -0300 | [diff] [blame] | 116 | goto exit; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /* read request, copy returned data to return buf */ |
| 120 | if (req->rlen) |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 121 | memcpy(req->rbuf, &state->buf[ACK_HDR_LEN], req->rlen); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 122 | exit: |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 123 | mutex_unlock(&d->usb_mutex); |
Wei Yongjun | 0170a39 | 2013-03-26 01:32:19 -0300 | [diff] [blame] | 124 | if (ret < 0) |
Antti Palosaari | 3484d37 | 2013-02-26 13:56:34 -0300 | [diff] [blame] | 125 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 126 | return ret; |
| 127 | } |
| 128 | |
| 129 | /* write multiple registers */ |
| 130 | static int af9035_wr_regs(struct dvb_usb_device *d, u32 reg, u8 *val, int len) |
| 131 | { |
Mauro Carvalho Chehab | 7760e14 | 2013-11-02 08:07:12 -0300 | [diff] [blame] | 132 | u8 wbuf[MAX_XFER_SIZE]; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 133 | u8 mbox = (reg >> 16) & 0xff; |
Antti Palosaari | 9323297 | 2013-11-27 17:23:00 -0300 | [diff] [blame] | 134 | struct usb_req req = { CMD_MEM_WR, mbox, 6 + len, wbuf, 0, NULL }; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 135 | |
Mauro Carvalho Chehab | 7760e14 | 2013-11-02 08:07:12 -0300 | [diff] [blame] | 136 | if (6 + len > sizeof(wbuf)) { |
| 137 | dev_warn(&d->udev->dev, "%s: i2c wr: len=%d is too big!\n", |
| 138 | KBUILD_MODNAME, len); |
| 139 | return -EOPNOTSUPP; |
| 140 | } |
| 141 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 142 | wbuf[0] = len; |
| 143 | wbuf[1] = 2; |
| 144 | wbuf[2] = 0; |
| 145 | wbuf[3] = 0; |
| 146 | wbuf[4] = (reg >> 8) & 0xff; |
| 147 | wbuf[5] = (reg >> 0) & 0xff; |
| 148 | memcpy(&wbuf[6], val, len); |
| 149 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 150 | return af9035_ctrl_msg(d, &req); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* read multiple registers */ |
| 154 | static int af9035_rd_regs(struct dvb_usb_device *d, u32 reg, u8 *val, int len) |
| 155 | { |
| 156 | u8 wbuf[] = { len, 2, 0, 0, (reg >> 8) & 0xff, reg & 0xff }; |
| 157 | u8 mbox = (reg >> 16) & 0xff; |
| 158 | struct usb_req req = { CMD_MEM_RD, mbox, sizeof(wbuf), wbuf, len, val }; |
| 159 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 160 | return af9035_ctrl_msg(d, &req); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /* write single register */ |
| 164 | static int af9035_wr_reg(struct dvb_usb_device *d, u32 reg, u8 val) |
| 165 | { |
| 166 | return af9035_wr_regs(d, reg, &val, 1); |
| 167 | } |
| 168 | |
| 169 | /* read single register */ |
| 170 | static int af9035_rd_reg(struct dvb_usb_device *d, u32 reg, u8 *val) |
| 171 | { |
| 172 | return af9035_rd_regs(d, reg, val, 1); |
| 173 | } |
| 174 | |
| 175 | /* write single register with mask */ |
| 176 | static int af9035_wr_reg_mask(struct dvb_usb_device *d, u32 reg, u8 val, |
| 177 | u8 mask) |
| 178 | { |
| 179 | int ret; |
| 180 | u8 tmp; |
| 181 | |
| 182 | /* no need for read if whole reg is written */ |
| 183 | if (mask != 0xff) { |
| 184 | ret = af9035_rd_regs(d, reg, &tmp, 1); |
| 185 | if (ret) |
| 186 | return ret; |
| 187 | |
| 188 | val &= mask; |
| 189 | tmp &= ~mask; |
| 190 | val |= tmp; |
| 191 | } |
| 192 | |
| 193 | return af9035_wr_regs(d, reg, &val, 1); |
| 194 | } |
| 195 | |
Kees Cook | a1ecf3c | 2014-10-20 18:47:34 -0300 | [diff] [blame] | 196 | static int af9035_add_i2c_dev(struct dvb_usb_device *d, const char *type, |
| 197 | u8 addr, void *platform_data, struct i2c_adapter *adapter) |
Antti Palosaari | 3b2a5e8 | 2014-08-26 17:14:16 -0300 | [diff] [blame] | 198 | { |
| 199 | int ret, num; |
| 200 | struct state *state = d_to_priv(d); |
| 201 | struct i2c_client *client; |
Antti Palosaari | 3b2a5e8 | 2014-08-26 17:14:16 -0300 | [diff] [blame] | 202 | struct i2c_board_info board_info = { |
| 203 | .addr = addr, |
| 204 | .platform_data = platform_data, |
| 205 | }; |
| 206 | |
| 207 | strlcpy(board_info.type, type, I2C_NAME_SIZE); |
| 208 | |
| 209 | /* find first free client */ |
| 210 | for (num = 0; num < AF9035_I2C_CLIENT_MAX; num++) { |
| 211 | if (state->i2c_client[num] == NULL) |
| 212 | break; |
| 213 | } |
| 214 | |
| 215 | dev_dbg(&d->udev->dev, "%s: num=%d\n", __func__, num); |
| 216 | |
| 217 | if (num == AF9035_I2C_CLIENT_MAX) { |
| 218 | dev_err(&d->udev->dev, "%s: I2C client out of index\n", |
| 219 | KBUILD_MODNAME); |
| 220 | ret = -ENODEV; |
| 221 | goto err; |
| 222 | } |
| 223 | |
Kees Cook | a1ecf3c | 2014-10-20 18:47:34 -0300 | [diff] [blame] | 224 | request_module("%s", board_info.type); |
Antti Palosaari | 3b2a5e8 | 2014-08-26 17:14:16 -0300 | [diff] [blame] | 225 | |
| 226 | /* register I2C device */ |
| 227 | client = i2c_new_device(adapter, &board_info); |
| 228 | if (client == NULL || client->dev.driver == NULL) { |
| 229 | ret = -ENODEV; |
| 230 | goto err; |
| 231 | } |
| 232 | |
| 233 | /* increase I2C driver usage count */ |
| 234 | if (!try_module_get(client->dev.driver->owner)) { |
| 235 | i2c_unregister_device(client); |
| 236 | ret = -ENODEV; |
| 237 | goto err; |
| 238 | } |
| 239 | |
| 240 | state->i2c_client[num] = client; |
| 241 | return 0; |
| 242 | err: |
| 243 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 244 | return ret; |
| 245 | } |
| 246 | |
| 247 | static void af9035_del_i2c_dev(struct dvb_usb_device *d) |
| 248 | { |
| 249 | int num; |
| 250 | struct state *state = d_to_priv(d); |
| 251 | struct i2c_client *client; |
| 252 | |
| 253 | /* find last used client */ |
| 254 | num = AF9035_I2C_CLIENT_MAX; |
| 255 | while (num--) { |
| 256 | if (state->i2c_client[num] != NULL) |
| 257 | break; |
| 258 | } |
| 259 | |
| 260 | dev_dbg(&d->udev->dev, "%s: num=%d\n", __func__, num); |
| 261 | |
| 262 | if (num == -1) { |
| 263 | dev_err(&d->udev->dev, "%s: I2C client out of index\n", |
| 264 | KBUILD_MODNAME); |
| 265 | goto err; |
| 266 | } |
| 267 | |
| 268 | client = state->i2c_client[num]; |
| 269 | |
| 270 | /* decrease I2C driver usage count */ |
| 271 | module_put(client->dev.driver->owner); |
| 272 | |
| 273 | /* unregister I2C device */ |
| 274 | i2c_unregister_device(client); |
| 275 | |
| 276 | state->i2c_client[num] = NULL; |
| 277 | return; |
| 278 | err: |
| 279 | dev_dbg(&d->udev->dev, "%s: failed\n", __func__); |
| 280 | } |
| 281 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 282 | static int af9035_i2c_master_xfer(struct i2c_adapter *adap, |
| 283 | struct i2c_msg msg[], int num) |
| 284 | { |
| 285 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 286 | struct state *state = d_to_priv(d); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 287 | int ret; |
| 288 | |
| 289 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
| 290 | return -EAGAIN; |
| 291 | |
Antti Palosaari | ad30e91 | 2012-04-02 20:18:59 -0300 | [diff] [blame] | 292 | /* |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 293 | * AF9035 I2C sub header is 5 bytes long. Meaning of those bytes are: |
Antti Palosaari | ad30e91 | 2012-04-02 20:18:59 -0300 | [diff] [blame] | 294 | * 0: data len |
| 295 | * 1: I2C addr << 1 |
| 296 | * 2: reg addr len |
| 297 | * byte 3 and 4 can be used as reg addr |
| 298 | * 3: reg addr MSB |
| 299 | * used when reg addr len is set to 2 |
| 300 | * 4: reg addr LSB |
| 301 | * used when reg addr len is set to 1 or 2 |
| 302 | * |
| 303 | * For the simplify we do not use register addr at all. |
| 304 | * NOTE: As a firmware knows tuner type there is very small possibility |
| 305 | * there could be some tuner I2C hacks done by firmware and this may |
| 306 | * lead problems if firmware expects those bytes are used. |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 307 | * |
| 308 | * TODO: Here is few hacks. AF9035 chip integrates AF9033 demodulator. |
| 309 | * IT9135 chip integrates AF9033 demodulator and RF tuner. For dual |
| 310 | * tuner devices, there is also external AF9033 demodulator connected |
| 311 | * via external I2C bus. All AF9033 demod I2C traffic, both single and |
| 312 | * dual tuner configuration, is covered by firmware - actual USB IO |
| 313 | * looks just like a memory access. |
| 314 | * In case of IT913x chip, there is own tuner driver. It is implemented |
| 315 | * currently as a I2C driver, even tuner IP block is likely build |
| 316 | * directly into the demodulator memory space and there is no own I2C |
| 317 | * bus. I2C subsystem does not allow register multiple devices to same |
| 318 | * bus, having same slave address. Due to that we reuse demod address, |
| 319 | * shifted by one bit, on that case. |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 320 | * |
| 321 | * For IT930x we use a different command and the sub header is |
| 322 | * different as well: |
| 323 | * 0: data len |
| 324 | * 1: I2C bus (0x03 seems to be only value used) |
| 325 | * 2: I2C addr << 1 |
Antti Palosaari | ad30e91 | 2012-04-02 20:18:59 -0300 | [diff] [blame] | 326 | */ |
Antti Palosaari | ee36381 | 2014-08-31 22:17:12 -0300 | [diff] [blame] | 327 | #define AF9035_IS_I2C_XFER_WRITE_READ(_msg, _num) \ |
| 328 | (_num == 2 && !(_msg[0].flags & I2C_M_RD) && (_msg[1].flags & I2C_M_RD)) |
| 329 | #define AF9035_IS_I2C_XFER_WRITE(_msg, _num) \ |
| 330 | (_num == 1 && !(_msg[0].flags & I2C_M_RD)) |
| 331 | #define AF9035_IS_I2C_XFER_READ(_msg, _num) \ |
| 332 | (_num == 1 && (_msg[0].flags & I2C_M_RD)) |
| 333 | |
| 334 | if (AF9035_IS_I2C_XFER_WRITE_READ(msg, num)) { |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 335 | if (msg[0].len > 40 || msg[1].len > 40) { |
| 336 | /* TODO: correct limits > 40 */ |
| 337 | ret = -EOPNOTSUPP; |
Antti Palosaari | a781edd | 2014-08-31 22:57:26 -0300 | [diff] [blame] | 338 | } else if ((msg[0].addr == state->af9033_i2c_addr[0]) || |
| 339 | (msg[0].addr == state->af9033_i2c_addr[1]) || |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 340 | (state->chip_type == 0x9135)) { |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 341 | /* demod access via firmware interface */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 342 | u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | |
| 343 | msg[0].buf[2]; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 344 | |
Antti Palosaari | a781edd | 2014-08-31 22:57:26 -0300 | [diff] [blame] | 345 | if (msg[0].addr == state->af9033_i2c_addr[1] || |
| 346 | msg[0].addr == (state->af9033_i2c_addr[1] >> 1)) |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 347 | reg |= 0x100000; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 348 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 349 | ret = af9035_rd_regs(d, reg, &msg[1].buf[0], |
| 350 | msg[1].len); |
| 351 | } else { |
Antti Palosaari | ee36381 | 2014-08-31 22:17:12 -0300 | [diff] [blame] | 352 | /* I2C write + read */ |
Mauro Carvalho Chehab | 7760e14 | 2013-11-02 08:07:12 -0300 | [diff] [blame] | 353 | u8 buf[MAX_XFER_SIZE]; |
Antti Palosaari | 9323297 | 2013-11-27 17:23:00 -0300 | [diff] [blame] | 354 | struct usb_req req = { CMD_I2C_RD, 0, 5 + msg[0].len, |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 355 | buf, msg[1].len, msg[1].buf }; |
Mauro Carvalho Chehab | 7760e14 | 2013-11-02 08:07:12 -0300 | [diff] [blame] | 356 | |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 357 | if (state->chip_type == 0x9306) { |
| 358 | req.cmd = CMD_GENERIC_I2C_RD; |
| 359 | req.wlen = 3 + msg[0].len; |
| 360 | } |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 361 | req.mbox |= ((msg[0].addr & 0x80) >> 3); |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 362 | |
Hans-Frieder Vogt | 812fe6d | 2012-04-01 14:11:29 -0300 | [diff] [blame] | 363 | buf[0] = msg[1].len; |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 364 | if (state->chip_type == 0x9306) { |
| 365 | buf[1] = 0x03; /* I2C bus */ |
| 366 | buf[2] = msg[0].addr << 1; |
| 367 | memcpy(&buf[3], msg[0].buf, msg[0].len); |
| 368 | } else { |
| 369 | buf[1] = msg[0].addr << 1; |
| 370 | buf[2] = 0x00; /* reg addr len */ |
| 371 | buf[3] = 0x00; /* reg addr MSB */ |
| 372 | buf[4] = 0x00; /* reg addr LSB */ |
| 373 | memcpy(&buf[5], msg[0].buf, msg[0].len); |
| 374 | } |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 375 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 376 | } |
Antti Palosaari | ee36381 | 2014-08-31 22:17:12 -0300 | [diff] [blame] | 377 | } else if (AF9035_IS_I2C_XFER_WRITE(msg, num)) { |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 378 | if (msg[0].len > 40) { |
| 379 | /* TODO: correct limits > 40 */ |
| 380 | ret = -EOPNOTSUPP; |
Antti Palosaari | a781edd | 2014-08-31 22:57:26 -0300 | [diff] [blame] | 381 | } else if ((msg[0].addr == state->af9033_i2c_addr[0]) || |
| 382 | (msg[0].addr == state->af9033_i2c_addr[1]) || |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 383 | (state->chip_type == 0x9135)) { |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 384 | /* demod access via firmware interface */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 385 | u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | |
| 386 | msg[0].buf[2]; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 387 | |
Antti Palosaari | a781edd | 2014-08-31 22:57:26 -0300 | [diff] [blame] | 388 | if (msg[0].addr == state->af9033_i2c_addr[1] || |
| 389 | msg[0].addr == (state->af9033_i2c_addr[1] >> 1)) |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 390 | reg |= 0x100000; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 391 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 392 | ret = af9035_wr_regs(d, reg, &msg[0].buf[3], |
| 393 | msg[0].len - 3); |
| 394 | } else { |
Antti Palosaari | ee36381 | 2014-08-31 22:17:12 -0300 | [diff] [blame] | 395 | /* I2C write */ |
Mauro Carvalho Chehab | 7760e14 | 2013-11-02 08:07:12 -0300 | [diff] [blame] | 396 | u8 buf[MAX_XFER_SIZE]; |
Antti Palosaari | 9323297 | 2013-11-27 17:23:00 -0300 | [diff] [blame] | 397 | struct usb_req req = { CMD_I2C_WR, 0, 5 + msg[0].len, |
| 398 | buf, 0, NULL }; |
Mauro Carvalho Chehab | 7760e14 | 2013-11-02 08:07:12 -0300 | [diff] [blame] | 399 | |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 400 | if (state->chip_type == 0x9306) { |
| 401 | req.cmd = CMD_GENERIC_I2C_WR; |
| 402 | req.wlen = 3 + msg[0].len; |
| 403 | } |
| 404 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 405 | req.mbox |= ((msg[0].addr & 0x80) >> 3); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 406 | buf[0] = msg[0].len; |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 407 | if (state->chip_type == 0x9306) { |
| 408 | buf[1] = 0x03; /* I2C bus */ |
| 409 | buf[2] = msg[0].addr << 1; |
| 410 | memcpy(&buf[3], msg[0].buf, msg[0].len); |
| 411 | } else { |
| 412 | buf[1] = msg[0].addr << 1; |
| 413 | buf[2] = 0x00; /* reg addr len */ |
| 414 | buf[3] = 0x00; /* reg addr MSB */ |
| 415 | buf[4] = 0x00; /* reg addr LSB */ |
| 416 | memcpy(&buf[5], msg[0].buf, msg[0].len); |
| 417 | } |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 418 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 419 | } |
Antti Palosaari | ee36381 | 2014-08-31 22:17:12 -0300 | [diff] [blame] | 420 | } else if (AF9035_IS_I2C_XFER_READ(msg, num)) { |
Antti Palosaari | 3b98c34 | 2013-03-11 19:05:39 -0300 | [diff] [blame] | 421 | if (msg[0].len > 40) { |
| 422 | /* TODO: correct limits > 40 */ |
| 423 | ret = -EOPNOTSUPP; |
| 424 | } else { |
Antti Palosaari | ee36381 | 2014-08-31 22:17:12 -0300 | [diff] [blame] | 425 | /* I2C read */ |
Antti Palosaari | 3b98c34 | 2013-03-11 19:05:39 -0300 | [diff] [blame] | 426 | u8 buf[5]; |
| 427 | struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf), |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 428 | buf, msg[0].len, msg[0].buf }; |
| 429 | |
| 430 | if (state->chip_type == 0x9306) { |
| 431 | req.cmd = CMD_GENERIC_I2C_RD; |
| 432 | req.wlen = 3; |
| 433 | } |
Antti Palosaari | 3b98c34 | 2013-03-11 19:05:39 -0300 | [diff] [blame] | 434 | req.mbox |= ((msg[0].addr & 0x80) >> 3); |
| 435 | buf[0] = msg[0].len; |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 436 | if (state->chip_type == 0x9306) { |
| 437 | buf[1] = 0x03; /* I2C bus */ |
| 438 | buf[2] = msg[0].addr << 1; |
| 439 | } else { |
| 440 | buf[1] = msg[0].addr << 1; |
| 441 | buf[2] = 0x00; /* reg addr len */ |
| 442 | buf[3] = 0x00; /* reg addr MSB */ |
| 443 | buf[4] = 0x00; /* reg addr LSB */ |
| 444 | } |
Antti Palosaari | 3b98c34 | 2013-03-11 19:05:39 -0300 | [diff] [blame] | 445 | ret = af9035_ctrl_msg(d, &req); |
| 446 | } |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 447 | } else { |
| 448 | /* |
Antti Palosaari | 3b98c34 | 2013-03-11 19:05:39 -0300 | [diff] [blame] | 449 | * We support only three kind of I2C transactions: |
Antti Palosaari | ee36381 | 2014-08-31 22:17:12 -0300 | [diff] [blame] | 450 | * 1) 1 x write + 1 x read (repeated start) |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 451 | * 2) 1 x write |
Antti Palosaari | 3b98c34 | 2013-03-11 19:05:39 -0300 | [diff] [blame] | 452 | * 3) 1 x read |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 453 | */ |
| 454 | ret = -EOPNOTSUPP; |
| 455 | } |
| 456 | |
| 457 | mutex_unlock(&d->i2c_mutex); |
| 458 | |
| 459 | if (ret < 0) |
| 460 | return ret; |
| 461 | else |
| 462 | return num; |
| 463 | } |
| 464 | |
| 465 | static u32 af9035_i2c_functionality(struct i2c_adapter *adapter) |
| 466 | { |
| 467 | return I2C_FUNC_I2C; |
| 468 | } |
| 469 | |
| 470 | static struct i2c_algorithm af9035_i2c_algo = { |
| 471 | .master_xfer = af9035_i2c_master_xfer, |
| 472 | .functionality = af9035_i2c_functionality, |
| 473 | }; |
| 474 | |
Antti Palosaari | a0921af | 2012-06-18 23:42:53 -0300 | [diff] [blame] | 475 | 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] | 476 | { |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 477 | struct state *state = d_to_priv(d); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 478 | int ret; |
| 479 | u8 wbuf[1] = { 1 }; |
| 480 | u8 rbuf[4]; |
| 481 | struct usb_req req = { CMD_FW_QUERYINFO, 0, sizeof(wbuf), wbuf, |
| 482 | sizeof(rbuf), rbuf }; |
| 483 | |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 484 | ret = af9035_rd_regs(d, 0x1222, rbuf, 3); |
| 485 | if (ret < 0) |
| 486 | goto err; |
| 487 | |
| 488 | state->chip_version = rbuf[0]; |
| 489 | state->chip_type = rbuf[2] << 8 | rbuf[1] << 0; |
| 490 | |
| 491 | ret = af9035_rd_reg(d, 0x384f, &state->prechip_version); |
| 492 | if (ret < 0) |
| 493 | goto err; |
| 494 | |
| 495 | dev_info(&d->udev->dev, |
| 496 | "%s: prechip_version=%02x chip_version=%02x chip_type=%04x\n", |
Antti Palosaari | e8292e2 | 2013-06-03 18:50:43 -0300 | [diff] [blame] | 497 | KBUILD_MODNAME, state->prechip_version, |
| 498 | state->chip_version, state->chip_type); |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 499 | |
| 500 | if (state->chip_type == 0x9135) { |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 501 | if (state->chip_version == 0x02) |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 502 | *name = AF9035_FIRMWARE_IT9135_V2; |
| 503 | else |
| 504 | *name = AF9035_FIRMWARE_IT9135_V1; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 505 | state->eeprom_addr = EEPROM_BASE_IT9135; |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 506 | } else if (state->chip_type == 0x9306) { |
| 507 | *name = AF9035_FIRMWARE_IT9303; |
| 508 | state->eeprom_addr = EEPROM_BASE_IT9135; |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 509 | } else { |
| 510 | *name = AF9035_FIRMWARE_AF9035; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 511 | state->eeprom_addr = EEPROM_BASE_AF9035; |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 512 | } |
| 513 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 514 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 515 | if (ret < 0) |
| 516 | goto err; |
| 517 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 518 | dev_dbg(&d->udev->dev, "%s: reply=%*ph\n", __func__, 4, rbuf); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 519 | if (rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3]) |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 520 | ret = WARM; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 521 | else |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 522 | ret = COLD; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 523 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 524 | return ret; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 525 | |
| 526 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 527 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 528 | |
| 529 | return ret; |
| 530 | } |
| 531 | |
Antti Palosaari | 8229da5 | 2013-03-07 17:59:55 -0300 | [diff] [blame] | 532 | static int af9035_download_firmware_old(struct dvb_usb_device *d, |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 533 | const struct firmware *fw) |
| 534 | { |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 535 | int ret, i, j, len; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 536 | u8 wbuf[1]; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 537 | struct usb_req req = { 0, 0, 0, NULL, 0, NULL }; |
| 538 | 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] | 539 | u8 hdr_core; |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 540 | u16 hdr_addr, hdr_data_len, hdr_checksum; |
Antti Palosaari | 6fb39c5 | 2012-04-06 16:32:30 -0300 | [diff] [blame] | 541 | #define MAX_DATA 58 |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 542 | #define HDR_SIZE 7 |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 543 | |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 544 | /* |
| 545 | * Thanks to Daniel Glöckner <daniel-gl@gmx.net> about that info! |
| 546 | * |
| 547 | * byte 0: MCS 51 core |
| 548 | * There are two inside the AF9035 (1=Link and 2=OFDM) with separate |
| 549 | * address spaces |
| 550 | * byte 1-2: Big endian destination address |
| 551 | * byte 3-4: Big endian number of data bytes following the header |
| 552 | * byte 5-6: Big endian header checksum, apparently ignored by the chip |
| 553 | * Calculated as ~(h[0]*256+h[1]+h[2]*256+h[3]+h[4]*256) |
| 554 | */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 555 | |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 556 | for (i = fw->size; i > HDR_SIZE;) { |
| 557 | hdr_core = fw->data[fw->size - i + 0]; |
| 558 | hdr_addr = fw->data[fw->size - i + 1] << 8; |
| 559 | hdr_addr |= fw->data[fw->size - i + 2] << 0; |
| 560 | hdr_data_len = fw->data[fw->size - i + 3] << 8; |
| 561 | hdr_data_len |= fw->data[fw->size - i + 4] << 0; |
| 562 | hdr_checksum = fw->data[fw->size - i + 5] << 8; |
| 563 | hdr_checksum |= fw->data[fw->size - i + 6] << 0; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 564 | |
Antti Palosaari | cb9114e | 2013-06-03 18:42:14 -0300 | [diff] [blame] | 565 | dev_dbg(&d->udev->dev, |
| 566 | "%s: core=%d addr=%04x data_len=%d checksum=%04x\n", |
| 567 | __func__, hdr_core, hdr_addr, hdr_data_len, |
| 568 | hdr_checksum); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 569 | |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 570 | if (((hdr_core != 1) && (hdr_core != 2)) || |
| 571 | (hdr_data_len > i)) { |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 572 | dev_dbg(&d->udev->dev, "%s: bad firmware\n", __func__); |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 573 | break; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 574 | } |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 575 | |
| 576 | /* download begin packet */ |
| 577 | req.cmd = CMD_FW_DL_BEGIN; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 578 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | 41d44a8 | 2012-04-01 11:06:23 -0300 | [diff] [blame] | 579 | if (ret < 0) |
| 580 | goto err; |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 581 | |
| 582 | /* download firmware packet(s) */ |
| 583 | for (j = HDR_SIZE + hdr_data_len; j > 0; j -= MAX_DATA) { |
| 584 | len = j; |
| 585 | if (len > MAX_DATA) |
| 586 | len = MAX_DATA; |
| 587 | req_fw_dl.wlen = len; |
| 588 | req_fw_dl.wbuf = (u8 *) &fw->data[fw->size - i + |
| 589 | HDR_SIZE + hdr_data_len - j]; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 590 | ret = af9035_ctrl_msg(d, &req_fw_dl); |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 591 | if (ret < 0) |
| 592 | goto err; |
| 593 | } |
| 594 | |
| 595 | /* download end packet */ |
| 596 | req.cmd = CMD_FW_DL_END; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 597 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | 77c5ff2 | 2012-04-01 01:32:23 -0300 | [diff] [blame] | 598 | if (ret < 0) |
| 599 | goto err; |
| 600 | |
| 601 | i -= hdr_data_len + HDR_SIZE; |
| 602 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 603 | dev_dbg(&d->udev->dev, "%s: data uploaded=%zu\n", |
| 604 | __func__, fw->size - i); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 605 | } |
| 606 | |
Antti Palosaari | ff4e3fe | 2012-12-09 16:25:08 -0300 | [diff] [blame] | 607 | /* print warn if firmware is bad, continue and see what happens */ |
| 608 | if (i) |
| 609 | dev_warn(&d->udev->dev, "%s: bad firmware\n", KBUILD_MODNAME); |
| 610 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 611 | return 0; |
| 612 | |
| 613 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 614 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 615 | |
| 616 | return ret; |
| 617 | } |
| 618 | |
Antti Palosaari | 8229da5 | 2013-03-07 17:59:55 -0300 | [diff] [blame] | 619 | static int af9035_download_firmware_new(struct dvb_usb_device *d, |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 620 | const struct firmware *fw) |
| 621 | { |
| 622 | int ret, i, i_prev; |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 623 | 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] | 624 | #define HDR_SIZE 7 |
| 625 | |
| 626 | /* |
| 627 | * There seems to be following firmware header. Meaning of bytes 0-3 |
| 628 | * is unknown. |
| 629 | * |
| 630 | * 0: 3 |
| 631 | * 1: 0, 1 |
| 632 | * 2: 0 |
| 633 | * 3: 1, 2, 3 |
| 634 | * 4: addr MSB |
| 635 | * 5: addr LSB |
| 636 | * 6: count of data bytes ? |
| 637 | */ |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 638 | for (i = HDR_SIZE, i_prev = 0; i <= fw->size; i++) { |
| 639 | if (i == fw->size || |
| 640 | (fw->data[i + 0] == 0x03 && |
| 641 | (fw->data[i + 1] == 0x00 || |
| 642 | fw->data[i + 1] == 0x01) && |
| 643 | fw->data[i + 2] == 0x00)) { |
| 644 | req_fw_dl.wlen = i - i_prev; |
| 645 | req_fw_dl.wbuf = (u8 *) &fw->data[i_prev]; |
| 646 | i_prev = i; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 647 | ret = af9035_ctrl_msg(d, &req_fw_dl); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 648 | if (ret < 0) |
| 649 | goto err; |
| 650 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 651 | dev_dbg(&d->udev->dev, "%s: data uploaded=%d\n", |
| 652 | __func__, i); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 656 | return 0; |
| 657 | |
| 658 | err: |
| 659 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 660 | |
| 661 | return ret; |
| 662 | } |
| 663 | |
| 664 | static int af9035_download_firmware(struct dvb_usb_device *d, |
| 665 | const struct firmware *fw) |
| 666 | { |
| 667 | struct state *state = d_to_priv(d); |
| 668 | int ret; |
| 669 | u8 wbuf[1]; |
| 670 | u8 rbuf[4]; |
| 671 | u8 tmp; |
| 672 | struct usb_req req = { 0, 0, 0, NULL, 0, NULL }; |
Antti Palosaari | cb9114e | 2013-06-03 18:42:14 -0300 | [diff] [blame] | 673 | struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf }; |
Antti Palosaari | c10989a | 2014-08-09 14:49:46 -0300 | [diff] [blame] | 674 | |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 675 | dev_dbg(&d->udev->dev, "%s:\n", __func__); |
| 676 | |
| 677 | /* |
| 678 | * In case of dual tuner configuration we need to do some extra |
| 679 | * initialization in order to download firmware to slave demod too, |
| 680 | * which is done by master demod. |
| 681 | * Master feeds also clock and controls power via GPIO. |
| 682 | */ |
Antti Palosaari | d716ef4 | 2013-06-03 19:39:51 -0300 | [diff] [blame] | 683 | ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_TS_MODE, &tmp); |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 684 | if (ret < 0) |
| 685 | goto err; |
| 686 | |
Antti Palosaari | d716ef4 | 2013-06-03 19:39:51 -0300 | [diff] [blame] | 687 | if (tmp == 1 || tmp == 3) { |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 688 | /* configure gpioh1, reset & power slave demod */ |
| 689 | ret = af9035_wr_reg_mask(d, 0x00d8b0, 0x01, 0x01); |
| 690 | if (ret < 0) |
| 691 | goto err; |
| 692 | |
| 693 | ret = af9035_wr_reg_mask(d, 0x00d8b1, 0x01, 0x01); |
| 694 | if (ret < 0) |
| 695 | goto err; |
| 696 | |
| 697 | ret = af9035_wr_reg_mask(d, 0x00d8af, 0x00, 0x01); |
| 698 | if (ret < 0) |
| 699 | goto err; |
| 700 | |
| 701 | usleep_range(10000, 50000); |
| 702 | |
| 703 | ret = af9035_wr_reg_mask(d, 0x00d8af, 0x01, 0x01); |
| 704 | if (ret < 0) |
| 705 | goto err; |
| 706 | |
| 707 | /* tell the slave I2C address */ |
| 708 | ret = af9035_rd_reg(d, |
| 709 | state->eeprom_addr + EEPROM_2ND_DEMOD_ADDR, |
| 710 | &tmp); |
| 711 | if (ret < 0) |
| 712 | goto err; |
| 713 | |
Antti Palosaari | 14992f0 | 2014-02-12 15:50:17 -0300 | [diff] [blame] | 714 | /* use default I2C address if eeprom has no address set */ |
| 715 | if (!tmp) |
| 716 | tmp = 0x3a; |
Malcolm Priestley | a1310ff | 2014-02-09 10:02:49 -0300 | [diff] [blame] | 717 | |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 718 | if ((state->chip_type == 0x9135) || |
| 719 | (state->chip_type == 0x9306)) { |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 720 | ret = af9035_wr_reg(d, 0x004bfb, tmp); |
| 721 | if (ret < 0) |
| 722 | goto err; |
| 723 | } else { |
| 724 | ret = af9035_wr_reg(d, 0x00417f, tmp); |
| 725 | if (ret < 0) |
| 726 | goto err; |
| 727 | |
| 728 | /* enable clock out */ |
| 729 | ret = af9035_wr_reg_mask(d, 0x00d81a, 0x01, 0x01); |
| 730 | if (ret < 0) |
| 731 | goto err; |
| 732 | } |
| 733 | } |
| 734 | |
Antti Palosaari | 8229da5 | 2013-03-07 17:59:55 -0300 | [diff] [blame] | 735 | if (fw->data[0] == 0x01) |
| 736 | ret = af9035_download_firmware_old(d, fw); |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 737 | else |
Antti Palosaari | 8229da5 | 2013-03-07 17:59:55 -0300 | [diff] [blame] | 738 | ret = af9035_download_firmware_new(d, fw); |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 739 | if (ret < 0) |
| 740 | goto err; |
| 741 | |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 742 | /* firmware loaded, request boot */ |
| 743 | req.cmd = CMD_FW_BOOT; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 744 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 745 | if (ret < 0) |
| 746 | goto err; |
| 747 | |
| 748 | /* ensure firmware starts */ |
| 749 | wbuf[0] = 1; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 750 | ret = af9035_ctrl_msg(d, &req_fw_ver); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 751 | if (ret < 0) |
| 752 | goto err; |
| 753 | |
| 754 | if (!(rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3])) { |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 755 | dev_err(&d->udev->dev, "%s: firmware did not run\n", |
| 756 | KBUILD_MODNAME); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 757 | ret = -ENODEV; |
| 758 | goto err; |
| 759 | } |
| 760 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 761 | dev_info(&d->udev->dev, "%s: firmware version=%d.%d.%d.%d", |
| 762 | KBUILD_MODNAME, rbuf[0], rbuf[1], rbuf[2], rbuf[3]); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 763 | |
| 764 | return 0; |
| 765 | |
| 766 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 767 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 768 | |
| 769 | return ret; |
| 770 | } |
| 771 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 772 | static int af9035_read_config(struct dvb_usb_device *d) |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 773 | { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 774 | struct state *state = d_to_priv(d); |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 775 | int ret, i; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 776 | u8 tmp; |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 777 | u16 tmp16, addr; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 778 | |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 779 | /* demod I2C "address" */ |
Antti Palosaari | a781edd | 2014-08-31 22:57:26 -0300 | [diff] [blame] | 780 | state->af9033_i2c_addr[0] = 0x38; |
| 781 | state->af9033_i2c_addr[1] = 0x3a; |
Antti Palosaari | 0d94d6a | 2013-01-07 15:26:05 -0300 | [diff] [blame] | 782 | state->af9033_config[0].adc_multiplier = AF9033_ADC_MULTIPLIER_2X; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 783 | state->af9033_config[1].adc_multiplier = AF9033_ADC_MULTIPLIER_2X; |
Antti Palosaari | ab56ad6 | 2013-03-07 18:43:51 -0300 | [diff] [blame] | 784 | state->af9033_config[0].ts_mode = AF9033_TS_MODE_USB; |
| 785 | state->af9033_config[1].ts_mode = AF9033_TS_MODE_SERIAL; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 786 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 787 | if (state->chip_type == 0x9135) { |
Antti Palosaari | 15ba820 | 2014-08-09 00:08:57 -0300 | [diff] [blame] | 788 | /* feed clock for integrated RF tuner */ |
| 789 | state->af9033_config[0].dyn0_clk = true; |
| 790 | state->af9033_config[1].dyn0_clk = true; |
| 791 | |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 792 | if (state->chip_version == 0x02) { |
| 793 | state->af9033_config[0].tuner = AF9033_TUNER_IT9135_60; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 794 | state->af9033_config[1].tuner = AF9033_TUNER_IT9135_60; |
Antti Palosaari | 15ba820 | 2014-08-09 00:08:57 -0300 | [diff] [blame] | 795 | tmp16 = 0x00461d; /* eeprom memory mapped location */ |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 796 | } else { |
| 797 | state->af9033_config[0].tuner = AF9033_TUNER_IT9135_38; |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 798 | state->af9033_config[1].tuner = AF9033_TUNER_IT9135_38; |
Antti Palosaari | 15ba820 | 2014-08-09 00:08:57 -0300 | [diff] [blame] | 799 | tmp16 = 0x00461b; /* eeprom memory mapped location */ |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 800 | } |
| 801 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 802 | /* check if eeprom exists */ |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 803 | ret = af9035_rd_reg(d, tmp16, &tmp); |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 804 | if (ret < 0) |
| 805 | goto err; |
| 806 | |
Antti Palosaari | 431a6d4 | 2013-03-07 18:28:25 -0300 | [diff] [blame] | 807 | if (tmp == 0x00) { |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 808 | dev_dbg(&d->udev->dev, "%s: no eeprom\n", __func__); |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 809 | goto skip_eeprom; |
| 810 | } |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 811 | } else if (state->chip_type == 0x9306) { |
| 812 | /* |
| 813 | * IT930x is an USB bridge, only single demod-single tuner |
| 814 | * configurations seen so far. |
| 815 | */ |
| 816 | return 0; |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 817 | } |
| 818 | |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 819 | |
| 820 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 821 | /* check if there is dual tuners */ |
Antti Palosaari | d716ef4 | 2013-06-03 19:39:51 -0300 | [diff] [blame] | 822 | ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_TS_MODE, &tmp); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 823 | if (ret < 0) |
| 824 | goto err; |
| 825 | |
Antti Palosaari | d716ef4 | 2013-06-03 19:39:51 -0300 | [diff] [blame] | 826 | if (tmp == 1 || tmp == 3) |
| 827 | state->dual_mode = true; |
| 828 | |
| 829 | dev_dbg(&d->udev->dev, "%s: ts mode=%d dual mode=%d\n", __func__, |
| 830 | tmp, state->dual_mode); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 831 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 832 | if (state->dual_mode) { |
| 833 | /* read 2nd demodulator I2C address */ |
Antti Palosaari | 431a6d4 | 2013-03-07 18:28:25 -0300 | [diff] [blame] | 834 | ret = af9035_rd_reg(d, |
| 835 | state->eeprom_addr + EEPROM_2ND_DEMOD_ADDR, |
| 836 | &tmp); |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 837 | if (ret < 0) |
| 838 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 839 | |
Antti Palosaari | 14992f0 | 2014-02-12 15:50:17 -0300 | [diff] [blame] | 840 | if (tmp) |
Antti Palosaari | a781edd | 2014-08-31 22:57:26 -0300 | [diff] [blame] | 841 | state->af9033_i2c_addr[1] = tmp; |
Malcolm Priestley | a1310ff | 2014-02-09 10:02:49 -0300 | [diff] [blame] | 842 | |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 843 | dev_dbg(&d->udev->dev, "%s: 2nd demod I2C addr=%02x\n", |
| 844 | __func__, tmp); |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 845 | } |
| 846 | |
Antti Palosaari | 431a6d4 | 2013-03-07 18:28:25 -0300 | [diff] [blame] | 847 | addr = state->eeprom_addr; |
| 848 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 849 | for (i = 0; i < state->dual_mode + 1; i++) { |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 850 | /* tuner */ |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 851 | ret = af9035_rd_reg(d, addr + EEPROM_1_TUNER_ID, &tmp); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 852 | if (ret < 0) |
| 853 | goto err; |
| 854 | |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 855 | dev_dbg(&d->udev->dev, "%s: [%d]tuner=%02x\n", |
Antti Palosaari | 1cbbf90 | 2014-06-24 10:03:59 -0300 | [diff] [blame] | 856 | __func__, i, tmp); |
| 857 | |
| 858 | /* tuner sanity check */ |
| 859 | if (state->chip_type == 0x9135) { |
| 860 | if (state->chip_version == 0x02) { |
| 861 | /* IT9135 BX (v2) */ |
| 862 | switch (tmp) { |
| 863 | case AF9033_TUNER_IT9135_60: |
| 864 | case AF9033_TUNER_IT9135_61: |
| 865 | case AF9033_TUNER_IT9135_62: |
| 866 | state->af9033_config[i].tuner = tmp; |
| 867 | break; |
| 868 | } |
| 869 | } else { |
| 870 | /* IT9135 AX (v1) */ |
| 871 | switch (tmp) { |
| 872 | case AF9033_TUNER_IT9135_38: |
| 873 | case AF9033_TUNER_IT9135_51: |
| 874 | case AF9033_TUNER_IT9135_52: |
| 875 | state->af9033_config[i].tuner = tmp; |
| 876 | break; |
| 877 | } |
| 878 | } |
| 879 | } else { |
| 880 | /* AF9035 */ |
| 881 | state->af9033_config[i].tuner = tmp; |
| 882 | } |
| 883 | |
| 884 | if (state->af9033_config[i].tuner != tmp) { |
| 885 | dev_info(&d->udev->dev, |
| 886 | "%s: [%d] overriding tuner from %02x to %02x\n", |
| 887 | KBUILD_MODNAME, i, tmp, |
| 888 | state->af9033_config[i].tuner); |
| 889 | } |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 890 | |
| 891 | switch (state->af9033_config[i].tuner) { |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 892 | case AF9033_TUNER_TUA9001: |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 893 | case AF9033_TUNER_FC0011: |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 894 | case AF9033_TUNER_MXL5007T: |
Gianluca Gennari | ce1fe37 | 2012-04-02 17:25:14 -0300 | [diff] [blame] | 895 | case AF9033_TUNER_TDA18218: |
Oliver Schinagl | d67ceb3 | 2012-09-20 14:57:17 -0300 | [diff] [blame] | 896 | case AF9033_TUNER_FC2580: |
Antti Palosaari | 7e0bc29 | 2012-12-02 20:12:29 -0300 | [diff] [blame] | 897 | case AF9033_TUNER_FC0012: |
Antti Palosaari | 2a79eef | 2012-05-07 14:50:40 -0300 | [diff] [blame] | 898 | state->af9033_config[i].spec_inv = 1; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 899 | break; |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 900 | case AF9033_TUNER_IT9135_38: |
| 901 | case AF9033_TUNER_IT9135_51: |
| 902 | case AF9033_TUNER_IT9135_52: |
| 903 | case AF9033_TUNER_IT9135_60: |
| 904 | case AF9033_TUNER_IT9135_61: |
| 905 | case AF9033_TUNER_IT9135_62: |
| 906 | break; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 907 | default: |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 908 | dev_warn(&d->udev->dev, |
| 909 | "%s: tuner id=%02x not supported, please report!", |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 910 | KBUILD_MODNAME, tmp); |
Peter Senna Tschudin | c2c1b41 | 2012-09-28 05:37:22 -0300 | [diff] [blame] | 911 | } |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 912 | |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 913 | /* disable dual mode if driver does not support it */ |
| 914 | if (i == 1) |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 915 | switch (state->af9033_config[i].tuner) { |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 916 | case AF9033_TUNER_FC0012: |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 917 | case AF9033_TUNER_IT9135_38: |
| 918 | case AF9033_TUNER_IT9135_51: |
| 919 | case AF9033_TUNER_IT9135_52: |
| 920 | case AF9033_TUNER_IT9135_60: |
| 921 | case AF9033_TUNER_IT9135_61: |
| 922 | case AF9033_TUNER_IT9135_62: |
Jose Alberto Reguero | 78c7bc4 | 2013-02-10 15:43:03 -0300 | [diff] [blame] | 923 | case AF9033_TUNER_MXL5007T: |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 924 | break; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 925 | default: |
| 926 | state->dual_mode = false; |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 927 | dev_info(&d->udev->dev, |
| 928 | "%s: driver does not support 2nd tuner and will disable it", |
| 929 | KBUILD_MODNAME); |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 930 | } |
| 931 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 932 | /* tuner IF frequency */ |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 933 | ret = af9035_rd_reg(d, addr + EEPROM_1_IF_L, &tmp); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 934 | if (ret < 0) |
| 935 | goto err; |
| 936 | |
| 937 | tmp16 = tmp; |
| 938 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 939 | ret = af9035_rd_reg(d, addr + EEPROM_1_IF_H, &tmp); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 940 | if (ret < 0) |
| 941 | goto err; |
| 942 | |
| 943 | tmp16 |= tmp << 8; |
| 944 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 945 | 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] | 946 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 947 | addr += 0x10; /* shift for the 2nd tuner params */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 948 | } |
| 949 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 950 | skip_eeprom: |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 951 | /* get demod clock */ |
| 952 | ret = af9035_rd_reg(d, 0x00d800, &tmp); |
| 953 | if (ret < 0) |
| 954 | goto err; |
| 955 | |
| 956 | tmp = (tmp >> 0) & 0x0f; |
| 957 | |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 958 | for (i = 0; i < ARRAY_SIZE(state->af9033_config); i++) { |
| 959 | if (state->chip_type == 0x9135) |
| 960 | state->af9033_config[i].clock = clock_lut_it9135[tmp]; |
| 961 | else |
| 962 | state->af9033_config[i].clock = clock_lut_af9035[tmp]; |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 963 | } |
| 964 | |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 965 | return 0; |
| 966 | |
| 967 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 968 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | f2b61d0 | 2012-04-05 20:28:51 -0300 | [diff] [blame] | 969 | |
| 970 | return ret; |
| 971 | } |
| 972 | |
Antti Palosaari | 51639be | 2012-09-16 22:26:56 -0300 | [diff] [blame] | 973 | static int af9035_tua9001_tuner_callback(struct dvb_usb_device *d, |
| 974 | int cmd, int arg) |
| 975 | { |
| 976 | int ret; |
| 977 | u8 val; |
| 978 | |
| 979 | dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg); |
| 980 | |
| 981 | /* |
| 982 | * CEN always enabled by hardware wiring |
| 983 | * RESETN GPIOT3 |
| 984 | * RXEN GPIOT2 |
| 985 | */ |
| 986 | |
| 987 | switch (cmd) { |
| 988 | case TUA9001_CMD_RESETN: |
| 989 | if (arg) |
| 990 | val = 0x00; |
| 991 | else |
| 992 | val = 0x01; |
| 993 | |
| 994 | ret = af9035_wr_reg_mask(d, 0x00d8e7, val, 0x01); |
| 995 | if (ret < 0) |
| 996 | goto err; |
| 997 | break; |
| 998 | case TUA9001_CMD_RXEN: |
| 999 | if (arg) |
| 1000 | val = 0x01; |
| 1001 | else |
| 1002 | val = 0x00; |
| 1003 | |
| 1004 | ret = af9035_wr_reg_mask(d, 0x00d8eb, val, 0x01); |
| 1005 | if (ret < 0) |
| 1006 | goto err; |
| 1007 | break; |
| 1008 | } |
| 1009 | |
| 1010 | return 0; |
| 1011 | |
| 1012 | err: |
| 1013 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 1014 | |
| 1015 | return ret; |
| 1016 | } |
| 1017 | |
| 1018 | |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1019 | static int af9035_fc0011_tuner_callback(struct dvb_usb_device *d, |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 1020 | int cmd, int arg) |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1021 | { |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 1022 | int ret; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1023 | |
| 1024 | switch (cmd) { |
| 1025 | case FC0011_FE_CALLBACK_POWER: |
| 1026 | /* Tuner enable */ |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 1027 | ret = af9035_wr_reg_mask(d, 0xd8eb, 1, 1); |
| 1028 | if (ret < 0) |
| 1029 | goto err; |
| 1030 | |
| 1031 | ret = af9035_wr_reg_mask(d, 0xd8ec, 1, 1); |
| 1032 | if (ret < 0) |
| 1033 | goto err; |
| 1034 | |
| 1035 | ret = af9035_wr_reg_mask(d, 0xd8ed, 1, 1); |
| 1036 | if (ret < 0) |
| 1037 | goto err; |
| 1038 | |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1039 | /* LED */ |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 1040 | ret = af9035_wr_reg_mask(d, 0xd8d0, 1, 1); |
| 1041 | if (ret < 0) |
| 1042 | goto err; |
| 1043 | |
| 1044 | ret = af9035_wr_reg_mask(d, 0xd8d1, 1, 1); |
| 1045 | if (ret < 0) |
| 1046 | goto err; |
| 1047 | |
Michael Büsch | de2bec5 | 2012-04-03 05:11:30 -0300 | [diff] [blame] | 1048 | usleep_range(10000, 50000); |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1049 | break; |
| 1050 | case FC0011_FE_CALLBACK_RESET: |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 1051 | ret = af9035_wr_reg(d, 0xd8e9, 1); |
| 1052 | if (ret < 0) |
| 1053 | goto err; |
| 1054 | |
| 1055 | ret = af9035_wr_reg(d, 0xd8e8, 1); |
| 1056 | if (ret < 0) |
| 1057 | goto err; |
| 1058 | |
| 1059 | ret = af9035_wr_reg(d, 0xd8e7, 1); |
| 1060 | if (ret < 0) |
| 1061 | goto err; |
| 1062 | |
Michael Büsch | de2bec5 | 2012-04-03 05:11:30 -0300 | [diff] [blame] | 1063 | usleep_range(10000, 20000); |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 1064 | |
| 1065 | ret = af9035_wr_reg(d, 0xd8e7, 0); |
| 1066 | if (ret < 0) |
| 1067 | goto err; |
| 1068 | |
Michael Büsch | de2bec5 | 2012-04-03 05:11:30 -0300 | [diff] [blame] | 1069 | usleep_range(10000, 20000); |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1070 | break; |
| 1071 | default: |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 1072 | ret = -EINVAL; |
| 1073 | goto err; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | return 0; |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 1077 | |
| 1078 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 1079 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | daacd5b | 2012-04-05 21:52:21 -0300 | [diff] [blame] | 1080 | |
| 1081 | return ret; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | static int af9035_tuner_callback(struct dvb_usb_device *d, int cmd, int arg) |
| 1085 | { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1086 | struct state *state = d_to_priv(d); |
Antti Palosaari | 2a79eef | 2012-05-07 14:50:40 -0300 | [diff] [blame] | 1087 | |
| 1088 | switch (state->af9033_config[0].tuner) { |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1089 | case AF9033_TUNER_FC0011: |
| 1090 | return af9035_fc0011_tuner_callback(d, cmd, arg); |
Antti Palosaari | 51639be | 2012-09-16 22:26:56 -0300 | [diff] [blame] | 1091 | case AF9033_TUNER_TUA9001: |
| 1092 | return af9035_tua9001_tuner_callback(d, cmd, arg); |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1093 | default: |
| 1094 | break; |
| 1095 | } |
| 1096 | |
Antti Palosaari | 1835af1 | 2012-09-11 22:27:06 -0300 | [diff] [blame] | 1097 | return 0; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | static int af9035_frontend_callback(void *adapter_priv, int component, |
| 1101 | int cmd, int arg) |
| 1102 | { |
| 1103 | struct i2c_adapter *adap = adapter_priv; |
| 1104 | struct dvb_usb_device *d = i2c_get_adapdata(adap); |
| 1105 | |
Antti Palosaari | 1835af1 | 2012-09-11 22:27:06 -0300 | [diff] [blame] | 1106 | dev_dbg(&d->udev->dev, "%s: component=%d cmd=%d arg=%d\n", |
| 1107 | __func__, component, cmd, arg); |
| 1108 | |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1109 | switch (component) { |
| 1110 | case DVB_FRONTEND_COMPONENT_TUNER: |
| 1111 | return af9035_tuner_callback(d, cmd, arg); |
| 1112 | default: |
| 1113 | break; |
| 1114 | } |
| 1115 | |
Antti Palosaari | 1835af1 | 2012-09-11 22:27:06 -0300 | [diff] [blame] | 1116 | return 0; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1117 | } |
| 1118 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1119 | static int af9035_get_adapter_count(struct dvb_usb_device *d) |
| 1120 | { |
| 1121 | struct state *state = d_to_priv(d); |
Antti Palosaari | c10989a | 2014-08-09 14:49:46 -0300 | [diff] [blame] | 1122 | |
Antti Palosaari | b24c2b4 | 2014-02-13 15:53:05 -0300 | [diff] [blame] | 1123 | return state->dual_mode + 1; |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1124 | } |
| 1125 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1126 | static int af9035_frontend_attach(struct dvb_usb_adapter *adap) |
| 1127 | { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1128 | struct state *state = adap_to_priv(adap); |
| 1129 | struct dvb_usb_device *d = adap_to_d(adap); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1130 | int ret; |
Antti Palosaari | c10989a | 2014-08-09 14:49:46 -0300 | [diff] [blame] | 1131 | |
Antti Palosaari | d4d6a34 | 2014-09-04 18:35:59 -0300 | [diff] [blame] | 1132 | dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1133 | |
Antti Palosaari | 1cbabf9 | 2012-05-07 14:59:55 -0300 | [diff] [blame] | 1134 | if (!state->af9033_config[adap->id].tuner) { |
| 1135 | /* unsupported tuner */ |
Antti Palosaari | 5a9abae | 2012-03-30 17:15:16 -0300 | [diff] [blame] | 1136 | ret = -ENODEV; |
| 1137 | goto err; |
| 1138 | } |
| 1139 | |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1140 | state->af9033_config[adap->id].fe = &adap->fe[0]; |
| 1141 | state->af9033_config[adap->id].ops = &state->ops; |
Antti Palosaari | a781edd | 2014-08-31 22:57:26 -0300 | [diff] [blame] | 1142 | ret = af9035_add_i2c_dev(d, "af9033", state->af9033_i2c_addr[adap->id], |
Olli Salonen | 5dcf5bf | 2014-09-21 07:53:18 -0300 | [diff] [blame] | 1143 | &state->af9033_config[adap->id], &d->i2c_adap); |
Antti Palosaari | f5b00a7 | 2014-08-31 20:57:05 -0300 | [diff] [blame] | 1144 | if (ret) |
| 1145 | goto err; |
| 1146 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1147 | if (adap->fe[0] == NULL) { |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1148 | ret = -ENODEV; |
| 1149 | goto err; |
| 1150 | } |
Antti Palosaari | 852f0d9 | 2012-04-06 07:09:23 -0300 | [diff] [blame] | 1151 | |
| 1152 | /* disable I2C-gate */ |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1153 | adap->fe[0]->ops.i2c_gate_ctrl = NULL; |
| 1154 | adap->fe[0]->callback = af9035_frontend_callback; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1155 | |
| 1156 | return 0; |
| 1157 | |
| 1158 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 1159 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1160 | |
| 1161 | return ret; |
| 1162 | } |
| 1163 | |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 1164 | static int it930x_frontend_attach(struct dvb_usb_adapter *adap) |
| 1165 | { |
| 1166 | struct state *state = adap_to_priv(adap); |
| 1167 | struct dvb_usb_device *d = adap_to_d(adap); |
| 1168 | int ret; |
| 1169 | struct si2168_config si2168_config; |
| 1170 | struct i2c_adapter *adapter; |
| 1171 | |
| 1172 | dev_dbg(&d->udev->dev, "adap->id=%d\n", adap->id); |
| 1173 | |
Olli Salonen | 251a5c4 | 2014-11-20 17:33:48 -0300 | [diff] [blame] | 1174 | memset(&si2168_config, 0, sizeof(si2168_config)); |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 1175 | si2168_config.i2c_adapter = &adapter; |
| 1176 | si2168_config.fe = &adap->fe[0]; |
| 1177 | si2168_config.ts_mode = SI2168_TS_SERIAL; |
| 1178 | |
| 1179 | state->af9033_config[adap->id].fe = &adap->fe[0]; |
| 1180 | state->af9033_config[adap->id].ops = &state->ops; |
| 1181 | ret = af9035_add_i2c_dev(d, "si2168", 0x67, &si2168_config, |
| 1182 | &d->i2c_adap); |
| 1183 | if (ret) |
| 1184 | goto err; |
| 1185 | |
| 1186 | if (adap->fe[0] == NULL) { |
| 1187 | ret = -ENODEV; |
| 1188 | goto err; |
| 1189 | } |
| 1190 | state->i2c_adapter_demod = adapter; |
| 1191 | |
| 1192 | return 0; |
| 1193 | |
| 1194 | err: |
| 1195 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 1196 | |
| 1197 | return ret; |
| 1198 | } |
| 1199 | |
Antti Palosaari | d4d6a34 | 2014-09-04 18:35:59 -0300 | [diff] [blame] | 1200 | static int af9035_frontend_detach(struct dvb_usb_adapter *adap) |
| 1201 | { |
| 1202 | struct state *state = adap_to_priv(adap); |
| 1203 | struct dvb_usb_device *d = adap_to_d(adap); |
| 1204 | int demod2; |
| 1205 | |
| 1206 | dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id); |
| 1207 | |
| 1208 | /* |
| 1209 | * For dual tuner devices we have to resolve 2nd demod client, as there |
| 1210 | * is two different kind of tuner drivers; one is using I2C binding |
| 1211 | * and the other is using DVB attach/detach binding. |
| 1212 | */ |
| 1213 | switch (state->af9033_config[adap->id].tuner) { |
| 1214 | case AF9033_TUNER_IT9135_38: |
| 1215 | case AF9033_TUNER_IT9135_51: |
| 1216 | case AF9033_TUNER_IT9135_52: |
| 1217 | case AF9033_TUNER_IT9135_60: |
| 1218 | case AF9033_TUNER_IT9135_61: |
| 1219 | case AF9033_TUNER_IT9135_62: |
| 1220 | demod2 = 2; |
| 1221 | break; |
| 1222 | default: |
| 1223 | demod2 = 1; |
| 1224 | } |
| 1225 | |
| 1226 | if (adap->id == 1) { |
| 1227 | if (state->i2c_client[demod2]) |
| 1228 | af9035_del_i2c_dev(d); |
| 1229 | } else if (adap->id == 0) { |
| 1230 | if (state->i2c_client[0]) |
| 1231 | af9035_del_i2c_dev(d); |
| 1232 | } |
| 1233 | |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1237 | static const struct fc0011_config af9035_fc0011_config = { |
| 1238 | .i2c_address = 0x60, |
| 1239 | }; |
| 1240 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1241 | static struct mxl5007t_config af9035_mxl5007t_config[] = { |
| 1242 | { |
| 1243 | .xtal_freq_hz = MxL_XTAL_24_MHZ, |
| 1244 | .if_freq_hz = MxL_IF_4_57_MHZ, |
| 1245 | .invert_if = 0, |
| 1246 | .loop_thru_enable = 0, |
| 1247 | .clk_out_enable = 0, |
| 1248 | .clk_out_amp = MxL_CLKOUT_AMP_0_94V, |
| 1249 | }, { |
| 1250 | .xtal_freq_hz = MxL_XTAL_24_MHZ, |
| 1251 | .if_freq_hz = MxL_IF_4_57_MHZ, |
| 1252 | .invert_if = 0, |
| 1253 | .loop_thru_enable = 1, |
| 1254 | .clk_out_enable = 1, |
| 1255 | .clk_out_amp = MxL_CLKOUT_AMP_0_94V, |
| 1256 | } |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1257 | }; |
| 1258 | |
Gianluca Gennari | ce1fe37 | 2012-04-02 17:25:14 -0300 | [diff] [blame] | 1259 | static struct tda18218_config af9035_tda18218_config = { |
| 1260 | .i2c_address = 0x60, |
| 1261 | .i2c_wr_max = 21, |
| 1262 | }; |
| 1263 | |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1264 | static const struct fc0012_config af9035_fc0012_config[] = { |
| 1265 | { |
| 1266 | .i2c_address = 0x63, |
| 1267 | .xtal_freq = FC_XTAL_36_MHZ, |
Antti Palosaari | 3a98477 | 2012-12-09 12:33:04 -0300 | [diff] [blame] | 1268 | .dual_master = true, |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1269 | .loop_through = true, |
| 1270 | .clock_out = true, |
| 1271 | }, { |
| 1272 | .i2c_address = 0x63 | 0x80, /* I2C bus select hack */ |
| 1273 | .xtal_freq = FC_XTAL_36_MHZ, |
Antti Palosaari | 3a98477 | 2012-12-09 12:33:04 -0300 | [diff] [blame] | 1274 | .dual_master = true, |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1275 | } |
Antti Palosaari | ad3a758 | 2012-12-08 23:27:49 -0300 | [diff] [blame] | 1276 | }; |
| 1277 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1278 | static int af9035_tuner_attach(struct dvb_usb_adapter *adap) |
| 1279 | { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1280 | struct state *state = adap_to_priv(adap); |
| 1281 | struct dvb_usb_device *d = adap_to_d(adap); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1282 | int ret; |
| 1283 | struct dvb_frontend *fe; |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1284 | struct i2c_msg msg[1]; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1285 | u8 tuner_addr; |
Antti Palosaari | c10989a | 2014-08-09 14:49:46 -0300 | [diff] [blame] | 1286 | |
Antti Palosaari | d4d6a34 | 2014-09-04 18:35:59 -0300 | [diff] [blame] | 1287 | dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id); |
Antti Palosaari | df8f1be | 2013-02-03 13:46:56 -0300 | [diff] [blame] | 1288 | |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1289 | /* |
| 1290 | * XXX: Hack used in that function: we abuse unused I2C address bit [7] |
| 1291 | * to carry info about used I2C bus for dual tuner configuration. |
| 1292 | */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1293 | |
Antti Palosaari | 2a79eef | 2012-05-07 14:50:40 -0300 | [diff] [blame] | 1294 | switch (state->af9033_config[adap->id].tuner) { |
Antti Palosaari | b6c5fe7 | 2015-04-15 19:18:40 -0300 | [diff] [blame] | 1295 | case AF9033_TUNER_TUA9001: { |
| 1296 | struct tua9001_platform_data tua9001_pdata = { |
| 1297 | .dvb_frontend = adap->fe[0], |
| 1298 | }; |
| 1299 | |
| 1300 | /* |
| 1301 | * AF9035 gpiot3 = TUA9001 RESETN |
| 1302 | * AF9035 gpiot2 = TUA9001 RXEN |
| 1303 | */ |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1304 | |
| 1305 | /* configure gpiot2 and gpiot2 as output */ |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1306 | ret = af9035_wr_reg_mask(d, 0x00d8ec, 0x01, 0x01); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1307 | if (ret < 0) |
| 1308 | goto err; |
| 1309 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1310 | ret = af9035_wr_reg_mask(d, 0x00d8ed, 0x01, 0x01); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1311 | if (ret < 0) |
| 1312 | goto err; |
| 1313 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1314 | ret = af9035_wr_reg_mask(d, 0x00d8e8, 0x01, 0x01); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1315 | if (ret < 0) |
| 1316 | goto err; |
| 1317 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1318 | ret = af9035_wr_reg_mask(d, 0x00d8e9, 0x01, 0x01); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1319 | if (ret < 0) |
| 1320 | goto err; |
| 1321 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1322 | /* attach tuner */ |
Antti Palosaari | b6c5fe7 | 2015-04-15 19:18:40 -0300 | [diff] [blame] | 1323 | ret = af9035_add_i2c_dev(d, "tua9001", 0x60, &tua9001_pdata, |
| 1324 | &d->i2c_adap); |
| 1325 | if (ret) |
| 1326 | goto err; |
| 1327 | |
| 1328 | fe = adap->fe[0]; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1329 | break; |
Antti Palosaari | b6c5fe7 | 2015-04-15 19:18:40 -0300 | [diff] [blame] | 1330 | } |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1331 | case AF9033_TUNER_FC0011: |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1332 | fe = dvb_attach(fc0011_attach, adap->fe[0], |
| 1333 | &d->i2c_adap, &af9035_fc0011_config); |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 1334 | break; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1335 | case AF9033_TUNER_MXL5007T: |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1336 | if (adap->id == 0) { |
| 1337 | ret = af9035_wr_reg(d, 0x00d8e0, 1); |
| 1338 | if (ret < 0) |
| 1339 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1340 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1341 | ret = af9035_wr_reg(d, 0x00d8e1, 1); |
| 1342 | if (ret < 0) |
| 1343 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1344 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1345 | ret = af9035_wr_reg(d, 0x00d8df, 0); |
| 1346 | if (ret < 0) |
| 1347 | goto err; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1348 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1349 | msleep(30); |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1350 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1351 | ret = af9035_wr_reg(d, 0x00d8df, 1); |
| 1352 | if (ret < 0) |
| 1353 | goto err; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1354 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1355 | msleep(300); |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1356 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1357 | ret = af9035_wr_reg(d, 0x00d8c0, 1); |
| 1358 | if (ret < 0) |
| 1359 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1360 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1361 | ret = af9035_wr_reg(d, 0x00d8c1, 1); |
| 1362 | if (ret < 0) |
| 1363 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1364 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1365 | ret = af9035_wr_reg(d, 0x00d8bf, 0); |
| 1366 | if (ret < 0) |
| 1367 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1368 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1369 | ret = af9035_wr_reg(d, 0x00d8b4, 1); |
| 1370 | if (ret < 0) |
| 1371 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1372 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1373 | ret = af9035_wr_reg(d, 0x00d8b5, 1); |
| 1374 | if (ret < 0) |
| 1375 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1376 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1377 | ret = af9035_wr_reg(d, 0x00d8b3, 1); |
| 1378 | if (ret < 0) |
| 1379 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1380 | |
| 1381 | tuner_addr = 0x60; |
| 1382 | } else { |
| 1383 | tuner_addr = 0x60 | 0x80; /* I2C bus hack */ |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1384 | } |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1385 | |
| 1386 | /* attach tuner */ |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 1387 | fe = dvb_attach(mxl5007t_attach, adap->fe[0], &d->i2c_adap, |
| 1388 | tuner_addr, &af9035_mxl5007t_config[adap->id]); |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 1389 | break; |
Gianluca Gennari | ce1fe37 | 2012-04-02 17:25:14 -0300 | [diff] [blame] | 1390 | case AF9033_TUNER_TDA18218: |
| 1391 | /* attach tuner */ |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1392 | fe = dvb_attach(tda18218_attach, adap->fe[0], |
| 1393 | &d->i2c_adap, &af9035_tda18218_config); |
Gianluca Gennari | ce1fe37 | 2012-04-02 17:25:14 -0300 | [diff] [blame] | 1394 | break; |
Antti Palosaari | 7a893ba | 2015-04-14 20:07:16 -0300 | [diff] [blame] | 1395 | case AF9033_TUNER_FC2580: { |
| 1396 | struct fc2580_platform_data fc2580_pdata = { |
| 1397 | .dvb_frontend = adap->fe[0], |
| 1398 | }; |
| 1399 | |
Oliver Schinagl | d67ceb3 | 2012-09-20 14:57:17 -0300 | [diff] [blame] | 1400 | /* Tuner enable using gpiot2_o, gpiot2_en and gpiot2_on */ |
| 1401 | ret = af9035_wr_reg_mask(d, 0xd8eb, 0x01, 0x01); |
| 1402 | if (ret < 0) |
| 1403 | goto err; |
| 1404 | |
| 1405 | ret = af9035_wr_reg_mask(d, 0xd8ec, 0x01, 0x01); |
| 1406 | if (ret < 0) |
| 1407 | goto err; |
| 1408 | |
| 1409 | ret = af9035_wr_reg_mask(d, 0xd8ed, 0x01, 0x01); |
| 1410 | if (ret < 0) |
| 1411 | goto err; |
| 1412 | |
| 1413 | usleep_range(10000, 50000); |
| 1414 | /* attach tuner */ |
Antti Palosaari | 7a893ba | 2015-04-14 20:07:16 -0300 | [diff] [blame] | 1415 | ret = af9035_add_i2c_dev(d, "fc2580", 0x56, &fc2580_pdata, |
| 1416 | &d->i2c_adap); |
| 1417 | if (ret) |
| 1418 | goto err; |
| 1419 | |
| 1420 | fe = adap->fe[0]; |
Oliver Schinagl | d67ceb3 | 2012-09-20 14:57:17 -0300 | [diff] [blame] | 1421 | break; |
Antti Palosaari | 7a893ba | 2015-04-14 20:07:16 -0300 | [diff] [blame] | 1422 | } |
Antti Palosaari | 7e0bc29 | 2012-12-02 20:12:29 -0300 | [diff] [blame] | 1423 | case AF9033_TUNER_FC0012: |
| 1424 | /* |
| 1425 | * AF9035 gpiot2 = FC0012 enable |
| 1426 | * XXX: there seems to be something on gpioh8 too, but on my |
| 1427 | * my test I didn't find any difference. |
| 1428 | */ |
| 1429 | |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1430 | if (adap->id == 0) { |
| 1431 | /* configure gpiot2 as output and high */ |
| 1432 | ret = af9035_wr_reg_mask(d, 0xd8eb, 0x01, 0x01); |
| 1433 | if (ret < 0) |
| 1434 | goto err; |
Antti Palosaari | 7e0bc29 | 2012-12-02 20:12:29 -0300 | [diff] [blame] | 1435 | |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1436 | ret = af9035_wr_reg_mask(d, 0xd8ec, 0x01, 0x01); |
| 1437 | if (ret < 0) |
| 1438 | goto err; |
Antti Palosaari | 7e0bc29 | 2012-12-02 20:12:29 -0300 | [diff] [blame] | 1439 | |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1440 | ret = af9035_wr_reg_mask(d, 0xd8ed, 0x01, 0x01); |
| 1441 | if (ret < 0) |
| 1442 | goto err; |
| 1443 | } else { |
| 1444 | /* |
| 1445 | * FIXME: That belongs for the FC0012 driver. |
| 1446 | * Write 02 to FC0012 master tuner register 0d directly |
| 1447 | * in order to make slave tuner working. |
| 1448 | */ |
| 1449 | msg[0].addr = 0x63; |
| 1450 | msg[0].flags = 0; |
| 1451 | msg[0].len = 2; |
| 1452 | msg[0].buf = "\x0d\x02"; |
| 1453 | ret = i2c_transfer(&d->i2c_adap, msg, 1); |
| 1454 | if (ret < 0) |
| 1455 | goto err; |
| 1456 | } |
Antti Palosaari | 7e0bc29 | 2012-12-02 20:12:29 -0300 | [diff] [blame] | 1457 | |
| 1458 | usleep_range(10000, 50000); |
| 1459 | |
Antti Palosaari | ad3a758 | 2012-12-08 23:27:49 -0300 | [diff] [blame] | 1460 | fe = dvb_attach(fc0012_attach, adap->fe[0], &d->i2c_adap, |
Antti Palosaari | 0bb3d8a | 2012-12-09 12:01:41 -0300 | [diff] [blame] | 1461 | &af9035_fc0012_config[adap->id]); |
Antti Palosaari | 7e0bc29 | 2012-12-02 20:12:29 -0300 | [diff] [blame] | 1462 | break; |
Antti Palosaari | ac77fb0 | 2013-01-07 09:51:13 -0300 | [diff] [blame] | 1463 | case AF9033_TUNER_IT9135_38: |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 1464 | case AF9033_TUNER_IT9135_51: |
| 1465 | case AF9033_TUNER_IT9135_52: |
Antti Palosaari | 3b2a5e8 | 2014-08-26 17:14:16 -0300 | [diff] [blame] | 1466 | { |
| 1467 | struct it913x_config it913x_config = { |
| 1468 | .fe = adap->fe[0], |
| 1469 | .chip_ver = 1, |
| 1470 | }; |
| 1471 | |
Antti Palosaari | 676c350 | 2014-08-27 03:59:27 -0300 | [diff] [blame] | 1472 | if (state->dual_mode) { |
| 1473 | if (adap->id == 0) |
| 1474 | it913x_config.role = IT913X_ROLE_DUAL_MASTER; |
| 1475 | else |
| 1476 | it913x_config.role = IT913X_ROLE_DUAL_SLAVE; |
| 1477 | } |
| 1478 | |
Antti Palosaari | 3b2a5e8 | 2014-08-26 17:14:16 -0300 | [diff] [blame] | 1479 | ret = af9035_add_i2c_dev(d, "it913x", |
Antti Palosaari | a781edd | 2014-08-31 22:57:26 -0300 | [diff] [blame] | 1480 | state->af9033_i2c_addr[adap->id] >> 1, |
Olli Salonen | 5dcf5bf | 2014-09-21 07:53:18 -0300 | [diff] [blame] | 1481 | &it913x_config, &d->i2c_adap); |
Antti Palosaari | 3b2a5e8 | 2014-08-26 17:14:16 -0300 | [diff] [blame] | 1482 | if (ret) |
| 1483 | goto err; |
| 1484 | |
| 1485 | fe = adap->fe[0]; |
| 1486 | break; |
| 1487 | } |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 1488 | case AF9033_TUNER_IT9135_60: |
| 1489 | case AF9033_TUNER_IT9135_61: |
| 1490 | case AF9033_TUNER_IT9135_62: |
Antti Palosaari | 3b2a5e8 | 2014-08-26 17:14:16 -0300 | [diff] [blame] | 1491 | { |
| 1492 | struct it913x_config it913x_config = { |
| 1493 | .fe = adap->fe[0], |
| 1494 | .chip_ver = 2, |
| 1495 | }; |
| 1496 | |
Antti Palosaari | 676c350 | 2014-08-27 03:59:27 -0300 | [diff] [blame] | 1497 | if (state->dual_mode) { |
| 1498 | if (adap->id == 0) |
| 1499 | it913x_config.role = IT913X_ROLE_DUAL_MASTER; |
| 1500 | else |
| 1501 | it913x_config.role = IT913X_ROLE_DUAL_SLAVE; |
| 1502 | } |
| 1503 | |
Antti Palosaari | 3b2a5e8 | 2014-08-26 17:14:16 -0300 | [diff] [blame] | 1504 | ret = af9035_add_i2c_dev(d, "it913x", |
Antti Palosaari | a781edd | 2014-08-31 22:57:26 -0300 | [diff] [blame] | 1505 | state->af9033_i2c_addr[adap->id] >> 1, |
Olli Salonen | 5dcf5bf | 2014-09-21 07:53:18 -0300 | [diff] [blame] | 1506 | &it913x_config, &d->i2c_adap); |
Antti Palosaari | 3b2a5e8 | 2014-08-26 17:14:16 -0300 | [diff] [blame] | 1507 | if (ret) |
| 1508 | goto err; |
| 1509 | |
| 1510 | fe = adap->fe[0]; |
Antti Palosaari | ac77fb0 | 2013-01-07 09:51:13 -0300 | [diff] [blame] | 1511 | break; |
Antti Palosaari | 3b2a5e8 | 2014-08-26 17:14:16 -0300 | [diff] [blame] | 1512 | } |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1513 | default: |
| 1514 | fe = NULL; |
| 1515 | } |
| 1516 | |
| 1517 | if (fe == NULL) { |
| 1518 | ret = -ENODEV; |
| 1519 | goto err; |
| 1520 | } |
| 1521 | |
| 1522 | return 0; |
| 1523 | |
| 1524 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 1525 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1526 | |
| 1527 | return ret; |
| 1528 | } |
| 1529 | |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 1530 | static int it930x_tuner_attach(struct dvb_usb_adapter *adap) |
| 1531 | { |
| 1532 | struct state *state = adap_to_priv(adap); |
| 1533 | struct dvb_usb_device *d = adap_to_d(adap); |
| 1534 | int ret; |
| 1535 | struct si2157_config si2157_config; |
| 1536 | |
| 1537 | dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id); |
| 1538 | |
| 1539 | /* I2C master bus 2 clock speed 300k */ |
| 1540 | ret = af9035_wr_reg(d, 0x00f6a7, 0x07); |
| 1541 | if (ret < 0) |
| 1542 | goto err; |
| 1543 | |
| 1544 | /* I2C master bus 1,3 clock speed 300k */ |
| 1545 | ret = af9035_wr_reg(d, 0x00f103, 0x07); |
| 1546 | if (ret < 0) |
| 1547 | goto err; |
| 1548 | |
| 1549 | /* set gpio11 low */ |
| 1550 | ret = af9035_wr_reg_mask(d, 0xd8d4, 0x01, 0x01); |
| 1551 | if (ret < 0) |
| 1552 | goto err; |
| 1553 | |
| 1554 | ret = af9035_wr_reg_mask(d, 0xd8d5, 0x01, 0x01); |
| 1555 | if (ret < 0) |
| 1556 | goto err; |
| 1557 | |
| 1558 | ret = af9035_wr_reg_mask(d, 0xd8d3, 0x01, 0x01); |
| 1559 | if (ret < 0) |
| 1560 | goto err; |
| 1561 | |
| 1562 | /* Tuner enable using gpiot2_en, gpiot2_on and gpiot2_o (reset) */ |
| 1563 | ret = af9035_wr_reg_mask(d, 0xd8b8, 0x01, 0x01); |
| 1564 | if (ret < 0) |
| 1565 | goto err; |
| 1566 | |
| 1567 | ret = af9035_wr_reg_mask(d, 0xd8b9, 0x01, 0x01); |
| 1568 | if (ret < 0) |
| 1569 | goto err; |
| 1570 | |
| 1571 | ret = af9035_wr_reg_mask(d, 0xd8b7, 0x00, 0x01); |
| 1572 | if (ret < 0) |
| 1573 | goto err; |
| 1574 | |
| 1575 | msleep(200); |
| 1576 | |
| 1577 | ret = af9035_wr_reg_mask(d, 0xd8b7, 0x01, 0x01); |
| 1578 | if (ret < 0) |
| 1579 | goto err; |
| 1580 | |
| 1581 | memset(&si2157_config, 0, sizeof(si2157_config)); |
| 1582 | si2157_config.fe = adap->fe[0]; |
Olli Salonen | ee3c3e4 | 2015-05-05 13:54:17 -0300 | [diff] [blame] | 1583 | si2157_config.if_port = 1; |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 1584 | ret = af9035_add_i2c_dev(d, "si2157", 0x63, |
| 1585 | &si2157_config, state->i2c_adapter_demod); |
| 1586 | |
| 1587 | if (ret) |
| 1588 | goto err; |
| 1589 | |
| 1590 | return 0; |
| 1591 | |
| 1592 | err: |
| 1593 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 1594 | |
| 1595 | return ret; |
| 1596 | } |
| 1597 | |
| 1598 | |
| 1599 | static int it930x_tuner_detach(struct dvb_usb_adapter *adap) |
| 1600 | { |
| 1601 | struct state *state = adap_to_priv(adap); |
| 1602 | struct dvb_usb_device *d = adap_to_d(adap); |
| 1603 | |
| 1604 | dev_dbg(&d->udev->dev, "adap->id=%d\n", adap->id); |
| 1605 | |
| 1606 | if (adap->id == 1) { |
| 1607 | if (state->i2c_client[3]) |
| 1608 | af9035_del_i2c_dev(d); |
| 1609 | } else if (adap->id == 0) { |
| 1610 | if (state->i2c_client[1]) |
| 1611 | af9035_del_i2c_dev(d); |
| 1612 | } |
| 1613 | |
| 1614 | return 0; |
| 1615 | } |
| 1616 | |
| 1617 | |
Antti Palosaari | d4d6a34 | 2014-09-04 18:35:59 -0300 | [diff] [blame] | 1618 | static int af9035_tuner_detach(struct dvb_usb_adapter *adap) |
| 1619 | { |
| 1620 | struct state *state = adap_to_priv(adap); |
| 1621 | struct dvb_usb_device *d = adap_to_d(adap); |
| 1622 | |
| 1623 | dev_dbg(&d->udev->dev, "%s: adap->id=%d\n", __func__, adap->id); |
| 1624 | |
| 1625 | switch (state->af9033_config[adap->id].tuner) { |
Antti Palosaari | b6c5fe7 | 2015-04-15 19:18:40 -0300 | [diff] [blame] | 1626 | case AF9033_TUNER_TUA9001: |
Antti Palosaari | 7a893ba | 2015-04-14 20:07:16 -0300 | [diff] [blame] | 1627 | case AF9033_TUNER_FC2580: |
Antti Palosaari | d4d6a34 | 2014-09-04 18:35:59 -0300 | [diff] [blame] | 1628 | case AF9033_TUNER_IT9135_38: |
| 1629 | case AF9033_TUNER_IT9135_51: |
| 1630 | case AF9033_TUNER_IT9135_52: |
| 1631 | case AF9033_TUNER_IT9135_60: |
| 1632 | case AF9033_TUNER_IT9135_61: |
| 1633 | case AF9033_TUNER_IT9135_62: |
| 1634 | if (adap->id == 1) { |
| 1635 | if (state->i2c_client[3]) |
| 1636 | af9035_del_i2c_dev(d); |
| 1637 | } else if (adap->id == 0) { |
| 1638 | if (state->i2c_client[1]) |
| 1639 | af9035_del_i2c_dev(d); |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | return 0; |
| 1644 | } |
| 1645 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1646 | static int af9035_init(struct dvb_usb_device *d) |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1647 | { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1648 | struct state *state = d_to_priv(d); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1649 | int ret, i; |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 1650 | u16 frame_size = (d->udev->speed == USB_SPEED_FULL ? 5 : 87) * 188 / 4; |
| 1651 | u8 packet_size = (d->udev->speed == USB_SPEED_FULL ? 64 : 512) / 4; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1652 | struct reg_val_mask tab[] = { |
| 1653 | { 0x80f99d, 0x01, 0x01 }, |
| 1654 | { 0x80f9a4, 0x01, 0x01 }, |
| 1655 | { 0x00dd11, 0x00, 0x20 }, |
| 1656 | { 0x00dd11, 0x00, 0x40 }, |
| 1657 | { 0x00dd13, 0x00, 0x20 }, |
| 1658 | { 0x00dd13, 0x00, 0x40 }, |
| 1659 | { 0x00dd11, 0x20, 0x20 }, |
| 1660 | { 0x00dd88, (frame_size >> 0) & 0xff, 0xff}, |
| 1661 | { 0x00dd89, (frame_size >> 8) & 0xff, 0xff}, |
| 1662 | { 0x00dd0c, packet_size, 0xff}, |
| 1663 | { 0x00dd11, state->dual_mode << 6, 0x40 }, |
| 1664 | { 0x00dd8a, (frame_size >> 0) & 0xff, 0xff}, |
| 1665 | { 0x00dd8b, (frame_size >> 8) & 0xff, 0xff}, |
| 1666 | { 0x00dd0d, packet_size, 0xff }, |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1667 | { 0x80f9a3, state->dual_mode, 0x01 }, |
| 1668 | { 0x80f9cd, state->dual_mode, 0x01 }, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1669 | { 0x80f99d, 0x00, 0x01 }, |
| 1670 | { 0x80f9a4, 0x00, 0x01 }, |
| 1671 | }; |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1672 | |
Antti Palosaari | cb9114e | 2013-06-03 18:42:14 -0300 | [diff] [blame] | 1673 | dev_dbg(&d->udev->dev, |
| 1674 | "%s: USB speed=%d frame_size=%04x packet_size=%02x\n", |
| 1675 | __func__, d->udev->speed, frame_size, packet_size); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1676 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1677 | /* init endpoints */ |
| 1678 | for (i = 0; i < ARRAY_SIZE(tab); i++) { |
| 1679 | ret = af9035_wr_reg_mask(d, tab[i].reg, tab[i].val, |
| 1680 | tab[i].mask); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1681 | if (ret < 0) |
| 1682 | goto err; |
| 1683 | } |
| 1684 | |
| 1685 | return 0; |
| 1686 | |
| 1687 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 1688 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 1689 | |
| 1690 | return ret; |
| 1691 | } |
| 1692 | |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 1693 | static int it930x_init(struct dvb_usb_device *d) |
| 1694 | { |
| 1695 | struct state *state = d_to_priv(d); |
| 1696 | int ret, i; |
| 1697 | u16 frame_size = (d->udev->speed == USB_SPEED_FULL ? 5 : 816) * 188 / 4; |
| 1698 | u8 packet_size = (d->udev->speed == USB_SPEED_FULL ? 64 : 512) / 4; |
| 1699 | struct reg_val_mask tab[] = { |
| 1700 | { 0x00da1a, 0x00, 0x01 }, /* ignore_sync_byte */ |
| 1701 | { 0x00f41f, 0x04, 0x04 }, /* dvbt_inten */ |
| 1702 | { 0x00da10, 0x00, 0x01 }, /* mpeg_full_speed */ |
| 1703 | { 0x00f41a, 0x01, 0x01 }, /* dvbt_en */ |
| 1704 | { 0x00da1d, 0x01, 0x01 }, /* mp2_sw_rst, reset EP4 */ |
| 1705 | { 0x00dd11, 0x00, 0x20 }, /* ep4_tx_en, disable EP4 */ |
| 1706 | { 0x00dd13, 0x00, 0x20 }, /* ep4_tx_nak, disable EP4 NAK */ |
| 1707 | { 0x00dd11, 0x20, 0x20 }, /* ep4_tx_en, enable EP4 */ |
| 1708 | { 0x00dd11, 0x00, 0x40 }, /* ep5_tx_en, disable EP5 */ |
| 1709 | { 0x00dd13, 0x00, 0x40 }, /* ep5_tx_nak, disable EP5 NAK */ |
| 1710 | { 0x00dd11, state->dual_mode << 6, 0x40 }, /* enable EP5 */ |
| 1711 | { 0x00dd88, (frame_size >> 0) & 0xff, 0xff}, |
| 1712 | { 0x00dd89, (frame_size >> 8) & 0xff, 0xff}, |
| 1713 | { 0x00dd0c, packet_size, 0xff}, |
| 1714 | { 0x00dd8a, (frame_size >> 0) & 0xff, 0xff}, |
| 1715 | { 0x00dd8b, (frame_size >> 8) & 0xff, 0xff}, |
| 1716 | { 0x00dd0d, packet_size, 0xff }, |
| 1717 | { 0x00da1d, 0x00, 0x01 }, /* mp2_sw_rst, disable */ |
| 1718 | { 0x00d833, 0x01, 0xff }, /* slew rate ctrl: slew rate boosts */ |
| 1719 | { 0x00d830, 0x00, 0xff }, /* Bit 0 of output driving control */ |
| 1720 | { 0x00d831, 0x01, 0xff }, /* Bit 1 of output driving control */ |
| 1721 | { 0x00d832, 0x00, 0xff }, /* Bit 2 of output driving control */ |
| 1722 | |
| 1723 | /* suspend gpio1 for TS-C */ |
| 1724 | { 0x00d8b0, 0x01, 0xff }, /* gpio1 */ |
| 1725 | { 0x00d8b1, 0x01, 0xff }, /* gpio1 */ |
| 1726 | { 0x00d8af, 0x00, 0xff }, /* gpio1 */ |
| 1727 | |
| 1728 | /* suspend gpio7 for TS-D */ |
| 1729 | { 0x00d8c4, 0x01, 0xff }, /* gpio7 */ |
| 1730 | { 0x00d8c5, 0x01, 0xff }, /* gpio7 */ |
| 1731 | { 0x00d8c3, 0x00, 0xff }, /* gpio7 */ |
| 1732 | |
| 1733 | /* suspend gpio13 for TS-B */ |
| 1734 | { 0x00d8dc, 0x01, 0xff }, /* gpio13 */ |
| 1735 | { 0x00d8dd, 0x01, 0xff }, /* gpio13 */ |
| 1736 | { 0x00d8db, 0x00, 0xff }, /* gpio13 */ |
| 1737 | |
| 1738 | /* suspend gpio14 for TS-E */ |
| 1739 | { 0x00d8e4, 0x01, 0xff }, /* gpio14 */ |
| 1740 | { 0x00d8e5, 0x01, 0xff }, /* gpio14 */ |
| 1741 | { 0x00d8e3, 0x00, 0xff }, /* gpio14 */ |
| 1742 | |
| 1743 | /* suspend gpio15 for TS-A */ |
| 1744 | { 0x00d8e8, 0x01, 0xff }, /* gpio15 */ |
| 1745 | { 0x00d8e9, 0x01, 0xff }, /* gpio15 */ |
| 1746 | { 0x00d8e7, 0x00, 0xff }, /* gpio15 */ |
| 1747 | |
| 1748 | { 0x00da58, 0x00, 0x01 }, /* ts_in_src, serial */ |
| 1749 | { 0x00da73, 0x01, 0xff }, /* ts0_aggre_mode */ |
| 1750 | { 0x00da78, 0x47, 0xff }, /* ts0_sync_byte */ |
| 1751 | { 0x00da4c, 0x01, 0xff }, /* ts0_en */ |
| 1752 | { 0x00da5a, 0x1f, 0xff }, /* ts_fail_ignore */ |
| 1753 | }; |
| 1754 | |
| 1755 | dev_dbg(&d->udev->dev, |
| 1756 | "%s: USB speed=%d frame_size=%04x packet_size=%02x\n", |
| 1757 | __func__, d->udev->speed, frame_size, packet_size); |
| 1758 | |
| 1759 | /* init endpoints */ |
| 1760 | for (i = 0; i < ARRAY_SIZE(tab); i++) { |
| 1761 | ret = af9035_wr_reg_mask(d, tab[i].reg, |
| 1762 | tab[i].val, tab[i].mask); |
| 1763 | |
| 1764 | if (ret < 0) |
| 1765 | goto err; |
| 1766 | } |
| 1767 | |
| 1768 | return 0; |
| 1769 | err: |
| 1770 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 1771 | |
| 1772 | return ret; |
| 1773 | } |
| 1774 | |
| 1775 | |
Antti Palosaari | 37b44a0 | 2013-01-04 15:21:26 -0300 | [diff] [blame] | 1776 | #if IS_ENABLED(CONFIG_RC_CORE) |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1777 | static int af9035_rc_query(struct dvb_usb_device *d) |
| 1778 | { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1779 | int ret; |
Antti Palosaari | 75cd588 | 2013-03-08 17:50:21 -0300 | [diff] [blame] | 1780 | u32 key; |
| 1781 | u8 buf[4]; |
| 1782 | struct usb_req req = { CMD_IR_GET, 0, 0, NULL, 4, buf }; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1783 | |
| 1784 | ret = af9035_ctrl_msg(d, &req); |
Antti Palosaari | 1bfd529 | 2013-03-08 17:39:12 -0300 | [diff] [blame] | 1785 | if (ret == 1) |
| 1786 | return 0; |
| 1787 | else if (ret < 0) |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1788 | goto err; |
| 1789 | |
Antti Palosaari | 75cd588 | 2013-03-08 17:50:21 -0300 | [diff] [blame] | 1790 | if ((buf[2] + buf[3]) == 0xff) { |
| 1791 | if ((buf[0] + buf[1]) == 0xff) { |
| 1792 | /* NEC standard 16bit */ |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 1793 | key = RC_SCANCODE_NEC(buf[0], buf[2]); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1794 | } else { |
Antti Palosaari | 75cd588 | 2013-03-08 17:50:21 -0300 | [diff] [blame] | 1795 | /* NEC extended 24bit */ |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 1796 | key = RC_SCANCODE_NECX(buf[0] << 8 | buf[1], buf[2]); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1797 | } |
| 1798 | } else { |
Antti Palosaari | 75cd588 | 2013-03-08 17:50:21 -0300 | [diff] [blame] | 1799 | /* NEC full code 32bit */ |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 1800 | key = RC_SCANCODE_NEC32(buf[0] << 24 | buf[1] << 16 | |
| 1801 | buf[2] << 8 | buf[3]); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1802 | } |
| 1803 | |
Antti Palosaari | 75cd588 | 2013-03-08 17:50:21 -0300 | [diff] [blame] | 1804 | dev_dbg(&d->udev->dev, "%s: %*ph\n", __func__, 4, buf); |
| 1805 | |
David Härdeman | 120703f | 2014-04-03 20:31:30 -0300 | [diff] [blame] | 1806 | rc_keydown(d->rc_dev, RC_TYPE_NEC, key, 0); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1807 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1808 | return 0; |
Antti Palosaari | 1bfd529 | 2013-03-08 17:39:12 -0300 | [diff] [blame] | 1809 | |
| 1810 | err: |
| 1811 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
| 1812 | |
| 1813 | return ret; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | static int af9035_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc) |
| 1817 | { |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 1818 | struct state *state = d_to_priv(d); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1819 | int ret; |
| 1820 | u8 tmp; |
| 1821 | |
Antti Palosaari | 431a6d4 | 2013-03-07 18:28:25 -0300 | [diff] [blame] | 1822 | ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_IR_MODE, &tmp); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1823 | if (ret < 0) |
| 1824 | goto err; |
| 1825 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 1826 | dev_dbg(&d->udev->dev, "%s: ir_mode=%02x\n", __func__, tmp); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1827 | |
| 1828 | /* don't activate rc if in HID mode or if not available */ |
| 1829 | if (tmp == 5) { |
Antti Palosaari | 431a6d4 | 2013-03-07 18:28:25 -0300 | [diff] [blame] | 1830 | ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_IR_TYPE, |
Antti Palosaari | 9ea3681 | 2013-01-11 22:16:25 -0300 | [diff] [blame] | 1831 | &tmp); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1832 | if (ret < 0) |
| 1833 | goto err; |
| 1834 | |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 1835 | dev_dbg(&d->udev->dev, "%s: ir_type=%02x\n", __func__, tmp); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1836 | |
| 1837 | switch (tmp) { |
| 1838 | case 0: /* NEC */ |
| 1839 | default: |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1840 | rc->allowed_protos = RC_BIT_NEC; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1841 | break; |
| 1842 | case 1: /* RC6 */ |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 1843 | rc->allowed_protos = RC_BIT_RC6_MCE; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1844 | break; |
| 1845 | } |
| 1846 | |
| 1847 | rc->query = af9035_rc_query; |
| 1848 | rc->interval = 500; |
Antti Palosaari | de73bee | 2012-07-05 19:57:07 -0300 | [diff] [blame] | 1849 | |
| 1850 | /* load empty to enable rc */ |
| 1851 | if (!rc->map_name) |
| 1852 | rc->map_name = RC_MAP_EMPTY; |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | return 0; |
| 1856 | |
| 1857 | err: |
Antti Palosaari | 119f7a8 | 2012-09-12 20:23:53 -0300 | [diff] [blame] | 1858 | dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1859 | |
| 1860 | return ret; |
| 1861 | } |
Antti Palosaari | eed5670 | 2012-12-09 20:18:31 -0300 | [diff] [blame] | 1862 | #else |
| 1863 | #define af9035_get_rc_config NULL |
| 1864 | #endif |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1865 | |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 1866 | static int af9035_get_stream_config(struct dvb_frontend *fe, u8 *ts_type, |
| 1867 | struct usb_data_stream_properties *stream) |
| 1868 | { |
| 1869 | struct dvb_usb_device *d = fe_to_d(fe); |
Antti Palosaari | c10989a | 2014-08-09 14:49:46 -0300 | [diff] [blame] | 1870 | |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 1871 | dev_dbg(&d->udev->dev, "%s: adap=%d\n", __func__, fe_to_adap(fe)->id); |
| 1872 | |
| 1873 | if (d->udev->speed == USB_SPEED_FULL) |
| 1874 | stream->u.bulk.buffersize = 5 * 188; |
| 1875 | |
| 1876 | return 0; |
| 1877 | } |
| 1878 | |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 1879 | static int af9035_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) |
| 1880 | { |
Mauro Carvalho Chehab | ed97a6f | 2014-03-14 14:29:06 -0300 | [diff] [blame] | 1881 | struct state *state = adap_to_priv(adap); |
| 1882 | |
| 1883 | return state->ops.pid_filter_ctrl(adap->fe[0], onoff); |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | static int af9035_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, |
| 1887 | int onoff) |
| 1888 | { |
Mauro Carvalho Chehab | ed97a6f | 2014-03-14 14:29:06 -0300 | [diff] [blame] | 1889 | struct state *state = adap_to_priv(adap); |
| 1890 | |
| 1891 | return state->ops.pid_filter(adap->fe[0], index, pid, onoff); |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 1892 | } |
| 1893 | |
Antti Palosaari | b799b81 | 2013-01-11 16:22:07 -0300 | [diff] [blame] | 1894 | static int af9035_probe(struct usb_interface *intf, |
| 1895 | const struct usb_device_id *id) |
| 1896 | { |
| 1897 | struct usb_device *udev = interface_to_usbdev(intf); |
| 1898 | char manufacturer[sizeof("Afatech")]; |
| 1899 | |
| 1900 | memset(manufacturer, 0, sizeof(manufacturer)); |
| 1901 | usb_string(udev, udev->descriptor.iManufacturer, |
| 1902 | manufacturer, sizeof(manufacturer)); |
| 1903 | /* |
| 1904 | * There is two devices having same ID but different chipset. One uses |
| 1905 | * AF9015 and the other IT9135 chipset. Only difference seen on lsusb |
| 1906 | * is iManufacturer string. |
| 1907 | * |
| 1908 | * idVendor 0x0ccd TerraTec Electronic GmbH |
| 1909 | * idProduct 0x0099 |
| 1910 | * bcdDevice 2.00 |
| 1911 | * iManufacturer 1 Afatech |
| 1912 | * iProduct 2 DVB-T 2 |
| 1913 | * |
| 1914 | * idVendor 0x0ccd TerraTec Electronic GmbH |
| 1915 | * idProduct 0x0099 |
| 1916 | * bcdDevice 2.00 |
| 1917 | * iManufacturer 1 ITE Technologies, Inc. |
| 1918 | * iProduct 2 DVB-T TV Stick |
| 1919 | */ |
| 1920 | if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VID_TERRATEC) && |
| 1921 | (le16_to_cpu(udev->descriptor.idProduct) == 0x0099)) { |
| 1922 | if (!strcmp("Afatech", manufacturer)) { |
| 1923 | dev_dbg(&udev->dev, "%s: rejecting device\n", __func__); |
| 1924 | return -ENODEV; |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | return dvb_usbv2_probe(intf, id); |
| 1929 | } |
| 1930 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1931 | /* interface 0 is used by DVB-T receiver and |
| 1932 | interface 1 is for remote controller (HID) */ |
| 1933 | static const struct dvb_usb_device_properties af9035_props = { |
| 1934 | .driver_name = KBUILD_MODNAME, |
| 1935 | .owner = THIS_MODULE, |
| 1936 | .adapter_nr = adapter_nr, |
| 1937 | .size_of_priv = sizeof(struct state), |
| 1938 | |
| 1939 | .generic_bulk_ctrl_endpoint = 0x02, |
| 1940 | .generic_bulk_ctrl_endpoint_response = 0x81, |
| 1941 | |
| 1942 | .identify_state = af9035_identify_state, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1943 | .download_firmware = af9035_download_firmware, |
| 1944 | |
| 1945 | .i2c_algo = &af9035_i2c_algo, |
| 1946 | .read_config = af9035_read_config, |
| 1947 | .frontend_attach = af9035_frontend_attach, |
Antti Palosaari | d4d6a34 | 2014-09-04 18:35:59 -0300 | [diff] [blame] | 1948 | .frontend_detach = af9035_frontend_detach, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1949 | .tuner_attach = af9035_tuner_attach, |
Antti Palosaari | d4d6a34 | 2014-09-04 18:35:59 -0300 | [diff] [blame] | 1950 | .tuner_detach = af9035_tuner_detach, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1951 | .init = af9035_init, |
| 1952 | .get_rc_config = af9035_get_rc_config, |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 1953 | .get_stream_config = af9035_get_stream_config, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1954 | |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 1955 | .get_adapter_count = af9035_get_adapter_count, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1956 | .adapter = { |
| 1957 | { |
Antti Palosaari | bada342 | 2013-01-11 20:45:11 -0300 | [diff] [blame] | 1958 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | |
| 1959 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, |
| 1960 | |
| 1961 | .pid_filter_count = 32, |
| 1962 | .pid_filter_ctrl = af9035_pid_filter_ctrl, |
| 1963 | .pid_filter = af9035_pid_filter, |
| 1964 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1965 | .stream = DVB_USB_STREAM_BULK(0x84, 6, 87 * 188), |
| 1966 | }, { |
Antti Palosaari | b24c2b4 | 2014-02-13 15:53:05 -0300 | [diff] [blame] | 1967 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | |
| 1968 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, |
| 1969 | |
| 1970 | .pid_filter_count = 32, |
| 1971 | .pid_filter_ctrl = af9035_pid_filter_ctrl, |
| 1972 | .pid_filter = af9035_pid_filter, |
| 1973 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 1974 | .stream = DVB_USB_STREAM_BULK(0x85, 6, 87 * 188), |
| 1975 | }, |
| 1976 | }, |
| 1977 | }; |
| 1978 | |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 1979 | static const struct dvb_usb_device_properties it930x_props = { |
| 1980 | .driver_name = KBUILD_MODNAME, |
| 1981 | .owner = THIS_MODULE, |
| 1982 | .adapter_nr = adapter_nr, |
| 1983 | .size_of_priv = sizeof(struct state), |
| 1984 | |
| 1985 | .generic_bulk_ctrl_endpoint = 0x02, |
| 1986 | .generic_bulk_ctrl_endpoint_response = 0x81, |
| 1987 | |
| 1988 | .identify_state = af9035_identify_state, |
| 1989 | .download_firmware = af9035_download_firmware, |
| 1990 | |
| 1991 | .i2c_algo = &af9035_i2c_algo, |
| 1992 | .read_config = af9035_read_config, |
| 1993 | .frontend_attach = it930x_frontend_attach, |
| 1994 | .frontend_detach = af9035_frontend_detach, |
| 1995 | .tuner_attach = it930x_tuner_attach, |
| 1996 | .tuner_detach = it930x_tuner_detach, |
| 1997 | .init = it930x_init, |
| 1998 | .get_stream_config = af9035_get_stream_config, |
| 1999 | |
| 2000 | .get_adapter_count = af9035_get_adapter_count, |
| 2001 | .adapter = { |
| 2002 | { |
| 2003 | .stream = DVB_USB_STREAM_BULK(0x84, 4, 816 * 188), |
| 2004 | }, { |
| 2005 | .stream = DVB_USB_STREAM_BULK(0x85, 4, 816 * 188), |
| 2006 | }, |
| 2007 | }, |
| 2008 | }; |
| 2009 | |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 2010 | static const struct usb_device_id af9035_id_table[] = { |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 2011 | /* AF9035 devices */ |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 2012 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_9035, |
| 2013 | &af9035_props, "Afatech AF9035 reference design", NULL) }, |
| 2014 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1000, |
| 2015 | &af9035_props, "Afatech AF9035 reference design", NULL) }, |
| 2016 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1001, |
| 2017 | &af9035_props, "Afatech AF9035 reference design", NULL) }, |
| 2018 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1002, |
| 2019 | &af9035_props, "Afatech AF9035 reference design", NULL) }, |
| 2020 | { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1003, |
| 2021 | &af9035_props, "Afatech AF9035 reference design", NULL) }, |
| 2022 | { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK, |
| 2023 | &af9035_props, "TerraTec Cinergy T Stick", NULL) }, |
| 2024 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835, |
| 2025 | &af9035_props, "AVerMedia AVerTV Volar HD/PRO (A835)", NULL) }, |
| 2026 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_B835, |
| 2027 | &af9035_props, "AVerMedia AVerTV Volar HD/PRO (A835)", NULL) }, |
| 2028 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_1867, |
| 2029 | &af9035_props, "AVerMedia HD Volar (A867)", NULL) }, |
| 2030 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A867, |
| 2031 | &af9035_props, "AVerMedia HD Volar (A867)", NULL) }, |
| 2032 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_TWINSTAR, |
| 2033 | &af9035_props, "AVerMedia Twinstar (A825)", NULL) }, |
Oliver Schinagl | d67ceb3 | 2012-09-20 14:57:17 -0300 | [diff] [blame] | 2034 | { DVB_USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3100MINI_PLUS, |
| 2035 | &af9035_props, "Asus U3100Mini Plus", NULL) }, |
Antti Palosaari | cb9114e | 2013-06-03 18:42:14 -0300 | [diff] [blame] | 2036 | { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00aa, |
Fabrizio Gazzato | d9b7595 | 2013-02-17 18:25:34 -0300 | [diff] [blame] | 2037 | &af9035_props, "TerraTec Cinergy T Stick (rev. 2)", NULL) }, |
Antti Palosaari | baf06b5 | 2015-05-21 16:47:15 -0300 | [diff] [blame] | 2038 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, 0x0337, |
| 2039 | &af9035_props, "AVerMedia HD Volar (A867)", NULL) }, |
Antti Palosaari | b3f0227 | 2015-04-15 15:01:22 -0300 | [diff] [blame] | 2040 | |
Antti Palosaari | bc3c9e1 | 2013-02-01 22:23:07 -0300 | [diff] [blame] | 2041 | /* IT9135 devices */ |
Malcolm Priestley | 7a541ce | 2014-02-08 13:11:16 -0300 | [diff] [blame] | 2042 | { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135, |
| 2043 | &af9035_props, "ITE 9135 Generic", RC_MAP_IT913X_V1) }, |
| 2044 | { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9005, |
| 2045 | &af9035_props, "ITE 9135(9005) Generic", RC_MAP_IT913X_V2) }, |
| 2046 | { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9006, |
| 2047 | &af9035_props, "ITE 9135(9006) Generic", RC_MAP_IT913X_V1) }, |
| 2048 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835B_1835, |
| 2049 | &af9035_props, "Avermedia A835B(1835)", RC_MAP_IT913X_V2) }, |
| 2050 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835B_2835, |
| 2051 | &af9035_props, "Avermedia A835B(2835)", RC_MAP_IT913X_V2) }, |
| 2052 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835B_3835, |
| 2053 | &af9035_props, "Avermedia A835B(3835)", RC_MAP_IT913X_V2) }, |
| 2054 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835B_4835, |
| 2055 | &af9035_props, "Avermedia A835B(4835)", RC_MAP_IT913X_V2) }, |
| 2056 | { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_H335, |
| 2057 | &af9035_props, "Avermedia H335", RC_MAP_IT913X_V2) }, |
Malcolm Priestley | 37973e0 | 2014-02-09 10:04:06 -0300 | [diff] [blame] | 2058 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB499_2T_T09, |
| 2059 | &af9035_props, "Kworld UB499-2T T09", RC_MAP_IT913X_V1) }, |
| 2060 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV22_IT9137, |
| 2061 | &af9035_props, "Sveon STV22 Dual DVB-T HDTV", |
| 2062 | RC_MAP_IT913X_V1) }, |
| 2063 | { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CTVDIGDUAL_V2, |
| 2064 | &af9035_props, "Digital Dual TV Receiver CTVDIGDUAL_V2", |
| 2065 | RC_MAP_IT913X_V1) }, |
Antti Palosaari | b799b81 | 2013-01-11 16:22:07 -0300 | [diff] [blame] | 2066 | /* XXX: that same ID [0ccd:0099] is used by af9015 driver too */ |
| 2067 | { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x0099, |
Antti Palosaari | c10989a | 2014-08-09 14:49:46 -0300 | [diff] [blame] | 2068 | &af9035_props, "TerraTec Cinergy T Stick Dual RC (rev. 2)", |
| 2069 | NULL) }, |
Antti Palosaari | 0c413d1 | 2013-08-08 19:41:06 -0300 | [diff] [blame] | 2070 | { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a05, |
| 2071 | &af9035_props, "Leadtek WinFast DTV Dongle Dual", NULL) }, |
Antti Palosaari | 261cb200 | 2014-02-01 11:30:50 -0300 | [diff] [blame] | 2072 | { DVB_USB_DEVICE(USB_VID_HAUPPAUGE, 0xf900, |
| 2073 | &af9035_props, "Hauppauge WinTV-MiniStick 2", NULL) }, |
Malcolm Priestley | a04646c | 2014-08-05 06:19:16 -0300 | [diff] [blame] | 2074 | { DVB_USB_DEVICE(USB_VID_PCTV, USB_PID_PCTV_78E, |
Antti Palosaari | 5c114a4 | 2014-09-01 00:38:01 -0300 | [diff] [blame] | 2075 | &af9035_props, "PCTV AndroiDTV (78e)", RC_MAP_IT913X_V1) }, |
Malcolm Priestley | a04646c | 2014-08-05 06:19:16 -0300 | [diff] [blame] | 2076 | { DVB_USB_DEVICE(USB_VID_PCTV, USB_PID_PCTV_79E, |
Antti Palosaari | 5c114a4 | 2014-09-01 00:38:01 -0300 | [diff] [blame] | 2077 | &af9035_props, "PCTV microStick (79e)", RC_MAP_IT913X_V2) }, |
Antti Palosaari | b3f0227 | 2015-04-15 15:01:22 -0300 | [diff] [blame] | 2078 | |
| 2079 | /* IT930x devices */ |
| 2080 | { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9303, |
| 2081 | &it930x_props, "ITE 9303 Generic", NULL) }, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 2082 | { } |
| 2083 | }; |
| 2084 | MODULE_DEVICE_TABLE(usb, af9035_id_table); |
| 2085 | |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 2086 | static struct usb_driver af9035_usb_driver = { |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 2087 | .name = KBUILD_MODNAME, |
| 2088 | .id_table = af9035_id_table, |
Antti Palosaari | b799b81 | 2013-01-11 16:22:07 -0300 | [diff] [blame] | 2089 | .probe = af9035_probe, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 2090 | .disconnect = dvb_usbv2_disconnect, |
| 2091 | .suspend = dvb_usbv2_suspend, |
| 2092 | .resume = dvb_usbv2_resume, |
Antti Palosaari | 04966aa | 2012-08-14 22:21:08 -0300 | [diff] [blame] | 2093 | .reset_resume = dvb_usbv2_reset_resume, |
Antti Palosaari | 5da2aec | 2012-06-17 23:15:03 -0300 | [diff] [blame] | 2094 | .no_dynamic_id = 1, |
| 2095 | .soft_unbind = 1, |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 2096 | }; |
| 2097 | |
Gianluca Gennari | 48bf7e1 | 2012-04-02 17:25:17 -0300 | [diff] [blame] | 2098 | module_usb_driver(af9035_usb_driver); |
Antti Palosaari | 7f882c2 | 2012-03-30 09:10:08 -0300 | [diff] [blame] | 2099 | |
| 2100 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 2101 | MODULE_DESCRIPTION("Afatech AF9035 driver"); |
| 2102 | MODULE_LICENSE("GPL"); |
Antti Palosaari | 4395e4b | 2012-09-12 12:19:06 -0300 | [diff] [blame] | 2103 | MODULE_FIRMWARE(AF9035_FIRMWARE_AF9035); |
Antti Palosaari | 74c1883 | 2013-01-07 15:16:54 -0300 | [diff] [blame] | 2104 | MODULE_FIRMWARE(AF9035_FIRMWARE_IT9135_V1); |
| 2105 | MODULE_FIRMWARE(AF9035_FIRMWARE_IT9135_V2); |
Olli Salonen | 5b55608 | 2014-09-21 07:53:19 -0300 | [diff] [blame] | 2106 | MODULE_FIRMWARE(AF9035_FIRMWARE_IT9303); |