1 // SPDX-License-Identifier: GPL-2.0-only
3 // Copyright(c) 2020 Intel Corporation. All rights reserved.
4 #include <linux/string.h>
7 #include <sound/soc-dai.h>
8 #include <sound/soc-dapm.h>
9 #include <uapi/sound/asound.h>
10 #include "sof_maxim_common.h"
12 #define MAX_98373_PIN_NAME 16
14 const struct snd_soc_dapm_route max_98373_dapm_routes
[] = {
16 { "Left Spk", NULL
, "Left BE_OUT" },
17 { "Right Spk", NULL
, "Right BE_OUT" },
20 static struct snd_soc_codec_conf max_98373_codec_conf
[] = {
22 .dlc
= COMP_CODEC_CONF(MAX_98373_DEV0_NAME
),
23 .name_prefix
= "Right",
26 .dlc
= COMP_CODEC_CONF(MAX_98373_DEV1_NAME
),
27 .name_prefix
= "Left",
31 struct snd_soc_dai_link_component max_98373_components
[] = {
33 .name
= MAX_98373_DEV0_NAME
,
34 .dai_name
= MAX_98373_CODEC_DAI
,
37 .name
= MAX_98373_DEV1_NAME
,
38 .dai_name
= MAX_98373_CODEC_DAI
,
42 static int max98373_hw_params(struct snd_pcm_substream
*substream
,
43 struct snd_pcm_hw_params
*params
)
45 struct snd_soc_pcm_runtime
*rtd
= asoc_substream_to_rtd(substream
);
46 struct snd_soc_dai
*codec_dai
;
49 for_each_rtd_codec_dais(rtd
, j
, codec_dai
) {
50 if (!strcmp(codec_dai
->component
->name
, MAX_98373_DEV0_NAME
)) {
51 /* DEV0 tdm slot configuration */
52 snd_soc_dai_set_tdm_slot(codec_dai
, 0x03, 3, 8, 32);
54 if (!strcmp(codec_dai
->component
->name
, MAX_98373_DEV1_NAME
)) {
55 /* DEV1 tdm slot configuration */
56 snd_soc_dai_set_tdm_slot(codec_dai
, 0x0C, 3, 8, 32);
62 int max98373_trigger(struct snd_pcm_substream
*substream
, int cmd
)
64 struct snd_soc_pcm_runtime
*rtd
= asoc_substream_to_rtd(substream
);
65 struct snd_soc_dai
*codec_dai
;
69 /* set spk pin by playback only */
70 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
73 for_each_rtd_codec_dais(rtd
, j
, codec_dai
) {
74 struct snd_soc_component
*component
= codec_dai
->component
;
75 struct snd_soc_dapm_context
*dapm
=
76 snd_soc_component_get_dapm(component
);
77 char pin_name
[MAX_98373_PIN_NAME
];
79 snprintf(pin_name
, ARRAY_SIZE(pin_name
), "%s Spk",
80 codec_dai
->component
->name_prefix
);
83 case SNDRV_PCM_TRIGGER_START
:
84 case SNDRV_PCM_TRIGGER_RESUME
:
85 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
86 ret
= snd_soc_dapm_enable_pin(dapm
, pin_name
);
88 snd_soc_dapm_sync(dapm
);
90 case SNDRV_PCM_TRIGGER_STOP
:
91 case SNDRV_PCM_TRIGGER_SUSPEND
:
92 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
93 ret
= snd_soc_dapm_disable_pin(dapm
, pin_name
);
95 snd_soc_dapm_sync(dapm
);
105 struct snd_soc_ops max_98373_ops
= {
106 .hw_params
= max98373_hw_params
,
107 .trigger
= max98373_trigger
,
110 int max98373_spk_codec_init(struct snd_soc_pcm_runtime
*rtd
)
112 struct snd_soc_card
*card
= rtd
->card
;
115 ret
= snd_soc_dapm_add_routes(&card
->dapm
, max_98373_dapm_routes
,
116 ARRAY_SIZE(max_98373_dapm_routes
));
118 dev_err(rtd
->dev
, "Speaker map addition failed: %d\n", ret
);
122 void sof_max98373_codec_conf(struct snd_soc_card
*card
)
124 card
->codec_conf
= max_98373_codec_conf
;
125 card
->num_configs
= ARRAY_SIZE(max_98373_codec_conf
);