public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] dm: implement a Timer uclass
@ 2015-09-28 13:19 Thomas Chou
  2015-09-28 13:19 ` [U-Boot] [PATCH 2/2] nios2: convert altera timer to driver model Thomas Chou
                   ` (8 more replies)
  0 siblings, 9 replies; 45+ messages in thread
From: Thomas Chou @ 2015-09-28 13:19 UTC (permalink / raw)
  To: u-boot

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

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
 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

diff --git a/common/board_r.c b/common/board_r.c
index f8c1baa..2d8ad11 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -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)
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 63c92c5..f9496f7 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
 
 source "drivers/thermal/Kconfig"
 
+source "drivers/timer/Kconfig"
+
 source "drivers/tpm/Kconfig"
 
 source "drivers/usb/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 9d0a595..692da78 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -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/
diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig
new file mode 100644
index 0000000..97014f3
--- /dev/null
+++ b/drivers/timer/Kconfig
@@ -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
diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile
new file mode 100644
index 0000000..58acd7c
--- /dev/null
+++ b/drivers/timer/Makefile
@@ -0,0 +1,7 @@
+#
+# Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-$(CONFIG_DM_TIMER)		+= timer-uclass.o timer.o
diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c
new file mode 100644
index 0000000..1f088bf
--- /dev/null
+++ b/drivers/timer/timer-uclass.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * 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",
+};
diff --git a/drivers/timer/timer.c b/drivers/timer/timer.c
new file mode 100644
index 0000000..648fd06
--- /dev/null
+++ b/drivers/timer/timer.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * 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 100000000; /* 100MHz, fail-safe */
+
+	timer_get_rate(dev, &rate);
+
+	return rate;
+}
+
+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 */
+
+	timer_get_count(dev, &count);
+
+	return count;
+}
+
+int timer_init(void)
+{
+	struct udevice *dev;
+
+	uclass_first_device(UCLASS_TIMER, &dev);
+	if (!dev)
+		return -ENODEV;
+
+	return 0;
+}
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 1eeec74..aff34a4 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -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 */
diff --git a/include/timer.h b/include/timer.h
new file mode 100644
index 0000000..5d71612
--- /dev/null
+++ b/include/timer.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
+ *
+ * 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_ */
-- 
2.1.4

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

end of thread, other threads:[~2015-10-19 10:54 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-28 13:19 [U-Boot] [PATCH 1/2] dm: implement a Timer uclass Thomas Chou
2015-09-28 13:19 ` [U-Boot] [PATCH 2/2] nios2: convert altera timer to driver model Thomas Chou
2015-09-29  1:32 ` [U-Boot] [PATCH 1/2] dm: implement a Timer uclass Thomas Chou
2015-09-29 12:39 ` [U-Boot] [PATCH v2 " Thomas Chou
2015-09-29 12:39   ` [U-Boot] [PATCH v2 2/2] nios2: convert altera timer to driver model Thomas Chou
2015-09-30  0:27     ` Chin Liang See
2015-10-01  2:51       ` Thomas Chou
2015-10-01  9:12         ` Thomas Chou
2015-09-29 13:57   ` [U-Boot] [PATCH v2 1/2] dm: implement a Timer uclass Simon Glass
2015-10-01  7:22     ` Thomas Chou
2015-10-03  9:19 ` [U-Boot] [PATCH v3 " Thomas Chou
2015-10-03  9:19   ` [U-Boot] [PATCH v3 2/2] nios2: convert altera timer to driver model Thomas Chou
2015-10-03 14:29   ` [U-Boot] [PATCH v3 1/2] dm: implement a Timer uclass Simon Glass
2015-10-04 13:09     ` Thomas Chou
2015-10-04 13:56 ` [U-Boot] [PATCH v4 " Thomas Chou
2015-10-04 13:56   ` [U-Boot] [PATCH v4 2/2] nios2: convert altera timer to driver model Thomas Chou
2015-10-07  2:27     ` Chin Liang See
2015-10-06 14:14   ` [U-Boot] [PATCH v4 1/2] dm: implement a Timer uclass Simon Glass
2015-10-08  0:55     ` Thomas Chou
2015-10-08  1:03 ` [U-Boot] [PATCH v5 1/3] " Thomas Chou
2015-10-08  1:03   ` [U-Boot] [PATCH v5 2/3] timer: start a new dm_timer after relocation Thomas Chou
2015-10-08 16:09     ` Simon Glass
2015-10-08  1:03   ` [U-Boot] [PATCH v5 3/3] nios2: convert altera timer to driver model Thomas Chou
2015-10-08 17:14   ` [U-Boot] [PATCH v5 1/3] dm: implement a Timer uclass Simon Glass
2015-10-09  1:19     ` Thomas Chou
2015-10-09  1:17 ` [U-Boot] [PATCH v6 " Thomas Chou
2015-10-09  1:17   ` [U-Boot] [PATCH v6 2/3] timer: start a new TIMER after relocation Thomas Chou
2015-10-09  1:32     ` Bin Meng
2015-10-09  5:26       ` Thomas Chou
2015-10-09  1:17   ` [U-Boot] [PATCH v6 3/3] nios2: convert altera timer to driver model Thomas Chou
2015-10-09  9:36   ` [U-Boot] [PATCH v6 1/3] dm: implement a Timer uclass Simon Glass
2015-10-09 10:44     ` Thomas Chou
2015-10-09 10:46       ` Bin Meng
2015-10-09 13:18         ` Thomas Chou
2015-10-09  7:08 ` [U-Boot] [PATCH v7 " Thomas Chou
2015-10-09  7:08   ` [U-Boot] [PATCH v7 2/3] timer: start a new dm_timer after relocation Thomas Chou
2015-10-09  7:08   ` [U-Boot] [PATCH v7 3/3] nios2: convert altera timer to driver model Thomas Chou
2015-10-10  7:16 ` [U-Boot] [PATCH v8 1/3] dm: implement a Timer uclass Thomas Chou
2015-10-10  7:16   ` [U-Boot] [PATCH v8 2/3] timer: start a new timer after relocation Thomas Chou
2015-10-13 13:17     ` Thomas Chou
2015-10-10  7:16   ` [U-Boot] [PATCH v8 3/3] nios2: convert altera timer to driver model Thomas Chou
2015-10-13 13:17     ` Thomas Chou
2015-10-13 13:17   ` [U-Boot] [PATCH v8 1/3] dm: implement a Timer uclass Thomas Chou
2015-10-19  1:53     ` Simon Glass
2015-10-19 10:54       ` Thomas Chou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox