1 // SPDX-License-Identifier: GPL-2.0+ 2 3 #include "../codecs/wm8994.h" 4 #include <sound/pcm_params.h> 5 #include <sound/soc.h> 6 #include <linux/module.h> 7 #include <linux/of.h> 8 9 /* 10 * Default CFG switch settings to use this driver: 11 * SMDKV310: CFG5-1000, CFG7-111111 12 */ 13 14 /* 15 * Configure audio route as :- 16 * $ amixer sset 'DAC1' on,on 17 * $ amixer sset 'Right Headphone Mux' 'DAC' 18 * $ amixer sset 'Left Headphone Mux' 'DAC' 19 * $ amixer sset 'DAC1R Mixer AIF1.1' on 20 * $ amixer sset 'DAC1L Mixer AIF1.1' on 21 * $ amixer sset 'IN2L' on 22 * $ amixer sset 'IN2L PGA IN2LN' on 23 * $ amixer sset 'MIXINL IN2L' on 24 * $ amixer sset 'AIF1ADC1L Mixer ADC/DMIC' on 25 * $ amixer sset 'IN2R' on 26 * $ amixer sset 'IN2R PGA IN2RN' on 27 * $ amixer sset 'MIXINR IN2R' on 28 * $ amixer sset 'AIF1ADC1R Mixer ADC/DMIC' on 29 */ 30 31 /* SMDK has a 16.934MHZ crystal attached to WM8994 */ 32 #define SMDK_WM8994_FREQ 16934000 33 34 static int smdk_hw_params(struct snd_pcm_substream *substream, 35 struct snd_pcm_hw_params *params) 36 { 37 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 38 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); 39 unsigned int pll_out; 40 int ret; 41 42 /* AIF1CLK should be >=3MHz for optimal performance */ 43 if (params_width(params) == 24) 44 pll_out = params_rate(params) * 384; 45 else if (params_rate(params) == 8000 || params_rate(params) == 11025) 46 pll_out = params_rate(params) * 512; 47 else 48 pll_out = params_rate(params) * 256; 49 50 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1, 51 SMDK_WM8994_FREQ, pll_out); 52 if (ret < 0) 53 return ret; 54 55 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1, 56 pll_out, SND_SOC_CLOCK_IN); 57 if (ret < 0) 58 return ret; 59 60 return 0; 61 } 62 63 /* 64 * SMDK WM8994 DAI operations. 65 */ 66 static const struct snd_soc_ops smdk_ops = { 67 .hw_params = smdk_hw_params, 68 }; 69 70 static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd) 71 { 72 struct snd_soc_dapm_context *dapm = &rtd->card->dapm; 73 74 /* Other pins NC */ 75 snd_soc_dapm_nc_pin(dapm, "HPOUT2P"); 76 snd_soc_dapm_nc_pin(dapm, "HPOUT2N"); 77 snd_soc_dapm_nc_pin(dapm, "SPKOUTLN"); 78 snd_soc_dapm_nc_pin(dapm, "SPKOUTLP"); 79 snd_soc_dapm_nc_pin(dapm, "SPKOUTRP"); 80 snd_soc_dapm_nc_pin(dapm, "SPKOUTRN"); 81 snd_soc_dapm_nc_pin(dapm, "LINEOUT1N"); 82 snd_soc_dapm_nc_pin(dapm, "LINEOUT1P"); 83 snd_soc_dapm_nc_pin(dapm, "LINEOUT2N"); 84 snd_soc_dapm_nc_pin(dapm, "LINEOUT2P"); 85 snd_soc_dapm_nc_pin(dapm, "IN1LP"); 86 snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN"); 87 snd_soc_dapm_nc_pin(dapm, "IN1RP"); 88 snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP"); 89 90 return 0; 91 } 92 93 SND_SOC_DAILINK_DEFS(aif1, 94 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")), 95 DAILINK_COMP_ARRAY(COMP_CODEC("wm8994-codec", "wm8994-aif1")), 96 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0"))); 97 98 SND_SOC_DAILINK_DEFS(fifo_tx, 99 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s-sec")), 100 DAILINK_COMP_ARRAY(COMP_CODEC("wm8994-codec", "wm8994-aif1")), 101 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s-sec"))); 102 103 static struct snd_soc_dai_link smdk_dai[] = { 104 { /* Primary DAI i/f */ 105 .name = "WM8994 AIF1", 106 .stream_name = "Pri_Dai", 107 .init = smdk_wm8994_init_paiftx, 108 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 109 SND_SOC_DAIFMT_CBM_CFM, 110 .ops = &smdk_ops, 111 SND_SOC_DAILINK_REG(aif1), 112 }, { /* Sec_Fifo Playback i/f */ 113 .name = "Sec_FIFO TX", 114 .stream_name = "Sec_Dai", 115 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 116 SND_SOC_DAIFMT_CBM_CFM, 117 .ops = &smdk_ops, 118 SND_SOC_DAILINK_REG(fifo_tx), 119 }, 120 }; 121 122 static struct snd_soc_card smdk = { 123 .name = "SMDK-I2S", 124 .owner = THIS_MODULE, 125 .dai_link = smdk_dai, 126 .num_links = ARRAY_SIZE(smdk_dai), 127 }; 128 129 static const struct of_device_id samsung_wm8994_of_match[] = { 130 { .compatible = "samsung,smdk-wm8994" }, 131 {}, 132 }; 133 MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match); 134 135 static int smdk_audio_probe(struct platform_device *pdev) 136 { 137 int ret; 138 struct device_node *np = pdev->dev.of_node; 139 struct snd_soc_card *card = &smdk; 140 141 card->dev = &pdev->dev; 142 143 if (np) { 144 smdk_dai[0].cpus->dai_name = NULL; 145 smdk_dai[0].cpus->of_node = of_parse_phandle(np, 146 "samsung,i2s-controller", 0); 147 if (!smdk_dai[0].cpus->of_node) { 148 dev_err(&pdev->dev, 149 "Property 'samsung,i2s-controller' missing or invalid\n"); 150 ret = -EINVAL; 151 return ret; 152 } 153 154 smdk_dai[0].platforms->name = NULL; 155 smdk_dai[0].platforms->of_node = smdk_dai[0].cpus->of_node; 156 } 157 158 ret = devm_snd_soc_register_card(&pdev->dev, card); 159 160 if (ret) 161 dev_err_probe(&pdev->dev, ret, "snd_soc_register_card() failed\n"); 162 163 return ret; 164 } 165 166 static struct platform_driver smdk_audio_driver = { 167 .driver = { 168 .name = "smdk-audio-wm8994", 169 .of_match_table = samsung_wm8994_of_match, 170 .pm = &snd_soc_pm_ops, 171 }, 172 .probe = smdk_audio_probe, 173 }; 174 175 module_platform_driver(smdk_audio_driver); 176 177 MODULE_DESCRIPTION("ALSA SoC SMDK WM8994"); 178 MODULE_LICENSE("GPL"); 179 MODULE_ALIAS("platform:smdk-audio-wm8994"); 180