Merge: ALSA: hda/tegra: Add Tegra264 support

MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/1182

JIRA: https://issues.redhat.com/browse/RHEL-102696

## Summary of Changes

The following series adds ACPI HDA sound driver for NVIDIA Tegra264 devices. Also adds needed IDs for enablement of this platform.

Signed-off-by: Marcin Juszkiewicz <mjuszkiewicz@redhat.com>

Approved-by: Tony Camuso <tcamuso@redhat.com>
Approved-by: Desnes Nunes <desnesn@redhat.com>
Approved-by: John W. Linville <linville@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: Julio Faracco <jfaracco@redhat.com>
This commit is contained in:
Julio Faracco 2025-08-20 16:24:30 -03:00
commit 64728bb7fb
10 changed files with 408 additions and 6 deletions

View File

@ -0,0 +1 @@
# CONFIG_SND_HDA_ACPI is not set

View File

@ -0,0 +1 @@
# CONFIG_SND_HDA_ACPI is not set

View File

@ -0,0 +1 @@
# CONFIG_SND_HDA_ACPI is not set

View File

@ -0,0 +1 @@
CONFIG_SND_HDA_ACPI=m

View File

@ -0,0 +1 @@
CONFIG_SND_HDA_ACPI=m

View File

@ -42,6 +42,17 @@ config SND_HDA_TEGRA
To compile this driver as a module, choose M here: the module
will be called snd-hda-tegra.
config SND_HDA_ACPI
tristate "HD Audio ACPI"
depends on ACPI
select SND_HDA
help
Say Y here to include support for Azalia-compatible HDA controllers
which are advertised via ACPI objects.
To compile this driver as a module, choose M here: the module
will be called snd-hda-acpi.
if SND_HDA
config SND_HDA_HWDEP

View File

@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
snd-hda-intel-y := hda_intel.o
snd-hda-tegra-y := hda_tegra.o
snd-hda-acpi-y := hda_acpi.o
snd-hda-codec-y := hda_bind.o hda_codec.o hda_jack.o hda_auto_parser.o hda_sysfs.o
snd-hda-codec-y += hda_controller.o
@ -80,3 +81,4 @@ obj-$(CONFIG_SND_HDA_SCODEC_TAS2781_SPI) += snd-hda-scodec-tas2781-spi.o
# when built in kernel
obj-$(CONFIG_SND_HDA_INTEL) += snd-hda-intel.o
obj-$(CONFIG_SND_HDA_TEGRA) += snd-hda-tegra.o
obj-$(CONFIG_SND_HDA_ACPI) += snd-hda-acpi.o

325
sound/pci/hda/hda_acpi.c Normal file
View File

