sandbox-reset.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. };
  16. struct sandbox_reset {
  17. struct sandbox_reset_signal signals[SANDBOX_RESET_SIGNALS];
  18. };
  19. static int sandbox_reset_request(struct reset_ctl *reset_ctl)
  20. {
  21. debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
  22. if (reset_ctl->id >= SANDBOX_RESET_SIGNALS)
  23. return -EINVAL;
  24. return 0;
  25. }
  26. static int sandbox_reset_free(struct reset_ctl *reset_ctl)
  27. {
  28. debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
  29. return 0;
  30. }
  31. static int sandbox_reset_assert(struct reset_ctl *reset_ctl)
  32. {
  33. struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
  34. debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
  35. sbr->signals[reset_ctl->id].asserted = true;
  36. return 0;
  37. }
  38. static int sandbox_reset_deassert(struct reset_ctl *reset_ctl)
  39. {
  40. struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
  41. debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
  42. sbr->signals[reset_ctl->id].asserted = false;
  43. return 0;
  44. }
  45. static int sandbox_reset_bind(struct udevice *dev)
  46. {
  47. debug("%s(dev=%p)\n", __func__, dev);
  48. return 0;
  49. }
  50. static int sandbox_reset_probe(struct udevice *dev)
  51. {
  52. debug("%s(dev=%p)\n", __func__, dev);
  53. return 0;
  54. }
  55. static const struct udevice_id sandbox_reset_ids[] = {
  56. { .compatible = "sandbox,reset-ctl" },
  57. { }
  58. };
  59. struct reset_ops sandbox_reset_reset_ops = {
  60. .request = sandbox_reset_request,
  61. .rfree = sandbox_reset_free,
  62. .rst_assert = sandbox_reset_assert,
  63. .rst_deassert = sandbox_reset_deassert,
  64. };
  65. U_BOOT_DRIVER(sandbox_reset) = {
  66. .name = "sandbox_reset",
  67. .id = UCLASS_RESET,
  68. .of_match = sandbox_reset_ids,
  69. .bind = sandbox_reset_bind,
  70. .probe = sandbox_reset_probe,
  71. .priv_auto_alloc_size = sizeof(struct sandbox_reset),
  72. .ops = &sandbox_reset_reset_ops,
  73. };
  74. int sandbox_reset_query(struct udevice *dev, unsigned long id)
  75. {
  76. struct sandbox_reset *sbr = dev_get_priv(dev);
  77. debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
  78. if (id >= SANDBOX_RESET_SIGNALS)
  79. return -EINVAL;
  80. return sbr->signals[id].asserted;
  81. }