blob: fa0b3273a8a9c5d389bf86df4c6040a28793c03c [file] [log] [blame]
Bin Meng9f1fad12017-04-21 07:24:38 -07001/*
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
18u8 cmos_read8(u8 addr)
19{
20 outb(addr, CMOS_IO_PORT);
21
22 return inb(CMOS_IO_PORT + 1);
23}
24
25u16 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
39u32 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}