1 // SPDX-License-Identifier: GPL-2.0-only
3 // Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
5 // Authors: Cezary Rojewski <cezary.rojewski@intel.com>
6 // Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <sound/core.h>
12 #include <sound/pcm.h>
13 #include <sound/pcm_params.h>
14 #include <sound/soc.h>
15 #include <sound/soc-acpi.h>
16 #include "../../../codecs/nau8825.h"
19 #define SKL_SSM_CODEC_DAI "ssm4567-hifi"
21 static struct snd_soc_codec_conf card_codec_conf[] = {
23 .dlc = COMP_CODEC_CONF("i2c-INT343B:00"),
24 .name_prefix = "Left",
27 .dlc = COMP_CODEC_CONF("i2c-INT343B:01"),
28 .name_prefix = "Right",
32 static const struct snd_kcontrol_new card_controls[] = {
33 SOC_DAPM_PIN_SWITCH("Left Speaker"),
34 SOC_DAPM_PIN_SWITCH("Right Speaker"),
37 static const struct snd_soc_dapm_widget card_widgets[] = {
38 SND_SOC_DAPM_SPK("Left Speaker", NULL),
39 SND_SOC_DAPM_SPK("Right Speaker", NULL),
40 SND_SOC_DAPM_SPK("DP1", NULL),
41 SND_SOC_DAPM_SPK("DP2", NULL),
44 static const struct snd_soc_dapm_route card_base_routes[] = {
45 {"Left Speaker", NULL, "Left OUT"},
46 {"Right Speaker", NULL, "Right OUT"},
49 static int avs_ssm4567_codec_init(struct snd_soc_pcm_runtime *runtime)
54 ret = snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_codec(runtime, 0), 0x01, 0x01, 2, 48);
58 /* Slot 2 for right */
59 ret = snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_codec(runtime, 1), 0x02, 0x02, 2, 48);
67 avs_ssm4567_be_fixup(struct snd_soc_pcm_runtime *runrime, struct snd_pcm_hw_params *params)
69 struct snd_interval *rate, *channels;
72 rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
73 channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
74 fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
76 /* The ADSP will convert the FE rate to 48k, stereo */
77 rate->min = rate->max = 48000;
78 channels->min = channels->max = 2;
80 /* set SSP0 to 24 bit */
82 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
86 static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
87 int tdm_slot, struct snd_soc_dai_link **dai_link)
89 struct snd_soc_dai_link_component *platform;
90 struct snd_soc_dai_link *dl;
92 dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
93 platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL);
97 platform->name = platform_name;
99 dl->name = devm_kasprintf(dev, GFP_KERNEL,
100 AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot));
101 dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
102 dl->codecs = devm_kzalloc(dev, sizeof(*dl->codecs) * 2, GFP_KERNEL);
103 if (!dl->name || !dl->cpus || !dl->codecs)
106 dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
107 AVS_STRING_FMT("SSP", " Pin", ssp_port, tdm_slot));
108 dl->codecs[0].name = devm_kasprintf(dev, GFP_KERNEL, "i2c-INT343B:00");
109 dl->codecs[0].dai_name = devm_kasprintf(dev, GFP_KERNEL, "ssm4567-hifi");
110 dl->codecs[1].name = devm_kasprintf(dev, GFP_KERNEL, "i2c-INT343B:01");
111 dl->codecs[1].dai_name = devm_kasprintf(dev, GFP_KERNEL, "ssm4567-hifi");
112 if (!dl->cpus->dai_name || !dl->codecs[0].name || !dl->codecs[0].dai_name ||
113 !dl->codecs[1].name || !dl->codecs[1].dai_name)
118 dl->platforms = platform;
119 dl->num_platforms = 1;
121 dl->dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBS_CFS;
122 dl->init = avs_ssm4567_codec_init;
123 dl->be_hw_params_fixup = avs_ssm4567_be_fixup;
126 dl->dpcm_capture = 1;
127 dl->dpcm_playback = 1;
128 dl->ignore_pmdown_time = 1;
135 static int avs_ssm4567_probe(struct platform_device *pdev)
137 struct snd_soc_dai_link *dai_link;
138 struct snd_soc_acpi_mach *mach;
139 struct snd_soc_card *card;
140 struct device *dev = &pdev->dev;
142 int ssp_port, tdm_slot, ret;
144 mach = dev_get_platdata(dev);
145 pname = mach->mach_params.platform;
147 ret = avs_mach_get_ssp_tdm(dev, mach, &ssp_port, &tdm_slot);
151 ret = avs_create_dai_link(dev, pname, ssp_port, tdm_slot, &dai_link);
153 dev_err(dev, "Failed to create dai link: %d", ret);
157 card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
161 card->name = "avs_ssm4567-adi";
163 card->owner = THIS_MODULE;
164 card->dai_link = dai_link;
166 card->codec_conf = card_codec_conf;
167 card->num_configs = ARRAY_SIZE(card_codec_conf);
168 card->controls = card_controls;
169 card->num_controls = ARRAY_SIZE(card_controls);
170 card->dapm_widgets = card_widgets;
171 card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
172 card->dapm_routes = card_base_routes;
173 card->num_dapm_routes = ARRAY_SIZE(card_base_routes);
174 card->fully_routed = true;
175 card->disable_route_checks = true;
177 ret = snd_soc_fixup_dai_links_platform_name(card, pname);
181 return devm_snd_soc_register_card(dev, card);
184 static const struct platform_device_id avs_ssm4567_driver_ids[] = {
186 .name = "avs_ssm4567",
190 MODULE_DEVICE_TABLE(platform, avs_ssm4567_driver_ids);
192 static struct platform_driver avs_ssm4567_driver = {
193 .probe = avs_ssm4567_probe,
195 .name = "avs_ssm4567",
196 .pm = &snd_soc_pm_ops,
198 .id_table = avs_ssm4567_driver_ids,
201 module_platform_driver(avs_ssm4567_driver)
203 MODULE_LICENSE("GPL");