From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [RFC 5/5] commands: add hwclock
Date: Thu, 10 Jul 2014 12:33:19 +0400 [thread overview]
Message-ID: <1404981199-21293-6-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1404981199-21293-1-git-send-email-antonynpavlov@gmail.com>
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
commands/Kconfig | 8 ++++++++
commands/Makefile | 1 +
commands/hwclock.c | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/commands/Kconfig b/commands/Kconfig
index 61816f5..a594f7c 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1691,6 +1691,14 @@ config CMD_GPIO
Usage: gpio_set_value GPIO VALUE
+config CMD_HWCLOCK
+ bool
+ depends on RTC_CLASS
+ prompt "hwclock command"
+ default y
+ help
+ The lspci command allows to query or set the hardware clock (RTC).
+
config CMD_I2C
bool
depends on I2C
diff --git a/commands/Makefile b/commands/Makefile
index d42aca5..44dd9d4 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -100,3 +100,4 @@ obj-$(CONFIG_CMD_MENUTREE) += menutree.o
obj-$(CONFIG_CMD_2048) += 2048.o
obj-$(CONFIG_CMD_REGULATOR) += regulator.o
obj-$(CONFIG_CMD_LSPCI) += lspci.o
+obj-$(CONFIG_CMD_HWCLOCK) += hwclock.o
diff --git a/commands/hwclock.c b/commands/hwclock.c
new file mode 100644
index 0000000..4671fee
--- /dev/null
+++ b/commands/hwclock.c
@@ -0,0 +1,37 @@
+#include <common.h>
+#include <command.h>
+#include <getopt.h>
+#include <linux/err.h>
+#include <rtc.h>
+#include <linux/rtc.h>
+
+static int do_hwclock(int argc, char *argv[])
+{
+ struct rtc_device *r;
+ struct rtc_time tm;
+ char *rtc_name;
+
+ rtc_name = "rtc0";
+
+ if (argc > 1)
+ rtc_name = argv[1];
+
+ r = rtc_lookup(rtc_name);
+ if (IS_ERR(r))
+ return PTR_ERR(r);
+
+ rtc_read_time(r, &tm);
+
+ printf("%02d:%02d:%02d %02d-%02d-%04d\n",
+ tm.tm_hour, tm.tm_min, tm.tm_sec,
+ tm.tm_mday, tm.tm_mon, tm.tm_year);
+
+ return 0;
+}
+
+BAREBOX_CMD_START(hwclock)
+ .cmd = do_hwclock,
+ BAREBOX_CMD_DESC("query or set the hardware clock (RTC)")
+ BAREBOX_CMD_OPTS("[RTC]")
+ BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
+BAREBOX_CMD_END
--
2.0.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2014-07-10 8:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-10 8:33 [RFC 0/5] add rtc support Antony Pavlov
2014-07-10 8:33 ` [RFC 1/5] lib: import 'bcd' from linux-3.15 Antony Pavlov
2014-07-10 8:33 ` [RFC 2/5] add rtc support Antony Pavlov
2014-07-10 21:40 ` Sascha Hauer
2014-07-11 5:31 ` Antony Pavlov
2014-07-10 8:33 ` [RFC 3/5] i2c: import SMBus stuff from linux Antony Pavlov
2014-07-10 8:33 ` [RFC 4/5] rtc: add ds1307 support Antony Pavlov
2014-07-10 8:33 ` Antony Pavlov [this message]
2014-07-10 21:45 ` [RFC 5/5] commands: add hwclock Sascha Hauer
2014-07-11 5:59 ` Antony Pavlov
2014-07-11 6:07 ` Sascha Hauer
2014-07-11 5:37 ` [RFC 0/5] add rtc support Sascha Hauer
2014-07-11 6:12 ` Antony Pavlov
2014-07-11 6:10 ` Sascha Hauer
2014-07-11 6:32 ` Antony Pavlov
2014-07-11 6:37 ` Sascha Hauer
2014-07-11 11:27 ` Antony Pavlov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1404981199-21293-6-git-send-email-antonynpavlov@gmail.com \
--to=antonynpavlov@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox