Linux-ARM-Kernel Archive on lore.kernel.org
 help / Atom feed
* [PATCH 00/17] ARM: davinci: modernize the timer support
@ 2019-01-11 17:21 Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 01/17] ARM: dts: da850: fix interrupt numbers for clocksource Bartosz Golaszewski
                   ` (16 more replies)
  0 siblings, 17 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

This series removes the legacy timer code from mach-davinci in favor of
a new clocksource driver it introduces.

The first patch fixes a device tree bug that's been around for a while.
Unfortunately any systems shipped with the buggy device will stop booting
once they switch to the new clocksource driver.

Patch 2 adds a new clocksource driver for davinci.

Patch 3 enables the new driver for device-tree based systems.

Patches 4-9 add a WARN() to the machine code of all davinci boards
which is triggered if clk_get() for the timer clock fails. This is needed
as the new driver expects the clock to be functional and doesn't check it.

Patches 10-11 and 13-16 switch the board files to using the new
clocksource driver while patch 12 moves some necessary defines to
a different place since we'll be removing the file that contains them.

Patch 17 removes legacy timer code.

Bartosz Golaszewski (17):
  ARM: dts: da850: fix interrupt numbers for clocksource
  clocksource: davinci-timer: new driver
  ARM: davinci: enable the clocksource driver for DT mode
  ARM: davinci: da850: WARN() if clk_get() fails
  ARM: davinci: da830: WARN() if clk_get() fails
  ARM: davinci: dm355: WARN() if clk_get() fails
  ARM: davinci: dm365: WARN() if clk_get() fails
  ARM: davinci: dm644x: WARN() if clk_get() fails
  ARM: davinci: dm646x: WARN() if clk_get() fails
  ARM: davinci: da850: switch to using the clocksource driver
  ARM: davinci: da830: switch to using the clocksource driver
  ARM: davinci: move timer definitions to davinci.h
  ARM: davinci: dm355: switch to using the clocksource driver
  ARM: davinci: dm365: switch to using the clocksource driver
  ARM: davinci: dm644x: switch to using the clocksource driver
  ARM: davinci: dm646x: switch to using the clocksource driver
  ARM: davinci: remove legacy timer support

 arch/arm/Kconfig                            |   1 +
 arch/arm/boot/dts/da850.dtsi                |   2 +-
 arch/arm/mach-davinci/Makefile              |   3 +-
 arch/arm/mach-davinci/da830.c               |  57 +--
 arch/arm/mach-davinci/da850.c               |  57 ++-
 arch/arm/mach-davinci/davinci.h             |   3 +
 arch/arm/mach-davinci/devices-da8xx.c       |   1 -
 arch/arm/mach-davinci/devices.c             |  19 -
 arch/arm/mach-davinci/dm355.c               |  37 +-
 arch/arm/mach-davinci/dm365.c               |  31 +-
 arch/arm/mach-davinci/dm644x.c              |  37 +-
 arch/arm/mach-davinci/dm646x.c              |  37 +-
 arch/arm/mach-davinci/include/mach/common.h |  17 -
 arch/arm/mach-davinci/include/mach/time.h   |  35 --
 arch/arm/mach-davinci/time.c                | 414 -------------------
 drivers/clocksource/Kconfig                 |   5 +
 drivers/clocksource/Makefile                |   1 +
 drivers/clocksource/timer-davinci.c         | 415 ++++++++++++++++++++
 include/clocksource/timer-davinci.h         |  35 ++
 19 files changed, 611 insertions(+), 596 deletions(-)
 delete mode 100644 arch/arm/mach-davinci/include/mach/time.h
 delete mode 100644 arch/arm/mach-davinci/time.c
 create mode 100644 drivers/clocksource/timer-davinci.c
 create mode 100644 include/clocksource/timer-davinci.h

-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 01/17] ARM: dts: da850: fix interrupt numbers for clocksource
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
@ 2019-01-11 17:21 ` Bartosz Golaszewski
  2019-01-17 14:22   ` Sekhar Nori
  2019-01-11 17:21 ` [PATCH 02/17] clocksource: davinci-timer: new driver Bartosz Golaszewski
                   ` (15 subsequent siblings)
  16 siblings, 1 reply; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, stable, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

The timer interrupts specified in commit 3652e2741f42 ("ARM: dts:
da850: Add clocks") are wrong but since the current timer code
hard-codes them, the bug was never spotted.

This patch must go into stable since, once we introduce a proper
clocksource driver, devices with buggy device tree will stop booting.

Fixes: 3652e2741f42 ("ARM: dts: da850: Add clocks")
Cc: stable@vger.kernel.org
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/boot/dts/da850.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
index 47aa53ba6b92..559659b399d0 100644
--- a/arch/arm/boot/dts/da850.dtsi
+++ b/arch/arm/boot/dts/da850.dtsi
@@ -476,7 +476,7 @@
 		clocksource: timer@20000 {
 			compatible = "ti,da830-timer";
 			reg = <0x20000 0x1000>;
-			interrupts = <12>, <13>;
+			interrupts = <21>, <22>;
 			interrupt-names = "tint12", "tint34";
 			clocks = <&pll0_auxclk>;
 		};
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 02/17] clocksource: davinci-timer: new driver
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 01/17] ARM: dts: da850: fix interrupt numbers for clocksource Bartosz Golaszewski
@ 2019-01-11 17:21 ` Bartosz Golaszewski
  2019-01-14 12:20   ` Sekhar Nori
  2019-01-11 17:21 ` [PATCH 03/17] ARM: davinci: enable the clocksource driver for DT mode Bartosz Golaszewski
                   ` (14 subsequent siblings)
  16 siblings, 1 reply; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Currently the clocksource and clockevent support for davinci platforms
lives in mach-davinci. It hard-codes many things, used global variables,
implements functionalities unused by any platform and has code fragments
scattered across many (often unrelated) files.

Implement a new, modern and simplified timer driver and put it into
drivers/clocksource. We still need to support legacy board files so
export a config structure and a function that allows machine code to
register the timer.

We don't check the return values of regmap reads and writes since with
mmio it's only likely to fail due to programmer's errors.

We also don't bother freeing resources on errors in
davinci_timer_register() as the system won't boot without a timer anyway.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/clocksource/Kconfig         |   5 +
 drivers/clocksource/Makefile        |   1 +
 drivers/clocksource/timer-davinci.c | 415 ++++++++++++++++++++++++++++
 include/clocksource/timer-davinci.h |  35 +++
 4 files changed, 456 insertions(+)
 create mode 100644 drivers/clocksource/timer-davinci.c
 create mode 100644 include/clocksource/timer-davinci.h

diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index a9e26f6a81a1..36d222c3fa4a 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -42,6 +42,11 @@ config BCM_KONA_TIMER
 	help
 	  Enables the support for the BCM Kona mobile timer driver.
 
+config DAVINCI_TIMER
+	bool "Texas Instruments DaVinci timer driver"
+	help
+	  Enables the support for the TI DaVinci timer driver.
+
 config DIGICOLOR_TIMER
 	bool "Digicolor timer driver" if COMPILE_TEST
 	select CLKSRC_MMIO
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index cdd210ff89ea..1be97aa7a699 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_SH_TIMER_TMU)	+= sh_tmu.o
 obj-$(CONFIG_EM_TIMER_STI)	+= em_sti.o
 obj-$(CONFIG_CLKBLD_I8253)	+= i8253.o
 obj-$(CONFIG_CLKSRC_MMIO)	+= mmio.o
+obj-$(CONFIG_DAVINCI_TIMER)	+= timer-davinci.o
 obj-$(CONFIG_DIGICOLOR_TIMER)	+= timer-digicolor.o
 obj-$(CONFIG_OMAP_DM_TIMER)	+= timer-ti-dm.o
 obj-$(CONFIG_DW_APB_TIMER)	+= dw_apb_timer.o
diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c
new file mode 100644
index 000000000000..7282a1fda80f
--- /dev/null
+++ b/drivers/clocksource/timer-davinci.c
@@ -0,0 +1,415 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * TI DaVinci clocksource driver
+ *
+ * Copyright (C) 2019 Texas Instruments
+ * Author: Bartosz Golaszewski <bgolaszewski@baylibre.com>
+ * (with some parts adopted from code by Kevin Hilman <khilman@baylibre.com>)
+ */
+
+#include <linux/clk.h>
+#include <linux/clockchips.h>
+#include <linux/clocksource.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/regmap.h>
+#include <linux/sched_clock.h>
+
+#include <clocksource/timer-davinci.h>
+
+#define DAVINCI_TIMER_REG_TIM12			0x10
+#define DAVINCI_TIMER_REG_TIM34			0x14
+#define DAVINCI_TIMER_REG_PRD12			0x18
+#define DAVINCI_TIMER_REG_PRD34			0x1c
+#define DAVINCI_TIMER_REG_TCR			0x20
+#define DAVINCI_TIMER_REG_TGCR			0x24
+
+#define DAVINCI_TIMER_TIMMODE_MASK		0x0000000c
+#define DAVINCI_TIMER_RESET_MASK		0x00000003
+#define DAVINCI_TIMER_TIMMODE_32BIT_UNCHAINED	0x00000004
+#define DAVINCI_TIMER_UNRESET			0x00000003
+
+/* Shift depends on timer. */
+#define DAVINCI_TIMER_ENAMODE_MASK		0x03
+#define DAVINCI_TIMER_ENAMODE_DISABLED		0x00
+#define DAVINCI_TIMER_ENAMODE_ONESHOT		0x01
+#define DAVINCI_TIMER_ENAMODE_PERIODIC		0x02
+
+#define DAVINCI_TIMER_ENAMODE_SHIFT_TIM12	6
+#define DAVINCI_TIMER_ENAMODE_SHIFT_TIM34	22
+
+#define DAVINCI_TIMER_MIN_DELTA			0x01
+#define DAVINCI_TIMER_MAX_DELTA			0xfffffffe
+
+#define DAVINCI_TIMER_CLKSRC_BITS		32
+
+enum {
+	DAVINCI_TIMER_MODE_DISABLED = 0,
+	DAVINCI_TIMER_MODE_ONESHOT,
+	DAVINCI_TIMER_MODE_PERIODIC,
+};
+
+struct davinci_timer_data;
+
+typedef void (*davinci_timer_set_period_func)(struct davinci_timer_data *,
+					      unsigned int period);
+
+struct davinci_timer_regs {
+	unsigned int tim_off;
+	unsigned int prd_off;
+	unsigned int enamode_shift;
+};
+
+struct davinci_timer_data {
+	const struct davinci_timer_regs *regs;
+	unsigned int mode;
+	struct regmap *map;
+	davinci_timer_set_period_func set_period;
+	unsigned int cmp_off;
+};
+
+struct davinci_timer_clockevent {
+	struct clock_event_device dev;
+	unsigned int tick_rate;
+	struct davinci_timer_data timer;
+};
+
+struct davinci_timer_clocksource {
+	struct clocksource dev;
+	struct davinci_timer_data timer;
+};
+
+static const struct regmap_config davinci_timer_regmap_config = {
+	.name			= "timer-davinci",
+	.reg_bits		= 32,
+	.reg_stride		= 4,
+	.val_bits		= 32,
+	.fast_io		= true,
+};
+
+static const struct davinci_timer_regs davinci_timer_tim12_regs = {
+	.tim_off		= DAVINCI_TIMER_REG_TIM12,
+	.prd_off		= DAVINCI_TIMER_REG_PRD12,
+	.enamode_shift		= DAVINCI_TIMER_ENAMODE_SHIFT_TIM12,
+};
+
+static const struct davinci_timer_regs davinci_timer_tim34_regs = {
+	.tim_off		= DAVINCI_TIMER_REG_TIM34,
+	.prd_off		= DAVINCI_TIMER_REG_PRD34,
+	.enamode_shift		= DAVINCI_TIMER_ENAMODE_SHIFT_TIM34,
+};
+
+/* Must be global for davinci_timer_read_sched_clock(). */
+static struct davinci_timer_data *davinci_timer_clksrc_timer;
+
+static struct davinci_timer_clockevent *
+to_davinci_timer_clockevent(struct clock_event_device *clockevent)
+{
+	return container_of(clockevent, struct davinci_timer_clockevent, dev);
+}
+
+static struct davinci_timer_clocksource *
+to_davinci_timer_clocksource(struct clocksource *clocksource)
+{
+	return container_of(clocksource, struct davinci_timer_clocksource, dev);
+}
+
+static void davinci_timer_set_period(struct davinci_timer_data *timer,
+				     unsigned int period)
+{
+	timer->set_period(timer, period);
+}
+
+static void davinci_timer_set_period_std(struct davinci_timer_data *timer,
+					 unsigned int period)
+{
+	const struct davinci_timer_regs *regs = timer->regs;
+	unsigned int enamode;
+
+	regmap_read(timer->map, DAVINCI_TIMER_REG_TCR, &enamode);
+
+	regmap_update_bits(timer->map, DAVINCI_TIMER_REG_TCR,
+			DAVINCI_TIMER_ENAMODE_MASK << regs->enamode_shift,
+			DAVINCI_TIMER_ENAMODE_DISABLED << regs->enamode_shift);
+
+	regmap_write(timer->map, regs->tim_off, 0x0);
+	regmap_write(timer->map, regs->prd_off, period);
+
+	if (timer->mode == DAVINCI_TIMER_MODE_ONESHOT)
+		enamode = DAVINCI_TIMER_ENAMODE_ONESHOT;
+	else if (timer->mode == DAVINCI_TIMER_MODE_PERIODIC)
+		enamode = DAVINCI_TIMER_ENAMODE_PERIODIC;
+
+	regmap_update_bits(timer->map, DAVINCI_TIMER_REG_TCR,
+			   DAVINCI_TIMER_ENAMODE_MASK << regs->enamode_shift,
+			   enamode << regs->enamode_shift);
+}
+
+static void davinci_timer_set_period_cmp(struct davinci_timer_data *timer,
+					 unsigned int period)
+{
+	const struct davinci_timer_regs *regs = timer->regs;
+	unsigned int curr_time;
+
+	regmap_read(timer->map, regs->tim_off, &curr_time);
+	regmap_write(timer->map, timer->cmp_off, curr_time + period);
+}
+
+static irqreturn_t davinci_timer_irq_timer(int irq, void *data)
+{
+	struct davinci_timer_clockevent *clockevent = data;
+
+	clockevent->dev.event_handler(&clockevent->dev);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t davinci_timer_irq_freerun(int irq, void *data)
+{
+	return IRQ_HANDLED;
+}
+
+static u64 notrace davinci_timer_read_sched_clock(void)
+{
+	struct davinci_timer_data *timer;
+	unsigned int val;
+
+	timer = davinci_timer_clksrc_timer;
+	regmap_read(timer->map, timer->regs->tim_off, &val);
+
+	return val;
+}
+
+static u64 davinci_timer_read(struct clocksource *dev)
+{
+	struct davinci_timer_clocksource *clocksource;
+	const struct davinci_timer_regs *regs;
+	unsigned int val;
+
+	clocksource = to_davinci_timer_clocksource(dev);
+	regs = clocksource->timer.regs;
+
+	regmap_read(clocksource->timer.map, regs->tim_off, &val);
+
+	return val;
+}
+
+static int davinci_timer_set_next_event(unsigned long cycles,
+					struct clock_event_device *dev)
+{
+	struct davinci_timer_clockevent *clockevent;
+
+	clockevent = to_davinci_timer_clockevent(dev);
+	davinci_timer_set_period(&clockevent->timer, cycles);
+
+	return 0;
+}
+
+static int davinci_timer_set_state_shutdown(struct clock_event_device *dev)
+{
+	struct davinci_timer_clockevent *clockevent;
+
+	clockevent = to_davinci_timer_clockevent(dev);
+	clockevent->timer.mode = DAVINCI_TIMER_MODE_DISABLED;
+
+	return 0;
+}
+
+static int davinci_timer_set_state_periodic(struct clock_event_device *dev)
+{
+	struct davinci_timer_clockevent *clockevent;
+	unsigned int period;
+
+	clockevent = to_davinci_timer_clockevent(dev);
+	period = clockevent->tick_rate / HZ;
+
+	clockevent->timer.mode = DAVINCI_TIMER_MODE_PERIODIC;
+	davinci_timer_set_period(&clockevent->timer, period);
+
+	return 0;
+}
+
+static int davinci_timer_set_state_oneshot(struct clock_event_device *dev)
+{
+	struct davinci_timer_clockevent *clockevent;
+
+	clockevent = to_davinci_timer_clockevent(dev);
+	clockevent->timer.mode = DAVINCI_TIMER_MODE_ONESHOT;
+
+	return 0;
+}
+
+int __init davinci_timer_register(struct clk *clk,
+				  const struct davinci_timer_cfg *timer_cfg)
+{
+	struct davinci_timer_clocksource *clocksource;
+	struct davinci_timer_clockevent *clockevent;
+	struct regmap *map;
+	int rv, clkev_irq;
+	void *base;
+
+	rv = clk_prepare_enable(clk);
+	if (rv) {
+		pr_err("%s: Unable to prepare and enable the timer clock\n",
+		       __func__);
+		return rv;
+	}
+
+	base = ioremap(timer_cfg->reg.start, resource_size(&timer_cfg->reg));
+	if (!base) {
+		pr_err("%s: Unable to map the register range", __func__);
+		return -ENOMEM;
+	}
+
+	map = regmap_init_mmio(NULL, base, &davinci_timer_regmap_config);
+	if (IS_ERR(map)) {
+		pr_err("%s: Error initiating regmap\n", __func__);
+		return PTR_ERR(map);
+	}
+
+	/* Global timer init. */
+
+	/* Set clock to internal mode and disable it. */
+	regmap_write(map, DAVINCI_TIMER_REG_TCR, 0x0);
+	/* Reset both 32-bit timers, set no prescaler for timer 34. */
+	regmap_write(map, DAVINCI_TIMER_REG_TGCR, 0x0);
+	/* Set the timer to dual 32-bit unchained mode. */
+	regmap_update_bits(map, DAVINCI_TIMER_REG_TGCR,
+			   DAVINCI_TIMER_TIMMODE_MASK,
+			   DAVINCI_TIMER_TIMMODE_32BIT_UNCHAINED);
+	/* Unreset both 32-bit timers. */
+	regmap_update_bits(map, DAVINCI_TIMER_REG_TGCR,
+			   DAVINCI_TIMER_RESET_MASK, DAVINCI_TIMER_UNRESET);
+	/* Init both counters to zero. */
+	regmap_write(map, DAVINCI_TIMER_REG_TIM12, 0x0);
+	regmap_write(map, DAVINCI_TIMER_REG_TIM34, 0x0);
+
+	/* Setup clockevent. */
+
+	clockevent = kzalloc(sizeof(*clockevent), GFP_KERNEL);
+	if (!clockevent) {
+		pr_err("%s: Error allocating memory for clockevent data",
+		       __func__);
+		return -ENOMEM;
+	}
+
+	clockevent->dev.name = "timer0_0";
+	clockevent->dev.features = CLOCK_EVT_FEAT_ONESHOT;
+	clockevent->dev.set_next_event = davinci_timer_set_next_event;
+	clockevent->dev.set_state_shutdown = davinci_timer_set_state_shutdown;
+	clockevent->dev.set_state_periodic = davinci_timer_set_state_periodic;
+	clockevent->dev.set_state_oneshot = davinci_timer_set_state_oneshot;
+	clockevent->dev.cpumask = cpumask_of(0);
+	clockevent->tick_rate = clk_get_rate(clk);
+	clockevent->timer.mode = DAVINCI_TIMER_MODE_DISABLED;
+	clockevent->timer.map = map;
+	clockevent->timer.regs = &davinci_timer_tim12_regs;
+
+	if (timer_cfg->cmp.offset) {
+		clkev_irq = timer_cfg->cmp.irq.start;
+		clockevent->timer.cmp_off = timer_cfg->cmp.offset;
+		clockevent->timer.set_period = davinci_timer_set_period_cmp;
+	} else {
+		clkev_irq = timer_cfg->irq[DAVINCI_TIMER_TIM12_IRQ].start;
+		clockevent->dev.features |= CLOCK_EVT_FEAT_PERIODIC;
+		clockevent->timer.set_period = davinci_timer_set_period_std;
+	}
+
+	rv = request_irq(clkev_irq, davinci_timer_irq_timer,
+			 IRQF_TIMER, "clockevent", clockevent);
+	if (rv) {
+		pr_err("%s: Unable to request the clockevent interrupt\n",
+		       __func__);
+		return rv;
+	}
+
+	clockevents_config_and_register(&clockevent->dev,
+					clockevent->tick_rate,
+					DAVINCI_TIMER_MIN_DELTA,
+					DAVINCI_TIMER_MAX_DELTA);
+
+	/* Setup clocksource */
+
+	clocksource = kzalloc(sizeof(*clocksource), GFP_KERNEL);
+	if (!clocksource) {
+		pr_err("%s: Error allocating memory for clocksource data",
+		       __func__);
+		return -ENOMEM;
+	}
+
+	clocksource->dev.name = timer_cfg->cmp.offset ? "timer0_0" : "timer0_1";
+	clocksource->dev.rating = 300;
+	clocksource->dev.read = davinci_timer_read;
+	clocksource->dev.mask = CLOCKSOURCE_MASK(DAVINCI_TIMER_CLKSRC_BITS);
+	clocksource->dev.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	clocksource->timer.set_period = davinci_timer_set_period_std;
+	clocksource->timer.mode = DAVINCI_TIMER_MODE_PERIODIC;
+	clocksource->timer.map = map;
+	clocksource->timer.regs = &davinci_timer_tim34_regs;
+
+	rv = request_irq(timer_cfg->irq[DAVINCI_TIMER_TIM34_IRQ].start,
+			 davinci_timer_irq_freerun, IRQF_TIMER,
+			 "free-run counter", clocksource);
+	if (rv) {
+		pr_err("%s: Unable to request the clocksource interrupt\n",
+		       __func__);
+		return rv;
+	}
+
+	rv = clocksource_register_hz(&clocksource->dev, clockevent->tick_rate);
+	if (rv) {
+		pr_err("%s: Unable to register clocksource\n",
+		       __func__);
+		return rv;
+	}
+
+	davinci_timer_clksrc_timer = &clocksource->timer;
+
+	sched_clock_register(davinci_timer_read_sched_clock,
+			     DAVINCI_TIMER_CLKSRC_BITS,
+			     clockevent->tick_rate);
+
+	davinci_timer_set_period(&clockevent->timer,
+				 clockevent->tick_rate / HZ);
+	davinci_timer_set_period(&clocksource->timer, UINT_MAX);
+
+	return 0;
+}
+
+static int __init of_davinci_timer_register(struct device_node *np)
+{
+	struct davinci_timer_cfg timer_cfg = { };
+	struct clk *clk;
+	int rv;
+
+	rv = of_address_to_resource(np, 0, &timer_cfg.reg);
+	if (rv) {
+		pr_err("%s: Unable to get the register range for timer\n",
+		       __func__);
+		return rv;
+	}
+
+	rv = of_irq_to_resource_table(np, timer_cfg.irq,
+				      DAVINCI_TIMER_NUM_IRQS);
+	if (rv != DAVINCI_TIMER_NUM_IRQS) {
+		pr_err("%s: Unable to get the interrupts for timer\n",
+		       __func__);
+		return rv;
+	}
+
+	clk = of_clk_get(np, 0);
+	if (IS_ERR(clk)) {
+		pr_err("%s: Unable to get the timer clock\n", __func__);
+		return PTR_ERR(clk);
+	}
+
+	rv = davinci_timer_register(clk, &timer_cfg);
+	if (rv)
+		clk_put(clk);
+
+	return rv;
+}
+TIMER_OF_DECLARE(davinci_timer, "ti,da830-timer", of_davinci_timer_register);
diff --git a/include/clocksource/timer-davinci.h b/include/clocksource/timer-davinci.h
new file mode 100644
index 000000000000..77a98cbd040b
--- /dev/null
+++ b/include/clocksource/timer-davinci.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * TI DaVinci clocksource driver
+ *
+ * Copyright (C) 2019 Texas Instruments
+ * Author: Bartosz Golaszewski <bgolaszewski@baylibre.com>
+ */
+
+#ifndef __TIMER_DAVINCI_H__
+#define __TIMER_DAVINCI_H__
+
+#include <linux/clk.h>
+#include <linux/ioport.h>
+
+enum {
+	DAVINCI_TIMER_TIM12_IRQ = 0,
+	DAVINCI_TIMER_TIM34_IRQ,
+	DAVINCI_TIMER_NUM_IRQS,
+};
+
+struct davinci_timer_cmp_cfg {
+	struct resource irq;
+	unsigned int offset;
+};
+
+struct davinci_timer_cfg {
+	struct resource reg;
+	struct resource irq[DAVINCI_TIMER_NUM_IRQS];
+	struct davinci_timer_cmp_cfg cmp;
+};
+
+int __init davinci_timer_register(struct clk *clk,
+				  const struct davinci_timer_cfg *data);
+
+#endif /* __TIMER_DAVINCI_H__ */
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 03/17] ARM: davinci: enable the clocksource driver for DT mode
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 01/17] ARM: dts: da850: fix interrupt numbers for clocksource Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 02/17] clocksource: davinci-timer: new driver Bartosz Golaszewski
@ 2019-01-11 17:21 ` Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 04/17] ARM: davinci: da850: WARN() if clk_get() fails Bartosz Golaszewski
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Switch all davinci boards using device tree to using the new
clocksource driver: remove the previous OF_TIMER_DECLARE() from
mach-davinci and select davinci-timer to be built for
davinci_all_defconfig.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/Kconfig             |  1 +
 arch/arm/mach-davinci/time.c | 14 --------------
 2 files changed, 1 insertion(+), 14 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 664e918e2624..8a09a0ab0ce2 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -586,6 +586,7 @@ config ARCH_DAVINCI
 	select ARCH_HAS_HOLES_MEMORYMODEL
 	select COMMON_CLK
 	select CPU_ARM926T
