Skip to contentSkip to conversation

dm: implement a Timer uclass

PATCH New Thomas Chou 4 participants 45 messages Sep 28, 2015 – Oct 19, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 dm: implement a Timer uclass

Implement a Timer uclass to work with lib/time.c.

---
 common/board_r.c             |  2 +-
 drivers/Kconfig              |  2 ++
 drivers/Makefile             |  1 +
 drivers/timer/Kconfig        |  9 ++++++++
 drivers/timer/Makefile       |  7 ++++++
 drivers/timer/timer-uclass.c | 35 ++++++++++++++++++++++++++++++
 drivers/timer/timer.c        | 51 ++++++++++++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h       |  1 +
 include/timer.h              | 36 +++++++++++++++++++++++++++++++
 9 files changed, 143 insertions(+), 1 deletion(-)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 drivers/timer/timer.c
 create mode 100644 include/timer.h
common/board_r.c +1 -1
index f8c1baa..2d8ad11 100644
@@ -829,7 +829,7 @@ init_fnc_t init_sequence_r[] = {
 	initr_enable_interrupts,
 #endif
 #if defined(CONFIG_X86) || defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) \
-	|| defined(CONFIG_M68K)
+	|| defined(CONFIG_M68K) || defined(CONFIG_DM_TIMER)
 	timer_init,		/* initialize timer */
 #endif
 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
drivers/Kconfig +2 -0
index 63c92c5..f9496f7 100644
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
drivers/Makefile +1 -0
index 9d0a595..692da78 100644
@@ -48,6 +48,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
 obj-y += video/
drivers/timer/Kconfig new file +9 -0
new file mode 100644
index 0000000..97014f3
@@ -0,0 +1,9 @@
+menu "Timer Support"
+
+config DM_TIMER
+	bool "Enable Driver Model for Timer drivers"
+	depends on DM
+	help
+	  Enable driver model for Timer access.
+
+endmenu
drivers/timer/Makefile new file +7 -0
new file mode 100644
index 0000000..58acd7c
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2015 Thomas Chou <[email protected]>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_DM_TIMER)		+= timer-uclass.o timer.o
drivers/timer/timer-uclass.c new file +35 -0
new file mode 100644
index 0000000..1f088bf
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <timer.h>
+
+int timer_get_count(struct udevice *dev, unsigned long *count)
+{
+	const struct dm_timer_ops *ops = device_get_ops(dev);
+
+	if (!ops->get_count)
+		return -ENOSYS;
+
+	return ops->get_count(dev, count);
+}
+
+int timer_get_rate(struct udevice *dev, unsigned long *rate)
+{
+	const struct dm_timer_ops *ops = device_get_ops(dev);
+
+	if (!ops->get_rate)
+		return -ENOSYS;
+
+	return ops->get_rate(dev, rate);
+}
+
+UCLASS_DRIVER(timer) = {
+	.id		= UCLASS_TIMER,
+	.name		= "timer",
+};
drivers/timer/timer.c new file +51 -0

