xref: /openbmc/linux/sound/soc/samsung/lowland.c (revision d5943db34af3825b73690724f10fe2bc95cc8dc2)
1*d5943db3SSylwester Nawrocki // SPDX-License-Identifier: GPL-2.0+
2*d5943db3SSylwester Nawrocki //
3*d5943db3SSylwester Nawrocki // Lowland audio support
4*d5943db3SSylwester Nawrocki //
5*d5943db3SSylwester Nawrocki // Copyright 2011 Wolfson Microelectronics
6abda5dfdSMark Brown 
7abda5dfdSMark Brown #include <sound/soc.h>
8abda5dfdSMark Brown #include <sound/soc-dapm.h>
9abda5dfdSMark Brown #include <sound/jack.h>
10abda5dfdSMark Brown #include <linux/gpio.h>
11abda5dfdSMark Brown #include <linux/module.h>
12abda5dfdSMark Brown 
13abda5dfdSMark Brown #include "../codecs/wm5100.h"
14abda5dfdSMark Brown #include "../codecs/wm9081.h"
15abda5dfdSMark Brown 
16abda5dfdSMark Brown #define MCLK1_RATE (44100 * 512)
17abda5dfdSMark Brown #define CLKOUT_RATE (44100 * 256)
18abda5dfdSMark Brown 
19abda5dfdSMark Brown static struct snd_soc_jack lowland_headset;
20abda5dfdSMark Brown 
21abda5dfdSMark Brown /* Headset jack detection DAPM pins */
22abda5dfdSMark Brown static struct snd_soc_jack_pin lowland_headset_pins[] = {
23abda5dfdSMark Brown 	{
24abda5dfdSMark Brown 		.pin = "Headphone",
25abda5dfdSMark Brown 		.mask = SND_JACK_HEADPHONE | SND_JACK_LINEOUT,
26abda5dfdSMark Brown 	},
27abda5dfdSMark Brown 	{
28abda5dfdSMark Brown 		.pin = "Headset Mic",
29abda5dfdSMark Brown 		.mask = SND_JACK_MICROPHONE,
30abda5dfdSMark Brown 	},
31abda5dfdSMark Brown };
32abda5dfdSMark Brown 
33abda5dfdSMark Brown static int lowland_wm5100_init(struct snd_soc_pcm_runtime *rtd)
34abda5dfdSMark Brown {
3561195838SKuninori Morimoto 	struct snd_soc_component *component = rtd->codec_dai->component;
36abda5dfdSMark Brown 	int ret;
37abda5dfdSMark Brown 
3861195838SKuninori Morimoto 	ret = snd_soc_component_set_sysclk(component, WM5100_CLK_SYSCLK,
39abda5dfdSMark Brown 				       WM5100_CLKSRC_MCLK1, MCLK1_RATE,
40abda5dfdSMark Brown 				       SND_SOC_CLOCK_IN);
41abda5dfdSMark Brown 	if (ret < 0) {
42abda5dfdSMark Brown 		pr_err("Failed to set SYSCLK clock source: %d\n", ret);
43abda5dfdSMark Brown 		return ret;
44abda5dfdSMark Brown 	}
45abda5dfdSMark Brown 
46abda5dfdSMark Brown 	/* Clock OPCLK, used by the other audio components. */
4761195838SKuninori Morimoto 	ret = snd_soc_component_set_sysclk(component, WM5100_CLK_OPCLK, 0,
48abda5dfdSMark Brown 				       CLKOUT_RATE, 0);
49abda5dfdSMark Brown 	if (ret < 0) {
50abda5dfdSMark Brown 		pr_err("Failed to set OPCLK rate: %d\n", ret);
51abda5dfdSMark Brown 		return ret;
52abda5dfdSMark Brown 	}
53abda5dfdSMark Brown 
54f97e0eacSLars-Peter Clausen 	ret = snd_soc_card_jack_new(rtd->card, "Headset", SND_JACK_LINEOUT |
55f97e0eacSLars-Peter Clausen 				    SND_JACK_HEADSET | SND_JACK_BTN_0,
56f97e0eacSLars-Peter Clausen 				    &lowland_headset, lowland_headset_pins,
57f97e0eacSLars-Peter Clausen 				    ARRAY_SIZE(lowland_headset_pins));
58abda5dfdSMark Brown 	if (ret)
59abda5dfdSMark Brown 		return ret;
60abda5dfdSMark Brown 
6161195838SKuninori Morimoto 	wm5100_detect(component, &lowland_headset);
62abda5dfdSMark Brown 
63abda5dfdSMark Brown 	return 0;
64abda5dfdSMark Brown }
65abda5dfdSMark Brown 
6655b27847SMark Brown static int lowland_wm9081_init(struct snd_soc_pcm_runtime *rtd)
6755b27847SMark Brown {
6861195838SKuninori Morimoto 	struct snd_soc_component *component = rtd->codec_dai->component;
6955b27847SMark Brown 
70239ad6a1SLars-Peter Clausen 	snd_soc_dapm_nc_pin(&rtd->card->dapm, "LINEOUT");
7155b27847SMark Brown 
7255b27847SMark Brown 	/* At any time the WM9081 is active it will have this clock */
7361195838SKuninori Morimoto 	return snd_soc_component_set_sysclk(component, WM9081_SYSCLK_MCLK, 0,
7455b27847SMark Brown 					CLKOUT_RATE, 0);
7555b27847SMark Brown }
7655b27847SMark Brown 
7755b27847SMark Brown static const struct snd_soc_pcm_stream sub_params = {
7855b27847SMark Brown 	.formats = SNDRV_PCM_FMTBIT_S32_LE,
7955b27847SMark Brown 	.rate_min = 44100,
8055b27847SMark Brown 	.rate_max = 44100,
8155b27847SMark Brown 	.channels_min = 2,
8255b27847SMark Brown 	.channels_max = 2,
8355b27847SMark Brown };
8455b27847SMark Brown 
85abda5dfdSMark Brown static struct snd_soc_dai_link lowland_dai[] = {
86abda5dfdSMark Brown 	{
87abda5dfdSMark Brown 		.name = "CPU",
88abda5dfdSMark Brown 		.stream_name = "CPU",
89abda5dfdSMark Brown 		.cpu_dai_name = "samsung-i2s.0",
90abda5dfdSMark Brown 		.codec_dai_name = "wm5100-aif1",
91a08485d8SPadmavathi Venna 		.platform_name = "samsung-i2s.0",
92abda5dfdSMark Brown 		.codec_name = "wm5100.1-001a",
93277b6fdaSMark Brown 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
94277b6fdaSMark Brown 				SND_SOC_DAIFMT_CBM_CFM,
95abda5dfdSMark Brown 		.init = lowland_wm5100_init,
96abda5dfdSMark Brown 	},
97abda5dfdSMark Brown 	{
98abda5dfdSMark Brown 		.name = "Baseband",
99abda5dfdSMark Brown 		.stream_name = "Baseband",
100abda5dfdSMark Brown 		.cpu_dai_name = "wm5100-aif2",
101abda5dfdSMark Brown 		.codec_dai_name = "wm1250-ev1",
102abda5dfdSMark Brown 		.codec_name = "wm1250-ev1.1-0027",
103277b6fdaSMark Brown 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
104277b6fdaSMark Brown 				SND_SOC_DAIFMT_CBM_CFM,
105abda5dfdSMark Brown 		.ignore_suspend = 1,
106abda5dfdSMark Brown 	},
107abda5dfdSMark Brown 	{
10855b27847SMark Brown 		.name = "Sub Speaker",
10955b27847SMark Brown 		.stream_name = "Sub Speaker",
11055b27847SMark Brown 		.cpu_dai_name = "wm5100-aif3",
11155b27847SMark Brown 		.codec_dai_name = "wm9081-hifi",
112abda5dfdSMark Brown 		.codec_name = "wm9081.1-006c",
11355b27847SMark Brown 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
11455b27847SMark Brown 				SND_SOC_DAIFMT_CBM_CFM,
11555b27847SMark Brown 		.ignore_suspend = 1,
11655b27847SMark Brown 		.params = &sub_params,
117abda5dfdSMark Brown 		.init = lowland_wm9081_init,
118abda5dfdSMark Brown 	},
119abda5dfdSMark Brown };
120abda5dfdSMark Brown 
121abda5dfdSMark Brown static struct snd_soc_codec_conf lowland_codec_conf[] = {
122abda5dfdSMark Brown 	{
123abda5dfdSMark Brown 		.dev_name = "wm9081.1-006c",
124abda5dfdSMark Brown 		.name_prefix = "Sub",
125abda5dfdSMark Brown 	},
126abda5dfdSMark Brown };
127abda5dfdSMark Brown 
128abda5dfdSMark Brown static const struct snd_kcontrol_new controls[] = {
129abda5dfdSMark Brown 	SOC_DAPM_PIN_SWITCH("Main Speaker"),
130abda5dfdSMark Brown 	SOC_DAPM_PIN_SWITCH("Main DMIC"),
131abda5dfdSMark Brown 	SOC_DAPM_PIN_SWITCH("Main AMIC"),
132abda5dfdSMark Brown 	SOC_DAPM_PIN_SWITCH("WM1250 Input"),
133abda5dfdSMark Brown 	SOC_DAPM_PIN_SWITCH("WM1250 Output"),
134abda5dfdSMark Brown 	SOC_DAPM_PIN_SWITCH("Headphone"),
135abda5dfdSMark Brown };
136abda5dfdSMark Brown 
137abda5dfdSMark Brown static struct snd_soc_dapm_widget widgets[] = {
138abda5dfdSMark Brown 	SND_SOC_DAPM_HP("Headphone", NULL),
139abda5dfdSMark Brown 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
140abda5dfdSMark Brown 
141abda5dfdSMark Brown 	SND_SOC_DAPM_SPK("Main Speaker", NULL),
142abda5dfdSMark Brown 
143abda5dfdSMark Brown 	SND_SOC_DAPM_MIC("Main AMIC", NULL),
144abda5dfdSMark Brown 	SND_SOC_DAPM_MIC("Main DMIC", NULL),
145abda5dfdSMark Brown };
146abda5dfdSMark Brown 
147abda5dfdSMark Brown static struct snd_soc_dapm_route audio_paths[] = {
148abda5dfdSMark Brown 	{ "Sub IN1", NULL, "HPOUT2L" },
149abda5dfdSMark Brown 	{ "Sub IN2", NULL, "HPOUT2R" },
150abda5dfdSMark Brown 
151abda5dfdSMark Brown 	{ "Main Speaker", NULL, "Sub SPKN" },
152abda5dfdSMark Brown 	{ "Main Speaker", NULL, "Sub SPKP" },
153abda5dfdSMark Brown 	{ "Main Speaker", NULL, "SPKDAT1" },
154abda5dfdSMark Brown };
155abda5dfdSMark Brown 
156abda5dfdSMark Brown static struct snd_soc_card lowland = {
157abda5dfdSMark Brown 	.name = "Lowland",
158095d79dcSAxel Lin 	.owner = THIS_MODULE,
159abda5dfdSMark Brown 	.dai_link = lowland_dai,
160abda5dfdSMark Brown 	.num_links = ARRAY_SIZE(lowland_dai),
161abda5dfdSMark Brown 	.codec_conf = lowland_codec_conf,
162abda5dfdSMark Brown 	.num_configs = ARRAY_SIZE(lowland_codec_conf),
163abda5dfdSMark Brown 
164abda5dfdSMark Brown 	.controls = controls,
165abda5dfdSMark Brown 	.num_controls = ARRAY_SIZE(controls),
166abda5dfdSMark Brown 	.dapm_widgets = widgets,
167abda5dfdSMark Brown 	.num_dapm_widgets = ARRAY_SIZE(widgets),
168abda5dfdSMark Brown 	.dapm_routes = audio_paths,
169abda5dfdSMark Brown 	.num_dapm_routes = ARRAY_SIZE(audio_paths),
170abda5dfdSMark Brown };
171abda5dfdSMark Brown 
172fdca21adSBill Pemberton static int lowland_probe(struct platform_device *pdev)
173abda5dfdSMark Brown {
174abda5dfdSMark Brown 	struct snd_soc_card *card = &lowland;
175abda5dfdSMark Brown 	int ret;
176abda5dfdSMark Brown 
177abda5dfdSMark Brown 	card->dev = &pdev->dev;
178abda5dfdSMark Brown 
179c583883eSTushar Behera 	ret = devm_snd_soc_register_card(&pdev->dev, card);
180c583883eSTushar Behera 	if (ret)
181abda5dfdSMark Brown 		dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
182abda5dfdSMark Brown 			ret);
183c583883eSTushar Behera 
184abda5dfdSMark Brown 	return ret;
185abda5dfdSMark Brown }
186abda5dfdSMark Brown 
187abda5dfdSMark Brown static struct platform_driver lowland_driver = {
188abda5dfdSMark Brown 	.driver = {
189abda5dfdSMark Brown 		.name = "lowland",
190abda5dfdSMark Brown 		.pm = &snd_soc_pm_ops,
191abda5dfdSMark Brown 	},
192abda5dfdSMark Brown 	.probe = lowland_probe,
193abda5dfdSMark Brown };
194abda5dfdSMark Brown 
195e00c3f55SMark Brown module_platform_driver(lowland_driver);
196abda5dfdSMark Brown 
197abda5dfdSMark Brown MODULE_DESCRIPTION("Lowland audio support");
198abda5dfdSMark Brown MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
199abda5dfdSMark Brown MODULE_LICENSE("GPL");
200abda5dfdSMark Brown MODULE_ALIAS("platform:lowland");
201