blob: 5a503a6bb8c5dc9f40b0a4b051db9d489d8ff92c [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
Antti Palosaarid18ca5b2015-10-06 00:22:23 -030037 mutex_lock(&d->usb_mutex);
38
39 if (req->size > sizeof(dev->buf)) {
40 dev_err(&d->intf->dev, "too large message %u\n", req->size);
41 ret = -EINVAL;
42 goto err_mutex_unlock;
43 }
44
Antti Palosaari831e0b72011-07-08 23:36:07 -030045 if (req->index & CMD_WR_FLAG) {
46 /* write */
Antti Palosaaric56222a2014-12-21 18:33:14 -030047 memcpy(dev->buf, req->data, req->size);
Antti Palosaari831e0b72011-07-08 23:36:07 -030048 requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT);
49 pipe = usb_sndctrlpipe(d->udev, 0);
50 } else {
51 /* read */
52 requesttype = (USB_TYPE_VENDOR | USB_DIR_IN);
53 pipe = usb_rcvctrlpipe(d->udev, 0);
54 }
55
56 ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value,
Antti Palosaaric56222a2014-12-21 18:33:14 -030057 req->index, dev->buf, req->size, 1000);
Antti Palosaarid89b9362012-08-22 19:42:00 -030058 dvb_usb_dbg_usb_control_msg(d->udev, 0, requesttype, req->value,
Antti Palosaaric56222a2014-12-21 18:33:14 -030059 req->index, dev->buf, req->size);
60 if (ret < 0)
Antti Palosaarid18ca5b2015-10-06 00:22:23 -030061 goto err_mutex_unlock;
Antti Palosaari9935eea2012-01-21 22:26:52 -030062
Antti Palosaaric56222a2014-12-21 18:33:14 -030063 /* read request, copy returned data to return buf */
64 if (requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
65 memcpy(req->data, dev->buf, req->size);
66
Antti Palosaarid18ca5b2015-10-06 00:22:23 -030067 mutex_unlock(&d->usb_mutex);
68
Antti Palosaaric56222a2014-12-21 18:33:14 -030069 return 0;
Antti Palosaarid18ca5b2015-10-06 00:22:23 -030070err_mutex_unlock:
71 mutex_unlock(&d->usb_mutex);
Antti Palosaari5ba4ca12014-12-21 11:25:57 -030072 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -030073 return ret;
74}
75
Antti Palosaari670ef052014-12-23 14:32:35 -030076static int rtl28xxu_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
Antti Palosaari831e0b72011-07-08 23:36:07 -030077{
78 struct rtl28xxu_req req;
79
80 if (reg < 0x3000)
81 req.index = CMD_USB_WR;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -030082 else if (reg < 0x4000)
Antti Palosaari831e0b72011-07-08 23:36:07 -030083 req.index = CMD_SYS_WR;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -030084 else
85 req.index = CMD_IR_WR;
Antti Palosaari831e0b72011-07-08 23:36:07 -030086
87 req.value = reg;
88 req.size = len;
89 req.data = val;
90
91 return rtl28xxu_ctrl_msg(d, &req);
92}
93
Antti Palosaari670ef052014-12-23 14:32:35 -030094static int rtl28xxu_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
Antti Palosaari831e0b72011-07-08 23:36:07 -030095{
96 struct rtl28xxu_req req;
97
98 if (reg < 0x3000)
99 req.index = CMD_USB_RD;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300100 else if (reg < 0x4000)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300101 req.index = CMD_SYS_RD;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300102 else
103 req.index = CMD_IR_RD;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300104
105 req.value = reg;
106 req.size = len;
107 req.data = val;
108
109 return rtl28xxu_ctrl_msg(d, &req);
110}
111
Antti Palosaari670ef052014-12-23 14:32:35 -0300112static int rtl28xxu_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300113{
Antti Palosaari670ef052014-12-23 14:32:35 -0300114 return rtl28xxu_wr_regs(d, reg, &val, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300115}
116
Antti Palosaari670ef052014-12-23 14:32:35 -0300117static int rtl28xxu_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300118{
Antti Palosaari670ef052014-12-23 14:32:35 -0300119 return rtl28xxu_rd_regs(d, reg, val, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300120}
121
Antti Palosaari670ef052014-12-23 14:32:35 -0300122static int rtl28xxu_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300123 u8 mask)
124{
125 int ret;
126 u8 tmp;
127
128 /* no need for read if whole reg is written */
129 if (mask != 0xff) {
Antti Palosaari670ef052014-12-23 14:32:35 -0300130 ret = rtl28xxu_rd_reg(d, reg, &tmp);
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300131 if (ret)
132 return ret;
133
134 val &= mask;
135 tmp &= ~mask;
136 val |= tmp;
137 }
138
Antti Palosaari670ef052014-12-23 14:32:35 -0300139 return rtl28xxu_wr_reg(d, reg, val);
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300140}
141
Antti Palosaari831e0b72011-07-08 23:36:07 -0300142/* I2C */
143static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
144 int num)
145{
146 int ret;
147 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300148 struct rtl28xxu_dev *dev = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300149 struct rtl28xxu_req req;
150
151 /*
152 * It is not known which are real I2C bus xfer limits, but testing
153 * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes.
Antti Palosaari34ec2932011-08-04 20:21:16 -0300154 * TODO: find out RTL2832U lens
155 */
156
157 /*
158 * I2C adapter logic looks rather complicated due to fact it handles
159 * three different access methods. Those methods are;
160 * 1) integrated demod access
161 * 2) old I2C access
162 * 3) new I2C access
163 *
164 * Used method is selected in order 1, 2, 3. Method 3 can handle all
165 * requests but there is two reasons why not use it always;
166 * 1) It is most expensive, usually two USB messages are needed
167 * 2) At least RTL2831U does not support it
168 *
169 * Method 3 is needed in case of I2C write+read (typical register read)
170 * where write is more than one byte.
Antti Palosaari831e0b72011-07-08 23:36:07 -0300171 */
172
173 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
174 return -EAGAIN;
175
176 if (num == 2 && !(msg[0].flags & I2C_M_RD) &&
177 (msg[1].flags & I2C_M_RD)) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300178 if (msg[0].len > 24 || msg[1].len > 24) {
179 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300180 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300181 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300182 } else if (msg[0].addr == 0x10) {
183 /* method 1 - integrated demod */
184 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300185 req.index = CMD_DEMOD_RD | dev->page;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300186 req.size = msg[1].len;
187 req.data = &msg[1].buf[0];
188 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300189 } else if (msg[0].len < 2) {
190 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300191 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
192 req.index = CMD_I2C_RD;
193 req.size = msg[1].len;
194 req.data = &msg[1].buf[0];
195 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300196 } else {
197 /* method 3 - new I2C */
198 req.value = (msg[0].addr << 1);
199 req.index = CMD_I2C_DA_WR;
200 req.size = msg[0].len;
201 req.data = msg[0].buf;
202 ret = rtl28xxu_ctrl_msg(d, &req);
203 if (ret)
Antti Palosaari9935eea2012-01-21 22:26:52 -0300204 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300205
206 req.value = (msg[0].addr << 1);
207 req.index = CMD_I2C_DA_RD;
208 req.size = msg[1].len;
209 req.data = msg[1].buf;
210 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300211 }
212 } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
213 if (msg[0].len > 22) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300214 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300215 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300216 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300217 } else if (msg[0].addr == 0x10) {
218 /* method 1 - integrated demod */
219 if (msg[0].buf[0] == 0x00) {
220 /* save demod page for later demod access */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300221 dev->page = msg[0].buf[1];
Antti Palosaari34ec2932011-08-04 20:21:16 -0300222 ret = 0;
223 } else {
224 req.value = (msg[0].buf[0] << 8) |
225 (msg[0].addr << 1);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300226 req.index = CMD_DEMOD_WR | dev->page;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300227 req.size = msg[0].len-1;
228 req.data = &msg[0].buf[1];
229 ret = rtl28xxu_ctrl_msg(d, &req);
230 }
Olli Salonen699dcff2015-05-05 13:54:19 -0300231 } else if ((msg[0].len < 23) && (!dev->new_i2c_write)) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300232 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300233 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
234 req.index = CMD_I2C_WR;
235 req.size = msg[0].len-1;
236 req.data = &msg[0].buf[1];
237 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300238 } else {
239 /* method 3 - new I2C */
240 req.value = (msg[0].addr << 1);
241 req.index = CMD_I2C_DA_WR;
242 req.size = msg[0].len;
243 req.data = msg[0].buf;
244 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300245 }
Olli Salonend744a0c2015-05-05 13:54:18 -0300246 } else if (num == 1 && (msg[0].flags & I2C_M_RD)) {
247 req.value = (msg[0].addr << 1);
248 req.index = CMD_I2C_DA_RD;
249 req.size = msg[0].len;
250 req.data = msg[0].buf;
251 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300252 } else {
Olli Salonend744a0c2015-05-05 13:54:18 -0300253 ret = -EOPNOTSUPP;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300254 }
255
Antti Palosaari9935eea2012-01-21 22:26:52 -0300256err_mutex_unlock:
Antti Palosaari831e0b72011-07-08 23:36:07 -0300257 mutex_unlock(&d->i2c_mutex);
258
259 return ret ? ret : num;
260}
261
262static u32 rtl28xxu_i2c_func(struct i2c_adapter *adapter)
263{
264 return I2C_FUNC_I2C;
265}
266
267static struct i2c_algorithm rtl28xxu_i2c_algo = {
268 .master_xfer = rtl28xxu_i2c_xfer,
269 .functionality = rtl28xxu_i2c_func,
270};
271
Antti Palosaari81347f52012-09-17 16:50:36 -0300272static int rtl2831u_read_config(struct dvb_usb_device *d)
273{
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300274 struct rtl28xxu_dev *dev = d_to_priv(d);
Antti Palosaari81347f52012-09-17 16:50:36 -0300275 int ret;
276 u8 buf[1];
277 /* open RTL2831U/RTL2830 I2C gate */
278 struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x08"};
279 /* tuner probes */
280 struct rtl28xxu_req req_mt2060 = {0x00c0, CMD_I2C_RD, 1, buf};
281 struct rtl28xxu_req req_qt1010 = {0x0fc4, CMD_I2C_RD, 1, buf};
282
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300283 dev_dbg(&d->intf->dev, "\n");
Antti Palosaari81347f52012-09-17 16:50:36 -0300284
285 /*
286 * RTL2831U GPIOs
287 * =========================================================
288 * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?)
289 * GPIO2 | LED | 0 off | 1 on |
290 * GPIO4 | tuner#1 | 0 on | 1 off | MT2060
291 */
292
293 /* GPIO direction */
Antti Palosaari670ef052014-12-23 14:32:35 -0300294 ret = rtl28xxu_wr_reg(d, SYS_GPIO_DIR, 0x0a);
Antti Palosaari81347f52012-09-17 16:50:36 -0300295 if (ret)
296 goto err;
297
298 /* enable as output GPIO0, GPIO2, GPIO4 */
Antti Palosaari670ef052014-12-23 14:32:35 -0300299 ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_EN, 0x15);
Antti Palosaari81347f52012-09-17 16:50:36 -0300300 if (ret)
301 goto err;
302
303 /*
304 * Probe used tuner. We need to know used tuner before demod attach
305 * since there is some demod params needed to set according to tuner.
306 */
307
308 /* demod needs some time to wake up */
309 msleep(20);
310
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300311 dev->tuner_name = "NONE";
Antti Palosaari81347f52012-09-17 16:50:36 -0300312
313 /* open demod I2C gate */
314 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
315 if (ret)
316 goto err;
317
318 /* check QT1010 ID(?) register; reg=0f val=2c */
319 ret = rtl28xxu_ctrl_msg(d, &req_qt1010);
320 if (ret == 0 && buf[0] == 0x2c) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300321 dev->tuner = TUNER_RTL2830_QT1010;
322 dev->tuner_name = "QT1010";
Antti Palosaari81347f52012-09-17 16:50:36 -0300323 goto found;
324 }
325
326 /* open demod I2C gate */
327 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
328 if (ret)
329 goto err;
330
331 /* check MT2060 ID register; reg=00 val=63 */
332 ret = rtl28xxu_ctrl_msg(d, &req_mt2060);
333 if (ret == 0 && buf[0] == 0x63) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300334 dev->tuner = TUNER_RTL2830_MT2060;
335 dev->tuner_name = "MT2060";
Antti Palosaari81347f52012-09-17 16:50:36 -0300336 goto found;
337 }
338
339 /* assume MXL5005S */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300340 dev->tuner = TUNER_RTL2830_MXL5005S;
341 dev->tuner_name = "MXL5005S";
Antti Palosaari81347f52012-09-17 16:50:36 -0300342 goto found;
343
344found:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300345 dev_dbg(&d->intf->dev, "tuner=%s\n", dev->tuner_name);
Antti Palosaari81347f52012-09-17 16:50:36 -0300346
347 return 0;
348err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300349 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari81347f52012-09-17 16:50:36 -0300350 return ret;
351}
352
Antti Palosaarief37be12012-09-17 14:01:35 -0300353static int rtl2832u_read_config(struct dvb_usb_device *d)
354{
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300355 struct rtl28xxu_dev *dev = d_to_priv(d);
Antti Palosaarief37be12012-09-17 14:01:35 -0300356 int ret;
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300357 u8 buf[2];
Antti Palosaarief37be12012-09-17 14:01:35 -0300358 /* open RTL2832U/RTL2832 I2C gate */
359 struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"};
360 /* close RTL2832U/RTL2832 I2C gate */
361 struct rtl28xxu_req req_gate_close = {0x0120, 0x0011, 0x0001, "\x10"};
362 /* tuner probes */
363 struct rtl28xxu_req req_fc0012 = {0x00c6, CMD_I2C_RD, 1, buf};
364 struct rtl28xxu_req req_fc0013 = {0x00c6, CMD_I2C_RD, 1, buf};
365 struct rtl28xxu_req req_mt2266 = {0x00c0, CMD_I2C_RD, 1, buf};
366 struct rtl28xxu_req req_fc2580 = {0x01ac, CMD_I2C_RD, 1, buf};
367 struct rtl28xxu_req req_mt2063 = {0x00c0, CMD_I2C_RD, 1, buf};
368 struct rtl28xxu_req req_max3543 = {0x00c0, CMD_I2C_RD, 1, buf};
369 struct rtl28xxu_req req_tua9001 = {0x7ec0, CMD_I2C_RD, 2, buf};
370 struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf};
371 struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
372 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
Gianluca Gennaria908eb92013-06-02 17:24:24 -0300373 struct rtl28xxu_req req_r820t = {0x0034, CMD_I2C_RD, 1, buf};
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300374 struct rtl28xxu_req req_r828d = {0x0074, CMD_I2C_RD, 1, buf};
Antti Palosaari80f189a2013-12-01 13:44:23 -0300375 struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf};
Antti Palosaarifc694e42014-09-30 01:03:04 -0300376 struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf};
Olli Salonen699dcff2015-05-05 13:54:19 -0300377 struct rtl28xxu_req req_si2157 = {0x00c0, CMD_I2C_RD, 1, buf};
378 struct rtl28xxu_req req_si2168 = {0x00c8, CMD_I2C_RD, 1, buf};
Antti Palosaarief37be12012-09-17 14:01:35 -0300379
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300380 dev_dbg(&d->intf->dev, "\n");
Antti Palosaarief37be12012-09-17 14:01:35 -0300381
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300382 /* enable GPIO3 and GPIO6 as output */
Antti Palosaari670ef052014-12-23 14:32:35 -0300383 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x40);
Antti Palosaarief37be12012-09-17 14:01:35 -0300384 if (ret)
385 goto err;
386
Antti Palosaari670ef052014-12-23 14:32:35 -0300387 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x48, 0x48);
Antti Palosaarief37be12012-09-17 14:01:35 -0300388 if (ret)
389 goto err;
390
391 /*
392 * Probe used tuner. We need to know used tuner before demod attach
393 * since there is some demod params needed to set according to tuner.
394 */
395
396 /* open demod I2C gate */
397 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
398 if (ret)
399 goto err;
400
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300401 dev->tuner_name = "NONE";
Antti Palosaarief37be12012-09-17 14:01:35 -0300402
403 /* check FC0012 ID register; reg=00 val=a1 */
404 ret = rtl28xxu_ctrl_msg(d, &req_fc0012);
405 if (ret == 0 && buf[0] == 0xa1) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300406 dev->tuner = TUNER_RTL2832_FC0012;
407 dev->tuner_name = "FC0012";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300408 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300409 }
410
411 /* check FC0013 ID register; reg=00 val=a3 */
412 ret = rtl28xxu_ctrl_msg(d, &req_fc0013);
413 if (ret == 0 && buf[0] == 0xa3) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300414 dev->tuner = TUNER_RTL2832_FC0013;
415 dev->tuner_name = "FC0013";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300416 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300417 }
418
419 /* check MT2266 ID register; reg=00 val=85 */
420 ret = rtl28xxu_ctrl_msg(d, &req_mt2266);
421 if (ret == 0 && buf[0] == 0x85) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300422 dev->tuner = TUNER_RTL2832_MT2266;
423 dev->tuner_name = "MT2266";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300424 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300425 }
426
427 /* check FC2580 ID register; reg=01 val=56 */
428 ret = rtl28xxu_ctrl_msg(d, &req_fc2580);
429 if (ret == 0 && buf[0] == 0x56) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300430 dev->tuner = TUNER_RTL2832_FC2580;
431 dev->tuner_name = "FC2580";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300432 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300433 }
434
435 /* check MT2063 ID register; reg=00 val=9e || 9c */
436 ret = rtl28xxu_ctrl_msg(d, &req_mt2063);
437 if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300438 dev->tuner = TUNER_RTL2832_MT2063;
439 dev->tuner_name = "MT2063";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300440 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300441 }
442
443 /* check MAX3543 ID register; reg=00 val=38 */
444 ret = rtl28xxu_ctrl_msg(d, &req_max3543);
445 if (ret == 0 && buf[0] == 0x38) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300446 dev->tuner = TUNER_RTL2832_MAX3543;
447 dev->tuner_name = "MAX3543";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300448 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300449 }
450
451 /* check TUA9001 ID register; reg=7e val=2328 */
452 ret = rtl28xxu_ctrl_msg(d, &req_tua9001);
453 if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300454 dev->tuner = TUNER_RTL2832_TUA9001;
455 dev->tuner_name = "TUA9001";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300456 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300457 }
458
459 /* check MXL5007R ID register; reg=d9 val=14 */
460 ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t);
461 if (ret == 0 && buf[0] == 0x14) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300462 dev->tuner = TUNER_RTL2832_MXL5007T;
463 dev->tuner_name = "MXL5007T";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300464 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300465 }
466
467 /* check E4000 ID register; reg=02 val=40 */
468 ret = rtl28xxu_ctrl_msg(d, &req_e4000);
469 if (ret == 0 && buf[0] == 0x40) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300470 dev->tuner = TUNER_RTL2832_E4000;
471 dev->tuner_name = "E4000";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300472 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300473 }
474
475 /* check TDA18272 ID register; reg=00 val=c760 */
476 ret = rtl28xxu_ctrl_msg(d, &req_tda18272);
477 if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300478 dev->tuner = TUNER_RTL2832_TDA18272;
479 dev->tuner_name = "TDA18272";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300480 goto tuner_found;
Antti Palosaarief37be12012-09-17 14:01:35 -0300481 }
482
Gianluca Gennaria908eb92013-06-02 17:24:24 -0300483 /* check R820T ID register; reg=00 val=69 */
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300484 ret = rtl28xxu_ctrl_msg(d, &req_r820t);
Gianluca Gennaria908eb92013-06-02 17:24:24 -0300485 if (ret == 0 && buf[0] == 0x69) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300486 dev->tuner = TUNER_RTL2832_R820T;
487 dev->tuner_name = "R820T";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300488 goto tuner_found;
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300489 }
490
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300491 /* check R828D ID register; reg=00 val=69 */
492 ret = rtl28xxu_ctrl_msg(d, &req_r828d);
493 if (ret == 0 && buf[0] == 0x69) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300494 dev->tuner = TUNER_RTL2832_R828D;
495 dev->tuner_name = "R828D";
Antti Palosaari80f189a2013-12-01 13:44:23 -0300496 goto tuner_found;
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300497 }
498
Olli Salonen699dcff2015-05-05 13:54:19 -0300499 /* GPIO0 and GPIO5 to reset Si2157/Si2168 tuner and demod */
500 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x00, 0x21);
501 if (ret)
502 goto err;
503
504 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x00, 0x21);
505 if (ret)
506 goto err;
507
508 msleep(50);
509
510 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x21, 0x21);
511 if (ret)
512 goto err;
513
514 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x21, 0x21);
515 if (ret)
516 goto err;
517
518 msleep(50);
519
520 /* check Si2157 ID register; reg=c0 val=80 */
521 ret = rtl28xxu_ctrl_msg(d, &req_si2157);
522 if (ret == 0 && ((buf[0] & 0x80) == 0x80)) {
523 dev->tuner = TUNER_RTL2832_SI2157;
524 dev->tuner_name = "SI2157";
525 goto tuner_found;
526 }
527
Antti Palosaari80f189a2013-12-01 13:44:23 -0300528tuner_found:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300529 dev_dbg(&d->intf->dev, "tuner=%s\n", dev->tuner_name);
Antti Palosaarief37be12012-09-17 14:01:35 -0300530
Antti Palosaari80f189a2013-12-01 13:44:23 -0300531 /* probe slave demod */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300532 if (dev->tuner == TUNER_RTL2832_R828D) {
Antti Palosaari80f189a2013-12-01 13:44:23 -0300533 /* power on MN88472 demod on GPIO0 */
Antti Palosaari670ef052014-12-23 14:32:35 -0300534 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x01, 0x01);
Antti Palosaari80f189a2013-12-01 13:44:23 -0300535 if (ret)
536 goto err;
537
Antti Palosaari670ef052014-12-23 14:32:35 -0300538 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x01);
Antti Palosaari80f189a2013-12-01 13:44:23 -0300539 if (ret)
540 goto err;
541
Antti Palosaari670ef052014-12-23 14:32:35 -0300542 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x01, 0x01);
Antti Palosaari80f189a2013-12-01 13:44:23 -0300543 if (ret)
544 goto err;
545
546 /* check MN88472 answers */
547 ret = rtl28xxu_ctrl_msg(d, &req_mn88472);
548 if (ret == 0 && buf[0] == 0x02) {
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300549 dev_dbg(&d->intf->dev, "MN88472 found\n");
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300550 dev->slave_demod = SLAVE_DEMOD_MN88472;
Antti Palosaari80f189a2013-12-01 13:44:23 -0300551 goto demod_found;
552 }
Antti Palosaarifc694e42014-09-30 01:03:04 -0300553
554 ret = rtl28xxu_ctrl_msg(d, &req_mn88473);
555 if (ret == 0 && buf[0] == 0x03) {
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300556 dev_dbg(&d->intf->dev, "MN88473 found\n");
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300557 dev->slave_demod = SLAVE_DEMOD_MN88473;
Antti Palosaarifc694e42014-09-30 01:03:04 -0300558 goto demod_found;
559 }
Antti Palosaari80f189a2013-12-01 13:44:23 -0300560 }
Olli Salonen699dcff2015-05-05 13:54:19 -0300561 if (dev->tuner == TUNER_RTL2832_SI2157) {
562 /* check Si2168 ID register; reg=c8 val=80 */
563 ret = rtl28xxu_ctrl_msg(d, &req_si2168);
564 if (ret == 0 && ((buf[0] & 0x80) == 0x80)) {
565 dev_dbg(&d->intf->dev, "Si2168 found\n");
566 dev->slave_demod = SLAVE_DEMOD_SI2168;
567 goto demod_found;
568 }
569 }
Antti Palosaari80f189a2013-12-01 13:44:23 -0300570
571demod_found:
Antti Palosaarief37be12012-09-17 14:01:35 -0300572 /* close demod I2C gate */
573 ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
574 if (ret < 0)
575 goto err;
576
577 return 0;
578err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300579 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaarief37be12012-09-17 14:01:35 -0300580 return ret;
581}
582
Antti Palosaaride701f02014-12-23 14:09:13 -0300583static int rtl28xxu_read_config(struct dvb_usb_device *d)
584{
585 struct rtl28xxu_dev *dev = d_to_priv(d);
586
587 if (dev->chip_id == CHIP_ID_RTL2831U)
588 return rtl2831u_read_config(d);
589 else
590 return rtl2832u_read_config(d);
591}
592
Antti Palosaarid0f232e2014-12-23 13:14:36 -0300593static int rtl28xxu_identify_state(struct dvb_usb_device *d, const char **name)
594{
595 struct rtl28xxu_dev *dev = d_to_priv(d);
596 int ret;
597 struct rtl28xxu_req req_demod_i2c = {0x0020, CMD_I2C_DA_RD, 0, NULL};
598
599 dev_dbg(&d->intf->dev, "\n");
600
601 /*
602 * Detect chip type using I2C command that is not supported
603 * by old RTL2831U.
604 */
605 ret = rtl28xxu_ctrl_msg(d, &req_demod_i2c);
606 if (ret == -EPIPE) {
607 dev->chip_id = CHIP_ID_RTL2831U;
608 } else if (ret == 0) {
609 dev->chip_id = CHIP_ID_RTL2832U;
610 } else {
611 dev_err(&d->intf->dev, "chip type detection failed %d\n", ret);
612 goto err;
613 }
614 dev_dbg(&d->intf->dev, "chip_id=%u\n", dev->chip_id);
615
616 return WARM;
617err:
618 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
619 return ret;
620}
621
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300622static const struct rtl2830_platform_data rtl2830_mt2060_platform_data = {
623 .clk = 28800000,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300624 .spec_inv = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300625 .vtop = 0x20,
626 .krf = 0x04,
627 .agc_targ_val = 0x2d,
628
629};
630
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300631static const struct rtl2830_platform_data rtl2830_qt1010_platform_data = {
632 .clk = 28800000,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300633 .spec_inv = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300634 .vtop = 0x20,
635 .krf = 0x04,
636 .agc_targ_val = 0x2d,
637};
638
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300639static const struct rtl2830_platform_data rtl2830_mxl5005s_platform_data = {
640 .clk = 28800000,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300641 .spec_inv = 0,
Antti Palosaari831e0b72011-07-08 23:36:07 -0300642 .vtop = 0x3f,
643 .krf = 0x04,
644 .agc_targ_val = 0x3e,
645};
646
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300647static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300648{
Antti Palosaaric01a3592012-08-12 22:27:07 -0300649 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300650 struct rtl28xxu_dev *dev = d_to_priv(d);
651 struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data;
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300652 struct i2c_board_info board_info;
653 struct i2c_client *client;
Antti Palosaari81347f52012-09-17 16:50:36 -0300654 int ret;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300655
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300656 dev_dbg(&d->intf->dev, "\n");
Antti Palosaari831e0b72011-07-08 23:36:07 -0300657
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300658 switch (dev->tuner) {
Antti Palosaari81347f52012-09-17 16:50:36 -0300659 case TUNER_RTL2830_QT1010:
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300660 *pdata = rtl2830_qt1010_platform_data;
Antti Palosaari81347f52012-09-17 16:50:36 -0300661 break;
662 case TUNER_RTL2830_MT2060:
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300663 *pdata = rtl2830_mt2060_platform_data;
Antti Palosaari81347f52012-09-17 16:50:36 -0300664 break;
665 case TUNER_RTL2830_MXL5005S:
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300666 *pdata = rtl2830_mxl5005s_platform_data;
Antti Palosaari81347f52012-09-17 16:50:36 -0300667 break;
668 default:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300669 dev_err(&d->intf->dev, "unknown tuner %s\n", dev->tuner_name);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300670 ret = -ENODEV;
671 goto err;
672 }
673
Antti Palosaari81347f52012-09-17 16:50:36 -0300674 /* attach demodulator */
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300675 memset(&board_info, 0, sizeof(board_info));
676 strlcpy(board_info.type, "rtl2830", I2C_NAME_SIZE);
677 board_info.addr = 0x10;
678 board_info.platform_data = pdata;
679 request_module("%s", board_info.type);
680 client = i2c_new_device(&d->i2c_adap, &board_info);
681 if (client == NULL || client->dev.driver == NULL) {
Antti Palosaari81347f52012-09-17 16:50:36 -0300682 ret = -ENODEV;
683 goto err;
684 }
685
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300686 if (!try_module_get(client->dev.driver->owner)) {
687 i2c_unregister_device(client);
688 ret = -ENODEV;
689 goto err;
690 }
691
692 adap->fe[0] = pdata->get_dvb_frontend(client);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300693 dev->demod_i2c_adapter = pdata->get_i2c_adapter(client);
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300694
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300695 dev->i2c_client_demod = client;
Antti Palosaaric0ceac92014-12-07 22:02:23 -0300696
Antti Palosaari81347f52012-09-17 16:50:36 -0300697 return 0;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300698err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300699 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300700 return ret;
701}
702
Antti Palosaari7e33f8a2015-04-23 22:54:03 -0300703static const struct rtl2832_platform_data rtl2832_fc2580_platform_data = {
704 .clk = 28800000,
705 .tuner = TUNER_RTL2832_FC2580,
706};
707
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300708static const struct rtl2832_platform_data rtl2832_fc0012_platform_data = {
709 .clk = 28800000,
710 .tuner = TUNER_RTL2832_FC0012
711};
712
713static const struct rtl2832_platform_data rtl2832_fc0013_platform_data = {
714 .clk = 28800000,
715 .tuner = TUNER_RTL2832_FC0013
716};
717
718static const struct rtl2832_platform_data rtl2832_tua9001_platform_data = {
719 .clk = 28800000,
720 .tuner = TUNER_RTL2832_TUA9001,
721};
722
723static const struct rtl2832_platform_data rtl2832_e4000_platform_data = {
724 .clk = 28800000,
725 .tuner = TUNER_RTL2832_E4000,
726};
727
728static const struct rtl2832_platform_data rtl2832_r820t_platform_data = {
729 .clk = 28800000,
730 .tuner = TUNER_RTL2832_R820T,
731};
732
Olli Salonen699dcff2015-05-05 13:54:19 -0300733static const struct rtl2832_platform_data rtl2832_si2157_platform_data = {
734 .clk = 28800000,
735 .tuner = TUNER_RTL2832_SI2157,
736};
737
Thomas Mair5cf66312012-05-18 14:47:41 -0300738static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
739 int cmd, int arg)
740{
741 int ret;
742 u8 val;
743
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300744 dev_dbg(&d->intf->dev, "cmd=%d arg=%d\n", cmd, arg);
Antti Palosaaric01a3592012-08-12 22:27:07 -0300745
Thomas Mair5cf66312012-05-18 14:47:41 -0300746 switch (cmd) {
747 case FC_FE_CALLBACK_VHF_ENABLE:
748 /* set output values */
Antti Palosaari670ef052014-12-23 14:32:35 -0300749 ret = rtl28xxu_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300750 if (ret)
751 goto err;
752
753 if (arg)
754 val &= 0xbf; /* set GPIO6 low */
755 else
756 val |= 0x40; /* set GPIO6 high */
757
758
Antti Palosaari670ef052014-12-23 14:32:35 -0300759 ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300760 if (ret)
761 goto err;
762 break;
763 default:
764 ret = -EINVAL;
765 goto err;
766 }
767 return 0;
Thomas Mair5cf66312012-05-18 14:47:41 -0300768err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300769 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Thomas Mair5cf66312012-05-18 14:47:41 -0300770 return ret;
771}
772
Antti Palosaari5be65722012-09-11 22:27:09 -0300773static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d,
774 int cmd, int arg)
775{
776 int ret;
777 u8 val;
778
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300779 dev_dbg(&d->intf->dev, "cmd=%d arg=%d\n", cmd, arg);
Antti Palosaari5be65722012-09-11 22:27:09 -0300780
781 /*
782 * CEN always enabled by hardware wiring
783 * RESETN GPIO4
784 * RXEN GPIO1
785 */
786
Antti Palosaari5be65722012-09-11 22:27:09 -0300787 switch (cmd) {
788 case TUA9001_CMD_RESETN:
789 if (arg)
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300790 val = (1 << 4);
Antti Palosaari5be65722012-09-11 22:27:09 -0300791 else
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300792 val = (0 << 4);
Antti Palosaari5be65722012-09-11 22:27:09 -0300793
Antti Palosaari670ef052014-12-23 14:32:35 -0300794 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x10);
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300795 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300796 goto err;
797 break;
798 case TUA9001_CMD_RXEN:
799 if (arg)
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300800 val = (1 << 1);
Antti Palosaari5be65722012-09-11 22:27:09 -0300801 else
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300802 val = (0 << 1);
Antti Palosaari5be65722012-09-11 22:27:09 -0300803
Antti Palosaari670ef052014-12-23 14:32:35 -0300804 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x02);
Antti Palosaari4005c1a2012-09-17 15:43:57 -0300805 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -0300806 goto err;
807 break;
808 }
809
810 return 0;
Antti Palosaari5be65722012-09-11 22:27:09 -0300811err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300812 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari5be65722012-09-11 22:27:09 -0300813 return ret;
814}
815
Thomas Mair5cf66312012-05-18 14:47:41 -0300816static int rtl2832u_frontend_callback(void *adapter_priv, int component,
Antti Palosaari8acc91c2012-09-17 16:55:39 -0300817 int cmd, int arg)
Thomas Mair5cf66312012-05-18 14:47:41 -0300818{
Antti Palosaari1dbbdce2014-12-17 02:55:41 -0300819 struct i2c_adapter *adapter = adapter_priv;
820 struct device *parent = adapter->dev.parent;
821 struct i2c_adapter *parent_adapter;
822 struct dvb_usb_device *d;
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300823 struct rtl28xxu_dev *dev;
Antti Palosaari1dbbdce2014-12-17 02:55:41 -0300824
825 /*
826 * All tuners are connected to demod muxed I2C adapter. We have to
827 * resolve its parent adapter in order to get handle for this driver
828 * private data. That is a bit hackish solution, GPIO or direct driver
829 * callback would be better...
830 */
831 if (parent != NULL && parent->type == &i2c_adapter_type)
832 parent_adapter = to_i2c_adapter(parent);
833 else
834 return -EINVAL;
835
836 d = i2c_get_adapdata(parent_adapter);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300837 dev = d->priv;
Thomas Mair5cf66312012-05-18 14:47:41 -0300838
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300839 dev_dbg(&d->intf->dev, "component=%d cmd=%d arg=%d\n",
840 component, cmd, arg);
Antti Palosaari8acc91c2012-09-17 16:55:39 -0300841
Thomas Mair5cf66312012-05-18 14:47:41 -0300842 switch (component) {
843 case DVB_FRONTEND_COMPONENT_TUNER:
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300844 switch (dev->tuner) {
Antti Palosaaria6f62432014-12-17 03:09:32 -0300845 case TUNER_RTL2832_FC0012:
846 return rtl2832u_fc0012_tuner_callback(d, cmd, arg);
847 case TUNER_RTL2832_TUA9001:
848 return rtl2832u_tua9001_tuner_callback(d, cmd, arg);
849 }
Thomas Mair5cf66312012-05-18 14:47:41 -0300850 }
851
Antti Palosaari97efe782012-09-17 15:49:54 -0300852 return 0;
Thomas Mair5cf66312012-05-18 14:47:41 -0300853}
854
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300855static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
856{
Antti Palosaaric01a3592012-08-12 22:27:07 -0300857 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300858 struct rtl28xxu_dev *dev = d_to_priv(d);
859 struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data;
Antti Palosaari77a2e762014-12-13 00:09:57 -0300860 struct i2c_board_info board_info;
Antti Palosaari83b2f842014-12-02 11:00:23 -0300861 struct i2c_client *client;
Antti Palosaari77a2e762014-12-13 00:09:57 -0300862 int ret;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300863
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300864 dev_dbg(&d->intf->dev, "\n");
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300865
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300866 switch (dev->tuner) {
Antti Palosaarief37be12012-09-17 14:01:35 -0300867 case TUNER_RTL2832_FC0012:
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300868 *pdata = rtl2832_fc0012_platform_data;
Antti Palosaarief37be12012-09-17 14:01:35 -0300869 break;
870 case TUNER_RTL2832_FC0013:
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300871 *pdata = rtl2832_fc0013_platform_data;
Antti Palosaarief37be12012-09-17 14:01:35 -0300872 break;
873 case TUNER_RTL2832_FC2580:
Antti Palosaari7e33f8a2015-04-23 22:54:03 -0300874 *pdata = rtl2832_fc2580_platform_data;
Antti Palosaarief37be12012-09-17 14:01:35 -0300875 break;
876 case TUNER_RTL2832_TUA9001:
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300877 *pdata = rtl2832_tua9001_platform_data;
Antti Palosaarief37be12012-09-17 14:01:35 -0300878 break;
879 case TUNER_RTL2832_E4000:
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300880 *pdata = rtl2832_e4000_platform_data;
Antti Palosaarief37be12012-09-17 14:01:35 -0300881 break;
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300882 case TUNER_RTL2832_R820T:
Antti Palosaari8b4cac12013-10-30 00:45:38 -0300883 case TUNER_RTL2832_R828D:
Antti Palosaaride0a5f12014-12-13 05:44:05 -0300884 *pdata = rtl2832_r820t_platform_data;
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -0300885 break;
Olli Salonen699dcff2015-05-05 13:54:19 -0300886 case TUNER_RTL2832_SI2157:
887 *pdata = rtl2832_si2157_platform_data;
888 break;
Antti Palosaarief37be12012-09-17 14:01:35 -0300889 default:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -0300890 dev_err(&d->intf->dev, "unknown tuner %s\n", dev->tuner_name);
Antti Palosaarief37be12012-09-17 14:01:35 -0300891 ret = -ENODEV;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300892 goto err;
Antti Palosaarief37be12012-09-17 14:01:35 -0300893 }
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300894
895 /* attach demodulator */
Antti Palosaari77a2e762014-12-13 00:09:57 -0300896 memset(&board_info, 0, sizeof(board_info));
Antti Palosaari83b2f842014-12-02 11:00:23 -0300897 strlcpy(board_info.type, "rtl2832", I2C_NAME_SIZE);
898 board_info.addr = 0x10;
Antti Palosaari77a2e762014-12-13 00:09:57 -0300899 board_info.platform_data = pdata;
Antti Palosaari83b2f842014-12-02 11:00:23 -0300900 request_module("%s", board_info.type);
901 client = i2c_new_device(&d->i2c_adap, &board_info);
902 if (client == NULL || client->dev.driver == NULL) {
Antti Palosaarief37be12012-09-17 14:01:35 -0300903 ret = -ENODEV;
904 goto err;
905 }
Thomas Mair5cf66312012-05-18 14:47:41 -0300906
Antti Palosaari83b2f842014-12-02 11:00:23 -0300907 if (!try_module_get(client->dev.driver->owner)) {
908 i2c_unregister_device(client);
909 ret = -ENODEV;
910 goto err;
911 }
912
Antti Palosaari77a2e762014-12-13 00:09:57 -0300913 adap->fe[0] = pdata->get_dvb_frontend(client);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300914 dev->demod_i2c_adapter = pdata->get_i2c_adapter(client);
Antti Palosaari83b2f842014-12-02 11:00:23 -0300915
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300916 dev->i2c_client_demod = client;
Antti Palosaariae1f8452014-02-08 04:03:57 -0300917
Antti Palosaarief37be12012-09-17 14:01:35 -0300918 /* set fe callback */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300919 adap->fe[0]->callback = rtl2832u_frontend_callback;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300920
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300921 if (dev->slave_demod) {
Antti Palosaari80f189a2013-12-01 13:44:23 -0300922 struct i2c_board_info info = {};
Antti Palosaari80f189a2013-12-01 13:44:23 -0300923
924 /*
925 * We continue on reduced mode, without DVB-T2/C, using master
926 * demod, when slave demod fails.
927 */
928 ret = 0;
929
930 /* attach slave demodulator */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300931 if (dev->slave_demod == SLAVE_DEMOD_MN88472) {
Antti Palosaari80f189a2013-12-01 13:44:23 -0300932 struct mn88472_config mn88472_config = {};
933
934 mn88472_config.fe = &adap->fe[1];
935 mn88472_config.i2c_wr_max = 22,
936 strlcpy(info.type, "mn88472", I2C_NAME_SIZE);
Benjamin Larssond2fb7852014-11-26 18:51:46 -0300937 mn88472_config.xtal = 20500000;
Benjamin Larsson021cd2d2014-12-05 21:25:33 -0300938 mn88472_config.ts_mode = SERIAL_TS_MODE;
939 mn88472_config.ts_clock = VARIABLE_TS_CLOCK;
Antti Palosaari80f189a2013-12-01 13:44:23 -0300940 info.addr = 0x18;
941 info.platform_data = &mn88472_config;
942 request_module(info.type);
Antti Palosaari488be132014-12-16 11:05:08 -0300943 client = i2c_new_device(&d->i2c_adap, &info);
Antti Palosaari80f189a2013-12-01 13:44:23 -0300944 if (client == NULL || client->dev.driver == NULL) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300945 dev->slave_demod = SLAVE_DEMOD_NONE;
Antti Palosaari80f189a2013-12-01 13:44:23 -0300946 goto err_slave_demod_failed;
947 }
948
949 if (!try_module_get(client->dev.driver->owner)) {
950 i2c_unregister_device(client);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300951 dev->slave_demod = SLAVE_DEMOD_NONE;
Antti Palosaari80f189a2013-12-01 13:44:23 -0300952 goto err_slave_demod_failed;
953 }
954
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300955 dev->i2c_client_slave_demod = client;
Olli Salonen699dcff2015-05-05 13:54:19 -0300956 } else if (dev->slave_demod == SLAVE_DEMOD_MN88473) {
Antti Palosaarifc694e42014-09-30 01:03:04 -0300957 struct mn88473_config mn88473_config = {};
958
959 mn88473_config.fe = &adap->fe[1];
960 mn88473_config.i2c_wr_max = 22,
961 strlcpy(info.type, "mn88473", I2C_NAME_SIZE);
962 info.addr = 0x18;
963 info.platform_data = &mn88473_config;
964 request_module(info.type);
Antti Palosaari488be132014-12-16 11:05:08 -0300965 client = i2c_new_device(&d->i2c_adap, &info);
Antti Palosaarifc694e42014-09-30 01:03:04 -0300966 if (client == NULL || client->dev.driver == NULL) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300967 dev->slave_demod = SLAVE_DEMOD_NONE;
Antti Palosaarifc694e42014-09-30 01:03:04 -0300968 goto err_slave_demod_failed;
969 }
970
971 if (!try_module_get(client->dev.driver->owner)) {
972 i2c_unregister_device(client);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300973 dev->slave_demod = SLAVE_DEMOD_NONE;
Antti Palosaarifc694e42014-09-30 01:03:04 -0300974 goto err_slave_demod_failed;
975 }
976
Antti Palosaari9a02e8f2014-12-18 08:05:23 -0300977 dev->i2c_client_slave_demod = client;
Olli Salonen699dcff2015-05-05 13:54:19 -0300978 } else {
979 struct si2168_config si2168_config = {};
980 struct i2c_adapter *adapter;
981
982 si2168_config.i2c_adapter = &adapter;
983 si2168_config.fe = &adap->fe[1];
984 si2168_config.ts_mode = SI2168_TS_SERIAL;
985 si2168_config.ts_clock_inv = false;
986 si2168_config.ts_clock_gapped = true;
987 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
988 info.addr = 0x64;
989 info.platform_data = &si2168_config;
990 request_module(info.type);
991 client = i2c_new_device(&d->i2c_adap, &info);
992 if (client == NULL || client->dev.driver == NULL) {
993 dev->slave_demod = SLAVE_DEMOD_NONE;
994 goto err_slave_demod_failed;
995 }
996
997 if (!try_module_get(client->dev.driver->owner)) {
998 i2c_unregister_device(client);
999 dev->slave_demod = SLAVE_DEMOD_NONE;
1000 goto err_slave_demod_failed;
1001 }
1002
1003 dev->i2c_client_slave_demod = client;
1004
1005 /* for Si2168 devices use only new I2C write method */
1006 dev->new_i2c_write = true;
Antti Palosaari80f189a2013-12-01 13:44:23 -03001007 }
1008 }
Antti Palosaarief37be12012-09-17 14:01:35 -03001009 return 0;
Antti Palosaari80f189a2013-12-01 13:44:23 -03001010err_slave_demod_failed:
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001011err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001012 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001013 return ret;
1014}
1015
Antti Palosaaride701f02014-12-23 14:09:13 -03001016static int rtl28xxu_frontend_attach(struct dvb_usb_adapter *adap)
1017{
1018 struct rtl28xxu_dev *dev = adap_to_priv(adap);
1019
1020 if (dev->chip_id == CHIP_ID_RTL2831U)
1021 return rtl2831u_frontend_attach(adap);
1022 else
1023 return rtl2832u_frontend_attach(adap);
1024}
1025
1026static int rtl28xxu_frontend_detach(struct dvb_usb_adapter *adap)
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001027{
1028 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001029 struct rtl28xxu_dev *dev = d_to_priv(d);
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001030 struct i2c_client *client;
1031
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001032 dev_dbg(&d->intf->dev, "\n");
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001033
1034 /* remove I2C slave demod */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001035 client = dev->i2c_client_slave_demod;
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001036 if (client) {
1037 module_put(client->dev.driver->owner);
1038 i2c_unregister_device(client);
1039 }
1040
1041 /* remove I2C demod */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001042 client = dev->i2c_client_demod;
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001043 if (client) {
1044 module_put(client->dev.driver->owner);
1045 i2c_unregister_device(client);
1046 }
1047
1048 return 0;
1049}
1050
Antti Palosaari831e0b72011-07-08 23:36:07 -03001051static struct qt1010_config rtl28xxu_qt1010_config = {
1052 .i2c_address = 0x62, /* 0xc4 */
1053};
1054
1055static struct mt2060_config rtl28xxu_mt2060_config = {
1056 .i2c_address = 0x60, /* 0xc0 */
1057 .clock_out = 0,
1058};
1059
1060static struct mxl5005s_config rtl28xxu_mxl5005s_config = {
1061 .i2c_address = 0x63, /* 0xc6 */
1062 .if_freq = IF_FREQ_4570000HZ,
1063 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
1064 .agc_mode = MXL_SINGLE_AGC,
1065 .tracking_filter = MXL_TF_C_H,
1066 .rssi_enable = MXL_RSSI_ENABLE,
1067 .cap_select = MXL_CAP_SEL_ENABLE,
1068 .div_out = MXL_DIV_OUT_4,
1069 .clock_out = MXL_CLOCK_OUT_DISABLE,
1070 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
1071 .top = MXL5005S_TOP_25P2,
1072 .mod_mode = MXL_DIGITAL_MODE,
1073 .if_mode = MXL_ZERO_IF,
1074 .AgcMasterByte = 0x00,
1075};
1076
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001077static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001078{
1079 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -03001080 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001081 struct rtl28xxu_dev *dev = d_to_priv(d);
Antti Palosaari9935eea2012-01-21 22:26:52 -03001082 struct dvb_frontend *fe;
Antti Palosaari831e0b72011-07-08 23:36:07 -03001083
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001084 dev_dbg(&d->intf->dev, "\n");
Antti Palosaari831e0b72011-07-08 23:36:07 -03001085
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001086 switch (dev->tuner) {
Antti Palosaari831e0b72011-07-08 23:36:07 -03001087 case TUNER_RTL2830_QT1010:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001088 fe = dvb_attach(qt1010_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001089 dev->demod_i2c_adapter,
Antti Palosaaric0ceac92014-12-07 22:02:23 -03001090 &rtl28xxu_qt1010_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001091 break;
1092 case TUNER_RTL2830_MT2060:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001093 fe = dvb_attach(mt2060_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001094 dev->demod_i2c_adapter,
Antti Palosaaric0ceac92014-12-07 22:02:23 -03001095 &rtl28xxu_mt2060_config, 1220);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001096 break;
1097 case TUNER_RTL2830_MXL5005S:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001098 fe = dvb_attach(mxl5005s_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001099 dev->demod_i2c_adapter,
Antti Palosaaric0ceac92014-12-07 22:02:23 -03001100 &rtl28xxu_mxl5005s_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001101 break;
1102 default:
Antti Palosaari9935eea2012-01-21 22:26:52 -03001103 fe = NULL;
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001104 dev_err(&d->intf->dev, "unknown tuner %d\n", dev->tuner);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001105 }
1106
1107 if (fe == NULL) {
1108 ret = -ENODEV;
1109 goto err;
1110 }
1111
1112 return 0;
1113err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001114 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001115 return ret;
1116}
1117
Antti Palosaariad3a7582012-12-08 23:27:49 -03001118static const struct fc0012_config rtl2832u_fc0012_config = {
1119 .i2c_address = 0x63, /* 0xc6 >> 1 */
1120 .xtal_freq = FC_XTAL_28_8_MHZ,
1121};
1122
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -03001123static const struct r820t_config rtl2832u_r820t_config = {
1124 .i2c_addr = 0x1a,
1125 .xtal = 28800000,
1126 .max_i2c_msg_len = 2,
1127 .rafael_chip = CHIP_R820T,
1128};
1129
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001130static const struct r820t_config rtl2832u_r828d_config = {
1131 .i2c_addr = 0x3a,
1132 .xtal = 16000000,
1133 .max_i2c_msg_len = 2,
1134 .rafael_chip = CHIP_R828D,
1135};
1136
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001137static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
1138{
1139 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -03001140 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001141 struct rtl28xxu_dev *dev = d_to_priv(d);
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001142 struct dvb_frontend *fe = NULL;
1143 struct i2c_board_info info;
1144 struct i2c_client *client;
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001145 struct v4l2_subdev *subdev = NULL;
Mauro Carvalho Chehabe181b1f2015-02-03 16:36:28 -02001146 struct platform_device *pdev;
1147 struct rtl2832_sdr_platform_data pdata;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001148
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001149 dev_dbg(&d->intf->dev, "\n");
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001150
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001151 memset(&info, 0, sizeof(struct i2c_board_info));
Mauro Carvalho Chehabe181b1f2015-02-03 16:36:28 -02001152 memset(&pdata, 0, sizeof(pdata));
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001153
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001154 switch (dev->tuner) {
Thomas Mair5cf66312012-05-18 14:47:41 -03001155 case TUNER_RTL2832_FC0012:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001156 fe = dvb_attach(fc0012_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001157 dev->demod_i2c_adapter, &rtl2832u_fc0012_config);
Thomas Mair5cf66312012-05-18 14:47:41 -03001158
1159 /* since fc0012 includs reading the signal strength delegate
1160 * that to the tuner driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -03001161 adap->fe[0]->ops.read_signal_strength =
1162 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001163 break;
Thomas Mair5cf66312012-05-18 14:47:41 -03001164 case TUNER_RTL2832_FC0013:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001165 fe = dvb_attach(fc0013_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001166 dev->demod_i2c_adapter, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -03001167
1168 /* fc0013 also supports signal strength reading */
Antti Palosaaric01a3592012-08-12 22:27:07 -03001169 adap->fe[0]->ops.read_signal_strength =
1170 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Antti Palosaari55cdb7d2014-02-03 23:07:21 -03001171 break;
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001172 case TUNER_RTL2832_E4000: {
1173 struct e4000_config e4000_config = {
1174 .fe = adap->fe[0],
1175 .clock = 28800000,
1176 };
1177
1178 strlcpy(info.type, "e4000", I2C_NAME_SIZE);
1179 info.addr = 0x64;
1180 info.platform_data = &e4000_config;
1181
1182 request_module(info.type);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001183 client = i2c_new_device(dev->demod_i2c_adapter, &info);
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001184 if (client == NULL || client->dev.driver == NULL)
1185 break;
1186
1187 if (!try_module_get(client->dev.driver->owner)) {
1188 i2c_unregister_device(client);
1189 break;
1190 }
1191
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001192 dev->i2c_client_tuner = client;
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001193 subdev = i2c_get_clientdata(client);
Antti Palosaari28fd31f2013-10-15 19:22:45 -03001194 }
Antti Palosaari542f6a52012-09-01 21:09:22 -03001195 break;
Antti Palosaari35fc0e02015-04-14 19:55:51 -03001196 case TUNER_RTL2832_FC2580: {
1197 struct fc2580_platform_data fc2580_pdata = {
1198 .dvb_frontend = adap->fe[0],
1199 };
1200 struct i2c_board_info board_info = {};
1201
1202 strlcpy(board_info.type, "fc2580", I2C_NAME_SIZE);
1203 board_info.addr = 0x56;
1204 board_info.platform_data = &fc2580_pdata;
1205 request_module("fc2580");
1206 client = i2c_new_device(dev->demod_i2c_adapter,
1207 &board_info);
1208 if (client == NULL || client->dev.driver == NULL)
1209 break;
1210 if (!try_module_get(client->dev.driver->owner)) {
1211 i2c_unregister_device(client);
1212 break;
1213 }
1214 dev->i2c_client_tuner = client;
Antti Palosaari9ea964f2015-05-03 21:48:47 -03001215 subdev = fc2580_pdata.get_v4l2_subdev(client);
Antti Palosaari35fc0e02015-04-14 19:55:51 -03001216 }
Antti Palosaari384df492012-09-08 22:07:25 -03001217 break;
Antti Palosaari88ffe552015-04-15 19:25:32 -03001218 case TUNER_RTL2832_TUA9001: {
1219 struct tua9001_platform_data tua9001_pdata = {
1220 .dvb_frontend = adap->fe[0],
1221 };
1222 struct i2c_board_info board_info = {};
1223
Antti Palosaari5be65722012-09-11 22:27:09 -03001224 /* enable GPIO1 and GPIO4 as output */
Antti Palosaari670ef052014-12-23 14:32:35 -03001225 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12);
Antti Palosaari4005c1a2012-09-17 15:43:57 -03001226 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -03001227 goto err;
1228
Antti Palosaari670ef052014-12-23 14:32:35 -03001229 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12);
Antti Palosaari4005c1a2012-09-17 15:43:57 -03001230 if (ret)
Antti Palosaari5be65722012-09-11 22:27:09 -03001231 goto err;
1232
Antti Palosaari88ffe552015-04-15 19:25:32 -03001233 strlcpy(board_info.type, "tua9001", I2C_NAME_SIZE);
1234 board_info.addr = 0x60;
1235 board_info.platform_data = &tua9001_pdata;
1236 request_module("tua9001");
1237 client = i2c_new_device(dev->demod_i2c_adapter, &board_info);
1238 if (client == NULL || client->dev.driver == NULL)
1239 break;
1240 if (!try_module_get(client->dev.driver->owner)) {
1241 i2c_unregister_device(client);
1242 break;
1243 }
1244 dev->i2c_client_tuner = client;
Antti Palosaari5be65722012-09-11 22:27:09 -03001245 break;
Antti Palosaari88ffe552015-04-15 19:25:32 -03001246 }
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -03001247 case TUNER_RTL2832_R820T:
Antti Palosaari164f3d22014-12-14 11:45:55 -03001248 fe = dvb_attach(r820t_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001249 dev->demod_i2c_adapter,
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -03001250 &rtl2832u_r820t_config);
Mauro Carvalho Chehab9e30edd2013-04-07 18:57:15 -03001251
1252 /* Use tuner to get the signal strength */
1253 adap->fe[0]->ops.read_signal_strength =
1254 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Mauro Carvalho Chehab6889ab22013-04-06 09:40:11 -03001255 break;
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001256 case TUNER_RTL2832_R828D:
Antti Palosaari80f189a2013-12-01 13:44:23 -03001257 fe = dvb_attach(r820t_attach, adap->fe[0],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001258 dev->demod_i2c_adapter,
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001259 &rtl2832u_r828d_config);
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001260 adap->fe[0]->ops.read_signal_strength =
1261 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Antti Palosaari80f189a2013-12-01 13:44:23 -03001262
1263 if (adap->fe[1]) {
1264 fe = dvb_attach(r820t_attach, adap->fe[1],
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001265 dev->demod_i2c_adapter,
Antti Palosaari80f189a2013-12-01 13:44:23 -03001266 &rtl2832u_r828d_config);
1267 adap->fe[1]->ops.read_signal_strength =
1268 adap->fe[1]->ops.tuner_ops.get_rf_strength;
1269 }
Antti Palosaari8b4cac12013-10-30 00:45:38 -03001270 break;
Olli Salonen699dcff2015-05-05 13:54:19 -03001271 case TUNER_RTL2832_SI2157: {
1272 struct si2157_config si2157_config = {
1273 .fe = adap->fe[0],
1274 .if_port = 0,
1275 .inversion = false,
1276 };
1277
1278 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1279 info.addr = 0x60;
1280 info.platform_data = &si2157_config;
1281 request_module(info.type);
1282 client = i2c_new_device(&d->i2c_adap, &info);
1283 if (client == NULL || client->dev.driver == NULL)
1284 break;
1285
1286 if (!try_module_get(client->dev.driver->owner)) {
1287 i2c_unregister_device(client);
1288 break;
1289 }
1290
1291 dev->i2c_client_tuner = client;
1292 subdev = i2c_get_clientdata(client);
1293
1294 /* copy tuner ops for 2nd FE as tuner is shared */
1295 if (adap->fe[1]) {
1296 adap->fe[1]->tuner_priv =
1297 adap->fe[0]->tuner_priv;
1298 memcpy(&adap->fe[1]->ops.tuner_ops,
1299 &adap->fe[0]->ops.tuner_ops,
1300 sizeof(struct dvb_tuner_ops));
1301 }
1302 }
1303 break;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001304 default:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001305 dev_err(&d->intf->dev, "unknown tuner %d\n", dev->tuner);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001306 }
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001307 if (fe == NULL && dev->i2c_client_tuner == NULL) {
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001308 ret = -ENODEV;
1309 goto err;
1310 }
1311
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001312 /* register SDR */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001313 switch (dev->tuner) {
Antti Palosaari9ea964f2015-05-03 21:48:47 -03001314 case TUNER_RTL2832_FC2580:
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001315 case TUNER_RTL2832_FC0012:
1316 case TUNER_RTL2832_FC0013:
1317 case TUNER_RTL2832_E4000:
1318 case TUNER_RTL2832_R820T:
1319 case TUNER_RTL2832_R828D:
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001320 pdata.clk = dev->rtl2832_platform_data.clk;
1321 pdata.tuner = dev->tuner;
1322 pdata.i2c_client = dev->i2c_client_demod;
1323 pdata.bulk_read = dev->rtl2832_platform_data.bulk_read;
1324 pdata.bulk_write = dev->rtl2832_platform_data.bulk_write;
1325 pdata.update_bits = dev->rtl2832_platform_data.update_bits;
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001326 pdata.dvb_frontend = adap->fe[0];
1327 pdata.dvb_usb_device = d;
1328 pdata.v4l2_subdev = subdev;
1329
1330 request_module("%s", "rtl2832_sdr");
Antti Palosaari6a53fa22014-12-17 08:16:10 -03001331 pdev = platform_device_register_data(&d->intf->dev,
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001332 "rtl2832_sdr",
1333 PLATFORM_DEVID_AUTO,
1334 &pdata, sizeof(pdata));
Wei Yongjun250d2ff2015-04-16 09:22:46 -03001335 if (IS_ERR(pdev) || pdev->dev.driver == NULL)
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001336 break;
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001337 dev->platform_device_sdr = pdev;
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001338 break;
1339 default:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001340 dev_dbg(&d->intf->dev, "no SDR for tuner=%d\n", dev->tuner);
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001341 }
1342
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001343 return 0;
1344err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001345 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001346 return ret;
1347}
1348
Antti Palosaaride701f02014-12-23 14:09:13 -03001349static int rtl28xxu_tuner_attach(struct dvb_usb_adapter *adap)
1350{
1351 struct rtl28xxu_dev *dev = adap_to_priv(adap);
1352
1353 if (dev->chip_id == CHIP_ID_RTL2831U)
1354 return rtl2831u_tuner_attach(adap);
1355 else
1356 return rtl2832u_tuner_attach(adap);
1357}
1358
1359static int rtl28xxu_tuner_detach(struct dvb_usb_adapter *adap)
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001360{
1361 struct dvb_usb_device *d = adap_to_d(adap);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001362 struct rtl28xxu_dev *dev = d_to_priv(d);
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001363 struct i2c_client *client;
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001364 struct platform_device *pdev;
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001365
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001366 dev_dbg(&d->intf->dev, "\n");
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001367
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001368 /* remove platform SDR */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001369 pdev = dev->platform_device_sdr;
Antti Palosaari6a53fa22014-12-17 08:16:10 -03001370 if (pdev)
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001371 platform_device_unregister(pdev);
Antti Palosaaria2f7f222014-12-16 10:50:54 -03001372
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001373 /* remove I2C tuner */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001374 client = dev->i2c_client_tuner;
Antti Palosaari8d44aee2014-12-02 11:23:49 -03001375 if (client) {
1376 module_put(client->dev.driver->owner);
1377 i2c_unregister_device(client);
1378 }
1379
1380 return 0;
1381}
1382
Antti Palosaaric01a3592012-08-12 22:27:07 -03001383static int rtl28xxu_init(struct dvb_usb_device *d)
1384{
1385 int ret;
1386 u8 val;
1387
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001388 dev_dbg(&d->intf->dev, "\n");
Antti Palosaaric01a3592012-08-12 22:27:07 -03001389
1390 /* init USB endpoints */
Antti Palosaari670ef052014-12-23 14:32:35 -03001391 ret = rtl28xxu_rd_reg(d, USB_SYSCTL_0, &val);
Antti Palosaaric01a3592012-08-12 22:27:07 -03001392 if (ret)
1393 goto err;
1394
1395 /* enable DMA and Full Packet Mode*/
1396 val |= 0x09;
Antti Palosaari670ef052014-12-23 14:32:35 -03001397 ret = rtl28xxu_wr_reg(d, USB_SYSCTL_0, val);
Antti Palosaaric01a3592012-08-12 22:27:07 -03001398 if (ret)
1399 goto err;
1400
1401 /* set EPA maximum packet size to 0x0200 */
Antti Palosaari670ef052014-12-23 14:32:35 -03001402 ret = rtl28xxu_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
Antti Palosaaric01a3592012-08-12 22:27:07 -03001403 if (ret)
1404 goto err;
1405
1406 /* change EPA FIFO length */
Antti Palosaari670ef052014-12-23 14:32:35 -03001407 ret = rtl28xxu_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
Antti Palosaaric01a3592012-08-12 22:27:07 -03001408 if (ret)
1409 goto err;
1410
1411 return ret;
1412err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001413 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaaric01a3592012-08-12 22:27:07 -03001414 return ret;
1415}
1416
Thomas Mair5cf66312012-05-18 14:47:41 -03001417static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001418{
1419 int ret;
Antti Palosaari8b036632012-09-01 09:54:43 -03001420 u8 gpio, sys0, epa_ctl[2];
Antti Palosaari831e0b72011-07-08 23:36:07 -03001421
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001422 dev_dbg(&d->intf->dev, "onoff=%d\n", onoff);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001423
1424 /* demod adc */
Antti Palosaari670ef052014-12-23 14:32:35 -03001425 ret = rtl28xxu_rd_reg(d, SYS_SYS0, &sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001426 if (ret)
1427 goto err;
1428
1429 /* tuner power, read GPIOs */
Antti Palosaari670ef052014-12-23 14:32:35 -03001430 ret = rtl28xxu_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001431 if (ret)
1432 goto err;
1433
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001434 dev_dbg(&d->intf->dev, "RD SYS0=%02x GPIO_OUT_VAL=%02x\n", sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001435
1436 if (onoff) {
1437 gpio |= 0x01; /* GPIO0 = 1 */
1438 gpio &= (~0x10); /* GPIO4 = 0 */
Antti Palosaari991452a2012-08-12 22:27:08 -03001439 gpio |= 0x04; /* GPIO2 = 1, LED on */
Antti Palosaari831e0b72011-07-08 23:36:07 -03001440 sys0 = sys0 & 0x0f;
1441 sys0 |= 0xe0;
Antti Palosaari8b036632012-09-01 09:54:43 -03001442 epa_ctl[0] = 0x00; /* clear stall */
1443 epa_ctl[1] = 0x00; /* clear reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -03001444 } else {
Antti Palosaari831e0b72011-07-08 23:36:07 -03001445 gpio &= (~0x01); /* GPIO0 = 0 */
1446 gpio |= 0x10; /* GPIO4 = 1 */
Antti Palosaari991452a2012-08-12 22:27:08 -03001447 gpio &= (~0x04); /* GPIO2 = 1, LED off */
Antti Palosaari831e0b72011-07-08 23:36:07 -03001448 sys0 = sys0 & (~0xc0);
Antti Palosaari8b036632012-09-01 09:54:43 -03001449 epa_ctl[0] = 0x10; /* set stall */
1450 epa_ctl[1] = 0x02; /* set reset */
Antti Palosaari831e0b72011-07-08 23:36:07 -03001451 }
1452
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001453 dev_dbg(&d->intf->dev, "WR SYS0=%02x GPIO_OUT_VAL=%02x\n", sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001454
1455 /* demod adc */
Antti Palosaari670ef052014-12-23 14:32:35 -03001456 ret = rtl28xxu_wr_reg(d, SYS_SYS0, sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001457 if (ret)
1458 goto err;
1459
1460 /* tuner power, write GPIOs */
Antti Palosaari670ef052014-12-23 14:32:35 -03001461 ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001462 if (ret)
1463 goto err;
1464
Antti Palosaari8b036632012-09-01 09:54:43 -03001465 /* streaming EP: stall & reset */
Antti Palosaari670ef052014-12-23 14:32:35 -03001466 ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, epa_ctl, 2);
Antti Palosaari8b036632012-09-01 09:54:43 -03001467 if (ret)
1468 goto err;
1469
1470 if (onoff)
1471 usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
1472
Antti Palosaari831e0b72011-07-08 23:36:07 -03001473 return ret;
1474err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001475 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001476 return ret;
1477}
1478
Thomas Mair5cf66312012-05-18 14:47:41 -03001479static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
1480{
1481 int ret;
Thomas Mair5cf66312012-05-18 14:47:41 -03001482
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001483 dev_dbg(&d->intf->dev, "onoff=%d\n", onoff);
Thomas Mair5cf66312012-05-18 14:47:41 -03001484
1485 if (onoff) {
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001486 /* GPIO3=1, GPIO4=0 */
Antti Palosaari670ef052014-12-23 14:32:35 -03001487 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x08, 0x18);
Thomas Mair5cf66312012-05-18 14:47:41 -03001488 if (ret)
1489 goto err;
1490
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001491 /* suspend? */
Antti Palosaari670ef052014-12-23 14:32:35 -03001492 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL1, 0x00, 0x10);
Thomas Mair5cf66312012-05-18 14:47:41 -03001493 if (ret)
1494 goto err;
1495
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001496 /* enable PLL */
Antti Palosaari670ef052014-12-23 14:32:35 -03001497 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x80, 0x80);
Thomas Mair5cf66312012-05-18 14:47:41 -03001498 if (ret)
1499 goto err;
1500
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001501 /* disable reset */
Antti Palosaari670ef052014-12-23 14:32:35 -03001502 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x20, 0x20);
Thomas Mair5cf66312012-05-18 14:47:41 -03001503 if (ret)
1504 goto err;
1505
Antti Palosaari8b036632012-09-01 09:54:43 -03001506 /* streaming EP: clear stall & reset */
Antti Palosaari670ef052014-12-23 14:32:35 -03001507 ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2);
Antti Palosaari8b036632012-09-01 09:54:43 -03001508 if (ret)
1509 goto err;
1510
1511 ret = usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x81));
1512 if (ret)
1513 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001514 } else {
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001515 /* GPIO4=1 */
Antti Palosaari670ef052014-12-23 14:32:35 -03001516 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x10, 0x10);
Thomas Mair5cf66312012-05-18 14:47:41 -03001517 if (ret)
1518 goto err;
1519
Antti Palosaari526ca8d2013-06-04 18:26:54 -03001520 /* disable PLL */
Antti Palosaari670ef052014-12-23 14:32:35 -03001521 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x80);
Thomas Mair5cf66312012-05-18 14:47:41 -03001522 if (ret)
1523 goto err;
1524
Antti Palosaari8b036632012-09-01 09:54:43 -03001525 /* streaming EP: set stall & reset */
Antti Palosaari670ef052014-12-23 14:32:35 -03001526 ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2);
Antti Palosaari8b036632012-09-01 09:54:43 -03001527 if (ret)
1528 goto err;
Thomas Mair5cf66312012-05-18 14:47:41 -03001529 }
1530
1531 return ret;
1532err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001533 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Thomas Mair5cf66312012-05-18 14:47:41 -03001534 return ret;
1535}
1536
Antti Palosaaride701f02014-12-23 14:09:13 -03001537static int rtl28xxu_power_ctrl(struct dvb_usb_device *d, int onoff)
1538{
1539 struct rtl28xxu_dev *dev = d_to_priv(d);
1540
1541 if (dev->chip_id == CHIP_ID_RTL2831U)
1542 return rtl2831u_power_ctrl(d, onoff);
1543 else
1544 return rtl2832u_power_ctrl(d, onoff);
1545}
1546
1547static int rtl28xxu_frontend_ctrl(struct dvb_frontend *fe, int onoff)
Antti Palosaari698f6262014-09-27 01:22:45 -03001548{
1549 struct dvb_usb_device *d = fe_to_d(fe);
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001550 struct rtl28xxu_dev *dev = fe_to_priv(fe);
1551 struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data;
Antti Palosaari698f6262014-09-27 01:22:45 -03001552 int ret;
1553 u8 val;
1554
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001555 dev_dbg(&d->intf->dev, "fe=%d onoff=%d\n", fe->id, onoff);
Antti Palosaari698f6262014-09-27 01:22:45 -03001556
Antti Palosaaride701f02014-12-23 14:09:13 -03001557 if (dev->chip_id == CHIP_ID_RTL2831U)
1558 return 0;
1559
Antti Palosaari698f6262014-09-27 01:22:45 -03001560 /* control internal demod ADC */
1561 if (fe->id == 0 && onoff)
1562 val = 0x48; /* enable ADC */
1563 else
1564 val = 0x00; /* disable ADC */
1565
Antti Palosaari670ef052014-12-23 14:32:35 -03001566 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, val, 0x48);
Antti Palosaari698f6262014-09-27 01:22:45 -03001567 if (ret)
1568 goto err;
1569
Antti Palosaari80f189a2013-12-01 13:44:23 -03001570 /* bypass slave demod TS through master demod */
1571 if (fe->id == 1 && onoff) {
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001572 ret = pdata->enable_slave_ts(dev->i2c_client_demod);
Antti Palosaari80f189a2013-12-01 13:44:23 -03001573 if (ret)
1574 goto err;
1575 }
1576
Antti Palosaari698f6262014-09-27 01:22:45 -03001577 return 0;
1578err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001579 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari698f6262014-09-27 01:22:45 -03001580 return ret;
1581}
1582
Antti Palosaari37b44a02013-01-04 15:21:26 -03001583#if IS_ENABLED(CONFIG_RC_CORE)
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001584static int rtl2831u_rc_query(struct dvb_usb_device *d)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001585{
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001586 int ret, i;
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001587 struct rtl28xxu_dev *dev = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -03001588 u8 buf[5];
1589 u32 rc_code;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001590 struct rtl28xxu_reg_val rc_nec_tab[] = {
1591 { 0x3033, 0x80 },
1592 { 0x3020, 0x43 },
1593 { 0x3021, 0x16 },
1594 { 0x3022, 0x16 },
1595 { 0x3023, 0x5a },
1596 { 0x3024, 0x2d },
1597 { 0x3025, 0x16 },
1598 { 0x3026, 0x01 },
1599 { 0x3028, 0xb0 },
1600 { 0x3029, 0x04 },
1601 { 0x302c, 0x88 },
1602 { 0x302e, 0x13 },
1603 { 0x3030, 0xdf },
1604 { 0x3031, 0x05 },
1605 };
1606
1607 /* init remote controller */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001608 if (!dev->rc_active) {
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001609 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Antti Palosaari670ef052014-12-23 14:32:35 -03001610 ret = rtl28xxu_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001611 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001612 if (ret)
1613 goto err;
1614 }
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001615 dev->rc_active = true;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001616 }
Antti Palosaari831e0b72011-07-08 23:36:07 -03001617
Antti Palosaari670ef052014-12-23 14:32:35 -03001618 ret = rtl28xxu_rd_regs(d, SYS_IRRC_RP, buf, 5);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001619 if (ret)
1620 goto err;
1621
1622 if (buf[4] & 0x01) {
1623 if (buf[2] == (u8) ~buf[3]) {
1624 if (buf[0] == (u8) ~buf[1]) {
1625 /* NEC standard (16 bit) */
David Härdeman120703f2014-04-03 20:31:30 -03001626 rc_code = RC_SCANCODE_NEC(buf[0], buf[2]);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001627 } else {
1628 /* NEC extended (24 bit) */
David Härdeman120703f2014-04-03 20:31:30 -03001629 rc_code = RC_SCANCODE_NECX(buf[0] << 8 | buf[1],
1630 buf[2]);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001631 }
1632 } else {
1633 /* NEC full (32 bit) */
David Härdeman120703f2014-04-03 20:31:30 -03001634 rc_code = RC_SCANCODE_NEC32(buf[0] << 24 | buf[1] << 16 |
1635 buf[2] << 8 | buf[3]);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001636 }
1637
David Härdeman120703f2014-04-03 20:31:30 -03001638 rc_keydown(d->rc_dev, RC_TYPE_NEC, rc_code, 0);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001639
Antti Palosaari670ef052014-12-23 14:32:35 -03001640 ret = rtl28xxu_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001641 if (ret)
1642 goto err;
1643
1644 /* repeated intentionally to avoid extra keypress */
Antti Palosaari670ef052014-12-23 14:32:35 -03001645 ret = rtl28xxu_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001646 if (ret)
1647 goto err;
1648 }
1649
1650 return ret;
1651err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001652 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001653 return ret;
1654}
1655
Antti Palosaaric01a3592012-08-12 22:27:07 -03001656static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
1657 struct dvb_usb_rc *rc)
1658{
1659 rc->map_name = RC_MAP_EMPTY;
David Härdemanc003ab12012-10-11 19:11:54 -03001660 rc->allowed_protos = RC_BIT_NEC;
Antti Palosaaric01a3592012-08-12 22:27:07 -03001661 rc->query = rtl2831u_rc_query;
1662 rc->interval = 400;
1663
1664 return 0;
1665}
1666
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001667static int rtl2832u_rc_query(struct dvb_usb_device *d)
1668{
Antti Palosaarif39fac32013-06-04 09:17:03 -03001669 int ret, i, len;
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001670 struct rtl28xxu_dev *dev = d->priv;
Antti Palosaarif39fac32013-06-04 09:17:03 -03001671 struct ir_raw_event ev;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001672 u8 buf[128];
Antti Palosaarif39fac32013-06-04 09:17:03 -03001673 static const struct rtl28xxu_reg_val_mask refresh_tab[] = {
1674 {IR_RX_IF, 0x03, 0xff},
1675 {IR_RX_BUF_CTRL, 0x80, 0xff},
1676 {IR_RX_CTRL, 0x80, 0xff},
1677 };
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001678
1679 /* init remote controller */
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001680 if (!dev->rc_active) {
Antti Palosaarif39fac32013-06-04 09:17:03 -03001681 static const struct rtl28xxu_reg_val_mask init_tab[] = {
1682 {SYS_DEMOD_CTL1, 0x00, 0x04},
1683 {SYS_DEMOD_CTL1, 0x00, 0x08},
1684 {USB_CTRL, 0x20, 0x20},
1685 {SYS_GPIO_DIR, 0x00, 0x08},
1686 {SYS_GPIO_OUT_EN, 0x08, 0x08},
1687 {SYS_GPIO_OUT_VAL, 0x08, 0x08},
1688 {IR_MAX_DURATION0, 0xd0, 0xff},
1689 {IR_MAX_DURATION1, 0x07, 0xff},
1690 {IR_IDLE_LEN0, 0xc0, 0xff},
1691 {IR_IDLE_LEN1, 0x00, 0xff},
1692 {IR_GLITCH_LEN, 0x03, 0xff},
1693 {IR_RX_CLK, 0x09, 0xff},
1694 {IR_RX_CFG, 0x1c, 0xff},
1695 {IR_MAX_H_TOL_LEN, 0x1e, 0xff},
1696 {IR_MAX_L_TOL_LEN, 0x1e, 0xff},
1697 {IR_RX_CTRL, 0x80, 0xff},
1698 };
1699
1700 for (i = 0; i < ARRAY_SIZE(init_tab); i++) {
Antti Palosaari670ef052014-12-23 14:32:35 -03001701 ret = rtl28xxu_wr_reg_mask(d, init_tab[i].reg,
Antti Palosaarif39fac32013-06-04 09:17:03 -03001702 init_tab[i].val, init_tab[i].mask);
Rodrigo Tartajo1e414132013-04-20 20:02:12 -03001703 if (ret)
1704 goto err;
1705 }
Antti Palosaarif39fac32013-06-04 09:17:03 -03001706
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001707 dev->rc_active = true;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001708 }
1709
Antti Palosaari670ef052014-12-23 14:32:35 -03001710 ret = rtl28xxu_rd_reg(d, IR_RX_IF, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001711 if (ret)
1712 goto err;
1713
1714 if (buf[0] != 0x83)
Antti Palosaarif39fac32013-06-04 09:17:03 -03001715 goto exit;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001716
Antti Palosaari670ef052014-12-23 14:32:35 -03001717 ret = rtl28xxu_rd_reg(d, IR_RX_BC, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001718 if (ret)
1719 goto err;
1720
1721 len = buf[0];
Antti Palosaarif39fac32013-06-04 09:17:03 -03001722
1723 /* read raw code from hw */
Antti Palosaari670ef052014-12-23 14:32:35 -03001724 ret = rtl28xxu_rd_regs(d, IR_RX_BUF, buf, len);
Antti Palosaarif39fac32013-06-04 09:17:03 -03001725 if (ret)
1726 goto err;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001727
Antti Palosaarif39fac32013-06-04 09:17:03 -03001728 /* let hw receive new code */
1729 for (i = 0; i < ARRAY_SIZE(refresh_tab); i++) {
Antti Palosaari670ef052014-12-23 14:32:35 -03001730 ret = rtl28xxu_wr_reg_mask(d, refresh_tab[i].reg,
Antti Palosaarif39fac32013-06-04 09:17:03 -03001731 refresh_tab[i].val, refresh_tab[i].mask);
Rodrigo Tartajo1e414132013-04-20 20:02:12 -03001732 if (ret)
1733 goto err;
1734 }
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001735
Antti Palosaarif39fac32013-06-04 09:17:03 -03001736 /* pass data to Kernel IR decoder */
1737 init_ir_raw_event(&ev);
1738
1739 for (i = 0; i < len; i++) {
1740 ev.pulse = buf[i] >> 7;
1741 ev.duration = 50800 * (buf[i] & 0x7f);
1742 ir_raw_event_store_with_filter(d->rc_dev, &ev);
1743 }
1744
1745 /* 'flush' ir_raw_event_store_with_filter() */
1746 ir_raw_event_set_idle(d->rc_dev, true);
1747 ir_raw_event_handle(d->rc_dev);
1748exit:
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001749 return ret;
1750err:
Antti Palosaari5ba4ca12014-12-21 11:25:57 -03001751 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001752 return ret;
1753}
1754
Antti Palosaaric01a3592012-08-12 22:27:07 -03001755static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1756 struct dvb_usb_rc *rc)
1757{
Antti Palosaari94b5fa62013-11-22 14:20:14 -03001758 /* disable IR interrupts in order to avoid SDR sample loss */
1759 if (rtl28xxu_disable_rc)
Antti Palosaari670ef052014-12-23 14:32:35 -03001760 return rtl28xxu_wr_reg(d, IR_RX_IE, 0x00);
Antti Palosaari94b5fa62013-11-22 14:20:14 -03001761
Antti Palosaarif39fac32013-06-04 09:17:03 -03001762 /* load empty to enable rc */
1763 if (!rc->map_name)
1764 rc->map_name = RC_MAP_EMPTY;
Rodrigo Tartajo1e414132013-04-20 20:02:12 -03001765 rc->allowed_protos = RC_BIT_ALL;
Antti Palosaarif39fac32013-06-04 09:17:03 -03001766 rc->driver_type = RC_DRIVER_IR_RAW;
Antti Palosaaric01a3592012-08-12 22:27:07 -03001767 rc->query = rtl2832u_rc_query;
Benjamin Larsson46cf7072015-03-15 19:57:48 -03001768 rc->interval = 200;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001769
Antti Palosaaric01a3592012-08-12 22:27:07 -03001770 return 0;
1771}
Antti Palosaaride701f02014-12-23 14:09:13 -03001772
1773static int rtl28xxu_get_rc_config(struct dvb_usb_device *d,
1774 struct dvb_usb_rc *rc)
1775{
1776 struct rtl28xxu_dev *dev = d_to_priv(d);
1777
1778 if (dev->chip_id == CHIP_ID_RTL2831U)
1779 return rtl2831u_get_rc_config(d, rc);
1780 else
1781 return rtl2832u_get_rc_config(d, rc);
1782}
Antti Palosaaricedda372012-12-09 20:06:00 -03001783#else
Antti Palosaaride701f02014-12-23 14:09:13 -03001784#define rtl28xxu_get_rc_config NULL
Antti Palosaaricedda372012-12-09 20:06:00 -03001785#endif
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001786
Antti Palosaaride701f02014-12-23 14:09:13 -03001787static int rtl28xxu_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
Antti Palosaarid9bd3fa2014-12-09 16:10:14 -03001788{
Antti Palosaaride701f02014-12-23 14:09:13 -03001789 struct rtl28xxu_dev *dev = adap_to_priv(adap);
Antti Palosaarid9bd3fa2014-12-09 16:10:14 -03001790
Antti Palosaaride701f02014-12-23 14:09:13 -03001791 if (dev->chip_id == CHIP_ID_RTL2831U) {
1792 struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data;
1793
1794 return pdata->pid_filter_ctrl(adap->fe[0], onoff);
1795 } else {
1796 struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data;
1797
1798 return pdata->pid_filter_ctrl(adap->fe[0], onoff);
1799 }
Antti Palosaarid9bd3fa2014-12-09 16:10:14 -03001800}
1801
Antti Palosaaride701f02014-12-23 14:09:13 -03001802static int rtl28xxu_pid_filter(struct dvb_usb_adapter *adap, int index,
1803 u16 pid, int onoff)
Antti Palosaarie20b0cf2014-12-14 14:10:47 -03001804{
Antti Palosaaride701f02014-12-23 14:09:13 -03001805 struct rtl28xxu_dev *dev = adap_to_priv(adap);
Antti Palosaarie20b0cf2014-12-14 14:10:47 -03001806
Antti Palosaaride701f02014-12-23 14:09:13 -03001807 if (dev->chip_id == CHIP_ID_RTL2831U) {
1808 struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data;
Antti Palosaarie20b0cf2014-12-14 14:10:47 -03001809
Antti Palosaaride701f02014-12-23 14:09:13 -03001810 return pdata->pid_filter(adap->fe[0], index, pid, onoff);
1811 } else {
1812 struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data;
Antti Palosaarid9bd3fa2014-12-09 16:10:14 -03001813
Antti Palosaaride701f02014-12-23 14:09:13 -03001814 return pdata->pid_filter(adap->fe[0], index, pid, onoff);
1815 }
Antti Palosaarie20b0cf2014-12-14 14:10:47 -03001816}
1817
Antti Palosaari723abfd2014-12-23 14:21:10 -03001818static const struct dvb_usb_device_properties rtl28xxu_props = {
Antti Palosaaric01a3592012-08-12 22:27:07 -03001819 .driver_name = KBUILD_MODNAME,
1820 .owner = THIS_MODULE,
1821 .adapter_nr = adapter_nr,
Antti Palosaari9a02e8f2014-12-18 08:05:23 -03001822 .size_of_priv = sizeof(struct rtl28xxu_dev),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001823
Antti Palosaarid0f232e2014-12-23 13:14:36 -03001824 .identify_state = rtl28xxu_identify_state,
Antti Palosaaride701f02014-12-23 14:09:13 -03001825 .power_ctrl = rtl28xxu_power_ctrl,
1826 .frontend_ctrl = rtl28xxu_frontend_ctrl,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001827 .i2c_algo = &rtl28xxu_i2c_algo,
Antti Palosaaride701f02014-12-23 14:09:13 -03001828 .read_config = rtl28xxu_read_config,
1829 .frontend_attach = rtl28xxu_frontend_attach,
1830 .frontend_detach = rtl28xxu_frontend_detach,
1831 .tuner_attach = rtl28xxu_tuner_attach,
1832 .tuner_detach = rtl28xxu_tuner_detach,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001833 .init = rtl28xxu_init,
Antti Palosaaride701f02014-12-23 14:09:13 -03001834 .get_rc_config = rtl28xxu_get_rc_config,
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001835
Antti Palosaaric01a3592012-08-12 22:27:07 -03001836 .num_adapters = 1,
1837 .adapter = {
1838 {
Antti Palosaarie20b0cf2014-12-14 14:10:47 -03001839 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1840 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1841
1842 .pid_filter_count = 32,
Antti Palosaaride701f02014-12-23 14:09:13 -03001843 .pid_filter_ctrl = rtl28xxu_pid_filter_ctrl,
1844 .pid_filter = rtl28xxu_pid_filter,
Antti Palosaarie20b0cf2014-12-14 14:10:47 -03001845
Antti Palosaaric01a3592012-08-12 22:27:07 -03001846 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001847 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001848 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001849};
1850
Antti Palosaaric01a3592012-08-12 22:27:07 -03001851static const struct usb_device_id rtl28xxu_id_table[] = {
Jan Vcelak60aa4c62014-02-26 15:33:40 -03001852 /* RTL2831U devices: */
Antti Palosaaric01a3592012-08-12 22:27:07 -03001853 { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001854 &rtl28xxu_props, "Realtek RTL2831U reference design", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001855 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001856 &rtl28xxu_props, "Freecom USB2.0 DVB-T", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001857 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001858 &rtl28xxu_props, "Freecom USB2.0 DVB-T", NULL) },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001859
Jan Vcelak60aa4c62014-02-26 15:33:40 -03001860 /* RTL2832U devices: */
Antti Palosaari254ee2e2012-09-18 10:27:05 -03001861 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001862 &rtl28xxu_props, "Realtek RTL2832U reference design", NULL) },
Antti Palosaari254ee2e2012-09-18 10:27:05 -03001863 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001864 &rtl28xxu_props, "Realtek RTL2832U reference design", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001865 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001866 &rtl28xxu_props, "TerraTec Cinergy T Stick Black", RC_MAP_TERRATEC_SLIM) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001867 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001868 &rtl28xxu_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001869 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001870 &rtl28xxu_props, "TerraTec NOXON DAB Stick", NULL) },
Juergen Locke9de0512012-11-13 14:09:28 -03001871 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV2,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001872 &rtl28xxu_props, "TerraTec NOXON DAB Stick (rev 2)", NULL) },
Till Dörgesa24bc322014-02-11 17:27:57 -03001873 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV3,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001874 &rtl28xxu_props, "TerraTec NOXON DAB Stick (rev 3)", NULL) },
Philipp Dreimann6d608052012-09-02 19:30:54 -03001875 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001876 &rtl28xxu_props, "Trekstor DVB-T Stick Terres 2.0", NULL) },
Antti Palosaaric2d246d12012-09-08 22:07:26 -03001877 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001878 &rtl28xxu_props, "Dexatek DK DVB-T Dongle", NULL) },
Antti Palosaari3d8866d2012-09-20 18:34:50 -03001879 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6680,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001880 &rtl28xxu_props, "DigitalNow Quad DVB-T Receiver", NULL) },
Robert Backhausd22d32e2013-12-13 09:59:10 -03001881 { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_MINID,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001882 &rtl28xxu_props, "Leadtek Winfast DTV Dongle Mini D", NULL) },
Christian Dale09f50122015-03-09 02:19:01 -03001883 { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS_PLUS,
1884 &rtl28xxu_props, "Leadtek WinFast DTV2000DS Plus", RC_MAP_LEADTEK_Y04G0051) },
Antti Palosaaria4f64402012-09-29 15:28:56 -03001885 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d3,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001886 &rtl28xxu_props, "TerraTec Cinergy T Stick RC (Rev. 3)", NULL) },
Antti Palosaari08e57272012-11-06 16:03:35 -03001887 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1102,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001888 &rtl28xxu_props, "Dexatek DK mini DVB-T Dongle", NULL) },
Andrew Karpow86163ad2012-11-06 20:01:16 -03001889 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d7,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001890 &rtl28xxu_props, "TerraTec Cinergy T Stick+", NULL) },
Antti Palosaari3971e792012-12-16 11:47:07 -03001891 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd3a8,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001892 &rtl28xxu_props, "ASUS My Cinema-U3100Mini Plus V2", NULL) },
Alexander Inyukhin78a5e702013-01-04 18:19:02 -03001893 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd393,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001894 &rtl28xxu_props, "GIGABYTE U7300", NULL) },
Eddi De Pieri09f94082013-01-14 18:21:32 -03001895 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1104,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001896 &rtl28xxu_props, "MSI DIGIVOX Micro HD", NULL) },
Alistair Buxtonb9e2aff2013-02-12 21:58:47 -03001897 { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001898 &rtl28xxu_props, "Compro VideoMate U620F", NULL) },
Graham Eccleston702c2872015-08-09 11:38:07 -03001899 { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0650,
1900 &rtl28xxu_props, "Compro VideoMate U650F", NULL) },
Fabrizio Gazzatoe6a60d72013-02-15 18:54:54 -03001901 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001902 &rtl28xxu_props, "MaxMedia HU394-T", NULL) },
Miroslav Ĺ ustek6c5a4062013-05-14 19:42:11 -03001903 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001904 &rtl28xxu_props, "Leadtek WinFast DTV Dongle mini", NULL) },
Alessandro Micelic6be7522013-06-04 16:10:34 -03001905 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001906 &rtl28xxu_props, "Crypto ReDi PC 50 A", NULL) },
Jan Vcelakac298cc2014-02-26 15:33:39 -03001907 { DVB_USB_DEVICE(USB_VID_KYE, 0x707f,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001908 &rtl28xxu_props, "Genius TVGo DVB-T03", NULL) },
Brian Healy9ca24ae2014-05-04 18:43:39 -03001909 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd395,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001910 &rtl28xxu_props, "Peak DVB-T USB", NULL) },
Alessandro Micelif27f5b02014-05-04 07:37:15 -03001911 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20_RTL2832U,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001912 &rtl28xxu_props, "Sveon STV20", NULL) },
Sebastian89c5ff02014-06-12 03:22:45 -03001913 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV21,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001914 &rtl28xxu_props, "Sveon STV21", NULL) },
Alessandro Miceli74a86272014-05-04 07:50:31 -03001915 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV27,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001916 &rtl28xxu_props, "Sveon STV27", NULL) },
Dimitris Lampridis882302c2015-02-14 11:11:34 -03001917 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TURBOX_DTT_2000,
1918 &rtl28xxu_props, "TURBO-X Pure TV Tuner DTT-2000", NULL) },
Antti Palosaari8fdd33b2013-10-30 02:33:42 -03001919
Jan Vcelak60aa4c62014-02-26 15:33:40 -03001920 /* RTL2832P devices: */
Antti Palosaari8fdd33b2013-10-30 02:33:42 -03001921 { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131,
Antti Palosaari723abfd2014-12-23 14:21:10 -03001922 &rtl28xxu_props, "Astrometa DVB-T2", NULL) },
Olli Salonen699dcff2015-05-05 13:54:19 -03001923 { DVB_USB_DEVICE(0x5654, 0xca42,
1924 &rtl28xxu_props, "GoTView MasterHD 3", NULL) },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001925 { }
1926};
1927MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001928
Antti Palosaaric01a3592012-08-12 22:27:07 -03001929static struct usb_driver rtl28xxu_usb_driver = {
1930 .name = KBUILD_MODNAME,
1931 .id_table = rtl28xxu_id_table,
1932 .probe = dvb_usbv2_probe,
1933 .disconnect = dvb_usbv2_disconnect,
1934 .suspend = dvb_usbv2_suspend,
1935 .resume = dvb_usbv2_resume,
Antti Palosaari78fa5902012-08-14 22:21:09 -03001936 .reset_resume = dvb_usbv2_reset_resume,
Antti Palosaaric01a3592012-08-12 22:27:07 -03001937 .no_dynamic_id = 1,
1938 .soft_unbind = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001939};
1940
Antti Palosaaric01a3592012-08-12 22:27:07 -03001941module_usb_driver(rtl28xxu_usb_driver);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001942
1943MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
1944MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
Thomas Mair5cf66312012-05-18 14:47:41 -03001945MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>");
Antti Palosaari831e0b72011-07-08 23:36:07 -03001946MODULE_LICENSE("GPL");