]> git.hungrycats.org Git - linux/commitdiff
[PATCH] BIN_TO_BCD consolidation
authorAndrew Morton <akpm@digeo.com>
Mon, 30 Dec 2002 05:40:19 +0000 (21:40 -0800)
committerLinus Torvalds <torvalds@home.transmeta.com>
Mon, 30 Dec 2002 05:40:19 +0000 (21:40 -0800)
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.

40 files changed:
arch/alpha/kernel/time.c
arch/arm/kernel/time.c
arch/cris/drivers/ds1302.c
arch/cris/kernel/time.c
arch/i386/kernel/time.c
arch/m68k/atari/time.c
arch/m68k/sun3x/time.c
arch/mips/ddb5xxx/common/rtc_ds1386.c
arch/mips/dec/time.c
arch/mips/kernel/old-time.c
arch/mips64/sgi-ip27/ip27-rtc.c
arch/mips64/sgi-ip27/ip27-timer.c
arch/ppc/iSeries/mf.c
arch/ppc/platforms/chrp_time.c
arch/ppc/platforms/gemini_setup.c
arch/ppc/platforms/prep_time.c
arch/ppc/syslib/todc_time.c
arch/ppc64/kernel/mf.c
arch/ppc64/kernel/rtc.c
arch/sh/kernel/rtc.c
arch/sparc64/kernel/time.c
arch/x86_64/kernel/time.c
drivers/acorn/char/pcf8583.c
drivers/acpi/sleep.c
drivers/char/rtc.c
drivers/scsi/sr_vendor.c
drivers/sgi/char/ds1286.c
include/asm-arm/arch-ebsa285/time.h
include/asm-cris/rtc.h
include/asm-generic/rtc.h
include/asm-mips/ds1286.h
include/asm-mips64/ds1286.h
include/asm-mips64/m48t35.h
include/asm-ppc/m48t35.h
include/asm-ppc/mk48t59.h
include/asm-ppc/nvram.h
include/asm-ppc/todc.h
include/asm-ppc64/nvram.h
include/linux/bcd.h [new file with mode: 0644]
include/linux/mc146818rtc.h

index 4ccda6679804b7bd4dbdd03888aeed346d271c56..03fed82384dd81a40395646d6b72328ad4031ef3 100644 (file)
@@ -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>
index 2af6dbda06d52d0c494c4c6a94264d389fc31638..685d59b08623a6de06be2998ca645420747b728b 100644 (file)
@@ -47,14 +47,6 @@ EXPORT_SYMBOL(rtc_lock);
 /* 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;
index 867f3c63ba0c876c8644a26e38f0a81044157628..23814c3843d3f8d5b68f9476ca5186aab56f824d 100644 (file)
@@ -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>
index 1ee0bbfeab7e59e09ceba045229c104767ac6e85..0541e25a48aad9f027fccbf51096c71baa7ee32f 100644 (file)
@@ -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>
index 2040b6039df8a136510b5ea4c9dadb3a7c94b906..ef1cfa33b1542a2808a9d4771e0f9608e2c38ca7 100644 (file)
@@ -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>
index 98e344a0111ce8e9f05d2a7eaf6faf5786edd62d..8a26073adb233b13d1e57c90cb74d676cd584012 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/interrupt.h>
 #include <linux/init.h>
 #include <linux/rtc.h>
+#include <linux/bcd.h>
 
 #include <asm/rtc.h>
 
index 683a34e815d49cae6fa4a4cc5c386b51d04fb846..b9b334e0db7ff85cd62de91ba653fa65564f0d0a 100644 (file)
@@ -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>
@@ -36,9 +37,6 @@
 #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)
 {
        volatile struct mostek_dt *h = 
@@ -49,23 +47,23 @@ int sun3x_hwclk(int set, struct rtc_time *t)
        
        if(set) {
                h->csr |= C_WRITE;
-               h->sec = BIN_TO_BCD(t->tm_sec);
-               h->min = BIN_TO_BCD(t->tm_min);
-               h->hour = BIN_TO_BCD(t->tm_hour);
-               h->wday = BIN_TO_BCD(t->tm_wday);
-               h->mday = BIN_TO_BCD(t->tm_mday);
-               h->month = BIN_TO_BCD(t->tm_mon);
-               h->year = BIN_TO_BCD(t->tm_year);
+               h->sec = BIN2BCD(t->tm_sec);
+               h->min = BIN2BCD(t->tm_min);
+               h->hour = BIN2BCD(t->tm_hour);
+               h->wday = BIN2BCD(t->tm_wday);
+               h->mday = BIN2BCD(t->tm_mday);
+               h->month = BIN2BCD(t->tm_mon);
+               h->year = BIN2BCD(t->tm_year);
                h->csr &= ~C_WRITE;
        } else {
                h->csr |= C_READ;
-               t->tm_sec = BCD_TO_BIN(h->sec);
-               t->tm_min = BCD_TO_BIN(h->min);
-               t->tm_hour = BCD_TO_BIN(h->hour);
-               t->tm_wday = BCD_TO_BIN(h->wday);
-               t->tm_mday = BCD_TO_BIN(h->mday);
-               t->tm_mon = BCD_TO_BIN(h->month);
-               t->tm_year = BCD_TO_BIN(h->year);
+               t->tm_sec = BCD2BIN(h->sec);
+               t->tm_min = BCD2BIN(h->min);
+               t->tm_hour = BCD2BIN(h->hour);
+               t->tm_wday = BCD2BIN(h->wday);
+               t->tm_mday = BCD2BIN(h->mday);
+               t->tm_mon = BCD2BIN(h->month);
+               t->tm_year = BCD2BIN(h->year);
                h->csr &= ~C_READ;
        }
 
index 91ea9749eda0ec152d162143f401ceeb17e763e4..e8b37abad54328bb4b2038ba30d6c8821789b26f 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <linux/types.h>
 #include <linux/time.h>
+#include <linux/bcd.h>
 
 #include <asm/time.h>
 #include <asm/addrspace.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
 
@@ -52,11 +47,11 @@ rtc_ds1386_get_time(void)
        WRITE_RTC(0xB, byte);
 
        /* read time data */
