From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: <broonie@kernel.org>, <tiwai@suse.com>
Cc: <linux-sound@vger.kernel.org>, <alsa-devel@alsa-project.org>,
<linux-kernel@vger.kernel.org>, <patches@opensource.cirrus.com>,
"Richard Fitzgerald" <rf@opensource.cirrus.com>
Subject: [PATCH 7/9] ALSA: hda: hda_cs_dsp_ctl: Add helper function to write calibration
Date: Wed, 21 Feb 2024 15:05:05 +0000 [thread overview]
Message-ID: <20240221150507.1039979-8-rf@opensource.cirrus.com> (raw)
In-Reply-To: <20240221150507.1039979-1-rf@opensource.cirrus.com>
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@opensource.cirrus.com>
---
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@opensource.cirrus.com>");
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
next prev parent reply other threads:[~2024-02-21 15:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-21 15:04 [PATCH 0/9] ALSA: cs35l56: Apply calibration from EFI Richard Fitzgerald
2024-02-21 15:04 ` [PATCH 1/9] ASoC: wm_adsp: Fix missing mutex_lock in wm_adsp_write_ctl() Richard Fitzgerald
2024-02-21 15:05 ` [PATCH 2/9] ALSA: hda: hda_cs_dsp_ctl: Only call notify when a control has been added to a card Richard Fitzgerald
2024-02-21 15:05 ` [PATCH 3/9] ASoC: wm_adsp: Add wm_adsp_start() and wm_adsp_stop() Richard Fitzgerald
2024-02-21 15:05 ` [PATCH 4/9] ASoC: cs-amp-lib: Add helpers for factory calibration data Richard Fitzgerald
2024-02-21 15:05 ` [PATCH 5/9] ASoC: cs35l56: Add helper functions for amp calibration Richard Fitzgerald
2024-02-21 15:05 ` [PATCH 6/9] ASoC: cs35l56: Apply amp calibration from EFI data Richard Fitzgerald
2024-02-21 15:05 ` Richard Fitzgerald [this message]
2024-02-21 15:05 ` [PATCH 8/9] ALSA: hda: " Richard Fitzgerald
2024-02-21 15:05 ` [PATCH 9/9] ASoC: cs-amp-lib: Add KUnit test for calibration helpers Richard Fitzgerald
2024-02-27 3:14 ` kernel test robot
2024-02-22 9:03 ` [PATCH 0/9] ALSA: cs35l56: Apply calibration from EFI Takashi Iwai
2024-02-22 14:40 ` Richard Fitzgerald
2024-02-26 16:42 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240221150507.1039979-8-rf@opensource.cirrus.com \
--to=rf@opensource.cirrus.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox