From patchwork Fri Mar 2 05:48:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 130470 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp906677lja; Thu, 1 Mar 2018 21:51:31 -0800 (PST) X-Google-Smtp-Source: AG47ELsyxsvYRqLt6EXWFj7jQXdEikOy4tGYLRhADqWr3haxGvk5P5ogql5VnPRv6bZf6j9OiTWx X-Received: by 10.98.12.149 with SMTP id 21mr4574165pfm.118.1519969891243; Thu, 01 Mar 2018 21:51:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519969891; cv=none; d=google.com; s=arc-20160816; b=C03SWM2ORo+Unn+r++mWDTUMdXlbfzS1fivSjF5Ynt1naoby3zFZT/O1/nTYkNRjDs 9HYisPBx7ZCn/53Qd76WRWRjIB1qxor1e317U+RCXQ6famHi09ovt8Mdm5fCu9p5rySG 0AuwedSO+IUlcEN6a48z70ZiVSTy0Cb9PoLnn/DCAFcMPRqZOJf1ExX25xmllI6yAxrx qmzlYX4m1tpTtbHdlOlN/fwcvbiLtbHbOpche55MYFfcYXQ3fgi+QTC7fdWl7AJ1wawb UDz5nZmurMkE5a2lSuuBCAEbF91RYKtnizY3lwBfjihZJzwlWOCUqGzi+1+T0naMNKsd qAWg== 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=Tok+ItM6RVX4iLhCpEbSqqi5TKJXcFO9HlirsgGga4A=; b=rK0+F3fELhpq9ivuk8fiY6QW4zbzw+Sp8NpThd5zWtlrm1xMSF2Fx2uoNMI+DMVsUg dAfRcESK8nQb1asC2pPQFzNI8Ewdybqhf70/bkUXUFjWjPK0Vxl+G1Mq30zghAraoB/Y yUM7ceNSeJSL+1UDEt+0Isgqdpop3BovMsycMxJXIv66+2CwJw2Z27fPhiUMgM+dPPTw Pu2/6xyOisxreRhOyB/U4uZdwK7ka3OR551dkLh7r8cjpLhw4SZku5P2Zy1MRvjn2ep2 c26Pg29LStX03bpgK2T7jY+X+Wj8lHiiwNXO+sFpUiDnrFhtziS5u8cTLgLhB5ENjylx 0ZhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UOS2B1fm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9-v6si4204910plt.685.2018.03.01.21.51.31; Thu, 01 Mar 2018 21:51:31 -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=pass header.i=@linaro.org header.s=google header.b=UOS2B1fm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936000AbeCBFvX (ORCPT + 28 others); Fri, 2 Mar 2018 00:51:23 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:39046 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935951AbeCBFvT (ORCPT ); Fri, 2 Mar 2018 00:51:19 -0500 Received: by mail-pg0-f67.google.com with SMTP id w16so2447360pgv.6 for ; Thu, 01 Mar 2018 21:51:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Tok+ItM6RVX4iLhCpEbSqqi5TKJXcFO9HlirsgGga4A=; b=UOS2B1fm5JTyQ9Qv4lxvVwjK7oLN43nU3zkcHEH3ZvQm4MJZN70sDFEjDe5Gx0ixMf 5FvUH5aGVGYc1ClCXASEG69dn0G0djl8mmOJ3MwFsjMjK5iDL7nIyJCaPwhTkh9kxeu+ gg6BqAbvV9MPTcmTFYq97l7pob/Mb+xdFHrPc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Tok+ItM6RVX4iLhCpEbSqqi5TKJXcFO9HlirsgGga4A=; b=XzexrWQQ00QdROGQFzfqwe4OiCwG5EXrHH16AVSMrCv0ofRV1FNRKkLEdaCGk3017o c6vuTjAEWkuib2F+uDguSinecb82ewGvNhOyqqimq41eRi1P/zyfxECS2cpQXXjcbmLI hPxi1MJGcfCTTLFQB4Juh5QiJLHliFfDakX5er94dWIAoR3tBdZVrkih3iXZH36fWooz eBqszinotUNweEsBcLW+pgK4kkSyRiR72pWQnmq9y3EzvOJKepIFvcrRSDPGQGv837ja 48Dbqpz6DMLQD/TEJnp4E9Rpsbv3Yr8PyhneSilHOb0bs9GsYFLXyRvNxpxa767WePHv i3JQ== X-Gm-Message-State: APf1xPAW5qS0JQk6JEiocN/iA76Z3dqbswZEX+vxsyubeh150i0wSkr5 3KdX8TBQqZwMLedxLG6VcrgSLhJr6w== X-Received: by 10.98.135.76 with SMTP id i73mr4562690pfe.140.1519969878319; Thu, 01 Mar 2018 21:51:18 -0800 (PST) Received: from localhost.localdomain ([2405:204:71c0:7f9a:bd87:b648:dccb:cbc9]) by smtp.gmail.com with ESMTPSA id t63sm12569748pfj.44.2018.03.01.21.51.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 21:51:17 -0800 (PST) From: Manivannan Sadhasivam To: mturquette@baylibre.com, sboyd@kernel.org, afaerber@suse.de, robh+dt@kernel.org, mark.rutland@arm.com Cc: liuwei@actions-semi.com, mp-cs@actions-semi.com, 96boards@ucrobotics.com, devicetree@vger.kernel.org, davem@davemloft.net, mchehab@kernel.org, daniel.thompson@linaro.org, amit.kucheria@linaro.org, viresh.kumar@linaro.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, manivannanece23@gmail.com, Manivannan Sadhasivam Subject: [PATCH v4 05/11] clk: actions: Add gate clock support Date: Fri, 2 Mar 2018 11:18:54 +0530 Message-Id: <20180302054900.11275-6-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180302054900.11275-1-manivannan.sadhasivam@linaro.org> References: <20180302054900.11275-1-manivannan.sadhasivam@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for Actions Semi gate clock together with helper functions to be used in composite clock. Signed-off-by: Manivannan Sadhasivam --- drivers/clk/actions/Makefile | 1 + drivers/clk/actions/owl-gate.c | 77 ++++++++++++++++++++++++++++++++++++++++++ drivers/clk/actions/owl-gate.h | 73 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 drivers/clk/actions/owl-gate.c create mode 100644 drivers/clk/actions/owl-gate.h -- 2.14.1 diff --git a/drivers/clk/actions/Makefile b/drivers/clk/actions/Makefile index 64a50fc2d335..1f0917872c9d 100644 --- a/drivers/clk/actions/Makefile +++ b/drivers/clk/actions/Makefile @@ -1,3 +1,4 @@ obj-$(CONFIG_CLK_ACTIONS) += clk-owl.o clk-owl-y += owl-common.o +clk-owl-y += owl-gate.o diff --git a/drivers/clk/actions/owl-gate.c b/drivers/clk/actions/owl-gate.c new file mode 100644 index 000000000000..25dd94ac0f35 --- /dev/null +++ b/drivers/clk/actions/owl-gate.c @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-2.0+ +// +// OWL gate clock driver +// +// Copyright (c) 2014 Actions Semi Inc. +// Author: David Liu +// +// Copyright (c) 2018 Linaro Ltd. +// Author: Manivannan Sadhasivam + +#include +#include + +#include "owl-gate.h" + +void clk_gate_set(const struct owl_clk_common *common, + const struct owl_gate_hw *gate_hw, bool enable) +{ + int set = gate_hw->gate_flags & CLK_GATE_SET_TO_DISABLE ? 1 : 0; + u32 reg; + + set ^= enable; + + regmap_read(common->regmap, gate_hw->reg, ®); + + if (set) + reg |= BIT(gate_hw->bit_idx); + else + reg &= ~BIT(gate_hw->bit_idx); + + regmap_write(common->regmap, gate_hw->reg, reg); +} + +static void owl_gate_disable(struct clk_hw *hw) +{ + struct owl_gate *gate = hw_to_owl_gate(hw); + struct owl_clk_common *common = &gate->common; + + clk_gate_set(common, &gate->gate_hw, false); +} + +static int owl_gate_enable(struct clk_hw *hw) +{ + struct owl_gate *gate = hw_to_owl_gate(hw); + struct owl_clk_common *common = &gate->common; + + clk_gate_set(common, &gate->gate_hw, true); + + return 0; +} + +int clk_is_enabled(const struct owl_clk_common *common, + const struct owl_gate_hw *gate_hw) +{ + u32 reg; + + regmap_read(common->regmap, gate_hw->reg, ®); + + if (gate_hw->gate_flags & CLK_GATE_SET_TO_DISABLE) + reg ^= BIT(gate_hw->bit_idx); + + return !!(reg & BIT(gate_hw->bit_idx)); +} + +static int owl_gate_is_enabled(struct clk_hw *hw) +{ + struct owl_gate *gate = hw_to_owl_gate(hw); + struct owl_clk_common *common = &gate->common; + + return clk_is_enabled(common, &gate->gate_hw); +} + +const struct clk_ops owl_gate_ops = { + .disable = owl_gate_disable, + .enable = owl_gate_enable, + .is_enabled = owl_gate_is_enabled, +}; diff --git a/drivers/clk/actions/owl-gate.h b/drivers/clk/actions/owl-gate.h new file mode 100644 index 000000000000..4fc609647ae4 --- /dev/null +++ b/drivers/clk/actions/owl-gate.h @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0+ +// +// OWL gate clock driver +// +// Copyright (c) 2014 Actions Semi Inc. +// Author: David Liu +// +// Copyright (c) 2018 Linaro Ltd. +// Author: Manivannan Sadhasivam + +#ifndef _OWL_GATE_H_ +#define _OWL_GATE_H_ + +#include "owl-common.h" + +struct owl_gate_hw { + u32 reg; + u8 bit_idx; + u8 gate_flags; +}; + +struct owl_gate { + struct owl_gate_hw gate_hw; + struct owl_clk_common common; +}; + +#define OWL_GATE_HW(_reg, _bit_idx, _gate_flags) \ + { \ + .reg = _reg, \ + .bit_idx = _bit_idx, \ + .gate_flags = _gate_flags, \ + } + +#define OWL_GATE(_struct, _name, _parent, _reg, \ + _bit_idx, _gate_flags, _flags) \ + struct owl_gate _struct = { \ + .gate_hw = OWL_GATE_HW(_reg, _bit_idx, _gate_flags), \ + .common = { \ + .regmap = NULL, \ + .hw.init = CLK_HW_INIT(_name, \ + _parent, \ + &owl_gate_ops, \ + _flags), \ + } \ + } \ + +#define OWL_GATE_NO_PARENT(_struct, _name, _reg, \ + _bit_idx, _gate_flags, _flags) \ + struct owl_gate _struct = { \ + .gate_hw = OWL_GATE_HW(_reg, _bit_idx, _gate_flags), \ + .common = { \ + .regmap = NULL, \ + .hw.init = CLK_HW_INIT_NO_PARENT(_name, \ + &owl_gate_ops, \ + _flags), \ + }, \ + } \ + +static inline struct owl_gate *hw_to_owl_gate(const struct clk_hw *hw) +{ + struct owl_clk_common *common = hw_to_owl_clk_common(hw); + + return container_of(common, struct owl_gate, common); +} + +void clk_gate_set(const struct owl_clk_common *common, + const struct owl_gate_hw *gate_hw, bool enable); +int clk_is_enabled(const struct owl_clk_common *common, + const struct owl_gate_hw *gate_hw); + +extern const struct clk_ops owl_gate_ops; + +#endif /* _OWL_GATE_H_ */