| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* mt8188-mt6359.c -- MT8188-MT6359 ALSA SoC machine driver |
| 4 |
* |
| 5 |
* Copyright (c) 2022 MediaTek Inc. |
| 6 |
* Author: Trevor Wu <[email protected]> |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <linux/bitfield.h> |
| 10 |
#include <linux/input.h> |
| 11 |
#include <linux/module.h> |
| 12 |
#include <linux/of.h> |
| 13 |
#include <linux/pm_runtime.h> |
| 14 |
#include <sound/jack.h> |
| 15 |
#include <sound/pcm_params.h> |
| 16 |
#include <sound/soc.h> |
| 17 |
#include "mt8188-afe-common.h" |
| 18 |
#include "../../codecs/nau8825.h" |
| 19 |
#include "../../codecs/mt6359.h" |
| 20 |
#include "../../codecs/mt6359-accdet.h" |
| 21 |
#include "../../codecs/rt5682.h" |
| 22 |
#include "../common/mtk-afe-platform-driver.h" |
| 23 |
#include "../common/mtk-soundcard-driver.h" |
| 24 |
#include "../common/mtk-dsp-sof-common.h" |
| 25 |
#include "../common/mtk-soc-card.h" |
| 26 |
|
| 27 |
#define CKSYS_AUD_TOP_CFG 0x032c |
| 28 |
#define RG_TEST_ON BIT(0) |
| 29 |
#define RG_TEST_TYPE BIT(2) |
| 30 |
#define CKSYS_AUD_TOP_MON 0x0330 |
| 31 |
#define TEST_MISO_COUNT_1 GENMASK(3, 0) |
| 32 |
#define TEST_MISO_COUNT_2 GENMASK(7, 4) |
| 33 |
#define TEST_MISO_DONE_1 BIT(28) |
| 34 |
#define TEST_MISO_DONE_2 BIT(29) |
| 35 |
|
| 36 |
#define NAU8825_HS_PRESENT BIT(0) |
| 37 |
#define RT5682S_HS_PRESENT BIT(1) |
| 38 |
#define ES8326_HS_PRESENT BIT(2) |
| 39 |
#define MAX98390_TWO_AMP BIT(3) |
| 40 |
/* |
| 41 |
* Maxim MAX98390 |
| 42 |
*/ |
| 43 |
#define MAX98390_CODEC_DAI "max98390-aif1" |
| 44 |
#define MAX98390_DEV0_NAME "max98390.0-0038" /* rear right */ |
| 45 |
#define MAX98390_DEV1_NAME "max98390.0-0039" /* rear left */ |
| 46 |
#define MAX98390_DEV2_NAME "max98390.0-003a" /* front right */ |
| 47 |
#define MAX98390_DEV3_NAME "max98390.0-003b" /* front left */ |
| 48 |
|
| 49 |
/* |
| 50 |
* Nau88l25 |
| 51 |
*/ |
| 52 |
#define NAU8825_CODEC_DAI "nau8825-hifi" |
| 53 |
|
| 54 |
/* |
| 55 |
* ES8326 |
| 56 |
*/ |
| 57 |
#define ES8326_CODEC_DAI "ES8326 HiFi" |
| 58 |
|
| 59 |
#define SOF_DMA_DL2 "SOF_DMA_DL2" |
| 60 |
#define SOF_DMA_DL3 "SOF_DMA_DL3" |
| 61 |
#define SOF_DMA_UL4 "SOF_DMA_UL4" |
| 62 |
#define SOF_DMA_UL5 "SOF_DMA_UL5" |
| 63 |
|
| 64 |
#define RT5682S_CODEC_DAI "rt5682s-aif1" |
| 65 |
|
| 66 |
/* FE */ |
| 67 |
SND_SOC_DAILINK_DEFS(playback2, |
| 68 |
DAILINK_COMP_ARRAY(COMP_CPU("DL2")), |
| 69 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 70 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 71 |
|
| 72 |
SND_SOC_DAILINK_DEFS(playback3, |
| 73 |
DAILINK_COMP_ARRAY(COMP_CPU("DL3")), |
| 74 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 75 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 76 |
|
| 77 |
SND_SOC_DAILINK_DEFS(playback6, |
| 78 |
DAILINK_COMP_ARRAY(COMP_CPU("DL6")), |
| 79 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 80 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 81 |
|
| 82 |
SND_SOC_DAILINK_DEFS(playback7, |
| 83 |
DAILINK_COMP_ARRAY(COMP_CPU("DL7")), |
| 84 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 85 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 86 |
|
| 87 |
SND_SOC_DAILINK_DEFS(playback8, |
| 88 |
DAILINK_COMP_ARRAY(COMP_CPU("DL8")), |
| 89 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 90 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 91 |
|
| 92 |
SND_SOC_DAILINK_DEFS(playback10, |
| 93 |
DAILINK_COMP_ARRAY(COMP_CPU("DL10")), |
| 94 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 95 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 96 |
|
| 97 |
SND_SOC_DAILINK_DEFS(playback11, |
| 98 |
DAILINK_COMP_ARRAY(COMP_CPU("DL11")), |
| 99 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 100 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 101 |
|
| 102 |
SND_SOC_DAILINK_DEFS(capture1, |
| 103 |
DAILINK_COMP_ARRAY(COMP_CPU("UL1")), |
| 104 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 105 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 106 |
|
| 107 |
SND_SOC_DAILINK_DEFS(capture2, |
| 108 |
DAILINK_COMP_ARRAY(COMP_CPU("UL2")), |
| 109 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 110 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 111 |
|
| 112 |
SND_SOC_DAILINK_DEFS(capture3, |
| 113 |
DAILINK_COMP_ARRAY(COMP_CPU("UL3")), |
| 114 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 115 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 116 |
|
| 117 |
SND_SOC_DAILINK_DEFS(capture4, |
| 118 |
DAILINK_COMP_ARRAY(COMP_CPU("UL4")), |
| 119 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 120 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 121 |
|
| 122 |
SND_SOC_DAILINK_DEFS(capture5, |
| 123 |
DAILINK_COMP_ARRAY(COMP_CPU("UL5")), |
| 124 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 125 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 126 |
|
| 127 |
SND_SOC_DAILINK_DEFS(capture6, |
| 128 |
DAILINK_COMP_ARRAY(COMP_CPU("UL6")), |
| 129 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 130 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 131 |
|
| 132 |
SND_SOC_DAILINK_DEFS(capture8, |
| 133 |
DAILINK_COMP_ARRAY(COMP_CPU("UL8")), |
| 134 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 135 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 136 |
|
| 137 |
SND_SOC_DAILINK_DEFS(capture9, |
| 138 |
DAILINK_COMP_ARRAY(COMP_CPU("UL9")), |
| 139 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 140 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 141 |
|
| 142 |
SND_SOC_DAILINK_DEFS(capture10, |
| 143 |
DAILINK_COMP_ARRAY(COMP_CPU("UL10")), |
| 144 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 145 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 146 |
|
| 147 |
/* BE */ |
| 148 |
SND_SOC_DAILINK_DEFS(dl_src, |
| 149 |
DAILINK_COMP_ARRAY(COMP_CPU("DL_SRC")), |
| 150 |
DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound", |
| 151 |
"mt6359-snd-codec-aif1")), |
| 152 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 153 |
|
| 154 |
SND_SOC_DAILINK_DEFS(DMIC_BE, |
| 155 |
DAILINK_COMP_ARRAY(COMP_CPU("DMIC")), |
| 156 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 157 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 158 |
|
| 159 |
SND_SOC_DAILINK_DEFS(dptx, |
| 160 |
DAILINK_COMP_ARRAY(COMP_CPU("DPTX")), |
| 161 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 162 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 163 |
|
| 164 |
SND_SOC_DAILINK_DEFS(etdm1_in, |
| 165 |
DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_IN")), |
| 166 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 167 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 168 |
|
| 169 |
SND_SOC_DAILINK_DEFS(etdm2_in, |
| 170 |
DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_IN")), |
| 171 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 172 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 173 |
|
| 174 |
SND_SOC_DAILINK_DEFS(etdm1_out, |
| 175 |
DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_OUT")), |
| 176 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 177 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 178 |
|
| 179 |
SND_SOC_DAILINK_DEFS(etdm2_out, |
| 180 |
DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_OUT")), |
| 181 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 182 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 183 |
|
| 184 |
SND_SOC_DAILINK_DEFS(etdm3_out, |
| 185 |
DAILINK_COMP_ARRAY(COMP_CPU("ETDM3_OUT")), |
| 186 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 187 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 188 |
|
| 189 |
SND_SOC_DAILINK_DEFS(pcm1, |
| 190 |
DAILINK_COMP_ARRAY(COMP_CPU("PCM1")), |
| 191 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 192 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 193 |
|
| 194 |
SND_SOC_DAILINK_DEFS(ul_src, |
| 195 |
DAILINK_COMP_ARRAY(COMP_CPU("UL_SRC")), |
| 196 |
DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound", |
| 197 |
"mt6359-snd-codec-aif1")), |
| 198 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 199 |
|
| 200 |
SND_SOC_DAILINK_DEFS(AFE_SOF_DL2, |
| 201 |
DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL2")), |
| 202 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 203 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 204 |
|
| 205 |
SND_SOC_DAILINK_DEFS(AFE_SOF_DL3, |
| 206 |
DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL3")), |
| 207 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 208 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 209 |
|
| 210 |
SND_SOC_DAILINK_DEFS(AFE_SOF_UL4, |
| 211 |
DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL4")), |
| 212 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 213 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 214 |
|
| 215 |
SND_SOC_DAILINK_DEFS(AFE_SOF_UL5, |
| 216 |
DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL5")), |
| 217 |
DAILINK_COMP_ARRAY(COMP_DUMMY()), |
| 218 |
DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 219 |
|
| 220 |
static const struct sof_conn_stream g_sof_conn_streams[] = { |
| 221 |
{ |
| 222 |
.sof_link = "AFE_SOF_DL2", |
| 223 |
.sof_dma = SOF_DMA_DL2, |
| 224 |
.stream_dir = SNDRV_PCM_STREAM_PLAYBACK |
| 225 |
}, |
| 226 |
{ |
| 227 |
.sof_link = "AFE_SOF_DL3", |
| 228 |
.sof_dma = SOF_DMA_DL3, |
| 229 |
.stream_dir = SNDRV_PCM_STREAM_PLAYBACK |
| 230 |
}, |
| 231 |
{ |
| 232 |
.sof_link = "AFE_SOF_UL4", |
| 233 |
.sof_dma = SOF_DMA_UL4, |
| 234 |
.stream_dir = SNDRV_PCM_STREAM_CAPTURE |
| 235 |
}, |
| 236 |
{ |
| 237 |
.sof_link = "AFE_SOF_UL5", |
| 238 |
.sof_dma = SOF_DMA_UL5, |
| 239 |
.stream_dir = SNDRV_PCM_STREAM_CAPTURE |
| 240 |
}, |
| 241 |
}; |
| 242 |
|
| 243 |
enum mt8188_jacks { |
| 244 |
MT8188_JACK_HEADSET, |
| 245 |
MT8188_JACK_DP, |
| 246 |
MT8188_JACK_HDMI, |
| 247 |
MT8188_JACK_MAX, |
| 248 |
}; |
| 249 |
|
| 250 |
static struct snd_soc_jack_pin mt8188_hdmi_jack_pins[] = { |
| 251 |
{ |
| 252 |
.pin = "HDMI", |
| 253 |
.mask = SND_JACK_AVOUT, |
| 254 |
}, |
| 255 |
}; |
| 256 |
|
| 257 |
static struct snd_soc_jack_pin mt8188_dp_jack_pins[] = { |
| 258 |
{ |
| 259 |
.pin = "DP", |
| 260 |
.mask = SND_JACK_AVOUT, |
| 261 |
}, |
| 262 |
}; |
| 263 |
|
| 264 |
static struct snd_soc_jack_pin nau8825_jack_pins[] = { |
| 265 |
{ |
| 266 |
.pin = "Headphone Jack", |
| 267 |
.mask = SND_JACK_HEADPHONE, |
| 268 |
}, |
| 269 |
{ |
| 270 |
.pin = "Headset Mic", |
| 271 |
.mask = SND_JACK_MICROPHONE, |
| 272 |
}, |
| 273 |
}; |
| 274 |
|
| 275 |
static struct snd_soc_jack_pin mt8188_headset_jack_pins[] = { |
| 276 |
{ |
| 277 |
.pin = "Headphone", |
| 278 |
.mask = SND_JACK_HEADPHONE, |
| 279 |
}, |
| 280 |
{ |
| 281 |
.pin = "Headset Mic", |
| 282 |
.mask = SND_JACK_MICROPHONE, |
| 283 |
}, |
| 284 |
}; |
| 285 |
|
| 286 |
static const struct snd_kcontrol_new mt8188_dumb_spk_controls[] = { |
| 287 |
SOC_DAPM_PIN_SWITCH("Ext Spk"), |
| 288 |
}; |
| 289 |
|
| 290 |
static const struct snd_soc_dapm_widget mt8188_dumb_spk_widgets[] = { |
| 291 |
SND_SOC_DAPM_SPK("Ext Spk", NULL), |
| 292 |
}; |
| 293 |
|
| 294 |
static const struct snd_kcontrol_new mt8188_dual_spk_controls[] = { |
| 295 |
SOC_DAPM_PIN_SWITCH("Left Spk"), |
| 296 |
SOC_DAPM_PIN_SWITCH("Right Spk"), |
| 297 |
}; |
| 298 |
|
| 299 |
static const struct snd_soc_dapm_widget mt8188_dual_spk_widgets[] = { |
| 300 |
SND_SOC_DAPM_SPK("Left Spk", NULL), |
| 301 |
SND_SOC_DAPM_SPK("Right Spk", NULL), |
| 302 |
}; |
| 303 |
|
| 304 |
static const struct snd_kcontrol_new mt8188_rear_spk_controls[] = { |
| 305 |
SOC_DAPM_PIN_SWITCH("Rear Left Spk"), |
| 306 |
SOC_DAPM_PIN_SWITCH("Rear Right Spk"), |
| 307 |
}; |
| 308 |
|
| 309 |
static const struct snd_soc_dapm_widget mt8188_rear_spk_widgets[] = { |
| 310 |
SND_SOC_DAPM_SPK("Rear Left Spk", NULL), |
| 311 |
SND_SOC_DAPM_SPK("Rear Right Spk", NULL), |
| 312 |
}; |
| 313 |
|
| 314 |
static const struct snd_soc_dapm_widget mt8188_mt6359_widgets[] = { |
| 315 |
SND_SOC_DAPM_HP("Headphone", NULL), |
| 316 |
SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 317 |
SND_SOC_DAPM_MIC("AP DMIC", NULL), |
| 318 |
SND_SOC_DAPM_SINK("HDMI"), |
| 319 |
SND_SOC_DAPM_SINK("DP"), |
| 320 |
SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0), |
| 321 |
SND_SOC_DAPM_MIXER(SOF_DMA_DL3, SND_SOC_NOPM, 0, 0, NULL, 0), |
| 322 |
SND_SOC_DAPM_MIXER(SOF_DMA_UL4, SND_SOC_NOPM, 0, 0, NULL, 0), |
| 323 |
SND_SOC_DAPM_MIXER(SOF_DMA_UL5, SND_SOC_NOPM, 0, 0, NULL, 0), |
| 324 |
|
| 325 |
/* dynamic pinctrl */ |
| 326 |
SND_SOC_DAPM_PINCTRL("ETDM_SPK_PIN", "aud_etdm_spk_on", "aud_etdm_spk_off"), |
| 327 |
SND_SOC_DAPM_PINCTRL("ETDM_HP_PIN", "aud_etdm_hp_on", "aud_etdm_hp_off"), |
| 328 |
SND_SOC_DAPM_PINCTRL("MTKAIF_PIN", "aud_mtkaif_on", "aud_mtkaif_off"), |
| 329 |
}; |
| 330 |
|
| 331 |
static const struct snd_kcontrol_new mt8188_mt6359_controls[] = { |
| 332 |
SOC_DAPM_PIN_SWITCH("Headphone"), |
| 333 |
SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 334 |
}; |
| 335 |
|
| 336 |
static const struct snd_soc_dapm_widget mt8188_nau8825_widgets[] = { |
| 337 |
SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 338 |
}; |
| 339 |
|
| 340 |
static const struct snd_kcontrol_new mt8188_nau8825_controls[] = { |
| 341 |
SOC_DAPM_PIN_SWITCH("Headphone Jack"), |
| 342 |
}; |
| 343 |
|
| 344 |
static const struct snd_soc_dapm_route mt8188_mt6359_routes[] = { |
| 345 |
/* SOF Uplink */ |
| 346 |
{SOF_DMA_UL4, NULL, "O034"}, |
| 347 |
{SOF_DMA_UL4, NULL, "O035"}, |
| 348 |
{SOF_DMA_UL5, NULL, "O036"}, |
| 349 |
{SOF_DMA_UL5, NULL, "O037"}, |
| 350 |
/* SOF Downlink */ |
| 351 |
{"I070", NULL, SOF_DMA_DL2}, |
| 352 |
{"I071", NULL, SOF_DMA_DL2}, |
| 353 |
{"I020", NULL, SOF_DMA_DL3}, |
| 354 |
{"I021", NULL, SOF_DMA_DL3}, |
| 355 |
}; |
| 356 |
|
| 357 |
static int mt8188_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd) |
| 358 |
{ |
| 359 |
struct snd_soc_component *cmpnt_afe = |
| 360 |
snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); |
| 361 |
struct snd_soc_component *cmpnt_codec = |
| 362 |
snd_soc_rtd_to_codec(rtd, 0)->component; |
| 363 |
struct snd_soc_dapm_widget *pin_w = NULL, *w; |
| 364 |
struct mtk_base_afe *afe; |
| 365 |
struct mt8188_afe_private *afe_priv; |
| 366 |
struct mtkaif_param *param; |
| 367 |
int chosen_phase_1, chosen_phase_2; |
| 368 |
int prev_cycle_1, prev_cycle_2; |
| 369 |
u8 test_done_1, test_done_2; |
| 370 |
int cycle_1, cycle_2; |
| 371 |
int mtkaif_chosen_phase[MT8188_MTKAIF_MISO_NUM]; |
| 372 |
int mtkaif_phase_cycle[MT8188_MTKAIF_MISO_NUM]; |
| 373 |
int mtkaif_calibration_num_phase; |
| 374 |
bool mtkaif_calibration_ok; |
| 375 |
u32 monitor = 0; |
| 376 |
int counter; |
| 377 |
int phase; |
| 378 |
int i; |
| 379 |
|
| 380 |
if (!cmpnt_afe) |
| 381 |
return -EINVAL; |
| 382 |
|
| 383 |
afe = snd_soc_component_get_drvdata(cmpnt_afe); |
| 384 |
afe_priv = afe->platform_priv; |
| 385 |
param = &afe_priv->mtkaif_params; |
| 386 |
|
| 387 |
dev_dbg(afe->dev, "%s(), start\n", __func__); |
| 388 |
|
| 389 |
param->mtkaif_calibration_ok = false; |
| 390 |
for (i = 0; i < MT8188_MTKAIF_MISO_NUM; i++) { |
| 391 |
param->mtkaif_chosen_phase[i] = -1; |
| 392 |
param->mtkaif_phase_cycle[i] = 0; |
| 393 |
mtkaif_chosen_phase[i] = -1; |
| 394 |
mtkaif_phase_cycle[i] = 0; |
| 395 |
} |
| 396 |
|
| 397 |
if (IS_ERR(afe_priv->topckgen)) { |
| 398 |
dev_info(afe->dev, "%s() Cannot find topckgen controller\n", |
| 399 |
__func__); |
| 400 |
return 0; |
| 401 |
} |
| 402 |
|
| 403 |
for_each_card_widgets(rtd->card, w) { |
| 404 |
if (!strcmp(w->name, "MTKAIF_PIN")) { |
| 405 |
pin_w = w; |
| 406 |
break; |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
if (pin_w) |
| 411 |
snd_soc_dapm_pinctrl_event(pin_w, NULL, SND_SOC_DAPM_PRE_PMU); |
| 412 |
else |
| 413 |
dev_dbg(afe->dev, "%s(), no pinmux widget, please check if default on\n", __func__); |
| 414 |
|
| 415 |
pm_runtime_get_sync(afe->dev); |
| 416 |
mt6359_mtkaif_calibration_enable(cmpnt_codec); |
| 417 |
|
| 418 |
/* set test type to synchronizer pulse */ |
| 419 |
regmap_write(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, RG_TEST_TYPE); |
| 420 |
mtkaif_calibration_num_phase = 42; /* mt6359: 0 ~ 42 */ |
| 421 |
mtkaif_calibration_ok = true; |
| 422 |
|
| 423 |
for (phase = 0; |
| 424 |
phase <= mtkaif_calibration_num_phase && mtkaif_calibration_ok; |
| 425 |
phase++) { |
| 426 |
mt6359_set_mtkaif_calibration_phase(cmpnt_codec, |
| 427 |
phase, phase, phase); |
| 428 |
|
| 429 |
regmap_set_bits(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, RG_TEST_ON); |
| 430 |
|
| 431 |
test_done_1 = 0; |
| 432 |
test_done_2 = 0; |
| 433 |
|
| 434 |
cycle_1 = -1; |
| 435 |
cycle_2 = -1; |
| 436 |
|
| 437 |
counter = 0; |
| 438 |
while (!(test_done_1 & test_done_2)) { |
| 439 |
regmap_read(afe_priv->topckgen, |
| 440 |
CKSYS_AUD_TOP_MON, &monitor); |
| 441 |
test_done_1 = FIELD_GET(TEST_MISO_DONE_1, monitor); |
| 442 |
test_done_2 = FIELD_GET(TEST_MISO_DONE_2, monitor); |
| 443 |
|
| 444 |
if (test_done_1 == 1) |
| 445 |
cycle_1 = FIELD_GET(TEST_MISO_COUNT_1, monitor); |
| 446 |
|
| 447 |
if (test_done_2 == 1) |
| 448 |
cycle_2 = FIELD_GET(TEST_MISO_COUNT_2, monitor); |
| 449 |
|
| 450 |
/* handle if never test done */ |
| 451 |
if (++counter > 10000) { |
| 452 |
dev_err(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, monitor 0x%x\n", |
| 453 |
__func__, cycle_1, cycle_2, monitor); |
| 454 |
mtkaif_calibration_ok = false; |
| 455 |
break; |
| 456 |
} |
| 457 |
} |
| 458 |
|
| 459 |
if (phase == 0) { |
| 460 |
prev_cycle_1 = cycle_1; |
| 461 |
prev_cycle_2 = cycle_2; |
| 462 |
} |
| 463 |
|
| 464 |
if (cycle_1 != prev_cycle_1 && |
| 465 |
mtkaif_chosen_phase[MT8188_MTKAIF_MISO_0] < 0) { |
| 466 |
mtkaif_chosen_phase[MT8188_MTKAIF_MISO_0] = phase - 1; |
| 467 |
mtkaif_phase_cycle[MT8188_MTKAIF_MISO_0] = prev_cycle_1; |
| 468 |
} |
| 469 |
|
| 470 |
if (cycle_2 != prev_cycle_2 && |
| 471 |
mtkaif_chosen_phase[MT8188_MTKAIF_MISO_1] < 0) { |
| 472 |
mtkaif_chosen_phase[MT8188_MTKAIF_MISO_1] = phase - 1; |
| 473 |
mtkaif_phase_cycle[MT8188_MTKAIF_MISO_1] = prev_cycle_2; |
| 474 |
} |
| 475 |
|
| 476 |
regmap_clear_bits(afe_priv->topckgen, CKSYS_AUD_TOP_CFG, RG_TEST_ON); |
| 477 |
|
| 478 |
if (mtkaif_chosen_phase[MT8188_MTKAIF_MISO_0] >= 0 && |
| 479 |
mtkaif_chosen_phase[MT8188_MTKAIF_MISO_1] >= 0) |
| 480 |
break; |
| 481 |
} |
| 482 |
|
| 483 |
if (mtkaif_chosen_phase[MT8188_MTKAIF_MISO_0] < 0) { |
| 484 |
mtkaif_calibration_ok = false; |
| 485 |
chosen_phase_1 = 0; |
| 486 |
} else { |
| 487 |
chosen_phase_1 = mtkaif_chosen_phase[MT8188_MTKAIF_MISO_0]; |
| 488 |
} |
| 489 |
|
| 490 |
if (mtkaif_chosen_phase[MT8188_MTKAIF_MISO_1] < 0) { |
| 491 |
mtkaif_calibration_ok = false; |
| 492 |
chosen_phase_2 = 0; |
| 493 |
} else { |
| 494 |
chosen_phase_2 = mtkaif_chosen_phase[MT8188_MTKAIF_MISO_1]; |
| 495 |
} |
| 496 |
|
| 497 |
mt6359_set_mtkaif_calibration_phase(cmpnt_codec, |
| 498 |
chosen_phase_1, |
| 499 |
chosen_phase_2, |
| 500 |
0); |
| 501 |
|
| 502 |
mt6359_mtkaif_calibration_disable(cmpnt_codec); |
| 503 |
pm_runtime_put(afe->dev); |
| 504 |
|
| 505 |
param->mtkaif_calibration_ok = mtkaif_calibration_ok; |
| 506 |
param->mtkaif_chosen_phase[MT8188_MTKAIF_MISO_0] = chosen_phase_1; |
| 507 |
param->mtkaif_chosen_phase[MT8188_MTKAIF_MISO_1] = chosen_phase_2; |
| 508 |
|
| 509 |
for (i = 0; i < MT8188_MTKAIF_MISO_NUM; i++) |
| 510 |
param->mtkaif_phase_cycle[i] = mtkaif_phase_cycle[i]; |
| 511 |
|
| 512 |
if (pin_w) |
| 513 |
snd_soc_dapm_pinctrl_event(pin_w, NULL, SND_SOC_DAPM_POST_PMD); |
| 514 |
|
| 515 |
dev_dbg(afe->dev, "%s(), end, calibration ok %d\n", |
| 516 |
__func__, param->mtkaif_calibration_ok); |
| 517 |
|
| 518 |
return 0; |
| 519 |
} |
| 520 |
|
| 521 |
static int mt8188_mt6359_accdet_init(struct snd_soc_pcm_runtime *rtd) |
| 522 |
{ |
| 523 |
struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); |
| 524 |
struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HEADSET]; |
| 525 |
int ret; |
| 526 |
|
| 527 |
if (!soc_card_data->accdet) |
| 528 |
return 0; |
| 529 |
|
| 530 |
ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", |
| 531 |
SND_JACK_HEADSET | SND_JACK_BTN_0 | |
| 532 |
SND_JACK_BTN_1 | SND_JACK_BTN_2 | |
| 533 |
SND_JACK_BTN_3, |
| 534 |
jack, mt8188_headset_jack_pins, |
| 535 |
ARRAY_SIZE(mt8188_headset_jack_pins)); |
| 536 |
if (ret) { |
| 537 |
dev_err(rtd->dev, "Headset Jack create failed: %d\n", ret); |
| 538 |
return ret; |
| 539 |
} |
| 540 |
|
| 541 |
ret = mt6359_accdet_enable_jack_detect(soc_card_data->accdet, jack); |
| 542 |
if (ret) { |
| 543 |
dev_err(rtd->dev, "Headset Jack enable failed: %d\n", ret); |
| 544 |
return ret; |
| 545 |
} |
| 546 |
|
| 547 |
return 0; |
| 548 |
} |
| 549 |
|
| 550 |
static int mt8188_mt6359_init(struct snd_soc_pcm_runtime *rtd) |
| 551 |
{ |
| 552 |
struct snd_soc_component *cmpnt_codec = |
| 553 |
snd_soc_rtd_to_codec(rtd, 0)->component; |
| 554 |
|
| 555 |
/* set mtkaif protocol */ |
| 556 |
mt6359_set_mtkaif_protocol(cmpnt_codec, |
| 557 |
MT6359_MTKAIF_PROTOCOL_2_CLK_P2); |
| 558 |
|
| 559 |
/* mtkaif calibration */ |
| 560 |
mt8188_mt6359_mtkaif_calibration(rtd); |
| 561 |
|
| 562 |
mt8188_mt6359_accdet_init(rtd); |
| 563 |
|
| 564 |
return 0; |
| 565 |
} |
| 566 |
|
| 567 |
enum { |
| 568 |
DAI_LINK_DL2_FE, |
| 569 |
DAI_LINK_DL3_FE, |
| 570 |
DAI_LINK_DL6_FE, |
| 571 |
DAI_LINK_DL7_FE, |
| 572 |
DAI_LINK_DL8_FE, |
| 573 |
DAI_LINK_DL10_FE, |
| 574 |
DAI_LINK_DL11_FE, |
| 575 |
DAI_LINK_UL1_FE, |
| 576 |
DAI_LINK_UL2_FE, |
| 577 |
DAI_LINK_UL3_FE, |
| 578 |
DAI_LINK_UL4_FE, |
| 579 |
DAI_LINK_UL5_FE, |
| 580 |
DAI_LINK_UL6_FE, |
| 581 |
DAI_LINK_UL8_FE, |
| 582 |
DAI_LINK_UL9_FE, |
| 583 |
DAI_LINK_UL10_FE, |
| 584 |
DAI_LINK_DL_SRC_BE, |
| 585 |
DAI_LINK_DMIC_BE, |
| 586 |
DAI_LINK_DPTX_BE, |
| 587 |
DAI_LINK_ETDM1_IN_BE, |
| 588 |
DAI_LINK_ETDM2_IN_BE, |
| 589 |
DAI_LINK_ETDM1_OUT_BE, |
| 590 |
DAI_LINK_ETDM2_OUT_BE, |
| 591 |
DAI_LINK_ETDM3_OUT_BE, |
| 592 |
DAI_LINK_PCM1_BE, |
| 593 |
DAI_LINK_UL_SRC_BE, |
| 594 |
DAI_LINK_REGULAR_LAST = DAI_LINK_UL_SRC_BE, |
| 595 |
DAI_LINK_SOF_START, |
| 596 |
DAI_LINK_SOF_DL2_BE = DAI_LINK_SOF_START, |
| 597 |
DAI_LINK_SOF_DL3_BE, |
| 598 |
DAI_LINK_SOF_UL4_BE, |
| 599 |
DAI_LINK_SOF_UL5_BE, |
| 600 |
DAI_LINK_SOF_END = DAI_LINK_SOF_UL5_BE, |
| 601 |
}; |
| 602 |
|
| 603 |
#define DAI_LINK_REGULAR_NUM (DAI_LINK_REGULAR_LAST + 1) |
| 604 |
|
| 605 |
static int mt8188_dptx_hw_params(struct snd_pcm_substream *substream, |
| 606 |
struct snd_pcm_hw_params *params) |
| 607 |
{ |
| 608 |
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
| 609 |
unsigned int rate = params_rate(params); |
| 610 |
unsigned int mclk_fs_ratio = 256; |
| 611 |
unsigned int mclk_fs = rate * mclk_fs_ratio; |
| 612 |
struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0); |
| 613 |
|
| 614 |
return snd_soc_dai_set_sysclk(dai, 0, mclk_fs, SND_SOC_CLOCK_OUT); |
| 615 |
} |
| 616 |
|
| 617 |
static const struct snd_soc_ops mt8188_dptx_ops = { |
| 618 |
.hw_params = mt8188_dptx_hw_params, |
| 619 |
}; |
| 620 |
|
| 621 |
static int mt8188_dptx_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, |
| 622 |
struct snd_pcm_hw_params *params) |
| 623 |
{ |
| 624 |
/* fix BE i2s format to 32bit, clean param mask first */ |
| 625 |
snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), |
| 626 |
0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); |
| 627 |
|
| 628 |
params_set_format(params, SNDRV_PCM_FORMAT_S32_LE); |
| 629 |
|
| 630 |
return 0; |
| 631 |
} |
| 632 |
|
| 633 |
static int mt8188_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd) |
| 634 |
{ |
| 635 |
struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); |
| 636 |
struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HDMI]; |
| 637 |
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; |
| 638 |
int ret = 0; |
| 639 |
|
| 640 |
ret = snd_soc_card_jack_new_pins(rtd->card, "HDMI Jack", |
| 641 |
SND_JACK_AVOUT, jack, |
| 642 |
mt8188_hdmi_jack_pins, |
| 643 |
ARRAY_SIZE(mt8188_hdmi_jack_pins)); |
| 644 |
if (ret) { |
| 645 |
dev_err(rtd->dev, "%s, new jack failed: %d\n", __func__, ret); |
| 646 |
return ret; |
| 647 |
} |
| 648 |
|
| 649 |
ret = snd_soc_component_set_jack(component, jack, NULL); |
| 650 |
if (ret) { |
| 651 |
dev_err(rtd->dev, "%s, set jack failed on %s (ret=%d)\n", |
| 652 |
__func__, component->name, ret); |
| 653 |
return ret; |
| 654 |
} |
| 655 |
|
| 656 |
return 0; |
| 657 |
} |
| 658 |
|
| 659 |
static int mt8188_dptx_codec_init(struct snd_soc_pcm_runtime *rtd) |
| 660 |
{ |
| 661 |
struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); |
| 662 |
struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_DP]; |
| 663 |
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; |
| 664 |
int ret = 0; |
| 665 |
|
| 666 |
ret = snd_soc_card_jack_new_pins(rtd->card, "DP Jack", SND_JACK_AVOUT, |
| 667 |
jack, mt8188_dp_jack_pins, |
| 668 |
ARRAY_SIZE(mt8188_dp_jack_pins)); |
| 669 |
if (ret) { |
| 670 |
dev_err(rtd->dev, "%s, new jack failed: %d\n", __func__, ret); |
| 671 |
return ret; |
| 672 |
} |
| 673 |
|
| 674 |
ret = snd_soc_component_set_jack(component, jack, NULL); |
| 675 |
if (ret) { |
| 676 |
dev_err(rtd->dev, "%s, set jack failed on %s (ret=%d)\n", |
| 677 |
__func__, component->name, ret); |
| 678 |
return ret; |
| 679 |
} |
| 680 |
|
| 681 |
return 0; |
| 682 |
} |
| 683 |
|
| 684 |
static int mt8188_dumb_amp_init(struct snd_soc_pcm_runtime *rtd) |
| 685 |
{ |
| 686 |
struct snd_soc_card *card = rtd->card; |
| 687 |
struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card); |
| 688 |
int ret = 0; |
| 689 |
|
| 690 |
ret = snd_soc_dapm_new_controls(dapm, mt8188_dumb_spk_widgets, |
| 691 |
ARRAY_SIZE(mt8188_dumb_spk_widgets)); |
| 692 |
if (ret) { |
| 693 |
dev_err(rtd->dev, "unable to add Dumb Speaker dapm, ret %d\n", ret); |
| 694 |
return ret; |
| 695 |
} |
| 696 |
|
| 697 |
ret = snd_soc_add_card_controls(card, mt8188_dumb_spk_controls, |
| 698 |
ARRAY_SIZE(mt8188_dumb_spk_controls)); |
| 699 |
if (ret) { |
| 700 |
dev_err(rtd->dev, "unable to add Dumb card controls, ret %d\n", ret); |
| 701 |
return ret; |
| 702 |
} |
| 703 |
|
| 704 |
return 0; |
| 705 |
} |
| 706 |
|
| 707 |
static int mt8188_max98390_hw_params(struct snd_pcm_substream *substream, |
| 708 |
struct snd_pcm_hw_params *params) |
| 709 |
{ |
| 710 |
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
| 711 |
unsigned int bit_width = params_width(params); |
| 712 |
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); |
| 713 |
struct snd_soc_dai *codec_dai; |
| 714 |
int i; |
| 715 |
|
| 716 |
snd_soc_dai_set_tdm_slot(cpu_dai, 0xf, 0xf, 4, bit_width); |
| 717 |
|
| 718 |
for_each_rtd_codec_dais(rtd, i, codec_dai) { |
| 719 |
if (!strcmp(codec_dai->component->name, MAX98390_DEV0_NAME)) |
| 720 |
snd_soc_dai_set_tdm_slot(codec_dai, 0x8, 0x3, 4, bit_width); |
| 721 |
|
| 722 |
if (!strcmp(codec_dai->component->name, MAX98390_DEV1_NAME)) |
| 723 |
snd_soc_dai_set_tdm_slot(codec_dai, 0x4, 0x3, 4, bit_width); |
| 724 |
|
| 725 |
if (!strcmp(codec_dai->component->name, MAX98390_DEV2_NAME)) |
| 726 |
snd_soc_dai_set_tdm_slot(codec_dai, 0x2, 0x3, 4, bit_width); |
| 727 |
|
| 728 |
if (!strcmp(codec_dai->component->name, MAX98390_DEV3_NAME)) |
| 729 |
snd_soc_dai_set_tdm_slot(codec_dai, 0x1, 0x3, 4, bit_width); |
| 730 |
} |
| 731 |
return 0; |
| 732 |
} |
| 733 |
|
| 734 |
static const struct snd_soc_ops mt8188_max98390_ops = { |
| 735 |
.hw_params = mt8188_max98390_hw_params, |
| 736 |
}; |
| 737 |
|
| 738 |
static int mt8188_max98390_codec_init(struct snd_soc_pcm_runtime *rtd) |
| 739 |
{ |
| 740 |
struct snd_soc_card *card = rtd->card; |
| 741 |
struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card); |
| 742 |
int ret; |
| 743 |
|
| 744 |
/* add regular speakers dapm route */ |
| 745 |
ret = snd_soc_dapm_new_controls(dapm, mt8188_dual_spk_widgets, |
| 746 |
ARRAY_SIZE(mt8188_dual_spk_widgets)); |
| 747 |
if (ret) { |
| 748 |
dev_err(rtd->dev, "unable to add Left/Right Speaker widget, ret %d\n", ret); |
| 749 |
return ret; |
| 750 |
} |
| 751 |
|
| 752 |
ret = snd_soc_add_card_controls(card, mt8188_dual_spk_controls, |
| 753 |
ARRAY_SIZE(mt8188_dual_spk_controls)); |
| 754 |
if (ret) { |
| 755 |
dev_err(rtd->dev, "unable to add Left/Right card controls, ret %d\n", ret); |
| 756 |
return ret; |
| 757 |
} |
| 758 |
|
| 759 |
if (rtd->dai_link->num_codecs <= 2) |
| 760 |
return 0; |
| 761 |
|
| 762 |
/* add widgets/controls/dapm for rear speakers */ |
| 763 |
ret = snd_soc_dapm_new_controls(dapm, mt8188_rear_spk_widgets, |
| 764 |
ARRAY_SIZE(mt8188_rear_spk_widgets)); |
| 765 |
if (ret) { |
| 766 |
dev_err(rtd->dev, "unable to add Rear Speaker widget, ret %d\n", ret); |
| 767 |
/* Don't need to add routes if widget addition failed */ |
| 768 |
return ret; |
| 769 |
} |
| 770 |
|
| 771 |
ret = snd_soc_add_card_controls(card, mt8188_rear_spk_controls, |
| 772 |
ARRAY_SIZE(mt8188_rear_spk_controls)); |
| 773 |
if (ret) { |
| 774 |
dev_err(rtd->dev, "unable to add Rear card controls, ret %d\n", ret); |
| 775 |
return ret; |
| 776 |
} |
| 777 |
|
| 778 |
return 0; |
| 779 |
} |
| 780 |
|
| 781 |
static int mt8188_headset_codec_init(struct snd_soc_pcm_runtime *rtd) |
| 782 |
{ |
| 783 |
struct snd_soc_card *card = rtd->card; |
| 784 |
struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card); |
| 785 |
struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); |
| 786 |
struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HEADSET]; |
| 787 |
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; |
| 788 |
struct mtk_platform_card_data *card_data = soc_card_data->card_data; |
| 789 |
int ret; |
| 790 |
|
| 791 |
ret = snd_soc_dapm_new_controls(dapm, mt8188_nau8825_widgets, |
| 792 |
ARRAY_SIZE(mt8188_nau8825_widgets)); |
| 793 |
if (ret) { |
| 794 |
dev_err(rtd->dev, "unable to add nau8825 card widget, ret %d\n", ret); |
| 795 |
return ret; |
| 796 |
} |
| 797 |
|
| 798 |
ret = snd_soc_add_card_controls(card, mt8188_nau8825_controls, |
| 799 |
ARRAY_SIZE(mt8188_nau8825_controls)); |
| 800 |
if (ret) { |
| 801 |
dev_err(rtd->dev, "unable to add nau8825 card controls, ret %d\n", ret); |
| 802 |
return ret; |
| 803 |
} |
| 804 |
|
| 805 |
ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", |
| 806 |
SND_JACK_HEADSET | SND_JACK_BTN_0 | |
| 807 |
SND_JACK_BTN_1 | SND_JACK_BTN_2 | |
| 808 |
SND_JACK_BTN_3, |
| 809 |
jack, |
| 810 |
nau8825_jack_pins, |
| 811 |
ARRAY_SIZE(nau8825_jack_pins)); |
| 812 |
if (ret) { |
| 813 |
dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); |
| 814 |
return ret; |
| 815 |
} |
| 816 |
|
| 817 |
if (card_data->flags & ES8326_HS_PRESENT) { |
| 818 |
snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); |
| 819 |
snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP); |
| 820 |
snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); |
| 821 |
snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); |
| 822 |
} else { |
| 823 |
snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); |
| 824 |
snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); |
| 825 |
snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); |
| 826 |
snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); |
| 827 |
} |
| 828 |
|
| 829 |
ret = snd_soc_component_set_jack(component, jack, NULL); |
| 830 |
|
| 831 |
if (ret) { |
| 832 |
dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret); |
| 833 |
return ret; |
| 834 |
} |
| 835 |
|
| 836 |
return 0; |
| 837 |
}; |
| 838 |
|
| 839 |
static void mt8188_headset_codec_exit(struct snd_soc_pcm_runtime *rtd) |
| 840 |
{ |
| 841 |
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; |
| 842 |
|
| 843 |
snd_soc_component_set_jack(component, NULL, NULL); |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
static int mt8188_nau8825_hw_params(struct snd_pcm_substream *substream, |
| 848 |
struct snd_pcm_hw_params *params) |
| 849 |
{ |
| 850 |
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
| 851 |
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); |
| 852 |
unsigned int rate = params_rate(params); |
| 853 |
unsigned int bit_width = params_width(params); |
| 854 |
int clk_freq, ret; |
| 855 |
|
| 856 |
clk_freq = rate * 2 * bit_width; |
| 857 |
|
| 858 |
/* Configure clock for codec */ |
| 859 |
ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_BLK, 0, |
| 860 |
SND_SOC_CLOCK_IN); |
| 861 |
if (ret < 0) { |
| 862 |
dev_err(codec_dai->dev, "can't set BCLK clock %d\n", ret); |
| 863 |
return ret; |
| 864 |
} |
| 865 |
|
| 866 |
/* Configure pll for codec */ |
| 867 |
ret = snd_soc_dai_set_pll(codec_dai, 0, 0, clk_freq, |
| 868 |
params_rate(params) * 256); |
| 869 |
if (ret < 0) { |
| 870 |
dev_err(codec_dai->dev, "can't set BCLK: %d\n", ret); |
| 871 |
return ret; |
| 872 |
} |
| 873 |
|
| 874 |
return 0; |
| 875 |
} |
| 876 |
|
| 877 |
static const struct snd_soc_ops mt8188_nau8825_ops = { |
| 878 |
.hw_params = mt8188_nau8825_hw_params, |
| 879 |
}; |
| 880 |
|
| 881 |
static int mt8188_rt5682s_i2s_hw_params(struct snd_pcm_substream *substream, |
| 882 |
struct snd_pcm_hw_params *params) |
| 883 |
{ |
| 884 |
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
| 885 |
struct snd_soc_card *card = rtd->card; |
| 886 |
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); |
| 887 |
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); |
| 888 |
unsigned int rate = params_rate(params); |
| 889 |
int bitwidth; |
| 890 |
int ret; |
| 891 |
|
| 892 |
bitwidth = snd_pcm_format_width(params_format(params)); |
| 893 |
if (bitwidth < 0) { |
| 894 |
dev_err(card->dev, "invalid bit width: %d\n", bitwidth); |
| 895 |
return bitwidth; |
| 896 |
} |
| 897 |
|
| 898 |
ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth); |
| 899 |
if (ret) { |
| 900 |
dev_err(card->dev, "failed to set tdm slot\n"); |
| 901 |
return ret; |
| 902 |
} |
| 903 |
|
| 904 |
ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1, RT5682_PLL1_S_BCLK1, |
| 905 |
rate * 32, rate * 512); |
| 906 |
if (ret) { |
| 907 |
dev_err(card->dev, "failed to set pll\n"); |
| 908 |
return ret; |
| 909 |
} |
| 910 |
|
| 911 |
ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL1, |
| 912 |
rate * 512, SND_SOC_CLOCK_IN); |
| 913 |
if (ret) { |
| 914 |
dev_err(card->dev, "failed to set sysclk\n"); |
| 915 |
return ret; |
| 916 |
} |
| 917 |
|
| 918 |
return snd_soc_dai_set_sysclk(cpu_dai, 0, rate * 128, |
| 919 |
SND_SOC_CLOCK_OUT); |
| 920 |
} |
| 921 |
|
| 922 |
static const struct snd_soc_ops mt8188_rt5682s_i2s_ops = { |
| 923 |
.hw_params = mt8188_rt5682s_i2s_hw_params, |
| 924 |
}; |
| 925 |
|
| 926 |
static int mt8188_sof_be_hw_params(struct snd_pcm_substream *substream, |
| 927 |
struct snd_pcm_hw_params *params) |
| 928 |
{ |
| 929 |
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
| 930 |
struct snd_soc_component *cmpnt_afe = NULL; |
| 931 |
struct snd_soc_pcm_runtime *runtime; |
| 932 |
|
| 933 |
/* find afe component */ |
| 934 |
for_each_card_rtds(rtd->card, runtime) { |
| 935 |
cmpnt_afe = snd_soc_rtdcom_lookup(runtime, AFE_PCM_NAME); |
| 936 |
if (cmpnt_afe) |
| 937 |
break; |
| 938 |
} |
| 939 |
|
| 940 |
if (cmpnt_afe && !pm_runtime_active(cmpnt_afe->dev)) { |
| 941 |
dev_err(rtd->dev, "afe pm runtime is not active!!\n"); |
| 942 |
return -EINVAL; |
| 943 |
} |
| 944 |
|
| 945 |
return 0; |
| 946 |
} |
| 947 |
|
| 948 |
static const struct snd_soc_ops mt8188_sof_be_ops = { |
| 949 |
.hw_params = mt8188_sof_be_hw_params, |
| 950 |
}; |
| 951 |
|
| 952 |
static int mt8188_es8326_hw_params(struct snd_pcm_substream *substream, |
| 953 |
struct snd_pcm_hw_params *params) |
| 954 |
{ |
| 955 |
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
| 956 |
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); |
| 957 |
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); |
| 958 |
unsigned int rate = params_rate(params); |
| 959 |
int ret; |
| 960 |
|
| 961 |
/* Configure MCLK for codec */ |
| 962 |
ret = snd_soc_dai_set_sysclk(codec_dai, 0, rate * 256, SND_SOC_CLOCK_IN); |
| 963 |
if (ret < 0) { |
| 964 |
dev_err(codec_dai->dev, "can't set MCLK %d\n", ret); |
| 965 |
return ret; |
| 966 |
} |
| 967 |
|
| 968 |
/* Configure MCLK for cpu */ |
| 969 |
return snd_soc_dai_set_sysclk(cpu_dai, 0, rate * 256, SND_SOC_CLOCK_OUT); |
| 970 |
} |
| 971 |
|
| 972 |
static const struct snd_soc_ops mt8188_es8326_ops = { |
| 973 |
.hw_params = mt8188_es8326_hw_params, |
| 974 |
}; |
| 975 |
|
| 976 |
static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = { |
| 977 |
/* FE */ |
| 978 |
[DAI_LINK_DL2_FE] = { |
| 979 |
.name = "DL2_FE", |
| 980 |
.stream_name = "DL2 Playback", |
| 981 |
.trigger = { |
| 982 |
SND_SOC_DPCM_TRIGGER_POST, |
| 983 |
SND_SOC_DPCM_TRIGGER_POST, |
| 984 |
}, |
| 985 |
.dynamic = 1, |
| 986 |
.playback_only = 1, |
| 987 |
.dpcm_merged_chan = 1, |
| 988 |
.dpcm_merged_rate = 1, |
| 989 |
.dpcm_merged_format = 1, |
| 990 |
SND_SOC_DAILINK_REG(playback2), |
| 991 |
}, |
| 992 |
[DAI_LINK_DL3_FE] = { |
| 993 |
.name = "DL3_FE", |
| 994 |
.stream_name = "DL3 Playback", |
| 995 |
.trigger = { |
| 996 |
SND_SOC_DPCM_TRIGGER_POST, |
| 997 |
SND_SOC_DPCM_TRIGGER_POST, |
| 998 |
}, |
| 999 |
.dynamic = 1, |
| 1000 |
.playback_only = 1, |
| 1001 |
.dpcm_merged_chan = 1, |
| 1002 |
.dpcm_merged_rate = 1, |
| 1003 |
.dpcm_merged_format = 1, |
| 1004 |
SND_SOC_DAILINK_REG(playback3), |
| 1005 |
}, |
| 1006 |
[DAI_LINK_DL6_FE] = { |
| 1007 |
.name = "DL6_FE", |
| 1008 |
.stream_name = "DL6 Playback", |
| 1009 |
.trigger = { |
| 1010 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1011 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1012 |
}, |
| 1013 |
.dynamic = 1, |
| 1014 |
.playback_only = 1, |
| 1015 |
.dpcm_merged_chan = 1, |
| 1016 |
.dpcm_merged_rate = 1, |
| 1017 |
.dpcm_merged_format = 1, |
| 1018 |
SND_SOC_DAILINK_REG(playback6), |
| 1019 |
}, |
| 1020 |
[DAI_LINK_DL7_FE] = { |
| 1021 |
.name = "DL7_FE", |
| 1022 |
.stream_name = "DL7 Playback", |
| 1023 |
.trigger = { |
| 1024 |
SND_SOC_DPCM_TRIGGER_PRE, |
| 1025 |
SND_SOC_DPCM_TRIGGER_PRE, |
| 1026 |
}, |
| 1027 |
.dynamic = 1, |
| 1028 |
.playback_only = 1, |
| 1029 |
SND_SOC_DAILINK_REG(playback7), |
| 1030 |
}, |
| 1031 |
[DAI_LINK_DL8_FE] = { |
| 1032 |
.name = "DL8_FE", |
| 1033 |
.stream_name = "DL8 Playback", |
| 1034 |
.trigger = { |
| 1035 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1036 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1037 |
}, |
| 1038 |
.dynamic = 1, |
| 1039 |
.playback_only = 1, |
| 1040 |
SND_SOC_DAILINK_REG(playback8), |
| 1041 |
}, |
| 1042 |
[DAI_LINK_DL10_FE] = { |
| 1043 |
.name = "DL10_FE", |
| 1044 |
.stream_name = "DL10 Playback", |
| 1045 |
.trigger = { |
| 1046 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1047 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1048 |
}, |
| 1049 |
.dynamic = 1, |
| 1050 |
.playback_only = 1, |
| 1051 |
SND_SOC_DAILINK_REG(playback10), |
| 1052 |
}, |
| 1053 |
[DAI_LINK_DL11_FE] = { |
| 1054 |
.name = "DL11_FE", |
| 1055 |
.stream_name = "DL11 Playback", |
| 1056 |
.trigger = { |
| 1057 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1058 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1059 |
}, |
| 1060 |
.dynamic = 1, |
| 1061 |
.playback_only = 1, |
| 1062 |
SND_SOC_DAILINK_REG(playback11), |
| 1063 |
}, |
| 1064 |
[DAI_LINK_UL1_FE] = { |
| 1065 |
.name = "UL1_FE", |
| 1066 |
.stream_name = "UL1 Capture", |
| 1067 |
.trigger = { |
| 1068 |
SND_SOC_DPCM_TRIGGER_PRE, |
| 1069 |
SND_SOC_DPCM_TRIGGER_PRE, |
| 1070 |
}, |
| 1071 |
.dynamic = 1, |
| 1072 |
.capture_only = 1, |
| 1073 |
SND_SOC_DAILINK_REG(capture1), |
| 1074 |
}, |
| 1075 |
[DAI_LINK_UL2_FE] = { |
| 1076 |
.name = "UL2_FE", |
| 1077 |
.stream_name = "UL2 Capture", |
| 1078 |
.trigger = { |
| 1079 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1080 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1081 |
}, |
| 1082 |
.dynamic = 1, |
| 1083 |
.capture_only = 1, |
| 1084 |
SND_SOC_DAILINK_REG(capture2), |
| 1085 |
}, |
| 1086 |
[DAI_LINK_UL3_FE] = { |
| 1087 |
.name = "UL3_FE", |
| 1088 |
.stream_name = "UL3 Capture", |
| 1089 |
.trigger = { |
| 1090 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1091 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1092 |
}, |
| 1093 |
.dynamic = 1, |
| 1094 |
.capture_only = 1, |
| 1095 |
SND_SOC_DAILINK_REG(capture3), |
| 1096 |
}, |
| 1097 |
[DAI_LINK_UL4_FE] = { |
| 1098 |
.name = "UL4_FE", |
| 1099 |
.stream_name = "UL4 Capture", |
| 1100 |
.trigger = { |
| 1101 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1102 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1103 |
}, |
| 1104 |
.dynamic = 1, |
| 1105 |
.capture_only = 1, |
| 1106 |
.dpcm_merged_chan = 1, |
| 1107 |
.dpcm_merged_rate = 1, |
| 1108 |
.dpcm_merged_format = 1, |
| 1109 |
SND_SOC_DAILINK_REG(capture4), |
| 1110 |
}, |
| 1111 |
[DAI_LINK_UL5_FE] = { |
| 1112 |
.name = "UL5_FE", |
| 1113 |
.stream_name = "UL5 Capture", |
| 1114 |
.trigger = { |
| 1115 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1116 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1117 |
}, |
| 1118 |
.dynamic = 1, |
| 1119 |
.capture_only = 1, |
| 1120 |
.dpcm_merged_chan = 1, |
| 1121 |
.dpcm_merged_rate = 1, |
| 1122 |
.dpcm_merged_format = 1, |
| 1123 |
SND_SOC_DAILINK_REG(capture5), |
| 1124 |
}, |
| 1125 |
[DAI_LINK_UL6_FE] = { |
| 1126 |
.name = "UL6_FE", |
| 1127 |
.stream_name = "UL6 Capture", |
| 1128 |
.trigger = { |
| 1129 |
SND_SOC_DPCM_TRIGGER_PRE, |
| 1130 |
SND_SOC_DPCM_TRIGGER_PRE, |
| 1131 |
}, |
| 1132 |
.dynamic = 1, |
| 1133 |
.capture_only = 1, |
| 1134 |
SND_SOC_DAILINK_REG(capture6), |
| 1135 |
}, |
| 1136 |
[DAI_LINK_UL8_FE] = { |
| 1137 |
.name = "UL8_FE", |
| 1138 |
.stream_name = "UL8 Capture", |
| 1139 |
.trigger = { |
| 1140 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1141 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1142 |
}, |
| 1143 |
.dynamic = 1, |
| 1144 |
.capture_only = 1, |
| 1145 |
SND_SOC_DAILINK_REG(capture8), |
| 1146 |
}, |
| 1147 |
[DAI_LINK_UL9_FE] = { |
| 1148 |
.name = "UL9_FE", |
| 1149 |
.stream_name = "UL9 Capture", |
| 1150 |
.trigger = { |
| 1151 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1152 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1153 |
}, |
| 1154 |
.dynamic = 1, |
| 1155 |
.capture_only = 1, |
| 1156 |
SND_SOC_DAILINK_REG(capture9), |
| 1157 |
}, |
| 1158 |
[DAI_LINK_UL10_FE] = { |
| 1159 |
.name = "UL10_FE", |
| 1160 |
.stream_name = "UL10 Capture", |
| 1161 |
.trigger = { |
| 1162 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1163 |
SND_SOC_DPCM_TRIGGER_POST, |
| 1164 |
}, |
| 1165 |
.dynamic = 1, |
| 1166 |
.capture_only = 1, |
| 1167 |
SND_SOC_DAILINK_REG(capture10), |
| 1168 |
}, |
| 1169 |
/* BE */ |
| 1170 |
[DAI_LINK_DL_SRC_BE] = { |
| 1171 |
.name = "DL_SRC_BE", |
| 1172 |
.no_pcm = 1, |
| 1173 |
.playback_only = 1, |
| 1174 |
SND_SOC_DAILINK_REG(dl_src), |
| 1175 |
}, |
| 1176 |
[DAI_LINK_DMIC_BE] = { |
| 1177 |
.name = "DMIC_BE", |
| 1178 |
.no_pcm = 1, |
| 1179 |
.capture_only = 1, |
| 1180 |
.ignore_suspend = 1, |
| 1181 |
SND_SOC_DAILINK_REG(DMIC_BE), |
| 1182 |
}, |
| 1183 |
[DAI_LINK_DPTX_BE] = { |
| 1184 |
.name = "DPTX_BE", |
| 1185 |
.ops = &mt8188_dptx_ops, |
| 1186 |
.be_hw_params_fixup = mt8188_dptx_hw_params_fixup, |
| 1187 |
.no_pcm = 1, |
| 1188 |
.playback_only = 1, |
| 1189 |
SND_SOC_DAILINK_REG(dptx), |
| 1190 |
}, |
| 1191 |
[DAI_LINK_ETDM1_IN_BE] = { |
| 1192 |
.name = "ETDM1_IN_BE", |
| 1193 |
.no_pcm = 1, |
| 1194 |
.dai_fmt = SND_SOC_DAIFMT_I2S | |
| 1195 |
SND_SOC_DAIFMT_NB_NF | |
| 1196 |
SND_SOC_DAIFMT_CBP_CFP, |
| 1197 |
.capture_only = 1, |
| 1198 |
.ignore_suspend = 1, |
| 1199 |
SND_SOC_DAILINK_REG(etdm1_in), |
| 1200 |
}, |
| 1201 |
[DAI_LINK_ETDM2_IN_BE] = { |
| 1202 |
.name = "ETDM2_IN_BE", |
| 1203 |
.no_pcm = 1, |
| 1204 |
.dai_fmt = SND_SOC_DAIFMT_I2S | |
| 1205 |
SND_SOC_DAIFMT_NB_NF | |
| 1206 |
SND_SOC_DAIFMT_CBP_CFP, |
| 1207 |
.capture_only = 1, |
| 1208 |
SND_SOC_DAILINK_REG(etdm2_in), |
| 1209 |
}, |
| 1210 |
[DAI_LINK_ETDM1_OUT_BE] = { |
| 1211 |
.name = "ETDM1_OUT_BE", |
| 1212 |
.no_pcm = 1, |
| 1213 |
.dai_fmt = SND_SOC_DAIFMT_I2S | |
| 1214 |
SND_SOC_DAIFMT_NB_NF | |
| 1215 |
SND_SOC_DAIFMT_CBC_CFC, |
| 1216 |
.playback_only = 1, |
| 1217 |
SND_SOC_DAILINK_REG(etdm1_out), |
| 1218 |
}, |
| 1219 |
[DAI_LINK_ETDM2_OUT_BE] = { |
| 1220 |
.name = "ETDM2_OUT_BE", |
| 1221 |
.no_pcm = 1, |
| 1222 |
.dai_fmt = SND_SOC_DAIFMT_I2S | |
| 1223 |
SND_SOC_DAIFMT_NB_NF | |
| 1224 |
SND_SOC_DAIFMT_CBC_CFC, |
| 1225 |
.playback_only = 1, |
| 1226 |
SND_SOC_DAILINK_REG(etdm2_out), |
| 1227 |
}, |
| 1228 |
[DAI_LINK_ETDM3_OUT_BE] = { |
| 1229 |
.name = "ETDM3_OUT_BE", |
| 1230 |
.no_pcm = 1, |
| 1231 |
.dai_fmt = SND_SOC_DAIFMT_I2S | |
| 1232 |
SND_SOC_DAIFMT_NB_NF | |
| 1233 |
SND_SOC_DAIFMT_CBC_CFC, |
| 1234 |
.playback_only = 1, |
| 1235 |
SND_SOC_DAILINK_REG(etdm3_out), |
| 1236 |
}, |
| 1237 |
[DAI_LINK_PCM1_BE] = { |
| 1238 |
.name = "PCM1_BE", |
| 1239 |
.no_pcm = 1, |
| 1240 |
.dai_fmt = SND_SOC_DAIFMT_I2S | |
| 1241 |
SND_SOC_DAIFMT_NB_NF | |
| 1242 |
SND_SOC_DAIFMT_CBC_CFC, |
| 1243 |
SND_SOC_DAILINK_REG(pcm1), |
| 1244 |
}, |
| 1245 |
[DAI_LINK_UL_SRC_BE] = { |
| 1246 |
.name = "UL_SRC_BE", |
| 1247 |
.no_pcm = 1, |
| 1248 |
.capture_only = 1, |
| 1249 |
SND_SOC_DAILINK_REG(ul_src), |
| 1250 |
}, |
| 1251 |
|
| 1252 |
/* SOF BE */ |
| 1253 |
[DAI_LINK_SOF_DL2_BE] = { |
| 1254 |
.name = "AFE_SOF_DL2", |
| 1255 |
.no_pcm = 1, |
| 1256 |
.playback_only = 1, |
| 1257 |
.ops = &mt8188_sof_be_ops, |
| 1258 |
SND_SOC_DAILINK_REG(AFE_SOF_DL2), |
| 1259 |
}, |
| 1260 |
[DAI_LINK_SOF_DL3_BE] = { |
| 1261 |
.name = "AFE_SOF_DL3", |
| 1262 |
.no_pcm = 1, |
| 1263 |
.playback_only = 1, |
| 1264 |
.ops = &mt8188_sof_be_ops, |
| 1265 |
SND_SOC_DAILINK_REG(AFE_SOF_DL3), |
| 1266 |
}, |
| 1267 |
[DAI_LINK_SOF_UL4_BE] = { |
| 1268 |
.name = "AFE_SOF_UL4", |
| 1269 |
.no_pcm = 1, |
| 1270 |
.capture_only = 1, |
| 1271 |
.ops = &mt8188_sof_be_ops, |
| 1272 |
SND_SOC_DAILINK_REG(AFE_SOF_UL4), |
| 1273 |
}, |
| 1274 |
[DAI_LINK_SOF_UL5_BE] = { |
| 1275 |
.name = "AFE_SOF_UL5", |
| 1276 |
.no_pcm = 1, |
| 1277 |
.capture_only = 1, |
| 1278 |
.ops = &mt8188_sof_be_ops, |
| 1279 |
SND_SOC_DAILINK_REG(AFE_SOF_UL5), |
| 1280 |
}, |
| 1281 |
}; |
| 1282 |
|
| 1283 |
static void mt8188_fixup_controls(struct snd_soc_card *card) |
| 1284 |
{ |
| 1285 |
struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); |
| 1286 |
struct mtk_platform_card_data *card_data = soc_card_data->card_data; |
| 1287 |
struct snd_kcontrol *kctl; |
| 1288 |
|
| 1289 |
if (card_data->flags & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT | ES8326_HS_PRESENT)) { |
| 1290 |
struct snd_soc_dapm_widget *w, *next_w; |
| 1291 |
|
| 1292 |
for_each_card_widgets_safe(card, w, next_w) { |
| 1293 |
if (strcmp(w->name, "Headphone")) |
| 1294 |
continue; |
| 1295 |
|
| 1296 |
snd_soc_dapm_free_widget(w); |
| 1297 |
} |
| 1298 |
|
| 1299 |
kctl = snd_ctl_find_id_mixer(card->snd_card, "Headphone Switch"); |
| 1300 |
if (kctl) |
| 1301 |
snd_ctl_remove(card->snd_card, kctl); |
| 1302 |
else |
| 1303 |
dev_warn(card->dev, "Cannot find ctl : Headphone Switch\n"); |
| 1304 |
} |
| 1305 |
} |
| 1306 |
|
| 1307 |
static struct snd_soc_card mt8188_mt6359_soc_card = { |
| 1308 |
.owner = THIS_MODULE, |
| 1309 |
.dai_link = mt8188_mt6359_dai_links, |
| 1310 |
.num_links = ARRAY_SIZE(mt8188_mt6359_dai_links), |
| 1311 |
.dapm_widgets = mt8188_mt6359_widgets, |
| 1312 |
.num_dapm_widgets = ARRAY_SIZE(mt8188_mt6359_widgets), |
| 1313 |
.dapm_routes = mt8188_mt6359_routes, |
| 1314 |
.num_dapm_routes = ARRAY_SIZE(mt8188_mt6359_routes), |
| 1315 |
.controls = mt8188_mt6359_controls, |
| 1316 |
.num_controls = ARRAY_SIZE(mt8188_mt6359_controls), |
| 1317 |
.fixup_controls = mt8188_fixup_controls, |
| 1318 |
}; |
| 1319 |
|
| 1320 |
static int mt8188_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy) |
| 1321 |
{ |
| 1322 |
struct mtk_platform_card_data *card_data = soc_card_data->card_data; |
| 1323 |
struct snd_soc_card *card = soc_card_data->card_data->card; |
| 1324 |
struct snd_soc_dai_link *dai_link; |
| 1325 |
bool init_mt6359 = false; |
| 1326 |
bool init_es8326 = false; |
| 1327 |
bool init_nau8825 = false; |
| 1328 |
bool init_rt5682s = false; |
| 1329 |
bool init_max98390 = false; |
| 1330 |
bool init_dumb = false; |
| 1331 |
int i; |
| 1332 |
|
| 1333 |
if (legacy) |
| 1334 |
return -EINVAL; |
| 1335 |
|
| 1336 |
for_each_card_prelinks(card, i, dai_link) { |
| 1337 |
if (strcmp(dai_link->name, "DPTX_BE") == 0) { |
| 1338 |
if (dai_link->num_codecs && |
| 1339 |
!snd_soc_dlc_is_dummy(dai_link->codecs)) |
| 1340 |
dai_link->init = mt8188_dptx_codec_init; |
| 1341 |
} else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { |
| 1342 |
if (dai_link->num_codecs && |
| 1343 |
!snd_soc_dlc_is_dummy(dai_link->codecs)) |
| 1344 |
dai_link->init = mt8188_hdmi_codec_init; |
| 1345 |
} else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 || |
| 1346 |
strcmp(dai_link->name, "UL_SRC_BE") == 0) { |
| 1347 |
if (!init_mt6359) { |
| 1348 |
dai_link->init = mt8188_mt6359_init; |
| 1349 |
init_mt6359 = true; |
| 1350 |
} |
| 1351 |
} else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 || |
| 1352 |
strcmp(dai_link->name, "ETDM2_OUT_BE") == 0 || |
| 1353 |
strcmp(dai_link->name, "ETDM1_IN_BE") == 0 || |
| 1354 |
strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { |
| 1355 |
if (!dai_link->num_codecs) |
| 1356 |
continue; |
| 1357 |
|
| 1358 |
if (!strcmp(dai_link->codecs->dai_name, MAX98390_CODEC_DAI)) { |
| 1359 |
/* |
| 1360 |
* The TDM protocol settings with fixed 4 slots are defined in |
| 1361 |
* mt8188_max98390_ops. Two amps is I2S mode, |
| 1362 |
* SOC and codec don't require TDM settings. |
| 1363 |
*/ |
| 1364 |
if (!(card_data->flags & MAX98390_TWO_AMP)) { |
| 1365 |
dai_link->ops = &mt8188_max98390_ops; |
| 1366 |
} |
| 1367 |
if (!init_max98390) { |
| 1368 |
dai_link->init = mt8188_max98390_codec_init; |
| 1369 |
init_max98390 = true; |
| 1370 |
} |
| 1371 |
} else if (!strcmp(dai_link->codecs->dai_name, NAU8825_CODEC_DAI)) { |
| 1372 |
dai_link->ops = &mt8188_nau8825_ops; |
| 1373 |
if (!init_nau8825) { |
| 1374 |
dai_link->init = mt8188_headset_codec_init; |
| 1375 |
dai_link->exit = mt8188_headset_codec_exit; |
| 1376 |
init_nau8825 = true; |
| 1377 |
} |
| 1378 |
} else if (!strcmp(dai_link->codecs->dai_name, RT5682S_CODEC_DAI)) { |
| 1379 |
dai_link->ops = &mt8188_rt5682s_i2s_ops; |
| 1380 |
if (!init_rt5682s) { |
| 1381 |
dai_link->init = mt8188_headset_codec_init; |
| 1382 |
dai_link->exit = mt8188_headset_codec_exit; |
| 1383 |
init_rt5682s = true; |
| 1384 |
} |
| 1385 |
} else if (!strcmp(dai_link->codecs->dai_name, ES8326_CODEC_DAI)) { |
| 1386 |
dai_link->ops = &mt8188_es8326_ops; |
| 1387 |
if (!init_es8326) { |
| 1388 |
dai_link->init = mt8188_headset_codec_init; |
| 1389 |
dai_link->exit = mt8188_headset_codec_exit; |
| 1390 |
init_es8326 = true; |
| 1391 |
} |
| 1392 |
} else { |
| 1393 |
if (!snd_soc_dlc_is_dummy(dai_link->codecs)) { |
| 1394 |
if (!init_dumb) { |
| 1395 |
dai_link->init = mt8188_dumb_amp_init; |
| 1396 |
init_dumb = true; |
| 1397 |
} |
| 1398 |
} |
| 1399 |
} |
| 1400 |
} |
| 1401 |
} |
| 1402 |
|
| 1403 |
return 0; |
| 1404 |
} |
| 1405 |
|
| 1406 |
static const struct mtk_sof_priv mt8188_sof_priv = { |
| 1407 |
.conn_streams = g_sof_conn_streams, |
| 1408 |
.num_streams = ARRAY_SIZE(g_sof_conn_streams), |
| 1409 |
}; |
| 1410 |
|
| 1411 |
static const struct mtk_soundcard_pdata mt8188_evb_card = { |
| 1412 |
.card_name = "mt8188_mt6359", |
| 1413 |
.card_data = &(struct mtk_platform_card_data) { |
| 1414 |
.card = &mt8188_mt6359_soc_card, |
| 1415 |
.num_jacks = MT8188_JACK_MAX, |
| 1416 |
}, |
| 1417 |
.sof_priv = &mt8188_sof_priv, |
| 1418 |
.soc_probe = mt8188_mt6359_soc_card_probe, |
| 1419 |
}; |
| 1420 |
|
| 1421 |
static const struct mtk_soundcard_pdata mt8188_nau8825_card = { |
| 1422 |
.card_name = "mt8188_nau8825", |
| 1423 |
.card_data = &(struct mtk_platform_card_data) { |
| 1424 |
.card = &mt8188_mt6359_soc_card, |
| 1425 |
.num_jacks = MT8188_JACK_MAX, |
| 1426 |
.flags = NAU8825_HS_PRESENT |
| 1427 |
}, |
| 1428 |
.sof_priv = &mt8188_sof_priv, |
| 1429 |
.soc_probe = mt8188_mt6359_soc_card_probe, |
| 1430 |
}; |
| 1431 |
|
| 1432 |
static const struct mtk_soundcard_pdata mt8188_rt5682s_card = { |
| 1433 |
.card_name = "mt8188_rt5682s", |
| 1434 |
.card_data = &(struct mtk_platform_card_data) { |
| 1435 |
.card = &mt8188_mt6359_soc_card, |
| 1436 |
.num_jacks = MT8188_JACK_MAX, |
| 1437 |
.flags = RT5682S_HS_PRESENT | MAX98390_TWO_AMP |
| 1438 |
}, |
| 1439 |
.sof_priv = &mt8188_sof_priv, |
| 1440 |
.soc_probe = mt8188_mt6359_soc_card_probe, |
| 1441 |
}; |
| 1442 |
|
| 1443 |
static const struct mtk_soundcard_pdata mt8188_es8326_card = { |
| 1444 |
.card_name = "mt8188_es8326", |
| 1445 |
.card_data = &(struct mtk_platform_card_data) { |
| 1446 |
.card = &mt8188_mt6359_soc_card, |
| 1447 |
.num_jacks = MT8188_JACK_MAX, |
| 1448 |
.flags = ES8326_HS_PRESENT | MAX98390_TWO_AMP |
| 1449 |
}, |
| 1450 |
.sof_priv = &mt8188_sof_priv, |
| 1451 |
.soc_probe = mt8188_mt6359_soc_card_probe, |
| 1452 |
}; |
| 1453 |
|
| 1454 |
static const struct of_device_id mt8188_mt6359_dt_match[] = { |
| 1455 |
{ .compatible = "mediatek,mt8188-mt6359-evb", .data = &mt8188_evb_card, }, |
| 1456 |
{ .compatible = "mediatek,mt8188-nau8825", .data = &mt8188_nau8825_card, }, |
| 1457 |
{ .compatible = "mediatek,mt8188-rt5682s", .data = &mt8188_rt5682s_card, }, |
| 1458 |
{ .compatible = "mediatek,mt8188-es8326", .data = &mt8188_es8326_card, }, |
| 1459 |
{ /* sentinel */ }, |
| 1460 |
}; |
| 1461 |
MODULE_DEVICE_TABLE(of, mt8188_mt6359_dt_match); |
| 1462 |
|
| 1463 |
static struct platform_driver mt8188_mt6359_driver = { |
| 1464 |
.driver = { |
| 1465 |
.name = "mt8188_mt6359", |
| 1466 |
.of_match_table = mt8188_mt6359_dt_match, |
| 1467 |
.pm = &snd_soc_pm_ops, |
| 1468 |
}, |
| 1469 |
.probe = mtk_soundcard_common_probe, |
| 1470 |
}; |
| 1471 |
|
| 1472 |
module_platform_driver(mt8188_mt6359_driver); |
| 1473 |
|
| 1474 |
/* Module information */ |
| 1475 |
MODULE_DESCRIPTION("MT8188-MT6359 ALSA SoC machine driver"); |
| 1476 |
MODULE_AUTHOR("Trevor Wu <[email protected]>"); |
| 1477 |
MODULE_LICENSE("GPL"); |
| 1478 |
MODULE_ALIAS("mt8188 mt6359 soc card"); |