blob: a2d1e5b9d9d4d5f7e946354ca68d9f8d78c6e580 [file] [log] [blame]
Antti Palosaari831e0b72011-07-08 23:36:07 -03001/*
2 * Realtek RTL28xxU DVB USB driver
3 *
4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
5 * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
Thomas Mair5cf66312012-05-18 14:47:41 -03006 * Copyright (C) 2012 Thomas Mair <thomas.mair86@googlemail.com>
Antti Palosaari831e0b72011-07-08 23:36:07 -03007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#include "rtl28xxu.h"
24
25#include "rtl2830.h"
Thomas Mair5cf66312012-05-18 14:47:41 -030026#include "rtl2832.h"
Antti Palosaari831e0b72011-07-08 23:36:07 -030027
28#include "qt1010.h"
29#include "mt2060.h"
30#include "mxl5005s.h"
Thomas Mair5cf66312012-05-18 14:47:41 -030031#include "fc0012.h"
32#include "fc0013.h"
Antti Palosaari831e0b72011-07-08 23:36:07 -030033
Antti Palosaari831e0b72011-07-08 23:36:07 -030034DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
35
36static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
37{
38 int ret;
39 unsigned int pipe;
40 u8 requesttype;
41 u8 *buf;
42
43 buf = kmalloc(req->size, GFP_KERNEL);
44 if (!buf) {
45 ret = -ENOMEM;
46 goto err;
47 }
48
49 if (req->index & CMD_WR_FLAG) {
50 /* write */
51 memcpy(buf, req->data, req->size);
52 requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT);
53 pipe = usb_sndctrlpipe(d->udev, 0);
54 } else {
55 /* read */
56 requesttype = (USB_TYPE_VENDOR | USB_DIR_IN);
57 pipe = usb_rcvctrlpipe(d->udev, 0);
58 }
59
60 ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value,
Antti Palosaari9935eea2012-01-21 22:26:52 -030061 req->index, buf, req->size, 1000);
62 if (ret > 0)
63 ret = 0;
Antti Palosaari831e0b72011-07-08 23:36:07 -030064
Antti Palosaaric01a3592012-08-12 22:27:07 -030065 deb_dump(0, requesttype, req->value, req->index, buf, req->size);
Antti Palosaari831e0b72011-07-08 23:36:07 -030066
67 /* read request, copy returned data to return buf */
68 if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
69 memcpy(req->data, buf, req->size);
70
71 kfree(buf);
Antti Palosaari831e0b72011-07-08 23:36:07 -030072
Antti Palosaari9935eea2012-01-21 22:26:52 -030073 if (ret)
74 goto err;
75
76 return ret;
Antti Palosaari831e0b72011-07-08 23:36:07 -030077err:
Antti Palosaaric01a3592012-08-12 22:27:07 -030078 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -030079 return ret;
80}
81
Thomas Mair40a2d3c2012-05-18 14:47:42 -030082static int rtl28xx_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
Antti Palosaari831e0b72011-07-08 23:36:07 -030083{
84 struct rtl28xxu_req req;
85
86 if (reg < 0x3000)
87 req.index = CMD_USB_WR;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -030088 else if (reg < 0x4000)
Antti Palosaari831e0b72011-07-08 23:36:07 -030089 req.index = CMD_SYS_WR;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -030090 else
91 req.index = CMD_IR_WR;
Antti Palosaari831e0b72011-07-08 23:36:07 -030092
93 req.value = reg;
94 req.size = len;
95 req.data = val;
96
97 return rtl28xxu_ctrl_msg(d, &req);
98}
99
100static int rtl2831_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
101{
102 struct rtl28xxu_req req;
103
104 if (reg < 0x3000)
105 req.index = CMD_USB_RD;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300106 else if (reg < 0x4000)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300107 req.index = CMD_SYS_RD;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300108 else
109 req.index = CMD_IR_RD;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300110
111 req.value = reg;
112 req.size = len;
113 req.data = val;
114
115 return rtl28xxu_ctrl_msg(d, &req);
116}
117
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300118static int rtl28xx_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300119{
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300120 return rtl28xx_wr_regs(d, reg, &val, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300121}
122
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300123static int rtl28xx_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300124{
125 return rtl2831_rd_regs(d, reg, val, 1);
126}
127
128/* I2C */
129static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
130 int num)
131{
132 int ret;
133 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300134 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300135 struct rtl28xxu_req req;
136
137 /*
138 * It is not known which are real I2C bus xfer limits, but testing
139 * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes.
Antti Palosaari34ec2932011-08-04 20:21:16 -0300140 * TODO: find out RTL2832U lens
141 */
142
143 /*
144 * I2C adapter logic looks rather complicated due to fact it handles
145 * three different access methods. Those methods are;
146 * 1) integrated demod access
147 * 2) old I2C access
148 * 3) new I2C access
149 *
150 * Used method is selected in order 1, 2, 3. Method 3 can handle all
151 * requests but there is two reasons why not use it always;
152 * 1) It is most expensive, usually two USB messages are needed
153 * 2) At least RTL2831U does not support it
154 *
155 * Method 3 is needed in case of I2C write+read (typical register read)
156 * where write is more than one byte.
Antti Palosaari831e0b72011-07-08 23:36:07 -0300157 */
158
159 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
160 return -EAGAIN;
161
162 if (num == 2 && !(msg[0].flags & I2C_M_RD) &&
163 (msg[1].flags & I2C_M_RD)) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300164 if (msg[0].len > 24 || msg[1].len > 24) {
165 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300166 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300167 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300168 } else if (msg[0].addr == 0x10) {
169 /* method 1 - integrated demod */
170 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
171 req.index = CMD_DEMOD_RD | priv->page;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300172 req.size = msg[1].len;
173 req.data = &msg[1].buf[0];
174 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300175 } else if (msg[0].len < 2) {
176 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300177 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
178 req.index = CMD_I2C_RD;
179 req.size = msg[1].len;
180 req.data = &msg[1].buf[0];
181 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300182 } else {
183 /* method 3 - new I2C */
184 req.value = (msg[0].addr << 1);
185 req.index = CMD_I2C_DA_WR;
186 req.size = msg[0].len;
187 req.data = msg[0].buf;
188 ret = rtl28xxu_ctrl_msg(d, &req);
189 if (ret)
Antti Palosaari9935eea2012-01-21 22:26:52 -0300190 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300191
192 req.value = (msg[0].addr << 1);
193 req.index = CMD_I2C_DA_RD;
194 req.size = msg[1].len;
195 req.data = msg[1].buf;
196 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300197 }
198 } else if (num == 1 && !(msg[0].flags & I2C_M_RD)) {
199 if (msg[0].len > 22) {
Antti Palosaari34ec2932011-08-04 20:21:16 -0300200 /* TODO: check msg[0].len max */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300201 ret = -EOPNOTSUPP;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300202 goto err_mutex_unlock;
Antti Palosaari34ec2932011-08-04 20:21:16 -0300203 } else if (msg[0].addr == 0x10) {
204 /* method 1 - integrated demod */
205 if (msg[0].buf[0] == 0x00) {
206 /* save demod page for later demod access */
207 priv->page = msg[0].buf[1];
208 ret = 0;
209 } else {
210 req.value = (msg[0].buf[0] << 8) |
211 (msg[0].addr << 1);
212 req.index = CMD_DEMOD_WR | priv->page;
213 req.size = msg[0].len-1;
214 req.data = &msg[0].buf[1];
215 ret = rtl28xxu_ctrl_msg(d, &req);
216 }
217 } else if (msg[0].len < 23) {
218 /* method 2 - old I2C */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300219 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
220 req.index = CMD_I2C_WR;
221 req.size = msg[0].len-1;
222 req.data = &msg[0].buf[1];
223 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari34ec2932011-08-04 20:21:16 -0300224 } else {
225 /* method 3 - new I2C */
226 req.value = (msg[0].addr << 1);
227 req.index = CMD_I2C_DA_WR;
228 req.size = msg[0].len;
229 req.data = msg[0].buf;
230 ret = rtl28xxu_ctrl_msg(d, &req);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300231 }
232 } else {
233 ret = -EINVAL;
234 }
235
Antti Palosaari9935eea2012-01-21 22:26:52 -0300236err_mutex_unlock:
Antti Palosaari831e0b72011-07-08 23:36:07 -0300237 mutex_unlock(&d->i2c_mutex);
238
239 return ret ? ret : num;
240}
241
242static u32 rtl28xxu_i2c_func(struct i2c_adapter *adapter)
243{
244 return I2C_FUNC_I2C;
245}
246
247static struct i2c_algorithm rtl28xxu_i2c_algo = {
248 .master_xfer = rtl28xxu_i2c_xfer,
249 .functionality = rtl28xxu_i2c_func,
250};
251
252static struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = {
253 .i2c_addr = 0x10, /* 0x20 */
254 .xtal = 28800000,
255 .ts_mode = 0,
256 .spec_inv = 1,
257 .if_dvbt = 36150000,
258 .vtop = 0x20,
259 .krf = 0x04,
260 .agc_targ_val = 0x2d,
261
262};
263
264static struct rtl2830_config rtl28xxu_rtl2830_qt1010_config = {
265 .i2c_addr = 0x10, /* 0x20 */
266 .xtal = 28800000,
267 .ts_mode = 0,
268 .spec_inv = 1,
269 .if_dvbt = 36125000,
270 .vtop = 0x20,
271 .krf = 0x04,
272 .agc_targ_val = 0x2d,
273};
274
275static struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = {
276 .i2c_addr = 0x10, /* 0x20 */
277 .xtal = 28800000,
278 .ts_mode = 0,
279 .spec_inv = 0,
280 .if_dvbt = 4570000,
281 .vtop = 0x3f,
282 .krf = 0x04,
283 .agc_targ_val = 0x3e,
284};
285
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300286static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300287{
288 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300289 struct dvb_usb_device *d = adap_to_d(adap);
290 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300291 u8 buf[1];
292 struct rtl2830_config *rtl2830_config;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300293 /* open RTL2831U/RTL2830 I2C gate */
Antti Palosaari9935eea2012-01-21 22:26:52 -0300294 struct rtl28xxu_req req_gate = { 0x0120, 0x0011, 0x0001, "\x08" };
Antti Palosaari831e0b72011-07-08 23:36:07 -0300295 /* for MT2060 tuner probe */
Antti Palosaari9935eea2012-01-21 22:26:52 -0300296 struct rtl28xxu_req req_mt2060 = { 0x00c0, CMD_I2C_RD, 1, buf };
Antti Palosaari831e0b72011-07-08 23:36:07 -0300297 /* for QT1010 tuner probe */
Antti Palosaari9935eea2012-01-21 22:26:52 -0300298 struct rtl28xxu_req req_qt1010 = { 0x0fc4, CMD_I2C_RD, 1, buf };
Antti Palosaari831e0b72011-07-08 23:36:07 -0300299
Antti Palosaaric01a3592012-08-12 22:27:07 -0300300 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300301
302 /*
303 * RTL2831U GPIOs
304 * =========================================================
305 * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?)
306 * GPIO2 | LED | 0 off | 1 on |
307 * GPIO4 | tuner#1 | 0 on | 1 off | MT2060
308 */
309
310 /* GPIO direction */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300311 ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, 0x0a);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300312 if (ret)
313 goto err;
314
315 /* enable as output GPIO0, GPIO2, GPIO4 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300316 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, 0x15);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300317 if (ret)
318 goto err;
319
320 /*
321 * Probe used tuner. We need to know used tuner before demod attach
322 * since there is some demod params needed to set according to tuner.
323 */
324
Antti Palosaariccb5cf92012-05-18 16:07:46 -0300325 /* demod needs some time to wake up */
326 msleep(20);
327
Antti Palosaari831e0b72011-07-08 23:36:07 -0300328 /* open demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300329 ret = rtl28xxu_ctrl_msg(d, &req_gate);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300330 if (ret)
331 goto err;
332
333 /* check QT1010 ID(?) register; reg=0f val=2c */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300334 ret = rtl28xxu_ctrl_msg(d, &req_qt1010);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300335 if (ret == 0 && buf[0] == 0x2c) {
336 priv->tuner = TUNER_RTL2830_QT1010;
337 rtl2830_config = &rtl28xxu_rtl2830_qt1010_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300338 dev_dbg(&d->udev->dev, "%s: QT1010\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300339 goto found;
340 } else {
Antti Palosaaric01a3592012-08-12 22:27:07 -0300341 dev_dbg(&d->udev->dev, "%s: QT1010 probe failed=%d - %02x\n",
342 __func__, ret, buf[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300343 }
344
345 /* open demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300346 ret = rtl28xxu_ctrl_msg(d, &req_gate);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300347 if (ret)
348 goto err;
349
350 /* check MT2060 ID register; reg=00 val=63 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300351 ret = rtl28xxu_ctrl_msg(d, &req_mt2060);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300352 if (ret == 0 && buf[0] == 0x63) {
353 priv->tuner = TUNER_RTL2830_MT2060;
354 rtl2830_config = &rtl28xxu_rtl2830_mt2060_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300355 dev_dbg(&d->udev->dev, "%s: MT2060\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300356 goto found;
357 } else {
Antti Palosaaric01a3592012-08-12 22:27:07 -0300358 dev_dbg(&d->udev->dev, "%s: MT2060 probe failed=%d - %02x\n",
359 __func__, ret, buf[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300360 }
361
362 /* assume MXL5005S */
Antti Palosaarie9320ec2011-08-03 04:35:30 -0300363 ret = 0;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300364 priv->tuner = TUNER_RTL2830_MXL5005S;
365 rtl2830_config = &rtl28xxu_rtl2830_mxl5005s_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300366 dev_dbg(&d->udev->dev, "%s: MXL5005S\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300367 goto found;
368
369found:
370 /* attach demodulator */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300371 adap->fe[0] = dvb_attach(rtl2830_attach, rtl2830_config,
372 &d->i2c_adap);
373 if (adap->fe[0] == NULL) {
Antti Palosaari831e0b72011-07-08 23:36:07 -0300374 ret = -ENODEV;
375 goto err;
376 }
377
378 return ret;
379err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300380 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300381 return ret;
382}
383
Thomas Mair5cf66312012-05-18 14:47:41 -0300384static struct rtl2832_config rtl28xxu_rtl2832_fc0012_config = {
385 .i2c_addr = 0x10, /* 0x20 */
386 .xtal = 28800000,
387 .if_dvbt = 0,
388 .tuner = TUNER_RTL2832_FC0012
389};
390
391static struct rtl2832_config rtl28xxu_rtl2832_fc0013_config = {
392 .i2c_addr = 0x10, /* 0x20 */
393 .xtal = 28800000,
394 .if_dvbt = 0,
395 .tuner = TUNER_RTL2832_FC0013
396};
397
398static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
399 int cmd, int arg)
400{
401 int ret;
402 u8 val;
403
Antti Palosaaric01a3592012-08-12 22:27:07 -0300404 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg);
405
Thomas Mair5cf66312012-05-18 14:47:41 -0300406 switch (cmd) {
407 case FC_FE_CALLBACK_VHF_ENABLE:
408 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300409 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300410 if (ret)
411 goto err;
412
413 if (arg)
414 val &= 0xbf; /* set GPIO6 low */
415 else
416 val |= 0x40; /* set GPIO6 high */
417
418
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300419 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300420 if (ret)
421 goto err;
422 break;
423 default:
424 ret = -EINVAL;
425 goto err;
426 }
427 return 0;
428
429err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300430 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -0300431 return ret;
432}
433
434
435static int rtl2832u_fc0013_tuner_callback(struct dvb_usb_device *d,
436 int cmd, int arg)
437{
438 /* TODO implement*/
439 return 0;
440}
441
442static int rtl2832u_tuner_callback(struct dvb_usb_device *d, int cmd, int arg)
443{
444 struct rtl28xxu_priv *priv = d->priv;
445
446 switch (priv->tuner) {
447 case TUNER_RTL2832_FC0012:
448 return rtl2832u_fc0012_tuner_callback(d, cmd, arg);
449
450 case TUNER_RTL2832_FC0013:
451 return rtl2832u_fc0013_tuner_callback(d, cmd, arg);
452 default:
453 break;
454 }
455
456 return -ENODEV;
457}
458
459static int rtl2832u_frontend_callback(void *adapter_priv, int component,
460 int cmd, int arg)
461{
462 struct i2c_adapter *adap = adapter_priv;
463 struct dvb_usb_device *d = i2c_get_adapdata(adap);
464
465 switch (component) {
466 case DVB_FRONTEND_COMPONENT_TUNER:
467 return rtl2832u_tuner_callback(d, cmd, arg);
468 default:
469 break;
470 }
471
472 return -EINVAL;
473}
474
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300475static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
476{
477 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300478 struct dvb_usb_device *d = adap_to_d(adap);
479 struct rtl28xxu_priv *priv = d_to_priv(d);
Thomas Mair5cf66312012-05-18 14:47:41 -0300480 struct rtl2832_config *rtl2832_config;
Thomas Mair5cf66312012-05-18 14:47:41 -0300481 u8 buf[2], val;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300482 /* open RTL2832U/RTL2832 I2C gate */
483 struct rtl28xxu_req req_gate_open = {0x0120, 0x0011, 0x0001, "\x18"};
484 /* close RTL2832U/RTL2832 I2C gate */
485 struct rtl28xxu_req req_gate_close = {0x0120, 0x0011, 0x0001, "\x10"};
Thomas Mair5cf66312012-05-18 14:47:41 -0300486 /* for FC0012 tuner probe */
487 struct rtl28xxu_req req_fc0012 = {0x00c6, CMD_I2C_RD, 1, buf};
488 /* for FC0013 tuner probe */
489 struct rtl28xxu_req req_fc0013 = {0x00c6, CMD_I2C_RD, 1, buf};
490 /* for MT2266 tuner probe */
491 struct rtl28xxu_req req_mt2266 = {0x00c0, CMD_I2C_RD, 1, buf};
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300492 /* for FC2580 tuner probe */
493 struct rtl28xxu_req req_fc2580 = {0x01ac, CMD_I2C_RD, 1, buf};
Thomas Mair5cf66312012-05-18 14:47:41 -0300494 /* for MT2063 tuner probe */
495 struct rtl28xxu_req req_mt2063 = {0x00c0, CMD_I2C_RD, 1, buf};
496 /* for MAX3543 tuner probe */
497 struct rtl28xxu_req req_max3543 = {0x00c0, CMD_I2C_RD, 1, buf};
498 /* for TUA9001 tuner probe */
499 struct rtl28xxu_req req_tua9001 = {0x7ec0, CMD_I2C_RD, 2, buf};
500 /* for MXL5007T tuner probe */
501 struct rtl28xxu_req req_mxl5007t = {0xd9c0, CMD_I2C_RD, 1, buf};
502 /* for E4000 tuner probe */
503 struct rtl28xxu_req req_e4000 = {0x02c8, CMD_I2C_RD, 1, buf};
504 /* for TDA18272 tuner probe */
505 struct rtl28xxu_req req_tda18272 = {0x00c0, CMD_I2C_RD, 2, buf};
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300506
Antti Palosaaric01a3592012-08-12 22:27:07 -0300507 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300508
Antti Palosaaric01a3592012-08-12 22:27:07 -0300509 ret = rtl28xx_rd_reg(d, SYS_GPIO_DIR, &val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300510 if (ret)
511 goto err;
512
Thomas Mair5cf66312012-05-18 14:47:41 -0300513 val &= 0xbf;
514
Antti Palosaaric01a3592012-08-12 22:27:07 -0300515 ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300516 if (ret)
517 goto err;
518
Thomas Mair5cf66312012-05-18 14:47:41 -0300519 /* enable as output GPIO3 and GPIO6*/
Antti Palosaaric01a3592012-08-12 22:27:07 -0300520 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_EN, &val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300521 if (ret)
522 goto err;
523
Thomas Mair5cf66312012-05-18 14:47:41 -0300524 val |= 0x48;
525
Antti Palosaaric01a3592012-08-12 22:27:07 -0300526 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300527 if (ret)
528 goto err;
529
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300530 /*
531 * Probe used tuner. We need to know used tuner before demod attach
532 * since there is some demod params needed to set according to tuner.
533 */
534
535 /* open demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300536 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300537 if (ret)
538 goto err;
539
Thomas Mair5cf66312012-05-18 14:47:41 -0300540 priv->tuner = TUNER_NONE;
541
542 /* check FC0012 ID register; reg=00 val=a1 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300543 ret = rtl28xxu_ctrl_msg(d, &req_fc0012);
Thomas Mair5cf66312012-05-18 14:47:41 -0300544 if (ret == 0 && buf[0] == 0xa1) {
545 priv->tuner = TUNER_RTL2832_FC0012;
546 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300547 dev_info(&d->udev->dev, "%s: FC0012 tuner found",
548 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300549 goto found;
550 }
551
552 /* check FC0013 ID register; reg=00 val=a3 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300553 ret = rtl28xxu_ctrl_msg(d, &req_fc0013);
Thomas Mair5cf66312012-05-18 14:47:41 -0300554 if (ret == 0 && buf[0] == 0xa3) {
555 priv->tuner = TUNER_RTL2832_FC0013;
556 rtl2832_config = &rtl28xxu_rtl2832_fc0013_config;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300557 dev_info(&d->udev->dev, "%s: FC0013 tuner found",
558 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300559 goto found;
560 }
561
562 /* check MT2266 ID register; reg=00 val=85 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300563 ret = rtl28xxu_ctrl_msg(d, &req_mt2266);
Thomas Mair5cf66312012-05-18 14:47:41 -0300564 if (ret == 0 && buf[0] == 0x85) {
565 priv->tuner = TUNER_RTL2832_MT2266;
566 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300567 dev_info(&d->udev->dev, "%s: MT2266 tuner found",
568 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300569 goto unsupported;
570 }
571
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300572 /* check FC2580 ID register; reg=01 val=56 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300573 ret = rtl28xxu_ctrl_msg(d, &req_fc2580);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300574 if (ret == 0 && buf[0] == 0x56) {
575 priv->tuner = TUNER_RTL2832_FC2580;
Thomas Mair5cf66312012-05-18 14:47:41 -0300576 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300577 dev_info(&d->udev->dev, "%s: FC2580 tuner found",
578 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300579 goto unsupported;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300580 }
581
Thomas Mair5cf66312012-05-18 14:47:41 -0300582 /* check MT2063 ID register; reg=00 val=9e || 9c */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300583 ret = rtl28xxu_ctrl_msg(d, &req_mt2063);
Thomas Mair5cf66312012-05-18 14:47:41 -0300584 if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) {
585 priv->tuner = TUNER_RTL2832_MT2063;
586 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300587 dev_info(&d->udev->dev, "%s: MT2063 tuner found",
588 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300589 goto unsupported;
590 }
591
592 /* check MAX3543 ID register; reg=00 val=38 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300593 ret = rtl28xxu_ctrl_msg(d, &req_max3543);
Thomas Mair5cf66312012-05-18 14:47:41 -0300594 if (ret == 0 && buf[0] == 0x38) {
595 priv->tuner = TUNER_RTL2832_MAX3543;
596 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300597 dev_info(&d->udev->dev, "%s: MAX3534 tuner found",
598 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300599 goto unsupported;
600 }
601
602 /* check TUA9001 ID register; reg=7e val=2328 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300603 ret = rtl28xxu_ctrl_msg(d, &req_tua9001);
Thomas Mair5cf66312012-05-18 14:47:41 -0300604 if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) {
605 priv->tuner = TUNER_RTL2832_TUA9001;
606 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300607 dev_info(&d->udev->dev, "%s: TUA9001 tuner found",
608 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300609 goto unsupported;
610 }
611
612 /* check MXL5007R ID register; reg=d9 val=14 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300613 ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t);
Thomas Mair5cf66312012-05-18 14:47:41 -0300614 if (ret == 0 && buf[0] == 0x14) {
615 priv->tuner = TUNER_RTL2832_MXL5007T;
616 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300617 dev_info(&d->udev->dev, "%s: MXL5007T tuner found",
618 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300619 goto unsupported;
620 }
621
622 /* check E4000 ID register; reg=02 val=40 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300623 ret = rtl28xxu_ctrl_msg(d, &req_e4000);
Thomas Mair5cf66312012-05-18 14:47:41 -0300624 if (ret == 0 && buf[0] == 0x40) {
625 priv->tuner = TUNER_RTL2832_E4000;
626 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300627 dev_info(&d->udev->dev, "%s: E4000 tuner found",
628 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300629 goto unsupported;
630 }
631
632 /* check TDA18272 ID register; reg=00 val=c760 */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300633 ret = rtl28xxu_ctrl_msg(d, &req_tda18272);
Thomas Mair5cf66312012-05-18 14:47:41 -0300634 if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) {
635 priv->tuner = TUNER_RTL2832_TDA18272;
636 /* TODO implement tuner */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300637 dev_info(&d->udev->dev, "%s: TDA18272 tuner found",
638 KBUILD_MODNAME);
Thomas Mair5cf66312012-05-18 14:47:41 -0300639 goto unsupported;
640 }
641
642unsupported:
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300643 /* close demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300644 ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300645 if (ret)
646 goto err;
647
648 /* tuner not found */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300649 dev_dbg(&d->udev->dev, "%s: No compatible tuner found\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300650 ret = -ENODEV;
Thomas Mair5cf66312012-05-18 14:47:41 -0300651 return ret;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300652
653found:
654 /* close demod I2C gate */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300655 ret = rtl28xxu_ctrl_msg(d, &req_gate_close);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300656 if (ret)
657 goto err;
658
659 /* attach demodulator */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300660 adap->fe[0] = dvb_attach(rtl2832_attach, rtl2832_config,
661 &d->i2c_adap);
662 if (adap->fe[0] == NULL) {
Thomas Mair5cf66312012-05-18 14:47:41 -0300663 ret = -ENODEV;
664 goto err;
665 }
666
667 /* set fe callbacks */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300668 adap->fe[0]->callback = rtl2832u_frontend_callback;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300669
670 return ret;
Thomas Mair5cf66312012-05-18 14:47:41 -0300671
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300672err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300673 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300674 return ret;
675}
676
Antti Palosaari831e0b72011-07-08 23:36:07 -0300677static struct qt1010_config rtl28xxu_qt1010_config = {
678 .i2c_address = 0x62, /* 0xc4 */
679};
680
681static struct mt2060_config rtl28xxu_mt2060_config = {
682 .i2c_address = 0x60, /* 0xc0 */
683 .clock_out = 0,
684};
685
686static struct mxl5005s_config rtl28xxu_mxl5005s_config = {
687 .i2c_address = 0x63, /* 0xc6 */
688 .if_freq = IF_FREQ_4570000HZ,
689 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
690 .agc_mode = MXL_SINGLE_AGC,
691 .tracking_filter = MXL_TF_C_H,
692 .rssi_enable = MXL_RSSI_ENABLE,
693 .cap_select = MXL_CAP_SEL_ENABLE,
694 .div_out = MXL_DIV_OUT_4,
695 .clock_out = MXL_CLOCK_OUT_DISABLE,
696 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
697 .top = MXL5005S_TOP_25P2,
698 .mod_mode = MXL_DIGITAL_MODE,
699 .if_mode = MXL_ZERO_IF,
700 .AgcMasterByte = 0x00,
701};
702
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300703static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300704{
705 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300706 struct dvb_usb_device *d = adap_to_d(adap);
707 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300708 struct i2c_adapter *rtl2830_tuner_i2c;
Antti Palosaari9935eea2012-01-21 22:26:52 -0300709 struct dvb_frontend *fe;
Antti Palosaari831e0b72011-07-08 23:36:07 -0300710
Antti Palosaaric01a3592012-08-12 22:27:07 -0300711 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300712
713 /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300714 rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe[0]);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300715
716 switch (priv->tuner) {
717 case TUNER_RTL2830_QT1010:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300718 fe = dvb_attach(qt1010_attach, adap->fe[0],
Antti Palosaarifba16b12012-01-21 20:28:38 -0300719 rtl2830_tuner_i2c, &rtl28xxu_qt1010_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300720 break;
721 case TUNER_RTL2830_MT2060:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300722 fe = dvb_attach(mt2060_attach, adap->fe[0],
Antti Palosaarifba16b12012-01-21 20:28:38 -0300723 rtl2830_tuner_i2c, &rtl28xxu_mt2060_config,
724 1220);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300725 break;
726 case TUNER_RTL2830_MXL5005S:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300727 fe = dvb_attach(mxl5005s_attach, adap->fe[0],
Antti Palosaari9935eea2012-01-21 22:26:52 -0300728 rtl2830_tuner_i2c, &rtl28xxu_mxl5005s_config);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300729 break;
730 default:
Antti Palosaari9935eea2012-01-21 22:26:52 -0300731 fe = NULL;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300732 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
733 priv->tuner);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300734 }
735
736 if (fe == NULL) {
737 ret = -ENODEV;
738 goto err;
739 }
740
741 return 0;
742err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300743 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300744 return ret;
745}
746
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300747static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
748{
749 int ret;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300750 struct dvb_usb_device *d = adap_to_d(adap);
751 struct rtl28xxu_priv *priv = d_to_priv(d);
Antti Palosaari9935eea2012-01-21 22:26:52 -0300752 struct dvb_frontend *fe;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300753
Antti Palosaaric01a3592012-08-12 22:27:07 -0300754 dev_dbg(&d->udev->dev, "%s:\n", __func__);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300755
756 switch (priv->tuner) {
Thomas Mair5cf66312012-05-18 14:47:41 -0300757 case TUNER_RTL2832_FC0012:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300758 fe = dvb_attach(fc0012_attach, adap->fe[0],
759 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -0300760
761 /* since fc0012 includs reading the signal strength delegate
762 * that to the tuner driver */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300763 adap->fe[0]->ops.read_signal_strength =
764 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Thomas Mair5cf66312012-05-18 14:47:41 -0300765 return 0;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300766 break;
Thomas Mair5cf66312012-05-18 14:47:41 -0300767 case TUNER_RTL2832_FC0013:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300768 fe = dvb_attach(fc0013_attach, adap->fe[0],
769 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
Thomas Mair5cf66312012-05-18 14:47:41 -0300770
771 /* fc0013 also supports signal strength reading */
Antti Palosaaric01a3592012-08-12 22:27:07 -0300772 adap->fe[0]->ops.read_signal_strength =
773 adap->fe[0]->ops.tuner_ops.get_rf_strength;
Thomas Mair5cf66312012-05-18 14:47:41 -0300774 return 0;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300775 default:
Antti Palosaari9935eea2012-01-21 22:26:52 -0300776 fe = NULL;
Antti Palosaaric01a3592012-08-12 22:27:07 -0300777 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME,
778 priv->tuner);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300779 }
780
781 if (fe == NULL) {
782 ret = -ENODEV;
783 goto err;
784 }
785
786 return 0;
787err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300788 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -0300789 return ret;
790}
791
Antti Palosaaric01a3592012-08-12 22:27:07 -0300792static int rtl28xxu_init(struct dvb_usb_device *d)
793{
794 int ret;
795 u8 val;
796
797 dev_dbg(&d->udev->dev, "%s:\n", __func__);
798
799 /* init USB endpoints */
800 ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val);
801 if (ret)
802 goto err;
803
804 /* enable DMA and Full Packet Mode*/
805 val |= 0x09;
806 ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val);
807 if (ret)
808 goto err;
809
810 /* set EPA maximum packet size to 0x0200 */
811 ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
812 if (ret)
813 goto err;
814
815 /* change EPA FIFO length */
816 ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
817 if (ret)
818 goto err;
819
820 return ret;
821err:
822 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
823 return ret;
824}
825
Antti Palosaari991452a2012-08-12 22:27:08 -0300826static int rtl28xxu_streaming_ctrl(struct dvb_frontend *fe , int onoff)
Thomas Mair5cf66312012-05-18 14:47:41 -0300827{
828 int ret;
829 u8 buf[2];
Antti Palosaaric01a3592012-08-12 22:27:07 -0300830 struct dvb_usb_device *d = fe_to_d(fe);
Thomas Mair5cf66312012-05-18 14:47:41 -0300831
Antti Palosaaric01a3592012-08-12 22:27:07 -0300832 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Thomas Mair5cf66312012-05-18 14:47:41 -0300833
834 if (onoff) {
835 buf[0] = 0x00;
836 buf[1] = 0x00;
837 } else {
838 buf[0] = 0x10; /* stall EPA */
839 buf[1] = 0x02; /* reset EPA */
840 }
841
Antti Palosaaric01a3592012-08-12 22:27:07 -0300842 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, buf, 2);
Thomas Mair5cf66312012-05-18 14:47:41 -0300843 if (ret)
844 goto err;
845
846 return ret;
847err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300848 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -0300849 return ret;
850}
851
852static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
Antti Palosaari831e0b72011-07-08 23:36:07 -0300853{
854 int ret;
855 u8 gpio, sys0;
856
Antti Palosaaric01a3592012-08-12 22:27:07 -0300857 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300858
859 /* demod adc */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300860 ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300861 if (ret)
862 goto err;
863
864 /* tuner power, read GPIOs */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300865 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300866 if (ret)
867 goto err;
868
Antti Palosaaric01a3592012-08-12 22:27:07 -0300869 dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
870 sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300871
872 if (onoff) {
873 gpio |= 0x01; /* GPIO0 = 1 */
874 gpio &= (~0x10); /* GPIO4 = 0 */
Antti Palosaari991452a2012-08-12 22:27:08 -0300875 gpio |= 0x04; /* GPIO2 = 1, LED on */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300876 sys0 = sys0 & 0x0f;
877 sys0 |= 0xe0;
878 } else {
Antti Palosaari831e0b72011-07-08 23:36:07 -0300879 gpio &= (~0x01); /* GPIO0 = 0 */
880 gpio |= 0x10; /* GPIO4 = 1 */
Antti Palosaari991452a2012-08-12 22:27:08 -0300881 gpio &= (~0x04); /* GPIO2 = 1, LED off */
Antti Palosaari831e0b72011-07-08 23:36:07 -0300882 sys0 = sys0 & (~0xc0);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300883 }
884
Antti Palosaaric01a3592012-08-12 22:27:07 -0300885 dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__,
886 sys0, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300887
888 /* demod adc */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300889 ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300890 if (ret)
891 goto err;
892
893 /* tuner power, write GPIOs */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300894 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300895 if (ret)
896 goto err;
897
898 return ret;
899err:
Antti Palosaaric01a3592012-08-12 22:27:07 -0300900 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -0300901 return ret;
902}
903
Thomas Mair5cf66312012-05-18 14:47:41 -0300904static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
905{
906 int ret;
907 u8 val;
908
Antti Palosaaric01a3592012-08-12 22:27:07 -0300909 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
Thomas Mair5cf66312012-05-18 14:47:41 -0300910
911 if (onoff) {
912 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300913 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300914 if (ret)
915 goto err;
916
917 val |= 0x08;
918 val &= 0xef;
919
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300920 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300921 if (ret)
922 goto err;
923
924 /* demod_ctl_1 */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300925 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300926 if (ret)
927 goto err;
928
929 val &= 0xef;
930
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300931 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300932 if (ret)
933 goto err;
934
935 /* demod control */
936 /* PLL enable */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300937 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300938 if (ret)
939 goto err;
940
941 /* bit 7 to 1 */
942 val |= 0x80;
943
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300944 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300945 if (ret)
946 goto err;
947
948 /* demod HW reset */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300949 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300950 if (ret)
951 goto err;
952 /* bit 5 to 0 */
953 val &= 0xdf;
954
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300955 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300956 if (ret)
957 goto err;
958
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300959 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300960 if (ret)
961 goto err;
962
963 val |= 0x20;
964
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300965 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300966 if (ret)
967 goto err;
968
969 mdelay(5);
970
971 /*enable ADC_Q and ADC_I */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300972 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300973 if (ret)
974 goto err;
975
976 val |= 0x48;
977
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300978 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300979 if (ret)
980 goto err;
981
982
983 } else {
984 /* demod_ctl_1 */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300985 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300986 if (ret)
987 goto err;
988
989 val |= 0x0c;
990
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300991 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300992 if (ret)
993 goto err;
994
995 /* set output values */
Thomas Mair40a2d3c2012-05-18 14:47:42 -0300996 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -0300997 if (ret)
998 goto err;
999
1000 val |= 0x10;
1001
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001002 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001003 if (ret)
1004 goto err;
1005
1006 /* demod control */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001007 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001008 if (ret)
1009 goto err;
1010
1011 val &= 0x37;
1012
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001013 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
Thomas Mair5cf66312012-05-18 14:47:41 -03001014 if (ret)
1015 goto err;
1016
1017 }
1018
1019 return ret;
1020err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001021 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Thomas Mair5cf66312012-05-18 14:47:41 -03001022 return ret;
1023}
1024
1025
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001026static int rtl2831u_rc_query(struct dvb_usb_device *d)
Antti Palosaari831e0b72011-07-08 23:36:07 -03001027{
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001028 int ret, i;
1029 struct rtl28xxu_priv *priv = d->priv;
Antti Palosaari831e0b72011-07-08 23:36:07 -03001030 u8 buf[5];
1031 u32 rc_code;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001032 struct rtl28xxu_reg_val rc_nec_tab[] = {
1033 { 0x3033, 0x80 },
1034 { 0x3020, 0x43 },
1035 { 0x3021, 0x16 },
1036 { 0x3022, 0x16 },
1037 { 0x3023, 0x5a },
1038 { 0x3024, 0x2d },
1039 { 0x3025, 0x16 },
1040 { 0x3026, 0x01 },
1041 { 0x3028, 0xb0 },
1042 { 0x3029, 0x04 },
1043 { 0x302c, 0x88 },
1044 { 0x302e, 0x13 },
1045 { 0x3030, 0xdf },
1046 { 0x3031, 0x05 },
1047 };
1048
1049 /* init remote controller */
1050 if (!priv->rc_active) {
1051 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001052 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001053 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001054 if (ret)
1055 goto err;
1056 }
1057 priv->rc_active = true;
1058 }
Antti Palosaari831e0b72011-07-08 23:36:07 -03001059
1060 ret = rtl2831_rd_regs(d, SYS_IRRC_RP, buf, 5);
1061 if (ret)
1062 goto err;
1063
1064 if (buf[4] & 0x01) {
1065 if (buf[2] == (u8) ~buf[3]) {
1066 if (buf[0] == (u8) ~buf[1]) {
1067 /* NEC standard (16 bit) */
1068 rc_code = buf[0] << 8 | buf[2];
1069 } else {
1070 /* NEC extended (24 bit) */
1071 rc_code = buf[0] << 16 |
Antti Palosaari9935eea2012-01-21 22:26:52 -03001072 buf[1] << 8 | buf[2];
Antti Palosaari831e0b72011-07-08 23:36:07 -03001073 }
1074 } else {
1075 /* NEC full (32 bit) */
1076 rc_code = buf[0] << 24 | buf[1] << 16 |
1077 buf[2] << 8 | buf[3];
1078 }
1079
1080 rc_keydown(d->rc_dev, rc_code, 0);
1081
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001082 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001083 if (ret)
1084 goto err;
1085
1086 /* repeated intentionally to avoid extra keypress */
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001087 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001088 if (ret)
1089 goto err;
1090 }
1091
1092 return ret;
1093err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001094 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001095 return ret;
1096}
1097
Antti Palosaaric01a3592012-08-12 22:27:07 -03001098static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
1099 struct dvb_usb_rc *rc)
1100{
1101 rc->map_name = RC_MAP_EMPTY;
1102 rc->allowed_protos = RC_TYPE_NEC;
1103 rc->query = rtl2831u_rc_query;
1104 rc->interval = 400;
1105
1106 return 0;
1107}
1108
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001109static int rtl2832u_rc_query(struct dvb_usb_device *d)
1110{
1111 int ret, i;
1112 struct rtl28xxu_priv *priv = d->priv;
1113 u8 buf[128];
1114 int len;
1115 struct rtl28xxu_reg_val rc_nec_tab[] = {
Antti Palosaari9935eea2012-01-21 22:26:52 -03001116 { IR_RX_CTRL, 0x20 },
1117 { IR_RX_BUF_CTRL, 0x80 },
1118 { IR_RX_IF, 0xff },
1119 { IR_RX_IE, 0xff },
1120 { IR_MAX_DURATION0, 0xd0 },
1121 { IR_MAX_DURATION1, 0x07 },
1122 { IR_IDLE_LEN0, 0xc0 },
1123 { IR_IDLE_LEN1, 0x00 },
1124 { IR_GLITCH_LEN, 0x03 },
1125 { IR_RX_CLK, 0x09 },
1126 { IR_RX_CFG, 0x1c },
1127 { IR_MAX_H_TOL_LEN, 0x1e },
1128 { IR_MAX_L_TOL_LEN, 0x1e },
1129 { IR_RX_CTRL, 0x80 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001130 };
1131
1132 /* init remote controller */
1133 if (!priv->rc_active) {
1134 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001135 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg,
Antti Palosaari9935eea2012-01-21 22:26:52 -03001136 rc_nec_tab[i].val);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001137 if (ret)
1138 goto err;
1139 }
1140 priv->rc_active = true;
1141 }
1142
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001143 ret = rtl28xx_rd_reg(d, IR_RX_IF, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001144 if (ret)
1145 goto err;
1146
1147 if (buf[0] != 0x83)
1148 goto exit;
1149
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001150 ret = rtl28xx_rd_reg(d, IR_RX_BC, &buf[0]);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001151 if (ret)
1152 goto err;
1153
1154 len = buf[0];
1155 ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len);
1156
1157 /* TODO: pass raw IR to Kernel IR decoder */
1158
Thomas Mair40a2d3c2012-05-18 14:47:42 -03001159 ret = rtl28xx_wr_reg(d, IR_RX_IF, 0x03);
1160 ret = rtl28xx_wr_reg(d, IR_RX_BUF_CTRL, 0x80);
1161 ret = rtl28xx_wr_reg(d, IR_RX_CTRL, 0x80);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001162
1163exit:
1164 return ret;
1165err:
Antti Palosaaric01a3592012-08-12 22:27:07 -03001166 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret);
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001167 return ret;
1168}
1169
Antti Palosaaric01a3592012-08-12 22:27:07 -03001170static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1171 struct dvb_usb_rc *rc)
1172{
1173 rc->map_name = RC_MAP_EMPTY;
1174 rc->allowed_protos = RC_TYPE_NEC;
1175 rc->query = rtl2832u_rc_query;
1176 rc->interval = 400;
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001177
Antti Palosaaric01a3592012-08-12 22:27:07 -03001178 return 0;
1179}
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001180
Antti Palosaaric01a3592012-08-12 22:27:07 -03001181static const struct dvb_usb_device_properties rtl2831u_props = {
1182 .driver_name = KBUILD_MODNAME,
1183 .owner = THIS_MODULE,
1184 .adapter_nr = adapter_nr,
1185 .size_of_priv = sizeof(struct rtl28xxu_priv),
Antti Palosaari831e0b72011-07-08 23:36:07 -03001186
Antti Palosaaric01a3592012-08-12 22:27:07 -03001187 .power_ctrl = rtl2831u_power_ctrl,
1188 .i2c_algo = &rtl28xxu_i2c_algo,
1189 .frontend_attach = rtl2831u_frontend_attach,
1190 .tuner_attach = rtl2831u_tuner_attach,
1191 .init = rtl28xxu_init,
1192 .get_rc_config = rtl2831u_get_rc_config,
Antti Palosaari991452a2012-08-12 22:27:08 -03001193 .streaming_ctrl = rtl28xxu_streaming_ctrl,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001194
Antti Palosaaric01a3592012-08-12 22:27:07 -03001195 .num_adapters = 1,
1196 .adapter = {
1197 {
1198 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaari831e0b72011-07-08 23:36:07 -03001199 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001200 },
Antti Palosaaric01a3592012-08-12 22:27:07 -03001201};
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001202
Antti Palosaaric01a3592012-08-12 22:27:07 -03001203static const struct dvb_usb_device_properties rtl2832u_props = {
1204 .driver_name = KBUILD_MODNAME,
1205 .owner = THIS_MODULE,
1206 .adapter_nr = adapter_nr,
1207 .size_of_priv = sizeof(struct rtl28xxu_priv),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001208
Antti Palosaaric01a3592012-08-12 22:27:07 -03001209 .power_ctrl = rtl2832u_power_ctrl,
1210 .i2c_algo = &rtl28xxu_i2c_algo,
1211 .frontend_attach = rtl2832u_frontend_attach,
1212 .tuner_attach = rtl2832u_tuner_attach,
1213 .init = rtl28xxu_init,
1214 .get_rc_config = rtl2832u_get_rc_config,
Antti Palosaari991452a2012-08-12 22:27:08 -03001215 .streaming_ctrl = rtl28xxu_streaming_ctrl,
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001216
Antti Palosaaric01a3592012-08-12 22:27:07 -03001217 .num_adapters = 1,
1218 .adapter = {
1219 {
1220 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001221 },
Antti Palosaarib5cbaa42011-08-04 13:26:10 -03001222 },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001223};
1224
Antti Palosaaric01a3592012-08-12 22:27:07 -03001225static const struct usb_device_id rtl28xxu_id_table[] = {
1226 { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U,
1227 &rtl2831u_props, "Realtek RTL2831U reference design", NULL) },
1228 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT,
1229 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
1230 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2,
1231 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) },
Antti Palosaari831e0b72011-07-08 23:36:07 -03001232
Antti Palosaaric01a3592012-08-12 22:27:07 -03001233 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
1234 &rtl2832u_props, "Terratec Cinergy T Stick Black", NULL) },
1235 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
1236 &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
1237 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
1238 &rtl2832u_props, "NOXON DAB/DAB+ USB dongle", NULL) },
1239 { }
1240};
1241MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001242
Antti Palosaaric01a3592012-08-12 22:27:07 -03001243static struct usb_driver rtl28xxu_usb_driver = {
1244 .name = KBUILD_MODNAME,
1245 .id_table = rtl28xxu_id_table,
1246 .probe = dvb_usbv2_probe,
1247 .disconnect = dvb_usbv2_disconnect,
1248 .suspend = dvb_usbv2_suspend,
1249 .resume = dvb_usbv2_resume,
1250 .no_dynamic_id = 1,
1251 .soft_unbind = 1,
Antti Palosaari831e0b72011-07-08 23:36:07 -03001252};
1253
Antti Palosaaric01a3592012-08-12 22:27:07 -03001254module_usb_driver(rtl28xxu_usb_driver);
Antti Palosaari831e0b72011-07-08 23:36:07 -03001255
1256MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
1257MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
Thomas Mair5cf66312012-05-18 14:47:41 -03001258MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>");
Antti Palosaari831e0b72011-07-08 23:36:07 -03001259MODULE_LICENSE("GPL");