V4L/DVB (6196): cx23885: add support for DViCO FusionHDTV 5 Express

This patch adds digital ATSC / QAM support for the DViCO FusionHDTV5 Express.
Remote control is supported by ir-kbd-i2c, RTC is supported by rtc-isl1208.

Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Steven Toth <stoth@hauppauge.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index 09d4376..cdda11d 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -109,6 +109,10 @@
 			.gpio0  = 0xff02,
 		}},
 	},
+	[CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP] = {
+		.name		= "DViCO FusionHDTV5 Express",
+		.portc		= CX23885_MPEG_DVB,
+	},
 };
 const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
 
@@ -136,6 +140,10 @@
 		.subvendor = 0x0070,
 		.subdevice = 0x7911,
 		.card      = CX23885_BOARD_HAUPPAUGE_HVR1250,
+	},{
+		.subvendor = 0x18ac,
+		.subdevice = 0xd500,
+		.card      = CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP,
 	},
 };
 const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
diff --git a/drivers/media/video/cx23885/cx23885-core.c b/drivers/media/video/cx23885/cx23885-core.c
index 553a72a..bcba192 100644
--- a/drivers/media/video/cx23885/cx23885-core.c
+++ b/drivers/media/video/cx23885/cx23885-core.c
@@ -793,6 +793,32 @@
 	cx23885_ir_init(dev);
 
 	switch (dev->board) {
+	case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
+		dev->ts2.reg_gpcnt          = VID_B_GPCNT;
+		dev->ts2.reg_gpcnt_ctl      = VID_B_GPCNT_CTL;
+		dev->ts2.reg_dma_ctl        = VID_B_DMA_CTL;
+		dev->ts2.reg_lngth          = VID_B_LNGTH;
+		dev->ts2.reg_hw_sop_ctrl    = VID_B_HW_SOP_CTL;
+		dev->ts2.reg_gen_ctrl       = VID_B_GEN_CTL;
+		dev->ts2.reg_bd_pkt_status  = VID_B_BD_PKT_STATUS;
+		dev->ts2.reg_sop_status     = VID_B_SOP_STATUS;
+		dev->ts2.reg_fifo_ovfl_stat = VID_B_FIFO_OVFL_STAT;
+		dev->ts2.reg_vld_misc       = VID_B_VLD_MISC;
+		dev->ts2.reg_ts_clk_en      = VID_B_TS_CLK_EN;
+		dev->ts2.reg_ts_int_msk     = VID_B_INT_MSK;
+		dev->ts2.reg_src_sel        = VID_B_SRC_SEL;
+
+		// FIXME: Make this board specific
+		dev->ts2.pci_irqmask = 0x02; /* TS Port 2 bit */
+		dev->ts2.dma_ctl_val = 0x11; /* Enable RISC controller and Fifo */
+		dev->ts2.ts_int_msk_val = 0x1111; /* TS port bits for RISC */
+		dev->ts2.gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
+		dev->ts2.ts_clk_en_val = 0x1; /* Enable TS_CLK */
+		dev->ts2.src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
+
+		// Drive this from cards.c (portb/c) and move it outside of this switch
+		dev->ts2.sram_chno = SRAM_CH03;
+		break;
 	default:
 		dev->ts2.reg_gpcnt          = VID_C_GPCNT;
 		dev->ts2.reg_gpcnt_ctl      = VID_C_GPCNT_CTL;
diff --git a/drivers/media/video/cx23885/cx23885-dvb.c b/drivers/media/video/cx23885/cx23885-dvb.c
index ffa4c49..0ace919 100644
--- a/drivers/media/video/cx23885/cx23885-dvb.c
+++ b/drivers/media/video/cx23885/cx23885-dvb.c
@@ -32,6 +32,8 @@
 
 #include "s5h1409.h"
 #include "mt2131.h"
+#include "lgdt330x.h"
+#include "dvb-pll.h"
 
 static unsigned int debug = 0;
 
@@ -101,6 +103,12 @@
 	0x61
 };
 
