blob: 597395e6e358c62dde39cb517e3585ecdb4be170 [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
34static int snd_cs5535audio_ctl_info(struct snd_kcontrol *kcontrol,
35 struct snd_ctl_elem_info *uinfo)
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
Jaya Kumar57d4bf62008-11-06 16:43:34 -050044static int snd_cs5535audio_ctl_get(struct snd_kcontrol *kcontrol,
45 struct snd_ctl_elem_value *ucontrol)
46{
47 struct cs5535audio *cs5535au = snd_kcontrol_chip(kcontrol);
Andres Salomon1e2232b2008-11-06 16:47:05 -050048 u8 val;
Jaya Kumar57d4bf62008-11-06 16:43:34 -050049
Andres Salomon1e2232b2008-11-06 16:47:05 -050050 val = snd_ac97_read(cs5535au->ac97, AC97_AD_TEST2);
51 val >>= AC97_AD_HPFD_SHIFT;
52 ucontrol->value.integer.value[0] = val & 0x1;
Jaya Kumar57d4bf62008-11-06 16:43:34 -050053
54 return 0;
55}
56
57static int snd_cs5535audio_ctl_put(struct snd_kcontrol *kcontrol,
58 struct snd_ctl_elem_value *ucontrol)
59{
Jaya Kumar57d4bf62008-11-06 16:43:34 -050060 struct cs5535audio *cs5535au = snd_kcontrol_chip(kcontrol);
Jaya Kumar57d4bf62008-11-06 16:43:34 -050061
Andres Salomond6276b72008-11-06 16:49:38 -050062 olpc_analog_input(cs5535au->ac97, ucontrol->value.integer.value[0]);
Jaya Kumar57d4bf62008-11-06 16:43:34 -050063 return 1;
64}
65
66static struct snd_kcontrol_new snd_cs5535audio_controls __devinitdata =
67{
68 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
69 .name = "Analog Input Switch",
70 .info = snd_cs5535audio_ctl_info,
71 .get = snd_cs5535audio_ctl_get,
72 .put = snd_cs5535audio_ctl_put,
73 .private_value = 0
74};
75
Andres Salomon3556d182008-11-06 16:44:08 -050076void __devinit olpc_prequirks(struct snd_card *card,
77 struct snd_ac97_template *ac97)
78{
79 if (!machine_is_olpc())
80 return;
81
82 /* invert EAPD if on an OLPC B3 or higher */
83 if (olpc_board_at_least(olpc_board_pre(0xb3)))
84 ac97->scaps |= AC97_SCAP_INV_EAPD;
85}
86
Jaya Kumar57d4bf62008-11-06 16:43:34 -050087int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
88{
Jordan Crousec8974be2008-11-06 16:43:53 -050089 if (!machine_is_olpc())
90 return 0;
91
Jaya Kumar57d4bf62008-11-06 16:43:34 -050092 /* setup callback for mixer control that does analog input mode */
93 return snd_ctl_add(card, snd_ctl_new1(&snd_cs5535audio_controls,
94 ac97->private_data));
95}
96