Skip to contentSkip to conversation

Add bridged amplifiers to cs42l43

PATCH In review Charles Keepax 3 participants 8 messages Apr 16, 2024 – Apr 17, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v7 cover Add bridged amplifiers to cs42l43

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 v6:
- Use devm_add_action to free swnode

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     | 123 ++++++++++++++++++++++++++++++++--
 drivers/spi/spi.c             |  12 +++-
 include/linux/gpio/property.h |   4 ++
 6 files changed, 186 insertions(+), 7 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH v7 1/4 gpio: swnode: Add ability to specify native chip selects for SPI

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.

---

No changes since v6.

Thanks,
Charles

 drivers/gpio/Kconfig          |  9 +++++++
 drivers/gpio/gpiolib-swnode.c | 44 +++++++++++++++++++++++++++++++++++
 include/linux/gpio/property.h |  4 ++++
 3 files changed, 57 insertions(+)
drivers/gpio/Kconfig +9 -0
index b50d0b470849..00b5c007a2bb 100644
@@ -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
drivers/gpio/gpiolib-swnode.c +44 -0

67 lines not on this page · raw message

include/linux/gpio/property.h +4 -0
index 6c75c8bd44a0..832a60c2e0b9 100644
@@ -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 */
Signature · 1 line
2.39.2
#2 lore raw

PATCH v7 2/4 spi: Switch to using is_acpi_device_node() in spi_dev_set_name()

In reply to Charles Keepax

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.

---

No changes since v6.

Thanks,
Charles

 drivers/spi/spi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/spi/spi.c +4 -3
index a2f01116ba09..d1f82a35f2d0 100644
@@ -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;
 	}
 
Signature · 1 line
2.39.2
#3 lore raw

PATCH v7 3/4 spi: Update swnode based SPI devices to use the fwnode name

In reply to Charles Keepax

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.

---

No changes since v6.

Thanks,
Charles

 drivers/spi/spi.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/spi/spi.c +5 -0
index d1f82a35f2d0..4fcaadf8a484 100644
@@ -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));
 }
Signature · 1 line
2.39.2
#4 lore raw

PATCH v7 4/4 spi: cs42l43: Add bridged cs35l56 amplifiers

In reply to Charles Keepax

From: Maciej Strozek <[email protected]>

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.

---

Changes since v6:
- Use devm_add_action to free swnode

Thanks,
Charles

 drivers/spi/Kconfig       |   1 +
 drivers/spi/spi-cs42l43.c | 123 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 120 insertions(+), 4 deletions(-)
drivers/spi/Kconfig +1 -0
index 554664efda86..17325e0b7bd5 100644
@@ -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.
drivers/spi/spi-cs42l43.c +119 -4

177 lines not on this page · raw message

Signature · 1 line
2.39.2
#5 lore raw

Re: [PATCH v7 4/4] spi: cs42l43: Add bridged cs35l56 amplifiers

Quoted 16 lines · Charles Keepax

From: Maciej Strozek <[email protected]>

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.

...

Quoted 4 lines
drivers/spi/spi-cs42l43.c +4 -0
+static void cs42l43_release_sw_node(void *data)
+{
+       software_node_unregister(&cs42l43_gpiochip_swnode);
+}

...

drivers/spi/spi-cs42l43.c static int cs42l43_spi_probe(struct platform_device *pdev)

Quoted 4 lines
drivers/spi/spi-cs42l43.c +3 -0
+               ret = devm_add_action(priv->dev, cs42l43_release_sw_node, NULL);
+               if (ret) {
 
+                       software_node_unregister(&cs42l43_gpiochip_swnode);

This is not needed when you use devm_add_action_or_reset(); that's why I mentioned that API and not simple devm_add_action(). Can be fixed later of course, not a big deal.

Quoted 2 lines
(quoted diff) +2 -0
+                       return ret;
+               }
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw

Re: [PATCH v7 4/4] spi: cs42l43: Add bridged cs35l56 amplifiers

Quoted 4 lines · Andy Shevchenko
Quoted 1 line · Charles Keepax

From: Maciej Strozek <[email protected]>

Quoted 9 lines

drivers/spi/spi-cs42l43.c static int cs42l43_spi_probe(struct platform_device *pdev)

Quoted 4 lines
drivers/spi/spi-cs42l43.c +3 -0
+               ret = devm_add_action(priv->dev, cs42l43_release_sw_node, NULL);
+               if (ret) {
 
+                       software_node_unregister(&cs42l43_gpiochip_swnode);

This is not needed when you use devm_add_action_or_reset(); that's why I mentioned that API and not simple devm_add_action(). Can be fixed later of course, not a big deal.

Argh... sorry about that, not doing well on this series. Still a few people to look at the series so I will fix it up and doing another spin probably the next couple of days.

Thanks,
Charles

maintainer
#7 lore raw
In reply to Charles Keepax
Quoted 11 lines · Charles Keepax

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.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/4] gpio: swnode: Add ability to specify native chip selects for SPI

      commit: 9d50f95bc0d5df56f2591b950a251d90bffad094
[2/4] spi: Switch to using is_acpi_device_node() in spi_dev_set_name()
      commit: 8a101146bcf014060530d71eba8edc52eca257f7
[3/4] spi: Update swnode based SPI devices to use the fwnode name
      commit: ed8921188f3568ba1659ff041f21e83565c74ec2
[4/4] spi: cs42l43: Add bridged cs35l56 amplifiers
      commit: 439fbc97502ae16f3e54e05d266d103674cc4f06

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark