summaryrefslogtreecommitdiffstats
path: root/drivers/rtc/class.c
diff options
context:
space:
mode:
authorAntony Pavlov <antonynpavlov@gmail.com>2014-07-30 00:10:18 +0400
committerSascha Hauer <s.hauer@pengutronix.de>2014-07-31 07:30:51 +0200
commited98f1522d2157a0266095b00ab1481da6085337 (patch)
treec84e29e556e102fe2548688123da19cba8a23c38 /drivers/rtc/class.c
parent6d3fc76b7720c6eeb5f38cce32290cbbe28ae146 (diff)
downloadbarebox-ed98f1522d2157a0266095b00ab1481da6085337.tar.gz
barebox-ed98f1522d2157a0266095b00ab1481da6085337.tar.xz
Add a simple rtc framework
This patch adds a simple rtc framework for reading and setting board's RTC time. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/rtc/class.c')
-rw-r--r--drivers/rtc/class.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
new file mode 100644
index 0000000000..356707be2f
--- /dev/null
+++ b/drivers/rtc/class.c
@@ -0,0 +1,70 @@
+/*
+ * RTC barebox subsystem, base class
+ *
+ * Copyright (C) 2014 Antony Pavlov <antonynpavlov@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/err.h>
+#include <rtc.h>
+#include <linux/rtc.h>
+
+LIST_HEAD(rtc_list);
+EXPORT_SYMBOL(rtc_list);
+
+struct rtc_device *rtc_lookup(const char *name)
+{
+ struct rtc_device *r;
+
+ if (!name)
+ return ERR_PTR(-ENODEV);
+
+ list_for_each_entry(r, &rtc_list, list) {
+ if (!strcmp(dev_name(&r->class_dev), name))
+ return r;
+ }
+
+ return ERR_PTR(-ENODEV);
+}
+EXPORT_SYMBOL(rtc_lookup);
+
+int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
+{
+ return rtc->ops->read_time(rtc, tm);
+}
+EXPORT_SYMBOL(rtc_read_time);
+
+int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
+{
+ return rtc->ops->set_time(rtc, tm);
+}
+EXPORT_SYMBOL(rtc_set_time);
+
+int rtc_register(struct rtc_device *rtcdev)
+{
+ struct device_d *dev = &rtcdev->class_dev;
+
+ if (!rtcdev->ops)
+ return -EINVAL;
+
+ dev->id = DEVICE_ID_DYNAMIC;
+ strcpy(dev->name, "rtc");
+ if (rtcdev->dev)
+ dev->parent = rtcdev->dev;
+ platform_device_register(dev);
+
+ list_add_tail(&rtcdev->list, &rtc_list);
+
+ return 0;
+}
+EXPORT_SYMBOL(rtc_register);