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: 10290709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 51459601BE for ; Sat, 17 Mar 2018 10:18:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3679029077 for ; Sat, 17 Mar 2018 10:17:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B1DE290A2; Sat, 17 Mar 2018 10:17:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7502229077 for ; Sat, 17 Mar 2018 10:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=4RfVJCa1lYurCSo44mEifDzZW9w9uhDqV7CPcaDBOto=; b=AOBr6pmsOorUfoiNXlAkQGHjAT xuI7Lc4oZP1WlboJ2MAd2HWrs4SMK1MB2xUGeMAHR2Yd7X7eCJxrLKojsvKHrNFiyPegJ2xtjYypP wUbekOhysLWFpPDSjJ2q64oHThnkqLkHXKlmbDwYN3urOlOdNIfGFgkBbEEuDSGrl9cXnF8AFG1g3 crz4mgJC2N7H0z3Du4NyVmgnG0cWAw3yw1c/Vl3n+yjOv6cfPSxdM3ivFy/AOA3tLprkrV+s5So8r BmKE6RlJEiSarbIDU8LAXqBoCi7rkPxYIUyIZfJ0qcmx4Iyvhxu82tcQX2HiGxrP3mrzP60EwJttA IAE1mhmQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ex8sy-0001Px-LP; Sat, 17 Mar 2018 10:16:24 +0000 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ex8p1-0006WI-SN for linux-arm-kernel@lists.infradead.org; Sat, 17 Mar 2018 10:13:17 +0000 Received: by mail-pg0-x242.google.com with SMTP id n11so342569pgp.4 for ; Sat, 17 Mar 2018 03:12:09 -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=C0JDFhDiVOubCrq8QzifMFdA1hKaJwGjD5YY/i/IHf4pPJVtdmxHD3OJ24WFKRvdRQ 84OVVhX0vGDJSvbTUjKnwl6qhF4bYV3ypSjRiKM8nHYgWAIuWMovfMg0bla7/4N4a430 a9kk4bVMk/Nsh9JymkgqALlcMcpBxWXS0/utYvYi6o12kR/FHOvhBuKuivyF+oyqhVov GYjG/pwXhv1RXZXcU5EzBSqZ4My4v9CuhP/A49tRjp54o/CpEOiiprvCmnmrze2StOyz u3cSDLDMkT7b6wFTqxkU+28becgJmNWraoufFc6QiLCUSm01KHREEtpx2JkZ/kkZpamP WtUg== X-Gm-Message-State: AElRT7F0YCoBUo1n9CDSLQ6soPUkMcGF+sxsz25MLUescDCQTbBigY8d ZW0dc18wxf+eaED3gn0WL2d1momUXQ== X-Google-Smtp-Source: AG47ELvyv+sNMtJEBT81QKMCakn5B7aTmbaMDGgIi72YXOT9FLWCEX1iGU9fSft1aCkdaAHHwBCj6A== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180317_031220_767280_D8BD761D X-CRM114-Status: GOOD ( 16.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, daniel.thompson@linaro.org, manivannanece23@gmail.com, viresh.kumar@linaro.org, bdong@ucrobotics.com, liuwei@actions-semi.com, linux-kernel@vger.kernel.org, amit.kucheria@linaro.org, linux-clk@vger.kernel.org, hzhang@ucrobotics.com, mp-cs@actions-semi.com, 96boards@ucrobotics.com, mchehab@kernel.org, Manivannan Sadhasivam , davem@davemloft.net, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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_ */