sysreset_sandbox.c 2.1 KB

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