ASoC: soc-cache: Add support for default readable()/volatile() functions
Subsystems (4)
PATCH v2 1/3 ASoC: soc-cache: Add support for default readable()/volatile() functions
For common scenarios, device drivers can provide a table of all the registers that are at least either readable/writable/volatile. The idea is that if a register lookup fails, all of its read/write/vol members will be zero and will be treated as default. This also reduces the size of the register access array.
--- include/sound/soc.h | 22 ++++++++++++++++++++++ sound/soc/soc-cache.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 0 deletions(-)
include/sound/soc.h +22 -0
@@ -276,6 +276,10 @@ int snd_soc_cache_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value);int snd_soc_cache_read (struct snd_soc_codec *codec,unsigned int reg,unsigned int *value); +int snd_soc_default_volatile_register (struct snd_soc_codec *codec, +unsigned int reg); +int snd_soc_default_readable_register (struct snd_soc_codec *codec, +unsigned int reg);/* Utility functions to get clock rates from various things */ int snd_soc_calc_frame_size (int sample_size,int channels,int tdm_slots);
@@ -367,6 +371,22 @@ int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);/** +* struct snd_soc_reg_access - Describes whether a given register is +* readable, writable or volatile. +* +* @reg: the register number +* @read: whether this register is readable +* @write: whether this register is writable +* @vol: whether this register is volatile +*/ +struct snd_soc_reg_access { +u16 reg; +u16 read; +u16 write; +u16 vol; +}; + +/** * struct snd_soc_jack_pin - Describes a pin to update based on jack detection * * @pin: name of the pin to update
@@ -515,6 +535,8 @@ struct snd_soc_codec_driver {short reg_cache_step;short reg_word_size;const void *reg_cache_default; +short reg_access_size; +const struct snd_soc_reg_access *reg_access_default;enum snd_soc_compress_type compress_type;/* codec bias level */
sound/soc/soc-cache.c +49 -0
52 lines not on this page · raw message
Signature · 1 line
1.7.3.5
PATCH v2 2/3 ASoC: Update users of readable_register()/volatile_register()
--- include/sound/soc.h | 4 ++-- sound/soc/codecs/cs4270.c | 4 ++-- sound/soc/codecs/max98088.c | 2 +- sound/soc/codecs/wm8523.c | 2 +- sound/soc/codecs/wm8804.c | 2 +- sound/soc/codecs/wm8900.c | 2 +- sound/soc/codecs/wm8903.c | 2 +- sound/soc/codecs/wm8904.c | 2 +- sound/soc/codecs/wm8961.c | 2 +- sound/soc/codecs/wm8962.c | 4 ++-- sound/soc/codecs/wm8993.c | 2 +- sound/soc/codecs/wm8994.c | 10 +++++----- sound/soc/codecs/wm8995.c | 2 +- sound/soc/codecs/wm9081.c | 2 +- sound/soc/codecs/wm9090.c | 4 ++-- sound/soc/soc-core.c | 4 ++-- 16 files changed, 25 insertions(+), 25 deletions(-)
include/sound/soc.h +2 -2
@@ -529,8 +529,8 @@ struct snd_soc_codec_driver {int (*write)(struct snd_soc_codec *,unsigned int ,unsigned int );int (*display_register)(struct snd_soc_codec *,char *,size_t ,unsigned int ); -int (*volatile_register)(unsigned int ); -int (*readable_register)(unsigned int ); +int (*volatile_register)(struct snd_soc_codec *,unsigned int ); +int (*readable_register)(struct snd_soc_codec *,unsigned int );short reg_cache_size;short reg_cache_step;short reg_word_size;
sound/soc/codecs/cs4270.c +2 -2
@@ -193,12 +193,12 @@ static struct cs4270_mode_ratios cs4270_mode_ratios[] = {/* The number of MCLK/LRCK ratios supported by the CS4270 */ #define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios) -static int cs4270_reg_is_readable (unsigned int reg) +static int cs4270_reg_is_readable (struct snd_soc_codec *codec,unsigned int reg) {return (reg >=CS4270_FIRSTREG ) && (reg <=CS4270_LASTREG ); } -static int cs4270_reg_is_volatile (unsigned int reg) +static int cs4270_reg_is_volatile (struct snd_soc_codec *codec,unsigned int reg) {/* Unreadable registers are considered volatile */ if ((reg <CS4270_FIRSTREG ) || (reg >CS4270_LASTREG ))
sound/soc/codecs/max98088.c +1 -1
@@ -608,7 +608,7 @@ static struct { { 0xFF, 0x00, 1 }, /* FF */ }; -static int max98088_volatile_register (unsigned int reg) +static int max98088_volatile_register (struct snd_soc_codec *codec,unsigned int reg) {return max98088_access[reg].vol; }
sound/soc/codecs/wm8523.c +1 -1
@@ -58,7 +58,7 @@ static const u16 wm8523_reg[WM8523_REGISTER_COUNT] = { 0x0000, /* R8 - ZERO_DETECT */ }; -static int wm8523_volatile_register (unsigned int reg) +static int wm8523_volatile_register (struct snd_soc_codec *codec,unsigned int reg) {switch (reg) {case WM8523_DEVICE_ID :
sound/soc/codecs/wm8804.c +1 -1
@@ -175,7 +175,7 @@ static int txsrc_put(struct snd_kcontrol *kcontrol,return 0 ; } -static int wm8804_volatile (unsigned int reg) +static int wm8804_volatile (struct snd_soc_codec *codec,unsigned int reg) {switch (reg) {case WM8804_RST_DEVID1 :
sound/soc/codecs/wm8900.c +1 -1
@@ -180,7 +180,7 @@ static const u16 wm8900_reg_defaults[WM8900_MAXREG] = {/* Remaining registers all zero */ }; -static int wm8900_volatile_register (unsigned int reg) +static int wm8900_volatile_register (struct snd_soc_codec *codec,unsigned int reg) {switch (reg) {case WM8900_REG_ID :
sound/soc/codecs/wm8903.c +1 -1
@@ -232,7 +232,7 @@ struct wm8903_priv {int mic_delay; }; -static int wm8903_volatile_register (unsigned int reg) +static int wm8903_volatile_register (struct snd_soc_codec *codec,unsigned int reg) {switch (reg) {case WM8903_SW_RESET_AND_ID :
sound/soc/codecs/wm8904.c +1 -1
@@ -596,7 +596,7 @@ static struct { { 0x003F, 0x003F, 0 }, /* R248 - FLL NCO Test 1 */ }; -static int wm8904_volatile_register (unsigned int reg) +static int wm8904_volatile_register (struct snd_soc_codec *codec,unsigned int reg) {return wm8904_access[reg].vol; }
sound/soc/codecs/wm8961.c +1 -1
@@ -291,7 +291,7 @@ struct wm8961_priv {int sysclk; }; -static int wm8961_volatile_register (unsigned int reg) +static int wm8961_volatile_register (struct snd_soc_codec *codec,unsigned int reg) {switch (reg) {case WM8961_SOFTWARE_RESET :
sound/soc/codecs/wm8962.c +2 -2
@@ -1938,7 +1938,7 @@ static const struct wm8962_reg_access { [21139] = { 0xFFFF, 0xFFFF, 0x0000 }, /* R21139 - VSS_XTS32_0 */ }; -static int wm8962_volatile_register (unsigned int reg) +static int wm8962_volatile_register (struct snd_soc_codec *codec,unsigned int reg) {if (wm8962_reg_access[reg].vol)return 1 ;
@@ -1946,7 +1946,7 @@ static int wm8962_volatile_register(unsigned int reg)return 0 ; } -static int wm8962_readable_register (unsigned int reg) +static int wm8962_readable_register (struct snd_soc_codec *codec,unsigned int reg) {if (wm8962_reg_access[reg].read)return 1 ;
sound/soc/codecs/wm8993.c +1 -1
@@ -242,7 +242,7 @@ struct wm8993_priv {int fll_src; }; -static int wm8993_volatile (unsigned int reg) +static int wm8993_volatile (struct snd_soc_codec *codec,unsigned int reg) {switch (reg) {case WM8993_SOFTWARE_RESET :
sound/soc/codecs/wm8994.c +5 -5
@@ -109,7 +109,7 @@ struct wm8994_priv {struct wm8994_pdata *pdata; }; -static int wm8994_readable (unsigned int reg) +static int wm8994_readable (struct snd_soc_codec *codec,unsigned int reg) {switch (reg) {case WM8994_GPIO_1 :
@@ -136,7 +136,7 @@ static int wm8994_readable(unsigned int reg)return wm8994_access_masks[reg].readable !=0 ; } -static int wm8994_volatile (unsigned int reg) +static int wm8994_volatile (struct snd_soc_codec *codec,unsigned int reg) {if (reg >=WM8994_CACHE_SIZE )return 1 ;
@@ -164,7 +164,7 @@ static int wm8994_write(struct snd_soc_codec *codec, unsigned int reg,BUG_ON (reg >WM8994_MAX_REGISTER ); -if (!wm8994_volatile (reg)) { +if (!wm8994_volatile (codec, reg)) { ret =snd_soc_cache_write (codec, reg, value);if (ret !=0 ) dev_err(codec->dev, "Cache write to %x failed: %d\n",
@@ -182,7 +182,7 @@ static unsigned int wm8994_read(struct snd_soc_codec *codec,BUG_ON (reg >WM8994_MAX_REGISTER ); -if (!wm8994_volatile (reg) &&wm8994_readable (reg) && +if (!wm8994_volatile (codec, reg) &&wm8994_readable (codec, reg) && reg < codec->driver->reg_cache_size) { ret =snd_soc_cache_read (codec, reg, &val);if (ret >=0 )
@@ -2943,7 +2943,7 @@ static int wm8994_codec_probe(struct snd_soc_codec *codec)/* Read our current status back from the chip - we don't want to * reset as this may interfere with the GPIO or LDO operation. */ for (i =0 ; i <WM8994_CACHE_SIZE ; i++) { -if (!wm8994_readable (i) ||wm8994_volatile (i)) +if (!wm8994_readable (codec, i) ||wm8994_volatile (codec, i))continue ; ret =wm8994_reg_read (codec->control_data, i);
sound/soc/codecs/wm8995.c +1 -1
@@ -909,7 +909,7 @@ static const struct snd_soc_dapm_route wm8995_intercon[] = { { "SPK2R", NULL, "SPK2R Driver" } }; -static int wm8995_volatile (unsigned int reg) +static int wm8995_volatile (struct snd_soc_codec *codec,unsigned int reg) {/* out of bounds registers are generally considered * volatile to support register banks that are partially
sound/soc/codecs/wm9081.c +1 -1
@@ -169,7 +169,7 @@ struct wm9081_priv {struct wm9081_retune_mobile_config *retune; }; -static int wm9081_volatile_register (unsigned int reg) +static int wm9081_volatile_register (struct snd_soc_codec *codec,unsigned int reg) {switch (reg) {case WM9081_SOFTWARE_RESET :
sound/soc/codecs/wm9090.c +2 -2
@@ -144,7 +144,7 @@ struct wm9090_priv {void *control_data; }; -static int wm9090_volatile (unsigned int reg) +static int wm9090_volatile (struct snd_soc_codec *codec,unsigned int reg) {switch (reg) {case WM9090_SOFTWARE_RESET :
@@ -518,7 +518,7 @@ static int wm9090_set_bias_level(struct snd_soc_codec *codec,for (i =1 ; i < codec->driver->reg_cache_size; i++) {if (reg_cache[i] == wm9090_reg_defaults[i])continue ; -if (wm9090_volatile (i)) +if (wm9090_volatile (codec, i))continue ; ret =snd_soc_write (codec, i, reg_cache[i]);
sound/soc/soc-core.c +2 -2
@@ -84,7 +84,7 @@ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf) count +=sprintf (buf,"%s registers\n" , codec->name);for (i =0 ; i < codec->driver->reg_cache_size; i += step) { -if (codec->driver->readable_register && !codec->driver->readable_register (i)) +if (codec->driver->readable_register && !codec->driver->readable_register (codec, i))continue ; count +=sprintf (buf + count,"%2x: " , i);
@@ -2030,7 +2030,7 @@ static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)int snd_soc_codec_volatile_register (struct snd_soc_codec *codec,int reg) {if (codec->driver->volatile_register) -return codec->driver->volatile_register (reg); +return codec->driver->volatile_register (codec, reg);else return 0 ; }
Signature · 1 line
1.7.3.5
PATCH v2 3/3 ASoC: Automatically assign the default readable()/volatile() functions
In reply to Dimitris PapastamosEnsure that all calls to readable_register()/volatile_register() go via the snd_soc_codec function pointers.
If the default register access table has been given but no functions for handling readable()/volatile() registers, use the default ones provided by soc-cache.
--- include/sound/soc.h | 2 ++ sound/soc/soc-core.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-)
include/sound/soc.h +2 -0
@@ -480,6 +480,8 @@ struct snd_soc_codec {int num_dai;enum snd_soc_compress_type compress_type;size_t reg_size;/* reg_cache_size * reg_word_size */ +int (*volatile_register)(struct snd_soc_codec *,unsigned int ); +int (*readable_register)(struct snd_soc_codec *,unsigned int );/* runtime */ struct snd_ac97 *ac97;/* for ad-hoc ac97 devices */
sound/soc/soc-core.c +12 -3
@@ -84,7 +84,7 @@ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf) count +=sprintf (buf,"%s registers\n" , codec->name);for (i =0 ; i < codec->driver->reg_cache_size; i += step) { -if (codec->driver->readable_register && !codec->driver->readable_register (codec, i)) +if (codec->readable_register && !codec->readable_register (codec, i))continue ; count +=sprintf (buf + count,"%2x: " , i);
@@ -2029,8 +2029,8 @@ static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)*/ int snd_soc_codec_volatile_register (struct snd_soc_codec *codec,int reg) { -if (codec->driver->volatile_register) -return codec->driver->volatile_register (codec, reg); +if (codec->volatile_register) +return codec->volatile_register (codec, reg);else return 0 ; }
@@ -3489,6 +3489,8 @@ int snd_soc_register_codec(struct device *dev, codec->write = codec_drv->write; codec->read = codec_drv->read; + codec->volatile_register = codec_drv->volatile_register; + codec->readable_register = codec_drv->readable_register; codec->dapm.bias_level =SND_SOC_BIAS_OFF ; codec->dapm.dev = dev; codec->dapm.codec = codec;
@@ -3517,6 +3519,13 @@ int snd_soc_register_codec(struct device *dev, } } +if (codec_drv->reg_access_size && codec_drv->reg_access_default) { +if (!codec->volatile_register) + codec->volatile_register = snd_soc_default_volatile_register; +if (!codec->readable_register) + codec->readable_register = snd_soc_default_readable_register; + } +for (i =0 ; i < num_dai; i++) {fixup_codec_formats (&dai_drv[i].playback);fixup_codec_formats (&dai_drv[i].capture);
Signature · 1 line
1.7.3.5
Quoted 7 lines · Dimitris Papastamos
For common scenarios, device drivers can provide a table of all the registers that are at least either readable/writable/volatile. The idea is that if a register lookup fails, all of its read/write/vol members will be zero and will be treated as default. This also reduces the size of the register access array.
Signed-off-by Dimitris Papastamos <[email protected]>
I think we may be getting to the point where we should probably look into making this register cache functionality available to other non ASoC I2C and SPI based drivers.
Thanks
Liam
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
Mark Brown
AppliedQuoted 5 lines · Dimitris Papastamos
For common scenarios, device drivers can provide a table of all the registers that are at least either readable/writable/volatile. The idea is that if a register lookup fails, all of its read/write/vol members will be zero and will be treated as default. This also reduces the size of the register access array.
Applied all three, thanks.
Liam was just mentioning on IM that it might be worth looking at pulling the cache and I/O code out of ASoC for use by other I2C/SPI based subsystems. I'll take a look at that.