blob: 757abee4c2cc2a4696897435ca3eb8edb580b04f [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;
Thomas Mair5cf66312012-05-18 14:47:41 -0300594err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300595 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -0300596 return ret;
597}
598
599
600static int rtl2832u_fc0013_tuner_callback(struct dvb_usb_device *d,
601 int cmd, int arg)
602{
603 /* TODO implement*/
604 return 0;
605}
606
Antti Palosaari5be65722012-09-11 22:27:09 -0300607static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d,
608 int cmd, int arg)
609{
610 int ret;
611 u8 val;
612
613 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
614
615 /*
616 * CEN always enabled by hardware wiring
617 * RESETN GPIO4
618 * RXEN GPIO1
619 */
620
Antti Palosaari5be65722012-09-11 22:27:09 -0300621 switch (cmd) {
622 case TUA9001_CMD_RESETN:
623 if (arg)
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300624 val = (1 << 4);
Antti Palosaari5be65722012-09-11 22:27:09 -0300625 else
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300626 val = (0 << 4);
Antti Palosaari5be65722012-09-11 22:27:09 -0300627
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300628 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x10);
629 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300630 goto err;
631 break;
632 case TUA9001_CMD_RXEN:
633 if (arg)
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300634 val = (1 << 1);
Antti Palosaari5be65722012-09-11 22:27:09 -0300635 else
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300636 val = (0 << 1);
Antti Palosaari5be65722012-09-11 22:27:09 -0300637
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300638 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x02);
639 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300640 goto err;
641 break;
642 }
643
644 return 0;
Antti Palosaari5be65722012-09-11 22:27:09 -0300645err:
646 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
647 return ret;
648}
649
Thomas Mair5cf66312012-05-18 14:47:41 -0300650static int rtl2832u_tuner_callback(struct dvb_usb_device *d, int cmd, int arg)
651{
652 struct rtl28xxu_priv *priv = d->priv;
653
654 switch (priv->tuner) {
655 case TUNER_RTL2832_FC0012:
656 return rtl2832u_fc0012_tuner_callback(d, cmd, arg);
Thomas Mair5cf66312012-05-18 14:47:41 -0300657 case TUNER_RTL2832_FC0013:
658 return rtl2832u_fc0013_tuner_callback(d, cmd, arg);
Antti Palosaari5be65722012-09-11 22:27:09 -0300659 case TUNER_RTL2832_TUA9001:
660 return rtl2832u_tua9001_tuner_callback(d, cmd, arg);
Thomas Mair5cf66312012-05-18 14:47:41 -0300661 default:
662 break;
663 }
664
Antti Palosaari97efe782012-09-17 15:49:54 -0300665 return 0;
Thomas Mair5cf66312012-05-18 14:47:41 -0300666}
667
668static int rtl2832u_frontend_callback(void *adapter_priv, int component,
669 int cmd, int arg)
670{
671 struct i2c_adapter *adap = adapter_priv;
672 struct dvb_usb_device *d = i2c_get_adapdata(adap);
673
674 switch (component) {
675 case DVB_FRONTEND_COMPONENT_TUNER:
676 return rtl2832u_tuner_callback(d, cmd, arg);
677 default:
678 break;
679 }
680
Antti Palosaari97efe782012-09-17 15:49:54 -0300681 return 0;
Thomas Mair5cf66312012-05-18 14:47:41 -0300682}
683
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300684static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
685{
686 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300687 struct dvb_usb_device *d = adap_to_d(adap);
688 struct rtl28xxu_priv *priv = d_to_priv(d);
Thomas Mair5cf66312012-05-18 14:47:41 -0300689 struct rtl2832_config *rtl2832_config;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300690
Antti Palosaaric01a3592012-08-12 22:27:07 -0300691 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300692
Antti Palosaarief37be12012-09-17 14:01:35 -0300693 switch (priv->tuner) {
694 case TUNER_RTL2832_FC0012:
Thomas Mair5cf66312012-05-18 14:47:41 -0300695 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300696 break;
697 case TUNER_RTL2832_FC0013:
Thomas Mair5cf66312012-05-18 14:47:41 -0300698 rtl2832_config = &rtl28xxu_rtl2832_fc0013_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300699 break;
700 case TUNER_RTL2832_FC2580:
Antti Palosaari384df492012-09-08 22:07:25 -0300701 /* FIXME: do not abuse fc0012 settings */
702 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300703 break;
704 case TUNER_RTL2832_TUA9001:
Antti Palosaari5be65722012-09-11 22:27:09 -0300705 rtl2832_config = &rtl28xxu_rtl2832_tua9001_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300706 break;
707 case TUNER_RTL2832_E4000:
Antti Palosaari542f6a52012-09-01 21:09:22 -0300708 /* FIXME: do not abuse fc0012 settings */
709 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
Antti Palosaarief37be12012-09-17 14:01:35 -0300710 break;
711 default:
712 dev_err(&d->udev->dev, "%s: unknown tuner=%s\n",
713 KBUILD_MODNAME, priv->tuner_name);
714 ret = -ENODEV;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300715 goto err;
Antti Palosaarief37be12012-09-17 14:01:35 -0300716 }
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300717
718 /* attach demodulator */
Antti Palosaarief37be12012-09-17 14:01:35 -0300719 adap->fe[0] = dvb_attach(rtl2832_attach, rtl2832_config, &d->i2c_adap);
720 if (!adap->fe[0]) {
721 ret = -ENODEV;
722 goto err;
723 }
Thomas Mair5cf66312012-05-18 14:47:41 -0300724
Antti Palosaarief37be12012-09-17 14:01:35 -0300725 /* set fe callback */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300726 adap->fe[0]->callback = rtl2832u_frontend_callback;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300727
Antti Palosaarief37be12012-09-17 14:01:35 -0300728 return 0;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300729err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300730 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300731 return ret;
732}
733
Antti Palosaari831e0b72011-07-08 23:36:07 -0300734static struct qt1010_config rtl28xxu_qt1010_config = {
735 .i2c_address = 0x62, /* 0xc4 */
736};
737
738static struct mt2060_config rtl28xxu_mt2060_config = {
739 .i2c_address = 0x60, /* 0xc0 */
740 .clock_out = 0,
741};
742
743static struct mxl5005s_config rtl28xxu_mxl5005s_config = {
744 .i2c_address = 0x63, /* 0xc6 */
745 .if_freq = IF_FREQ_4570000HZ,
746 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
747 .agc_mode = MXL_SINGLE_AGC,
748 .tracking_filter = MXL_TF_C_H,
749 .rssi_enable = MXL_RSSI_ENABLE,
750 .cap_select = MXL_CAP_SEL_ENABLE,
751 .div_out = MXL_DIV_OUT_4,
752 .clock_out = MXL_CLOCK_OUT_DISABLE,
753 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
754 .top = MXL5005S_TOP_25P2,
755 .mod_mode = MXL_DIGITAL_MODE,
756 .if_mode = MXL_ZERO_IF,
757 .AgcMasterByte = 0x00,
758};
759
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300760static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300761{
762 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300763 struct dvb_usb_device *d = adap_to_d(adap);
764 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300765 struct i2c_adapter *rtl2830_tuner_i2c;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300766 struct dvb_frontend *fe;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300767
Antti Palosaaric01a3592012-08-12 22:27:07 -0300768 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300769
770 /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300771 rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300772
773 switch (priv->tuner) {
774 case TUNER_RTL2830_QT1010:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300775 fe = dvb_attach(qt1010_attach, adap->fe[0],
Antti Palosaarifba16b12012-01-21 20:28:38 -0300776 rtl2830_tuner_i2c, &rtl28xxu_qt1010_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300777 break;
778 case TUNER_RTL2830_MT2060:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300779 fe = dvb_attach(mt2060_attach, adap->fe[0],
Antti Palosaarifba16b12012-01-21 20:28:38 -0300780 rtl2830_tuner_i2c, &rtl28xxu_mt2060_config,
781 1220);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300782 break;
783 case TUNER_RTL2830_MXL5005S:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300784 fe = dvb_attach(mxl5005s_attach, adap->fe[0],
Antti Palosaari9935eea2012-01-21 22:26:52 -0300785 rtl2830_tuner_i2c, &rtl28xxu_mxl5005s_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300786 break;
787 default:
Antti Palosaari9935eea2012-01-21 22:26:52 -0300788 fe = NULL;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300789 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
790 priv->tuner);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300791 }
792
793 if (fe == NULL) {
794 ret = -ENODEV;
795 goto err;
796 }
797
798 return 0;
799err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300800 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300801 return ret;
802}
803
Antti Palosaari542f6a52012-09-01 21:09:22 -0300804static const struct e4000_config rtl2832u_e4000_config = {
805 .i2c_addr = 0x64,
806 .clock = 28800000,
807};
808
Antti Palosaari384df492012-09-08 22:07:25 -0300809static const struct fc2580_config rtl2832u_fc2580_config = {
810 .i2c_addr = 0x56,
811 .clock = 16384000,
812};
813
Antti Palosaari5be65722012-09-11 22:27:09 -0300814static struct tua9001_config rtl2832u_tua9001_config = {
815 .i2c_addr = 0x60,
816};
817
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300818static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
819{
820 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300821 struct dvb_usb_device *d = adap_to_d(adap);
822 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari9935eea2012-01-21 22:26:52 -0300823 struct dvb_frontend *fe;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300824
Antti Palosaaric01a3592012-08-12 22:27:07 -0300825 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300826
827 switch (priv->tuner) {
Thomas Mair5cf66312012-05-18 14:47:41 -0300828 case TUNER_RTL2832_FC0012:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300829 fe = dvb_attach(fc0012_attach, adap->fe[0],
830 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -0300831
832 /* since fc0012 includs reading the signal strength delegate
833 * that to the tuner driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300834 adap->fe[0]->ops.read_signal_strength =
835 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Thomas Mair5cf66312012-05-18 14:47:41 -0300836 return 0;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300837 break;
Thomas Mair5cf66312012-05-18 14:47:41 -0300838 case TUNER_RTL2832_FC0013:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300839 fe = dvb_attach(fc0013_attach, adap->fe[0],
840 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -0300841
842 /* fc0013 also supports signal strength reading */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300843 adap->fe[0]->ops.read_signal_strength =
844 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Thomas Mair5cf66312012-05-18 14:47:41 -0300845 return 0;
Antti Palosaari542f6a52012-09-01 21:09:22 -0300846 case TUNER_RTL2832_E4000:
847 fe = dvb_attach(e4000_attach, adap->fe[0], &d->i2c_adap,
848 &rtl2832u_e4000_config);
849 break;
Antti Palosaari384df492012-09-08 22:07:25 -0300850 case TUNER_RTL2832_FC2580:
851 fe = dvb_attach(fc2580_attach, adap->fe[0], &d->i2c_adap,
852 &rtl2832u_fc2580_config);
853 break;
Antti Palosaari5be65722012-09-11 22:27:09 -0300854 case TUNER_RTL2832_TUA9001:
855 /* enable GPIO1 and GPIO4 as output */
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300856 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12);
857 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300858 goto err;
859
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300860 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12);
861 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300862 goto err;
863
864 fe = dvb_attach(tua9001_attach, adap->fe[0], &d->i2c_adap,
865 &rtl2832u_tua9001_config);
866 break;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300867 default:
Antti Palosaari9935eea2012-01-21 22:26:52 -0300868 fe = NULL;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300869 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
870 priv->tuner);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300871 }
872
873 if (fe == NULL) {
874 ret = -ENODEV;
875 goto err;
876 }
877
878 return 0;
879err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300880 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300881 return ret;
882}
883
Antti Palosaaric01a3592012-08-12 22:27:07 -0300884static int rtl28xxu_init(struct dvb_usb_device *d)
885{
886 int ret;
887 u8 val;
888
889 dev_dbg(&d->udev->dev, "%s:\n", __func__);
890
891 /* init USB endpoints */
892 ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val);
893 if (ret)
894 goto err;
895
896 /* enable DMA and Full Packet Mode*/
897 val |= 0x09;
898 ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val);
899 if (ret)
900 goto err;
901
902 /* set EPA maximum packet size to 0x0200 */
903 ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
904 if (ret)
905 goto err;
906
907 /* change EPA FIFO length */
908 ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
909 if (ret)
910 goto err;
911
912 return ret;
913err:
914 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
915 return ret;
916}
917
Thomas Mair5cf66312012-05-18 14:47:41 -0300918static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300919{
920 int ret;
Antti Palosaari8b036632012-09-01 09:54:43 -0300921 u8 gpio, sys0, epa_ctl[2];
Antti Palosaari831e0b72011-07-08 23:36:07 -0300922
Antti Palosaaric01a3592012-08-12 22:27:07 -0300923 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300924
925 /* demod adc */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300926 ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300927 if (ret)
928 goto err;
929
930 /* tuner power, read GPIOs */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300931 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300932 if (ret)
933 goto err;
934
Antti Palosaaric01a3592012-08-12 22:27:07 -0300935 dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
936 sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300937
938 if (onoff) {
939 gpio |= 0x01; /* GPIO0 = 1 */
940 gpio &= (~0x10); /* GPIO4 = 0 */
Antti Palosaari991452a2012-08-12 22:27:08 -0300941 gpio |= 0x04; /* GPIO2 = 1, LED on */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300942 sys0 = sys0 & 0x0f;
943 sys0 |= 0xe0;
Antti Palosaari8b036632012-09-01 09:54:43 -0300944 epa_ctl[0] = 0x00; /* clear stall */
945 epa_ctl[1] = 0x00; /* clear reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300946 } else {
Antti Palosaari831e0b72011-07-08 23:36:07 -0300947 gpio &= (~0x01); /* GPIO0 = 0 */
948 gpio |= 0x10; /* GPIO4 = 1 */
Antti Palosaari991452a2012-08-12 22:27:08 -0300949 gpio &= (~0x04); /* GPIO2 = 1, LED off */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300950 sys0 = sys0 & (~0xc0);
Antti Palosaari8b036632012-09-01 09:54:43 -0300951 epa_ctl[0] = 0x10; /* set stall */
952 epa_ctl[1] = 0x02; /* set reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300953 }
954
Antti Palosaaric01a3592012-08-12 22:27:07 -0300955 dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
956 sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300957
958 /* demod adc */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300959 ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300960 if (ret)
961 goto err;
962
963 /* tuner power, write GPIOs */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300964 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300965 if (ret)
966 goto err;
967
Antti Palosaari8b036632012-09-01 09:54:43 -0300968 /* streaming EP: stall & reset */
969 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, epa_ctl, 2);
970 if (ret)
971 goto err;
972
973 if (onoff)
974 usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
975
Antti Palosaari831e0b72011-07-08 23:36:07 -0300976 return ret;
977err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300978 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300979 return ret;
980}
981
Thomas Mair5cf66312012-05-18 14:47:41 -0300982static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
983{
984 int ret;
985 u8 val;
986
Antti Palosaaric01a3592012-08-12 22:27:07 -0300987 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Thomas Mair5cf66312012-05-18 14:47:41 -0300988
989 if (onoff) {
990 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300991 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300992 if (ret)
993 goto err;
994
995 val |= 0x08;
996 val &= 0xef;
997
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300998 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300999 if (ret)
1000 goto err;
1001
1002 /* demod_ctl_1 */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001003 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001004 if (ret)
1005 goto err;
1006
1007 val &= 0xef;
1008
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001009 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001010 if (ret)
1011 goto err;
1012
1013 /* demod control */
1014 /* PLL enable */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001015 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001016 if (ret)
1017 goto err;
1018
1019 /* bit 7 to 1 */
1020 val |= 0x80;
1021
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001022 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001023 if (ret)
1024 goto err;
1025
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001026 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001027 if (ret)
1028 goto err;
1029
1030 val |= 0x20;
1031
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001032 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001033 if (ret)
1034 goto err;
1035
1036 mdelay(5);
1037
1038 /*enable ADC_Q and ADC_I */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001039 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001040 if (ret)
1041 goto err;
1042
1043 val |= 0x48;
1044
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001045 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001046 if (ret)
1047 goto err;
1048
Antti Palosaari8b036632012-09-01 09:54:43 -03001049 /* streaming EP: clear stall & reset */
1050 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2);
1051 if (ret)
1052 goto err;
1053
1054 ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
1055 if (ret)
1056 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001057 } else {
1058 /* demod_ctl_1 */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001059 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001060 if (ret)
1061 goto err;
1062
1063 val |= 0x0c;
1064
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001065 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001066 if (ret)
1067 goto err;
1068
1069 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001070 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001071 if (ret)
1072 goto err;
1073
1074 val |= 0x10;
1075
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001076 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001077 if (ret)
1078 goto err;
1079
1080 /* demod control */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001081 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001082 if (ret)
1083 goto err;
1084
1085 val &= 0x37;
1086
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001087 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001088 if (ret)
1089 goto err;
1090
Antti Palosaari8b036632012-09-01 09:54:43 -03001091 /* streaming EP: set stall & reset */
1092 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2);
1093 if (ret)
1094 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001095 }
1096
1097 return ret;
1098err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001099 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -03001100 return ret;
1101}
1102
1103
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001104static int rtl2831u_rc_query(struct dvb_usb_device *d)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001105{
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001106 int ret, i;
1107 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -03001108 u8 buf[5];
1109 u32 rc_code;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001110 struct rtl28xxu_reg_val rc_nec_tab[] = {
1111 { 0x3033, 0x80 },
1112 { 0x3020, 0x43 },
1113 { 0x3021, 0x16 },
1114 { 0x3022, 0x16 },
1115 { 0x3023, 0x5a },
1116 { 0x3024, 0x2d },
1117 { 0x3025, 0x16 },
1118 { 0x3026, 0x01 },
1119 { 0x3028, 0xb0 },
1120 { 0x3029, 0x04 },
1121 { 0x302c, 0x88 },
1122 { 0x302e, 0x13 },
1123 { 0x3030, 0xdf },
1124 { 0x3031, 0x05 },
1125 };
1126
1127 /* init remote controller */
1128 if (!priv->rc_active) {
1129 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001130 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001131 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001132 if (ret)
1133 goto err;
1134 }
1135 priv->rc_active = true;
1136 }
Antti Palosaari831e0b72011-07-08 23:36:07 -03001137
1138 ret = rtl2831_rd_regs(d, SYS_IRRC_RP, buf, 5);
1139 if (ret)
1140 goto err;
1141
1142 if (buf[4] & 0x01) {
1143 if (buf[2] == (u8) ~buf[3]) {
1144 if (buf[0] == (u8) ~buf[1]) {
1145 /* NEC standard (16 bit) */
1146 rc_code = buf[0] << 8 | buf[2];
1147 } else {
1148 /* NEC extended (24 bit) */
1149 rc_code = buf[0] << 16 |
Antti Palosaari9935eea2012-01-21 22:26:52 -03001150 buf[1] << 8 | buf[2];
Antti Palosaari831e0b72011-07-08 23:36:07 -03001151 }
1152 } else {
1153 /* NEC full (32 bit) */
1154 rc_code = buf[0] << 24 | buf[1] << 16 |
1155 buf[2] << 8 | buf[3];
1156 }
1157
1158 rc_keydown(d->rc_dev, rc_code, 0);
1159
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001160 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001161 if (ret)
1162 goto err;
1163
1164 /* repeated intentionally to avoid extra keypress */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001165 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001166 if (ret)
1167 goto err;
1168 }
1169
1170 return ret;
1171err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001172 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001173 return ret;
1174}
1175
Antti Palosaaric01a3592012-08-12 22:27:07 -03001176static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
1177 struct dvb_usb_rc *rc)
1178{
1179 rc->map_name = RC_MAP_EMPTY;
1180 rc->allowed_protos = RC_TYPE_NEC;
1181 rc->query = rtl2831u_rc_query;
1182 rc->interval = 400;
1183
1184 return 0;
1185}
1186
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001187static int rtl2832u_rc_query(struct dvb_usb_device *d)
1188{
1189 int ret, i;
1190 struct rtl28xxu_priv *priv = d->priv;
1191 u8 buf[128];
1192 int len;
1193 struct rtl28xxu_reg_val rc_nec_tab[] = {
Antti Palosaari9935eea2012-01-21 22:26:52 -03001194 { IR_RX_CTRL, 0x20 },
1195 { IR_RX_BUF_CTRL, 0x80 },
1196 { IR_RX_IF, 0xff },
1197 { IR_RX_IE, 0xff },
1198 { IR_MAX_DURATION0, 0xd0 },
1199 { IR_MAX_DURATION1, 0x07 },
1200 { IR_IDLE_LEN0, 0xc0 },
1201 { IR_IDLE_LEN1, 0x00 },
1202 { IR_GLITCH_LEN, 0x03 },
1203 { IR_RX_CLK, 0x09 },
1204 { IR_RX_CFG, 0x1c },
1205 { IR_MAX_H_TOL_LEN, 0x1e },
1206 { IR_MAX_L_TOL_LEN, 0x1e },
1207 { IR_RX_CTRL, 0x80 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001208 };
1209
1210 /* init remote controller */
1211 if (!priv->rc_active) {
1212 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001213 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001214 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001215 if (ret)
1216 goto err;
1217 }
1218 priv->rc_active = true;
1219 }
1220
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001221 ret = rtl28xx_rd_reg(d, IR_RX_IF, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001222 if (ret)
1223 goto err;
1224
1225 if (buf[0] != 0x83)
1226 goto exit;
1227
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001228 ret = rtl28xx_rd_reg(d, IR_RX_BC, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001229 if (ret)
1230 goto err;
1231
1232 len = buf[0];
1233 ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len);
1234
1235 /* TODO: pass raw IR to Kernel IR decoder */
1236
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001237 ret = rtl28xx_wr_reg(d, IR_RX_IF, 0x03);
1238 ret = rtl28xx_wr_reg(d, IR_RX_BUF_CTRL, 0x80);
1239 ret = rtl28xx_wr_reg(d, IR_RX_CTRL, 0x80);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001240
1241exit:
1242 return ret;
1243err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001244 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001245 return ret;
1246}
1247
Antti Palosaaric01a3592012-08-12 22:27:07 -03001248static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1249 struct dvb_usb_rc *rc)
1250{
1251 rc->map_name = RC_MAP_EMPTY;
1252 rc->allowed_protos = RC_TYPE_NEC;
1253 rc->query = rtl2832u_rc_query;
1254 rc->interval = 400;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001255
Antti Palosaaric01a3592012-08-12 22:27:07 -03001256 return 0;
1257}
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001258
Antti Palosaaric01a3592012-08-12 22:27:07 -03001259static const struct dvb_usb_device_properties rtl2831u_props = {
1260 .driver_name = KBUILD_MODNAME,
1261 .owner = THIS_MODULE,
1262 .adapter_nr = adapter_nr,
1263 .size_of_priv = sizeof(struct rtl28xxu_priv),
Antti Palosaari831e0b72011-07-08 23:36:07 -03001264
Antti Palosaaric01a3592012-08-12 22:27:07 -03001265 .power_ctrl = rtl2831u_power_ctrl,
1266 .i2c_algo = &rtl28xxu_i2c_algo,
1267 .frontend_attach = rtl2831u_frontend_attach,
1268 .tuner_attach = rtl2831u_tuner_attach,
1269 .init = rtl28xxu_init,
1270 .get_rc_config = rtl2831u_get_rc_config,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001271
Antti Palosaaric01a3592012-08-12 22:27:07 -03001272 .num_adapters = 1,
1273 .adapter = {
1274 {
1275 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaari831e0b72011-07-08 23:36:07 -03001276 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001277 },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001278};
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001279
Antti Palosaaric01a3592012-08-12 22:27:07 -03001280static const struct dvb_usb_device_properties rtl2832u_props = {
1281 .driver_name = KBUILD_MODNAME,
1282 .owner = THIS_MODULE,
1283 .adapter_nr = adapter_nr,
1284 .size_of_priv = sizeof(struct rtl28xxu_priv),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001285
Antti Palosaaric01a3592012-08-12 22:27:07 -03001286 .power_ctrl = rtl2832u_power_ctrl,
1287 .i2c_algo = &rtl28xxu_i2c_algo,
Antti Palosaarief37be12012-09-17 14:01:35 -03001288 .read_config = rtl2832u_read_config,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001289 .frontend_attach = rtl2832u_frontend_attach,
1290 .tuner_attach = rtl2832u_tuner_attach,
1291 .init = rtl28xxu_init,
1292 .get_rc_config = rtl2832u_get_rc_config,
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001293
Antti Palosaaric01a3592012-08-12 22:27:07 -03001294 .num_adapters = 1,
1295 .adapter = {
1296 {
1297 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001298 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001299 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001300};
1301
Antti Palosaaric01a3592012-08-12 22:27:07 -03001302static const struct usb_device_id rtl28xxu_id_table[] = {
1303 { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U,
1304 &rtl2831u_props, "Realtek RTL2831U reference design", NULL) },
1305 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT,
1306 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
1307 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2,
1308 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001309
Antti Palosaari254ee2e2012-09-18 10:27:05 -03001310 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832,
1311 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
1312 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
1313 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001314 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
1315 &rtl2832u_props, "Terratec Cinergy T Stick Black", NULL) },
1316 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
1317 &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
1318 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
1319 &rtl2832u_props, "NOXON DAB/DAB+ USB dongle", NULL) },
Philipp Dreimann6d608052012-09-02 19:30:54 -03001320 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0,
1321 &rtl2832u_props, "Trekstor DVB-T Stick Terres 2.0", NULL) },
Antti Palosaaric2d246d12012-09-08 22:07:26 -03001322 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101,
1323 &rtl2832u_props, "Dexatek DK DVB-T Dongle", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001324 { }
1325};
1326MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001327
Antti Palosaaric01a3592012-08-12 22:27:07 -03001328static struct usb_driver rtl28xxu_usb_driver = {
1329 .name = KBUILD_MODNAME,
1330 .id_table = rtl28xxu_id_table,
1331 .probe = dvb_usbv2_probe,
1332 .disconnect = dvb_usbv2_disconnect,
1333 .suspend = dvb_usbv2_suspend,
1334 .resume = dvb_usbv2_resume,
Antti Palosaari78fa5902012-08-14 22:21:09 -03001335 .reset_resume = dvb_usbv2_reset_resume,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001336 .no_dynamic_id = 1,
1337 .soft_unbind = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001338};
1339
Antti Palosaaric01a3592012-08-12 22:27:07 -03001340module_usb_driver(rtl28xxu_usb_driver);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001341
1342MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
1343MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
Thomas Mair5cf66312012-05-18 14:47:41 -03001344MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>");
Antti Palosaari831e0b72011-07-08 23:36:07 -03001345MODULE_LICENSE("GPL");