sysreset_sandbox.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <sysreset.h>
  10. #include <asm/state.h>
  11. #include <asm/test.h>
  12. static int sandbox_warm_sysreset_request(struct udevice *dev,
  13. enum sysreset_t type)
  14. {
  15. struct sandbox_state *state = state_get_current();
  16. switch (type) {
  17. case SYSRESET_WARM:
  18. state->last_sysreset = type;
  19. break;
  20. default:
  21. return -ENOSYS;
  22. }
  23. if (!state->sysreset_allowed[type])
  24. return -EACCES;
  25. return -EINPROGRESS;
  26. }
  27. int sandbox_warm_sysreset_get_status(struct udevice *dev, char *buf, int size)
  28. {
  29. strlcpy(buf, "Reset Status: WARM", size);
  30. return 0;
  31. }
  32. int sandbox_warm_sysreset_get_last(struct udevice *dev)
  33. {
  34. return SYSRESET_WARM;
  35. }
  36. static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
  37. {
  38. struct sandbox_state *state = state_get_current();
  39. /*
  40. * If we have a device tree, the device we created from platform data
  41. * (see the U_BOOT_DRVINFO() declaration below) should not do anything.
  42. * If we are that device, return an error.
  43. */
  44. if (state->fdt_fname && !dev_has_ofnode(dev))
  45. return -ENODEV;
  46. switch (type) {
  47. case SYSRESET_COLD:
  48. state->last_sysreset = type;
  49. if (!state->sysreset_allowed[type])
  50. return -EACCES;
  51. sandbox_reset();
  52. break;
  53. case SYSRESET_POWER_OFF:
  54. state->last_sysreset = type;
  55. if (!state->sysreset_allowed[type])
  56. return -EACCES;
  57. sandbox_exit();
  58. case SYSRESET_POWER:
  59. if (!state->sysreset_allowed[type])
  60. return -EACCES;
  61. sandbox_exit();
  62. default:
  63. return -ENOSYS;
  64. }
  65. if (!state->sysreset_allowed[type])
  66. return -EACCES;
  67. return -EINPROGRESS;
  68. }
  69. int sandbox_sysreset_get_status(struct udevice *dev, char *buf, int size)
  70. {
  71. strlcpy(buf, "Reset Status: COLD", size);
  72. return 0;
  73. }
  74. int sandbox_sysreset_get_last(struct udevice *dev)
  75. {
  76. struct sandbox_state *state = state_get_current();
  77. /*
  78. * The first phase is a power reset, after that we assume we don't
  79. * know.
  80. */
  81. return state->jumped_fname ? SYSRESET_WARM : SYSRESET_POWER;
  82. }
  83. static struct sysreset_ops sandbox_sysreset_ops = {
  84. .request = sandbox_sysreset_request,
  85. .get_status = sandbox_sysreset_get_status,
  86. .get_last = sandbox_sysreset_get_last,
  87. };
  88. static const struct udevice_id sandbox_sysreset_ids[] = {
  89. { .compatible = "sandbox,reset" },
  90. { }
  91. };
  92. U_BOOT_DRIVER(sysreset_sandbox) = {
  93. .name = "sysreset_sandbox",
  94. .id = UCLASS_SYSRESET,
  95. .of_match = sandbox_sysreset_ids,
  96. .ops = &sandbox_sysreset_ops,
  97. };
  98. static struct sysreset_ops sandbox_warm_sysreset_ops = {
  99. .request = sandbox_warm_sysreset_request,
  100. .get_status = sandbox_warm_sysreset_get_status,
  101. .get_last = sandbox_warm_sysreset_get_last,
  102. };
  103. static const struct udevice_id sandbox_warm_sysreset_ids[] = {
  104. { .compatible = "sandbox,warm-reset" },
  105. { }
  106. };
  107. U_BOOT_DRIVER(warm_sysreset_sandbox) = {
  108. .name = "warm_sysreset_sandbox",
  109. .id = UCLASS_SYSRESET,
  110. .of_match = sandbox_warm_sysreset_ids,
  111. .ops = &sandbox_warm_sysreset_ops,
  112. };
  113. #if CONFIG_IS_ENABLED(OF_REAL)
  114. /* This is here in case we don't have a device tree */
  115. U_BOOT_DRVINFO(sysreset_sandbox_non_fdt) = {
  116. .name = "sysreset_sandbox",
  117. };
  118. #endif