From patchwork Thu Jul 2 05:12:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 6707511 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2A6C39F38C for ; Thu, 2 Jul 2015 05:13:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BF85B2041A for ; Thu, 2 Jul 2015 05:13:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 513B8203C0 for ; Thu, 2 Jul 2015 05:12:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750784AbbGBFM6 (ORCPT ); Thu, 2 Jul 2015 01:12:58 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:44090 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751262AbbGBFM4 (ORCPT ); Thu, 2 Jul 2015 01:12:56 -0400 Received: from unknown (HELO relmlir3.idc.renesas.com) ([10.200.68.153]) by relmlie2.idc.renesas.com with ESMTP; 02 Jul 2015 14:12:55 +0900 Received: from relmlac1.idc.renesas.com (relmlac1.idc.renesas.com [10.200.69.21]) by relmlir3.idc.renesas.com (Postfix) with ESMTP id B73B74F844; Thu, 2 Jul 2015 14:12:55 +0900 (JST) Received: by relmlac1.idc.renesas.com (Postfix, from userid 0) id B482C8002E; Thu, 2 Jul 2015 14:12:55 +0900 (JST) Received: from relmlac1.idc.renesas.com (localhost [127.0.0.1]) by relmlac1.idc.renesas.com (Postfix) with ESMTP id AF37B8002D; Thu, 2 Jul 2015 14:12:55 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac1.idc.renesas.com with ESMTP id QAW25018; Thu, 2 Jul 2015 14:12:55 +0900 X-IronPort-AV: E=Sophos;i="5.15,390,1432566000"; d="scan'";a="190741518" Received: from mail-hk1lp0118.outbound.protection.outlook.com (HELO APAC01-HK1-obe.outbound.protection.outlook.com) ([207.46.51.118]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA; 02 Jul 2015 14:12:55 +0900 Received: from HKXPR06MB0599.apcprd06.prod.outlook.com (10.161.181.148) by HKXPR06MB0536.apcprd06.prod.outlook.com (10.161.137.26) with Microsoft SMTP Server (TLS) id 15.1.207.19; Thu, 2 Jul 2015 05:12:54 +0000 Authentication-Results: verge.net.au; dkim=none (message not signed) header.d=none; 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.201.16; Thu, 2 Jul 2015 05:12:52 +0000 Message-ID: <877fqjm9fv.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 1/4 v2][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 CC: Magnus , , YOSHIYUKI ITO , Hisao Munakata , Yusuke Goda , Yoshihiro Shimoda , TOSHIAKI KOMATSU , Gaku Inami In-Reply-To: <878uazm9gu.wl%kuninori.morimoto.gx@renesas.com> References: <878uazm9gu.wl%kuninori.morimoto.gx@renesas.com> Date: Thu, 2 Jul 2015 05:12:52 +0000 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: TY1PR01CA0051.jpnprd01.prod.outlook.com (25.164.162.161) To HKXPR06MB0599.apcprd06.prod.outlook.com (25.161.181.148) X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0599; 2:pYcRISIpx5fbecXhYF0BqDs6Fd+k6GqF+aRygJ3pR7lFmUFnYJR2veEZ1XOR0pPH; 3:EfRX6DKgU8pZWizvU4r+wD6aixcZXKdIhdHZpmBaP5NXTTZmgTWAy/VvDo7kDivATIhq0TAFlaCBe7i+JlN6sYXnlU/Z+VGD2YFvHFEojXvPBQI1kC01Y9c3BVVApCk42lg6W+qmuySZb2KaSgcxwQ==; 25:+qiaddIjHIi/hPDwpccG55cTucfqsuFg1v9+EYC2G7IUoIrIGZGAXEeI/jX1LfgGsmejuTt7OzFCZeEnDVhGsMVYyFHI2dxj6uvioQgRLfs+IaqblB77EENsdTPxsyJm/rBlIVagDdoDnUtoNLyRRQUR9iJESMRkvR1dRW3QQFi/MFbzZUTMypr3MrGjbahvqb5C8lm/diQNa8i4hsC2J1d2kWZBP4C1yWqBf+MdJvyplmkYLLNiu2Hs/y619Zda3F+1S7gFY8gzxy7/oDmzxw== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:; SRVR:HKXPR06MB0599; UriScan:; BCL:0; PCL:0; RULEID:; SRVR:HKXPR06MB0536; X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0599; 20:MsunKyVD9uUGkL4wdfWUcAz5MAZ22Sv6f6TsWbGfaSX6ugCZikDHCn1VIgL+jL2002QIqhikOlJJOV3YtOziCKKflL4EeNFyrZayQeQjfZPkSVlUFMxJzsmh6yfhYOWckAmSOuIKzsxnocu+IzDod/LFgrLXb18QT3vyfZaUSPuTXUgIUay93JX1sRWMYjjtQavil2waeRD2gtF2JMhEPDGOxEe7XoiydehOSbR2gXQjWeW6t3g7x8zqoS+o6x9Y98Bufz3TR9LkMqLvdm8gRy99TgrHPfrgkcKOPOtizJznzCpUU7CfjTmmfZSb8r7ASktxqqKwxb9x7P9zdeDk818FRyVOuzqha6Ztk5R7p6TMCRgKhsob1OP5LvCh08whOIdMzZkJuFpOvfSizkgkfo+yJR8LffRIFmWB5M52+M6ggbdlrHCxMXGnD5931iVCvppcliBOq6QU3BU4KIgxIgJjJnfkOJNWZ/JBz5PsXv6WH2EeekVg5+8OsvLKiD5S; 4:yaO+Htb0wugYyNvdK+POfIRQ5g7iit4bxgdQd4h+Y5TBCBcP1EKMWb+Xuat7ENPnvJGQsObHKwTqJrAni6HF8TerETT0eaitm+r9uvE3WvEsb3GSC42XcitGG/tcWGakBIdybCtzGzWEQW1hxPi7Uk9RFbwxsPfkKELdT+PiglGzu1CHlDRFAsNM554DmqonXeP4facqe6zVPA9jC3l8/AndeVoqbVz9b73mtThEgbtZrDK9yqP96j5SpVa4tVbKCdkTiKawSl7UriHBbaPXnWn8jDnspFRQ0eWtc0iPnNg= 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: 06259BA5A2 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(92566002)(2950100001)(19580405001)(66066001)(4001350100001)(87976001)(23726002)(19580395003)(189998001)(62966003)(122386002)(77156002)(54356999)(50986999)(76176999)(110136002)(86362001)(47776003)(107886002)(575784001)(5001960100002)(50466002)(77096005)(229853001)(33646002)(46102003)(53416004)(42186005)(40100003)(83506001)(46406003)(36756003)(2004002)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:HKXPR06MB0599; H:morimoto-PC.renesas.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0599; 23:VF9egOjnOrgtrhoy49dHqgx1ZJ7d88wQ7tT7/g6OkxdwMVRNH+BC6+c7DU31Lna6VlAuw2f7v7JQSAVmSRmNb8FGRJxsuWKr6MKKEW1H1NT2o/KV7SiwYYpO7hJiGRxrbUOJxfJQSTHDZ2Ly4KJamEK/7+Ht3W8KrjHUkVTS9wacp2FOkPtQ638Rlh8W0lFrKPxmlm7OGohHsm6GZMzuiTxDvpja9mXB6m0Ag+pWeCoZin1Q0QPw1nH2FS972jz0i9wG4b1WuNEVLnzCv6vScHSznsuph5LlPoJ7+xe5ZEFOmAcvDJPvjcQE72OsOW8sIDyzuSlIkEPgwBFn+2GVZu/2ED9wN63m+5ZWDcdT6vXwpSiiEcaE8h763ZGsUf6xPKkbe7Z6lJ4wc4uQHrCgwbk6FDJ+jWyd+rZ0InaOOxvHs2Oz2Yj8qPv/jZRiOqEum83Ohj7RwZgXbGB8wL//dwgEc5tvjlBradWbiHy5/oVkbH7G0evIpUVSyXYbKbfqe68dV42VCAYDP8dMEmRgP1cfPxJnbh2IrlTywkNZqzD/m86P5f+1H51mZn6TWLRFz7Iyz5TR28IEi/wwxTurx4OzEjFvQhfkVVW8w7sPfICuuK+ccqvKrfKeL3kqaoQB2IvIvTLmKXL+Ge34uoLYWghMvkB+RMQAjIziIuK5yOyZXeQKK+hDoYy3Pf/+aqGir5kDShm/xIw/2Yom03Xc8+xTATIKRnqFFCHhJHAU8Tn6u/6sUtVYacF5JV0HThypFgJZCSAvnmpHI9sNr2jDDCERXoKKcb5/jDFi+FK7TIPbC/Tk8TdAYkbJsC1nWgjm3vHX3CLZSWazQ8hHeQkKlrGUQrBcJlJmYSIg2S/C7VMX/asGLX0mPdxeLfIXa6f/ecqRdf+doz39o/L6506aVzkWlgmWxXFJmt1deViuZ zwsa/48oF6ir+z+S08t4hs6 X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0599; 5:XaZqQiEXUMplI/5FNicFKCT9ltaWMPCDT+Pw4qIVKEhMSvkPuhR0SSkTKZmzf/jAC8WLdd3B3JpXLRdi/blb0V298kFponJpVBm+SvxzeukIfEO6LcY/TVHt2R+of3KGYu0o4l9kH6OrEPh2LvGj8A==; 24:ogueZmOUuVETR5wR0rPcfU7qAtMIqJOlG9FZDXwy40/GlzTCFIiYHHzxt76HnINM2qLpWL2Tf0Ny3QAaCWv+nHqnyRLnlPdp46GGk9EdGzY=; 20:KAHVTCa3lmkOafZnIpvS+8ccLWq5QsVcyvTxobr/pM2w+d2ljrupatlbvj+fuU8zc1wpmI4mPaeP7l9CbbFPtYXb6MLxjmTpESkrMhcciLWgy9VU3amt4DAaAIwXlLsQ6MCdetxT3B4tWSazJ8uFQyYUul1Ejl997VeaDu8Zpls= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2015 05:12:52.0621 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HKXPR06MB0599 X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0536; 2:bQAfrXnN4Vq/JXGO4853CyjUYnCDiVgrom/U1lOewHwuMwJQmSh4UWHMJcqUurdL; 3:67I8TlSP+Y/kCUKftNTNWFu5PxVBlzQ7YPz3ftImn1F/wR7SH/AW4GWoxh7tV5fpqY7H+sS/7NOIbE4y/E3U1b3nMyiCPMscK+Jw/y9P63zTI4q+gdWtfCYLMdu1i2k6WT390DR7NlCyEgRwiME5Sw==; 25:EVyBbyfIyeroB9CjCx0BzWNlyKOfutaZ7fDPnyI+yAFdQzGSnsuLDV5R8lUnTeSZ9aENW4PlS4H93YXyDev0qRCdKG6bvoP/wBGDkMgVX39++GLZpzx/y/vUb0VP5vr3EJ/JsmKaj4w8y5OLrpRW3jNwGXCEYxPZdIauqlbkwo6gEToe0zsCR3czipqbueL7cS7bcsNhEqCXzZUcnL6VAQcsmBDwn4QXCE6nd8BG4GWv+/zzHrMvkpHZU6IFeDP5ctDIPPCpBxHuVlardwbg3Q==; 23:r/f/q28sM8XrHHtEkBpeIYkRfWrpfhLQDDwlC9/rxR2UtgislyeezLCWfAKZwZRFPq/5xFnpGIrtDuxa8pCnqtMl7FV25v5Ge2kLUDOoHWwgqcszGPts1U/h7S2arI4SI6u8TTAcFXF/cqgqrLs8VbqiQmtzN6t6YuJcRgRgmWIBT8o8AVbwuUJ63ew7/EOoo9G/sa7OTeeflx4uzECLVwYEOv8tZGv/fZvik/RYIWdD14aoButT8BmzmTkPs9sT X-OriginatorOrg: renesas.com 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.5 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. Signed-off-by: Gaku Inami Signed-off-by: Kuninori Morimoto --- v1 -> v2 - Add Copyright - Add DT Documentation - Don't care CPG write protection .../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);