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