ASoC: core: Add SND_SOC_BYTES control for coefficient blocks
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 10 Oct 2011 17:31:26 +0000 (18:31 +0100)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Tue, 21 Feb 2012 19:34:48 +0000 (19:34 +0000)
Allow devices to export blocks of registers to the application layer,
intended for use for reading and writing coefficient data which can't
usefully be worked with by the kernel at runtime (for example, due to
requiring complex and expensive calculations or being the results of
callibration procedures). Currently drivers are using platform data to
provide configurations for coefficient blocks which isn't at all
convenient for runtime management or configuration development.

Currently only devices using regmap are supported, an error will be
generated for any attempt to work with a byte control on a non-regmap
device. There's no fundamental block to other devices so support could
be added if required.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@ti.com>
include/sound/soc.h
sound/soc/soc-core.c

index 1e16d6e3f2a8c7211698b73a94b5b097df7ed44b..3e9cae001eab8aaadbe278a10b5a0024ea42a4ac 100644 (file)
                 .rreg = xreg_right, .shift = xshift, \
                 .min = xmin, .max = xmax} }
 
+#define SND_SOC_BYTES(xname, xbase, xregs)                   \
+{      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,   \
+       .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
+       .put = snd_soc_bytes_put, .private_value =            \
+               ((unsigned long)&(struct soc_bytes)           \
+               {.base = xbase, .num_regs = xregs }) }
 
 /*
  * Simplified versions of above macros, declaring a struct and calculating
@@ -413,6 +419,13 @@ int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol);
 int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol);
+int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
+                      struct snd_ctl_elem_info *uinfo);
+int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
+                     struct snd_ctl_elem_value *ucontrol);
+int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
+                     struct snd_ctl_elem_value *ucontrol);
+
 
 /**
  * struct snd_soc_reg_access - Describes whether a given register is
@@ -888,6 +901,11 @@ struct soc_mixer_control {
        unsigned int reg, rreg, shift, rshift, invert;
 };
 
+struct soc_bytes {
+       int base;
+       int num_regs;
+};
+
 /* enumerated kcontrol */
 struct soc_enum {
        unsigned short reg;
index 3ca70594e2423e2121160bf2f9fbb6b1b6432798..a9786ab705046a75023398aa6a03911bf1f94986 100644 (file)
@@ -2736,6 +2736,55 @@ int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
 }
 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
 
+int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
+                      struct snd_ctl_elem_info *uinfo)
+{
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       struct soc_bytes *params = (void *)kcontrol->private_value;
+
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
+       uinfo->count = params->num_regs * codec->val_bytes;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_bytes_info);
+
+int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
+                     struct snd_ctl_elem_value *ucontrol)
+{
+       struct soc_bytes *params = (void *)kcontrol->private_value;
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       int ret;
+
+       if (codec->using_regmap)
+               ret = regmap_raw_read(codec->control_data, params->base,
+                                     ucontrol->value.bytes.data,
+                                     params->num_regs * codec->val_bytes);
+       else
+               ret = -EINVAL;
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_bytes_get);
+
+int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
+                     struct snd_ctl_elem_value *ucontrol)
+{
+       struct soc_bytes *params = (void *)kcontrol->private_value;
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       int ret;
+
+       if (codec->using_regmap)
+               ret = regmap_raw_write(codec->control_data, params->base,
+                                      ucontrol->value.bytes.data,
+                                      params->num_regs * codec->val_bytes);
+       else
+               ret = -EINVAL;
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_bytes_put);
+
 /**
  * snd_soc_dai_set_sysclk - configure DAI system or master clock.
  * @dai: DAI