V4L/DVB (10759): cx18: Convert GPIO connected functions to act as v4l2_subdevices

Convert GPIO line functions, such a audio routing and device resets, to
v4l2_subdevices.  This essentially completes the conversion of cx18 to the
v4l2_device/v4l2_subdevice framework.  No regression testing has taken place as
of yet.  Also an ivtv legacy bug with GPIO mux routing and going to/from radio
mode was commented, but not fixed.

Signed-off-by: Andy Walls <awalls@radix.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
index edbb83c..79b3bf5 100644
--- a/drivers/media/video/cx18/cx18-driver.c
+++ b/drivers/media/video/cx18/cx18-driver.c
@@ -684,7 +684,6 @@
 			continue;
 
 		switch (device) {
-		case CX18_HW_GPIO_AUDIO_MUX:
 		case CX18_HW_DVB:
 		case CX18_HW_TVEEPROM:
 			/* These subordinate devices do not use probing */
@@ -695,6 +694,16 @@
 			/* Just note that the card uses it (i.e. has analog) */
 			cx->hw_flags |= device;
 			break;
+		case CX18_HW_GPIO_RESET_CTRL:
+			/*
+			 * The Reset Controller gets probed and added to
+			 * hw_flags earlier for i2c adapter/bus initialization
+			 */
+			break;
+		case CX18_HW_GPIO_MUX:
+			if (cx18_gpio_register(cx, device) == 0)
+				cx->hw_flags |= device;
+			break;
 		default:
 			if (cx18_i2c_register(cx, i) == 0)
 				cx->hw_flags |= device;
@@ -793,7 +802,6 @@
 	cx->scb = (struct cx18_scb __iomem *)(cx->enc_mem + SCB_OFFSET);
 	cx18_init_scb(cx);
 
-	/* Initialize GPIO early so I2C device resets can be performed */
 	cx18_gpio_init(cx);
 
 	/* Initialize integrated A/V decoder early to set PLLs, just in case */
@@ -802,9 +810,17 @@
 		CX18_ERR("Could not register A/V decoder subdevice\n");
 		goto free_map;
 	}
-	/* Initialize the A/V decoder PLLs to sane defaults */
 	cx18_call_hw(cx, CX18_HW_418_AV, core, init, (u32) CX18_AV_INIT_PLLS);
 
+	/* Initialize GPIO Reset Controller to do chip resets during i2c init */
+	if (cx->card->hw_all & CX18_HW_GPIO_RESET_CTRL) {
+		if (cx18_gpio_register(cx, CX18_HW_GPIO_RESET_CTRL) != 0)
+			CX18_WARN("Could not register GPIO reset controller"
+				  "subdevice; proceeding anyway.\n");
+		else
+			cx->hw_flags |= CX18_HW_GPIO_RESET_CTRL;
+	}
+
 	/* active i2c  */
 	CX18_DEBUG_INFO("activating i2c...\n");
 	retval = init_cx18_i2c(cx);