// SPDX-License-Identifier: GPL-2.0 /* * drivers/base/power/domain.c - Common code related to device power domains. * * Copyright (C) 2011 Rafael J. Wysocki <[email protected]>, Renesas Electronics Corp. */ #define pr_fmt(fmt) … #include <linux/delay.h> #include <linux/kernel.h> #include <linux/io.h> #include <linux/platform_device.h> #include <linux/pm_opp.h> #include <linux/pm_runtime.h> #include <linux/pm_domain.h> #include <linux/pm_qos.h> #include <linux/pm_clock.h> #include <linux/slab.h> #include <linux/err.h> #include <linux/sched.h> #include <linux/suspend.h> #include <linux/export.h> #include <linux/cpu.h> #include <linux/debugfs.h> #define GENPD_RETRY_MAX_MS … #define GENPD_DEV_CALLBACK(genpd, type, callback, dev) … static LIST_HEAD(gpd_list); static DEFINE_MUTEX(gpd_list_lock); struct genpd_lock_ops { … }; static void genpd_lock_mtx(struct generic_pm_domain *genpd) { … } static void genpd_lock_nested_mtx(struct generic_pm_domain *genpd, int depth) { … } static int genpd_lock_interruptible_mtx(struct generic_pm_domain *genpd) { … } static void genpd_unlock_mtx(struct generic_pm_domain *genpd) { … } static const struct genpd_lock_ops genpd_mtx_ops = …; static void genpd_lock_spin(struct generic_pm_domain *genpd) __acquires(&genpd->slock) { … } static void genpd_lock_nested_spin(struct generic_pm_domain *genpd, int depth) __acquires(&genpd->slock) { … } static int genpd_lock_interruptible_spin(struct generic_pm_domain *genpd) __acquires(&genpd->slock) { … } static void genpd_unlock_spin(struct generic_pm_domain *genpd) __releases(&genpd->slock) { … } static const struct genpd_lock_ops genpd_spin_ops = …; #define genpd_lock(p) … #define genpd_lock_nested(p, d) … #define genpd_lock_interruptible(p) … #define genpd_unlock(p) … #define genpd_status_on(genpd) … #define genpd_is_irq_safe(genpd) … #define genpd_is_always_on(genpd) … #define genpd_is_active_wakeup(genpd) … #define genpd_is_cpu_domain(genpd) … #define genpd_is_rpm_always_on(genpd) … #define genpd_is_opp_table_fw(genpd) … static inline bool irq_safe_dev_in_sleep_domain(struct device *dev, const struct generic_pm_domain *genpd) { … } static int genpd_runtime_suspend(struct device *dev); /* * Get the generic PM domain for a particular struct device. * This validates the struct device pointer, the PM domain pointer, * and checks that the PM domain pointer is a real generic PM domain. * Any failure results in NULL being returned. */ static struct generic_pm_domain *dev_to_genpd_safe(struct device *dev) { … } /* * This should only be used where we are certain that the pm_domain * attached to the device is a genpd domain. */ static struct generic_pm_domain *dev_to_genpd(struct device *dev) { … } struct device *dev_to_genpd_dev(struct device *dev) { … } static int genpd_stop_dev(const struct generic_pm_domain *genpd, struct device *dev) { … } static int genpd_start_dev(const struct generic_pm_domain *genpd, struct device *dev) { … } static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd) { … } static void genpd_sd_counter_inc(struct generic_pm_domain *genpd) { … } #ifdef CONFIG_DEBUG_FS static struct dentry *genpd_debugfs_dir; static void genpd_debug_add(struct generic_pm_domain *genpd); static void genpd_debug_remove(struct generic_pm_domain *genpd) { … } static void genpd_update_accounting(struct generic_pm_domain *genpd) { … } #else static inline void genpd_debug_add(struct generic_pm_domain *genpd) {} static inline void genpd_debug_remove(struct generic_pm_domain *genpd) {} static inline void genpd_update_accounting(struct generic_pm_domain *genpd) {} #endif static int _genpd_reeval_performance_state(struct generic_pm_domain *genpd, unsigned int state) { … } static int genpd_xlate_performance_state(struct generic_pm_domain *genpd, struct generic_pm_domain *parent, unsigned int pstate) { … } static int _genpd_set_performance_state(struct generic_pm_domain *genpd, unsigned int state, int depth); static void _genpd_rollback_parent_state(struct gpd_link *link, int depth) { … } static int _genpd_set_parent_state(struct generic_pm_domain *genpd, struct gpd_link *link, unsigned int state, int depth) { … } static int _genpd_set_performance_state(struct generic_pm_domain *genpd, unsigned int state, int depth) { … } static int genpd_set_performance_state(struct device *dev, unsigned int state) { … } static int genpd_drop_performance_state(struct device *dev) { … } static void genpd_restore_performance_state(struct device *dev, unsigned int state) { … } static int genpd_dev_pm_set_performance_state(struct device *dev, unsigned int state) { … } /** * dev_pm_genpd_set_performance_state- Set performance state of device's power * domain. * * @dev: Device for which the performance-state needs to be set. * @state: Target performance state of the device. This can be set as 0 when the * device doesn't have any performance state constraints left (And so * the device wouldn't participate anymore to find the target * performance state of the genpd). * * It is assumed that the users guarantee that the genpd wouldn't be detached * while this routine is getting called. * * Returns 0 on success and negative error values on failures. */ int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_genpd_set_next_wakeup - Notify PM framework of an impending wakeup. * * @dev: Device to handle * @next: impending interrupt/wakeup for the device * * * Allow devices to inform of the next wakeup. It's assumed that the users * guarantee that the genpd wouldn't be detached while this routine is getting * called. Additionally, it's also assumed that @dev isn't runtime suspended * (RPM_SUSPENDED)." * Although devices are expected to update the next_wakeup after the end of * their usecase as well, it is possible the devices themselves may not know * about that, so stale @next will be ignored when powering off the domain. */ void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_genpd_get_next_hrtimer - Return the next_hrtimer for the genpd * @dev: A device that is attached to the genpd. * * This routine should typically be called for a device, at the point of when a * GENPD_NOTIFY_PRE_OFF notification has been sent for it. * * Returns the aggregated value of the genpd's next hrtimer or KTIME_MAX if no * valid value have been set. */ ktime_t dev_pm_genpd_get_next_hrtimer(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /* * dev_pm_genpd_synced_poweroff - Next power off should be synchronous * * @dev: A device that is attached to the genpd. * * Allows a consumer of the genpd to notify the provider that the next power off * should be synchronous. * * It is assumed that the users guarantee that the genpd wouldn't be detached * while this routine is getting called. */ void dev_pm_genpd_synced_poweroff(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_genpd_set_hwmode() - Set the HW mode for the device and its PM domain. * * @dev: Device for which the HW-mode should be changed. * @enable: Value to set or unset the HW-mode. * * Some PM domains can rely on HW signals to control the power for a device. To * allow a consumer driver to switch the behaviour for its device in runtime, * which may be beneficial from a latency or energy point of view, this function * may be called. * * It is assumed that the users guarantee that the genpd wouldn't be detached * while this routine is getting called. * * Return: Returns 0 on success and negative error values on failures. */ int dev_pm_genpd_set_hwmode(struct device *dev, bool enable) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_genpd_get_hwmode() - Get the HW mode setting for the device. * * @dev: Device for which the current HW-mode setting should be fetched. * * This helper function allows consumer drivers to fetch the current HW mode * setting of its the device. * * It is assumed that the users guarantee that the genpd wouldn't be detached * while this routine is getting called. * * Return: Returns the HW mode setting of device from SW cached hw_mode. */ bool dev_pm_genpd_get_hwmode(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); static int _genpd_power_on(struct generic_pm_domain *genpd, bool timed) { … } static int _genpd_power_off(struct generic_pm_domain *genpd, bool timed) { … } /** * genpd_queue_power_off_work - Queue up the execution of genpd_power_off(). * @genpd: PM domain to power off. * * Queue up the execution of genpd_power_off() unless it's already been done * before. */ static void genpd_queue_power_off_work(struct generic_pm_domain *genpd) { … } /** * genpd_power_off - Remove power from a given PM domain. * @genpd: PM domain to power down. * @one_dev_on: If invoked from genpd's ->runtime_suspend|resume() callback, the * RPM status of the releated device is in an intermediate state, not yet turned * into RPM_SUSPENDED. This means genpd_power_off() must allow one device to not * be RPM_SUSPENDED, while it tries to power off the PM domain. * @depth: nesting count for lockdep. * * If all of the @genpd's devices have been suspended and all of its subdomains * have been powered down, remove power from @genpd. */ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, unsigned int depth) { … } /** * genpd_power_on - Restore power to a given PM domain and its parents. * @genpd: PM domain to power up. * @depth: nesting count for lockdep. * * Restore power to @genpd and all of its parents so that it is possible to * resume a device belonging to it. */ static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth) { … } static int genpd_dev_pm_start(struct device *dev) { … } static int genpd_dev_pm_qos_notifier(struct notifier_block *nb, unsigned long val, void *ptr) { … } /** * genpd_power_off_work_fn - Power off PM domain whose subdomain count is 0. * @work: Work structure used for scheduling the execution of this function. */ static void genpd_power_off_work_fn(struct work_struct *work) { … } /** * __genpd_runtime_suspend - walk the hierarchy of ->runtime_suspend() callbacks * @dev: Device to handle. */ static int __genpd_runtime_suspend(struct device *dev) { … } /** * __genpd_runtime_resume - walk the hierarchy of ->runtime_resume() callbacks * @dev: Device to handle. */ static int __genpd_runtime_resume(struct device *dev) { … } /** * genpd_runtime_suspend - Suspend a device belonging to I/O PM domain. * @dev: Device to suspend. * * Carry out a runtime suspend of a device under the assumption that its * pm_domain field points to the domain member of an object of type * struct generic_pm_domain representing a PM domain consisting of I/O devices. */ static int genpd_runtime_suspend(struct device *dev) { … } /** * genpd_runtime_resume - Resume a device belonging to I/O PM domain. * @dev: Device to resume. * * Carry out a runtime resume of a device under the assumption that its * pm_domain field points to the domain member of an object of type * struct generic_pm_domain representing a PM domain consisting of I/O devices. */ static int genpd_runtime_resume(struct device *dev) { … } static bool pd_ignore_unused; static int __init pd_ignore_unused_setup(char *__unused) { … } __setup(…); /** * genpd_power_off_unused - Power off all PM domains with no devices in use. */ static int __init genpd_power_off_unused(void) { … } late_initcall_sync(genpd_power_off_unused); #ifdef CONFIG_PM_SLEEP /** * genpd_sync_power_off - Synchronously power off a PM domain and its parents. * @genpd: PM domain to power off, if possible. * @use_lock: use the lock. * @depth: nesting count for lockdep. * * Check if the given PM domain can be powered off (during system suspend or * hibernation) and do that if so. Also, in that case propagate to its parents. * * This function is only called in "noirq" and "syscore" stages of system power * transitions. The "noirq" callbacks may be executed asynchronously, thus in * these cases the lock must be held. */ static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock, unsigned int depth) { … } /** * genpd_sync_power_on - Synchronously power on a PM domain and its parents. * @genpd: PM domain to power on. * @use_lock: use the lock. * @depth: nesting count for lockdep. * * This function is only called in "noirq" and "syscore" stages of system power * transitions. The "noirq" callbacks may be executed asynchronously, thus in * these cases the lock must be held. */ static void genpd_sync_power_on(struct generic_pm_domain *genpd, bool use_lock, unsigned int depth) { … } /** * genpd_prepare - Start power transition of a device in a PM domain. * @dev: Device to start the transition of. * * Start a power transition of a device (during a system-wide power transition) * under the assumption that its pm_domain field points to the domain member of * an object of type struct generic_pm_domain representing a PM domain * consisting of I/O devices. */ static int genpd_prepare(struct device *dev) { … } /** * genpd_finish_suspend - Completion of suspend or hibernation of device in an * I/O pm domain. * @dev: Device to suspend. * @suspend_noirq: Generic suspend_noirq callback. * @resume_noirq: Generic resume_noirq callback. * * Stop the device and remove power from the domain if all devices in it have * been stopped. */ static int genpd_finish_suspend(struct device *dev, int (*suspend_noirq)(struct device *dev), int (*resume_noirq)(struct device *dev)) { … } /** * genpd_suspend_noirq - Completion of suspend of device in an I/O PM domain. * @dev: Device to suspend. * * Stop the device and remove power from the domain if all devices in it have * been stopped. */ static int genpd_suspend_noirq(struct device *dev) { … } /** * genpd_finish_resume - Completion of resume of device in an I/O PM domain. * @dev: Device to resume. * @resume_noirq: Generic resume_noirq callback. * * Restore power to the device's PM domain, if necessary, and start the device. */ static int genpd_finish_resume(struct device *dev, int (*resume_noirq)(struct device *dev)) { … } /** * genpd_resume_noirq - Start of resume of device in an I/O PM domain. * @dev: Device to resume. * * Restore power to the device's PM domain, if necessary, and start the device. */ static int genpd_resume_noirq(struct device *dev) { … } /** * genpd_freeze_noirq - Completion of freezing a device in an I/O PM domain. * @dev: Device to freeze. * * Carry out a late freeze of a device under the assumption that its * pm_domain field points to the domain member of an object of type * struct generic_pm_domain representing a power domain consisting of I/O * devices. */ static int genpd_freeze_noirq(struct device *dev) { … } /** * genpd_thaw_noirq - Early thaw of device in an I/O PM domain. * @dev: Device to thaw. * * Start the device, unless power has been removed from the domain already * before the system transition. */ static int genpd_thaw_noirq(struct device *dev) { … } /** * genpd_poweroff_noirq - Completion of hibernation of device in an * I/O PM domain. * @dev: Device to poweroff. * * Stop the device and remove power from the domain if all devices in it have * been stopped. */ static int genpd_poweroff_noirq(struct device *dev) { … } /** * genpd_restore_noirq - Start of restore of device in an I/O PM domain. * @dev: Device to resume. * * Make sure the domain will be in the same power state as before the * hibernation the system is resuming from and start the device if necessary. */ static int genpd_restore_noirq(struct device *dev) { … } /** * genpd_complete - Complete power transition of a device in a power domain. * @dev: Device to complete the transition of. * * Complete a power transition of a device (during a system-wide power * transition) under the assumption that its pm_domain field points to the * domain member of an object of type struct generic_pm_domain representing * a power domain consisting of I/O devices. */ static void genpd_complete(struct device *dev) { … } static void genpd_switch_state(struct device *dev, bool suspend) { … } /** * dev_pm_genpd_suspend - Synchronously try to suspend the genpd for @dev * @dev: The device that is attached to the genpd, that can be suspended. * * This routine should typically be called for a device that needs to be * suspended during the syscore suspend phase. It may also be called during * suspend-to-idle to suspend a corresponding CPU device that is attached to a * genpd. */ void dev_pm_genpd_suspend(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_genpd_resume - Synchronously try to resume the genpd for @dev * @dev: The device that is attached to the genpd, which needs to be resumed. * * This routine should typically be called for a device that needs to be resumed * during the syscore resume phase. It may also be called during suspend-to-idle * to resume a corresponding CPU device that is attached to a genpd. */ void dev_pm_genpd_resume(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); #else /* !CONFIG_PM_SLEEP */ #define genpd_prepare … #define genpd_suspend_noirq … #define genpd_resume_noirq … #define genpd_freeze_noirq … #define genpd_thaw_noirq … #define genpd_poweroff_noirq … #define genpd_restore_noirq … #define genpd_complete … #endif /* CONFIG_PM_SLEEP */ static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev, bool has_governor) { … } static void genpd_free_dev_data(struct device *dev, struct generic_pm_domain_data *gpd_data) { … } static void genpd_update_cpumask(struct generic_pm_domain *genpd, int cpu, bool set, unsigned int depth) { … } static void genpd_set_cpumask(struct generic_pm_domain *genpd, int cpu) { … } static void genpd_clear_cpumask(struct generic_pm_domain *genpd, int cpu) { … } static int genpd_get_cpu(struct generic_pm_domain *genpd, struct device *dev) { … } static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, struct device *base_dev) { … } /** * pm_genpd_add_device - Add a device to an I/O PM domain. * @genpd: PM domain to add the device to. * @dev: Device to be added. */ int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev) { … } EXPORT_SYMBOL_GPL(…); static int genpd_remove_device(struct generic_pm_domain *genpd, struct device *dev) { … } /** * pm_genpd_remove_device - Remove a device from an I/O PM domain. * @dev: Device to be removed. */ int pm_genpd_remove_device(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_genpd_add_notifier - Add a genpd power on/off notifier for @dev * * @dev: Device that should be associated with the notifier * @nb: The notifier block to register * * Users may call this function to add a genpd power on/off notifier for an * attached @dev. Only one notifier per device is allowed. The notifier is * sent when genpd is powering on/off the PM domain. * * It is assumed that the user guarantee that the genpd wouldn't be detached * while this routine is getting called. * * Returns 0 on success and negative error values on failures. */ int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_genpd_remove_notifier - Remove a genpd power on/off notifier for @dev * * @dev: Device that is associated with the notifier * * Users may call this function to remove a genpd power on/off notifier for an * attached @dev. * * It is assumed that the user guarantee that the genpd wouldn't be detached * while this routine is getting called. * * Returns 0 on success and negative error values on failures. */ int dev_pm_genpd_remove_notifier(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); static int genpd_add_subdomain(struct generic_pm_domain *genpd, struct generic_pm_domain *subdomain) { … } /** * pm_genpd_add_subdomain - Add a subdomain to an I/O PM domain. * @genpd: Leader PM domain to add the subdomain to. * @subdomain: Subdomain to be added. */ int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, struct generic_pm_domain *subdomain) { … } EXPORT_SYMBOL_GPL(…); /** * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain. * @genpd: Leader PM domain to remove the subdomain from. * @subdomain: Subdomain to be removed. */ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, struct generic_pm_domain *subdomain) { … } EXPORT_SYMBOL_GPL(…); static void genpd_free_default_power_state(struct genpd_power_state *states, unsigned int state_count) { … } static int genpd_set_default_power_state(struct generic_pm_domain *genpd) { … } static int genpd_alloc_data(struct generic_pm_domain *genpd) { … } static void genpd_free_data(struct generic_pm_domain *genpd) { … } static void genpd_lock_init(struct generic_pm_domain *genpd) { … } /** * pm_genpd_init - Initialize a generic I/O PM domain object. * @genpd: PM domain object to initialize. * @gov: PM domain governor to associate with the domain (may be NULL). * @is_off: Initial value of the domain's power_is_off field. * * Returns 0 on successful initialization, else a negative error code. */ int pm_genpd_init(struct generic_pm_domain *genpd, struct dev_power_governor *gov, bool is_off) { … } EXPORT_SYMBOL_GPL(…); static int genpd_remove(struct generic_pm_domain *genpd) { … } /** * pm_genpd_remove - Remove a generic I/O PM domain * @genpd: Pointer to PM domain that is to be removed. * * To remove the PM domain, this function: * - Removes the PM domain as a subdomain to any parent domains, * if it was added. * - Removes the PM domain from the list of registered PM domains. * * The PM domain will only be removed, if the associated provider has * been removed, it is not a parent to any other PM domain and has no * devices associated with it. */ int pm_genpd_remove(struct generic_pm_domain *genpd) { … } EXPORT_SYMBOL_GPL(…); #ifdef CONFIG_PM_GENERIC_DOMAINS_OF /* * Device Tree based PM domain providers. * * The code below implements generic device tree based PM domain providers that * bind device tree nodes with generic PM domains registered in the system. * * Any driver that registers generic PM domains and needs to support binding of * devices to these domains is supposed to register a PM domain provider, which * maps a PM domain specifier retrieved from the device tree to a PM domain. * * Two simple mapping functions have been provided for convenience: * - genpd_xlate_simple() for 1:1 device tree node to PM domain mapping. * - genpd_xlate_onecell() for mapping of multiple PM domains per node by * index. */ /** * struct of_genpd_provider - PM domain provider registration structure * @link: Entry in global list of PM domain providers * @node: Pointer to device tree node of PM domain provider * @xlate: Provider-specific xlate callback mapping a set of specifier cells * into a PM domain. * @data: context pointer to be passed into @xlate callback */ struct of_genpd_provider { … }; /* List of registered PM domain providers. */ static LIST_HEAD(of_genpd_providers); /* Mutex to protect the list above. */ static DEFINE_MUTEX(of_genpd_mutex); /** * genpd_xlate_simple() - Xlate function for direct node-domain mapping * @genpdspec: OF phandle args to map into a PM domain * @data: xlate function private data - pointer to struct generic_pm_domain * * This is a generic xlate function that can be used to model PM domains that * have their own device tree nodes. The private data of xlate function needs * to be a valid pointer to struct generic_pm_domain. */ static struct generic_pm_domain *genpd_xlate_simple( const struct of_phandle_args *genpdspec, void *data) { … } /** * genpd_xlate_onecell() - Xlate function using a single index. * @genpdspec: OF phandle args to map into a PM domain * @data: xlate function private data - pointer to struct genpd_onecell_data * * This is a generic xlate function that can be used to model simple PM domain * controllers that have one device tree node and provide multiple PM domains. * A single cell is used as an index into an array of PM domains specified in * the genpd_onecell_data struct when registering the provider. */ static struct generic_pm_domain *genpd_xlate_onecell( const struct of_phandle_args *genpdspec, void *data) { … } /** * genpd_add_provider() - Register a PM domain provider for a node * @np: Device node pointer associated with the PM domain provider. * @xlate: Callback for decoding PM domain from phandle arguments. * @data: Context pointer for @xlate callback. */ static int genpd_add_provider(struct device_node *np, genpd_xlate_t xlate, void *data) { … } static bool genpd_present(const struct generic_pm_domain *genpd) { … } /** * of_genpd_add_provider_simple() - Register a simple PM domain provider * @np: Device node pointer associated with the PM domain provider. * @genpd: Pointer to PM domain associated with the PM domain provider. */ int of_genpd_add_provider_simple(struct device_node *np, struct generic_pm_domain *genpd) { … } EXPORT_SYMBOL_GPL(…); /** * of_genpd_add_provider_onecell() - Register a onecell PM domain provider * @np: Device node pointer associated with the PM domain provider. * @data: Pointer to the data associated with the PM domain provider. */ int of_genpd_add_provider_onecell(struct device_node *np, struct genpd_onecell_data *data) { … } EXPORT_SYMBOL_GPL(…); /** * of_genpd_del_provider() - Remove a previously registered PM domain provider * @np: Device node pointer associated with the PM domain provider */ void of_genpd_del_provider(struct device_node *np) { … } EXPORT_SYMBOL_GPL(…); /** * genpd_get_from_provider() - Look-up PM domain * @genpdspec: OF phandle args to use for look-up * * Looks for a PM domain provider under the node specified by @genpdspec and if * found, uses xlate function of the provider to map phandle args to a PM * domain. * * Returns a valid pointer to struct generic_pm_domain on success or ERR_PTR() * on failure. */ static struct generic_pm_domain *genpd_get_from_provider( const struct of_phandle_args *genpdspec) { … } /** * of_genpd_add_device() - Add a device to an I/O PM domain * @genpdspec: OF phandle args to use for look-up PM domain * @dev: Device to be added. * * Looks-up an I/O PM domain based upon phandle args provided and adds * the device to the PM domain. Returns a negative error code on failure. */ int of_genpd_add_device(const struct of_phandle_args *genpdspec, struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * of_genpd_add_subdomain - Add a subdomain to an I/O PM domain. * @parent_spec: OF phandle args to use for parent PM domain look-up * @subdomain_spec: OF phandle args to use for subdomain look-up * * Looks-up a parent PM domain and subdomain based upon phandle args * provided and adds the subdomain to the parent PM domain. Returns a * negative error code on failure. */ int of_genpd_add_subdomain(const struct of_phandle_args *parent_spec, const struct of_phandle_args *subdomain_spec) { … } EXPORT_SYMBOL_GPL(…); /** * of_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain. * @parent_spec: OF phandle args to use for parent PM domain look-up * @subdomain_spec: OF phandle args to use for subdomain look-up * * Looks-up a parent PM domain and subdomain based upon phandle args * provided and removes the subdomain from the parent PM domain. Returns a * negative error code on failure. */ int of_genpd_remove_subdomain(const struct of_phandle_args *parent_spec, const struct of_phandle_args *subdomain_spec) { … } EXPORT_SYMBOL_GPL(…); /** * of_genpd_remove_last - Remove the last PM domain registered for a provider * @np: Pointer to device node associated with provider * * Find the last PM domain that was added by a particular provider and * remove this PM domain from the list of PM domains. The provider is * identified by the 'provider' device structure that is passed. The PM * domain will only be removed, if the provider associated with domain * has been removed. * * Returns a valid pointer to struct generic_pm_domain on success or * ERR_PTR() on failure. */ struct generic_pm_domain *of_genpd_remove_last(struct device_node *np) { … } EXPORT_SYMBOL_GPL(…); static void genpd_release_dev(struct device *dev) { … } static const struct bus_type genpd_bus_type = …; /** * genpd_dev_pm_detach - Detach a device from its PM domain. * @dev: Device to detach. * @power_off: Currently not used * * Try to locate a corresponding generic PM domain, which the device was * attached to previously. If such is found, the device is detached from it. */ static void genpd_dev_pm_detach(struct device *dev, bool power_off) { … } static void genpd_dev_pm_sync(struct device *dev) { … } static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev, unsigned int index, bool power_on) { … } /** * genpd_dev_pm_attach - Attach a device to its PM domain using DT. * @dev: Device to attach. * * Parse device's OF node to find a PM domain specifier. If such is found, * attaches the device to retrieved pm_domain ops. * * Returns 1 on successfully attached PM domain, 0 when the device don't need a * PM domain or when multiple power-domains exists for it, else a negative error * code. Note that if a power-domain exists for the device, but it cannot be * found or turned on, then return -EPROBE_DEFER to ensure that the device is * not probed and to re-try again later. */ int genpd_dev_pm_attach(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * genpd_dev_pm_attach_by_id - Associate a device with one of its PM domains. * @dev: The device used to lookup the PM domain. * @index: The index of the PM domain. * * Parse device's OF node to find a PM domain specifier at the provided @index. * If such is found, creates a virtual device and attaches it to the retrieved * pm_domain ops. To deal with detaching of the virtual device, the ->detach() * callback in the struct dev_pm_domain are assigned to genpd_dev_pm_detach(). * * Returns the created virtual device if successfully attached PM domain, NULL * when the device don't need a PM domain, else an ERR_PTR() in case of * failures. If a power-domain exists for the device, but cannot be found or * turned on, then ERR_PTR(-EPROBE_DEFER) is returned to ensure that the device * is not probed and to re-try again later. */ struct device *genpd_dev_pm_attach_by_id(struct device *dev, unsigned int index) { … } EXPORT_SYMBOL_GPL(…); /** * genpd_dev_pm_attach_by_name - Associate a device with one of its PM domains. * @dev: The device used to lookup the PM domain. * @name: The name of the PM domain. * * Parse device's OF node to find a PM domain specifier using the * power-domain-names DT property. For further description see * genpd_dev_pm_attach_by_id(). */ struct device *genpd_dev_pm_attach_by_name(struct device *dev, const char *name) { … } static const struct of_device_id idle_state_match[] = …; static int genpd_parse_state(struct genpd_power_state *genpd_state, struct device_node *state_node) { … } static int genpd_iterate_idle_states(struct device_node *dn, struct genpd_power_state *states) { … } /** * of_genpd_parse_idle_states: Return array of idle states for the genpd. * * @dn: The genpd device node * @states: The pointer to which the state array will be saved. * @n: The count of elements in the array returned from this function. * * Returns the device states parsed from the OF node. The memory for the states * is allocated by this function and is the responsibility of the caller to * free the memory after use. If any or zero compatible domain idle states is * found it returns 0 and in case of errors, a negative error code is returned. */ int of_genpd_parse_idle_states(struct device_node *dn, struct genpd_power_state **states, int *n) { … } EXPORT_SYMBOL_GPL(…); static int __init genpd_bus_init(void) { … } core_initcall(genpd_bus_init); #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ /*** debugfs support ***/ #ifdef CONFIG_DEBUG_FS /* * TODO: This function is a slightly modified version of rtpm_status_show * from sysfs.c, so generalize it. */ static void rtpm_status_str(struct seq_file *s, struct device *dev) { … } static void mode_status_str(struct seq_file *s, struct device *dev) { … } static void perf_status_str(struct seq_file *s, struct device *dev) { … } static int genpd_summary_one(struct seq_file *s, struct generic_pm_domain *genpd) { … } static int summary_show(struct seq_file *s, void *data) { … } static int status_show(struct seq_file *s, void *data) { … } static int sub_domains_show(struct seq_file *s, void *data) { … } static int idle_states_show(struct seq_file *s, void *data) { … } static int active_time_show(struct seq_file *s, void *data) { … } static int total_idle_time_show(struct seq_file *s, void *data) { … } static int devices_show(struct seq_file *s, void *data) { … } static int perf_state_show(struct seq_file *s, void *data) { … } DEFINE_SHOW_ATTRIBUTE(…); DEFINE_SHOW_ATTRIBUTE(…); DEFINE_SHOW_ATTRIBUTE(…); DEFINE_SHOW_ATTRIBUTE(…); DEFINE_SHOW_ATTRIBUTE(…); DEFINE_SHOW_ATTRIBUTE(…); DEFINE_SHOW_ATTRIBUTE(…); DEFINE_SHOW_ATTRIBUTE(…); static void genpd_debug_add(struct generic_pm_domain *genpd) { … } static int __init genpd_debug_init(void) { … } late_initcall(genpd_debug_init); static void __exit genpd_debug_exit(void) { … } __exitcall(…); #endif /* CONFIG_DEBUG_FS */