IEI Kino added to IEI mainboard Kconfig. I missed this in r5812
[coreboot.git] / src / pc80 / mc146818rtc.c
index cc37f04f85dedd7c12cf823a65f528c82ffe4b6a..23b834c06ad5994b3cdb0606392424e84e27a355 100644 (file)
@@ -1,19 +1,8 @@
 #include <console/console.h>
-#include <arch/io.h>
 #include <pc80/mc146818rtc.h>
-#include <boot/linuxbios_tables.h>
+#include <boot/coreboot_tables.h>
 #include <string.h>
 
-#define CMOS_READ(addr) ({ \
-outb((addr),RTC_PORT(0)); \
-inb(RTC_PORT(1)); \
-})
-
-#define CMOS_WRITE(val, addr) ({ \
-outb((addr),RTC_PORT(0)); \
-outb((val),RTC_PORT(1)); \
-})
-
 /* control registers - Moto names
  */
 #define RTC_REG_A              10
@@ -83,18 +72,17 @@ outb((val),RTC_PORT(1)); \
 # define RTC_VRT 0x80          /* valid RAM and time */
 /**********************************************************************/
 
-
-
+#if CONFIG_USE_OPTION_TABLE
 static int rtc_checksum_valid(int range_start, int range_end, int cks_loc)
 {
        int i;
        unsigned sum, old_sum;
        sum = 0;
        for(i = range_start; i <= range_end; i++) {
-               sum += CMOS_READ(i);
+               sum += cmos_read(i);
        }
        sum = (~sum)&0x0ffff;
-       old_sum = ((CMOS_READ(cks_loc)<<8) | CMOS_READ(cks_loc+1))&0x0ffff;
+       old_sum = ((cmos_read(cks_loc)<<8) | cmos_read(cks_loc+1))&0x0ffff;
        return sum == old_sum;
 }
 
@@ -104,31 +92,36 @@ static void rtc_set_checksum(int range_start, int range_end, int cks_loc)
        unsigned sum;
        sum = 0;
        for(i = range_start; i <= range_end; i++) {
-               sum += CMOS_READ(i);
+               sum += cmos_read(i);
        }
        sum = ~(sum & 0x0ffff);
-       CMOS_WRITE(((sum >> 8) & 0x0ff), cks_loc);
-       CMOS_WRITE(((sum >> 0) & 0x0ff), cks_loc+1);
+       cmos_write(((sum >> 8) & 0x0ff), cks_loc);
+       cmos_write(((sum >> 0) & 0x0ff), cks_loc+1);
 }
+#endif
 
+#if CONFIG_ARCH_X86
 #define RTC_CONTROL_DEFAULT (RTC_24H)
 #define RTC_FREQ_SELECT_DEFAULT (RTC_REF_CLCK_32KHZ | RTC_RATE_1024HZ)
-
-#if 0 /* alpha setup */
-#undef RTC_CONTROL_DEFAULT
-#undef RTC_FREQ_SELECT_DEFAULT
+#else
+#if CONFIG_ARCH_ALPHA
 #define RTC_CONTROL_DEFAULT (RTC_SQWE | RTC_24H)
 #define RTC_FREQ_SELECT_DEFAULT (RTC_REF_CLCK_32KHZ | RTC_RATE_1024HZ)
 #endif
