All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hollis Blanchard <hollis@austin.ibm.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH] BIN_TO_BCD consolidation
Date: 12 Dec 2002 17:32:36 -0600	[thread overview]
Message-ID: <1039735956.3538.116.camel@granite.austin.ibm.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 3263 bytes --]

All I wanted to do was "secal = BIN_TO_BCD(secs % 60)" ...

Has anyone else noticed the number of BCD_TO_BIN / BIN_TO_BCD
definitions?
	egrep -lr -e "define (BCD_TO_BIN|BIN_TO_BCD)" linux/

Definitions are all over (in arch C files, arch includes, generic
includes, even a SCSI C file). They're all identical. They're almost all
wrapped with #ifndef to keep from clobbering each other.

My biggest problem is that they make an assignment:
	#define BIN_TO_BCD(val) ((val)=(((val)/10)<<4) + (val)%10)
This makes it impossible to write code like
	secal = BIN_TO_BCD(secs % 60);
because 'secs % 60' is not an lvalue.

The following patch moves all those definitions into include/linux/bcd.h
and defines BIN2BCD which doesn't make an assignment. I don't care what
it's called if that offends anyone; I just want to be able to do it. I'd
like to see BIN_TO_BCD deprecated, but maybe that's just me.

I tried to catch everything; I apologize if I missed an instance or two.
Obviously I couldn't test it all, but it builds on PPC. Comments?

-Hollis
-- 
PowerPC Linux
IBM Linux Technology Center

 arch/alpha/kernel/time.c              |    1 +
 arch/arm/kernel/time.c                |    8 --------
 arch/cris/drivers/ds1302.c            |    1 +
 arch/cris/kernel/time.c               |    1 +
 arch/i386/kernel/time.c               |    1 +
 arch/m68k/atari/time.c                |    1 +
 arch/m68k/sun3x/time.c                |    4 +---
 arch/mips/ddb5xxx/common/rtc_ds1386.c |    7 +------
 arch/mips/dec/time.c                  |    1 +
 arch/mips/kernel/old-time.c           |    1 +
 arch/mips64/sgi-ip27/ip27-rtc.c       |    1 +
 arch/mips64/sgi-ip27/ip27-timer.c     |    1 +
 arch/ppc/iSeries/mf.c                 |    1 +
 arch/ppc/platforms/chrp_time.c        |    1 +
 arch/ppc/platforms/gemini_setup.c     |    1 +
 arch/ppc/platforms/prep_time.c        |    1 +
 arch/ppc/syslib/todc_time.c           |    1 +
 arch/ppc64/kernel/mf.c                |    1 +
 arch/ppc64/kernel/rtc.c               |    1 +
 arch/sh/kernel/rtc.c                  |    9 +--------
 arch/sparc64/kernel/time.c            |    9 +--------
 arch/x86_64/kernel/time.c             |    1 +
 drivers/acorn/char/pcf8583.c          |    1 +
 drivers/acpi/sleep.c                  |    1 +
 drivers/char/rtc.c                    |    1 +
 drivers/scsi/sr_vendor.c              |    3 +--
 drivers/sgi/char/ds1286.c             |    1 +
 include/asm-arm/arch-ebsa285/time.h   |    1 +
 include/asm-cris/rtc.h                |    5 -----
 include/asm-generic/rtc.h             |    1 +
 include/asm-mips/ds1286.h             |   11 -----------
 include/asm-mips64/ds1286.h           |   11 -----------
 include/asm-mips64/m48t35.h           |    8 --------
 include/asm-ppc/m48t35.h              |    9 ---------
 include/asm-ppc/mk48t59.h             |    8 --------
 include/asm-ppc/nvram.h               |    8 --------
 include/asm-ppc/todc.h                |    8 --------
 include/asm-ppc64/nvram.h             |    8 --------
 include/linux/bcd.h                   |   20 ++++++++++++++++++++
 include/linux/mc146818rtc.h           |   11 -----------
 40 files changed, 48 insertions(+), 122 deletions(-)

