ALSA: hda: hda_cs_dsp_ctl: Add apis to write the controls directly
authorStefan Binding <sbinding@opensource.cirrus.com>
Thu, 30 Jun 2022 00:23:23 +0000 (01:23 +0100)
committerTakashi Iwai <tiwai@suse.de>
Thu, 14 Jul 2022 09:22:39 +0000 (11:22 +0200)
DSP controls are exposed as ALSA controls, however,
some of these controls are required to be accessed by
the driver. Add apis which allow read/write of these
controls. The write api will also notify the ALSA control
on value change.

Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
Link: https://lore.kernel.org/r/20220630002335.366545-3-vitalyr@opensource.cirrus.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/hda/hda_cs_dsp_ctl.c
sound/pci/hda/hda_cs_dsp_ctl.h

index 74e2c5bd1b08a1962d32d95b1791ed75acf33be1..2351476c9ee6b24f2616fdbeea69598c92b35a2c 100644 (file)
@@ -188,6 +188,45 @@ void hda_cs_dsp_control_remove(struct cs_dsp_coeff_ctl *cs_ctl)
 }
 EXPORT_SYMBOL_NS_GPL(hda_cs_dsp_control_remove, SND_HDA_CS_DSP_CONTROLS);
 
+int hda_cs_dsp_write_ctl(struct cs_dsp *dsp, const char *name, int type,
+                        unsigned int alg, const void *buf, size_t len)
+{
+       struct cs_dsp_coeff_ctl *cs_ctl;
+       struct hda_cs_dsp_coeff_ctl *ctl;
+       int ret;
+
+       cs_ctl = cs_dsp_get_ctl(dsp, name, type, alg);
+       if (!cs_ctl)
+               return -EINVAL;
+
+       ctl = cs_ctl->priv;
+
+       ret = cs_dsp_coeff_write_ctrl(cs_ctl, 0, buf, len);
+       if (ret)
+               return ret;
+
+       if (cs_ctl->flags & WMFW_CTL_FLAG_SYS)
+               return 0;
+
+       snd_ctl_notify(ctl->card, SNDRV_CTL_EVENT_MASK_VALUE, &ctl->kctl->id);
+
+       return 0;
+}
+EXPORT_SYMBOL_NS_GPL(hda_cs_dsp_write_ctl, SND_HDA_CS_DSP_CONTROLS);
+
+int hda_cs_dsp_read_ctl(struct cs_dsp *dsp, const char *name, int type,
+                       unsigned int alg, void *buf, size_t len)
+{
+       struct cs_dsp_coeff_ctl *cs_ctl;
+
+       cs_ctl = cs_dsp_get_ctl(dsp, name, type, alg);
+       if (!cs_ctl)
+               return -EINVAL;
+
+       return cs_dsp_coeff_read_ctrl(cs_ctl, 0, buf, len);
+}
+EXPORT_SYMBOL_NS_GPL(hda_cs_dsp_read_ctl, SND_HDA_CS_DSP_CONTROLS);
+
 MODULE_DESCRIPTION("CS_DSP ALSA Control HDA Library");
 MODULE_AUTHOR("Stefan Binding, <sbinding@opensource.cirrus.com>");
 MODULE_LICENSE("GPL");
index 1c6d0fc9a2cc541b5f1e70fc24030200874567cf..c65bfd6878fde4c668103fcede15107557a81adf 100644 (file)
@@ -29,5 +29,9 @@ struct hda_cs_dsp_ctl_info {
 
 int hda_cs_dsp_control_add(struct cs_dsp_coeff_ctl *cs_ctl, struct hda_cs_dsp_ctl_info *info);
 void hda_cs_dsp_control_remove(struct cs_dsp_coeff_ctl *cs_ctl);
+int hda_cs_dsp_write_ctl(struct cs_dsp *dsp, const char *name, int type,
+                        unsigned int alg, const void *buf, size_t len);
+int hda_cs_dsp_read_ctl(struct cs_dsp *dsp, const char *name, int type,
+                       unsigned int alg, void *buf, size_t len);
 
 #endif /*__HDA_CS_DSP_CTL_H__*/