From patchwork Fri Apr 1 20:21:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noam Camus X-Patchwork-Id: 605006 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qcCTx5SqJz9sdm for ; Sat, 2 Apr 2016 07:22:13 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b=qKT4ddB+; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1am5a8-0002WA-Bx; Fri, 01 Apr 2016 20:22:12 +0000 Received: from mail-db3on0085.outbound.protection.outlook.com ([157.55.234.85] helo=emea01-db3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1am5a3-0002OD-Gn for linux-snps-arc@lists.infradead.org; Fri, 01 Apr 2016 20:22:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=HgImnbe3IijvDL8xWv9mSCkfoFrahkL8HUclo1XYXgw=; b=qKT4ddB+/LeePoRecO0yBvKSrsU3VKZMBRfZWn10lSSZ986q2cPxXqrqSgcwaWGkFywXAjzsws2+Crg/OHBE77psyWMkVAtNsL6t3UFsU1ckDlTB/d6U1LkSzDwcguyC1xwNEf1t12MJleSZR0XHq15rkkXfrHAE/GpcECaykfE= Received: from AMSPR05CA0030.eurprd05.prod.outlook.com (10.242.77.158) by DB3PR05MB0667.eurprd05.prod.outlook.com (10.255.184.23) with Microsoft SMTP Server (TLS) id 15.1.447.15; Fri, 1 Apr 2016 20:21:44 +0000 Received: from AM1FFO11FD006.protection.gbl (2a01:111:f400:7e00::103) by AMSPR05CA0030.outlook.office365.com (2a01:111:e400:8000::30) with Microsoft SMTP Server (TLS) id 15.1.447.15 via Frontend Transport; Fri, 1 Apr 2016 20:21:43 +0000 Authentication-Results: spf=pass (sender IP is 193.47.165.134) smtp.mailfrom=mellanox.com; kernel.org; dkim=none (message not signed) header.d=none; kernel.org; dmarc=pass action=none header.from=mellanox.com; Received-SPF: Pass (protection.outlook.com: domain of mellanox.com designates 193.47.165.134 as permitted sender) receiver=protection.outlook.com; client-ip=193.47.165.134; helo=mtlcas13.mtl.com; Received: from mtlcas13.mtl.com (193.47.165.134) by AM1FFO11FD006.mail.protection.outlook.com (10.174.64.68) with Microsoft SMTP Server (TLS) id 15.1.453.6 via Frontend Transport; Fri, 1 Apr 2016 20:21:42 +0000 Received: from MTLCAS13.mtl.com (10.0.8.78) by mtlcas13.mtl.com (10.0.8.78) with Microsoft SMTP Server (TLS) id 15.0.775.38; Fri, 1 Apr 2016 23:21:34 +0300 Received: from MTLCAS01.mtl.com (10.0.8.71) by MTLCAS13.mtl.com (10.0.8.78) with Microsoft SMTP Server (TLS) id 15.0.775.38 via Frontend Transport; Fri, 1 Apr 2016 23:21:34 +0300 Received: from ezex10.ezchip.com (10.0.13.1) by MTLCAS01.MTL.COM (10.0.8.71) with Microsoft SMTP Server (TLS) id 14.3.123.3; Fri, 1 Apr 2016 23:21:33 +0300 Received: from localhost.localdomain (10.1.3.132) by ezex10.ezchip.com (10.1.1.4) with Microsoft SMTP Server (TLS) id 14.3.224.2; Fri, 1 Apr 2016 23:21:33 +0300 From: Noam Camus To: , , Subject: [PATCH v7 2/3] clocksource: Add NPS400 timers driver Date: Fri, 1 Apr 2016 23:21:24 +0300 Message-ID: <1459542085-3065-3-git-send-email-noamca@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1459542085-3065-1-git-send-email-noamca@mellanox.com> References: <1459542085-3065-1-git-send-email-noamca@mellanox.com> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-11.0.0.1191-8.000.1202-22234.001 X-TM-AS-Result: No--24.707500-8.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No Received-SPF: None (MTLCAS01.mtl.com: noamca@mellanox.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:193.47.165.134; IPV:NLI; CTRY:IL; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(199003)(189002)(5001770100001)(33646002)(49486002)(87936001)(11100500001)(575784001)(5003940100001)(92566002)(1096002)(86362001)(76176999)(36756003)(106466001)(101416001)(2201001)(50226001)(50986999)(19580405001)(189998001)(2906002)(48376002)(47776003)(4326007)(15975445007)(77096005)(2950100001)(5008740100001)(19580395003)(81166005)(50466002)(229853001)(1220700001)(586003)(6806005); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR05MB0667; H:mtlcas13.mtl.com; FPR:; SPF:Pass; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11FD006; 1:qAo4JSm0ZXDS8Bvsym/A5GiWvSkAOvLEWMYRKjkoQZgVkhxPmdVxoaBb+/o3adzE5Pd5C9mTNA3HnI+WPMDKKYdQp2PNaQbwpZw+sOjPWg0ZCYX68mABdCUa7r98KHyTHiiq2XmvjeU+X2GKtivE59wJyvaZSV19MGBr4OzYhI0L/2YQvi+VZuW527ef0rZwX2hVsAUuFBv/UCIjeHuS+4AUrojNqJtuYYacgg1QOPQN5cKTnr/F5Aix+Pq50Pjy0E2MYUeZ8TNTZPbDorgrcPERcyKO2U6GZQWtVnHqScC+xJWHYkAQQKNiGUge0c5hkU+cqHZwXj4p1OLWf0y+tfVWr7MxGZ6K+elkb8xxDKv1Z6+FkWJdpvyD061ALdHV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aV7jO5dDTw91GGpmMW8ckOyhPwpniBVqAKHzcreudFZlo= X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501002); SRVR:DB3PR05MB0667; X-Microsoft-Exchange-Diagnostics: 1; DB3PR05MB0667; 20:kPboHucv7vZK6B9qt/fHtJ/ZrJk6pdfFC6zi0b1whtUruAkw0eoMdXR7EJfeJsRaXAkph84vluaL94hUgX7iNhMrhWiP1+hyZdlQNFNFV6+CMRGiH8+beXwoYzF2m5EVrP0R7kdOVxPFXvdkuFsKkoD6uQ4r0qTMmvYZPvvz9bDMLgTyH9/Xxk/30NB+mpBCxyXFG0oHbu56v4o03g0lDRTPVpKsIB3bczvhLRdmJsndINHrRbB4RfOCw4buNeOIUQoT3OcJ5aWZSZjl81FOHPgKC0uuR/Mc3GLHBwP3BVSrUzJ36ggtqv2ynMObNVFeKd+MqmCqfWqES1ZSHlJArvQnLshqY1xZg7GRMIDYoHot17eSfY3bvLEJjI2QP6KB1HiFXRwVTf/tnaAOgBm1lgD1rrXU9Tdp2RfUjMbDEc3RRChRWqbTgm6EpA/syeGKkvf5LAucYFxi7BMYNlgctK+4xt680eEsMlgKmPWKLodEwQ2il1So4Zkms5ozT+fe X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(13015025)(13018025)(13024025)(8121501046)(13023025)(13017025)(3002001)(10201501046); SRVR:DB3PR05MB0667; BCL:0; PCL:0; RULEID:; SRVR:DB3PR05MB0667; X-Microsoft-Exchange-Diagnostics: 1; DB3PR05MB0667; 4:whDLcP13YMk0fAdodWIXKD2RrRnKz51AspiUehZlnfU6yQEDkzUqbaTo3yWoRIsGH1DYfW+wgjHKj0D5g5go7FkQQ/DVf90QaIE4PoWjt3PU51RqABIsJ3IkmslhaPvR4lRy1ZCY6eQjlnRDnzZ2HdhSvh5cHsk06368aUOL1T+zvDuXSaWCJk9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q?UtxZyjII/0ktL35aT0m6UO+4Oyw4wVpvnea6rLi2Gj1DgdbB3Fi+oZT+2eBj?= =?us-ascii?Q?94GsBk5Znanx9JS+TCD/FQn9UDbKVjdnQyEKhwZCubmPSF0hFIXIcLEXqd1H?= =?us-ascii?Q?C/ewF6p/qK5X77nm6GC+Zz/on0zbnxVG/12VNuc2zam7OPW/prbQsDww48Br?= =?us-ascii?Q?v+DZ9xpMUsMjWF90CBAAfcRlpL3qCZTH4QfsIi1vNP7eWvA+6MIHwJkxSmyQ?= =?us-ascii?Q?OApqL9ugV+laiC7xxqyc1zytRsFV4I2SGjNJNJmWmfoExutAFJbhoy2I/PkN?= =?us-ascii?Q?A+CZSjH2VTxx5D9GN2BKNI1KInhRL5OJZOFvFMnDSRXtFwjHYqMQwbMeElj+?= =?us-ascii?Q?0vqk/NH6/bm9lqKbdJcT/Fj+5uJoVs8sTvCUk5i/lkERZEfFX84CLI45fUZn?= =?us-ascii?Q?f4/UsGMewyfa5aEX5iGtjDFv5OI4SKtkOausB9eGxnU1Q=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB3PR05MB0667; 5:m7zMRTxRjIZ1IlVqLdk9SgyZQqtPIbLzfIk6eLMwy2lfYYzFcdI7KUM3Dhdv0X4UdI8WscXaMLDNSsrExNpdjUQTYNVq73g/NxEujgpN6xNegc68sN3qXO0nEYUnk8zVsdykRVauG46mPdG03B6PkA==; 24:VM0xRAOekKbuzH8C9loODsZKCdvqKXiS5Czg3A5dF7M/2qvywogrNk8mx3CqfhuU0FSx9KEwi0o0oHHYRowcNXZ+8t3j6MPk+tNKWA3cKLQ= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2016 20:21:42.5345 (UTC) X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=a652971c-7d2e-4d9b-a6a4-d149256f461b; Ip=[193.47.165.134]; Helo=[mtlcas13.mtl.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR05MB0667 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160401_132208_146269_8002A180 X-CRM114-Status: GOOD ( 20.70 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [157.55.234.85 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [157.55.234.85 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vineet Gupta , linux-kernel@vger.kernel.org, Rob Herring , John Stultz , Noam Camus , Thomas Gleixner , linux-snps-arc@lists.infradead.org Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Noam Camus Add internal tick generator which is shared by all cores. Each cluster of cores view it through dedicated address. This is used for SMP system where all CPUs synced by same clock source. Signed-off-by: Noam Camus Cc: Daniel Lezcano Cc: Rob Herring Cc: Thomas Gleixner Cc: John Stultz Cc: Vineet Gupta --- v7: Rebased on latest HEAD (4.6-rc1) v6: Files headers changed to start with: Copyright (c) 2016, Mellanox Technologies ... This is due to the acquisition of EZchip made by Mellanox. One can still find "EZchip" used in tree, and this is ok. This patch set is a requierement before I can insert new platform to ARC, one that supports the NPS400 SoC. v5: Clocksource, irqchip - Fix gracefull return. replace call to panic() with pr_err() and proper return value. v4: clocksource -- Apply all Daniel comments (Thanks) Handle gracefull return and also using clocksoure mmio driver at init v3: irqchip - Fix ARM build failure by adding missing include of linux/irq.h clocksource -- Avoid 64bit arch's to build driver by adding new dependency !PHYS_ADDR_T_64BIT This is since we use explicit io access of 32 bit. So for test coverage we allow not only build for ARC, but restrict it to 32 bit arch's. irqchip - Apply all Thomas comments (Thank you) v2: Add header file include/soc/nps/common.h. Now to build we do not depend on ARC subtree. General summay: Both drivers are now apart of previous basic patch set of new platform for ARC. The rest is now can be seen at ARC srctree: https://git.kernel.org/cgit/linux/kernel/git/vgupta/arc.git/ Now ARC is supporting DT for clockevents and the interrupt controller ARC uses irq domain handling. Compare to last version now clocksource driver do not include clockevent registration since NPS400 can use ARC generic driver. Compare to last version now irqchip driver sets domain as default since it is the root domain. Also mapping of IPI is done in this driver. Last thing is that drivers can be build cleanly for i386 (still runs only for ARC) Note: in order to build we need to merge drivers into srctree which includes new header: soc/nps/common.h This header is part of patch set applied to ARC srctree. Regards, Noam Camus --- .../bindings/timer/ezchip,nps400-timer.txt | 15 +++ drivers/clocksource/Kconfig | 10 ++ drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-nps.c | 98 ++++++++++++++++++++ 4 files changed, 124 insertions(+), 0 deletions(-) create mode 100644 Documentation/devicetree/bindings/timer/ezchip,nps400-timer.txt create mode 100644 drivers/clocksource/timer-nps.c diff --git a/Documentation/devicetree/bindings/timer/ezchip,nps400-timer.txt b/Documentation/devicetree/bindings/timer/ezchip,nps400-timer.txt new file mode 100644 index 0000000..c8c03d7 --- /dev/null +++ b/Documentation/devicetree/bindings/timer/ezchip,nps400-timer.txt @@ -0,0 +1,15 @@ +NPS Network Processor + +Required properties: + +- compatible : should be "ezchip,nps400-timer" + +Clocks required for compatible = "ezchip,nps400-timer": +- clocks : Must contain a single entry describing the clock input + +Example: + +timer { + compatible = "ezchip,nps400-timer"; + clocks = <&sysclk>; +}; diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index c346be6..3932d09 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -181,6 +181,16 @@ config CLKSRC_TI_32K This option enables support for Texas Instruments 32.768 Hz clocksource available on many OMAP-like platforms. +config CLKSRC_NPS + bool "NPS400 clocksource driver" if COMPILE_TEST + depends on !PHYS_ADDR_T_64BIT + select CLKSRC_MMIO + select CLKSRC_OF if OF + help + NPS400 clocksource support. + Got 64 bit counter with update rate up to 1000MHz. + This counter is accessed via couple of 32 bit memory mapped registers. + config CLKSRC_STM32 bool "Clocksource for STM32 SoCs" if !ARCH_STM32 depends on OF && ARM && (ARCH_STM32 || COMPILE_TEST) diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index dc2b899..0b0a4b5 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -46,6 +46,7 @@ obj-$(CONFIG_CLKSRC_QCOM) += qcom-timer.o obj-$(CONFIG_MTK_TIMER) += mtk_timer.o obj-$(CONFIG_CLKSRC_PISTACHIO) += time-pistachio.o obj-$(CONFIG_CLKSRC_TI_32K) += timer-ti-32k.o +obj-$(CONFIG_CLKSRC_NPS) += timer-nps.o obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o obj-$(CONFIG_ARM_GLOBAL_TIMER) += arm_global_timer.o diff --git a/drivers/clocksource/timer-nps.c b/drivers/clocksource/timer-nps.c new file mode 100644 index 0000000..d461089 --- /dev/null +++ b/drivers/clocksource/timer-nps.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2016, Mellanox Technologies. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define NPS_MSU_TICK_LOW 0xC8 +#define NPS_CLUSTER_OFFSET 8 +#define NPS_CLUSTER_NUM 16 + +/* This array is per cluster of CPUs (Each NPS400 cluster got 256 CPUs) */ +static void *nps_msu_reg_low_addr[NPS_CLUSTER_NUM] __read_mostly; + +static unsigned long nps_timer_rate; + +static cycle_t nps_clksrc_read(struct clocksource *clksrc) +{ + int cluster = raw_smp_processor_id() >> NPS_CLUSTER_OFFSET; + + return (cycle_t)ioread32be(nps_msu_reg_low_addr[cluster]); +} + +static void __init nps_setup_clocksource(struct device_node *node, + struct clk *clk) +{ + int ret, cluster; + + for (cluster = 0; cluster < NPS_CLUSTER_NUM; cluster++) + nps_msu_reg_low_addr[cluster] = + nps_host_reg((cluster << NPS_CLUSTER_OFFSET), + NPS_MSU_BLKID, NPS_MSU_TICK_LOW); + + ret = clk_prepare_enable(clk); + if (ret) { + pr_err("Couldn't enable parent clock\n"); + return; + } + + nps_timer_rate = clk_get_rate(clk); + + ret = clocksource_mmio_init(nps_msu_reg_low_addr, "EZnps-tick", + nps_timer_rate, 301, 32, nps_clksrc_read); + if (ret) { + pr_err("Couldn't register clock source.\n"); + clk_disable_unprepare(clk); + } +} + +static void __init nps_timer_init(struct device_node *node) +{ + struct clk *clk; + + clk = of_clk_get(node, 0); + if (IS_ERR(clk)) { + pr_err("Can't get timer clock.\n"); + return; + } + + nps_setup_clocksource(node, clk); +} + +CLOCKSOURCE_OF_DECLARE(ezchip_nps400_clksrc, "ezchip,nps400-timer", + nps_timer_init);