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