From nobody Sat Sep 26 05:29:34 2026 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CEAE455632 for ; Fri, 4 Sep 2026 10:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788516775; cv=none; b=cttqrb1AJyW3wNydx0DoKmsHYdEaDTowBmIzGOptrxSWt5tIX4gMSjsY+GoxvYRNoEoHNNqgD5eQi7JJeXskHsDYWvuH0MqkaOaZwNH8alE7hWtFNQ8TYTaJbAP/s0LwBeugu7UgOfxbdfDICf7HPtMvkVju88Mwx2beGTLzILc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788516775; c=relaxed/simple; bh=JOoI2fQ3bWoSNiNb4j+XTtCV5WPlewq2Kxd7FdUTZYA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BgWvNLffUwwSYwMwIacluIVfauKf0xsu/HbmvBzrTnrkdiZKO33G5g04P4R4qZeIROEH/Ca8xJudrKGpKqg7Mx02MyhrlHw0LCoesKQPS1ZpMxghd8dZBa07yicB9LLMgOz2ZBbpq6vpWSt8b4qo65GWyJ82iANGf177iICpRJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com; spf=pass smtp.mailfrom=amarulasolutions.com; dkim=pass (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b=DmMak626; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amarulasolutions.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="DmMak626" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-47f96c5b722so545274f8f.0 for ; Fri, 04 Sep 2026 03:12:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1788516771; x=1789121571; darn=vger.kernel.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:content-type; bh=trMLdDdWbBp5aYskl2hpYhEKm0ijNRyi5bjjWx05fj4=; b=DmMak626qAsG77i5dAhWAlPlfCMsx2Oz348NUbAba/CD4zmHwh1PMqhB0I7NZeLFjQ D0R1QVQ8GAWGzc/iAAbnZo9Ekv8TBuIUWcKRCbmvxBVvxpmeZzwV80gAZNBs8FpTlF5F cRmx7eNC3o9JArisZz1Ctbv5EoFixFxHJWpHk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788516771; x=1789121571; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=trMLdDdWbBp5aYskl2hpYhEKm0ijNRyi5bjjWx05fj4=; b=hJOTGHONTnkvTiQCYh9KgehDA6uYYL2nityMsE3eeNHyDF204FaOlljgn9CH8G1GtB VZ3HUX27SLG5/jzQzec+PxRqvyOph9aymR9nZoym52w1kFD6+q88pXWKgV7MImlugKtg JZ+HyqKiJ/i3NMtRWwC/wEB5GSnP04L8sgsEYRse/naGxqqdNB420RDVLGAIC/ZFL4M/ X43bC8LUkeO5FTCIfy/Vsbjn216yZRt+jdkibbDkW3BKAahrFeVNknDtKRUIrtzOyUZm itznYDu9ipisTj4PyoDGBvvX6DWDCBnwTlHYG1qvRW3AjEW6uhBHwKGGg53BrufhyqWt Kq5g== X-Gm-Message-State: AFuF++miggwk1CFS/hxdXVdYFn3+j1IFkuUP/Abp6qvNbChRGtjmG0vp e2csPOxxTwLm63u/fd6DDllLbfX6CDFqnZXmthYZAvR3oWwLoycCrPY6ZUWLDXk5JB0ovUN6g20 Sind6f0M= X-Gm-Gg: AYBFou1vfclpxmxIgSUYJFMOD5S4Z3Qu7f1B2Nq9RyvZuPC9/GHMuOl3AQ6BgDh0a7Z ty3eyNdDeDF1/RU0PSKwyvs0LK6eJCl9k5X/DPIpM9bEaOc/+qcuAAF6shiOfW7/uwue9fqAUKd mcX6PvLR9iznwxnKuJTxUsarSdr+e5Jh2TOxe1uARzsBZVprnmAaDAtDn1n71Ocyd3E6s6KrhMy TK5v6flowNRA9Ra9s99CZxAVuQfEQzcFAVRsnYWiUieIAwp5b0sGqoIqvpYzUeE1tM/AR+64b7C TQVzIAjJsfJysBUEc/wx7Z43t/RlTY68MjvB1KMw9fsKzkIrlZuR1b8UCCpYEhmzQW9Ymf2Xdh1 Jmsv4Wl3I3Es0h/TwlVnexNq/73r91PuNNIJMNz8jVg4FI/IbL15Dg8fEqnmox1/UR/bh/3UMWX CxSJRs8mT5apSKOjisF6VvUhYzg7TdD2t58Uy2MIoQ/yIpgVPT2UQRLUu1hq7PhZ+mL98TV60dT Tgtj+C98KVs4kfGuKHrmJC1W+VfzP3k1nAo23dQcTY7w5VPmwgYDNnCAblIB2vH36HDcSHmVSsQ bhxH2KOsIaJlDQNbeTm7z8PWDBhyeuENRQl6YoWC7ysIM1zKzNHM6Bsol6diOqiAdw== X-Received: by 2002:a05:6000:41d8:b0:485:8a47:5b96 with SMTP id ffacd0b85a97d-4858a475cc1mr2833945f8f.51.1788516771007; Fri, 04 Sep 2026 03:12:51 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 03:12:50 -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 v14 1/4] clk: scmi: fix SSC spread conversion Date: Fri, 4 Sep 2026 12:06:30 +0200 Message-ID: <20260904101243.412006-2-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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.o= rg Reported-by: Peng Fan Closes: https://lore.kernel.org/r/ZR6PR04MB375776A27E98F140534E8F7FE488B62@= ZR6PR04MB375776.eurprd04.prod.outlook.com Reviewed-by: Peng Fan Signed-off-by: Dario Binacchi --- Changes in v14: - Add Reviewed-by of 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; =20 /* - * 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 =3D FIELD_PREP(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK, ss_conf->spread_bp = / 10000); + val =3D FIELD_PREP(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK, ss_conf->spread_bp = / 10); val |=3D FIELD_PREP(SCMI_CLOCK_IMX_SS_MOD_FREQ_MASK, ss_conf->modfreq_hz); if (ss_conf->method !=3D CLK_SPREAD_NO) val |=3D SCMI_CLOCK_IMX_SS_ENABLE_MASK; --=20 2.43.0 From nobody Sat Sep 26 05:29:34 2026 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 431F144237A for ; Fri, 4 Sep 2026 10:13:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788516817; cv=none; b=NBFQxqGoRaond/sV+RLA3Aux5u4DJ2wlKUXKrZCfzEy2OjxfMlDhzK/aVqUTh6XfwBnz8gl6tQ1tSWTNgIjaCebTc/Kd+cxK7dkusxkRXfXSLB5Wx8Laui0SCb83UnANF+ZkntuXRg9j/N0nrR2P7cx1xF5FnTZLxWA7b0i5NoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788516817; c=relaxed/simple; bh=xZ2sBnhrYKqxY/S8zO9jUQA4qCcp7CsTSlId62VD62U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rn19NuAlgyR29S8RwUQrq11Gp0XCh4TGy5eJGDnUm4nbRqH4P17x8uUhtyQpVxMvrmKBfTBzLCKTgGFS+73GhOqUwmVmodWoMeWm4ZZ/CYH33Sv6NA0VftFUhP/Zwp/ri/xVCvB8f+aatKCqhP/dA9AEm8cRAhsQmT/8PDkGdcc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com; spf=pass smtp.mailfrom=amarulasolutions.com; dkim=pass (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b=aA3G6LdS; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amarulasolutions.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="aA3G6LdS" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-482e067e908so740592f8f.2 for ; Fri, 04 Sep 2026 03:13:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1788516814; x=1789121614; darn=vger.kernel.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:content-type; bh=U/iBVA9/Ii7qFgco17f5RCUwPjhgNhGPbu+zTwjLGmA=; b=aA3G6LdSfBEFdJO5IcUlngaRT9cJtLRlJ2Fy7sBP8eggwremX/vAWSiEsZG5gLXe4F YSdHygtrG63memrbX4o5iYFEPef5abqOBkcUZPt8d2rfZCHFGwowrHzq9Y259JUKO3yT dR1Rs/noSnImP6n6Sfk2N+qcQDZkVuJJs8blA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788516814; x=1789121614; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=U/iBVA9/Ii7qFgco17f5RCUwPjhgNhGPbu+zTwjLGmA=; b=dLyDTIHTtJsmzB4xJMLIfx9o8KSdLjuxnIlv5GwbM3kn59IuoPz93mHYkLXgS1Hi/W AVUsWXWpQ0KK6MointBSr4mTABngOyxXxCvWemACMABPRl8YUcT7bsltNSdwibD9k1NG dCfSbZdrmLAyJdRxJS7qMmoIwxGrP0biRypmU+uK7oxNTjDvr5rzls6DI+wur9mX8DPi QziCCpR8AQ4t4CSlml9ViFo04I6n0fM9ixz4k339uEjNXCpghFlA5bNSE00UGSx7eh24 JdPW4nIL8EctHGKw913Xmmz95qCko1efJ6df2idaqwMmeXyS2aQTIPfbE3WzTtTpHZYx IJQw== X-Gm-Message-State: AFuF++kYcZ6AOGDjhoIqDRGxgFjG5sCvGagCEPAX6mBULVfY1BDmQzZ4 fA9vD4SNffjHtSWciQWQKyAmJkg1aAu/46QLEeGuwnoVcIcO9lo2Xy28Dc41C/cgIXVd5hwvPAR LnTPV5tU= X-Gm-Gg: AYBFou34uF2Y3T3hPfPfkakw0l+bJSjp7SSrQSE2AyCaZncMD21xCoAhLHdKO2ALsF3 TxvXRKatP3Ggi5f5OM0aWy6ROBw2dgUt37x14RkAjyiCLlGkOdDKxeMWIHKyGhk6kUINWwT2wpL smzOAoDTVDVUl3wpO1/OvFpMZdLTs8gMWx1eUz2uBevIRc7unZktgC03jF9u7FsYuhwk60sLiq+ 6z6ZGGqa56xxn3oQHlkJ3hgFYt1Bxd17h8f86ZTTdcqahaAyJyGvg0IwGXj/W7bjgnTfbhcB30/ 7DxyNL004A+zhYHnsR31R6mMy282A3lMAGWl1wqIzf2LKcnDbLmvJI9s6Nv+XLq/evYHQ4uk0HL AgVW3usAPzqz5o636zGw+l89ZtzyA1LzyxpYZzchvFsldJv5zarY0C3p9TS6+qSzRM9xtSK1ex4 cPOPD8ni8Bb/74Pe32iMvtw/ROsKe8b5G+8M+TyD/jCcTzYwqfZt2E7+x85EU8nt3x9xCW1N8Jc VubeHtbM2gSOiBZOYVC7KkVHLuKnr8dGScbUahID/KpXCiXrxtMs3pHbYy0AomgE1mEC6E6I3Nb vLIzFi1/94dwMMaWUvV0qNtLLa8LbM/U7lRGTfFUJpSk4uva4C4Wb84= X-Received: by 2002:a05:6000:40c7:b0:484:3310:f394 with SMTP id ffacd0b85a97d-485872d2de3mr5945970f8f.23.1788516773023; Fri, 04 Sep 2026 03:12: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-48588390e30sm5317990f8f.7.2026.09.04.03.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 03:12:52 -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 , Jerome Brunet , Sebin Francis , Stephen Boyd , linux-clk@vger.kernel.org Subject: [PATCH v14 2/4] clk: validate spread spectrum configuration Date: Fri, 4 Sep 2026 12:06:31 +0200 Message-ID: <20260904101243.412006-3-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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.o= rg Reviewed-by: Peng Fan Signed-off-by: Dario Binacchi --- Changes in v14: - Add Reviewed-by of 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, co= nst struct clk_spread_spectr if (!hw) return 0; =20 + 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 =3D hw->core; =20 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 =3D "provider missing assigned-clocks", TEST_PARAM_OVERLAY(kunit_clk_assigned_sscs_without), - .sscs =3D {50000, 60000, 3}, + .sscs =3D {50000, 600, 3}, }, { /* @@ -3535,7 +3535,7 @@ static const struct clk_assigned_rates_test_param clk= _assigned_sscs_skips_test_p */ .desc =3D "consumer missing assigned-clocks", TEST_PARAM_OVERLAY(kunit_clk_assigned_sscs_without_consumer), - .sscs =3D {50000, 60000, 3}, + .sscs =3D {50000, 600, 3}, .consumer_test =3D true, }, { @@ -3545,7 +3545,7 @@ static const struct clk_assigned_rates_test_param clk= _assigned_sscs_skips_test_p */ .desc =3D "provider assigned-clock-sscs of zero", TEST_PARAM_OVERLAY(kunit_clk_assigned_sscs_zero), - .sscs =3D {50000, 60000, 3}, + .sscs =3D {50000, 600, 3}, }, { /* @@ -3554,7 +3554,7 @@ static const struct clk_assigned_rates_test_param clk= _assigned_sscs_skips_test_p */ .desc =3D "consumer assigned-clock-sscs of zero", TEST_PARAM_OVERLAY(kunit_clk_assigned_sscs_zero_consumer), - .sscs =3D {50000, 60000, 3}, + .sscs =3D {50000, 600, 3}, .consumer_test =3D true, }, { @@ -3564,7 +3564,7 @@ static const struct clk_assigned_rates_test_param clk= _assigned_sscs_skips_test_p */ .desc =3D "provider assigned-clocks null phandle", TEST_PARAM_OVERLAY(kunit_clk_assigned_sscs_null), - .sscs =3D {50000, 60000, 3}, + .sscs =3D {50000, 600, 3}, }, { /* @@ -3573,7 +3573,7 @@ static const struct clk_assigned_rates_test_param clk= _assigned_sscs_skips_test_p */ .desc =3D "consumer assigned-clocks null phandle", TEST_PARAM_OVERLAY(kunit_clk_assigned_sscs_null_consumer), - .sscs =3D {50000, 60000, 3}, + .sscs =3D {50000, 600, 3}, .consumer_test =3D 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 =20 #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 =20 #endif --=20 2.43.0 From nobody Sat Sep 26 05:29:34 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD4131A682C for ; Fri, 4 Sep 2026 10:12:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788516778; cv=none; b=Nz8ifIztt0C/e0aIgaArSPNd3Bgd4hhW0IRvLXlVXzmRDdLNLjaiQTWfZhLab7zrVfsSoeQj0oekKVFM7+TvbJ0pCUGdN1P5/WNFH6rjwxTRivwMK0lCSf6hUMU0A+PNZV80jJXGuQg/NvUMieo2YjKavq+qjZKOJTTXA6m61rQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788516778; c=relaxed/simple; bh=NiMVJbmVsoK8R121qi2cF+5KCHnnjg8UxRitDRHK/AI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MC3pAZqS2NS+zAOH0T4OPFpp+hZQDuyhfENDizNnR59hdNUlNgZY4hS/XvmRzTUntsjCvnhuhi5Z+92QzODe4Twpbu3C0kYYnSYnyYcTvpwLmijOnqCbpKYJq/PAdPCuhFaYldQNZOEmp0b/BIma3f1UbvtCYXGIhOfyu0OeinE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com; spf=pass smtp.mailfrom=amarulasolutions.com; dkim=pass (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b=jkv57C+4; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amarulasolutions.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="jkv57C+4" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-48441fa5c37so523967f8f.3 for ; Fri, 04 Sep 2026 03:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1788516775; x=1789121575; darn=vger.kernel.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:content-type; bh=fjBHI89nbApApOn8aT/Os8kMb1n8Jfct1CD1+zTK8UU=; b=jkv57C+48mN347W1j2kWJcKnKw9Mvsl73qJPHmMXY2Gcoa3RMwpxHduWxkalOt+IUm F0dzGMy26cOjWffdB8fGy+fp489u73jQ9rV4l+Lro7u5NxNXIleNx0w+iRG/L/YH6dzx Wb7eR1+vP3fiVcYx8GvxSj3edvn2X2X93SfMc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788516775; x=1789121575; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=fjBHI89nbApApOn8aT/Os8kMb1n8Jfct1CD1+zTK8UU=; b=k/wnlxhC35rslmsmPsu0iK4ngcZjYJU86/iQdeb10L9KH0aOMtluxhW6mV3x748kyP HG6vLtyuof2sKnGaRtfSKdCiD1NmWRsrX/XBnAZ7a8uNyDSqKcnz0aVP3m+rWuayue27 8H/ZSCSdLULWroZsNP5cIX3BtfcRbfV63PSwBMe+JZN92tqb7G2LEkv9Dt2m90x+b+Z0 T9V+oJ/bw17RjwwD5PNpkRtNG6BNZyt0pu3lBax7BOQ+jFuCmSCyxfmgyE32UE2O2yCl Ixt4g7ApF1NZ9+FTUzqB7kM19Kcf1078pcyrCy6Gx9n+KOJafDFPxjmxnJ5I21JitNeW YBeA== X-Gm-Message-State: AFuF++mO0DLpRdSHsIdmB2u+++O4lfuEiUgrqu0F0AxqYhgHrYgrVAne uV4xsx3hSrP7x9wvaz35hqLx/1ufa81A3QQUbF7rN6I7amNIl7hwvY9Lc8gMZJOkHSs0BXVbT90 Q+rQckkM= X-Gm-Gg: AYBFou36nFEY9OK8vH89PB6XWpwdU4ZuXvmUlEmb/rtB2hKru8lkT53SPLOFOZfvEjm PSgEXKVjeIzbv1dkTTRZVxWMfB55UUsy8ZI9YT0jwINkDRf6lyJTmTqpDsB4LKV5vftEjQU8xt7 tJrzPdJR34FcB3UmV3lFdJJhX+gZJ6V64fdHIImLib03gYiLyUQwTJZNEP52rFEShH9UcCb6SVu ia9a574GkAFSMYGv+3//IsAqcRO4k+sowrvhOqoOQS1YRKUL5uCmQunizW6rf9R5R1h3lqO16tq +jOuKGafHfkATCdacfesXjM8tzfeXssRPCJyn+xNSeFk8nMuTdlX5mPi9rNvTe+FinpGMNGwujz qOPXvT5KzGYxn7/vRQ+6pTJrKh/ZRvv33KuGPxpQHGz+gFBOhwukGjaX0TQ2HEngZOk8jqgRQK/ jbIkR3I9alXhDkW4F6dqXvSV7A/jnkl78Ac95Clpb+jw2YdWwyM8ihTsm0ferycokBlttk9A/B9 je/bUK5FNvVm65TyaYYxkt1ckftvdjuGHtFtCUT468SOMTLGNMVfmXDaTtm4PzOEmY+sBuJFpTg o1WPreA0urOk9d2Y1f1vG4AF0w3X0T24HckezkrE7S3dC4pNY73ykkQ= X-Received: by 2002:a05:6000:26d3:b0:482:f5f6:d253 with SMTP id ffacd0b85a97d-4858728a2ddmr6662967f8f.12.1788516774774; Fri, 04 Sep 2026 03:12:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2026 03:12:53 -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 v14 3/4] clk: scmi: reject SSC configuration out of the OEM field range Date: Fri, 4 Sep 2026 12:06:32 +0200 Message-ID: <20260904101243.412006-4-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. A request with no spread method disables SSC, so send a zeroed configuration to the firmware in that case, without checking the spread and the modulation frequency, which are meaningless then. Signed-off-by: Dario Binacchi --- Changes in v14: - Send a zeroed configuration when no spread method is requested, instead of rejecting it, so that SSC can still be disabled. Changes in v13: - New patch drivers/clk/clk-scmi-oem.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/clk/clk-scmi-oem.c b/drivers/clk/clk-scmi-oem.c index c1ebbdc6bbc5..29acd2923fd6 100644 --- a/drivers/clk/clk-scmi-oem.c +++ b/drivers/clk/clk-scmi-oem.c @@ -35,19 +35,38 @@ scmi_clk_imx_set_spread_spectrum(struct clk_hw *hw, const struct clk_spread_spectrum *ss_conf) { struct scmi_clk *clk =3D to_scmi_clk(hw); + u32 spread_pm =3D ss_conf->spread_bp / 10; int ret; u32 val; =20 + if (ss_conf->method =3D=3D CLK_SPREAD_NO) { + val =3D 0; + goto oem_set; + } + /* * extConfigValue[7:0] - spread percentage in tenths of a percent * extConfigValue[23:8] - Modulation Frequency * extConfigValue[24] - Enable/Disable * extConfigValue[31:25] - Reserved */ - val =3D 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 =3D FIELD_PREP(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK, spread_pm); val |=3D FIELD_PREP(SCMI_CLOCK_IMX_SS_MOD_FREQ_MASK, ss_conf->modfreq_hz); - if (ss_conf->method !=3D CLK_SPREAD_NO) - val |=3D SCMI_CLOCK_IMX_SS_ENABLE_MASK; + val |=3D SCMI_CLOCK_IMX_SS_ENABLE_MASK; + +oem_set: ret =3D scmi_proto_clk_ops->config_oem_set(clk->ph, clk->id, SCMI_CLOCK_CFG_IMX_SSC, val, false); --=20 2.43.0 From nobody Sat Sep 26 05:29:34 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF89F4570FD for ; Fri, 4 Sep 2026 10:12:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788516781; cv=none; b=t7n/zbAXRuVH2fgcIzzZlgw4EoTfHllu5M80+LnZsUcgTLM9dOS6ag6rLgpPC8Ds5WWfvSVfu9HERa8cUhwyG+Ekh7XHtxrJrlL8sDZ/U1aEFbMeAaLwBvwFwam9qNMR74mL3dC09pxpY20aaCPEGEubRjmTkI+lS6/kO5fpyeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788516781; c=relaxed/simple; bh=4DxJyEuA+T0h7/bpEIXzn7e/8Z/b3XxwkEaB7qbGt10=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pNVpFlUdWXnUkIydsM3JurSpZcS1Ehh4yYYdupAA1QzxpmVmhJOk3Ri72KHAYIRKCzW3AJmQAdWOhAYjYN/LWmmqV+0xaVUmn6h3RHQANrFTxhrKnbbRwuvhN76gkwD9/e1rVKJPXI5C/o9El6eOimDPC8r6RfG3d/f0zq+pIYw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com; spf=pass smtp.mailfrom=amarulasolutions.com; dkim=pass (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b=EAT9PjnZ; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amarulasolutions.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="EAT9PjnZ" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-49a97714f5dso6855275e9.0 for ; Fri, 04 Sep 2026 03:12:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1788516777; x=1789121577; darn=vger.kernel.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:content-type; bh=hWVY1uMj4PCC62NWVYIfzX5Mbc8Yyn+zUzGlrLMkZwU=; b=EAT9PjnZ4sXey1wMqnFBV52H3I5CcprIwv6RHm7rk1O+YBZYEymVoR9zm6kUgBH4gm zO39nA37/GbvVKDT7q0TWARcDtV+sx6xJNNELbMSbtOKruP+Jd4jAEneL65kr56Fvxln WgfzVLvBlZMsoldQF+kMfCqzx5wWti9J4OnyM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788516777; x=1789121577; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=hWVY1uMj4PCC62NWVYIfzX5Mbc8Yyn+zUzGlrLMkZwU=; b=emKWvglPqUEEAeoUJFUf8sMN+moxyTWvXwCRQQrAUpPT2ff1JGP88Ol+9t9HDO1O5j YstvihhEoqpOCDmiY8sDY3VnfEpI4/xgnW6OMx+/DsB8qbkXCgtPNwFwfllhb6nCZknu YKRFxNLxBFk22nm51x6tgNpeLvArqHvME9b6tBcIVWwyn8W81/jWrISpJUIksQ56Wrp7 oz1Pi3ojNo2ao9IK4KVPj+TWNYfFUvCvlQC22o52JV/7QkxiLPO1hFG226svnrOs0Bxh o1LfO29aE9xe8GWxjKqIB0ZOQHttdXamKrzkVQaRrMcgpXubUU0lgtNU6zMUV/EtxZmg L4wQ== X-Gm-Message-State: AFuF++k1otyh8GF2ybAvIWpbcF/LO3XPu1EDHwO212WwqgtYmXhXRGBJ 4TdmCjqHGqrDwWqiIiU+dpOt0CSIQlCug0bXvrf5uoWVtmuWJUVVG3mi5QgEw8w/zsZFP9e8dfq xxLBWSLo= X-Gm-Gg: AYBFou3tqHwN67cSzkX6uz2lEJy/RQk0YFwnfV5UF+MFr/SjgoOzhZilDaxA+e/t3JQ EAW7u0s1mJglJt+wUcipITfw3tJ099MYWgvKiEYLhsmS7DQF2RKmvRvTgWgTIWvRSoCrQlmBbOr LjkuTlHu8UWmYLcsmtzK8qY3akcDEEyYzR3TaF4jq8wDsVn0qa35/4MYaaRdahqK8917JRQj0Bv Jcl/N8I0BmF/PsNxdG5W8WHBukOzjWUZZhSC86SssLSBWku5Zq0s+Z5QVYSIvkIZdCrBqJlYn1O 50OQ29pmOEyGB963PgXWvRz7fiX5uSQedF1xWJgYNHk29X2GVbWB85PfrYD7jBO11VsNpQlpGUv LNq0MXbE5qWcam2xATqG1S8MCZOZiKqbupzTWTdNoOQxbn5u0UkYpMk6RWWEUtUiCz4B9QSM4iS iZTGHr2vpBu3VbTceaCEo1+8n6N8xcPK4gFFVyBzqy+84BaNDlL1DKtgX/+qz1r2Xy2U1PVzKcG b6dTq5658ZxigzdnCTLZ5an/sE+fuuD+9jEKgfHTkp37NBrdewDbZb2bSqy18CrK9mWS48s2clu wzCTvwXMLmqYaRUfW54NfcpsY4iMwOxahLY2TnNFxqxnmlI/GAmJfjo= 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) =20 #define LOCK_TIMEOUT_US 10000 =20 @@ -44,6 +54,7 @@ struct clk_pll14xx { int rate_count; s16 delta_k; spinlock_t lock; + struct clk_spread_spectrum ss_conf; }; =20 #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, un= signed long drate, return 0; } =20 +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 =3D to_clk_pll14xx(hw); + struct clk_spread_spectrum *conf =3D &pll->ss_conf; + u32 sscg_ctrl, mfr, mrr, sel_pf; + + sscg_ctrl =3D readl_relaxed(pll->base + SSCG_CTRL); + sscg_ctrl &=3D ~(SSCG_ENABLE | MFREQ_CTL_MASK | MRAT_CTL_MASK | SEL_PF_MA= SK); + + switch (conf->method) { + case CLK_SPREAD_CENTER: + sel_pf =3D SEL_PF_CENTER_SPREAD; + break; + case CLK_SPREAD_UP: + sel_pf =3D SEL_PF_UP_SPREAD; + break; + case CLK_SPREAD_DOWN: + sel_pf =3D 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 =3D 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 =3D (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 rang= e\n", + clk_hw_get_name(hw), conf->spread_bp); + goto out; + } + + sscg_ctrl |=3D 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, uns= igned long drate, writel_relaxed(FIELD_PREP(KDIV_MASK, rate.kdiv), pll->base + DIV_CTL1); =20 + __clk_pll1443x_set_spread_spectrum(hw, prate, rate.pdiv, + rate.mdiv); + spin_unlock_irqrestore(&pll->lock, flags); =20 return 0; @@ -411,6 +481,8 @@ static int clk_pll1443x_set_rate(struct clk_hw *hw, uns= igned long drate, =20 writel_relaxed(FIELD_PREP(KDIV_MASK, rate.kdiv), pll->base + DIV_CTL1); =20 + __clk_pll1443x_set_spread_spectrum(hw, prate, rate.pdiv, rate.mdiv); + spin_unlock_irqrestore(&pll->lock, flags); =20 /* @@ -437,6 +509,36 @@ static int clk_pll1443x_set_rate(struct clk_hw *hw, un= signed long drate, return 0; } =20 +static int clk_pll1443x_set_spread_spectrum(struct clk_hw *hw, + const struct clk_spread_spectrum *ss_conf) +{ + struct clk_pll14xx *pll =3D to_clk_pll14xx(hw); + struct clk_hw *parent =3D clk_hw_get_parent(hw); + unsigned long parent_rate =3D parent ? clk_hw_get_rate(parent) : 0; + unsigned long flags; + u32 div_ctl0; + + spin_lock_irqsave(&pll->lock, flags); + + pll->ss_conf =3D *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 =3D 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 =3D to_clk_pll14xx(hw); @@ -509,6 +611,7 @@ static const struct clk_ops clk_pll1443x_ops =3D { .recalc_rate =3D clk_pll14xx_recalc_rate, .determine_rate =3D clk_pll1443x_determine_rate, .set_rate =3D clk_pll1443x_set_rate, + .set_spread_spectrum =3D clk_pll1443x_set_spread_spectrum, }; =20 struct clk_hw *imx_dev_clk_hw_pll14xx(struct device *dev, const char *name, --=20 2.43.0