Skip to content

Commit 4dd339c

Browse files
committed
ASoC: sdw_utils: Add cs42l45 support functions
Add the helper functions into the machine driver for the cs42l45, this will register a jack for jack detection and add things into to the components string if they are needed. Signed-off-by: Charles Keepax <[email protected]>
1 parent fd740ca commit 4dd339c

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

include/sound/soc_sdw_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ int asoc_sdw_cs42l42_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_da
257257
int asoc_sdw_cs42l43_hs_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
258258
int asoc_sdw_cs42l43_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
259259
int asoc_sdw_cs42l43_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
260+
int asoc_sdw_cs42l45_hs_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
261+
int asoc_sdw_cs42l45_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
260262
int asoc_sdw_cs_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
261263
int asoc_sdw_maxim_spk_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai);
262264
/* TI */

sound/soc/sdw_utils/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ snd-soc-sdw-utils-y := soc_sdw_utils.o soc_sdw_dmic.o soc_sdw_rt_dmic.o \
55
soc_sdw_rt_amp.o soc_sdw_rt_mf_sdca.o \
66
soc_sdw_bridge_cs35l56.o \
77
soc_sdw_cs42l42.o soc_sdw_cs42l43.o \
8+
soc_sdw_cs42l45.o \
89
soc_sdw_cs_amp.o \
910
soc_sdw_maxim.o \
1011
soc_sdw_ti_amp.o
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
// Based on sof_sdw_rt5682.c
3+
// This file incorporates work covered by the following copyright notice:
4+
// Copyright (c) 2023 Intel Corporation
5+
// Copyright (c) 2024 Advanced Micro Devices, Inc.
6+
7+
/*
8+
* soc_sdw_cs42l45 - Helpers to handle CS42L45 from generic machine driver
9+
*/
10+
#include <linux/device.h>
11+
#include <linux/errno.h>
12+
#include <sound/jack.h>
13+
#include <sound/soc.h>
14+
#include <sound/soc-card.h>
15+
#include <sound/soc-component.h>
16+
#include <sound/soc-dai.h>
17+
#include <sound/soc_sdw_utils.h>
18+
19+
static struct snd_soc_jack_pin soc_jack_pins[] = {
20+
{
21+
.pin = "cs42l45 OT 43",
22+
.mask = SND_JACK_HEADPHONE,
23+
},
24+
{
25+
.pin = "cs42l45 OT 45",
26+
.mask = SND_JACK_HEADPHONE,
27+
},
28+
{
29+
.pin = "cs42l45 IT 31",
30+
.mask = SND_JACK_MICROPHONE,
31+
},
32+
{
33+
.pin = "cs42l45 IT 33",
34+
.mask = SND_JACK_MICROPHONE,
35+
},
36+
};
37+
38+
int asoc_sdw_cs42l45_hs_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
39+
{
40+
struct snd_soc_card *card = rtd->card;
41+
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
42+
struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card);
43+
struct snd_soc_jack *jack = &ctx->sdw_headset;
44+
int ret;
45+
46+
card->components = devm_kasprintf(card->dev, GFP_KERNEL, "%s hs:cs42l45",
47+
card->components);
48+
if (!card->components)
49+
return -ENOMEM;
50+
51+
ret = snd_soc_card_jack_new_pins(card, "Jack", SND_JACK_MECHANICAL |
52+
SND_JACK_HEADSET | SND_JACK_LINEOUT, jack,
53+
soc_jack_pins, ARRAY_SIZE(soc_jack_pins));
54+
if (ret) {
55+
dev_err(card->dev, "Failed to create jack: %d\n", ret);
56+
return ret;
57+
}
58+
59+
ret = snd_soc_component_set_jack(component, jack, NULL);
60+
if (ret) {
61+
dev_err(card->dev, "Failed to register jack: %d\n", ret);
62+
return ret;
63+
}
64+
65+
return 0;
66+
}
67+
EXPORT_SYMBOL_NS(asoc_sdw_cs42l45_hs_rtd_init, "SND_SOC_SDW_UTILS");
68+
69+
int asoc_sdw_cs42l45_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
70+
{
71+
struct snd_soc_card *card = rtd->card;
72+
73+
card->components = devm_kasprintf(card->dev, GFP_KERNEL, "%s mic:cs42l45-dmic",
74+
card->components);
75+
if (!card->components)
76+
return -ENOMEM;
77+
78+
return 0;
79+
}
80+
EXPORT_SYMBOL_NS(asoc_sdw_cs42l45_dmic_rtd_init, "SND_SOC_SDW_UTILS");

0 commit comments

Comments
 (0)