From patchwork Thu Dec 5 11:17:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 13895091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2935EE77170 for ; Thu, 5 Dec 2024 11:40:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RMocBLcHro+o7F7SOdKyuWq3E4fYkgXCw+gmS/pjce4=; b=jJ0LquvwGqamIsRMg/w9dPk0LG wcKWySvCW+iaBEZmMgyQKmLYAXDEiT2I94qpojEzmP31cdy44mO3SrWBmk7ag7dP050Ya6bodF/XN CNgK+C0w4hFg4w19UXbhz+VxRDkw0wIPaLXOxxO4NLSvvuoGoAqUYN6LJnuPBpLUz2ugqdGaYqEU3 UGsW2a0m8QJSXd0PZDNMm/YdBxL3mWd1azM7yBXJIthiJliQciIRoLPl3Ppi4tjwIsyYWRchD/qG0 56ZtyMHlZTVVyHf77JctFRVrs3xv6jsV+Je0Nb0rbCMRKjffhhwbLSiwR0fGoBimzs9YPQCsUNQhF 6r5If9dA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tJADL-0000000Fkfp-0qzz; Thu, 05 Dec 2024 11:40:11 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tJ9tz-0000000FglJ-3zR0 for linux-arm-kernel@lists.infradead.org; Thu, 05 Dec 2024 11:20:13 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5d0d4a2da4dso1186906a12.1 for ; Thu, 05 Dec 2024 03:20:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1733397610; x=1734002410; darn=lists.infradead.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; bh=RMocBLcHro+o7F7SOdKyuWq3E4fYkgXCw+gmS/pjce4=; b=CMkkc9KPiBLuOlbkNRe3679hjDYe5+joy4FBE9SNfYyE/I0TioxZ4qU42gekm7ZORt gYQHoF4kppiuPCtnplnF8cSoJkRxE5ED7O4nPknljAKnPCkH+3SbrnAxBZbelAvuGI/O TTmUcEXEjTT/wPnnD33Yq/lsQOUnjOyxidY2k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733397610; x=1734002410; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RMocBLcHro+o7F7SOdKyuWq3E4fYkgXCw+gmS/pjce4=; b=YbOMLpBisxybqi6CA2mCDJwK/UjZ3bs60GgA2gcp2tpvlfWgPcZh/inlQe9rh6JM+F YRSW5QEvmIyZohJNgyarIf/n6netqmZdra0vymFz5G3tGszGqnCcRKD6lI14SaUEj7iq zCZAM6tuA2/dwZaGcZCl/XVNy5bONuCOfuf9ql9DAj0mF0dH52i2bEpm0BYCJFkOC7Hz ezFFAh0S3U0Udsg36/JqDmNiOJIKt8+NIQ6kNryeN38JuuqWFjO0geTCIvChDm0pNsI3 wuPi9jYc+z/iKuWMWbNg6YHmYbmLcrqKR93w4dG/GwSa6odIcVj1pC/VXC08Oc0KV2xX DOtA== X-Forwarded-Encrypted: i=1; AJvYcCVVir6pHblEEG7sXKCwTpNjWcz0ol6YcqT17cMI72qlTOTDtw4tYPdpUcj25eLo2E0ovxPKVTi55X2JvU/IizqF@lists.infradead.org X-Gm-Message-State: AOJu0Yz8yQrVjZV+BA4TUZIWAWfKnmZ2STzfr1QBhn0/blOWZfMGHbQq U6roc75y6FP3dfd/UdIWXZg6CegMc9tbhTBG2vAZ07GzN2c7cn2MtnV5vISKv58= X-Gm-Gg: ASbGncutBglUFSwD0KQZVf+yUm65x+9fcXSbaH6PSMKsqRjbFN8BMJEBP18kFXAPm2/ kfLAqjDOx+kO9oEC6t42IrpHfuVJcJNzI6zqlQwpiXJoqrfDLOW4lDcucBThx3x55GuEDwhUxGT SyB0dm5iJ5I7Y/DiLl3NH5BkACjr3uNFP1t4IouG/r9/nExlIoNlwSC8fcdD3Gz2N+/lhq5TTm1 l1bSL36jwgs5BndBQTS4CyVSFObw/Ih8yQJWccnQj0zAeIxlhG9QV6N7LBK/TtzW6+a8UySLna+ uapY3Sy6xRaVJeem5TCtI9RGXYhHCGXeBYXStFetXYDTcw== X-Google-Smtp-Source: AGHT+IHv/Fr64yXiEsAqy/lH7qJb40cD7p0U+/rHAj8ItetqNUW7tmK2NTCHhIBQ/5FLqjRqUTU12A== X-Received: by 2002:a17:907:3a57:b0:aa6:2cfc:3157 with SMTP id a640c23a62f3a-aa62cfc4dffmr74669566b.33.1733397610192; Thu, 05 Dec 2024 03:20:10 -0800 (PST) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com ([2001:b07:6474:ebbf:61a1:9bc8:52c6:3c2d]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa625eedcd0sm77505266b.87.2024.12.05.03.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 03:20:09 -0800 (PST) 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 v5 19/20] clk: imx: pll14xx: support spread spectrum clock generation Date: Thu, 5 Dec 2024 12:17:54 +0100 Message-ID: <20241205111939.1796244-20-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241205111939.1796244-1-dario.binacchi@amarulasolutions.com> References: <20241205111939.1796244-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241205_032011_992064_48016407 X-CRM114-Status: GOOD ( 17.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support for spread spectrum clock (SSC) generation to the pll14xxx driver. Signed-off-by: Dario Binacchi --- (no changes since v1) drivers/clk/imx/clk-pll14xx.c | 126 ++++++++++++++++++++++++++++++++++ drivers/clk/imx/clk.h | 16 +++++ 2 files changed, 142 insertions(+) diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c index d63564dbb12c..1e66c3bb230d 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,94 @@ 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 } + }; + + pr_info("%s, name: %s\n", __func__, name); + 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; +} + +int imx_clk_pll14xx_ssc_parse_dt(struct device_node *np, const char *pll_name, + struct imx_pll14xx_ssc *conf) +{ + int i, ret, num_clks; + const char *s; + + if (!conf) + return -EINVAL; + + ret = of_property_count_strings(np, "clock-names"); + if (ret < 0) + return ret; + + num_clks = ret; + for (i = 0; i < num_clks; i++) { + ret = of_property_read_string_index(np, "clock-names", i, &s); + if (strcmp(pll_name, s)) + continue; + + ret = of_property_read_u32_index(np, "fsl,ssc-modfreq-hz", i, + &conf->mod_freq); + if (ret) + return ret; + + ret = of_property_read_u32_index(np, "fsl,ssc-modrate-percent", i, + &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", i, &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: mod_freq: %d, mod_rate: %d: mod_method: %s [%d]\n", + __func__, conf->mod_freq, conf->mod_rate, s, conf->mod_type); + + return 0; + } + + return -ENODEV; +} +EXPORT_SYMBOL_GPL(imx_clk_pll14xx_ssc_parse_dt); diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index 52055fda3058..edd28b78b115 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; @@ -494,4 +506,8 @@ struct clk_hw *imx_clk_gpr_mux(const char *name, const char *compatible, struct clk_hw *imx8m_anatop_get_clk_hw(int id); #endif +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