sandbox-reset.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2016, NVIDIA CORPORATION.
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <log.h>
  8. #include <malloc.h>
  9. #include <reset-uclass.h>
  10. #include <asm/io.h>
  11. #include <asm/reset.h>
  12. #define SANDBOX_RESET_SIGNALS 101
  13. struct sandbox_reset_signal {
  14. bool asserted;
  15. bool requested;
  16. };
  17. struct sandbox_reset {
  18. struct sandbox_reset_signal signals[SANDBOX_RESET_SIGNALS];
  19. };
  20. static int sandbox_reset_request(struct reset_ctl *reset_ctl)
  21. {
  22. struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
  23. debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
  24. if (reset_ctl->id >= SANDBOX_RESET_SIGNALS)
  25. return -EINVAL;
  26. sbr->signals[reset_ctl->id].requested = true;
  27. return 0;
  28. }
  29. static int sandbox_reset_free(struct reset_ctl *reset_ctl)
  30. {
  31. struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
  32. debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
  33. sbr->signals[reset_ctl->id].requested = false;
  34. return 0;
  35. }
  36. static int sandbox_reset_assert(struct reset_ctl *reset_ctl)
  37. {
  38. struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
  39. debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
  40. sbr->signals[reset_ctl->id].asserted = true;
  41. return 0;
  42. }
  43. static int sandbox_reset_deassert(struct reset_ctl *reset_ctl)
  44. {
  45. struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
  46. debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
  47. sbr->signals[reset_ctl->id].asserted = false;
  48. return 0;
  49. }
  50. static int sandbox_reset_bind(struct udevice *dev)
  51. {
  52. debug("%s(dev=%p)\n", __func__, dev);
  53. return 0;
  54. }
  55. static int sandbox_reset_probe(struct udevice *dev)
  56. {
  57. debug("%s(dev=%p)\n", __func__, dev);
  58. return 0;
  59. }
  60. static const struct udevice_id sandbox_reset_ids[] = {
  61. { .compatible = "sandbox,reset-ctl" },
  62. { }
  63. };
  64. struct reset_ops sandbox_reset_reset_ops = {
  65. .request = sandbox_reset_request,
  66. .rfree = sandbox_reset_free,
  67. .rst_assert = sandbox_reset_assert,
  68. .rst_deassert = sandbox_reset_deassert,
  69. };
  70. U_BOOT_DRIVER(sandbox_reset) = {
  71. .name = "sandbox_reset",
  72. .id = UCLASS_RESET,
  73. .of_match = sandbox_reset_ids,
  74. .bind = sandbox_reset_bind,
  75. .probe = sandbox_reset_probe,
  76. .priv_auto_alloc_size = sizeof(struct sandbox_reset),
  77. .ops = &sandbox_reset_reset_ops,
  78. };
  79. int sandbox_reset_query(struct udevice *dev, unsigned long id)
  80. {
  81. struct sandbox_reset *sbr = dev_get_priv(dev);
  82. debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
  83. if (id >= SANDBOX_RESET_SIGNALS)
  84. return -EINVAL;
  85. return sbr->signals[id].asserted;
  86. }
  87. int sandbox_reset_is_requested(struct udevice *dev, unsigned long id)
  88. {
  89. struct sandbox_reset *sbr = dev_get_priv(dev);
  90. debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
  91. if (id >= SANDBOX_RESET_SIGNALS)
  92. return -EINVAL;
  93. return sbr->signals[id].requested;
  94. }