-       year = BCD_TO_BIN(READ_RTC(0xA)) + EPOCH;
-       month = BCD_TO_BIN(READ_RTC(0x9) & 0x1f);
-       day = BCD_TO_BIN(READ_RTC(0x8));
-       minute = BCD_TO_BIN(READ_RTC(0x2));
-       second = BCD_TO_BIN(READ_RTC(0x1));
+       year = BCD2BIN(READ_RTC(0xA)) + EPOCH;
+       month = BCD2BIN(READ_RTC(0x9) & 0x1f);
+       day = BCD2BIN(READ_RTC(0x8));
+       minute = BCD2BIN(READ_RTC(0x2));
+       second = BCD2BIN(READ_RTC(0x1));
 
        /* hour is special - deal with it later */
        temp = READ_RTC(0x4);
@@ -68,11 +63,11 @@ rtc_ds1386_get_time(void)
        /* calc hour */
        if (temp & 0x40) {
                /* 12 hour format */
-               hour = BCD_TO_BIN(temp & 0x1f);
+               hour = BCD2BIN(temp & 0x1f);
                if (temp & 0x20) hour += 12;            /* PM */
        } else {
                /* 24 hour format */
-               hour = BCD_TO_BIN(temp & 0x3f);
+               hour = BCD2BIN(temp & 0x3f);
        }
 
        return mktime(year, month, day, hour, minute, second);
@@ -95,19 +90,19 @@ rtc_ds1386_set_time(unsigned long t)
        to_tm(t, &tm);
 
        /* check each field one by one */
-       year = BIN_TO_BCD(tm.tm_year - EPOCH);
+       year = BIN2BCD(tm.tm_year - EPOCH);
        if (year != READ_RTC(0xA)) {
                WRITE_RTC(0xA, year);
        }
 
        temp = READ_RTC(0x9);
-       month = BIN_TO_BCD(tm.tm_mon);
+       month = BIN2BCD(tm.tm_mon);
        if (month != (temp & 0x1f)) {
                WRITE_RTC( 0x9,
                           (month & 0x1f) | (temp & ~0x1f) );
        }
 
-       day = BIN_TO_BCD(tm.tm_mday);
+       day = BIN2BCD(tm.tm_mday);
        if (day != READ_RTC(0x8)) {
                WRITE_RTC(0x8, day);
        }
