From patchwork Mon Dec 31 16:59:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 115 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f200.google.com (cartago.priv [10.11.12.1]) by cassiopea.amarulasolutions.com (Postfix) with ESMTPS id 6CA5A2E0AD1 for ; Mon, 31 Dec 2018 18:00:29 +0100 (CET) Received: by mail-pf1-f200.google.com with SMTP id 68sf29387284pfr.6 for ; Mon, 31 Dec 2018 09:00:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1546275627; cv=pass; d=google.com; s=arc-20160816; b=KVgue89ui+ikdKi2Zhwp+RXjpej7jE2woQAGvo54fajlpxNtRb0SD10l14YrfaVckV RziHTUnsPZyLbGSJ5XV+JwHwIR6qB/ZpcdjZRhYF93aVF+amilXa+X2Caa3M4aWHym8L TyGwR6TlVODBL6yddbLEwF+l5eiohGNOZRBAa9Ge49dCWQfFnBQCTNas4+ipZ/LoW8BH llMYCaf/34LVoGToVmRWMhjvPNXtNEUepe5olIH2uk0IkP4XkP9GKjB5F9IVpFc8JPO5 xjQzUKUsv4mv3qxcQP5+mYZlOXhmawtX6YWRblFgaPg71P3wQM4O7/Ci3aYX8WA42swC UKgw== 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:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=13lh1JCzYnLbrt+OnxpgRxd2gdlp9wkb0cpR83R7iwE=; b=QfPUX0xbRjoSGHodc8b8r85HfXb/4PamrUUTanP2dWn/2z2Cu1XASplUzLC9QyhW5b rH2P5INKHpGzqas0ukNpe6omblZh7El/b3R19dO+NuPHEKEyurY7irSALhjXqf1EK05K OFA6rE27+dxtBw3V1/y/I/yUjG04Jz51O1IHwdKchqUbwTVM6Whzjutudbm94J5OLpQ8 bgX6EIoAnuF0VrIqmAWLK8JG2mnKnmewBJSA91T4roke6BjR2DFwnvvS198ri2uwJaEP sbKc/uOA08Gaf1rd4P11wpKTFCY2fHvXCi7+ravMa6Ev3DoeCOU+Qu4W6W0+lEinAtdB wyNQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Tl5oXTGI; 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:content-transfer-encoding:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=13lh1JCzYnLbrt+OnxpgRxd2gdlp9wkb0cpR83R7iwE=; b=aXddSVSOmZpItxX9mBKtBz1ngSHa8Pp4DNJQrJF3y4kOd+UhWtJO8Qc8qG2doqoE2Y ROlGVgIDkrd1WcDIzCIkQopPBjqXMtd8ixBuoJWNVGOvZ61MOv4879qbjdxf6sFSZIpg aCaq9zOm34UfC1vYGAwghOhdDu0PSDRSNE9qE= 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:content-transfer-encoding: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=13lh1JCzYnLbrt+OnxpgRxd2gdlp9wkb0cpR83R7iwE=; b=LrwYmfoAPe5cyX7a+THFRsxtKuSNuBeUxC/+Z8g+/hoT4mXwYq/KlvYM6ZHvOQXG8n JX7bQDnjo5Pi8PwWZqQi3YQfRbuK+qahNQ7boKwOLiLwG7U/jcI/JcVR30DVf8f/a4FU 0ivqsZSGL3/Rk6Shby67INSs1uDEG7/cO8rHVlhC8NyeQdTycNDO8YuqxQN+bpDggK5o 1K6GftaSEGloh76LCaDVWs1rxt3iH28igXEh2OakxTFaRD5tDwn4myiKZrytaCo2rHqu LIB3N0gmmebZh6HiNQvzpM2+TaeDCXMkxa0232+6hLE1JOTUds1piEYXChZNUTrlpjYQ e28w== X-Gm-Message-State: AA+aEWa7egYpYRni1KQNmEFHCUUTXqoiO++lei/6izWvAxvGkmkVspoM eTQSNPPb5C2o2Qq79Su4Z9jBW1gP X-Google-Smtp-Source: ALg8bN7KJoQoWgFzKpy39vVBkIYdAeeH9llsyOAfx+8Y8nc8ooVGTDtsGK+3VDeyf2NIoWMe9cRzwQ== X-Received: by 2002:a62:7693:: with SMTP id r141mr16983466pfc.119.1546275627656; Mon, 31 Dec 2018 09:00:27 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:a718:: with SMTP id w24ls13412134plq.7.gmail; Mon, 31 Dec 2018 09:00:27 -0800 (PST) X-Received: by 2002:a17:902:47aa:: with SMTP id r39mr37395434pld.219.1546275627302; Mon, 31 Dec 2018 09:00:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546275627; cv=none; d=google.com; s=arc-20160816; b=sw739Qed/lseopkaYDjFsXBKJlME79bWQut3Xh94xvEh5rRBFNjHMmd2AE6KjZoA14 upbOo0MOTHsEpN7vIaGJtpeCJkks3+t3r/6v+DFgjT1nh4CwXaJ/XN09xbWNbJhwB1no pg+U+ki6tvuNQ6Z/ZnEmLbgTv5wsTPXWZCbQfLtkTDV1meeCP5uihJxap8IGnHf4JOfA fLkoUGP+In6A0B6Xe23gMzBN65Jbbel1oPd3bY8ivLY96CtT56e9BjYBYqxtmwI+uJmh 5peDKioNCiBnu6ImvhF0hbe053/H13rcRu+H5LaQKx8GuXjpHaq7rxOCYPRFNSgZAHVU v9bw== 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=13lh1JCzYnLbrt+OnxpgRxd2gdlp9wkb0cpR83R7iwE=; b=WW+jGrwpcrDNBgc7ZcCyscwCqTgOOtes2JBtiEg229OMkrQLWBGM5EjMiww1hSbHfI cRQwdZlnyfyiEkc2dQmUickU500dwL59204YJ5+hOGCUC8DA0Nbzt4QJ159TQ9kF1oQY Za5LA3IYY7hFCLh78+3ENl/AQXkNJwq7bQPRb7Dz6DxTj9+hhhBOAOGHcue17LU0y0aS FB6OOR3jI/jGIWGrWztpVF+Oncv2iNUwj6WIumoZOjXbFWxLpJKAHU0nckVw/Q0CmG93 WgMDWA9Eun+q7BcOQZg6EZdYFTjhVLsBQOdauJcMytWoz4rqT0IABDZo5ONTMb9TVyxh onSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Tl5oXTGI; 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 x8sor13234637plo.55.2018.12.31.09.00.27 for (Google Transport Security); Mon, 31 Dec 2018 09:00:27 -0800 (PST) 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:a17:902:3283:: with SMTP id z3mr38324482plb.76.1546275626843; Mon, 31 Dec 2018 09:00:26 -0800 (PST) Received: from localhost.localdomain ([115.97.184.237]) by smtp.gmail.com with ESMTPSA id p7sm90692925pfj.72.2018.12.31.09.00.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Dec 2018 09:00:26 -0800 (PST) From: Jagan Teki To: Maxime Ripard , Andre Przywara Cc: Chen-Yu Tsai , Simon Glass , Tom Rini , u-boot@lists.denx.de, linux-sunxi@googlegroups.com, Michael Trimarchi , linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v5 01/26] clk: Add Allwinner A64 CLK driver Date: Mon, 31 Dec 2018 22:29:02 +0530 Message-Id: <20181231165927.13803-2-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20181231165927.13803-1-jagan@amarulasolutions.com> References: <20181231165927.13803-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=Tl5oXTGI; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com 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 initial clock driver for Allwinner A64. Implement USB clock enable and disable functions for OHCI, EHCI, OTG and USBPHY gate and clock registers via ccu clk gate table. Signed-off-by: Jagan Teki Acked-by: Maxime Ripard --- arch/arm/include/asm/arch-sunxi/ccu.h | 65 +++++++++++++++++++++++ drivers/clk/Kconfig | 1 + drivers/clk/Makefile | 1 + drivers/clk/sunxi/Kconfig | 18 +++++++ drivers/clk/sunxi/Makefile | 9 ++++ drivers/clk/sunxi/clk_a64.c | 46 +++++++++++++++++ drivers/clk/sunxi/clk_sunxi.c | 74 +++++++++++++++++++++++++++ 7 files changed, 214 insertions(+) create mode 100644 arch/arm/include/asm/arch-sunxi/ccu.h create mode 100644 drivers/clk/sunxi/Kconfig create mode 100644 drivers/clk/sunxi/Makefile create mode 100644 drivers/clk/sunxi/clk_a64.c create mode 100644 drivers/clk/sunxi/clk_sunxi.c diff --git a/arch/arm/include/asm/arch-sunxi/ccu.h b/arch/arm/include/asm/arch-sunxi/ccu.h new file mode 100644 index 0000000000..db69c8f0d5 --- /dev/null +++ b/arch/arm/include/asm/arch-sunxi/ccu.h @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Amarula Solutions. + * Author: Jagan Teki + */ + +#ifndef _ASM_ARCH_CCU_H +#define _ASM_ARCH_CCU_H + +/** + * enum ccu_clk_flags - ccu clock flags + * + * @CCU_CLK_F_INIT_DONE: clock gate init done check + */ +enum ccu_clk_flags { + CCU_CLK_F_INIT_DONE = BIT(0), +}; + +/** + * struct ccu_clk_gate - ccu clock gate + * @off: gate offset + * @bit: gate bit + * @flags: clock gate flags + */ +struct ccu_clk_gate { + u16 off; + u32 bit; + enum ccu_clk_flags flags; +}; + +#define GATE(_off, _bit) { \ + .off = _off, \ + .bit = _bit, \ + .flags = CCU_CLK_F_INIT_DONE, \ +} + +/** + * struct ccu_desc - clock control unit descriptor + * + * @gates: clock gates + */ +struct ccu_desc { + const struct ccu_clk_gate *gates; +}; + +/** + * struct ccu_priv - sunxi clock control unit + * + * @base: base address + * @desc: ccu descriptor + */ +struct ccu_priv { + void *base; + const struct ccu_desc *desc; +}; + +/** + * sunxi_clk_probe - common sunxi clock probe + * @dev: clock device + */ +int sunxi_clk_probe(struct udevice *dev); + +extern struct clk_ops sunxi_clk_ops; + +#endif /* _ASM_ARCH_CCU_H */ diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index eadf7f8250..51c931b906 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -104,6 +104,7 @@ source "drivers/clk/imx/Kconfig" source "drivers/clk/mvebu/Kconfig" source "drivers/clk/owl/Kconfig" source "drivers/clk/renesas/Kconfig" +source "drivers/clk/sunxi/Kconfig" source "drivers/clk/tegra/Kconfig" source "drivers/clk/uniphier/Kconfig" diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index 9acbb1a650..6a4ff9143b 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -22,6 +22,7 @@ obj-$(CONFIG_CLK_HSDK) += clk-hsdk-cgu.o obj-$(CONFIG_CLK_MPC83XX) += mpc83xx_clk.o obj-$(CONFIG_CLK_OWL) += owl/ obj-$(CONFIG_CLK_RENESAS) += renesas/ +obj-$(CONFIG_ARCH_SUNXI) += sunxi/ obj-$(CONFIG_CLK_STM32F) += clk_stm32f.o obj-$(CONFIG_CLK_STM32MP1) += clk_stm32mp1.o obj-$(CONFIG_CLK_UNIPHIER) += uniphier/ diff --git a/drivers/clk/sunxi/Kconfig b/drivers/clk/sunxi/Kconfig new file mode 100644 index 0000000000..bf5ecb3801 --- /dev/null +++ b/drivers/clk/sunxi/Kconfig @@ -0,0 +1,18 @@ +config CLK_SUNXI + bool "Clock support for Allwinner SoCs" + depends on CLK && ARCH_SUNXI + default y + help + This enables support for common clock driver API on Allwinner + SoCs. + +if CLK_SUNXI + +config CLK_SUN50I_A64 + bool "Clock driver for Allwinner A64" + default MACH_SUN50I + help + This enables common clock driver support for platforms based + on Allwinner A64 SoC. + +endif # CLK_SUNXI diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile new file mode 100644 index 0000000000..fb20d28333 --- /dev/null +++ b/drivers/clk/sunxi/Makefile @@ -0,0 +1,9 @@ +# +# Copyright (C) 2018 Amarula Solutions. +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-$(CONFIG_CLK_SUNXI) += clk_sunxi.o + +obj-$(CONFIG_CLK_SUN50I_A64) += clk_a64.o diff --git a/drivers/clk/sunxi/clk_a64.c b/drivers/clk/sunxi/clk_a64.c new file mode 100644 index 0000000000..803a2f711d --- /dev/null +++ b/drivers/clk/sunxi/clk_a64.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Amarula Solutions. + * Author: Jagan Teki + */ + +#include +#include +#include +#include +#include +#include + +static const struct ccu_clk_gate a64_gates[] = { + [CLK_BUS_OTG] = GATE(0x060, BIT(23)), + [CLK_BUS_EHCI0] = GATE(0x060, BIT(24)), + [CLK_BUS_EHCI1] = GATE(0x060, BIT(25)), + [CLK_BUS_OHCI0] = GATE(0x060, BIT(28)), + [CLK_BUS_OHCI1] = GATE(0x060, BIT(29)), + + [CLK_USB_PHY0] = GATE(0x0cc, BIT(8)), + [CLK_USB_PHY1] = GATE(0x0cc, BIT(9)), + [CLK_USB_HSIC] = GATE(0x0cc, BIT(10)), + [CLK_USB_HSIC_12M] = GATE(0x0cc, BIT(11)), + [CLK_USB_OHCI0] = GATE(0x0cc, BIT(16)), + [CLK_USB_OHCI1] = GATE(0x0cc, BIT(17)), +}; + +static const struct ccu_desc a64_ccu_desc = { + .gates = a64_gates, +}; + +static const struct udevice_id a64_ccu_ids[] = { + { .compatible = "allwinner,sun50i-a64-ccu", + .data = (ulong)&a64_ccu_desc }, + { } +}; + +U_BOOT_DRIVER(clk_sun50i_a64) = { + .name = "sun50i_a64_ccu", + .id = UCLASS_CLK, + .of_match = a64_ccu_ids, + .priv_auto_alloc_size = sizeof(struct ccu_priv), + .ops = &sunxi_clk_ops, + .probe = sunxi_clk_probe, +}; diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c new file mode 100644 index 0000000000..345d706c2a --- /dev/null +++ b/drivers/clk/sunxi/clk_sunxi.c @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Amarula Solutions. + * Author: Jagan Teki + */ + +#include +#include +#include +#include +#include +#include +#include + +static const struct ccu_clk_gate *priv_to_gate(struct ccu_priv *priv, + unsigned long id) +{ + return &priv->desc->gates[id]; +} + +static int sunxi_set_gate(struct clk *clk, bool on) +{ + struct ccu_priv *priv = dev_get_priv(clk->dev); + const struct ccu_clk_gate *gate = priv_to_gate(priv, clk->id); + u32 reg; + + if (!(gate->flags & CCU_CLK_F_INIT_DONE)) { + printf("%s: (CLK#%ld) unhandled\n", __func__, clk->id); + return 0; + } + + 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 sunxi_clk_enable(struct clk *clk) +{ + return sunxi_set_gate(clk, true); +} + +static int sunxi_clk_disable(struct clk *clk) +{ + return sunxi_set_gate(clk, false); +} + +struct clk_ops sunxi_clk_ops = { + .enable = sunxi_clk_enable, + .disable = sunxi_clk_disable, +}; + +int sunxi_clk_probe(struct udevice *dev) +{ + struct ccu_priv *priv = dev_get_priv(dev); + + priv->base = dev_read_addr_ptr(dev); + if (!priv->base) + return -ENOMEM; + + priv->desc = (const struct ccu_desc *)dev_get_driver_data(dev); + if (!priv->desc) + return -EINVAL; + + return 0; +}