ASoC: pxa: magician: Convert to table based DAPM and control setup
authorLars-Peter Clausen <lars@metafoo.de>
Wed, 12 Mar 2014 14:27:38 +0000 (15:27 +0100)
committerMark Brown <broonie@linaro.org>
Thu, 13 Mar 2014 09:41:00 +0000 (09:41 +0000)
Use table based setup to register the controls and DAPM widgets and routes. This
on one hand makes the code a bit shorter and cleaner and on the other hand the
board level DAPM elements get registered in the card's DAPM context rather than
in the CODEC's DAPM context.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
sound/soc/pxa/magician.c

index 41ab667..259e048 100644 (file)
@@ -41,9 +41,8 @@ static int magician_hp_switch;
 static int magician_spk_switch = 1;
 static int magician_in_sel = MAGICIAN_MIC;
 
-static void magician_ext_control(struct snd_soc_codec *codec)
+static void magician_ext_control(struct snd_soc_dapm_context *dapm)
 {
-       struct snd_soc_dapm_context *dapm = &codec->dapm;
 
        snd_soc_dapm_mutex_lock(dapm);
 
@@ -75,10 +74,9 @@ static void magician_ext_control(struct snd_soc_codec *codec)
 static int magician_startup(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec *codec = rtd->codec;
 
        /* check the jack status at stream startup */
-       magician_ext_control(codec);
+       magician_ext_control(&rtd->card->dapm);
 
        return 0;
 }
@@ -277,13 +275,13 @@ static int magician_get_hp(struct snd_kcontrol *kcontrol,
 static int magician_set_hp(struct snd_kcontrol *kcontrol,
                             struct snd_ctl_elem_value *ucontrol)
 {
-       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
 
        if (magician_hp_switch == ucontrol->value.integer.value[0])
                return 0;
 
        magician_hp_switch = ucontrol->value.integer.value[0];
-       magician_ext_control(codec);
+       magician_ext_control(&card->dapm);
        return 1;
 }
 
@@ -297,13 +295,13 @@ static int magician_get_spk(struct snd_kcontrol *kcontrol,
 static int magician_set_spk(struct snd_kcontrol *kcontrol,
                            struct snd_ctl_elem_value *ucontrol)
 {
-       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
 
        if (magician_spk_switch == ucontrol->value.integer.value[0])
                return 0;
 
        magician_spk_switch = ucontrol->value.integer.value[0];
-       magician_ext_control(codec);
+       magician_ext_control(&card->dapm);
        return 1;
 }
 
@@ -400,7 +398,6 @@ static int magician_uda1380_init(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_soc_codec *codec = rtd->codec;
        struct snd_soc_dapm_context *dapm = &codec->dapm;
-       int err;
 
        /* NC codec pins */
        snd_soc_dapm_nc_pin(dapm, "VOUTLHP");
@@ -410,19 +407,6 @@ static int magician_uda1380_init(struct snd_soc_pcm_runtime *rtd)
        snd_soc_dapm_nc_pin(dapm, "VINL");
        snd_soc_dapm_nc_pin(dapm, "VINR");
 
-       /* Add magician specific controls */
-       err = snd_soc_add_codec_controls(codec, uda1380_magician_controls,
-                               ARRAY_SIZE(uda1380_magician_controls));
-       if (err < 0)
-               return err;
-
-       /* Add magician specific widgets */
-       snd_soc_dapm_new_controls(dapm, uda1380_dapm_widgets,
-                                 ARRAY_SIZE(uda1380_dapm_widgets));
-
-       /* Set up magician specific audio path interconnects */
-       snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
-
        return 0;
 }
 
@@ -456,6 +440,12 @@ static struct snd_soc_card snd_soc_card_magician = {
        .dai_link = magician_dai,
        .num_links = ARRAY_SIZE(magician_dai),
 
+       .controls = uda1380_magician_controls,
+       .num_controls = ARRAY_SIZE(uda1380_magician_controls),
+       .dapm_widgets = uda1380_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets),
+       .dapm_routes = audio_map,
+       .num_dapm_routes = ARRAY_SIZE(audio_map),
 };
 
 static struct platform_device *magician_snd_device;