From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751496AbcKFRq1 (ORCPT ); Sun, 6 Nov 2016 12:46:27 -0500 Received: from mail-ve1eur01on0055.outbound.protection.outlook.com ([104.47.1.55]:57147 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750927AbcKFRqY (ORCPT ); Sun, 6 Nov 2016 12:46:24 -0500 Authentication-Results: spf=pass (sender IP is 193.47.165.134) smtp.mailfrom=mellanox.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=pass action=none header.from=mellanox.com; X-IncomingTopHeaderMarker: OriginalChecksum:;UpperCasedChecksum:;SizeAsReceived:1619;Count:21 From: Noam Camus To: , , CC: , , , Noam Camus Subject: [PATCH v4 3/3] clocksource: Add clockevent support to NPS400 driver Date: Sun, 6 Nov 2016 19:44:58 +0200 Message-ID: <1478454298-381-4-git-send-email-noamca@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1478454298-381-1-git-send-email-noamca@mellanox.com> References: <1478454298-381-1-git-send-email-noamca@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-Product-Ver: SMEX-11.0.0.1191-8.000.1202-22520.000 X-TM-AS-Result: No--21.177600-8.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-IncomingHeaderCount: 21 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:193.47.165.134;IPV:NLI;CTRY:IL;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(7916002)(2980300002)(438002)(199003)(189002)(107886002)(6666003)(77096005)(2950100002)(33646002)(92566002)(4326007)(586003)(189998001)(76176999)(50986999)(50226002)(2906002)(8936002)(626004)(5003940100001)(106466001)(5001770100001)(86362001)(575784001)(11100500001)(87936001)(49486002)(305945005)(5660300001)(7846002)(4001430100002)(81166006)(81156014)(229853001)(36756003)(356003)(47776003)(8676002)(19580395003)(19580405001)(50466002)(48376002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR05MB1232;H:mtlcas13.mtl.com;FPR:;SPF:Pass;PTR:mail13.mellanox.com;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;DB3FFO11FD046;1:iL+Uet6rfZ+T1a+B9J8ss/0JgYQw9LkGYmhqCCPAFWDMtyVjgiqa5cGDvbvooqjzGiE0TRSeGZtUoRRCllTUTygHCthRGvP4armwKDhMFuRZbfsB/v7+2nx90My8X8z2YL3Utw/M1f0RGJaWIIrwBeERGV99FqxU06EiTE8qofXTPt2zj++dL+aXnCoIMeF3c3BgnM1/MPRhaJsNQKR4PyzR+wgi+3ghTFMnwe+7+cGsZpw+anM4NHh1HrIaNIsy+i9mlaKtY/G7ml2/WQGOwjXFmUVGC4Pk58P8DWq/XyW1gT5SlT7EIRMe61sbWkgbuWqMxA6HwTMxDkhJS6TU0+akDmQv8TOsugsEObtV1DOOgR1MkPVWqDU+M20ViF3oT9ste4rCz9BpsnAH3lIC3eC2OWsuT3hVXtRcsMk0JdmF9Xh6NHUDm5cOhIfVsHN4rqr+YYNj8P7mpjJUFrkSRXTYw8/3y29qYcU+peqDODiHxnQ/r5hLzPN5xk66uQ4zHdSBD27ZYKAEwRFaZHF6HYh3BaA8tiSoIPAre2jqwLfDSOy1CCM3PQ0J/G43Y9+UFQCu4LcDKwzG1+UbJL8eHnyUo7IDIWbYklDd5MjwYKY= X-MS-Office365-Filtering-Correlation-Id: e5c8c5bc-5205-464c-a5dc-08d4066cd03f X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1232;2:VBMoriB1JNqBFYPbNOZt99MWfEQ0PX2hHadQDNADtu+I3dRLuoOCYLORRxh7fsZtDmqgNqTo4qzmxDuCdUDPsuEBJYrAvlJA4suQpFQpHnUJbmH62tBCSsVM55+HPbdR41z4wluS8m4hDDK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ZjPYPs+NFYiBfBy1VC/THadcsDpgMTc95Jz0VRurfMXPCaq2sHTGsJPLRTiWGFGi5Wmg/1SWNYxtcOEw/hSHE/YIQ8Ges7eF6Bb0bKCJPKfGy+ZAKVH0+uX1MH X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1232;20:tUccLvf//UO/l2OOXolLPZ9MDtC/j6QuQklGrdDb7UaW2v2U9H4gshavxrsZQKPT3MMT7aI2Ab8dkBN8uE0KCVEZT9ADKzCGns07yb0JGtLhLuPz8g0WHnDbLwIvqOL+YOWR1upbWw1z3HkxP27ZZsTk7G1+C3UghZsfbQGf9OhjzTkXYW1G0/A7wJJVkxP6DNO/0EzGv8AxCwbZdTkJGO68/4IxByQgDoTHgaEsqhtFSN8snuLL/hj/5LLf8yPSZf5HwaCK/hjo8LNEK6k1KHh+9Pi0T1Hp5bBTQ6M0XO7CIdL3Z3Eq4mSYOkzl+uFfdKICXWFwouDV5TfWpPIwbq+vG5N9SSxZvpxBS7yK+hAR0eBA4/6wIqxHMdJY3g9yYbX31g3C0hHxRC9o7kGhLELqXCfxJ50B8jIBd24YT4gG/JBFjG1IS57ihHBhCuDosF5UFIYrQyHsJQ3Nky8aYEKCObYA1hht1dxwPyhFRN84I38usF6ySuJ1eQujM4G5 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(13018025)(13016025)(8121501046)(5005006)(10201501046)(3002001)(6055026);SRVR:VI1PR05MB1232;BCL:0;PCL:0;RULEID:;SRVR:VI1PR05MB1232; X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1232;4:T+eGh2cPJ/9O14w/quOY8kdrqqd1jpmfy3mrKR6xk3dVYRumgSe9xuWAFrxk2EMZIhM4nehcpudLE64aOv26g000zsYVuF1EFk3jeAlm0UzKDOJGGvG4vNIvXy+NP6AOAAV+O9DBRwBJar55ciXYh5/ymD+K99BUF2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ZznhTHBFYzLu6+AVHZZsafyiQ9cvJQcClodKhW+/JVU=;5:6/hO7qB/ana2WmWSFQo5htztKQ4c2mnmruFzRkEQ+RdYMhiijMV0nj5+CLQVgeCecUCn36V+n5BB2RWNjPURVXf8MqyP5qSISfIwzXU3kQKqxfC5ylTSXFOQHJtkfDAxwP745Pbd3GdJkRoJXk2tsg==;24:X94JA8w2iycZyV4+s+t6c9PSB8txzYVY2GxBp6y+PztzV22KjUXsTUJSQt9FLY9Vvth4rOyJqc7mvFOLDlQbkVMU94gn0tiagQ+iiSl2WYA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;VI1PR05MB1232;7:6ZDVVUkQsuviCE9MXGLfdus6QUm13dTp1N2bNquGhAmCZkRgf/jYguxPJmf/oeI5+8Yww/D2qRYaU8YFCVJ+6WgHpjnnryltuwOdhuKuo0GvhpwmDzHzGj6SprCQ/bXSRaul/3J7HOMGIprl1wSVeRMJGVgbSqDrvR+RPPaH9hyD9qCCoxpKjpfGo0CwADWBj9h8FtlcXL7Jku95NtSAYzW1uO76TmcIzP49LyWihwBbdQuKExkNVPmX5gbiqyk1goRdNknZRqLvq63yGuM/eZdg4FS8NMLju7zwsVTkpgLx6v71Iii4FW7gwRBn9JmUr8e4XN1YTnmc+sSocDgI5q5ve7XlK1iiJMcMTv2RRMw= X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Nov 2016 17:46:18.3965 (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: VI1PR05MB1232 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Noam Camus Till now we used clockevent from generic ARC driver. This was enough as long as we worked with simple multicore SoC. When we are working with multithread SoC each HW thread can be scheduled to receive timer interrupt using timer mask register. This patch will provide a way to control clock events per HW thread. The design idea is that for each core there is dedicated regirtser (TSI) serving all 16 HW threads. The register is a bitmask with one bit for each HW thread. When HW thread wants that next expiration of timer interrupt will hit it then the proper bit should be set in this dedicated register. When timer expires all HW threads within this core which their bit is set at the TSI register will be interrupted. Driver can be used from device tree by: compatible = "ezchip,nps400-timer0" <-- for clocksource compatible = "ezchip,nps400-timer1" <-- for clockevent Note that name convention for timer0/timer1 was taken from legacy ARC design. This design is our base before adding HW threads. For backward compatibility we keep "ezchip,nps400-timer" for clocksource Signed-off-by: Noam Camus --- .../bindings/timer/ezchip,nps400-timer.txt | 15 -- .../bindings/timer/ezchip,nps400-timer0.txt | 17 ++ .../bindings/timer/ezchip,nps400-timer1.txt | 15 ++ drivers/clocksource/timer-nps.c | 213 ++++++++++++++++++++ 4 files changed, 245 insertions(+), 15 deletions(-) delete mode 100644 Documentation/devicetree/bindings/timer/ezchip,nps400-timer.txt create mode 100644 Documentation/devicetree/bindings/timer/ezchip,nps400-timer0.txt create mode 100644 Documentation/devicetree/bindings/timer/ezchip,nps400-timer1.txt diff --git a/Documentation/devicetree/bindings/timer/ezchip,nps400-timer.txt b/Documentation/devicetree/bindings/timer/ezchip,nps400-timer.txt deleted file mode 100644 index c8c03d7..0000000 --- a/Documentation/devicetree/bindings/timer/ezchip,nps400-timer.txt +++ /dev/null @@ -1,15 +0,0 @@ -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/Documentation/devicetree/bindings/timer/ezchip,nps400-timer0.txt b/Documentation/devicetree/bindings/timer/ezchip,nps400-timer0.txt new file mode 100644 index 0000000..e3cfce8 --- /dev/null +++ b/Documentation/devicetree/bindings/timer/ezchip,nps400-timer0.txt @@ -0,0 +1,17 @@ +NPS Network Processor + +Required properties: + +- compatible : should be "ezchip,nps400-timer0" + +Clocks required for compatible = "ezchip,nps400-timer0": +- interrupts : The interrupt of the first timer +- clocks : Must contain a single entry describing the clock input + +Example: + +timer { + compatible = "ezchip,nps400-timer0"; + interrupts = <3>; + clocks = <&sysclk>; +}; diff --git a/Documentation/devicetree/bindings/timer/ezchip,nps400-timer1.txt b/Documentation/devicetree/bindings/timer/ezchip,nps400-timer1.txt new file mode 100644 index 0000000..c0ab419 --- /dev/null +++ b/Documentation/devicetree/bindings/timer/ezchip,nps400-timer1.txt @@ -0,0 +1,15 @@ +NPS Network Processor + +Required properties: + +- compatible : should be "ezchip,nps400-timer1" + +Clocks required for compatible = "ezchip,nps400-timer1": +- clocks : Must contain a single entry describing the clock input + +Example: + +timer { + compatible = "ezchip,nps400-timer1"; + clocks = <&sysclk>; +}; diff --git a/drivers/clocksource/timer-nps.c b/drivers/clocksource/timer-nps.c index 1533349..1097ad6 100644 --- a/drivers/clocksource/timer-nps.c +++ b/drivers/clocksource/timer-nps.c @@ -109,3 +109,216 @@ static int __init nps_setup_clocksource(struct device_node *node) CLOCKSOURCE_OF_DECLARE(ezchip_nps400_clksrc, "ezchip,nps400-timer", nps_setup_clocksource); +CLOCKSOURCE_OF_DECLARE(ezchip_nps400_clk_src, "ezchip,nps400-timer1", + nps_setup_clocksource); + +#ifdef CONFIG_EZNPS_MTM_EXT +#include + +/* Timer related Aux registers */ +#define NPS_REG_TIMER0_TSI 0xFFFFF850 +#define NPS_REG_TIMER0_LIMIT 0x23 +#define NPS_REG_TIMER0_CTRL 0x22 +#define NPS_REG_TIMER0_CNT 0x21 + +/* + * Interrupt Enabled (IE) - re-arm the timer + * Not Halted (NH) - is cleared when working with JTAG (for debug) + */ +#define TIMER0_CTRL_IE BIT(0) +#define TIMER0_CTRL_NH BIT(1) + +static unsigned long nps_timer0_freq; +static unsigned long nps_timer0_irq; + +/* + * Arm the timer to interrupt after @cycles + */ +static void nps_clkevent_timer_event_setup(unsigned int cycles) +{ + write_aux_reg(NPS_REG_TIMER0_LIMIT, cycles); + write_aux_reg(NPS_REG_TIMER0_CNT, 0); + + write_aux_reg(NPS_REG_TIMER0_CTRL, TIMER0_CTRL_IE | TIMER0_CTRL_NH); +} + +/* + * Clear from TSI the bit for this thread (if not in periodic mode) + * If still there are pending HW treads set next timer event + */ +static void nps_clkevent_rm_thread(bool remove_thread) +{ + unsigned int cflags; + unsigned int enabled_threads = 0; + int thread; + + hw_schd_save(&cflags); + + enabled_threads = read_aux_reg(NPS_REG_TIMER0_TSI); + + /* remove thread from TSI1 */ + if (remove_thread) { + thread = read_aux_reg(CTOP_AUX_THREAD_ID); + enabled_threads &= ~(1 << thread); + write_aux_reg(NPS_REG_TIMER0_TSI, enabled_threads); + } + + /* Re-arm the timer if needed */ + if (!enabled_threads) + write_aux_reg(NPS_REG_TIMER0_CTRL, TIMER0_CTRL_NH); + else + write_aux_reg(NPS_REG_TIMER0_CTRL, + TIMER0_CTRL_IE | TIMER0_CTRL_NH); + + hw_schd_restore(cflags); +} + +static void nps_clkevent_add_thread(bool set_event) +{ + int thread; + unsigned int cflags, enabled_threads; + + hw_schd_save(&cflags); + + /* add thread to TSI1 */ + thread = read_aux_reg(CTOP_AUX_THREAD_ID); + enabled_threads = read_aux_reg(NPS_REG_TIMER0_TSI); + enabled_threads |= (1 << thread); + write_aux_reg(NPS_REG_TIMER0_TSI, enabled_threads); + + /* set next timer event */ + if (set_event) + write_aux_reg(NPS_REG_TIMER0_CTRL, + TIMER0_CTRL_IE | TIMER0_CTRL_NH); + + hw_schd_restore(cflags); +} + +static int nps_clkevent_set_next_event(unsigned long delta, + struct clock_event_device *dev) +{ + nps_clkevent_add_thread(true); + enable_percpu_irq(nps_timer0_irq, IRQ_TYPE_NONE); + + return 0; +} + +/* + * Whenever anyone tries to change modes, we just mask interrupts + * and wait for the next event to get set. + */ +static int nps_clkevent_timer_shutdown(struct clock_event_device *dev) +{ + disable_percpu_irq(nps_timer0_irq); + + return 0; +} + +/* + * For each HW thread set its relevant bit at the TSI register + * To arm the timer only thread 0 is needed since it is shared + * by all HW threads within same core. + */ +static int nps_clkevent_set_periodic(struct clock_event_device *dev) +{ + nps_clkevent_add_thread(false); + if (read_aux_reg(CTOP_AUX_THREAD_ID) == 0) + nps_clkevent_timer_event_setup(nps_timer0_freq / HZ); + + return 0; +} + +static int nps_clkevent_set_oneshot(struct clock_event_device *dev) +{ + nps_clkevent_rm_thread(true); + nps_clkevent_timer_shutdown(dev); + + return 0; +} + +static DEFINE_PER_CPU(struct clock_event_device, nps_clockevent_device) = { + .name = "NPS Timer0", + .features = CLOCK_EVT_FEAT_ONESHOT | + CLOCK_EVT_FEAT_PERIODIC, + .rating = 300, + .set_next_event = nps_clkevent_set_next_event, + .set_state_periodic = nps_clkevent_set_periodic, + .set_state_oneshot = nps_clkevent_set_oneshot, + .set_state_oneshot_stopped = nps_clkevent_timer_shutdown, + .set_state_shutdown = nps_clkevent_timer_shutdown, + .tick_resume = nps_clkevent_timer_shutdown, +}; + +static irqreturn_t timer_irq_handler(int irq, void *dev_id) +{ + struct clock_event_device *evt = dev_id; + int irq_reenable = clockevent_state_periodic(evt); + + /* Remove HW thread from TSI only if NOT in periodic state */ + nps_clkevent_rm_thread(!irq_reenable); + + evt->event_handler(evt); + + return IRQ_HANDLED; +} + +static int nps_timer_starting_cpu(unsigned int cpu) +{ + struct clock_event_device *evt = this_cpu_ptr(&nps_clockevent_device); + + evt->cpumask = cpumask_of(smp_processor_id()); + + clockevents_config_and_register(evt, nps_timer0_freq, 0, ULONG_MAX); + enable_percpu_irq(nps_timer0_irq, IRQ_TYPE_NONE); + + return 0; +} + +static int nps_timer_dying_cpu(unsigned int cpu) +{ + disable_percpu_irq(nps_timer0_irq); + return 0; +} + +static int __init nps_setup_clockevent(struct device_node *node) +{ + struct clk *clk; + int ret; + + nps_timer0_irq = irq_of_parse_and_map(node, 0); + if (nps_timer0_irq <= 0) { + pr_err("clockevent: missing irq"); + return -EINVAL; + } + + ret = nps_get_timer_clk(node, &nps_timer0_freq, &clk); + if (ret) + return ret; + + /* Needs apriori irq_set_percpu_devid() done in intc map function */ + ret = request_percpu_irq(nps_timer0_irq, timer_irq_handler, + "Timer0 (per-cpu-tick)", + &nps_clockevent_device); + if (ret) { + pr_err("Couldn't request irq\n"); + clk_disable_unprepare(clk); + return ret; + } + + ret = cpuhp_setup_state(CPUHP_AP_ARC_TIMER_STARTING, + "clockevents/nps:starting", + nps_timer_starting_cpu, + nps_timer_dying_cpu); + if (ret) { + pr_err("Failed to setup hotplug state"); + clk_disable_unprepare(clk); + free_percpu_irq(nps_timer0_irq, &nps_clockevent_device); + return ret; + } + + return 0; +} + +CLOCKSOURCE_OF_DECLARE(ezchip_nps400_clk_evt, "ezchip,nps400-timer0", + nps_setup_clockevent); +#endif /* CONFIG_EZNPS_MTM_EXT */ -- 1.7.1