From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [RFC v3 1/5] lib: import 'bcd' from linux-3.15
Date: Tue, 15 Jul 2014 00:48:32 +0400 [thread overview]
Message-ID: <1405370916-6828-2-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1405370916-6828-1-git-send-email-antonynpavlov@gmail.com>
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
include/linux/bcd.h | 22 ++++++++++++++++++++++
lib/Makefile | 1 +
lib/bcd.c | 14 ++++++++++++++
3 files changed, 37 insertions(+)
diff --git a/include/linux/bcd.h b/include/linux/bcd.h
new file mode 100644
index 0000000..18fff11
--- /dev/null
+++ b/include/linux/bcd.h
@@ -0,0 +1,22 @@
+#ifndef _BCD_H
+#define _BCD_H
+
+#include <linux/compiler.h>
+
+#define bcd2bin(x) \
+ (__builtin_constant_p((u8 )(x)) ? \
+ const_bcd2bin(x) : \
+ _bcd2bin(x))
+
+#define bin2bcd(x) \
+ (__builtin_constant_p((u8 )(x)) ? \
+ const_bin2bcd(x) : \
+ _bin2bcd(x))
+
+#define const_bcd2bin(x) (((x) & 0x0f) + ((x) >> 4) * 10)
+#define const_bin2bcd(x) ((((x) / 10) << 4) + (x) % 10)
+
+unsigned _bcd2bin(unsigned char val) __attribute_const__;
+unsigned char _bin2bcd(unsigned val) __attribute_const__;
+
+#endif /* _BCD_H */
diff --git a/lib/Makefile b/lib/Makefile
index 48c953d..18a99a7 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,3 +1,4 @@
+obj-y += bcd.o
obj-$(CONFIG_BOOTSTRAP) += bootstrap/
obj-y += ctype.o
obj-y += rbtree.o
diff --git a/lib/bcd.c b/lib/bcd.c
new file mode 100644
index 0000000..b072d50
--- /dev/null
+++ b/lib/bcd.c
@@ -0,0 +1,14 @@
+#include <linux/bcd.h>
+#include <module.h>
+
+unsigned _bcd2bin(unsigned char val)
+{
+ return (val & 0x0f) + (val >> 4) * 10;
+}
+EXPORT_SYMBOL(_bcd2bin);
+
+unsigned char _bin2bcd(unsigned val)
+{
+ return ((val / 10) << 4) + val % 10;
+}
+EXPORT_SYMBOL(_bin2bcd);
--
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-14 20:49 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-14 20:48 [RFC v3 0/5] add rtc support Antony Pavlov
2014-07-14 20:48 ` Antony Pavlov [this message]
2014-07-14 20:48 ` [RFC v3 2/5] " Antony Pavlov
2014-07-14 20:48 ` [RFC v3 3/5] rtc: import ds1307 driver from linux-3.15 Antony Pavlov
2014-07-14 20:48 ` [RFC v3 4/5] commands: add hwclock Antony Pavlov
2014-07-18 5:44 ` Sascha Hauer
2014-07-18 7:36 ` Antony Pavlov
2014-07-19 19:02 ` Holger Schurig
2014-07-20 5:55 ` Antony Pavlov
2014-07-21 6:41 ` Sascha Hauer
2014-07-21 7:10 ` Antony Pavlov
2014-07-21 8:11 ` Sascha Hauer
2014-07-21 15:41 ` Antony Pavlov
2014-07-21 17:34 ` Antony Pavlov
2014-07-24 19:17 ` Antony Pavlov
2014-07-25 7:38 ` Sascha Hauer
2014-07-25 7:39 ` Sascha Hauer
2014-07-14 20:48 ` [RFC v3 5/5] ARM: versatilepb_defconfig: enable RTC support 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=1405370916-6828-2-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.