1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2020 Intel Corporation
5 * sof_sdw_rt1316 - Helpers to handle RT1316 from generic machine driver
8 #include <linux/device.h>
9 #include <linux/errno.h>
10 #include <sound/control.h>
11 #include <sound/soc.h>
12 #include <sound/soc-acpi.h>
13 #include <sound/soc-dapm.h>
14 #include "sof_sdw_common.h"
16 static const struct snd_soc_dapm_widget rt1316_widgets
[] = {
17 SND_SOC_DAPM_SPK("Speaker", NULL
),
21 * dapm routes for rt1316 will be registered dynamically according
22 * to the number of rt1316 used. The first two entries will be registered
23 * for one codec case, and the last two entries are also registered
24 * if two 1316s are used.
26 static const struct snd_soc_dapm_route rt1316_map
[] = {
27 { "Speaker", NULL
, "rt1316-1 SPOL" },
28 { "Speaker", NULL
, "rt1316-1 SPOR" },
29 { "Speaker", NULL
, "rt1316-2 SPOL" },
30 { "Speaker", NULL
, "rt1316-2 SPOR" },
33 static const struct snd_kcontrol_new rt1316_controls
[] = {
34 SOC_DAPM_PIN_SWITCH("Speaker"),
37 static int first_spk_init(struct snd_soc_pcm_runtime
*rtd
)
39 struct snd_soc_card
*card
= rtd
->card
;
42 card
->components
= devm_kasprintf(card
->dev
, GFP_KERNEL
,
45 if (!card
->components
)
48 ret
= snd_soc_add_card_controls(card
, rt1316_controls
,
49 ARRAY_SIZE(rt1316_controls
));
51 dev_err(card
->dev
, "rt1316 controls addition failed: %d\n", ret
);
55 ret
= snd_soc_dapm_new_controls(&card
->dapm
, rt1316_widgets
,
56 ARRAY_SIZE(rt1316_widgets
));
58 dev_err(card
->dev
, "rt1316 widgets addition failed: %d\n", ret
);
62 ret
= snd_soc_dapm_add_routes(&card
->dapm
, rt1316_map
, 2);
64 dev_err(rtd
->dev
, "failed to add first SPK map: %d\n", ret
);
69 static int second_spk_init(struct snd_soc_pcm_runtime
*rtd
)
71 struct snd_soc_card
*card
= rtd
->card
;
74 ret
= snd_soc_dapm_add_routes(&card
->dapm
, rt1316_map
+ 2, 2);
76 dev_err(rtd
->dev
, "failed to add second SPK map: %d\n", ret
);
81 static int all_spk_init(struct snd_soc_pcm_runtime
*rtd
)
85 ret
= first_spk_init(rtd
);
89 return second_spk_init(rtd
);
92 int sof_sdw_rt1316_init(const struct snd_soc_acpi_link_adr
*link
,
93 struct snd_soc_dai_link
*dai_links
,
94 struct sof_sdw_codec_info
*info
,
97 /* Count amp number and do init on playback link only. */
102 if (info
->amp_num
== 1)
103 dai_links
->init
= first_spk_init
;
105 if (info
->amp_num
== 2) {
107 * if two 1316s are in one dai link, the init function
108 * in this dai link will be first set for the first speaker,
109 * and it should be reset to initialize all speakers when
110 * the second speaker is found.
113 dai_links
->init
= all_spk_init
;
115 dai_links
->init
= second_spk_init
;