GNU Linux-libre 6.1.91-gnu
[releases.git] / sound / soc / samsung / lowland.c
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                 .params = &sub_params,
123                 .init = lowland_wm9081_init,
124                 SND_SOC_DAILINK_REG(speaker),
125         },
126 };
127
128 static struct snd_soc_codec_conf lowland_codec_conf[] = {
129         {
130                 .dlc = COMP_CODEC_CONF("wm9081.1-006c"),
131                 .name_prefix = "Sub",
132         },
133 };
134
135 static const struct snd_kcontrol_new controls[] = {
136         SOC_DAPM_PIN_SWITCH("Main Speaker"),
137         SOC_DAPM_PIN_SWITCH("Main DMIC"),
138         SOC_DAPM_PIN_SWITCH("Main AMIC"),
139         SOC_DAPM_PIN_SWITCH("WM1250 Input"),
140         SOC_DAPM_PIN_SWITCH("WM1250 Output"),
141         SOC_DAPM_PIN_SWITCH("Headphone"),
142 };
143
144 static const struct snd_soc_dapm_widget widgets[] = {
145         SND_SOC_DAPM_HP("Headphone", NULL),
146         SND_SOC_DAPM_MIC("Headset Mic", NULL),
147
148         SND_SOC_DAPM_SPK("Main Speaker", NULL),
149
150         SND_SOC_DAPM_MIC("Main AMIC", NULL),
151         SND_SOC_DAPM_MIC("Main DMIC", NULL),
152 };
153
154 static const struct snd_soc_dapm_route audio_paths[] = {
155         { "Sub IN1", NULL, "HPOUT2L" },
156         { "Sub IN2", NULL, "HPOUT2R" },
157
158         { "Main Speaker", NULL, "Sub SPKN" },
159         { "Main Speaker", NULL, "Sub SPKP" },
160         { "Main Speaker", NULL, "SPKDAT1" },
161 };
162
163 static struct snd_soc_card lowland = {
164         .name = "Lowland",
165         .owner = THIS_MODULE,
166         .dai_link = lowland_dai,
167         .num_links = ARRAY_SIZE(lowland_dai),
168         .codec_conf = lowland_codec_conf,
169         .num_configs = ARRAY_SIZE(lowland_codec_conf),
170
171         .controls = controls,
172         .num_controls = ARRAY_SIZE(controls),
173         .dapm_widgets = widgets,
174         .num_dapm_widgets = ARRAY_SIZE(widgets),
175         .dapm_routes = audio_paths,
176         .num_dapm_routes = ARRAY_SIZE(audio_paths),
177 };
178
179 static int lowland_probe(struct platform_device *pdev)
180 {
181         struct snd_soc_card *card = &lowland;
182         int ret;
183
184         card->dev = &pdev->dev;
185
186         ret = devm_snd_soc_register_card(&pdev->dev, card);
187         if (ret)
188                 dev_err_probe(&pdev->dev, ret, "snd_soc_register_card() failed\n");
189
190         return ret;
191 }
192
193 static struct platform_driver lowland_driver = {
194         .driver = {
195                 .name = "lowland",
196                 .pm = &snd_soc_pm_ops,
197         },
198         .probe = lowland_probe,
199 };
200
201 module_platform_driver(lowland_driver);
202
203 MODULE_DESCRIPTION("Lowland audio support");
204 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
205 MODULE_LICENSE("GPL");
206 MODULE_ALIAS("platform:lowland");