Skip to content

Commit

Permalink
Add SDCA register map support
Browse files Browse the repository at this point in the history
Merge series from Charles Keepax <ckeepax@opensource.cirrus.com>:

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.
  • Loading branch information
Mark Brown committed Feb 27, 2025
2 parents 79ed408 + c143755 commit d0343fd
Show file tree
Hide file tree
Showing 5 changed files with 391 additions and 1 deletion.
31 changes: 31 additions & 0 deletions drivers/base/regmap/regcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,37 @@ static const struct regcache_ops *cache_types[] = {
&regcache_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;
Expand Down
7 changes: 7 additions & 0 deletions include/linux/regmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
31 changes: 31 additions & 0 deletions include/sound/sdca_regmap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* 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 device;
struct sdca_function_data;
struct regmap;
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);
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);

int sdca_regmap_write_defaults(struct device *dev, struct regmap *regmap,
struct sdca_function_data *function);

#endif // __SDCA_REGMAP_H__
2 changes: 1 addition & 1 deletion sound/soc/sdca/Makefile
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit d0343fd

Please sign in to comment.