+	select DAVINCI_TIMER
 	select GENERIC_ALLOCATOR
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_IRQ_CHIP
diff --git a/arch/arm/mach-davinci/time.c b/arch/arm/mach-davinci/time.c
index 5a6de5368ab0..740410a3bb6a 100644
--- a/arch/arm/mach-davinci/time.c
+++ b/arch/arm/mach-davinci/time.c
@@ -398,17 +398,3 @@ void __init davinci_timer_init(struct clk *timer_clk)
 	for (i=0; i< ARRAY_SIZE(timers); i++)
 		timer32_config(&timers[i]);
 }
-
-static int __init of_davinci_timer_init(struct device_node *np)
-{
-	struct clk *clk;
-
-	clk = of_clk_get(np, 0);
-	if (IS_ERR(clk))
-		return PTR_ERR(clk);
-
-	davinci_timer_init(clk);
-
-	return 0;
-}
-TIMER_OF_DECLARE(davinci_timer, "ti,da830-timer", of_davinci_timer_init);
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 04/17] ARM: davinci: da850: WARN() if clk_get() fails
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (2 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 03/17] ARM: davinci: enable the clocksource driver for DT mode Bartosz Golaszewski
@ 2019-01-11 17:21 ` Bartosz Golaszewski
  2019-01-14 12:22   ` Sekhar Nori
  2019-01-11 17:21 ` [PATCH 05/17] ARM: davinci: da830: " Bartosz Golaszewski
                   ` (12 subsequent siblings)
  16 siblings, 1 reply; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Currently the timer code checks if the clock pointer passed to it is
good (!IS_ERR(clk)). The new clocksource driver expects the clock to
be functional and doesn't perform any checks so emit a warning if
clk_get() fails.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/da850.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-davinci/da850.c b/arch/arm/mach-davinci/da850.c
index e7b78df2bfef..9ff377f26c4b 100644
--- a/arch/arm/mach-davinci/da850.c
+++ b/arch/arm/mach-davinci/da850.c
@@ -774,6 +774,7 @@ void __init da850_init_time(void)
 	da850_pll0_init(NULL, pll0, cfgchip);
 
 	clk = clk_get(NULL, "timer0");
