#include <console/console.h>
-#include <arch/io.h>
#include <pc80/mc146818rtc.h>
#include <boot/coreboot_tables.h>
#include <string.h>
+#if CONFIG_USE_OPTION_TABLE
+#include "option_table.h"
+#include <cbfs.h>
+#endif
/* control registers - Moto names
*/
# define RTC_VRT 0x80 /* valid RAM and time */
/**********************************************************************/
-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);
-}
-
+#if CONFIG_USE_OPTION_TABLE
static int rtc_checksum_valid(int range_start, int range_end, int cks_loc)
{
int i;
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)
void rtc_init(int invalid)
{
-#if CONFIG_HAVE_OPTION_TABLE
+#if CONFIG_USE_OPTION_TABLE
unsigned char x;
int cmos_invalid, checksum_invalid;
#endif
- printk_debug("RTC Init\n");
+ printk(BIOS_DEBUG, "RTC Init\n");
-#if CONFIG_HAVE_OPTION_TABLE
+#if CONFIG_USE_OPTION_TABLE
/* See if there has been a CMOS power problem. */
x = cmos_read(RTC_VALID);
cmos_invalid = !(x & RTC_VRT);
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
for(i = 10; i < 48; i++) {
cmos_write(0, i);
}
-
+
if (cmos_invalid) {
/* Now setup a default date of Sat 1 January 2000 */
cmos_write(0, 0x00); /* seconds */
/* Setup the frequency it operates at */
cmos_write(RTC_FREQ_SELECT_DEFAULT, RTC_FREQ_SELECT);
-#if CONFIG_HAVE_OPTION_TABLE
+#if CONFIG_USE_OPTION_TABLE
/* See if there is a LB CMOS checksum error */
- checksum_invalid = !rtc_checksum_valid(CONFIG_LB_CKS_RANGE_START,
- CONFIG_LB_CKS_RANGE_END,CONFIG_LB_CKS_LOC);
+ 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");
/* Make certain we have a valid checksum */
rtc_set_checksum(PC_CKS_RANGE_START,
}
-#if CONFIG_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
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 */
int get_option(void *dest, const char *name)
{
- extern struct cmos_option_table option_table;
struct cmos_option_table *ct;
struct cmos_entries *ce;
size_t namelen;
/* Figure out how long name is */
namelen = strnlen(name, CMOS_MAX_NAME_LENGTH);
-
+
/* find the requested entry record */
- ct=&option_table;
+ ct=cbfs_find_file("cmos_layout.bin", CBFS_COMPONENT_CMOS_LAYOUT);
+ if (!ct) {
+ printk(BIOS_ERR, "cmos_layout.bin could not be found. Options are disabled\n");
+ return(-2);
+ }
ce=(struct cmos_entries*)((unsigned char *)ct + ct->header_length);
for(;ce->tag==LB_TAG_OPTION;
ce=(struct cmos_entries*)((unsigned char *)ce + ce->size)) {
}
}
if(!found) {
- printk_debug("WARNING: 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(CONFIG_LB_CKS_RANGE_START,
- CONFIG_LB_CKS_RANGE_END,CONFIG_LB_CKS_LOC))
+ if(!rtc_checksum_valid(LB_CKS_RANGE_START,
+ LB_CKS_RANGE_END,LB_CKS_LOC))
return(-4);
return(0);
}
+
+static int set_cmos_value(unsigned long bit, unsigned long length, void *vret)
+{
+ unsigned char *ret;
+ unsigned long byte,byte_bit;
+ unsigned long i;
+ unsigned char uchar, mask;
+ unsigned int chksum_update_needed = 0;
+
+ 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 <= 8) { /* one byte or less */
+ mask = (1 << length) - 1;
+ mask <<= byte_bit;
+
+ uchar = cmos_read(byte);
+ uchar &= ~mask;
+ uchar |= (ret[0] << byte_bit);
+ cmos_write(uchar, byte);
+ if (byte >= LB_CKS_RANGE_START && byte <= LB_CKS_RANGE_END)
+ chksum_update_needed = 1;
+ } else { /* more that one byte so transfer the whole bytes */
+ if (byte_bit || length % 8)
+ return -1;
+
+ for(i=0; length; i++, length-=8, byte++)
+ cmos_write(ret[i], byte);
+ if (byte >= LB_CKS_RANGE_START && byte <= LB_CKS_RANGE_END)
+ chksum_update_needed = 1;
+ }
+
+ if (chksum_update_needed) {
+ rtc_set_checksum(LB_CKS_RANGE_START,
+ LB_CKS_RANGE_END,LB_CKS_LOC);
+ }
+ return 0;
+}
+
+
+int set_option(const char *name, void *value)
+{
+ struct cmos_option_table *ct;
+ struct cmos_entries *ce;
+ unsigned long length;
+ size_t namelen;
+ int found=0;
+
+ /* Figure out how long name is */
+ namelen = strnlen(name, CMOS_MAX_NAME_LENGTH);
+
+ /* find the requested entry record */
+ ct=cbfs_find_file("cmos_layout.bin", CBFS_COMPONENT_CMOS_LAYOUT);
+ if (!ct) {
+ printk(BIOS_ERR, "cmos_layout.bin could not be found. Options are disabled\n");
+ return(-2);
+ }
+ ce=(struct cmos_entries*)((unsigned char *)ct + ct->header_length);
+ for(;ce->tag==LB_TAG_OPTION;
+ ce=(struct cmos_entries*)((unsigned char *)ce + ce->size)) {
+ if (memcmp(ce->name, name, namelen) == 0) {
+ found=1;
+ break;
+ }
+ }
+ if(!found) {
+ printk(BIOS_DEBUG, "WARNING: No CMOS option '%s'.\n", name);
+ return(-2);
+ }
+
+ length = ce->length;
+ if (ce->config == 's') {
+ length = MAX(strlen((const char *)value) * 8, ce->length - 8);
+ /* make sure the string is null terminated */
+ if ((set_cmos_value(ce->bit + ce->length - 8, 8, &(u8[]){0})))
+ return (-3);
+ }
+
+ if ((set_cmos_value(ce->bit, length, value)))
+ return (-3);
+
+ return 0;
+}
#endif /* CONFIG_USE_OPTION_TABLE */