blob: 45b24f718d626a6fb47616adce96ff4de2a732f7 [file] [log] [blame]
Jaya Kumar57d4bf62008-11-06 16:43:34 -05001#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>
Jordan Crousec8974be2008-11-06 16:43:53 -05006
7#include <asm/olpc.h>
Jaya Kumar57d4bf62008-11-06 16:43:34 -05008#include "cs5535audio.h"
9
Andres Salomond6276b72008-11-06 16:49:38 -050010/*
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 supported on B2 and later models.
14 */
15void olpc_analog_input(struct snd_ac97 *ac97, int on)
16{
17 int err;
18
19 /* update the High Pass Filter (via AC97_AD_TEST2) */
20 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
21 1 << AC97_AD_HPFD_SHIFT, on << AC97_AD_HPFD_SHIFT);
22 if (err < 0) {
23 snd_printk(KERN_ERR "setting High Pass Filter - %d\n", err);
24 return;
25 }
26
27 /* set Analog Input through GPIO */
28 if (on)
29 geode_gpio_set(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
30 else
31 geode_gpio_clear(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
32}
Jaya Kumar57d4bf62008-11-06 16:43:34 -050033
Andres Salomonbf1e5272008-11-06 16:53:03 -050034/*
35 * OLPC XO-1's V_REFOUT is a mic bias enable.
36 */
37void olpc_mic_bias(struct snd_ac97 *ac97, int on)
38{
39 int err;
40
41 on = on ? 0 : 1;
42 err = snd_ac97_update_bits(ac97, AC97_AD_MISC,
43 1 << AC97_AD_VREFD_SHIFT, on << AC97_AD_VREFD_SHIFT);
44 if (err < 0)
45 snd_printk(KERN_ERR "setting MIC Bias - %d\n", err);
46}
47
Andres Salomon466ae30552008-11-06 16:49:46 -050048static int olpc_dc_info(struct snd_kcontrol *kctl,
49 struct snd_ctl_elem_info *uinfo)
Jaya Kumar57d4bf62008-11-06 16:43:34 -050050{
51 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
52 uinfo->count = 1;
53 uinfo->value.integer.min = 0;
54 uinfo->value.integer.max = 1;
55 return 0;
56}
57
Andres Salomon466ae30552008-11-06 16:49:46 -050058static int olpc_dc_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
Jaya Kumar57d4bf62008-11-06 16:43:34 -050059{
Andres Salomon189d34e2008-11-06 16:49:55 -050060 v->value.integer.value[0] = geode_gpio_isset(OLPC_GPIO_MIC_AC,
61 GPIO_OUTPUT_VAL);
Jaya Kumar57d4bf62008-11-06 16:43:34 -050062 return 0;
63}
64
Andres Salomon466ae30552008-11-06 16:49:46 -050065static int olpc_dc_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
Jaya Kumar57d4bf62008-11-06 16:43:34 -050066{
Andres Salomon466ae30552008-11-06 16:49:46 -050067 struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
Jaya Kumar57d4bf62008-11-06 16:43:34 -050068
Andres Salomon466ae30552008-11-06 16:49:46 -050069 olpc_analog_input(cs5535au->ac97, v->value.integer.value[0]);
Jaya Kumar57d4bf62008-11-06 16:43:34 -050070 return 1;
71}
72
Andres Salomonbf1e5272008-11-06 16:53:03 -050073static int olpc_mic_info(struct snd_kcontrol *kctl,
74 struct snd_ctl_elem_info *uinfo)
75{
76 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
77 uinfo->count = 1;
78 uinfo->value.integer.min = 0;
79 uinfo->value.integer.max = 1;
80 return 0;
81}
82
83static int olpc_mic_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
84{
85 struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
86 struct snd_ac97 *ac97 = cs5535au->ac97;
87 int i;
88
89 i = (snd_ac97_read(ac97, AC97_AD_MISC) >> AC97_AD_VREFD_SHIFT) & 0x1;
90 v->value.integer.value[0] = i ? 0 : 1;
91 return 0;
92}
93
94static int olpc_mic_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
95{
96 struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
97
98 olpc_mic_bias(cs5535au->ac97, v->value.integer.value[0]);
99 return 1;
100}
101
102static struct snd_kcontrol_new olpc_cs5535audio_ctls[] __devinitdata = {
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500103{
104 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Andres Salomon466ae30552008-11-06 16:49:46 -0500105 .name = "DC Mode Enable",
106 .info = olpc_dc_info,
107 .get = olpc_dc_get,
108 .put = olpc_dc_put,
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500109 .private_value = 0
Andres Salomonbf1e5272008-11-06 16:53:03 -0500110},
111{
112 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
113 .name = "MIC Bias Enable",
114 .info = olpc_mic_info,
115 .get = olpc_mic_get,
116 .put = olpc_mic_put,
117 .private_value = 0,
118},
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500119};
120
Andres Salomon3556d182008-11-06 16:44:08 -0500121void __devinit olpc_prequirks(struct snd_card *card,
122 struct snd_ac97_template *ac97)
123{
124 if (!machine_is_olpc())
125 return;
126
127 /* invert EAPD if on an OLPC B3 or higher */
128 if (olpc_board_at_least(olpc_board_pre(0xb3)))
129 ac97->scaps |= AC97_SCAP_INV_EAPD;
130}
131
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500132int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
133{
Andres Salomon466ae30552008-11-06 16:49:46 -0500134 struct snd_ctl_elem_id elem;
Andres Salomonbf1e5272008-11-06 16:53:03 -0500135 int i, err;
Andres Salomon466ae30552008-11-06 16:49:46 -0500136
Jordan Crousec8974be2008-11-06 16:43:53 -0500137 if (!machine_is_olpc())
138 return 0;
139
Andres Salomon466ae30552008-11-06 16:49:46 -0500140 /* drop the original AD1888 HPF control */
141 memset(&elem, 0, sizeof(elem));
142 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
143 strncpy(elem.name, "High Pass Filter Enable", sizeof(elem.name));
144 snd_ctl_remove_id(card, &elem);
145
Andres Salomonbf1e5272008-11-06 16:53:03 -0500146 /* drop the original V_REFOUT control */
147 memset(&elem, 0, sizeof(elem));
148 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
149 strncpy(elem.name, "V_REFOUT Enable", sizeof(elem.name));
150 snd_ctl_remove_id(card, &elem);
151
152 /* add the OLPC-specific controls */
153 for (i = 0; i < ARRAY_SIZE(olpc_cs5535audio_ctls); i++) {
154 err = snd_ctl_add(card, snd_ctl_new1(&olpc_cs5535audio_ctls[i],
155 ac97->private_data));
156 if (err < 0)
157 return err;
158 }
159
Andres Salomonc8f0eee2008-11-06 16:53:19 -0500160 /* turn off the mic by default */
161 olpc_mic_bias(ac97, 0);
Andres Salomonbf1e5272008-11-06 16:53:03 -0500162 return 0;
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500163}
164