From patchwork Tue Apr 2 11:28:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 191 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 2232E3F078 for ; Tue, 2 Apr 2019 13:29:16 +0200 (CEST) Received: by mail-pf1-f199.google.com with SMTP id y2sf5327983pfn.13 for ; Tue, 02 Apr 2019 04:29:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1554204555; cv=pass; d=google.com; s=arc-20160816; b=SzB8t5Ms90NuVCx9WHWl3j9SJ93hvIAtc7z5hRL663Ew1+cLo9WcGXDfn7Td3ABElq ueDvNQfxehqN6uu4alqYXWpg+uRiBYlWXBT/ThWRtS+P5SAIPbyvGWCLyXd6J7UK+fxc Y7LF/WpCAnNB1IWhDR4U5PxtISbm8fmzIyaiITe86xHdkmVSGRZAbvseB+kOA9McvoT5 qWFc4AA3X5ZAMiB2ROfe6fdjLyHUNRXpSJeve9TOMmfHlJYEN+YOPhPEueIC1++E11dc 61gLuwNkJNfMQVAHixU2LyRjUc01+gh2et2ZfuIZWvuvEPIfohM5oSWcuc3sfIvwqkJ1 m+jw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=Sl+2gLuLs5A93/YCfHcWIT1fiXHKPoKZYDYXVRN99Bo=; b=kvEi4b9wzXeRqZxJUoGNlJhJdubT7lU2G7ArymHYtptWVzcFi2vO6KHTWm5+aIS01z 9G6Ik+OsjbmKGaHpsAmVmTlC3FChanPOnu3vpTA62MLzigEBda8DWsxNOG/Vt6sSlEcz Sap0lDeliQW/mk93vvIIb7l7wX06vS9X7b9nsT2KpXsv7q4bxiSTerGTJWNBviGRBCVo NpQlsAL1v/enRw3O2QQ8qfTcjRB1kuq+IGAAiovPPMP4KYe8gKcmI5WEF2vT0wW5IT/p zyNBmVwAb7Ha5FCiGfGTrMAUscHHAhMzR4Zmfhm7dAE3HUSzl36NPNEDYO6ygI8yKwva fyzQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ey9lIdgh; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=Sl+2gLuLs5A93/YCfHcWIT1fiXHKPoKZYDYXVRN99Bo=; b=HM9FbccPPZO4a8AIlqYg+My6k9zFsK4B8mIq6KzaYpsGjQcfNos/bi9fAwtYMUGGaX JoSiAFrcDFaOn4iZf9nFJ5XemQW7m47suFiK8mvRJXnaO9ybaeOk6H8qIoZcrqZhFwhX OgYYL5p1y4fz0mSM6fmYQOLIAdQhbEXV9KIqQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=Sl+2gLuLs5A93/YCfHcWIT1fiXHKPoKZYDYXVRN99Bo=; b=ZFsFIKKBMnlKl8fHDvpG81NNweBwtVc2khnT8kibjfEDwCSPgi1R8OEwPykhFozXPs C9z5SvGXtyEyy/EszrDhHx53MHP5kxw4KvYkx76V7EgnVLUtpN8NEkcy2oqmpykUQWwW 1cnEMd7mk74vkik9uSZ10U4LHWDOxxfIdDMxR57GfzQCInY8+L8+CCVL7V8WUutIpP8f ZMSLIf+ffZLDR5rZ9cEQom5x6cVsOuCOZEBj4K8wJ/X83mFCC1EANEl9kjlQzx2Gs28r L05Oniuy8k35B1PlBEzd03f5rj/H6w12ng4EcslKgcVJlO74SPkmlfIF0dGOL493JRSZ uy1Q== X-Gm-Message-State: APjAAAUkn5CbsIcauvbiAuHcylC3FSgo9mKjr4ZslNfgpe6WeerWtJ++ 8CdfSqFE4cfPzEf2f2d+GvESCRys X-Google-Smtp-Source: APXvYqyiw+lZzeIoxSPmtBmkeMjcI2giJ8X7PNjrqSU4+qqKxvZwf/Wrxf1mbcJwpG+G0r8PMYu2Zw== X-Received: by 2002:a17:902:1ab:: with SMTP id b40mr95895plb.139.1554204554904; Tue, 02 Apr 2019 04:29:14 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a62:4554:: with SMTP id s81ls145090pfa.3.gmail; Tue, 02 Apr 2019 04:29:14 -0700 (PDT) X-Received: by 2002:a62:5385:: with SMTP id h127mr66239290pfb.10.1554204554465; Tue, 02 Apr 2019 04:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554204554; cv=none; d=google.com; s=arc-20160816; b=FLuJ8HFlYVRD8zd+dE+VceNu4RXpHBQapLZRQO5SE55TOOdFq13JdUbk03RofVvOuQ 0oUndBLcX7m9DAoM45j40uC7gA1Jm4qiIsf/wrp8zhSCOoFip6N0ZkMiO+w4rFxtlMHu UCYIVK96JGFoPjhY/LHLJtGLENqCvFCkW6fdwcNpvD2/Y0zx7LnztY/u0RNzR/Id4a6J qNUznXEbcGb7xK1vhhtPgbMiKC9Lhu01UaAm7vMOghyzPF6j9gvBXzsObsfrEQ8Nu5Tj 70+JQgrKn6zoA6yyKCQUJYqLj9e7MA3i90agDt7hYDWZGnFkibqyJLNKNq6+VLtSPvcA zJtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=LXIxXUhtyJWzir7sGVpBhJ+M/jZkPrnV0ICtRuNFk3E=; b=HFtGUh+fRAh7P2r+8BfZv20G4Jd3A+s2zgSCfqbqIzNE6/KZTaqbg7ML1FFcE60or8 u+h7VAz2VHvwGO5NXykN/SnJvhySgpjM9OwhN3/eihqE5zvv56pVKzYX46w4LxEwqkVj 5EnBMBlgrMVHdU8X1fs0MTDoSKrtJYj7G2eTrvsagGXy/mcjtBqU+zqNAegRQ6N20hWg vYv2CjGbaJoR1Hl08YCEMUKpxH9DfZ8svbg1IF+VSLZNIs7pzQek0kOE039CkkhY+xI7 5Hlz6TWWLhfEToHkB6HkCiLEaBXJAWOdVgzKE77sm9f1aNienqhV+YFkVlcu09ayE4RG pVJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ey9lIdgh; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id q71sor12990338pfc.2.2019.04.02.04.29.13 for (Google Transport Security); Tue, 02 Apr 2019 04:29:13 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:aa7:83ce:: with SMTP id j14mr490554pfn.57.1554204552971; Tue, 02 Apr 2019 04:29:12 -0700 (PDT) Received: from jagan-XPS-13-9350.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u62sm23992715pfa.124.2019.04.02.04.29.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 04:29:12 -0700 (PDT) From: Jagan Teki To: Simon Glass , Tom Rini , Neil Armstrong , Philipp Tomsich , Marek Vasut , Stefano Babic , Fabio Estevam , Peng Fan , Maxime Ripard , Michael Trimarchi , Andre Przywara Cc: u-boot@lists.denx.de, uboot-imx@nxp.com, Shyam Saini , linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v2 02/10] clk: imx: Add i.MX6Q clock driver Date: Tue, 2 Apr 2019 16:58:35 +0530 Message-Id: <20190402112843.992-3-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20190402112843.992-1-jagan@amarulasolutions.com> References: <20190402112843.992-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ey9lIdgh; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@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: , i.MX6 clock control module comprise of parent clocks, gates, multiplexers, dividers, PODF, PLL, fixed rate and etc. This patch add i.MX6Q USDHC clocks via gate clock which would eventually handle enable/disable operations via imx6_clock_gate. Signed-off-by: Jagan Teki --- arch/arm/include/asm/arch-mx6/clock.h | 44 +++++++++++++++++ drivers/clk/imx/Kconfig | 9 +++- drivers/clk/imx/Makefile | 5 ++ drivers/clk/imx/clk-imx6-common.c | 69 +++++++++++++++++++++++++++ drivers/clk/imx/clk-imx6q.c | 39 +++++++++++++++ 5 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 drivers/clk/imx/clk-imx6-common.c create mode 100644 drivers/clk/imx/clk-imx6q.c diff --git a/arch/arm/include/asm/arch-mx6/clock.h b/arch/arm/include/asm/arch-mx6/clock.h index a9481a5fea..fa921a9f08 100644 --- a/arch/arm/include/asm/arch-mx6/clock.h +++ b/arch/arm/include/asm/arch-mx6/clock.h @@ -21,6 +21,50 @@ #define MXC_CLK32 32768 #endif +/** + * struct imx6_clk_gate - imx6 ccm clock gate + * + * @off: ccm gate offset + * @bit: ccm gate bit + */ +struct imx6_clk_gate { + u16 off; + u32 bit; +}; + +#define GATE(_off, _bit) { \ + .off = _off, \ + .bit = _bit, \ +} + +/** + * struct imx6_clk_desc - imx6 clock control module descriptor + * + * @gates: ccm clock gates + */ +struct imx6_clk_desc { + const struct imx6_clk_gate *gates; +}; + +/** + * struct imx6_clk_priv - imx6 clock control module + * + * @base: ccm base address + * @desc: ccm descriptor + */ +struct imx6_clk_priv { + void *base; + const struct imx6_clk_desc *desc; +}; + +/** + * imx6_clk_probe - common imx6 clock probe + * @dev: clock device + */ +int imx6_clk_probe(struct udevice *dev); + +extern struct clk_ops imx6_clk_ops; + enum mxc_clock { MXC_ARM_CLK = 0, MXC_PER_CLK, diff --git a/drivers/clk/imx/Kconfig b/drivers/clk/imx/Kconfig index a125c23a19..f81903dcf4 100644 --- a/drivers/clk/imx/Kconfig +++ b/drivers/clk/imx/Kconfig @@ -1,6 +1,6 @@ config CLK_IMX bool "Clock support for i.MX SoCs" - depends on CLK && ARCH_IMX8 + depends on CLK && (ARCH_MX6 || ARCH_IMX8) default y help This enables support for common clock driver API on i.MX @@ -8,6 +8,13 @@ config CLK_IMX if CLK_IMX +config CLK_IMX6Q + bool "Clock driver for i.MX6QDL" + default MX6QDL + help + This enables common clock driver support for platforms based + on i.MX6 QDL SoC. + config CLK_IMX8 bool "Clock support for i.MX8" default ARCH_IMX8 diff --git a/drivers/clk/imx/Makefile b/drivers/clk/imx/Makefile index 5505ae52e2..a4cb2bbf3b 100644 --- a/drivers/clk/imx/Makefile +++ b/drivers/clk/imx/Makefile @@ -2,4 +2,9 @@ # # SPDX-License-Identifier: GPL-2.0 +ifdef CONFIG_ARCH_MX6 +obj-$(CONFIG_CLK_IMX) += clk-imx6-common.o +endif + +obj-$(CONFIG_CLK_IMX6Q) += clk-imx6q.o obj-$(CONFIG_CLK_IMX8) += clk-imx8.o diff --git a/drivers/clk/imx/clk-imx6-common.c b/drivers/clk/imx/clk-imx6-common.c new file mode 100644 index 0000000000..1d38f51f7e --- /dev/null +++ b/drivers/clk/imx/clk-imx6-common.c @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019 Amarula Solutions. + * Author: Jagan Teki + */ + +#include +#include +#include +#include +#include +#include +#include + +static const struct imx6_clk_gate *priv_to_gate(struct imx6_clk_priv *priv, + unsigned long id) +{ + return &priv->desc->gates[id]; +} + +static int imx6_set_gate(struct clk *clk, bool on) +{ + struct imx6_clk_priv *priv = dev_get_priv(clk->dev); + const struct imx6_clk_gate *gate = priv_to_gate(priv, clk->id); + u32 reg; + + debug("%s: (CLK#%ld) off#0x%x, BIT(%d)\n", __func__, + clk->id, gate->off, ilog2(gate->bit)); + + reg = readl(priv->base + gate->off); + if (on) + reg |= gate->bit; + else + reg &= ~gate->bit; + + writel(reg, priv->base + gate->off); + + return 0; +} + +static int imx6_clk_enable(struct clk *clk) +{ + return imx6_set_gate(clk, true); +} + +static int imx6_clk_disable(struct clk *clk) +{ + return imx6_set_gate(clk, false); +} + +struct clk_ops imx6_clk_ops = { + .enable = imx6_clk_enable, + .disable = imx6_clk_disable, +}; + +int imx6_clk_probe(struct udevice *dev) +{ + struct imx6_clk_priv *priv = dev_get_priv(dev); + + priv->base = dev_read_addr_ptr(dev); + if (!priv->base) + return -ENOMEM; + + priv->desc = (const struct imx6_clk_desc *)dev_get_driver_data(dev); + if (!priv->desc) + return -EINVAL; + + return 0; +} diff --git a/drivers/clk/imx/clk-imx6q.c b/drivers/clk/imx/clk-imx6q.c new file mode 100644 index 0000000000..8ec713298d --- /dev/null +++ b/drivers/clk/imx/clk-imx6q.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2019 Amarula Solutions. + * Author: Jagan Teki + */ + +#include +#include +#include +#include +#include + +static const struct imx6_clk_gate imx6q_gates[] = { + [IMX6QDL_CLK_USDHC1] = GATE(0x080, GENMASK(3, 2)), + [IMX6QDL_CLK_USDHC2] = GATE(0x080, GENMASK(5, 4)), + [IMX6QDL_CLK_USDHC3] = GATE(0x080, GENMASK(7, 6)), + [IMX6QDL_CLK_USDHC4] = GATE(0x080, GENMASK(9, 8)), +}; + +static const struct imx6_clk_desc imx6q_clk_desc = { + .gates = imx6q_gates, +}; + +static const struct udevice_id clk_imx6q_ids[] = { + { + .compatible = "fsl,imx6q-ccm", + .data = (ulong)&imx6q_clk_desc + }, + { /* sentinel */ } +}; + +U_BOOT_DRIVER(clk_imx6q) = { + .name = "clk_imx6q", + .id = UCLASS_CLK, + .of_match = clk_imx6q_ids, + .priv_auto_alloc_size = sizeof(struct imx6_clk_priv), + .ops = &imx6_clk_ops, + .probe = imx6_clk_probe, +};