Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * SoC audio for HTC Magician |
| 3 | * |
| 4 | * Copyright (c) 2006 Philipp Zabel <philipp.zabel@gmail.com> |
| 5 | * |
| 6 | * based on spitz.c, |
| 7 | * Authors: Liam Girdwood <lrg@slimlogic.co.uk> |
| 8 | * Richard Purdie <richard@openedhand.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/timer.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/gpio.h> |
Philipp Zabel | 1abd918 | 2009-06-15 22:18:23 +0200 | [diff] [blame] | 23 | #include <linux/i2c.h> |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 24 | |
| 25 | #include <sound/core.h> |
| 26 | #include <sound/pcm.h> |
| 27 | #include <sound/pcm_params.h> |
| 28 | #include <sound/soc.h> |
| 29 | #include <sound/soc-dapm.h> |
Philipp Zabel | 1abd918 | 2009-06-15 22:18:23 +0200 | [diff] [blame] | 30 | #include <sound/uda1380.h> |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 31 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 32 | #include <mach/magician.h> |
| 33 | #include <asm/mach-types.h> |
| 34 | #include "../codecs/uda1380.h" |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 35 | #include "pxa2xx-i2s.h" |
| 36 | #include "pxa-ssp.h" |
| 37 | |
| 38 | #define MAGICIAN_MIC 0 |
| 39 | #define MAGICIAN_MIC_EXT 1 |
| 40 | |
| 41 | static int magician_hp_switch; |
| 42 | static int magician_spk_switch = 1; |
| 43 | static int magician_in_sel = MAGICIAN_MIC; |
| 44 | |
| 45 | static void magician_ext_control(struct snd_soc_codec *codec) |
| 46 | { |
| 47 | if (magician_spk_switch) |
| 48 | snd_soc_dapm_enable_pin(codec, "Speaker"); |
| 49 | else |
| 50 | snd_soc_dapm_disable_pin(codec, "Speaker"); |
| 51 | if (magician_hp_switch) |
| 52 | snd_soc_dapm_enable_pin(codec, "Headphone Jack"); |
| 53 | else |
| 54 | snd_soc_dapm_disable_pin(codec, "Headphone Jack"); |
| 55 | |
| 56 | switch (magician_in_sel) { |
| 57 | case MAGICIAN_MIC: |
| 58 | snd_soc_dapm_disable_pin(codec, "Headset Mic"); |
| 59 | snd_soc_dapm_enable_pin(codec, "Call Mic"); |
| 60 | break; |
| 61 | case MAGICIAN_MIC_EXT: |
| 62 | snd_soc_dapm_disable_pin(codec, "Call Mic"); |
| 63 | snd_soc_dapm_enable_pin(codec, "Headset Mic"); |
| 64 | break; |
| 65 | } |
| 66 | |
| 67 | snd_soc_dapm_sync(codec); |
| 68 | } |
| 69 | |
| 70 | static int magician_startup(struct snd_pcm_substream *substream) |
| 71 | { |
| 72 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 73 | struct snd_soc_codec *codec = rtd->codec; |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 74 | |
| 75 | /* check the jack status at stream startup */ |
| 76 | magician_ext_control(codec); |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * Magician uses SSP port for playback. |
| 83 | */ |
| 84 | static int magician_playback_hw_params(struct snd_pcm_substream *substream, |
| 85 | struct snd_pcm_hw_params *params) |
| 86 | { |
| 87 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 88 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 89 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 90 | unsigned int acps, acds, width, rate; |
| 91 | unsigned int div4 = PXA_SSP_CLK_SCDB_4; |
| 92 | int ret = 0; |
| 93 | |
| 94 | rate = params_rate(params); |
| 95 | width = snd_pcm_format_physical_width(params_format(params)); |
| 96 | |
| 97 | /* |
| 98 | * rate = SSPSCLK / (2 * width(16 or 32)) |
| 99 | * SSPSCLK = (ACPS / ACDS) / SSPSCLKDIV(div4 or div1) |
| 100 | */ |
| 101 | switch (params_rate(params)) { |
| 102 | case 8000: |
| 103 | /* off by a factor of 2: bug in the PXA27x audio clock? */ |
| 104 | acps = 32842000; |
| 105 | switch (width) { |
| 106 | case 16: |
| 107 | /* 513156 Hz ~= _2_ * 8000 Hz * 32 (+0.23%) */ |
| 108 | acds = PXA_SSP_CLK_AUDIO_DIV_16; |
| 109 | break; |
Takashi Iwai | 2bf2778 | 2009-05-15 12:20:52 +0200 | [diff] [blame] | 110 | default: /* 32 */ |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 111 | /* 1026312 Hz ~= _2_ * 8000 Hz * 64 (+0.23%) */ |
| 112 | acds = PXA_SSP_CLK_AUDIO_DIV_8; |
| 113 | } |
| 114 | break; |
| 115 | case 11025: |
| 116 | acps = 5622000; |
| 117 | switch (width) { |
| 118 | case 16: |
| 119 | /* 351375 Hz ~= 11025 Hz * 32 (-0.41%) */ |
| 120 | acds = PXA_SSP_CLK_AUDIO_DIV_4; |
| 121 | break; |
Takashi Iwai | 2bf2778 | 2009-05-15 12:20:52 +0200 | [diff] [blame] | 122 | default: /* 32 */ |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 123 | /* 702750 Hz ~= 11025 Hz * 64 (-0.41%) */ |
| 124 | acds = PXA_SSP_CLK_AUDIO_DIV_2; |
| 125 | } |
| 126 | break; |
| 127 | case 22050: |
| 128 | acps = 5622000; |
| 129 | switch (width) { |
| 130 | case 16: |
| 131 | /* 702750 Hz ~= 22050 Hz * 32 (-0.41%) */ |
| 132 | acds = PXA_SSP_CLK_AUDIO_DIV_2; |
| 133 | break; |
Takashi Iwai | 2bf2778 | 2009-05-15 12:20:52 +0200 | [diff] [blame] | 134 | default: /* 32 */ |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 135 | /* 1405500 Hz ~= 22050 Hz * 64 (-0.41%) */ |
| 136 | acds = PXA_SSP_CLK_AUDIO_DIV_1; |
| 137 | } |
| 138 | break; |
| 139 | case 44100: |
| 140 | acps = 5622000; |
| 141 | switch (width) { |
| 142 | case 16: |
| 143 | /* 1405500 Hz ~= 44100 Hz * 32 (-0.41%) */ |
| 144 | acds = PXA_SSP_CLK_AUDIO_DIV_2; |
| 145 | break; |
Takashi Iwai | 2bf2778 | 2009-05-15 12:20:52 +0200 | [diff] [blame] | 146 | default: /* 32 */ |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 147 | /* 2811000 Hz ~= 44100 Hz * 64 (-0.41%) */ |
| 148 | acds = PXA_SSP_CLK_AUDIO_DIV_1; |
| 149 | } |
| 150 | break; |
| 151 | case 48000: |
| 152 | acps = 12235000; |
| 153 | switch (width) { |
| 154 | case 16: |
| 155 | /* 1529375 Hz ~= 48000 Hz * 32 (-0.44%) */ |
| 156 | acds = PXA_SSP_CLK_AUDIO_DIV_2; |
| 157 | break; |
Takashi Iwai | 2bf2778 | 2009-05-15 12:20:52 +0200 | [diff] [blame] | 158 | default: /* 32 */ |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 159 | /* 3058750 Hz ~= 48000 Hz * 64 (-0.44%) */ |
| 160 | acds = PXA_SSP_CLK_AUDIO_DIV_1; |
| 161 | } |
| 162 | break; |
| 163 | case 96000: |
Takashi Iwai | 2bf2778 | 2009-05-15 12:20:52 +0200 | [diff] [blame] | 164 | default: |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 165 | acps = 12235000; |
| 166 | switch (width) { |
| 167 | case 16: |
| 168 | /* 3058750 Hz ~= 96000 Hz * 32 (-0.44%) */ |
| 169 | acds = PXA_SSP_CLK_AUDIO_DIV_1; |
| 170 | break; |
Takashi Iwai | 2bf2778 | 2009-05-15 12:20:52 +0200 | [diff] [blame] | 171 | default: /* 32 */ |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 172 | /* 6117500 Hz ~= 96000 Hz * 64 (-0.44%) */ |
| 173 | acds = PXA_SSP_CLK_AUDIO_DIV_2; |
| 174 | div4 = PXA_SSP_CLK_SCDB_1; |
| 175 | break; |
| 176 | } |
| 177 | break; |
| 178 | } |
| 179 | |
| 180 | /* set codec DAI configuration */ |
| 181 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_MSB | |
| 182 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); |
| 183 | if (ret < 0) |
| 184 | return ret; |
| 185 | |
| 186 | /* set cpu DAI configuration */ |
| 187 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A | |
Philipp Zabel | 33745fb | 2009-06-14 12:51:30 +0200 | [diff] [blame] | 188 | SND_SOC_DAIFMT_NB_IF | SND_SOC_DAIFMT_CBS_CFS); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 189 | if (ret < 0) |
| 190 | return ret; |
| 191 | |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 192 | ret = snd_soc_dai_set_tdm_slot(cpu_dai, 1, 0, 1, width); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 193 | if (ret < 0) |
| 194 | return ret; |
| 195 | |
| 196 | /* set audio clock as clock source */ |
| 197 | ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0, |
| 198 | SND_SOC_CLOCK_OUT); |
| 199 | if (ret < 0) |
| 200 | return ret; |
| 201 | |
| 202 | /* set the SSP audio system clock ACDS divider */ |
| 203 | ret = snd_soc_dai_set_clkdiv(cpu_dai, |
| 204 | PXA_SSP_AUDIO_DIV_ACDS, acds); |
| 205 | if (ret < 0) |
| 206 | return ret; |
| 207 | |
| 208 | /* set the SSP audio system clock SCDB divider4 */ |
| 209 | ret = snd_soc_dai_set_clkdiv(cpu_dai, |
| 210 | PXA_SSP_AUDIO_DIV_SCDB, div4); |
| 211 | if (ret < 0) |
| 212 | return ret; |
| 213 | |
| 214 | /* set SSP audio pll clock */ |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 215 | ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, 0, acps); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 216 | if (ret < 0) |
| 217 | return ret; |
| 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | * Magician uses I2S for capture. |
| 224 | */ |
| 225 | static int magician_capture_hw_params(struct snd_pcm_substream *substream, |
| 226 | struct snd_pcm_hw_params *params) |
| 227 | { |
| 228 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 229 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 230 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 231 | int ret = 0; |
| 232 | |
| 233 | /* set codec DAI configuration */ |
| 234 | ret = snd_soc_dai_set_fmt(codec_dai, |
| 235 | SND_SOC_DAIFMT_MSB | SND_SOC_DAIFMT_NB_NF | |
| 236 | SND_SOC_DAIFMT_CBS_CFS); |
| 237 | if (ret < 0) |
| 238 | return ret; |
| 239 | |
| 240 | /* set cpu DAI configuration */ |
| 241 | ret = snd_soc_dai_set_fmt(cpu_dai, |
| 242 | SND_SOC_DAIFMT_MSB | SND_SOC_DAIFMT_NB_NF | |
| 243 | SND_SOC_DAIFMT_CBS_CFS); |
| 244 | if (ret < 0) |
| 245 | return ret; |
| 246 | |
| 247 | /* set the I2S system clock as output */ |
| 248 | ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0, |
| 249 | SND_SOC_CLOCK_OUT); |
| 250 | if (ret < 0) |
| 251 | return ret; |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | static struct snd_soc_ops magician_capture_ops = { |
| 257 | .startup = magician_startup, |
| 258 | .hw_params = magician_capture_hw_params, |
| 259 | }; |
| 260 | |
| 261 | static struct snd_soc_ops magician_playback_ops = { |
| 262 | .startup = magician_startup, |
| 263 | .hw_params = magician_playback_hw_params, |
| 264 | }; |
| 265 | |
| 266 | static int magician_get_hp(struct snd_kcontrol *kcontrol, |
| 267 | struct snd_ctl_elem_value *ucontrol) |
| 268 | { |
| 269 | ucontrol->value.integer.value[0] = magician_hp_switch; |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | static int magician_set_hp(struct snd_kcontrol *kcontrol, |
| 274 | struct snd_ctl_elem_value *ucontrol) |
| 275 | { |
| 276 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 277 | |
| 278 | if (magician_hp_switch == ucontrol->value.integer.value[0]) |
| 279 | return 0; |
| 280 | |
| 281 | magician_hp_switch = ucontrol->value.integer.value[0]; |
| 282 | magician_ext_control(codec); |
| 283 | return 1; |
| 284 | } |
| 285 | |
| 286 | static int magician_get_spk(struct snd_kcontrol *kcontrol, |
| 287 | struct snd_ctl_elem_value *ucontrol) |
| 288 | { |
| 289 | ucontrol->value.integer.value[0] = magician_spk_switch; |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static int magician_set_spk(struct snd_kcontrol *kcontrol, |
| 294 | struct snd_ctl_elem_value *ucontrol) |
| 295 | { |
| 296 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 297 | |
| 298 | if (magician_spk_switch == ucontrol->value.integer.value[0]) |
| 299 | return 0; |
| 300 | |
| 301 | magician_spk_switch = ucontrol->value.integer.value[0]; |
| 302 | magician_ext_control(codec); |
| 303 | return 1; |
| 304 | } |
| 305 | |
| 306 | static int magician_get_input(struct snd_kcontrol *kcontrol, |
| 307 | struct snd_ctl_elem_value *ucontrol) |
| 308 | { |
| 309 | ucontrol->value.integer.value[0] = magician_in_sel; |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | static int magician_set_input(struct snd_kcontrol *kcontrol, |
| 314 | struct snd_ctl_elem_value *ucontrol) |
| 315 | { |
| 316 | if (magician_in_sel == ucontrol->value.integer.value[0]) |
| 317 | return 0; |
| 318 | |
| 319 | magician_in_sel = ucontrol->value.integer.value[0]; |
| 320 | |
| 321 | switch (magician_in_sel) { |
| 322 | case MAGICIAN_MIC: |
| 323 | gpio_set_value(EGPIO_MAGICIAN_IN_SEL1, 1); |
| 324 | break; |
| 325 | case MAGICIAN_MIC_EXT: |
| 326 | gpio_set_value(EGPIO_MAGICIAN_IN_SEL1, 0); |
| 327 | } |
| 328 | |
| 329 | return 1; |
| 330 | } |
| 331 | |
| 332 | static int magician_spk_power(struct snd_soc_dapm_widget *w, |
| 333 | struct snd_kcontrol *k, int event) |
| 334 | { |
| 335 | gpio_set_value(EGPIO_MAGICIAN_SPK_POWER, SND_SOC_DAPM_EVENT_ON(event)); |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static int magician_hp_power(struct snd_soc_dapm_widget *w, |
| 340 | struct snd_kcontrol *k, int event) |
| 341 | { |
| 342 | gpio_set_value(EGPIO_MAGICIAN_EP_POWER, SND_SOC_DAPM_EVENT_ON(event)); |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | static int magician_mic_bias(struct snd_soc_dapm_widget *w, |
| 347 | struct snd_kcontrol *k, int event) |
| 348 | { |
| 349 | gpio_set_value(EGPIO_MAGICIAN_MIC_POWER, SND_SOC_DAPM_EVENT_ON(event)); |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | /* magician machine dapm widgets */ |
| 354 | static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = { |
| 355 | SND_SOC_DAPM_HP("Headphone Jack", magician_hp_power), |
| 356 | SND_SOC_DAPM_SPK("Speaker", magician_spk_power), |
| 357 | SND_SOC_DAPM_MIC("Call Mic", magician_mic_bias), |
| 358 | SND_SOC_DAPM_MIC("Headset Mic", magician_mic_bias), |
| 359 | }; |
| 360 | |
| 361 | /* magician machine audio_map */ |
| 362 | static const struct snd_soc_dapm_route audio_map[] = { |
| 363 | |
| 364 | /* Headphone connected to VOUTL, VOUTR */ |
| 365 | {"Headphone Jack", NULL, "VOUTL"}, |
| 366 | {"Headphone Jack", NULL, "VOUTR"}, |
| 367 | |
| 368 | /* Speaker connected to VOUTL, VOUTR */ |
| 369 | {"Speaker", NULL, "VOUTL"}, |
| 370 | {"Speaker", NULL, "VOUTR"}, |
| 371 | |
| 372 | /* Mics are connected to VINM */ |
| 373 | {"VINM", NULL, "Headset Mic"}, |
| 374 | {"VINM", NULL, "Call Mic"}, |
| 375 | }; |
| 376 | |
| 377 | static const char *input_select[] = {"Call Mic", "Headset Mic"}; |
| 378 | static const struct soc_enum magician_in_sel_enum = |
| 379 | SOC_ENUM_SINGLE_EXT(2, input_select); |
| 380 | |
| 381 | static const struct snd_kcontrol_new uda1380_magician_controls[] = { |
| 382 | SOC_SINGLE_BOOL_EXT("Headphone Switch", |
| 383 | (unsigned long)&magician_hp_switch, |
| 384 | magician_get_hp, magician_set_hp), |
| 385 | SOC_SINGLE_BOOL_EXT("Speaker Switch", |
| 386 | (unsigned long)&magician_spk_switch, |
| 387 | magician_get_spk, magician_set_spk), |
| 388 | SOC_ENUM_EXT("Input Select", magician_in_sel_enum, |
| 389 | magician_get_input, magician_set_input), |
| 390 | }; |
| 391 | |
| 392 | /* |
| 393 | * Logic for a uda1380 as connected on a HTC Magician |
| 394 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 395 | static int magician_uda1380_init(struct snd_soc_pcm_runtime *rtd) |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 396 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 397 | struct snd_soc_codec *codec = rtd->codec; |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 398 | int err; |
| 399 | |
| 400 | /* NC codec pins */ |
| 401 | snd_soc_dapm_nc_pin(codec, "VOUTLHP"); |
| 402 | snd_soc_dapm_nc_pin(codec, "VOUTRHP"); |
| 403 | |
| 404 | /* FIXME: is anything connected here? */ |
| 405 | snd_soc_dapm_nc_pin(codec, "VINL"); |
| 406 | snd_soc_dapm_nc_pin(codec, "VINR"); |
| 407 | |
| 408 | /* Add magician specific controls */ |
| 409 | err = snd_soc_add_controls(codec, uda1380_magician_controls, |
| 410 | ARRAY_SIZE(uda1380_magician_controls)); |
| 411 | if (err < 0) |
| 412 | return err; |
| 413 | |
| 414 | /* Add magician specific widgets */ |
| 415 | snd_soc_dapm_new_controls(codec, uda1380_dapm_widgets, |
| 416 | ARRAY_SIZE(uda1380_dapm_widgets)); |
| 417 | |
| 418 | /* Set up magician specific audio path interconnects */ |
| 419 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
| 420 | |
| 421 | snd_soc_dapm_sync(codec); |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | /* magician digital audio interface glue - connects codec <--> CPU */ |
| 426 | static struct snd_soc_dai_link magician_dai[] = { |
| 427 | { |
| 428 | .name = "uda1380", |
| 429 | .stream_name = "UDA1380 Playback", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 430 | .cpu_dai_name = "pxa-ssp-dai.0", |
| 431 | .codec_dai_name = "uda1380-hifi-playback", |
| 432 | .platform_name = "pxa-pcm-audio", |
| 433 | .codec_name = "uda1380-codec.0-0018", |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 434 | .init = magician_uda1380_init, |
| 435 | .ops = &magician_playback_ops, |
| 436 | }, |
| 437 | { |
| 438 | .name = "uda1380", |
| 439 | .stream_name = "UDA1380 Capture", |
Ian Lartey | a2a0086 | 2010-08-20 17:18:43 +0100 | [diff] [blame^] | 440 | .cpu_dai_name = "pxa2xx-i2s", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 441 | .codec_dai_name = "uda1380-hifi-capture", |
| 442 | .platform_name = "pxa-pcm-audio", |
| 443 | .codec_name = "uda1380-codec.0-0018", |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 444 | .ops = &magician_capture_ops, |
| 445 | } |
| 446 | }; |
| 447 | |
| 448 | /* magician audio machine driver */ |
| 449 | static struct snd_soc_card snd_soc_card_magician = { |
| 450 | .name = "Magician", |
| 451 | .dai_link = magician_dai, |
| 452 | .num_links = ARRAY_SIZE(magician_dai), |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 453 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 454 | }; |
| 455 | |
| 456 | static struct platform_device *magician_snd_device; |
| 457 | |
Philipp Zabel | 1abd918 | 2009-06-15 22:18:23 +0200 | [diff] [blame] | 458 | /* |
| 459 | * FIXME: move into magician board file once merged into the pxa tree |
| 460 | */ |
| 461 | static struct uda1380_platform_data uda1380_info = { |
| 462 | .gpio_power = EGPIO_MAGICIAN_CODEC_POWER, |
| 463 | .gpio_reset = EGPIO_MAGICIAN_CODEC_RESET, |
| 464 | .dac_clk = UDA1380_DAC_CLK_WSPLL, |
| 465 | }; |
| 466 | |
| 467 | static struct i2c_board_info i2c_board_info[] = { |
| 468 | { |
| 469 | I2C_BOARD_INFO("uda1380", 0x18), |
| 470 | .platform_data = &uda1380_info, |
| 471 | }, |
| 472 | }; |
| 473 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 474 | static int __init magician_init(void) |
| 475 | { |
| 476 | int ret; |
Philipp Zabel | 1abd918 | 2009-06-15 22:18:23 +0200 | [diff] [blame] | 477 | struct i2c_adapter *adapter; |
| 478 | struct i2c_client *client; |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 479 | |
| 480 | if (!machine_is_magician()) |
| 481 | return -ENODEV; |
| 482 | |
Philipp Zabel | 1abd918 | 2009-06-15 22:18:23 +0200 | [diff] [blame] | 483 | adapter = i2c_get_adapter(0); |
| 484 | if (!adapter) |
| 485 | return -ENODEV; |
| 486 | client = i2c_new_device(adapter, i2c_board_info); |
| 487 | i2c_put_adapter(adapter); |
| 488 | if (!client) |
| 489 | return -ENODEV; |
| 490 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 491 | ret = gpio_request(EGPIO_MAGICIAN_SPK_POWER, "SPK_POWER"); |
| 492 | if (ret) |
| 493 | goto err_request_spk; |
| 494 | ret = gpio_request(EGPIO_MAGICIAN_EP_POWER, "EP_POWER"); |
| 495 | if (ret) |
| 496 | goto err_request_ep; |
| 497 | ret = gpio_request(EGPIO_MAGICIAN_MIC_POWER, "MIC_POWER"); |
| 498 | if (ret) |
| 499 | goto err_request_mic; |
| 500 | ret = gpio_request(EGPIO_MAGICIAN_IN_SEL0, "IN_SEL0"); |
| 501 | if (ret) |
| 502 | goto err_request_in_sel0; |
| 503 | ret = gpio_request(EGPIO_MAGICIAN_IN_SEL1, "IN_SEL1"); |
| 504 | if (ret) |
| 505 | goto err_request_in_sel1; |
| 506 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 507 | gpio_set_value(EGPIO_MAGICIAN_IN_SEL0, 0); |
| 508 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 509 | magician_snd_device = platform_device_alloc("soc-audio", -1); |
| 510 | if (!magician_snd_device) { |
| 511 | ret = -ENOMEM; |
| 512 | goto err_pdev; |
| 513 | } |
| 514 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 515 | platform_set_drvdata(magician_snd_device, &snd_soc_card_magician); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 516 | ret = platform_device_add(magician_snd_device); |
| 517 | if (ret) { |
| 518 | platform_device_put(magician_snd_device); |
| 519 | goto err_pdev; |
| 520 | } |
| 521 | |
| 522 | return 0; |
| 523 | |
| 524 | err_pdev: |
| 525 | gpio_free(EGPIO_MAGICIAN_IN_SEL1); |
| 526 | err_request_in_sel1: |
| 527 | gpio_free(EGPIO_MAGICIAN_IN_SEL0); |
| 528 | err_request_in_sel0: |
| 529 | gpio_free(EGPIO_MAGICIAN_MIC_POWER); |
| 530 | err_request_mic: |
| 531 | gpio_free(EGPIO_MAGICIAN_EP_POWER); |
| 532 | err_request_ep: |
| 533 | gpio_free(EGPIO_MAGICIAN_SPK_POWER); |
| 534 | err_request_spk: |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 535 | return ret; |
| 536 | } |
| 537 | |
| 538 | static void __exit magician_exit(void) |
| 539 | { |
| 540 | platform_device_unregister(magician_snd_device); |
| 541 | |
| 542 | gpio_set_value(EGPIO_MAGICIAN_SPK_POWER, 0); |
| 543 | gpio_set_value(EGPIO_MAGICIAN_EP_POWER, 0); |
| 544 | gpio_set_value(EGPIO_MAGICIAN_MIC_POWER, 0); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 545 | |
| 546 | gpio_free(EGPIO_MAGICIAN_IN_SEL1); |
| 547 | gpio_free(EGPIO_MAGICIAN_IN_SEL0); |
| 548 | gpio_free(EGPIO_MAGICIAN_MIC_POWER); |
| 549 | gpio_free(EGPIO_MAGICIAN_EP_POWER); |
| 550 | gpio_free(EGPIO_MAGICIAN_SPK_POWER); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | module_init(magician_init); |
| 554 | module_exit(magician_exit); |
| 555 | |
| 556 | MODULE_AUTHOR("Philipp Zabel"); |
| 557 | MODULE_DESCRIPTION("ALSA SoC Magician"); |
| 558 | MODULE_LICENSE("GPL"); |