+static struct lgdt330x_config fusionhdtv_5_express = {
+	.demod_address = 0x0e,
+	.demod_chip = LGDT3303,
+	.serial_mpeg = 0x40,
+};
+
 static int dvb_register(struct cx23885_tsport *port)
 {
 	struct cx23885_dev *dev = port->dev;
@@ -131,6 +139,16 @@
 				   &hauppauge_generic_tunerconfig, 0);
 		}
 		break;
+	case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
+		port->dvb.frontend = dvb_attach(lgdt330x_attach,
+						&fusionhdtv_5_express,
+						&dev->i2c_bus[0].i2c_adap);
+		if (port->dvb.frontend != NULL) {
+			dvb_attach(dvb_pll_attach, port->dvb.frontend,
+				   0x61, &dev->i2c_bus[0].i2c_adap,
+				   DVB_PLL_LG_TDVS_H06XF);
+		}
+		break;
 	default:
 		printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
 		       dev->name);
diff --git a/drivers/media/video/cx23885/cx23885-i2c.c b/drivers/media/video/cx23885/cx23885-i2c.c
index 5572fbb..b517c8b 100644
--- a/drivers/media/video/cx23885/cx23885-i2c.c
+++ b/drivers/media/video/cx23885/cx23885-i2c.c
@@ -305,12 +305,14 @@
 };
 
 static char *i2c_devs[128] = {
+	[ 0x1c >> 1 ] = "lgdt3303",
+	[ 0x86 >> 1 ] = "tda9887",
 	[ 0x32 >> 1 ] = "cx24227",
 	[ 0x88 >> 1 ] = "cx25837",
 	[ 0x84 >> 1 ] = "tda8295",
 	[ 0xa0 >> 1 ] = "eeprom",
-	[ 0xc0 >> 1 ] = "mt2131/tda8275",
-	[ 0xc2 >> 1 ] = "mt2131/tda8275",
+	[ 0xc0 >> 1 ] = "tuner/mt2131/tda8275",
+	[ 0xc2 >> 1 ] = "tuner/mt2131/tda8275",
 };
 
 static void do_i2c_scan(char *name, struct i2c_client *c)
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
index 62b44f6..4933274 100644
--- a/drivers/media/video/cx23885/cx23885.h
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -54,6 +54,7 @@
 #define CX23885_BOARD_HAUPPAUGE_HVR1800lp      1
 #define CX23885_BOARD_HAUPPAUGE_HVR1800        2
 #define CX23885_BOARD_HAUPPAUGE_HVR1250        3
+#define CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP   4
 
 enum cx23885_itype {
 	CX23885_VMUX_COMPOSITE1 = 1,
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 04f6eb5..d98dd0d 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -507,6 +507,7 @@
 	static const int probe_saa7134[] = { 0x7a, 0x47, 0x71, -1 };
 	static const int probe_em28XX[] = { 0x30, 0x47, -1 };
 	static const int probe_cx88[] = { 0x18, 0x6b, 0x71, -1 };
+	static const int probe_cx23885[] = { 0x6b, -1 };
 	const int *probe = NULL;
 	struct i2c_client c;
 	unsigned char buf;
@@ -527,6 +528,8 @@
 		break;
 	case I2C_HW_B_CX2388x:
 		probe = probe_cx88;
+	case I2C_HW_B_CX23885:
+		probe = probe_cx23885;
 		break;
 	}
 	if (NULL == probe)
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 2d4a3e3..9484308 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -665,7 +665,8 @@
 	 * FusionHDTV5 RT Gold has an ir receiver at 0x6b
 	 * and an RTC at 0x6f which can get corrupted if probed.
 	 */
-	if (adap->id == I2C_HW_B_CX2388x) {
+	if ((adap->id == I2C_HW_B_CX2388x) ||
+	    (adap->id == I2C_HW_B_CX23885)) {
 		unsigned int i = 0;
 
 		while (i < I2C_CLIENT_MAX_OPTS && ignore[i] != I2C_CLIENT_END)