1 // SPDX-License-Identifier: GPL-2.0-only
3 * This file defines data structures and functions used in Machine
4 * Driver for Intel platforms with Cirrus Logic Codecs.
6 * Copyright 2022 Intel Corporation.
8 #include <linux/module.h>
10 #include "../../codecs/cs35l41.h"
11 #include "sof_cirrus_common.h"
14 * Cirrus Logic CS35L41/CS35L53
16 static const struct snd_kcontrol_new cs35l41_kcontrols[] = {
17 SOC_DAPM_PIN_SWITCH("WL Spk"),
18 SOC_DAPM_PIN_SWITCH("WR Spk"),
19 SOC_DAPM_PIN_SWITCH("TL Spk"),
20 SOC_DAPM_PIN_SWITCH("TR Spk"),
23 static const struct snd_soc_dapm_widget cs35l41_dapm_widgets[] = {
24 SND_SOC_DAPM_SPK("WL Spk", NULL),
25 SND_SOC_DAPM_SPK("WR Spk", NULL),
26 SND_SOC_DAPM_SPK("TL Spk", NULL),
27 SND_SOC_DAPM_SPK("TR Spk", NULL),
30 static const struct snd_soc_dapm_route cs35l41_dapm_routes[] = {
32 {"WL Spk", NULL, "WL SPK"},
33 {"WR Spk", NULL, "WR SPK"},
34 {"TL Spk", NULL, "TL SPK"},
35 {"TR Spk", NULL, "TR SPK"},
38 static struct snd_soc_dai_link_component cs35l41_components[] = {
40 .name = CS35L41_DEV0_NAME,
41 .dai_name = CS35L41_CODEC_DAI,
44 .name = CS35L41_DEV1_NAME,
45 .dai_name = CS35L41_CODEC_DAI,
48 .name = CS35L41_DEV2_NAME,
49 .dai_name = CS35L41_CODEC_DAI,
52 .name = CS35L41_DEV3_NAME,
53 .dai_name = CS35L41_CODEC_DAI,
57 static struct snd_soc_codec_conf cs35l41_codec_conf[] = {
59 .dlc = COMP_CODEC_CONF(CS35L41_DEV0_NAME),
63 .dlc = COMP_CODEC_CONF(CS35L41_DEV1_NAME),
67 .dlc = COMP_CODEC_CONF(CS35L41_DEV2_NAME),
71 .dlc = COMP_CODEC_CONF(CS35L41_DEV3_NAME),
76 static int cs35l41_init(struct snd_soc_pcm_runtime *rtd)
78 struct snd_soc_card *card = rtd->card;
81 ret = snd_soc_dapm_new_controls(&card->dapm, cs35l41_dapm_widgets,
82 ARRAY_SIZE(cs35l41_dapm_widgets));
84 dev_err(rtd->dev, "fail to add dapm controls, ret %d\n", ret);
88 ret = snd_soc_add_card_controls(card, cs35l41_kcontrols,
89 ARRAY_SIZE(cs35l41_kcontrols));
91 dev_err(rtd->dev, "fail to add card controls, ret %d\n", ret);
95 ret = snd_soc_dapm_add_routes(&card->dapm, cs35l41_dapm_routes,
96 ARRAY_SIZE(cs35l41_dapm_routes));
99 dev_err(rtd->dev, "fail to add dapm routes, ret %d\n", ret);
104 static int cs35l41_hw_params(struct snd_pcm_substream *substream,
105 struct snd_pcm_hw_params *params)
107 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
108 struct snd_soc_dai *codec_dai;
109 int clk_freq, i, ret;
111 clk_freq = sof_dai_get_bclk(rtd); /* BCLK freq */
114 dev_err(rtd->dev, "fail to get bclk freq, ret %d\n", clk_freq);
118 for_each_rtd_codec_dais(rtd, i, codec_dai) {
119 /* call dai driver's set_sysclk() callback */
120 ret = snd_soc_dai_set_sysclk(codec_dai, CS35L41_CLKID_SCLK,
121 clk_freq, SND_SOC_CLOCK_IN);
123 dev_err(codec_dai->dev, "fail to set sysclk, ret %d\n",
128 /* call component driver's set_sysclk() callback */
129 ret = snd_soc_component_set_sysclk(codec_dai->component,
130 CS35L41_CLKID_SCLK, 0,
131 clk_freq, SND_SOC_CLOCK_IN);
133 dev_err(codec_dai->dev, "fail to set component sysclk, ret %d\n",
142 static const struct snd_soc_ops cs35l41_ops = {
143 .hw_params = cs35l41_hw_params,
146 void cs35l41_set_dai_link(struct snd_soc_dai_link *link)
148 link->codecs = cs35l41_components;
149 link->num_codecs = ARRAY_SIZE(cs35l41_components);
150 link->init = cs35l41_init;
151 link->ops = &cs35l41_ops;
153 EXPORT_SYMBOL_NS(cs35l41_set_dai_link, SND_SOC_INTEL_SOF_CIRRUS_COMMON);
155 void cs35l41_set_codec_conf(struct snd_soc_card *card)
157 card->codec_conf = cs35l41_codec_conf;
158 card->num_configs = ARRAY_SIZE(cs35l41_codec_conf);
160 EXPORT_SYMBOL_NS(cs35l41_set_codec_conf, SND_SOC_INTEL_SOF_CIRRUS_COMMON);
162 MODULE_DESCRIPTION("ASoC Intel SOF Cirrus Logic helpers");
163 MODULE_LICENSE("GPL");