power-domain.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2016, NVIDIA CORPORATION.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0
  5. */
  6. #ifndef _POWER_DOMAIN_H
  7. #define _POWER_DOMAIN_H
  8. /**
  9. * A power domain is a portion of an SoC or chip that is powered by a
  10. * switchable source of power. In many cases, software has control over the
  11. * power domain, and can turn the power source on or off. This is typically
  12. * done to save power by powering off unused devices, or to enable software
  13. * sequencing of initial powerup at boot. This API provides a means for
  14. * drivers to turn power domains on and off.
  15. *
  16. * A driver that implements UCLASS_POWER_DOMAIN is a power domain controller or
  17. * provider. A controller will often implement multiple separate power domains,
  18. * since the hardware it manages often has this capability.
  19. * power-domain-uclass.h describes the interface which power domain controllers
  20. * must implement.
  21. *
  22. * Depending on the power domain controller hardware, changing the state of a
  23. * power domain may require performing related operations on other resources.
  24. * For example, some power domains may require certain clocks to be enabled
  25. * whenever the power domain is powered on, or during the time when the power
  26. * domain is transitioning state. These details are implementation-specific
  27. * and should ideally be encapsulated entirely within the provider driver, or
  28. * configured through mechanisms (e.g. device tree) that do not require client
  29. * drivers to provide extra configuration information.
  30. *
  31. * Power domain consumers/clients are the drivers for HW modules within the
  32. * power domain. This header file describes the API used by those drivers.
  33. *
  34. * In many cases, a single complex IO controller (e.g. a PCIe controller) will
  35. * be the sole logic contained within a power domain. In such cases, it is
  36. * logical for the relevant device driver to directly control that power
  37. * domain. In other cases, multiple controllers, each with their own driver,
  38. * may be contained in a single power domain. Any logic require to co-ordinate
  39. * between drivers for these multiple controllers is beyond the scope of this
  40. * API at present. Equally, this API does not define or implement any policy
  41. * by which power domains are managed.
  42. */
  43. struct udevice;
  44. /**
  45. * struct power_domain - A handle to (allowing control of) a single power domain.
  46. *
  47. * Clients provide storage for power domain handles. The content of the
  48. * structure is managed solely by the power domain API and power domain
  49. * drivers. A power domain struct is initialized by "get"ing the power domain
  50. * struct. The power domain struct is passed to all other power domain APIs to
  51. * identify which power domain to operate upon.
  52. *
  53. * @dev: The device which implements the power domain.
  54. * @id: The power domain ID within the provider.
  55. *
  56. * Currently, the power domain API assumes that a single integer ID is enough
  57. * to identify and configure any power domain for any power domain provider. If
  58. * this assumption becomes invalid in the future, the struct could be expanded
  59. * to either (a) add more fields to allow power domain providers to store
  60. * additional information, or (b) replace the id field with an opaque pointer,
  61. * which the provider would dynamically allocate during its .of_xlate op, and
  62. * process during is .request op. This may require the addition of an extra op
  63. * to clean up the allocation.
  64. */
  65. struct power_domain {
  66. struct udevice *dev;
  67. /*
  68. * Written by of_xlate. We assume a single id is enough for now. In the
  69. * future, we might add more fields here.
  70. */
  71. unsigned long id;
  72. };
  73. /**
  74. * power_domain_get - Get/request the power domain for a device.
  75. *
  76. * This looks up and requests a power domain. Each device is assumed to have
  77. * a single (or, at least one) power domain associated with it somehow, and
  78. * that domain, or the first/default domain. The mapping of client device to
  79. * provider power domain may be via device-tree properties, board-provided
  80. * mapping tables, or some other mechanism.
  81. *
  82. * @dev: The client device.
  83. * @power_domain A pointer to a power domain struct to initialize.
  84. * @return 0 if OK, or a negative error code.
  85. */
  86. int power_domain_get(struct udevice *dev, struct power_domain *power_domain);
  87. /**
  88. * power_domain_free - Free a previously requested power domain.
  89. *
  90. * @power_domain: A power domain struct that was previously successfully
  91. * requested by power_domain_get().
  92. * @return 0 if OK, or a negative error code.
  93. */
  94. int power_domain_free(struct power_domain *power_domain);
  95. /**
  96. * power_domain_on - Enable power to a power domain.
  97. *
  98. * @power_domain: A power domain struct that was previously successfully
  99. * requested by power_domain_get().
  100. * @return 0 if OK, or a negative error code.
  101. */
  102. int power_domain_on(struct power_domain *power_domain);
  103. /**
  104. * power_domain_off - Disable power ot a power domain.
  105. *
  106. * @power_domain: A power domain struct that was previously successfully
  107. * requested by power_domain_get().
  108. * @return 0 if OK, or a negative error code.
  109. */
  110. int power_domain_off(struct power_domain *power_domain);
  111. #endif