Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 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> |
Jordan Crouse | c8974be | 2008-11-06 16:43:53 -0500 | [diff] [blame] | 6 | |
| 7 | #include <asm/olpc.h> |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 8 | #include "cs5535audio.h" |
| 9 | |
| 10 | /* OLPC has an additional feature on top of regular AD1888 codec |
| 11 | features. This is support for an analog input mode. This is a |
| 12 | 2 step process. First, to turn off the AD1888 codec bias voltage |
| 13 | and high pass filter. Second, to tell the embedded controller to |
| 14 | reroute from a capacitive trace to a direct trace using an analog |
| 15 | switch. The *_ec()s are what talk to that controller */ |
| 16 | |
| 17 | static 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) |
| 29 | static 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); |
Andres Salomon | 1e2232b | 2008-11-06 16:47:05 -0500 | [diff] [blame^] | 33 | u8 val; |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 34 | |
Andres Salomon | 1e2232b | 2008-11-06 16:47:05 -0500 | [diff] [blame^] | 35 | val = snd_ac97_read(cs5535au->ac97, AC97_AD_TEST2); |
| 36 | val >>= AC97_AD_HPFD_SHIFT; |
| 37 | ucontrol->value.integer.value[0] = val & 0x1; |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static 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 | |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 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 | |
Jordan Crouse | c8974be | 2008-11-06 16:43:53 -0500 | [diff] [blame] | 63 | /* B2 and newer writes directly to a GPIO pin */ |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 64 | if (value) |
Jordan Crouse | c8974be | 2008-11-06 16:43:53 -0500 | [diff] [blame] | 65 | geode_gpio_set(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL); |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 66 | else |
Jordan Crouse | c8974be | 2008-11-06 16:43:53 -0500 | [diff] [blame] | 67 | geode_gpio_clear(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL); |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 68 | |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 69 | return 1; |
| 70 | } |
| 71 | |
| 72 | static 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 | |
Andres Salomon | 3556d18 | 2008-11-06 16:44:08 -0500 | [diff] [blame] | 82 | void __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 | |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 93 | int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97) |
| 94 | { |
Jordan Crouse | c8974be | 2008-11-06 16:43:53 -0500 | [diff] [blame] | 95 | if (!machine_is_olpc()) |
| 96 | return 0; |
| 97 | |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 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 | |