blob: def92cc09f9caa0bf8a1ea0b178d5d29b6885c5f [file] [log] [blame]
Sylwester Nawrockif9ff3802019-04-19 12:21:57 +02001// SPDX-License-Identifier: GPL-2.0+
Jassi Brar96657d32010-12-20 11:05:57 +09002
3#include "../codecs/wm8994.h"
Giridhar Maruthyb3d76152011-07-13 16:52:06 +05304#include <sound/pcm_params.h>
Sachin Kamatde0022d2013-10-16 15:58:48 +05305#include <sound/soc.h>
Boojin Kim3d94a2a2011-11-22 11:03:22 +09006#include <linux/module.h>
Padmavathi Venna28a48052013-01-18 17:17:06 +05307#include <linux/of.h>
Jassi Brar96657d32010-12-20 11:05:57 +09008
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
34static int smdk_hw_params(struct snd_pcm_substream *substream,
35 struct snd_pcm_hw_params *params)
36{
Kuninori Morimoto21b6cd52023-09-11 23:49:45 +000037 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);
Jassi Brar96657d32010-12-20 11:05:57 +090039 unsigned int pll_out;
40 int ret;
41
42 /* AIF1CLK should be >=3MHz for optimal performance */
Tushar Behera88ce1462014-05-23 17:35:39 +053043 if (params_width(params) == 24)
Giridhar Maruthyb3d76152011-07-13 16:52:06 +053044 pll_out = params_rate(params) * 384;
45 else if (params_rate(params) == 8000 || params_rate(params) == 11025)
Jassi Brar96657d32010-12-20 11:05:57 +090046 pll_out = params_rate(params) * 512;
47 else
48 pll_out = params_rate(params) * 256;
49
Jassi Brar96657d32010-12-20 11:05:57 +090050 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 */
Rikard Falkeborn2080acf2021-07-28 19:25:48 +020066static const struct snd_soc_ops smdk_ops = {
Jassi Brar96657d32010-12-20 11:05:57 +090067 .hw_params = smdk_hw_params,
68};
69
70static int smdk_wm8994_init_paiftx(struct snd_soc_pcm_runtime *rtd)
71{
Lars-Peter Clausene6963002015-05-03 19:27:07 +020072 struct snd_soc_dapm_context *dapm = &rtd->card->dapm;
Jassi Brar96657d32010-12-20 11:05:57 +090073
Jassi Brar96657d32010-12-20 11:05:57 +090074 /* 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
Jassi Brar96657d32010-12-20 11:05:57 +090090 return 0;
91}
92
Kuninori Morimoto2f8ea842019-06-06 13:09:06 +090093SND_SOC_DAILINK_DEFS(aif1,
94 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
Kuninori Morimoto806bfc22019-06-28 10:48:19 +090095 DAILINK_COMP_ARRAY(COMP_CODEC("wm8994-codec", "wm8994-aif1")),
96 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
Kuninori Morimoto2f8ea842019-06-06 13:09:06 +090097
98SND_SOC_DAILINK_DEFS(fifo_tx,
99 DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s-sec")),
Kuninori Morimoto806bfc22019-06-28 10:48:19 +0900100 DAILINK_COMP_ARRAY(COMP_CODEC("wm8994-codec", "wm8994-aif1")),
101 DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s-sec")));
Kuninori Morimoto2f8ea842019-06-06 13:09:06 +0900102
Jassi Brar96657d32010-12-20 11:05:57 +0900103static struct snd_soc_dai_link smdk_dai[] = {
104 { /* Primary DAI i/f */
105 .name = "WM8994 AIF1",
106 .stream_name = "Pri_Dai",
Jassi Brar96657d32010-12-20 11:05:57 +0900107 .init = smdk_wm8994_init_paiftx,
Mark Brownf6ecf502013-07-26 12:01:53 +0100108 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
109 SND_SOC_DAIFMT_CBM_CFM,
Jassi Brar96657d32010-12-20 11:05:57 +0900110 .ops = &smdk_ops,
Kuninori Morimoto2f8ea842019-06-06 13:09:06 +0900111 SND_SOC_DAILINK_REG(aif1),
Jassi Brar96657d32010-12-20 11:05:57 +0900112 }, { /* Sec_Fifo Playback i/f */
113 .name = "Sec_FIFO TX",
114 .stream_name = "Sec_Dai",
Mark Brownf6ecf502013-07-26 12:01:53 +0100115 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
116 SND_SOC_DAIFMT_CBM_CFM,
Jassi Brar96657d32010-12-20 11:05:57 +0900117 .ops = &smdk_ops,
Kuninori Morimoto2f8ea842019-06-06 13:09:06 +0900118 SND_SOC_DAILINK_REG(fifo_tx),
Jassi Brar96657d32010-12-20 11:05:57 +0900119 },
120};
121
122static struct snd_soc_card smdk = {
123 .name = "SMDK-I2S",
Axel Lin095d79d2011-12-22 10:53:15 +0800124 .owner = THIS_MODULE,
Jassi Brar96657d32010-12-20 11:05:57 +0900125 .dai_link = smdk_dai,
126 .num_links = ARRAY_SIZE(smdk_dai),
127};
128
Rob Herring9958d852023-10-06 15:09:14 -0500129static const struct of_device_id samsung_wm8994_of_match[] = {
130 { .compatible = "samsung,smdk-wm8994" },
Mark Brownd30c1482013-07-26 12:42:19 +0100131 {},
132};
133MODULE_DEVICE_TABLE(of, samsung_wm8994_of_match);
Jassi Brar96657d32010-12-20 11:05:57 +0900134
Bill Pembertonfdca21a2012-12-07 09:26:15 -0500135static int smdk_audio_probe(struct platform_device *pdev)
Jassi Brar96657d32010-12-20 11:05:57 +0900136{
137 int ret;
Padmavathi Venna28a48052013-01-18 17:17:06 +0530138 struct device_node *np = pdev->dev.of_node;
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530139 struct snd_soc_card *card = &smdk;
Jassi Brar96657d32010-12-20 11:05:57 +0900140
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530141 card->dev = &pdev->dev;
Padmavathi Venna28a48052013-01-18 17:17:06 +0530142
143 if (np) {
Kuninori Morimoto2f8ea842019-06-06 13:09:06 +0900144 smdk_dai[0].cpus->dai_name = NULL;
145 smdk_dai[0].cpus->of_node = of_parse_phandle(np,
Padmavathi Venna28a48052013-01-18 17:17:06 +0530146 "samsung,i2s-controller", 0);
Kuninori Morimoto2f8ea842019-06-06 13:09:06 +0900147 if (!smdk_dai[0].cpus->of_node) {
Padmavathi Venna28a48052013-01-18 17:17:06 +0530148 dev_err(&pdev->dev,
149 "Property 'samsung,i2s-controller' missing or invalid\n");
150 ret = -EINVAL;
Pierre-Louis Bossartfbb123e2021-02-19 17:09:15 -0600151 return ret;
Padmavathi Venna28a48052013-01-18 17:17:06 +0530152 }
Kuninori Morimoto806bfc22019-06-28 10:48:19 +0900153
154 smdk_dai[0].platforms->name = NULL;
155 smdk_dai[0].platforms->of_node = smdk_dai[0].cpus->of_node;
Padmavathi Venna28a48052013-01-18 17:17:06 +0530156 }
157
Mark Brown9a8e0322013-09-16 18:02:28 +0100158 ret = devm_snd_soc_register_card(&pdev->dev, card);
Jassi Brar96657d32010-12-20 11:05:57 +0900159
Kuninori Morimoto27c6eae2021-12-14 11:08:41 +0900160 if (ret)
161 dev_err_probe(&pdev->dev, ret, "snd_soc_register_card() failed\n");
Jassi Brar96657d32010-12-20 11:05:57 +0900162
163 return ret;
164}
Jassi Brar96657d32010-12-20 11:05:57 +0900165
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530166static struct platform_driver smdk_audio_driver = {
167 .driver = {
Paul Bolle0b166d82014-02-10 22:25:31 +0100168 .name = "smdk-audio-wm8994",
Rob Herring9958d852023-10-06 15:09:14 -0500169 .of_match_table = samsung_wm8994_of_match,
Sachin Kamatde0022d2013-10-16 15:58:48 +0530170 .pm = &snd_soc_pm_ops,
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530171 },
172 .probe = smdk_audio_probe,
Sachin Kamat9c9acc92012-07-03 14:04:04 +0530173};
174
175module_platform_driver(smdk_audio_driver);
Jassi Brar96657d32010-12-20 11:05:57 +0900176
177MODULE_DESCRIPTION("ALSA SoC SMDK WM8994");
178MODULE_LICENSE("GPL");
Mark Brown0d47acc2013-07-17 17:20:19 +0100179MODULE_ALIAS("platform:smdk-audio-wm8994");