cleaning up olpc patch 1
[openwrt.git] / target / linux / olpc / files / sound / pci / cs5535audio / cs5535audio_olpc.c
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>
6
7 #include <asm/olpc.h>
8 #include "cs5535audio.h"
9
10 /*
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.
14  */
15
16 int olpc_ai_enable(struct snd_ac97 *ac97, u8 val)
17 {
18         int err;
19
20         /*
21          * update the High Pass Filter (via AC97_AD_TEST2), and then set
22          * Analog Input mode through a GPIO.
23          */
24
25         if (val) {
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);
29         }
30         else {
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);
34         }
35         if (err < 0)
36                 snd_printk(KERN_ERR "Error updating AD_TEST2: %d\n", err);
37
38         return err;
39 }
40 EXPORT_SYMBOL_GPL(olpc_ai_enable);
41
42 static int snd_cs5535audio_ai_info(struct snd_kcontrol *kcontrol,
43                 struct snd_ctl_elem_info *uinfo)
44 {
45         uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
46         uinfo->count = 1;
47         uinfo->value.integer.min = 0;
48         uinfo->value.integer.max = 1;
49         return 0;
50 }
51
52 static int snd_cs5535audio_ai_get(struct snd_kcontrol *kcontrol,
53                 struct snd_ctl_elem_value *ucontrol)
54 {
55         ucontrol->value.integer.value[0] = geode_gpio_isset(OLPC_GPIO_MIC_AC,
56                         GPIO_OUTPUT_VAL);
57         return 0;
58 }
59
60 static int snd_cs5535audio_ai_put(struct snd_kcontrol *kcontrol,
61                 struct snd_ctl_elem_value *ucontrol)
62 {
63         struct cs5535audio *cs5535au = snd_kcontrol_chip(kcontrol);
64         struct snd_ac97 *ac97 = cs5535au->ac97;
65
66         olpc_ai_enable(ac97, ucontrol->value.integer.value[0]);
67
68         return 1;
69 }
70
71 static struct snd_kcontrol_new snd_cs5535audio_controls __devinitdata =
72 {
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,
78         .private_value = 0
79 };
80
81 void __devinit olpc_prequirks(struct snd_card *card,
82                 struct snd_ac97_template *ac97)
83 {
84         /* Bail if this isn't an OLPC platform */
85         if (!machine_is_olpc())
86                 return;
87
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;
91 }
92
93 int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
94 {
95         struct snd_ctl_elem_id elem;
96
97         /* Bail if this isn't an OLPC platform */
98         if (!machine_is_olpc())
99                 return 0;
100
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);
106
107         /* add the override for OLPC's HPF */
108         return snd_ctl_add(card, snd_ctl_new1(&snd_cs5535audio_controls,
109                         ac97->private_data));
110 }