From patchwork Mon Dec 4 12:47:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 750414 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5F72FC10F04 for ; Mon, 4 Dec 2023 12:48:32 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 13AEE827; Mon, 4 Dec 2023 13:48:20 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 13AEE827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1701694110; bh=gwEACH/aMrwkoIBjPUrdeotQmFvpJYGpN56GuamW+G8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=tq1zx6gMNmwB/LummZss4fdnidi9EWg3zC2jk8wZXkDybjghd6UXY8yFgVTkUeV9Y wkaG5OmmSIUO2QRaV3e8d2hSo6Rzc2Ie6iSkXw7xi8J5iNca1aQbaHq5pcEiz7UklA J/7VEBvg0K3MTaWIwZN2TVOtDgEwv06TR5KK7DLc= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4E5A2F80589; Mon, 4 Dec 2023 13:47:56 +0100 (CET) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id CAD6CF80587; Mon, 4 Dec 2023 13:47:55 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 777B5F8024E; Mon, 4 Dec 2023 13:47:51 +0100 (CET) Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 45456F800AC for ; Mon, 4 Dec 2023 13:47:42 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 45456F800AC Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=sXBNAyvc Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-54c846da5e9so1632561a12.3 for ; Mon, 04 Dec 2023 04:47:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1701694062; x=1702298862; darn=alsa-project.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+ziVbN5ZTP69p6FxRTQ/DrNWjlcr9menHHHhzgnVhU0=; b=sXBNAyvcuy07ld7Y3n6jAF0Fk1SdoKw9SLUhZ/pzUsXSEgHxFDvV4pbOtBgRafDILS 9aebF0n0R5n652ASkFrvUniVfhIs8TdWsCm1zAqGc0jMqw/YcgPFoRaO0lY6j8uH04oI UYDHycZZ4Onv3eKg0S6Bd2NTqeuaeNE3TM/bbqlqgVBy6IY/44x6Fqrk+qM1158bD0EW M+/QfFGVmu9Wc/F6cRKWZoGtN76q0VMrd/e+4Lf90LFyltAy3/n18pzRr3YxPYEpvqv2 vY9L20aUohrsCzaG829pWeUhJkbBsZ1jctkVxJZc6uYO+NHAvQ9IHpiXbzcoCY0RNl8X 6FpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701694062; x=1702298862; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+ziVbN5ZTP69p6FxRTQ/DrNWjlcr9menHHHhzgnVhU0=; b=TPlz2TECq8jGtTKgizYmSaMp3K9ncX8yRTZtcE+L1caNy17B4IjNzM4RpBi+UYrH4E Zfbo3vasTGH8lEMk3QHykVdtjFxmsK6x+dZpo8pkyGSl/3kpMrkxRZuuARiYb8wmXXgz NjZ2/UQRWmcjUBEzcCGdCF6V4E466U8bivPpwQE9AFwieoM7aCRnoa5nyvb49RfmmRix dddex/U8sGdRbL6kzSfC0pcptbCxqevO4GVfK7pKLxZZLo2uVBR2pPTnwmCOrAwrAJDy 03+dAn4IHpEz/Osvpa1Gwh5gsx+0Z0HGNP9METvG0hRpr1gCJgKnSXJTwpbdw1LmK+Bs lqQw== X-Gm-Message-State: AOJu0YyX58UGrI7x5S2vNpqz5AGycWhLBVYFVMzrD7Lu+EsO2WHrGIOX fyzDrDvRTM82/aDVMB+Ng+DkBQ== X-Google-Smtp-Source: AGHT+IHApXDdpr226FRyb9j61M1tzyPuEc1Ds/nq5f9VgF00NIL9sLCBQAy4dDG6sIZWA3NbhrjkNA== X-Received: by 2002:a50:d59a:0:b0:54c:4837:903c with SMTP id v26-20020a50d59a000000b0054c4837903cmr3836618edi.52.1701694062023; Mon, 04 Dec 2023 04:47:42 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id dc15-20020a056402310f00b0054ced65bd26sm457017edb.41.2023.12.04.04.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 04:47:41 -0800 (PST) From: srinivas.kandagatla@linaro.org To: broonie@kernel.org, alsa-devel@alsa-project.org Cc: perex@perex.cz, tiwai@suse.com, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, johan+linaro@kernel.org, Srinivas Kandagatla Subject: [PATCH 1/2] ASoC: ops: add correct range check for limiting volume Date: Mon, 4 Dec 2023 12:47:35 +0000 Message-Id: <20231204124736.132185-2-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231204124736.132185-1-srinivas.kandagatla@linaro.org> References: <20231204124736.132185-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Message-ID-Hash: VYRGQV63PEOPVL5LSHNLJ4RK6CLD3OLF X-Message-ID-Hash: VYRGQV63PEOPVL5LSHNLJ4RK6CLD3OLF X-MailFrom: srinivas.kandagatla@linaro.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Srinivas Kandagatla Volume can have ranges that start with negative values, ex: -84dB to +40dB. Apply correct range check in snd_soc_limit_volume before setting the platform_max. Without this patch, for example setting a 0dB limit on a volume range of -84dB to +40dB would fail. Signed-off-by: Srinivas Kandagatla --- sound/soc/soc-ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c index 55b009d3c681..2d25748ca706 100644 --- a/sound/soc/soc-ops.c +++ b/sound/soc/soc-ops.c @@ -661,7 +661,7 @@ int snd_soc_limit_volume(struct snd_soc_card *card, kctl = snd_soc_card_get_kcontrol(card, name); if (kctl) { struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value; - if (max <= mc->max) { + if (max <= mc->max - mc->min) { mc->platform_max = max; ret = 0; } From patchwork Mon Dec 4 12:47:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 750413 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6C66C4167B for ; Mon, 4 Dec 2023 12:49:03 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 6353FDEF; Mon, 4 Dec 2023 13:48:51 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6353FDEF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1701694141; bh=jcskp8bYdET0mSh8F04wbmedTl0NWod2/AT6Yc2rhOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=IN/O5RCRHCU67Xix26SnijRhZOZuK3ebizaSIGUwLRiB6wphyCAYRRh5q03xp4crk 2BEWL7L4U4lem4u82jSRPitrCkSabvz1IZO8Jm9dQ/5RQxqey4wyJhR+gVRhqvBosU HkOhfIUQNt7oQaAvg1jncszEWVUNBUyZKXin8FDw= Received: by alsa1.perex.cz (Postfix, from userid 50401) id E77C2F805E5; Mon, 4 Dec 2023 13:48:10 +0100 (CET) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id A5DC5F805D8; Mon, 4 Dec 2023 13:48:10 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 86A65F805BA; Mon, 4 Dec 2023 13:48:05 +0100 (CET) Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id AE478F80588 for ; Mon, 4 Dec 2023 13:47:43 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz AE478F80588 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=gl2YUU8e Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-54cb4fa667bso1428260a12.3 for ; Mon, 04 Dec 2023 04:47:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1701694063; x=1702298863; darn=alsa-project.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KY0JnJRKpd3/EUynN0UwcoxBlBhaBotyx7RxLf0wHWk=; b=gl2YUU8eKd9/sbmA84jxibnGat9ZAaxpv4BYp5Js/d8bc1SGFWnrn++i4RzHp/FHie dJcNigfYXwhIZYOpQCYzp/WiHT1/WXJXKPZDknxp/n3F7e5msww1oUBrljXNtE1xkuvl ur2b76Ma9gzLFcD/0zLiRvrF6HRe+biFfZI9mfymLWSpKU/oY/XWA2DJucNtp4ek0mcV 9+QihOPWK5lw5kPcNJEwwqZXQ1/SgPWcxcDNL5P0+4Ko0D4Y9TP/kUXIewv9/jAmUNkL MFL2UxnoSxvdUCUna60jghxbgB16hIalRWeffMNZ5QGR1ED46bS/tRpL5D8G9YUtwZue MfRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701694063; x=1702298863; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KY0JnJRKpd3/EUynN0UwcoxBlBhaBotyx7RxLf0wHWk=; b=NALp1zainczZ9PoUd92Tb0faP7jvP+14hPThe0UDszizdqg11ECTYO17bggFK1aHhq 7zIMilXoJMXtZvmg616FlXD863PmEUaVj4lKktfDBSptjQlYJtefwuw4vSDFwr8N0mzv kl8rHWyaD7iuOihvrsp/u8Aj9P3dMqrpPgFrHqy9LumaLhyQb0ieU/3LR/NV5ysH5LBu dhC83dsZQ2/yETXaGqs/IS3xJwAf3U8X8x4y9i7DBa8QuxLdeoAR49XSaReBe9W1uZ5Z jvvBH50IB8XQ8CrqBv694IX7wb6ChHyNoJWz8Xpfz+RNBL0ryVajO7dUV3OW0Nh1eaS4 N1DA== X-Gm-Message-State: AOJu0YzDKEvO1dkgFJ4KpSpmzHb2Ww2KGV1X7gVjdAUqWhWjttYouXrT 8+gcXLierVqAu+vKJJWb6HY4PA== X-Google-Smtp-Source: AGHT+IFhu/InStD612XpzFwPv9bBK0nLIg+7JO9nMW2ZvtutTmDe1Q3IXR3v2X7PDbYWSph/4G/iGg== X-Received: by 2002:a05:6402:17dc:b0:54c:a21b:8088 with SMTP id s28-20020a05640217dc00b0054ca21b8088mr1192577edy.63.1701694063127; Mon, 04 Dec 2023 04:47:43 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id dc15-20020a056402310f00b0054ced65bd26sm457017edb.41.2023.12.04.04.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 04:47:42 -0800 (PST) From: srinivas.kandagatla@linaro.org To: broonie@kernel.org, alsa-devel@alsa-project.org Cc: perex@perex.cz, tiwai@suse.com, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, johan+linaro@kernel.org, Srinivas Kandagatla Subject: [PATCH 2/2] ASoC: qcom: sc8280xp: Limit speaker digital volumes Date: Mon, 4 Dec 2023 12:47:36 +0000 Message-Id: <20231204124736.132185-3-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231204124736.132185-1-srinivas.kandagatla@linaro.org> References: <20231204124736.132185-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Message-ID-Hash: OEGD637L4TX2OJFIHZHLDGPUMCOKZVUO X-Message-ID-Hash: OEGD637L4TX2OJFIHZHLDGPUMCOKZVUO X-MailFrom: srinivas.kandagatla@linaro.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Srinivas Kandagatla Limit the speaker digital gains to 0dB so that the users will not damage them. Currently there is a limit in UCM, but this does not stop the user form changing the digital gains from command line. So limit this in driver which makes the speakers more safer without active speaker protection in place. Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/sc8280xp.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sound/soc/qcom/sc8280xp.c b/sound/soc/qcom/sc8280xp.c index 249a43e1dee3..1e8f9452cd28 100644 --- a/sound/soc/qcom/sc8280xp.c +++ b/sound/soc/qcom/sc8280xp.c @@ -25,6 +25,23 @@ struct sc8280xp_snd_data { static int sc8280xp_snd_init(struct snd_soc_pcm_runtime *rtd) { struct sc8280xp_snd_data *data = snd_soc_card_get_drvdata(rtd->card); + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + struct snd_soc_card *card = rtd->card; + + switch (cpu_dai->id) { + case WSA_CODEC_DMA_RX_0: + case WSA_CODEC_DMA_RX_1: + /* + * set limit of 0dB on Digital Volume for Speakers, + * this can prevent damage of speakers to some extent without + * active speaker protection + */ + snd_soc_limit_volume(card, "WSA_RX0 Digital Volume", 84); + snd_soc_limit_volume(card, "WSA_RX1 Digital Volume", 84); + break; + default: + break; + } return qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup); }