From patchwork Sun Sep 29 17:27:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3538 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id EE1E63FA24 for ; Sun, 29 Sep 2024 19:27:51 +0200 (CEST) Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a8d13a9cc7asf272610766b.1 for ; Sun, 29 Sep 2024 10:27:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1727630871; cv=pass; d=google.com; s=arc-20240605; b=ZGWIVcJm650+24vwZ42CnJisWGAyRbR9g38sW3y0TxaRCXC9ndtwDo/BH1kPUeH7st pJAi+kqH+mG20GoV/mnMzBVXSlmboEAVSSHprQoYLZC5Qc7vr/4z70/dXZbQ03DwcbQe Tw9nifAj6OJJw/me4p3iWrJ+BPazIuUj8wQb9JN/b7tCeEz40LiY5yEutra8SlhFOsNd aEiOW0ZHf2NCVbrdkVZBs21u4tOhopl0ZJRUCg5Pzk1HIb/tansKvxhm05HkOjPd0yVB 9klXKkPtXxcPS8pFvez7GofTCOe0RPh2vhKjIevxywyGPQkKH3MBW0X4G6I0Ar4nj++H XJkw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=hDpHbkpfdx4gXd1JCeuNz3EmiSCdKkWZGM7BYT+VG9o=; fh=/ByvMSqipvj+jWNAi7r5Uiu5Jez+jLdD6DOTcw4NEcI=; b=GW+s6VS63b5zI/r10Y8VKLZ1gysuoOCoum5nMQ34sXrIkBkxs8hK/anBRwh17ybMto Fs98MGpbaMwtQ66Ss9pXz+yUyt1fMviSoLQ4VvmkN/o6yynuXm8vSRTIq2Q5x1QCYVYQ cvjDMqghK3wtY/4MJouJT5/7ahAxikYZMkEriIupxgmi82wTKpYq+PW8/AZ4C1oD0S1X 7GCeADg/v8m/jHuBjJ79zZkhuYnejYwvTNIHn8GUBmNwrhIjELpXzxqmTXza/ac6F3mL 0XYKeg7Ex3ZnCRVOpb9myE8rxIGdkJ+JBJf3njat0o5Thw4qVZY2+VBfLHKXdttNSvoi yndA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=H89UFI0p; 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=pass header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1727630871; x=1728235671; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence: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; bh=hDpHbkpfdx4gXd1JCeuNz3EmiSCdKkWZGM7BYT+VG9o=; b=U4vDvT7L8bRgX8sAbC13M9EWf4wMzjE7Mk52z+8LTCzl3/TUKLhW0YJztC+uPtNjAr qZdIFkFVhUaU0sYK7AJNZvwoii6NSz+MqIUgm6S4gPF9OzXenI5GaXU6JqsKKeWo4Rlo iEUHmQNPMjTuhI01rPtw/d7es4zhj/nXuPNe8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727630871; x=1728235671; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hDpHbkpfdx4gXd1JCeuNz3EmiSCdKkWZGM7BYT+VG9o=; b=uehfPMBmQ5VcUtZhJw7k4ZOE2keIlGmUoUocj4yHqDX9JnbBULWd6GVV2muuFF9u87 n+nnHtKKlY5C7h/hTLHPMVzW3Z22xrIO4+NwxqNQILkXgEBhRwqxvS7lMYqGvg8M6U0U 1Ec5SUiT8ZxiY/ROVZAmwinrFNAMau0NZ+ds0DAwsEG2SBYilbcM7khe1HYaj5hDYfvV 7evqyNIYbMYzBxjSPQXaazp+aK7MCwnLqzRlQUAkyahUzYNiQ55I5TJwNkv+RF8DyOUZ pC11vdWiste+bbiO0aVC/by3B7Qe9PshI8YmtRpJm53RBo1dD53B6I5ZwrFpU0+rhmuy UhzA== X-Forwarded-Encrypted: i=2; AJvYcCVMPfwf5Tc3GBz7qT7PMPrmfCsYWz4xAQwhrdUEt1o6IScLC3SVg3JUKtxTYFnZoqCjuG2/6TaFjm9Jhsax@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YzJZa2UIT85HMSWB+ITfQJ2k2M7laRH68FmGTL6UgOQTsWEcifu lDJ3Y4YAaxUNjCXaTKlRueEIkheojJIu3hL/asa2sSXJFMqMufg9+ipLPnCCWODEtQ== X-Google-Smtp-Source: AGHT+IFcKbpd4ofuwJ9JP5W8vsCpqTFNVUxsif+T9ayiXqUpCYhIHG04n0DPbCj4RxQ+GlJf9zHeuQ== X-Received: by 2002:a17:906:dc92:b0:a8a:926a:d02a with SMTP id a640c23a62f3a-a93c4adebfcmr905669566b.49.1727630871136; Sun, 29 Sep 2024 10:27:51 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:1ed1:b0:5c4:20f0:95bb with SMTP id 4fb4d7f45d1cf-5c87776511dls1148894a12.0.-pod-prod-09-eu; Sun, 29 Sep 2024 10:27:50 -0700 (PDT) X-Received: by 2002:a17:907:3d8d:b0:a8a:926a:d027 with SMTP id a640c23a62f3a-a93c4adeca2mr1132804566b.45.1727630869541; Sun, 29 Sep 2024 10:27:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727630869; cv=none; d=google.com; s=arc-20160816; b=udL4NVOwbY9KncZCMFjZ/ZLuBFzeZHjTDteOI4A+7v8WujvYoVa0WPaa07yXhEs9aq wKZQ6z8jzAW6beUr3SlTCMDNdQBIYpnVmUfQtsmHQeg1LZUQ2DYXv/vk9pJVYO0fJH4U S36nmhUuFrcPRHjpss1/ynQkHi/4p/2Vrth8MtfCPaGXy35rko01APM/0JOTeESknmLS /4FBD/8jXCxVskqbBLHsuDf3qoylEI+G5HakpY/TNiR8GQ1TCcuImhPA4tyT0yfLGhMT GM5tpFvWPpS47hi3pNPCY7ZVOoX3eo4OHu6rv6eD7LvycgDV0kxnd+J19SpYYPwu75um WNVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=HYFE+8+xJyXnOIazKfuEkYOBmIG07KamRjf0rhIE9ik=; fh=u/u80m6tBSaxW7VWG5AQatIbYzkIAnRGhZp/RTASK5o=; b=h0EL6hk8O0kcSVCkKEzY7UIaj70XgOLDQpjlJEPpsA0dMScU5ljlxdOAdGyMJnJmDI jGn3qnIEbntKMcMnBIyLv8+RsoeDEzdrp0BLOoFBbm3uzAhFPCSXZmHKeycONiVM6LlG Jt4Y3j77+gcnBIWxKmmQw+05S7BqSzj/dJdiQdC/M2FFGAHDBPmOz5rQxjbdKa4U2U1G Sz96my+iX8Ll0FRDIEpDcocSZy8N1urpDcy1nISaaqmmb5nsgTbUpyVu+8qkCFYNrLkC nwg2BJXsQcbKI7Zs5RjVO6CVVCjCSynBpKyjeUIKQw4sjPOhb7F+XKj2ji0tGwoAXiF+ qMuA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=H89UFI0p; 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=pass 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 a640c23a62f3a-a93c2979a1csor204579466b.20.2024.09.29.10.27.49 for (Google Transport Security); Sun, 29 Sep 2024 10:27:49 -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-Received: by 2002:a17:906:da85:b0:a8d:35cf:85f6 with SMTP id a640c23a62f3a-a93c4c26a25mr860443366b.57.1727630869076; Sun, 29 Sep 2024 10:27:49 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-79-54-102-102.retail.telecomitalia.it. [79.54.102.102]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c27776a1sm403176866b.8.2024.09.29.10.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Sep 2024 10:27:48 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: linux-amarula@amarulasolutions.com, Dario Binacchi , Abel Vesa , Fabio Estevam , Michael Turquette , Peng Fan , Pengutronix Kernel Team , Sascha Hauer , Shawn Guo , Stephen Boyd , imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org Subject: [PATCH v2 2/6] clk: imx: pll14xx: support spread spectrum clock generation Date: Sun, 29 Sep 2024 19:27:12 +0200 Message-ID: <20240929172743.1758292-3-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240929172743.1758292-1-dario.binacchi@amarulasolutions.com> References: <20240929172743.1758292-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=H89UFI0p; 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=pass 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: , This patch adds support for spread spectrum clock (SSC) generation for the pll14xxx. The addition of the "imx_clk_hw_pll14xx_ssc" macro has minimized the number of changes required to avoid compilation errors following the addition of the SSC setup parameter to the "imx_dev_clk_hw_pll14xx" macro used in the files clk-imx8m{m,n,p}.c. The change to the clk-imx8mp-audiomix.c file prevents the patch from causing a compilation error. Signed-off-by: Dario Binacchi --- (no changes since v1) drivers/clk/imx/clk-imx8mp-audiomix.c | 2 +- drivers/clk/imx/clk-pll14xx.c | 102 +++++++++++++++++++++++++- drivers/clk/imx/clk.h | 24 +++++- 3 files changed, 124 insertions(+), 4 deletions(-) diff --git a/drivers/clk/imx/clk-imx8mp-audiomix.c b/drivers/clk/imx/clk-imx8mp-audiomix.c index b2cb157703c5..bfcf2975c217 100644 --- a/drivers/clk/imx/clk-imx8mp-audiomix.c +++ b/drivers/clk/imx/clk-imx8mp-audiomix.c @@ -365,7 +365,7 @@ static int clk_imx8mp_audiomix_probe(struct platform_device *pdev) clk_hw_data->hws[IMX8MP_CLK_AUDIOMIX_SAI_PLL_REF_SEL] = hw; hw = imx_dev_clk_hw_pll14xx(dev, "sai_pll", "sai_pll_ref_sel", - base + 0x400, &imx_1443x_pll); + base + 0x400, &imx_1443x_pll, NULL); if (IS_ERR(hw)) { ret = PTR_ERR(hw); goto err_clk_register; diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c index d63564dbb12c..76014e243a57 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,7 @@ struct clk_pll14xx { enum imx_pll14xx_type type; const struct imx_pll14xx_rate_table *rate_table; int rate_count; + struct imx_pll14xx_ssc ssc; }; #define to_clk_pll14xx(_hw) container_of(_hw, struct clk_pll14xx, hw) @@ -347,6 +354,27 @@ static int clk_pll1416x_set_rate(struct clk_hw *hw, unsigned long drate, return 0; } +static void clk_pll1443x_set_sscg(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 *ssc = &pll->ssc; + u32 sscg_ctrl = readl_relaxed(pll->base + SSCG_CTRL); + + sscg_ctrl &= + ~(SSCG_ENABLE | MFREQ_CTL_MASK | MRAT_CTL_MASK | SEL_PF_MASK); + if (ssc->enable) { + u32 mfr = parent_rate / (ssc->mod_freq * pdiv * (1 << 5)); + u32 mrr = (ssc->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, ssc->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 +396,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_set_sscg(hw, prate, rate.pdiv, rate.mdiv); + return 0; } @@ -408,6 +439,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_set_sscg(hw, prate, rate.pdiv, rate.mdiv); + return 0; } @@ -487,7 +521,8 @@ static const struct clk_ops clk_pll1443x_ops = { struct clk_hw *imx_dev_clk_hw_pll14xx(struct device *dev, const char *name, const char *parent_name, void __iomem *base, - const struct imx_pll14xx_clk *pll_clk) + const struct imx_pll14xx_clk *pll_clk, + const struct imx_pll14xx_ssc *ssc) { struct clk_pll14xx *pll; struct clk_hw *hw; @@ -525,6 +560,8 @@ struct clk_hw *imx_dev_clk_hw_pll14xx(struct device *dev, const char *name, pll->type = pll_clk->type; pll->rate_table = pll_clk->rate_table; pll->rate_count = pll_clk->rate_count; + if (ssc) + memcpy(&pll->ssc, ssc, sizeof(pll->ssc)); val = readl_relaxed(pll->base + GNRL_CTL); val &= ~BYPASS_MASK; @@ -542,3 +579,66 @@ struct clk_hw *imx_dev_clk_hw_pll14xx(struct device *dev, const char *name, return hw; } EXPORT_SYMBOL_GPL(imx_dev_clk_hw_pll14xx); + +static enum imx_pll14xx_ssc_mod_type clk_pll14xx_ssc_mode(const char *name, + enum imx_pll14xx_ssc_mod_type def) +{ + int i; + struct { + const char *name; + enum imx_pll14xx_ssc_mod_type id; + } mod_methods[] = { + { .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_methods); i++) { + if (!strcmp(name, mod_methods[i].name)) + return mod_methods[i].id; + } + + return def; +} + +void imx_clk_pll14xx_get_ssc_conf(struct device_node *np, int pll_id, + struct imx_pll14xx_ssc *ssc) +{ + int i, ret, offset, num_clks; + u32 clk_id, clk_cell_size; + const char *s; + + if (!ssc) + return; + + memset(ssc, 0, sizeof(*ssc)); + + num_clks = of_count_phandle_with_args(np, "fsl,ssc-clocks", + "#clock-cells"); + if (num_clks <= 0) + return; + + ret = of_property_read_u32(np, "#clock-cells", &clk_cell_size); + if (ret) + return; + + for (i = 0; i < num_clks; i++) { + offset = i * clk_cell_size + 1; + of_property_read_u32_index(np, "fsl,ssc-clocks", offset, + &clk_id); + if (clk_id != pll_id) + continue; + + of_property_read_u32_index(np, "fsl,ssc-modfreq-hz", i, + &ssc->mod_freq); + of_property_read_u32_index(np, "fsl,ssc-modrate-percent", i, + &ssc->mod_rate); + if (!of_property_read_string(np, "fsl,ssc-modmethod", &s)) + ssc->mod_type = clk_pll14xx_ssc_mode( + s, IMX_PLL14XX_SSC_DOWN_SPREAD); + + ssc->enable = true; + break; + } +} +EXPORT_SYMBOL_GPL(imx_clk_pll14xx_get_ssc_conf); diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index aa5202f284f3..8cbc75480569 100644 --- a/drivers/clk/imx/clk.h +++ b/drivers/clk/imx/clk.h @@ -62,6 +62,19 @@ struct imx_pll14xx_rate_table { unsigned int kdiv; }; +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 { + bool enable; + unsigned int mod_freq; + unsigned int mod_rate; + enum imx_pll14xx_ssc_mod_type mod_type; +}; + struct imx_pll14xx_clk { enum imx_pll14xx_type type; const struct imx_pll14xx_rate_table *rate_table; @@ -222,11 +235,18 @@ extern struct imx_fracn_gppll_clk imx_fracn_gppll_integer; __imx_clk_hw_divider(name, parent, reg, shift, width, flags) #define imx_clk_hw_pll14xx(name, parent_name, base, pll_clk) \ - imx_dev_clk_hw_pll14xx(NULL, name, parent_name, base, pll_clk) + imx_dev_clk_hw_pll14xx(NULL, name, parent_name, base, pll_clk, NULL) + +#define imx_clk_hw_pll14xx_ssc(name, parent_name, base, pll_clk, ssc) \ + imx_dev_clk_hw_pll14xx(NULL, name, parent_name, base, pll_clk, ssc) struct clk_hw *imx_dev_clk_hw_pll14xx(struct device *dev, const char *name, const char *parent_name, void __iomem *base, - const struct imx_pll14xx_clk *pll_clk); + const struct imx_pll14xx_clk *pll_clk, + const struct imx_pll14xx_ssc *ssc); + +void imx_clk_pll14xx_get_ssc_conf(struct device_node *np, int pll_id, + struct imx_pll14xx_ssc *ssc); struct clk_hw *imx_clk_hw_pllv1(enum imx_pllv1_type type, const char *name, const char *parent, void __iomem *base);