From patchwork Thu Aug 6 08:04:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 6956961 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 78B59C05AC for ; Thu, 6 Aug 2015 08:04:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 235F82068C for ; Thu, 6 Aug 2015 08:04:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BDF7B20688 for ; Thu, 6 Aug 2015 08:04:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753059AbbHFIEZ (ORCPT ); Thu, 6 Aug 2015 04:04:25 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:6260 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753501AbbHFIEW (ORCPT ); Thu, 6 Aug 2015 04:04:22 -0400 Received: from unknown (HELO relmlir1.idc.renesas.com) ([10.200.68.151]) by relmlie2.idc.renesas.com with ESMTP; 06 Aug 2015 17:04:19 +0900 Received: from relmlac3.idc.renesas.com (relmlac3.idc.renesas.com [10.200.69.23]) by relmlir1.idc.renesas.com (Postfix) with ESMTP id D923B55474; Thu, 6 Aug 2015 17:04:19 +0900 (JST) Received: by relmlac3.idc.renesas.com (Postfix, from userid 0) id DD36E1806F; Thu, 6 Aug 2015 17:04:19 +0900 (JST) Received: from relmlac3.idc.renesas.com (localhost [127.0.0.1]) by relmlac3.idc.renesas.com (Postfix) with ESMTP id D91CA1800A; Thu, 6 Aug 2015 17:04:19 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac3.idc.renesas.com with ESMTP id TAH17914; Thu, 6 Aug 2015 17:04:19 +0900 X-IronPort-AV: E=Sophos;i="5.15,622,1432566000"; d="scan'";a="193108210" Received: from mail-hk2apc01lp0216.outbound.protection.outlook.com (HELO APC01-HK2-obe.outbound.protection.outlook.com) ([65.55.88.216]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA; 06 Aug 2015 17:04:18 +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 HK2PR06MB0594.apcprd06.prod.outlook.com (10.161.187.145) with Microsoft SMTP Server (TLS) id 15.1.225.19; Thu, 6 Aug 2015 08:04:16 +0000 Message-ID: <87vbcsyhfu.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 01/13 v4][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 In-Reply-To: <87wpx8yhhm.wl%kuninori.morimoto.gx@renesas.com> References: <87wpx8yhhm.wl%kuninori.morimoto.gx@renesas.com> Date: Thu, 6 Aug 2015 08:04:16 +0000 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: OS2PR01CA0008.jpnprd01.prod.outlook.com (25.161.74.146) To HK2PR06MB0594.apcprd06.prod.outlook.com (25.161.187.145) X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB0594; 2:YbJwvUGob7koXLQT62Tz4zbPcHMF21OJS8v1wJ29RSSVO/VQAvTSP7/tCtmH4GKA8FTbFBw+xpzqYI8FcfAAkMihk4on1isGQmX/jj3Gfj+EDp4yePe+siAZy1MPxzQEqhD3HUKcUn9i95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nGqiSBjn+4cu5rpBV4u2GBLvbnatdxY3EquyJXepvC/xt+iehvxdZVIZbp3r+B0h7/Adjr7sUmWX3l5OQDUYiQShej7cNAbn8TEYVzeYKAH3MFsQAIgD4VnPZZ7EAflepl9+r42A9RuXKG+eIhecVOPeyRSTlE9NW1BijPhsQEbjLYA1pzKzPFOxIAWtL/H7RWIwczQVXUQRqVLUNkMuYb6gc7fEZM30AIwB/4FjGFbtSVdWaWdknDKLkT24crw1MXH2nk17PwkgVB+mB3JR4iVCBUCOpFU4= 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:HK2PR06MB0594; BCL:0; PCL:0; RULEID:; SRVR:HK2PR06MB0594; X-Forefront-PRVS: 06607E485E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(199003)(189002)(4001540100001)(575784001)(33646002)(189998001)(83506001)(101416001)(50466002)(77096005)(5001770100001)(5001860100001)(68736005)(105586002)(81156007)(106356001)(229853001)(5001830100001)(69596002)(76176999)(87976001)(107886002)(97736004)(54356999)(5001960100002)(50986999)(23726002)(2950100001)(86362001)(92566002)(36756003)(46102003)(42186005)(4001350100001)(47776003)(46406003)(122386002)(64706001)(19580405001)(66066001)(53416004)(62966003)(19580395003)(77156002)(40100003)(2004002)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:HK2PR06MB0594; H:morimoto-PC.renesas.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HK2PR06MB0594; 23:QRhWg21obHawLr4nlv+D90I/bqzMV8iAMzXPmp0Vy?= =?us-ascii?Q?LG0b04z3H69xC2fSURXYB4+BXPLpVXj6tz9fYhunX3nJlwjJonirB/vOKcZs?= =?us-ascii?Q?GblAxQKv4EjWeWp3Mr3DgdG6N/kpKh6f+3SB9ZpPVd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bpgMnSOfqPROvxZhJWd89+lImg5pXxyoPdc+iz?= =?us-ascii?Q?fXk0I8FLFQBt5RX6WFNmBQORiRSPlF3YBvGAcjkgTW4pw4J7HUY/NttFJiAK?= =?us-ascii?Q?ayJGy+ab4927DtHo8kgATiASUuaWbs9M9yVyKuQvob1PZvh1Q1zQwYnytgLB?= =?us-ascii?Q?3u6ddyvG84kAr3Docbz8dAZgdHrDcCNiSV4+DuCgV7EaH1ZuJ0/jghm5voCY?= =?us-ascii?Q?xd3VGrtBVeS0LQITzdnReRy4gZ5KV2NwOhI/m+Q?= X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB0594; 5:3sWSaP632Wp9MS0N/mOYKhS/LfUe0GVir1kBvE9DVB3YMv95VwwU3tsLMi2ST2fWahfDCSTKX4wyGWgxCZ+bUfdbhC83CYg04NtZKM3nf2G4AjEqzMwiJEZVCvXDlDCllMwKujrfG6QnWLkVnGatOA==; 24:kZdOMkhqGfPuDDPV95dWgvl4PHNGRKfez4nbXoHIOyia1zd/llqp6PPGzXZHa1ApKi0iHuStlzn+MxElFl1vXsJ+kB24q83MKHgFbnlAoxU=; 20:JPw+e2b2Db7XVytihWDvOWbF1bfLUSlEaKlcuNzomMeQwPJ7/WPrhKPcThmKEGkKd7hMJKLQm/KUQCcbco8d8y80WazG6Es05A7D3iH7NuPpL7a+NKo7pnlm2nwHrjsEhrb87hBTqq8saFr6K3sMYQnnhwzN3w3L0ZPRowS9wtE= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2015 08:04:16.2449 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2PR06MB0594 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 --- v3 -> v4 - 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);