sandbox-power-domain.c 2.2 KB

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