From patchwork Mon Aug 3 01:52:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 6926561 X-Patchwork-Delegate: horms@verge.net.au 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 083AB9F373 for ; Mon, 3 Aug 2015 01:52:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A0367203B8 for ; Mon, 3 Aug 2015 01:52:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3BEC62028D for ; Mon, 3 Aug 2015 01:52:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752212AbbHCBwu (ORCPT ); Sun, 2 Aug 2015 21:52:50 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:20881 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752103AbbHCBwt (ORCPT ); Sun, 2 Aug 2015 21:52:49 -0400 Received: from unknown (HELO relmlir1.idc.renesas.com) ([10.200.68.151]) by relmlie2.idc.renesas.com with ESMTP; 03 Aug 2015 10:52:47 +0900 Received: from relmlac3.idc.renesas.com (relmlac3.idc.renesas.com [10.200.69.23]) by relmlir1.idc.renesas.com (Postfix) with ESMTP id 932A9474DB; Mon, 3 Aug 2015 10:52:47 +0900 (JST) Received: by relmlac3.idc.renesas.com (Postfix, from userid 0) id 76B361806F; Mon, 3 Aug 2015 10:52:47 +0900 (JST) Received: from relmlac3.idc.renesas.com (localhost [127.0.0.1]) by relmlac3.idc.renesas.com (Postfix) with ESMTP id 720BB1800A; Mon, 3 Aug 2015 10:52:47 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac3.idc.renesas.com with ESMTP id LAG11163; Mon, 3 Aug 2015 10:52:47 +0900 X-IronPort-AV: E=Sophos;i="5.15,598,1432566000"; d="scan'";a="192825905" Received: from mail-hk1lp0117.outbound.protection.outlook.com (HELO APAC01-HK1-obe.outbound.protection.outlook.com) ([207.46.51.117]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA; 03 Aug 2015 10:52:46 +0900 Authentication-Results: verge.net.au; dkim=none (message not signed) header.d=none; Received: from morimoto-PC.renesas.com (211.11.155.144) by SG2PR06MB0602.apcprd06.prod.outlook.com (10.161.10.152) with Microsoft SMTP Server (TLS) id 15.1.225.19; Mon, 3 Aug 2015 01:52:43 +0000 Message-ID: <87614xw38d.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 1/4 v3][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 , Magnus CC: , Geert Uytterhoeven In-Reply-To: <877fpdw3av.wl%kuninori.morimoto.gx@renesas.com> References: <877fpdw3av.wl%kuninori.morimoto.gx@renesas.com> Date: Mon, 3 Aug 2015 01:52:43 +0000 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: OS1PR01CA0034.jpnprd01.prod.outlook.com (25.164.162.18) To SG2PR06MB0602.apcprd06.prod.outlook.com (25.161.10.152) X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0602; 2:dUymKV6w5EprJnqLr4ZEKUltXkdvIXKbMOOgTexh3qaID4dUswOH4rMcMPfNdW/1asoSmMiK4c+EIDGaYDdH3JWmATqgCYUYiWu8qYLMBs617rmXtBv4osU7FyeYuBUyNOBaTRilPNy6BI7qZcoLD24UFVx3eI7yMcr3mG/JRg4=; 3:gIzt0wl/Wo1q9L0np4iBZiteLEbSaOSqpmmrP+n02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5NPadn4Hn8lUqmar8TnSDwGUD6+xsY32FdWbPPxD8sdx6DB/+mdIn1N434o6YZ9I2+e84o2x3n3cLxZfcIrgnOzqotJJGmoVXTiAtXDUXnR0l5LzAnpjsKxswlW8wN3my2M5XF2tc8s+dzD0k1d/9Mq+RoU3Q/jsHT5Ctp8PXtgATYyIfiYjJUCDJaGtgpBabfukVKxRiIwnRhy9JbtQ8q7YVEk= 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:SG2PR06MB0602; BCL:0; PCL:0; RULEID:; SRVR:SG2PR06MB0602; X-Forefront-PRVS: 0657D528EC X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(5001770100001)(4001350100001)(36756003)(50986999)(76176999)(33646002)(229853001)(54356999)(23726002)(46406003)(5001960100002)(92566002)(77096005)(2950100001)(122386002)(62966003)(77156002)(66066001)(189998001)(19580405001)(19580395003)(83506001)(40100003)(575784001)(47776003)(46102003)(50466002)(53416004)(42186005)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:SG2PR06MB0602; H:morimoto-PC.renesas.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0602; 23:38AwogX3o8D0KkKfOxNg+ohMLVc6A/9lntJrhX12lnGNV6XYW1IhErp1PLw0jSVWD5/bDbk3x1zJuPWjs1amAIhnxGDgjg6j1zfyt1I1+Mpty0AHb2BRwUn7aL1qemo0ruSgi2VpZc3SJiwamyAuS+No42gxDdiJGs8haTTYsm+7s8SQr8O3XmGTbkAOkr70GD8CbnaVaV79KqLDAz3eRpOSXzRusMvxzysNICdbzEex6/UBt85SKlSi2LGsUNCnEGy22QmNwYZKPDndSzXfyboyj3kn8YRLMynjwE5h5svepfsKU9FBA1WUvc+LA9+mTDJ6XSyNrhfnUduZurGvG/p6w6XVtsrKvssNBeVthX/XG+frlufjuWju/XLXP3fcxnTU7z89Hp/rGEE8sHNR+T9qRSQmRIUMELigKlYGD6UP/AMU1yeBtYQHMc8jNSwbzBFw9VdKZVUKW8lpo5NM7RjNAJFo1ZK+nTQrnyGqrCOG54HYEksdIvzmftFnkNKOnX62EHYeKmyQu3vpJ+HdMIlLIMd+uiz+IjYR3Vgqt+qfh1nW0DlXpABab9qI8KGny8/HeyNCVzUgV6dPLuhjUYEGokdaZEhsgAFoQUGrhuQMLQBIKft3cYHmCg9rU0HfdxqYb8SdP0iCMBa/TeLY/brNyYuhozeoewhvj7OxEQIUerlhpySg9ZBBxJ5hW+7EU9oEqBr+0iCGCJ/cSx2QVB+pLQGKZo6zFLkraOE71F517zcwhciVh40sKb46ZPP8dI+2ga42xQ/sQFlz0tagZ88LmRqPW37fMUutOxJyOvXp8dgQPwzsp618OS0ky8xzfzc/gE1K/0qYqvUXitX95uLnY+H6WsRt5cmtbTLFOoI= X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0602; 5:Wyz2mIJwrMXLfwo45DWs/dDqPCo/fLTvXmRqzaMzxI9qplhmCidGH/EfhjR5nbR2bmk+DlLB+zOsFBWSsxzOaB8upJ6/Kv4QcwjTCykT15iFV/MTEuiqPHBhsXEGJbJeGWV1/waeBYMluK//7DgkTQ==; 24:9E7gw6exmIxSvzRIeG/CryUNcJjGz5GihMF+xmipJZ28XfIPyYoNMzyS2nOsFzcHd3ph/u7a4q1La5f0pnVlxdQ640eaMr1nm9x9qUUqf4k=; 20:ZU2f/a4xv1l/BYhEdjl7u1hiNSXGRbZwTl88hBww4jHnfUTEPzQn87CVhUhYabUUrKn7pJiWUjJXoDETI8TU338tDwbmRb2e8Z1g3wTNhnBWzh6pg5yDKNjKGwSl/PsOs++sWiVp2FL3J3UYM2BV81Fy04g2VBlnIeWxsJh2tf4= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2015 01:52:43.4134 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB0602 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. Signed-off-by: Gaku Inami Signed-off-by: Kuninori Morimoto --- v2 -> v3 - 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);