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 | * |
| 6 | * Contact: Jarkko Nikula <jarkko.nikula@nokia.com> |
| 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> |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <sound/core.h> |
| 27 | #include <sound/pcm.h> |
| 28 | #include <sound/soc.h> |
| 29 | #include <sound/soc-dapm.h> |
| 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> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 34 | #include <mach/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" |
| 38 | #include "../codecs/tlv320aic3x.h" |
| 39 | |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 40 | #define N810_HEADSET_AMP_GPIO 10 |
| 41 | #define N810_SPEAKER_AMP_GPIO 101 |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 42 | |
| 43 | static struct clk *sys_clkout2; |
| 44 | static struct clk *sys_clkout2_src; |
| 45 | static struct clk *func96m_clk; |
| 46 | |
| 47 | static int n810_spk_func; |
| 48 | static int n810_jack_func; |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 49 | static int n810_dmic_func; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 50 | |
| 51 | static void n810_ext_control(struct snd_soc_codec *codec) |
| 52 | { |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 53 | if (n810_spk_func) |
| 54 | snd_soc_dapm_enable_pin(codec, "Ext Spk"); |
| 55 | else |
| 56 | snd_soc_dapm_disable_pin(codec, "Ext Spk"); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 57 | |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 58 | if (n810_jack_func) |
| 59 | snd_soc_dapm_enable_pin(codec, "Headphone Jack"); |
| 60 | else |
| 61 | snd_soc_dapm_disable_pin(codec, "Headphone Jack"); |
| 62 | |
| 63 | if (n810_dmic_func) |
| 64 | snd_soc_dapm_enable_pin(codec, "DMic"); |
| 65 | else |
Liam Girdwood | ac8615b | 2008-07-08 13:20:39 +0100 | [diff] [blame] | 66 | snd_soc_dapm_disable_pin(codec, "DMic"); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 67 | |
| 68 | snd_soc_dapm_sync(codec); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static int n810_startup(struct snd_pcm_substream *substream) |
| 72 | { |
Jarkko Nikula | 0be4305 | 2008-11-25 12:45:08 +0200 | [diff] [blame] | 73 | struct snd_pcm_runtime *runtime = substream->runtime; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 74 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Takashi Iwai | 9e30d77 | 2009-02-11 08:28:04 +0100 | [diff] [blame] | 75 | struct snd_soc_codec *codec = rtd->socdev->card->codec; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 76 | |
Jarkko Nikula | 0be4305 | 2008-11-25 12:45:08 +0200 | [diff] [blame] | 77 | snd_pcm_hw_constraint_minmax(runtime, |
| 78 | SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2); |
| 79 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 80 | n810_ext_control(codec); |
| 81 | return clk_enable(sys_clkout2); |
| 82 | } |
| 83 | |
| 84 | static void n810_shutdown(struct snd_pcm_substream *substream) |
| 85 | { |
| 86 | clk_disable(sys_clkout2); |
| 87 | } |
| 88 | |
| 89 | static int n810_hw_params(struct snd_pcm_substream *substream, |
| 90 | struct snd_pcm_hw_params *params) |
| 91 | { |
| 92 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | 8687eb8 | 2008-07-07 16:08:07 +0100 | [diff] [blame] | 93 | struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; |
| 94 | struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 95 | int err; |
| 96 | |
| 97 | /* Set codec DAI configuration */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 98 | err = snd_soc_dai_set_fmt(codec_dai, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 99 | SND_SOC_DAIFMT_I2S | |
| 100 | SND_SOC_DAIFMT_NB_NF | |
| 101 | SND_SOC_DAIFMT_CBM_CFM); |
| 102 | if (err < 0) |
| 103 | return err; |
| 104 | |
| 105 | /* Set cpu DAI configuration */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 106 | err = snd_soc_dai_set_fmt(cpu_dai, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 107 | SND_SOC_DAIFMT_I2S | |
| 108 | SND_SOC_DAIFMT_NB_NF | |
| 109 | SND_SOC_DAIFMT_CBM_CFM); |
| 110 | if (err < 0) |
| 111 | return err; |
| 112 | |
| 113 | /* Set the codec system clock for DAC and ADC */ |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 114 | err = snd_soc_dai_set_sysclk(codec_dai, 0, 12000000, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 115 | SND_SOC_CLOCK_IN); |
| 116 | |
| 117 | return err; |
| 118 | } |
| 119 | |
| 120 | static struct snd_soc_ops n810_ops = { |
| 121 | .startup = n810_startup, |
| 122 | .hw_params = n810_hw_params, |
| 123 | .shutdown = n810_shutdown, |
| 124 | }; |
| 125 | |
| 126 | static int n810_get_spk(struct snd_kcontrol *kcontrol, |
| 127 | struct snd_ctl_elem_value *ucontrol) |
| 128 | { |
| 129 | ucontrol->value.integer.value[0] = n810_spk_func; |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static int n810_set_spk(struct snd_kcontrol *kcontrol, |
| 135 | struct snd_ctl_elem_value *ucontrol) |
| 136 | { |
| 137 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 138 | |
| 139 | if (n810_spk_func == ucontrol->value.integer.value[0]) |
| 140 | return 0; |
| 141 | |
| 142 | n810_spk_func = ucontrol->value.integer.value[0]; |
| 143 | n810_ext_control(codec); |
| 144 | |
| 145 | return 1; |
| 146 | } |
| 147 | |
| 148 | static int n810_get_jack(struct snd_kcontrol *kcontrol, |
| 149 | struct snd_ctl_elem_value *ucontrol) |
| 150 | { |
| 151 | ucontrol->value.integer.value[0] = n810_jack_func; |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | static int n810_set_jack(struct snd_kcontrol *kcontrol, |
| 157 | struct snd_ctl_elem_value *ucontrol) |
| 158 | { |
| 159 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 160 | |
| 161 | if (n810_jack_func == ucontrol->value.integer.value[0]) |
| 162 | return 0; |
| 163 | |
| 164 | n810_jack_func = ucontrol->value.integer.value[0]; |
| 165 | n810_ext_control(codec); |
| 166 | |
| 167 | return 1; |
| 168 | } |
| 169 | |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 170 | static int n810_get_input(struct snd_kcontrol *kcontrol, |
| 171 | struct snd_ctl_elem_value *ucontrol) |
| 172 | { |
| 173 | ucontrol->value.integer.value[0] = n810_dmic_func; |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static int n810_set_input(struct snd_kcontrol *kcontrol, |
| 179 | struct snd_ctl_elem_value *ucontrol) |
| 180 | { |
| 181 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 182 | |
| 183 | if (n810_dmic_func == ucontrol->value.integer.value[0]) |
| 184 | return 0; |
| 185 | |
| 186 | n810_dmic_func = ucontrol->value.integer.value[0]; |
| 187 | n810_ext_control(codec); |
| 188 | |
| 189 | return 1; |
| 190 | } |
| 191 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 192 | static int n810_spk_event(struct snd_soc_dapm_widget *w, |
| 193 | struct snd_kcontrol *k, int event) |
| 194 | { |
| 195 | if (SND_SOC_DAPM_EVENT_ON(event)) |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 196 | gpio_set_value(N810_SPEAKER_AMP_GPIO, 1); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 197 | else |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 198 | gpio_set_value(N810_SPEAKER_AMP_GPIO, 0); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static int n810_jack_event(struct snd_soc_dapm_widget *w, |
| 204 | struct snd_kcontrol *k, int event) |
| 205 | { |
| 206 | if (SND_SOC_DAPM_EVENT_ON(event)) |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 207 | gpio_set_value(N810_HEADSET_AMP_GPIO, 1); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 208 | else |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 209 | gpio_set_value(N810_HEADSET_AMP_GPIO, 0); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | static const struct snd_soc_dapm_widget aic33_dapm_widgets[] = { |
| 215 | SND_SOC_DAPM_SPK("Ext Spk", n810_spk_event), |
| 216 | SND_SOC_DAPM_HP("Headphone Jack", n810_jack_event), |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 217 | SND_SOC_DAPM_MIC("DMic", NULL), |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 218 | }; |
| 219 | |
Mark Brown | 1a25059 | 2008-05-13 14:58:57 +0200 | [diff] [blame] | 220 | static const struct snd_soc_dapm_route audio_map[] = { |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 221 | {"Headphone Jack", NULL, "HPLOUT"}, |
| 222 | {"Headphone Jack", NULL, "HPROUT"}, |
| 223 | |
| 224 | {"Ext Spk", NULL, "LLOUT"}, |
| 225 | {"Ext Spk", NULL, "RLOUT"}, |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 226 | |
| 227 | {"DMic Rate 64", NULL, "Mic Bias 2V"}, |
| 228 | {"Mic Bias 2V", NULL, "DMic"}, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | static const char *spk_function[] = {"Off", "On"}; |
| 232 | static const char *jack_function[] = {"Off", "Headphone"}; |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 233 | static const char *input_function[] = {"ADC", "Digital Mic"}; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 234 | static const struct soc_enum n810_enum[] = { |
Jarkko Nikula | 3c17279 | 2008-05-13 16:02:04 +0200 | [diff] [blame] | 235 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function), |
| 236 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(jack_function), jack_function), |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 237 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_function), input_function), |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 238 | }; |
| 239 | |
| 240 | static const struct snd_kcontrol_new aic33_n810_controls[] = { |
| 241 | SOC_ENUM_EXT("Speaker Function", n810_enum[0], |
| 242 | n810_get_spk, n810_set_spk), |
| 243 | SOC_ENUM_EXT("Jack Function", n810_enum[1], |
| 244 | n810_get_jack, n810_set_jack), |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 245 | SOC_ENUM_EXT("Input Select", n810_enum[2], |
| 246 | n810_get_input, n810_set_input), |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | static int n810_aic33_init(struct snd_soc_codec *codec) |
| 250 | { |
Philipp Zabel | eb5f6d75 | 2009-03-12 11:07:54 +0100 | [diff] [blame^] | 251 | int err; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 252 | |
| 253 | /* Not connected */ |
Mark Brown | 869fbb3 | 2008-09-27 10:48:31 +0100 | [diff] [blame] | 254 | snd_soc_dapm_nc_pin(codec, "MONO_LOUT"); |
| 255 | snd_soc_dapm_nc_pin(codec, "HPLCOM"); |
| 256 | snd_soc_dapm_nc_pin(codec, "HPRCOM"); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 257 | |
| 258 | /* Add N810 specific controls */ |
Philipp Zabel | eb5f6d75 | 2009-03-12 11:07:54 +0100 | [diff] [blame^] | 259 | err = snd_soc_add_controls(codec, aic33_n810_controls, |
| 260 | ARRAY_SIZE(aic33_n810_controls)); |
| 261 | if (err < 0) |
| 262 | return err; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 263 | |
| 264 | /* Add N810 specific widgets */ |
Mark Brown | 1a25059 | 2008-05-13 14:58:57 +0200 | [diff] [blame] | 265 | snd_soc_dapm_new_controls(codec, aic33_dapm_widgets, |
| 266 | ARRAY_SIZE(aic33_dapm_widgets)); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 267 | |
| 268 | /* Set up N810 specific audio path audio_map */ |
Mark Brown | 1a25059 | 2008-05-13 14:58:57 +0200 | [diff] [blame] | 269 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 270 | |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 271 | snd_soc_dapm_sync(codec); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 277 | static struct snd_soc_dai_link n810_dai = { |
| 278 | .name = "TLV320AIC33", |
| 279 | .stream_name = "AIC33", |
| 280 | .cpu_dai = &omap_mcbsp_dai[0], |
| 281 | .codec_dai = &aic3x_dai, |
| 282 | .init = n810_aic33_init, |
| 283 | .ops = &n810_ops, |
| 284 | }; |
| 285 | |
| 286 | /* Audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 287 | static struct snd_soc_card snd_soc_n810 = { |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 288 | .name = "N810", |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 289 | .platform = &omap_soc_platform, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 290 | .dai_link = &n810_dai, |
| 291 | .num_links = 1, |
| 292 | }; |
| 293 | |
| 294 | /* Audio private data */ |
| 295 | static struct aic3x_setup_data n810_aic33_setup = { |
Jean Delvare | ba8ed12 | 2008-09-22 14:15:53 +0200 | [diff] [blame] | 296 | .i2c_bus = 2, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 297 | .i2c_address = 0x18, |
Jarkko Nikula | 90b9e47 | 2008-06-25 14:58:47 +0300 | [diff] [blame] | 298 | .gpio_func[0] = AIC3X_GPIO1_FUNC_DISABLED, |
| 299 | .gpio_func[1] = AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | /* Audio subsystem */ |
| 303 | static struct snd_soc_device n810_snd_devdata = { |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 304 | .card = &snd_soc_n810, |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 305 | .codec_dev = &soc_codec_dev_aic3x, |
| 306 | .codec_data = &n810_aic33_setup, |
| 307 | }; |
| 308 | |
| 309 | static struct platform_device *n810_snd_device; |
| 310 | |
| 311 | static int __init n810_soc_init(void) |
| 312 | { |
| 313 | int err; |
| 314 | struct device *dev; |
| 315 | |
Jarkko Nikula | 6e132fa | 2008-06-11 13:47:15 +0100 | [diff] [blame] | 316 | if (!(machine_is_nokia_n810() || machine_is_nokia_n810_wimax())) |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 317 | return -ENODEV; |
| 318 | |
| 319 | n810_snd_device = platform_device_alloc("soc-audio", -1); |
| 320 | if (!n810_snd_device) |
| 321 | return -ENOMEM; |
| 322 | |
| 323 | platform_set_drvdata(n810_snd_device, &n810_snd_devdata); |
| 324 | n810_snd_devdata.dev = &n810_snd_device->dev; |
| 325 | *(unsigned int *)n810_dai.cpu_dai->private_data = 1; /* McBSP2 */ |
| 326 | err = platform_device_add(n810_snd_device); |
| 327 | if (err) |
| 328 | goto err1; |
| 329 | |
| 330 | dev = &n810_snd_device->dev; |
| 331 | |
| 332 | sys_clkout2_src = clk_get(dev, "sys_clkout2_src"); |
| 333 | if (IS_ERR(sys_clkout2_src)) { |
| 334 | dev_err(dev, "Could not get sys_clkout2_src clock\n"); |
Jarkko Nikula | e784539 | 2008-08-26 13:32:57 +0300 | [diff] [blame] | 335 | err = PTR_ERR(sys_clkout2_src); |
| 336 | goto err2; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 337 | } |
| 338 | sys_clkout2 = clk_get(dev, "sys_clkout2"); |
| 339 | if (IS_ERR(sys_clkout2)) { |
| 340 | dev_err(dev, "Could not get sys_clkout2\n"); |
Jarkko Nikula | e784539 | 2008-08-26 13:32:57 +0300 | [diff] [blame] | 341 | err = PTR_ERR(sys_clkout2); |
| 342 | goto err3; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 343 | } |
| 344 | /* |
| 345 | * Configure 12 MHz output on SYS_CLKOUT2. Therefore we must use |
| 346 | * 96 MHz as its parent in order to get 12 MHz |
| 347 | */ |
| 348 | func96m_clk = clk_get(dev, "func_96m_ck"); |
| 349 | if (IS_ERR(func96m_clk)) { |
| 350 | dev_err(dev, "Could not get func 96M clock\n"); |
Jarkko Nikula | e784539 | 2008-08-26 13:32:57 +0300 | [diff] [blame] | 351 | err = PTR_ERR(func96m_clk); |
| 352 | goto err4; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 353 | } |
| 354 | clk_set_parent(sys_clkout2_src, func96m_clk); |
| 355 | clk_set_rate(sys_clkout2, 12000000); |
| 356 | |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 357 | if (gpio_request(N810_HEADSET_AMP_GPIO, "hs_amp") < 0) |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 358 | BUG(); |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 359 | if (gpio_request(N810_SPEAKER_AMP_GPIO, "spk_amp") < 0) |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 360 | BUG(); |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 361 | gpio_direction_output(N810_HEADSET_AMP_GPIO, 0); |
| 362 | gpio_direction_output(N810_SPEAKER_AMP_GPIO, 0); |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 363 | |
| 364 | return 0; |
Jarkko Nikula | e784539 | 2008-08-26 13:32:57 +0300 | [diff] [blame] | 365 | err4: |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 366 | clk_put(sys_clkout2); |
Jarkko Nikula | e784539 | 2008-08-26 13:32:57 +0300 | [diff] [blame] | 367 | err3: |
| 368 | clk_put(sys_clkout2_src); |
| 369 | err2: |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 370 | platform_device_del(n810_snd_device); |
| 371 | err1: |
| 372 | platform_device_put(n810_snd_device); |
| 373 | |
| 374 | return err; |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static void __exit n810_soc_exit(void) |
| 378 | { |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 379 | gpio_free(N810_SPEAKER_AMP_GPIO); |
| 380 | gpio_free(N810_HEADSET_AMP_GPIO); |
Jarkko Nikula | e784539 | 2008-08-26 13:32:57 +0300 | [diff] [blame] | 381 | clk_put(sys_clkout2_src); |
| 382 | clk_put(sys_clkout2); |
| 383 | clk_put(func96m_clk); |
Jarkko Nikula | f99a633 | 2008-05-15 11:01:36 +0200 | [diff] [blame] | 384 | |
Jarkko Nikula | 2e74796 | 2008-04-25 13:55:19 +0200 | [diff] [blame] | 385 | platform_device_unregister(n810_snd_device); |
| 386 | } |
| 387 | |
| 388 | module_init(n810_soc_init); |
| 389 | module_exit(n810_soc_exit); |
| 390 | |
| 391 | MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@nokia.com>"); |
| 392 | MODULE_DESCRIPTION("ALSA SoC Nokia N810"); |
| 393 | MODULE_LICENSE("GPL"); |