From patchwork Fri Sep 4 10:06:33 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 4841 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 117283F182 for ; Fri, 4 Sep 2026 12:12:59 +0200 (CEST) Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-49cd74fc1aasf5032835e9.1 for ; Fri, 04 Sep 2026 03:12:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1788516778; cv=pass; d=google.com; s=arc-20260327; b=IfZCdRhc1/KJlOtiplTYCe4K0qvMVuI1ZAPhNgcJPPe6ryns6pmG9nvA7h6NIdjoxV DZG5fSAMn2zri/V3xto03CTMMY8htZQ8sKFAZFzanf9P5+oDhM7ozxyLJObdAHmL8d6Y GeJXvZ/HF3wHm/oTSxbqwlMksu/9P8+uiSupZqfEaFT5E+IV+jaKCk0sQemyvNrIe4vk Lzylx6Rqy2Bu3GIQSiCK5hE5KDfUe+rdPkZHHnJKblADBt/Zs4j3q0J/0ZArDBr5pTW3 iO1syA702oAReByzLAwn+H3V+t3F9R/0yGrO8oH6HQ6yW03b/8A3OYj+h/WdSpkcwbse CiPQ== 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=XYKA77Wr6YrhhUaTbpqrAk4+d5hhRjwQ3+/LI8Lo/Xs=; fh=mEtwXnHM0mRjpxcIVMqYKkMezT42mNNEdYBq08XU11k=; b=SjzeJKB1YcOzcZpoJYUVKOwK8M8wS1jEPhx0nfFxgVE1I1YOj48RHFEJCx64RaS55Y hkVwPhcjZS8iOwYVXJVmK7fTJ65DhFUF80pMxMBV9OncMr7nVnv9CvWUQ+W3japAaTc5 gXW3y44mI8ePb2C0+cdZIJz5vPiXW1FO4Z24raF0wiKVxG+Dfp5FhAjFGkAqeI3i0eu1 dOvKGXj+YdcqYgsYHy6V0mwiS1HuMHdZmb4nYW8t1NLCjqtcjzcJfm0epDoD0wRTDK2e CV6xFJHPmN8fQjXDKww7L2g90YDYlIvtF5YEClFHYEUL8NOIoslRNyJvt/UgIHDIbUCR 3iBQ==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=eGhhIda+; 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=1788516778; x=1789121578; 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=XYKA77Wr6YrhhUaTbpqrAk4+d5hhRjwQ3+/LI8Lo/Xs=; b=YKTmOsXzDqTkdAydYOoLLPAV7KIf1eH0fuFDsk4bZoT6lC9bzvYNjpFss0BMYBDCI2 /ngq1EwuVn1vAB9GjQ79I3qCLlA7nlAPAvCSttt07mow8/n+H7hAvNBDn6iFvKr2dkeK gyrbrfh+4zQVYz1bzq0peAQQm5ZeaOesSA2Oc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788516778; x=1789121578; 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=XYKA77Wr6YrhhUaTbpqrAk4+d5hhRjwQ3+/LI8Lo/Xs=; b=Q5TcryvjDeoY3nKz5xx9ygMbXxm7ElwTzvqyx9rO3Oy7Zf6FRSVx4m5esONK0zAMwP lt0sCDqnk05wfb6TppJix/KW4fA3uW38Z3YcwwU2TanyyVs13MKJzDfY9XRq6ZeN3T9v RqSPHlNT4O0tb0Rcy8AJdoAvwuuECt8c0aVoAZsskbhsbjaf1EE8gQCihIpGpXJPFgKk 2LDzdKz1D/NtBShxSR1lM8ziJ9eC8mJIbi9DsGQKax3OzgJqsNRSxrvnNwXZxq1kQC53 BvzzSwpWU56MKDRSaVUmMVsgvwpdnqVHn+C1XvDsk6JbIJUUDmeeR2tB3daotsC0oSoh cnfw== X-Forwarded-Encrypted: i=2; AKwUvByWxfZbESR5BhYEbdF/y3w0Tyq37oxRoOtVX4JCLTMwa1EsEIxEjO0ILo9/OJ1r0uCo07RVrNqDXLhn5Dz6@patchwork.amarulasolutions.com X-Gm-Message-State: AFuF++nR9Lpo3/s+L64ftvA94CD9uVnK/z/EV0OCsObmaHhKU8Dswdw0 mk+nzc2DrMWsgiRLpBJZJ873TYr3rJoKNYEiiDu404w+6ZGITtVCgjD5DijjTR/gp5D2ncVqUCz wxQ== X-Received: by 2002:a05:600c:4e86:b0:49c:fa20:cbfa with SMTP id 5b1f17b1804b1-49cfa20ccb9mr30515715e9.17.1788516778659; Fri, 04 Sep 2026 03:12:58 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com; h="ATskLddNLwAOJj0ZcO/zPcG2QnSSZVdrdTZQ7whDqxwz+f222w==" Received: by 2002:a05:600c:3b8f:b0:499:8364:19be with SMTP id 5b1f17b1804b1-49cf688c9a4ls2576555e9.2.-pod-prod-04-eu; Fri, 04 Sep 2026 03:12:57 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBzWqJkw8wMwczsMqDYMalk9kEDSvXHqO5LnArg0IbOmkrc1fJjGnfm3UxW/7RWtEK3LozWeSCVtsdx1urrJ@amarulasolutions.com X-Received: by 2002:a05:600c:5247:b0:493:aa0a:45ad with SMTP id 5b1f17b1804b1-49cf81dadcamr44521625e9.2.1788516777197; Fri, 04 Sep 2026 03:12:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788516777; cv=none; d=google.com; s=arc-20260327; b=Ap8jBNEJGcEdyKo8s2M0853zqfNcQOgqIA7Ui7yLta2fZVOXDZsFPtBFivsVV/3XQ5 EW5QngS+F/jFCUGxjb1gZ9er9TbvCyXghiM4eU+XDgV4uFJLhEgsTNdhi3aT9Sryaj1M KukMW16HjGdVhBj/HfhRfrekYYt3NC9MTL7g50rz+/lfY6qbs3rKrHp4AJ99I8pTHjFf jPOoxhsKDiBYt+Z4Ojb+0DESaEJjyG05SBc6CWT+Hz6ODdYZOCfWjFllBnDHYjXqdnj6 UyqrDQgVI5fsuHVC7V6rWTXr9fjAnsAY7mldJP1aaZDH7h5ByGsXjSlfxv/fsSpC86m4 YxoQ== 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=hWVY1uMj4PCC62NWVYIfzX5Mbc8Yyn+zUzGlrLMkZwU=; fh=7H5G0N4M0q9lFjxHqpbUcnxtTeOqf3wnmEchMYdgF5U=; b=nVgzYnDtHErAkvzl8q4Zd8i8sngiikO/KwsczhE93rWrw7wQJO03afpwjw7jnqfJjs ohjnN0CJuOKW2M5IkzpgPeQOBA43ml6eZeOkTaIY9bxaNmn5FS1afcDbXxbdCA5ZZLsJ kcoiyEo2SQwULzj5Sp4Uy/yKfBigmYTUc5BWsdualIHaoStJkG618kgFGD2GlKBhcT6I a3UXl2VtP8J5tC27c5XW3sdVTxb6y/24VMDE1WGg8HQ0gE3FXYZjJA2vGSzwfCgzxW26 v2/79NzDx6do8yQPYXK041lpDviEjMsSY9sm3m584qslvyaSR1aN4q+1lILvLSKw0QFl BddQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=eGhhIda+; 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-49cf7744f55sor3124025e9.16.2026.09.04.03.12.57 for (Google Transport Security); Fri, 04 Sep 2026 03:12:57 -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; AKwUvBxmMYT811oEj2+NYwh/pxNvIkoBEeAL8j5flFn1w5+woIvmXIdYjzZNlGwTm21EJb3fyLa9AsHXc9F/Um0n@amarulasolutions.com X-Gm-Gg: AYBFou1qZIl8v3IHmwIFsR2QS1+u0HoEGpH+Pk50VWfpTiNgq/dp/U9Lynhi0zYUt+3 Fa+ED8Wcba8qJzqeN7Gtmiqw7261bU5HKsOmeeKZ9ut7FNDmzKnn9laW+voZ7IA1F+m+O43BOU2 bCerkwVMa40K7D8AKy3Pl+pLMk4ES3woDYwABMa7HTkthTui4KfCstNhNTAroLXKPl7tlLGBPC7 ++mjaafO7mbCYfZmzfgmomRSzWHh1Ejt6PUk1lYr38unr2oxFzsbpE1DxkjKLFTiyT447zCK/Le 1H+BgNe+1K2EKDOJQUTAeUN66g77hHOajdVCBx/5sroOwesnv5zIOER5L5J9Qs27AFUYxFNrARi 1PX/shzRFQifq6TAUT65zEYdJ4YcpZ+8z6uLnncERBN0Mc1pGsNhaasUCGl5mJwjTohJ5hPYjN5 OvefUgTUVGbUoNMxT4frjVKQnca886KLm+6MEMDpY5blGBvXld12Xq063CIyANg4r69u4H/8PlW KwLLJMxp6UostKTH733o4p8ZfS/90sU123OBlaiqK0UBKGaV1psUcJv/QfcLnNG58YDLe4Cg1Gs pm/5OQAX7akGs8o9pdTj8n4Esbxlyw0RPptZALG2gM9i/Q4eb2jWkHk= X-Received: by 2002:a05:600c:37c8:b0:49c:cee2:a508 with SMTP id 5b1f17b1804b1-49cf826c4e2mr44990695e9.16.1788516776720; Fri, 04 Sep 2026 03:12:56 -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-48588390e30sm5317990f8f.7.2026.09.04.03.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 03:12:56 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, linux-amarula@amarulasolutions.com, Dario Binacchi , Peng Fan , Abel Vesa , Brian Masney , Fabio Estevam , Frank Li , Jerome Brunet , Pengutronix Kernel Team , Sascha Hauer , Stephen Boyd , imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org Subject: [PATCH v14 4/4] clk: imx: pll14xx: support spread spectrum clock generation Date: Fri, 4 Sep 2026 12:06:33 +0200 Message-ID: <20260904101243.412006-5-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260904101243.412006-1-dario.binacchi@amarulasolutions.com> References: <20260904101243.412006-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=eGhhIda+; 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. Reviewed-by: Peng Fan Signed-off-by: Dario Binacchi Reviewed-by: Abel Vesa --- Changes in v14: - Rate limit the warnings on out of range SSC parameters, as they are re-evaluated on every rate change. - Add a comment on why the mrr computation cannot overflow. - Add Reviewed-by of Peng Fan. 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 | 103 ++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c index b6f1cc9f5700..84e081193f24 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,62 @@ 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_ratelimited("%s: SSC disabled, modulation frequency (%u Hz) out of range\n", + clk_hw_get_name(hw), conf->modfreq_hz); + goto out; + } + + /* + * No overflow: the core limits spread_bp to 10000 and mdiv is a 10-bit + * field, so the product is at most 10000 * 1023 * 64 < 2^32. + */ + mrr = (conf->spread_bp * mdiv * BIT(6)) / (10000 * mfr); + if (!mrr || mrr > FIELD_MAX(MRAT_CTL_MASK)) { + pr_warn_ratelimited("%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 +457,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 +481,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 +509,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 +611,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,