1 #include <linux/olpc.h>
2 #include <sound/driver.h>
3 #include <sound/core.h>
4 #include <sound/info.h>
5 #include <sound/control.h>
6 #include <sound/ac97_codec.h>
7 #include "cs5535audio.h"
9 /* OLPC has an additional feature on top of regular AD1888 codec
10 features. This is support for an analog input mode. This is a
11 2 step process. First, to turn off the AD1888 codec bias voltage
12 and high pass filter. Second, to tell the embedded controller to
13 reroute from a capacitive trace to a direct trace using an analog
14 switch. The *_ec()s are what talk to that controller */
16 static int snd_cs5535audio_ctl_info(struct snd_kcontrol *kcontrol,
17 struct snd_ctl_elem_info *uinfo)
19 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
21 uinfo->value.integer.min = 0;
22 uinfo->value.integer.max = 1;
26 #define AD1888_VREFOUT_EN_BIT (1 << 2)
27 #define AD1888_HPF_EN_BIT (1 << 12)
28 static int snd_cs5535audio_ctl_get(struct snd_kcontrol *kcontrol,
29 struct snd_ctl_elem_value *ucontrol)
31 struct cs5535audio *cs5535au = snd_kcontrol_chip(kcontrol);
34 /* if either AD1888 VRef Bias and High Pass Filter are enabled
35 or the EC is not in analog mode then flag as not in analog mode.
36 No EC command to read current analog state so we cache that. */
37 reg1 = snd_ac97_read(cs5535au->ac97, AC97_AD_MISC);
38 reg2 = snd_ac97_read(cs5535au->ac97, AC97_AD_TEST2);
40 if ((reg1 & AD1888_VREFOUT_EN_BIT) && (reg2 & AD1888_HPF_EN_BIT) &&
41 cs5535au->ec_analog_input_mode)
42 ucontrol->value.integer.value[0] = 1;
44 ucontrol->value.integer.value[0] = 0;
49 static int snd_cs5535audio_ctl_put(struct snd_kcontrol *kcontrol,
50 struct snd_ctl_elem_value *ucontrol)
53 struct cs5535audio *cs5535au = snd_kcontrol_chip(kcontrol);
55 struct snd_ac97 *ac97 = cs5535au->ac97;
57 /* value is 1 if analog input is desired */
58 value = ucontrol->value.integer.value[0];
60 /* use ec mode as flag to determine if any change needed */
61 if (cs5535au->ec_analog_input_mode == value)
64 /* sets High Z on VREF Bias if 1 */
66 err = snd_ac97_update_bits(ac97, AC97_AD_MISC,
67 AD1888_VREFOUT_EN_BIT, AD1888_VREFOUT_EN_BIT);
69 err = snd_ac97_update_bits(ac97, AC97_AD_MISC,
70 AD1888_VREFOUT_EN_BIT, 0);
72 snd_printk(KERN_ERR "Error updating AD_MISC %d\n", err);
74 /* turns off High Pass Filter if 1 */
76 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
77 AD1888_HPF_EN_BIT, AD1888_HPF_EN_BIT);
79 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
80 AD1888_HPF_EN_BIT, 0);
82 snd_printk(KERN_ERR "Error updating AD_TEST2 %d\n", err);
85 err = write_ec_command(0x01); /* activate MIC_AC_OFF */
87 err = write_ec_command(0x02); /* deactivates MIC_AC_OFF */
90 snd_printk(KERN_ERR "Error talking to EC %d\n", err);
92 cs5535au->ec_analog_input_mode = value;
97 static struct snd_kcontrol_new snd_cs5535audio_controls __devinitdata =
99 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
100 .name = "Analog Input Switch",
101 .info = snd_cs5535audio_ctl_info,
102 .get = snd_cs5535audio_ctl_get,
103 .put = snd_cs5535audio_ctl_put,
107 int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
109 /* setup callback for mixer control that does analog input mode */
110 return snd_ctl_add(card, snd_ctl_new1(&snd_cs5535audio_controls,
111 ac97->private_data));