sysreset_sandbox.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. break;
  59. case SYSRESET_POWER:
  60. if (!state->sysreset_allowed[type])
  61. return -EACCES;
  62. sandbox_exit();
  63. default:
  64. return -ENOSYS;
  65. }
  66. if (!state->sysreset_allowed[type])
  67. return -EACCES;
  68. return -EINPROGRESS;
  69. }
  70. int sandbox_sysreset_get_status(struct udevice *dev, char *buf, int size)
  71. {
  72. strlcpy(buf, "Reset Status: COLD", size);
  73. return 0;
  74. }
  75. int sandbox_sysreset_get_last(struct udevice *dev)
  76. {
  77. struct sandbox_state *state = state_get_current();
  78. /*
  79. * The first phase is a power reset, after that we assume we don't
  80. * know.
  81. */
  82. return state->jumped_fname ? SYSRESET_WARM : SYSRESET_POWER;
  83. }
  84. static struct sysreset_ops sandbox_sysreset_ops = {
  85. .request = sandbox_sysreset_request,
  86. .get_status = sandbox_sysreset_get_status,
  87. .get_last = sandbox_sysreset_get_last,
  88. };
  89. static const struct udevice_id sandbox_sysreset_ids[] = {
  90. { .compatible = "sandbox,reset" },
  91. { }
  92. };
  93. U_BOOT_DRIVER(sysreset_sandbox) = {
  94. .name = "sysreset_sandbox",
  95. .id = UCLASS_SYSRESET,
  96. .of_match = sandbox_sysreset_ids,
  97. .ops = &sandbox_sysreset_ops,
  98. };
  99. static struct sysreset_ops sandbox_warm_sysreset_ops = {
  100. .request = sandbox_warm_sysreset_request,
  101. .get_status = sandbox_warm_sysreset_get_status,
  102. .get_last = sandbox_warm_sysreset_get_last,
  103. };
  104. static const struct udevice_id sandbox_warm_sysreset_ids[] = {
  105. { .compatible = "sandbox,warm-reset" },
  106. { }
  107. };
  108. U_BOOT_DRIVER(warm_sysreset_sandbox) = {
  109. .name = "warm_sysreset_sandbox",
  110. .id = UCLASS_SYSRESET,
  111. .of_match = sandbox_warm_sysreset_ids,
  112. .ops = &sandbox_warm_sysreset_ops,
  113. };
  114. #if !CONFIG_IS_ENABLED(OF_PLATDATA)
  115. /* This is here in case we don't have a device tree */
  116. U_BOOT_DRVINFO(sysreset_sandbox_non_fdt) = {
  117. .name = "sysreset_sandbox",
  118. };
  119. #endif