Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // |
| 3 | // mt8183-mt6358.c -- |
| 4 | // MT8183-MT6358-TS3A227-MAX98357 ALSA SoC machine driver |
| 5 | // |
| 6 | // Copyright (c) 2018 MediaTek Inc. |
| 7 | // Author: Shunli Wang <shunli.wang@mediatek.com> |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <sound/pcm_params.h> |
| 11 | #include <sound/soc.h> |
| 12 | #include <sound/jack.h> |
| 13 | #include <linux/pinctrl/consumer.h> |
| 14 | |
| 15 | #include "mt8183-afe-common.h" |
| 16 | #include "../../codecs/ts3a227e.h" |
| 17 | |
Tzung-Bi Shih | 96ed769 | 2019-08-30 15:42:37 +0800 | [diff] [blame] | 18 | enum PINCTRL_PIN_STATE { |
| 19 | PIN_STATE_DEFAULT = 0, |
| 20 | PIN_TDM_OUT_ON, |
| 21 | PIN_TDM_OUT_OFF, |
Tzung-Bi Shih | 2cc3cd5 | 2019-10-19 15:02:54 +0800 | [diff] [blame] | 22 | PIN_WOV, |
Tzung-Bi Shih | 96ed769 | 2019-08-30 15:42:37 +0800 | [diff] [blame] | 23 | PIN_STATE_MAX |
| 24 | }; |
| 25 | |
| 26 | static const char * const mt8183_pin_str[PIN_STATE_MAX] = { |
Tzung-Bi Shih | 2cc3cd5 | 2019-10-19 15:02:54 +0800 | [diff] [blame] | 27 | "default", "aud_tdm_out_on", "aud_tdm_out_off", "wov", |
Tzung-Bi Shih | 96ed769 | 2019-08-30 15:42:37 +0800 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | struct mt8183_mt6358_ts3a227_max98357_priv { |
| 31 | struct pinctrl *pinctrl; |
| 32 | struct pinctrl_state *pin_states[PIN_STATE_MAX]; |
Tzung-Bi Shih | 95d779b | 2019-08-30 15:42:38 +0800 | [diff] [blame] | 33 | struct snd_soc_jack headset_jack; |
Tzung-Bi Shih | 96ed769 | 2019-08-30 15:42:37 +0800 | [diff] [blame] | 34 | }; |
| 35 | |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 36 | static int mt8183_mt6358_i2s_hw_params(struct snd_pcm_substream *substream, |
| 37 | struct snd_pcm_hw_params *params) |
| 38 | { |
| 39 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 40 | unsigned int rate = params_rate(params); |
| 41 | unsigned int mclk_fs_ratio = 128; |
| 42 | unsigned int mclk_fs = rate * mclk_fs_ratio; |
| 43 | |
| 44 | return snd_soc_dai_set_sysclk(rtd->cpu_dai, |
| 45 | 0, mclk_fs, SND_SOC_CLOCK_OUT); |
| 46 | } |
| 47 | |
| 48 | static const struct snd_soc_ops mt8183_mt6358_i2s_ops = { |
| 49 | .hw_params = mt8183_mt6358_i2s_hw_params, |
| 50 | }; |
| 51 | |
| 52 | static int mt8183_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
| 53 | struct snd_pcm_hw_params *params) |
| 54 | { |
| 55 | dev_dbg(rtd->dev, "%s(), fix format to 32bit\n", __func__); |
| 56 | |
| 57 | /* fix BE i2s format to 32bit, clean param mask first */ |
| 58 | snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), |
| 59 | 0, SNDRV_PCM_FORMAT_LAST); |
| 60 | |
| 61 | params_set_format(params, SNDRV_PCM_FORMAT_S32_LE); |
| 62 | return 0; |
| 63 | } |
| 64 | |
Tzung-Bi Shih | 1df1e54 | 2019-04-08 18:47:28 +0800 | [diff] [blame] | 65 | static int |
| 66 | mt8183_mt6358_ts3a227_max98357_bt_sco_startup( |
| 67 | struct snd_pcm_substream *substream) |
| 68 | { |
| 69 | static const unsigned int rates[] = { |
| 70 | 8000, 16000 |
| 71 | }; |
| 72 | static const struct snd_pcm_hw_constraint_list constraints_rates = { |
| 73 | .count = ARRAY_SIZE(rates), |
| 74 | .list = rates, |
| 75 | .mask = 0, |
| 76 | }; |
| 77 | static const unsigned int channels[] = { |
| 78 | 1, |
| 79 | }; |
| 80 | static const struct snd_pcm_hw_constraint_list constraints_channels = { |
| 81 | .count = ARRAY_SIZE(channels), |
| 82 | .list = channels, |
| 83 | .mask = 0, |
| 84 | }; |
| 85 | |
| 86 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 87 | |
| 88 | snd_pcm_hw_constraint_list(runtime, 0, |
| 89 | SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); |
| 90 | runtime->hw.channels_max = 1; |
| 91 | snd_pcm_hw_constraint_list(runtime, 0, |
| 92 | SNDRV_PCM_HW_PARAM_CHANNELS, |
| 93 | &constraints_channels); |
| 94 | |
| 95 | runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; |
| 96 | snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16); |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | static const struct snd_soc_ops mt8183_mt6358_ts3a227_max98357_bt_sco_ops = { |
| 102 | .startup = mt8183_mt6358_ts3a227_max98357_bt_sco_startup, |
| 103 | }; |
| 104 | |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 105 | /* FE */ |
| 106 | SND_SOC_DAILINK_DEFS(playback1, |
| 107 | DAILINK_COMP_ARRAY(COMP_CPU("DL1")), |
| 108 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 109 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 110 | |
| 111 | SND_SOC_DAILINK_DEFS(playback2, |
| 112 | DAILINK_COMP_ARRAY(COMP_CPU("DL2")), |
| 113 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 114 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 115 | |
| 116 | SND_SOC_DAILINK_DEFS(playback3, |
| 117 | DAILINK_COMP_ARRAY(COMP_CPU("DL3")), |
| 118 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 119 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 120 | |
| 121 | SND_SOC_DAILINK_DEFS(capture1, |
| 122 | DAILINK_COMP_ARRAY(COMP_CPU("UL1")), |
| 123 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 124 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 125 | |
| 126 | SND_SOC_DAILINK_DEFS(capture2, |
| 127 | DAILINK_COMP_ARRAY(COMP_CPU("UL2")), |
| 128 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 129 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 130 | |
| 131 | SND_SOC_DAILINK_DEFS(capture3, |
| 132 | DAILINK_COMP_ARRAY(COMP_CPU("UL3")), |
| 133 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 134 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 135 | |
| 136 | SND_SOC_DAILINK_DEFS(capture_mono, |
| 137 | DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_1")), |
| 138 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 139 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 140 | |
| 141 | SND_SOC_DAILINK_DEFS(playback_hdmi, |
| 142 | DAILINK_COMP_ARRAY(COMP_CPU("HDMI")), |
| 143 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 144 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 145 | |
Tzung-Bi Shih | 2cc3cd5 | 2019-10-19 15:02:54 +0800 | [diff] [blame] | 146 | SND_SOC_DAILINK_DEFS(wake_on_voice, |
| 147 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 148 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 149 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 150 | |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 151 | /* BE */ |
| 152 | SND_SOC_DAILINK_DEFS(primary_codec, |
| 153 | DAILINK_COMP_ARRAY(COMP_CPU("ADDA")), |
| 154 | DAILINK_COMP_ARRAY(COMP_CODEC("mt6358-sound", "mt6358-snd-codec-aif1")), |
| 155 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 156 | |
| 157 | SND_SOC_DAILINK_DEFS(pcm1, |
| 158 | DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")), |
| 159 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 160 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 161 | |
| 162 | SND_SOC_DAILINK_DEFS(pcm2, |
| 163 | DAILINK_COMP_ARRAY(COMP_CPU("PCM 2")), |
| 164 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 165 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 166 | |
| 167 | SND_SOC_DAILINK_DEFS(i2s0, |
| 168 | DAILINK_COMP_ARRAY(COMP_CPU("I2S0")), |
| 169 | DAILINK_COMP_ARRAY(COMP_CODEC("bt-sco", "bt-sco-pcm")), |
| 170 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 171 | |
| 172 | SND_SOC_DAILINK_DEFS(i2s1, |
| 173 | DAILINK_COMP_ARRAY(COMP_CPU("I2S1")), |
| 174 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 175 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 176 | |
| 177 | SND_SOC_DAILINK_DEFS(i2s2, |
| 178 | DAILINK_COMP_ARRAY(COMP_CPU("I2S2")), |
| 179 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 180 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 181 | |
| 182 | SND_SOC_DAILINK_DEFS(i2s3, |
| 183 | DAILINK_COMP_ARRAY(COMP_CPU("I2S3")), |
| 184 | DAILINK_COMP_ARRAY(COMP_CODEC("max98357a", "HiFi")), |
| 185 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 186 | |
| 187 | SND_SOC_DAILINK_DEFS(i2s5, |
| 188 | DAILINK_COMP_ARRAY(COMP_CPU("I2S5")), |
| 189 | DAILINK_COMP_ARRAY(COMP_CODEC("bt-sco", "bt-sco-pcm")), |
| 190 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 191 | |
| 192 | SND_SOC_DAILINK_DEFS(tdm, |
| 193 | DAILINK_COMP_ARRAY(COMP_CPU("TDM")), |
| 194 | DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 195 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 196 | |
Jiaxin Yu | 6191cbd | 2019-08-22 20:51:00 +0800 | [diff] [blame] | 197 | static int mt8183_mt6358_tdm_startup(struct snd_pcm_substream *substream) |
| 198 | { |
| 199 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 200 | struct mt8183_mt6358_ts3a227_max98357_priv *priv = |
| 201 | snd_soc_card_get_drvdata(rtd->card); |
| 202 | int ret; |
| 203 | |
| 204 | if (IS_ERR(priv->pin_states[PIN_TDM_OUT_ON])) |
| 205 | return PTR_ERR(priv->pin_states[PIN_TDM_OUT_ON]); |
| 206 | |
| 207 | ret = pinctrl_select_state(priv->pinctrl, |
| 208 | priv->pin_states[PIN_TDM_OUT_ON]); |
| 209 | if (ret) |
| 210 | dev_err(rtd->card->dev, "%s failed to select state %d\n", |
| 211 | __func__, ret); |
| 212 | |
| 213 | return ret; |
| 214 | } |
| 215 | |
| 216 | static void mt8183_mt6358_tdm_shutdown(struct snd_pcm_substream *substream) |
| 217 | { |
| 218 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 219 | struct mt8183_mt6358_ts3a227_max98357_priv *priv = |
| 220 | snd_soc_card_get_drvdata(rtd->card); |
| 221 | int ret; |
| 222 | |
| 223 | if (IS_ERR(priv->pin_states[PIN_TDM_OUT_OFF])) |
| 224 | return; |
| 225 | |
| 226 | ret = pinctrl_select_state(priv->pinctrl, |
| 227 | priv->pin_states[PIN_TDM_OUT_OFF]); |
| 228 | if (ret) |
| 229 | dev_err(rtd->card->dev, "%s failed to select state %d\n", |
| 230 | __func__, ret); |
| 231 | } |
| 232 | |
| 233 | static struct snd_soc_ops mt8183_mt6358_tdm_ops = { |
| 234 | .startup = mt8183_mt6358_tdm_startup, |
| 235 | .shutdown = mt8183_mt6358_tdm_shutdown, |
| 236 | }; |
| 237 | |
Tzung-Bi Shih | 2cc3cd5 | 2019-10-19 15:02:54 +0800 | [diff] [blame] | 238 | static int |
| 239 | mt8183_mt6358_ts3a227_max98357_wov_startup( |
| 240 | struct snd_pcm_substream *substream) |
| 241 | { |
| 242 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 243 | struct snd_soc_card *card = rtd->card; |
| 244 | struct mt8183_mt6358_ts3a227_max98357_priv *priv = |
| 245 | snd_soc_card_get_drvdata(card); |
| 246 | |
| 247 | return pinctrl_select_state(priv->pinctrl, |
| 248 | priv->pin_states[PIN_WOV]); |
| 249 | } |
| 250 | |
| 251 | static void |
| 252 | mt8183_mt6358_ts3a227_max98357_wov_shutdown( |
| 253 | struct snd_pcm_substream *substream) |
| 254 | { |
| 255 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 256 | struct snd_soc_card *card = rtd->card; |
| 257 | struct mt8183_mt6358_ts3a227_max98357_priv *priv = |
| 258 | snd_soc_card_get_drvdata(card); |
| 259 | int ret; |
| 260 | |
| 261 | ret = pinctrl_select_state(priv->pinctrl, |
| 262 | priv->pin_states[PIN_STATE_DEFAULT]); |
| 263 | if (ret) |
| 264 | dev_err(card->dev, "%s failed to select state %d\n", |
| 265 | __func__, ret); |
| 266 | } |
| 267 | |
| 268 | static const struct snd_soc_ops mt8183_mt6358_ts3a227_max98357_wov_ops = { |
| 269 | .startup = mt8183_mt6358_ts3a227_max98357_wov_startup, |
| 270 | .shutdown = mt8183_mt6358_ts3a227_max98357_wov_shutdown, |
| 271 | }; |
| 272 | |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 273 | static struct snd_soc_dai_link |
| 274 | mt8183_mt6358_ts3a227_max98357_dai_links[] = { |
| 275 | /* FE */ |
| 276 | { |
| 277 | .name = "Playback_1", |
| 278 | .stream_name = "Playback_1", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 279 | .trigger = {SND_SOC_DPCM_TRIGGER_PRE, |
| 280 | SND_SOC_DPCM_TRIGGER_PRE}, |
| 281 | .dynamic = 1, |
| 282 | .dpcm_playback = 1, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 283 | SND_SOC_DAILINK_REG(playback1), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 284 | }, |
| 285 | { |
| 286 | .name = "Playback_2", |
| 287 | .stream_name = "Playback_2", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 288 | .trigger = {SND_SOC_DPCM_TRIGGER_PRE, |
| 289 | SND_SOC_DPCM_TRIGGER_PRE}, |
| 290 | .dynamic = 1, |
| 291 | .dpcm_playback = 1, |
Tzung-Bi Shih | 1df1e54 | 2019-04-08 18:47:28 +0800 | [diff] [blame] | 292 | .ops = &mt8183_mt6358_ts3a227_max98357_bt_sco_ops, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 293 | SND_SOC_DAILINK_REG(playback2), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 294 | }, |
| 295 | { |
| 296 | .name = "Playback_3", |
| 297 | .stream_name = "Playback_3", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 298 | .trigger = {SND_SOC_DPCM_TRIGGER_PRE, |
| 299 | SND_SOC_DPCM_TRIGGER_PRE}, |
| 300 | .dynamic = 1, |
| 301 | .dpcm_playback = 1, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 302 | SND_SOC_DAILINK_REG(playback3), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 303 | }, |
| 304 | { |
| 305 | .name = "Capture_1", |
| 306 | .stream_name = "Capture_1", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 307 | .trigger = {SND_SOC_DPCM_TRIGGER_PRE, |
| 308 | SND_SOC_DPCM_TRIGGER_PRE}, |
| 309 | .dynamic = 1, |
| 310 | .dpcm_capture = 1, |
Tzung-Bi Shih | 1df1e54 | 2019-04-08 18:47:28 +0800 | [diff] [blame] | 311 | .ops = &mt8183_mt6358_ts3a227_max98357_bt_sco_ops, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 312 | SND_SOC_DAILINK_REG(capture1), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 313 | }, |
| 314 | { |
| 315 | .name = "Capture_2", |
| 316 | .stream_name = "Capture_2", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 317 | .trigger = {SND_SOC_DPCM_TRIGGER_PRE, |
| 318 | SND_SOC_DPCM_TRIGGER_PRE}, |
| 319 | .dynamic = 1, |
| 320 | .dpcm_capture = 1, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 321 | SND_SOC_DAILINK_REG(capture2), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 322 | }, |
| 323 | { |
| 324 | .name = "Capture_3", |
| 325 | .stream_name = "Capture_3", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 326 | .trigger = {SND_SOC_DPCM_TRIGGER_PRE, |
| 327 | SND_SOC_DPCM_TRIGGER_PRE}, |
| 328 | .dynamic = 1, |
| 329 | .dpcm_capture = 1, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 330 | SND_SOC_DAILINK_REG(capture3), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 331 | }, |
| 332 | { |
| 333 | .name = "Capture_Mono_1", |
| 334 | .stream_name = "Capture_Mono_1", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 335 | .trigger = {SND_SOC_DPCM_TRIGGER_PRE, |
| 336 | SND_SOC_DPCM_TRIGGER_PRE}, |
| 337 | .dynamic = 1, |
| 338 | .dpcm_capture = 1, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 339 | SND_SOC_DAILINK_REG(capture_mono), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 340 | }, |
| 341 | { |
| 342 | .name = "Playback_HDMI", |
| 343 | .stream_name = "Playback_HDMI", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 344 | .trigger = {SND_SOC_DPCM_TRIGGER_PRE, |
| 345 | SND_SOC_DPCM_TRIGGER_PRE}, |
| 346 | .dynamic = 1, |
| 347 | .dpcm_playback = 1, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 348 | SND_SOC_DAILINK_REG(playback_hdmi), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 349 | }, |
Tzung-Bi Shih | 2cc3cd5 | 2019-10-19 15:02:54 +0800 | [diff] [blame] | 350 | { |
| 351 | .name = "Wake on Voice", |
| 352 | .stream_name = "Wake on Voice", |
| 353 | .ignore_suspend = 1, |
| 354 | .ignore = 1, |
| 355 | SND_SOC_DAILINK_REG(wake_on_voice), |
| 356 | .ops = &mt8183_mt6358_ts3a227_max98357_wov_ops, |
| 357 | }, |
| 358 | |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 359 | /* BE */ |
| 360 | { |
| 361 | .name = "Primary Codec", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 362 | .no_pcm = 1, |
| 363 | .dpcm_playback = 1, |
| 364 | .dpcm_capture = 1, |
| 365 | .ignore_suspend = 1, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 366 | SND_SOC_DAILINK_REG(primary_codec), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 367 | }, |
| 368 | { |
| 369 | .name = "PCM 1", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 370 | .no_pcm = 1, |
| 371 | .dpcm_playback = 1, |
| 372 | .dpcm_capture = 1, |
| 373 | .ignore_suspend = 1, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 374 | SND_SOC_DAILINK_REG(pcm1), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 375 | }, |
| 376 | { |
| 377 | .name = "PCM 2", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 378 | .no_pcm = 1, |
| 379 | .dpcm_playback = 1, |
| 380 | .dpcm_capture = 1, |
| 381 | .ignore_suspend = 1, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 382 | SND_SOC_DAILINK_REG(pcm2), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 383 | }, |
| 384 | { |
| 385 | .name = "I2S0", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 386 | .no_pcm = 1, |
| 387 | .dpcm_capture = 1, |
| 388 | .ignore_suspend = 1, |
| 389 | .be_hw_params_fixup = mt8183_i2s_hw_params_fixup, |
| 390 | .ops = &mt8183_mt6358_i2s_ops, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 391 | SND_SOC_DAILINK_REG(i2s0), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 392 | }, |
| 393 | { |
| 394 | .name = "I2S1", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 395 | .no_pcm = 1, |
| 396 | .dpcm_playback = 1, |
| 397 | .ignore_suspend = 1, |
| 398 | .be_hw_params_fixup = mt8183_i2s_hw_params_fixup, |
| 399 | .ops = &mt8183_mt6358_i2s_ops, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 400 | SND_SOC_DAILINK_REG(i2s1), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 401 | }, |
| 402 | { |
| 403 | .name = "I2S2", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 404 | .no_pcm = 1, |
| 405 | .dpcm_capture = 1, |
| 406 | .ignore_suspend = 1, |
| 407 | .be_hw_params_fixup = mt8183_i2s_hw_params_fixup, |
| 408 | .ops = &mt8183_mt6358_i2s_ops, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 409 | SND_SOC_DAILINK_REG(i2s2), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 410 | }, |
| 411 | { |
| 412 | .name = "I2S3", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 413 | .no_pcm = 1, |
| 414 | .dpcm_playback = 1, |
| 415 | .ignore_suspend = 1, |
| 416 | .be_hw_params_fixup = mt8183_i2s_hw_params_fixup, |
| 417 | .ops = &mt8183_mt6358_i2s_ops, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 418 | SND_SOC_DAILINK_REG(i2s3), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 419 | }, |
| 420 | { |
| 421 | .name = "I2S5", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 422 | .no_pcm = 1, |
| 423 | .dpcm_playback = 1, |
| 424 | .ignore_suspend = 1, |
| 425 | .be_hw_params_fixup = mt8183_i2s_hw_params_fixup, |
| 426 | .ops = &mt8183_mt6358_i2s_ops, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 427 | SND_SOC_DAILINK_REG(i2s5), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 428 | }, |
| 429 | { |
| 430 | .name = "TDM", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 431 | .no_pcm = 1, |
Jiaxin Yu | 8e58c52 | 2019-08-24 12:37:24 +0800 | [diff] [blame] | 432 | .dai_fmt = SND_SOC_DAIFMT_I2S | |
| 433 | SND_SOC_DAIFMT_IB_IF | |
| 434 | SND_SOC_DAIFMT_CBM_CFM, |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 435 | .dpcm_playback = 1, |
| 436 | .ignore_suspend = 1, |
Jiaxin Yu | 6191cbd | 2019-08-22 20:51:00 +0800 | [diff] [blame] | 437 | .be_hw_params_fixup = mt8183_i2s_hw_params_fixup, |
| 438 | .ops = &mt8183_mt6358_tdm_ops, |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 439 | SND_SOC_DAILINK_REG(tdm), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 440 | }, |
| 441 | }; |
| 442 | |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 443 | static struct snd_soc_card mt8183_mt6358_ts3a227_max98357_card = { |
| 444 | .name = "mt8183_mt6358_ts3a227_max98357", |
| 445 | .owner = THIS_MODULE, |
| 446 | .dai_link = mt8183_mt6358_ts3a227_max98357_dai_links, |
| 447 | .num_links = ARRAY_SIZE(mt8183_mt6358_ts3a227_max98357_dai_links), |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 448 | }; |
| 449 | |
| 450 | static int |
| 451 | mt8183_mt6358_ts3a227_max98357_headset_init(struct snd_soc_component *component) |
| 452 | { |
| 453 | int ret; |
Tzung-Bi Shih | 95d779b | 2019-08-30 15:42:38 +0800 | [diff] [blame] | 454 | struct mt8183_mt6358_ts3a227_max98357_priv *priv = |
| 455 | snd_soc_card_get_drvdata(component->card); |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 456 | |
| 457 | /* Enable Headset and 4 Buttons Jack detection */ |
| 458 | ret = snd_soc_card_jack_new(&mt8183_mt6358_ts3a227_max98357_card, |
| 459 | "Headset Jack", |
| 460 | SND_JACK_HEADSET | |
| 461 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | |
| 462 | SND_JACK_BTN_2 | SND_JACK_BTN_3, |
Tzung-Bi Shih | 95d779b | 2019-08-30 15:42:38 +0800 | [diff] [blame] | 463 | &priv->headset_jack, |
Tzung-Bi Shih | 108d0d4 | 2019-05-22 22:55:05 +0800 | [diff] [blame] | 464 | NULL, 0); |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 465 | if (ret) |
| 466 | return ret; |
| 467 | |
Tzung-Bi Shih | 95d779b | 2019-08-30 15:42:38 +0800 | [diff] [blame] | 468 | ret = ts3a227e_enable_jack_detect(component, &priv->headset_jack); |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 469 | |
| 470 | return ret; |
| 471 | } |
| 472 | |
Tzung-Bi Shih | fc34748 | 2019-08-30 15:42:39 +0800 | [diff] [blame] | 473 | static struct snd_soc_aux_dev mt8183_mt6358_ts3a227_max98357_headset_dev = { |
| 474 | .dlc = COMP_EMPTY(), |
| 475 | .init = mt8183_mt6358_ts3a227_max98357_headset_init, |
| 476 | }; |
| 477 | |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 478 | static int |
| 479 | mt8183_mt6358_ts3a227_max98357_dev_probe(struct platform_device *pdev) |
| 480 | { |
| 481 | struct snd_soc_card *card = &mt8183_mt6358_ts3a227_max98357_card; |
Tzung-Bi Shih | 2cc3cd5 | 2019-10-19 15:02:54 +0800 | [diff] [blame] | 482 | struct device_node *platform_node, *ec_codec; |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 483 | struct snd_soc_dai_link *dai_link; |
Jiaxin Yu | 6191cbd | 2019-08-22 20:51:00 +0800 | [diff] [blame] | 484 | struct mt8183_mt6358_ts3a227_max98357_priv *priv; |
| 485 | int ret; |
Tzung-Bi Shih | 63ba8e4 | 2019-05-22 22:54:02 +0800 | [diff] [blame] | 486 | int i; |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 487 | |
| 488 | card->dev = &pdev->dev; |
| 489 | |
| 490 | platform_node = of_parse_phandle(pdev->dev.of_node, |
| 491 | "mediatek,platform", 0); |
| 492 | if (!platform_node) { |
| 493 | dev_err(&pdev->dev, "Property 'platform' missing or invalid\n"); |
| 494 | return -EINVAL; |
| 495 | } |
| 496 | |
Tzung-Bi Shih | 2cc3cd5 | 2019-10-19 15:02:54 +0800 | [diff] [blame] | 497 | ec_codec = of_parse_phandle(pdev->dev.of_node, "mediatek,ec-codec", 0); |
| 498 | |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 499 | for_each_card_prelinks(card, i, dai_link) { |
Kuninori Morimoto | fa284fd | 2019-06-06 13:08:49 +0900 | [diff] [blame] | 500 | if (dai_link->platforms->name) |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 501 | continue; |
Tzung-Bi Shih | 2cc3cd5 | 2019-10-19 15:02:54 +0800 | [diff] [blame] | 502 | |
| 503 | if (ec_codec && strcmp(dai_link->name, "Wake on Voice") == 0) { |
| 504 | dai_link->cpus[0].name = NULL; |
| 505 | dai_link->cpus[0].of_node = ec_codec; |
| 506 | dai_link->cpus[0].dai_name = NULL; |
| 507 | dai_link->codecs[0].name = NULL; |
| 508 | dai_link->codecs[0].of_node = ec_codec; |
| 509 | dai_link->codecs[0].dai_name = "Wake on Voice"; |
| 510 | dai_link->platforms[0].of_node = ec_codec; |
| 511 | dai_link->ignore = 0; |
| 512 | } else { |
| 513 | dai_link->platforms->of_node = platform_node; |
| 514 | } |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 515 | } |
| 516 | |
Kuninori Morimoto | b812cd5 | 2019-08-08 14:53:52 +0900 | [diff] [blame] | 517 | mt8183_mt6358_ts3a227_max98357_headset_dev.dlc.of_node = |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 518 | of_parse_phandle(pdev->dev.of_node, |
| 519 | "mediatek,headset-codec", 0); |
Kuninori Morimoto | b812cd5 | 2019-08-08 14:53:52 +0900 | [diff] [blame] | 520 | if (mt8183_mt6358_ts3a227_max98357_headset_dev.dlc.of_node) { |
Tzung-Bi Shih | a962a809 | 2019-07-16 11:24:17 +0800 | [diff] [blame] | 521 | card->aux_dev = &mt8183_mt6358_ts3a227_max98357_headset_dev; |
| 522 | card->num_aux_devs = 1; |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 523 | } |
| 524 | |
Jiaxin Yu | 6191cbd | 2019-08-22 20:51:00 +0800 | [diff] [blame] | 525 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
| 526 | if (!priv) |
| 527 | return -ENOMEM; |
| 528 | |
| 529 | snd_soc_card_set_drvdata(card, priv); |
| 530 | |
| 531 | priv->pinctrl = devm_pinctrl_get(&pdev->dev); |
| 532 | if (IS_ERR(priv->pinctrl)) { |
| 533 | dev_err(&pdev->dev, "%s devm_pinctrl_get failed\n", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 534 | __func__); |
Jiaxin Yu | 6191cbd | 2019-08-22 20:51:00 +0800 | [diff] [blame] | 535 | return PTR_ERR(priv->pinctrl); |
| 536 | } |
| 537 | |
Tzung-Bi Shih | e5b3ae3 | 2019-08-30 15:42:40 +0800 | [diff] [blame] | 538 | for (i = 0; i < PIN_STATE_MAX; i++) { |
Jiaxin Yu | 6191cbd | 2019-08-22 20:51:00 +0800 | [diff] [blame] | 539 | priv->pin_states[i] = pinctrl_lookup_state(priv->pinctrl, |
| 540 | mt8183_pin_str[i]); |
| 541 | if (IS_ERR(priv->pin_states[i])) { |
| 542 | ret = PTR_ERR(priv->pin_states[i]); |
| 543 | dev_info(&pdev->dev, "%s Can't find pin state %s %d\n", |
| 544 | __func__, mt8183_pin_str[i], ret); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | if (!IS_ERR(priv->pin_states[PIN_TDM_OUT_OFF])) { |
| 549 | ret = pinctrl_select_state(priv->pinctrl, |
| 550 | priv->pin_states[PIN_TDM_OUT_OFF]); |
| 551 | if (ret) |
| 552 | dev_info(&pdev->dev, |
| 553 | "%s failed to select state %d\n", |
| 554 | __func__, ret); |
| 555 | } |
| 556 | |
| 557 | if (!IS_ERR(priv->pin_states[PIN_STATE_DEFAULT])) { |
| 558 | ret = pinctrl_select_state(priv->pinctrl, |
| 559 | priv->pin_states[PIN_STATE_DEFAULT]); |
| 560 | if (ret) |
| 561 | dev_info(&pdev->dev, |
| 562 | "%s failed to select state %d\n", |
| 563 | __func__, ret); |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 564 | } |
| 565 | |
Tzung-Bi Shih | 63ba8e4 | 2019-05-22 22:54:02 +0800 | [diff] [blame] | 566 | return devm_snd_soc_register_card(&pdev->dev, card); |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | #ifdef CONFIG_OF |
| 570 | static const struct of_device_id mt8183_mt6358_ts3a227_max98357_dt_match[] = { |
| 571 | {.compatible = "mediatek,mt8183_mt6358_ts3a227_max98357",}, |
| 572 | {} |
| 573 | }; |
| 574 | #endif |
| 575 | |
| 576 | static struct platform_driver mt8183_mt6358_ts3a227_max98357_driver = { |
| 577 | .driver = { |
| 578 | .name = "mt8183_mt6358_ts3a227_max98357", |
Shunli Wang | 11c0269 | 2019-03-29 16:34:46 +0800 | [diff] [blame] | 579 | #ifdef CONFIG_OF |
| 580 | .of_match_table = mt8183_mt6358_ts3a227_max98357_dt_match, |
| 581 | #endif |
| 582 | }, |
| 583 | .probe = mt8183_mt6358_ts3a227_max98357_dev_probe, |
| 584 | }; |
| 585 | |
| 586 | module_platform_driver(mt8183_mt6358_ts3a227_max98357_driver); |
| 587 | |
| 588 | /* Module information */ |
| 589 | MODULE_DESCRIPTION("MT8183-MT6358-TS3A227-MAX98357 ALSA SoC machine driver"); |
| 590 | MODULE_AUTHOR("Shunli Wang <shunli.wang@mediatek.com>"); |
| 591 | MODULE_LICENSE("GPL v2"); |
| 592 | MODULE_ALIAS("mt8183_mt6358_ts3a227_max98357 soc card"); |