Commit | Line | Data |
---|---|---|
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 | ||
d6276b78 AS |
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 supported on B2 and later models. | |
14 | */ | |
15 | void 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 | } | |
57d4bf6d | 33 | |
466ae305 AS |
34 | static int olpc_dc_info(struct snd_kcontrol *kctl, |
35 | struct snd_ctl_elem_info *uinfo) | |
57d4bf6d JK |
36 | { |
37 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
38 | uinfo->count = 1; | |
39 | uinfo->value.integer.min = 0; | |
40 | uinfo->value.integer.max = 1; | |
41 | return 0; | |
42 | } | |
43 | ||
466ae305 | 44 | static int olpc_dc_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v) |
57d4bf6d | 45 | { |
466ae305 | 46 | struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl); |
1e2232bc | 47 | u8 val; |
57d4bf6d | 48 | |
1e2232bc AS |
49 | val = snd_ac97_read(cs5535au->ac97, AC97_AD_TEST2); |
50 | val >>= AC97_AD_HPFD_SHIFT; | |
466ae305 | 51 | v->value.integer.value[0] = val & 0x1; |
57d4bf6d JK |
52 | |
53 | return 0; | |
54 | } | |
55 | ||
466ae305 | 56 | static int olpc_dc_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v) |
57d4bf6d | 57 | { |
466ae305 | 58 | struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl); |
57d4bf6d | 59 | |
466ae305 | 60 | olpc_analog_input(cs5535au->ac97, v->value.integer.value[0]); |
57d4bf6d JK |
61 | return 1; |
62 | } | |
63 | ||
64 | static struct snd_kcontrol_new snd_cs5535audio_controls __devinitdata = | |
65 | { | |
66 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
466ae305 AS |
67 | .name = "DC Mode Enable", |
68 | .info = olpc_dc_info, | |
69 | .get = olpc_dc_get, | |
70 | .put = olpc_dc_put, | |
57d4bf6d JK |
71 | .private_value = 0 |
72 | }; | |
73 | ||
3556d184 AS |
74 | void __devinit olpc_prequirks(struct snd_card *card, |
75 | struct snd_ac97_template *ac97) | |
76 | { | |
77 | if (!machine_is_olpc()) | |
78 | return; | |
79 | ||
80 | /* invert EAPD if on an OLPC B3 or higher */ | |
81 | if (olpc_board_at_least(olpc_board_pre(0xb3))) | |
82 | ac97->scaps |= AC97_SCAP_INV_EAPD; | |
83 | } | |
84 | ||
57d4bf6d JK |
85 | int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97) |
86 | { | |
466ae305 AS |
87 | struct snd_ctl_elem_id elem; |
88 | ||
c8974be5 JC |
89 | if (!machine_is_olpc()) |
90 | return 0; | |
91 | ||
466ae305 AS |
92 | /* drop the original AD1888 HPF control */ |
93 | memset(&elem, 0, sizeof(elem)); | |
94 | elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
95 | strncpy(elem.name, "High Pass Filter Enable", sizeof(elem.name)); | |
96 | snd_ctl_remove_id(card, &elem); | |
97 | ||
98 | /* add the override for OLPC's HPF */ | |
57d4bf6d JK |
99 | return snd_ctl_add(card, snd_ctl_new1(&snd_cs5535audio_controls, |
100 | ac97->private_data)); | |
101 | } | |
102 |