From patchwork Sun Dec 1 17:46:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3688 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id B45923F033 for ; Sun, 1 Dec 2024 18:47:54 +0100 (CET) Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5d0b063a162sf2375464a12.0 for ; Sun, 01 Dec 2024 09:47:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1733075274; cv=pass; d=google.com; s=arc-20240605; b=VGDxIvHYsIGiVzi/BECenunLzoaKjlSaiziLdjFTYcsvI05BAeyAPwMeZ6CFFgcGYS p1ODeG4wV5kotSL1r7vDqUyQFxpidQZj1KWgSeQ1wsAPF0CO7tjQZ7RLKlqgLCYl6yav 9vALrDGClFTv+fBhmUdGcbh4fBbz6Do+RrkgXvy4pzpVXbmQ5FLed3kgAjqNtihvUTjq 19tLw5Ylq/fvwiBFlhUx1yn69R+5xqhPCqLBEL4GZeUckRnDsUT6B6vcruWVu5mdaK/S RjyzghMkDh1ToRtudIfPK9p57vA7oh5Q8Zp9XyR+eG/SzHxwTlg0qT41tJKqwGNLdbsi igcg== 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=7yTTxPYBRvHOHf4I95C0ZaF2c1eD08vYzvjkCvB7wec=; fh=GJVvUHlNo6ct+4u9H1SkMS0eFy74YJlKvqCWIf2RCxw=; b=QKANDerCEhNM/MJXeIwJf0iD8PF/bEj2/3aPhHpPDBRyZEanhKtc+Y0XOB9VehSJ09 LsE+3XFqlGs2IAMHE87P4+OYUsAq5/kDnXHSgosuVeTDypcg6K9arBtsLlXbA7UJqMsB Y9BHf1x1ohM7wpFdtvGyTMeci6BBv1C7LOQ/bNGydlXx1xWFv/VP+bWBwhLlKsxdXEOk RBfZM2ULPgzFPPNDzbkOYPZxuUpK2bBK0xJ0uC+FFIa8yS9PBUvNGgi7ODrLCi79Pyho IoHxpHWGt3Oe2Rw9N2HS7SWgHUuYC+sTIsV6oF3hvP/Wb/lpxO1hy6RQzqn9eDYueD4B Yk6g==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ae0plQ3A; 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=1733075274; x=1733680074; 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=7yTTxPYBRvHOHf4I95C0ZaF2c1eD08vYzvjkCvB7wec=; b=I+CBK3JEkvUUHbDm7qWoo6hoCxbqJepXp0yZxvkEcx8+PYSKtS/6aLVSrKkBfv/z5F c6qJAMScgftPMGjJFBNiYfO6io2GZwp/O8L8OHFBU07Mzv3jR/nmHPeNb6pyRBqo7ibE 7pMmNLCk3/eQeyf/54IH+qwFDoFmtWfM8zaAk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733075274; x=1733680074; 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=7yTTxPYBRvHOHf4I95C0ZaF2c1eD08vYzvjkCvB7wec=; b=G6hpTbMNkvLf+kc/p6pLWwmVE3jeCTDEVK/aBI6469+zhOlcJqfybE7xmxTVWLUm8F GXaUlQ2RhQTcNb9TC25FVKMhymGCP9HhtDo+COkY4mrUNdOqRIMT0xyN2TsWM95fidss EyeNJ7nFI/OHVGiDkZIGQTkuodYulHMAYu4O1VySTu7RwSAz0E5yEKYeBm0sLx7bO9B/ 3CG+uBsTrakl5yLNo4PKGJ6ljRsqltTR7if94uxfSYeEX+FUqJ41K3n44Kszx/c91t34 upWqWflUz3P+zonOQXABfxNgrxrZ+152rVoYftDcV4gqxabv5j0dcQUA2Hci24C5i7/c v9Qg== X-Forwarded-Encrypted: i=2; AJvYcCVGvfrIKuptHratsiVFATeeEnidAr6PQLKmLGNTTKzl9KY8DelJlC3rTfpWw7xGC2EfG/bcJ3nDrlV2gzZY@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YyV2qxs7ZrRsfRXg7q4S2T4FmWaGmi9mN5knURdSnnQJt/3ww9/ 7mmwpX/KrU4MMj6UWmAvBEbhfPLpaBkkiDi5hKnmGLVT29ftt+tHLe0jTqKVKjxgBw== X-Google-Smtp-Source: AGHT+IFuK5VOCtFaOp9FrVgmVg6Yn14pCpgaHzY1Z8AuGKSOBKZcgTMs1nwCzjeadTUN9lFH9Tyo6w== X-Received: by 2002:a05:6402:2809:b0:5d0:b61a:89c9 with SMTP id 4fb4d7f45d1cf-5d0b61a8be1mr11587415a12.5.1733075274424; Sun, 01 Dec 2024 09:47:54 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:aa7:c0d6:0:b0:5d0:b1e8:b0c3 with SMTP id 4fb4d7f45d1cf-5d0b1e8b5dals787599a12.0.-pod-prod-00-eu; Sun, 01 Dec 2024 09:47:53 -0800 (PST) X-Received: by 2002:a17:907:3e83:b0:a9a:662f:ff4a with SMTP id a640c23a62f3a-aa59431fad7mr1907546366b.0.1733075272710; Sun, 01 Dec 2024 09:47:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733075272; cv=none; d=google.com; s=arc-20240605; b=PvnWS1iuzzn77kAeaa+fEiaw7D/iis6V9iSwEmKUnnsOdojt6xVYl7B7kb3S52y30v y/NEjDJmPnTv/iXKdF2Z6vi9dWhmMJ18iS47gUCZWNmQSM//8ptDn+snJeiBBwhd3m3P bydS6hZwYpKsT41fpI2/2S1LF+VZROiCC980M1mwKQO6T52lW/QqsOM/kV5z8CbctoRP RatTm6wOOA5TiX+kTThVY/f2LUd3Yg5a81SmyczvriIcUj0g5mVkPXo/C7nZ0g2hrYkB bYk/9K72wUEtOVfycgH7qyBUIRWFBGP4ceFhlkQfWJzTy+RjYEQcmUJpNizjlcl3VNPK j1HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=KkX+s5EHVn/U/f89vXhboloGzSq+GXoMTZ4AsN/1EgI=; fh=u/u80m6tBSaxW7VWG5AQatIbYzkIAnRGhZp/RTASK5o=; b=N72JtJFYe2H68BkuNaSF8MgpR1Z5+YpOUIPbVteLJmiC3nYIIXZwwEi+TCopoLYtz9 LpoFfnQ4BfTMfN25w0dTY8Z1gC4kxul6Ki1qFUZ9UhYYWCO8xNkR0yZClZGdCF0xNSo2 GCqg4vwtihSG/fJKfKMq4I+sNvZlAWPseJBPfmqxRWyXH/mIbbgT9xke1wiyd6hA1hYQ YN+NuwrqxmD3hKp+Ikvw/plc2U0CNHY4LJoIAfaGy/xQOVRoI8XSOhd3GSNUkt1UrJGz Wi15Kn2zBSrYxHsWT1HfOAkxuIh1UH/awHKU7oJqV85YfwqfsRjMspPkLsGAw0RX4p9m 5LDw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ae0plQ3A; 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-aa5974c6814sor266035966b.0.2024.12.01.09.47.52 for (Google Transport Security); Sun, 01 Dec 2024 09:47:52 -0800 (PST) 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: ASbGnctNhi6Jpk0mqKuxCBDqADPhf4YI1c6Q+MrhVgduGtAqKe3k0OtNK0QpxLNaleE eXQQqQRndzeQ4sx23NRknC5yfGvSLvV+J9FtVLhFjpTCL0300Lxai13ITprKGTqmliPUpVzI9Hp AfTxN585o2/B9nGTSVm1alX8W2oQzY4d8B0Rgo9Ieu8ocJU3hqBybOnvgHA6pRgzZm6Qoqk0n4W tcXgAyAVvNRB4xtXKMmY8n8HIYcePmY7yiBlpwZa0k9XbSumh37AYEx3xQzoKVlKncbbd+tYSmj u0Tr91YI5npfgh58lP+7xJZeUdgYDiZerBJHEbRrVGptD2y/YWCmoBmtZFtf9LInX9QjIXOglCN j/C03pINzlanUirsc X-Received: by 2002:a17:907:9494:b0:aa5:63a0:5d97 with SMTP id a640c23a62f3a-aa5945cdbdcmr2003825166b.13.1733075272328; Sun, 01 Dec 2024 09:47:52 -0800 (PST) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-82-54-94-193.retail.telecomitalia.it. [82.54.94.193]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa59990a78esm415220066b.163.2024.12.01.09.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Dec 2024 09:47:51 -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 v4 17/18] clk: imx: pll14xx: support spread spectrum clock generation Date: Sun, 1 Dec 2024 18:46:17 +0100 Message-ID: <20241201174639.742000-18-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241201174639.742000-1-dario.binacchi@amarulasolutions.com> References: <20241201174639.742000-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=ae0plQ3A; 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: , 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 | 127 ++++++++++++++++++++++++++++++++++ drivers/clk/imx/clk.h | 16 +++++ 2 files changed, 143 insertions(+) diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c index d63564dbb12c..b07c59fd659a 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,95 @@ 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 6b6af26f4f1e..dad6e90c7dc0 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; @@ -493,4 +505,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