blob: f7b3bb2a8e190bd201e455daf587a02502c75dfa [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Meng9f1fad12017-04-21 07:24:38 -07002/*
3 * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
Bin Meng9f1fad12017-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
13#include <common.h>
14#include <asm/early_cmos.h>
15#include <asm/io.h>
16
17u8 cmos_read8(u8 addr)
18{
19 outb(addr, CMOS_IO_PORT);
20
21 return inb(CMOS_IO_PORT + 1);
22}
23
24u16 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
38u32 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}