ALSA: es1968: convert TEA575x support to new interface

Use common functions to access TEA575x tuner - remove original read/write
functions and provide new pin manipulation functions instead.

Tested with SF64-PCE2 card.

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index faf91389..75c5e0e 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -2591,96 +2591,48 @@
 #define STR_WREN	0x0100 /* GPIO8 */
 #define STR_MOST	0x0200 /* GPIO9 */
 
-static void snd_es1968_tea575x_write(struct snd_tea575x *tea, unsigned int val)
+static void snd_es1968_tea575x_set_pins(struct snd_tea575x *tea, u8 pins)
 {
 	struct es1968 *chip = tea->private_data;
 	unsigned long io = chip->io_port + GPIO_DATA;
-	u16 l, bits;
-	u16 omask, odir;
+	u16 val = 0;
 
-	omask = inw(io + IO_MASK);
-	odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN);
-	outw(odir | STR_DATA, io + IO_DIR);
-	outw(~(STR_DATA | STR_CLK | STR_WREN), io + IO_MASK);
-	udelay(16);
+	val |= (pins & TEA575X_DATA) ? STR_DATA : 0;
+	val |= (pins & TEA575X_CLK)  ? STR_CLK  : 0;
+	val |= (pins & TEA575X_WREN) ? STR_WREN : 0;
 
-	for (l = 25; l; l--) {
-		bits = ((val >> 18) & STR_DATA) | STR_WREN;
-		val <<= 1;			/* shift data */
-		outw(bits, io);			/* start strobe */
-		udelay(2);
-		outw(bits | STR_CLK, io);	/* HI level */
-		udelay(2);
-		outw(bits, io);			/* LO level */
-		udelay(4);
-	}
-
-	if (!tea->mute)
-		outw(0, io);
-
-	udelay(4);
-	outw(omask, io + IO_MASK);
-	outw(odir, io + IO_DIR);
-	msleep(125);
+	outw(val, io);
 }
 
-static unsigned int snd_es1968_tea575x_read(struct snd_tea575x *tea)
+static u8 snd_es1968_tea575x_get_pins(struct snd_tea575x *tea)
 {
 	struct es1968 *chip = tea->private_data;
 	unsigned long io = chip->io_port + GPIO_DATA;
-	u16 l, rdata;
-	u32 data = 0;
-	u16 omask;
+	u16 val = inw(io);
 
-	omask = inw(io + IO_MASK);
-	outw(~(STR_CLK | STR_WREN), io + IO_MASK);
-	outw(0, io);
-	udelay(16);
-
-	for (l = 24; l--;) {
-		outw(STR_CLK, io);		/* HI state */
-		udelay(2);
-		if (!l)
-			tea->tuned = inw(io) & STR_MOST ? 0 : 1;
-		outw(0, io);			/* LO state */
-		udelay(2);
-		data <<= 1;			/* shift data */
-		rdata = inw(io);
-		if (!l)
-			tea->stereo = (rdata & STR_MOST) ?  0 : 1;
-		else if (l && rdata & STR_DATA)
-			data++;
-		udelay(2);
-	}
-
-	if (tea->mute)
-		outw(STR_WREN, io);
-
-	udelay(4);
-	outw(omask, io + IO_MASK);
-
-	return data & 0x3ffe;
+	return  (val & STR_DATA) ? TEA575X_DATA : 0 |
+		(val & STR_MOST) ? TEA575X_MOST : 0;
 }
 
-static void snd_es1968_tea575x_mute(struct snd_tea575x *tea, unsigned int mute)
+static void snd_es1968_tea575x_set_direction(struct snd_tea575x *tea, bool output)
 {
 	struct es1968 *chip = tea->private_data;
 	unsigned long io = chip->io_port + GPIO_DATA;
-	u16 omask;
+	u16 odir = inw(io + IO_DIR);
 
-	omask = inw(io + IO_MASK);
-	outw(~STR_WREN, io + IO_MASK);
-	tea->mute = mute;
-	outw(tea->mute ? STR_WREN : 0, io);
-	udelay(4);
-	outw(omask, io + IO_MASK);
-	msleep(125);
+	if (output) {
+		outw(~(STR_DATA | STR_CLK | STR_WREN), io + IO_MASK);
+		outw(odir | STR_DATA | STR_CLK | STR_WREN, io + IO_DIR);
+	} else {
+		outw(~(STR_CLK | STR_WREN | STR_DATA | STR_MOST), io + IO_MASK);
+		outw((odir & ~(STR_DATA | STR_MOST)) | STR_CLK | STR_WREN, io + IO_DIR);
+	}
 }
 
 static struct snd_tea575x_ops snd_es1968_tea_ops = {
-	.write = snd_es1968_tea575x_write,
-	.read  = snd_es1968_tea575x_read,
-	.mute  = snd_es1968_tea575x_mute,
+	.set_pins = snd_es1968_tea575x_set_pins,
+	.get_pins = snd_es1968_tea575x_get_pins,
+	.set_direction = snd_es1968_tea575x_set_direction,
 };
 #endif
 
@@ -2845,7 +2797,8 @@
 	chip->tea.freq_fixup = 10700;
 	chip->tea.private_data = chip;
 	chip->tea.ops = &snd_es1968_tea_ops;
-	snd_tea575x_init(&chip->tea);
+	if (!snd_tea575x_init(&chip->tea))
+		printk(KERN_INFO "es1968: detected TEA575x radio\n");
 #endif
 
 	*chip_ret = chip;