From patchwork Fri Dec 22 02:45:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 122621 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1689102qgn; Thu, 21 Dec 2017 18:46:18 -0800 (PST) X-Google-Smtp-Source: ACJfBovPkTKVWOyGL1oQaWLcIu5nDXR+kib9lArOGNy9w4E8SrZrY0bD3J0P1XJub1DczKdtAUPx X-Received: by 10.99.176.69 with SMTP id z5mr11745713pgo.131.1513910777938; Thu, 21 Dec 2017 18:46:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513910777; cv=none; d=google.com; s=arc-20160816; b=p+xfLPwrvN9WgUfz5oIAE1GzWM+qB27M3STjFAtJ8Qy2NIesuE8Lv3qeuVjtYigmxr 8mviS5cggsT4F4sBWt3J7ZwVYLPPEYP54xVH+2pVsX3xryTg4zQcIFq4UnZxnYq4sMjp NB4wFVoHhz4x4mduMuoWFCrMReA3Gyul5AH6X/9axMDjxuXAlMAqTxtjL2YY4QTvPdaK P7413jvd0Ti1mpxTmoz8Dsl5hOaFaAGne7LKJkhRSv0jBUV9s1hhFQVjmfRR+UhIQO/W GHt1U6SRxWH0oxzvrPK64vjx/bykDDgZZmS4B5psMSvzKNVEO8YaCMaHoRKfYgIdg8Tw YrjQ== 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=ikq1O6sKIQWceAZ3BytSz0CjURSvlBviz43X3na9U/k=; b=A0NH7RQjIEHxwPO8hh5hLj7nk/1swOMkbyiDeza8bCRzQzlSxwf3Y9CySdl34SGCgs gy8u06mnPGJn00NQIrZ+yw1xYHfT1TImiUVfu6ikiXRu3emOgfB8yHPOOfau9JZFwtm2 0YW0IPhm1TXSNyRQsDwLJq/aZfdXPzqpYz3s5nElnZ0lLQcldc2T+rdHlBC2ZIGhhSxs B+SzNzVyT71VKTmVInuX+pDFNmseci2vMEpo/+moOrEV9Ey/k6kb4y9tExs30o2H6Ejr xTgK7HiyCjRH98ZoUStG//TRVmsIv/7UScLh35vR4EUYpmf22CXvs3Q/Ml4lRxAiMN3Y BYBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Wa9hb74S; 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 f21si16353230plr.757.2017.12.21.18.46.17; Thu, 21 Dec 2017 18:46:17 -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=Wa9hb74S; 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 S1755994AbdLVCqB (ORCPT + 28 others); Thu, 21 Dec 2017 21:46:01 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:46590 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755891AbdLVCps (ORCPT ); Thu, 21 Dec 2017 21:45:48 -0500 Received: by mail-pf0-f195.google.com with SMTP id c204so14759920pfc.13; Thu, 21 Dec 2017 18:45:48 -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=ikq1O6sKIQWceAZ3BytSz0CjURSvlBviz43X3na9U/k=; b=Wa9hb74SJV/6VXjnlgkkuRXo62LeqFA/DNRZLkosXtGU9uiea0yDZj6IwZay/40nEf XCM6DnyeikB14uQaH6Zt7jCLLquoVtvL19YGDyEUa78QKDFpdwJ/fzDKG6q5F02Q/Q7K DW8wfknH1wEMAv47m3wKIBUK5mo1n0YEMIuZUtvHA7EmIO5iXwZ3iofSzCCwrKhhgOEV P9g+T5N72BdXTgx2D2cbjzI0ZyKigGrVZrq4WE+uRBa5rYUe/RFz6okhsFjTDO6alcHh vxpUVNN0Bnu67X5rGLxFXfW7kYISjrWbdd7tcv+XMEbjN3thwNnSlFcPXM7IP3R8TSl0 ukaw== 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=ikq1O6sKIQWceAZ3BytSz0CjURSvlBviz43X3na9U/k=; b=ophPVAT6QdCAIfo6mOyXRf+jXeyfq1ZOjwMMMK0pjbrwhtd9paSTFMw9o1PXik+JWG bYvgbYHvJgjHxcWxPZPeN0NusewHZ7e/LRApL3spx8b+8my0vBTu6ojo/lQnQRA2csFD AUK7SDfklA0dJMnGQ03BuUS0DJ+UcjrZPVZATP4sFhkFt/TGD4s+zuF2xi8tytNrSN9/ LUy57DwR4MLGsywcpygwMBvArr1WsoebISk9+/8ryrRDJPY5TGyR9OivuzEIzIcu4SmP I2ueEoFbPOcetRCdTmvZa20GOso0lyblTzCeAg404Lc3kvknVuU+a2DkD2bTMXCJA3Oy HJig== X-Gm-Message-State: AKGB3mLMO3xLMX49AgTrtjTMo3OUIB7YWQelQyB4oAZHiQLP48yqTNNs 5asookww8Q3x8hHwhTOx1Kg= X-Received: by 10.99.125.27 with SMTP id y27mr9063646pgc.233.1513910747581; Thu, 21 Dec 2017 18:45:47 -0800 (PST) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id u67sm42107501pfd.162.2017.12.21.18.45.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Dec 2017 18:45:46 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Fri, 22 Dec 2017 13:15:38 +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 v7 1/5] clk: Add clock driver for ASPEED BMC SoCs Date: Fri, 22 Dec 2017 13:15:18 +1030 Message-Id: <20171222024522.10362-2-joel@jms.id.au> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171222024522.10362-1-joel@jms.id.au> References: <20171222024522.10362-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 --- v7: - Rebase on dt-bindings patch - Add ASPEED_NUM_CLKS as it no longer lives in the header 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 | 141 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 drivers/clk/clk-aspeed.c -- 2.15.1 Reviewed-by: Benjamin Herrenschmidt 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..7a86ee08ea4f --- /dev/null +++ b/drivers/clk/clk-aspeed.c @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#define pr_fmt(fmt) "clk-aspeed: " fmt + +#include +#include +#include +#include +#include +#include + +#include + +#define ASPEED_NUM_CLKS 35 + +#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); From patchwork Fri Dec 22 02:45:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 122622 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1689113qgn; Thu, 21 Dec 2017 18:46:19 -0800 (PST) X-Google-Smtp-Source: ACJfBouSE7ZJnRIF7D/8CO/LmyUstLtPEG9LcOTTNSAcXBsT+dDiJdhdVGTnkpNI+h/Lip22jt6l X-Received: by 10.98.237.14 with SMTP id u14mr3647749pfh.170.1513910778938; Thu, 21 Dec 2017 18:46:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513910778; cv=none; d=google.com; s=arc-20160816; b=eZ/P4oWDiplBma9eIc2LW7RqaNhYUXU9SOXgQCBgo3WuRn9YVrdgaYX64Zg0ho99DA rHblNn28/PURtIBQbFt8gqC3h8xwXnp/+PKk+xEJg93lu2gizI1HrZ88Sl+lamOySgHu Hp0B4v9CcLgmLuQk4dxH9gPqy94oxtbkucbLXepYkqVpK+LPGK2WgHU/gp4cS4Bkc+kt jgK05AAE1YMzOq41A7Rq/2L9ITQtsfM3+IUUDwh9dc6ohLzAa5fAcGftcHiaWwDiD/F/ meAD79GvHyPTZWrg77QveuCNaW7Bof9cuNgqYOTuLLOA2l2bOt+TupUR6eqRwqhW9ZI9 hXjw== 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=FGMhEOawsy0F5FE8CmY4BuECgE2lwdwdJn74QnIQPZk=; b=JGmajOBAOPWtVmqUVUMLuSov2hjAO7yxjTQhy+NZ6t3AS9TL5GIzyo8qRreVEkpkzh fxK5yv7jy9qLeT0HLXJSb+GIgv4JeoJooLkY8+Xgu+/LFxRgNr9IIwr+Vc66tGLf8zYv IpQ1qliqdYB/ICRUXyaJkrwkEc4qgP5Uo0V5pgHnGAYWSAAc9OCAhlAhYbQPocooH5tL G/UZELlQABioVspKE62tePEDel+JV/WC1l4sSpVbRlBvAgR0CHRK9/KciA6/MmqWsyjr WBHnpjwovotm+f7QhYy9d8IpVgxyLH0oxk7yVU6mw0SCDxtILWj5T1nGob7vMJbpO2vS 8M3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=pNq7Eo8l; 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 f21si16353230plr.757.2017.12.21.18.46.18; Thu, 21 Dec 2017 18:46:18 -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=pNq7Eo8l; 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 S1756046AbdLVCqG (ORCPT + 28 others); Thu, 21 Dec 2017 21:46:06 -0500 Received: from mail-pl0-f66.google.com ([209.85.160.66]:44807 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755893AbdLVCp6 (ORCPT ); Thu, 21 Dec 2017 21:45:58 -0500 Received: by mail-pl0-f66.google.com with SMTP id n13so12170413plp.11; Thu, 21 Dec 2017 18:45:57 -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=FGMhEOawsy0F5FE8CmY4BuECgE2lwdwdJn74QnIQPZk=; b=pNq7Eo8lhBDjffhAdIWTwniL/hStsuuk+/xsGnY51RYsihPED5oSofxnVWjAe+6SN2 d+XvMPtbsD3a9xT+gh0TacngDoR9al6cszSlNygXfo8jQXGrL9gkwuKvGJlpECpJPR5G Dhey2dr3cA0BZRlql4CnKICAwE7HIDR4YkhXGiLQdxnYFn00axRItA3Z4n4KAF8NNSGh V2Vuga3ztJdDVfm9PH4Oq5c74zwQ2L04sNScNKCt3rI9rM1wFAKtkK/D/iM/psR7Mr/R VuEKoJqpBCwxNEz3bgpSlTeW6tsf0p30pVjU8qUd6UUI058ZNpJJPwAxptCbDjPZQgE/ ub0w== 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=FGMhEOawsy0F5FE8CmY4BuECgE2lwdwdJn74QnIQPZk=; b=R2RMkdt1CvcvxoTpHCxLJav9zrTeqQLdL3XuppS190OfkoLDzZyG1A55ZWeVOH4Wy4 BGUJA+REsL7KXSc69X+P9cXDjwWt70BUp1tlUQdmv/G5HnbeRukY1I2j8LZ4/1C3i2u1 +n2tu9nRVi97HHiT1PDDFmQj+2KeMSMOpN93nX6qzP5OAIjgpSbbAlQqiGs6kRb2l/yq kN9vvl6QNDIupkpUvOTex2z2H5AXunh1etVqA3gVj93s8IqZEgc3OohwmkUM0DlPZOSQ Qr19PBc+vJfW/++riuVxiXQKeogRREXpAkab0IubgrPRjdxtfAhtPkzVgPR7R1BJtzm/ yXPA== X-Gm-Message-State: AKGB3mLluCwrRfmSo+aZjKWF+SL2fKZ1oVaOSvqMabvWJ+qosSSoxF9U BDt/IlbX8wxoSKqyxZltVHs= X-Received: by 10.159.246.7 with SMTP id b7mr12146452pls.81.1513910757354; Thu, 21 Dec 2017 18:45:57 -0800 (PST) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id e9sm43270925pfl.138.2017.12.21.18.45.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Dec 2017 18:45:56 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Fri, 22 Dec 2017 13:15:48 +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 v7 2/5] clk: aspeed: Register core clocks Date: Fri, 22 Dec 2017 13:15:19 +1030 Message-Id: <20171222024522.10362-3-joel@jms.id.au> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171222024522.10362-1-joel@jms.id.au> References: <20171222024522.10362-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.15.1 Reviewed-by: Benjamin Herrenschmidt diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c index 7a86ee08ea4f..5adedda82d26 100644 --- a/drivers/clk/clk-aspeed.c +++ b/drivers/clk/clk-aspeed.c @@ -13,7 +13,23 @@ #define ASPEED_NUM_CLKS 35 +#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; @@ -91,6 +107,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; @@ -132,6 +302,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 Fri Dec 22 02:45:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 122623 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1689198qgn; Thu, 21 Dec 2017 18:46:26 -0800 (PST) X-Google-Smtp-Source: ACJfBou6wpiVOrpFeu+O6XkXWKvREZ91HFLLInfQ/ccRsCHBt68J4nrAk1s8bbJ3z9N8dRd/K646 X-Received: by 10.84.193.129 with SMTP id f1mr12384630pld.363.1513910786101; Thu, 21 Dec 2017 18:46:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513910786; cv=none; d=google.com; s=arc-20160816; b=YpheC+WfDBsNYyHqDeCaPH4JlozbewdRV8FXY9f5fbccLPeKZiBYnrSkACdcaXGOVR SE3FFhEZnB1gf7+nmIkt/ZmUPkt3WM0s9LR7/zMwy10of3pqfJsoxOAj0hO8gktxi5Rl xQfBoMA9bqw2wD39avEwdMgXO/8fGMn9PZ/sNVpZL0Z5Ewo14zgubuIwo9Q9q0I6I3sl HNiB41Kw1+aAw/kzYoJGOyqoOo2qxZGCPuj7nozYoaNkG3bGzmEZxT8Or8mE0Ahi37mp 7vuQg1SkEvgE12HZDoUdlpma6szx0uPyQg6/y57a9VNOpwSZ1B2ZhQnj+fFkDYEupRac PBVQ== 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=NrEj55mGpzLhTGK9QtKdFfbqHQgeuIBipFHduLrbLek=; b=MokIxE+g8/Ak9RMFTkFnmN2SeDtv6BVZdQwkbm9JURpg2oSXFcrCaA9tHOFWDiaO3+ ab5XZjtvPrui+2d0gzqwu+VxXmZ5LWiD65jM8uEU2oOS3eeQqS8R1Ku5pJDQNyUVmmh6 s1lWNLPFkQiSx6P/6ZPHq9NmaYkNRCUpr6y5ueF+WtMzheGuynxLh/NbS+JO9RgjdAnN DkUrN5Gu668aSiDcBsXniTlgehkf5oA6KaZXw02HLGXYR4vWuihwaKz5t656GpaCb4Wa KLZO2iGbrKGopc1d1A9Ozan1sg73dXNx/rXDSuufB9NJydpIpzlsaRh13fVtUASKU/fx uHUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=DssmEsSb; 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 d8si14599417pgu.56.2017.12.21.18.46.25; Thu, 21 Dec 2017 18:46: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=DssmEsSb; 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 S1756087AbdLVCqS (ORCPT + 28 others); Thu, 21 Dec 2017 21:46:18 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:42700 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755893AbdLVCqH (ORCPT ); Thu, 21 Dec 2017 21:46:07 -0500 Received: by mail-pg0-f66.google.com with SMTP id q67so4778156pga.9; Thu, 21 Dec 2017 18:46:07 -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=NrEj55mGpzLhTGK9QtKdFfbqHQgeuIBipFHduLrbLek=; b=DssmEsSbxvKWwA003VzpX++SqE/USrr2PRTSHHQh7I4Fn30GnMZvUTPH3VdJLLelZh U4fgNUN1aa1sKds1xKnFAGvvEaZ+tFFtT+OWBbmRozLMAmXmJ/kMX6fPDD0PIyFg5pdO lxjZuwpFzH7+2jn/O+Yv4JIo3q54ReRvH0d6qYLFm2yihq5ZASy+YLlq0Py57ojuLMBb pJ4GBk3CvXRL2xWzSa04aw6cm075l0gYgyoY9vFKK784lN80MAqoQk4zObORzZle+7FI DHN/pK0NuW6rhoLRcWnLQgSSWuNZdHiO+5tGhVH75MgMb3dy97+Ebw1clfFeVw6Ow8+7 /5xQ== 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=NrEj55mGpzLhTGK9QtKdFfbqHQgeuIBipFHduLrbLek=; b=PoS8OLGKUaEZoGtG1+0gfFrPuzyi4T+T/0mT3U6UUsMAnTPxOxvxypdjcy4bkkCKjy 9fbRhCW6mZJ+Gdgyx4XjOCyaBz/rdBlwyHv7wUnY8adjOrLAVGuCBxh+O1gkUEjz1TtR 16BRcD9Sc486uO7NKp1b3BzSVK6Grx7mEnJJZancXX8tlYTPRXzCQbhOwdkU7dcZZ6/z tWEM9iFYNu0nyE6oNuPuYjDqIyWTSEDWduCZHrZJYj8EW2AJv9GL3h4c9pxsBPcUpEw+ VA9nxdQ3RsDvuaI8wk/OPqhJAfHYrdbMYblTScOjyCwpZj5Qh6y6UDdYfDg4RGEzjFlx rJnA== X-Gm-Message-State: AKGB3mK6zUyiP3hWpbK1/e4Q4cBQTjqmpqLYyjYtBz856bgCeW4d/agn 86vCA3YCglgz62nxPygS294= X-Received: by 10.99.127.29 with SMTP id a29mr11156958pgd.3.1513910766875; Thu, 21 Dec 2017 18:46:06 -0800 (PST) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id k14sm22200401pgt.48.2017.12.21.18.46.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Dec 2017 18:46:05 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Fri, 22 Dec 2017 13:15:57 +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 v7 3/5] clk: aspeed: Add platform driver and register PLLs Date: Fri, 22 Dec 2017 13:15:20 +1030 Message-Id: <20171222024522.10362-4-joel@jms.id.au> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171222024522.10362-1-joel@jms.id.au> References: <20171222024522.10362-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.15.1 Reviewed-by: Benjamin Herrenschmidt diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c index 5adedda82d26..cf5ea63feb31 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 @@ -107,6 +109,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 }, @@ -172,6 +186,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 Fri Dec 22 02:45:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 122625 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1693240qgn; Thu, 21 Dec 2017 18:51:53 -0800 (PST) X-Google-Smtp-Source: ACJfBotdmBV7H0vUeq0hBaXBvzs9ApDhNPUmgQ9TpJSsMRfnusw3zXxZ+3zCXjDML3BI1LbayX5U X-Received: by 10.98.67.78 with SMTP id q75mr12626562pfa.110.1513911113488; Thu, 21 Dec 2017 18:51:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513911113; cv=none; d=google.com; s=arc-20160816; b=hnVZQ5ybXelkGFR637vH46EB56go2CA1FazjUYeY4YbfEdOWmuVncSUZI6s0gLxfmt c0N2ME3MMfHXme0ZxtEMxiwk9WK7MPbWJVBx9LJZK85nQyFXEFcVcf4EWELj6Ij68v+s Jql5AKSaLJjY+I4dTLtmIP8fEQCwYM2E0T8A1G/Ac85IDIUC4GaxPnqmq7Ny/DmZZDi7 Bx3XTpX1gU1w9WhUuB6qVJVHi3iqYGOsjTYwS3uOpN2MmIQZI+QTcbhE48naEcSO4JSc bEa2e3j3owK8UVwrJZn5UUdMdW1vdOyd2XfBOc/bUsR91WfZ2ZTyQMg9Qw6HW/ACmQcT 3xUw== 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=qeuE+ctt7XYsjIzS18U+mQ8BIaLSb4ppIwtKqoduEes=; b=ZGJiFLSY+GWKuqsVD3TOelbG1cknfCNgBOCfGDN5H78vWp7KILMVpq8DIYbChXrH5n HgJiuh6zpklqR7WrroJvhskClXlxOMbZ080vlMVCb2h6t41v9/eJkLz20+frp70SvkG5 +EO4aBcwqirWDPSfIdj9HY98vtc+3kqW9mOstXmxKMhdifxz1jlku08Iyqx2WcmjMEmm FuNLR7QOCckddv/QV7yFTIjZX2lqw8sTTvYY+bWOkOTf34qF5kBqAzAds1sRxELljcJ0 QIbGCmxpHjDUDlSa/hP551E2G/nuKuXlX2Udz+EsL5NSf+Jj+I7lynBMCMWLDGxhG65l BnCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=B8Yyf5QR; 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 g12si16375585plm.149.2017.12.21.18.51.53; Thu, 21 Dec 2017 18:51:53 -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=B8Yyf5QR; 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 S1755664AbdLVCvt (ORCPT + 28 others); Thu, 21 Dec 2017 21:51:49 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:41471 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752901AbdLVCvr (ORCPT ); Thu, 21 Dec 2017 21:51:47 -0500 Received: by mail-pg0-f68.google.com with SMTP id 77so645518pgd.8; Thu, 21 Dec 2017 18:51:47 -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=qeuE+ctt7XYsjIzS18U+mQ8BIaLSb4ppIwtKqoduEes=; b=B8Yyf5QRmil9+fNcQ7mJBredoaKp7H6FnMYf3zo8pb8Sf7PGyQ1chwz0/RsDsUy5WJ 24LaLn/QafB1aqCSKCIvghZBlRm+X3ZPTUBBU9VLHVLHdr9SDRWwtBcDkovC0FLWzG25 O3pu5Ui07BBywKMgLnjggbRp/LgsskNrv1OzgrbNq5myuaCioHb0cnSdg4ake8SHBTiV ptC9aL+4TtbN5U8K3C3WxOk0lKag2t5z1JItE0miULef7TE3xPeZsoCdT9W+IDWtFg0m hf7Ko1XKt3upWYrKn2w/SilHHn4nToduAuHKn+wt137Q6nY2pD6H72MdBThEA9a07JfP CD+A== 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=qeuE+ctt7XYsjIzS18U+mQ8BIaLSb4ppIwtKqoduEes=; b=aC0rIU54YosRvbAXr63XltgGu+YjXi/5tlAABuHGx392kqmDACvYqbAMMMqUCRAkfc beiWRiuFZJgy7znu6WOuyXr/sTmFCGTfkSSrGQQRVNjUhGdv5IeHOrySCBOA5JMmakNo m6m3IPqexOH4FVYkdWi/OF8VoHWQoheV+8byrX/K7f4V66WFbjXLt3O/Vq2zmjiTmjH2 V8hEtyphi9jfqTT/AzPxVDdieIXCbOkL1wH51BylbvOEbtmdBm7bF7adv7wBFVib6RXq cnpj59PLYiHw6fiT65x1tar/h4e5CsdFteK9hEU0EqFsFFwr0dJErcJ0m3KeGnl8DSlB hGpg== X-Gm-Message-State: AKGB3mJmFGUqKcCGZyavIv8ie50vFxYGiH4uQwBHzxHI7lTKAdjeXX1G gA9tMpZkG2oTu+BmsuNUHd8= X-Received: by 10.99.45.67 with SMTP id t64mr11366793pgt.146.1513910776333; Thu, 21 Dec 2017 18:46:16 -0800 (PST) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id k63sm42098806pfk.172.2017.12.21.18.46.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Dec 2017 18:46:15 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Fri, 22 Dec 2017 13:16:07 +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 v7 4/5] clk: aspeed: Register gated clocks Date: Fri, 22 Dec 2017 13:15:21 +1030 Message-Id: <20171222024522.10362-5-joel@jms.id.au> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171222024522.10362-1-joel@jms.id.au> References: <20171222024522.10362-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 --- v7: - Use mdelay instead of msleep and remove the todo. Stephen points out: > No you can't sleep here. It needs to delay because this is inside > spinlock_irqsave. 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 mdelay Signed-off-by: Joel Stanley --- drivers/clk/clk-aspeed.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) -- 2.15.1 Reviewed-by: Benjamin Herrenschmidt diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c index cf5ea63feb31..dbd3c7774831 100644 --- a/drivers/clk/clk-aspeed.c +++ b/drivers/clk/clk-aspeed.c @@ -204,6 +204,106 @@ 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) { + /* A delay of 10ms is specified by the ASPEED docs */ + mdelay(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; @@ -211,6 +311,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)) { @@ -283,6 +384,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 Fri Dec 22 02:45:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 122624 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp1689293qgn; Thu, 21 Dec 2017 18:46:33 -0800 (PST) X-Google-Smtp-Source: ACJfBotnuUMsgoL24cbrFwZCxlTtyQydShc3/icMEMc8KZl/3i2i5NEe2Qdwry6k8yY7Rgpbk5nQ X-Received: by 10.99.142.199 with SMTP id k190mr11293939pge.129.1513910793672; Thu, 21 Dec 2017 18:46:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513910793; cv=none; d=google.com; s=arc-20160816; b=kpe1tgS74BNkdlnTtXSTnI4irENni2mPwplxAcHMnoIYZYGKa/ni62ks1n3/2xGQ1G dxJDeYhE7t01DKNCWgdIHvyqAmorWgVaOmjHDQCSxF2iTBlBdaWKO2gbSmzsAT6qlJEd gToNYNoMrje5AKWP2QxREdf5XugR5umjqwC1qSj6i9EejscXZ0QEoBXc3VVmdVtlTF3F HhafM4O8Z5sIrybGZLmlsqcIZvhNp2JrZBCaM6YulSv8GyyGViu4iTPoeKUPoOJrh7Hi APC2EMoBsmkUdVhsJBKJhCp+iWumYRjErikKGcUILC6fQQi4hbIX2j5IG2HuCQfalX3r 3J5g== 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=tpR8qyGU2q4CSR7ehBU5bjr+Vz3UbL3xFgSfK2SiWZA=; b=PPqzGTG285/4f0pTmh7dMLGXDgh4hg0dsBJbt1rR2tZlIXcoHDb2/PHFtCATSRZOP/ +dFmnCrTobGEeRBe9gbgq8DP2WLdDpcW4V3fUU8CuNPJ1p6hAv1VIdrEWfTNK+00Ob1F 3S8ycONUHl7FEtYYxr0aaDDj4OxunG2JP3oLyrADqZZ6/V94+1xzEc3fHJol+UpOd/mN h56DEQSpdN0X8KQ6XdXJxiOMvVW+T1lD5Q9+yapTRGqHSUU8/L6SiSXmQQAtcAWS0kNU dQiHUG8wQm7c1y+UMBLMEUs4SCubRx24Eqdy/5vrVbqJPa7gM/Xhb4G3UKhg0zAe23fE KhPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=pVl98C49; 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 u7si15494102plr.399.2017.12.21.18.46.33; Thu, 21 Dec 2017 18:46:33 -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=pVl98C49; 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 S1756126AbdLVCq3 (ORCPT + 28 others); Thu, 21 Dec 2017 21:46:29 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34665 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755893AbdLVCq0 (ORCPT ); Thu, 21 Dec 2017 21:46:26 -0500 Received: by mail-pf0-f195.google.com with SMTP id a90so14782978pfk.1; Thu, 21 Dec 2017 18:46:26 -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=tpR8qyGU2q4CSR7ehBU5bjr+Vz3UbL3xFgSfK2SiWZA=; b=pVl98C49gEzktXvp3CZ8AddwhHGhSIkDwn6pC4GQM/iv32omL3Ox/nnDhh82t3BsAF HNUBXwaAwpFDsIPUtspsnzJhRMFEeOl3C9NLpfYn9oA/Z2yQ0NhTz2LO5T7PBJjcoYPR LuqvZXbAU+xn8rhpGF137mW4f0Bsj3v18avrxMuapfGmSzyeEajiD7Cyo4f1u5b1kFsf SrFtUvcpbIg3kiHmNiRaJrNQ1a8IYZZVAEdUTDpFxp7fMJy6mIer56hYu6yVu5DdQNb0 lYK5kFPt/5gKeVYeDkWyrzrZ+7K90pFKDY32cimabAJTY4s2m6vLlfNP4/P2qOn7jpKL Dgog== 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=tpR8qyGU2q4CSR7ehBU5bjr+Vz3UbL3xFgSfK2SiWZA=; b=QfcqH0H2vrvE89QqGtOeTj0y3jfm6FeX9vE3wo+nijTbLMuvFgNbOc95TFhISAobLv H7YsGKhA2MOY3eqI6HqgwnlC0+zbzQCCW/CXCEV76JB8VNwGfYJLO10sGI8HSmN2DMKD Ywx9IqVxv1dfY+KjLqz4MX4uVk1SxKX8GcA2L86V2bUIYc68VLG58DAzu5Tb8Q1IpBjD LZidNNo3M1rgEEowDUaOvHLBTeotaJR8KpUGdwXVuMVKLzUigzQyJnWXrA3AzfA8kUHg tWmd29bGxd01n6tyMzgXoMElOfVIZC+3WvLWA5d088IVeyoVoPNDNayOrkaB/PMDCH9Q SJKQ== X-Gm-Message-State: AKGB3mJnSw9u7fg+xt3A1OvKsTN2SYf9h3mwWikjnEr+9KuJcRv6+0/n 5eugsKptCb++mSCL403fyoM= X-Received: by 10.99.96.10 with SMTP id u10mr11382115pgb.303.1513910786277; Thu, 21 Dec 2017 18:46:26 -0800 (PST) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id u6sm42720595pfk.126.2017.12.21.18.46.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Dec 2017 18:46:25 -0800 (PST) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Fri, 22 Dec 2017 13:16:16 +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 v7 5/5] clk: aspeed: Add reset controller Date: Fri, 22 Dec 2017 13:15:22 +1030 Message-Id: <20171222024522.10362-6-joel@jms.id.au> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171222024522.10362-1-joel@jms.id.au> References: <20171222024522.10362-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 --- v7: - Rebase on dt-bindings patch v5: - Add Andrew's Reviewed-by v3: - Add named initalisers for the reset defines - Add define for ADC --- drivers/clk/clk-aspeed.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) -- 2.15.1 Reviewed-by: Benjamin Herrenschmidt diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c index dbd3c7774831..6fb344730cea 100644 --- a/drivers/clk/clk-aspeed.c +++ b/drivers/clk/clk-aspeed.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -267,6 +268,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, @@ -308,10 +371,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)) { @@ -319,6 +383,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) {