+	WARN(IS_ERR(clk), "Unable to get the timer clock\n");
 
 	davinci_timer_init(clk);
 }
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 05/17] ARM: davinci: da830: WARN() if clk_get() fails
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (3 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 04/17] ARM: davinci: da850: WARN() if clk_get() fails Bartosz Golaszewski
@ 2019-01-11 17:21 ` " Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 06/17] ARM: davinci: dm355: " Bartosz Golaszewski
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Currently the timer code checks if the clock pointer passed to it is
good (!IS_ERR(clk)). The new clocksource driver expects the clock to
be functional and doesn't perform any checks so emit a warning if
clk_get() fails.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/da830.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-davinci/da830.c b/arch/arm/mach-davinci/da830.c
index 2cc9fe4c3a91..ceb0417f10f6 100644
--- a/arch/arm/mach-davinci/da830.c
+++ b/arch/arm/mach-davinci/da830.c
@@ -834,6 +834,7 @@ void __init da830_init_time(void)
 	da830_pll_init(NULL, pll, NULL);
 
 	clk = clk_get(NULL, "timer0");
+	WARN(IS_ERR(clk), "Unable to get the timer clock\n");
 
 	davinci_timer_init(clk);
 }
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 06/17] ARM: davinci: dm355: WARN() if clk_get() fails
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (4 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 05/17] ARM: davinci: da830: " Bartosz Golaszewski
@ 2019-01-11 17:21 ` " Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 07/17] ARM: davinci: dm365: " Bartosz Golaszewski
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Currently the timer code checks if the clock pointer passed to it is
good (!IS_ERR(clk)). The new clocksource driver expects the clock to
be functional and doesn't perform any checks so emit a warning if
clk_get() fails.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/dm355.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-davinci/dm355.c b/arch/arm/mach-davinci/dm355.c
index 4c6e0bef4509..07ad9d6c9cae 100644
--- a/arch/arm/mach-davinci/dm355.c
+++ b/arch/arm/mach-davinci/dm355.c
@@ -745,6 +745,7 @@ void __init dm355_init_time(void)
 	dm355_psc_init(NULL, psc);
 
 	clk = clk_get(NULL, "timer0");
+	WARN(IS_ERR(clk), "Unable to get the timer clock\n");
 
 	davinci_timer_init(clk);
 }
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 07/17] ARM: davinci: dm365: WARN() if clk_get() fails
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (5 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 06/17] ARM: davinci: dm355: " Bartosz Golaszewski
@ 2019-01-11 17:21 ` " Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 08/17] ARM: davinci: dm644x: " Bartosz Golaszewski
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Currently the timer code checks if the clock pointer passed to it is
good (!IS_ERR(clk)). The new clocksource driver expects the clock to
be functional and doesn't perform any checks so emit a warning if
clk_get() fails.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/dm365.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-davinci/dm365.c b/arch/arm/mach-davinci/dm365.c
index 01fb2b0c82de..842b7e706ba1 100644
--- a/arch/arm/mach-davinci/dm365.c
+++ b/arch/arm/mach-davinci/dm365.c
@@ -786,6 +786,7 @@ void __init dm365_init_time(void)
 	dm365_psc_init(NULL, psc);
 
 	clk = clk_get(NULL, "timer0");
+	WARN(IS_ERR(clk), "Unable to get the timer clock\n");
 
 	davinci_timer_init(clk);
 }
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 08/17] ARM: davinci: dm644x: WARN() if clk_get() fails
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (6 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 07/17] ARM: davinci: dm365: " Bartosz Golaszewski
@ 2019-01-11 17:21 ` " Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 09/17] ARM: davinci: dm646x: " Bartosz Golaszewski
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Currently the timer code checks if the clock pointer passed to it is
good (!IS_ERR(clk)). The new clocksource driver expects the clock to
be functional and doesn't perform any checks so emit a warning if
clk_get() fails.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/dm644x.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-davinci/dm644x.c b/arch/arm/mach-davinci/dm644x.c
index 38f92b7d413e..85d69ac1bd70 100644
--- a/arch/arm/mach-davinci/dm644x.c
+++ b/arch/arm/mach-davinci/dm644x.c
@@ -681,6 +681,7 @@ void __init dm644x_init_time(void)
 	dm644x_psc_init(NULL, psc);
 
 	clk = clk_get(NULL, "timer0");
+	WARN(IS_ERR(clk), "Unable to get the timer clock\n");
 
 	davinci_timer_init(clk);
 }
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 09/17] ARM: davinci: dm646x: WARN() if clk_get() fails
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (7 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 08/17] ARM: davinci: dm644x: " Bartosz Golaszewski
@ 2019-01-11 17:21 ` " Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 10/17] ARM: davinci: da850: switch to using the clocksource driver Bartosz Golaszewski
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Currently the timer code checks if the clock pointer passed to it is
good (!IS_ERR(clk)). The new clocksource driver expects the clock to
be functional and doesn't perform any checks so emit a warning if
clk_get() fails.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/dm646x.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-davinci/dm646x.c b/arch/arm/mach-davinci/dm646x.c
index 7dc54b2a610f..018315fa9aa9 100644
--- a/arch/arm/mach-davinci/dm646x.c
+++ b/arch/arm/mach-davinci/dm646x.c
@@ -665,6 +665,7 @@ void __init dm646x_init_time(unsigned long ref_clk_rate,
 	dm646x_psc_init(NULL, psc);
 
 	clk = clk_get(NULL, "timer0");
+	WARN(IS_ERR(clk), "Unable to get the timer clock\n");
 
 	davinci_timer_init(clk);
 }
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 10/17] ARM: davinci: da850: switch to using the clocksource driver
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (8 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 09/17] ARM: davinci: dm646x: " Bartosz Golaszewski
@ 2019-01-11 17:21 ` Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 11/17] ARM: davinci: da830: " Bartosz Golaszewski
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

We now have a proper clocksource driver for davinci. Switch the platform
to using it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/da850.c | 56 ++++++++++++++---------------------
 1 file changed, 22 insertions(+), 34 deletions(-)

diff --git a/arch/arm/mach-davinci/da850.c b/arch/arm/mach-davinci/da850.c
index 9ff377f26c4b..e5b855103193 100644
--- a/arch/arm/mach-davinci/da850.c
+++ b/arch/arm/mach-davinci/da850.c
@@ -34,7 +34,8 @@
 #include <mach/da8xx.h>
 #include <mach/irqs.h>
 #include <mach/pm.h>
-#include <mach/time.h>
+
+#include <clocksource/timer-davinci.h>
 
 #include "mux.h"
 
@@ -436,38 +437,24 @@ static struct davinci_id da850_ids[] = {
 	},
 };
 
-static struct davinci_timer_instance da850_timer_instance[4] = {
-	{
-		.base		= DA8XX_TIMER64P0_BASE,
-		.bottom_irq	= IRQ_DA8XX_TINT12_0,
-		.top_irq	= IRQ_DA8XX_TINT34_0,
-	},
-	{
-		.base		= DA8XX_TIMER64P1_BASE,
-		.bottom_irq	= IRQ_DA8XX_TINT12_1,
-		.top_irq	= IRQ_DA8XX_TINT34_1,
-	},
-	{
-		.base		= DA850_TIMER64P2_BASE,
-		.bottom_irq	= IRQ_DA850_TINT12_2,
-		.top_irq	= IRQ_DA850_TINT34_2,
-	},
-	{
-		.base		= DA850_TIMER64P3_BASE,
-		.bottom_irq	= IRQ_DA850_TINT12_3,
-		.top_irq	= IRQ_DA850_TINT34_3,
+static const struct davinci_timer_cfg da850_timer_cfg = {
+	.reg = {
+		.start		= DA8XX_TIMER64P0_BASE,
+		.end		= DA8XX_TIMER64P0_BASE + SZ_4K,
+		.flags		= IORESOURCE_MEM,
 	},
-};
-
-/*
- * T0_BOT: Timer 0, bottom		: Used for clock_event
- * T0_TOP: Timer 0, top			: Used for clocksource
- * T1_BOT, T1_TOP: Timer 1, bottom & top: Used for watchdog timer
- */
-static struct davinci_timer_info da850_timer_info = {
-	.timers		= da850_timer_instance,
-	.clockevent_id	= T0_BOT,
-	.clocksource_id	= T0_TOP,
+	.irq = {
+		{
+			.start	= IRQ_DA8XX_TINT12_0,
+			.end	= IRQ_DA8XX_TINT12_0,
+			.flags	= IORESOURCE_IRQ,
+		},
+		{
+			.start	= IRQ_DA8XX_TINT34_0,
+			.end	= IRQ_DA8XX_TINT34_0,
+			.flags	= IORESOURCE_IRQ,
+		}
+	}
 };
 
 #ifdef CONFIG_CPU_FREQ
@@ -742,7 +729,6 @@ static const struct davinci_soc_info davinci_soc_info_da850 = {
 	.intc_type		= DAVINCI_INTC_TYPE_CP_INTC,
 	.intc_irq_prios		= da850_default_priorities,
 	.intc_irq_num		= DA850_N_CP_INTC_IRQ,
-	.timer_info		= &da850_timer_info,
 	.emac_pdata		= &da8xx_emac_pdata,
 	.sram_dma		= DA8XX_SHARED_RAM_BASE,
 	.sram_len		= SZ_128K,
@@ -765,6 +751,7 @@ void __init da850_init_time(void)
 	void __iomem *pll0;
 	struct regmap *cfgchip;
 	struct clk *clk;
+	int rv;
 
 	clk_register_fixed_rate(NULL, "ref_clk", NULL, 0, DA850_REF_FREQ);
 
@@ -776,7 +763,8 @@ void __init da850_init_time(void)
 	clk = clk_get(NULL, "timer0");
 	WARN(IS_ERR(clk), "Unable to get the timer clock\n");
 
-	davinci_timer_init(clk);
+	rv = davinci_timer_register(clk, &da850_timer_cfg);
+	WARN(rv, "Unable to register the timer: %d\n", rv);
 }
 
 static struct resource da850_pll1_resources[] = {
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 11/17] ARM: davinci: da830: switch to using the clocksource driver
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (9 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 10/17] ARM: davinci: da850: switch to using the clocksource driver Bartosz Golaszewski
@ 2019-01-11 17:21 ` " Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 12/17] ARM: davinci: move timer definitions to davinci.h Bartosz Golaszewski
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

We now have a proper clocksource driver for davinci. Switch the platform
to using it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/da830.c | 56 ++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 27 deletions(-)

diff --git a/arch/arm/mach-davinci/da830.c b/arch/arm/mach-davinci/da830.c
index ceb0417f10f6..0d81a8fdd9e6 100644
--- a/arch/arm/mach-davinci/da830.c
+++ b/arch/arm/mach-davinci/da830.c
@@ -20,7 +20,8 @@
 #include <mach/cputype.h>
 #include <mach/da8xx.h>
 #include <mach/irqs.h>
-#include <mach/time.h>
+
+#include <clocksource/timer-davinci.h>
 
 #include "mux.h"
 
@@ -769,32 +770,32 @@ int __init da830_register_gpio(void)
 	return da8xx_register_gpio(&da830_gpio_platform_data);
 }
 
-static struct davinci_timer_instance da830_timer_instance[2] = {
-	{
-		.base		= DA8XX_TIMER64P0_BASE,
-		.bottom_irq	= IRQ_DA8XX_TINT12_0,
-		.top_irq	= IRQ_DA8XX_TINT34_0,
-		.cmp_off	= DA830_CMP12_0,
-		.cmp_irq	= IRQ_DA830_T12CMPINT0_0,
+static const struct davinci_timer_cfg da830_timer_cfg = {
+	.reg = {
+		.start		= DA8XX_TIMER64P0_BASE,
+		.end		= DA8XX_TIMER64P0_BASE + SZ_4K,
+		.flags		= IORESOURCE_MEM,
 	},
-	{
-		.base		= DA8XX_TIMER64P1_BASE,
-		.bottom_irq	= IRQ_DA8XX_TINT12_1,
-		.top_irq	= IRQ_DA8XX_TINT34_1,
-		.cmp_off	= DA830_CMP12_0,
-		.cmp_irq	= IRQ_DA830_T12CMPINT0_1,
+	.irq = {
+		{
+			.start	= IRQ_DA8XX_TINT12_0,
+			.end	= IRQ_DA8XX_TINT12_0,
+			.flags	= IORESOURCE_IRQ,
+		},
+		{
+			.start	= IRQ_DA8XX_TINT34_0,
+			.end	= IRQ_DA8XX_TINT34_0,
+			.flags	= IORESOURCE_IRQ,
+		},
 	},
-};
-
-/*
- * T0_BOT: Timer 0, bottom		: Used for clock_event & clocksource
- * T0_TOP: Timer 0, top			: Used by DSP
- * T1_BOT, T1_TOP: Timer 1, bottom & top: Used for watchdog timer
- */
-static struct davinci_timer_info da830_timer_info = {
-	.timers		= da830_timer_instance,
-	.clockevent_id	= T0_BOT,
-	.clocksource_id	= T0_BOT,
+	.cmp = {
+		.irq = {
+			.start	= IRQ_DA830_T12CMPINT0_0,
+			.end	= IRQ_DA830_T12CMPINT0_0,
+			.flags	= IORESOURCE_IRQ,
+		},
+		.offset		= DA830_CMP12_0,
+	}
 };
 
 static const struct davinci_soc_info davinci_soc_info_da830 = {
@@ -810,7 +811,6 @@ static const struct davinci_soc_info davinci_soc_info_da830 = {
 	.intc_type		= DAVINCI_INTC_TYPE_CP_INTC,
 	.intc_irq_prios		= da830_default_priorities,
 	.intc_irq_num		= DA830_N_CP_INTC_IRQ,
-	.timer_info		= &da830_timer_info,
 	.emac_pdata		= &da8xx_emac_pdata,
 };
 
@@ -826,6 +826,7 @@ void __init da830_init_time(void)
 {
 	void __iomem *pll;
 	struct clk *clk;
+	int rv;
 
 	clk_register_fixed_rate(NULL, "ref_clk", NULL, 0, DA830_REF_FREQ);
 
@@ -836,7 +837,8 @@ void __init da830_init_time(void)
 	clk = clk_get(NULL, "timer0");
 	WARN(IS_ERR(clk), "Unable to get the timer clock\n");
 
-	davinci_timer_init(clk);
+	rv = davinci_timer_register(clk, &da830_timer_cfg);
+	WARN(rv, "Unable to register the timer: %d\n", rv);
 }
 
 static struct resource da830_psc0_resources[] = {
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 12/17] ARM: davinci: move timer definitions to davinci.h
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (10 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 11/17] ARM: davinci: da830: " Bartosz Golaszewski
@ 2019-01-11 17:21 ` Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 13/17] ARM: davinci: dm355: switch to using the clocksource driver Bartosz Golaszewski
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Boards from the dm* family rely on register offset definitions from
arch/arm/mach-davinci/include/mach/time.h. We'll be removing this file
soon, so move the required defines to davinci.h where the rest of such
constants live.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/davinci.h           | 3 +++
 arch/arm/mach-davinci/include/mach/time.h | 2 --
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-davinci/davinci.h b/arch/arm/mach-davinci/davinci.h
index db4c95ef4d5c..dfd1b1ab7b59 100644
--- a/arch/arm/mach-davinci/davinci.h
+++ b/arch/arm/mach-davinci/davinci.h
@@ -60,6 +60,9 @@ void davinci_map_sysmod(void);
 #define DAVINCI_GPIO_BASE 0x01C67000
 int davinci_gpio_register(struct resource *res, int size, void *pdata);
 
+#define DAVINCI_TIMER0_BASE		(IO_PHYS + 0x21400)
+#define DAVINCI_WDOG_BASE		(IO_PHYS + 0x21C00)
+
 /* DM355 base addresses */
 #define DM355_ASYNC_EMIF_CONTROL_BASE	0x01e10000
 #define DM355_ASYNC_EMIF_DATA_CE0_BASE	0x02000000
diff --git a/arch/arm/mach-davinci/include/mach/time.h b/arch/arm/mach-davinci/include/mach/time.h
index 1c971d8d8ba8..ba913736990f 100644
--- a/arch/arm/mach-davinci/include/mach/time.h
+++ b/arch/arm/mach-davinci/include/mach/time.h
@@ -11,9 +11,7 @@
 #ifndef __ARCH_ARM_MACH_DAVINCI_TIME_H
 #define __ARCH_ARM_MACH_DAVINCI_TIME_H
 
-#define DAVINCI_TIMER0_BASE		(IO_PHYS + 0x21400)
 #define DAVINCI_TIMER1_BASE		(IO_PHYS + 0x21800)
-#define DAVINCI_WDOG_BASE		(IO_PHYS + 0x21C00)
 
 enum {
 	T0_BOT,
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 13/17] ARM: davinci: dm355: switch to using the clocksource driver
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (11 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 12/17] ARM: davinci: move timer definitions to davinci.h Bartosz Golaszewski
@ 2019-01-11 17:21 ` Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 14/17] ARM: davinci: dm365: " Bartosz Golaszewski
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

We now have a proper clocksource driver for davinci. Switch the platform
to using it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/dm355.c | 36 ++++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/arch/arm/mach-davinci/dm355.c b/arch/arm/mach-davinci/dm355.c
index 07ad9d6c9cae..2fd1186ceef6 100644
--- a/arch/arm/mach-davinci/dm355.c
+++ b/arch/arm/mach-davinci/dm355.c
@@ -29,7 +29,8 @@
 #include <mach/irqs.h>
 #include <mach/mux.h>
 #include <mach/serial.h>
-#include <mach/time.h>
+
+#include <clocksource/timer-davinci.h>
 
 #include "asp.h"
 #include "davinci.h"
@@ -617,16 +618,24 @@ static struct davinci_id dm355_ids[] = {
 	},
 };
 
-/*
- * T0_BOT: Timer 0, bottom:  clockevent source for hrtimers
- * T0_TOP: Timer 0, top   :  clocksource for generic timekeeping
- * T1_BOT: Timer 1, bottom:  (used by DSP in TI DSPLink code)
- * T1_TOP: Timer 1, top   :  <unused>
- */
-static struct davinci_timer_info dm355_timer_info = {
-	.timers		= davinci_timer_instance,
-	.clockevent_id	= T0_BOT,
-	.clocksource_id	= T0_TOP,
+static const struct davinci_timer_cfg dm355_timer_cfg = {
+	.reg = {
+		.start		= DAVINCI_TIMER0_BASE,
+		.end		= DAVINCI_TIMER0_BASE + SZ_4K,
+		.flags		= IORESOURCE_MEM,
+	},
+	.irq = {
+		{
+			.start	= IRQ_TINT0_TINT12,
+			.end	= IRQ_TINT0_TINT12,
+			.flags	= IORESOURCE_IRQ,
+		},
+		{
+			.start	= IRQ_TINT0_TINT34,
+			.end	= IRQ_TINT0_TINT34,
+			.flags	= IORESOURCE_IRQ,
+		}
+	}
 };
 
 static struct plat_serial8250_port dm355_serial0_platform_data[] = {
@@ -708,7 +717,6 @@ static const struct davinci_soc_info davinci_soc_info_dm355 = {
 	.intc_type		= DAVINCI_INTC_TYPE_AINTC,
 	.intc_irq_prios		= dm355_default_priorities,
 	.intc_irq_num		= DAVINCI_N_AINTC_IRQ,
-	.timer_info		= &dm355_timer_info,
 	.sram_dma		= 0x00010000,
 	.sram_len		= SZ_32K,
 };
@@ -735,6 +743,7 @@ void __init dm355_init_time(void)
 {
 	void __iomem *pll1, *psc;
 	struct clk *clk;
+	int rv;
 
 	clk_register_fixed_rate(NULL, "ref_clk", NULL, 0, DM355_REF_FREQ);
 
@@ -747,7 +756,8 @@ void __init dm355_init_time(void)
 	clk = clk_get(NULL, "timer0");
 	WARN(IS_ERR(clk), "Unable to get the timer clock\n");
 
-	davinci_timer_init(clk);
+	rv = davinci_timer_register(clk, &dm355_timer_cfg);
+	WARN(rv, "Unable to register the timer: %d\n", rv);
 }
 
 static struct resource dm355_pll2_resources[] = {
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 14/17] ARM: davinci: dm365: switch to using the clocksource driver
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (12 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 13/17] ARM: davinci: dm355: switch to using the clocksource driver Bartosz Golaszewski
@ 2019-01-11 17:21 ` " Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 15/17] ARM: davinci: dm644x: " Bartosz Golaszewski
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

We now have a proper clocksource driver for davinci. Switch the platform
to using it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/dm365.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-davinci/dm365.c b/arch/arm/mach-davinci/dm365.c
index 842b7e706ba1..ff7754ce2bbe 100644
--- a/arch/arm/mach-davinci/dm365.c
+++ b/arch/arm/mach-davinci/dm365.c
@@ -34,7 +34,8 @@
 #include <mach/irqs.h>
 #include <mach/mux.h>
 #include <mach/serial.h>
-#include <mach/time.h>
+
+#include <clocksource/timer-davinci.h>
 
 #include "asp.h"
 #include "davinci.h"
@@ -658,10 +659,24 @@ static struct davinci_id dm365_ids[] = {
 	},
 };
 
