From patchwork Tue Nov 28 07:19:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 119797 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1357663qgn; Mon, 27 Nov 2017 23:19:47 -0800 (PST) X-Google-Smtp-Source: AGs4zMZl5m36XApwTVuN49Z43bS6cpTejqeEIMXnY6ILm2wISdnj2JwcBjKcASh4sSgTxu6fIrMO X-Received: by 10.98.87.13 with SMTP id l13mr40585618pfb.193.1511853587547; Mon, 27 Nov 2017 23:19:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511853587; cv=none; d=google.com; s=arc-20160816; b=kEwTBecJIk0hMNzUH3oRciXVD8bfgmnPdBI9MKVB5uGHkXePOkSQD4cjvmyVn7YmV7 JK115H+vNUvQrXh2fPrXE9C79HaPt82qRTUijVpu0KazIco/aoeqJnyDkEL2KwG8y/Va N1rQZ1DE3tpv2tgOs72D/sxMoDNB7parh3a+ebE/eD4YP0QllGUn2NEtp7u/9Aqs2XSw rzLe2Suj0qXHvMB5fA4otUJZKF2Dja3SKNIw/AnGhEzWuw7O06Z6M1ZlCoqopQqwXCCy 60E39uXKVyFj9/Z5PzKEHci7Zz2C7sHfKO/E93+L09kUYPA32mqRy8/nHC/I2SJlvb34 1dfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=U7Lvb9iV1++55WZtZ6OlYhJtoJpRjNtatZlg4XpfJNI=; b=gN0Ub3fwUwSBLAt6I9m145ssSSJ48QDydYJPkIvnBKR7iLA++3Hl8FOnTPdC9KBYgM 87ec96FuKX3whpEdcx+oXLQZbiKwo7REeXsGsNizF+sfL6vVgWq727vJzs4Gf57LIc86 8SJtz80/lCaZGDaYOXJv7JptsGNA1Uugfbz+s4ZYjwg92YHjW1EQPEUR2DRyMxjXrglk EPo5VY+S2wiXudFR0jgXGiWbKC01iS3XoSu8xc/Z7yHYXPwE/btK0EOywil8dvp18lkI rn4ibokCFTjDXdDTaNRXPzCXZxrPasBtD3oG7Flkn0AcRz3nqKzZdv+FY585nbrL9OMB 2diA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=iJfNv+Rj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7si4493238pgq.631.2017.11.27.23.19.47; Mon, 27 Nov 2017 23:19:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=iJfNv+Rj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751889AbdK1HTp (ORCPT + 28 others); Tue, 28 Nov 2017 02:19:45 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:39052 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751256AbdK1HTn (ORCPT ); Tue, 28 Nov 2017 02:19:43 -0500 Received: by mail-pf0-f193.google.com with SMTP id l24so18584432pfj.6; Mon, 27 Nov 2017 23:19:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=U7Lvb9iV1++55WZtZ6OlYhJtoJpRjNtatZlg4XpfJNI=; b=iJfNv+Rj3X5mjeEhZS3OlOjuw1ru9M35SWhyS5jhNOYfdMwf8ynK8EDznfPmhgrEVU 8bS3IlrXssFXwYB9e68h80KU9LTuODdAprQ4Jw5rv2B35YEl/OKbfsxSJQVfAWAxv2yf hmysQ9RpIpVzgkuvFvebz81K7MCXjR5BrNhiGOfbEtbUMtMDf8ESmOHaaCPzegYwx8Uk aak/l0eTL5lduo7aJlE1fYBkYvBKAmGMYiHD45PpL5kP1F6+zmTrdx1mU5zXhygGelCC 34qb62pzcrXzTLQFyMfiTFXT7VeyqeuWC9LZ5MHJkayEj1M48gbV5ivTgnEZUha231en aL2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=U7Lvb9iV1++55WZtZ6OlYhJtoJpRjNtatZlg4XpfJNI=; b=RXKe40Nw+U55gcOylNPGqirYZelRxM93/cKvKNfvkaho0UuFo+2SgxgG9XwmKxS0x1 iLSmjekl/hIC5EgGTIGTdxoVQDsgBvlBZ4VPzfK67AljBVkKUMRregwstKcfOTbzUiTi i7lNHGOzLVjLcYGAg0kIoPdGP5ueCotk285JEjljy5hU05FwRd+NdRA/LWQLnwuJqakD NwbznLFCN9Q1A8oBMNRe8TsvuE7YXm1QI69hs4DdQiS8nO6wr/Nm3MT2YrH9QD/vgqF3 cSVDggfiCvDkygEAoMFdLzaBh9jQDfAiGrXQ1mClj+/ZunRfsmFLngCyJlWFt5u7WuEV 0A/Q== X-Gm-Message-State: AJaThX7Nf1q9S0I89x4bKeN+0EMYT/CKDSdOw9x0UbuqVAnvWMOV5ZHe i8A0MElmPtr2CJEq0BSgJd4= X-Received: by 10.98.223.217 with SMTP id d86mr40254820pfl.190.1511853582837; Mon, 27 Nov 2017 23:19:42 -0800 (PST) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id b9sm42267277pgu.20.2017.11.27.23.19.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Nov 2017 23:19:41 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Tue, 28 Nov 2017 17:49:33 +1030 From: Joel Stanley To: Lee Jones , Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Andrew Jeffery , Benjamin Herrenschmidt , Jeremy Kerr , Rick Altherr , Ryan Chen , Arnd Bergmann Subject: [PATCH v6 1/5] clk: Add clock driver for ASPEED BMC SoCs Date: Tue, 28 Nov 2017 17:49:04 +1030 Message-Id: <20171128071908.12279-2-joel@jms.id.au> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171128071908.12279-1-joel@jms.id.au> References: <20171128071908.12279-1-joel@jms.id.au> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds the stub of a driver for the ASPEED SoCs. The clocks are defined and the static registration is set up. Reviewed-by: Andrew Jeffery Signed-off-by: Joel Stanley --- v6: - Add SPDX copyright notices v5: - Add Andrew's reviewed-by - Make aspeed_gates not initconst to avoid section mismatch warning v3: - use named initlisers for aspeed_gates table - fix clocks typo - Move ASPEED_NUM_CLKS to the bottom of the list - Put gates at the start of the list, so we can use them to initalise the aspeed_gates table - Add ASPEED_CLK_SELECTION_2 - Set parent of network MAC gates --- drivers/clk/Kconfig | 12 +++ drivers/clk/Makefile | 1 + drivers/clk/clk-aspeed.c | 139 +++++++++++++++++++++++++++++++ include/dt-bindings/clock/aspeed-clock.h | 44 ++++++++++ 4 files changed, 196 insertions(+) create mode 100644 drivers/clk/clk-aspeed.c create mode 100644 include/dt-bindings/clock/aspeed-clock.h -- 2.14.1 diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index 1c4e1aa6767e..9abe063ef8d2 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -142,6 +142,18 @@ config COMMON_CLK_GEMINI This driver supports the SoC clocks on the Cortina Systems Gemini platform, also known as SL3516 or CS3516. +config COMMON_CLK_ASPEED + bool "Clock driver for Aspeed BMC SoCs" + depends on ARCH_ASPEED || COMPILE_TEST + default ARCH_ASPEED + select MFD_SYSCON + select RESET_CONTROLLER + ---help--- + This driver supports the SoC clocks on the Aspeed BMC platforms. + + The G4 and G5 series, including the ast2400 and ast2500, are supported + by this driver. + config COMMON_CLK_S2MPS11 tristate "Clock driver for S2MPS1X/S5M8767 MFD" depends on MFD_SEC_CORE || COMPILE_TEST diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index f7f761b02bed..d260da4809f8 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_ARCH_CLPS711X) += clk-clps711x.o obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.o obj-$(CONFIG_ARCH_EFM32) += clk-efm32gg.o obj-$(CONFIG_COMMON_CLK_GEMINI) += clk-gemini.o +obj-$(CONFIG_COMMON_CLK_ASPEED) += clk-aspeed.o obj-$(CONFIG_ARCH_HIGHBANK) += clk-highbank.o obj-$(CONFIG_CLK_HSDK) += clk-hsdk-pll.o obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c new file mode 100644 index 000000000000..381be5547178 --- /dev/null +++ b/drivers/clk/clk-aspeed.c @@ -0,0 +1,139 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#define pr_fmt(fmt) "clk-aspeed: " fmt + +#include +#include +#include +#include +#include +#include + +#include + +#define ASPEED_STRAP 0x70 + +/* Keeps track of all clocks */ +static struct clk_hw_onecell_data *aspeed_clk_data; + +static void __iomem *scu_base; + +/** + * struct aspeed_gate_data - Aspeed gated clocks + * @clock_idx: bit used to gate this clock in the clock register + * @reset_idx: bit used to reset this IP in the reset register. -1 if no + * reset is required when enabling the clock + * @name: the clock name + * @parent_name: the name of the parent clock + * @flags: standard clock framework flags + */ +struct aspeed_gate_data { + u8 clock_idx; + s8 reset_idx; + const char *name; + const char *parent_name; + unsigned long flags; +}; + +/** + * struct aspeed_clk_gate - Aspeed specific clk_gate structure + * @hw: handle between common and hardware-specific interfaces + * @reg: register controlling gate + * @clock_idx: bit used to gate this clock in the clock register + * @reset_idx: bit used to reset this IP in the reset register. -1 if no + * reset is required when enabling the clock + * @flags: hardware-specific flags + * @lock: register lock + * + * Some of the clocks in the Aspeed SoC must be put in reset before enabling. + * This modified version of clk_gate allows an optional reset bit to be + * specified. + */ +struct aspeed_clk_gate { + struct clk_hw hw; + struct regmap *map; + u8 clock_idx; + s8 reset_idx; + u8 flags; + spinlock_t *lock; +}; + +#define to_aspeed_clk_gate(_hw) container_of(_hw, struct aspeed_clk_gate, hw) + +/* TODO: ask Aspeed about the actual parent data */ +static const struct aspeed_gate_data aspeed_gates[] = { + /* clk rst name parent flags */ + [ASPEED_CLK_GATE_ECLK] = { 0, -1, "eclk-gate", "eclk", 0 }, /* Video Engine */ + [ASPEED_CLK_GATE_GCLK] = { 1, 7, "gclk-gate", NULL, 0 }, /* 2D engine */ + [ASPEED_CLK_GATE_MCLK] = { 2, -1, "mclk-gate", "mpll", CLK_IS_CRITICAL }, /* SDRAM */ + [ASPEED_CLK_GATE_VCLK] = { 3, 6, "vclk-gate", NULL, 0 }, /* Video Capture */ + [ASPEED_CLK_GATE_BCLK] = { 4, 10, "bclk-gate", "bclk", 0 }, /* PCIe/PCI */ + [ASPEED_CLK_GATE_DCLK] = { 5, -1, "dclk-gate", NULL, 0 }, /* DAC */ + [ASPEED_CLK_GATE_REFCLK] = { 6, -1, "refclk-gate", "clkin", CLK_IS_CRITICAL }, + [ASPEED_CLK_GATE_USBPORT2CLK] = { 7, 3, "usb-port2-gate", NULL, 0 }, /* USB2.0 Host port 2 */ + [ASPEED_CLK_GATE_LCLK] = { 8, 5, "lclk-gate", NULL, 0 }, /* LPC */ + [ASPEED_CLK_GATE_USBUHCICLK] = { 9, 15, "usb-uhci-gate", NULL, 0 }, /* USB1.1 (requires port 2 enabled) */ + [ASPEED_CLK_GATE_D1CLK] = { 10, 13, "d1clk-gate", NULL, 0 }, /* GFX CRT */ + [ASPEED_CLK_GATE_YCLK] = { 13, 4, "yclk-gate", NULL, 0 }, /* HAC */ + [ASPEED_CLK_GATE_USBPORT1CLK] = { 14, 14, "usb-port1-gate", NULL, 0 }, /* USB2 hub/USB2 host port 1/USB1.1 dev */ + [ASPEED_CLK_GATE_UART1CLK] = { 15, -1, "uart1clk-gate", "uart", 0 }, /* UART1 */ + [ASPEED_CLK_GATE_UART2CLK] = { 16, -1, "uart2clk-gate", "uart", 0 }, /* UART2 */ + [ASPEED_CLK_GATE_UART5CLK] = { 17, -1, "uart5clk-gate", "uart", 0 }, /* UART5 */ + [ASPEED_CLK_GATE_ESPICLK] = { 19, -1, "espiclk-gate", NULL, 0 }, /* eSPI */ + [ASPEED_CLK_GATE_MAC1CLK] = { 20, 11, "mac1clk-gate", "mac", 0 }, /* MAC1 */ + [ASPEED_CLK_GATE_MAC2CLK] = { 21, 12, "mac2clk-gate", "mac", 0 }, /* MAC2 */ + [ASPEED_CLK_GATE_RSACLK] = { 24, -1, "rsaclk-gate", NULL, 0 }, /* RSA */ + [ASPEED_CLK_GATE_UART3CLK] = { 25, -1, "uart3clk-gate", "uart", 0 }, /* UART3 */ + [ASPEED_CLK_GATE_UART4CLK] = { 26, -1, "uart4clk-gate", "uart", 0 }, /* UART4 */ + [ASPEED_CLK_GATE_SDCLKCLK] = { 27, 16, "sdclk-gate", NULL, 0 }, /* SDIO/SD */ + [ASPEED_CLK_GATE_LHCCLK] = { 28, -1, "lhclk-gate", "lhclk", 0 }, /* LPC master/LPC+ */ +}; + +static void __init aspeed_cc_init(struct device_node *np) +{ + struct regmap *map; + u32 val; + int ret; + int i; + + scu_base = of_iomap(np, 0); + if (IS_ERR(scu_base)) + return; + + aspeed_clk_data = kzalloc(sizeof(*aspeed_clk_data) + + sizeof(*aspeed_clk_data->hws) * ASPEED_NUM_CLKS, + GFP_KERNEL); + if (!aspeed_clk_data) + return; + + /* + * This way all clocks fetched before the platform device probes, + * except those we assign here for early use, will be deferred. + */ + for (i = 0; i < ASPEED_NUM_CLKS; i++) + aspeed_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER); + + map = syscon_node_to_regmap(np); + if (IS_ERR(map)) { + pr_err("no syscon regmap\n"); + return; + } + /* + * We check that the regmap works on this very first access, + * but as this is an MMIO-backed regmap, subsequent regmap + * access is not going to fail and we skip error checks from + * this point. + */ + ret = regmap_read(map, ASPEED_STRAP, &val); + if (ret) { + pr_err("failed to read strapping register\n"); + return; + } + + aspeed_clk_data->num = ASPEED_NUM_CLKS; + ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, aspeed_clk_data); + if (ret) + pr_err("failed to add DT provider: %d\n", ret); +}; +CLK_OF_DECLARE_DRIVER(aspeed_cc_g5, "aspeed,ast2500-scu", aspeed_cc_init); +CLK_OF_DECLARE_DRIVER(aspeed_cc_g4, "aspeed,ast2400-scu", aspeed_cc_init); diff --git a/include/dt-bindings/clock/aspeed-clock.h b/include/dt-bindings/clock/aspeed-clock.h new file mode 100644 index 000000000000..9e170fb9a0da --- /dev/null +++ b/include/dt-bindings/clock/aspeed-clock.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */ + +#ifndef DT_BINDINGS_ASPEED_CLOCK_H +#define DT_BINDINGS_ASPEED_CLOCK_H + +#define ASPEED_CLK_GATE_ECLK 0 +#define ASPEED_CLK_GATE_GCLK 1 +#define ASPEED_CLK_GATE_MCLK 2 +#define ASPEED_CLK_GATE_VCLK 3 +#define ASPEED_CLK_GATE_BCLK 4 +#define ASPEED_CLK_GATE_DCLK 5 +#define ASPEED_CLK_GATE_REFCLK 6 +#define ASPEED_CLK_GATE_USBPORT2CLK 7 +#define ASPEED_CLK_GATE_LCLK 8 +#define ASPEED_CLK_GATE_USBUHCICLK 9 +#define ASPEED_CLK_GATE_D1CLK 10 +#define ASPEED_CLK_GATE_YCLK 11 +#define ASPEED_CLK_GATE_USBPORT1CLK 12 +#define ASPEED_CLK_GATE_UART1CLK 13 +#define ASPEED_CLK_GATE_UART2CLK 14 +#define ASPEED_CLK_GATE_UART5CLK 15 +#define ASPEED_CLK_GATE_ESPICLK 16 +#define ASPEED_CLK_GATE_MAC1CLK 17 +#define ASPEED_CLK_GATE_MAC2CLK 18 +#define ASPEED_CLK_GATE_RSACLK 19 +#define ASPEED_CLK_GATE_UART3CLK 20 +#define ASPEED_CLK_GATE_UART4CLK 21 +#define ASPEED_CLK_GATE_SDCLKCLK 22 +#define ASPEED_CLK_GATE_LHCCLK 23 +#define ASPEED_CLK_HPLL 24 +#define ASPEED_CLK_AHB 25 +#define ASPEED_CLK_APB 26 +#define ASPEED_CLK_UART 27 +#define ASPEED_CLK_SDIO 28 +#define ASPEED_CLK_ECLK 29 +#define ASPEED_CLK_ECLK_MUX 30 +#define ASPEED_CLK_LHCLK 31 +#define ASPEED_CLK_MAC 32 +#define ASPEED_CLK_BCLK 33 +#define ASPEED_CLK_MPLL 34 + +#define ASPEED_NUM_CLKS 35 + +#endif From patchwork Tue Nov 28 07:19:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 119798 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1357808qgn; Mon, 27 Nov 2017 23:19:57 -0800 (PST) X-Google-Smtp-Source: AGs4zMapzLv35zeDJfdQLkIwIi0NyByp6SLhSA1TGTOX3Mr+kHrDEV4aj4tpSH7QWBPEr01Sjd5G X-Received: by 10.98.161.25 with SMTP id b25mr40127512pff.103.1511853597691; Mon, 27 Nov 2017 23:19:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511853597; cv=none; d=google.com; s=arc-20160816; b=fm+5GJg01tCDvrbJuPu4QtjvFtAdHoXAWWwj3Gg8OB7nTvxY4UT77T46JpFOcl6/K0 6ZMswO+pwyuvCYrMkvUH5CB2hFbgMAzm6IeQUDoJytswcciwRGW466yXmpgZDTj2IlB/ V36rcCjtT0wEBJK/innje5xHiqbRgS8aOHCzR3JfZjAsOKTgPp6IahopRqFlGrXq71Xj OEr4alSF8rTzNlzearquWd/YOVQ7mmx0I9uUgUSwFsUmZQz3KU+fJTFmEq3mf4ibIJrN nioLomkjcHjTH5bIzfYw3ER61tw6itfUOZ6rRtmsraAaHSxs6jV6w4DF32o8E7yB5+3u zUlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=xxVwBCV3Q+1UYkdjI7iuVrOWGDrKX7Gdy+/FpNTDiKM=; b=zAFMEhJS9AzhqXMBRweAxUBZoOJlf+UzDuiEWGR+OhdjQ2ArMn6FdOYbsFE+Xmie8n 6stEdc1C97c3Y2Dw5fbGjQlqNP2TbRu5bi3HbYsVWBQgs3g8BPJHo27NgQwYvvul/o73 wOKGgfPP3ob9cask7p0FT0Njl3orypPbw9OhRTqYL8WNPs0tGDGTLTk56heBJXBAf8n1 F2vIAFQWZhXUbQFvtN+TudGWGFiyTxwH8EM2xTc3BK2M6F+PAtgf5Ejx1WXM7QJuC23r 5xclsKbOjBt5yN7SAftvAuQoffbLDKSFdqSbYDZ+F9tVstButImwajEqc9rZb7laf/Ka Uwxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=IQ0O0Zus; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h69si24043864pge.382.2017.11.27.23.19.57; Mon, 27 Nov 2017 23:19:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=IQ0O0Zus; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751935AbdK1HT4 (ORCPT + 28 others); Tue, 28 Nov 2017 02:19:56 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:42973 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751256AbdK1HTx (ORCPT ); Tue, 28 Nov 2017 02:19:53 -0500 Received: by mail-pf0-f195.google.com with SMTP id m88so18560134pfi.9; Mon, 27 Nov 2017 23:19:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=xxVwBCV3Q+1UYkdjI7iuVrOWGDrKX7Gdy+/FpNTDiKM=; b=IQ0O0ZusBdfDFktIOf2GkK80jbrl6lrG+Fq66v4/rr7yuCBvTnmNp5QkZiGVjzy9DW JCHB/l4UgeFXDKhTMOout4zaSPMWIWgsLI9A9qTv8uNW9WaWn3zT3BCC8HP8Q+2nS6HV f9OhSMggBBLBG0MolaZoujLdaVOZeaEAww4yFeitZLxeCndG9LhgQB7tf+DJNGr3tayF RXt2bSRHcK2M0YD0hHZI9ee/Y4LLJ0eIU+Ycg8lmuUkWBIa8eUkWeeOtY04xh0o3CfLL cO7e2dHHL1JiF15mQdVjU2PL8yDJPie3AZCd29T63PnvRfBO2rZTELUAtyhJWzFMpMuF zeYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=xxVwBCV3Q+1UYkdjI7iuVrOWGDrKX7Gdy+/FpNTDiKM=; b=dDCWetUKB6JVZ5YKbPqmu/CgmI/+rd3gYKZSrmZ2vc6lG1VNQOie8J+QuH4CUeGv4L lDYsFnx4PivzRqExXUyMSflRUUocr+GACx1v/UBjmKJiy4fRTP5R3kGrr7z9appwfcjw zu0rBCuZB+xvcDyyQUfw9vARfHbWQs9DQBIXhGSiQKv/tVVpwf37ZKl1+kzNpJDSOD5i FqL7+Nf/OW2o3A8wgxmmNX9VQUO5Xyo5x7UJRAEukswtWGs+cPjTI+/f9xEl48lmRlR9 f4WNT9TW9mu3S4jebdkL9rfJBTz/6cC/Ym+AeaYc4Fr5KHfMI8oVfP5lTBY1cA7PItiH 3hgg== X-Gm-Message-State: AJaThX7giIHxA4e2QVIhKjGTl+O5vQwrLeasyvKURIpI13/uZtf8bTnO bEOnuzJH0PqLsZuFOesK3bs= X-Received: by 10.98.60.27 with SMTP id j27mr39761890pfa.68.1511853592657; Mon, 27 Nov 2017 23:19:52 -0800 (PST) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id h6sm48692564pgn.63.2017.11.27.23.19.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Nov 2017 23:19:51 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Tue, 28 Nov 2017 17:49:43 +1030 From: Joel Stanley To: Lee Jones , Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Andrew Jeffery , Benjamin Herrenschmidt , Jeremy Kerr , Rick Altherr , Ryan Chen , Arnd Bergmann Subject: [PATCH v6 2/5] clk: aspeed: Register core clocks Date: Tue, 28 Nov 2017 17:49:05 +1030 Message-Id: <20171128071908.12279-3-joel@jms.id.au> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171128071908.12279-1-joel@jms.id.au> References: <20171128071908.12279-1-joel@jms.id.au> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This registers the core clocks; those which are required to calculate the rate of the timer peripheral so the system can load a clocksource driver. Reviewed-by: Andrew Jeffery Signed-off-by: Joel Stanley --- v5: - Add Andrew's Reviewed-by v4: - Add defines to document the BIT() macros v3: - Fix ast2400 ahb calculation - Remove incorrect 'this is wrong' comment - Separate out clkin calc to be per platform - Support 48MHz clkin on ast2400 --- drivers/clk/clk-aspeed.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) -- 2.14.1 diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c index 381be5547178..9742f1d0977f 100644 --- a/drivers/clk/clk-aspeed.c +++ b/drivers/clk/clk-aspeed.c @@ -11,7 +11,23 @@ #include +#define ASPEED_RESET_CTRL 0x04 +#define ASPEED_CLK_SELECTION 0x08 +#define ASPEED_CLK_STOP_CTRL 0x0c +#define ASPEED_MPLL_PARAM 0x20 +#define ASPEED_HPLL_PARAM 0x24 +#define AST2500_HPLL_BYPASS_EN BIT(20) +#define AST2400_HPLL_STRAPPED BIT(18) +#define AST2400_HPLL_BYPASS_EN BIT(17) +#define ASPEED_MISC_CTRL 0x2c +#define UART_DIV13_EN BIT(12) #define ASPEED_STRAP 0x70 +#define CLKIN_25MHZ_EN BIT(23) +#define AST2400_CLK_SOURCE_SEL BIT(18) +#define ASPEED_CLK_SELECTION_2 0xd8 + +/* Globally visible clocks */ +static DEFINE_SPINLOCK(aspeed_clk_lock); /* Keeps track of all clocks */ static struct clk_hw_onecell_data *aspeed_clk_data; @@ -89,6 +105,160 @@ static const struct aspeed_gate_data aspeed_gates[] = { [ASPEED_CLK_GATE_LHCCLK] = { 28, -1, "lhclk-gate", "lhclk", 0 }, /* LPC master/LPC+ */ }; +static const struct clk_div_table ast2400_div_table[] = { + { 0x0, 2 }, + { 0x1, 4 }, + { 0x2, 6 }, + { 0x3, 8 }, + { 0x4, 10 }, + { 0x5, 12 }, + { 0x6, 14 }, + { 0x7, 16 }, + { 0 } +}; + +static const struct clk_div_table ast2500_div_table[] = { + { 0x0, 4 }, + { 0x1, 8 }, + { 0x2, 12 }, + { 0x3, 16 }, + { 0x4, 20 }, + { 0x5, 24 }, + { 0x6, 28 }, + { 0x7, 32 }, + { 0 } +}; + +static struct clk_hw *aspeed_ast2400_calc_pll(const char *name, u32 val) +{ + unsigned int mult, div; + + if (val & AST2400_HPLL_BYPASS_EN) { + /* Pass through mode */ + mult = div = 1; + } else { + /* F = 24Mhz * (2-OD) * [(N + 2) / (D + 1)] */ + u32 n = (val >> 5) & 0x3f; + u32 od = (val >> 4) & 0x1; + u32 d = val & 0xf; + + mult = (2 - od) * (n + 2); + div = d + 1; + } + return clk_hw_register_fixed_factor(NULL, name, "clkin", 0, + mult, div); +}; + +static struct clk_hw *aspeed_ast2500_calc_pll(const char *name, u32 val) +{ + unsigned int mult, div; + + if (val & AST2500_HPLL_BYPASS_EN) { + /* Pass through mode */ + mult = div = 1; + } else { + /* F = clkin * [(M+1) / (N+1)] / (P + 1) */ + u32 p = (val >> 13) & 0x3f; + u32 m = (val >> 5) & 0xff; + u32 n = val & 0x1f; + + mult = (m + 1) / (n + 1); + div = p + 1; + } + + return clk_hw_register_fixed_factor(NULL, name, "clkin", 0, + mult, div); +} + +static void __init aspeed_ast2400_cc(struct regmap *map) +{ + struct clk_hw *hw; + u32 val, freq, div; + + /* + * CLKIN is the crystal oscillator, 24, 48 or 25MHz selected by + * strapping + */ + regmap_read(map, ASPEED_STRAP, &val); + if (val & CLKIN_25MHZ_EN) + freq = 25000000; + else if (val & AST2400_CLK_SOURCE_SEL) + freq = 48000000; + else + freq = 24000000; + hw = clk_hw_register_fixed_rate(NULL, "clkin", NULL, 0, freq); + pr_debug("clkin @%u MHz\n", freq / 1000000); + + /* + * High-speed PLL clock derived from the crystal. This the CPU clock, + * and we assume that it is enabled + */ + regmap_read(map, ASPEED_HPLL_PARAM, &val); + WARN(val & AST2400_HPLL_STRAPPED, "hpll is strapped not configured"); + aspeed_clk_data->hws[ASPEED_CLK_HPLL] = aspeed_ast2400_calc_pll("hpll", val); + + /* + * Strap bits 11:10 define the CPU/AHB clock frequency ratio (aka HCLK) + * 00: Select CPU:AHB = 1:1 + * 01: Select CPU:AHB = 2:1 + * 10: Select CPU:AHB = 4:1 + * 11: Select CPU:AHB = 3:1 + */ + regmap_read(map, ASPEED_STRAP, &val); + val = (val >> 10) & 0x3; + div = val + 1; + if (div == 3) + div = 4; + else if (div == 4) + div = 3; + hw = clk_hw_register_fixed_factor(NULL, "ahb", "hpll", 0, 1, div); + aspeed_clk_data->hws[ASPEED_CLK_AHB] = hw; + + /* APB clock clock selection register SCU08 (aka PCLK) */ + hw = clk_hw_register_divider_table(NULL, "apb", "hpll", 0, + scu_base + ASPEED_CLK_SELECTION, 23, 3, 0, + ast2400_div_table, + &aspeed_clk_lock); + aspeed_clk_data->hws[ASPEED_CLK_APB] = hw; +} + +static void __init aspeed_ast2500_cc(struct regmap *map) +{ + struct clk_hw *hw; + u32 val, freq, div; + + /* CLKIN is the crystal oscillator, 24 or 25MHz selected by strapping */ + regmap_read(map, ASPEED_STRAP, &val); + if (val & CLKIN_25MHZ_EN) + freq = 25000000; + else + freq = 24000000; + hw = clk_hw_register_fixed_rate(NULL, "clkin", NULL, 0, freq); + pr_debug("clkin @%u MHz\n", freq / 1000000); + + /* + * High-speed PLL clock derived from the crystal. This the CPU clock, + * and we assume that it is enabled + */ + regmap_read(map, ASPEED_HPLL_PARAM, &val); + aspeed_clk_data->hws[ASPEED_CLK_HPLL] = aspeed_ast2500_calc_pll("hpll", val); + + /* Strap bits 11:9 define the AXI/AHB clock frequency ratio (aka HCLK)*/ + regmap_read(map, ASPEED_STRAP, &val); + val = (val >> 9) & 0x7; + WARN(val == 0, "strapping is zero: cannot determine ahb clock"); + div = 2 * (val + 1); + hw = clk_hw_register_fixed_factor(NULL, "ahb", "hpll", 0, 1, div); + aspeed_clk_data->hws[ASPEED_CLK_AHB] = hw; + + /* APB clock clock selection register SCU08 (aka PCLK) */ + regmap_read(map, ASPEED_CLK_SELECTION, &val); + val = (val >> 23) & 0x7; + div = 4 * (val + 1); + hw = clk_hw_register_fixed_factor(NULL, "apb", "hpll", 0, 1, div); + aspeed_clk_data->hws[ASPEED_CLK_APB] = hw; +}; + static void __init aspeed_cc_init(struct device_node *np) { struct regmap *map; @@ -130,6 +300,13 @@ static void __init aspeed_cc_init(struct device_node *np) return; } + if (of_device_is_compatible(np, "aspeed,ast2400-scu")) + aspeed_ast2400_cc(map); + else if (of_device_is_compatible(np, "aspeed,ast2500-scu")) + aspeed_ast2500_cc(map); + else + pr_err("unknown platform, failed to add clocks\n"); + aspeed_clk_data->num = ASPEED_NUM_CLKS; ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, aspeed_clk_data); if (ret) From patchwork Tue Nov 28 07:19:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 119799 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1357923qgn; Mon, 27 Nov 2017 23:20:06 -0800 (PST) X-Google-Smtp-Source: AGs4zMYXyWzoJJkwCeSl/5vQG8Rj2C8evBb1UZyIrOGmHClx+ykL4i/TUF3Hun+n05MTmL8dgGzH X-Received: by 10.98.214.145 with SMTP id a17mr39275034pfl.167.1511853606765; Mon, 27 Nov 2017 23:20:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511853606; cv=none; d=google.com; s=arc-20160816; b=KUxm1prMfyoful4/XhRROs+1Go1dpbd2i44S2G2DCHjLg+quL0PCc0lAl+qx2OBg92 8rwv2fWzi8sy4yW0zTy+ZPJktzqiqVkQ3pcXGa+0yiUsYQEzCWUaLjJYIvoqdsrNXtG5 m5oLeuOU5Bh0Dp1CLRwIvl7i6/vNbM5yPpdY8unQN7X+9IxNdjUGuZcZPcknwBqxnV0F 2wipD4mTP4W5raUx3KBKBGHPApE4lScGHBaDMj4dJAC4G1BG29i/gOW6ddKYI9t+wwq/ 2nGm6ZhFOtX/rfIpGBUsa+dx1PLOJHOZyblGy5ZsBuLNfl0BHuBKhCOUzWQBncJOvwMC CXEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=B9hlvz4fzbr3WeUqdM2yLJvbopNzwCUYsRjxegH1NzA=; b=IEAgA3MBFrEnVfQX79GRP8cggZtlOuQFsE+55evpAk2ovn2RWASlyJJsRLkXbSkT+B r5Mbfo96/oAi2/sNq7cCXiO5vmrLm9Spl6X9gndB6+20JktccwQeLsueaNYMm6CuFTzX h1VnRBcJ9WufkD+0KUDBczLZYsBd0cYS4MIUTLUe6bXYDsM5bM20QpVPUsvgHjR22BeC cCJfDCfMsCprfLzAtv+Xddlzl9lejHuZ4EpsB4iTeF49GyUACw1MDbohr96N+yILV/EV NGiULpgY482FHtAxxyOYkuai8mz10SaohMQv75xJRUUtISQY1aTzgi+ARR3Yc91l7P/r HNig== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=RdNNVKJr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si23893167pgt.29.2017.11.27.23.20.06; Mon, 27 Nov 2017 23:20:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=RdNNVKJr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752028AbdK1HUE (ORCPT + 28 others); Tue, 28 Nov 2017 02:20:04 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:42887 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751256AbdK1HUC (ORCPT ); Tue, 28 Nov 2017 02:20:02 -0500 Received: by mail-pl0-f65.google.com with SMTP id z3so10132057plh.9; Mon, 27 Nov 2017 23:20:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=B9hlvz4fzbr3WeUqdM2yLJvbopNzwCUYsRjxegH1NzA=; b=RdNNVKJr2FBuvCPV8soSUR+e+pGVPhI25IrC4xMdZvgWlGbwZfxcbaBPueoqO+cCSt 1ihR6avUfnVWI/EZodYx7iYJvGKvSKICs6kGciRwTdFQWyYyjBxszEk1u3vEmJG6/Fmp waaEtVZIfBPymqrpyVC04dz8bEmAEOXpxE/nbqrRF5cVNF1ZOGqQt/dkyTrNI3CyDu51 eoygOX/e5MYzdd8zKO1mfjc7oFk5ZtZwGkcFlRoMljijN+/PDAbDaKCqRr13W0Fo/rkA 5PVTApAVWzbdiMnOOKDf28na+dEriDyQ9QmNaptxkbgWmAJVD9tta6vklkc+nYYEaOtc 5BWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=B9hlvz4fzbr3WeUqdM2yLJvbopNzwCUYsRjxegH1NzA=; b=ro/2fxfvfupzPKk0fo15ytocapeYhm8IhkJ/9omXf2zXX3NDegg9QZfolgs3O9jYnY /42+G3gmmqzc5Oc0q5o8YVPM50tgveDKjKpC5SRqJtzhih0vTMsh9bRkJl5z5J8vdQSj g2Loa1qOtoxJipje8OWq/Vwdr6MAAmF06wGs2+Vl/bAkm9WEOPhm6uND2SVjjKEG7Sow /CBtTfQHkNjaZkOGwb4OREjUk42rf+R7R2mhBhQYkNFoXcKb7Tf6yz0FjyFmYQEWbdaX To3gs6spx8QJyg/T2sRTpv2OnkdWZg7MbhY7FGwSpWw+9NN0xJYx/Ld9uElLcJKc+D20 W5dg== X-Gm-Message-State: AJaThX7+MWNlFkZq+z0EZInn4li2TxGHcEjueNcPY82WooEUGS0Ck/+G vvO8QfoxCJuypzf+Pp5O2M4qxfo27kU= X-Received: by 10.84.174.129 with SMTP id r1mr42338134plb.337.1511853602109; Mon, 27 Nov 2017 23:20:02 -0800 (PST) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id b10sm49348923pfj.20.2017.11.27.23.19.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Nov 2017 23:20:00 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Tue, 28 Nov 2017 17:49:53 +1030 From: Joel Stanley To: Lee Jones , Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Andrew Jeffery , Benjamin Herrenschmidt , Jeremy Kerr , Rick Altherr , Ryan Chen , Arnd Bergmann Subject: [PATCH v6 3/5] clk: aspeed: Add platform driver and register PLLs Date: Tue, 28 Nov 2017 17:49:06 +1030 Message-Id: <20171128071908.12279-4-joel@jms.id.au> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171128071908.12279-1-joel@jms.id.au> References: <20171128071908.12279-1-joel@jms.id.au> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This registers a platform driver to set up all of the non-core clocks. The clocks that have configurable rates are now registered. Reviewed-by: Andrew Jeffery Signed-off-by: Joel Stanley -- v6: - Add Andrew's reviewed-by v5: - Remove eclk configuration. We do not have enough information to correctly implement the mux and divisor, so it will have to be implemented in the future v4: - Add eclk div table to fix ast2500 calculation - Add defines to document the BIT() macros - Pass dev where we can when registering clocks - Check for errors when registering clk_hws v3: - Fix bclk and eclk calculation - Separate out ast2400 and ast25000 for pll calculation --- drivers/clk/clk-aspeed.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) -- 2.14.1 diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c index 9742f1d0977f..839243691b26 100644 --- a/drivers/clk/clk-aspeed.c +++ b/drivers/clk/clk-aspeed.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include #include @@ -105,6 +107,18 @@ static const struct aspeed_gate_data aspeed_gates[] = { [ASPEED_CLK_GATE_LHCCLK] = { 28, -1, "lhclk-gate", "lhclk", 0 }, /* LPC master/LPC+ */ }; +static const struct clk_div_table ast2500_mac_div_table[] = { + { 0x0, 4 }, /* Yep, really. Aspeed confirmed this is correct */ + { 0x1, 4 }, + { 0x2, 6 }, + { 0x3, 8 }, + { 0x4, 10 }, + { 0x5, 12 }, + { 0x6, 14 }, + { 0x7, 16 }, + { 0 } +}; + static const struct clk_div_table ast2400_div_table[] = { { 0x0, 2 }, { 0x1, 4 }, @@ -170,6 +184,122 @@ static struct clk_hw *aspeed_ast2500_calc_pll(const char *name, u32 val) mult, div); } +struct aspeed_clk_soc_data { + const struct clk_div_table *div_table; + const struct clk_div_table *mac_div_table; + struct clk_hw *(*calc_pll)(const char *name, u32 val); +}; + +static const struct aspeed_clk_soc_data ast2500_data = { + .div_table = ast2500_div_table, + .mac_div_table = ast2500_mac_div_table, + .calc_pll = aspeed_ast2500_calc_pll, +}; + +static const struct aspeed_clk_soc_data ast2400_data = { + .div_table = ast2400_div_table, + .mac_div_table = ast2400_div_table, + .calc_pll = aspeed_ast2400_calc_pll, +}; + +static int aspeed_clk_probe(struct platform_device *pdev) +{ + const struct aspeed_clk_soc_data *soc_data; + struct device *dev = &pdev->dev; + struct regmap *map; + struct clk_hw *hw; + u32 val, rate; + + map = syscon_node_to_regmap(dev->of_node); + if (IS_ERR(map)) { + dev_err(dev, "no syscon regmap\n"); + return PTR_ERR(map); + } + + /* SoC generations share common layouts but have different divisors */ + soc_data = of_device_get_match_data(dev); + if (!soc_data) { + dev_err(dev, "no match data for platform\n"); + return -EINVAL; + } + + /* UART clock div13 setting */ + regmap_read(map, ASPEED_MISC_CTRL, &val); + if (val & UART_DIV13_EN) + rate = 24000000 / 13; + else + rate = 24000000; + /* TODO: Find the parent data for the uart clock */ + hw = clk_hw_register_fixed_rate(dev, "uart", NULL, 0, rate); + if (IS_ERR(hw)) + return PTR_ERR(hw); + aspeed_clk_data->hws[ASPEED_CLK_UART] = hw; + + /* + * Memory controller (M-PLL) PLL. This clock is configured by the + * bootloader, and is exposed to Linux as a read-only clock rate. + */ + regmap_read(map, ASPEED_MPLL_PARAM, &val); + hw = soc_data->calc_pll("mpll", val); + if (IS_ERR(hw)) + return PTR_ERR(hw); + aspeed_clk_data->hws[ASPEED_CLK_MPLL] = hw; + + /* SD/SDIO clock divider (TODO: There's a gate too) */ + hw = clk_hw_register_divider_table(dev, "sdio", "hpll", 0, + scu_base + ASPEED_CLK_SELECTION, 12, 3, 0, + soc_data->div_table, + &aspeed_clk_lock); + if (IS_ERR(hw)) + return PTR_ERR(hw); + aspeed_clk_data->hws[ASPEED_CLK_SDIO] = hw; + + /* MAC AHB bus clock divider */ + hw = clk_hw_register_divider_table(dev, "mac", "hpll", 0, + scu_base + ASPEED_CLK_SELECTION, 16, 3, 0, + soc_data->mac_div_table, + &aspeed_clk_lock); + if (IS_ERR(hw)) + return PTR_ERR(hw); + aspeed_clk_data->hws[ASPEED_CLK_MAC] = hw; + + /* LPC Host (LHCLK) clock divider */ + hw = clk_hw_register_divider_table(dev, "lhclk", "hpll", 0, + scu_base + ASPEED_CLK_SELECTION, 20, 3, 0, + soc_data->div_table, + &aspeed_clk_lock); + if (IS_ERR(hw)) + return PTR_ERR(hw); + aspeed_clk_data->hws[ASPEED_CLK_LHCLK] = hw; + + /* P-Bus (BCLK) clock divider */ + hw = clk_hw_register_divider_table(dev, "bclk", "hpll", 0, + scu_base + ASPEED_CLK_SELECTION_2, 0, 2, 0, + soc_data->div_table, + &aspeed_clk_lock); + if (IS_ERR(hw)) + return PTR_ERR(hw); + aspeed_clk_data->hws[ASPEED_CLK_BCLK] = hw; + + return 0; +}; + +static const struct of_device_id aspeed_clk_dt_ids[] = { + { .compatible = "aspeed,ast2400-scu", .data = &ast2400_data }, + { .compatible = "aspeed,ast2500-scu", .data = &ast2500_data }, + { } +}; + +static struct platform_driver aspeed_clk_driver = { + .probe = aspeed_clk_probe, + .driver = { + .name = "aspeed-clk", + .of_match_table = aspeed_clk_dt_ids, + .suppress_bind_attrs = true, + }, +}; +builtin_platform_driver(aspeed_clk_driver); + static void __init aspeed_ast2400_cc(struct regmap *map) { struct clk_hw *hw; From patchwork Tue Nov 28 07:19:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 119800 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1358049qgn; Mon, 27 Nov 2017 23:20:16 -0800 (PST) X-Google-Smtp-Source: AGs4zMbtsQ4RPAGpPHIj/69auVdoe6A5ve0FpRj8tvtKVS7aLNYGLcOMwmeqx9dtYFpHhTu7NfWN X-Received: by 10.84.129.70 with SMTP id 64mr41522924plb.444.1511853616232; Mon, 27 Nov 2017 23:20:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511853616; cv=none; d=google.com; s=arc-20160816; b=TlxPuRRtoXSoNOPiGZnMvSRJ7ZeXIuCXCzSms/c2SgrzS0ge85ScSiEvZO/feO1aXm 7FmlnJHvKh012QLUReCSlH6thAIP0nyTAXC9BAdQ+RD+m9uYYLpAO1sSq0TP4ptdbw+9 DDoD6xtUxQgbn5CndoDcCKvNecCUwpfWe/fuB4/gJliOoqF6Hg3dEt4PGdPsyNuA7Zmj 8JDGKWLUxzsZl0mXvt/EsXrLNN8UmDxPe7EmsgKxyQ9Z2MwhqfGbFHl0fk8VrlM4UQik fKiYlq1ueJ+zm8M5+NNBBCQ0YEJKjj+cFBZaVeNvZ1JzAEthzF6LG2xhuEuY5O/9Ghsb 8iPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=A23Czos41//RZcbvNo1A4RY3+7Kf1myy5v3/nSvq9w0=; b=lF9rYJxQbEcwACsvihUW+zEb0xEKNDS4Qb3/JcVKr+m5tsMXsudBwbqy9KckHfh8AE OANT0NDZnLWEm5OesGeRoH56E8f2V9epAxCq1fHBTorsgXpVlvkHwoW69HqIxiOuPaBx EShduCOp1SZzbHGZ+dzq//T9K//ygptHxDdNLETFe7mzA4HI8Ztk0xN4/ngK9bFKNc1l 4NyqqKY/vnGlTPrqrEUp4vTsFcwWeZkN99jiObpG52DgiW8RdYgzjWvnf+SZxBrdG9ar Hkb7eJJd+pM79T/WgiRTK0ldKGN2/aBpk9KthBiLrxzwWUgnB0R8zzJM+0gnAjL5Pe+r UpKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tNaS9Gly; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si23893167pgt.29.2017.11.27.23.20.15; Mon, 27 Nov 2017 23:20:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tNaS9Gly; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752057AbdK1HUP (ORCPT + 28 others); Tue, 28 Nov 2017 02:20:15 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36285 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751256AbdK1HUM (ORCPT ); Tue, 28 Nov 2017 02:20:12 -0500 Received: by mail-pg0-f67.google.com with SMTP id 199so8259148pgg.3; Mon, 27 Nov 2017 23:20:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=A23Czos41//RZcbvNo1A4RY3+7Kf1myy5v3/nSvq9w0=; b=tNaS9GlygH4AKb28rUqDmQO4M95EGfWnajz5uas58N7wKCJaKlDQuJJ2j1IZinTq4r 2lryagRxQeUmpa04rz+A4puGQIQJCJvq1ynQIZVYOqy9FPBAnHML+cEpfS1u9ebnRMIB 8PM36+YJX9r5oSi3ltyBn9N38Y6iuWNQWZzAzg9ff1LAPOSij5T6nTg72CtZ3FAo1vRp uhErpj1xZBYjKKsD82rXTVljR4UI0EQ9nsk4wwF8NPxe/2xI7JLxYeoK0jSxPn/s6a14 8YkyfCK7jnvAJaHiyLCwMJuAYNQ+z4e2JIKDwWTxkD260LRJzbESw5/Xcd1Hjzbz2UgL yoIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=A23Czos41//RZcbvNo1A4RY3+7Kf1myy5v3/nSvq9w0=; b=oqrfIEXzYsvarcVueIWPviiQKzudEMpyLVD07W7JVk7hWdR4Ji2w8IF+LEwD+9+NH7 Kdd8Iq0bGfGvM0LyYjPuWuKAMJ5GjpT3tetb4kMqKV4oXQDudFTHtZdP6xS4j8VLLjD8 EynWNx1KoDcbLrvc9ar7DSgsI2Lewa4B+qd7ngQQ7KyqbLq49eh8Fw6p5FqKCT5MDP8t JR/TvSEX3oIAwOXPuFg9vjASl+1WVurALdFpBTR62KKszMyGFknYwgEDWd9RZBy0jdIY 9MzgPoE8N4AfrQLPg6Ihf+sT4bUx5wgH9ykgEL1bpBrtVsm6XtK+41rlBtg4d0VSb2Os +c9w== X-Gm-Message-State: AJaThX5hb8iLdplLjzSBUT1jWTnQWmWOKtEhJ0ubKjtZIvDM1O1fSyTx 8rF5lg9vsW8nle9DddAom70= X-Received: by 10.99.160.100 with SMTP id u36mr39728443pgn.22.1511853611901; Mon, 27 Nov 2017 23:20:11 -0800 (PST) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id t62sm27116021pgt.23.2017.11.27.23.20.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Nov 2017 23:20:10 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Tue, 28 Nov 2017 17:50:02 +1030 From: Joel Stanley To: Lee Jones , Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Andrew Jeffery , Benjamin Herrenschmidt , Jeremy Kerr , Rick Altherr , Ryan Chen , Arnd Bergmann Subject: [PATCH v6 4/5] clk: aspeed: Register gated clocks Date: Tue, 28 Nov 2017 17:49:07 +1030 Message-Id: <20171128071908.12279-5-joel@jms.id.au> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171128071908.12279-1-joel@jms.id.au> References: <20171128071908.12279-1-joel@jms.id.au> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The majority of the clocks in the system are gates paired with a reset controller that holds the IP in reset. This borrows from clk_hw_register_gate, but registers two 'gates', one to control the clock enable register and the other to control the reset IP. This allows us to enforce the ordering: 1. Place IP in reset 2. Enable clock 3. Delay 4. Release reset There are some gates that do not have an associated reset; these are handled by using -1 as the index for the reset. Reviewed-by: Andrew Jeffery Signed-off-by: Joel Stanley --- v5: - Add Andrew's Reviewed-by v4: - Drop useless 'disable clock' comment - Drop CLK_IS_BASIC flag - Fix 'there are a number of clocks...' comment - Pass device to clk registration functions - Check for errors when registering clk_hws v3: - Remove gates offset as gates are now at the start of the list --- drivers/clk/clk-aspeed.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) -- 2.14.1 diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c index 839243691b26..b5dc3e298693 100644 --- a/drivers/clk/clk-aspeed.c +++ b/drivers/clk/clk-aspeed.c @@ -202,6 +202,107 @@ static const struct aspeed_clk_soc_data ast2400_data = { .calc_pll = aspeed_ast2400_calc_pll, }; +static int aspeed_clk_enable(struct clk_hw *hw) +{ + struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw); + unsigned long flags; + u32 clk = BIT(gate->clock_idx); + u32 rst = BIT(gate->reset_idx); + + spin_lock_irqsave(gate->lock, flags); + + if (gate->reset_idx >= 0) { + /* Put IP in reset */ + regmap_update_bits(gate->map, ASPEED_RESET_CTRL, rst, rst); + + /* Delay 100us */ + udelay(100); + } + + /* Enable clock */ + regmap_update_bits(gate->map, ASPEED_CLK_STOP_CTRL, clk, 0); + + if (gate->reset_idx >= 0) { + /* Delay 10ms */ + /* TODO: can we sleep here? */ + msleep(10); + + /* Take IP out of reset */ + regmap_update_bits(gate->map, ASPEED_RESET_CTRL, rst, 0); + } + + spin_unlock_irqrestore(gate->lock, flags); + + return 0; +} + +static void aspeed_clk_disable(struct clk_hw *hw) +{ + struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw); + unsigned long flags; + u32 clk = BIT(gate->clock_idx); + + spin_lock_irqsave(gate->lock, flags); + + regmap_update_bits(gate->map, ASPEED_CLK_STOP_CTRL, clk, clk); + + spin_unlock_irqrestore(gate->lock, flags); +} + +static int aspeed_clk_is_enabled(struct clk_hw *hw) +{ + struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw); + u32 clk = BIT(gate->clock_idx); + u32 reg; + + regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, ®); + + return (reg & clk) ? 0 : 1; +} + +static const struct clk_ops aspeed_clk_gate_ops = { + .enable = aspeed_clk_enable, + .disable = aspeed_clk_disable, + .is_enabled = aspeed_clk_is_enabled, +}; + +static struct clk_hw *aspeed_clk_hw_register_gate(struct device *dev, + const char *name, const char *parent_name, unsigned long flags, + struct regmap *map, u8 clock_idx, u8 reset_idx, + u8 clk_gate_flags, spinlock_t *lock) +{ + struct aspeed_clk_gate *gate; + struct clk_init_data init; + struct clk_hw *hw; + int ret; + + gate = kzalloc(sizeof(*gate), GFP_KERNEL); + if (!gate) + return ERR_PTR(-ENOMEM); + + init.name = name; + init.ops = &aspeed_clk_gate_ops; + init.flags = flags; + init.parent_names = parent_name ? &parent_name : NULL; + init.num_parents = parent_name ? 1 : 0; + + gate->map = map; + gate->clock_idx = clock_idx; + gate->reset_idx = reset_idx; + gate->flags = clk_gate_flags; + gate->lock = lock; + gate->hw.init = &init; + + hw = &gate->hw; + ret = clk_hw_register(dev, hw); + if (ret) { + kfree(gate); + hw = ERR_PTR(ret); + } + + return hw; +} + static int aspeed_clk_probe(struct platform_device *pdev) { const struct aspeed_clk_soc_data *soc_data; @@ -209,6 +310,7 @@ static int aspeed_clk_probe(struct platform_device *pdev) struct regmap *map; struct clk_hw *hw; u32 val, rate; + int i; map = syscon_node_to_regmap(dev->of_node); if (IS_ERR(map)) { @@ -281,6 +383,35 @@ static int aspeed_clk_probe(struct platform_device *pdev) return PTR_ERR(hw); aspeed_clk_data->hws[ASPEED_CLK_BCLK] = hw; + /* + * TODO: There are a number of clocks that not included in this driver + * as more information is required: + * D2-PLL + * D-PLL + * YCLK + * RGMII + * RMII + * UART[1..5] clock source mux + * Video Engine (ECLK) mux and clock divider + */ + + for (i = 0; i < ARRAY_SIZE(aspeed_gates); i++) { + const struct aspeed_gate_data *gd = &aspeed_gates[i]; + + hw = aspeed_clk_hw_register_gate(dev, + gd->name, + gd->parent_name, + gd->flags, + map, + gd->clock_idx, + gd->reset_idx, + CLK_GATE_SET_TO_DISABLE, + &aspeed_clk_lock); + if (IS_ERR(hw)) + return PTR_ERR(hw); + aspeed_clk_data->hws[i] = hw; + } + return 0; }; From patchwork Tue Nov 28 07:19:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 119801 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1358198qgn; Mon, 27 Nov 2017 23:20:26 -0800 (PST) X-Google-Smtp-Source: AGs4zMbeiztV9V7GVyaanUDIubMFrT3Pys0m48ZaOR7qprVNCNp8Wd9a43hjO+1x6kjcLxYxyiS2 X-Received: by 10.98.216.193 with SMTP id e184mr38990001pfg.98.1511853626442; Mon, 27 Nov 2017 23:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511853626; cv=none; d=google.com; s=arc-20160816; b=B4uC90SsKP3RSOfm613O520n0X9uFlgltyXqhUen0laFVg2qTef+cHravmRO9DYCQJ gSOf8ct8YfDZl7rCScV2bwV0jM5v5EbGg2UWFgvlkDL/60dDgw5aGp4MwzHQE3/fd8y6 7fpBNrVZRDEtBD8q0isBKEUqCqNnvU9P4v0vuSlDya5ZFQYecGAyzHJBDvfbedjowVQD pFFDYqR00cpP/gNtppwkg02ttzpdtiLITgLwV60S9a6Gd4lia3ZPKjtPD4yRwfiiOJJp 4Kf8jaovtHXDq/lCn5Wys5ievYjV26/xkqZe1Os4jx4Q30Tvc/sA3DiRNDiYZRLVqx6K z26g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=JhFBI1MPf+an05XEAQYvCgTn9As8sDHyGSLy5fYlbm0=; b=qYI0GYbuirNWtlzBd84JhLrDNRgjpEWjHG6OZJxr8Bemj5sQ5rnb0uvvcl1aZL7Zcp Dfbw/Vp1EYIYuT/5Tp/WT6qGEX97Yy8nisiWTWFG0jP1xWHUrnXZyD/1hI6T9HcwihrM EElAzjfIBbj2xdZyO1sc75PRTtVVkgAwLjuhsT2Wt6GT2u3Cayb5Nz1M8AxCfL0t2RIv qDdUwOTwc8srrCgqymWyDmaMGUO+8AHS9GDOR++P0anY9EGo2A5s/dZcLW2vtNC3Vejs BuxElEIQnwGOZSKcn/TREANUKlNgMYekNunkJXSn01ASMy4WCYrYLffWnhPyNrOVu79n rVTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=WdCk+3ho; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si23893167pgt.29.2017.11.27.23.20.26; Mon, 27 Nov 2017 23:20:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=WdCk+3ho; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752093AbdK1HUY (ORCPT + 28 others); Tue, 28 Nov 2017 02:20:24 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:34458 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751690AbdK1HUW (ORCPT ); Tue, 28 Nov 2017 02:20:22 -0500 Received: by mail-pl0-f65.google.com with SMTP id o17so10139805pli.1; Mon, 27 Nov 2017 23:20:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=JhFBI1MPf+an05XEAQYvCgTn9As8sDHyGSLy5fYlbm0=; b=WdCk+3hoBaYzhpnkHjvka3Irr3bQzWYUL4As9CO3PYs+uOv9uUXNQURAXZHjD0KsFz vCKOnwP+wGMyZZUGSMBm8h7BSu3Fw59FI5WlhwYBTJmNCV3EnrtrORb9401PvJ37dIAq ENGKEWKCCqVxqpuAedNY+4/s9fzHIDoQcazelLxVkSYHu3Bj+odvB1lOP1yoWNgB0+it W3ZFz6YHJ/a3z2fayYJNRr+M+Sjjlleb22h/ux1/MkUyU1AV+E0eM321Jx84Vtu2lNdS WFEX7mSLC8RbLgMc8ilGJqVJx/DAUVr9pUQT03lK0NoPj7pmKZineCeNsZDnTQO8Veb0 FhxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=JhFBI1MPf+an05XEAQYvCgTn9As8sDHyGSLy5fYlbm0=; b=KrYPE9aGa9ZZbLuLPxRiXmjWtYbjAQ2UiocrCi0lkEgix+lgludtyI8CHJjrSs5q/+ WL5RI0idCXYlh1bzR4Ck/kKsPhek3s8Q1jvbfOT9616HEP5jTmvWdWE7LajrtZawmOmo ECvO0y7t0VnAD4w9mTu3kvqy0RIWmO73wvfXMuxATMb9a0rUWCC7l1C6zZ6/6n/YrPQQ P3VhUbKw9PvATpCD+ph57GAWecGOXWfm+7i9SfthkO5gxJeq1gATNEFhyb2Apm2AibFr V0W4TcrCSATL+FcmKkBYbFSmiWO4I6bHjj/q8t4d03B4ZIiiPwfEQ4bOTsbJdtBiMf6J b8cw== X-Gm-Message-State: AJaThX5t3QvtpzeqalxOTSpW4f2OAa4cstx2KknTRqeDG69glfjy8m3E UMfIzBAd04NYQGh4FBMEkrg= X-Received: by 10.84.141.164 with SMTP id 33mr19826659plv.100.1511853622130; Mon, 27 Nov 2017 23:20:22 -0800 (PST) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id g127sm41606029pgc.29.2017.11.27.23.20.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Nov 2017 23:20:20 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Tue, 28 Nov 2017 17:50:12 +1030 From: Joel Stanley To: Lee Jones , Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Andrew Jeffery , Benjamin Herrenschmidt , Jeremy Kerr , Rick Altherr , Ryan Chen , Arnd Bergmann Subject: [PATCH v6 5/5] clk: aspeed: Add reset controller Date: Tue, 28 Nov 2017 17:49:08 +1030 Message-Id: <20171128071908.12279-6-joel@jms.id.au> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171128071908.12279-1-joel@jms.id.au> References: <20171128071908.12279-1-joel@jms.id.au> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are some resets that are not associated with gates. These are represented by a reset controller. Reviewed-by: Andrew Jeffery Signed-off-by: Joel Stanley --- v5: - Add Andrew's Reviewed-by v3: - Add named initalisers for the reset defines - Add define for ADC --- drivers/clk/clk-aspeed.c | 82 +++++++++++++++++++++++++++++++- include/dt-bindings/clock/aspeed-clock.h | 10 ++++ 2 files changed, 91 insertions(+), 1 deletion(-) -- 2.14.1 diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c index b5dc3e298693..f2722be17ede 100644 --- a/drivers/clk/clk-aspeed.c +++ b/drivers/clk/clk-aspeed.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -266,6 +267,68 @@ static const struct clk_ops aspeed_clk_gate_ops = { .is_enabled = aspeed_clk_is_enabled, }; +/** + * struct aspeed_reset - Aspeed reset controller + * @map: regmap to access the containing system controller + * @rcdev: reset controller device + */ +struct aspeed_reset { + struct regmap *map; + struct reset_controller_dev rcdev; +}; + +#define to_aspeed_reset(p) container_of((p), struct aspeed_reset, rcdev) + +static const u8 aspeed_resets[] = { + [ASPEED_RESET_XDMA] = 25, + [ASPEED_RESET_MCTP] = 24, + [ASPEED_RESET_ADC] = 23, + [ASPEED_RESET_JTAG_MASTER] = 22, + [ASPEED_RESET_MIC] = 18, + [ASPEED_RESET_PWM] = 9, + [ASPEED_RESET_PCIVGA] = 8, + [ASPEED_RESET_I2C] = 2, + [ASPEED_RESET_AHB] = 1, +}; + +static int aspeed_reset_deassert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct aspeed_reset *ar = to_aspeed_reset(rcdev); + u32 rst = BIT(aspeed_resets[id]); + + return regmap_update_bits(ar->map, ASPEED_RESET_CTRL, rst, 0); +} + +static int aspeed_reset_assert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct aspeed_reset *ar = to_aspeed_reset(rcdev); + u32 rst = BIT(aspeed_resets[id]); + + return regmap_update_bits(ar->map, ASPEED_RESET_CTRL, rst, rst); +} + +static int aspeed_reset_status(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct aspeed_reset *ar = to_aspeed_reset(rcdev); + u32 val, rst = BIT(aspeed_resets[id]); + int ret; + + ret = regmap_read(ar->map, ASPEED_RESET_CTRL, &val); + if (ret) + return ret; + + return !!(val & rst); +} + +static const struct reset_control_ops aspeed_reset_ops = { + .assert = aspeed_reset_assert, + .deassert = aspeed_reset_deassert, + .status = aspeed_reset_status, +}; + static struct clk_hw *aspeed_clk_hw_register_gate(struct device *dev, const char *name, const char *parent_name, unsigned long flags, struct regmap *map, u8 clock_idx, u8 reset_idx, @@ -307,10 +370,11 @@ static int aspeed_clk_probe(struct platform_device *pdev) { const struct aspeed_clk_soc_data *soc_data; struct device *dev = &pdev->dev; + struct aspeed_reset *ar; struct regmap *map; struct clk_hw *hw; u32 val, rate; - int i; + int i, ret; map = syscon_node_to_regmap(dev->of_node); if (IS_ERR(map)) { @@ -318,6 +382,22 @@ static int aspeed_clk_probe(struct platform_device *pdev) return PTR_ERR(map); } + ar = devm_kzalloc(dev, sizeof(*ar), GFP_KERNEL); + if (!ar) + return -ENOMEM; + + ar->map = map; + ar->rcdev.owner = THIS_MODULE; + ar->rcdev.nr_resets = ARRAY_SIZE(aspeed_resets); + ar->rcdev.ops = &aspeed_reset_ops; + ar->rcdev.of_node = dev->of_node; + + ret = devm_reset_controller_register(dev, &ar->rcdev); + if (ret) { + dev_err(dev, "could not register reset controller\n"); + return ret; + } + /* SoC generations share common layouts but have different divisors */ soc_data = of_device_get_match_data(dev); if (!soc_data) { diff --git a/include/dt-bindings/clock/aspeed-clock.h b/include/dt-bindings/clock/aspeed-clock.h index 9e170fb9a0da..fe46ab69da5c 100644 --- a/include/dt-bindings/clock/aspeed-clock.h +++ b/include/dt-bindings/clock/aspeed-clock.h @@ -41,4 +41,14 @@ #define ASPEED_NUM_CLKS 35 +#define ASPEED_RESET_XDMA 0 +#define ASPEED_RESET_MCTP 1 +#define ASPEED_RESET_ADC 2 +#define ASPEED_RESET_JTAG_MASTER 3 +#define ASPEED_RESET_MIC 4 +#define ASPEED_RESET_PWM 5 +#define ASPEED_RESET_PCIVGA 6 +#define ASPEED_RESET_I2C 7 +#define ASPEED_RESET_AHB 8 + #endif