sysreset_sbi.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2021, Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <errno.h>
  8. #include <log.h>
  9. #include <sysreset.h>
  10. #include <asm/sbi.h>
  11. static enum sbi_srst_reset_type reset_type_map[SYSRESET_COUNT] = {
  12. [SYSRESET_WARM] = SBI_SRST_RESET_TYPE_WARM_REBOOT,
  13. [SYSRESET_COLD] = SBI_SRST_RESET_TYPE_COLD_REBOOT,
  14. [SYSRESET_POWER] = SBI_SRST_RESET_TYPE_COLD_REBOOT,
  15. [SYSRESET_POWER_OFF] = SBI_SRST_RESET_TYPE_SHUTDOWN,
  16. };
  17. static int sbi_sysreset_request(struct udevice *dev, enum sysreset_t type)
  18. {
  19. enum sbi_srst_reset_type reset_type;
  20. reset_type = reset_type_map[type];
  21. sbi_srst_reset(reset_type, SBI_SRST_RESET_REASON_NONE);
  22. return -EINPROGRESS;
  23. }
  24. static int sbi_sysreset_probe(struct udevice *dev)
  25. {
  26. long have_reset;
  27. have_reset = sbi_probe_extension(SBI_EXT_SRST);
  28. if (have_reset)
  29. return 0;
  30. log_warning("SBI has no system reset extension\n");
  31. return -ENOENT;
  32. }
  33. static struct sysreset_ops sbi_sysreset_ops = {
  34. .request = sbi_sysreset_request,
  35. };
  36. U_BOOT_DRIVER(sbi_sysreset) = {
  37. .name = "sbi-sysreset",
  38. .id = UCLASS_SYSRESET,
  39. .ops = &sbi_sysreset_ops,
  40. .probe = sbi_sysreset_probe,
  41. };