linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 0/4] Add bridged amplifiers to cs42l43
@ 2024-04-15 14:09 Charles Keepax
  2024-04-15 14:09 ` [PATCH v6 1/4] gpio: swnode: Add ability to specify native chip selects for SPI Charles Keepax
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Charles Keepax @ 2024-04-15 14:09 UTC (permalink / raw)
  To: broonie, linus.walleij, brgl
  Cc: andy.shevchenko, bard.liao, linux-gpio, linux-spi, patches

In some cs42l43 systems a couple of cs35l56 amplifiers are attached
to the cs42l43's SPI and I2S. On Windows the cs42l43 is controlled
by a SDCA class driver and these two amplifiers are controlled by
firmware running on the cs42l43. However, under Linux the decision
was made to interact with the cs42l43 directly, affording the user
greater control over the audio system. However, this has resulted
in an issue where these two bridged cs35l56 amplifiers are not
populated in ACPI and must be added manually. There is at least an
SDCA extension unit DT entry we can key off.

The process of adding this is handled using a software node, firstly the
ability to add native chip selects to software nodes must be added.
Secondly, an additional flag for naming the SPI devices is added this
allows the machine driver to key to the correct amplifier. Then finally,
the cs42l43 SPI driver adds the two amplifiers directly onto its SPI
bus.

An additional series will follow soon to add the audio machine driver
parts (in the sof-sdw driver), however that is fairly orthogonal to
this part of the process, getting the actual amplifiers registered.

Thanks,
Charles

Series changes since v5:
 - Add back help for GPIO_SWNODE_UNDEFINED
 - Correct some typos
 - Only check for undefined swnode if the Kconfig is set
 - Add a pr_fmt
 - Move swnode_gpio_undefined to include/linux/gpio/property.h
 - Remove includes of fwnode.h
 - Use %pwfP to get firmware node name
 - Remove NULL check on acpi_handle

Series changes since v4:
 - Remove extraneous fwnode_handle_puts in driver/spi/spi-cs42l43.c
 - Make Kconfig for swnode undef gpios not user visible
 - Add some missing headers
 - Add patch to update handling in spi_dev_set_name
 - Remove stray blank line
 - Use ACPI_HANDLE_FWNODE

Series changes since v3:
 - Add Kconfig to make swnode conditionally built
 - Add define for swnode name
 - Add custom init and exit calls to register swnode
 - Use export namespaces
 - Always name swnode SPI devices after the node name
 - Correct some header includes
 - Use HZ_PER_MHZ
 - Use some swnode helper macros
 - Use acpi_get_local_address
 - Correct some handle puts
 - Add some dev_err_probes

Series changes since v2:
 - Add missing fwnode_handle_puts in driver/spi/spi-cs423l43.c

Series changes since v1:
 - Add missing statics in driver/spi/spi-cs42l43.c


Charles Keepax (3):
  gpio: swnode: Add ability to specify native chip selects for SPI
  spi: Switch to using is_acpi_device_node() in spi_dev_set_name()
  spi: Update swnode based SPI devices to use the fwnode name

Maciej Strozek (1):
  spi: cs42l43: Add bridged cs35l56 amplifiers

 drivers/gpio/Kconfig          |   9 +++
 drivers/gpio/gpiolib-swnode.c |  44 +++++++++++
 drivers/spi/Kconfig           |   1 +
 drivers/spi/spi-cs42l43.c     | 135 +++++++++++++++++++++++++++++++++-
 drivers/spi/spi.c             |  12 ++-
 include/linux/gpio/property.h |   4 +
 6 files changed, 200 insertions(+), 5 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v6 1/4] gpio: swnode: Add ability to specify native chip selects for SPI
  2024-04-15 14:09 [PATCH v6 0/4] Add bridged amplifiers to cs42l43 Charles Keepax
@ 2024-04-15 14:09 ` Charles Keepax
  2024-04-15 16:05   ` Andy Shevchenko
  2024-04-16 21:09   ` Bartosz Golaszewski
  2024-04-15 14:09 ` [PATCH v6 2/4] spi: Switch to using is_acpi_device_node() in spi_dev_set_name() Charles Keepax
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 12+ messages in thread
From: Charles Keepax @ 2024-04-15 14:09 UTC (permalink / raw)
  To: broonie, linus.walleij, brgl
  Cc: andy.shevchenko, bard.liao, linux-gpio, linux-spi, patches

SPI devices can specify a cs-gpios property to enumerate their
chip selects. Under device tree, a zero entry in this property can
be used to specify that a particular chip select is using the SPI
controllers native chip select, for example:

        cs-gpios = <&gpio1 0 0>, <0>;

Here, the second chip select is native. However, when using swnodes
there is currently no way to specify a native chip select. The
proposal here is to register a swnode_gpio_undefined software node,
that can be specified to allow the indication of a native chip
select. For example:

static const struct software_node_ref_args device_cs_refs[] = {
	{
		.node  = &device_gpiochip_swnode,
		.nargs = 2,
		.args  = { 0, GPIO_ACTIVE_LOW },
	},
	{
		.node  = &swnode_gpio_undefined,
		.nargs = 0,
	},
};

Register the swnode as the gpiolib is initialised and check in
swnode_get_gpio_device() if the returned node matches
swnode_gpio_undefined and return -ENOENT, which matches the
behaviour of the device tree system when it encounters a 0 phandle.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---

Series changes since v5:
 - Add back help for GPIO_SWNODE_UNDEFINED
 - Correct some typos
 - Only check for undefined swnode if the Kconfig is set
 - Add a pr_fmt
 - Move swnode_gpio_undefined to include/linux/gpio/property.h

Thanks,
Charles

 drivers/gpio/Kconfig          |  9 +++++++
 drivers/gpio/gpiolib-swnode.c | 44 +++++++++++++++++++++++++++++++++++
 include/linux/gpio/property.h |  4 ++++
 3 files changed, 57 insertions(+)

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index b50d0b470849..00b5c007a2bb 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -103,6 +103,15 @@ config GPIO_REGMAP
 	select REGMAP
 	tristate
 
+config GPIO_SWNODE_UNDEFINED
+	bool
+	help
+	  This adds a special place holder for software nodes to contain an
+	  undefined GPIO reference, this is primarily used by SPI to allow a
+	  list of GPIO chip selects to mark a certain chip select as being
+	  controlled the SPI device's internal chip select mechanism and not
+	  a GPIO.
+
 # put drivers in the right section, in alphabetical order
 
 # This symbol is selected by both I2C and SPI expanders
diff --git a/drivers/gpio/gpiolib-swnode.c b/drivers/gpio/gpiolib-swnode.c
index fa52bdb1a29a..cec1ab878af8 100644
--- a/drivers/gpio/gpiolib-swnode.c
+++ b/drivers/gpio/gpiolib-swnode.c
@@ -4,8 +4,13 @@
  *
  * Copyright 2022 Google LLC
  */
+
+#define pr_fmt(fmt) "gpiolib: swnode: " fmt
+
 #include <linux/err.h>
 #include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/printk.h>
 #include <linux/property.h>
@@ -17,6 +22,8 @@
 #include "gpiolib.h"
 #include "gpiolib-swnode.h"
 
+#define GPIOLIB_SWNODE_UNDEFINED_NAME "swnode-gpio-undefined"
+
 static void swnode_format_propname(const char *con_id, char *propname,
 				   size_t max_size)
 {
@@ -40,6 +47,14 @@ static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode)
 	if (!gdev_node || !gdev_node->name)
 		return ERR_PTR(-EINVAL);
 
+	/*
+	 * Check for a special node that identifies undefined GPIOs, this is
+	 * primarily used as a key for internal chip selects in SPI bindings.
+	 */
+	if (IS_ENABLED(CONFIG_GPIO_SWNODE_UNDEFINED) &&
+	    !strcmp(gdev_node->name, GPIOLIB_SWNODE_UNDEFINED_NAME))
+		return ERR_PTR(-ENOENT);
+
 	gdev = gpio_device_find_by_label(gdev_node->name);
 	return gdev ?: ERR_PTR(-EPROBE_DEFER);
 }
@@ -121,3 +136,32 @@ int swnode_gpio_count(const struct fwnode_handle *fwnode, const char *con_id)
 
 	return count ?: -ENOENT;
 }
+
+#if IS_ENABLED(CONFIG_GPIO_SWNODE_UNDEFINED)
+/*
+ * A special node that identifies undefined GPIOs, this is primarily used as
+ * a key for internal chip selects in SPI bindings.
+ */
+const struct software_node swnode_gpio_undefined = {
+	.name = GPIOLIB_SWNODE_UNDEFINED_NAME,
+};
+EXPORT_SYMBOL_NS_GPL(swnode_gpio_undefined, GPIO_SWNODE);
+
+static int __init swnode_gpio_init(void)
+{
+	int ret;
+
+	ret = software_node_register(&swnode_gpio_undefined);
+	if (ret < 0)
+		pr_err("failed to register swnode: %d\n", ret);
+
+	return ret;
+}
+subsys_initcall(swnode_gpio_init);
+
+static void __exit swnode_gpio_cleanup(void)
+{
+	software_node_unregister(&swnode_gpio_undefined);
+}
+__exitcall(swnode_gpio_cleanup);
+#endif
diff --git a/include/linux/gpio/property.h b/include/linux/gpio/property.h
index 6c75c8bd44a0..832a60c2e0b9 100644
--- a/include/linux/gpio/property.h
+++ b/include/linux/gpio/property.h
@@ -5,7 +5,11 @@
 #include <dt-bindings/gpio/gpio.h> /* for GPIO_* flags */
 #include <linux/property.h>
 
+struct software_node;
+
 #define PROPERTY_ENTRY_GPIO(_name_, _chip_node_, _idx_, _flags_) \
 	PROPERTY_ENTRY_REF(_name_, _chip_node_, _idx_, _flags_)
 
+extern const struct software_node swnode_gpio_undefined;
+
 #endif /* __LINUX_GPIO_PROPERTY_H */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v6 2/4] spi: Switch to using is_acpi_device_node() in spi_dev_set_name()
  2024-04-15 14:09 [PATCH v6 0/4] Add bridged amplifiers to cs42l43 Charles Keepax
  2024-04-15 14:09 ` [PATCH v6 1/4] gpio: swnode: Add ability to specify native chip selects for SPI Charles Keepax
