Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Machine driver for AMD ACP Audio engine using DA7219 & MAX98357 codec |
| 3 | * |
| 4 | * Copyright 2017 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <sound/core.h> |
| 27 | #include <sound/soc.h> |
| 28 | #include <sound/pcm.h> |
| 29 | #include <sound/pcm_params.h> |
| 30 | #include <sound/soc-dapm.h> |
| 31 | #include <sound/jack.h> |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 32 | #include <linux/clk.h> |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 33 | #include <linux/gpio.h> |
| 34 | #include <linux/module.h> |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 35 | #include <linux/regulator/machine.h> |
| 36 | #include <linux/regulator/driver.h> |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 37 | #include <linux/i2c.h> |
Agrawal, Akshu | 923859e | 2018-04-12 17:57:11 +0800 | [diff] [blame] | 38 | #include <linux/input.h> |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 39 | #include <linux/acpi.h> |
| 40 | |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 41 | #include "acp.h" |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 42 | #include "../codecs/da7219.h" |
| 43 | #include "../codecs/da7219-aad.h" |
| 44 | |
Akshu Agrawal | a1b1e98 | 2018-08-21 12:29:43 +0530 | [diff] [blame] | 45 | #define CZ_PLAT_CLK 48000000 |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 46 | #define DUAL_CHANNEL 2 |
| 47 | |
| 48 | static struct snd_soc_jack cz_jack; |
Wei Yongjun | ede1d35 | 2018-03-29 02:14:03 +0000 | [diff] [blame] | 49 | static struct clk *da7219_dai_clk; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 50 | extern int bt_uart_enable; |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 51 | |
| 52 | static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd) |
| 53 | { |
| 54 | int ret; |
| 55 | struct snd_soc_card *card = rtd->card; |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 56 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Kuninori Morimoto | 9a60cde | 2018-02-19 04:16:06 +0000 | [diff] [blame] | 57 | struct snd_soc_component *component = codec_dai->component; |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 58 | |
| 59 | dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name); |
| 60 | |
| 61 | ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, |
| 62 | CZ_PLAT_CLK, SND_SOC_CLOCK_IN); |
| 63 | if (ret < 0) { |
| 64 | dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret); |
| 65 | return ret; |
| 66 | } |
| 67 | |
| 68 | ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL, |
Akshu Agrawal | 6e55407 | 2018-05-08 10:17:51 +0530 | [diff] [blame] | 69 | CZ_PLAT_CLK, DA7219_PLL_FREQ_OUT_98304); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 70 | if (ret < 0) { |
| 71 | dev_err(rtd->dev, "can't set codec pll: %d\n", ret); |
| 72 | return ret; |
| 73 | } |
| 74 | |
Kuninori Morimoto | 4c50e1e | 2018-03-28 01:48:07 +0000 | [diff] [blame] | 75 | da7219_dai_clk = clk_get(component->dev, "da7219-dai-clks"); |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 76 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 77 | ret = snd_soc_card_jack_new(card, "Headset Jack", |
Akshu Agrawal | 2657c6a | 2018-10-15 12:24:44 +0530 | [diff] [blame] | 78 | SND_JACK_HEADSET | SND_JACK_LINEOUT | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 79 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | |
| 80 | SND_JACK_BTN_2 | SND_JACK_BTN_3, |
| 81 | &cz_jack, NULL, 0); |
| 82 | if (ret) { |
| 83 | dev_err(card->dev, "HP jack creation failed %d\n", ret); |
| 84 | return ret; |
| 85 | } |
| 86 | |
Agrawal, Akshu | 923859e | 2018-04-12 17:57:11 +0800 | [diff] [blame] | 87 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); |
| 88 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP); |
| 89 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); |
| 90 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); |
| 91 | |
Kuninori Morimoto | 9a60cde | 2018-02-19 04:16:06 +0000 | [diff] [blame] | 92 | da7219_aad_jack_det(component, &cz_jack); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 97 | static int da7219_clk_enable(struct snd_pcm_substream *substream) |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 98 | { |
| 99 | int ret = 0; |
| 100 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 101 | |
| 102 | ret = clk_prepare_enable(da7219_dai_clk); |
| 103 | if (ret < 0) { |
| 104 | dev_err(rtd->dev, "can't enable master clock %d\n", ret); |
| 105 | return ret; |
| 106 | } |
| 107 | |
| 108 | return ret; |
| 109 | } |
| 110 | |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 111 | static void da7219_clk_disable(void) |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 112 | { |
| 113 | clk_disable_unprepare(da7219_dai_clk); |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 114 | } |
| 115 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 116 | static const unsigned int channels[] = { |
| 117 | DUAL_CHANNEL, |
| 118 | }; |
| 119 | |
| 120 | static const unsigned int rates[] = { |
| 121 | 48000, |
| 122 | }; |
| 123 | |
| 124 | static const struct snd_pcm_hw_constraint_list constraints_rates = { |
| 125 | .count = ARRAY_SIZE(rates), |
| 126 | .list = rates, |
| 127 | .mask = 0, |
| 128 | }; |
| 129 | |
| 130 | static const struct snd_pcm_hw_constraint_list constraints_channels = { |
| 131 | .count = ARRAY_SIZE(channels), |
| 132 | .list = channels, |
| 133 | .mask = 0, |
| 134 | }; |
| 135 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 136 | static int cz_da7219_play_startup(struct snd_pcm_substream *substream) |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 137 | { |
| 138 | struct snd_pcm_runtime *runtime = substream->runtime; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 139 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 140 | struct snd_soc_card *card = rtd->card; |
| 141 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 142 | |
| 143 | /* |
| 144 | * On this platform for PCM device we support stereo |
| 145 | */ |
| 146 | |
| 147 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 148 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 149 | &constraints_channels); |
| 150 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 151 | &constraints_rates); |
| 152 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 153 | machine->play_i2s_instance = I2S_SP_INSTANCE; |
| 154 | return da7219_clk_enable(substream); |
| 155 | } |
| 156 | |
| 157 | static int cz_da7219_cap_startup(struct snd_pcm_substream *substream) |
| 158 | { |
| 159 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 160 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 161 | struct snd_soc_card *card = rtd->card; |
| 162 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 163 | |
| 164 | /* |
| 165 | * On this platform for PCM device we support stereo |
| 166 | */ |
| 167 | |
| 168 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 169 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 170 | &constraints_channels); |
| 171 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 172 | &constraints_rates); |
| 173 | |
| 174 | machine->cap_i2s_instance = I2S_SP_INSTANCE; |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 175 | machine->capture_channel = CAP_CHANNEL1; |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 176 | return da7219_clk_enable(substream); |
| 177 | } |
| 178 | |
| 179 | static void cz_da7219_shutdown(struct snd_pcm_substream *substream) |
| 180 | { |
| 181 | da7219_clk_disable(); |
| 182 | } |
| 183 | |
| 184 | static int cz_max_startup(struct snd_pcm_substream *substream) |
| 185 | { |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 186 | struct snd_pcm_runtime *runtime = substream->runtime; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 187 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 188 | struct snd_soc_card *card = rtd->card; |
| 189 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 190 | |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 191 | /* |
| 192 | * On this platform for PCM device we support stereo |
| 193 | */ |
| 194 | |
| 195 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 196 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 197 | &constraints_channels); |
| 198 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 199 | &constraints_rates); |
| 200 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 201 | machine->play_i2s_instance = I2S_BT_INSTANCE; |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 202 | return da7219_clk_enable(substream); |
| 203 | } |
| 204 | |
| 205 | static void cz_max_shutdown(struct snd_pcm_substream *substream) |
| 206 | { |
| 207 | da7219_clk_disable(); |
| 208 | } |
| 209 | |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 210 | static int cz_dmic0_startup(struct snd_pcm_substream *substream) |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 211 | { |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 212 | struct snd_pcm_runtime *runtime = substream->runtime; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 213 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 214 | struct snd_soc_card *card = rtd->card; |
| 215 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 216 | |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 217 | /* |
| 218 | * On this platform for PCM device we support stereo |
| 219 | */ |
| 220 | |
| 221 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 222 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 223 | &constraints_channels); |
| 224 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 225 | &constraints_rates); |
| 226 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 227 | machine->cap_i2s_instance = I2S_BT_INSTANCE; |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 228 | return da7219_clk_enable(substream); |
| 229 | } |
| 230 | |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 231 | static int cz_dmic1_startup(struct snd_pcm_substream *substream) |
| 232 | { |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 233 | struct snd_pcm_runtime *runtime = substream->runtime; |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 234 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 235 | struct snd_soc_card *card = rtd->card; |
| 236 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 237 | |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 238 | /* |
| 239 | * On this platform for PCM device we support stereo |
| 240 | */ |
| 241 | |
| 242 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 243 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 244 | &constraints_channels); |
| 245 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 246 | &constraints_rates); |
| 247 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 248 | machine->cap_i2s_instance = I2S_SP_INSTANCE; |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 249 | machine->capture_channel = CAP_CHANNEL0; |
| 250 | return da7219_clk_enable(substream); |
| 251 | } |
| 252 | |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 253 | static void cz_dmic_shutdown(struct snd_pcm_substream *substream) |
| 254 | { |
| 255 | da7219_clk_disable(); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 256 | } |
| 257 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 258 | static const struct snd_soc_ops cz_da7219_play_ops = { |
| 259 | .startup = cz_da7219_play_startup, |
| 260 | .shutdown = cz_da7219_shutdown, |
| 261 | }; |
| 262 | |
Akshu Agrawal | 839a12c | 2018-05-08 10:17:52 +0530 | [diff] [blame] | 263 | static const struct snd_soc_ops cz_da7219_cap_ops = { |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 264 | .startup = cz_da7219_cap_startup, |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 265 | .shutdown = cz_da7219_shutdown, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 266 | }; |
| 267 | |
Akshu Agrawal | 839a12c | 2018-05-08 10:17:52 +0530 | [diff] [blame] | 268 | static const struct snd_soc_ops cz_max_play_ops = { |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 269 | .startup = cz_max_startup, |
| 270 | .shutdown = cz_max_shutdown, |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 271 | }; |
| 272 | |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 273 | static const struct snd_soc_ops cz_dmic0_cap_ops = { |
| 274 | .startup = cz_dmic0_startup, |
| 275 | .shutdown = cz_dmic_shutdown, |
| 276 | }; |
| 277 | |
| 278 | static const struct snd_soc_ops cz_dmic1_cap_ops = { |
| 279 | .startup = cz_dmic1_startup, |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 280 | .shutdown = cz_dmic_shutdown, |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 281 | }; |
| 282 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 283 | static struct snd_soc_dai_link cz_dai_7219_98357[] = { |
| 284 | { |
Agrawal, Akshu | 3bec6fa | 2018-06-21 12:58:16 +0800 | [diff] [blame] | 285 | .name = "amd-da7219-play", |
| 286 | .stream_name = "Playback", |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 287 | .platform_name = "acp_audio_dma.0.auto", |
Agrawal, Akshu | 3bec6fa | 2018-06-21 12:58:16 +0800 | [diff] [blame] | 288 | .cpu_dai_name = "designware-i2s.1.auto", |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 289 | .codec_dai_name = "da7219-hifi", |
| 290 | .codec_name = "i2c-DLGS7219:00", |
| 291 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 292 | | SND_SOC_DAIFMT_CBM_CFM, |
| 293 | .init = cz_da7219_init, |
| 294 | .dpcm_playback = 1, |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 295 | .ops = &cz_da7219_play_ops, |
Agrawal, Akshu | 3bec6fa | 2018-06-21 12:58:16 +0800 | [diff] [blame] | 296 | }, |
| 297 | { |
| 298 | .name = "amd-da7219-cap", |
| 299 | .stream_name = "Capture", |
| 300 | .platform_name = "acp_audio_dma.0.auto", |
| 301 | .cpu_dai_name = "designware-i2s.2.auto", |
| 302 | .codec_dai_name = "da7219-hifi", |
| 303 | .codec_name = "i2c-DLGS7219:00", |
| 304 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 305 | | SND_SOC_DAIFMT_CBM_CFM, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 306 | .dpcm_capture = 1, |
| 307 | .ops = &cz_da7219_cap_ops, |
| 308 | }, |
| 309 | { |
| 310 | .name = "amd-max98357-play", |
| 311 | .stream_name = "HiFi Playback", |
| 312 | .platform_name = "acp_audio_dma.0.auto", |
Agrawal, Akshu | 3bec6fa | 2018-06-21 12:58:16 +0800 | [diff] [blame] | 313 | .cpu_dai_name = "designware-i2s.3.auto", |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 314 | .codec_dai_name = "HiFi", |
| 315 | .codec_name = "MX98357A:00", |
| 316 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 317 | | SND_SOC_DAIFMT_CBM_CFM, |
| 318 | .dpcm_playback = 1, |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 319 | .ops = &cz_max_play_ops, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 320 | }, |
| 321 | { |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 322 | /* C panel DMIC */ |
| 323 | .name = "dmic0", |
| 324 | .stream_name = "DMIC0 Capture", |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 325 | .platform_name = "acp_audio_dma.0.auto", |
Agrawal, Akshu | 3bec6fa | 2018-06-21 12:58:16 +0800 | [diff] [blame] | 326 | .cpu_dai_name = "designware-i2s.3.auto", |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 327 | .codec_dai_name = "adau7002-hifi", |
| 328 | .codec_name = "ADAU7002:00", |
| 329 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 330 | | SND_SOC_DAIFMT_CBM_CFM, |
| 331 | .dpcm_capture = 1, |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 332 | .ops = &cz_dmic0_cap_ops, |
| 333 | }, |
| 334 | { |
| 335 | /* A/B panel DMIC */ |
| 336 | .name = "dmic1", |
| 337 | .stream_name = "DMIC1 Capture", |
| 338 | .platform_name = "acp_audio_dma.0.auto", |
| 339 | .cpu_dai_name = "designware-i2s.2.auto", |
| 340 | .codec_dai_name = "adau7002-hifi", |
| 341 | .codec_name = "ADAU7002:00", |
| 342 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 343 | | SND_SOC_DAIFMT_CBM_CFM, |
| 344 | .dpcm_capture = 1, |
| 345 | .ops = &cz_dmic1_cap_ops, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 346 | }, |
| 347 | }; |
| 348 | |
| 349 | static const struct snd_soc_dapm_widget cz_widgets[] = { |
| 350 | SND_SOC_DAPM_HP("Headphones", NULL), |
| 351 | SND_SOC_DAPM_SPK("Speakers", NULL), |
| 352 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 353 | SND_SOC_DAPM_MIC("Int Mic", NULL), |
| 354 | }; |
| 355 | |
| 356 | static const struct snd_soc_dapm_route cz_audio_route[] = { |
| 357 | {"Headphones", NULL, "HPL"}, |
| 358 | {"Headphones", NULL, "HPR"}, |
| 359 | {"MIC", NULL, "Headset Mic"}, |
| 360 | {"Speakers", NULL, "Speaker"}, |
| 361 | {"PDM_DAT", NULL, "Int Mic"}, |
| 362 | }; |
| 363 | |
| 364 | static const struct snd_kcontrol_new cz_mc_controls[] = { |
| 365 | SOC_DAPM_PIN_SWITCH("Headphones"), |
| 366 | SOC_DAPM_PIN_SWITCH("Speakers"), |
| 367 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 368 | SOC_DAPM_PIN_SWITCH("Int Mic"), |
| 369 | }; |
| 370 | |
| 371 | static struct snd_soc_card cz_card = { |
| 372 | .name = "acpd7219m98357", |
| 373 | .owner = THIS_MODULE, |
| 374 | .dai_link = cz_dai_7219_98357, |
| 375 | .num_links = ARRAY_SIZE(cz_dai_7219_98357), |
| 376 | .dapm_widgets = cz_widgets, |
| 377 | .num_dapm_widgets = ARRAY_SIZE(cz_widgets), |
| 378 | .dapm_routes = cz_audio_route, |
| 379 | .num_dapm_routes = ARRAY_SIZE(cz_audio_route), |
| 380 | .controls = cz_mc_controls, |
| 381 | .num_controls = ARRAY_SIZE(cz_mc_controls), |
| 382 | }; |
| 383 | |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 384 | static struct regulator_consumer_supply acp_da7219_supplies[] = { |
| 385 | REGULATOR_SUPPLY("VDD", "i2c-DLGS7219:00"), |
| 386 | REGULATOR_SUPPLY("VDDMIC", "i2c-DLGS7219:00"), |
| 387 | REGULATOR_SUPPLY("VDDIO", "i2c-DLGS7219:00"), |
| 388 | REGULATOR_SUPPLY("IOVDD", "ADAU7002:00"), |
| 389 | }; |
| 390 | |
| 391 | static struct regulator_init_data acp_da7219_data = { |
| 392 | .constraints = { |
| 393 | .always_on = 1, |
| 394 | }, |
| 395 | .num_consumer_supplies = ARRAY_SIZE(acp_da7219_supplies), |
| 396 | .consumer_supplies = acp_da7219_supplies, |
| 397 | }; |
| 398 | |
| 399 | static struct regulator_config acp_da7219_cfg = { |
| 400 | .init_data = &acp_da7219_data, |
| 401 | }; |
| 402 | |
| 403 | static struct regulator_ops acp_da7219_ops = { |
| 404 | }; |
| 405 | |
Julia Lawall | de36364 | 2018-10-28 06:56:08 +0100 | [diff] [blame^] | 406 | static const struct regulator_desc acp_da7219_desc = { |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 407 | .name = "reg-fixed-1.8V", |
| 408 | .type = REGULATOR_VOLTAGE, |
| 409 | .owner = THIS_MODULE, |
| 410 | .ops = &acp_da7219_ops, |
| 411 | .fixed_uV = 1800000, /* 1.8V */ |
| 412 | .n_voltages = 1, |
| 413 | }; |
| 414 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 415 | static int cz_probe(struct platform_device *pdev) |
| 416 | { |
| 417 | int ret; |
| 418 | struct snd_soc_card *card; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 419 | struct acp_platform_info *machine; |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 420 | struct regulator_dev *rdev; |
| 421 | |
| 422 | acp_da7219_cfg.dev = &pdev->dev; |
| 423 | rdev = devm_regulator_register(&pdev->dev, &acp_da7219_desc, |
| 424 | &acp_da7219_cfg); |
| 425 | if (IS_ERR(rdev)) { |
| 426 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", |
Akshu Agrawal | 7699676 | 2018-07-26 14:04:08 +0800 | [diff] [blame] | 427 | (int)PTR_ERR(rdev)); |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 428 | return -EINVAL; |
| 429 | } |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 430 | |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 431 | machine = devm_kzalloc(&pdev->dev, sizeof(struct acp_platform_info), |
| 432 | GFP_KERNEL); |
| 433 | if (!machine) |
| 434 | return -ENOMEM; |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 435 | card = &cz_card; |
| 436 | cz_card.dev = &pdev->dev; |
| 437 | platform_set_drvdata(pdev, card); |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 438 | snd_soc_card_set_drvdata(card, machine); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 439 | ret = devm_snd_soc_register_card(&pdev->dev, &cz_card); |
| 440 | if (ret) { |
| 441 | dev_err(&pdev->dev, |
| 442 | "devm_snd_soc_register_card(%s) failed: %d\n", |
| 443 | cz_card.name, ret); |
| 444 | return ret; |
| 445 | } |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 446 | bt_uart_enable = !device_property_read_bool(&pdev->dev, |
| 447 | "bt-pad-enable"); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static const struct acpi_device_id cz_audio_acpi_match[] = { |
| 452 | { "AMD7219", 0 }, |
| 453 | {}, |
| 454 | }; |
| 455 | MODULE_DEVICE_TABLE(acpi, cz_audio_acpi_match); |
| 456 | |
| 457 | static struct platform_driver cz_pcm_driver = { |
| 458 | .driver = { |
| 459 | .name = "cz-da7219-max98357a", |
| 460 | .acpi_match_table = ACPI_PTR(cz_audio_acpi_match), |
| 461 | .pm = &snd_soc_pm_ops, |
| 462 | }, |
| 463 | .probe = cz_probe, |
| 464 | }; |
| 465 | |
| 466 | module_platform_driver(cz_pcm_driver); |
| 467 | |
| 468 | MODULE_AUTHOR("akshu.agrawal@amd.com"); |
| 469 | MODULE_DESCRIPTION("DA7219 & MAX98357A audio support"); |
| 470 | MODULE_LICENSE("GPL v2"); |