From patchwork Sun Dec 22 17:04:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3737 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 C1CC340CF6 for ; Sun, 22 Dec 2024 18:06:12 +0100 (CET) Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-5d4e0ac28b2sf2724337a12.0 for ; Sun, 22 Dec 2024 09:06:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1734887172; cv=pass; d=google.com; s=arc-20240605; b=Zbf8n1IOW/rC9ApvL6IJf+UTkIpQx3xNu2NZ3Z2LqEguyTOIIvnV98cZElg7SPq5hp LojjMTII0vMHfcwYIuQON0878f/gFeNQQWBJ/sd4JaDHKVERdb5cWsCOAyKnj5dWoZrM MRmABjTrj0AKRyzLSEoTsg2wvYdFAyrELlFBv9XpGxT/c9xPl8EihBOE9FAp2NkTgFmF tBxlUmTSEy1qUbAPiFN7S7FnrauoD6l8Vu7/dYb3zr9W5Em1+g+Au6Xp2lHN3G5uL49i 6co6g7ywGlV9fwTgtz8GXUyyvAzypqiPyRrCn/8qGqgRwciBeZ8Dq8slB0hvcVeUzHmi EYWw== 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=JbiwhAF3/n56OlzVNhdNkVLYvv0g08enKneulEVmg0Q=; fh=DlAl0Bnn5iIPHumW4420ByQpbmj3eQeXiqrItkxLwcM=; b=ZxYGmPWh4hwCblvOTlaTgeaxe7fav7VR2fHlwFcy/qJDEoUwSJXwJ7nBn6TiIk889o du+lG6BCtolU0r4+bwneYBoLZDmtwr9oZzf6/SzSOZ2J/GMZobjbxA2IAg8jM9PYINFr 0H4cDI3Xp9XbeTXL7MSRrRORTs6/gsbQ9/ggtHcirGL0rRf4UPtkaBrouWeWH0NbkBG/ TkiKpo0FU9rjWSeVvqOqpvd5hWiSfxKo6W4eZwLJsvKZHahOdaXexavMGm1spJCOSK+E oqgzAEXEsKEs7ycQv8UVNAMpcaoJ4fssGHJ1kOD1E4oQWjNWSesEFxud99Htd+Y9mVOt kPoQ==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=UX+wPOR8; 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=1734887172; x=1735491972; 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=JbiwhAF3/n56OlzVNhdNkVLYvv0g08enKneulEVmg0Q=; b=JxL6nQlS0ZlILa9aJtP6XdK2Yl8rgXNpTa+nJkVdstrUwCWt/lBW3tNPEiJSdiY2RN mYQT3knL+Wh3XL+69qWuFko1Yo0zDH/7KMo9syhjTx87hMQEiiJzLsLhBOCVbYjYqN6a Eto9Dvyz25iWttE+pNzbvbqfKV4O38FUikaMk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734887172; x=1735491972; 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=JbiwhAF3/n56OlzVNhdNkVLYvv0g08enKneulEVmg0Q=; b=lfuUGsqxSE2zHL9pzP3qvYnX8o65qa345t8UqJpk9GubKPacxGzANR0CqUs/+DfTQd i7kYPgtNDbT1wPrQq4l74Oy+Wgb7EsncL5Hj/EgmQBLlmp2Ie3Woy69je6d4wQsOMgZX mwjEitKdwVcE5HhYHSIfG+2JU7uOruEooTjb9Ia3VilXz788cmdGUph26/9dLFVkAfaj OJ0ytIWzDgucnu/07+od7tCyylcJQYlj7evbA1a2MNo7vl6aqEVs6j5wTNZGigwwnP6x IxPKrC95OAlW+hK6VZ+tKdg8bFWvLwlfjGm+MYe4HXnF+kjuO//528ytFdH0L8T7AGsM 8rhw== X-Forwarded-Encrypted: i=2; AJvYcCWTB8OduzIzluQlQIWybqB2BH9lmsYMcx/gaLKtAAQcTfd3YzFKimAeHwtDhzt2jAUSeQd9yfFbxandONdv@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0Yzx7gG88b9x4tHFGR2usItlOrB2qy+7zZ9yg6vnSDBDglKwpL6x hlTZ10oClacydvRKmIXagRNZys7wvsca0WI21ueGVpW6c5BPj8dvxk8xIVCHt3gLEw== X-Google-Smtp-Source: AGHT+IE9SgbSHLDmYwTxPSgqKQmCMGBr2PjvnnSX/uGMqvquqpV1hjVujqczfiX1Pop7ud+K9suW/A== X-Received: by 2002:a05:6402:26ca:b0:5d1:f009:925f with SMTP id 4fb4d7f45d1cf-5d81ddacb7fmr8190514a12.15.1734887172434; Sun, 22 Dec 2024 09:06:12 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a50:931b:0:b0:5d0:bf73:1c41 with SMTP id 4fb4d7f45d1cf-5d8025c9ddels172659a12.2.-pod-prod-02-eu; Sun, 22 Dec 2024 09:06:11 -0800 (PST) X-Received: by 2002:a17:907:944d:b0:aa6:c266:97cc with SMTP id a640c23a62f3a-aac2ad8e1c2mr798337666b.23.1734887170646; Sun, 22 Dec 2024 09:06:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1734887170; cv=none; d=google.com; s=arc-20240605; b=aDRBjJxgdoKxWL7MPXIi+/12LJ1b8YdRim8tNbCS2vACWYyvQ20QSpBODZRevhnx3K MDJ8obqGpnh7A6G1nxAQ0avg07zCOuTaMQt4uq2EB3ZNSLxQ9o0gswIywzhI1lOvHOSm fBeoKW+IDDkHSIBfpzR0Wku4tgQzkTkSOTIZK7E7idscJEoG4qD7uYeLu7TmjxJtm2DH /lqftOyxy/5lKBjUUVtcXE53iFlozTegFKyWRSjOrbubVTuZaZ+w2RPoZFBw1mxajrrp 9KlJtYFnOYnowMZ/csPJvORdpNc3g0yE5XNj4cEPVkLoad0hndCm9Mf6K4ChOkCHQPSN OZLg== 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=nqIvltahhRDuJ7U9kepGituOp6saQuOpjRV8BXhF69I=; fh=u/u80m6tBSaxW7VWG5AQatIbYzkIAnRGhZp/RTASK5o=; b=Wi1oPBzEguTU/ZYNRP50UqsY7mZO6nVllhM5lAY8XvVZzkD1QEw8VDro9KeSYdtojc NS6X/9VntjfwFsYU/zFRuGiF6A7giUb4Zl/Kj542cQW+BOZ4PX9JQ/oRIy4LaQIqXvO7 piB+a7bWJZ/8gWMel9pafjW8RmJR6sdlW/btypalV8lL2yYOOtUg85Ja/Ca2fgoDiOMu hMpmvMbSxKeT+yK4FpV8oEFZZX4UYOcEdhsMiDLxgixU23svh0gNS6/VjPRx2DEZXirg Ff4QWQbMOOr3QbHcVZ5eKXjkSsnRe6UeN6QQOBK7+1lS1UCvuXIT9w5gNqAJEFYOd6EJ U7xQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=UX+wPOR8; 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-aac0eb3f514sor241090566b.11.2024.12.22.09.06.10 for (Google Transport Security); Sun, 22 Dec 2024 09:06:10 -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: ASbGncvJeNK7c1F/oW829uMcQ9jJEX62UCJO02BGjTmLwAWLkPCQuwJETgtVjbNd2yF 3yoc/Qbdd7emUnrpkE4mv77ZFLstj7Yg0tJGTJSeQ6KoFu0iWlXSrIBruw2LrratoiHgTQuwS5A lVHC60+9Hu1IZp40uGsXbYoFnd9uFpsHeNaqc4JsZxAYwQIWDnrQjFClIilpuAa4cEtuwmrkKnZ lfCLOGegTArT75tfTPPRjahsvY/FRM6eX753KRJ52oTrUS207PwQ9PkP9G3s+1y2Jw3UI/RD9Y/ 5KNAI6TmdheeApe2PfzpppYFtrKQmSsd0HuH6TPx2EMM1Q== X-Received: by 2002:a17:907:7e8c:b0:aac:2128:c89e with SMTP id a640c23a62f3a-aac334f31fbmr1056581066b.43.1734887170206; Sun, 22 Dec 2024 09:06:10 -0800 (PST) Received: from dario-ThinkPad-T14s-Gen-2i.amarulasolutions.com ([2.196.41.87]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0efe48d6sm414056566b.127.2024.12.22.09.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Dec 2024 09:06: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 v6 17/18] clk: imx: pll14xx: support spread spectrum clock generation Date: Sun, 22 Dec 2024 18:04:32 +0100 Message-ID: <20241222170534.3621453-18-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241222170534.3621453-1-dario.binacchi@amarulasolutions.com> References: <20241222170534.3621453-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=UX+wPOR8; 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 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 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