From patchwork Mon Jan 8 02:17:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 10148729 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 1CFAF60210 for ; Mon, 8 Jan 2018 02:27:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09931287F3 for ; Mon, 8 Jan 2018 02:27:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F276F287FE; Mon, 8 Jan 2018 02:27:37 +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 5DB12287F3 for ; Mon, 8 Jan 2018 02:27:37 +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=gTsGlwtG4gvJGLCVUhUs+ag19nCUpMAaDHoNQy8uEFo=; b=JTkkwVAyolgvsJlg5sUJIYYIYp CjCywkD1wmXgC+6UyAhBi9a2Cvmk55ZnM/OC+buQiOUzX03dunk3QWIk9ShIFLTXFvo+Oo/RBpjMe 7+oKZQuOh/VCHW3FUoddLA46EJXu+5Si9tv5G93fvXeFHpi3E0VLlzxza9N1OVcVe5NKs+3bZUX5o Zb2Vi3z64u/RE23xI4OHW4REOSChH6AHK/URdpHtnlrkLTV5wz6s8NTuwueuBimZsiYKZjYnvtUvM uMsoD9TxOZFSmDtule8s+X7WmYi3DUHXz0XS71Gc4Mwp8jqmuLt+l0gahxvalyMV0iQmomSlou0ly c6EtBRNQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eYN9w-0007QH-Qs; Mon, 08 Jan 2018 02:27:32 +0000 Received: from vern.gendns.com ([206.190.152.46]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eYN1a-0008Jd-R2 for linux-arm-kernel@lists.infradead.org; Mon, 08 Jan 2018 02:19:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject :Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=m3oMBdckIyH+grXdxzgvMTHIqSRYQQa4VQmHF3vz1G4=; b=vv5PY4udus48eZFY56gJZMPxx KO1QAiozu6OyQLxrq5R13vDrY+jJyxMHfh27pbH6tikVQleW5pVIfcjRdxB72slUZshqfu9DOeQNn v9qEFa7Zi+9xSSVx4YfNXMvylo52FQUF5s6/AHb6cNYm/omwBl5kW+dJJNefjgOoZRdhZUZBcMj8B n+tbtuDFgbyL/duDdDTlb/31oiOVigo/HX4pmPZkChOMFPQAx7vgn5X3iTmA1rPuXvy3mW8FDZlL4 nOaBzT04Tp+I/J7JvOgYAA7x+8T3bR5MRLPKys9Kkud6N+ltylE46A2iyUJOHEzsZ8utZDXuLWv6A /fHYv3opA==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:53904 helo=freyr.lechnology.com) by vern.gendns.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-SHA256:128) (Exim 4.89) (envelope-from ) id 1eYN1M-0009GR-UC; Sun, 07 Jan 2018 21:18:41 -0500 From: David Lechner To: linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 19/44] clk: davinci: New driver for TI DA8XX CFGCHIP clocks Date: Sun, 7 Jan 2018 20:17:18 -0600 Message-Id: <1515377863-20358-20-git-send-email-david@lechnology.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515377863-20358-1-git-send-email-david@lechnology.com> References: <1515377863-20358-1-git-send-email-david@lechnology.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180107_181855_830333_12060B78 X-CRM114-Status: GOOD ( 13.18 ) 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: Mark Rutland , David Lechner , Kevin Hilman , Stephen Boyd , Michael Turquette , Sekhar Nori , linux-kernel@vger.kernel.org, Rob Herring , Adam Ford 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 This adds a new driver for the gate and multiplexer clocks in the CFGCHIPn syscon registers on TI DA8XX-type SoCs. Signed-off-by: David Lechner --- drivers/clk/davinci/Makefile | 2 + drivers/clk/davinci/da8xx-cfgchip.c | 203 ++++++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+) create mode 100644 drivers/clk/davinci/da8xx-cfgchip.c diff --git a/drivers/clk/davinci/Makefile b/drivers/clk/davinci/Makefile index 6c388d4..11178b7 100644 --- a/drivers/clk/davinci/Makefile +++ b/drivers/clk/davinci/Makefile @@ -1,6 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 ifeq ($(CONFIG_COMMON_CLK), y) +obj-$(CONFIG_ARCH_DAVINCI_DA8XX) += da8xx-cfgchip.o + obj-y += pll.o obj-$(CONFIG_ARCH_DAVINCI_DA830) += pll-da830.o obj-$(CONFIG_ARCH_DAVINCI_DA850) += pll-da850.o diff --git a/drivers/clk/davinci/da8xx-cfgchip.c b/drivers/clk/davinci/da8xx-cfgchip.c new file mode 100644 index 0000000..772e09a --- /dev/null +++ b/drivers/clk/davinci/da8xx-cfgchip.c @@ -0,0 +1,203 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Clock driver for DA8xx/AM17xx/AM18xx/OMAP-L13x CFGCHIP + * + * Copyright (C) 2017 David Lechner + */ + +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_OF +struct da8xx_cfgchip_gate_clk { + struct clk_hw hw; + struct regmap *regmap; + u32 reg; + u32 mask; +}; + +#define to_da8xx_cfgchip_gate_clk(_hw) \ + container_of((_hw), struct da8xx_cfgchip_gate_clk, hw) + +static int da8xx_cfgchip_gate_clk_enable(struct clk_hw *hw) +{ + struct da8xx_cfgchip_gate_clk *clk = to_da8xx_cfgchip_gate_clk(hw); + + return regmap_write_bits(clk->regmap, clk->reg, clk->mask, clk->mask); +} + +static void da8xx_cfgchip_gate_clk_disable(struct clk_hw *hw) +{ + struct da8xx_cfgchip_gate_clk *clk = to_da8xx_cfgchip_gate_clk(hw); + + regmap_write_bits(clk->regmap, clk->reg, clk->mask, 0); +} + +static int da8xx_cfgchip_gate_clk_is_enabled(struct clk_hw *hw) +{ + struct da8xx_cfgchip_gate_clk *clk = to_da8xx_cfgchip_gate_clk(hw); + unsigned int val; + + regmap_read(clk->regmap, clk->reg, &val); + + return !!(val & clk->mask); +} + +static const struct clk_ops da8xx_cfgchip_gate_clk_ops = { + .enable = da8xx_cfgchip_gate_clk_enable, + .disable = da8xx_cfgchip_gate_clk_disable, + .is_enabled = da8xx_cfgchip_gate_clk_is_enabled, +}; + +static void da8xx_cfgchip_gate_clk_init(struct device_node *np, u32 reg, + u32 mask) +{ + struct da8xx_cfgchip_gate_clk *clk; + struct clk_init_data init; + const char *name = np->name; + const char *parent_name; + struct regmap *regmap; + int ret; + + of_property_read_string(np, "clock-output-names", &name); + parent_name = of_clk_get_parent_name(np, 0); + + regmap = syscon_node_to_regmap(of_get_parent(np)); + if (IS_ERR(regmap)) { + pr_err("%s: no regmap for syscon parent of %s (%ld)\n", + __func__, np->full_name, PTR_ERR(regmap)); + return; + } + + clk = kzalloc(sizeof(*clk), GFP_KERNEL); + if (!clk) + return; + + init.name = name; + init.ops = &da8xx_cfgchip_gate_clk_ops; + init.parent_names = parent_name ? &parent_name : NULL; + init.num_parents = parent_name ? 1 : 0; + init.flags = 0; + + clk->hw.init = &init; + clk->regmap = regmap; + clk->reg = reg; + clk->mask = mask; + + ret = clk_hw_register(NULL, &clk->hw); + if (ret) { + pr_err("%s: failed to register %s (%d)\n", __func__, + np->full_name, ret); + return; + } + + of_clk_add_hw_provider(np, of_clk_hw_simple_get, &clk->hw); +} + +static void da8xx_tbclk_init(struct device_node *np) +{ + da8xx_cfgchip_gate_clk_init(np, CFGCHIP(1), CFGCHIP1_TBCLKSYNC); +} +CLK_OF_DECLARE(da8xx_tbclk, "ti,da830-tbclk", da8xx_tbclk_init); + +struct da8xx_cfgchip_mux_clk { + struct clk_hw hw; + struct regmap *regmap; + u32 reg; + u32 mask; +}; + +#define to_da8xx_cfgchip_mux_clk(_hw) \ + container_of((_hw), struct da8xx_cfgchip_mux_clk, hw) + +static int da8xx_cfgchip_mux_clk_set_parent(struct clk_hw *hw, u8 index) +{ + struct da8xx_cfgchip_mux_clk *clk = to_da8xx_cfgchip_mux_clk(hw); + unsigned int val = index ? clk->mask : 0; + + return regmap_write_bits(clk->regmap, clk->reg, clk->mask, val); +} + +static u8 da8xx_cfgchip_mux_clk_get_parent(struct clk_hw *hw) +{ + struct da8xx_cfgchip_mux_clk *clk = to_da8xx_cfgchip_mux_clk(hw); + unsigned int val; + + regmap_read(clk->regmap, clk->reg, &val); + + return (val & clk->mask) ? 1 : 0; +} + +static const struct clk_ops da8xx_cfgchip_mux_clk_ops = { + .set_parent = da8xx_cfgchip_mux_clk_set_parent, + .get_parent = da8xx_cfgchip_mux_clk_get_parent, +}; + +static void da8xx_cfgchip_mux_clk_init(struct device_node *np, u32 reg, + u32 mask) +{ + struct da8xx_cfgchip_mux_clk *clk; + struct clk_init_data init; + const char *name = np->name; + const char *parent_names[2]; + struct regmap *regmap; + int ret; + + ret = of_property_match_string(np, "clock-names", "pll0_sysclk2"); + parent_names[0] = of_clk_get_parent_name(np, ret); + if (!parent_names[0]) { + pr_err("%s: missing pll0_sysclk2 clock\n", __func__); + return; + } + + ret = of_property_match_string(np, "clock-names", "pll1_sysclk2"); + parent_names[1] = of_clk_get_parent_name(np, ret); + if (!parent_names[1]) { + pr_err("%s: missing pll1_sysclk2 clock\n", __func__); + return; + } + + regmap = syscon_node_to_regmap(of_get_parent(np)); + if (IS_ERR(regmap)) { + pr_err("%s: no regmap for syscon parent of %s (%ld)\n", + __func__, np->full_name, PTR_ERR(regmap)); + return; + } + + of_property_read_string(np, "clock-output-names", &name); + + clk = kzalloc(sizeof(*clk), GFP_KERNEL); + if (!clk) + return; + + init.name = name; + init.ops = &da8xx_cfgchip_mux_clk_ops; + init.parent_names = parent_names; + init.num_parents = 2; + init.flags = 0; + + clk->hw.init = &init; + clk->regmap = regmap; + clk->reg = reg; + clk->mask = mask; + + ret = clk_hw_register(NULL, &clk->hw); + if (ret) { + pr_err("%s: failed to register %s (%d)\n", __func__, + np->full_name, ret); + return; + } + + of_clk_add_hw_provider(np, of_clk_hw_simple_get, &clk->hw); +} + +static void da8xx_async3_init(struct device_node *np) +{ + da8xx_cfgchip_mux_clk_init(np, CFGCHIP(3), CFGCHIP3_ASYNC3_CLKSRC); +} +CLK_OF_DECLARE(da8xx_async3, "ti,da850-async3-clock", da8xx_async3_init); +#endif