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