LKML Archive on lore.kernel.org help / color / mirror / Atom feed
From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> 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 <manivannan.sadhasivam@linaro.org> Subject: [PATCH v5 09/12] clk: actions: Add fixed factor clock support Date: Sat, 17 Mar 2018 15:39:49 +0530 [thread overview] Message-ID: <20180317100952.28538-10-manivannan.sadhasivam@linaro.org> (raw) In-Reply-To: <20180317100952.28538-1-manivannan.sadhasivam@linaro.org> Add support for Actions Semi fixed factor clock together with helper functions to be used in composite clock. Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> --- 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 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 <liuwei@actions-semi.com> +// +// Copyright (c) 2018 Linaro Ltd. +// Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> + +#include <linux/clk-provider.h> +#include <linux/regmap.h> +#include <linux/slab.h> + +#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 <liuwei@actions-semi.com> +// +// Copyright (c) 2018 Linaro Ltd. +// Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> + +#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_ */ -- 2.14.1
next prev parent reply other threads:[~2018-03-17 10:12 UTC|newest] Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-03-17 10:09 [PATCH v5 00/12] Add clock driver for Actions S900 SoC Manivannan Sadhasivam 2018-03-17 10:09 ` [PATCH v5 01/12] dt-bindings: clock: Add Actions S900 clock bindings Manivannan Sadhasivam 2018-03-20 0:59 ` Stephen Boyd 2018-03-17 10:09 ` [PATCH v5 02/12] arm64: dts: actions: Add S900 clock management unit nodes Manivannan Sadhasivam 2018-03-17 10:09 ` [PATCH v5 03/12] arm64: dts: actions: Source CMU clock for UART5 Manivannan Sadhasivam 2018-03-17 10:09 ` [PATCH v5 04/12] clk: actions: Add common clock driver support Manivannan Sadhasivam 2018-03-20 1:02 ` Stephen Boyd 2018-03-17 10:09 ` [PATCH v5 05/12] clk: actions: Add gate clock support Manivannan Sadhasivam 2018-03-20 1:04 ` Stephen Boyd 2018-03-17 10:09 ` [PATCH v5 06/12] clk: actions: Add mux " Manivannan Sadhasivam 2018-03-20 1:05 ` Stephen Boyd 2018-03-17 10:09 ` [PATCH v5 07/12] clk: actions: Add divider " Manivannan Sadhasivam 2018-03-20 1:06 ` Stephen Boyd 2018-03-17 10:09 ` [PATCH v5 08/12] clk: actions: Add factor " Manivannan Sadhasivam 2018-03-18 20:31 ` kbuild test robot 2018-03-20 1:08 ` Stephen Boyd 2018-03-20 1:11 ` Stephen Boyd 2018-03-20 1:41 ` kbuild test robot 2018-03-17 10:09 ` Manivannan Sadhasivam [this message] 2018-03-20 1:10 ` [PATCH v5 09/12] clk: actions: Add fixed " Stephen Boyd 2018-03-20 9:04 ` Manivannan Sadhasivam 2018-03-20 17:15 ` Stephen Boyd 2018-03-17 10:09 ` [PATCH v5 10/12] clk: actions: Add composite " Manivannan Sadhasivam 2018-03-17 10:09 ` [PATCH v5 11/12] clk: actions: Add pll " Manivannan Sadhasivam 2018-03-17 10:09 ` [PATCH v5 12/12] clk: actions: Add S900 SoC " Manivannan Sadhasivam 2018-03-18 20:38 ` kbuild test robot 2018-03-18 21:28 ` kbuild test robot 2018-03-20 7:16 ` Stephen Boyd
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180317100952.28538-10-manivannan.sadhasivam@linaro.org \ --to=manivannan.sadhasivam@linaro.org \ --cc=96boards@ucrobotics.com \ --cc=afaerber@suse.de \ --cc=amit.kucheria@linaro.org \ --cc=bdong@ucrobotics.com \ --cc=daniel.thompson@linaro.org \ --cc=davem@davemloft.net \ --cc=devicetree@vger.kernel.org \ --cc=hzhang@ucrobotics.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-clk@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=liuwei@actions-semi.com \ --cc=manivannanece23@gmail.com \ --cc=mark.rutland@arm.com \ --cc=mchehab@kernel.org \ --cc=mp-cs@actions-semi.com \ --cc=mturquette@baylibre.com \ --cc=robh+dt@kernel.org \ --cc=sboyd@kernel.org \ --cc=viresh.kumar@linaro.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).