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