From patchwork Mon Sep 24 10:39:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 10612219 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 D192C13A4 for ; Mon, 24 Sep 2018 10:41:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B572129CD4 for ; Mon, 24 Sep 2018 10:41:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7D1829CE1; Mon, 24 Sep 2018 10:41:13 +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=ham 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 D3E7129CD4 for ; Mon, 24 Sep 2018 10:41:12 +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=eT5RPRMLdXhdKfFWXxw/+yDXNClfZPhr13i8x4JHDIA=; b=QHL742O5SNoP0A puuCmwdF6ABaRM6l0+lNrrcOg4iqAtRwW6wapWmVCeAE8jq2NvjlHA02SkC9bUQuPTckM6Y+djPL1 2QlUxSnUYkfoJk3Dftat4U2ocnXT3PtKZNbw+loXIZnp9gb9ouHS5Pt1/h9q4gCOCiux0okhVCG2f G2FQknGEesqjE8JgZ65NHVZc9WECyNLgQyGziHjoKnznzq/thSgEpjjbqmd94cJD6aNN5x/MuucVx CiuTWwxVYyVPvrRZaG7FI13EEDymmcIGYhDtTIIxLQkqA7Krzxvx3ERZb3V3TuxP7BxEj9G9l+3FH tmakPfSS0kaVBNrxM03A==; 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 1g4OIa-0003X6-IT; Mon, 24 Sep 2018 10:41:04 +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 1g4OIW-0003W8-DB for linux-arm-kernel@lists.infradead.org; Mon, 24 Sep 2018 10:41:02 +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=vtHEEvRM2DMReWf5kbqx6ieAhRxAOteOVt4WK4r9rOY=; b=QrNq4yb3Q+IcSTLpPJ0jSiUnVnMLw/1IyMdHYs2fOjRelZ2WtDNhnWMqn9ldUrdVYyzXlkI0ivhykCLTO1zJVi6ozXjEDjGn6Pn5DPQUoxp6/ZqpcCF5YrfBKexqYQ9Fjmj3jW/RjpUiBwpdVWnC6/Q0n/6KPxGfPAHlCTGvAmc= 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:43 +0000 From: Abel Vesa To: Lucas Stach , Sascha Hauer , Dong Aisheng , Fabio Estevam , Anson Huang , Andrey Smirnov , Rob Herring Subject: [PATCH v9 2/5] clk: imx: add fractional PLL output clock Date: Mon, 24 Sep 2018 13:39:54 +0300 Message-Id: <1537785597-26499-3-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: 92dbe092-d77b-46c4-ebed-08d6220a2e1e 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:o8rZGqQLzBYmrJSH6D5Nc9JEnawbo1qGbogrBtIfnHzFIedUHv2T64TC/t2MKsk50/a8KiIyRo+1gsTPK4W4YaMBSepk5S3lGscxheWup2xZJFqkdI6Rg2tTVlORRvMx2qn1O4ctIWagFJIuv+VDK8a9RSEn5NUAkAG3/09v3CHVXULVdvgPLNU7LOlhlV7e3GtiUZZWPN/X50BW0mPO3JwrK7wzwAgoesr9UFgo/Z+dxw9CAw/xpb6u+sEgq/jm; 25:wFjSw5aJQ5tgbbWaKjjwXTsHEWc9MMUyaZ3N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dokr9K7xFl6O3R4jI4KJNlSdMDwSdBRbSAA3F776tlkUlJVvmOjwHREgk; 4:I6QQ08Zk42rOoOIpNudxvA6LyRIpcjQqARRzVElP/N2+fPSxMrItf2UtJSQ5ufcd4b1NZb6e3GNyWqDJoc1PO3vz70Rhf9DvBcCSDbz+BXcD9RS0TQMDvmmxBRIv5ZpFOuIGg9C2m9QZH/FiN4JZKwyEcwIedbTsJYLzOtyTGYrKbWdbayVMQJwrbPhghIOYMo+lZDGOv2wxk8wcAHejsawRS68IaojZ2z6mndFPS1pvE9RQOBojBe2BKZEiBCXeoiaLsVCvgPkqytHpAP+6A0kvIuEf2SNHfb8dTGfidPysNLhmdFclEygEO0fub9ZR 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)(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:kw6A6PdZu1cwk/OFmohaIJ41vWaz6KPSnPGPZgmO4?= U1ZWqF+5TvFXWBAFD2InfdaBQHZ7MX1XKWmhUJ3LmHhLFvMfCj/vhaQI0TcobaMLMzFcwPRphkdZ2BdlpoitkfstKySYTFB2twE/wmcKpW05O6xbOMgfEivA5n2xicRPVroSqrgVQmHnOA2W4YTcRwxeK4X9UZgrkmBHerUW0DCf8TuAJShilJKMwVnhFg8I8pmwCF9oEf/lMrVhRSbynuwNXvSauiHCTvJi5tPr1AD0ZiiSfH0x6kST4mZZE8zXWA9hFW/Cp9ftoOrniUVIw3c2Q0BsxHKnYNsHKF5XkDyo98P7PI3+dhukupakazA/zJwz2K5Y9zmO/KNY6dBxYdgH5U7+bURe94UAa5tlgosQG1vLxPBAt7Sx2f9DI3GQ0WFWqpaHI7RLI4dpelnuSODmTY0CMWTLVi69qLOO4KXZgEZ9WV69jrj+tbfVMqSQk8MA9Qjo+7TcPS4L/STh3vxwTlE0bG2Meh03lGcNl08vUDO20y09c6TN25Nsk+i2pQ5P2NRGmmcmsGFWGstb7Mx1mee/4hVinCH5amxwSksQqbrGei2kRxryKR+QkRlYIZWOqyR7xExMjmMUMEWyrKfQg6nGOmE6dO+sKeBOGI18CHJFcjathZJ0JYV5ofwJ5JM2/ifoDu0bG62MfnEtKIbvMe8iyDnl/DelyHcehXLp/gm4WQmOMgVZ+bs6M+ryQu3TSD6zlV5zoIdiZqIggTAca5L7+X4Z29SSGkK4FuJb+LObL3G6rC0mjF9MTej5XnYKzkiohorZ1z0LeYYa4vKYunxZYaw7orTApYhn0CmZsShWInlJClJxmWqfY+umY0WmUUpVvCOFNJCDqDbbjwasHfGHOke8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kwzrm898vPXc61p5ko7sO3WkfJ36PfZJ3zLIdY52wp5l+MuVrY/2QoU7iPbVmw/i5PFO7WFqz9yJLLbiIql0/qlVsCGRW73E/S9Xs7HdpH3Wq9MZdSK+EJRQW93eTtlAuOfEPd6bmsoMEWgjwReQnSGhNKq66ypGXnd/u4jYjQ1CTkCDBUD5PA9md7OXlctVXfw==; 5:PW3+Ml8NxQxII5d16I+eDx0kjJq0u6tex/gbaT9CpQ1xw9SriZUC2pZA4a9BGGvrKEdFOfXMKQREZv9+KcepjeSivB4FffKAx/ThL95eXlcHQJWige29CkXG2OgrYB5nnigBX8bT/ipYCIdVCwAuA0aj2sidHqSruPDFJahpUOw=; 7:vjDSlaDU2xTUvMVzRbupjPkqMwU2hq0ofzyM25z+hBeFZgPmn/FjJ/DbGHzvVH0CiPvsBpRpIF8W5NSY81Mks5xUNVo+qTrgQjrIfyxSVdW4T1GOUKvCjZj0DZya7D3zejcc3eL46fl/LqEcbEICJ1/Fn63cD6zOO3eFX+H7npLIW0LI7UJeNa/T6+05wQUsb4js/zOZbMKPjKpCyArxPjASd+cyEbmAoFN+KeRBxStx3o6PqXsgp0CbyTJT7wVM SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2018 10:40:43.1393 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 92dbe092-d77b-46c4-ebed-08d6220a2e1e 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_034100_643838_80C51C19 X-CRM114-Status: GOOD ( 17.31 ) 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 From: Lucas Stach This is a new clock type introduced on i.MX8. Signed-off-by: Lucas Stach Signed-off-by: Abel Vesa --- drivers/clk/imx/Makefile | 1 + drivers/clk/imx/clk-frac-pll.c | 215 +++++++++++++++++++++++++++++++++++++++++ drivers/clk/imx/clk.h | 3 + 3 files changed, 219 insertions(+) create mode 100644 drivers/clk/imx/clk-frac-pll.c diff --git a/drivers/clk/imx/Makefile b/drivers/clk/imx/Makefile index 8c3baa7..4893c1f 100644 --- a/drivers/clk/imx/Makefile +++ b/drivers/clk/imx/Makefile @@ -6,6 +6,7 @@ obj-y += \ clk-cpu.o \ clk-fixup-div.o \ clk-fixup-mux.o \ + clk-frac-pll.o \ clk-gate-exclusive.o \ clk-gate2.o \ clk-pllv1.o \ diff --git a/drivers/clk/imx/clk-frac-pll.c b/drivers/clk/imx/clk-frac-pll.c new file mode 100644 index 0000000..030df76 --- /dev/null +++ b/drivers/clk/imx/clk-frac-pll.c @@ -0,0 +1,215 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2018 NXP. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "clk.h" + +#define PLL_CFG0 0x0 +#define PLL_CFG1 0x4 + +#define PLL_LOCK_STATUS BIT(31) +#define PLL_PD_MASK BIT(19) +#define PLL_BYPASS_MASK BIT(14) +#define PLL_NEWDIV_VAL BIT(12) +#define PLL_NEWDIV_ACK BIT(11) +#define PLL_FRAC_DIV_MASK GENMASK(30, 7) +#define PLL_INT_DIV_MASK GENMASK(6, 0) +#define PLL_OUTPUT_DIV_MASK GENMASK(4, 0) +#define PLL_FRAC_DENOM 0x1000000 + +#define PLL_FRAC_LOCK_TIMEOUT 10000 +#define PLL_FRAC_ACK_TIMEOUT 500000 + +struct clk_frac_pll { + struct clk_hw hw; + void __iomem *base; +}; + +#define to_clk_frac_pll(_hw) container_of(_hw, struct clk_frac_pll, hw) + +static int clk_wait_lock(struct clk_frac_pll *pll) +{ + u32 val; + + return readl_poll_timeout(pll->base, val, val & PLL_LOCK_STATUS, 0, + PLL_FRAC_LOCK_TIMEOUT); +} + +static int clk_wait_ack(struct clk_frac_pll *pll) +{ + u32 val; + + /* return directly if the pll is in powerdown or in bypass */ + if (readl_relaxed(pll->base) & (PLL_PD_MASK | PLL_BYPASS_MASK)) + return 0; + + /* Wait for the pll's divfi and divff to be reloaded */ + return readl_poll_timeout(pll->base, val, val & PLL_NEWDIV_ACK, 0, + PLL_FRAC_ACK_TIMEOUT); +} + +static int clk_pll_prepare(struct clk_hw *hw) +{ + struct clk_frac_pll *pll = to_clk_frac_pll(hw); + u32 val; + + val = readl_relaxed(pll->base + PLL_CFG0); + val &= ~PLL_PD_MASK; + writel_relaxed(val, pll->base + PLL_CFG0); + + return clk_wait_lock(pll); +} + +static void clk_pll_unprepare(struct clk_hw *hw) +{ + struct clk_frac_pll *pll = to_clk_frac_pll(hw); + u32 val; + + val = readl_relaxed(pll->base + PLL_CFG0); + val |= PLL_PD_MASK; + writel_relaxed(val, pll->base + PLL_CFG0); +} + +static int clk_pll_is_prepared(struct clk_hw *hw) +{ + struct clk_frac_pll *pll = to_clk_frac_pll(hw); + u32 val; + + val = readl_relaxed(pll->base + PLL_CFG0); + return (val & PLL_PD_MASK) ? 0 : 1; +} + +static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct clk_frac_pll *pll = to_clk_frac_pll(hw); + u32 val, divff, divfi, divq; + u64 temp64; + + val = readl_relaxed(pll->base + PLL_CFG0); + divq = ((val & PLL_OUTPUT_DIV_MASK) + 1) * 2; + val = readl_relaxed(pll->base + PLL_CFG1); + divff = FIELD_GET(PLL_FRAC_DIV_MASK, val); + divfi = (val & PLL_INT_DIV_MASK); + + temp64 = (u64)parent_rate * 8; + temp64 *= divff; + do_div(temp64, PLL_FRAC_DENOM); + temp64 /= divq; + + return parent_rate * 8 * (divfi + 1) / divq + (unsigned long)temp64; +} + +static long clk_pll_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *prate) +{ + unsigned long parent_rate = *prate; + u32 divff, divfi; + u64 temp64; + + parent_rate *= 8; + rate *= 2; + divfi = rate / parent_rate; + temp64 = (u64)(rate - divfi * parent_rate); + temp64 *= PLL_FRAC_DENOM; + do_div(temp64, parent_rate); + divff = temp64; + + temp64 = (u64)parent_rate; + temp64 *= divff; + do_div(temp64, PLL_FRAC_DENOM); + + return (parent_rate * divfi + (unsigned long)temp64) / 2; +} + +/* + * To simplify the clock calculation, we can keep the 'PLL_OUTPUT_VAL' at zero + * (means the PLL output will be divided by 2). So the PLL output can use + * the below formula: + * pllout = parent_rate * 8 / 2 * DIVF_VAL; + * where DIVF_VAL = 1 + DIVFI + DIVFF / 2^24. + */ +static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct clk_frac_pll *pll = to_clk_frac_pll(hw); + u32 val, divfi, divff; + u64 temp64; + int ret; + + parent_rate *= 8; + rate *= 2; + divfi = rate / parent_rate; + temp64 = (u64) (rate - divfi * parent_rate); + temp64 *= PLL_FRAC_DENOM; + do_div(temp64, parent_rate); + divff = temp64; + + val = readl_relaxed(pll->base + PLL_CFG1); + val &= ~(PLL_FRAC_DIV_MASK | PLL_INT_DIV_MASK); + val |= ((divff << 7) | (divfi - 1)); + writel_relaxed(val, pll->base + PLL_CFG1); + + val = readl_relaxed(pll->base + PLL_CFG0); + val &= ~0x1f; + writel_relaxed(val, pll->base + PLL_CFG0); + + /* Set the NEV_DIV_VAL to reload the DIVFI and DIVFF */ + val = readl_relaxed(pll->base + PLL_CFG0); + val |= PLL_NEWDIV_VAL; + writel_relaxed(val, pll->base + PLL_CFG0); + + ret = clk_wait_ack(pll); + + /* clear the NEV_DIV_VAL */ + val = readl_relaxed(pll->base + PLL_CFG0); + val &= ~PLL_NEWDIV_VAL; + writel_relaxed(val, pll->base + PLL_CFG0); + + return ret; +} + +static const struct clk_ops clk_frac_pll_ops = { + .prepare = clk_pll_prepare, + .unprepare = clk_pll_unprepare, + .is_prepared = clk_pll_is_prepared, + .recalc_rate = clk_pll_recalc_rate, + .round_rate = clk_pll_round_rate, + .set_rate = clk_pll_set_rate, +}; + +struct clk *imx_clk_frac_pll(const char *name, const char *parent_name, + void __iomem *base) +{ + struct clk_init_data init; + struct clk_frac_pll *pll; + struct clk *clk; + + pll = kzalloc(sizeof(*pll), GFP_KERNEL); + if (!pll) + return ERR_PTR(-ENOMEM); + + pll->base = base; + init.name = name; + init.ops = &clk_frac_pll_ops; + init.flags = 0; + init.parent_names = &parent_name; + init.num_parents = 1; + + pll->hw.init = &init; + + clk = clk_register(NULL, &pll->hw); + if (IS_ERR(clk)) + kfree(pll); + + return clk; +} diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index 8076ec0..13daf1c 100644 --- a/drivers/clk/imx/clk.h +++ b/drivers/clk/imx/clk.h @@ -27,6 +27,9 @@ struct clk *imx_clk_pllv1(enum imx_pllv1_type type, const char *name, struct clk *imx_clk_pllv2(const char *name, const char *parent, void __iomem *base); +struct clk *imx_clk_frac_pll(const char *name, const char *parent_name, + void __iomem *base); + enum imx_pllv3_type { IMX_PLLV3_GENERIC, IMX_PLLV3_SYS,