Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bin Meng | 9f1fad1 | 2017-04-21 07:24:38 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | 9f1fad1 | 2017-04-21 07:24:38 -0700 | [diff] [blame] | 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 | } |