[-- Attachment #1.2: bcd-consolidate.diff --]
[-- Type: text/plain, Size: 20763 bytes --]

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.744   -> 1.745  
#	include/asm-ppc/m48t35.h	1.5     -> 1.6    
#	drivers/acpi/sleep.c	1.8     -> 1.9    
#	arch/ppc/platforms/chrp_time.c	1.7     -> 1.8    
#	include/asm-cris/rtc.h	1.2     -> 1.3    
#	include/asm-ppc/mk48t59.h	1.4     -> 1.5    
#	drivers/sgi/char/ds1286.c	1.6     -> 1.7    
#	arch/mips64/sgi-ip27/ip27-timer.c	1.3     -> 1.4    
#	  drivers/char/rtc.c	1.18    -> 1.19   
#	include/asm-ppc64/nvram.h	1.2     -> 1.3    
#	include/asm-generic/rtc.h	1.1     -> 1.2    
#	arch/ppc/iSeries/mf.c	1.2     -> 1.3    
#	arch/mips64/sgi-ip27/ip27-rtc.c	1.5     -> 1.6    
#	drivers/scsi/sr_vendor.c	1.10    -> 1.11   
#	arch/i386/kernel/time.c	1.22    -> 1.23   
#	arch/ppc/platforms/prep_time.c	1.7     -> 1.8    
#	arch/sparc64/kernel/time.c	1.18    -> 1.19   
#	include/asm-mips64/m48t35.h	1.1     -> 1.2    
#	arch/ppc/platforms/gemini_setup.c	1.12    -> 1.13   
#	arch/alpha/kernel/time.c	1.11    -> 1.12   
#	arch/cris/kernel/time.c	1.6     -> 1.7    
#	arch/ppc64/kernel/rtc.c	1.3     -> 1.4    
#	include/asm-mips/ds1286.h	1.1     -> 1.2    
#	arch/m68k/sun3x/time.c	1.4     -> 1.5    
#	include/asm-mips64/ds1286.h	1.2     -> 1.3    
#	arch/x86_64/kernel/time.c	1.5     -> 1.6    
#	arch/arm/kernel/time.c	1.11    -> 1.12   
#	arch/mips/kernel/old-time.c	1.3     -> 1.4    
#	arch/ppc64/kernel/mf.c	1.3     -> 1.4    
#	include/asm-ppc/todc.h	1.1     -> 1.2    
#	arch/ppc/syslib/todc_time.c	1.4     -> 1.5    
#	arch/m68k/atari/time.c	1.3     -> 1.4    
#	arch/mips/dec/time.c	1.2     -> 1.3    
#	arch/mips/ddb5xxx/common/rtc_ds1386.c	1.1     -> 1.2    
#	include/linux/mc146818rtc.h	1.2     -> 1.3    
#	arch/sh/kernel/rtc.c	1.5     -> 1.6    
#	arch/cris/drivers/ds1302.c	1.4     -> 1.5    
#	drivers/acorn/char/pcf8583.c	1.5     -> 1.6    
#	include/asm-ppc/nvram.h	1.4     -> 1.5    
#	include/asm-arm/arch-ebsa285/time.h	1.5     -> 1.6    
#	               (new)	        -> 1.1     include/linux/bcd.h
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/12/12	hollis@granite.austin.ibm.com	1.745
# consolidate all the BCD_TO_BIN / BIN_TO_BCD definitions into bcd.h
# --------------------------------------------
#
diff -Nru a/arch/alpha/kernel/time.c b/arch/alpha/kernel/time.c
--- a/arch/alpha/kernel/time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/alpha/kernel/time.c	Thu Dec 12 17:29:52 2002
@@ -37,6 +37,7 @@
 #include <linux/irq.h>
 #include <linux/interrupt.h>
 #include <linux/init.h>
+#include <linux/bcd.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
diff -Nru a/arch/arm/kernel/time.c b/arch/arm/kernel/time.c
--- a/arch/arm/kernel/time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/arm/kernel/time.c	Thu Dec 12 17:29:52 2002
@@ -47,14 +47,6 @@
 /* change this if you have some constant time drift */
 #define USECS_PER_JIFFY	(1000000/HZ)
 
-#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
-
 static int dummy_set_rtc(void)
 {
 	return 0;
diff -Nru a/arch/cris/drivers/ds1302.c b/arch/cris/drivers/ds1302.c
--- a/arch/cris/drivers/ds1302.c	Thu Dec 12 17:29:52 2002
+++ b/arch/cris/drivers/ds1302.c	Thu Dec 12 17:29:52 2002
@@ -97,6 +97,7 @@
 #include <linux/module.h>
 #include <linux/miscdevice.h>
 #include <linux/delay.h>
+#include <linux/bcd.h>
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
diff -Nru a/arch/cris/kernel/time.c b/arch/cris/kernel/time.c
--- a/arch/cris/kernel/time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/cris/kernel/time.c	Thu Dec 12 17:29:52 2002
@@ -32,6 +32,7 @@
 #include <linux/interrupt.h>
 #include <linux/time.h>
 #include <linux/delay.h>
+#include <linux/bcd.h>
 
 #include <asm/segment.h>
 #include <asm/io.h>
diff -Nru a/arch/i386/kernel/time.c b/arch/i386/kernel/time.c
--- a/arch/i386/kernel/time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/i386/kernel/time.c	Thu Dec 12 17:29:52 2002
@@ -43,6 +43,7 @@
 #include <linux/smp.h>
 #include <linux/module.h>
 #include <linux/device.h>
+#include <linux/bcd.h>
 
 #include <asm/io.h>
 #include <asm/smp.h>
diff -Nru a/arch/m68k/atari/time.c b/arch/m68k/atari/time.c
--- a/arch/m68k/atari/time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/m68k/atari/time.c	Thu Dec 12 17:29:52 2002
@@ -15,6 +15,7 @@
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/rtc.h>
+#include <linux/bcd.h>
 
 #include <asm/rtc.h>
 
diff -Nru a/arch/m68k/sun3x/time.c b/arch/m68k/sun3x/time.c
--- a/arch/m68k/sun3x/time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/m68k/sun3x/time.c	Thu Dec 12 17:29:52 2002
@@ -11,6 +11,7 @@
 #include <linux/kernel_stat.h>
 #include <linux/interrupt.h>
 #include <linux/rtc.h>
+#include <linux/bcd.h>
 
 #include <asm/irq.h>
 #include <asm/io.h>
@@ -35,9 +36,6 @@
 #define C_READ    0x40
 #define C_SIGN    0x20
 #define C_CALIB   0x1f
-
-#define BCD_TO_BIN(val) (((val)&15) + ((val)>>4)*10)
-#define BIN_TO_BCD(val) (((val/10) << 4) | (val % 10))
 
 int sun3x_hwclk(int set, struct rtc_time *t)
 {
diff -Nru a/arch/mips/ddb5xxx/common/rtc_ds1386.c b/arch/mips/ddb5xxx/common/rtc_ds1386.c
--- a/arch/mips/ddb5xxx/common/rtc_ds1386.c	Thu Dec 12 17:29:52 2002
+++ b/arch/mips/ddb5xxx/common/rtc_ds1386.c	Thu Dec 12 17:29:52 2002
@@ -20,6 +20,7 @@
 
 #include <linux/types.h>
 #include <linux/time.h>
+#include <linux/bcd.h>
 
 #include <asm/time.h>
 #include <asm/addrspace.h>
@@ -27,12 +28,6 @@
 #include <asm/ddb5xxx/debug.h>
 
 #define	EPOCH		2000
-
-#undef BCD_TO_BIN
-#define BCD_TO_BIN(val) (((val)&15) + ((val)>>4)*10)
-
-#undef BIN_TO_BCD
-#define BIN_TO_BCD(val) ((((val)/10)<<4) + (val)%10)
 
 #define	READ_RTC(x)	*(volatile unsigned char*)(rtc_base+x)
 #define	WRITE_RTC(x, y)	*(volatile unsigned char*)(rtc_base+x) = y
diff -Nru a/arch/mips/dec/time.c b/arch/mips/dec/time.c
--- a/arch/mips/dec/time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/mips/dec/time.c	Thu Dec 12 17:29:52 2002
@@ -16,6 +16,7 @@
 #include <linux/string.h>
 #include <linux/mm.h>
 #include <linux/interrupt.h>
+#include <linux/bcd.h>
 
 #include <asm/cpu.h>
 #include <asm/bootinfo.h>
diff -Nru a/arch/mips/kernel/old-time.c b/arch/mips/kernel/old-time.c
--- a/arch/mips/kernel/old-time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/mips/kernel/old-time.c	Thu Dec 12 17:29:52 2002
@@ -16,6 +16,7 @@
 #include <linux/mm.h>
 #include <linux/interrupt.h>
 #include <linux/kernel_stat.h>
+#include <linux/bcd.h>
 
 #include <asm/bootinfo.h>
 #include <asm/cpu.h>
diff -Nru a/arch/mips64/sgi-ip27/ip27-rtc.c b/arch/mips64/sgi-ip27/ip27-rtc.c
--- a/arch/mips64/sgi-ip27/ip27-rtc.c	Thu Dec 12 17:29:52 2002
+++ b/arch/mips64/sgi-ip27/ip27-rtc.c	Thu Dec 12 17:29:52 2002
@@ -35,6 +35,7 @@
 #include <linux/poll.h>
 #include <linux/proc_fs.h>
 #include <linux/smp_lock.h>
+#include <linux/bcd.h>
 
 #include <asm/m48t35.h>
 #include <asm/sn/ioc3.h>
diff -Nru a/arch/mips64/sgi-ip27/ip27-timer.c b/arch/mips64/sgi-ip27/ip27-timer.c
--- a/arch/mips64/sgi-ip27/ip27-timer.c	Thu Dec 12 17:29:52 2002
+++ b/arch/mips64/sgi-ip27/ip27-timer.c	Thu Dec 12 17:29:52 2002
@@ -11,6 +11,7 @@
 #include <linux/param.h>
 #include <linux/timex.h>
 #include <linux/mm.h>		
+#include <linux/bcd.h>		
 
 #include <asm/pgtable.h>
 #include <asm/sgialib.h>
diff -Nru a/arch/ppc/iSeries/mf.c b/arch/ppc/iSeries/mf.c
--- a/arch/ppc/iSeries/mf.c	Thu Dec 12 17:29:52 2002
+++ b/arch/ppc/iSeries/mf.c	Thu Dec 12 17:29:52 2002
@@ -40,6 +40,7 @@
 #include <asm/iSeries/iSeries_proc.h>
 #include <asm/uaccess.h>
 #include <linux/pci.h>
+#include <linux/bcd.h>
 
 
 /*
diff -Nru a/arch/ppc/platforms/chrp_time.c b/arch/ppc/platforms/chrp_time.c
--- a/arch/ppc/platforms/chrp_time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/ppc/platforms/chrp_time.c	Thu Dec 12 17:29:52 2002
@@ -20,6 +20,7 @@
 #include <linux/kernel_stat.h>
 #include <linux/mc146818rtc.h>
 #include <linux/init.h>
+#include <linux/bcd.h>
 
 #include <asm/segment.h>
 #include <asm/io.h>
diff -Nru a/arch/ppc/platforms/gemini_setup.c b/arch/ppc/platforms/gemini_setup.c
--- a/arch/ppc/platforms/gemini_setup.c	Thu Dec 12 17:29:52 2002
+++ b/arch/ppc/platforms/gemini_setup.c	Thu Dec 12 17:29:52 2002
@@ -24,6 +24,7 @@
 #include <linux/irq.h>
 #include <linux/seq_file.h>
 #include <linux/root_dev.h>
+#include <linux/bcd.h>
 
 #include <asm/system.h>
 #include <asm/pgtable.h>
diff -Nru a/arch/ppc/platforms/prep_time.c b/arch/ppc/platforms/prep_time.c
--- a/arch/ppc/platforms/prep_time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/ppc/platforms/prep_time.c	Thu Dec 12 17:29:52 2002
@@ -19,6 +19,7 @@
 #include <linux/timex.h>
 #include <linux/kernel_stat.h>
 #include <linux/init.h>
+#include <linux/bcd.h>
 
 #include <asm/sections.h>
 #include <asm/segment.h>
diff -Nru a/arch/ppc/syslib/todc_time.c b/arch/ppc/syslib/todc_time.c
--- a/arch/ppc/syslib/todc_time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/ppc/syslib/todc_time.c	Thu Dec 12 17:29:52 2002
@@ -19,6 +19,7 @@
 #include <linux/kernel.h>
 #include <linux/time.h>
 #include <linux/timex.h>
+#include <linux/bcd.h>
 
 #include <asm/machdep.h>
 #include <asm/io.h>
diff -Nru a/arch/ppc64/kernel/mf.c b/arch/ppc64/kernel/mf.c
--- a/arch/ppc64/kernel/mf.c	Thu Dec 12 17:29:52 2002
+++ b/arch/ppc64/kernel/mf.c	Thu Dec 12 17:29:52 2002
@@ -40,6 +40,7 @@
 #include <asm/iSeries/iSeries_proc.h>
 #include <asm/uaccess.h>
 #include <linux/pci.h>
+#include <linux/bcd.h>
 
 extern struct pci_dev * iSeries_vio_dev;
 
diff -Nru a/arch/ppc64/kernel/rtc.c b/arch/ppc64/kernel/rtc.c
--- a/arch/ppc64/kernel/rtc.c	Thu Dec 12 17:29:52 2002
+++ b/arch/ppc64/kernel/rtc.c	Thu Dec 12 17:29:52 2002
@@ -32,6 +32,7 @@
 #include <linux/poll.h>
 #include <linux/proc_fs.h>
 #include <linux/spinlock.h>
+#include <linux/bcd.h>
 
 #include <asm/io.h>
 #include <asm/uaccess.h>
diff -Nru a/arch/sh/kernel/rtc.c b/arch/sh/kernel/rtc.c
--- a/arch/sh/kernel/rtc.c	Thu Dec 12 17:29:52 2002
+++ b/arch/sh/kernel/rtc.c	Thu Dec 12 17:29:52 2002
@@ -9,17 +9,10 @@
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/time.h>
+#include <linux/bcd.h>
 
 #include <asm/io.h>
 #include <asm/rtc.h>
-
-#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
 
 void sh_rtc_gettimeofday(struct timeval *tv)
 {
diff -Nru a/arch/sparc64/kernel/time.c b/arch/sparc64/kernel/time.c
--- a/arch/sparc64/kernel/time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/sparc64/kernel/time.c	Thu Dec 12 17:29:52 2002
@@ -23,6 +23,7 @@
 #include <linux/mc146818rtc.h>
 #include <linux/delay.h>
 #include <linux/profile.h>
+#include <linux/bcd.h>
 
 #include <asm/oplib.h>
 #include <asm/mostek.h>
@@ -329,14 +330,6 @@
 
 	return (data1 == data2);	/* Was the write blocked? */
 }
-
-#ifndef BCD_TO_BIN
-#define BCD_TO_BIN(val) (((val)&15) + ((val)>>4)*10)
-#endif
-
-#ifndef BIN_TO_BCD
-#define BIN_TO_BCD(val) ((((val)/10)<<4) + (val)%10)
-#endif
 
 /* Probe for the real time clock chip. */
 static void __init set_system_time(void)
diff -Nru a/arch/x86_64/kernel/time.c b/arch/x86_64/kernel/time.c
--- a/arch/x86_64/kernel/time.c	Thu Dec 12 17:29:52 2002
+++ b/arch/x86_64/kernel/time.c	Thu Dec 12 17:29:52 2002
@@ -21,6 +21,7 @@
 #include <linux/ioport.h>
 #include <linux/module.h>
 #include <linux/device.h>
+#include <linux/bcd.h>
 #include <asm/vsyscall.h>
 #include <asm/timex.h>
 
diff -Nru a/drivers/acorn/char/pcf8583.c b/drivers/acorn/char/pcf8583.c
--- a/drivers/acorn/char/pcf8583.c	Thu Dec 12 17:29:52 2002
+++ b/drivers/acorn/char/pcf8583.c	Thu Dec 12 17:29:52 2002
@@ -14,6 +14,7 @@
 #include <linux/string.h>
 #include <linux/mc146818rtc.h>
 #include <linux/init.h>
+#include <linux/bcd.h>
 
 #include "pcf8583.h"
 
diff -Nru a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
--- a/drivers/acpi/sleep.c	Thu Dec 12 17:29:52 2002
+++ b/drivers/acpi/sleep.c	Thu Dec 12 17:29:52 2002
@@ -16,6 +16,7 @@
 #include <linux/device.h>
 #include <linux/suspend.h>
 #include <linux/seq_file.h>
+#include <linux/bcd.h>
 
 #include <asm/uaccess.h>
 #include <asm/acpi.h>
diff -Nru a/drivers/char/rtc.c b/drivers/char/rtc.c
--- a/drivers/char/rtc.c	Thu Dec 12 17:29:52 2002
+++ b/drivers/char/rtc.c	Thu Dec 12 17:29:52 2002
@@ -72,6 +72,7 @@
 #include <linux/spinlock.h>
 #include <linux/sysctl.h>
 #include <linux/wait.h>
+#include <linux/bcd.h>
 
 #include <asm/current.h>
 #include <asm/uaccess.h>
diff -Nru a/drivers/scsi/sr_vendor.c b/drivers/scsi/sr_vendor.c
--- a/drivers/scsi/sr_vendor.c	Thu Dec 12 17:29:52 2002
+++ b/drivers/scsi/sr_vendor.c	Thu Dec 12 17:29:52 2002
@@ -37,6 +37,7 @@
 #include <linux/config.h>
 #include <linux/errno.h>
 #include <linux/string.h>
+#include <linux/bcd.h>
 
 #include <linux/blk.h>
 #include "scsi.h"
@@ -150,8 +151,6 @@
 
 /* This function gets called after a media change. Checks if the CD is
    multisession, asks for offset etc. */
-
-#define BCD_TO_BIN(x)    ((((int)x & 0xf0) >> 4)*10 + ((int)x & 0x0f))
 
 int sr_cd_check(struct cdrom_device_info *cdi)
 {
diff -Nru a/drivers/sgi/char/ds1286.c b/drivers/sgi/char/ds1286.c
--- a/drivers/sgi/char/ds1286.c	Thu Dec 12 17:29:52 2002
+++ b/drivers/sgi/char/ds1286.c	Thu Dec 12 17:29:52 2002
@@ -36,6 +36,7 @@
 #include <linux/poll.h>
 #include <linux/rtc.h>
 #include <linux/spinlock.h>
+#include <linux/bcd.h>
 
 #include <asm/ds1286.h>
 #include <asm/io.h>
diff -Nru a/include/asm-arm/arch-ebsa285/time.h b/include/asm-arm/arch-ebsa285/time.h
--- a/include/asm-arm/arch-ebsa285/time.h	Thu Dec 12 17:29:52 2002
+++ b/include/asm-arm/arch-ebsa285/time.h	Thu Dec 12 17:29:52 2002
@@ -18,6 +18,7 @@
 #define RTC_ALWAYS_BCD		0
 
 #include <linux/mc146818rtc.h>
+#include <linux/bcd.h>
 
 #include <asm/hardware/dec21285.h>
 #include <asm/leds.h>
diff -Nru a/include/asm-cris/rtc.h b/include/asm-cris/rtc.h
--- a/include/asm-cris/rtc.h	Thu Dec 12 17:29:52 2002
+++ b/include/asm-cris/rtc.h	Thu Dec 12 17:29:52 2002
@@ -39,11 +39,6 @@
 #define RTC_INIT() (-1)
 #endif
 
-/* conversions to and from the stupid RTC internal format */
-
-#define BCD_TO_BIN(x) x = (((x & 0xf0) >> 3) * 5 + (x & 0xf))
-#define BIN_TO_BCD(x) x = (x % 10) | ((x / 10) << 4) 
-
 /*
  * The struct used to pass data via the following ioctl. Similar to the
  * struct tm in <time.h>, but it needs to be here so that the kernel 
diff -Nru a/include/asm-generic/rtc.h b/include/asm-generic/rtc.h
--- a/include/asm-generic/rtc.h	Thu Dec 12 17:29:52 2002
+++ b/include/asm-generic/rtc.h	Thu Dec 12 17:29:52 2002
@@ -16,6 +16,7 @@
 
 #include <linux/mc146818rtc.h>
 #include <linux/rtc.h>
+#include <linux/bcd.h>
 
 #define RTC_PIE 0x40		/* periodic interrupt enable */
 #define RTC_AIE 0x20		/* alarm interrupt enable */
diff -Nru a/include/asm-mips/ds1286.h b/include/asm-mips/ds1286.h
--- a/include/asm-mips/ds1286.h	Thu Dec 12 17:29:52 2002
+++ b/include/asm-mips/ds1286.h	Thu Dec 12 17:29:52 2002
@@ -57,15 +57,4 @@
 #define RTC_IPSW		0x40
 #define RTC_TE			0x80
 
-/*
- * Conversion between binary and BCD.
- */
-#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 /* _ASM_DS1286_h */
diff -Nru a/include/asm-mips64/ds1286.h b/include/asm-mips64/ds1286.h
--- a/include/asm-mips64/ds1286.h	Thu Dec 12 17:29:52 2002
+++ b/include/asm-mips64/ds1286.h	Thu Dec 12 17:29:52 2002
@@ -56,15 +56,4 @@
 #define RTC_IPSW		0x40
 #define RTC_TE			0x80
 
-/*
- * Conversion between binary and BCD.
- */
-#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 /* _ASM_DS1286_h */
diff -Nru a/include/asm-mips64/m48t35.h b/include/asm-mips64/m48t35.h
--- a/include/asm-mips64/m48t35.h	Thu Dec 12 17:29:52 2002
+++ b/include/asm-mips64/m48t35.h	Thu Dec 12 17:29:52 2002
@@ -21,12 +21,4 @@
 #define M48T35_RTC_STOPPED  0x80
 #define M48T35_RTC_READ     0x40
 
-#ifndef BCD_TO_BIN
-#define BCD_TO_BIN(x)   ((x)=((x)&15) + ((x)>>4)*10)
-#endif
-
-#ifndef BIN_TO_BCD
-#define BIN_TO_BCD(x)   ((x)=(((x)/10)<<4) + (x)%10)
-#endif
-
 #endif
diff -Nru a/include/asm-ppc/m48t35.h b/include/asm-ppc/m48t35.h
--- a/include/asm-ppc/m48t35.h	Thu Dec 12 17:29:52 2002
+++ b/include/asm-ppc/m48t35.h	Thu Dec 12 17:29:52 2002
@@ -74,13 +74,4 @@
 #define M48T35_RTC_READ     0x40
 
 
-/* read/write conversions */
-#ifndef BCD_TO_BIN
-#define BCD_TO_BIN(x)   ((x)=((x)&15) + ((x)>>4)*10)
-#endif
-
-#ifndef BIN_TO_BCD
-#define BIN_TO_BCD(x)   ((x)=(((x)/10)<<4) + (x)%10)
-#endif
-
 #endif
diff -Nru a/include/asm-ppc/mk48t59.h b/include/asm-ppc/mk48t59.h
--- a/include/asm-ppc/mk48t59.h	Thu Dec 12 17:29:52 2002
+++ b/include/asm-ppc/mk48t59.h	Thu Dec 12 17:29:52 2002
@@ -24,12 +24,4 @@
 #define MK48T59_RTC_CONTROLB		0x1FF9
 #define MK48T59_RTC_CB_STOP		0x80
 
-#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 /* _PPC_MK48T59_H */
diff -Nru a/include/asm-ppc/nvram.h b/include/asm-ppc/nvram.h
--- a/include/asm-ppc/nvram.h	Thu Dec 12 17:29:52 2002
+++ b/include/asm-ppc/nvram.h	Thu Dec 12 17:29:52 2002
@@ -23,14 +23,6 @@
 #define MOTO_RTC_CONTROLA            0x1FF8
 #define MOTO_RTC_CONTROLB            0x1FF9
 
-#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
-
 /* PowerMac specific nvram stuffs */
 
 enum {
diff -Nru a/include/asm-ppc/todc.h b/include/asm-ppc/todc.h
--- a/include/asm-ppc/todc.h	Thu Dec 12 17:29:52 2002
+++ b/include/asm-ppc/todc.h	Thu Dec 12 17:29:52 2002
@@ -355,14 +355,6 @@
 	todc_info->flags         = clock_type ##_FLAGS;			\
 }
 
-#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
-
 extern todc_info_t *todc_info;
 
 unsigned char todc_direct_read_val(int addr);
diff -Nru a/include/asm-ppc64/nvram.h b/include/asm-ppc64/nvram.h
--- a/include/asm-ppc64/nvram.h	Thu Dec 12 17:29:52 2002
+++ b/include/asm-ppc64/nvram.h	Thu Dec 12 17:29:52 2002
@@ -28,12 +28,4 @@
 #define MOTO_RTC_CONTROLA       0x1FF8
 #define MOTO_RTC_CONTROLB       0x1FF9
 
-#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 /* _PPC64_NVRAM_H */
diff -Nru a/include/linux/bcd.h b/include/linux/bcd.h
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/include/linux/bcd.h	Thu Dec 12 17:29:52 2002
@@ -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 -Nru a/include/linux/mc146818rtc.h b/include/linux/mc146818rtc.h
--- a/include/linux/mc146818rtc.h	Thu Dec 12 17:29:52 2002
+++ b/include/linux/mc146818rtc.h	Thu Dec 12 17:29:52 2002
@@ -87,15 +87,4 @@
 # 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 */

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

             reply	other threads:[~2002-12-12 23:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-12 23:32 Hollis Blanchard [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-12-16 18:42 [PATCH] BIN_TO_BCD consolidation Hollis Blanchard
2002-12-16 19:53 ` Hollis Blanchard

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=1039735956.3538.116.camel@granite.austin.ibm.com \
    --to=hollis@austin.ibm.com \
    --cc=linux-kernel@vger.kernel.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.