From patchwork Wed Sep 27 06:27:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 114351 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4673967qgf; Tue, 26 Sep 2017 23:28:09 -0700 (PDT) X-Received: by 10.84.244.6 with SMTP id g6mr346354pll.223.1506493689249; Tue, 26 Sep 2017 23:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506493689; cv=none; d=google.com; s=arc-20160816; b=KssrrWk7lBfjs7uY6n27leQxuhLt6b0R45ZXbKZG/9Jv4ifhvmWAEsP5QEDddk+L+W 36vMu2xNdDSAiTv9k4fRIE5Xnzyn8nHCeNj6NYQk70tJq+unl/fZWyO7UiNsUgJgnvE8 ClauNMgC2XiHlEES5h/BXrKhupRleV3uzQyuN4NLDQpbdg9/Es6fJX1EOq1EstxB9ZcP x4uuD9njde8FAHqioTU/9JM06qlFKt+W0ey4hNJKAr/wXf1fgT+mVpvUTSvEJE2I+hfo oUxI01Yx2mulbDXAzQw4lR2xhLQeGNvvb1vu2UYuwayLwHlYX/13UzaS4sI3uMpjK4WK iYGg== 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=G5XTmFmLjm8m02fUeC0jL1eiDTE1nYAhHWdOxGxhi3s=; b=UhzpvRPXJFnFXROeKe5a0lJuCI03CAMmRcPuoF0lCwV8Q678RYRNV3JW621AR88S8p ltymTILuQ+auN3BiL5DBgVwQWuUK3501+0jGJ1WyhQYH2mTMBlSg5HvnhxpM8OAPhIvX 8hYQ03KoG80EZipw/kb+HRL3zZTTis5xcAMrGaaZXY8sZx0w6E+5Jus4e5z3xPC3uXRI A47glatl6Y0mllhxqAlZ6HFOyPTeiCp+57vG50Lvz2bYWt5FMU3uBTW2y2XSImnplT2F 16guM8OWD/x8K2owPOpZ1mBW7qOJOKQjLSXdOWSONxVlXqusD9nbkbN9TYpqkkVvDQ5c NTOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Nd1oq+ax; 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.09; Tue, 26 Sep 2017 23:28:09 -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=Nd1oq+ax; 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 S1752155AbdI0G2H (ORCPT + 26 others); Wed, 27 Sep 2017 02:28:07 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:38437 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750805AbdI0G2E (ORCPT ); Wed, 27 Sep 2017 02:28:04 -0400 Received: by mail-pf0-f194.google.com with SMTP id a7so6001926pfj.5; Tue, 26 Sep 2017 23:28:04 -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=G5XTmFmLjm8m02fUeC0jL1eiDTE1nYAhHWdOxGxhi3s=; b=Nd1oq+axWxFggN7qGyNDV4B2s+QrmH+z0wh735HPWjxmigqcWogUpfbxKR/TKxbHKp /mGUT8Sebj6BlwmjsvQUqEpOAwqCAWaXvNaUGuXEWovmVvNVycFpzbwXKSkVWs7c6kPe 9ecTwBSXuyq496GakH8NLMQAJNV5M/9AcLypj0ZCtk7NeZ3f731KJtl9gjF6NMNlyRr/ AQJvqWGyesqN1JYuXtoQuGKmfbkfav+gCJEmJKbKGHKd4Zemime4cpSqiFOrvJKo9gCE ejxlaQEBud9E2LW8CLg1NdgQpEo9Q5cv7leM6771P/a7ZNo/b0T3Q/EA256SKNwXsfDq vGFw== 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=G5XTmFmLjm8m02fUeC0jL1eiDTE1nYAhHWdOxGxhi3s=; b=OFb8NveezyyLlpXRUcTYRIlzpQF2WTc2ozSahqO2teqRYNEenIrzQThAC5f70jczhw vqnlBgKphOF6jqCNZFlUNwr2FrBcyOT2Euydd/AVN0jXmA4hW20b9UGIDzPRlKxm/iYw GeIFlg59skVOv/WO95knF7Sk5XCU6PyfQP67MFRAAV+v/FfJXsCq5oU6ls2oEeV/bEhd Xotd97XbBvtejlRXSWlQNnki0i5XlqeTwDj2K671DZXFfMwnXvlkEawa4C8C89ggD1uS Yp7wjNn1/wngXS2H3PGhmPxCPdmpW1mJ65YVqb5eAUR7GNijWp9tSR8L3HjFrBBKipCm TEiA== X-Gm-Message-State: AHPjjUhZrdly9tBusj7114W2cs0ENewvBERkN4PdSOn2qK+XDga6ymjY QYaL2vMw5hPsf2MlQdfGG50= X-Google-Smtp-Source: AOwi7QAX+z+8l4MsgA++lHeoAdQKC8Boh8Qf+F6X8pOISsiJzc6wVSUHTjKoY+A49D2vI0KHez5ojA== X-Received: by 10.99.138.73 with SMTP id y70mr365280pgd.317.1506493684201; Tue, 26 Sep 2017 23:28:04 -0700 (PDT) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id i84sm18681071pfj.105.2017.09.26.23.27.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Sep 2017 23:28:02 -0700 (PDT) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Wed, 27 Sep 2017 15:57:55 +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 4/5] clk: aspeed: Register gated clocks Date: Wed, 27 Sep 2017 15:57:01 +0930 Message-Id: <20170927062702.11350-5-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 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. Signed-off-by: Joel Stanley --- V3: - Remove gates offset as gates are now at the start of the list --- drivers/clk/clk-aspeed.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) -- 2.14.1 diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c index e43016ea82cd..42a69839d86e 100644 --- a/drivers/clk/clk-aspeed.c +++ b/drivers/clk/clk-aspeed.c @@ -207,6 +207,108 @@ 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); + + /* Disable clock */ + 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 | CLK_IS_BASIC; + 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 __init aspeed_clk_probe(struct platform_device *pdev) { const struct aspeed_clk_soc_data *soc_data; @@ -214,6 +316,7 @@ static int __init 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 +384,31 @@ static int __init aspeed_clk_probe(struct platform_device *pdev) &aspeed_clk_lock); aspeed_clk_data->hws[ASPEED_CLK_BCLK] = hw; + /* 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 + */ + + for (i = 0; i < ARRAY_SIZE(aspeed_gates); i++) { + const struct aspeed_gate_data *gd; + + gd = &aspeed_gates[i]; + aspeed_clk_data->hws[i] = aspeed_clk_hw_register_gate(NULL, + gd->name, + gd->parent_name, + gd->flags, + map, + gd->clock_idx, + gd->reset_idx, + CLK_GATE_SET_TO_DISABLE, + &aspeed_clk_lock); + } + return 0; };