@@ -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)
@@ -56,6 +56,8 @@ source "drivers/spi/Kconfig"
source "drivers/thermal/Kconfig"
+source "drivers/timer/Kconfig"
+
source "drivers/tpm/Kconfig"
source "drivers/usb/Kconfig"
@@ -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/
new file mode 100644
@@ -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
new file mode 100644
@@ -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
new file mode 100644
@@ -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",
+};
new file mode 100644
@@ -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;
+}
@@ -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 */
new file mode 100644
@@ -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_ */
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