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 10/10] ASoC: SDCA: Add support for PDE Entity properties
Date: Wed, 5 Feb 2025 11:38:01 +0000 [thread overview]
Message-ID: <20250205113801.3699902-11-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20250205113801.3699902-1-ckeepax@opensource.cirrus.com>
Add support for parsing the Power Domain Entity properties from
DisCo/ACPI.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
include/sound/sdca_function.h | 48 +++++++++++
sound/soc/sdca/sdca_functions.c | 138 ++++++++++++++++++++++++++++++++
2 files changed, 186 insertions(+)
diff --git a/include/sound/sdca_function.h b/include/sound/sdca_function.h
index 13edc976679ac..f001ab643fed4 100644
--- a/include/sound/sdca_function.h
+++ b/include/sound/sdca_function.h
@@ -39,6 +39,11 @@ struct sdca_function_desc;
*/
#define SDCA_MAX_CHANNEL_COUNT 32
+/*
+ * Sanity check on number of PDE delays, can be expanded if needed.
+ */
+#define SDCA_MAX_DELAY_COUNT 256
+
/**
* enum sdca_function_type - SDCA Function Type codes
* @SDCA_FUNCTION_TYPE_SMART_AMP: Amplifier with protection features.
@@ -807,6 +812,47 @@ struct sdca_entity_cs {
unsigned int max_delay;
};
+/**
+ * enum sdca_pde_power_state - SDCA Power States
+ *
+ * SDCA Power State values from SDCA specification v1.0 Section 7.12.4.
+ */
+enum sdca_pde_power_state {
+ SDCA_PDE_PS0 = 0x0,
+ SDCA_PDE_PS1 = 0x1,
+ SDCA_PDE_PS2 = 0x2,
+ SDCA_PDE_PS3 = 0x3,
+ SDCA_PDE_PS4 = 0x4,
+};
+
+/**
+ * struct sdca_pde_delay - describes the delay changing between 2 power states
+ * @from_ps: The power state being exited.
+ * @to_ps: The power state being entered.
+ * @us: The delay in microseconds switching between the two states.
+ */
+struct sdca_pde_delay {
+ int from_ps;
+ int to_ps;
+ unsigned int us;
+};
+
+/**
+ * struct sdca_entity_pde - information specific to Power Domain Entities
+ * @managed: Dynamically allocated array pointing to each Entity
+ * controlled by this PDE.
+ * @max_delay: Dynamically allocated array of delays for switching
+ * between power states.
+ * @num_managed: Number of Entities controlled by this PDE.
+ * @num_max_delay: Number of delays specified for state changes.
+ */
+struct sdca_entity_pde {
+ struct sdca_entity **managed;
+ struct sdca_pde_delay *max_delay;
+ int num_managed;
+ int num_max_delay;
+};
+
/**
* enum sdca_entity_type - SDCA Entity Type codes
* @SDCA_ENTITY_TYPE_ENTITY_0: Entity 0, not actually from the
@@ -870,6 +916,7 @@ enum sdca_entity_type {
* @num_controls: Number of Controls for the Entity.
* @iot: Input/Output Terminal specific Entity properties.
* @cs: Clock Source specific Entity properties.
+ * @pde: Power Domain Entity specific Entity properties.
*/
struct sdca_entity {
const char *label;
@@ -883,6 +930,7 @@ struct sdca_entity {
union {
struct sdca_entity_iot iot;
struct sdca_entity_cs cs;
+ struct sdca_entity_pde pde;
};
};
diff --git a/sound/soc/sdca/sdca_functions.c b/sound/soc/sdca/sdca_functions.c
index dd9e2dce6e658..091d55abe1091 100644
--- a/sound/soc/sdca/sdca_functions.c
+++ b/sound/soc/sdca/sdca_functions.c
@@ -908,6 +908,66 @@ static int find_sdca_entity_cs(struct device *dev,
return 0;
}
+static int find_sdca_entity_pde(struct device *dev,
+ struct fwnode_handle *entity_node,
+ struct sdca_entity *entity)
+{
+ static const int mult_delay = 3;
+ struct sdca_entity_pde *power = &entity->pde;
+ struct sdca_pde_delay *delays;
+ int num_delays;
+ u32 *delay_list;
+ int i, j;
+
+ num_delays = fwnode_property_count_u32(entity_node,
+ "mipi-sdca-powerdomain-transition-max-delay");
+ if (num_delays <= 0) {
+ dev_err(dev, "%s: max delay list missing: %d\n",
+ entity->label, num_delays);
+ return -EINVAL;
+ } else if (num_delays % mult_delay != 0) {
+ dev_err(dev, "%s: delays not multiple of %d\n",
+ entity->label, mult_delay);
+ return -EINVAL;
+ } else if (num_delays > SDCA_MAX_DELAY_COUNT) {
+ dev_err(dev, "%s: maximum number of transition delays exceeded\n",
+ entity->label);
+ return -EINVAL;
+ }
+
+ /* There are 3 values per delay */
+ delays = devm_kcalloc(dev, num_delays / mult_delay,
+ sizeof(*delays), GFP_KERNEL);
+ if (!delays)
+ return -ENOMEM;
+
+ delay_list = kcalloc(num_delays, sizeof(*delay_list), GFP_KERNEL);
+ if (!delay_list)
+ return -ENOMEM;
+
+ fwnode_property_read_u32_array(entity_node,
+ "mipi-sdca-powerdomain-transition-max-delay",
+ delay_list, num_delays);
+
+ num_delays /= mult_delay;
+
+ for (i = 0, j = 0; i < num_delays; i++) {
+ delays[i].from_ps = delay_list[j++];
+ delays[i].to_ps = delay_list[j++];
+ delays[i].us = delay_list[j++];
+
+ dev_info(dev, "%s: from %#x to %#x delay %dus\n", entity->label,
+ delays[i].from_ps, delays[i].to_ps, delays[i].us);
+ }
+
+ power->num_max_delay = num_delays;
+ power->max_delay = delays;
+
+ kfree(delay_list);
+
+ return 0;
+}
+
static int find_sdca_entity(struct device *dev,
struct fwnode_handle *function_node,
struct fwnode_handle *entity_node,
@@ -943,6 +1003,9 @@ static int find_sdca_entity(struct device *dev,
case SDCA_ENTITY_TYPE_CS:
ret = find_sdca_entity_cs(dev, entity_node, entity);
break;
+ case SDCA_ENTITY_TYPE_PDE:
+ ret = find_sdca_entity_pde(dev, entity_node, entity);
+ break;
default:
break;
}
@@ -1047,6 +1110,21 @@ static struct sdca_entity *find_sdca_entity_by_label(struct sdca_function_data *
return NULL;
}
+static struct sdca_entity *find_sdca_entity_by_id(struct sdca_function_data *function,
+ const int id)
+{
+ int i;
+
+ for (i = 0; i < function->num_entities; i++) {
+ struct sdca_entity *entity = &function->entities[i];
+
+ if (entity->id == id)
+ return entity;
+ }
+
+ return NULL;
+}
+
static int find_sdca_entity_connection_iot(struct device *dev,
struct sdca_function_data *function,
struct fwnode_handle *entity_node,
@@ -1087,6 +1165,62 @@ static int find_sdca_entity_connection_iot(struct device *dev,
return 0;
}
+static int find_sdca_entity_connection_pde(struct device *dev,
+ struct sdca_function_data *function,
+ struct fwnode_handle *entity_node,
+ struct sdca_entity *entity)
+{
+ struct sdca_entity_pde *power = &entity->pde;
+ struct sdca_entity **managed;
+ u32 *managed_list;
+ int num_managed;
+ int i;
+
+ num_managed = fwnode_property_count_u32(entity_node,
+ "mipi-sdca-powerdomain-managed-list");
+ if (!num_managed) {
+ return 0;
+ } else if (num_managed < 0) {
+ dev_err(dev, "%s: managed list missing: %d\n", entity->label, num_managed);
+ return num_managed;
+ } else if (num_managed > SDCA_MAX_ENTITY_COUNT) {
+ dev_err(dev, "%s: maximum number of managed entities exceeded\n",
+ entity->label);
+ return -EINVAL;
+ }
+
+ managed = devm_kcalloc(dev, num_managed, sizeof(*managed), GFP_KERNEL);
+ if (!managed)
+ return -ENOMEM;
+
+ managed_list = kcalloc(num_managed, sizeof(*managed_list), GFP_KERNEL);
+ if (!managed_list)
+ return -ENOMEM;
+
+ fwnode_property_read_u32_array(entity_node,
+ "mipi-sdca-powerdomain-managed-list",
+ managed_list, num_managed);
+
+ for (i = 0; i < num_managed; i++) {
+ managed[i] = find_sdca_entity_by_id(function, managed_list[i]);
+ if (!managed[i]) {
+ dev_err(dev, "%s: failed to find entity with id %#x\n",
+ entity->label, managed_list[i]);
+ kfree(managed_list);
+ return -EINVAL;
+ }
+
+ dev_info(dev, "%s -> %s\n", managed[i]->label, entity->label);
+ }
+
+ kfree(managed_list);
+
+ power->num_managed = num_managed;
+ power->managed = managed;
+
+ return 0;
+}
+
static int find_sdca_entity_connection(struct device *dev,
struct sdca_function_data *function,
struct fwnode_handle *entity_node,
@@ -1103,6 +1237,10 @@ static int find_sdca_entity_connection(struct device *dev,
ret = find_sdca_entity_connection_iot(dev, function,
entity_node, entity);
break;
+ case SDCA_ENTITY_TYPE_PDE:
+ ret = find_sdca_entity_connection_pde(dev, function,
+ entity_node, entity);
+ break;
default:
ret = 0;
break;
--
2.39.5
next prev 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 ` [PATCH 06/10] ASoC: SDCA: Add parsing for Control range structures Charles Keepax
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 ` Charles Keepax [this message]
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-11-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