public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: <broonie@kernel.org>
Cc: <lgirdwood@gmail.com>, <yung-chuan.liao@linux.intel.com>,
	<pierre-louis.bossart@linux.dev>,
	<peter.ujfalusi@linux.intel.com>, <linux-sound@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <patches@opensource.cirrus.com>
Subject: [PATCH 06/10] ASoC: SDCA: Add parsing for Control range structures
Date: Wed, 5 Feb 2025 11:37:57 +0000	[thread overview]
Message-ID: <20250205113801.3699902-7-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20250205113801.3699902-1-ckeepax@opensource.cirrus.com>

DisCo/SDCA contains small buffers of data that hold ranges of valid
values for the various SDCA Controls. Add support for parsing these
from ACPI.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
 include/sound/sdca_function.h   | 14 ++++++++++
 sound/soc/sdca/sdca_functions.c | 45 +++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)

diff --git a/include/sound/sdca_function.h b/include/sound/sdca_function.h
index 64043090fe76e..769ae68410647 100644
--- a/include/sound/sdca_function.h
+++ b/include/sound/sdca_function.h
@@ -612,6 +612,18 @@ enum sdca_access_layer {
 	SDCA_ACCESS_LAYER_EXTENSION			= 1 << 5,
 };
 
+/**
+ * struct sdca_control_range - SDCA Control range table
+ * @cols: Number of columns in the range table.
+ * @rows: Number of rows in the range table.
+ * @data: Array of values contained in the range table.
+ */
+struct sdca_control_range {
+	unsigned int cols;
+	unsigned int rows;
+	u32 *data;
+};
+
 /**
  * struct sdca_control - information for one SDCA Control
  * @label: Name for the Control, from SDCA Specification v1.0, section 7.1.7.
@@ -622,6 +634,7 @@ enum sdca_access_layer {
  * Control.
  * @cn_list: A bitmask showing the valid Control Numbers within this Control,
  * Control Numbers typically represent channels.
+ * @range: Buffer describing valid range of values for the Control.
  * @mode: Access mode of the Control.
  * @layers: Bitmask of access layers of the Control.
  * @deferrable: Indicates if the access to the Control can be deferred.
@@ -637,6 +650,7 @@ struct sdca_control {
 	int interrupt_position;
 	u64 cn_list;
 
+	struct sdca_control_range range;
 	enum sdca_access_mode mode;
 	u8 layers;
 
diff --git a/sound/soc/sdca/sdca_functions.c b/sound/soc/sdca/sdca_functions.c
index e495ccc5b4b6f..d65b413f6d2f4 100644
--- a/sound/soc/sdca/sdca_functions.c
+++ b/sound/soc/sdca/sdca_functions.c
@@ -603,6 +603,44 @@ static unsigned int find_sdca_control_bits(const struct sdca_entity *entity,
 	}
 }
 
+static int find_sdca_control_range(struct device *dev,
+				   struct fwnode_handle *control_node,
+				   struct sdca_control_range *range)
+{
+	u8 *range_list;
+	int num_range;
+	u16 *limits;
+	int i;
+
+	num_range = fwnode_property_count_u8(control_node, "mipi-sdca-control-range");
+	if (!num_range || num_range == -EINVAL)
+		return 0;
+	else if (num_range < 0)
+		return num_range;
+
+	range_list = devm_kcalloc(dev, num_range, sizeof(*range_list), GFP_KERNEL);
+	if (!range_list)
+		return -ENOMEM;
+
+	fwnode_property_read_u8_array(control_node, "mipi-sdca-control-range",
+				      range_list, num_range);
+
+	limits = (u16 *)range_list;
+
+	range->cols = le16_to_cpu(limits[0]);
+	range->rows = le16_to_cpu(limits[1]);
+	range->data = (u32 *)&limits[2];
+
+	num_range = (num_range - (2 * sizeof(*limits))) / sizeof(*range->data);
+	if (num_range != range->cols * range->rows)
+		return -EINVAL;
+
+	for (i = 0; i < num_range; i++)
+		range->data[i] = le32_to_cpu(range->data[i]);
+
+	return 0;
+}
+
 /*
  * TODO: Add support for -cn- properties, allowing different channels to have
  * different defaults etc.
@@ -678,6 +716,13 @@ static int find_sdca_entity_control(struct device *dev, struct sdca_entity *enti
 		break;
 	}
 
+	ret = find_sdca_control_range(dev, control_node, &control->range);
+	if (ret) {
+		dev_err(dev, "%s: control %#x: range missing: %d\n",
+			entity->label, control->sel, ret);
+		return ret;
+	}
+
 	ret = fwnode_property_read_u64(control_node, "mipi-sdca-control-cn-list",
 				       &control->cn_list);
 	if (ret == -EINVAL) {
-- 
2.39.5


  parent reply	other threads:[~2025-02-05 11:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-05 11:37 [PATCH 00/10] Add SDCA DisCo parsing support Charles Keepax
2025-02-05 11:37 ` [PATCH 01/10] ASoC: SDCA: Minor formatting and naming tweaks Charles Keepax
2025-02-05 11:37 ` [PATCH 02/10] ASoC: SDCA: Add code to parse Function information Charles Keepax
2025-02-05 11:37 ` [PATCH 03/10] ASoC: SDCA: Parse initialization write table Charles Keepax
2025-02-05 11:37 ` [PATCH 04/10] ASoC: SDCA: Add support for Entity 0 Charles Keepax
2025-02-05 11:37 ` [PATCH 05/10] ASoC: SDCA: Add SDCA Control parsing Charles Keepax
2025-02-05 11:37 ` Charles Keepax [this message]
2025-02-05 11:37 ` [PATCH 07/10] ASoC: SDCA: Add Channel Cluster parsing Charles Keepax
2025-02-05 11:37 ` [PATCH 08/10] ASoC: SDCA: Add support for IT/OT Entity properties Charles Keepax
2025-02-05 11:38 ` [PATCH 09/10] ASoC: SDCA: Add support for clock " Charles Keepax
2025-02-05 11:38 ` [PATCH 10/10] ASoC: SDCA: Add support for PDE " Charles Keepax
2025-02-07 17:14 ` [PATCH 00/10] Add SDCA DisCo parsing support Pierre-Louis Bossart
2025-02-10 16:30 ` 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=20250205113801.3699902-7-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=patches@opensource.cirrus.com \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=yung-chuan.liao@linux.intel.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