+#endif
 
 void rtc_init(int invalid)
 {
+#if CONFIG_USE_OPTION_TABLE
        unsigned char x;
        int cmos_invalid, checksum_invalid;
+#endif
+
+       printk(BIOS_DEBUG, "RTC Init\n");
 
-       printk_debug("RTC Init\n");
+#if CONFIG_USE_OPTION_TABLE
        /* See if there has been a CMOS power problem. */
-       x = CMOS_READ(RTC_VALID);
+       x = cmos_read(RTC_VALID);
        cmos_invalid = !(x & RTC_VRT);
 
        /* See if there is a CMOS checksum error */
@@ -136,49 +129,55 @@ void rtc_init(int invalid)
                        PC_CKS_RANGE_END,PC_CKS_LOC);
 
        if (invalid || cmos_invalid || checksum_invalid) {
-               printk_warning("RTC:%s%s%s zeroing cmos\n",
-                       invalid?" Clear requested":"", 
+               printk(BIOS_WARNING, "RTC:%s%s%s zeroing cmos\n",
+                       invalid?" Clear requested":"",
                        cmos_invalid?" Power Problem":"",
                        checksum_invalid?" Checksum invalid":"");
 #if 0
-               CMOS_WRITE(0, 0x01);
-               CMOS_WRITE(0, 0x03);
-               CMOS_WRITE(0, 0x05);
+               cmos_write(0, 0x01);
+               cmos_write(0, 0x03);
+               cmos_write(0, 0x05);
                for(i = 10; i < 48; i++) {
-                       CMOS_WRITE(0, i);
+                       cmos_write(0, i);
                }
-               
+
                if (cmos_invalid) {
                        /* Now setup a default date of Sat 1 January 2000 */
-                       CMOS_WRITE(0, 0x00); /* seconds */
-                       CMOS_WRITE(0, 0x02); /* minutes */
-                       CMOS_WRITE(1, 0x04); /* hours */
-                       CMOS_WRITE(7, 0x06); /* day of week */
-                       CMOS_WRITE(1, 0x07); /* day of month */
-                       CMOS_WRITE(1, 0x08); /* month */
-                       CMOS_WRITE(0, 0x09); /* year */
+                       cmos_write(0, 0x00); /* seconds */
+                       cmos_write(0, 0x02); /* minutes */
+                       cmos_write(1, 0x04); /* hours */
+                       cmos_write(7, 0x06); /* day of week */
+                       cmos_write(1, 0x07); /* day of month */
+                       cmos_write(1, 0x08); /* month */
+                       cmos_write(0, 0x09); /* year */
                }
 #endif
        }
+#endif
+
+       /* Setup the real time clock */
+       cmos_write(RTC_CONTROL_DEFAULT, RTC_CONTROL);
+       /* Setup the frequency it operates at */
+       cmos_write(RTC_FREQ_SELECT_DEFAULT, RTC_FREQ_SELECT);
+
+#if CONFIG_USE_OPTION_TABLE
        /* See if there is a LB CMOS checksum error */
        checksum_invalid = !rtc_checksum_valid(LB_CKS_RANGE_START,
                        LB_CKS_RANGE_END,LB_CKS_LOC);
        if(checksum_invalid)
-               printk_debug("Invalid CMOS LB checksum\n");
+               printk(BIOS_DEBUG, "Invalid CMOS LB checksum\n");
 
-       /* Setup the real time clock */
-       CMOS_WRITE(RTC_CONTROL_DEFAULT, RTC_CONTROL);
-       /* Setup the frequency it operates at */
-       CMOS_WRITE(RTC_FREQ_SELECT_DEFAULT, RTC_FREQ_SELECT);
        /* Make certain we have a valid checksum */
        rtc_set_checksum(PC_CKS_RANGE_START,
                         PC_CKS_RANGE_END,PC_CKS_LOC);
+#endif
+
        /* Clear any pending interrupts */
-       (void) CMOS_READ(RTC_INTR_FLAGS);
+       (void) cmos_read(RTC_INTR_FLAGS);
 }
 
 
-#if USE_OPTION_TABLE == 1
+#if CONFIG_USE_OPTION_TABLE
 /* This routine returns the value of the requested bits
        input bit = bit count from the beginning of the cmos image
              length = number of bits to include in the value
@@ -193,13 +192,13 @@ static int get_cmos_value(unsigned long bit, unsigned long length, void *vret)
        unsigned long i;
        unsigned char uchar;
 
-       /* The table is checked when it is built to ensure all 
+       /* The table is checked when it is built to ensure all
                values are valid. */
        ret = vret;
        byte=bit/8;     /* find the byte where the data starts */
        byte_bit=bit%8; /* find the bit in the byte where the data starts */
        if(length<9) {  /* one byte or less */
-               uchar = CMOS_READ(byte); /* load the byte */
+               uchar = cmos_read(byte); /* load the byte */
                uchar >>= byte_bit;     /* shift the bits to byte align */
                /* clear unspecified bits */
                ret[0] = uchar & ((1 << length) -1);
@@ -207,13 +206,13 @@ static int get_cmos_value(unsigned long bit, unsigned long length, void *vret)
        else {  /* more that one byte so transfer the whole bytes */
                for(i=0;length;i++,length-=8,byte++) {
                        /* load the byte */
-                       ret[i]=CMOS_READ(byte);
+                       ret[i]=cmos_read(byte);
                }
        }
        return 0;
 }
 
-int get_option(void *dest, char *name)
+int get_option(void *dest, const char *name)
 {
        extern struct cmos_option_table option_table;
        struct cmos_option_table *ct;
@@ -223,7 +222,7 @@ int get_option(void *dest, char *name)
 
        /* Figure out how long name is */
        namelen = strnlen(name, CMOS_MAX_NAME_LENGTH);
-       
+
        /* find the requested entry record */
        ct=&option_table;
        ce=(struct cmos_entries*)((unsigned char *)ct + ct->header_length);
@@ -235,10 +234,10 @@ int get_option(void *dest, char *name)
                }
        }
        if(!found) {
-               printk_err("ERROR: No cmos option '%s'\n", name);
+               printk(BIOS_DEBUG, "WARNING: No CMOS option '%s'.\n", name);
                return(-2);
        }
-       
+
        if(get_cmos_value(ce->bit, ce->length, dest))
                return(-3);
        if(!rtc_checksum_valid(LB_CKS_RANGE_START,
@@ -246,4 +245,4 @@ int get_option(void *dest, char *name)
                return(-4);
        return(0);
 }
-#endif /* USE_OPTION_TABLE */
+#endif /* CONFIG_USE_OPTION_TABLE */