From patchwork Mon Mar 26 17:39:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 132429 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp4117031ljb; Mon, 26 Mar 2018 10:42:35 -0700 (PDT) X-Google-Smtp-Source: AG47ELupH3J2JmN5H9bvNkxqTsplZsYzdv+UxB0Pp4254EHIvJUcHe1betrwjOVkyWSGNhn2tAuh X-Received: by 2002:a17:902:684d:: with SMTP id f13-v6mr31131313pln.230.1522086154987; Mon, 26 Mar 2018 10:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522086154; cv=none; d=google.com; s=arc-20160816; b=QMVR0YTHz5UwZat0oorznAP3Oaibt5xZyAVfOG6p1JysXp9ojV3yhA57jOy+D7NwTW efGcUf58GcUDA0O0EnJPpV+YgkINIU3sBafLS7Fhn7AwA8h+8psOKejuD3KBd5qGRH1j YNFNCyiWqSfhYWsDgsT2pxKnKz4EYqNr9M1W/uT5JbDa+HfSkOIR9K83k8pZfp2TLTeQ zDmJ60qZKteO4QZxv9IljkR8tIwMifreWeK8Vm6ApKYcQPNc8w0k/3y/I9SnEs+hLYdd x6NYZW3FZxZk3+8EvHfoRgVk4b3617uQ6jhfrBXwGJYLerReRSYitauqKDOkBcrImpac 9d2A== 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=k1/hNRWci4pmlpYzNZcg9sW2pPvKa4BA0HsYXv5ume0=; b=yaE9pIJCMtG23h6vAu4TPfCdy/nvdCGt0hgC/sD/oRkWauW3SwILG4SshkSP5HCeBh 44Z7dFCSqxaEzw8qnTFwxZLiQ4THjTIK7quN10jo728/+FmwHU2mPHdLupuK4P/kgn8i 7Kpki2aoXqHTJb5VKnkmKsQMOrT3V9ZVkwVxSCMe0C4KtErzKo9QObbjd8aIsW6NG7tb fDlJ0BOY1V2T7ejEK4NtBRIc+pxioKxqCkTQMknsZAkyLH8EJ/bhIP/7WPnl96fYTSne DO31kgEhIAUGekXZ68/QU7DrOzd4CeMJ2Qh/b4vBcO3mcfsDPxcB1bxPYEt5nCXKDh5j I23Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TIy0p6rn; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (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 d81si12070551pfd.210.2018.03.26.10.42.34; Mon, 26 Mar 2018 10:42:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TIy0p6rn; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752926AbeCZRmd (ORCPT + 6 others); Mon, 26 Mar 2018 13:42:33 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:37912 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752918AbeCZRmb (ORCPT ); Mon, 26 Mar 2018 13:42:31 -0400 Received: by mail-pg0-f68.google.com with SMTP id a15so7546848pgn.5 for ; Mon, 26 Mar 2018 10:42:31 -0700 (PDT) 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=Uy+OnSE0HzTbPuBqcNNil7FWRqCLLGEQ+YyxDvuuSwQ=; b=TIy0p6rnlIfY1n4HB5YHe4nHAjvJirDkw3wjwvA+eBmbTST6LMu7KrbODdjd0WJOiV SKkKen9ct6VpTnFiLV57WD94RnW58kxdiwwMko/J1sfa+MJEdzaAvV3f8D2pd0mewcX2 QkE5nQ5k43kloF+ypCCmim+/KhBFna1z7Uo7o= 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=Uy+OnSE0HzTbPuBqcNNil7FWRqCLLGEQ+YyxDvuuSwQ=; b=Nw+M18Cm/l1WPweW/oDy9PX9OKIPls5chcoylccYwsNxngYvp4EzDPb7ZPXXPnr2mh P/N/gCpVC+iy0S+YIytTOpvXuU+B+TqPVsZYLUjPnusRnixsp1YcbUpXXf75gJ1S4sL2 2y+AjERQRn9v8Zbo1mDGAFeByQXCF7Mh5qxQiGswPp/bL62mMnLRgErZ8wTYoQUwvilY pLpT6N7NtzE/TouyInG2+bmGBa62PmBUjOFldFnejfKfe2HqwtCeDsIce2ML6d5+bvfJ lmH1uLiXXs7W4IPQU/6uL+TRacRnwFEDoLTUIdiFJ/SnNOZ5FgOU28Zsh8ZxIsc2tUto p3EQ== X-Gm-Message-State: AElRT7HzdxqHKr9W4xZlV+5dhJfwT1NLkVgosB1+AuQ3WCKvtt1Cmzhz aquQuNE1AFMIHj0n8L8kqrIQ X-Received: by 10.99.113.83 with SMTP id b19mr29122045pgn.167.1522086150999; Mon, 26 Mar 2018 10:42:30 -0700 (PDT) Received: from localhost.localdomain ([2405:204:73cc:afee:304e:6518:873b:59b1]) by smtp.gmail.com with ESMTPSA id x14sm24986115pgo.82.2018.03.26.10.42.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Mar 2018 10:42:30 -0700 (PDT) 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, hzhang@ucrobotics.com, bdong@ucrobotics.com, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, manivannanece23@gmail.com, Manivannan Sadhasivam Subject: [PATCH v7 06/11] clk: actions: Add divider clock support Date: Mon, 26 Mar 2018 23:09:00 +0530 Message-Id: <20180326173905.22313-7-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180326173905.22313-1-manivannan.sadhasivam@linaro.org> References: <20180326173905.22313-1-manivannan.sadhasivam@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add support for Actions Semi divider 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-divider.c | 94 +++++++++++++++++++++++++++++++++++++++ drivers/clk/actions/owl-divider.h | 75 +++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 drivers/clk/actions/owl-divider.c create mode 100644 drivers/clk/actions/owl-divider.h -- 2.14.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/clk/actions/Makefile b/drivers/clk/actions/Makefile index 2d4aa8f35d90..5ce75df57e1a 100644 --- a/drivers/clk/actions/Makefile +++ b/drivers/clk/actions/Makefile @@ -3,3 +3,4 @@ obj-$(CONFIG_CLK_ACTIONS) += clk-owl.o clk-owl-y += owl-common.o clk-owl-y += owl-gate.o clk-owl-y += owl-mux.o +clk-owl-y += owl-divider.o diff --git a/drivers/clk/actions/owl-divider.c b/drivers/clk/actions/owl-divider.c new file mode 100644 index 000000000000..cddac00fe324 --- /dev/null +++ b/drivers/clk/actions/owl-divider.c @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0+ +// +// OWL divider clock driver +// +// Copyright (c) 2014 Actions Semi Inc. +// Author: David Liu +// +// Copyright (c) 2018 Linaro Ltd. +// Author: Manivannan Sadhasivam + +#include +#include + +#include "owl-divider.h" + +long owl_divider_helper_round_rate(struct owl_clk_common *common, + const struct owl_divider_hw *div_hw, + unsigned long rate, + unsigned long *parent_rate) +{ + return divider_round_rate(&common->hw, rate, parent_rate, + div_hw->table, div_hw->width, + div_hw->div_flags); +} + +static long owl_divider_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *parent_rate) +{ + struct owl_divider *div = hw_to_owl_divider(hw); + + return owl_divider_helper_round_rate(&div->common, &div->div_hw, + rate, parent_rate); +} + +unsigned long owl_divider_helper_recalc_rate(struct owl_clk_common *common, + const struct owl_divider_hw *div_hw, + unsigned long parent_rate) +{ + unsigned long val; + unsigned int reg; + + regmap_read(common->regmap, div_hw->reg, ®); + val = reg >> div_hw->shift; + val &= (1 << div_hw->width) - 1; + + return divider_recalc_rate(&common->hw, parent_rate, + val, div_hw->table, + div_hw->div_flags, + div_hw->width); +} + +static unsigned long owl_divider_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct owl_divider *div = hw_to_owl_divider(hw); + + return owl_divider_helper_recalc_rate(&div->common, + &div->div_hw, parent_rate); +} + +int owl_divider_helper_set_rate(const struct owl_clk_common *common, + const struct owl_divider_hw *div_hw, + unsigned long rate, + unsigned long parent_rate) +{ + unsigned long val; + unsigned int reg; + + val = divider_get_val(rate, parent_rate, div_hw->table, + div_hw->width, 0); + + regmap_read(common->regmap, div_hw->reg, ®); + reg &= ~GENMASK(div_hw->width + div_hw->shift - 1, div_hw->shift); + + regmap_write(common->regmap, div_hw->reg, + reg | (val << div_hw->shift)); + + return 0; +} + +static int owl_divider_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct owl_divider *div = hw_to_owl_divider(hw); + + return owl_divider_helper_set_rate(&div->common, &div->div_hw, + rate, parent_rate); +} + +const struct clk_ops owl_divider_ops = { + .recalc_rate = owl_divider_recalc_rate, + .round_rate = owl_divider_round_rate, + .set_rate = owl_divider_set_rate, +}; diff --git a/drivers/clk/actions/owl-divider.h b/drivers/clk/actions/owl-divider.h new file mode 100644 index 000000000000..92d3e3d23967 --- /dev/null +++ b/drivers/clk/actions/owl-divider.h @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0+ +// +// OWL divider clock driver +// +// Copyright (c) 2014 Actions Semi Inc. +// Author: David Liu +// +// Copyright (c) 2018 Linaro Ltd. +// Author: Manivannan Sadhasivam + +#ifndef _OWL_DIVIDER_H_ +#define _OWL_DIVIDER_H_ + +#include "owl-common.h" + +struct owl_divider_hw { + u32 reg; + u8 shift; + u8 width; + u8 div_flags; + struct clk_div_table *table; +}; + +struct owl_divider { + struct owl_divider_hw div_hw; + struct owl_clk_common common; +}; + +#define OWL_DIVIDER_HW(_reg, _shift, _width, _div_flags, _table) \ + { \ + .reg = _reg, \ + .shift = _shift, \ + .width = _width, \ + .div_flags = _div_flags, \ + .table = _table, \ + } + +#define OWL_DIVIDER(_struct, _name, _parent, _reg, \ + _shift, _width, _table, _div_flags, _flags) \ + struct owl_divider _struct = { \ + .div_hw = OWL_DIVIDER_HW(_reg, _shift, _width, \ + _div_flags, _table), \ + .common = { \ + .regmap = NULL, \ + .hw.init = CLK_HW_INIT(_name, \ + _parent, \ + &owl_divider_ops, \ + _flags), \ + }, \ + } + +static inline struct owl_divider *hw_to_owl_divider(const struct clk_hw *hw) +{ + struct owl_clk_common *common = hw_to_owl_clk_common(hw); + + return container_of(common, struct owl_divider, common); +} + +long owl_divider_helper_round_rate(struct owl_clk_common *common, + const struct owl_divider_hw *div_hw, + unsigned long rate, + unsigned long *parent_rate); + +unsigned long owl_divider_helper_recalc_rate(struct owl_clk_common *common, + const struct owl_divider_hw *div_hw, + unsigned long parent_rate); + +int owl_divider_helper_set_rate(const struct owl_clk_common *common, + const struct owl_divider_hw *div_hw, + unsigned long rate, + unsigned long parent_rate); + +extern const struct clk_ops owl_divider_ops; + +#endif /* _OWL_DIVIDER_H_ */