Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp188136iob; Wed, 11 May 2022 12:10:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwo5NP9W6gU9AkSRqJTaM7kVvJ7iyF7BA9ZX3D/QxI+FHZ8BQaN2xme57MxwWsM+QN/NHJZ X-Received: by 2002:a05:6402:289a:b0:425:d682:105d with SMTP id eg26-20020a056402289a00b00425d682105dmr31342779edb.175.1652296239672; Wed, 11 May 2022 12:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652296239; cv=none; d=google.com; s=arc-20160816; b=UMIwoy/KK/yhZev0eTEZ9TSsZe0rIEGQPsnL9le1vYkoXCzC9tkTR25DtElwQG/774 oMeE/5/HsMpiETglgeso3xRp1CWOAEPfGUoiCp4gTcTQFnokyMNwkUlv6cHGOOKlxzuY mAeinvYeO1m20ayqV3m4Awv6B+g17rSxTmDba+wVfLuYLzvV7J0SO3D+kcNRbxsVqCNJ +CH8Cjp/OVH4roq4bXP2DTfB2zILaasHUR0RFA8c+mOxp+iFZ6jNHqbM5F/5prU2t4P9 EPDWTe3sADAHvMn7G9MAVFbhPBg6l1v7B1K1azDHFfQIQitr3nv+ZVb7FuWb6d0JGr4V u/0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=vy1RHNn6+NEqxgAxPBD+llyUwtMO3GKyAbDkm5VBlZA=; b=XcovKt/+dkqvcniDLz1EULxhc7aidZ/TAKM5A+VJWisTFskRVM1jeBDOBB/3/hkPTn 34s6fHO4s5TqH7CtIklLdJPaprUGUCEd3UZLAjSzly2XMAtjHyHmt5kqQK2ihwDcet92 nQXRg7Yyz6SF1IzEgbPNvv1opG5AeS6hjkD0M+ha4LOFbXBobyPRhZ7U60sVBq3zwV6f owDtj51Vjv5NsE3r+CwboMUL2tPlg0xPpGoz2jqnKi8yTXCbCLrjjvrJjfPYrm27j/P1 4rNmPIf348R9noUKADupeZbfZ64qYlnEbN7k+1tfLIyPCKCCEoFOmmUI3Mr+Heyn166z 5Vmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=s7iigxFX; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 7-20020a508e07000000b00425b5cafe53si2985345edw.420.2022.05.11.12.10.13; Wed, 11 May 2022 12:10:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=s7iigxFX; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244322AbiEKN5a (ORCPT + 99 others); Wed, 11 May 2022 09:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244327AbiEKN51 (ORCPT ); Wed, 11 May 2022 09:57:27 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E114A4D629 for ; Wed, 11 May 2022 06:57:25 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 816D221A08; Wed, 11 May 2022 13:57:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1652277444; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vy1RHNn6+NEqxgAxPBD+llyUwtMO3GKyAbDkm5VBlZA=; b=s7iigxFXJvLdJfmOb+Lhbw1MqV2qnXaDz4Kl/qCoGsdhr4xz6ccPHhY0rMzRPl0uCosN4i IBdlHKYIlNnCLa1aevbmCgFjwDN6U7P9vXsYGlc0nRF0xPPXh1jGnri2GXzdgeMvLJZV1p CxS4flpSHvcKyROQ+Gz5l880JL2E1Os= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1652277444; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vy1RHNn6+NEqxgAxPBD+llyUwtMO3GKyAbDkm5VBlZA=; b=9HbknvhnXH10CDQ6pJ3RdMpD+I/u+AdrGTLADI5dHoHjB6BWl/TUi9acyTyQeAm5pXtkhg XKXIBcNTdELVeyAg== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 7185F2C141; Wed, 11 May 2022 13:57:24 +0000 (UTC) Date: Wed, 11 May 2022 15:57:24 +0200 Message-ID: From: Takashi Iwai To: Vitaly Rodionov Cc: Jaroslav Kysela , Takashi Iwai , Mark Brown , , , , Stefan Binding Subject: Re: [PATCH v2 22/26] ALSA: hda: cs35l41: Read Speaker Calibration data from UEFI variables In-Reply-To: <20220509214703.4482-23-vitalyr@opensource.cirrus.com> References: <20220509214703.4482-1-vitalyr@opensource.cirrus.com> <20220509214703.4482-23-vitalyr@opensource.cirrus.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 09 May 2022 23:46:59 +0200, Vitaly Rodionov wrote: > > From: Stefan Binding > > Speaker Calibration data, specific to an individual speaker is > stored inside UEFI variables during calibration, and can be > used by the DSP. Does this build without CONFIG_EFI? thanks, Takashi > Signed-off-by: Stefan Binding > Signed-off-by: Vitaly Rodionov > --- > sound/pci/hda/cs35l41_hda.c | 57 +++++++++++++++++++++++++++++++++++++ > sound/pci/hda/cs35l41_hda.h | 15 ++++++++++ > 2 files changed, 72 insertions(+) > > diff --git a/sound/pci/hda/cs35l41_hda.c b/sound/pci/hda/cs35l41_hda.c > index 9c622104bf01..7e87b355b369 100644 > --- a/sound/pci/hda/cs35l41_hda.c > +++ b/sound/pci/hda/cs35l41_hda.c > @@ -22,10 +22,18 @@ > #define CS35L41_FIRMWARE_ROOT "cirrus/" > #define CS35L41_PART "cs35l41" > #define FW_NAME "CSPL" > +#define CIRRUS_EFI_GUID \ > + EFI_GUID(0x02f9af02, 0x7734, 0x4233, 0xb4, 0x3d, 0x93, 0xfe, 0x5a, 0xa3, 0x5d, 0xb3) > > #define HALO_STATE_DSP_CTL_NAME "HALO_STATE" > #define HALO_STATE_DSP_CTL_TYPE 5 > #define HALO_STATE_DSP_CTL_ALG 262308 > +#define CAL_R_DSP_CTL_NAME "CAL_R" > +#define CAL_R_DSP_CTL_TYPE 5 > +#define CAL_R_DSP_CTL_ALG 205 > + > +static efi_char16_t efi_name[] = L"CirrusSmartAmpCalibrationData"; > +static efi_guid_t efi_guid = CIRRUS_EFI_GUID; > > static const struct reg_sequence cs35l41_hda_config[] = { > { CS35L41_PLL_CLK_CTRL, 0x00000430 }, // 3072000Hz, BCLK Input, PLL_REFCLK_EN = 1 > @@ -282,6 +290,50 @@ static int cs35l41_request_firmware_files(struct cs35l41_hda *cs35l41, > return ret; > } > > +static int cs35l41_apply_calibration(struct cs35l41_hda *cs35l41) > +{ > + const struct cs35l41_amp_efi_data *efi_data; > + const struct cs35l41_amp_cal_data *cl; > + unsigned long data_size = 0; > + efi_status_t status; > + int ret = 0; > + u8 *data = NULL; > + u32 attr; > + u32 r0; > + > + /* Get real size of UEFI variable */ > + status = efi.get_variable(efi_name, &efi_guid, &attr, &data_size, data); > + if (status == EFI_BUFFER_TOO_SMALL) { > + ret = -ENODEV; > + /* Allocate data buffer of data_size bytes */ > + data = vmalloc(data_size); > + if (!data) > + return -ENOMEM; > + /* Get variable contents into buffer */ > + status = efi.get_variable(efi_name, &efi_guid, &attr, &data_size, data); > + if (status == EFI_SUCCESS) { > + efi_data = (struct cs35l41_amp_efi_data *)data; > + dev_dbg(cs35l41->dev, "Calibration: Size=%d, Amp Count=%d\n", > + efi_data->size, efi_data->count); > + if (efi_data->count > cs35l41->index) { > + cl = &efi_data->data[cs35l41->index]; > + dev_dbg(cs35l41->dev, > + "Calibration: Ambient=%02x, Status=%02x, R0=%d\n", > + cl->calAmbient, cl->calStatus, cl->calR); > + r0 = cpu_to_be32(cl->calR); > + ret = hda_cs_dsp_write_ctl(&cs35l41->cs_dsp, CAL_R_DSP_CTL_NAME, > + CAL_R_DSP_CTL_TYPE, CAL_R_DSP_CTL_ALG, > + &r0, 4); > + if (ret) > + dev_err(cs35l41->dev, "Cannot Write Control: %s - %d\n", > + CAL_R_DSP_CTL_NAME, ret); > + } > + } > + vfree(data); > + } > + return ret; > +} > + > static int cs35l41_init_dsp(struct cs35l41_hda *cs35l41) > { > const struct firmware *coeff_firmware = NULL; > @@ -314,7 +366,12 @@ static int cs35l41_init_dsp(struct cs35l41_hda *cs35l41) > > ret = cs_dsp_power_up(dsp, wmfw_firmware, wmfw_filename, coeff_firmware, coeff_filename, > FW_NAME); > + if (ret) > + goto err_release; > + > + ret = cs35l41_apply_calibration(cs35l41); > > +err_release: > if (wmfw_firmware) > release_firmware(wmfw_firmware); > if (coeff_firmware) > diff --git a/sound/pci/hda/cs35l41_hda.h b/sound/pci/hda/cs35l41_hda.h > index 54521a013e78..3cf9871fbed2 100644 > --- a/sound/pci/hda/cs35l41_hda.h > +++ b/sound/pci/hda/cs35l41_hda.h > @@ -10,6 +10,7 @@ > #ifndef __CS35L41_HDA_H__ > #define __CS35L41_HDA_H__ > > +#include > #include > #include > #include > @@ -18,6 +19,20 @@ > #include > #include > > +struct cs35l41_amp_cal_data { > + u32 calTarget[2]; > + u32 calTime[2]; > + s8 calAmbient; > + u8 calStatus; > + u16 calR; > +} __packed; > + > +struct cs35l41_amp_efi_data { > + u32 size; > + u32 count; > + struct cs35l41_amp_cal_data data[]; > +} __packed; > + > enum cs35l41_hda_spk_pos { > CS35l41_LEFT, > CS35l41_RIGHT, > -- > 2.34.1 >