@@ -117,22 +112,22 @@ rtc_ds1386_set_time(unsigned long t)
                /* 12 hour format */
                hour = 0x40;
                if (tm.tm_hour > 12) {
-                       hour |= 0x20 | (BIN_TO_BCD(hour-12) & 0x1f);
+                       hour |= 0x20 | (BIN2BCD(hour-12) & 0x1f);
                } else {
-                       hour |= BIN_TO_BCD(tm.tm_hour);
+                       hour |= BIN2BCD(tm.tm_hour);
                }
        } else {
                /* 24 hour format */
-               hour = BIN_TO_BCD(tm.tm_hour) & 0x3f;
+               hour = BIN2BCD(tm.tm_hour) & 0x3f;
        }
        if (hour != temp) WRITE_RTC(0x4, hour);
 
-       minute = BIN_TO_BCD(tm.tm_min);
+       minute = BIN2BCD(tm.tm_min);
        if (minute != READ_RTC(0x2)) {
                WRITE_RTC(0x2, minute);
        }
 
-       second = BIN_TO_BCD(tm.tm_sec);
+       second = BIN2BCD(tm.tm_sec);
        if (second != READ_RTC(0x1)) {
                WRITE_RTC(0x1, second);
        }
index 9188af33f6786616dbd6019869d9ee7ed7cacf43..c7c5640a7d615f16f707a4730cd865c7df2d3d66 100644 (file)
@@ -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>
index a58202bfae6f1d6ad51c89e12d0e14802335d61a..4793acd60c1988bb1d8defe33cec59c04c00336e 100644 (file)
@@ -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>
index f7983dbb570fb8a3407381768bc7a2c85a7ccd26..3a71a4b8b2fdd34962debc4229ecbb610659dc42 100644 (file)
@@ -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>
index e0251cd0d379126466bb2075b45c8c35b78c0627..d4ed43d11d6677a50ebd253564ec4646eaec1ce0 100644 (file)
@@ -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>
index aa822233e43cfc3ddda92dc6550854ce572442db..59b1782797345bee17f929cc9bf313d2ac3ef71c 100644 (file)
@@ -40,6 +40,7 @@
 #include <asm/iSeries/iSeries_proc.h>
 #include <asm/uaccess.h>
 #include <linux/pci.h>
+#include <linux/bcd.h>
 
 
 /*
index 9a5333428f2c4b926cfc39c87e61435583c503e1..a7e4e5a81429ea85a5fdcf956d612877721a0ca6 100644 (file)
@@ -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>
index 41458519f54b3e14277923450d68560775da27c3..dc976899f604ad00e688e3c67be4070d7a95c9b2 100644 (file)
@@ -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>
index 49ac7d2638ed0353978b4bd9a965746a04ddfc12..4c75081fd17864c588dcfba441c995fe71c20052 100644 (file)
@@ -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>
index 9591c7ee0eef2a8cf836dadece2c6b29d9af241b..85ee80b4e5811606dfe45955607f1b62827c2a63 100644 (file)
@@ -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>
index 3999ea9ee8133a414263239527f79fe42dcde64c..876570387150b4a465a21a08f358d89da6c8993c 100644 (file)
@@ -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;
 
index 5ace02abc1bc2315efb19fec2aab0d20ac388c98..c0f714551a0dd2eac821a1e0dcda18cc194815e6 100644 (file)
@@ -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>
index 6eb2f2cb4a8aaca6c8a88ab898ad4f8f441e656d..08a029f5e3c1b181e33741294f873b722acc74d9 100644 (file)
@@ -9,18 +9,11 @@
 #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)
 {
        unsigned int sec128, sec, min, hr, wk, day, mon, yr, yr100;
index cdb33d996328a42c8b10aeb1598aa1ef1db2b9bb..3c48ed49ea5ad6221bb520093450e685cd4d2782 100644 (file)
@@ -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>
@@ -330,14 +331,6 @@ static int __init has_low_battery(void)
        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)
 {
index 67d2cf41c2ed2f7f93843156ed7d15bfeb88ead0..65a2c76f002169903f4797eb37955122e4d4496c 100644 (file)
@@ -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>
 
index 115078c60d4cd3bd6a1d4914b6f98ab334555e02..05ed2e52c1906200fbdb5539ca962b69b238dd0e 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/string.h>
 #include <linux/mc146818rtc.h>
 #include <linux/init.h>
+#include <linux/bcd.h>
 
 #include "pcf8583.h"
 
index e84ceeb85eebb554cc38171ce33fda0ea0ae8cc9..cdb4fe6d5b4ffcd99314cc6b255ee2018e95d2b7 100644 (file)
@@ -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>
index 75dffcb2b48c705e61bdde6bae9e78ddee65143d..1e5f4c6ec5a15fa5110d53155a227ae2839cfe5f 100644 (file)
@@ -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>
index 76a701bb4502eadde7352445d893c9121ef13cde..690d8feafe6ee22e551bac07039f9c59778b4f6b 100644 (file)
@@ -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"
@@ -151,8 +152,6 @@ int sr_set_blocklength(Scsi_CD *cd, int blocklength)
 /* 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)
 {
        Scsi_CD *cd = cdi->handle;
@@ -223,9 +222,9 @@ int sr_cd_check(struct cdrom_device_info *cdi)
                                no_multi = 1;
                                break;
                        }
-                       min = BCD_TO_BIN(buffer[15]);
-                       sec = BCD_TO_BIN(buffer[16]);
-                       frame = BCD_TO_BIN(buffer[17]);
+                       min = BCD2BIN(buffer[15]);
+                       sec = BCD2BIN(buffer[16]);
+                       frame = BCD2BIN(buffer[17]);
                        sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame;
                        break;
                }
@@ -252,9 +251,9 @@ int sr_cd_check(struct cdrom_device_info *cdi)
                        }
                        if (rc != 0)
                                break;
-                       min = BCD_TO_BIN(buffer[1]);
-                       sec = BCD_TO_BIN(buffer[2]);
-                       frame = BCD_TO_BIN(buffer[3]);
+                       min = BCD2BIN(buffer[1]);
+                       sec = BCD2BIN(buffer[2]);
+                       frame = BCD2BIN(buffer[3]);
                        sector = min * CD_SECS * CD_FRAMES + sec * CD_FRAMES + frame;
                        if (sector)
                                sector -= CD_MSF_OFFSET;
index ae11cb96484bb18770df7ccdabc07c3da2aed33a..d98e2a63ec635a129ff4dc89cd70e38a731227f7 100644 (file)
@@ -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>
index a500b9c08b8b1899832e6aa4c725c037cdb1f573..feb175ee806b98a2a510c59b94b1b3b0637cef80 100644 (file)
@@ -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>
index 239b1bb22839698f060b97db982b4dc1e3678a7d..72ff33a48a8d78ac7b83db6e592c9bc1472b4c96 100644 (file)
 #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 
index ebdeefd49822d9b8aa9d5457c1495fa32459042c..845641b06b0c30474b6cdcf6b48ea4f115b7532f 100644 (file)
@@ -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 */
index 2d60fb89d328ef46aacf8e61a45431e97a46333f..92686b110dc937b82d1bd686d027c7c1693c674b 100644 (file)
 #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 */
index 5280850b374a157afe8c0a3b847ef610ac3d487b..56af9b10d01b969026c5278f83b1cab27ee3c8aa 100644 (file)
 #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 */
index 1137603979574246d86147a0a69362d4fbadf8e3..865ec0c379e3c76e63b44e67fe9af6a53a1e99a1 100644 (file)
@@ -21,12 +21,4 @@ struct m48t35_rtc {
 #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
index 86b8be5987a8cdcaa32724e4fd013085285f3761..97d2129f8d5377d7cc8727990d9c001b16f0a7d7 100644 (file)
 #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
index 4700fcdc824cdb38597435e9a1dbb2a1df701d9c..6a0ed6fc2d5695926f952a3a0f6303f32171066d 100644 (file)
 #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 */
index 7f6fc08b18685761f206ac2dc1c2dfe57b381937..47e4dfc74a779fd714dd537b13d45487b3ab02d8 100644 (file)
 #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 {
index 9b4d58e9efebdc0a8efce60cbe16052a0899eba9..3f72c47e09bf48f5fd50c256f7ec90fcad85e548 100644 (file)
@@ -355,14 +355,6 @@ typedef struct {
        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);
index 46ef2c3106d32b18a19c0f4a83b7a545e0d5b96b..1c304357c223721025a90c440dd6cb2ebbcda7ce 100644 (file)
 #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 --git a/include/linux/bcd.h b/include/linux/bcd.h
new file mode 100644 (file)
index 0000000..c545308
--- /dev/null
@@ -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 */
index 2ec35699a8e871e34eb03edf5ea00350ea6b6248..cde7dbae375ea0696e52aa8887c82664f694ab2e 100644 (file)
@@ -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 */