early_cmos.c 918 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  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. #include <common.h>
  13. #include <asm/early_cmos.h>
  14. #include <asm/io.h>
  15. u8 cmos_read8(u8 addr)
  16. {
  17. outb(addr, CMOS_IO_PORT);
  18. return inb(CMOS_IO_PORT + 1);
  19. }
  20. u16 cmos_read16(u8 addr)
  21. {
  22. u16 value = 0;
  23. u16 data;
  24. int i;
  25. for (i = 0; i < sizeof(value); i++) {
  26. data = cmos_read8(addr + i);
  27. value |= data << (i << 3);
  28. }
  29. return value;
  30. }
  31. u32 cmos_read32(u8 addr)
  32. {
  33. u32 value = 0;
  34. u32 data;
  35. int i;
  36. for (i = 0; i < sizeof(value); i++) {
  37. data = cmos_read8(addr + i);
  38. value |= data << (i << 3);
  39. }
  40. return value;
  41. }