From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
To: linux-kernel@vger.kernel.org
Cc: linux-amarula@amarulasolutions.com,
Dario Binacchi <dario.binacchi@amarulasolutions.com>,
Peng Fan <peng.fan@nxp.com>, Abel Vesa <abelvesa@kernel.org>,
Fabio Estevam <festevam@gmail.com>,
Michael Turquette <mturquette@baylibre.com>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Sascha Hauer <s.hauer@pengutronix.de>,
Shawn Guo <shawnguo@kernel.org>, Stephen Boyd <sboyd@kernel.org>,
imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-clk@vger.kernel.org
Subject: [PATCH v8 17/18] clk: imx: pll14xx: support spread spectrum clock generation
Date: Sun, 29 Dec 2024 15:49:41 +0100 [thread overview]
Message-ID: <20241229145027.3984542-18-dario.binacchi@amarulasolutions.com> (raw)
In-Reply-To: <20241229145027.3984542-1-dario.binacchi@amarulasolutions.com>
Add support for spread spectrum clock (SSC) generation to the pll14xxx
driver.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
---
(no changes since v7)
Changes in v7:
- Add 'Reviewed-by' tag of Peng Fan
Changes in v6:
- Update the code based on the changes made to the DT bindings
drivers/clk/imx/clk-pll14xx.c | 134 ++++++++++++++++++++++++++++++++++
drivers/clk/imx/clk.h | 16 ++++
2 files changed, 150 insertions(+)
diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c
index d63564dbb12c..c20f1ade9dff 100644
--- a/drivers/clk/imx/clk-pll14xx.c
+++ b/drivers/clk/imx/clk-pll14xx.c
@@ -20,6 +20,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)
@@ -31,6 +33,10 @@
#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_MASK GENMASK(1, 0)
#define LOCK_TIMEOUT_US 10000
@@ -40,6 +46,8 @@ struct clk_pll14xx {
enum imx_pll14xx_type type;
const struct imx_pll14xx_rate_table *rate_table;
int rate_count;
+ bool ssc_enable;
+ struct imx_pll14xx_ssc ssc_conf;
};
#define to_clk_pll14xx(_hw) container_of(_hw, struct clk_pll14xx, hw)
@@ -347,6 +355,27 @@ static int clk_pll1416x_set_rate(struct clk_hw *hw, unsigned long drate,
return 0;
}
+static void clk_pll1443x_enable_ssc(struct clk_hw *hw, unsigned long parent_rate,
+ unsigned int pdiv, unsigned int mdiv)
+{
+ struct clk_pll14xx *pll = to_clk_pll14xx(hw);
+ struct imx_pll14xx_ssc *conf = &pll->ssc_conf;
+ u32 sscg_ctrl, mfr, mrr;
+
+ sscg_ctrl = readl_relaxed(pll->base + SSCG_CTRL);
+ sscg_ctrl &=
+ ~(SSCG_ENABLE | MFREQ_CTL_MASK | MRAT_CTL_MASK | SEL_PF_MASK);
+
+ mfr = parent_rate / (conf->mod_freq * pdiv * (1 << 5));
+ mrr = (conf->mod_rate * mdiv * (1 << 6)) / (100 * mfr);
+
+ sscg_ctrl |= SSCG_ENABLE | FIELD_PREP(MFREQ_CTL_MASK, mfr) |
+ FIELD_PREP(MRAT_CTL_MASK, mrr) |
+ FIELD_PREP(SEL_PF_MASK, conf->mod_type);
+
+ writel_relaxed(sscg_ctrl, pll->base + SSCG_CTRL);
+}
+
static int clk_pll1443x_set_rate(struct clk_hw *hw, unsigned long drate,
unsigned long prate)
{
@@ -368,6 +397,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);
+ if (pll->ssc_enable)
+ clk_pll1443x_enable_ssc(hw, prate, rate.pdiv, rate.mdiv);
+
return 0;
}
@@ -408,6 +440,9 @@ static int clk_pll1443x_set_rate(struct clk_hw *hw, unsigned long drate,
gnrl_ctl &= ~BYPASS_MASK;
writel_relaxed(gnrl_ctl, pll->base + GNRL_CTL);
+ if (pll->ssc_enable)
+ clk_pll1443x_enable_ssc(hw, prate, rate.pdiv, rate.mdiv);
+
return 0;
}
@@ -542,3 +577,102 @@ struct clk_hw *imx_dev_clk_hw_pll14xx(struct device *dev, const char *name,
return hw;
}
EXPORT_SYMBOL_GPL(imx_dev_clk_hw_pll14xx);
+
+void imx_clk_pll14xx_enable_ssc(struct clk_hw *hw, struct imx_pll14xx_ssc *conf)
+{
+ struct clk_pll14xx *pll = to_clk_pll14xx(hw);
+
+ pll->ssc_enable = true;
+ memcpy(&pll->ssc_conf, conf, sizeof(pll->ssc_conf));
+}
+EXPORT_SYMBOL_GPL(imx_clk_pll14xx_enable_ssc);
+
+static int clk_pll14xx_ssc_mod_type(const char *name,
+ enum imx_pll14xx_ssc_mod_type *mod_type)
+{
+ int i;
+ struct {
+ const char *name;
+ enum imx_pll14xx_ssc_mod_type id;
+ } mod_types[] = {
+ { .name = "down-spread", .id = IMX_PLL14XX_SSC_DOWN_SPREAD },
+ { .name = "up-spread", .id = IMX_PLL14XX_SSC_UP_SPREAD },
+ { .name = "center-spread", .id = IMX_PLL14XX_SSC_CENTER_SPREAD }
+ };
+
+ for (i = 0; i < ARRAY_SIZE(mod_types); i++) {
+ if (!strcmp(name, mod_types[i].name)) {
+ *mod_type = mod_types[i].id;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+static int clk_pll14xx_ssc_index(const char *pll_name)
+{
+ static const char *const pll_names[] = {
+ "audio_pll1",
+ "audio_pll2",
+ "dram_pll",
+ "video_pll"
+ };
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(pll_names); i++) {
+ if (!strcmp(pll_names[i], pll_name))
+ return i;
+ }
+
+ return -ENODEV;
+}
+
+int imx_clk_pll14xx_ssc_parse_dt(struct device_node *np, const char *pll_name,
+ struct imx_pll14xx_ssc *conf)
+{
+ int index, ret;
+ const char *s;
+
+ if (!conf)
+ return -EINVAL;
+
+ index = clk_pll14xx_ssc_index(pll_name);
+ if (index < 0)
+ return index;
+
+ ret = of_property_read_u32_index(np, "fsl,ssc-modfreq-hz", index,
+ &conf->mod_freq);
+ if (ret)
+ return ret;
+
+ ret = of_property_read_u32_index(np, "fsl,ssc-modrate-percent", index,
+ &conf->mod_rate);
+ if (ret) {
+ pr_err("missing fsl,ssc-modrate-percent property for %pOFn\n",
+ np);
+ return ret;
+ }
+
+ ret = of_property_read_string_index(np, "fsl,ssc-modmethod", index, &s);
+ if (ret) {
+ pr_err("failed to get fsl,ssc-modmethod property for %pOFn\n",
+ np);
+ return ret;
+ }
+
+ if (strlen(s) == 0)
+ return -ENODEV;
+
+ ret = clk_pll14xx_ssc_mod_type(s, &conf->mod_type);
+ if (ret) {
+ pr_err("wrong fsl,ssc-modmethod property for %pOFn\n", np);
+ return ret;
+ }
+
+ pr_debug("%s: SSC %s settings: mod_freq: %d, mod_rate: %d: mod_method: %s [%d]\n",
+ __func__, pll_name, conf->mod_freq, conf->mod_rate, s, conf->mod_type);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(imx_clk_pll14xx_ssc_parse_dt);
diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h
index 50e407cf48d9..38e4a4cf253d 100644
--- a/drivers/clk/imx/clk.h
+++ b/drivers/clk/imx/clk.h
@@ -69,6 +69,18 @@ struct imx_pll14xx_clk {
int flags;
};
+enum imx_pll14xx_ssc_mod_type {
+ IMX_PLL14XX_SSC_DOWN_SPREAD,
+ IMX_PLL14XX_SSC_UP_SPREAD,
+ IMX_PLL14XX_SSC_CENTER_SPREAD,
+};
+
+struct imx_pll14xx_ssc {
+ unsigned int mod_freq;
+ unsigned int mod_rate;
+ enum imx_pll14xx_ssc_mod_type mod_type;
+};
+
extern struct imx_pll14xx_clk imx_1416x_pll;
extern struct imx_pll14xx_clk imx_1443x_pll;
extern struct imx_pll14xx_clk imx_1443x_dram_pll;
@@ -489,4 +501,8 @@ struct clk_hw *imx_clk_gpr_mux(const char *name, const char *compatible,
struct clk_hw *imx_anatop_get_clk_hw(struct device_node *np, int id);
+void imx_clk_pll14xx_enable_ssc(struct clk_hw *hw, struct imx_pll14xx_ssc *conf);
+int imx_clk_pll14xx_ssc_parse_dt(struct device_node *np, const char *pll_name,
+ struct imx_pll14xx_ssc *conf);
+
#endif
--
2.43.0
next prev parent reply other threads:[~2024-12-29 15:12 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-29 14:49 [PATCH v8 00/18] Support spread spectrum clocking for i.MX8N PLLs Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 01/18] dt-bindings: clock: imx8mm: add VIDEO_PLL clocks Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 02/18] clk: imx8mm: rename video_pll1 to video_pll Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 03/18] dt-bindings: clock: imx8mp: add VIDEO_PLL clocks Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 04/18] clk: imx8mp: rename video_pll1 to video_pll Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 05/18] dt-bindings: clock: imx8m-anatop: add oscillators and PLLs Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 06/18] arm64: dts: imx8mm: add anatop clocks Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 07/18] arm64: dts: imx8mn: " Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 08/18] arm64: dts: imx8mp: " Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 09/18] arm64: dts: imx8mq: " Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 10/18] clk: imx: add hw API imx_anatop_get_clk_hw Dario Binacchi
2025-01-06 9:04 ` Peng Fan
2024-12-29 14:49 ` [PATCH v8 11/18] clk: imx: add support for i.MX8MN anatop clock driver Dario Binacchi
2025-01-06 9:05 ` Peng Fan
2025-01-06 11:06 ` Dan Carpenter
2024-12-29 14:49 ` [PATCH v8 12/18] dt-bindings: clock: imx8m-clock: add PLLs Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 13/18] arm64: dts: imx8mm: add PLLs to clock controller module (CCM) Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 14/18] arm64: dts: imx8mn: " Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 15/18] arm64: dts: imx8mp: " Dario Binacchi
2024-12-29 14:49 ` [PATCH v8 16/18] dt-bindings: clock: imx8m-clock: support spread spectrum clocking Dario Binacchi
2024-12-29 14:49 ` Dario Binacchi [this message]
2024-12-29 14:49 ` [PATCH v8 18/18] clk: imx8mn: support spread spectrum clock generation Dario Binacchi
2025-01-06 9:06 ` Peng Fan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241229145027.3984542-18-dario.binacchi@amarulasolutions.com \
--to=dario.binacchi@amarulasolutions.com \
--cc=abelvesa@kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=linux-amarula@amarulasolutions.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=peng.fan@nxp.com \
--cc=s.hauer@pengutronix.de \
--cc=sboyd@kernel.org \
--cc=shawnguo@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox