1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Realtek RTL28xxU DVB USB driver
5 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
6 * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
7 * Copyright (C) 2012 Thomas Mair <thomas.mair86@googlemail.com>
12 static int rtl28xxu_disable_rc
;
13 module_param_named(disable_rc
, rtl28xxu_disable_rc
, int, 0644);
14 MODULE_PARM_DESC(disable_rc
, "disable RTL2832U remote controller");
15 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
17 static int rtl28xxu_ctrl_msg(struct dvb_usb_device
*d
, struct rtl28xxu_req
*req
)
19 struct rtl28xxu_dev
*dev
= d
->priv
;
24 mutex_lock(&d
->usb_mutex
);
26 if (req
->size
> sizeof(dev
->buf
)) {
27 dev_err(&d
->intf
->dev
, "too large message %u\n", req
->size
);
29 goto err_mutex_unlock
;
32 if (req
->index
& CMD_WR_FLAG
) {
34 memcpy(dev
->buf
, req
->data
, req
->size
);
35 requesttype
= (USB_TYPE_VENDOR
| USB_DIR_OUT
);
36 pipe
= usb_sndctrlpipe(d
->udev
, 0);
39 requesttype
= (USB_TYPE_VENDOR
| USB_DIR_IN
);
40 pipe
= usb_rcvctrlpipe(d
->udev
, 0);
43 ret
= usb_control_msg(d
->udev
, pipe
, 0, requesttype
, req
->value
,
44 req
->index
, dev
->buf
, req
->size
, 1000);
45 dvb_usb_dbg_usb_control_msg(d
->udev
, 0, requesttype
, req
->value
,
46 req
->index
, dev
->buf
, req
->size
);
48 goto err_mutex_unlock
;
50 /* read request, copy returned data to return buf */
51 if (requesttype
== (USB_TYPE_VENDOR
| USB_DIR_IN
))
52 memcpy(req
->data
, dev
->buf
, req
->size
);
54 mutex_unlock(&d
->usb_mutex
);
58 mutex_unlock(&d
->usb_mutex
);
59 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
63 static int rtl28xxu_wr_regs(struct dvb_usb_device
*d
, u16 reg
, u8
*val
, int len
)
65 struct rtl28xxu_req req
;
68 req
.index
= CMD_USB_WR
;
69 else if (reg
< 0x4000)
70 req
.index
= CMD_SYS_WR
;
72 req
.index
= CMD_IR_WR
;
78 return rtl28xxu_ctrl_msg(d
, &req
);
81 static int rtl28xxu_rd_regs(struct dvb_usb_device
*d
, u16 reg
, u8
*val
, int len
)
83 struct rtl28xxu_req req
;
86 req
.index
= CMD_USB_RD
;
87 else if (reg
< 0x4000)
88 req
.index
= CMD_SYS_RD
;
90 req
.index
= CMD_IR_RD
;
96 return rtl28xxu_ctrl_msg(d
, &req
);
99 static int rtl28xxu_wr_reg(struct dvb_usb_device
*d
, u16 reg
, u8 val
)
101 return rtl28xxu_wr_regs(d
, reg
, &val
, 1);
104 static int rtl28xxu_rd_reg(struct dvb_usb_device
*d
, u16 reg
, u8
*val
)
106 return rtl28xxu_rd_regs(d
, reg
, val
, 1);
109 static int rtl28xxu_wr_reg_mask(struct dvb_usb_device
*d
, u16 reg
, u8 val
,
115 /* no need for read if whole reg is written */
117 ret
= rtl28xxu_rd_reg(d
, reg
, &tmp
);
126 return rtl28xxu_wr_reg(d
, reg
, val
);
130 static int rtl28xxu_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg msg
[],
134 struct dvb_usb_device
*d
= i2c_get_adapdata(adap
);
135 struct rtl28xxu_dev
*dev
= d
->priv
;
136 struct rtl28xxu_req req
;
139 * It is not known which are real I2C bus xfer limits, but testing
140 * with RTL2831U + MT2060 gives max RD 24 and max WR 22 bytes.
141 * TODO: find out RTL2832U lens
145 * I2C adapter logic looks rather complicated due to fact it handles
146 * three different access methods. Those methods are;
147 * 1) integrated demod access
151 * Used method is selected in order 1, 2, 3. Method 3 can handle all
152 * requests but there is two reasons why not use it always;
153 * 1) It is most expensive, usually two USB messages are needed
154 * 2) At least RTL2831U does not support it
156 * Method 3 is needed in case of I2C write+read (typical register read)
157 * where write is more than one byte.
160 if (mutex_lock_interruptible(&d
->i2c_mutex
) < 0)
163 if (num
== 2 && !(msg
[0].flags
& I2C_M_RD
) &&
164 (msg
[1].flags
& I2C_M_RD
)) {
165 if (msg
[0].len
> 24 || msg
[1].len
> 24) {
166 /* TODO: check msg[0].len max */
168 goto err_mutex_unlock
;
169 } else if (msg
[0].addr
== 0x10) {
170 /* method 1 - integrated demod */
171 if (msg
[0].buf
[0] == 0x00) {
172 /* return demod page from driver cache */
173 msg
[1].buf
[0] = dev
->page
;
176 req
.value
= (msg
[0].buf
[0] << 8) | (msg
[0].addr
<< 1);
177 req
.index
= CMD_DEMOD_RD
| dev
->page
;
178 req
.size
= msg
[1].len
;
179 req
.data
= &msg
[1].buf
[0];
180 ret
= rtl28xxu_ctrl_msg(d
, &req
);
182 } else if (msg
[0].len
< 2) {
183 /* method 2 - old I2C */
184 req
.value
= (msg
[0].buf
[0] << 8) | (msg
[0].addr
<< 1);
185 req
.index
= CMD_I2C_RD
;
186 req
.size
= msg
[1].len
;
187 req
.data
= &msg
[1].buf
[0];
188 ret
= rtl28xxu_ctrl_msg(d
, &req
);
190 /* method 3 - new I2C */
191 req
.value
= (msg
[0].addr
<< 1);
192 req
.index
= CMD_I2C_DA_WR
;
193 req
.size
= msg
[0].len
;
194 req
.data
= msg
[0].buf
;
195 ret
= rtl28xxu_ctrl_msg(d
, &req
);
197 goto err_mutex_unlock
;
199 req
.value
= (msg
[0].addr
<< 1);
200 req
.index
= CMD_I2C_DA_RD
;
201 req
.size
= msg
[1].len
;
202 req
.data
= msg
[1].buf
;
203 ret
= rtl28xxu_ctrl_msg(d
, &req
);
205 } else if (num
== 1 && !(msg
[0].flags
& I2C_M_RD
)) {
206 if (msg
[0].len
> 22) {
207 /* TODO: check msg[0].len max */
209 goto err_mutex_unlock
;
210 } else if (msg
[0].addr
== 0x10) {
211 /* method 1 - integrated demod */
212 if (msg
[0].buf
[0] == 0x00) {
213 /* save demod page for later demod access */
214 dev
->page
= msg
[0].buf
[1];
217 req
.value
= (msg
[0].buf
[0] << 8) |
219 req
.index
= CMD_DEMOD_WR
| dev
->page
;
220 req
.size
= msg
[0].len
-1;
221 req
.data
= &msg
[0].buf
[1];
222 ret
= rtl28xxu_ctrl_msg(d
, &req
);
224 } else if ((msg
[0].len
< 23) && (!dev
->new_i2c_write
)) {
225 /* method 2 - old I2C */
226 req
.value
= (msg
[0].buf
[0] << 8) | (msg
[0].addr
<< 1);
227 req
.index
= CMD_I2C_WR
;
228 req
.size
= msg
[0].len
-1;
229 req
.data
= &msg
[0].buf
[1];
230 ret
= rtl28xxu_ctrl_msg(d
, &req
);
232 /* method 3 - new I2C */
233 req
.value
= (msg
[0].addr
<< 1);
234 req
.index
= CMD_I2C_DA_WR
;
235 req
.size
= msg
[0].len
;
236 req
.data
= msg
[0].buf
;
237 ret
= rtl28xxu_ctrl_msg(d
, &req
);
239 } else if (num
== 1 && (msg
[0].flags
& I2C_M_RD
)) {
240 req
.value
= (msg
[0].addr
<< 1);
241 req
.index
= CMD_I2C_DA_RD
;
242 req
.size
= msg
[0].len
;
243 req
.data
= msg
[0].buf
;
244 ret
= rtl28xxu_ctrl_msg(d
, &req
);
249 /* Retry failed I2C messages */
254 mutex_unlock(&d
->i2c_mutex
);
256 return ret
? ret
: num
;
259 static u32
rtl28xxu_i2c_func(struct i2c_adapter
*adapter
)
264 static struct i2c_algorithm rtl28xxu_i2c_algo
= {
265 .master_xfer
= rtl28xxu_i2c_xfer
,
266 .functionality
= rtl28xxu_i2c_func
,
269 static int rtl2831u_read_config(struct dvb_usb_device
*d
)
271 struct rtl28xxu_dev
*dev
= d_to_priv(d
);
274 /* open RTL2831U/RTL2830 I2C gate */
275 struct rtl28xxu_req req_gate_open
= {0x0120, 0x0011, 0x0001, "\x08"};
277 struct rtl28xxu_req req_mt2060
= {0x00c0, CMD_I2C_RD
, 1, buf
};
278 struct rtl28xxu_req req_qt1010
= {0x0fc4, CMD_I2C_RD
, 1, buf
};
280 dev_dbg(&d
->intf
->dev
, "\n");
284 * =========================================================
285 * GPIO0 | tuner#0 | 0 off | 1 on | MXL5005S (?)
286 * GPIO2 | LED | 0 off | 1 on |
287 * GPIO4 | tuner#1 | 0 on | 1 off | MT2060
291 ret
= rtl28xxu_wr_reg(d
, SYS_GPIO_DIR
, 0x0a);
295 /* enable as output GPIO0, GPIO2, GPIO4 */
296 ret
= rtl28xxu_wr_reg(d
, SYS_GPIO_OUT_EN
, 0x15);
301 * Probe used tuner. We need to know used tuner before demod attach
302 * since there is some demod params needed to set according to tuner.
305 /* demod needs some time to wake up */
308 dev
->tuner_name
= "NONE";
310 /* open demod I2C gate */
311 ret
= rtl28xxu_ctrl_msg(d
, &req_gate_open
);
315 /* check QT1010 ID(?) register; reg=0f val=2c */
316 ret
= rtl28xxu_ctrl_msg(d
, &req_qt1010
);
317 if (ret
== 0 && buf
[0] == 0x2c) {
318 dev
->tuner
= TUNER_RTL2830_QT1010
;
319 dev
->tuner_name
= "QT1010";
323 /* open demod I2C gate */
324 ret
= rtl28xxu_ctrl_msg(d
, &req_gate_open
);
328 /* check MT2060 ID register; reg=00 val=63 */
329 ret
= rtl28xxu_ctrl_msg(d
, &req_mt2060
);
330 if (ret
== 0 && buf
[0] == 0x63) {
331 dev
->tuner
= TUNER_RTL2830_MT2060
;
332 dev
->tuner_name
= "MT2060";
336 /* assume MXL5005S */
337 dev
->tuner
= TUNER_RTL2830_MXL5005S
;
338 dev
->tuner_name
= "MXL5005S";
342 dev_dbg(&d
->intf
->dev
, "tuner=%s\n", dev
->tuner_name
);
346 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
350 static int rtl2832u_read_config(struct dvb_usb_device
*d
)
352 struct rtl28xxu_dev
*dev
= d_to_priv(d
);
355 /* open RTL2832U/RTL2832 I2C gate */
356 struct rtl28xxu_req req_gate_open
= {0x0120, 0x0011, 0x0001, "\x18"};
357 /* close RTL2832U/RTL2832 I2C gate */
358 struct rtl28xxu_req req_gate_close
= {0x0120, 0x0011, 0x0001, "\x10"};
360 struct rtl28xxu_req req_fc0012
= {0x00c6, CMD_I2C_RD
, 1, buf
};
361 struct rtl28xxu_req req_fc0013
= {0x00c6, CMD_I2C_RD
, 1, buf
};
362 struct rtl28xxu_req req_mt2266
= {0x00c0, CMD_I2C_RD
, 1, buf
};
363 struct rtl28xxu_req req_fc2580
= {0x01ac, CMD_I2C_RD
, 1, buf
};
364 struct rtl28xxu_req req_mt2063
= {0x00c0, CMD_I2C_RD
, 1, buf
};
365 struct rtl28xxu_req req_max3543
= {0x00c0, CMD_I2C_RD
, 1, buf
};
366 struct rtl28xxu_req req_tua9001
= {0x7ec0, CMD_I2C_RD
, 2, buf
};
367 struct rtl28xxu_req req_mxl5007t
= {0xd9c0, CMD_I2C_RD
, 1, buf
};
368 struct rtl28xxu_req req_e4000
= {0x02c8, CMD_I2C_RD
, 1, buf
};
369 struct rtl28xxu_req req_tda18272
= {0x00c0, CMD_I2C_RD
, 2, buf
};
370 struct rtl28xxu_req req_r820t
= {0x0034, CMD_I2C_RD
, 1, buf
};
371 struct rtl28xxu_req req_r828d
= {0x0074, CMD_I2C_RD
, 1, buf
};
372 struct rtl28xxu_req req_mn88472
= {0xff38, CMD_I2C_RD
, 1, buf
};
373 struct rtl28xxu_req req_mn88473
= {0xff38, CMD_I2C_RD
, 1, buf
};
374 struct rtl28xxu_req req_cxd2837er
= {0xfdd8, CMD_I2C_RD
, 1, buf
};
375 struct rtl28xxu_req req_si2157
= {0x00c0, CMD_I2C_RD
, 1, buf
};
376 struct rtl28xxu_req req_si2168
= {0x00c8, CMD_I2C_RD
, 1, buf
};
378 dev_dbg(&d
->intf
->dev
, "\n");
380 /* enable GPIO3 and GPIO6 as output */
381 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_DIR
, 0x00, 0x40);
385 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_EN
, 0x48, 0x48);
390 * Probe used tuner. We need to know used tuner before demod attach
391 * since there is some demod params needed to set according to tuner.
394 /* open demod I2C gate */
395 ret
= rtl28xxu_ctrl_msg(d
, &req_gate_open
);
399 dev
->tuner_name
= "NONE";
401 /* check FC0012 ID register; reg=00 val=a1 */
402 ret
= rtl28xxu_ctrl_msg(d
, &req_fc0012
);
403 if (ret
== 0 && buf
[0] == 0xa1) {
404 dev
->tuner
= TUNER_RTL2832_FC0012
;
405 dev
->tuner_name
= "FC0012";
409 /* check FC0013 ID register; reg=00 val=a3 */
410 ret
= rtl28xxu_ctrl_msg(d
, &req_fc0013
);
411 if (ret
== 0 && buf
[0] == 0xa3) {
412 dev
->tuner
= TUNER_RTL2832_FC0013
;
413 dev
->tuner_name
= "FC0013";
417 /* check MT2266 ID register; reg=00 val=85 */
418 ret
= rtl28xxu_ctrl_msg(d
, &req_mt2266
);
419 if (ret
== 0 && buf
[0] == 0x85) {
420 dev
->tuner
= TUNER_RTL2832_MT2266
;
421 dev
->tuner_name
= "MT2266";
425 /* check FC2580 ID register; reg=01 val=56 */
426 ret
= rtl28xxu_ctrl_msg(d
, &req_fc2580
);
427 if (ret
== 0 && buf
[0] == 0x56) {
428 dev
->tuner
= TUNER_RTL2832_FC2580
;
429 dev
->tuner_name
= "FC2580";
433 /* check MT2063 ID register; reg=00 val=9e || 9c */
434 ret
= rtl28xxu_ctrl_msg(d
, &req_mt2063
);
435 if (ret
== 0 && (buf
[0] == 0x9e || buf
[0] == 0x9c)) {
436 dev
->tuner
= TUNER_RTL2832_MT2063
;
437 dev
->tuner_name
= "MT2063";
441 /* check MAX3543 ID register; reg=00 val=38 */
442 ret
= rtl28xxu_ctrl_msg(d
, &req_max3543
);
443 if (ret
== 0 && buf
[0] == 0x38) {
444 dev
->tuner
= TUNER_RTL2832_MAX3543
;
445 dev
->tuner_name
= "MAX3543";
449 /* check TUA9001 ID register; reg=7e val=2328 */
450 ret
= rtl28xxu_ctrl_msg(d
, &req_tua9001
);
451 if (ret
== 0 && buf
[0] == 0x23 && buf
[1] == 0x28) {
452 dev
->tuner
= TUNER_RTL2832_TUA9001
;
453 dev
->tuner_name
= "TUA9001";
457 /* check MXL5007R ID register; reg=d9 val=14 */
458 ret
= rtl28xxu_ctrl_msg(d
, &req_mxl5007t
);
459 if (ret
== 0 && buf
[0] == 0x14) {
460 dev
->tuner
= TUNER_RTL2832_MXL5007T
;
461 dev
->tuner_name
= "MXL5007T";
465 /* check E4000 ID register; reg=02 val=40 */
466 ret
= rtl28xxu_ctrl_msg(d
, &req_e4000
);
467 if (ret
== 0 && buf
[0] == 0x40) {
468 dev
->tuner
= TUNER_RTL2832_E4000
;
469 dev
->tuner_name
= "E4000";
473 /* check TDA18272 ID register; reg=00 val=c760 */
474 ret
= rtl28xxu_ctrl_msg(d
, &req_tda18272
);
475 if (ret
== 0 && (buf
[0] == 0xc7 || buf
[1] == 0x60)) {
476 dev
->tuner
= TUNER_RTL2832_TDA18272
;
477 dev
->tuner_name
= "TDA18272";
481 /* check R820T ID register; reg=00 val=69 */
482 ret
= rtl28xxu_ctrl_msg(d
, &req_r820t
);
483 if (ret
== 0 && buf
[0] == 0x69) {
484 dev
->tuner
= TUNER_RTL2832_R820T
;
485 dev
->tuner_name
= "R820T";
489 /* check R828D ID register; reg=00 val=69 */
490 ret
= rtl28xxu_ctrl_msg(d
, &req_r828d
);
491 if (ret
== 0 && buf
[0] == 0x69) {
492 dev
->tuner
= TUNER_RTL2832_R828D
;
493 dev
->tuner_name
= "R828D";
497 /* GPIO0 and GPIO5 to reset Si2157/Si2168 tuner and demod */
498 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_VAL
, 0x00, 0x21);
502 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_EN
, 0x00, 0x21);
508 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_VAL
, 0x21, 0x21);
512 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_EN
, 0x21, 0x21);
518 /* check Si2157 ID register; reg=c0 val=80 */
519 ret
= rtl28xxu_ctrl_msg(d
, &req_si2157
);
520 if (ret
== 0 && ((buf
[0] & 0x80) == 0x80)) {
521 dev
->tuner
= TUNER_RTL2832_SI2157
;
522 dev
->tuner_name
= "SI2157";
527 dev_dbg(&d
->intf
->dev
, "tuner=%s\n", dev
->tuner_name
);
529 /* probe slave demod */
530 if (dev
->tuner
== TUNER_RTL2832_R828D
) {
531 /* power off slave demod on GPIO0 to reset CXD2837ER */
532 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_VAL
, 0x00, 0x01);
536 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_EN
, 0x00, 0x01);
542 /* power on slave demod on GPIO0 */
543 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_VAL
, 0x01, 0x01);
547 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_DIR
, 0x00, 0x01);
551 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_EN
, 0x01, 0x01);
555 /* check slave answers */
556 ret
= rtl28xxu_ctrl_msg(d
, &req_mn88472
);
557 if (ret
== 0 && buf
[0] == 0x02) {
558 dev_dbg(&d
->intf
->dev
, "MN88472 found\n");
559 dev
->slave_demod
= SLAVE_DEMOD_MN88472
;
563 ret
= rtl28xxu_ctrl_msg(d
, &req_mn88473
);
564 if (ret
== 0 && buf
[0] == 0x03) {
565 dev_dbg(&d
->intf
->dev
, "MN88473 found\n");
566 dev
->slave_demod
= SLAVE_DEMOD_MN88473
;
570 ret
= rtl28xxu_ctrl_msg(d
, &req_cxd2837er
);
571 if (ret
== 0 && buf
[0] == 0xb1) {
572 dev_dbg(&d
->intf
->dev
, "CXD2837ER found\n");
573 dev
->slave_demod
= SLAVE_DEMOD_CXD2837ER
;
577 if (dev
->tuner
== TUNER_RTL2832_SI2157
) {
578 /* check Si2168 ID register; reg=c8 val=80 */
579 ret
= rtl28xxu_ctrl_msg(d
, &req_si2168
);
580 if (ret
== 0 && ((buf
[0] & 0x80) == 0x80)) {
581 dev_dbg(&d
->intf
->dev
, "Si2168 found\n");
582 dev
->slave_demod
= SLAVE_DEMOD_SI2168
;
588 /* close demod I2C gate */
589 ret
= rtl28xxu_ctrl_msg(d
, &req_gate_close
);
595 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
599 static int rtl28xxu_read_config(struct dvb_usb_device
*d
)
601 struct rtl28xxu_dev
*dev
= d_to_priv(d
);
603 if (dev
->chip_id
== CHIP_ID_RTL2831U
)
604 return rtl2831u_read_config(d
);
606 return rtl2832u_read_config(d
);
609 static int rtl28xxu_identify_state(struct dvb_usb_device
*d
, const char **name
)
611 struct rtl28xxu_dev
*dev
= d_to_priv(d
);
613 struct rtl28xxu_req req_demod_i2c
= {0x0020, CMD_I2C_DA_RD
, 0, NULL
};
615 dev_dbg(&d
->intf
->dev
, "\n");
618 * Detect chip type using I2C command that is not supported
621 ret
= rtl28xxu_ctrl_msg(d
, &req_demod_i2c
);
623 dev
->chip_id
= CHIP_ID_RTL2831U
;
624 } else if (ret
== 0) {
625 dev
->chip_id
= CHIP_ID_RTL2832U
;
627 dev_err(&d
->intf
->dev
, "chip type detection failed %d\n", ret
);
630 dev_dbg(&d
->intf
->dev
, "chip_id=%u\n", dev
->chip_id
);
632 /* Retry failed I2C messages */
633 d
->i2c_adap
.retries
= 3;
634 d
->i2c_adap
.timeout
= msecs_to_jiffies(10);
638 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
642 static const struct rtl2830_platform_data rtl2830_mt2060_platform_data
= {
647 .agc_targ_val
= 0x2d,
651 static const struct rtl2830_platform_data rtl2830_qt1010_platform_data
= {
656 .agc_targ_val
= 0x2d,
659 static const struct rtl2830_platform_data rtl2830_mxl5005s_platform_data
= {
664 .agc_targ_val
= 0x3e,
667 static int rtl2831u_frontend_attach(struct dvb_usb_adapter
*adap
)
669 struct dvb_usb_device
*d
= adap_to_d(adap
);
670 struct rtl28xxu_dev
*dev
= d_to_priv(d
);
671 struct rtl2830_platform_data
*pdata
= &dev
->rtl2830_platform_data
;
672 struct i2c_board_info board_info
;
673 struct i2c_client
*client
;
676 dev_dbg(&d
->intf
->dev
, "\n");
678 switch (dev
->tuner
) {
679 case TUNER_RTL2830_QT1010
:
680 *pdata
= rtl2830_qt1010_platform_data
;
682 case TUNER_RTL2830_MT2060
:
683 *pdata
= rtl2830_mt2060_platform_data
;
685 case TUNER_RTL2830_MXL5005S
:
686 *pdata
= rtl2830_mxl5005s_platform_data
;
689 dev_err(&d
->intf
->dev
, "unknown tuner %s\n", dev
->tuner_name
);
694 /* attach demodulator */
695 memset(&board_info
, 0, sizeof(board_info
));
696 strscpy(board_info
.type
, "rtl2830", I2C_NAME_SIZE
);
697 board_info
.addr
= 0x10;
698 board_info
.platform_data
= pdata
;
699 request_module("%s", board_info
.type
);
700 client
= i2c_new_client_device(&d
->i2c_adap
, &board_info
);
701 if (!i2c_client_has_driver(client
)) {
706 if (!try_module_get(client
->dev
.driver
->owner
)) {
707 i2c_unregister_device(client
);
712 adap
->fe
[0] = pdata
->get_dvb_frontend(client
);
713 dev
->demod_i2c_adapter
= pdata
->get_i2c_adapter(client
);
715 dev
->i2c_client_demod
= client
;
719 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
723 static const struct rtl2832_platform_data rtl2832_fc2580_platform_data
= {
725 .tuner
= TUNER_RTL2832_FC2580
,
728 static const struct rtl2832_platform_data rtl2832_fc0012_platform_data
= {
730 .tuner
= TUNER_RTL2832_FC0012
733 static const struct rtl2832_platform_data rtl2832_fc0013_platform_data
= {
735 .tuner
= TUNER_RTL2832_FC0013
738 static const struct rtl2832_platform_data rtl2832_tua9001_platform_data
= {
740 .tuner
= TUNER_RTL2832_TUA9001
,
743 static const struct rtl2832_platform_data rtl2832_e4000_platform_data
= {
745 .tuner
= TUNER_RTL2832_E4000
,
748 static const struct rtl2832_platform_data rtl2832_r820t_platform_data
= {
750 .tuner
= TUNER_RTL2832_R820T
,
753 static const struct rtl2832_platform_data rtl2832_si2157_platform_data
= {
755 .tuner
= TUNER_RTL2832_SI2157
,
758 static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device
*d
,
764 dev_dbg(&d
->intf
->dev
, "cmd=%d arg=%d\n", cmd
, arg
);
767 case FC_FE_CALLBACK_VHF_ENABLE
:
768 /* set output values */
769 ret
= rtl28xxu_rd_reg(d
, SYS_GPIO_OUT_VAL
, &val
);
774 val
&= 0xbf; /* set GPIO6 low */
776 val
|= 0x40; /* set GPIO6 high */
779 ret
= rtl28xxu_wr_reg(d
, SYS_GPIO_OUT_VAL
, val
);
789 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
793 static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device
*d
,
799 dev_dbg(&d
->intf
->dev
, "cmd=%d arg=%d\n", cmd
, arg
);
802 * CEN always enabled by hardware wiring
808 case TUA9001_CMD_RESETN
:
814 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_VAL
, val
, 0x10);
818 case TUA9001_CMD_RXEN
:
824 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_VAL
, val
, 0x02);
832 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
836 static int rtl2832u_frontend_callback(void *adapter_priv
, int component
,
839 struct i2c_adapter
*adapter
= adapter_priv
;
840 struct device
*parent
= adapter
->dev
.parent
;
841 struct i2c_adapter
*parent_adapter
;
842 struct dvb_usb_device
*d
;
843 struct rtl28xxu_dev
*dev
;
846 * All tuners are connected to demod muxed I2C adapter. We have to
847 * resolve its parent adapter in order to get handle for this driver
848 * private data. That is a bit hackish solution, GPIO or direct driver
849 * callback would be better...
851 if (parent
!= NULL
&& parent
->type
== &i2c_adapter_type
)
852 parent_adapter
= to_i2c_adapter(parent
);
856 d
= i2c_get_adapdata(parent_adapter
);
859 dev_dbg(&d
->intf
->dev
, "component=%d cmd=%d arg=%d\n",
860 component
, cmd
, arg
);
863 case DVB_FRONTEND_COMPONENT_TUNER
:
864 switch (dev
->tuner
) {
865 case TUNER_RTL2832_FC0012
:
866 return rtl2832u_fc0012_tuner_callback(d
, cmd
, arg
);
867 case TUNER_RTL2832_TUA9001
:
868 return rtl2832u_tua9001_tuner_callback(d
, cmd
, arg
);
875 static int rtl2832u_frontend_attach(struct dvb_usb_adapter
*adap
)
877 struct dvb_usb_device
*d
= adap_to_d(adap
);
878 struct rtl28xxu_dev
*dev
= d_to_priv(d
);
879 struct rtl2832_platform_data
*pdata
= &dev
->rtl2832_platform_data
;
880 struct i2c_board_info board_info
;
881 struct i2c_client
*client
;
884 dev_dbg(&d
->intf
->dev
, "\n");
886 switch (dev
->tuner
) {
887 case TUNER_RTL2832_FC0012
:
888 *pdata
= rtl2832_fc0012_platform_data
;
890 case TUNER_RTL2832_FC0013
:
891 *pdata
= rtl2832_fc0013_platform_data
;
893 case TUNER_RTL2832_FC2580
:
894 *pdata
= rtl2832_fc2580_platform_data
;
896 case TUNER_RTL2832_TUA9001
:
897 *pdata
= rtl2832_tua9001_platform_data
;
899 case TUNER_RTL2832_E4000
:
900 *pdata
= rtl2832_e4000_platform_data
;
902 case TUNER_RTL2832_R820T
:
903 case TUNER_RTL2832_R828D
:
904 *pdata
= rtl2832_r820t_platform_data
;
906 case TUNER_RTL2832_SI2157
:
907 *pdata
= rtl2832_si2157_platform_data
;
910 dev_err(&d
->intf
->dev
, "unknown tuner %s\n", dev
->tuner_name
);
915 /* attach demodulator */
916 memset(&board_info
, 0, sizeof(board_info
));
917 strscpy(board_info
.type
, "rtl2832", I2C_NAME_SIZE
);
918 board_info
.addr
= 0x10;
919 board_info
.platform_data
= pdata
;
920 request_module("%s", board_info
.type
);
921 client
= i2c_new_client_device(&d
->i2c_adap
, &board_info
);
922 if (!i2c_client_has_driver(client
)) {
927 if (!try_module_get(client
->dev
.driver
->owner
)) {
928 i2c_unregister_device(client
);
933 adap
->fe
[0] = pdata
->get_dvb_frontend(client
);
934 dev
->demod_i2c_adapter
= pdata
->get_i2c_adapter(client
);
936 dev
->i2c_client_demod
= client
;
938 /* set fe callback */
939 adap
->fe
[0]->callback
= rtl2832u_frontend_callback
;
941 if (dev
->slave_demod
) {
942 struct i2c_board_info info
= {};
945 * We continue on reduced mode, without DVB-T2/C, using master
946 * demod, when slave demod fails.
950 /* attach slave demodulator */
951 if (dev
->slave_demod
== SLAVE_DEMOD_MN88472
) {
952 struct mn88472_config mn88472_config
= {};
954 mn88472_config
.fe
= &adap
->fe
[1];
955 mn88472_config
.i2c_wr_max
= 22,
956 strscpy(info
.type
, "mn88472", I2C_NAME_SIZE
);
957 mn88472_config
.xtal
= 20500000;
958 mn88472_config
.ts_mode
= SERIAL_TS_MODE
;
959 mn88472_config
.ts_clock
= VARIABLE_TS_CLOCK
;
961 info
.platform_data
= &mn88472_config
;
962 request_module(info
.type
);
963 client
= i2c_new_client_device(&d
->i2c_adap
, &info
);
964 if (!i2c_client_has_driver(client
)) {
965 dev
->slave_demod
= SLAVE_DEMOD_NONE
;
966 goto err_slave_demod_failed
;
969 if (!try_module_get(client
->dev
.driver
->owner
)) {
970 i2c_unregister_device(client
);
971 dev
->slave_demod
= SLAVE_DEMOD_NONE
;
972 goto err_slave_demod_failed
;
975 dev
->i2c_client_slave_demod
= client
;
976 } else if (dev
->slave_demod
== SLAVE_DEMOD_MN88473
) {
977 struct mn88473_config mn88473_config
= {};
979 mn88473_config
.fe
= &adap
->fe
[1];
980 mn88473_config
.i2c_wr_max
= 22,
981 strscpy(info
.type
, "mn88473", I2C_NAME_SIZE
);
983 info
.platform_data
= &mn88473_config
;
984 request_module(info
.type
);
985 client
= i2c_new_client_device(&d
->i2c_adap
, &info
);
986 if (!i2c_client_has_driver(client
)) {
987 dev
->slave_demod
= SLAVE_DEMOD_NONE
;
988 goto err_slave_demod_failed
;
991 if (!try_module_get(client
->dev
.driver
->owner
)) {
992 i2c_unregister_device(client
);
993 dev
->slave_demod
= SLAVE_DEMOD_NONE
;
994 goto err_slave_demod_failed
;
997 dev
->i2c_client_slave_demod
= client
;
998 } else if (dev
->slave_demod
== SLAVE_DEMOD_CXD2837ER
) {
999 struct cxd2841er_config cxd2837er_config
= {};
1001 cxd2837er_config
.i2c_addr
= 0xd8;
1002 cxd2837er_config
.xtal
= SONY_XTAL_20500
;
1003 cxd2837er_config
.flags
= (CXD2841ER_AUTO_IFHZ
|
1004 CXD2841ER_NO_AGCNEG
| CXD2841ER_TSBITS
|
1005 CXD2841ER_EARLY_TUNE
| CXD2841ER_TS_SERIAL
);
1006 adap
->fe
[1] = dvb_attach(cxd2841er_attach_t_c
,
1010 dev
->slave_demod
= SLAVE_DEMOD_NONE
;
1011 goto err_slave_demod_failed
;
1013 adap
->fe
[1]->id
= 1;
1014 dev
->i2c_client_slave_demod
= NULL
;
1016 struct si2168_config si2168_config
= {};
1017 struct i2c_adapter
*adapter
;
1019 si2168_config
.i2c_adapter
= &adapter
;
1020 si2168_config
.fe
= &adap
->fe
[1];
1021 si2168_config
.ts_mode
= SI2168_TS_SERIAL
;
1022 si2168_config
.ts_clock_inv
= false;
1023 si2168_config
.ts_clock_gapped
= true;
1024 strscpy(info
.type
, "si2168", I2C_NAME_SIZE
);
1026 info
.platform_data
= &si2168_config
;
1027 request_module(info
.type
);
1028 client
= i2c_new_client_device(&d
->i2c_adap
, &info
);
1029 if (!i2c_client_has_driver(client
)) {
1030 dev
->slave_demod
= SLAVE_DEMOD_NONE
;
1031 goto err_slave_demod_failed
;
1034 if (!try_module_get(client
->dev
.driver
->owner
)) {
1035 i2c_unregister_device(client
);
1036 dev
->slave_demod
= SLAVE_DEMOD_NONE
;
1037 goto err_slave_demod_failed
;
1040 dev
->i2c_client_slave_demod
= client
;
1042 /* for Si2168 devices use only new I2C write method */
1043 dev
->new_i2c_write
= true;
1047 err_slave_demod_failed
:
1049 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
1053 static int rtl28xxu_frontend_attach(struct dvb_usb_adapter
*adap
)
1055 struct rtl28xxu_dev
*dev
= adap_to_priv(adap
);
1057 if (dev
->chip_id
== CHIP_ID_RTL2831U
)
1058 return rtl2831u_frontend_attach(adap
);
1060 return rtl2832u_frontend_attach(adap
);
1063 static int rtl28xxu_frontend_detach(struct dvb_usb_adapter
*adap
)
1065 struct dvb_usb_device
*d
= adap_to_d(adap
);
1066 struct rtl28xxu_dev
*dev
= d_to_priv(d
);
1067 struct i2c_client
*client
;
1069 dev_dbg(&d
->intf
->dev
, "\n");
1071 /* remove I2C slave demod */
1072 client
= dev
->i2c_client_slave_demod
;
1074 module_put(client
->dev
.driver
->owner
);
1075 i2c_unregister_device(client
);
1078 /* remove I2C demod */
1079 client
= dev
->i2c_client_demod
;
1081 module_put(client
->dev
.driver
->owner
);
1082 i2c_unregister_device(client
);
1088 static struct qt1010_config rtl28xxu_qt1010_config
= {
1089 .i2c_address
= 0x62, /* 0xc4 */
1092 static struct mt2060_config rtl28xxu_mt2060_config
= {
1093 .i2c_address
= 0x60, /* 0xc0 */
1097 static struct mxl5005s_config rtl28xxu_mxl5005s_config
= {
1098 .i2c_address
= 0x63, /* 0xc6 */
1099 .if_freq
= IF_FREQ_4570000HZ
,
1100 .xtal_freq
= CRYSTAL_FREQ_16000000HZ
,
1101 .agc_mode
= MXL_SINGLE_AGC
,
1102 .tracking_filter
= MXL_TF_C_H
,
1103 .rssi_enable
= MXL_RSSI_ENABLE
,
1104 .cap_select
= MXL_CAP_SEL_ENABLE
,
1105 .div_out
= MXL_DIV_OUT_4
,
1106 .clock_out
= MXL_CLOCK_OUT_DISABLE
,
1107 .output_load
= MXL5005S_IF_OUTPUT_LOAD_200_OHM
,
1108 .top
= MXL5005S_TOP_25P2
,
1109 .mod_mode
= MXL_DIGITAL_MODE
,
1110 .if_mode
= MXL_ZERO_IF
,
1111 .AgcMasterByte
= 0x00,
1114 static int rtl2831u_tuner_attach(struct dvb_usb_adapter
*adap
)
1117 struct dvb_usb_device
*d
= adap_to_d(adap
);
1118 struct rtl28xxu_dev
*dev
= d_to_priv(d
);
1119 struct dvb_frontend
*fe
;
1121 dev_dbg(&d
->intf
->dev
, "\n");
1123 switch (dev
->tuner
) {
1124 case TUNER_RTL2830_QT1010
:
1125 fe
= dvb_attach(qt1010_attach
, adap
->fe
[0],
1126 dev
->demod_i2c_adapter
,
1127 &rtl28xxu_qt1010_config
);
1129 case TUNER_RTL2830_MT2060
:
1130 fe
= dvb_attach(mt2060_attach
, adap
->fe
[0],
1131 dev
->demod_i2c_adapter
,
1132 &rtl28xxu_mt2060_config
, 1220);
1134 case TUNER_RTL2830_MXL5005S
:
1135 fe
= dvb_attach(mxl5005s_attach
, adap
->fe
[0],
1136 dev
->demod_i2c_adapter
,
1137 &rtl28xxu_mxl5005s_config
);
1141 dev_err(&d
->intf
->dev
, "unknown tuner %d\n", dev
->tuner
);
1151 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
1155 static const struct fc0012_config rtl2832u_fc0012_config
= {
1156 .i2c_address
= 0x63, /* 0xc6 >> 1 */
1157 .xtal_freq
= FC_XTAL_28_8_MHZ
,
1160 static const struct r820t_config rtl2832u_r820t_config
= {
1163 .max_i2c_msg_len
= 2,
1164 .rafael_chip
= CHIP_R820T
,
1167 static const struct r820t_config rtl2832u_r828d_config
= {
1170 .max_i2c_msg_len
= 2,
1171 .rafael_chip
= CHIP_R828D
,
1174 static int rtl2832u_tuner_attach(struct dvb_usb_adapter
*adap
)
1177 struct dvb_usb_device
*d
= adap_to_d(adap
);
1178 struct rtl28xxu_dev
*dev
= d_to_priv(d
);
1179 struct dvb_frontend
*fe
= NULL
;
1180 struct i2c_board_info info
;
1181 struct i2c_client
*client
;
1182 struct v4l2_subdev
*subdev
= NULL
;
1183 struct platform_device
*pdev
;
1184 struct rtl2832_sdr_platform_data pdata
;
1186 dev_dbg(&d
->intf
->dev
, "\n");
1188 memset(&info
, 0, sizeof(struct i2c_board_info
));
1189 memset(&pdata
, 0, sizeof(pdata
));
1191 switch (dev
->tuner
) {
1192 case TUNER_RTL2832_FC0012
:
1193 fe
= dvb_attach(fc0012_attach
, adap
->fe
[0],
1194 dev
->demod_i2c_adapter
, &rtl2832u_fc0012_config
);
1196 /* since fc0012 includs reading the signal strength delegate
1197 * that to the tuner driver */
1198 adap
->fe
[0]->ops
.read_signal_strength
=
1199 adap
->fe
[0]->ops
.tuner_ops
.get_rf_strength
;
1201 case TUNER_RTL2832_FC0013
:
1202 fe
= dvb_attach(fc0013_attach
, adap
->fe
[0],
1203 dev
->demod_i2c_adapter
, 0xc6>>1, 0, FC_XTAL_28_8_MHZ
);
1205 /* fc0013 also supports signal strength reading */
1206 adap
->fe
[0]->ops
.read_signal_strength
=
1207 adap
->fe
[0]->ops
.tuner_ops
.get_rf_strength
;
1209 case TUNER_RTL2832_E4000
: {
1210 struct e4000_config e4000_config
= {
1215 strscpy(info
.type
, "e4000", I2C_NAME_SIZE
);
1217 info
.platform_data
= &e4000_config
;
1219 request_module(info
.type
);
1220 client
= i2c_new_client_device(dev
->demod_i2c_adapter
,
1222 if (!i2c_client_has_driver(client
))
1225 if (!try_module_get(client
->dev
.driver
->owner
)) {
1226 i2c_unregister_device(client
);
1230 dev
->i2c_client_tuner
= client
;
1231 subdev
= i2c_get_clientdata(client
);
1234 case TUNER_RTL2832_FC2580
: {
1235 struct fc2580_platform_data fc2580_pdata
= {
1236 .dvb_frontend
= adap
->fe
[0],
1238 struct i2c_board_info board_info
= {};
1240 strscpy(board_info
.type
, "fc2580", I2C_NAME_SIZE
);
1241 board_info
.addr
= 0x56;
1242 board_info
.platform_data
= &fc2580_pdata
;
1243 request_module("fc2580");
1244 client
= i2c_new_client_device(dev
->demod_i2c_adapter
,
1246 if (!i2c_client_has_driver(client
))
1248 if (!try_module_get(client
->dev
.driver
->owner
)) {
1249 i2c_unregister_device(client
);
1252 dev
->i2c_client_tuner
= client
;
1253 subdev
= fc2580_pdata
.get_v4l2_subdev(client
);
1256 case TUNER_RTL2832_TUA9001
: {
1257 struct tua9001_platform_data tua9001_pdata
= {
1258 .dvb_frontend
= adap
->fe
[0],
1260 struct i2c_board_info board_info
= {};
1262 /* enable GPIO1 and GPIO4 as output */
1263 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_DIR
, 0x00, 0x12);
1267 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_EN
, 0x12, 0x12);
1271 strscpy(board_info
.type
, "tua9001", I2C_NAME_SIZE
);
1272 board_info
.addr
= 0x60;
1273 board_info
.platform_data
= &tua9001_pdata
;
1274 request_module("tua9001");
1275 client
= i2c_new_client_device(dev
->demod_i2c_adapter
,
1277 if (!i2c_client_has_driver(client
))
1279 if (!try_module_get(client
->dev
.driver
->owner
)) {
1280 i2c_unregister_device(client
);
1283 dev
->i2c_client_tuner
= client
;
1286 case TUNER_RTL2832_R820T
:
1287 fe
= dvb_attach(r820t_attach
, adap
->fe
[0],
1288 dev
->demod_i2c_adapter
,
1289 &rtl2832u_r820t_config
);
1291 /* Use tuner to get the signal strength */
1292 adap
->fe
[0]->ops
.read_signal_strength
=
1293 adap
->fe
[0]->ops
.tuner_ops
.get_rf_strength
;
1295 case TUNER_RTL2832_R828D
:
1296 fe
= dvb_attach(r820t_attach
, adap
->fe
[0],
1297 dev
->demod_i2c_adapter
,
1298 &rtl2832u_r828d_config
);
1299 adap
->fe
[0]->ops
.read_signal_strength
=
1300 adap
->fe
[0]->ops
.tuner_ops
.get_rf_strength
;
1303 fe
= dvb_attach(r820t_attach
, adap
->fe
[1],
1304 dev
->demod_i2c_adapter
,
1305 &rtl2832u_r828d_config
);
1306 adap
->fe
[1]->ops
.read_signal_strength
=
1307 adap
->fe
[1]->ops
.tuner_ops
.get_rf_strength
;
1310 case TUNER_RTL2832_SI2157
: {
1311 struct si2157_config si2157_config
= {
1317 strscpy(info
.type
, "si2157", I2C_NAME_SIZE
);
1319 info
.platform_data
= &si2157_config
;
1320 request_module(info
.type
);
1321 client
= i2c_new_client_device(&d
->i2c_adap
, &info
);
1322 if (!i2c_client_has_driver(client
))
1325 if (!try_module_get(client
->dev
.driver
->owner
)) {
1326 i2c_unregister_device(client
);
1330 dev
->i2c_client_tuner
= client
;
1331 subdev
= i2c_get_clientdata(client
);
1333 /* copy tuner ops for 2nd FE as tuner is shared */
1335 adap
->fe
[1]->tuner_priv
=
1336 adap
->fe
[0]->tuner_priv
;
1337 memcpy(&adap
->fe
[1]->ops
.tuner_ops
,
1338 &adap
->fe
[0]->ops
.tuner_ops
,
1339 sizeof(struct dvb_tuner_ops
));
1344 dev_err(&d
->intf
->dev
, "unknown tuner %d\n", dev
->tuner
);
1346 if (fe
== NULL
&& dev
->i2c_client_tuner
== NULL
) {
1352 switch (dev
->tuner
) {
1353 case TUNER_RTL2832_FC2580
:
1354 case TUNER_RTL2832_FC0012
:
1355 case TUNER_RTL2832_FC0013
:
1356 case TUNER_RTL2832_E4000
:
1357 case TUNER_RTL2832_R820T
:
1358 case TUNER_RTL2832_R828D
:
1359 pdata
.clk
= dev
->rtl2832_platform_data
.clk
;
1360 pdata
.tuner
= dev
->tuner
;
1361 pdata
.regmap
= dev
->rtl2832_platform_data
.regmap
;
1362 pdata
.dvb_frontend
= adap
->fe
[0];
1363 pdata
.dvb_usb_device
= d
;
1364 pdata
.v4l2_subdev
= subdev
;
1366 request_module("%s", "rtl2832_sdr");
1367 pdev
= platform_device_register_data(&d
->intf
->dev
,
1369 PLATFORM_DEVID_AUTO
,
1370 &pdata
, sizeof(pdata
));
1371 if (IS_ERR(pdev
) || pdev
->dev
.driver
== NULL
)
1373 dev
->platform_device_sdr
= pdev
;
1376 dev_dbg(&d
->intf
->dev
, "no SDR for tuner=%d\n", dev
->tuner
);
1381 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
1385 static int rtl28xxu_tuner_attach(struct dvb_usb_adapter
*adap
)
1387 struct rtl28xxu_dev
*dev
= adap_to_priv(adap
);
1389 if (dev
->chip_id
== CHIP_ID_RTL2831U
)
1390 return rtl2831u_tuner_attach(adap
);
1392 return rtl2832u_tuner_attach(adap
);
1395 static int rtl28xxu_tuner_detach(struct dvb_usb_adapter
*adap
)
1397 struct dvb_usb_device
*d
= adap_to_d(adap
);
1398 struct rtl28xxu_dev
*dev
= d_to_priv(d
);
1399 struct i2c_client
*client
;
1400 struct platform_device
*pdev
;
1402 dev_dbg(&d
->intf
->dev
, "\n");
1404 /* remove platform SDR */
1405 pdev
= dev
->platform_device_sdr
;
1407 platform_device_unregister(pdev
);
1409 /* remove I2C tuner */
1410 client
= dev
->i2c_client_tuner
;
1412 module_put(client
->dev
.driver
->owner
);
1413 i2c_unregister_device(client
);
1419 static int rtl28xxu_init(struct dvb_usb_device
*d
)
1424 dev_dbg(&d
->intf
->dev
, "\n");
1426 /* init USB endpoints */
1427 ret
= rtl28xxu_rd_reg(d
, USB_SYSCTL_0
, &val
);
1431 /* enable DMA and Full Packet Mode*/
1433 ret
= rtl28xxu_wr_reg(d
, USB_SYSCTL_0
, val
);
1437 /* set EPA maximum packet size to 0x0200 */
1438 ret
= rtl28xxu_wr_regs(d
, USB_EPA_MAXPKT
, "\x00\x02\x00\x00", 4);
1442 /* change EPA FIFO length */
1443 ret
= rtl28xxu_wr_regs(d
, USB_EPA_FIFO_CFG
, "\x14\x00\x00\x00", 4);
1449 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
1453 static int rtl2831u_power_ctrl(struct dvb_usb_device
*d
, int onoff
)
1456 u8 gpio
, sys0
, epa_ctl
[2];
1458 dev_dbg(&d
->intf
->dev
, "onoff=%d\n", onoff
);
1461 ret
= rtl28xxu_rd_reg(d
, SYS_SYS0
, &sys0
);
1465 /* tuner power, read GPIOs */
1466 ret
= rtl28xxu_rd_reg(d
, SYS_GPIO_OUT_VAL
, &gpio
);
1470 dev_dbg(&d
->intf
->dev
, "RD SYS0=%02x GPIO_OUT_VAL=%02x\n", sys0
, gpio
);
1473 gpio
|= 0x01; /* GPIO0 = 1 */
1474 gpio
&= (~0x10); /* GPIO4 = 0 */
1475 gpio
|= 0x04; /* GPIO2 = 1, LED on */
1478 epa_ctl
[0] = 0x00; /* clear stall */
1479 epa_ctl
[1] = 0x00; /* clear reset */
1481 gpio
&= (~0x01); /* GPIO0 = 0 */
1482 gpio
|= 0x10; /* GPIO4 = 1 */
1483 gpio
&= (~0x04); /* GPIO2 = 1, LED off */
1484 sys0
= sys0
& (~0xc0);
1485 epa_ctl
[0] = 0x10; /* set stall */
1486 epa_ctl
[1] = 0x02; /* set reset */
1489 dev_dbg(&d
->intf
->dev
, "WR SYS0=%02x GPIO_OUT_VAL=%02x\n", sys0
, gpio
);
1492 ret
= rtl28xxu_wr_reg(d
, SYS_SYS0
, sys0
);
1496 /* tuner power, write GPIOs */
1497 ret
= rtl28xxu_wr_reg(d
, SYS_GPIO_OUT_VAL
, gpio
);
1501 /* streaming EP: stall & reset */
1502 ret
= rtl28xxu_wr_regs(d
, USB_EPA_CTL
, epa_ctl
, 2);
1507 usb_clear_halt(d
->udev
, usb_rcvbulkpipe(d
->udev
, 0x81));
1511 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
1515 static int rtl2832u_power_ctrl(struct dvb_usb_device
*d
, int onoff
)
1519 dev_dbg(&d
->intf
->dev
, "onoff=%d\n", onoff
);
1522 /* GPIO3=1, GPIO4=0 */
1523 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_VAL
, 0x08, 0x18);
1528 ret
= rtl28xxu_wr_reg_mask(d
, SYS_DEMOD_CTL1
, 0x00, 0x10);
1533 ret
= rtl28xxu_wr_reg_mask(d
, SYS_DEMOD_CTL
, 0x80, 0x80);
1538 ret
= rtl28xxu_wr_reg_mask(d
, SYS_DEMOD_CTL
, 0x20, 0x20);
1542 /* streaming EP: clear stall & reset */
1543 ret
= rtl28xxu_wr_regs(d
, USB_EPA_CTL
, "\x00\x00", 2);
1547 ret
= usb_clear_halt(d
->udev
, usb_rcvbulkpipe(d
->udev
, 0x81));
1552 ret
= rtl28xxu_wr_reg_mask(d
, SYS_GPIO_OUT_VAL
, 0x10, 0x10);
1557 ret
= rtl28xxu_wr_reg_mask(d
, SYS_DEMOD_CTL
, 0x00, 0x80);
1561 /* streaming EP: set stall & reset */
1562 ret
= rtl28xxu_wr_regs(d
, USB_EPA_CTL
, "\x10\x02", 2);
1569 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
1573 static int rtl28xxu_power_ctrl(struct dvb_usb_device
*d
, int onoff
)
1575 struct rtl28xxu_dev
*dev
= d_to_priv(d
);
1577 if (dev
->chip_id
== CHIP_ID_RTL2831U
)
1578 return rtl2831u_power_ctrl(d
, onoff
);
1580 return rtl2832u_power_ctrl(d
, onoff
);
1583 static int rtl28xxu_frontend_ctrl(struct dvb_frontend
*fe
, int onoff
)
1585 struct dvb_usb_device
*d
= fe_to_d(fe
);
1586 struct rtl28xxu_dev
*dev
= fe_to_priv(fe
);
1587 struct rtl2832_platform_data
*pdata
= &dev
->rtl2832_platform_data
;
1591 dev_dbg(&d
->intf
->dev
, "fe=%d onoff=%d\n", fe
->id
, onoff
);
1593 if (dev
->chip_id
== CHIP_ID_RTL2831U
)
1597 /* control internal demod ADC */
1599 val
= 0x48; /* enable ADC */
1601 val
= 0x00; /* disable ADC */
1603 ret
= rtl28xxu_wr_reg_mask(d
, SYS_DEMOD_CTL
, val
, 0x48);
1606 } else if (fe
->id
== 1) {
1607 /* bypass slave demod TS through master demod */
1608 ret
= pdata
->slave_ts_ctrl(dev
->i2c_client_demod
, onoff
);
1615 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
1619 #if IS_ENABLED(CONFIG_RC_CORE)
1620 static int rtl2831u_rc_query(struct dvb_usb_device
*d
)
1623 struct rtl28xxu_dev
*dev
= d
->priv
;
1626 static const struct rtl28xxu_reg_val rc_nec_tab
[] = {
1643 /* init remote controller */
1644 if (!dev
->rc_active
) {
1645 for (i
= 0; i
< ARRAY_SIZE(rc_nec_tab
); i
++) {
1646 ret
= rtl28xxu_wr_reg(d
, rc_nec_tab
[i
].reg
,
1651 dev
->rc_active
= true;
1654 ret
= rtl28xxu_rd_regs(d
, SYS_IRRC_RP
, buf
, 5);
1658 if (buf
[4] & 0x01) {
1659 enum rc_proto proto
;
1661 if (buf
[2] == (u8
) ~buf
[3]) {
1662 if (buf
[0] == (u8
) ~buf
[1]) {
1663 /* NEC standard (16 bit) */
1664 rc_code
= RC_SCANCODE_NEC(buf
[0], buf
[2]);
1665 proto
= RC_PROTO_NEC
;
1667 /* NEC extended (24 bit) */
1668 rc_code
= RC_SCANCODE_NECX(buf
[0] << 8 | buf
[1],
1670 proto
= RC_PROTO_NECX
;
1673 /* NEC full (32 bit) */
1674 rc_code
= RC_SCANCODE_NEC32(buf
[0] << 24 | buf
[1] << 16 |
1675 buf
[2] << 8 | buf
[3]);
1676 proto
= RC_PROTO_NEC32
;
1679 rc_keydown(d
->rc_dev
, proto
, rc_code
, 0);
1681 ret
= rtl28xxu_wr_reg(d
, SYS_IRRC_SR
, 1);
1685 /* repeated intentionally to avoid extra keypress */
1686 ret
= rtl28xxu_wr_reg(d
, SYS_IRRC_SR
, 1);
1693 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
1697 static int rtl2831u_get_rc_config(struct dvb_usb_device
*d
,
1698 struct dvb_usb_rc
*rc
)
1700 rc
->map_name
= RC_MAP_EMPTY
;
1701 rc
->allowed_protos
= RC_PROTO_BIT_NEC
| RC_PROTO_BIT_NECX
|
1703 rc
->query
= rtl2831u_rc_query
;
1709 static int rtl2832u_rc_query(struct dvb_usb_device
*d
)
1712 struct rtl28xxu_dev
*dev
= d
->priv
;
1713 struct ir_raw_event ev
= {};
1715 static const struct rtl28xxu_reg_val_mask refresh_tab
[] = {
1716 {IR_RX_IF
, 0x03, 0xff},
1717 {IR_RX_BUF_CTRL
, 0x80, 0xff},
1718 {IR_RX_CTRL
, 0x80, 0xff},
1721 /* init remote controller */
1722 if (!dev
->rc_active
) {
1723 static const struct rtl28xxu_reg_val_mask init_tab
[] = {
1724 {SYS_DEMOD_CTL1
, 0x00, 0x04},
1725 {SYS_DEMOD_CTL1
, 0x00, 0x08},
1726 {USB_CTRL
, 0x20, 0x20},
1727 {SYS_GPIO_DIR
, 0x00, 0x08},
1728 {SYS_GPIO_OUT_EN
, 0x08, 0x08},
1729 {SYS_GPIO_OUT_VAL
, 0x08, 0x08},
1730 {IR_MAX_DURATION0
, 0xd0, 0xff},
1731 {IR_MAX_DURATION1
, 0x07, 0xff},
1732 {IR_IDLE_LEN0
, 0xc0, 0xff},
1733 {IR_IDLE_LEN1
, 0x00, 0xff},
1734 {IR_GLITCH_LEN
, 0x03, 0xff},
1735 {IR_RX_CLK
, 0x09, 0xff},
1736 {IR_RX_CFG
, 0x1c, 0xff},
1737 {IR_MAX_H_TOL_LEN
, 0x1e, 0xff},
1738 {IR_MAX_L_TOL_LEN
, 0x1e, 0xff},
1739 {IR_RX_CTRL
, 0x80, 0xff},
1742 for (i
= 0; i
< ARRAY_SIZE(init_tab
); i
++) {
1743 ret
= rtl28xxu_wr_reg_mask(d
, init_tab
[i
].reg
,
1744 init_tab
[i
].val
, init_tab
[i
].mask
);
1749 dev
->rc_active
= true;
1752 ret
= rtl28xxu_rd_reg(d
, IR_RX_IF
, &buf
[0]);
1759 ret
= rtl28xxu_rd_reg(d
, IR_RX_BC
, &buf
[0]);
1760 if (ret
|| buf
[0] > sizeof(buf
))
1765 /* read raw code from hw */
1766 ret
= rtl28xxu_rd_regs(d
, IR_RX_BUF
, buf
, len
);
1770 /* let hw receive new code */
1771 for (i
= 0; i
< ARRAY_SIZE(refresh_tab
); i
++) {
1772 ret
= rtl28xxu_wr_reg_mask(d
, refresh_tab
[i
].reg
,
1773 refresh_tab
[i
].val
, refresh_tab
[i
].mask
);
1778 /* pass data to Kernel IR decoder */
1779 for (i
= 0; i
< len
; i
++) {
1780 ev
.pulse
= buf
[i
] >> 7;
1781 ev
.duration
= 50800 * (buf
[i
] & 0x7f);
1782 ir_raw_event_store_with_filter(d
->rc_dev
, &ev
);
1785 /* 'flush'Â ir_raw_event_store_with_filter() */
1786 ir_raw_event_handle(d
->rc_dev
);
1790 dev_dbg(&d
->intf
->dev
, "failed=%d\n", ret
);
1794 static int rtl2832u_get_rc_config(struct dvb_usb_device
*d
,
1795 struct dvb_usb_rc
*rc
)
1797 /* disable IR interrupts in order to avoid SDR sample loss */
1798 if (rtl28xxu_disable_rc
)
1799 return rtl28xxu_wr_reg(d
, IR_RX_IE
, 0x00);
1801 /* load empty to enable rc */
1803 rc
->map_name
= RC_MAP_EMPTY
;
1804 rc
->allowed_protos
= RC_PROTO_BIT_ALL_IR_DECODER
;
1805 rc
->driver_type
= RC_DRIVER_IR_RAW
;
1806 rc
->query
= rtl2832u_rc_query
;
1808 /* we program idle len to 0xc0, set timeout to one less */
1809 rc
->timeout
= 0xbf * 50800;
1814 static int rtl28xxu_get_rc_config(struct dvb_usb_device
*d
,
1815 struct dvb_usb_rc
*rc
)
1817 struct rtl28xxu_dev
*dev
= d_to_priv(d
);
1819 if (dev
->chip_id
== CHIP_ID_RTL2831U
)
1820 return rtl2831u_get_rc_config(d
, rc
);
1822 return rtl2832u_get_rc_config(d
, rc
);
1825 #define rtl28xxu_get_rc_config NULL
1828 static int rtl28xxu_pid_filter_ctrl(struct dvb_usb_adapter
*adap
, int onoff
)
1830 struct rtl28xxu_dev
*dev
= adap_to_priv(adap
);
1832 if (dev
->chip_id
== CHIP_ID_RTL2831U
) {
1833 struct rtl2830_platform_data
*pdata
= &dev
->rtl2830_platform_data
;
1835 return pdata
->pid_filter_ctrl(adap
->fe
[0], onoff
);
1837 struct rtl2832_platform_data
*pdata
= &dev
->rtl2832_platform_data
;
1839 return pdata
->pid_filter_ctrl(adap
->fe
[0], onoff
);
1843 static int rtl28xxu_pid_filter(struct dvb_usb_adapter
*adap
, int index
,
1846 struct rtl28xxu_dev
*dev
= adap_to_priv(adap
);
1848 if (dev
->chip_id
== CHIP_ID_RTL2831U
) {
1849 struct rtl2830_platform_data
*pdata
= &dev
->rtl2830_platform_data
;
1851 return pdata
->pid_filter(adap
->fe
[0], index
, pid
, onoff
);
1853 struct rtl2832_platform_data
*pdata
= &dev
->rtl2832_platform_data
;
1855 return pdata
->pid_filter(adap
->fe
[0], index
, pid
, onoff
);
1859 static const struct dvb_usb_device_properties rtl28xxu_props
= {
1860 .driver_name
= KBUILD_MODNAME
,
1861 .owner
= THIS_MODULE
,
1862 .adapter_nr
= adapter_nr
,
1863 .size_of_priv
= sizeof(struct rtl28xxu_dev
),
1865 .identify_state
= rtl28xxu_identify_state
,
1866 .power_ctrl
= rtl28xxu_power_ctrl
,
1867 .frontend_ctrl
= rtl28xxu_frontend_ctrl
,
1868 .i2c_algo
= &rtl28xxu_i2c_algo
,
1869 .read_config
= rtl28xxu_read_config
,
1870 .frontend_attach
= rtl28xxu_frontend_attach
,
1871 .frontend_detach
= rtl28xxu_frontend_detach
,
1872 .tuner_attach
= rtl28xxu_tuner_attach
,
1873 .tuner_detach
= rtl28xxu_tuner_detach
,
1874 .init
= rtl28xxu_init
,
1875 .get_rc_config
= rtl28xxu_get_rc_config
,
1880 .caps
= DVB_USB_ADAP_HAS_PID_FILTER
|
1881 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF
,
1883 .pid_filter_count
= 32,
1884 .pid_filter_ctrl
= rtl28xxu_pid_filter_ctrl
,
1885 .pid_filter
= rtl28xxu_pid_filter
,
1887 .stream
= DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
1892 static const struct usb_device_id rtl28xxu_id_table
[] = {
1893 /* RTL2831U devices: */
1894 { DVB_USB_DEVICE(USB_VID_REALTEK
, USB_PID_REALTEK_RTL2831U
,
1895 &rtl28xxu_props
, "Realtek RTL2831U reference design", NULL
) },
1896 { DVB_USB_DEVICE(USB_VID_WIDEVIEW
, USB_PID_FREECOM_DVBT
,
1897 &rtl28xxu_props
, "Freecom USB2.0 DVB-T", NULL
) },
1898 { DVB_USB_DEVICE(USB_VID_WIDEVIEW
, USB_PID_FREECOM_DVBT_2
,
1899 &rtl28xxu_props
, "Freecom USB2.0 DVB-T", NULL
) },
1901 /* RTL2832U devices: */
1902 { DVB_USB_DEVICE(USB_VID_REALTEK
, 0x2832,
1903 &rtl28xxu_props
, "Realtek RTL2832U reference design", NULL
) },
1904 { DVB_USB_DEVICE(USB_VID_REALTEK
, 0x2838,
1905 &rtl28xxu_props
, "Realtek RTL2832U reference design", NULL
) },
1906 { DVB_USB_DEVICE(USB_VID_TERRATEC
, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1
,
1907 &rtl28xxu_props
, "TerraTec Cinergy T Stick Black", RC_MAP_TERRATEC_SLIM
) },
1908 { DVB_USB_DEVICE(USB_VID_GTEK
, USB_PID_DELOCK_USB2_DVBT
,
1909 &rtl28xxu_props
, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL
) },
1910 { DVB_USB_DEVICE(USB_VID_TERRATEC
, USB_PID_NOXON_DAB_STICK
,
1911 &rtl28xxu_props
, "TerraTec NOXON DAB Stick", NULL
) },
1912 { DVB_USB_DEVICE(USB_VID_TERRATEC
, USB_PID_NOXON_DAB_STICK_REV2
,
1913 &rtl28xxu_props
, "TerraTec NOXON DAB Stick (rev 2)", NULL
) },
1914 { DVB_USB_DEVICE(USB_VID_TERRATEC
, USB_PID_NOXON_DAB_STICK_REV3
,
1915 &rtl28xxu_props
, "TerraTec NOXON DAB Stick (rev 3)", NULL
) },
1916 { DVB_USB_DEVICE(USB_VID_GTEK
, USB_PID_TREKSTOR_TERRES_2_0
,
1917 &rtl28xxu_props
, "Trekstor DVB-T Stick Terres 2.0", NULL
) },
1918 { DVB_USB_DEVICE(USB_VID_DEXATEK
, 0x1101,
1919 &rtl28xxu_props
, "Dexatek DK DVB-T Dongle", NULL
) },
1920 { DVB_USB_DEVICE(USB_VID_LEADTEK
, 0x6680,
1921 &rtl28xxu_props
, "DigitalNow Quad DVB-T Receiver", NULL
) },
1922 { DVB_USB_DEVICE(USB_VID_LEADTEK
, USB_PID_WINFAST_DTV_DONGLE_MINID
,
1923 &rtl28xxu_props
, "Leadtek Winfast DTV Dongle Mini D", NULL
) },
1924 { DVB_USB_DEVICE(USB_VID_LEADTEK
, USB_PID_WINFAST_DTV2000DS_PLUS
,
1925 &rtl28xxu_props
, "Leadtek WinFast DTV2000DS Plus", RC_MAP_LEADTEK_Y04G0051
) },
1926 { DVB_USB_DEVICE(USB_VID_TERRATEC
, 0x00d3,
1927 &rtl28xxu_props
, "TerraTec Cinergy T Stick RC (Rev. 3)", NULL
) },
1928 { DVB_USB_DEVICE(USB_VID_DEXATEK
, 0x1102,
1929 &rtl28xxu_props
, "Dexatek DK mini DVB-T Dongle", NULL
) },
1930 { DVB_USB_DEVICE(USB_VID_TERRATEC
, 0x00d7,
1931 &rtl28xxu_props
, "TerraTec Cinergy T Stick+", NULL
) },
1932 { DVB_USB_DEVICE(USB_VID_KWORLD_2
, 0xd3a8,
1933 &rtl28xxu_props
, "ASUS My Cinema-U3100Mini Plus V2", NULL
) },
1934 { DVB_USB_DEVICE(USB_VID_KWORLD_2
, 0xd393,
1935 &rtl28xxu_props
, "GIGABYTE U7300", NULL
) },
1936 { DVB_USB_DEVICE(USB_VID_DEXATEK
, 0x1104,
1937 &rtl28xxu_props
, "MSI DIGIVOX Micro HD", NULL
) },
1938 { DVB_USB_DEVICE(USB_VID_COMPRO
, 0x0620,
1939 &rtl28xxu_props
, "Compro VideoMate U620F", NULL
) },
1940 { DVB_USB_DEVICE(USB_VID_COMPRO
, 0x0650,
1941 &rtl28xxu_props
, "Compro VideoMate U650F", NULL
) },
1942 { DVB_USB_DEVICE(USB_VID_KWORLD_2
, 0xd394,
1943 &rtl28xxu_props
, "MaxMedia HU394-T", NULL
) },
1944 { DVB_USB_DEVICE(USB_VID_LEADTEK
, 0x6a03,
1945 &rtl28xxu_props
, "Leadtek WinFast DTV Dongle mini", NULL
) },
1946 { DVB_USB_DEVICE(USB_VID_GTEK
, USB_PID_CPYTO_REDI_PC50A
,
1947 &rtl28xxu_props
, "Crypto ReDi PC 50 A", NULL
) },
1948 { DVB_USB_DEVICE(USB_VID_KYE
, 0x707f,
1949 &rtl28xxu_props
, "Genius TVGo DVB-T03", NULL
) },
1950 { DVB_USB_DEVICE(USB_VID_KWORLD_2
, 0xd395,
1951 &rtl28xxu_props
, "Peak DVB-T USB", NULL
) },
1952 { DVB_USB_DEVICE(USB_VID_KWORLD_2
, USB_PID_SVEON_STV20_RTL2832U
,
1953 &rtl28xxu_props
, "Sveon STV20", NULL
) },
1954 { DVB_USB_DEVICE(USB_VID_KWORLD_2
, USB_PID_SVEON_STV21
,
1955 &rtl28xxu_props
, "Sveon STV21", NULL
) },
1956 { DVB_USB_DEVICE(USB_VID_KWORLD_2
, USB_PID_SVEON_STV27
,
1957 &rtl28xxu_props
, "Sveon STV27", NULL
) },
1958 { DVB_USB_DEVICE(USB_VID_KWORLD_2
, USB_PID_TURBOX_DTT_2000
,
1959 &rtl28xxu_props
, "TURBO-X Pure TV Tuner DTT-2000", NULL
) },
1960 { DVB_USB_DEVICE(USB_VID_GTEK
, USB_PID_PROLECTRIX_DV107669
,
1961 &rtl28xxu_props
, "PROlectrix DV107669", NULL
) },
1963 /* RTL2832P devices: */
1964 { DVB_USB_DEVICE(USB_VID_HANFTEK
, 0x0131,
1965 &rtl28xxu_props
, "Astrometa DVB-T2",
1966 RC_MAP_ASTROMETA_T2HYBRID
) },
1967 { DVB_USB_DEVICE(0x5654, 0xca42,
1968 &rtl28xxu_props
, "GoTView MasterHD 3", NULL
) },
1971 MODULE_DEVICE_TABLE(usb
, rtl28xxu_id_table
);
1973 static struct usb_driver rtl28xxu_usb_driver
= {
1974 .name
= KBUILD_MODNAME
,
1975 .id_table
= rtl28xxu_id_table
,
1976 .probe
= dvb_usbv2_probe
,
1977 .disconnect
= dvb_usbv2_disconnect
,
1978 .suspend
= dvb_usbv2_suspend
,
1979 .resume
= dvb_usbv2_resume
,
1980 .reset_resume
= dvb_usbv2_reset_resume
,
1985 module_usb_driver(rtl28xxu_usb_driver
);
1987 MODULE_DESCRIPTION("Realtek RTL28xxU DVB USB driver");
1988 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1989 MODULE_AUTHOR("Thomas Mair <thomas.mair86@googlemail.com>");
1990 MODULE_LICENSE("GPL");