-static struct davinci_timer_info dm365_timer_info = {
-	.timers		= davinci_timer_instance,
-	.clockevent_id	= T0_BOT,
-	.clocksource_id	= T0_TOP,
+static const struct davinci_timer_cfg dm365_timer_cfg = {
+	.reg = {
+		.start		= DAVINCI_TIMER0_BASE,
+		.end		= DAVINCI_TIMER0_BASE + SZ_4K,
+		.flags		= IORESOURCE_MEM,
+	},
+	.irq = {
+		{
+			.start	= IRQ_TINT0_TINT12,
+			.end	= IRQ_TINT0_TINT12,
+			.flags	= IORESOURCE_IRQ,
+		},
+		{
+			.start	= IRQ_TINT0_TINT34,
+			.end	= IRQ_TINT0_TINT34,
+			.flags	= IORESOURCE_IRQ,
+		}
+	}
 };
 
 #define DM365_UART1_BASE	(IO_PHYS + 0x106000)
@@ -725,7 +740,6 @@ static const struct davinci_soc_info davinci_soc_info_dm365 = {
 	.intc_type		= DAVINCI_INTC_TYPE_AINTC,
 	.intc_irq_prios		= dm365_default_priorities,
 	.intc_irq_num		= DAVINCI_N_AINTC_IRQ,
-	.timer_info		= &dm365_timer_info,
 	.emac_pdata		= &dm365_emac_pdata,
 	.sram_dma		= 0x00010000,
 	.sram_len		= SZ_32K,
@@ -773,6 +787,7 @@ void __init dm365_init_time(void)
 {
 	void __iomem *pll1, *pll2, *psc;
 	struct clk *clk;
+	int rv;
 
 	clk_register_fixed_rate(NULL, "ref_clk", NULL, 0, DM365_REF_FREQ);
 
@@ -788,7 +803,8 @@ void __init dm365_init_time(void)
 	clk = clk_get(NULL, "timer0");
 	WARN(IS_ERR(clk), "Unable to get the timer clock\n");
 
-	davinci_timer_init(clk);
+	rv = davinci_timer_register(clk, &dm365_timer_cfg);
+	WARN(rv, "Unable to register the timer: %d\n", rv);
 }
 
 void __init dm365_register_clocks(void)
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 15/17] ARM: davinci: dm644x: switch to using the clocksource driver
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (13 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 14/17] ARM: davinci: dm365: " Bartosz Golaszewski
@ 2019-01-11 17:21 ` " Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 16/17] ARM: davinci: dm646x: " Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 17/17] ARM: davinci: remove legacy timer support Bartosz Golaszewski
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

We now have a proper clocksource driver for davinci. Switch the platform
to using it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/dm644x.c | 36 ++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/arch/arm/mach-davinci/dm644x.c b/arch/arm/mach-davinci/dm644x.c
index 85d69ac1bd70..adbcdefadee8 100644
--- a/arch/arm/mach-davinci/dm644x.c
+++ b/arch/arm/mach-davinci/dm644x.c
@@ -26,7 +26,8 @@
 #include <mach/irqs.h>
 #include <mach/mux.h>
 #include <mach/serial.h>
-#include <mach/time.h>
+
+#include <clocksource/timer-davinci.h>
 
 #include "asp.h"
 #include "davinci.h"
@@ -558,16 +559,24 @@ static struct davinci_id dm644x_ids[] = {
 	},
 };
 
-/*
- * T0_BOT: Timer 0, bottom:  clockevent source for hrtimers
- * T0_TOP: Timer 0, top   :  clocksource for generic timekeeping
- * T1_BOT: Timer 1, bottom:  (used by DSP in TI DSPLink code)
- * T1_TOP: Timer 1, top   :  <unused>
- */
-static struct davinci_timer_info dm644x_timer_info = {
-	.timers		= davinci_timer_instance,
-	.clockevent_id	= T0_BOT,
-	.clocksource_id	= T0_TOP,
+static const struct davinci_timer_cfg dm644x_timer_cfg = {
+	.reg = {
+		.start		= DAVINCI_TIMER0_BASE,
+		.end		= DAVINCI_TIMER0_BASE + SZ_4K,
+		.flags		= IORESOURCE_MEM,
+	},
+	.irq = {
+		{
+			.start	= IRQ_TINT0_TINT12,
+			.end	= IRQ_TINT0_TINT12,
+			.flags	= IORESOURCE_IRQ,
+		},
+		{
+			.start	= IRQ_TINT0_TINT34,
+			.end	= IRQ_TINT0_TINT34,
+			.flags	= IORESOURCE_IRQ,
+		}
+	}
 };
 
 static struct plat_serial8250_port dm644x_serial0_platform_data[] = {
@@ -649,7 +658,6 @@ static const struct davinci_soc_info davinci_soc_info_dm644x = {
 	.intc_type		= DAVINCI_INTC_TYPE_AINTC,
 	.intc_irq_prios 	= dm644x_default_priorities,
 	.intc_irq_num		= DAVINCI_N_AINTC_IRQ,
-	.timer_info		= &dm644x_timer_info,
 	.emac_pdata		= &dm644x_emac_pdata,
 	.sram_dma		= 0x00008000,
 	.sram_len		= SZ_16K,
@@ -671,6 +679,7 @@ void __init dm644x_init_time(void)
 {
 	void __iomem *pll1, *psc;
 	struct clk *clk;
+	int rv;
 
 	clk_register_fixed_rate(NULL, "ref_clk", NULL, 0, DM644X_REF_FREQ);
 
@@ -683,7 +692,8 @@ void __init dm644x_init_time(void)
 	clk = clk_get(NULL, "timer0");
 	WARN(IS_ERR(clk), "Unable to get the timer clock\n");
 
-	davinci_timer_init(clk);
+	rv = davinci_timer_register(clk, &dm644x_timer_cfg);
+	WARN(rv, "Unable to register the timer: %d\n", rv);
 }
 
 static struct resource dm644x_pll2_resources[] = {
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 16/17] ARM: davinci: dm646x: switch to using the clocksource driver
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (14 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 15/17] ARM: davinci: dm644x: " Bartosz Golaszewski
@ 2019-01-11 17:21 ` " Bartosz Golaszewski
  2019-01-11 17:21 ` [PATCH 17/17] ARM: davinci: remove legacy timer support Bartosz Golaszewski
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

We now have a proper clocksource driver for davinci. Switch the platform
to using it.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/dm646x.c | 36 ++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/arch/arm/mach-davinci/dm646x.c b/arch/arm/mach-davinci/dm646x.c
index 018315fa9aa9..b3412920da0a 100644
--- a/arch/arm/mach-davinci/dm646x.c
+++ b/arch/arm/mach-davinci/dm646x.c
@@ -27,7 +27,8 @@
 #include <mach/irqs.h>
 #include <mach/mux.h>
 #include <mach/serial.h>
-#include <mach/time.h>
+
+#include <clocksource/timer-davinci.h>
 
 #include "asp.h"
 #include "davinci.h"
@@ -498,16 +499,24 @@ static struct davinci_id dm646x_ids[] = {
 	},
 };
 
-/*
- * T0_BOT: Timer 0, bottom:  clockevent source for hrtimers
- * T0_TOP: Timer 0, top   :  clocksource for generic timekeeping
- * T1_BOT: Timer 1, bottom:  (used by DSP in TI DSPLink code)
- * T1_TOP: Timer 1, top   :  <unused>
- */
-static struct davinci_timer_info dm646x_timer_info = {
-	.timers		= davinci_timer_instance,
-	.clockevent_id	= T0_BOT,
-	.clocksource_id	= T0_TOP,
+static const struct davinci_timer_cfg dm646x_timer_cfg = {
+	.reg = {
+		.start		= DAVINCI_TIMER0_BASE,
+		.end		= DAVINCI_TIMER0_BASE + SZ_4K,
+		.flags		= IORESOURCE_MEM,
+	},
+	.irq = {
+		{
+			.start	= IRQ_TINT0_TINT12,
+			.end	= IRQ_TINT0_TINT12,
+			.flags	= IORESOURCE_IRQ,
+		},
+		{
+			.start	= IRQ_TINT0_TINT34,
+			.end	= IRQ_TINT0_TINT34,
+			.flags	= IORESOURCE_IRQ,
+		}
+	}
 };
 
 static struct plat_serial8250_port dm646x_serial0_platform_data[] = {
@@ -589,7 +598,6 @@ static const struct davinci_soc_info davinci_soc_info_dm646x = {
 	.intc_type		= DAVINCI_INTC_TYPE_AINTC,
 	.intc_irq_prios		= dm646x_default_priorities,
 	.intc_irq_num		= DAVINCI_N_AINTC_IRQ,
-	.timer_info		= &dm646x_timer_info,
 	.emac_pdata		= &dm646x_emac_pdata,
 	.sram_dma		= 0x10010000,
 	.sram_len		= SZ_32K,
@@ -654,6 +662,7 @@ void __init dm646x_init_time(unsigned long ref_clk_rate,
 {
 	void __iomem *pll1, *psc;
 	struct clk *clk;
+	int rv;
 
 	clk_register_fixed_rate(NULL, "ref_clk", NULL, 0, ref_clk_rate);
 	clk_register_fixed_rate(NULL, "aux_clkin", NULL, 0, aux_clkin_rate);
@@ -667,7 +676,8 @@ void __init dm646x_init_time(unsigned long ref_clk_rate,
 	clk = clk_get(NULL, "timer0");
 	WARN(IS_ERR(clk), "Unable to get the timer clock\n");
 
-	davinci_timer_init(clk);
+	rv = davinci_timer_register(clk, &dm646x_timer_cfg);
+	WARN(rv, "Unable to register the timer: %d\n", rv);
 }
 
 static struct resource dm646x_pll2_resources[] = {
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 17/17] ARM: davinci: remove legacy timer support
  2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
                   ` (15 preceding siblings ...)
  2019-01-11 17:21 ` [PATCH 16/17] ARM: davinci: dm646x: " Bartosz Golaszewski
@ 2019-01-11 17:21 ` Bartosz Golaszewski
  16 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 17:21 UTC (permalink / raw)
  To: Sekhar Nori, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

All platforms have now been switched to the new clocksource driver.
Remove the old code and various no longer needed bits and pieces.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 arch/arm/mach-davinci/Makefile              |   3 +-
 arch/arm/mach-davinci/devices-da8xx.c       |   1 -
 arch/arm/mach-davinci/devices.c             |  19 -
 arch/arm/mach-davinci/include/mach/common.h |  17 -
 arch/arm/mach-davinci/include/mach/time.h   |  33 --
 arch/arm/mach-davinci/time.c                | 400 --------------------
 6 files changed, 1 insertion(+), 472 deletions(-)
 delete mode 100644 arch/arm/mach-davinci/include/mach/time.h
 delete mode 100644 arch/arm/mach-davinci/time.c

diff --git a/arch/arm/mach-davinci/Makefile b/arch/arm/mach-davinci/Makefile
index 93d271b4d84b..fa8e66a223b6 100644
--- a/arch/arm/mach-davinci/Makefile
+++ b/arch/arm/mach-davinci/Makefile
@@ -5,8 +5,7 @@
 #
 
 # Common objects
-obj-y 					:= time.o serial.o usb.o \
-					   common.o sram.o
+obj-y 					:= serial.o usb.o common.o sram.o
 
 obj-$(CONFIG_DAVINCI_MUX)		+= mux.o
 
diff --git a/arch/arm/mach-davinci/devices-da8xx.c b/arch/arm/mach-davinci/devices-da8xx.c
index cf78da5ab054..0e6047f0189a 100644
--- a/arch/arm/mach-davinci/devices-da8xx.c
+++ b/arch/arm/mach-davinci/devices-da8xx.c
@@ -24,7 +24,6 @@
 #include <mach/common.h>
 #include <mach/cputype.h>
 #include <mach/da8xx.h>
-#include <mach/time.h>
 
 #include "asp.h"
 #include "cpuidle.h"
diff --git a/arch/arm/mach-davinci/devices.c b/arch/arm/mach-davinci/devices.c
index e8dbbb7479ab..584b4fa14a82 100644
--- a/arch/arm/mach-davinci/devices.c
+++ b/arch/arm/mach-davinci/devices.c
@@ -21,7 +21,6 @@
 #include <mach/cputype.h>
 #include <mach/mux.h>
 #include <linux/platform_data/mmc-davinci.h>
-#include <mach/time.h>
 #include <linux/platform_data/edma.h>
 
 
@@ -305,21 +304,3 @@ int davinci_gpio_register(struct resource *res, int size, void *pdata)
 	davinci_gpio_device.dev.platform_data = pdata;
 	return platform_device_register(&davinci_gpio_device);
 }
