Vijendar Mukunda | 23f23db | 2021-03-26 22:14:30 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: MIT |
| 2 | // |
| 3 | // Machine driver for AMD ACP Audio engine using DA7219, RT5682 & MAX98357 codec |
| 4 | // |
| 5 | //Copyright 2017-2021 Advanced Micro Devices, Inc. |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 6 | |
| 7 | #include <sound/core.h> |
| 8 | #include <sound/soc.h> |
| 9 | #include <sound/pcm.h> |
| 10 | #include <sound/pcm_params.h> |
| 11 | #include <sound/soc-dapm.h> |
| 12 | #include <sound/jack.h> |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 13 | #include <linux/clk.h> |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 14 | #include <linux/gpio.h> |
| 15 | #include <linux/module.h> |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 16 | #include <linux/regulator/machine.h> |
| 17 | #include <linux/regulator/driver.h> |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 18 | #include <linux/i2c.h> |
Agrawal, Akshu | 923859e | 2018-04-12 17:57:11 +0800 | [diff] [blame] | 19 | #include <linux/input.h> |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 20 | #include <linux/acpi.h> |
| 21 | |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 22 | #include "acp.h" |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 23 | #include "../codecs/da7219.h" |
| 24 | #include "../codecs/da7219-aad.h" |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 25 | #include "../codecs/rt5682.h" |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 26 | |
Akshu Agrawal | a1b1e98 | 2018-08-21 12:29:43 +0530 | [diff] [blame] | 27 | #define CZ_PLAT_CLK 48000000 |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 28 | #define DUAL_CHANNEL 2 |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 29 | #define RT5682_PLL_FREQ (48000 * 512) |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 30 | |
| 31 | static struct snd_soc_jack cz_jack; |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 32 | static struct clk *da7219_dai_wclk; |
| 33 | static struct clk *da7219_dai_bclk; |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 34 | static struct clk *rt5682_dai_wclk; |
| 35 | static struct clk *rt5682_dai_bclk; |
Pierre-Louis Bossart | 1984330 | 2021-09-07 13:42:14 -0500 | [diff] [blame] | 36 | |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 37 | void *acp_soc_is_rltk_max(struct device *dev); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 38 | |
| 39 | static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd) |
| 40 | { |
| 41 | int ret; |
| 42 | struct snd_soc_card *card = rtd->card; |
Kuninori Morimoto | b09b22f | 2020-03-23 14:17:13 +0900 | [diff] [blame] | 43 | struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
Kuninori Morimoto | 9a60cde | 2018-02-19 04:16:06 +0000 | [diff] [blame] | 44 | struct snd_soc_component *component = codec_dai->component; |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 45 | |
| 46 | dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name); |
| 47 | |
| 48 | ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, |
| 49 | CZ_PLAT_CLK, SND_SOC_CLOCK_IN); |
| 50 | if (ret < 0) { |
| 51 | dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret); |
| 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL, |
Akshu Agrawal | 6e55407 | 2018-05-08 10:17:51 +0530 | [diff] [blame] | 56 | CZ_PLAT_CLK, DA7219_PLL_FREQ_OUT_98304); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 57 | if (ret < 0) { |
| 58 | dev_err(rtd->dev, "can't set codec pll: %d\n", ret); |
| 59 | return ret; |
| 60 | } |
| 61 | |
Chuhong Yuan | 95d3bef | 2020-12-04 14:36:10 +0800 | [diff] [blame] | 62 | da7219_dai_wclk = devm_clk_get(component->dev, "da7219-dai-wclk"); |
| 63 | if (IS_ERR(da7219_dai_wclk)) |
| 64 | return PTR_ERR(da7219_dai_wclk); |
| 65 | |
| 66 | da7219_dai_bclk = devm_clk_get(component->dev, "da7219-dai-bclk"); |
| 67 | if (IS_ERR(da7219_dai_bclk)) |
| 68 | return PTR_ERR(da7219_dai_bclk); |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 69 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 70 | ret = snd_soc_card_jack_new(card, "Headset Jack", |
Akshu Agrawal | 2657c6a | 2018-10-15 12:24:44 +0530 | [diff] [blame] | 71 | SND_JACK_HEADSET | SND_JACK_LINEOUT | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 72 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | |
| 73 | SND_JACK_BTN_2 | SND_JACK_BTN_3, |
| 74 | &cz_jack, NULL, 0); |
| 75 | if (ret) { |
| 76 | dev_err(card->dev, "HP jack creation failed %d\n", ret); |
| 77 | return ret; |
| 78 | } |
| 79 | |
Agrawal, Akshu | 923859e | 2018-04-12 17:57:11 +0800 | [diff] [blame] | 80 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); |
| 81 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP); |
| 82 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); |
| 83 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); |
| 84 | |
Kuninori Morimoto | 9a60cde | 2018-02-19 04:16:06 +0000 | [diff] [blame] | 85 | da7219_aad_jack_det(component, &cz_jack); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
Yu-Hsuan Hsu | 756ae8f | 2019-11-26 15:54:24 +0800 | [diff] [blame] | 90 | static int da7219_clk_enable(struct snd_pcm_substream *substream) |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 91 | { |
| 92 | int ret = 0; |
Kuninori Morimoto | ded0054 | 2020-07-20 10:18:34 +0900 | [diff] [blame] | 93 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 94 | |
Yu-Hsuan Hsu | 756ae8f | 2019-11-26 15:54:24 +0800 | [diff] [blame] | 95 | /* |
| 96 | * Set wclk to 48000 because the rate constraint of this driver is |
| 97 | * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is |
| 98 | * minimum of 64x the LRCLK sample rate." DA7219 is the only clk |
| 99 | * source so for all codecs we have to limit bclk to 64X lrclk. |
| 100 | */ |
| 101 | clk_set_rate(da7219_dai_wclk, 48000); |
| 102 | clk_set_rate(da7219_dai_bclk, 48000 * 64); |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 103 | ret = clk_prepare_enable(da7219_dai_bclk); |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 104 | if (ret < 0) { |
| 105 | dev_err(rtd->dev, "can't enable master clock %d\n", ret); |
| 106 | return ret; |
| 107 | } |
| 108 | |
| 109 | return ret; |
| 110 | } |
| 111 | |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 112 | static void da7219_clk_disable(void) |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 113 | { |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 114 | clk_disable_unprepare(da7219_dai_bclk); |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 115 | } |
| 116 | |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 117 | static int cz_rt5682_init(struct snd_soc_pcm_runtime *rtd) |
| 118 | { |
| 119 | int ret; |
| 120 | struct snd_soc_card *card = rtd->card; |
| 121 | struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
| 122 | struct snd_soc_component *component = codec_dai->component; |
| 123 | |
| 124 | dev_info(codec_dai->dev, "codec dai name = %s\n", codec_dai->name); |
| 125 | |
| 126 | /* Set codec sysclk */ |
| 127 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL2, |
| 128 | RT5682_PLL_FREQ, SND_SOC_CLOCK_IN); |
| 129 | if (ret < 0) { |
| 130 | dev_err(codec_dai->dev, |
| 131 | "Failed to set rt5682 SYSCLK: %d\n", ret); |
| 132 | return ret; |
| 133 | } |
| 134 | /* set codec PLL */ |
| 135 | ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL2, RT5682_PLL2_S_MCLK, |
| 136 | CZ_PLAT_CLK, RT5682_PLL_FREQ); |
| 137 | if (ret < 0) { |
| 138 | dev_err(codec_dai->dev, "can't set rt5682 PLL: %d\n", ret); |
| 139 | return ret; |
| 140 | } |
| 141 | |
| 142 | rt5682_dai_wclk = devm_clk_get(component->dev, "rt5682-dai-wclk"); |
| 143 | if (IS_ERR(rt5682_dai_wclk)) |
| 144 | return PTR_ERR(rt5682_dai_wclk); |
| 145 | |
| 146 | rt5682_dai_bclk = devm_clk_get(component->dev, "rt5682-dai-bclk"); |
| 147 | if (IS_ERR(rt5682_dai_bclk)) |
| 148 | return PTR_ERR(rt5682_dai_bclk); |
| 149 | |
| 150 | ret = snd_soc_card_jack_new(card, "Headset Jack", |
| 151 | SND_JACK_HEADSET | SND_JACK_LINEOUT | |
| 152 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | |
| 153 | SND_JACK_BTN_2 | SND_JACK_BTN_3, |
| 154 | &cz_jack, NULL, 0); |
| 155 | if (ret) { |
| 156 | dev_err(card->dev, "HP jack creation failed %d\n", ret); |
| 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); |
| 161 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP); |
| 162 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); |
| 163 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); |
| 164 | |
| 165 | ret = snd_soc_component_set_jack(component, &cz_jack, NULL); |
| 166 | if (ret) { |
| 167 | dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret); |
| 168 | return ret; |
| 169 | } |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static int rt5682_clk_enable(struct snd_pcm_substream *substream) |
| 174 | { |
| 175 | int ret; |
| 176 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
| 177 | |
| 178 | /* |
| 179 | * Set wclk to 48000 because the rate constraint of this driver is |
| 180 | * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is |
| 181 | * minimum of 64x the LRCLK sample rate." RT5682 is the only clk |
| 182 | * source so for all codecs we have to limit bclk to 64X lrclk. |
| 183 | */ |
| 184 | ret = clk_set_rate(rt5682_dai_wclk, 48000); |
| 185 | if (ret) { |
| 186 | dev_err(rtd->dev, "Error setting wclk rate: %d\n", ret); |
| 187 | return ret; |
| 188 | } |
| 189 | ret = clk_set_rate(rt5682_dai_bclk, 48000 * 64); |
| 190 | if (ret) { |
| 191 | dev_err(rtd->dev, "Error setting bclk rate: %d\n", ret); |
| 192 | return ret; |
| 193 | } |
| 194 | ret = clk_prepare_enable(rt5682_dai_wclk); |
| 195 | if (ret < 0) { |
| 196 | dev_err(rtd->dev, "can't enable wclk %d\n", ret); |
| 197 | return ret; |
| 198 | } |
| 199 | return ret; |
| 200 | } |
| 201 | |
| 202 | static void rt5682_clk_disable(void) |
| 203 | { |
| 204 | clk_disable_unprepare(rt5682_dai_wclk); |
| 205 | } |
| 206 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 207 | static const unsigned int channels[] = { |
| 208 | DUAL_CHANNEL, |
| 209 | }; |
| 210 | |
| 211 | static const unsigned int rates[] = { |
| 212 | 48000, |
| 213 | }; |
| 214 | |
| 215 | static const struct snd_pcm_hw_constraint_list constraints_rates = { |
| 216 | .count = ARRAY_SIZE(rates), |
| 217 | .list = rates, |
| 218 | .mask = 0, |
| 219 | }; |
| 220 | |
| 221 | static const struct snd_pcm_hw_constraint_list constraints_channels = { |
| 222 | .count = ARRAY_SIZE(channels), |
| 223 | .list = channels, |
| 224 | .mask = 0, |
| 225 | }; |
| 226 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 227 | static int cz_da7219_play_startup(struct snd_pcm_substream *substream) |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 228 | { |
| 229 | struct snd_pcm_runtime *runtime = substream->runtime; |
Kuninori Morimoto | ded0054 | 2020-07-20 10:18:34 +0900 | [diff] [blame] | 230 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 231 | struct snd_soc_card *card = rtd->card; |
| 232 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 233 | |
| 234 | /* |
| 235 | * On this platform for PCM device we support stereo |
| 236 | */ |
| 237 | |
| 238 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 239 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 240 | &constraints_channels); |
| 241 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 242 | &constraints_rates); |
| 243 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 244 | machine->play_i2s_instance = I2S_SP_INSTANCE; |
Yu-Hsuan Hsu | 756ae8f | 2019-11-26 15:54:24 +0800 | [diff] [blame] | 245 | return da7219_clk_enable(substream); |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | static int cz_da7219_cap_startup(struct snd_pcm_substream *substream) |
| 249 | { |
| 250 | struct snd_pcm_runtime *runtime = substream->runtime; |
Kuninori Morimoto | ded0054 | 2020-07-20 10:18:34 +0900 | [diff] [blame] | 251 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 252 | struct snd_soc_card *card = rtd->card; |
| 253 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 254 | |
| 255 | /* |
| 256 | * On this platform for PCM device we support stereo |
| 257 | */ |
| 258 | |
| 259 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 260 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 261 | &constraints_channels); |
| 262 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 263 | &constraints_rates); |
| 264 | |
| 265 | machine->cap_i2s_instance = I2S_SP_INSTANCE; |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 266 | machine->capture_channel = CAP_CHANNEL1; |
Yu-Hsuan Hsu | 756ae8f | 2019-11-26 15:54:24 +0800 | [diff] [blame] | 267 | return da7219_clk_enable(substream); |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static int cz_max_startup(struct snd_pcm_substream *substream) |
| 271 | { |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 272 | struct snd_pcm_runtime *runtime = substream->runtime; |
Kuninori Morimoto | ded0054 | 2020-07-20 10:18:34 +0900 | [diff] [blame] | 273 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 274 | struct snd_soc_card *card = rtd->card; |
| 275 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 276 | |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 277 | /* |
| 278 | * On this platform for PCM device we support stereo |
| 279 | */ |
| 280 | |
| 281 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 282 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 283 | &constraints_channels); |
| 284 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 285 | &constraints_rates); |
| 286 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 287 | machine->play_i2s_instance = I2S_BT_INSTANCE; |
Yu-Hsuan Hsu | 756ae8f | 2019-11-26 15:54:24 +0800 | [diff] [blame] | 288 | return da7219_clk_enable(substream); |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 289 | } |
| 290 | |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 291 | static int cz_dmic0_startup(struct snd_pcm_substream *substream) |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 292 | { |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 293 | struct snd_pcm_runtime *runtime = substream->runtime; |
Kuninori Morimoto | ded0054 | 2020-07-20 10:18:34 +0900 | [diff] [blame] | 294 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 295 | struct snd_soc_card *card = rtd->card; |
| 296 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 297 | |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 298 | /* |
| 299 | * On this platform for PCM device we support stereo |
| 300 | */ |
| 301 | |
| 302 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 303 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 304 | &constraints_channels); |
| 305 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 306 | &constraints_rates); |
| 307 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 308 | machine->cap_i2s_instance = I2S_BT_INSTANCE; |
Yu-Hsuan Hsu | 756ae8f | 2019-11-26 15:54:24 +0800 | [diff] [blame] | 309 | return da7219_clk_enable(substream); |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 310 | } |
| 311 | |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 312 | static int cz_dmic1_startup(struct snd_pcm_substream *substream) |
| 313 | { |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 314 | struct snd_pcm_runtime *runtime = substream->runtime; |
Kuninori Morimoto | ded0054 | 2020-07-20 10:18:34 +0900 | [diff] [blame] | 315 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 316 | struct snd_soc_card *card = rtd->card; |
| 317 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 318 | |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 319 | /* |
| 320 | * On this platform for PCM device we support stereo |
| 321 | */ |
| 322 | |
| 323 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 324 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 325 | &constraints_channels); |
| 326 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 327 | &constraints_rates); |
| 328 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 329 | machine->cap_i2s_instance = I2S_SP_INSTANCE; |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 330 | machine->capture_channel = CAP_CHANNEL0; |
Yu-Hsuan Hsu | 756ae8f | 2019-11-26 15:54:24 +0800 | [diff] [blame] | 331 | return da7219_clk_enable(substream); |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | static void cz_da7219_shutdown(struct snd_pcm_substream *substream) |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 335 | { |
| 336 | da7219_clk_disable(); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 337 | } |
| 338 | |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 339 | static int cz_rt5682_play_startup(struct snd_pcm_substream *substream) |
| 340 | { |
| 341 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 342 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
| 343 | struct snd_soc_card *card = rtd->card; |
| 344 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 345 | |
| 346 | /* |
| 347 | * On this platform for PCM device we support stereo |
| 348 | */ |
| 349 | |
| 350 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 351 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 352 | &constraints_channels); |
| 353 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 354 | &constraints_rates); |
| 355 | |
| 356 | machine->play_i2s_instance = I2S_SP_INSTANCE; |
| 357 | return rt5682_clk_enable(substream); |
| 358 | } |
| 359 | |
| 360 | static int cz_rt5682_cap_startup(struct snd_pcm_substream *substream) |
| 361 | { |
| 362 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 363 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
| 364 | struct snd_soc_card *card = rtd->card; |
| 365 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 366 | |
| 367 | /* |
| 368 | * On this platform for PCM device we support stereo |
| 369 | */ |
| 370 | |
| 371 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 372 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 373 | &constraints_channels); |
| 374 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 375 | &constraints_rates); |
| 376 | |
| 377 | machine->cap_i2s_instance = I2S_SP_INSTANCE; |
| 378 | machine->capture_channel = CAP_CHANNEL1; |
| 379 | return rt5682_clk_enable(substream); |
| 380 | } |
| 381 | |
| 382 | static int cz_rt5682_max_startup(struct snd_pcm_substream *substream) |
| 383 | { |
| 384 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 385 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
| 386 | struct snd_soc_card *card = rtd->card; |
| 387 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 388 | |
| 389 | /* |
| 390 | * On this platform for PCM device we support stereo |
| 391 | */ |
| 392 | |
| 393 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 394 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 395 | &constraints_channels); |
| 396 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 397 | &constraints_rates); |
| 398 | |
| 399 | machine->play_i2s_instance = I2S_BT_INSTANCE; |
| 400 | return rt5682_clk_enable(substream); |
| 401 | } |
| 402 | |
| 403 | static int cz_rt5682_dmic0_startup(struct snd_pcm_substream *substream) |
| 404 | { |
| 405 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 406 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
| 407 | struct snd_soc_card *card = rtd->card; |
| 408 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 409 | |
| 410 | /* |
| 411 | * On this platform for PCM device we support stereo |
| 412 | */ |
| 413 | |
| 414 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 415 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 416 | &constraints_channels); |
| 417 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 418 | &constraints_rates); |
| 419 | |
| 420 | machine->cap_i2s_instance = I2S_BT_INSTANCE; |
| 421 | return rt5682_clk_enable(substream); |
| 422 | } |
| 423 | |
| 424 | static int cz_rt5682_dmic1_startup(struct snd_pcm_substream *substream) |
| 425 | { |
| 426 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 427 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
| 428 | struct snd_soc_card *card = rtd->card; |
| 429 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 430 | |
| 431 | /* |
| 432 | * On this platform for PCM device we support stereo |
| 433 | */ |
| 434 | |
| 435 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 436 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 437 | &constraints_channels); |
| 438 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 439 | &constraints_rates); |
| 440 | |
| 441 | machine->cap_i2s_instance = I2S_SP_INSTANCE; |
| 442 | machine->capture_channel = CAP_CHANNEL0; |
| 443 | return rt5682_clk_enable(substream); |
| 444 | } |
| 445 | |
| 446 | static void cz_rt5682_shutdown(struct snd_pcm_substream *substream) |
| 447 | { |
| 448 | rt5682_clk_disable(); |
| 449 | } |
| 450 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 451 | static const struct snd_soc_ops cz_da7219_play_ops = { |
| 452 | .startup = cz_da7219_play_startup, |
| 453 | .shutdown = cz_da7219_shutdown, |
| 454 | }; |
| 455 | |
Akshu Agrawal | 839a12c | 2018-05-08 10:17:52 +0530 | [diff] [blame] | 456 | static const struct snd_soc_ops cz_da7219_cap_ops = { |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 457 | .startup = cz_da7219_cap_startup, |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 458 | .shutdown = cz_da7219_shutdown, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 459 | }; |
| 460 | |
Akshu Agrawal | 839a12c | 2018-05-08 10:17:52 +0530 | [diff] [blame] | 461 | static const struct snd_soc_ops cz_max_play_ops = { |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 462 | .startup = cz_max_startup, |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 463 | .shutdown = cz_da7219_shutdown, |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 464 | }; |
| 465 | |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 466 | static const struct snd_soc_ops cz_dmic0_cap_ops = { |
| 467 | .startup = cz_dmic0_startup, |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 468 | .shutdown = cz_da7219_shutdown, |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 469 | }; |
| 470 | |
| 471 | static const struct snd_soc_ops cz_dmic1_cap_ops = { |
| 472 | .startup = cz_dmic1_startup, |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 473 | .shutdown = cz_da7219_shutdown, |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 474 | }; |
| 475 | |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 476 | static const struct snd_soc_ops cz_rt5682_play_ops = { |
| 477 | .startup = cz_rt5682_play_startup, |
| 478 | .shutdown = cz_rt5682_shutdown, |
| 479 | }; |
| 480 | |
| 481 | static const struct snd_soc_ops cz_rt5682_cap_ops = { |
| 482 | .startup = cz_rt5682_cap_startup, |
| 483 | .shutdown = cz_rt5682_shutdown, |
| 484 | }; |
| 485 | |
| 486 | static const struct snd_soc_ops cz_rt5682_max_play_ops = { |
| 487 | .startup = cz_rt5682_max_startup, |
| 488 | .shutdown = cz_rt5682_shutdown, |
| 489 | }; |
| 490 | |
| 491 | static const struct snd_soc_ops cz_rt5682_dmic0_cap_ops = { |
| 492 | .startup = cz_rt5682_dmic0_startup, |
| 493 | .shutdown = cz_rt5682_shutdown, |
| 494 | }; |
| 495 | |
| 496 | static const struct snd_soc_ops cz_rt5682_dmic1_cap_ops = { |
| 497 | .startup = cz_rt5682_dmic1_startup, |
| 498 | .shutdown = cz_rt5682_shutdown, |
| 499 | }; |
| 500 | |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 501 | SND_SOC_DAILINK_DEF(designware1, |
| 502 | DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.1.auto"))); |
| 503 | SND_SOC_DAILINK_DEF(designware2, |
| 504 | DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.2.auto"))); |
| 505 | SND_SOC_DAILINK_DEF(designware3, |
| 506 | DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.3.auto"))); |
| 507 | |
| 508 | SND_SOC_DAILINK_DEF(dlgs, |
| 509 | DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00", "da7219-hifi"))); |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 510 | SND_SOC_DAILINK_DEF(rt5682, |
| 511 | DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00", "rt5682-aif1"))); |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 512 | SND_SOC_DAILINK_DEF(mx, |
| 513 | DAILINK_COMP_ARRAY(COMP_CODEC("MX98357A:00", "HiFi"))); |
| 514 | SND_SOC_DAILINK_DEF(adau, |
| 515 | DAILINK_COMP_ARRAY(COMP_CODEC("ADAU7002:00", "adau7002-hifi"))); |
| 516 | |
| 517 | SND_SOC_DAILINK_DEF(platform, |
| 518 | DAILINK_COMP_ARRAY(COMP_PLATFORM("acp_audio_dma.0.auto"))); |
| 519 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 520 | static struct snd_soc_dai_link cz_dai_7219_98357[] = { |
| 521 | { |
Agrawal, Akshu | 3bec6fa | 2018-06-21 12:58:16 +0800 | [diff] [blame] | 522 | .name = "amd-da7219-play", |
| 523 | .stream_name = "Playback", |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 524 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
Mark Brown | 62df223 | 2021-09-15 19:09:57 +0100 | [diff] [blame] | 525 | | SND_SOC_DAIFMT_CBP_CFP, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 526 | .init = cz_da7219_init, |
| 527 | .dpcm_playback = 1, |
Vijendar Mukunda | 5434d0d | 2021-07-22 18:33:15 +0530 | [diff] [blame] | 528 | .stop_dma_first = 1, |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 529 | .ops = &cz_da7219_play_ops, |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 530 | SND_SOC_DAILINK_REG(designware1, dlgs, platform), |
Agrawal, Akshu | 3bec6fa | 2018-06-21 12:58:16 +0800 | [diff] [blame] | 531 | }, |
| 532 | { |
| 533 | .name = "amd-da7219-cap", |
| 534 | .stream_name = "Capture", |
Agrawal, Akshu | 3bec6fa | 2018-06-21 12:58:16 +0800 | [diff] [blame] | 535 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
Mark Brown | 62df223 | 2021-09-15 19:09:57 +0100 | [diff] [blame] | 536 | | SND_SOC_DAIFMT_CBP_CFP, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 537 | .dpcm_capture = 1, |
Vijendar Mukunda | 5434d0d | 2021-07-22 18:33:15 +0530 | [diff] [blame] | 538 | .stop_dma_first = 1, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 539 | .ops = &cz_da7219_cap_ops, |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 540 | SND_SOC_DAILINK_REG(designware2, dlgs, platform), |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 541 | }, |
| 542 | { |
| 543 | .name = "amd-max98357-play", |
| 544 | .stream_name = "HiFi Playback", |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 545 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
Mark Brown | 62df223 | 2021-09-15 19:09:57 +0100 | [diff] [blame] | 546 | | SND_SOC_DAIFMT_CBP_CFP, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 547 | .dpcm_playback = 1, |
Vijendar Mukunda | 5434d0d | 2021-07-22 18:33:15 +0530 | [diff] [blame] | 548 | .stop_dma_first = 1, |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 549 | .ops = &cz_max_play_ops, |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 550 | SND_SOC_DAILINK_REG(designware3, mx, platform), |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 551 | }, |
| 552 | { |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 553 | /* C panel DMIC */ |
| 554 | .name = "dmic0", |
| 555 | .stream_name = "DMIC0 Capture", |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 556 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
Mark Brown | 62df223 | 2021-09-15 19:09:57 +0100 | [diff] [blame] | 557 | | SND_SOC_DAIFMT_CBP_CFP, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 558 | .dpcm_capture = 1, |
Vijendar Mukunda | 5434d0d | 2021-07-22 18:33:15 +0530 | [diff] [blame] | 559 | .stop_dma_first = 1, |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 560 | .ops = &cz_dmic0_cap_ops, |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 561 | SND_SOC_DAILINK_REG(designware3, adau, platform), |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 562 | }, |
| 563 | { |
| 564 | /* A/B panel DMIC */ |
| 565 | .name = "dmic1", |
| 566 | .stream_name = "DMIC1 Capture", |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 567 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
Mark Brown | 62df223 | 2021-09-15 19:09:57 +0100 | [diff] [blame] | 568 | | SND_SOC_DAIFMT_CBP_CFP, |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 569 | .dpcm_capture = 1, |
Vijendar Mukunda | 5434d0d | 2021-07-22 18:33:15 +0530 | [diff] [blame] | 570 | .stop_dma_first = 1, |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 571 | .ops = &cz_dmic1_cap_ops, |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 572 | SND_SOC_DAILINK_REG(designware2, adau, platform), |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 573 | }, |
| 574 | }; |
| 575 | |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 576 | static struct snd_soc_dai_link cz_dai_5682_98357[] = { |
| 577 | { |
| 578 | .name = "amd-rt5682-play", |
| 579 | .stream_name = "Playback", |
| 580 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
Mark Brown | 62df223 | 2021-09-15 19:09:57 +0100 | [diff] [blame] | 581 | | SND_SOC_DAIFMT_CBP_CFP, |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 582 | .init = cz_rt5682_init, |
| 583 | .dpcm_playback = 1, |
Vijendar Mukunda | 7883490 | 2021-07-16 18:00:13 +0530 | [diff] [blame] | 584 | .stop_dma_first = 1, |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 585 | .ops = &cz_rt5682_play_ops, |
| 586 | SND_SOC_DAILINK_REG(designware1, rt5682, platform), |
| 587 | }, |
| 588 | { |
| 589 | .name = "amd-rt5682-cap", |
| 590 | .stream_name = "Capture", |
| 591 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
Mark Brown | 62df223 | 2021-09-15 19:09:57 +0100 | [diff] [blame] | 592 | | SND_SOC_DAIFMT_CBP_CFP, |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 593 | .dpcm_capture = 1, |
Vijendar Mukunda | 7883490 | 2021-07-16 18:00:13 +0530 | [diff] [blame] | 594 | .stop_dma_first = 1, |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 595 | .ops = &cz_rt5682_cap_ops, |
| 596 | SND_SOC_DAILINK_REG(designware2, rt5682, platform), |
| 597 | }, |
| 598 | { |
| 599 | .name = "amd-max98357-play", |
| 600 | .stream_name = "HiFi Playback", |
| 601 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
Mark Brown | 62df223 | 2021-09-15 19:09:57 +0100 | [diff] [blame] | 602 | | SND_SOC_DAIFMT_CBP_CFP, |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 603 | .dpcm_playback = 1, |
Vijendar Mukunda | 7883490 | 2021-07-16 18:00:13 +0530 | [diff] [blame] | 604 | .stop_dma_first = 1, |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 605 | .ops = &cz_rt5682_max_play_ops, |
| 606 | SND_SOC_DAILINK_REG(designware3, mx, platform), |
| 607 | }, |
| 608 | { |
| 609 | /* C panel DMIC */ |
| 610 | .name = "dmic0", |
| 611 | .stream_name = "DMIC0 Capture", |
| 612 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
Mark Brown | 62df223 | 2021-09-15 19:09:57 +0100 | [diff] [blame] | 613 | | SND_SOC_DAIFMT_CBP_CFP, |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 614 | .dpcm_capture = 1, |
Vijendar Mukunda | 7883490 | 2021-07-16 18:00:13 +0530 | [diff] [blame] | 615 | .stop_dma_first = 1, |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 616 | .ops = &cz_rt5682_dmic0_cap_ops, |
| 617 | SND_SOC_DAILINK_REG(designware3, adau, platform), |
| 618 | }, |
| 619 | { |
| 620 | /* A/B panel DMIC */ |
| 621 | .name = "dmic1", |
| 622 | .stream_name = "DMIC1 Capture", |
| 623 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
Mark Brown | 62df223 | 2021-09-15 19:09:57 +0100 | [diff] [blame] | 624 | | SND_SOC_DAIFMT_CBP_CFP, |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 625 | .dpcm_capture = 1, |
Vijendar Mukunda | 7883490 | 2021-07-16 18:00:13 +0530 | [diff] [blame] | 626 | .stop_dma_first = 1, |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 627 | .ops = &cz_rt5682_dmic1_cap_ops, |
| 628 | SND_SOC_DAILINK_REG(designware2, adau, platform), |
| 629 | }, |
| 630 | }; |
| 631 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 632 | static const struct snd_soc_dapm_widget cz_widgets[] = { |
| 633 | SND_SOC_DAPM_HP("Headphones", NULL), |
| 634 | SND_SOC_DAPM_SPK("Speakers", NULL), |
| 635 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 636 | SND_SOC_DAPM_MIC("Int Mic", NULL), |
| 637 | }; |
| 638 | |
| 639 | static const struct snd_soc_dapm_route cz_audio_route[] = { |
| 640 | {"Headphones", NULL, "HPL"}, |
| 641 | {"Headphones", NULL, "HPR"}, |
| 642 | {"MIC", NULL, "Headset Mic"}, |
| 643 | {"Speakers", NULL, "Speaker"}, |
| 644 | {"PDM_DAT", NULL, "Int Mic"}, |
| 645 | }; |
| 646 | |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 647 | static const struct snd_soc_dapm_route cz_rt5682_audio_route[] = { |
| 648 | {"Headphones", NULL, "HPOL"}, |
| 649 | {"Headphones", NULL, "HPOR"}, |
| 650 | {"IN1P", NULL, "Headset Mic"}, |
| 651 | {"Speakers", NULL, "Speaker"}, |
| 652 | {"PDM_DAT", NULL, "Int Mic"}, |
| 653 | }; |
| 654 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 655 | static const struct snd_kcontrol_new cz_mc_controls[] = { |
| 656 | SOC_DAPM_PIN_SWITCH("Headphones"), |
| 657 | SOC_DAPM_PIN_SWITCH("Speakers"), |
| 658 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 659 | SOC_DAPM_PIN_SWITCH("Int Mic"), |
| 660 | }; |
| 661 | |
| 662 | static struct snd_soc_card cz_card = { |
| 663 | .name = "acpd7219m98357", |
| 664 | .owner = THIS_MODULE, |
| 665 | .dai_link = cz_dai_7219_98357, |
| 666 | .num_links = ARRAY_SIZE(cz_dai_7219_98357), |
| 667 | .dapm_widgets = cz_widgets, |
| 668 | .num_dapm_widgets = ARRAY_SIZE(cz_widgets), |
| 669 | .dapm_routes = cz_audio_route, |
| 670 | .num_dapm_routes = ARRAY_SIZE(cz_audio_route), |
| 671 | .controls = cz_mc_controls, |
| 672 | .num_controls = ARRAY_SIZE(cz_mc_controls), |
| 673 | }; |
| 674 | |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 675 | static struct snd_soc_card cz_rt5682_card = { |
| 676 | .name = "acpr5682m98357", |
| 677 | .owner = THIS_MODULE, |
| 678 | .dai_link = cz_dai_5682_98357, |
| 679 | .num_links = ARRAY_SIZE(cz_dai_5682_98357), |
| 680 | .dapm_widgets = cz_widgets, |
| 681 | .num_dapm_widgets = ARRAY_SIZE(cz_widgets), |
| 682 | .dapm_routes = cz_rt5682_audio_route, |
| 683 | .controls = cz_mc_controls, |
| 684 | .num_controls = ARRAY_SIZE(cz_mc_controls), |
| 685 | }; |
| 686 | |
| 687 | void *acp_soc_is_rltk_max(struct device *dev) |
| 688 | { |
| 689 | const struct acpi_device_id *match; |
| 690 | |
| 691 | match = acpi_match_device(dev->driver->acpi_match_table, dev); |
| 692 | if (!match) |
| 693 | return NULL; |
| 694 | return (void *)match->driver_data; |
| 695 | } |
| 696 | |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 697 | static struct regulator_consumer_supply acp_da7219_supplies[] = { |
| 698 | REGULATOR_SUPPLY("VDD", "i2c-DLGS7219:00"), |
| 699 | REGULATOR_SUPPLY("VDDMIC", "i2c-DLGS7219:00"), |
| 700 | REGULATOR_SUPPLY("VDDIO", "i2c-DLGS7219:00"), |
| 701 | REGULATOR_SUPPLY("IOVDD", "ADAU7002:00"), |
| 702 | }; |
| 703 | |
| 704 | static struct regulator_init_data acp_da7219_data = { |
| 705 | .constraints = { |
| 706 | .always_on = 1, |
| 707 | }, |
| 708 | .num_consumer_supplies = ARRAY_SIZE(acp_da7219_supplies), |
| 709 | .consumer_supplies = acp_da7219_supplies, |
| 710 | }; |
| 711 | |
| 712 | static struct regulator_config acp_da7219_cfg = { |
| 713 | .init_data = &acp_da7219_data, |
| 714 | }; |
| 715 | |
| 716 | static struct regulator_ops acp_da7219_ops = { |
| 717 | }; |
| 718 | |
Julia Lawall | de36364 | 2018-10-28 06:56:08 +0100 | [diff] [blame] | 719 | static const struct regulator_desc acp_da7219_desc = { |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 720 | .name = "reg-fixed-1.8V", |
| 721 | .type = REGULATOR_VOLTAGE, |
| 722 | .owner = THIS_MODULE, |
| 723 | .ops = &acp_da7219_ops, |
| 724 | .fixed_uV = 1800000, /* 1.8V */ |
| 725 | .n_voltages = 1, |
| 726 | }; |
| 727 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 728 | static int cz_probe(struct platform_device *pdev) |
| 729 | { |
| 730 | int ret; |
| 731 | struct snd_soc_card *card; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 732 | struct acp_platform_info *machine; |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 733 | struct regulator_dev *rdev; |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 734 | struct device *dev = &pdev->dev; |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 735 | |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 736 | card = (struct snd_soc_card *)acp_soc_is_rltk_max(dev); |
| 737 | if (!card) |
| 738 | return -ENODEV; |
| 739 | if (!strcmp(card->name, "acpd7219m98357")) { |
| 740 | acp_da7219_cfg.dev = &pdev->dev; |
| 741 | rdev = devm_regulator_register(&pdev->dev, &acp_da7219_desc, |
| 742 | &acp_da7219_cfg); |
| 743 | if (IS_ERR(rdev)) { |
| 744 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", |
| 745 | (int)PTR_ERR(rdev)); |
| 746 | return -EINVAL; |
| 747 | } |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 748 | } |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 749 | |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 750 | machine = devm_kzalloc(&pdev->dev, sizeof(struct acp_platform_info), |
| 751 | GFP_KERNEL); |
| 752 | if (!machine) |
| 753 | return -ENOMEM; |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 754 | card->dev = &pdev->dev; |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 755 | platform_set_drvdata(pdev, card); |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 756 | snd_soc_card_set_drvdata(card, machine); |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 757 | ret = devm_snd_soc_register_card(&pdev->dev, card); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 758 | if (ret) { |
Mario Limonciello | 7186933 | 2021-07-22 08:27:28 -0500 | [diff] [blame] | 759 | return dev_err_probe(&pdev->dev, ret, |
| 760 | "devm_snd_soc_register_card(%s) failed\n", |
| 761 | card->name); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 762 | } |
Pierre-Louis Bossart | 1984330 | 2021-09-07 13:42:14 -0500 | [diff] [blame] | 763 | acp_bt_uart_enable = !device_property_read_bool(&pdev->dev, |
| 764 | "bt-pad-enable"); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 765 | return 0; |
| 766 | } |
| 767 | |
Pierre-Louis Bossart | dc1aff7 | 2020-07-02 11:44:28 -0500 | [diff] [blame] | 768 | #ifdef CONFIG_ACPI |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 769 | static const struct acpi_device_id cz_audio_acpi_match[] = { |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 770 | { "AMD7219", (unsigned long)&cz_card }, |
| 771 | { "AMDI5682", (unsigned long)&cz_rt5682_card}, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 772 | {}, |
| 773 | }; |
| 774 | MODULE_DEVICE_TABLE(acpi, cz_audio_acpi_match); |
Pierre-Louis Bossart | dc1aff7 | 2020-07-02 11:44:28 -0500 | [diff] [blame] | 775 | #endif |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 776 | |
| 777 | static struct platform_driver cz_pcm_driver = { |
| 778 | .driver = { |
| 779 | .name = "cz-da7219-max98357a", |
| 780 | .acpi_match_table = ACPI_PTR(cz_audio_acpi_match), |
| 781 | .pm = &snd_soc_pm_ops, |
| 782 | }, |
| 783 | .probe = cz_probe, |
| 784 | }; |
| 785 | |
| 786 | module_platform_driver(cz_pcm_driver); |
| 787 | |
| 788 | MODULE_AUTHOR("akshu.agrawal@amd.com"); |
Vijendar Mukunda | 7e71b48 | 2021-03-19 07:10:42 +0530 | [diff] [blame] | 789 | MODULE_AUTHOR("Vijendar.Mukunda@amd.com"); |
| 790 | MODULE_DESCRIPTION("DA7219, RT5682 & MAX98357A audio support"); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 791 | MODULE_LICENSE("GPL v2"); |