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; |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 49 | static struct clk *da7219_dai_wclk; |
| 50 | static struct clk *da7219_dai_bclk; |
Andi Kleen | eddb608 | 2019-03-21 15:00:05 -0700 | [diff] [blame] | 51 | extern bool bt_uart_enable; |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 52 | |
| 53 | static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd) |
| 54 | { |
| 55 | int ret; |
| 56 | struct snd_soc_card *card = rtd->card; |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 57 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Kuninori Morimoto | 9a60cde | 2018-02-19 04:16:06 +0000 | [diff] [blame] | 58 | struct snd_soc_component *component = codec_dai->component; |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 59 | |
| 60 | dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name); |
| 61 | |
| 62 | ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, |
| 63 | CZ_PLAT_CLK, SND_SOC_CLOCK_IN); |
| 64 | if (ret < 0) { |
| 65 | dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret); |
| 66 | return ret; |
| 67 | } |
| 68 | |
| 69 | ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL, |
Akshu Agrawal | 6e55407 | 2018-05-08 10:17:51 +0530 | [diff] [blame] | 70 | CZ_PLAT_CLK, DA7219_PLL_FREQ_OUT_98304); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 71 | if (ret < 0) { |
| 72 | dev_err(rtd->dev, "can't set codec pll: %d\n", ret); |
| 73 | return ret; |
| 74 | } |
| 75 | |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 76 | da7219_dai_wclk = clk_get(component->dev, "da7219-dai-wclk"); |
| 77 | da7219_dai_bclk = clk_get(component->dev, "da7219-dai-bclk"); |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 78 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 79 | ret = snd_soc_card_jack_new(card, "Headset Jack", |
Akshu Agrawal | 2657c6a | 2018-10-15 12:24:44 +0530 | [diff] [blame] | 80 | SND_JACK_HEADSET | SND_JACK_LINEOUT | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 81 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | |
| 82 | SND_JACK_BTN_2 | SND_JACK_BTN_3, |
| 83 | &cz_jack, NULL, 0); |
| 84 | if (ret) { |
| 85 | dev_err(card->dev, "HP jack creation failed %d\n", ret); |
| 86 | return ret; |
| 87 | } |
| 88 | |
Agrawal, Akshu | 923859e | 2018-04-12 17:57:11 +0800 | [diff] [blame] | 89 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); |
| 90 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP); |
| 91 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); |
| 92 | snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); |
| 93 | |
Kuninori Morimoto | 9a60cde | 2018-02-19 04:16:06 +0000 | [diff] [blame] | 94 | da7219_aad_jack_det(component, &cz_jack); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 99 | static int da7219_clk_enable(struct snd_pcm_substream *substream, |
| 100 | int wclk_rate, int bclk_rate) |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 101 | { |
| 102 | int ret = 0; |
| 103 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 104 | |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 105 | clk_set_rate(da7219_dai_wclk, wclk_rate); |
| 106 | clk_set_rate(da7219_dai_bclk, bclk_rate); |
| 107 | ret = clk_prepare_enable(da7219_dai_bclk); |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 108 | if (ret < 0) { |
| 109 | dev_err(rtd->dev, "can't enable master clock %d\n", ret); |
| 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | return ret; |
| 114 | } |
| 115 | |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 116 | static void da7219_clk_disable(void) |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 117 | { |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 118 | clk_disable_unprepare(da7219_dai_bclk); |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 119 | } |
| 120 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 121 | static const unsigned int channels[] = { |
| 122 | DUAL_CHANNEL, |
| 123 | }; |
| 124 | |
| 125 | static const unsigned int rates[] = { |
| 126 | 48000, |
| 127 | }; |
| 128 | |
| 129 | static const struct snd_pcm_hw_constraint_list constraints_rates = { |
| 130 | .count = ARRAY_SIZE(rates), |
| 131 | .list = rates, |
| 132 | .mask = 0, |
| 133 | }; |
| 134 | |
| 135 | static const struct snd_pcm_hw_constraint_list constraints_channels = { |
| 136 | .count = ARRAY_SIZE(channels), |
| 137 | .list = channels, |
| 138 | .mask = 0, |
| 139 | }; |
| 140 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 141 | static int cz_da7219_play_startup(struct snd_pcm_substream *substream) |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 142 | { |
| 143 | struct snd_pcm_runtime *runtime = substream->runtime; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 144 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 145 | struct snd_soc_card *card = rtd->card; |
| 146 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 147 | |
| 148 | /* |
| 149 | * On this platform for PCM device we support stereo |
| 150 | */ |
| 151 | |
| 152 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 153 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 154 | &constraints_channels); |
| 155 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 156 | &constraints_rates); |
| 157 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 158 | machine->play_i2s_instance = I2S_SP_INSTANCE; |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 159 | return 0; |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | static int cz_da7219_cap_startup(struct snd_pcm_substream *substream) |
| 163 | { |
| 164 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 165 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 166 | struct snd_soc_card *card = rtd->card; |
| 167 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 168 | |
| 169 | /* |
| 170 | * On this platform for PCM device we support stereo |
| 171 | */ |
| 172 | |
| 173 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 174 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 175 | &constraints_channels); |
| 176 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 177 | &constraints_rates); |
| 178 | |
| 179 | machine->cap_i2s_instance = I2S_SP_INSTANCE; |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 180 | machine->capture_channel = CAP_CHANNEL1; |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 181 | return 0; |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 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; |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 202 | return 0; |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 203 | } |
| 204 | |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 205 | static int cz_dmic0_startup(struct snd_pcm_substream *substream) |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 206 | { |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 207 | struct snd_pcm_runtime *runtime = substream->runtime; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 208 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 209 | struct snd_soc_card *card = rtd->card; |
| 210 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 211 | |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 212 | /* |
| 213 | * On this platform for PCM device we support stereo |
| 214 | */ |
| 215 | |
| 216 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 217 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 218 | &constraints_channels); |
| 219 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 220 | &constraints_rates); |
| 221 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 222 | machine->cap_i2s_instance = I2S_BT_INSTANCE; |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 223 | return 0; |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 224 | } |
| 225 | |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 226 | static int cz_dmic1_startup(struct snd_pcm_substream *substream) |
| 227 | { |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 228 | struct snd_pcm_runtime *runtime = substream->runtime; |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 229 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 230 | struct snd_soc_card *card = rtd->card; |
| 231 | struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); |
| 232 | |
Akshu Agrawal | c736cbd | 2018-08-21 12:25:05 +0530 | [diff] [blame] | 233 | /* |
| 234 | * On this platform for PCM device we support stereo |
| 235 | */ |
| 236 | |
| 237 | runtime->hw.channels_max = DUAL_CHANNEL; |
| 238 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 239 | &constraints_channels); |
| 240 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 241 | &constraints_rates); |
| 242 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 243 | machine->cap_i2s_instance = I2S_SP_INSTANCE; |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 244 | machine->capture_channel = CAP_CHANNEL0; |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 245 | return 0; |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 246 | } |
| 247 | |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 248 | static int cz_da7219_params(struct snd_pcm_substream *substream, |
| 249 | struct snd_pcm_hw_params *params) |
| 250 | { |
| 251 | int wclk, bclk; |
| 252 | |
| 253 | wclk = params_rate(params); |
| 254 | bclk = wclk * params_channels(params) * |
| 255 | snd_pcm_format_width(params_format(params)); |
| 256 | /* ADAU7002 spec: "The ADAU7002 requires a BCLK rate |
| 257 | * that is minimum of 64x the LRCLK sample rate." |
| 258 | * DA7219 is the only clk source so for all codecs |
| 259 | * we have to limit bclk to 64X lrclk. |
| 260 | */ |
| 261 | if (bclk < (wclk * 64)) |
| 262 | bclk = wclk * 64; |
| 263 | return da7219_clk_enable(substream, wclk, bclk); |
| 264 | } |
| 265 | |
| 266 | static void cz_da7219_shutdown(struct snd_pcm_substream *substream) |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 267 | { |
| 268 | da7219_clk_disable(); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 269 | } |
| 270 | |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 271 | static const struct snd_soc_ops cz_da7219_play_ops = { |
| 272 | .startup = cz_da7219_play_startup, |
| 273 | .shutdown = cz_da7219_shutdown, |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 274 | .hw_params = cz_da7219_params, |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 275 | }; |
| 276 | |
Akshu Agrawal | 839a12c | 2018-05-08 10:17:52 +0530 | [diff] [blame] | 277 | static const struct snd_soc_ops cz_da7219_cap_ops = { |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 278 | .startup = cz_da7219_cap_startup, |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 279 | .shutdown = cz_da7219_shutdown, |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 280 | .hw_params = cz_da7219_params, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 281 | }; |
| 282 | |
Akshu Agrawal | 839a12c | 2018-05-08 10:17:52 +0530 | [diff] [blame] | 283 | static const struct snd_soc_ops cz_max_play_ops = { |
Akshu Agrawal | e9716ff | 2018-05-08 10:17:50 +0530 | [diff] [blame] | 284 | .startup = cz_max_startup, |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 285 | .shutdown = cz_da7219_shutdown, |
| 286 | .hw_params = cz_da7219_params, |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 287 | }; |
| 288 | |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 289 | static const struct snd_soc_ops cz_dmic0_cap_ops = { |
| 290 | .startup = cz_dmic0_startup, |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 291 | .shutdown = cz_da7219_shutdown, |
| 292 | .hw_params = cz_da7219_params, |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 293 | }; |
| 294 | |
| 295 | static const struct snd_soc_ops cz_dmic1_cap_ops = { |
| 296 | .startup = cz_dmic1_startup, |
Agrawal, Akshu | bb24a31 | 2019-04-17 10:05:13 +0000 | [diff] [blame] | 297 | .shutdown = cz_da7219_shutdown, |
| 298 | .hw_params = cz_da7219_params, |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 299 | }; |
| 300 | |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 301 | SND_SOC_DAILINK_DEF(designware1, |
| 302 | DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.1.auto"))); |
| 303 | SND_SOC_DAILINK_DEF(designware2, |
| 304 | DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.2.auto"))); |
| 305 | SND_SOC_DAILINK_DEF(designware3, |
| 306 | DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.3.auto"))); |
| 307 | |
| 308 | SND_SOC_DAILINK_DEF(dlgs, |
| 309 | DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00", "da7219-hifi"))); |
| 310 | SND_SOC_DAILINK_DEF(mx, |
| 311 | DAILINK_COMP_ARRAY(COMP_CODEC("MX98357A:00", "HiFi"))); |
| 312 | SND_SOC_DAILINK_DEF(adau, |
| 313 | DAILINK_COMP_ARRAY(COMP_CODEC("ADAU7002:00", "adau7002-hifi"))); |
| 314 | |
| 315 | SND_SOC_DAILINK_DEF(platform, |
| 316 | DAILINK_COMP_ARRAY(COMP_PLATFORM("acp_audio_dma.0.auto"))); |
| 317 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 318 | static struct snd_soc_dai_link cz_dai_7219_98357[] = { |
| 319 | { |
Agrawal, Akshu | 3bec6fa | 2018-06-21 12:58:16 +0800 | [diff] [blame] | 320 | .name = "amd-da7219-play", |
| 321 | .stream_name = "Playback", |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 322 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 323 | | SND_SOC_DAIFMT_CBM_CFM, |
| 324 | .init = cz_da7219_init, |
| 325 | .dpcm_playback = 1, |
Akshu Agrawal | 8dcb0c9 | 2018-09-10 22:50:27 +0530 | [diff] [blame] | 326 | .ops = &cz_da7219_play_ops, |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 327 | SND_SOC_DAILINK_REG(designware1, dlgs, platform), |
Agrawal, Akshu | 3bec6fa | 2018-06-21 12:58:16 +0800 | [diff] [blame] | 328 | }, |
| 329 | { |
| 330 | .name = "amd-da7219-cap", |
| 331 | .stream_name = "Capture", |
Agrawal, Akshu | 3bec6fa | 2018-06-21 12:58:16 +0800 | [diff] [blame] | 332 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 333 | | SND_SOC_DAIFMT_CBM_CFM, |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 334 | .dpcm_capture = 1, |
| 335 | .ops = &cz_da7219_cap_ops, |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 336 | SND_SOC_DAILINK_REG(designware2, dlgs, platform), |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 337 | }, |
| 338 | { |
| 339 | .name = "amd-max98357-play", |
| 340 | .stream_name = "HiFi Playback", |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 341 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 342 | | SND_SOC_DAIFMT_CBM_CFM, |
| 343 | .dpcm_playback = 1, |
Akshu Agrawal | c88d311 | 2018-03-19 11:07:42 +0530 | [diff] [blame] | 344 | .ops = &cz_max_play_ops, |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 345 | SND_SOC_DAILINK_REG(designware3, mx, platform), |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 346 | }, |
| 347 | { |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 348 | /* C panel DMIC */ |
| 349 | .name = "dmic0", |
| 350 | .stream_name = "DMIC0 Capture", |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 351 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 352 | | SND_SOC_DAIFMT_CBM_CFM, |
| 353 | .dpcm_capture = 1, |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 354 | .ops = &cz_dmic0_cap_ops, |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 355 | SND_SOC_DAILINK_REG(designware3, adau, platform), |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 356 | }, |
| 357 | { |
| 358 | /* A/B panel DMIC */ |
| 359 | .name = "dmic1", |
| 360 | .stream_name = "DMIC1 Capture", |
Akshu Agrawal | 2718c89 | 2018-06-21 12:58:17 +0800 | [diff] [blame] | 361 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
| 362 | | SND_SOC_DAIFMT_CBM_CFM, |
| 363 | .dpcm_capture = 1, |
| 364 | .ops = &cz_dmic1_cap_ops, |
Kuninori Morimoto | 48696d0 | 2019-06-06 13:13:29 +0900 | [diff] [blame] | 365 | SND_SOC_DAILINK_REG(designware2, adau, platform), |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 366 | }, |
| 367 | }; |
| 368 | |
| 369 | static const struct snd_soc_dapm_widget cz_widgets[] = { |
| 370 | SND_SOC_DAPM_HP("Headphones", NULL), |
| 371 | SND_SOC_DAPM_SPK("Speakers", NULL), |
| 372 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 373 | SND_SOC_DAPM_MIC("Int Mic", NULL), |
| 374 | }; |
| 375 | |
| 376 | static const struct snd_soc_dapm_route cz_audio_route[] = { |
| 377 | {"Headphones", NULL, "HPL"}, |
| 378 | {"Headphones", NULL, "HPR"}, |
| 379 | {"MIC", NULL, "Headset Mic"}, |
| 380 | {"Speakers", NULL, "Speaker"}, |
| 381 | {"PDM_DAT", NULL, "Int Mic"}, |
| 382 | }; |
| 383 | |
| 384 | static const struct snd_kcontrol_new cz_mc_controls[] = { |
| 385 | SOC_DAPM_PIN_SWITCH("Headphones"), |
| 386 | SOC_DAPM_PIN_SWITCH("Speakers"), |
| 387 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 388 | SOC_DAPM_PIN_SWITCH("Int Mic"), |
| 389 | }; |
| 390 | |
| 391 | static struct snd_soc_card cz_card = { |
| 392 | .name = "acpd7219m98357", |
| 393 | .owner = THIS_MODULE, |
| 394 | .dai_link = cz_dai_7219_98357, |
| 395 | .num_links = ARRAY_SIZE(cz_dai_7219_98357), |
| 396 | .dapm_widgets = cz_widgets, |
| 397 | .num_dapm_widgets = ARRAY_SIZE(cz_widgets), |
| 398 | .dapm_routes = cz_audio_route, |
| 399 | .num_dapm_routes = ARRAY_SIZE(cz_audio_route), |
| 400 | .controls = cz_mc_controls, |
| 401 | .num_controls = ARRAY_SIZE(cz_mc_controls), |
| 402 | }; |
| 403 | |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 404 | static struct regulator_consumer_supply acp_da7219_supplies[] = { |
| 405 | REGULATOR_SUPPLY("VDD", "i2c-DLGS7219:00"), |
| 406 | REGULATOR_SUPPLY("VDDMIC", "i2c-DLGS7219:00"), |
| 407 | REGULATOR_SUPPLY("VDDIO", "i2c-DLGS7219:00"), |
| 408 | REGULATOR_SUPPLY("IOVDD", "ADAU7002:00"), |
| 409 | }; |
| 410 | |
| 411 | static struct regulator_init_data acp_da7219_data = { |
| 412 | .constraints = { |
| 413 | .always_on = 1, |
| 414 | }, |
| 415 | .num_consumer_supplies = ARRAY_SIZE(acp_da7219_supplies), |
| 416 | .consumer_supplies = acp_da7219_supplies, |
| 417 | }; |
| 418 | |
| 419 | static struct regulator_config acp_da7219_cfg = { |
| 420 | .init_data = &acp_da7219_data, |
| 421 | }; |
| 422 | |
| 423 | static struct regulator_ops acp_da7219_ops = { |
| 424 | }; |
| 425 | |
Julia Lawall | de36364 | 2018-10-28 06:56:08 +0100 | [diff] [blame] | 426 | static const struct regulator_desc acp_da7219_desc = { |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 427 | .name = "reg-fixed-1.8V", |
| 428 | .type = REGULATOR_VOLTAGE, |
| 429 | .owner = THIS_MODULE, |
| 430 | .ops = &acp_da7219_ops, |
| 431 | .fixed_uV = 1800000, /* 1.8V */ |
| 432 | .n_voltages = 1, |
| 433 | }; |
| 434 | |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 435 | static int cz_probe(struct platform_device *pdev) |
| 436 | { |
| 437 | int ret; |
| 438 | struct snd_soc_card *card; |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 439 | struct acp_platform_info *machine; |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 440 | struct regulator_dev *rdev; |
| 441 | |
| 442 | acp_da7219_cfg.dev = &pdev->dev; |
| 443 | rdev = devm_regulator_register(&pdev->dev, &acp_da7219_desc, |
| 444 | &acp_da7219_cfg); |
| 445 | if (IS_ERR(rdev)) { |
| 446 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", |
Akshu Agrawal | 7699676 | 2018-07-26 14:04:08 +0800 | [diff] [blame] | 447 | (int)PTR_ERR(rdev)); |
Akshu Agrawal | c183fec | 2018-07-25 17:00:59 +0800 | [diff] [blame] | 448 | return -EINVAL; |
| 449 | } |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 450 | |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 451 | machine = devm_kzalloc(&pdev->dev, sizeof(struct acp_platform_info), |
| 452 | GFP_KERNEL); |
| 453 | if (!machine) |
| 454 | return -ENOMEM; |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 455 | card = &cz_card; |
| 456 | cz_card.dev = &pdev->dev; |
| 457 | platform_set_drvdata(pdev, card); |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 458 | snd_soc_card_set_drvdata(card, machine); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 459 | ret = devm_snd_soc_register_card(&pdev->dev, &cz_card); |
| 460 | if (ret) { |
| 461 | dev_err(&pdev->dev, |
| 462 | "devm_snd_soc_register_card(%s) failed: %d\n", |
| 463 | cz_card.name, ret); |
| 464 | return ret; |
| 465 | } |
Mukunda, Vijendar | ccfbb4f | 2018-05-08 10:17:53 +0530 | [diff] [blame] | 466 | bt_uart_enable = !device_property_read_bool(&pdev->dev, |
| 467 | "bt-pad-enable"); |
Akshu Agrawal | 608a300f | 2018-02-16 13:11:13 +0530 | [diff] [blame] | 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | static const struct acpi_device_id cz_audio_acpi_match[] = { |
| 472 | { "AMD7219", 0 }, |
| 473 | {}, |
| 474 | }; |
| 475 | MODULE_DEVICE_TABLE(acpi, cz_audio_acpi_match); |
| 476 | |
| 477 | static struct platform_driver cz_pcm_driver = { |
| 478 | .driver = { |
| 479 | .name = "cz-da7219-max98357a", |
| 480 | .acpi_match_table = ACPI_PTR(cz_audio_acpi_match), |
| 481 | .pm = &snd_soc_pm_ops, |
| 482 | }, |
| 483 | .probe = cz_probe, |
| 484 | }; |
| 485 | |
| 486 | module_platform_driver(cz_pcm_driver); |
| 487 | |
| 488 | MODULE_AUTHOR("akshu.agrawal@amd.com"); |
| 489 | MODULE_DESCRIPTION("DA7219 & MAX98357A audio support"); |
| 490 | MODULE_LICENSE("GPL v2"); |