···1818#include <linux/err.h>1919#include <linux/slab.h>2020#include <linux/device.h>2121-#include <linux/of.h>2221#include <linux/export.h>2322#include <linux/regulator/consumer.h>2423···2829 * from here, with each opp_table containing the list of opps it supports in2930 * various states of availability.3031 */3131-static LIST_HEAD(opp_tables);3232+LIST_HEAD(opp_tables);3233/* Lock to allow exclusive modification to the device and opp lists */3334DEFINE_MUTEX(opp_table_lock);3435···4849 list_for_each_entry(opp_dev, &opp_table->dev_list, node)4950 if (opp_dev->dev == dev)5051 return opp_dev;5151-5252- return NULL;5353-}5454-5555-static struct opp_table *_managed_opp(const struct device_node *np)5656-{5757- struct opp_table *opp_table;5858-5959- list_for_each_entry_rcu(opp_table, &opp_tables, node) {6060- if (opp_table->np == np) {6161- /*6262- * Multiple devices can point to the same OPP table and6363- * so will have same node-pointer, np.6464- *6565- * But the OPPs will be considered as shared only if the6666- * OPP table contains a "opp-shared" property.6767- */6868- return opp_table->shared_opp ? opp_table : NULL;6969- }7070- }71527253 return NULL;7354}···736757{737758 struct opp_table *opp_table;738759 struct opp_device *opp_dev;739739- struct device_node *np;740760 int ret;741761742762 /* Check for existing table for 'dev' first */···759781 return NULL;760782 }761783762762- /*763763- * Only required for backward compatibility with v1 bindings, but isn't764764- * harmful for other cases. And so we do it unconditionally.765765- */766766- np = of_node_get(dev->of_node);767767- if (np) {768768- u32 val;769769-770770- if (!of_property_read_u32(np, "clock-latency", &val))771771- opp_table->clock_latency_ns_max = val;772772- of_property_read_u32(np, "voltage-tolerance",773773- &opp_table->voltage_tolerance_v1);774774- of_node_put(np);775775- }784784+ _of_init_opp_table(opp_table, dev);776785777786 /* Set regulator to a non-NULL error value */778787 opp_table->regulator = ERR_PTR(-ENXIO);···855890 * It is assumed that the caller holds required mutex for an RCU updater856891 * strategy.857892 */858858-static void _opp_remove(struct opp_table *opp_table,859859- struct dev_pm_opp *opp, bool notify)893893+void _opp_remove(struct opp_table *opp_table, struct dev_pm_opp *opp,894894+ bool notify)860895{861896 /*862897 * Notify the changes in the availability of the operable···917952}918953EXPORT_SYMBOL_GPL(dev_pm_opp_remove);919954920920-static struct dev_pm_opp *_allocate_opp(struct device *dev,921921- struct opp_table **opp_table)955955+struct dev_pm_opp *_allocate_opp(struct device *dev,956956+ struct opp_table **opp_table)922957{923958 struct dev_pm_opp *opp;924959···954989 return true;955990}956991957957-static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,958958- struct opp_table *opp_table)992992+int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,993993+ struct opp_table *opp_table)959994{960995 struct dev_pm_opp *opp;961996 struct list_head *head = &opp_table->opp_list;···10311066 * Duplicate OPPs (both freq and volt are same) and !opp->available10321067 * -ENOMEM Memory allocation failure10331068 */10341034-static int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt,10351035- bool dynamic)10691069+int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt,10701070+ bool dynamic)10361071{10371072 struct opp_table *opp_table;10381073 struct dev_pm_opp *new_opp;···10751110unlock:10761111 mutex_unlock(&opp_table_lock);10771112 return ret;10781078-}10791079-10801080-/* TODO: Support multiple regulators */10811081-static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,10821082- struct opp_table *opp_table)10831083-{10841084- u32 microvolt[3] = {0};10851085- u32 val;10861086- int count, ret;10871087- struct property *prop = NULL;10881088- char name[NAME_MAX];10891089-10901090- /* Search for "opp-microvolt-<name>" */10911091- if (opp_table->prop_name) {10921092- snprintf(name, sizeof(name), "opp-microvolt-%s",10931093- opp_table->prop_name);10941094- prop = of_find_property(opp->np, name, NULL);10951095- }10961096-10971097- if (!prop) {10981098- /* Search for "opp-microvolt" */10991099- sprintf(name, "opp-microvolt");11001100- prop = of_find_property(opp->np, name, NULL);11011101-11021102- /* Missing property isn't a problem, but an invalid entry is */11031103- if (!prop)11041104- return 0;11051105- }11061106-11071107- count = of_property_count_u32_elems(opp->np, name);11081108- if (count < 0) {11091109- dev_err(dev, "%s: Invalid %s property (%d)\n",11101110- __func__, name, count);11111111- return count;11121112- }11131113-11141114- /* There can be one or three elements here */11151115- if (count != 1 && count != 3) {11161116- dev_err(dev, "%s: Invalid number of elements in %s property (%d)\n",11171117- __func__, name, count);11181118- return -EINVAL;11191119- }11201120-11211121- ret = of_property_read_u32_array(opp->np, name, microvolt, count);11221122- if (ret) {11231123- dev_err(dev, "%s: error parsing %s: %d\n", __func__, name, ret);11241124- return -EINVAL;11251125- }11261126-11271127- opp->u_volt = microvolt[0];11281128-11291129- if (count == 1) {11301130- opp->u_volt_min = opp->u_volt;11311131- opp->u_volt_max = opp->u_volt;11321132- } else {11331133- opp->u_volt_min = microvolt[1];11341134- opp->u_volt_max = microvolt[2];11351135- }11361136-11371137- /* Search for "opp-microamp-<name>" */11381138- prop = NULL;11391139- if (opp_table->prop_name) {11401140- snprintf(name, sizeof(name), "opp-microamp-%s",11411141- opp_table->prop_name);11421142- prop = of_find_property(opp->np, name, NULL);11431143- }11441144-11451145- if (!prop) {11461146- /* Search for "opp-microamp" */11471147- sprintf(name, "opp-microamp");11481148- prop = of_find_property(opp->np, name, NULL);11491149- }11501150-11511151- if (prop && !of_property_read_u32(opp->np, name, &val))11521152- opp->u_amp = val;11531153-11541154- return 0;11551113}1156111411571115/**···14051517}14061518EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulator);1407151914081408-static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table,14091409- struct device_node *np)14101410-{14111411- unsigned int count = opp_table->supported_hw_count;14121412- u32 version;14131413- int ret;14141414-14151415- if (!opp_table->supported_hw)14161416- return true;14171417-14181418- while (count--) {14191419- ret = of_property_read_u32_index(np, "opp-supported-hw", count,14201420- &version);14211421- if (ret) {14221422- dev_warn(dev, "%s: failed to read opp-supported-hw property at index %d: %d\n",14231423- __func__, count, ret);14241424- return false;14251425- }14261426-14271427- /* Both of these are bitwise masks of the versions */14281428- if (!(version & opp_table->supported_hw[count]))14291429- return false;14301430- }14311431-14321432- return true;14331433-}14341434-14351435-/**14361436- * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)14371437- * @dev: device for which we do this operation14381438- * @np: device node14391439- *14401440- * This function adds an opp definition to the opp table and returns status. The14411441- * opp can be controlled using dev_pm_opp_enable/disable functions and may be14421442- * removed by dev_pm_opp_remove.14431443- *14441444- * Locking: The internal opp_table and opp structures are RCU protected.14451445- * Hence this function internally uses RCU updater strategy with mutex locks14461446- * to keep the integrity of the internal data structures. Callers should ensure14471447- * that this function is *NOT* called under RCU protection or in contexts where14481448- * mutex cannot be locked.14491449- *14501450- * Return:14511451- * 0 On success OR14521452- * Duplicate OPPs (both freq and volt are same) and opp->available14531453- * -EEXIST Freq are same and volt are different OR14541454- * Duplicate OPPs (both freq and volt are same) and !opp->available14551455- * -ENOMEM Memory allocation failure14561456- * -EINVAL Failed parsing the OPP node14571457- */14581458-static int _opp_add_static_v2(struct device *dev, struct device_node *np)14591459-{14601460- struct opp_table *opp_table;14611461- struct dev_pm_opp *new_opp;14621462- u64 rate;14631463- u32 val;14641464- int ret;14651465-14661466- /* Hold our table modification lock here */14671467- mutex_lock(&opp_table_lock);14681468-14691469- new_opp = _allocate_opp(dev, &opp_table);14701470- if (!new_opp) {14711471- ret = -ENOMEM;14721472- goto unlock;14731473- }14741474-14751475- ret = of_property_read_u64(np, "opp-hz", &rate);14761476- if (ret < 0) {14771477- dev_err(dev, "%s: opp-hz not found\n", __func__);14781478- goto free_opp;14791479- }14801480-14811481- /* Check if the OPP supports hardware's hierarchy of versions or not */14821482- if (!_opp_is_supported(dev, opp_table, np)) {14831483- dev_dbg(dev, "OPP not supported by hardware: %llu\n", rate);14841484- goto free_opp;14851485- }14861486-14871487- /*14881488- * Rate is defined as an unsigned long in clk API, and so casting14891489- * explicitly to its type. Must be fixed once rate is 64 bit14901490- * guaranteed in clk API.14911491- */14921492- new_opp->rate = (unsigned long)rate;14931493- new_opp->turbo = of_property_read_bool(np, "turbo-mode");14941494-14951495- new_opp->np = np;14961496- new_opp->dynamic = false;14971497- new_opp->available = true;14981498-14991499- if (!of_property_read_u32(np, "clock-latency-ns", &val))15001500- new_opp->clock_latency_ns = val;15011501-15021502- ret = opp_parse_supplies(new_opp, dev, opp_table);15031503- if (ret)15041504- goto free_opp;15051505-15061506- ret = _opp_add(dev, new_opp, opp_table);15071507- if (ret)15081508- goto free_opp;15091509-15101510- /* OPP to select on device suspend */15111511- if (of_property_read_bool(np, "opp-suspend")) {15121512- if (opp_table->suspend_opp) {15131513- dev_warn(dev, "%s: Multiple suspend OPPs found (%lu %lu)\n",15141514- __func__, opp_table->suspend_opp->rate,15151515- new_opp->rate);15161516- } else {15171517- new_opp->suspend = true;15181518- opp_table->suspend_opp = new_opp;15191519- }15201520- }15211521-15221522- if (new_opp->clock_latency_ns > opp_table->clock_latency_ns_max)15231523- opp_table->clock_latency_ns_max = new_opp->clock_latency_ns;15241524-15251525- mutex_unlock(&opp_table_lock);15261526-15271527- pr_debug("%s: turbo:%d rate:%lu uv:%lu uvmin:%lu uvmax:%lu latency:%lu\n",15281528- __func__, new_opp->turbo, new_opp->rate, new_opp->u_volt,15291529- new_opp->u_volt_min, new_opp->u_volt_max,15301530- new_opp->clock_latency_ns);15311531-15321532- /*15331533- * Notify the changes in the availability of the operable15341534- * frequency/voltage list.15351535- */15361536- srcu_notifier_call_chain(&opp_table->srcu_head, OPP_EVENT_ADD, new_opp);15371537- return 0;15381538-15391539-free_opp:15401540- _opp_remove(opp_table, new_opp, false);15411541-unlock:15421542- mutex_unlock(&opp_table_lock);15431543- return ret;15441544-}15451545-15461520/**15471521 * dev_pm_opp_add() - Add an OPP table from a table definitions15481522 * @dev: device for which we do this operation···15921842}15931843EXPORT_SYMBOL_GPL(dev_pm_opp_get_notifier);1594184415951595-#ifdef CONFIG_OF15961596-/**15971597- * dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT15981598- * entries15991599- * @dev: device pointer used to lookup OPP table.16001600- *16011601- * Free OPPs created using static entries present in DT.16021602- *16031603- * Locking: The internal opp_table and opp structures are RCU protected.16041604- * Hence this function indirectly uses RCU updater strategy with mutex locks16051605- * to keep the integrity of the internal data structures. Callers should ensure16061606- * that this function is *NOT* called under RCU protection or in contexts where16071607- * mutex cannot be locked.18451845+/*18461846+ * Free OPPs either created using static entries present in DT or even the18471847+ * dynamically added entries based on remove_all param.16081848 */16091609-void dev_pm_opp_of_remove_table(struct device *dev)18491849+void _dev_pm_opp_remove_table(struct device *dev, bool remove_all)16101850{16111851 struct opp_table *opp_table;16121852 struct dev_pm_opp *opp, *tmp;···16211881 if (list_is_singular(&opp_table->dev_list)) {16221882 /* Free static OPPs */16231883 list_for_each_entry_safe(opp, tmp, &opp_table->opp_list, node) {16241624- if (!opp->dynamic)18841884+ if (remove_all || !opp->dynamic)16251885 _opp_remove(opp_table, opp, true);16261886 }16271887 } else {···16311891unlock:16321892 mutex_unlock(&opp_table_lock);16331893}16341634-EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table);16351635-16361636-/* Returns opp descriptor node for a device, caller must do of_node_put() */16371637-struct device_node *_of_get_opp_desc_node(struct device *dev)16381638-{16391639- /*16401640- * TODO: Support for multiple OPP tables.16411641- *16421642- * There should be only ONE phandle present in "operating-points-v2"16431643- * property.16441644- */16451645-16461646- return of_parse_phandle(dev->of_node, "operating-points-v2", 0);16471647-}16481648-16491649-/* Initializes OPP tables based on new bindings */16501650-static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np)16511651-{16521652- struct device_node *np;16531653- struct opp_table *opp_table;16541654- int ret = 0, count = 0;16551655-16561656- mutex_lock(&opp_table_lock);16571657-16581658- opp_table = _managed_opp(opp_np);16591659- if (opp_table) {16601660- /* OPPs are already managed */16611661- if (!_add_opp_dev(dev, opp_table))16621662- ret = -ENOMEM;16631663- mutex_unlock(&opp_table_lock);16641664- return ret;16651665- }16661666- mutex_unlock(&opp_table_lock);16671667-16681668- /* We have opp-table node now, iterate over it and add OPPs */16691669- for_each_available_child_of_node(opp_np, np) {16701670- count++;16711671-16721672- ret = _opp_add_static_v2(dev, np);16731673- if (ret) {16741674- dev_err(dev, "%s: Failed to add OPP, %d\n", __func__,16751675- ret);16761676- goto free_table;16771677- }16781678- }16791679-16801680- /* There should be one of more OPP defined */16811681- if (WARN_ON(!count))16821682- return -ENOENT;16831683-16841684- mutex_lock(&opp_table_lock);16851685-16861686- opp_table = _find_opp_table(dev);16871687- if (WARN_ON(IS_ERR(opp_table))) {16881688- ret = PTR_ERR(opp_table);16891689- mutex_unlock(&opp_table_lock);16901690- goto free_table;16911691- }16921692-16931693- opp_table->np = opp_np;16941694- opp_table->shared_opp = of_property_read_bool(opp_np, "opp-shared");16951695-16961696- mutex_unlock(&opp_table_lock);16971697-16981698- return 0;16991699-17001700-free_table:17011701- dev_pm_opp_of_remove_table(dev);17021702-17031703- return ret;17041704-}17051705-17061706-/* Initializes OPP tables based on old-deprecated bindings */17071707-static int _of_add_opp_table_v1(struct device *dev)17081708-{17091709- const struct property *prop;17101710- const __be32 *val;17111711- int nr;17121712-17131713- prop = of_find_property(dev->of_node, "operating-points", NULL);17141714- if (!prop)17151715- return -ENODEV;17161716- if (!prop->value)17171717- return -ENODATA;17181718-17191719- /*17201720- * Each OPP is a set of tuples consisting of frequency and17211721- * voltage like <freq-kHz vol-uV>.17221722- */17231723- nr = prop->length / sizeof(u32);17241724- if (nr % 2) {17251725- dev_err(dev, "%s: Invalid OPP table\n", __func__);17261726- return -EINVAL;17271727- }17281728-17291729- val = prop->value;17301730- while (nr) {17311731- unsigned long freq = be32_to_cpup(val++) * 1000;17321732- unsigned long volt = be32_to_cpup(val++);17331733-17341734- if (_opp_add_v1(dev, freq, volt, false))17351735- dev_warn(dev, "%s: Failed to add OPP %ld\n",17361736- __func__, freq);17371737- nr -= 2;17381738- }17391739-17401740- return 0;17411741-}1742189417431895/**17441744- * dev_pm_opp_of_add_table() - Initialize opp table from device tree18961896+ * dev_pm_opp_remove_table() - Free all OPPs associated with the device17451897 * @dev: device pointer used to lookup OPP table.17461898 *17471747- * Register the initial OPP table with the OPP library for given device.18991899+ * Free both OPPs created using static entries present in DT and the19001900+ * dynamically added entries.17481901 *17491902 * Locking: The internal opp_table and opp structures are RCU protected.17501903 * Hence this function indirectly uses RCU updater strategy with mutex locks17511904 * to keep the integrity of the internal data structures. Callers should ensure17521905 * that this function is *NOT* called under RCU protection or in contexts where17531906 * mutex cannot be locked.17541754- *17551755- * Return:17561756- * 0 On success OR17571757- * Duplicate OPPs (both freq and volt are same) and opp->available17581758- * -EEXIST Freq are same and volt are different OR17591759- * Duplicate OPPs (both freq and volt are same) and !opp->available17601760- * -ENOMEM Memory allocation failure17611761- * -ENODEV when 'operating-points' property is not found or is invalid data17621762- * in device node.17631763- * -ENODATA when empty 'operating-points' property is found17641764- * -EINVAL when invalid entries are found in opp-v2 table17651907 */17661766-int dev_pm_opp_of_add_table(struct device *dev)19081908+void dev_pm_opp_remove_table(struct device *dev)17671909{17681768- struct device_node *opp_np;17691769- int ret;17701770-17711771- /*17721772- * OPPs have two version of bindings now. The older one is deprecated,17731773- * try for the new binding first.17741774- */17751775- opp_np = _of_get_opp_desc_node(dev);17761776- if (!opp_np) {17771777- /*17781778- * Try old-deprecated bindings for backward compatibility with17791779- * older dtbs.17801780- */17811781- return _of_add_opp_table_v1(dev);17821782- }17831783-17841784- ret = _of_add_opp_table_v2(dev, opp_np);17851785- of_node_put(opp_np);17861786-17871787- return ret;19101910+ _dev_pm_opp_remove_table(dev, true);17881911}17891789-EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table);17901790-#endif19121912+EXPORT_SYMBOL_GPL(dev_pm_opp_remove_table);
+97-102
drivers/base/power/opp/cpu.c
···1818#include <linux/err.h>1919#include <linux/errno.h>2020#include <linux/export.h>2121-#include <linux/of.h>2221#include <linux/slab.h>23222423#include "opp.h"···118119EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table);119120#endif /* CONFIG_CPU_FREQ */120121121121-/* Required only for V1 bindings, as v2 can manage it from DT itself */122122-int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)122122+void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of)123123+{124124+ struct device *cpu_dev;125125+ int cpu;126126+127127+ WARN_ON(cpumask_empty(cpumask));128128+129129+ for_each_cpu(cpu, cpumask) {130130+ cpu_dev = get_cpu_device(cpu);131131+ if (!cpu_dev) {132132+ pr_err("%s: failed to get cpu%d device\n", __func__,133133+ cpu);134134+ continue;135135+ }136136+137137+ if (of)138138+ dev_pm_opp_of_remove_table(cpu_dev);139139+ else140140+ dev_pm_opp_remove_table(cpu_dev);141141+ }142142+}143143+144144+/**145145+ * dev_pm_opp_cpumask_remove_table() - Removes OPP table for @cpumask146146+ * @cpumask: cpumask for which OPP table needs to be removed147147+ *148148+ * This removes the OPP tables for CPUs present in the @cpumask.149149+ * This should be used to remove all the OPPs entries associated with150150+ * the cpus in @cpumask.151151+ *152152+ * Locking: The internal opp_table and opp structures are RCU protected.153153+ * Hence this function internally uses RCU updater strategy with mutex locks154154+ * to keep the integrity of the internal data structures. Callers should ensure155155+ * that this function is *NOT* called under RCU protection or in contexts where156156+ * mutex cannot be locked.157157+ */158158+void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)159159+{160160+ _dev_pm_opp_cpumask_remove_table(cpumask, false);161161+}162162+EXPORT_SYMBOL_GPL(dev_pm_opp_cpumask_remove_table);163163+164164+/**165165+ * dev_pm_opp_set_sharing_cpus() - Mark OPP table as shared by few CPUs166166+ * @cpu_dev: CPU device for which we do this operation167167+ * @cpumask: cpumask of the CPUs which share the OPP table with @cpu_dev168168+ *169169+ * This marks OPP table of the @cpu_dev as shared by the CPUs present in170170+ * @cpumask.171171+ *172172+ * Returns -ENODEV if OPP table isn't already present.173173+ *174174+ * Locking: The internal opp_table and opp structures are RCU protected.175175+ * Hence this function internally uses RCU updater strategy with mutex locks176176+ * to keep the integrity of the internal data structures. Callers should ensure177177+ * that this function is *NOT* called under RCU protection or in contexts where178178+ * mutex cannot be locked.179179+ */180180+int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev,181181+ const struct cpumask *cpumask)123182{124183 struct opp_device *opp_dev;125184 struct opp_table *opp_table;···188131189132 opp_table = _find_opp_table(cpu_dev);190133 if (IS_ERR(opp_table)) {191191- ret = -EINVAL;134134+ ret = PTR_ERR(opp_table);192135 goto unlock;193136 }194137···209152 __func__, cpu);210153 continue;211154 }155155+156156+ /* Mark opp-table as multiple CPUs are sharing it now */157157+ opp_table->shared_opp = true;212158 }213159unlock:214160 mutex_unlock(&opp_table_lock);···220160}221161EXPORT_SYMBOL_GPL(dev_pm_opp_set_sharing_cpus);222162223223-#ifdef CONFIG_OF224224-void dev_pm_opp_of_cpumask_remove_table(cpumask_var_t cpumask)225225-{226226- struct device *cpu_dev;227227- int cpu;228228-229229- WARN_ON(cpumask_empty(cpumask));230230-231231- for_each_cpu(cpu, cpumask) {232232- cpu_dev = get_cpu_device(cpu);233233- if (!cpu_dev) {234234- pr_err("%s: failed to get cpu%d device\n", __func__,235235- cpu);236236- continue;237237- }238238-239239- dev_pm_opp_of_remove_table(cpu_dev);240240- }241241-}242242-EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table);243243-244244-int dev_pm_opp_of_cpumask_add_table(cpumask_var_t cpumask)245245-{246246- struct device *cpu_dev;247247- int cpu, ret = 0;248248-249249- WARN_ON(cpumask_empty(cpumask));250250-251251- for_each_cpu(cpu, cpumask) {252252- cpu_dev = get_cpu_device(cpu);253253- if (!cpu_dev) {254254- pr_err("%s: failed to get cpu%d device\n", __func__,255255- cpu);256256- continue;257257- }258258-259259- ret = dev_pm_opp_of_add_table(cpu_dev);260260- if (ret) {261261- pr_err("%s: couldn't find opp table for cpu:%d, %d\n",262262- __func__, cpu, ret);263263-264264- /* Free all other OPPs */265265- dev_pm_opp_of_cpumask_remove_table(cpumask);266266- break;267267- }268268- }269269-270270- return ret;271271-}272272-EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_add_table);273273-274274-/*275275- * Works only for OPP v2 bindings.163163+/**164164+ * dev_pm_opp_get_sharing_cpus() - Get cpumask of CPUs sharing OPPs with @cpu_dev165165+ * @cpu_dev: CPU device for which we do this operation166166+ * @cpumask: cpumask to update with information of sharing CPUs276167 *277277- * Returns -ENOENT if operating-points-v2 bindings aren't supported.168168+ * This updates the @cpumask with CPUs that are sharing OPPs with @cpu_dev.169169+ *170170+ * Returns -ENODEV if OPP table isn't already present.171171+ *172172+ * Locking: The internal opp_table and opp structures are RCU protected.173173+ * Hence this function internally uses RCU updater strategy with mutex locks174174+ * to keep the integrity of the internal data structures. Callers should ensure175175+ * that this function is *NOT* called under RCU protection or in contexts where176176+ * mutex cannot be locked.278177 */279279-int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask)178178+int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)280179{281281- struct device_node *np, *tmp_np;282282- struct device *tcpu_dev;283283- int cpu, ret = 0;180180+ struct opp_device *opp_dev;181181+ struct opp_table *opp_table;182182+ int ret = 0;284183285285- /* Get OPP descriptor node */286286- np = _of_get_opp_desc_node(cpu_dev);287287- if (!np) {288288- dev_dbg(cpu_dev, "%s: Couldn't find cpu_dev node.\n", __func__);289289- return -ENOENT;184184+ mutex_lock(&opp_table_lock);185185+186186+ opp_table = _find_opp_table(cpu_dev);187187+ if (IS_ERR(opp_table)) {188188+ ret = PTR_ERR(opp_table);189189+ goto unlock;290190 }291191292292- cpumask_set_cpu(cpu_dev->id, cpumask);192192+ cpumask_clear(cpumask);293193294294- /* OPPs are shared ? */295295- if (!of_property_read_bool(np, "opp-shared"))296296- goto put_cpu_node;297297-298298- for_each_possible_cpu(cpu) {299299- if (cpu == cpu_dev->id)300300- continue;301301-302302- tcpu_dev = get_cpu_device(cpu);303303- if (!tcpu_dev) {304304- dev_err(cpu_dev, "%s: failed to get cpu%d device\n",305305- __func__, cpu);306306- ret = -ENODEV;307307- goto put_cpu_node;308308- }309309-310310- /* Get OPP descriptor node */311311- tmp_np = _of_get_opp_desc_node(tcpu_dev);312312- if (!tmp_np) {313313- dev_err(tcpu_dev, "%s: Couldn't find tcpu_dev node.\n",314314- __func__);315315- ret = -ENOENT;316316- goto put_cpu_node;317317- }318318-319319- /* CPUs are sharing opp node */320320- if (np == tmp_np)321321- cpumask_set_cpu(cpu, cpumask);322322-323323- of_node_put(tmp_np);194194+ if (opp_table->shared_opp) {195195+ list_for_each_entry(opp_dev, &opp_table->dev_list, node)196196+ cpumask_set_cpu(opp_dev->dev->id, cpumask);197197+ } else {198198+ cpumask_set_cpu(cpu_dev->id, cpumask);324199 }325200326326-put_cpu_node:327327- of_node_put(np);201201+unlock:202202+ mutex_unlock(&opp_table_lock);203203+328204 return ret;329205}330330-EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus);331331-#endif206206+EXPORT_SYMBOL_GPL(dev_pm_opp_get_sharing_cpus);
+591
drivers/base/power/opp/of.c
···11+/*22+ * Generic OPP OF helpers33+ *44+ * Copyright (C) 2009-2010 Texas Instruments Incorporated.55+ * Nishanth Menon66+ * Romit Dasgupta77+ * Kevin Hilman88+ *99+ * This program is free software; you can redistribute it and/or modify1010+ * it under the terms of the GNU General Public License version 2 as1111+ * published by the Free Software Foundation.1212+ */1313+1414+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt1515+1616+#include <linux/cpu.h>1717+#include <linux/errno.h>1818+#include <linux/device.h>1919+#include <linux/of.h>2020+#include <linux/export.h>2121+2222+#include "opp.h"2323+2424+static struct opp_table *_managed_opp(const struct device_node *np)2525+{2626+ struct opp_table *opp_table;2727+2828+ list_for_each_entry_rcu(opp_table, &opp_tables, node) {2929+ if (opp_table->np == np) {3030+ /*3131+ * Multiple devices can point to the same OPP table and3232+ * so will have same node-pointer, np.3333+ *3434+ * But the OPPs will be considered as shared only if the3535+ * OPP table contains a "opp-shared" property.3636+ */3737+ return opp_table->shared_opp ? opp_table : NULL;3838+ }3939+ }4040+4141+ return NULL;4242+}4343+4444+void _of_init_opp_table(struct opp_table *opp_table, struct device *dev)4545+{4646+ struct device_node *np;4747+4848+ /*4949+ * Only required for backward compatibility with v1 bindings, but isn't5050+ * harmful for other cases. And so we do it unconditionally.5151+ */5252+ np = of_node_get(dev->of_node);5353+ if (np) {5454+ u32 val;5555+5656+ if (!of_property_read_u32(np, "clock-latency", &val))5757+ opp_table->clock_latency_ns_max = val;5858+ of_property_read_u32(np, "voltage-tolerance",5959+ &opp_table->voltage_tolerance_v1);6060+ of_node_put(np);6161+ }6262+}6363+6464+static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table,6565+ struct device_node *np)6666+{6767+ unsigned int count = opp_table->supported_hw_count;6868+ u32 version;6969+ int ret;7070+7171+ if (!opp_table->supported_hw)7272+ return true;7373+7474+ while (count--) {7575+ ret = of_property_read_u32_index(np, "opp-supported-hw", count,7676+ &version);7777+ if (ret) {7878+ dev_warn(dev, "%s: failed to read opp-supported-hw property at index %d: %d\n",7979+ __func__, count, ret);8080+ return false;8181+ }8282+8383+ /* Both of these are bitwise masks of the versions */8484+ if (!(version & opp_table->supported_hw[count]))8585+ return false;8686+ }8787+8888+ return true;8989+}9090+9191+/* TODO: Support multiple regulators */9292+static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,9393+ struct opp_table *opp_table)9494+{9595+ u32 microvolt[3] = {0};9696+ u32 val;9797+ int count, ret;9898+ struct property *prop = NULL;9999+ char name[NAME_MAX];100100+101101+ /* Search for "opp-microvolt-<name>" */102102+ if (opp_table->prop_name) {103103+ snprintf(name, sizeof(name), "opp-microvolt-%s",104104+ opp_table->prop_name);105105+ prop = of_find_property(opp->np, name, NULL);106106+ }107107+108108+ if (!prop) {109109+ /* Search for "opp-microvolt" */110110+ sprintf(name, "opp-microvolt");111111+ prop = of_find_property(opp->np, name, NULL);112112+113113+ /* Missing property isn't a problem, but an invalid entry is */114114+ if (!prop)115115+ return 0;116116+ }117117+118118+ count = of_property_count_u32_elems(opp->np, name);119119+ if (count < 0) {120120+ dev_err(dev, "%s: Invalid %s property (%d)\n",121121+ __func__, name, count);122122+ return count;123123+ }124124+125125+ /* There can be one or three elements here */126126+ if (count != 1 && count != 3) {127127+ dev_err(dev, "%s: Invalid number of elements in %s property (%d)\n",128128+ __func__, name, count);129129+ return -EINVAL;130130+ }131131+132132+ ret = of_property_read_u32_array(opp->np, name, microvolt, count);133133+ if (ret) {134134+ dev_err(dev, "%s: error parsing %s: %d\n", __func__, name, ret);135135+ return -EINVAL;136136+ }137137+138138+ opp->u_volt = microvolt[0];139139+140140+ if (count == 1) {141141+ opp->u_volt_min = opp->u_volt;142142+ opp->u_volt_max = opp->u_volt;143143+ } else {144144+ opp->u_volt_min = microvolt[1];145145+ opp->u_volt_max = microvolt[2];146146+ }147147+148148+ /* Search for "opp-microamp-<name>" */149149+ prop = NULL;150150+ if (opp_table->prop_name) {151151+ snprintf(name, sizeof(name), "opp-microamp-%s",152152+ opp_table->prop_name);153153+ prop = of_find_property(opp->np, name, NULL);154154+ }155155+156156+ if (!prop) {157157+ /* Search for "opp-microamp" */158158+ sprintf(name, "opp-microamp");159159+ prop = of_find_property(opp->np, name, NULL);160160+ }161161+162162+ if (prop && !of_property_read_u32(opp->np, name, &val))163163+ opp->u_amp = val;164164+165165+ return 0;166166+}167167+168168+/**169169+ * dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT170170+ * entries171171+ * @dev: device pointer used to lookup OPP table.172172+ *173173+ * Free OPPs created using static entries present in DT.174174+ *175175+ * Locking: The internal opp_table and opp structures are RCU protected.176176+ * Hence this function indirectly uses RCU updater strategy with mutex locks177177+ * to keep the integrity of the internal data structures. Callers should ensure178178+ * that this function is *NOT* called under RCU protection or in contexts where179179+ * mutex cannot be locked.180180+ */181181+void dev_pm_opp_of_remove_table(struct device *dev)182182+{183183+ _dev_pm_opp_remove_table(dev, false);184184+}185185+EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table);186186+187187+/* Returns opp descriptor node for a device, caller must do of_node_put() */188188+struct device_node *_of_get_opp_desc_node(struct device *dev)189189+{190190+ /*191191+ * TODO: Support for multiple OPP tables.192192+ *193193+ * There should be only ONE phandle present in "operating-points-v2"194194+ * property.195195+ */196196+197197+ return of_parse_phandle(dev->of_node, "operating-points-v2", 0);198198+}199199+200200+/**201201+ * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)202202+ * @dev: device for which we do this operation203203+ * @np: device node204204+ *205205+ * This function adds an opp definition to the opp table and returns status. The206206+ * opp can be controlled using dev_pm_opp_enable/disable functions and may be207207+ * removed by dev_pm_opp_remove.208208+ *209209+ * Locking: The internal opp_table and opp structures are RCU protected.210210+ * Hence this function internally uses RCU updater strategy with mutex locks211211+ * to keep the integrity of the internal data structures. Callers should ensure212212+ * that this function is *NOT* called under RCU protection or in contexts where213213+ * mutex cannot be locked.214214+ *215215+ * Return:216216+ * 0 On success OR217217+ * Duplicate OPPs (both freq and volt are same) and opp->available218218+ * -EEXIST Freq are same and volt are different OR219219+ * Duplicate OPPs (both freq and volt are same) and !opp->available220220+ * -ENOMEM Memory allocation failure221221+ * -EINVAL Failed parsing the OPP node222222+ */223223+static int _opp_add_static_v2(struct device *dev, struct device_node *np)224224+{225225+ struct opp_table *opp_table;226226+ struct dev_pm_opp *new_opp;227227+ u64 rate;228228+ u32 val;229229+ int ret;230230+231231+ /* Hold our table modification lock here */232232+ mutex_lock(&opp_table_lock);233233+234234+ new_opp = _allocate_opp(dev, &opp_table);235235+ if (!new_opp) {236236+ ret = -ENOMEM;237237+ goto unlock;238238+ }239239+240240+ ret = of_property_read_u64(np, "opp-hz", &rate);241241+ if (ret < 0) {242242+ dev_err(dev, "%s: opp-hz not found\n", __func__);243243+ goto free_opp;244244+ }245245+246246+ /* Check if the OPP supports hardware's hierarchy of versions or not */247247+ if (!_opp_is_supported(dev, opp_table, np)) {248248+ dev_dbg(dev, "OPP not supported by hardware: %llu\n", rate);249249+ goto free_opp;250250+ }251251+252252+ /*253253+ * Rate is defined as an unsigned long in clk API, and so casting254254+ * explicitly to its type. Must be fixed once rate is 64 bit255255+ * guaranteed in clk API.256256+ */257257+ new_opp->rate = (unsigned long)rate;258258+ new_opp->turbo = of_property_read_bool(np, "turbo-mode");259259+260260+ new_opp->np = np;261261+ new_opp->dynamic = false;262262+ new_opp->available = true;263263+264264+ if (!of_property_read_u32(np, "clock-latency-ns", &val))265265+ new_opp->clock_latency_ns = val;266266+267267+ ret = opp_parse_supplies(new_opp, dev, opp_table);268268+ if (ret)269269+ goto free_opp;270270+271271+ ret = _opp_add(dev, new_opp, opp_table);272272+ if (ret)273273+ goto free_opp;274274+275275+ /* OPP to select on device suspend */276276+ if (of_property_read_bool(np, "opp-suspend")) {277277+ if (opp_table->suspend_opp) {278278+ dev_warn(dev, "%s: Multiple suspend OPPs found (%lu %lu)\n",279279+ __func__, opp_table->suspend_opp->rate,280280+ new_opp->rate);281281+ } else {282282+ new_opp->suspend = true;283283+ opp_table->suspend_opp = new_opp;284284+ }285285+ }286286+287287+ if (new_opp->clock_latency_ns > opp_table->clock_latency_ns_max)288288+ opp_table->clock_latency_ns_max = new_opp->clock_latency_ns;289289+290290+ mutex_unlock(&opp_table_lock);291291+292292+ pr_debug("%s: turbo:%d rate:%lu uv:%lu uvmin:%lu uvmax:%lu latency:%lu\n",293293+ __func__, new_opp->turbo, new_opp->rate, new_opp->u_volt,294294+ new_opp->u_volt_min, new_opp->u_volt_max,295295+ new_opp->clock_latency_ns);296296+297297+ /*298298+ * Notify the changes in the availability of the operable299299+ * frequency/voltage list.300300+ */301301+ srcu_notifier_call_chain(&opp_table->srcu_head, OPP_EVENT_ADD, new_opp);302302+ return 0;303303+304304+free_opp:305305+ _opp_remove(opp_table, new_opp, false);306306+unlock:307307+ mutex_unlock(&opp_table_lock);308308+ return ret;309309+}310310+311311+/* Initializes OPP tables based on new bindings */312312+static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np)313313+{314314+ struct device_node *np;315315+ struct opp_table *opp_table;316316+ int ret = 0, count = 0;317317+318318+ mutex_lock(&opp_table_lock);319319+320320+ opp_table = _managed_opp(opp_np);321321+ if (opp_table) {322322+ /* OPPs are already managed */323323+ if (!_add_opp_dev(dev, opp_table))324324+ ret = -ENOMEM;325325+ mutex_unlock(&opp_table_lock);326326+ return ret;327327+ }328328+ mutex_unlock(&opp_table_lock);329329+330330+ /* We have opp-table node now, iterate over it and add OPPs */331331+ for_each_available_child_of_node(opp_np, np) {332332+ count++;333333+334334+ ret = _opp_add_static_v2(dev, np);335335+ if (ret) {336336+ dev_err(dev, "%s: Failed to add OPP, %d\n", __func__,337337+ ret);338338+ goto free_table;339339+ }340340+ }341341+342342+ /* There should be one of more OPP defined */343343+ if (WARN_ON(!count))344344+ return -ENOENT;345345+346346+ mutex_lock(&opp_table_lock);347347+348348+ opp_table = _find_opp_table(dev);349349+ if (WARN_ON(IS_ERR(opp_table))) {350350+ ret = PTR_ERR(opp_table);351351+ mutex_unlock(&opp_table_lock);352352+ goto free_table;353353+ }354354+355355+ opp_table->np = opp_np;356356+ opp_table->shared_opp = of_property_read_bool(opp_np, "opp-shared");357357+358358+ mutex_unlock(&opp_table_lock);359359+360360+ return 0;361361+362362+free_table:363363+ dev_pm_opp_of_remove_table(dev);364364+365365+ return ret;366366+}367367+368368+/* Initializes OPP tables based on old-deprecated bindings */369369+static int _of_add_opp_table_v1(struct device *dev)370370+{371371+ const struct property *prop;372372+ const __be32 *val;373373+ int nr;374374+375375+ prop = of_find_property(dev->of_node, "operating-points", NULL);376376+ if (!prop)377377+ return -ENODEV;378378+ if (!prop->value)379379+ return -ENODATA;380380+381381+ /*382382+ * Each OPP is a set of tuples consisting of frequency and383383+ * voltage like <freq-kHz vol-uV>.384384+ */385385+ nr = prop->length / sizeof(u32);386386+ if (nr % 2) {387387+ dev_err(dev, "%s: Invalid OPP table\n", __func__);388388+ return -EINVAL;389389+ }390390+391391+ val = prop->value;392392+ while (nr) {393393+ unsigned long freq = be32_to_cpup(val++) * 1000;394394+ unsigned long volt = be32_to_cpup(val++);395395+396396+ if (_opp_add_v1(dev, freq, volt, false))397397+ dev_warn(dev, "%s: Failed to add OPP %ld\n",398398+ __func__, freq);399399+ nr -= 2;400400+ }401401+402402+ return 0;403403+}404404+405405+/**406406+ * dev_pm_opp_of_add_table() - Initialize opp table from device tree407407+ * @dev: device pointer used to lookup OPP table.408408+ *409409+ * Register the initial OPP table with the OPP library for given device.410410+ *411411+ * Locking: The internal opp_table and opp structures are RCU protected.412412+ * Hence this function indirectly uses RCU updater strategy with mutex locks413413+ * to keep the integrity of the internal data structures. Callers should ensure414414+ * that this function is *NOT* called under RCU protection or in contexts where415415+ * mutex cannot be locked.416416+ *417417+ * Return:418418+ * 0 On success OR419419+ * Duplicate OPPs (both freq and volt are same) and opp->available420420+ * -EEXIST Freq are same and volt are different OR421421+ * Duplicate OPPs (both freq and volt are same) and !opp->available422422+ * -ENOMEM Memory allocation failure423423+ * -ENODEV when 'operating-points' property is not found or is invalid data424424+ * in device node.425425+ * -ENODATA when empty 'operating-points' property is found426426+ * -EINVAL when invalid entries are found in opp-v2 table427427+ */428428+int dev_pm_opp_of_add_table(struct device *dev)429429+{430430+ struct device_node *opp_np;431431+ int ret;432432+433433+ /*434434+ * OPPs have two version of bindings now. The older one is deprecated,435435+ * try for the new binding first.436436+ */437437+ opp_np = _of_get_opp_desc_node(dev);438438+ if (!opp_np) {439439+ /*440440+ * Try old-deprecated bindings for backward compatibility with441441+ * older dtbs.442442+ */443443+ return _of_add_opp_table_v1(dev);444444+ }445445+446446+ ret = _of_add_opp_table_v2(dev, opp_np);447447+ of_node_put(opp_np);448448+449449+ return ret;450450+}451451+EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table);452452+453453+/* CPU device specific helpers */454454+455455+/**456456+ * dev_pm_opp_of_cpumask_remove_table() - Removes OPP table for @cpumask457457+ * @cpumask: cpumask for which OPP table needs to be removed458458+ *459459+ * This removes the OPP tables for CPUs present in the @cpumask.460460+ * This should be used only to remove static entries created from DT.461461+ *462462+ * Locking: The internal opp_table and opp structures are RCU protected.463463+ * Hence this function internally uses RCU updater strategy with mutex locks464464+ * to keep the integrity of the internal data structures. Callers should ensure465465+ * that this function is *NOT* called under RCU protection or in contexts where466466+ * mutex cannot be locked.467467+ */468468+void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)469469+{470470+ _dev_pm_opp_cpumask_remove_table(cpumask, true);471471+}472472+EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table);473473+474474+/**475475+ * dev_pm_opp_of_cpumask_add_table() - Adds OPP table for @cpumask476476+ * @cpumask: cpumask for which OPP table needs to be added.477477+ *478478+ * This adds the OPP tables for CPUs present in the @cpumask.479479+ *480480+ * Locking: The internal opp_table and opp structures are RCU protected.481481+ * Hence this function internally uses RCU updater strategy with mutex locks482482+ * to keep the integrity of the internal data structures. Callers should ensure483483+ * that this function is *NOT* called under RCU protection or in contexts where484484+ * mutex cannot be locked.485485+ */486486+int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)487487+{488488+ struct device *cpu_dev;489489+ int cpu, ret = 0;490490+491491+ WARN_ON(cpumask_empty(cpumask));492492+493493+ for_each_cpu(cpu, cpumask) {494494+ cpu_dev = get_cpu_device(cpu);495495+ if (!cpu_dev) {496496+ pr_err("%s: failed to get cpu%d device\n", __func__,497497+ cpu);498498+ continue;499499+ }500500+501501+ ret = dev_pm_opp_of_add_table(cpu_dev);502502+ if (ret) {503503+ pr_err("%s: couldn't find opp table for cpu:%d, %d\n",504504+ __func__, cpu, ret);505505+506506+ /* Free all other OPPs */507507+ dev_pm_opp_of_cpumask_remove_table(cpumask);508508+ break;509509+ }510510+ }511511+512512+ return ret;513513+}514514+EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_add_table);515515+516516+/*517517+ * Works only for OPP v2 bindings.518518+ *519519+ * Returns -ENOENT if operating-points-v2 bindings aren't supported.520520+ */521521+/**522522+ * dev_pm_opp_of_get_sharing_cpus() - Get cpumask of CPUs sharing OPPs with523523+ * @cpu_dev using operating-points-v2524524+ * bindings.525525+ *526526+ * @cpu_dev: CPU device for which we do this operation527527+ * @cpumask: cpumask to update with information of sharing CPUs528528+ *529529+ * This updates the @cpumask with CPUs that are sharing OPPs with @cpu_dev.530530+ *531531+ * Returns -ENOENT if operating-points-v2 isn't present for @cpu_dev.532532+ *533533+ * Locking: The internal opp_table and opp structures are RCU protected.534534+ * Hence this function internally uses RCU updater strategy with mutex locks535535+ * to keep the integrity of the internal data structures. Callers should ensure536536+ * that this function is *NOT* called under RCU protection or in contexts where537537+ * mutex cannot be locked.538538+ */539539+int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev,540540+ struct cpumask *cpumask)541541+{542542+ struct device_node *np, *tmp_np;543543+ struct device *tcpu_dev;544544+ int cpu, ret = 0;545545+546546+ /* Get OPP descriptor node */547547+ np = _of_get_opp_desc_node(cpu_dev);548548+ if (!np) {549549+ dev_dbg(cpu_dev, "%s: Couldn't find cpu_dev node.\n", __func__);550550+ return -ENOENT;551551+ }552552+553553+ cpumask_set_cpu(cpu_dev->id, cpumask);554554+555555+ /* OPPs are shared ? */556556+ if (!of_property_read_bool(np, "opp-shared"))557557+ goto put_cpu_node;558558+559559+ for_each_possible_cpu(cpu) {560560+ if (cpu == cpu_dev->id)561561+ continue;562562+563563+ tcpu_dev = get_cpu_device(cpu);564564+ if (!tcpu_dev) {565565+ dev_err(cpu_dev, "%s: failed to get cpu%d device\n",566566+ __func__, cpu);567567+ ret = -ENODEV;568568+ goto put_cpu_node;569569+ }570570+571571+ /* Get OPP descriptor node */572572+ tmp_np = _of_get_opp_desc_node(tcpu_dev);573573+ if (!tmp_np) {574574+ dev_err(tcpu_dev, "%s: Couldn't find tcpu_dev node.\n",575575+ __func__);576576+ ret = -ENOENT;577577+ goto put_cpu_node;578578+ }579579+580580+ /* CPUs are sharing opp node */581581+ if (np == tmp_np)582582+ cpumask_set_cpu(cpu, cpumask);583583+584584+ of_node_put(tmp_np);585585+ }586586+587587+put_cpu_node:588588+ of_node_put(np);589589+ return ret;590590+}591591+EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus);
+14
drivers/base/power/opp/opp.h
···2828/* Lock to allow exclusive modification to the device and opp lists */2929extern struct mutex opp_table_lock;30303131+extern struct list_head opp_tables;3232+3133/*3234 * Internal data structure organization with the OPP layer library is as3335 * follows:···185183struct opp_table *_find_opp_table(struct device *dev);186184struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table);187185struct device_node *_of_get_opp_desc_node(struct device *dev);186186+void _dev_pm_opp_remove_table(struct device *dev, bool remove_all);187187+struct dev_pm_opp *_allocate_opp(struct device *dev, struct opp_table **opp_table);188188+int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table);189189+void _opp_remove(struct opp_table *opp_table, struct dev_pm_opp *opp, bool notify);190190+int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt, bool dynamic);191191+void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of);192192+193193+#ifdef CONFIG_OF194194+void _of_init_opp_table(struct opp_table *opp_table, struct device *dev);195195+#else196196+static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev) {}197197+#endif188198189199#ifdef CONFIG_DEBUG_FS190200void opp_debug_remove_one(struct dev_pm_opp *opp);