From patchwork Thu Sep 3 15:32:13 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 4834 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id AC8D93F0E6 for ; Thu, 3 Sep 2026 17:38:56 +0200 (CEST) Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-499b99a8a10sf8813495e9.0 for ; Thu, 03 Sep 2026 08:38:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1788449936; cv=pass; d=google.com; s=arc-20260327; b=ig3bU39OC8uimyVTgNJKcms2bZm5Lm2WYRsSCiLrAVtWDtwGWjMi+Uw60OxX7eL8f6 pL6/senZfgfVzcqnYjM8yn7KT1jKTsAEU9EmK5IGjNhbSAbZGiNuTKwkAqX7FzLOymVX rOWJPLEPNE1MGVfY5xTKI9uBKQpehitIH/ByncxkV8Lh4e6c5py4MJ4sGVau6O8PLxQU Z1ttPYhxP6YTQndeSfKEkTNXYQXdXiz3THYVOa9h78osEGxW+QJ36UrXAxdz4N8tIRi1 iUnXJOkdoj7KBMsSdtIUSTkKZqFNhzi9NZKprBSCXNSIO7MOWJqjvYViZ7hlf3qPdsLB ZAbg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=n7nM6brmD4YUksdHJS2gnMAxelHWMJCOzJoMjT3JN5g=; fh=hVn3O1SZFzGR3ByOf2Udr/9evj8eJ9KDsqFo+UQT35g=; b=rGsLIpsCCJsQ3oQ24PO0qFUawaA2uMxasW1pKZ5QTprH4VC90eJnu9S2/NaWzEU5Gp s5E8E5VlOreWqCcfjIfjJVHiywL0+RDqWjtuA5yAZrR86081PeIivBvnSFc2GWYooZzl InN0qectIOl/UDKtoIWe3YWEwsWjGi8uB8G+jyp3NeqJuJBTZn2oRQB2J8pQjwjb9Su2 Xrg3WsZ2GzTx3MjuvZ6YNSyx9vdaMKMJgsZbrkd1FYg4QD9AoXw0z4dy1Nh+L63PaWJU GPMkkmYALOABRtzsbbwgYKCs892nkeZwRfL9iODuDy/roqWHT7bIazJu4YQvDstJ+IMk v1oQ==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=QTcpBA0Y; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1788449936; x=1789054736; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:content-type :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=n7nM6brmD4YUksdHJS2gnMAxelHWMJCOzJoMjT3JN5g=; b=HaX05vYkmpChpS+7Lh3u/TF63Smk+r5oA5YgF4I5ZJDKXL86Jkd1mTpqUBP/qDPWd/ RO2WoUoN/Oh6yvrYn0gUIMSUq6wULkGI4YGJJm6Yo5hvw/iJZGbQMCLI8pdzZDuC5IPT GZpy7E/6sOD1xJEm8R/a+rScV40j2S72LGreI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788449936; x=1789054736; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :content-type:x-original-authentication-results:x-original-sender :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-gg:x-beenthere:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=n7nM6brmD4YUksdHJS2gnMAxelHWMJCOzJoMjT3JN5g=; b=DcHUauT0fy1kdjGFf7CpLQtnw2+dqeE178vAMpF90dCwd7z37EbIFDesuEK1Ct0XGr ukcr56eQ4p/26QB3U2WYzzNdWJcN8hQr1c1cqR0WmIUjoeXuJJl5Drj3F7VwZr+iVHlm 1Wr+QDsRPyk3szGGrFeatVq2IlHQJQUYpUSGkPMatSrrupUAPe+PK4jJcSBTvqHa+ssT Fm6y4y4J3Q7U+i7exg6ITQ/mhUBwt703hbJQ/7ZHT63dANK52W6ESsrK5dSeOaT2KOpR kJt0QGi1WBzLutqdrGMrcCfHFu0WjOAJHYfio8Wot9ZnPvyOFqo/BLmJoO+PrdMJiCKb VnSA== X-Forwarded-Encrypted: i=2; AKwUvBze7MCanZybakzaLoPZ7EwcolD5edqEJJPsuXpHAWBMFB9lRJjq+pBm/aS1y0821gxKcb6tphlCwTY2QN8d@patchwork.amarulasolutions.com X-Gm-Message-State: AFuF++n9TpQGMxItzKePNyPY4bXh6P+DDTwQWiOc94gqsgQ1NdbxXaxb mKQFF26NCaeC5xG3B4hniYTUn9oBV5OPZdS/NoWcrroT7KLZEdHfPVQHEF/cN77iH7gnkBueFev EEQ== X-Received: by 2002:a05:600c:46c6:b0:49c:799a:177b with SMTP id 5b1f17b1804b1-49cf1576df1mr45685995e9.2.1788449936146; Thu, 03 Sep 2026 08:38:56 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com; h="ATskLdcmMO7yo2VQhvUH71YvRxMfecdaqSzFH4yLKaatMWBp5g==" Received: by 2002:a05:600d:a:b0:499:d480:ced0 with SMTP id 5b1f17b1804b1-49cee32905als3752045e9.0.-pod-prod-00-eu-canary; Thu, 03 Sep 2026 08:38:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvByX1H0ycJ2NqLsuXV94EQpeVkwGg0+obQP/TL8QYTmPWckeziWrDaWKtG35BKPcAh2jvGx2NhHsW0Bb5m8u@amarulasolutions.com X-Received: by 2002:a05:600c:1388:b0:49c:eded:44e with SMTP id 5b1f17b1804b1-49cf158e77fmr45406705e9.7.1788449934383; Thu, 03 Sep 2026 08:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788449934; cv=none; d=google.com; s=arc-20260327; b=bMdLI3bJsLywfevxmRNOtxl+WTRY9esMLfWYjUaGIpu3zNdjQ2EEGMZtZnRe2V4LFh 2O7w+pJ8AE+eB+C7pSIq0fyr5eHxbc0E6yoc0uJ860mZ0dQ0LYLXloUGyqLO4MIgyyxH MsT1PPOmQRt+mu3cJsPTC651DSiZapeEG2ywi87N4RjycB7E/G/xsONONb3LOwW+CLIH 0n+MJCscBemDZygcmYMdKwkGVaG40ebIavUArSQNMQ2c5laoyXbtjARoPDn4r4/Zvscf 7F+fF5PlLwmbaiJaRMWnG+JFCGTnb9ZA70zIpyluw3g/C8c6oBlAghht0r3v5Vw8Np7A adTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=0o+HCmOQx9XAtsX24zUFSwjZJzmYz+uo9CE80R3VvZQ=; fh=qD75TUcM+OiA69oMg18yG9zIgCmpDBw/od9eEWRT4E0=; b=JUbIDCFAfJNyBOd1/iMlUolbdQMYPoIacS0wynTGB60amsw9LSUF3dVhvNchvu2lEJ LAM3b2UNoqxkDgpw7SkRLLFtPzfRlMsvuMM5PMY15xVO1QfpkT/3sjOaYG5zl20iPK+g 0lVIMKUDuQXABjqhYc6aU895EeRNmcor9WZAoXuxaCKGlk+be6gE/5A06T0nisMAQcbv bTor68fRuRrY31yT7tY6meoXZ3OS9DCVlmT3NHVGsSdHxUw8mYMwkvBV44fcFTVUTI1o ysr0tdsRHF5Uzi29/TRgjNNjQKE64wcmid9bK77WhordhCP9WldsD29xigRYZsWMUCYO gq8A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=QTcpBA0Y; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 5b1f17b1804b1-49cee6051bcsor3263235e9.10.2026.09.03.08.38.54 for (Google Transport Security); Thu, 03 Sep 2026 08:38:54 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Forwarded-Encrypted: i=1; AKwUvBxObVIjyh8f0KxXKmAIDywoh8BgilBBe90pTGFPCqQYH6PZdtZ3tv/h8LOOXSgEtfxC/U+5pt7T7PH/8cnA@amarulasolutions.com X-Gm-Gg: AYBFou2k4pervB+yQIhpEvlHTALoKpMlfExgBp5LwXC9bKJn/lVhcW2AKiSJJOm1yQ4 CuWpNbrXtcDbeoiSG1ERgRP4UV8slGNfbNX0oVDtmdHg/CLdxG1K6HT/uXzu3Fbm7QUvCsKtlK8 9SdDK0XWG84xasWkamROwfoG/6vbQWNFGOsN+EFYwiamG9pah1PgiznqiIP7/ZY9oMcRatafwMm h7y64TxqeUyDCN9mgGiDGgQ4td/xO/1RW20lgu2RxMvEnfLiO5xpeVaR4Ib7oOEgjECVZMpEFgj oMSoAsgjho4jYdBOP+XAdrZALMSTvNAPvo4VwJZ5TJKIwU3FZRUeSsQsvs1fGucyS5lWSWxQwgJ pcC7fXfs74hfe2218zXboTRf0ife4djdWNusT4t57h6YmykMMVo/+tKyUJOrMtcbPsoecljYATT pwN4BBaRrmBfMHfjDyNTMgnqYvURoO6+/+F1uCLZYMV73h12biPyibaRjnAZF3mywOqC+NondKR 9f1T+vTjI8eeTccgr95Tt5N3eBLWjV9uMTxn6eQJWCwaeiLRDJUtxGYAv0DA6ZxJBRWSbqIufCH KLMmp0c/JQ6OmYTCpM/WWP0B+7/6Ne27Su9bmjLkQ2CM6hc/GCfnWSNC3re7QhueP+o= X-Received: by 2002:a05:600c:46c6:b0:49c:799a:177b with SMTP id 5b1f17b1804b1-49cf1576df1mr45683825e9.2.1788449933923; Thu, 03 Sep 2026 08:38:53 -0700 (PDT) Received: from dario-ThinkPad-P14s-Gen-5.amarulasolutions.com (host-95-245-93-90.retail.telecomitalia.it. [95.245.93.90]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48448e72df2sm15366301f8f.1.2026.09.03.08.38.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 08:38:53 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, linux-amarula@amarulasolutions.com, Dario Binacchi , Sashiko , Peng Fan , Brian Masney , Cristian Marussi , Jerome Brunet , Sebin Francis , Stephen Boyd , linux-clk@vger.kernel.org Subject: [PATCH v13 1/4] clk: scmi: fix SSC spread conversion Date: Thu, 3 Sep 2026 17:32:13 +0200 Message-ID: <20260903153836.373267-2-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260903153836.373267-1-dario.binacchi@amarulasolutions.com> References: <20260903153836.373267-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=QTcpBA0Y; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The spread_bp field of struct clk_spread_spectrum holds the modulation depth in permyriad (1/100 of a percent), as documented in clk-provider.h and in the assigned-clock-sscs binding, while the i.MX SCMI OEM extension expects a value in tenths of a percent, as pointed out by Peng Fan. The conversion divides spread_bp by 10000 instead of 10, as reported by Sashiko, so any valid configuration is truncated to 0 and the hardware is silently programmed with no spread at all. Divide by 10 and fix the comment accordingly. Fixes: 77369b1e6a37 ("clk: scmi: Add i.MX95 OEM extension support for SCMI clock driver") Reported-by: Sashiko Closes: https://lore.kernel.org/r/20260901155657.6A5981F00A3A@smtp.kernel.org Reported-by: Peng Fan Closes: https://lore.kernel.org/r/ZR6PR04MB375776A27E98F140534E8F7FE488B62@ZR6PR04MB375776.eurprd04.prod.outlook.com Signed-off-by: Dario Binacchi Reviewed-by: Peng Fan --- Changes in v13: - Divide spread_bp by 10 instead of 100 as requested by Peng Fan. - Rename the patch title and reword the description accordingly. - Add the Reported-by/Closes tags for Sashiko and Peng Fan. drivers/clk/clk-scmi-oem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk-scmi-oem.c b/drivers/clk/clk-scmi-oem.c index be11d359b4ec..c1ebbdc6bbc5 100644 --- a/drivers/clk/clk-scmi-oem.c +++ b/drivers/clk/clk-scmi-oem.c @@ -39,12 +39,12 @@ scmi_clk_imx_set_spread_spectrum(struct clk_hw *hw, u32 val; /* - * extConfigValue[7:0] - spread percentage (%) + * extConfigValue[7:0] - spread percentage in tenths of a percent * extConfigValue[23:8] - Modulation Frequency * extConfigValue[24] - Enable/Disable * extConfigValue[31:25] - Reserved */ - val = FIELD_PREP(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK, ss_conf->spread_bp / 10000); + val = FIELD_PREP(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK, ss_conf->spread_bp / 10); val |= FIELD_PREP(SCMI_CLOCK_IMX_SS_MOD_FREQ_MASK, ss_conf->modfreq_hz); if (ss_conf->method != CLK_SPREAD_NO) val |= SCMI_CLOCK_IMX_SS_ENABLE_MASK; From patchwork Thu Sep 3 15:32:14 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 4835 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 6C9393F0E6 for ; Thu, 3 Sep 2026 17:38:58 +0200 (CEST) Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-49b0d7a07acsf27906855e9.3 for ; Thu, 03 Sep 2026 08:38:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1788449938; cv=pass; d=google.com; s=arc-20260327; b=lyTEOTJBOCu2vjASoh0kLn59CZvK4PIuVNmTQj267MEFTuqHLhXoz3dQt+yTDnwV24 h6g72bg9/Spx8vqK7oxHiCiGcTeSH8NibkWCj9jj/siwzCKJWEFQJgkYbdm53zvM7I54 DAXDJPnE3SqYkU3BYDKkumuRKg7wDaLgx7l/JR8SK3Z+PE3XXZlesJphHHYXbI6aWQbI TziGO9dVeN4vm4tU9BerCdecMxkRzjTgKEm/2rAQqJlgRI6Df7jCqpJuGq53uavA6TyU bfDYNrCAN9eKNVdwZRpK9ASm8lQZwC4maG1SPGgLY5WR/lKIZ4zydjWiHpZTR0l2YmTJ TsSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=FUGPljnPGyGjm9qSRMzQKA5zs1fmKl/g9j5yxyPnY2Y=; fh=xjMXdK3vAib5rBYnuoK6iRvkjDQ1M59EqtrxUfx3YlE=; b=r82LxfSWYiPacWDBvaZoaPj9rOAz8mRXdGKbzJ7BPmOliOjRT/U8+tZG1EYNu3Jrjj 84OTBLKP+ccEEL9nu3QbqTiA4SBjmrvD3T+wRkWktIFimScsBbLzSqpTrA3NsrYEAKf9 nPdWgks5CMV91k/KzMulfpvpE0/lAZUptXI0MqE5BOc9xQMwZI9SlHmszDmaKKZgyG3x kc2yQ5AfIshhebNIV/n31ArqiOQTnX9+0+/00xEsGvt/DSabMyAXN7qLT5WkrkfmoYLd UJeDUJsKiNK7WcUqw/q2CCceQGIADsvWRR2fNHGwJ15HWA4KTC0aoUoSegNyZRgfZODz +W+g==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NFqX85tp; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1788449938; x=1789054738; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:content-type :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=FUGPljnPGyGjm9qSRMzQKA5zs1fmKl/g9j5yxyPnY2Y=; b=hn7s7U21uf1x6rNEmH9mA44rumzymAiY+o4RZKu1EXtqLv0vrJEvP6zRtPucBeYSFb V5/V1YiMw1WYINhs3DFGDdzafrdDYh6NlPiSeqY9NUPkJYlaP7XhSGdhb3nlYW2j5Vqb d5fPDU0tn6S1O0FfWfeavWhE0fSU+8epuJXj8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788449938; x=1789054738; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :content-type:x-original-authentication-results:x-original-sender :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-gg:x-beenthere:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FUGPljnPGyGjm9qSRMzQKA5zs1fmKl/g9j5yxyPnY2Y=; b=B8qodO7UswX8wXv/0g21VQOV8z9d0e9FUf0P3hAUdnGnXRs9Kq5uFpBQdELfFP8G+p 296Ze4mMUEUPf8rh+fHeZt0fjRfLed0oewgRkn/vpi9U5F8P4h25mgNDQJXEgMem6uH7 aS4y858Sy27zeNaxqO4U9CF3U/GYtdpfsBT6iOUSUDDQQXU5Oi88hXh0eZHr2idWpi9R 3hYsA9GpCIx9pNA1K8CeQbJRgw82oUe5WUkorTKbZviHOAdDqYmatMdFSCnesdZQ1y/z WaJx6yZKF2IwPbMTAHmC+5kk3oe2O9hjsNUppC9L9bDsjo6GssPPrNV1w6yG+GPUNT8L hW9Q== X-Forwarded-Encrypted: i=2; AKwUvByUyhC4CtSRUnjYedV1iKypf6CBuFtjL0Bt4pFGIV6rf+CvY4/rh/XYqKvoGo9zTrgQC67EaMsywbLi9TQv@patchwork.amarulasolutions.com X-Gm-Message-State: AFuF++km8BjPTa2aQu2u7z0LXrJYbhl1e8AwO6TkeR+3K5nXy6HzaNAn xdB4mMwjLYw+h78T6HbrALuO3Sutd/POMDuv6rWZp8jSYY6rriatHkfaDAUMP7nHBXiUrLz/6dO z3Q== X-Received: by 2002:a05:600c:4e03:b0:499:60bf:c6f7 with SMTP id 5b1f17b1804b1-49cf5be1652mr17508885e9.13.1788449938047; Thu, 03 Sep 2026 08:38:58 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com; h="ATskLdfv/xTEak3o54K/OxQM/ljFdMAfOZs/aBtQyUGmHUgWwA==" Received: by 2002:a05:600c:19cd:b0:496:b3a3:20bb with SMTP id 5b1f17b1804b1-49cf6613375ls430905e9.0.-pod-prod-09-eu; Thu, 03 Sep 2026 08:38:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBwMQbROorBX0y0fKJqZCKQNftICcPVxQbrf5dbbtB1aXr+zGGUJCk9UFR/HawyfxFONXkpx+YE7LUQ4qvg+@amarulasolutions.com X-Received: by 2002:a5d:4562:0:b0:484:373b:5f12 with SMTP id ffacd0b85a97d-485860c48dcmr2198359f8f.24.1788449936324; Thu, 03 Sep 2026 08:38:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788449936; cv=none; d=google.com; s=arc-20260327; b=II3RFpJBxf9zjAx7ofVydMf00OTnb3npWxVp4MDWW1N/LikSB5KNOH3inPSTzwj6Ob BlXPOzXpFw8REQV2M+RSEE/nehjermUU1aueJmu8smDVWlEulTF1X98TMbYwu+KBn1wi WYvHWeDeAnCfdoI7WjHUAkFmHJscAxp6GcXZXvLYyEUdN604JC6VVtZr7KY1ANFsiPnE WK5vgPXPR/OAzczD62ImBB+KZM2uNmZ88ZVVAWfFQtAEl0XBSfXbjKZZkhVGChyvv6ve FKB+z7Xvx2iCWV8ubbXPzga2B8gv65N/1KIyamE/noPJtyHBShz+Ramm0Q3bXZmBrrhx emzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=f1yqnW0S/sSBoLbGGpdBGirLwApxYqu22jjVHzyaFhI=; fh=2FkePlqUjdQJsmMhHm1BWwQFnKCMemt1aWLqiXq9eI4=; b=EWa+QqihQ4UfOfoGbH6KRpeT7hw8bDL7svtGX4z2yoepKZ2yxKAXr6p/svFeqi2fes Cd4fDU2kbrDQrhYhfn1URylFN4eWthps6Mw4hbjO/Glwu2rBqpaFUZr01Fq9cKb1wrWD CDWpf+IrjYwrNwWIIxGQ1Vo0j7hNUSWhKuhJZUevefNNGWjyceO7AdxZKrWdC5Kntujg fjVcofzkB9vR28tFvH2Fw0l/lmYnh4dCSGNY7Gxdm8SWhUd8S0byJ54LHtsTxHfoP6C3 KhspPPJdFnEiWGo+O2wOmlDTe0x3ON4aq6JZ0KMktKezXteUq23AGelDiEmIjX5eGJ2c WBwg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NFqX85tp; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ffacd0b85a97d-484494cc9c2sor1178249f8f.19.2026.09.03.08.38.56 for (Google Transport Security); Thu, 03 Sep 2026 08:38:56 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Forwarded-Encrypted: i=1; AKwUvBy/v/+emTsmbzsF/LsZ7EG2eiee34R2qeFGz/pOXuYvq9gLjSnasCtIDkPGwTeU+xx5noN/In7tZN1+LgYr@amarulasolutions.com X-Gm-Gg: AYBFou37rwmo62cuzQVEy1htefKMpZG4NFtlaeXX3xpD0VsHXvG2/vpRTDJVcfmom/F 6rSQyCSztzBPbJAA/XRbjcnhPLOjDn9bVVves+GWTgTOfJ3SRe1W15enWmB0kWgNcdvyDVKfk9Z IpGK8d3Fgv3LIuHxOPapE0uE5XIGhjUAdTJZoZ6yZ9Pj70gDeg7ZlFz1YkXuIT3i7hgRc17ZqvP PHCXIaBMTVFPQd3s4KRUS1mqaIo9gq/R1Sg/393AjpAhP0tqab8cQ/WWZAN1bZLqOWDA7Gc9K1x dZ/m4rx3U+nRicHdncCs0Cq6Gy/ZNLvHX8xmwcSSKAw8bOcHdb+ljle11yO9b/VxE3vjSv7XyjD K1BMfIt6b/VC04jGOuajZn7+ito8KssE3Rj+xvW1Au5Wur+rTcVGaifhyWJmlARLwrfLjbrJNRS pxxCNCnnih7v2kPMSv/X82h3kmsKx2WSsFNsfxY8AkC8tyGWn/rcSoKuvL1+B5iCbFQ0qFjwdQO f/H0lC2B4JJpmgHCBbeArzwzhT8BZ7dJ5QD+B/MGF5DoCHFfi9WPbZvq4jm61AHNqT39eZOldNB QRLEqKAdVBhmaA7G2GUPjZmmOHsgxDFfw9gshxiCwU49U1UihJZIkgE= X-Received: by 2002:adf:e3c1:0:b0:485:847f:fd82 with SMTP id ffacd0b85a97d-48586034408mr1988754f8f.8.1788449935865; Thu, 03 Sep 2026 08:38:55 -0700 (PDT) Received: from dario-ThinkPad-P14s-Gen-5.amarulasolutions.com (host-95-245-93-90.retail.telecomitalia.it. [95.245.93.90]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48448e72df2sm15366301f8f.1.2026.09.03.08.38.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 08:38:55 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, linux-amarula@amarulasolutions.com, Dario Binacchi , Brian Masney , Jerome Brunet , Stephen Boyd , linux-clk@vger.kernel.org Subject: [PATCH v13 2/4] clk: scmi: reject SSC configuration out of the OEM field range Date: Thu, 3 Sep 2026 17:32:14 +0200 Message-ID: <20260903153836.373267-3-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260903153836.373267-1-dario.binacchi@amarulasolutions.com> References: <20260903153836.373267-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NFqX85tp; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The i.MX SCMI OEM extension stores the spread in an 8-bit field, in tenths of a percent, and the modulation frequency in a 16-bit field. FIELD_PREP() silently truncates values that do not fit in the target field. Moreover, the conversion from permyriad to tenths of a percent turns values below 10 permyriad into zero, which is then passed to the firmware as no spread at all. Reject these cases with a warning instead of silently programming a configuration different from the requested one. Signed-off-by: Dario Binacchi --- Changes in v13: - New patch drivers/clk/clk-scmi-oem.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-scmi-oem.c b/drivers/clk/clk-scmi-oem.c index c1ebbdc6bbc5..4dac608edd4c 100644 --- a/drivers/clk/clk-scmi-oem.c +++ b/drivers/clk/clk-scmi-oem.c @@ -35,6 +35,7 @@ scmi_clk_imx_set_spread_spectrum(struct clk_hw *hw, const struct clk_spread_spectrum *ss_conf) { struct scmi_clk *clk = to_scmi_clk(hw); + u32 spread_pm = ss_conf->spread_bp / 10; int ret; u32 val; @@ -44,7 +45,19 @@ scmi_clk_imx_set_spread_spectrum(struct clk_hw *hw, * extConfigValue[24] - Enable/Disable * extConfigValue[31:25] - Reserved */ - val = FIELD_PREP(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK, ss_conf->spread_bp / 10); + if (!spread_pm || spread_pm > FIELD_MAX(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK)) { + dev_warn(clk->dev, "%s: spread (%u permyriad) out of range\n", + clk_hw_get_name(hw), ss_conf->spread_bp); + return -EINVAL; + } + + if (ss_conf->modfreq_hz > FIELD_MAX(SCMI_CLOCK_IMX_SS_MOD_FREQ_MASK)) { + dev_warn(clk->dev, "%s: modulation frequency (%u Hz) out of range\n", + clk_hw_get_name(hw), ss_conf->modfreq_hz); + return -EINVAL; + } + + val = FIELD_PREP(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK, spread_pm); val |= FIELD_PREP(SCMI_CLOCK_IMX_SS_MOD_FREQ_MASK, ss_conf->modfreq_hz); if (ss_conf->method != CLK_SPREAD_NO) val |= SCMI_CLOCK_IMX_SS_ENABLE_MASK; From patchwork Thu Sep 3 15:32:15 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 4836 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 5502D3F0E6 for ; Thu, 3 Sep 2026 17:39:00 +0200 (CEST) Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-49b7c1dc61esf23756985e9.3 for ; Thu, 03 Sep 2026 08:39:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1788449940; cv=pass; d=google.com; s=arc-20260327; b=VXljeLaFfcQI8AA4r5l+uu+0wxzgJss/o5i/pPPjd2bYaOHicsPJr73uVNKjKtRjvg scGM52w9otQkrRGiKhv7JSMRhogM+2RND4Sfh/htud0w00PjrMwMSRdlCrVZhUmC6aQU JrJpdtR4gZMxkD4FWULA6kf94pBbXHieBux4o1h77dZEncCiAgznbD2LzqcOnu7i1zkM jnKjKndzeajXNN5PcD17dJQw3XyKHyAyF2B0LPtnEsBfnl3pFs+MkQxUFD/IgchQ5Syd ZwJ+7IKVLxwOlmfzVj5UGC4PNK96rnSEBeKg01qAIGNNjuzUahL/G90hbXDjGV+SYNs+ SjtQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=p5qSQsPBLLFODrAy6ZtqVyxV8UOB5as2nkUOwBUu+44=; fh=LYs/sQNQGMaRVXI8iTYb4pvRUm602nKYLzkKQfXnGXs=; b=jat0aIm54gBQSZOut5EGihcpeCKzueQIh4Wmo5FCcvVxVNpKKKJ/07+f6GKfoWL9hL IpwTl694Svhd63iWu1XcO0UslAIJue9ktONGZkS+SZkfHzi3uuc2x/wIGi/Syx9uPxCG ln6dbvtUBgqueQQ0aAI9aD5A9PX1aScJqCAK3F7mb95GeXGOEQdJ+wuv0torh1bxvkcL AXbIRo39KPS0La8XB+iRGbqgv8/QpR6ZGm5v5oyOKtiozF8jzy5FZxLxsAkmMsTqzo6N TwpfH+PMFksb8xhNM44UYuoPYdZU6dm2vzmoHaNN307llmVN3aEfPtySFmezHNg2yhgd 3U/g==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=AVbjKfz6; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1788449940; x=1789054740; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:content-type :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=p5qSQsPBLLFODrAy6ZtqVyxV8UOB5as2nkUOwBUu+44=; b=LohJAw0bw0PUCtT3FiTuauLPstPfDlkj8cx28VsbryOY13Fqchrp/NoAObxqhrWOR/ n7h+aK7WbtRWVm3ktn4an/8WGNKwEAd0z8ydxfW02mVqn4Zo8xAo3FYjCwdohx600iEd CDU90HMkqI9zY7S/sWv0ja7af4ARurnofhc6I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788449940; x=1789054740; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :content-type:x-original-authentication-results:x-original-sender :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-gg:x-beenthere:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=p5qSQsPBLLFODrAy6ZtqVyxV8UOB5as2nkUOwBUu+44=; b=GiSTx0vivIU53uNy2Zej3IcFP1VauBV6wNnh9ug1ox61s3rmSekWDLMQkEG+PnOvym 9kGNIVqD0cjFalQ7e+MQHIqGMaw0CFl4FqrRuBbKhaBx73XoAMns711+J67NhnL8w2lD HnMOu3B9qSHceCxYP9Enb//WLyXofoHRW8WhFgRwInfrXCOcdVOc+aQywWidZh9KJ7xr r8KSLg+eJWpMjii/09CxJCCPO0SXr3xZzPsG1r7coKBzwcmdJ/dgMs1zzdYGyce/piSv 6x5uWGxt374fmf+kEhNfTIrnubKNlmLKupmeRBpMWO6RZJThUm4j922r2wcIVXUPR/6/ IFeg== X-Forwarded-Encrypted: i=2; AKwUvBy3twS0/zG96eZlrpiUmVAUIuCNu1QWBAyfVWwBpR/+UrTb8eugK/n8lQP4LBFSEi03WG7MMMaoICAwwClO@patchwork.amarulasolutions.com X-Gm-Message-State: AFuF++mvOoffaaDOcjpMQfL75NidefeT6btJ5MqxobVFgrTWWKoQXZxB e3A53++vGrdstzY2AcZCg/mLghEjbbsf65rWHlztkA83pHE5+jamoiUNmow4xXFxwV4Inw== X-Received: by 2002:a05:600c:5489:b0:499:4e47:eaf2 with SMTP id 5b1f17b1804b1-49ce58092a6mr210606505e9.6.1788449940034; Thu, 03 Sep 2026 08:39:00 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com; h="ATskLddI9rW1ty39bsg5VifYH7/vMiIRPZCY5HJFO95Br0XgSA==" Received: by 2002:a05:600c:1c09:b0:49b:91c2:4f05 with SMTP id 5b1f17b1804b1-49cf68794bdls145615e9.1.-pod-prod-03-eu; Thu, 03 Sep 2026 08:38:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBzs0xyvmv+CTWJQ3k0k4ed8GUsoETbITkrQvGbeDT4n/yfN/KVUjYOTNebbnAVqwuISfsj2CeExE0yj43fd@amarulasolutions.com X-Received: by 2002:a05:600c:a318:b0:49c:f516:1cd0 with SMTP id 5b1f17b1804b1-49cf5161f4emr50413305e9.10.1788449938633; Thu, 03 Sep 2026 08:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788449938; cv=none; d=google.com; s=arc-20260327; b=UnsfowbZP8A1GMVqBQjoUhkUBJnw6x46lKcIuMtGlsiR4g/d3daByfgTOD3RRv8wsV l9VCqgVKTPuXkrKA4uvX3Lxw3CNrpNNH01OVgocU0svaw+93ladrhepDntf1H8zfeC3i /lTHCxmtNJHWGzlsYEt2IByoKq0PNigRB8WoZf+s+n23MEs5WIyt2Ejiry+qUgSeHs3B 3+V0H1+0NdKP7D7qwa9TyeuOltONnBJthTavDyT5PbGtHjcJt+I0xrLsId5TomHHrpPF tDHHpNP9GKVVO09TziksLQu5ZA2oR70lXX0HIF3HIIXozZlA1lD/c+iDbzOXgJuklHBW aLkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=waRfo/eMT+qYYnkf6SXoDP5wBnkJd2wqce5jm4IDuSY=; fh=YsyBVP1PhCE1lD9OEhpKeERMbK4rhPqOKuev2hEWX0Y=; b=SPZxA7LjQyGiivd9Ldt0PstiIaO3Rc1HG6YWWEZKlb7NuCEWcydcv9tiu0IWP8HeKV KScMqp9zNKoMPpKYLl4C5XmsoNLdoRDwopJ1gKMX1KkcqExLlQ4pyQxPsfqnJ3WehA2d p5FxLMPESSjuvP8XhZCvBevFxA2B9WPc0d5DuIREK4SiOh0SlS8cEmX8pxgQIxFZF4f6 RZtolEkYB3uqiSfIELqxRkd/gY1vMfbGb+BlR1FQEab+/hxbYd7Fo8VgO0vqcpU2fk29 A+sHRsZwDLhvkuzE8Wd3lKeL3+WfJgm6nlnF6v0l+cRlIi4FRVOVYG47DSHj4JkIzPp0 Nw8Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=AVbjKfz6; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ffacd0b85a97d-48448e7ffb2sor1065462f8f.6.2026.09.03.08.38.58 for (Google Transport Security); Thu, 03 Sep 2026 08:38:58 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Forwarded-Encrypted: i=1; AKwUvBymHe2LrNrB0DzCHDyPIyMgxsTgdcsrok9bb2AQI1/m0UbZMyajH4LVHcrgCGkPvO2rEw/Oho+JgAGGw5TT@amarulasolutions.com X-Gm-Gg: AYBFou2LL2N6QEoY7MaZ0Vdn9GCYG7JMdIzrGsqURn6N1eDmZ0P2UTuMaiCry+q0Qmz u+tGO5YpBKuXAquGSnoWaN9WNaWpWs1UnA9MfnmrBQAUpK8ollpUEdnA8rglgrwgt66mtCFbkaB Yqsx1pdVIMMF12DBfZZTw5aiwN07q7iiE3I4DlvdR52P8Kkz0hLQLrxtaBIPvKM98CAZTxNTKE1 IOjjfjRYMECX9ykFYruZ5V/iyKAYAYQQVE2A4FptE8S/hDyIsx9Es60k5T0F968EsRImrkcI1Yn S/r7sdwlmw6XUQl3XTTH1Dyah/gWWGmA1zFNfJONQerj7wVUzlcuOxiw3RGThLxQkUkwaDTSngw X6i/g3MCcQnwlVLCZnVBoGpsxu9zhlFkekI7Z5fRgA8DD6KGNCaViwbwlue7HX/1Z/9H2gm2h+n 2nrpXkuvl6gwWopAaKS1W6jhUz19g7SgzTJBcH4SosIdQ+acwb+UP0H96S632hRc+Tf/E3JvnPi 2k6UzVmED/Pu+2fTimd9PXRIeyMuZu3Om423RJVa2IUVmoqKWtgr/uZh/drJ8pNOEsQQoyeOAKk KZPylQT+NxXcpAZCrRMkA76/HWtJju3jg42R8N/yuiipFUmon7y6MCujT550paPppS4= X-Received: by 2002:a05:6000:268a:b0:481:5b58:c589 with SMTP id ffacd0b85a97d-48488f0e30emr24641045f8f.10.1788449938221; Thu, 03 Sep 2026 08:38:58 -0700 (PDT) Received: from dario-ThinkPad-P14s-Gen-5.amarulasolutions.com (host-95-245-93-90.retail.telecomitalia.it. [95.245.93.90]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48448e72df2sm15366301f8f.1.2026.09.03.08.38.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 08:38:56 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, linux-amarula@amarulasolutions.com, Dario Binacchi , Sashiko , Brian Masney , Jerome Brunet , Peng Fan , Sebin Francis , Stephen Boyd , linux-clk@vger.kernel.org Subject: [PATCH v13 3/4] clk: validate spread spectrum configuration Date: Thu, 3 Sep 2026 17:32:15 +0200 Message-ID: <20260903153836.373267-4-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260903153836.373267-1-dario.binacchi@amarulasolutions.com> References: <20260903153836.373267-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=AVbjKfz6; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The spread spectrum configuration is passed to the provider's set_spread_spectrum() callback without any validation, as clk-conf.c only skips all-zero triplets from "assigned-clock-sscs". An invalid device tree can hand providers a zero modulation frequency or a spread ratio above 100%, and each provider would have to add the same checks to protect e.g. divisions in its rate computations. The KUnit test data for assigned-clock-sscs uses spread values of 30000 and 40000 permyriad (300% and 400%), which the new check rejects, as reported by Sashiko, so fix them to 300 and 400 (3% and 4%). Also use a realistic 6% value for the initial settings of the skip tests, for consistency. Fixes: c86814e70390 ("clk: Introduce clk_hw_set_spread_spectrum") Reported-by: Sashiko Closes: https://lore.kernel.org/r/20260901155657.6A5981F00A3A@smtp.kernel.org Signed-off-by: Dario Binacchi Reviewed-by: Peng Fan --- Changes in v13: - Fix the KUnit test data to realistic spread values. - Add the Reported-by/Closes tag for Sashiko. drivers/clk/clk.c | 14 ++++++++++++++ drivers/clk/clk_test.c | 12 ++++++------ drivers/clk/kunit_clk_assigned_rates.h | 4 ++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index fef87167a60b..208caf60eeb5 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2851,6 +2851,20 @@ int clk_hw_set_spread_spectrum(struct clk_hw *hw, const struct clk_spread_spectr if (!hw) return 0; + switch (ss_conf->method) { + case CLK_SPREAD_NO: + break; + case CLK_SPREAD_CENTER: + case CLK_SPREAD_UP: + case CLK_SPREAD_DOWN: + if (!ss_conf->modfreq_hz || !ss_conf->spread_bp || + ss_conf->spread_bp > 10000) + return -EINVAL; + break; + default: + return -EINVAL; + } + core = hw->core; clk_prepare_lock(); diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c index 1c5c8b7c1f3c..21e62d68f87f 100644 --- a/drivers/clk/clk_test.c +++ b/drivers/clk/clk_test.c @@ -3526,7 +3526,7 @@ static const struct clk_assigned_rates_test_param clk_assigned_sscs_skips_test_p */ .desc = "provider missing assigned-clocks", TEST_PARAM_OVERLAY(kunit_clk_assigned_sscs_without), - .sscs = {50000, 60000, 3}, + .sscs = {50000, 600, 3}, }, { /* @@ -3535,7 +3535,7 @@ static const struct clk_assigned_rates_test_param clk_assigned_sscs_skips_test_p */ .desc = "consumer missing assigned-clocks", TEST_PARAM_OVERLAY(kunit_clk_assigned_sscs_without_consumer), - .sscs = {50000, 60000, 3}, + .sscs = {50000, 600, 3}, .consumer_test = true, }, { @@ -3545,7 +3545,7 @@ static const struct clk_assigned_rates_test_param clk_assigned_sscs_skips_test_p */ .desc = "provider assigned-clock-sscs of zero", TEST_PARAM_OVERLAY(kunit_clk_assigned_sscs_zero), - .sscs = {50000, 60000, 3}, + .sscs = {50000, 600, 3}, }, { /* @@ -3554,7 +3554,7 @@ static const struct clk_assigned_rates_test_param clk_assigned_sscs_skips_test_p */ .desc = "consumer assigned-clock-sscs of zero", TEST_PARAM_OVERLAY(kunit_clk_assigned_sscs_zero_consumer), - .sscs = {50000, 60000, 3}, + .sscs = {50000, 600, 3}, .consumer_test = true, }, { @@ -3564,7 +3564,7 @@ static const struct clk_assigned_rates_test_param clk_assigned_sscs_skips_test_p */ .desc = "provider assigned-clocks null phandle", TEST_PARAM_OVERLAY(kunit_clk_assigned_sscs_null), - .sscs = {50000, 60000, 3}, + .sscs = {50000, 600, 3}, }, { /* @@ -3573,7 +3573,7 @@ static const struct clk_assigned_rates_test_param clk_assigned_sscs_skips_test_p */ .desc = "consumer assigned-clocks null phandle", TEST_PARAM_OVERLAY(kunit_clk_assigned_sscs_null_consumer), - .sscs = {50000, 60000, 3}, + .sscs = {50000, 600, 3}, .consumer_test = true, }, }; diff --git a/drivers/clk/kunit_clk_assigned_rates.h b/drivers/clk/kunit_clk_assigned_rates.h index d7ae5ec2d25b..c5d9f004ee81 100644 --- a/drivers/clk/kunit_clk_assigned_rates.h +++ b/drivers/clk/kunit_clk_assigned_rates.h @@ -9,10 +9,10 @@ #define ASSIGNED_RATES_1_RATE 9700000 #define ASSIGNED_SSCS_0_MODFREQ 10000 -#define ASSIGNED_SSCS_0_SPREAD 30000 +#define ASSIGNED_SSCS_0_SPREAD 300 #define ASSIGNED_SSCS_0_METHOD CLK_SSC_CENTER_SPREAD #define ASSIGNED_SSCS_1_MODFREQ 20000 -#define ASSIGNED_SSCS_1_SPREAD 40000 +#define ASSIGNED_SSCS_1_SPREAD 400 #define ASSIGNED_SSCS_1_METHOD CLK_SSC_UP_SPREAD #endif From patchwork Thu Sep 3 15:32:16 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 4837 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 315C93F0E6 for ; Thu, 3 Sep 2026 17:39:03 +0200 (CEST) Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4994cf6cdb9sf17750475e9.3 for ; Thu, 03 Sep 2026 08:39:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1788449943; cv=pass; d=google.com; s=arc-20260327; b=McRrkD1ghIs+oBxGCpovyJDoy45A3UKoxicuZZGnYCW0gSpjDcfOtE4SeNzvnTF21M xxyf2tkyCUAq7O4hPSvqqRyLvsU/Ir+ZTUKOP4E0xRvK8RNqTdIlxEFf/hq2QK1WYThX hInLTFjMFXlhilZw/2ww8xnK7s7D296GXTydOVI7iqL/lt+MVhMui6M9+jkLa46vGxv0 JnC+pzUbsG0YvBEY+oxSaUTimc6dPoCnigAOHBlqMmD3FROT4saTny1EdkL7d8eYu4TT iizPrj/LEh19tKmUu725TczW3OU4+p3GFdP/TAVKzQh/1/1LEwqPdzajKXgIjy0+HGGS hGxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Y1d8X8uM9FkKm89DOGhCID8lQF7Afpw9NOOSEnYoGSs=; fh=0cBepB90VzB6ZzI0i0NcaB3TClEbr8MQJf2z2X6dR9M=; b=NY2i7/F7MmF/wy91jmyYm9bpfYHrhqi4+ud2tJZxF6ySdl98kT8YsZV45itaRY7Sbs HM9j4ABrT9O4IhA19JdhZ+8zD8l/ObVm6haDPzG1HNHSTcu4Dg4rDIaRRq++rVhuO1wG sRyXoBoWUCKRMf3lOGXhwEvB3fKvS3iwgjFuEyNp8/4T9TOlESqkORPrID02NqHUKBC+ Zg0Cts8DIWL82aPt5jjW1A34CgRdkw/QLmU3W7kmRamAVgCzqASShbAS3JZstypdMZlG AUvVKb7R2DRJQ9tKFwsqQLGyyBI73Q1ild0lMNbEYTf874LV/GisRNrgy2BM8WO/JRvT 02Mg==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=llI208DO; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1788449943; x=1789054743; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:content-type :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=Y1d8X8uM9FkKm89DOGhCID8lQF7Afpw9NOOSEnYoGSs=; b=SOAnsbqvIY20THJiKU6MQL4tKVc7F4+8kYs8OI6eKY1a8cCe7sx2tCTdmCfvkGnTNo zD8WqyI/mpXa9Qq3DZlw3avzH01rRlW72cMxWqqOmqf1Q4+aVnA/HQ9+p9/xd3JqvlzB 96ykeezI+vK329ftmsYVXh+NW9Tts/E2gQxd8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788449943; x=1789054743; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :content-type:x-original-authentication-results:x-original-sender :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-gg:x-beenthere:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Y1d8X8uM9FkKm89DOGhCID8lQF7Afpw9NOOSEnYoGSs=; b=BC/dqoZ3gL4yVUfQqd7JErQVDWChYUO0a9CYatpgXUHL5j0D5N+aJPgcTgyo8sCcxC WCWblgOFPg7064Ch3fhZlmbyjlTOtk2tedkHJU8uWQf2pHUNLrulAiWXIJ4ZhgFn4g7h JJTxypGlb6mni1HvAShrVnZgjNDkgG1R19guJgFQjaXNhzf27SS/2F5i4QwGEDN1xL87 pUOuWGwZ4z9LO34IpNGu77p8JcL961An0Ne7vwGy+q3KrL7Xr3Z+UXBowKStbgL7JRhr TkhESbRV2IxRKoUrw8yaSebooEeTmJxKUGZ0rWXgHDnjv3/UfvIa0I469ODS6mv8SalN XAKw== X-Forwarded-Encrypted: i=2; AKwUvBzXy/91+9TV5Rzx1v537iBYdaMHhm2jeEmeElBruKhh2HDqTozXfTe+tw80D2Y8y8zLXeJ5I/B8SyYIWk6z@patchwork.amarulasolutions.com X-Gm-Message-State: AFuF++mMftKvOHw6uH1TSWtQPbdu9UOBbdynmoQZt38kW+CF4LGy3B1E PEZqnZowAc6LM9H7ruAoflX1tEauOdEclGMMsRoOSTp3XqZp4WsE88Eoe+fcvhtZC/6+2g== X-Received: by 2002:a05:600c:3113:b0:49b:924e:9a28 with SMTP id 5b1f17b1804b1-49ce58163aemr221493275e9.1.1788449942620; Thu, 03 Sep 2026 08:39:02 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com; h="ATskLdetAgq2vwQruveNbdRRiYM4ZxeOPzxS3YgmRorUFK78nA==" Received: by 2002:a05:600c:1d01:b0:495:458f:eb16 with SMTP id 5b1f17b1804b1-49b21771792ls5463325e9.1.-pod-prod-05-eu; Thu, 03 Sep 2026 08:39:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBwnYj5S6VMgKFV0SajvpesVQzVPFpa4Vp4sKb1L/B94FHDr3y1Utj+LSC5IS4eOjx1bvdZrRk0rtR3Db4Pe@amarulasolutions.com X-Received: by 2002:a05:600c:6296:b0:499:621a:2ec2 with SMTP id 5b1f17b1804b1-49ce581635bmr266505165e9.3.1788449940857; Thu, 03 Sep 2026 08:39:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788449940; cv=none; d=google.com; s=arc-20260327; b=APV6nMi9fJ3RAOFIRyYGNvVClYAWJS81XfFSN5Ehn2zZgSYNoO2RQlpBHftmqobKc/ rnmzYc2V8YJS8gBXj2WLriMRIFprY/BbxOZyIiP0ksoWQgZTmeIINHUakRcOFf99pABV 5LDh16h/kJ1u/vQ2RFL3NLQ9aBv4orhxX9d+FP2FwuD1gpwk4R1AT9m3sVOm7aMMn+9A RdeKhxSLDpRyCcjmbewjjpExV0Z2+Z+nF+e+Gmf6gVW/2/s/m9ToBxLtWABvgvOK8rg1 eIzEf1zEEAeJAcomTPQKd2QZACnVKyNWFwvbYwQkv/ucCc41ov+Aeta9o3b7rb5j6Prm 2ryw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=cm4uXra2L9WOBsP9ackTlqi/Ub+9G7ZP+SENv4y3Q0o=; fh=3/gl2SXvHL2zPPV5cecDUeGHr2tCCP7FbSYSYL0ewS4=; b=nyQoXfuGIBQVK3Zev5RSBCQeHSxr391ZIQf4jkBtdQfGYpVd+uK/NbJEJGxT40sZ7r 8NlfIqNARsk1xDtNttaJTx25ZVdXg7rtCYYdZRLtk7aWvDefHHvZk4vsYYQFfjDyZy89 0CrCmYL7tsnSk7Xl5kczMFlLOp4TLxeyNoFo8UZXWwap6M4w8xuX0ewR2oXAvDU0z3dj bcJVh+pzAQwe6kwGS+Z7Syzz0Hnrv9KXwzOYtFrEDlKmyxkfK0ag1/15QH9YRv/8vwne l88yq4xiuye+3rIFAW5TuJNihG9b4gwUmfeQaQFOBO5POe7JKTTs8yIGyubCCjELQVic cBAw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=llI208DO; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ffacd0b85a97d-48448ed578fsor1044901f8f.13.2026.09.03.08.39.00 for (Google Transport Security); Thu, 03 Sep 2026 08:39:00 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Forwarded-Encrypted: i=1; AKwUvByKCnDumrSF00XLzoX1HN6lSRHH30JhkwUoBZudoLcHR/cp007Ci0kzwXD6YMsd2mCPvUReTGtjsMf8YLXq@amarulasolutions.com X-Gm-Gg: AYBFou3Y40i+cSgnkDselVjRXgJ6jz2FH4qrldh0nI0pNuWTyYjhknB7r7JK+QiXs3K qGNSaxzzKT/3VdJ9H7Dtt11paRBVkY5IJ3lUbdo+A047pm6p7Y0t8nD9Zi+BZqJshKH9tkF+ZHv aT/aYMGj777fD7FXy0COueRtoHQyFJ0np/4TUqflMhnQJA+jJsFYxJIDW60Y/+JA4w1P90+f4Ux ZctorGTUDB7r0/wkGm+RMMzZdzzZa+zJPmq/WEp7MV5RlAsJ+sR+5WjPbt2Htwni1QMx9rgkaNC Dv46Htqmc4H95fJ18GZDF4GwX99HZS5lc930fg4VDRTKcytFpYlV1Q5VpF7mcsgmTW6vW+5TfNc fYxt0DQRT6rmPX/Y1NpUhu0hGGCFG4I2svjbXmBwjuBWY6FKx1hHS+fHSTym8KovIKZJIN6ZzJ+ 8IbssKuXI1zxfzJNmMpsmU6vCewrc7jbYnKcYcJwMwIFR9O3mkoovXVgEOAy1EcrDLSS7u29SeI kPZwZchOqKX6dpZJ7XSleVSX9REWFmgU1W+OKbrnJcioBeB+AkFLdUTl6z5AcrlAPl0zWc6H9V8 7PAs9TjUkzO8ffr2s2IpOebqHvAJviT9Kn13SEIkUgOfunkn2iUsmmVw0Fg2Du9rEC4= X-Received: by 2002:a05:6000:2210:b0:47f:ec8a:214f with SMTP id ffacd0b85a97d-48488f0f6c6mr22597779f8f.15.1788449940413; Thu, 03 Sep 2026 08:39:00 -0700 (PDT) Received: from dario-ThinkPad-P14s-Gen-5.amarulasolutions.com (host-95-245-93-90.retail.telecomitalia.it. [95.245.93.90]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48448e72df2sm15366301f8f.1.2026.09.03.08.38.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2026 08:38:59 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, linux-amarula@amarulasolutions.com, Dario Binacchi , Abel Vesa , Brian Masney , Fabio Estevam , Frank Li , Jerome Brunet , Peng Fan , Pengutronix Kernel Team , Sascha Hauer , Stephen Boyd , imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org Subject: [PATCH v13 4/4] clk: imx: pll14xx: support spread spectrum clock generation Date: Thu, 3 Sep 2026 17:32:16 +0200 Message-ID: <20260903153836.373267-5-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260903153836.373267-1-dario.binacchi@amarulasolutions.com> References: <20260903153836.373267-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=llI208DO; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add support for spread spectrum clock (SSC) generation to the pll14xx driver. Tested on the video PLL of i.MX8MN and i.MX8MP based boards. Signed-off-by: Dario Binacchi Reviewed-by: Peng Fan --- (no changes since v12) Changes in v12: - Apply the SSC settings also from the set_spread_spectrum() callback to handle the case the clock framework skips set_rate() if the requested rate is unchanged. Changes in v11: - Drop the dt-bindings/clock/clock.h include and use the enum clk_ssc_method values from clk-provider.h, as clk-scmi-oem.c does. - Disable SSC and clear the modulation fields in SSCG_CTRL when no spread method is configured, so that a setup left enabled by the bootloader is not kept active. - Skip the SSC setup instead of dividing by zero when modfreq_hz is zero or mfr truncates to zero. - Reject mfr and mrr values that do not fit the MFREQ_CTL and MRAT_CTL register fields instead of letting FIELD_PREP silently truncate them. This also prevents the 10000 * mfr multiplication from overflowing. - Compute the mfr divisor in 64-bit arithmetic, as the 32-bit product could wrap with out of range modfreq_hz values. Changes in v10: - Drop 'Reviewed-by' tag of Peng Fan. - Adapt the driver to the new infrastructure. Implement the set_spread_spectrum() and get the modulation parameters from struct clk_spread_spectrum. Changes in v9: - Add 'Reviewed-by' tag of Peng Fan. drivers/clk/imx/clk-pll14xx.c | 99 +++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c index b6f1cc9f5700..5b187101c558 100644 --- a/drivers/clk/imx/clk-pll14xx.c +++ b/drivers/clk/imx/clk-pll14xx.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,8 @@ #define GNRL_CTL 0x0 #define DIV_CTL0 0x4 #define DIV_CTL1 0x8 +#define SSCG_CTRL 0xc + #define LOCK_STATUS BIT(31) #define LOCK_SEL_MASK BIT(29) #define CLKE_MASK BIT(11) @@ -33,6 +36,13 @@ #define KDIV_MASK GENMASK(15, 0) #define KDIV_MIN SHRT_MIN #define KDIV_MAX SHRT_MAX +#define SSCG_ENABLE BIT(31) +#define MFREQ_CTL_MASK GENMASK(19, 12) +#define MRAT_CTL_MASK GENMASK(9, 4) +#define SEL_PF_DOWN_SPREAD 0 +#define SEL_PF_UP_SPREAD 1 +#define SEL_PF_CENTER_SPREAD 2 +#define SEL_PF_MASK GENMASK(1, 0) #define LOCK_TIMEOUT_US 10000 @@ -44,6 +54,7 @@ struct clk_pll14xx { int rate_count; s16 delta_k; spinlock_t lock; + struct clk_spread_spectrum ss_conf; }; #define to_clk_pll14xx(_hw) container_of(_hw, struct clk_pll14xx, hw) @@ -366,6 +377,58 @@ static int clk_pll1416x_set_rate(struct clk_hw *hw, unsigned long drate, return 0; } +static void __clk_pll1443x_set_spread_spectrum(struct clk_hw *hw, + unsigned long parent_rate, + unsigned int pdiv, + unsigned int mdiv) +{ + struct clk_pll14xx *pll = to_clk_pll14xx(hw); + struct clk_spread_spectrum *conf = &pll->ss_conf; + u32 sscg_ctrl, mfr, mrr, sel_pf; + + sscg_ctrl = readl_relaxed(pll->base + SSCG_CTRL); + sscg_ctrl &= ~(SSCG_ENABLE | MFREQ_CTL_MASK | MRAT_CTL_MASK | SEL_PF_MASK); + + switch (conf->method) { + case CLK_SPREAD_CENTER: + sel_pf = SEL_PF_CENTER_SPREAD; + break; + case CLK_SPREAD_UP: + sel_pf = SEL_PF_UP_SPREAD; + break; + case CLK_SPREAD_DOWN: + sel_pf = SEL_PF_DOWN_SPREAD; + break; + default: + /* No spread: disable modulation and clear any stale state */ + goto out; + } + + if (!conf->modfreq_hz || !parent_rate || !pdiv) + goto out; + + mfr = div64_u64(parent_rate, (u64)conf->modfreq_hz * pdiv * BIT(5)); + if (!mfr || mfr > FIELD_MAX(MFREQ_CTL_MASK)) { + pr_warn("%s: SSC disabled, modulation frequency (%u Hz) out of range\n", + clk_hw_get_name(hw), conf->modfreq_hz); + goto out; + } + + mrr = (conf->spread_bp * mdiv * BIT(6)) / (10000 * mfr); + if (!mrr || mrr > FIELD_MAX(MRAT_CTL_MASK)) { + pr_warn("%s: SSC disabled, spread (%u permyriad) out of range\n", + clk_hw_get_name(hw), conf->spread_bp); + goto out; + } + + sscg_ctrl |= SSCG_ENABLE | FIELD_PREP(MFREQ_CTL_MASK, mfr) | + FIELD_PREP(MRAT_CTL_MASK, mrr) | + FIELD_PREP(SEL_PF_MASK, sel_pf); + +out: + writel_relaxed(sscg_ctrl, pll->base + SSCG_CTRL); +} + static int clk_pll1443x_set_rate(struct clk_hw *hw, unsigned long drate, unsigned long prate) { @@ -390,6 +453,9 @@ static int clk_pll1443x_set_rate(struct clk_hw *hw, unsigned long drate, writel_relaxed(FIELD_PREP(KDIV_MASK, rate.kdiv), pll->base + DIV_CTL1); + __clk_pll1443x_set_spread_spectrum(hw, prate, rate.pdiv, + rate.mdiv); + spin_unlock_irqrestore(&pll->lock, flags); return 0; @@ -411,6 +477,8 @@ static int clk_pll1443x_set_rate(struct clk_hw *hw, unsigned long drate, writel_relaxed(FIELD_PREP(KDIV_MASK, rate.kdiv), pll->base + DIV_CTL1); + __clk_pll1443x_set_spread_spectrum(hw, prate, rate.pdiv, rate.mdiv); + spin_unlock_irqrestore(&pll->lock, flags); /* @@ -437,6 +505,36 @@ static int clk_pll1443x_set_rate(struct clk_hw *hw, unsigned long drate, return 0; } +static int clk_pll1443x_set_spread_spectrum(struct clk_hw *hw, + const struct clk_spread_spectrum *ss_conf) +{ + struct clk_pll14xx *pll = to_clk_pll14xx(hw); + struct clk_hw *parent = clk_hw_get_parent(hw); + unsigned long parent_rate = parent ? clk_hw_get_rate(parent) : 0; + unsigned long flags; + u32 div_ctl0; + + spin_lock_irqsave(&pll->lock, flags); + + pll->ss_conf = *ss_conf; + + /* + * Apply the configuration to the hardware right away, using the + * current PLL dividers: the clock framework does not call set_rate() + * if the requested rate is unchanged, so relying on it would leave + * the SSC settings unapplied when the PLL is already at the target + * rate (e.g. configured by the bootloader). + */ + div_ctl0 = readl_relaxed(pll->base + DIV_CTL0); + __clk_pll1443x_set_spread_spectrum(hw, parent_rate, + FIELD_GET(PDIV_MASK, div_ctl0), + FIELD_GET(MDIV_MASK, div_ctl0)); + + spin_unlock_irqrestore(&pll->lock, flags); + + return 0; +} + static int clk_pll14xx_prepare(struct clk_hw *hw) { struct clk_pll14xx *pll = to_clk_pll14xx(hw); @@ -509,6 +607,7 @@ static const struct clk_ops clk_pll1443x_ops = { .recalc_rate = clk_pll14xx_recalc_rate, .determine_rate = clk_pll1443x_determine_rate, .set_rate = clk_pll1443x_set_rate, + .set_spread_spectrum = clk_pll1443x_set_spread_spectrum, }; struct clk_hw *imx_dev_clk_hw_pll14xx(struct device *dev, const char *name,