From b1bdb9886f1a5d848ca7dab70bfa78045b071b92 Mon Sep 17 00:00:00 2001
From: =?utf8?q?=E9=99=88=E9=87=91=E6=B3=89?= <chenjq@rock-chips.com>
Date: Tue, 4 Jun 2013 11:23:07 +0800
Subject: [PATCH] rk616 codec:add reset in fun shutdown

---
 arch/arm/mach-rk3188/board-rk3188m-tb.c | 16 +--------
 sound/soc/codecs/rk616_codec.c          | 45 ++++++++++++++++---------
 2 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/arch/arm/mach-rk3188/board-rk3188m-tb.c b/arch/arm/mach-rk3188/board-rk3188m-tb.c
index 542e17569386..297f59b01340 100644
--- a/arch/arm/mach-rk3188/board-rk3188m-tb.c
+++ b/arch/arm/mach-rk3188/board-rk3188m-tb.c
@@ -698,25 +698,11 @@ static struct rk610_ctl_platform_data rk610_ctl_pdata = {
 #if defined(CONFIG_MFD_RK616)
 #define RK616_RST_PIN 			RK30_PIN3_PB2
 #define RK616_PWREN_PIN			RK30_PIN0_PC5
-#define RK616_SPK_CTL2			RK30_PIN0_PD5
 #define RK616_SCL_RATE			(80*1000)   //i2c scl rate
 static int rk616_power_on_init(void)
 {
 	int ret;
-#if 1
-	if(RK616_SPK_CTL2 != INVALID_GPIO)
-	{
-		ret = gpio_request(RK616_SPK_CTL2, "rk616 spk ctl2");
-		if (ret)
-		{
-			printk(KERN_ERR "rk616 spk_ctl2 gpio request fail\n");
-		}
-		else 
-		{
-			gpio_direction_output(RK616_SPK_CTL2,GPIO_HIGH);
-		}
-	}
-#endif
+
 	if(RK616_PWREN_PIN != INVALID_GPIO)
 	{
 		ret = gpio_request(RK616_PWREN_PIN, "rk616 pwren");
diff --git a/sound/soc/codecs/rk616_codec.c b/sound/soc/codecs/rk616_codec.c
index be42b02fd009..689313590ec9 100755
--- a/sound/soc/codecs/rk616_codec.c
+++ b/sound/soc/codecs/rk616_codec.c
@@ -1533,7 +1533,7 @@ static int rk616_hw_params(struct snd_pcm_substream *substream,
 		return -EINVAL;
 	}
 
-	switch (params_channels(params)) {
+	/*switch (params_channels(params)) {
 	case RK616_MONO:
 		adc_aif1 |= RK616_ADC_TYPE_MONO;
 		break;
@@ -1542,7 +1542,10 @@ static int rk616_hw_params(struct snd_pcm_substream *substream,
 		break;
 	default:
 		return -EINVAL;
-	}
+	}*/
+
+	//MIC1N/P and MIC2N/P can only line to ADCL, so set mono type.
+	adc_aif1 |= RK616_ADC_TYPE_MONO;
 
 	adc_aif1 |= RK616_ADC_SWAP_DIS;
 	adc_aif2 |= RK616_ADC_RST_DIS;
@@ -2075,6 +2078,19 @@ static int rk616_remove(struct snd_soc_codec *codec)
 {
 	DBG("%s\n", __func__);
 
+	if (!rk616_priv) {
+		printk("%s : rk616_priv is NULL\n", __func__);
+		return 0;
+	}
+
+	if (rk616_priv->spk_ctl_gpio != INVALID_GPIO)
+		gpio_set_value(rk616_priv->spk_ctl_gpio, GPIO_LOW);
+
+	if (rk616_priv->hp_ctl_gpio != INVALID_GPIO)
+		gpio_set_value(rk616_priv->hp_ctl_gpio, GPIO_LOW);
+
+	mdelay(10);
+
 	if (rk616_for_mid)
 	{
 		cancel_delayed_work_sync(&capture_delayed_work);
@@ -2082,16 +2098,13 @@ static int rk616_remove(struct snd_soc_codec *codec)
 		if (rk616_codec_work_capture_type != RK616_CODEC_WORK_NULL) {
 			rk616_codec_work_capture_type = RK616_CODEC_WORK_NULL;
 		}
-		rk616_codec_power_down(RK616_CODEC_ALL);
-	}
-	else
-	{
-		snd_soc_write(codec, RK616_RESET, 0xfc);
-		mdelay(10);
-		snd_soc_write(codec, RK616_RESET, 0x3);
-		mdelay(10);
 	}
 
+	snd_soc_write(codec, RK616_RESET, 0xfc);
+	mdelay(10);
+	snd_soc_write(codec, RK616_RESET, 0x3);
+	mdelay(10);
+
 	if (rk616_priv)
 		kfree(rk616_priv);
 
@@ -2163,12 +2176,14 @@ void rk616_platform_shutdown(struct platform_device *pdev)
 		if (rk616_codec_work_capture_type != RK616_CODEC_WORK_NULL) {
 			rk616_codec_work_capture_type = RK616_CODEC_WORK_NULL;
 		}
-		rk616_codec_power_down(RK616_CODEC_ALL);
-	} else {
-		snd_soc_write(rk616_priv->codec, RK616_RESET, 0xfc);
-		mdelay(10);
-		snd_soc_write(rk616_priv->codec, RK616_RESET, 0x3);
 	}
+
+	snd_soc_write(rk616_priv->codec, RK616_RESET, 0xfc);
+	mdelay(10);
+	snd_soc_write(rk616_priv->codec, RK616_RESET, 0x3);
+
+	if (rk616_priv)
+		kfree(rk616_priv);
 }
 
 static struct platform_driver rk616_codec_driver = {
-- 
2.34.1