// SPDX-License-Identifier: GPL-2.0-only /* * Generic OPP Interface * * Copyright (C) 2009-2010 Texas Instruments Incorporated. * Nishanth Menon * Romit Dasgupta * Kevin Hilman */ #define pr_fmt(fmt) … #include <linux/clk.h> #include <linux/errno.h> #include <linux/err.h> #include <linux/device.h> #include <linux/export.h> #include <linux/pm_domain.h> #include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/xarray.h> #include "opp.h" /* * The root of the list of all opp-tables. All opp_table structures branch off * from here, with each opp_table containing the list of opps it supports in * various states of availability. */ LIST_HEAD(…); /* Lock to allow exclusive modification to the device and opp lists */ DEFINE_MUTEX(…) …; /* Flag indicating that opp_tables list is being updated at the moment */ static bool opp_tables_busy; /* OPP ID allocator */ static DEFINE_XARRAY_ALLOC1(opp_configs); static bool _find_opp_dev(const struct device *dev, struct opp_table *opp_table) { … } static struct opp_table *_find_opp_table_unlocked(struct device *dev) { … } /** * _find_opp_table() - find opp_table struct using device pointer * @dev: device pointer used to lookup OPP table * * Search OPP table for one containing matching device. * * Return: pointer to 'struct opp_table' if found, otherwise -ENODEV or * -EINVAL based on type of error. * * The callers must call dev_pm_opp_put_opp_table() after the table is used. */ struct opp_table *_find_opp_table(struct device *dev) { … } /* * Returns true if multiple clocks aren't there, else returns false with WARN. * * We don't force clk_count == 1 here as there are users who don't have a clock * representation in the OPP table and manage the clock configuration themselves * in an platform specific way. */ static bool assert_single_clk(struct opp_table *opp_table) { … } /** * dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp * @opp: opp for which voltage has to be returned for * * Return: voltage in micro volt corresponding to the opp, else * return 0 * * This is useful only for devices with single power supply. */ unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_get_supplies() - Gets the supply information corresponding to an opp * @opp: opp for which voltage has to be returned for * @supplies: Placeholder for copying the supply information. * * Return: negative error number on failure, 0 otherwise on success after * setting @supplies. * * This can be used for devices with any number of power supplies. The caller * must ensure the @supplies array must contain space for each regulator. */ int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_get_power() - Gets the power corresponding to an opp * @opp: opp for which power has to be returned for * * Return: power in micro watt corresponding to the opp, else * return 0 * * This is useful only for devices with single power supply. */ unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_get_freq_indexed() - Gets the frequency corresponding to an * available opp with specified index * @opp: opp for which frequency has to be returned for * @index: index of the frequency within the required opp * * Return: frequency in hertz corresponding to the opp with specified index, * else return 0 */ unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_get_level() - Gets the level corresponding to an available opp * @opp: opp for which level value has to be returned for * * Return: level read from device tree corresponding to the opp, else * return U32_MAX. */ unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_get_required_pstate() - Gets the required performance state * corresponding to an available opp * @opp: opp for which performance state has to be returned for * @index: index of the required opp * * Return: performance state read from device tree corresponding to the * required opp, else return U32_MAX. */ unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp, unsigned int index) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_is_turbo() - Returns if opp is turbo OPP or not * @opp: opp for which turbo mode is being verified * * Turbo OPPs are not for normal use, and can be enabled (under certain * conditions) for short duration of times to finish high throughput work * quickly. Running on them for longer times may overheat the chip. * * Return: true if opp is turbo opp, else false. */ bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_get_max_clock_latency() - Get max clock latency in nanoseconds * @dev: device for which we do this operation * * Return: This function returns the max clock latency in nanoseconds. */ unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_get_max_volt_latency() - Get max voltage latency in nanoseconds * @dev: device for which we do this operation * * Return: This function returns the max voltage latency in nanoseconds. */ unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_get_max_transition_latency() - Get max transition latency in * nanoseconds * @dev: device for which we do this operation * * Return: This function returns the max transition latency, in nanoseconds, to * switch from one OPP to other. */ unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_get_suspend_opp_freq() - Get frequency of suspend opp in Hz * @dev: device for which we do this operation * * Return: This function returns the frequency of the OPP marked as suspend_opp * if one is available, else returns 0; */ unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); int _get_opp_count(struct opp_table *opp_table) { … } /** * dev_pm_opp_get_opp_count() - Get number of opps available in the opp table * @dev: device for which we do this operation * * Return: This function returns the number of available opps if there are any, * else returns 0 if none or the corresponding error value. */ int dev_pm_opp_get_opp_count(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /* Helpers to read keys */ static unsigned long _read_freq(struct dev_pm_opp *opp, int index) { … } static unsigned long _read_level(struct dev_pm_opp *opp, int index) { … } static unsigned long _read_bw(struct dev_pm_opp *opp, int index) { … } /* Generic comparison helpers */ static bool _compare_exact(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, unsigned long opp_key, unsigned long key) { … } static bool _compare_ceil(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, unsigned long opp_key, unsigned long key) { … } static bool _compare_floor(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, unsigned long opp_key, unsigned long key) { … } /* Generic key finding helpers */ static struct dev_pm_opp *_opp_table_find_key(struct opp_table *opp_table, unsigned long *key, int index, bool available, unsigned long (*read)(struct dev_pm_opp *opp, int index), bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, unsigned long opp_key, unsigned long key), bool (*assert)(struct opp_table *opp_table)) { … } static struct dev_pm_opp * _find_key(struct device *dev, unsigned long *key, int index, bool available, unsigned long (*read)(struct dev_pm_opp *opp, int index), bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, unsigned long opp_key, unsigned long key), bool (*assert)(struct opp_table *opp_table)) { … } static struct dev_pm_opp *_find_key_exact(struct device *dev, unsigned long key, int index, bool available, unsigned long (*read)(struct dev_pm_opp *opp, int index), bool (*assert)(struct opp_table *opp_table)) { … } static struct dev_pm_opp *_opp_table_find_key_ceil(struct opp_table *opp_table, unsigned long *key, int index, bool available, unsigned long (*read)(struct dev_pm_opp *opp, int index), bool (*assert)(struct opp_table *opp_table)) { … } static struct dev_pm_opp *_find_key_ceil(struct device *dev, unsigned long *key, int index, bool available, unsigned long (*read)(struct dev_pm_opp *opp, int index), bool (*assert)(struct opp_table *opp_table)) { … } static struct dev_pm_opp *_find_key_floor(struct device *dev, unsigned long *key, int index, bool available, unsigned long (*read)(struct dev_pm_opp *opp, int index), bool (*assert)(struct opp_table *opp_table)) { … } /** * dev_pm_opp_find_freq_exact() - search for an exact frequency * @dev: device for which we do this operation * @freq: frequency to search for * @available: true/false - match for available opp * * Return: Searches for exact match in the opp table and returns pointer to the * matching opp if found, else returns ERR_PTR in case of error and should * be handled using IS_ERR. Error return values can be: * EINVAL: for bad pointer * ERANGE: no match found for search * ENODEV: if device not found in list of registered devices * * Note: available is a modifier for the search. if available=true, then the * match is for exact matching frequency and is available in the stored OPP * table. if false, the match is for exact frequency which is not available. * * This provides a mechanism to enable an opp which is not available currently * or the opposite as well. * * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, unsigned long freq, bool available) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_find_freq_exact_indexed() - Search for an exact freq for the * clock corresponding to the index * @dev: Device for which we do this operation * @freq: frequency to search for * @index: Clock index * @available: true/false - match for available opp * * Search for the matching exact OPP for the clock corresponding to the * specified index from a starting freq for a device. * * Return: matching *opp , else returns ERR_PTR in case of error and should be * handled using IS_ERR. Error return values can be: * EINVAL: for bad pointer * ERANGE: no match found for search * ENODEV: if device not found in list of registered devices * * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ struct dev_pm_opp * dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq, u32 index, bool available) { … } EXPORT_SYMBOL_GPL(…); static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table, unsigned long *freq) { … } /** * dev_pm_opp_find_freq_ceil() - Search for an rounded ceil freq * @dev: device for which we do this operation * @freq: Start frequency * * Search for the matching ceil *available* OPP from a starting freq * for a device. * * Return: matching *opp and refreshes *freq accordingly, else returns * ERR_PTR in case of error and should be handled using IS_ERR. Error return * values can be: * EINVAL: for bad pointer * ERANGE: no match found for search * ENODEV: if device not found in list of registered devices * * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, unsigned long *freq) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_find_freq_ceil_indexed() - Search for a rounded ceil freq for the * clock corresponding to the index * @dev: Device for which we do this operation * @freq: Start frequency * @index: Clock index * * Search for the matching ceil *available* OPP for the clock corresponding to * the specified index from a starting freq for a device. * * Return: matching *opp and refreshes *freq accordingly, else returns * ERR_PTR in case of error and should be handled using IS_ERR. Error return * values can be: * EINVAL: for bad pointer * ERANGE: no match found for search * ENODEV: if device not found in list of registered devices * * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ struct dev_pm_opp * dev_pm_opp_find_freq_ceil_indexed(struct device *dev, unsigned long *freq, u32 index) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_find_freq_floor() - Search for a rounded floor freq * @dev: device for which we do this operation * @freq: Start frequency * * Search for the matching floor *available* OPP from a starting freq * for a device. * * Return: matching *opp and refreshes *freq accordingly, else returns * ERR_PTR in case of error and should be handled using IS_ERR. Error return * values can be: * EINVAL: for bad pointer * ERANGE: no match found for search * ENODEV: if device not found in list of registered devices * * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, unsigned long *freq) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_find_freq_floor_indexed() - Search for a rounded floor freq for the * clock corresponding to the index * @dev: Device for which we do this operation * @freq: Start frequency * @index: Clock index * * Search for the matching floor *available* OPP for the clock corresponding to * the specified index from a starting freq for a device. * * Return: matching *opp and refreshes *freq accordingly, else returns * ERR_PTR in case of error and should be handled using IS_ERR. Error return * values can be: * EINVAL: for bad pointer * ERANGE: no match found for search * ENODEV: if device not found in list of registered devices * * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ struct dev_pm_opp * dev_pm_opp_find_freq_floor_indexed(struct device *dev, unsigned long *freq, u32 index) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_find_level_exact() - search for an exact level * @dev: device for which we do this operation * @level: level to search for * * Return: Searches for exact match in the opp table and returns pointer to the * matching opp if found, else returns ERR_PTR in case of error and should * be handled using IS_ERR. Error return values can be: * EINVAL: for bad pointer * ERANGE: no match found for search * ENODEV: if device not found in list of registered devices * * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev, unsigned int level) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_find_level_ceil() - search for an rounded up level * @dev: device for which we do this operation * @level: level to search for * * Return: Searches for rounded up match in the opp table and returns pointer * to the matching opp if found, else returns ERR_PTR in case of error and * should be handled using IS_ERR. Error return values can be: * EINVAL: for bad pointer * ERANGE: no match found for search * ENODEV: if device not found in list of registered devices * * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev, unsigned int *level) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_find_level_floor() - Search for a rounded floor level * @dev: device for which we do this operation * @level: Start level * * Search for the matching floor *available* OPP from a starting level * for a device. * * Return: matching *opp and refreshes *level accordingly, else returns * ERR_PTR in case of error and should be handled using IS_ERR. Error return * values can be: * EINVAL: for bad pointer * ERANGE: no match found for search * ENODEV: if device not found in list of registered devices * * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ struct dev_pm_opp *dev_pm_opp_find_level_floor(struct device *dev, unsigned int *level) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_find_bw_ceil() - Search for a rounded ceil bandwidth * @dev: device for which we do this operation * @bw: start bandwidth * @index: which bandwidth to compare, in case of OPPs with several values * * Search for the matching floor *available* OPP from a starting bandwidth * for a device. * * Return: matching *opp and refreshes *bw accordingly, else returns * ERR_PTR in case of error and should be handled using IS_ERR. Error return * values can be: * EINVAL: for bad pointer * ERANGE: no match found for search * ENODEV: if device not found in list of registered devices * * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev, unsigned int *bw, int index) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_find_bw_floor() - Search for a rounded floor bandwidth * @dev: device for which we do this operation * @bw: start bandwidth * @index: which bandwidth to compare, in case of OPPs with several values * * Search for the matching floor *available* OPP from a starting bandwidth * for a device. * * Return: matching *opp and refreshes *bw accordingly, else returns * ERR_PTR in case of error and should be handled using IS_ERR. Error return * values can be: * EINVAL: for bad pointer * ERANGE: no match found for search * ENODEV: if device not found in list of registered devices * * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. */ struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev, unsigned int *bw, int index) { … } EXPORT_SYMBOL_GPL(…); static int _set_opp_voltage(struct device *dev, struct regulator *reg, struct dev_pm_opp_supply *supply) { … } static int _opp_config_clk_single(struct device *dev, struct opp_table *opp_table, struct dev_pm_opp *opp, void *data, bool scaling_down) { … } /* * Simple implementation for configuring multiple clocks. Configure clocks in * the order in which they are present in the array while scaling up. */ int dev_pm_opp_config_clks_simple(struct device *dev, struct opp_table *opp_table, struct dev_pm_opp *opp, void *data, bool scaling_down) { … } EXPORT_SYMBOL_GPL(…); static int _opp_config_regulator_single(struct device *dev, struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp, struct regulator **regulators, unsigned int count) { … } static int _set_opp_bw(const struct opp_table *opp_table, struct dev_pm_opp *opp, struct device *dev) { … } /* This is only called for PM domain for now */ static int _set_required_opps(struct device *dev, struct opp_table *opp_table, struct dev_pm_opp *opp, bool up) { … } static int _set_opp_level(struct device *dev, struct dev_pm_opp *opp) { … } static void _find_current_opp(struct device *dev, struct opp_table *opp_table) { … } static int _disable_opp_table(struct device *dev, struct opp_table *opp_table) { … } static int _set_opp(struct device *dev, struct opp_table *opp_table, struct dev_pm_opp *opp, void *clk_data, bool forced) { … } /** * dev_pm_opp_set_rate() - Configure new OPP based on frequency * @dev: device for which we do this operation * @target_freq: frequency to achieve * * This configures the power-supplies to the levels specified by the OPP * corresponding to the target_freq, and programs the clock to a value <= * target_freq, as rounded by clk_round_rate(). Device wanting to run at fmax * provided by the opp, should have already rounded to the target OPP's * frequency. */ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_set_opp() - Configure device for OPP * @dev: device for which we do this operation * @opp: OPP to set to * * This configures the device based on the properties of the OPP passed to this * routine. * * Return: 0 on success, a negative error number otherwise. */ int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp) { … } EXPORT_SYMBOL_GPL(…); /* OPP-dev Helpers */ static void _remove_opp_dev(struct opp_device *opp_dev, struct opp_table *opp_table) { … } struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table) { … } static struct opp_table *_allocate_opp_table(struct device *dev, int index) { … } void _get_opp_table_kref(struct opp_table *opp_table) { … } static struct opp_table *_update_opp_table_clk(struct device *dev, struct opp_table *opp_table, bool getclk) { … } /* * We need to make sure that the OPP table for a device doesn't get added twice, * if this routine gets called in parallel with the same device pointer. * * The simplest way to enforce that is to perform everything (find existing * table and if not found, create a new one) under the opp_table_lock, so only * one creator gets access to the same. But that expands the critical section * under the lock and may end up causing circular dependencies with frameworks * like debugfs, interconnect or clock framework as they may be direct or * indirect users of OPP core. * * And for that reason we have to go for a bit tricky implementation here, which * uses the opp_tables_busy flag to indicate if another creator is in the middle * of adding an OPP table and others should wait for it to finish. */ struct opp_table *_add_opp_table_indexed(struct device *dev, int index, bool getclk) { … } static struct opp_table *_add_opp_table(struct device *dev, bool getclk) { … } struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); static void _opp_table_kref_release(struct kref *kref) { … } void dev_pm_opp_put_opp_table(struct opp_table *opp_table) { … } EXPORT_SYMBOL_GPL(…); void _opp_free(struct dev_pm_opp *opp) { … } static void _opp_kref_release(struct kref *kref) { … } void dev_pm_opp_get(struct dev_pm_opp *opp) { … } void dev_pm_opp_put(struct dev_pm_opp *opp) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_remove() - Remove an OPP from OPP table * @dev: device for which we do this operation * @freq: OPP to remove with matching 'freq' * * This function removes an opp from the opp table. */ void dev_pm_opp_remove(struct device *dev, unsigned long freq) { … } EXPORT_SYMBOL_GPL(…); static struct dev_pm_opp *_opp_get_next(struct opp_table *opp_table, bool dynamic) { … } /* * Can't call dev_pm_opp_put() from under the lock as debugfs removal needs to * happen lock less to avoid circular dependency issues. This routine must be * called without the opp_table->lock held. */ static void _opp_remove_all(struct opp_table *opp_table, bool dynamic) { … } bool _opp_remove_all_static(struct opp_table *opp_table) { … } /** * dev_pm_opp_remove_all_dynamic() - Remove all dynamically created OPPs * @dev: device for which we do this operation * * This function removes all dynamically created OPPs from the opp table. */ void dev_pm_opp_remove_all_dynamic(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table) { … } static bool _opp_supported_by_regulators(struct dev_pm_opp *opp, struct opp_table *opp_table) { … } static int _opp_compare_rate(struct opp_table *opp_table, struct dev_pm_opp *opp1, struct dev_pm_opp *opp2) { … } static int _opp_compare_bw(struct opp_table *opp_table, struct dev_pm_opp *opp1, struct dev_pm_opp *opp2) { … } /* * Returns * 0: opp1 == opp2 * 1: opp1 > opp2 * -1: opp1 < opp2 */ int _opp_compare_key(struct opp_table *opp_table, struct dev_pm_opp *opp1, struct dev_pm_opp *opp2) { … } static int _opp_is_duplicate(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, struct list_head **head) { … } void _required_opps_available(struct dev_pm_opp *opp, int count) { … } /* * Returns: * 0: On success. And appropriate error message for duplicate OPPs. * -EBUSY: For OPP with same freq/volt and is available. The callers of * _opp_add() must return 0 if they receive -EBUSY from it. This is to make * sure we don't print error messages unnecessarily if different parts of * kernel try to initialize the OPP table. * -EEXIST: For OPP with same freq but different volt or is unavailable. This * should be considered an error by the callers of _opp_add(). */ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table) { … } /** * _opp_add_v1() - Allocate a OPP based on v1 bindings. * @opp_table: OPP table * @dev: device for which we do this operation * @data: The OPP data for the OPP to add * @dynamic: Dynamically added OPPs. * * This function adds an opp definition to the opp table and returns status. * The opp is made available by default and it can be controlled using * dev_pm_opp_enable/disable functions and may be removed by dev_pm_opp_remove. * * NOTE: "dynamic" parameter impacts OPPs added by the dev_pm_opp_of_add_table * and freed by dev_pm_opp_of_remove_table. * * Return: * 0 On success OR * Duplicate OPPs (both freq and volt are same) and opp->available * -EEXIST Freq are same and volt are different OR * Duplicate OPPs (both freq and volt are same) and !opp->available * -ENOMEM Memory allocation failure */ int _opp_add_v1(struct opp_table *opp_table, struct device *dev, struct dev_pm_opp_data *data, bool dynamic) { … } /* * This is required only for the V2 bindings, and it enables a platform to * specify the hierarchy of versions it supports. OPP layer will then enable * OPPs, which are available for those versions, based on its 'opp-supported-hw' * property. */ static int _opp_set_supported_hw(struct opp_table *opp_table, const u32 *versions, unsigned int count) { … } static void _opp_put_supported_hw(struct opp_table *opp_table) { … } /* * This is required only for the V2 bindings, and it enables a platform to * specify the extn to be used for certain property names. The properties to * which the extension will apply are opp-microvolt and opp-microamp. OPP core * should postfix the property name with -<name> while looking for them. */ static int _opp_set_prop_name(struct opp_table *opp_table, const char *name) { … } static void _opp_put_prop_name(struct opp_table *opp_table) { … } /* * In order to support OPP switching, OPP layer needs to know the name of the * device's regulators, as the core would be required to switch voltages as * well. * * This must be called before any OPPs are initialized for the device. */ static int _opp_set_regulators(struct opp_table *opp_table, struct device *dev, const char * const names[]) { … } static void _opp_put_regulators(struct opp_table *opp_table) { … } static void _put_clks(struct opp_table *opp_table, int count) { … } /* * In order to support OPP switching, OPP layer needs to get pointers to the * clocks for the device. Simple cases work fine without using this routine * (i.e. by passing connection-id as NULL), but for a device with multiple * clocks available, the OPP core needs to know the exact names of the clks to * use. * * This must be called before any OPPs are initialized for the device. */ static int _opp_set_clknames(struct opp_table *opp_table, struct device *dev, const char * const names[], config_clks_t config_clks) { … } static void _opp_put_clknames(struct opp_table *opp_table) { … } /* * This is useful to support platforms with multiple regulators per device. * * This must be called before any OPPs are initialized for the device. */ static int _opp_set_config_regulators_helper(struct opp_table *opp_table, struct device *dev, config_regulators_t config_regulators) { … } static void _opp_put_config_regulators_helper(struct opp_table *opp_table) { … } static void _opp_detach_genpd(struct opp_table *opp_table) { … } /* * Multiple generic power domains for a device are supported with the help of * virtual genpd devices, which are created for each consumer device - genpd * pair. These are the device structures which are attached to the power domain * and are required by the OPP core to set the performance state of the genpd. * The same API also works for the case where single genpd is available and so * we don't need to support that separately. * * This helper will normally be called by the consumer driver of the device * "dev", as only that has details of the genpd names. * * This helper needs to be called once with a list of all genpd to attach. * Otherwise the original device structure will be used instead by the OPP core. * * The order of entries in the names array must match the order in which * "required-opps" are added in DT. */ static int _opp_attach_genpd(struct opp_table *opp_table, struct device *dev, const char * const *names, struct device ***virt_devs) { … } static int _opp_set_required_devs(struct opp_table *opp_table, struct device *dev, struct device **required_devs) { … } static void _opp_put_required_devs(struct opp_table *opp_table) { … } static void _opp_clear_config(struct opp_config_data *data) { … } /** * dev_pm_opp_set_config() - Set OPP configuration for the device. * @dev: Device for which configuration is being set. * @config: OPP configuration. * * This allows all device OPP configurations to be performed at once. * * This must be called before any OPPs are initialized for the device. This may * be called multiple times for the same OPP table, for example once for each * CPU that share the same table. This must be balanced by the same number of * calls to dev_pm_opp_clear_config() in order to free the OPP table properly. * * This returns a token to the caller, which must be passed to * dev_pm_opp_clear_config() to free the resources later. The value of the * returned token will be >= 1 for success and negative for errors. The minimum * value of 1 is chosen here to make it easy for callers to manage the resource. */ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_clear_config() - Releases resources blocked for OPP configuration. * @token: The token returned by dev_pm_opp_set_config() previously. * * This allows all device OPP configurations to be cleared at once. This must be * called once for each call made to dev_pm_opp_set_config(), in order to free * the OPPs properly. * * Currently the first call itself ends up freeing all the OPP configurations, * while the later ones only drop the OPP table reference. This works well for * now as we would never want to use an half initialized OPP table and want to * remove the configurations together. */ void dev_pm_opp_clear_config(int token) { … } EXPORT_SYMBOL_GPL(…); static void devm_pm_opp_config_release(void *token) { … } /** * devm_pm_opp_set_config() - Set OPP configuration for the device. * @dev: Device for which configuration is being set. * @config: OPP configuration. * * This allows all device OPP configurations to be performed at once. * This is a resource-managed variant of dev_pm_opp_set_config(). * * Return: 0 on success and errorno otherwise. */ int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_xlate_required_opp() - Find required OPP for @src_table OPP. * @src_table: OPP table which has @dst_table as one of its required OPP table. * @dst_table: Required OPP table of the @src_table. * @src_opp: OPP from the @src_table. * * This function returns the OPP (present in @dst_table) pointed out by the * "required-opps" property of the @src_opp (present in @src_table). * * The callers are required to call dev_pm_opp_put() for the returned OPP after * use. * * Return: pointer to 'struct dev_pm_opp' on success and errorno otherwise. */ struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, struct opp_table *dst_table, struct dev_pm_opp *src_opp) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_xlate_performance_state() - Find required OPP's pstate for src_table. * @src_table: OPP table which has dst_table as one of its required OPP table. * @dst_table: Required OPP table of the src_table. * @pstate: Current performance state of the src_table. * * This Returns pstate of the OPP (present in @dst_table) pointed out by the * "required-opps" property of the OPP (present in @src_table) which has * performance state set to @pstate. * * Return: Zero or positive performance state on success, otherwise negative * value on errors. */ int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate) { … } /** * dev_pm_opp_add_dynamic() - Add an OPP table from a table definitions * @dev: The device for which we do this operation * @data: The OPP data for the OPP to add * * This function adds an opp definition to the opp table and returns status. * The opp is made available by default and it can be controlled using * dev_pm_opp_enable/disable functions. * * Return: * 0 On success OR * Duplicate OPPs (both freq and volt are same) and opp->available * -EEXIST Freq are same and volt are different OR * Duplicate OPPs (both freq and volt are same) and !opp->available * -ENOMEM Memory allocation failure */ int dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *data) { … } EXPORT_SYMBOL_GPL(…); /** * _opp_set_availability() - helper to set the availability of an opp * @dev: device for which we do this operation * @freq: OPP frequency to modify availability * @availability_req: availability status requested for this opp * * Set the availability of an OPP, opp_{enable,disable} share a common logic * which is isolated here. * * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the * copy operation, returns 0 if no modification was done OR modification was * successful. */ static int _opp_set_availability(struct device *dev, unsigned long freq, bool availability_req) { … } /** * dev_pm_opp_adjust_voltage() - helper to change the voltage of an OPP * @dev: device for which we do this operation * @freq: OPP frequency to adjust voltage of * @u_volt: new OPP target voltage * @u_volt_min: new OPP min voltage * @u_volt_max: new OPP max voltage * * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the * copy operation, returns 0 if no modifcation was done OR modification was * successful. */ int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq, unsigned long u_volt, unsigned long u_volt_min, unsigned long u_volt_max) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_sync_regulators() - Sync state of voltage regulators * @dev: device for which we do this operation * * Sync voltage state of the OPP table regulators. * * Return: 0 on success or a negative error value. */ int dev_pm_opp_sync_regulators(struct device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_enable() - Enable a specific OPP * @dev: device for which we do this operation * @freq: OPP frequency to enable * * Enables a provided opp. If the operation is valid, this returns 0, else the * corresponding error value. It is meant to be used for users an OPP available * after being temporarily made unavailable with dev_pm_opp_disable. * * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the * copy operation, returns 0 if no modification was done OR modification was * successful. */ int dev_pm_opp_enable(struct device *dev, unsigned long freq) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_disable() - Disable a specific OPP * @dev: device for which we do this operation * @freq: OPP frequency to disable * * Disables a provided opp. If the operation is valid, this returns * 0, else the corresponding error value. It is meant to be a temporary * control by users to make this OPP not available until the circumstances are * right to make it available again (with a call to dev_pm_opp_enable). * * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the * copy operation, returns 0 if no modification was done OR modification was * successful. */ int dev_pm_opp_disable(struct device *dev, unsigned long freq) { … } EXPORT_SYMBOL_GPL(…); /** * dev_pm_opp_register_notifier() - Register OPP notifier for the device * @dev: Device for which notifier needs to be registered * @nb: Notifier block to be registered * * Return: 0 on success or a negative error value. */ int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb) { … } EXPORT_SYMBOL(…); /** * dev_pm_opp_unregister_notifier() - Unregister OPP notifier for the device * @dev: Device for which notifier needs to be unregistered * @nb: Notifier block to be unregistered * * Return: 0 on success or a negative error value. */ int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb) { … } EXPORT_SYMBOL(…); /** * dev_pm_opp_remove_table() - Free all OPPs associated with the device * @dev: device pointer used to lookup OPP table. * * Free both OPPs created using static entries present in DT and the * dynamically added entries. */ void dev_pm_opp_remove_table(struct device *dev) { … } EXPORT_SYMBOL_GPL(…);