All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v1 16/43] sound: Add an ACPI driver for Maxim MAX98357ac
Date: Sun, 14 Jun 2020 21:57:11 -0600	[thread overview]
Message-ID: <20200614215726.v1.16.Ia2e108d28eecf6576fd92294b9871cd94143a01f@changeid> (raw)
In-Reply-To: <20200615035738.248710-1-sjg@chromium.org>

This chip is used on coral and we need to generate ACPI tables for sound
to make it work. Add a driver that does just this (i.e. at present does
not actually support playing sound).

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v1:
- Use acpi,ddn instead of acpi,desc
- Drop the unwanted acpi_device_write_gpio_desc()
- Rename max97357a to max98357a
- Add NHLT support
- Capitalise ACPI_OPS_PTR
- Rebase to master

 configs/sandbox_defconfig                    |   1 +
 doc/device-tree-bindings/sound/max98357a.txt |  22 +++
 drivers/sound/Kconfig                        |   9 ++
 drivers/sound/Makefile                       |   1 +
 drivers/sound/max98357a.c                    | 160 +++++++++++++++++++
 5 files changed, 193 insertions(+)
 create mode 100644 doc/device-tree-bindings/sound/max98357a.txt
 create mode 100644 drivers/sound/max98357a.c

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 6368e278f2..96c6e0fcd5 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -203,6 +203,7 @@ CONFIG_SMEM=y
 CONFIG_SANDBOX_SMEM=y
 CONFIG_SOUND=y
 CONFIG_SOUND_DA7219=y
+CONFIG_SOUND_MAX98357A=y
 CONFIG_SOUND_SANDBOX=y
 CONFIG_SANDBOX_SPI=y
 CONFIG_SPMI=y
diff --git a/doc/device-tree-bindings/sound/max98357a.txt b/doc/device-tree-bindings/sound/max98357a.txt
new file mode 100644
index 0000000000..4bce14ce80
--- /dev/null
+++ b/doc/device-tree-bindings/sound/max98357a.txt
@@ -0,0 +1,22 @@
+Maxim MAX98357A audio DAC
+
+This node models the Maxim MAX98357A DAC.
+
+Required properties:
+- compatible   : "maxim,max98357a"
+
+Optional properties:
+- sdmode-gpios : GPIO specifier for the chip's SD_MODE pin.
+        If this option is not specified then driver does not manage
+        the pin state (e.g. chip is always on).
+- sdmode-delay : specify delay time for SD_MODE pin.
+        If this option is specified, which means it's required i2s clocks
+        ready before SD_MODE is unmuted in order to avoid the speaker pop noise.
+        It's observed that 5ms is sufficient.
+
+Example:
+
+max98357a {
+	compatible = "maxim,max98357a";
+	sdmode-gpios = <&qcom_pinmux 25 0>;
+};
diff --git a/drivers/sound/Kconfig b/drivers/sound/Kconfig
index 7f214b97be..0948d8caab 100644
--- a/drivers/sound/Kconfig
+++ b/drivers/sound/Kconfig
@@ -113,6 +113,15 @@ config SOUND_MAX98095
 	  audio data and I2C for codec control. At present it only works
 	  with the Samsung I2S driver.
 
+config SOUND_MAX98357A
+	bool "Support Maxim max98357a audio codec"
+	depends on PCI
+	help
+	  Enable the max98357a audio codec. This is connected on PCI for
+	  audio data codec control. This is currently only capable of providing
+	  ACPI information. A full driver (with sound in U-Boot) is currently
+	  not available.
+
 config SOUND_RT5677
 	bool "Support Realtek RT5677 audio codec"
 	depends on SOUND
diff --git a/drivers/sound/Makefile b/drivers/sound/Makefile
index 8c3933ad15..9b40c8012f 100644
--- a/drivers/sound/Makefile
+++ b/drivers/sound/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_SOUND_WM8994)	+= wm8994.o
 obj-$(CONFIG_SOUND_MAX98088)	+= max98088.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98090)	+= max98090.o maxim_codec.o
 obj-$(CONFIG_SOUND_MAX98095)	+= max98095.o maxim_codec.o
