* [PATCH 0/4] Add SDCA register map support
@ 2025-02-17 14:01 Charles Keepax
2025-02-17 14:01 ` [PATCH 1/4] regcache: Add support for sorting defaults arrays Charles Keepax
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Charles Keepax @ 2025-02-17 14:01 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, peter.ujfalusi, yung-chuan.liao, pierre-louis.bossart,
linux-kernel, linux-sound
This series is the next step of adding SDCA support. Here we add
helper functions to allow drivers to easily use the SDCA DisCo
information to create a register map for the device.
The basic idea here is the code takes the list of SDCA controls parsed
from DisCo and uses primarily the Access Mode to determine if the
register should be marked as readable/writable etc. Further more
some additional concepts such as DisCo Constants and Defaults are
handled. There is some potential confusion, as DisCo Constants are
handled as an entry in the regmap defaults table, whereas a DisCo
Default is simply handled as a write to the register. Alas the naming
confusion is an unavoidable result of the slight impedance mismatch
between the two systems.
Thanks,
Charles
Charles Keepax (4):
regcache: Add support for sorting defaults arrays
ASoC: SDCA: Add generic regmap SDCA helpers
ASoC: SDCA: Add regmap helpers for parsing for DisCo Constant values
ASoC: SDCA: Add helper to write out defaults and fixed values
drivers/base/regmap/regcache.c | 31 ++++
include/linux/regmap.h | 7 +
include/sound/sdca_regmap.h | 31 ++++
sound/soc/sdca/Makefile | 2 +-
sound/soc/sdca/sdca_regmap.c | 321 +++++++++++++++++++++++++++++++++
5 files changed, 391 insertions(+), 1 deletion(-)
create mode 100644 include/sound/sdca_regmap.h
create mode 100644 sound/soc/sdca/sdca_regmap.c
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/4] regcache: Add support for sorting defaults arrays
2025-02-17 14:01 [PATCH 0/4] Add SDCA register map support Charles Keepax
@ 2025-02-17 14:01 ` Charles Keepax
2025-02-17 14:01 ` [PATCH 2/4] ASoC: SDCA: Add generic regmap SDCA helpers Charles Keepax
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Charles Keepax @ 2025-02-17 14:01 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, peter.ujfalusi, yung-chuan.liao, pierre-louis.bossart,
linux-kernel, linux-sound
The defaults array in regcache must be sorted into ascending register
address order, because binary search is used to locate values in
the array. Add a helper to sort the register defaults array which
can be useful for systems that dynamically create a defaults array
based on external information.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
drivers/base/regmap/regcache.c | 31 +++++++++++++++++++++++++++++++
include/linux/regmap.h | 7 +++++++
2 files changed, 38 insertions(+)
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index b1f8508c3966..f7fcf2de1301 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -21,6 +21,37 @@ static const struct regcache_ops *cache_types[] = {
®cache_flat_ops,
};
+static int regcache_defaults_cmp(const void *a, const void *b)
+{
+ const struct reg_default *x = a;
+ const struct reg_default *y = b;
+
+ if (x->reg > y->reg)
+ return 1;
+ else if (x->reg < y->reg)
+ return -1;
+ else
+ return 0;
+}
+
+static void regcache_defaults_swap(void *a, void *b, int size)
+{
+ struct reg_default *x = a;
+ struct reg_default *y = b;
+ struct reg_default tmp;
+
+ tmp = *x;
+ *x = *y;
+ *y = tmp;
+}
+
+void regcache_sort_defaults(struct reg_default *defaults, unsigned int ndefaults)
+{
+ sort(defaults, ndefaults, sizeof(*defaults),
+ regcache_defaults_cmp, regcache_defaults_swap);
+}
+EXPORT_SYMBOL_GPL(regcache_sort_defaults);
+
static int regcache_hw_init(struct regmap *map)
{
int i, j;
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 3a96d068915f..d17c5ea3d55d 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -1352,6 +1352,7 @@ bool regmap_can_raw_write(struct regmap *map);
size_t regmap_get_raw_read_max(struct regmap *map);
size_t regmap_get_raw_write_max(struct regmap *map);
+void regcache_sort_defaults(struct reg_default *defaults, unsigned int ndefaults);
int regcache_sync(struct regmap *map);
int regcache_sync_region(struct regmap *map, unsigned int min,
unsigned int max);
@@ -2043,6 +2044,12 @@ static inline bool regmap_might_sleep(struct regmap *map)
return true;
}
+static inline void regcache_sort_defaults(struct reg_default *defaults,
+ unsigned int ndefaults)
+{
+ WARN_ONCE(1, "regmap API is disabled");
+}
+
static inline int regcache_sync(struct regmap *map)
{
WARN_ONCE(1, "regmap API is disabled");
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/4] ASoC: SDCA: Add generic regmap SDCA helpers
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 ` Charles Keepax
2025-02-17 14:01 ` [PATCH 3/4] ASoC: SDCA: Add regmap helpers for parsing for DisCo Constant values Charles Keepax
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Charles Keepax @ 2025-02-17 14:01 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, peter.ujfalusi, yung-chuan.liao, pierre-louis.bossart,
linux-kernel, linux-sound
Add helper functions that SDCA drivers can use to calculate the
properties of SDCA Controls (registers) specified through DisCo.
Most of these are fairly obvious from the SDCA Access Modes.
DisCo Constants, values which are specified in the ACPI rather than on
the device, are handled as unreadable and unwritable registers. The
intention is these will be populated in the register defaults table
allowing drivers to read them normally. This means the drivers can be
agnostic as to which values are DisCo Constants.
Finally, support for SDCA Dual Ranked Controls is currently limited
here, at the moment the current value will be used directly. Writing
the current value directly is valid as per the specification
although the synchronicity of updates across multiple registers is
lost. Support for this will probably need to be added later. But its a
fairly hard problem and doesn't need to be solved immediately.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
include/sound/sdca_regmap.h | 21 ++++
sound/soc/sdca/Makefile | 2 +-
sound/soc/sdca/sdca_regmap.c | 192 +++++++++++++++++++++++++++++++++++
3 files changed, 214 insertions(+), 1 deletion(-)
create mode 100644 include/sound/sdca_regmap.h
create mode 100644 sound/soc/sdca/sdca_regmap.c
diff --git a/include/sound/sdca_regmap.h b/include/sound/sdca_regmap.h
new file mode 100644
index 000000000000..11826f4f0726
--- /dev/null
+++ b/include/sound/sdca_regmap.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * The MIPI SDCA specification is available for public downloads at
+ * https://www.mipi.org/mipi-sdca-v1-0-download
+ *
+ * Copyright (C) 2025 Cirrus Logic, Inc. and
+ * Cirrus Logic International Semiconductor Ltd.
+ */
+
+#ifndef __SDCA_REGMAP_H__
+#define __SDCA_REGMAP_H__
+
+struct sdca_function_data;
+
+bool sdca_regmap_readable(struct sdca_function_data *function, unsigned int reg);
+bool sdca_regmap_writeable(struct sdca_function_data *function, unsigned int reg);
+bool sdca_regmap_volatile(struct sdca_function_data *function, unsigned int reg);
+bool sdca_regmap_deferrable(struct sdca_function_data *function, unsigned int reg);
+int sdca_regmap_mbq_size(struct sdca_function_data *function, unsigned int reg);
+
+#endif // __SDCA_REGMAP_H__
diff --git a/sound/soc/sdca/Makefile b/sound/soc/sdca/Makefile
index 5d1ddbbfbf62..dddc3e694256 100644
--- a/sound/soc/sdca/Makefile
+++ b/sound/soc/sdca/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
-snd-soc-sdca-y := sdca_functions.o sdca_device.o
+snd-soc-sdca-y := sdca_functions.o sdca_device.o sdca_regmap.o
obj-$(CONFIG_SND_SOC_SDCA) += snd-soc-sdca.o
diff --git a/sound/soc/sdca/sdca_regmap.c b/sound/soc/sdca/sdca_regmap.c
new file mode 100644
index 000000000000..ae6358f0fc26
--- /dev/null
+++ b/sound/soc/sdca/sdca_regmap.c
@@ -0,0 +1,192 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2025 Cirrus Logic, Inc. and
+// Cirrus Logic International Semiconductor Ltd.
+
+/*
+ * The MIPI SDCA specification is available for public downloads at
+ * https://www.mipi.org/mipi-sdca-v1-0-download
+ */
+
+#include <linux/bitops.h>
+#include <linux/minmax.h>
+#include <linux/module.h>
+#include <linux/soundwire/sdw_registers.h>
+#include <linux/types.h>
+#include <sound/sdca_function.h>
+#include <sound/sdca_regmap.h>
+
+static struct sdca_entity *
+function_find_entity(struct sdca_function_data *function, unsigned int reg)
+{
+ int i;
+
+ for (i = 0; i < function->num_entities; i++)
+ if (SDW_SDCA_CTL_ENT(reg) == function->entities[i].id)
+ return &function->entities[i];
+
+ return NULL;
+}
+
+static struct sdca_control *
+entity_find_control(struct sdca_entity *entity, unsigned int reg)
+{
+ int i;
+
+ for (i = 0; i < entity->num_controls; i++) {
+ if (SDW_SDCA_CTL_CSEL(reg) == entity->controls[i].sel)
+ return &entity->controls[i];
+ }
+
+ return NULL;
+}
+
+static struct sdca_control *
+function_find_control(struct sdca_function_data *function, unsigned int reg)
+{
+ struct sdca_entity *entity;
+
+ entity = function_find_entity(function, reg);
+ if (!entity)
+ return NULL;
+
+ return entity_find_control(entity, reg);
+}
+
+/**
+ * sdca_regmap_readable - return if a given SDCA Control is readable
+ * @function: Pointer to the Function information.
+ * @reg: Register address/Control to be processed.
+ *
+ * Return: Returns true if the register is readable.
+ */
+bool sdca_regmap_readable(struct sdca_function_data *function, unsigned int reg)
+{
+ struct sdca_control *control;
+
+ if (!SDW_SDCA_VALID_CTL(reg))
+ return false;
+
+ control = function_find_control(function, reg);
+ if (!control)
+ return false;
+
+ switch (control->mode) {
+ case SDCA_ACCESS_MODE_RW:
+ case SDCA_ACCESS_MODE_RO:
+ case SDCA_ACCESS_MODE_DUAL:
+ case SDCA_ACCESS_MODE_RW1S:
+ case SDCA_ACCESS_MODE_RW1C:
+ /* No access to registers marked solely for device use */
+ return control->layers & ~SDCA_ACCESS_LAYER_DEVICE;
+ default:
+ return false;
+ }
+}
+EXPORT_SYMBOL_NS(sdca_regmap_readable, "SND_SOC_SDCA");
+
+/**
+ * sdca_regmap_writeable - return if a given SDCA Control is writeable
+ * @function: Pointer to the Function information.
+ * @reg: Register address/Control to be processed.
+ *
+ * Return: Returns true if the register is writeable.
+ */
+bool sdca_regmap_writeable(struct sdca_function_data *function, unsigned int reg)
+{
+ struct sdca_control *control;
+
+ if (!SDW_SDCA_VALID_CTL(reg))
+ return false;
+
+ control = function_find_control(function, reg);
+ if (!control)
+ return false;
+
+ switch (control->mode) {
+ case SDCA_ACCESS_MODE_RW:
+ case SDCA_ACCESS_MODE_DUAL:
+ case SDCA_ACCESS_MODE_RW1S:
+ case SDCA_ACCESS_MODE_RW1C:
+ /* No access to registers marked solely for device use */
+ return control->layers & ~SDCA_ACCESS_LAYER_DEVICE;
+ default:
+ return false;
+ }
+}
+EXPORT_SYMBOL_NS(sdca_regmap_writeable, "SND_SOC_SDCA");
+
+/**
+ * sdca_regmap_volatile - return if a given SDCA Control is volatile
+ * @function: Pointer to the Function information.
+ * @reg: Register address/Control to be processed.
+ *
+ * Return: Returns true if the register is volatile.
+ */
+bool sdca_regmap_volatile(struct sdca_function_data *function, unsigned int reg)
+{
+ struct sdca_control *control;
+
+ if (!SDW_SDCA_VALID_CTL(reg))
+ return false;
+
+ control = function_find_control(function, reg);
+ if (!control)
+ return false;
+
+ switch (control->mode) {
+ case SDCA_ACCESS_MODE_RO:
+ case SDCA_ACCESS_MODE_RW1S:
+ case SDCA_ACCESS_MODE_RW1C:
+ return true;
+ default:
+ return false;
+ }
+}
+EXPORT_SYMBOL_NS(sdca_regmap_volatile, "SND_SOC_SDCA");
+
+/**
+ * sdca_regmap_deferrable - return if a given SDCA Control is deferrable
+ * @function: Pointer to the Function information.
+ * @reg: Register address/Control to be processed.
+ *
+ * Return: Returns true if the register is deferrable.
+ */
+bool sdca_regmap_deferrable(struct sdca_function_data *function, unsigned int reg)
+{
+ struct sdca_control *control;
+
+ if (!SDW_SDCA_VALID_CTL(reg))
+ return false;
+
+ control = function_find_control(function, reg);
+ if (!control)
+ return false;
+
+ return control->deferrable;
+}
+EXPORT_SYMBOL_NS(sdca_regmap_deferrable, "SND_SOC_SDCA");
+
+/**
+ * sdca_regmap_mbq_size - return size in bytes of a given SDCA Control
+ * @function: Pointer to the Function information.
+ * @reg: Register address/Control to be processed.
+ *
+ * Return: Returns the size in bytes of the Control.
+ */
+int sdca_regmap_mbq_size(struct sdca_function_data *function, unsigned int reg)
+{
+ struct sdca_control *control;
+
+ if (!SDW_SDCA_VALID_CTL(reg))
+ return -EINVAL;
+
+ control = function_find_control(function, reg);
+ if (!control)
+ return false;
+
+ return clamp_val(control->nbits / BITS_PER_BYTE, sizeof(u8), sizeof(u32));
+}
+EXPORT_SYMBOL_NS(sdca_regmap_mbq_size, "SND_SOC_SDCA");
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("SDCA library");
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/4] ASoC: SDCA: Add regmap helpers for parsing for DisCo Constant values
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 ` Charles Keepax
2025-02-17 14:01 ` [PATCH 4/4] ASoC: SDCA: Add helper to write out defaults and fixed values Charles Keepax
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Charles Keepax @ 2025-02-17 14:01 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, peter.ujfalusi, yung-chuan.liao, pierre-louis.bossart,
linux-kernel, linux-sound
Add helpers to parse the DisCo Constant values from ACPI and populate an
array of reg_defaults with these. This will allow drivers to access
these ACPI specified values through the same interface as other
registers that are physically present on the device, using the regmap
cache.
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---
include/sound/sdca_regmap.h | 6 +++
sound/soc/sdca/sdca_regmap.c | 80 ++++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+)
diff --git a/include/sound/sdca_regmap.h b/include/sound/sdca_regmap.h
index 11826f4f0726..850533e83f3b 100644
--- a/include/sound/sdca_regmap.h
+++ b/include/sound/sdca_regmap.h
@@ -10,7 +10,9 @@
#ifndef __SDCA_REGMAP_H__
#define __SDCA_REGMAP_H__
+struct device;
struct sdca_function_data;
+struct reg_default;
bool sdca_regmap_readable(struct sdca_function_data *function, unsigned int reg);
bool sdca_regmap_writeable(struct sdca_function_data *function, unsigned int reg);
@@ -18,4 +20,8 @@ bool sdca_regmap_volatile(struct sdca_function_data *function, unsigned int reg)
bool sdca_regmap_deferrable(struct sdca_function_data *function, unsigned int reg);
int sdca_regmap_mbq_size(struct sdca_function_data *function, unsigned int reg);
+int sdca_regmap_count_constants(struct device *dev, struct sdca_function_data *function);
+int sdca_regmap_populate_constants(struct device *dev, struct sdca_function_data *function,
+ struct reg_default *consts);
+
#endif // __SDCA_REGMAP_H__
diff --git a/sound/soc/sdca/sdca_regmap.c b/sound/soc/sdca/sdca_regmap.c
index ae6358f0fc26..dba4188620f9 100644
--- a/sound/soc/sdca/sdca_regmap.c
+++ b/sound/soc/sdca/sdca_regmap.c
@@ -10,8 +10,10 @@
#include <linux/bitops.h>
#include <linux/minmax.h>
#include <linux/module.h>
+#include <linux/regmap.h>
#include <linux/soundwire/sdw_registers.h>
#include <linux/types.h>
+#include <sound/sdca.h>
#include <sound/sdca_function.h>
#include <sound/sdca_regmap.h>
@@ -188,5 +190,83 @@ int sdca_regmap_mbq_size(struct sdca_function_data *function, unsigned int reg)
}
EXPORT_SYMBOL_NS(sdca_regmap_mbq_size, "SND_SOC_SDCA");
+/**
+ * sdca_regmap_count_constants - count the number of DisCo constant Controls
+ * @dev: Pointer to the device.
+ * @function: Pointer to the Function information, to be parsed.
+ *
+ * This function returns the number of DisCo constant Controls present
+ * in a function. Typically this information will be used to populate
+ * the regmap defaults array, allowing drivers to access the values of
+ * DisCo constants as any other physical register.
+ *
+ * Return: Returns number of DisCo constant controls, or a negative error
+ * code on failure.
+ */
+int sdca_regmap_count_constants(struct device *dev,
+ struct sdca_function_data *function)
+{
+ int nconsts = 0;
+ int i, j;
+
+ for (i = 0; i < function->num_entities; i++) {
+ struct sdca_entity *entity = &function->entities[i];
+
+ for (j = 0; j < entity->num_controls; j++) {
+ if (entity->controls[j].mode == SDCA_ACCESS_MODE_DC)
+ nconsts += hweight64(entity->controls[j].cn_list);
+ }
+ }
+
+ return nconsts;
+}
+EXPORT_SYMBOL_NS(sdca_regmap_count_constants, "SND_SOC_SDCA");
+
+/**
+ * sdca_regmap_populate_constants - fill an array with DisCo constant values
+ * @dev: Pointer to the device.
+ * @function: Pointer to the Function information, to be parsed.
+ * @consts: Pointer to the array which should be filled with the DisCo
+ * constant values.
+ *
+ * This function will populate a regmap struct reg_default array with
+ * the values of the DisCo constants for a given Function. This
+ * allows to access the values of DisCo constants the same as any
+ * other physical register.
+ *
+ * Return: Returns the number of constants populated on success, a negative
+ * error code on failure.
+ */
+int sdca_regmap_populate_constants(struct device *dev,
+ struct sdca_function_data *function,
+ struct reg_default *consts)
+{
+ int i, j, k;
+
+ for (i = 0, k = 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;
+
+ for_each_set_bit(cn, (unsigned long *)&control->cn_list,
+ BITS_PER_TYPE(control->cn_list)) {
+ consts[k].reg = SDW_SDCA_CTL(function->desc->adr,
+ entity->id,
+ control->sel, cn);
+ consts[k].def = control->value;
+ k++;
+ }
+ }
+ }
+
+ return k;
+}
+EXPORT_SYMBOL_NS(sdca_regmap_populate_constants, "SND_SOC_SDCA");
+
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("SDCA library");
--
2.39.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/4] ASoC: SDCA: Add helper to write out defaults and fixed values
2025-02-17 14:01 [PATCH 0/4] Add SDCA register map support Charles Keepax
` (2 preceding siblings ...)
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
2025-02-20 13:01 ` [PATCH 0/4] Add SDCA register map support Pierre-Louis Bossart
2025-02-27 17:27 ` Mark Brown
5 siblings, 0 replies; 8+ messages in thread
From: Charles Keepax @ 2025-02-17 14:01 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, peter.ujfalusi, yung-chuan.liao, pierre-louis.bossart,
linux-kernel, linux-sound
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 0/4] Add SDCA register map support
2025-02-17 14:01 [PATCH 0/4] Add SDCA register map support Charles Keepax
` (3 preceding siblings ...)
2025-02-17 14:01 ` [PATCH 4/4] ASoC: SDCA: Add helper to write out defaults and fixed values Charles Keepax
@ 2025-02-20 13:01 ` Pierre-Louis Bossart
2025-02-21 9:46 ` Charles Keepax
2025-02-27 17:27 ` Mark Brown
5 siblings, 1 reply; 8+ messages in thread
From: Pierre-Louis Bossart @ 2025-02-20 13:01 UTC (permalink / raw)
To: Charles Keepax, broonie
Cc: lgirdwood, peter.ujfalusi, yung-chuan.liao, linux-kernel,
linux-sound
On 2/17/25 08:01, Charles Keepax wrote:
> This series is the next step of adding SDCA support. Here we add
> helper functions to allow drivers to easily use the SDCA DisCo
> information to create a register map for the device.
Can you remind me where we ended-up in the discussion on one regmap per physical device or one regmap per function?
The DisCo definition are all function-centric, but the physical SoundWire bus access for all read/writes is shared by all functions so having a single regmap isn't silly either.
> The basic idea here is the code takes the list of SDCA controls parsed
> from DisCo and uses primarily the Access Mode to determine if the
> register should be marked as readable/writable etc. Further more
> some additional concepts such as DisCo Constants and Defaults are
> handled. There is some potential confusion, as DisCo Constants are
> handled as an entry in the regmap defaults table, whereas a DisCo
> Default is simply handled as a write to the register. Alas the naming
> confusion is an unavoidable result of the slight impedance mismatch
> between the two systems.
>
> Thanks,
> Charles
>
> Charles Keepax (4):
> regcache: Add support for sorting defaults arrays
> ASoC: SDCA: Add generic regmap SDCA helpers
> ASoC: SDCA: Add regmap helpers for parsing for DisCo Constant values
> ASoC: SDCA: Add helper to write out defaults and fixed values
The code looks fine, thanks!
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
>
> drivers/base/regmap/regcache.c | 31 ++++
> include/linux/regmap.h | 7 +
> include/sound/sdca_regmap.h | 31 ++++
> sound/soc/sdca/Makefile | 2 +-
> sound/soc/sdca/sdca_regmap.c | 321 +++++++++++++++++++++++++++++++++
> 5 files changed, 391 insertions(+), 1 deletion(-)
> create mode 100644 include/sound/sdca_regmap.h
> create mode 100644 sound/soc/sdca/sdca_regmap.c
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/4] Add SDCA register map support
2025-02-20 13:01 ` [PATCH 0/4] Add SDCA register map support Pierre-Louis Bossart
@ 2025-02-21 9:46 ` Charles Keepax
0 siblings, 0 replies; 8+ messages in thread
From: Charles Keepax @ 2025-02-21 9:46 UTC (permalink / raw)
To: Pierre-Louis Bossart
Cc: broonie, lgirdwood, peter.ujfalusi, yung-chuan.liao, linux-kernel,
linux-sound
On Thu, Feb 20, 2025 at 07:01:44AM -0600, Pierre-Louis Bossart wrote:
> On 2/17/25 08:01, Charles Keepax wrote:
> > This series is the next step of adding SDCA support. Here we add
> > helper functions to allow drivers to easily use the SDCA DisCo
> > information to create a register map for the device.
>
> Can you remind me where we ended-up in the discussion on one
> regmap per physical device or one regmap per function?
>
> The DisCo definition are all function-centric, but the physical
> SoundWire bus access for all read/writes is shared by all functions
> so having a single regmap isn't silly either.
>
We haven't really fully resolved that yet, however, I have
came to the conclusion that all the helper function bits I am
currently adding are completely agnostic of the choice.
So I think it makes most sense to address this once we are adding
an actually driver component. That way we will have the most
context for discussion.
Thanks,
Charles
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/4] Add SDCA register map support
2025-02-17 14:01 [PATCH 0/4] Add SDCA register map support Charles Keepax
` (4 preceding siblings ...)
2025-02-20 13:01 ` [PATCH 0/4] Add SDCA register map support Pierre-Louis Bossart
@ 2025-02-27 17:27 ` Mark Brown
5 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2025-02-27 17:27 UTC (permalink / raw)
To: Charles Keepax
Cc: lgirdwood, peter.ujfalusi, yung-chuan.liao, pierre-louis.bossart,
linux-kernel, linux-sound
On Mon, 17 Feb 2025 14:01:55 +0000, Charles Keepax wrote:
> This series is the next step of adding SDCA support. Here we add
> helper functions to allow drivers to easily use the SDCA DisCo
> information to create a register map for the device.
>
> The basic idea here is the code takes the list of SDCA controls parsed
> from DisCo and uses primarily the Access Mode to determine if the
> register should be marked as readable/writable etc. Further more
> some additional concepts such as DisCo Constants and Defaults are
> handled. There is some potential confusion, as DisCo Constants are
> handled as an entry in the regmap defaults table, whereas a DisCo
> Default is simply handled as a write to the register. Alas the naming
> confusion is an unavoidable result of the slight impedance mismatch
> between the two systems.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/4] regcache: Add support for sorting defaults arrays
commit: fd80df352ba1884ce2b62dd8d9495582308101b7
[2/4] ASoC: SDCA: Add generic regmap SDCA helpers
commit: e3f7caf74b795621252e3c25b4a9fb6888336ef1
[3/4] ASoC: SDCA: Add regmap helpers for parsing for DisCo Constant values
commit: 28c12866c22c2826ccbd8c82dc353f02ab2deea5
[4/4] ASoC: SDCA: Add helper to write out defaults and fixed values
commit: c143755d8cce31e770234732ff23134993b0550f
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-02-27 17:27 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 4/4] ASoC: SDCA: Add helper to write out defaults and fixed values Charles Keepax
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox