Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 1 | /* |
| 2 | * smdk_wm8994.c |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the |
| 6 | * Free Software Foundation; either version 2 of the License, or (at your |
| 7 | * option) any later version. |
| 8 | */ |
| 9 | |
| 10 | #include "../codecs/wm8994.h" |
Giridhar Maruthy | b3d7615 | 2011-07-13 16:52:06 +0530 | [diff] [blame] | 11 | #include <sound/pcm_params.h> |
Boojin Kim | 3d94a2a | 2011-11-22 11:03:22 +0900 | [diff] [blame] | 12 | #include <linux/module.h> |
Padmavathi Venna | 28a4805 | 2013-01-18 17:17:06 +0530 | [diff] [blame] | 13 | #include <linux/of.h> |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 14 | |
| 15 | /* |
| 16 | * Default CFG switch settings to use this driver: |
| 17 | * SMDKV310: CFG5-1000, CFG7-111111 |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * Configure audio route as :- |
| 22 | * $ amixer sset 'DAC1' on,on |
| 23 | * $ amixer sset 'Right Headphone Mux' 'DAC' |
| 24 | * $ amixer sset 'Left Headphone Mux' 'DAC' |
| 25 | * $ amixer sset 'DAC1R Mixer AIF1.1' on |
| 26 | * $ amixer sset 'DAC1L Mixer AIF1.1' on |
| 27 | * $ amixer sset 'IN2L' on |
| 28 | * $ amixer sset 'IN2L PGA IN2LN' on |
| 29 | * $ amixer sset 'MIXINL IN2L' on |
| 30 | * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on |
| 31 | * $ amixer sset 'IN2R' on |
| 32 | * $ amixer sset 'IN2R PGA IN2RN' on |
| 33 | * $ amixer sset 'MIXINR IN2R' on |
| 34 | * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on |
| 35 | */ |
| 36 | |
| 37 | /* SMDK has a 16.934MHZ crystal attached to WM8994 */ |
| 38 | #define SMDK_WM8994_FREQ 16934000 |
| 39 | |
| 40 | static int smdk_hw_params(struct snd_pcm_substream *substream, |
| 41 | struct snd_pcm_hw_params *params) |
| 42 | { |
| 43 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 44 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 45 | unsigned int pll_out; |
| 46 | int ret; |
| 47 | |
| 48 | /* AIF1CLK should be >=3MHz for optimal performance */ |
Giridhar Maruthy | b3d7615 | 2011-07-13 16:52:06 +0530 | [diff] [blame] | 49 | if (params_format(params) == SNDRV_PCM_FORMAT_S24_LE) |
| 50 | pll_out = params_rate(params) * 384; |
| 51 | else if (params_rate(params) == 8000 || params_rate(params) == 11025) |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 52 | pll_out = params_rate(params) * 512; |
| 53 | else |
| 54 | pll_out = params_rate(params) * 256; |
| 55 | |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 56 | ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1, |
| 57 | SMDK_WM8994_FREQ, pll_out); |
| 58 | if (ret < 0) |
| 59 | return ret; |
| 60 | |
| 61 | ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1, |
| 62 | pll_out, SND_SOC_CLOCK_IN); |
| 63 | if (ret < 0) |
| 64 | return ret; |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | * SMDK WM8994 DAI operations. |
| 71 | */ |
| 72 | static struct snd_soc_ops smdk_ops = { |
| 73 | .hw_params = smdk_hw_params, |
| 74 | }; |
| 75 | |
| 76 | static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd) |
| 77 | { |
| 78 | struct snd_soc_codec *codec = rtd->codec; |
| 79 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 80 | |
| 81 | /* HeadPhone */ |
| 82 | snd_soc_dapm_enable_pin(dapm, "HPOUT1R"); |
| 83 | snd_soc_dapm_enable_pin(dapm, "HPOUT1L"); |
| 84 | |
| 85 | /* MicIn */ |
| 86 | snd_soc_dapm_enable_pin(dapm, "IN1LN"); |
| 87 | snd_soc_dapm_enable_pin(dapm, "IN1RN"); |
| 88 | |
| 89 | /* LineIn */ |
| 90 | snd_soc_dapm_enable_pin(dapm, "IN2LN"); |
| 91 | snd_soc_dapm_enable_pin(dapm, "IN2RN"); |
| 92 | |
| 93 | /* Other pins NC */ |
| 94 | snd_soc_dapm_nc_pin(dapm, "HPOUT2P"); |
| 95 | snd_soc_dapm_nc_pin(dapm, "HPOUT2N"); |
| 96 | snd_soc_dapm_nc_pin(dapm, "SPKOUTLN"); |
| 97 | snd_soc_dapm_nc_pin(dapm, "SPKOUTLP"); |
| 98 | snd_soc_dapm_nc_pin(dapm, "SPKOUTRP"); |
| 99 | snd_soc_dapm_nc_pin(dapm, "SPKOUTRN"); |
| 100 | snd_soc_dapm_nc_pin(dapm, "LINEOUT1N"); |
| 101 | snd_soc_dapm_nc_pin(dapm, "LINEOUT1P"); |
| 102 | snd_soc_dapm_nc_pin(dapm, "LINEOUT2N"); |
| 103 | snd_soc_dapm_nc_pin(dapm, "LINEOUT2P"); |
| 104 | snd_soc_dapm_nc_pin(dapm, "IN1LP"); |
| 105 | snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN"); |
| 106 | snd_soc_dapm_nc_pin(dapm, "IN1RP"); |
| 107 | snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP"); |
| 108 | |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | static struct snd_soc_dai_link smdk_dai[] = { |
| 113 | { /* Primary DAI i/f */ |
| 114 | .name = "WM8994 AIF1", |
| 115 | .stream_name = "Pri_Dai", |
| 116 | .cpu_dai_name = "samsung-i2s.0", |
| 117 | .codec_dai_name = "wm8994-aif1", |
Padmavathi Venna | a08485d8 | 2012-12-07 13:59:21 +0530 | [diff] [blame] | 118 | .platform_name = "samsung-i2s.0", |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 119 | .codec_name = "wm8994-codec", |
| 120 | .init = smdk_wm8994_init_paiftx, |
Mark Brown | f6ecf50 | 2013-07-26 12:01:53 +0100 | [diff] [blame^] | 121 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 122 | SND_SOC_DAIFMT_CBM_CFM, |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 123 | .ops = &smdk_ops, |
| 124 | }, { /* Sec_Fifo Playback i/f */ |
| 125 | .name = "Sec_FIFO TX", |
| 126 | .stream_name = "Sec_Dai", |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 127 | .cpu_dai_name = "samsung-i2s-sec", |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 128 | .codec_dai_name = "wm8994-aif1", |
Padmavathi Venna | 7c62eeb | 2013-01-18 17:17:00 +0530 | [diff] [blame] | 129 | .platform_name = "samsung-i2s-sec", |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 130 | .codec_name = "wm8994-codec", |
Mark Brown | f6ecf50 | 2013-07-26 12:01:53 +0100 | [diff] [blame^] | 131 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 132 | SND_SOC_DAIFMT_CBM_CFM, |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 133 | .ops = &smdk_ops, |
| 134 | }, |
| 135 | }; |
| 136 | |
| 137 | static struct snd_soc_card smdk = { |
| 138 | .name = "SMDK-I2S", |
Axel Lin | 095d79d | 2011-12-22 10:53:15 +0800 | [diff] [blame] | 139 | .owner = THIS_MODULE, |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 140 | .dai_link = smdk_dai, |
| 141 | .num_links = ARRAY_SIZE(smdk_dai), |
| 142 | }; |
| 143 | |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 144 | |
Bill Pemberton | fdca21a | 2012-12-07 09:26:15 -0500 | [diff] [blame] | 145 | static int smdk_audio_probe(struct platform_device *pdev) |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 146 | { |
| 147 | int ret; |
Padmavathi Venna | 28a4805 | 2013-01-18 17:17:06 +0530 | [diff] [blame] | 148 | struct device_node *np = pdev->dev.of_node; |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 149 | struct snd_soc_card *card = &smdk; |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 150 | |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 151 | card->dev = &pdev->dev; |
Padmavathi Venna | 28a4805 | 2013-01-18 17:17:06 +0530 | [diff] [blame] | 152 | |
| 153 | if (np) { |
| 154 | smdk_dai[0].cpu_dai_name = NULL; |
| 155 | smdk_dai[0].cpu_of_node = of_parse_phandle(np, |
| 156 | "samsung,i2s-controller", 0); |
| 157 | if (!smdk_dai[0].cpu_of_node) { |
| 158 | dev_err(&pdev->dev, |
| 159 | "Property 'samsung,i2s-controller' missing or invalid\n"); |
| 160 | ret = -EINVAL; |
| 161 | } |
| 162 | |
| 163 | smdk_dai[0].platform_name = NULL; |
| 164 | smdk_dai[0].platform_of_node = smdk_dai[0].cpu_of_node; |
| 165 | } |
| 166 | |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 167 | ret = snd_soc_register_card(card); |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 168 | |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 169 | if (ret) |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 170 | dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret); |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 171 | |
| 172 | return ret; |
| 173 | } |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 174 | |
Bill Pemberton | fdca21a | 2012-12-07 09:26:15 -0500 | [diff] [blame] | 175 | static int smdk_audio_remove(struct platform_device *pdev) |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 176 | { |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 177 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 178 | |
| 179 | snd_soc_unregister_card(card); |
| 180 | |
| 181 | return 0; |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 182 | } |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 183 | |
Padmavathi Venna | 28a4805 | 2013-01-18 17:17:06 +0530 | [diff] [blame] | 184 | #ifdef CONFIG_OF |
| 185 | static const struct of_device_id samsung_wm8994_of_match[] = { |
| 186 | { .compatible = "samsung,smdk-wm8994", }, |
| 187 | {}, |
| 188 | }; |
| 189 | MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match); |
| 190 | #endif /* CONFIG_OF */ |
| 191 | |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 192 | static struct platform_driver smdk_audio_driver = { |
| 193 | .driver = { |
Mark Brown | 0d47acc | 2013-07-17 17:20:19 +0100 | [diff] [blame] | 194 | .name = "smdk-audio-wm8894", |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 195 | .owner = THIS_MODULE, |
Padmavathi Venna | 28a4805 | 2013-01-18 17:17:06 +0530 | [diff] [blame] | 196 | .of_match_table = of_match_ptr(samsung_wm8994_of_match), |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 197 | }, |
| 198 | .probe = smdk_audio_probe, |
Bill Pemberton | fdca21a | 2012-12-07 09:26:15 -0500 | [diff] [blame] | 199 | .remove = smdk_audio_remove, |
Sachin Kamat | 9c9acc9 | 2012-07-03 14:04:04 +0530 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | module_platform_driver(smdk_audio_driver); |
Jassi Brar | 96657d3 | 2010-12-20 11:05:57 +0900 | [diff] [blame] | 203 | |
| 204 | MODULE_DESCRIPTION("ALSA SoC SMDK WM8994"); |
| 205 | MODULE_LICENSE("GPL"); |
Mark Brown | 0d47acc | 2013-07-17 17:20:19 +0100 | [diff] [blame] | 206 | MODULE_ALIAS("platform:smdk-audio-wm8994"); |