Received: by 10.223.176.46 with SMTP id f43csp1033294wra; Sat, 20 Jan 2018 09:23:03 -0800 (PST) X-Google-Smtp-Source: AH8x224Zhkb1YOw/2gMWGHJBDC2ADHxPzSPqIzZ+8B770wrTHE87NQBUGZ16ueEltgSDg2BnABFg X-Received: by 10.99.97.87 with SMTP id v84mr2607455pgb.342.1516468983119; Sat, 20 Jan 2018 09:23:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516468983; cv=none; d=google.com; s=arc-20160816; b=QjPDmJk4xTGV3gs8JG6g7EDwiNAI7v8pMDiFLS43JgpwpCIJOAtRMCjgJctNaSZGbH In7vY8hYWR4oWRV1NUR6fWaS6E3UsoaotKUPcTe8lSdyllxVYALkojW5dBr4X33McUs5 qnadG7NsEaFyE+M+GZwieHRUehXB6LPvx60x70WA/e1pVIohHrFhbQQEDdVheMn5xcEX 0alTCa1itmf+1pkRBi9Gn/gg8FS2mlfhf2Y51mCNSgdNspNsKzKSJW0k/e9L0SuKNmGY vWG8yPN/5EsqDOR2GWO1ewT53l6HveOet0fNxnqz9/KlH59mTbfFxEKDOWVk2hH1lmwP SoUw== 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=Px5qCpw2D7C1mfm6zsCjOqbisZvtohY4MKVBQqCTKF0=; b=QNmLsttZ8KSemUdLCGx2k3yL3h+DAGwj3NTvjnWlUNtsHECoCRT+ubmncdcYCQ/1hh gnNXkGMctBD0saXs+R3Aq7P5q3fjWsrMr97h9zGMZ7mEScUiGa5LVizKN04rbHqe2e9B HvDh2fWWxlBakGxouLnOkq0SvrG9sjgV8Xtt1U/kQsTj2DsiIR6GkA17LVcZnPK2Ggfu SLK8WbLU0IbLFa5S0t8NqlbdD1Vh1DdGtsQ+ZD60LeUffgf9S48BIjXx4H9LMZz684QH R/kaFQ/vfYUeH4lMto6WwqNpHbhto0w8uqhlboJk7q0Otf3CNoqbGFjDhoYB2la9k2uj cN5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=HZC88MVg; 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 y5si10569973pgs.359.2018.01.20.09.22.48; Sat, 20 Jan 2018 09:23:03 -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=@lechnology.com header.s=default header.b=HZC88MVg; 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 S1756823AbeATRVH (ORCPT + 99 others); Sat, 20 Jan 2018 12:21:07 -0500 Received: from vern.gendns.com ([206.190.152.46]:42714 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756579AbeATRPc (ORCPT ); Sat, 20 Jan 2018 12:15:32 -0500 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=Px5qCpw2D7C1mfm6zsCjOqbisZvtohY4MKVBQqCTKF0=; b=HZC88MVg22Xk7XD5ftvRMIFMi 0qx7zmVplUM1B3hQkCubTEl720PLCCHT1ZaJKDRa0Vb4qccKr8P+eJqjAtC/9CJ1DxHqmBY3wK47Y UOYtKwvzSy80oCuhQCWHSmawhqRMsXhZ5U4KcA13j/+nCUFtj6pTcmEKwsE2tIYbK1JWEcDtHaz4v GxAkfxDKWQhV9X9YN+tPyGn7hcFImdx55cqX6eAhIoEXX3pVD4mGGrqr2pWSySyixHUJoVvViEL+U /r99EsQ2O0wkT2GFEKDS38SIAl2eD2eqNglx7SQwyqVL+06p/4kHK7EWjTos67HEBG/wss6TjHkzP kSRs01P+w==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:53590 helo=freyr.lechnology.com) by vern.gendns.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-SHA256:128) (Exim 4.89_1) (envelope-from ) id 1ecwjM-00059q-0F; Sat, 20 Jan 2018 12:15:00 -0500 From: David Lechner To: linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Michael Turquette , Stephen Boyd , Rob Herring , Mark Rutland , Sekhar Nori , Kevin Hilman , Bartosz Golaszewski , Adam Ford , linux-kernel@vger.kernel.org, David Lechner Subject: [PATCH v6 18/41] clk: davinci: New driver for TI DA8XX CFGCHIP clocks Date: Sat, 20 Jan 2018 11:13:57 -0600 Message-Id: <1516468460-4908-19-git-send-email-david@lechnology.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516468460-4908-1-git-send-email-david@lechnology.com> References: <1516468460-4908-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 - vger.kernel.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: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- v6 changes: - added DIV4.5 and ASYNC1 clocks - refactored code to be more generic - added functions for registering clocks from board files (no longer device tree only) - use pr_fmt macro drivers/clk/davinci/Makefile | 2 + drivers/clk/davinci/da8xx-cfgchip.c | 305 ++++++++++++++++++++++++++++++++++++ include/linux/clk/davinci.h | 5 + 3 files changed, 312 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..21dedb4 --- /dev/null +++ b/drivers/clk/davinci/da8xx-cfgchip.c @@ -0,0 +1,305 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Clock driver for DA8xx/AM17xx/AM18xx/OMAP-L13x CFGCHIP + * + * Copyright (C) 2018 David Lechner + */ + +#define pr_fmt(fmt) "%s: " fmt "\n", __func__ + +#include +#include +#include +#include +#include +#include +#include + +#define DA8XX_GATE_CLOCK_IS_DIV4P5 BIT(1) + +struct da8xx_cfgchip_gate_clk_info { + const char *name; + u32 cfgchip; + u32 bit; + u32 flags; +}; + +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 unsigned long da8xx_cfgchip_div4p5_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + /* this clock divides by 4.5 */ + return parent_rate * 2 / 9; +} + +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 const struct clk_ops da8xx_cfgchip_div4p5_clk_ops = { + .enable = da8xx_cfgchip_gate_clk_enable, + .disable = da8xx_cfgchip_gate_clk_disable, + .is_enabled = da8xx_cfgchip_gate_clk_is_enabled, + .recalc_rate = da8xx_cfgchip_div4p5_recalc_rate, +}; + +static struct clk * __init +da8xx_cfgchip_gate_clk_register(const struct da8xx_cfgchip_gate_clk_info *info, + const char *parent_name, + struct regmap *regmap) +{ + struct da8xx_cfgchip_gate_clk *gate; + struct clk_init_data init; + + gate = kzalloc(sizeof(*gate), GFP_KERNEL); + if (!gate) + return ERR_PTR(-ENOMEM); + + init.name = info->name; + if (info->flags & DA8XX_GATE_CLOCK_IS_DIV4P5) + init.ops = &da8xx_cfgchip_div4p5_clk_ops; + else + 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; + + gate->hw.init = &init; + gate->regmap = regmap; + gate->reg = info->cfgchip; + gate->mask = info->bit; + + return clk_register(NULL, &gate->hw); +} + +static const struct da8xx_cfgchip_gate_clk_info da8xx_tbclksync_info __initconst = { + .name = "ehrpwm_tbclk", + .cfgchip = CFGCHIP(1), + .bit = CFGCHIP1_TBCLKSYNC, +}; + +struct clk * __init da8xx_cfgchip_register_tbclk(struct regmap *regmap) +{ + return da8xx_cfgchip_gate_clk_register(&da8xx_tbclksync_info, "ehrpwm", + regmap); +} + +static const struct da8xx_cfgchip_gate_clk_info da8xx_div4p5ena_info __initconst = { + .name = "div4.5", + .cfgchip = CFGCHIP(3), + .bit = CFGCHIP3_DIV45PENA, + .flags = DA8XX_GATE_CLOCK_IS_DIV4P5, +}; + +struct clk * __init da8xx_cfgchip_register_div4p5(struct regmap *regmap) +{ + return da8xx_cfgchip_gate_clk_register(&da8xx_div4p5ena_info, + "pll0_pllout", regmap); +} + +#ifdef CONFIG_OF +static void __init +of_da8xx_cfgchip_gate_clk_init(struct device_node *np, + const struct da8xx_cfgchip_gate_clk_info *info) +{ + const char *parent_name; + struct regmap *regmap; + struct clk *clk; + + parent_name = of_clk_get_parent_name(np, 0); + + regmap = syscon_node_to_regmap(of_get_parent(np)); + if (IS_ERR(regmap)) { + pr_err("no regmap for syscon parent of %s (%lu)", np->full_name, + PTR_ERR(regmap)); + return; + } + + clk = da8xx_cfgchip_gate_clk_register(info, parent_name, regmap); + if (IS_ERR(clk)) { + pr_err("failed to register %s (%lu)", np->full_name, + PTR_ERR(clk)); + return; + } + + of_clk_add_provider(np, of_clk_src_simple_get, clk); +} + +static void __init da8xx_tbclksync_init(struct device_node *np) +{ + of_da8xx_cfgchip_gate_clk_init(np, &da8xx_tbclksync_info); +} +CLK_OF_DECLARE(da8xx_tbclksync, "ti,da830-tbclksync", da8xx_tbclksync_init); + +static void __init da8xx_div4p5ena_init(struct device_node *np) +{ + of_da8xx_cfgchip_gate_clk_init(np, &da8xx_div4p5ena_info); +} +CLK_OF_DECLARE(da8xx_div4p5ena, "ti,da830-div4p5ena", da8xx_div4p5ena_init); +#endif + +struct da8xx_cfgchip_mux_clk_info { + const char *name; + const char *parent0; + const char *parent1; + u32 cfgchip; + u32 bit; +}; + +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 struct clk * __init +da8xx_cfgchip_mux_clk_register(const struct da8xx_cfgchip_mux_clk_info *info, + struct regmap *regmap) +{ + const char * const parent_names[] = { info->parent0, info->parent1 }; + struct da8xx_cfgchip_mux_clk *mux; + struct clk_init_data init; + + mux = kzalloc(sizeof(*mux), GFP_KERNEL); + if (!mux) + return ERR_PTR(-ENOMEM); + + init.name = info->name; + init.ops = &da8xx_cfgchip_mux_clk_ops; + init.parent_names = parent_names; + init.num_parents = 2; + init.flags = 0; + + mux->hw.init = &init; + mux->regmap = regmap; + mux->reg = info->cfgchip; + mux->mask = info->bit; + + return clk_register(NULL, &mux->hw); +} + +static const struct da8xx_cfgchip_mux_clk_info da850_async1_info __initconst = { + .name = "async1", + .parent0 = "pll0_sysclk3", + .parent1 = "div4.5", + .cfgchip = CFGCHIP(3), + .bit = CFGCHIP3_EMA_CLKSRC, +}; + +struct clk * __init da8xx_cfgchip_register_async1(struct regmap *cfgchip) +{ + return da8xx_cfgchip_mux_clk_register(&da850_async1_info, cfgchip); +} + +static const struct da8xx_cfgchip_mux_clk_info da850_async3_info __initconst = { + .name = "async3", + .parent0 = "pll0_sysclk2", + .parent1 = "pll1_sysclk2", + .cfgchip = CFGCHIP(3), + .bit = CFGCHIP3_ASYNC3_CLKSRC, +}; + +struct clk * __init da8xx_cfgchip_register_async3(struct regmap *cfgchip) +{ + return da8xx_cfgchip_mux_clk_register(&da850_async3_info, cfgchip); +} + +#ifdef CONFIG_OF +static void __init +of_da8xx_cfgchip_init_mux_clock(struct device_node *np, + const struct da8xx_cfgchip_mux_clk_info *info) +{ + struct regmap *regmap; + struct clk *clk; + + regmap = syscon_node_to_regmap(of_get_parent(np)); + if (IS_ERR(regmap)) { + pr_err("no regmap for syscon parent of %s (%ld)", np->full_name, + PTR_ERR(regmap)); + return; + } + + clk = da8xx_cfgchip_mux_clk_register(info, regmap); + if (IS_ERR(clk)) { + pr_err("Failed to register %s (%ld)", np->full_name, + PTR_ERR(clk)); + return; + } + + of_clk_add_provider(np, of_clk_src_simple_get, clk); +} + +static void __init da850_async1_init(struct device_node *np) +{ + of_da8xx_cfgchip_init_mux_clock(np, &da850_async1_info); +} +CLK_OF_DECLARE(da850_async1, "ti,da850-async1-clksrc", da850_async1_init); + +static void __init da850_async3_init(struct device_node *np) +{ + of_da8xx_cfgchip_init_mux_clock(np, &da850_async3_info); +} +CLK_OF_DECLARE(da850_async3, "ti,da850-async3-clksrc", da850_async3_init); +#endif diff --git a/include/linux/clk/davinci.h b/include/linux/clk/davinci.h index 3810ea3..54ea3ff 100644 --- a/include/linux/clk/davinci.h +++ b/include/linux/clk/davinci.h @@ -23,4 +23,9 @@ void dm365_psc_clk_init(void __iomem *psc); void dm644x_psc_clk_init(void __iomem *psc); void dm646x_psc_clk_init(void __iomem *psc); +struct clk *da8xx_cfgchip_register_tbclk(struct regmap *regmap); +struct clk *da8xx_cfgchip_register_div4p5(struct regmap *regmap); +struct clk *da8xx_cfgchip_register_async1(struct regmap *regmap); +struct clk *da8xx_cfgchip_register_async3(struct regmap *regmap); + #endif /* __LINUX_CLK_DAVINCI_H__ */ -- 2.7.4