blob: 164f6bdab9915628b5ddff4a986339952ea17f31 [file] [log] [blame]
Andres Salomonb5ccc572008-11-06 16:53:26 -05001/*
2 * OLPC XO-1 additional sound features
3 *
4 * Copyright © 2006 Jaya Kumar <jayakumar.lkml@gmail.com>
5 * Copyright © 2007-2008 Andres Salomon <dilinger@debian.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
Jaya Kumar57d4bf62008-11-06 16:43:34 -050012#include <sound/core.h>
13#include <sound/info.h>
14#include <sound/control.h>
15#include <sound/ac97_codec.h>
Jordan Crousec8974be2008-11-06 16:43:53 -050016
17#include <asm/olpc.h>
Jaya Kumar57d4bf62008-11-06 16:43:34 -050018#include "cs5535audio.h"
19
Andres Salomond6276b72008-11-06 16:49:38 -050020/*
21 * OLPC has an additional feature on top of the regular AD1888 codec features.
22 * It has an Analog Input mode that is switched into (after disabling the
23 * High Pass Filter) via GPIO. It is supported on B2 and later models.
24 */
25void olpc_analog_input(struct snd_ac97 *ac97, int on)
26{
27 int err;
28
29 /* update the High Pass Filter (via AC97_AD_TEST2) */
30 err = snd_ac97_update_bits(ac97, AC97_AD_TEST2,
31 1 << AC97_AD_HPFD_SHIFT, on << AC97_AD_HPFD_SHIFT);
32 if (err < 0) {
33 snd_printk(KERN_ERR "setting High Pass Filter - %d\n", err);
34 return;
35 }
36
37 /* set Analog Input through GPIO */
38 if (on)
39 geode_gpio_set(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
40 else
41 geode_gpio_clear(OLPC_GPIO_MIC_AC, GPIO_OUTPUT_VAL);
42}
Jaya Kumar57d4bf62008-11-06 16:43:34 -050043
Andres Salomonbf1e5272008-11-06 16:53:03 -050044/*
45 * OLPC XO-1's V_REFOUT is a mic bias enable.
46 */
47void olpc_mic_bias(struct snd_ac97 *ac97, int on)
48{
49 int err;
50
51 on = on ? 0 : 1;
52 err = snd_ac97_update_bits(ac97, AC97_AD_MISC,
53 1 << AC97_AD_VREFD_SHIFT, on << AC97_AD_VREFD_SHIFT);
54 if (err < 0)
55 snd_printk(KERN_ERR "setting MIC Bias - %d\n", err);
56}
57
Andres Salomon466ae30552008-11-06 16:49:46 -050058static int olpc_dc_info(struct snd_kcontrol *kctl,
59 struct snd_ctl_elem_info *uinfo)
Jaya Kumar57d4bf62008-11-06 16:43:34 -050060{
61 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
62 uinfo->count = 1;
63 uinfo->value.integer.min = 0;
64 uinfo->value.integer.max = 1;
65 return 0;
66}
67
Andres Salomon466ae30552008-11-06 16:49:46 -050068static int olpc_dc_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
Jaya Kumar57d4bf62008-11-06 16:43:34 -050069{
Andres Salomon189d34e2008-11-06 16:49:55 -050070 v->value.integer.value[0] = geode_gpio_isset(OLPC_GPIO_MIC_AC,
71 GPIO_OUTPUT_VAL);
Jaya Kumar57d4bf62008-11-06 16:43:34 -050072 return 0;
73}
74
Andres Salomon466ae30552008-11-06 16:49:46 -050075static int olpc_dc_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
Jaya Kumar57d4bf62008-11-06 16:43:34 -050076{
Andres Salomon466ae30552008-11-06 16:49:46 -050077 struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
Jaya Kumar57d4bf62008-11-06 16:43:34 -050078
Andres Salomon466ae30552008-11-06 16:49:46 -050079 olpc_analog_input(cs5535au->ac97, v->value.integer.value[0]);
Jaya Kumar57d4bf62008-11-06 16:43:34 -050080 return 1;
81}
82
Andres Salomonbf1e5272008-11-06 16:53:03 -050083static int olpc_mic_info(struct snd_kcontrol *kctl,
84 struct snd_ctl_elem_info *uinfo)
85{
86 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
87 uinfo->count = 1;
88 uinfo->value.integer.min = 0;
89 uinfo->value.integer.max = 1;
90 return 0;
91}
92
93static int olpc_mic_get(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
94{
95 struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
96 struct snd_ac97 *ac97 = cs5535au->ac97;
97 int i;
98
99 i = (snd_ac97_read(ac97, AC97_AD_MISC) >> AC97_AD_VREFD_SHIFT) & 0x1;
100 v->value.integer.value[0] = i ? 0 : 1;
101 return 0;
102}
103
104static int olpc_mic_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *v)
105{
106 struct cs5535audio *cs5535au = snd_kcontrol_chip(kctl);
107
108 olpc_mic_bias(cs5535au->ac97, v->value.integer.value[0]);
109 return 1;
110}
111
112static struct snd_kcontrol_new olpc_cs5535audio_ctls[] __devinitdata = {
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500113{
114 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Andres Salomon466ae30552008-11-06 16:49:46 -0500115 .name = "DC Mode Enable",
116 .info = olpc_dc_info,
117 .get = olpc_dc_get,
118 .put = olpc_dc_put,
Andres Salomonb5ccc572008-11-06 16:53:26 -0500119 .private_value = 0,
Andres Salomonbf1e5272008-11-06 16:53:03 -0500120},
121{
122 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
123 .name = "MIC Bias Enable",
124 .info = olpc_mic_info,
125 .get = olpc_mic_get,
126 .put = olpc_mic_put,
127 .private_value = 0,
128},
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500129};
130
Andres Salomon3556d182008-11-06 16:44:08 -0500131void __devinit olpc_prequirks(struct snd_card *card,
132 struct snd_ac97_template *ac97)
133{
134 if (!machine_is_olpc())
135 return;
136
137 /* invert EAPD if on an OLPC B3 or higher */
138 if (olpc_board_at_least(olpc_board_pre(0xb3)))
139 ac97->scaps |= AC97_SCAP_INV_EAPD;
140}
141
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500142int __devinit olpc_quirks(struct snd_card *card, struct snd_ac97 *ac97)
143{
Andres Salomon466ae30552008-11-06 16:49:46 -0500144 struct snd_ctl_elem_id elem;
Andres Salomonbf1e5272008-11-06 16:53:03 -0500145 int i, err;
Andres Salomon466ae30552008-11-06 16:49:46 -0500146
Jordan Crousec8974be2008-11-06 16:43:53 -0500147 if (!machine_is_olpc())
148 return 0;
149
Andres Salomon466ae30552008-11-06 16:49:46 -0500150 /* drop the original AD1888 HPF control */
151 memset(&elem, 0, sizeof(elem));
152 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
153 strncpy(elem.name, "High Pass Filter Enable", sizeof(elem.name));
154 snd_ctl_remove_id(card, &elem);
155
Andres Salomonbf1e5272008-11-06 16:53:03 -0500156 /* drop the original V_REFOUT control */
157 memset(&elem, 0, sizeof(elem));
158 elem.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
159 strncpy(elem.name, "V_REFOUT Enable", sizeof(elem.name));
160 snd_ctl_remove_id(card, &elem);
161
162 /* add the OLPC-specific controls */
163 for (i = 0; i < ARRAY_SIZE(olpc_cs5535audio_ctls); i++) {
164 err = snd_ctl_add(card, snd_ctl_new1(&olpc_cs5535audio_ctls[i],
165 ac97->private_data));
166 if (err < 0)
167 return err;
168 }
169
Andres Salomonc8f0eee2008-11-06 16:53:19 -0500170 /* turn off the mic by default */
171 olpc_mic_bias(ac97, 0);
Andres Salomonbf1e5272008-11-06 16:53:03 -0500172 return 0;
Jaya Kumar57d4bf62008-11-06 16:43:34 -0500173}