From patchwork Tue Oct 3 06:55:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 114664 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp1540891qgn; Mon, 2 Oct 2017 23:56:49 -0700 (PDT) X-Received: by 10.84.151.68 with SMTP id i62mr15986847pli.179.1507013809784; Mon, 02 Oct 2017 23:56:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507013809; cv=none; d=google.com; s=arc-20160816; b=KkoCte/STQ8sfvsKBwsCgp2Qfkd5Sj5tosu9pQXJz3YiyV6aFIYvajWYcn78uCY1Sg JPrSm022vpdU2XBpryWeo5A6zav1KDnvJ5KMIdHhM0T9UfxtwG2wYygl0tDoOD1rAeEc +a5vyFClyfX8F8yDFEi8aCB9KbH/uZjMZxKs8tiuKePfNP3GeItS2I7LVeuvOCnvIT5Z 5iz6zggY2zpZAcb23Ys8atRY42R21d4ejl3o6MzdXB2wyooPeb4Zp00sZ7//A3PEaSZQ dmjMVky/7CGXNQyyNW1UNMt/rJ7RK0dDkgJfOWPHf98sXgR+ir10gtz4XnA8KAcq86RO 36xw== 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=hjEcFKTT9PaVOvEKoj6gVSwkNjyog+673B9+xTLMJv0=; b=t7vLVRng6EefvARbtOSsocrvEpr8JUZRiQolC+6zcn7JY6NsctQ4XbzQEcoiQgoBAI slLpTS/tUN94r/IokIN0BtJxg7LksP77nKJBlSnB3QHpFBDh/+sZOMITJoq+IcthGbe7 J6pZ/OBBppTTsyIRb3Sn2ywgBObOYg8VY6ixL0BTqdjQ6TyPzsqJ5I9DDSnjvdoTvkki luJcrtE7RnzhUhDvLWOIIZvvHJ055HXlABwyA1jXYd4/M3bHYgkHdQ1S1JOjA9HLxsxz cA4WvSsDxvzXM7qeeLpk65DjX0MBCZPZfyFK9vTw7lIPyixwDkYh6ZoY9M1sjCWv8AvN tToA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=q/QXSQ/v; 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 i87si9208157pfi.397.2017.10.02.23.56.49; Mon, 02 Oct 2017 23:56:49 -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=q/QXSQ/v; 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 S1751345AbdJCG4s (ORCPT + 26 others); Tue, 3 Oct 2017 02:56:48 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36418 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750812AbdJCG4p (ORCPT ); Tue, 3 Oct 2017 02:56:45 -0400 Received: by mail-pf0-f196.google.com with SMTP id f84so8133304pfj.3; Mon, 02 Oct 2017 23:56:45 -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=hjEcFKTT9PaVOvEKoj6gVSwkNjyog+673B9+xTLMJv0=; b=q/QXSQ/vxVlA9kOI76k/7U69ho4hLaLP3xPfIznJ7nnmStipfNZOUt/gvZ//YFsPXk zhOeSuoHcwE8y0lh48Xx2q0KTsLeeSRugOe0prYagy/HSaFcLqMoVjfjGtn+bk1oMswD AvY3bKp7XZvQilhZ7kIU7Of8xKKIwzIr6ywbUcoQYlnp8ollJAIi4flVqNDJO9LTIYz2 VWb/+2V6bWNl9oW2a91wedHsmalMTTY68C94tHgGqndVf8kUcdCOcoshJGmXwzF59uZ5 SLbAT9hbP/MaECshdeMJxoHdN52omwgNcXdxrTFGAUQsN32tUqdSgYLCjEqpqFMqC886 WOHw== 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=hjEcFKTT9PaVOvEKoj6gVSwkNjyog+673B9+xTLMJv0=; b=n+NemUodh8FqSOR68QBAEzugmpeAUV21gM7AevqnwCpD4Yklpil2RCGNXHzd15ShdN af+rvzTfvS1WgyFflAM/mc1dyKpJJiwPmjxm1Xeq1SHyeBtynDgrKe7s4IntmiFn+4s9 XufA9qqWzKNB4XzUSdhSGlaCsSNHjse5/duajxAEuZ0/4DZOLX6M/EpcYqShVtWwmggP vlHHUvmJB+0PMYo19U/72OBVD/7JmDBbIAv+DVYuqqe3gXd5LVLWEdDfCgdSky1Gwpa+ ciM2H4yCkTVMa1gn396DNfG0TWTIOt7C5D6tNMeeO0V8vPVx0LeCwmd/F72OPhSUDD1N qpIw== X-Gm-Message-State: AMCzsaUHnprKR/q5K2afblHTSUPZ8VdT1wRPindMEjTIEeeL36cZEwPH 9Z8gvNDxycvgbDId8ZJcAlc= X-Google-Smtp-Source: AOwi7QCgFm4WU8unindTlET7d18GHols3z+TM3kNT1jJLl5yxOm63PKRncPJIDvIpKJvOtGWSn4zgQ== X-Received: by 10.84.228.193 with SMTP id y1mr7290582pli.301.1507013805256; Mon, 02 Oct 2017 23:56:45 -0700 (PDT) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id i10sm18530758pgo.71.2017.10.02.23.56.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Oct 2017 23:56:44 -0700 (PDT) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Tue, 03 Oct 2017 17:26:36 +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 v4 4/5] clk: aspeed: Register gated clocks Date: Tue, 3 Oct 2017 17:25:39 +1030 Message-Id: <20171003065540.11722-5-joel@jms.id.au> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171003065540.11722-1-joel@jms.id.au> References: <20171003065540.11722-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 --- 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 | 130 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) -- 2.14.1 Acked-by: Andrew Jeffery diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c index adb295292189..a424b056e767 100644 --- a/drivers/clk/clk-aspeed.c +++ b/drivers/clk/clk-aspeed.c @@ -228,6 +228,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; @@ -235,6 +336,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)) { @@ -323,6 +425,34 @@ 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 + */ + + 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; };