summaryrefslogtreecommitdiffstats
path: root/include/time-utils.h
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2015-07-03 13:49:22 +1000
committerStewart Smith <stewart@linux.vnet.ibm.com>2015-07-03 17:09:44 +1000
commit642a2f8a27629ef0782b29d7a719cab0688456f8 (patch)
treefa37ea55b76dae1278ddd4f132f463366ea34286 /include/time-utils.h
parentef50b5f5ad2834996eabc7e10885659a1ef65196 (diff)
downloadblackbird-skiboot-642a2f8a27629ef0782b29d7a719cab0688456f8.tar.gz
blackbird-skiboot-642a2f8a27629ef0782b29d7a719cab0688456f8.zip
plat/qemu: Add LPC based RTC support
This adds a driver for standard CMOS RTC chips and use it from the QEMU platform. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'include/time-utils.h')
-rw-r--r--include/time-utils.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/time-utils.h b/include/time-utils.h
index 721b6f7e..e0a9a98d 100644
--- a/include/time-utils.h
+++ b/include/time-utils.h
@@ -20,6 +20,24 @@
#include <stdint.h>
#include <time.h>
+/* BCD conversion utilities. MSB is byte 3, LSB is byte 0 */
+
+static inline unsigned int bcd_byte(uint32_t bcd, int byteno)
+{
+ bcd >>= byteno * 8;
+ return (bcd >> 4 & 0xf) * 10 + (bcd & 0xf);
+}
+
+static inline uint32_t int_to_bcd2(unsigned int x)
+{
+ return (((x / 10) << 4) & 0xf0) | (x % 10);
+}
+
+static inline uint32_t int_to_bcd4(unsigned int x)
+{
+ return int_to_bcd2(x / 100) << 8 | int_to_bcd2(x % 100);
+}
+
void tm_to_datetime(struct tm *tm, uint32_t *y_m_d, uint64_t *h_m_s_m);
void datetime_to_tm(uint32_t y_m_d, uint64_t h_m_s_m, struct tm *tm);
OpenPOWER on IntegriCloud