From patchwork Wed Feb 21 15:04:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 204256 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1095011dyc; Wed, 21 Feb 2024 07:07:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWL8z7WiUb2eHNR27EDq62oYlGuyV9I+wA+f2+66b2Z9ugDtGh3WrxjE446aklzZ9pPx3Rz46P8Nz8q5+yB5W0hh4sy6w== X-Google-Smtp-Source: AGHT+IEDpiFsHfk5adubg7W/edB+Sg4cFIjml1HWtiRmV6SapF9xGIC0KmCbJpCidOYqoA6P6bmP X-Received: by 2002:a05:6102:b16:b0:470:5e90:a45a with SMTP id b22-20020a0561020b1600b004705e90a45amr8073289vst.18.1708528035421; Wed, 21 Feb 2024 07:07:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708528035; cv=pass; d=google.com; s=arc-20160816; b=PvU977T1rr1oN16TPp06IxwlxjapzD4CAP6nvwooYniIEfcwykaykWY+Nqy50B1dVz 8hRe5I+fulVcgUp8rZua44hgeaFKL+X4WNnRGJcjTP8NTkvIx0vXi2aWYlPlIMfhTbSg 2OX7qvuwUsMiR7t26TlHCS830TNB/qQR6wkaYky0mGF7SHkME6AuUa14bSW7bnd4BaNk +Gbjm4YmsqNU5u7fB1PEK3Hb2tzpb7/MQcAfyUIvwVE2dIy7jPP/6yAMgM2afLjkdafw SUgyJabfrEQO02xgvatlLKlpDG178l8WbHJkC7uD/eukbsrdWGvaBEVkLb6aYFDNkNUn LB7w== 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=4PkYbCkiKIkB58Faq2G3nqngCiyJ4P2kQI5muB7wT6Q=; fh=x7+OzJIeN5mJd4Ln+gczq2EazpTbLb1MfGhRMe/0Fjo=; b=m5z9PHHVSGS220WjFj6K1FdbL5WLlmZ6M7WQmBNulnyA7MOLqbU36nVbGpt3ES6UaZ 71i2sAuzhbzw0CeblHAubqg+z3qhvR/t+M+UHLQKQK+m1Ks26PaAkSAZzWLeOb1Va7RP FKA5TsMJ927R63uox9JVe+IUU1aokEonrUFre0mlnQ9wD+iex7ZkyrCahPAVz3d8yKEq 3SbWGDiPTQVyMENR2l5Tkbngz7UHAtnDXZaYW3JO3AhKysE6r6wIMKSEq4XNML4bvkJh GSiu1qmva/77o5/cKHlkb+mGAGWoVZ/jHz5f2t/MA+GU3h0WVkF2ahCwFylEbot2ynV6 6/4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=Xa6Z0iZR; 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-74964-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74964-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c27-20020a0561023c9b00b004705f7fd901si988173vsv.679.2024.02.21.07.07.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:07:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74964-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=Xa6Z0iZR; 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-74964-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74964-ouuuleilei=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 B2D401C23926 for ; Wed, 21 Feb 2024 15:07:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8898681AC8; Wed, 21 Feb 2024 15:05:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="Xa6Z0iZR" 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 1162C80609; Wed, 21 Feb 2024 15:05:27 +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=1708527929; cv=none; b=IguRlApvFd7iaAwuURyhxT8J+SOqTTpLpo+yFjmhpySv2GgcAK6ErnLNXTbSd13mC+ctWuUPZB6+uwCigfXIe2VKh3IVNFFyrS5gZfoOUB1L5T7lw8Ac0e3XbNApH4NuPxAFkn88MsqZTjS4j1lHBwoyysgnTBGinjPrglLTsHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708527929; c=relaxed/simple; bh=w+dJPyOkY5qsuIzQgZfSwqb9xanTcEuadfMSXxqoeBM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jZPDKUnYOhR+UkA3g+ARaUf48FlSZduGBvgsYMJCMSElaOG/EEUF/HdJF5Tk4q62ZbK+o5x3vAjTCqa/NMq0dsKoVd5/C9kCqHN1fm5/aovK6fB+RX/0mrQnwQ8biF26sBN0y+37iVQ0rY8P3FrGdJucvNYwt4R3cJSuQudqJXw= 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=Xa6Z0iZR; 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 41L72AOx020807; Wed, 21 Feb 2024 09:05:10 -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=4PkYbCkiKIkB58Faq2G3nqngCiyJ4P2kQI5muB7wT6Q=; b= Xa6Z0iZR+77w3EQxC+7S5zndnTobyRZiyo+e5k8x1hUZN0LhlCITeHhOpWaAfDBs oQnO/HkXNVbLgLFqM9C+lKsYMYVZS5NY/4DVMjATfNKXRgInRvUOt5krwrczAFpu UwKImNX8guoDPICSlHB1ZiHrlf2m2/c/OKCaCpXPZnInJWmka/a6G+4PJaFnQOi2 fk7WBleRuL4tqlYKF9/PjoCpdDYRZ3rw6Sqv2LnvECuLHnkQADXYcggabQZvYpar HkFSQ724eFQp0uPUPXFX3keKIUhGGFEokjugFBinxt3DkuI9tzLszVan98Skex60 3uSsIg/lYSXIHq5aD+TyZA== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3wd207h58t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Feb 2024 09:05:09 -0600 (CST) Received: from ediex02.ad.cirrus.com (198.61.84.81) 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 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 1721E820248; Wed, 21 Feb 2024 15:05:07 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , , , "Richard Fitzgerald" Subject: [PATCH 1/9] ASoC: wm_adsp: Fix missing mutex_lock in wm_adsp_write_ctl() Date: Wed, 21 Feb 2024 15:04:59 +0000 Message-ID: <20240221150507.1039979-2-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 X-Proofpoint-GUID: uDnOhEGR_jtgGxSdppD9YoZ1qcO6fB7t X-Proofpoint-ORIG-GUID: uDnOhEGR_jtgGxSdppD9YoZ1qcO6fB7t X-Proofpoint-Spam-Reason: safe X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791521493527033982 X-GMAIL-MSGID: 1791521493527033982 wm_adsp_write_ctl() must hold the pwr_lock mutex when calling cs_dsp_get_ctl(). This was previously partially fixed by commit 781118bc2fc1 ("ASoC: wm_adsp: Fix missing locking in wm_adsp_[read|write]_ctl()") but this only put locking around the call to cs_dsp_coeff_write_ctrl(), missing the call to cs_dsp_get_ctl(). Signed-off-by: Richard Fitzgerald Fixes: 781118bc2fc1 ("ASoC: wm_adsp: Fix missing locking in wm_adsp_[read|write]_ctl()") --- sound/soc/codecs/wm_adsp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c index 36ea0dcdc7ab..9cb9068c0462 100644 --- a/sound/soc/codecs/wm_adsp.c +++ b/sound/soc/codecs/wm_adsp.c @@ -683,11 +683,12 @@ static void wm_adsp_control_remove(struct cs_dsp_coeff_ctl *cs_ctl) int wm_adsp_write_ctl(struct wm_adsp *dsp, const char *name, int type, unsigned int alg, void *buf, size_t len) { - struct cs_dsp_coeff_ctl *cs_ctl = cs_dsp_get_ctl(&dsp->cs_dsp, name, type, alg); + struct cs_dsp_coeff_ctl *cs_ctl; struct wm_coeff_ctl *ctl; int ret; mutex_lock(&dsp->cs_dsp.pwr_lock); + cs_ctl = cs_dsp_get_ctl(&dsp->cs_dsp, name, type, alg); ret = cs_dsp_coeff_write_ctrl(cs_ctl, 0, buf, len); mutex_unlock(&dsp->cs_dsp.pwr_lock); From patchwork Wed Feb 21 15:05:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 204265 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1101867dyc; Wed, 21 Feb 2024 07:17:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV0mD6zpjCfth1NVp1INMSaqzwEgdslccPlRhGfAD6F76c0Mw/OcJ9/FFpzizBD37VR9DdRXftWDbAhXEDpqda+eeqkRw== X-Google-Smtp-Source: AGHT+IG7AjBe092IiHIOaQ5aRTtWUE3qKLyu50tMC27ESUKmlSry+KkcKYYcoGq9fKHoRbG0aPMf X-Received: by 2002:a05:6358:470d:b0:178:75cb:18dc with SMTP id j13-20020a056358470d00b0017875cb18dcmr23176552rwn.10.1708528628180; Wed, 21 Feb 2024 07:17:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708528628; cv=pass; d=google.com; s=arc-20160816; b=c+hxbrzmrbj3vm7MW6NAy0pZG1g2IZOnb+6VZh94wn8JG0uQXq4ydlRRfZ+QJWPYos xqYMNqW9xDktuPcOdEmRVdDXDcO05Rs6I4HXTKgjMWCf/kJbzl/uWhEj23jeXHUGiupI 0xs9VEG/P7mtM+rp2P8TpcNXH4MrsqRAxq1yJn9U/a5PIfYKrKT9hXiHzl+a44r5r9Gx HAQTcfvb1PJw11fX+9odq9YHV4yTbofoMYUCaM63sGSnVUkP3eV1LGlo+OXKvQSvwKNx DfO53ZXS+hOTafFgTTqL4/vdxoZi+QiJ6B45oZWbblzEki0+7nCoshPJblHooRRFMzvc j9YQ== 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=GPX9S1rm9Vg8m5o14NSvRKfN2x1/7W0W6eYoN9/iRhQ=; fh=j1wfx+Y1gw6Ds+sNuwdsEMvQffxGHz9AhyK97x1PvPA=; b=CWywLcJPKOExDwXLFJI53IruNVwIsFd/C7xbNcQR63yGLK3J736FxmnyI8k+MpXrh+ 46VtHsCqy19UHs5WcFi/tyYicHnA1lIrmm2Lkyqjpz1srjcmYKx97Q1EY4jmcH/jn5rR 8rdNhtvWhmqIVGRF1+bhRX9ifwGBsXt24lwvzYoJjz2kefbNI47WyhgqFrPm5f4rvx4Z dyXr8LVj9pw33D7HDFkuLCDC6IIJKv4lpyNoz2lKBzTgL+WSALpra+rtvjZAhwpg7+6Q bgMWG9f1Ttj3k0p/m7tgcHC6o99dJuk+DoxD0ijunduXiOXS/0MZinO3tKLlb+4AOJF9 jsAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=mzO4ha5z; 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-74957-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74957-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s7-20020a635e07000000b005cd77a0fd8dsi8129495pgb.484.2024.02.21.07.17.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:17:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74957-ouuuleilei=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=mzO4ha5z; 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-74957-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74957-ouuuleilei=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 C2F7B288EE7 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 415A580BFD; 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="mzO4ha5z" 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 D952B7FBA9; Wed, 21 Feb 2024 15:05:24 +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=1708527926; cv=none; b=R5Aw0Ny+8aA/ynAyIYTI6TGIil6Kuk8huDSpeyHlOVSnWJwdhf1Kb9Cy2ZVH8yjBQrZdE21ngM2P8u7ORfFPO7LkybA5b5smRZRuuQIMCx1juDMpbJqYEiLCpYxk78luG1A91GhBj/MG4NJ2tkfhyh3/DG4VJ/J35DNDI+3LSAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708527926; c=relaxed/simple; bh=UyKUyA0qy67u/z9olIiAbwtiRO0bhToCby8jmDX8fYg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sTyO4i26kOG+o+qSWW782fhJ+V0hO9mmNnJUoKSqCPHBPWPa7c1/RH53U/sr9V1IgMw1aVRObWp4FWEoX/A5VOhDVmFYvKAMZI2A8aD/80lqTyR8MjXf8WAqf7ahujHat2vsZkzV7rgTWYNF4S6PEliYyl1bow2nC913QdpxVQs= 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=mzO4ha5z; 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 41LCUQsF011338; Wed, 21 Feb 2024 09:05:09 -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=GPX9S1rm9Vg8m5o14NSvRKfN2x1/7W0W6eYoN9/iRhQ=; b= mzO4ha5zy8nyIjrVN2bdR++IumITPnNQBE1Rnu3EWPYm4e2Iy8sKD53722eVlyVR CZWirtpVIqTH/GAsp35DtOPAhssdnG5gTzLXQDILZNOPQIZklk7fMMXytYm5eZDX Fn3Hftjs4a1RwPjmCyjbz+nKbvV0ZipvI1qDpfT3OHjAQTzj2SAw1NyPE/Ha5aCP e0StsRlVcPDXsQq0BR+vdqvpkLzrKy9U8vTkk25G4ygO30YJujQtvVPUwAIf55K1 yrhD3/4NcZZCtkR5BepZIyJSTm9RHHQkH/4ihWtQT2pzPduVWE4bguQ5xLarHwPo 8VPu8g8aTlwkHOmufmr5CQ== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3wd205h4tk-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Feb 2024 09:05:09 -0600 (CST) Received: from ediex01.ad.cirrus.com (198.61.84.80) 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 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 248E0820249; Wed, 21 Feb 2024 15:05:07 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , , , "Simon Trimmer" , Richard Fitzgerald Subject: [PATCH 2/9] ALSA: hda: hda_cs_dsp_ctl: Only call notify when a control has been added to a card Date: Wed, 21 Feb 2024 15:05:00 +0000 Message-ID: <20240221150507.1039979-3-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 X-Proofpoint-ORIG-GUID: dLqKW47PULXLedpvlwNu-fXJ16-lFzlY X-Proofpoint-GUID: dLqKW47PULXLedpvlwNu-fXJ16-lFzlY X-Proofpoint-Spam-Reason: safe X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791522114606707555 X-GMAIL-MSGID: 1791522114606707555 From: Simon Trimmer There is a window of time where the cs_dsp_coeff_ctl has been created but has not been registered as a control with ALSA. The hda_cs_dsp_write_ctl() helper function can be used update the cs_dsp coefficient before it has been registered, but it should only call snd_ctl_notify() once the control is associated with a card. Signed-off-by: Simon Trimmer Signed-off-by: Richard Fitzgerald Fixes: e414b05e724f ("ALSA: hda: hda_cs_dsp_ctl: Add apis to write the controls directly") --- sound/pci/hda/hda_cs_dsp_ctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/pci/hda/hda_cs_dsp_ctl.c b/sound/pci/hda/hda_cs_dsp_ctl.c index 463ca06036bf..0f5fdd44721c 100644 --- a/sound/pci/hda/hda_cs_dsp_ctl.c +++ b/sound/pci/hda/hda_cs_dsp_ctl.c @@ -224,9 +224,10 @@ int hda_cs_dsp_write_ctl(struct cs_dsp *dsp, const char *name, int type, if (ret == 0 || (cs_ctl->flags & WMFW_CTL_FLAG_SYS)) return 0; + /* Notify when a control has been added to a card */ ctl = cs_ctl->priv; - - snd_ctl_notify(ctl->card, SNDRV_CTL_EVENT_MASK_VALUE, &ctl->kctl->id); + if (ctl && ctl->kctl) + snd_ctl_notify(ctl->card, SNDRV_CTL_EVENT_MASK_VALUE, &ctl->kctl->id); return 0; } From patchwork Wed Feb 21 15:05:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 204263 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1100909dyc; Wed, 21 Feb 2024 07:15:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXOp1YGgigeff1SOTjFDZ1Skwrxd4oUNZpVCqq7tyrbpd8m6ICBMIMg1NG8gveLQXWkc0ahKn2/+leyjD7obCOo7Hed4A== X-Google-Smtp-Source: AGHT+IGug87oK/ch/jBDkn0vsvnoS/nBige3SODuu4m7n8i+TWaZTh7Wmk8uv1x3vR5M5J4VlrLn X-Received: by 2002:a05:6a00:3a83:b0:6e4:3e76:4af5 with SMTP id fk3-20020a056a003a8300b006e43e764af5mr9613484pfb.14.1708528543928; Wed, 21 Feb 2024 07:15:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708528543; cv=pass; d=google.com; s=arc-20160816; b=cVNHRaN2D1l8AO11b35VB40IohLu4tnL0qcLD2p5E4LlKbIR/1F6Tj9W98rqnQwnaa q4xXIVf4qdLbLfs5fjzHqyYmEQxs/FpybdqhpBrOdrUh0x1JTR8dD2JHmsPpgczJbMhP byaWdkAde8+z5xOc4Mca21lQDRRAIFqwhdxZ8Irs1aDgr/ic4rFNTd27rOM+WqzKn34Z Lv1X7DMre40kcnyhreEeNxUiXgjYlD6QGTJ+3P9C34U8JGhY5rM1r/mcC4hv/ROysSYU ERFhhlck0kYIMmzV7X1hgj7NTaVI+noumExDW6TNuurXmwb+LoX0ljPaw2r+ZxcypPxJ gG2A== 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=Sizjv7tpDmpvEHXjeISDmExQ5SKpIBfS9L7tW67IHs8=; fh=x7+OzJIeN5mJd4Ln+gczq2EazpTbLb1MfGhRMe/0Fjo=; b=wbufEE9M82WmJGvbVZw2GfZaK3x4zp7efNy0hGFu6Jb/TvR/D4Iq7Frj6fGZIrw4EE rDby0kHfixzkCmMG0LFRD1aHPY/SUlncP+x+sPtVTJRZZ1JJjYOt3tS0os8CfkBIWoye Ja+743WZAfbqoSM2bbLuNzeCwiUvduU8sI47bQ/QXap1+a0lMzrbD/t/e9nGSF0B7Vcz AxEqgW+mgL63HEjV7/MtTqbGw4kp7OwGNROZ5hy1Y6pyv/xKAc8+1cPCeUkCZFVLEiiZ jQVG3ARO9KD1sRD3r2rQtBEMAbL+qgiUp8mSg+NJqTdOiqqifBfiphEotfV15lQDeEwx Ut4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=GSqanBK3; 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-74962-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74962-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q21-20020a638c55000000b005d8b313de26si8072270pgn.594.2024.02.21.07.15.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:15:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74962-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=GSqanBK3; 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-74962-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74962-ouuuleilei=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 9FB1728A0A9 for ; Wed, 21 Feb 2024 15:07:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B844881ACE; Wed, 21 Feb 2024 15:05:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="GSqanBK3" 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 D95617FBB8; Wed, 21 Feb 2024 15:05:24 +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=1708527928; cv=none; b=dn2jiTIQ/1A0dGgdmo9wWmTwO3e++aA8sQqmRHV+FCgnvqYkLyvQCr0x3XPAmRo0vt+JTWx0fmRS3lHVU4P89TITFZvxHiV47Sms23FXpEmtdpZGBSXlu9IIvY2ju8ljfVhGC8Q6f7l5tKO6eKn7KlBbM6Xj7Zlt/KD/08uJBag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708527928; c=relaxed/simple; bh=jX810ij3p5ZFO4Igvf8q484HyyCU9Cos8rBPENBPp+4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JiskZs5XqsNjyYM5At5UQRd/S1Toy536U8cMpvVaNzhom/coy21KbzQGpxMstdSKzD0Eu2J01blKFHd2KlBjMRsHo+pxVzZSGUBHzejAbuSOZY43yG6e59HO9LrliSxJosN587mKijIYnJ9Ad0MoeZvNzvAVxR1TWAo8Iykj0Ho= 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=GSqanBK3; 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 41LCUQsG011338; Wed, 21 Feb 2024 09:05:10 -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=Sizjv7tpDmpvEHXjeISDmExQ5SKpIBfS9L7tW67IHs8=; b= GSqanBK3XFM46jFVrQKOnA27EkzaGeaCbHONVMxsr0xGG1QT2dUIbxQx3vCF70Zh ZZO9UdxNmy30d9SVtVDhyFPC0qvvquMzK7TWlQE8IWt47UyUH+eVwYCmHDuDo/HH hS6N9OlezWCqCNd9lvVV/kLCoJDXyPAvxCauAF3x+jcpK0bCcWJh18AVwEC5zxxg Xv9vNlqsfTtFrDWiZbsfRzRqC8vpPRQzwLxJDCXKaj4BdnbGvhRMMYqeS9XPdRuo 8R0PkT11UqKtlFygQ5hhJcUm4QZeLL5PRR8jQC8IM7UdIW1S/Glhg+ZfeoOV47Ju dWOsgjTgpi2tLX0CH/pY6w== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3wd205h4tk-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Feb 2024 09:05:10 -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 3230D82024A; Wed, 21 Feb 2024 15:05:07 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , , , "Richard Fitzgerald" Subject: [PATCH 3/9] ASoC: wm_adsp: Add wm_adsp_start() and wm_adsp_stop() Date: Wed, 21 Feb 2024 15:05:01 +0000 Message-ID: <20240221150507.1039979-4-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 X-Proofpoint-ORIG-GUID: SyrTgmLshJ9gIovvuGWFUVv3XdsHlgf_ X-Proofpoint-GUID: SyrTgmLshJ9gIovvuGWFUVv3XdsHlgf_ X-Proofpoint-Spam-Reason: safe X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791522026543857410 X-GMAIL-MSGID: 1791522026543857410 Separate the functionality of wm_adsp_event() into two exported functions wm_adsp_start() and wm_adsp_stop(). This allows the codec driver to start and stop the DSP outside of a DAPM widget. Signed-off-by: Richard Fitzgerald --- sound/soc/codecs/wm_adsp.c | 27 ++++++++++++++++++--------- sound/soc/codecs/wm_adsp.h | 2 ++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c index 9cb9068c0462..7d5c096e06cd 100644 --- a/sound/soc/codecs/wm_adsp.c +++ b/sound/soc/codecs/wm_adsp.c @@ -1093,27 +1093,36 @@ static void wm_adsp_event_post_stop(struct cs_dsp *cs_dsp) dsp->fatal_error = false; } +int wm_adsp_run(struct wm_adsp *dsp) +{ + flush_work(&dsp->boot_work); + + return cs_dsp_run(&dsp->cs_dsp); +} +EXPORT_SYMBOL_GPL(wm_adsp_run); + +void wm_adsp_stop(struct wm_adsp *dsp) +{ + cs_dsp_stop(&dsp->cs_dsp); +} +EXPORT_SYMBOL_GPL(wm_adsp_stop); + int wm_adsp_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event) { struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); struct wm_adsp *dsps = snd_soc_component_get_drvdata(component); struct wm_adsp *dsp = &dsps[w->shift]; - int ret = 0; switch (event) { case SND_SOC_DAPM_POST_PMU: - flush_work(&dsp->boot_work); - ret = cs_dsp_run(&dsp->cs_dsp); - break; + return wm_adsp_run(dsp); case SND_SOC_DAPM_PRE_PMD: - cs_dsp_stop(&dsp->cs_dsp); - break; + wm_adsp_stop(dsp); + return 0; default: - break; + return 0; } - - return ret; } EXPORT_SYMBOL_GPL(wm_adsp_event); diff --git a/sound/soc/codecs/wm_adsp.h b/sound/soc/codecs/wm_adsp.h index 067d807a7ca8..e53dfcf1f78f 100644 --- a/sound/soc/codecs/wm_adsp.h +++ b/sound/soc/codecs/wm_adsp.h @@ -98,6 +98,8 @@ irqreturn_t wm_adsp2_bus_error(int irq, void *data); irqreturn_t wm_halo_bus_error(int irq, void *data); irqreturn_t wm_halo_wdt_expire(int irq, void *data); +int wm_adsp_run(struct wm_adsp *dsp); +void wm_adsp_stop(struct wm_adsp *dsp); int wm_adsp_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event); From patchwork Wed Feb 21 15:05:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 204269 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1109009dyc; Wed, 21 Feb 2024 07:28:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVw+4jaI5bPtzsY1uqnqKxQiANWr2ogPhLIDLVJL2tYqEZ9wQF8o5FspdefvPUAYmTLX5YA06ptXou0Cu93xeKFf8Xgqg== X-Google-Smtp-Source: AGHT+IHf6ZrGe3dTe4heiN5tFnrufhR1ClDvIyvWHKFXYb0qmQR7/ZfoapHDVdJP4K+Sl4v1PhRa X-Received: by 2002:a05:6a20:ce47:b0:19e:b95f:123c with SMTP id id7-20020a056a20ce4700b0019eb95f123cmr21333842pzb.49.1708529330571; Wed, 21 Feb 2024 07:28:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708529330; cv=pass; d=google.com; s=arc-20160816; b=ENZ/olL95hfFQsJvEIqHiU+QBw/z05xySO3Ijs0TwH+5/uxrG8bFT060lSC+l4W9Go t9G3Vxz1++Yd1VxNLGWP33ACzzURLWJEhXgjuLDstpJm1R7JQG+LmHmIzrD/b/HY4swr mW/EysuUMjmb9IlbIfAzydaLd5vazlpbi1p1o3noVQUvFum3OxPZLx4jZdt+5RlohmOx /3HumD+Zc/YfycN5kgjPv7FgFh/+kNnh12bUdXia5pTHkCzf1phTnu5794SSKjNDcwta u2qe1HwyNvw41kk6eWuiIX0dblIRXKQO2Ws679rTvJJ9pjiStupHOC7bZU696GU7cXJc YEKg== 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=Uo+dEY+Nyt9VJFpgVFoLbOjBVkQZDZkESRiC9k7HK5U=; fh=x7+OzJIeN5mJd4Ln+gczq2EazpTbLb1MfGhRMe/0Fjo=; b=GpEkZODWJZCmbTA69ztD0LSRYy9PGR1c8mTD3WJbnWSXxRmGdTdFAhEmRH7I0qk+t3 0zoz3qmYnZ1ddtCdi9J2pI9mYxP4JIpV6cozalvA1LpTDlFws/Ez9TA+2kx2xKfRvOJI ttHkAidB9GQ/jZfmha3aXoofQ7aYERJeEqIOarImgYEB0EMcn2ncewyDMzJwul78/uQq HC5OeoBQSudZbijiVC68z287UJ9yzmOXq9LqXjOguUn94KR8IkZzRl7/5d9J3RW16PY6 uSVBcK3S07pFa9F+X7ZuPkEqUN7MxQ0bBlDc1rsUg0gNLb/Umt64Bx3Sk64ekp6Bo2lK ZjIw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=lpr7cSiy; 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-74960-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74960-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id t4-20020a62d144000000b006e39f3c2c59si7145888pfl.21.2024.02.21.07.28.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:28:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74960-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=lpr7cSiy; 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-74960-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74960-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id BBBB0B23759 for ; Wed, 21 Feb 2024 15:07:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E28F181AD4; Wed, 21 Feb 2024 15:05:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="lpr7cSiy" 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 D86757FBBC; 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=jYQmqW0nATMzOPdScOAzm2T4BngJiviKRxpI8kgRcNliqnHfCtZeSW/ffnhP0qwGYDXSKdGBPdWUlduSSeyiAl5wMWi4d4DKQm+m2nqrJ9J11hn/l+m00VN82aG0dH0+rxu1W6+EwFssdVo5mIJRnkLOsAEE8wy4UKrnMWHbdvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708527927; c=relaxed/simple; bh=P1BHzkuWSjIzuWkSow29+n9tVFKJ7V5CgSlp5Ealq+0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Kn0/xri7VzFLYuPVKO1BBAUSO9CAUFhudSK2H+YsvefFy/uypzGa3CQtnASkySqVjOZd7j1Djr1GDstnibsW1iXRvMv7Rhzx2ODT5cTVt3q/syjSgXAhdzJqBuFKUwECXX0xlf6Fdh2+57ghpvHwO3vJ5Nc0K0vrTY5IsvBzY8I= 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=lpr7cSiy; 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 41LCUQsI011338; Wed, 21 Feb 2024 09:05:11 -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=Uo+dEY+Nyt9VJFpgVFoLbOjBVkQZDZkESRiC9k7HK5U=; b= lpr7cSiyf9qq8IGE8XXUFAo4hOjjBUrjrjC75FjgpoKMCiypLzb4pNOyF1IlZkkE xwc6O1ZORc7cnGuqyvubOn849f0Je2cmiOESURql9mNCCVYy6RTVpQSM+7I8PlL7 4YsL44ZSQBWvgEERIBgLAwqtv1hsYi0w1zNDLknM7aXedNpBVu0U/jiHev9HHZRD dBm/pg40ZzOIY8AVi4/YBl2PDAGD5bv4DhvNTq+OEI0sA/F5fF995fZgD2r/OeMj NPhWRilCIz3WB9jvBab8qgPZsGZCxj6imyi3xLh9IYAZBLxH7q29EgUuTM2xS4SO WYb888e7TIVixGkdlwcvhg== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3wd205h4tk-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Feb 2024 09:05:11 -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 3EC9582024B; Wed, 21 Feb 2024 15:05:07 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , , , "Richard Fitzgerald" Subject: [PATCH 4/9] ASoC: cs-amp-lib: Add helpers for factory calibration data Date: Wed, 21 Feb 2024 15:05:02 +0000 Message-ID: <20240221150507.1039979-5-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 X-Proofpoint-ORIG-GUID: oR4SXLnghigTqPRSKywwA1Fde1o-e8iq X-Proofpoint-GUID: oR4SXLnghigTqPRSKywwA1Fde1o-e8iq X-Proofpoint-Spam-Reason: safe X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791522851127836313 X-GMAIL-MSGID: 1791522851127836313 Create a new library for code that is used by multiple Cirrus Logic amps. This initially implements extracting amp calibration data from EFI and writing it to firmware controls. During factory calibration of built-in speakers the firmware calibration constants are stored in an EFI file. The file contains an array of calibration constants for each of the speakers. cs_amp_get_calibration_data() searches for an entry matching the requested UID stamp, otherwise by array index. If the data is found in EFI the constants for that speaker are copied back to the caller. If EFI is not enabled, the cs_amp_get_calibration_data() implementation will compile to simply return -ENOENT and the linker can drop the code. The code to write calibration controls uses wm_adsp. Not all drivers use wm_adsp (notably, HDA drivers do not) so cs-amp-lib does not force building of wm_adsp. Instead, the code will compile away the call to wm_adsp_write_ctl() if wm_adsp is not reachable. This strategy of conditional code allows cs-amp-lib to be shared by multiple drivers without forcing inclusion of other modules that might be unnecessary. The calls to efi.get_variable() and wm_adsp_write_ctl() are in small wrapper functions. This is so that a KUNIT_STATIC_STUB_REDIRECT can be added in a future patch to redirect these calls to replacement functions for KUnit testing. Signed-off-by: Richard Fitzgerald --- include/sound/cs-amp-lib.h | 52 +++++++ sound/soc/codecs/Kconfig | 3 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/cs-amp-lib.c | 256 ++++++++++++++++++++++++++++++++++ 4 files changed, 313 insertions(+) create mode 100644 include/sound/cs-amp-lib.h create mode 100644 sound/soc/codecs/cs-amp-lib.c diff --git a/include/sound/cs-amp-lib.h b/include/sound/cs-amp-lib.h new file mode 100644 index 000000000000..35f7bd848276 --- /dev/null +++ b/include/sound/cs-amp-lib.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024 Cirrus Logic, Inc. and + * Cirrus Logic International Semiconductor Ltd. + */ + +#ifndef CS_AMP_LIB_H +#define CS_AMP_LIB_H + +#include +#include + +struct wm_adsp; + +struct cirrus_amp_cal_data { + u32 calTarget[2]; + u32 calTime[2]; + s8 calAmbient; + u8 calStatus; + u16 calR; +} __packed; + +struct cirrus_amp_efi_data { + u32 size; + u32 count; + struct cirrus_amp_cal_data data[]; +} __packed; + +/** + * struct cirrus_amp_cal_controls - definition of firmware calibration controls + * @alg_id: ID of algorithm containing the controls. + * @mem_region: DSP memory region containing the controls. + * @ambient: Name of control for calAmbient value. + * @calr: Name of control for calR value. + * @status: Name of control for calStatus value. + * @checksum: Name of control for checksum value. + */ +struct cirrus_amp_cal_controls { + unsigned int alg_id; + int mem_region; + const char *ambient; + const char *calr; + const char *status; + const char *checksum; +}; + +int cs_amp_write_cal_coeffs(struct wm_adsp *dsp, + const struct cirrus_amp_cal_controls *controls, + const struct cirrus_amp_cal_data *data); +int cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index, + struct cirrus_amp_cal_data *out_data); +#endif /* CS_AMP_LIB_H */ diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 027d9da85251..8356bd1256d8 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -729,6 +729,9 @@ config SND_SOC_CROS_EC_CODEC If you say yes here you will get support for the ChromeOS Embedded Controller's Audio Codec. +config SND_SOC_CS_AMP_LIB + tristate + config SND_SOC_CS35L32 tristate "Cirrus Logic CS35L32 CODEC" depends on I2C diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 4080646b2dd6..0fc40640e5d0 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -59,6 +59,7 @@ snd-soc-chv3-codec-objs := chv3-codec.o snd-soc-cpcap-objs := cpcap.o snd-soc-cq93vc-objs := cq93vc.o snd-soc-cros-ec-codec-objs := cros_ec_codec.o +snd-soc-cs-amp-lib-objs := cs-amp-lib.o snd-soc-cs35l32-objs := cs35l32.o snd-soc-cs35l33-objs := cs35l33.o snd-soc-cs35l34-objs := cs35l34.o @@ -452,6 +453,7 @@ obj-$(CONFIG_SND_SOC_CHV3_CODEC) += snd-soc-chv3-codec.o obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o obj-$(CONFIG_SND_SOC_CPCAP) += snd-soc-cpcap.o obj-$(CONFIG_SND_SOC_CROS_EC_CODEC) += snd-soc-cros-ec-codec.o +obj-$(CONFIG_SND_SOC_CS_AMP_LIB) += snd-soc-cs-amp-lib.o obj-$(CONFIG_SND_SOC_CS35L32) += snd-soc-cs35l32.o obj-$(CONFIG_SND_SOC_CS35L33) += snd-soc-cs35l33.o obj-$(CONFIG_SND_SOC_CS35L34) += snd-soc-cs35l34.o diff --git a/sound/soc/codecs/cs-amp-lib.c b/sound/soc/codecs/cs-amp-lib.c new file mode 100644 index 000000000000..0e1249342a78 --- /dev/null +++ b/sound/soc/codecs/cs-amp-lib.c @@ -0,0 +1,256 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// Common code for Cirrus Logic Smart Amplifiers +// +// Copyright (C) 2024 Cirrus Logic, Inc. and +// Cirrus Logic International Semiconductor Ltd. + +#include +#include +#include +#include +#include +#include +#include +#include "wm_adsp.h" + +#define CS_AMP_CAL_GUID \ + EFI_GUID(0x02f9af02, 0x7734, 0x4233, 0xb4, 0x3d, 0x93, 0xfe, 0x5a, 0xa3, 0x5d, 0xb3) + +#define CS_AMP_CAL_NAME L"CirrusSmartAmpCalibrationData" + +static int cs_amp_write_cal_coeff(struct wm_adsp *dsp, + const struct cirrus_amp_cal_controls *controls, + const char *ctl_name, u32 val) +{ + __be32 beval = cpu_to_be32(val); + int ret; + + if (IS_REACHABLE(CONFIG_SND_SOC_WM_ADSP)) { + ret = wm_adsp_write_ctl(dsp, ctl_name, controls->mem_region, + controls->alg_id, &beval, sizeof(beval)); + if (ret) + dev_err(dsp->cs_dsp.dev, "Failed to write to '%s': %d\n", ctl_name, ret); + + return ret; + } + + return -ENODEV; +} + +static int _cs_amp_write_cal_coeffs(struct wm_adsp *dsp, + const struct cirrus_amp_cal_controls *controls, + const struct cirrus_amp_cal_data *data) +{ + int ret; + + dev_dbg(dsp->cs_dsp.dev, "Calibration: Ambient=%#x, Status=%#x, CalR=%d\n", + data->calAmbient, data->calStatus, data->calR); + + ret = cs_amp_write_cal_coeff(dsp, controls, controls->ambient, data->calAmbient); + if (ret) + return ret; + + ret = cs_amp_write_cal_coeff(dsp, controls, controls->calr, data->calR); + if (ret) + return ret; + + ret = cs_amp_write_cal_coeff(dsp, controls, controls->status, data->calStatus); + if (ret) + return ret; + + ret = cs_amp_write_cal_coeff(dsp, controls, controls->checksum, data->calR + 1); + if (ret) + return ret; + + return 0; +} + +/** + * cs_amp_write_cal_coeffs - Write calibration data to firmware controls. + * @dsp: Pointer to struct wm_adsp. + * @controls: Pointer to definition of firmware controls to be written. + * @data: Pointer to calibration data. + * + * Returns: 0 on success, else negative error value. + */ +int cs_amp_write_cal_coeffs(struct wm_adsp *dsp, + const struct cirrus_amp_cal_controls *controls, + const struct cirrus_amp_cal_data *data) +{ + if (IS_REACHABLE(CONFIG_SND_SOC_WM_ADSP)) + return _cs_amp_write_cal_coeffs(dsp, controls, data); + else + return -ENODEV; +} +EXPORT_SYMBOL_NS_GPL(cs_amp_write_cal_coeffs, SND_SOC_CS_AMP_LIB); + +static efi_status_t cs_amp_get_efi_variable(efi_char16_t *name, + efi_guid_t *guid, + unsigned long *size, + void *buf) +{ + u32 attr; + + if (IS_ENABLED(CONFIG_EFI)) + return efi.get_variable(name, guid, &attr, size, buf); + + return EFI_NOT_FOUND; +} + +static struct cirrus_amp_efi_data *cs_amp_get_cal_efi_buffer(struct device *dev) +{ + struct cirrus_amp_efi_data *efi_data; + unsigned long data_size = 0; + u8 *data; + efi_status_t status; + int ret; + + /* Get real size of UEFI variable */ + status = cs_amp_get_efi_variable(CS_AMP_CAL_NAME, &CS_AMP_CAL_GUID, &data_size, NULL); + if (status != EFI_BUFFER_TOO_SMALL) + return ERR_PTR(-ENOENT); + + if (data_size < sizeof(*efi_data)) { + dev_err(dev, "EFI cal variable truncated\n"); + return ERR_PTR(-EOVERFLOW); + } + + /* Get variable contents into buffer */ + data = kmalloc(data_size, GFP_KERNEL); + if (!data) + return ERR_PTR(-ENOMEM); + + status = cs_amp_get_efi_variable(CS_AMP_CAL_NAME, &CS_AMP_CAL_GUID, &data_size, data); + if (status != EFI_SUCCESS) { + ret = efi_status_to_err(status); + goto err; + } + + efi_data = (struct cirrus_amp_efi_data *)data; + dev_dbg(dev, "Calibration: Size=%d, Amp Count=%d\n", efi_data->size, efi_data->count); + + if ((efi_data->count > 128) || + offsetof(struct cirrus_amp_efi_data, data[efi_data->count]) > data_size) { + dev_err(dev, "EFI cal variable truncated\n"); + ret = -EOVERFLOW; + goto err; + } + + return efi_data; + +err: + kfree(data); + dev_err(dev, "Failed to read calibration data from EFI: %d\n", ret); + + return ERR_PTR(ret); +} + +static u64 cs_amp_cal_target_u64(const struct cirrus_amp_cal_data *data) +{ + return ((u64)data->calTarget[1] << 32) | data->calTarget[0]; +} + +static int _cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index, + struct cirrus_amp_cal_data *out_data) +{ + struct cirrus_amp_efi_data *efi_data; + struct cirrus_amp_cal_data *cal = NULL; + int i, ret; + + efi_data = cs_amp_get_cal_efi_buffer(dev); + if (IS_ERR(efi_data)) + return PTR_ERR(efi_data); + + if (target_uid) { + for (i = 0; i < efi_data->count; ++i) { + u64 cal_target = cs_amp_cal_target_u64(&efi_data->data[i]); + + /* Skip entries with unpopulated silicon ID */ + if (cal_target == 0) + continue; + + if (cal_target == target_uid) { + cal = &efi_data->data[i]; + break; + } + } + } + + if (!cal && (amp_index >= 0) && (amp_index < efi_data->count)) { + u64 cal_target = cs_amp_cal_target_u64(&efi_data->data[amp_index]); + + /* + * Treat unpopulated cal_target as a wildcard. + * If target_uid != 0 we can only get here if cal_target == 0 + * or it didn't match any cal_target value. + * If target_uid == 0 it is a wildcard. + */ + if ((cal_target == 0) || (target_uid == 0)) + cal = &efi_data->data[amp_index]; + else + dev_warn(dev, "Calibration entry %d does not match silicon ID", amp_index); + } + + if (cal) { + memcpy(out_data, cal, sizeof(*out_data)); + ret = 0; + } else { + dev_warn(dev, "No calibration for silicon ID %#llx\n", target_uid); + ret = -ENOENT; + } + + kfree(efi_data); + + return ret; +} + +/** + * cs_amp_get_efi_calibration_data - get an entry from calibration data in EFI. + * @dev: struct device of the caller. + * @target_uid: UID to match, or zero to ignore UID matching. + * @amp_index: Entry index to use, or -1 to prevent lookup by index. + * @out_data: struct cirrus_amp_cal_data where the entry will be copied. + * + * This function can perform 3 types of lookup: + * + * (target_uid > 0, amp_index >= 0) + * UID search with fallback to using the array index. + * Search the calibration data for a non-zero calTarget that matches + * target_uid, and if found return that entry. Else, if the entry at + * [amp_index] has calTarget == 0, return that entry. Else fail. + * + * (target_uid > 0, amp_index < 0) + * UID search only. + * Search the calibration data for a non-zero calTarget that matches + * target_uid, and if found return that entry. Else fail. + * + * (target_uid == 0, amp_index >= 0) + * Array index fetch only. + * Return the entry at [amp_index]. + * + * An array lookup will be skipped if amp_index exceeds the number of + * entries in the calibration array, and in this case the return will + * be -ENOENT. An out-of-range amp_index does not prevent matching by + * target_uid - it has the same effect as passing amp_index < 0. + * + * If the EFI data is too short to be a valid entry, or the entry count + * in the EFI data overflows the actual length of the data, this function + * returns -EOVERFLOW. + * + * Return: 0 if the entry was found, -ENOENT if no entry was found, + * -EOVERFLOW if the EFI file is corrupt, else other error value. + */ +int cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index, + struct cirrus_amp_cal_data *out_data) +{ + if (IS_ENABLED(CONFIG_EFI)) + return _cs_amp_get_efi_calibration_data(dev, target_uid, amp_index, out_data); + else + return -ENOENT; +} +EXPORT_SYMBOL_NS_GPL(cs_amp_get_efi_calibration_data, SND_SOC_CS_AMP_LIB); + +MODULE_DESCRIPTION("Cirrus Logic amplifier library"); +MODULE_AUTHOR("Richard Fitzgerald "); +MODULE_LICENSE("GPL"); From patchwork Wed Feb 21 15:05:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 204264 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1101226dyc; Wed, 21 Feb 2024 07:16:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWWnOIC4XTHbmuvvTqLDMgqqTY2aGC3EISMcM9egR5s/WP3AzUdJo/4KN/Bqqh3eojXUc6fIjE0FvjYt93zS+6JqvuVtQ== X-Google-Smtp-Source: AGHT+IGom14FHnx0gIAizZ1saICkq3AX5gk2beLXIEozc1u022vrR5GQMSp8SEnO8S6tbnUJZn6z X-Received: by 2002:a6b:7407:0:b0:7c7:6cd2:a8a3 with SMTP id s7-20020a6b7407000000b007c76cd2a8a3mr3956219iog.16.1708528569270; Wed, 21 Feb 2024 07:16:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708528569; cv=pass; d=google.com; s=arc-20160816; b=Xs3tNrGPuzFVs5wTpTYYDu5cYJdl/d+gBoMYXT4cJ2RYJrTc+wnRLZsGexszR0oPTJ RJBB4TO0e/vUrevGB6BpUshpLYnDdH52HencPKsKHnFECrdAaVrRX93hBb5ddUhqM0s2 mhBXfsi7eL8I6zO5DTeNUFu4xDaYZd/LzrQbjVLQUay/fhY+wHkaI6rG9n9mTBsuwnW5 hNlKyOKyjfhbGrnLa43QI55BD75/uROFrcgOAVpw1ZGIpOs1oZeRSANH77SiEzhrjLyh UdMMMyYhZrTtS9vhV30uXZVXIcjuhGw3QWdoBS+FSQT/iiy0kqwBi0cbbJboaEKBoy2J plAA== 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=vizjXmHcd079C2mw5k4d+8ZahdNc9pZNwCbEzx/xBg8=; fh=x7+OzJIeN5mJd4Ln+gczq2EazpTbLb1MfGhRMe/0Fjo=; b=TpbWqEtlQjUsgYLFCuuJNKaBvq+IvrGcLFdi3jjuu22iE1qx10FQ7pq3MtAduxXf09 LkF4y0oBT1dHDDtHbVD/akp6K2b/Lr0cIH262Srq8uykPESxxgdPMGtBaAKCkndpJxQj 56EV2lcGPv0sNmezOtCrBWL0MYBe1eUBKhpGGqfqT36yCzbV+rBLr3B1WU9A8B6Uu+mo n/0XZpv8sIvB4dMeTWcRyCZdPb0I3Ox+02h6VXz6syJxfoaHj4dbTHUq0Yh4p+SUhu5C egSEA721pZQmjVsP5uMQb5xZHmzid5Suq+bqwnNuMYZejAYVRO2Ls3S4aSct7QeRiU4k B82w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=UyWy+uP+; 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-74963-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74963-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id t29-20020a63b25d000000b005dc8914839bsi8362693pgo.5.2024.02.21.07.16.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:16:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74963-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=UyWy+uP+; 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-74963-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74963-ouuuleilei=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 EF3DE28A0DF for ; Wed, 21 Feb 2024 15:07:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A5AD4823A6; Wed, 21 Feb 2024 15:05:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="UyWy+uP+" 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 8EF078004B; Wed, 21 Feb 2024 15:05:27 +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=1708527929; cv=none; b=rGmejX6RE4CuSpEDGptTmfMm2WJhdrPlB1DKDg2Jz/8wBFjhA/bPcVgxsJ/yD8QNcClDgqEL/yAH/gxQTShTVL4czmwrzNDzSm+1pxhmKWXSqNJsbAhyrF0QnemdcZ46mvTspHYy2Q8SMef2TfHLEwP+4rHSbN+c4foWyuTnAJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708527929; c=relaxed/simple; bh=AyhWYPSqg+SbEKRLSFfHUk7zH/sfDacTTWQa5bUQwDU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=igMkFu+t6r0tOa9P81CfW9lEBTgdAcVntcIA7NKc0p37fu9FNfoKsrj4/l6RnA+oOB8rYzogq5u0e8hLWv12vMr8d5x7uudPJObHaD73Z9fftdQA/JgBZ0uU0ZnJeG5aZaJAoJZlmfOCeEx/oXkEpRxGdCskDQodY7Y7ho5jHak= 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=UyWy+uP+; 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 41L72AP0020807; Wed, 21 Feb 2024 09:05:11 -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=vizjXmHcd079C2mw5k4d+8ZahdNc9pZNwCbEzx/xBg8=; b= UyWy+uP+qvW1bTEoeu6Ydy4TrL1ELOz14mwwLxJnLDos68Zhtj9wdmylJ+bPXmva /PFRuGWK82rQ0AG2yeAAAK4fQNzOVnuBOkysEz1yKgH5NTeStKnjyPhxGBPWoauV wHdm0MH6Z5fZShAyX2+7z6vZY/YzxWJPDVbUUrbDKWCqfAiomXfm9ZrVQ2D2YaMj M/z1kn199IIL07J8en9aqP817g29B85DZhMfSdp+2/JeELEGvPCfA0enAsaq0guT r/SYquNqjdGbCRZJmXnCZLWCV/HLW7XVQJafbNsPQpqYoUYPU8ntS8TRtffIS6zS Fz4uNspRr5zgnjjcCaXmfQ== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3wd207h58t-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Feb 2024 09:05:10 -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 420EF820257; Wed, 21 Feb 2024 15:05:07 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , , , "Richard Fitzgerald" Subject: [PATCH 5/9] ASoC: cs35l56: Add helper functions for amp calibration Date: Wed, 21 Feb 2024 15:05:03 +0000 Message-ID: <20240221150507.1039979-6-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 X-Proofpoint-GUID: 7o-TXZ2GxFoqRXENefoL9zMQhlvjcma3 X-Proofpoint-ORIG-GUID: 7o-TXZ2GxFoqRXENefoL9zMQhlvjcma3 X-Proofpoint-Spam-Reason: safe X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791522052861339578 X-GMAIL-MSGID: 1791522052861339578 Adds some helper functions and data for applying amp calibration. 1. cs35l56_read_silicon_uid() to get the silicon ID that is used to search for the correct calibration data entry. 2. Add the registers for the silicon ID to the readable registers. 3. cs35l56_get_calibration() wrapper around cs_amp_get_efi_calibration_data() 4. cs35l56_calibration_controls() table of the firmware controls for calibration data. 5. Added members to struct cs35l56_base to store the calibration data. Signed-off-by: Richard Fitzgerald --- include/sound/cs35l56.h | 10 ++++ sound/soc/codecs/Kconfig | 1 + sound/soc/codecs/cs35l56-shared.c | 83 +++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) diff --git a/include/sound/cs35l56.h b/include/sound/cs35l56.h index b24716ab2750..4014ed7097b3 100644 --- a/include/sound/cs35l56.h +++ b/include/sound/cs35l56.h @@ -12,6 +12,7 @@ #include #include #include +#include #define CS35L56_DEVID 0x0000000 #define CS35L56_REVID 0x0000004 @@ -23,6 +24,9 @@ #define CS35L56_BLOCK_ENABLES2 0x000201C #define CS35L56_REFCLK_INPUT 0x0002C04 #define CS35L56_GLOBAL_SAMPLE_RATE 0x0002C0C +#define CS35L56_OTP_MEM_53 0x00300D4 +#define CS35L56_OTP_MEM_54 0x00300D8 +#define CS35L56_OTP_MEM_55 0x00300DC #define CS35L56_ASP1_ENABLES1 0x0004800 #define CS35L56_ASP1_CONTROL1 0x0004804 #define CS35L56_ASP1_CONTROL2 0x0004808 @@ -262,6 +266,9 @@ struct cs35l56_base { bool fw_patched; bool secured; bool can_hibernate; + bool cal_data_valid; + s8 cal_index; + struct cirrus_amp_cal_data cal_data; struct gpio_desc *reset_gpio; }; @@ -269,6 +276,8 @@ extern struct regmap_config cs35l56_regmap_i2c; extern struct regmap_config cs35l56_regmap_spi; extern struct regmap_config cs35l56_regmap_sdw; +extern const struct cirrus_amp_cal_controls cs35l56_calibration_controls; + extern const char * const cs35l56_tx_input_texts[CS35L56_NUM_INPUT_SRC]; extern const unsigned int cs35l56_tx_input_values[CS35L56_NUM_INPUT_SRC]; @@ -286,6 +295,7 @@ int cs35l56_is_fw_reload_needed(struct cs35l56_base *cs35l56_base); int cs35l56_runtime_suspend_common(struct cs35l56_base *cs35l56_base); int cs35l56_runtime_resume_common(struct cs35l56_base *cs35l56_base, bool is_soundwire); void cs35l56_init_cs_dsp(struct cs35l56_base *cs35l56_base, struct cs_dsp *cs_dsp); +int cs35l56_get_calibration(struct cs35l56_base *cs35l56_base); int cs35l56_read_prot_status(struct cs35l56_base *cs35l56_base, bool *fw_missing, unsigned int *fw_version); int cs35l56_hw_init(struct cs35l56_base *cs35l56_base); diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 8356bd1256d8..15f287784d8b 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -800,6 +800,7 @@ config SND_SOC_CS35L56 tristate config SND_SOC_CS35L56_SHARED + select SND_SOC_CS_AMP_LIB tristate config SND_SOC_CS35L56_I2C diff --git a/sound/soc/codecs/cs35l56-shared.c b/sound/soc/codecs/cs35l56-shared.c index cb4e83126b08..20b6dbd3fbab 100644 --- a/sound/soc/codecs/cs35l56-shared.c +++ b/sound/soc/codecs/cs35l56-shared.c @@ -5,10 +5,12 @@ // Copyright (C) 2023 Cirrus Logic, Inc. and // Cirrus Logic International Semiconductor Ltd. +#include #include #include #include #include +#include #include "cs35l56.h" @@ -36,6 +38,8 @@ int cs35l56_set_patch(struct cs35l56_base *cs35l56_base) EXPORT_SYMBOL_NS_GPL(cs35l56_set_patch, SND_SOC_CS35L56_SHARED); static const struct reg_default cs35l56_reg_defaults[] = { + /* no defaults for OTP_MEM - first read populates cache */ + { CS35L56_ASP1_ENABLES1, 0x00000000 }, { CS35L56_ASP1_CONTROL1, 0x00000028 }, { CS35L56_ASP1_CONTROL2, 0x18180200 }, @@ -91,6 +95,9 @@ static bool cs35l56_readable_reg(struct device *dev, unsigned int reg) case CS35L56_BLOCK_ENABLES2: case CS35L56_REFCLK_INPUT: case CS35L56_GLOBAL_SAMPLE_RATE: + case CS35L56_OTP_MEM_53: + case CS35L56_OTP_MEM_54: + case CS35L56_OTP_MEM_55: case CS35L56_ASP1_ENABLES1: case CS35L56_ASP1_CONTROL1: case CS35L56_ASP1_CONTROL2: @@ -629,6 +636,81 @@ void cs35l56_init_cs_dsp(struct cs35l56_base *cs35l56_base, struct cs_dsp *cs_ds } EXPORT_SYMBOL_NS_GPL(cs35l56_init_cs_dsp, SND_SOC_CS35L56_SHARED); +struct cs35l56_pte { + u8 x; + u8 wafer_id; + u8 pte[2]; + u8 lot[3]; + u8 y; + u8 unused[3]; + u8 dvs; +} __packed; +static_assert((sizeof(struct cs35l56_pte) % sizeof(u32)) == 0); + +static int cs35l56_read_silicon_uid(struct cs35l56_base *cs35l56_base, u64 *uid) +{ + struct cs35l56_pte pte; + u64 unique_id; + int ret; + + ret = regmap_raw_read(cs35l56_base->regmap, CS35L56_OTP_MEM_53, &pte, sizeof(pte)); + if (ret) { + dev_err(cs35l56_base->dev, "Failed to read OTP: %d\n", ret); + return ret; + } + + unique_id = pte.lot[2] | (pte.lot[1] << 8) | (pte.lot[0] << 16); + unique_id <<= 32; + unique_id |= pte.x | (pte.y << 8) | (pte.wafer_id << 16) | (pte.dvs << 24); + + dev_dbg(cs35l56_base->dev, "UniqueID = %#llx\n", unique_id); + + *uid = unique_id; + + return 0; +} + +/* Firmware calibration controls */ +const struct cirrus_amp_cal_controls cs35l56_calibration_controls = { + .alg_id = 0x9f210, + .mem_region = WMFW_ADSP2_YM, + .ambient = "CAL_AMBIENT", + .calr = "CAL_R", + .status = "CAL_STATUS", + .checksum = "CAL_CHECKSUM", +}; +EXPORT_SYMBOL_NS_GPL(cs35l56_calibration_controls, SND_SOC_CS35L56_SHARED); + +int cs35l56_get_calibration(struct cs35l56_base *cs35l56_base) +{ + u64 silicon_uid; + int ret; + + /* Driver can't apply calibration to a secured part, so skip */ + if (cs35l56_base->secured) + return 0; + + ret = cs35l56_read_silicon_uid(cs35l56_base, &silicon_uid); + if (ret < 0) + return ret; + + ret = cs_amp_get_efi_calibration_data(cs35l56_base->dev, silicon_uid, + cs35l56_base->cal_index, + &cs35l56_base->cal_data); + + /* Only return an error status if probe should be aborted */ + if ((ret == -ENOENT) || (ret == -EOVERFLOW)) + return 0; + + if (ret < 0) + return ret; + + cs35l56_base->cal_data_valid = true; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cs35l56_get_calibration, SND_SOC_CS35L56_SHARED); + int cs35l56_read_prot_status(struct cs35l56_base *cs35l56_base, bool *fw_missing, unsigned int *fw_version) { @@ -923,3 +1005,4 @@ MODULE_DESCRIPTION("ASoC CS35L56 Shared"); MODULE_AUTHOR("Richard Fitzgerald "); MODULE_AUTHOR("Simon Trimmer "); MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS(SND_SOC_CS_AMP_LIB); From patchwork Wed Feb 21 15:05:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 204254 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1094711dyc; Wed, 21 Feb 2024 07:06:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXKCbT5x6eWyzVyLAYguNblU4THN+Q5rws4hxzdxKI8zMLY0rClEJJbSyPaopbk93+BTzgwRiNUFiOHBG0E1QhWBvZnxw== X-Google-Smtp-Source: AGHT+IGF2t0pz+ZS3PqxxCew/RIQbnN/NYiVh2CaLRuZNEbgm2vwbfeExYZoMLkROhscxqq3xods X-Received: by 2002:a17:906:e2d9:b0:a3f:6326:723d with SMTP id gr25-20020a170906e2d900b00a3f6326723dmr385138ejb.73.1708528015200; Wed, 21 Feb 2024 07:06:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708528015; cv=pass; d=google.com; s=arc-20160816; b=mQ541ENY23MPB49fzy+7+me5g0FMXQKuHydZyG4kfAlWi+x0S/7Fuv9cS1B+XCqZ5V Rp6U6SboK3JAUlbne+Z7CV5tZPCtIyskznvokKY4jYE73kuqP1OImxGTe1UYpX9dhCDd A51kpgUdeLhik/6ogQHIvC+RlM9jy0Dj1CZp509a3wKeLQh7M8G4nqRE1ojn3pHIFnLj NcBBJfkuqLd/fdrpZE6mwhVrI8pPmDdGTfLlzv+N/qcTgab9btpYm0b0us4/RqjMgpVc 8uoYDT3JY96fL+2LlApxt0cCu6oRw7kZkzt6u0sgEe6WoK/XjCEnjgmKUrsNk0GFWOo7 70+A== 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=hfJuyJkb/UeH7E/1q9QsoAdADQ7qN6nCp5C5HIbEbi0=; fh=x7+OzJIeN5mJd4Ln+gczq2EazpTbLb1MfGhRMe/0Fjo=; b=RFtKa3wOSqB+3wHV+0nyLrYtqMyCyzi7hYoApSBqWIU+KcdZeHQS98Ze8MFUVhKPWa Qe4rHZ4PWzhYJvkukBGKoGharancTmzOr91QhGVHfVJfxq3e5o3TDtA30477c/nnX4yZ rt6wqTYsO96ZMBiAoMjk0swAxLQsgPL3IyAu9nIUvtcfwIJsWOaLwZ59TeoQ5a5l2Lxe c77xaJgDskU8L05lnh0buv/pkZoiOD+aupDixWCkErR7mYKIyx4d27QHjlJNj/xa4z/I WLgv0bFj+oox0Sl+TZJALrDuRlwTr7T9ZRRAq4z7xutn1NvxED9fzHRpRUAMeCA4AN1d tHtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=cyQt60MP; 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-74958-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74958-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h14-20020a170906718e00b00a3f335c3878si791463ejk.884.2024.02.21.07.06.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:06:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74958-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=cyQt60MP; 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-74958-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74958-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 759FF1F24C76 for ; Wed, 21 Feb 2024 15:06:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F225F81734; Wed, 21 Feb 2024 15:05:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="cyQt60MP" 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 D86BD7FBC8; 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=sy3nLoMKmv3FnOmT2FNJYGYeSRynxXLm2S5Hw/Lusl2IliBxasvtjkJKhZdEPn57BjLFK/yshCJgT9bmt0m55F592ybjZUCss59TIEXgBguI3ElrffzgPbqAmR6++Vpgxb0kUdO+eDcCcTF2KhbkjhcP881v1DElBTCjRNVijQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708527927; c=relaxed/simple; bh=u8i+ZnlB55tkVJL4SKf/DyIo9KYqNTXHQ9mCewQrFTA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oIwDmOHbRHkIkTEyT9O6R9T4QtO74/+3y7PgTLt8VXVbCM9NxitNeUubK20w1onP9aaD9zR5QvYeTOtTnHkClzk1WubhPIvJZQPHlFxjue4jdxsKgc0wnwOWGrYgJCwOur08ocE+eet/KkvgO9m+vMIrSceLWexhE1w0KZ4OfM8= 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=cyQt60MP; 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 41LCUQsJ011338; 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=hfJuyJkb/UeH7E/1q9QsoAdADQ7qN6nCp5C5HIbEbi0=; b= cyQt60MPolxCa0Xnl9zeUX/+5rkIhEp2JpUq4x6bgDTbx/u+I392COU0wPh+Xuox QJDmMGZVO5QkFibyL69MMJENpwREyWKuS2Dvdk4xRiEOb33izezOo3UVVjYpmDgv q1HqlcFMAvHB5WGvR1fK3H48XzeC6TQ7Tm/WP1NHYAwjiUAcz6lRVX682jIer9AL 74Xe5wpswW9tStnTrUbDZciX05VAoDkwsvqrWbqG0NClh84bas1xd3TshRfaBXe7 32+FPl1XItxZeICl15/CLY35KMR0SCvfwzaga+BECu/GeMtm3f3dK++nSdJdAf6v +ac7Y3AvPhoECTIB8iDdRA== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3wd205h4tk-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Feb 2024 09:05:12 -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 454D2820258; Wed, 21 Feb 2024 15:05:07 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , , , "Richard Fitzgerald" Subject: [PATCH 6/9] ASoC: cs35l56: Apply amp calibration from EFI data Date: Wed, 21 Feb 2024 15:05:04 +0000 Message-ID: <20240221150507.1039979-7-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 X-Proofpoint-ORIG-GUID: V0vilrXqH8-PFut6s-PYWXt6VIiO0_CD X-Proofpoint-GUID: V0vilrXqH8-PFut6s-PYWXt6VIiO0_CD X-Proofpoint-Spam-Reason: safe X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791521471816598283 X-GMAIL-MSGID: 1791521471816598283 If there are factory calibration settings in EFI, extract the settings and write them to the firmware calibration controls. This must be done after any firmware or coefficients have been downloaded to the amp. Signed-off-by: Richard Fitzgerald --- sound/soc/codecs/cs35l56-sdw.c | 20 ++++++++++++++++ sound/soc/codecs/cs35l56.c | 43 +++++++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/sound/soc/codecs/cs35l56-sdw.c b/sound/soc/codecs/cs35l56-sdw.c index ab960a1c171e..eaa4c706f3a2 100644 --- a/sound/soc/codecs/cs35l56-sdw.c +++ b/sound/soc/codecs/cs35l56-sdw.c @@ -161,6 +161,20 @@ static const struct regmap_bus cs35l56_regmap_bus_sdw = { .val_format_endian_default = REGMAP_ENDIAN_BIG, }; +static int cs35l56_sdw_set_cal_index(struct cs35l56_private *cs35l56) +{ + int ret; + + /* SoundWire UniqueId is used to index the calibration array */ + ret = sdw_read_no_pm(cs35l56->sdw_peripheral, SDW_SCP_DEVID_0); + if (ret < 0) + return ret; + + cs35l56->base.cal_index = ret & 0xf; + + return 0; +} + static void cs35l56_sdw_init(struct sdw_slave *peripheral) { struct cs35l56_private *cs35l56 = dev_get_drvdata(&peripheral->dev); @@ -168,6 +182,12 @@ static void cs35l56_sdw_init(struct sdw_slave *peripheral) pm_runtime_get_noresume(cs35l56->base.dev); + if (cs35l56->base.cal_index < 0) { + ret = cs35l56_sdw_set_cal_index(cs35l56); + if (ret < 0) + goto out; + } + regcache_cache_only(cs35l56->base.regmap, false); ret = cs35l56_init(cs35l56); diff --git a/sound/soc/codecs/cs35l56.c b/sound/soc/codecs/cs35l56.c index 6dd0319bc843..73cc123db567 100644 --- a/sound/soc/codecs/cs35l56.c +++ b/sound/soc/codecs/cs35l56.c @@ -802,16 +802,44 @@ static struct snd_soc_dai_driver cs35l56_dai[] = { } }; +static int cs35l56_write_cal(struct cs35l56_private *cs35l56) +{ + int ret; + + if (cs35l56->base.secured || !cs35l56->base.cal_data_valid) + return -ENODATA; + + ret = wm_adsp_run(&cs35l56->dsp); + if (ret) + return ret; + + ret = cs_amp_write_cal_coeffs(&cs35l56->dsp, + &cs35l56_calibration_controls, + &cs35l56->base.cal_data); + + wm_adsp_stop(&cs35l56->dsp); + + if (ret == 0) + dev_info(cs35l56->base.dev, "Calibration applied\n"); + + return ret; +} + static void cs35l56_reinit_patch(struct cs35l56_private *cs35l56) { int ret; /* Use wm_adsp to load and apply the firmware patch and coefficient files */ ret = wm_adsp_power_up(&cs35l56->dsp, true); - if (ret) + if (ret) { dev_dbg(cs35l56->base.dev, "%s: wm_adsp_power_up ret %d\n", __func__, ret); - else - cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_AUDIO_REINIT); + return; + } + + cs35l56_write_cal(cs35l56); + + /* Always REINIT after applying patch or coefficients */ + cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_AUDIO_REINIT); } static void cs35l56_patch(struct cs35l56_private *cs35l56, bool firmware_missing) @@ -874,6 +902,9 @@ static void cs35l56_patch(struct cs35l56_private *cs35l56, bool firmware_missing CS35L56_FIRMWARE_MISSING); cs35l56->base.fw_patched = true; + if (cs35l56_write_cal(cs35l56) == 0) + cs35l56_mbox_send(&cs35l56->base, CS35L56_MBOX_CMD_AUDIO_REINIT); + err_unlock: mutex_unlock(&cs35l56->base.irq_lock); err: @@ -1356,6 +1387,7 @@ int cs35l56_common_probe(struct cs35l56_private *cs35l56) init_completion(&cs35l56->init_completion); mutex_init(&cs35l56->base.irq_lock); + cs35l56->base.cal_index = -1; cs35l56->speaker_id = -ENOENT; dev_set_drvdata(cs35l56->base.dev, cs35l56); @@ -1457,6 +1489,10 @@ int cs35l56_init(struct cs35l56_private *cs35l56) if (ret) return ret; + ret = cs35l56_get_calibration(&cs35l56->base); + if (ret) + return ret; + if (!cs35l56->base.reset_gpio) { dev_dbg(cs35l56->base.dev, "No reset gpio: using soft reset\n"); cs35l56->soft_resetting = true; @@ -1541,6 +1577,7 @@ EXPORT_NS_GPL_DEV_PM_OPS(cs35l56_pm_ops_i2c_spi, SND_SOC_CS35L56_CORE) = { MODULE_DESCRIPTION("ASoC CS35L56 driver"); MODULE_IMPORT_NS(SND_SOC_CS35L56_SHARED); +MODULE_IMPORT_NS(SND_SOC_CS_AMP_LIB); MODULE_AUTHOR("Richard Fitzgerald "); MODULE_AUTHOR("Simon Trimmer "); MODULE_LICENSE("GPL"); From patchwork Wed Feb 21 15:05:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 204255 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1094771dyc; Wed, 21 Feb 2024 07:07:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVOLI3v2iAWxL4o9V+FhDeK7tJptowgcKch+wsgH7APncn/dkdXjn9rYCg/o0NgPVQPoY9vsToRrrQ3aftB8Nw/lhdyYg== X-Google-Smtp-Source: AGHT+IHIz6ZX9D64YdA1sVUsPWA4GeIFiVtXpQQkPgQDQjVOdkM8/xsP8PFfyQKtkAk/rjBk4191 X-Received: by 2002:a17:906:33cf:b0:a3e:c134:92a7 with SMTP id w15-20020a17090633cf00b00a3ec13492a7mr5165083eja.25.1708528019919; Wed, 21 Feb 2024 07:06:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708528019; cv=pass; d=google.com; s=arc-20160816; b=EGbxN2RTtGnSpiQU10QPxg8bVHR6YhRKppRJy2UvC3utC1Lpx5bZM2W+nRVHgPBGKU ef8Pt23eE/5BF4NO2N1GPudp1SUw2SaI9ocyw4UmxqJn+zfc0T/Cfyr/iwPTjGmLMp4Y 7oZ2q08bsx2jSDMOK4LsEON68r39RTmJ2frN+uEdDWpO9+GEuWPdtG0o4yHpaiKsmjtH kFmB6VJ9Rd9sZCfGTJ5yY5koVUpu4K7R4GXCv08D3P8kDGcQRuU+cmgeAorqKeOL76b0 XKywIJmEDYo9xe/2oFUf4lYo6kcrDd0oVjO6FznjQkM6H65y9J8vfsVNnXmOWKj2NP7J hRYg== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74961-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z23-20020a1709060f1700b00a38a0206c0esi4574223eji.633.2024.02.21.07.06.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:06:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74961-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74961-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id DCE9C1F245B5 for ; Wed, 21 Feb 2024 15:06:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4BBC581749; Wed, 21 Feb 2024 15:05:31 +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 X-Proofpoint-GUID: w0IK1iOTQqvTEzp0K88FP1p3gONu8Es5 X-Proofpoint-ORIG-GUID: w0IK1iOTQqvTEzp0K88FP1p3gONu8Es5 X-Proofpoint-Spam-Reason: safe X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791521476899778087 X-GMAIL-MSGID: 1791521476899778087 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__*/ From patchwork Wed Feb 21 15:05:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 204253 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1094692dyc; Wed, 21 Feb 2024 07:06:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXT8/sUf8NBARHQ5Q0kGESvAc32h9peJkb7cOIx8RzmpmrbQTvkIurKSaq5PZCkOS/vYARQSm2OO+6gD57HWzSvjnt+hg== X-Google-Smtp-Source: AGHT+IGx6coTZqsYYdJV9zMOqSgTQF0x1yArIZXHTTaRAwEe94ny8iKut/gWn18GlPYTrb3njv3C X-Received: by 2002:a05:6402:1c05:b0:563:dcc8:a294 with SMTP id ck5-20020a0564021c0500b00563dcc8a294mr10395791edb.30.1708528013625; Wed, 21 Feb 2024 07:06:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708528013; cv=pass; d=google.com; s=arc-20160816; b=sq51AdGbZYZX35GP72QjY0uMJ2vqioOoCwvPJ3WfhuWTxDsO8cQpm+iTCYiSzLT/Qw S6DhRc95Zi91tjmKC9fWjhlBbG5ZdAwsXqCR0PlOoxvo+H7QP0vk9YopiOEhUvizQQT4 vHWScshifogfAVYPCXGD+SGBqgW8pVknv5lnfRQpJKdJ9xbIqJJKqCRaMPWxVUWhIo7u 44ExKU5VOzKyi0yPOHu+1d0CrWW6bhvf/cMJ/F2lDYNEBxnr8tNhDHp534qXYPtFwME9 5A+cyXWft+nO4BS4bKbCJOKKjUCMfP+Z0MxNrL7Zue5/fYKEP0Kfy8VR4ZfCxjxC33w4 m2sQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74959-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id i16-20020a50fc10000000b0056434e48810si3885038edr.75.2024.02.21.07.06.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:06:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74959-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74959-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 806A31F22776 for ; Wed, 21 Feb 2024 15:06:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE29B81731; Wed, 21 Feb 2024 15:05:30 +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 X-Proofpoint-ORIG-GUID: k2y-l2KGer9iwDt8BYqoie2PBIRRsdIE X-Proofpoint-GUID: k2y-l2KGer9iwDt8BYqoie2PBIRRsdIE X-Proofpoint-Spam-Reason: safe X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791521470451559618 X-GMAIL-MSGID: 1791521470451559618 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"); From patchwork Wed Feb 21 15:05:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Fitzgerald X-Patchwork-Id: 204257 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1095229dyc; Wed, 21 Feb 2024 07:07:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVyERpYvpWIvyukeAiQV/hHr9jOrOxedysWSqJKVG4GjKrY2BdobdNvbPNpVNMEitCCm3QXC8BVXs9uhtiY4zp2vO9wIg== X-Google-Smtp-Source: AGHT+IEg8PxZetCLiI+4JUu/Mqq0MQYZW1zQgqFeaP0A7ALVtNk9k4DauOXGlK0cYgXPae7z7seC X-Received: by 2002:a05:622a:1b8d:b0:42c:70a8:1b40 with SMTP id bp13-20020a05622a1b8d00b0042c70a81b40mr23167352qtb.17.1708528055055; Wed, 21 Feb 2024 07:07:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708528055; cv=pass; d=google.com; s=arc-20160816; b=psl/DwNpwp9n7i9Q+xd41D89awskCixHAdxjlHCb92ZB/m2vWdd8WktT3zccFovcB6 b/mYBSL5p4elzet4lReauNo5aiI3LNKY1LAN5sD7Jlrley0NradlcSZXWmGJJN10mVC8 ZKqQQIbJJQXd86H+Im5caaE/9rAJv+yIfqhUZHsZPVx8JyVMvbA4T2bDU+K/ZJuTGtrq w68FZ4oKBnjaDi9fdi2FRicO7tWuEpd/V5ZiK+t3joQ7nCRpZV6Ik0/MgTZ8EicVKHDS GTWhOQIpDXhig+cQEk59HufG2W5wo41MTBZ0xXJj37oAPvsl1O9DdIDLbYlyl6ZCd3JU nRtA== 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=lFHHp7Hf86/Y2k2Gbux127+DN+4Y38NV8nInI1CKNKg=; fh=x7+OzJIeN5mJd4Ln+gczq2EazpTbLb1MfGhRMe/0Fjo=; b=GfJCFws7+PrAd1qBxvFEajUcrQqzdUlEy0LXp89/BIqf0VE2niAt1R2rXe6UIHmXm6 pOc1ow/qH0oN8o4LEn7Zb/DW/TD5ML4PINgUUnx4Wlro4zBhsZcd+JEhxUAk0QRYNE/+ 7KULfwuBsDroXskF5OpG784L4kRz0c6gthmKlSp31ThuUx1qDnHd6X5fZ9nwKE3z7KJX SCgGNTq6V2T6AiIvQFWeVJCyF5aNv9vjUYBBYClz7OitJ34rwqJA/8R9hhJfT61VW5Kn bZS4Nejn/A9HHiAvkLy/q0lQg3XgxYiIf/VxKvh7N4hH5IrJB6fnKn74HORNxMDcmvcx eRwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=NuEy6yBL; 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-74965-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74965-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h6-20020a05620a13e600b007875c8bb93csi8708508qkl.554.2024.02.21.07.07.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:07:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74965-ouuuleilei=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=NuEy6yBL; 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-74965-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74965-ouuuleilei=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 540C51C225B3 for ; Wed, 21 Feb 2024 15:07:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5925823BE; Wed, 21 Feb 2024 15:05:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cirrus.com header.i=@cirrus.com header.b="NuEy6yBL" 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 61AD880042; Wed, 21 Feb 2024 15:05:27 +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=1708527930; cv=none; b=nJ53G9p0o0o/HmYSp4GcaFJRKZZpr8tkYy/PFPdElTcW8VTMQ9bQ3pPp2gS89rn2Qo4MXVcXCCy/V/5Rf4IDMgqYpCgNo61K3C6FQT2z8edr4uq9pMEUnDRDQ8SKOtmxfzbQ6YyKvn4iOkAxIl3GRBV1IV/3GP47UIpLTkHiMIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708527930; c=relaxed/simple; bh=FLDeM9Gn5BRmvPJw4831XzE31NwzjSqXo8OSpfZxOl8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ue0vVvORh26gDJR7zukahv13BaTt/I7JaZhezc6kTGf6WASEy6L1/DpAHV6jUtsweO4QuU/KcD/eldyfLeYOHo6eZsdF4cMJaCmmPxb7wxugyhA5gZU6gjMh6FHuwbVv938IX4Z+zYMCBplu79nRRycAqI7zcYWhW+8TxVrS+yo= 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=NuEy6yBL; 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 41L72AP1020807; 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=lFHHp7Hf86/Y2k2Gbux127+DN+4Y38NV8nInI1CKNKg=; b= NuEy6yBL471FUI8+J5QRevhzbswcvNuyug4HvmtzJWHvFQ1e4KIKuM+RiYbBUcyJ 0UFoJrRiigePbV9CX5PutkJHwHXuNCw4wYC3ZH+jtO+CnwFBmeEo6sBAfuiX6U1y fGt3P+OluOr3pHaQ7eDRuJHl78YO9S0ie3rBriNCKz2IXjzaPQqFOOhM/tnaC506 TE+zOQJKTqDvw/nKUv7YcRvt89uNhCsxl/ERGG7Uodhfm9VqDj+a40fRh8AE2o5H XS1NwCEXc5lOs/VeBrId7GMtaYBQUKuTZJFtlykvoMvesSOHJqQKyuNuaQfhrQft BT4276LPGHpAEgbWc+WUEQ== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3wd207h58t-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 21 Feb 2024 09:05:11 -0600 (CST) Received: from ediex02.ad.cirrus.com (198.61.84.81) 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 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 523DC820270; Wed, 21 Feb 2024 15:05:07 +0000 (UTC) From: Richard Fitzgerald To: , CC: , , , , "Richard Fitzgerald" Subject: [PATCH 9/9] ASoC: cs-amp-lib: Add KUnit test for calibration helpers Date: Wed, 21 Feb 2024 15:05:07 +0000 Message-ID: <20240221150507.1039979-10-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 X-Proofpoint-GUID: W_kcH0L5JPgoWf4a_gBFHknaAzwmnbAa X-Proofpoint-ORIG-GUID: W_kcH0L5JPgoWf4a_gBFHknaAzwmnbAa X-Proofpoint-Spam-Reason: safe X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791521513606521628 X-GMAIL-MSGID: 1791521513606521628 Add a KUnit test for the cs-amp-lib library. This has test cases for cs_amp_get_efi_calibration_data() and cs_amp_write_cal_coeffs(). A KUNIT_STATIC_STUB_REDIRECT() has been added to cs_amp_get_efi_variable() and cs_amp_write_cal_coeff() so that the KUnit test can redirect these to test harness functions. Signed-off-by: Richard Fitzgerald --- include/sound/cs-amp-lib.h | 14 + sound/soc/codecs/Kconfig | 14 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/cs-amp-lib-test.c | 709 +++++++++++++++++++++++++++++ sound/soc/codecs/cs-amp-lib.c | 18 +- 5 files changed, 755 insertions(+), 2 deletions(-) create mode 100644 sound/soc/codecs/cs-amp-lib-test.c diff --git a/include/sound/cs-amp-lib.h b/include/sound/cs-amp-lib.h index 35f7bd848276..c9055d833bd0 100644 --- a/include/sound/cs-amp-lib.h +++ b/include/sound/cs-amp-lib.h @@ -49,4 +49,18 @@ int cs_amp_write_cal_coeffs(struct wm_adsp *dsp, const struct cirrus_amp_cal_data *data); int cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index, struct cirrus_amp_cal_data *out_data); + +struct cs_amp_test_hooks { + efi_status_t (*get_efi_variable)(efi_char16_t *name, + efi_guid_t *guid, + unsigned long *size, + void *buf); + + int (*write_cal_coeff)(struct wm_adsp *dsp, + const struct cirrus_amp_cal_controls *controls, + const char *ctl_name, u32 val); +}; + +extern const struct cs_amp_test_hooks * const cs_amp_test_hooks; + #endif /* CS_AMP_LIB_H */ diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 15f287784d8b..373d0f6478ae 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -732,6 +732,20 @@ config SND_SOC_CROS_EC_CODEC config SND_SOC_CS_AMP_LIB tristate +config SND_SOC_CS_AMP_LIB_TEST + tristate "KUnit test for Cirrus Logic cs-amp-lib" + depends on KUNIT + depends on ACPI || COMPILE_TEST + default KUNIT_ALL_TESTS + select SND_SOC_CS_AMP_LIB + help + This builds KUnit tests for the Cirrus Logic common + amplifier library. + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + If in doubt, say "N". + config SND_SOC_CS35L32 tristate "Cirrus Logic CS35L32 CODEC" depends on I2C diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 0fc40640e5d0..7c075539dc47 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -60,6 +60,7 @@ snd-soc-cpcap-objs := cpcap.o snd-soc-cq93vc-objs := cq93vc.o snd-soc-cros-ec-codec-objs := cros_ec_codec.o snd-soc-cs-amp-lib-objs := cs-amp-lib.o +snd-soc-cs-amp-lib-test-objs := cs-amp-lib-test.o snd-soc-cs35l32-objs := cs35l32.o snd-soc-cs35l33-objs := cs35l33.o snd-soc-cs35l34-objs := cs35l34.o @@ -454,6 +455,7 @@ obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o obj-$(CONFIG_SND_SOC_CPCAP) += snd-soc-cpcap.o obj-$(CONFIG_SND_SOC_CROS_EC_CODEC) += snd-soc-cros-ec-codec.o obj-$(CONFIG_SND_SOC_CS_AMP_LIB) += snd-soc-cs-amp-lib.o +obj-$(CONFIG_SND_SOC_CS_AMP_LIB_TEST) += snd-soc-cs-amp-lib-test.o obj-$(CONFIG_SND_SOC_CS35L32) += snd-soc-cs35l32.o obj-$(CONFIG_SND_SOC_CS35L33) += snd-soc-cs35l33.o obj-$(CONFIG_SND_SOC_CS35L34) += snd-soc-cs35l34.o diff --git a/sound/soc/codecs/cs-amp-lib-test.c b/sound/soc/codecs/cs-amp-lib-test.c new file mode 100644 index 000000000000..6f9e5755e145 --- /dev/null +++ b/sound/soc/codecs/cs-amp-lib-test.c @@ -0,0 +1,709 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// KUnit test for the Cirrus common amplifier library. +// +// Copyright (C) 2024 Cirrus Logic, Inc. and +// Cirrus Logic International Semiconductor Ltd. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "wm_adsp.h" + +struct cs_amp_lib_test_priv { + struct platform_device amp_pdev; + + struct cirrus_amp_efi_data *cal_blob; + struct list_head ctl_write_list; +}; + +struct cs_amp_lib_test_ctl_write_entry { + struct list_head list; + unsigned int value; + char name[16]; +}; + +struct cs_amp_lib_test_param { + int num_amps; + int amp_index; +}; + +static void cs_amp_lib_test_init_dummy_cal_blob(struct kunit *test, int num_amps) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + unsigned int blob_size; + + blob_size = offsetof(struct cirrus_amp_efi_data, data) + + sizeof(struct cirrus_amp_cal_data) * num_amps; + + priv->cal_blob = kunit_kzalloc(test, blob_size, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, priv->cal_blob); + + priv->cal_blob->size = blob_size; + priv->cal_blob->count = num_amps; + + get_random_bytes(priv->cal_blob->data, sizeof(struct cirrus_amp_cal_data) * num_amps); +} + +static u64 cs_amp_lib_test_get_target_uid(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + const struct cs_amp_lib_test_param *param = test->param_value; + u64 uid; + + uid = priv->cal_blob->data[param->amp_index].calTarget[1]; + uid <<= 32; + uid |= priv->cal_blob->data[param->amp_index].calTarget[0]; + + return uid; +} + +/* Redirected get_efi_variable to simulate that the file is too short */ +static efi_status_t cs_amp_lib_test_get_efi_variable_nohead(efi_char16_t *name, + efi_guid_t *guid, + unsigned long *size, + void *buf) +{ + if (!buf) { + *size = offsetof(struct cirrus_amp_efi_data, data) - 1; + return EFI_BUFFER_TOO_SMALL; + } + + return EFI_NOT_FOUND; +} + +/* Should return -EOVERFLOW if the header is larger than the EFI data */ +static void cs_amp_lib_test_cal_data_too_short_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + struct cirrus_amp_cal_data result_data; + int ret; + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable_nohead); + + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, 0, &result_data); + KUNIT_EXPECT_EQ(test, ret, -EOVERFLOW); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); +} + +/* Redirected get_efi_variable to simulate that the count is larger than the file */ +static efi_status_t cs_amp_lib_test_get_efi_variable_bad_count(efi_char16_t *name, + efi_guid_t *guid, + unsigned long *size, + void *buf) +{ + struct kunit *test = kunit_get_current_test(); + struct cs_amp_lib_test_priv *priv = test->priv; + + if (!buf) { + /* + * Return a size that is shorter than required for the + * declared number of entries. + */ + *size = priv->cal_blob->size - 1; + return EFI_BUFFER_TOO_SMALL; + } + + memcpy(buf, priv->cal_blob, priv->cal_blob->size - 1); + + return EFI_SUCCESS; +} + +/* Should return -EOVERFLOW if the entry count is larger than the EFI data */ +static void cs_amp_lib_test_cal_count_too_big_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + struct cirrus_amp_cal_data result_data; + int ret; + + cs_amp_lib_test_init_dummy_cal_blob(test, 8); + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable_bad_count); + + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, 0, &result_data); + KUNIT_EXPECT_EQ(test, ret, -EOVERFLOW); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); +} + +/* Redirected get_efi_variable to simulate that the variable not found */ +static efi_status_t cs_amp_lib_test_get_efi_variable_none(efi_char16_t *name, + efi_guid_t *guid, + unsigned long *size, + void *buf) +{ + return EFI_NOT_FOUND; +} + +/* If EFI doesn't contain a cal data variable the result should be -ENOENT */ +static void cs_amp_lib_test_no_cal_data_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + struct cirrus_amp_cal_data result_data; + int ret; + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable_none); + + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, 0, &result_data); + KUNIT_EXPECT_EQ(test, ret, -ENOENT); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); +} + +/* Redirected get_efi_variable to simulate reading a cal data blob */ +static efi_status_t cs_amp_lib_test_get_efi_variable(efi_char16_t *name, + efi_guid_t *guid, + unsigned long *size, + void *buf) +{ + static const efi_char16_t expected_name[] = L"CirrusSmartAmpCalibrationData"; + static const efi_guid_t expected_guid = + EFI_GUID(0x02f9af02, 0x7734, 0x4233, 0xb4, 0x3d, 0x93, 0xfe, 0x5a, 0xa3, 0x5d, 0xb3); + struct kunit *test = kunit_get_current_test(); + struct cs_amp_lib_test_priv *priv = test->priv; + + KUNIT_EXPECT_NOT_ERR_OR_NULL(test, name); + KUNIT_EXPECT_NOT_ERR_OR_NULL(test, guid); + KUNIT_EXPECT_NOT_ERR_OR_NULL(test, size); + + KUNIT_EXPECT_MEMEQ(test, name, expected_name, sizeof(expected_name)); + KUNIT_EXPECT_MEMEQ(test, guid, &expected_guid, sizeof(expected_guid)); + + if (!buf) { + *size = priv->cal_blob->size; + return EFI_BUFFER_TOO_SMALL; + } + + KUNIT_ASSERT_GE_MSG(test, ksize(buf), priv->cal_blob->size, "Buffer to small"); + + memcpy(buf, priv->cal_blob, priv->cal_blob->size); + + return EFI_SUCCESS; +} + +/* Get cal data block for a given amp, matched by target UID. */ +static void cs_amp_lib_test_get_efi_cal_by_uid_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + const struct cs_amp_lib_test_param *param = test->param_value; + struct cirrus_amp_cal_data result_data; + u64 target_uid; + int ret; + + cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps); + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable); + + target_uid = cs_amp_lib_test_get_target_uid(test); + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, target_uid, -1, &result_data); + KUNIT_EXPECT_EQ(test, ret, 0); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); + + KUNIT_EXPECT_EQ(test, result_data.calTarget[0], target_uid & 0xFFFFFFFFULL); + KUNIT_EXPECT_EQ(test, result_data.calTarget[1], target_uid >> 32); + KUNIT_EXPECT_EQ(test, result_data.calTime[0], + priv->cal_blob->data[param->amp_index].calTime[0]); + KUNIT_EXPECT_EQ(test, result_data.calTime[1], + priv->cal_blob->data[param->amp_index].calTime[1]); + KUNIT_EXPECT_EQ(test, result_data.calAmbient, + priv->cal_blob->data[param->amp_index].calAmbient); + KUNIT_EXPECT_EQ(test, result_data.calStatus, + priv->cal_blob->data[param->amp_index].calStatus); + KUNIT_EXPECT_EQ(test, result_data.calR, + priv->cal_blob->data[param->amp_index].calR); +} + +/* Get cal data block for a given amp index without checking target UID. */ +static void cs_amp_lib_test_get_efi_cal_by_index_unchecked_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + const struct cs_amp_lib_test_param *param = test->param_value; + struct cirrus_amp_cal_data result_data; + int ret; + + cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps); + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable); + + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, + param->amp_index, &result_data); + KUNIT_EXPECT_EQ(test, ret, 0); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); + + KUNIT_EXPECT_EQ(test, result_data.calTime[0], + priv->cal_blob->data[param->amp_index].calTime[0]); + KUNIT_EXPECT_EQ(test, result_data.calTime[1], + priv->cal_blob->data[param->amp_index].calTime[1]); + KUNIT_EXPECT_EQ(test, result_data.calAmbient, + priv->cal_blob->data[param->amp_index].calAmbient); + KUNIT_EXPECT_EQ(test, result_data.calStatus, + priv->cal_blob->data[param->amp_index].calStatus); + KUNIT_EXPECT_EQ(test, result_data.calR, + priv->cal_blob->data[param->amp_index].calR); +} + +/* Get cal data block for a given amp index with checked target UID. */ +static void cs_amp_lib_test_get_efi_cal_by_index_checked_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + const struct cs_amp_lib_test_param *param = test->param_value; + struct cirrus_amp_cal_data result_data; + u64 target_uid; + int ret; + + cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps); + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable); + + target_uid = cs_amp_lib_test_get_target_uid(test); + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, target_uid, + param->amp_index, &result_data); + KUNIT_EXPECT_EQ(test, ret, 0); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); + + KUNIT_EXPECT_EQ(test, result_data.calTime[0], + priv->cal_blob->data[param->amp_index].calTime[0]); + KUNIT_EXPECT_EQ(test, result_data.calTime[1], + priv->cal_blob->data[param->amp_index].calTime[1]); + KUNIT_EXPECT_EQ(test, result_data.calAmbient, + priv->cal_blob->data[param->amp_index].calAmbient); + KUNIT_EXPECT_EQ(test, result_data.calStatus, + priv->cal_blob->data[param->amp_index].calStatus); + KUNIT_EXPECT_EQ(test, result_data.calR, + priv->cal_blob->data[param->amp_index].calR); +} + +/* + * Get cal data block for a given amp index with checked target UID. + * The UID does not match so the result should be -ENOENT. + */ +static void cs_amp_lib_test_get_efi_cal_by_index_uid_mismatch_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + const struct cs_amp_lib_test_param *param = test->param_value; + struct cirrus_amp_cal_data result_data; + u64 target_uid; + int ret; + + cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps); + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable); + + /* Get a target UID that won't match the entry */ + target_uid = ~cs_amp_lib_test_get_target_uid(test); + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, target_uid, + param->amp_index, &result_data); + KUNIT_EXPECT_EQ(test, ret, -ENOENT); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); +} + +/* + * Get cal data block for a given amp, where the cal data does not + * specify calTarget so the lookup falls back to using the index + */ +static void cs_amp_lib_test_get_efi_cal_by_index_fallback_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + const struct cs_amp_lib_test_param *param = test->param_value; + struct cirrus_amp_cal_data result_data; + static const u64 bad_target_uid = 0xBADCA100BABABABAULL; + int i, ret; + + cs_amp_lib_test_init_dummy_cal_blob(test, param->num_amps); + + /* Make all the target values zero so they are ignored */ + for (i = 0; i < priv->cal_blob->count; ++i) { + priv->cal_blob->data[i].calTarget[0] = 0; + priv->cal_blob->data[i].calTarget[1] = 0; + } + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable); + + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, bad_target_uid, + param->amp_index, &result_data); + KUNIT_EXPECT_EQ(test, ret, 0); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); + + KUNIT_EXPECT_EQ(test, result_data.calTime[0], + priv->cal_blob->data[param->amp_index].calTime[0]); + KUNIT_EXPECT_EQ(test, result_data.calTime[1], + priv->cal_blob->data[param->amp_index].calTime[1]); + KUNIT_EXPECT_EQ(test, result_data.calAmbient, + priv->cal_blob->data[param->amp_index].calAmbient); + KUNIT_EXPECT_EQ(test, result_data.calStatus, + priv->cal_blob->data[param->amp_index].calStatus); + KUNIT_EXPECT_EQ(test, result_data.calR, + priv->cal_blob->data[param->amp_index].calR); +} + +/* + * If the target UID isn't present in the cal data, and there isn't an + * index to fall back do, the result should be -ENOENT. + */ +static void cs_amp_lib_test_get_efi_cal_uid_not_found_noindex_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + struct cirrus_amp_cal_data result_data; + static const u64 bad_target_uid = 0xBADCA100BABABABAULL; + int i, ret; + + cs_amp_lib_test_init_dummy_cal_blob(test, 8); + + /* Make all the target values != bad_target_uid */ + for (i = 0; i < priv->cal_blob->count; ++i) { + priv->cal_blob->data[i].calTarget[0] &= ~(bad_target_uid & 0xFFFFFFFFULL); + priv->cal_blob->data[i].calTarget[1] &= ~(bad_target_uid >> 32); + } + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable); + + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, bad_target_uid, -1, + &result_data); + KUNIT_EXPECT_EQ(test, ret, -ENOENT); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); +} + +/* + * If the target UID isn't present in the cal data, and the index is + * out of range, the result should be -ENOENT. + */ +static void cs_amp_lib_test_get_efi_cal_uid_not_found_index_not_found_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + struct cirrus_amp_cal_data result_data; + static const u64 bad_target_uid = 0xBADCA100BABABABAULL; + int i, ret; + + cs_amp_lib_test_init_dummy_cal_blob(test, 8); + + /* Make all the target values != bad_target_uid */ + for (i = 0; i < priv->cal_blob->count; ++i) { + priv->cal_blob->data[i].calTarget[0] &= ~(bad_target_uid & 0xFFFFFFFFULL); + priv->cal_blob->data[i].calTarget[1] &= ~(bad_target_uid >> 32); + } + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable); + + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, bad_target_uid, 99, + &result_data); + KUNIT_EXPECT_EQ(test, ret, -ENOENT); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); +} + +/* + * If the target UID isn't given, and the index is out of range, the + * result should be -ENOENT. + */ +static void cs_amp_lib_test_get_efi_cal_no_uid_index_not_found_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + struct cirrus_amp_cal_data result_data; + int ret; + + cs_amp_lib_test_init_dummy_cal_blob(test, 8); + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable); + + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, 99, &result_data); + KUNIT_EXPECT_EQ(test, ret, -ENOENT); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); +} + +/* If neither the target UID or the index is given the result should be -ENOENT. */ +static void cs_amp_lib_test_get_efi_cal_no_uid_no_index_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + struct cirrus_amp_cal_data result_data; + int ret; + + cs_amp_lib_test_init_dummy_cal_blob(test, 8); + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable); + + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, -1, &result_data); + KUNIT_EXPECT_EQ(test, ret, -ENOENT); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); +} + +/* + * If the UID is passed as 0 this must not match an entry with an + * unpopulated calTarget + */ +static void cs_amp_lib_test_get_efi_cal_zero_not_matched_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + struct cirrus_amp_cal_data result_data; + int i, ret; + + cs_amp_lib_test_init_dummy_cal_blob(test, 8); + + /* Make all the target values zero so they are ignored */ + for (i = 0; i < priv->cal_blob->count; ++i) { + priv->cal_blob->data[i].calTarget[0] = 0; + priv->cal_blob->data[i].calTarget[1] = 0; + } + + /* Redirect calls to get EFI data */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->get_efi_variable, + cs_amp_lib_test_get_efi_variable); + + ret = cs_amp_get_efi_calibration_data(&priv->amp_pdev.dev, 0, -1, &result_data); + KUNIT_EXPECT_EQ(test, ret, -ENOENT); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->get_efi_variable); +} + +static const struct cirrus_amp_cal_controls cs_amp_lib_test_calibration_controls = { + .alg_id = 0x9f210, + .mem_region = WMFW_ADSP2_YM, + .ambient = "CAL_AMBIENT", + .calr = "CAL_R", + .status = "CAL_STATUS", + .checksum = "CAL_CHECKSUM", +}; + +static int cs_amp_lib_test_write_cal_coeff(struct wm_adsp *dsp, + const struct cirrus_amp_cal_controls *controls, + const char *ctl_name, u32 val) +{ + struct kunit *test = kunit_get_current_test(); + struct cs_amp_lib_test_priv *priv = test->priv; + struct cs_amp_lib_test_ctl_write_entry *entry; + + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctl_name); + KUNIT_EXPECT_PTR_EQ(test, controls, &cs_amp_lib_test_calibration_controls); + + entry = kunit_kzalloc(test, sizeof(*entry), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, entry); + + INIT_LIST_HEAD(&entry->list); + strscpy(entry->name, ctl_name, sizeof(entry->name)); + entry->value = val; + + list_add_tail(&entry->list, &priv->ctl_write_list); + + return 0; +} + +static void cs_amp_lib_test_write_cal_data_test(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + struct cs_amp_lib_test_ctl_write_entry *entry; + struct cirrus_amp_cal_data data; + struct wm_adsp *dsp; + int ret; + + dsp = kunit_kzalloc(test, sizeof(*dsp), GFP_KERNEL); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dsp); + dsp->cs_dsp.dev = &priv->amp_pdev.dev; + + get_random_bytes(&data, sizeof(data)); + + /* Redirect calls to write firmware controls */ + kunit_activate_static_stub(test, + cs_amp_test_hooks->write_cal_coeff, + cs_amp_lib_test_write_cal_coeff); + + ret = cs_amp_write_cal_coeffs(dsp, &cs_amp_lib_test_calibration_controls, &data); + KUNIT_EXPECT_EQ(test, ret, 0); + + kunit_deactivate_static_stub(test, cs_amp_test_hooks->write_cal_coeff); + + KUNIT_EXPECT_EQ(test, list_count_nodes(&priv->ctl_write_list), 4); + + /* Checksum control must be written last */ + entry = list_last_entry(&priv->ctl_write_list, typeof(*entry), list); + KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.checksum); + KUNIT_EXPECT_EQ(test, entry->value, data.calR + 1); + list_del(&entry->list); + + entry = list_first_entry(&priv->ctl_write_list, typeof(*entry), list); + KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.ambient); + KUNIT_EXPECT_EQ(test, entry->value, data.calAmbient); + list_del(&entry->list); + + entry = list_first_entry(&priv->ctl_write_list, typeof(*entry), list); + KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.calr); + KUNIT_EXPECT_EQ(test, entry->value, data.calR); + list_del(&entry->list); + + entry = list_first_entry(&priv->ctl_write_list, typeof(*entry), list); + KUNIT_EXPECT_STREQ(test, entry->name, cs_amp_lib_test_calibration_controls.status); + KUNIT_EXPECT_EQ(test, entry->value, data.calStatus); +} + +static void cs_amp_lib_test_dev_release(struct device *dev) +{ +} + +static int cs_amp_lib_test_case_init(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv; + int ret; + + KUNIT_ASSERT_NOT_NULL(test, cs_amp_test_hooks); + + priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + test->priv = priv; + INIT_LIST_HEAD(&priv->ctl_write_list); + + /* Create dummy amp driver dev */ + priv->amp_pdev.name = "cs_amp_lib_test_drv"; + priv->amp_pdev.id = -1; + priv->amp_pdev.dev.release = cs_amp_lib_test_dev_release; + ret = platform_device_register(&priv->amp_pdev); + KUNIT_ASSERT_GE_MSG(test, ret, 0, "Failed to register amp platform device\n"); + + return 0; +} + +static void cs_amp_lib_test_case_exit(struct kunit *test) +{ + struct cs_amp_lib_test_priv *priv = test->priv; + + if (priv->amp_pdev.name) + platform_device_unregister(&priv->amp_pdev); +} + +static const struct cs_amp_lib_test_param cs_amp_lib_test_get_cal_param_cases[] = { + { .num_amps = 2, .amp_index = 0 }, + { .num_amps = 2, .amp_index = 1 }, + + { .num_amps = 3, .amp_index = 0 }, + { .num_amps = 3, .amp_index = 1 }, + { .num_amps = 3, .amp_index = 2 }, + + { .num_amps = 4, .amp_index = 0 }, + { .num_amps = 4, .amp_index = 1 }, + { .num_amps = 4, .amp_index = 2 }, + { .num_amps = 4, .amp_index = 3 }, + + { .num_amps = 5, .amp_index = 0 }, + { .num_amps = 5, .amp_index = 1 }, + { .num_amps = 5, .amp_index = 2 }, + { .num_amps = 5, .amp_index = 3 }, + { .num_amps = 5, .amp_index = 4 }, + + { .num_amps = 6, .amp_index = 0 }, + { .num_amps = 6, .amp_index = 1 }, + { .num_amps = 6, .amp_index = 2 }, + { .num_amps = 6, .amp_index = 3 }, + { .num_amps = 6, .amp_index = 4 }, + { .num_amps = 6, .amp_index = 5 }, + + { .num_amps = 8, .amp_index = 0 }, + { .num_amps = 8, .amp_index = 1 }, + { .num_amps = 8, .amp_index = 2 }, + { .num_amps = 8, .amp_index = 3 }, + { .num_amps = 8, .amp_index = 4 }, + { .num_amps = 8, .amp_index = 5 }, + { .num_amps = 8, .amp_index = 6 }, + { .num_amps = 8, .amp_index = 7 }, +}; + +static void cs_amp_lib_test_get_cal_param_desc(const struct cs_amp_lib_test_param *param, + char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "num_amps:%d amp_index:%d", + param->num_amps, param->amp_index); +} + +KUNIT_ARRAY_PARAM(cs_amp_lib_test_get_cal, cs_amp_lib_test_get_cal_param_cases, + cs_amp_lib_test_get_cal_param_desc); + +static struct kunit_case cs_amp_lib_test_cases[] = { + /* Tests for getting calibration data from EFI */ + KUNIT_CASE(cs_amp_lib_test_cal_data_too_short_test), + KUNIT_CASE(cs_amp_lib_test_cal_count_too_big_test), + KUNIT_CASE(cs_amp_lib_test_no_cal_data_test), + KUNIT_CASE(cs_amp_lib_test_get_efi_cal_uid_not_found_noindex_test), + KUNIT_CASE(cs_amp_lib_test_get_efi_cal_uid_not_found_index_not_found_test), + KUNIT_CASE(cs_amp_lib_test_get_efi_cal_no_uid_index_not_found_test), + KUNIT_CASE(cs_amp_lib_test_get_efi_cal_no_uid_no_index_test), + KUNIT_CASE(cs_amp_lib_test_get_efi_cal_zero_not_matched_test), + KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_uid_test, + cs_amp_lib_test_get_cal_gen_params), + KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_unchecked_test, + cs_amp_lib_test_get_cal_gen_params), + KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_checked_test, + cs_amp_lib_test_get_cal_gen_params), + KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_uid_mismatch_test, + cs_amp_lib_test_get_cal_gen_params), + KUNIT_CASE_PARAM(cs_amp_lib_test_get_efi_cal_by_index_fallback_test, + cs_amp_lib_test_get_cal_gen_params), + + /* Tests for writing calibration data */ + KUNIT_CASE(cs_amp_lib_test_write_cal_data_test), + + { } /* terminator */ +}; + +static struct kunit_suite cs_amp_lib_test_suite = { + .name = "snd-soc-cs-amp-lib-test", + .init = cs_amp_lib_test_case_init, + .exit = cs_amp_lib_test_case_exit, + .test_cases = cs_amp_lib_test_cases, +}; + +kunit_test_suite(cs_amp_lib_test_suite); + +MODULE_IMPORT_NS(SND_SOC_CS_AMP_LIB); +MODULE_DESCRIPTION("KUnit test for Cirrus Logic amplifier library"); +MODULE_AUTHOR("Richard Fitzgerald "); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/codecs/cs-amp-lib.c b/sound/soc/codecs/cs-amp-lib.c index 0e1249342a78..a6ac96ecb176 100644 --- a/sound/soc/codecs/cs-amp-lib.c +++ b/sound/soc/codecs/cs-amp-lib.c @@ -6,6 +6,7 @@ // Cirrus Logic International Semiconductor Ltd. #include +#include #include #include #include @@ -26,6 +27,8 @@ static int cs_amp_write_cal_coeff(struct wm_adsp *dsp, __be32 beval = cpu_to_be32(val); int ret; + KUNIT_STATIC_STUB_REDIRECT(cs_amp_write_cal_coeff, dsp, controls, ctl_name, val); + if (IS_REACHABLE(CONFIG_SND_SOC_WM_ADSP)) { ret = wm_adsp_write_ctl(dsp, ctl_name, controls->mem_region, controls->alg_id, &beval, sizeof(beval)); @@ -78,7 +81,7 @@ int cs_amp_write_cal_coeffs(struct wm_adsp *dsp, const struct cirrus_amp_cal_controls *controls, const struct cirrus_amp_cal_data *data) { - if (IS_REACHABLE(CONFIG_SND_SOC_WM_ADSP)) + if (IS_REACHABLE(CONFIG_SND_SOC_WM_ADSP) || IS_ENABLED(CONFIG_SND_SOC_CS_AMP_LIB_TEST)) return _cs_amp_write_cal_coeffs(dsp, controls, data); else return -ENODEV; @@ -92,6 +95,8 @@ static efi_status_t cs_amp_get_efi_variable(efi_char16_t *name, { u32 attr; + KUNIT_STATIC_STUB_REDIRECT(cs_amp_get_efi_variable, name, guid, size, buf); + if (IS_ENABLED(CONFIG_EFI)) return efi.get_variable(name, guid, &attr, size, buf); @@ -244,13 +249,22 @@ static int _cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int cs_amp_get_efi_calibration_data(struct device *dev, u64 target_uid, int amp_index, struct cirrus_amp_cal_data *out_data) { - if (IS_ENABLED(CONFIG_EFI)) + if (IS_ENABLED(CONFIG_EFI) || IS_ENABLED(CONFIG_SND_SOC_CS_AMP_LIB_TEST)) return _cs_amp_get_efi_calibration_data(dev, target_uid, amp_index, out_data); else return -ENOENT; } EXPORT_SYMBOL_NS_GPL(cs_amp_get_efi_calibration_data, SND_SOC_CS_AMP_LIB); +static const struct cs_amp_test_hooks cs_amp_test_hook_ptrs = { + .get_efi_variable = cs_amp_get_efi_variable, + .write_cal_coeff = cs_amp_write_cal_coeff, +}; + +const struct cs_amp_test_hooks * const cs_amp_test_hooks = + PTR_IF(IS_ENABLED(CONFIG_SND_SOC_CS_AMP_LIB_TEST), &cs_amp_test_hook_ptrs); +EXPORT_SYMBOL_NS_GPL(cs_amp_test_hooks, SND_SOC_CS_AMP_LIB); + MODULE_DESCRIPTION("Cirrus Logic amplifier library"); MODULE_AUTHOR("Richard Fitzgerald "); MODULE_LICENSE("GPL");