Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2415641rdb; Wed, 21 Feb 2024 07:06:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXSm41az6Bj+kwEk4QRq+SiTVZ52vac2YgDwwM0GrdhMFGyWb9kdEiEr3flCKLy4L0FZ1EYN9Vh4xxFnT6ALsja+eZHmQFm18juxFe9qg== X-Google-Smtp-Source: AGHT+IGQPCfJDT/lauLkOi8Qc0SF4KxbrtWkqVCVM+WOMzJbTtjjt8twDmghsnyK2h0cw7I6RsaT X-Received: by 2002:a05:620a:38f:b0:787:2372:475e with SMTP id q15-20020a05620a038f00b007872372475emr19603831qkm.24.1708527968665; Wed, 21 Feb 2024 07:06:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708527968; cv=pass; d=google.com; s=arc-20160816; b=Bv0cdawlrWH6hALFwnzADFJ4PDIv6F4WgX465tSzPrZkAJPAH1bG/F/uYpLpN3ZRD4 +eh/pA4g/RCtixNAa9RmuaSJ2FTLiM9EmQ1qUp5YdCi35L+8/4ww37UmzmZo4m6Hqcc3 M3QVMxU8+AT7f8YkE6UPV3yjysClY1Bcjqk2LUYzwRyYXVlgfa3SmlYc7aILYCNWe7Lg rQ5hDaU9ZQYxlEUnyw7QCcet+jrgrVVy5v2REJFSHboLfW76W/waFK6zicWEHpFAuFDj 9xP5d9kC2ADV37F7WDHCyb3G96uwAc+az54Bj6UcUIOvkEv0EQho2Ahe0+svGYCFbMSc FbPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=jxurZ9g8byiCpiiilA/KSypC/QlK/0d0/qRchJfkX/o=; fh=x7+OzJIeN5mJd4Ln+gczq2EazpTbLb1MfGhRMe/0Fjo=; b=xNI2xeI9UKuaH0ZF93IE5erEBq1kboq1Aqhx8ZR2YkKp4FJ02tniVXEYIIIJ6nhjGW ZKURsd8C3cE4NYmJmDthHu8Gqkh8UBc6e1NdVLVvF0ijFIRU0CPZfyRlc2nLSWaq53K3 UMClc6VCUd5dZ4D9/0r9exsdkCDQ+yKIKE27omQxyYdSts4ORg4k41emiQxUQsgJtz5s 22x2PfHIk6TV3cJZgf2JFaPgLepiEOblXB9NXaZNDliuTGQ6zQsE4avUO8VdZLokCfAh Erj4lKhQ3e9vDrYpQE7XSnlf/E6/tGPNCDCztXzPaldJBlOEveWrk0yrGFMi/cD6k+Ib zj0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=D6E2nmUs; arc=pass (i=1 spf=pass spfdomain=opensource.cirrus.com dkim=pass dkdomain=cirrus.com dmarc=pass fromdomain=opensource.cirrus.com); spf=pass (google.com: domain of linux-kernel+bounces-74961-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74961-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f18-20020a05620a15b200b00785955d82cfsi10763883qkk.343.2024.02.21.07.06.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:06:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74961-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=D6E2nmUs; arc=pass (i=1 spf=pass spfdomain=opensource.cirrus.com dkim=pass dkdomain=cirrus.com dmarc=pass fromdomain=opensource.cirrus.com); spf=pass (google.com: domain of linux-kernel+bounces-74961-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74961-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2D4D11C24030 for ; Wed, 21 Feb 2024 15:06:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2DA0980BF7; Wed, 21 Feb 2024 15:05:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="D6E2nmUs" Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A742880023; Wed, 21 Feb 2024 15:05:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.149.25 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708527928; cv=none; b=iGRk2FyFeRw4RU9iCPA3gbFjnOwDXidIoudjdbw7l7QTGJJ81MIWHbJOe2PQoXqQhaU9TJ3AEN6y4ctAlNeFTeQAAYuY1G1HwwKfDFt0WxDMBHKOZSs4pg74rqKUggSGpeMRZgKSW/Sf1E5aUULgxE+Z7CrrCSo73puSAMn01Zc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708527928; c=relaxed/simple; bh=uf6vpbcIoUtdbhnJ3basXbSQ/u2ojbk1oT1gnr/GaPg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jbmp2RCUU6XvxtwVmbkU4pqxVlxUfnSivfEsSkJZ3g+zN4a99VJHf50S+wcDin1bz6FlDsXrEe4nZUCYdz5NsPtyTSArrg/sbgZq2YDGGj7x/B4gHEfmoaRLQy+QSyy6U33txJRaJvZWweHUOU8E+iyZLkAMZRvmMStqNgomasI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com; spf=pass smtp.mailfrom=opensource.cirrus.com; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b=D6E2nmUs; arc=none smtp.client-ip=67.231.149.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=opensource.cirrus.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=opensource.cirrus.com Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41L72AP2020807; Wed, 21 Feb 2024 09:05:12 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= PODMain02222019; bh=jxurZ9g8byiCpiiilA/KSypC/QlK/0d0/qRchJfkX/o=; b= D6E2nmUsC1Dv7F3EMC4iI4D9UrsdLWIVk7rDEd4DH1psPQmOnSFmgjzW0ijNNxqH 47VzgMsIlooEwFJcGUimPMxbI46E+p/DDUvv/LWAabsc6IlnTzDcpeMR2HyI4aWt k7Oj9uFHBezZuVP+ID6WW2Ndve4MYak047jaMXWiK5seBVrydSCYjfYICtKMl92z Jb/mL/TayVb1dT9zhjKsXJhrZ3I1p9TcxVU487p3ao7nyQhuAasQItWFZIfocNmj SfDghvp3cJeRTDBdgkhGg58XSTiMYGlTHyR/orReDxz+51LtX/wDDqSIuRRxeOm9 fO8nc7r0HC6zydFWhUbBKA== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3wd207h58t-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Feb 2024 09:05:12 -0600 (CST) Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Wed, 21 Feb 2024 15:05:07 +0000 Received: from ediswmail9.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Wed, 21 Feb 2024 15:05:07 +0000 Received: from ediswws06.ad.cirrus.com (ediswws06.ad.cirrus.com [198.90.208.18]) by ediswmail9.ad.cirrus.com (Postfix) with ESMTP id 48CA8820259; Wed, 21 Feb 2024 15:05:07 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , , , "Richard Fitzgerald" 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 Message-ID: <20240221150507.1039979-8-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240221150507.1039979-1-rf@opensource.cirrus.com> References: <20240221150507.1039979-1-rf@opensource.cirrus.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: w0IK1iOTQqvTEzp0K88FP1p3gONu8Es5 X-Proofpoint-ORIG-GUID: w0IK1iOTQqvTEzp0K88FP1p3gONu8Es5 X-Proofpoint-Spam-Reason: safe 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 --- 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 #include #include +#include #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, "); 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 #include #include @@ -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