ASoC: tlv320dac33: Introduce prefill and playback state handlers
authorPeter Ujfalusi <peter.ujfalusi@nokia.com>
Thu, 31 Dec 2009 08:30:20 +0000 (10:30 +0200)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Thu, 31 Dec 2009 11:54:27 +0000 (11:54 +0000)
Ensure that the code is going to be readable, when new FIFO modes
are introduced later.
Move the prefill and playback state handling to inlined
functions.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@nokia.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
sound/soc/codecs/tlv320dac33.c

index b67961d..f7c7bbc 100644 (file)
@@ -543,6 +543,44 @@ static int dac33_set_bias_level(struct snd_soc_codec *codec,
        return 0;
 }
 
+static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
+{
+       struct snd_soc_codec *codec;
+
+       codec = &dac33->codec;
+
+       switch (dac33->fifo_mode) {
+       case DAC33_FIFO_MODE1:
+               dac33_write16(codec, DAC33_NSAMPLE_MSB,
+                               DAC33_THRREG(dac33->nsample));
+               dac33_write16(codec, DAC33_PREFILL_MSB,
+                               DAC33_THRREG(dac33->alarm_threshold));
+               break;
+       default:
+               dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
+                                                       dac33->fifo_mode);
+               break;
+       }
+}
+
+static inline void dac33_playback_handler(struct tlv320dac33_priv *dac33)
+{
+       struct snd_soc_codec *codec;
+
+       codec = &dac33->codec;
+
+       switch (dac33->fifo_mode) {
+       case DAC33_FIFO_MODE1:
+               dac33_write16(codec, DAC33_NSAMPLE_MSB,
+                               DAC33_THRREG(dac33->nsample));
+               break;
+       default:
+               dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
+                                                       dac33->fifo_mode);
+               break;
+       }
+}
+
 static void dac33_work(struct work_struct *work)
 {
        struct snd_soc_codec *codec;
@@ -556,14 +594,10 @@ static void dac33_work(struct work_struct *work)
        switch (dac33->state) {
        case DAC33_PREFILL:
                dac33->state = DAC33_PLAYBACK;
-               dac33_write16(codec, DAC33_NSAMPLE_MSB,
-                               DAC33_THRREG(dac33->nsample));
-               dac33_write16(codec, DAC33_PREFILL_MSB,
-                               DAC33_THRREG(dac33->alarm_threshold));
+               dac33_prefill_handler(dac33);
                break;
        case DAC33_PLAYBACK:
-               dac33_write16(codec, DAC33_NSAMPLE_MSB,
-                               DAC33_THRREG(dac33->nsample));
+               dac33_playback_handler(dac33);
                break;
        case DAC33_IDLE:
                break;