blob: 66f65197c40d26ffa88695d0bc47e843d486297a [file] [log] [blame]
Antti Palosaari7f882c22012-03-30 09:10:08 -03001/*
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 Palosaari7f882c22012-03-30 09:10:08 -030023
24DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
Antti Palosaari7f882c22012-03-30 09:10:08 -030025
Michael Büschb1a95992012-04-01 16:33:48 -030026static u16 af9035_checksum(const u8 *buf, size_t len)
27{
28 size_t i;
29 u16 checksum = 0;
30
31 for (i = 1; i < len; i++) {
32 if (i % 2)
33 checksum += buf[i] << 8;
34 else
35 checksum += buf[i];
36 }
37 checksum = ~checksum;
38
39 return checksum;
40}
41
Antti Palosaari5da2aec2012-06-17 23:15:03 -030042static int af9035_ctrl_msg(struct dvb_usb_device *d, struct usb_req *req)
Antti Palosaari7f882c22012-03-30 09:10:08 -030043{
Antti Palosaari7f882c22012-03-30 09:10:08 -030044#define REQ_HDR_LEN 4 /* send header size */
45#define ACK_HDR_LEN 3 /* rece header size */
46#define CHECKSUM_LEN 2
47#define USB_TIMEOUT 2000
Antti Palosaari5da2aec2012-06-17 23:15:03 -030048 struct state *state = d_to_priv(d);
49 int ret, wlen, rlen;
Antti Palosaari6fb39c52012-04-06 16:32:30 -030050 u16 checksum, tmp_checksum;
Antti Palosaari7f882c22012-03-30 09:10:08 -030051
Antti Palosaari3484d372013-02-26 13:56:34 -030052 mutex_lock(&d->usb_mutex);
53
Antti Palosaari7f882c22012-03-30 09:10:08 -030054 /* buffer overflow check */
55 if (req->wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) ||
Antti Palosaari119f7a82012-09-12 20:23:53 -030056 req->rlen > (BUF_LEN - ACK_HDR_LEN - CHECKSUM_LEN)) {
57 dev_err(&d->udev->dev, "%s: too much data wlen=%d rlen=%d\n",
58 __func__, req->wlen, req->rlen);
Antti Palosaari3484d372013-02-26 13:56:34 -030059 ret = -EINVAL;
60 goto err;
Antti Palosaari7f882c22012-03-30 09:10:08 -030061 }
62
Antti Palosaari3484d372013-02-26 13:56:34 -030063 state->buf[0] = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN - 1;
64 state->buf[1] = req->mbox;
65 state->buf[2] = req->cmd;
66 state->buf[3] = state->seq++;
67 memcpy(&state->buf[REQ_HDR_LEN], req->wbuf, req->wlen);
Antti Palosaari5da2aec2012-06-17 23:15:03 -030068
69 wlen = REQ_HDR_LEN + req->wlen + CHECKSUM_LEN;
70 rlen = ACK_HDR_LEN + req->rlen + CHECKSUM_LEN;
Antti Palosaari7f882c22012-03-30 09:10:08 -030071
72 /* calc and add checksum */
Antti Palosaari3484d372013-02-26 13:56:34 -030073 checksum = af9035_checksum(state->buf, state->buf[0] - 1);
74 state->buf[state->buf[0] - 1] = (checksum >> 8);
75 state->buf[state->buf[0] - 0] = (checksum & 0xff);
Antti Palosaari7f882c22012-03-30 09:10:08 -030076
Antti Palosaari5da2aec2012-06-17 23:15:03 -030077 /* no ack for these packets */
78 if (req->cmd == CMD_FW_DL)
79 rlen = 0;
Antti Palosaari7f882c22012-03-30 09:10:08 -030080
Antti Palosaari3484d372013-02-26 13:56:34 -030081 ret = dvb_usbv2_generic_rw_locked(d,
82 state->buf, wlen, state->buf, rlen);
Antti Palosaari5da2aec2012-06-17 23:15:03 -030083 if (ret)
84 goto err;
Antti Palosaari7f882c22012-03-30 09:10:08 -030085
86 /* no ack for those packets */
87 if (req->cmd == CMD_FW_DL)
Antti Palosaari5da2aec2012-06-17 23:15:03 -030088 goto exit;
Antti Palosaari7f882c22012-03-30 09:10:08 -030089
Michael Büschb1a95992012-04-01 16:33:48 -030090 /* verify checksum */
Antti Palosaari3484d372013-02-26 13:56:34 -030091 checksum = af9035_checksum(state->buf, rlen - 2);
92 tmp_checksum = (state->buf[rlen - 2] << 8) | state->buf[rlen - 1];
Antti Palosaari6fb39c52012-04-06 16:32:30 -030093 if (tmp_checksum != checksum) {
Antti Palosaari119f7a82012-09-12 20:23:53 -030094 dev_err(&d->udev->dev, "%s: command=%02x checksum mismatch " \
95 "(%04x != %04x)\n", KBUILD_MODNAME, req->cmd,
96 tmp_checksum, checksum);
Michael Büschb1a95992012-04-01 16:33:48 -030097 ret = -EIO;
Antti Palosaari5da2aec2012-06-17 23:15:03 -030098 goto err;
Michael Büschb1a95992012-04-01 16:33:48 -030099 }
Antti Palosaari6fb39c52012-04-06 16:32:30 -0300100
Antti Palosaari7f882c22012-03-30 09:10:08 -0300101 /* check status */
Antti Palosaari3484d372013-02-26 13:56:34 -0300102 if (state->buf[2]) {
Antti Palosaari119f7a82012-09-12 20:23:53 -0300103 dev_dbg(&d->udev->dev, "%s: command=%02x failed fw error=%d\n",
Antti Palosaari3484d372013-02-26 13:56:34 -0300104 __func__, req->cmd, state->buf[2]);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300105 ret = -EIO;
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300106 goto err;
Antti Palosaari7f882c22012-03-30 09:10:08 -0300107 }
108
109 /* read request, copy returned data to return buf */
110 if (req->rlen)
Antti Palosaari3484d372013-02-26 13:56:34 -0300111 memcpy(req->rbuf, &state->buf[ACK_HDR_LEN], req->rlen);
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300112exit:
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300113err:
Antti Palosaari3484d372013-02-26 13:56:34 -0300114 mutex_unlock(&d->usb_mutex);
115 if (ret)
116 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300117 return ret;
118}
119
120/* write multiple registers */
121static int af9035_wr_regs(struct dvb_usb_device *d, u32 reg, u8 *val, int len)
122{
123 u8 wbuf[6 + len];
124 u8 mbox = (reg >> 16) & 0xff;
125 struct usb_req req = { CMD_MEM_WR, mbox, sizeof(wbuf), wbuf, 0, NULL };
126
127 wbuf[0] = len;
128 wbuf[1] = 2;
129 wbuf[2] = 0;
130 wbuf[3] = 0;
131 wbuf[4] = (reg >> 8) & 0xff;
132 wbuf[5] = (reg >> 0) & 0xff;
133 memcpy(&wbuf[6], val, len);
134
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300135 return af9035_ctrl_msg(d, &req);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300136}
137
138/* read multiple registers */
139static int af9035_rd_regs(struct dvb_usb_device *d, u32 reg, u8 *val, int len)
140{
141 u8 wbuf[] = { len, 2, 0, 0, (reg >> 8) & 0xff, reg & 0xff };
142 u8 mbox = (reg >> 16) & 0xff;
143 struct usb_req req = { CMD_MEM_RD, mbox, sizeof(wbuf), wbuf, len, val };
144
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300145 return af9035_ctrl_msg(d, &req);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300146}
147
148/* write single register */
149static int af9035_wr_reg(struct dvb_usb_device *d, u32 reg, u8 val)
150{
151 return af9035_wr_regs(d, reg, &val, 1);
152}
153
154/* read single register */
155static int af9035_rd_reg(struct dvb_usb_device *d, u32 reg, u8 *val)
156{
157 return af9035_rd_regs(d, reg, val, 1);
158}
159
160/* write single register with mask */
161static int af9035_wr_reg_mask(struct dvb_usb_device *d, u32 reg, u8 val,
162 u8 mask)
163{
164 int ret;
165 u8 tmp;
166
167 /* no need for read if whole reg is written */
168 if (mask != 0xff) {
169 ret = af9035_rd_regs(d, reg, &tmp, 1);
170 if (ret)
171 return ret;
172
173 val &= mask;
174 tmp &= ~mask;
175 val |= tmp;
176 }
177
178 return af9035_wr_regs(d, reg, &val, 1);
179}
180
181static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
182 struct i2c_msg msg[], int num)
183{
184 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300185 struct state *state = d_to_priv(d);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300186 int ret;
187
188 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
189 return -EAGAIN;
190
Antti Palosaariad30e912012-04-02 20:18:59 -0300191 /*
192 * I2C sub header is 5 bytes long. Meaning of those bytes are:
193 * 0: data len
194 * 1: I2C addr << 1
195 * 2: reg addr len
196 * byte 3 and 4 can be used as reg addr
197 * 3: reg addr MSB
198 * used when reg addr len is set to 2
199 * 4: reg addr LSB
200 * used when reg addr len is set to 1 or 2
201 *
202 * For the simplify we do not use register addr at all.
203 * NOTE: As a firmware knows tuner type there is very small possibility
204 * there could be some tuner I2C hacks done by firmware and this may
205 * lead problems if firmware expects those bytes are used.
206 */
Antti Palosaari7f882c22012-03-30 09:10:08 -0300207 if (num == 2 && !(msg[0].flags & I2C_M_RD) &&
208 (msg[1].flags & I2C_M_RD)) {
209 if (msg[0].len > 40 || msg[1].len > 40) {
210 /* TODO: correct limits > 40 */
211 ret = -EOPNOTSUPP;
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300212 } else if ((msg[0].addr == state->af9033_config[0].i2c_addr) ||
213 (msg[0].addr == state->af9033_config[1].i2c_addr)) {
Antti Palosaaribf97b632012-12-08 22:51:19 -0300214 /* demod access via firmware interface */
Antti Palosaari7f882c22012-03-30 09:10:08 -0300215 u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 |
216 msg[0].buf[2];
Antti Palosaaribf97b632012-12-08 22:51:19 -0300217
218 if (msg[0].addr == state->af9033_config[1].i2c_addr)
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300219 reg |= 0x100000;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300220
Antti Palosaari7f882c22012-03-30 09:10:08 -0300221 ret = af9035_rd_regs(d, reg, &msg[1].buf[0],
222 msg[1].len);
223 } else {
224 /* I2C */
Antti Palosaariad30e912012-04-02 20:18:59 -0300225 u8 buf[5 + msg[0].len];
Antti Palosaari7f882c22012-03-30 09:10:08 -0300226 struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf),
227 buf, msg[1].len, msg[1].buf };
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300228 req.mbox |= ((msg[0].addr & 0x80) >> 3);
Hans-Frieder Vogt812fe6d2012-04-01 14:11:29 -0300229 buf[0] = msg[1].len;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300230 buf[1] = msg[0].addr << 1;
Antti Palosaariad30e912012-04-02 20:18:59 -0300231 buf[2] = 0x00; /* reg addr len */
232 buf[3] = 0x00; /* reg addr MSB */
233 buf[4] = 0x00; /* reg addr LSB */
234 memcpy(&buf[5], msg[0].buf, msg[0].len);
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300235 ret = af9035_ctrl_msg(d, &req);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300236 }
237 } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
238 if (msg[0].len > 40) {
239 /* TODO: correct limits > 40 */
240 ret = -EOPNOTSUPP;
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300241 } else if ((msg[0].addr == state->af9033_config[0].i2c_addr) ||
242 (msg[0].addr == state->af9033_config[1].i2c_addr)) {
Antti Palosaaribf97b632012-12-08 22:51:19 -0300243 /* demod access via firmware interface */
Antti Palosaari7f882c22012-03-30 09:10:08 -0300244 u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 |
245 msg[0].buf[2];
Antti Palosaaribf97b632012-12-08 22:51:19 -0300246
247 if (msg[0].addr == state->af9033_config[1].i2c_addr)
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300248 reg |= 0x100000;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300249
Antti Palosaari7f882c22012-03-30 09:10:08 -0300250 ret = af9035_wr_regs(d, reg, &msg[0].buf[3],
251 msg[0].len - 3);
252 } else {
253 /* I2C */
Antti Palosaariad30e912012-04-02 20:18:59 -0300254 u8 buf[5 + msg[0].len];
Antti Palosaari7f882c22012-03-30 09:10:08 -0300255 struct usb_req req = { CMD_I2C_WR, 0, sizeof(buf), buf,
256 0, NULL };
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300257 req.mbox |= ((msg[0].addr & 0x80) >> 3);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300258 buf[0] = msg[0].len;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300259 buf[1] = msg[0].addr << 1;
Antti Palosaariad30e912012-04-02 20:18:59 -0300260 buf[2] = 0x00; /* reg addr len */
261 buf[3] = 0x00; /* reg addr MSB */
262 buf[4] = 0x00; /* reg addr LSB */
263 memcpy(&buf[5], msg[0].buf, msg[0].len);
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300264 ret = af9035_ctrl_msg(d, &req);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300265 }
266 } else {
267 /*
268 * We support only two kind of I2C transactions:
269 * 1) 1 x read + 1 x write
270 * 2) 1 x write
271 */
272 ret = -EOPNOTSUPP;
273 }
274
275 mutex_unlock(&d->i2c_mutex);
276
277 if (ret < 0)
278 return ret;
279 else
280 return num;
281}
282
283static u32 af9035_i2c_functionality(struct i2c_adapter *adapter)
284{
285 return I2C_FUNC_I2C;
286}
287
288static struct i2c_algorithm af9035_i2c_algo = {
289 .master_xfer = af9035_i2c_master_xfer,
290 .functionality = af9035_i2c_functionality,
291};
292
Antti Palosaaria0921af2012-06-18 23:42:53 -0300293static int af9035_identify_state(struct dvb_usb_device *d, const char **name)
Antti Palosaari7f882c22012-03-30 09:10:08 -0300294{
295 int ret;
296 u8 wbuf[1] = { 1 };
297 u8 rbuf[4];
298 struct usb_req req = { CMD_FW_QUERYINFO, 0, sizeof(wbuf), wbuf,
299 sizeof(rbuf), rbuf };
300
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300301 ret = af9035_ctrl_msg(d, &req);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300302 if (ret < 0)
303 goto err;
304
Antti Palosaari119f7a82012-09-12 20:23:53 -0300305 dev_dbg(&d->udev->dev, "%s: reply=%*ph\n", __func__, 4, rbuf);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300306 if (rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3])
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300307 ret = WARM;
Antti Palosaari7f882c22012-03-30 09:10:08 -0300308 else
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300309 ret = COLD;
Antti Palosaari7f882c22012-03-30 09:10:08 -0300310
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300311 return ret;
Antti Palosaari7f882c22012-03-30 09:10:08 -0300312
313err:
Antti Palosaari119f7a82012-09-12 20:23:53 -0300314 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300315
316 return ret;
317}
318
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300319static int af9035_download_firmware(struct dvb_usb_device *d,
Antti Palosaari7f882c22012-03-30 09:10:08 -0300320 const struct firmware *fw)
321{
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300322 int ret, i, j, len;
Antti Palosaari7f882c22012-03-30 09:10:08 -0300323 u8 wbuf[1];
324 u8 rbuf[4];
Antti Palosaari7f882c22012-03-30 09:10:08 -0300325 struct usb_req req = { 0, 0, 0, NULL, 0, NULL };
326 struct usb_req req_fw_dl = { CMD_FW_DL, 0, 0, wbuf, 0, NULL };
327 struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300328 u8 hdr_core, tmp;
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300329 u16 hdr_addr, hdr_data_len, hdr_checksum;
Antti Palosaari6fb39c52012-04-06 16:32:30 -0300330 #define MAX_DATA 58
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300331 #define HDR_SIZE 7
Antti Palosaari7f882c22012-03-30 09:10:08 -0300332
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300333 /*
Antti Palosaaribf97b632012-12-08 22:51:19 -0300334 * In case of dual tuner configuration we need to do some extra
335 * initialization in order to download firmware to slave demod too,
336 * which is done by master demod.
337 * Master feeds also clock and controls power via GPIO.
338 */
339 ret = af9035_rd_reg(d, EEPROM_DUAL_MODE, &tmp);
340 if (ret < 0)
341 goto err;
342
343 if (tmp) {
344 /* configure gpioh1, reset & power slave demod */
345 ret = af9035_wr_reg_mask(d, 0x00d8b0, 0x01, 0x01);
346 if (ret < 0)
347 goto err;
348
349 ret = af9035_wr_reg_mask(d, 0x00d8b1, 0x01, 0x01);
350 if (ret < 0)
351 goto err;
352
353 ret = af9035_wr_reg_mask(d, 0x00d8af, 0x00, 0x01);
354 if (ret < 0)
355 goto err;
356
357 usleep_range(10000, 50000);
358
359 ret = af9035_wr_reg_mask(d, 0x00d8af, 0x01, 0x01);
360 if (ret < 0)
361 goto err;
362
363 /* tell the slave I2C address */
364 ret = af9035_rd_reg(d, EEPROM_2ND_DEMOD_ADDR, &tmp);
365 if (ret < 0)
366 goto err;
367
368 ret = af9035_wr_reg(d, 0x00417f, tmp);
369 if (ret < 0)
370 goto err;
371
372 /* enable clock out */
373 ret = af9035_wr_reg_mask(d, 0x00d81a, 0x01, 0x01);
374 if (ret < 0)
375 goto err;
376 }
377
378 /*
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300379 * Thanks to Daniel Glöckner <daniel-gl@gmx.net> about that info!
380 *
381 * byte 0: MCS 51 core
382 * There are two inside the AF9035 (1=Link and 2=OFDM) with separate
383 * address spaces
384 * byte 1-2: Big endian destination address
385 * byte 3-4: Big endian number of data bytes following the header
386 * byte 5-6: Big endian header checksum, apparently ignored by the chip
387 * Calculated as ~(h[0]*256+h[1]+h[2]*256+h[3]+h[4]*256)
388 */
Antti Palosaari7f882c22012-03-30 09:10:08 -0300389
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300390 for (i = fw->size; i > HDR_SIZE;) {
391 hdr_core = fw->data[fw->size - i + 0];
392 hdr_addr = fw->data[fw->size - i + 1] << 8;
393 hdr_addr |= fw->data[fw->size - i + 2] << 0;
394 hdr_data_len = fw->data[fw->size - i + 3] << 8;
395 hdr_data_len |= fw->data[fw->size - i + 4] << 0;
396 hdr_checksum = fw->data[fw->size - i + 5] << 8;
397 hdr_checksum |= fw->data[fw->size - i + 6] << 0;
Antti Palosaari7f882c22012-03-30 09:10:08 -0300398
Antti Palosaari119f7a82012-09-12 20:23:53 -0300399 dev_dbg(&d->udev->dev, "%s: core=%d addr=%04x data_len=%d " \
400 "checksum=%04x\n", __func__, hdr_core, hdr_addr,
401 hdr_data_len, hdr_checksum);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300402
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300403 if (((hdr_core != 1) && (hdr_core != 2)) ||
404 (hdr_data_len > i)) {
Antti Palosaari119f7a82012-09-12 20:23:53 -0300405 dev_dbg(&d->udev->dev, "%s: bad firmware\n", __func__);
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300406 break;
Antti Palosaari7f882c22012-03-30 09:10:08 -0300407 }
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300408
409 /* download begin packet */
410 req.cmd = CMD_FW_DL_BEGIN;
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300411 ret = af9035_ctrl_msg(d, &req);
Antti Palosaari41d44a82012-04-01 11:06:23 -0300412 if (ret < 0)
413 goto err;
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300414
415 /* download firmware packet(s) */
416 for (j = HDR_SIZE + hdr_data_len; j > 0; j -= MAX_DATA) {
417 len = j;
418 if (len > MAX_DATA)
419 len = MAX_DATA;
420 req_fw_dl.wlen = len;
421 req_fw_dl.wbuf = (u8 *) &fw->data[fw->size - i +
422 HDR_SIZE + hdr_data_len - j];
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300423 ret = af9035_ctrl_msg(d, &req_fw_dl);
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300424 if (ret < 0)
425 goto err;
426 }
427
428 /* download end packet */
429 req.cmd = CMD_FW_DL_END;
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300430 ret = af9035_ctrl_msg(d, &req);
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300431 if (ret < 0)
432 goto err;
433
434 i -= hdr_data_len + HDR_SIZE;
435
Antti Palosaari119f7a82012-09-12 20:23:53 -0300436 dev_dbg(&d->udev->dev, "%s: data uploaded=%zu\n",
437 __func__, fw->size - i);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300438 }
439
Antti Palosaariff4e3fe2012-12-09 16:25:08 -0300440 /* print warn if firmware is bad, continue and see what happens */
441 if (i)
442 dev_warn(&d->udev->dev, "%s: bad firmware\n", KBUILD_MODNAME);
443
Antti Palosaari7f882c22012-03-30 09:10:08 -0300444 /* firmware loaded, request boot */
445 req.cmd = CMD_FW_BOOT;
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300446 ret = af9035_ctrl_msg(d, &req);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300447 if (ret < 0)
448 goto err;
449
450 /* ensure firmware starts */
451 wbuf[0] = 1;
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300452 ret = af9035_ctrl_msg(d, &req_fw_ver);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300453 if (ret < 0)
454 goto err;
455
Antti Palosaari7f882c22012-03-30 09:10:08 -0300456 if (!(rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3])) {
Antti Palosaari119f7a82012-09-12 20:23:53 -0300457 dev_err(&d->udev->dev, "%s: firmware did not run\n",
458 KBUILD_MODNAME);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300459 ret = -ENODEV;
460 goto err;
461 }
462
Antti Palosaari119f7a82012-09-12 20:23:53 -0300463 dev_info(&d->udev->dev, "%s: firmware version=%d.%d.%d.%d",
464 KBUILD_MODNAME, rbuf[0], rbuf[1], rbuf[2], rbuf[3]);
Antti Palosaari77c5ff22012-04-01 01:32:23 -0300465
Antti Palosaari7f882c22012-03-30 09:10:08 -0300466 return 0;
467
468err:
Antti Palosaari119f7a82012-09-12 20:23:53 -0300469 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300470
471 return ret;
472}
473
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300474static int af9035_download_firmware_it9135(struct dvb_usb_device *d,
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300475 const struct firmware *fw)
476{
477 int ret, i, i_prev;
478 u8 wbuf[1];
479 u8 rbuf[4];
480 struct usb_req req = { 0, 0, 0, NULL, 0, NULL };
481 struct usb_req req_fw_dl = { CMD_FW_SCATTER_WR, 0, 0, NULL, 0, NULL };
482 struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ;
483 #define HDR_SIZE 7
484
485 /*
486 * There seems to be following firmware header. Meaning of bytes 0-3
487 * is unknown.
488 *
489 * 0: 3
490 * 1: 0, 1
491 * 2: 0
492 * 3: 1, 2, 3
493 * 4: addr MSB
494 * 5: addr LSB
495 * 6: count of data bytes ?
496 */
497
498 for (i = HDR_SIZE, i_prev = 0; i <= fw->size; i++) {
499 if (i == fw->size ||
500 (fw->data[i + 0] == 0x03 &&
501 (fw->data[i + 1] == 0x00 ||
502 fw->data[i + 1] == 0x01) &&
503 fw->data[i + 2] == 0x00)) {
504 req_fw_dl.wlen = i - i_prev;
505 req_fw_dl.wbuf = (u8 *) &fw->data[i_prev];
506 i_prev = i;
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300507 ret = af9035_ctrl_msg(d, &req_fw_dl);
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300508 if (ret < 0)
509 goto err;
510
Antti Palosaari119f7a82012-09-12 20:23:53 -0300511 dev_dbg(&d->udev->dev, "%s: data uploaded=%d\n",
512 __func__, i);
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300513 }
514 }
515
516 /* firmware loaded, request boot */
517 req.cmd = CMD_FW_BOOT;
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300518 ret = af9035_ctrl_msg(d, &req);
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300519 if (ret < 0)
520 goto err;
521
522 /* ensure firmware starts */
523 wbuf[0] = 1;
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300524 ret = af9035_ctrl_msg(d, &req_fw_ver);
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300525 if (ret < 0)
526 goto err;
527
528 if (!(rbuf[0] || rbuf[1] || rbuf[2] || rbuf[3])) {
Antti Palosaari119f7a82012-09-12 20:23:53 -0300529 dev_err(&d->udev->dev, "%s: firmware did not run\n",
530 KBUILD_MODNAME);
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300531 ret = -ENODEV;
532 goto err;
533 }
534
Antti Palosaari119f7a82012-09-12 20:23:53 -0300535 dev_info(&d->udev->dev, "%s: firmware version=%d.%d.%d.%d",
536 KBUILD_MODNAME, rbuf[0], rbuf[1], rbuf[2], rbuf[3]);
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300537
538 return 0;
539
540err:
Antti Palosaari119f7a82012-09-12 20:23:53 -0300541 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300542
543 return ret;
544}
545
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300546static int af9035_read_config(struct dvb_usb_device *d)
Antti Palosaari7f882c22012-03-30 09:10:08 -0300547{
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300548 struct state *state = d_to_priv(d);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300549 int ret, i, eeprom_shift = 0;
550 u8 tmp;
551 u16 tmp16;
552
Antti Palosaaribf97b632012-12-08 22:51:19 -0300553 /* demod I2C "address" */
554 state->af9033_config[0].i2c_addr = 0x38;
555
Antti Palosaari7f882c22012-03-30 09:10:08 -0300556 /* check if there is dual tuners */
557 ret = af9035_rd_reg(d, EEPROM_DUAL_MODE, &tmp);
558 if (ret < 0)
559 goto err;
560
Antti Palosaari2a79eef2012-05-07 14:50:40 -0300561 state->dual_mode = tmp;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300562 dev_dbg(&d->udev->dev, "%s: dual mode=%d\n", __func__,
563 state->dual_mode);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300564
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300565 if (state->dual_mode) {
566 /* read 2nd demodulator I2C address */
Antti Palosaaribf97b632012-12-08 22:51:19 -0300567 ret = af9035_rd_reg(d, EEPROM_2ND_DEMOD_ADDR, &tmp);
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300568 if (ret < 0)
569 goto err;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300570
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300571 state->af9033_config[1].i2c_addr = tmp;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300572 dev_dbg(&d->udev->dev, "%s: 2nd demod I2C addr=%02x\n",
573 __func__, tmp);
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300574 }
575
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300576 for (i = 0; i < state->dual_mode + 1; i++) {
Antti Palosaari7f882c22012-03-30 09:10:08 -0300577 /* tuner */
578 ret = af9035_rd_reg(d, EEPROM_1_TUNER_ID + eeprom_shift, &tmp);
579 if (ret < 0)
580 goto err;
581
Antti Palosaari2a79eef2012-05-07 14:50:40 -0300582 state->af9033_config[i].tuner = tmp;
Antti Palosaari119f7a82012-09-12 20:23:53 -0300583 dev_dbg(&d->udev->dev, "%s: [%d]tuner=%02x\n",
584 __func__, i, tmp);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300585
586 switch (tmp) {
587 case AF9033_TUNER_TUA9001:
Michael Büschffc501f2012-04-02 12:18:36 -0300588 case AF9033_TUNER_FC0011:
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300589 case AF9033_TUNER_MXL5007T:
Gianluca Gennarice1fe372012-04-02 17:25:14 -0300590 case AF9033_TUNER_TDA18218:
Oliver Schinagld67ceb32012-09-20 14:57:17 -0300591 case AF9033_TUNER_FC2580:
Antti Palosaari7e0bc292012-12-02 20:12:29 -0300592 case AF9033_TUNER_FC0012:
Antti Palosaari2a79eef2012-05-07 14:50:40 -0300593 state->af9033_config[i].spec_inv = 1;
Antti Palosaari7f882c22012-03-30 09:10:08 -0300594 break;
595 default:
Antti Palosaari119f7a82012-09-12 20:23:53 -0300596 dev_warn(&d->udev->dev, "%s: tuner id=%02x not " \
597 "supported, please report!",
598 KBUILD_MODNAME, tmp);
Peter Senna Tschudinc2c1b412012-09-28 05:37:22 -0300599 }
Antti Palosaari7f882c22012-03-30 09:10:08 -0300600
Antti Palosaaribf97b632012-12-08 22:51:19 -0300601 /* disable dual mode if driver does not support it */
602 if (i == 1)
603 switch (tmp) {
Antti Palosaari0bb3d8a2012-12-09 12:01:41 -0300604 case AF9033_TUNER_FC0012:
605 break;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300606 default:
607 state->dual_mode = false;
608 dev_info(&d->udev->dev, "%s: driver does not " \
609 "support 2nd tuner and will " \
610 "disable it", KBUILD_MODNAME);
611 }
612
Antti Palosaari7f882c22012-03-30 09:10:08 -0300613 /* tuner IF frequency */
614 ret = af9035_rd_reg(d, EEPROM_1_IFFREQ_L + eeprom_shift, &tmp);
615 if (ret < 0)
616 goto err;
617
618 tmp16 = tmp;
619
620 ret = af9035_rd_reg(d, EEPROM_1_IFFREQ_H + eeprom_shift, &tmp);
621 if (ret < 0)
622 goto err;
623
624 tmp16 |= tmp << 8;
625
Antti Palosaari119f7a82012-09-12 20:23:53 -0300626 dev_dbg(&d->udev->dev, "%s: [%d]IF=%d\n", __func__, i, tmp16);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300627
628 eeprom_shift = 0x10; /* shift for the 2nd tuner params */
629 }
630
631 /* get demod clock */
632 ret = af9035_rd_reg(d, 0x00d800, &tmp);
633 if (ret < 0)
634 goto err;
635
636 tmp = (tmp >> 0) & 0x0f;
637
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300638 for (i = 0; i < ARRAY_SIZE(state->af9033_config); i++)
Antti Palosaari2a79eef2012-05-07 14:50:40 -0300639 state->af9033_config[i].clock = clock_lut[tmp];
Antti Palosaari7f882c22012-03-30 09:10:08 -0300640
641 return 0;
642
643err:
Antti Palosaari119f7a82012-09-12 20:23:53 -0300644 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300645
646 return ret;
647}
648
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300649static int af9035_read_config_it9135(struct dvb_usb_device *d)
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300650{
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300651 struct state *state = d_to_priv(d);
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300652 int ret, i;
653 u8 tmp;
654
Antti Palosaari2a79eef2012-05-07 14:50:40 -0300655 state->dual_mode = false;
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300656
657 /* get demod clock */
658 ret = af9035_rd_reg(d, 0x00d800, &tmp);
659 if (ret < 0)
660 goto err;
661
662 tmp = (tmp >> 0) & 0x0f;
663
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300664 for (i = 0; i < ARRAY_SIZE(state->af9033_config); i++)
Antti Palosaari2a79eef2012-05-07 14:50:40 -0300665 state->af9033_config[i].clock = clock_lut_it9135[tmp];
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300666
667 return 0;
668
669err:
Antti Palosaari119f7a82012-09-12 20:23:53 -0300670 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarif2b61d02012-04-05 20:28:51 -0300671
672 return ret;
673}
674
Antti Palosaari51639be2012-09-16 22:26:56 -0300675static int af9035_tua9001_tuner_callback(struct dvb_usb_device *d,
676 int cmd, int arg)
677{
678 int ret;
679 u8 val;
680
681 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
682
683 /*
684 * CEN always enabled by hardware wiring
685 * RESETN GPIOT3
686 * RXEN GPIOT2
687 */
688
689 switch (cmd) {
690 case TUA9001_CMD_RESETN:
691 if (arg)
692 val = 0x00;
693 else
694 val = 0x01;
695
696 ret = af9035_wr_reg_mask(d, 0x00d8e7, val, 0x01);
697 if (ret < 0)
698 goto err;
699 break;
700 case TUA9001_CMD_RXEN:
701 if (arg)
702 val = 0x01;
703 else
704 val = 0x00;
705
706 ret = af9035_wr_reg_mask(d, 0x00d8eb, val, 0x01);
707 if (ret < 0)
708 goto err;
709 break;
710 }
711
712 return 0;
713
714err:
715 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
716
717 return ret;
718}
719
720
Michael Büschffc501f2012-04-02 12:18:36 -0300721static int af9035_fc0011_tuner_callback(struct dvb_usb_device *d,
Antti Palosaaridaacd5b2012-04-05 21:52:21 -0300722 int cmd, int arg)
Michael Büschffc501f2012-04-02 12:18:36 -0300723{
Antti Palosaaridaacd5b2012-04-05 21:52:21 -0300724 int ret;
Michael Büschffc501f2012-04-02 12:18:36 -0300725
726 switch (cmd) {
727 case FC0011_FE_CALLBACK_POWER:
728 /* Tuner enable */
Antti Palosaaridaacd5b2012-04-05 21:52:21 -0300729 ret = af9035_wr_reg_mask(d, 0xd8eb, 1, 1);
730 if (ret < 0)
731 goto err;
732
733 ret = af9035_wr_reg_mask(d, 0xd8ec, 1, 1);
734 if (ret < 0)
735 goto err;
736
737 ret = af9035_wr_reg_mask(d, 0xd8ed, 1, 1);
738 if (ret < 0)
739 goto err;
740
Michael Büschffc501f2012-04-02 12:18:36 -0300741 /* LED */
Antti Palosaaridaacd5b2012-04-05 21:52:21 -0300742 ret = af9035_wr_reg_mask(d, 0xd8d0, 1, 1);
743 if (ret < 0)
744 goto err;
745
746 ret = af9035_wr_reg_mask(d, 0xd8d1, 1, 1);
747 if (ret < 0)
748 goto err;
749
Michael Büschde2bec52012-04-03 05:11:30 -0300750 usleep_range(10000, 50000);
Michael Büschffc501f2012-04-02 12:18:36 -0300751 break;
752 case FC0011_FE_CALLBACK_RESET:
Antti Palosaaridaacd5b2012-04-05 21:52:21 -0300753 ret = af9035_wr_reg(d, 0xd8e9, 1);
754 if (ret < 0)
755 goto err;
756
757 ret = af9035_wr_reg(d, 0xd8e8, 1);
758 if (ret < 0)
759 goto err;
760
761 ret = af9035_wr_reg(d, 0xd8e7, 1);
762 if (ret < 0)
763 goto err;
764
Michael Büschde2bec52012-04-03 05:11:30 -0300765 usleep_range(10000, 20000);
Antti Palosaaridaacd5b2012-04-05 21:52:21 -0300766
767 ret = af9035_wr_reg(d, 0xd8e7, 0);
768 if (ret < 0)
769 goto err;
770
Michael Büschde2bec52012-04-03 05:11:30 -0300771 usleep_range(10000, 20000);
Michael Büschffc501f2012-04-02 12:18:36 -0300772 break;
773 default:
Antti Palosaaridaacd5b2012-04-05 21:52:21 -0300774 ret = -EINVAL;
775 goto err;
Michael Büschffc501f2012-04-02 12:18:36 -0300776 }
777
778 return 0;
Antti Palosaaridaacd5b2012-04-05 21:52:21 -0300779
780err:
Antti Palosaari119f7a82012-09-12 20:23:53 -0300781 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaaridaacd5b2012-04-05 21:52:21 -0300782
783 return ret;
Michael Büschffc501f2012-04-02 12:18:36 -0300784}
785
786static int af9035_tuner_callback(struct dvb_usb_device *d, int cmd, int arg)
787{
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300788 struct state *state = d_to_priv(d);
Antti Palosaari2a79eef2012-05-07 14:50:40 -0300789
790 switch (state->af9033_config[0].tuner) {
Michael Büschffc501f2012-04-02 12:18:36 -0300791 case AF9033_TUNER_FC0011:
792 return af9035_fc0011_tuner_callback(d, cmd, arg);
Antti Palosaari51639be2012-09-16 22:26:56 -0300793 case AF9033_TUNER_TUA9001:
794 return af9035_tua9001_tuner_callback(d, cmd, arg);
Michael Büschffc501f2012-04-02 12:18:36 -0300795 default:
796 break;
797 }
798
Antti Palosaari1835af12012-09-11 22:27:06 -0300799 return 0;
Michael Büschffc501f2012-04-02 12:18:36 -0300800}
801
802static int af9035_frontend_callback(void *adapter_priv, int component,
803 int cmd, int arg)
804{
805 struct i2c_adapter *adap = adapter_priv;
806 struct dvb_usb_device *d = i2c_get_adapdata(adap);
807
Antti Palosaari1835af12012-09-11 22:27:06 -0300808 dev_dbg(&d->udev->dev, "%s: component=%d cmd=%d arg=%d\n",
809 __func__, component, cmd, arg);
810
Michael Büschffc501f2012-04-02 12:18:36 -0300811 switch (component) {
812 case DVB_FRONTEND_COMPONENT_TUNER:
813 return af9035_tuner_callback(d, cmd, arg);
814 default:
815 break;
816 }
817
Antti Palosaari1835af12012-09-11 22:27:06 -0300818 return 0;
Michael Büschffc501f2012-04-02 12:18:36 -0300819}
820
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300821static int af9035_get_adapter_count(struct dvb_usb_device *d)
822{
823 struct state *state = d_to_priv(d);
824 return state->dual_mode + 1;
825}
826
Antti Palosaari7f882c22012-03-30 09:10:08 -0300827static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
828{
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300829 struct state *state = adap_to_priv(adap);
830 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300831 int ret;
832
Antti Palosaari1cbabf92012-05-07 14:59:55 -0300833 if (!state->af9033_config[adap->id].tuner) {
834 /* unsupported tuner */
Antti Palosaari5a9abae2012-03-30 17:15:16 -0300835 ret = -ENODEV;
836 goto err;
837 }
838
Antti Palosaari7f882c22012-03-30 09:10:08 -0300839 if (adap->id == 0) {
Antti Palosaari2a79eef2012-05-07 14:50:40 -0300840 state->af9033_config[0].ts_mode = AF9033_TS_MODE_USB;
841 state->af9033_config[1].ts_mode = AF9033_TS_MODE_SERIAL;
842
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300843 ret = af9035_wr_reg(d, 0x00417f,
Antti Palosaari2a79eef2012-05-07 14:50:40 -0300844 state->af9033_config[1].i2c_addr);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300845 if (ret < 0)
846 goto err;
847
Antti Palosaaribf97b632012-12-08 22:51:19 -0300848 ret = af9035_wr_reg(d, 0x00d81a, state->dual_mode);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300849 if (ret < 0)
850 goto err;
851 }
852
853 /* attach demodulator */
Antti Palosaaribf97b632012-12-08 22:51:19 -0300854 adap->fe[0] = dvb_attach(af9033_attach, &state->af9033_config[adap->id],
855 &d->i2c_adap);
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300856 if (adap->fe[0] == NULL) {
Antti Palosaari7f882c22012-03-30 09:10:08 -0300857 ret = -ENODEV;
858 goto err;
859 }
Antti Palosaari852f0d92012-04-06 07:09:23 -0300860
861 /* disable I2C-gate */
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300862 adap->fe[0]->ops.i2c_gate_ctrl = NULL;
863 adap->fe[0]->callback = af9035_frontend_callback;
Antti Palosaari7f882c22012-03-30 09:10:08 -0300864
865 return 0;
866
867err:
Antti Palosaari119f7a82012-09-12 20:23:53 -0300868 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300869
870 return ret;
871}
872
873static struct tua9001_config af9035_tua9001_config = {
874 .i2c_addr = 0x60,
875};
876
Michael Büschffc501f2012-04-02 12:18:36 -0300877static const struct fc0011_config af9035_fc0011_config = {
878 .i2c_address = 0x60,
879};
880
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300881static struct mxl5007t_config af9035_mxl5007t_config[] = {
882 {
883 .xtal_freq_hz = MxL_XTAL_24_MHZ,
884 .if_freq_hz = MxL_IF_4_57_MHZ,
885 .invert_if = 0,
886 .loop_thru_enable = 0,
887 .clk_out_enable = 0,
888 .clk_out_amp = MxL_CLKOUT_AMP_0_94V,
889 }, {
890 .xtal_freq_hz = MxL_XTAL_24_MHZ,
891 .if_freq_hz = MxL_IF_4_57_MHZ,
892 .invert_if = 0,
893 .loop_thru_enable = 1,
894 .clk_out_enable = 1,
895 .clk_out_amp = MxL_CLKOUT_AMP_0_94V,
896 }
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300897};
898
Gianluca Gennarice1fe372012-04-02 17:25:14 -0300899static struct tda18218_config af9035_tda18218_config = {
900 .i2c_address = 0x60,
901 .i2c_wr_max = 21,
902};
903
Oliver Schinagld67ceb32012-09-20 14:57:17 -0300904static const struct fc2580_config af9035_fc2580_config = {
905 .i2c_addr = 0x56,
906 .clock = 16384000,
907};
908
Antti Palosaari0bb3d8a2012-12-09 12:01:41 -0300909static const struct fc0012_config af9035_fc0012_config[] = {
910 {
911 .i2c_address = 0x63,
912 .xtal_freq = FC_XTAL_36_MHZ,
Antti Palosaari3a984772012-12-09 12:33:04 -0300913 .dual_master = true,
Antti Palosaari0bb3d8a2012-12-09 12:01:41 -0300914 .loop_through = true,
915 .clock_out = true,
916 }, {
917 .i2c_address = 0x63 | 0x80, /* I2C bus select hack */
918 .xtal_freq = FC_XTAL_36_MHZ,
Antti Palosaari3a984772012-12-09 12:33:04 -0300919 .dual_master = true,
Antti Palosaari0bb3d8a2012-12-09 12:01:41 -0300920 }
Antti Palosaariad3a7582012-12-08 23:27:49 -0300921};
922
Antti Palosaari7f882c22012-03-30 09:10:08 -0300923static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
924{
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300925 struct state *state = adap_to_priv(adap);
926 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300927 int ret;
928 struct dvb_frontend *fe;
Antti Palosaari0bb3d8a2012-12-09 12:01:41 -0300929 struct i2c_msg msg[1];
Antti Palosaaribf97b632012-12-08 22:51:19 -0300930 u8 tuner_addr;
931 /*
932 * XXX: Hack used in that function: we abuse unused I2C address bit [7]
933 * to carry info about used I2C bus for dual tuner configuration.
934 */
Antti Palosaari7f882c22012-03-30 09:10:08 -0300935
Antti Palosaari2a79eef2012-05-07 14:50:40 -0300936 switch (state->af9033_config[adap->id].tuner) {
Antti Palosaari7f882c22012-03-30 09:10:08 -0300937 case AF9033_TUNER_TUA9001:
938 /* AF9035 gpiot3 = TUA9001 RESETN
939 AF9035 gpiot2 = TUA9001 RXEN */
940
941 /* configure gpiot2 and gpiot2 as output */
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300942 ret = af9035_wr_reg_mask(d, 0x00d8ec, 0x01, 0x01);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300943 if (ret < 0)
944 goto err;
945
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300946 ret = af9035_wr_reg_mask(d, 0x00d8ed, 0x01, 0x01);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300947 if (ret < 0)
948 goto err;
949
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300950 ret = af9035_wr_reg_mask(d, 0x00d8e8, 0x01, 0x01);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300951 if (ret < 0)
952 goto err;
953
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300954 ret = af9035_wr_reg_mask(d, 0x00d8e9, 0x01, 0x01);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300955 if (ret < 0)
956 goto err;
957
Antti Palosaari7f882c22012-03-30 09:10:08 -0300958 /* attach tuner */
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300959 fe = dvb_attach(tua9001_attach, adap->fe[0],
960 &d->i2c_adap, &af9035_tua9001_config);
Antti Palosaari7f882c22012-03-30 09:10:08 -0300961 break;
Michael Büschffc501f2012-04-02 12:18:36 -0300962 case AF9033_TUNER_FC0011:
Antti Palosaari5da2aec2012-06-17 23:15:03 -0300963 fe = dvb_attach(fc0011_attach, adap->fe[0],
964 &d->i2c_adap, &af9035_fc0011_config);
Michael Büschffc501f2012-04-02 12:18:36 -0300965 break;
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300966 case AF9033_TUNER_MXL5007T:
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300967 if (adap->id == 0) {
968 ret = af9035_wr_reg(d, 0x00d8e0, 1);
969 if (ret < 0)
970 goto err;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300971
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300972 ret = af9035_wr_reg(d, 0x00d8e1, 1);
973 if (ret < 0)
974 goto err;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300975
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300976 ret = af9035_wr_reg(d, 0x00d8df, 0);
977 if (ret < 0)
978 goto err;
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300979
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300980 msleep(30);
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300981
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300982 ret = af9035_wr_reg(d, 0x00d8df, 1);
983 if (ret < 0)
984 goto err;
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300985
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300986 msleep(300);
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -0300987
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300988 ret = af9035_wr_reg(d, 0x00d8c0, 1);
989 if (ret < 0)
990 goto err;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300991
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300992 ret = af9035_wr_reg(d, 0x00d8c1, 1);
993 if (ret < 0)
994 goto err;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300995
Jose Alberto Reguero98059922012-09-23 16:48:47 -0300996 ret = af9035_wr_reg(d, 0x00d8bf, 0);
997 if (ret < 0)
998 goto err;
Antti Palosaaribf97b632012-12-08 22:51:19 -0300999
Jose Alberto Reguero98059922012-09-23 16:48:47 -03001000 ret = af9035_wr_reg(d, 0x00d8b4, 1);
1001 if (ret < 0)
1002 goto err;
Antti Palosaaribf97b632012-12-08 22:51:19 -03001003
Jose Alberto Reguero98059922012-09-23 16:48:47 -03001004 ret = af9035_wr_reg(d, 0x00d8b5, 1);
1005 if (ret < 0)
1006 goto err;
Antti Palosaaribf97b632012-12-08 22:51:19 -03001007
Jose Alberto Reguero98059922012-09-23 16:48:47 -03001008 ret = af9035_wr_reg(d, 0x00d8b3, 1);
1009 if (ret < 0)
1010 goto err;
Antti Palosaaribf97b632012-12-08 22:51:19 -03001011
1012 tuner_addr = 0x60;
1013 } else {
1014 tuner_addr = 0x60 | 0x80; /* I2C bus hack */
Jose Alberto Reguero98059922012-09-23 16:48:47 -03001015 }
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -03001016
1017 /* attach tuner */
Antti Palosaaribf97b632012-12-08 22:51:19 -03001018 fe = dvb_attach(mxl5007t_attach, adap->fe[0], &d->i2c_adap,
1019 tuner_addr, &af9035_mxl5007t_config[adap->id]);
Hans-Frieder Vogt540fd4b2012-04-02 14:18:16 -03001020 break;
Gianluca Gennarice1fe372012-04-02 17:25:14 -03001021 case AF9033_TUNER_TDA18218:
1022 /* attach tuner */
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001023 fe = dvb_attach(tda18218_attach, adap->fe[0],
1024 &d->i2c_adap, &af9035_tda18218_config);
Gianluca Gennarice1fe372012-04-02 17:25:14 -03001025 break;
Oliver Schinagld67ceb32012-09-20 14:57:17 -03001026 case AF9033_TUNER_FC2580:
1027 /* Tuner enable using gpiot2_o, gpiot2_en and gpiot2_on */
1028 ret = af9035_wr_reg_mask(d, 0xd8eb, 0x01, 0x01);
1029 if (ret < 0)
1030 goto err;
1031
1032 ret = af9035_wr_reg_mask(d, 0xd8ec, 0x01, 0x01);
1033 if (ret < 0)
1034 goto err;
1035
1036 ret = af9035_wr_reg_mask(d, 0xd8ed, 0x01, 0x01);
1037 if (ret < 0)
1038 goto err;
1039
1040 usleep_range(10000, 50000);
1041 /* attach tuner */
1042 fe = dvb_attach(fc2580_attach, adap->fe[0],
1043 &d->i2c_adap, &af9035_fc2580_config);
1044 break;
Antti Palosaari7e0bc292012-12-02 20:12:29 -03001045 case AF9033_TUNER_FC0012:
1046 /*
1047 * AF9035 gpiot2 = FC0012 enable
1048 * XXX: there seems to be something on gpioh8 too, but on my
1049 * my test I didn't find any difference.
1050 */
1051
Antti Palosaari0bb3d8a2012-12-09 12:01:41 -03001052 if (adap->id == 0) {
1053 /* configure gpiot2 as output and high */
1054 ret = af9035_wr_reg_mask(d, 0xd8eb, 0x01, 0x01);
1055 if (ret < 0)
1056 goto err;
Antti Palosaari7e0bc292012-12-02 20:12:29 -03001057
Antti Palosaari0bb3d8a2012-12-09 12:01:41 -03001058 ret = af9035_wr_reg_mask(d, 0xd8ec, 0x01, 0x01);
1059 if (ret < 0)
1060 goto err;
Antti Palosaari7e0bc292012-12-02 20:12:29 -03001061
Antti Palosaari0bb3d8a2012-12-09 12:01:41 -03001062 ret = af9035_wr_reg_mask(d, 0xd8ed, 0x01, 0x01);
1063 if (ret < 0)
1064 goto err;
1065 } else {
1066 /*
1067 * FIXME: That belongs for the FC0012 driver.
1068 * Write 02 to FC0012 master tuner register 0d directly
1069 * in order to make slave tuner working.
1070 */
1071 msg[0].addr = 0x63;
1072 msg[0].flags = 0;
1073 msg[0].len = 2;
1074 msg[0].buf = "\x0d\x02";
1075 ret = i2c_transfer(&d->i2c_adap, msg, 1);
1076 if (ret < 0)
1077 goto err;
1078 }
Antti Palosaari7e0bc292012-12-02 20:12:29 -03001079
1080 usleep_range(10000, 50000);
1081
Antti Palosaariad3a7582012-12-08 23:27:49 -03001082 fe = dvb_attach(fc0012_attach, adap->fe[0], &d->i2c_adap,
Antti Palosaari0bb3d8a2012-12-09 12:01:41 -03001083 &af9035_fc0012_config[adap->id]);
Antti Palosaari7e0bc292012-12-02 20:12:29 -03001084 break;
Antti Palosaari7f882c22012-03-30 09:10:08 -03001085 default:
1086 fe = NULL;
1087 }
1088
1089 if (fe == NULL) {
1090 ret = -ENODEV;
1091 goto err;
1092 }
1093
1094 return 0;
1095
1096err:
Antti Palosaari119f7a82012-09-12 20:23:53 -03001097 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari7f882c22012-03-30 09:10:08 -03001098
1099 return ret;
1100}
1101
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001102static int af9035_init(struct dvb_usb_device *d)
Antti Palosaari7f882c22012-03-30 09:10:08 -03001103{
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001104 struct state *state = d_to_priv(d);
Antti Palosaari7f882c22012-03-30 09:10:08 -03001105 int ret, i;
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001106 u16 frame_size = 87 * 188 / 4;
1107 u8 packet_size = 512 / 4;
1108 struct reg_val_mask tab[] = {
1109 { 0x80f99d, 0x01, 0x01 },
1110 { 0x80f9a4, 0x01, 0x01 },
1111 { 0x00dd11, 0x00, 0x20 },
1112 { 0x00dd11, 0x00, 0x40 },
1113 { 0x00dd13, 0x00, 0x20 },
1114 { 0x00dd13, 0x00, 0x40 },
1115 { 0x00dd11, 0x20, 0x20 },
1116 { 0x00dd88, (frame_size >> 0) & 0xff, 0xff},
1117 { 0x00dd89, (frame_size >> 8) & 0xff, 0xff},
1118 { 0x00dd0c, packet_size, 0xff},
1119 { 0x00dd11, state->dual_mode << 6, 0x40 },
1120 { 0x00dd8a, (frame_size >> 0) & 0xff, 0xff},
1121 { 0x00dd8b, (frame_size >> 8) & 0xff, 0xff},
1122 { 0x00dd0d, packet_size, 0xff },
Jose Alberto Reguero98059922012-09-23 16:48:47 -03001123 { 0x80f9a3, state->dual_mode, 0x01 },
1124 { 0x80f9cd, state->dual_mode, 0x01 },
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001125 { 0x80f99d, 0x00, 0x01 },
1126 { 0x80f9a4, 0x00, 0x01 },
1127 };
Antti Palosaari7f882c22012-03-30 09:10:08 -03001128
Antti Palosaari119f7a82012-09-12 20:23:53 -03001129 dev_dbg(&d->udev->dev, "%s: USB speed=%d frame_size=%04x " \
1130 "packet_size=%02x\n", __func__,
1131 d->udev->speed, frame_size, packet_size);
Antti Palosaari7f882c22012-03-30 09:10:08 -03001132
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001133 /* init endpoints */
1134 for (i = 0; i < ARRAY_SIZE(tab); i++) {
1135 ret = af9035_wr_reg_mask(d, tab[i].reg, tab[i].val,
1136 tab[i].mask);
Antti Palosaari7f882c22012-03-30 09:10:08 -03001137 if (ret < 0)
1138 goto err;
1139 }
1140
1141 return 0;
1142
1143err:
Antti Palosaari119f7a82012-09-12 20:23:53 -03001144 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari7f882c22012-03-30 09:10:08 -03001145
1146 return ret;
1147}
1148
Antti Palosaari37b44a02013-01-04 15:21:26 -03001149#if IS_ENABLED(CONFIG_RC_CORE)
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001150static int af9035_rc_query(struct dvb_usb_device *d)
1151{
1152 unsigned int key;
1153 unsigned char b[4];
1154 int ret;
1155 struct usb_req req = { CMD_IR_GET, 0, 0, NULL, 4, b };
1156
1157 ret = af9035_ctrl_msg(d, &req);
1158 if (ret < 0)
1159 goto err;
1160
1161 if ((b[2] + b[3]) == 0xff) {
1162 if ((b[0] + b[1]) == 0xff) {
1163 /* NEC */
1164 key = b[0] << 8 | b[2];
1165 } else {
1166 /* ext. NEC */
1167 key = b[0] << 16 | b[1] << 8 | b[2];
1168 }
1169 } else {
1170 key = b[0] << 24 | b[1] << 16 | b[2] << 8 | b[3];
1171 }
1172
1173 rc_keydown(d->rc_dev, key, 0);
1174
1175err:
1176 /* ignore errors */
1177 return 0;
1178}
1179
1180static int af9035_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
1181{
1182 int ret;
1183 u8 tmp;
1184
1185 ret = af9035_rd_reg(d, EEPROM_IR_MODE, &tmp);
1186 if (ret < 0)
1187 goto err;
1188
Antti Palosaari119f7a82012-09-12 20:23:53 -03001189 dev_dbg(&d->udev->dev, "%s: ir_mode=%02x\n", __func__, tmp);
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001190
1191 /* don't activate rc if in HID mode or if not available */
1192 if (tmp == 5) {
1193 ret = af9035_rd_reg(d, EEPROM_IR_TYPE, &tmp);
1194 if (ret < 0)
1195 goto err;
1196
Antti Palosaari119f7a82012-09-12 20:23:53 -03001197 dev_dbg(&d->udev->dev, "%s: ir_type=%02x\n", __func__, tmp);
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001198
1199 switch (tmp) {
1200 case 0: /* NEC */
1201 default:
David Härdemanc003ab12012-10-11 19:11:54 -03001202 rc->allowed_protos = RC_BIT_NEC;
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001203 break;
1204 case 1: /* RC6 */
David Härdemanc003ab12012-10-11 19:11:54 -03001205 rc->allowed_protos = RC_BIT_RC6_MCE;
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001206 break;
1207 }
1208
1209 rc->query = af9035_rc_query;
1210 rc->interval = 500;
Antti Palosaaride73bee2012-07-05 19:57:07 -03001211
1212 /* load empty to enable rc */
1213 if (!rc->map_name)
1214 rc->map_name = RC_MAP_EMPTY;
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001215 }
1216
1217 return 0;
1218
1219err:
Antti Palosaari119f7a82012-09-12 20:23:53 -03001220 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001221
1222 return ret;
1223}
Antti Palosaarieed56702012-12-09 20:18:31 -03001224#else
1225 #define af9035_get_rc_config NULL
1226#endif
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001227
1228/* interface 0 is used by DVB-T receiver and
1229 interface 1 is for remote controller (HID) */
1230static const struct dvb_usb_device_properties af9035_props = {
1231 .driver_name = KBUILD_MODNAME,
1232 .owner = THIS_MODULE,
1233 .adapter_nr = adapter_nr,
1234 .size_of_priv = sizeof(struct state),
1235
1236 .generic_bulk_ctrl_endpoint = 0x02,
1237 .generic_bulk_ctrl_endpoint_response = 0x81,
1238
1239 .identify_state = af9035_identify_state,
Antti Palosaari4395e4b2012-09-12 12:19:06 -03001240 .firmware = AF9035_FIRMWARE_AF9035,
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001241 .download_firmware = af9035_download_firmware,
1242
1243 .i2c_algo = &af9035_i2c_algo,
1244 .read_config = af9035_read_config,
1245 .frontend_attach = af9035_frontend_attach,
1246 .tuner_attach = af9035_tuner_attach,
1247 .init = af9035_init,
1248 .get_rc_config = af9035_get_rc_config,
1249
Jose Alberto Reguero98059922012-09-23 16:48:47 -03001250 .get_adapter_count = af9035_get_adapter_count,
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001251 .adapter = {
1252 {
1253 .stream = DVB_USB_STREAM_BULK(0x84, 6, 87 * 188),
1254 }, {
1255 .stream = DVB_USB_STREAM_BULK(0x85, 6, 87 * 188),
1256 },
1257 },
1258};
1259
1260static const struct dvb_usb_device_properties it9135_props = {
1261 .driver_name = KBUILD_MODNAME,
1262 .owner = THIS_MODULE,
1263 .adapter_nr = adapter_nr,
1264 .size_of_priv = sizeof(struct state),
1265
1266 .generic_bulk_ctrl_endpoint = 0x02,
1267 .generic_bulk_ctrl_endpoint_response = 0x81,
1268
1269 .identify_state = af9035_identify_state,
Antti Palosaari4395e4b2012-09-12 12:19:06 -03001270 .firmware = AF9035_FIRMWARE_IT9135,
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001271 .download_firmware = af9035_download_firmware_it9135,
1272
1273 .i2c_algo = &af9035_i2c_algo,
1274 .read_config = af9035_read_config_it9135,
1275 .frontend_attach = af9035_frontend_attach,
1276 .tuner_attach = af9035_tuner_attach,
1277 .init = af9035_init,
1278 .get_rc_config = af9035_get_rc_config,
1279
1280 .num_adapters = 1,
1281 .adapter = {
1282 {
1283 .stream = DVB_USB_STREAM_BULK(0x84, 6, 87 * 188),
1284 }, {
1285 .stream = DVB_USB_STREAM_BULK(0x85, 6, 87 * 188),
1286 },
1287 },
1288};
1289
1290static const struct usb_device_id af9035_id_table[] = {
1291 { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_9035,
1292 &af9035_props, "Afatech AF9035 reference design", NULL) },
1293 { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1000,
1294 &af9035_props, "Afatech AF9035 reference design", NULL) },
1295 { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1001,
1296 &af9035_props, "Afatech AF9035 reference design", NULL) },
1297 { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1002,
1298 &af9035_props, "Afatech AF9035 reference design", NULL) },
1299 { DVB_USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9035_1003,
1300 &af9035_props, "Afatech AF9035 reference design", NULL) },
1301 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK,
1302 &af9035_props, "TerraTec Cinergy T Stick", NULL) },
1303 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835,
1304 &af9035_props, "AVerMedia AVerTV Volar HD/PRO (A835)", NULL) },
1305 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_B835,
1306 &af9035_props, "AVerMedia AVerTV Volar HD/PRO (A835)", NULL) },
1307 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_1867,
1308 &af9035_props, "AVerMedia HD Volar (A867)", NULL) },
1309 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A867,
1310 &af9035_props, "AVerMedia HD Volar (A867)", NULL) },
1311 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_TWINSTAR,
1312 &af9035_props, "AVerMedia Twinstar (A825)", NULL) },
Oliver Schinagld67ceb32012-09-20 14:57:17 -03001313 { DVB_USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3100MINI_PLUS,
1314 &af9035_props, "Asus U3100Mini Plus", NULL) },
Fabrizio Gazzatod9b75952013-02-17 18:25:34 -03001315 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00aa,
1316 &af9035_props, "TerraTec Cinergy T Stick (rev. 2)", NULL) },
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001317 { }
1318};
1319MODULE_DEVICE_TABLE(usb, af9035_id_table);
1320
Antti Palosaari7f882c22012-03-30 09:10:08 -03001321static struct usb_driver af9035_usb_driver = {
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001322 .name = KBUILD_MODNAME,
1323 .id_table = af9035_id_table,
1324 .probe = dvb_usbv2_probe,
1325 .disconnect = dvb_usbv2_disconnect,
1326 .suspend = dvb_usbv2_suspend,
1327 .resume = dvb_usbv2_resume,
Antti Palosaari04966aa2012-08-14 22:21:08 -03001328 .reset_resume = dvb_usbv2_reset_resume,
Antti Palosaari5da2aec2012-06-17 23:15:03 -03001329 .no_dynamic_id = 1,
1330 .soft_unbind = 1,
Antti Palosaari7f882c22012-03-30 09:10:08 -03001331};
1332
Gianluca Gennari48bf7e12012-04-02 17:25:17 -03001333module_usb_driver(af9035_usb_driver);
Antti Palosaari7f882c22012-03-30 09:10:08 -03001334
1335MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1336MODULE_DESCRIPTION("Afatech AF9035 driver");
1337MODULE_LICENSE("GPL");
Antti Palosaari4395e4b2012-09-12 12:19:06 -03001338MODULE_FIRMWARE(AF9035_FIRMWARE_AF9035);
1339MODULE_FIRMWARE(AF9035_FIRMWARE_IT9135);