blob: f195b778794a54adeca27720d745e1df37a8e563 [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 Palosaari831e0b72011-07-08 23:36:07 -030035
Antti Palosaari831e0b72011-07-08 23:36:07 -030036DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
37
38static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
39{
40 int ret;
41 unsigned int pipe;
42 u8 requesttype;
43 u8 *buf;
44
45 buf = kmalloc(req->size, GFP_KERNEL);
46 if (!buf) {
47 ret = -ENOMEM;
48 goto err;
49 }
50
51 if (req->index & CMD_WR_FLAG) {
52 /* write */
53 memcpy(buf, req->data, req->size);
54 requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT);
55 pipe = usb_sndctrlpipe(d->udev, 0);
56 } else {
57 /* read */
58 requesttype = (USB_TYPE_VENDOR | USB_DIR_IN);
59 pipe = usb_rcvctrlpipe(d->udev, 0);
60 }
61
62 ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value,
Antti Palosaari9935eea2012-01-21 22:26:52 -030063 req->index, buf, req->size, 1000);
Antti Palosaarid89b9362012-08-22 19:42:00 -030064
65 dvb_usb_dbg_usb_control_msg(d->udev, 0, requesttype, req->value,
66 req->index, buf, req->size);
67
Antti Palosaari9935eea2012-01-21 22:26:52 -030068 if (ret > 0)
69 ret = 0;
Antti Palosaari831e0b72011-07-08 23:36:07 -030070
Antti Palosaari831e0b72011-07-08 23:36:07 -030071 /* read request, copy returned data to return buf */
72 if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
73 memcpy(req->data, buf, req->size);
74
75 kfree(buf);
Antti Palosaari831e0b72011-07-08 23:36:07 -030076
Antti Palosaari9935eea2012-01-21 22:26:52 -030077 if (ret)
78 goto err;
79
80 return ret;
Antti Palosaari831e0b72011-07-08 23:36:07 -030081err:
Antti Palosaaric01a3592012-08-12 22:27:07 -030082 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -030083 return ret;
84}
85
Thomas Mair40a2d3c2012-05-18 14:47:42 -030086static int rtl28xx_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
Antti Palosaari831e0b72011-07-08 23:36:07 -030087{
88 struct rtl28xxu_req req;
89
90 if (reg < 0x3000)
91 req.index = CMD_USB_WR;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -030092 else if (reg < 0x4000)
Antti Palosaari831e0b72011-07-08 23:36:07 -030093 req.index = CMD_SYS_WR;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -030094 else
95 req.index = CMD_IR_WR;
Antti Palosaari831e0b72011-07-08 23:36:07 -030096
97 req.value = reg;
98 req.size = len;
99 req.data = val;
100
101 return rtl28xxu_ctrl_msg(d, &req);
102}
103
104static int rtl2831_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
105{
106 struct rtl28xxu_req req;
107
108 if (reg < 0x3000)
109 req.index = CMD_USB_RD;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300110 else if (reg < 0x4000)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300111 req.index = CMD_SYS_RD;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300112 else
113 req.index = CMD_IR_RD;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300114
115 req.value = reg;
116 req.size = len;
117 req.data = val;
118
119 return rtl28xxu_ctrl_msg(d, &req);
120}
121
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300122static int rtl28xx_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300123{
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300124 return rtl28xx_wr_regs(d, reg, &val, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300125}
126
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300127static int rtl28xx_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300128{
129 return rtl2831_rd_regs(d, reg, val, 1);
130}
131
132/* I2C */
133static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
134 int num)
135{
136 int ret;
137 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300138 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300139 struct rtl28xxu_req req;
140
141 /*
142 * It is not known which are real I2C bus xfer limits, but testing
143 * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes.
Antti Palosaari34ec2932011-08-04 20:21:16 -0300144 * TODO: find out RTL2832U lens
145 */
146
147 /*
148 * I2C adapter logic looks rather complicated due to fact it handles
149 * three different access methods. Those methods are;
150 * 1) integrated demod access
151 * 2) old I2C access
152 * 3) new I2C access
153 *
154 * Used method is selected in order 1, 2, 3. Method 3 can handle all
155 * requests but there is two reasons why not use it always;
156 * 1) It is most expensive, usually two USB messages are needed
157 * 2) At least RTL2831U does not support it
158 *
159 * Method 3 is needed in case of I2C write+read (typical register read)
160 * where write is more than one byte.
Antti Palosaari831e0b72011-07-08 23:36:07 -0300161 */
162
163 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
164 return -EAGAIN;
165
166 if (num == 2 && !(msg[0].flags & I2C_M_RD) &&
167 (msg[1].flags & I2C_M_RD)) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300168 if (msg[0].len > 24 || msg[1].len > 24) {
169 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300170 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300171 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300172 } else if (msg[0].addr == 0x10) {
173 /* method 1 - integrated demod */
174 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
175 req.index = CMD_DEMOD_RD | priv->page;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300176 req.size = msg[1].len;
177 req.data = &msg[1].buf[0];
178 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300179 } else if (msg[0].len < 2) {
180 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300181 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
182 req.index = CMD_I2C_RD;
183 req.size = msg[1].len;
184 req.data = &msg[1].buf[0];
185 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300186 } else {
187 /* method 3 - new I2C */
188 req.value = (msg[0].addr << 1);
189 req.index = CMD_I2C_DA_WR;
190 req.size = msg[0].len;
191 req.data = msg[0].buf;
192 ret = rtl28xxu_ctrl_msg(d, &req);
193 if (ret)
Antti Palosaari9935eea2012-01-21 22:26:52 -0300194 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300195
196 req.value = (msg[0].addr << 1);
197 req.index = CMD_I2C_DA_RD;
198 req.size = msg[1].len;
199 req.data = msg[1].buf;
200 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300201 }
202 } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
203 if (msg[0].len > 22) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300204 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300205 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300206 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300207 } else if (msg[0].addr == 0x10) {
208 /* method 1 - integrated demod */
209 if (msg[0].buf[0] == 0x00) {
210 /* save demod page for later demod access */
211 priv->page = msg[0].buf[1];
212 ret = 0;
213 } else {
214 req.value = (msg[0].buf[0] << 8) |
215 (msg[0].addr << 1);
216 req.index = CMD_DEMOD_WR | priv->page;
217 req.size = msg[0].len-1;
218 req.data = &msg[0].buf[1];
219 ret = rtl28xxu_ctrl_msg(d, &req);
220 }
221 } else if (msg[0].len < 23) {
222 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300223 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
224 req.index = CMD_I2C_WR;
225 req.size = msg[0].len-1;
226 req.data = &msg[0].buf[1];
227 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300228 } else {
229 /* method 3 - new I2C */
230 req.value = (msg[0].addr << 1);
231 req.index = CMD_I2C_DA_WR;
232 req.size = msg[0].len;
233 req.data = msg[0].buf;
234 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300235 }
236 } else {
237 ret = -EINVAL;
238 }
239
Antti Palosaari9935eea2012-01-21 22:26:52 -0300240err_mutex_unlock:
Antti Palosaari831e0b72011-07-08 23:36:07 -0300241 mutex_unlock(&d->i2c_mutex);
242
243 return ret ? ret : num;
244}
245
246static u32 rtl28xxu_i2c_func(struct i2c_adapter *adapter)
247{
248 return I2C_FUNC_I2C;
249}
250
251static struct i2c_algorithm rtl28xxu_i2c_algo = {
252 .master_xfer = rtl28xxu_i2c_xfer,
253 .functionality = rtl28xxu_i2c_func,
254};
255
256static struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = {
257 .i2c_addr = 0x10, /* 0x20 */
258 .xtal = 28800000,
259 .ts_mode = 0,
260 .spec_inv = 1,
261 .if_dvbt = 36150000,
262 .vtop = 0x20,
263 .krf = 0x04,
264 .agc_targ_val = 0x2d,
265
266};
267
268static struct rtl2830_config rtl28xxu_rtl2830_qt1010_config = {
269 .i2c_addr = 0x10, /* 0x20 */
270 .xtal = 28800000,
271 .ts_mode = 0,
272 .spec_inv = 1,
273 .if_dvbt = 36125000,
274 .vtop = 0x20,
275 .krf = 0x04,
276 .agc_targ_val = 0x2d,
277};
278
279static struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = {
280 .i2c_addr = 0x10, /* 0x20 */
281 .xtal = 28800000,
282 .ts_mode = 0,
283 .spec_inv = 0,
284 .if_dvbt = 4570000,
285 .vtop = 0x3f,
286 .krf = 0x04,
287 .agc_targ_val = 0x3e,
288};
289
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300290static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300291{
292 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300293 struct dvb_usb_device *d = adap_to_d(adap);
294 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300295 u8 buf[1];
296 struct rtl2830_config *rtl2830_config;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300297 /* open RTL2831U/RTL2830 I2C gate */
Antti Palosaari9935eea2012-01-21 22:26:52 -0300298 struct rtl28xxu_req req_gate = { 0x0120, 0x0011, 0x0001, "\x08" };
Antti Palosaari831e0b72011-07-08 23:36:07 -0300299 /* for MT2060 tuner probe */
Antti Palosaari9935eea2012-01-21 22:26:52 -0300300 struct rtl28xxu_req req_mt2060 = { 0x00c0, CMD_I2C_RD, 1, buf };
Antti Palosaari831e0b72011-07-08 23:36:07 -0300301 /* for QT1010 tuner probe */
Antti Palosaari9935eea2012-01-21 22:26:52 -0300302 struct rtl28xxu_req req_qt1010 = { 0x0fc4, CMD_I2C_RD, 1, buf };
Antti Palosaari831e0b72011-07-08 23:36:07 -0300303
Antti Palosaaric01a3592012-08-12 22:27:07 -0300304 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300305
306 /*
307 * RTL2831U GPIOs
308 * =========================================================
309 * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?)
310 * GPIO2 | LED | 0 off | 1 on |
311 * GPIO4 | tuner#1 | 0 on | 1 off | MT2060
312 */
313
314 /* GPIO direction */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300315 ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, 0x0a);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300316 if (ret)
317 goto err;
318
319 /* enable as output GPIO0, GPIO2, GPIO4 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300320 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, 0x15);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300321 if (ret)
322 goto err;
323
324 /*
325 * Probe used tuner. We need to know used tuner before demod attach
326 * since there is some demod params needed to set according to tuner.
327 */
328
Antti Palosaariccb5cf92012-05-18 16:07:46 -0300329 /* demod needs some time to wake up */
330 msleep(20);
331
Antti Palosaari831e0b72011-07-08 23:36:07 -0300332 /* open demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300333 ret = rtl28xxu_ctrl_msg(d, &req_gate);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300334 if (ret)
335 goto err;
336
337 /* check QT1010 ID(?) register; reg=0f val=2c */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300338 ret = rtl28xxu_ctrl_msg(d, &req_qt1010);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300339 if (ret == 0 && buf[0] == 0x2c) {
340 priv->tuner = TUNER_RTL2830_QT1010;
341 rtl2830_config = &rtl28xxu_rtl2830_qt1010_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300342 dev_dbg(&d->udev->dev, "%s: QT1010\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300343 goto found;
344 } else {
Antti Palosaaric01a3592012-08-12 22:27:07 -0300345 dev_dbg(&d->udev->dev, "%s: QT1010 probe failed=%d - %02x\n",
346 __func__, ret, buf[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300347 }
348
349 /* open demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300350 ret = rtl28xxu_ctrl_msg(d, &req_gate);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300351 if (ret)
352 goto err;
353
354 /* check MT2060 ID register; reg=00 val=63 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300355 ret = rtl28xxu_ctrl_msg(d, &req_mt2060);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300356 if (ret == 0 && buf[0] == 0x63) {
357 priv->tuner = TUNER_RTL2830_MT2060;
358 rtl2830_config = &rtl28xxu_rtl2830_mt2060_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300359 dev_dbg(&d->udev->dev, "%s: MT2060\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300360 goto found;
361 } else {
Antti Palosaaric01a3592012-08-12 22:27:07 -0300362 dev_dbg(&d->udev->dev, "%s: MT2060 probe failed=%d - %02x\n",
363 __func__, ret, buf[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300364 }
365
366 /* assume MXL5005S */
Antti Palosaarie9320ec2011-08-03 04:35:30 -0300367 ret = 0;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300368 priv->tuner = TUNER_RTL2830_MXL5005S;
369 rtl2830_config = &rtl28xxu_rtl2830_mxl5005s_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300370 dev_dbg(&d->udev->dev, "%s: MXL5005S\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300371 goto found;
372
373found:
374 /* attach demodulator */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300375 adap->fe[0] = dvb_attach(rtl2830_attach, rtl2830_config,
376 &d->i2c_adap);
377 if (adap->fe[0] == NULL) {
Antti Palosaari831e0b72011-07-08 23:36:07 -0300378 ret = -ENODEV;
379 goto err;
380 }
381
382 return ret;
383err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300384 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300385 return ret;
386}
387
Thomas Mair5cf66312012-05-18 14:47:41 -0300388static struct rtl2832_config rtl28xxu_rtl2832_fc0012_config = {
389 .i2c_addr = 0x10, /* 0x20 */
390 .xtal = 28800000,
391 .if_dvbt = 0,
392 .tuner = TUNER_RTL2832_FC0012
393};
394
395static struct rtl2832_config rtl28xxu_rtl2832_fc0013_config = {
396 .i2c_addr = 0x10, /* 0x20 */
397 .xtal = 28800000,
398 .if_dvbt = 0,
399 .tuner = TUNER_RTL2832_FC0013
400};
401
402static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
403 int cmd, int arg)
404{
405 int ret;
406 u8 val;
407
Antti Palosaaric01a3592012-08-12 22:27:07 -0300408 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
409
Thomas Mair5cf66312012-05-18 14:47:41 -0300410 switch (cmd) {
411 case FC_FE_CALLBACK_VHF_ENABLE:
412 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300413 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300414 if (ret)
415 goto err;
416
417 if (arg)
418 val &= 0xbf; /* set GPIO6 low */
419 else
420 val |= 0x40; /* set GPIO6 high */
421
422
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300423 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300424 if (ret)
425 goto err;
426 break;
427 default:
428 ret = -EINVAL;
429 goto err;
430 }
431 return 0;
432
433err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300434 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -0300435 return ret;
436}
437
438
439static int rtl2832u_fc0013_tuner_callback(struct dvb_usb_device *d,
440 int cmd, int arg)
441{
442 /* TODO implement*/
443 return 0;
444}
445
446static int rtl2832u_tuner_callback(struct dvb_usb_device *d, int cmd, int arg)
447{
448 struct rtl28xxu_priv *priv = d->priv;
449
450 switch (priv->tuner) {
451 case TUNER_RTL2832_FC0012:
452 return rtl2832u_fc0012_tuner_callback(d, cmd, arg);
453
454 case TUNER_RTL2832_FC0013:
455 return rtl2832u_fc0013_tuner_callback(d, cmd, arg);
456 default:
457 break;
458 }
459
460 return -ENODEV;
461}
462
463static int rtl2832u_frontend_callback(void *adapter_priv, int component,
464 int cmd, int arg)
465{
466 struct i2c_adapter *adap = adapter_priv;
467 struct dvb_usb_device *d = i2c_get_adapdata(adap);
468
469 switch (component) {
470 case DVB_FRONTEND_COMPONENT_TUNER:
471 return rtl2832u_tuner_callback(d, cmd, arg);
472 default:
473 break;
474 }
475
476 return -EINVAL;
477}
478
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300479static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
480{
481 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300482 struct dvb_usb_device *d = adap_to_d(adap);
483 struct rtl28xxu_priv *priv = d_to_priv(d);
Thomas Mair5cf66312012-05-18 14:47:41 -0300484 struct rtl2832_config *rtl2832_config;
Thomas Mair5cf66312012-05-18 14:47:41 -0300485 u8 buf[2], val;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300486 /* open RTL2832U/RTL2832 I2C gate */
487 struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"};
488 /* close RTL2832U/RTL2832 I2C gate */
489 struct rtl28xxu_req req_gate_close = {0x0120, 0x0011, 0x0001, "\x10"};
Thomas Mair5cf66312012-05-18 14:47:41 -0300490 /* for FC0012 tuner probe */
491 struct rtl28xxu_req req_fc0012 = {0x00c6, CMD_I2C_RD, 1, buf};
492 /* for FC0013 tuner probe */
493 struct rtl28xxu_req req_fc0013 = {0x00c6, CMD_I2C_RD, 1, buf};
494 /* for MT2266 tuner probe */
495 struct rtl28xxu_req req_mt2266 = {0x00c0, CMD_I2C_RD, 1, buf};
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300496 /* for FC2580 tuner probe */
497 struct rtl28xxu_req req_fc2580 = {0x01ac, CMD_I2C_RD, 1, buf};
Thomas Mair5cf66312012-05-18 14:47:41 -0300498 /* for MT2063 tuner probe */
499 struct rtl28xxu_req req_mt2063 = {0x00c0, CMD_I2C_RD, 1, buf};
500 /* for MAX3543 tuner probe */
501 struct rtl28xxu_req req_max3543 = {0x00c0, CMD_I2C_RD, 1, buf};
502 /* for TUA9001 tuner probe */
503 struct rtl28xxu_req req_tua9001 = {0x7ec0, CMD_I2C_RD, 2, buf};
504 /* for MXL5007T tuner probe */
505 struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf};
506 /* for E4000 tuner probe */
507 struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
508 /* for TDA18272 tuner probe */
509 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300510
Antti Palosaaric01a3592012-08-12 22:27:07 -0300511 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300512
Antti Palosaaric01a3592012-08-12 22:27:07 -0300513 ret = rtl28xx_rd_reg(d, SYS_GPIO_DIR, &val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300514 if (ret)
515 goto err;
516
Thomas Mair5cf66312012-05-18 14:47:41 -0300517 val &= 0xbf;
518
Antti Palosaaric01a3592012-08-12 22:27:07 -0300519 ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300520 if (ret)
521 goto err;
522
Thomas Mair5cf66312012-05-18 14:47:41 -0300523 /* enable as output GPIO3 and GPIO6*/
Antti Palosaaric01a3592012-08-12 22:27:07 -0300524 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_EN, &val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300525 if (ret)
526 goto err;
527
Thomas Mair5cf66312012-05-18 14:47:41 -0300528 val |= 0x48;
529
Antti Palosaaric01a3592012-08-12 22:27:07 -0300530 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300531 if (ret)
532 goto err;
533
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300534 /*
535 * Probe used tuner. We need to know used tuner before demod attach
536 * since there is some demod params needed to set according to tuner.
537 */
538
539 /* open demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300540 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300541 if (ret)
542 goto err;
543
Thomas Mair5cf66312012-05-18 14:47:41 -0300544 priv->tuner = TUNER_NONE;
545
546 /* check FC0012 ID register; reg=00 val=a1 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300547 ret = rtl28xxu_ctrl_msg(d, &req_fc0012);
Thomas Mair5cf66312012-05-18 14:47:41 -0300548 if (ret == 0 && buf[0] == 0xa1) {
549 priv->tuner = TUNER_RTL2832_FC0012;
550 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300551 dev_info(&d->udev->dev, "%s: FC0012 tuner found",
552 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300553 goto found;
554 }
555
556 /* check FC0013 ID register; reg=00 val=a3 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300557 ret = rtl28xxu_ctrl_msg(d, &req_fc0013);
Thomas Mair5cf66312012-05-18 14:47:41 -0300558 if (ret == 0 && buf[0] == 0xa3) {
559 priv->tuner = TUNER_RTL2832_FC0013;
560 rtl2832_config = &rtl28xxu_rtl2832_fc0013_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300561 dev_info(&d->udev->dev, "%s: FC0013 tuner found",
562 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300563 goto found;
564 }
565
566 /* check MT2266 ID register; reg=00 val=85 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300567 ret = rtl28xxu_ctrl_msg(d, &req_mt2266);
Thomas Mair5cf66312012-05-18 14:47:41 -0300568 if (ret == 0 && buf[0] == 0x85) {
569 priv->tuner = TUNER_RTL2832_MT2266;
570 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300571 dev_info(&d->udev->dev, "%s: MT2266 tuner found",
572 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300573 goto unsupported;
574 }
575
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300576 /* check FC2580 ID register; reg=01 val=56 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300577 ret = rtl28xxu_ctrl_msg(d, &req_fc2580);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300578 if (ret == 0 && buf[0] == 0x56) {
579 priv->tuner = TUNER_RTL2832_FC2580;
Antti Palosaari384df492012-09-08 22:07:25 -0300580 /* FIXME: do not abuse fc0012 settings */
581 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300582 dev_info(&d->udev->dev, "%s: FC2580 tuner found",
583 KBUILD_MODNAME);
Antti Palosaari384df492012-09-08 22:07:25 -0300584 goto found;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300585 }
586
Thomas Mair5cf66312012-05-18 14:47:41 -0300587 /* check MT2063 ID register; reg=00 val=9e || 9c */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300588 ret = rtl28xxu_ctrl_msg(d, &req_mt2063);
Thomas Mair5cf66312012-05-18 14:47:41 -0300589 if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) {
590 priv->tuner = TUNER_RTL2832_MT2063;
591 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300592 dev_info(&d->udev->dev, "%s: MT2063 tuner found",
593 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300594 goto unsupported;
595 }
596
597 /* check MAX3543 ID register; reg=00 val=38 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300598 ret = rtl28xxu_ctrl_msg(d, &req_max3543);
Thomas Mair5cf66312012-05-18 14:47:41 -0300599 if (ret == 0 && buf[0] == 0x38) {
600 priv->tuner = TUNER_RTL2832_MAX3543;
601 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300602 dev_info(&d->udev->dev, "%s: MAX3534 tuner found",
603 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300604 goto unsupported;
605 }
606
607 /* check TUA9001 ID register; reg=7e val=2328 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300608 ret = rtl28xxu_ctrl_msg(d, &req_tua9001);
Thomas Mair5cf66312012-05-18 14:47:41 -0300609 if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) {
610 priv->tuner = TUNER_RTL2832_TUA9001;
611 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300612 dev_info(&d->udev->dev, "%s: TUA9001 tuner found",
613 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300614 goto unsupported;
615 }
616
617 /* check MXL5007R ID register; reg=d9 val=14 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300618 ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t);
Thomas Mair5cf66312012-05-18 14:47:41 -0300619 if (ret == 0 && buf[0] == 0x14) {
620 priv->tuner = TUNER_RTL2832_MXL5007T;
621 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300622 dev_info(&d->udev->dev, "%s: MXL5007T tuner found",
623 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300624 goto unsupported;
625 }
626
627 /* check E4000 ID register; reg=02 val=40 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300628 ret = rtl28xxu_ctrl_msg(d, &req_e4000);
Thomas Mair5cf66312012-05-18 14:47:41 -0300629 if (ret == 0 && buf[0] == 0x40) {
630 priv->tuner = TUNER_RTL2832_E4000;
Antti Palosaari542f6a52012-09-01 21:09:22 -0300631 /* FIXME: do not abuse fc0012 settings */
632 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300633 dev_info(&d->udev->dev, "%s: E4000 tuner found",
634 KBUILD_MODNAME);
Antti Palosaari542f6a52012-09-01 21:09:22 -0300635 goto found;
Thomas Mair5cf66312012-05-18 14:47:41 -0300636 }
637
638 /* check TDA18272 ID register; reg=00 val=c760 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300639 ret = rtl28xxu_ctrl_msg(d, &req_tda18272);
Thomas Mair5cf66312012-05-18 14:47:41 -0300640 if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) {
641 priv->tuner = TUNER_RTL2832_TDA18272;
642 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300643 dev_info(&d->udev->dev, "%s: TDA18272 tuner found",
644 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300645 goto unsupported;
646 }
647
648unsupported:
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300649 /* close demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300650 ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300651 if (ret)
652 goto err;
653
654 /* tuner not found */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300655 dev_dbg(&d->udev->dev, "%s: No compatible tuner found\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300656 ret = -ENODEV;
Thomas Mair5cf66312012-05-18 14:47:41 -0300657 return ret;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300658
659found:
660 /* close demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300661 ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300662 if (ret)
663 goto err;
664
665 /* attach demodulator */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300666 adap->fe[0] = dvb_attach(rtl2832_attach, rtl2832_config,
667 &d->i2c_adap);
668 if (adap->fe[0] == NULL) {
Thomas Mair5cf66312012-05-18 14:47:41 -0300669 ret = -ENODEV;
670 goto err;
671 }
672
673 /* set fe callbacks */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300674 adap->fe[0]->callback = rtl2832u_frontend_callback;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300675
676 return ret;
Thomas Mair5cf66312012-05-18 14:47:41 -0300677
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300678err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300679 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300680 return ret;
681}
682
Antti Palosaari831e0b72011-07-08 23:36:07 -0300683static struct qt1010_config rtl28xxu_qt1010_config = {
684 .i2c_address = 0x62, /* 0xc4 */
685};
686
687static struct mt2060_config rtl28xxu_mt2060_config = {
688 .i2c_address = 0x60, /* 0xc0 */
689 .clock_out = 0,
690};
691
692static struct mxl5005s_config rtl28xxu_mxl5005s_config = {
693 .i2c_address = 0x63, /* 0xc6 */
694 .if_freq = IF_FREQ_4570000HZ,
695 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
696 .agc_mode = MXL_SINGLE_AGC,
697 .tracking_filter = MXL_TF_C_H,
698 .rssi_enable = MXL_RSSI_ENABLE,
699 .cap_select = MXL_CAP_SEL_ENABLE,
700 .div_out = MXL_DIV_OUT_4,
701 .clock_out = MXL_CLOCK_OUT_DISABLE,
702 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
703 .top = MXL5005S_TOP_25P2,
704 .mod_mode = MXL_DIGITAL_MODE,
705 .if_mode = MXL_ZERO_IF,
706 .AgcMasterByte = 0x00,
707};
708
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300709static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300710{
711 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300712 struct dvb_usb_device *d = adap_to_d(adap);
713 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300714 struct i2c_adapter *rtl2830_tuner_i2c;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300715 struct dvb_frontend *fe;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300716
Antti Palosaaric01a3592012-08-12 22:27:07 -0300717 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300718
719 /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300720 rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300721
722 switch (priv->tuner) {
723 case TUNER_RTL2830_QT1010:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300724 fe = dvb_attach(qt1010_attach, adap->fe[0],
Antti Palosaarifba16b12012-01-21 20:28:38 -0300725 rtl2830_tuner_i2c, &rtl28xxu_qt1010_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300726 break;
727 case TUNER_RTL2830_MT2060:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300728 fe = dvb_attach(mt2060_attach, adap->fe[0],
Antti Palosaarifba16b12012-01-21 20:28:38 -0300729 rtl2830_tuner_i2c, &rtl28xxu_mt2060_config,
730 1220);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300731 break;
732 case TUNER_RTL2830_MXL5005S:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300733 fe = dvb_attach(mxl5005s_attach, adap->fe[0],
Antti Palosaari9935eea2012-01-21 22:26:52 -0300734 rtl2830_tuner_i2c, &rtl28xxu_mxl5005s_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300735 break;
736 default:
Antti Palosaari9935eea2012-01-21 22:26:52 -0300737 fe = NULL;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300738 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
739 priv->tuner);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300740 }
741
742 if (fe == NULL) {
743 ret = -ENODEV;
744 goto err;
745 }
746
747 return 0;
748err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300749 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300750 return ret;
751}
752
Antti Palosaari542f6a52012-09-01 21:09:22 -0300753static const struct e4000_config rtl2832u_e4000_config = {
754 .i2c_addr = 0x64,
755 .clock = 28800000,
756};
757
Antti Palosaari384df492012-09-08 22:07:25 -0300758static const struct fc2580_config rtl2832u_fc2580_config = {
759 .i2c_addr = 0x56,
760 .clock = 16384000,
761};
762
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300763static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
764{
765 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300766 struct dvb_usb_device *d = adap_to_d(adap);
767 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari9935eea2012-01-21 22:26:52 -0300768 struct dvb_frontend *fe;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300769
Antti Palosaaric01a3592012-08-12 22:27:07 -0300770 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300771
772 switch (priv->tuner) {
Thomas Mair5cf66312012-05-18 14:47:41 -0300773 case TUNER_RTL2832_FC0012:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300774 fe = dvb_attach(fc0012_attach, adap->fe[0],
775 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -0300776
777 /* since fc0012 includs reading the signal strength delegate
778 * that to the tuner driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300779 adap->fe[0]->ops.read_signal_strength =
780 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Thomas Mair5cf66312012-05-18 14:47:41 -0300781 return 0;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300782 break;
Thomas Mair5cf66312012-05-18 14:47:41 -0300783 case TUNER_RTL2832_FC0013:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300784 fe = dvb_attach(fc0013_attach, adap->fe[0],
785 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -0300786
787 /* fc0013 also supports signal strength reading */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300788 adap->fe[0]->ops.read_signal_strength =
789 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Thomas Mair5cf66312012-05-18 14:47:41 -0300790 return 0;
Antti Palosaari542f6a52012-09-01 21:09:22 -0300791 case TUNER_RTL2832_E4000:
792 fe = dvb_attach(e4000_attach, adap->fe[0], &d->i2c_adap,
793 &rtl2832u_e4000_config);
794 break;
Antti Palosaari384df492012-09-08 22:07:25 -0300795 case TUNER_RTL2832_FC2580:
796 fe = dvb_attach(fc2580_attach, adap->fe[0], &d->i2c_adap,
797 &rtl2832u_fc2580_config);
798 break;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300799 default:
Antti Palosaari9935eea2012-01-21 22:26:52 -0300800 fe = NULL;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300801 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
802 priv->tuner);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300803 }
804
805 if (fe == NULL) {
806 ret = -ENODEV;
807 goto err;
808 }
809
810 return 0;
811err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300812 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300813 return ret;
814}
815
Antti Palosaaric01a3592012-08-12 22:27:07 -0300816static int rtl28xxu_init(struct dvb_usb_device *d)
817{
818 int ret;
819 u8 val;
820
821 dev_dbg(&d->udev->dev, "%s:\n", __func__);
822
823 /* init USB endpoints */
824 ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val);
825 if (ret)
826 goto err;
827
828 /* enable DMA and Full Packet Mode*/
829 val |= 0x09;
830 ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val);
831 if (ret)
832 goto err;
833
834 /* set EPA maximum packet size to 0x0200 */
835 ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
836 if (ret)
837 goto err;
838
839 /* change EPA FIFO length */
840 ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
841 if (ret)
842 goto err;
843
844 return ret;
845err:
846 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
847 return ret;
848}
849
Thomas Mair5cf66312012-05-18 14:47:41 -0300850static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300851{
852 int ret;
Antti Palosaari8b036632012-09-01 09:54:43 -0300853 u8 gpio, sys0, epa_ctl[2];
Antti Palosaari831e0b72011-07-08 23:36:07 -0300854
Antti Palosaaric01a3592012-08-12 22:27:07 -0300855 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300856
857 /* demod adc */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300858 ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300859 if (ret)
860 goto err;
861
862 /* tuner power, read GPIOs */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300863 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300864 if (ret)
865 goto err;
866
Antti Palosaaric01a3592012-08-12 22:27:07 -0300867 dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
868 sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300869
870 if (onoff) {
871 gpio |= 0x01; /* GPIO0 = 1 */
872 gpio &= (~0x10); /* GPIO4 = 0 */
Antti Palosaari991452a2012-08-12 22:27:08 -0300873 gpio |= 0x04; /* GPIO2 = 1, LED on */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300874 sys0 = sys0 & 0x0f;
875 sys0 |= 0xe0;
Antti Palosaari8b036632012-09-01 09:54:43 -0300876 epa_ctl[0] = 0x00; /* clear stall */
877 epa_ctl[1] = 0x00; /* clear reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300878 } else {
Antti Palosaari831e0b72011-07-08 23:36:07 -0300879 gpio &= (~0x01); /* GPIO0 = 0 */
880 gpio |= 0x10; /* GPIO4 = 1 */
Antti Palosaari991452a2012-08-12 22:27:08 -0300881 gpio &= (~0x04); /* GPIO2 = 1, LED off */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300882 sys0 = sys0 & (~0xc0);
Antti Palosaari8b036632012-09-01 09:54:43 -0300883 epa_ctl[0] = 0x10; /* set stall */
884 epa_ctl[1] = 0x02; /* set reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300885 }
886
Antti Palosaaric01a3592012-08-12 22:27:07 -0300887 dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
888 sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300889
890 /* demod adc */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300891 ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300892 if (ret)
893 goto err;
894
895 /* tuner power, write GPIOs */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300896 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300897 if (ret)
898 goto err;
899
Antti Palosaari8b036632012-09-01 09:54:43 -0300900 /* streaming EP: stall & reset */
901 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, epa_ctl, 2);
902 if (ret)
903 goto err;
904
905 if (onoff)
906 usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
907
Antti Palosaari831e0b72011-07-08 23:36:07 -0300908 return ret;
909err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300910 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300911 return ret;
912}
913
Thomas Mair5cf66312012-05-18 14:47:41 -0300914static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
915{
916 int ret;
917 u8 val;
918
Antti Palosaaric01a3592012-08-12 22:27:07 -0300919 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Thomas Mair5cf66312012-05-18 14:47:41 -0300920
921 if (onoff) {
922 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300923 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300924 if (ret)
925 goto err;
926
927 val |= 0x08;
928 val &= 0xef;
929
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300930 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300931 if (ret)
932 goto err;
933
934 /* demod_ctl_1 */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300935 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300936 if (ret)
937 goto err;
938
939 val &= 0xef;
940
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300941 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300942 if (ret)
943 goto err;
944
945 /* demod control */
946 /* PLL enable */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300947 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300948 if (ret)
949 goto err;
950
951 /* bit 7 to 1 */
952 val |= 0x80;
953
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300954 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300955 if (ret)
956 goto err;
957
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300958 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300959 if (ret)
960 goto err;
961
962 val |= 0x20;
963
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300964 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300965 if (ret)
966 goto err;
967
968 mdelay(5);
969
970 /*enable ADC_Q and ADC_I */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300971 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300972 if (ret)
973 goto err;
974
975 val |= 0x48;
976
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300977 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300978 if (ret)
979 goto err;
980
981
Antti Palosaari8b036632012-09-01 09:54:43 -0300982 /* streaming EP: clear stall & reset */
983 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2);
984 if (ret)
985 goto err;
986
987 ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
988 if (ret)
989 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -0300990 } else {
991 /* demod_ctl_1 */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300992 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300993 if (ret)
994 goto err;
995
996 val |= 0x0c;
997
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300998 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300999 if (ret)
1000 goto err;
1001
1002 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001003 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001004 if (ret)
1005 goto err;
1006
1007 val |= 0x10;
1008
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001009 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001010 if (ret)
1011 goto err;
1012
1013 /* demod control */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001014 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001015 if (ret)
1016 goto err;
1017
1018 val &= 0x37;
1019
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001020 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001021 if (ret)
1022 goto err;
1023
Antti Palosaari8b036632012-09-01 09:54:43 -03001024 /* streaming EP: set stall & reset */
1025 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2);
1026 if (ret)
1027 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001028 }
1029
1030 return ret;
1031err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001032 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -03001033 return ret;
1034}
1035
1036
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001037static int rtl2831u_rc_query(struct dvb_usb_device *d)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001038{
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001039 int ret, i;
1040 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -03001041 u8 buf[5];
1042 u32 rc_code;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001043 struct rtl28xxu_reg_val rc_nec_tab[] = {
1044 { 0x3033, 0x80 },
1045 { 0x3020, 0x43 },
1046 { 0x3021, 0x16 },
1047 { 0x3022, 0x16 },
1048 { 0x3023, 0x5a },
1049 { 0x3024, 0x2d },
1050 { 0x3025, 0x16 },
1051 { 0x3026, 0x01 },
1052 { 0x3028, 0xb0 },
1053 { 0x3029, 0x04 },
1054 { 0x302c, 0x88 },
1055 { 0x302e, 0x13 },
1056 { 0x3030, 0xdf },
1057 { 0x3031, 0x05 },
1058 };
1059
1060 /* init remote controller */
1061 if (!priv->rc_active) {
1062 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001063 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001064 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001065 if (ret)
1066 goto err;
1067 }
1068 priv->rc_active = true;
1069 }
Antti Palosaari831e0b72011-07-08 23:36:07 -03001070
1071 ret = rtl2831_rd_regs(d, SYS_IRRC_RP, buf, 5);
1072 if (ret)
1073 goto err;
1074
1075 if (buf[4] & 0x01) {
1076 if (buf[2] == (u8) ~buf[3]) {
1077 if (buf[0] == (u8) ~buf[1]) {
1078 /* NEC standard (16 bit) */
1079 rc_code = buf[0] << 8 | buf[2];
1080 } else {
1081 /* NEC extended (24 bit) */
1082 rc_code = buf[0] << 16 |
Antti Palosaari9935eea2012-01-21 22:26:52 -03001083 buf[1] << 8 | buf[2];
Antti Palosaari831e0b72011-07-08 23:36:07 -03001084 }
1085 } else {
1086 /* NEC full (32 bit) */
1087 rc_code = buf[0] << 24 | buf[1] << 16 |
1088 buf[2] << 8 | buf[3];
1089 }
1090
1091 rc_keydown(d->rc_dev, rc_code, 0);
1092
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001093 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001094 if (ret)
1095 goto err;
1096
1097 /* repeated intentionally to avoid extra keypress */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001098 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001099 if (ret)
1100 goto err;
1101 }
1102
1103 return ret;
1104err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001105 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001106 return ret;
1107}
1108
Antti Palosaaric01a3592012-08-12 22:27:07 -03001109static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
1110 struct dvb_usb_rc *rc)
1111{
1112 rc->map_name = RC_MAP_EMPTY;
1113 rc->allowed_protos = RC_TYPE_NEC;
1114 rc->query = rtl2831u_rc_query;
1115 rc->interval = 400;
1116
1117 return 0;
1118}
1119
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001120static int rtl2832u_rc_query(struct dvb_usb_device *d)
1121{
1122 int ret, i;
1123 struct rtl28xxu_priv *priv = d->priv;
1124 u8 buf[128];
1125 int len;
1126 struct rtl28xxu_reg_val rc_nec_tab[] = {
Antti Palosaari9935eea2012-01-21 22:26:52 -03001127 { IR_RX_CTRL, 0x20 },
1128 { IR_RX_BUF_CTRL, 0x80 },
1129 { IR_RX_IF, 0xff },
1130 { IR_RX_IE, 0xff },
1131 { IR_MAX_DURATION0, 0xd0 },
1132 { IR_MAX_DURATION1, 0x07 },
1133 { IR_IDLE_LEN0, 0xc0 },
1134 { IR_IDLE_LEN1, 0x00 },
1135 { IR_GLITCH_LEN, 0x03 },
1136 { IR_RX_CLK, 0x09 },
1137 { IR_RX_CFG, 0x1c },
1138 { IR_MAX_H_TOL_LEN, 0x1e },
1139 { IR_MAX_L_TOL_LEN, 0x1e },
1140 { IR_RX_CTRL, 0x80 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001141 };
1142
1143 /* init remote controller */
1144 if (!priv->rc_active) {
1145 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001146 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001147 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001148 if (ret)
1149 goto err;
1150 }
1151 priv->rc_active = true;
1152 }
1153
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001154 ret = rtl28xx_rd_reg(d, IR_RX_IF, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001155 if (ret)
1156 goto err;
1157
1158 if (buf[0] != 0x83)
1159 goto exit;
1160
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001161 ret = rtl28xx_rd_reg(d, IR_RX_BC, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001162 if (ret)
1163 goto err;
1164
1165 len = buf[0];
1166 ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len);
1167
1168 /* TODO: pass raw IR to Kernel IR decoder */
1169
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001170 ret = rtl28xx_wr_reg(d, IR_RX_IF, 0x03);
1171 ret = rtl28xx_wr_reg(d, IR_RX_BUF_CTRL, 0x80);
1172 ret = rtl28xx_wr_reg(d, IR_RX_CTRL, 0x80);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001173
1174exit:
1175 return ret;
1176err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001177 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001178 return ret;
1179}
1180
Antti Palosaaric01a3592012-08-12 22:27:07 -03001181static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1182 struct dvb_usb_rc *rc)
1183{
1184 rc->map_name = RC_MAP_EMPTY;
1185 rc->allowed_protos = RC_TYPE_NEC;
1186 rc->query = rtl2832u_rc_query;
1187 rc->interval = 400;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001188
Antti Palosaaric01a3592012-08-12 22:27:07 -03001189 return 0;
1190}
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001191
Antti Palosaaric01a3592012-08-12 22:27:07 -03001192static const struct dvb_usb_device_properties rtl2831u_props = {
1193 .driver_name = KBUILD_MODNAME,
1194 .owner = THIS_MODULE,
1195 .adapter_nr = adapter_nr,
1196 .size_of_priv = sizeof(struct rtl28xxu_priv),
Antti Palosaari831e0b72011-07-08 23:36:07 -03001197
Antti Palosaaric01a3592012-08-12 22:27:07 -03001198 .power_ctrl = rtl2831u_power_ctrl,
1199 .i2c_algo = &rtl28xxu_i2c_algo,
1200 .frontend_attach = rtl2831u_frontend_attach,
1201 .tuner_attach = rtl2831u_tuner_attach,
1202 .init = rtl28xxu_init,
1203 .get_rc_config = rtl2831u_get_rc_config,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001204
Antti Palosaaric01a3592012-08-12 22:27:07 -03001205 .num_adapters = 1,
1206 .adapter = {
1207 {
1208 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaari831e0b72011-07-08 23:36:07 -03001209 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001210 },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001211};
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001212
Antti Palosaaric01a3592012-08-12 22:27:07 -03001213static const struct dvb_usb_device_properties rtl2832u_props = {
1214 .driver_name = KBUILD_MODNAME,
1215 .owner = THIS_MODULE,
1216 .adapter_nr = adapter_nr,
1217 .size_of_priv = sizeof(struct rtl28xxu_priv),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001218
Antti Palosaaric01a3592012-08-12 22:27:07 -03001219 .power_ctrl = rtl2832u_power_ctrl,
1220 .i2c_algo = &rtl28xxu_i2c_algo,
1221 .frontend_attach = rtl2832u_frontend_attach,
1222 .tuner_attach = rtl2832u_tuner_attach,
1223 .init = rtl28xxu_init,
1224 .get_rc_config = rtl2832u_get_rc_config,
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001225
Antti Palosaaric01a3592012-08-12 22:27:07 -03001226 .num_adapters = 1,
1227 .adapter = {
1228 {
1229 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001230 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001231 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001232};
1233
Antti Palosaaric01a3592012-08-12 22:27:07 -03001234static const struct usb_device_id rtl28xxu_id_table[] = {
1235 { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U,
1236 &rtl2831u_props, "Realtek RTL2831U reference design", NULL) },
1237 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT,
1238 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
1239 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2,
1240 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001241
Antti Palosaaric01a3592012-08-12 22:27:07 -03001242 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
1243 &rtl2832u_props, "Terratec Cinergy T Stick Black", NULL) },
1244 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
1245 &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
1246 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
1247 &rtl2832u_props, "NOXON DAB/DAB+ USB dongle", NULL) },
Antti Palosaari542f6a52012-09-01 21:09:22 -03001248 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
1249 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
Philipp Dreimann6d608052012-09-02 19:30:54 -03001250 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0,
1251 &rtl2832u_props, "Trekstor DVB-T Stick Terres 2.0", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001252 { }
1253};
1254MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001255
Antti Palosaaric01a3592012-08-12 22:27:07 -03001256static struct usb_driver rtl28xxu_usb_driver = {
1257 .name = KBUILD_MODNAME,
1258 .id_table = rtl28xxu_id_table,
1259 .probe = dvb_usbv2_probe,
1260 .disconnect = dvb_usbv2_disconnect,
1261 .suspend = dvb_usbv2_suspend,
1262 .resume = dvb_usbv2_resume,
Antti Palosaari78fa5902012-08-14 22:21:09 -03001263 .reset_resume = dvb_usbv2_reset_resume,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001264 .no_dynamic_id = 1,
1265 .soft_unbind = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001266};
1267
Antti Palosaaric01a3592012-08-12 22:27:07 -03001268module_usb_driver(rtl28xxu_usb_driver);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001269
1270MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
1271MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
Thomas Mair5cf66312012-05-18 14:47:41 -03001272MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>");
Antti Palosaari831e0b72011-07-08 23:36:07 -03001273MODULE_LICENSE("GPL");