linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] spi: cs42l43: Refactor accessing the SDCA extension properties
@ 2024-06-11 13:25 Charles Keepax
  2024-06-11 13:25 ` [PATCH 2/3] spi: cs42l43: Add speaker id support to the bridge configuration Charles Keepax
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Charles Keepax @ 2024-06-11 13:25 UTC (permalink / raw)
  To: broonie; +Cc: lgirdwood, linux-sound, linux-spi, linux-kernel, patches

Refactor accessing the SDCA extension properties to make it easier to
access multiple properties to assist with future features. Return the
node itself and allow the caller to read the actual properties.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 drivers/spi/spi-cs42l43.c | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/drivers/spi/spi-cs42l43.c b/drivers/spi/spi-cs42l43.c
index 8b618ef0f711..0a4475ae931b 100644
--- a/drivers/spi/spi-cs42l43.c
+++ b/drivers/spi/spi-cs42l43.c
@@ -246,11 +246,10 @@ 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 struct fwnode_handle *cs42l43_find_xu_node(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;
 
@@ -266,21 +265,12 @@ static bool cs42l43_has_sidecar(struct fwnode_handle *fwnode)
 		if (!ext_fwnode)
 			continue;
 
-		ret = fwnode_property_read_u32(ext_fwnode,
-					       "01fa-sidecar-instances",
-					       &val);
-
-		fwnode_handle_put(ext_fwnode);
-
-		if (ret)
-			continue;
-
 		fwnode_handle_put(child_fwnode);
 
-		return !!val;
+		return ext_fwnode;
 	}
 
-	return false;
+	return NULL;
 }
 
 static void cs42l43_release_of_node(void *data)
@@ -298,7 +288,8 @@ 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);
+	struct fwnode_handle *xu_fwnode __free(fwnode_handle) = cs42l43_find_xu_node(fwnode);
+	int nsidecars = 0;
 	int ret;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
@@ -350,7 +341,9 @@ static int cs42l43_spi_probe(struct platform_device *pdev)
 			return ret;
 	}
 
-	if (has_sidecar) {
+	fwnode_property_read_u32(xu_fwnode, "01fa-sidecar-instances", &nsidecars);
+
+	if (nsidecars) {
 		ret = software_node_register(&cs42l43_gpiochip_swnode);
 		if (ret)
 			return dev_err_probe(priv->dev, ret,
@@ -373,7 +366,7 @@ static int cs42l43_spi_probe(struct platform_device *pdev)
 		return dev_err_probe(priv->dev, ret,
 				     "Failed to register SPI controller\n");
 
-	if (has_sidecar) {
+	if (nsidecars) {
 		if (!spi_new_device(priv->ctlr, &ampl_info))
 			return dev_err_probe(priv->dev, -ENODEV,
 					     "Failed to create left amp slave\n");
-- 
2.39.2


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

* [PATCH 2/3] spi: cs42l43: Add speaker id support to the bridge configuration
  2024-06-11 13:25 [PATCH 1/3] spi: cs42l43: Refactor accessing the SDCA extension properties Charles Keepax
@ 2024-06-11 13:25 ` Charles Keepax
  2024-06-18 16:06   ` Mark Brown
  2024-06-11 13:25 ` [PATCH 3/3] ASoC: cs35l56: Attempt to read from cirrus,speaker-id device property first Charles Keepax
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Charles Keepax @ 2024-06-11 13:25 UTC (permalink / raw)
  To: broonie; +Cc: lgirdwood, linux-sound, linux-spi, linux-kernel, patches

From: Simon Trimmer <simont@opensource.cirrus.com>

OEMs can connect a number of types of speakers to the sidecar cs35l56
amplifiers and a different speaker requires a different firmware
configuration.

When the cs42l43 ACPI includes a property indicating a particular type
of speaker has been installed this should be passed to the cs35l56
driver instances as a device property.

Signed-off-by: Simon Trimmer <simont@opensource.cirrus.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 drivers/spi/spi-cs42l43.c | 74 ++++++++++++++++++++++++++++-----------
 1 file changed, 53 insertions(+), 21 deletions(-)

