From patchwork Fri Dec 27 16:56:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3761 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id A927843436 for ; Fri, 27 Dec 2024 17:58:01 +0100 (CET) Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-5d3f01eeef8sf6808188a12.0 for ; Fri, 27 Dec 2024 08:58:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1735318681; cv=pass; d=google.com; s=arc-20240605; b=Or3ESetcTL5mV2z4BA/FL21jRvoUrn8EPQkVgqSqWXmBsq7H4W7m1wGJUv2nuRuPzN +5rqD1cmCwWqzVYNasPsrcB+SVvfCbC81/2HITIigG/XdXajbl9tRPu9JOayT6cx5RKO E1PFJZpdBi7Us5MT8oSevxDWRMyJMBvGALqw0PgqXmpnYRUYwcngqnvpVKAq9sl5gSE+ 9ncqoOc09u3bM5zPqFDyMqcXvUWYUVHOkUPoEICTzcmgZMbb5hXl+jvy79Lk9RuJtdXe Q91r9UfcCOq1M2OB6jmD6LoGKjHvjatlYlet9T6WR3ffsRCVf0QIQR46GQaWSfBIfbni iuDw== 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=UcsG9FcafiVQX+NtmAt3hRm362hrgT3NC78iAvUWkII=; fh=4JcMjYjBWg/L45hB7XIX6gJmYdEu+RjOAAyT/fy0ovs=; b=P7lefB42vv0E2GYfi/Q7sAfSt0SsrWgKcjt94ogo7lr50seAD6LD56pFjH5CL0z42W uMKj0kWalVVzx+Yg50rqLydeX+V4a09JemAS/1jl5HsAnWzRliivc3o+6u5wSg2+R6X2 xHJsAZlK6VZxPXxQaaYGEepHGY4bJm+Ab6FlaoUL0zOC5FrDzclfTGAHhQF0TwkwdAIe l//FJ1mUCsj93pv0LwH+i55FMn/QeV9xye7fx9knCNFMB9zBeB+r06RM0772x6I8GbCF XVsTdSnacbYIApZgAOuEeo5SAdUsc4gqVVat6uE5T+4imk4UuzRbMYok/b+fk5WkLSzG TgrA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=n5+Yo54W; 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=1735318681; x=1735923481; 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=UcsG9FcafiVQX+NtmAt3hRm362hrgT3NC78iAvUWkII=; b=jft/ZjZTJfQ5XTbLGuFyt0I2gDqsOBUADF0Wm73aQ7C31T4I09nQrdj8h8fuY28uvp yQT/K3AhKONb13w3Wwr+LQVnFDUJRXspBTEQ+FC5x3co7/RhIiWJokwB/DzDIv3w7f5+ 0JyB32OlvG4BU/j5UpEqKBub4FAE+UlbXuYbw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735318681; x=1735923481; 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=UcsG9FcafiVQX+NtmAt3hRm362hrgT3NC78iAvUWkII=; b=Hk3EhfQGW56ebllBUyBQw2IlymtyKsKNQg3RxoJSXsY8Yt44LiqjsAZ9DBjI5dJmKK QhxqqVxAj2XVx56/kJMTQASamPUJ0xiunB+5E87I422F5nD4DnV8j0kW3B1N1yvnRxBE rbb8M8mw9QaqZ08zT19USFkXNwllKVO4BsbBVuAD3hPWVKwI+9xzVGUbGyBI8lnqbDfG HUb7gwzo/lzwurnHnToRc1hII1bTDrSv4nOg5hzOv3/2bMMnDazxLrUh7DMuKA4UhbCN 8Nh2t5SXnqQ8bZ3nEgZSMvEyBkfbtO6zRMnRE8mdYLEVi/OrUD486BdXr52vBH9HT7bq 1ECA== X-Forwarded-Encrypted: i=2; AJvYcCVAiey0c38pISE2o+6EGTtE9juxOnkE0lNeiD8DdlE6C57D+G9d+VNuB89fAoipdiMyZQTRjJjZCC9drErt@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YwOjQZHNh6ygxzaWSG6Rpxsz7WB79QOuyHSDIPR96cNwSMQVciH oxaXBlb/snCwMN2vXW+68EIH52H4VEn0hr01EWdm2z86Y+GRM8oVkQcfp58oyme8Y02GhX0kfw= = X-Google-Smtp-Source: AGHT+IFe7OH8dmKiO5ujO0jQIJzPMj5XFkAywrvQ+x4q73kXJ8+yxHJ+OpPFyhWTBai3XatCp1h5dA== X-Received: by 2002:a05:6402:5245:b0:5d3:ba42:e9fa with SMTP id 4fb4d7f45d1cf-5d81ddc01a0mr66468377a12.16.1735318681267; Fri, 27 Dec 2024 08:58:01 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a50:a455:0:b0:5d0:e410:4698 with SMTP id 4fb4d7f45d1cf-5d87a5d96a4ls739176a12.1.-pod-prod-05-eu; Fri, 27 Dec 2024 08:57:59 -0800 (PST) X-Received: by 2002:a05:6402:2693:b0:5d6:688d:b683 with SMTP id 4fb4d7f45d1cf-5d81dd9c716mr60769471a12.9.1735318679401; Fri, 27 Dec 2024 08:57:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1735318679; cv=none; d=google.com; s=arc-20240605; b=VypEv/TUwNf3C/1Vw75jaZr1p7xWv6EZOqGAk08vw54c9mNT3Wo35V7RykT4jzoOD4 jviv0aDNxE87Vb2zF4CRftIWiyZOSQLh6kFjjKMiaYqn4fuBL1D5NMoIAn9UlRbGmTtU 28r7IJj316EJww2OpgjWMaUKyb6q2jFrsVaKL1DI78NAIBiJztQq+QvfL3yv3LqDyYfZ 4Y2C2RDGYvXZxc07g7LsgxFHulDcMWlShDbm4y2BbGEmdnliP7bAIwdO2aFvOTXE3UM5 2OxyvJL5wwZkEn7ZfE5NHzPO9newmMuLv2ONYD6ns+bDKArdGrhTNT8VvEiY7FI+qGcx WJbg== 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=amw3Jgbei0RitJdkiNW15Rq4RQFyAbmJQvbl0wunMWQ=; fh=qtyXckgbBbLtvZf5GbbGzM1eq+vR1FBslTS8HapIlOs=; b=B/+TL3uVnJFQVFLE0+FyvBqqVJME7kU19gmo8+Kj8c8rJUifUvfUHgNm6NHxRBr+HD ELU8Sz9NDW0hZQH72p7t9fT6VgWB/Y1P/uC9PONRJqvIYTuOvyrWCiaa7gBYW1JxCcYB dHN/t4c8UlASKjDM/7Cpvio72gi6Bm7qXSbgw6RyCwJxyIJXhW+IU9tIivg0vHLgXxRh IbXJE/dglk+CRo5V1W5laNQsIOB4VVDfKUsj8yGXodIymlkcaVS47NwtNtXAw01NQ9rs IsE+oW81pTQ3kdCWLcr7qLGxGTTlSCzq0+Krzixe0YJhtXJoifAIsewHgJaqofyNWnM4 84mA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=n5+Yo54W; 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 4fb4d7f45d1cf-5d806ff214bsor5419557a12.7.2024.12.27.08.57.59 for (Google Transport Security); Fri, 27 Dec 2024 08:57:59 -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: ASbGncvptsdJZtcMkz7YJdByK8RzpXFp6t+rjY8gCCiunNOZrnZy/5gb29o8RaJ1VMR tZjemyGn9/2fItxqA9eX3E8/9HBYHRD3hrDJPWPeTvCHkV+LEh/DGwg3rOV2vUV9mfTbjDCtAQ1 Uat/3BghhnhIjk2Gj9NfYyp9CTQIhlesEXrXEeXPUbfZB3airgb35mwN8NkbKpqBGAWFS/uY7XT Tjm/C2ecZb6bKRkf6O6zW9m1nTfirMPvkGkhVRe9aF82K3jWrkqqLbAQ/DtNqDOnVsgjy4xEDrQ zyCCbzuvRIskwL9aNWVerw== X-Received: by 2002:a05:6402:3224:b0:5d0:d3eb:a78f with SMTP id 4fb4d7f45d1cf-5d81dc79cadmr66066660a12.0.1735318679004; Fri, 27 Dec 2024 08:57:59 -0800 (PST) Received: from dario-ThinkPad-T14s-Gen-2i.. ([2.196.43.175]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0f0159f1sm1130097266b.154.2024.12.27.08.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2024 08:57:58 -0800 (PST) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: linux-amarula@amarulasolutions.com, Dario Binacchi , Peng Fan , Abel Vesa , Fabio Estevam , Michael Turquette , 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 v7 22/23] clk: imx: pll14xx: support spread spectrum clock generation Date: Fri, 27 Dec 2024 17:56:25 +0100 Message-ID: <20241227165719.3902388-23-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241227165719.3902388-1-dario.binacchi@amarulasolutions.com> References: <20241227165719.3902388-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=n5+Yo54W; 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 Reviewed-by: Peng Fan --- 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