From patchwork Mon Sep 24 10:39:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 10612229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61CA6161F for ; Mon, 24 Sep 2018 10:42:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5346F29CD4 for ; Mon, 24 Sep 2018 10:42:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45C1A29CE1; Mon, 24 Sep 2018 10:42:38 +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=-2.9 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE 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 9AD4229CD4 for ; Mon, 24 Sep 2018 10:42:37 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=RkYdMzOYark6RXLcGc1FUg+bMtVi4YICV8TWrnGrHv4=; b=tZAqWddXo2tzxj kTw8Uv+y2M+rz+w4lJp00Cub6lPgO0GzxdJsBuluC8lXVRtgF6A7Wsqp/up7gkVj94mOEgIXWE30a wLvPA9cRVfZHIFWLPuN2haOefgCfHxHnqNS8gla/FZO2OdvPRH8q5jlycKtgHxGdzxLirF/Gsa5O7 UMacd2dCV+XuauNFg/2bHsoJqWSvySDbQgtLSWwzi5ofpB+mxrOjRgGonUhsvbbc598gNFbjH2eM3 eDcxnQfGU46vzZBXDP5TIJePxnmwPcqvuryOpBmLfXtpI6tsqW+p3lmFoHoIGO+NocRNZccrqFdGC W2v4I0dAoQhGc0GfexpQ==; 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 1g4OJv-00044Z-Dn; Mon, 24 Sep 2018 10:42:27 +0000 Received: from mail-ve1eur03on0614.outbound.protection.outlook.com ([2a01:111:f400:fe09::614] helo=EUR03-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g4OIf-0003W8-HD for linux-arm-kernel@lists.infradead.org; Mon, 24 Sep 2018 10:41:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=slBA9PFtR5weZ6Q+vyULpdbIoS5mfGSDNDiCKxldOJE=; b=TIpptwUAeTM7kSrSu5tELnIm8LpKHWKL0SBA4YB1iXXE3z8x3BLzj0cWiQ+v/rxrLszD/f3uQc68zas0/5+KB+DkFHgxVQlVMWx4pTw0x5qm+adHGnaAf9vzJzFWN6r9aLbEHgjyPni/KWmxT/xYZqmC0HD8QiPRI3cqkHHpjeY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=abel.vesa@nxp.com; Received: from fsr-ub1664-175.ea.freescale.net (95.76.156.53) by VI1PR04MB1616.eurprd04.prod.outlook.com (2a01:111:e400:596b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1164.22; Mon, 24 Sep 2018 10:40:48 +0000 From: Abel Vesa To: Lucas Stach , Sascha Hauer , Dong Aisheng , Fabio Estevam , Anson Huang , Andrey Smirnov , Rob Herring Subject: [PATCH v9 4/5] clk: imx: add imx composite clock Date: Mon, 24 Sep 2018 13:39:56 +0300 Message-Id: <1537785597-26499-5-git-send-email-abel.vesa@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537785597-26499-1-git-send-email-abel.vesa@nxp.com> References: <1537785597-26499-1-git-send-email-abel.vesa@nxp.com> MIME-Version: 1.0 X-Originating-IP: [95.76.156.53] X-ClientProxiedBy: VI1PR0102CA0003.eurprd01.prod.exchangelabs.com (2603:10a6:802::16) To VI1PR04MB1616.eurprd04.prod.outlook.com (2a01:111:e400:596b::22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 60ea690f-038e-4050-88c5-08d6220a3114 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:VI1PR04MB1616; X-Microsoft-Exchange-Diagnostics: 1; VI1PR04MB1616; 3:9H9V3Kdlma6VNdtlMg4slJkG1nnXPNyyqN2o7u79znL875JGQhEY3ErAz97+oaOkgbJRpkFdq9kuY5aqC1sMuNxHVaiIkCzAn896xHZr6FReGe8iqjrYfQSn+XsrXIFnFBKbzeWqpuqMGyDMka8JgGrTYsjTzFvmnQqmuticruemoemFsNHcYaNG3mJdLRjnGk7dtWEVmmb81m9I5FH3sKNuf2fSnw498WkLz04d+YpdpiwBg+FvF9jK9MIgLQbp; 25:9yiCOi7P5d1mZ++v5yMNmhlmiDyroQasWX/NyJ/9JoFJNNPuU/aa6x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J9SwcgaSeNjq0QJDqpVk; 4:eaAQu+R/qWXIBkODHwXsN7kM4XMxseNQMwOYF7pFf25b892DKLfMrjnVyqyJV5/1cuPaY7GXP+bgOyWm3nrMpRpoqzXCHMfv2cpE6VH/E0dTnmb4gofynB4sjP/iSz3z/+Jlj/hzj4Nn79N2qiZ9Bw8SJ9w5QsrtiMIrfVWzLEilsojkXiIkZKLcByjBfZ0rBr6TdhcIMrE9FDWhy4pyOa39drDllj1+bDcGUaYjY93AiTLpaTi+nRmYKUYKzPQdxpQ7bNI69Y9Nu4zSRLU+8WuOE6qCIKjTIAlj0l1ruRNzTFgdvjbTI2MTy/rInCKn X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231355)(944501410)(52105095)(10201501046)(3002001)(6055026)(149066)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201708071742011)(7699051); SRVR:VI1PR04MB1616; BCL:0; PCL:0; RULEID:; SRVR:VI1PR04MB1616; X-Forefront-PRVS: 0805EC9467 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(396003)(39860400002)(366004)(136003)(346002)(376002)(199004)(189003)(52116002)(51416003)(14444005)(48376002)(50466002)(36756003)(76176011)(53936002)(6506007)(478600001)(44832011)(4326008)(6486002)(6512007)(25786009)(26005)(186003)(16526019)(386003)(11346002)(446003)(486006)(476003)(2616005)(956004)(8936002)(50226002)(2906002)(68736007)(81156014)(7416002)(81166006)(575784001)(8676002)(47776003)(66066001)(105586002)(6116002)(3846002)(305945005)(106356001)(97736004)(5660300001)(39060400002)(110136005)(6666003)(54906003)(316002)(86362001)(16586007)(7736002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR04MB1616; H:fsr-ub1664-175.ea.freescale.net; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR04MB1616; 23:zuq4tTFAPSVUVwBwm7nfkYcfWZ8ujc++EWidB2gJs?= YyrBLN6rL5pJfNwxmfsnNljNn+HR8/YsNzbsmheC6/7sziiby0uCqjveA+Bjf0EC+YCdvR8Dn5RXIBnCjBGUZNBE30KKHWbENwY7IzDYy6KGTnTGzxVOKlSftxN2fMPTFCuebqRwX3QbQBnihhqODMpdxESqHVcUtQNiExUdDnM1XtFcdMemjbvjcQnDrPeyhwjp0MWSn5Jd2MxJgixVYn+l6CgpkQgtOTgxvbpnGKBQvdkCpEvVzjkwHfq3qUQiX63rHvOTbRU1s0Ad1QmozBBp+bnm+XYE0TA4G34Gv6EDlYglgvH2tO/efawUQ29xKnwrRmeI6rPSygoATV7Bo+GtVIssdfrKN/q4HONzMkFJlCS/3ljgfFOoSxd95iQjdU2k0MyCiofMcNsUnMXzJYXKiGKaImBXYuLWdq/SBobGcSFSfjbtSpI24DAgn8LBGHIzP0jdK4gQoH2WBG7bfoJgZ75Y7mXgxnZinVzH5qiRcTgu++DtVuXE9Nc1MYtYPubCLUBOrpVwAkURGGYIGtGGIbjQ6J8MGu3gYs6o+mmldIDgbJvNAPwPAFp4iHQ/2fY2MK9o2J1FSZdjKnuKka3deuCJBiwMaC2AsTfl25Bpm+T0F/hzyfSNpBL6nweMl/YG3BYjGqMobajq/pNP63H3FFNVWC6Hp2L1gUtEea/bsdqfO+FRnVLdyDI9UNUw1IyMYX044qD7IaLUxNbiBcy66hltp1IomMu2PhiYDC41wJxKbJi4kiOQfp8GS0IILzxki0uQsM4w5QNYN/m/GaB0mdXlwtEdt74SNvX3fpI52UaIjzcxO+INaafD4tulTvqgT4+G4cV0aoqMEeOqOYu6kNP8mqPH+WRYVE7V7BEbUCnh6t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SQq1c6yotreTyz8D0xHZkHJt0JYR44QcLY3WfW+FpnHYEUn8Sy0dFk+w8hUTq+WhEJhxVXS0e9AumJUsA1TZ/rBibxnQk8QXyaSQkgbYvtqF6yTo2Ga602f5P1Fu41N87jlK6khmxFHa/vijGvrvCct0y4/FkGGTbi3OgPbar1uei4DTevei4rnHN+qOEErA==; 5:xje7i6iyWf/1ofrMqYgcvdVYPU6hapN3hXHzDrchrJqrt07hFu9D3ELcJzMc8DXN2mgPDwJBfHpx+1VnZ5YbYx+vb91g1KzgoJDYtb3DkkpTDLo0FeuDsqbLb+Rc4ag02Q4zxXWvKM1h/p1DhFT6wfsQDC/8404OOBaP/NwrFW4=; 7:/BPR/jDYf8i3IIcrpwLgp1pPi28U6xgd9TbBLvpbDKV6eJEYPk6ymPgrcJa3gpDRGGlIbxIcNsAhQk9NEwT7f3IPqdhFoL+lAKbHqi7xpQvfbpAcoAcdMn59X4L0VwYbfHrIYuhHTgOieVgonsJXVh0LtbQgzDZS3t+5BRw1lztgUx2LzCPPD4tHV+hJn1kJygX46eblJ+McGPwF2dCXJGdNdEpU8VNlt6MGquSbwTESvvWEiCQpHEZ7d5P35dne SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2018 10:40:48.1084 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 60ea690f-038e-4050-88c5-08d6220a3114 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB1616 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180924_034109_774390_E01EA4E2 X-CRM114-Status: GOOD ( 17.24 ) 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: Abel Vesa , Stephen Boyd , Michael Turquette , open list , "open list:COMMON CLK FRAMEWORK" , Abel Vesa , linux-imx@nxp.com, Shawn Guo , Sascha Hauer , "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" 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 Since a lot of clocks on imx8 are formed by a mux, gate, predivider and divider, the idea here is to combine all of those into one composite clock, but we need to deal with both predivider and divider at the same time and therefore we add the imx_clk_composite_divider_ops and register the composite clock with those. Signed-off-by: Abel Vesa Suggested-by: Sascha Hauer --- drivers/clk/imx/Makefile | 1 + drivers/clk/imx/clk-composite.c | 181 ++++++++++++++++++++++++++++++++++++++++ drivers/clk/imx/clk.h | 14 ++++ 3 files changed, 196 insertions(+) create mode 100644 drivers/clk/imx/clk-composite.c diff --git a/drivers/clk/imx/Makefile b/drivers/clk/imx/Makefile index b87513c..4fabb0a 100644 --- a/drivers/clk/imx/Makefile +++ b/drivers/clk/imx/Makefile @@ -3,6 +3,7 @@ obj-y += \ clk.o \ clk-busy.o \ + clk-composite.o \ clk-cpu.o \ clk-fixup-div.o \ clk-fixup-mux.o \ diff --git a/drivers/clk/imx/clk-composite.c b/drivers/clk/imx/clk-composite.c new file mode 100644 index 0000000..4b03107 --- /dev/null +++ b/drivers/clk/imx/clk-composite.c @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2018 NXP + */ + +#include +#include +#include +#include + +#include "clk.h" + +#define PCG_PREDIV_SHIFT 16 +#define PCG_PREDIV_WIDTH 3 +#define PCG_PREDIV_MAX 8 + +#define PCG_DIV_SHIFT 0 +#define PCG_DIV_WIDTH 6 +#define PCG_DIV_MAX 64 + +#define PCG_PCS_SHIFT 24 +#define PCG_PCS_MASK 0x7 + +#define PCG_CGC_SHIFT 28 + +static unsigned long imx_clk_composite_divider_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct clk_divider *divider = to_clk_divider(hw); + unsigned long prediv_rate; + unsigned int prediv_value; + unsigned int div_value; + + prediv_value = clk_readl(divider->reg) >> divider->shift; + prediv_value &= clk_div_mask(divider->width); + + prediv_rate = divider_recalc_rate(hw, parent_rate, prediv_value, + NULL, divider->flags, + divider->width); + + div_value = clk_readl(divider->reg) >> PCG_DIV_SHIFT; + div_value &= clk_div_mask(PCG_DIV_WIDTH); + + return divider_recalc_rate(hw, prediv_rate, div_value, NULL, + divider->flags, PCG_DIV_WIDTH); +} + +static int imx_clk_composite_compute_dividers(unsigned long rate, + unsigned long parent_rate, + int *prediv, int *postdiv) +{ + int div1, div2; + int error = INT_MAX; + int ret = -EINVAL; + + /* default values */ + *prediv = 1; + *postdiv = 1; + + for (div1 = 1; div1 <= PCG_PREDIV_MAX; div1++) { + for (div2 = 1; div2 <= PCG_DIV_MAX; div2++) { + int new_error = ((parent_rate / div1) / div2) - rate; + + if (abs(new_error) < abs(error)) { + *prediv = div1; + *postdiv = div2; + error = new_error; + ret = 0; + } + } + } + return ret; +} + +static long imx_clk_composite_divider_round_rate(struct clk_hw *hw, + unsigned long rate, + unsigned long *prate) +{ + int prediv_value; + int div_value; + + imx_clk_composite_compute_dividers(rate, *prate, + &prediv_value, &div_value); + + rate = DIV_ROUND_UP_ULL((u64)*prate, prediv_value); + rate = DIV_ROUND_UP_ULL((u64)rate, div_value); + + return rate; +} + +static int imx_clk_composite_divider_set_rate(struct clk_hw *hw, + unsigned long rate, + unsigned long parent_rate) +{ + struct clk_divider *divider = to_clk_divider(hw); + unsigned long flags = 0; + int prediv_value; + int div_value; + int ret = 0; + u32 val; + + ret = imx_clk_composite_compute_dividers(rate, parent_rate, + &prediv_value, &div_value); + if (ret) + return -EINVAL; + + spin_lock_irqsave(divider->lock, flags); + + val = clk_readl(divider->reg); + val &= ~((clk_div_mask(divider->width) << divider->shift) | + (clk_div_mask(PCG_DIV_WIDTH) << PCG_DIV_SHIFT)); + + val |= (u32)(prediv_value - 1) << divider->shift; + val |= (u32)(div_value - 1) << PCG_DIV_SHIFT; + clk_writel(val, divider->reg); + + spin_unlock_irqrestore(divider->lock, flags); + + return ret; +} + +static const struct clk_ops imx_clk_composite_divider_ops = { + .recalc_rate = imx_clk_composite_divider_recalc_rate, + .round_rate = imx_clk_composite_divider_round_rate, + .set_rate = imx_clk_composite_divider_set_rate, +}; + +struct clk *imx_clk_composite_flags(const char *name, + const char **parent_names, + int num_parents, void __iomem *reg, + unsigned long flags) +{ + struct clk_hw *mux_hw = NULL, *div_hw = NULL, *gate_hw = NULL; + struct clk_divider *div = NULL; + struct clk_gate *gate = NULL; + struct clk_mux *mux = NULL; + struct clk *clk = ERR_PTR(-ENOMEM); + + mux = kzalloc(sizeof(*mux), GFP_KERNEL); + if (!mux) + goto fail; + + mux_hw = &mux->hw; + mux->reg = reg; + mux->shift = PCG_PCS_SHIFT; + mux->mask = PCG_PCS_MASK; + + div = kzalloc(sizeof(*div), GFP_KERNEL); + if (!div) + goto fail; + + div_hw = &div->hw; + div->reg = reg; + div->shift = PCG_PREDIV_SHIFT; + div->width = PCG_PREDIV_WIDTH; + div->lock = &imx_ccm_lock; + div->flags = CLK_DIVIDER_ROUND_CLOSEST; + + gate = kzalloc(sizeof(*gate), GFP_KERNEL); + if (!gate) + goto fail; + + gate_hw = &gate->hw; + gate->reg = reg; + gate->bit_idx = PCG_CGC_SHIFT; + + clk = clk_register_composite(NULL, name, parent_names, num_parents, + mux_hw, &clk_mux_ops, div_hw, + &imx_clk_composite_divider_ops, gate_hw, + &clk_gate_ops, flags); + if (IS_ERR(clk)) + goto fail; + + return clk; + +fail: + kfree(gate); + kfree(div); + kfree(mux); + return clk; +} diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index 12b3fd6..9d7c9c8 100644 --- a/drivers/clk/imx/clk.h +++ b/drivers/clk/imx/clk.h @@ -232,4 +232,18 @@ struct clk *imx_clk_cpu(const char *name, const char *parent_name, struct clk *div, struct clk *mux, struct clk *pll, struct clk *step); +struct clk *imx_clk_composite_flags(const char *name, const char **parent_names, + int num_parents, void __iomem *reg, unsigned long flags); + +#define __imx_clk_composite(name, parent_names, reg, flags) \ + imx_clk_composite_flags(name, parent_names, \ + ARRAY_SIZE(parent_names), reg, \ + flags | CLK_SET_RATE_NO_REPARENT | CLK_OPS_PARENT_ENABLE) + +#define imx_clk_composite(name, parent_names, reg) \ + __imx_clk_composite(name, parent_names, reg, 0) + +#define imx_clk_composite_critical(name, parent_names, reg) \ + __imx_clk_composite(name, parent_names, reg, CLK_IS_CRITICAL) + #endif