[PATCH 7/9] ALSA: hda: hda_cs_dsp_ctl: Add helper function to write calibration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Add hda_cs_dsp_write_cal_coeffs(), a helper function to write amp
calibration data to firmware controls.

The calibration data is passed in a struct cirrus_amp_cal_data and
a definition of the firmware algorithm controls in a struct
cirrus_amp_cal_controls.

Signed-off-by: Richard Fitzgerald <rf@xxxxxxxxxxxxxxxxxxxxx>
---
 sound/pci/hda/hda_cs_dsp_ctl.c | 47 ++++++++++++++++++++++++++++++++++
 sound/pci/hda/hda_cs_dsp_ctl.h |  4 +++
 2 files changed, 51 insertions(+)

diff --git a/sound/pci/hda/hda_cs_dsp_ctl.c b/sound/pci/hda/hda_cs_dsp_ctl.c
index 0f5fdd44721c..bdc21a117dd2 100644
--- a/sound/pci/hda/hda_cs_dsp_ctl.c
+++ b/sound/pci/hda/hda_cs_dsp_ctl.c
@@ -10,6 +10,7 @@
 #include <sound/soc.h>
 #include <linux/firmware/cirrus/cs_dsp.h>
 #include <linux/firmware/cirrus/wmfw.h>
+#include <sound/cs-amp-lib.h>
 #include "hda_cs_dsp_ctl.h"
 
 #define ADSP_MAX_STD_CTRL_SIZE               512
@@ -247,6 +248,52 @@ int hda_cs_dsp_read_ctl(struct cs_dsp *dsp, const char *name, int type,
 }
 EXPORT_SYMBOL_NS_GPL(hda_cs_dsp_read_ctl, SND_HDA_CS_DSP_CONTROLS);
 
+static int hda_cs_dsp_write_cal_coeff(struct cs_dsp *cs_dsp,
+				      const struct cirrus_amp_cal_controls *controls,
+				      const char *ctl_name, unsigned int val)
+{
+	__be32 beval = cpu_to_be32(val);
+	int ret;
+
+	ret = hda_cs_dsp_write_ctl(cs_dsp, ctl_name, controls->mem_region,
+				   controls->alg_id, &beval, 4);
+	if (ret) {
+		dev_err(cs_dsp->dev, "Failed to write control %s: %d\n", ctl_name, ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+int hda_cs_dsp_write_cal_coeffs(struct cs_dsp *cs_dsp,
+				const struct cirrus_amp_cal_controls *controls,
+				const struct cirrus_amp_cal_data *data)
+{
+	int ret;
+
+	dev_dbg(cs_dsp->dev, "Calibration: Ambient=%#x, Status=%#x, R0=%d\n",
+		data->calAmbient, data->calStatus, data->calR);
+
+	ret = hda_cs_dsp_write_cal_coeff(cs_dsp, controls, controls->ambient, data->calAmbient);
+	if (ret)
+		return ret;
+
+	ret = hda_cs_dsp_write_cal_coeff(cs_dsp, controls, controls->calr, data->calR);
+	if (ret)
+		return ret;
+
+	ret = hda_cs_dsp_write_cal_coeff(cs_dsp, controls, controls->status, data->calStatus);
+	if (ret)
+		return ret;
+
+	ret = hda_cs_dsp_write_cal_coeff(cs_dsp, controls, controls->checksum, data->calR + 1);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(hda_cs_dsp_write_cal_coeffs, SND_HDA_CS_DSP_CONTROLS);
+
 MODULE_DESCRIPTION("CS_DSP ALSA Control HDA Library");
 MODULE_AUTHOR("Stefan Binding, <sbinding@xxxxxxxxxxxxxxxxxxxxx>");
 MODULE_LICENSE("GPL");
diff --git a/sound/pci/hda/hda_cs_dsp_ctl.h b/sound/pci/hda/hda_cs_dsp_ctl.h
index 2cf93359c4f2..329531672005 100644
--- a/sound/pci/hda/hda_cs_dsp_ctl.h
+++ b/sound/pci/hda/hda_cs_dsp_ctl.h
@@ -10,6 +10,7 @@
 #ifndef __HDA_CS_DSP_CTL_H__
 #define __HDA_CS_DSP_CTL_H__
 
+#include <sound/cs-amp-lib.h>
 #include <sound/soc.h>
 #include <linux/firmware/cirrus/cs_dsp.h>
 
@@ -35,5 +36,8 @@ 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);
+int hda_cs_dsp_write_cal_coeffs(struct cs_dsp *cs_dsp,
+				const struct cirrus_amp_cal_controls *controls,
+				const struct cirrus_amp_cal_data *data);
 
 #endif /*__HDA_CS_DSP_CTL_H__*/
-- 
2.30.2





[Index of Archives]     [Pulseaudio]     [Linux Audio Users]     [ALSA Devel]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux