Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * wm1133-ev1.c - Audio for WM1133-EV1 on i.MX31ADS |
| 3 | * |
| 4 | * Copyright (c) 2010 Wolfson Microelectronics plc |
| 5 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 6 | * |
| 7 | * Based on an earlier driver for the same hardware by Liam Girdwood. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/clk.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 17 | #include <linux/module.h> |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 18 | #include <sound/core.h> |
| 19 | #include <sound/jack.h> |
| 20 | #include <sound/pcm.h> |
| 21 | #include <sound/pcm_params.h> |
| 22 | #include <sound/soc.h> |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 23 | |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 24 | #include "imx-ssi.h" |
| 25 | #include "../codecs/wm8350.h" |
Shawn Guo | 3c77c29 | 2012-03-05 22:30:53 +0800 | [diff] [blame] | 26 | #include "imx-audmux.h" |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 27 | |
| 28 | /* There is a silicon mic on the board optionally connected via a solder pad |
| 29 | * SP1. Define this to enable it. |
| 30 | */ |
| 31 | #undef USE_SIMIC |
| 32 | |
| 33 | struct _wm8350_audio { |
| 34 | unsigned int channels; |
| 35 | snd_pcm_format_t format; |
| 36 | unsigned int rate; |
| 37 | unsigned int sysclk; |
| 38 | unsigned int bclkdiv; |
| 39 | unsigned int clkdiv; |
| 40 | unsigned int lr_rate; |
| 41 | }; |
| 42 | |
| 43 | /* in order of power consumption per rate (lowest first) */ |
| 44 | static const struct _wm8350_audio wm8350_audio[] = { |
| 45 | /* 16bit mono modes */ |
| 46 | {1, SNDRV_PCM_FORMAT_S16_LE, 8000, 12288000 >> 1, |
| 47 | WM8350_BCLK_DIV_48, WM8350_DACDIV_3, 16,}, |
| 48 | |
| 49 | /* 16 bit stereo modes */ |
| 50 | {2, SNDRV_PCM_FORMAT_S16_LE, 8000, 12288000, |
| 51 | WM8350_BCLK_DIV_48, WM8350_DACDIV_6, 32,}, |
| 52 | {2, SNDRV_PCM_FORMAT_S16_LE, 16000, 12288000, |
| 53 | WM8350_BCLK_DIV_24, WM8350_DACDIV_3, 32,}, |
| 54 | {2, SNDRV_PCM_FORMAT_S16_LE, 32000, 12288000, |
| 55 | WM8350_BCLK_DIV_12, WM8350_DACDIV_1_5, 32,}, |
| 56 | {2, SNDRV_PCM_FORMAT_S16_LE, 48000, 12288000, |
| 57 | WM8350_BCLK_DIV_8, WM8350_DACDIV_1, 32,}, |
| 58 | {2, SNDRV_PCM_FORMAT_S16_LE, 96000, 24576000, |
| 59 | WM8350_BCLK_DIV_8, WM8350_DACDIV_1, 32,}, |
| 60 | {2, SNDRV_PCM_FORMAT_S16_LE, 11025, 11289600, |
| 61 | WM8350_BCLK_DIV_32, WM8350_DACDIV_4, 32,}, |
| 62 | {2, SNDRV_PCM_FORMAT_S16_LE, 22050, 11289600, |
| 63 | WM8350_BCLK_DIV_16, WM8350_DACDIV_2, 32,}, |
| 64 | {2, SNDRV_PCM_FORMAT_S16_LE, 44100, 11289600, |
| 65 | WM8350_BCLK_DIV_8, WM8350_DACDIV_1, 32,}, |
| 66 | {2, SNDRV_PCM_FORMAT_S16_LE, 88200, 22579200, |
| 67 | WM8350_BCLK_DIV_8, WM8350_DACDIV_1, 32,}, |
| 68 | |
| 69 | /* 24bit stereo modes */ |
| 70 | {2, SNDRV_PCM_FORMAT_S24_LE, 48000, 12288000, |
| 71 | WM8350_BCLK_DIV_4, WM8350_DACDIV_1, 64,}, |
| 72 | {2, SNDRV_PCM_FORMAT_S24_LE, 96000, 24576000, |
| 73 | WM8350_BCLK_DIV_4, WM8350_DACDIV_1, 64,}, |
| 74 | {2, SNDRV_PCM_FORMAT_S24_LE, 44100, 11289600, |
| 75 | WM8350_BCLK_DIV_4, WM8350_DACDIV_1, 64,}, |
| 76 | {2, SNDRV_PCM_FORMAT_S24_LE, 88200, 22579200, |
| 77 | WM8350_BCLK_DIV_4, WM8350_DACDIV_1, 64,}, |
| 78 | }; |
| 79 | |
| 80 | static int wm1133_ev1_hw_params(struct snd_pcm_substream *substream, |
| 81 | struct snd_pcm_hw_params *params) |
| 82 | { |
| 83 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 84 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 85 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 86 | int i, found = 0; |
| 87 | snd_pcm_format_t format = params_format(params); |
| 88 | unsigned int rate = params_rate(params); |
| 89 | unsigned int channels = params_channels(params); |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 90 | |
| 91 | /* find the correct audio parameters */ |
| 92 | for (i = 0; i < ARRAY_SIZE(wm8350_audio); i++) { |
| 93 | if (rate == wm8350_audio[i].rate && |
| 94 | format == wm8350_audio[i].format && |
| 95 | channels == wm8350_audio[i].channels) { |
| 96 | found = 1; |
| 97 | break; |
| 98 | } |
| 99 | } |
| 100 | if (!found) |
| 101 | return -EINVAL; |
| 102 | |
| 103 | /* codec FLL input is 14.75 MHz from MCLK */ |
| 104 | snd_soc_dai_set_pll(codec_dai, 0, 0, 14750000, wm8350_audio[i].sysclk); |
| 105 | |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 106 | /* TODO: The SSI driver should figure this out for us */ |
| 107 | switch (channels) { |
| 108 | case 2: |
Lars-Peter Clausen | d0077aa | 2015-01-12 10:27:18 +0100 | [diff] [blame] | 109 | snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 0); |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 110 | break; |
| 111 | case 1: |
Lars-Peter Clausen | d0077aa | 2015-01-12 10:27:18 +0100 | [diff] [blame] | 112 | snd_soc_dai_set_tdm_slot(cpu_dai, 0x1, 0x1, 1, 0); |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 113 | break; |
| 114 | default: |
| 115 | return -EINVAL; |
| 116 | } |
| 117 | |
| 118 | /* set MCLK as the codec system clock for DAC and ADC */ |
| 119 | snd_soc_dai_set_sysclk(codec_dai, WM8350_MCLK_SEL_PLL_MCLK, |
| 120 | wm8350_audio[i].sysclk, SND_SOC_CLOCK_IN); |
| 121 | |
| 122 | /* set codec BCLK division for sample rate */ |
| 123 | snd_soc_dai_set_clkdiv(codec_dai, WM8350_BCLK_CLKDIV, |
| 124 | wm8350_audio[i].bclkdiv); |
| 125 | |
| 126 | /* DAI is synchronous and clocked with DAC LRCLK & ADC LRC */ |
| 127 | snd_soc_dai_set_clkdiv(codec_dai, |
| 128 | WM8350_DACLR_CLKDIV, wm8350_audio[i].lr_rate); |
| 129 | snd_soc_dai_set_clkdiv(codec_dai, |
| 130 | WM8350_ADCLR_CLKDIV, wm8350_audio[i].lr_rate); |
| 131 | |
| 132 | /* now configure DAC and ADC clocks */ |
| 133 | snd_soc_dai_set_clkdiv(codec_dai, |
| 134 | WM8350_DAC_CLKDIV, wm8350_audio[i].clkdiv); |
| 135 | |
| 136 | snd_soc_dai_set_clkdiv(codec_dai, |
| 137 | WM8350_ADC_CLKDIV, wm8350_audio[i].clkdiv); |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static struct snd_soc_ops wm1133_ev1_ops = { |
| 143 | .hw_params = wm1133_ev1_hw_params, |
| 144 | }; |
| 145 | |
| 146 | static const struct snd_soc_dapm_widget wm1133_ev1_widgets[] = { |
| 147 | #ifdef USE_SIMIC |
| 148 | SND_SOC_DAPM_MIC("SiMIC", NULL), |
| 149 | #endif |
| 150 | SND_SOC_DAPM_MIC("Mic1 Jack", NULL), |
| 151 | SND_SOC_DAPM_MIC("Mic2 Jack", NULL), |
| 152 | SND_SOC_DAPM_LINE("Line In Jack", NULL), |
| 153 | SND_SOC_DAPM_LINE("Line Out Jack", NULL), |
| 154 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 155 | }; |
| 156 | |
| 157 | /* imx32ads soc_card audio map */ |
| 158 | static const struct snd_soc_dapm_route wm1133_ev1_map[] = { |
| 159 | |
| 160 | #ifdef USE_SIMIC |
| 161 | /* SiMIC --> IN1LN (with automatic bias) via SP1 */ |
| 162 | { "IN1LN", NULL, "Mic Bias" }, |
| 163 | { "Mic Bias", NULL, "SiMIC" }, |
| 164 | #endif |
| 165 | |
| 166 | /* Mic 1 Jack --> IN1LN and IN1LP (with automatic bias) */ |
| 167 | { "IN1LN", NULL, "Mic Bias" }, |
| 168 | { "IN1LP", NULL, "Mic1 Jack" }, |
| 169 | { "Mic Bias", NULL, "Mic1 Jack" }, |
| 170 | |
| 171 | /* Mic 2 Jack --> IN1RN and IN1RP (with automatic bias) */ |
| 172 | { "IN1RN", NULL, "Mic Bias" }, |
Mark Brown | 27648b2 | 2010-03-16 16:09:47 +0000 | [diff] [blame] | 173 | { "IN1RP", NULL, "Mic2 Jack" }, |
| 174 | { "Mic Bias", NULL, "Mic2 Jack" }, |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 175 | |
| 176 | /* Line in Jack --> AUX (L+R) */ |
| 177 | { "IN3R", NULL, "Line In Jack" }, |
| 178 | { "IN3L", NULL, "Line In Jack" }, |
| 179 | |
| 180 | /* Out1 --> Headphone Jack */ |
| 181 | { "Headphone Jack", NULL, "OUT1R" }, |
| 182 | { "Headphone Jack", NULL, "OUT1L" }, |
| 183 | |
| 184 | /* Out1 --> Line Out Jack */ |
| 185 | { "Line Out Jack", NULL, "OUT2R" }, |
| 186 | { "Line Out Jack", NULL, "OUT2L" }, |
| 187 | }; |
| 188 | |
| 189 | static struct snd_soc_jack hp_jack; |
| 190 | |
| 191 | static struct snd_soc_jack_pin hp_jack_pins[] = { |
| 192 | { .pin = "Headphone Jack", .mask = SND_JACK_HEADPHONE }, |
| 193 | }; |
| 194 | |
Mark Brown | 093208f | 2010-03-16 16:11:14 +0000 | [diff] [blame] | 195 | static struct snd_soc_jack mic_jack; |
| 196 | |
| 197 | static struct snd_soc_jack_pin mic_jack_pins[] = { |
| 198 | { .pin = "Mic1 Jack", .mask = SND_JACK_MICROPHONE }, |
| 199 | { .pin = "Mic2 Jack", .mask = SND_JACK_MICROPHONE }, |
| 200 | }; |
| 201 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 202 | static int wm1133_ev1_init(struct snd_soc_pcm_runtime *rtd) |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 203 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 204 | struct snd_soc_codec *codec = rtd->codec; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 205 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 206 | |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 207 | /* Headphone jack detection */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 208 | snd_soc_jack_new(codec, "Headphone", SND_JACK_HEADPHONE, &hp_jack); |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 209 | snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins), |
| 210 | hp_jack_pins); |
| 211 | wm8350_hp_jack_detect(codec, WM8350_JDR, &hp_jack, SND_JACK_HEADPHONE); |
| 212 | |
Mark Brown | 093208f | 2010-03-16 16:11:14 +0000 | [diff] [blame] | 213 | /* Microphone jack detection */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 214 | snd_soc_jack_new(codec, "Microphone", |
Mark Brown | 093208f | 2010-03-16 16:11:14 +0000 | [diff] [blame] | 215 | SND_JACK_MICROPHONE | SND_JACK_BTN_0, &mic_jack); |
| 216 | snd_soc_jack_add_pins(&mic_jack, ARRAY_SIZE(mic_jack_pins), |
| 217 | mic_jack_pins); |
| 218 | wm8350_mic_jack_detect(codec, &mic_jack, SND_JACK_MICROPHONE, |
| 219 | SND_JACK_BTN_0); |
| 220 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 221 | snd_soc_dapm_force_enable_pin(dapm, "Mic Bias"); |
Mark Brown | 2f14430 | 2010-03-22 13:48:36 +0000 | [diff] [blame] | 222 | |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | |
| 227 | static struct snd_soc_dai_link wm1133_ev1_dai = { |
| 228 | .name = "WM1133-EV1", |
| 229 | .stream_name = "Audio", |
Mark Brown | 205d231 | 2010-09-30 13:46:14 -0700 | [diff] [blame] | 230 | .cpu_dai_name = "imx-ssi.0", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 231 | .codec_dai_name = "wm8350-hifi", |
Shawn Guo | 2bf9d4b | 2013-04-25 11:18:49 +0800 | [diff] [blame] | 232 | .platform_name = "imx-ssi.0", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 233 | .codec_name = "wm8350-codec.0-0x1a", |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 234 | .init = wm1133_ev1_init, |
| 235 | .ops = &wm1133_ev1_ops, |
| 236 | .symmetric_rates = 1, |
Lars-Peter Clausen | 734890a | 2015-01-01 17:16:14 +0100 | [diff] [blame] | 237 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 238 | SND_SOC_DAIFMT_CBM_CFM, |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | static struct snd_soc_card wm1133_ev1 = { |
| 242 | .name = "WM1133-EV1", |
Axel Lin | 6aff8cc | 2011-12-23 14:47:08 +0800 | [diff] [blame] | 243 | .owner = THIS_MODULE, |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 244 | .dai_link = &wm1133_ev1_dai, |
| 245 | .num_links = 1, |
Lars-Peter Clausen | 112ad7f | 2014-03-03 08:17:08 +0100 | [diff] [blame] | 246 | |
| 247 | .dapm_widgets = wm1133_ev1_widgets, |
| 248 | .num_dapm_widgets = ARRAY_SIZE(wm1133_ev1_widgets), |
| 249 | .dapm_routes = wm1133_ev1_map, |
| 250 | .num_dapm_routes = ARRAY_SIZE(wm1133_ev1_map), |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 251 | }; |
| 252 | |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 253 | static struct platform_device *wm1133_ev1_snd_device; |
| 254 | |
| 255 | static int __init wm1133_ev1_audio_init(void) |
| 256 | { |
| 257 | int ret; |
| 258 | unsigned int ptcr, pdcr; |
| 259 | |
| 260 | /* SSI0 mastered by port 5 */ |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 261 | ptcr = IMX_AUDMUX_V2_PTCR_SYN | |
| 262 | IMX_AUDMUX_V2_PTCR_TFSDIR | |
| 263 | IMX_AUDMUX_V2_PTCR_TFSEL(MX31_AUDMUX_PORT5_SSI_PINS_5) | |
| 264 | IMX_AUDMUX_V2_PTCR_TCLKDIR | |
| 265 | IMX_AUDMUX_V2_PTCR_TCSEL(MX31_AUDMUX_PORT5_SSI_PINS_5); |
| 266 | pdcr = IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT5_SSI_PINS_5); |
| 267 | imx_audmux_v2_configure_port(MX31_AUDMUX_PORT1_SSI0, ptcr, pdcr); |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 268 | |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 269 | ptcr = IMX_AUDMUX_V2_PTCR_SYN; |
| 270 | pdcr = IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT1_SSI0); |
| 271 | imx_audmux_v2_configure_port(MX31_AUDMUX_PORT5_SSI_PINS_5, ptcr, pdcr); |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 272 | |
| 273 | wm1133_ev1_snd_device = platform_device_alloc("soc-audio", -1); |
| 274 | if (!wm1133_ev1_snd_device) |
| 275 | return -ENOMEM; |
| 276 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 277 | platform_set_drvdata(wm1133_ev1_snd_device, &wm1133_ev1); |
Mark Brown | eeec124 | 2010-02-23 11:15:34 +0000 | [diff] [blame] | 278 | ret = platform_device_add(wm1133_ev1_snd_device); |
| 279 | |
| 280 | if (ret) |
| 281 | platform_device_put(wm1133_ev1_snd_device); |
| 282 | |
| 283 | return ret; |
| 284 | } |
| 285 | module_init(wm1133_ev1_audio_init); |
| 286 | |
| 287 | static void __exit wm1133_ev1_audio_exit(void) |
| 288 | { |
| 289 | platform_device_unregister(wm1133_ev1_snd_device); |
| 290 | } |
| 291 | module_exit(wm1133_ev1_audio_exit); |
| 292 | |
| 293 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 294 | MODULE_DESCRIPTION("Audio for WM1133-EV1 on i.MX31ADS"); |
| 295 | MODULE_LICENSE("GPL"); |