-
-/*-------------------------------------------------------------------------*/
-
-/*-------------------------------------------------------------------------*/
-
-struct davinci_timer_instance davinci_timer_instance[2] = {
-	{
-		.base		= DAVINCI_TIMER0_BASE,
-		.bottom_irq	= IRQ_TINT0_TINT12,
-		.top_irq	= IRQ_TINT0_TINT34,
-	},
-	{
-		.base		= DAVINCI_TIMER1_BASE,
-		.bottom_irq	= IRQ_TINT1_TINT12,
-		.top_irq	= IRQ_TINT1_TINT34,
-	},
-};
-
diff --git a/arch/arm/mach-davinci/include/mach/common.h b/arch/arm/mach-davinci/include/mach/common.h
index b577e13a9c23..ec721c1842ae 100644
--- a/arch/arm/mach-davinci/include/mach/common.h
+++ b/arch/arm/mach-davinci/include/mach/common.h
@@ -17,26 +17,10 @@
 #include <linux/types.h>
 #include <linux/reboot.h>
 
-void davinci_timer_init(struct clk *clk);
-
 extern void davinci_irq_init(void);
 extern void __iomem *davinci_intc_base;
 extern int davinci_intc_type;
 
-struct davinci_timer_instance {
-	u32		base;
-	u32		bottom_irq;
-	u32		top_irq;
-	unsigned long	cmp_off;
-	unsigned int	cmp_irq;
-};
-
-struct davinci_timer_info {
-	struct davinci_timer_instance	*timers;
-	unsigned int			clockevent_id;
-	unsigned int			clocksource_id;
-};
-
 struct davinci_gpio_controller;
 
 /*
@@ -62,7 +46,6 @@ struct davinci_soc_info {
 	u8				*intc_irq_prios;
 	unsigned long			intc_irq_num;
 	u32				*intc_host_map;
-	struct davinci_timer_info	*timer_info;
 	int				gpio_type;
 	u32				gpio_base;
 	unsigned			gpio_num;
diff --git a/arch/arm/mach-davinci/include/mach/time.h b/arch/arm/mach-davinci/include/mach/time.h
deleted file mode 100644
index ba913736990f..000000000000
--- a/arch/arm/mach-davinci/include/mach/time.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Local header file for DaVinci time code.
- *
- * Author: Kevin Hilman, MontaVista Software, Inc. <source@mvista.com>
- *
- * 2007 (c) MontaVista Software, Inc. This file is licensed under
- * the terms of the GNU General Public License version 2. This program
- * is licensed "as is" without any warranty of any kind, whether express
- * or implied.
- */
-#ifndef __ARCH_ARM_MACH_DAVINCI_TIME_H
-#define __ARCH_ARM_MACH_DAVINCI_TIME_H
-
-#define DAVINCI_TIMER1_BASE		(IO_PHYS + 0x21800)
-
-enum {
-	T0_BOT,
-	T0_TOP,
-	T1_BOT,
-	T1_TOP,
-	NUM_TIMERS
-};
-
-#define IS_TIMER1(id)		(id & 0x2)
-#define IS_TIMER0(id)		(!IS_TIMER1(id))
-#define IS_TIMER_TOP(id)	((id & 0x1))
-#define IS_TIMER_BOT(id)	(!IS_TIMER_TOP(id))
-
-#define ID_TO_TIMER(id)		(IS_TIMER1(id) != 0)
-
-extern struct davinci_timer_instance davinci_timer_instance[];
-
-#endif /* __ARCH_ARM_MACH_DAVINCI_TIME_H */
diff --git a/arch/arm/mach-davinci/time.c b/arch/arm/mach-davinci/time.c
deleted file mode 100644
index 740410a3bb6a..000000000000
--- a/arch/arm/mach-davinci/time.c
+++ /dev/null
@@ -1,400 +0,0 @@
-/*
- * DaVinci timer subsystem
- *
- * Author: Kevin Hilman, MontaVista Software, Inc. <source@mvista.com>
- *
- * 2007 (c) MontaVista Software, Inc. This file is licensed under
- * the terms of the GNU General Public License version 2. This program
- * is licensed "as is" without any warranty of any kind, whether express
- * or implied.
- */
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/types.h>
-#include <linux/interrupt.h>
-#include <linux/clocksource.h>
-#include <linux/clockchips.h>
-#include <linux/io.h>
-#include <linux/clk.h>
-#include <linux/err.h>
-#include <linux/of.h>
-#include <linux/platform_device.h>
-#include <linux/sched_clock.h>
-
-#include <asm/mach/irq.h>
-#include <asm/mach/time.h>
-
-#include <mach/cputype.h>
-#include <mach/hardware.h>
-#include <mach/time.h>
-
-static struct clock_event_device clockevent_davinci;
-static unsigned int davinci_clock_tick_rate;
-
-/*
- * This driver configures the 2 64-bit count-up timers as 4 independent
- * 32-bit count-up timers used as follows:
- */
-
-enum {
-	TID_CLOCKEVENT,
-	TID_CLOCKSOURCE,
-};
-
-/* Timer register offsets */
-#define PID12			0x0
-#define TIM12			0x10
-#define TIM34			0x14
-#define PRD12			0x18
-#define PRD34			0x1c
-#define TCR			0x20
-#define TGCR			0x24
-#define WDTCR			0x28
-
-/* Offsets of the 8 compare registers */
-#define	CMP12_0			0x60
-#define	CMP12_1			0x64
-#define	CMP12_2			0x68
-#define	CMP12_3			0x6c
-#define	CMP12_4			0x70
-#define	CMP12_5			0x74
-#define	CMP12_6			0x78
-#define	CMP12_7			0x7c
-
-/* Timer register bitfields */
-#define TCR_ENAMODE_DISABLE          0x0
-#define TCR_ENAMODE_ONESHOT          0x1
-#define TCR_ENAMODE_PERIODIC         0x2
-#define TCR_ENAMODE_MASK             0x3
-
-#define TGCR_TIMMODE_SHIFT           2
-#define TGCR_TIMMODE_64BIT_GP        0x0
-#define TGCR_TIMMODE_32BIT_UNCHAINED 0x1
-#define TGCR_TIMMODE_64BIT_WDOG      0x2
-#define TGCR_TIMMODE_32BIT_CHAINED   0x3
-
-#define TGCR_TIM12RS_SHIFT           0
-#define TGCR_TIM34RS_SHIFT           1
-#define TGCR_RESET                   0x0
-#define TGCR_UNRESET                 0x1
-#define TGCR_RESET_MASK              0x3
-
-struct timer_s {
-	char *name;
-	unsigned int id;
-	unsigned long period;
-	unsigned long opts;
-	unsigned long flags;
-	void __iomem *base;
-	unsigned long tim_off;
-	unsigned long prd_off;
-	unsigned long enamode_shift;
-	struct irqaction irqaction;
-};
-static struct timer_s timers[];
-
-/* values for 'opts' field of struct timer_s */
-#define TIMER_OPTS_DISABLED		0x01
-#define TIMER_OPTS_ONESHOT		0x02
-#define TIMER_OPTS_PERIODIC		0x04
-#define TIMER_OPTS_STATE_MASK		0x07
-
-#define TIMER_OPTS_USE_COMPARE		0x80000000
-#define USING_COMPARE(t)		((t)->opts & TIMER_OPTS_USE_COMPARE)
-
-static char *id_to_name[] = {
-	[T0_BOT]	= "timer0_0",
-	[T0_TOP]	= "timer0_1",
-	[T1_BOT]	= "timer1_0",
-	[T1_TOP]	= "timer1_1",
-};
-
-static int timer32_config(struct timer_s *t)
-{
-	u32 tcr;
-	struct davinci_soc_info *soc_info = &davinci_soc_info;
-
-	if (USING_COMPARE(t)) {
-		struct davinci_timer_instance *dtip =
-				soc_info->timer_info->timers;
-		int event_timer = ID_TO_TIMER(timers[TID_CLOCKEVENT].id);
-
-		/*
-		 * Next interrupt should be the current time reg value plus
-		 * the new period (using 32-bit unsigned addition/wrapping
-		 * to 0 on overflow).  This assumes that the clocksource
-		 * is setup to count to 2^32-1 before wrapping around to 0.
-		 */
-		__raw_writel(__raw_readl(t->base + t->tim_off) + t->period,
-			t->base + dtip[event_timer].cmp_off);
-	} else {
-		tcr = __raw_readl(t->base + TCR);
-
-		/* disable timer */
-		tcr &= ~(TCR_ENAMODE_MASK << t->enamode_shift);
-		__raw_writel(tcr, t->base + TCR);
-
-		/* reset counter to zero, set new period */
-		__raw_writel(0, t->base + t->tim_off);
-		__raw_writel(t->period, t->base + t->prd_off);
-
-		/* Set enable mode */
-		if (t->opts & TIMER_OPTS_ONESHOT)
-			tcr |= TCR_ENAMODE_ONESHOT << t->enamode_shift;
-		else if (t->opts & TIMER_OPTS_PERIODIC)
-			tcr |= TCR_ENAMODE_PERIODIC << t->enamode_shift;
-
-		__raw_writel(tcr, t->base + TCR);
-	}
-	return 0;
-}
-
-static inline u32 timer32_read(struct timer_s *t)
-{
-	return __raw_readl(t->base + t->tim_off);
-}
-
-static irqreturn_t timer_interrupt(int irq, void *dev_id)
-{
-	struct clock_event_device *evt = &clockevent_davinci;
-
-	evt->event_handler(evt);
-	return IRQ_HANDLED;
-}
-
-/* called when 32-bit counter wraps */
-static irqreturn_t freerun_interrupt(int irq, void *dev_id)
-{
-	return IRQ_HANDLED;
-}
-
-static struct timer_s timers[] = {
-	[TID_CLOCKEVENT] = {
-		.name      = "clockevent",
-		.opts      = TIMER_OPTS_DISABLED,
-		.irqaction = {
-			.flags   = IRQF_TIMER,
-			.handler = timer_interrupt,
-		}
-	},
-	[TID_CLOCKSOURCE] = {
-		.name       = "free-run counter",
-		.period     = ~0,
-		.opts       = TIMER_OPTS_PERIODIC,
-		.irqaction = {
-			.flags   = IRQF_TIMER,
-			.handler = freerun_interrupt,
-		}
-	},
-};
-
-static void __init timer_init(void)
-{
-	struct davinci_soc_info *soc_info = &davinci_soc_info;
-	struct davinci_timer_instance *dtip = soc_info->timer_info->timers;
-	void __iomem *base[2];
-	int i;
-
-	/* Global init of each 64-bit timer as a whole */
-	for(i=0; i<2; i++) {
-		u32 tgcr;
-
-		base[i] = ioremap(dtip[i].base, SZ_4K);
-		if (WARN_ON(!base[i]))
-			continue;
-
-		/* Disabled, Internal clock source */
-		__raw_writel(0, base[i] + TCR);
-
-		/* reset both timers, no pre-scaler for timer34 */
-		tgcr = 0;
-		__raw_writel(tgcr, base[i] + TGCR);
-
-		/* Set both timers to unchained 32-bit */
-		tgcr = TGCR_TIMMODE_32BIT_UNCHAINED << TGCR_TIMMODE_SHIFT;
-		__raw_writel(tgcr, base[i] + TGCR);
-
-		/* Unreset timers */
-		tgcr |= (TGCR_UNRESET << TGCR_TIM12RS_SHIFT) |
-			(TGCR_UNRESET << TGCR_TIM34RS_SHIFT);
-		__raw_writel(tgcr, base[i] + TGCR);
-
-		/* Init both counters to zero */
-		__raw_writel(0, base[i] + TIM12);
-		__raw_writel(0, base[i] + TIM34);
-	}
-
-	/* Init of each timer as a 32-bit timer */
-	for (i=0; i< ARRAY_SIZE(timers); i++) {
-		struct timer_s *t = &timers[i];
-		int timer = ID_TO_TIMER(t->id);
-		u32 irq;
-
-		t->base = base[timer];
-		if (!t->base)
-			continue;
-
-		if (IS_TIMER_BOT(t->id)) {
-			t->enamode_shift = 6;
-			t->tim_off = TIM12;
-			t->prd_off = PRD12;
-			irq = dtip[timer].bottom_irq;
-		} else {
-			t->enamode_shift = 22;
-			t->tim_off = TIM34;
-			t->prd_off = PRD34;
-			irq = dtip[timer].top_irq;
-		}
-
-		/* Register interrupt */
-		t->irqaction.name = t->name;
-		t->irqaction.dev_id = (void *)t;
-
-		if (t->irqaction.handler != NULL) {
-			irq = USING_COMPARE(t) ? dtip[i].cmp_irq : irq;
-			setup_irq(irq, &t->irqaction);
-		}
-	}
-}
-
-/*
- * clocksource
- */
-static u64 read_cycles(struct clocksource *cs)
-{
-	struct timer_s *t = &timers[TID_CLOCKSOURCE];
-
-	return (cycles_t)timer32_read(t);
-}
-
-static struct clocksource clocksource_davinci = {
-	.rating		= 300,
-	.read		= read_cycles,
-	.mask		= CLOCKSOURCE_MASK(32),
-	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
-};
-
-/*
- * Overwrite weak default sched_clock with something more precise
- */
-static u64 notrace davinci_read_sched_clock(void)
-{
-	return timer32_read(&timers[TID_CLOCKSOURCE]);
-}
-
-/*
- * clockevent
- */
-static int davinci_set_next_event(unsigned long cycles,
-				  struct clock_event_device *evt)
-{
-	struct timer_s *t = &timers[TID_CLOCKEVENT];
-
-	t->period = cycles;
-	timer32_config(t);
-	return 0;
-}
-
-static int davinci_shutdown(struct clock_event_device *evt)
-{
-	struct timer_s *t = &timers[TID_CLOCKEVENT];
-
-	t->opts &= ~TIMER_OPTS_STATE_MASK;
-	t->opts |= TIMER_OPTS_DISABLED;
-	return 0;
-}
-
-static int davinci_set_oneshot(struct clock_event_device *evt)
-{
-	struct timer_s *t = &timers[TID_CLOCKEVENT];
-
-	t->opts &= ~TIMER_OPTS_STATE_MASK;
-	t->opts |= TIMER_OPTS_ONESHOT;
-	return 0;
-}
-
-static int davinci_set_periodic(struct clock_event_device *evt)
-{
-	struct timer_s *t = &timers[TID_CLOCKEVENT];
-
-	t->period = davinci_clock_tick_rate / (HZ);
-	t->opts &= ~TIMER_OPTS_STATE_MASK;
-	t->opts |= TIMER_OPTS_PERIODIC;
-	timer32_config(t);
-	return 0;
-}
-
-static struct clock_event_device clockevent_davinci = {
-	.features		= CLOCK_EVT_FEAT_PERIODIC |
-				  CLOCK_EVT_FEAT_ONESHOT,
-	.set_next_event		= davinci_set_next_event,
-	.set_state_shutdown	= davinci_shutdown,
-	.set_state_periodic	= davinci_set_periodic,
-	.set_state_oneshot	= davinci_set_oneshot,
-};
-
-void __init davinci_timer_init(struct clk *timer_clk)
-{
-	struct davinci_soc_info *soc_info = &davinci_soc_info;
-	unsigned int clockevent_id;
-	unsigned int clocksource_id;
-	int i;
-
-	clockevent_id = soc_info->timer_info->clockevent_id;
-	clocksource_id = soc_info->timer_info->clocksource_id;
-
-	timers[TID_CLOCKEVENT].id = clockevent_id;
-	timers[TID_CLOCKSOURCE].id = clocksource_id;
-
-	/*
-	 * If using same timer for both clock events & clocksource,
-	 * a compare register must be used to generate an event interrupt.
-	 * This is equivalent to a oneshot timer only (not periodic).
-	 */
-	if (clockevent_id == clocksource_id) {
-		struct davinci_timer_instance *dtip =
-				soc_info->timer_info->timers;
-		int event_timer = ID_TO_TIMER(clockevent_id);
-
-		/* Only bottom timers can use compare regs */
-		if (IS_TIMER_TOP(clockevent_id))
-			pr_warn("%s: Invalid use of system timers.  Results unpredictable.\n",
-				__func__);
-		else if ((dtip[event_timer].cmp_off == 0)
-				|| (dtip[event_timer].cmp_irq == 0))
-			pr_warn("%s: Invalid timer instance setup.  Results unpredictable.\n",
-				__func__);
-		else {
-			timers[TID_CLOCKEVENT].opts |= TIMER_OPTS_USE_COMPARE;
-			clockevent_davinci.features = CLOCK_EVT_FEAT_ONESHOT;
-		}
-	}
-
-	BUG_ON(IS_ERR(timer_clk));
-	clk_prepare_enable(timer_clk);
-
-	/* init timer hw */
-	timer_init();
-
-	davinci_clock_tick_rate = clk_get_rate(timer_clk);
-
-	/* setup clocksource */
-	clocksource_davinci.name = id_to_name[clocksource_id];
-	if (clocksource_register_hz(&clocksource_davinci,
-				    davinci_clock_tick_rate))
-		pr_err("%s: can't register clocksource!\n",
-		       clocksource_davinci.name);
-
-	sched_clock_register(davinci_read_sched_clock, 32,
-			  davinci_clock_tick_rate);
-
-	/* setup clockevent */
-	clockevent_davinci.name = id_to_name[timers[TID_CLOCKEVENT].id];
-
-	clockevent_davinci.cpumask = cpumask_of(0);
-	clockevents_config_and_register(&clockevent_davinci,
-					davinci_clock_tick_rate, 1, 0xfffffffe);
-
-	for (i=0; i< ARRAY_SIZE(timers); i++)
-		timer32_config(&timers[i]);
-}
-- 
2.19.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 02/17] clocksource: davinci-timer: new driver
  2019-01-11 17:21 ` [PATCH 02/17] clocksource: davinci-timer: new driver Bartosz Golaszewski
@ 2019-01-14 12:20   ` Sekhar Nori
  2019-01-14 16:39     ` Bartosz Golaszewski
  0 siblings, 1 reply; 28+ messages in thread
From: Sekhar Nori @ 2019-01-14 12:20 UTC (permalink / raw)
  To: Bartosz Golaszewski, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

Hi Bartosz,

On 11/01/19 10:51 PM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> 
> Currently the clocksource and clockevent support for davinci platforms
> lives in mach-davinci. It hard-codes many things, used global variables,
> implements functionalities unused by any platform and has code fragments
> scattered across many (often unrelated) files.
> 
> Implement a new, modern and simplified timer driver and put it into
> drivers/clocksource. We still need to support legacy board files so
> export a config structure and a function that allows machine code to
> register the timer.
> 
> We don't check the return values of regmap reads and writes since with
> mmio it's only likely to fail due to programmer's errors.
> 
> We also don't bother freeing resources on errors in
> davinci_timer_register() as the system won't boot without a timer anyway.
> 
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

With this series, DA830 fails to boot. Rest of the devices are okay from
boot perspective.

DA830 is pretty unique because it uses the same timer-half for both
clocksource and clockevent. May be you can set the same configuration on
your DA850 to see the same issue? Else, I will enable low-level debug
and try to provide more debug data.

Some minor comments below from quick look:

> diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c
> new file mode 100644
> index 000000000000..7282a1fda80f
> --- /dev/null
> +++ b/drivers/clocksource/timer-davinci.c
> @@ -0,0 +1,415 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * TI DaVinci clocksource driver
> + *
> + * Copyright (C) 2019 Texas Instruments
> + * Author: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> + * (with some parts adopted from code by Kevin Hilman <khilman@baylibre.com>)

Did you really intend GPL v2 or later? The original code referred to
above is marked 2.0 only.

> + */
> +
> +#include <linux/clk.h>
> +#include <linux/clockchips.h>
> +#include <linux/clocksource.h>
> +#include <linux/err.h>
> +#include <linux/interrupt.h>
> +#include <linux/kernel.h>
> +#include <linux/of_address.h>
> +#include <linux/of_irq.h>
> +#include <linux/regmap.h>
> +#include <linux/sched_clock.h>
> +
> +#include <clocksource/timer-davinci.h>
> +
> +#define DAVINCI_TIMER_REG_TIM12			0x10
> +#define DAVINCI_TIMER_REG_TIM34			0x14
> +#define DAVINCI_TIMER_REG_PRD12			0x18
> +#define DAVINCI_TIMER_REG_PRD34			0x1c
> +#define DAVINCI_TIMER_REG_TCR			0x20
> +#define DAVINCI_TIMER_REG_TGCR			0x24
> +
> +#define DAVINCI_TIMER_TIMMODE_MASK		0x0000000c
> +#define DAVINCI_TIMER_RESET_MASK		0x00000003
> +#define DAVINCI_TIMER_TIMMODE_32BIT_UNCHAINED	0x00000004
> +#define DAVINCI_TIMER_UNRESET			0x00000003

I think these are more readable if using BIT() and GENMASK()

Thanks,
Sekhar

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 04/17] ARM: davinci: da850: WARN() if clk_get() fails
  2019-01-11 17:21 ` [PATCH 04/17] ARM: davinci: da850: WARN() if clk_get() fails Bartosz Golaszewski
