From patchwork Sun Dec 29 14:49:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3782 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 2DADF3F174 for ; Sun, 29 Dec 2024 15:51:02 +0100 (CET) Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5d3e77fd3b3sf10074959a12.0 for ; Sun, 29 Dec 2024 06:51:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1735483862; cv=pass; d=google.com; s=arc-20240605; b=iCXuJeg3HrJbwDmFm5VhQkGhPeZ7L1tkk87bGIdmGJ5xHtbPWXY76E+7nDyD59XvVd QwpQSkcc0gAv88DOoOcHuXtQ2WbkpEt3RR0rp/Z7kReHrc0xwTPtnj7Rl5eQJNot8D6G Tc6eHa1b1c3tNF/J73NprgAUmDrzAmm5Qk/WpSEO6EwCEmPQbA1zEdV2xG10Qji0ZDkr 9vkhqc0ZgoeMY+TC0kQR8bwIpi6/U1H+3mpNgktr40TxcIYYaWsWsA5uHidoVZQ9j5U3 pboRyec1fCPAk+aTBUSD2ud8uDvYV8+Nv9FeLHu2OJ8MxQIeEoqHhWGoI4XJLNw+MCAs ulXg== 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=vlcJsby7jA453afvnIdNpxDVpLARloppODt0st+9qDc=; fh=97/Kpdr4lnl9By1IRK+/AxQl3Wyv15xq8CKp1ZEMfTQ=; b=BoQAliTRyBQkcHsP6sspwXF6/X/YMogh3HgsTjTI2gOJ/JhhlcVPK0m1bVcd4YMkHS jNUmvFOJaVBeBS5N3vMSMyFVGFnitE4u13BOGG8l9pAY9Se9DsJcRJFxPwwMxnppgQwV 1rtF7E4siQcnCB+0Dg2vae0MpY1j1RapN0JVlZceoC7/vJ7Zab9RMCAT71FH/UHd3JW3 jweyzGhK5Dp2A+Adjr24p93FqUY0wFYGaREW3J5Yb2cUIalWdPyqFeIfyQyh4lqiwwjz Hh2IdrUt7sX3TXcY5D9QnCNo2dnWYSGVplfo8Z7ANukP0kYWBjw6xwuzdle+v4C0evZP tuIQ==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=RcxUDned; 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=1735483862; x=1736088662; 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=vlcJsby7jA453afvnIdNpxDVpLARloppODt0st+9qDc=; b=P948sjSissOqXw7oSzvZtfIDwszf47Wui8cidmzNVesi1GRBPnoV9F27WGAZy/xHc0 2qEG8Xrw8QOLIe6PTi0Cm+LHkTGNcSrQ6VPekFGX7RQ2LzoE05/a4patYGbylHktaTVc sufuxiIanDTmw0U8PVddMtO+/jMhaFu5PDspw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735483862; x=1736088662; 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=vlcJsby7jA453afvnIdNpxDVpLARloppODt0st+9qDc=; b=BvwvcQEsbglartCLqCgNLIi9QR1eXQdV+97gk07JDt78dJrtDOe1h+jRMFy9HGDT/R RNwCTb4l+dtLRPzfXxpLPCQ+r8Sr0sTgqr8k7xSSOmIdv5gmnQffoEPTJxf0Xs6e9sAE qnlLrC5T9SEVLBHnqEbh/cYGainVTq6nGn0Xg8mLTCsrBJzNxsoMhrK6v/jLe17oN1Vm g7FfYJ+aWw0S3TDOAzQi2qOdGCUTvXStNe8DjoWIQ8U/PvR14kAa8nyNB7pNboGNxyUh /oKAIYPw7pZqI6GXBKK7yDX0aE5Wsxi6W8wgA+oBum2FeRSeEwELY9AbAlZaNsMW3CgI yavw== X-Forwarded-Encrypted: i=2; AJvYcCVlGJHnHr+FmLCuvuXr6W/gxdi5zr8R6MbZacGMomaL0DJcy2/hOnKA7u6tPmLe/5j1xq/C3rGQlypEYGlS@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YyhIixpvwl5iAqhFroQwT3FeVZ5XChD6EcbMZBVPn0YAlR8E+Xg qqIQtU7KR4CPZ+TdUm2rNkzIJEkZB6AKK9O5aCV2ki6m83jbduR1Sgn/YkL/nIFxDw== X-Google-Smtp-Source: AGHT+IFtE9UBlG89PP/sKhz7DTk3et5o3Hp9mm5gWkvxdyKwenSdofNTvs4aABY85zxbIk2aPtMSeQ== X-Received: by 2002:a05:6402:354b:b0:5d0:ef55:8451 with SMTP id 4fb4d7f45d1cf-5d81dd9c75emr32026769a12.8.1735483861841; Sun, 29 Dec 2024 06:51:01 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a50:9505:0:b0:5d3:d143:5a84 with SMTP id 4fb4d7f45d1cf-5d8c57b6af5ls488438a12.1.-pod-prod-03-eu; Sun, 29 Dec 2024 06:51:00 -0800 (PST) X-Received: by 2002:a17:907:1c16:b0:aaf:208:fd3f with SMTP id a640c23a62f3a-aaf0209031bmr1223161966b.13.1735483859963; Sun, 29 Dec 2024 06:50:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1735483859; cv=none; d=google.com; s=arc-20240605; b=j9KyReJJxRJySMyu6zm+k8bMKzKK54NFCoryym0Jf7ygE+gp/3D6w1ZWuI4in4cL1e qL0Yg5gn7ffoFAWBAKei6JwbOg4aB2+hpMqgO9CyLJXSOm6zvY7Y4K6BPJpg3Eyozmd9 SMV+wxPUfeH8VOlgl9AY33IOtZPcIVrhQoPz9c1HF01vZ/ZwfkFopzC9w4U1Hy8cUXQP bGeBE5eF6RjrmOFhTHCSTol6+laglhW76qJIWOu3n2hWl2+2qTwFbMJQ8gTnkttW8yL4 eLHWKllK7tNueJ9p4P9MJa1okFkiGqr1yEsC7dQyZGTe/2hcI0DqDfzq9v+Me9NuOZjr dlCw== 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=jzsVBhjhlmiF36sGbiHfZNPUdaBOg5gbMlUQSL+IAZc=; fh=qtyXckgbBbLtvZf5GbbGzM1eq+vR1FBslTS8HapIlOs=; b=YuoL3KaqJ1kE+Qs3GRSk4K/k8MnxlMWvLD9uqHBPey+phg/WzuM2Eg4JMFAZhcXQHL /WSuJ+eOgNqgaMNmuOz3AA/SE1GWV0q5tbwlJ3PEA+fsRn4gfQBmX35K1eis2/uvpYYl DsnWrkuG5gsf92nbxARHItGCrOy3O9MyYd4eOFjlwreq1edD5GVdl0qqEP4us3LOvdp4 QQJKGr6YifX3GDdjcK2zBl2m007LeQGm7bp/RDl4d8KatKZlaharteoNkOxf2w6JN/X/ hk7+AzKjcLk0/UUkiL7ZDMQh8D2N1qJxpMhEwkLCBdZDQ3KICBVS6RL36CsYNQ0ljtaA 0EIg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=RcxUDned; 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-aac0ef1e8d0sor769361666b.13.2024.12.29.06.50.59 for (Google Transport Security); Sun, 29 Dec 2024 06:50: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: ASbGncu4flz4hAoHf0eIJvcX/DSHIMSCKzzDuAv0BHYpCa7jhXTW58NfDKTqqcnJBSt e5Xoeokqx2XCtlTpMGOrBO6toL8tDm5zQk1duhqm74bNEGVcCdK5BzN+Wsrrj3l+ON3iTBaQm9t tnRNzI82z6KZPjSCMbsN4npNZuslz8jAMmzBa1Q9xc077AxPbqc0Zv9kAQ7puumTU9fg4TtZJcB 5dw7l8i9pM4r8LVspk9nMrfGg4kNB0VQY4Zhstm6HQvfsZKKZh/dWkhMZ0CKkyPAaWKx3YAYbiR Ibkalfi5n901L5O6xk7h/g== X-Received: by 2002:a17:906:f598:b0:aae:c3c1:1361 with SMTP id a640c23a62f3a-aaec3c1186fmr2529063966b.44.1735483859533; Sun, 29 Dec 2024 06:50:59 -0800 (PST) Received: from dario-ThinkPad-T14s-Gen-2i.. ([2.196.43.175]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0e895080sm1362084466b.47.2024.12.29.06.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2024 06:50:59 -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 v8 17/18] clk: imx: pll14xx: support spread spectrum clock generation Date: Sun, 29 Dec 2024 15:49:41 +0100 Message-ID: <20241229145027.3984542-18-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241229145027.3984542-1-dario.binacchi@amarulasolutions.com> References: <20241229145027.3984542-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=RcxUDned; 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 --- (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