1 // SPDX-License-Identifier: GPL-2.0-only
2 //
3 // Copyright(c) 2020 Intel Corporation. All rights reserved.
4 #include <linux/string.h>
5 #include <sound/pcm.h>
6 #include <sound/soc.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"
11 
12 static const struct snd_soc_dapm_route max_98373_dapm_routes[] = {
13 	/* speaker */
14 	{ "Left Spk", NULL, "Left BE_OUT" },
15 	{ "Right Spk", NULL, "Right BE_OUT" },
16 };
17 
18 static struct snd_soc_codec_conf max_98373_codec_conf[] = {
19 	{
20 		.dlc = COMP_CODEC_CONF(MAX_98373_DEV0_NAME),
21 		.name_prefix = "Right",
22 	},
23 	{
24 		.dlc = COMP_CODEC_CONF(MAX_98373_DEV1_NAME),
25 		.name_prefix = "Left",
26 	},
27 };
28 
29 struct snd_soc_dai_link_component max_98373_components[] = {
30 	{  /* For Left */
31 		.name = MAX_98373_DEV0_NAME,
32 		.dai_name = MAX_98373_CODEC_DAI,
33 	},
34 	{  /* For Right */
35 		.name = MAX_98373_DEV1_NAME,
36 		.dai_name = MAX_98373_CODEC_DAI,
37 	},
38 };
39 
40 static int max98373_hw_params(struct snd_pcm_substream *substream,
41 			      struct snd_pcm_hw_params *params)
42 {
43 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
44 	struct snd_soc_dai *codec_dai;
45 	int j;
46 
47 	for_each_rtd_codec_dais(rtd, j, codec_dai) {
48 		if (!strcmp(codec_dai->component->name, MAX_98373_DEV0_NAME)) {
49 			/* DEV0 tdm slot configuration */
50 			snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
51 		}
52 		if (!strcmp(codec_dai->component->name, MAX_98373_DEV1_NAME)) {
53 			/* DEV1 tdm slot configuration */
54 			snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
55 		}
56 	}
57 	return 0;
58 }
59 
60 struct snd_soc_ops max_98373_ops = {
61 	.hw_params = max98373_hw_params,
62 };
63 
64 int max98373_spk_codec_init(struct snd_soc_pcm_runtime *rtd)
65 {
66 	struct snd_soc_card *card = rtd->card;
67 	int ret;
68 
69 	ret = snd_soc_dapm_add_routes(&card->dapm, max_98373_dapm_routes,
70 				      ARRAY_SIZE(max_98373_dapm_routes));
71 	if (ret)
72 		dev_err(rtd->dev, "Speaker map addition failed: %d\n", ret);
73 	return ret;
74 }
75 
76 void sof_max98373_codec_conf(struct snd_soc_card *card)
77 {
78 	card->codec_conf = max_98373_codec_conf;
79 	card->num_configs = ARRAY_SIZE(max_98373_codec_conf);
80 }
81