From f62690fe3b656d0b25a324abde6a8ea820d978d2 Mon Sep 17 00:00:00 2001 From: smj Date: Thu, 29 Jan 2015 08:51:26 +0800 Subject: [PATCH] rk312x codec: fix rk312x codec switch state error Signed-off-by: lxt --- sound/soc/codecs/rk312x_codec.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/sound/soc/codecs/rk312x_codec.c b/sound/soc/codecs/rk312x_codec.c index 961d8ed37c0b..38023cf823cc 100755 --- a/sound/soc/codecs/rk312x_codec.c +++ b/sound/soc/codecs/rk312x_codec.c @@ -116,9 +116,9 @@ struct rk312x_codec_priv { long int voice_call_path; struct clk *pclk; struct switch_dev sdev; - struct timer_list timer; struct work_struct work; struct delayed_work init_delayed_work; + struct delayed_work hpdet_work; }; static struct rk312x_codec_priv *rk312x_priv; @@ -2120,8 +2120,8 @@ static int rk312x_suspend(struct snd_soc_codec *codec) val = readl_relaxed(RK_GRF_VIRT + GRF_ACODEC_CON); writel_relaxed(0x1f0013, RK_GRF_VIRT + GRF_ACODEC_CON); val = readl_relaxed(RK_GRF_VIRT + GRF_ACODEC_CON); - printk("GRF_ACODEC_CON is 0x%x\n", val); - del_timer(&rk312x_priv->timer); + cancel_delayed_work_sync(&rk312x_priv->hpdet_work); + } if (rk312x_priv->rk312x_for_mid) { cancel_delayed_work_sync(&capture_delayed_work); @@ -2214,7 +2214,7 @@ static int rk312x_resume(struct snd_soc_codec *codec) writel_relaxed(0x1f001f, RK_GRF_VIRT + GRF_ACODEC_CON); val = readl_relaxed(RK_GRF_VIRT + GRF_ACODEC_CON); printk("GRF_ACODEC_CON is 0x%x\n", val); - add_timer(&rk312x_priv->timer); + schedule_delayed_work(&rk312x_priv->hpdet_work, msecs_to_jiffies(20)); } if (!rk312x_priv->rk312x_for_mid) rk312x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); @@ -2233,11 +2233,11 @@ static irqreturn_t codec_hp_det_isr(int irq, void *data) DBG("%s hp det falling\n", __func__); writel_relaxed(val|0x20002, RK_GRF_VIRT + GRF_ACODEC_CON); } - del_timer(&rk312x_priv->timer); - add_timer(&rk312x_priv->timer); + cancel_delayed_work_sync(&rk312x_priv->hpdet_work); + schedule_delayed_work(&rk312x_priv->hpdet_work, msecs_to_jiffies(20)); return IRQ_HANDLED; } -static void hp_det_timer_func(unsigned long data) +static void hpdet_work_func(struct work_struct *work) { unsigned int val = 0; @@ -2289,9 +2289,6 @@ static void rk312x_delay_workq(struct work_struct *work) IRQF_TRIGGER_RISING, "codec_hp_det", NULL); if (ret < 0) DBG(" codec_hp_det request_irq failed %d\n", ret); - init_timer(&rk312x_codec->timer); - rk312x_codec->timer.function = hp_det_timer_func; - rk312x_codec->timer.expires = jiffies + HZ/100; rk312x_codec->sdev.name = "h2w"; rk312x_codec->sdev.print_name = h2w_print_name; ret = switch_dev_register(&rk312x_codec->sdev); @@ -2305,7 +2302,7 @@ static void rk312x_delay_workq(struct work_struct *work) snd_soc_write(codec, RK312x_DAC_CTL, 0x08); DBG("0xa0 -- 0x%x\n", snd_soc_read(codec, RK312x_DAC_CTL)); /* codec hp det once */ - add_timer(&rk312x_priv->timer); + schedule_delayed_work(&rk312x_priv->hpdet_work, msecs_to_jiffies(100)); } @@ -2351,6 +2348,8 @@ static int rk312x_probe(struct snd_soc_codec *codec) snd_soc_add_codec_controls(codec, rk312x_snd_path_controls, ARRAY_SIZE(rk312x_snd_path_controls)); INIT_DELAYED_WORK(&rk312x_priv->init_delayed_work, rk312x_delay_workq); + INIT_DELAYED_WORK(&rk312x_priv->hpdet_work, hpdet_work_func); + schedule_delayed_work(&rk312x_priv->init_delayed_work, msecs_to_jiffies(3000)); if (rk312x_codec->gpio_debug) { gpio_kobj = kobject_create_and_add("codec-spk-ctl", NULL); @@ -2615,7 +2614,7 @@ void rk312x_platform_shutdown(struct platform_device *pdev) writel_relaxed(0x1f0013, RK_GRF_VIRT + GRF_ACODEC_CON); val = readl_relaxed(RK_GRF_VIRT + GRF_ACODEC_CON); DBG("disable codec_hp_det GRF_ACODEC_CON is 0x%x\n", val); - del_timer(&rk312x_priv->timer); + cancel_delayed_work_sync(&rk312x_priv->hpdet_work); } if (rk312x_priv->spk_ctl_gpio != INVALID_GPIO) -- 2.34.1