CMOS: add set_option()
[coreboot.git] / src / include / pc80 / mc146818rtc.h
index 1561e4e811ce6968134990da44d9583899177618..d6dcf01b77cd767392b687fe326d3d374284c144 100644 (file)
 #define PC_CKS_RANGE_END       45
 #define PC_CKS_LOC             46
 
-/* Linux bios checksum is built only over bytes 49..125 */
-#ifndef CONFIG_LB_CKS_RANGE_START
-#define CONFIG_LB_CKS_RANGE_START      49
-#endif
-#ifndef CONFIG_LB_CKS_RANGE_END
-#define CONFIG_LB_CKS_RANGE_END        125
-#endif
-#ifndef CONFIG_LB_CKS_LOC
-#define CONFIG_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);
+}
 #endif
 
-#if !defined(ASSEMBLY)
+#if !defined(__ROMCC__)
 void rtc_init(int invalid);
-#if CONFIG_USE_OPTION_TABLE == 1
+#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
-static inline int get_option(void *dest, const char *name) { return -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; }
+static inline unsigned read_option_lowlevel(unsigned start, unsigned size, unsigned def)
+       { return 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 */