early_cmos.c 915 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
  4. */
  5. /*
  6. * This library provides CMOS (inside RTC SRAM) access routines at a very
  7. * early stage when driver model is not available yet. Only read access is
  8. * provided. The 16-bit/32-bit read are compatible with driver model RTC
  9. * uclass write ops, that data is stored in little-endian mode.
  10. */
  11. #include <common.h>
  12. #include <asm/early_cmos.h>
  13. #include <asm/io.h>
  14. u8 cmos_read8(u8 addr)
  15. {
  16. outb(addr, CMOS_IO_PORT);
  17. return inb(CMOS_IO_PORT + 1);
  18. }
  19. u16 cmos_read16(u8 addr)
  20. {
  21. u16 value = 0;
  22. u16 data;
  23. int i;
  24. for (i = 0; i < sizeof(value); i++) {
  25. data = cmos_read8(addr + i);
  26. value |= data << (i << 3);
  27. }
  28. return value;
  29. }
  30. u32 cmos_read32(u8 addr)
  31. {
  32. u32 value = 0;
  33. u32 data;
  34. int i;
  35. for (i = 0; i < sizeof(value); i++) {
  36. data = cmos_read8(addr + i);
  37. value |= data << (i << 3);
  38. }
  39. return value;
  40. }