Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bin Meng | 39f8b08 | 2017-04-21 07:24:38 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | 39f8b08 | 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 | |
Bin Meng | 39f8b08 | 2017-04-21 07:24:38 -0700 | [diff] [blame] | 13 | #include <asm/early_cmos.h> |
| 14 | #include <asm/io.h> |
| 15 | |
| 16 | u8 cmos_read8(u8 addr) |
| 17 | { |
| 18 | outb(addr, CMOS_IO_PORT); |
| 19 | |
| 20 | return inb(CMOS_IO_PORT + 1); |
| 21 | } |
| 22 | |
| 23 | u16 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 | |
| 37 | u32 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 | } |