From patchwork Thu Aug 9 14:45:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 10561503 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 7DF0813B4 for ; Thu, 9 Aug 2018 14:47:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6987F2B35C for ; Thu, 9 Aug 2018 14:47:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D32B2B49E; Thu, 9 Aug 2018 14:47:00 +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 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 C989F2B35C for ; Thu, 9 Aug 2018 14:46:54 +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=JghW7wwTaLK6qE4ivROKNJgP/rrv6GyYAEN2BaAPawg=; b=NCzAOJQqgYUnLS IUOYVHDL5uP4LVUJZnIF3YIMMvxngMFQUNCtsylauIWJSwFGeJ9r+Sw2TRxS+37r7jQ0uXlyUR704 rS7gr2LyAPXTUGXd1KJX2HciHfpM4Rphhyxd94DfDHxdKxw0SXcKS4sJwpojB5VMBpj+AuS5eNNpm 6IXvp8JZqj8q69jwXxNZohbRXj0YRz85jGGy3/s+jhB1+oxIlZ372e3LmrufmK3ZgdlGtO7KdnhIC 7n/vGjk/NdBEBbSicQAoeD0C0+UH9JJ590tjLmI34sIB7O6EP+/q+oim3n9Arbjgq0eVvyEWKgGIq V+oiJR35NShSEwf3gh5Q==; 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 1fnmDE-0003FW-Tl; Thu, 09 Aug 2018 14:46:52 +0000 Received: from mail-db3eur04on0604.outbound.protection.outlook.com ([2a01:111:f400:fe0c::604] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fnmCm-0002OY-W2 for linux-arm-kernel@lists.infradead.org; Thu, 09 Aug 2018 14:46:31 +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=lXf7qO38vaYskqGDfbVulsm2QujivvVj2Ne8jKVWVAk=; b=cEvOJGq3ZFt2rjSi0ghRP0JSUTT6CBXngfy6dd0EjS8IomMgzvhfOTtizp1BjlGpbyWFYbbResRl+KwP686ccW0s+2ABYIptCEKwdbqbULs8KMWvNv/RF3wGxEjPeElnG1CM2d95Q5UNS4zZ4w1P+tIGUejSs0arXtDKl7G6SbQ= Received: from fsr-ub1664-175.ea.freescale.net (95.76.156.53) by HE1PR04MB1611.eurprd04.prod.outlook.com (2a01:111:e400:59a9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1017.18; Thu, 9 Aug 2018 14:46:01 +0000 From: Abel Vesa To: Lucas Stach , Dong Aisheng , Pengutronix Kernel Team Subject: [PATCH v3 3/4] clk: imx: add SCCG PLL type Date: Thu, 9 Aug 2018 17:45:40 +0300 Message-Id: <1533825941-17224-4-git-send-email-abel.vesa@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1533825941-17224-1-git-send-email-abel.vesa@nxp.com> References: <1533825941-17224-1-git-send-email-abel.vesa@nxp.com> MIME-Version: 1.0 X-Originating-IP: [95.76.156.53] X-ClientProxiedBy: AM3PR04CA0141.eurprd04.prod.outlook.com (2603:10a6:207::25) To HE1PR04MB1611.eurprd04.prod.outlook.com (2a01:111:e400:59a9::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bb55c6a6-3b13-47b7-4dd0-08d5fe06d46a X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4618075)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:HE1PR04MB1611; X-Microsoft-Exchange-Diagnostics: 1; HE1PR04MB1611; 3:WkchbzzIIed0PkVC73Em8kPMhv686tsBSCQX7skkUiyBDbo5BcjJGeIkX6h7Gz2VBEeWp2waaCX9fTazcf5ISb431Yj7K4OICwypalzxtV13y65dSrASE41X22pNIqPgPZCLF+rUNOernUai7wyBXbU+Zzd9CfVz3TpkJpNeS+XWn43CaSk33cAuPd8P6oz7AYnsVkUQZsMDsH8LtAyx6Zf8Pq1+VVOc64BtLTeXWui/Y/BTo/r1WYp9HM+JtLXc; 25:QXOP2B5ne0YF6RFphn+j5umjCdaUQommT/baA8iAa4r7vI7crNNNOLx7hDK0BdejGSwkzhj+ZhbOeC88K/1jlvJl4yv7abb1Fw1e+23RwW7CX0O4yaIk0g+q90hSx/Enc0TW636EXW6MTzOowrj1D6VmdUMXBTW9AqiXy1yxCNgzWNt+Dtq3ADXreLgF+fVgWyFFGWP01lCXINl1dkJZBfhbobSILrZ7AgifMjM2d9L1OyeRBDIXnyU6xobTYTqmUsDVjSpDlGuudl5kxAqYSYDni9QMJhT3sDBbWAypSR26XmtJd/BnlVFAamvtr7+mNrBL5jWnkagrTXckaUtBNA==; 31:6fZt3ijtB6bX0BgiQYkmdkgiDN5H7wN+fNRlWtzrHe25oz5ICQ1+Wwbxn2/hlGp9l7k9P/tWDbL/01TCEWcTbUS+qyhfjKvzRea4wQs9JFcFNSiTKcAqYsrj18oS2MztEXGA5ggwtn2kiNv3i1ekRK9Jw4iB4Qt6CWg8w6Z1PNzL3cVmRfrjTS/mdjAWtWkJ1MtQJ5F2oTZlEKv7jxAVeUCcclGc50N5Oq3Hwv2eMJw= X-MS-TrafficTypeDiagnostic: HE1PR04MB1611: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=abel.vesa@nxp.com; X-Microsoft-Exchange-Diagnostics: 1; HE1PR04MB1611; 20:sGAJyCnuoC9GtafBYDFmtnfLbu4v0ceeCY+SWW1ij/9NlJloyT135CbFFhIX485ciCvEeVrjptcv78YHYvALSM0I4NsCy9dDWWAdupMlr4Suppi1UQle6eUTaQJTxC6vbBefOZJWjw5K2gadwUVeaPTtr96gYzetpj9wZXCmX3hUy33uXD9PTObOckbFCC+5xhczn2MKFvobq2tg136ITWpKly7I4KG1Aai+60QchSu2Nrl1hMWNiniuk8tPUvi5OBBGO4SutdCzD5EX+zXg6oZxo9aZGl53K8TcpeyU1eRi1clK3PlAMijfRwHRXzUYP3KW7kW6CsVFK8+9TavNtyrYYXi5tNDNYgy/wDMNkoW8AgqS++6jGcxhztCoNDgRGmD1AV5zclUCk5jOU6oo2lqKeNgtLaT7m19fUspZQJe1U1Uy03AxUKbb0BoIjTjVbAOtvZSpNxE5M+qScedOicad1NrXTULUng8FxPgjMUizAdFGLaJ4FYrtEbY0Xwkv; 4:/qWsHsRwUCE99y9dC7oop+LjdIvfd/bqs3NvaJ2cjGG7AAgRPleE+iA9gxFv23/DfvI3Z+Y+yMNiUdR8wzgn52rzU2V3rT7StbISRSHpoSXflQNAJRZXmJe8H3d3kSY5C4mP0MX80igT7KJwhf1gV/l0RfS2SmcXrBDeMICWw3syV1yQ/HTfUHvP0v2XLCf9fMoZLfl8vAEmAqaJG3tZPrIwdmVBdgvrWOUgK1D3GzFM5ofxhA4+xSgXhRy54natEso6ZArF6ed1aNa9QWBwW7G0Gr4G8PgvVsmG9OeYwxBGZ6KQlTQpdHvvKES3n0BO 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)(3231311)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:HE1PR04MB1611; BCL:0; PCL:0; RULEID:; SRVR:HE1PR04MB1611; X-Forefront-PRVS: 0759F7A50A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(396003)(376002)(366004)(346002)(136003)(189003)(199004)(8936002)(47776003)(50226002)(53936002)(6116002)(81156014)(54906003)(110136005)(81166006)(217873002)(8676002)(16586007)(5660300001)(68736007)(316002)(7736002)(305945005)(14444005)(6666003)(7416002)(51416003)(66066001)(52116002)(76176011)(36756003)(3846002)(25786009)(105586002)(97736004)(6506007)(386003)(106356001)(48376002)(6512007)(186003)(2906002)(16526019)(26005)(4326008)(50466002)(478600001)(476003)(446003)(44832011)(2616005)(6486002)(11346002)(956004)(86362001)(486006); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR04MB1611; H:fsr-ub1664-175.ea.freescale.net; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR04MB1611; 23:XW9g43fYOLiIanDABS4qJZ5hxMJAQzF2mPFIy7Qyu?= OYbfGpu/Veq8oXhjhJ8t0am9fbEI65k8wvEMTzHgQLIbC8NyuVi57JyVOew/DjcytXGdbnaPDbqTZMu7xxh7X46KrnEfy1yAGjMUAdU/TBtTNn1ci29JJEi+bLd8ZWT8rFMdzGNbPK64SV0auhy0l0nfh1t8/qylrWNvws60OmIr920hp01NfHi3ltM3gNpQAy3AY+YIiy0ItQqfh0Z+Jb3BasijZYjS2ROQMeDGvIsnti6WICciw0HmHixgDNnadtiqXF5KR84gunIGvEUuv9Do6aUC5jViD4+WedB9/8lka3USMue99+zSlia5d3zxgczYOw/vjoz5pssrVfzsdObEukkqy/eCH9IkZToLtB1hqcuy1ifXqf8ozVO2d9yruBBDCIrIx6og1o+dWnlDwrlVYymm7p9+KTXRlXBITlgYQrl0XZFqbrfw8kRJ7690Py4NSftUmZ+tqxkrC10qNlQp8TBEkypLsD6k8fmCrutbfzNq89h23GbJrNgMcKLfN1+ETdmV2ZuL/JyCj2frOdXCbSybiogMvkZslTAzV3kSaBbQBpHT0+u7uOFJ+c88HVQpDAyA+AZ+OuwMQ8SRHKc3KyfRQcJUw8I/w5zDRDrn8oYyq1Xu0M/DeLZ2H1Y+tvxZEYtrBtDnbCZ5WyMJGyAE6CTGO4+3/+PsS+X8SsfoM8rcg5llvvGpmLz8EbC4MVpBYIGHDhfRAajjbuBB27GetgJmdJPABwGwWXhnJELq01ZK7KRdPhgPa1SCQkeK61DNl2fMb1ymjcxleiVQIQsx2iT1V+UFsPtKJzzp5yVMlaYxVLCdWRLZcrxkG2iJ7vgqkXXF1aeMQf14DyOVOCi0YH/Rppy/NqBK5EHOezKrhcdX7TVIOYI3Hz7fvi62fhoBfl9LKWATGMXalcoFB5wcPH4IVMljlGeJV5FfoVddzsh59GN0eMC7ohceVxWbXB7y6eQDcFkA7HPiYYPiO1itI2P1RLiJv0gVj2DfmaTnC7OJaPaDN70luzjkGBxCyT2zIxKElI1tZvYzatajEFIRPDzOczc2EfTiun+Vh7rCMHEm0xeXwwD/BH4JloA1QSLO8lBCBXO434W3EgC+Tni8t2hIh4XuKKB1adLDR+86php3+LCqXYj1D/9tK6m+0sld3Q+/KMdJZwXZaltzm4oHpozZSa77SXnFnGW81oE7teob9mR5XwR/9qdkTfrh3GOQaNqrCef6UgDZk2bFo74 X-Microsoft-Antispam-Message-Info: drqPZHNv1rJayTks1sXrGF10dWB13GAfJTFQy1B6Md85afgmwrYhntOU1PNUME/27EL64pr/4z++kLkexsnOfm6iKU1WgdeUNo3PSKuatKl5dHEasHov/91c4aL+F5SijbuIXJpstwet5El/9yoDZ4I79iM1RvDpY/NWJEBYq23fJACR7W/gmX/ifasAn7hkP4XEFOLFNJInm5miPqvAx3CHGK8GR4JJpBy1uUN2V3hFoBUffmPkPtG6ug7Da0YVdzX09cJIJEMiJWFUVXWsEfwbWO3ghjtFMZL/lKaagUvFbX1liAxe27CTVjcPnOJYuhkFwYlV1TukhEG6REIaC0LULe0QhgcP/N6uoOo4ijw= X-Microsoft-Exchange-Diagnostics: 1; HE1PR04MB1611; 6:Wv9f3gtiA7WP7rLLhfAxlub+6w3K2FpmLA5qAw62Y1oMx+fuXUskjYYF1GbqnCCPnF4mYNFeeRKhdKzXRmm0fxRHHZNZPk46hitUzafrjIwzplmApkN5Is7qq5r1nu18N6yULH9wfZX3zNRngiggpUhb3WHthzg0AJj7Nsfr8nhOB1XxcRYJrPq84qzMFBmWdtw4ZdYY4v+A7wKuFbiP73B285JYu3edTTUdqLclDUGNMvV4Lhv0ToWEYsRR3OyT2TcKTayg7xGKdDPBY3ExtM8OXrWdr2CwT+aJfJRzOyyuCN6WUfswK3HlGFFOyJhvfIHVlhRHc4GjmmWvEfs7TTBpU5WVPwrm6IlfGungPfzLDR3MK4jTB65HsSumo4pGu/A2U5+Jbgejfnl4nVQP70BlsR8WQpPmzL+HTBYKDvS8ANwXbb3N8WCcRPmiA1DEtjIWMtWewFuA3B1n/bmlMw==; 5:cK5AxmskKUTKW3rQnEWFxGaDzGTMrXBiu1PmIsgBqwxjjO8GNESaYdasuzvbS9YfQcixwa+Gf2ZYon7Ei/7AaKN7dH3svEzfdzeRu92RLl+h2djmQTYuOSTosTOUVe9UhokcKMgdW1V1eZjqZRxKEJPgmh92fQyKv+JBzgxJBUA=; 7:4W17GIo/GvkcL8831kU9V1Fr+HMcSLBnpjXjEb7eBW0fodajIXtnTTmD9T2sEyQY5mDz6g+hXeTyiM0PQZu1/Mi1yWTkrqWs/k91JARTs/1o+898tkLxzetqvytJppCGuqbLTITaZJOIgXoKItWwPMtaM8NDthBj8NYrqAImNEb0HGtrNUPzkbHmAFOtCs+5Vy/EoQ2AcJONsOJcNfKggHNqcvjdd6qGtsQX2QeCQg+c3/AikhSkAEqd+xIk26A2 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2018 14:46:01.7308 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb55c6a6-3b13-47b7-4dd0-08d5fe06d46a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR04MB1611 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180809_074625_665032_0653691E X-CRM114-Status: GOOD ( 17.64 ) 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: Mark Rutland , Rob Herring , Abel Vesa , devicetree@vger.kernel.org, Stephen Boyd , Michael Turquette , linux-kernel@vger.kernel.org, linux-imx@nxp.com, Fabio Estevam , Shawn Guo , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 The SCCG is a new PLL type introduced on i.MX8. Add support for this. The driver currently misses the PLL lock check, as the preliminary documentation mentions lock configurations, but is quiet about where to find the actual lock status signal. Signed-off-by: Lucas Stach Signed-off-by: Abel Vesa --- drivers/clk/imx/Makefile | 3 +- drivers/clk/imx/clk-sccg-pll.c | 231 +++++++++++++++++++++++++++++++++++++++++ drivers/clk/imx/clk.h | 9 ++ 3 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 drivers/clk/imx/clk-sccg-pll.c diff --git a/drivers/clk/imx/Makefile b/drivers/clk/imx/Makefile index 4893c1f..b87513c 100644 --- a/drivers/clk/imx/Makefile +++ b/drivers/clk/imx/Makefile @@ -12,7 +12,8 @@ obj-y += \ clk-pllv1.o \ clk-pllv2.o \ clk-pllv3.o \ - clk-pfd.o + clk-pfd.o \ + clk-sccg-pll.o obj-$(CONFIG_SOC_IMX1) += clk-imx1.o obj-$(CONFIG_SOC_IMX21) += clk-imx21.o diff --git a/drivers/clk/imx/clk-sccg-pll.c b/drivers/clk/imx/clk-sccg-pll.c new file mode 100644 index 0000000..886ae03 --- /dev/null +++ b/drivers/clk/imx/clk-sccg-pll.c @@ -0,0 +1,231 @@ +// SPDX-License-Identifier: (GPL-2.0 OR MIT) +/* + * Copyright 2018 NXP. + */ + +#include +#include +#include +#include + +#include "clk.h" + +/* PLL CFGs */ +#define PLL_CFG0 0x0 +#define PLL_CFG1 0x4 +#define PLL_CFG2 0x8 + +#define PLL_DIVF1_SHIFT 13 +#define PLL_DIVF2_SHIFT 7 +#define PLL_DIVF_MASK 0x3f + +#define PLL_DIVR1_SHIFT 25 +#define PLL_DIVR2_SHIFT 19 +#define PLL_DIVR1_MASK 0x3 +#define PLL_DIVR2_MASK 0x3f +#define PLL_REF_SHIFT 0 +#define PLL_REF_MASK 0x3 + +#define PLL_LOCK 31 +#define PLL_PD 7 + +#define OSC_25M 25000000 +#define OSC_27M 27000000 + +struct clk_sccg_pll { + struct clk_hw hw; + void __iomem *base; +}; + +#define to_clk_sccg_pll(_hw) container_of(_hw, struct clk_sccg_pll, hw) + +static int clk_pll1_is_prepared(struct clk_hw *hw) +{ + struct clk_sccg_pll *pll = to_clk_sccg_pll(hw); + u32 val; + + val = readl_relaxed(pll->base + PLL_CFG0); + return (val & (1 << PLL_PD)) ? 0 : 1; +} + +static unsigned long clk_pll1_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct clk_sccg_pll *pll = to_clk_sccg_pll(hw); + u32 val, divf; + + val = readl_relaxed(pll->base + PLL_CFG2); + divf = (val >> PLL_DIVF1_SHIFT) & PLL_DIVF_MASK; + + return parent_rate * 2 * (divf + 1); +} + +static long clk_pll1_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *prate) +{ + unsigned long parent_rate = *prate; + u32 div; + + div = rate / (parent_rate * 2); + + return parent_rate * div * 2; +} + +static int clk_pll1_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct clk_sccg_pll *pll = to_clk_sccg_pll(hw); + u32 val; + u32 divf; + + divf = rate / (parent_rate * 2); + + val = readl_relaxed(pll->base + PLL_CFG2); + val &= ~(PLL_DIVF_MASK << PLL_DIVF1_SHIFT); + val |= (divf - 1) << PLL_DIVF1_SHIFT; + writel_relaxed(val, pll->base + PLL_CFG2); + + /* FIXME: PLL lock check */ + + return 0; +} + +static int clk_pll1_prepare(struct clk_hw *hw) +{ + struct clk_sccg_pll *pll = to_clk_sccg_pll(hw); + u32 val; + + val = readl_relaxed(pll->base); + val &= ~(1 << PLL_PD); + writel_relaxed(val, pll->base); + + /* FIXME: PLL lock check */ + + return 0; +} + +static void clk_pll1_unprepare(struct clk_hw *hw) +{ + struct clk_sccg_pll *pll = to_clk_sccg_pll(hw); + u32 val; + + val = readl_relaxed(pll->base); + val |= (1 << PLL_PD); + writel_relaxed(val, pll->base); +} + +static unsigned long clk_pll2_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct clk_sccg_pll *pll = to_clk_sccg_pll(hw); + u32 val, ref, divr1, divf1, divr2, divf2; + u64 temp64; + + val = readl_relaxed(pll->base + PLL_CFG0); + switch ((val >> PLL_REF_SHIFT) & PLL_REF_MASK) { + case 0: + ref = OSC_25M; + break; + case 1: + ref = OSC_27M; + break; + default: + ref = OSC_25M; + break; + } + + val = readl_relaxed(pll->base + PLL_CFG2); + divr1 = (val >> PLL_DIVR1_SHIFT) & PLL_DIVR1_MASK; + divr2 = (val >> PLL_DIVR2_SHIFT) & PLL_DIVR2_MASK; + divf1 = (val >> PLL_DIVF1_SHIFT) & PLL_DIVF_MASK; + divf2 = (val >> PLL_DIVF2_SHIFT) & PLL_DIVF_MASK; + + temp64 = ref * 2; + temp64 *= (divf1 + 1) * (divf2 + 1); + + do_div(temp64, (divr1 + 1) * (divr2 + 1)); + + return (unsigned long)temp64; +} + +static long clk_pll2_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *prate) +{ + u32 div; + unsigned long parent_rate = *prate; + + div = rate / (parent_rate); + + return parent_rate * div; +} + +static int clk_pll2_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + u32 val; + u32 divf; + struct clk_sccg_pll *pll = to_clk_sccg_pll(hw); + + divf = rate / (parent_rate); + + val = readl_relaxed(pll->base + PLL_CFG2); + val &= ~(PLL_DIVF_MASK << PLL_DIVF2_SHIFT); + val |= (divf - 1) << PLL_DIVF2_SHIFT; + writel_relaxed(val, pll->base + PLL_CFG2); + + /* FIXME: PLL lock check */ + + return 0; +} + +static const struct clk_ops clk_sccg_pll1_ops = { + .is_prepared = clk_pll1_is_prepared, + .recalc_rate = clk_pll1_recalc_rate, + .round_rate = clk_pll1_round_rate, + .set_rate = clk_pll1_set_rate, +}; + +static const struct clk_ops clk_sccg_pll2_ops = { + .prepare = clk_pll1_prepare, + .unprepare = clk_pll1_unprepare, + .recalc_rate = clk_pll2_recalc_rate, + .round_rate = clk_pll2_round_rate, + .set_rate = clk_pll2_set_rate, +}; + +struct clk *imx_clk_sccg_pll(const char *name, + const char *parent_name, + void __iomem *base, + enum imx_sccg_pll_type pll_type) +{ + struct clk_sccg_pll *pll; + struct clk *clk; + struct clk_init_data init; + + pll = kzalloc(sizeof(*pll), GFP_KERNEL); + if (!pll) + return ERR_PTR(-ENOMEM); + + pll->base = base; + init.name = name; + switch (pll_type) { + case SCCG_PLL1: + init.ops = &clk_sccg_pll1_ops; + break; + case SCCG_PLL2: + init.ops = &clk_sccg_pll2_ops; + break; + } + + 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 13daf1c..12b3fd6 100644 --- a/drivers/clk/imx/clk.h +++ b/drivers/clk/imx/clk.h @@ -21,6 +21,11 @@ enum imx_pllv1_type { IMX_PLLV1_IMX35, }; +enum imx_sccg_pll_type { + SCCG_PLL1, + SCCG_PLL2, +}; + struct clk *imx_clk_pllv1(enum imx_pllv1_type type, const char *name, const char *parent, void __iomem *base); @@ -30,6 +35,10 @@ struct clk *imx_clk_pllv2(const char *name, const char *parent, struct clk *imx_clk_frac_pll(const char *name, const char *parent_name, void __iomem *base); +struct clk *imx_clk_sccg_pll(const char *name, const char *parent_name, + void __iomem *base, + enum imx_sccg_pll_type pll_type); + enum imx_pllv3_type { IMX_PLLV3_GENERIC, IMX_PLLV3_SYS,