blob: 5635d08718fa8baecac00da6dc0ad44625ff3566 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Meng39f8b082017-04-21 07:24:38 -07002/*
3 * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
Bin Meng39f8b082017-04-21 07:24:38 -07004 */
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
Bin Meng39f8b082017-04-21 07:24:38 -070013#include <asm/early_cmos.h>
14#include <asm/io.h>
15
16u8 cmos_read8(u8 addr)
17{
18 outb(addr, CMOS_IO_PORT);
19
20 return inb(CMOS_IO_PORT + 1);
21}
22
23u16 cmos_read16(u8 addr)
24{
25 u16 value = 0;
26 u16 data;
27 int i;
28
29 for (i = 0; i < sizeof(value); i++) {
30 data = cmos_read8(addr + i);
31 value |= data << (i << 3);
32 }
33
34 return value;
35}
36
37u32 cmos_read32(u8 addr)
38{
39 u32 value = 0;
40 u32 data;
41 int i;
42
43 for (i = 0; i < sizeof(value); i++) {
44 data = cmos_read8(addr + i);
45 value |= data << (i << 3);
46 }
47
48 return value;
49}