51 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 1eeec74..aff34a4 100644
@@ -56,6 +56,7 @@ enum uclass_id {
 	UCLASS_SPI_GENERIC,	/* Generic SPI flash target */
 	UCLASS_SYSCON,		/* System configuration device */
 	UCLASS_THERMAL,		/* Thermal sensor */
+	UCLASS_TIMER,		/* Timer device */
 	UCLASS_TPM,		/* Trusted Platform Module TIS interface */
 	UCLASS_USB,		/* USB bus */
 	UCLASS_USB_DEV_GENERIC,	/* USB generic device */
include/timer.h new file +36 -0
new file mode 100644
index 0000000..5d71612
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _DM_TIMER_H_
+#define _DM_TIMER_H_
+
+int timer_get_count(struct udevice *dev, unsigned long *count);
+int timer_get_rate(struct udevice *dev, unsigned long *rate);
+
+/*
+ * struct dm_timer_ops - Driver model Timer operations
+ *
+ * The uclass interface is implemented by all Timer devices which use
+ * driver model.
+ */
+struct dm_timer_ops {
+	/*
+	 * Get the current timer count
+	 *
+	 * @dev:	The Timer device
+	 * @count:	pointer that returns the currnet timer count
+	 */
+	int (*get_count)(struct udevice *dev, unsigned long *count);
+	/*
+	 * Get the timer clock rate
+	 *
+	 * @dev:	The Timer device
+	 * @rate:	pointer that returns the timer clock rate
+	 */
+	int (*get_rate)(struct udevice *dev, unsigned long *rate);
+};
+
+#endif	/* _DM_TIMER_H_ */
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/2 dm: implement a Timer uclass

Quoted 17 lines · Thomas Chou
drivers/timer/timer.c new file +11 -0
new file mode 100644
index 0000000..648fd06
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <timer.h>
+

drivers/timer/timer.c line 21

Quoted 10 lines
drivers/timer/timer.c new file +10 -0
+DECLARE_GLOBAL_DATA_PTR;
+
+unsigned long notrace get_tbclk(void)
+{
+	struct udevice *dev;
+	unsigned long rate;
+
+	uclass_first_device(UCLASS_TIMER, &dev);
+	if (!dev)
+		return 100000000; /* 100MHz, fail-safe */
		return -ENODEV;
Quoted 4 lines
drivers/timer/timer.c new file +4 -0
+
+	timer_get_rate(dev, &rate);
+
+	return rate;

drivers/timer/timer.c line 35

Quoted 10 lines
drivers/timer/timer.c new file +10 -0
+}
+
+unsigned long notrace timer_read_counter(void)
+{
+	struct udevice *dev;
+	unsigned long count;
+
+	uclass_first_device(UCLASS_TIMER, &dev);
+	if (!dev)
+		return 0; /* 0, fail-safe */
		return -ENODEV;
#2 lore raw

PATCH 2/2 nios2: convert altera timer to driver model

In reply to Thomas Chou

Convert altera timer to driver model.

---
 arch/nios2/cpu/Makefile         |   2 +-
 arch/nios2/cpu/timer.c          |  65 ------------------------
 common/board_f.c                |   3 +-
 configs/nios2-generic_defconfig |   2 +
 drivers/timer/Kconfig           |   7 +++
 drivers/timer/Makefile          |   1 +
 drivers/timer/altera_timer.c    | 110 ++++++++++++++++++++++++++++++++++++++++
 include/configs/nios2-generic.h |   6 ---
 8 files changed, 122 insertions(+), 74 deletions(-)
 delete mode 100644 arch/nios2/cpu/timer.c
 create mode 100644 drivers/timer/altera_timer.c
arch/nios2/cpu/Makefile +1 -1
index c85e261..3fe7847 100644
@@ -7,5 +7,5 @@
 
 extra-y	= start.o
 obj-y	= exceptions.o
-obj-y	+= cpu.o interrupts.o sysid.o timer.o traps.o
+obj-y	+= cpu.o interrupts.o sysid.o traps.o
 obj-y	+= fdt.o
arch/nios2/cpu/timer.c deleted +0 -65

65 lines not on this page · raw message

common/board_f.c +1 -2
index d0a9ff7..4c23a7f 100644
@@ -795,8 +795,7 @@ static init_fnc_t init_sequence_f[] = {
 	init_timebase,
 #endif
 #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
-    defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
-    defined(CONFIG_NIOS2)
+    defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32)
 	timer_init,		/* initialize timer */
 #endif
 #ifdef CONFIG_SYS_ALLOC_DPRAM
configs/nios2-generic_defconfig +2 -0
index 63d99d8..1aa2d9e 100644
@@ -17,3 +17,5 @@ CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
+CONFIG_DM_TIMER=y
+CONFIG_ALTERA_TIMER=y
drivers/timer/Kconfig +7 -0
index 97014f3..70fbcda 100644
@@ -6,4 +6,11 @@ config DM_TIMER
 	help
 	  Enable driver model for Timer access.
 
+config ALTERA_TIMER
+	bool "Altera Timer support"
+	depends on DM_TIMER
+	help
+	  Select this to enable an timer for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 endmenu
drivers/timer/Makefile +1 -0
index 58acd7c..db8fa2b 100644
@@ -5,3 +5,4 @@
 #
 
 obj-$(CONFIG_DM_TIMER)		+= timer-uclass.o timer.o
+obj-$(CONFIG_ALTERA_TIMER)	+= altera_timer.o
drivers/timer/altera_timer.c new file +110 -0

110 lines not on this page · raw message

include/configs/nios2-generic.h +0 -6
index 90ccbd1..ae19676 100644
@@ -27,12 +27,6 @@
 #define CONFIG_SYS_CONSOLE_INFO_QUIET	/* Suppress console info */
 
 /*
- * TIMER
- */
-#define CONFIG_SYS_TIMER_COUNTS_DOWN
-#define CONFIG_SYS_TIMER_RATE		CONFIG_SYS_TIMER_FREQ
-
-/*
  * BOOTP options
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
Signature · 1 line
2.1.4
#3 lore raw

PATCH v2 1/2 dm: implement a Timer uclass

In reply to Thomas Chou

Implement a Timer uclass to work with lib/time.c.

---
v2
fix coding style.

 common/board_r.c             |  5 +++--
 drivers/Kconfig              |  2 ++
 drivers/Makefile             |  1 +
 drivers/timer/Kconfig        |  9 ++++++++
 drivers/timer/Makefile       |  7 ++++++
 drivers/timer/timer-uclass.c | 35 ++++++++++++++++++++++++++++++
 drivers/timer/timer.c        | 51 ++++++++++++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h       |  1 +
 include/timer.h              | 36 +++++++++++++++++++++++++++++++
 9 files changed, 145 insertions(+), 2 deletions(-)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 drivers/timer/timer.c
 create mode 100644 include/timer.h
common/board_r.c +3 -2
index f8c1baa..64b0577 100644
@@ -828,8 +828,9 @@ init_fnc_t init_sequence_r[] = {
 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32)
 	initr_enable_interrupts,
 #endif
-#if defined(CONFIG_X86) || defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) \
-	|| defined(CONFIG_M68K)
+#if defined(CONFIG_X86) || defined(CONFIG_MICROBLAZE) || \
+		defined(CONFIG_AVR32) || defined(CONFIG_M68K) || \
+		defined(CONFIG_DM_TIMER)
 	timer_init,		/* initialize timer */
 #endif
 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
drivers/Kconfig +2 -0
index 63c92c5..f9496f7 100644
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
drivers/Makefile +1 -0
index 9d0a595..692da78 100644
@@ -48,6 +48,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
 obj-y += video/
drivers/timer/Kconfig new file +9 -0
new file mode 100644
index 0000000..97014f3
@@ -0,0 +1,9 @@
+menu "Timer Support"
+
+config DM_TIMER
+	bool "Enable Driver Model for Timer drivers"
+	depends on DM
+	help
+	  Enable driver model for Timer access.
+
+endmenu
drivers/timer/Makefile new file +7 -0
new file mode 100644
index 0000000..58acd7c
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2015 Thomas Chou <[email protected]>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_DM_TIMER)		+= timer-uclass.o timer.o
drivers/timer/timer-uclass.c new file +35 -0
new file mode 100644
index 0000000..1f088bf
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <timer.h>
+
+int timer_get_count(struct udevice *dev, unsigned long *count)
+{
+	const struct dm_timer_ops *ops = device_get_ops(dev);
+
+	if (!ops->get_count)
+		return -ENOSYS;
+
+	return ops->get_count(dev, count);
+}
+
+int timer_get_rate(struct udevice *dev, unsigned long *rate)
+{
+	const struct dm_timer_ops *ops = device_get_ops(dev);
+
+	if (!ops->get_rate)
+		return -ENOSYS;
+
+	return ops->get_rate(dev, rate);
+}
+
+UCLASS_DRIVER(timer) = {
+	.id		= UCLASS_TIMER,
+	.name		= "timer",
+};
drivers/timer/timer.c new file +51 -0

51 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 1eeec74..aff34a4 100644
@@ -56,6 +56,7 @@ enum uclass_id {
 	UCLASS_SPI_GENERIC,	/* Generic SPI flash target */
 	UCLASS_SYSCON,		/* System configuration device */
 	UCLASS_THERMAL,		/* Thermal sensor */
+	UCLASS_TIMER,		/* Timer device */
 	UCLASS_TPM,		/* Trusted Platform Module TIS interface */
 	UCLASS_USB,		/* USB bus */
 	UCLASS_USB_DEV_GENERIC,	/* USB generic device */
include/timer.h new file +36 -0
new file mode 100644
index 0000000..5d71612
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _DM_TIMER_H_
+#define _DM_TIMER_H_
+
+int timer_get_count(struct udevice *dev, unsigned long *count);
+int timer_get_rate(struct udevice *dev, unsigned long *rate);
+
+/*
+ * struct dm_timer_ops - Driver model Timer operations
+ *
+ * The uclass interface is implemented by all Timer devices which use
+ * driver model.
+ */
+struct dm_timer_ops {
+	/*
+	 * Get the current timer count
+	 *
+	 * @dev:	The Timer device
+	 * @count:	pointer that returns the currnet timer count
+	 */
+	int (*get_count)(struct udevice *dev, unsigned long *count);
+	/*
+	 * Get the timer clock rate
+	 *
+	 * @dev:	The Timer device
+	 * @rate:	pointer that returns the timer clock rate
+	 */
+	int (*get_rate)(struct udevice *dev, unsigned long *rate);
+};
+
+#endif	/* _DM_TIMER_H_ */
Signature · 1 line
2.1.4
#4 lore raw

PATCH v2 2/2 nios2: convert altera timer to driver model

Convert altera timer to driver model.

---
v2
fix coding style.

 arch/nios2/cpu/Makefile         |   2 +-
 arch/nios2/cpu/timer.c          |  65 ------------------------
 common/board_f.c                |   3 +-
 configs/nios2-generic_defconfig |   2 +
 drivers/timer/Kconfig           |   7 +++
 drivers/timer/Makefile          |   1 +
 drivers/timer/altera_timer.c    | 110 ++++++++++++++++++++++++++++++++++++++++
 include/configs/nios2-generic.h |   6 ---
 8 files changed, 122 insertions(+), 74 deletions(-)
 delete mode 100644 arch/nios2/cpu/timer.c
 create mode 100644 drivers/timer/altera_timer.c
arch/nios2/cpu/Makefile +1 -1
index c85e261..3fe7847 100644
@@ -7,5 +7,5 @@
 
 extra-y	= start.o
 obj-y	= exceptions.o
-obj-y	+= cpu.o interrupts.o sysid.o timer.o traps.o
+obj-y	+= cpu.o interrupts.o sysid.o traps.o
 obj-y	+= fdt.o
arch/nios2/cpu/timer.c deleted +0 -65

65 lines not on this page · raw message

common/board_f.c +1 -2
index d0a9ff7..613332e 100644
@@ -795,8 +795,7 @@ static init_fnc_t init_sequence_f[] = {
 	init_timebase,
 #endif
 #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
-    defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
-    defined(CONFIG_NIOS2)
+		defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32)
 	timer_init,		/* initialize timer */
 #endif
 #ifdef CONFIG_SYS_ALLOC_DPRAM
configs/nios2-generic_defconfig +2 -0
index 707ee33..dac0b62 100644
@@ -18,3 +18,5 @@ CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
+CONFIG_DM_TIMER=y
+CONFIG_ALTERA_TIMER=y
drivers/timer/Kconfig +7 -0
index 97014f3..70fbcda 100644
@@ -6,4 +6,11 @@ config DM_TIMER
 	help
 	  Enable driver model for Timer access.
 
+config ALTERA_TIMER
+	bool "Altera Timer support"
+	depends on DM_TIMER
+	help
+	  Select this to enable an timer for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 endmenu
drivers/timer/Makefile +1 -0
index 58acd7c..db8fa2b 100644
@@ -5,3 +5,4 @@
 #
 
 obj-$(CONFIG_DM_TIMER)		+= timer-uclass.o timer.o
+obj-$(CONFIG_ALTERA_TIMER)	+= altera_timer.o
drivers/timer/altera_timer.c new file +110 -0

110 lines not on this page · raw message

include/configs/nios2-generic.h +0 -6
index 90ccbd1..ae19676 100644
@@ -27,12 +27,6 @@
 #define CONFIG_SYS_CONSOLE_INFO_QUIET	/* Suppress console info */
 
 /*
- * TIMER
- */
-#define CONFIG_SYS_TIMER_COUNTS_DOWN
-#define CONFIG_SYS_TIMER_RATE		CONFIG_SYS_TIMER_FREQ
-
-/*
  * BOOTP options
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
Signature · 1 line
2.1.4
#5 lore raw

PATCH v2 2/2 nios2: convert altera timer to driver model

Hi Thomas,

Quoted 7 lines · thomas at wytron.com.tw

Convert altera timer to driver model.

---
v2
fix coding style.

Quoted 12 lines
 arch/nios2/cpu/Makefile         |   2 +-
 arch/nios2/cpu/timer.c          |  65 ------------------------
 common/board_f.c                |   3 +-
 configs/nios2-generic_defconfig |   2 +
 drivers/timer/Kconfig           |   7 +++
 drivers/timer/Makefile          |   1 +
 drivers/timer/altera_timer.c    | 110 ++++++++++++++++++++++++++++++++++++++++
 include/configs/nios2-generic.h |   6 ---
 8 files changed, 122 insertions(+), 74 deletions(-)
 delete mode 100644 arch/nios2/cpu/timer.c
 create mode 100644 drivers/timer/altera_timer.c

Thanks for the patch.
The patch looks good except it misses the changes for dts.

Thanks
Chin Liang

#6 lore raw

PATCH v2 2/2 nios2: convert altera timer to driver model

Hi Chin Liang,

Quoted 2 lines · Chin Liang See

Thanks for the patch.
The patch looks good except it misses the changes for dts.

If you mean pre relocation, I will add a pre relocation flag, DM_FLAG_PRE_RELOC, to the altera_timer driver. Though I think there is no need to initialize the timer before relocation for nios2 and the dts is not changed. Those who need timer before relocation can add the property "u-boot,dm-pre-reloc;" to dts.

Best regards,
Thomas Chou

#7 lore raw

PATCH v2 2/2 nios2: convert altera timer to driver model

Hi Chin Liang,

Quoted 6 lines · Thomas Chou

Hi Chin Liang,

Quoted 2 lines · Chin Liang See

Thanks for the patch.
The patch looks good except it misses the changes for dts.

Sorry. I guess I misunderstood. The dts binding is added.

Best regards,
Thomas Chou

#8 lore raw

PATCH v2 1/2 dm: implement a Timer uclass

In reply to Thomas Chou

Hi Thomas,

Quoted 3 lines · Thomas Chou

Implement a Timer uclass to work with lib/time.c.

Thanks for doing this work! I have some comments below.

Quoted 67 lines

---
v2
fix coding style.

 common/board_r.c             |  5 +++--
 drivers/Kconfig              |  2 ++
 drivers/Makefile             |  1 +
 drivers/timer/Kconfig        |  9 ++++++++
 drivers/timer/Makefile       |  7 ++++++
 drivers/timer/timer-uclass.c | 35 ++++++++++++++++++++++++++++++
 drivers/timer/timer.c        | 51 ++++++++++++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h       |  1 +
 include/timer.h              | 36 +++++++++++++++++++++++++++++++
 9 files changed, 145 insertions(+), 2 deletions(-)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 drivers/timer/timer.c
 create mode 100644 include/timer.h
common/board_r.c +3 -2
index f8c1baa..64b0577 100644
@@ -828,8 +828,9 @@ init_fnc_t init_sequence_r[] = {
 #if defined(CONFIG_ARM) || defined(CONFIG_AVR32)
        initr_enable_interrupts,
 #endif
-#if defined(CONFIG_X86) || defined(CONFIG_MICROBLAZE) || defined(CONFIG_AVR32) \
-       || defined(CONFIG_M68K)
+#if defined(CONFIG_X86) || defined(CONFIG_MICROBLAZE) || \
+               defined(CONFIG_AVR32) || defined(CONFIG_M68K) || \
+               defined(CONFIG_DM_TIMER)
        timer_init,             /* initialize timer */
 #endif
 #if defined(CONFIG_STATUS_LED) && defined(STATUS_LED_BOOT)
drivers/Kconfig +2 -0
index 63c92c5..f9496f7 100644
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
drivers/Makefile +1 -0
index 9d0a595..692da78 100644
@@ -48,6 +48,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
 obj-y += video/
drivers/timer/Kconfig new file +0 -0
new file mode 100644
index 0000000..97014f3

drivers/timer/Kconfig line 7

Quoted 7 lines
drivers/timer/Kconfig new file +7 -0
@@ -0,0 +1,9 @@
+menu "Timer Support"
+
+config DM_TIMER
+       bool "Enable Driver Model for Timer drivers"
+       depends on DM
+       help
+         Enable driver model for Timer access.

Can you expand this a little bit?

- Uses the same API
- But now implemented by the uclass
- The first timer is used

drivers/timer/timer.c

Quoted 61 lines
drivers/timer/Kconfig new file +2 -0
+
+endmenu
drivers/timer/Makefile new file +7 -0
new file mode 100644
index 0000000..58acd7c
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2015 Thomas Chou <[email protected]>
+#
+# SPDX-License-Identifier:     GPL-2.0+
+#
+
+obj-$(CONFIG_DM_TIMER)         += timer-uclass.o timer.o
drivers/timer/timer-uclass.c new file +35 -0
new file mode 100644
index 0000000..1f088bf
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <timer.h>
+
+int timer_get_count(struct udevice *dev, unsigned long *count)
+{
+       const struct dm_timer_ops *ops = device_get_ops(dev);
+
+       if (!ops->get_count)
+               return -ENOSYS;
+
+       return ops->get_count(dev, count);
+}
+
+int timer_get_rate(struct udevice *dev, unsigned long *rate)
+{
+       const struct dm_timer_ops *ops = device_get_ops(dev);
+
+       if (!ops->get_rate)
+               return -ENOSYS;
+
+       return ops->get_rate(dev, rate);
+}
+
+UCLASS_DRIVER(timer) = {
+       .id             = UCLASS_TIMER,
+       .name           = "timer",
+};
drivers/timer/timer.c new file +0 -0
new file mode 100644
index 0000000..766eabf

I think these functions should go in lib/time.c.

At some point we should look at implementing udelay() also.

Quoted 26 lines
drivers/timer/timer.c new file +25 -0
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <timer.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+unsigned long notrace get_tbclk(void)
+{
+       struct udevice *dev;
+       unsigned long rate;
+
+       uclass_first_device(UCLASS_TIMER, &dev);
+       if (!dev)
+               return -ENODEV;
+
+       timer_get_rate(dev, &rate);
+
+       return rate;

drivers/timer/timer.c line 35

Quoted 10 lines
drivers/timer/timer.c new file +10 -0
+}
+
+unsigned long notrace timer_read_counter(void)
+{
+       struct udevice *dev;
+       unsigned long count;
+
+       uclass_first_device(UCLASS_TIMER, &dev);
+       if (!dev)
+               return -ENODEV;

I suggest saving this device in global_data. This might get called a lot.

drivers/timer/timer.c line 42

Quoted 7 lines
drivers/timer/timer.c new file +7 -0
+
+       timer_get_count(dev, &count);
+
+       return count;
+}
+
+int timer_init(void)

I suspect this function is not needed. We should try to avoid this sort of thing with driver model - devices should be able to be inited when needed. Granted the timer is a very basic device, but it should follow the same model if possible.

Quoted 27 lines
drivers/timer/timer.c new file +9 -0
+{
+       struct udevice *dev;
+
+       uclass_first_device(UCLASS_TIMER, &dev);
+       if (!dev)
+               return -ENODEV;
+
+       return 0;
+}
include/dm/uclass-id.h +1 -0
index 1eeec74..aff34a4 100644
@@ -56,6 +56,7 @@ enum uclass_id {
        UCLASS_SPI_GENERIC,     /* Generic SPI flash target */
        UCLASS_SYSCON,          /* System configuration device */
        UCLASS_THERMAL,         /* Thermal sensor */
+       UCLASS_TIMER,           /* Timer device */
        UCLASS_TPM,             /* Trusted Platform Module TIS interface */
        UCLASS_USB,             /* USB bus */
        UCLASS_USB_DEV_GENERIC, /* USB generic device */
include/timer.h new file +0 -0
new file mode 100644
index 0000000..5d71612

include/timer.h line 10

Quoted 10 lines
include/timer.h new file +10 -0
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef _DM_TIMER_H_
+#define _DM_TIMER_H_
+
+int timer_get_count(struct udevice *dev, unsigned long *count);

We should also handle microsecond time in this API. How about:

timer_get_ms()
timer_get_us()

include/timer.h line 11

Quoted 1 line
include/timer.h new file +1 -0
+int timer_get_rate(struct udevice *dev, unsigned long *rate);

Function comments.

include/timer.h line 24

Quoted 13 lines
include/timer.h new file +13 -0
+
+/*
+ * struct dm_timer_ops - Driver model Timer operations
+ *
+ * The uclass interface is implemented by all Timer devices which use
+ * driver model.
+ */
+struct dm_timer_ops {
+       /*
+        * Get the current timer count
+        *
+        * @dev:        The Timer device
+        * @count:      pointer that returns the currnet timer count

current
Also don't forget @return

include/timer.h line 31

Quoted 7 lines
include/timer.h new file +7 -0
+        */
+       int (*get_count)(struct udevice *dev, unsigned long *count);
+       /*
+        * Get the timer clock rate
+        *
+        * @dev:        The Timer device
+        * @rate:       pointer that returns the timer clock rate

in Hz. Also, isn't the clock rate required to be 1000 now?

Quoted 8 lines
include/timer.h new file +5 -1
+        */
+       int (*get_rate)(struct udevice *dev, unsigned long *rate);
+};
+
+#endif /* _DM_TIMER_H_ */
--

2.1.4

Regards,
Simon

#9 lore raw

PATCH v2 1/2 dm: implement a Timer uclass

Hi Simon,

Quoted 6 lines · Simon Glass
Quoted 1 line

+int timer_get_count(struct udevice *dev, unsigned long *count);

We should also handle microsecond time in this API. How about:

timer_get_ms()
timer_get_us()

Please allow the additional API be implemented at some later point. It might be better to keep the first patch simple as possible,

Quoted 9 lines

include/timer.h line 33

Quoted 7 lines
include/timer.h new file +7 -0
+       /*
+        * Get the timer clock rate
+        *
+        * @dev:        The Timer device
+        * @rate:       pointer that returns the timer clock rate
+        */
+       int (*get_rate)(struct udevice *dev, unsigned long *rate);

in Hz. Also, isn't the clock rate required to be 1000 now?

Sorry for the confusion. It meant the timer input clock frequency. I rename it to get_clock() now. Will this be better?

Thanks a lot for your review.

Best regards,
Thomas Chou

#10 lore raw

PATCH v3 1/2 dm: implement a Timer uclass

In reply to Thomas Chou

Implement a Timer uclass to work with lib/time.c.

---
v2
fix coding style.
v3
add description to Kconfig as Simon suggested.
move timer.c code to lib/time.c.
add dm_timer dev to global data.
remove timer_init().
change API name get_clock.

 common/board_r.c                  |  3 +++
 drivers/Kconfig                   |  2 ++
 drivers/Makefile                  |  1 +
 drivers/timer/Kconfig             | 11 ++++++++
 drivers/timer/Makefile            |  7 +++++
 drivers/timer/timer-uclass.c      | 35 +++++++++++++++++++++++++
 include/asm-generic/global_data.h |  3 +++
 include/dm/uclass-id.h            |  1 +
 include/timer.h                   | 52 +++++++++++++++++++++++++++++++++++++
 lib/time.c                        | 54 +++++++++++++++++++++++++++++++++++++++
 10 files changed, 169 insertions(+)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 include/timer.h
common/board_r.c +3 -0
index f8c1baa..aaf390e 100644
@@ -290,6 +290,9 @@ static int initr_dm(void)
 	/* Save the pre-reloc driver model and start a new one */
 	gd->dm_root_f = gd->dm_root;
 	gd->dm_root = NULL;
+#ifdef CONFIG_DM_TIMER
+	gd->dm_timer = NULL;
+#endif
 	return dm_init_and_scan(false);
 }
 #endif
drivers/Kconfig +2 -0
index 63c92c5..f9496f7 100644
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
drivers/Makefile +1 -0
index 9d0a595..692da78 100644
@@ -48,6 +48,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
 obj-y += video/
drivers/timer/Kconfig new file +11 -0
new file mode 100644
index 0000000..5228e26
@@ -0,0 +1,11 @@
+menu "Timer Support"
+
+config DM_TIMER
+	bool "Enable Driver Model for Timer drivers"
+	depends on DM
+	help
+	  Enable driver model for Timer access. It uses the same API as
+	  lib/time.c. But now implemented by the uclass. The first timer
+	  will be used.
+
+endmenu
drivers/timer/Makefile new file +7 -0
new file mode 100644
index 0000000..a24179a
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2015 Thomas Chou <[email protected]>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_DM_TIMER)		+= timer-uclass.o
drivers/timer/timer-uclass.c new file +35 -0
new file mode 100644
index 0000000..8071fcc
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <timer.h>
+
+int timer_get_count(struct udevice *dev, unsigned long *count)
+{
+	const struct dm_timer_ops *ops = device_get_ops(dev);
+
+	if (!ops->get_count)
+		return -ENOSYS;
+
+	return ops->get_count(dev, count);
+}
+
+int timer_get_clock(struct udevice *dev, unsigned long *freq)
+{
+	const struct dm_timer_ops *ops = device_get_ops(dev);
+
+	if (!ops->get_clock)
+		return -ENOSYS;
+
+	return ops->get_clock(dev, freq);
+}
+
+UCLASS_DRIVER(timer) = {
+	.id		= UCLASS_TIMER,
+	.name		= "timer",
+};
include/asm-generic/global_data.h +3 -0
index 2155265..ebecb5f 100644
@@ -69,6 +69,9 @@ typedef struct global_data {
 	struct udevice	*dm_root_f;	/* Pre-relocation root instance */
 	struct list_head uclass_root;	/* Head of core tree */
 #endif
+#ifdef CONFIG_DM_TIMER
+	struct udevice	*dm_timer;	/* Timer instance for Driver Model */
+#endif
 
 	const void *fdt_blob;	/* Our device tree, NULL if none */
 	void *new_fdt;		/* Relocated FDT */
include/dm/uclass-id.h +1 -0
index 1eeec74..aff34a4 100644
@@ -56,6 +56,7 @@ enum uclass_id {
 	UCLASS_SPI_GENERIC,	/* Generic SPI flash target */
 	UCLASS_SYSCON,		/* System configuration device */
 	UCLASS_THERMAL,		/* Thermal sensor */
+	UCLASS_TIMER,		/* Timer device */
 	UCLASS_TPM,		/* Trusted Platform Module TIS interface */
 	UCLASS_USB,		/* USB bus */
 	UCLASS_USB_DEV_GENERIC,	/* USB generic device */
include/timer.h new file +52 -0

52 lines not on this page · raw message

lib/time.c +54 -0

66 lines not on this page · raw message

Signature · 1 line
2.1.4
#11 lore raw

PATCH v3 2/2 nios2: convert altera timer to driver model

Convert altera timer to driver model.

---
v2
fix coding style.
v3
doc dts binding.

 arch/nios2/cpu/Makefile                         |   2 +-
 arch/nios2/cpu/timer.c                          |  65 --------------
 common/board_f.c                                |   3 +-
 configs/nios2-generic_defconfig                 |   2 +
 doc/device-tree-bindings/timer/altera_timer.txt |  19 ++++
 drivers/timer/Kconfig                           |   7 ++
 drivers/timer/Makefile                          |   1 +
 drivers/timer/altera_timer.c                    | 110 ++++++++++++++++++++++++
 include/configs/nios2-generic.h                 |   6 --
 9 files changed, 141 insertions(+), 74 deletions(-)
 delete mode 100644 arch/nios2/cpu/timer.c
 create mode 100644 doc/device-tree-bindings/timer/altera_timer.txt
 create mode 100644 drivers/timer/altera_timer.c
arch/nios2/cpu/Makefile +1 -1
index c85e261..3fe7847 100644
@@ -7,5 +7,5 @@
 
 extra-y	= start.o
 obj-y	= exceptions.o
-obj-y	+= cpu.o interrupts.o sysid.o timer.o traps.o
+obj-y	+= cpu.o interrupts.o sysid.o traps.o
 obj-y	+= fdt.o
arch/nios2/cpu/timer.c deleted +0 -65

65 lines not on this page · raw message

common/board_f.c +1 -2
index d0a9ff7..613332e 100644
@@ -795,8 +795,7 @@ static init_fnc_t init_sequence_f[] = {
 	init_timebase,
 #endif
 #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
-    defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
-    defined(CONFIG_NIOS2)
+		defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32)
 	timer_init,		/* initialize timer */
 #endif
 #ifdef CONFIG_SYS_ALLOC_DPRAM
configs/nios2-generic_defconfig +2 -0
index 707ee33..dac0b62 100644
@@ -18,3 +18,5 @@ CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
+CONFIG_DM_TIMER=y
+CONFIG_ALTERA_TIMER=y
doc/device-tree-bindings/timer/altera_timer.txt new file +19 -0
new file mode 100644
index 0000000..904a584
@@ -0,0 +1,19 @@
+Altera Timer
+
+Required properties:
+
+- compatible : should be "altr,timer-1.0"
+- reg : Specifies base physical address and size of the registers.
+- interrupt-parent: phandle of the interrupt controller
+- interrupts : Should contain the timer interrupt number
+- clock-frequency : The frequency of the clock that drives the counter, in Hz.
+
+Example:
+
+timer {
+	compatible = "altr,timer-1.0";
+	reg = <0x00400000 0x00000020>;
+	interrupt-parent = <&cpu>;
+	interrupts = <11>;
+	clock-frequency = <125000000>;
+};
drivers/timer/Kconfig +7 -0
index 5228e26..5a5558d 100644
@@ -8,4 +8,11 @@ config DM_TIMER
 	  lib/time.c. But now implemented by the uclass. The first timer
 	  will be used.
 
+config ALTERA_TIMER
+	bool "Altera Timer support"
+	depends on DM_TIMER
+	help
+	  Select this to enable an timer for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 endmenu
drivers/timer/Makefile +1 -0
index a24179a..0c7398f 100644
@@ -5,3 +5,4 @@
 #
 
 obj-$(CONFIG_DM_TIMER)		+= timer-uclass.o
+obj-$(CONFIG_ALTERA_TIMER)	+= altera_timer.o
drivers/timer/altera_timer.c new file +110 -0

110 lines not on this page · raw message

include/configs/nios2-generic.h +0 -6
index 90ccbd1..ae19676 100644
@@ -27,12 +27,6 @@
 #define CONFIG_SYS_CONSOLE_INFO_QUIET	/* Suppress console info */
 
 /*
- * TIMER
- */
-#define CONFIG_SYS_TIMER_COUNTS_DOWN
-#define CONFIG_SYS_TIMER_RATE		CONFIG_SYS_TIMER_FREQ
-
-/*
  * BOOTP options
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
Signature · 1 line
2.1.4
#12 lore raw

PATCH v3 1/2 dm: implement a Timer uclass

In reply to Thomas Chou

Hi Thomas,

Quoted 13 lines · Thomas Chou

Implement a Timer uclass to work with lib/time.c.

---
v2
fix coding style.
v3
add description to Kconfig as Simon suggested.
move timer.c code to lib/time.c.
add dm_timer dev to global data.
remove timer_init().
change API name get_clock.

Quoted 15 lines
 common/board_r.c                  |  3 +++
 drivers/Kconfig                   |  2 ++
 drivers/Makefile                  |  1 +
 drivers/timer/Kconfig             | 11 ++++++++
 drivers/timer/Makefile            |  7 +++++
 drivers/timer/timer-uclass.c      | 35 +++++++++++++++++++++++++
 include/asm-generic/global_data.h |  3 +++
 include/dm/uclass-id.h            |  1 +
 include/timer.h                   | 52 +++++++++++++++++++++++++++++++++++++
 lib/time.c                        | 54 +++++++++++++++++++++++++++++++++++++++
 10 files changed, 169 insertions(+)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 include/timer.h

Please see one nit below.

Quoted 85 lines
common/board_r.c +3 -0
index f8c1baa..aaf390e 100644
@@ -290,6 +290,9 @@ static int initr_dm(void)
        /* Save the pre-reloc driver model and start a new one */
        gd->dm_root_f = gd->dm_root;
        gd->dm_root = NULL;
+#ifdef CONFIG_DM_TIMER
+       gd->dm_timer = NULL;
+#endif
        return dm_init_and_scan(false);
 }
 #endif
drivers/Kconfig +2 -0
index 63c92c5..f9496f7 100644
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
drivers/Makefile +1 -0
index 9d0a595..692da78 100644
@@ -48,6 +48,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
 obj-y += video/
drivers/timer/Kconfig new file +11 -0
new file mode 100644
index 0000000..5228e26
@@ -0,0 +1,11 @@
+menu "Timer Support"
+
+config DM_TIMER
+       bool "Enable Driver Model for Timer drivers"
+       depends on DM
+       help
+         Enable driver model for Timer access. It uses the same API as
+         lib/time.c. But now implemented by the uclass. The first timer
+         will be used.
+
+endmenu
drivers/timer/Makefile new file +7 -0
new file mode 100644
index 0000000..a24179a
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2015 Thomas Chou <[email protected]>
+#
+# SPDX-License-Identifier:     GPL-2.0+
+#
+
+obj-$(CONFIG_DM_TIMER)         += timer-uclass.o
drivers/timer/timer-uclass.c new file +9 -0
new file mode 100644
index 0000000..8071fcc
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>

drivers/timer/timer-uclass.c line 19

Quoted 10 lines
drivers/timer/timer-uclass.c new file +10 -0
+#include <timer.h>
+
+int timer_get_count(struct udevice *dev, unsigned long *count)
+{
+       const struct dm_timer_ops *ops = device_get_ops(dev);
+
+       if (!ops->get_count)
+               return -ENOSYS;
+
+       return ops->get_count(dev, count);

I'm not too keen on get_count(). Isn't this required to be in milliiseconds now? If so, how about get_ms()?

drivers/timer/timer-uclass.c line 29

Quoted 10 lines
drivers/timer/timer-uclass.c new file +10 -0
+}
+
+int timer_get_clock(struct udevice *dev, unsigned long *freq)
+{
+       const struct dm_timer_ops *ops = device_get_ops(dev);
+
+       if (!ops->get_clock)
+               return -ENOSYS;
+
+       return ops->get_clock(dev, freq);

Isn't this always 1000?

Quoted 105 lines
drivers/timer/timer-uclass.c new file +6 -0
+}
+
+UCLASS_DRIVER(timer) = {
+       .id             = UCLASS_TIMER,
+       .name           = "timer",
+};
include/asm-generic/global_data.h +3 -0
index 2155265..ebecb5f 100644
@@ -69,6 +69,9 @@ typedef struct global_data {
        struct udevice  *dm_root_f;     /* Pre-relocation root instance */
        struct list_head uclass_root;   /* Head of core tree */
 #endif
+#ifdef CONFIG_DM_TIMER
+       struct udevice  *dm_timer;      /* Timer instance for Driver Model */
+#endif
 
        const void *fdt_blob;   /* Our device tree, NULL if none */
        void *new_fdt;          /* Relocated FDT */
include/dm/uclass-id.h +1 -0
index 1eeec74..aff34a4 100644
@@ -56,6 +56,7 @@ enum uclass_id {
        UCLASS_SPI_GENERIC,     /* Generic SPI flash target */
        UCLASS_SYSCON,          /* System configuration device */
        UCLASS_THERMAL,         /* Thermal sensor */
+       UCLASS_TIMER,           /* Timer device */
        UCLASS_TPM,             /* Trusted Platform Module TIS interface */
        UCLASS_USB,             /* USB bus */
        UCLASS_USB_DEV_GENERIC, /* USB generic device */
include/timer.h new file +52 -0
new file mode 100644
index 0000000..c18a195
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef _DM_TIMER_H_
+#define _DM_TIMER_H_
+
+/*
+ * Get the current timer count
+ *
+ * @dev: The Timer device
+ * @count: pointer that returns the current timer count
+ * @return: 0 if OK, -ve on error
+ */
+int timer_get_count(struct udevice *dev, unsigned long *count);
+/*
+ * Get the timer input clock frequency
+ *
+ * @dev: The Timer device
+ * @freq: pointer that returns the timer clock frequency
+ * @return: 0 if OK, -ve on error
+ */
+int timer_get_clock(struct udevice *dev, unsigned long *freq);
+
+/*
+ * struct dm_timer_ops - Driver model Timer operations
+ *
+ * The uclass interface is implemented by all Timer devices which use
+ * driver model.
+ */
+struct dm_timer_ops {
+       /*
+        * Get the current timer count
+        *
+        * @dev: The Timer device
+        * @count: pointer that returns the current timer count
+        * @return: 0 if OK, -ve on error
+        */
+       int (*get_count)(struct udevice *dev, unsigned long *count);
+       /*
+        * Get the timer input clock frequency
+        *
+        * @dev: The Timer device
+        * @freq: pointer that returns the timer clock frequency
+        * @return: 0 if OK, -ve on error
+        */
+       int (*get_clock)(struct udevice *dev, unsigned long *freq);
+};
+
+#endif /* _DM_TIMER_H_ */
lib/time.c +3 -0
index 477440d..6b7342e 100644
@@ -6,6 +6,9 @@
  */
 
 #include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <timer.h>
 #include <watchdog.h>
 #include <div64.h>
 #include <asm/io.h>

lib/time.c unsigned long notrace timer_read_counter(void) · line 44

Quoted 5 lines
lib/time.c +2 -0
@@ -37,6 +40,57 @@ unsigned long notrace timer_read_counter(void)
 extern unsigned long __weak timer_read_counter(void);
 #endif
 
+#ifdef CONFIG_DM_TIMER
+static int dm_timer_init(void)

nit: need notrace on this one too.

Quoted 53 lines
lib/time.c +49 -1
+{
+       struct udevice *dev;
+       int ret;
+
+       if (!gd->dm_timer) {
+               ret = uclass_first_device(UCLASS_TIMER, &dev);
+               if (ret)
+                       return ret;
+               if (!dev)
+                       return -ENODEV;
+               gd->dm_timer = dev;
+       }
+
+       return 0;
+}
+
+ulong notrace get_tbclk(void)
+{
+       unsigned long freq;
+       int ret;
+
+       ret = dm_timer_init();
+       if (ret)
+               return ret;
+
+       ret = timer_get_clock(gd->dm_timer, &freq);
+       if (ret)
+               return ret;
+
+       return freq;
+}
+
+unsigned long notrace timer_read_counter(void)
+{
+       unsigned long count;
+       int ret;
+
+       ret = dm_timer_init();
+       if (ret)
+               return ret;
+
+       ret = timer_get_count(gd->dm_timer, &count);
+       if (ret)
+               return ret;
+
+       return count;
+}
+#endif /* CONFIG_DM_TIMER */
+
 uint64_t __weak notrace get_ticks(void)
 {
        unsigned long now = timer_read_counter();
--
Quoted 2 lines

2.1.4

Regards,
Simon

#13 lore raw

PATCH v3 1/2 dm: implement a Timer uclass

Hi Simon,

Quoted 5 lines · Simon Glass
Quoted 1 line

+ return ops->get_count(dev, count);

I'm not too keen on get_count(). Isn't this required to be in milliiseconds now? If so, how about get_ms()?

Quoted 13 lines

drivers/timer/timer-uclass.c line 29

Quoted 10 lines
drivers/timer/timer-uclass.c new file +10 -0
+}
+
+int timer_get_clock(struct udevice *dev, unsigned long *freq)
+{
+       const struct dm_timer_ops *ops = device_get_ops(dev);
+
+       if (!ops->get_clock)
+               return -ENOSYS;
+
+       return ops->get_clock(dev, freq);

Isn't this always 1000?

I will add a more specific comment on the uclass.

Implement a Timer uclass to work with lib/time.c. The timer is usually a 32 bits free-running up counter. The get_clock() method is used to get the input clock frequency of the timer. The get_count() method is used get the current 32 bits count value. If the hardware is counting down, the value should be inversed inside the method. There is no real tick, and no timer interrupt.

Ex, the altera timer of nois2 reference design runs at 125MHz and the down counter value is inversed inside the get_count() method.

Thanks again for your review.

Best regards,
Thomas Chou

#14 lore raw

PATCH v4 1/2 dm: implement a Timer uclass

In reply to Thomas Chou

Implement a Timer uclass to work with lib/time.c.

---
v2
fix coding style.
v3
add description to Kconfig as Simon suggested.
move timer.c code to lib/time.c.
add dm_timer dev to global data.
remove timer_init().
change API name get_clock.
v4
add comment about timer hardware.

 common/board_r.c                  |  3 +++
 drivers/Kconfig                   |  2 ++
 drivers/Makefile                  |  1 +
 drivers/timer/Kconfig             | 12 +++++++++
 drivers/timer/Makefile            |  7 +++++
 drivers/timer/timer-uclass.c      | 44 +++++++++++++++++++++++++++++++
 include/asm-generic/global_data.h |  3 +++
 include/dm/uclass-id.h            |  1 +
 include/timer.h                   | 52 +++++++++++++++++++++++++++++++++++++
 lib/time.c                        | 54 +++++++++++++++++++++++++++++++++++++++
 10 files changed, 179 insertions(+)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 include/timer.h
common/board_r.c +3 -0
index f8c1baa..aaf390e 100644
@@ -290,6 +290,9 @@ static int initr_dm(void)
 	/* Save the pre-reloc driver model and start a new one */
 	gd->dm_root_f = gd->dm_root;
 	gd->dm_root = NULL;
+#ifdef CONFIG_DM_TIMER
+	gd->dm_timer = NULL;
+#endif
 	return dm_init_and_scan(false);
 }
 #endif
drivers/Kconfig +2 -0
index 63c92c5..f9496f7 100644
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
drivers/Makefile +1 -0
index 9d0a595..692da78 100644
@@ -48,6 +48,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
 obj-y += video/
drivers/timer/Kconfig new file +12 -0
new file mode 100644
index 0000000..54a4c40
@@ -0,0 +1,12 @@
+menu "Timer Support"
+
+config DM_TIMER
+	bool "Enable Driver Model for Timer drivers"
+	depends on DM
+	help
+	  Enable driver model for Timer access. It uses the same API as
+	  lib/time.c. But now implemented by the uclass. The first timer
+	  will be used. The timer is usually a 32 bits free-running up
+	  counter. There may be no real tick, and no timer interrupt.
+
+endmenu
drivers/timer/Makefile new file +7 -0
new file mode 100644
index 0000000..a24179a
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2015 Thomas Chou <[email protected]>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_DM_TIMER)		+= timer-uclass.o
drivers/timer/timer-uclass.c new file +44 -0

44 lines not on this page · raw message

include/asm-generic/global_data.h +3 -0
index 2155265..ebecb5f 100644
@@ -69,6 +69,9 @@ typedef struct global_data {
 	struct udevice	*dm_root_f;	/* Pre-relocation root instance */
 	struct list_head uclass_root;	/* Head of core tree */
 #endif
+#ifdef CONFIG_DM_TIMER
+	struct udevice	*dm_timer;	/* Timer instance for Driver Model */
+#endif
 
 	const void *fdt_blob;	/* Our device tree, NULL if none */
 	void *new_fdt;		/* Relocated FDT */
include/dm/uclass-id.h +1 -0
index 1eeec74..aff34a4 100644
@@ -56,6 +56,7 @@ enum uclass_id {
 	UCLASS_SPI_GENERIC,	/* Generic SPI flash target */
 	UCLASS_SYSCON,		/* System configuration device */
 	UCLASS_THERMAL,		/* Thermal sensor */
+	UCLASS_TIMER,		/* Timer device */
 	UCLASS_TPM,		/* Trusted Platform Module TIS interface */
 	UCLASS_USB,		/* USB bus */
 	UCLASS_USB_DEV_GENERIC,	/* USB generic device */
include/timer.h new file +52 -0

52 lines not on this page · raw message

lib/time.c +54 -0

66 lines not on this page · raw message

Signature · 1 line
2.1.4
#15 lore raw

PATCH v4 2/2 nios2: convert altera timer to driver model

Convert altera timer to driver model.

---
v2
fix coding style.
v3
doc dts binding.
v4
no change.

 arch/nios2/cpu/Makefile                         |   2 +-
 arch/nios2/cpu/timer.c                          |  65 --------------
 common/board_f.c                                |   3 +-
 configs/nios2-generic_defconfig                 |   2 +
 doc/device-tree-bindings/timer/altera_timer.txt |  19 ++++
 drivers/timer/Kconfig                           |   7 ++
 drivers/timer/Makefile                          |   1 +
 drivers/timer/altera_timer.c                    | 110 ++++++++++++++++++++++++
 include/configs/nios2-generic.h                 |   6 --
 9 files changed, 141 insertions(+), 74 deletions(-)
 delete mode 100644 arch/nios2/cpu/timer.c
 create mode 100644 doc/device-tree-bindings/timer/altera_timer.txt
 create mode 100644 drivers/timer/altera_timer.c
arch/nios2/cpu/Makefile +1 -1
index c85e261..3fe7847 100644
@@ -7,5 +7,5 @@
 
 extra-y	= start.o
 obj-y	= exceptions.o
-obj-y	+= cpu.o interrupts.o sysid.o timer.o traps.o
+obj-y	+= cpu.o interrupts.o sysid.o traps.o
 obj-y	+= fdt.o
arch/nios2/cpu/timer.c deleted +0 -65

65 lines not on this page · raw message

common/board_f.c +1 -2
index d0a9ff7..613332e 100644
@@ -795,8 +795,7 @@ static init_fnc_t init_sequence_f[] = {
 	init_timebase,
 #endif
 #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
-    defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
-    defined(CONFIG_NIOS2)
+		defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32)
 	timer_init,		/* initialize timer */
 #endif
 #ifdef CONFIG_SYS_ALLOC_DPRAM
configs/nios2-generic_defconfig +2 -0
index 707ee33..dac0b62 100644
@@ -18,3 +18,5 @@ CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
+CONFIG_DM_TIMER=y
+CONFIG_ALTERA_TIMER=y
doc/device-tree-bindings/timer/altera_timer.txt new file +19 -0
new file mode 100644
index 0000000..904a584
@@ -0,0 +1,19 @@
+Altera Timer
+
+Required properties:
+
+- compatible : should be "altr,timer-1.0"
+- reg : Specifies base physical address and size of the registers.
+- interrupt-parent: phandle of the interrupt controller
+- interrupts : Should contain the timer interrupt number
+- clock-frequency : The frequency of the clock that drives the counter, in Hz.
+
+Example:
+
+timer {
+	compatible = "altr,timer-1.0";
+	reg = <0x00400000 0x00000020>;
+	interrupt-parent = <&cpu>;
+	interrupts = <11>;
+	clock-frequency = <125000000>;
+};
drivers/timer/Kconfig +7 -0
index 54a4c40..f1e681c 100644
@@ -9,4 +9,11 @@ config DM_TIMER
 	  will be used. The timer is usually a 32 bits free-running up
 	  counter. There may be no real tick, and no timer interrupt.
 
+config ALTERA_TIMER
+	bool "Altera Timer support"
+	depends on DM_TIMER
+	help
+	  Select this to enable an timer for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 endmenu
drivers/timer/Makefile +1 -0
index a24179a..0c7398f 100644
@@ -5,3 +5,4 @@
 #
 
 obj-$(CONFIG_DM_TIMER)		+= timer-uclass.o
+obj-$(CONFIG_ALTERA_TIMER)	+= altera_timer.o
drivers/timer/altera_timer.c new file +110 -0

110 lines not on this page · raw message

include/configs/nios2-generic.h +0 -6
index 90ccbd1..ae19676 100644
@@ -27,12 +27,6 @@
 #define CONFIG_SYS_CONSOLE_INFO_QUIET	/* Suppress console info */
 
 /*
- * TIMER
- */
-#define CONFIG_SYS_TIMER_COUNTS_DOWN
-#define CONFIG_SYS_TIMER_RATE		CONFIG_SYS_TIMER_FREQ
-
-/*
  * BOOTP options
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
Signature · 1 line
2.1.4
#16 lore raw

PATCH v4 2/2 nios2: convert altera timer to driver model

Hi,

Quoted 11 lines · thomas at wytron.com.tw

Convert altera timer to driver model.

---
v2
fix coding style.
v3
doc dts binding.
v4
no change.

Quoted 14 lines
 arch/nios2/cpu/Makefile                         |   2 +-
 arch/nios2/cpu/timer.c                          |  65 --------------
 common/board_f.c                                |   3 +-
 configs/nios2-generic_defconfig                 |   2 +
 doc/device-tree-bindings/timer/altera_timer.txt |  19 ++++
 drivers/timer/Kconfig                           |   7 ++
 drivers/timer/Makefile                          |   1 +
 drivers/timer/altera_timer.c                    | 110 ++++++++++++++++++++++++
 include/configs/nios2-generic.h                 |   6 --
 9 files changed, 141 insertions(+), 74 deletions(-)
 delete mode 100644 arch/nios2/cpu/timer.c
 create mode 100644 doc/device-tree-bindings/timer/altera_timer.txt
 create mode 100644 drivers/timer/altera_timer.c

Thanks
Chin Liang

#17 lore raw

PATCH v4 1/2 dm: implement a Timer uclass

In reply to Thomas Chou

Hi Thomas,

Quoted 4 lines · Thomas Chou

Implement a Timer uclass to work with lib/time.c.

Sorry, after a lot of consideration I'd like to retract that :-(

Please see below.

Quoted 12 lines

---
v2
fix coding style.
v3
add description to Kconfig as Simon suggested.
move timer.c code to lib/time.c.
add dm_timer dev to global data.
remove timer_init().
change API name get_clock.
v4
add comment about timer hardware.

Quoted 15 lines
 common/board_r.c                  |  3 +++
 drivers/Kconfig                   |  2 ++
 drivers/Makefile                  |  1 +
 drivers/timer/Kconfig             | 12 +++++++++
 drivers/timer/Makefile            |  7 +++++
 drivers/timer/timer-uclass.c      | 44 +++++++++++++++++++++++++++++++
 include/asm-generic/global_data.h |  3 +++
 include/dm/uclass-id.h            |  1 +
 include/timer.h                   | 52 +++++++++++++++++++++++++++++++++++++
 lib/time.c                        | 54 +++++++++++++++++++++++++++++++++++++++
 10 files changed, 179 insertions(+)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 include/timer.h

Can you please split this into a patch that adds the uclass and one that plumbs it into board_r.c?

Also can you add a patch with a sandbox timer driver and a test (in test/dm) for the timer?

Quoted 98 lines
common/board_r.c +3 -0
index f8c1baa..aaf390e 100644
@@ -290,6 +290,9 @@ static int initr_dm(void)
        /* Save the pre-reloc driver model and start a new one */
        gd->dm_root_f = gd->dm_root;
        gd->dm_root = NULL;
+#ifdef CONFIG_DM_TIMER
+       gd->dm_timer = NULL;
+#endif
        return dm_init_and_scan(false);
 }
 #endif
drivers/Kconfig +2 -0
index 63c92c5..f9496f7 100644
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
drivers/Makefile +1 -0
index 9d0a595..692da78 100644
@@ -48,6 +48,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
 obj-y += video/
drivers/timer/Kconfig new file +12 -0
new file mode 100644
index 0000000..54a4c40
@@ -0,0 +1,12 @@
+menu "Timer Support"
+
+config DM_TIMER
+       bool "Enable Driver Model for Timer drivers"
+       depends on DM
+       help
+         Enable driver model for Timer access. It uses the same API as
+         lib/time.c. But now implemented by the uclass. The first timer
+         will be used. The timer is usually a 32 bits free-running up
+         counter. There may be no real tick, and no timer interrupt.
+
+endmenu
drivers/timer/Makefile new file +7 -0
new file mode 100644
index 0000000..a24179a
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2015 Thomas Chou <[email protected]>
+#
+# SPDX-License-Identifier:     GPL-2.0+
+#
+
+obj-$(CONFIG_DM_TIMER)         += timer-uclass.o
drivers/timer/timer-uclass.c new file +21 -0
new file mode 100644
index 0000000..bcf1dde
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <timer.h>
+
+/*
+ * Implement a Timer uclass to work with lib/time.c. The timer is usually
+ * a 32 bits free-running up counter. The get_clock() method is used to get
+ * the input clock frequency of the timer. The get_count() method is used
+ * get the current 32 bits count value. If the hardware is counting down,
+ * the value should be inversed inside the method. There may be no real
+ * tick, and no timer interrupt.
+ */
+
+int timer_get_count(struct udevice *dev, unsigned long *count)

drivers/timer/timer-uclass.c line 31

Quoted 10 lines
drivers/timer/timer-uclass.c new file +10 -0
+{
+       const struct dm_timer_ops *ops = device_get_ops(dev);
+
+       if (!ops->get_count)
+               return -ENOSYS;
+
+       return ops->get_count(dev, count);
+}
+
+int timer_get_clock(struct udevice *dev, unsigned long *freq)

Probably timer_get_rate() is better - we yes it has a clock but it is the clock rate that we are returning.

Isn't the frequency always the same for a given timer? I think this should be stored in the uclass private data. The timer could do this in its probe function. Then this function can just return that value rather than needing a driver method:

unsigned long timer_get_rate(struct udevice *dev) {
struct uc_priv *priv = dev_get_uclass_pric(dev);

return priv->clock_rate;
}

Quoted 170 lines
drivers/timer/timer-uclass.c new file +13 -0
+{
+       const struct dm_timer_ops *ops = device_get_ops(dev);
+
+       if (!ops->get_clock)
+               return -ENOSYS;
+
+       return ops->get_clock(dev, freq);
+}
+
+UCLASS_DRIVER(timer) = {
+       .id             = UCLASS_TIMER,
+       .name           = "timer",
+};
include/asm-generic/global_data.h +3 -0
index 2155265..ebecb5f 100644
@@ -69,6 +69,9 @@ typedef struct global_data {
        struct udevice  *dm_root_f;     /* Pre-relocation root instance */
        struct list_head uclass_root;   /* Head of core tree */
 #endif
+#ifdef CONFIG_DM_TIMER
+       struct udevice  *dm_timer;      /* Timer instance for Driver Model */
+#endif
 
        const void *fdt_blob;   /* Our device tree, NULL if none */
        void *new_fdt;          /* Relocated FDT */
include/dm/uclass-id.h +1 -0
index 1eeec74..aff34a4 100644
@@ -56,6 +56,7 @@ enum uclass_id {
        UCLASS_SPI_GENERIC,     /* Generic SPI flash target */
        UCLASS_SYSCON,          /* System configuration device */
        UCLASS_THERMAL,         /* Thermal sensor */
+       UCLASS_TIMER,           /* Timer device */
        UCLASS_TPM,             /* Trusted Platform Module TIS interface */
        UCLASS_USB,             /* USB bus */
        UCLASS_USB_DEV_GENERIC, /* USB generic device */
include/timer.h new file +52 -0
new file mode 100644
index 0000000..c18a195
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#ifndef _DM_TIMER_H_
+#define _DM_TIMER_H_
+
+/*
+ * Get the current timer count
+ *
+ * @dev: The Timer device
+ * @count: pointer that returns the current timer count
+ * @return: 0 if OK, -ve on error
+ */
+int timer_get_count(struct udevice *dev, unsigned long *count);
+/*
+ * Get the timer input clock frequency
+ *
+ * @dev: The Timer device
+ * @freq: pointer that returns the timer clock frequency
+ * @return: 0 if OK, -ve on error
+ */
+int timer_get_clock(struct udevice *dev, unsigned long *freq);
+
+/*
+ * struct dm_timer_ops - Driver model Timer operations
+ *
+ * The uclass interface is implemented by all Timer devices which use
+ * driver model.
+ */
+struct dm_timer_ops {
+       /*
+        * Get the current timer count
+        *
+        * @dev: The Timer device
+        * @count: pointer that returns the current timer count
+        * @return: 0 if OK, -ve on error
+        */
+       int (*get_count)(struct udevice *dev, unsigned long *count);
+       /*
+        * Get the timer input clock frequency
+        *
+        * @dev: The Timer device
+        * @freq: pointer that returns the timer clock frequency
+        * @return: 0 if OK, -ve on error
+        */
+       int (*get_clock)(struct udevice *dev, unsigned long *freq);
+};
+
+#endif /* _DM_TIMER_H_ */
lib/time.c +54 -1
index 477440d..ba063cf 100644
@@ -6,6 +6,9 @@
  */
 
 #include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <timer.h>
 #include <watchdog.h>
 #include <div64.h>
 #include <asm/io.h>
@@ -37,6 +40,57 @@ unsigned long notrace timer_read_counter(void)
 extern unsigned long __weak timer_read_counter(void);
 #endif
 
+#ifdef CONFIG_DM_TIMER
+static int notrace dm_timer_init(void)
+{
+       struct udevice *dev;
+       int ret;
+
+       if (!gd->dm_timer) {
+               ret = uclass_first_device(UCLASS_TIMER, &dev);
+               if (ret)
+                       return ret;
+               if (!dev)
+                       return -ENODEV;
+               gd->dm_timer = dev;
+       }
+
+       return 0;
+}
+
+ulong notrace get_tbclk(void)
+{
+       unsigned long freq;
+       int ret;
+
+       ret = dm_timer_init();
+       if (ret)
+               return ret;
+
+       ret = timer_get_clock(gd->dm_timer, &freq);
+       if (ret)
+               return ret;
+
+       return freq;
+}
+
+unsigned long notrace timer_read_counter(void)
+{
+       unsigned long count;
+       int ret;
+
+       ret = dm_timer_init();
+       if (ret)
+               return ret;
+
+       ret = timer_get_count(gd->dm_timer, &count);
+       if (ret)
+               return ret;
+
+       return count;
+}
+#endif /* CONFIG_DM_TIMER */
+
 uint64_t __weak notrace get_ticks(void)
 {
        unsigned long now = timer_read_counter();
--
Quoted 2 lines

2.1.4

Regards,
Simon

#18 lore raw

PATCH v4 1/2 dm: implement a Timer uclass

Hi Simon,

Quoted 11 lines · Simon Glass

Hi Thomas,

Quoted 4 lines · Thomas Chou

Implement a Timer uclass to work with lib/time.c.

Sorry, after a lot of consideration I'd like to retract that :-(

Please see below.

No worries. Your nits are welcome.

Quoted 2 lines

Also can you add a patch with a sandbox timer driver and a test (in test/dm) for the timer?

I didn't try sandbox before. I will learn sandbox and test. Then submit a patch for a sandbox timer driver.

Best regards,
Thomas

#19 lore raw

PATCH v5 1/3 dm: implement a Timer uclass

In reply to Thomas Chou

Implement a Timer uclass to work with lib/time.c.

---
v2
fix coding style.
v3
add description to Kconfig as Simon suggested.
move timer.c code to lib/time.c.
add dm_timer dev to global data.
remove timer_init().
change API name get_clock.
v4
add comment about timer hardware.
v5
revert to get_rate and use uclass priv to store the clock_rate. split gd->dm_timer renewal to anohter patch.

 drivers/Kconfig                   |  2 ++
 drivers/Makefile                  |  1 +
 drivers/timer/Kconfig             | 12 +++++++++
 drivers/timer/Makefile            |  7 ++++++
 drivers/timer/timer-uclass.c      | 42 +++++++++++++++++++++++++++++++
 include/asm-generic/global_data.h |  3 +++
 include/dm/uclass-id.h            |  1 +
 include/timer.h                   | 52 +++++++++++++++++++++++++++++++++++++++
 lib/time.c                        | 49 ++++++++++++++++++++++++++++++++++++
 9 files changed, 169 insertions(+)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 include/timer.h
drivers/Kconfig +2 -0
index 63c92c5..f9496f7 100644
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
drivers/Makefile +1 -0
index 9d0a595..692da78 100644
@@ -48,6 +48,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
 obj-y += video/
drivers/timer/Kconfig new file +12 -0
new file mode 100644
index 0000000..54a4c40
@@ -0,0 +1,12 @@
+menu "Timer Support"
+
+config DM_TIMER
+	bool "Enable Driver Model for Timer drivers"
+	depends on DM
+	help
+	  Enable driver model for Timer access. It uses the same API as
+	  lib/time.c. But now implemented by the uclass. The first timer
+	  will be used. The timer is usually a 32 bits free-running up
+	  counter. There may be no real tick, and no timer interrupt.
+
+endmenu
drivers/timer/Makefile new file +7 -0
new file mode 100644
index 0000000..a24179a
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2015 Thomas Chou <[email protected]>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_DM_TIMER)		+= timer-uclass.o
drivers/timer/timer-uclass.c new file +42 -0

42 lines not on this page · raw message

include/asm-generic/global_data.h +3 -0
index 2155265..ebecb5f 100644
@@ -69,6 +69,9 @@ typedef struct global_data {
 	struct udevice	*dm_root_f;	/* Pre-relocation root instance */
 	struct list_head uclass_root;	/* Head of core tree */
 #endif
+#ifdef CONFIG_DM_TIMER
+	struct udevice	*dm_timer;	/* Timer instance for Driver Model */
+#endif
 
 	const void *fdt_blob;	/* Our device tree, NULL if none */
 	void *new_fdt;		/* Relocated FDT */
include/dm/uclass-id.h +1 -0
index 1eeec74..aff34a4 100644
@@ -56,6 +56,7 @@ enum uclass_id {
 	UCLASS_SPI_GENERIC,	/* Generic SPI flash target */
 	UCLASS_SYSCON,		/* System configuration device */
 	UCLASS_THERMAL,		/* Thermal sensor */
+	UCLASS_TIMER,		/* Timer device */
 	UCLASS_TPM,		/* Trusted Platform Module TIS interface */
 	UCLASS_USB,		/* USB bus */
 	UCLASS_USB_DEV_GENERIC,	/* USB generic device */
include/timer.h new file +52 -0

52 lines not on this page · raw message

lib/time.c +49 -0

61 lines not on this page · raw message

Signature · 1 line
2.1.4
#20 lore raw

PATCH v5 2/3 timer: start a new dm_timer after relocation

Start a new dm_timer after relocation, just in case the timer has been used in per-relocation.

---
 common/board_r.c | 3 +++
 1 file changed, 3 insertions(+)
common/board_r.c +3 -0
index f8c1baa..aaf390e 100644
@@ -290,6 +290,9 @@ static int initr_dm(void)
 	/* Save the pre-reloc driver model and start a new one */
 	gd->dm_root_f = gd->dm_root;
 	gd->dm_root = NULL;
+#ifdef CONFIG_DM_TIMER
+	gd->dm_timer = NULL;
+#endif
 	return dm_init_and_scan(false);
 }
 #endif
Signature · 1 line
2.1.4
#22 lore raw

PATCH v5 3/3 nios2: convert altera timer to driver model

In reply to Thomas Chou

Convert altera timer to driver model.

---
v2
fix coding style.
v3
doc dts binding.
v4
no change.
v5
revert to get_rate and use uclass priv to store the clock_rate.

 arch/nios2/cpu/Makefile                         |   2 +-
 arch/nios2/cpu/timer.c                          |  65 ---------------
 common/board_f.c                                |   3 +-
 configs/nios2-generic_defconfig                 |   2 +
 doc/device-tree-bindings/timer/altera_timer.txt |  19 +++++
 drivers/timer/Kconfig                           |   7 ++
 drivers/timer/Makefile                          |   1 +
 drivers/timer/altera_timer.c                    | 103 ++++++++++++++++++++++++
 include/configs/nios2-generic.h                 |   6 --
 9 files changed, 134 insertions(+), 74 deletions(-)
 delete mode 100644 arch/nios2/cpu/timer.c
 create mode 100644 doc/device-tree-bindings/timer/altera_timer.txt
 create mode 100644 drivers/timer/altera_timer.c
arch/nios2/cpu/Makefile +1 -1
index c85e261..3fe7847 100644
@@ -7,5 +7,5 @@
 
 extra-y	= start.o
 obj-y	= exceptions.o
-obj-y	+= cpu.o interrupts.o sysid.o timer.o traps.o
+obj-y	+= cpu.o interrupts.o sysid.o traps.o
 obj-y	+= fdt.o
arch/nios2/cpu/timer.c deleted +0 -65

65 lines not on this page · raw message

common/board_f.c +1 -2
index d0a9ff7..613332e 100644
@@ -795,8 +795,7 @@ static init_fnc_t init_sequence_f[] = {
 	init_timebase,
 #endif
 #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
-    defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
-    defined(CONFIG_NIOS2)
+		defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32)
 	timer_init,		/* initialize timer */
 #endif
 #ifdef CONFIG_SYS_ALLOC_DPRAM
configs/nios2-generic_defconfig +2 -0
index 707ee33..dac0b62 100644
@@ -18,3 +18,5 @@ CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
+CONFIG_DM_TIMER=y
+CONFIG_ALTERA_TIMER=y
doc/device-tree-bindings/timer/altera_timer.txt new file +19 -0
new file mode 100644
index 0000000..904a584
@@ -0,0 +1,19 @@
+Altera Timer
+
+Required properties:
+
+- compatible : should be "altr,timer-1.0"
+- reg : Specifies base physical address and size of the registers.
+- interrupt-parent: phandle of the interrupt controller
+- interrupts : Should contain the timer interrupt number
+- clock-frequency : The frequency of the clock that drives the counter, in Hz.
+
+Example:
+
+timer {
+	compatible = "altr,timer-1.0";
+	reg = <0x00400000 0x00000020>;
+	interrupt-parent = <&cpu>;
+	interrupts = <11>;
+	clock-frequency = <125000000>;
+};
drivers/timer/Kconfig +7 -0
index 54a4c40..f1e681c 100644
@@ -9,4 +9,11 @@ config DM_TIMER
 	  will be used. The timer is usually a 32 bits free-running up
 	  counter. There may be no real tick, and no timer interrupt.
 
+config ALTERA_TIMER
+	bool "Altera Timer support"
+	depends on DM_TIMER
+	help
+	  Select this to enable an timer for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 endmenu
drivers/timer/Makefile +1 -0
index a24179a..0c7398f 100644
@@ -5,3 +5,4 @@
 #
 
 obj-$(CONFIG_DM_TIMER)		+= timer-uclass.o
+obj-$(CONFIG_ALTERA_TIMER)	+= altera_timer.o
drivers/timer/altera_timer.c new file +103 -0

103 lines not on this page · raw message

include/configs/nios2-generic.h +0 -6
index 90ccbd1..ae19676 100644
@@ -27,12 +27,6 @@
 #define CONFIG_SYS_CONSOLE_INFO_QUIET	/* Suppress console info */
 
 /*
- * TIMER
- */
-#define CONFIG_SYS_TIMER_COUNTS_DOWN
-#define CONFIG_SYS_TIMER_RATE		CONFIG_SYS_TIMER_FREQ
-
-/*
  * BOOTP options
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
Signature · 1 line
2.1.4
#23 lore raw

PATCH v5 1/3 dm: implement a Timer uclass

In reply to Thomas Chou

Hi Thomas,

Quoted 19 lines · Thomas Chou

Implement a Timer uclass to work with lib/time.c.

---
v2
fix coding style.
v3
add description to Kconfig as Simon suggested.
move timer.c code to lib/time.c.
add dm_timer dev to global data.
remove timer_init().
change API name get_clock.
v4
add comment about timer hardware.
v5
revert to get_rate and use uclass priv to store the clock_rate. split gd->dm_timer renewal to anohter patch.

Quoted 14 lines
 drivers/Kconfig                   |  2 ++
 drivers/Makefile                  |  1 +
 drivers/timer/Kconfig             | 12 +++++++++
 drivers/timer/Makefile            |  7 ++++++
 drivers/timer/timer-uclass.c      | 42 +++++++++++++++++++++++++++++++
 include/asm-generic/global_data.h |  3 +++
 include/dm/uclass-id.h            |  1 +
 include/timer.h                   | 52 +++++++++++++++++++++++++++++++++++++++
 lib/time.c                        | 49 ++++++++++++++++++++++++++++++++++++
 9 files changed, 169 insertions(+)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 include/timer.h

Please see one last thing below.

Quoted 32 lines
drivers/Kconfig +2 -0
index 63c92c5..f9496f7 100644
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
drivers/Makefile +1 -0
index 9d0a595..692da78 100644
@@ -48,6 +48,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
 obj-y += video/
drivers/timer/Kconfig new file +0 -0
new file mode 100644
index 0000000..54a4c40

drivers/timer/Kconfig line 3

Quoted 3 lines
drivers/timer/Kconfig new file +3 -0
@@ -0,0 +1,12 @@
+menu "Timer Support"
+
+config DM_TIMER

One more little nit - this should be just 'TIMER'? All of the DM_... options will eventually be removed. They indicate that driver model is being used for a function. In your case, there is no legacy version so you can just omit the DM_.

drivers/timer/Kconfig line 12

Quoted 9 lines
drivers/timer/Kconfig new file +9 -0
+       bool "Enable Driver Model for Timer drivers"
+       depends on DM
+       help
+         Enable driver model for Timer access. It uses the same API as
+         lib/time.c. But now implemented by the uclass. The first timer
+         will be used. The timer is usually a 32 bits free-running up
+         counter. There may be no real tick, and no timer interrupt.
+
+endmenu

Regards,
Simon

#24 lore raw

PATCH v5 1/3 dm: implement a Timer uclass

Hi Simon,

Quoted 6 lines · Simon Glass
Quoted 1 line

+config DM_TIMER

One more little nit - this should be just 'TIMER'? All of the DM_... options will eventually be removed. They indicate that driver model is being used for a function. In your case, there is no legacy version so you can just omit the DM_.

Yes, I will use CONFIG_TIMER instead. Thanks a lot for your reviews.

Best regards,
Thomas

#25 lore raw

PATCH v6 1/3 dm: implement a Timer uclass

In reply to Thomas Chou

Implement a Timer uclass to work with lib/time.c.

---
v2
fix coding style.
v3
add description to Kconfig as Simon suggested.
move timer.c code to lib/time.c.
add dm_timer dev to global data.
remove timer_init().
change API name get_clock.
v4
add comment about timer hardware.
v5
revert to get_rate and use uclass priv to store the clock_rate. split gd->dm_timer renewal to anohter patch.
v6
rename to CONFIG_TIMER as Simon suggested.

 drivers/Kconfig                   |  2 ++
 drivers/Makefile                  |  1 +
 drivers/timer/Kconfig             | 12 +++++++++
 drivers/timer/Makefile            |  7 ++++++
 drivers/timer/timer-uclass.c      | 42 +++++++++++++++++++++++++++++++
 include/asm-generic/global_data.h |  3 +++
 include/dm/uclass-id.h            |  1 +
 include/timer.h                   | 52 +++++++++++++++++++++++++++++++++++++++
 lib/time.c                        | 49 ++++++++++++++++++++++++++++++++++++
 9 files changed, 169 insertions(+)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 include/timer.h
drivers/Kconfig +2 -0
index 63c92c5..f9496f7 100644
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
drivers/Makefile +1 -0
index 9d0a595..692da78 100644
@@ -48,6 +48,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
 obj-y += video/
drivers/timer/Kconfig new file +12 -0
new file mode 100644
index 0000000..8e8d600
@@ -0,0 +1,12 @@
+menu "Timer Support"
+
+config TIMER
+	bool "Enable Driver Model for Timer drivers"
+	depends on DM
+	help
+	  Enable driver model for Timer access. It uses the same API as
+	  lib/time.c. But now implemented by the uclass. The first timer
+	  will be used. The timer is usually a 32 bits free-running up
+	  counter. There may be no real tick, and no timer interrupt.
+
+endmenu
drivers/timer/Makefile new file +7 -0
new file mode 100644
index 0000000..afb0009
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2015 Thomas Chou <[email protected]>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_TIMER)		+= timer-uclass.o
drivers/timer/timer-uclass.c new file +42 -0

42 lines not on this page · raw message

include/asm-generic/global_data.h +3 -0
index 2155265..4d109fb 100644
@@ -69,6 +69,9 @@ typedef struct global_data {
 	struct udevice	*dm_root_f;	/* Pre-relocation root instance */
 	struct list_head uclass_root;	/* Head of core tree */
 #endif
+#ifdef CONFIG_TIMER
+	struct udevice	*TIMER;	/* Timer instance for Driver Model */
+#endif
 
 	const void *fdt_blob;	/* Our device tree, NULL if none */
 	void *new_fdt;		/* Relocated FDT */
include/dm/uclass-id.h +1 -0
index 1eeec74..aff34a4 100644
@@ -56,6 +56,7 @@ enum uclass_id {
 	UCLASS_SPI_GENERIC,	/* Generic SPI flash target */
 	UCLASS_SYSCON,		/* System configuration device */
 	UCLASS_THERMAL,		/* Thermal sensor */
+	UCLASS_TIMER,		/* Timer device */
 	UCLASS_TPM,		/* Trusted Platform Module TIS interface */
 	UCLASS_USB,		/* USB bus */
 	UCLASS_USB_DEV_GENERIC,	/* USB generic device */
include/timer.h new file +52 -0

52 lines not on this page · raw message

lib/time.c +49 -0

61 lines not on this page · raw message

Signature · 1 line
2.1.4
#26 lore raw

PATCH v6 2/3 timer: start a new TIMER after relocation

Start a new TIMER after relocation, just in case the timer has been used in per-relocation.

---
v6
rename to CONFIG_TIMER as Simon suggested.

 common/board_r.c | 3 +++
 1 file changed, 3 insertions(+)
common/board_r.c +3 -0
index f8c1baa..3b193b5 100644
@@ -290,6 +290,9 @@ static int initr_dm(void)
 	/* Save the pre-reloc driver model and start a new one */
 	gd->dm_root_f = gd->dm_root;
 	gd->dm_root = NULL;
+#ifdef CONFIG_TIMER
+	gd->TIMER = NULL;
+#endif
 	return dm_init_and_scan(false);
 }
 #endif
Signature · 1 line
2.1.4
#27 lore raw

PATCH v6 2/3 timer: start a new TIMER after relocation

Hi Thomas,

Quoted 17 lines · Thomas Chou

Start a new TIMER after relocation, just in case the timer has been used in per-relocation.

---
v6
rename to CONFIG_TIMER as Simon suggested.

 common/board_r.c | 3 +++
 1 file changed, 3 insertions(+)
common/board_r.c +0 -0
index f8c1baa..3b193b5 100644

common/board_r.c static int initr_dm(void) · line 294

Quoted 5 lines
common/board_r.c +2 -0
@@ -290,6 +290,9 @@ static int initr_dm(void)
        /* Save the pre-reloc driver model and start a new one */
        gd->dm_root_f = gd->dm_root;
        gd->dm_root = NULL;
+#ifdef CONFIG_TIMER
+       gd->TIMER = NULL;

Sorry for jumping in so late. But why is this TIMER all capital letters?

common/board_r.c static int initr_dm(void)

Quoted 5 lines
common/board_r.c +1 -1
+#endif
        return dm_init_and_scan(false);
 }
 #endif
--

Regards,
Bin

#28 lore raw

PATCH v6 2/3 timer: start a new TIMER after relocation

Hi Bin,

Quoted 4 lines · Bin Meng

common/board_r.c static int initr_dm(void) · line 294

Quoted 2 lines
common/board_r.c +2 -0
+#ifdef CONFIG_TIMER
+       gd->TIMER = NULL;

Sorry for jumping in so late. But why is this TIMER all capital letters?

Thanks for reminding. I made wrong string replacement.

Best regards,
Thomas Chou

#29 lore raw

PATCH v6 3/3 nios2: convert altera timer to driver model

In reply to Thomas Chou

Convert altera timer to driver model.

---
v2
fix coding style.
v3
doc dts binding.
v4
no change.
v5
revert to get_rate and use uclass priv to store the clock_rate.
v6
rename to CONFIG_TIMER as Simon suggested.

 arch/nios2/cpu/Makefile                         |   2 +-
 arch/nios2/cpu/timer.c                          |  65 ---------------
 common/board_f.c                                |   3 +-
 configs/nios2-generic_defconfig                 |   2 +
 doc/device-tree-bindings/timer/altera_timer.txt |  19 +++++
 drivers/timer/Kconfig                           |   7 ++
 drivers/timer/Makefile                          |   1 +
 drivers/timer/altera_timer.c                    | 103 ++++++++++++++++++++++++
 include/configs/nios2-generic.h                 |   5 --
 9 files changed, 134 insertions(+), 73 deletions(-)
 delete mode 100644 arch/nios2/cpu/timer.c
 create mode 100644 doc/device-tree-bindings/timer/altera_timer.txt
 create mode 100644 drivers/timer/altera_timer.c
arch/nios2/cpu/Makefile +1 -1
index c85e261..3fe7847 100644
@@ -7,5 +7,5 @@
 
 extra-y	= start.o
 obj-y	= exceptions.o
-obj-y	+= cpu.o interrupts.o sysid.o timer.o traps.o
+obj-y	+= cpu.o interrupts.o sysid.o traps.o
 obj-y	+= fdt.o
arch/nios2/cpu/timer.c deleted +0 -65

65 lines not on this page · raw message

common/board_f.c +1 -2
index 8bb8ded..613332e 100644
@@ -795,8 +795,7 @@ static init_fnc_t init_sequence_f[] = {
 	init_timebase,
 #endif
 #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
-		defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
-		defined(CONFIG_NIOS2)
+		defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32)
 	timer_init,		/* initialize timer */
 #endif
 #ifdef CONFIG_SYS_ALLOC_DPRAM
configs/nios2-generic_defconfig +2 -0
index 707ee33..505a2cf 100644
@@ -18,3 +18,5 @@ CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
+CONFIG_TIMER=y
+CONFIG_ALTERA_TIMER=y
doc/device-tree-bindings/timer/altera_timer.txt new file +19 -0
new file mode 100644
index 0000000..904a584
@@ -0,0 +1,19 @@
+Altera Timer
+
+Required properties:
+
+- compatible : should be "altr,timer-1.0"
+- reg : Specifies base physical address and size of the registers.
+- interrupt-parent: phandle of the interrupt controller
+- interrupts : Should contain the timer interrupt number
+- clock-frequency : The frequency of the clock that drives the counter, in Hz.
+
+Example:
+
+timer {
+	compatible = "altr,timer-1.0";
+	reg = <0x00400000 0x00000020>;
+	interrupt-parent = <&cpu>;
+	interrupts = <11>;
+	clock-frequency = <125000000>;
+};
drivers/timer/Kconfig +7 -0
index 8e8d600..97c4128 100644
@@ -9,4 +9,11 @@ config TIMER
 	  will be used. The timer is usually a 32 bits free-running up
 	  counter. There may be no real tick, and no timer interrupt.
 
+config ALTERA_TIMER
+	bool "Altera Timer support"
+	depends on TIMER
+	help
+	  Select this to enable an timer for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 endmenu
drivers/timer/Makefile +1 -0
index afb0009..ae66c07 100644
@@ -5,3 +5,4 @@
 #
 
 obj-$(CONFIG_TIMER)		+= timer-uclass.o
+obj-$(CONFIG_ALTERA_TIMER)	+= altera_timer.o
drivers/timer/altera_timer.c new file +103 -0

103 lines not on this page · raw message

include/configs/nios2-generic.h +0 -5
index 62f7db9..c65b3b3 100644
@@ -26,11 +26,6 @@
 #define CONFIG_SYS_CONSOLE_INFO_QUIET	/* Suppress console info */
 
 /*
- * TIMER
- */
-#define CONFIG_SYS_TIMER_RATE		CONFIG_SYS_TIMER_FREQ
-
-/*
  * BOOTP options
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
Signature · 1 line
2.1.4
#30 lore raw

PATCH v6 1/3 dm: implement a Timer uclass

In reply to Thomas Chou

Hi Thomas,

Quoted 4 lines · Thomas Chou

Implement a Timer uclass to work with lib/time.c.

Quoted 16 lines

---
v2
fix coding style.
v3
add description to Kconfig as Simon suggested.
move timer.c code to lib/time.c.
add dm_timer dev to global data.
remove timer_init().
change API name get_clock.
v4
add comment about timer hardware.
v5
revert to get_rate and use uclass priv to store the clock_rate. split gd->dm_timer renewal to anohter patch.
v6
rename to CONFIG_TIMER as Simon suggested.

But note you have changed this too broadly - 'TIMER' appears in several places where it should be 'timer'.

Quoted 16 lines
 drivers/Kconfig                   |  2 ++
 drivers/Makefile                  |  1 +
 drivers/timer/Kconfig             | 12 +++++++++
 drivers/timer/Makefile            |  7 ++++++
 drivers/timer/timer-uclass.c      | 42 +++++++++++++++++++++++++++++++
 include/asm-generic/global_data.h |  3 +++
 include/dm/uclass-id.h            |  1 +
 include/timer.h                   | 52 +++++++++++++++++++++++++++++++++++++++
 lib/time.c                        | 49 ++++++++++++++++++++++++++++++++++++
 9 files changed, 169 insertions(+)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 include/timer.h

Regards,
Simon

#31 lore raw

PATCH v6 1/3 dm: implement a Timer uclass

Hi Simon,

Quoted 5 lines · Simon Glass
Quoted 2 lines

v6
rename to CONFIG_TIMER as Simon suggested.

But note you have changed this too broadly - 'TIMER' appears in several places where it should be 'timer'.

Sorry, I made a mistake in the string replacement. Please see v7.

Best regards,
Thomas

#32 lore raw

PATCH v6 1/3 dm: implement a Timer uclass

Hi Thomas,

Quoted 8 lines · Thomas Chou

Hi Simon,

Quoted 5 lines · Simon Glass
Quoted 3 lines

v6
rename to CONFIG_TIMER as Simon suggested.

Quoted 6 lines
Quoted 2 lines

But note you have changed this too broadly - 'TIMER' appears in several places where it should be 'timer'.

Sorry, I made a mistake in the string replacement. Please see v7.

But in v7, it is gd->dm_timer. I think it should be gd->timer?

Regards,
Bin

#33 lore raw

PATCH v6 1/3 dm: implement a Timer uclass

Hi Bin,

Quoted 1 line · Bin Meng

But in v7, it is gd->dm_timer. I think it should be gd->timer?

I think it is only CONFIG_DM_TIMER, that Simon suggested to change.

In the gd structure, I keep it neighbor to dm_root. In the initr_dm(), they are set to NULL similarly. So I would keep dm_ prefix.

I also spelled the macro in include/timer.h as
+#ifndef _DM_TIMER_H_
+#define _DM_TIMER_H_
because some archs have their timer.h.

Best regards,
Thomas

#34 lore raw

PATCH v7 1/3 dm: implement a Timer uclass

In reply to Thomas Chou

Implement a Timer uclass to work with lib/time.c.

---
v2
fix coding style.
v3
add description to Kconfig as Simon suggested.
move timer.c code to lib/time.c.
add dm_timer dev to global data.
remove timer_init().
change API name get_clock.
v4
add comment about timer hardware.
v5
revert to get_rate and use uclass priv to store the clock_rate. split gd->dm_timer renewal to anohter patch.
v6
rename to CONFIG_TIMER as Simon suggested.
v7
fix string replacement error in v6

 drivers/Kconfig                   |  2 ++
 drivers/Makefile                  |  1 +
 drivers/timer/Kconfig             | 12 +++++++++
 drivers/timer/Makefile            |  7 ++++++
 drivers/timer/timer-uclass.c      | 42 +++++++++++++++++++++++++++++++
 include/asm-generic/global_data.h |  3 +++
 include/dm/uclass-id.h            |  1 +
 include/timer.h                   | 52 +++++++++++++++++++++++++++++++++++++++
 lib/time.c                        | 49 ++++++++++++++++++++++++++++++++++++
 9 files changed, 169 insertions(+)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 include/timer.h
drivers/Kconfig +2 -0
index 63c92c5..f9496f7 100644
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
drivers/Makefile +1 -0
index 9d0a595..692da78 100644
@@ -48,6 +48,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
 obj-y += video/
drivers/timer/Kconfig new file +12 -0
new file mode 100644
index 0000000..8e8d600
@@ -0,0 +1,12 @@
+menu "Timer Support"
+
+config TIMER
+	bool "Enable Driver Model for Timer drivers"
+	depends on DM
+	help
+	  Enable driver model for Timer access. It uses the same API as
+	  lib/time.c. But now implemented by the uclass. The first timer
+	  will be used. The timer is usually a 32 bits free-running up
+	  counter. There may be no real tick, and no timer interrupt.
+
+endmenu
drivers/timer/Makefile new file +7 -0
new file mode 100644
index 0000000..afb0009
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2015 Thomas Chou <[email protected]>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_TIMER)		+= timer-uclass.o
drivers/timer/timer-uclass.c new file +42 -0

42 lines not on this page · raw message

include/asm-generic/global_data.h +3 -0
index 2155265..78da709 100644
@@ -69,6 +69,9 @@ typedef struct global_data {
 	struct udevice	*dm_root_f;	/* Pre-relocation root instance */
 	struct list_head uclass_root;	/* Head of core tree */
 #endif
+#ifdef CONFIG_TIMER
+	struct udevice	*dm_timer;	/* Timer instance for Driver Model */
+#endif
 
 	const void *fdt_blob;	/* Our device tree, NULL if none */
 	void *new_fdt;		/* Relocated FDT */
include/dm/uclass-id.h +1 -0
index 1eeec74..aff34a4 100644
@@ -56,6 +56,7 @@ enum uclass_id {
 	UCLASS_SPI_GENERIC,	/* Generic SPI flash target */
 	UCLASS_SYSCON,		/* System configuration device */
 	UCLASS_THERMAL,		/* Thermal sensor */
+	UCLASS_TIMER,		/* Timer device */
 	UCLASS_TPM,		/* Trusted Platform Module TIS interface */
 	UCLASS_USB,		/* USB bus */
 	UCLASS_USB_DEV_GENERIC,	/* USB generic device */
include/timer.h new file +52 -0

52 lines not on this page · raw message

lib/time.c +49 -0

61 lines not on this page · raw message

Signature · 1 line
2.1.4
#35 lore raw

PATCH v7 2/3 timer: start a new dm_timer after relocation

Start a new dm_timer after relocation, just in case the timer has been used in per-relocation.

---
v6
rename to CONFIG_TIMER as Simon suggested.
v7
fix string replacement error in v6

 common/board_r.c | 3 +++
 1 file changed, 3 insertions(+)
common/board_r.c +3 -0
index f8c1baa..d22118b 100644
@@ -290,6 +290,9 @@ static int initr_dm(void)
 	/* Save the pre-reloc driver model and start a new one */
 	gd->dm_root_f = gd->dm_root;
 	gd->dm_root = NULL;
+#ifdef CONFIG_TIMER
+	gd->dm_timer = NULL;
+#endif
 	return dm_init_and_scan(false);
 }
 #endif
Signature · 1 line
2.1.4
#36 lore raw

PATCH v7 3/3 nios2: convert altera timer to driver model

In reply to Thomas Chou

Convert altera timer to driver model.

---
v2
fix coding style.
v3
doc dts binding.
v4
no change.
v5
revert to get_rate and use uclass priv to store the clock_rate.
v6
rename to CONFIG_TIMER as Simon suggested.
v7
fix string replacement error in v6.

 arch/nios2/cpu/Makefile                         |   2 +-
 arch/nios2/cpu/timer.c                          |  65 ---------------
 common/board_f.c                                |   3 +-
 configs/nios2-generic_defconfig                 |   2 +
 doc/device-tree-bindings/timer/altera_timer.txt |  19 +++++
 drivers/timer/Kconfig                           |   7 ++
 drivers/timer/Makefile                          |   1 +
 drivers/timer/altera_timer.c                    | 103 ++++++++++++++++++++++++
 include/configs/nios2-generic.h                 |   5 --
 9 files changed, 134 insertions(+), 73 deletions(-)
 delete mode 100644 arch/nios2/cpu/timer.c
 create mode 100644 doc/device-tree-bindings/timer/altera_timer.txt
 create mode 100644 drivers/timer/altera_timer.c
arch/nios2/cpu/Makefile +1 -1
index c85e261..3fe7847 100644
@@ -7,5 +7,5 @@
 
 extra-y	= start.o
 obj-y	= exceptions.o
-obj-y	+= cpu.o interrupts.o sysid.o timer.o traps.o
+obj-y	+= cpu.o interrupts.o sysid.o traps.o
 obj-y	+= fdt.o
arch/nios2/cpu/timer.c deleted +0 -65

65 lines not on this page · raw message

common/board_f.c +1 -2
index 8bb8ded..613332e 100644
@@ -795,8 +795,7 @@ static init_fnc_t init_sequence_f[] = {
 	init_timebase,
 #endif
 #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
-		defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
-		defined(CONFIG_NIOS2)
+		defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32)
 	timer_init,		/* initialize timer */
 #endif
 #ifdef CONFIG_SYS_ALLOC_DPRAM
configs/nios2-generic_defconfig +2 -0
index 707ee33..505a2cf 100644
@@ -18,3 +18,5 @@ CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
+CONFIG_TIMER=y
+CONFIG_ALTERA_TIMER=y
doc/device-tree-bindings/timer/altera_timer.txt new file +19 -0
new file mode 100644
index 0000000..904a584
@@ -0,0 +1,19 @@
+Altera Timer
+
+Required properties:
+
+- compatible : should be "altr,timer-1.0"
+- reg : Specifies base physical address and size of the registers.
+- interrupt-parent: phandle of the interrupt controller
+- interrupts : Should contain the timer interrupt number
+- clock-frequency : The frequency of the clock that drives the counter, in Hz.
+
+Example:
+
+timer {
+	compatible = "altr,timer-1.0";
+	reg = <0x00400000 0x00000020>;
+	interrupt-parent = <&cpu>;
+	interrupts = <11>;
+	clock-frequency = <125000000>;
+};
drivers/timer/Kconfig +7 -0
index 8e8d600..97c4128 100644
@@ -9,4 +9,11 @@ config TIMER
 	  will be used. The timer is usually a 32 bits free-running up
 	  counter. There may be no real tick, and no timer interrupt.
 
+config ALTERA_TIMER
+	bool "Altera Timer support"
+	depends on TIMER
+	help
+	  Select this to enable an timer for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 endmenu
drivers/timer/Makefile +1 -0
index afb0009..ae66c07 100644
@@ -5,3 +5,4 @@
 #
 
 obj-$(CONFIG_TIMER)		+= timer-uclass.o
+obj-$(CONFIG_ALTERA_TIMER)	+= altera_timer.o
drivers/timer/altera_timer.c new file +103 -0

103 lines not on this page · raw message

include/configs/nios2-generic.h +0 -5
index 62f7db9..c65b3b3 100644
@@ -26,11 +26,6 @@
 #define CONFIG_SYS_CONSOLE_INFO_QUIET	/* Suppress console info */
 
 /*
- * TIMER
- */
-#define CONFIG_SYS_TIMER_RATE		CONFIG_SYS_TIMER_FREQ
-
-/*
  * BOOTP options
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
Signature · 1 line
2.1.4
#37 lore raw

PATCH v8 1/3 dm: implement a Timer uclass

In reply to Thomas Chou

Implement a Timer uclass to work with lib/time.c.

---
v2
fix coding style.
v3
add description to Kconfig as Simon suggested.
move timer.c code to lib/time.c.
add dm_timer dev to global data.
remove timer_init().
change API name get_clock.
v4
add comment about timer hardware.
v5
revert to get_rate and use uclass priv to store the clock_rate. split gd->dm_timer renewal to anohter patch.
v6
rename to CONFIG_TIMER as Simon suggested.
v7
fix string replacement error in v6
v8
replace all dm_timer with timer.

 drivers/Kconfig                   |  2 ++
 drivers/Makefile                  |  1 +
 drivers/timer/Kconfig             | 12 +++++++++
 drivers/timer/Makefile            |  7 ++++++
 drivers/timer/timer-uclass.c      | 42 +++++++++++++++++++++++++++++++
 include/asm-generic/global_data.h |  3 +++
 include/dm/uclass-id.h            |  1 +
 include/timer.h                   | 52 +++++++++++++++++++++++++++++++++++++++
 lib/time.c                        | 49 ++++++++++++++++++++++++++++++++++++
 9 files changed, 169 insertions(+)
 create mode 100644 drivers/timer/Kconfig
 create mode 100644 drivers/timer/Makefile
 create mode 100644 drivers/timer/timer-uclass.c
 create mode 100644 include/timer.h
drivers/Kconfig +2 -0
index 63c92c5..f9496f7 100644
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
drivers/Makefile +1 -0
index 9d0a595..692da78 100644
@@ -48,6 +48,7 @@ obj-y += pcmcia/
 obj-y += dfu/
 obj-y += rtc/
 obj-y += sound/
+obj-y += timer/
 obj-y += tpm/
 obj-y += twserial/
 obj-y += video/
drivers/timer/Kconfig new file +12 -0
new file mode 100644
index 0000000..8e8d600
@@ -0,0 +1,12 @@
+menu "Timer Support"
+
+config TIMER
+	bool "Enable Driver Model for Timer drivers"
+	depends on DM
+	help
+	  Enable driver model for Timer access. It uses the same API as
+	  lib/time.c. But now implemented by the uclass. The first timer
+	  will be used. The timer is usually a 32 bits free-running up
+	  counter. There may be no real tick, and no timer interrupt.
+
+endmenu
drivers/timer/Makefile new file +7 -0
new file mode 100644
index 0000000..afb0009
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2015 Thomas Chou <[email protected]>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_TIMER)		+= timer-uclass.o
drivers/timer/timer-uclass.c new file +42 -0

42 lines not on this page · raw message

include/asm-generic/global_data.h +3 -0
index 2155265..78da709 100644
@@ -69,6 +69,9 @@ typedef struct global_data {
 	struct udevice	*dm_root_f;	/* Pre-relocation root instance */
 	struct list_head uclass_root;	/* Head of core tree */
 #endif
+#ifdef CONFIG_TIMER
+	struct udevice	*timer;	/* Timer instance for Driver Model */
+#endif
 
 	const void *fdt_blob;	/* Our device tree, NULL if none */
 	void *new_fdt;		/* Relocated FDT */
include/dm/uclass-id.h +1 -0
index 1eeec74..aff34a4 100644
@@ -56,6 +56,7 @@ enum uclass_id {
 	UCLASS_SPI_GENERIC,	/* Generic SPI flash target */
 	UCLASS_SYSCON,		/* System configuration device */
 	UCLASS_THERMAL,		/* Thermal sensor */
+	UCLASS_TIMER,		/* Timer device */
 	UCLASS_TPM,		/* Trusted Platform Module TIS interface */
 	UCLASS_USB,		/* USB bus */
 	UCLASS_USB_DEV_GENERIC,	/* USB generic device */
include/timer.h new file +52 -0

52 lines not on this page · raw message

lib/time.c +49 -0

61 lines not on this page · raw message

Signature · 1 line
2.1.4
#38 lore raw

PATCH v8 1/3 dm: implement a Timer uclass

Quoted 35 lines · Thomas Chou

Implement a Timer uclass to work with lib/time.c.

---
v2
fix coding style.
v3
add description to Kconfig as Simon suggested.
move timer.c code to lib/time.c.
add dm_timer dev to global data.
remove timer_init().
change API name get_clock.
v4
add comment about timer hardware.
v5
revert to get_rate and use uclass priv to store the clock_rate. split gd->dm_timer renewal to anohter patch.
v6
rename to CONFIG_TIMER as Simon suggested.
v7
fix string replacement error in v6
v8
replace all dm_timer with timer.

  drivers/Kconfig                   |  2 ++
  drivers/Makefile                  |  1 +
  drivers/timer/Kconfig             | 12 +++++++++
  drivers/timer/Makefile            |  7 ++++++
  drivers/timer/timer-uclass.c      | 42 +++++++++++++++++++++++++++++++
  include/asm-generic/global_data.h |  3 +++
  include/dm/uclass-id.h            |  1 +
  include/timer.h                   | 52 +++++++++++++++++++++++++++++++++++++++
  lib/time.c                        | 49 ++++++++++++++++++++++++++++++++++++
  9 files changed, 169 insertions(+)
Quoted 5 lines

create mode 100644 drivers/timer/Kconfig
create mode 100644 drivers/timer/Makefile
create mode 100644 drivers/timer/timer-uclass.c
create mode 100644 include/timer.h

Applied to u-boot-nios.

#39 lore raw

PATCH v8 1/3 dm: implement a Timer uclass

Hi Thomas,

Quoted 47 lines · Thomas Chou
Quoted 38 lines · Thomas Chou

Implement a Timer uclass to work with lib/time.c.

---
v2
fix coding style.
v3
add description to Kconfig as Simon suggested.
move timer.c code to lib/time.c.
add dm_timer dev to global data.
remove timer_init().
change API name get_clock.
v4
add comment about timer hardware.
v5
revert to get_rate and use uclass priv to store the clock_rate. split gd->dm_timer renewal to anohter patch.
v6
rename to CONFIG_TIMER as Simon suggested.
v7
fix string replacement error in v6
v8
replace all dm_timer with timer.

  drivers/Kconfig                   |  2 ++
  drivers/Makefile                  |  1 +
  drivers/timer/Kconfig             | 12 +++++++++
  drivers/timer/Makefile            |  7 ++++++
  drivers/timer/timer-uclass.c      | 42 +++++++++++++++++++++++++++++++
  include/asm-generic/global_data.h |  3 +++
  include/dm/uclass-id.h            |  1 +
  include/timer.h                   | 52
+++++++++++++++++++++++++++++++++++++++
  lib/time.c                        | 49
++++++++++++++++++++++++++++++++++++
  9 files changed, 169 insertions(+)
Quoted 5 lines

create mode 100644 drivers/timer/Kconfig
create mode 100644 drivers/timer/Makefile
create mode 100644 drivers/timer/timer-uclass.c
create mode 100644 include/timer.h

Quoted 2 lines

Applied to u-boot-nios.

Please do create a test for this uclass using a fake sandbox timer. Note also time_ut.c which might have some ideas.

Regards,
Simon

#40 lore raw

PATCH v8 1/3 dm: implement a Timer uclass

Hi Simon,

Quoted 2 lines · Simon Glass

Please do create a test for this uclass using a fake sandbox timer. Note also time_ut.c which might have some ideas.

I am learning sandbox and working on a sandbox timer now.

Best regards,
Thomas

#41 lore raw

PATCH v8 2/3 timer: start a new timer after relocation

In reply to Thomas Chou

Start a new timer after relocation, just in case the timer has been used in per-relocation.

---
v6
rename to CONFIG_TIMER as Simon suggested.
v7
fix string replacement error in v6
v8
replace all dm_timer with timer.

 common/board_r.c | 3 +++
 1 file changed, 3 insertions(+)
common/board_r.c +3 -0
index f8c1baa..d22118b 100644
@@ -290,6 +290,9 @@ static int initr_dm(void)
 	/* Save the pre-reloc driver model and start a new one */
 	gd->dm_root_f = gd->dm_root;
 	gd->dm_root = NULL;
+#ifdef CONFIG_TIMER
+	gd->timer = NULL;
+#endif
 	return dm_init_and_scan(false);
 }
 #endif
Signature · 1 line
2.1.4
#42 lore raw

PATCH v8 2/3 timer: start a new timer after relocation

Quoted 13 lines · Thomas Chou

Start a new timer after relocation, just in case the timer has been used in per-relocation.

---
v6
rename to CONFIG_TIMER as Simon suggested.
v7
fix string replacement error in v6
v8
replace all dm_timer with timer.

Quoted 3 lines
  common/board_r.c | 3 +++
  1 file changed, 3 insertions(+)

Applied to u-boot-nios.

Quoted 15 lines
common/board_r.c +3 -0
index f8c1baa..d22118b 100644
@@ -290,6 +290,9 @@ static int initr_dm(void)
  	/* Save the pre-reloc driver model and start a new one */
  	gd->dm_root_f = gd->dm_root;
  	gd->dm_root = NULL;
+#ifdef CONFIG_TIMER
+	gd->timer = NULL;
+#endif
  	return dm_init_and_scan(false);
  }
  #endif
#43 lore raw

PATCH v8 3/3 nios2: convert altera timer to driver model

In reply to Thomas Chou

Convert altera timer to driver model.

---
v2
fix coding style.
v3
doc dts binding.
v4
no change.
v5
revert to get_rate and use uclass priv to store the clock_rate.
v6
rename to CONFIG_TIMER as Simon suggested.
v7
fix string replacement error in v6.
v8
replace all dm_timer with timer.

 arch/nios2/cpu/Makefile                         |   2 +-
 arch/nios2/cpu/timer.c                          |  65 ---------------
 common/board_f.c                                |   3 +-
 configs/nios2-generic_defconfig                 |   2 +
 doc/device-tree-bindings/timer/altera_timer.txt |  19 +++++
 drivers/timer/Kconfig                           |   7 ++
 drivers/timer/Makefile                          |   1 +
 drivers/timer/altera_timer.c                    | 103 ++++++++++++++++++++++++
 include/configs/nios2-generic.h                 |   5 --
 9 files changed, 134 insertions(+), 73 deletions(-)
 delete mode 100644 arch/nios2/cpu/timer.c
 create mode 100644 doc/device-tree-bindings/timer/altera_timer.txt
 create mode 100644 drivers/timer/altera_timer.c
arch/nios2/cpu/Makefile +1 -1
index c85e261..3fe7847 100644
@@ -7,5 +7,5 @@
 
 extra-y	= start.o
 obj-y	= exceptions.o
-obj-y	+= cpu.o interrupts.o sysid.o timer.o traps.o
+obj-y	+= cpu.o interrupts.o sysid.o traps.o
 obj-y	+= fdt.o
arch/nios2/cpu/timer.c deleted +0 -65

65 lines not on this page · raw message

common/board_f.c +1 -2
index 8bb8ded..613332e 100644
@@ -795,8 +795,7 @@ static init_fnc_t init_sequence_f[] = {
 	init_timebase,
 #endif
 #if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || \
-		defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32) || \
-		defined(CONFIG_NIOS2)
+		defined(CONFIG_BLACKFIN) || defined(CONFIG_NDS32)
 	timer_init,		/* initialize timer */
 #endif
 #ifdef CONFIG_SYS_ALLOC_DPRAM
configs/nios2-generic_defconfig +2 -0
index 707ee33..505a2cf 100644
@@ -18,3 +18,5 @@ CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_ALTERA_PIO=y
 CONFIG_ALTERA_JTAG_UART=y
 CONFIG_ALTERA_JTAG_UART_BYPASS=y
+CONFIG_TIMER=y
+CONFIG_ALTERA_TIMER=y
doc/device-tree-bindings/timer/altera_timer.txt new file +19 -0
new file mode 100644
index 0000000..904a584
@@ -0,0 +1,19 @@
+Altera Timer
+
+Required properties:
+
+- compatible : should be "altr,timer-1.0"
+- reg : Specifies base physical address and size of the registers.
+- interrupt-parent: phandle of the interrupt controller
+- interrupts : Should contain the timer interrupt number
+- clock-frequency : The frequency of the clock that drives the counter, in Hz.
+
+Example:
+
+timer {
+	compatible = "altr,timer-1.0";
+	reg = <0x00400000 0x00000020>;
+	interrupt-parent = <&cpu>;
+	interrupts = <11>;
+	clock-frequency = <125000000>;
+};
drivers/timer/Kconfig +7 -0
index 8e8d600..97c4128 100644
@@ -9,4 +9,11 @@ config TIMER
 	  will be used. The timer is usually a 32 bits free-running up
 	  counter. There may be no real tick, and no timer interrupt.
 
+config ALTERA_TIMER
+	bool "Altera Timer support"
+	depends on TIMER
+	help
+	  Select this to enable an timer for Altera devices. Please find
+	  details on the "Embedded Peripherals IP User Guide" of Altera.
+
 endmenu
drivers/timer/Makefile +1 -0
index afb0009..ae66c07 100644
@@ -5,3 +5,4 @@
 #
 
 obj-$(CONFIG_TIMER)		+= timer-uclass.o
+obj-$(CONFIG_ALTERA_TIMER)	+= altera_timer.o
drivers/timer/altera_timer.c new file +103 -0

103 lines not on this page · raw message

include/configs/nios2-generic.h +0 -5
index 62f7db9..c65b3b3 100644
@@ -26,11 +26,6 @@
 #define CONFIG_SYS_CONSOLE_INFO_QUIET	/* Suppress console info */
 
 /*
- * TIMER
- */
-#define CONFIG_SYS_TIMER_RATE		CONFIG_SYS_TIMER_FREQ
-
-/*
  * BOOTP options
  */
 #define CONFIG_BOOTP_BOOTFILESIZE
Signature · 1 line
2.1.4
#44 lore raw

PATCH v8 3/3 nios2: convert altera timer to driver model

Quoted 30 lines · Thomas Chou

Convert altera timer to driver model.

---
v2
fix coding style.
v3
doc dts binding.
v4
no change.
v5
revert to get_rate and use uclass priv to store the clock_rate.
v6
rename to CONFIG_TIMER as Simon suggested.
v7
fix string replacement error in v6.
v8
replace all dm_timer with timer.

  arch/nios2/cpu/Makefile                         |   2 +-
  arch/nios2/cpu/timer.c                          |  65 ---------------
  common/board_f.c                                |   3 +-
  configs/nios2-generic_defconfig                 |   2 +
  doc/device-tree-bindings/timer/altera_timer.txt |  19 +++++
  drivers/timer/Kconfig                           |   7 ++
  drivers/timer/Makefile                          |   1 +
  drivers/timer/altera_timer.c                    | 103 ++++++++++++++++++++++++
  include/configs/nios2-generic.h                 |   5 --
  9 files changed, 134 insertions(+), 73 deletions(-)
Quoted 4 lines

delete mode 100644 arch/nios2/cpu/timer.c
create mode 100644 doc/device-tree-bindings/timer/altera_timer.txt create mode 100644 drivers/timer/altera_timer.c

Applied to u-boot-nios.