[ALSA] hda-codec - Clean up bind-controls
authorTakashi Iwai <tiwai@suse.de>
Fri, 10 Aug 2007 15:12:15 +0000 (17:12 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 16 Oct 2007 13:58:45 +0000 (15:58 +0200)
We have already a generic bind-control helper, so let's clean up the codes
using it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@suse.cz>
sound/pci/hda/patch_analog.c
sound/pci/hda/patch_conexant.c
sound/pci/hda/patch_realtek.c
sound/pci/hda/patch_sigmatel.c

index febc2053f08e9e4ba7afc6d5a1de70a272c8b92c..f9390a544ea4abb9de5bbd06d2722b63c6fa8739 100644 (file)
@@ -1127,23 +1127,14 @@ static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
 }
 
 /* bind volumes of both NID 0x05 and 0x06 */
-static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
-                                   struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       long *valp = ucontrol->value.integer.value;
-       int change;
-
-       change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
-                                         HDA_AMP_VOLMASK, valp[0]);
-       change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
-                                          HDA_AMP_VOLMASK, valp[1]);
-       snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
-                                HDA_AMP_VOLMASK, valp[0]);
-       snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
-                                HDA_AMP_VOLMASK, valp[1]);
-       return change;
-}
+static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
+       .ops = &snd_hda_bind_vol,
+       .values = {
+               HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
+               0
+       },
+};
 
 /* mute internal speaker if HP is plugged */
 static void ad1981_hp_automute(struct hda_codec *codec)
@@ -1204,14 +1195,7 @@ static struct hda_input_mux ad1981_hp_capture_source = {
 };
 
 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Volume",
-               .info = snd_hda_mixer_amp_volume_info,
-               .get = snd_hda_mixer_amp_volume_get,
-               .put = ad1981_hp_master_vol_put,
-               .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
-       },
+       HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
        {
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
                .name = "Master Playback Switch",
index ebf83275756ec51018d906f171ef72523aa51cce..080e3001d9c548d0e775425b7ce94b743de88782 100644 (file)
@@ -483,23 +483,14 @@ static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
 }
 
 /* bind volumes of both NID 0x10 and 0x11 */
-static int cxt5045_hp_master_vol_put(struct snd_kcontrol *kcontrol,
-                                    struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       long *valp = ucontrol->value.integer.value;
-       int change;
-
-       change = snd_hda_codec_amp_update(codec, 0x10, 0, HDA_OUTPUT, 0,
-                                         HDA_AMP_VOLMASK, valp[0]);
-       change |= snd_hda_codec_amp_update(codec, 0x10, 1, HDA_OUTPUT, 0,
-                                          HDA_AMP_VOLMASK, valp[1]);
-       snd_hda_codec_amp_update(codec, 0x11, 0, HDA_OUTPUT, 0,
-                                HDA_AMP_VOLMASK, valp[0]);
-       snd_hda_codec_amp_update(codec, 0x11, 1, HDA_OUTPUT, 0,
-                                HDA_AMP_VOLMASK, valp[1]);
-       return change;
-}
+static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
+       .ops = &snd_hda_bind_vol,
+       .values = {
+               HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
+               0
+       },
+};
 
 /* toggle input of built-in and mic jack appropriately */
 static void cxt5045_hp_automic(struct hda_codec *codec)
@@ -567,14 +558,7 @@ static struct snd_kcontrol_new cxt5045_mixers[] = {
        HDA_CODEC_MUTE("Int Mic Switch", 0x1a, 0x01, HDA_INPUT),
        HDA_CODEC_VOLUME("Ext Mic Volume", 0x1a, 0x02, HDA_INPUT),
        HDA_CODEC_MUTE("Ext Mic Switch", 0x1a, 0x02, HDA_INPUT),
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Volume",
-               .info = snd_hda_mixer_amp_volume_info,
-               .get = snd_hda_mixer_amp_volume_get,
-               .put = cxt5045_hp_master_vol_put,
-               .private_value = HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
-       },
+       HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
        {
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
                .name = "Master Playback Switch",
@@ -897,23 +881,14 @@ static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
 }
 
 /* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
-static int cxt5047_hp_master_vol_put(struct snd_kcontrol *kcontrol,
-                                    struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       long *valp = ucontrol->value.integer.value;
-       int change;
-
-       change = snd_hda_codec_amp_update(codec, 0x1d, 0, HDA_OUTPUT, 0,
-                                         HDA_AMP_VOLMASK, valp[0]);
-       change |= snd_hda_codec_amp_update(codec, 0x1d, 1, HDA_OUTPUT, 0,
-                                          HDA_AMP_VOLMASK, valp[1]);
-       snd_hda_codec_amp_update(codec, 0x13, 0, HDA_OUTPUT, 0,
-                                HDA_AMP_VOLMASK, valp[0]);
-       snd_hda_codec_amp_update(codec, 0x13, 1, HDA_OUTPUT, 0,
-                                HDA_AMP_VOLMASK, valp[1]);
-       return change;
-}
+static struct hda_bind_ctls cxt5047_bind_master_vol = {
+       .ops = &snd_hda_bind_vol,
+       .values = {
+               HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
+               0
+       },
+};
 
 /* mute internal speaker if HP is plugged */
 static void cxt5047_hp_automute(struct hda_codec *codec)
