aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimothy Lee <timothy.lee@siriushk.com>2008-08-09 12:36:51 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2008-10-12 07:36:49 -0400
commitdfbdce04905d3196c828ca36f01ef06e6fdb2428 (patch)
treef3665bc518d6365b6e0533d49eee47c33b43c069
parent2e06d2ff548fc6333f5b34d188646ded327187c3 (diff)
V4L/DVB (8657): cxusb: add lgs8gl5 and support for Magic-Pro DMB-TH usb stick
Add support for Magic-Pro DMB-TH usb stick. DMB-TH is the HDTV broadcast standard used in Hong Kong and China. [...] I've also attached a second patch against the dvb-apps repository which adds a DMB-TH scan file for Hong Kong. Since the ProHDTV stick contains a DMB-TH decoder (lgs8gl5) onboard, it outputs MPEG-TS to the PC. Signed-off-by: Timothy Lee <timothy.lee@siriushk.com> Signed-off-by: Michael Krufky <mkrufky@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c286
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h2
-rw-r--r--drivers/media/dvb/frontends/Kconfig7
-rw-r--r--drivers/media/dvb/frontends/Makefile1
-rw-r--r--drivers/media/dvb/frontends/lgs8gl5.c480
-rw-r--r--drivers/media/dvb/frontends/lgs8gl5.h45
6 files changed, 821 insertions, 0 deletions
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index 338c819ca739..bffb44380389 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -38,6 +38,7 @@
38#include "mxl5005s.h" 38#include "mxl5005s.h"
39#include "dib7000p.h" 39#include "dib7000p.h"
40#include "dib0070.h" 40#include "dib0070.h"
41#include "lgs8gl5.h"
41 42
42/* debug */ 43/* debug */
43static int dvb_usb_cxusb_debug; 44static int dvb_usb_cxusb_debug;
@@ -111,6 +112,25 @@ static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff)
111 cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40); 112 cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);
112} 113}
113 114
115static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,
116 u8 addr, int onoff)
117{
118 u8 o[2] = {addr, onoff};
119 u8 i;
120 int rc;
121
122 rc = cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
123
124 if (rc < 0)
125 return rc;
126 if (i == 0x01)
127 return 0;
128 else {
129 deb_info("gpio_write failed.\n");
130 return -EIO;
131 }
132}
133
114/* I2C */ 134/* I2C */
115static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], 135static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
116 int num) 136 int num)
@@ -264,6 +284,20 @@ static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff)
264 return rc; 284 return rc;
265} 285}
266 286
287static int cxusb_d680_dmb_power_ctrl(struct dvb_usb_device *d, int onoff)
288{
289 int ret;
290 u8 b;
291 ret = cxusb_power_ctrl(d, onoff);
292 if (!onoff)
293 return ret;
294
295 msleep(128);
296 cxusb_ctrl_msg(d, CMD_DIGITAL, NULL, 0, &b, 1);
297 msleep(100);
298 return ret;
299}
300
267static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) 301static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
268{ 302{
269 u8 buf[2] = { 0x03, 0x00 }; 303 u8 buf[2] = { 0x03, 0x00 };
@@ -285,6 +319,67 @@ static int cxusb_aver_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
285 return 0; 319 return 0;
286} 320}
287 321
322static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d)
323{
324 int ep = d->props.generic_bulk_ctrl_endpoint;
325 const int timeout = 100;
326 const int junk_len = 32;
327 u8 *junk;
328 int rd_count;
329
330 /* Discard remaining data in video pipe */
331 junk = kmalloc(junk_len, GFP_KERNEL);
332 if (!junk)
333 return;
334 while (1) {
335 if (usb_bulk_msg(d->udev,
336 usb_rcvbulkpipe(d->udev, ep),
337 junk, junk_len, &rd_count, timeout) < 0)
338 break;
339 if (!rd_count)
340 break;
341 }
342 kfree(junk);
343}
344
345static void cxusb_d680_dmb_drain_video(struct dvb_usb_device *d)
346{
347 struct usb_data_stream_properties *p = &d->props.adapter[0].stream;
348 const int timeout = 100;
349 const int junk_len = p->u.bulk.buffersize;
350 u8 *junk;
351 int rd_count;
352
353 /* Discard remaining data in video pipe */
354 junk = kmalloc(junk_len, GFP_KERNEL);
355 if (!junk)
356 return;
357 while (1) {
358 if (usb_bulk_msg(d->udev,
359 usb_rcvbulkpipe(d->udev, p->endpoint),
360 junk, junk_len, &rd_count, timeout) < 0)
361 break;
362 if (!rd_count)
363 break;
364 }
365 kfree(junk);
366}
367
368static int cxusb_d680_dmb_streaming_ctrl(
369 struct dvb_usb_adapter *adap, int onoff)
370{
371 if (onoff) {
372 u8 buf[2] = { 0x03, 0x00 };
373 cxusb_d680_dmb_drain_video(adap->dev);
374 return cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON,
375 buf, sizeof(buf), NULL, 0);
376 } else {
377 int ret = cxusb_ctrl_msg(adap->dev,
378 CMD_STREAMING_OFF, NULL, 0, NULL, 0);
379 return ret;
380 }
381}
382
288static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 383static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
289{ 384{
290 struct dvb_usb_rc_key *keymap = d->props.rc_key_map; 385 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
@@ -337,6 +432,32 @@ static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
337 return 0; 432 return 0;
338} 433}
339 434
435static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
436 int *state)
437{
438 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
439 u8 ircode[2];
440 int i;
441
442 *event = 0;
443 *state = REMOTE_NO_KEY_PRESSED;
444
445 if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)
446 return 0;
447
448 for (i = 0; i < d->props.rc_key_map_size; i++) {
449 if (keymap[i].custom == ircode[0] &&
450 keymap[i].data == ircode[1]) {
451 *event = keymap[i].event;
452 *state = REMOTE_KEY_PRESSED;
453
454 return 0;
455 }
456 }
457
458 return 0;
459}
460
340static struct dvb_usb_rc_key dvico_mce_rc_keys[] = { 461static struct dvb_usb_rc_key dvico_mce_rc_keys[] = {
341 { 0xfe, 0x02, KEY_TV }, 462 { 0xfe, 0x02, KEY_TV },
342 { 0xfe, 0x0e, KEY_MP3 }, 463 { 0xfe, 0x0e, KEY_MP3 },
@@ -424,6 +545,44 @@ static struct dvb_usb_rc_key dvico_portable_rc_keys[] = {
424 { 0xfc, 0x00, KEY_UNKNOWN }, /* HD */ 545 { 0xfc, 0x00, KEY_UNKNOWN }, /* HD */
425}; 546};
426 547
548static struct dvb_usb_rc_key d680_dmb_rc_keys[] = {
549 { 0x00, 0x38, KEY_UNKNOWN }, /* TV/AV */
550 { 0x08, 0x0c, KEY_ZOOM },
551 { 0x08, 0x00, KEY_0 },
552 { 0x00, 0x01, KEY_1 },
553 { 0x08, 0x02, KEY_2 },
554 { 0x00, 0x03, KEY_3 },
555 { 0x08, 0x04, KEY_4 },
556 { 0x00, 0x05, KEY_5 },
557 { 0x08, 0x06, KEY_6 },
558 { 0x00, 0x07, KEY_7 },
559 { 0x08, 0x08, KEY_8 },
560 { 0x00, 0x09, KEY_9 },
561 { 0x00, 0x0a, KEY_MUTE },
562 { 0x08, 0x29, KEY_BACK },
563 { 0x00, 0x12, KEY_CHANNELUP },
564 { 0x08, 0x13, KEY_CHANNELDOWN },
565 { 0x00, 0x2b, KEY_VOLUMEUP },
566 { 0x08, 0x2c, KEY_VOLUMEDOWN },
567 { 0x00, 0x20, KEY_UP },
568 { 0x08, 0x21, KEY_DOWN },
569 { 0x00, 0x11, KEY_LEFT },
570 { 0x08, 0x10, KEY_RIGHT },
571 { 0x00, 0x0d, KEY_OK },
572 { 0x08, 0x1f, KEY_RECORD },
573 { 0x00, 0x17, KEY_PLAYPAUSE },
574 { 0x08, 0x16, KEY_PLAYPAUSE },
575 { 0x00, 0x0b, KEY_STOP },
576 { 0x08, 0x27, KEY_FASTFORWARD },
577 { 0x00, 0x26, KEY_REWIND },
578 { 0x08, 0x1e, KEY_UNKNOWN }, /* Time Shift */
579 { 0x00, 0x0e, KEY_UNKNOWN }, /* Snapshot */
580 { 0x08, 0x2d, KEY_UNKNOWN }, /* Mouse Cursor */
581 { 0x00, 0x0f, KEY_UNKNOWN }, /* Minimize/Maximize */
582 { 0x08, 0x14, KEY_UNKNOWN }, /* Shuffle */
583 { 0x00, 0x25, KEY_POWER },
584};
585
427static int cxusb_dee1601_demod_init(struct dvb_frontend* fe) 586static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)
428{ 587{
429 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x28 }; 588 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x28 };
@@ -529,6 +688,24 @@ static struct mxl5005s_config aver_a868r_tuner = {
529 .AgcMasterByte = 0x00, 688 .AgcMasterByte = 0x00,
530}; 689};
531 690
691/* FIXME: needs tweaking */
692static struct mxl5005s_config d680_dmb_tuner = {
693 .i2c_address = 0x63,
694 .if_freq = 36125000UL,
695 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
696 .agc_mode = MXL_SINGLE_AGC,
697 .tracking_filter = MXL_TF_C,
698 .rssi_enable = MXL_RSSI_ENABLE,
699 .cap_select = MXL_CAP_SEL_ENABLE,
700 .div_out = MXL_DIV_OUT_4,
701 .clock_out = MXL_CLOCK_OUT_DISABLE,
702 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
703 .top = MXL5005S_TOP_25P2,
704 .mod_mode = MXL_DIGITAL_MODE,
705 .if_mode = MXL_ZERO_IF,
706 .AgcMasterByte = 0x00,
707};
708
532/* Callbacks for DVB USB */ 709/* Callbacks for DVB USB */
533static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap) 710static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
534{ 711{
@@ -617,6 +794,14 @@ static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
617 return 0; 794 return 0;
618} 795}
619 796
797static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
798{
799 struct dvb_frontend *fe;
800 fe = dvb_attach(mxl5005s_attach, adap->fe,
801 &adap->dev->i2c_adap, &d680_dmb_tuner);
802 return (fe == NULL) ? -EIO : 0;
803}
804
620static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap) 805static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
621{ 806{
622 u8 b; 807 u8 b;
@@ -906,6 +1091,54 @@ static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
906 return -EIO; 1091 return -EIO;
907} 1092}
908 1093
1094static struct lgs8gl5_config lgs8gl5_cfg = {
1095 .demod_address = 0x19,
1096};
1097
1098static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)
1099{
1100 struct dvb_usb_device *d = adap->dev;
1101 int n;
1102
1103 /* Select required USB configuration */
1104 if (usb_set_interface(d->udev, 0, 0) < 0)
1105 err("set interface failed");
1106
1107 /* Unblock all USB pipes */
1108 usb_clear_halt(d->udev,
1109 usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1110 usb_clear_halt(d->udev,
1111 usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1112 usb_clear_halt(d->udev,
1113 usb_rcvbulkpipe(d->udev, d->props.adapter[0].stream.endpoint));
1114
1115 /* Drain USB pipes to avoid hang after reboot */
1116 for (n = 0; n < 5; n++) {
1117 cxusb_d680_dmb_drain_message(d);
1118 cxusb_d680_dmb_drain_video(d);
1119 msleep(200);
1120 }
1121
1122 /* Reset the tuner */
1123 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
1124 err("clear tuner gpio failed");
1125 return -EIO;
1126 }
1127 msleep(100);
1128 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
1129 err("set tuner gpio failed");
1130 return -EIO;
1131 }
1132 msleep(100);
1133
1134 /* Attach frontend */
1135 adap->fe = dvb_attach(lgs8gl5_attach, &lgs8gl5_cfg, &d->i2c_adap);
1136 if (adap->fe == NULL)
1137 return -EIO;
1138
1139 return 0;
1140}
1141
909/* 1142/*
910 * DViCO has shipped two devices with the same USB ID, but only one of them 1143 * DViCO has shipped two devices with the same USB ID, but only one of them
911 * needs a firmware download. Check the device class details to see if they 1144 * needs a firmware download. Check the device class details to see if they
@@ -985,6 +1218,7 @@ static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties;
985static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties; 1218static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;
986static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties; 1219static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;
987static struct dvb_usb_device_properties cxusb_aver_a868r_properties; 1220static struct dvb_usb_device_properties cxusb_aver_a868r_properties;
1221static struct dvb_usb_device_properties cxusb_d680_dmb_properties;
988 1222
989static int cxusb_probe(struct usb_interface *intf, 1223static int cxusb_probe(struct usb_interface *intf,
990 const struct usb_device_id *id) 1224 const struct usb_device_id *id)
@@ -1011,6 +1245,8 @@ static int cxusb_probe(struct usb_interface *intf,
1011 0 == dvb_usb_device_init(intf, 1245 0 == dvb_usb_device_init(intf,
1012 &cxusb_bluebird_dualdig4_rev2_properties, 1246 &cxusb_bluebird_dualdig4_rev2_properties,
1013 THIS_MODULE, NULL, adapter_nr) || 1247 THIS_MODULE, NULL, adapter_nr) ||
1248 0 == dvb_usb_device_init(intf, &cxusb_d680_dmb_properties,
1249 THIS_MODULE, NULL, adapter_nr) ||
1014 0) 1250 0)
1015 return 0; 1251 return 0;
1016 1252
@@ -1036,6 +1272,7 @@ static struct usb_device_id cxusb_table [] = {
1036 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM) }, 1272 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM) },
1037 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R) }, 1273 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R) },
1038 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2) }, 1274 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2) },
1275 { USB_DEVICE(USB_VID_CONEXANT, USB_PID_CONEXANT_D680_DMB) },
1039 {} /* Terminating entry */ 1276 {} /* Terminating entry */
1040}; 1277};
1041MODULE_DEVICE_TABLE (usb, cxusb_table); 1278MODULE_DEVICE_TABLE (usb, cxusb_table);
@@ -1530,6 +1767,55 @@ struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
1530 } 1767 }
1531}; 1768};
1532 1769
1770static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
1771 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1772
1773 .usb_ctrl = CYPRESS_FX2,
1774
1775 .size_of_priv = sizeof(struct cxusb_state),
1776
1777 .num_adapters = 1,
1778 .adapter = {
1779 {
1780 .streaming_ctrl = cxusb_d680_dmb_streaming_ctrl,
1781 .frontend_attach = cxusb_d680_dmb_frontend_attach,
1782 .tuner_attach = cxusb_d680_dmb_tuner_attach,
1783
1784 /* parameter for the MPEG2-data transfer */
1785 .stream = {
1786 .type = USB_BULK,
1787 .count = 5,
1788 .endpoint = 0x02,
1789 .u = {
1790 .bulk = {
1791 .buffersize = 8192,
1792 }
1793 }
1794 },
1795 },
1796 },
1797
1798 .power_ctrl = cxusb_d680_dmb_power_ctrl,
1799
1800 .i2c_algo = &cxusb_i2c_algo,
1801
1802 .generic_bulk_ctrl_endpoint = 0x01,
1803
1804 .rc_interval = 100,
1805 .rc_key_map = d680_dmb_rc_keys,
1806 .rc_key_map_size = ARRAY_SIZE(d680_dmb_rc_keys),
1807 .rc_query = cxusb_d680_dmb_rc_query,
1808
1809 .num_device_descs = 1,
1810 .devices = {
1811 {
1812 "Conexant DMB-TH Stick",
1813 { NULL },
1814 { &cxusb_table[18], NULL },
1815 },
1816 }
1817};
1818
1533static struct usb_driver cxusb_driver = { 1819static struct usb_driver cxusb_driver = {
1534 .name = "dvb_usb_cxusb", 1820 .name = "dvb_usb_cxusb",
1535 .probe = cxusb_probe, 1821 .probe = cxusb_probe,
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index f327a154b6c6..81369b79e75a 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -22,6 +22,7 @@
22#define USB_VID_AVERMEDIA 0x07ca 22#define USB_VID_AVERMEDIA 0x07ca
23#define USB_VID_COMPRO 0x185b 23#define USB_VID_COMPRO 0x185b
24#define USB_VID_COMPRO_UNK 0x145f 24#define USB_VID_COMPRO_UNK 0x145f
25#define USB_VID_CONEXANT 0x0572
25#define USB_VID_CYPRESS 0x04b4 26#define USB_VID_CYPRESS 0x04b4
26#define USB_VID_DIBCOM 0x10b8 27#define USB_VID_DIBCOM 0x10b8
27#define USB_VID_DPOSH 0x1498 28#define USB_VID_DPOSH 0x1498
@@ -69,6 +70,7 @@
69#define USB_PID_COMPRO_DVBU2000_UNK_WARM 0x010d 70#define USB_PID_COMPRO_DVBU2000_UNK_WARM 0x010d
70#define USB_PID_COMPRO_VIDEOMATE_U500 0x1e78 71#define USB_PID_COMPRO_VIDEOMATE_U500 0x1e78
71#define USB_PID_COMPRO_VIDEOMATE_U500_PC 0x1e80 72#define USB_PID_COMPRO_VIDEOMATE_U500_PC 0x1e80
73#define USB_PID_CONEXANT_D680_DMB 0x86d6
72#define USB_PID_DIBCOM_HOOK_DEFAULT 0x0064 74#define USB_PID_DIBCOM_HOOK_DEFAULT 0x0064
73#define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM 0x0065 75#define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM 0x0065
74#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8 76#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index 7dbb4a223c99..774f5c2a71e8 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -385,4 +385,11 @@ config DVB_ISL6421
385 help 385 help
386 An SEC control chip. 386 An SEC control chip.
387 387
388config DVB_LGS8GL5
389 tristate "Silicon Legend LGS-8GL5 demodulator (OFDM)"
390 depends on DVB_CORE && I2C
391 default m if DVB_FE_CUSTOMISE
392 help
393 A DMB-TH tuner module. Say Y when you want to support this frontend.
394
388endmenu 395endmenu
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 028da55611c0..262eaa429f5d 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -48,3 +48,4 @@ obj-$(CONFIG_DVB_TUNER_ITD1000) += itd1000.o
48obj-$(CONFIG_DVB_AU8522) += au8522.o 48obj-$(CONFIG_DVB_AU8522) += au8522.o
49obj-$(CONFIG_DVB_TDA10048) += tda10048.o 49obj-$(CONFIG_DVB_TDA10048) += tda10048.o
50obj-$(CONFIG_DVB_S5H1411) += s5h1411.o 50obj-$(CONFIG_DVB_S5H1411) += s5h1411.o
51obj-$(CONFIG_DVB_LGS8GL5) += lgs8gl5.o
diff --git a/drivers/media/dvb/frontends/lgs8gl5.c b/drivers/media/dvb/frontends/lgs8gl5.c
new file mode 100644
index 000000000000..c0a223d28b0f
--- /dev/null
+++ b/drivers/media/dvb/frontends/lgs8gl5.c
@@ -0,0 +1,480 @@
1/*
2 Legend Silicon LGS-8GL5 DMB-TH OFDM demodulator driver
3
4 Copyright (C) 2008 Sirius International (Hong Kong) Limited
5 Timothy Lee <timothy.lee@siriushk.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21*/
22
23#include <linux/kernel.h>
24#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/string.h>
27#include <linux/slab.h>
28#include "dvb_frontend.h"
29#include "lgs8gl5.h"
30
31
32#define REG_RESET 0x02
33#define REG_RESET_OFF 0x01
34#define REG_03 0x03
35#define REG_04 0x04
36#define REG_07 0x07
37#define REG_09 0x09
38#define REG_0A 0x0a
39#define REG_0B 0x0b
40#define REG_0C 0x0c
41#define REG_37 0x37
42#define REG_STRENGTH 0x4b
43#define REG_STRENGTH_MASK 0x7f
44#define REG_STRENGTH_CARRIER 0x80
45#define REG_INVERSION 0x7c
46#define REG_INVERSION_ON 0x80
47#define REG_7D 0x7d
48#define REG_7E 0x7e
49#define REG_A2 0xa2
50#define REG_STATUS 0xa4
51#define REG_STATUS_SYNC 0x04
52#define REG_STATUS_LOCK 0x01
53
54
55struct lgs8gl5_state {
56 struct i2c_adapter *i2c;
57 const struct lgs8gl5_config *config;
58 struct dvb_frontend frontend;
59};
60
61
62static int debug;
63#define dprintk(args...) \
64 do { \
65 if (debug) \
66 printk(KERN_DEBUG "lgs8gl5: " args); \
67 } while (0)
68
69
70/* Writes into demod's register */
71static int
72lgs8gl5_write_reg(struct lgs8gl5_state *state, u8 reg, u8 data)
73{
74 int ret;
75 u8 buf[] = {reg, data};
76 struct i2c_msg msg = {
77 .addr = state->config->demod_address,
78 .flags = 0,
79 .buf = buf,
80 .len = 2
81 };
82
83 ret = i2c_transfer(state->i2c, &msg, 1);
84 if (ret != 1)
85 dprintk("%s: error (reg=0x%02x, val=0x%02x, ret=%i)\n",
86 __func__, reg, data, ret);
87 return (ret != 1) ? -1 : 0;
88}
89
90
91/* Reads from demod's register */
92static int
93lgs8gl5_read_reg(struct lgs8gl5_state *state, u8 reg)
94{
95 int ret, j;
96 u8 b0[] = {reg};
97 u8 b1[] = {0};
98 struct i2c_msg msg[2] = {
99 {
100 .addr = state->config->demod_address,
101 .flags = 0,
102 .buf = b0,
103 .len = 1
104 },
105 {
106 .addr = state->config->demod_address,
107 .flags = I2C_M_RD,
108 .buf = b1,
109 .len = 1
110 }
111 };
112
113 ret = i2c_transfer(state->i2c, msg, 2);
114 if (ret != 2)
115 return -EIO;
116
117 return b1[0];
118}
119
120
121static int
122lgs8gl5_update_reg(struct lgs8gl5_state *state, u8 reg, u8 data)
123{
124 lgs8gl5_read_reg(state, reg);
125 lgs8gl5_write_reg(state, reg, data);
126 return 0;
127}
128
129
130/* Writes into alternate device's register */
131/* TODO: Find out what that device is for! */
132static int
133lgs8gl5_update_alt_reg(struct lgs8gl5_state *state, u8 reg, u8 data)
134{
135 int ret, j;
136 u8 b0[] = {reg};
137 u8 b1[] = {0};
138 u8 b2[] = {reg, data};
139 struct i2c_msg msg[3] = {
140 {
141 .addr = state->config->demod_address + 2,
142 .flags = 0,
143 .buf = b0,
144 .len = 1
145 },
146 {
147 .addr = state->config->demod_address + 2,
148 .flags = I2C_M_RD,
149 .buf = b1,
150 .len = 1
151 },
152 {
153 .addr = state->config->demod_address + 2,
154 .flags = 0,
155 .buf = b2,
156 .len = 2
157 },
158 };
159
160 ret = i2c_transfer(state->i2c, msg, 3);
161 return (ret != 3) ? -1 : 0;
162}
163
164
165static void
166lgs8gl5_soft_reset(struct lgs8gl5_state *state)
167{
168 u8 val;
169
170 dprintk("%s\n", __func__);
171
172 val = lgs8gl5_read_reg(state, REG_RESET);
173 lgs8gl5_write_reg(state, REG_RESET, val & ~REG_RESET_OFF);
174 lgs8gl5_write_reg(state, REG_RESET, val | REG_RESET_OFF);
175 msleep(5);
176}
177
178
179static int
180lgs8gl5_set_inversion(struct lgs8gl5_state *state, int inversion)
181{
182 u8 val;
183
184 dprintk("%s\n", __func__);
185
186 switch (inversion) {
187 case INVERSION_AUTO:
188 return -EOPNOTSUPP;
189 case INVERSION_ON:
190 val = lgs8gl5_read_reg(state, REG_INVERSION);
191 return lgs8gl5_write_reg(state, REG_INVERSION,
192 val | REG_INVERSION_ON);
193 case INVERSION_OFF:
194 val = lgs8gl5_read_reg(state, REG_INVERSION);
195 return lgs8gl5_write_reg(state, REG_INVERSION,
196 val & ~REG_INVERSION_ON);
197 default:
198 return -EINVAL;
199 }
200}
201
202
203/* Starts demodulation */
204static void
205lgs8gl5_start_demod(struct lgs8gl5_state *state)
206{
207 u8 val;
208 int n;
209
210 dprintk("%s\n", __func__);
211
212 lgs8gl5_update_alt_reg(state, 0xc2, 0x28);
213 lgs8gl5_soft_reset(state);
214 lgs8gl5_update_reg(state, REG_07, 0x10);
215 lgs8gl5_update_reg(state, REG_07, 0x10);
216 lgs8gl5_write_reg(state, REG_09, 0x0e);
217 lgs8gl5_write_reg(state, REG_0A, 0xe5);
218 lgs8gl5_write_reg(state, REG_0B, 0x35);
219 lgs8gl5_write_reg(state, REG_0C, 0x30);
220
221 lgs8gl5_update_reg(state, REG_03, 0x00);
222 lgs8gl5_update_reg(state, REG_7E, 0x01);
223 lgs8gl5_update_alt_reg(state, 0xc5, 0x00);
224 lgs8gl5_update_reg(state, REG_04, 0x02);
225 lgs8gl5_update_reg(state, REG_37, 0x01);
226 lgs8gl5_soft_reset(state);
227
228 /* Wait for carrier */
229 for (n = 0; n < 10; n++) {
230 val = lgs8gl5_read_reg(state, REG_STRENGTH);
231 dprintk("Wait for carrier[%d] 0x%02X\n", n, val);
232 if (val & REG_STRENGTH_CARRIER)
233 break;
234 msleep(4);
235 }
236 if (!(val & REG_STRENGTH_CARRIER))
237 return;
238
239 /* Wait for lock */
240 for (n = 0; n < 20; n++) {
241 val = lgs8gl5_read_reg(state, REG_STATUS);
242 dprintk("Wait for lock[%d] 0x%02X\n", n, val);
243 if (val & REG_STATUS_LOCK)
244 break;
245 msleep(12);
246 }
247 if (!(val & REG_STATUS_LOCK))
248 return;
249
250 lgs8gl5_write_reg(state, REG_7D, lgs8gl5_read_reg(state, REG_A2));
251 lgs8gl5_soft_reset(state);
252}
253
254
255static int
256lgs8gl5_init(struct dvb_frontend *fe)
257{
258 struct lgs8gl5_state *state = fe->demodulator_priv;
259
260 dprintk("%s\n", __func__);
261
262 lgs8gl5_update_alt_reg(state, 0xc2, 0x28);
263 lgs8gl5_soft_reset(state);
264 lgs8gl5_update_reg(state, REG_07, 0x10);
265 lgs8gl5_update_reg(state, REG_07, 0x10);
266 lgs8gl5_write_reg(state, REG_09, 0x0e);
267 lgs8gl5_write_reg(state, REG_0A, 0xe5);
268 lgs8gl5_write_reg(state, REG_0B, 0x35);
269 lgs8gl5_write_reg(state, REG_0C, 0x30);
270
271 return 0;
272}
273
274
275static int
276lgs8gl5_read_status(struct dvb_frontend *fe, fe_status_t *status)
277{
278 struct lgs8gl5_state *state = fe->demodulator_priv;
279 u8 level = lgs8gl5_read_reg(state, REG_STRENGTH);
280 u8 flags = lgs8gl5_read_reg(state, REG_STATUS);
281
282 *status = 0;
283
284 if ((level & REG_STRENGTH_MASK) > 0)
285 *status |= FE_HAS_SIGNAL;
286 if (level & REG_STRENGTH_CARRIER)
287 *status |= FE_HAS_CARRIER;
288 if (flags & REG_STATUS_SYNC)
289 *status |= FE_HAS_SYNC;
290 if (flags & REG_STATUS_LOCK)
291 *status |= FE_HAS_LOCK;
292
293 return 0;
294}
295
296
297static int
298lgs8gl5_read_ber(struct dvb_frontend *fe, u32 *ber)
299{
300 struct lgs8gl5_state *state = fe->demodulator_priv;
301 *ber = 0;
302
303 return 0;
304}
305
306
307static int
308lgs8gl5_read_signal_strength(struct dvb_frontend *fe, u16 *signal_strength)
309{
310 struct lgs8gl5_state *state = fe->demodulator_priv;
311 u8 level = lgs8gl5_read_reg(state, REG_STRENGTH);
312 *signal_strength = (level & REG_STRENGTH_MASK) << 8;
313
314 return 0;
315}
316
317
318static int
319lgs8gl5_read_snr(struct dvb_frontend *fe, u16 *snr)
320{
321 struct lgs8gl5_state *state = fe->demodulator_priv;
322 u8 level = lgs8gl5_read_reg(state, REG_STRENGTH);
323 *snr = (level & REG_STRENGTH_MASK) << 8;
324
325 return 0;
326}
327
328
329static int
330lgs8gl5_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
331{
332 struct lgs8gl5_state *state = fe->demodulator_priv;
333 *ucblocks = 0;
334
335 return 0;
336}
337
338
339static int
340lgs8gl5_set_frontend(struct dvb_frontend *fe,
341 struct dvb_frontend_parameters *p)
342{
343 struct lgs8gl5_state *state = fe->demodulator_priv;
344
345 dprintk("%s\n", __func__);
346
347 if (p->u.ofdm.bandwidth != BANDWIDTH_8_MHZ)
348 return -EINVAL;
349
350 if (fe->ops.tuner_ops.set_params) {
351 fe->ops.tuner_ops.set_params(fe, p);
352 if (fe->ops.i2c_gate_ctrl)
353 fe->ops.i2c_gate_ctrl(fe, 0);
354 }
355
356 /* lgs8gl5_set_inversion(state, p->inversion); */
357
358 lgs8gl5_start_demod(state);
359
360 return 0;
361}
362
363
364static int
365lgs8gl5_get_frontend(struct dvb_frontend *fe,
366 struct dvb_frontend_parameters *p)
367{
368 struct lgs8gl5_state *state = fe->demodulator_priv;
369 u8 inv = lgs8gl5_read_reg(state, REG_INVERSION);
370 struct dvb_ofdm_parameters *o = &p->u.ofdm;
371
372 p->inversion = (inv & REG_INVERSION_ON) ? INVERSION_ON : INVERSION_OFF;
373
374 o->code_rate_HP = FEC_1_2;
375 o->code_rate_LP = FEC_7_8;
376 o->guard_interval = GUARD_INTERVAL_1_32;
377 o->transmission_mode = TRANSMISSION_MODE_2K;
378 o->constellation = QAM_64;
379 o->hierarchy_information = HIERARCHY_NONE;
380 o->bandwidth = BANDWIDTH_8_MHZ;
381
382 return 0;
383}
384
385
386static int
387lgs8gl5_get_tune_settings(struct dvb_frontend *fe,
388 struct dvb_frontend_tune_settings *fesettings)
389{
390 fesettings->min_delay_ms = 240;
391 fesettings->step_size = 0;
392 fesettings->max_drift = 0;
393 return 0;
394}
395
396
397static void
398lgs8gl5_release(struct dvb_frontend *fe)
399{
400 struct lgs8gl5_state *state = fe->demodulator_priv;
401 kfree(state);
402}
403
404
405static struct dvb_frontend_ops lgs8gl5_ops;
406
407
408struct dvb_frontend*
409lgs8gl5_attach(const struct lgs8gl5_config *config, struct i2c_adapter *i2c)
410{
411 struct lgs8gl5_state *state = NULL;
412
413 dprintk("%s\n", __func__);
414
415 /* Allocate memory for the internal state */
416 state = kmalloc(sizeof(struct lgs8gl5_state), GFP_KERNEL);
417 if (state == NULL)
418 goto error;
419
420 /* Setup the state */
421 state->config = config;
422 state->i2c = i2c;
423
424 /* Check if the demod is there */
425 if (lgs8gl5_read_reg(state, REG_RESET) < 0)
426 goto error;
427
428 /* Create dvb_frontend */
429 memcpy(&state->frontend.ops, &lgs8gl5_ops,
430 sizeof(struct dvb_frontend_ops));
431 state->frontend.demodulator_priv = state;
432 return &state->frontend;
433
434error:
435 kfree(state);
436 return NULL;
437}
438EXPORT_SYMBOL(lgs8gl5_attach);
439
440
441static struct dvb_frontend_ops lgs8gl5_ops = {
442 .info = {
443 .name = "Legend Silicon LGS-8GL5 DMB-TH",
444 .type = FE_OFDM,
445 .frequency_min = 474000000,
446 .frequency_max = 858000000,
447 .frequency_stepsize = 10000,
448 .frequency_tolerance = 0,
449 .caps = FE_CAN_FEC_AUTO |
450 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_32 |
451 FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
452 FE_CAN_TRANSMISSION_MODE_AUTO |
453 FE_CAN_BANDWIDTH_AUTO |
454 FE_CAN_GUARD_INTERVAL_AUTO |
455 FE_CAN_HIERARCHY_AUTO |
456 FE_CAN_RECOVER
457 },
458
459 .release = lgs8gl5_release,
460
461 .init = lgs8gl5_init,
462
463 .set_frontend = lgs8gl5_set_frontend,
464 .get_frontend = lgs8gl5_get_frontend,
465 .get_tune_settings = lgs8gl5_get_tune_settings,
466
467 .read_status = lgs8gl5_read_status,
468 .read_ber = lgs8gl5_read_ber,
469 .read_signal_strength = lgs8gl5_read_signal_strength,
470 .read_snr = lgs8gl5_read_snr,
471 .read_ucblocks = lgs8gl5_read_ucblocks,
472};
473
474
475module_param(debug, int, 0644);
476MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
477
478MODULE_DESCRIPTION("Legend Silicon LGS-8GL5 DMB-TH Demodulator driver");
479MODULE_AUTHOR("Timothy Lee");
480MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/lgs8gl5.h b/drivers/media/dvb/frontends/lgs8gl5.h
new file mode 100644
index 000000000000..d14176787a7d
--- /dev/null
+++ b/drivers/media/dvb/frontends/lgs8gl5.h
@@ -0,0 +1,45 @@
1/*
2 Legend Silicon LGS-8GL5 DMB-TH OFDM demodulator driver
3
4 Copyright (C) 2008 Sirius International (Hong Kong) Limited
5 Timothy Lee <timothy.lee@siriushk.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21*/
22
23#ifndef LGS8GL5_H
24#define LGS8GL5_H
25
26#include <linux/dvb/frontend.h>
27
28struct lgs8gl5_config {
29 /* the demodulator's i2c address */
30 u8 demod_address;
31};
32
33#if defined(CONFIG_DVB_LGS8GL5) || \
34 (defined(CONFIG_DVB_LGS8GL5_MODULE) && defined(MODULE))
35extern struct dvb_frontend *lgs8gl5_attach(
36 const struct lgs8gl5_config *config, struct i2c_adapter *i2c);
37#else
38static inline struct dvb_frontend *lgs8gl5_attach(
39 const struct lgs8gl5_config *config, struct i2c_adapter *i2c) {
40 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
41 return NULL;
42}
43#endif /* CONFIG_DVB_LGS8GL5 */
44
45#endif /* LGS8GL5_H */