ALSA: cs5535audio: decouple HPF from V_REFOUT in OLPC code
[deliverable/linux.git] / sound / pci / cs5535audio / cs5535audio_olpc.c
CommitLineData
57d4bf6d
JK
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>
c8974be5
JC
6
7#include <asm/olpc.h>
57d4bf6d
JK
8#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);
1e2232bc 33 u8 val;
57d4bf6d 34
1e2232bc
AS
35 val = snd_ac97_read(cs5535au->ac97, AC97_AD_TEST2);
36 val >>= AC97_AD_HPFD_SHIFT;
37 ucontrol->value.integer.value[0] = val & 0x1;
57d4bf6d
JK
38
39 return 0;
40}
41
42static int snd_cs5535audio_ctl_put(struct snd_kcontrol *kcontrol,
43 struct snd_ctl_elem_value *ucontrol)
44{
45 int err;
46 struct cs5535audio *cs5535au = snd_kcontrol_chip(kcontrol);
47 u8 value;
48 struct snd_ac97 *ac97 = cs5535au->ac97;
49
50 /* value is 1 if analog input is desired */
51 value = ucontrol->value.integer.value[0];
52
57d4bf6d
JK
53 /* turns off High Pass Filter if 1 */
54 if (value)
55 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
56 AD1888_HPF_EN_BIT, AD1888_HPF_EN_BIT);
57 else
58 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
59 AD1888_HPF_EN_BIT, 0);
60 if (err < 0)
61 snd_printk(KERN_ERR "Error updating AD_TEST2 %d\n", err);
62
c8974be5 63 /* B2 and newer writes directly to a GPIO pin */
57d4bf6d 64 if (value)
c8974be5 65 geode_gpio_set(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
57d4bf6d 66 else
c8974be5 67 geode_gpio_clear(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
57d4bf6d 68
57d4bf6d
JK
69 return 1;
70}
71
72static struct snd_kcontrol_new snd_cs5535audio_controls __devinitdata =
73{
74 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
75 .name = "Analog Input Switch",
76 .info = snd_cs5535audio_ctl_info,
77 .get = snd_cs5535audio_ctl_get,
78 .put = snd_cs5535audio_ctl_put,
79 .private_value = 0
80};
81
3556d184
AS
82void __devinit olpc_prequirks(struct snd_card *card,
83 struct snd_ac97_template *ac97)
84{
85 if (!machine_is_olpc())
86 return;
87
88 /* invert EAPD if on an OLPC B3 or higher */
89 if (olpc_board_at_least(olpc_board_pre(0xb3)))
90 ac97->scaps |= AC97_SCAP_INV_EAPD;
91}
92
57d4bf6d
JK
93int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
94{
c8974be5
JC
95 if (!machine_is_olpc())
96 return 0;
97
57d4bf6d
JK
98 /* setup callback for mixer control that does analog input mode */
99 return snd_ctl_add(card, snd_ctl_new1(&snd_cs5535audio_controls,
100 ac97->private_data));
101}
102
This page took 0.034192 seconds and 5 git commands to generate.