diff --git a/drivers/spi/spi-cs42l43.c b/drivers/spi/spi-cs42l43.c
index 0a4475ae931b..5b8ed65f8094 100644
--- a/drivers/spi/spi-cs42l43.c
+++ b/drivers/spi/spi-cs42l43.c
@@ -9,6 +9,7 @@
 #include <linux/array_size.h>
 #include <linux/bits.h>
 #include <linux/bitfield.h>
+#include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/errno.h>
 #include <linux/gpio/machine.h>
@@ -44,28 +45,10 @@ 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 = {
+static struct spi_board_info amp_info_template = {
 	.modalias		= "cs35l56",
 	.max_speed_hz		= 11 * HZ_PER_MHZ,
-	.chip_select		= 0,
 	.mode			= SPI_MODE_0,
-	.swnode			= &ampl,
-};
-
-static struct spi_board_info ampr_info = {
-	.modalias		= "cs35l56",
-	.max_speed_hz		= 11 * HZ_PER_MHZ,
-	.chip_select		= 1,
-	.mode			= SPI_MODE_0,
-	.swnode			= &ampr,
 };
 
 static const struct software_node cs42l43_gpiochip_swnode = {
@@ -273,6 +256,39 @@ static struct fwnode_handle *cs42l43_find_xu_node(struct fwnode_handle *fwnode)
 	return NULL;
 }
 
+static struct spi_board_info *cs42l43_create_bridge_amp(struct cs42l43_spi *priv,
+							const char * const name,
+							int cs, int spkid)
+{
+	struct property_entry *props = NULL;
+	struct software_node *swnode;
+	struct spi_board_info *info;
+
+	if (spkid >= 0) {
+		props = devm_kmalloc(priv->dev, sizeof(*props), GFP_KERNEL);
+		if (!props)
+			return NULL;
+
+		*props = PROPERTY_ENTRY_U32("cirrus,speaker-id", spkid);
+	}
+
+	swnode = devm_kmalloc(priv->dev, sizeof(*swnode), GFP_KERNEL);
+	if (!swnode)
+		return NULL;
+
+	*swnode = SOFTWARE_NODE(name, props, NULL);
+
+	info = devm_kmemdup(priv->dev, &amp_info_template,
+			    sizeof(amp_info_template), GFP_KERNEL);
+	if (!info)
+		return NULL;
+
+	info->chip_select = cs;
+	info->swnode = swnode;
+
+	return info;
+}
+
 static void cs42l43_release_of_node(void *data)
 {
 	fwnode_handle_put(data);
@@ -367,11 +383,27 @@ static int cs42l43_spi_probe(struct platform_device *pdev)
 				     "Failed to register SPI controller\n");
 
 	if (nsidecars) {
-		if (!spi_new_device(priv->ctlr, &ampl_info))
+		struct spi_board_info *ampl_info;
+		struct spi_board_info *ampr_info;
+		int spkid = -EINVAL;
+
+		fwnode_property_read_u32(xu_fwnode, "01fa-spk-id-val", &spkid);
+
+		dev_dbg(priv->dev, "Found speaker ID %d\n", spkid);
+
+		ampl_info = cs42l43_create_bridge_amp(priv, "cs35l56-left", 0, spkid);
+		if (!ampl_info)
+			return -ENOMEM;
+
+		ampr_info = cs42l43_create_bridge_amp(priv, "cs35l56-right", 1, spkid);
+		if (!ampr_info)
+			return -ENOMEM;
+
+		if (!spi_new_device(priv->ctlr, ampl_info))
 			return dev_err_probe(priv->dev, -ENODEV,
 					     "Failed to create left amp slave\n");
 
-		if (!spi_new_device(priv->ctlr, &ampr_info))
+		if (!spi_new_device(priv->ctlr, ampr_info))
 			return dev_err_probe(priv->dev, -ENODEV,
 					     "Failed to create right amp slave\n");
 	}
-- 
2.39.2


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

* [PATCH 3/3] ASoC: cs35l56: Attempt to read from cirrus,speaker-id device property first
  2024-06-11 13:25 [PATCH 1/3] spi: cs42l43: Refactor accessing the SDCA extension properties Charles Keepax
  2024-06-11 13:25 ` [PATCH 2/3] spi: cs42l43: Add speaker id support to the bridge configuration Charles Keepax
@ 2024-06-11 13:25 ` Charles Keepax
  2024-06-12 17:09 ` (subset) [PATCH 1/3] spi: cs42l43: Refactor accessing the SDCA extension properties Mark Brown
  2024-06-19 12:50 ` Mark Brown
  3 siblings, 0 replies; 7+ messages in thread
From: Charles Keepax @ 2024-06-11 13:25 UTC (permalink / raw)
  To: broonie; +Cc: lgirdwood, linux-sound, linux-spi, linux-kernel, patches

From: Simon Trimmer <simont@opensource.cirrus.com>

When cs35l56 is connected via cs42l43 there isn't an ACPI node for the
cs35l56 so all properties are under the cs42l43 ACPI node. We're adding
a property as a way for the cs42l43 driver to pass this info in via a
software node.

Signed-off-by: Simon Trimmer <simont@opensource.cirrus.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 sound/soc/codecs/cs35l56-shared.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/cs35l56-shared.c b/sound/soc/codecs/cs35l56-shared.c
index 8af89a263594..e89027cd40d1 100644
--- a/sound/soc/codecs/cs35l56-shared.c
+++ b/sound/soc/codecs/cs35l56-shared.c
@@ -853,9 +853,16 @@ EXPORT_SYMBOL_NS_GPL(cs35l56_hw_init, SND_SOC_CS35L56_SHARED);
 int cs35l56_get_speaker_id(struct cs35l56_base *cs35l56_base)
 {
 	struct gpio_descs *descs;
-	int speaker_id;
+	u32 speaker_id;
 	int i, ret;
 
+	/* Attempt to read the speaker type from a device property first */
+	ret = device_property_read_u32(cs35l56_base->dev, "cirrus,speaker-id", &speaker_id);
+	if (!ret) {
+		dev_dbg(cs35l56_base->dev, "Speaker ID = %d\n", speaker_id);
+		return speaker_id;
+	}
+
 	/* Read the speaker type qualifier from the motherboard GPIOs */
 	descs = gpiod_get_array_optional(cs35l56_base->dev, "spk-id", GPIOD_IN);
 	if (!descs) {
-- 
2.39.2


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

* Re: (subset) [PATCH 1/3] spi: cs42l43: Refactor accessing the SDCA extension properties
  2024-06-11 13:25 [PATCH 1/3] spi: cs42l43: Refactor accessing the SDCA extension properties Charles Keepax
  2024-06-11 13:25 ` [PATCH 2/3] spi: cs42l43: Add speaker id support to the bridge configuration Charles Keepax
  2024-06-11 13:25 ` [PATCH 3/3] ASoC: cs35l56: Attempt to read from cirrus,speaker-id device property first Charles Keepax
@ 2024-06-12 17:09 ` Mark Brown
  2024-06-19 12:50 ` Mark Brown
  3 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2024-06-12 17:09 UTC (permalink / raw)
  To: Charles Keepax; +Cc: lgirdwood, linux-sound, linux-spi, linux-kernel, patches

On Tue, 11 Jun 2024 14:25:54 +0100, Charles Keepax wrote:
> Refactor accessing the SDCA extension properties to make it easier to
> access multiple properties to assist with future features. Return the
> node itself and allow the caller to read the actual properties.
> 
> 

Applied to

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

Thanks!

[3/3] ASoC: cs35l56: Attempt to read from cirrus,speaker-id device property first
      commit: c38082bf223fb4a3f2bdf1f79650af53d3499dea

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


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

* Re: [PATCH 2/3] spi: cs42l43: Add speaker id support to the bridge configuration
  2024-06-11 13:25 ` [PATCH 2/3] spi: cs42l43: Add speaker id support to the bridge configuration Charles Keepax
@ 2024-06-18 16:06   ` Mark Brown
  2024-06-18 16:44     ` Simon Trimmer
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2024-06-18 16:06 UTC (permalink / raw)
  To: Charles Keepax; +Cc: lgirdwood, linux-sound, linux-spi, linux-kernel, patches

[-- Attachment #1: Type: text/plain, Size: 351 bytes --]

On Tue, Jun 11, 2024 at 02:25:55PM +0100, Charles Keepax wrote:
> From: Simon Trimmer <simont@opensource.cirrus.com>
> 
> OEMs can connect a number of types of speakers to the sidecar cs35l56
> amplifiers and a different speaker requires a different firmware
> configuration.

This doesn't apply against current code, please check and resend.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* RE: [PATCH 2/3] spi: cs42l43: Add speaker id support to the bridge configuration
  2024-06-18 16:06   ` Mark Brown
@ 2024-06-18 16:44     ` Simon Trimmer
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Trimmer @ 2024-06-18 16:44 UTC (permalink / raw)
  To: 'Mark Brown', 'Charles Keepax'
  Cc: lgirdwood, linux-sound, linux-spi, linux-kernel, patches

On Tue, Jun 18, 2024 at 5:06 PM Mark Brown wrote:
> On Tue, Jun 11, 2024 at 02:25:55PM +0100, Charles Keepax wrote:
> > From: Simon Trimmer <simont@opensource.cirrus.com>
> >
> > OEMs can connect a number of types of speakers to the sidecar cs35l56
> > amplifiers and a different speaker requires a different firmware
> > configuration.
> 
> This doesn't apply against current code, please check and resend.

I'll catchup with Charles about this tomorrow (hopefully) - the snag seems to be that an ancestor has been taken for integration via the linux-spi tree

https://lore.kernel.org/all/171778072618.80456.1164637774989487170.b4-ty@kernel.org/

-Simon


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

* Re: (subset) [PATCH 1/3] spi: cs42l43: Refactor accessing the SDCA extension properties
  2024-06-11 13:25 [PATCH 1/3] spi: cs42l43: Refactor accessing the SDCA extension properties Charles Keepax
                   ` (2 preceding siblings ...)
  2024-06-12 17:09 ` (subset) [PATCH 1/3] spi: cs42l43: Refactor accessing the SDCA extension properties Mark Brown
@ 2024-06-19 12:50 ` Mark Brown
  3 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2024-06-19 12:50 UTC (permalink / raw)
  To: Charles Keepax; +Cc: lgirdwood, linux-sound, linux-spi, linux-kernel, patches

On Tue, 11 Jun 2024 14:25:54 +0100, Charles Keepax wrote:
> Refactor accessing the SDCA extension properties to make it easier to
> access multiple properties to assist with future features. Return the
> node itself and allow the caller to read the actual properties.
> 
> 

Applied to

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

Thanks!

[1/3] spi: cs42l43: Refactor accessing the SDCA extension properties
      commit: 6914ee9cd1b0c91bd2fb4dbe204947c3c31259e1
[2/3] spi: cs42l43: Add speaker id support to the bridge configuration
      (no commit info)

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


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

end of thread, other threads:[~2024-06-19 12:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-11 13:25 [PATCH 1/3] spi: cs42l43: Refactor accessing the SDCA extension properties Charles Keepax
2024-06-11 13:25 ` [PATCH 2/3] spi: cs42l43: Add speaker id support to the bridge configuration Charles Keepax
2024-06-18 16:06   ` Mark Brown
2024-06-18 16:44     ` Simon Trimmer
2024-06-11 13:25 ` [PATCH 3/3] ASoC: cs35l56: Attempt to read from cirrus,speaker-id device property first Charles Keepax
2024-06-12 17:09 ` (subset) [PATCH 1/3] spi: cs42l43: Refactor accessing the SDCA extension properties Mark Brown
2024-06-19 12:50 ` Mark Brown

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).