@ 2024-04-15 14:09 ` Charles Keepax
  2024-04-15 16:06   ` Andy Shevchenko
  2024-04-15 14:09 ` [PATCH v6 3/4] spi: Update swnode based SPI devices to use the fwnode name Charles Keepax
  2024-04-15 14:09 ` [PATCH v6 4/4] spi: cs42l43: Add bridged cs35l56 amplifiers Charles Keepax
  3 siblings, 1 reply; 12+ messages in thread
From: Charles Keepax @ 2024-04-15 14:09 UTC (permalink / raw)
  To: broonie, linus.walleij, brgl
  Cc: andy.shevchenko, bard.liao, linux-gpio, linux-spi, patches

Use is_acpi_device_node() rather than checking ACPI_COMPANION(), such
that when checking for other types of firmware node the code can
consistently do checks against the fwnode.

Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---

Series changes since v5:
 - Remove includes of fwnode.h
 - Update commit message

Thanks,
Charles

 drivers/spi/spi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index a2f01116ba09..d1f82a35f2d0 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -597,10 +597,11 @@ EXPORT_SYMBOL_GPL(spi_alloc_device);
 
 static void spi_dev_set_name(struct spi_device *spi)
 {
-	struct acpi_device *adev = ACPI_COMPANION(&spi->dev);
+	struct device *dev = &spi->dev;
+	struct fwnode_handle *fwnode = dev_fwnode(dev);
 
-	if (adev) {
-		dev_set_name(&spi->dev, "spi-%s", acpi_dev_name(adev));
+	if (is_acpi_device_node(fwnode)) {
+		dev_set_name(dev, "spi-%s", acpi_dev_name(to_acpi_device_node(fwnode)));
 		return;
 	}
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v6 3/4] spi: Update swnode based SPI devices to use the fwnode name
  2024-04-15 14:09 [PATCH v6 0/4] Add bridged amplifiers to cs42l43 Charles Keepax
  2024-04-15 14:09 ` [PATCH v6 1/4] gpio: swnode: Add ability to specify native chip selects for SPI Charles Keepax
  2024-04-15 14:09 ` [PATCH v6 2/4] spi: Switch to using is_acpi_device_node() in spi_dev_set_name() Charles Keepax
@ 2024-04-15 14:09 ` Charles Keepax
  2024-04-15 16:09   ` Andy Shevchenko
  2024-04-15 14:09 ` [PATCH v6 4/4] spi: cs42l43: Add bridged cs35l56 amplifiers Charles Keepax
  3 siblings, 1 reply; 12+ messages in thread
From: Charles Keepax @ 2024-04-15 14:09 UTC (permalink / raw)
  To: broonie, linus.walleij, brgl
  Cc: andy.shevchenko, bard.liao, linux-gpio, linux-spi, patches

Update the name for software node based SPI devices to use the fwnode
name as the device name. This is helpful since swnode devices are
usually added within the kernel, and the kernel often then requires a
predictable name such that it can refer back to the device.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---

Series changes since v5:
 - Use %pwfP to get firmware node name

Thanks,
Charles

 drivers/spi/spi.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index d1f82a35f2d0..4fcaadf8a484 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -605,6 +605,11 @@ static void spi_dev_set_name(struct spi_device *spi)
 		return;
 	}
 
+	if (is_software_node(fwnode)) {
+		dev_set_name(dev, "spi-%pfwP", fwnode);
+		return;
+	}
+
 	dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->controller->dev),
 		     spi_get_chipselect(spi, 0));
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v6 4/4] spi: cs42l43: Add bridged cs35l56 amplifiers
  2024-04-15 14:09 [PATCH v6 0/4] Add bridged amplifiers to cs42l43 Charles Keepax
                   ` (2 preceding siblings ...)
  2024-04-15 14:09 ` [PATCH v6 3/4] spi: Update swnode based SPI devices to use the fwnode name Charles Keepax
@ 2024-04-15 14:09 ` Charles Keepax
  2024-04-15 16:17   ` Andy Shevchenko
  3 siblings, 1 reply; 12+ messages in thread
From: Charles Keepax @ 2024-04-15 14:09 UTC (permalink / raw)
  To: broonie, linus.walleij, brgl
  Cc: andy.shevchenko, bard.liao, linux-gpio, linux-spi, patches

From: Maciej Strozek <mstrozek@opensource.cirrus.com>

On some cs42l43 systems a couple of cs35l56 amplifiers are attached
to the cs42l43's SPI and I2S. On Windows the cs42l43 is controlled
by a SDCA class driver and these two amplifiers are controlled by
firmware running on the cs42l43. However, under Linux the decision
was made to interact with the cs42l43 directly, affording the user
greater control over the audio system. However, this has resulted
in an issue where these two bridged cs35l56 amplifiers are not
populated in ACPI and must be added manually.

Check for the presence of the "01fa-cirrus-sidecar-instances" property
in the SDCA extension unit's ACPI properties to confirm the presence
of these two amplifiers and if they exist add them manually onto the
SPI bus.

Signed-off-by: Maciej Strozek <mstrozek@opensource.cirrus.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---

Series changes since v5:
 - Remove NULL check on acpi_handle

Thanks,
Charles

 drivers/spi/Kconfig       |   1 +
 drivers/spi/spi-cs42l43.c | 135 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 134 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 554664efda86..17325e0b7bd5 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -284,6 +284,7 @@ config SPI_COLDFIRE_QSPI
 config SPI_CS42L43
 	tristate "Cirrus Logic CS42L43 SPI controller"
 	depends on MFD_CS42L43 && PINCTRL_CS42L43
+	select GPIO_SWNODE_UNDEFINED
 	help
 	  This enables support for the SPI controller inside the Cirrus Logic
 	  CS42L43 audio codec.
diff --git a/drivers/spi/spi-cs42l43.c b/drivers/spi/spi-cs42l43.c
index aabef9fc84bd..dbc60ddaca93 100644
--- a/drivers/spi/spi-cs42l43.c
+++ b/drivers/spi/spi-cs42l43.c
@@ -5,10 +5,14 @@
 // Copyright (C) 2022-2023 Cirrus Logic, Inc. and
 //                         Cirrus Logic International Semiconductor Ltd.
 
+#include <linux/acpi.h>
+#include <linux/array_size.h>
 #include <linux/bits.h>
 #include <linux/bitfield.h>
 #include <linux/device.h>
 #include <linux/errno.h>
+#include <linux/gpio/machine.h>
+#include <linux/gpio/property.h>
 #include <linux/mfd/cs42l43.h>
 #include <linux/mfd/cs42l43-regs.h>
 #include <linux/mod_devicetable.h>
@@ -16,6 +20,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/property.h>
 #include <linux/regmap.h>
 #include <linux/spi/spi.h>
 #include <linux/units.h>
@@ -39,6 +44,44 @@ static const unsigned int cs42l43_clock_divs[] = {
 	2, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
 };
 
+static const struct software_node ampl = {
+	.name			= "cs35l56-left",
+};
+
+static const struct software_node ampr = {
+	.name			= "cs35l56-right",
+};
+
+static struct spi_board_info ampl_info = {
+	.modalias		= "cs35l56",
+	.max_speed_hz		= 20 * HZ_PER_MHZ,
+	.chip_select		= 0,
+	.mode			= SPI_MODE_0,
+	.swnode			= &ampl,
+};
+
+static struct spi_board_info ampr_info = {
+	.modalias		= "cs35l56",
+	.max_speed_hz		= 20 * HZ_PER_MHZ,
+	.chip_select		= 1,
+	.mode			= SPI_MODE_0,
+	.swnode			= &ampr,
+};
+
+static const struct software_node cs42l43_gpiochip_swnode = {
+	.name			= "cs42l43-pinctrl",
+};
+
+static const struct software_node_ref_args cs42l43_cs_refs[] = {
+	SOFTWARE_NODE_REFERENCE(&cs42l43_gpiochip_swnode, 0, GPIO_ACTIVE_LOW),
+	SOFTWARE_NODE_REFERENCE(&swnode_gpio_undefined),
+};
+
+static const struct property_entry cs42l43_cs_props[] = {
+	PROPERTY_ENTRY_REF_ARRAY("cs-gpios", cs42l43_cs_refs),
+	{}
+};
+
 static int cs42l43_spi_tx(struct regmap *regmap, const u8 *buf, unsigned int len)
 {
 	const u8 *end = buf + len;
@@ -203,6 +246,43 @@ static size_t cs42l43_spi_max_length(struct spi_device *spi)
 	return CS42L43_SPI_MAX_LENGTH;
 }
 
+static bool cs42l43_has_sidecar(struct fwnode_handle *fwnode)
+{
+	static const u32 func_smart_amp = 0x1;
+	struct fwnode_handle *child_fwnode, *ext_fwnode;
+	unsigned int val;
+	u32 function;
+	int ret;
+
+	fwnode_for_each_child_node(fwnode, child_fwnode) {
+		acpi_handle handle = ACPI_HANDLE_FWNODE(child_fwnode);
+
+		ret = acpi_get_local_address(handle, &function);
+		if (ret || function != func_smart_amp)
+			continue;
+
+		ext_fwnode = fwnode_get_named_child_node(child_fwnode,
+				"mipi-sdca-function-expansion-subproperties");
+		if (!ext_fwnode)
+			continue;
+
+		ret = fwnode_property_read_u32(ext_fwnode,
+					       "01fa-cirrus-sidecar-instances",
+					       &val);
+
+		fwnode_handle_put(ext_fwnode);
+
+		if (ret)
+			continue;
+
+		fwnode_handle_put(child_fwnode);
+
+		return !!val;
+	}
+
+	return false;
+}
+
 static void cs42l43_release_of_node(void *data)
 {
 	fwnode_handle_put(data);
@@ -213,6 +293,7 @@ static int cs42l43_spi_probe(struct platform_device *pdev)
 	struct cs42l43 *cs42l43 = dev_get_drvdata(pdev->dev.parent);
 	struct cs42l43_spi *priv;
 	struct fwnode_handle *fwnode = dev_fwnode(cs42l43->dev);
+	bool has_sidecar = cs42l43_has_sidecar(fwnode);
 	int ret;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
@@ -266,16 +347,64 @@ static int cs42l43_spi_probe(struct platform_device *pdev)
 		}
 	}
 
-	device_set_node(&priv->ctlr->dev, fwnode);
+	if (has_sidecar) {
+		ret = software_node_register(&cs42l43_gpiochip_swnode);
+		if (ret) {
+			return dev_err_probe(priv->dev, ret,
+					     "Failed to register gpio swnode\n");
+		}
+
+		ret = device_create_managed_software_node(&priv->ctlr->dev,
+							  cs42l43_cs_props, NULL);
+		if (ret) {
+			dev_err_probe(priv->dev, ret, "Failed to add swnode\n");
+			goto err;
+		}
+	} else {
+		device_set_node(&priv->ctlr->dev, fwnode);
+	}
 
 	ret = devm_spi_register_controller(priv->dev, priv->ctlr);
 	if (ret) {
-		dev_err(priv->dev, "Failed to register SPI controller: %d\n", ret);
+		dev_err_probe(priv->dev, ret, "Failed to register SPI controller\n");
+		goto err;
+	}
+
+	if (has_sidecar) {
+		if (!spi_new_device(priv->ctlr, &ampl_info)) {
+			ret = dev_err_probe(priv->dev, -ENODEV,
+					    "Failed to create left amp slave\n");
+			goto err;
+		}
+
+		if (!spi_new_device(priv->ctlr, &ampr_info)) {
+			ret = dev_err_probe(priv->dev, -ENODEV,
+					    "Failed to create right amp slave\n");
+			goto err;
+		}
 	}
 
+	return 0;
+
+err:
+	if (has_sidecar)
+		software_node_unregister(&cs42l43_gpiochip_swnode);
+
 	return ret;
 }
 
+static int cs42l43_spi_remove(struct platform_device *pdev)
+{
+	struct cs42l43 *cs42l43 = dev_get_drvdata(pdev->dev.parent);
+	struct fwnode_handle *fwnode = dev_fwnode(cs42l43->dev);
+	bool has_sidecar = cs42l43_has_sidecar(fwnode);
+
+	if (has_sidecar)
+		software_node_unregister(&cs42l43_gpiochip_swnode);
+
+	return 0;
+};
+
 static const struct platform_device_id cs42l43_spi_id_table[] = {
 	{ "cs42l43-spi", },
 	{}
@@ -288,9 +417,11 @@ static struct platform_driver cs42l43_spi_driver = {
 	},
 	.probe		= cs42l43_spi_probe,
 	.id_table	= cs42l43_spi_id_table,
+	.remove		= cs42l43_spi_remove,
 };
 module_platform_driver(cs42l43_spi_driver);
 
+MODULE_IMPORT_NS(GPIO_SWNODE);
 MODULE_DESCRIPTION("CS42L43 SPI Driver");
 MODULE_AUTHOR("Lucas Tanure <tanureal@opensource.cirrus.com>");
 MODULE_AUTHOR("Maciej Strozek <mstrozek@opensource.cirrus.com>");
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v6 1/4] gpio: swnode: Add ability to specify native chip selects for SPI
  2024-04-15 14:09 ` [PATCH v6 1/4] gpio: swnode: Add ability to specify native chip selects for SPI Charles Keepax
@ 2024-04-15 16:05   ` Andy Shevchenko
  2024-04-16 21:09   ` Bartosz Golaszewski
  1 sibling, 0 replies; 12+ messages in thread
From: Andy Shevchenko @ 2024-04-15 16:05 UTC (permalink / raw)
  To: Charles Keepax
  Cc: broonie, linus.walleij, brgl, bard.liao, linux-gpio, linux-spi, patches

On Mon, Apr 15, 2024 at 5:09 PM Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:
>
> SPI devices can specify a cs-gpios property to enumerate their
> chip selects. Under device tree, a zero entry in this property can
> be used to specify that a particular chip select is using the SPI
> controllers native chip select, for example:
>
>         cs-gpios = <&gpio1 0 0>, <0>;
>
> Here, the second chip select is native. However, when using swnodes
> there is currently no way to specify a native chip select. The
> proposal here is to register a swnode_gpio_undefined software node,
> that can be specified to allow the indication of a native chip
> select. For example:
>
> static const struct software_node_ref_args device_cs_refs[] = {
>         {
>                 .node  = &device_gpiochip_swnode,
>                 .nargs = 2,
>                 .args  = { 0, GPIO_ACTIVE_LOW },
>         },
>         {
>                 .node  = &swnode_gpio_undefined,
>                 .nargs = 0,
>         },
> };
>
> Register the swnode as the gpiolib is initialised and check in
> swnode_get_gpio_device() if the returned node matches
> swnode_gpio_undefined and return -ENOENT, which matches the
> behaviour of the device tree system when it encounters a 0 phandle.

FWIW,
Reviewed-by: Andy Shevchenko <andy@kernel.org>
(I assume that this is _not_ going to be applied standalone as we
don't want this without users, i.o.w. all or none as per this series)

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v6 2/4] spi: Switch to using is_acpi_device_node() in spi_dev_set_name()
  2024-04-15 14:09 ` [PATCH v6 2/4] spi: Switch to using is_acpi_device_node() in spi_dev_set_name() Charles Keepax
@ 2024-04-15 16:06   ` Andy Shevchenko
  2024-04-16  9:53     ` Charles Keepax
  0 siblings, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2024-04-15 16:06 UTC (permalink / raw)
  To: Charles Keepax
  Cc: broonie, linus.walleij, brgl, bard.liao, linux-gpio, linux-spi, patches

On Mon, Apr 15, 2024 at 5:09 PM Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:
>
> Use is_acpi_device_node() rather than checking ACPI_COMPANION(), such
> that when checking for other types of firmware node the code can

a firmware node

> consistently do checks against the fwnode.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v6 3/4] spi: Update swnode based SPI devices to use the fwnode name
  2024-04-15 14:09 ` [PATCH v6 3/4] spi: Update swnode based SPI devices to use the fwnode name Charles Keepax
@ 2024-04-15 16:09   ` Andy Shevchenko
  0 siblings, 0 replies; 12+ messages in thread
From: Andy Shevchenko @ 2024-04-15 16:09 UTC (permalink / raw)
  To: Charles Keepax
  Cc: broonie, linus.walleij, brgl, bard.liao, linux-gpio, linux-spi, patches

On Mon, Apr 15, 2024 at 5:09 PM Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:
>
> Update the name for software node based SPI devices to use the fwnode
> name as the device name. This is helpful since swnode devices are
> usually added within the kernel, and the kernel often then requires a
> predictable name such that it can refer back to the device.

Assuming we have no users like this right now, so there won't be any breakages.
Reviewed-by: Andy Shevchenko <andy@kernel.org>

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v6 4/4] spi: cs42l43: Add bridged cs35l56 amplifiers
  2024-04-15 14:09 ` [PATCH v6 4/4] spi: cs42l43: Add bridged cs35l56 amplifiers Charles Keepax
@ 2024-04-15 16:17   ` Andy Shevchenko
  2024-04-16  9:54     ` Charles Keepax
  0 siblings, 1 reply; 12+ messages in thread
From: Andy Shevchenko @ 2024-04-15 16:17 UTC (permalink / raw)
  To: Charles Keepax
  Cc: broonie, linus.walleij, brgl, bard.liao, linux-gpio, linux-spi, patches

On Mon, Apr 15, 2024 at 5:09 PM Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:
>
> From: Maciej Strozek <mstrozek@opensource.cirrus.com>
>
> On some cs42l43 systems a couple of cs35l56 amplifiers are attached
> to the cs42l43's SPI and I2S. On Windows the cs42l43 is controlled
> by a SDCA class driver and these two amplifiers are controlled by
> firmware running on the cs42l43. However, under Linux the decision
> was made to interact with the cs42l43 directly, affording the user
> greater control over the audio system. However, this has resulted
> in an issue where these two bridged cs35l56 amplifiers are not
> populated in ACPI and must be added manually.
>
> Check for the presence of the "01fa-cirrus-sidecar-instances" property
> in the SDCA extension unit's ACPI properties to confirm the presence
> of these two amplifiers and if they exist add them manually onto the
> SPI bus.

FWIW,
Reviewed-by: Andy Shevchenko <andy@kernel.org>
with the caveats:
- assuming primary - secondary fwnode expectations are correct
- no support for more than expected (2?) amplifiers as per global
naming of swnodes

See also the comment below.

...

> +       if (has_sidecar) {
> +               ret = software_node_register(&cs42l43_gpiochip_swnode);
> +               if (ret) {
> +                       return dev_err_probe(priv->dev, ret,
> +                                            "Failed to register gpio swnode\n");
> +               }
> +
> +               ret = device_create_managed_software_node(&priv->ctlr->dev,
> +                                                         cs42l43_cs_props, NULL);
> +               if (ret) {
> +                       dev_err_probe(priv->dev, ret, "Failed to add swnode\n");
> +                       goto err;
> +               }
> +       } else {
> +               device_set_node(&priv->ctlr->dev, fwnode);
> +       }
>
>         ret = devm_spi_register_controller(priv->dev, priv->ctlr);

Left this chunk for the context below.

>         if (ret) {
> -               dev_err(priv->dev, "Failed to register SPI controller: %d\n", ret);
> +               dev_err_probe(priv->dev, ret, "Failed to register SPI controller\n");
> +               goto err;
> +       }
> +
> +       if (has_sidecar) {
> +               if (!spi_new_device(priv->ctlr, &ampl_info)) {
> +                       ret = dev_err_probe(priv->dev, -ENODEV,
> +                                           "Failed to create left amp slave\n");
> +                       goto err;
> +               }
> +
> +               if (!spi_new_device(priv->ctlr, &ampr_info)) {
> +                       ret = dev_err_probe(priv->dev, -ENODEV,
> +                                           "Failed to create right amp slave\n");
> +                       goto err;
> +               }
>         }
>
> +       return 0;

...

> +err:
> +       if (has_sidecar)
> +               software_node_unregister(&cs42l43_gpiochip_swnode);
> +
>         return ret;

This is wrong in terms of ordering.

...

> +static int cs42l43_spi_remove(struct platform_device *pdev)
> +{
> +       struct cs42l43 *cs42l43 = dev_get_drvdata(pdev->dev.parent);
> +       struct fwnode_handle *fwnode = dev_fwnode(cs42l43->dev);
> +       bool has_sidecar = cs42l43_has_sidecar(fwnode);
> +
> +       if (has_sidecar)
> +               software_node_unregister(&cs42l43_gpiochip_swnode);
> +
> +       return 0;

As this one.

> +};

You will remove the software node before removing the controller, this
seems incorrect ordering to me. What you need is to wrap by
devm_add_action_or_reset() and it won't be any remove() callback
needed.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v6 2/4] spi: Switch to using is_acpi_device_node() in spi_dev_set_name()
  2024-04-15 16:06   ` Andy Shevchenko
@ 2024-04-16  9:53     ` Charles Keepax
  0 siblings, 0 replies; 12+ messages in thread
From: Charles Keepax @ 2024-04-16  9:53 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: broonie, linus.walleij, brgl, bard.liao, linux-gpio, linux-spi, patches

On Mon, Apr 15, 2024 at 07:06:56PM +0300, Andy Shevchenko wrote:
> On Mon, Apr 15, 2024 at 5:09 PM Charles Keepax
> <ckeepax@opensource.cirrus.com> wrote:
> >
> > Use is_acpi_device_node() rather than checking ACPI_COMPANION(), such
> > that when checking for other types of firmware node the code can
> 
> a firmware node
> 

Pretty sure this parses better without the 'a'.

Thanks,
Charles

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v6 4/4] spi: cs42l43: Add bridged cs35l56 amplifiers
  2024-04-15 16:17   ` Andy Shevchenko
@ 2024-04-16  9:54     ` Charles Keepax
  0 siblings, 0 replies; 12+ messages in thread
From: Charles Keepax @ 2024-04-16  9:54 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: broonie, linus.walleij, brgl, bard.liao, linux-gpio, linux-spi, patches

On Mon, Apr 15, 2024 at 07:17:16PM +0300, Andy Shevchenko wrote:
> On Mon, Apr 15, 2024 at 5:09 PM Charles Keepax
> <ckeepax@opensource.cirrus.com> wrote:
> > From: Maciej Strozek <mstrozek@opensource.cirrus.com>
> > +static int cs42l43_spi_remove(struct platform_device *pdev)
> > +{
> > +       struct cs42l43 *cs42l43 = dev_get_drvdata(pdev->dev.parent);
> > +       struct fwnode_handle *fwnode = dev_fwnode(cs42l43->dev);
> > +       bool has_sidecar = cs42l43_has_sidecar(fwnode);
> > +
> > +       if (has_sidecar)
> > +               software_node_unregister(&cs42l43_gpiochip_swnode);
> > +
> > +       return 0;
> 
> As this one.
> 
> > +};
> 
> You will remove the software node before removing the controller, this
> seems incorrect ordering to me. What you need is to wrap by
> devm_add_action_or_reset() and it won't be any remove() callback
> needed.
> 

