xref: /openbmc/u-boot/arch/x86/lib/early_cmos.c (revision d9b23e26)
1 /*
2  * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 /*
8  * This library provides CMOS (inside RTC SRAM) access routines at a very
9  * early stage when driver model is not available yet. Only read access is
10  * provided. The 16-bit/32-bit read are compatible with driver model RTC
11  * uclass write ops, that data is stored in little-endian mode.
12  */
13 
14 #include <common.h>
15 #include <asm/early_cmos.h>
16 #include <asm/io.h>
17 
18 u8 cmos_read8(u8 addr)
19 {
20 	outb(addr, CMOS_IO_PORT);
21 
22 	return inb(CMOS_IO_PORT + 1);
23 }
24 
25 u16 cmos_read16(u8 addr)
26 {
27 	u16 value = 0;
28 	u16 data;
29 	int i;
30 
31 	for (i = 0; i < sizeof(value); i++) {
32 		data = cmos_read8(addr + i);
33 		value |= data << (i << 3);
34 	}
35 
36 	return value;
37 }
38 
39 u32 cmos_read32(u8 addr)
40 {
41 	u32 value = 0;
42 	u32 data;
43 	int i;
44 
45 	for (i = 0; i < sizeof(value); i++) {
46 		data = cmos_read8(addr + i);
47 		value |= data << (i << 3);
48 	}
49 
50 	return value;
51 }
52