sandbox-power-domain.c 2.2 KB

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