blob: d9ee1a9c5cbefb95e031c993fffa24dff6aeb26a [file] [log] [blame]
Antti Palosaari831e0b72011-07-08 23:36:07 -03001/*
2 * Realtek RTL28xxU DVB USB driver
3 *
4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
5 * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
Thomas Mair5cf66312012-05-18 14:47:41 -03006 * Copyright (C) 2012 Thomas Mair <thomas.mair86@googlemail.com>
Antti Palosaari831e0b72011-07-08 23:36:07 -03007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#include "rtl28xxu.h"
24
25#include "rtl2830.h"
Thomas Mair5cf66312012-05-18 14:47:41 -030026#include "rtl2832.h"
Antti Palosaari80f189a2013-12-01 13:44:23 -030027#include "mn88472.h"
Antti Palosaari831e0b72011-07-08 23:36:07 -030028
29#include "qt1010.h"
30#include "mt2060.h"
31#include "mxl5005s.h"
Thomas Mair5cf66312012-05-18 14:47:41 -030032#include "fc0012.h"
33#include "fc0013.h"
Antti Palosaari542f6a52012-09-01 21:09:22 -030034#include "e4000.h"
Antti Palosaari384df492012-09-08 22:07:25 -030035#include "fc2580.h"
Antti Palosaari5be65722012-09-11 22:27:09 -030036#include "tua9001.h"
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -030037#include "r820t.h"
Antti Palosaari831e0b72011-07-08 23:36:07 -030038
Antti Palosaari1fd10f92014-04-09 12:42:35 -030039/*
40 * RTL2832_SDR module is in staging. That logic is added in order to avoid any
41 * hard dependency to drivers/staging/ directory as we want compile mainline
42 * driver even whole staging directory is missing.
43 */
44#include <media/v4l2-subdev.h>
45
46#if IS_ENABLED(CONFIG_DVB_RTL2832_SDR)
47struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe,
48 struct i2c_adapter *i2c, const struct rtl2832_config *cfg,
49 struct v4l2_subdev *sd);
50#else
51static inline struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe,
52 struct i2c_adapter *i2c, const struct rtl2832_config *cfg,
53 struct v4l2_subdev *sd)
54{
55 return NULL;
56}
57#endif
58
Antti Palosaaribeab1b52014-04-09 18:08:37 -030059#ifdef CONFIG_MEDIA_ATTACH
60#define dvb_attach_sdr(FUNCTION, ARGS...) ({ \
61 void *__r = NULL; \
62 typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
63 if (__a) { \
64 __r = (void *) __a(ARGS); \
65 if (__r == NULL) \
66 symbol_put(FUNCTION); \
67 } \
68 __r; \
69})
70
71#else
72#define dvb_attach_sdr(FUNCTION, ARGS...) ({ \
73 FUNCTION(ARGS); \
74})
75
76#endif
77
Antti Palosaari94b5fa62013-11-22 14:20:14 -030078static int rtl28xxu_disable_rc;
79module_param_named(disable_rc, rtl28xxu_disable_rc, int, 0644);
80MODULE_PARM_DESC(disable_rc, "disable RTL2832U remote controller");
Antti Palosaari831e0b72011-07-08 23:36:07 -030081DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
82
83static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
84{
85 int ret;
86 unsigned int pipe;
87 u8 requesttype;
88 u8 *buf;
89
90 buf = kmalloc(req->size, GFP_KERNEL);
91 if (!buf) {
92 ret = -ENOMEM;
93 goto err;
94 }
95
96 if (req->index & CMD_WR_FLAG) {
97 /* write */
98 memcpy(buf, req->data, req->size);
99 requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT);
100 pipe = usb_sndctrlpipe(d->udev, 0);
101 } else {
102 /* read */
103 requesttype = (USB_TYPE_VENDOR | USB_DIR_IN);
104 pipe = usb_rcvctrlpipe(d->udev, 0);
105 }
106
107 ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value,
Antti Palosaari9935eea2012-01-21 22:26:52 -0300108 req->index, buf, req->size, 1000);
Antti Palosaarid89b9362012-08-22 19:42:00 -0300109
110 dvb_usb_dbg_usb_control_msg(d->udev, 0, requesttype, req->value,
111 req->index, buf, req->size);
112
Antti Palosaari9935eea2012-01-21 22:26:52 -0300113 if (ret > 0)
114 ret = 0;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300115
Antti Palosaari831e0b72011-07-08 23:36:07 -0300116 /* read request, copy returned data to return buf */
117 if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
118 memcpy(req->data, buf, req->size);
119
120 kfree(buf);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300121
Antti Palosaari9935eea2012-01-21 22:26:52 -0300122 if (ret)
123 goto err;
124
125 return ret;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300126err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300127 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300128 return ret;
129}
130
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300131static int rtl28xx_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300132{
133 struct rtl28xxu_req req;
134
135 if (reg < 0x3000)
136 req.index = CMD_USB_WR;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300137 else if (reg < 0x4000)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300138 req.index = CMD_SYS_WR;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300139 else
140 req.index = CMD_IR_WR;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300141
142 req.value = reg;
143 req.size = len;
144 req.data = val;
145
146 return rtl28xxu_ctrl_msg(d, &req);
147}
148
149static int rtl2831_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
150{
151 struct rtl28xxu_req req;
152
153 if (reg < 0x3000)
154 req.index = CMD_USB_RD;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300155 else if (reg < 0x4000)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300156 req.index = CMD_SYS_RD;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300157 else
158 req.index = CMD_IR_RD;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300159
160 req.value = reg;
161 req.size = len;
162 req.data = val;
163
164 return rtl28xxu_ctrl_msg(d, &req);
165}
166
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300167static int rtl28xx_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300168{
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300169 return rtl28xx_wr_regs(d, reg, &val, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300170}
171
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300172static int rtl28xx_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300173{
174 return rtl2831_rd_regs(d, reg, val, 1);
175}
176
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300177static int rtl28xx_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
178 u8 mask)
179{
180 int ret;
181 u8 tmp;
182
183 /* no need for read if whole reg is written */
184 if (mask != 0xff) {
185 ret = rtl28xx_rd_reg(d, reg, &tmp);
186 if (ret)
187 return ret;
188
189 val &= mask;
190 tmp &= ~mask;
191 val |= tmp;
192 }
193
194 return rtl28xx_wr_reg(d, reg, val);
195}
196
Antti Palosaari831e0b72011-07-08 23:36:07 -0300197/* I2C */
198static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
199 int num)
200{
201 int ret;
202 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300203 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300204 struct rtl28xxu_req req;
205
206 /*
207 * It is not known which are real I2C bus xfer limits, but testing
208 * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes.
Antti Palosaari34ec2932011-08-04 20:21:16 -0300209 * TODO: find out RTL2832U lens
210 */
211
212 /*
213 * I2C adapter logic looks rather complicated due to fact it handles
214 * three different access methods. Those methods are;
215 * 1) integrated demod access
216 * 2) old I2C access
217 * 3) new I2C access
218 *
219 * Used method is selected in order 1, 2, 3. Method 3 can handle all
220 * requests but there is two reasons why not use it always;
221 * 1) It is most expensive, usually two USB messages are needed
222 * 2) At least RTL2831U does not support it
223 *
224 * Method 3 is needed in case of I2C write+read (typical register read)
225 * where write is more than one byte.
Antti Palosaari831e0b72011-07-08 23:36:07 -0300226 */
227
228 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
229 return -EAGAIN;
230
231 if (num == 2 && !(msg[0].flags & I2C_M_RD) &&
232 (msg[1].flags & I2C_M_RD)) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300233 if (msg[0].len > 24 || msg[1].len > 24) {
234 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300235 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300236 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300237 } else if (msg[0].addr == 0x10) {
238 /* method 1 - integrated demod */
239 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
240 req.index = CMD_DEMOD_RD | priv->page;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300241 req.size = msg[1].len;
242 req.data = &msg[1].buf[0];
243 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300244 } else if (msg[0].len < 2) {
245 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300246 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
247 req.index = CMD_I2C_RD;
248 req.size = msg[1].len;
249 req.data = &msg[1].buf[0];
250 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300251 } else {
252 /* method 3 - new I2C */
253 req.value = (msg[0].addr << 1);
254 req.index = CMD_I2C_DA_WR;
255 req.size = msg[0].len;
256 req.data = msg[0].buf;
257 ret = rtl28xxu_ctrl_msg(d, &req);
258 if (ret)
Antti Palosaari9935eea2012-01-21 22:26:52 -0300259 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300260
261 req.value = (msg[0].addr << 1);
262 req.index = CMD_I2C_DA_RD;
263 req.size = msg[1].len;
264 req.data = msg[1].buf;
265 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300266 }
267 } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
268 if (msg[0].len > 22) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300269 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300270 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300271 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300272 } else if (msg[0].addr == 0x10) {
273 /* method 1 - integrated demod */
274 if (msg[0].buf[0] == 0x00) {
275 /* save demod page for later demod access */
276 priv->page = msg[0].buf[1];
277 ret = 0;
278 } else {
279 req.value = (msg[0].buf[0] << 8) |
280 (msg[0].addr << 1);
281 req.index = CMD_DEMOD_WR | priv->page;
282 req.size = msg[0].len-1;
283 req.data = &msg[0].buf[1];
284 ret = rtl28xxu_ctrl_msg(d, &req);
285 }
286 } else if (msg[0].len < 23) {
287 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300288 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
289 req.index = CMD_I2C_WR;
290 req.size = msg[0].len-1;
291 req.data = &msg[0].buf[1];
292 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300293 } else {
294 /* method 3 - new I2C */
295 req.value = (msg[0].addr << 1);
296 req.index = CMD_I2C_DA_WR;
297 req.size = msg[0].len;
298 req.data = msg[0].buf;
299 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300300 }
301 } else {
302 ret = -EINVAL;
303 }
304
Antti Palosaari9935eea2012-01-21 22:26:52 -0300305err_mutex_unlock:
Antti Palosaari831e0b72011-07-08 23:36:07 -0300306 mutex_unlock(&d->i2c_mutex);
307
308 return ret ? ret : num;
309}
310
311static u32 rtl28xxu_i2c_func(struct i2c_adapter *adapter)
312{
313 return I2C_FUNC_I2C;
314}
315
316static struct i2c_algorithm rtl28xxu_i2c_algo = {
317 .master_xfer = rtl28xxu_i2c_xfer,
318 .functionality = rtl28xxu_i2c_func,
319};
320
Antti Palosaari81347f52012-09-17 16:50:36 -0300321static int rtl2831u_read_config(struct dvb_usb_device *d)
322{
323 struct rtl28xxu_priv *priv = d_to_priv(d);
324 int ret;
325 u8 buf[1];
326 /* open RTL2831U/RTL2830 I2C gate */
327 struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x08"};
328 /* tuner probes */
329 struct rtl28xxu_req req_mt2060 = {0x00c0, CMD_I2C_RD, 1, buf};
330 struct rtl28xxu_req req_qt1010 = {0x0fc4, CMD_I2C_RD, 1, buf};
331
332 dev_dbg(&d->udev->dev, "%s:\n", __func__);
333
334 /*
335 * RTL2831U GPIOs
336 * =========================================================
337 * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?)
338 * GPIO2 | LED | 0 off | 1 on |
339 * GPIO4 | tuner#1 | 0 on | 1 off | MT2060
340 */
341
342 /* GPIO direction */
343 ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, 0x0a);
344 if (ret)
345 goto err;
346
347 /* enable as output GPIO0, GPIO2, GPIO4 */
348 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, 0x15);
349 if (ret)
350 goto err;
351
352 /*
353 * Probe used tuner. We need to know used tuner before demod attach
354 * since there is some demod params needed to set according to tuner.
355 */
356
357 /* demod needs some time to wake up */
358 msleep(20);
359
360 priv->tuner_name = "NONE";
361
362 /* open demod I2C gate */
363 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
364 if (ret)
365 goto err;
366
367 /* check QT1010 ID(?) register; reg=0f val=2c */
368 ret = rtl28xxu_ctrl_msg(d, &req_qt1010);
369 if (ret == 0 && buf[0] == 0x2c) {
370 priv->tuner = TUNER_RTL2830_QT1010;
371 priv->tuner_name = "QT1010";
372 goto found;
373 }
374
375 /* open demod I2C gate */
376 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
377 if (ret)
378 goto err;
379
380 /* check MT2060 ID register; reg=00 val=63 */
381 ret = rtl28xxu_ctrl_msg(d, &req_mt2060);
382 if (ret == 0 && buf[0] == 0x63) {
383 priv->tuner = TUNER_RTL2830_MT2060;
384 priv->tuner_name = "MT2060";
385 goto found;
386 }
387
388 /* assume MXL5005S */
389 priv->tuner = TUNER_RTL2830_MXL5005S;
390 priv->tuner_name = "MXL5005S";
391 goto found;
392
393found:
394 dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name);
395
396 return 0;
397err:
398 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
399 return ret;
400}
401
Antti Palosaarief37be12012-09-17 14:01:35 -0300402static int rtl2832u_read_config(struct dvb_usb_device *d)
403{
404 struct rtl28xxu_priv *priv = d_to_priv(d);
405 int ret;
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300406 u8 buf[2];
Antti Palosaarief37be12012-09-17 14:01:35 -0300407 /* open RTL2832U/RTL2832 I2C gate */
408 struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"};
409 /* close RTL2832U/RTL2832 I2C gate */
410 struct rtl28xxu_req req_gate_close = {0x0120, 0x0011, 0x0001, "\x10"};
411 /* tuner probes */
412 struct rtl28xxu_req req_fc0012 = {0x00c6, CMD_I2C_RD, 1, buf};
413 struct rtl28xxu_req req_fc0013 = {0x00c6, CMD_I2C_RD, 1, buf};
414 struct rtl28xxu_req req_mt2266 = {0x00c0, CMD_I2C_RD, 1, buf};
415 struct rtl28xxu_req req_fc2580 = {0x01ac, CMD_I2C_RD, 1, buf};
416 struct rtl28xxu_req req_mt2063 = {0x00c0, CMD_I2C_RD, 1, buf};
417 struct rtl28xxu_req req_max3543 = {0x00c0, CMD_I2C_RD, 1, buf};
418 struct rtl28xxu_req req_tua9001 = {0x7ec0, CMD_I2C_RD, 2, buf};
419 struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf};
420 struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
421 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
Gianluca Gennaria908eb92013-06-02 17:24:24 -0300422 struct rtl28xxu_req req_r820t = {0x0034, CMD_I2C_RD, 1, buf};
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300423 struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf};
Antti Palosaari80f189a2013-12-01 13:44:23 -0300424 struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf};
Antti Palosaarief37be12012-09-17 14:01:35 -0300425
426 dev_dbg(&d->udev->dev, "%s:\n", __func__);
427
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300428 /* enable GPIO3 and GPIO6 as output */
429 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x40);
Antti Palosaarief37be12012-09-17 14:01:35 -0300430 if (ret)
431 goto err;
432
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300433 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x48, 0x48);
Antti Palosaarief37be12012-09-17 14:01:35 -0300434 if (ret)
435 goto err;
436
437 /*
438 * Probe used tuner. We need to know used tuner before demod attach
439 * since there is some demod params needed to set according to tuner.
440 */
441
442 /* open demod I2C gate */
443 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
444 if (ret)
445 goto err;
446
447 priv->tuner_name = "NONE";
448
449 /* check FC0012 ID register; reg=00 val=a1 */
450 ret = rtl28xxu_ctrl_msg(d, &req_fc0012);
451 if (ret == 0 && buf[0] == 0xa1) {
452 priv->tuner = TUNER_RTL2832_FC0012;
453 priv->tuner_name = "FC0012";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300454 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300455 }
456
457 /* check FC0013 ID register; reg=00 val=a3 */
458 ret = rtl28xxu_ctrl_msg(d, &req_fc0013);
459 if (ret == 0 && buf[0] == 0xa3) {
460 priv->tuner = TUNER_RTL2832_FC0013;
461 priv->tuner_name = "FC0013";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300462 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300463 }
464
465 /* check MT2266 ID register; reg=00 val=85 */
466 ret = rtl28xxu_ctrl_msg(d, &req_mt2266);
467 if (ret == 0 && buf[0] == 0x85) {
468 priv->tuner = TUNER_RTL2832_MT2266;
469 priv->tuner_name = "MT2266";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300470 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300471 }
472
473 /* check FC2580 ID register; reg=01 val=56 */
474 ret = rtl28xxu_ctrl_msg(d, &req_fc2580);
475 if (ret == 0 && buf[0] == 0x56) {
476 priv->tuner = TUNER_RTL2832_FC2580;
477 priv->tuner_name = "FC2580";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300478 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300479 }
480
481 /* check MT2063 ID register; reg=00 val=9e || 9c */
482 ret = rtl28xxu_ctrl_msg(d, &req_mt2063);
483 if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) {
484 priv->tuner = TUNER_RTL2832_MT2063;
485 priv->tuner_name = "MT2063";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300486 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300487 }
488
489 /* check MAX3543 ID register; reg=00 val=38 */
490 ret = rtl28xxu_ctrl_msg(d, &req_max3543);
491 if (ret == 0 && buf[0] == 0x38) {
492 priv->tuner = TUNER_RTL2832_MAX3543;
493 priv->tuner_name = "MAX3543";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300494 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300495 }
496
497 /* check TUA9001 ID register; reg=7e val=2328 */
498 ret = rtl28xxu_ctrl_msg(d, &req_tua9001);
499 if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) {
500 priv->tuner = TUNER_RTL2832_TUA9001;
501 priv->tuner_name = "TUA9001";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300502 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300503 }
504
505 /* check MXL5007R ID register; reg=d9 val=14 */
506 ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t);
507 if (ret == 0 && buf[0] == 0x14) {
508 priv->tuner = TUNER_RTL2832_MXL5007T;
509 priv->tuner_name = "MXL5007T";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300510 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300511 }
512
513 /* check E4000 ID register; reg=02 val=40 */
514 ret = rtl28xxu_ctrl_msg(d, &req_e4000);
515 if (ret == 0 && buf[0] == 0x40) {
516 priv->tuner = TUNER_RTL2832_E4000;
517 priv->tuner_name = "E4000";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300518 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300519 }
520
521 /* check TDA18272 ID register; reg=00 val=c760 */
522 ret = rtl28xxu_ctrl_msg(d, &req_tda18272);
523 if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) {
524 priv->tuner = TUNER_RTL2832_TDA18272;
525 priv->tuner_name = "TDA18272";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300526 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300527 }
528
Gianluca Gennaria908eb92013-06-02 17:24:24 -0300529 /* check R820T ID register; reg=00 val=69 */
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300530 ret = rtl28xxu_ctrl_msg(d, &req_r820t);
Gianluca Gennaria908eb92013-06-02 17:24:24 -0300531 if (ret == 0 && buf[0] == 0x69) {
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300532 priv->tuner = TUNER_RTL2832_R820T;
533 priv->tuner_name = "R820T";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300534 goto tuner_found;
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300535 }
536
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300537 /* check R828D ID register; reg=00 val=69 */
538 ret = rtl28xxu_ctrl_msg(d, &req_r828d);
539 if (ret == 0 && buf[0] == 0x69) {
540 priv->tuner = TUNER_RTL2832_R828D;
541 priv->tuner_name = "R828D";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300542 goto tuner_found;
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300543 }
544
Antti Palosaari80f189a2013-12-01 13:44:23 -0300545tuner_found:
Antti Palosaarief37be12012-09-17 14:01:35 -0300546 dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name);
547
Antti Palosaari80f189a2013-12-01 13:44:23 -0300548 /* probe slave demod */
549 if (priv->tuner == TUNER_RTL2832_R828D) {
550 /* power on MN88472 demod on GPIO0 */
551 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x01, 0x01);
552 if (ret)
553 goto err;
554
555 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x01);
556 if (ret)
557 goto err;
558
559 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x01, 0x01);
560 if (ret)
561 goto err;
562
563 /* check MN88472 answers */
564 ret = rtl28xxu_ctrl_msg(d, &req_mn88472);
565 if (ret == 0 && buf[0] == 0x02) {
566 dev_dbg(&d->udev->dev, "%s: MN88472 found\n", __func__);
567 priv->slave_demod = SLAVE_DEMOD_MN88472;
568 goto demod_found;
569 }
570 }
571
572demod_found:
Antti Palosaarief37be12012-09-17 14:01:35 -0300573 /* close demod I2C gate */
574 ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
575 if (ret < 0)
576 goto err;
577
578 return 0;
579err:
580 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
581 return ret;
582}
583
Antti Palosaarie8b46682013-10-12 23:35:35 -0300584static const struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = {
Antti Palosaari831e0b72011-07-08 23:36:07 -0300585 .i2c_addr = 0x10, /* 0x20 */
586 .xtal = 28800000,
587 .ts_mode = 0,
588 .spec_inv = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300589 .vtop = 0x20,
590 .krf = 0x04,
591 .agc_targ_val = 0x2d,
592
593};
594
Antti Palosaarie8b46682013-10-12 23:35:35 -0300595static const struct rtl2830_config rtl28xxu_rtl2830_qt1010_config = {
Antti Palosaari831e0b72011-07-08 23:36:07 -0300596 .i2c_addr = 0x10, /* 0x20 */
597 .xtal = 28800000,
598 .ts_mode = 0,
599 .spec_inv = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300600 .vtop = 0x20,
601 .krf = 0x04,
602 .agc_targ_val = 0x2d,
603};
604
Antti Palosaarie8b46682013-10-12 23:35:35 -0300605static const struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = {
Antti Palosaari831e0b72011-07-08 23:36:07 -0300606 .i2c_addr = 0x10, /* 0x20 */
607 .xtal = 28800000,
608 .ts_mode = 0,
609 .spec_inv = 0,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300610 .vtop = 0x3f,
611 .krf = 0x04,
612 .agc_targ_val = 0x3e,
613};
614
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300615static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300616{
Antti Palosaaric01a3592012-08-12 22:27:07 -0300617 struct dvb_usb_device *d = adap_to_d(adap);
618 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaarie8b46682013-10-12 23:35:35 -0300619 const struct rtl2830_config *rtl2830_config;
Antti Palosaari81347f52012-09-17 16:50:36 -0300620 int ret;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300621
Antti Palosaaric01a3592012-08-12 22:27:07 -0300622 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300623
Antti Palosaari81347f52012-09-17 16:50:36 -0300624 switch (priv->tuner) {
625 case TUNER_RTL2830_QT1010:
Antti Palosaari831e0b72011-07-08 23:36:07 -0300626 rtl2830_config = &rtl28xxu_rtl2830_qt1010_config;
Antti Palosaari81347f52012-09-17 16:50:36 -0300627 break;
628 case TUNER_RTL2830_MT2060:
Antti Palosaari831e0b72011-07-08 23:36:07 -0300629 rtl2830_config = &rtl28xxu_rtl2830_mt2060_config;
Antti Palosaari81347f52012-09-17 16:50:36 -0300630 break;
631 case TUNER_RTL2830_MXL5005S:
632 rtl2830_config = &rtl28xxu_rtl2830_mxl5005s_config;
633 break;
634 default:
635 dev_err(&d->udev->dev, "%s: unknown tuner=%s\n",
636 KBUILD_MODNAME, priv->tuner_name);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300637 ret = -ENODEV;
638 goto err;
639 }
640
Antti Palosaari81347f52012-09-17 16:50:36 -0300641 /* attach demodulator */
642 adap->fe[0] = dvb_attach(rtl2830_attach, rtl2830_config, &d->i2c_adap);
643 if (!adap->fe[0]) {
644 ret = -ENODEV;
645 goto err;
646 }
647
648 return 0;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300649err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300650 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300651 return ret;
652}
653
Antti Palosaarie8b46682013-10-12 23:35:35 -0300654static const struct rtl2832_config rtl28xxu_rtl2832_fc0012_config = {
Thomas Mair5cf66312012-05-18 14:47:41 -0300655 .i2c_addr = 0x10, /* 0x20 */
656 .xtal = 28800000,
Thomas Mair5cf66312012-05-18 14:47:41 -0300657 .tuner = TUNER_RTL2832_FC0012
658};
659
Antti Palosaarie8b46682013-10-12 23:35:35 -0300660static const struct rtl2832_config rtl28xxu_rtl2832_fc0013_config = {
Thomas Mair5cf66312012-05-18 14:47:41 -0300661 .i2c_addr = 0x10, /* 0x20 */
662 .xtal = 28800000,
Thomas Mair5cf66312012-05-18 14:47:41 -0300663 .tuner = TUNER_RTL2832_FC0013
664};
665
Antti Palosaarie8b46682013-10-12 23:35:35 -0300666static const struct rtl2832_config rtl28xxu_rtl2832_tua9001_config = {
Antti Palosaari5be65722012-09-11 22:27:09 -0300667 .i2c_addr = 0x10, /* 0x20 */
668 .xtal = 28800000,
669 .tuner = TUNER_RTL2832_TUA9001,
670};
671
Antti Palosaarie8b46682013-10-12 23:35:35 -0300672static const struct rtl2832_config rtl28xxu_rtl2832_e4000_config = {
Antti Palosaari3d8a60d2012-09-17 17:54:27 -0300673 .i2c_addr = 0x10, /* 0x20 */
674 .xtal = 28800000,
675 .tuner = TUNER_RTL2832_E4000,
676};
677
Antti Palosaarie8b46682013-10-12 23:35:35 -0300678static const struct rtl2832_config rtl28xxu_rtl2832_r820t_config = {
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300679 .i2c_addr = 0x10,
680 .xtal = 28800000,
681 .tuner = TUNER_RTL2832_R820T,
682};
683
Thomas Mair5cf66312012-05-18 14:47:41 -0300684static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
685 int cmd, int arg)
686{
687 int ret;
688 u8 val;
689
Antti Palosaaric01a3592012-08-12 22:27:07 -0300690 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
691
Thomas Mair5cf66312012-05-18 14:47:41 -0300692 switch (cmd) {
693 case FC_FE_CALLBACK_VHF_ENABLE:
694 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300695 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300696 if (ret)
697 goto err;
698
699 if (arg)
700 val &= 0xbf; /* set GPIO6 low */
701 else
702 val |= 0x40; /* set GPIO6 high */
703
704
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300705 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300706 if (ret)
707 goto err;
708 break;
709 default:
710 ret = -EINVAL;
711 goto err;
712 }
713 return 0;
Thomas Mair5cf66312012-05-18 14:47:41 -0300714err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300715 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -0300716 return ret;
717}
718
Antti Palosaari5be65722012-09-11 22:27:09 -0300719static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d,
720 int cmd, int arg)
721{
722 int ret;
723 u8 val;
724
725 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
726
727 /*
728 * CEN always enabled by hardware wiring
729 * RESETN GPIO4
730 * RXEN GPIO1
731 */
732
Antti Palosaari5be65722012-09-11 22:27:09 -0300733 switch (cmd) {
734 case TUA9001_CMD_RESETN:
735 if (arg)
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300736 val = (1 << 4);
Antti Palosaari5be65722012-09-11 22:27:09 -0300737 else
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300738 val = (0 << 4);
Antti Palosaari5be65722012-09-11 22:27:09 -0300739
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300740 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x10);
741 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300742 goto err;
743 break;
744 case TUA9001_CMD_RXEN:
745 if (arg)
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300746 val = (1 << 1);
Antti Palosaari5be65722012-09-11 22:27:09 -0300747 else
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300748 val = (0 << 1);
Antti Palosaari5be65722012-09-11 22:27:09 -0300749
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300750 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x02);
751 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300752 goto err;
753 break;
754 }
755
756 return 0;
Antti Palosaari5be65722012-09-11 22:27:09 -0300757err:
758 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
759 return ret;
760}
761
Thomas Mair5cf66312012-05-18 14:47:41 -0300762static int rtl2832u_tuner_callback(struct dvb_usb_device *d, int cmd, int arg)
763{
764 struct rtl28xxu_priv *priv = d->priv;
765
766 switch (priv->tuner) {
767 case TUNER_RTL2832_FC0012:
768 return rtl2832u_fc0012_tuner_callback(d, cmd, arg);
Antti Palosaari5be65722012-09-11 22:27:09 -0300769 case TUNER_RTL2832_TUA9001:
770 return rtl2832u_tua9001_tuner_callback(d, cmd, arg);
Thomas Mair5cf66312012-05-18 14:47:41 -0300771 default:
772 break;
773 }
774
Antti Palosaari97efe782012-09-17 15:49:54 -0300775 return 0;
Thomas Mair5cf66312012-05-18 14:47:41 -0300776}
777
778static int rtl2832u_frontend_callback(void *adapter_priv, int component,
Antti Palosaari8acc91c2012-09-17 16:55:39 -0300779 int cmd, int arg)
Thomas Mair5cf66312012-05-18 14:47:41 -0300780{
781 struct i2c_adapter *adap = adapter_priv;
782 struct dvb_usb_device *d = i2c_get_adapdata(adap);
783
Antti Palosaari8acc91c2012-09-17 16:55:39 -0300784 dev_dbg(&d->udev->dev, "%s: component=%d cmd=%d arg=%d\n",
785 __func__, component, cmd, arg);
786
Thomas Mair5cf66312012-05-18 14:47:41 -0300787 switch (component) {
788 case DVB_FRONTEND_COMPONENT_TUNER:
789 return rtl2832u_tuner_callback(d, cmd, arg);
790 default:
791 break;
792 }
793
Antti Palosaari97efe782012-09-17 15:49:54 -0300794 return 0;
Thomas Mair5cf66312012-05-18 14:47:41 -0300795}
796
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300797static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
798{
799 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300800 struct dvb_usb_device *d = adap_to_d(adap);
801 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaarie8b46682013-10-12 23:35:35 -0300802 const struct rtl2832_config *rtl2832_config;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300803
Antti Palosaaric01a3592012-08-12 22:27:07 -0300804 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300805
Antti Palosaarief37be12012-09-17 14:01:35 -0300806 switch (priv->tuner) {
807 case TUNER_RTL2832_FC0012:
Thomas Mair5cf66312012-05-18 14:47:41 -0300808 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300809 break;
810 case TUNER_RTL2832_FC0013:
Thomas Mair5cf66312012-05-18 14:47:41 -0300811 rtl2832_config = &rtl28xxu_rtl2832_fc0013_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300812 break;
813 case TUNER_RTL2832_FC2580:
Antti Palosaari384df492012-09-08 22:07:25 -0300814 /* FIXME: do not abuse fc0012 settings */
815 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300816 break;
817 case TUNER_RTL2832_TUA9001:
Antti Palosaari5be65722012-09-11 22:27:09 -0300818 rtl2832_config = &rtl28xxu_rtl2832_tua9001_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300819 break;
820 case TUNER_RTL2832_E4000:
Antti Palosaari3d8a60d2012-09-17 17:54:27 -0300821 rtl2832_config = &rtl28xxu_rtl2832_e4000_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300822 break;
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300823 case TUNER_RTL2832_R820T:
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300824 case TUNER_RTL2832_R828D:
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300825 rtl2832_config = &rtl28xxu_rtl2832_r820t_config;
826 break;
Antti Palosaarief37be12012-09-17 14:01:35 -0300827 default:
828 dev_err(&d->udev->dev, "%s: unknown tuner=%s\n",
829 KBUILD_MODNAME, priv->tuner_name);
830 ret = -ENODEV;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300831 goto err;
Antti Palosaarief37be12012-09-17 14:01:35 -0300832 }
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300833
834 /* attach demodulator */
Antti Palosaarief37be12012-09-17 14:01:35 -0300835 adap->fe[0] = dvb_attach(rtl2832_attach, rtl2832_config, &d->i2c_adap);
836 if (!adap->fe[0]) {
837 ret = -ENODEV;
838 goto err;
839 }
Thomas Mair5cf66312012-05-18 14:47:41 -0300840
Antti Palosaariae1f8452014-02-08 04:03:57 -0300841 /* RTL2832 I2C repeater */
842 priv->demod_i2c_adapter = rtl2832_get_i2c_adapter(adap->fe[0]);
843
Antti Palosaarief37be12012-09-17 14:01:35 -0300844 /* set fe callback */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300845 adap->fe[0]->callback = rtl2832u_frontend_callback;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300846
Antti Palosaari80f189a2013-12-01 13:44:23 -0300847 if (priv->slave_demod) {
848 struct i2c_board_info info = {};
849 struct i2c_client *client;
850
851 /*
852 * We continue on reduced mode, without DVB-T2/C, using master
853 * demod, when slave demod fails.
854 */
855 ret = 0;
856
857 /* attach slave demodulator */
858 if (priv->slave_demod == SLAVE_DEMOD_MN88472) {
859 struct mn88472_config mn88472_config = {};
860
861 mn88472_config.fe = &adap->fe[1];
862 mn88472_config.i2c_wr_max = 22,
863 strlcpy(info.type, "mn88472", I2C_NAME_SIZE);
864 info.addr = 0x18;
865 info.platform_data = &mn88472_config;
866 request_module(info.type);
867 client = i2c_new_device(priv->demod_i2c_adapter, &info);
868 if (client == NULL || client->dev.driver == NULL) {
869 priv->slave_demod = SLAVE_DEMOD_NONE;
870 goto err_slave_demod_failed;
871 }
872
873 if (!try_module_get(client->dev.driver->owner)) {
874 i2c_unregister_device(client);
875 priv->slave_demod = SLAVE_DEMOD_NONE;
876 goto err_slave_demod_failed;
877 }
878
879 priv->i2c_client_slave_demod = client;
880 }
881 }
882
Antti Palosaarief37be12012-09-17 14:01:35 -0300883 return 0;
Antti Palosaari80f189a2013-12-01 13:44:23 -0300884err_slave_demod_failed:
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300885err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300886 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300887 return ret;
888}
889
Antti Palosaari831e0b72011-07-08 23:36:07 -0300890static struct qt1010_config rtl28xxu_qt1010_config = {
891 .i2c_address = 0x62, /* 0xc4 */
892};
893
894static struct mt2060_config rtl28xxu_mt2060_config = {
895 .i2c_address = 0x60, /* 0xc0 */
896 .clock_out = 0,
897};
898
899static struct mxl5005s_config rtl28xxu_mxl5005s_config = {
900 .i2c_address = 0x63, /* 0xc6 */
901 .if_freq = IF_FREQ_4570000HZ,
902 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
903 .agc_mode = MXL_SINGLE_AGC,
904 .tracking_filter = MXL_TF_C_H,
905 .rssi_enable = MXL_RSSI_ENABLE,
906 .cap_select = MXL_CAP_SEL_ENABLE,
907 .div_out = MXL_DIV_OUT_4,
908 .clock_out = MXL_CLOCK_OUT_DISABLE,
909 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
910 .top = MXL5005S_TOP_25P2,
911 .mod_mode = MXL_DIGITAL_MODE,
912 .if_mode = MXL_ZERO_IF,
913 .AgcMasterByte = 0x00,
914};
915
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300916static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300917{
918 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300919 struct dvb_usb_device *d = adap_to_d(adap);
920 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300921 struct i2c_adapter *rtl2830_tuner_i2c;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300922 struct dvb_frontend *fe;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300923
Antti Palosaaric01a3592012-08-12 22:27:07 -0300924 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300925
926 /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300927 rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300928
929 switch (priv->tuner) {
930 case TUNER_RTL2830_QT1010:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300931 fe = dvb_attach(qt1010_attach, adap->fe[0],
Antti Palosaarifba16b12012-01-21 20:28:38 -0300932 rtl2830_tuner_i2c, &rtl28xxu_qt1010_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300933 break;
934 case TUNER_RTL2830_MT2060:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300935 fe = dvb_attach(mt2060_attach, adap->fe[0],
Antti Palosaarifba16b12012-01-21 20:28:38 -0300936 rtl2830_tuner_i2c, &rtl28xxu_mt2060_config,
937 1220);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300938 break;
939 case TUNER_RTL2830_MXL5005S:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300940 fe = dvb_attach(mxl5005s_attach, adap->fe[0],
Antti Palosaari9935eea2012-01-21 22:26:52 -0300941 rtl2830_tuner_i2c, &rtl28xxu_mxl5005s_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300942 break;
943 default:
Antti Palosaari9935eea2012-01-21 22:26:52 -0300944 fe = NULL;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300945 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
946 priv->tuner);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300947 }
948
949 if (fe == NULL) {
950 ret = -ENODEV;
951 goto err;
952 }
953
954 return 0;
955err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300956 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300957 return ret;
958}
959
Antti Palosaari384df492012-09-08 22:07:25 -0300960static const struct fc2580_config rtl2832u_fc2580_config = {
961 .i2c_addr = 0x56,
962 .clock = 16384000,
963};
964
Antti Palosaari5be65722012-09-11 22:27:09 -0300965static struct tua9001_config rtl2832u_tua9001_config = {
966 .i2c_addr = 0x60,
967};
968
Antti Palosaariad3a7582012-12-08 23:27:49 -0300969static const struct fc0012_config rtl2832u_fc0012_config = {
970 .i2c_address = 0x63, /* 0xc6 >> 1 */
971 .xtal_freq = FC_XTAL_28_8_MHZ,
972};
973
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300974static const struct r820t_config rtl2832u_r820t_config = {
975 .i2c_addr = 0x1a,
976 .xtal = 28800000,
977 .max_i2c_msg_len = 2,
978 .rafael_chip = CHIP_R820T,
979};
980
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300981static const struct r820t_config rtl2832u_r828d_config = {
982 .i2c_addr = 0x3a,
983 .xtal = 16000000,
984 .max_i2c_msg_len = 2,
985 .rafael_chip = CHIP_R828D,
986};
987
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300988static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
989{
990 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300991 struct dvb_usb_device *d = adap_to_d(adap);
992 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari28fd31f2013-10-15 19:22:45 -0300993 struct dvb_frontend *fe = NULL;
994 struct i2c_board_info info;
995 struct i2c_client *client;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300996
Antti Palosaaric01a3592012-08-12 22:27:07 -0300997 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300998
Antti Palosaari28fd31f2013-10-15 19:22:45 -0300999 memset(&info, 0, sizeof(struct i2c_board_info));
1000
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001001 switch (priv->tuner) {
Thomas Mair5cf66312012-05-18 14:47:41 -03001002 case TUNER_RTL2832_FC0012:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001003 fe = dvb_attach(fc0012_attach, adap->fe[0],
Antti Palosaariad3a7582012-12-08 23:27:49 -03001004 &d->i2c_adap, &rtl2832u_fc0012_config);
Thomas Mair5cf66312012-05-18 14:47:41 -03001005
1006 /* since fc0012 includs reading the signal strength delegate
1007 * that to the tuner driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -03001008 adap->fe[0]->ops.read_signal_strength =
1009 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Antti Palosaaribcf43392013-09-10 00:13:57 -03001010
1011 /* attach SDR */
Antti Palosaaribeab1b52014-04-09 18:08:37 -03001012 dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap,
Antti Palosaaribcf43392013-09-10 00:13:57 -03001013 &rtl28xxu_rtl2832_fc0012_config, NULL);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001014 break;
Thomas Mair5cf66312012-05-18 14:47:41 -03001015 case TUNER_RTL2832_FC0013:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001016 fe = dvb_attach(fc0013_attach, adap->fe[0],
1017 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -03001018
1019 /* fc0013 also supports signal strength reading */
Antti Palosaaric01a3592012-08-12 22:27:07 -03001020 adap->fe[0]->ops.read_signal_strength =
1021 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Antti Palosaaribcf43392013-09-10 00:13:57 -03001022
1023 /* attach SDR */
Antti Palosaaribeab1b52014-04-09 18:08:37 -03001024 dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap,
Antti Palosaaribcf43392013-09-10 00:13:57 -03001025 &rtl28xxu_rtl2832_fc0013_config, NULL);
Antti Palosaari55cdb7d2014-02-03 23:07:21 -03001026 break;
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001027 case TUNER_RTL2832_E4000: {
Antti Palosaaribcf43392013-09-10 00:13:57 -03001028 struct v4l2_subdev *sd;
Antti Palosaariae1f8452014-02-08 04:03:57 -03001029 struct i2c_adapter *i2c_adap_internal =
1030 rtl2832_get_private_i2c_adapter(adap->fe[0]);
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001031 struct e4000_config e4000_config = {
1032 .fe = adap->fe[0],
1033 .clock = 28800000,
1034 };
1035
1036 strlcpy(info.type, "e4000", I2C_NAME_SIZE);
1037 info.addr = 0x64;
1038 info.platform_data = &e4000_config;
1039
1040 request_module(info.type);
Antti Palosaariae1f8452014-02-08 04:03:57 -03001041 client = i2c_new_device(priv->demod_i2c_adapter, &info);
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001042 if (client == NULL || client->dev.driver == NULL)
1043 break;
1044
1045 if (!try_module_get(client->dev.driver->owner)) {
1046 i2c_unregister_device(client);
1047 break;
1048 }
1049
1050 priv->client = client;
Antti Palosaaribcf43392013-09-10 00:13:57 -03001051 sd = i2c_get_clientdata(client);
Antti Palosaariae1f8452014-02-08 04:03:57 -03001052 i2c_set_adapdata(i2c_adap_internal, d);
Antti Palosaaribcf43392013-09-10 00:13:57 -03001053
1054 /* attach SDR */
Antti Palosaaribeab1b52014-04-09 18:08:37 -03001055 dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0],
Antti Palosaariae1f8452014-02-08 04:03:57 -03001056 i2c_adap_internal,
Antti Palosaaribcf43392013-09-10 00:13:57 -03001057 &rtl28xxu_rtl2832_e4000_config, sd);
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001058 }
Antti Palosaari542f6a52012-09-01 21:09:22 -03001059 break;
Antti Palosaari384df492012-09-08 22:07:25 -03001060 case TUNER_RTL2832_FC2580:
1061 fe = dvb_attach(fc2580_attach, adap->fe[0], &d->i2c_adap,
1062 &rtl2832u_fc2580_config);
1063 break;
Antti Palosaari5be65722012-09-11 22:27:09 -03001064 case TUNER_RTL2832_TUA9001:
1065 /* enable GPIO1 and GPIO4 as output */
Antti Palosaari4005c1a2012-09-17 15:43:57 -03001066 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12);
1067 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -03001068 goto err;
1069
Antti Palosaari4005c1a2012-09-17 15:43:57 -03001070 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12);
1071 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -03001072 goto err;
1073
1074 fe = dvb_attach(tua9001_attach, adap->fe[0], &d->i2c_adap,
1075 &rtl2832u_tua9001_config);
1076 break;
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -03001077 case TUNER_RTL2832_R820T:
1078 fe = dvb_attach(r820t_attach, adap->fe[0], &d->i2c_adap,
1079 &rtl2832u_r820t_config);
Mauro Carvalho Chehab9e30edd2013-04-07 18:57:15 -03001080
1081 /* Use tuner to get the signal strength */
1082 adap->fe[0]->ops.read_signal_strength =
1083 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Antti Palosaaribcf43392013-09-10 00:13:57 -03001084
1085 /* attach SDR */
Antti Palosaaribeab1b52014-04-09 18:08:37 -03001086 dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap,
Antti Palosaaribcf43392013-09-10 00:13:57 -03001087 &rtl28xxu_rtl2832_r820t_config, NULL);
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -03001088 break;
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001089 case TUNER_RTL2832_R828D:
Antti Palosaari80f189a2013-12-01 13:44:23 -03001090 fe = dvb_attach(r820t_attach, adap->fe[0],
1091 priv->demod_i2c_adapter,
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001092 &rtl2832u_r828d_config);
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001093 adap->fe[0]->ops.read_signal_strength =
1094 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Antti Palosaari80f189a2013-12-01 13:44:23 -03001095
1096 if (adap->fe[1]) {
1097 fe = dvb_attach(r820t_attach, adap->fe[1],
1098 priv->demod_i2c_adapter,
1099 &rtl2832u_r828d_config);
1100 adap->fe[1]->ops.read_signal_strength =
1101 adap->fe[1]->ops.tuner_ops.get_rf_strength;
1102 }
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001103 break;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001104 default:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001105 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
1106 priv->tuner);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001107 }
1108
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001109 if (fe == NULL && priv->client == NULL) {
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001110 ret = -ENODEV;
1111 goto err;
1112 }
1113
1114 return 0;
1115err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001116 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001117 return ret;
1118}
1119
Antti Palosaaric01a3592012-08-12 22:27:07 -03001120static int rtl28xxu_init(struct dvb_usb_device *d)
1121{
1122 int ret;
1123 u8 val;
1124
1125 dev_dbg(&d->udev->dev, "%s:\n", __func__);
1126
1127 /* init USB endpoints */
1128 ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val);
1129 if (ret)
1130 goto err;
1131
1132 /* enable DMA and Full Packet Mode*/
1133 val |= 0x09;
1134 ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val);
1135 if (ret)
1136 goto err;
1137
1138 /* set EPA maximum packet size to 0x0200 */
1139 ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
1140 if (ret)
1141 goto err;
1142
1143 /* change EPA FIFO length */
1144 ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
1145 if (ret)
1146 goto err;
1147
1148 return ret;
1149err:
1150 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
1151 return ret;
1152}
1153
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001154static void rtl28xxu_exit(struct dvb_usb_device *d)
1155{
1156 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaari80f189a2013-12-01 13:44:23 -03001157 struct i2c_client *client;
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001158
1159 dev_dbg(&d->udev->dev, "%s:\n", __func__);
1160
1161 /* remove I2C tuner */
Antti Palosaari80f189a2013-12-01 13:44:23 -03001162 client = priv->client;
1163 if (client) {
1164 module_put(client->dev.driver->owner);
1165 i2c_unregister_device(client);
1166 }
1167
1168 /* remove I2C slave demod */
1169 client = priv->i2c_client_slave_demod;
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001170 if (client) {
1171 module_put(client->dev.driver->owner);
1172 i2c_unregister_device(client);
1173 }
1174
1175 return;
1176}
1177
Thomas Mair5cf66312012-05-18 14:47:41 -03001178static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001179{
1180 int ret;
Antti Palosaari8b036632012-09-01 09:54:43 -03001181 u8 gpio, sys0, epa_ctl[2];
Antti Palosaari831e0b72011-07-08 23:36:07 -03001182
Antti Palosaaric01a3592012-08-12 22:27:07 -03001183 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001184
1185 /* demod adc */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001186 ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001187 if (ret)
1188 goto err;
1189
1190 /* tuner power, read GPIOs */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001191 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001192 if (ret)
1193 goto err;
1194
Antti Palosaaric01a3592012-08-12 22:27:07 -03001195 dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
1196 sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001197
1198 if (onoff) {
1199 gpio |= 0x01; /* GPIO0 = 1 */
1200 gpio &= (~0x10); /* GPIO4 = 0 */
Antti Palosaari991452a2012-08-12 22:27:08 -03001201 gpio |= 0x04; /* GPIO2 = 1, LED on */
Antti Palosaari831e0b72011-07-08 23:36:07 -03001202 sys0 = sys0 & 0x0f;
1203 sys0 |= 0xe0;
Antti Palosaari8b036632012-09-01 09:54:43 -03001204 epa_ctl[0] = 0x00; /* clear stall */
1205 epa_ctl[1] = 0x00; /* clear reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -03001206 } else {
Antti Palosaari831e0b72011-07-08 23:36:07 -03001207 gpio &= (~0x01); /* GPIO0 = 0 */
1208 gpio |= 0x10; /* GPIO4 = 1 */
Antti Palosaari991452a2012-08-12 22:27:08 -03001209 gpio &= (~0x04); /* GPIO2 = 1, LED off */
Antti Palosaari831e0b72011-07-08 23:36:07 -03001210 sys0 = sys0 & (~0xc0);
Antti Palosaari8b036632012-09-01 09:54:43 -03001211 epa_ctl[0] = 0x10; /* set stall */
1212 epa_ctl[1] = 0x02; /* set reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -03001213 }
1214
Antti Palosaaric01a3592012-08-12 22:27:07 -03001215 dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
1216 sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001217
1218 /* demod adc */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001219 ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001220 if (ret)
1221 goto err;
1222
1223 /* tuner power, write GPIOs */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001224 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001225 if (ret)
1226 goto err;
1227
Antti Palosaari8b036632012-09-01 09:54:43 -03001228 /* streaming EP: stall & reset */
1229 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, epa_ctl, 2);
1230 if (ret)
1231 goto err;
1232
1233 if (onoff)
1234 usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
1235
Antti Palosaari831e0b72011-07-08 23:36:07 -03001236 return ret;
1237err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001238 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001239 return ret;
1240}
1241
Thomas Mair5cf66312012-05-18 14:47:41 -03001242static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
1243{
1244 int ret;
Thomas Mair5cf66312012-05-18 14:47:41 -03001245
Antti Palosaaric01a3592012-08-12 22:27:07 -03001246 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Thomas Mair5cf66312012-05-18 14:47:41 -03001247
1248 if (onoff) {
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001249 /* GPIO3=1, GPIO4=0 */
1250 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x08, 0x18);
Thomas Mair5cf66312012-05-18 14:47:41 -03001251 if (ret)
1252 goto err;
1253
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001254 /* suspend? */
1255 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL1, 0x00, 0x10);
Thomas Mair5cf66312012-05-18 14:47:41 -03001256 if (ret)
1257 goto err;
1258
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001259 /* enable PLL */
1260 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x80, 0x80);
Thomas Mair5cf66312012-05-18 14:47:41 -03001261 if (ret)
1262 goto err;
1263
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001264 /* disable reset */
1265 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x20, 0x20);
Thomas Mair5cf66312012-05-18 14:47:41 -03001266 if (ret)
1267 goto err;
1268
Antti Palosaari8b036632012-09-01 09:54:43 -03001269 /* streaming EP: clear stall & reset */
1270 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2);
1271 if (ret)
1272 goto err;
1273
1274 ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
1275 if (ret)
1276 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001277 } else {
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001278 /* GPIO4=1 */
1279 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x10, 0x10);
Thomas Mair5cf66312012-05-18 14:47:41 -03001280 if (ret)
1281 goto err;
1282
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001283 /* disable PLL */
1284 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x80);
Thomas Mair5cf66312012-05-18 14:47:41 -03001285 if (ret)
1286 goto err;
1287
Antti Palosaari8b036632012-09-01 09:54:43 -03001288 /* streaming EP: set stall & reset */
1289 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2);
1290 if (ret)
1291 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001292 }
1293
1294 return ret;
1295err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001296 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -03001297 return ret;
1298}
1299
Antti Palosaari698f6262014-09-27 01:22:45 -03001300static int rtl2832u_frontend_ctrl(struct dvb_frontend *fe, int onoff)
1301{
1302 struct dvb_usb_device *d = fe_to_d(fe);
Antti Palosaari80f189a2013-12-01 13:44:23 -03001303 struct dvb_usb_adapter *adap = fe_to_adap(fe);
Antti Palosaari698f6262014-09-27 01:22:45 -03001304 int ret;
1305 u8 val;
1306
1307 dev_dbg(&d->udev->dev, "%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
1308
1309 /* control internal demod ADC */
1310 if (fe->id == 0 && onoff)
1311 val = 0x48; /* enable ADC */
1312 else
1313 val = 0x00; /* disable ADC */
1314
1315 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, val, 0x48);
1316 if (ret)
1317 goto err;
1318
Antti Palosaari80f189a2013-12-01 13:44:23 -03001319 /* bypass slave demod TS through master demod */
1320 if (fe->id == 1 && onoff) {
1321 ret = rtl2832_enable_external_ts_if(adap->fe[0]);
1322 if (ret)
1323 goto err;
1324 }
1325
Antti Palosaari698f6262014-09-27 01:22:45 -03001326 return 0;
1327err:
1328 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
1329 return ret;
1330}
1331
Antti Palosaari37b44a02013-01-04 15:21:26 -03001332#if IS_ENABLED(CONFIG_RC_CORE)
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001333static int rtl2831u_rc_query(struct dvb_usb_device *d)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001334{
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001335 int ret, i;
1336 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -03001337 u8 buf[5];
1338 u32 rc_code;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001339 struct rtl28xxu_reg_val rc_nec_tab[] = {
1340 { 0x3033, 0x80 },
1341 { 0x3020, 0x43 },
1342 { 0x3021, 0x16 },
1343 { 0x3022, 0x16 },
1344 { 0x3023, 0x5a },
1345 { 0x3024, 0x2d },
1346 { 0x3025, 0x16 },
1347 { 0x3026, 0x01 },
1348 { 0x3028, 0xb0 },
1349 { 0x3029, 0x04 },
1350 { 0x302c, 0x88 },
1351 { 0x302e, 0x13 },
1352 { 0x3030, 0xdf },
1353 { 0x3031, 0x05 },
1354 };
1355
1356 /* init remote controller */
1357 if (!priv->rc_active) {
1358 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001359 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001360 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001361 if (ret)
1362 goto err;
1363 }
1364 priv->rc_active = true;
1365 }
Antti Palosaari831e0b72011-07-08 23:36:07 -03001366
1367 ret = rtl2831_rd_regs(d, SYS_IRRC_RP, buf, 5);
1368 if (ret)
1369 goto err;
1370
1371 if (buf[4] & 0x01) {
1372 if (buf[2] == (u8) ~buf[3]) {
1373 if (buf[0] == (u8) ~buf[1]) {
1374 /* NEC standard (16 bit) */
David Härdeman120703f2014-04-03 20:31:30 -03001375 rc_code = RC_SCANCODE_NEC(buf[0], buf[2]);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001376 } else {
1377 /* NEC extended (24 bit) */
David Härdeman120703f2014-04-03 20:31:30 -03001378 rc_code = RC_SCANCODE_NECX(buf[0] << 8 | buf[1],
1379 buf[2]);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001380 }
1381 } else {
1382 /* NEC full (32 bit) */
David Härdeman120703f2014-04-03 20:31:30 -03001383 rc_code = RC_SCANCODE_NEC32(buf[0] << 24 | buf[1] << 16 |
1384 buf[2] << 8 | buf[3]);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001385 }
1386
David Härdeman120703f2014-04-03 20:31:30 -03001387 rc_keydown(d->rc_dev, RC_TYPE_NEC, rc_code, 0);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001388
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001389 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001390 if (ret)
1391 goto err;
1392
1393 /* repeated intentionally to avoid extra keypress */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001394 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001395 if (ret)
1396 goto err;
1397 }
1398
1399 return ret;
1400err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001401 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001402 return ret;
1403}
1404
Antti Palosaaric01a3592012-08-12 22:27:07 -03001405static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
1406 struct dvb_usb_rc *rc)
1407{
1408 rc->map_name = RC_MAP_EMPTY;
David Härdemanc003ab12012-10-11 19:11:54 -03001409 rc->allowed_protos = RC_BIT_NEC;
Antti Palosaaric01a3592012-08-12 22:27:07 -03001410 rc->query = rtl2831u_rc_query;
1411 rc->interval = 400;
1412
1413 return 0;
1414}
1415
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001416static int rtl2832u_rc_query(struct dvb_usb_device *d)
1417{
Antti Palosaarif39fac32013-06-04 09:17:03 -03001418 int ret, i, len;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001419 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaarif39fac32013-06-04 09:17:03 -03001420 struct ir_raw_event ev;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001421 u8 buf[128];
Antti Palosaarif39fac32013-06-04 09:17:03 -03001422 static const struct rtl28xxu_reg_val_mask refresh_tab[] = {
1423 {IR_RX_IF, 0x03, 0xff},
1424 {IR_RX_BUF_CTRL, 0x80, 0xff},
1425 {IR_RX_CTRL, 0x80, 0xff},
1426 };
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001427
1428 /* init remote controller */
1429 if (!priv->rc_active) {
Antti Palosaarif39fac32013-06-04 09:17:03 -03001430 static const struct rtl28xxu_reg_val_mask init_tab[] = {
1431 {SYS_DEMOD_CTL1, 0x00, 0x04},
1432 {SYS_DEMOD_CTL1, 0x00, 0x08},
1433 {USB_CTRL, 0x20, 0x20},
1434 {SYS_GPIO_DIR, 0x00, 0x08},
1435 {SYS_GPIO_OUT_EN, 0x08, 0x08},
1436 {SYS_GPIO_OUT_VAL, 0x08, 0x08},
1437 {IR_MAX_DURATION0, 0xd0, 0xff},
1438 {IR_MAX_DURATION1, 0x07, 0xff},
1439 {IR_IDLE_LEN0, 0xc0, 0xff},
1440 {IR_IDLE_LEN1, 0x00, 0xff},
1441 {IR_GLITCH_LEN, 0x03, 0xff},
1442 {IR_RX_CLK, 0x09, 0xff},
1443 {IR_RX_CFG, 0x1c, 0xff},
1444 {IR_MAX_H_TOL_LEN, 0x1e, 0xff},
1445 {IR_MAX_L_TOL_LEN, 0x1e, 0xff},
1446 {IR_RX_CTRL, 0x80, 0xff},
1447 };
1448
1449 for (i = 0; i < ARRAY_SIZE(init_tab); i++) {
1450 ret = rtl28xx_wr_reg_mask(d, init_tab[i].reg,
1451 init_tab[i].val, init_tab[i].mask);
Rodrigo Tartajo1e414132013-04-20 20:02:12 -03001452 if (ret)
1453 goto err;
1454 }
Antti Palosaarif39fac32013-06-04 09:17:03 -03001455
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001456 priv->rc_active = true;
1457 }
1458
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001459 ret = rtl28xx_rd_reg(d, IR_RX_IF, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001460 if (ret)
1461 goto err;
1462
1463 if (buf[0] != 0x83)
Antti Palosaarif39fac32013-06-04 09:17:03 -03001464 goto exit;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001465
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001466 ret = rtl28xx_rd_reg(d, IR_RX_BC, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001467 if (ret)
1468 goto err;
1469
1470 len = buf[0];
Antti Palosaarif39fac32013-06-04 09:17:03 -03001471
1472 /* read raw code from hw */
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001473 ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len);
Antti Palosaarif39fac32013-06-04 09:17:03 -03001474 if (ret)
1475 goto err;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001476
Antti Palosaarif39fac32013-06-04 09:17:03 -03001477 /* let hw receive new code */
1478 for (i = 0; i < ARRAY_SIZE(refresh_tab); i++) {
1479 ret = rtl28xx_wr_reg_mask(d, refresh_tab[i].reg,
1480 refresh_tab[i].val, refresh_tab[i].mask);
Rodrigo Tartajo1e414132013-04-20 20:02:12 -03001481 if (ret)
1482 goto err;
1483 }
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001484
Antti Palosaarif39fac32013-06-04 09:17:03 -03001485 /* pass data to Kernel IR decoder */
1486 init_ir_raw_event(&ev);
1487
1488 for (i = 0; i < len; i++) {
1489 ev.pulse = buf[i] >> 7;
1490 ev.duration = 50800 * (buf[i] & 0x7f);
1491 ir_raw_event_store_with_filter(d->rc_dev, &ev);
1492 }
1493
1494 /* 'flush' ir_raw_event_store_with_filter() */
1495 ir_raw_event_set_idle(d->rc_dev, true);
1496 ir_raw_event_handle(d->rc_dev);
1497exit:
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001498 return ret;
1499err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001500 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001501 return ret;
1502}
1503
Antti Palosaaric01a3592012-08-12 22:27:07 -03001504static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1505 struct dvb_usb_rc *rc)
1506{
Antti Palosaari94b5fa62013-11-22 14:20:14 -03001507 /* disable IR interrupts in order to avoid SDR sample loss */
1508 if (rtl28xxu_disable_rc)
1509 return rtl28xx_wr_reg(d, IR_RX_IE, 0x00);
1510
Antti Palosaarif39fac32013-06-04 09:17:03 -03001511 /* load empty to enable rc */
1512 if (!rc->map_name)
1513 rc->map_name = RC_MAP_EMPTY;
Rodrigo Tartajo1e414132013-04-20 20:02:12 -03001514 rc->allowed_protos = RC_BIT_ALL;
Antti Palosaarif39fac32013-06-04 09:17:03 -03001515 rc->driver_type = RC_DRIVER_IR_RAW;
Antti Palosaaric01a3592012-08-12 22:27:07 -03001516 rc->query = rtl2832u_rc_query;
1517 rc->interval = 400;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001518
Antti Palosaaric01a3592012-08-12 22:27:07 -03001519 return 0;
1520}
Antti Palosaaricedda372012-12-09 20:06:00 -03001521#else
Antti Palosaari5a186642013-06-04 16:50:54 -03001522#define rtl2831u_get_rc_config NULL
1523#define rtl2832u_get_rc_config NULL
Antti Palosaaricedda372012-12-09 20:06:00 -03001524#endif
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001525
Antti Palosaaric01a3592012-08-12 22:27:07 -03001526static const struct dvb_usb_device_properties rtl2831u_props = {
1527 .driver_name = KBUILD_MODNAME,
1528 .owner = THIS_MODULE,
1529 .adapter_nr = adapter_nr,
1530 .size_of_priv = sizeof(struct rtl28xxu_priv),
Antti Palosaari831e0b72011-07-08 23:36:07 -03001531
Antti Palosaaric01a3592012-08-12 22:27:07 -03001532 .power_ctrl = rtl2831u_power_ctrl,
1533 .i2c_algo = &rtl28xxu_i2c_algo,
Antti Palosaari81347f52012-09-17 16:50:36 -03001534 .read_config = rtl2831u_read_config,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001535 .frontend_attach = rtl2831u_frontend_attach,
1536 .tuner_attach = rtl2831u_tuner_attach,
1537 .init = rtl28xxu_init,
1538 .get_rc_config = rtl2831u_get_rc_config,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001539
Antti Palosaaric01a3592012-08-12 22:27:07 -03001540 .num_adapters = 1,
1541 .adapter = {
1542 {
1543 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaari831e0b72011-07-08 23:36:07 -03001544 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001545 },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001546};
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001547
Antti Palosaaric01a3592012-08-12 22:27:07 -03001548static const struct dvb_usb_device_properties rtl2832u_props = {
1549 .driver_name = KBUILD_MODNAME,
1550 .owner = THIS_MODULE,
1551 .adapter_nr = adapter_nr,
1552 .size_of_priv = sizeof(struct rtl28xxu_priv),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001553
Antti Palosaaric01a3592012-08-12 22:27:07 -03001554 .power_ctrl = rtl2832u_power_ctrl,
Antti Palosaari698f6262014-09-27 01:22:45 -03001555 .frontend_ctrl = rtl2832u_frontend_ctrl,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001556 .i2c_algo = &rtl28xxu_i2c_algo,
Antti Palosaarief37be12012-09-17 14:01:35 -03001557 .read_config = rtl2832u_read_config,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001558 .frontend_attach = rtl2832u_frontend_attach,
1559 .tuner_attach = rtl2832u_tuner_attach,
1560 .init = rtl28xxu_init,
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001561 .exit = rtl28xxu_exit,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001562 .get_rc_config = rtl2832u_get_rc_config,
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001563
Antti Palosaaric01a3592012-08-12 22:27:07 -03001564 .num_adapters = 1,
1565 .adapter = {
1566 {
1567 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001568 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001569 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001570};
1571
Antti Palosaaric01a3592012-08-12 22:27:07 -03001572static const struct usb_device_id rtl28xxu_id_table[] = {
Jan Vcelak60aa4c62014-02-26 15:33:40 -03001573 /* RTL2831U devices: */
Antti Palosaaric01a3592012-08-12 22:27:07 -03001574 { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U,
1575 &rtl2831u_props, "Realtek RTL2831U reference design", NULL) },
1576 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT,
1577 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
1578 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2,
1579 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001580
Jan Vcelak60aa4c62014-02-26 15:33:40 -03001581 /* RTL2832U devices: */
Antti Palosaari254ee2e2012-09-18 10:27:05 -03001582 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832,
1583 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
1584 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
1585 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001586 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
Antti Palosaaribc6fc532013-06-04 17:24:06 -03001587 &rtl2832u_props, "TerraTec Cinergy T Stick Black", RC_MAP_TERRATEC_SLIM) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001588 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
1589 &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
1590 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
Antti Palosaari9db15632013-01-04 18:35:00 -03001591 &rtl2832u_props, "TerraTec NOXON DAB Stick", NULL) },
Juergen Locke9de0512012-11-13 14:09:28 -03001592 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV2,
Antti Palosaari9db15632013-01-04 18:35:00 -03001593 &rtl2832u_props, "TerraTec NOXON DAB Stick (rev 2)", NULL) },
Till Dörgesa24bc322014-02-11 17:27:57 -03001594 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV3,
1595 &rtl2832u_props, "TerraTec NOXON DAB Stick (rev 3)", NULL) },
Philipp Dreimann6d608052012-09-02 19:30:54 -03001596 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0,
1597 &rtl2832u_props, "Trekstor DVB-T Stick Terres 2.0", NULL) },
Antti Palosaaric2d246d12012-09-08 22:07:26 -03001598 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101,
1599 &rtl2832u_props, "Dexatek DK DVB-T Dongle", NULL) },
Antti Palosaari3d8866d2012-09-20 18:34:50 -03001600 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6680,
1601 &rtl2832u_props, "DigitalNow Quad DVB-T Receiver", NULL) },
Robert Backhausd22d32e2013-12-13 09:59:10 -03001602 { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_MINID,
1603 &rtl2832u_props, "Leadtek Winfast DTV Dongle Mini D", NULL) },
Antti Palosaaria4f64402012-09-29 15:28:56 -03001604 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d3,
1605 &rtl2832u_props, "TerraTec Cinergy T Stick RC (Rev. 3)", NULL) },
Antti Palosaari08e57272012-11-06 16:03:35 -03001606 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1102,
1607 &rtl2832u_props, "Dexatek DK mini DVB-T Dongle", NULL) },
Andrew Karpow86163ad2012-11-06 20:01:16 -03001608 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d7,
1609 &rtl2832u_props, "TerraTec Cinergy T Stick+", NULL) },
Antti Palosaari3971e792012-12-16 11:47:07 -03001610 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd3a8,
1611 &rtl2832u_props, "ASUS My Cinema-U3100Mini Plus V2", NULL) },
Alexander Inyukhin78a5e702013-01-04 18:19:02 -03001612 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd393,
Antti Palosaari9db15632013-01-04 18:35:00 -03001613 &rtl2832u_props, "GIGABYTE U7300", NULL) },
Eddi De Pieri09f94082013-01-14 18:21:32 -03001614 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1104,
Antti Palosaari7dc0a012013-06-04 17:01:25 -03001615 &rtl2832u_props, "MSI DIGIVOX Micro HD", NULL) },
Alistair Buxtonb9e2aff2013-02-12 21:58:47 -03001616 { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620,
1617 &rtl2832u_props, "Compro VideoMate U620F", NULL) },
Fabrizio Gazzatoe6a60d72013-02-15 18:54:54 -03001618 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
1619 &rtl2832u_props, "MaxMedia HU394-T", NULL) },
Miroslav Šustek6c5a4062013-05-14 19:42:11 -03001620 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
Antti Palosaari7dc0a012013-06-04 17:01:25 -03001621 &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
Alessandro Micelic6be7522013-06-04 16:10:34 -03001622 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
Antti Palosaari7df27252013-06-04 19:43:30 -03001623 &rtl2832u_props, "Crypto ReDi PC 50 A", NULL) },
Jan Vcelakac298cc2014-02-26 15:33:39 -03001624 { DVB_USB_DEVICE(USB_VID_KYE, 0x707f,
1625 &rtl2832u_props, "Genius TVGo DVB-T03", NULL) },
Brian Healy9ca24ae2014-05-04 18:43:39 -03001626 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd395,
1627 &rtl2832u_props, "Peak DVB-T USB", NULL) },
Alessandro Micelif27f5b02014-05-04 07:37:15 -03001628 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20_RTL2832U,
1629 &rtl2832u_props, "Sveon STV20", NULL) },
Sebastian89c5ff02014-06-12 03:22:45 -03001630 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV21,
1631 &rtl2832u_props, "Sveon STV21", NULL) },
Alessandro Miceli74a86272014-05-04 07:50:31 -03001632 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV27,
1633 &rtl2832u_props, "Sveon STV27", NULL) },
Antti Palosaari8fdd33b2013-10-30 02:33:42 -03001634
Jan Vcelak60aa4c62014-02-26 15:33:40 -03001635 /* RTL2832P devices: */
Antti Palosaari8fdd33b2013-10-30 02:33:42 -03001636 { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131,
1637 &rtl2832u_props, "Astrometa DVB-T2", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001638 { }
1639};
1640MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001641
Antti Palosaaric01a3592012-08-12 22:27:07 -03001642static struct usb_driver rtl28xxu_usb_driver = {
1643 .name = KBUILD_MODNAME,
1644 .id_table = rtl28xxu_id_table,
1645 .probe = dvb_usbv2_probe,
1646 .disconnect = dvb_usbv2_disconnect,
1647 .suspend = dvb_usbv2_suspend,
1648 .resume = dvb_usbv2_resume,
Antti Palosaari78fa5902012-08-14 22:21:09 -03001649 .reset_resume = dvb_usbv2_reset_resume,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001650 .no_dynamic_id = 1,
1651 .soft_unbind = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001652};
1653
Antti Palosaaric01a3592012-08-12 22:27:07 -03001654module_usb_driver(rtl28xxu_usb_driver);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001655
1656MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
1657MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
Thomas Mair5cf66312012-05-18 14:47:41 -03001658MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>");
Antti Palosaari831e0b72011-07-08 23:36:07 -03001659MODULE_LICENSE("GPL");