File Index
Files and directories
Sign in
FILE

soc_sdw_ti_amp.c

File preview with syntax highlighting.

linux-6.19.14/sound/soc/sdw_utils/soc_sdw_ti_amp.c C
 1// SPDX-License-Identifier: GPL-2.0-only
 2// Copyright (c) 2025 Texas Instruments Inc.
 3
 4/*
 5 *  soc_sdw_ti_amp - Helpers to handle TI's soundwire based codecs
 6 */
 7
 8#include <linux/device.h>
 9#include <linux/errno.h>
10#include <sound/soc.h>
11#include <sound/soc-acpi.h>
12#include <sound/soc-dai.h>
13#include <sound/soc_sdw_utils.h>
14
15#define TIAMP_SPK_VOLUME_0DB		200
16
17int asoc_sdw_ti_amp_initial_settings(struct snd_soc_card *card,
18				     const char *name_prefix)
19{
20	char *volume_ctl_name;
21	int ret;
22
23	volume_ctl_name = kasprintf(GFP_KERNEL, "%s Speaker Volume",
24				    name_prefix);
25	if (!volume_ctl_name)
26		return -ENOMEM;
27
28	ret = snd_soc_limit_volume(card, volume_ctl_name,
29				   TIAMP_SPK_VOLUME_0DB);
30	if (ret)
31		dev_err(card->dev,
32			"%s update failed %d\n",
33			volume_ctl_name, ret);
34
35	kfree(volume_ctl_name);
36	return 0;
37}
38EXPORT_SYMBOL_NS(asoc_sdw_ti_amp_initial_settings, "SND_SOC_SDW_UTILS");
39
40int asoc_sdw_ti_spk_rtd_init(struct snd_soc_pcm_runtime *rtd,
41			     struct snd_soc_dai *dai)
42{
43	struct snd_soc_card *card = rtd->card;
44	struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card);
45	char widget_name[16];
46	char speaker[16];
47	struct snd_soc_dapm_route route = {speaker, NULL, widget_name};
48	struct snd_soc_dai *codec_dai;
49	const char *prefix;
50	int i, ret = 0;
51
52	for_each_rtd_codec_dais(rtd, i, codec_dai) {
53		if (!strstr(codec_dai->name, "tas2783"))
54			continue;
55
56		prefix = codec_dai->component->name_prefix;
57		if (!strncmp(prefix, "tas2783-1", strlen("tas2783-1"))) {
58			strscpy(speaker, "Left Spk", sizeof(speaker));
59		} else if (!strncmp(prefix, "tas2783-2", strlen("tas2783-2"))) {
60			strscpy(speaker, "Right Spk", sizeof(speaker));
61		} else {
62			ret = -EINVAL;
63			dev_err(card->dev, "unhandled prefix %s", prefix);
64			break;
65		}
66
67		snprintf(widget_name, sizeof(widget_name), "%s SPK", prefix);
68		ret = asoc_sdw_ti_amp_initial_settings(card, prefix);
69		if (ret)
70			return ret;
71
72		ret = snd_soc_dapm_add_routes(dapm, &route, 1);
73		if (ret)
74			return ret;
75	}
76
77	return ret;
78}
79EXPORT_SYMBOL_NS(asoc_sdw_ti_spk_rtd_init, "SND_SOC_SDW_UTILS");
80
81int asoc_sdw_ti_amp_init(struct snd_soc_card *card,
82			 struct snd_soc_dai_link *dai_links,
83			 struct asoc_sdw_codec_info *info,
84			 bool playback)
85{
86	if (!playback)
87		return 0;
88
89	info->amp_num++;
90
91	return 0;
92}
93EXPORT_SYMBOL_NS(asoc_sdw_ti_amp_init, "SND_SOC_SDW_UTILS");
~/ Read-only file preview.