@ -0,0 +1,325 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* ALSA driver for ACPI-based HDA Controllers.
*/
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/acpi.h>
#include <sound/hda_codec.h>
#include "hda_controller.h"
struct hda_acpi {
struct azx azx;
struct snd_card *card;
struct platform_device *pdev;
void __iomem *regs;
struct work_struct probe_work;
const struct hda_data *data;
};
/**
* struct hda_data - Optional device-specific data
* @short_name: Used for the ALSA card name; defaults to KBUILD_MODNAME
* @long_name: Used for longer description; defaults to short_name
* @flags: Passed to &azx->driver_caps
*
* A pointer to a record of this type may be stored in the
* &acpi_device_id->driver_data field of an ACPI match table entry in order to
* customize the naming and behavior of a particular device. All fields are
* optional and sensible defaults will be selected in their absence.
*/
struct hda_data {
const char *short_name;
const char *long_name;
unsigned long flags;
};
static int hda_acpi_dev_disconnect(struct snd_device *device)
{
struct azx *chip = device->device_data;
chip->bus.shutdown = 1;
return 0;
}
static int hda_acpi_dev_free(struct snd_device *device)
{
struct azx *azx = device->device_data;
struct hda_acpi *hda = container_of(azx, struct hda_acpi, azx);
cancel_work_sync(&hda->probe_work);
if (azx_bus(azx)->chip_init) {
azx_stop_all_streams(azx);
azx_stop_chip(azx);
}
azx_free_stream_pages(azx);
azx_free_streams(azx);
snd_hdac_bus_exit(azx_bus(azx));
return 0;
}
static int hda_acpi_init(struct hda_acpi *hda)
{
struct hdac_bus *bus = azx_bus(&hda->azx);
struct snd_card *card = hda->azx.card;
struct device *dev = &hda->pdev->dev;
struct azx *azx = &hda->azx;
struct resource *res;
unsigned short gcap;
const char *sname, *lname;
int err, irq;
/* The base address for the HDA registers and the interrupt are wrapped
* in an ACPI _CRS object which can be parsed by platform_get_irq() and
* devm_platform_get_and_ioremap_resource()
*/
irq = platform_get_irq(hda->pdev, 0);
if (irq < 0)
return irq;
hda->regs = devm_platform_get_and_ioremap_resource(hda->pdev, 0, &res);
if (IS_ERR(hda->regs))
return PTR_ERR(hda->regs);
bus->remap_addr = hda->regs;
bus->addr = res->start;
err = devm_request_irq(dev, irq, azx_interrupt,
IRQF_SHARED, KBUILD_MODNAME, azx);
if (err) {
dev_err(dev, "unable to request IRQ %d, disabling device\n",
irq);
return err;
}
bus->irq = irq;
bus->dma_stop_delay = 100;
card->sync_irq = bus->irq;
gcap = azx_readw(azx, GCAP);
dev_dbg(dev, "chipset global capabilities = 0x%x\n", gcap);
azx->align_buffer_size = 1;
azx->capture_streams = (gcap >> 8) & 0x0f;
azx->playback_streams = (gcap >> 12) & 0x0f;
azx->capture_index_offset = 0;
azx->playback_index_offset = azx->capture_streams;
azx->num_streams = azx->playback_streams + azx->capture_streams;
err = azx_init_streams(azx);
if (err < 0) {
dev_err(dev, "failed to initialize streams: %d\n", err);
return err;
}
err = azx_alloc_stream_pages(azx);
if (err < 0) {
dev_err(dev, "failed to allocate stream pages: %d\n", err);
return err;
}
azx_init_chip(azx, 1);
if (!bus->codec_mask) {
dev_err(dev, "no codecs found!\n");
return -ENODEV;
}
strscpy(card->driver, "hda-acpi");
sname = hda->data->short_name ? hda->data->short_name : KBUILD_MODNAME;
if (strlen(sname) > sizeof(card->shortname))
dev_info(dev, "truncating shortname for card %s\n", sname);
strscpy(card->shortname, sname);
lname = hda->data->long_name ? hda->data->long_name : sname;
snprintf(card->longname, sizeof(card->longname),
"%s at 0x%lx irq %i", lname, bus->addr, bus->irq);
return 0;
}
static void hda_acpi_probe_work(struct work_struct *work)
{
struct hda_acpi *hda = container_of(work, struct hda_acpi, probe_work);
struct azx *chip = &hda->azx;
int err;
err = hda_acpi_init(hda);
if (err < 0)
return;
err = azx_probe_codecs(chip, 8);
if (err < 0)
return;
err = azx_codec_configure(chip);
if (err < 0)
return;
err = snd_card_register(chip->card);
if (err < 0)
return;
chip->running = 1;
}
static int hda_acpi_create(struct hda_acpi *hda)
{
static const struct snd_device_ops ops = {
.dev_disconnect = hda_acpi_dev_disconnect,
.dev_free = hda_acpi_dev_free,
};
static const struct hda_controller_ops null_ops;
struct azx *azx = &hda->azx;
int err;
mutex_init(&azx->open_mutex);
azx->card = hda->card;
INIT_LIST_HEAD(&azx->pcm_list);
azx->ops = &null_ops;
azx->driver_caps = hda->data->flags;
azx->driver_type = hda->data->flags & 0xff;
azx->codec_probe_mask = -1;
err = azx_bus_init(azx, NULL);
if (err < 0)
return err;
err = snd_device_new(hda->card, SNDRV_DEV_LOWLEVEL, &hda->azx, &ops);
if (err < 0) {
dev_err(&hda->pdev->dev, "Error creating device\n");
return err;
}
return 0;
}
static int hda_acpi_probe(struct platform_device *pdev)
{
struct hda_acpi *hda;
int err;
hda = devm_kzalloc(&pdev->dev, sizeof(*hda), GFP_KERNEL);
if (!hda)
return -ENOMEM;
hda->pdev = pdev;
hda->data = acpi_device_get_match_data(&pdev->dev);
/* Fall back to defaults if the table didn't have a *struct hda_data */
if (!hda->data)
hda->data = devm_kzalloc(&pdev->dev, sizeof(*hda->data),
GFP_KERNEL);
if (!hda->data)
return -ENOMEM;
err = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
THIS_MODULE, 0, &hda->card);
if (err < 0) {
dev_err(&pdev->dev, "Error creating card!\n");
return err;
}
INIT_WORK(&hda->probe_work, hda_acpi_probe_work);
err = hda_acpi_create(hda);
if (err < 0)
goto out_free;
hda->card->private_data = &hda->azx;
dev_set_drvdata(&pdev->dev, hda->card);
schedule_work(&hda->probe_work);
return 0;
out_free:
snd_card_free(hda->card);
return err;
}
static void hda_acpi_remove(struct platform_device *pdev)
{
snd_card_free(dev_get_drvdata(&pdev->dev));
}
static void hda_acpi_shutdown(struct platform_device *pdev)
{
struct snd_card *card = dev_get_drvdata(&pdev->dev);
struct azx *chip;
if (!card)
return;
chip = card->private_data;
if (chip && chip->running)
azx_stop_chip(chip);
}
static int hda_acpi_suspend(struct device *dev)
{
struct snd_card *card = dev_get_drvdata(dev);
int rc;
rc = pm_runtime_force_suspend(dev);
if (rc < 0)
return rc;
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
return 0;
}
static int hda_acpi_resume(struct device *dev)
{
struct snd_card *card = dev_get_drvdata(dev);
int rc;
rc = pm_runtime_force_resume(dev);
if (rc < 0)
return rc;
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
static const struct dev_pm_ops hda_acpi_pm = {
SYSTEM_SLEEP_PM_OPS(hda_acpi_suspend, hda_acpi_resume)
};
static const struct hda_data nvidia_hda_data = {
.short_name = "NVIDIA",
.long_name = "NVIDIA HDA Controller",
.flags = AZX_DCAPS_CORBRP_SELF_CLEAR,
};
static const struct acpi_device_id hda_acpi_match[] = {
{ .id = "NVDA2014", .driver_data = (uintptr_t) &nvidia_hda_data },
{ .id = "NVDA2015", .driver_data = (uintptr_t) &nvidia_hda_data },
{},
};
MODULE_DEVICE_TABLE(acpi, hda_acpi_match);
static struct platform_driver hda_acpi_platform_driver = {
.driver = {
.name = KBUILD_MODNAME,
.pm = &hda_acpi_pm,
.acpi_match_table = hda_acpi_match,
},
.probe = hda_acpi_probe,
.remove = hda_acpi_remove,
.shutdown = hda_acpi_shutdown,
};
module_platform_driver(hda_acpi_platform_driver);
MODULE_DESCRIPTION("Driver for ACPI-based HDA Controllers");
MODULE_LICENSE("GPL");

View File

@ -72,6 +72,10 @@
struct hda_tegra_soc {
bool has_hda2codec_2x_reset;
bool has_hda2hdmi;
bool has_hda2codec_2x;
bool input_stream;
bool always_on;
bool requires_init;
};
struct hda_tegra {
@ -187,7 +191,9 @@ static int hda_tegra_runtime_resume(struct device *dev)
if (rc != 0)
return rc;
if (chip->running) {
hda_tegra_init(hda);
if (hda->soc->requires_init)
hda_tegra_init(hda);
azx_init_chip(chip, 1);
/* disable controller wake up event*/
azx_writew(chip, WAKEEN, azx_readw(chip, WAKEEN) &
@ -250,7 +256,8 @@ static int hda_tegra_init_chip(struct azx *chip, struct platform_device *pdev)
bus->remap_addr = hda->regs + HDA_BAR0;
bus->addr = res->start + HDA_BAR0;
hda_tegra_init(hda);
if (hda->soc->requires_init)
hda_tegra_init(hda);
return 0;
}
@ -323,7 +330,7 @@ static int hda_tegra_first_init(struct azx *chip, struct platform_device *pdev)
* starts with offset 0 which is wrong as HW register for output stream
* offset starts with 4.
*/
if (of_device_is_compatible(np, "nvidia,tegra234-hda"))
if (!hda->soc->input_stream)
chip->capture_streams = 4;
chip->playback_streams = (gcap >> 12) & 0x0f;
@ -419,7 +426,6 @@ static int hda_tegra_create(struct snd_card *card,
chip->driver_caps = driver_caps;
chip->driver_type = driver_caps & 0xff;
chip->dev_index = 0;
chip->jackpoll_interval = msecs_to_jiffies(5000);
INIT_LIST_HEAD(&chip->pcm_list);
chip->codec_probe_mask = -1;
@ -436,7 +442,16 @@ static int hda_tegra_create(struct snd_card *card,
chip->bus.core.sync_write = 0;
chip->bus.core.needs_damn_long_delay = 1;
chip->bus.core.aligned_mmio = 1;
chip->bus.jackpoll_in_suspend = 1;
/*
* HDA power domain and clocks are always on for Tegra264 and
* the jack detection logic would work always, so no need of
* jack polling mechanism running.
*/
if (!hda->soc->always_on) {
chip->jackpoll_interval = msecs_to_jiffies(5000);
chip->bus.jackpoll_in_suspend = 1;
}
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
if (err < 0) {
@ -450,22 +465,44 @@ static int hda_tegra_create(struct snd_card *card,
static const struct hda_tegra_soc tegra30_data = {
.has_hda2codec_2x_reset = true,
.has_hda2hdmi = true,
.has_hda2codec_2x = true,
.input_stream = true,
.always_on = false,
.requires_init = true,
};
static const struct hda_tegra_soc tegra194_data = {
.has_hda2codec_2x_reset = false,
.has_hda2hdmi = true,
.has_hda2codec_2x = true,
.input_stream = true,
.always_on = false,
.requires_init = true,
};
static const struct hda_tegra_soc tegra234_data = {
.has_hda2codec_2x_reset = true,
.has_hda2hdmi = false,
.has_hda2codec_2x = true,
.input_stream = false,
.always_on = false,
.requires_init = true,
};
static const struct hda_tegra_soc tegra264_data = {
.has_hda2codec_2x_reset = true,
.has_hda2hdmi = false,
.has_hda2codec_2x = false,
.input_stream = false,
.always_on = true,
.requires_init = false,
};
static const struct of_device_id hda_tegra_match[] = {
{ .compatible = "nvidia,tegra30-hda", .data = &tegra30_data },
{ .compatible = "nvidia,tegra194-hda", .data = &tegra194_data },
{ .compatible = "nvidia,tegra234-hda", .data = &tegra234_data },
{ .compatible = "nvidia,tegra264-hda", .data = &tegra264_data },
{},
};
MODULE_DEVICE_TABLE(of, hda_tegra_match);
@ -520,7 +557,9 @@ static int hda_tegra_probe(struct platform_device *pdev)
hda->clocks[hda->nclocks++].id = "hda";
if (hda->soc->has_hda2hdmi)
hda->clocks[hda->nclocks++].id = "hda2hdmi";
hda->clocks[hda->nclocks++].id = "hda2codec_2x";
if (hda->soc->has_hda2codec_2x)
hda->clocks[hda->nclocks++].id = "hda2codec_2x";
err = devm_clk_bulk_get(&pdev->dev, hda->nclocks, hda->clocks);
if (err < 0)

View File

@ -4551,6 +4551,9 @@ HDA_CODEC_ENTRY(0x10de002e, "Tegra186 HDMI/DP1", patch_tegra_hdmi),
HDA_CODEC_ENTRY(0x10de002f, "Tegra194 HDMI/DP2", patch_tegra_hdmi),
HDA_CODEC_ENTRY(0x10de0030, "Tegra194 HDMI/DP3", patch_tegra_hdmi),
HDA_CODEC_ENTRY(0x10de0031, "Tegra234 HDMI/DP", patch_tegra234_hdmi),
HDA_CODEC_ENTRY(0x10de0033, "SoC 33 HDMI/DP", patch_tegra234_hdmi),
HDA_CODEC_ENTRY(0x10de0034, "Tegra264 HDMI/DP", patch_tegra234_hdmi),
HDA_CODEC_ENTRY(0x10de0035, "SoC 35 HDMI/DP", patch_tegra234_hdmi),
HDA_CODEC_ENTRY(0x10de0040, "GPU 40 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de0041, "GPU 41 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de0042, "GPU 42 HDMI/DP", patch_nvhdmi),
@ -4589,15 +4592,32 @@ HDA_CODEC_ENTRY(0x10de0097, "GPU 97 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de0098, "GPU 98 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de0099, "GPU 99 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de009a, "GPU 9a HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de009b, "GPU 9b HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de009c, "GPU 9c HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de009d, "GPU 9d HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de009e, "GPU 9e HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de009f, "GPU 9f HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00a0, "GPU a0 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00a1, "GPU a1 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00a3, "GPU a3 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00a4, "GPU a4 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00a5, "GPU a5 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00a6, "GPU a6 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00a7, "GPU a7 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00a8, "GPU a8 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00a9, "GPU a9 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00aa, "GPU aa HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00ab, "GPU ab HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00ad, "GPU ad HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00ae, "GPU ae HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00af, "GPU af HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00b0, "GPU b0 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00b1, "GPU b1 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00c0, "GPU c0 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00c1, "GPU c1 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00c3, "GPU c3 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00c4, "GPU c4 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de00c5, "GPU c5 HDMI/DP", patch_nvhdmi),
HDA_CODEC_ENTRY(0x10de8001, "MCP73 HDMI", patch_nvhdmi_2ch),
HDA_CODEC_ENTRY(0x10de8067, "MCP67/68 HDMI", patch_nvhdmi_2ch),
HDA_CODEC_ENTRY(0x67663d82, "Arise 82 HDMI/DP", patch_gf_hdmi),