Add cmos helper functions for reading/writing a dword
[coreboot.git] / src / include / pc80 / mc146818rtc.h
index 1daf39aa25b179c7d162f08569a8fda78bb7bca8..24dac2c098dcc39aad769fabd141b82457440813 100644 (file)
@@ -7,18 +7,6 @@
 
 #define RTC_PORT(x)    (RTC_BASE_PORT + (x))
 
-/* On PCs, the checksum is built only over bytes 16..45 */
-#define PC_CKS_RANGE_START     16
-#define PC_CKS_RANGE_END       45
-#define PC_CKS_LOC             46
-
-
-/* Linux bios checksum is built only over bytes 49..125 */
-#define LB_CKS_RANGE_START     49
-#define LB_CKS_RANGE_END       125
-#define LB_CKS_LOC             126
-
-
 /* control registers - Moto names
  */
 #define RTC_REG_A              10
 # define RTC_VRT 0x80          /* valid RAM and time */
 /**********************************************************************/
 
-
 /* On PCs, the checksum is built only over bytes 16..45 */
 #define PC_CKS_RANGE_START     16
 #define PC_CKS_RANGE_END       45
 #define PC_CKS_LOC             46
 
-#define LB_CKS_RANGE_START     49
-#define LB_CKS_RANGE_END       125
-#define LB_CKS_LOC             126
+#ifndef UTIL_BUILD_OPTION_TABLE
+#include <arch/io.h>
+static inline unsigned char cmos_read(unsigned char addr)
+{
+       int offs = 0;
+       if (addr >= 128) {
+               offs = 2;
+               addr -= 128;
+       }
+       outb(addr, RTC_BASE_PORT + offs + 0);
+       return inb(RTC_BASE_PORT + offs + 1);
+}
+
+static inline void cmos_write(unsigned char val, unsigned char addr)
+{
+       int offs = 0;
+       if (addr >= 128) {
+               offs = 2;
+               addr -= 128;
+       }
+       outb(addr, RTC_BASE_PORT + offs + 0);
+       outb(val, RTC_BASE_PORT + offs + 1);
+}
+
+static inline u32 cmos_read32(u8 offset)
+{
+       u32 value = 0;
+       u8 i;
+       for (i = 0; i < sizeof(value); ++i)
+               value |= cmos_read(offset + i) << (i << 3);
+       return value;
+}
+
+static inline void cmos_write32(u8 offset, u32 value)
+{
+       u8 i;
+       for (i = 0; i < sizeof(value); ++i)
+               cmos_write((value >> (i << 3)) & 0xff, offset + i);
+}
+#endif
 
-#if !defined(ASSEMBLY)
+#if !defined(__ROMCC__)
 void rtc_init(int invalid);
-#if USE_OPTION_TABLE == 1
-int get_option(void *dest, char *name);
+#if CONFIG_USE_OPTION_TABLE
+int set_option(const char *name, void *val);
+int get_option(void *dest, const char *name);
+unsigned read_option_lowlevel(unsigned start, unsigned size, unsigned def);
 #else
-#define get_option(dest, name) (-2)
+static inline int set_option(const char *name __attribute__((unused)), void *val __attribute__((unused))) { return -2; };
+static inline int get_option(void *dest __attribute__((unused)),
+       const char *name __attribute__((unused))) { return -2; }
+#define read_option_lowlevel(start, size, def) def
 #endif
+#else
+#include <pc80/mc146818rtc_early.c>
 #endif
+#define read_option(name, default) read_option_lowlevel(CMOS_VSTART_ ##name, CMOS_VLEN_ ##name, (default))
 
 #endif /*  PC80_MC146818RTC_H */