public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v10 1/4] ASoC: SDCA: Add PDE state transition helper
@ 2026-04-21 15:48 Niranjan H Y
  2026-04-21 15:48 ` [PATCH v10 2/4] ASoC: tac5xx2-sdw: add soundwire based codec driver Niranjan H Y
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Niranjan H Y @ 2026-04-21 15:48 UTC (permalink / raw)
  To: linux-sound
  Cc: linux-kernel, broonie, ckeepax, lgirdwood, perex, tiwai,
	cezary.rojewski, peter.ujfalusi, yung-chuan.liao,
	ranjani.sridharan, kai.vehmanen, pierre-louis.bossart, baojun.xu,
	shenghao-ding, sandeepk, v-hampiholi, Niranjan H Y

Per SDCA specification, after writing REQUESTED_PS, drivers must
poll ACTUAL_PS until the target power state is reached.
Implement sdca_asoc_set_pde_state_sync() helper function for
changing the power state of the PDE widget and wait for the power
transition to happen or timeout.

Changes include:
- Add sdca_asoc_set_pde_poll_sync() to handle write
  REQUESTED_PS register and poll ACTUAL_PS register until
  the target state is reached or timed out.
- Export function via sdca_asoc.h for use by SDCA-compliant drivers
- Refactor entity_pde_event() in sdca_asoc.c to use the helper

Signed-off-by: Niranjan H Y <niranjan.hy@ti.com>
---
v10:
- write REQUESTED_PS before checking the target state.
- change the API name sdca_asoc_pde_ensure_ps to
  sdca_asoc_set_pde_poll_sync

v9:
- newly added interface
---
 include/sound/sdca_asoc.h       |   4 ++
 include/sound/sdca_function.h   |   2 +
 sound/soc/sdca/sdca_asoc.c      | 111 ++++++++++++++++++++++----------
 sound/soc/sdca/sdca_functions.c |   4 +-
 4 files changed, 86 insertions(+), 35 deletions(-)

diff --git a/include/sound/sdca_asoc.h b/include/sound/sdca_asoc.h
index 46a61a52decc5..125a3d4e18c09 100644
--- a/include/sound/sdca_asoc.h
+++ b/include/sound/sdca_asoc.h
@@ -12,6 +12,7 @@
 
 struct device;
 struct regmap;
+struct sdca_pde_delay;
 struct sdca_function_data;
 struct snd_ctl_elem_value;
 struct snd_kcontrol;
@@ -99,4 +100,7 @@ int sdca_asoc_q78_put_volsw(struct snd_kcontrol *kcontrol,
 			    struct snd_ctl_elem_value *ucontrol);
 int sdca_asoc_q78_get_volsw(struct snd_kcontrol *kcontrol,
 			    struct snd_ctl_elem_value *ucontrol);
+int sdca_asoc_set_pde_poll_sync(struct device *dev, struct regmap *regmap,
+				int function_id, int entity_id, int from_ps, int to_ps,
+				const struct sdca_pde_delay *pde_delays, int num_delays);
 #endif // __SDCA_ASOC_H__
diff --git a/include/sound/sdca_function.h b/include/sound/sdca_function.h
index 0e871c786513f..18cee74fb1f9b 100644
--- a/include/sound/sdca_function.h
+++ b/include/sound/sdca_function.h
@@ -1173,6 +1173,7 @@ struct sdca_entity_xu {
  * @sources: Dynamically allocated array pointing to each input Entity
  * connected to this Entity.
  * @controls: Dynamically allocated array of Controls.
+ * @parent_func: Pointer to sdca_function_data to which this entity belongs to.
  * @num_sources: Number of sources for the Entity.
  * @num_controls: Number of Controls for the Entity.
  * @iot: Input/Output Terminal specific Entity properties.
@@ -1190,6 +1191,7 @@ struct sdca_entity {
 	struct sdca_entity *group;
 	struct sdca_entity **sources;
 	struct sdca_control *controls;
+	struct sdca_function_data *parent_func;
 	int num_sources;
 	int num_controls;
 	union {
diff --git a/sound/soc/sdca/sdca_asoc.c b/sound/soc/sdca/sdca_asoc.c
index 2bfc8e5aee31d..87e81ee4e90b9 100644
--- a/sound/soc/sdca/sdca_asoc.c
+++ b/sound/soc/sdca/sdca_asoc.c
@@ -359,16 +359,81 @@ static int entity_parse_ot(struct device *dev,
 	return 0;
 }
 
+/**
+ * sdca_asoc_set_pde_poll_sync - change PDE state and wait for trasntion to
+ * complete or timeout.
+ * @dev: Pointer to the device for error logging.
+ * @regmap: Register map for reading ACTUAL_PS register.
+ * @function_id: SDCA function identifier.
+ * @entity_id: SDCA entity identifier for the power domain.
+ * @from_ps: Source power state (SDCA_PDE_PSn value).
+ * @to_ps: Target power state (SDCA_PDE_PSn value).
+ * @pde_delays: Pointer to array of PDE delay specifications for this device,
+ *              or NULL to use default polling interval.
+ * @num_delays: Number of entries in pde_delays array.
+ *
+ * This function writes the REQUESTED_PS register and polls the ACTUAL_PS register to
+ * verify that a PDE power state transition has completed. Per SDCA specification,
+ * after writing REQUESTED_PS, the caller must poll ACTUAL_PS until it reflects the
+ * requested state.
+ *
+ * If a delay table is provided, appropriate polling intervals are extracted based
+ * on the from_ps and to_ps transition. If no table is provided or no matching entry
+ * is found, a default polling interval is used.
+ *
+ * Return: Returns zero when ACTUAL_PS becomes REQUESTED_PS, -ETIMEDOUT if the
+ * polling times out before reaching the target state, or a negative error code if
+ * a register access fails.
+ */
+int sdca_asoc_set_pde_poll_sync(struct device *dev, struct regmap *regmap,
+				int function_id, int entity_id, int from_ps, int to_ps,
+				const struct sdca_pde_delay *pde_delays, int num_delays)
+{
+	static const int polls = 100;
+	static const int default_poll_us = 100;
+	unsigned int requested_ps_reg, actual_ps_reg, val;
+	int poll_us;
+	int i, ret;
+
+	requested_ps_reg = SDW_SDCA_CTL(function_id, entity_id, SDCA_CTL_PDE_REQUESTED_PS, 0);
+	ret = regmap_write(regmap, requested_ps_reg, to_ps);
+	if (ret)
+		return ret;
+
+	poll_us = default_poll_us;
+	if (pde_delays && num_delays > 0) {
+		for (i = 0; i < num_delays; i++) {
+			if (pde_delays[i].from_ps == from_ps && pde_delays[i].to_ps == to_ps) {
+				poll_us = pde_delays[i].us / polls;
+				break;
+			}
+		}
+	}
+
+	actual_ps_reg = SDW_SDCA_CTL(function_id, entity_id, SDCA_CTL_PDE_ACTUAL_PS, 0);
+	for (i = 0; i < polls; i++) {
+		if (i)
+			fsleep(poll_us);
+
+		ret = regmap_read(regmap, actual_ps_reg, &val);
+		if (ret)
+			return ret;
+		else if (val == to_ps)
+			return 0;
+	}
+
+	dev_err(dev, "PDE power transition failed: expected 0x%x, got 0x%x\n", to_ps, val);
+	return -ETIMEDOUT;
+}
+EXPORT_SYMBOL(sdca_asoc_set_pde_poll_sync);
+
 static int entity_pde_event(struct snd_soc_dapm_widget *widget,
 			    struct snd_kcontrol *kctl, int event)
 {
 	struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm);
 	struct sdca_entity *entity = widget->priv;
-	static const int polls = 100;
-	unsigned int reg, val;
-	int from, to, i;
-	int poll_us;
-	int ret;
+	struct sdca_function_data *function;
+	int from, to;
 
 	if (!component)
 		return -EIO;
@@ -385,34 +450,12 @@ static int entity_pde_event(struct snd_soc_dapm_widget *widget,
 	default:
 		return 0;
 	}
+	function = entity->parent_func;
 
-	for (i = 0; i < entity->pde.num_max_delay; i++) {
-		struct sdca_pde_delay *delay = &entity->pde.max_delay[i];
-
-		if (delay->from_ps == from && delay->to_ps == to) {
-			poll_us = delay->us / polls;
-			break;
-		}
-	}
-
-	reg = SDW_SDCA_CTL(SDW_SDCA_CTL_FUNC(widget->reg),
-			   SDW_SDCA_CTL_ENT(widget->reg),
-			   SDCA_CTL_PDE_ACTUAL_PS, 0);
-
-	for (i = 0; i < polls; i++) {
-		if (i)
-			fsleep(poll_us);
-
-		ret = regmap_read(component->regmap, reg, &val);
-		if (ret)
-			return ret;
-		else if (val == to)
-			return 0;
-	}
-
-	dev_err(component->dev, "%s: power transition failed: %x\n",
-		entity->label, val);
-	return -ETIMEDOUT;
+	return sdca_asoc_set_pde_poll_sync(component->dev, component->regmap,
+				       function->desc->adr, entity->id, from, to,
+				       entity->pde.max_delay,
+				       entity->pde.num_max_delay);
 }
 
 static int entity_parse_pde(struct device *dev,
@@ -449,8 +492,8 @@ static int entity_parse_pde(struct device *dev,
 	}
 
 	(*widget)->id = snd_soc_dapm_supply;
-	(*widget)->reg = SDW_SDCA_CTL(function->desc->adr, entity->id, control->sel, 0);
-	(*widget)->mask = GENMASK(control->nbits - 1, 0);
+	(*widget)->reg = SND_SOC_NOPM;
+	(*widget)->mask = 0;
 	(*widget)->on_val = SDCA_PDE_PS0;
 	(*widget)->off_val = SDCA_PDE_PS3;
 	(*widget)->event_flags = SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD;
diff --git a/sound/soc/sdca/sdca_functions.c b/sound/soc/sdca/sdca_functions.c
index fd6a254c95305..2396487213819 100644
--- a/sound/soc/sdca/sdca_functions.c
+++ b/sound/soc/sdca/sdca_functions.c
@@ -1556,8 +1556,10 @@ static int find_sdca_entities(struct device *dev, struct sdw_slave *sdw,
 	fwnode_property_read_u32_array(function_node, "mipi-sdca-entity-id-list",
 				       entity_list, num_entities);
 
-	for (i = 0; i < num_entities; i++)
+	for (i = 0; i < num_entities; i++) {
 		entities[i].id = entity_list[i];
+		entities[i].parent_func = function;
+	}
 
 	/* now read subproperties */
 	for (i = 0; i < num_entities; i++) {
-- 
2.34.1


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

end of thread, other threads:[~2026-04-23 13:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-21 15:48 [PATCH v10 1/4] ASoC: SDCA: Add PDE state transition helper Niranjan H Y
2026-04-21 15:48 ` [PATCH v10 2/4] ASoC: tac5xx2-sdw: add soundwire based codec driver Niranjan H Y
2026-04-21 15:48 ` [PATCH v10 3/4] ASoC: sdw_utils: TI amp utility for tac5xx2 family Niranjan H Y
2026-04-21 15:48 ` [PATCH v10 4/4] ASoC: tac5xx2-sdw: ACPI match for intel mtl platform Niranjan H Y
2026-04-21 15:57 ` [PATCH v10 1/4] ASoC: SDCA: Add PDE state transition helper Charles Keepax
2026-04-21 16:21   ` Pierre-Louis Bossart
2026-04-22  8:26     ` Charles Keepax
2026-04-22 10:39       ` [EXTERNAL] " Holalu Yogendra, Niranjan
2026-04-22 17:56       ` Pierre-Louis Bossart
2026-04-23  8:52         ` Charles Keepax
2026-04-23 12:47           ` Pierre-Louis Bossart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox