Add bridged amplifiers to cs42l43
Subsystems (3)
v6 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 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(-)
Signature · 1 line
2.39.2
PATCH v6 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.
---
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(+)
drivers/gpio/Kconfig +9 -0
@@ -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
@@ -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
Re: [PATCH v6 1/4] gpio: swnode: Add ability to specify native chip selects for SPI
Quoted 26 lines · Charles Keepax
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_undefinedsoftware 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, }, };
Quoted 4 lines
Register the swnode as the gpiolib is initialised and check in
swnode_get_gpio_device()if the returned node matchesswnode_gpio_undefinedand return-ENOENT, which matches the behaviour of the device tree system when it encounters a 0 phandle.
FWIW,
(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)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v6 1/4] gpio: swnode: Add ability to specify native chip selects for SPI
In reply to Charles KeepaxQuoted 26 lines · Charles Keepax
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_undefinedsoftware 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, }, };
Quoted 9 lines
Register the swnode as the gpiolib is initialised and check in
swnode_get_gpio_device()if the returned node matchesswnode_gpio_undefinedand return-ENOENT, which matches the behaviour of the device tree system when it encounters a 0 phandle.Reviewed-by Linus Walleij <[email protected]>Signed-off-by Charles Keepax <[email protected]>---
PATCH v6 2/4 spi: Switch to using is_acpi_device_node() in spi_dev_set_name()
In reply to Charles KeepaxUse 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.
---
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(-)
drivers/spi/spi.c +4 -3
@@ -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
Re: [PATCH v6 2/4] spi: Switch to using is_acpi_device_node() in spi_dev_set_name()
Quoted 3 lines · Charles Keepax
Use
is_acpi_device_node()rather than checkingACPI_COMPANION(), such that when checking for other types of firmware node the code can
a firmware node
Quoted 1 line
consistently do checks against the fwnode.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v6 2/4] spi: Switch to using is_acpi_device_node() in spi_dev_set_name()
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines · Charles Keepax
Use
is_acpi_device_node()rather than checkingACPI_COMPANION(), such that when checking for other types of firmware node the code cana firmware node
Pretty sure this parses better without the 'a'.
Thanks,
Charles
PATCH v6 3/4 spi: Update swnode based SPI devices to use the fwnode name
In reply to Charles KeepaxUpdate 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.
---
Series changes since v5:
- Use %pwfP to get firmware node name
Thanks,
Charles
drivers/spi/spi.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/spi/spi.c +5 -0
@@ -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
Re: [PATCH v6 3/4] spi: Update swnode based SPI devices to use the fwnode name
Quoted 5 lines · 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.
Assuming we have no users like this right now, so there won't be any breakages.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v6 4/4 spi: cs42l43: Add bridged cs35l56 amplifiers
In reply to Charles KeepaxFrom: 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.
---
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(-)
drivers/spi/Kconfig +1 -0
@@ -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 +133 -2
192 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH v6 4/4] spi: cs42l43: Add bridged cs35l56 amplifiers
Quoted 12 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.
Quoted 4 lines
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,
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.
...
Quoted 8 lines
drivers/spi/spi-cs42l43.c +8
-0+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,
drivers/spi/spi-cs42l43.c static int cs42l43_spi_probe(struct platform_device *pdev) · line 367
Quoted 10 lines
drivers/spi/spi-cs42l43.c +8
-0+ 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.
Quoted 21 lines
if (ret) {drivers/spi/spi-cs42l43.c +17
-1-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, &l_info)) { + ret =dev_err_probe (priv->dev, -ENODEV , +"Failed to create left amp slave\n" ); + goto err; + } + +if (!spi_new_device (priv->ctlr, &r_info)) { + ret =dev_err_probe (priv->dev, -ENODEV , +"Failed to create right amp slave\n" ); + goto err; + } } +return 0 ;
...
drivers/spi/spi-cs42l43.c static int cs42l43_spi_probe(struct platform_device *pdev) · line 393
Quoted 5 lines
drivers/spi/spi-cs42l43.c +4
-0+err: +if (has_sidecar) +software_node_unregister (&cs42l43_gpiochip_swnode); +return ret;
This is wrong in terms of ordering.
...
drivers/spi/spi-cs42l43.c static int cs42l43_spi_probe(struct platform_device *pdev) · line 405
Quoted 10 lines
drivers/spi/spi-cs42l43.c +10
-0+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.
Quoted 1 line
+};
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.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v6 4/4] spi: cs42l43: Add bridged cs35l56 amplifiers
Quoted 16 lines · Andy Shevchenko
drivers/spi/spi-cs42l43.c static int cs42l43_spi_probe(struct platform_device *pdev) · line 405
Quoted 11 lines · Charles Keepax
From: Maciej Strozek <[email protected]>
drivers/spi/spi-cs42l43.c +10
-0+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.
Quoted 7 lines
Quoted 1 line
+};
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 anyremove()callback needed.
Yeah this is a good idea I will update.
Thanks,
Charles