summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorAndrew Morton <akpm@digeo.com>2002-12-29 21:40:19 -0800
committerLinus Torvalds <torvalds@home.transmeta.com>2002-12-29 21:40:19 -0800
commitdb8f4c7eda8a1594c165805c1717e13af8cfb4a9 (patch)
treeeb63a30af4f65c71f4f89087e2ff49e52aa99c6f /include/linux
parentfe04e9451e5a159247cf9f03c615a4273ac0c571 (diff)
[PATCH] BIN_TO_BCD consolidation
Cleanup patch from Hollis Blanchard <hollis@austin.ibm.com> We have a large number of private implementations of BIN_TO_BCD and BCD_TO_BIN, which are all the same. And a lot of them are inflexible because they modify their arg: #define BIN_TO_BCD(val) ((val)=(((val)/10)<<4) + (val)%10) - Create (in <linux/bcd.h> a generic BIN2BCD/BCD2BIN which does not modify its arg - Create generic BIN_TO_BCD/BCD_TO_BIN which uses the above - Update lots of callers to use the new generic version.
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/bcd.h20
-rw-r--r--include/linux/mc146818rtc.h11
2 files changed, 20 insertions, 11 deletions
diff --git a/include/linux/bcd.h b/include/linux/bcd.h
new file mode 100644
index 000000000000..c545308125b0
--- /dev/null
+++ b/include/linux/bcd.h
@@ -0,0 +1,20 @@
+/* Permission is hereby granted to copy, modify and redistribute this code
+ * in terms of the GNU Library General Public License, Version 2 or later,
+ * at your option.
+ */
+
+/* macros to translate to/from binary and binary-coded decimal (frequently
+ * found in RTC chips).
+ */
+
+#ifndef _BCD_H
+#define _BCD_H
+
+#define BCD2BIN(val) (((val) & 0x0f) + ((val)>>4)*10)
+#define BIN2BCD(val) ((((val)/10)<<4) + (val)%10)
+
+/* backwards compat */
+#define BCD_TO_BIN(val) ((val)=BCD2BIN(val))
+#define BIN_TO_BCD(val) ((val)=BIN2BCD(val))
+
+#endif /* _BCD_H */
diff --git a/include/linux/mc146818rtc.h b/include/linux/mc146818rtc.h
index 2ec35699a8e8..cde7dbae375e 100644
--- a/include/linux/mc146818rtc.h
+++ b/include/linux/mc146818rtc.h
@@ -87,15 +87,4 @@ extern spinlock_t rtc_lock; /* serialize CMOS RAM access */
# define RTC_VRT 0x80 /* valid RAM and time */
/**********************************************************************/
-/* example: !(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY)
- * determines if the following two #defines are needed
- */
-#ifndef BCD_TO_BIN
-#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
-#endif
-
-#ifndef BIN_TO_BCD
-#define BIN_TO_BCD(val) ((val)=(((val)/10)<<4) + (val)%10)
-#endif
-
#endif /* _MC146818RTC_H */