From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: <broonie@kernel.org>
Cc: <lgirdwood@gmail.com>, <peter.ujfalusi@linux.intel.com>,
<yung-chuan.liao@linux.intel.com>,
<pierre-louis.bossart@linux.dev>, <linux-kernel@vger.kernel.org>,
<linux-sound@vger.kernel.org>
Subject: [PATCH 4/4] ASoC: SDCA: Add helper to write out defaults and fixed values
Date: Mon, 17 Feb 2025 14:01:59 +0000 [thread overview]
Message-ID: <20250217140159.2288784-5-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20250217140159.2288784-1-ckeepax@opensource.cirrus.com>
The concept of an SDCA default value differs slightly from the regmap
usage of the term. An SDCA default is a value that is parsed from DisCo
and then written out to the hardware if no user value has superceded
it. Add a helper function that will iterate through all the SDCA
Controls and write out any default values. After these have been written
out once they will exist in the cache and that will take care of any
user values superceeding them. The code here also writes out any
Controls with a fixed value as there is only one available value for
these Controls there is no point in allowing the user to select them,
simply treat them similarly to a default.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
include/sound/sdca_regmap.h | 4 +++
sound/soc/sdca/sdca_regmap.c | 49 ++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+)
diff --git a/include/sound/sdca_regmap.h b/include/sound/sdca_regmap.h
index 850533e83f3b..b2e3c2ad2bb8 100644
--- a/include/sound/sdca_regmap.h
+++ b/include/sound/sdca_regmap.h
@@ -12,6 +12,7 @@
struct device;
struct sdca_function_data;
+struct regmap;
struct reg_default;
bool sdca_regmap_readable(struct sdca_function_data *function, unsigned int reg);
@@ -24,4 +25,7 @@ int sdca_regmap_count_constants(struct device *dev, struct sdca_function_data *f
int sdca_regmap_populate_constants(struct device *dev, struct sdca_function_data *function,
struct reg_default *consts);
+int sdca_regmap_write_defaults(struct device *dev, struct regmap *regmap,
+ struct sdca_function_data *function);
+
#endif // __SDCA_REGMAP_H__
diff --git a/sound/soc/sdca/sdca_regmap.c b/sound/soc/sdca/sdca_regmap.c
index dba4188620f9..4b78188cfceb 100644
--- a/sound/soc/sdca/sdca_regmap.c
+++ b/sound/soc/sdca/sdca_regmap.c
@@ -268,5 +268,54 @@ int sdca_regmap_populate_constants(struct device *dev,
}
EXPORT_SYMBOL_NS(sdca_regmap_populate_constants, "SND_SOC_SDCA");
+/**
+ * sdca_regmap_write_defaults - write out DisCo defaults to device
+ * @dev: Pointer to the device.
+ * @regmap: Pointer to the Function register map.
+ * @function: Pointer to the Function information, to be parsed.
+ *
+ * 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.
+ *
+ * Return: Returns zero on success, and a negative error code on failure.
+ */
+int sdca_regmap_write_defaults(struct device *dev, struct regmap *regmap,
+ struct sdca_function_data *function)
+{
+ int i, j;
+ int ret;
+
+ for (i = 0; i < function->num_entities; i++) {
+ struct sdca_entity *entity = &function->entities[i];
+
+ for (j = 0; j < entity->num_controls; j++) {
+ struct sdca_control *control = &entity->controls[j];
+ int cn;
+
+ if (control->mode == SDCA_ACCESS_MODE_DC)
+ continue;
+
+ if (!control->has_default && !control->has_fixed)
+ continue;
+
+ for_each_set_bit(cn, (unsigned long *)&control->cn_list,
+ BITS_PER_TYPE(control->cn_list)) {
+ unsigned int reg;
+
+ reg = SDW_SDCA_CTL(function->desc->adr, entity->id,
+ control->sel, cn);
+
+ ret = regmap_write(regmap, reg, control->value);
+ if (ret)
+ return ret;
+ }
+ }
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_NS(sdca_regmap_write_defaults, "SND_SOC_SDCA");
+
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("SDCA library");
--
2.39.5
next prev parent reply other threads:[~2025-02-17 14:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-17 14:01 [PATCH 0/4] Add SDCA register map support Charles Keepax
2025-02-17 14:01 ` [PATCH 1/4] regcache: Add support for sorting defaults arrays Charles Keepax
2025-02-17 14:01 ` [PATCH 2/4] ASoC: SDCA: Add generic regmap SDCA helpers Charles Keepax
2025-02-17 14:01 ` [PATCH 3/4] ASoC: SDCA: Add regmap helpers for parsing for DisCo Constant values Charles Keepax
2025-02-17 14:01 ` Charles Keepax [this message]
2025-02-20 13:01 ` [PATCH 0/4] Add SDCA register map support Pierre-Louis Bossart
2025-02-21 9:46 ` Charles Keepax
2025-02-27 17:27 ` 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=20250217140159.2288784-5-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=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