Skip to content

Commit

Permalink
ASoC: amd: acp: Add machine driver that enables sound for systems wit…
Browse files Browse the repository at this point in the history
…h a ES8336 codec

This commit enables sound for a line of Huawei laptops that use
the ES8336 codec which is connected to the ACP3X module.

Signed-off-by: Marian Postevca <posteuca@mutex.one>
  • Loading branch information
Marian Postevca authored and intel-lab-lkp committed Mar 20, 2023
1 parent a54ac66 commit 0562079
Show file tree
Hide file tree
Showing 8 changed files with 657 additions and 17 deletions.
70 changes: 70 additions & 0 deletions sound/soc/amd/acp-config.c
Expand Up @@ -47,6 +47,76 @@ static const struct config_entry config_table[] = {
{}
},
},
{
.flags = FLAG_AMD_LEGACY,
.device = ACP_PCI_DEV_ID,
.dmi_table = (const struct dmi_system_id []) {
{
.matches = {
DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"),
DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "KLVL-WXXW"),
DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"),
},
},
{}
},
},
{
.flags = FLAG_AMD_LEGACY,
.device = ACP_PCI_DEV_ID,
.dmi_table = (const struct dmi_system_id []) {
{
.matches = {
DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"),
DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "KLVL-WXX9"),
DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"),
},
},
{}
},
},
{
.flags = FLAG_AMD_LEGACY,
.device = ACP_PCI_DEV_ID,
.dmi_table = (const struct dmi_system_id []) {
{
.matches = {
DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"),
DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "BOM-WXX9"),
DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1010"),
},
},
{}
},
},
{
.flags = FLAG_AMD_LEGACY,
.device = ACP_PCI_DEV_ID,
.dmi_table = (const struct dmi_system_id []) {
{
.matches = {
DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"),
DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HVY-WXX9"),
DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1020"),
},
},
{}
},
},
{
.flags = FLAG_AMD_LEGACY,
.device = ACP_PCI_DEV_ID,
.dmi_table = (const struct dmi_system_id []) {
{
.matches = {
DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "HUAWEI"),
DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HVY-WXX9"),
DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "M1040"),
},
},
{}
},
},
};

int snd_amd_acp_find_config(struct pci_dev *pci)
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/amd/acp/Makefile
Expand Up @@ -16,7 +16,7 @@ snd-acp-rembrandt-objs := acp-rembrandt.o

#machine specific driver
snd-acp-mach-objs := acp-mach-common.o
snd-acp-legacy-mach-objs := acp-legacy-mach.o
snd-acp-legacy-mach-objs := acp-legacy-mach.o acp3x-es83xx/acp3x-es83xx.o
snd-acp-sof-mach-objs := acp-sof-mach.o

obj-$(CONFIG_SND_SOC_AMD_ACP_PCM) += snd-acp-pcm.o
Expand Down
105 changes: 89 additions & 16 deletions sound/soc/amd/acp/acp-legacy-mach.c
Expand Up @@ -20,6 +20,7 @@
#include <linux/module.h>

#include "acp-mach.h"
#include "acp3x-es83xx/acp3x-es83xx.h"

static struct acp_card_drvdata rt5682_rt1019_data = {
.hs_cpu_id = I2S_SP,
Expand Down Expand Up @@ -51,6 +52,14 @@ static struct acp_card_drvdata rt5682s_rt1019_data = {
.tdm_mode = false,
};

static struct acp_card_drvdata es83xx_rn_data = {
.hs_cpu_id = I2S_SP,
.dmic_cpu_id = DMIC,
.hs_codec_id = ES83XX,
.dmic_codec_id = DMIC,
.platform = RENOIR,
};

static struct acp_card_drvdata max_nau8825_data = {
.hs_cpu_id = I2S_HS,
.amp_cpu_id = I2S_HS,
Expand Down Expand Up @@ -92,6 +101,33 @@ static const struct snd_soc_dapm_widget acp_widgets[] = {
SND_SOC_DAPM_SPK("Right Spk", NULL),
};

static bool acp_asoc_init_ops(struct acp_card_drvdata *priv)
{
bool has_ops = false;

if (priv->hs_codec_id == ES83XX) {
has_ops = true;
acp3x_es83xx_init_ops(&priv->ops);
}
return has_ops;
}

static int acp_asoc_suspend_pre(struct snd_soc_card *card)
{
int ret;

ret = acp_ops_suspend_pre(card);
return ret == 1 ? 0 : ret;
}

static int acp_asoc_resume_post(struct snd_soc_card *card)
{
int ret;

ret = acp_ops_resume_post(card);
return ret == 1 ? 0 : ret;
}

static int acp_asoc_probe(struct platform_device *pdev)
{
struct snd_soc_card *card = NULL;
Expand All @@ -100,38 +136,70 @@ static int acp_asoc_probe(struct platform_device *pdev)
struct acp_card_drvdata *acp_card_drvdata;
int ret;

if (!pdev->id_entry)
return -EINVAL;
if (!pdev->id_entry) {
ret = -EINVAL;
goto out;
}

card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
if (!card)
return -ENOMEM;
if (!card) {
ret = -ENOMEM;
goto out;
}

card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
acp_card_drvdata = card->drvdata;
acp_card_drvdata->acpi_mach = (struct snd_soc_acpi_mach *)pdev->dev.platform_data;
card->dev = dev;
card->owner = THIS_MODULE;
card->name = pdev->id_entry->name;
card->dapm_widgets = acp_widgets;
card->num_dapm_widgets = ARRAY_SIZE(acp_widgets);
card->controls = acp_controls;
card->num_controls = ARRAY_SIZE(acp_controls);
card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;

acp_card_drvdata = card->drvdata;
acp_asoc_init_ops(card->drvdata);

ret = acp_ops_configure_widgets(card);
if (ret == 1) {
card->dapm_widgets = acp_widgets;
card->num_dapm_widgets = ARRAY_SIZE(acp_widgets);
card->controls = acp_controls;
card->num_controls = ARRAY_SIZE(acp_controls);
} else if (ret < 0) {
dev_err(&pdev->dev,
"Cannot configure widgets for card (%s): %d\n",
card->name, ret);
goto out;
}
card->suspend_pre = acp_asoc_suspend_pre;
card->resume_post = acp_asoc_resume_post;

ret = acp_ops_probe(card);
if (ret < 0) {
dev_err(&pdev->dev,
"Cannot probe card (%s): %d\n",
card->name, ret);
goto out;
}

dmi_id = dmi_first_match(acp_quirk_table);
if (dmi_id && dmi_id->driver_data)
acp_card_drvdata->tdm_mode = dmi_id->driver_data;

acp_legacy_dai_links_create(card);
ret = acp_legacy_dai_links_create(card);
if (ret) {
dev_err(&pdev->dev,
"Cannot create dai links for card (%s): %d\n",
card->name, ret);
goto out;
}

ret = devm_snd_soc_register_card(&pdev->dev, card);
if (ret) {
dev_err(&pdev->dev,
"devm_snd_soc_register_card(%s) failed: %d\n",
card->name, ret);
return ret;
"devm_snd_soc_register_card(%s) failed: %d\n",
card->name, ret);
goto out;
}

return 0;
out:
return ret;
}

static const struct platform_device_id board_ids[] = {
Expand All @@ -147,6 +215,10 @@ static const struct platform_device_id board_ids[] = {
.name = "acp3xalc5682s1019",
.driver_data = (kernel_ulong_t)&rt5682s_rt1019_data,
},
{
.name = "acp3x-es83xx",
.driver_data = (kernel_ulong_t)&es83xx_rn_data,
},
{
.name = "rmb-nau8825-max",
.driver_data = (kernel_ulong_t)&max_nau8825_data,
Expand All @@ -173,6 +245,7 @@ MODULE_DESCRIPTION("ACP chrome audio support");
MODULE_ALIAS("platform:acp3xalc56821019");
MODULE_ALIAS("platform:acp3xalc5682sm98360");
MODULE_ALIAS("platform:acp3xalc5682s1019");
MODULE_ALIAS("platform:acp3x-es83xx");
MODULE_ALIAS("platform:rmb-nau8825-max");
MODULE_ALIAS("platform:rmb-rt5682s-rt1019");
MODULE_LICENSE("GPL v2");
8 changes: 8 additions & 0 deletions sound/soc/amd/acp/acp-mach-common.c
Expand Up @@ -1053,6 +1053,7 @@ int acp_legacy_dai_links_create(struct snd_soc_card *card)
struct device *dev = card->dev;
struct acp_card_drvdata *drv_data = card->drvdata;
int i = 0, num_links = 0;
int rc;

if (drv_data->hs_cpu_id)
num_links++;
Expand Down Expand Up @@ -1091,6 +1092,13 @@ int acp_legacy_dai_links_create(struct snd_soc_card *card)
links[i].init = acp_card_rt5682s_init;
links[i].ops = &acp_card_rt5682s_ops;
}
if (drv_data->hs_codec_id == ES83XX) {
rc = acp_ops_configure_link(card, &links[i]);
if (rc != 0) {
dev_err(dev, "Failed to configure link for ES83XX: %d\n", rc);
return rc;
}
}
i++;
}

Expand Down
2 changes: 2 additions & 0 deletions sound/soc/amd/acp/acp-mach.h
Expand Up @@ -45,6 +45,7 @@ enum codec_endpoints {
MAX98360A,
RT5682S,
NAU8825,
ES83XX,
};

enum platform_end_point {
Expand Down Expand Up @@ -72,6 +73,7 @@ struct acp_card_drvdata {
struct clk *wclk;
struct clk *bclk;
struct acp_mach_ops ops;
struct snd_soc_acpi_mach *acpi_mach;
void *mach_priv;
bool soc_mclk;
bool tdm_mode;
Expand Down
4 changes: 4 additions & 0 deletions sound/soc/amd/acp/acp-renoir.c
Expand Up @@ -83,6 +83,10 @@ static struct snd_soc_acpi_mach snd_soc_acpi_amd_acp_machines[] = {
.id = "AMDI1019",
.drv_name = "renoir-acp",
},
{
.id = "ESSX8336",
.drv_name = "acp3x-es83xx",
},
{},
};

Expand Down

0 comments on commit 0562079

Please sign in to comment.