xref: /openbmc/linux/sound/soc/samsung/lowland.c (revision bbaf1ff0)
1 // SPDX-License-Identifier: GPL-2.0+
2 //
3 // Lowland audio support
4 //
5 // Copyright 2011 Wolfson Microelectronics
6 
7 #include <sound/soc.h>
8 #include <sound/soc-dapm.h>
9 #include <sound/jack.h>
10 #include <linux/gpio.h>
11 #include <linux/module.h>
12 
13 #include "../codecs/wm5100.h"
14 #include "../codecs/wm9081.h"
15 
16 #define MCLK1_RATE (44100 * 512)
17 #define CLKOUT_RATE (44100 * 256)
18 
19 static struct snd_soc_jack lowland_headset;
20 
21 /* Headset jack detection DAPM pins */
22 static struct snd_soc_jack_pin lowland_headset_pins[] = {
23 	{
24 		.pin = "Headphone",
25 		.mask = SND_JACK_HEADPHONE | SND_JACK_LINEOUT,
26 	},
27 	{
28 		.pin = "Headset Mic",
29 		.mask = SND_JACK_MICROPHONE,
30 	},
31 };
32 
33 static int lowland_wm5100_init(struct snd_soc_pcm_runtime *rtd)
34 {
35 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
36 	int ret;
37 
38 	ret = snd_soc_component_set_sysclk(component, WM5100_CLK_SYSCLK,
39 				       WM5100_CLKSRC_MCLK1, MCLK1_RATE,
40 				       SND_SOC_CLOCK_IN);
41 	if (ret < 0) {
42 		pr_err("Failed to set SYSCLK clock source: %d\n", ret);
43 		return ret;
44 	}
45 
46 	/* Clock OPCLK, used by the other audio components. */
47 	ret = snd_soc_component_set_sysclk(component, WM5100_CLK_OPCLK, 0,
48 				       CLKOUT_RATE, 0);
49 	if (ret < 0) {
50 		pr_err("Failed to set OPCLK rate: %d\n", ret);
51 		return ret;
52 	}
53 
54 	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset",
55 					 SND_JACK_LINEOUT | SND_JACK_HEADSET |
56 					 SND_JACK_BTN_0,
57 					 &lowland_headset, lowland_headset_pins,
58 					 ARRAY_SIZE(lowland_headset_pins));
59 	if (ret)
60 		return ret;
61 
62 	wm5100_detect(component, &lowland_headset);
63 
64 	return 0;
65 }
66 
67 static int lowland_wm9081_init(struct snd_soc_pcm_runtime *rtd)
68 {
69 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
70 
71 	snd_soc_dapm_nc_pin(&rtd->card->dapm, "LINEOUT");
72 
73 	/* At any time the WM9081 is active it will have this clock */
74 	return snd_soc_component_set_sysclk(component, WM9081_SYSCLK_MCLK, 0,
75 					CLKOUT_RATE, 0);
76 }
77 
78 static const struct snd_soc_pcm_stream sub_params = {
79 	.formats = SNDRV_PCM_FMTBIT_S32_LE,
80 	.rate_min = 44100,
81 	.rate_max = 44100,
82 	.channels_min = 2,
83 	.channels_max = 2,
84 };
85 
86 SND_SOC_DAILINK_DEFS(cpu,
87 	DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")),
88 	DAILINK_COMP_ARRAY(COMP_CODEC("wm5100.1-001a", "wm5100-aif1")),
89 	DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0")));
90 
91 SND_SOC_DAILINK_DEFS(baseband,
92 	DAILINK_COMP_ARRAY(COMP_CPU("wm5100-aif2")),
93 	DAILINK_COMP_ARRAY(COMP_CODEC("wm1250-ev1.1-0027", "wm1250-ev1")));
94 
95 SND_SOC_DAILINK_DEFS(speaker,
96 	DAILINK_COMP_ARRAY(COMP_CPU("wm5100-aif3")),
97 	DAILINK_COMP_ARRAY(COMP_CODEC("wm9081.1-006c", "wm9081-hifi")));
98 
99 static struct snd_soc_dai_link lowland_dai[] = {
100 	{
101 		.name = "CPU",
102 		.stream_name = "CPU",
103 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
104 				SND_SOC_DAIFMT_CBM_CFM,
105 		.init = lowland_wm5100_init,
106 		SND_SOC_DAILINK_REG(cpu),
107 	},
108 	{
109 		.name = "Baseband",
110 		.stream_name = "Baseband",
111 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
112 				SND_SOC_DAIFMT_CBM_CFM,
113 		.ignore_suspend = 1,
114 		SND_SOC_DAILINK_REG(baseband),
115 	},
116 	{
117 		.name = "Sub Speaker",
118 		.stream_name = "Sub Speaker",
119 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
120 				SND_SOC_DAIFMT_CBM_CFM,
121 		.ignore_suspend = 1,
122 		.c2c_params = &sub_params,
123 		.num_c2c_params = 1,
124 		.init = lowland_wm9081_init,
125 		SND_SOC_DAILINK_REG(speaker),
126 	},
127 };
128 
129 static struct snd_soc_codec_conf lowland_codec_conf[] = {
130 	{
131 		.dlc = COMP_CODEC_CONF("wm9081.1-006c"),
132 		.name_prefix = "Sub",
133 	},
134 };
135 
136 static const struct snd_kcontrol_new controls[] = {
137 	SOC_DAPM_PIN_SWITCH("Main Speaker"),
138 	SOC_DAPM_PIN_SWITCH("Main DMIC"),
139 	SOC_DAPM_PIN_SWITCH("Main AMIC"),
140 	SOC_DAPM_PIN_SWITCH("WM1250 Input"),
141 	SOC_DAPM_PIN_SWITCH("WM1250 Output"),
142 	SOC_DAPM_PIN_SWITCH("Headphone"),
143 };
144 
145 static const struct snd_soc_dapm_widget widgets[] = {
146 	SND_SOC_DAPM_HP("Headphone", NULL),
147 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
148 
149 	SND_SOC_DAPM_SPK("Main Speaker", NULL),
150 
151 	SND_SOC_DAPM_MIC("Main AMIC", NULL),
152 	SND_SOC_DAPM_MIC("Main DMIC", NULL),
153 };
154 
155 static const struct snd_soc_dapm_route audio_paths[] = {
156 	{ "Sub IN1", NULL, "HPOUT2L" },
157 	{ "Sub IN2", NULL, "HPOUT2R" },
158 
159 	{ "Main Speaker", NULL, "Sub SPKN" },
160 	{ "Main Speaker", NULL, "Sub SPKP" },
161 	{ "Main Speaker", NULL, "SPKDAT1" },
162 };
163 
164 static struct snd_soc_card lowland = {
165 	.name = "Lowland",
166 	.owner = THIS_MODULE,
167 	.dai_link = lowland_dai,
168 	.num_links = ARRAY_SIZE(lowland_dai),
169 	.codec_conf = lowland_codec_conf,
170 	.num_configs = ARRAY_SIZE(lowland_codec_conf),
171 
172 	.controls = controls,
173 	.num_controls = ARRAY_SIZE(controls),
174 	.dapm_widgets = widgets,
175 	.num_dapm_widgets = ARRAY_SIZE(widgets),
176 	.dapm_routes = audio_paths,
177 	.num_dapm_routes = ARRAY_SIZE(audio_paths),
178 };
179 
180 static int lowland_probe(struct platform_device *pdev)
181 {
182 	struct snd_soc_card *card = &lowland;
183 	int ret;
184 
185 	card->dev = &pdev->dev;
186 
187 	ret = devm_snd_soc_register_card(&pdev->dev, card);
188 	if (ret)
189 		dev_err_probe(&pdev->dev, ret, "snd_soc_register_card() failed\n");
190 
191 	return ret;
192 }
193 
194 static struct platform_driver lowland_driver = {
195 	.driver = {
196 		.name = "lowland",
197 		.pm = &snd_soc_pm_ops,
198 	},
199 	.probe = lowland_probe,
200 };
201 
202 module_platform_driver(lowland_driver);
203 
204 MODULE_DESCRIPTION("Lowland audio support");
205 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
206 MODULE_LICENSE("GPL");
207 MODULE_ALIAS("platform:lowland");
208