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; };