Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * n810.c -- SoC audio for Nokia N810 |
| 3 | * |
| 4 | * Copyright (C) 2008 Nokia Corporation |
| 5 | * |
Jarkko Nikula | b08f7a6 | 2009-04-17 14:42:26 +0300 | [diff] [blame] | 6 | * Contact: Jarkko Nikula <jhnikula@gmail.com> |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | * 02110-1301 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/clk.h> |
Ben Dooks | aa6b904 | 2009-08-20 22:50:42 +0100 | [diff] [blame] | 25 | #include <linux/i2c.h> |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 26 | #include <linux/platform_device.h> |
| 27 | #include <sound/core.h> |
| 28 | #include <sound/pcm.h> |
| 29 | #include <sound/soc.h> |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 30 | |
| 31 | #include <asm/mach-types.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 32 | #include <mach/hardware.h> |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 33 | #include <linux/gpio.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 34 | #include <plat/mcbsp.h> |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 35 | |
| 36 | #include "omap-mcbsp.h" |
| 37 | #include "omap-pcm.h" |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 38 | |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 39 | #define N810_HEADSET_AMP_GPIO 10 |
| 40 | #define N810_SPEAKER_AMP_GPIO 101 |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 41 | |
Jarkko Nikula | f8d5fc9 | 2009-03-18 16:46:54 +0200 | [diff] [blame] | 42 | enum { |
| 43 | N810_JACK_DISABLED, |
| 44 | N810_JACK_HP, |
| 45 | N810_JACK_HS, |
| 46 | N810_JACK_MIC, |
| 47 | }; |
| 48 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 49 | static struct clk *sys_clkout2; |
| 50 | static struct clk *sys_clkout2_src; |
| 51 | static struct clk *func96m_clk; |
| 52 | |
| 53 | static int n810_spk_func; |
| 54 | static int n810_jack_func; |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 55 | static int n810_dmic_func; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 56 | |
| 57 | static void n810_ext_control(struct snd_soc_codec *codec) |
| 58 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 59 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Jarkko Nikula | f8d5fc9 | 2009-03-18 16:46:54 +0200 | [diff] [blame] | 60 | int hp = 0, line1l = 0; |
| 61 | |
| 62 | switch (n810_jack_func) { |
| 63 | case N810_JACK_HS: |
| 64 | line1l = 1; |
| 65 | case N810_JACK_HP: |
| 66 | hp = 1; |
| 67 | break; |
| 68 | case N810_JACK_MIC: |
| 69 | line1l = 1; |
| 70 | break; |
| 71 | } |
| 72 | |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 73 | if (n810_spk_func) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 74 | snd_soc_dapm_enable_pin(dapm, "Ext Spk"); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 75 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 76 | snd_soc_dapm_disable_pin(dapm, "Ext Spk"); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 77 | |
Jarkko Nikula | f8d5fc9 | 2009-03-18 16:46:54 +0200 | [diff] [blame] | 78 | if (hp) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 79 | snd_soc_dapm_enable_pin(dapm, "Headphone Jack"); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 80 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 81 | snd_soc_dapm_disable_pin(dapm, "Headphone Jack"); |
Jarkko Nikula | f8d5fc9 | 2009-03-18 16:46:54 +0200 | [diff] [blame] | 82 | if (line1l) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 83 | snd_soc_dapm_enable_pin(dapm, "LINE1L"); |
Jarkko Nikula | f8d5fc9 | 2009-03-18 16:46:54 +0200 | [diff] [blame] | 84 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 85 | snd_soc_dapm_disable_pin(dapm, "LINE1L"); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 86 | |
| 87 | if (n810_dmic_func) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 88 | snd_soc_dapm_enable_pin(dapm, "DMic"); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 89 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 90 | snd_soc_dapm_disable_pin(dapm, "DMic"); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 91 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 92 | snd_soc_dapm_sync(dapm); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static int n810_startup(struct snd_pcm_substream *substream) |
| 96 | { |
Jarkko Nikula | 0be4305 | 2008-11-25 12:45:08 +0200 | [diff] [blame] | 97 | struct snd_pcm_runtime *runtime = substream->runtime; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 98 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 99 | struct snd_soc_codec *codec = rtd->codec; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 100 | |
Jarkko Nikula | 0be4305 | 2008-11-25 12:45:08 +0200 | [diff] [blame] | 101 | snd_pcm_hw_constraint_minmax(runtime, |
| 102 | SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2); |
| 103 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 104 | n810_ext_control(codec); |
| 105 | return clk_enable(sys_clkout2); |
| 106 | } |
| 107 | |
| 108 | static void n810_shutdown(struct snd_pcm_substream *substream) |
| 109 | { |
| 110 | clk_disable(sys_clkout2); |
| 111 | } |
| 112 | |
| 113 | static int n810_hw_params(struct snd_pcm_substream *substream, |
| 114 | struct snd_pcm_hw_params *params) |
| 115 | { |
| 116 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 117 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 118 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 119 | int err; |
| 120 | |
| 121 | /* Set codec DAI configuration */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 122 | err = snd_soc_dai_set_fmt(codec_dai, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 123 | SND_SOC_DAIFMT_I2S | |
| 124 | SND_SOC_DAIFMT_NB_NF | |
| 125 | SND_SOC_DAIFMT_CBM_CFM); |
| 126 | if (err < 0) |
| 127 | return err; |
| 128 | |
| 129 | /* Set cpu DAI configuration */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 130 | err = snd_soc_dai_set_fmt(cpu_dai, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 131 | SND_SOC_DAIFMT_I2S | |
| 132 | SND_SOC_DAIFMT_NB_NF | |
| 133 | SND_SOC_DAIFMT_CBM_CFM); |
| 134 | if (err < 0) |
| 135 | return err; |
| 136 | |
| 137 | /* Set the codec system clock for DAC and ADC */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 138 | err = snd_soc_dai_set_sysclk(codec_dai, 0, 12000000, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 139 | SND_SOC_CLOCK_IN); |
| 140 | |
| 141 | return err; |
| 142 | } |
| 143 | |
| 144 | static struct snd_soc_ops n810_ops = { |
| 145 | .startup = n810_startup, |
| 146 | .hw_params = n810_hw_params, |
| 147 | .shutdown = n810_shutdown, |
| 148 | }; |
| 149 | |
| 150 | static int n810_get_spk(struct snd_kcontrol *kcontrol, |
| 151 | struct snd_ctl_elem_value *ucontrol) |
| 152 | { |
| 153 | ucontrol->value.integer.value[0] = n810_spk_func; |
| 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static int n810_set_spk(struct snd_kcontrol *kcontrol, |
| 159 | struct snd_ctl_elem_value *ucontrol) |
| 160 | { |
| 161 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 162 | |
| 163 | if (n810_spk_func == ucontrol->value.integer.value[0]) |
| 164 | return 0; |
| 165 | |
| 166 | n810_spk_func = ucontrol->value.integer.value[0]; |
| 167 | n810_ext_control(codec); |
| 168 | |
| 169 | return 1; |
| 170 | } |
| 171 | |
| 172 | static int n810_get_jack(struct snd_kcontrol *kcontrol, |
| 173 | struct snd_ctl_elem_value *ucontrol) |
| 174 | { |
| 175 | ucontrol->value.integer.value[0] = n810_jack_func; |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static int n810_set_jack(struct snd_kcontrol *kcontrol, |
| 181 | struct snd_ctl_elem_value *ucontrol) |
| 182 | { |
| 183 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 184 | |
| 185 | if (n810_jack_func == ucontrol->value.integer.value[0]) |
| 186 | return 0; |
| 187 | |
| 188 | n810_jack_func = ucontrol->value.integer.value[0]; |
| 189 | n810_ext_control(codec); |
| 190 | |
| 191 | return 1; |
| 192 | } |
| 193 | |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 194 | static int n810_get_input(struct snd_kcontrol *kcontrol, |
| 195 | struct snd_ctl_elem_value *ucontrol) |
| 196 | { |
| 197 | ucontrol->value.integer.value[0] = n810_dmic_func; |
| 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | static int n810_set_input(struct snd_kcontrol *kcontrol, |
| 203 | struct snd_ctl_elem_value *ucontrol) |
| 204 | { |
| 205 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 206 | |
| 207 | if (n810_dmic_func == ucontrol->value.integer.value[0]) |
| 208 | return 0; |
| 209 | |
| 210 | n810_dmic_func = ucontrol->value.integer.value[0]; |
| 211 | n810_ext_control(codec); |
| 212 | |
| 213 | return 1; |
| 214 | } |
| 215 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 216 | static int n810_spk_event(struct snd_soc_dapm_widget *w, |
| 217 | struct snd_kcontrol *k, int event) |
| 218 | { |
| 219 | if (SND_SOC_DAPM_EVENT_ON(event)) |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 220 | gpio_set_value(N810_SPEAKER_AMP_GPIO, 1); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 221 | else |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 222 | gpio_set_value(N810_SPEAKER_AMP_GPIO, 0); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | static int n810_jack_event(struct snd_soc_dapm_widget *w, |
| 228 | struct snd_kcontrol *k, int event) |
| 229 | { |
| 230 | if (SND_SOC_DAPM_EVENT_ON(event)) |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 231 | gpio_set_value(N810_HEADSET_AMP_GPIO, 1); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 232 | else |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 233 | gpio_set_value(N810_HEADSET_AMP_GPIO, 0); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | static const struct snd_soc_dapm_widget aic33_dapm_widgets[] = { |
| 239 | SND_SOC_DAPM_SPK("Ext Spk", n810_spk_event), |
| 240 | SND_SOC_DAPM_HP("Headphone Jack", n810_jack_event), |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 241 | SND_SOC_DAPM_MIC("DMic", NULL), |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 242 | }; |
| 243 | |
Mark Brown | 1a25059 | 2008-05-13 14:58:57 +0200 | [diff] [blame] | 244 | static const struct snd_soc_dapm_route audio_map[] = { |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 245 | {"Headphone Jack", NULL, "HPLOUT"}, |
| 246 | {"Headphone Jack", NULL, "HPROUT"}, |
| 247 | |
| 248 | {"Ext Spk", NULL, "LLOUT"}, |
| 249 | {"Ext Spk", NULL, "RLOUT"}, |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 250 | |
| 251 | {"DMic Rate 64", NULL, "Mic Bias 2V"}, |
| 252 | {"Mic Bias 2V", NULL, "DMic"}, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | static const char *spk_function[] = {"Off", "On"}; |
Jarkko Nikula | f8d5fc9 | 2009-03-18 16:46:54 +0200 | [diff] [blame] | 256 | static const char *jack_function[] = {"Off", "Headphone", "Headset", "Mic"}; |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 257 | static const char *input_function[] = {"ADC", "Digital Mic"}; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 258 | static const struct soc_enum n810_enum[] = { |
Jarkko Nikula | 3c17279 | 2008-05-13 16:02:04 +0200 | [diff] [blame] | 259 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function), |
| 260 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(jack_function), jack_function), |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 261 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_function), input_function), |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | static const struct snd_kcontrol_new aic33_n810_controls[] = { |
| 265 | SOC_ENUM_EXT("Speaker Function", n810_enum[0], |
| 266 | n810_get_spk, n810_set_spk), |
| 267 | SOC_ENUM_EXT("Jack Function", n810_enum[1], |
| 268 | n810_get_jack, n810_set_jack), |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 269 | SOC_ENUM_EXT("Input Select", n810_enum[2], |
| 270 | n810_get_input, n810_set_input), |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 271 | }; |
| 272 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 273 | static int n810_aic33_init(struct snd_soc_pcm_runtime *rtd) |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 274 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 275 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 276 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Philipp Zabel | eb5f6d75 | 2009-03-12 11:07:54 +0100 | [diff] [blame] | 277 | int err; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 278 | |
| 279 | /* Not connected */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 280 | snd_soc_dapm_nc_pin(dapm, "MONO_LOUT"); |
| 281 | snd_soc_dapm_nc_pin(dapm, "HPLCOM"); |
| 282 | snd_soc_dapm_nc_pin(dapm, "HPRCOM"); |
| 283 | snd_soc_dapm_nc_pin(dapm, "MIC3L"); |
| 284 | snd_soc_dapm_nc_pin(dapm, "MIC3R"); |
| 285 | snd_soc_dapm_nc_pin(dapm, "LINE1R"); |
| 286 | snd_soc_dapm_nc_pin(dapm, "LINE2L"); |
| 287 | snd_soc_dapm_nc_pin(dapm, "LINE2R"); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 288 | |
| 289 | /* Add N810 specific controls */ |
Philipp Zabel | eb5f6d75 | 2009-03-12 11:07:54 +0100 | [diff] [blame] | 290 | err = snd_soc_add_controls(codec, aic33_n810_controls, |
| 291 | ARRAY_SIZE(aic33_n810_controls)); |
| 292 | if (err < 0) |
| 293 | return err; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 294 | |
| 295 | /* Add N810 specific widgets */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 296 | snd_soc_dapm_new_controls(dapm, aic33_dapm_widgets, |
Mark Brown | 1a25059 | 2008-05-13 14:58:57 +0200 | [diff] [blame] | 297 | ARRAY_SIZE(aic33_dapm_widgets)); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 298 | |
| 299 | /* Set up N810 specific audio path audio_map */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 300 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 301 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 302 | snd_soc_dapm_sync(dapm); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 308 | static struct snd_soc_dai_link n810_dai = { |
| 309 | .name = "TLV320AIC33", |
| 310 | .stream_name = "AIC33", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 311 | .cpu_dai_name = "omap-mcbsp-dai.1", |
| 312 | .platform_name = "omap-pcm-audio", |
| 313 | .codec_name = "tlv320aic3x-codec.2-0018", |
| 314 | .codec_dai_name = "tlv320aic3x-hifi", |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 315 | .init = n810_aic33_init, |
| 316 | .ops = &n810_ops, |
| 317 | }; |
| 318 | |
| 319 | /* Audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 320 | static struct snd_soc_card snd_soc_n810 = { |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 321 | .name = "N810", |
| 322 | .dai_link = &n810_dai, |
| 323 | .num_links = 1, |
| 324 | }; |
| 325 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 326 | static struct platform_device *n810_snd_device; |
| 327 | |
| 328 | static int __init n810_soc_init(void) |
| 329 | { |
| 330 | int err; |
| 331 | struct device *dev; |
| 332 | |
Jarkko Nikula | 6e132fa | 2008-06-11 13:47:15 +0100 | [diff] [blame] | 333 | if (!(machine_is_nokia_n810() || machine_is_nokia_n810_wimax())) |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 334 | return -ENODEV; |
| 335 | |
| 336 | n810_snd_device = platform_device_alloc("soc-audio", -1); |
| 337 | if (!n810_snd_device) |
| 338 | return -ENOMEM; |
| 339 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 340 | platform_set_drvdata(n810_snd_device, &snd_soc_n810); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 341 | err = platform_device_add(n810_snd_device); |
| 342 | if (err) |
| 343 | goto err1; |
| 344 | |
| 345 | dev = &n810_snd_device->dev; |
| 346 | |
| 347 | sys_clkout2_src = clk_get(dev, "sys_clkout2_src"); |
| 348 | if (IS_ERR(sys_clkout2_src)) { |
| 349 | dev_err(dev, "Could not get sys_clkout2_src clock\n"); |
Jarkko Nikula | e784539 | 2008-08-26 13:32:57 +0300 | [diff] [blame] | 350 | err = PTR_ERR(sys_clkout2_src); |
| 351 | goto err2; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 352 | } |
| 353 | sys_clkout2 = clk_get(dev, "sys_clkout2"); |
| 354 | if (IS_ERR(sys_clkout2)) { |
| 355 | dev_err(dev, "Could not get sys_clkout2\n"); |
Jarkko Nikula | e784539 | 2008-08-26 13:32:57 +0300 | [diff] [blame] | 356 | err = PTR_ERR(sys_clkout2); |
| 357 | goto err3; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 358 | } |
| 359 | /* |
| 360 | * Configure 12 MHz output on SYS_CLKOUT2. Therefore we must use |
| 361 | * 96 MHz as its parent in order to get 12 MHz |
| 362 | */ |
| 363 | func96m_clk = clk_get(dev, "func_96m_ck"); |
| 364 | if (IS_ERR(func96m_clk)) { |
| 365 | dev_err(dev, "Could not get func 96M clock\n"); |
Jarkko Nikula | e784539 | 2008-08-26 13:32:57 +0300 | [diff] [blame] | 366 | err = PTR_ERR(func96m_clk); |
| 367 | goto err4; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 368 | } |
| 369 | clk_set_parent(sys_clkout2_src, func96m_clk); |
| 370 | clk_set_rate(sys_clkout2, 12000000); |
| 371 | |
Alexander Beregalov | f4c1724 | 2009-04-12 05:04:43 +0400 | [diff] [blame] | 372 | BUG_ON((gpio_request(N810_HEADSET_AMP_GPIO, "hs_amp") < 0) || |
| 373 | (gpio_request(N810_SPEAKER_AMP_GPIO, "spk_amp") < 0)); |
| 374 | |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 375 | gpio_direction_output(N810_HEADSET_AMP_GPIO, 0); |
| 376 | gpio_direction_output(N810_SPEAKER_AMP_GPIO, 0); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 377 | |
| 378 | return 0; |
Jarkko Nikula | e784539 | 2008-08-26 13:32:57 +0300 | [diff] [blame] | 379 | err4: |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 380 | clk_put(sys_clkout2); |
Jarkko Nikula | e784539 | 2008-08-26 13:32:57 +0300 | [diff] [blame] | 381 | err3: |
| 382 | clk_put(sys_clkout2_src); |
| 383 | err2: |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 384 | platform_device_del(n810_snd_device); |
| 385 | err1: |
| 386 | platform_device_put(n810_snd_device); |
| 387 | |
| 388 | return err; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static void __exit n810_soc_exit(void) |
| 392 | { |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 393 | gpio_free(N810_SPEAKER_AMP_GPIO); |
| 394 | gpio_free(N810_HEADSET_AMP_GPIO); |
Jarkko Nikula | e784539 | 2008-08-26 13:32:57 +0300 | [diff] [blame] | 395 | clk_put(sys_clkout2_src); |
| 396 | clk_put(sys_clkout2); |
| 397 | clk_put(func96m_clk); |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 398 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 399 | platform_device_unregister(n810_snd_device); |
| 400 | } |
| 401 | |
| 402 | module_init(n810_soc_init); |
| 403 | module_exit(n810_soc_exit); |
| 404 | |
Jarkko Nikula | b08f7a6 | 2009-04-17 14:42:26 +0300 | [diff] [blame] | 405 | MODULE_AUTHOR("Jarkko Nikula <jhnikula@gmail.com>"); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 406 | MODULE_DESCRIPTION("ALSA SoC Nokia N810"); |
| 407 | MODULE_LICENSE("GPL"); |