Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | #include <console/console.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 2 | #include <pc80/mc146818rtc.h> |
Stefan Reinauer | ca374d4 | 2008-01-18 16:16:45 +0000 | [diff] [blame] | 3 | #include <boot/coreboot_tables.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 4 | #include <string.h> |
Stefan Reinauer | 10ec0fe | 2010-09-25 10:40:47 +0000 | [diff] [blame] | 5 | #if CONFIG_USE_OPTION_TABLE |
| 6 | #include "option_table.h" |
Patrick Georgi | 2447937 | 2011-01-18 13:56:36 +0000 | [diff] [blame] | 7 | #include <cbfs.h> |
Stefan Reinauer | 10ec0fe | 2010-09-25 10:40:47 +0000 | [diff] [blame] | 8 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 9 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 10 | /* control registers - Moto names |
| 11 | */ |
| 12 | #define RTC_REG_A 10 |
| 13 | #define RTC_REG_B 11 |
| 14 | #define RTC_REG_C 12 |
| 15 | #define RTC_REG_D 13 |
| 16 | |
| 17 | |
| 18 | /********************************************************************** |
| 19 | * register details |
| 20 | **********************************************************************/ |
| 21 | #define RTC_FREQ_SELECT RTC_REG_A |
| 22 | |
| 23 | /* update-in-progress - set to "1" 244 microsecs before RTC goes off the bus, |
| 24 | * reset after update (may take 1.984ms @ 32768Hz RefClock) is complete, |
| 25 | * totalling to a max high interval of 2.228 ms. |
| 26 | */ |
| 27 | # define RTC_UIP 0x80 |
| 28 | # define RTC_DIV_CTL 0x70 |
| 29 | /* divider control: refclock values 4.194 / 1.049 MHz / 32.768 kHz */ |
| 30 | # define RTC_REF_CLCK_4MHZ 0x00 |
| 31 | # define RTC_REF_CLCK_1MHZ 0x10 |
| 32 | # define RTC_REF_CLCK_32KHZ 0x20 |
| 33 | /* 2 values for divider stage reset, others for "testing purposes only" */ |
| 34 | # define RTC_DIV_RESET1 0x60 |
| 35 | # define RTC_DIV_RESET2 0x70 |
| 36 | /* Periodic intr. / Square wave rate select. 0=none, 1=32.8kHz,... 15=2Hz */ |
| 37 | # define RTC_RATE_SELECT 0x0F |
| 38 | # define RTC_RATE_NONE 0x00 |
| 39 | # define RTC_RATE_32786HZ 0x01 |
| 40 | # define RTC_RATE_16384HZ 0x02 |
| 41 | # define RTC_RATE_8192HZ 0x03 |
| 42 | # define RTC_RATE_4096HZ 0x04 |
| 43 | # define RTC_RATE_2048HZ 0x05 |
| 44 | # define RTC_RATE_1024HZ 0x06 |
| 45 | # define RTC_RATE_512HZ 0x07 |
| 46 | # define RTC_RATE_256HZ 0x08 |
| 47 | # define RTC_RATE_128HZ 0x09 |
| 48 | # define RTC_RATE_64HZ 0x0a |
| 49 | # define RTC_RATE_32HZ 0x0b |
| 50 | # define RTC_RATE_16HZ 0x0c |
| 51 | # define RTC_RATE_8HZ 0x0d |
| 52 | # define RTC_RATE_4HZ 0x0e |
| 53 | # define RTC_RATE_2HZ 0x0f |
| 54 | |
| 55 | /**********************************************************************/ |
| 56 | #define RTC_CONTROL RTC_REG_B |
| 57 | # define RTC_SET 0x80 /* disable updates for clock setting */ |
| 58 | # define RTC_PIE 0x40 /* periodic interrupt enable */ |
| 59 | # define RTC_AIE 0x20 /* alarm interrupt enable */ |
| 60 | # define RTC_UIE 0x10 /* update-finished interrupt enable */ |
| 61 | # define RTC_SQWE 0x08 /* enable square-wave output */ |
| 62 | # define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */ |
| 63 | # define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */ |
| 64 | # define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */ |
| 65 | |
| 66 | /**********************************************************************/ |
| 67 | #define RTC_INTR_FLAGS RTC_REG_C |
| 68 | /* caution - cleared by read */ |
| 69 | # define RTC_IRQF 0x80 /* any of the following 3 is active */ |
| 70 | # define RTC_PF 0x40 |
| 71 | # define RTC_AF 0x20 |
| 72 | # define RTC_UF 0x10 |
| 73 | |
| 74 | /**********************************************************************/ |
| 75 | #define RTC_VALID RTC_REG_D |
| 76 | # define RTC_VRT 0x80 /* valid RAM and time */ |
| 77 | /**********************************************************************/ |
| 78 | |
Edwin Beasant | eb50c7d | 2010-07-06 21:05:04 +0000 | [diff] [blame] | 79 | #if CONFIG_USE_OPTION_TABLE |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 80 | static int rtc_checksum_valid(int range_start, int range_end, int cks_loc) |
| 81 | { |
| 82 | int i; |
| 83 | unsigned sum, old_sum; |
| 84 | sum = 0; |
| 85 | for(i = range_start; i <= range_end; i++) { |
Stefan Reinauer | 73d5daa | 2009-04-22 09:03:08 +0000 | [diff] [blame] | 86 | sum += cmos_read(i); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 87 | } |
| 88 | sum = (~sum)&0x0ffff; |
Stefan Reinauer | 73d5daa | 2009-04-22 09:03:08 +0000 | [diff] [blame] | 89 | old_sum = ((cmos_read(cks_loc)<<8) | cmos_read(cks_loc+1))&0x0ffff; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 90 | return sum == old_sum; |
| 91 | } |
| 92 | |
| 93 | static void rtc_set_checksum(int range_start, int range_end, int cks_loc) |
| 94 | { |
| 95 | int i; |
| 96 | unsigned sum; |
| 97 | sum = 0; |
| 98 | for(i = range_start; i <= range_end; i++) { |
Stefan Reinauer | 73d5daa | 2009-04-22 09:03:08 +0000 | [diff] [blame] | 99 | sum += cmos_read(i); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 100 | } |
| 101 | sum = ~(sum & 0x0ffff); |
Stefan Reinauer | 73d5daa | 2009-04-22 09:03:08 +0000 | [diff] [blame] | 102 | cmos_write(((sum >> 8) & 0x0ff), cks_loc); |
| 103 | cmos_write(((sum >> 0) & 0x0ff), cks_loc+1); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 104 | } |
Stefan Reinauer | 2549d52 | 2010-03-17 03:44:45 +0000 | [diff] [blame] | 105 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 106 | |
Stefan Reinauer | 2fbbea0 | 2010-01-16 13:27:39 +0000 | [diff] [blame] | 107 | #if CONFIG_ARCH_X86 |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 108 | #define RTC_CONTROL_DEFAULT (RTC_24H) |
| 109 | #define RTC_FREQ_SELECT_DEFAULT (RTC_REF_CLCK_32KHZ | RTC_RATE_1024HZ) |
Stefan Reinauer | 2fbbea0 | 2010-01-16 13:27:39 +0000 | [diff] [blame] | 110 | #else |
| 111 | #if CONFIG_ARCH_ALPHA |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 112 | #define RTC_CONTROL_DEFAULT (RTC_SQWE | RTC_24H) |
| 113 | #define RTC_FREQ_SELECT_DEFAULT (RTC_REF_CLCK_32KHZ | RTC_RATE_1024HZ) |
| 114 | #endif |
Stefan Reinauer | 2fbbea0 | 2010-01-16 13:27:39 +0000 | [diff] [blame] | 115 | #endif |
Li-Ta Lo | 84a8028 | 2005-01-07 02:42:53 +0000 | [diff] [blame] | 116 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 117 | void rtc_init(int invalid) |
| 118 | { |
Edwin Beasant | eb50c7d | 2010-07-06 21:05:04 +0000 | [diff] [blame] | 119 | #if CONFIG_USE_OPTION_TABLE |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 120 | unsigned char x; |
| 121 | int cmos_invalid, checksum_invalid; |
Maciej Pijanka | ea92185 | 2009-10-27 14:29:29 +0000 | [diff] [blame] | 122 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 123 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 124 | printk(BIOS_DEBUG, "RTC Init\n"); |
Steven J. Magnani | 8cbc475 | 2005-09-12 18:43:27 +0000 | [diff] [blame] | 125 | |
Edwin Beasant | eb50c7d | 2010-07-06 21:05:04 +0000 | [diff] [blame] | 126 | #if CONFIG_USE_OPTION_TABLE |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 127 | /* See if there has been a CMOS power problem. */ |
Stefan Reinauer | 73d5daa | 2009-04-22 09:03:08 +0000 | [diff] [blame] | 128 | x = cmos_read(RTC_VALID); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 129 | cmos_invalid = !(x & RTC_VRT); |
| 130 | |
| 131 | /* See if there is a CMOS checksum error */ |
| 132 | checksum_invalid = !rtc_checksum_valid(PC_CKS_RANGE_START, |
| 133 | PC_CKS_RANGE_END,PC_CKS_LOC); |
| 134 | |
Stefan Reinauer | 1babddb | 2011-10-14 15:22:52 -0700 | [diff] [blame^] | 135 | #define CLEAR_CMOS 0 |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 136 | if (invalid || cmos_invalid || checksum_invalid) { |
Stefan Reinauer | 1babddb | 2011-10-14 15:22:52 -0700 | [diff] [blame^] | 137 | printk(BIOS_WARNING, "RTC:%s%s%s%s\n", |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 138 | invalid?" Clear requested":"", |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 139 | cmos_invalid?" Power Problem":"", |
Stefan Reinauer | 1babddb | 2011-10-14 15:22:52 -0700 | [diff] [blame^] | 140 | checksum_invalid?" Checksum invalid":"", |
| 141 | CLEAR_CMOS?" zeroing cmos":""); |
| 142 | #if CLEAR_CMOS |
Stefan Reinauer | 73d5daa | 2009-04-22 09:03:08 +0000 | [diff] [blame] | 143 | cmos_write(0, 0x01); |
| 144 | cmos_write(0, 0x03); |
| 145 | cmos_write(0, 0x05); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 146 | for(i = 10; i < 48; i++) { |
Stefan Reinauer | 73d5daa | 2009-04-22 09:03:08 +0000 | [diff] [blame] | 147 | cmos_write(0, i); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 148 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 149 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 150 | if (cmos_invalid) { |
| 151 | /* Now setup a default date of Sat 1 January 2000 */ |
Stefan Reinauer | 73d5daa | 2009-04-22 09:03:08 +0000 | [diff] [blame] | 152 | cmos_write(0, 0x00); /* seconds */ |
| 153 | cmos_write(0, 0x02); /* minutes */ |
| 154 | cmos_write(1, 0x04); /* hours */ |
| 155 | cmos_write(7, 0x06); /* day of week */ |
| 156 | cmos_write(1, 0x07); /* day of month */ |
| 157 | cmos_write(1, 0x08); /* month */ |
| 158 | cmos_write(0, 0x09); /* year */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 159 | } |
| 160 | #endif |
| 161 | } |
Steven J. Magnani | 8cbc475 | 2005-09-12 18:43:27 +0000 | [diff] [blame] | 162 | #endif |
| 163 | |
| 164 | /* Setup the real time clock */ |
Stefan Reinauer | 73d5daa | 2009-04-22 09:03:08 +0000 | [diff] [blame] | 165 | cmos_write(RTC_CONTROL_DEFAULT, RTC_CONTROL); |
Steven J. Magnani | 8cbc475 | 2005-09-12 18:43:27 +0000 | [diff] [blame] | 166 | /* Setup the frequency it operates at */ |
Stefan Reinauer | 73d5daa | 2009-04-22 09:03:08 +0000 | [diff] [blame] | 167 | cmos_write(RTC_FREQ_SELECT_DEFAULT, RTC_FREQ_SELECT); |
Steven J. Magnani | 8cbc475 | 2005-09-12 18:43:27 +0000 | [diff] [blame] | 168 | |
Edwin Beasant | eb50c7d | 2010-07-06 21:05:04 +0000 | [diff] [blame] | 169 | #if CONFIG_USE_OPTION_TABLE |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 170 | /* See if there is a LB CMOS checksum error */ |
Stefan Reinauer | b5828d7 | 2010-03-29 17:14:28 +0000 | [diff] [blame] | 171 | checksum_invalid = !rtc_checksum_valid(LB_CKS_RANGE_START, |
| 172 | LB_CKS_RANGE_END,LB_CKS_LOC); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 173 | if(checksum_invalid) |
Stefan Reinauer | 1babddb | 2011-10-14 15:22:52 -0700 | [diff] [blame^] | 174 | printk(BIOS_DEBUG, "RTC: coreboot checksum invalid\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 175 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 176 | /* Make certain we have a valid checksum */ |
| 177 | rtc_set_checksum(PC_CKS_RANGE_START, |
| 178 | PC_CKS_RANGE_END,PC_CKS_LOC); |
Steven J. Magnani | 8cbc475 | 2005-09-12 18:43:27 +0000 | [diff] [blame] | 179 | #endif |
| 180 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 181 | /* Clear any pending interrupts */ |
Stefan Reinauer | 73d5daa | 2009-04-22 09:03:08 +0000 | [diff] [blame] | 182 | (void) cmos_read(RTC_INTR_FLAGS); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | |
Edwin Beasant | eb50c7d | 2010-07-06 21:05:04 +0000 | [diff] [blame] | 186 | #if CONFIG_USE_OPTION_TABLE |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 187 | /* This routine returns the value of the requested bits |
| 188 | input bit = bit count from the beginning of the cmos image |
| 189 | length = number of bits to include in the value |
| 190 | ret = a character pointer to where the value is to be returned |
| 191 | output the value placed in ret |
| 192 | returns 0 = successful, -1 = an error occurred |
| 193 | */ |
| 194 | static int get_cmos_value(unsigned long bit, unsigned long length, void *vret) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 195 | { |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 196 | unsigned char *ret; |
| 197 | unsigned long byte,byte_bit; |
| 198 | unsigned long i; |
| 199 | unsigned char uchar; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 200 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 201 | /* The table is checked when it is built to ensure all |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 202 | values are valid. */ |
| 203 | ret = vret; |
| 204 | byte=bit/8; /* find the byte where the data starts */ |
| 205 | byte_bit=bit%8; /* find the bit in the byte where the data starts */ |
| 206 | if(length<9) { /* one byte or less */ |
| 207 | uchar = cmos_read(byte); /* load the byte */ |
| 208 | uchar >>= byte_bit; /* shift the bits to byte align */ |
| 209 | /* clear unspecified bits */ |
| 210 | ret[0] = uchar & ((1 << length) -1); |
Luc Verhaegen | 9ceae90 | 2009-06-03 10:47:19 +0000 | [diff] [blame] | 211 | } |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 212 | else { /* more that one byte so transfer the whole bytes */ |
| 213 | for(i=0;length;i++,length-=8,byte++) { |
| 214 | /* load the byte */ |
| 215 | ret[i]=cmos_read(byte); |
| 216 | } |
| 217 | } |
| 218 | return 0; |
Luc Verhaegen | 9ceae90 | 2009-06-03 10:47:19 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 221 | int get_option(void *dest, const char *name) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 222 | { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 223 | struct cmos_option_table *ct; |
| 224 | struct cmos_entries *ce; |
| 225 | size_t namelen; |
| 226 | int found=0; |
| 227 | |
| 228 | /* Figure out how long name is */ |
| 229 | namelen = strnlen(name, CMOS_MAX_NAME_LENGTH); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 230 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 231 | /* find the requested entry record */ |
Patrick Georgi | 5ccbbd9 | 2011-01-21 11:43:06 +0000 | [diff] [blame] | 232 | ct=cbfs_find_file("cmos_layout.bin", CBFS_COMPONENT_CMOS_LAYOUT); |
Patrick Georgi | cef3b89 | 2011-01-18 14:28:45 +0000 | [diff] [blame] | 233 | if (!ct) { |
Stefan Reinauer | 1babddb | 2011-10-14 15:22:52 -0700 | [diff] [blame^] | 234 | printk(BIOS_ERR, "RTC: cmos_layout.bin could not be found. " |
| 235 | "Options are disabled\n"); |
Patrick Georgi | cef3b89 | 2011-01-18 14:28:45 +0000 | [diff] [blame] | 236 | return(-2); |
| 237 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 238 | ce=(struct cmos_entries*)((unsigned char *)ct + ct->header_length); |
| 239 | for(;ce->tag==LB_TAG_OPTION; |
| 240 | ce=(struct cmos_entries*)((unsigned char *)ce + ce->size)) { |
| 241 | if (memcmp(ce->name, name, namelen) == 0) { |
| 242 | found=1; |
| 243 | break; |
| 244 | } |
| 245 | } |
| 246 | if(!found) { |
Stefan Reinauer | 8e726b7 | 2010-03-29 23:01:35 +0000 | [diff] [blame] | 247 | printk(BIOS_DEBUG, "WARNING: No CMOS option '%s'.\n", name); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 248 | return(-2); |
| 249 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 250 | |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 251 | if(get_cmos_value(ce->bit, ce->length, dest)) |
| 252 | return(-3); |
Stefan Reinauer | b5828d7 | 2010-03-29 17:14:28 +0000 | [diff] [blame] | 253 | if(!rtc_checksum_valid(LB_CKS_RANGE_START, |
| 254 | LB_CKS_RANGE_END,LB_CKS_LOC)) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 255 | return(-4); |
| 256 | return(0); |
| 257 | } |
Sven Schnelle | d29e5bb | 2011-06-06 15:58:54 +0200 | [diff] [blame] | 258 | |
| 259 | static int set_cmos_value(unsigned long bit, unsigned long length, void *vret) |
| 260 | { |
| 261 | unsigned char *ret; |
| 262 | unsigned long byte,byte_bit; |
| 263 | unsigned long i; |
| 264 | unsigned char uchar, mask; |
| 265 | unsigned int chksum_update_needed = 0; |
| 266 | |
| 267 | ret = vret; |
| 268 | byte = bit / 8; /* find the byte where the data starts */ |
| 269 | byte_bit = bit % 8; /* find the bit in the byte where the data starts */ |
| 270 | if(length <= 8) { /* one byte or less */ |
| 271 | mask = (1 << length) - 1; |
| 272 | mask <<= byte_bit; |
| 273 | |
| 274 | uchar = cmos_read(byte); |
| 275 | uchar &= ~mask; |
| 276 | uchar |= (ret[0] << byte_bit); |
| 277 | cmos_write(uchar, byte); |
| 278 | if (byte >= LB_CKS_RANGE_START && byte <= LB_CKS_RANGE_END) |
| 279 | chksum_update_needed = 1; |
| 280 | } else { /* more that one byte so transfer the whole bytes */ |
| 281 | if (byte_bit || length % 8) |
| 282 | return -1; |
| 283 | |
| 284 | for(i=0; length; i++, length-=8, byte++) |
| 285 | cmos_write(ret[i], byte); |
| 286 | if (byte >= LB_CKS_RANGE_START && byte <= LB_CKS_RANGE_END) |
| 287 | chksum_update_needed = 1; |
| 288 | } |
| 289 | |
| 290 | if (chksum_update_needed) { |
| 291 | rtc_set_checksum(LB_CKS_RANGE_START, |
| 292 | LB_CKS_RANGE_END,LB_CKS_LOC); |
| 293 | } |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | |
| 298 | int set_option(const char *name, void *value) |
| 299 | { |
| 300 | struct cmos_option_table *ct; |
| 301 | struct cmos_entries *ce; |
| 302 | unsigned long length; |
| 303 | size_t namelen; |
| 304 | int found=0; |
| 305 | |
| 306 | /* Figure out how long name is */ |
| 307 | namelen = strnlen(name, CMOS_MAX_NAME_LENGTH); |
| 308 | |
| 309 | /* find the requested entry record */ |
| 310 | ct=cbfs_find_file("cmos_layout.bin", CBFS_COMPONENT_CMOS_LAYOUT); |
| 311 | if (!ct) { |
| 312 | printk(BIOS_ERR, "cmos_layout.bin could not be found. Options are disabled\n"); |
| 313 | return(-2); |
| 314 | } |
| 315 | ce=(struct cmos_entries*)((unsigned char *)ct + ct->header_length); |
| 316 | for(;ce->tag==LB_TAG_OPTION; |
| 317 | ce=(struct cmos_entries*)((unsigned char *)ce + ce->size)) { |
| 318 | if (memcmp(ce->name, name, namelen) == 0) { |
| 319 | found=1; |
| 320 | break; |
| 321 | } |
| 322 | } |
| 323 | if(!found) { |
| 324 | printk(BIOS_DEBUG, "WARNING: No CMOS option '%s'.\n", name); |
| 325 | return(-2); |
| 326 | } |
| 327 | |
| 328 | length = ce->length; |
| 329 | if (ce->config == 's') { |
| 330 | length = MAX(strlen((const char *)value) * 8, ce->length - 8); |
| 331 | /* make sure the string is null terminated */ |
| 332 | if ((set_cmos_value(ce->bit + ce->length - 8, 8, &(u8[]){0}))) |
| 333 | return (-3); |
| 334 | } |
| 335 | |
| 336 | if ((set_cmos_value(ce->bit, length, value))) |
| 337 | return (-3); |
| 338 | |
| 339 | return 0; |
| 340 | } |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 341 | #endif /* CONFIG_USE_OPTION_TABLE */ |