@ 2019-01-14 12:22   ` Sekhar Nori
  0 siblings, 0 replies; 28+ messages in thread
From: Sekhar Nori @ 2019-01-14 12:22 UTC (permalink / raw)
  To: Bartosz Golaszewski, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

On 11/01/19 10:51 PM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> 
> Currently the timer code checks if the clock pointer passed to it is
> good (!IS_ERR(clk)). The new clocksource driver expects the clock to
> be functional and doesn't perform any checks so emit a warning if
> clk_get() fails.
> 
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

I think 4-9 can be a single patch. They are doing something very similar
and its unlikely we will have to patch/revert just one of them.

Thanks,
Sekhar

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 02/17] clocksource: davinci-timer: new driver
  2019-01-14 12:20   ` Sekhar Nori
@ 2019-01-14 16:39     ` Bartosz Golaszewski
  2019-01-16  9:18       ` Sekhar Nori
  2019-01-23  0:30       ` Kevin Hilman
  0 siblings, 2 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-14 16:39 UTC (permalink / raw)
  To: Sekhar Nori
  Cc: Mark Rutland, devicetree, Kevin Hilman, Daniel Lezcano,
	Linux Kernel Mailing List, Bartosz Golaszewski, Rob Herring,
	Thomas Gleixner, Linux ARM

pon., 14 sty 2019 o 13:20 Sekhar Nori <nsekhar@ti.com> napisał(a):
>
> Hi Bartosz,
>
> On 11/01/19 10:51 PM, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >
> > Currently the clocksource and clockevent support for davinci platforms
> > lives in mach-davinci. It hard-codes many things, used global variables,
> > implements functionalities unused by any platform and has code fragments
> > scattered across many (often unrelated) files.
> >
> > Implement a new, modern and simplified timer driver and put it into
> > drivers/clocksource. We still need to support legacy board files so
> > export a config structure and a function that allows machine code to
> > register the timer.
> >
> > We don't check the return values of regmap reads and writes since with
> > mmio it's only likely to fail due to programmer's errors.
> >
> > We also don't bother freeing resources on errors in
> > davinci_timer_register() as the system won't boot without a timer anyway.
> >
> > Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> With this series, DA830 fails to boot. Rest of the devices are okay from
> boot perspective.
>
> DA830 is pretty unique because it uses the same timer-half for both
> clocksource and clockevent. May be you can set the same configuration on
> your DA850 to see the same issue? Else, I will enable low-level debug
> and try to provide more debug data.
>

I can't boot da850 with the same config as da830 (0x60 compare
register, compare irq 74) even with the old timer code. Just to make
sure: does da830 boot fine with mainline v5.0-rc2?

> Some minor comments below from quick look:
>
> > diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c
> > new file mode 100644
> > index 000000000000..7282a1fda80f
> > --- /dev/null
> > +++ b/drivers/clocksource/timer-davinci.c
> > @@ -0,0 +1,415 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * TI DaVinci clocksource driver
> > + *
> > + * Copyright (C) 2019 Texas Instruments
> > + * Author: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> > + * (with some parts adopted from code by Kevin Hilman <khilman@baylibre.com>)
>
> Did you really intend GPL v2 or later? The original code referred to
> above is marked 2.0 only.
>

I'm not sure. Should it be GPLv2 only? I'm not well versed with licensing.

Bart

> > + */
> > +
> > +#include <linux/clk.h>
> > +#include <linux/clockchips.h>
> > +#include <linux/clocksource.h>
> > +#include <linux/err.h>
> > +#include <linux/interrupt.h>
> > +#include <linux/kernel.h>
> > +#include <linux/of_address.h>
> > +#include <linux/of_irq.h>
> > +#include <linux/regmap.h>
> > +#include <linux/sched_clock.h>
> > +
> > +#include <clocksource/timer-davinci.h>
> > +
> > +#define DAVINCI_TIMER_REG_TIM12                      0x10
> > +#define DAVINCI_TIMER_REG_TIM34                      0x14
> > +#define DAVINCI_TIMER_REG_PRD12                      0x18
> > +#define DAVINCI_TIMER_REG_PRD34                      0x1c
> > +#define DAVINCI_TIMER_REG_TCR                        0x20
> > +#define DAVINCI_TIMER_REG_TGCR                       0x24
> > +
> > +#define DAVINCI_TIMER_TIMMODE_MASK           0x0000000c
> > +#define DAVINCI_TIMER_RESET_MASK             0x00000003
> > +#define DAVINCI_TIMER_TIMMODE_32BIT_UNCHAINED        0x00000004
> > +#define DAVINCI_TIMER_UNRESET                        0x00000003
>
> I think these are more readable if using BIT() and GENMASK()
>
> Thanks,
> Sekhar

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 02/17] clocksource: davinci-timer: new driver
  2019-01-14 16:39     ` Bartosz Golaszewski
