* [PATCH v1 0/2] clocksource: npcm: add NPCM7xx timer driver
@ 2017-10-01 9:11 ` Tomer Maimon
0 siblings, 0 replies; 11+ messages in thread
From: Tomer Maimon @ 2017-10-01 9:11 UTC (permalink / raw)
To: robh+dt, mark.rutland, daniel.lezcano, tglx, avifishman70,
brendanhiggins, raltherr, joel
Cc: devicetree, linux-kernel, openbmc, Tomer Maimon
This patch set adds clocksource support for the Nuvoton NPCM7xx Baseboard
Management Controller (BMC).
The clocksource Enable 24-bit TIMER0 and TIMER1 counters in the NPCM7xx BMC,
while TIMER0 serves as clockevent and TIMER1 serves as clocksource.
clocksource patch set depand on approval of basic support for Nuvoton BMCs
and Nuvoton NPCM750 device tree patches.
https://patchwork.kernel.org/bundle/brendanhiggins/arm:%20npcm:%20add%20basic%20support%20for%20Nuvoton%20BMCs/
Tomer Maimon (2):
clocksource: npcm: add NPCM7xx timer driver
dt-binding: timer: document NPCM7xx timer DT bindings
.../bindings/timer/nuvoton,npcm7xx-timer.txt | 25 +++
drivers/clocksource/Kconfig | 9 +
drivers/clocksource/Makefile | 1 +
drivers/clocksource/npcm7xx_timer.c | 205 +++++++++++++++++++++
4 files changed, 240 insertions(+)
create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
create mode 100644 drivers/clocksource/npcm7xx_timer.c
--
2.14.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v1 0/2] clocksource: npcm: add NPCM7xx timer driver
@ 2017-10-01 9:11 ` Tomer Maimon
0 siblings, 0 replies; 11+ messages in thread
From: Tomer Maimon @ 2017-10-01 9:11 UTC (permalink / raw)
To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A,
tglx-hfZtesqFncYOwBW4kG4KsQ, avifishman70-Re5JQEeQqe8AvxtiuMwx3w,
brendanhiggins-hpIqsD4AKlfQT0dZR+AlfA,
raltherr-hpIqsD4AKlfQT0dZR+AlfA, joel-U3u1mxZcP9KHXe+LvDLADg
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
openbmc-uLR06cmDAlY/bJ5BZ2RsiQ, Tomer Maimon
This patch set adds clocksource support for the Nuvoton NPCM7xx Baseboard
Management Controller (BMC).
The clocksource Enable 24-bit TIMER0 and TIMER1 counters in the NPCM7xx BMC,
while TIMER0 serves as clockevent and TIMER1 serves as clocksource.
clocksource patch set depand on approval of basic support for Nuvoton BMCs
and Nuvoton NPCM750 device tree patches.
https://patchwork.kernel.org/bundle/brendanhiggins/arm:%20npcm:%20add%20basic%20support%20for%20Nuvoton%20BMCs/
Tomer Maimon (2):
clocksource: npcm: add NPCM7xx timer driver
dt-binding: timer: document NPCM7xx timer DT bindings
.../bindings/timer/nuvoton,npcm7xx-timer.txt | 25 +++
drivers/clocksource/Kconfig | 9 +
drivers/clocksource/Makefile | 1 +
drivers/clocksource/npcm7xx_timer.c | 205 +++++++++++++++++++++
4 files changed, 240 insertions(+)
create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
create mode 100644 drivers/clocksource/npcm7xx_timer.c
--
2.14.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v1 1/2] clocksource: npcm: add NPCM7xx timer driver
2017-10-01 9:11 ` Tomer Maimon
(?)
@ 2017-10-01 9:11 ` Tomer Maimon
2017-10-01 16:44 ` Daniel Lezcano
-1 siblings, 1 reply; 11+ messages in thread
From: Tomer Maimon @ 2017-10-01 9:11 UTC (permalink / raw)
To: robh+dt, mark.rutland, daniel.lezcano, tglx, avifishman70,
brendanhiggins, raltherr, joel
Cc: devicetree, linux-kernel, openbmc, Tomer Maimon
Add Nuvoton BMC NPCM7xx timer driver.
Signed-off-by: Tomer Maimon <tmaimon77@gmail.com>
---
drivers/clocksource/Kconfig | 9 ++
drivers/clocksource/Makefile | 1 +
drivers/clocksource/npcm7xx_timer.c | 205 ++++++++++++++++++++++++++++++++++++
3 files changed, 215 insertions(+)
create mode 100644 drivers/clocksource/npcm7xx_timer.c
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index cc6062049170..e26a203ce4ab 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -140,6 +140,15 @@ config VT8500_TIMER
help
Enables support for the VT8500 driver.
+config NPCM7XX_TIMER
+ bool "NPCM7xx timer driver" if (COMPILE_TEST || ARCH_NPCM7XX)
+ depends on GENERIC_CLOCKEVENTS
+ depends on HAS_IOMEM
+ select CLKSRC_MMIO
+ help
+ Enable 24-bit TIMER0 and TIMER1 counters in the NPCM7xx arcithcture,
+ While TIMER0 serves as clockevent and TIMER1 serves as clocksource.
+
config CADENCE_TTC_TIMER
bool "Cadence TTC timer driver" if COMPILE_TEST
depends on COMMON_CLK
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index dbc1ad14515e..fd3a1c33364b 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_CLKSRC_TI_32K) += timer-ti-32k.o
obj-$(CONFIG_CLKSRC_NPS) += timer-nps.o
obj-$(CONFIG_OXNAS_RPS_TIMER) += timer-oxnas-rps.o
obj-$(CONFIG_OWL_TIMER) += owl-timer.o
+obj-$(CONFIG_NPCM7XX_TIMER) += npcm7xx_timer.o
obj-$(CONFIG_ARC_TIMERS) += arc_timer.o
obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o
diff --git a/drivers/clocksource/npcm7xx_timer.c b/drivers/clocksource/npcm7xx_timer.c
new file mode 100644
index 000000000000..6da77202a22d
--- /dev/null
+++ b/drivers/clocksource/npcm7xx_timer.c
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2017 Nuvoton Technology corporation.
+ * Copyright 2017 Google, Inc.
+ *
+ * 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 <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/err.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/clockchips.h>
+#include <linux/of_irq.h>
+#include <linux/of_address.h>
+
+struct npcm7xx_clockevent_data {
+ struct clock_event_device cvd;
+ void __iomem *timer_base;
+ unsigned int rate;
+};
+
+/* Timers registers */
+#define REG_TCSR0 0x0 /* Timer 0 Control and Status Register */
+#define REG_TICR0 0x8 /* Timer 0 Initial Count Register */
+#define REG_TCSR1 0x4 /* Timer 1 Control and Status Register */
+#define REG_TICR1 0xc /* Timer 1 Initial Count Register */
+#define REG_TDR1 0x14 /* Timer 1 Data Register */
+#define REG_TISR 0x18 /* Timer Interrupt Status Register */
+
+#define RESETINT 0x1f
+#define PERIOD BIT(27)
+#define INTEN BIT(29)
+#define COUNTEN BIT(30)
+#define ONESHOT 0x0
+#define TIMER_OPER GENMASK(3, 27)
+#define MIN_PRESCALE 0x1 /* minimal timer prescale */
+#define TDR_MASK_BITS 24
+#define MAX_TIMER_CNT 0xFFFFFF
+#define CLR_TIMER0_INT 0x1
+#define CLR_TIMER_CSR 0x0
+
+
+static int npcm7xx_timer_oneshot(struct clock_event_device *evt)
+{
+ u32 val;
+ struct npcm7xx_clockevent_data *cevtd =
+ container_of(evt, struct npcm7xx_clockevent_data, cvd);
+
+ val = readl(cevtd->timer_base + REG_TCSR0);
+ val &= ~TIMER_OPER;
+
+ val = readl(cevtd->timer_base + REG_TCSR0);
+ val |= (ONESHOT | COUNTEN | INTEN | MIN_PRESCALE);
+ writel(val, cevtd->timer_base + REG_TCSR0);
+
+ return 0;
+}
+
+static int npcm7xx_timer_periodic(struct clock_event_device *evt)
+{
+ struct npcm7xx_clockevent_data *cevtd =
+ container_of(evt, struct npcm7xx_clockevent_data, cvd);
+ u32 val;
+
+ val = readl(cevtd->timer_base + REG_TCSR0);
+ val &= ~TIMER_OPER;
+
+ writel((cevtd->rate / HZ), cevtd->timer_base + REG_TICR0);
+ val |= (PERIOD | COUNTEN | INTEN | MIN_PRESCALE);
+
+ writel(val, cevtd->timer_base + REG_TCSR0);
+
+ return 0;
+}
+
+static int npcm7xx_clockevent_setnextevent(unsigned long evt,
+ struct clock_event_device *clk)
+{
+ struct npcm7xx_clockevent_data *cevtd =
+ container_of(clk, struct npcm7xx_clockevent_data, cvd);
+ u32 val;
+
+ writel(evt, cevtd->timer_base + REG_TICR0);
+ val = readl(cevtd->timer_base + REG_TCSR0);
+ val |= (COUNTEN | INTEN | MIN_PRESCALE);
+ writel(val, cevtd->timer_base + REG_TCSR0);
+
+ return 0;
+}
+
+static struct npcm7xx_clockevent_data npcm7xx_clockevent_data = {
+ .cvd = {
+ .name = "npcm7xx-timer0",
+ .features = CLOCK_EVT_FEAT_PERIODIC |
+ CLOCK_EVT_FEAT_ONESHOT,
+ .set_next_event = npcm7xx_clockevent_setnextevent,
+ .set_state_shutdown = npcm7xx_timer_oneshot,
+ .set_state_periodic = npcm7xx_timer_periodic,
+ .set_state_oneshot = npcm7xx_timer_oneshot,
+ .tick_resume = npcm7xx_timer_oneshot,
+ .rating = 300
+ },
+};
+
+static irqreturn_t npcm7xx_timer0_interrupt(int irq, void *dev_id)
+{
+ struct npcm7xx_clockevent_data *cevtd = dev_id;
+ struct clock_event_device *evt = &cevtd->cvd;
+
+ writel(CLR_TIMER0_INT, cevtd->timer_base + REG_TISR);
+
+ if (evt->event_handler)
+ evt->event_handler(evt);
+
+ return IRQ_HANDLED;
+}
+
+static struct irqaction npcm7xx_timer0_irq = {
+ .name = "npcm7xx-timer0",
+ .flags = IRQF_TIMER | IRQF_IRQPOLL,
+ .handler = npcm7xx_timer0_interrupt,
+ .dev_id = &npcm7xx_clockevent_data,
+};
+
+static void __init npcm7xx_clockevents_init(int irq, u32 rate)
+{
+ writel(CLR_TIMER_CSR, npcm7xx_clockevent_data.timer_base + REG_TCSR0);
+
+ writel(RESETINT, npcm7xx_clockevent_data.timer_base + REG_TISR);
+ setup_irq(irq, &npcm7xx_timer0_irq);
+ npcm7xx_clockevent_data.cvd.cpumask = cpumask_of(0);
+
+ clockevents_config_and_register(&npcm7xx_clockevent_data.cvd, rate,
+ 0x1, MAX_TIMER_CNT);
+}
+
+static void __init npcm7xx_clocksource_init(u32 rate)
+{
+ u32 val;
+
+ writel(CLR_TIMER_CSR, npcm7xx_clockevent_data.timer_base + REG_TCSR1);
+ writel(MAX_TIMER_CNT, npcm7xx_clockevent_data.timer_base + REG_TICR1);
+
+ val = readl(npcm7xx_clockevent_data.timer_base + REG_TCSR1);
+ val |= (COUNTEN | PERIOD | MIN_PRESCALE);
+ writel(val, npcm7xx_clockevent_data.timer_base + REG_TCSR1);
+
+ clocksource_mmio_init(npcm7xx_clockevent_data.timer_base + REG_TDR1,
+ "npcm7xx-timer1", rate,
+ 300, (unsigned int)TDR_MASK_BITS,
+ clocksource_mmio_readl_down);
+}
+
+static int __init npcm7xx_timer_init(struct device_node *np)
+{
+ struct clk *clk;
+ int irq, ret;
+ u32 rate;
+
+ irq = irq_of_parse_and_map(np, 0);
+ if (!irq)
+ return -EINVAL;
+
+ npcm7xx_clockevent_data.timer_base = of_iomap(np, 0);
+ if (!npcm7xx_clockevent_data.timer_base)
+ return -ENXIO;
+
+ clk = of_clk_get(np, 0);
+
+ if (IS_ERR(clk)) {
+ ret = of_property_read_u32(np, "clock-frequency", &rate);
+ if (ret)
+ goto err_iounmap;
+ } else {
+ clk_prepare_enable(clk);
+ rate = clk_get_rate(clk);
+ }
+
+ /* Clock input is divided by PRESCALE + 1 before it is fed */
+ /* to the counter */
+ rate = rate / (MIN_PRESCALE + 1);
+
+ npcm7xx_clockevent_data.rate = rate;
+
+ npcm7xx_clocksource_init(rate);
+ npcm7xx_clockevents_init(irq, rate);
+
+ pr_info("Enabling NPCM7xx clocksource timer base: %p, IRQ: %u\n",
+ npcm7xx_clockevent_data.timer_base, irq);
+
+ return 0;
+
+err_iounmap:
+ iounmap(npcm7xx_clockevent_data.timer_base);
+ return ret;
+
+}
+
+TIMER_OF_DECLARE(npcm7xx, "nuvoton,npcm7xx-timer", npcm7xx_timer_init);
+
--
2.14.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v1 2/2] dt-binding: timer: document NPCM7xx timer DT bindings
2017-10-01 9:11 ` Tomer Maimon
(?)
(?)
@ 2017-10-01 9:11 ` Tomer Maimon
2017-10-10 15:57 ` Rob Herring
-1 siblings, 1 reply; 11+ messages in thread
From: Tomer Maimon @ 2017-10-01 9:11 UTC (permalink / raw)
To: robh+dt, mark.rutland, daniel.lezcano, tglx, avifishman70,
brendanhiggins, raltherr, joel
Cc: devicetree, linux-kernel, openbmc, Tomer Maimon
Added device tree binding documentation for Nuvoton NPCM7xx timer.
Signed-off-by: Tomer Maimon <tmaimon77@gmail.com>
---
.../bindings/timer/nuvoton,npcm7xx-timer.txt | 25 ++++++++++++++++++++++
1 file changed, 25 insertions(+)
create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
diff --git a/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt b/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
new file mode 100644
index 000000000000..d1beea901509
--- /dev/null
+++ b/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
@@ -0,0 +1,25 @@
+Nuvoton NPCM7xx timer
+
+Nuvoton NPCM7xx have three timer modules, each timer module provides five 24-bit
+timer counters.
+
+Required properties:
+- compatible : "nuvoton,npcm7xx-timer" for Poleg NPCM7xx.
+- reg : Offset and length of the register set for the device.
+- interrupts : Contain the timer interrupt with flags for
+ falling edge.
+
+Required clocking property, have to be one of:
+- clocks : phandle of timer reference clock.
+- clock-frequency : The frequency in Hz of the clock that drives the NPCM7xx
+ timer (usually 25000000).
+
+Example:
+
+timer@f0008000 {
+ compatible = "nuvoton,npcm7xx-timer";
+ interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
+ reg = <0xf0008000 0x1000>;
+ clocks = <&clk NPCM7XX_CLK_TIMER>;
+};
+
--
2.14.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v1 1/2] clocksource: npcm: add NPCM7xx timer driver
2017-10-01 9:11 ` [PATCH v1 1/2] " Tomer Maimon
@ 2017-10-01 16:44 ` Daniel Lezcano
0 siblings, 0 replies; 11+ messages in thread
From: Daniel Lezcano @ 2017-10-01 16:44 UTC (permalink / raw)
To: Tomer Maimon
Cc: robh+dt, mark.rutland, tglx, avifishman70, brendanhiggins,
raltherr, joel, devicetree, linux-kernel, openbmc
Hi Tomer,
On Sun, Oct 01, 2017 at 12:11:37PM +0300, Tomer Maimon wrote:
> Add Nuvoton BMC NPCM7xx timer driver.
Give a more detailed description of the timer please.
> Signed-off-by: Tomer Maimon <tmaimon77@gmail.com>
> ---
> drivers/clocksource/Kconfig | 9 ++
> drivers/clocksource/Makefile | 1 +
> drivers/clocksource/npcm7xx_timer.c | 205 ++++++++++++++++++++++++++++++++++++
Rename the driver to timer-npcm7xx.c
> 3 files changed, 215 insertions(+)
> create mode 100644 drivers/clocksource/npcm7xx_timer.c
>
> diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
> index cc6062049170..e26a203ce4ab 100644
> --- a/drivers/clocksource/Kconfig
> +++ b/drivers/clocksource/Kconfig
> @@ -140,6 +140,15 @@ config VT8500_TIMER
> help
> Enables support for the VT8500 driver.
>
> +config NPCM7XX_TIMER
> + bool "NPCM7xx timer driver" if (COMPILE_TEST || ARCH_NPCM7XX)
Remove the ARCH_NPCM7XX dependency, we want to have the timer selection hidden.
> + depends on GENERIC_CLOCKEVENTS
You can remove this dependency, there is a patch in the queue moving the
dependency up for all the timers.
> + depends on HAS_IOMEM
> + select CLKSRC_MMIO
> + help
> + Enable 24-bit TIMER0 and TIMER1 counters in the NPCM7xx arcithcture,
> + While TIMER0 serves as clockevent and TIMER1 serves as clocksource.
> +
> config CADENCE_TTC_TIMER
> bool "Cadence TTC timer driver" if COMPILE_TEST
> depends on COMMON_CLK
> diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
> index dbc1ad14515e..fd3a1c33364b 100644
> --- a/drivers/clocksource/Makefile
> +++ b/drivers/clocksource/Makefile
> @@ -53,6 +53,7 @@ obj-$(CONFIG_CLKSRC_TI_32K) += timer-ti-32k.o
> obj-$(CONFIG_CLKSRC_NPS) += timer-nps.o
> obj-$(CONFIG_OXNAS_RPS_TIMER) += timer-oxnas-rps.o
> obj-$(CONFIG_OWL_TIMER) += owl-timer.o
> +obj-$(CONFIG_NPCM7XX_TIMER) += npcm7xx_timer.o
>
> obj-$(CONFIG_ARC_TIMERS) += arc_timer.o
> obj-$(CONFIG_ARM_ARCH_TIMER) += arm_arch_timer.o
> diff --git a/drivers/clocksource/npcm7xx_timer.c b/drivers/clocksource/npcm7xx_timer.c
> new file mode 100644
> index 000000000000..6da77202a22d
> --- /dev/null
> +++ b/drivers/clocksource/npcm7xx_timer.c
> @@ -0,0 +1,205 @@
> +/*
> + * Copyright (c) 2017 Nuvoton Technology corporation.
> + * Copyright 2017 Google, Inc.
> + *
> + * 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 <linux/kernel.h>
> +#include <linux/sched.h>
> +#include <linux/init.h>
> +#include <linux/interrupt.h>
> +#include <linux/err.h>
> +#include <linux/clk.h>
> +#include <linux/io.h>
> +#include <linux/clockchips.h>
> +#include <linux/of_irq.h>
> +#include <linux/of_address.h>
> +
> +struct npcm7xx_clockevent_data {
> + struct clock_event_device cvd;
> + void __iomem *timer_base;
> + unsigned int rate;
> +};
> +
> +/* Timers registers */
> +#define REG_TCSR0 0x0 /* Timer 0 Control and Status Register */
> +#define REG_TICR0 0x8 /* Timer 0 Initial Count Register */
> +#define REG_TCSR1 0x4 /* Timer 1 Control and Status Register */
> +#define REG_TICR1 0xc /* Timer 1 Initial Count Register */
> +#define REG_TDR1 0x14 /* Timer 1 Data Register */
> +#define REG_TISR 0x18 /* Timer Interrupt Status Register */
> +
> +#define RESETINT 0x1f
> +#define PERIOD BIT(27)
> +#define INTEN BIT(29)
> +#define COUNTEN BIT(30)
> +#define ONESHOT 0x0
> +#define TIMER_OPER GENMASK(3, 27)
> +#define MIN_PRESCALE 0x1 /* minimal timer prescale */
> +#define TDR_MASK_BITS 24
Extra tab.
The macro names are too generic, please prefix them, eg. NPCM7XX_PERIOD
> +#define MAX_TIMER_CNT 0xFFFFFF
> +#define CLR_TIMER0_INT 0x1
> +#define CLR_TIMER_CSR 0x0
>
> +static int npcm7xx_timer_oneshot(struct clock_event_device *evt)
> +{
> + u32 val;
> + struct npcm7xx_clockevent_data *cevtd =
> + container_of(evt, struct npcm7xx_clockevent_data, cvd);
nit: alignment
> +
> + val = readl(cevtd->timer_base + REG_TCSR0);
> + val &= ~TIMER_OPER;
> +
> + val = readl(cevtd->timer_base + REG_TCSR0);
> + val |= (ONESHOT | COUNTEN | INTEN | MIN_PRESCALE);
These flags combination may deserve a macro.
> + writel(val, cevtd->timer_base + REG_TCSR0);
> +
> + return 0;
> +}
> +
> +static int npcm7xx_timer_periodic(struct clock_event_device *evt)
> +{
> + struct npcm7xx_clockevent_data *cevtd =
> + container_of(evt, struct npcm7xx_clockevent_data, cvd);
> + u32 val;
> +
> + val = readl(cevtd->timer_base + REG_TCSR0);
> + val &= ~TIMER_OPER;
> +
> + writel((cevtd->rate / HZ), cevtd->timer_base + REG_TICR0);
> + val |= (PERIOD | COUNTEN | INTEN | MIN_PRESCALE);
> +
> + writel(val, cevtd->timer_base + REG_TCSR0);
> +
> + return 0;
> +}
> +
> +static int npcm7xx_clockevent_setnextevent(unsigned long evt,
> + struct clock_event_device *clk)
> +{
> + struct npcm7xx_clockevent_data *cevtd =
> + container_of(clk, struct npcm7xx_clockevent_data, cvd);
> + u32 val;
> +
> + writel(evt, cevtd->timer_base + REG_TICR0);
> + val = readl(cevtd->timer_base + REG_TCSR0);
> + val |= (COUNTEN | INTEN | MIN_PRESCALE);
> + writel(val, cevtd->timer_base + REG_TCSR0);
> +
> + return 0;
> +}
> +
> +static struct npcm7xx_clockevent_data npcm7xx_clockevent_data = {
> + .cvd = {
> + .name = "npcm7xx-timer0",
> + .features = CLOCK_EVT_FEAT_PERIODIC |
> + CLOCK_EVT_FEAT_ONESHOT,
> + .set_next_event = npcm7xx_clockevent_setnextevent,
> + .set_state_shutdown = npcm7xx_timer_oneshot,
> + .set_state_periodic = npcm7xx_timer_periodic,
> + .set_state_oneshot = npcm7xx_timer_oneshot,
> + .tick_resume = npcm7xx_timer_oneshot,
> + .rating = 300
> + },
> +};
> +
> +static irqreturn_t npcm7xx_timer0_interrupt(int irq, void *dev_id)
> +{
> + struct npcm7xx_clockevent_data *cevtd = dev_id;
> + struct clock_event_device *evt = &cevtd->cvd;
> +
> + writel(CLR_TIMER0_INT, cevtd->timer_base + REG_TISR);
> +
> + if (evt->event_handler)
> + evt->event_handler(evt);
In which scenario it is possible to have this condition false?
> + return IRQ_HANDLED;
> +}
> +
> +static struct irqaction npcm7xx_timer0_irq = {
> + .name = "npcm7xx-timer0",
> + .flags = IRQF_TIMER | IRQF_IRQPOLL,
> + .handler = npcm7xx_timer0_interrupt,
> + .dev_id = &npcm7xx_clockevent_data,
> +};
> +
> +static void __init npcm7xx_clockevents_init(int irq, u32 rate)
> +{
> + writel(CLR_TIMER_CSR, npcm7xx_clockevent_data.timer_base + REG_TCSR0);
> +
> + writel(RESETINT, npcm7xx_clockevent_data.timer_base + REG_TISR);
> + setup_irq(irq, &npcm7xx_timer0_irq);
Consider using request_irq instead of setup_irq or, see below, timer-of.c API.
> + npcm7xx_clockevent_data.cvd.cpumask = cpumask_of(0);
> +
> + clockevents_config_and_register(&npcm7xx_clockevent_data.cvd, rate,
> + 0x1, MAX_TIMER_CNT);
> +}
> +
> +static void __init npcm7xx_clocksource_init(u32 rate)
> +{
> + u32 val;
> +
> + writel(CLR_TIMER_CSR, npcm7xx_clockevent_data.timer_base + REG_TCSR1);
> + writel(MAX_TIMER_CNT, npcm7xx_clockevent_data.timer_base + REG_TICR1);
> +
> + val = readl(npcm7xx_clockevent_data.timer_base + REG_TCSR1);
> + val |= (COUNTEN | PERIOD | MIN_PRESCALE);
> + writel(val, npcm7xx_clockevent_data.timer_base + REG_TCSR1);
> +
> + clocksource_mmio_init(npcm7xx_clockevent_data.timer_base + REG_TDR1,
> + "npcm7xx-timer1", rate,
> + 300, (unsigned int)TDR_MASK_BITS,
> + clocksource_mmio_readl_down);
> +}
> +
> +static int __init npcm7xx_timer_init(struct device_node *np)
> +{
> + struct clk *clk;
> + int irq, ret;
> + u32 rate;
> +
> + irq = irq_of_parse_and_map(np, 0);
> + if (!irq)
> + return -EINVAL;
> +
> + npcm7xx_clockevent_data.timer_base = of_iomap(np, 0);
> + if (!npcm7xx_clockevent_data.timer_base)
> + return -ENXIO;
> +
> + clk = of_clk_get(np, 0);
> +
> + if (IS_ERR(clk)) {
> + ret = of_property_read_u32(np, "clock-frequency", &rate);
> + if (ret)
> + goto err_iounmap;
> + } else {
> + clk_prepare_enable(clk);
> + rate = clk_get_rate(clk);
> + }
> +
> + /* Clock input is divided by PRESCALE + 1 before it is fed */
> + /* to the counter */
> + rate = rate / (MIN_PRESCALE + 1);
> +
> + npcm7xx_clockevent_data.rate = rate;
Can you consider using the timer-of.c API? It should simplify the code.
> +
> + npcm7xx_clocksource_init(rate);
> + npcm7xx_clockevents_init(irq, rate);
> +
> + pr_info("Enabling NPCM7xx clocksource timer base: %p, IRQ: %u\n",
> + npcm7xx_clockevent_data.timer_base, irq);
> +
> + return 0;
> +
> +err_iounmap:
> + iounmap(npcm7xx_clockevent_data.timer_base);
> + return ret;
> +
> +}
> +
> +TIMER_OF_DECLARE(npcm7xx, "nuvoton,npcm7xx-timer", npcm7xx_timer_init);
> +
> --
> 2.14.1
>
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v1 0/2] clocksource: npcm: add NPCM7xx timer driver
@ 2017-10-01 16:47 ` Daniel Lezcano
0 siblings, 0 replies; 11+ messages in thread
From: Daniel Lezcano @ 2017-10-01 16:47 UTC (permalink / raw)
To: Tomer Maimon
Cc: robh+dt, mark.rutland, tglx, avifishman70, brendanhiggins,
raltherr, joel, devicetree, linux-kernel, openbmc
On Sun, Oct 01, 2017 at 12:11:36PM +0300, Tomer Maimon wrote:
> This patch set adds clocksource support for the Nuvoton NPCM7xx Baseboard
> Management Controller (BMC).
>
> The clocksource Enable 24-bit TIMER0 and TIMER1 counters in the NPCM7xx BMC,
> while TIMER0 serves as clockevent and TIMER1 serves as clocksource.
>
> clocksource patch set depand on approval of basic support for Nuvoton BMCs
> and Nuvoton NPCM750 device tree patches.
> https://patchwork.kernel.org/bundle/brendanhiggins/arm:%20npcm:%20add%20basic%20support%20for%20Nuvoton%20BMCs/
>
> Tomer Maimon (2):
> clocksource: npcm: add NPCM7xx timer driver
> dt-binding: timer: document NPCM7xx timer DT bindings
>
> .../bindings/timer/nuvoton,npcm7xx-timer.txt | 25 +++
> drivers/clocksource/Kconfig | 9 +
> drivers/clocksource/Makefile | 1 +
> drivers/clocksource/npcm7xx_timer.c | 205 +++++++++++++++++++++
> 4 files changed, 240 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
Add me in copy of the binding, so I can take the patch along with the driver.
Thanks.
-- Daniel
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v1 0/2] clocksource: npcm: add NPCM7xx timer driver
@ 2017-10-01 16:47 ` Daniel Lezcano
0 siblings, 0 replies; 11+ messages in thread
From: Daniel Lezcano @ 2017-10-01 16:47 UTC (permalink / raw)
To: Tomer Maimon
Cc: robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
tglx-hfZtesqFncYOwBW4kG4KsQ, avifishman70-Re5JQEeQqe8AvxtiuMwx3w,
brendanhiggins-hpIqsD4AKlfQT0dZR+AlfA,
raltherr-hpIqsD4AKlfQT0dZR+AlfA, joel-U3u1mxZcP9KHXe+LvDLADg,
devicetree-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA,
openbmc-uLR06cmDAlY/bJ5BZ2RsiQ
On Sun, Oct 01, 2017 at 12:11:36PM +0300, Tomer Maimon wrote:
> This patch set adds clocksource support for the Nuvoton NPCM7xx Baseboard
> Management Controller (BMC).
>
> The clocksource Enable 24-bit TIMER0 and TIMER1 counters in the NPCM7xx BMC,
> while TIMER0 serves as clockevent and TIMER1 serves as clocksource.
>
> clocksource patch set depand on approval of basic support for Nuvoton BMCs
> and Nuvoton NPCM750 device tree patches.
> https://patchwork.kernel.org/bundle/brendanhiggins/arm:%20npcm:%20add%20basic%20support%20for%20Nuvoton%20BMCs/
>
> Tomer Maimon (2):
> clocksource: npcm: add NPCM7xx timer driver
> dt-binding: timer: document NPCM7xx timer DT bindings
>
> .../bindings/timer/nuvoton,npcm7xx-timer.txt | 25 +++
> drivers/clocksource/Kconfig | 9 +
> drivers/clocksource/Makefile | 1 +
> drivers/clocksource/npcm7xx_timer.c | 205 +++++++++++++++++++++
> 4 files changed, 240 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
Add me in copy of the binding, so I can take the patch along with the driver.
Thanks.
-- Daniel
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v1 2/2] dt-binding: timer: document NPCM7xx timer DT bindings
2017-10-01 9:11 ` [PATCH v1 2/2] dt-binding: timer: document NPCM7xx timer DT bindings Tomer Maimon
@ 2017-10-10 15:57 ` Rob Herring
2017-10-29 20:49 ` Tomer Maimon
0 siblings, 1 reply; 11+ messages in thread
From: Rob Herring @ 2017-10-10 15:57 UTC (permalink / raw)
To: Tomer Maimon
Cc: mark.rutland, daniel.lezcano, tglx, avifishman70, brendanhiggins,
raltherr, joel, devicetree, linux-kernel, openbmc
On Sun, Oct 01, 2017 at 12:11:38PM +0300, Tomer Maimon wrote:
> Added device tree binding documentation for Nuvoton NPCM7xx timer.
>
> Signed-off-by: Tomer Maimon <tmaimon77@gmail.com>
> ---
> .../bindings/timer/nuvoton,npcm7xx-timer.txt | 25 ++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
>
> diff --git a/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt b/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
> new file mode 100644
> index 000000000000..d1beea901509
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
> @@ -0,0 +1,25 @@
> +Nuvoton NPCM7xx timer
> +
> +Nuvoton NPCM7xx have three timer modules, each timer module provides five 24-bit
> +timer counters.
> +
> +Required properties:
> +- compatible : "nuvoton,npcm7xx-timer" for Poleg NPCM7xx.
Don't use wildcards in compatible strings. Use SoC specific compatible
strings with a fallback (the string for the 1st SoC which the block
appeared) if necessary.
> +- reg : Offset and length of the register set for the device.
> +- interrupts : Contain the timer interrupt with flags for
> + falling edge.
> +
> +Required clocking property, have to be one of:
> +- clocks : phandle of timer reference clock.
> +- clock-frequency : The frequency in Hz of the clock that drives the NPCM7xx
> + timer (usually 25000000).
> +
> +Example:
> +
> +timer@f0008000 {
> + compatible = "nuvoton,npcm7xx-timer";
> + interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
> + reg = <0xf0008000 0x1000>;
> + clocks = <&clk NPCM7XX_CLK_TIMER>;
> +};
> +
> --
> 2.14.1
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v1 2/2] dt-binding: timer: document NPCM7xx timer DT bindings
2017-10-10 15:57 ` Rob Herring
2017-10-29 20:49 ` Tomer Maimon
@ 2017-10-29 20:49 ` Tomer Maimon
0 siblings, 0 replies; 11+ messages in thread
From: Tomer Maimon @ 2017-10-29 20:49 UTC (permalink / raw)
To: Rob Herring
Cc: Mark Rutland, Daniel Lezcano, tglx, Avi Fishman, Brendan Higgins,
Rick Altherr, joel, devicetree, Linux Kernel Mailing List,
OpenBMC Maillist
Sorry for the delay,
On 10 October 2017 at 17:57, Rob Herring <robh@kernel.org> wrote:
> On Sun, Oct 01, 2017 at 12:11:38PM +0300, Tomer Maimon wrote:
>> Added device tree binding documentation for Nuvoton NPCM7xx timer.
>>
>> Signed-off-by: Tomer Maimon <tmaimon77@gmail.com>
>> ---
>> .../bindings/timer/nuvoton,npcm7xx-timer.txt | 25 ++++++++++++++++++++++
>> 1 file changed, 25 insertions(+)
>> create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
>>
>> diff --git a/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt b/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
>> new file mode 100644
>> index 000000000000..d1beea901509
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
>> @@ -0,0 +1,25 @@
>> +Nuvoton NPCM7xx timer
>> +
>> +Nuvoton NPCM7xx have three timer modules, each timer module provides five 24-bit
>> +timer counters.
>> +
>> +Required properties:
>> +- compatible : "nuvoton,npcm7xx-timer" for Poleg NPCM7xx.
>
> Don't use wildcards in compatible strings. Use SoC specific compatible
> strings with a fallback (the string for the 1st SoC which the block
> appeared) if necessary.
>
The SOC NPCM7xx is now on upstream process, I asked Brendan to modify
the NPCM7xx device tree to support the clock source driver
https://www.spinics.net/lists/arm-kernel/msg614424.html
and also the arcitecture name
https://www.spinics.net/lists/arm-kernel/msg614059.html
>> +- reg : Offset and length of the register set for the device.
>> +- interrupts : Contain the timer interrupt with flags for
>> + falling edge.
>> +
>> +Required clocking property, have to be one of:
>> +- clocks : phandle of timer reference clock.
>> +- clock-frequency : The frequency in Hz of the clock that drives the NPCM7xx
>> + timer (usually 25000000).
>> +
>> +Example:
>> +
>> +timer@f0008000 {
>> + compatible = "nuvoton,npcm7xx-timer";
>> + interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
>> + reg = <0xf0008000 0x1000>;
>> + clocks = <&clk NPCM7XX_CLK_TIMER>;
>> +};
>> +
>> --
>> 2.14.1
>>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v1 2/2] dt-binding: timer: document NPCM7xx timer DT bindings
@ 2017-10-29 20:49 ` Tomer Maimon
0 siblings, 0 replies; 11+ messages in thread
From: Tomer Maimon @ 2017-10-29 20:49 UTC (permalink / raw)
To: Rob Herring
Cc: Mark Rutland, Daniel Lezcano, tglx-hfZtesqFncYOwBW4kG4KsQ,
Avi Fishman, Brendan Higgins, Rick Altherr,
joel-U3u1mxZcP9KHXe+LvDLADg, devicetree,
Linux Kernel Mailing List, OpenBMC Maillist
Sorry for the delay,
On 10 October 2017 at 17:57, Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
> On Sun, Oct 01, 2017 at 12:11:38PM +0300, Tomer Maimon wrote:
>> Added device tree binding documentation for Nuvoton NPCM7xx timer.
>>
>> Signed-off-by: Tomer Maimon <tmaimon77-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> ---
>> .../bindings/timer/nuvoton,npcm7xx-timer.txt | 25 ++++++++++++++++++++++
>> 1 file changed, 25 insertions(+)
>> create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
>>
>> diff --git a/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt b/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
>> new file mode 100644
>> index 000000000000..d1beea901509
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
>> @@ -0,0 +1,25 @@
>> +Nuvoton NPCM7xx timer
>> +
>> +Nuvoton NPCM7xx have three timer modules, each timer module provides five 24-bit
>> +timer counters.
>> +
>> +Required properties:
>> +- compatible : "nuvoton,npcm7xx-timer" for Poleg NPCM7xx.
>
> Don't use wildcards in compatible strings. Use SoC specific compatible
> strings with a fallback (the string for the 1st SoC which the block
> appeared) if necessary.
>
The SOC NPCM7xx is now on upstream process, I asked Brendan to modify
the NPCM7xx device tree to support the clock source driver
https://www.spinics.net/lists/arm-kernel/msg614424.html
and also the arcitecture name
https://www.spinics.net/lists/arm-kernel/msg614059.html
>> +- reg : Offset and length of the register set for the device.
>> +- interrupts : Contain the timer interrupt with flags for
>> + falling edge.
>> +
>> +Required clocking property, have to be one of:
>> +- clocks : phandle of timer reference clock.
>> +- clock-frequency : The frequency in Hz of the clock that drives the NPCM7xx
>> + timer (usually 25000000).
>> +
>> +Example:
>> +
>> +timer@f0008000 {
>> + compatible = "nuvoton,npcm7xx-timer";
>> + interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
>> + reg = <0xf0008000 0x1000>;
>> + clocks = <&clk NPCM7XX_CLK_TIMER>;
>> +};
>> +
>> --
>> 2.14.1
>>
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v1 2/2] dt-binding: timer: document NPCM7xx timer DT bindings
@ 2017-10-29 20:49 ` Tomer Maimon
0 siblings, 0 replies; 11+ messages in thread
From: Tomer Maimon @ 2017-10-29 20:49 UTC (permalink / raw)
To: Rob Herring
Cc: Mark Rutland, Daniel Lezcano, tglx, Avi Fishman, Brendan Higgins,
Rick Altherr, joel, devicetree, Linux Kernel Mailing List,
OpenBMC Maillist
Sorry for the delay,
On 10 October 2017 at 17:57, Rob Herring <robh@kernel.org> wrote:
> On Sun, Oct 01, 2017 at 12:11:38PM +0300, Tomer Maimon wrote:
>> Added device tree binding documentation for Nuvoton NPCM7xx timer.
>>
>> Signed-off-by: Tomer Maimon <tmaimon77@gmail.com>
>> ---
>> .../bindings/timer/nuvoton,npcm7xx-timer.txt | 25 ++++++++++++++++++++++
>> 1 file changed, 25 insertions(+)
>> create mode 100644 Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
>>
>> diff --git a/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt b/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
>> new file mode 100644
>> index 000000000000..d1beea901509
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/timer/nuvoton,npcm7xx-timer.txt
>> @@ -0,0 +1,25 @@
>> +Nuvoton NPCM7xx timer
>> +
>> +Nuvoton NPCM7xx have three timer modules, each timer module provides five 24-bit
>> +timer counters.
>> +
>> +Required properties:
>> +- compatible : "nuvoton,npcm7xx-timer" for Poleg NPCM7xx.
>
> Don't use wildcards in compatible strings. Use SoC specific compatible
> strings with a fallback (the string for the 1st SoC which the block
> appeared) if necessary.
>
The SOC NPCM7xx is now on upstream process, I asked Brendan to modify
the NPCM7xx device tree to support the clock source driver
https://www.spinics.net/lists/arm-kernel/msg614424.html
and also the arcitecture name
https://www.spinics.net/lists/arm-kernel/msg614059.html
>> +- reg : Offset and length of the register set for the device.
>> +- interrupts : Contain the timer interrupt with flags for
>> + falling edge.
>> +
>> +Required clocking property, have to be one of:
>> +- clocks : phandle of timer reference clock.
>> +- clock-frequency : The frequency in Hz of the clock that drives the NPCM7xx
>> + timer (usually 25000000).
>> +
>> +Example:
>> +
>> +timer@f0008000 {
>> + compatible = "nuvoton,npcm7xx-timer";
>> + interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>;
>> + reg = <0xf0008000 0x1000>;
>> + clocks = <&clk NPCM7XX_CLK_TIMER>;
>> +};
>> +
>> --
>> 2.14.1
>>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2017-10-29 20:49 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-01 9:11 [PATCH v1 0/2] clocksource: npcm: add NPCM7xx timer driver Tomer Maimon
2017-10-01 9:11 ` Tomer Maimon
2017-10-01 9:11 ` [PATCH v1 1/2] " Tomer Maimon
2017-10-01 16:44 ` Daniel Lezcano
2017-10-01 9:11 ` [PATCH v1 2/2] dt-binding: timer: document NPCM7xx timer DT bindings Tomer Maimon
2017-10-10 15:57 ` Rob Herring
2017-10-29 20:49 ` Tomer Maimon
2017-10-29 20:49 ` Tomer Maimon
2017-10-29 20:49 ` Tomer Maimon
2017-10-01 16:47 ` [PATCH v1 0/2] clocksource: npcm: add NPCM7xx timer driver Daniel Lezcano
2017-10-01 16:47 ` Daniel Lezcano
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.