+obj-$(CONFIG_SOUND_MAX98357A)	+= max98357a.o
 obj-$(CONFIG_SOUND_INTEL_HDA)	+= hda_codec.o
 obj-$(CONFIG_SOUND_I8254)	+= i8254_beep.o
 obj-$(CONFIG_SOUND_RT5677)	+= rt5677.o
diff --git a/drivers/sound/max98357a.c b/drivers/sound/max98357a.c
new file mode 100644
index 0000000000..33fdd0ba1e
--- /dev/null
+++ b/drivers/sound/max98357a.c
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * max98357a.c -- MAX98357A Audio driver
+ *
+ * Copyright 2019 Google LLC
+ * Parts taken from coreboot
+ */
+
+#include <common.h>
+#include <audio_codec.h>
+#include <dm.h>
+#include <log.h>
+#include <sound.h>
+#include <acpi/acpigen.h>
+#include <acpi/acpi_device.h>
+#include <acpi/acpi_dp.h>
+#include <asm-generic/gpio.h>
+#ifdef CONFIG_X86
+#include <asm/acpi_nhlt.h>
+#endif
+#include <dt-bindings/sound/nhlt.h>
+#include <dm/acpi.h>
+
+struct max98357a_priv {
+	struct gpio_desc sdmode_gpio;
+};
+
+static int max98357a_ofdata_to_platdata(struct udevice *dev)
+{
+	struct max98357a_priv *priv = dev_get_priv(dev);
+	int ret;
+
+	ret = gpio_request_by_name(dev, "sdmode-gpios", 0, &priv->sdmode_gpio,
+				   GPIOD_IS_IN);
+	if (ret)
+		return log_msg_ret("gpio", ret);
+
+	return 0;
+}
+
+static int max98357a_acpi_fill_ssdt(const struct udevice *dev,
+				    struct acpi_ctx *ctx)
+{
+	struct max98357a_priv *priv = dev_get_priv(dev);
+	char scope[ACPI_PATH_MAX];
+	char name[ACPI_NAME_MAX];
+	char path[ACPI_PATH_MAX];
+	struct acpi_dp *dp;
+	int ret;
+
+	ret = acpi_device_scope(dev, scope, sizeof(scope));
+	if (ret)
+		return log_msg_ret("scope", ret);
+	ret = acpi_get_name(dev, name);
+	if (ret)
+		return log_msg_ret("name", ret);
+
+	/* Device */
+	acpigen_write_scope(ctx, scope);
+	acpigen_write_device(ctx, name);
+	acpigen_write_name_string(ctx, "_HID",
+				  dev_read_string(dev, "acpi,hid"));
+	acpigen_write_name_integer(ctx, "_UID", 0);
+	acpigen_write_name_string(ctx, "_DDN",
+				  dev_read_string(dev, "acpi,ddn"));
+	acpigen_write_sta(ctx, acpi_device_status(dev));
+
+	/* Resources */
+	acpigen_write_name(ctx, "_CRS");
+	acpigen_write_resourcetemplate_header(ctx);
+	ret = acpi_device_write_gpio_desc(ctx, &priv->sdmode_gpio);
+	if (ret)
+		return log_msg_ret("gpio", ret);
+	acpigen_write_resourcetemplate_footer(ctx);
+
+	/* _DSD for devicetree properties */
+	/* This points to the first pin in the first gpio entry in _CRS */
+	ret = acpi_device_path(dev, path, sizeof(path));
+	if (ret)
+		return log_msg_ret("path", ret);
+	dp = acpi_dp_new_table("_DSD");
+	acpi_dp_add_gpio(dp, "sdmode-gpio", path, 0, 0,
+			 priv->sdmode_gpio.flags & GPIOD_ACTIVE_LOW ?
+			 ACPI_GPIO_ACTIVE_LOW : ACPI_GPIO_ACTIVE_HIGH);
+	acpi_dp_add_integer(dp, "sdmode-delay",
+			    dev_read_u32_default(dev, "sdmode-delay", 0));
+	acpi_dp_write(ctx, dp);
+
+	acpigen_pop_len(ctx); /* Device */
+	acpigen_pop_len(ctx); /* Scope */
+
+	return 0;
+}
+
+#ifdef CONFIG_X86
+static const struct nhlt_format_config max98357a_formats[] = {
+	/* 48 KHz 24-bits per sample. */
+	{
+		.num_channels = 2,
+		.sample_freq_khz = 48,
+		.container_bits_per_sample = 32,
+		.valid_bits_per_sample = 24,
+		.settings_file = "max98357-render-2ch-48khz-24b.dat",
+	},
+};
+
+static const struct nhlt_endp_descriptor max98357a_descriptors[] = {
+	{
+		.link = NHLT_LINK_SSP,
+		.device = NHLT_SSP_DEV_I2S,
+		.direction = NHLT_DIR_RENDER,
+		.vid = NHLT_VID,
+		.did = NHLT_DID_SSP,
+		.formats = max98357a_formats,
+		.num_formats = ARRAY_SIZE(max98357a_formats),
+	},
+};
+
+static int max98357a_acpi_setup_nhlt(const struct udevice *dev,
+				     struct acpi_ctx *ctx)
+{
+	u32 hwlink;
+	int ret;
+
+	if (dev_read_u32(dev, "acpi,audio-link", &hwlink))
+		return log_msg_ret("link", -EINVAL);
+
+	/* Virtual bus id of SSP links are the hardware port ids proper. */
+	ret = nhlt_add_ssp_endpoints(ctx->nhlt, hwlink, max98357a_descriptors,
+				     ARRAY_SIZE(max98357a_descriptors));
+	if (ret)
+		return log_msg_ret("add", ret);
+
+	return 0;
+}
+#endif
+
+struct acpi_ops max98357a_acpi_ops = {
+	.fill_ssdt	= max98357a_acpi_fill_ssdt,
+#ifdef CONFIG_X86
+	.setup_nhlt	= max98357a_acpi_setup_nhlt,
+#endif
+};
+
+static const struct audio_codec_ops max98357a_ops = {
+};
+
+static const struct udevice_id max98357a_ids[] = {
+	{ .compatible = "maxim,max98357a" },
+	{ }
+};
+
+U_BOOT_DRIVER(max98357a) = {
+	.name		= "max98357a",
+	.id		= UCLASS_AUDIO_CODEC,
+	.of_match	= max98357a_ids,
+	.ofdata_to_platdata	= max98357a_ofdata_to_platdata,
+	.ops		= &max98357a_ops,
+	ACPI_OPS_PTR(&max98357a_acpi_ops)
+};
-- 
2.27.0.290.gba653c62da-goog

  parent reply	other threads:[~2020-06-15  3:57 UTC|newest]

