sysreset_sandbox.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) 2015 Google, Inc
  3. * Written by Simon Glass <sjg@chromium.org>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <sysreset.h>
  11. #include <asm/state.h>
  12. #include <asm/test.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. static int sandbox_warm_sysreset_request(struct udevice *dev,
  15. enum sysreset_t type)
  16. {
  17. struct sandbox_state *state = state_get_current();
  18. switch (type) {
  19. case SYSRESET_WARM:
  20. state->last_sysreset = type;
  21. break;
  22. default:
  23. return -ENOSYS;
  24. }
  25. if (!state->sysreset_allowed[type])
  26. return -EACCES;
  27. return -EINPROGRESS;
  28. }
  29. static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
  30. {
  31. struct sandbox_state *state = state_get_current();
  32. /*
  33. * If we have a device tree, the device we created from platform data
  34. * (see the U_BOOT_DEVICE() declaration below) should not do anything.
  35. * If we are that device, return an error.
  36. */
  37. if (state->fdt_fname && dev->of_offset == -1)
  38. return -ENODEV;
  39. switch (type) {
  40. case SYSRESET_COLD:
  41. state->last_sysreset = type;
  42. break;
  43. case SYSRESET_POWER:
  44. state->last_sysreset = type;
  45. if (!state->sysreset_allowed[type])
  46. return -EACCES;
  47. sandbox_exit();
  48. break;
  49. default:
  50. return -ENOSYS;
  51. }
  52. if (!state->sysreset_allowed[type])
  53. return -EACCES;
  54. return -EINPROGRESS;
  55. }
  56. static struct sysreset_ops sandbox_sysreset_ops = {
  57. .request = sandbox_sysreset_request,
  58. };
  59. static const struct udevice_id sandbox_sysreset_ids[] = {
  60. { .compatible = "sandbox,reset" },
  61. { }
  62. };
  63. U_BOOT_DRIVER(sysreset_sandbox) = {
  64. .name = "sysreset_sandbox",
  65. .id = UCLASS_SYSRESET,
  66. .of_match = sandbox_sysreset_ids,
  67. .ops = &sandbox_sysreset_ops,
  68. };
  69. static struct sysreset_ops sandbox_warm_sysreset_ops = {
  70. .request = sandbox_warm_sysreset_request,
  71. };
  72. static const struct udevice_id sandbox_warm_sysreset_ids[] = {
  73. { .compatible = "sandbox,warm-reset" },
  74. { }
  75. };
  76. U_BOOT_DRIVER(warm_sysreset_sandbox) = {
  77. .name = "warm_sysreset_sandbox",
  78. .id = UCLASS_SYSRESET,
  79. .of_match = sandbox_warm_sysreset_ids,
  80. .ops = &sandbox_warm_sysreset_ops,
  81. };
  82. /* This is here in case we don't have a device tree */
  83. U_BOOT_DEVICE(sysreset_sandbox_non_fdt) = {
  84. .name = "sysreset_sandbox",
  85. };