From patchwork Sat Mar 17 10:09:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 131967 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp490370ljb; Sat, 17 Mar 2018 03:12:12 -0700 (PDT) X-Google-Smtp-Source: AG47ELvV0snzqJ7IQ81YIlJpAnDV5zS9AA4FqItKIDtBfru3GCJIsG3CBXwcsoDaJ0/MucsSczOp X-Received: by 10.99.124.25 with SMTP id x25mr4140532pgc.46.1521281532687; Sat, 17 Mar 2018 03:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521281532; cv=none; d=google.com; s=arc-20160816; b=k1XYpN2zIkOvleANicg1HGPr1taQXBeclSRAjgzXGNJMOGDvQ1zyRbvudJLkp8g2VA zoZt8QIFxGAmqfQ9W9HLsqbFvCiSTmCtgKGpA4l4HNVLXd0V41/uVQNpkPnDvBpqf9ve RU1y18aw4tCL1uxSkyKL1IFD3jfzkS/jwSXSBwDzJRMQCyom8yNWx8r95PM0aCV9qhb8 iGh2N4Ug7tgMWo3hVnD7fV9Z6DyBBSCx7w7fewVPE19Bg9cEAgTsSB6wEyT3Pj04JaKV /CeXP6OyViuPIlVNuE7h2MPr7jwUtWEPRdtqXMumFkPJ0K3vlSccNS5prWD3Uoq1pap4 QPeA== 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=wgb/NyrUQmzPHhPRwb14h88YImflVBaaFOuMqV7J9NQ=; b=zXYD8dcfmBKf64pTqy+AK3xdmxE1kjhkZRb7Wi3bxDdxyALQt/JF7Mp7vIh0N7cRwr FNCZJVlHt5+TX2WETU/U8UOdcA41wJyPFEu+1Zp1ayoK/cAJ1/IYuJSSn5dnCeCQALZ8 3kAKGHFu1KG5Hul9pBcl4PtCeI2R/LP7qyqKnozbnHA9XBr5B9FXsDjgL/G9WEZ/JfHd r2cqsn3gAXeo/Mou5aqUMkOetyZXLSmOVUa+Us62KhwWsxauysPtFOs/ZOBfCd3leSlu cnD7KMqaos/HJ1DvkMKYAZzpvEoyhq2hFI3D7T5QQNqKjhp/a0pXFfFYbm+x/Zqladkw g+8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FpiazzG3; 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 c15si7137320pfm.199.2018.03.17.03.12.12; Sat, 17 Mar 2018 03:12:12 -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=FpiazzG3; 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 S1752798AbeCQKMK (ORCPT + 6 others); Sat, 17 Mar 2018 06:12:10 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:45441 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752808AbeCQKMJ (ORCPT ); Sat, 17 Mar 2018 06:12:09 -0400 Received: by mail-pg0-f68.google.com with SMTP id s13so5056376pgn.12 for ; Sat, 17 Mar 2018 03:12:08 -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=nJPoXNzIdzLpvgdLZr8MDm8UjE8xePTrl1+77SJeenw=; b=FpiazzG3aNC10g7aMhF8rGFetYxMECk7a3bOmDBuNDJCr+ncaZsZNtAAZ8WDanEbAK 2T7lePy4yULRHGlpWQkEdp4ZDcH4Ntywi3rOGzihY7Q37NCjb6dw4i/jk8JzUMxFzYLm yFmPuVMFSHo3nREwO4WZ3Oos3v+w5kOJuql2g= 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=nJPoXNzIdzLpvgdLZr8MDm8UjE8xePTrl1+77SJeenw=; b=tjdWcbUY9DU8zu/jFD/64+NCug+HDe9g1wjwDj0EQj91P/8jQ0a29f6X+u444z2Ugr xIMovc7CUoXeXehX2ybBC+Qg0qJ7mc7SvTBUiAR/xHgmN85PWeyNIPGBEUbqHH1aoA9k jsi7vxwJzsVtKvxx2mrSisJrZ96nDLXQpwUFo2XWxMs0ubZrEbbPPWIk8+8cpIsuEJOu w+2HMi3X5bwDPg70kgm2Tg0PRyNNWaapojWknRfDUa/4UJfu1LAAxCRopN7o2HohCJ18 9z8n4Kg7d+56GNs3euz0m225Pjy0PtEuqi8y+LohqqywAYZUrIb+dX9iToC5hwNM//rh JsEA== X-Gm-Message-State: AElRT7Ek8V+LZf3oSrN6kMXLVn2ShPlzIcTvQHLrA5V2YYA2O1OW7hz1 tnGgWhug2plG6Bp5G0TtMsqI X-Received: by 10.99.55.70 with SMTP id g6mr4016229pgn.284.1521281528450; Sat, 17 Mar 2018 03:12:08 -0700 (PDT) Received: from mani-Aspire-E5-573.domain.name ([171.49.203.57]) by smtp.gmail.com with ESMTPSA id i27sm3771625pfj.123.2018.03.17.03.12.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Mar 2018 03:12:07 -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 v5 09/12] clk: actions: Add fixed factor clock support Date: Sat, 17 Mar 2018 15:39:49 +0530 Message-Id: <20180317100952.28538-10-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180317100952.28538-1-manivannan.sadhasivam@linaro.org> References: <20180317100952.28538-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 fixed factor 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-fixed-factor.c | 81 ++++++++++++++++++++++++++++++++++ drivers/clk/actions/owl-fixed-factor.h | 62 ++++++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 drivers/clk/actions/owl-fixed-factor.c create mode 100644 drivers/clk/actions/owl-fixed-factor.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 994357fa560b..b618696ba54e 100644 --- a/drivers/clk/actions/Makefile +++ b/drivers/clk/actions/Makefile @@ -5,3 +5,4 @@ clk-owl-y += owl-gate.o clk-owl-y += owl-mux.o clk-owl-y += owl-divider.o clk-owl-y += owl-factor.o +clk-owl-y += owl-fixed-factor.o diff --git a/drivers/clk/actions/owl-fixed-factor.c b/drivers/clk/actions/owl-fixed-factor.c new file mode 100644 index 000000000000..f1281565129c --- /dev/null +++ b/drivers/clk/actions/owl-fixed-factor.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0+ +// +// OWL fixed factor clock driver +// +// Copyright (c) 2014 Actions Semi Inc. +// Author: David Liu +// +// Copyright (c) 2018 Linaro Ltd. +// Author: Manivannan Sadhasivam + +#include +#include +#include + +#include "owl-fixed-factor.h" + +long owl_fix_fact_helper_round_rate(struct owl_clk_common *common, + const struct owl_fix_fact_hw *fix_fact_hw, + unsigned long rate, + unsigned long *parent_rate) +{ + if (clk_hw_get_flags(&common->hw) & CLK_SET_RATE_PARENT) { + unsigned long best_parent; + + best_parent = (rate / fix_fact_hw->mul) * fix_fact_hw->div; + *parent_rate = clk_hw_round_rate(clk_hw_get_parent(&common->hw), + best_parent); + } + + return (*parent_rate / fix_fact_hw->div) * fix_fact_hw->mul; +} + +static long owl_fix_fact_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *parent_rate) +{ + struct owl_fix_fact *fix_fact = hw_to_owl_fix_fact(hw); + struct owl_fix_fact_hw *fix_fact_hw = &fix_fact->fix_fact_hw; + + return owl_fix_fact_helper_round_rate(&fix_fact->common, fix_fact_hw, + rate, parent_rate); +} + +unsigned long owl_fix_fact_helper_recalc_rate(struct owl_clk_common *common, + const struct owl_fix_fact_hw *fix_fact_hw, + unsigned long parent_rate) +{ + unsigned long long int rate; + + rate = (unsigned long long int)parent_rate * fix_fact_hw->mul; + do_div(rate, fix_fact_hw->div); + + return (unsigned long)rate; +} + +static unsigned long owl_fix_fact_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct owl_fix_fact *fix_fact = hw_to_owl_fix_fact(hw); + struct owl_fix_fact_hw *fix_fact_hw = &fix_fact->fix_fact_hw; + + return owl_fix_fact_helper_recalc_rate(&fix_fact->common, fix_fact_hw, + parent_rate); +} + +static int owl_fix_fact_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + /* + * We must report success but we can do so unconditionally because + * clk_fix_fact_round_rate returns values that ensure this call is a + * nop. + */ + + return 0; +} + +const struct clk_ops owl_fix_fact_ops = { + .round_rate = owl_fix_fact_round_rate, + .recalc_rate = owl_fix_fact_recalc_rate, + .set_rate = owl_fix_fact_set_rate, +}; diff --git a/drivers/clk/actions/owl-fixed-factor.h b/drivers/clk/actions/owl-fixed-factor.h new file mode 100644 index 000000000000..665dadef8738 --- /dev/null +++ b/drivers/clk/actions/owl-fixed-factor.h @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0+ +// +// OWL fixed factor clock driver +// +// Copyright (c) 2014 Actions Semi Inc. +// Author: David Liu +// +// Copyright (c) 2018 Linaro Ltd. +// Author: Manivannan Sadhasivam + +#ifndef _OWL_FIXED_FACTOR_H_ +#define _OWL_FIXED_FACTOR_H_ + +#include "owl-common.h" + +struct owl_fix_fact_hw { + unsigned int mul; + unsigned int div; +}; + +struct owl_fix_fact { + struct owl_fix_fact_hw fix_fact_hw; + struct owl_clk_common common; +}; + +#define OWL_FIX_FACT_HW(_mul, _div) \ + { \ + .mul = _mul, \ + .div = _div, \ + } + +#define OWL_FIX_FACT(_struct, _name, _parent, _mul, _div, _flags) \ + struct owl_fix_fact _struct = { \ + .fix_fact_hw = OWL_FIX_FACT_HW(_mul, _div), \ + .common = { \ + .regmap = NULL, \ + .hw.init = CLK_HW_INIT(_name, \ + _parent, \ + &owl_fix_fact_ops,\ + _flags), \ + }, \ + } + +static inline struct owl_fix_fact *hw_to_owl_fix_fact(const struct clk_hw *hw) +{ + struct owl_clk_common *common = hw_to_owl_clk_common(hw); + + return container_of(common, struct owl_fix_fact, common); +} + +long owl_fix_fact_helper_round_rate(struct owl_clk_common *common, + const struct owl_fix_fact_hw *fix_fact_hw, + unsigned long rate, + unsigned long *parent_rate); + +unsigned long owl_fix_fact_helper_recalc_rate(struct owl_clk_common *common, + const struct owl_fix_fact_hw *fix_fact_hw, + unsigned long parent_rate); + +extern const struct clk_ops owl_fix_fact_ops; + +#endif /* _OWL_FIXED_FACTOR_H_ */