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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 564C6C433EF for ; Sun, 20 Mar 2022 19:17:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2181983A65; Sun, 20 Mar 2022 20:17:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="A5mgwMAx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5410D83960; Sun, 20 Mar 2022 20:17:17 +0100 (CET) Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7F95D8398C for ; Sun, 20 Mar 2022 20:17:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf2f.google.com with SMTP id kd12so10178964qvb.1 for ; Sun, 20 Mar 2022 12:17:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=3hnl4fd5V8+2Pnnhjwud7cunHkXvpFJABEDTE+zyZTY=; b=A5mgwMAxskguQdRqOqXHj4oh17kJ9UOekOB3Gz51pJOJZ73txZBPH+SK23GJxlOKeL D6fJbiMlHsOC9MXcTTyVoMn3zTU2H4i9XyT27A27h86UL4+eKHoLFme2XtRoOWbVwUvl KVJ0+JmqH9gN2iJoqpKsdkEQ104zGYBCod4WEGJC3rb8naqoawOg4CP5mabWbwsQGw7t HYT3DnG7OBJkJAKosr1oYDGMjLTj4pyEYNZU147WqMJya4bDQGf1+f2S16MBn7Ztt72v 2zzNLvLrRUZWPJgiYwBRYilgKzQyj27e5/TyeAByTkHZ8kTvGA90YLIF3In7pOsVwD23 0uEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=3hnl4fd5V8+2Pnnhjwud7cunHkXvpFJABEDTE+zyZTY=; b=qOSvm5HjnouR0dH67oCxXGc8zFZZlQptYh0YPrmHeZczvBDxaCnTaH96rWhu5/yIpD LDVfNka2+OkDoCBy78XMs7PBNSZ/tOx9bOJMDEiSASwoJM26iI0o2RnRNkP+6pjGKH4x In/dBEgrvPCgqlWnunzh2+2qWxB5Ja3KnuW6EBLjWJKSNROhI7tTyK+egFRKLKIvaffY XHwJXam7Bus0TRyu68A88DvKs3WkUYRvOao59KjoP5BIBkq0mmN8PBvi7wdC8x9g7j1x eaqQORJFRJg9W9J6UJVZJC2LCNl2s10BMSp3njXb+IN5UJxluuKBJqUA6CopK7M2rN+8 WWUQ== X-Gm-Message-State: AOAM531Ga+OGrcuuSOjvGcZhE7BJKIjJ02r/epNmoAqno+tNVzLJJ3mO /9uMiFJMkolTm7y81Bz/d+U= X-Google-Smtp-Source: ABdhPJybYfEmjuZUWE+HtmEXjTjJ+XwQSffACsSRRZW/VLm2DcV0WEBNESQ9W93slfZgOBTXQnUazg== X-Received: by 2002:a05:6214:e6f:b0:440:c472:febe with SMTP id jz15-20020a0562140e6f00b00440c472febemr13865884qvb.9.1647803831221; Sun, 20 Mar 2022 12:17:11 -0700 (PDT) Received: from [192.168.1.201] (pool-108-18-137-133.washdc.fios.verizon.net. [108.18.137.133]) by smtp.googlemail.com with ESMTPSA id bk15-20020a05620a1a0f00b0067e5bd7a9ccsm3705727qkb.50.2022.03.20.12.17.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 20 Mar 2022 12:17:10 -0700 (PDT) Subject: Re: [PATCH v1 5/8] clk: imx: Add initial support for i.MXRT1170 clock driver To: Jesse Taube , u-boot@lists.denx.de Cc: sbabic@denx.de, festevam@gmail.com, festevam@denx.de, uboot-imx@nxp.com, giulio.benetti@benettiengineering.com, lukma@denx.de, sjg@chromium.org, jagan@amarulasolutions.com, kever.yang@rock-chips.com, andre.przywara@arm.com, pbrobinson@gmail.com, tharvey@gateworks.com, paul.liu@linaro.org, christianshewitt@gmail.com, samuel@sholland.org References: <20220317183300.315173-1-Mr.Bossman075@gmail.com> <20220317183300.315173-6-Mr.Bossman075@gmail.com> From: Sean Anderson Message-ID: <5b364f05-25ac-18cd-4bb7-96121b808d5e@gmail.com> Date: Sun, 20 Mar 2022 15:17:09 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20220317183300.315173-6-Mr.Bossman075@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean On 3/17/22 2:32 PM, Jesse Taube wrote: > Add clock driver support for i.MXRT1170. > > Signed-off-by: Jesse Taube > --- > drivers/clk/imx/Kconfig | 16 +++ > drivers/clk/imx/Makefile | 1 + > drivers/clk/imx/clk-imxrt1170.c | 215 ++++++++++++++++++++++++++++++++ > 3 files changed, 232 insertions(+) > create mode 100644 drivers/clk/imx/clk-imxrt1170.c > > diff --git a/drivers/clk/imx/Kconfig b/drivers/clk/imx/Kconfig > index 96721bcbf3..ae56603194 100644 > --- a/drivers/clk/imx/Kconfig > +++ b/drivers/clk/imx/Kconfig > @@ -100,3 +100,19 @@ config CLK_IMXRT1050 > select CLK_CCF > help > This enables support clock driver for i.MXRT1050 platforms. > + > +config SPL_CLK_IMXRT1170 > + bool "SPL clock support for i.MXRT1170" > + depends on ARCH_IMXRT && SPL > + select SPL_CLK > + select SPL_CLK_CCF > + help > + This enables SPL DM/DTS support for clock driver in i.MXRT1170. > + > +config CLK_IMXRT1170 > + bool "Clock support for i.MXRT1170" > + depends on ARCH_IMXRT > + select CLK > + select CLK_CCF > + help > + This enables support clock driver for i.MXRT1170 platforms. > diff --git a/drivers/clk/imx/Makefile b/drivers/clk/imx/Makefile > index 01bbbdf3ae..3ed326739a 100644 > --- a/drivers/clk/imx/Makefile > +++ b/drivers/clk/imx/Makefile > @@ -19,3 +19,4 @@ obj-$(CONFIG_$(SPL_TPL_)CLK_IMX8MP) += clk-imx8mp.o clk-pll14xx.o \ > > obj-$(CONFIG_$(SPL_TPL_)CLK_IMXRT1020) += clk-imxrt1020.o > obj-$(CONFIG_$(SPL_TPL_)CLK_IMXRT1050) += clk-imxrt1050.o > +obj-$(CONFIG_$(SPL_TPL_)CLK_IMXRT1170) += clk-imxrt1170.o > diff --git a/drivers/clk/imx/clk-imxrt1170.c b/drivers/clk/imx/clk-imxrt1170.c > new file mode 100644 > index 0000000000..6ea46b6a52 > --- /dev/null > +++ b/drivers/clk/imx/clk-imxrt1170.c > @@ -0,0 +1,215 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +/* > + * Copyright (C) 2022 > + * Author(s): Jesse Taube > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "clk.h" > + > +static ulong imxrt1170_clk_get_rate(struct clk *clk) > +{ > + struct clk *c; > + int ret; > + > + debug("%s(#%lu)\n", __func__, clk->id); Consider dev_dbg() if you do a v2. > + > + ret = clk_get_by_id(clk->id, &c); > + if (ret) > + return ret; > + > + return clk_get_rate(c); > +} > + > +static ulong imxrt1170_clk_set_rate(struct clk *clk, ulong rate) > +{ > + struct clk *c; > + int ret; > + > + debug("%s(#%lu), rate: %lu\n", __func__, clk->id, rate); > + > + ret = clk_get_by_id(clk->id, &c); > + if (ret) > + return ret; > + > + return clk_set_rate(c, rate); > +} > + > +static int __imxrt1170_clk_enable(struct clk *clk, bool enable) > +{ > + struct clk *c; > + int ret; > + > + debug("%s(#%lu) en: %d\n", __func__, clk->id, enable); > + > + ret = clk_get_by_id(clk->id, &c); > + if (ret) > + return ret; > + > + if (enable) > + ret = clk_enable(c); > + else > + ret = clk_disable(c); > + > + return ret; > +} > + > +static int imxrt1170_clk_disable(struct clk *clk) > +{ > + return __imxrt1170_clk_enable(clk, 0); > +} > + > +static int imxrt1170_clk_enable(struct clk *clk) > +{ > + return __imxrt1170_clk_enable(clk, 1); > +} > + > +static int imxrt1170_clk_set_parent(struct clk *clk, struct clk *parent) > +{ > + struct clk *c, *cp; > + int ret; > + > + debug("%s(#%lu), parent: %lu\n", __func__, clk->id, parent->id); > + > + ret = clk_get_by_id(clk->id, &c); > + if (ret) > + return ret; > + > + ret = clk_get_by_id(parent->id, &cp); > + if (ret) > + return ret; > + > + return clk_set_parent(c, cp); > +} > + > +static struct clk_ops imxrt1170_clk_ops = { > + .set_rate = imxrt1170_clk_set_rate, > + .get_rate = imxrt1170_clk_get_rate, > + .enable = imxrt1170_clk_enable, > + .disable = imxrt1170_clk_disable, > + .set_parent = imxrt1170_clk_set_parent, > +}; > + > +static const char * const lpuart1_sels[] = {"rcosc48M_div2", "osc", "rcosc400M", "rcosc16M", > +"pll3_div2", "pll1_div5", "pll2_sys", "pll2_pfd3"}; > +static const char * const gpt1_sels[] = {"rcosc48M_div2", "osc", "rcosc400M", "rcosc16M", > +"pll3_div2", "pll1_div5", "pll3_pfd2", "pll3_pfd3"}; > +static const char * const usdhc1_sels[] = {"rcosc48M_div2", "osc", "rcosc400M", "rcosc16M", > +"pll2_pfd2", "pll2_pfd0", "pll1_div5", "pll_arm"}; > +static const char * const semc_sels[] = {"rcosc48M_div2", "osc", "rcosc400M", "rcosc16M", > +"pll1_div5", "pll2_sys", "pll2_pfd2", "pll3_pfd0"}; > + > +static int imxrt1170_clk_probe(struct udevice *dev) > +{ > + void *base; > + > + /* Anatop clocks */ > + base = (void *)ofnode_get_addr(ofnode_by_compatible(ofnode_null(), "fsl,imxrt-anatop")); Where does this compatible come from? I don't see it in Linux or U-Boot. > + > + clk_dm(IMXRT1170_CLK_PLL_ARM, > + imx_clk_pllv3(IMX_PLLV3_SYS, "pll_arm", "osc", > + base + 0x200, 0xff)); > + clk_dm(IMXRT1170_CLK_PLL3, > + imx_clk_pllv3(IMX_PLLV3_GENERICV2, "pll3_sys", "osc", > + base + 0x210, 1)); > + clk_dm(IMXRT1170_CLK_PLL2, > + imx_clk_pllv3(IMX_PLLV3_GENERICV2, "pll2_sys", "osc", > + base + 0x240, 1)); > + > + clk_dm(IMXRT1170_CLK_PLL3_PFD0, > + imx_clk_pfd("pll3_pfd0", "pll3_sys", base + 0x230, 0)); > + clk_dm(IMXRT1170_CLK_PLL3_PFD1, > + imx_clk_pfd("pll3_pfd1", "pll3_sys", base + 0x230, 1)); > + clk_dm(IMXRT1170_CLK_PLL3_PFD2, > + imx_clk_pfd("pll3_pfd2", "pll3_sys", base + 0x230, 2)); > + clk_dm(IMXRT1170_CLK_PLL3_PFD3, > + imx_clk_pfd("pll3_pfd3", "pll3_sys", base + 0x230, 3)); > + > + clk_dm(IMXRT1170_CLK_PLL2_PFD0, > + imx_clk_pfd("pll2_pfd0", "pll2_sys", base + 0x270, 0)); > + clk_dm(IMXRT1170_CLK_PLL2_PFD1, > + imx_clk_pfd("pll2_pfd1", "pll2_sys", base + 0x270, 1)); > + clk_dm(IMXRT1170_CLK_PLL2_PFD2, > + imx_clk_pfd("pll2_pfd2", "pll2_sys", base + 0x270, 2)); > + clk_dm(IMXRT1170_CLK_PLL2_PFD3, > + imx_clk_pfd("pll2_pfd3", "pll2_sys", base + 0x270, 3)); > + > + clk_dm(IMXRT1170_CLK_PLL3_DIV2, > + imx_clk_fixed_factor("pll3_div2", "pll3_sys", 1, 2)); > + > + /* CCM clocks */ > + base = dev_read_addr_ptr(dev); > + if (base == (void *)FDT_ADDR_T_NONE) > + return -EINVAL; > + > + clk_dm(IMXRT1170_CLK_LPUART1_SEL, > + imx_clk_mux("lpuart1_sel", base + (25 * 0x80), 8, 3, > + lpuart1_sels, ARRAY_SIZE(lpuart1_sels))); > + clk_dm(IMXRT1170_CLK_LPUART1, > + imx_clk_divider("lpuart1", "lpuart1_sel", > + base + (25 * 0x80), 0, 8)); > + > + clk_dm(IMXRT1170_CLK_USDHC1_SEL, > + imx_clk_mux("usdhc1_sel", base + (58 * 0x80), 8, 3, > + usdhc1_sels, ARRAY_SIZE(usdhc1_sels))); > + clk_dm(IMXRT1170_CLK_USDHC1, > + imx_clk_divider("usdhc1", "usdhc1_sel", > + base + (58 * 0x80), 0, 8)); > + > + clk_dm(IMXRT1170_CLK_GPT1_SEL, > + imx_clk_mux("gpt1_sel", base + (14 * 0x80), 8, 3, > + gpt1_sels, ARRAY_SIZE(gpt1_sels))); > + clk_dm(IMXRT1170_CLK_GPT1, > + imx_clk_divider("gpt1", "gpt1_sel", > + base + (14 * 0x80), 0, 8)); > + > + clk_dm(IMXRT1170_CLK_SEMC_SEL, > + imx_clk_mux("semc_sel", base + (4 * 0x80), 8, 3, > + semc_sels, ARRAY_SIZE(semc_sels))); > + clk_dm(IMXRT1170_CLK_SEMC, > + imx_clk_divider("semc", "semc_sel", > + base + (4 * 0x80), 0, 8)); > + struct clk *clk, *clk1; > + > + clk_get_by_id(IMXRT1170_CLK_PLL2, &clk); > + clk_enable(clk); > + clk_set_rate(clk, 528000000UL); > + > + clk_get_by_id(IMXRT1170_CLK_PLL2_PFD2, &clk); > + > + clk_get_by_id(IMXRT1170_CLK_SEMC_SEL, &clk1); > + clk_enable(clk1); > + clk_set_parent(clk1, clk); > + > + clk_get_by_id(IMXRT1170_CLK_SEMC, &clk); > + clk_enable(clk); > + clk_set_rate(clk, 132000000UL); > + > + clk_get_by_id(IMXRT1170_CLK_PLL3, &clk); > + clk_enable(clk); > + clk_set_rate(clk, 480000000UL); Can this be done using assigned-clock-(frequency|parent)? > + return 0; > +} > + > +static const struct udevice_id imxrt1170_clk_ids[] = { > + { .compatible = "fsl,imxrt1170-ccm" }, > + { }, > +}; > + > +U_BOOT_DRIVER(imxrt1170_clk) = { > + .name = "clk_imxrt1170", > + .id = UCLASS_CLK, > + .of_match = imxrt1170_clk_ids, > + .ops = &imxrt1170_clk_ops, > + .probe = imxrt1170_clk_probe, > + .flags = DM_FLAG_PRE_RELOC, > +}; > --Sean