aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs
diff options
context:
space:
mode:
authorPeter Ujfalusi <peter.ujfalusi@ti.com>2011-09-29 08:22:37 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-09-30 08:55:08 -0400
commit009d196b4755b42c02414b287889a337955f7e09 (patch)
tree4ee049f634119b4777490adac0a51247049a1d5b /sound/soc/codecs
parent6fbb32d175368b6ab8fb827e65cd8d18ed04c1f3 (diff)
ASoC: twl6040: Simplify code in out_drv_event for pending work check
Instead of checking, if the work is pending, it is safer to cancel the pending work, or wait till the scheduled work finishes. This way we can avoid modifying the variables used by the work function. Since we know that no work is pending, we can remove the two additional checks in POST_PMU, and PRE_PMD for non pending works. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r--sound/soc/codecs/twl6040.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c
index 738d1022247c..d040905cfa9b 100644
--- a/sound/soc/codecs/twl6040.c
+++ b/sound/soc/codecs/twl6040.c
@@ -565,12 +565,26 @@ static int out_drv_event(struct snd_soc_dapm_widget *w,
565 switch (w->shift) { 565 switch (w->shift) {
566 case 2: /* Headset output driver */ 566 case 2: /* Headset output driver */
567 out = &priv->headset; 567 out = &priv->headset;
568 work = &out->work;
569 /*
570 * Make sure, that we do not mess up variables for already
571 * executing work.
572 */
573 cancel_delayed_work_sync(work);
574
568 out->left_step = priv->hs_left_step; 575 out->left_step = priv->hs_left_step;
569 out->right_step = priv->hs_right_step; 576 out->right_step = priv->hs_right_step;
570 out->step_delay = 5; /* 5 ms between volume ramp steps */ 577 out->step_delay = 5; /* 5 ms between volume ramp steps */
571 break; 578 break;
572 case 4: /* Handsfree output driver */ 579 case 4: /* Handsfree output driver */
573 out = &priv->handsfree; 580 out = &priv->handsfree;
581 work = &out->work;
582 /*
583 * Make sure, that we do not mess up variables for already
584 * executing work.
585 */
586 cancel_delayed_work_sync(work);
587
574 out->left_step = priv->hf_left_step; 588 out->left_step = priv->hf_left_step;
575 out->right_step = priv->hf_right_step; 589 out->right_step = priv->hf_right_step;
576 out->step_delay = 5; /* 5 ms between volume ramp steps */ 590 out->step_delay = 5; /* 5 ms between volume ramp steps */
@@ -583,39 +597,31 @@ static int out_drv_event(struct snd_soc_dapm_widget *w,
583 return -1; 597 return -1;
584 } 598 }
585 599
586 work = &out->work;
587
588 switch (event) { 600 switch (event) {
589 case SND_SOC_DAPM_POST_PMU: 601 case SND_SOC_DAPM_POST_PMU:
590 if (out->active) 602 if (out->active)
591 break; 603 break;
592 604
593 /* don't use volume ramp for power-up */ 605 /* don't use volume ramp for power-up */
606 out->ramp = TWL6040_RAMP_UP;
594 out->left_step = out->left_vol; 607 out->left_step = out->left_vol;
595 out->right_step = out->right_vol; 608 out->right_step = out->right_vol;
596 609
597 if (!delayed_work_pending(work)) { 610 queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1));
598 out->ramp = TWL6040_RAMP_UP;
599 queue_delayed_work(priv->workqueue, work,
600 msecs_to_jiffies(1));
601 }
602 break; 611 break;
603 612
604 case SND_SOC_DAPM_PRE_PMD: 613 case SND_SOC_DAPM_PRE_PMD:
605 if (!out->active) 614 if (!out->active)
606 break; 615 break;
607 616
608 if (!delayed_work_pending(work)) { 617 /* use volume ramp for power-down */
609 /* use volume ramp for power-down */ 618 out->ramp = TWL6040_RAMP_DOWN;
610 out->ramp = TWL6040_RAMP_DOWN; 619 INIT_COMPLETION(out->ramp_done);
611 INIT_COMPLETION(out->ramp_done);
612 620
613 queue_delayed_work(priv->workqueue, work, 621 queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1));
614 msecs_to_jiffies(1));
615 622
616 wait_for_completion_timeout(&out->ramp_done, 623 wait_for_completion_timeout(&out->ramp_done,
617 msecs_to_jiffies(2000)); 624 msecs_to_jiffies(2000));
618 }
619 break; 625 break;
620 } 626 }
621 627