summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorAlexandru Gagniuc <mr.nuke.me@gmail.com>2013-11-23 18:54:44 -0600
committerAlexandru Gagniuc <mr.nuke.me@gmail.com>2013-11-25 23:59:59 +0100
commitd7134e06b1b1ac21108b23438604b7385e4a43fa (patch)
treeaf710fa02c9dc7a87593aa22627e34fc89eca571 /src/drivers
parentfe9e30d6b74e340f9a97b9e358e20ec8a2785954 (diff)
downloadcoreboot-d7134e06b1b1ac21108b23438604b7385e4a43fa.tar.xz
pc80/mc146818rtc: Return an error code rather than an integer
Do not return hardcoded numerical values to communicate succes/failure, but instead use an enumeration. Change-Id: I742b08796adf136dce5984b702533f91640846dd Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com> Reviewed-on: http://review.coreboot.org/4265 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/pc80/mc146818rtc.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/drivers/pc80/mc146818rtc.c b/src/drivers/pc80/mc146818rtc.c
index 79aba27fbd..bd94bd29ff 100644
--- a/src/drivers/pc80/mc146818rtc.c
+++ b/src/drivers/pc80/mc146818rtc.c
@@ -151,9 +151,10 @@ void rtc_init(int invalid)
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 0 = successful, -1 = an error occurred
+ returns CB_SUCCESS = successful, cb_err code if an error occurred
*/
-static int get_cmos_value(unsigned long bit, unsigned long length, void *vret)
+static enum cb_err get_cmos_value(unsigned long bit, unsigned long length,
+ void *vret)
{
unsigned char *ret;
unsigned long byte,byte_bit;
@@ -177,10 +178,10 @@ static int get_cmos_value(unsigned long bit, unsigned long length, void *vret)
ret[i]=cmos_read(byte);
}
}
- return 0;
+ return CB_SUCCESS;
}
-int get_option(void *dest, const char *name)
+enum cb_err get_option(void *dest, const char *name)
{
struct cmos_option_table *ct;
struct cmos_entries *ce;
@@ -196,7 +197,7 @@ int get_option(void *dest, const char *name)
if (!ct) {
printk(BIOS_ERR, "RTC: cmos_layout.bin could not be found. "
"Options are disabled\n");
- return(-2);
+ return CB_CMOS_LAYOUT_NOT_FOUND;
}
ce=(struct cmos_entries*)((unsigned char *)ct + ct->header_length);
for(;ce->tag==LB_TAG_OPTION;
@@ -208,18 +209,18 @@ int get_option(void *dest, const char *name)
}
if(!found) {
printk(BIOS_DEBUG, "WARNING: No CMOS option '%s'.\n", name);
- return(-2);
+ return CB_CMOS_OPTION_NOT_FOUND;
}
- if(get_cmos_value(ce->bit, ce->length, dest))
- return(-3);
- if(!rtc_checksum_valid(LB_CKS_RANGE_START,
- LB_CKS_RANGE_END,LB_CKS_LOC))
- return(-4);
- return(0);
+ 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))
+ return CB_CMOS_CHECKSUM_INVALID;
+ return CB_SUCCESS;
}
-static int set_cmos_value(unsigned long bit, unsigned long length, void *vret)
+static enum cb_err set_cmos_value(unsigned long bit, unsigned long length,
+ void *vret)
{
unsigned char *ret;
unsigned long byte,byte_bit;
@@ -242,7 +243,7 @@ static int set_cmos_value(unsigned long bit, unsigned long length, void *vret)
chksum_update_needed = 1;
} else { /* more that one byte so transfer the whole bytes */
if (byte_bit || length % 8)
- return -1;
+ return CB_ERR_ARG;
for(i=0; length; i++, length-=8, byte++)
cmos_write(ret[i], byte);
@@ -254,11 +255,11 @@ static int set_cmos_value(unsigned long bit, unsigned long length, void *vret)
rtc_set_checksum(LB_CKS_RANGE_START,
LB_CKS_RANGE_END,LB_CKS_LOC);
}
- return 0;
+ return CB_SUCCESS;
}
-int set_option(const char *name, void *value)
+enum cb_err set_option(const char *name, void *value)
{
struct cmos_option_table *ct;
struct cmos_entries *ce;
@@ -274,7 +275,7 @@ int set_option(const char *name, void *value)
CBFS_COMPONENT_CMOS_LAYOUT);
if (!ct) {
printk(BIOS_ERR, "cmos_layout.bin could not be found. Options are disabled\n");
- return(-2);
+ return CB_CMOS_LAYOUT_NOT_FOUND;
}
ce=(struct cmos_entries*)((unsigned char *)ct + ct->header_length);
for(;ce->tag==LB_TAG_OPTION;
@@ -286,21 +287,22 @@ int set_option(const char *name, void *value)
}
if(!found) {
printk(BIOS_DEBUG, "WARNING: No CMOS option '%s'.\n", name);
- return(-2);
+ return CB_CMOS_OPTION_NOT_FOUND;
}
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 + ce->length - 8, 8, &(u8[]){0})
+ != CB_SUCCESS)
+ return (CB_CMOS_ACCESS_ERROR);
}
- if ((set_cmos_value(ce->bit, length, value)))
- return (-3);
+ if (set_cmos_value(ce->bit, length, value) != CB_SUCCESS)
+ return (CB_CMOS_ACCESS_ERROR);
- return 0;
+ return CB_SUCCESS;
}
#endif /* CONFIG_USE_OPTION_TABLE */