@ 2019-01-16  9:18       ` Sekhar Nori
  2019-01-17 12:42         ` Sekhar Nori
  2019-01-23  0:30       ` Kevin Hilman
  1 sibling, 1 reply; 28+ messages in thread
From: Sekhar Nori @ 2019-01-16  9:18 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Mark Rutland, devicetree, Kevin Hilman, Daniel Lezcano,
	Linux Kernel Mailing List, Bartosz Golaszewski, Rob Herring,
	Thomas Gleixner, Linux ARM

On 14/01/19 10:09 PM, Bartosz Golaszewski wrote:
> pon., 14 sty 2019 o 13:20 Sekhar Nori <nsekhar@ti.com> napisał(a):
>>
>> Hi Bartosz,
>>
>> On 11/01/19 10:51 PM, Bartosz Golaszewski wrote:
>>> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>>>
>>> Currently the clocksource and clockevent support for davinci platforms
>>> lives in mach-davinci. It hard-codes many things, used global variables,
>>> implements functionalities unused by any platform and has code fragments
>>> scattered across many (often unrelated) files.
>>>
>>> Implement a new, modern and simplified timer driver and put it into
>>> drivers/clocksource. We still need to support legacy board files so
>>> export a config structure and a function that allows machine code to
>>> register the timer.
>>>
>>> We don't check the return values of regmap reads and writes since with
>>> mmio it's only likely to fail due to programmer's errors.
>>>
>>> We also don't bother freeing resources on errors in
>>> davinci_timer_register() as the system won't boot without a timer anyway.
>>>
>>> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>>
>> With this series, DA830 fails to boot. Rest of the devices are okay from
>> boot perspective.
>>
>> DA830 is pretty unique because it uses the same timer-half for both
>> clocksource and clockevent. May be you can set the same configuration on
>> your DA850 to see the same issue? Else, I will enable low-level debug
>> and try to provide more debug data.
>>
> 
> I can't boot da850 with the same config as da830 (0x60 compare
> register, compare irq 74) even with the old timer code. Just to make
> sure: does da830 boot fine with mainline v5.0-rc2?

Yeah, I did check that without the patch DA830 does boot.

Thanks,
Sekhar

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 02/17] clocksource: davinci-timer: new driver
  2019-01-16  9:18       ` Sekhar Nori
@ 2019-01-17 12:42         ` Sekhar Nori
  2019-01-17 14:01           ` Bartosz Golaszewski
  0 siblings, 1 reply; 28+ messages in thread
From: Sekhar Nori @ 2019-01-17 12:42 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Mark Rutland, devicetree, Kevin Hilman, Daniel Lezcano,
	Linux Kernel Mailing List, Bartosz Golaszewski, Rob Herring,
	Thomas Gleixner, Linux ARM

On 16/01/19 2:48 PM, Sekhar Nori wrote:
> On 14/01/19 10:09 PM, Bartosz Golaszewski wrote:
>> pon., 14 sty 2019 o 13:20 Sekhar Nori <nsekhar@ti.com> napisał(a):
>>>
>>> Hi Bartosz,
>>>
>>> On 11/01/19 10:51 PM, Bartosz Golaszewski wrote:
>>>> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>>>>
>>>> Currently the clocksource and clockevent support for davinci platforms
>>>> lives in mach-davinci. It hard-codes many things, used global variables,
>>>> implements functionalities unused by any platform and has code fragments
>>>> scattered across many (often unrelated) files.
>>>>
>>>> Implement a new, modern and simplified timer driver and put it into
>>>> drivers/clocksource. We still need to support legacy board files so
>>>> export a config structure and a function that allows machine code to
>>>> register the timer.
>>>>
>>>> We don't check the return values of regmap reads and writes since with
>>>> mmio it's only likely to fail due to programmer's errors.
>>>>
>>>> We also don't bother freeing resources on errors in
>>>> davinci_timer_register() as the system won't boot without a timer anyway.
>>>>
>>>> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>>>
>>> With this series, DA830 fails to boot. Rest of the devices are okay from
>>> boot perspective.
>>>
>>> DA830 is pretty unique because it uses the same timer-half for both
>>> clocksource and clockevent. May be you can set the same configuration on
>>> your DA850 to see the same issue? Else, I will enable low-level debug
>>> and try to provide more debug data.
>>>
>>
>> I can't boot da850 with the same config as da830 (0x60 compare
>> register, compare irq 74) even with the old timer code. Just to make
>> sure: does da830 boot fine with mainline v5.0-rc2?
> 
> Yeah, I did check that without the patch DA830 does boot.

You are right that DA850 lacks compare interrupts for timers 0 and 1.
So, yes, it seems like we will have to shift to timer2 to test
compare interrupts on DA850.

Just to confirm, DA830 boots fine with the compare section removed:

---8<---
diff --git a/arch/arm/mach-davinci/da830.c b/arch/arm/mach-davinci/da830.c
index 0d81a8fdd9e6..f34398a7e47c 100644
--- a/arch/arm/mach-davinci/da830.c
+++ b/arch/arm/mach-davinci/da830.c
@@ -788,14 +788,6 @@ static const struct davinci_timer_cfg da830_timer_cfg = {
 			.flags	= IORESOURCE_IRQ,
 		},
 	},
-	.cmp = {
-		.irq = {
-			.start	= IRQ_DA830_T12CMPINT0_0,
-			.end	= IRQ_DA830_T12CMPINT0_0,
-			.flags	= IORESOURCE_IRQ,
-		},
-		.offset		= DA830_CMP12_0,
-	}
 };
 
 static const struct davinci_soc_info davinci_soc_info_da830 = {
---8<---

And the low-level debug with your patches shows that its hanging at 
delay loop calibration.

Uncompressing Linux... done, booting the kernel.                                
Booting Linux on physical CPU 0x0                                               
Linux version 5.0.0-rc1-08699-gc87d386784f3-dirty (a0875516@psplinux063) (gcc v9
CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=0005317f                   
CPU: VIVT data cache, VIVT instruction cache                                    
Machine: DaVinci DA830/OMAP-L137/AM17x EVM                                      
Memory policy: Data cache writethrough                                          
cma: Reserved 16 MiB at 0xc2800000                                              
DaVinci da830/omap-l137 rev2.0 variant 0x9                                      
On node 0 totalpages: 14336                                                     
  DMA zone: 112 pages used for memmap                                           
  DMA zone: 0 pages reserved                                                    
  DMA zone: 14336 pages, LIFO batch:3                                           
random: get_random_bytes called from start_kernel+0x80/0x3ec with crng_init=0   
pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768                                   
pcpu-alloc: [0] 0                                                               
Built 1 zonelists, mobility grouping on.  Total pages: 14224                    
Kernel command line: console=ttyS2,115200n8                                     
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)                   
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)                    
Memory: 33876K/57344K available (4607K kernel code, 308K rwdata, 1072K rodata, )
Virtual kernel memory layout:                                                   
    vector  : 0xffff0000 - 0xffff1000   (   4 kB)                               
    fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)                               
    vmalloc : 0xc4000000 - 0xff800000   ( 952 MB)                               
    lowmem  : 0xc0000000 - 0xc3800000   (  56 MB)                               
    modules : 0xbf000000 - 0xc0000000   (  16 MB)                               
      .text : 0x(ptrval) - 0x(ptrval)   (4609 kB)                               
      .init : 0x(ptrval) - 0x(ptrval)   ( 212 kB)                               
      .data : 0x(ptrval) - 0x(ptrval)   ( 309 kB)                               
       .bss : 0x(ptrval) - 0x(ptrval)   ( 137 kB)                               
SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1                      
rcu: Preemptible hierarchical RCU implementation.                               
        Tasks RCU enabled.                                                      
rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.          
NR_IRQS: 245                                                                    
clocksource: timer0_0: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79s
sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns       
Console: colour dummy device 80x30                                              
Calibrating delay loop... 
<hangs>

Thanks,
Sekhar

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 02/17] clocksource: davinci-timer: new driver
  2019-01-17 12:42         ` Sekhar Nori
@ 2019-01-17 14:01           ` Bartosz Golaszewski
  2019-01-24 12:09             ` Sekhar Nori
  0 siblings, 1 reply; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-17 14:01 UTC (permalink / raw)
  To: Sekhar Nori
  Cc: Mark Rutland, devicetree, Kevin Hilman, Daniel Lezcano,
	Linux Kernel Mailing List, Bartosz Golaszewski, Rob Herring,
	Thomas Gleixner, Linux ARM

czw., 17 sty 2019 o 13:42 Sekhar Nori <nsekhar@ti.com> napisał(a):
>
> On 16/01/19 2:48 PM, Sekhar Nori wrote:
> > On 14/01/19 10:09 PM, Bartosz Golaszewski wrote:
> >> pon., 14 sty 2019 o 13:20 Sekhar Nori <nsekhar@ti.com> napisał(a):
> >>>
> >>> Hi Bartosz,
> >>>
> >>> On 11/01/19 10:51 PM, Bartosz Golaszewski wrote:
> >>>> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >>>>
> >>>> Currently the clocksource and clockevent support for davinci platforms
> >>>> lives in mach-davinci. It hard-codes many things, used global variables,
> >>>> implements functionalities unused by any platform and has code fragments
> >>>> scattered across many (often unrelated) files.
> >>>>
> >>>> Implement a new, modern and simplified timer driver and put it into
> >>>> drivers/clocksource. We still need to support legacy board files so
> >>>> export a config structure and a function that allows machine code to
> >>>> register the timer.
> >>>>
> >>>> We don't check the return values of regmap reads and writes since with
> >>>> mmio it's only likely to fail due to programmer's errors.
> >>>>
> >>>> We also don't bother freeing resources on errors in
> >>>> davinci_timer_register() as the system won't boot without a timer anyway.
> >>>>
> >>>> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >>>
> >>> With this series, DA830 fails to boot. Rest of the devices are okay from
> >>> boot perspective.
> >>>
> >>> DA830 is pretty unique because it uses the same timer-half for both
> >>> clocksource and clockevent. May be you can set the same configuration on
> >>> your DA850 to see the same issue? Else, I will enable low-level debug
> >>> and try to provide more debug data.
> >>>
> >>
> >> I can't boot da850 with the same config as da830 (0x60 compare
> >> register, compare irq 74) even with the old timer code. Just to make
> >> sure: does da830 boot fine with mainline v5.0-rc2?
> >
> > Yeah, I did check that without the patch DA830 does boot.
>
> You are right that DA850 lacks compare interrupts for timers 0 and 1.
> So, yes, it seems like we will have to shift to timer2 to test
> compare interrupts on DA850.
>

Timers 2 and 3 are a bit different on da850 - for instance they don't
have separate interrupts for bottom and top halfs.

I configured the old code to use timer 2 - bottom half only with
compare register 0x60 and compare intterupt 74. It boots although very
slowly and something's broken with timekeeping as the clock goes
backwards and forward (seemingly) randomly.

Kevin has an OMAP-L137 starter kit - is this the same as da830-evm? If
so, then I can get remote access to it and work on this problem.
Otherwise, I can prepare something that works on da850 with broken
timekeeping and let you see if it works correctly on da830.

Bart

> Just to confirm, DA830 boots fine with the compare section removed:
>
> ---8<---
> diff --git a/arch/arm/mach-davinci/da830.c b/arch/arm/mach-davinci/da830.c
> index 0d81a8fdd9e6..f34398a7e47c 100644
> --- a/arch/arm/mach-davinci/da830.c
> +++ b/arch/arm/mach-davinci/da830.c
> @@ -788,14 +788,6 @@ static const struct davinci_timer_cfg da830_timer_cfg = {
>                         .flags  = IORESOURCE_IRQ,
>                 },
>         },
> -       .cmp = {
> -               .irq = {
> -                       .start  = IRQ_DA830_T12CMPINT0_0,
> -                       .end    = IRQ_DA830_T12CMPINT0_0,
> -                       .flags  = IORESOURCE_IRQ,
> -               },
> -               .offset         = DA830_CMP12_0,
> -       }
>  };
>
>  static const struct davinci_soc_info davinci_soc_info_da830 = {
> ---8<---
>
> And the low-level debug with your patches shows that its hanging at
> delay loop calibration.
>
> Uncompressing Linux... done, booting the kernel.
> Booting Linux on physical CPU 0x0
> Linux version 5.0.0-rc1-08699-gc87d386784f3-dirty (a0875516@psplinux063) (gcc v9
> CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=0005317f
> CPU: VIVT data cache, VIVT instruction cache
> Machine: DaVinci DA830/OMAP-L137/AM17x EVM
> Memory policy: Data cache writethrough
> cma: Reserved 16 MiB at 0xc2800000
> DaVinci da830/omap-l137 rev2.0 variant 0x9
> On node 0 totalpages: 14336
>   DMA zone: 112 pages used for memmap
>   DMA zone: 0 pages reserved
>   DMA zone: 14336 pages, LIFO batch:3
> random: get_random_bytes called from start_kernel+0x80/0x3ec with crng_init=0
> pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
> pcpu-alloc: [0] 0
> Built 1 zonelists, mobility grouping on.  Total pages: 14224
> Kernel command line: console=ttyS2,115200n8
> Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
> Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
> Memory: 33876K/57344K available (4607K kernel code, 308K rwdata, 1072K rodata, )
> Virtual kernel memory layout:
>     vector  : 0xffff0000 - 0xffff1000   (   4 kB)
>     fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
>     vmalloc : 0xc4000000 - 0xff800000   ( 952 MB)
>     lowmem  : 0xc0000000 - 0xc3800000   (  56 MB)
>     modules : 0xbf000000 - 0xc0000000   (  16 MB)
>       .text : 0x(ptrval) - 0x(ptrval)   (4609 kB)
>       .init : 0x(ptrval) - 0x(ptrval)   ( 212 kB)
>       .data : 0x(ptrval) - 0x(ptrval)   ( 309 kB)
>        .bss : 0x(ptrval) - 0x(ptrval)   ( 137 kB)
> SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
> rcu: Preemptible hierarchical RCU implementation.
>         Tasks RCU enabled.
> rcu: RCU calculated value of scheduler-enlistment delay is 10 jiffies.
> NR_IRQS: 245
> clocksource: timer0_0: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79s
> sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns
> Console: colour dummy device 80x30
> Calibrating delay loop...
> <hangs>
>
> Thanks,
> Sekhar

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 01/17] ARM: dts: da850: fix interrupt numbers for clocksource
  2019-01-11 17:21 ` [PATCH 01/17] ARM: dts: da850: fix interrupt numbers for clocksource Bartosz Golaszewski
