Received: by 10.223.176.46 with SMTP id f43csp981078wra; Fri, 19 Jan 2018 05:13:01 -0800 (PST) X-Google-Smtp-Source: ACJfBovWo7mWgmCKLr+eJ78eApm5IM1AO/1kg98tljR365AhYhkPD7KX20615HHyoi4FykSFLqtk X-Received: by 10.99.114.90 with SMTP id c26mr30224801pgn.114.1516367580944; Fri, 19 Jan 2018 05:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516367580; cv=none; d=google.com; s=arc-20160816; b=U17aIo1E4jZNI5twfpvZl/Apw/KmBNHAUi/AufNNyDQ97HKzFsHYxAcSxWJGS9KzFC hhxyAjmAKG7ew3eaJzfrDwkt9zOKv20ssPy5NSBPaPb00DsBgi6CJBskF3KCIzb45cpY 47ju5Kp0DqQK+95W4zFH00PRh6ZLbOH3dQW/JxS4fZZZgK2kD2MZ2xIRZjQqhetTgps+ I9q29tss4sydCnvmVKJFiGaL0lyDaM+xwmaVi2Sha3WuFYYBYmFYcX97Ge0700GaSqiF ze4JQ/9gDwKkF2yfXq61D1bGCfIS3XDw60mJFl0q86YZAVbMDMqAHGAJizgZviNZMGQv npBw== 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=GP7cw/HnjLMlUYLaHfqHSmo+riNk1Y9RNFIWyJ5Kido=; b=CGtc4Kt8nSKHXanXhcYh4jff2ujJPQtBYUJSD7ichMKYslYECokILsQkbhRQ4fOq31 ciChl6IuqpWJRn/WUMD9snzTH/hFJ0YCyB2vSTxeQErfvrlOtlpSs42fIb7AZlmLiTJb fp+Eq7fQg7UKZs8a/SQfEOGjmD1StT7gBLDztZvRoiKbt8n/2zLvL/oPabqTEcGkK3iy 028MCStHQUAL/TPvETI2L1EKZCItWzW75bwfn2RRP+wJcNDDV3HI7P7TurLktDo/r3+F Pi1KqsdFNjA+iwMAUR3blHUNoKeQBqRBBcIWKlRVUIqHcZQmcmkMOuq7tyHEDSsNW3Rg UGcg== 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 k127si8284790pgc.352.2018.01.19.05.12.46; Fri, 19 Jan 2018 05:13:00 -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 S1755772AbeASNMC (ORCPT + 99 others); Fri, 19 Jan 2018 08:12:02 -0500 Received: from mail-bl2nam02on0053.outbound.protection.outlook.com ([104.47.38.53]:26880 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754860AbeASNLk (ORCPT ); Fri, 19 Jan 2018 08:11:40 -0500 Received: from BN6PR03CA0071.namprd03.prod.outlook.com (10.173.137.33) by CO2PR03MB2358.namprd03.prod.outlook.com (10.166.93.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Fri, 19 Jan 2018 13:11:37 +0000 Received: from BY2FFO11FD035.protection.gbl (2a01:111:f400:7c0c::186) by BN6PR03CA0071.outlook.office365.com (2603:10b6:404:4c::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.407.7 via Frontend Transport; Fri, 19 Jan 2018 13:11:37 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; 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 BY2FFO11FD035.mail.protection.outlook.com (10.1.14.220) 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 13:11:32 +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 w0JDBGiN013190; Fri, 19 Jan 2018 06:11:28 -0700 From: Dong Aisheng To: CC: , , , , , , , , , Dong Aisheng Subject: [PATCH V3 03/10] clk: imx: add pllv4 support Date: Fri, 19 Jan 2018 21:11:03 +0800 Message-ID: <1516367470-24340-4-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: 131608410965264537;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(7966004)(396003)(39860400002)(376002)(346002)(39380400002)(2980300002)(1110001)(1109001)(339900001)(189003)(199004)(54534003)(81156014)(50466002)(53936002)(51416003)(8676002)(36756003)(8936002)(47776003)(59450400001)(68736007)(104016004)(76176011)(50226002)(7416002)(48376002)(77096007)(97736004)(305945005)(26005)(2906002)(356003)(81166006)(6306002)(966005)(54906003)(2351001)(86362001)(2950100002)(85426001)(16586007)(6666003)(105606002)(4326008)(6916009)(508600001)(8656006)(5660300001)(106466001)(316002)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:CO2PR03MB2358;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD035;1:wYlHi4LX+GTrXdip552B/SHaHDS3AL8kxuPgfWeUMNqLhSn6j25R11JaAJs9xcYn3OI/70dFx+vDWTjVzB4/91Au7EsOxURUjUic/oQfQyq49U9osYSwxtthp0XhmFH1 MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 69fcf405-fbb7-427a-c899-08d55f3e2b80 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(5600026)(4604075)(2017052603307);SRVR:CO2PR03MB2358; X-Microsoft-Exchange-Diagnostics: 1;CO2PR03MB2358;3:8vYqvuHHqe7JsAKqvKiO+zM2/DThsIeatwiPdOQ9u3vuQ8MhieYDTcyalCF5FGY5MlIorWNmKypGEi3wP/yGTRTCJjfT1gToyu8vFx9hiYDfQZbHv2ooxWlnGpLb4IvUkCAoBIVGTceXLpJBnMhkQn1O9lmcGK21EjdVRoaPK0ysof/fF9mN3V+eQmmrMGUiiRq89ja7OPuQna55v08lZIzV9i88NQ2UeYEJMIaKaGYiyLLWr7ExJILSzFu77UY1xYhc6+9AwwY+Q1IOXdGcN5Dcdx9vPcPAKhJdKdzl3Q/Kfpg9aYwx1kSMCMsIIeguUUlRh8thP61AubQLOa4dMbTP8Cwit6EKwDXKCJie//g=;25:4TYPAzxk4AJWBiqoC8Zv4IoXQVNwkvTOGnLVvJdXcdq+Mdwwz24B6nSc/y7xiv4cjEipM/GGSKkiHqu0cDA4RJpXzdNdi+LKRseu0/01ZMD1oUVuNHyVXkyHdbGSnE23hXrJ8TRDoD7dQLLVFSyq8zVtDpD/SL6LWb8wRFWnGdtZis4E4jgwBNJbHbeqj5OY434ZVPuJLiSZRK07mJ4KqnqFdivTWIzyNfHVOeYdjlZKy5KjTwUjqtomknX7UKpgN7Frt6epP1kwtexJgs6JYGzVTVLKDC9925RhzJLvaXDize3DlSNfz6x2hpkbBsWY1jJMNrytWxe8msix1C0R6w== X-MS-TrafficTypeDiagnostic: CO2PR03MB2358: X-Microsoft-Exchange-Diagnostics: 1;CO2PR03MB2358;31:V25ekFkXqMpL2SDHJrhfllHfA9Rpx1y5g5oAeG9FWIy+LrDLd2FlxFHThkqg/Mu0HuPyG6nwUfVnTUrkPv0RGyaG+I0D5/4fw5bgTlEZZhtnnUyVNI68/teMI6Kvf4UGuFCIXcptb5prXLGG+4n0b2UFQjf1jnDWFez/KWih/Yu/1G+lHZ088iJkpMI1CQmU2L1iSpjT033GyZOk06/C5OYlxMbLjE9QHR5CTu6aiDE=;4:wBNKjvA6BTHKGjAuxE8x6EMKelS10Mr+1It5i1SWCKgWN2J2jNnswHhQhmnTqpKbbzUjGxLTKSNTMrpoSq9sPdOsxJbErNVxo1599caxR7ApgQaaysIxX3s4y6CMt/jIkhIgdxMkI1Z82KC/EIU+ylAZ/Bbs2efpfyzVVsvB61DHk8ewuCQYKVy8H1RyJeZs4bLtKoD5sCL9ARWiAs7zFeFbNA++XLvRAj/jhV63+qO7X/OUzbX49n91MuzQ6jw9jIN3iKbEEsjE+LqMLM52gIXNU0EXXEzUO/tmmrSRUV/AAyfj7Pj4zB9WCl1AMsEqx1wTV13kXX4cSI7827MAMYo2vjXSwdm0lOWoBk59O8Ith09gtLtpLLSafr9MkPQR 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)(2400077)(944501161)(3002001)(93006095)(93001095)(6055026)(6096035)(20161123559100)(201703131430075)(201703131441075)(201703131448075)(201703131433075)(20161123561025)(20161123563025)(20161123556025)(20161123565025)(201708071742011);SRVR:CO2PR03MB2358;BCL:0;PCL:0;RULEID:(100000803101)(100110400095)(400006);SRVR:CO2PR03MB2358; X-Forefront-PRVS: 0557CBAD84 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CO2PR03MB2358;23:6DCYLRgsdO1KkgNpE1Dqqg9OFLid30VZykHPXaVnD?= =?us-ascii?Q?ex1/0lU08j2DDKuoM4Lwd3FbvQ9ZijIxjrBGceMl/2JGTXwQKW/ccyErSYGW?= =?us-ascii?Q?3ZB8K6oH3BZPivVKn+3cHw8D3ZBz0gw9Rdx1DP54cwWR7OdurB2yCVznacAS?= =?us-ascii?Q?H2ozZQ+OUF/0yMWBCh5R0wX2C4y6JKeatUjfX7afBIRffdsXVAjSeEKNC6RR?= =?us-ascii?Q?X05pWF4Nu50qIyjA9Ds564imjhugAi3pp+UsDY2GyRL3GtPApJTUdwcXUKGU?= =?us-ascii?Q?D2Go6t0ZOaVJltkWiWuenKsXAekoQcs1UztxHZTow0fahpGwANdoBekh6aih?= =?us-ascii?Q?D5TFXtZ36rcaffKeE5vrn9MPE3cYuMxhKBv7SDaGjrP0SkwMapR7kDe+IKTx?= =?us-ascii?Q?ZnI1+GxTDrt3ptHyKmuxvBFxhNTSHdtXGgioogcyGrF/8CXK+TEACXYpufmk?= =?us-ascii?Q?SvS9BUrtUKriRdOm9CbMlVTK5dthdXIubGK/iHktmtcSTvYLCQBPhljsgBCX?= =?us-ascii?Q?TG4PY5wLr7O2a1Ayk22hsKfYMAXSZHL/8mqNqRrXBKbqMEKm0R+9AyjWewoi?= =?us-ascii?Q?QYYvIont0klrgBHt0JByabjJb8EzvI6m5IIkdZgiuLZZexIdwRS0eSRcOIwq?= =?us-ascii?Q?B9i2UIqRizvXjwIwvCcjtLFMJ5eZet5jOlZJU2sZKMG+KzEt3tiEuO5QCiIG?= =?us-ascii?Q?WqWi3FfXGAYZJQ/40WvNvmESwKC0l3jBeytxL8L9QbG4qWZ63HHRvRTIgXta?= =?us-ascii?Q?FQeT7O0MGA2SDWjLYYQ10S+CmZMclkf1Kz0fwo6+I6MOVvMBz3MrEYhBnqZD?= =?us-ascii?Q?dqgdPLOpznWoFevc6vi5QmcRprf4HmhDUwBIDoWmfSXlmnvqfy4853cl7iXO?= =?us-ascii?Q?Az1OJk6myFgmBIBxowpm9FoglURX2NDaf2meiBpoU0S2o4C5KBat/tkdAn6k?= =?us-ascii?Q?QtSNazgFe8VOAuRXz7CsktAsj+qTQlP78WKj0Fu//O9ug8hh/nGGCJ2bg5iw?= =?us-ascii?Q?u3tDSoamBtKBGH+EJpoZvQHNIDee3j8mGlbDo2jTMsge3SJFULPU7DfiOlqU?= =?us-ascii?Q?YCfOt/pcNrRL+LPL8v7dxZvf+bCG6OA2yl7EkZgXJ7nNkV9G0olNy2uMJAyU?= =?us-ascii?Q?9cVjljdjucBs25zn5MGMWauC6bJ2QaqQ2JxmMZetbi/fikmpSb66RrtaflYZ?= =?us-ascii?Q?/8GoXueAdX7ygeZgN5QKLk4CHDgiRoye75iWIHp2rPJof4oYo5ruCtDzA=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1;CO2PR03MB2358;6:pCnAV0QoB54U9nhG3JOQm8zWsCWrl01cYd92Wlx3NLsw9myJiNwN+0m33x2EkUOw5KDxeHmK2+Iv5vrvQPgEwytsB3bDqCnjGA5esxdussk9UrAVwQONyv001K7VhZZ5r+j70wkfUABwwZCsa0t8EoMVJJYdo7CbG5OeumGgyNyctkhK0JrIXXrpK74alot8ZqF0prNWR1Lh/jKXYF2X66EaYgMjmanz2lS7YdZ2vV0bVieIbdAsRl9yFN//mHQB8PLCLAymfPhANm1/wUcF8eVwHOMXA6uFBKM0+T55t1259aecIeGZ6AIsQ2vQ5LiymnCBdiEdC6kdxH78Kzp/MBfciWMYdz8RAQVOYFs4RxY=;5:07HMHoHL3E2P1YzUGUqP4rOqbGOMTERZ5/NoXttc44bJSEWwESeW6/v8dGi85lCq19ldlu7MxmXRft0H+JgxaGciqghNiFNreXaLD2pBzyZKulmxufQUru/5IYZ1yk2oVEo0JaBjDzft75ABzS55DW662K58q33Np3NzeDYC3S4=;24:Iwg38/06isXspcBgfrZjYJlRgPHdFP5uER39w383R8IqXkFBNpHvy5Q2g+eV+c105wHyYpl0DSSoT5XfiMUjSm8XgC1ar6iMwO2yhgLtTxY=;7:FRumO/9m0qI/OZAtX0egklOHyDCMpVWEUJZNBbFxHvTeaAan1hu8wtgtE4UuMyPy+oqxGW6v68jnIUHWAPrtNdsJANa3cy0ZuZY9v6MnqXT0pC7VkVqF5aLvFfT9KJKzXX3kVdYxiUijrnaGmftOepGoeWFRMe5eMf7a+fBszN2KWT/HeK9nDgFi1wcn/lIUfEnSMdpsumspQuOMAx2Wabw3ijZY97uMz6FkpW11CJUAFbvM6OzUjcWTMudeF3pN SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2018 13:11:32.4235 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 69fcf405-fbb7-427a-c899-08d55f3e2b80 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: CO2PR03MB2358 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org pllv4 is designed for System Clock Generation (SCG) module observed in IMX ULP SoC series. e.g. i.MX7ULP. The SCG modules generates clock used to derive processor, system, peripheral bus and external memory interface clocks while this patch intends to support the PLL part. 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: * remove clk_pllv4_is_enabled() check in set_rate, instead it will be handled by core later. * use readl_poll_timeout * use clk_hw_register instead of clk_register * other minor changes --- drivers/clk/imx/Makefile | 1 + drivers/clk/imx/clk-pllv4.c | 188 ++++++++++++++++++++++++++++++++++++++++++++ drivers/clk/imx/clk.h | 3 + 3 files changed, 192 insertions(+) create mode 100644 drivers/clk/imx/clk-pllv4.c diff --git a/drivers/clk/imx/Makefile b/drivers/clk/imx/Makefile index f91f2b2..2f00b03 100644 --- a/drivers/clk/imx/Makefile +++ b/drivers/clk/imx/Makefile @@ -11,6 +11,7 @@ obj-y += \ clk-pllv1.o \ clk-pllv2.o \ clk-pllv3.o \ + clk-pllv4.o \ clk-pfd.o obj-$(CONFIG_SOC_IMX1) += clk-imx1.o diff --git a/drivers/clk/imx/clk-pllv4.c b/drivers/clk/imx/clk-pllv4.c new file mode 100644 index 0000000..47e4d1c --- /dev/null +++ b/drivers/clk/imx/clk-pllv4.c @@ -0,0 +1,188 @@ +/* + * 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 + +/* PLL Control Status Register (xPLLCSR) */ +#define PLL_CSR_OFFSET 0x0 +#define PLL_VLD BIT(24) +#define PLL_EN BIT(0) + +/* PLL Configuration Register (xPLLCFG) */ +#define PLL_CFG_OFFSET 0x08 +#define BP_PLL_MULT 16 +#define BM_PLL_MULT (0x7f << 16) + +/* PLL Numerator Register (xPLLNUM) */ +#define PLL_NUM_OFFSET 0x10 + +/* PLL Denominator Register (xPLLDENOM) */ +#define PLL_DENOM_OFFSET 0x14 + +struct clk_pllv4 { + struct clk_hw hw; + void __iomem *base; +}; + +/* Valid PLL MULT Table */ +static const int pllv4_mult_table[] = {33, 27, 22, 20, 17, 16}; + +#define to_clk_pllv4(__hw) container_of(__hw, struct clk_pllv4, hw) + +#define LOCK_TIMEOUT_US USEC_PER_MSEC + +static inline int clk_pllv4_wait_lock(struct clk_pllv4 *pll) +{ + u32 csr; + + return readl_poll_timeout(pll->base + PLL_CSR_OFFSET, + csr, csr & PLL_VLD, 0, LOCK_TIMEOUT_US); +} + +static int clk_pllv4_is_enabled(struct clk_hw *hw) +{ + struct clk_pllv4 *pll = to_clk_pllv4(hw); + + if (readl_relaxed(pll->base) & PLL_EN) + return 1; + + return 0; +} + +static unsigned long clk_pllv4_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct clk_pllv4 *pll = to_clk_pllv4(hw); + u32 div; + + div = readl_relaxed(pll->base + PLL_CFG_OFFSET); + div &= BM_PLL_MULT; + div >>= BP_PLL_MULT; + + return parent_rate * div; +} + +static long clk_pllv4_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *prate) +{ + unsigned long parent_rate = *prate; + unsigned long round_rate, i; + + for (i = 0; i < ARRAY_SIZE(pllv4_mult_table); i++) { + round_rate = parent_rate * pllv4_mult_table[i]; + if (rate >= round_rate) + return round_rate; + } + + return round_rate; +} + +static bool clk_pllv4_is_valid_mult(unsigned int mult) +{ + int i; + + /* check if mult is in valid MULT table */ + for (i = 0; i < ARRAY_SIZE(pllv4_mult_table); i++) { + if (pllv4_mult_table[i] == mult) + return true; + } + + return false; +} + +static int clk_pllv4_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct clk_pllv4 *pll = to_clk_pllv4(hw); + u32 val, mult; + + mult = rate / parent_rate; + + if (clk_pllv4_is_valid_mult(mult)) + return -EINVAL; + + val = readl_relaxed(pll->base + PLL_CFG_OFFSET); + val &= ~BM_PLL_MULT; + val |= mult << BP_PLL_MULT; + writel_relaxed(val, pll->base + PLL_CFG_OFFSET); + + return 0; +} + +static int clk_pllv4_enable(struct clk_hw *hw) +{ + u32 val; + struct clk_pllv4 *pll = to_clk_pllv4(hw); + + val = readl_relaxed(pll->base); + val |= PLL_EN; + writel_relaxed(val, pll->base); + + return clk_pllv4_wait_lock(pll); +} + +static void clk_pllv4_disable(struct clk_hw *hw) +{ + u32 val; + struct clk_pllv4 *pll = to_clk_pllv4(hw); + + val = readl_relaxed(pll->base); + val &= ~PLL_EN; + writel_relaxed(val, pll->base); +} + +static const struct clk_ops clk_pllv4_ops = { + .recalc_rate = clk_pllv4_recalc_rate, + .round_rate = clk_pllv4_round_rate, + .set_rate = clk_pllv4_set_rate, + .enable = clk_pllv4_enable, + .disable = clk_pllv4_disable, + .is_enabled = clk_pllv4_is_enabled, +}; + +struct clk_hw *imx_clk_pllv4(const char *name, const char *parent_name, + void __iomem *base) +{ + struct clk_pllv4 *pll; + struct clk_hw *hw; + struct clk_init_data init; + int ret; + + pll = kzalloc(sizeof(*pll), GFP_KERNEL); + if (!pll) + return ERR_PTR(-ENOMEM); + + pll->base = base; + + init.name = name; + init.ops = &clk_pllv4_ops; + init.parent_names = &parent_name; + init.num_parents = 1; + init.flags = CLK_SET_RATE_GATE; + + pll->hw.init = &init; + + hw = &pll->hw; + ret = clk_hw_register(NULL, hw); + if (ret) { + kfree(pll); + hw = ERR_PTR(ret); + } + + return hw; +} diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index d69c4bb..52f7c9d 100644 --- a/drivers/clk/imx/clk.h +++ b/drivers/clk/imx/clk.h @@ -42,6 +42,9 @@ enum imx_pllv3_type { struct clk *imx_clk_pllv3(enum imx_pllv3_type type, const char *name, const char *parent_name, void __iomem *base, u32 div_mask); +struct clk_hw *imx_clk_pllv4(const char *name, const char *parent_name, + void __iomem *base); + struct clk *clk_register_gate2(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 bit_idx, u8 cgr_val, -- 2.7.4