Thread overview: 143+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15  3:56 [PATCH v1 00/43] x86: Programmatic generation of ACPI tables (Part C) Simon Glass
2020-06-15  3:56 ` [PATCH v1 01/43] binman: Allow setting the ROM offset Simon Glass
2020-06-15  3:56 ` [PATCH v1 02/43] binman: Refactor binman_entry_find() to allow other nodes Simon Glass
2020-06-30  2:33   ` Bin Meng
2020-07-08  2:22     ` Simon Glass
2020-07-08  4:07       ` Bin Meng
2020-07-08 14:40         ` Tom Rini
2020-06-15  3:56 ` [PATCH v1 03/43] binman: Add way to locate an entry in memory Simon Glass
2020-06-15  3:56 ` [PATCH v1 04/43] acpi: Allow creating the GNVS to fail Simon Glass
2020-06-25 12:45   ` Wolfgang Wallner
2020-06-30  2:36   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 05/43] dtoc: Support ACPI paths in of-platdata Simon Glass
2020-06-15  3:57 ` [PATCH v1 06/43] dm: core: Add a way of overriding the ACPI device path Simon Glass
2020-06-25 12:45   ` Wolfgang Wallner
2020-06-30  2:49   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 07/43] dm: acpi: Add support for the NHLT table Simon Glass
2020-06-25 13:35   ` Wolfgang Wallner
2020-06-30  2:49   ` Bin Meng
2020-07-03  0:46     ` Simon Glass
2020-07-03  0:54       ` Bin Meng
2020-07-03  3:50         ` Simon Glass
2020-07-03  4:33           ` Bin Meng
2020-07-06 19:21             ` Simon Glass
2020-07-07  0:22               ` Bin Meng
2020-07-08  3:25                 ` Simon Glass
2020-07-12 19:37                   ` Simon Glass
2020-07-13  6:09                     ` Bin Meng
2020-07-14 13:31                       ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 08/43] acpi: Export functions to write sized values Simon Glass
2020-06-25 13:35   ` Wolfgang Wallner
2020-06-30  2:49   ` Bin Meng
2020-07-08  2:23     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 09/43] acpi: Support generation of a scope Simon Glass
2020-06-25 10:55   ` Wolfgang Wallner
2020-06-15  3:57 ` [PATCH v1 10/43] acpi: Support generation of a generic register Simon Glass
2020-06-25 10:55   ` Wolfgang Wallner
2020-06-30  2:49   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 11/43] acpi: mmc: Generate ACPI info for the PCI SD Card Simon Glass
2020-06-25 13:35   ` Wolfgang Wallner
2020-06-30  5:57   ` Bin Meng
2020-07-08  2:23     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 12/43] x86: Add bindings for NHLT Simon Glass
2020-06-25 13:36   ` Wolfgang Wallner
2020-06-30  5:57   ` Bin Meng
2020-07-08  3:32     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 13/43] acpi: Support generation of a device Simon Glass
2020-06-25 10:55   ` Wolfgang Wallner
2020-06-30  5:58   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 14/43] acpi: Support writing named values Simon Glass
2020-06-25 10:55   ` Wolfgang Wallner
2020-06-30  5:58   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 15/43] sound: Add an ACPI driver for Dialog Semicondutor da7219 Simon Glass
2020-06-30  6:06   ` Bin Meng
2020-07-08  3:32     ` Simon Glass
2020-06-15  3:57 ` Simon Glass [this message]
2020-06-15  3:57 ` [PATCH v1 17/43] x86: pinctrl: Add a way to get the pinctrl reg address Simon Glass
2020-06-25 13:36   ` Wolfgang Wallner
2020-06-30  6:42   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 18/43] x86: pinctrl: Update comment for intel_pinctrl_get_pad() Simon Glass
2020-06-30  6:42   ` Bin Meng
2020-07-03  0:46     ` Simon Glass
2020-07-03  0:58       ` Bin Meng
2020-07-06 18:42         ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 19/43] x86: pinctrl: Add multi-ACPI control Simon Glass
2020-06-30  6:42   ` Bin Meng
2020-07-02  8:11   ` Wolfgang Wallner
2020-06-15  3:57 ` [PATCH v1 20/43] x86: pinctrl: Set up itss in the probe() method Simon Glass
2020-06-30  6:42   ` Bin Meng
2020-07-03  0:46     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 21/43] x86: pinctrl: Drop the acpi_name member Simon Glass
2020-06-25 10:55   ` Wolfgang Wallner
2020-06-15  3:57 ` [PATCH v1 22/43] x86: Add support for building up an NHLT structure Simon Glass
2020-06-15  3:57 ` [PATCH v1 23/43] x86: Add error checking for csrt table generation Simon Glass
2020-06-30  7:47   ` Bin Meng
2020-07-02  8:11   ` Wolfgang Wallner
2020-06-15  3:57 ` [PATCH v1 24/43] x86: apl: Use memory-mapped access for VBT Simon Glass
2020-06-30  7:47   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 25/43] x86: gpio: Add support for obtaining ACPI info for a GPIO Simon Glass
2020-06-30  7:47   ` Bin Meng
2020-07-08  3:32     ` Simon Glass
2020-07-08 11:06       ` Wolfgang Wallner
2020-08-29 21:20         ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 26/43] i2c: designware_i2c: Add a little more debugging Simon Glass
2020-06-25 12:45   ` Wolfgang Wallner
2020-06-30  7:54   ` Bin Meng
2020-07-03  6:05   ` Heiko Schocher
2020-06-15  3:57 ` [PATCH v1 27/43] i2c: Add log_ret() on error Simon Glass
2020-06-25 12:45   ` Wolfgang Wallner
2020-06-30  7:54   ` Bin Meng
2020-07-03  6:10   ` Heiko Schocher
2020-06-15  3:57 ` [PATCH v1 28/43] i2c: designware_i2c: Support ACPI table generation Simon Glass
2020-06-25 12:46   ` Wolfgang Wallner
2020-07-08  3:33     ` Simon Glass
2020-07-03  6:10   ` Heiko Schocher
2020-06-15  3:57 ` [PATCH v1 29/43] p2sb: Add a method to hide the bus Simon Glass
2020-06-23 10:49   ` Wolfgang Wallner
2020-06-30  7:54   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 30/43] x86: apl: Support set_hide() in p2sb driver Simon Glass
2020-06-23 10:49   ` Wolfgang Wallner
2020-06-30  7:54   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 31/43] x86: apl: Hide the p2sb on exit from U-Boot Simon Glass
2020-06-23 10:49   ` Wolfgang Wallner
2020-06-30  8:27   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 32/43] pmc: Move common registers to the header file Simon Glass
2020-06-25 12:46   ` Wolfgang Wallner
2020-06-30  8:27   ` Bin Meng
2020-07-08  3:33     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 33/43] x86: irq: Support flags for acpi_gpe Simon Glass
2020-06-30  8:27   ` Bin Meng
2020-07-01 15:15   ` Wolfgang Wallner
2020-07-08  3:33     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 34/43] x86: apl: Fix save/restore of ITSS priorities Simon Glass
2020-06-30  8:27   ` Bin Meng
2020-07-08  3:33     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 35/43] x86: Add debugging to table writing Simon Glass
2020-06-25 12:46   ` Wolfgang Wallner
2020-06-30  8:27   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 36/43] x86: apl: Adjust FSP-M code to avoid hard-coded address Simon Glass
2020-06-25 10:55   ` Wolfgang Wallner
2020-06-15  3:57 ` [PATCH v1 37/43] x86: Store the coreboot table address in global_data Simon Glass
2020-06-30  8:40   ` Bin Meng
2020-07-01 15:16   ` Wolfgang Wallner
2020-07-08  3:33     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 38/43] x86: mp: Allow use of mp_run_on_cpus() without MP Simon Glass
2020-06-30  8:40   ` Bin Meng
2020-07-08  3:33     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 39/43] x86: Update the comment about booting for FSP2 Simon Glass
2020-06-25 12:46   ` Wolfgang Wallner
2020-06-30  8:40   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 40/43] x86: Drop setup_pcat_compatibility() Simon Glass
2020-06-30  8:40   ` Bin Meng
2020-07-08  3:33     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 41/43] x86: acpi: Correct the version of the MADT Simon Glass
2020-06-30  8:42   ` Bin Meng
2020-07-01 15:16   ` Wolfgang Wallner
2020-06-15  3:57 ` [PATCH v1 42/43] x86: Rename board_final_cleanup() to board_final_init() Simon Glass
2020-06-25 12:46   ` Wolfgang Wallner
2020-06-30  8:42   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 43/43] acpi: Enable ACPI table generation by default on x86 Simon Glass
2020-06-30  8:42   ` Bin Meng
2020-07-02  8:11 ` [PATCH v1 22/43] x86: Add support for building up an NHLT structure Wolfgang Wallner
2020-07-08  3:32   ` Simon Glass
2020-07-08 11:05     ` Wolfgang Wallner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200614215726.v1.16.Ia2e108d28eecf6576fd92294b9871cd94143a01f@changeid \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.