From patchwork Wed Sep 27 06:27:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 114352 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4674063qgf; Tue, 26 Sep 2017 23:28:18 -0700 (PDT) X-Received: by 10.99.109.71 with SMTP id i68mr384142pgc.252.1506493698892; Tue, 26 Sep 2017 23:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506493698; cv=none; d=google.com; s=arc-20160816; b=ZSba4F2D4hv3xpSpvitmxPBo2yf7Lf+fhFn4IeWapq5y/eaW7c3YkEt6IJa271LonW xpQepecPLiXnt8qD5WRBLyjA8fd3Nn0A3zu8TAsjTLObtb6vs02plwwJ/J2cnRaMJ0kN 4Na29QA6mo4OarZXT842bAyLV/DKTOtPaBw7JF70E2IlSGG4m9/JrQyzu6AkyG7E8yNi AoHf1nBXAIp++0/NrwJDiXOoFBtKeR2HX1jzMEskrxNhbyeauXdlhWVWHuNXhTLC9tEe FFTNlwYQVtEr9bu1EbsiSrRuIdT9ApUbzjaBULUuFAhisxgou0Ov7HFHbtWHUc4/k297 wdtg== 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=tabUEba9bihTTYuienB300wIGl8uqcC+QFp6tat38BY=; b=Y4KeDRcfThif7ogumFOYffHEeGhq6zEvpAt//UAqWkA++5WOQb9KDP5vFad8CWqOWq TmXOfjKX7eHq5Cs05IDQd1boxOCACVhYsfTfyQ8uFeyb7sE5bwzVcdSBd8l42LHG2ECE WW8U/18hjC+iN7SwkFi6GM34KYwOtxiG84pDh5kivy+QkJRdehSwrOC+nZi9xY68GLI0 bEKrHxWd5Fp80cM6hCVT4R0HrMUgagMXNAozC811zQy24rWXdQlCiqHOUelqevI9whmK vFAhnFitwYBokYlPG39JoPMHc+bNwBmK1kKfgIpiy+PqGE5pToLagRFm66p5j6grMVGf Nt0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=GcnMaiT1; 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 82si6755756pfn.379.2017.09.26.23.28.18; Tue, 26 Sep 2017 23:28:18 -0700 (PDT) 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=GcnMaiT1; 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 S1752178AbdI0G2R (ORCPT + 26 others); Wed, 27 Sep 2017 02:28:17 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:36974 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750805AbdI0G2O (ORCPT ); Wed, 27 Sep 2017 02:28:14 -0400 Received: by mail-pg0-f66.google.com with SMTP id v5so8147354pgn.4; Tue, 26 Sep 2017 23:28:14 -0700 (PDT) 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=tabUEba9bihTTYuienB300wIGl8uqcC+QFp6tat38BY=; b=GcnMaiT1e43zFKF2ktzWUoSScjUGuDox0E49Md9Izs8Cw7sL7939e8CnfzEFaeRw8y i/nQNVoCCIvI8MSMzKKVYmHN1iWNcA6bWlWQKd0Qk/4nhGaMFAwl7SO01RTNSRDQHFtm +iQHRNgks1n6NFpOvZxFD+Qt/8qq5bddVyJh9RCzoz8YCteO0fuLjBKjkPue3QFFuy0X uPlSIjiNvDvcBzpzrWIvGEPDXq6TwhqngTGfP8yktF2NHm/qOjbn8GdI/Q+jE6lWulS3 /PtfY0ghHCroxO8zr/rKy8Ui0ec6H/qKDT5mKb4fYYgLLDtTXCiNbqQ1/I4NHa7o8I5L 9VZA== 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=tabUEba9bihTTYuienB300wIGl8uqcC+QFp6tat38BY=; b=TcpL+ZrbYZtRrRXYXAk1I9484oA78+sPNP2zduqPFPevcSCPrxZ8n4g8k8IXCKJI8C 3UrwxA3D6DBgVOMPESzYzqMCNukMXZa0dx9u8i6uUbaYmYhJsymE5loQGytkY2R36dzz rRiJvfOTYyC/5SXeUCeg3/XARw2k0OAoL3P1g2mXmEACF1EFq+X2cw4QCesu2vZ6MHzX yxywpCg7ffd0AxpwojZJtOKKCkIiPpbD7FXZt1F9evfxXu0z3kGjycCJuO1hJ5FDnr2n T+frhcwE8bE0x2ugNtSsMeyBHASCcmKFw8puc7mo4mN7mOZVEpIzlG+OfBdCNV8t11d5 QR5A== X-Gm-Message-State: AHPjjUityL/vnwQCm+fjfDD/PUWFs1GnGazeihbbFjXk1xJypZpC/dEA cZz08xlVdOnvAn6xV/H3jhY= X-Google-Smtp-Source: AOwi7QDv4l9iVCGqugPa63K4RRP30GaBJL8KqAPx/bIQUSjemCo9SHz0stDYntJUATI2AXdYHBxTXA== X-Received: by 10.159.218.6 with SMTP id v6mr361057plp.1.1506493693767; Tue, 26 Sep 2017 23:28:13 -0700 (PDT) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id v2sm18708482pgo.38.2017.09.26.23.28.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Sep 2017 23:28:12 -0700 (PDT) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Wed, 27 Sep 2017 15:58:04 +0930 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 v3 5/5] clk: aspeed: Add reset controller Date: Wed, 27 Sep 2017 15:57:02 +0930 Message-Id: <20170927062702.11350-6-joel@jms.id.au> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170927062702.11350-1-joel@jms.id.au> References: <20170927062702.11350-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. Signed-off-by: Joel Stanley --- 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 42a69839d86e..4b08ad3b7960 100644 --- a/drivers/clk/clk-aspeed.c +++ b/drivers/clk/clk-aspeed.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -272,6 +273,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, @@ -313,10 +376,11 @@ static int __init 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)) { @@ -324,6 +388,22 @@ static int __init 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(&pdev->dev); diff --git a/include/dt-bindings/clock/aspeed-clock.h b/include/dt-bindings/clock/aspeed-clock.h index 4a99421d77c8..8e19646d8025 100644 --- a/include/dt-bindings/clock/aspeed-clock.h +++ b/include/dt-bindings/clock/aspeed-clock.h @@ -39,4 +39,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