sandbox-reset.c 2.1 KB

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