Yeah this is a good idea I will update.

Thanks,
Charles

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v6 1/4] gpio: swnode: Add ability to specify native chip selects for SPI
  2024-04-15 14:09 ` [PATCH v6 1/4] gpio: swnode: Add ability to specify native chip selects for SPI Charles Keepax
  2024-04-15 16:05   ` Andy Shevchenko
@ 2024-04-16 21:09   ` Bartosz Golaszewski
  1 sibling, 0 replies; 12+ messages in thread
From: Bartosz Golaszewski @ 2024-04-16 21:09 UTC (permalink / raw)
  To: Charles Keepax
  Cc: broonie, linus.walleij, andy.shevchenko, bard.liao, linux-gpio,
	linux-spi, patches

On Mon, Apr 15, 2024 at 4:09 PM Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:
>
> SPI devices can specify a cs-gpios property to enumerate their
> chip selects. Under device tree, a zero entry in this property can
> be used to specify that a particular chip select is using the SPI
> controllers native chip select, for example:
>
>         cs-gpios = <&gpio1 0 0>, <0>;
>
> Here, the second chip select is native. However, when using swnodes
> there is currently no way to specify a native chip select. The
> proposal here is to register a swnode_gpio_undefined software node,
> that can be specified to allow the indication of a native chip
> select. For example:
>
> static const struct software_node_ref_args device_cs_refs[] = {
>         {
>                 .node  = &device_gpiochip_swnode,
>                 .nargs = 2,
>                 .args  = { 0, GPIO_ACTIVE_LOW },
>         },
>         {
>                 .node  = &swnode_gpio_undefined,
>                 .nargs = 0,
>         },
> };
>
> Register the swnode as the gpiolib is initialised and check in
> swnode_get_gpio_device() if the returned node matches
> swnode_gpio_undefined and return -ENOENT, which matches the
> behaviour of the device tree system when it encounters a 0 phandle.
>
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
> ---
>

Acked-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-04-16 21:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-15 14:09 [PATCH v6 0/4] Add bridged amplifiers to cs42l43 Charles Keepax
2024-04-15 14:09 ` [PATCH v6 1/4] gpio: swnode: Add ability to specify native chip selects for SPI Charles Keepax
2024-04-15 16:05   ` Andy Shevchenko
2024-04-16 21:09   ` Bartosz Golaszewski
2024-04-15 14:09 ` [PATCH v6 2/4] spi: Switch to using is_acpi_device_node() in spi_dev_set_name() Charles Keepax
2024-04-15 16:06   ` Andy Shevchenko
2024-04-16  9:53     ` Charles Keepax
2024-04-15 14:09 ` [PATCH v6 3/4] spi: Update swnode based SPI devices to use the fwnode name Charles Keepax
2024-04-15 16:09   ` Andy Shevchenko
2024-04-15 14:09 ` [PATCH v6 4/4] spi: cs42l43: Add bridged cs35l56 amplifiers Charles Keepax
2024-04-15 16:17   ` Andy Shevchenko
2024-04-16  9:54     ` Charles Keepax

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).