Received: by 10.223.176.5 with SMTP id f5csp1377545wra; Fri, 9 Feb 2018 18:44:27 -0800 (PST) X-Google-Smtp-Source: AH8x226I6pvqRFNRQKDHcO/p2/YiVBVSryZG9USuiWCWR2i2VjFO3Nb9TMoJp486VTGWZkYiOEIa X-Received: by 10.98.86.27 with SMTP id k27mr3035149pfb.174.1518230667197; Fri, 09 Feb 2018 18:44:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518230667; cv=none; d=google.com; s=arc-20160816; b=qVeYbkkos/KjJ2C6ZIEL84dd24DA/KCKGdMcNkujKIhfN0gtG6gr4vtME5RNwsvbq2 d+mS0dVQ8M9JewWFjRBNXuASvOXrs80AoAIkQreDEgboWdRUsmfEyL0D8JoNrMkwdNZp oc9PohlGBSJSqDQy1d31Aqs6563zioOX1VyKGJN6Q3JJ/mgmsdl7y4LfgNgB4cHhId/G VCWF0drE7IfdlbkOS0e9pzc3RuuDvPGwRgDdOSnVd/rpjZ2Gr6nmsVWzn0wZyV5S7pfM fBKLtFX0qUsNAJie8s8/kGcJQGE1vEtB7lBoN5Je01ABRs2uo90RSWTSzhFbsBJDqRJX j8TA== 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=kQsDma/U+5R9vhGGnJvWVBxN3LvDlJ6G9qSfLoCx8mXE5k9R1ZJajuXNTacHwu+WJ7 6OjBLpugfaOdpL9FYnGrEjS0v6vcgtvZP9MYJ1ibUbPGf+kaDMnPI6sgmj3nrqQxRSde 7MeMIXoCYuq10RjSFNolGiHrfWltwAN25o363UJO+XiJzuuWHrxhkRJ6e659nYdO/dV3 Y8DheHH9xgT46QD4+gmaiui/WIU4CZ83k25ZQ2sz/sLIaaVRlYObi4CGpkLjYkOZnTj6 B7iwfUO3DkiPVp6/3P7PbSUD4I9SKZn08/4A1y6rdVqY61XFaSLU9CGJ/nJinzlAJ7cc Ppuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nz8+nSwJ; 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 t65si2160605pgc.599.2018.02.09.18.44.13; Fri, 09 Feb 2018 18:44:27 -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=Nz8+nSwJ; 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 S1752222AbeBJCmf (ORCPT + 99 others); Fri, 9 Feb 2018 21:42:35 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:34985 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752220AbeBJCmb (ORCPT ); Fri, 9 Feb 2018 21:42:31 -0500 Received: by mail-pl0-f68.google.com with SMTP id j19so2327457pll.2 for ; Fri, 09 Feb 2018 18:42:31 -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=Nz8+nSwJrbfhM7QZ4o3w/Do5hODieIB0MCruVneld2KipN9eqHhmxbJCov8D3zpIG9 CtXtcOA1Kkl2y+1WvvhCrUMgy709BbKkUKu7X7ww5gTo9gN6qmOUoiCm7qQc93gCQ9Ov 6Dyj30Mn64TK9tqTiyb70yD1bzQfplInglPj0= 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=gQrwIAF+/w/xr+LqWPT8jlRAaQTNFswgA402ekodVXgaGzL2aZWekNKv8MgdAq8zvf 2Xj2nfXON8t0f042WJYueHTlvmBnEfmzdv3lGT1DBMsWjTW1tUEwL/y0oQbmskYqPrKX yqikBsTEipRMMQgFbqVJGAB+bNoVHT5IAZUWgZHNiwVI1zQ5cs8pIw3+jyB345QNEfpA 6cev+7UHcQpzyTyV1Cbb+mtwwLvhAmsuF4oCTs1YTt3/HQit1bQ6U+ewJaGQvUhge/lO VTd+AiZiVQhqg6YZM+K6EsMHsg1Ggs0KcXoSV7tihEkYDRAnn3JGqQZUFwaO/SqTESM5 g+Lw== X-Gm-Message-State: APf1xPD7rhCpOl/aY4ztGE1StvNxzhJKR5375JOh2tq56tUXckp9B8UG QfD1wGmNXbmrnxyktgo2K80m X-Received: by 2002:a17:902:d81:: with SMTP id 1-v6mr4472579plv.270.1518230550901; Fri, 09 Feb 2018 18:42:30 -0800 (PST) Received: from localhost.localdomain ([2405:204:7185:1f8f:fdb9:648e:14d3:8b97]) by smtp.gmail.com with ESMTPSA id z6sm7883286pgu.49.2018.02.09.18.42.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Feb 2018 18:42:30 -0800 (PST) From: Manivannan Sadhasivam To: mturquette@baylibre.com, sboyd@codeaurora.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, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, viresh.kumar@linaro.org, Manivannan Sadhasivam Subject: [PATCH v3 05/11] clk: actions: Add gate clock support Date: Sat, 10 Feb 2018 08:11:14 +0530 Message-Id: <20180210024120.27503-6-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180210024120.27503-1-manivannan.sadhasivam@linaro.org> References: <20180210024120.27503-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 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_ */ -- 2.14.1