sysreset_sandbox.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
  33. {
  34. struct sandbox_state *state = state_get_current();
  35. /*
  36. * If we have a device tree, the device we created from platform data
  37. * (see the U_BOOT_DEVICE() declaration below) should not do anything.
  38. * If we are that device, return an error.
  39. */
  40. if (state->fdt_fname && !dev_of_valid(dev))
  41. return -ENODEV;
  42. switch (type) {
  43. case SYSRESET_COLD:
  44. state->last_sysreset = type;
  45. break;
  46. case SYSRESET_POWER:
  47. state->last_sysreset = type;
  48. if (!state->sysreset_allowed[type])
  49. return -EACCES;
  50. sandbox_exit();
  51. break;
  52. default:
  53. return -ENOSYS;
  54. }
  55. if (!state->sysreset_allowed[type])
  56. return -EACCES;
  57. return -EINPROGRESS;
  58. }
  59. int sandbox_sysreset_get_status(struct udevice *dev, char *buf, int size)
  60. {
  61. strlcpy(buf, "Reset Status: COLD", size);
  62. return 0;
  63. }
  64. static struct sysreset_ops sandbox_sysreset_ops = {
  65. .request = sandbox_sysreset_request,
  66. .get_status = sandbox_sysreset_get_status,
  67. };
  68. static const struct udevice_id sandbox_sysreset_ids[] = {
  69. { .compatible = "sandbox,reset" },
  70. { }
  71. };
  72. U_BOOT_DRIVER(sysreset_sandbox) = {
  73. .name = "sysreset_sandbox",
  74. .id = UCLASS_SYSRESET,
  75. .of_match = sandbox_sysreset_ids,
  76. .ops = &sandbox_sysreset_ops,
  77. };
  78. static struct sysreset_ops sandbox_warm_sysreset_ops = {
  79. .request = sandbox_warm_sysreset_request,
  80. .get_status = sandbox_warm_sysreset_get_status,
  81. };
  82. static const struct udevice_id sandbox_warm_sysreset_ids[] = {
  83. { .compatible = "sandbox,warm-reset" },
  84. { }
  85. };
  86. U_BOOT_DRIVER(warm_sysreset_sandbox) = {
  87. .name = "warm_sysreset_sandbox",
  88. .id = UCLASS_SYSRESET,
  89. .of_match = sandbox_warm_sysreset_ids,
  90. .ops = &sandbox_warm_sysreset_ops,
  91. };
  92. /* This is here in case we don't have a device tree */
  93. U_BOOT_DEVICE(sysreset_sandbox_non_fdt) = {
  94. .name = "sysreset_sandbox",
  95. };