reset_sandbox.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 <reset.h>
  11. #include <asm/state.h>
  12. #include <asm/test.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. static int sandbox_warm_reset_request(struct udevice *dev, enum reset_t type)
  15. {
  16. struct sandbox_state *state = state_get_current();
  17. switch (type) {
  18. case RESET_WARM:
  19. state->last_reset = type;
  20. break;
  21. default:
  22. return -ENOSYS;
  23. }
  24. if (!state->reset_allowed[type])
  25. return -EACCES;
  26. return -EINPROGRESS;
  27. }
  28. static int sandbox_reset_request(struct udevice *dev, enum reset_t type)
  29. {
  30. struct sandbox_state *state = state_get_current();
  31. /*
  32. * If we have a device tree, the device we created from platform data
  33. * (see the U_BOOT_DEVICE() declaration below) should not do anything.
  34. * If we are that device, return an error.
  35. */
  36. if (state->fdt_fname && dev->of_offset == -1)
  37. return -ENODEV;
  38. switch (type) {
  39. case RESET_COLD:
  40. state->last_reset = type;
  41. break;
  42. case RESET_POWER:
  43. state->last_reset = type;
  44. if (!state->reset_allowed[type])
  45. return -EACCES;
  46. sandbox_exit();
  47. break;
  48. default:
  49. return -ENOSYS;
  50. }
  51. if (!state->reset_allowed[type])
  52. return -EACCES;
  53. return -EINPROGRESS;
  54. }
  55. static struct reset_ops sandbox_reset_ops = {
  56. .request = sandbox_reset_request,
  57. };
  58. static const struct udevice_id sandbox_reset_ids[] = {
  59. { .compatible = "sandbox,reset" },
  60. { }
  61. };
  62. U_BOOT_DRIVER(reset_sandbox) = {
  63. .name = "reset_sandbox",
  64. .id = UCLASS_RESET,
  65. .of_match = sandbox_reset_ids,
  66. .ops = &sandbox_reset_ops,
  67. };
  68. static struct reset_ops sandbox_warm_reset_ops = {
  69. .request = sandbox_warm_reset_request,
  70. };
  71. static const struct udevice_id sandbox_warm_reset_ids[] = {
  72. { .compatible = "sandbox,warm-reset" },
  73. { }
  74. };
  75. U_BOOT_DRIVER(warm_reset_sandbox) = {
  76. .name = "warm_reset_sandbox",
  77. .id = UCLASS_RESET,
  78. .of_match = sandbox_warm_reset_ids,
  79. .ops = &sandbox_warm_reset_ops,
  80. };
  81. /* This is here in case we don't have a device tree */
  82. U_BOOT_DEVICE(reset_sandbox_non_fdt) = {
  83. .name = "reset_sandbox",
  84. };