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