sandbox-power-domain.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 <power-domain-uclass.h>
  10. #include <asm/io.h>
  11. #include <asm/power-domain.h>
  12. #define SANDBOX_POWER_DOMAINS 3
  13. struct sandbox_power_domain {
  14. bool on[SANDBOX_POWER_DOMAINS];
  15. };
  16. static int sandbox_power_domain_request(struct power_domain *power_domain)
  17. {
  18. debug("%s(power_domain=%p)\n", __func__, power_domain);
  19. if (power_domain->id >= SANDBOX_POWER_DOMAINS)
  20. return -EINVAL;
  21. return 0;
  22. }
  23. static int sandbox_power_domain_free(struct power_domain *power_domain)
  24. {
  25. debug("%s(power_domain=%p)\n", __func__, power_domain);
  26. return 0;
  27. }
  28. static int sandbox_power_domain_on(struct power_domain *power_domain)
  29. {
  30. struct sandbox_power_domain *sbr = dev_get_priv(power_domain->dev);
  31. debug("%s(power_domain=%p)\n", __func__, power_domain);
  32. sbr->on[power_domain->id] = true;
  33. return 0;
  34. }
  35. static int sandbox_power_domain_off(struct power_domain *power_domain)
  36. {
  37. struct sandbox_power_domain *sbr = dev_get_priv(power_domain->dev);
  38. debug("%s(power_domain=%p)\n", __func__, power_domain);
  39. sbr->on[power_domain->id] = false;
  40. return 0;
  41. }
  42. static int sandbox_power_domain_bind(struct udevice *dev)
  43. {
  44. debug("%s(dev=%p)\n", __func__, dev);
  45. return 0;
  46. }
  47. static int sandbox_power_domain_probe(struct udevice *dev)
  48. {
  49. debug("%s(dev=%p)\n", __func__, dev);
  50. return 0;
  51. }
  52. static const struct udevice_id sandbox_power_domain_ids[] = {
  53. { .compatible = "sandbox,power-domain" },
  54. { }
  55. };
  56. struct power_domain_ops sandbox_power_domain_ops = {
  57. .request = sandbox_power_domain_request,
  58. .rfree = sandbox_power_domain_free,
  59. .on = sandbox_power_domain_on,
  60. .off = sandbox_power_domain_off,
  61. };
  62. U_BOOT_DRIVER(sandbox_power_domain) = {
  63. .name = "sandbox_power_domain",
  64. .id = UCLASS_POWER_DOMAIN,
  65. .of_match = sandbox_power_domain_ids,
  66. .bind = sandbox_power_domain_bind,
  67. .probe = sandbox_power_domain_probe,
  68. .priv_auto_alloc_size = sizeof(struct sandbox_power_domain),
  69. .ops = &sandbox_power_domain_ops,
  70. };
  71. int sandbox_power_domain_query(struct udevice *dev, unsigned long id)
  72. {
  73. struct sandbox_power_domain *sbr = dev_get_priv(dev);
  74. debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
  75. if (id >= SANDBOX_POWER_DOMAINS)
  76. return -EINVAL;
  77. return sbr->on[id];
  78. }