From patchwork Fri Aug 7 03:15:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 6964721 X-Patchwork-Delegate: horms@verge.net.au Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 85569C05AC for ; Fri, 7 Aug 2015 03:15:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 17E34206D5 for ; Fri, 7 Aug 2015 03:15:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A0DB4206B2 for ; Fri, 7 Aug 2015 03:15:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752623AbbHGDPS (ORCPT ); Thu, 6 Aug 2015 23:15:18 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:24710 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752524AbbHGDPQ (ORCPT ); Thu, 6 Aug 2015 23:15:16 -0400 Received: from unknown (HELO relmlir3.idc.renesas.com) ([10.200.68.153]) by relmlie2.idc.renesas.com with ESMTP; 07 Aug 2015 12:15:14 +0900 Received: from relmlac4.idc.renesas.com (relmlac4.idc.renesas.com [10.200.69.24]) by relmlir3.idc.renesas.com (Postfix) with ESMTP id 29E6F4BDFB; Fri, 7 Aug 2015 12:15:14 +0900 (JST) Received: by relmlac4.idc.renesas.com (Postfix, from userid 0) id 266F8480A3; Fri, 7 Aug 2015 12:15:14 +0900 (JST) Received: from relmlac4.idc.renesas.com (localhost [127.0.0.1]) by relmlac4.idc.renesas.com (Postfix) with ESMTP id 2003148014; Fri, 7 Aug 2015 12:15:14 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac4.idc.renesas.com with ESMTP id NAP14725; Fri, 7 Aug 2015 12:15:14 +0900 X-IronPort-AV: E=Sophos;i="5.15,626,1432566000"; d="scan'";a="193170272" Received: from mail-hk1lp0123.outbound.protection.outlook.com (HELO APAC01-HK1-obe.outbound.protection.outlook.com) ([207.46.51.123]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA; 07 Aug 2015 12:15:12 +0900 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=kuninori.morimoto.gx@renesas.com; Received: from morimoto-PC.renesas.com (211.11.155.144) by HKXPR06MB0599.apcprd06.prod.outlook.com (10.161.181.148) with Microsoft SMTP Server (TLS) id 15.1.225.19; Fri, 7 Aug 2015 03:15:11 +0000 Message-ID: <877fp7eqrt.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 01/16 v5][RFC] clk: shmobile: add Renesas R-Car Gen3 CPG support User-Agent: Wanderlust/2.15.9 Emacs/24.3 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") To: Simon , Geert Uytterhoeven CC: YOSHIYUKI ITO , Magnus , Linux-SH , Gaku Inami , shimoda , munakata , komatsu , goda Date: Fri, 7 Aug 2015 03:15:11 +0000 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: TY1PR01CA0016.jpnprd01.prod.outlook.com (25.161.131.154) To HKXPR06MB0599.apcprd06.prod.outlook.com (25.161.181.148) X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0599; 2:GsT8hwu1gpUEyLHYP4eG6RGG/qpFRHzRq8awuC1eTk2Qh0MtKRVIHMETW04RXE8JMY7qIopX+v5LY2aChUeMT9mtMunTyT/gfqQTtkAC2cIMsT6rzspm3kTD2gpkSRlXLcbMbfE2HKeJCNZo9IVfpJqL7jjVhDXvYnmdpBpyxiY=; 3:DPh+UOymlBCvoD7K1U2qG+c1fXf1ThzpSrxfcH+kBSeSWe/8yrvgPyxxGrM0+mzj/l8KNyA1LxTWwnx22OjjgWRqDBweG92lAHaYRVwghdO3YIvjtLS0FvzT3kXscaFM5/sTH1z9mAbYPOMAvxexWA==; 25:8ID59YsnS8M7aNQ20s2hrVBGyC5hV+LoaXg998jwOsfIHYzRrWcH2fdPxf5A/WxHS6k7a3tOrJITLuFBTmhgjzHSVvJjpHeDG8eiSi8nRThJrdilds2YCqqLJFd9cBLJex8aIT0PH15vmzLGncRDvK09Jw4wOqPemrgCzPCy3hN8A2HvQEg93X6jemp9Xxu6qSpIQ6t8cGRmmYgCSrM4UpvDXjrNKKgZbiBtiW9i5W0PivvEjUQymrKObPcLD86uuqYSQOwk9svEaQAAnOkgAg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HKXPR06MB0599; X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0599; 20:9TM2myW7Xza9FvTIZ01s5TL7t/5S6MyhKse94xUirrmNA34F0jp/vNbDAF9aesPdAqqJXoMquLoHkHsgeww2+FY/G8wK3AoFojcNGQVAKyv/NTUClXEiqQU1Vjk8mKgX8KXGzUwSnxYldGtXdEaTfgzEl/g3q6PcKEKmy57RjpYhFCP2U6JuggEkfy3zWTXzSe45lTaxmlpVfdCRksKpSeQFqKW51/NAV5y49wtM09Gd7WXUUJdxxaaQG5AXFrVZJfM53k4qeR4BsNmipRX5vb0qlAhs4Jm9F0p3ctd3GrIRZms1K5L2c+zD0LhFTIbjG71h1PzPEchSVEvDN/MXh4qHILUaahQNqsI64lhUoV5LjkabdzaeN7DgIT+3MKieAzr+vlJ313vCB2y1BfNP7wjOodawXVaFAiZcj6/2rSuKPHPImRu70/g3+do/GVKAwB1iLrzAcC9c4pP+0MsBveIgc287nEuyYjqRCYv74dTGG7P6el8R78Y8rzhp8jIU; 4:/IUVthQPlVFHRB6widmNOnQzbOz6XApvrKkrgx+COhiVI0UKBhz43I4oen5hiEaMQ6TdHR2DY3tLKOGCEzJiO0NISsfhRw/D86dn1JoPUR04zNxylNZTn5ZCdkFPgN5qyh+bGgdcabFzVU2Vphsa3oEUo7GbOnLGQMNxx1SZohlph3EKPhWCrFYs4ygZ2BHBfWOgWCMv/xMzNHe8wHtEJ40SjlA9JKU3fbAnkqQt4dDzki3f9obAEU6UsS4TUcKO9CQxMtZYbSmvvzJgcZ4xmf67pzJ9Lzl+dVxN8Na0hmQ= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:HKXPR06MB0599; BCL:0; PCL:0; RULEID:; SRVR:HKXPR06MB0599; X-Forefront-PRVS: 066153096A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(199003)(189002)(189998001)(69596002)(83506001)(19580395003)(19580405001)(54356999)(42186005)(46406003)(50986999)(53416004)(575784001)(87976001)(50466002)(86362001)(101416001)(23726002)(33646002)(105586002)(36756003)(46102003)(229853001)(106356001)(122386002)(107886002)(64706001)(92566002)(81156007)(47776003)(4001540100001)(5001860100001)(5001830100001)(77096005)(77156002)(5001960100002)(40100003)(97736004)(5001770100001)(62966003)(68736005)(66066001)(4001350100001)(2004002)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:HKXPR06MB0599; H:morimoto-PC.renesas.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HKXPR06MB0599; 23:n35jhRip6cJ7pO0Dw/skZB44n5maZW5lCvXT7bRbQ?= =?us-ascii?Q?I0ynK0gfu2jZyGQxElesCoiVVwR/Csi+WPr57Cxn1F3Xs3fdmZ6/5UAYedJ7?= =?us-ascii?Q?mNmbwDDP4DMCWINPrdNUWdiFek9B29zDIdFUEliP2y5r4mLS/5EazL+3UfV4?= =?us-ascii?Q?606CDXi13RMDhB0xVdionmRezQ3Yl8Dw1ttQYNKgCvHYowy02w7VqI0zoWZg?= =?us-ascii?Q?axU6ao35Do6jDYoBovApZg8/aqNFaGt8KbIWk/jxFWIcyxdS/H2/8sNxB75O?= =?us-ascii?Q?BmEDfGPMf+dkQy1GbD+sH6EGW6ofHa/tE7kv0RDjt/3/BuCsFmlN+x7JQa1N?= =?us-ascii?Q?nRBxe59bo80plWjaAxuVxLCP4BGon5ThWA0ZaaboV5oxWCdVb696nlqVX1pk?= =?us-ascii?Q?EAlLly8GQDtwkrbjHfkIP1XqReAclpevvMtxVdPQg7ylHg4CnORt1Mzg00kx?= =?us-ascii?Q?P9MaqFCG/VT3/IzPyRm8iugHKOrSbXuXJg4GCyK519zkIqXayaKeEGWO3nEs?= =?us-ascii?Q?PxMON8pIQ28t+Q/rbsooVXQRl6P8UdXs4jo9DyriP/USXDnS0RhCQSI1zgPJ?= =?us-ascii?Q?RZWFauQ1paq+J57eKUicir8eAqjQz5wjXe/kS6uF6jhl0xRnuuStzTDhq3O7?= =?us-ascii?Q?vdK/WjyB+YLsu2jgs53TVkYSHzPydn2IBIzrUNzBfZRaoQVXXs/cwucdHkgN?= =?us-ascii?Q?K4dTXnKzE+AeD0MXOG4xzfjWrgD7Hn6bsMdOASyuclHDxCHioVvuuFwUCq5a?= =?us-ascii?Q?z0irOp0buAKmuwqukg2F4mic1t8iaMqbISSd2dBGtvz5wV28bmezVQ7GrTfD?= =?us-ascii?Q?YDKz5Qp7av+sRZOtCuU7SUyozT7/DRoBBVuAzB8nFLQnu7Ctl6qqXvVgauh/?= =?us-ascii?Q?Qfu91+DiuiIjfHe31Bj+XOM6f8Fe2qjMdTxhZTGSRRWZssjaKF15haGyOmYV?= =?us-ascii?Q?bnT0yp+svhOVUtsCtpjpLb0Hg5/bzD5Dabx883umULoy5LjOt/35NNKBqWDe?= =?us-ascii?Q?KOPFAqkIFHKTECUDdf6ALhSVX/aJzYiCn3cnxmAKgZHRh/S3zES8oKb8vtBF?= =?us-ascii?Q?lxyihQwkc2piBUBpy1btxZbNWZ003DqstuS1cEfj4Pv3mFOLblRpt/1CXv/H?= =?us-ascii?Q?6H3qGeYVSVdiEWayoWoL23p1euwySr8FwbsZl+VrTwZip5zP38pkDvHlCVjJ?= =?us-ascii?Q?ip0qfkO9fgk+t9ZmsAbeeejDyBkY/fh1lLrdSzXATHKI7hVoLfY6sEkIA=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0599; 5:Mq5N7KwYOagDCpOsS8RjkbRjXaAskh/dXJNhLbqt6q0XjCp79170hy6fEcNsIHDkVd9VxRcqg4OZRezk5d+BJwC4wJr/Fgm06qNsb6NPgozz0JgBkDrHz8+L3TKH+iYADGwy/iKm3aMIxsVSYRzLsA==; 24:bIyQ+S6QLmud281jNz+Tb2uPots+C5HiqNtpJhfyhHIKmlDeHvj17UcpxvGHE5gBv/zpvso0IW5VmsJZAFNuFtrSweFlK/oSTGL2PrM+WFQ=; 20:uVBTQ7OWch40pyI18fdb0ra1fal/0bym7bHuyOM2LVIYzuQC6JEmHQjl8SZ3HKjh076/na67sMk5+Oqy6V59oiQr+2pIhgQY74/4JaxyqqgcruMgK8piKkMjriVkgkiR14+8dWOLclP8DSL3iJKGEWnzrpddZKExPTMxEXh0Q14= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2015 03:15:11.1802 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HKXPR06MB0599 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Gaku Inami This patch adds very initial CPG support. R-Car Gen3 write function should use CPG write protection method which is shared with MSTP driver. This patch has it but not used. # this should be replaced Signed-off-by: Gaku Inami Signed-off-by: Kuninori Morimoto --- v4 -> v5 - no change .../clock/renesas,rcar-gen3-cpg-clocks.txt | 31 +++ drivers/clk/shmobile/Makefile | 1 + drivers/clk/shmobile/clk-rcar-gen3.c | 232 +++++++++++++++++++++ 3 files changed, 264 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/renesas,rcar-gen3-cpg-clocks.txt create mode 100644 drivers/clk/shmobile/clk-rcar-gen3.c diff --git a/Documentation/devicetree/bindings/clock/renesas,rcar-gen3-cpg-clocks.txt b/Documentation/devicetree/bindings/clock/renesas,rcar-gen3-cpg-clocks.txt new file mode 100644 index 0000000..b1a7e01 --- /dev/null +++ b/Documentation/devicetree/bindings/clock/renesas,rcar-gen3-cpg-clocks.txt @@ -0,0 +1,31 @@ +* Renesas R-Car Gen3 Clock Pulse Generator (CPG) + +The CPG generates core clocks for the R-Car Gen3 SoCs. It includes three PLLs +and several fixed ratio dividers. + +Required Properties: + + - compatible: Must be one of + - "renesas,r8a7795-cpg-clocks" for the r8a7795 CPG + - "renesas,rcar-gen3-cpg-clocks" for the generic R-Car Gen3 CPG + + - reg: Base address and length of the memory resource used by the CPG + + - clocks: References to the parent clocks: first to the EXTAL clock + - #clock-cells: Must be 1 + - clock-output-names: The names of the clocks. Supported clocks are + "main", "pll0", "pll1", "pll2", "pll3", "pll4" + + +Example +------- + + cpg_clocks: cpg_clocks@e6150000 { + compatible = "renesas,r8a7795-cpg-clocks", + "renesas,rcar-gen3-cpg-clocks"; + reg = <0 0xe6150000 0 0x1000>; + clocks = <&extal_clk>; + #clock-cells = <1>; + clock-output-names = "main", "pll0", "pll1","pll2", + "pll3", "pll4"; + }; diff --git a/drivers/clk/shmobile/Makefile b/drivers/clk/shmobile/Makefile index 97c71c8..4e70a73 100644 --- a/drivers/clk/shmobile/Makefile +++ b/drivers/clk/shmobile/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_ARCH_R8A7790) += clk-rcar-gen2.o obj-$(CONFIG_ARCH_R8A7791) += clk-rcar-gen2.o obj-$(CONFIG_ARCH_R8A7793) += clk-rcar-gen2.o obj-$(CONFIG_ARCH_R8A7794) += clk-rcar-gen2.o +obj-$(CONFIG_ARCH_RCAR_GEN3) += clk-rcar-gen3.o obj-$(CONFIG_ARCH_SH73A0) += clk-sh73a0.o obj-$(CONFIG_ARCH_SHMOBILE_MULTI) += clk-div6.o obj-$(CONFIG_ARCH_SHMOBILE_MULTI) += clk-mstp.o diff --git a/drivers/clk/shmobile/clk-rcar-gen3.c b/drivers/clk/shmobile/clk-rcar-gen3.c new file mode 100644 index 0000000..098caac --- /dev/null +++ b/drivers/clk/shmobile/clk-rcar-gen3.c @@ -0,0 +1,232 @@ +/* + * rcar_gen3 Core CPG Clocks + * + * Copyright (C) 2015 Renesas Electronics Corp. + * + * Based on rcar_gen2 Core CPG Clocks driver. + * + * 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; version 2 of the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct rcar_gen3_cpg { + struct clk_onecell_data data; + spinlock_t lock; + void __iomem *reg; +}; + +#define CPG_PLL0CR 0x00d8 +#define CPG_PLL2CR 0x002c + +/* + * common function + */ +#define rcar_clk_readl(cpg, _reg) clk_readl(cpg->reg + _reg) + +/* + * Reset register definitions. + */ +#define MODEMR 0xe6160060 + +static u32 rcar_gen3_read_mode_pins(void) +{ + static u32 mode; + static bool mode_valid; + + if (!mode_valid) { + void __iomem *modemr = ioremap_nocache(MODEMR, 4); + + BUG_ON(!modemr); + mode = ioread32(modemr); + iounmap(modemr); + mode_valid = true; + } + + return mode; +} + +/* ----------------------------------------------------------------------------- + * CPG Clock Data + */ + +/* + * MD EXTAL PLL0 PLL1 PLL2 PLL3 PLL4 + * 14 13 19 17 (MHz) *1 *1 *1 + *------------------------------------------------------------------- + * 0 0 0 0 16.66 x 1 x180/2 x192/2 x144/2 x192 x144 + * 0 0 0 1 16.66 x 1 x180/2 x192/2 x144/2 x128 x144 + * 0 0 1 0 Prohibited setting + * 0 0 1 1 16.66 x 1 x180/2 x192/2 x144/2 x192 x144 + * 0 1 0 0 20 x 1 x150/2 x156/2 x120/2 x156 x120 + * 0 1 0 1 20 x 1 x150/2 x156/2 x120/2 x106 x120 + * 0 1 1 0 Prohibited setting + * 0 1 1 1 20 x 1 x150/2 x156/2 x120/2 x156 x120 + * 1 0 0 0 25 x 1 x120/2 x128/2 x96/2 x128 x96 + * 1 0 0 1 25 x 1 x120/2 x128/2 x96/2 x84 x96 + * 1 0 1 0 Prohibited setting + * 1 0 1 1 25 x 1 x120/2 x128/2 x96/2 x128 x96 + * 1 1 0 0 33.33 / 2 x180/2 x192/2 x144/2 x192 x144 + * 1 1 0 1 33.33 / 2 x180/2 x192/2 x144/2 x128 x144 + * 1 1 1 0 Prohibited setting + * 1 1 1 1 33.33 / 2 x180/2 x192/2 x144/2 x192 x144 + * + * *1 : datasheet indicates VCO output (PLLx = VCO/2) + * + */ +#define CPG_PLL_CONFIG_INDEX(md) ((((md) & BIT(14)) >> 11) | \ + (((md) & BIT(13)) >> 11) | \ + (((md) & BIT(19)) >> 18) | \ + (((md) & BIT(17)) >> 17)) +struct cpg_pll_config { + unsigned int extal_div; + unsigned int pll1_mult; + unsigned int pll3_mult; + unsigned int pll4_mult; +}; + +static const struct cpg_pll_config cpg_pll_configs[16] __initconst = { +/* EXTAL div PLL1 PLL3 PLL4 */ + { 1, 192, 192, 144, }, + { 1, 192, 128, 144, }, + { 0, 0, 0, 0, }, /* Prohibited setting */ + { 1, 192, 192, 144, }, + { 1, 156, 156, 120, }, + { 1, 156, 106, 120, }, + { 0, 0, 0, 0, }, /* Prohibited setting */ + { 1, 156, 156, 120, }, + { 1, 128, 128, 96, }, + { 1, 128, 84, 96, }, + { 0, 0, 0, 0, }, /* Prohibited setting */ + { 1, 128, 128, 96, }, + { 2, 192, 192, 144, }, + { 2, 192, 128, 144, }, + { 0, 0, 0, 0, }, /* Prohibited setting */ + { 2, 192, 192, 144, }, +}; + +/* ----------------------------------------------------------------------------- + * Initialization + */ + +static u32 cpg_mode __initdata; + +static struct clk * __init +rcar_gen3_cpg_register_clock(struct device_node *np, struct rcar_gen3_cpg *cpg, + const struct cpg_pll_config *config, + const char *name) +{ + const char *parent_name; + unsigned int mult = 1; + unsigned int div = 1; + + if (!strcmp(name, "main")) { + parent_name = of_clk_get_parent_name(np, 0); + div = config->extal_div; + } else if (!strcmp(name, "pll0")) { + /* PLL0 is a configurable multiplier clock. Register it as a + * fixed factor clock for now as there's no generic multiplier + * clock implementation and we currently have no need to change + * the multiplier value. + */ + u32 value = rcar_clk_readl(cpg, CPG_PLL0CR); + + parent_name = "main"; + mult = ((value >> 24) & ((1 << 7) - 1)) + 1; + } else if (!strcmp(name, "pll1")) { + parent_name = "main"; + mult = config->pll1_mult / 2; + } else if (!strcmp(name, "pll2")) { + /* PLL2 is a configurable multiplier clock. Register it as a + * fixed factor clock for now as there's no generic multiplier + * clock implementation and we currently have no need to change + * the multiplier value. + */ + u32 value = rcar_clk_readl(cpg, CPG_PLL2CR); + + parent_name = "main"; + mult = ((value >> 24) & ((1 << 7) - 1)) + 1; + } else if (!strcmp(name, "pll3")) { + parent_name = "main"; + mult = config->pll3_mult; + } else if (!strcmp(name, "pll4")) { + parent_name = "main"; + mult = config->pll4_mult; + } else { + return ERR_PTR(-EINVAL); + } + + return clk_register_fixed_factor(NULL, name, parent_name, 0, mult, div); +} + +static void __init rcar_gen3_cpg_clocks_init(struct device_node *np) +{ + const struct cpg_pll_config *config; + struct rcar_gen3_cpg *cpg; + struct clk **clks; + unsigned int i; + int num_clks; + + cpg_mode = rcar_gen3_read_mode_pins(); + + num_clks = of_property_count_strings(np, "clock-output-names"); + if (num_clks < 0) { + pr_err("%s: failed to count clocks\n", __func__); + return; + } + + cpg = kzalloc(sizeof(*cpg), GFP_KERNEL); + clks = kzalloc((num_clks * sizeof(*clks)), GFP_KERNEL); + if (cpg == NULL || clks == NULL) { + /* We're leaking memory on purpose, there's no point in cleaning + * up as the system won't boot anyway. + */ + pr_err("%s: failed to allocate cpg\n", __func__); + return; + } + + spin_lock_init(&cpg->lock); + + cpg->data.clks = clks; + cpg->data.clk_num = num_clks; + + cpg->reg = of_iomap(np, 0); + if (WARN_ON(cpg->reg == NULL)) + return; + + config = &cpg_pll_configs[CPG_PLL_CONFIG_INDEX(cpg_mode)]; + if (!config->extal_div) { + pr_err("%s: Prohibited setting (cpg_mode=0x%x)\n", + __func__, cpg_mode); + return; + } + + for (i = 0; i < num_clks; ++i) { + const char *name; + struct clk *clk; + + of_property_read_string_index(np, "clock-output-names", i, + &name); + + clk = rcar_gen3_cpg_register_clock(np, cpg, config, name); + if (IS_ERR(clk)) + pr_err("%s: failed to register %s %s clock (%ld)\n", + __func__, np->name, name, PTR_ERR(clk)); + else + cpg->data.clks[i] = clk; + } + + of_clk_add_provider(np, of_clk_src_onecell_get, &cpg->data); +} +CLK_OF_DECLARE(rcar_gen3_cpg_clks, "renesas,rcar-gen3-cpg-clocks", + rcar_gen3_cpg_clocks_init);