V4L/DVB (4205): Merge tda9887 module into tuner.

Most uses a tda988[5/6/7] IF demodulator as part of the device.
Having this as a separate stuff makes harder to configure it, since there
are some tda9887 options that are tuner-dependent and should be bound into
tuner-types structures.
This patch merges tda9887 module into tuner. More work is required to make
tuner-types to properly use it.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index cc4a38b3..e95792f 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -215,6 +215,9 @@
 		i2c_master_send(c,buffer,4);
 		default_tuner_init(c);
 		break;
+	case TUNER_TDA9887:
+		tda9887_tuner_init(c);
+		break;
 	default:
 		default_tuner_init(c);
 		break;
@@ -241,6 +244,8 @@
 {
 	struct tuner *t = i2c_get_clientdata(c);
 
+	tuner_dbg("set addr for type %i\n", t->type);
+
 	if ( t->type == UNSET && ((tun_setup->addr == ADDR_UNSET &&
 		(t->mode_mask & tun_setup->mode_mask)) ||
 		tun_setup->addr == c->addr)) {
@@ -436,6 +441,7 @@
 	t->radio_if2 = 10700 * 1000;	/* 10.7MHz - FM radio */
 	t->audmode = V4L2_TUNER_MODE_STEREO;
 	t->mode_mask = T_UNINITIALIZED;
+	t->tuner_status = tuner_status;
 	if (tuner_debug_old) {
 		tuner_debug = tuner_debug_old;
 		printk(KERN_ERR "tuner: tuner_debug is deprecated and will be removed in 2.6.17.\n");
@@ -462,10 +468,14 @@
 		case 0x4b:
 			/* If chip is not tda8290, don't register.
 			   since it can be tda9887*/
-			if (tda8290_probe(&t->i2c) != 0) {
-				tuner_dbg("chip at addr %x is not a tda8290\n", addr);
-				kfree(t);
-				return 0;
+			if (tda8290_probe(&t->i2c) == 0) {
+				tuner_dbg("chip at addr %x is a tda8290\n", addr);
+			} else {
+				/* Default is being tda9887 */
+				t->type = TUNER_TDA9887;
+				t->mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
+				t->mode = T_STANDBY;
+				goto register_client;
 			}
 			break;
 		case 0x60:
@@ -592,6 +602,7 @@
 	case TUNER_SET_STANDBY:
 		if (check_mode(t, "TUNER_SET_STANDBY") == EINVAL)
 			return 0;
+		t->mode = T_STANDBY;
 		if (t->standby)
 			t->standby (client);
 		break;
@@ -604,6 +615,14 @@
 		/* Should be implemented, since bttv calls it */
 		tuner_dbg("VIDIOCSAUDIO not implemented.\n");
 		break;
+	case TDA9887_SET_CONFIG:
+	{
+		int *i = arg;
+
+		t->tda9887_config = *i;
+		set_freq(client, t->tv_freq);
+		break;
+	}
 	/* --- v4l ioctls --- */
 	/* take care: bttv does userspace copying, we'll get a
 	   kernel pointer here... */
@@ -744,6 +763,8 @@
 			switch_v4l2();
 
 			tuner->type = t->mode;
+			if (t->get_afc)
+				tuner->afc=t->get_afc(client);
 			if (t->mode == V4L2_TUNER_ANALOG_TV)
 				tuner->capability |= V4L2_TUNER_CAP_NORM;
 			if (t->mode != V4L2_TUNER_RADIO) {
@@ -787,7 +808,8 @@
 			break;
 		}
 	case VIDIOC_LOG_STATUS:
-		tuner_status(client);
+		if (t->tuner_status)
+			t->tuner_status(client);
 		break;
 	}