@ 2019-01-17 14:22   ` Sekhar Nori
  2019-01-17 14:32     ` Bartosz Golaszewski
  0 siblings, 1 reply; 28+ messages in thread
From: Sekhar Nori @ 2019-01-17 14:22 UTC (permalink / raw)
  To: Bartosz Golaszewski, Kevin Hilman, Daniel Lezcano, Rob Herring,
	Mark Rutland, Thomas Gleixner
  Cc: devicetree, stable, linux-kernel, linux-arm-kernel, Bartosz Golaszewski

On 11/01/19 10:51 PM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> 
> The timer interrupts specified in commit 3652e2741f42 ("ARM: dts:
> da850: Add clocks") are wrong but since the current timer code
> hard-codes them, the bug was never spotted.
> 
> This patch must go into stable since, once we introduce a proper
> clocksource driver, devices with buggy device tree will stop booting.

Is this the case where someone uses device-tree from a stable tree and
kernel from latest mainline?

I have added it to my fixes branch for v5.0 anyway.

Thanks,
Sekhar

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 01/17] ARM: dts: da850: fix interrupt numbers for clocksource
  2019-01-17 14:22   ` Sekhar Nori
@ 2019-01-17 14:32     ` Bartosz Golaszewski
  0 siblings, 0 replies; 28+ messages in thread
From: Bartosz Golaszewski @ 2019-01-17 14:32 UTC (permalink / raw)
  To: Sekhar Nori
  Cc: Mark Rutland, devicetree, Kevin Hilman, Daniel Lezcano,
	Linux Kernel Mailing List, stable, Bartosz Golaszewski,
	Rob Herring, Thomas Gleixner, Linux ARM

czw., 17 sty 2019 o 15:23 Sekhar Nori <nsekhar@ti.com> napisał(a):
>
> On 11/01/19 10:51 PM, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >
> > The timer interrupts specified in commit 3652e2741f42 ("ARM: dts:
> > da850: Add clocks") are wrong but since the current timer code
> > hard-codes them, the bug was never spotted.
> >
> > This patch must go into stable since, once we introduce a proper
> > clocksource driver, devices with buggy device tree will stop booting.
>
> Is this the case where someone uses device-tree from a stable tree and
> kernel from latest mainline?
>

Well, if someone wants to use an old device tree and a newer kernel,
then it'll be broken anyway. If we get it to stable then at least the
fixed device tree will work in the future. That was my reasoning.

Bart

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 02/17] clocksource: davinci-timer: new driver
  2019-01-14 16:39     ` Bartosz Golaszewski
  2019-01-16  9:18       ` Sekhar Nori
@ 2019-01-23  0:30       ` Kevin Hilman
  1 sibling, 0 replies; 28+ messages in thread
From: Kevin Hilman @ 2019-01-23  0:30 UTC (permalink / raw)
  To: Bartosz Golaszewski, Sekhar Nori
  Cc: Mark Rutland, devicetree, Kevin Hilman, Daniel Lezcano,
	Linux Kernel Mailing List, Bartosz Golaszewski, Rob Herring,
	Thomas Gleixner, Linux ARM

Bartosz Golaszewski <brgl@bgdev.pl> writes:

> pon., 14 sty 2019 o 13:20 Sekhar Nori <nsekhar@ti.com> napisał(a):
>>
>> Hi Bartosz,
>>
>> On 11/01/19 10:51 PM, Bartosz Golaszewski wrote:
>> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>> >
>> > Currently the clocksource and clockevent support for davinci platforms
>> > lives in mach-davinci. It hard-codes many things, used global variables,
>> > implements functionalities unused by any platform and has code fragments
>> > scattered across many (often unrelated) files.
>> >
>> > Implement a new, modern and simplified timer driver and put it into
>> > drivers/clocksource. We still need to support legacy board files so
>> > export a config structure and a function that allows machine code to
>> > register the timer.
>> >
>> > We don't check the return values of regmap reads and writes since with
>> > mmio it's only likely to fail due to programmer's errors.
>> >
>> > We also don't bother freeing resources on errors in
>> > davinci_timer_register() as the system won't boot without a timer anyway.
>> >
>> > Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>>
>> With this series, DA830 fails to boot. Rest of the devices are okay from
>> boot perspective.
>>
>> DA830 is pretty unique because it uses the same timer-half for both
>> clocksource and clockevent. May be you can set the same configuration on
>> your DA850 to see the same issue? Else, I will enable low-level debug
>> and try to provide more debug data.
>>
>
> I can't boot da850 with the same config as da830 (0x60 compare
> register, compare irq 74) even with the old timer code. Just to make
> sure: does da830 boot fine with mainline v5.0-rc2?
>
>> Some minor comments below from quick look:
>>
>> > diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c
>> > new file mode 100644
>> > index 000000000000..7282a1fda80f
>> > --- /dev/null
>> > +++ b/drivers/clocksource/timer-davinci.c
>> > @@ -0,0 +1,415 @@
>> > +// SPDX-License-Identifier: GPL-2.0+
>> > +/*
>> > + * TI DaVinci clocksource driver
>> > + *
>> > + * Copyright (C) 2019 Texas Instruments
>> > + * Author: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>> > + * (with some parts adopted from code by Kevin Hilman <khilman@baylibre.com>)
>>
>> Did you really intend GPL v2 or later? The original code referred to
>> above is marked 2.0 only.
>>
>
> I'm not sure. Should it be GPLv2 only? I'm not well versed with licensing.

I guess it's up to you since you're the author of this new, reworked
driver, but the original one I wrote was GPLv2 only.

Note however that that the choice of v2 only was not out of objection to
v2+ but because I wrote that in 2007, when there was no "+" ;)

Kevin


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 02/17] clocksource: davinci-timer: new driver
  2019-01-17 14:01           ` Bartosz Golaszewski
@ 2019-01-24 12:09             ` Sekhar Nori
  0 siblings, 0 replies; 28+ messages in thread
From: Sekhar Nori @ 2019-01-24 12:09 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Mark Rutland, devicetree, Kevin Hilman, Daniel Lezcano,
	Linux Kernel Mailing List, Bartosz Golaszewski, Rob Herring,
	Thomas Gleixner, Linux ARM

On 17/01/19 7:31 PM, Bartosz Golaszewski wrote:
> czw., 17 sty 2019 o 13:42 Sekhar Nori <nsekhar@ti.com> napisał(a):
>>
>> On 16/01/19 2:48 PM, Sekhar Nori wrote:
>>> On 14/01/19 10:09 PM, Bartosz Golaszewski wrote:
>>>> pon., 14 sty 2019 o 13:20 Sekhar Nori <nsekhar@ti.com> napisał(a):
>>>>>
>>>>> Hi Bartosz,
>>>>>
>>>>> On 11/01/19 10:51 PM, Bartosz Golaszewski wrote:
>>>>>> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>>>>>>
>>>>>> Currently the clocksource and clockevent support for davinci platforms
>>>>>> lives in mach-davinci. It hard-codes many things, used global variables,
>>>>>> implements functionalities unused by any platform and has code fragments
>>>>>> scattered across many (often unrelated) files.
>>>>>>
>>>>>> Implement a new, modern and simplified timer driver and put it into
>>>>>> drivers/clocksource. We still need to support legacy board files so
>>>>>> export a config structure and a function that allows machine code to
>>>>>> register the timer.
>>>>>>
>>>>>> We don't check the return values of regmap reads and writes since with
>>>>>> mmio it's only likely to fail due to programmer's errors.
>>>>>>
>>>>>> We also don't bother freeing resources on errors in
>>>>>> davinci_timer_register() as the system won't boot without a timer anyway.
>>>>>>
>>>>>> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>>>>>
>>>>> With this series, DA830 fails to boot. Rest of the devices are okay from
>>>>> boot perspective.
>>>>>
>>>>> DA830 is pretty unique because it uses the same timer-half for both
>>>>> clocksource and clockevent. May be you can set the same configuration on
>>>>> your DA850 to see the same issue? Else, I will enable low-level debug
>>>>> and try to provide more debug data.
>>>>>
>>>>
>>>> I can't boot da850 with the same config as da830 (0x60 compare
>>>> register, compare irq 74) even with the old timer code. Just to make
>>>> sure: does da830 boot fine with mainline v5.0-rc2?
>>>
>>> Yeah, I did check that without the patch DA830 does boot.
>>
>> You are right that DA850 lacks compare interrupts for timers 0 and 1.
>> So, yes, it seems like we will have to shift to timer2 to test
>> compare interrupts on DA850.
>>
> 
> Timers 2 and 3 are a bit different on da850 - for instance they don't
> have separate interrupts for bottom and top halfs.

We should only be using the compare feature which has a a separate
interrupt (distinct from top and bottom half interrupts). Only timer 2
and 3 of DA850 have the compare interrupts though. So you will have to
use those timers to be able to test compare feature on DA850.

> 
> I configured the old code to use timer 2 - bottom half only with
> compare register 0x60 and compare intterupt 74. It boots although very
> slowly and something's broken with timekeeping as the clock goes
> backwards and forward (seemingly) randomly.

Ah, okay. Timer 2/3 use ASYNC3 as clock input instead of PLL0_AUXCLK.
Did you make adjustment for this too?

> 
> Kevin has an OMAP-L137 starter kit - is this the same as da830-evm? If

Yes.

> so, then I can get remote access to it and work on this problem.
> Otherwise, I can prepare something that works on da850 with broken
> timekeeping and let you see if it works correctly on da830.

Alright, happy to test.

Thanks,
Sekhar

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, back to index

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11 17:21 [PATCH 00/17] ARM: davinci: modernize the timer support Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 01/17] ARM: dts: da850: fix interrupt numbers for clocksource Bartosz Golaszewski
2019-01-17 14:22   ` Sekhar Nori
2019-01-17 14:32     ` Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 02/17] clocksource: davinci-timer: new driver Bartosz Golaszewski
2019-01-14 12:20   ` Sekhar Nori
2019-01-14 16:39     ` Bartosz Golaszewski
2019-01-16  9:18       ` Sekhar Nori
2019-01-17 12:42         ` Sekhar Nori
2019-01-17 14:01           ` Bartosz Golaszewski
2019-01-24 12:09             ` Sekhar Nori
2019-01-23  0:30       ` Kevin Hilman
2019-01-11 17:21 ` [PATCH 03/17] ARM: davinci: enable the clocksource driver for DT mode Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 04/17] ARM: davinci: da850: WARN() if clk_get() fails Bartosz Golaszewski
2019-01-14 12:22   ` Sekhar Nori
2019-01-11 17:21 ` [PATCH 05/17] ARM: davinci: da830: " Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 06/17] ARM: davinci: dm355: " Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 07/17] ARM: davinci: dm365: " Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 08/17] ARM: davinci: dm644x: " Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 09/17] ARM: davinci: dm646x: " Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 10/17] ARM: davinci: da850: switch to using the clocksource driver Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 11/17] ARM: davinci: da830: " Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 12/17] ARM: davinci: move timer definitions to davinci.h Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 13/17] ARM: davinci: dm355: switch to using the clocksource driver Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 14/17] ARM: davinci: dm365: " Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 15/17] ARM: davinci: dm644x: " Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 16/17] ARM: davinci: dm646x: " Bartosz Golaszewski
2019-01-11 17:21 ` [PATCH 17/17] ARM: davinci: remove legacy timer support Bartosz Golaszewski

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org infradead-linux-arm-kernel@archiver.kernel.org
	public-inbox-index linux-arm-kernel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox