1 #include <sound/driver.h>
2 #include <sound/core.h>
3 #include <sound/info.h>
4 #include <sound/control.h>
5 #include <sound/ac97_codec.h>
8 #include "cs5535audio.h"
11 * OLPC has an additional feature on top of the regular AD1888 codec features.
12 * It has an Analog Input mode that is switched into (after disabling the
13 * High Pass Filter) via GPIO. It is only supported on B2 and later models.
16 int olpc_ai_enable(struct snd_ac97 *ac97, u8 val)
21 * update the High Pass Filter (via AC97_AD_TEST2), and then set
22 * Analog Input mode through a GPIO.
26 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
27 1<<AC97_AD_HPFD_SHIFT, 1<<AC97_AD_HPFD_SHIFT);
28 geode_gpio_set(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
31 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
32 1<<AC97_AD_HPFD_SHIFT, 0);
33 geode_gpio_clear(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
36 snd_printk(KERN_ERR "Error updating AD_TEST2: %d\n", err);
40 EXPORT_SYMBOL_GPL(olpc_ai_enable);
42 static int snd_cs5535audio_ai_info(struct snd_kcontrol *kcontrol,
43 struct snd_ctl_elem_info *uinfo)
45 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
47 uinfo->value.integer.min = 0;
48 uinfo->value.integer.max = 1;
52 static int snd_cs5535audio_ai_get(struct snd_kcontrol *kcontrol,
53 struct snd_ctl_elem_value *ucontrol)
55 ucontrol->value.integer.value[0] = geode_gpio_isset(OLPC_GPIO_MIC_AC,
60 static int snd_cs5535audio_ai_put(struct snd_kcontrol *kcontrol,
61 struct snd_ctl_elem_value *ucontrol)
63 struct cs5535audio *cs5535au = snd_kcontrol_chip(kcontrol);
64 struct snd_ac97 *ac97 = cs5535au->ac97;
66 olpc_ai_enable(ac97, ucontrol->value.integer.value[0]);
71 static struct snd_kcontrol_new snd_cs5535audio_controls __devinitdata =
73 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
74 .name = "DC Mode Enable",
75 .info = snd_cs5535audio_ai_info,
76 .get = snd_cs5535audio_ai_get,
77 .put = snd_cs5535audio_ai_put,
81 void __devinit olpc_prequirks(struct snd_card *card,
82 struct snd_ac97_template *ac97)
84 /* Bail if this isn't an OLPC platform */
85 if (!machine_is_olpc())
88 /* If on an OLPC B3 or higher, invert EAPD. */
89 if (olpc_rev_after(OLPC_REV_B2))
90 ac97->scaps |= AC97_SCAP_INV_EAPD;
93 int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
95 struct snd_ctl_elem_id elem;
97 /* Bail if this isn't an OLPC platform */
98 if (!machine_is_olpc())
101 /* drop the original ad1888 HPF control */
102 memset(&elem, 0, sizeof(elem));
103 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
104 strcpy(elem.name, "High Pass Filter Enable");
105 snd_ctl_remove_id(card, &elem);
107 /* add the override for OLPC's HPF */
108 return snd_ctl_add(card, snd_ctl_new1(&snd_cs5535audio_controls,
109 ac97->private_data));