All of lore.kernel.org
 help / color / mirror / Atom feed
From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: broonie@kernel.org
Cc: vkoul@kernel.org, yung-chuan.liao@linux.intel.com,
	pierre-louis.bossart@linux.dev, peter.ujfalusi@linux.intel.com,
	shumingf@realtek.com, lgirdwood@gmail.com,
	linux-sound@vger.kernel.org, patches@opensource.cirrus.com
Subject: [PATCH v3 09/13] ASoC: SDCA: Populate regmap cache for readable Controls
Date: Thu,  6 Nov 2025 11:44:18 +0000	[thread overview]
Message-ID: <20251106114422.906370-10-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20251106114422.906370-1-ckeepax@opensource.cirrus.com>

It is not uncommon for an SDCA Control to have no specified default
value in the DisCo. Non-volatile registers with no defaults will not be
present in the cache until they are accessed. However, if the first
operation user-space performs is a read whilst the device is runtime
suspended this read will fail.

To avoid such problems we should populate values from the hardware into
the cache for all non-volatile readable registers with no defaults.
Update the defaults handling to do this cache population since it is
iterating over the Controls and happens at a time the hardware is
always powered up.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---

No changes since v2.

 sound/soc/sdca/sdca_regmap.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/sound/soc/sdca/sdca_regmap.c b/sound/soc/sdca/sdca_regmap.c
index 5104ae99df33a..6fbb241d9d357 100644
--- a/sound/soc/sdca/sdca_regmap.c
+++ b/sound/soc/sdca/sdca_regmap.c
@@ -286,24 +286,33 @@ static int populate_control_defaults(struct device *dev, struct regmap *regmap,
 	if (control->mode == SDCA_ACCESS_MODE_DC)
 		return 0;
 
-	if (!control->has_default && !control->has_fixed)
+	if (control->layers & SDCA_ACCESS_LAYER_DEVICE)
 		return 0;
 
 	i = 0;
 	for_each_set_bit(cn, (unsigned long *)&control->cn_list,
 			 BITS_PER_TYPE(control->cn_list)) {
-		unsigned int reg;
+		unsigned int reg, val;
 
 		reg = SDW_SDCA_CTL(function->desc->adr, entity->id, control->sel, cn);
 
-		ret = regmap_write(regmap, reg, control->values[i]);
-		if (ret) {
-			dev_err(dev, "Failed to write default %#x: %d\n",
-				reg, ret);
-			return ret;
-		}
+		if (control->has_default || control->has_fixed) {
+			ret = regmap_write(regmap, reg, control->values[i]);
+			if (ret) {
+				dev_err(dev, "Failed to write default %#x: %d\n",
+					reg, ret);
+				return ret;
+			}
 
-		i++;
+			i++;
+		} else if (!control->is_volatile) {
+			ret = regmap_read(regmap, reg, &val);
+			if (ret) {
+				dev_err(dev, "Failed to read initial %#x: %d\n",
+					reg, ret);
+				return ret;
+			}
+		}
 	}
 
 	return 0;
@@ -317,7 +326,10 @@ static int populate_control_defaults(struct device *dev, struct regmap *regmap,
  *
  * This function will write out to the hardware all the DisCo default and
  * fixed value controls. This will cause them to be populated into the cache,
- * and subsequent handling can be done through a cache sync.
+ * and subsequent handling can be done through a cache sync. It will also
+ * read any non-volatile registers that don't have defaults/fixed values to
+ * populate those into the cache, this ensures they are available for reads
+ * even when the device is runtime suspended.
  *
  * Return: Returns zero on success, and a negative error code on failure.
  */
-- 
2.47.3


  parent reply	other threads:[~2025-11-06 11:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-06 11:44 [PATCH v3 00/13] Add SDCA class driver Charles Keepax
2025-11-06 11:44 ` [PATCH v3 01/13] ASoC: SDCA: Remove duplicated module macros Charles Keepax
2025-11-06 11:44 ` [PATCH v3 02/13] ASoC: SDCA: Fix missing dash in HIDE DisCo property Charles Keepax
2025-11-06 11:44 ` [PATCH v3 03/13] ASoC: SDCA: Add missing forward declaration in header Charles Keepax
2025-11-06 11:44 ` [PATCH v3 04/13] ASoC: SDCA: Correct FDL locking in sdca_fdl_process() Charles Keepax
2025-11-06 11:44 ` [PATCH v3 05/13] ASoC: SDCA: Add comment for function reset polling Charles Keepax
2025-11-06 11:44 ` [PATCH v3 06/13] ASoC: SDCA: Move most of the messages from info to debug Charles Keepax
2025-11-06 11:44 ` [PATCH v3 07/13] ASoC: SDCA: Use helper macros for control identification Charles Keepax
2025-11-06 11:44 ` [PATCH v3 08/13] ASoC: SDCA: Factor out helper to process Control defaults Charles Keepax
2025-11-06 11:44 ` Charles Keepax [this message]
2025-11-06 11:44 ` [PATCH v3 10/13] ASoC: SDCA: Add helper to write initialization writes Charles Keepax
2025-11-06 11:44 ` [PATCH v3 11/13] ASoC: SDCA: add function devices Charles Keepax
2025-11-06 11:44 ` [PATCH v3 12/13] ASoC: SDCA: Add basic SDCA class driver Charles Keepax
2025-11-06 11:44 ` [PATCH v3 13/13] ASoC: SDCA: Add basic SDCA function driver Charles Keepax
2025-11-17  6:13 ` [PATCH v3 00/13] Add SDCA class driver Liao, Bard
2025-11-19 11:53 ` Maciej Strozek
2025-11-19 13:59 ` Péter Ujfalusi
2025-11-19 15:02 ` Richard Fitzgerald
2025-11-21 22:11 ` 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=20251106114422.906370-10-ckeepax@opensource.cirrus.com \
    --to=ckeepax@opensource.cirrus.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=shumingf@realtek.com \
    --cc=vkoul@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.