Skip to content

Commit

Permalink
ASoC: Intel: sof_sdw: Add rt722 support
Browse files Browse the repository at this point in the history
RT722 is a multi-function codec which supports headset,
amp, and dmic functions. Each function provides a DAI
which can be used in different dailinks.

The RT711 supports up to 3 SoundWire lanes, but that
should not have any impact in the machine driver:
the lanes are allocated and controlled by the manager
and bandwidth allocation algorithm.

Signed-off-by: Chao Song <[email protected]>
  • Loading branch information
Chao Song authored and plbossart committed Nov 1, 2023
1 parent f64901e commit 3ddabe5
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 1 deletion.
1 change: 1 addition & 0 deletions sound/soc/intel/boards/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ config SND_SOC_INTEL_SOUNDWIRE_SOF_MACH
select SND_SOC_RT712_SDCA_DMIC_SDW
select SND_SOC_RT715_SDW
select SND_SOC_RT715_SDCA_SDW
select SND_SOC_RT722_SDCA_SDW
select SND_SOC_RT1308_SDW
select SND_SOC_RT1308
select SND_SOC_RT1316_SDW
Expand Down
3 changes: 2 additions & 1 deletion sound/soc/intel/boards/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ snd-soc-sof-sdw-objs += sof_sdw.o \
sof_sdw_rt5682.o sof_sdw_rt700.o \
sof_sdw_rt711.o sof_sdw_rt_sdca_jack_common.o \
sof_sdw_rt712_sdca.o sof_sdw_rt715.o \
sof_sdw_rt715_sdca.o sof_sdw_dmic.o \
sof_sdw_rt715_sdca.o sof_sdw_rt722_sdca.o \
sof_sdw_cs42l42.o sof_sdw_cs42l43.o \
sof_sdw_cs_amp.o \
sof_sdw_dmic.o \
sof_sdw_hdmi.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_RT5682_MACH) += snd-soc-sof_rt5682.o
obj-$(CONFIG_SND_SOC_INTEL_SOF_CS42L42_MACH) += snd-soc-sof_cs42l42.o
Expand Down
30 changes: 30 additions & 0 deletions sound/soc/intel/boards/sof_sdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,36 @@ static struct sof_sdw_codec_info codec_info_list[] = {
},
.dai_num = 1,
},
{
.part_id = 0x722,
.version_id = 3,
.dais = {
{
.direction = {true, true},
.dai_name = "rt722-sdca-aif1",
.dai_type = SOF_SDW_DAI_TYPE_JACK,
.dailink = {SDW_JACK_OUT_DAI_ID, SDW_JACK_IN_DAI_ID},
.init = sof_sdw_rt_sdca_jack_init,
.exit = sof_sdw_rt_sdca_jack_exit,
},
{
.direction = {true, false},
.dai_name = "rt722-sdca-aif2",
.dai_type = SOF_SDW_DAI_TYPE_AMP,
/* No feedback capability is provided by rt722-sdca codec driver*/
.dailink = {SDW_AMP_OUT_DAI_ID, SDW_UNUSED_DAI_ID},
.init = sof_sdw_rt722_spk_init,
},
{
.direction = {false, true},
.dai_name = "rt722-sdca-aif3",
.dai_type = SOF_SDW_DAI_TYPE_MIC,
.dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
.init = sof_sdw_rt722_sdca_dmic_init,
},
},
.dai_num = 3,
},
{
.part_id = 0x8373,
.dais = {
Expand Down
12 changes: 12 additions & 0 deletions sound/soc/intel/boards/sof_sdw_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ int sof_sdw_rt715_sdca_init(struct snd_soc_card *card,
struct sof_sdw_codec_info *info,
bool playback);

/* RT722-SDCA support */
int sof_sdw_rt722_spk_init(struct snd_soc_card *card,
const struct snd_soc_acpi_link_adr *link,
struct snd_soc_dai_link *dai_links,
struct sof_sdw_codec_info *info,
bool playback);
int sof_sdw_rt722_sdca_dmic_init(struct snd_soc_card *card,
const struct snd_soc_acpi_link_adr *link,
struct snd_soc_dai_link *dai_links,
struct sof_sdw_codec_info *info,
bool playback);

/* MAXIM codec support */
int sof_sdw_maxim_init(struct snd_soc_card *card,
const struct snd_soc_acpi_link_adr *link,
Expand Down
97 changes: 97 additions & 0 deletions sound/soc/intel/boards/sof_sdw_rt722_sdca.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// SPDX-License-Identifier: GPL-2.0-only
// Copyright (c) 2023 Intel Corporation

/*
* sof_sdw_rt722_sdca - Helpers to handle RT722-SDCA from generic machine driver
*/

#include <linux/device.h>
#include <linux/errno.h>
#include <linux/soundwire/sdw.h>
#include <linux/soundwire/sdw_type.h>
#include <sound/control.h>
#include <sound/soc.h>
#include <sound/soc-acpi.h>
#include <sound/soc-dapm.h>
#include "sof_sdw_common.h"

static const struct snd_soc_dapm_widget rt722_spk_widgets[] = {
SND_SOC_DAPM_SPK("Speaker", NULL),
};

static const struct snd_soc_dapm_route rt722_spk_map[] = {
{ "Speaker", NULL, "rt722 SPK" },
};

static const struct snd_kcontrol_new rt722_spk_controls[] = {
SOC_DAPM_PIN_SWITCH("Speaker"),
};

static int rt722_spk_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_card *card = rtd->card;
int ret;

card->components = devm_kasprintf(card->dev, GFP_KERNEL,
"%s spk:rt722",
card->components);
if (!card->components)
return -ENOMEM;

ret = snd_soc_add_card_controls(card, rt722_spk_controls,
ARRAY_SIZE(rt722_spk_controls));
if (ret) {
dev_err(card->dev, "failed to add rt722 spk controls: %d\n", ret);
return ret;
}

ret = snd_soc_dapm_new_controls(&card->dapm, rt722_spk_widgets,
ARRAY_SIZE(rt722_spk_widgets));
if (ret) {
dev_err(card->dev, "failed to add rt722 spk widgets: %d\n", ret);
return ret;
}

ret = snd_soc_dapm_add_routes(&card->dapm, rt722_spk_map, ARRAY_SIZE(rt722_spk_map));
if (ret)
dev_err(rtd->dev, "failed to add rt722 spk map: %d\n", ret);

return ret;
}

int sof_sdw_rt722_spk_init(struct snd_soc_card *card,
const struct snd_soc_acpi_link_adr *link,
struct snd_soc_dai_link *dai_links,
struct sof_sdw_codec_info *info,
bool playback)
{
dai_links->init = rt722_spk_init;

return 0;
}

static int rt722_sdca_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_card *card = rtd->card;
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
struct snd_soc_component *component = codec_dai->component;

card->components = devm_kasprintf(card->dev, GFP_KERNEL,
"%s mic:%s",
card->components, component->name_prefix);
if (!card->components)
return -ENOMEM;

return 0;
}

int sof_sdw_rt722_sdca_dmic_init(struct snd_soc_card *card,
const struct snd_soc_acpi_link_adr *link,
struct snd_soc_dai_link *dai_links,
struct sof_sdw_codec_info *info,
bool playback)
{
dai_links->init = rt722_sdca_dmic_rtd_init;

return 0;
}
8 changes: 8 additions & 0 deletions sound/soc/intel/boards/sof_sdw_rt_sdca_jack_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ static const struct snd_soc_dapm_route rt713_sdca_map[] = {
{ "rt713 MIC2", NULL, "Headset Mic" },
};

static const struct snd_soc_dapm_route rt722_sdca_map[] = {
{ "Headphone", NULL, "rt722 HP" },
{ "rt722 MIC2", NULL, "Headset Mic" },
};

static const struct snd_kcontrol_new rt_sdca_jack_controls[] = {
SOC_DAPM_PIN_SWITCH("Headphone"),
SOC_DAPM_PIN_SWITCH("Headset Mic"),
Expand Down Expand Up @@ -117,6 +122,9 @@ static int rt_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd)
} else if (strstr(component->name_prefix, "rt713")) {
ret = snd_soc_dapm_add_routes(&card->dapm, rt713_sdca_map,
ARRAY_SIZE(rt713_sdca_map));
} else if (strstr(component->name_prefix, "rt722")) {
ret = snd_soc_dapm_add_routes(&card->dapm, rt722_sdca_map,
ARRAY_SIZE(rt722_sdca_map));
} else {
dev_err(card->dev, "%s is not supported\n", component->name_prefix);
return -EINVAL;
Expand Down

0 comments on commit 3ddabe5

Please sign in to comment.