From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: <broonie@kernel.org>
Cc: <lgirdwood@gmail.com>, <linux-sound@vger.kernel.org>,
<linux-spi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<patches@opensource.cirrus.com>
Subject: [PATCH 2/3] spi: cs42l43: Add speaker id support to the bridge configuration
Date: Tue, 11 Jun 2024 14:25:55 +0100 [thread overview]
Message-ID: <20240611132556.1557075-2-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20240611132556.1557075-1-ckeepax@opensource.cirrus.com>
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 = &l,
-};
-
-static struct spi_board_info ampr_info = {
- .modalias = "cs35l56",
- .max_speed_hz = 11 * HZ_PER_MHZ,
- .chip_select = 1,
- .mode = SPI_MODE_0,
- .swnode = &r,
};
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, &_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, &l_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, &r_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
next prev parent reply other threads:[~2024-06-11 13:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2024-06-18 16:06 ` [PATCH 2/3] spi: cs42l43: Add speaker id support to the bridge configuration 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
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=20240611132556.1557075-2-ckeepax@opensource.cirrus.com \
--to=ckeepax@opensource.cirrus.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
/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 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).