blob: 3b98ad4cd0a676760de3111ae46cf97acefefbde [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 Palosaari831e0b72011-07-08 23:36:07 -030027
28#include "qt1010.h"
29#include "mt2060.h"
30#include "mxl5005s.h"
Thomas Mair5cf66312012-05-18 14:47:41 -030031#include "fc0012.h"
32#include "fc0013.h"
Antti Palosaari542f6a52012-09-01 21:09:22 -030033#include "e4000.h"
Antti Palosaari384df492012-09-08 22:07:25 -030034#include "fc2580.h"
Antti Palosaari5be65722012-09-11 22:27:09 -030035#include "tua9001.h"
Antti Palosaari831e0b72011-07-08 23:36:07 -030036
Antti Palosaari831e0b72011-07-08 23:36:07 -030037DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
38
39static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
40{
41 int ret;
42 unsigned int pipe;
43 u8 requesttype;
44 u8 *buf;
45
46 buf = kmalloc(req->size, GFP_KERNEL);
47 if (!buf) {
48 ret = -ENOMEM;
49 goto err;
50 }
51
52 if (req->index & CMD_WR_FLAG) {
53 /* write */
54 memcpy(buf, req->data, req->size);
55 requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT);
56 pipe = usb_sndctrlpipe(d->udev, 0);
57 } else {
58 /* read */
59 requesttype = (USB_TYPE_VENDOR | USB_DIR_IN);
60 pipe = usb_rcvctrlpipe(d->udev, 0);
61 }
62
63 ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value,
Antti Palosaari9935eea2012-01-21 22:26:52 -030064 req->index, buf, req->size, 1000);
Antti Palosaarid89b9362012-08-22 19:42:00 -030065
66 dvb_usb_dbg_usb_control_msg(d->udev, 0, requesttype, req->value,
67 req->index, buf, req->size);
68
Antti Palosaari9935eea2012-01-21 22:26:52 -030069 if (ret > 0)
70 ret = 0;
Antti Palosaari831e0b72011-07-08 23:36:07 -030071
Antti Palosaari831e0b72011-07-08 23:36:07 -030072 /* read request, copy returned data to return buf */
73 if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
74 memcpy(req->data, buf, req->size);
75
76 kfree(buf);
Antti Palosaari831e0b72011-07-08 23:36:07 -030077
Antti Palosaari9935eea2012-01-21 22:26:52 -030078 if (ret)
79 goto err;
80
81 return ret;
Antti Palosaari831e0b72011-07-08 23:36:07 -030082err:
Antti Palosaaric01a3592012-08-12 22:27:07 -030083 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -030084 return ret;
85}
86
Thomas Mair40a2d3c2012-05-18 14:47:42 -030087static int rtl28xx_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
Antti Palosaari831e0b72011-07-08 23:36:07 -030088{
89 struct rtl28xxu_req req;
90
91 if (reg < 0x3000)
92 req.index = CMD_USB_WR;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -030093 else if (reg < 0x4000)
Antti Palosaari831e0b72011-07-08 23:36:07 -030094 req.index = CMD_SYS_WR;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -030095 else
96 req.index = CMD_IR_WR;
Antti Palosaari831e0b72011-07-08 23:36:07 -030097
98 req.value = reg;
99 req.size = len;
100 req.data = val;
101
102 return rtl28xxu_ctrl_msg(d, &req);
103}
104
105static int rtl2831_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
106{
107 struct rtl28xxu_req req;
108
109 if (reg < 0x3000)
110 req.index = CMD_USB_RD;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300111 else if (reg < 0x4000)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300112 req.index = CMD_SYS_RD;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300113 else
114 req.index = CMD_IR_RD;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300115
116 req.value = reg;
117 req.size = len;
118 req.data = val;
119
120 return rtl28xxu_ctrl_msg(d, &req);
121}
122
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300123static int rtl28xx_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300124{
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300125 return rtl28xx_wr_regs(d, reg, &val, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300126}
127
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300128static int rtl28xx_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300129{
130 return rtl2831_rd_regs(d, reg, val, 1);
131}
132
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300133static int rtl28xx_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
134 u8 mask)
135{
136 int ret;
137 u8 tmp;
138
139 /* no need for read if whole reg is written */
140 if (mask != 0xff) {
141 ret = rtl28xx_rd_reg(d, reg, &tmp);
142 if (ret)
143 return ret;
144
145 val &= mask;
146 tmp &= ~mask;
147 val |= tmp;
148 }
149
150 return rtl28xx_wr_reg(d, reg, val);
151}
152
Antti Palosaari831e0b72011-07-08 23:36:07 -0300153/* I2C */
154static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
155 int num)
156{
157 int ret;
158 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300159 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300160 struct rtl28xxu_req req;
161
162 /*
163 * It is not known which are real I2C bus xfer limits, but testing
164 * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes.
Antti Palosaari34ec2932011-08-04 20:21:16 -0300165 * TODO: find out RTL2832U lens
166 */
167
168 /*
169 * I2C adapter logic looks rather complicated due to fact it handles
170 * three different access methods. Those methods are;
171 * 1) integrated demod access
172 * 2) old I2C access
173 * 3) new I2C access
174 *
175 * Used method is selected in order 1, 2, 3. Method 3 can handle all
176 * requests but there is two reasons why not use it always;
177 * 1) It is most expensive, usually two USB messages are needed
178 * 2) At least RTL2831U does not support it
179 *
180 * Method 3 is needed in case of I2C write+read (typical register read)
181 * where write is more than one byte.
Antti Palosaari831e0b72011-07-08 23:36:07 -0300182 */
183
184 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
185 return -EAGAIN;
186
187 if (num == 2 && !(msg[0].flags & I2C_M_RD) &&
188 (msg[1].flags & I2C_M_RD)) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300189 if (msg[0].len > 24 || msg[1].len > 24) {
190 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300191 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300192 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300193 } else if (msg[0].addr == 0x10) {
194 /* method 1 - integrated demod */
195 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
196 req.index = CMD_DEMOD_RD | priv->page;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300197 req.size = msg[1].len;
198 req.data = &msg[1].buf[0];
199 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300200 } else if (msg[0].len < 2) {
201 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300202 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
203 req.index = CMD_I2C_RD;
204 req.size = msg[1].len;
205 req.data = &msg[1].buf[0];
206 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300207 } else {
208 /* method 3 - new I2C */
209 req.value = (msg[0].addr << 1);
210 req.index = CMD_I2C_DA_WR;
211 req.size = msg[0].len;
212 req.data = msg[0].buf;
213 ret = rtl28xxu_ctrl_msg(d, &req);
214 if (ret)
Antti Palosaari9935eea2012-01-21 22:26:52 -0300215 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300216
217 req.value = (msg[0].addr << 1);
218 req.index = CMD_I2C_DA_RD;
219 req.size = msg[1].len;
220 req.data = msg[1].buf;
221 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300222 }
223 } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
224 if (msg[0].len > 22) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300225 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300226 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300227 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300228 } else if (msg[0].addr == 0x10) {
229 /* method 1 - integrated demod */
230 if (msg[0].buf[0] == 0x00) {
231 /* save demod page for later demod access */
232 priv->page = msg[0].buf[1];
233 ret = 0;
234 } else {
235 req.value = (msg[0].buf[0] << 8) |
236 (msg[0].addr << 1);
237 req.index = CMD_DEMOD_WR | priv->page;
238 req.size = msg[0].len-1;
239 req.data = &msg[0].buf[1];
240 ret = rtl28xxu_ctrl_msg(d, &req);
241 }
242 } else if (msg[0].len < 23) {
243 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300244 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
245 req.index = CMD_I2C_WR;
246 req.size = msg[0].len-1;
247 req.data = &msg[0].buf[1];
248 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300249 } else {
250 /* method 3 - new I2C */
251 req.value = (msg[0].addr << 1);
252 req.index = CMD_I2C_DA_WR;
253 req.size = msg[0].len;
254 req.data = msg[0].buf;
255 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300256 }
257 } else {
258 ret = -EINVAL;
259 }
260
Antti Palosaari9935eea2012-01-21 22:26:52 -0300261err_mutex_unlock:
Antti Palosaari831e0b72011-07-08 23:36:07 -0300262 mutex_unlock(&d->i2c_mutex);
263
264 return ret ? ret : num;
265}
266
267static u32 rtl28xxu_i2c_func(struct i2c_adapter *adapter)
268{
269 return I2C_FUNC_I2C;
270}
271
272static struct i2c_algorithm rtl28xxu_i2c_algo = {
273 .master_xfer = rtl28xxu_i2c_xfer,
274 .functionality = rtl28xxu_i2c_func,
275};
276
Antti Palosaarief37be12012-09-17 14:01:35 -0300277static int rtl2832u_read_config(struct dvb_usb_device *d)
278{
279 struct rtl28xxu_priv *priv = d_to_priv(d);
280 int ret;
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300281 u8 buf[2];
Antti Palosaarief37be12012-09-17 14:01:35 -0300282 /* open RTL2832U/RTL2832 I2C gate */
283 struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"};
284 /* close RTL2832U/RTL2832 I2C gate */
285 struct rtl28xxu_req req_gate_close = {0x0120, 0x0011, 0x0001, "\x10"};
286 /* tuner probes */
287 struct rtl28xxu_req req_fc0012 = {0x00c6, CMD_I2C_RD, 1, buf};
288 struct rtl28xxu_req req_fc0013 = {0x00c6, CMD_I2C_RD, 1, buf};
289 struct rtl28xxu_req req_mt2266 = {0x00c0, CMD_I2C_RD, 1, buf};
290 struct rtl28xxu_req req_fc2580 = {0x01ac, CMD_I2C_RD, 1, buf};
291 struct rtl28xxu_req req_mt2063 = {0x00c0, CMD_I2C_RD, 1, buf};
292 struct rtl28xxu_req req_max3543 = {0x00c0, CMD_I2C_RD, 1, buf};
293 struct rtl28xxu_req req_tua9001 = {0x7ec0, CMD_I2C_RD, 2, buf};
294 struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf};
295 struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
296 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
297
298 dev_dbg(&d->udev->dev, "%s:\n", __func__);
299
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300300 /* enable GPIO3 and GPIO6 as output */
301 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x40);
Antti Palosaarief37be12012-09-17 14:01:35 -0300302 if (ret)
303 goto err;
304
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300305 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x48, 0x48);
Antti Palosaarief37be12012-09-17 14:01:35 -0300306 if (ret)
307 goto err;
308
309 /*
310 * Probe used tuner. We need to know used tuner before demod attach
311 * since there is some demod params needed to set according to tuner.
312 */
313
314 /* open demod I2C gate */
315 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
316 if (ret)
317 goto err;
318
319 priv->tuner_name = "NONE";
320
321 /* check FC0012 ID register; reg=00 val=a1 */
322 ret = rtl28xxu_ctrl_msg(d, &req_fc0012);
323 if (ret == 0 && buf[0] == 0xa1) {
324 priv->tuner = TUNER_RTL2832_FC0012;
325 priv->tuner_name = "FC0012";
326 goto found;
327 }
328
329 /* check FC0013 ID register; reg=00 val=a3 */
330 ret = rtl28xxu_ctrl_msg(d, &req_fc0013);
331 if (ret == 0 && buf[0] == 0xa3) {
332 priv->tuner = TUNER_RTL2832_FC0013;
333 priv->tuner_name = "FC0013";
334 goto found;
335 }
336
337 /* check MT2266 ID register; reg=00 val=85 */
338 ret = rtl28xxu_ctrl_msg(d, &req_mt2266);
339 if (ret == 0 && buf[0] == 0x85) {
340 priv->tuner = TUNER_RTL2832_MT2266;
341 priv->tuner_name = "MT2266";
342 goto found;
343 }
344
345 /* check FC2580 ID register; reg=01 val=56 */
346 ret = rtl28xxu_ctrl_msg(d, &req_fc2580);
347 if (ret == 0 && buf[0] == 0x56) {
348 priv->tuner = TUNER_RTL2832_FC2580;
349 priv->tuner_name = "FC2580";
350 goto found;
351 }
352
353 /* check MT2063 ID register; reg=00 val=9e || 9c */
354 ret = rtl28xxu_ctrl_msg(d, &req_mt2063);
355 if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) {
356 priv->tuner = TUNER_RTL2832_MT2063;
357 priv->tuner_name = "MT2063";
358 goto found;
359 }
360
361 /* check MAX3543 ID register; reg=00 val=38 */
362 ret = rtl28xxu_ctrl_msg(d, &req_max3543);
363 if (ret == 0 && buf[0] == 0x38) {
364 priv->tuner = TUNER_RTL2832_MAX3543;
365 priv->tuner_name = "MAX3543";
366 goto found;
367 }
368
369 /* check TUA9001 ID register; reg=7e val=2328 */
370 ret = rtl28xxu_ctrl_msg(d, &req_tua9001);
371 if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) {
372 priv->tuner = TUNER_RTL2832_TUA9001;
373 priv->tuner_name = "TUA9001";
374 goto found;
375 }
376
377 /* check MXL5007R ID register; reg=d9 val=14 */
378 ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t);
379 if (ret == 0 && buf[0] == 0x14) {
380 priv->tuner = TUNER_RTL2832_MXL5007T;
381 priv->tuner_name = "MXL5007T";
382 goto found;
383 }
384
385 /* check E4000 ID register; reg=02 val=40 */
386 ret = rtl28xxu_ctrl_msg(d, &req_e4000);
387 if (ret == 0 && buf[0] == 0x40) {
388 priv->tuner = TUNER_RTL2832_E4000;
389 priv->tuner_name = "E4000";
390 goto found;
391 }
392
393 /* check TDA18272 ID register; reg=00 val=c760 */
394 ret = rtl28xxu_ctrl_msg(d, &req_tda18272);
395 if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) {
396 priv->tuner = TUNER_RTL2832_TDA18272;
397 priv->tuner_name = "TDA18272";
398 goto found;
399 }
400
401found:
402 dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name);
403
404 /* close demod I2C gate */
405 ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
406 if (ret < 0)
407 goto err;
408
409 return 0;
410err:
411 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
412 return ret;
413}
414
Antti Palosaari831e0b72011-07-08 23:36:07 -0300415static struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = {
416 .i2c_addr = 0x10, /* 0x20 */
417 .xtal = 28800000,
418 .ts_mode = 0,
419 .spec_inv = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300420 .vtop = 0x20,
421 .krf = 0x04,
422 .agc_targ_val = 0x2d,
423
424};
425
426static struct rtl2830_config rtl28xxu_rtl2830_qt1010_config = {
427 .i2c_addr = 0x10, /* 0x20 */
428 .xtal = 28800000,
429 .ts_mode = 0,
430 .spec_inv = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300431 .vtop = 0x20,
432 .krf = 0x04,
433 .agc_targ_val = 0x2d,
434};
435
436static struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = {
437 .i2c_addr = 0x10, /* 0x20 */
438 .xtal = 28800000,
439 .ts_mode = 0,
440 .spec_inv = 0,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300441 .vtop = 0x3f,
442 .krf = 0x04,
443 .agc_targ_val = 0x3e,
444};
445
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300446static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300447{
448 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300449 struct dvb_usb_device *d = adap_to_d(adap);
450 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300451 u8 buf[1];
452 struct rtl2830_config *rtl2830_config;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300453 /* open RTL2831U/RTL2830 I2C gate */
Antti Palosaari9935eea2012-01-21 22:26:52 -0300454 struct rtl28xxu_req req_gate = { 0x0120, 0x0011, 0x0001, "\x08" };
Antti Palosaari831e0b72011-07-08 23:36:07 -0300455 /* for MT2060 tuner probe */
Antti Palosaari9935eea2012-01-21 22:26:52 -0300456 struct rtl28xxu_req req_mt2060 = { 0x00c0, CMD_I2C_RD, 1, buf };
Antti Palosaari831e0b72011-07-08 23:36:07 -0300457 /* for QT1010 tuner probe */
Antti Palosaari9935eea2012-01-21 22:26:52 -0300458 struct rtl28xxu_req req_qt1010 = { 0x0fc4, CMD_I2C_RD, 1, buf };
Antti Palosaari831e0b72011-07-08 23:36:07 -0300459
Antti Palosaaric01a3592012-08-12 22:27:07 -0300460 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300461
462 /*
463 * RTL2831U GPIOs
464 * =========================================================
465 * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?)
466 * GPIO2 | LED | 0 off | 1 on |
467 * GPIO4 | tuner#1 | 0 on | 1 off | MT2060
468 */
469
470 /* GPIO direction */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300471 ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, 0x0a);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300472 if (ret)
473 goto err;
474
475 /* enable as output GPIO0, GPIO2, GPIO4 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300476 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, 0x15);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300477 if (ret)
478 goto err;
479
480 /*
481 * Probe used tuner. We need to know used tuner before demod attach
482 * since there is some demod params needed to set according to tuner.
483 */
484
Antti Palosaariccb5cf92012-05-18 16:07:46 -0300485 /* demod needs some time to wake up */
486 msleep(20);
487
Antti Palosaari831e0b72011-07-08 23:36:07 -0300488 /* open demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300489 ret = rtl28xxu_ctrl_msg(d, &req_gate);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300490 if (ret)
491 goto err;
492
493 /* check QT1010 ID(?) register; reg=0f val=2c */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300494 ret = rtl28xxu_ctrl_msg(d, &req_qt1010);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300495 if (ret == 0 && buf[0] == 0x2c) {
496 priv->tuner = TUNER_RTL2830_QT1010;
497 rtl2830_config = &rtl28xxu_rtl2830_qt1010_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300498 dev_dbg(&d->udev->dev, "%s: QT1010\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300499 goto found;
500 } else {
Antti Palosaaric01a3592012-08-12 22:27:07 -0300501 dev_dbg(&d->udev->dev, "%s: QT1010 probe failed=%d - %02x\n",
502 __func__, ret, buf[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300503 }
504
505 /* open demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300506 ret = rtl28xxu_ctrl_msg(d, &req_gate);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300507 if (ret)
508 goto err;
509
510 /* check MT2060 ID register; reg=00 val=63 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300511 ret = rtl28xxu_ctrl_msg(d, &req_mt2060);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300512 if (ret == 0 && buf[0] == 0x63) {
513 priv->tuner = TUNER_RTL2830_MT2060;
514 rtl2830_config = &rtl28xxu_rtl2830_mt2060_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300515 dev_dbg(&d->udev->dev, "%s: MT2060\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300516 goto found;
517 } else {
Antti Palosaaric01a3592012-08-12 22:27:07 -0300518 dev_dbg(&d->udev->dev, "%s: MT2060 probe failed=%d - %02x\n",
519 __func__, ret, buf[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300520 }
521
522 /* assume MXL5005S */
Antti Palosaarie9320ec2011-08-03 04:35:30 -0300523 ret = 0;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300524 priv->tuner = TUNER_RTL2830_MXL5005S;
525 rtl2830_config = &rtl28xxu_rtl2830_mxl5005s_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300526 dev_dbg(&d->udev->dev, "%s: MXL5005S\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300527 goto found;
528
529found:
530 /* attach demodulator */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300531 adap->fe[0] = dvb_attach(rtl2830_attach, rtl2830_config,
532 &d->i2c_adap);
533 if (adap->fe[0] == NULL) {
Antti Palosaari831e0b72011-07-08 23:36:07 -0300534 ret = -ENODEV;
535 goto err;
536 }
537
538 return ret;
539err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300540 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300541 return ret;
542}
543
Thomas Mair5cf66312012-05-18 14:47:41 -0300544static struct rtl2832_config rtl28xxu_rtl2832_fc0012_config = {
545 .i2c_addr = 0x10, /* 0x20 */
546 .xtal = 28800000,
547 .if_dvbt = 0,
548 .tuner = TUNER_RTL2832_FC0012
549};
550
551static struct rtl2832_config rtl28xxu_rtl2832_fc0013_config = {
552 .i2c_addr = 0x10, /* 0x20 */
553 .xtal = 28800000,
554 .if_dvbt = 0,
555 .tuner = TUNER_RTL2832_FC0013
556};
557
Antti Palosaari5be65722012-09-11 22:27:09 -0300558static struct rtl2832_config rtl28xxu_rtl2832_tua9001_config = {
559 .i2c_addr = 0x10, /* 0x20 */
560 .xtal = 28800000,
561 .tuner = TUNER_RTL2832_TUA9001,
562};
563
Thomas Mair5cf66312012-05-18 14:47:41 -0300564static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
565 int cmd, int arg)
566{
567 int ret;
568 u8 val;
569
Antti Palosaaric01a3592012-08-12 22:27:07 -0300570 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
571
Thomas Mair5cf66312012-05-18 14:47:41 -0300572 switch (cmd) {
573 case FC_FE_CALLBACK_VHF_ENABLE:
574 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300575 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300576 if (ret)
577 goto err;
578
579 if (arg)
580 val &= 0xbf; /* set GPIO6 low */
581 else
582 val |= 0x40; /* set GPIO6 high */
583
584
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300585 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300586 if (ret)
587 goto err;
588 break;
589 default:
590 ret = -EINVAL;
591 goto err;
592 }
593 return 0;
594
595err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300596 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -0300597 return ret;
598}
599
600
601static int rtl2832u_fc0013_tuner_callback(struct dvb_usb_device *d,
602 int cmd, int arg)
603{
604 /* TODO implement*/
605 return 0;
606}
607
Antti Palosaari5be65722012-09-11 22:27:09 -0300608static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d,
609 int cmd, int arg)
610{
611 int ret;
612 u8 val;
613
614 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
615
616 /*
617 * CEN always enabled by hardware wiring
618 * RESETN GPIO4
619 * RXEN GPIO1
620 */
621
Antti Palosaari5be65722012-09-11 22:27:09 -0300622 switch (cmd) {
623 case TUA9001_CMD_RESETN:
624 if (arg)
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300625 val = (1 << 4);
Antti Palosaari5be65722012-09-11 22:27:09 -0300626 else
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300627 val = (0 << 4);
Antti Palosaari5be65722012-09-11 22:27:09 -0300628
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300629 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x10);
630 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300631 goto err;
632 break;
633 case TUA9001_CMD_RXEN:
634 if (arg)
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300635 val = (1 << 1);
Antti Palosaari5be65722012-09-11 22:27:09 -0300636 else
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300637 val = (0 << 1);
Antti Palosaari5be65722012-09-11 22:27:09 -0300638
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300639 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x02);
640 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300641 goto err;
642 break;
643 }
644
645 return 0;
646
647err:
648 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
649 return ret;
650}
651
Thomas Mair5cf66312012-05-18 14:47:41 -0300652static int rtl2832u_tuner_callback(struct dvb_usb_device *d, int cmd, int arg)
653{
654 struct rtl28xxu_priv *priv = d->priv;
655
656 switch (priv->tuner) {
657 case TUNER_RTL2832_FC0012:
658 return rtl2832u_fc0012_tuner_callback(d, cmd, arg);
659
660 case TUNER_RTL2832_FC0013:
661 return rtl2832u_fc0013_tuner_callback(d, cmd, arg);
Antti Palosaari5be65722012-09-11 22:27:09 -0300662
663 case TUNER_RTL2832_TUA9001:
664 return rtl2832u_tua9001_tuner_callback(d, cmd, arg);
Thomas Mair5cf66312012-05-18 14:47:41 -0300665 default:
666 break;
667 }
668
669 return -ENODEV;
670}
671
672static int rtl2832u_frontend_callback(void *adapter_priv, int component,
673 int cmd, int arg)
674{
675 struct i2c_adapter *adap = adapter_priv;
676 struct dvb_usb_device *d = i2c_get_adapdata(adap);
677
678 switch (component) {
679 case DVB_FRONTEND_COMPONENT_TUNER:
680 return rtl2832u_tuner_callback(d, cmd, arg);
681 default:
682 break;
683 }
684
685 return -EINVAL;
686}
687
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300688static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
689{
690 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300691 struct dvb_usb_device *d = adap_to_d(adap);
692 struct rtl28xxu_priv *priv = d_to_priv(d);
Thomas Mair5cf66312012-05-18 14:47:41 -0300693 struct rtl2832_config *rtl2832_config;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300694
Antti Palosaaric01a3592012-08-12 22:27:07 -0300695 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300696
Antti Palosaarief37be12012-09-17 14:01:35 -0300697 switch (priv->tuner) {
698 case TUNER_RTL2832_FC0012:
Thomas Mair5cf66312012-05-18 14:47:41 -0300699 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300700 break;
701 case TUNER_RTL2832_FC0013:
Thomas Mair5cf66312012-05-18 14:47:41 -0300702 rtl2832_config = &rtl28xxu_rtl2832_fc0013_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300703 break;
704 case TUNER_RTL2832_FC2580:
Antti Palosaari384df492012-09-08 22:07:25 -0300705 /* FIXME: do not abuse fc0012 settings */
706 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300707 break;
708 case TUNER_RTL2832_TUA9001:
Antti Palosaari5be65722012-09-11 22:27:09 -0300709 rtl2832_config = &rtl28xxu_rtl2832_tua9001_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300710 break;
711 case TUNER_RTL2832_E4000:
Antti Palosaari542f6a52012-09-01 21:09:22 -0300712 /* FIXME: do not abuse fc0012 settings */
713 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300714 break;
715 default:
716 dev_err(&d->udev->dev, "%s: unknown tuner=%s\n",
717 KBUILD_MODNAME, priv->tuner_name);
718 ret = -ENODEV;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300719 goto err;
Antti Palosaarief37be12012-09-17 14:01:35 -0300720 }
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300721
722 /* attach demodulator */
Antti Palosaarief37be12012-09-17 14:01:35 -0300723 adap->fe[0] = dvb_attach(rtl2832_attach, rtl2832_config, &d->i2c_adap);
724 if (!adap->fe[0]) {
725 ret = -ENODEV;
726 goto err;
727 }
Thomas Mair5cf66312012-05-18 14:47:41 -0300728
Antti Palosaarief37be12012-09-17 14:01:35 -0300729 /* set fe callback */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300730 adap->fe[0]->callback = rtl2832u_frontend_callback;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300731
Antti Palosaarief37be12012-09-17 14:01:35 -0300732 return 0;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300733err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300734 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300735 return ret;
736}
737
Antti Palosaari831e0b72011-07-08 23:36:07 -0300738static struct qt1010_config rtl28xxu_qt1010_config = {
739 .i2c_address = 0x62, /* 0xc4 */
740};
741
742static struct mt2060_config rtl28xxu_mt2060_config = {
743 .i2c_address = 0x60, /* 0xc0 */
744 .clock_out = 0,
745};
746
747static struct mxl5005s_config rtl28xxu_mxl5005s_config = {
748 .i2c_address = 0x63, /* 0xc6 */
749 .if_freq = IF_FREQ_4570000HZ,
750 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
751 .agc_mode = MXL_SINGLE_AGC,
752 .tracking_filter = MXL_TF_C_H,
753 .rssi_enable = MXL_RSSI_ENABLE,
754 .cap_select = MXL_CAP_SEL_ENABLE,
755 .div_out = MXL_DIV_OUT_4,
756 .clock_out = MXL_CLOCK_OUT_DISABLE,
757 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
758 .top = MXL5005S_TOP_25P2,
759 .mod_mode = MXL_DIGITAL_MODE,
760 .if_mode = MXL_ZERO_IF,
761 .AgcMasterByte = 0x00,
762};
763
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300764static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300765{
766 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300767 struct dvb_usb_device *d = adap_to_d(adap);
768 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300769 struct i2c_adapter *rtl2830_tuner_i2c;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300770 struct dvb_frontend *fe;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300771
Antti Palosaaric01a3592012-08-12 22:27:07 -0300772 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300773
774 /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300775 rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300776
777 switch (priv->tuner) {
778 case TUNER_RTL2830_QT1010:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300779 fe = dvb_attach(qt1010_attach, adap->fe[0],
Antti Palosaarifba16b12012-01-21 20:28:38 -0300780 rtl2830_tuner_i2c, &rtl28xxu_qt1010_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300781 break;
782 case TUNER_RTL2830_MT2060:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300783 fe = dvb_attach(mt2060_attach, adap->fe[0],
Antti Palosaarifba16b12012-01-21 20:28:38 -0300784 rtl2830_tuner_i2c, &rtl28xxu_mt2060_config,
785 1220);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300786 break;
787 case TUNER_RTL2830_MXL5005S:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300788 fe = dvb_attach(mxl5005s_attach, adap->fe[0],
Antti Palosaari9935eea2012-01-21 22:26:52 -0300789 rtl2830_tuner_i2c, &rtl28xxu_mxl5005s_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300790 break;
791 default:
Antti Palosaari9935eea2012-01-21 22:26:52 -0300792 fe = NULL;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300793 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
794 priv->tuner);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300795 }
796
797 if (fe == NULL) {
798 ret = -ENODEV;
799 goto err;
800 }
801
802 return 0;
803err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300804 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300805 return ret;
806}
807
Antti Palosaari542f6a52012-09-01 21:09:22 -0300808static const struct e4000_config rtl2832u_e4000_config = {
809 .i2c_addr = 0x64,
810 .clock = 28800000,
811};
812
Antti Palosaari384df492012-09-08 22:07:25 -0300813static const struct fc2580_config rtl2832u_fc2580_config = {
814 .i2c_addr = 0x56,
815 .clock = 16384000,
816};
817
Antti Palosaari5be65722012-09-11 22:27:09 -0300818static struct tua9001_config rtl2832u_tua9001_config = {
819 .i2c_addr = 0x60,
820};
821
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300822static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
823{
824 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300825 struct dvb_usb_device *d = adap_to_d(adap);
826 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari9935eea2012-01-21 22:26:52 -0300827 struct dvb_frontend *fe;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300828
Antti Palosaaric01a3592012-08-12 22:27:07 -0300829 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300830
831 switch (priv->tuner) {
Thomas Mair5cf66312012-05-18 14:47:41 -0300832 case TUNER_RTL2832_FC0012:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300833 fe = dvb_attach(fc0012_attach, adap->fe[0],
834 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -0300835
836 /* since fc0012 includs reading the signal strength delegate
837 * that to the tuner driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300838 adap->fe[0]->ops.read_signal_strength =
839 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Thomas Mair5cf66312012-05-18 14:47:41 -0300840 return 0;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300841 break;
Thomas Mair5cf66312012-05-18 14:47:41 -0300842 case TUNER_RTL2832_FC0013:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300843 fe = dvb_attach(fc0013_attach, adap->fe[0],
844 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -0300845
846 /* fc0013 also supports signal strength reading */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300847 adap->fe[0]->ops.read_signal_strength =
848 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Thomas Mair5cf66312012-05-18 14:47:41 -0300849 return 0;
Antti Palosaari542f6a52012-09-01 21:09:22 -0300850 case TUNER_RTL2832_E4000:
851 fe = dvb_attach(e4000_attach, adap->fe[0], &d->i2c_adap,
852 &rtl2832u_e4000_config);
853 break;
Antti Palosaari384df492012-09-08 22:07:25 -0300854 case TUNER_RTL2832_FC2580:
855 fe = dvb_attach(fc2580_attach, adap->fe[0], &d->i2c_adap,
856 &rtl2832u_fc2580_config);
857 break;
Antti Palosaari5be65722012-09-11 22:27:09 -0300858 case TUNER_RTL2832_TUA9001:
859 /* enable GPIO1 and GPIO4 as output */
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300860 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12);
861 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300862 goto err;
863
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300864 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12);
865 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300866 goto err;
867
868 fe = dvb_attach(tua9001_attach, adap->fe[0], &d->i2c_adap,
869 &rtl2832u_tua9001_config);
870 break;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300871 default:
Antti Palosaari9935eea2012-01-21 22:26:52 -0300872 fe = NULL;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300873 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
874 priv->tuner);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300875 }
876
877 if (fe == NULL) {
878 ret = -ENODEV;
879 goto err;
880 }
881
882 return 0;
883err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300884 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300885 return ret;
886}
887
Antti Palosaaric01a3592012-08-12 22:27:07 -0300888static int rtl28xxu_init(struct dvb_usb_device *d)
889{
890 int ret;
891 u8 val;
892
893 dev_dbg(&d->udev->dev, "%s:\n", __func__);
894
895 /* init USB endpoints */
896 ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val);
897 if (ret)
898 goto err;
899
900 /* enable DMA and Full Packet Mode*/
901 val |= 0x09;
902 ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val);
903 if (ret)
904 goto err;
905
906 /* set EPA maximum packet size to 0x0200 */
907 ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
908 if (ret)
909 goto err;
910
911 /* change EPA FIFO length */
912 ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
913 if (ret)
914 goto err;
915
916 return ret;
917err:
918 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
919 return ret;
920}
921
Thomas Mair5cf66312012-05-18 14:47:41 -0300922static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300923{
924 int ret;
Antti Palosaari8b036632012-09-01 09:54:43 -0300925 u8 gpio, sys0, epa_ctl[2];
Antti Palosaari831e0b72011-07-08 23:36:07 -0300926
Antti Palosaaric01a3592012-08-12 22:27:07 -0300927 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300928
929 /* demod adc */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300930 ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300931 if (ret)
932 goto err;
933
934 /* tuner power, read GPIOs */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300935 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300936 if (ret)
937 goto err;
938
Antti Palosaaric01a3592012-08-12 22:27:07 -0300939 dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
940 sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300941
942 if (onoff) {
943 gpio |= 0x01; /* GPIO0 = 1 */
944 gpio &= (~0x10); /* GPIO4 = 0 */
Antti Palosaari991452a2012-08-12 22:27:08 -0300945 gpio |= 0x04; /* GPIO2 = 1, LED on */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300946 sys0 = sys0 & 0x0f;
947 sys0 |= 0xe0;
Antti Palosaari8b036632012-09-01 09:54:43 -0300948 epa_ctl[0] = 0x00; /* clear stall */
949 epa_ctl[1] = 0x00; /* clear reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300950 } else {
Antti Palosaari831e0b72011-07-08 23:36:07 -0300951 gpio &= (~0x01); /* GPIO0 = 0 */
952 gpio |= 0x10; /* GPIO4 = 1 */
Antti Palosaari991452a2012-08-12 22:27:08 -0300953 gpio &= (~0x04); /* GPIO2 = 1, LED off */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300954 sys0 = sys0 & (~0xc0);
Antti Palosaari8b036632012-09-01 09:54:43 -0300955 epa_ctl[0] = 0x10; /* set stall */
956 epa_ctl[1] = 0x02; /* set reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300957 }
958
Antti Palosaaric01a3592012-08-12 22:27:07 -0300959 dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
960 sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300961
962 /* demod adc */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300963 ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300964 if (ret)
965 goto err;
966
967 /* tuner power, write GPIOs */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300968 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300969 if (ret)
970 goto err;
971
Antti Palosaari8b036632012-09-01 09:54:43 -0300972 /* streaming EP: stall & reset */
973 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, epa_ctl, 2);
974 if (ret)
975 goto err;
976
977 if (onoff)
978 usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
979
Antti Palosaari831e0b72011-07-08 23:36:07 -0300980 return ret;
981err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300982 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300983 return ret;
984}
985
Thomas Mair5cf66312012-05-18 14:47:41 -0300986static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
987{
988 int ret;
989 u8 val;
990
Antti Palosaaric01a3592012-08-12 22:27:07 -0300991 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Thomas Mair5cf66312012-05-18 14:47:41 -0300992
993 if (onoff) {
994 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300995 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300996 if (ret)
997 goto err;
998
999 val |= 0x08;
1000 val &= 0xef;
1001
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001002 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001003 if (ret)
1004 goto err;
1005
1006 /* demod_ctl_1 */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001007 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001008 if (ret)
1009 goto err;
1010
1011 val &= 0xef;
1012
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001013 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001014 if (ret)
1015 goto err;
1016
1017 /* demod control */
1018 /* PLL enable */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001019 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001020 if (ret)
1021 goto err;
1022
1023 /* bit 7 to 1 */
1024 val |= 0x80;
1025
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001026 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001027 if (ret)
1028 goto err;
1029
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001030 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001031 if (ret)
1032 goto err;
1033
1034 val |= 0x20;
1035
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001036 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001037 if (ret)
1038 goto err;
1039
1040 mdelay(5);
1041
1042 /*enable ADC_Q and ADC_I */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001043 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001044 if (ret)
1045 goto err;
1046
1047 val |= 0x48;
1048
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001049 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001050 if (ret)
1051 goto err;
1052
Antti Palosaari8b036632012-09-01 09:54:43 -03001053 /* streaming EP: clear stall & reset */
1054 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2);
1055 if (ret)
1056 goto err;
1057
1058 ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
1059 if (ret)
1060 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001061 } else {
1062 /* demod_ctl_1 */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001063 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001064 if (ret)
1065 goto err;
1066
1067 val |= 0x0c;
1068
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001069 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001070 if (ret)
1071 goto err;
1072
1073 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001074 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001075 if (ret)
1076 goto err;
1077
1078 val |= 0x10;
1079
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001080 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001081 if (ret)
1082 goto err;
1083
1084 /* demod control */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001085 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001086 if (ret)
1087 goto err;
1088
1089 val &= 0x37;
1090
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001091 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001092 if (ret)
1093 goto err;
1094
Antti Palosaari8b036632012-09-01 09:54:43 -03001095 /* streaming EP: set stall & reset */
1096 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2);
1097 if (ret)
1098 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001099 }
1100
1101 return ret;
1102err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001103 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -03001104 return ret;
1105}
1106
1107
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001108static int rtl2831u_rc_query(struct dvb_usb_device *d)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001109{
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001110 int ret, i;
1111 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -03001112 u8 buf[5];
1113 u32 rc_code;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001114 struct rtl28xxu_reg_val rc_nec_tab[] = {
1115 { 0x3033, 0x80 },
1116 { 0x3020, 0x43 },
1117 { 0x3021, 0x16 },
1118 { 0x3022, 0x16 },
1119 { 0x3023, 0x5a },
1120 { 0x3024, 0x2d },
1121 { 0x3025, 0x16 },
1122 { 0x3026, 0x01 },
1123 { 0x3028, 0xb0 },
1124 { 0x3029, 0x04 },
1125 { 0x302c, 0x88 },
1126 { 0x302e, 0x13 },
1127 { 0x3030, 0xdf },
1128 { 0x3031, 0x05 },
1129 };
1130
1131 /* init remote controller */
1132 if (!priv->rc_active) {
1133 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001134 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001135 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001136 if (ret)
1137 goto err;
1138 }
1139 priv->rc_active = true;
1140 }
Antti Palosaari831e0b72011-07-08 23:36:07 -03001141
1142 ret = rtl2831_rd_regs(d, SYS_IRRC_RP, buf, 5);
1143 if (ret)
1144 goto err;
1145
1146 if (buf[4] & 0x01) {
1147 if (buf[2] == (u8) ~buf[3]) {
1148 if (buf[0] == (u8) ~buf[1]) {
1149 /* NEC standard (16 bit) */
1150 rc_code = buf[0] << 8 | buf[2];
1151 } else {
1152 /* NEC extended (24 bit) */
1153 rc_code = buf[0] << 16 |
Antti Palosaari9935eea2012-01-21 22:26:52 -03001154 buf[1] << 8 | buf[2];
Antti Palosaari831e0b72011-07-08 23:36:07 -03001155 }
1156 } else {
1157 /* NEC full (32 bit) */
1158 rc_code = buf[0] << 24 | buf[1] << 16 |
1159 buf[2] << 8 | buf[3];
1160 }
1161
1162 rc_keydown(d->rc_dev, rc_code, 0);
1163
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001164 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001165 if (ret)
1166 goto err;
1167
1168 /* repeated intentionally to avoid extra keypress */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001169 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001170 if (ret)
1171 goto err;
1172 }
1173
1174 return ret;
1175err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001176 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001177 return ret;
1178}
1179
Antti Palosaaric01a3592012-08-12 22:27:07 -03001180static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
1181 struct dvb_usb_rc *rc)
1182{
1183 rc->map_name = RC_MAP_EMPTY;
1184 rc->allowed_protos = RC_TYPE_NEC;
1185 rc->query = rtl2831u_rc_query;
1186 rc->interval = 400;
1187
1188 return 0;
1189}
1190
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001191static int rtl2832u_rc_query(struct dvb_usb_device *d)
1192{
1193 int ret, i;
1194 struct rtl28xxu_priv *priv = d->priv;
1195 u8 buf[128];
1196 int len;
1197 struct rtl28xxu_reg_val rc_nec_tab[] = {
Antti Palosaari9935eea2012-01-21 22:26:52 -03001198 { IR_RX_CTRL, 0x20 },
1199 { IR_RX_BUF_CTRL, 0x80 },
1200 { IR_RX_IF, 0xff },
1201 { IR_RX_IE, 0xff },
1202 { IR_MAX_DURATION0, 0xd0 },
1203 { IR_MAX_DURATION1, 0x07 },
1204 { IR_IDLE_LEN0, 0xc0 },
1205 { IR_IDLE_LEN1, 0x00 },
1206 { IR_GLITCH_LEN, 0x03 },
1207 { IR_RX_CLK, 0x09 },
1208 { IR_RX_CFG, 0x1c },
1209 { IR_MAX_H_TOL_LEN, 0x1e },
1210 { IR_MAX_L_TOL_LEN, 0x1e },
1211 { IR_RX_CTRL, 0x80 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001212 };
1213
1214 /* init remote controller */
1215 if (!priv->rc_active) {
1216 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001217 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001218 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001219 if (ret)
1220 goto err;
1221 }
1222 priv->rc_active = true;
1223 }
1224
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001225 ret = rtl28xx_rd_reg(d, IR_RX_IF, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001226 if (ret)
1227 goto err;
1228
1229 if (buf[0] != 0x83)
1230 goto exit;
1231
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001232 ret = rtl28xx_rd_reg(d, IR_RX_BC, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001233 if (ret)
1234 goto err;
1235
1236 len = buf[0];
1237 ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len);
1238
1239 /* TODO: pass raw IR to Kernel IR decoder */
1240
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001241 ret = rtl28xx_wr_reg(d, IR_RX_IF, 0x03);
1242 ret = rtl28xx_wr_reg(d, IR_RX_BUF_CTRL, 0x80);
1243 ret = rtl28xx_wr_reg(d, IR_RX_CTRL, 0x80);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001244
1245exit:
1246 return ret;
1247err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001248 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001249 return ret;
1250}
1251
Antti Palosaaric01a3592012-08-12 22:27:07 -03001252static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1253 struct dvb_usb_rc *rc)
1254{
1255 rc->map_name = RC_MAP_EMPTY;
1256 rc->allowed_protos = RC_TYPE_NEC;
1257 rc->query = rtl2832u_rc_query;
1258 rc->interval = 400;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001259
Antti Palosaaric01a3592012-08-12 22:27:07 -03001260 return 0;
1261}
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001262
Antti Palosaaric01a3592012-08-12 22:27:07 -03001263static const struct dvb_usb_device_properties rtl2831u_props = {
1264 .driver_name = KBUILD_MODNAME,
1265 .owner = THIS_MODULE,
1266 .adapter_nr = adapter_nr,
1267 .size_of_priv = sizeof(struct rtl28xxu_priv),
Antti Palosaari831e0b72011-07-08 23:36:07 -03001268
Antti Palosaaric01a3592012-08-12 22:27:07 -03001269 .power_ctrl = rtl2831u_power_ctrl,
1270 .i2c_algo = &rtl28xxu_i2c_algo,
1271 .frontend_attach = rtl2831u_frontend_attach,
1272 .tuner_attach = rtl2831u_tuner_attach,
1273 .init = rtl28xxu_init,
1274 .get_rc_config = rtl2831u_get_rc_config,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001275
Antti Palosaaric01a3592012-08-12 22:27:07 -03001276 .num_adapters = 1,
1277 .adapter = {
1278 {
1279 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaari831e0b72011-07-08 23:36:07 -03001280 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001281 },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001282};
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001283
Antti Palosaaric01a3592012-08-12 22:27:07 -03001284static const struct dvb_usb_device_properties rtl2832u_props = {
1285 .driver_name = KBUILD_MODNAME,
1286 .owner = THIS_MODULE,
1287 .adapter_nr = adapter_nr,
1288 .size_of_priv = sizeof(struct rtl28xxu_priv),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001289
Antti Palosaaric01a3592012-08-12 22:27:07 -03001290 .power_ctrl = rtl2832u_power_ctrl,
1291 .i2c_algo = &rtl28xxu_i2c_algo,
Antti Palosaarief37be12012-09-17 14:01:35 -03001292 .read_config = rtl2832u_read_config,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001293 .frontend_attach = rtl2832u_frontend_attach,
1294 .tuner_attach = rtl2832u_tuner_attach,
1295 .init = rtl28xxu_init,
1296 .get_rc_config = rtl2832u_get_rc_config,
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001297
Antti Palosaaric01a3592012-08-12 22:27:07 -03001298 .num_adapters = 1,
1299 .adapter = {
1300 {
1301 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001302 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001303 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001304};
1305
Antti Palosaaric01a3592012-08-12 22:27:07 -03001306static const struct usb_device_id rtl28xxu_id_table[] = {
1307 { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U,
1308 &rtl2831u_props, "Realtek RTL2831U reference design", NULL) },
1309 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT,
1310 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
1311 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2,
1312 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001313
Antti Palosaari254ee2e2012-09-18 10:27:05 -03001314 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832,
1315 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
1316 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
1317 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001318 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
1319 &rtl2832u_props, "Terratec Cinergy T Stick Black", NULL) },
1320 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
1321 &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
1322 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
1323 &rtl2832u_props, "NOXON DAB/DAB+ USB dongle", NULL) },
Philipp Dreimann6d608052012-09-02 19:30:54 -03001324 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0,
1325 &rtl2832u_props, "Trekstor DVB-T Stick Terres 2.0", NULL) },
Antti Palosaaric2d246d12012-09-08 22:07:26 -03001326 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101,
1327 &rtl2832u_props, "Dexatek DK DVB-T Dongle", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001328 { }
1329};
1330MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001331
Antti Palosaaric01a3592012-08-12 22:27:07 -03001332static struct usb_driver rtl28xxu_usb_driver = {
1333 .name = KBUILD_MODNAME,
1334 .id_table = rtl28xxu_id_table,
1335 .probe = dvb_usbv2_probe,
1336 .disconnect = dvb_usbv2_disconnect,
1337 .suspend = dvb_usbv2_suspend,
1338 .resume = dvb_usbv2_resume,
Antti Palosaari78fa5902012-08-14 22:21:09 -03001339 .reset_resume = dvb_usbv2_reset_resume,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001340 .no_dynamic_id = 1,
1341 .soft_unbind = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001342};
1343
Antti Palosaaric01a3592012-08-12 22:27:07 -03001344module_usb_driver(rtl28xxu_usb_driver);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001345
1346MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
1347MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
Thomas Mair5cf66312012-05-18 14:47:41 -03001348MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>");
Antti Palosaari831e0b72011-07-08 23:36:07 -03001349MODULE_LICENSE("GPL");