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: 9981805 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AD75360375 for ; Tue, 3 Oct 2017 06:58:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F46528868 for ; Tue, 3 Oct 2017 06:58:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93BEE2886A; Tue, 3 Oct 2017 06:58:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7B0CE28868 for ; Tue, 3 Oct 2017 06:58:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=CXlIC1Js1DYRE+aaLqeGVSacyBsxDbBdGd10rmcMb8I=; b=D72ahm8sdDpsVfjbgn4WHGsmSn nOXSDQwjRxy3IazQHuKar21jlS6ofxD9HqOGTYzDEjTN2SAlKMlIsqsiLSVs2j6FIMCiCGAYG0l2G suCvdr3LMVdnliPSm6Z8ipjzXHgQBQ854tiwnZDFNOyv2yBrbdH0VMjODhf48VY+YmwGhu7yfNByh XO8v9+u0wi1vDS+XIXWPreGE2REhz308uplYG0yB/i/LbA+mABn5ye9gqNrD83qBYOEaojFiQgk8F EQ6n9STjB0GWXM5fueSkH+BQfZWyOzoHv/ZhASkuZ9XfmywHc+Deiwj5O7RpbArE3mOJ/6XoxSRm3 f12EOPPg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dzH9f-0004rK-9Q; Tue, 03 Oct 2017 06:58:11 +0000 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dzH8X-0003jq-Qp for linux-arm-kernel@lists.infradead.org; Tue, 03 Oct 2017 06:57:15 +0000 Received: by mail-pf0-x244.google.com with SMTP id g65so8133098pfe.1 for ; Mon, 02 Oct 2017 23:56:46 -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=LQ+E4s9xLOzb+GxzsmHLaQX7NO6DqVsEVITA75/9mVbXeSzdB/7nBiQubYg8r72Pp7 wq5iXmCy+4ndsPQbwZfc5L5e0l78Snv6DW4+r0nV8o+OkjJh/o3YW5NgzXAn7tValKA2 0V/NYJ/zrVZnzLknwqwj2ARHCqxE0BCZdby3vCp6Xfi4G8BpQqwfKG0jVou93SdHRNOQ IhzPFaLkPD8ob/7juBYRTb981xKUB9nj7SyncvW7cM65+MICQ7l/jKrbW3OkElja8ZKw Rrob0RbnqHcy6FZRJx5WD8s/d0M5XgQt0zqWnMu7Y1Uhs1FQmINH11nmHS+V9Ti30wnX 4M7w== X-Gm-Message-State: AMCzsaUXwMeUncNLCqaO7Ky1LOcq2Or3U0dojMnT1Bpkp7e9W2KB0/8r r9UNnejaMIw+UI/qVUKSNgTJAA2t0UE= 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171002_235702_822744_EBB86768 X-CRM114-Status: GOOD ( 17.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ryan Chen , Arnd Bergmann , Andrew Jeffery , Benjamin Herrenschmidt , linux-kernel@vger.kernel.org, Rick Altherr , Jeremy Kerr , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Andrew Jeffery --- 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(+) 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; };