Add SDCA register map support
Subsystems (5)
Charles Keepax
maintainercover Add SDCA register map support
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
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH 1/4 regcache: Add support for sorting defaults arrays
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.
--- drivers/base/regmap/regcache.c | 31 +++++++++++++++++++++++++++++++ include/linux/regmap.h | 7 +++++++ 2 files changed, 38 insertions(+)
drivers/base/regmap/regcache.c +31 -0
@@ -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;
include/linux/regmap.h +7 -0
@@ -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" );
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH 2/4 ASoC: SDCA: Add generic regmap SDCA helpers
In reply to Charles KeepaxAdd 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.
--- 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
include/sound/sdca_regmap.h new file +21 -0
@@ -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__
sound/soc/sdca/Makefile +1 -1
@@ -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
sound/soc/sdca/sdca_regmap.c new file +192 -0
192 lines not on this page · raw message
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH 3/4 ASoC: SDCA: Add regmap helpers for parsing for DisCo Constant values
In reply to Charles KeepaxAdd 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.
--- include/sound/sdca_regmap.h | 6 +++ sound/soc/sdca/sdca_regmap.c | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+)
include/sound/sdca_regmap.h +6 -0
@@ -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__
sound/soc/sdca/sdca_regmap.c +80 -0
93 lines not on this page · raw message
Signature · 1 line
2.39.5
Charles Keepax
maintainerPATCH 4/4 ASoC: SDCA: Add helper to write out defaults and fixed values
In reply to Charles KeepaxThe 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.
--- include/sound/sdca_regmap.h | 4 +++ sound/soc/sdca/sdca_regmap.c | 49 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+)
include/sound/sdca_regmap.h +4 -0
@@ -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 *fint 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__
sound/soc/sdca/sdca_regmap.c +49 -0
54 lines not on this page · raw message
Signature · 1 line
2.39.5
Quoted 3 lines · Charles Keepax
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.
Quoted 10 lines
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.
Quoted 8 lines
Thanks,
CharlesCharles 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!
Quoted 10 lines
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
Charles Keepax
maintainerQuoted 5 lines · Pierre-Louis Bossart
Quoted 3 lines · Charles Keepax
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.
Quoted 7 lines
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
Mark Brown
maintainerQuoted 14 lines · Charles Keepax
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.
Quoted 1 line
[...]
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: c143755d8cce31e770234732ff23134993b0550fAll 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