Sylwester Nawrocki | d5943db | 2019-04-19 12:21:44 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // Lowland audio support |
| 4 | // |
| 5 | // Copyright 2011 Wolfson Microelectronics |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 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 | |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 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 | { |
Kuninori Morimoto | 6119583 | 2018-01-29 02:59:35 +0000 | [diff] [blame] | 35 | struct snd_soc_component *component = rtd->codec_dai->component; |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 36 | int ret; |
| 37 | |
Kuninori Morimoto | 6119583 | 2018-01-29 02:59:35 +0000 | [diff] [blame] | 38 | ret = snd_soc_component_set_sysclk(component, WM5100_CLK_SYSCLK, |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 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. */ |
Kuninori Morimoto | 6119583 | 2018-01-29 02:59:35 +0000 | [diff] [blame] | 47 | ret = snd_soc_component_set_sysclk(component, WM5100_CLK_OPCLK, 0, |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 48 | CLKOUT_RATE, 0); |
| 49 | if (ret < 0) { |
| 50 | pr_err("Failed to set OPCLK rate: %d\n", ret); |
| 51 | return ret; |
| 52 | } |
| 53 | |
Lars-Peter Clausen | f97e0ea | 2015-03-04 10:33:35 +0100 | [diff] [blame] | 54 | ret = snd_soc_card_jack_new(rtd->card, "Headset", SND_JACK_LINEOUT | |
| 55 | SND_JACK_HEADSET | SND_JACK_BTN_0, |
| 56 | &lowland_headset, lowland_headset_pins, |
| 57 | ARRAY_SIZE(lowland_headset_pins)); |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 58 | if (ret) |
| 59 | return ret; |
| 60 | |
Kuninori Morimoto | 6119583 | 2018-01-29 02:59:35 +0000 | [diff] [blame] | 61 | wm5100_detect(component, &lowland_headset); |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
Mark Brown | 55b2784 | 2012-05-08 11:11:46 +0100 | [diff] [blame] | 66 | static int lowland_wm9081_init(struct snd_soc_pcm_runtime *rtd) |
| 67 | { |
Kuninori Morimoto | 6119583 | 2018-01-29 02:59:35 +0000 | [diff] [blame] | 68 | struct snd_soc_component *component = rtd->codec_dai->component; |
Mark Brown | 55b2784 | 2012-05-08 11:11:46 +0100 | [diff] [blame] | 69 | |
Lars-Peter Clausen | 239ad6a | 2015-05-03 19:27:06 +0200 | [diff] [blame] | 70 | snd_soc_dapm_nc_pin(&rtd->card->dapm, "LINEOUT"); |
Mark Brown | 55b2784 | 2012-05-08 11:11:46 +0100 | [diff] [blame] | 71 | |
| 72 | /* At any time the WM9081 is active it will have this clock */ |
Kuninori Morimoto | 6119583 | 2018-01-29 02:59:35 +0000 | [diff] [blame] | 73 | return snd_soc_component_set_sysclk(component, WM9081_SYSCLK_MCLK, 0, |
Mark Brown | 55b2784 | 2012-05-08 11:11:46 +0100 | [diff] [blame] | 74 | CLKOUT_RATE, 0); |
| 75 | } |
| 76 | |
| 77 | static const struct snd_soc_pcm_stream sub_params = { |
| 78 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
| 79 | .rate_min = 44100, |
| 80 | .rate_max = 44100, |
| 81 | .channels_min = 2, |
| 82 | .channels_max = 2, |
| 83 | }; |
| 84 | |
Kuninori Morimoto | 7989919 | 2019-06-06 13:10:36 +0900 | [diff] [blame] | 85 | SND_SOC_DAILINK_DEFS(cpu, |
| 86 | DAILINK_COMP_ARRAY(COMP_CPU("samsung-i2s.0")), |
| 87 | DAILINK_COMP_ARRAY(COMP_CODEC("wm5100.1-001a", "wm5100-aif1")), |
| 88 | DAILINK_COMP_ARRAY(COMP_PLATFORM("samsung-i2s.0"))); |
| 89 | |
| 90 | SND_SOC_DAILINK_DEFS(baseband, |
| 91 | DAILINK_COMP_ARRAY(COMP_CPU("wm5100-aif2")), |
| 92 | DAILINK_COMP_ARRAY(COMP_CODEC("wm1250-ev1.1-0027", "wm1250-ev1"))); |
| 93 | |
| 94 | SND_SOC_DAILINK_DEFS(speaker, |
| 95 | DAILINK_COMP_ARRAY(COMP_CPU("wm5100-aif3")), |
| 96 | DAILINK_COMP_ARRAY(COMP_CODEC("wm9081.1-006c", "wm9081-hifi"))); |
| 97 | |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 98 | static struct snd_soc_dai_link lowland_dai[] = { |
| 99 | { |
| 100 | .name = "CPU", |
| 101 | .stream_name = "CPU", |
Mark Brown | 277b6fd | 2012-05-08 09:49:45 +0100 | [diff] [blame] | 102 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 103 | SND_SOC_DAIFMT_CBM_CFM, |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 104 | .init = lowland_wm5100_init, |
Kuninori Morimoto | 7989919 | 2019-06-06 13:10:36 +0900 | [diff] [blame] | 105 | SND_SOC_DAILINK_REG(cpu), |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 106 | }, |
| 107 | { |
| 108 | .name = "Baseband", |
| 109 | .stream_name = "Baseband", |
Mark Brown | 277b6fd | 2012-05-08 09:49:45 +0100 | [diff] [blame] | 110 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 111 | SND_SOC_DAIFMT_CBM_CFM, |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 112 | .ignore_suspend = 1, |
Kuninori Morimoto | 7989919 | 2019-06-06 13:10:36 +0900 | [diff] [blame] | 113 | SND_SOC_DAILINK_REG(baseband), |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 114 | }, |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 115 | { |
Mark Brown | 55b2784 | 2012-05-08 11:11:46 +0100 | [diff] [blame] | 116 | .name = "Sub Speaker", |
| 117 | .stream_name = "Sub Speaker", |
Mark Brown | 55b2784 | 2012-05-08 11:11:46 +0100 | [diff] [blame] | 118 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 119 | SND_SOC_DAIFMT_CBM_CFM, |
| 120 | .ignore_suspend = 1, |
| 121 | .params = &sub_params, |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 122 | .init = lowland_wm9081_init, |
Kuninori Morimoto | 7989919 | 2019-06-06 13:10:36 +0900 | [diff] [blame] | 123 | SND_SOC_DAILINK_REG(speaker), |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 124 | }, |
| 125 | }; |
| 126 | |
| 127 | static struct snd_soc_codec_conf lowland_codec_conf[] = { |
| 128 | { |
| 129 | .dev_name = "wm9081.1-006c", |
| 130 | .name_prefix = "Sub", |
| 131 | }, |
| 132 | }; |
| 133 | |
| 134 | static const struct snd_kcontrol_new controls[] = { |
| 135 | SOC_DAPM_PIN_SWITCH("Main Speaker"), |
| 136 | SOC_DAPM_PIN_SWITCH("Main DMIC"), |
| 137 | SOC_DAPM_PIN_SWITCH("Main AMIC"), |
| 138 | SOC_DAPM_PIN_SWITCH("WM1250 Input"), |
| 139 | SOC_DAPM_PIN_SWITCH("WM1250 Output"), |
| 140 | SOC_DAPM_PIN_SWITCH("Headphone"), |
| 141 | }; |
| 142 | |
| 143 | static struct snd_soc_dapm_widget widgets[] = { |
| 144 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 145 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 146 | |
| 147 | SND_SOC_DAPM_SPK("Main Speaker", NULL), |
| 148 | |
| 149 | SND_SOC_DAPM_MIC("Main AMIC", NULL), |
| 150 | SND_SOC_DAPM_MIC("Main DMIC", NULL), |
| 151 | }; |
| 152 | |
| 153 | static struct snd_soc_dapm_route audio_paths[] = { |
| 154 | { "Sub IN1", NULL, "HPOUT2L" }, |
| 155 | { "Sub IN2", NULL, "HPOUT2R" }, |
| 156 | |
| 157 | { "Main Speaker", NULL, "Sub SPKN" }, |
| 158 | { "Main Speaker", NULL, "Sub SPKP" }, |
| 159 | { "Main Speaker", NULL, "SPKDAT1" }, |
| 160 | }; |
| 161 | |
| 162 | static struct snd_soc_card lowland = { |
| 163 | .name = "Lowland", |
Axel Lin | 095d79d | 2011-12-22 10:53:15 +0800 | [diff] [blame] | 164 | .owner = THIS_MODULE, |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 165 | .dai_link = lowland_dai, |
| 166 | .num_links = ARRAY_SIZE(lowland_dai), |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 167 | .codec_conf = lowland_codec_conf, |
| 168 | .num_configs = ARRAY_SIZE(lowland_codec_conf), |
| 169 | |
| 170 | .controls = controls, |
| 171 | .num_controls = ARRAY_SIZE(controls), |
| 172 | .dapm_widgets = widgets, |
| 173 | .num_dapm_widgets = ARRAY_SIZE(widgets), |
| 174 | .dapm_routes = audio_paths, |
| 175 | .num_dapm_routes = ARRAY_SIZE(audio_paths), |
| 176 | }; |
| 177 | |
Bill Pemberton | fdca21a | 2012-12-07 09:26:15 -0500 | [diff] [blame] | 178 | static int lowland_probe(struct platform_device *pdev) |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 179 | { |
| 180 | struct snd_soc_card *card = &lowland; |
| 181 | int ret; |
| 182 | |
| 183 | card->dev = &pdev->dev; |
| 184 | |
Tushar Behera | c583883 | 2014-05-21 08:52:17 +0530 | [diff] [blame] | 185 | ret = devm_snd_soc_register_card(&pdev->dev, card); |
| 186 | if (ret) |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 187 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
| 188 | ret); |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 189 | |
Tushar Behera | c583883 | 2014-05-21 08:52:17 +0530 | [diff] [blame] | 190 | return ret; |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static struct platform_driver lowland_driver = { |
| 194 | .driver = { |
| 195 | .name = "lowland", |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 196 | .pm = &snd_soc_pm_ops, |
| 197 | }, |
| 198 | .probe = lowland_probe, |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 199 | }; |
| 200 | |
Mark Brown | e00c3f5 | 2011-11-23 15:20:13 +0000 | [diff] [blame] | 201 | module_platform_driver(lowland_driver); |
Mark Brown | abda5df | 2011-08-23 17:40:01 +0100 | [diff] [blame] | 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"); |