fdt_reset.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2020 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. */
  9. #include <sbi/sbi_scratch.h>
  10. #include <sbi_utils/fdt/fdt_helper.h>
  11. #include <sbi_utils/reset/fdt_reset.h>
  12. extern struct fdt_reset fdt_reset_sifive;
  13. extern struct fdt_reset fdt_reset_htif;
  14. extern struct fdt_reset fdt_reset_thead;
  15. static struct fdt_reset *reset_drivers[] = {
  16. &fdt_reset_sifive,
  17. &fdt_reset_htif,
  18. &fdt_reset_thead,
  19. };
  20. static struct fdt_reset *current_driver = NULL;
  21. int fdt_system_reset_check(u32 reset_type, u32 reset_reason)
  22. {
  23. if (current_driver && current_driver->system_reset_check)
  24. return current_driver->system_reset_check(reset_type,
  25. reset_reason);
  26. return 0;
  27. }
  28. void fdt_system_reset(u32 reset_type, u32 reset_reason)
  29. {
  30. if (current_driver && current_driver->system_reset)
  31. current_driver->system_reset(reset_type, reset_reason);
  32. }
  33. int fdt_reset_init(void)
  34. {
  35. int pos, noff, rc;
  36. struct fdt_reset *drv;
  37. const struct fdt_match *match;
  38. void *fdt = sbi_scratch_thishart_arg1_ptr();
  39. for (pos = 0; pos < array_size(reset_drivers); pos++) {
  40. drv = reset_drivers[pos];
  41. noff = fdt_find_match(fdt, -1, drv->match_table, &match);
  42. if (noff < 0)
  43. continue;
  44. if (drv->init) {
  45. rc = drv->init(fdt, noff, match);
  46. if (rc)
  47. return rc;
  48. }
  49. current_driver = drv;
  50. break;
  51. }
  52. return 0;
  53. }