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