blob: 5eabeacccbc1abe7a111f9fe86798821cda58639 [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
133/* I2C */
134static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
135 int num)
136{
137 int ret;
138 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300139 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300140 struct rtl28xxu_req req;
141
142 /*
143 * It is not known which are real I2C bus xfer limits, but testing
144 * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes.
Antti Palosaari34ec2932011-08-04 20:21:16 -0300145 * TODO: find out RTL2832U lens
146 */
147
148 /*
149 * I2C adapter logic looks rather complicated due to fact it handles
150 * three different access methods. Those methods are;
151 * 1) integrated demod access
152 * 2) old I2C access
153 * 3) new I2C access
154 *
155 * Used method is selected in order 1, 2, 3. Method 3 can handle all
156 * requests but there is two reasons why not use it always;
157 * 1) It is most expensive, usually two USB messages are needed
158 * 2) At least RTL2831U does not support it
159 *
160 * Method 3 is needed in case of I2C write+read (typical register read)
161 * where write is more than one byte.
Antti Palosaari831e0b72011-07-08 23:36:07 -0300162 */
163
164 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
165 return -EAGAIN;
166
167 if (num == 2 && !(msg[0].flags & I2C_M_RD) &&
168 (msg[1].flags & I2C_M_RD)) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300169 if (msg[0].len > 24 || msg[1].len > 24) {
170 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300171 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300172 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300173 } else if (msg[0].addr == 0x10) {
174 /* method 1 - integrated demod */
175 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
176 req.index = CMD_DEMOD_RD | priv->page;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300177 req.size = msg[1].len;
178 req.data = &msg[1].buf[0];
179 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300180 } else if (msg[0].len < 2) {
181 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300182 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
183 req.index = CMD_I2C_RD;
184 req.size = msg[1].len;
185 req.data = &msg[1].buf[0];
186 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300187 } else {
188 /* method 3 - new I2C */
189 req.value = (msg[0].addr << 1);
190 req.index = CMD_I2C_DA_WR;
191 req.size = msg[0].len;
192 req.data = msg[0].buf;
193 ret = rtl28xxu_ctrl_msg(d, &req);
194 if (ret)
Antti Palosaari9935eea2012-01-21 22:26:52 -0300195 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300196
197 req.value = (msg[0].addr << 1);
198 req.index = CMD_I2C_DA_RD;
199 req.size = msg[1].len;
200 req.data = msg[1].buf;
201 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300202 }
203 } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
204 if (msg[0].len > 22) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300205 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300206 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300207 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300208 } else if (msg[0].addr == 0x10) {
209 /* method 1 - integrated demod */
210 if (msg[0].buf[0] == 0x00) {
211 /* save demod page for later demod access */
212 priv->page = msg[0].buf[1];
213 ret = 0;
214 } else {
215 req.value = (msg[0].buf[0] << 8) |
216 (msg[0].addr << 1);
217 req.index = CMD_DEMOD_WR | priv->page;
218 req.size = msg[0].len-1;
219 req.data = &msg[0].buf[1];
220 ret = rtl28xxu_ctrl_msg(d, &req);
221 }
222 } else if (msg[0].len < 23) {
223 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300224 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
225 req.index = CMD_I2C_WR;
226 req.size = msg[0].len-1;
227 req.data = &msg[0].buf[1];
228 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300229 } else {
230 /* method 3 - new I2C */
231 req.value = (msg[0].addr << 1);
232 req.index = CMD_I2C_DA_WR;
233 req.size = msg[0].len;
234 req.data = msg[0].buf;
235 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300236 }
237 } else {
238 ret = -EINVAL;
239 }
240
Antti Palosaari9935eea2012-01-21 22:26:52 -0300241err_mutex_unlock:
Antti Palosaari831e0b72011-07-08 23:36:07 -0300242 mutex_unlock(&d->i2c_mutex);
243
244 return ret ? ret : num;
245}
246
247static u32 rtl28xxu_i2c_func(struct i2c_adapter *adapter)
248{
249 return I2C_FUNC_I2C;
250}
251
252static struct i2c_algorithm rtl28xxu_i2c_algo = {
253 .master_xfer = rtl28xxu_i2c_xfer,
254 .functionality = rtl28xxu_i2c_func,
255};
256
Antti Palosaarief37be12012-09-17 14:01:35 -0300257static int rtl2832u_read_config(struct dvb_usb_device *d)
258{
259 struct rtl28xxu_priv *priv = d_to_priv(d);
260 int ret;
261 u8 buf[2], val;
262 /* open RTL2832U/RTL2832 I2C gate */
263 struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"};
264 /* close RTL2832U/RTL2832 I2C gate */
265 struct rtl28xxu_req req_gate_close = {0x0120, 0x0011, 0x0001, "\x10"};
266 /* tuner probes */
267 struct rtl28xxu_req req_fc0012 = {0x00c6, CMD_I2C_RD, 1, buf};
268 struct rtl28xxu_req req_fc0013 = {0x00c6, CMD_I2C_RD, 1, buf};
269 struct rtl28xxu_req req_mt2266 = {0x00c0, CMD_I2C_RD, 1, buf};
270 struct rtl28xxu_req req_fc2580 = {0x01ac, CMD_I2C_RD, 1, buf};
271 struct rtl28xxu_req req_mt2063 = {0x00c0, CMD_I2C_RD, 1, buf};
272 struct rtl28xxu_req req_max3543 = {0x00c0, CMD_I2C_RD, 1, buf};
273 struct rtl28xxu_req req_tua9001 = {0x7ec0, CMD_I2C_RD, 2, buf};
274 struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf};
275 struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
276 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
277
278 dev_dbg(&d->udev->dev, "%s:\n", __func__);
279
280 ret = rtl28xx_rd_reg(d, SYS_GPIO_DIR, &val);
281 if (ret)
282 goto err;
283
284 val &= 0xbf;
285
286 ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, val);
287 if (ret)
288 goto err;
289
290 /* enable as output GPIO3 and GPIO6 */
291 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_EN, &val);
292 if (ret)
293 goto err;
294
295 val |= 0x48;
296
297 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, val);
298 if (ret)
299 goto err;
300
301 /*
302 * Probe used tuner. We need to know used tuner before demod attach
303 * since there is some demod params needed to set according to tuner.
304 */
305
306 /* open demod I2C gate */
307 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
308 if (ret)
309 goto err;
310
311 priv->tuner_name = "NONE";
312
313 /* check FC0012 ID register; reg=00 val=a1 */
314 ret = rtl28xxu_ctrl_msg(d, &req_fc0012);
315 if (ret == 0 && buf[0] == 0xa1) {
316 priv->tuner = TUNER_RTL2832_FC0012;
317 priv->tuner_name = "FC0012";
318 goto found;
319 }
320
321 /* check FC0013 ID register; reg=00 val=a3 */
322 ret = rtl28xxu_ctrl_msg(d, &req_fc0013);
323 if (ret == 0 && buf[0] == 0xa3) {
324 priv->tuner = TUNER_RTL2832_FC0013;
325 priv->tuner_name = "FC0013";
326 goto found;
327 }
328
329 /* check MT2266 ID register; reg=00 val=85 */
330 ret = rtl28xxu_ctrl_msg(d, &req_mt2266);
331 if (ret == 0 && buf[0] == 0x85) {
332 priv->tuner = TUNER_RTL2832_MT2266;
333 priv->tuner_name = "MT2266";
334 goto found;
335 }
336
337 /* check FC2580 ID register; reg=01 val=56 */
338 ret = rtl28xxu_ctrl_msg(d, &req_fc2580);
339 if (ret == 0 && buf[0] == 0x56) {
340 priv->tuner = TUNER_RTL2832_FC2580;
341 priv->tuner_name = "FC2580";
342 goto found;
343 }
344
345 /* check MT2063 ID register; reg=00 val=9e || 9c */
346 ret = rtl28xxu_ctrl_msg(d, &req_mt2063);
347 if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) {
348 priv->tuner = TUNER_RTL2832_MT2063;
349 priv->tuner_name = "MT2063";
350 goto found;
351 }
352
353 /* check MAX3543 ID register; reg=00 val=38 */
354 ret = rtl28xxu_ctrl_msg(d, &req_max3543);
355 if (ret == 0 && buf[0] == 0x38) {
356 priv->tuner = TUNER_RTL2832_MAX3543;
357 priv->tuner_name = "MAX3543";
358 goto found;
359 }
360
361 /* check TUA9001 ID register; reg=7e val=2328 */
362 ret = rtl28xxu_ctrl_msg(d, &req_tua9001);
363 if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) {
364 priv->tuner = TUNER_RTL2832_TUA9001;
365 priv->tuner_name = "TUA9001";
366 goto found;
367 }
368
369 /* check MXL5007R ID register; reg=d9 val=14 */
370 ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t);
371 if (ret == 0 && buf[0] == 0x14) {
372 priv->tuner = TUNER_RTL2832_MXL5007T;
373 priv->tuner_name = "MXL5007T";
374 goto found;
375 }
376
377 /* check E4000 ID register; reg=02 val=40 */
378 ret = rtl28xxu_ctrl_msg(d, &req_e4000);
379 if (ret == 0 && buf[0] == 0x40) {
380 priv->tuner = TUNER_RTL2832_E4000;
381 priv->tuner_name = "E4000";
382 goto found;
383 }
384
385 /* check TDA18272 ID register; reg=00 val=c760 */
386 ret = rtl28xxu_ctrl_msg(d, &req_tda18272);
387 if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) {
388 priv->tuner = TUNER_RTL2832_TDA18272;
389 priv->tuner_name = "TDA18272";
390 goto found;
391 }
392
393found:
394 dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name);
395
396 /* close demod I2C gate */
397 ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
398 if (ret < 0)
399 goto err;
400
401 return 0;
402err:
403 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
404 return ret;
405}
406
Antti Palosaari831e0b72011-07-08 23:36:07 -0300407static struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = {
408 .i2c_addr = 0x10, /* 0x20 */
409 .xtal = 28800000,
410 .ts_mode = 0,
411 .spec_inv = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300412 .vtop = 0x20,
413 .krf = 0x04,
414 .agc_targ_val = 0x2d,
415
416};
417
418static struct rtl2830_config rtl28xxu_rtl2830_qt1010_config = {
419 .i2c_addr = 0x10, /* 0x20 */
420 .xtal = 28800000,
421 .ts_mode = 0,
422 .spec_inv = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300423 .vtop = 0x20,
424 .krf = 0x04,
425 .agc_targ_val = 0x2d,
426};
427
428static struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = {
429 .i2c_addr = 0x10, /* 0x20 */
430 .xtal = 28800000,
431 .ts_mode = 0,
432 .spec_inv = 0,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300433 .vtop = 0x3f,
434 .krf = 0x04,
435 .agc_targ_val = 0x3e,
436};
437
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300438static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300439{
440 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300441 struct dvb_usb_device *d = adap_to_d(adap);
442 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300443 u8 buf[1];
444 struct rtl2830_config *rtl2830_config;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300445 /* open RTL2831U/RTL2830 I2C gate */
Antti Palosaari9935eea2012-01-21 22:26:52 -0300446 struct rtl28xxu_req req_gate = { 0x0120, 0x0011, 0x0001, "\x08" };
Antti Palosaari831e0b72011-07-08 23:36:07 -0300447 /* for MT2060 tuner probe */
Antti Palosaari9935eea2012-01-21 22:26:52 -0300448 struct rtl28xxu_req req_mt2060 = { 0x00c0, CMD_I2C_RD, 1, buf };
Antti Palosaari831e0b72011-07-08 23:36:07 -0300449 /* for QT1010 tuner probe */
Antti Palosaari9935eea2012-01-21 22:26:52 -0300450 struct rtl28xxu_req req_qt1010 = { 0x0fc4, CMD_I2C_RD, 1, buf };
Antti Palosaari831e0b72011-07-08 23:36:07 -0300451
Antti Palosaaric01a3592012-08-12 22:27:07 -0300452 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300453
454 /*
455 * RTL2831U GPIOs
456 * =========================================================
457 * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?)
458 * GPIO2 | LED | 0 off | 1 on |
459 * GPIO4 | tuner#1 | 0 on | 1 off | MT2060
460 */
461
462 /* GPIO direction */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300463 ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, 0x0a);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300464 if (ret)
465 goto err;
466
467 /* enable as output GPIO0, GPIO2, GPIO4 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300468 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, 0x15);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300469 if (ret)
470 goto err;
471
472 /*
473 * Probe used tuner. We need to know used tuner before demod attach
474 * since there is some demod params needed to set according to tuner.
475 */
476
Antti Palosaariccb5cf92012-05-18 16:07:46 -0300477 /* demod needs some time to wake up */
478 msleep(20);
479
Antti Palosaari831e0b72011-07-08 23:36:07 -0300480 /* open demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300481 ret = rtl28xxu_ctrl_msg(d, &req_gate);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300482 if (ret)
483 goto err;
484
485 /* check QT1010 ID(?) register; reg=0f val=2c */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300486 ret = rtl28xxu_ctrl_msg(d, &req_qt1010);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300487 if (ret == 0 && buf[0] == 0x2c) {
488 priv->tuner = TUNER_RTL2830_QT1010;
489 rtl2830_config = &rtl28xxu_rtl2830_qt1010_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300490 dev_dbg(&d->udev->dev, "%s: QT1010\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300491 goto found;
492 } else {
Antti Palosaaric01a3592012-08-12 22:27:07 -0300493 dev_dbg(&d->udev->dev, "%s: QT1010 probe failed=%d - %02x\n",
494 __func__, ret, buf[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300495 }
496
497 /* open demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300498 ret = rtl28xxu_ctrl_msg(d, &req_gate);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300499 if (ret)
500 goto err;
501
502 /* check MT2060 ID register; reg=00 val=63 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300503 ret = rtl28xxu_ctrl_msg(d, &req_mt2060);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300504 if (ret == 0 && buf[0] == 0x63) {
505 priv->tuner = TUNER_RTL2830_MT2060;
506 rtl2830_config = &rtl28xxu_rtl2830_mt2060_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300507 dev_dbg(&d->udev->dev, "%s: MT2060\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300508 goto found;
509 } else {
Antti Palosaaric01a3592012-08-12 22:27:07 -0300510 dev_dbg(&d->udev->dev, "%s: MT2060 probe failed=%d - %02x\n",
511 __func__, ret, buf[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300512 }
513
514 /* assume MXL5005S */
Antti Palosaarie9320ec2011-08-03 04:35:30 -0300515 ret = 0;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300516 priv->tuner = TUNER_RTL2830_MXL5005S;
517 rtl2830_config = &rtl28xxu_rtl2830_mxl5005s_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300518 dev_dbg(&d->udev->dev, "%s: MXL5005S\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300519 goto found;
520
521found:
522 /* attach demodulator */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300523 adap->fe[0] = dvb_attach(rtl2830_attach, rtl2830_config,
524 &d->i2c_adap);
525 if (adap->fe[0] == NULL) {
Antti Palosaari831e0b72011-07-08 23:36:07 -0300526 ret = -ENODEV;
527 goto err;
528 }
529
530 return ret;
531err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300532 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300533 return ret;
534}
535
Thomas Mair5cf66312012-05-18 14:47:41 -0300536static struct rtl2832_config rtl28xxu_rtl2832_fc0012_config = {
537 .i2c_addr = 0x10, /* 0x20 */
538 .xtal = 28800000,
539 .if_dvbt = 0,
540 .tuner = TUNER_RTL2832_FC0012
541};
542
543static struct rtl2832_config rtl28xxu_rtl2832_fc0013_config = {
544 .i2c_addr = 0x10, /* 0x20 */
545 .xtal = 28800000,
546 .if_dvbt = 0,
547 .tuner = TUNER_RTL2832_FC0013
548};
549
Antti Palosaari5be65722012-09-11 22:27:09 -0300550static struct rtl2832_config rtl28xxu_rtl2832_tua9001_config = {
551 .i2c_addr = 0x10, /* 0x20 */
552 .xtal = 28800000,
553 .tuner = TUNER_RTL2832_TUA9001,
554};
555
Thomas Mair5cf66312012-05-18 14:47:41 -0300556static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
557 int cmd, int arg)
558{
559 int ret;
560 u8 val;
561
Antti Palosaaric01a3592012-08-12 22:27:07 -0300562 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
563
Thomas Mair5cf66312012-05-18 14:47:41 -0300564 switch (cmd) {
565 case FC_FE_CALLBACK_VHF_ENABLE:
566 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300567 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300568 if (ret)
569 goto err;
570
571 if (arg)
572 val &= 0xbf; /* set GPIO6 low */
573 else
574 val |= 0x40; /* set GPIO6 high */
575
576
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300577 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300578 if (ret)
579 goto err;
580 break;
581 default:
582 ret = -EINVAL;
583 goto err;
584 }
585 return 0;
586
587err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300588 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -0300589 return ret;
590}
591
592
593static int rtl2832u_fc0013_tuner_callback(struct dvb_usb_device *d,
594 int cmd, int arg)
595{
596 /* TODO implement*/
597 return 0;
598}
599
Antti Palosaari5be65722012-09-11 22:27:09 -0300600static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d,
601 int cmd, int arg)
602{
603 int ret;
604 u8 val;
605
606 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
607
608 /*
609 * CEN always enabled by hardware wiring
610 * RESETN GPIO4
611 * RXEN GPIO1
612 */
613
614 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
615 if (ret < 0)
616 goto err;
617
618 switch (cmd) {
619 case TUA9001_CMD_RESETN:
620 if (arg)
621 val |= (1 << 4);
622 else
623 val &= ~(1 << 4);
624
625 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
626 if (ret < 0)
627 goto err;
628 break;
629 case TUA9001_CMD_RXEN:
630 if (arg)
631 val |= (1 << 1);
632 else
633 val &= ~(1 << 1);
634
635 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
636 if (ret < 0)
637 goto err;
638 break;
639 }
640
641 return 0;
642
643err:
644 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
645 return ret;
646}
647
Thomas Mair5cf66312012-05-18 14:47:41 -0300648static int rtl2832u_tuner_callback(struct dvb_usb_device *d, int cmd, int arg)
649{
650 struct rtl28xxu_priv *priv = d->priv;
651
652 switch (priv->tuner) {
653 case TUNER_RTL2832_FC0012:
654 return rtl2832u_fc0012_tuner_callback(d, cmd, arg);
655
656 case TUNER_RTL2832_FC0013:
657 return rtl2832u_fc0013_tuner_callback(d, cmd, arg);
Antti Palosaari5be65722012-09-11 22:27:09 -0300658
659 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
665 return -ENODEV;
666}
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
681 return -EINVAL;
682}
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 Palosaari5be65722012-09-11 22:27:09 -0300824 u8 val;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300825
Antti Palosaaric01a3592012-08-12 22:27:07 -0300826 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300827
828 switch (priv->tuner) {
Thomas Mair5cf66312012-05-18 14:47:41 -0300829 case TUNER_RTL2832_FC0012:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300830 fe = dvb_attach(fc0012_attach, adap->fe[0],
831 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -0300832
833 /* since fc0012 includs reading the signal strength delegate
834 * that to the tuner driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300835 adap->fe[0]->ops.read_signal_strength =
836 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Thomas Mair5cf66312012-05-18 14:47:41 -0300837 return 0;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300838 break;
Thomas Mair5cf66312012-05-18 14:47:41 -0300839 case TUNER_RTL2832_FC0013:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300840 fe = dvb_attach(fc0013_attach, adap->fe[0],
841 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -0300842
843 /* fc0013 also supports signal strength reading */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300844 adap->fe[0]->ops.read_signal_strength =
845 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Thomas Mair5cf66312012-05-18 14:47:41 -0300846 return 0;
Antti Palosaari542f6a52012-09-01 21:09:22 -0300847 case TUNER_RTL2832_E4000:
848 fe = dvb_attach(e4000_attach, adap->fe[0], &d->i2c_adap,
849 &rtl2832u_e4000_config);
850 break;
Antti Palosaari384df492012-09-08 22:07:25 -0300851 case TUNER_RTL2832_FC2580:
852 fe = dvb_attach(fc2580_attach, adap->fe[0], &d->i2c_adap,
853 &rtl2832u_fc2580_config);
854 break;
Antti Palosaari5be65722012-09-11 22:27:09 -0300855 case TUNER_RTL2832_TUA9001:
856 /* enable GPIO1 and GPIO4 as output */
857 ret = rtl28xx_rd_reg(d, SYS_GPIO_DIR, &val);
858 if (ret < 0)
859 goto err;
860
861 val &= ~(1 << 1);
862 val &= ~(1 << 4);
863
864 ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, val);
865 if (ret < 0)
866 goto err;
867
868 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_EN, &val);
869 if (ret < 0)
870 goto err;
871
872 val |= (1 << 1);
873 val |= (1 << 4);
874
875 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, val);
876 if (ret < 0)
877 goto err;
878
879 fe = dvb_attach(tua9001_attach, adap->fe[0], &d->i2c_adap,
880 &rtl2832u_tua9001_config);
881 break;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300882 default:
Antti Palosaari9935eea2012-01-21 22:26:52 -0300883 fe = NULL;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300884 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
885 priv->tuner);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300886 }
887
888 if (fe == NULL) {
889 ret = -ENODEV;
890 goto err;
891 }
892
893 return 0;
894err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300895 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300896 return ret;
897}
898
Antti Palosaaric01a3592012-08-12 22:27:07 -0300899static int rtl28xxu_init(struct dvb_usb_device *d)
900{
901 int ret;
902 u8 val;
903
904 dev_dbg(&d->udev->dev, "%s:\n", __func__);
905
906 /* init USB endpoints */
907 ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val);
908 if (ret)
909 goto err;
910
911 /* enable DMA and Full Packet Mode*/
912 val |= 0x09;
913 ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val);
914 if (ret)
915 goto err;
916
917 /* set EPA maximum packet size to 0x0200 */
918 ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
919 if (ret)
920 goto err;
921
922 /* change EPA FIFO length */
923 ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
924 if (ret)
925 goto err;
926
927 return ret;
928err:
929 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
930 return ret;
931}
932
Thomas Mair5cf66312012-05-18 14:47:41 -0300933static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300934{
935 int ret;
Antti Palosaari8b036632012-09-01 09:54:43 -0300936 u8 gpio, sys0, epa_ctl[2];
Antti Palosaari831e0b72011-07-08 23:36:07 -0300937
Antti Palosaaric01a3592012-08-12 22:27:07 -0300938 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300939
940 /* demod adc */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300941 ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300942 if (ret)
943 goto err;
944
945 /* tuner power, read GPIOs */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300946 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300947 if (ret)
948 goto err;
949
Antti Palosaaric01a3592012-08-12 22:27:07 -0300950 dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
951 sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300952
953 if (onoff) {
954 gpio |= 0x01; /* GPIO0 = 1 */
955 gpio &= (~0x10); /* GPIO4 = 0 */
Antti Palosaari991452a2012-08-12 22:27:08 -0300956 gpio |= 0x04; /* GPIO2 = 1, LED on */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300957 sys0 = sys0 & 0x0f;
958 sys0 |= 0xe0;
Antti Palosaari8b036632012-09-01 09:54:43 -0300959 epa_ctl[0] = 0x00; /* clear stall */
960 epa_ctl[1] = 0x00; /* clear reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300961 } else {
Antti Palosaari831e0b72011-07-08 23:36:07 -0300962 gpio &= (~0x01); /* GPIO0 = 0 */
963 gpio |= 0x10; /* GPIO4 = 1 */
Antti Palosaari991452a2012-08-12 22:27:08 -0300964 gpio &= (~0x04); /* GPIO2 = 1, LED off */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300965 sys0 = sys0 & (~0xc0);
Antti Palosaari8b036632012-09-01 09:54:43 -0300966 epa_ctl[0] = 0x10; /* set stall */
967 epa_ctl[1] = 0x02; /* set reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300968 }
969
Antti Palosaaric01a3592012-08-12 22:27:07 -0300970 dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
971 sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300972
973 /* demod adc */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300974 ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300975 if (ret)
976 goto err;
977
978 /* tuner power, write GPIOs */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300979 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300980 if (ret)
981 goto err;
982
Antti Palosaari8b036632012-09-01 09:54:43 -0300983 /* streaming EP: stall & reset */
984 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, epa_ctl, 2);
985 if (ret)
986 goto err;
987
988 if (onoff)
989 usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
990
Antti Palosaari831e0b72011-07-08 23:36:07 -0300991 return ret;
992err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300993 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300994 return ret;
995}
996
Thomas Mair5cf66312012-05-18 14:47:41 -0300997static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
998{
999 int ret;
1000 u8 val;
1001
Antti Palosaaric01a3592012-08-12 22:27:07 -03001002 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Thomas Mair5cf66312012-05-18 14:47:41 -03001003
1004 if (onoff) {
1005 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001006 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001007 if (ret)
1008 goto err;
1009
1010 val |= 0x08;
1011 val &= 0xef;
1012
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001013 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001014 if (ret)
1015 goto err;
1016
1017 /* demod_ctl_1 */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001018 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001019 if (ret)
1020 goto err;
1021
1022 val &= 0xef;
1023
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001024 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001025 if (ret)
1026 goto err;
1027
1028 /* demod control */
1029 /* PLL enable */
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 /* bit 7 to 1 */
1035 val |= 0x80;
1036
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001037 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001038 if (ret)
1039 goto err;
1040
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001041 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001042 if (ret)
1043 goto err;
1044
1045 val |= 0x20;
1046
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001047 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001048 if (ret)
1049 goto err;
1050
1051 mdelay(5);
1052
1053 /*enable ADC_Q and ADC_I */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001054 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001055 if (ret)
1056 goto err;
1057
1058 val |= 0x48;
1059
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001060 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001061 if (ret)
1062 goto err;
1063
Antti Palosaari8b036632012-09-01 09:54:43 -03001064 /* streaming EP: clear stall & reset */
1065 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2);
1066 if (ret)
1067 goto err;
1068
1069 ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
1070 if (ret)
1071 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001072 } else {
1073 /* demod_ctl_1 */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001074 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001075 if (ret)
1076 goto err;
1077
1078 val |= 0x0c;
1079
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001080 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001081 if (ret)
1082 goto err;
1083
1084 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001085 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001086 if (ret)
1087 goto err;
1088
1089 val |= 0x10;
1090
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001091 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001092 if (ret)
1093 goto err;
1094
1095 /* demod control */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001096 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001097 if (ret)
1098 goto err;
1099
1100 val &= 0x37;
1101
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001102 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001103 if (ret)
1104 goto err;
1105
Antti Palosaari8b036632012-09-01 09:54:43 -03001106 /* streaming EP: set stall & reset */
1107 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2);
1108 if (ret)
1109 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001110 }
1111
1112 return ret;
1113err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001114 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -03001115 return ret;
1116}
1117
1118
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001119static int rtl2831u_rc_query(struct dvb_usb_device *d)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001120{
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001121 int ret, i;
1122 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -03001123 u8 buf[5];
1124 u32 rc_code;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001125 struct rtl28xxu_reg_val rc_nec_tab[] = {
1126 { 0x3033, 0x80 },
1127 { 0x3020, 0x43 },
1128 { 0x3021, 0x16 },
1129 { 0x3022, 0x16 },
1130 { 0x3023, 0x5a },
1131 { 0x3024, 0x2d },
1132 { 0x3025, 0x16 },
1133 { 0x3026, 0x01 },
1134 { 0x3028, 0xb0 },
1135 { 0x3029, 0x04 },
1136 { 0x302c, 0x88 },
1137 { 0x302e, 0x13 },
1138 { 0x3030, 0xdf },
1139 { 0x3031, 0x05 },
1140 };
1141
1142 /* init remote controller */
1143 if (!priv->rc_active) {
1144 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001145 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001146 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001147 if (ret)
1148 goto err;
1149 }
1150 priv->rc_active = true;
1151 }
Antti Palosaari831e0b72011-07-08 23:36:07 -03001152
1153 ret = rtl2831_rd_regs(d, SYS_IRRC_RP, buf, 5);
1154 if (ret)
1155 goto err;
1156
1157 if (buf[4] & 0x01) {
1158 if (buf[2] == (u8) ~buf[3]) {
1159 if (buf[0] == (u8) ~buf[1]) {
1160 /* NEC standard (16 bit) */
1161 rc_code = buf[0] << 8 | buf[2];
1162 } else {
1163 /* NEC extended (24 bit) */
1164 rc_code = buf[0] << 16 |
Antti Palosaari9935eea2012-01-21 22:26:52 -03001165 buf[1] << 8 | buf[2];
Antti Palosaari831e0b72011-07-08 23:36:07 -03001166 }
1167 } else {
1168 /* NEC full (32 bit) */
1169 rc_code = buf[0] << 24 | buf[1] << 16 |
1170 buf[2] << 8 | buf[3];
1171 }
1172
1173 rc_keydown(d->rc_dev, rc_code, 0);
1174
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001175 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001176 if (ret)
1177 goto err;
1178
1179 /* repeated intentionally to avoid extra keypress */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001180 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001181 if (ret)
1182 goto err;
1183 }
1184
1185 return ret;
1186err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001187 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001188 return ret;
1189}
1190
Antti Palosaaric01a3592012-08-12 22:27:07 -03001191static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
1192 struct dvb_usb_rc *rc)
1193{
1194 rc->map_name = RC_MAP_EMPTY;
1195 rc->allowed_protos = RC_TYPE_NEC;
1196 rc->query = rtl2831u_rc_query;
1197 rc->interval = 400;
1198
1199 return 0;
1200}
1201
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001202static int rtl2832u_rc_query(struct dvb_usb_device *d)
1203{
1204 int ret, i;
1205 struct rtl28xxu_priv *priv = d->priv;
1206 u8 buf[128];
1207 int len;
1208 struct rtl28xxu_reg_val rc_nec_tab[] = {
Antti Palosaari9935eea2012-01-21 22:26:52 -03001209 { IR_RX_CTRL, 0x20 },
1210 { IR_RX_BUF_CTRL, 0x80 },
1211 { IR_RX_IF, 0xff },
1212 { IR_RX_IE, 0xff },
1213 { IR_MAX_DURATION0, 0xd0 },
1214 { IR_MAX_DURATION1, 0x07 },
1215 { IR_IDLE_LEN0, 0xc0 },
1216 { IR_IDLE_LEN1, 0x00 },
1217 { IR_GLITCH_LEN, 0x03 },
1218 { IR_RX_CLK, 0x09 },
1219 { IR_RX_CFG, 0x1c },
1220 { IR_MAX_H_TOL_LEN, 0x1e },
1221 { IR_MAX_L_TOL_LEN, 0x1e },
1222 { IR_RX_CTRL, 0x80 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001223 };
1224
1225 /* init remote controller */
1226 if (!priv->rc_active) {
1227 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001228 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001229 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001230 if (ret)
1231 goto err;
1232 }
1233 priv->rc_active = true;
1234 }
1235
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001236 ret = rtl28xx_rd_reg(d, IR_RX_IF, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001237 if (ret)
1238 goto err;
1239
1240 if (buf[0] != 0x83)
1241 goto exit;
1242
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001243 ret = rtl28xx_rd_reg(d, IR_RX_BC, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001244 if (ret)
1245 goto err;
1246
1247 len = buf[0];
1248 ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len);
1249
1250 /* TODO: pass raw IR to Kernel IR decoder */
1251
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001252 ret = rtl28xx_wr_reg(d, IR_RX_IF, 0x03);
1253 ret = rtl28xx_wr_reg(d, IR_RX_BUF_CTRL, 0x80);
1254 ret = rtl28xx_wr_reg(d, IR_RX_CTRL, 0x80);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001255
1256exit:
1257 return ret;
1258err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001259 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001260 return ret;
1261}
1262
Antti Palosaaric01a3592012-08-12 22:27:07 -03001263static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1264 struct dvb_usb_rc *rc)
1265{
1266 rc->map_name = RC_MAP_EMPTY;
1267 rc->allowed_protos = RC_TYPE_NEC;
1268 rc->query = rtl2832u_rc_query;
1269 rc->interval = 400;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001270
Antti Palosaaric01a3592012-08-12 22:27:07 -03001271 return 0;
1272}
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001273
Antti Palosaaric01a3592012-08-12 22:27:07 -03001274static const struct dvb_usb_device_properties rtl2831u_props = {
1275 .driver_name = KBUILD_MODNAME,
1276 .owner = THIS_MODULE,
1277 .adapter_nr = adapter_nr,
1278 .size_of_priv = sizeof(struct rtl28xxu_priv),
Antti Palosaari831e0b72011-07-08 23:36:07 -03001279
Antti Palosaaric01a3592012-08-12 22:27:07 -03001280 .power_ctrl = rtl2831u_power_ctrl,
1281 .i2c_algo = &rtl28xxu_i2c_algo,
1282 .frontend_attach = rtl2831u_frontend_attach,
1283 .tuner_attach = rtl2831u_tuner_attach,
1284 .init = rtl28xxu_init,
1285 .get_rc_config = rtl2831u_get_rc_config,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001286
Antti Palosaaric01a3592012-08-12 22:27:07 -03001287 .num_adapters = 1,
1288 .adapter = {
1289 {
1290 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaari831e0b72011-07-08 23:36:07 -03001291 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001292 },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001293};
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001294
Antti Palosaaric01a3592012-08-12 22:27:07 -03001295static const struct dvb_usb_device_properties rtl2832u_props = {
1296 .driver_name = KBUILD_MODNAME,
1297 .owner = THIS_MODULE,
1298 .adapter_nr = adapter_nr,
1299 .size_of_priv = sizeof(struct rtl28xxu_priv),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001300
Antti Palosaaric01a3592012-08-12 22:27:07 -03001301 .power_ctrl = rtl2832u_power_ctrl,
1302 .i2c_algo = &rtl28xxu_i2c_algo,
Antti Palosaarief37be12012-09-17 14:01:35 -03001303 .read_config = rtl2832u_read_config,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001304 .frontend_attach = rtl2832u_frontend_attach,
1305 .tuner_attach = rtl2832u_tuner_attach,
1306 .init = rtl28xxu_init,
1307 .get_rc_config = rtl2832u_get_rc_config,
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001308
Antti Palosaaric01a3592012-08-12 22:27:07 -03001309 .num_adapters = 1,
1310 .adapter = {
1311 {
1312 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001313 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001314 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001315};
1316
Antti Palosaaric01a3592012-08-12 22:27:07 -03001317static const struct usb_device_id rtl28xxu_id_table[] = {
1318 { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U,
1319 &rtl2831u_props, "Realtek RTL2831U reference design", NULL) },
1320 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT,
1321 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
1322 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2,
1323 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001324
Antti Palosaari254ee2e2012-09-18 10:27:05 -03001325 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832,
1326 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
1327 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
1328 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001329 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
1330 &rtl2832u_props, "Terratec Cinergy T Stick Black", NULL) },
1331 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
1332 &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
1333 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
1334 &rtl2832u_props, "NOXON DAB/DAB+ USB dongle", NULL) },
Philipp Dreimann6d608052012-09-02 19:30:54 -03001335 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0,
1336 &rtl2832u_props, "Trekstor DVB-T Stick Terres 2.0", NULL) },
Antti Palosaaric2d246d12012-09-08 22:07:26 -03001337 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101,
1338 &rtl2832u_props, "Dexatek DK DVB-T Dongle", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001339 { }
1340};
1341MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001342
Antti Palosaaric01a3592012-08-12 22:27:07 -03001343static struct usb_driver rtl28xxu_usb_driver = {
1344 .name = KBUILD_MODNAME,
1345 .id_table = rtl28xxu_id_table,
1346 .probe = dvb_usbv2_probe,
1347 .disconnect = dvb_usbv2_disconnect,
1348 .suspend = dvb_usbv2_suspend,
1349 .resume = dvb_usbv2_resume,
Antti Palosaari78fa5902012-08-14 22:21:09 -03001350 .reset_resume = dvb_usbv2_reset_resume,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001351 .no_dynamic_id = 1,
1352 .soft_unbind = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001353};
1354
Antti Palosaaric01a3592012-08-12 22:27:07 -03001355module_usb_driver(rtl28xxu_usb_driver);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001356
1357MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
1358MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
Thomas Mair5cf66312012-05-18 14:47:41 -03001359MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>");
Antti Palosaari831e0b72011-07-08 23:36:07 -03001360MODULE_LICENSE("GPL");