@@ -1035,14 +1010,7 @@ static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
        HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
        HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
        HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Volume",
-               .info = snd_hda_mixer_amp_volume_info,
-               .get = snd_hda_mixer_amp_volume_get,
-               .put = cxt5047_hp_master_vol_put,
-               .private_value = HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
-       },
+       HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
        {
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
                .name = "Master Playback Switch",
index 29119fd4017df4b34fea9aee53b9a9d41694610c..ebbabeb3293039ade8f4d64edf4c031f20257026 100644 (file)
@@ -7408,23 +7408,14 @@ static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
 }
 
 /* bind volumes of both NID 0x0c and 0x0d */
-static int alc262_fujitsu_master_vol_put(struct snd_kcontrol *kcontrol,
-                                        struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       long *valp = ucontrol->value.integer.value;
-       int change;
-
-       change = snd_hda_codec_amp_update(codec, 0x0c, 0, HDA_OUTPUT, 0,
-                                         HDA_AMP_VOLMASK, valp[0]);
-       change |= snd_hda_codec_amp_update(codec, 0x0c, 1, HDA_OUTPUT, 0,
-                                          HDA_AMP_VOLMASK, valp[1]);
-       snd_hda_codec_amp_update(codec, 0x0d, 0, HDA_OUTPUT, 0,
-                                HDA_AMP_VOLMASK, valp[0]);
-       snd_hda_codec_amp_update(codec, 0x0d, 1, HDA_OUTPUT, 0,
-                                HDA_AMP_VOLMASK, valp[1]);
-       return change;
-}
+static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
+       .ops = &snd_hda_bind_vol,
+       .values = {
+               HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
+               0
+       },
+};
 
 /* bind hp and internal speaker mute (with plug check) */
 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
@@ -7446,15 +7437,7 @@ static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
 }
 
 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Volume",
-               .info = snd_hda_mixer_amp_volume_info,
-               .get = snd_hda_mixer_amp_volume_get,
-               .put = alc262_fujitsu_master_vol_put,
-               .tlv = { .c = snd_hda_mixer_amp_tlv },
-               .private_value = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
-       },
+       HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
        {
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
                .name = "Master Playback Switch",
index 1690726c1e136d7131088b96281a5e93ccb77bfd..bf5d91b63d157710854a4d8baecd0f63d62b09a6 100644 (file)
@@ -2400,63 +2400,28 @@ static struct hda_verb vaio_ar_init[] = {
 };
 
 /* bind volumes of both NID 0x02 and 0x05 */
-static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
-                              struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       long *valp = ucontrol->value.integer.value;
-       int change;
-
-       change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
-                                         HDA_AMP_VOLMASK, valp[0]);
-       change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
-                                          HDA_AMP_VOLMASK, valp[1]);
-       snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
-                                HDA_AMP_VOLMASK, valp[0]);
-       snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
-                                HDA_AMP_VOLMASK, valp[1]);
-       return change;
-}
+static struct hda_bind_ctls vaio_bind_master_vol = {
+       .ops = &snd_hda_bind_vol,
+       .values = {
+               HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
+               0
+       },
+};
 
 /* bind volumes of both NID 0x02 and 0x05 */
-static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
-                             struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       long *valp = ucontrol->value.integer.value;
-       int change;
-
-       change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
-                                         HDA_AMP_MUTE,
-                                         (valp[0] ? 0 : HDA_AMP_MUTE));
-       change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
-                                          HDA_AMP_MUTE,
-                                          (valp[1] ? 0 : HDA_AMP_MUTE));
-       snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
-                                HDA_AMP_MUTE, (valp[0] ? 0 : HDA_AMP_MUTE));
-       snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
-                                HDA_AMP_MUTE, (valp[1] ? 0 : HDA_AMP_MUTE));
-       return change;
-}
+static struct hda_bind_ctls vaio_bind_master_sw = {
+       .ops = &snd_hda_bind_sw,
+       .values = {
+               HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
+               HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
+               0,
+       },
+};
 
 static struct snd_kcontrol_new vaio_mixer[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Volume",
-               .info = snd_hda_mixer_amp_volume_info,
-               .get = snd_hda_mixer_amp_volume_get,
-               .put = vaio_master_vol_put,
-               .tlv = { .c = snd_hda_mixer_amp_tlv },
-               .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
-       },
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Switch",
-               .info = snd_hda_mixer_amp_switch_info,
-               .get = snd_hda_mixer_amp_switch_get,
-               .put = vaio_master_sw_put,
-               .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
-       },
+       HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
+       HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
        /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
        HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
        HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
@@ -2472,22 +2437,8 @@ static struct snd_kcontrol_new vaio_mixer[] = {
 };
 
 static struct snd_kcontrol_new vaio_ar_mixer[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Volume",
-               .info = snd_hda_mixer_amp_volume_info,
-               .get = snd_hda_mixer_amp_volume_get,
-               .put = vaio_master_vol_put,
-               .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
-       },
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Switch",
-               .info = snd_hda_mixer_amp_switch_info,
-               .get = snd_hda_mixer_amp_switch_get,
-               .put = vaio_master_sw_put,
-               .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
-       },
+       HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
+       HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
        /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
        HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
        HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),