Received: by 10.223.176.46 with SMTP id f43csp1064475wra; Fri, 19 Jan 2018 06:26:45 -0800 (PST) X-Google-Smtp-Source: ACJfBov9JCeqzIdXFAQmh8ctjEKW3dTaFNU9WgUG6fAQ+Z7mFgBYxvq10vUaHN4qUkBqtTrgwqnC X-Received: by 2002:a17:902:7716:: with SMTP id n22-v6mr1697873pll.388.1516372005009; Fri, 19 Jan 2018 06:26:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516372004; cv=none; d=google.com; s=arc-20160816; b=IfrH2Xmx5UF6NJz1jNkQE5WqUMUdzVe6RJbeZy8k8xZwYRG49HV+1nUkD0171PPEaQ tY1WXaSBmGCmDqE5CkiKdGELI22aB5aOhVVA1WPDrVOYICxv+4zGXNFaGVnunwjn1dHW EMRgP6IlEHcvmbndji0p+tDlxqQ0d1g4K9xtePMGZbEG+6Tw5ktWnJblL2sLh1YanpgZ STth1VviLWaOQST4F7gLL7Haf6Sj8jzfErSmMhYhMEuqlEHtApj4M8e5aCo0nuH73/ot 4dk4iAqpWxtRdy9Tj8xjzlCYfPSxGdNlW/SvYtQR/UWbF+iSsYZoxDPzJhnSHtAN5dym V5lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results; bh=buMnvonNd9vV53F77ugX/BiMJ/NffqcPvZ/wu69mwQs=; b=LJwjGwuC18oReSFQe4z8c1qWZRRp+puZVJaT5pdeKUoRd8KMLD38WlcEBeQHhl4EY5 4OfZBxn4I1hfb/S/4UOTkK1lq8df/+oKDUHM84//cFR6A3y4Nud+iEEz2nDWSU67JgRl PsTaq02mxCVl4BYEgzLssqCenK/rv/lOQRKAVWZznRupvvRUfrbVp/Yia1TgQvR8ctYG YabmLX03XY/bZRIwjKDaq3qZBDNnb3yVsyiqyT6yXE4sl6bhZGFV4p+Zz0K72K15Lbcc P2jN/V33FKvabjlYnJFhVSZUixvwS+chSTb66fVuk4ix3XuEs9UrBL4cTN5o/wLTihK2 NhZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b75si9534923pfk.309.2018.01.19.06.26.30; Fri, 19 Jan 2018 06:26:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755640AbeASOZB (ORCPT + 99 others); Fri, 19 Jan 2018 09:25:01 -0500 Received: from mail-dm3nam03on0050.outbound.protection.outlook.com ([104.47.41.50]:48386 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754771AbeASOY5 (ORCPT ); Fri, 19 Jan 2018 09:24:57 -0500 Received: from BN6PR03CA0094.namprd03.prod.outlook.com (10.164.122.160) by CY1PR03MB2364.namprd03.prod.outlook.com (10.166.207.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Fri, 19 Jan 2018 14:24:56 +0000 Received: from BL2FFO11OLC015.protection.gbl (2a01:111:f400:7c09::164) by BN6PR03CA0094.outlook.office365.com (2603:10b6:405:6f::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.428.17 via Frontend Transport; Fri, 19 Jan 2018 14:24:55 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; lists.infradead.org; dkim=none (message not signed) header.d=none;lists.infradead.org; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11OLC015.mail.protection.outlook.com (10.173.160.81) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Fri, 19 Jan 2018 14:24:54 +0000 Received: from b29396-OptiPlex-7040.ap.freescale.net (b29396-OptiPlex-7040.ap.freescale.net [10.192.242.1]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id w0JDBGiO013190; Fri, 19 Jan 2018 06:11:31 -0700 From: Dong Aisheng To: CC: , , , , , , , , , Dong Aisheng Subject: [PATCH V3 04/10] clk: imx: add pfdv2 support Date: Fri, 19 Jan 2018 21:11:04 +0800 Message-ID: <1516367470-24340-5-git-send-email-aisheng.dong@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516367470-24340-1-git-send-email-aisheng.dong@nxp.com> References: <1516367470-24340-1-git-send-email-aisheng.dong@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131608454944304552;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(396003)(346002)(376002)(39380400002)(39860400002)(2980300002)(1110001)(1109001)(339900001)(54534003)(199004)(189003)(85426001)(6306002)(498600001)(8676002)(50226002)(50466002)(48376002)(305945005)(2351001)(356003)(2906002)(77096007)(26005)(53936002)(86362001)(966005)(16586007)(54906003)(316002)(97736004)(36756003)(8936002)(81166006)(81156014)(68736007)(4326008)(2950100002)(6666003)(6916009)(76176011)(51416003)(106466001)(105606002)(5660300001)(104016004)(59450400001)(47776003)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR03MB2364;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11OLC015;1:hDhdanZphnMdLfTVQ57r0+agAjcReei2kNnZK1hopnFi0hUZkX0tKDd+QjT+I9FsZi4n7ObFF+DMa/v9ePW5fUt6UHHDuebSxeAWX0DTPVFoNu2GAXv5oL/68vPSYgEb MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c46cd4d9-678f-46ad-ada8-08d55f4868db X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(5600026)(4604075)(2017052603307);SRVR:CY1PR03MB2364; X-Microsoft-Exchange-Diagnostics: 1;CY1PR03MB2364;3:hrNlekZ/2HEm5YXqGdi0a2VYBIfOgYCQniASYUrh7uhzEzq4ljRzxcqB1n0k4lJ2GSs1SZYVFDT90PjpfYyKDGSv24JdYGGACGvkNStM6S5jAv4guZF3qmC+rvyMm0ZfPLFU8kkSfuMzXWoi4lmFDKZtA+etluUxyPvnpLTCLu4Swk/b0/G9nRaPDnrHQEz+1st+IjoaNv10mNDo5MzuNPf+T6ukWoe+FdVLkgICSYxjYygE7rTztwcOKUtU2WR4BfeJoIRwRALjam0ndTChMcbMDemBF87mE3HYCvxX+G+isW5m41QB0bihL5nxmPVePhdz6DATGTS2cqk4gCQ7m575JkanEEq61AUwMovv6Ns=;25:M7WR5Gm2dOLuhZIWf9MCdDQFaYhEL7IOrOE1Tnj0jAHd5UCMmiLPhhC6xxm+nuzWg84AKIFQGWqYj9WEQwFvSLXe0jn3k3abCxMiL/cHE80/BmCa8l/G6oJph+ZQwzAN/BqKCQwRz+eHmRH5txdMl8mumjxmKPpdjpNcqDapsBwIeKIuIv3kNS4jNjIBTzf2JNovhpPTt80mX7YBIN9nAZQvSL3N5Qn7ulYSw6AJyw7aM19pB3I1Mvm06von+8ZIMxp2MzN2hJ6GmH+672+nhD7KFZM/mIm186625J0mJFFyJe8Gp7E7LWWq9zUC9uluowREuI23uAiv8xKN83gYmg== X-MS-TrafficTypeDiagnostic: CY1PR03MB2364: X-Microsoft-Exchange-Diagnostics: 1;CY1PR03MB2364;31:9eJzCPOlK53e+rkFPoAP/Yh3XOjvfl+vi+AFwaJJeVlKP0llx0HGNNkHhdOGOEC9+GlVTvT01KB7FpqwPH+BNbL9d88VQcytZpihE1vHCdBZcEdT0UONSkUcnWL1+d16/tO4ckH1A3d7TbBwfb79scvnBU0OqY85yjaiaevsFMriCqxyuTodXyDU/DhP6LhH3h4q9ntutq1m8ySdX4dQ2LdxB6qsizP7v1qkL23wX+w=;4:tO2bJ1TTotEOqKTxDzmLFlYd9RW0FIEA2VxNYA8Wadb4lpKnYHBJOVU7tMMlLrOhBxrZZouol1Qdnqcod5qCZF6Sx9vxsWYf+jAb5PSdR+AWFngMXgSMOTJVpkN3m2V7dMGxnw75+sof8xfxJed3U6M+liyTL5Fp/n2MYRxaBK5uzuE5Wt2DuG834F0bZHzIp3vhIN4UdeVPgL/0j5YeULqUnmAJqlZTxz9Bf+LM3nDce/tmOEDu+dJeH6iJSSlxEKCPjtalo/AoFvXbvQ27tjFsJ+fzKkkQsfDHqGpQ3wK1CrwWVTXtlrhW/FkSiVxtzlnEoylb4nogAAa5d00XjJOJJg9SwUPg9/+lZB5et32kupfa6EuZANB6NKdui/hk X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(22074186197030)(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6095135)(2401047)(5005006)(8121501046)(10201501046)(3231023)(2400078)(944501161)(3002001)(93006095)(93001095)(6055026)(6096035)(201703131430075)(201703131448075)(201703131433075)(201703151042153)(20161123565025)(20161123559100)(20161123561025)(20161123556025)(20161123563025)(201708071742011);SRVR:CY1PR03MB2364;BCL:0;PCL:0;RULEID:(100000803101)(100110400095)(400006);SRVR:CY1PR03MB2364; X-Forefront-PRVS: 0557CBAD84 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR03MB2364;23:QoUPhP6huJXwSVzMu0aW/qRt6y+EgXS/k1kaNPLyM?= =?us-ascii?Q?sevnGI0DtWDYplsxT04q6z7ABi8dblbuCAi7ujmIqdocwxXvlOHivJ6jbv5y?= =?us-ascii?Q?Atm6CnD45c3aLLspncAvl4Snco4ayc7Kn0ffSQa/OwfMQo8Sy1BIyjNqRtcO?= =?us-ascii?Q?aGJ8eQkbBx1042CMmJ2sQFnbB8k1kj/irbsgqReKmUzyyoaBIF5CciTQFrF/?= =?us-ascii?Q?ZBnH0/X29/8G+JL6CEKc0OSznNrHFa7G8tddq4VMuNJjqGOVOFuDCv+b64ZU?= =?us-ascii?Q?DXSqlJVEVj4AZQFfcZhMrMc/yJK24ASZ/KClntWzQNkmsmFoRHp/xhhm6OEa?= =?us-ascii?Q?CypkGITQ7zcIw4RuV2scr5Tw+xEhLBV8FrolVDp8AOs26tIKpuxGlMX+luct?= =?us-ascii?Q?PqJBTpY/9FnS/3YZjJaRWO+N6kAUreT4FudpdlKtZIudAQoLWsPcs6dR5119?= =?us-ascii?Q?aClP7RnVQ7Q1NJGH2K81qv/YlMhWD+M10Y42FIK7QR9ij9WMs1FE+GVVzS2Y?= =?us-ascii?Q?f/c1Q+NMyhFA3X4rBc06S8cLBnbodyPhC6wCTIkTTcJfshYl+9OP5AdXDeyz?= =?us-ascii?Q?9lhXyD1D7SgyNftSfB9vkejZNQfqSvHp7Yc5OPn9uL/fSeVjWDWvahWEm/ck?= =?us-ascii?Q?wQ8icJ6oCFbxdClNwyQ0chalAj6eS9fnY3PU1+AvsJxuyZB7F7Sy0DbHJbGO?= =?us-ascii?Q?AxtoaCL+/jiSMEAUeZi+wkkLdD9uC4KlaLm5dPfDm6AAXJu0G6xIYSY7UQsv?= =?us-ascii?Q?MoMkwXNQHNpveHSIa021BY1Ihl/lE0JfQv7fy3hszg83zaWfqJwujCWoDtsn?= =?us-ascii?Q?2L9bdvN4Z1Q87HYBcpWniHDGcHszXE5pSBs7/xqET7laYRMQbT/sp34mydUL?= =?us-ascii?Q?SzyfqNZoLJ8CcXhwVIfRZxw5EApB24/GYn4MeSVavau2Gm/PaVEJiqM3E41e?= =?us-ascii?Q?KnTUWiwJe5AxxCqcSnerZiupHkXrI7qgnuPNzyLi6atlrPfNbfCYXPu3BHA4?= =?us-ascii?Q?++a0xZSLmeRpMmMehWRYYU1QDqcJa6iROTso6URd8VsX37FAgSvEuvfMjCn+?= =?us-ascii?Q?QFKvq6rbxcuBmrcfnvMKY6byf1/FDsqd9aNcNZlR2OKgLk+A7Bk/d5V5DVhC?= =?us-ascii?Q?7C+xIivGX4/0C9jkx9khUE+Wo9dcfc941eM/3HqoGJjR+TqlQuixw=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR03MB2364;6:IZbzhphYfjpgXidhgBaujZOr+7FxRZDs5eytbSydyFH6BpQMgCdZ/VjbwxahDISNsTXAEL+rCh9IhCpZEaISJMmQV8P7jdOw4tT2OZHgrdKXzRjK9I2bJB7ZL3k2e+rs81YSM99wpbRTe9G0HXhfhpEIpbXCUh5ymiFLh2+wy60weBDNCjUwlm5ko7m6QsXdeR3U+Bk/poIPkCGvUCMYXiltcRKSVk6Lw5FJh7JcRwcbGXPQVqO8vfNwK2qgT9lyMouRWeixWxt4TI96cu+kF1fQUlnNLSmj8ig1bMxSXZGU9ga+CR3XCsbkBQPL5XrYh9vCFtFfzEuvjQr8Kh9e0norsqPAVn2JnFTlsoqk7L0=;5:BZLtON52+wOEHI1tsrPUGMToWEZ5PFghZEud69DsicK8PU772CJgqYJJeeuwDqK4hsxBlCrIrzICHtkmFyYYNziVs5WseGuxy1z5fme519SJNUhg7EUab97cBmTqKKbzxcKX/0luW3u85FnVuVjzP7ZWOjRO1sm50eNIkZ0ueBk=;24:GjAtdEmO85LqpRg2gk/fUtAahSOgUpUbOZ+FRshSy2xrGrNIL9EqSQfkbeST5oc9A7jhjANIRrG+JTsstZJ48Sv2nfP4tBTRcaRH9wcuTFU=;7:ADmz3zJb3SUSAv3xIDIOejXBLnvuoD8wTtB9isja6Xuvb97xlwi+R99eUVhQuJgugHIseNHXh5zXXV/bmlQxMlWO7YW/Z/inGoqUOmxWppom1XFN+13EGZIDP5/hEZ6BNhyNdOHyazBLTTC69UTmK3dXcOQrRNtCBr6D4IbpmKf2evYS8mhvUHHsyi/YboWPDo58UMbfu2UVodm3j1jPpad62nmpDealhCmLDKuCOkqcwt+avq2AuibEao61YWFc SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2018 14:24:54.2588 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c46cd4d9-678f-46ad-ada8-08d55f4868db X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB2364 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pfdv2 is designed for PLL Fractional Divide (PFD) observed in System Clock Generation (SCG) module in IMX ULP SoC series. e.g. i.MX7ULP. NOTE pfdv2 can only be operated when clk is gated. Cc: Stephen Boyd Cc: Michael Turquette Cc: Shawn Guo Cc: Anson Huang Cc: Bai Ping Signed-off-by: Dong Aisheng --- ChangeLog: v2->v3: * no changes v1->v2: * change to readl_poll_timeout * add pfd lock to protect share reg access between rate and enable/disable operations and multiple pfd instances. * use clk_hw_register --- drivers/clk/imx/Makefile | 3 +- drivers/clk/imx/clk-pfdv2.c | 207 ++++++++++++++++++++++++++++++++++++++++++++ drivers/clk/imx/clk.h | 3 + 3 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 drivers/clk/imx/clk-pfdv2.c diff --git a/drivers/clk/imx/Makefile b/drivers/clk/imx/Makefile index 2f00b03..9c04ae4 100644 --- a/drivers/clk/imx/Makefile +++ b/drivers/clk/imx/Makefile @@ -12,7 +12,8 @@ obj-y += \ clk-pllv2.o \ clk-pllv3.o \ clk-pllv4.o \ - clk-pfd.o + clk-pfd.o \ + clk-pfdv2.o obj-$(CONFIG_SOC_IMX1) += clk-imx1.o obj-$(CONFIG_SOC_IMX21) += clk-imx21.o diff --git a/drivers/clk/imx/clk-pfdv2.c b/drivers/clk/imx/clk-pfdv2.c new file mode 100644 index 0000000..5421bdf --- /dev/null +++ b/drivers/clk/imx/clk-pfdv2.c @@ -0,0 +1,207 @@ +/* + * Copyright (C) 2016 Freescale Semiconductor, Inc. + * Copyright 2017 NXP + * + * Author: Dong Aisheng + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * http://www.opensource.org/licenses/gpl-license.html + * http://www.gnu.org/copyleft/gpl.html + */ + +#include +#include +#include +#include + +/** + * struct clk_pfdv2 - IMX PFD clock + * @clk_hw: clock source + * @reg: PFD register address + * @gate_bit: Gate bit offset + * @vld_bit: Valid bit offset + * @frac_off: PLL Fractional Divider offset + */ + +struct clk_pfdv2 { + struct clk_hw hw; + void __iomem *reg; + u8 gate_bit; + u8 vld_bit; + u8 frac_off; +}; + +#define to_clk_pfdv2(_hw) container_of(_hw, struct clk_pfdv2, hw) + +#define CLK_PFDV2_FRAC_MASK 0x3f + +#define LOCK_TIMEOUT_US USEC_PER_MSEC + +static DEFINE_SPINLOCK(pfd_lock); + +static int clk_pfdv2_wait(struct clk_pfdv2 *pfd) +{ + u32 val; + + return readl_poll_timeout(pfd->reg, val, val & pfd->vld_bit, + 0, LOCK_TIMEOUT_US); +} + +static int clk_pfdv2_enable(struct clk_hw *hw) +{ + struct clk_pfdv2 *pfd = to_clk_pfdv2(hw); + unsigned long flags; + u32 val; + + spin_lock_irqsave(&pfd_lock, flags); + val = readl_relaxed(pfd->reg); + val &= ~pfd->gate_bit; + writel_relaxed(val, pfd->reg); + spin_unlock_irqrestore(&pfd_lock, flags); + + return clk_pfdv2_wait(pfd); +} + +static void clk_pfdv2_disable(struct clk_hw *hw) +{ + struct clk_pfdv2 *pfd = to_clk_pfdv2(hw); + unsigned long flags; + u32 val; + + spin_lock_irqsave(&pfd_lock, flags); + val = readl_relaxed(pfd->reg); + val |= pfd->gate_bit; + writel_relaxed(val, pfd->reg); + spin_unlock_irqrestore(&pfd_lock, flags); +} + +static unsigned long clk_pfdv2_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct clk_pfdv2 *pfd = to_clk_pfdv2(hw); + u64 tmp = parent_rate; + u8 frac; + + frac = (readl_relaxed(pfd->reg) >> pfd->frac_off) + & CLK_PFDV2_FRAC_MASK; + + if (!frac) { + pr_debug("clk_pfdv2: %s invalid pfd frac value 0\n", + clk_hw_get_name(hw)); + return 0; + } + + tmp *= 18; + do_div(tmp, frac); + + return tmp; +} + +static long clk_pfdv2_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *prate) +{ + u64 tmp = *prate; + u8 frac; + + tmp = tmp * 18 + rate / 2; + do_div(tmp, rate); + frac = tmp; + + if (frac < 12) + frac = 12; + else if (frac > 35) + frac = 35; + + tmp = *prate; + tmp *= 18; + do_div(tmp, frac); + + return tmp; +} + +static int clk_pfdv2_is_enabled(struct clk_hw *hw) +{ + struct clk_pfdv2 *pfd = to_clk_pfdv2(hw); + + if (readl_relaxed(pfd->reg) & pfd->gate_bit) + return 0; + + return 1; +} + +static int clk_pfdv2_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct clk_pfdv2 *pfd = to_clk_pfdv2(hw); + unsigned long flags; + u64 tmp = parent_rate; + u32 val; + u8 frac; + + tmp = tmp * 18 + rate / 2; + do_div(tmp, rate); + frac = tmp; + if (frac < 12) + frac = 12; + else if (frac > 35) + frac = 35; + + spin_lock_irqsave(&pfd_lock, flags); + val = readl_relaxed(pfd->reg); + val &= ~(CLK_PFDV2_FRAC_MASK << pfd->frac_off); + val |= frac << pfd->frac_off; + writel_relaxed(val, pfd->reg); + spin_unlock_irqrestore(&pfd_lock, flags); + + return 0; +} + +static const struct clk_ops clk_pfdv2_ops = { + .enable = clk_pfdv2_enable, + .disable = clk_pfdv2_disable, + .recalc_rate = clk_pfdv2_recalc_rate, + .round_rate = clk_pfdv2_round_rate, + .set_rate = clk_pfdv2_set_rate, + .is_enabled = clk_pfdv2_is_enabled, +}; + +struct clk_hw *imx_clk_pfdv2(const char *name, const char *parent_name, + void __iomem *reg, u8 idx) +{ + struct clk_init_data init; + struct clk_pfdv2 *pfd; + struct clk_hw *hw; + int ret; + + WARN_ON(idx > 3); + + pfd = kzalloc(sizeof(*pfd), GFP_KERNEL); + if (!pfd) + return ERR_PTR(-ENOMEM); + + pfd->reg = reg; + pfd->gate_bit = 1 << ((idx + 1) * 8 - 1); + pfd->vld_bit = pfd->gate_bit - 1; + pfd->frac_off = idx * 8; + + init.name = name; + init.ops = &clk_pfdv2_ops; + init.parent_names = &parent_name; + init.num_parents = 1; + init.flags = CLK_SET_RATE_GATE; + + pfd->hw.init = &init; + + hw = &pfd->hw; + ret = clk_hw_register(NULL, hw); + if (ret) { + kfree(pfd); + hw = ERR_PTR(ret); + } + + return hw; +} diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index 52f7c9d..ccd7181 100644 --- a/drivers/clk/imx/clk.h +++ b/drivers/clk/imx/clk.h @@ -60,6 +60,9 @@ struct clk *imx_clk_gate_exclusive(const char *name, const char *parent, struct clk *imx_clk_pfd(const char *name, const char *parent_name, void __iomem *reg, u8 idx); +struct clk_hw *imx_clk_pfdv2(const char *name, const char *parent_name, + void __iomem *reg, u8 idx); + struct clk *imx_clk_busy_divider(const char *name, const char *parent_name, void __iomem *reg, u8 shift, u8 width, void __iomem *busy_reg, u8 busy_shift); -- 2.7.4