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> |
Philipp Zabel | 1abd918 | 2009-06-15 22:18:23 +0200 | [diff] [blame] | 29 | #include <sound/uda1380.h> |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 30 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 31 | #include <mach/magician.h> |
| 32 | #include <asm/mach-types.h> |
| 33 | #include "../codecs/uda1380.h" |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 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 | |
Lars-Peter Clausen | 0fbd44a | 2014-03-12 15:27:38 +0100 | [diff] [blame] | 44 | static void magician_ext_control(struct snd_soc_dapm_context *dapm) |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 45 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 46 | |
Charles Keepax | f71b0fb | 2014-02-18 15:22:26 +0000 | [diff] [blame] | 47 | snd_soc_dapm_mutex_lock(dapm); |
| 48 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 49 | if (magician_spk_switch) |
Charles Keepax | f71b0fb | 2014-02-18 15:22:26 +0000 | [diff] [blame] | 50 | snd_soc_dapm_enable_pin_unlocked(dapm, "Speaker"); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 51 | else |
Charles Keepax | f71b0fb | 2014-02-18 15:22:26 +0000 | [diff] [blame] | 52 | snd_soc_dapm_disable_pin_unlocked(dapm, "Speaker"); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 53 | if (magician_hp_switch) |
Charles Keepax | f71b0fb | 2014-02-18 15:22:26 +0000 | [diff] [blame] | 54 | snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack"); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 55 | else |
Charles Keepax | f71b0fb | 2014-02-18 15:22:26 +0000 | [diff] [blame] | 56 | snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack"); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 57 | |
| 58 | switch (magician_in_sel) { |
| 59 | case MAGICIAN_MIC: |
Charles Keepax | f71b0fb | 2014-02-18 15:22:26 +0000 | [diff] [blame] | 60 | snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Mic"); |
| 61 | snd_soc_dapm_enable_pin_unlocked(dapm, "Call Mic"); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 62 | break; |
| 63 | case MAGICIAN_MIC_EXT: |
Charles Keepax | f71b0fb | 2014-02-18 15:22:26 +0000 | [diff] [blame] | 64 | snd_soc_dapm_disable_pin_unlocked(dapm, "Call Mic"); |
| 65 | snd_soc_dapm_enable_pin_unlocked(dapm, "Headset Mic"); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 66 | break; |
| 67 | } |
| 68 | |
Charles Keepax | f71b0fb | 2014-02-18 15:22:26 +0000 | [diff] [blame] | 69 | snd_soc_dapm_sync_unlocked(dapm); |
| 70 | |
| 71 | snd_soc_dapm_mutex_unlock(dapm); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static int magician_startup(struct snd_pcm_substream *substream) |
| 75 | { |
| 76 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 77 | |
| 78 | /* check the jack status at stream startup */ |
Lars-Peter Clausen | 0fbd44a | 2014-03-12 15:27:38 +0100 | [diff] [blame] | 79 | magician_ext_control(&rtd->card->dapm); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * Magician uses SSP port for playback. |
| 86 | */ |
| 87 | static int magician_playback_hw_params(struct snd_pcm_substream *substream, |
| 88 | struct snd_pcm_hw_params *params) |
| 89 | { |
| 90 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 91 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 92 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Daniel Mack | a8e43c2 | 2018-07-16 08:24:45 +0200 | [diff] [blame] | 93 | unsigned int width; |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 94 | int ret = 0; |
| 95 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 96 | /* set codec DAI configuration */ |
| 97 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_MSB | |
| 98 | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); |
| 99 | if (ret < 0) |
| 100 | return ret; |
| 101 | |
| 102 | /* set cpu DAI configuration */ |
| 103 | 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] | 104 | SND_SOC_DAIFMT_NB_IF | SND_SOC_DAIFMT_CBS_CFS); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 105 | if (ret < 0) |
| 106 | return ret; |
| 107 | |
Daniel Mack | a8e43c2 | 2018-07-16 08:24:45 +0200 | [diff] [blame] | 108 | width = snd_pcm_format_physical_width(params_format(params)); |
Daniel Ribeiro | a5479e3 | 2009-06-15 21:44:31 -0300 | [diff] [blame] | 109 | 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] | 110 | if (ret < 0) |
| 111 | return ret; |
| 112 | |
| 113 | /* set audio clock as clock source */ |
| 114 | ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0, |
| 115 | SND_SOC_CLOCK_OUT); |
| 116 | if (ret < 0) |
| 117 | return ret; |
| 118 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Magician uses I2S for capture. |
| 124 | */ |
| 125 | static int magician_capture_hw_params(struct snd_pcm_substream *substream, |
| 126 | struct snd_pcm_hw_params *params) |
| 127 | { |
| 128 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 129 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 130 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 131 | int ret = 0; |
| 132 | |
| 133 | /* set codec DAI configuration */ |
| 134 | ret = snd_soc_dai_set_fmt(codec_dai, |
| 135 | SND_SOC_DAIFMT_MSB | SND_SOC_DAIFMT_NB_NF | |
| 136 | SND_SOC_DAIFMT_CBS_CFS); |
| 137 | if (ret < 0) |
| 138 | return ret; |
| 139 | |
| 140 | /* set cpu DAI configuration */ |
| 141 | ret = snd_soc_dai_set_fmt(cpu_dai, |
| 142 | SND_SOC_DAIFMT_MSB | SND_SOC_DAIFMT_NB_NF | |
| 143 | SND_SOC_DAIFMT_CBS_CFS); |
| 144 | if (ret < 0) |
| 145 | return ret; |
| 146 | |
| 147 | /* set the I2S system clock as output */ |
| 148 | ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0, |
| 149 | SND_SOC_CLOCK_OUT); |
| 150 | if (ret < 0) |
| 151 | return ret; |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
Bhumika Goyal | 943b731 | 2017-03-14 01:16:40 +0530 | [diff] [blame] | 156 | static const struct snd_soc_ops magician_capture_ops = { |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 157 | .startup = magician_startup, |
| 158 | .hw_params = magician_capture_hw_params, |
| 159 | }; |
| 160 | |
Bhumika Goyal | 943b731 | 2017-03-14 01:16:40 +0530 | [diff] [blame] | 161 | static const struct snd_soc_ops magician_playback_ops = { |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 162 | .startup = magician_startup, |
| 163 | .hw_params = magician_playback_hw_params, |
| 164 | }; |
| 165 | |
| 166 | static int magician_get_hp(struct snd_kcontrol *kcontrol, |
| 167 | struct snd_ctl_elem_value *ucontrol) |
| 168 | { |
| 169 | ucontrol->value.integer.value[0] = magician_hp_switch; |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static int magician_set_hp(struct snd_kcontrol *kcontrol, |
| 174 | struct snd_ctl_elem_value *ucontrol) |
| 175 | { |
Lars-Peter Clausen | 0fbd44a | 2014-03-12 15:27:38 +0100 | [diff] [blame] | 176 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 177 | |
| 178 | if (magician_hp_switch == ucontrol->value.integer.value[0]) |
| 179 | return 0; |
| 180 | |
| 181 | magician_hp_switch = ucontrol->value.integer.value[0]; |
Lars-Peter Clausen | 0fbd44a | 2014-03-12 15:27:38 +0100 | [diff] [blame] | 182 | magician_ext_control(&card->dapm); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 183 | return 1; |
| 184 | } |
| 185 | |
| 186 | static int magician_get_spk(struct snd_kcontrol *kcontrol, |
| 187 | struct snd_ctl_elem_value *ucontrol) |
| 188 | { |
| 189 | ucontrol->value.integer.value[0] = magician_spk_switch; |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static int magician_set_spk(struct snd_kcontrol *kcontrol, |
| 194 | struct snd_ctl_elem_value *ucontrol) |
| 195 | { |
Lars-Peter Clausen | 0fbd44a | 2014-03-12 15:27:38 +0100 | [diff] [blame] | 196 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 197 | |
| 198 | if (magician_spk_switch == ucontrol->value.integer.value[0]) |
| 199 | return 0; |
| 200 | |
| 201 | magician_spk_switch = ucontrol->value.integer.value[0]; |
Lars-Peter Clausen | 0fbd44a | 2014-03-12 15:27:38 +0100 | [diff] [blame] | 202 | magician_ext_control(&card->dapm); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 203 | return 1; |
| 204 | } |
| 205 | |
| 206 | static int magician_get_input(struct snd_kcontrol *kcontrol, |
| 207 | struct snd_ctl_elem_value *ucontrol) |
| 208 | { |
Takashi Iwai | 127ee19 | 2016-02-29 17:23:50 +0100 | [diff] [blame] | 209 | ucontrol->value.enumerated.item[0] = magician_in_sel; |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | static int magician_set_input(struct snd_kcontrol *kcontrol, |
| 214 | struct snd_ctl_elem_value *ucontrol) |
| 215 | { |
Takashi Iwai | 127ee19 | 2016-02-29 17:23:50 +0100 | [diff] [blame] | 216 | if (magician_in_sel == ucontrol->value.enumerated.item[0]) |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 217 | return 0; |
| 218 | |
Takashi Iwai | 127ee19 | 2016-02-29 17:23:50 +0100 | [diff] [blame] | 219 | magician_in_sel = ucontrol->value.enumerated.item[0]; |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 220 | |
| 221 | switch (magician_in_sel) { |
| 222 | case MAGICIAN_MIC: |
| 223 | gpio_set_value(EGPIO_MAGICIAN_IN_SEL1, 1); |
| 224 | break; |
| 225 | case MAGICIAN_MIC_EXT: |
| 226 | gpio_set_value(EGPIO_MAGICIAN_IN_SEL1, 0); |
| 227 | } |
| 228 | |
| 229 | return 1; |
| 230 | } |
| 231 | |
| 232 | static int magician_spk_power(struct snd_soc_dapm_widget *w, |
| 233 | struct snd_kcontrol *k, int event) |
| 234 | { |
| 235 | gpio_set_value(EGPIO_MAGICIAN_SPK_POWER, SND_SOC_DAPM_EVENT_ON(event)); |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | static int magician_hp_power(struct snd_soc_dapm_widget *w, |
| 240 | struct snd_kcontrol *k, int event) |
| 241 | { |
| 242 | gpio_set_value(EGPIO_MAGICIAN_EP_POWER, SND_SOC_DAPM_EVENT_ON(event)); |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | static int magician_mic_bias(struct snd_soc_dapm_widget *w, |
| 247 | struct snd_kcontrol *k, int event) |
| 248 | { |
| 249 | gpio_set_value(EGPIO_MAGICIAN_MIC_POWER, SND_SOC_DAPM_EVENT_ON(event)); |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | /* magician machine dapm widgets */ |
| 254 | static const struct snd_soc_dapm_widget uda1380_dapm_widgets[] = { |
| 255 | SND_SOC_DAPM_HP("Headphone Jack", magician_hp_power), |
| 256 | SND_SOC_DAPM_SPK("Speaker", magician_spk_power), |
| 257 | SND_SOC_DAPM_MIC("Call Mic", magician_mic_bias), |
| 258 | SND_SOC_DAPM_MIC("Headset Mic", magician_mic_bias), |
| 259 | }; |
| 260 | |
| 261 | /* magician machine audio_map */ |
| 262 | static const struct snd_soc_dapm_route audio_map[] = { |
| 263 | |
| 264 | /* Headphone connected to VOUTL, VOUTR */ |
| 265 | {"Headphone Jack", NULL, "VOUTL"}, |
| 266 | {"Headphone Jack", NULL, "VOUTR"}, |
| 267 | |
| 268 | /* Speaker connected to VOUTL, VOUTR */ |
| 269 | {"Speaker", NULL, "VOUTL"}, |
| 270 | {"Speaker", NULL, "VOUTR"}, |
| 271 | |
| 272 | /* Mics are connected to VINM */ |
| 273 | {"VINM", NULL, "Headset Mic"}, |
| 274 | {"VINM", NULL, "Call Mic"}, |
| 275 | }; |
| 276 | |
Lars-Peter Clausen | 92be581 | 2016-11-12 14:23:13 +0100 | [diff] [blame] | 277 | static const char * const input_select[] = {"Call Mic", "Headset Mic"}; |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 278 | static const struct soc_enum magician_in_sel_enum = |
| 279 | SOC_ENUM_SINGLE_EXT(2, input_select); |
| 280 | |
| 281 | static const struct snd_kcontrol_new uda1380_magician_controls[] = { |
| 282 | SOC_SINGLE_BOOL_EXT("Headphone Switch", |
| 283 | (unsigned long)&magician_hp_switch, |
| 284 | magician_get_hp, magician_set_hp), |
| 285 | SOC_SINGLE_BOOL_EXT("Speaker Switch", |
| 286 | (unsigned long)&magician_spk_switch, |
| 287 | magician_get_spk, magician_set_spk), |
| 288 | SOC_ENUM_EXT("Input Select", magician_in_sel_enum, |
| 289 | magician_get_input, magician_set_input), |
| 290 | }; |
| 291 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 292 | /* magician digital audio interface glue - connects codec <--> CPU */ |
Kuninori Morimoto | 0182527 | 2019-06-06 13:11:51 +0900 | [diff] [blame^] | 293 | SND_SOC_DAILINK_DEFS(playback, |
| 294 | DAILINK_COMP_ARRAY(COMP_CPU("pxa-ssp-dai.0")), |
| 295 | DAILINK_COMP_ARRAY(COMP_CODEC("uda1380-codec.0-0018", |
| 296 | "uda1380-hifi-playback")), |
| 297 | DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio"))); |
| 298 | |
| 299 | SND_SOC_DAILINK_DEFS(capture, |
| 300 | DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-i2s")), |
| 301 | DAILINK_COMP_ARRAY(COMP_CODEC("uda1380-codec.0-0018", |
| 302 | "uda1380-hifi-capture")), |
| 303 | DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio"))); |
| 304 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 305 | static struct snd_soc_dai_link magician_dai[] = { |
| 306 | { |
| 307 | .name = "uda1380", |
| 308 | .stream_name = "UDA1380 Playback", |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 309 | .ops = &magician_playback_ops, |
Kuninori Morimoto | 0182527 | 2019-06-06 13:11:51 +0900 | [diff] [blame^] | 310 | SND_SOC_DAILINK_REG(playback), |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 311 | }, |
| 312 | { |
| 313 | .name = "uda1380", |
| 314 | .stream_name = "UDA1380 Capture", |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 315 | .ops = &magician_capture_ops, |
Kuninori Morimoto | 0182527 | 2019-06-06 13:11:51 +0900 | [diff] [blame^] | 316 | SND_SOC_DAILINK_REG(capture), |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 317 | } |
| 318 | }; |
| 319 | |
| 320 | /* magician audio machine driver */ |
| 321 | static struct snd_soc_card snd_soc_card_magician = { |
| 322 | .name = "Magician", |
Axel Lin | 561c6a1 | 2011-12-22 09:44:43 +0800 | [diff] [blame] | 323 | .owner = THIS_MODULE, |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 324 | .dai_link = magician_dai, |
| 325 | .num_links = ARRAY_SIZE(magician_dai), |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 326 | |
Lars-Peter Clausen | 0fbd44a | 2014-03-12 15:27:38 +0100 | [diff] [blame] | 327 | .controls = uda1380_magician_controls, |
| 328 | .num_controls = ARRAY_SIZE(uda1380_magician_controls), |
| 329 | .dapm_widgets = uda1380_dapm_widgets, |
| 330 | .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets), |
| 331 | .dapm_routes = audio_map, |
| 332 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Lars-Peter Clausen | 3cfaaaa | 2015-01-09 22:03:30 +0100 | [diff] [blame] | 333 | .fully_routed = true, |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 334 | }; |
| 335 | |
| 336 | static struct platform_device *magician_snd_device; |
| 337 | |
Philipp Zabel | 1abd918 | 2009-06-15 22:18:23 +0200 | [diff] [blame] | 338 | /* |
| 339 | * FIXME: move into magician board file once merged into the pxa tree |
| 340 | */ |
| 341 | static struct uda1380_platform_data uda1380_info = { |
| 342 | .gpio_power = EGPIO_MAGICIAN_CODEC_POWER, |
| 343 | .gpio_reset = EGPIO_MAGICIAN_CODEC_RESET, |
| 344 | .dac_clk = UDA1380_DAC_CLK_WSPLL, |
| 345 | }; |
| 346 | |
| 347 | static struct i2c_board_info i2c_board_info[] = { |
| 348 | { |
| 349 | I2C_BOARD_INFO("uda1380", 0x18), |
| 350 | .platform_data = &uda1380_info, |
| 351 | }, |
| 352 | }; |
| 353 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 354 | static int __init magician_init(void) |
| 355 | { |
| 356 | int ret; |
Philipp Zabel | 1abd918 | 2009-06-15 22:18:23 +0200 | [diff] [blame] | 357 | struct i2c_adapter *adapter; |
| 358 | struct i2c_client *client; |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 359 | |
| 360 | if (!machine_is_magician()) |
| 361 | return -ENODEV; |
| 362 | |
Philipp Zabel | 1abd918 | 2009-06-15 22:18:23 +0200 | [diff] [blame] | 363 | adapter = i2c_get_adapter(0); |
| 364 | if (!adapter) |
| 365 | return -ENODEV; |
| 366 | client = i2c_new_device(adapter, i2c_board_info); |
| 367 | i2c_put_adapter(adapter); |
| 368 | if (!client) |
| 369 | return -ENODEV; |
| 370 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 371 | ret = gpio_request(EGPIO_MAGICIAN_SPK_POWER, "SPK_POWER"); |
| 372 | if (ret) |
| 373 | goto err_request_spk; |
| 374 | ret = gpio_request(EGPIO_MAGICIAN_EP_POWER, "EP_POWER"); |
| 375 | if (ret) |
| 376 | goto err_request_ep; |
| 377 | ret = gpio_request(EGPIO_MAGICIAN_MIC_POWER, "MIC_POWER"); |
| 378 | if (ret) |
| 379 | goto err_request_mic; |
| 380 | ret = gpio_request(EGPIO_MAGICIAN_IN_SEL0, "IN_SEL0"); |
| 381 | if (ret) |
| 382 | goto err_request_in_sel0; |
| 383 | ret = gpio_request(EGPIO_MAGICIAN_IN_SEL1, "IN_SEL1"); |
| 384 | if (ret) |
| 385 | goto err_request_in_sel1; |
| 386 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 387 | gpio_set_value(EGPIO_MAGICIAN_IN_SEL0, 0); |
| 388 | |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 389 | magician_snd_device = platform_device_alloc("soc-audio", -1); |
| 390 | if (!magician_snd_device) { |
| 391 | ret = -ENOMEM; |
| 392 | goto err_pdev; |
| 393 | } |
| 394 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 395 | platform_set_drvdata(magician_snd_device, &snd_soc_card_magician); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 396 | ret = platform_device_add(magician_snd_device); |
| 397 | if (ret) { |
| 398 | platform_device_put(magician_snd_device); |
| 399 | goto err_pdev; |
| 400 | } |
| 401 | |
| 402 | return 0; |
| 403 | |
| 404 | err_pdev: |
| 405 | gpio_free(EGPIO_MAGICIAN_IN_SEL1); |
| 406 | err_request_in_sel1: |
| 407 | gpio_free(EGPIO_MAGICIAN_IN_SEL0); |
| 408 | err_request_in_sel0: |
| 409 | gpio_free(EGPIO_MAGICIAN_MIC_POWER); |
| 410 | err_request_mic: |
| 411 | gpio_free(EGPIO_MAGICIAN_EP_POWER); |
| 412 | err_request_ep: |
| 413 | gpio_free(EGPIO_MAGICIAN_SPK_POWER); |
| 414 | err_request_spk: |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 415 | return ret; |
| 416 | } |
| 417 | |
| 418 | static void __exit magician_exit(void) |
| 419 | { |
| 420 | platform_device_unregister(magician_snd_device); |
| 421 | |
| 422 | gpio_set_value(EGPIO_MAGICIAN_SPK_POWER, 0); |
| 423 | gpio_set_value(EGPIO_MAGICIAN_EP_POWER, 0); |
| 424 | gpio_set_value(EGPIO_MAGICIAN_MIC_POWER, 0); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 425 | |
| 426 | gpio_free(EGPIO_MAGICIAN_IN_SEL1); |
| 427 | gpio_free(EGPIO_MAGICIAN_IN_SEL0); |
| 428 | gpio_free(EGPIO_MAGICIAN_MIC_POWER); |
| 429 | gpio_free(EGPIO_MAGICIAN_EP_POWER); |
| 430 | gpio_free(EGPIO_MAGICIAN_SPK_POWER); |
Philipp Zabel | 7377226 | 2009-03-19 09:34:46 +0100 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | module_init(magician_init); |
| 434 | module_exit(magician_exit); |
| 435 | |
| 436 | MODULE_AUTHOR("Philipp Zabel"); |
| 437 | MODULE_DESCRIPTION("ALSA SoC Magician"); |
| 438 | MODULE_LICENSE("GPL"); |