Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2423071rdb; Wed, 21 Feb 2024 07:16:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXK1N79euhA3eAb0eqeqHu2tQbFtEwQa6yCTeYSRcuOOF0bTQnWsp4qTVbCWxIJ1hbgtaorHffnh1RG87d7Bupn7OYEbK14gQRKQEKHfw== X-Google-Smtp-Source: AGHT+IGhimQEhyxgfb9mDWqUUyVhRMsiqRezC3enqEWxp8WaBFQj870cLqTY1N3zvOdPgCNkm2qg X-Received: by 2002:a17:902:ce92:b0:1db:f41a:3d9b with SMTP id f18-20020a170902ce9200b001dbf41a3d9bmr11953613plg.22.1708528614860; Wed, 21 Feb 2024 07:16:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708528614; cv=pass; d=google.com; s=arc-20160816; b=VkZK/bw5P0mQkf7Rglg9kmWju876qAWaOxGjOXP9Wyntvo3Ik7NN/UT3+gRh583bHY g6A5fMsyZ+49Zl4yrmx2n4NgHRBJzhN+HvwGR1dMk9OgYnBqD/8R3hkid9fQjZEOdmbp 2NEtfoijXtDvo302ZMYDV+YYmzmMI+OSSm0mothjMVd8wtOVqiBnz/J1YhNL+kmBp4HH zYTbRecNxR5CFdWYDVSpTwDlGq28LEHfQHtRcln1j12Wsibzlrl7MkostALIaI7dMLOM FNlx3cW6rD+1HHlZxax0JiOwJXVmplYC2M8PyQET/n4ny7zjxR8IWM3buGAhg29KJgrY 74EQ== 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=yytQ7GXTVFXWsBrfAM2U1tdjKyAr/L1PFu8PYDeSpuk=; fh=x7+OzJIeN5mJd4Ln+gczq2EazpTbLb1MfGhRMe/0Fjo=; b=B/KtRF2PYXAS0U0MBucsHAbUxx9OSCTUyb9KbiutqDXXnoffTT+1nrW7k06VeLUn38 DM9213JS2yXJyQGYY/ETEp7xLugyY0xO0melCr3muL+kHfoR3qraJCylsYMmOfhdJR7B AAW8qnDQ9CLRH3BSjBIDfDM6c59CHT4yYkHAP5Kcwg3xkPho7D1Is4JB/zpbjRR6LtWn JYOSinCg2wpWsK92LJfKMnM7frl4RozVkTwqlK8KHTgyuDQx19pRQfmCnvaZxfXAxTF3 wOmdby1KYJLpi8+3bdgbh9os3KBQd7y9EQigmd5PgiCWroFFYBKxvxeNn3dZ4SuHCj5c ix8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=qU7lSW0g; 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-74959-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74959-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jb18-20020a170903259200b001dba356b96fsi8145323plb.420.2024.02.21.07.16.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:16:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74959-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=qU7lSW0g; 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-74959-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74959-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 070AD288C1E for ; Wed, 21 Feb 2024 15:05:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ABBB980633; Wed, 21 Feb 2024 15:05:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="qU7lSW0g" Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) (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 D86F67FBCA; Wed, 21 Feb 2024 15:05:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.152.168 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708527927; cv=none; b=cSlk0xbCvpEdBGnOibuvgdC4uPbzvCjxvLa3PcslOXlxAFTcTrrObtIeF0uM1TNpBe0g/w0tfYiXZnTNpmDO8lbR9eI8Sqjxu2yYNp/NbpSPr4oajSaZXlG+LZMnsnhjim03NF1hYGG4MKG4I7djOz+PeNELetNsNant7bcullo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708527927; c=relaxed/simple; bh=ezwGTmb0p2OuSkCHLsCPYmiNs24E5alpl0HgPG9YWWg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZVYHoRj1G7pp7gBHlSlVsRcoogzFdtU9lIIJPP0bNnWxk4g3OdWA776FteJ1B9aytR6hiLFJwV3vhHCB71Fc42DI3/cv+PUaFk+zDNO7q9K+U6PAMzGyPennc4CIqrTtJNoLt62ZxeeSsbweIY0Nys9ELCKAqsqyEA5TVxs7Alo= 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=qU7lSW0g; arc=none smtp.client-ip=67.231.152.168 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 (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41LCUQsK011338; Wed, 21 Feb 2024 09:05:13 -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=yytQ7GXTVFXWsBrfAM2U1tdjKyAr/L1PFu8PYDeSpuk=; b= qU7lSW0gY1I9XSP5MP3iw5+29WbYShFT/gR0Jx2zLyIxmWG36I8qL712wxXZiOF6 sUD6aUFpMPAhdnlZCJi31w//3bdJmMTRSGQ1EAHok/Iff+q2H2PQhJA33ZMxy0w+ i9ImqbXMjySKc6bz0FM6tXXrqr00myOBs52ZAp51JgCQGKE43RjXGiHHqwRln2yM 8csjA+KKjJ824YrhbvrzyMH4ZOj/xqqjPxNWaiF0nrqVY/79rxkL4oHCcYLVYotY c6UnQo35vjJ+dmD1tTXipDmVxlccheF3ugp0dNzcLjLDbfU5a5qXQuc4l2GMb5ye DcMrzKK+FDaucnRG7V5n8g== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3wd205h4tk-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Feb 2024 09:05:13 -0600 (CST) Received: from ediex02.ad.cirrus.com (198.61.84.81) 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; Wed, 21 Feb 2024 15:05:07 +0000 Received: from ediswmail9.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server 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 4CC6482025A; Wed, 21 Feb 2024 15:05:07 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , , , "Richard Fitzgerald" Subject: [PATCH 8/9] ALSA: hda: cs35l56: Apply amp calibration from EFI data Date: Wed, 21 Feb 2024 15:05:06 +0000 Message-ID: <20240221150507.1039979-9-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-ORIG-GUID: k2y-l2KGer9iwDt8BYqoie2PBIRRsdIE X-Proofpoint-GUID: k2y-l2KGer9iwDt8BYqoie2PBIRRsdIE X-Proofpoint-Spam-Reason: safe If there are factory calibration settings in EFI, extract the settings and write them to the firmware calibration controls. Signed-off-by: Richard Fitzgerald --- sound/pci/hda/Kconfig | 2 ++ sound/pci/hda/cs35l56_hda.c | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig index 21a90b3c4cc7..6edfdaf98a74 100644 --- a/sound/pci/hda/Kconfig +++ b/sound/pci/hda/Kconfig @@ -162,6 +162,7 @@ config SND_HDA_SCODEC_CS35L56_I2C select SND_HDA_SCODEC_CS35L56 select SND_HDA_CIRRUS_SCODEC select SND_HDA_CS_DSP_CONTROLS + select SND_SOC_CS_AMP_LIB help Say Y or M here to include CS35L56 amplifier support with I2C control. @@ -177,6 +178,7 @@ config SND_HDA_SCODEC_CS35L56_SPI select SND_HDA_SCODEC_CS35L56 select SND_HDA_CIRRUS_SCODEC select SND_HDA_CS_DSP_CONTROLS + select SND_SOC_CS_AMP_LIB help Say Y or M here to include CS35L56 amplifier support with SPI control. diff --git a/sound/pci/hda/cs35l56_hda.c b/sound/pci/hda/cs35l56_hda.c index 75a14ba54fcd..47a225114f56 100644 --- a/sound/pci/hda/cs35l56_hda.c +++ b/sound/pci/hda/cs35l56_hda.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include "cirrus_scodec.h" @@ -547,6 +548,22 @@ static void cs35l56_hda_add_dsp_controls(struct cs35l56_hda *cs35l56) hda_cs_dsp_add_controls(&cs35l56->cs_dsp, &info); } +static void cs35l56_hda_apply_calibration(struct cs35l56_hda *cs35l56) +{ + int ret; + + if (!cs35l56->base.cal_data_valid || cs35l56->base.secured) + return; + + ret = hda_cs_dsp_write_cal_coeffs(&cs35l56->cs_dsp, + &cs35l56_calibration_controls, + &cs35l56->base.cal_data); + if (ret < 0) + dev_warn(cs35l56->base.dev, "Failed to write calibration: %d\n", ret); + else + dev_info(cs35l56->base.dev, "Calibration applied\n"); +} + static int cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56) { const struct firmware *coeff_firmware = NULL; @@ -618,12 +635,8 @@ static int cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56) if (coeff_filename) dev_dbg(cs35l56->base.dev, "Loaded Coefficients: %s\n", coeff_filename); - if (!firmware_missing) { - ret = cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_AUDIO_REINIT); - if (ret) - goto err_powered_up; - } else if (wmfw_firmware || coeff_firmware) { - /* If we downloaded firmware, reset the device and wait for it to boot */ + /* If we downloaded firmware, reset the device and wait for it to boot */ + if (firmware_missing && (wmfw_firmware || coeff_firmware)) { cs35l56_system_reset(&cs35l56->base, false); regcache_mark_dirty(cs35l56->base.regmap); ret = cs35l56_wait_for_firmware_boot(&cs35l56->base); @@ -646,6 +659,11 @@ static int cs35l56_hda_fw_load(struct cs35l56_hda *cs35l56) if (ret) dev_dbg(cs35l56->base.dev, "%s: cs_dsp_run ret %d\n", __func__, ret); + cs35l56_hda_apply_calibration(cs35l56); + ret = cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_AUDIO_REINIT); + if (ret) + cs_dsp_stop(&cs35l56->cs_dsp); + err_powered_up: if (!cs35l56->base.fw_patched) cs_dsp_power_down(&cs35l56->cs_dsp); @@ -953,6 +971,8 @@ int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int id) goto err; } + cs35l56->base.cal_index = cs35l56->index; + cs35l56_init_cs_dsp(&cs35l56->base, &cs35l56->cs_dsp); cs35l56->cs_dsp.client_ops = &cs35l56_hda_client_ops; @@ -990,6 +1010,10 @@ int cs35l56_hda_common_probe(struct cs35l56_hda *cs35l56, int id) if (ret) goto err; + ret = cs35l56_get_calibration(&cs35l56->base); + if (ret) + goto err; + ret = cs_dsp_halo_init(&cs35l56->cs_dsp); if (ret) { dev_err_probe(cs35l56->base.dev, ret, "cs_dsp_halo_init failed\n"); -- 2.30.2