blob: 2bb71056ec3b859baa4ec5b5a1f1e26f59ec4feb [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
Antti Palosaari94b5fa62013-11-22 14:20:14 -030025static int rtl28xxu_disable_rc;
26module_param_named(disable_rc, rtl28xxu_disable_rc, int, 0644);
27MODULE_PARM_DESC(disable_rc, "disable RTL2832U remote controller");
Antti Palosaari831e0b72011-07-08 23:36:07 -030028DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
29
30static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
31{
Antti Palosaaric56222a2014-12-21 18:33:14 -030032 struct rtl28xxu_dev *dev = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -030033 int ret;
34 unsigned int pipe;
35 u8 requesttype;
Antti Palosaari831e0b72011-07-08 23:36:07 -030036
37 if (req->index & CMD_WR_FLAG) {
38 /* write */
Antti Palosaaric56222a2014-12-21 18:33:14 -030039 memcpy(dev->buf, req->data, req->size);
Antti Palosaari831e0b72011-07-08 23:36:07 -030040 requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT);
41 pipe = usb_sndctrlpipe(d->udev, 0);
42 } else {
43 /* read */
44 requesttype = (USB_TYPE_VENDOR | USB_DIR_IN);
45 pipe = usb_rcvctrlpipe(d->udev, 0);
46 }
47
48 ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value,
Antti Palosaaric56222a2014-12-21 18:33:14 -030049 req->index, dev->buf, req->size, 1000);
Antti Palosaarid89b9362012-08-22 19:42:00 -030050 dvb_usb_dbg_usb_control_msg(d->udev, 0, requesttype, req->value,
Antti Palosaaric56222a2014-12-21 18:33:14 -030051 req->index, dev->buf, req->size);
52 if (ret < 0)
Antti Palosaari9935eea2012-01-21 22:26:52 -030053 goto err;
54
Antti Palosaaric56222a2014-12-21 18:33:14 -030055 /* read request, copy returned data to return buf */
56 if (requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
57 memcpy(req->data, dev->buf, req->size);
58
59 return 0;
Antti Palosaari831e0b72011-07-08 23:36:07 -030060err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -030061 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -030062 return ret;
63}
64
Antti Palosaari670ef052014-12-23 14:32:35 -030065static int rtl28xxu_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
Antti Palosaari831e0b72011-07-08 23:36:07 -030066{
67 struct rtl28xxu_req req;
68
69 if (reg < 0x3000)
70 req.index = CMD_USB_WR;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -030071 else if (reg < 0x4000)
Antti Palosaari831e0b72011-07-08 23:36:07 -030072 req.index = CMD_SYS_WR;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -030073 else
74 req.index = CMD_IR_WR;
Antti Palosaari831e0b72011-07-08 23:36:07 -030075
76 req.value = reg;
77 req.size = len;
78 req.data = val;
79
80 return rtl28xxu_ctrl_msg(d, &req);
81}
82
Antti Palosaari670ef052014-12-23 14:32:35 -030083static int rtl28xxu_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
Antti Palosaari831e0b72011-07-08 23:36:07 -030084{
85 struct rtl28xxu_req req;
86
87 if (reg < 0x3000)
88 req.index = CMD_USB_RD;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -030089 else if (reg < 0x4000)
Antti Palosaari831e0b72011-07-08 23:36:07 -030090 req.index = CMD_SYS_RD;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -030091 else
92 req.index = CMD_IR_RD;
Antti Palosaari831e0b72011-07-08 23:36:07 -030093
94 req.value = reg;
95 req.size = len;
96 req.data = val;
97
98 return rtl28xxu_ctrl_msg(d, &req);
99}
100
Antti Palosaari670ef052014-12-23 14:32:35 -0300101static int rtl28xxu_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300102{
Antti Palosaari670ef052014-12-23 14:32:35 -0300103 return rtl28xxu_wr_regs(d, reg, &val, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300104}
105
Antti Palosaari670ef052014-12-23 14:32:35 -0300106static int rtl28xxu_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300107{
Antti Palosaari670ef052014-12-23 14:32:35 -0300108 return rtl28xxu_rd_regs(d, reg, val, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300109}
110
Antti Palosaari670ef052014-12-23 14:32:35 -0300111static int rtl28xxu_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300112 u8 mask)
113{
114 int ret;
115 u8 tmp;
116
117 /* no need for read if whole reg is written */
118 if (mask != 0xff) {
Antti Palosaari670ef052014-12-23 14:32:35 -0300119 ret = rtl28xxu_rd_reg(d, reg, &tmp);
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300120 if (ret)
121 return ret;
122
123 val &= mask;
124 tmp &= ~mask;
125 val |= tmp;
126 }
127
Antti Palosaari670ef052014-12-23 14:32:35 -0300128 return rtl28xxu_wr_reg(d, reg, val);
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300129}
130
Antti Palosaari831e0b72011-07-08 23:36:07 -0300131/* I2C */
132static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
133 int num)
134{
135 int ret;
136 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300137 struct rtl28xxu_dev *dev = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300138 struct rtl28xxu_req req;
139
140 /*
141 * It is not known which are real I2C bus xfer limits, but testing
142 * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes.
Antti Palosaari34ec2932011-08-04 20:21:16 -0300143 * TODO: find out RTL2832U lens
144 */
145
146 /*
147 * I2C adapter logic looks rather complicated due to fact it handles
148 * three different access methods. Those methods are;
149 * 1) integrated demod access
150 * 2) old I2C access
151 * 3) new I2C access
152 *
153 * Used method is selected in order 1, 2, 3. Method 3 can handle all
154 * requests but there is two reasons why not use it always;
155 * 1) It is most expensive, usually two USB messages are needed
156 * 2) At least RTL2831U does not support it
157 *
158 * Method 3 is needed in case of I2C write+read (typical register read)
159 * where write is more than one byte.
Antti Palosaari831e0b72011-07-08 23:36:07 -0300160 */
161
162 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
163 return -EAGAIN;
164
165 if (num == 2 && !(msg[0].flags & I2C_M_RD) &&
166 (msg[1].flags & I2C_M_RD)) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300167 if (msg[0].len > 24 || msg[1].len > 24) {
168 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300169 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300170 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300171 } else if (msg[0].addr == 0x10) {
172 /* method 1 - integrated demod */
173 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300174 req.index = CMD_DEMOD_RD | dev->page;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300175 req.size = msg[1].len;
176 req.data = &msg[1].buf[0];
177 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300178 } else if (msg[0].len < 2) {
179 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300180 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
181 req.index = CMD_I2C_RD;
182 req.size = msg[1].len;
183 req.data = &msg[1].buf[0];
184 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300185 } else {
186 /* method 3 - new I2C */
187 req.value = (msg[0].addr << 1);
188 req.index = CMD_I2C_DA_WR;
189 req.size = msg[0].len;
190 req.data = msg[0].buf;
191 ret = rtl28xxu_ctrl_msg(d, &req);
192 if (ret)
Antti Palosaari9935eea2012-01-21 22:26:52 -0300193 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300194
195 req.value = (msg[0].addr << 1);
196 req.index = CMD_I2C_DA_RD;
197 req.size = msg[1].len;
198 req.data = msg[1].buf;
199 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300200 }
201 } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
202 if (msg[0].len > 22) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300203 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300204 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300205 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300206 } else if (msg[0].addr == 0x10) {
207 /* method 1 - integrated demod */
208 if (msg[0].buf[0] == 0x00) {
209 /* save demod page for later demod access */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300210 dev->page = msg[0].buf[1];
Antti Palosaari34ec2932011-08-04 20:21:16 -0300211 ret = 0;
212 } else {
213 req.value = (msg[0].buf[0] << 8) |
214 (msg[0].addr << 1);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300215 req.index = CMD_DEMOD_WR | dev->page;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300216 req.size = msg[0].len-1;
217 req.data = &msg[0].buf[1];
218 ret = rtl28xxu_ctrl_msg(d, &req);
219 }
Olli Salonen699dcff2015-05-05 13:54:19 -0300220 } else if ((msg[0].len < 23) && (!dev->new_i2c_write)) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300221 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300222 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
223 req.index = CMD_I2C_WR;
224 req.size = msg[0].len-1;
225 req.data = &msg[0].buf[1];
226 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300227 } else {
228 /* method 3 - new I2C */
229 req.value = (msg[0].addr << 1);
230 req.index = CMD_I2C_DA_WR;
231 req.size = msg[0].len;
232 req.data = msg[0].buf;
233 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300234 }
Olli Salonend744a0c2015-05-05 13:54:18 -0300235 } else if (num == 1 && (msg[0].flags & I2C_M_RD)) {
236 req.value = (msg[0].addr << 1);
237 req.index = CMD_I2C_DA_RD;
238 req.size = msg[0].len;
239 req.data = msg[0].buf;
240 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300241 } else {
Olli Salonend744a0c2015-05-05 13:54:18 -0300242 ret = -EOPNOTSUPP;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300243 }
244
Antti Palosaari9935eea2012-01-21 22:26:52 -0300245err_mutex_unlock:
Antti Palosaari831e0b72011-07-08 23:36:07 -0300246 mutex_unlock(&d->i2c_mutex);
247
248 return ret ? ret : num;
249}
250
251static u32 rtl28xxu_i2c_func(struct i2c_adapter *adapter)
252{
253 return I2C_FUNC_I2C;
254}
255
256static struct i2c_algorithm rtl28xxu_i2c_algo = {
257 .master_xfer = rtl28xxu_i2c_xfer,
258 .functionality = rtl28xxu_i2c_func,
259};
260
Antti Palosaari81347f52012-09-17 16:50:36 -0300261static int rtl2831u_read_config(struct dvb_usb_device *d)
262{
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300263 struct rtl28xxu_dev *dev = d_to_priv(d);
Antti Palosaari81347f52012-09-17 16:50:36 -0300264 int ret;
265 u8 buf[1];
266 /* open RTL2831U/RTL2830 I2C gate */
267 struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x08"};
268 /* tuner probes */
269 struct rtl28xxu_req req_mt2060 = {0x00c0, CMD_I2C_RD, 1, buf};
270 struct rtl28xxu_req req_qt1010 = {0x0fc4, CMD_I2C_RD, 1, buf};
271
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300272 dev_dbg(&d->intf->dev, "\n");
Antti Palosaari81347f52012-09-17 16:50:36 -0300273
274 /*
275 * RTL2831U GPIOs
276 * =========================================================
277 * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?)
278 * GPIO2 | LED | 0 off | 1 on |
279 * GPIO4 | tuner#1 | 0 on | 1 off | MT2060
280 */
281
282 /* GPIO direction */
Antti Palosaari670ef052014-12-23 14:32:35 -0300283 ret = rtl28xxu_wr_reg(d, SYS_GPIO_DIR, 0x0a);
Antti Palosaari81347f52012-09-17 16:50:36 -0300284 if (ret)
285 goto err;
286
287 /* enable as output GPIO0, GPIO2, GPIO4 */
Antti Palosaari670ef052014-12-23 14:32:35 -0300288 ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_EN, 0x15);
Antti Palosaari81347f52012-09-17 16:50:36 -0300289 if (ret)
290 goto err;
291
292 /*
293 * Probe used tuner. We need to know used tuner before demod attach
294 * since there is some demod params needed to set according to tuner.
295 */
296
297 /* demod needs some time to wake up */
298 msleep(20);
299
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300300 dev->tuner_name = "NONE";
Antti Palosaari81347f52012-09-17 16:50:36 -0300301
302 /* open demod I2C gate */
303 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
304 if (ret)
305 goto err;
306
307 /* check QT1010 ID(?) register; reg=0f val=2c */
308 ret = rtl28xxu_ctrl_msg(d, &req_qt1010);
309 if (ret == 0 && buf[0] == 0x2c) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300310 dev->tuner = TUNER_RTL2830_QT1010;
311 dev->tuner_name = "QT1010";
Antti Palosaari81347f52012-09-17 16:50:36 -0300312 goto found;
313 }
314
315 /* open demod I2C gate */
316 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
317 if (ret)
318 goto err;
319
320 /* check MT2060 ID register; reg=00 val=63 */
321 ret = rtl28xxu_ctrl_msg(d, &req_mt2060);
322 if (ret == 0 && buf[0] == 0x63) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300323 dev->tuner = TUNER_RTL2830_MT2060;
324 dev->tuner_name = "MT2060";
Antti Palosaari81347f52012-09-17 16:50:36 -0300325 goto found;
326 }
327
328 /* assume MXL5005S */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300329 dev->tuner = TUNER_RTL2830_MXL5005S;
330 dev->tuner_name = "MXL5005S";
Antti Palosaari81347f52012-09-17 16:50:36 -0300331 goto found;
332
333found:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300334 dev_dbg(&d->intf->dev, "tuner=%s\n", dev->tuner_name);
Antti Palosaari81347f52012-09-17 16:50:36 -0300335
336 return 0;
337err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300338 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari81347f52012-09-17 16:50:36 -0300339 return ret;
340}
341
Antti Palosaarief37be12012-09-17 14:01:35 -0300342static int rtl2832u_read_config(struct dvb_usb_device *d)
343{
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300344 struct rtl28xxu_dev *dev = d_to_priv(d);
Antti Palosaarief37be12012-09-17 14:01:35 -0300345 int ret;
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300346 u8 buf[2];
Antti Palosaarief37be12012-09-17 14:01:35 -0300347 /* open RTL2832U/RTL2832 I2C gate */
348 struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"};
349 /* close RTL2832U/RTL2832 I2C gate */
350 struct rtl28xxu_req req_gate_close = {0x0120, 0x0011, 0x0001, "\x10"};
351 /* tuner probes */
352 struct rtl28xxu_req req_fc0012 = {0x00c6, CMD_I2C_RD, 1, buf};
353 struct rtl28xxu_req req_fc0013 = {0x00c6, CMD_I2C_RD, 1, buf};
354 struct rtl28xxu_req req_mt2266 = {0x00c0, CMD_I2C_RD, 1, buf};
355 struct rtl28xxu_req req_fc2580 = {0x01ac, CMD_I2C_RD, 1, buf};
356 struct rtl28xxu_req req_mt2063 = {0x00c0, CMD_I2C_RD, 1, buf};
357 struct rtl28xxu_req req_max3543 = {0x00c0, CMD_I2C_RD, 1, buf};
358 struct rtl28xxu_req req_tua9001 = {0x7ec0, CMD_I2C_RD, 2, buf};
359 struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf};
360 struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
361 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
Gianluca Gennaria908eb92013-06-02 17:24:24 -0300362 struct rtl28xxu_req req_r820t = {0x0034, CMD_I2C_RD, 1, buf};
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300363 struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf};
Antti Palosaari80f189a2013-12-01 13:44:23 -0300364 struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf};
Antti Palosaarifc694e42014-09-30 01:03:04 -0300365 struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf};
Olli Salonen699dcff2015-05-05 13:54:19 -0300366 struct rtl28xxu_req req_si2157 = {0x00c0, CMD_I2C_RD, 1, buf};
367 struct rtl28xxu_req req_si2168 = {0x00c8, CMD_I2C_RD, 1, buf};
Antti Palosaarief37be12012-09-17 14:01:35 -0300368
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300369 dev_dbg(&d->intf->dev, "\n");
Antti Palosaarief37be12012-09-17 14:01:35 -0300370
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300371 /* enable GPIO3 and GPIO6 as output */
Antti Palosaari670ef052014-12-23 14:32:35 -0300372 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x40);
Antti Palosaarief37be12012-09-17 14:01:35 -0300373 if (ret)
374 goto err;
375
Antti Palosaari670ef052014-12-23 14:32:35 -0300376 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x48, 0x48);
Antti Palosaarief37be12012-09-17 14:01:35 -0300377 if (ret)
378 goto err;
379
380 /*
381 * Probe used tuner. We need to know used tuner before demod attach
382 * since there is some demod params needed to set according to tuner.
383 */
384
385 /* open demod I2C gate */
386 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
387 if (ret)
388 goto err;
389
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300390 dev->tuner_name = "NONE";
Antti Palosaarief37be12012-09-17 14:01:35 -0300391
392 /* check FC0012 ID register; reg=00 val=a1 */
393 ret = rtl28xxu_ctrl_msg(d, &req_fc0012);
394 if (ret == 0 && buf[0] == 0xa1) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300395 dev->tuner = TUNER_RTL2832_FC0012;
396 dev->tuner_name = "FC0012";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300397 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300398 }
399
400 /* check FC0013 ID register; reg=00 val=a3 */
401 ret = rtl28xxu_ctrl_msg(d, &req_fc0013);
402 if (ret == 0 && buf[0] == 0xa3) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300403 dev->tuner = TUNER_RTL2832_FC0013;
404 dev->tuner_name = "FC0013";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300405 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300406 }
407
408 /* check MT2266 ID register; reg=00 val=85 */
409 ret = rtl28xxu_ctrl_msg(d, &req_mt2266);
410 if (ret == 0 && buf[0] == 0x85) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300411 dev->tuner = TUNER_RTL2832_MT2266;
412 dev->tuner_name = "MT2266";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300413 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300414 }
415
416 /* check FC2580 ID register; reg=01 val=56 */
417 ret = rtl28xxu_ctrl_msg(d, &req_fc2580);
418 if (ret == 0 && buf[0] == 0x56) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300419 dev->tuner = TUNER_RTL2832_FC2580;
420 dev->tuner_name = "FC2580";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300421 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300422 }
423
424 /* check MT2063 ID register; reg=00 val=9e || 9c */
425 ret = rtl28xxu_ctrl_msg(d, &req_mt2063);
426 if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300427 dev->tuner = TUNER_RTL2832_MT2063;
428 dev->tuner_name = "MT2063";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300429 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300430 }
431
432 /* check MAX3543 ID register; reg=00 val=38 */
433 ret = rtl28xxu_ctrl_msg(d, &req_max3543);
434 if (ret == 0 && buf[0] == 0x38) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300435 dev->tuner = TUNER_RTL2832_MAX3543;
436 dev->tuner_name = "MAX3543";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300437 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300438 }
439
440 /* check TUA9001 ID register; reg=7e val=2328 */
441 ret = rtl28xxu_ctrl_msg(d, &req_tua9001);
442 if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300443 dev->tuner = TUNER_RTL2832_TUA9001;
444 dev->tuner_name = "TUA9001";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300445 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300446 }
447
448 /* check MXL5007R ID register; reg=d9 val=14 */
449 ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t);
450 if (ret == 0 && buf[0] == 0x14) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300451 dev->tuner = TUNER_RTL2832_MXL5007T;
452 dev->tuner_name = "MXL5007T";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300453 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300454 }
455
456 /* check E4000 ID register; reg=02 val=40 */
457 ret = rtl28xxu_ctrl_msg(d, &req_e4000);
458 if (ret == 0 && buf[0] == 0x40) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300459 dev->tuner = TUNER_RTL2832_E4000;
460 dev->tuner_name = "E4000";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300461 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300462 }
463
464 /* check TDA18272 ID register; reg=00 val=c760 */
465 ret = rtl28xxu_ctrl_msg(d, &req_tda18272);
466 if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300467 dev->tuner = TUNER_RTL2832_TDA18272;
468 dev->tuner_name = "TDA18272";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300469 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300470 }
471
Gianluca Gennaria908eb92013-06-02 17:24:24 -0300472 /* check R820T ID register; reg=00 val=69 */
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300473 ret = rtl28xxu_ctrl_msg(d, &req_r820t);
Gianluca Gennaria908eb92013-06-02 17:24:24 -0300474 if (ret == 0 && buf[0] == 0x69) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300475 dev->tuner = TUNER_RTL2832_R820T;
476 dev->tuner_name = "R820T";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300477 goto tuner_found;
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300478 }
479
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300480 /* check R828D ID register; reg=00 val=69 */
481 ret = rtl28xxu_ctrl_msg(d, &req_r828d);
482 if (ret == 0 && buf[0] == 0x69) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300483 dev->tuner = TUNER_RTL2832_R828D;
484 dev->tuner_name = "R828D";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300485 goto tuner_found;
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300486 }
487
Olli Salonen699dcff2015-05-05 13:54:19 -0300488 /* GPIO0 and GPIO5 to reset Si2157/Si2168 tuner and demod */
489 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x00, 0x21);
490 if (ret)
491 goto err;
492
493 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x00, 0x21);
494 if (ret)
495 goto err;
496
497 msleep(50);
498
499 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x21, 0x21);
500 if (ret)
501 goto err;
502
503 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x21, 0x21);
504 if (ret)
505 goto err;
506
507 msleep(50);
508
509 /* check Si2157 ID register; reg=c0 val=80 */
510 ret = rtl28xxu_ctrl_msg(d, &req_si2157);
511 if (ret == 0 && ((buf[0] & 0x80) == 0x80)) {
512 dev->tuner = TUNER_RTL2832_SI2157;
513 dev->tuner_name = "SI2157";
514 goto tuner_found;
515 }
516
Antti Palosaari80f189a2013-12-01 13:44:23 -0300517tuner_found:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300518 dev_dbg(&d->intf->dev, "tuner=%s\n", dev->tuner_name);
Antti Palosaarief37be12012-09-17 14:01:35 -0300519
Antti Palosaari80f189a2013-12-01 13:44:23 -0300520 /* probe slave demod */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300521 if (dev->tuner == TUNER_RTL2832_R828D) {
Antti Palosaari80f189a2013-12-01 13:44:23 -0300522 /* power on MN88472 demod on GPIO0 */
Antti Palosaari670ef052014-12-23 14:32:35 -0300523 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x01, 0x01);
Antti Palosaari80f189a2013-12-01 13:44:23 -0300524 if (ret)
525 goto err;
526
Antti Palosaari670ef052014-12-23 14:32:35 -0300527 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x01);
Antti Palosaari80f189a2013-12-01 13:44:23 -0300528 if (ret)
529 goto err;
530
Antti Palosaari670ef052014-12-23 14:32:35 -0300531 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x01, 0x01);
Antti Palosaari80f189a2013-12-01 13:44:23 -0300532 if (ret)
533 goto err;
534
535 /* check MN88472 answers */
536 ret = rtl28xxu_ctrl_msg(d, &req_mn88472);
537 if (ret == 0 && buf[0] == 0x02) {
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300538 dev_dbg(&d->intf->dev, "MN88472 found\n");
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300539 dev->slave_demod = SLAVE_DEMOD_MN88472;
Antti Palosaari80f189a2013-12-01 13:44:23 -0300540 goto demod_found;
541 }
Antti Palosaarifc694e42014-09-30 01:03:04 -0300542
543 ret = rtl28xxu_ctrl_msg(d, &req_mn88473);
544 if (ret == 0 && buf[0] == 0x03) {
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300545 dev_dbg(&d->intf->dev, "MN88473 found\n");
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300546 dev->slave_demod = SLAVE_DEMOD_MN88473;
Antti Palosaarifc694e42014-09-30 01:03:04 -0300547 goto demod_found;
548 }
Antti Palosaari80f189a2013-12-01 13:44:23 -0300549 }
Olli Salonen699dcff2015-05-05 13:54:19 -0300550 if (dev->tuner == TUNER_RTL2832_SI2157) {
551 /* check Si2168 ID register; reg=c8 val=80 */
552 ret = rtl28xxu_ctrl_msg(d, &req_si2168);
553 if (ret == 0 && ((buf[0] & 0x80) == 0x80)) {
554 dev_dbg(&d->intf->dev, "Si2168 found\n");
555 dev->slave_demod = SLAVE_DEMOD_SI2168;
556 goto demod_found;
557 }
558 }
Antti Palosaari80f189a2013-12-01 13:44:23 -0300559
560demod_found:
Antti Palosaarief37be12012-09-17 14:01:35 -0300561 /* close demod I2C gate */
562 ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
563 if (ret < 0)
564 goto err;
565
566 return 0;
567err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300568 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaarief37be12012-09-17 14:01:35 -0300569 return ret;
570}
571
Antti Palosaaride701f02014-12-23 14:09:13 -0300572static int rtl28xxu_read_config(struct dvb_usb_device *d)
573{
574 struct rtl28xxu_dev *dev = d_to_priv(d);
575
576 if (dev->chip_id == CHIP_ID_RTL2831U)
577 return rtl2831u_read_config(d);
578 else
579 return rtl2832u_read_config(d);
580}
581
Antti Palosaarid0f232e2014-12-23 13:14:36 -0300582static int rtl28xxu_identify_state(struct dvb_usb_device *d, const char **name)
583{
584 struct rtl28xxu_dev *dev = d_to_priv(d);
585 int ret;
586 struct rtl28xxu_req req_demod_i2c = {0x0020, CMD_I2C_DA_RD, 0, NULL};
587
588 dev_dbg(&d->intf->dev, "\n");
589
590 /*
591 * Detect chip type using I2C command that is not supported
592 * by old RTL2831U.
593 */
594 ret = rtl28xxu_ctrl_msg(d, &req_demod_i2c);
595 if (ret == -EPIPE) {
596 dev->chip_id = CHIP_ID_RTL2831U;
597 } else if (ret == 0) {
598 dev->chip_id = CHIP_ID_RTL2832U;
599 } else {
600 dev_err(&d->intf->dev, "chip type detection failed %d\n", ret);
601 goto err;
602 }
603 dev_dbg(&d->intf->dev, "chip_id=%u\n", dev->chip_id);
604
605 return WARM;
606err:
607 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
608 return ret;
609}
610
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300611static const struct rtl2830_platform_data rtl2830_mt2060_platform_data = {
612 .clk = 28800000,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300613 .spec_inv = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300614 .vtop = 0x20,
615 .krf = 0x04,
616 .agc_targ_val = 0x2d,
617
618};
619
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300620static const struct rtl2830_platform_data rtl2830_qt1010_platform_data = {
621 .clk = 28800000,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300622 .spec_inv = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300623 .vtop = 0x20,
624 .krf = 0x04,
625 .agc_targ_val = 0x2d,
626};
627
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300628static const struct rtl2830_platform_data rtl2830_mxl5005s_platform_data = {
629 .clk = 28800000,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300630 .spec_inv = 0,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300631 .vtop = 0x3f,
632 .krf = 0x04,
633 .agc_targ_val = 0x3e,
634};
635
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300636static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300637{
Antti Palosaaric01a3592012-08-12 22:27:07 -0300638 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300639 struct rtl28xxu_dev *dev = d_to_priv(d);
640 struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data;
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300641 struct i2c_board_info board_info;
642 struct i2c_client *client;
Antti Palosaari81347f52012-09-17 16:50:36 -0300643 int ret;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300644
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300645 dev_dbg(&d->intf->dev, "\n");
Antti Palosaari831e0b72011-07-08 23:36:07 -0300646
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300647 switch (dev->tuner) {
Antti Palosaari81347f52012-09-17 16:50:36 -0300648 case TUNER_RTL2830_QT1010:
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300649 *pdata = rtl2830_qt1010_platform_data;
Antti Palosaari81347f52012-09-17 16:50:36 -0300650 break;
651 case TUNER_RTL2830_MT2060:
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300652 *pdata = rtl2830_mt2060_platform_data;
Antti Palosaari81347f52012-09-17 16:50:36 -0300653 break;
654 case TUNER_RTL2830_MXL5005S:
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300655 *pdata = rtl2830_mxl5005s_platform_data;
Antti Palosaari81347f52012-09-17 16:50:36 -0300656 break;
657 default:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300658 dev_err(&d->intf->dev, "unknown tuner %s\n", dev->tuner_name);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300659 ret = -ENODEV;
660 goto err;
661 }
662
Antti Palosaari81347f52012-09-17 16:50:36 -0300663 /* attach demodulator */
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300664 memset(&board_info, 0, sizeof(board_info));
665 strlcpy(board_info.type, "rtl2830", I2C_NAME_SIZE);
666 board_info.addr = 0x10;
667 board_info.platform_data = pdata;
668 request_module("%s", board_info.type);
669 client = i2c_new_device(&d->i2c_adap, &board_info);
670 if (client == NULL || client->dev.driver == NULL) {
Antti Palosaari81347f52012-09-17 16:50:36 -0300671 ret = -ENODEV;
672 goto err;
673 }
674
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300675 if (!try_module_get(client->dev.driver->owner)) {
676 i2c_unregister_device(client);
677 ret = -ENODEV;
678 goto err;
679 }
680
681 adap->fe[0] = pdata->get_dvb_frontend(client);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300682 dev->demod_i2c_adapter = pdata->get_i2c_adapter(client);
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300683
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300684 dev->i2c_client_demod = client;
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300685
Antti Palosaari81347f52012-09-17 16:50:36 -0300686 return 0;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300687err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300688 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300689 return ret;
690}
691
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300692static const struct rtl2832_platform_data rtl2832_fc0012_platform_data = {
693 .clk = 28800000,
694 .tuner = TUNER_RTL2832_FC0012
695};
696
697static const struct rtl2832_platform_data rtl2832_fc0013_platform_data = {
698 .clk = 28800000,
699 .tuner = TUNER_RTL2832_FC0013
700};
701
702static const struct rtl2832_platform_data rtl2832_tua9001_platform_data = {
703 .clk = 28800000,
704 .tuner = TUNER_RTL2832_TUA9001,
705};
706
707static const struct rtl2832_platform_data rtl2832_e4000_platform_data = {
708 .clk = 28800000,
709 .tuner = TUNER_RTL2832_E4000,
710};
711
712static const struct rtl2832_platform_data rtl2832_r820t_platform_data = {
713 .clk = 28800000,
714 .tuner = TUNER_RTL2832_R820T,
715};
716
Olli Salonen699dcff2015-05-05 13:54:19 -0300717static const struct rtl2832_platform_data rtl2832_si2157_platform_data = {
718 .clk = 28800000,
719 .tuner = TUNER_RTL2832_SI2157,
720};
721
Thomas Mair5cf66312012-05-18 14:47:41 -0300722static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
723 int cmd, int arg)
724{
725 int ret;
726 u8 val;
727
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300728 dev_dbg(&d->intf->dev, "cmd=%d arg=%d\n", cmd, arg);
Antti Palosaaric01a3592012-08-12 22:27:07 -0300729
Thomas Mair5cf66312012-05-18 14:47:41 -0300730 switch (cmd) {
731 case FC_FE_CALLBACK_VHF_ENABLE:
732 /* set output values */
Antti Palosaari670ef052014-12-23 14:32:35 -0300733 ret = rtl28xxu_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300734 if (ret)
735 goto err;
736
737 if (arg)
738 val &= 0xbf; /* set GPIO6 low */
739 else
740 val |= 0x40; /* set GPIO6 high */
741
742
Antti Palosaari670ef052014-12-23 14:32:35 -0300743 ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300744 if (ret)
745 goto err;
746 break;
747 default:
748 ret = -EINVAL;
749 goto err;
750 }
751 return 0;
Thomas Mair5cf66312012-05-18 14:47:41 -0300752err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300753 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Thomas Mair5cf66312012-05-18 14:47:41 -0300754 return ret;
755}
756
Antti Palosaari5be65722012-09-11 22:27:09 -0300757static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d,
758 int cmd, int arg)
759{
760 int ret;
761 u8 val;
762
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300763 dev_dbg(&d->intf->dev, "cmd=%d arg=%d\n", cmd, arg);
Antti Palosaari5be65722012-09-11 22:27:09 -0300764
765 /*
766 * CEN always enabled by hardware wiring
767 * RESETN GPIO4
768 * RXEN GPIO1
769 */
770
Antti Palosaari5be65722012-09-11 22:27:09 -0300771 switch (cmd) {
772 case TUA9001_CMD_RESETN:
773 if (arg)
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300774 val = (1 << 4);
Antti Palosaari5be65722012-09-11 22:27:09 -0300775 else
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300776 val = (0 << 4);
Antti Palosaari5be65722012-09-11 22:27:09 -0300777
Antti Palosaari670ef052014-12-23 14:32:35 -0300778 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x10);
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300779 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300780 goto err;
781 break;
782 case TUA9001_CMD_RXEN:
783 if (arg)
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300784 val = (1 << 1);
Antti Palosaari5be65722012-09-11 22:27:09 -0300785 else
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300786 val = (0 << 1);
Antti Palosaari5be65722012-09-11 22:27:09 -0300787
Antti Palosaari670ef052014-12-23 14:32:35 -0300788 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x02);
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300789 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300790 goto err;
791 break;
792 }
793
794 return 0;
Antti Palosaari5be65722012-09-11 22:27:09 -0300795err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300796 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari5be65722012-09-11 22:27:09 -0300797 return ret;
798}
799
Thomas Mair5cf66312012-05-18 14:47:41 -0300800static int rtl2832u_frontend_callback(void *adapter_priv, int component,
Antti Palosaari8acc91c2012-09-17 16:55:39 -0300801 int cmd, int arg)
Thomas Mair5cf66312012-05-18 14:47:41 -0300802{
Antti Palosaari1dbbdce2014-12-17 02:55:41 -0300803 struct i2c_adapter *adapter = adapter_priv;
804 struct device *parent = adapter->dev.parent;
805 struct i2c_adapter *parent_adapter;
806 struct dvb_usb_device *d;
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300807 struct rtl28xxu_dev *dev;
Antti Palosaari1dbbdce2014-12-17 02:55:41 -0300808
809 /*
810 * All tuners are connected to demod muxed I2C adapter. We have to
811 * resolve its parent adapter in order to get handle for this driver
812 * private data. That is a bit hackish solution, GPIO or direct driver
813 * callback would be better...
814 */
815 if (parent != NULL && parent->type == &i2c_adapter_type)
816 parent_adapter = to_i2c_adapter(parent);
817 else
818 return -EINVAL;
819
820 d = i2c_get_adapdata(parent_adapter);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300821 dev = d->priv;
Thomas Mair5cf66312012-05-18 14:47:41 -0300822
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300823 dev_dbg(&d->intf->dev, "component=%d cmd=%d arg=%d\n",
824 component, cmd, arg);
Antti Palosaari8acc91c2012-09-17 16:55:39 -0300825
Thomas Mair5cf66312012-05-18 14:47:41 -0300826 switch (component) {
827 case DVB_FRONTEND_COMPONENT_TUNER:
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300828 switch (dev->tuner) {
Antti Palosaaria6f62432014-12-17 03:09:32 -0300829 case TUNER_RTL2832_FC0012:
830 return rtl2832u_fc0012_tuner_callback(d, cmd, arg);
831 case TUNER_RTL2832_TUA9001:
832 return rtl2832u_tua9001_tuner_callback(d, cmd, arg);
833 }
Thomas Mair5cf66312012-05-18 14:47:41 -0300834 }
835
Antti Palosaari97efe782012-09-17 15:49:54 -0300836 return 0;
Thomas Mair5cf66312012-05-18 14:47:41 -0300837}
838
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300839static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
840{
Antti Palosaaric01a3592012-08-12 22:27:07 -0300841 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300842 struct rtl28xxu_dev *dev = d_to_priv(d);
843 struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data;
Antti Palosaari77a2e762014-12-13 00:09:57 -0300844 struct i2c_board_info board_info;
Antti Palosaari83b2f842014-12-02 11:00:23 -0300845 struct i2c_client *client;
Antti Palosaari77a2e762014-12-13 00:09:57 -0300846 int ret;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300847
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300848 dev_dbg(&d->intf->dev, "\n");
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300849
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300850 switch (dev->tuner) {
Antti Palosaarief37be12012-09-17 14:01:35 -0300851 case TUNER_RTL2832_FC0012:
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300852 *pdata = rtl2832_fc0012_platform_data;
Antti Palosaarief37be12012-09-17 14:01:35 -0300853 break;
854 case TUNER_RTL2832_FC0013:
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300855 *pdata = rtl2832_fc0013_platform_data;
Antti Palosaarief37be12012-09-17 14:01:35 -0300856 break;
857 case TUNER_RTL2832_FC2580:
Antti Palosaari384df492012-09-08 22:07:25 -0300858 /* FIXME: do not abuse fc0012 settings */
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300859 *pdata = rtl2832_fc0012_platform_data;
Antti Palosaarief37be12012-09-17 14:01:35 -0300860 break;
861 case TUNER_RTL2832_TUA9001:
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300862 *pdata = rtl2832_tua9001_platform_data;
Antti Palosaarief37be12012-09-17 14:01:35 -0300863 break;
864 case TUNER_RTL2832_E4000:
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300865 *pdata = rtl2832_e4000_platform_data;
Antti Palosaarief37be12012-09-17 14:01:35 -0300866 break;
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300867 case TUNER_RTL2832_R820T:
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300868 case TUNER_RTL2832_R828D:
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300869 *pdata = rtl2832_r820t_platform_data;
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300870 break;
Olli Salonen699dcff2015-05-05 13:54:19 -0300871 case TUNER_RTL2832_SI2157:
872 *pdata = rtl2832_si2157_platform_data;
873 break;
Antti Palosaarief37be12012-09-17 14:01:35 -0300874 default:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300875 dev_err(&d->intf->dev, "unknown tuner %s\n", dev->tuner_name);
Antti Palosaarief37be12012-09-17 14:01:35 -0300876 ret = -ENODEV;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300877 goto err;
Antti Palosaarief37be12012-09-17 14:01:35 -0300878 }
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300879
880 /* attach demodulator */
Antti Palosaari77a2e762014-12-13 00:09:57 -0300881 memset(&board_info, 0, sizeof(board_info));
Antti Palosaari83b2f842014-12-02 11:00:23 -0300882 strlcpy(board_info.type, "rtl2832", I2C_NAME_SIZE);
883 board_info.addr = 0x10;
Antti Palosaari77a2e762014-12-13 00:09:57 -0300884 board_info.platform_data = pdata;
Antti Palosaari83b2f842014-12-02 11:00:23 -0300885 request_module("%s", board_info.type);
886 client = i2c_new_device(&d->i2c_adap, &board_info);
887 if (client == NULL || client->dev.driver == NULL) {
Antti Palosaarief37be12012-09-17 14:01:35 -0300888 ret = -ENODEV;
889 goto err;
890 }
Thomas Mair5cf66312012-05-18 14:47:41 -0300891
Antti Palosaari83b2f842014-12-02 11:00:23 -0300892 if (!try_module_get(client->dev.driver->owner)) {
893 i2c_unregister_device(client);
894 ret = -ENODEV;
895 goto err;
896 }
897
Antti Palosaari77a2e762014-12-13 00:09:57 -0300898 adap->fe[0] = pdata->get_dvb_frontend(client);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300899 dev->demod_i2c_adapter = pdata->get_i2c_adapter(client);
Antti Palosaari83b2f842014-12-02 11:00:23 -0300900
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300901 dev->i2c_client_demod = client;
Antti Palosaariae1f8452014-02-08 04:03:57 -0300902
Antti Palosaarief37be12012-09-17 14:01:35 -0300903 /* set fe callback */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300904 adap->fe[0]->callback = rtl2832u_frontend_callback;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300905
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300906 if (dev->slave_demod) {
Antti Palosaari80f189a2013-12-01 13:44:23 -0300907 struct i2c_board_info info = {};
Antti Palosaari80f189a2013-12-01 13:44:23 -0300908
909 /*
910 * We continue on reduced mode, without DVB-T2/C, using master
911 * demod, when slave demod fails.
912 */
913 ret = 0;
914
915 /* attach slave demodulator */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300916 if (dev->slave_demod == SLAVE_DEMOD_MN88472) {
Antti Palosaari80f189a2013-12-01 13:44:23 -0300917 struct mn88472_config mn88472_config = {};
918
919 mn88472_config.fe = &adap->fe[1];
920 mn88472_config.i2c_wr_max = 22,
921 strlcpy(info.type, "mn88472", I2C_NAME_SIZE);
Benjamin Larssond2fb7852014-11-26 18:51:46 -0300922 mn88472_config.xtal = 20500000;
Benjamin Larsson021cd2d2014-12-05 21:25:33 -0300923 mn88472_config.ts_mode = SERIAL_TS_MODE;
924 mn88472_config.ts_clock = VARIABLE_TS_CLOCK;
Antti Palosaari80f189a2013-12-01 13:44:23 -0300925 info.addr = 0x18;
926 info.platform_data = &mn88472_config;
927 request_module(info.type);
Antti Palosaari488be132014-12-16 11:05:08 -0300928 client = i2c_new_device(&d->i2c_adap, &info);
Antti Palosaari80f189a2013-12-01 13:44:23 -0300929 if (client == NULL || client->dev.driver == NULL) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300930 dev->slave_demod = SLAVE_DEMOD_NONE;
Antti Palosaari80f189a2013-12-01 13:44:23 -0300931 goto err_slave_demod_failed;
932 }
933
934 if (!try_module_get(client->dev.driver->owner)) {
935 i2c_unregister_device(client);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300936 dev->slave_demod = SLAVE_DEMOD_NONE;
Antti Palosaari80f189a2013-12-01 13:44:23 -0300937 goto err_slave_demod_failed;
938 }
939
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300940 dev->i2c_client_slave_demod = client;
Olli Salonen699dcff2015-05-05 13:54:19 -0300941 } else if (dev->slave_demod == SLAVE_DEMOD_MN88473) {
Antti Palosaarifc694e42014-09-30 01:03:04 -0300942 struct mn88473_config mn88473_config = {};
943
944 mn88473_config.fe = &adap->fe[1];
945 mn88473_config.i2c_wr_max = 22,
946 strlcpy(info.type, "mn88473", I2C_NAME_SIZE);
947 info.addr = 0x18;
948 info.platform_data = &mn88473_config;
949 request_module(info.type);
Antti Palosaari488be132014-12-16 11:05:08 -0300950 client = i2c_new_device(&d->i2c_adap, &info);
Antti Palosaarifc694e42014-09-30 01:03:04 -0300951 if (client == NULL || client->dev.driver == NULL) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300952 dev->slave_demod = SLAVE_DEMOD_NONE;
Antti Palosaarifc694e42014-09-30 01:03:04 -0300953 goto err_slave_demod_failed;
954 }
955
956 if (!try_module_get(client->dev.driver->owner)) {
957 i2c_unregister_device(client);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300958 dev->slave_demod = SLAVE_DEMOD_NONE;
Antti Palosaarifc694e42014-09-30 01:03:04 -0300959 goto err_slave_demod_failed;
960 }
961
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300962 dev->i2c_client_slave_demod = client;
Olli Salonen699dcff2015-05-05 13:54:19 -0300963 } else {
964 struct si2168_config si2168_config = {};
965 struct i2c_adapter *adapter;
966
967 si2168_config.i2c_adapter = &adapter;
968 si2168_config.fe = &adap->fe[1];
969 si2168_config.ts_mode = SI2168_TS_SERIAL;
970 si2168_config.ts_clock_inv = false;
971 si2168_config.ts_clock_gapped = true;
972 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
973 info.addr = 0x64;
974 info.platform_data = &si2168_config;
975 request_module(info.type);
976 client = i2c_new_device(&d->i2c_adap, &info);
977 if (client == NULL || client->dev.driver == NULL) {
978 dev->slave_demod = SLAVE_DEMOD_NONE;
979 goto err_slave_demod_failed;
980 }
981
982 if (!try_module_get(client->dev.driver->owner)) {
983 i2c_unregister_device(client);
984 dev->slave_demod = SLAVE_DEMOD_NONE;
985 goto err_slave_demod_failed;
986 }
987
988 dev->i2c_client_slave_demod = client;
989
990 /* for Si2168 devices use only new I2C write method */
991 dev->new_i2c_write = true;
Antti Palosaari80f189a2013-12-01 13:44:23 -0300992 }
993 }
Antti Palosaarief37be12012-09-17 14:01:35 -0300994 return 0;
Antti Palosaari80f189a2013-12-01 13:44:23 -0300995err_slave_demod_failed:
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300996err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300997 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300998 return ret;
999}
1000
Antti Palosaaride701f02014-12-23 14:09:13 -03001001static int rtl28xxu_frontend_attach(struct dvb_usb_adapter *adap)
1002{
1003 struct rtl28xxu_dev *dev = adap_to_priv(adap);
1004
1005 if (dev->chip_id == CHIP_ID_RTL2831U)
1006 return rtl2831u_frontend_attach(adap);
1007 else
1008 return rtl2832u_frontend_attach(adap);
1009}
1010
1011static int rtl28xxu_frontend_detach(struct dvb_usb_adapter *adap)
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001012{
1013 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001014 struct rtl28xxu_dev *dev = d_to_priv(d);
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001015 struct i2c_client *client;
1016
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001017 dev_dbg(&d->intf->dev, "\n");
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001018
1019 /* remove I2C slave demod */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001020 client = dev->i2c_client_slave_demod;
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001021 if (client) {
1022 module_put(client->dev.driver->owner);
1023 i2c_unregister_device(client);
1024 }
1025
1026 /* remove I2C demod */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001027 client = dev->i2c_client_demod;
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001028 if (client) {
1029 module_put(client->dev.driver->owner);
1030 i2c_unregister_device(client);
1031 }
1032
1033 return 0;
1034}
1035
Antti Palosaari831e0b72011-07-08 23:36:07 -03001036static struct qt1010_config rtl28xxu_qt1010_config = {
1037 .i2c_address = 0x62, /* 0xc4 */
1038};
1039
1040static struct mt2060_config rtl28xxu_mt2060_config = {
1041 .i2c_address = 0x60, /* 0xc0 */
1042 .clock_out = 0,
1043};
1044
1045static struct mxl5005s_config rtl28xxu_mxl5005s_config = {
1046 .i2c_address = 0x63, /* 0xc6 */
1047 .if_freq = IF_FREQ_4570000HZ,
1048 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
1049 .agc_mode = MXL_SINGLE_AGC,
1050 .tracking_filter = MXL_TF_C_H,
1051 .rssi_enable = MXL_RSSI_ENABLE,
1052 .cap_select = MXL_CAP_SEL_ENABLE,
1053 .div_out = MXL_DIV_OUT_4,
1054 .clock_out = MXL_CLOCK_OUT_DISABLE,
1055 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
1056 .top = MXL5005S_TOP_25P2,
1057 .mod_mode = MXL_DIGITAL_MODE,
1058 .if_mode = MXL_ZERO_IF,
1059 .AgcMasterByte = 0x00,
1060};
1061
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001062static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001063{
1064 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -03001065 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001066 struct rtl28xxu_dev *dev = d_to_priv(d);
Antti Palosaari9935eea2012-01-21 22:26:52 -03001067 struct dvb_frontend *fe;
Antti Palosaari831e0b72011-07-08 23:36:07 -03001068
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001069 dev_dbg(&d->intf->dev, "\n");
Antti Palosaari831e0b72011-07-08 23:36:07 -03001070
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001071 switch (dev->tuner) {
Antti Palosaari831e0b72011-07-08 23:36:07 -03001072 case TUNER_RTL2830_QT1010:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001073 fe = dvb_attach(qt1010_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001074 dev->demod_i2c_adapter,
Antti Palosaaric0ceac92014-12-07 22:02:23 -03001075 &rtl28xxu_qt1010_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001076 break;
1077 case TUNER_RTL2830_MT2060:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001078 fe = dvb_attach(mt2060_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001079 dev->demod_i2c_adapter,
Antti Palosaaric0ceac92014-12-07 22:02:23 -03001080 &rtl28xxu_mt2060_config, 1220);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001081 break;
1082 case TUNER_RTL2830_MXL5005S:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001083 fe = dvb_attach(mxl5005s_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001084 dev->demod_i2c_adapter,
Antti Palosaaric0ceac92014-12-07 22:02:23 -03001085 &rtl28xxu_mxl5005s_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001086 break;
1087 default:
Antti Palosaari9935eea2012-01-21 22:26:52 -03001088 fe = NULL;
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001089 dev_err(&d->intf->dev, "unknown tuner %d\n", dev->tuner);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001090 }
1091
1092 if (fe == NULL) {
1093 ret = -ENODEV;
1094 goto err;
1095 }
1096
1097 return 0;
1098err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001099 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001100 return ret;
1101}
1102
Antti Palosaariad3a7582012-12-08 23:27:49 -03001103static const struct fc0012_config rtl2832u_fc0012_config = {
1104 .i2c_address = 0x63, /* 0xc6 >> 1 */
1105 .xtal_freq = FC_XTAL_28_8_MHZ,
1106};
1107
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -03001108static const struct r820t_config rtl2832u_r820t_config = {
1109 .i2c_addr = 0x1a,
1110 .xtal = 28800000,
1111 .max_i2c_msg_len = 2,
1112 .rafael_chip = CHIP_R820T,
1113};
1114
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001115static const struct r820t_config rtl2832u_r828d_config = {
1116 .i2c_addr = 0x3a,
1117 .xtal = 16000000,
1118 .max_i2c_msg_len = 2,
1119 .rafael_chip = CHIP_R828D,
1120};
1121
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001122static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
1123{
1124 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -03001125 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001126 struct rtl28xxu_dev *dev = d_to_priv(d);
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001127 struct dvb_frontend *fe = NULL;
1128 struct i2c_board_info info;
1129 struct i2c_client *client;
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001130 struct v4l2_subdev *subdev = NULL;
Mauro Carvalho Chehabe181b1f2015-02-03 16:36:28 -02001131 struct platform_device *pdev;
1132 struct rtl2832_sdr_platform_data pdata;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001133
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001134 dev_dbg(&d->intf->dev, "\n");
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001135
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001136 memset(&info, 0, sizeof(struct i2c_board_info));
Mauro Carvalho Chehabe181b1f2015-02-03 16:36:28 -02001137 memset(&pdata, 0, sizeof(pdata));
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001138
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001139 switch (dev->tuner) {
Thomas Mair5cf66312012-05-18 14:47:41 -03001140 case TUNER_RTL2832_FC0012:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001141 fe = dvb_attach(fc0012_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001142 dev->demod_i2c_adapter, &rtl2832u_fc0012_config);
Thomas Mair5cf66312012-05-18 14:47:41 -03001143
1144 /* since fc0012 includs reading the signal strength delegate
1145 * that to the tuner driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -03001146 adap->fe[0]->ops.read_signal_strength =
1147 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001148 break;
Thomas Mair5cf66312012-05-18 14:47:41 -03001149 case TUNER_RTL2832_FC0013:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001150 fe = dvb_attach(fc0013_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001151 dev->demod_i2c_adapter, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -03001152
1153 /* fc0013 also supports signal strength reading */
Antti Palosaaric01a3592012-08-12 22:27:07 -03001154 adap->fe[0]->ops.read_signal_strength =
1155 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Antti Palosaari55cdb7d2014-02-03 23:07:21 -03001156 break;
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001157 case TUNER_RTL2832_E4000: {
1158 struct e4000_config e4000_config = {
1159 .fe = adap->fe[0],
1160 .clock = 28800000,
1161 };
1162
1163 strlcpy(info.type, "e4000", I2C_NAME_SIZE);
1164 info.addr = 0x64;
1165 info.platform_data = &e4000_config;
1166
1167 request_module(info.type);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001168 client = i2c_new_device(dev->demod_i2c_adapter, &info);
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001169 if (client == NULL || client->dev.driver == NULL)
1170 break;
1171
1172 if (!try_module_get(client->dev.driver->owner)) {
1173 i2c_unregister_device(client);
1174 break;
1175 }
1176
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001177 dev->i2c_client_tuner = client;
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001178 subdev = i2c_get_clientdata(client);
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001179 }
Antti Palosaari542f6a52012-09-01 21:09:22 -03001180 break;
Antti Palosaari35fc0e02015-04-14 19:55:51 -03001181 case TUNER_RTL2832_FC2580: {
1182 struct fc2580_platform_data fc2580_pdata = {
1183 .dvb_frontend = adap->fe[0],
1184 };
1185 struct i2c_board_info board_info = {};
1186
1187 strlcpy(board_info.type, "fc2580", I2C_NAME_SIZE);
1188 board_info.addr = 0x56;
1189 board_info.platform_data = &fc2580_pdata;
1190 request_module("fc2580");
1191 client = i2c_new_device(dev->demod_i2c_adapter,
1192 &board_info);
1193 if (client == NULL || client->dev.driver == NULL)
1194 break;
1195 if (!try_module_get(client->dev.driver->owner)) {
1196 i2c_unregister_device(client);
1197 break;
1198 }
1199 dev->i2c_client_tuner = client;
1200 }
Antti Palosaari384df492012-09-08 22:07:25 -03001201 break;
Antti Palosaari88ffe552015-04-15 19:25:32 -03001202 case TUNER_RTL2832_TUA9001: {
1203 struct tua9001_platform_data tua9001_pdata = {
1204 .dvb_frontend = adap->fe[0],
1205 };
1206 struct i2c_board_info board_info = {};
1207
Antti Palosaari5be65722012-09-11 22:27:09 -03001208 /* enable GPIO1 and GPIO4 as output */
Antti Palosaari670ef052014-12-23 14:32:35 -03001209 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12);
Antti Palosaari4005c1a2012-09-17 15:43:57 -03001210 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -03001211 goto err;
1212
Antti Palosaari670ef052014-12-23 14:32:35 -03001213 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12);
Antti Palosaari4005c1a2012-09-17 15:43:57 -03001214 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -03001215 goto err;
1216
Antti Palosaari88ffe552015-04-15 19:25:32 -03001217 strlcpy(board_info.type, "tua9001", I2C_NAME_SIZE);
1218 board_info.addr = 0x60;
1219 board_info.platform_data = &tua9001_pdata;
1220 request_module("tua9001");
1221 client = i2c_new_device(dev->demod_i2c_adapter, &board_info);
1222 if (client == NULL || client->dev.driver == NULL)
1223 break;
1224 if (!try_module_get(client->dev.driver->owner)) {
1225 i2c_unregister_device(client);
1226 break;
1227 }
1228 dev->i2c_client_tuner = client;
Antti Palosaari5be65722012-09-11 22:27:09 -03001229 break;
Antti Palosaari88ffe552015-04-15 19:25:32 -03001230 }
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -03001231 case TUNER_RTL2832_R820T:
Antti Palosaari164f3d22014-12-14 11:45:55 -03001232 fe = dvb_attach(r820t_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001233 dev->demod_i2c_adapter,
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -03001234 &rtl2832u_r820t_config);
Mauro Carvalho Chehab9e30edd2013-04-07 18:57:15 -03001235
1236 /* Use tuner to get the signal strength */
1237 adap->fe[0]->ops.read_signal_strength =
1238 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -03001239 break;
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001240 case TUNER_RTL2832_R828D:
Antti Palosaari80f189a2013-12-01 13:44:23 -03001241 fe = dvb_attach(r820t_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001242 dev->demod_i2c_adapter,
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001243 &rtl2832u_r828d_config);
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001244 adap->fe[0]->ops.read_signal_strength =
1245 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Antti Palosaari80f189a2013-12-01 13:44:23 -03001246
1247 if (adap->fe[1]) {
1248 fe = dvb_attach(r820t_attach, adap->fe[1],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001249 dev->demod_i2c_adapter,
Antti Palosaari80f189a2013-12-01 13:44:23 -03001250 &rtl2832u_r828d_config);
1251 adap->fe[1]->ops.read_signal_strength =
1252 adap->fe[1]->ops.tuner_ops.get_rf_strength;
1253 }
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001254 break;
Olli Salonen699dcff2015-05-05 13:54:19 -03001255 case TUNER_RTL2832_SI2157: {
1256 struct si2157_config si2157_config = {
1257 .fe = adap->fe[0],
1258 .if_port = 0,
1259 .inversion = false,
1260 };
1261
1262 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1263 info.addr = 0x60;
1264 info.platform_data = &si2157_config;
1265 request_module(info.type);
1266 client = i2c_new_device(&d->i2c_adap, &info);
1267 if (client == NULL || client->dev.driver == NULL)
1268 break;
1269
1270 if (!try_module_get(client->dev.driver->owner)) {
1271 i2c_unregister_device(client);
1272 break;
1273 }
1274
1275 dev->i2c_client_tuner = client;
1276 subdev = i2c_get_clientdata(client);
1277
1278 /* copy tuner ops for 2nd FE as tuner is shared */
1279 if (adap->fe[1]) {
1280 adap->fe[1]->tuner_priv =
1281 adap->fe[0]->tuner_priv;
1282 memcpy(&adap->fe[1]->ops.tuner_ops,
1283 &adap->fe[0]->ops.tuner_ops,
1284 sizeof(struct dvb_tuner_ops));
1285 }
1286 }
1287 break;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001288 default:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001289 dev_err(&d->intf->dev, "unknown tuner %d\n", dev->tuner);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001290 }
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001291 if (fe == NULL && dev->i2c_client_tuner == NULL) {
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001292 ret = -ENODEV;
1293 goto err;
1294 }
1295
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001296 /* register SDR */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001297 switch (dev->tuner) {
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001298 case TUNER_RTL2832_FC0012:
1299 case TUNER_RTL2832_FC0013:
1300 case TUNER_RTL2832_E4000:
1301 case TUNER_RTL2832_R820T:
1302 case TUNER_RTL2832_R828D:
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001303 pdata.clk = dev->rtl2832_platform_data.clk;
1304 pdata.tuner = dev->tuner;
1305 pdata.i2c_client = dev->i2c_client_demod;
1306 pdata.bulk_read = dev->rtl2832_platform_data.bulk_read;
1307 pdata.bulk_write = dev->rtl2832_platform_data.bulk_write;
1308 pdata.update_bits = dev->rtl2832_platform_data.update_bits;
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001309 pdata.dvb_frontend = adap->fe[0];
1310 pdata.dvb_usb_device = d;
1311 pdata.v4l2_subdev = subdev;
1312
1313 request_module("%s", "rtl2832_sdr");
Antti Palosaari6a53fa22014-12-17 08:16:10 -03001314 pdev = platform_device_register_data(&d->intf->dev,
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001315 "rtl2832_sdr",
1316 PLATFORM_DEVID_AUTO,
1317 &pdata, sizeof(pdata));
Wei Yongjun250d2ff2015-04-16 09:22:46 -03001318 if (IS_ERR(pdev) || pdev->dev.driver == NULL)
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001319 break;
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001320 dev->platform_device_sdr = pdev;
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001321 break;
1322 default:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001323 dev_dbg(&d->intf->dev, "no SDR for tuner=%d\n", dev->tuner);
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001324 }
1325
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001326 return 0;
1327err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001328 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001329 return ret;
1330}
1331
Antti Palosaaride701f02014-12-23 14:09:13 -03001332static int rtl28xxu_tuner_attach(struct dvb_usb_adapter *adap)
1333{
1334 struct rtl28xxu_dev *dev = adap_to_priv(adap);
1335
1336 if (dev->chip_id == CHIP_ID_RTL2831U)
1337 return rtl2831u_tuner_attach(adap);
1338 else
1339 return rtl2832u_tuner_attach(adap);
1340}
1341
1342static int rtl28xxu_tuner_detach(struct dvb_usb_adapter *adap)
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001343{
1344 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001345 struct rtl28xxu_dev *dev = d_to_priv(d);
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001346 struct i2c_client *client;
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001347 struct platform_device *pdev;
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001348
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001349 dev_dbg(&d->intf->dev, "\n");
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001350
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001351 /* remove platform SDR */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001352 pdev = dev->platform_device_sdr;
Antti Palosaari6a53fa22014-12-17 08:16:10 -03001353 if (pdev)
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001354 platform_device_unregister(pdev);
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001355
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001356 /* remove I2C tuner */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001357 client = dev->i2c_client_tuner;
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001358 if (client) {
1359 module_put(client->dev.driver->owner);
1360 i2c_unregister_device(client);
1361 }
1362
1363 return 0;
1364}
1365
Antti Palosaaric01a3592012-08-12 22:27:07 -03001366static int rtl28xxu_init(struct dvb_usb_device *d)
1367{
1368 int ret;
1369 u8 val;
1370
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001371 dev_dbg(&d->intf->dev, "\n");
Antti Palosaaric01a3592012-08-12 22:27:07 -03001372
1373 /* init USB endpoints */
Antti Palosaari670ef052014-12-23 14:32:35 -03001374 ret = rtl28xxu_rd_reg(d, USB_SYSCTL_0, &val);
Antti Palosaaric01a3592012-08-12 22:27:07 -03001375 if (ret)
1376 goto err;
1377
1378 /* enable DMA and Full Packet Mode*/
1379 val |= 0x09;
Antti Palosaari670ef052014-12-23 14:32:35 -03001380 ret = rtl28xxu_wr_reg(d, USB_SYSCTL_0, val);
Antti Palosaaric01a3592012-08-12 22:27:07 -03001381 if (ret)
1382 goto err;
1383
1384 /* set EPA maximum packet size to 0x0200 */
Antti Palosaari670ef052014-12-23 14:32:35 -03001385 ret = rtl28xxu_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
Antti Palosaaric01a3592012-08-12 22:27:07 -03001386 if (ret)
1387 goto err;
1388
1389 /* change EPA FIFO length */
Antti Palosaari670ef052014-12-23 14:32:35 -03001390 ret = rtl28xxu_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
Antti Palosaaric01a3592012-08-12 22:27:07 -03001391 if (ret)
1392 goto err;
1393
1394 return ret;
1395err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001396 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaaric01a3592012-08-12 22:27:07 -03001397 return ret;
1398}
1399
Thomas Mair5cf66312012-05-18 14:47:41 -03001400static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001401{
1402 int ret;
Antti Palosaari8b036632012-09-01 09:54:43 -03001403 u8 gpio, sys0, epa_ctl[2];
Antti Palosaari831e0b72011-07-08 23:36:07 -03001404
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001405 dev_dbg(&d->intf->dev, "onoff=%d\n", onoff);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001406
1407 /* demod adc */
Antti Palosaari670ef052014-12-23 14:32:35 -03001408 ret = rtl28xxu_rd_reg(d, SYS_SYS0, &sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001409 if (ret)
1410 goto err;
1411
1412 /* tuner power, read GPIOs */
Antti Palosaari670ef052014-12-23 14:32:35 -03001413 ret = rtl28xxu_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001414 if (ret)
1415 goto err;
1416
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001417 dev_dbg(&d->intf->dev, "RD SYS0=%02x GPIO_OUT_VAL=%02x\n", sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001418
1419 if (onoff) {
1420 gpio |= 0x01; /* GPIO0 = 1 */
1421 gpio &= (~0x10); /* GPIO4 = 0 */
Antti Palosaari991452a2012-08-12 22:27:08 -03001422 gpio |= 0x04; /* GPIO2 = 1, LED on */
Antti Palosaari831e0b72011-07-08 23:36:07 -03001423 sys0 = sys0 & 0x0f;
1424 sys0 |= 0xe0;
Antti Palosaari8b036632012-09-01 09:54:43 -03001425 epa_ctl[0] = 0x00; /* clear stall */
1426 epa_ctl[1] = 0x00; /* clear reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -03001427 } else {
Antti Palosaari831e0b72011-07-08 23:36:07 -03001428 gpio &= (~0x01); /* GPIO0 = 0 */
1429 gpio |= 0x10; /* GPIO4 = 1 */
Antti Palosaari991452a2012-08-12 22:27:08 -03001430 gpio &= (~0x04); /* GPIO2 = 1, LED off */
Antti Palosaari831e0b72011-07-08 23:36:07 -03001431 sys0 = sys0 & (~0xc0);
Antti Palosaari8b036632012-09-01 09:54:43 -03001432 epa_ctl[0] = 0x10; /* set stall */
1433 epa_ctl[1] = 0x02; /* set reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -03001434 }
1435
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001436 dev_dbg(&d->intf->dev, "WR SYS0=%02x GPIO_OUT_VAL=%02x\n", sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001437
1438 /* demod adc */
Antti Palosaari670ef052014-12-23 14:32:35 -03001439 ret = rtl28xxu_wr_reg(d, SYS_SYS0, sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001440 if (ret)
1441 goto err;
1442
1443 /* tuner power, write GPIOs */
Antti Palosaari670ef052014-12-23 14:32:35 -03001444 ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001445 if (ret)
1446 goto err;
1447
Antti Palosaari8b036632012-09-01 09:54:43 -03001448 /* streaming EP: stall & reset */
Antti Palosaari670ef052014-12-23 14:32:35 -03001449 ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, epa_ctl, 2);
Antti Palosaari8b036632012-09-01 09:54:43 -03001450 if (ret)
1451 goto err;
1452
1453 if (onoff)
1454 usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
1455
Antti Palosaari831e0b72011-07-08 23:36:07 -03001456 return ret;
1457err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001458 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001459 return ret;
1460}
1461
Thomas Mair5cf66312012-05-18 14:47:41 -03001462static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
1463{
1464 int ret;
Thomas Mair5cf66312012-05-18 14:47:41 -03001465
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001466 dev_dbg(&d->intf->dev, "onoff=%d\n", onoff);
Thomas Mair5cf66312012-05-18 14:47:41 -03001467
1468 if (onoff) {
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001469 /* GPIO3=1, GPIO4=0 */
Antti Palosaari670ef052014-12-23 14:32:35 -03001470 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x08, 0x18);
Thomas Mair5cf66312012-05-18 14:47:41 -03001471 if (ret)
1472 goto err;
1473
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001474 /* suspend? */
Antti Palosaari670ef052014-12-23 14:32:35 -03001475 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL1, 0x00, 0x10);
Thomas Mair5cf66312012-05-18 14:47:41 -03001476 if (ret)
1477 goto err;
1478
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001479 /* enable PLL */
Antti Palosaari670ef052014-12-23 14:32:35 -03001480 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x80, 0x80);
Thomas Mair5cf66312012-05-18 14:47:41 -03001481 if (ret)
1482 goto err;
1483
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001484 /* disable reset */
Antti Palosaari670ef052014-12-23 14:32:35 -03001485 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x20, 0x20);
Thomas Mair5cf66312012-05-18 14:47:41 -03001486 if (ret)
1487 goto err;
1488
Antti Palosaari8b036632012-09-01 09:54:43 -03001489 /* streaming EP: clear stall & reset */
Antti Palosaari670ef052014-12-23 14:32:35 -03001490 ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2);
Antti Palosaari8b036632012-09-01 09:54:43 -03001491 if (ret)
1492 goto err;
1493
1494 ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
1495 if (ret)
1496 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001497 } else {
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001498 /* GPIO4=1 */
Antti Palosaari670ef052014-12-23 14:32:35 -03001499 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x10, 0x10);
Thomas Mair5cf66312012-05-18 14:47:41 -03001500 if (ret)
1501 goto err;
1502
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001503 /* disable PLL */
Antti Palosaari670ef052014-12-23 14:32:35 -03001504 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x80);
Thomas Mair5cf66312012-05-18 14:47:41 -03001505 if (ret)
1506 goto err;
1507
Antti Palosaari8b036632012-09-01 09:54:43 -03001508 /* streaming EP: set stall & reset */
Antti Palosaari670ef052014-12-23 14:32:35 -03001509 ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2);
Antti Palosaari8b036632012-09-01 09:54:43 -03001510 if (ret)
1511 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001512 }
1513
1514 return ret;
1515err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001516 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Thomas Mair5cf66312012-05-18 14:47:41 -03001517 return ret;
1518}
1519
Antti Palosaaride701f02014-12-23 14:09:13 -03001520static int rtl28xxu_power_ctrl(struct dvb_usb_device *d, int onoff)
1521{
1522 struct rtl28xxu_dev *dev = d_to_priv(d);
1523
1524 if (dev->chip_id == CHIP_ID_RTL2831U)
1525 return rtl2831u_power_ctrl(d, onoff);
1526 else
1527 return rtl2832u_power_ctrl(d, onoff);
1528}
1529
1530static int rtl28xxu_frontend_ctrl(struct dvb_frontend *fe, int onoff)
Antti Palosaari698f6262014-09-27 01:22:45 -03001531{
1532 struct dvb_usb_device *d = fe_to_d(fe);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001533 struct rtl28xxu_dev *dev = fe_to_priv(fe);
1534 struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data;
Antti Palosaari698f6262014-09-27 01:22:45 -03001535 int ret;
1536 u8 val;
1537
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001538 dev_dbg(&d->intf->dev, "fe=%d onoff=%d\n", fe->id, onoff);
Antti Palosaari698f6262014-09-27 01:22:45 -03001539
Antti Palosaaride701f02014-12-23 14:09:13 -03001540 if (dev->chip_id == CHIP_ID_RTL2831U)
1541 return 0;
1542
Antti Palosaari698f6262014-09-27 01:22:45 -03001543 /* control internal demod ADC */
1544 if (fe->id == 0 && onoff)
1545 val = 0x48; /* enable ADC */
1546 else
1547 val = 0x00; /* disable ADC */
1548
Antti Palosaari670ef052014-12-23 14:32:35 -03001549 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, val, 0x48);
Antti Palosaari698f6262014-09-27 01:22:45 -03001550 if (ret)
1551 goto err;
1552
Antti Palosaari80f189a2013-12-01 13:44:23 -03001553 /* bypass slave demod TS through master demod */
1554 if (fe->id == 1 && onoff) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001555 ret = pdata->enable_slave_ts(dev->i2c_client_demod);
Antti Palosaari80f189a2013-12-01 13:44:23 -03001556 if (ret)
1557 goto err;
1558 }
1559
Antti Palosaari698f6262014-09-27 01:22:45 -03001560 return 0;
1561err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001562 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari698f6262014-09-27 01:22:45 -03001563 return ret;
1564}
1565
Antti Palosaari37b44a02013-01-04 15:21:26 -03001566#if IS_ENABLED(CONFIG_RC_CORE)
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001567static int rtl2831u_rc_query(struct dvb_usb_device *d)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001568{
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001569 int ret, i;
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001570 struct rtl28xxu_dev *dev = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -03001571 u8 buf[5];
1572 u32 rc_code;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001573 struct rtl28xxu_reg_val rc_nec_tab[] = {
1574 { 0x3033, 0x80 },
1575 { 0x3020, 0x43 },
1576 { 0x3021, 0x16 },
1577 { 0x3022, 0x16 },
1578 { 0x3023, 0x5a },
1579 { 0x3024, 0x2d },
1580 { 0x3025, 0x16 },
1581 { 0x3026, 0x01 },
1582 { 0x3028, 0xb0 },
1583 { 0x3029, 0x04 },
1584 { 0x302c, 0x88 },
1585 { 0x302e, 0x13 },
1586 { 0x3030, 0xdf },
1587 { 0x3031, 0x05 },
1588 };
1589
1590 /* init remote controller */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001591 if (!dev->rc_active) {
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001592 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Antti Palosaari670ef052014-12-23 14:32:35 -03001593 ret = rtl28xxu_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001594 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001595 if (ret)
1596 goto err;
1597 }
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001598 dev->rc_active = true;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001599 }
Antti Palosaari831e0b72011-07-08 23:36:07 -03001600
Antti Palosaari670ef052014-12-23 14:32:35 -03001601 ret = rtl28xxu_rd_regs(d, SYS_IRRC_RP, buf, 5);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001602 if (ret)
1603 goto err;
1604
1605 if (buf[4] & 0x01) {
1606 if (buf[2] == (u8) ~buf[3]) {
1607 if (buf[0] == (u8) ~buf[1]) {
1608 /* NEC standard (16 bit) */
David Härdeman120703f2014-04-03 20:31:30 -03001609 rc_code = RC_SCANCODE_NEC(buf[0], buf[2]);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001610 } else {
1611 /* NEC extended (24 bit) */
David Härdeman120703f2014-04-03 20:31:30 -03001612 rc_code = RC_SCANCODE_NECX(buf[0] << 8 | buf[1],
1613 buf[2]);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001614 }
1615 } else {
1616 /* NEC full (32 bit) */
David Härdeman120703f2014-04-03 20:31:30 -03001617 rc_code = RC_SCANCODE_NEC32(buf[0] << 24 | buf[1] << 16 |
1618 buf[2] << 8 | buf[3]);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001619 }
1620
David Härdeman120703f2014-04-03 20:31:30 -03001621 rc_keydown(d->rc_dev, RC_TYPE_NEC, rc_code, 0);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001622
Antti Palosaari670ef052014-12-23 14:32:35 -03001623 ret = rtl28xxu_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001624 if (ret)
1625 goto err;
1626
1627 /* repeated intentionally to avoid extra keypress */
Antti Palosaari670ef052014-12-23 14:32:35 -03001628 ret = rtl28xxu_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001629 if (ret)
1630 goto err;
1631 }
1632
1633 return ret;
1634err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001635 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001636 return ret;
1637}
1638
Antti Palosaaric01a3592012-08-12 22:27:07 -03001639static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
1640 struct dvb_usb_rc *rc)
1641{
1642 rc->map_name = RC_MAP_EMPTY;
David Härdemanc003ab12012-10-11 19:11:54 -03001643 rc->allowed_protos = RC_BIT_NEC;
Antti Palosaaric01a3592012-08-12 22:27:07 -03001644 rc->query = rtl2831u_rc_query;
1645 rc->interval = 400;
1646
1647 return 0;
1648}
1649
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001650static int rtl2832u_rc_query(struct dvb_usb_device *d)
1651{
Antti Palosaarif39fac32013-06-04 09:17:03 -03001652 int ret, i, len;
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001653 struct rtl28xxu_dev *dev = d->priv;
Antti Palosaarif39fac32013-06-04 09:17:03 -03001654 struct ir_raw_event ev;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001655 u8 buf[128];
Antti Palosaarif39fac32013-06-04 09:17:03 -03001656 static const struct rtl28xxu_reg_val_mask refresh_tab[] = {
1657 {IR_RX_IF, 0x03, 0xff},
1658 {IR_RX_BUF_CTRL, 0x80, 0xff},
1659 {IR_RX_CTRL, 0x80, 0xff},
1660 };
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001661
1662 /* init remote controller */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001663 if (!dev->rc_active) {
Antti Palosaarif39fac32013-06-04 09:17:03 -03001664 static const struct rtl28xxu_reg_val_mask init_tab[] = {
1665 {SYS_DEMOD_CTL1, 0x00, 0x04},
1666 {SYS_DEMOD_CTL1, 0x00, 0x08},
1667 {USB_CTRL, 0x20, 0x20},
1668 {SYS_GPIO_DIR, 0x00, 0x08},
1669 {SYS_GPIO_OUT_EN, 0x08, 0x08},
1670 {SYS_GPIO_OUT_VAL, 0x08, 0x08},
1671 {IR_MAX_DURATION0, 0xd0, 0xff},
1672 {IR_MAX_DURATION1, 0x07, 0xff},
1673 {IR_IDLE_LEN0, 0xc0, 0xff},
1674 {IR_IDLE_LEN1, 0x00, 0xff},
1675 {IR_GLITCH_LEN, 0x03, 0xff},
1676 {IR_RX_CLK, 0x09, 0xff},
1677 {IR_RX_CFG, 0x1c, 0xff},
1678 {IR_MAX_H_TOL_LEN, 0x1e, 0xff},
1679 {IR_MAX_L_TOL_LEN, 0x1e, 0xff},
1680 {IR_RX_CTRL, 0x80, 0xff},
1681 };
1682
1683 for (i = 0; i < ARRAY_SIZE(init_tab); i++) {
Antti Palosaari670ef052014-12-23 14:32:35 -03001684 ret = rtl28xxu_wr_reg_mask(d, init_tab[i].reg,
Antti Palosaarif39fac32013-06-04 09:17:03 -03001685 init_tab[i].val, init_tab[i].mask);
Rodrigo Tartajo1e414132013-04-20 20:02:12 -03001686 if (ret)
1687 goto err;
1688 }
Antti Palosaarif39fac32013-06-04 09:17:03 -03001689
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001690 dev->rc_active = true;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001691 }
1692
Antti Palosaari670ef052014-12-23 14:32:35 -03001693 ret = rtl28xxu_rd_reg(d, IR_RX_IF, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001694 if (ret)
1695 goto err;
1696
1697 if (buf[0] != 0x83)
Antti Palosaarif39fac32013-06-04 09:17:03 -03001698 goto exit;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001699
Antti Palosaari670ef052014-12-23 14:32:35 -03001700 ret = rtl28xxu_rd_reg(d, IR_RX_BC, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001701 if (ret)
1702 goto err;
1703
1704 len = buf[0];
Antti Palosaarif39fac32013-06-04 09:17:03 -03001705
1706 /* read raw code from hw */
Antti Palosaari670ef052014-12-23 14:32:35 -03001707 ret = rtl28xxu_rd_regs(d, IR_RX_BUF, buf, len);
Antti Palosaarif39fac32013-06-04 09:17:03 -03001708 if (ret)
1709 goto err;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001710
Antti Palosaarif39fac32013-06-04 09:17:03 -03001711 /* let hw receive new code */
1712 for (i = 0; i < ARRAY_SIZE(refresh_tab); i++) {
Antti Palosaari670ef052014-12-23 14:32:35 -03001713 ret = rtl28xxu_wr_reg_mask(d, refresh_tab[i].reg,
Antti Palosaarif39fac32013-06-04 09:17:03 -03001714 refresh_tab[i].val, refresh_tab[i].mask);
Rodrigo Tartajo1e414132013-04-20 20:02:12 -03001715 if (ret)
1716 goto err;
1717 }
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001718
Antti Palosaarif39fac32013-06-04 09:17:03 -03001719 /* pass data to Kernel IR decoder */
1720 init_ir_raw_event(&ev);
1721
1722 for (i = 0; i < len; i++) {
1723 ev.pulse = buf[i] >> 7;
1724 ev.duration = 50800 * (buf[i] & 0x7f);
1725 ir_raw_event_store_with_filter(d->rc_dev, &ev);
1726 }
1727
1728 /* 'flush' ir_raw_event_store_with_filter() */
1729 ir_raw_event_set_idle(d->rc_dev, true);
1730 ir_raw_event_handle(d->rc_dev);
1731exit:
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001732 return ret;
1733err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001734 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001735 return ret;
1736}
1737
Antti Palosaaric01a3592012-08-12 22:27:07 -03001738static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1739 struct dvb_usb_rc *rc)
1740{
Antti Palosaari94b5fa62013-11-22 14:20:14 -03001741 /* disable IR interrupts in order to avoid SDR sample loss */
1742 if (rtl28xxu_disable_rc)
Antti Palosaari670ef052014-12-23 14:32:35 -03001743 return rtl28xxu_wr_reg(d, IR_RX_IE, 0x00);
Antti Palosaari94b5fa62013-11-22 14:20:14 -03001744
Antti Palosaarif39fac32013-06-04 09:17:03 -03001745 /* load empty to enable rc */
1746 if (!rc->map_name)
1747 rc->map_name = RC_MAP_EMPTY;
Rodrigo Tartajo1e414132013-04-20 20:02:12 -03001748 rc->allowed_protos = RC_BIT_ALL;
Antti Palosaarif39fac32013-06-04 09:17:03 -03001749 rc->driver_type = RC_DRIVER_IR_RAW;
Antti Palosaaric01a3592012-08-12 22:27:07 -03001750 rc->query = rtl2832u_rc_query;
Benjamin Larsson46cf7072015-03-15 19:57:48 -03001751 rc->interval = 200;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001752
Antti Palosaaric01a3592012-08-12 22:27:07 -03001753 return 0;
1754}
Antti Palosaaride701f02014-12-23 14:09:13 -03001755
1756static int rtl28xxu_get_rc_config(struct dvb_usb_device *d,
1757 struct dvb_usb_rc *rc)
1758{
1759 struct rtl28xxu_dev *dev = d_to_priv(d);
1760
1761 if (dev->chip_id == CHIP_ID_RTL2831U)
1762 return rtl2831u_get_rc_config(d, rc);
1763 else
1764 return rtl2832u_get_rc_config(d, rc);
1765}
Antti Palosaaricedda372012-12-09 20:06:00 -03001766#else
Antti Palosaaride701f02014-12-23 14:09:13 -03001767#define rtl28xxu_get_rc_config NULL
Antti Palosaaricedda372012-12-09 20:06:00 -03001768#endif
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001769
Antti Palosaaride701f02014-12-23 14:09:13 -03001770static int rtl28xxu_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
Antti Palosaarid9bd3fa2014-12-09 16:10:14 -03001771{
Antti Palosaaride701f02014-12-23 14:09:13 -03001772 struct rtl28xxu_dev *dev = adap_to_priv(adap);
Antti Palosaarid9bd3fa2014-12-09 16:10:14 -03001773
Antti Palosaaride701f02014-12-23 14:09:13 -03001774 if (dev->chip_id == CHIP_ID_RTL2831U) {
1775 struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data;
1776
1777 return pdata->pid_filter_ctrl(adap->fe[0], onoff);
1778 } else {
1779 struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data;
1780
1781 return pdata->pid_filter_ctrl(adap->fe[0], onoff);
1782 }
Antti Palosaarid9bd3fa2014-12-09 16:10:14 -03001783}
1784
Antti Palosaaride701f02014-12-23 14:09:13 -03001785static int rtl28xxu_pid_filter(struct dvb_usb_adapter *adap, int index,
1786 u16 pid, int onoff)
Antti Palosaarie20b0cf2014-12-14 14:10:47 -03001787{
Antti Palosaaride701f02014-12-23 14:09:13 -03001788 struct rtl28xxu_dev *dev = adap_to_priv(adap);
Antti Palosaarie20b0cf2014-12-14 14:10:47 -03001789
Antti Palosaaride701f02014-12-23 14:09:13 -03001790 if (dev->chip_id == CHIP_ID_RTL2831U) {
1791 struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data;
Antti Palosaarie20b0cf2014-12-14 14:10:47 -03001792
Antti Palosaaride701f02014-12-23 14:09:13 -03001793 return pdata->pid_filter(adap->fe[0], index, pid, onoff);
1794 } else {
1795 struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data;
Antti Palosaarid9bd3fa2014-12-09 16:10:14 -03001796
Antti Palosaaride701f02014-12-23 14:09:13 -03001797 return pdata->pid_filter(adap->fe[0], index, pid, onoff);
1798 }
Antti Palosaarie20b0cf2014-12-14 14:10:47 -03001799}
1800
Antti Palosaari723abfd2014-12-23 14:21:10 -03001801static const struct dvb_usb_device_properties rtl28xxu_props = {
Antti Palosaaric01a3592012-08-12 22:27:07 -03001802 .driver_name = KBUILD_MODNAME,
1803 .owner = THIS_MODULE,
1804 .adapter_nr = adapter_nr,
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001805 .size_of_priv = sizeof(struct rtl28xxu_dev),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001806
Antti Palosaarid0f232e2014-12-23 13:14:36 -03001807 .identify_state = rtl28xxu_identify_state,
Antti Palosaaride701f02014-12-23 14:09:13 -03001808 .power_ctrl = rtl28xxu_power_ctrl,
1809 .frontend_ctrl = rtl28xxu_frontend_ctrl,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001810 .i2c_algo = &rtl28xxu_i2c_algo,
Antti Palosaaride701f02014-12-23 14:09:13 -03001811 .read_config = rtl28xxu_read_config,
1812 .frontend_attach = rtl28xxu_frontend_attach,
1813 .frontend_detach = rtl28xxu_frontend_detach,
1814 .tuner_attach = rtl28xxu_tuner_attach,
1815 .tuner_detach = rtl28xxu_tuner_detach,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001816 .init = rtl28xxu_init,
Antti Palosaaride701f02014-12-23 14:09:13 -03001817 .get_rc_config = rtl28xxu_get_rc_config,
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001818
Antti Palosaaric01a3592012-08-12 22:27:07 -03001819 .num_adapters = 1,
1820 .adapter = {
1821 {
Antti Palosaarie20b0cf2014-12-14 14:10:47 -03001822 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1823 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1824
1825 .pid_filter_count = 32,
Antti Palosaaride701f02014-12-23 14:09:13 -03001826 .pid_filter_ctrl = rtl28xxu_pid_filter_ctrl,
1827 .pid_filter = rtl28xxu_pid_filter,
Antti Palosaarie20b0cf2014-12-14 14:10:47 -03001828
Antti Palosaaric01a3592012-08-12 22:27:07 -03001829 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001830 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001831 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001832};
1833
Antti Palosaaric01a3592012-08-12 22:27:07 -03001834static const struct usb_device_id rtl28xxu_id_table[] = {
Jan Vcelak60aa4c62014-02-26 15:33:40 -03001835 /* RTL2831U devices: */
Antti Palosaaric01a3592012-08-12 22:27:07 -03001836 { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001837 &rtl28xxu_props, "Realtek RTL2831U reference design", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001838 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001839 &rtl28xxu_props, "Freecom USB2.0 DVB-T", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001840 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001841 &rtl28xxu_props, "Freecom USB2.0 DVB-T", NULL) },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001842
Jan Vcelak60aa4c62014-02-26 15:33:40 -03001843 /* RTL2832U devices: */
Antti Palosaari254ee2e2012-09-18 10:27:05 -03001844 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001845 &rtl28xxu_props, "Realtek RTL2832U reference design", NULL) },
Antti Palosaari254ee2e2012-09-18 10:27:05 -03001846 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001847 &rtl28xxu_props, "Realtek RTL2832U reference design", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001848 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001849 &rtl28xxu_props, "TerraTec Cinergy T Stick Black", RC_MAP_TERRATEC_SLIM) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001850 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001851 &rtl28xxu_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001852 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001853 &rtl28xxu_props, "TerraTec NOXON DAB Stick", NULL) },
Juergen Locke9de0512012-11-13 14:09:28 -03001854 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV2,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001855 &rtl28xxu_props, "TerraTec NOXON DAB Stick (rev 2)", NULL) },
Till Dörgesa24bc322014-02-11 17:27:57 -03001856 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV3,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001857 &rtl28xxu_props, "TerraTec NOXON DAB Stick (rev 3)", NULL) },
Philipp Dreimann6d608052012-09-02 19:30:54 -03001858 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001859 &rtl28xxu_props, "Trekstor DVB-T Stick Terres 2.0", NULL) },
Antti Palosaaric2d246d12012-09-08 22:07:26 -03001860 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001861 &rtl28xxu_props, "Dexatek DK DVB-T Dongle", NULL) },
Antti Palosaari3d8866d2012-09-20 18:34:50 -03001862 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6680,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001863 &rtl28xxu_props, "DigitalNow Quad DVB-T Receiver", NULL) },
Robert Backhausd22d32e2013-12-13 09:59:10 -03001864 { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_MINID,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001865 &rtl28xxu_props, "Leadtek Winfast DTV Dongle Mini D", NULL) },
Christian Dale09f50122015-03-09 02:19:01 -03001866 { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS_PLUS,
1867 &rtl28xxu_props, "Leadtek WinFast DTV2000DS Plus", RC_MAP_LEADTEK_Y04G0051) },
Antti Palosaaria4f64402012-09-29 15:28:56 -03001868 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d3,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001869 &rtl28xxu_props, "TerraTec Cinergy T Stick RC (Rev. 3)", NULL) },
Antti Palosaari08e57272012-11-06 16:03:35 -03001870 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1102,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001871 &rtl28xxu_props, "Dexatek DK mini DVB-T Dongle", NULL) },
Andrew Karpow86163ad2012-11-06 20:01:16 -03001872 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d7,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001873 &rtl28xxu_props, "TerraTec Cinergy T Stick+", NULL) },
Antti Palosaari3971e792012-12-16 11:47:07 -03001874 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd3a8,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001875 &rtl28xxu_props, "ASUS My Cinema-U3100Mini Plus V2", NULL) },
Alexander Inyukhin78a5e702013-01-04 18:19:02 -03001876 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd393,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001877 &rtl28xxu_props, "GIGABYTE U7300", NULL) },
Eddi De Pieri09f94082013-01-14 18:21:32 -03001878 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1104,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001879 &rtl28xxu_props, "MSI DIGIVOX Micro HD", NULL) },
Alistair Buxtonb9e2aff2013-02-12 21:58:47 -03001880 { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001881 &rtl28xxu_props, "Compro VideoMate U620F", NULL) },
Fabrizio Gazzatoe6a60d72013-02-15 18:54:54 -03001882 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001883 &rtl28xxu_props, "MaxMedia HU394-T", NULL) },
Miroslav Šustek6c5a4062013-05-14 19:42:11 -03001884 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001885 &rtl28xxu_props, "Leadtek WinFast DTV Dongle mini", NULL) },
Alessandro Micelic6be7522013-06-04 16:10:34 -03001886 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001887 &rtl28xxu_props, "Crypto ReDi PC 50 A", NULL) },
Jan Vcelakac298cc2014-02-26 15:33:39 -03001888 { DVB_USB_DEVICE(USB_VID_KYE, 0x707f,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001889 &rtl28xxu_props, "Genius TVGo DVB-T03", NULL) },
Brian Healy9ca24ae2014-05-04 18:43:39 -03001890 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd395,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001891 &rtl28xxu_props, "Peak DVB-T USB", NULL) },
Alessandro Micelif27f5b02014-05-04 07:37:15 -03001892 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20_RTL2832U,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001893 &rtl28xxu_props, "Sveon STV20", NULL) },
Sebastian89c5ff02014-06-12 03:22:45 -03001894 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV21,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001895 &rtl28xxu_props, "Sveon STV21", NULL) },
Alessandro Miceli74a86272014-05-04 07:50:31 -03001896 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV27,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001897 &rtl28xxu_props, "Sveon STV27", NULL) },
Dimitris Lampridis882302c2015-02-14 11:11:34 -03001898 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TURBOX_DTT_2000,
1899 &rtl28xxu_props, "TURBO-X Pure TV Tuner DTT-2000", NULL) },
Antti Palosaari8fdd33b2013-10-30 02:33:42 -03001900
Jan Vcelak60aa4c62014-02-26 15:33:40 -03001901 /* RTL2832P devices: */
Antti Palosaari8fdd33b2013-10-30 02:33:42 -03001902 { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001903 &rtl28xxu_props, "Astrometa DVB-T2", NULL) },
Olli Salonen699dcff2015-05-05 13:54:19 -03001904 { DVB_USB_DEVICE(0x5654, 0xca42,
1905 &rtl28xxu_props, "GoTView MasterHD 3", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001906 { }
1907};
1908MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001909
Antti Palosaaric01a3592012-08-12 22:27:07 -03001910static struct usb_driver rtl28xxu_usb_driver = {
1911 .name = KBUILD_MODNAME,
1912 .id_table = rtl28xxu_id_table,
1913 .probe = dvb_usbv2_probe,
1914 .disconnect = dvb_usbv2_disconnect,
1915 .suspend = dvb_usbv2_suspend,
1916 .resume = dvb_usbv2_resume,
Antti Palosaari78fa5902012-08-14 22:21:09 -03001917 .reset_resume = dvb_usbv2_reset_resume,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001918 .no_dynamic_id = 1,
1919 .soft_unbind = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001920};
1921
Antti Palosaaric01a3592012-08-12 22:27:07 -03001922module_usb_driver(rtl28xxu_usb_driver);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001923
1924MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
1925MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
Thomas Mair5cf66312012-05-18 14:47:41 -03001926MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>");
Antti Palosaari831e0b72011-07-08 23:36:07 -03001927MODULE_LICENSE("GPL");