From patchwork Wed Sep 2 10:07:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 4830 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 BC43840D07 for ; Wed, 2 Sep 2026 12:15:41 +0200 (CEST) Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-490a767b782sf6666675e9.2 for ; Wed, 02 Sep 2026 03:15:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1788344141; cv=pass; d=google.com; s=arc-20260327; b=LUO7b0l8kVFQggohXZtnJowDWXxpeFtKZ0I848wtvo8jmmERkkHnVmJJgKL2IEBhCv JZeeFxI1UHbS4jQXwXnGHSoiurhLRb97V2nxnoh9y4Q1OfFEaDUaPk9sy5EudE4c/gAw zQ+0ndfc8+6Cbi7oDYU6Q9JQV3wblE5/Ns0nzKn7gHYyUyEN45XKAY2dgPFqFgHR3aCe bFZkHXeoDyFdnKSzw2YFxE2ZeM/eOPC8cDEWafGgRBdZYLUHF5c9UQfbuHzDkGwB5sF4 36Gfqnb3Ft7wMvSswYqrjLwQhNM4bhAwuo+hXkgBoyhc4q7YXElHAj36x2Hy5WxE1t9s m0+g== 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=CgOhzekUbK4zVc1O7tyq+SaNl39GnhCKOHv3l4H0jTk=; fh=e41p/CjHC3m2GNiml1WNTXMkvwtFvVgzxx1Rz3BKkp8=; b=ShONlf/4b5nMAcY8OEMBShO35GI10c1v8H1ipQMcDzakvGNtHZG7p7Po5TSaICo1SM Esxf8kIVdbBajI50w3qRhR+FSvLn9jZvipxOKqCD1Uca1FvdjKa6Mv/zRfiq8CK141G/ qsipdV1HV6PPCd4QYWMJsPv8Ryty0Nr0y9dtU6cKzXxzApZpT1xBs4YsDGj8luClqTRR 5MhOVv8R3KuPs4q7sNfK8ZG7/cpj0rvnA/kQJdqT8TRnSVBUGpA8vZKBSkRA+GCMbz28 1hEHoV6JtI76JKH675mzQh1y9rJujB24/HmQYzkSCA5QYFS9ORRo6T5UK3w1S8HfgPPe 9eHQ==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=HaRO7K+S; 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=1788344141; x=1788948941; 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=CgOhzekUbK4zVc1O7tyq+SaNl39GnhCKOHv3l4H0jTk=; b=lmgGIweMzT9QZg6wSrCuo+ELF7xNwMglEt51aFfB8VDIbYQrLEvqpF7/2098gdjkLQ pYlWt2JNtiR1qkuPt9kCrdWs3UT9fHnDzjkEecHks9PiPVJsqibh9zWZWwrFmkUC/yTc V+x5g/gkAh29txbWNwgKb41UZo97CgocnkwHk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788344141; x=1788948941; 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=CgOhzekUbK4zVc1O7tyq+SaNl39GnhCKOHv3l4H0jTk=; b=cFDYx0pfO98TMMUcOlRXCYnA06b4mM7AVcRt0CA4+qoSaj3bm3cSSFoai1vD2Mqp1M W8RuJr7IANMtAjhyeBmLAH9JYp+DT85DssJJPJMYrj7TEDDlZhOi1fSAz8m2AvIXOgBA adgBlhcGEdFTkKHmrI7hqgjHyOSzDUzeXKuCGcmwSVr+7aZUTHXkN4VnlK4HiElLUWEw HxLJJcyG8J9Kx63Ulk7+GlyOiaJwAcj3gMrxGzj4adJrZM18MPf4xpPzwo3cUba9sZc6 tJxyo4L/awFhpY7dGUzI79SCABnXuI5xefc6qS/K05tuo9h+H1LHlDi05gGHWZJPZkhT gRfg== X-Forwarded-Encrypted: i=2; AHgh+Ror/PoN+xvATWxR8eyUfx0BHKi3CJPIWGzi68afT7RAfNxBswH13HYJoQGUPV82UHG8cR1gBEBDWB1c+o63@patchwork.amarulasolutions.com X-Gm-Message-State: AFuF++lS7HHiNst15tMyZGDZu8NnlHTZbLtbZ/Gv3od/fzZ9388Kd//i vNTam2y4T66xd+8V1+Nd9i6YhtzqIQ/jRirpVsCHs0w2nOFUOp4dBLocO2eK8RULED2mDA== X-Received: by 2002:a05:600c:3556:b0:499:adb4:a922 with SMTP id 5b1f17b1804b1-49ce584088emr58392745e9.12.1788344141389; Wed, 02 Sep 2026 03:15:41 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com; h="ATskLddyFau3IsjnleU8Uow0/362H/jpuufYorhciyJA2o4HPw==" Received: by 2002:a05:600c:4e03:b0:495:47b8:810a with SMTP id 5b1f17b1804b1-49b22d8db16ls57697615e9.2.-pod-prod-08-eu; Wed, 02 Sep 2026 03:15:39 -0700 (PDT) X-Received: by 2002:a05:600c:3556:b0:499:adb4:a922 with SMTP id 5b1f17b1804b1-49ce584088emr58388285e9.12.1788344139363; Wed, 02 Sep 2026 03:15:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788344139; cv=none; d=google.com; s=arc-20260327; b=LkHxJ+nLOjmFokJo5lZ2+jVMHQck5wN1pajDDxRy2IGiyL/koJluWQrA+T5h5WugUT o5CjB/GGejlfahCi1wHjcGpXmv6ZJ+qjheS6VAwiYGa968pmPgMDE8qdMbc+orapCFtC LyoaPWbCSo0mYTAXN4R6+e+dghriWZS0CF5qVmPLyavyjFxEnXEgfLJutUEAP7iuuevI ZRC7EOKsulvESDZZeCsrRtURRmC7/j+AgXKgILoUk6vGi9wWFV8ECgcfGZPTt+fCfAhs Oo5AM8aQDTi0VwXpYzOpX3ztJKqcYdfve0p4i5PEJdi9It0PKqcFBuYwwkCaE77lRh7X jpMA== 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=cnN3xP1zwvn+tmeo5Jp/4ETSSusDTxDKIJZOHepiHeg=; fh=zuTFvgUbDA4p+duRUtqF1kHsKgia+Oibpqem6QzXfB0=; b=b1bYGAQ8zPyukoaLQL+MA0gfrrmNPHPSXLchPv7Qgie/6Tp1/Dn9ST7JDyzwhCpOBG IR9SBj/pvKyfPjluPjOz95UHlUwh8/wJvxW/CAwhfVLogaUtc1wenSK5p2n5agKramZH NsVBU2gei/T4sFcumkf+m4qeevd/FDzQ64e2h95q2VerzVBGdufKsTl1e7IcsPhyRpoL cPbCz9/LnmAatXHiEGivbtBToJXrqdaNN7uMcVEE4FlV2y+zCHlsK+bEXz7roA+WdbLn LW+In3iQ64rxzynRwukg2daaB6skzKsUWyTzibdlfB+f8aFxS2WCgu/NDFMrg6Kwakl2 FUpQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=HaRO7K+S; 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-49ce479c1absor3779825e9.16.2026.09.02.03.15.39 for (Google Transport Security); Wed, 02 Sep 2026 03:15:39 -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-Gm-Gg: AR+sD13jGaISo/uysYyuuZkoq1OeOm7EUf223OHd4KJTrVTXhM+jk2Y+0sjaNZ7qdem 6wYBMQZZVgW1RjybrIB53IhH+vvBty0saUUPLTbVaWUZvvn/KV9vH7vuvouESnV1tA2tMhqYKTG YFxlc2rp5495JcJZkoKMc+bp8UrLThfxPyhqhjzG0/PvJa/T+3T8s3686dcq/T1GvVH9GPyH4UY /WDQgiln8kupJGWsjRDG+/G5L/AizJYhHIenhws4E8EcqBJOe0N2t/2andgOthvFG/jTzsLbyZQ yav4LJ3G+s4hh+dhdMvY5TVF8UDAk2o7fmtWUJS539WT5QEgEpp0GiYhzhRCUSOJRbY8rIkt+Xk TFRi2UEbAX+GOUUL3nIX3T39fTgCYMoRyGmXddUHbHSlxHPpeBukZyDNQV1y15kLpssfV2Tsd6u KEZI73cySNB6b6fESeRxy164aEyu77k1+gQL8oA9ubZHlwRUcATaNpMsf+w/uNPoxSGSrFWUV/G FcYYNHkC+Xzbl753BHp2AR5YPiOQxMJjtYqnFivof119QZRWvz/d4fJoXldhI1wsxVsb1SY+IEJ r9X3kibH8qopclwnQw7vt2q55M8f4osklmX4fdRGKjkNZ1wXF8OLvf3XRxjV X-Received: by 2002:a05:600c:e558:10b0:49c:e906:ba16 with SMTP id 5b1f17b1804b1-49ce906bb7cmr17496535e9.15.1788344137993; Wed, 02 Sep 2026 03:15:37 -0700 (PDT) Received: from dario-ThinkPad-P14s-Gen-5.homenet.telecomitalia.it (host-87-9-102-148.retail.telecomitalia.it. [87.9.102.148]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49cdd73f7a4sm139618475e9.12.2026.09.02.03.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Sep 2026 03:15:36 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: 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 v12 3/3] clk: imx: pll14xx: support spread spectrum clock generation Date: Wed, 2 Sep 2026 12:07:35 +0200 Message-ID: <20260902101515.167819-4-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260902101515.167819-1-dario.binacchi@amarulasolutions.com> References: <20260902101515.167819-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=HaRO7K+S; 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 --- 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,