aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/pc80/mc146818rtc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/pc80/mc146818rtc.c')
-rw-r--r--src/drivers/pc80/mc146818rtc.c142
1 files changed, 72 insertions, 70 deletions
diff --git a/src/drivers/pc80/mc146818rtc.c b/src/drivers/pc80/mc146818rtc.c
index c54f6cefa5..9670e9ce6b 100644
--- a/src/drivers/pc80/mc146818rtc.c
+++ b/src/drivers/pc80/mc146818rtc.c
@@ -10,7 +10,8 @@
#endif
#include <arch/acpi.h>
-static void rtc_update_cmos_date(u8 has_century)
+
+static void cmos_update_date(u8 has_century)
{
/* Now setup a default date equals to the build date */
cmos_write(0, RTC_CLK_SECOND);
@@ -24,28 +25,27 @@ static void rtc_update_cmos_date(u8 has_century)
}
#if CONFIG_USE_OPTION_TABLE
-static int rtc_checksum_valid(int range_start, int range_end, int cks_loc)
+static int cmos_checksum_valid(int range_start, int range_end, int cks_loc)
{
int i;
u16 sum, old_sum;
sum = 0;
- for(i = range_start; i <= range_end; i++) {
+ for (i = range_start; i <= range_end; i++)
sum += cmos_read(i);
- }
- 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;
}
-static void rtc_set_checksum(int range_start, int range_end, int cks_loc)
+static void cmos_set_checksum(int range_start, int range_end, int cks_loc)
{
int i;
u16 sum;
sum = 0;
- for(i = range_start; i <= range_end; i++) {
+ for (i = range_start; i <= range_end; i++)
sum += cmos_read(i);
- }
cmos_write(((sum >> 8) & 0x0ff), cks_loc);
- cmos_write(((sum >> 0) & 0x0ff), cks_loc+1);
+ cmos_write(((sum >> 0) & 0x0ff), cks_loc + 1);
}
#endif
@@ -60,7 +60,7 @@ static void rtc_set_checksum(int range_start, int range_end, int cks_loc)
#endif
#ifndef __SMM__
-void rtc_init(int invalid)
+void cmos_init(int invalid)
{
int cmos_invalid = 0;
int checksum_invalid = 0;
@@ -87,7 +87,7 @@ void rtc_init(int invalid)
cmos_invalid = !(x & RTC_VRT);
/* See if there is a CMOS checksum error */
- checksum_invalid = !rtc_checksum_valid(PC_CKS_RANGE_START,
+ checksum_invalid = !cmos_checksum_valid(PC_CKS_RANGE_START,
PC_CKS_RANGE_END,PC_CKS_LOC);
#define CLEAR_CMOS 0
@@ -102,13 +102,11 @@ void rtc_init(int invalid)
cmos_write(0, 0x01);
cmos_write(0, 0x03);
cmos_write(0, 0x05);
- for(i = 10; i < 128; i++) {
+ for (i = 10; i < 128; i++)
cmos_write(0, i);
- }
#endif
- if (cmos_invalid) {
- rtc_update_cmos_date(RTC_HAS_NO_ALTCENTURY);
- }
+ if (cmos_invalid)
+ cmos_update_date(RTC_HAS_NO_ALTCENTURY);
printk(BIOS_WARNING, "RTC:%s%s%s%s\n",
invalid?" Clear requested":"",
@@ -126,30 +124,29 @@ void rtc_init(int invalid)
#if CONFIG_USE_OPTION_TABLE
/* See if there is a LB CMOS checksum error */
- checksum_invalid = !rtc_checksum_valid(LB_CKS_RANGE_START,
+ checksum_invalid = !cmos_checksum_valid(LB_CKS_RANGE_START,
LB_CKS_RANGE_END,LB_CKS_LOC);
- if(checksum_invalid)
+ if (checksum_invalid)
printk(BIOS_DEBUG, "RTC: coreboot checksum invalid\n");
/* Make certain we have a valid checksum */
- rtc_set_checksum(PC_CKS_RANGE_START,
- PC_CKS_RANGE_END,PC_CKS_LOC);
+ cmos_set_checksum(PC_CKS_RANGE_START, PC_CKS_RANGE_END, PC_CKS_LOC);
#endif
/* Clear any pending interrupts */
- (void) cmos_read(RTC_INTR_FLAGS);
+ cmos_read(RTC_INTR_FLAGS);
}
#endif
#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
- ret = a character pointer to where the value is to be returned
- output the value placed in ret
- returns CB_SUCCESS = successful, cb_err code if an error occurred
-*/
+/*
+ * 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
+ * ret = a character pointer to where the value is to be returned
+ * returns CB_SUCCESS = successful, cb_err code if an error occurred
+ */
static enum cb_err get_cmos_value(unsigned long bit, unsigned long length,
void *vret)
{
@@ -158,21 +155,22 @@ static enum cb_err get_cmos_value(unsigned long bit, unsigned long length,
unsigned long i;
unsigned char uchar;
- /* The table is checked when it is built to ensure all
- values are valid. */
+ /*
+ * 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 */
+ 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 >>= byte_bit; /* shift the bits to byte align */
/* clear unspecified bits */
- ret[0] = uchar & ((1 << length) -1);
- }
- else { /* more that one byte so transfer the whole bytes */
- for(i=0;length;i++,length-=8,byte++) {
+ ret[0] = uchar & ((1 << length) - 1);
+ } 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 CB_SUCCESS;
@@ -183,7 +181,7 @@ enum cb_err get_option(void *dest, const char *name)
struct cmos_option_table *ct;
struct cmos_entries *ce;
size_t namelen;
- int found=0;
+ int found = 0;
/* Figure out how long name is */
namelen = strnlen(name, CMOS_MAX_NAME_LENGTH);
@@ -196,22 +194,22 @@ enum cb_err get_option(void *dest, const char *name)
"Options are disabled\n");
return CB_CMOS_LAYOUT_NOT_FOUND;
}
- 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)) {
+ 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;
+ found = 1;
break;
}
}
- if(!found) {
+ if (!found) {
printk(BIOS_DEBUG, "WARNING: No CMOS option '%s'.\n", name);
return CB_CMOS_OPTION_NOT_FOUND;
}
- if(get_cmos_value(ce->bit, ce->length, dest) != CB_SUCCESS)
+ if (get_cmos_value(ce->bit, ce->length, dest) != CB_SUCCESS)
return CB_CMOS_ACCESS_ERROR;
- if(!rtc_checksum_valid(LB_CKS_RANGE_START, LB_CKS_RANGE_END,LB_CKS_LOC))
+ if (!cmos_checksum_valid(LB_CKS_RANGE_START, LB_CKS_RANGE_END, LB_CKS_LOC))
return CB_CMOS_CHECKSUM_INVALID;
return CB_SUCCESS;
}
@@ -226,9 +224,9 @@ static enum cb_err set_cmos_value(unsigned long bit, unsigned long length,
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 */
+ byte = bit / 8; /* find the byte where the data starts */
+ byte_bit = bit % 8; /* find the bit where the data starts */
+ if (length <= 8) { /* one byte or less */
mask = (1 << length) - 1;
mask <<= byte_bit;
@@ -238,19 +236,20 @@ static enum cb_err set_cmos_value(unsigned long bit, unsigned long length,
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 */
+ } else { /* more that one byte so transfer the whole bytes */
if (byte_bit || length % 8)
return CB_ERR_ARG;
- for(i=0; length; i++, length-=8, byte++)
+ for (i = 0; length; i++, length -= 8, byte++)
cmos_write(ret[i], byte);
- if (byte >= LB_CKS_RANGE_START && byte <= LB_CKS_RANGE_END)
+ 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);
+ cmos_set_checksum(LB_CKS_RANGE_START, LB_CKS_RANGE_END,
+ LB_CKS_LOC);
}
return CB_SUCCESS;
}
@@ -262,7 +261,7 @@ enum cb_err set_option(const char *name, void *value)
struct cmos_entries *ce;
unsigned long length;
size_t namelen;
- int found=0;
+ int found = 0;
/* Figure out how long name is */
namelen = strnlen(name, CMOS_MAX_NAME_LENGTH);
@@ -271,18 +270,19 @@ enum cb_err set_option(const char *name, void *value)
ct = cbfs_get_file_content(CBFS_DEFAULT_MEDIA, "cmos_layout.bin",
CBFS_COMPONENT_CMOS_LAYOUT, NULL);
if (!ct) {
- printk(BIOS_ERR, "cmos_layout.bin could not be found. Options are disabled\n");
+ printk(BIOS_ERR, "cmos_layout.bin could not be found. "
+ "Options are disabled\n");
return CB_CMOS_LAYOUT_NOT_FOUND;
}
- 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)) {
+ 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;
+ found = 1;
break;
}
}
- if(!found) {
+ if (!found) {
printk(BIOS_DEBUG, "WARNING: No CMOS option '%s'.\n", name);
return CB_CMOS_OPTION_NOT_FOUND;
}
@@ -308,17 +308,19 @@ enum cb_err set_option(const char *name, void *value)
* hurts some OSes. Even if we don't set USE_OPTION_TABLE, we need
* to make sure the date is valid.
*/
-void rtc_check_update_cmos_date(u8 has_century)
+void cmos_check_update_date(u8 has_century)
{
u8 year, century;
- /* Note: We need to check if the hardware supports RTC_CLK_ALTCENTURY. */
- century = has_century ? cmos_read(RTC_CLK_ALTCENTURY) : 0;
- year = cmos_read(RTC_CLK_YEAR);
+ /* Note: Need to check if the hardware supports RTC_CLK_ALTCENTURY. */
+ century = has_century ? cmos_read(RTC_CLK_ALTCENTURY) : 0;
+ year = cmos_read(RTC_CLK_YEAR);
- /* TODO: If century is 0xFF, 100% that the cmos is cleared.
- * Other than that, so far rtc_year is the only entry to check if the date is valid. */
- if (century > 0x99 || year > 0x99) { /* Invalid date */
- rtc_update_cmos_date(has_century);
- }
+ /*
+ * TODO: If century is 0xFF, 100% that the cmos is cleared.
+ * Other than that, so far rtc_year is the only entry to check
+ * if the date is valid.
+ */
+ if (century > 0x99 || year > 0x99) /* Invalid date */
+ cmos_update_date(has_century);
}