blob: 9073fb353f0e0de4ff76170c6f542787e3541590 [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
10/* OLPC has an additional feature on top of regular AD1888 codec
11features. This is support for an analog input mode. This is a
122 step process. First, to turn off the AD1888 codec bias voltage
13and high pass filter. Second, to tell the embedded controller to
14reroute from a capacitive trace to a direct trace using an analog
15switch. The *_ec()s are what talk to that controller */
16
17static int snd_cs5535audio_ctl_info(struct snd_kcontrol *kcontrol,
18 struct snd_ctl_elem_info *uinfo)
19{
20 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
21 uinfo->count = 1;
22 uinfo->value.integer.min = 0;
23 uinfo->value.integer.max = 1;
24 return 0;
25}
26
27#define AD1888_VREFOUT_EN_BIT (1 << 2)
28#define AD1888_HPF_EN_BIT (1 << 12)
29static int snd_cs5535audio_ctl_get(struct snd_kcontrol *kcontrol,
30 struct snd_ctl_elem_value *ucontrol)
31{
32 struct cs5535audio *cs5535au = snd_kcontrol_chip(kcontrol);
33 u16 reg1, reg2;
34
35 /* if either AD1888 VRef Bias and High Pass Filter are enabled
36 or the EC is not in analog mode then flag as not in analog mode.
37 No EC command to read current analog state so we cache that. */
38 reg1 = snd_ac97_read(cs5535au->ac97, AC97_AD_MISC);
39 reg2 = snd_ac97_read(cs5535au->ac97, AC97_AD_TEST2);
40
41 if ((reg1 & AD1888_VREFOUT_EN_BIT) && (reg2 & AD1888_HPF_EN_BIT) &&
42 cs5535au->ec_analog_input_mode)
43 ucontrol->value.integer.value[0] = 1;
44 else
45 ucontrol->value.integer.value[0] = 0;
46
47 return 0;
48}
49
50static int snd_cs5535audio_ctl_put(struct snd_kcontrol *kcontrol,
51 struct snd_ctl_elem_value *ucontrol)
52{
53 int err;
54 struct cs5535audio *cs5535au = snd_kcontrol_chip(kcontrol);
55 u8 value;
56 struct snd_ac97 *ac97 = cs5535au->ac97;
57
58 /* value is 1 if analog input is desired */
59 value = ucontrol->value.integer.value[0];
60
61 /* use ec mode as flag to determine if any change needed */
62 if (cs5535au->ec_analog_input_mode == value)
63 return 0;
64
65 /* sets High Z on VREF Bias if 1 */
66 if (value)
67 err = snd_ac97_update_bits(ac97, AC97_AD_MISC,
68 AD1888_VREFOUT_EN_BIT, AD1888_VREFOUT_EN_BIT);
69 else
70 err = snd_ac97_update_bits(ac97, AC97_AD_MISC,
71 AD1888_VREFOUT_EN_BIT, 0);
72 if (err < 0)
73 snd_printk(KERN_ERR "Error updating AD_MISC %d\n", err);
74
75 /* turns off High Pass Filter if 1 */
76 if (value)
77 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
78 AD1888_HPF_EN_BIT, AD1888_HPF_EN_BIT);
79 else
80 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
81 AD1888_HPF_EN_BIT, 0);
82 if (err < 0)
83 snd_printk(KERN_ERR "Error updating AD_TEST2 %d\n", err);
84
Jordan Crousec8974be2008-11-06 16:43:53 -050085 /* B2 and newer writes directly to a GPIO pin */
Jaya Kumar57d4bf62008-11-06 16:43:34 -050086 if (value)
Jordan Crousec8974be2008-11-06 16:43:53 -050087 geode_gpio_set(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
Jaya Kumar57d4bf62008-11-06 16:43:34 -050088 else
Jordan Crousec8974be2008-11-06 16:43:53 -050089 geode_gpio_clear(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
Jaya Kumar57d4bf62008-11-06 16:43:34 -050090
91 cs5535au->ec_analog_input_mode = value;
92
93 return 1;
94}
95
96static struct snd_kcontrol_new snd_cs5535audio_controls __devinitdata =
97{
98 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
99 .name = "Analog Input Switch",
100 .info = snd_cs5535audio_ctl_info,
101 .get = snd_cs5535audio_ctl_get,
102 .put = snd_cs5535audio_ctl_put,
103 .private_value = 0
104};
105
106int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
107{
Jordan Crousec8974be2008-11-06 16:43:53 -0500108 if (!machine_is_olpc())
109 return 0;
110
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500111 /* setup callback for mixer control that does analog input mode */
112 return snd_ctl_add(card, snd_ctl_new1(&snd_cs5535audio_controls,
113 ac97->private_data));
114}
115