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 | |
Andres Salomon | d6276b7 | 2008-11-06 16:49:38 -0500 | [diff] [blame] | 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 | } |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 33 | |
Andres Salomon | 466ae3055 | 2008-11-06 16:49:46 -0500 | [diff] [blame] | 34 | static int olpc_dc_info(struct snd_kcontrol *kctl, |
| 35 | struct snd_ctl_elem_info *uinfo) |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 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 | |
Andres Salomon | 466ae3055 | 2008-11-06 16:49:46 -0500 | [diff] [blame] | 44 | static int olpc_dc_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v) |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 45 | { |
Andres Salomon | 189d34e | 2008-11-06 16:49:55 -0500 | [diff] [blame^] | 46 | v->value.integer.value[0] = geode_gpio_isset(OLPC_GPIO_MIC_AC, |
| 47 | GPIO_OUTPUT_VAL); |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
Andres Salomon | 466ae3055 | 2008-11-06 16:49:46 -0500 | [diff] [blame] | 51 | static int olpc_dc_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v) |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 52 | { |
Andres Salomon | 466ae3055 | 2008-11-06 16:49:46 -0500 | [diff] [blame] | 53 | struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl); |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 54 | |
Andres Salomon | 466ae3055 | 2008-11-06 16:49:46 -0500 | [diff] [blame] | 55 | olpc_analog_input(cs5535au->ac97, v->value.integer.value[0]); |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 56 | return 1; |
| 57 | } |
| 58 | |
| 59 | static struct snd_kcontrol_new snd_cs5535audio_controls __devinitdata = |
| 60 | { |
| 61 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Andres Salomon | 466ae3055 | 2008-11-06 16:49:46 -0500 | [diff] [blame] | 62 | .name = "DC Mode Enable", |
| 63 | .info = olpc_dc_info, |
| 64 | .get = olpc_dc_get, |
| 65 | .put = olpc_dc_put, |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 66 | .private_value = 0 |
| 67 | }; |
| 68 | |
Andres Salomon | 3556d18 | 2008-11-06 16:44:08 -0500 | [diff] [blame] | 69 | void __devinit olpc_prequirks(struct snd_card *card, |
| 70 | struct snd_ac97_template *ac97) |
| 71 | { |
| 72 | if (!machine_is_olpc()) |
| 73 | return; |
| 74 | |
| 75 | /* invert EAPD if on an OLPC B3 or higher */ |
| 76 | if (olpc_board_at_least(olpc_board_pre(0xb3))) |
| 77 | ac97->scaps |= AC97_SCAP_INV_EAPD; |
| 78 | } |
| 79 | |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 80 | int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97) |
| 81 | { |
Andres Salomon | 466ae3055 | 2008-11-06 16:49:46 -0500 | [diff] [blame] | 82 | struct snd_ctl_elem_id elem; |
| 83 | |
Jordan Crouse | c8974be | 2008-11-06 16:43:53 -0500 | [diff] [blame] | 84 | if (!machine_is_olpc()) |
| 85 | return 0; |
| 86 | |
Andres Salomon | 466ae3055 | 2008-11-06 16:49:46 -0500 | [diff] [blame] | 87 | /* drop the original AD1888 HPF control */ |
| 88 | memset(&elem, 0, sizeof(elem)); |
| 89 | elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 90 | strncpy(elem.name, "High Pass Filter Enable", sizeof(elem.name)); |
| 91 | snd_ctl_remove_id(card, &elem); |
| 92 | |
| 93 | /* add the override for OLPC's HPF */ |
Jaya Kumar | 57d4bf6 | 2008-11-06 16:43:34 -0500 | [diff] [blame] | 94 | return snd_ctl_add(card, snd_ctl_new1(&snd_cs5535audio_controls, |
| 95 | ac97->private_data)); |
| 96 | } |
| 97 | |