VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
d2912cb15bdda drivers/opp/core.c            (Thomas Gleixner           2019-06-04 10:11:33 +0200    1) // SPDX-License-Identifier: GPL-2.0-only
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200    2) /*
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200    3)  * Generic OPP Interface
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200    4)  *
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200    5)  * Copyright (C) 2009-2010 Texas Instruments Incorporated.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200    6)  *	Nishanth Menon
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200    7)  *	Romit Dasgupta
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200    8)  *	Kevin Hilman
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200    9)  */
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   10) 
d6d2a5289a530 drivers/base/power/opp/core.c (Viresh Kumar              2015-10-17 09:45:18 +0530   11) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
d6d2a5289a530 drivers/base/power/opp/core.c (Viresh Kumar              2015-10-17 09:45:18 +0530   12) 
d54974c2513f4 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:38 +0530   13) #include <linux/clk.h>
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   14) #include <linux/errno.h>
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   15) #include <linux/err.h>
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   16) #include <linux/slab.h>
51990e8254310 drivers/base/power/opp.c      (Paul Gortmaker            2012-01-22 11:23:42 -0500   17) #include <linux/device.h>
80126ce7aeb4e drivers/base/power/opp.c      (Liam Girdwood             2012-10-23 01:27:44 +0200   18) #include <linux/export.h>
009acd196fc86 drivers/opp/core.c            (Viresh Kumar              2017-10-11 12:54:14 +0530   19) #include <linux/pm_domain.h>
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530   20) #include <linux/regulator/consumer.h>
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   21) 
f59d3ee8480d3 drivers/base/power/opp/core.c (Viresh Kumar              2015-09-04 13:47:26 +0530   22) #include "opp.h"
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   23) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   24) /*
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530   25)  * The root of the list of all opp-tables. All opp_table structures branch off
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530   26)  * from here, with each opp_table containing the list of opps it supports in
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   27)  * various states of availability.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   28)  */
f47b72a15a967 drivers/base/power/opp/core.c (Viresh Kumar              2016-05-05 16:20:33 +0530   29) LIST_HEAD(opp_tables);
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530   30) 
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530   31) /* OPP tables with uninitialized required OPPs */
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530   32) LIST_HEAD(lazy_opp_tables);
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530   33) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   34) /* Lock to allow exclusive modification to the device and opp lists */
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530   35) DEFINE_MUTEX(opp_table_lock);
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530   36) /* Flag indicating that opp_tables list is being updated at the moment */
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530   37) static bool opp_tables_busy;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   38) 
9e62edac519da drivers/opp/core.c            (Viresh Kumar              2020-10-27 11:49:03 +0530   39) static bool _find_opp_dev(const struct device *dev, struct opp_table *opp_table)
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530   40) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530   41) 	struct opp_device *opp_dev;
9e62edac519da drivers/opp/core.c            (Viresh Kumar              2020-10-27 11:49:03 +0530   42) 	bool found = false;
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530   43) 
9e62edac519da drivers/opp/core.c            (Viresh Kumar              2020-10-27 11:49:03 +0530   44) 	mutex_lock(&opp_table->lock);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530   45) 	list_for_each_entry(opp_dev, &opp_table->dev_list, node)
9e62edac519da drivers/opp/core.c            (Viresh Kumar              2020-10-27 11:49:03 +0530   46) 		if (opp_dev->dev == dev) {
9e62edac519da drivers/opp/core.c            (Viresh Kumar              2020-10-27 11:49:03 +0530   47) 			found = true;
9e62edac519da drivers/opp/core.c            (Viresh Kumar              2020-10-27 11:49:03 +0530   48) 			break;
9e62edac519da drivers/opp/core.c            (Viresh Kumar              2020-10-27 11:49:03 +0530   49) 		}
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530   50) 
9e62edac519da drivers/opp/core.c            (Viresh Kumar              2020-10-27 11:49:03 +0530   51) 	mutex_unlock(&opp_table->lock);
9e62edac519da drivers/opp/core.c            (Viresh Kumar              2020-10-27 11:49:03 +0530   52) 	return found;
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530   53) }
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530   54) 
6ac423973397d drivers/base/power/opp/core.c (Wei Yongjun               2017-02-06 14:29:55 +0000   55) static struct opp_table *_find_opp_table_unlocked(struct device *dev)
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   56) {
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   57) 	struct opp_table *opp_table;
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   58) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   59) 	list_for_each_entry(opp_table, &opp_tables, node) {
9e62edac519da drivers/opp/core.c            (Viresh Kumar              2020-10-27 11:49:03 +0530   60) 		if (_find_opp_dev(dev, opp_table)) {
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   61) 			_get_opp_table_kref(opp_table);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   62) 			return opp_table;
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   63) 		}
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   64) 	}
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   65) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   66) 	return ERR_PTR(-ENODEV);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   67) }
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   68) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   69) /**
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530   70)  * _find_opp_table() - find opp_table struct using device pointer
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530   71)  * @dev:	device pointer used to lookup OPP table
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   72)  *
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530   73)  * Search OPP table for one containing matching device.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   74)  *
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530   75)  * Return: pointer to 'struct opp_table' if found, otherwise -ENODEV or
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   76)  * -EINVAL based on type of error.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   77)  *
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   78)  * The callers must call dev_pm_opp_put_opp_table() after the table is used.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   79)  */
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530   80) struct opp_table *_find_opp_table(struct device *dev)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   81) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530   82) 	struct opp_table *opp_table;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   83) 
50a3cb04a5f9c drivers/base/power/opp.c      (Viresh Kumar              2015-08-12 15:59:39 +0530   84) 	if (IS_ERR_OR_NULL(dev)) {
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   85) 		pr_err("%s: Invalid parameters\n", __func__);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   86) 		return ERR_PTR(-EINVAL);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   87) 	}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   88) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   89) 	mutex_lock(&opp_table_lock);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   90) 	opp_table = _find_opp_table_unlocked(dev);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   91) 	mutex_unlock(&opp_table_lock);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   92) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530   93) 	return opp_table;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   94) }
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   95) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   96) /**
d6d007429f216 drivers/base/power/opp.c      (Javi Merino               2015-09-10 18:09:29 +0100   97)  * dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   98)  * @opp:	opp for which voltage has to be returned for
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200   99)  *
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600  100)  * Return: voltage in micro volt corresponding to the opp, else
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  101)  * return 0
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  102)  *
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  103)  * This is useful only for devices with single power supply.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  104)  */
47d43ba73eb98 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:51 -0500  105) unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  106) {
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  107) 	if (IS_ERR_OR_NULL(opp)) {
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  108) 		pr_err("%s: Invalid parameters\n", __func__);
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  109) 		return 0;
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  110) 	}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  111) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  112) 	return opp->supplies[0].u_volt;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  113) }
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500  114) EXPORT_SYMBOL_GPL(dev_pm_opp_get_voltage);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  115) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  116) /**
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500  117)  * dev_pm_opp_get_freq() - Gets the frequency corresponding to an available opp
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  118)  * @opp:	opp for which frequency has to be returned for
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  119)  *
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600  120)  * Return: frequency in hertz corresponding to the opp, else
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  121)  * return 0
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  122)  */
47d43ba73eb98 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:51 -0500  123) unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  124) {
06a8a059e88bd drivers/opp/core.c            (Andrew-sh.Cheng           2020-07-20 16:55:26 +0800  125) 	if (IS_ERR_OR_NULL(opp)) {
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  126) 		pr_err("%s: Invalid parameters\n", __func__);
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  127) 		return 0;
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  128) 	}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  129) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  130) 	return opp->rate;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  131) }
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500  132) EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  133) 
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  134) /**
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  135)  * dev_pm_opp_get_level() - Gets the level corresponding to an available opp
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  136)  * @opp:	opp for which level value has to be returned for
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  137)  *
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  138)  * Return: level read from device tree corresponding to the opp, else
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  139)  * return 0.
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  140)  */
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  141) unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  142) {
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  143) 	if (IS_ERR_OR_NULL(opp) || !opp->available) {
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  144) 		pr_err("%s: Invalid parameters\n", __func__);
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  145) 		return 0;
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  146) 	}
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  147) 
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  148) 	return opp->level;
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  149) }
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  150) EXPORT_SYMBOL_GPL(dev_pm_opp_get_level);
5b93ac5423010 drivers/opp/core.c            (Rajendra Nayak            2019-01-10 09:32:02 +0530  151) 
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  152) /**
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  153)  * dev_pm_opp_get_required_pstate() - Gets the required performance state
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  154)  *                                    corresponding to an available opp
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  155)  * @opp:	opp for which performance state has to be returned for
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  156)  * @index:	index of the required opp
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  157)  *
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  158)  * Return: performance state read from device tree corresponding to the
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  159)  * required opp, else return 0.
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  160)  */
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  161) unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  162) 					    unsigned int index)
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  163) {
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  164) 	if (IS_ERR_OR_NULL(opp) || !opp->available ||
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  165) 	    index >= opp->opp_table->required_opp_count) {
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  166) 		pr_err("%s: Invalid parameters\n", __func__);
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  167) 		return 0;
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  168) 	}
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  169) 
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530  170) 	/* required-opps not fully initialized yet */
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530  171) 	if (lazy_linking_pending(opp->opp_table))
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530  172) 		return 0;
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530  173) 
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  174) 	return opp->required_opps[index]->pstate;
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  175) }
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  176) EXPORT_SYMBOL_GPL(dev_pm_opp_get_required_pstate);
597ff5431fd41 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:19 +0300  177) 
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  178) /**
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  179)  * dev_pm_opp_is_turbo() - Returns if opp is turbo OPP or not
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  180)  * @opp: opp for which turbo mode is being verified
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  181)  *
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  182)  * Turbo OPPs are not for normal use, and can be enabled (under certain
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  183)  * conditions) for short duration of times to finish high throughput work
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  184)  * quickly. Running on them for longer times may overheat the chip.
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  185)  *
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  186)  * Return: true if opp is turbo opp, else false.
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  187)  */
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  188) bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  189) {
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  190) 	if (IS_ERR_OR_NULL(opp) || !opp->available) {
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  191) 		pr_err("%s: Invalid parameters\n", __func__);
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  192) 		return false;
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  193) 	}
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  194) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  195) 	return opp->turbo;
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  196) }
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  197) EXPORT_SYMBOL_GPL(dev_pm_opp_is_turbo);
19445b25e350e drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-07-09 17:43:35 +0200  198) 
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  199) /**
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  200)  * dev_pm_opp_get_max_clock_latency() - Get max clock latency in nanoseconds
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  201)  * @dev:	device for which we do this operation
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  202)  *
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  203)  * Return: This function returns the max clock latency in nanoseconds.
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  204)  */
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  205) unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  206) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  207) 	struct opp_table *opp_table;
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  208) 	unsigned long clock_latency_ns;
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  209) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  210) 	opp_table = _find_opp_table(dev);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  211) 	if (IS_ERR(opp_table))
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  212) 		return 0;
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  213) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  214) 	clock_latency_ns = opp_table->clock_latency_ns_max;
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  215) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  216) 	dev_pm_opp_put_opp_table(opp_table);
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  217) 
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  218) 	return clock_latency_ns;
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  219) }
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  220) EXPORT_SYMBOL_GPL(dev_pm_opp_get_max_clock_latency);
3ca9bb33c627f drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:03 +0530  221) 
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  222) /**
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  223)  * dev_pm_opp_get_max_volt_latency() - Get max voltage latency in nanoseconds
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  224)  * @dev: device for which we do this operation
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  225)  *
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  226)  * Return: This function returns the max voltage latency in nanoseconds.
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  227)  */
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  228) unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  229) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  230) 	struct opp_table *opp_table;
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  231) 	struct dev_pm_opp *opp;
478256bddb032 drivers/base/power/opp/core.c (Viresh Kumar              2017-05-23 09:32:11 +0530  232) 	struct regulator *reg;
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  233) 	unsigned long latency_ns = 0;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  234) 	int ret, i, count;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  235) 	struct {
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  236) 		unsigned long min;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  237) 		unsigned long max;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  238) 	} *uV;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  239) 
cdd3e614cfda7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:51 +0530  240) 	opp_table = _find_opp_table(dev);
cdd3e614cfda7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:51 +0530  241) 	if (IS_ERR(opp_table))
cdd3e614cfda7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:51 +0530  242) 		return 0;
cdd3e614cfda7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:51 +0530  243) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  244) 	/* Regulator may not be required for the device */
90e3577b5feb4 drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:32:47 +0530  245) 	if (!opp_table->regulators)
cdd3e614cfda7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:51 +0530  246) 		goto put_opp_table;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  247) 
90e3577b5feb4 drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:32:47 +0530  248) 	count = opp_table->regulator_count;
90e3577b5feb4 drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:32:47 +0530  249) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  250) 	uV = kmalloc_array(count, sizeof(*uV), GFP_KERNEL);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  251) 	if (!uV)
478256bddb032 drivers/base/power/opp/core.c (Viresh Kumar              2017-05-23 09:32:11 +0530  252) 		goto put_opp_table;
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  253) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  254) 	mutex_lock(&opp_table->lock);
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  255) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  256) 	for (i = 0; i < count; i++) {
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  257) 		uV[i].min = ~0;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  258) 		uV[i].max = 0;
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  259) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  260) 		list_for_each_entry(opp, &opp_table->opp_list, node) {
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  261) 			if (!opp->available)
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  262) 				continue;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  263) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  264) 			if (opp->supplies[i].u_volt_min < uV[i].min)
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  265) 				uV[i].min = opp->supplies[i].u_volt_min;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  266) 			if (opp->supplies[i].u_volt_max > uV[i].max)
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  267) 				uV[i].max = opp->supplies[i].u_volt_max;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  268) 		}
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  269) 	}
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  270) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  271) 	mutex_unlock(&opp_table->lock);
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  272) 
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  273) 	/*
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  274) 	 * The caller needs to ensure that opp_table (and hence the regulator)
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  275) 	 * isn't freed, while we are executing this routine.
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  276) 	 */
8cc311167c22f drivers/base/power/opp/core.c (Andrzej Hajda             2017-02-20 19:57:57 +0100  277) 	for (i = 0; i < count; i++) {
478256bddb032 drivers/base/power/opp/core.c (Viresh Kumar              2017-05-23 09:32:11 +0530  278) 		reg = opp_table->regulators[i];
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  279) 		ret = regulator_set_voltage_time(reg, uV[i].min, uV[i].max);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  280) 		if (ret > 0)
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  281) 			latency_ns += ret * 1000;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  282) 	}
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  283) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530  284) 	kfree(uV);
cdd3e614cfda7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:51 +0530  285) put_opp_table:
cdd3e614cfda7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:51 +0530  286) 	dev_pm_opp_put_opp_table(opp_table);
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  287) 
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  288) 	return latency_ns;
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  289) }
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  290) EXPORT_SYMBOL_GPL(dev_pm_opp_get_max_volt_latency);
655c9df961751 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:35 +0530  291) 
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  292) /**
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  293)  * dev_pm_opp_get_max_transition_latency() - Get max transition latency in
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  294)  *					     nanoseconds
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  295)  * @dev: device for which we do this operation
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  296)  *
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  297)  * Return: This function returns the max transition latency, in nanoseconds, to
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  298)  * switch from one OPP to other.
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  299)  */
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  300) unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  301) {
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  302) 	return dev_pm_opp_get_max_volt_latency(dev) +
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  303) 		dev_pm_opp_get_max_clock_latency(dev);
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  304) }
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  305) EXPORT_SYMBOL_GPL(dev_pm_opp_get_max_transition_latency);
2174344765f47 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:36 +0530  306) 
4eafbd15b6c84 drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-09-08 18:41:01 +0200  307) /**
3aa26a3b2ea63 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:02 +0530  308)  * dev_pm_opp_get_suspend_opp_freq() - Get frequency of suspend opp in Hz
4eafbd15b6c84 drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-09-08 18:41:01 +0200  309)  * @dev:	device for which we do this operation
4eafbd15b6c84 drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-09-08 18:41:01 +0200  310)  *
3aa26a3b2ea63 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:02 +0530  311)  * Return: This function returns the frequency of the OPP marked as suspend_opp
3aa26a3b2ea63 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:02 +0530  312)  * if one is available, else returns 0;
4eafbd15b6c84 drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-09-08 18:41:01 +0200  313)  */
3aa26a3b2ea63 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:02 +0530  314) unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
4eafbd15b6c84 drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-09-08 18:41:01 +0200  315) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  316) 	struct opp_table *opp_table;
3aa26a3b2ea63 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:02 +0530  317) 	unsigned long freq = 0;
4eafbd15b6c84 drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-09-08 18:41:01 +0200  318) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  319) 	opp_table = _find_opp_table(dev);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  320) 	if (IS_ERR(opp_table))
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  321) 		return 0;
3aa26a3b2ea63 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:02 +0530  322) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  323) 	if (opp_table->suspend_opp && opp_table->suspend_opp->available)
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  324) 		freq = dev_pm_opp_get_freq(opp_table->suspend_opp);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  325) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  326) 	dev_pm_opp_put_opp_table(opp_table);
4eafbd15b6c84 drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-09-08 18:41:01 +0200  327) 
3aa26a3b2ea63 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:02 +0530  328) 	return freq;
4eafbd15b6c84 drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-09-08 18:41:01 +0200  329) }
3aa26a3b2ea63 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:02 +0530  330) EXPORT_SYMBOL_GPL(dev_pm_opp_get_suspend_opp_freq);
4eafbd15b6c84 drivers/base/power/opp.c      (Bartlomiej Zolnierkiewicz 2015-09-08 18:41:01 +0200  331) 
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  332) int _get_opp_count(struct opp_table *opp_table)
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  333) {
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  334) 	struct dev_pm_opp *opp;
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  335) 	int count = 0;
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  336) 
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  337) 	mutex_lock(&opp_table->lock);
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  338) 
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  339) 	list_for_each_entry(opp, &opp_table->opp_list, node) {
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  340) 		if (opp->available)
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  341) 			count++;
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  342) 	}
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  343) 
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  344) 	mutex_unlock(&opp_table->lock);
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  345) 
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  346) 	return count;
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  347) }
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  348) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  349) /**
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  350)  * dev_pm_opp_get_opp_count() - Get number of opps available in the opp table
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  351)  * @dev:	device for which we do this operation
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  352)  *
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600  353)  * Return: This function returns the number of available opps if there are any,
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  354)  * else returns 0 if none or the corresponding error value.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  355)  */
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500  356) int dev_pm_opp_get_opp_count(struct device *dev)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  357) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  358) 	struct opp_table *opp_table;
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  359) 	int count;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  360) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  361) 	opp_table = _find_opp_table(dev);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  362) 	if (IS_ERR(opp_table)) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  363) 		count = PTR_ERR(opp_table);
035ed07208dc5 drivers/opp/core.c            (Fabio Estevam             2017-09-29 14:39:49 -0300  364) 		dev_dbg(dev, "%s: OPP table not found (%d)\n",
b4718c02f49ab drivers/base/power/opp.c      (Dmitry Torokhov           2014-12-16 15:09:38 -0800  365) 			__func__, count);
09f662f95306f drivers/opp/core.c            (Viresh Kumar              2018-10-03 15:22:03 +0530  366) 		return count;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  367) 	}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  368) 
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530  369) 	count = _get_opp_count(opp_table);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  370) 	dev_pm_opp_put_opp_table(opp_table);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  371) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  372) 	return count;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  373) }
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500  374) EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_count);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  375) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  376) /**
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500  377)  * dev_pm_opp_find_freq_exact() - search for an exact frequency
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  378)  * @dev:		device for which we do this operation
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  379)  * @freq:		frequency to search for
7ae496187876d drivers/base/power/opp.c      (Nishanth Menon            2011-02-25 23:46:18 +0100  380)  * @available:		true/false - match for available opp
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  381)  *
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  382)  * Return: Searches for exact match in the opp table and returns pointer to the
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600  383)  * matching opp if found, else returns ERR_PTR in case of error and should
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600  384)  * be handled using IS_ERR. Error return values can be:
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  385)  * EINVAL:	for bad pointer
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  386)  * ERANGE:	no match found for search
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  387)  * ENODEV:	if device not found in list of registered devices
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  388)  *
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  389)  * Note: available is a modifier for the search. if available=true, then the
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  390)  * match is for exact matching frequency and is available in the stored OPP
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  391)  * table. if false, the match is for exact frequency which is not available.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  392)  *
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  393)  * This provides a mechanism to enable an opp which is not available currently
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  394)  * or the opposite as well.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  395)  *
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  396)  * The callers are required to call dev_pm_opp_put() for the returned OPP after
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  397)  * use.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  398)  */
47d43ba73eb98 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:51 -0500  399) struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
47d43ba73eb98 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:51 -0500  400) 					      unsigned long freq,
47d43ba73eb98 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:51 -0500  401) 					      bool available)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  402) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  403) 	struct opp_table *opp_table;
47d43ba73eb98 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:51 -0500  404) 	struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  405) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  406) 	opp_table = _find_opp_table(dev);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  407) 	if (IS_ERR(opp_table)) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  408) 		int r = PTR_ERR(opp_table);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  409) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  410) 		dev_err(dev, "%s: OPP table not found (%d)\n", __func__, r);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  411) 		return ERR_PTR(r);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  412) 	}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  413) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  414) 	mutex_lock(&opp_table->lock);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  415) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  416) 	list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  417) 		if (temp_opp->available == available &&
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  418) 				temp_opp->rate == freq) {
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  419) 			opp = temp_opp;
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  420) 
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  421) 			/* Increment the reference count of OPP */
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  422) 			dev_pm_opp_get(opp);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  423) 			break;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  424) 		}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  425) 	}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  426) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  427) 	mutex_unlock(&opp_table->lock);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  428) 	dev_pm_opp_put_opp_table(opp_table);
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  429) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  430) 	return opp;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  431) }
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500  432) EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  433) 
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  434) /**
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  435)  * dev_pm_opp_find_level_exact() - search for an exact level
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  436)  * @dev:		device for which we do this operation
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  437)  * @level:		level to search for
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  438)  *
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  439)  * Return: Searches for exact match in the opp table and returns pointer to the
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  440)  * matching opp if found, else returns ERR_PTR in case of error and should
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  441)  * be handled using IS_ERR. Error return values can be:
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  442)  * EINVAL:	for bad pointer
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  443)  * ERANGE:	no match found for search
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  444)  * ENODEV:	if device not found in list of registered devices
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  445)  *
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  446)  * The callers are required to call dev_pm_opp_put() for the returned OPP after
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  447)  * use.
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  448)  */
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  449) struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  450) 					       unsigned int level)
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  451) {
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  452) 	struct opp_table *opp_table;
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  453) 	struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  454) 
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  455) 	opp_table = _find_opp_table(dev);
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  456) 	if (IS_ERR(opp_table)) {
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  457) 		int r = PTR_ERR(opp_table);
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  458) 
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  459) 		dev_err(dev, "%s: OPP table not found (%d)\n", __func__, r);
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  460) 		return ERR_PTR(r);
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  461) 	}
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  462) 
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  463) 	mutex_lock(&opp_table->lock);
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  464) 
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  465) 	list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  466) 		if (temp_opp->level == level) {
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  467) 			opp = temp_opp;
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  468) 
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  469) 			/* Increment the reference count of OPP */
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  470) 			dev_pm_opp_get(opp);
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  471) 			break;
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  472) 		}
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  473) 	}
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  474) 
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  475) 	mutex_unlock(&opp_table->lock);
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  476) 	dev_pm_opp_put_opp_table(opp_table);
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  477) 
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  478) 	return opp;
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  479) }
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  480) EXPORT_SYMBOL_GPL(dev_pm_opp_find_level_exact);
71419d84c216c drivers/opp/core.c            (Niklas Cassel             2019-07-25 12:41:29 +0200  481) 
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  482) /**
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  483)  * dev_pm_opp_find_level_ceil() - search for an rounded up level
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  484)  * @dev:		device for which we do this operation
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  485)  * @level:		level to search for
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  486)  *
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  487)  * Return: Searches for rounded up match in the opp table and returns pointer
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  488)  * to the  matching opp if found, else returns ERR_PTR in case of error and
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  489)  * should be handled using IS_ERR. Error return values can be:
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  490)  * EINVAL:	for bad pointer
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  491)  * ERANGE:	no match found for search
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  492)  * ENODEV:	if device not found in list of registered devices
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  493)  *
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  494)  * The callers are required to call dev_pm_opp_put() for the returned OPP after
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  495)  * use.
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  496)  */
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  497) struct dev_pm_opp *dev_pm_opp_find_level_ceil(struct device *dev,
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  498) 					      unsigned int *level)
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  499) {
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  500) 	struct opp_table *opp_table;
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  501) 	struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  502) 
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  503) 	opp_table = _find_opp_table(dev);
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  504) 	if (IS_ERR(opp_table)) {
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  505) 		int r = PTR_ERR(opp_table);
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  506) 
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  507) 		dev_err(dev, "%s: OPP table not found (%d)\n", __func__, r);
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  508) 		return ERR_PTR(r);
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  509) 	}
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  510) 
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  511) 	mutex_lock(&opp_table->lock);
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  512) 
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  513) 	list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  514) 		if (temp_opp->available && temp_opp->level >= *level) {
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  515) 			opp = temp_opp;
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  516) 			*level = opp->level;
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  517) 
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  518) 			/* Increment the reference count of OPP */
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  519) 			dev_pm_opp_get(opp);
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  520) 			break;
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  521) 		}
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  522) 	}
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  523) 
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  524) 	mutex_unlock(&opp_table->lock);
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  525) 	dev_pm_opp_put_opp_table(opp_table);
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  526) 
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  527) 	return opp;
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  528) }
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  529) EXPORT_SYMBOL_GPL(dev_pm_opp_find_level_ceil);
8dd5cada393f6 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:18 +0300  530) 
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  531) static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table,
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  532) 						   unsigned long *freq)
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  533) {
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  534) 	struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  535) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  536) 	mutex_lock(&opp_table->lock);
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  537) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  538) 	list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  539) 		if (temp_opp->available && temp_opp->rate >= *freq) {
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  540) 			opp = temp_opp;
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  541) 			*freq = opp->rate;
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  542) 
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  543) 			/* Increment the reference count of OPP */
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  544) 			dev_pm_opp_get(opp);
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  545) 			break;
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  546) 		}
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  547) 	}
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  548) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  549) 	mutex_unlock(&opp_table->lock);
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  550) 
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  551) 	return opp;
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  552) }
067b7ce083df6 drivers/base/power/opp/core.c (Jisheng Zhang             2016-07-25 14:11:16 +0800  553) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  554) /**
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500  555)  * dev_pm_opp_find_freq_ceil() - Search for an rounded ceil freq
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  556)  * @dev:	device for which we do this operation
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  557)  * @freq:	Start frequency
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  558)  *
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  559)  * Search for the matching ceil *available* OPP from a starting freq
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  560)  * for a device.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  561)  *
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600  562)  * Return: matching *opp and refreshes *freq accordingly, else returns
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  563)  * ERR_PTR in case of error and should be handled using IS_ERR. Error return
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  564)  * values can be:
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  565)  * EINVAL:	for bad pointer
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  566)  * ERANGE:	no match found for search
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  567)  * ENODEV:	if device not found in list of registered devices
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  568)  *
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  569)  * The callers are required to call dev_pm_opp_put() for the returned OPP after
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  570)  * use.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  571)  */
47d43ba73eb98 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:51 -0500  572) struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
47d43ba73eb98 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:51 -0500  573) 					     unsigned long *freq)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  574) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  575) 	struct opp_table *opp_table;
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  576) 	struct dev_pm_opp *opp;
b02ded246d011 drivers/base/power/opp.c      (Dmitry Torokhov           2014-12-16 15:09:36 -0800  577) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  578) 	if (!dev || !freq) {
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  579) 		dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  580) 		return ERR_PTR(-EINVAL);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  581) 	}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  582) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  583) 	opp_table = _find_opp_table(dev);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  584) 	if (IS_ERR(opp_table))
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  585) 		return ERR_CAST(opp_table);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  586) 
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  587) 	opp = _find_freq_ceil(opp_table, freq);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  588) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  589) 	dev_pm_opp_put_opp_table(opp_table);
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  590) 
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  591) 	return opp;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  592) }
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500  593) EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  594) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  595) /**
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500  596)  * dev_pm_opp_find_freq_floor() - Search for a rounded floor freq
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  597)  * @dev:	device for which we do this operation
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  598)  * @freq:	Start frequency
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  599)  *
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  600)  * Search for the matching floor *available* OPP from a starting freq
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  601)  * for a device.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  602)  *
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600  603)  * Return: matching *opp and refreshes *freq accordingly, else returns
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  604)  * ERR_PTR in case of error and should be handled using IS_ERR. Error return
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  605)  * values can be:
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  606)  * EINVAL:	for bad pointer
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  607)  * ERANGE:	no match found for search
0779726cc2658 drivers/base/power/opp.c      (Nishanth Menon            2012-10-24 22:00:12 +0200  608)  * ENODEV:	if device not found in list of registered devices
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  609)  *
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  610)  * The callers are required to call dev_pm_opp_put() for the returned OPP after
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  611)  * use.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  612)  */
47d43ba73eb98 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:51 -0500  613) struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
47d43ba73eb98 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:51 -0500  614) 					      unsigned long *freq)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  615) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  616) 	struct opp_table *opp_table;
47d43ba73eb98 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:51 -0500  617) 	struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  618) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  619) 	if (!dev || !freq) {
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  620) 		dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  621) 		return ERR_PTR(-EINVAL);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  622) 	}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  623) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  624) 	opp_table = _find_opp_table(dev);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  625) 	if (IS_ERR(opp_table))
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530  626) 		return ERR_CAST(opp_table);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  627) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  628) 	mutex_lock(&opp_table->lock);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  629) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  630) 	list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  631) 		if (temp_opp->available) {
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  632) 			/* go to the next node, before choosing prev */
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  633) 			if (temp_opp->rate > *freq)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  634) 				break;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  635) 			else
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  636) 				opp = temp_opp;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  637) 		}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  638) 	}
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  639) 
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  640) 	/* Increment the reference count of OPP */
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  641) 	if (!IS_ERR(opp))
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  642) 		dev_pm_opp_get(opp);
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530  643) 	mutex_unlock(&opp_table->lock);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530  644) 	dev_pm_opp_put_opp_table(opp_table);
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530  645) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  646) 	if (!IS_ERR(opp))
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  647) 		*freq = opp->rate;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  648) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  649) 	return opp;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  650) }
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500  651) EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200  652) 
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  653) /**
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  654)  * dev_pm_opp_find_freq_ceil_by_volt() - Find OPP with highest frequency for
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  655)  *					 target voltage.
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  656)  * @dev:	Device for which we do this operation.
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  657)  * @u_volt:	Target voltage.
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  658)  *
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  659)  * Search for OPP with highest (ceil) frequency and has voltage <= u_volt.
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  660)  *
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  661)  * Return: matching *opp, else returns ERR_PTR in case of error which should be
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  662)  * handled using IS_ERR.
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  663)  *
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  664)  * Error return values can be:
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  665)  * EINVAL:	bad parameters
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  666)  *
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  667)  * The callers are required to call dev_pm_opp_put() for the returned OPP after
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  668)  * use.
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  669)  */
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  670) struct dev_pm_opp *dev_pm_opp_find_freq_ceil_by_volt(struct device *dev,
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  671) 						     unsigned long u_volt)
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  672) {
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  673) 	struct opp_table *opp_table;
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  674) 	struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  675) 
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  676) 	if (!dev || !u_volt) {
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  677) 		dev_err(dev, "%s: Invalid argument volt=%lu\n", __func__,
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  678) 			u_volt);
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  679) 		return ERR_PTR(-EINVAL);
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  680) 	}
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  681) 
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  682) 	opp_table = _find_opp_table(dev);
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  683) 	if (IS_ERR(opp_table))
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  684) 		return ERR_CAST(opp_table);
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  685) 
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  686) 	mutex_lock(&opp_table->lock);
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  687) 
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  688) 	list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  689) 		if (temp_opp->available) {
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  690) 			if (temp_opp->supplies[0].u_volt > u_volt)
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  691) 				break;
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  692) 			opp = temp_opp;
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  693) 		}
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  694) 	}
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  695) 
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  696) 	/* Increment the reference count of OPP */
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  697) 	if (!IS_ERR(opp))
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  698) 		dev_pm_opp_get(opp);
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  699) 
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  700) 	mutex_unlock(&opp_table->lock);
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  701) 	dev_pm_opp_put_opp_table(opp_table);
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  702) 
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  703) 	return opp;
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  704) }
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  705) EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil_by_volt);
2f36bde0fc8f1 drivers/opp/core.c            (Andrew-sh.Cheng           2019-03-29 14:46:10 +0800  706) 
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  707) static int _set_opp_voltage(struct device *dev, struct regulator *reg,
ce31781a7574a drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:18 +0530  708) 			    struct dev_pm_opp_supply *supply)
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  709) {
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  710) 	int ret;
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  711) 
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  712) 	/* Regulator not available for device */
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  713) 	if (IS_ERR(reg)) {
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  714) 		dev_dbg(dev, "%s: regulator not available: %ld\n", __func__,
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  715) 			PTR_ERR(reg));
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  716) 		return 0;
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  717) 	}
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  718) 
ce31781a7574a drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:18 +0530  719) 	dev_dbg(dev, "%s: voltages (mV): %lu %lu %lu\n", __func__,
ce31781a7574a drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:18 +0530  720) 		supply->u_volt_min, supply->u_volt, supply->u_volt_max);
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  721) 
ce31781a7574a drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:18 +0530  722) 	ret = regulator_set_voltage_triplet(reg, supply->u_volt_min,
ce31781a7574a drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:18 +0530  723) 					    supply->u_volt, supply->u_volt_max);
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  724) 	if (ret)
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  725) 		dev_err(dev, "%s: failed to set voltage (%lu %lu %lu mV): %d\n",
ce31781a7574a drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:18 +0530  726) 			__func__, supply->u_volt_min, supply->u_volt,
ce31781a7574a drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:18 +0530  727) 			supply->u_volt_max, ret);
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  728) 
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  729) 	return ret;
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  730) }
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  731) 
285881b51eb58 drivers/opp/core.c            (Viresh Kumar              2019-01-31 13:53:25 +0530  732) static inline int _generic_set_opp_clk_only(struct device *dev, struct clk *clk,
285881b51eb58 drivers/opp/core.c            (Viresh Kumar              2019-01-31 13:53:25 +0530  733) 					    unsigned long freq)
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  734) {
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  735) 	int ret;
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  736) 
35e74b2ee8ec6 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  737) 	/* We may reach here for devices which don't change frequency */
35e74b2ee8ec6 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  738) 	if (IS_ERR(clk))
35e74b2ee8ec6 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  739) 		return 0;
35e74b2ee8ec6 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  740) 
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  741) 	ret = clk_set_rate(clk, freq);
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  742) 	if (ret) {
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  743) 		dev_err(dev, "%s: failed to set clock rate: %d\n", __func__,
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  744) 			ret);
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  745) 	}
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  746) 
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  747) 	return ret;
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  748) }
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  749) 
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200  750) static int _generic_set_opp_regulator(struct opp_table *opp_table,
c74b32fadc00f drivers/base/power/opp/core.c (Viresh Kumar              2017-05-23 09:32:10 +0530  751) 				      struct device *dev,
3f62670fcca4a drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  752) 				      struct dev_pm_opp *opp,
c74b32fadc00f drivers/base/power/opp/core.c (Viresh Kumar              2017-05-23 09:32:10 +0530  753) 				      unsigned long freq,
3f62670fcca4a drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  754) 				      int scaling_down)
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  755) {
c74b32fadc00f drivers/base/power/opp/core.c (Viresh Kumar              2017-05-23 09:32:10 +0530  756) 	struct regulator *reg = opp_table->regulators[0];
3f62670fcca4a drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  757) 	struct dev_pm_opp *old_opp = opp_table->current_opp;
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  758) 	int ret;
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  759) 
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  760) 	/* This function only supports single regulator per device */
c74b32fadc00f drivers/base/power/opp/core.c (Viresh Kumar              2017-05-23 09:32:10 +0530  761) 	if (WARN_ON(opp_table->regulator_count > 1)) {
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  762) 		dev_err(dev, "multiple regulators are not supported\n");
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  763) 		return -EINVAL;
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  764) 	}
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  765) 
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  766) 	/* Scaling up? Scale voltage before frequency */
3f62670fcca4a drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  767) 	if (!scaling_down) {
3f62670fcca4a drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  768) 		ret = _set_opp_voltage(dev, reg, opp->supplies);
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  769) 		if (ret)
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  770) 			goto restore_voltage;
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  771) 	}
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  772) 
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  773) 	/* Change frequency */
285881b51eb58 drivers/opp/core.c            (Viresh Kumar              2019-01-31 13:53:25 +0530  774) 	ret = _generic_set_opp_clk_only(dev, opp_table->clk, freq);
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  775) 	if (ret)
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  776) 		goto restore_voltage;
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  777) 
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  778) 	/* Scaling down? Scale voltage after frequency */
3f62670fcca4a drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  779) 	if (scaling_down) {
3f62670fcca4a drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  780) 		ret = _set_opp_voltage(dev, reg, opp->supplies);
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  781) 		if (ret)
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  782) 			goto restore_freq;
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  783) 	}
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  784) 
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200  785) 	/*
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200  786) 	 * Enable the regulator after setting its voltages, otherwise it breaks
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200  787) 	 * some boot-enabled regulators.
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200  788) 	 */
72f80ce4ef9b7 drivers/opp/core.c            (Viresh Kumar              2020-08-13 08:38:37 +0530  789) 	if (unlikely(!opp_table->enabled)) {
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200  790) 		ret = regulator_enable(reg);
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200  791) 		if (ret < 0)
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200  792) 			dev_warn(dev, "Failed to enable regulator: %d", ret);
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200  793) 	}
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200  794) 
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  795) 	return 0;
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  796) 
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  797) restore_freq:
3f62670fcca4a drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  798) 	if (_generic_set_opp_clk_only(dev, opp_table->clk, old_opp->rate))
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  799) 		dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n",
3f62670fcca4a drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  800) 			__func__, old_opp->rate);
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  801) restore_voltage:
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  802) 	/* This shouldn't harm even if the voltages weren't updated earlier */
3f62670fcca4a drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530  803) 	_set_opp_voltage(dev, reg, old_opp->supplies);
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  804) 
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  805) 	return ret;
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  806) }
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530  807) 
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  808) static int _set_opp_bw(const struct opp_table *opp_table,
240ae50e23061 drivers/opp/core.c            (Viresh Kumar              2021-01-21 15:27:55 +0530  809) 		       struct dev_pm_opp *opp, struct device *dev)
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  810) {
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  811) 	u32 avg, peak;
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  812) 	int i, ret;
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  813) 
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  814) 	if (!opp_table->paths)
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  815) 		return 0;
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  816) 
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  817) 	for (i = 0; i < opp_table->path_count; i++) {
240ae50e23061 drivers/opp/core.c            (Viresh Kumar              2021-01-21 15:27:55 +0530  818) 		if (!opp) {
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  819) 			avg = 0;
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  820) 			peak = 0;
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  821) 		} else {
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  822) 			avg = opp->bandwidth[i].avg;
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  823) 			peak = opp->bandwidth[i].peak;
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  824) 		}
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  825) 		ret = icc_set_bw(opp_table->paths[i], avg, peak);
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  826) 		if (ret) {
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  827) 			dev_err(dev, "Failed to %s bandwidth[%d]: %d\n",
240ae50e23061 drivers/opp/core.c            (Viresh Kumar              2021-01-21 15:27:55 +0530  828) 				opp ? "set" : "remove", i, ret);
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  829) 			return ret;
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  830) 		}
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  831) 	}
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  832) 
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  833) 	return 0;
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  834) }
b00e667a6d8b2 drivers/opp/core.c            (Viresh Kumar              2020-05-27 09:33:44 +0530  835) 
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530  836) static int _set_opp_custom(const struct opp_table *opp_table,
509e4777ca41d drivers/opp/core.c            (Viresh Kumar              2021-01-21 13:06:01 +0530  837) 			   struct device *dev, struct dev_pm_opp *opp,
509e4777ca41d drivers/opp/core.c            (Viresh Kumar              2021-01-21 13:06:01 +0530  838) 			   unsigned long freq)
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530  839) {
04b447df1d098 drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:49 +0300  840) 	struct dev_pm_set_opp_data *data = opp_table->set_opp_data;
509e4777ca41d drivers/opp/core.c            (Viresh Kumar              2021-01-21 13:06:01 +0530  841) 	struct dev_pm_opp *old_opp = opp_table->current_opp;
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530  842) 	int size;
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530  843) 
04b447df1d098 drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:49 +0300  844) 	/*
04b447df1d098 drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:49 +0300  845) 	 * We support this only if dev_pm_opp_set_regulators() was called
04b447df1d098 drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:49 +0300  846) 	 * earlier.
04b447df1d098 drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:49 +0300  847) 	 */
04b447df1d098 drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:49 +0300  848) 	if (opp_table->sod_supplies) {
509e4777ca41d drivers/opp/core.c            (Viresh Kumar              2021-01-21 13:06:01 +0530  849) 		size = sizeof(*old_opp->supplies) * opp_table->regulator_count;
509e4777ca41d drivers/opp/core.c            (Viresh Kumar              2021-01-21 13:06:01 +0530  850) 		memcpy(data->old_opp.supplies, old_opp->supplies, size);
509e4777ca41d drivers/opp/core.c            (Viresh Kumar              2021-01-21 13:06:01 +0530  851) 		memcpy(data->new_opp.supplies, opp->supplies, size);
04b447df1d098 drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:49 +0300  852) 		data->regulator_count = opp_table->regulator_count;
04b447df1d098 drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:49 +0300  853) 	} else {
04b447df1d098 drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:49 +0300  854) 		data->regulator_count = 0;
04b447df1d098 drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:49 +0300  855) 	}
04b447df1d098 drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:49 +0300  856) 
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530  857) 	data->regulators = opp_table->regulators;
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530  858) 	data->clk = opp_table->clk;
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530  859) 	data->dev = dev;
509e4777ca41d drivers/opp/core.c            (Viresh Kumar              2021-01-21 13:06:01 +0530  860) 	data->old_opp.rate = old_opp->rate;
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530  861) 	data->new_opp.rate = freq;
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530  862) 
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530  863) 	return opp_table->set_opp(data);
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530  864) }
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530  865) 
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  866) static int _set_required_opp(struct device *dev, struct device *pd_dev,
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  867) 			     struct dev_pm_opp *opp, int i)
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  868) {
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  869) 	unsigned int pstate = likely(opp) ? opp->required_opps[i]->pstate : 0;
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  870) 	int ret;
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  871) 
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  872) 	if (!pd_dev)
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  873) 		return 0;
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  874) 
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  875) 	ret = dev_pm_genpd_set_performance_state(pd_dev, pstate);
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  876) 	if (ret) {
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  877) 		dev_err(dev, "Failed to set performance rate of %s: %d (%d)\n",
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  878) 			dev_name(pd_dev), pstate, ret);
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  879) 	}
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  880) 
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  881) 	return ret;
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  882) }
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  883) 
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  884) /* This is only called for PM domain for now */
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  885) static int _set_required_opps(struct device *dev,
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  886) 			      struct opp_table *opp_table,
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  887) 			      struct dev_pm_opp *opp, bool up)
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  888) {
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  889) 	struct opp_table **required_opp_tables = opp_table->required_opp_tables;
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  890) 	struct device **genpd_virt_devs = opp_table->genpd_virt_devs;
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  891) 	int i, ret = 0;
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  892) 
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  893) 	if (!required_opp_tables)
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  894) 		return 0;
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  895) 
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530  896) 	/* required-opps not fully initialized yet */
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530  897) 	if (lazy_linking_pending(opp_table))
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530  898) 		return -EBUSY;
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530  899) 
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  900) 	/* Single genpd case */
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  901) 	if (!genpd_virt_devs)
60cdeae0d627e drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:44 +0200  902) 		return _set_required_opp(dev, dev, opp, 0);
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  903) 
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  904) 	/* Multiple genpd case */
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  905) 
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  906) 	/*
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  907) 	 * Acquire genpd_virt_dev_lock to make sure we don't use a genpd_dev
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  908) 	 * after it is freed from another thread.
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  909) 	 */
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  910) 	mutex_lock(&opp_table->genpd_virt_dev_lock);
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  911) 
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  912) 	/* Scaling up? Set required OPPs in normal order, else reverse */
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  913) 	if (up) {
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  914) 		for (i = 0; i < opp_table->required_opp_count; i++) {
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  915) 			ret = _set_required_opp(dev, genpd_virt_devs[i], opp, i);
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  916) 			if (ret)
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  917) 				break;
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  918) 		}
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  919) 	} else {
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  920) 		for (i = opp_table->required_opp_count - 1; i >= 0; i--) {
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  921) 			ret = _set_required_opp(dev, genpd_virt_devs[i], opp, i);
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  922) 			if (ret)
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  923) 				break;
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  924) 		}
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  925) 	}
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  926) 
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  927) 	mutex_unlock(&opp_table->genpd_virt_dev_lock);
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  928) 
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  929) 	return ret;
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  930) }
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530  931) 
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  932) static void _find_current_opp(struct device *dev, struct opp_table *opp_table)
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  933) {
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  934) 	struct dev_pm_opp *opp = ERR_PTR(-ENODEV);
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  935) 	unsigned long freq;
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  936) 
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  937) 	if (!IS_ERR(opp_table->clk)) {
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  938) 		freq = clk_get_rate(opp_table->clk);
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  939) 		opp = _find_freq_ceil(opp_table, &freq);
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  940) 	}
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  941) 
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  942) 	/*
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  943) 	 * Unable to find the current OPP ? Pick the first from the list since
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  944) 	 * it is in ascending order, otherwise rest of the code will need to
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  945) 	 * make special checks to validate current_opp.
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  946) 	 */
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  947) 	if (IS_ERR(opp)) {
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  948) 		mutex_lock(&opp_table->lock);
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  949) 		opp = list_first_entry(&opp_table->opp_list, struct dev_pm_opp, node);
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  950) 		dev_pm_opp_get(opp);
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  951) 		mutex_unlock(&opp_table->lock);
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  952) 	}
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  953) 
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  954) 	opp_table->current_opp = opp;
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  955) }
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  956) 
5ad58bbacf802 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:08:45 +0530  957) static int _disable_opp_table(struct device *dev, struct opp_table *opp_table)
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  958) {
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  959) 	int ret;
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  960) 
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  961) 	if (!opp_table->enabled)
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  962) 		return 0;
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  963) 
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  964) 	/*
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  965) 	 * Some drivers need to support cases where some platforms may
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  966) 	 * have OPP table for the device, while others don't and
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  967) 	 * opp_set_rate() just needs to behave like clk_set_rate().
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  968) 	 */
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  969) 	if (!_get_opp_count(opp_table))
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  970) 		return 0;
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  971) 
240ae50e23061 drivers/opp/core.c            (Viresh Kumar              2021-01-21 15:27:55 +0530  972) 	ret = _set_opp_bw(opp_table, NULL, dev);
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  973) 	if (ret)
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  974) 		return ret;
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  975) 
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  976) 	if (opp_table->regulators)
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  977) 		regulator_disable(opp_table->regulators[0]);
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  978) 
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200  979) 	ret = _set_required_opps(dev, opp_table, NULL, false);
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  980) 
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  981) 	opp_table->enabled = false;
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  982) 	return ret;
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  983) }
f3364e17d5716 drivers/opp/core.c            (Viresh Kumar              2020-08-13 09:48:04 +0530  984) 
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530  985) static int _set_opp(struct device *dev, struct opp_table *opp_table,
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530  986) 		    struct dev_pm_opp *opp, unsigned long freq)
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  987) {
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530  988) 	struct dev_pm_opp *old_opp;
f0b88fa455952 drivers/opp/core.c            (Viresh Kumar              2021-01-21 16:00:12 +0530  989) 	int scaling_down, ret;
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  990) 
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530  991) 	if (unlikely(!opp))
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530  992) 		return _disable_opp_table(dev, opp_table);
aca48b61f9638 drivers/opp/core.c            (Rajendra Nayak            2020-04-08 19:16:27 +0530  993) 
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  994) 	/* Find the currently set OPP if we don't know already */
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  995) 	if (unlikely(!opp_table->current_opp))
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  996) 		_find_current_opp(dev, opp_table);
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530  997) 
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  998) 	old_opp = opp_table->current_opp;
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530  999) 
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530 1000) 	/* Return early if nothing to do */
de04241ab87af drivers/opp/core.c            (Jonathan Marek            2021-02-16 15:10:29 -0500 1001) 	if (old_opp == opp && opp_table->current_rate == freq &&
de04241ab87af drivers/opp/core.c            (Jonathan Marek            2021-02-16 15:10:29 -0500 1002) 	    opp_table->enabled) {
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530 1003) 		dev_dbg(dev, "%s: OPPs are same, nothing to do\n", __func__);
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1004) 		return 0;
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530 1005) 	}
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530 1006) 
f0b88fa455952 drivers/opp/core.c            (Viresh Kumar              2021-01-21 16:00:12 +0530 1007) 	dev_dbg(dev, "%s: switching OPP: Freq %lu -> %lu Hz, Level %u -> %u, Bw %u -> %u\n",
de04241ab87af drivers/opp/core.c            (Jonathan Marek            2021-02-16 15:10:29 -0500 1008) 		__func__, opp_table->current_rate, freq, old_opp->level,
de04241ab87af drivers/opp/core.c            (Jonathan Marek            2021-02-16 15:10:29 -0500 1009) 		opp->level, old_opp->bandwidth ? old_opp->bandwidth[0].peak : 0,
f0b88fa455952 drivers/opp/core.c            (Viresh Kumar              2021-01-21 16:00:12 +0530 1010) 		opp->bandwidth ? opp->bandwidth[0].peak : 0);
f0b88fa455952 drivers/opp/core.c            (Viresh Kumar              2021-01-21 16:00:12 +0530 1011) 
f0b88fa455952 drivers/opp/core.c            (Viresh Kumar              2021-01-21 16:00:12 +0530 1012) 	scaling_down = _opp_compare_key(old_opp, opp);
f0b88fa455952 drivers/opp/core.c            (Viresh Kumar              2021-01-21 16:00:12 +0530 1013) 	if (scaling_down == -1)
f0b88fa455952 drivers/opp/core.c            (Viresh Kumar              2021-01-21 16:00:12 +0530 1014) 		scaling_down = 0;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1015) 
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530 1016) 	/* Scaling up? Configure required OPPs before frequency */
f0b88fa455952 drivers/opp/core.c            (Viresh Kumar              2021-01-21 16:00:12 +0530 1017) 	if (!scaling_down) {
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200 1018) 		ret = _set_required_opps(dev, opp_table, opp, true);
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1019) 		if (ret) {
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1020) 			dev_err(dev, "Failed to set required opps: %d\n", ret);
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1021) 			return ret;
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1022) 		}
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1023) 
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1024) 		ret = _set_opp_bw(opp_table, opp, dev);
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1025) 		if (ret) {
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1026) 			dev_err(dev, "Failed to set bw: %d\n", ret);
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1027) 			return ret;
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1028) 		}
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530 1029) 	}
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530 1030) 
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530 1031) 	if (opp_table->set_opp) {
509e4777ca41d drivers/opp/core.c            (Viresh Kumar              2021-01-21 13:06:01 +0530 1032) 		ret = _set_opp_custom(opp_table, dev, opp, freq);
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530 1033) 	} else if (opp_table->regulators) {
3f62670fcca4a drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530 1034) 		ret = _generic_set_opp_regulator(opp_table, dev, opp, freq,
3f62670fcca4a drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:38:13 +0530 1035) 						 scaling_down);
c74b32fadc00f drivers/base/power/opp/core.c (Viresh Kumar              2017-05-23 09:32:10 +0530 1036) 	} else {
7e535993fa4f6 drivers/opp/core.c            (Viresh Kumar              2018-06-12 14:47:03 +0530 1037) 		/* Only frequency scaling */
1d3c42cabbd35 drivers/opp/core.c            (Viresh Kumar              2021-01-20 15:57:21 +0530 1038) 		ret = _generic_set_opp_clk_only(dev, opp_table->clk, freq);
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530 1039) 	}
c74b32fadc00f drivers/base/power/opp/core.c (Viresh Kumar              2017-05-23 09:32:10 +0530 1040) 
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1041) 	if (ret)
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1042) 		return ret;
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1043) 
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530 1044) 	/* Scaling down? Configure required OPPs after frequency */
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1045) 	if (scaling_down) {
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1046) 		ret = _set_opp_bw(opp_table, opp, dev);
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1047) 		if (ret) {
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1048) 			dev_err(dev, "Failed to set bw: %d\n", ret);
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1049) 			return ret;
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1050) 		}
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1051) 
2c59138c22f17 drivers/opp/core.c            (Stephan Gerhold           2020-07-30 10:01:45 +0200 1052) 		ret = _set_required_opps(dev, opp_table, opp, false);
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1053) 		if (ret) {
ca1b5d77b1c69 drivers/opp/core.c            (Viresh Kumar              2018-06-14 10:03:26 +0530 1054) 			dev_err(dev, "Failed to set required opps: %d\n", ret);
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1055) 			return ret;
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1056) 		}
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1057) 	}
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1058) 
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1059) 	opp_table->enabled = true;
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1060) 	dev_pm_opp_put(old_opp);
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530 1061) 
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1062) 	/* Make sure current_opp doesn't get freed */
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1063) 	dev_pm_opp_get(opp);
870d5d963972d drivers/opp/core.c            (Viresh Kumar              2021-01-28 15:30:00 +0530 1064) 	opp_table->current_opp = opp;
de04241ab87af drivers/opp/core.c            (Jonathan Marek            2021-02-16 15:10:29 -0500 1065) 	opp_table->current_rate = freq;
fe2af40250bfc drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:23 +0300 1066) 
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1067) 	return ret;
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1068) }
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1069) 
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1070) /**
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1071)  * dev_pm_opp_set_rate() - Configure new OPP based on frequency
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1072)  * @dev:	 device for which we do this operation
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1073)  * @target_freq: frequency to achieve
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1074)  *
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1075)  * This configures the power-supplies to the levels specified by the OPP
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1076)  * corresponding to the target_freq, and programs the clock to a value <=
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1077)  * target_freq, as rounded by clk_round_rate(). Device wanting to run at fmax
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1078)  * provided by the opp, should have already rounded to the target OPP's
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1079)  * frequency.
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1080)  */
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1081) int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1082) {
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1083) 	struct opp_table *opp_table;
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1084) 	unsigned long freq = 0, temp_freq;
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1085) 	struct dev_pm_opp *opp = NULL;
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1086) 	int ret;
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1087) 
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1088) 	opp_table = _find_opp_table(dev);
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1089) 	if (IS_ERR(opp_table)) {
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1090) 		dev_err(dev, "%s: device's opp table doesn't exist\n", __func__);
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1091) 		return PTR_ERR(opp_table);
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1092) 	}
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1093) 
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1094) 	if (target_freq) {
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1095) 		/*
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1096) 		 * For IO devices which require an OPP on some platforms/SoCs
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1097) 		 * while just needing to scale the clock on some others
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1098) 		 * we look for empty OPP tables with just a clock handle and
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1099) 		 * scale only the clk. This makes dev_pm_opp_set_rate()
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1100) 		 * equivalent to a clk_set_rate()
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1101) 		 */
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1102) 		if (!_get_opp_count(opp_table)) {
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1103) 			ret = _generic_set_opp_clk_only(dev, opp_table->clk, target_freq);
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1104) 			goto put_opp_table;
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1105) 		}
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1106) 
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1107) 		freq = clk_round_rate(opp_table->clk, target_freq);
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1108) 		if ((long)freq <= 0)
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1109) 			freq = target_freq;
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1110) 
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1111) 		/*
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1112) 		 * The clock driver may support finer resolution of the
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1113) 		 * frequencies than the OPP table, don't update the frequency we
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1114) 		 * pass to clk_set_rate() here.
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1115) 		 */
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1116) 		temp_freq = freq;
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1117) 		opp = _find_freq_ceil(opp_table, &temp_freq);
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1118) 		if (IS_ERR(opp)) {
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1119) 			ret = PTR_ERR(opp);
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1120) 			dev_err(dev, "%s: failed to find OPP for freq %lu (%d)\n",
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1121) 				__func__, freq, ret);
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1122) 			goto put_opp_table;
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1123) 		}
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1124) 	}
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1125) 
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1126) 	ret = _set_opp(dev, opp_table, opp, freq);
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1127) 
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1128) 	if (target_freq)
386ba854d9f31 drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:12:09 +0530 1129) 		dev_pm_opp_put(opp);
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 1130) put_opp_table:
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 1131) 	dev_pm_opp_put_opp_table(opp_table);
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 1132) 	return ret;
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530 1133) }
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530 1134) EXPORT_SYMBOL_GPL(dev_pm_opp_set_rate);
6a0712f6f199e drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:39 +0530 1135) 
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1136) /**
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1137)  * dev_pm_opp_set_opp() - Configure device for OPP
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1138)  * @dev: device for which we do this operation
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1139)  * @opp: OPP to set to
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1140)  *
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1141)  * This configures the device based on the properties of the OPP passed to this
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1142)  * routine.
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1143)  *
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1144)  * Return: 0 on success, a negative error number otherwise.
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1145)  */
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1146) int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp)
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1147) {
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1148) 	struct opp_table *opp_table;
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1149) 	int ret;
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1150) 
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1151) 	opp_table = _find_opp_table(dev);
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1152) 	if (IS_ERR(opp_table)) {
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1153) 		dev_err(dev, "%s: device opp doesn't exist\n", __func__);
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1154) 		return PTR_ERR(opp_table);
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1155) 	}
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1156) 
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1157) 	ret = _set_opp(dev, opp_table, opp, opp ? opp->rate : 0);
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1158) 	dev_pm_opp_put_opp_table(opp_table);
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1159) 
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1160) 	return ret;
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1161) }
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1162) EXPORT_SYMBOL_GPL(dev_pm_opp_set_opp);
abbe348340c7d drivers/opp/core.c            (Viresh Kumar              2021-01-21 12:15:36 +0530 1163) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1164) /* OPP-dev Helpers */
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1165) static void _remove_opp_dev(struct opp_device *opp_dev,
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1166) 			    struct opp_table *opp_table)
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530 1167) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1168) 	opp_debug_unregister(opp_dev, opp_table);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1169) 	list_del(&opp_dev->node);
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 1170) 	kfree(opp_dev);
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530 1171) }
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530 1172) 
ef43f01ac0697 drivers/opp/core.c            (Viresh Kumar              2020-10-22 12:12:27 +0530 1173) struct opp_device *_add_opp_dev(const struct device *dev,
ef43f01ac0697 drivers/opp/core.c            (Viresh Kumar              2020-10-22 12:12:27 +0530 1174) 				struct opp_table *opp_table)
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530 1175) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1176) 	struct opp_device *opp_dev;
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530 1177) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1178) 	opp_dev = kzalloc(sizeof(*opp_dev), GFP_KERNEL);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1179) 	if (!opp_dev)
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530 1180) 		return NULL;
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530 1181) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1182) 	/* Initialize opp-dev */
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1183) 	opp_dev->dev = dev;
3d2556992a878 drivers/opp/core.c            (Viresh Kumar              2018-08-03 07:05:21 +0530 1184) 
ef43f01ac0697 drivers/opp/core.c            (Viresh Kumar              2020-10-22 12:12:27 +0530 1185) 	mutex_lock(&opp_table->lock);
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 1186) 	list_add(&opp_dev->node, &opp_table->dev_list);
ef43f01ac0697 drivers/opp/core.c            (Viresh Kumar              2020-10-22 12:12:27 +0530 1187) 	mutex_unlock(&opp_table->lock);
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530 1188) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1189) 	/* Create debugfs entries for the opp_table */
a2dea4cb90702 drivers/opp/core.c            (Greg Kroah-Hartman        2019-01-22 16:21:17 +0100 1190) 	opp_debug_register(opp_dev, opp_table);
283d55e68d8a0 drivers/opp/core.c            (Viresh Kumar              2018-09-07 09:01:54 +0530 1191) 
283d55e68d8a0 drivers/opp/core.c            (Viresh Kumar              2018-09-07 09:01:54 +0530 1192) 	return opp_dev;
283d55e68d8a0 drivers/opp/core.c            (Viresh Kumar              2018-09-07 09:01:54 +0530 1193) }
283d55e68d8a0 drivers/opp/core.c            (Viresh Kumar              2018-09-07 09:01:54 +0530 1194) 
eb7c8743d6cf4 drivers/opp/core.c            (Viresh Kumar              2018-09-05 16:17:14 +0530 1195) static struct opp_table *_allocate_opp_table(struct device *dev, int index)
07cce74a7b259 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:34 +0530 1196) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1197) 	struct opp_table *opp_table;
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1198) 	struct opp_device *opp_dev;
d54974c2513f4 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:38 +0530 1199) 	int ret;
07cce74a7b259 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:34 +0530 1200) 
07cce74a7b259 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:34 +0530 1201) 	/*
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1202) 	 * Allocate a new OPP table. In the infrequent case where a new
07cce74a7b259 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:34 +0530 1203) 	 * device is needed to be added, we pay this penalty.
07cce74a7b259 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:34 +0530 1204) 	 */
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1205) 	opp_table = kzalloc(sizeof(*opp_table), GFP_KERNEL);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1206) 	if (!opp_table)
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1207) 		return ERR_PTR(-ENOMEM);
07cce74a7b259 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:34 +0530 1208) 
3d2556992a878 drivers/opp/core.c            (Viresh Kumar              2018-08-03 07:05:21 +0530 1209) 	mutex_init(&opp_table->lock);
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 1210) 	mutex_init(&opp_table->genpd_virt_dev_lock);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1211) 	INIT_LIST_HEAD(&opp_table->dev_list);
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1212) 	INIT_LIST_HEAD(&opp_table->lazy);
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530 1213) 
46f48aca2e5ae drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:39:36 +0530 1214) 	/* Mark regulator count uninitialized */
46f48aca2e5ae drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:39:36 +0530 1215) 	opp_table->regulator_count = -1;
46f48aca2e5ae drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:39:36 +0530 1216) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1217) 	opp_dev = _add_opp_dev(dev, opp_table);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1218) 	if (!opp_dev) {
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1219) 		ret = -ENOMEM;
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1220) 		goto err;
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530 1221) 	}
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530 1222) 
eb7c8743d6cf4 drivers/opp/core.c            (Viresh Kumar              2018-09-05 16:17:14 +0530 1223) 	_of_init_opp_table(opp_table, dev, index);
50f8cfbd5897c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:37 +0530 1224) 
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1225) 	/* Find interconnect path(s) for the device */
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1226) 	ret = dev_pm_opp_of_find_icc_paths(dev, opp_table);
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1227) 	if (ret) {
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1228) 		if (ret == -EPROBE_DEFER)
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1229) 			goto remove_opp_dev;
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1230) 
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1231) 		dev_warn(dev, "%s: Error finding interconnect paths: %d\n",
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1232) 			 __func__, ret);
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1233) 	}
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1234) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 1235) 	BLOCKING_INIT_NOTIFIER_HEAD(&opp_table->head);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1236) 	INIT_LIST_HEAD(&opp_table->opp_list);
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1237) 	kref_init(&opp_table->kref);
07cce74a7b259 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:34 +0530 1238) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1239) 	return opp_table;
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1240) 
976509bb310b9 drivers/opp/core.c            (Quanyang Wang             2020-12-24 18:49:27 +0800 1241) remove_opp_dev:
976509bb310b9 drivers/opp/core.c            (Quanyang Wang             2020-12-24 18:49:27 +0800 1242) 	_remove_opp_dev(opp_dev, opp_table);
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1243) err:
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1244) 	kfree(opp_table);
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1245) 	return ERR_PTR(ret);
07cce74a7b259 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:34 +0530 1246) }
07cce74a7b259 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:34 +0530 1247) 
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1248) void _get_opp_table_kref(struct opp_table *opp_table)
b6160e26936bc drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:04 +0530 1249) {
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1250) 	kref_get(&opp_table->kref);
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1251) }
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1252) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1253) static struct opp_table *_update_opp_table_clk(struct device *dev,
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1254) 					       struct opp_table *opp_table,
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1255) 					       bool getclk)
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1256) {
d4a4c7a41153d drivers/opp/core.c            (Viresh Kumar              2021-01-29 16:12:04 +0530 1257) 	int ret;
d4a4c7a41153d drivers/opp/core.c            (Viresh Kumar              2021-01-29 16:12:04 +0530 1258) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1259) 	/*
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1260) 	 * Return early if we don't need to get clk or we have already tried it
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1261) 	 * earlier.
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1262) 	 */
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1263) 	if (!getclk || IS_ERR(opp_table) || opp_table->clk)
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1264) 		return opp_table;
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1265) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1266) 	/* Find clk for the device */
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1267) 	opp_table->clk = clk_get(dev, NULL);
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1268) 
d4a4c7a41153d drivers/opp/core.c            (Viresh Kumar              2021-01-29 16:12:04 +0530 1269) 	ret = PTR_ERR_OR_ZERO(opp_table->clk);
d4a4c7a41153d drivers/opp/core.c            (Viresh Kumar              2021-01-29 16:12:04 +0530 1270) 	if (!ret)
d4a4c7a41153d drivers/opp/core.c            (Viresh Kumar              2021-01-29 16:12:04 +0530 1271) 		return opp_table;
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1272) 
d4a4c7a41153d drivers/opp/core.c            (Viresh Kumar              2021-01-29 16:12:04 +0530 1273) 	if (ret == -ENOENT) {
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1274) 		dev_dbg(dev, "%s: Couldn't find clock: %d\n", __func__, ret);
d4a4c7a41153d drivers/opp/core.c            (Viresh Kumar              2021-01-29 16:12:04 +0530 1275) 		return opp_table;
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1276) 	}
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1277) 
d4a4c7a41153d drivers/opp/core.c            (Viresh Kumar              2021-01-29 16:12:04 +0530 1278) 	dev_pm_opp_put_opp_table(opp_table);
d4a4c7a41153d drivers/opp/core.c            (Viresh Kumar              2021-01-29 16:12:04 +0530 1279) 	dev_err_probe(dev, ret, "Couldn't find clock\n");
d4a4c7a41153d drivers/opp/core.c            (Viresh Kumar              2021-01-29 16:12:04 +0530 1280) 
d4a4c7a41153d drivers/opp/core.c            (Viresh Kumar              2021-01-29 16:12:04 +0530 1281) 	return ERR_PTR(ret);
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1282) }
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1283) 
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1284) /*
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1285)  * We need to make sure that the OPP table for a device doesn't get added twice,
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1286)  * if this routine gets called in parallel with the same device pointer.
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1287)  *
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1288)  * The simplest way to enforce that is to perform everything (find existing
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1289)  * table and if not found, create a new one) under the opp_table_lock, so only
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1290)  * one creator gets access to the same. But that expands the critical section
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1291)  * under the lock and may end up causing circular dependencies with frameworks
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1292)  * like debugfs, interconnect or clock framework as they may be direct or
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1293)  * indirect users of OPP core.
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1294)  *
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1295)  * And for that reason we have to go for a bit tricky implementation here, which
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1296)  * uses the opp_tables_busy flag to indicate if another creator is in the middle
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1297)  * of adding an OPP table and others should wait for it to finish.
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1298)  */
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1299) struct opp_table *_add_opp_table_indexed(struct device *dev, int index,
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1300) 					 bool getclk)
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1301) {
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1302) 	struct opp_table *opp_table;
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1303) 
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1304) again:
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1305) 	mutex_lock(&opp_table_lock);
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1306) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 1307) 	opp_table = _find_opp_table_unlocked(dev);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 1308) 	if (!IS_ERR(opp_table))
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1309) 		goto unlock;
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1310) 
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1311) 	/*
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1312) 	 * The opp_tables list or an OPP table's dev_list is getting updated by
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1313) 	 * another user, wait for it to finish.
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1314) 	 */
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1315) 	if (unlikely(opp_tables_busy)) {
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1316) 		mutex_unlock(&opp_table_lock);
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1317) 		cpu_relax();
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1318) 		goto again;
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1319) 	}
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1320) 
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1321) 	opp_tables_busy = true;
283d55e68d8a0 drivers/opp/core.c            (Viresh Kumar              2018-09-07 09:01:54 +0530 1322) 	opp_table = _managed_opp(dev, index);
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1323) 
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1324) 	/* Drop the lock to reduce the size of critical section */
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1325) 	mutex_unlock(&opp_table_lock);
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1326) 
283d55e68d8a0 drivers/opp/core.c            (Viresh Kumar              2018-09-07 09:01:54 +0530 1327) 	if (opp_table) {
ef43f01ac0697 drivers/opp/core.c            (Viresh Kumar              2020-10-22 12:12:27 +0530 1328) 		if (!_add_opp_dev(dev, opp_table)) {
283d55e68d8a0 drivers/opp/core.c            (Viresh Kumar              2018-09-07 09:01:54 +0530 1329) 			dev_pm_opp_put_opp_table(opp_table);
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1330) 			opp_table = ERR_PTR(-ENOMEM);
283d55e68d8a0 drivers/opp/core.c            (Viresh Kumar              2018-09-07 09:01:54 +0530 1331) 		}
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1332) 
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1333) 		mutex_lock(&opp_table_lock);
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1334) 	} else {
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1335) 		opp_table = _allocate_opp_table(dev, index);
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1336) 
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1337) 		mutex_lock(&opp_table_lock);
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1338) 		if (!IS_ERR(opp_table))
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1339) 			list_add(&opp_table->node, &opp_tables);
283d55e68d8a0 drivers/opp/core.c            (Viresh Kumar              2018-09-07 09:01:54 +0530 1340) 	}
283d55e68d8a0 drivers/opp/core.c            (Viresh Kumar              2018-09-07 09:01:54 +0530 1341) 
27c09484dd3d8 drivers/opp/core.c            (Viresh Kumar              2020-10-27 16:53:21 +0530 1342) 	opp_tables_busy = false;
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1343) 
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1344) unlock:
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1345) 	mutex_unlock(&opp_table_lock);
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1346) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1347) 	return _update_opp_table_clk(dev, opp_table, getclk);
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1348) }
eb7c8743d6cf4 drivers/opp/core.c            (Viresh Kumar              2018-09-05 16:17:14 +0530 1349) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1350) static struct opp_table *_add_opp_table(struct device *dev, bool getclk)
eb7c8743d6cf4 drivers/opp/core.c            (Viresh Kumar              2018-09-05 16:17:14 +0530 1351) {
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1352) 	return _add_opp_table_indexed(dev, 0, getclk);
eb7c8743d6cf4 drivers/opp/core.c            (Viresh Kumar              2018-09-05 16:17:14 +0530 1353) }
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1354) 
e77dcb0b732dd drivers/opp/core.c            (Viresh Kumar              2020-11-06 10:37:16 +0530 1355) struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
eb7c8743d6cf4 drivers/opp/core.c            (Viresh Kumar              2018-09-05 16:17:14 +0530 1356) {
e77dcb0b732dd drivers/opp/core.c            (Viresh Kumar              2020-11-06 10:37:16 +0530 1357) 	return _find_opp_table(dev);
eb7c8743d6cf4 drivers/opp/core.c            (Viresh Kumar              2018-09-05 16:17:14 +0530 1358) }
e77dcb0b732dd drivers/opp/core.c            (Viresh Kumar              2020-11-06 10:37:16 +0530 1359) EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_table);
eb7c8743d6cf4 drivers/opp/core.c            (Viresh Kumar              2018-09-05 16:17:14 +0530 1360) 
b83c1899a0e98 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:45 +0530 1361) static void _opp_table_kref_release(struct kref *kref)
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1362) {
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1363) 	struct opp_table *opp_table = container_of(kref, struct opp_table, kref);
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 1364) 	struct opp_device *opp_dev, *temp;
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1365) 	int i;
b6160e26936bc drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:04 +0530 1366) 
e0df59de670b4 drivers/opp/core.c            (Viresh Kumar              2020-10-22 12:26:08 +0530 1367) 	/* Drop the lock as soon as we can */
e0df59de670b4 drivers/opp/core.c            (Viresh Kumar              2020-10-22 12:26:08 +0530 1368) 	list_del(&opp_table->node);
e0df59de670b4 drivers/opp/core.c            (Viresh Kumar              2020-10-22 12:26:08 +0530 1369) 	mutex_unlock(&opp_table_lock);
e0df59de670b4 drivers/opp/core.c            (Viresh Kumar              2020-10-22 12:26:08 +0530 1370) 
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530 1371) 	if (opp_table->current_opp)
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530 1372) 		dev_pm_opp_put(opp_table->current_opp);
81c4d8a3c4148 drivers/opp/core.c            (Viresh Kumar              2021-01-20 16:16:48 +0530 1373) 
5d6d106fa4550 drivers/opp/core.c            (Viresh Kumar              2018-06-07 14:50:43 +0530 1374) 	_of_clear_opp_table(opp_table);
5d6d106fa4550 drivers/opp/core.c            (Viresh Kumar              2018-06-07 14:50:43 +0530 1375) 
b6160e26936bc drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:04 +0530 1376) 	/* Release clk */
b6160e26936bc drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:04 +0530 1377) 	if (!IS_ERR(opp_table->clk))
b6160e26936bc drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:04 +0530 1378) 		clk_put(opp_table->clk);
b6160e26936bc drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:04 +0530 1379) 
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1380) 	if (opp_table->paths) {
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1381) 		for (i = 0; i < opp_table->path_count; i++)
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1382) 			icc_put(opp_table->paths[i]);
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1383) 		kfree(opp_table->paths);
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1384) 	}
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1385) 
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 1386) 	WARN_ON(!list_empty(&opp_table->opp_list));
b6160e26936bc drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:04 +0530 1387) 
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 1388) 	list_for_each_entry_safe(opp_dev, temp, &opp_table->dev_list, node) {
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 1389) 		/*
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 1390) 		 * The OPP table is getting removed, drop the performance state
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 1391) 		 * constraints.
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 1392) 		 */
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 1393) 		if (opp_table->genpd_performance_state)
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 1394) 			dev_pm_genpd_set_performance_state((struct device *)(opp_dev->dev), 0);
b6160e26936bc drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:04 +0530 1395) 
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 1396) 		_remove_opp_dev(opp_dev, opp_table);
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 1397) 	}
b6160e26936bc drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:04 +0530 1398) 
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 1399) 	mutex_destroy(&opp_table->genpd_virt_dev_lock);
37a73ec0c9bbd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:41 +0530 1400) 	mutex_destroy(&opp_table->lock);
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 1401) 	kfree(opp_table);
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1402) }
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1403) 
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1404) void dev_pm_opp_put_opp_table(struct opp_table *opp_table)
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1405) {
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1406) 	kref_put_mutex(&opp_table->kref, _opp_table_kref_release,
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1407) 		       &opp_table_lock);
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1408) }
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1409) EXPORT_SYMBOL_GPL(dev_pm_opp_put_opp_table);
f067a982cefa8 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:42 +0530 1410) 
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 1411) void _opp_free(struct dev_pm_opp *opp)
969fceb3c7e6f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:40:59 +0530 1412) {
969fceb3c7e6f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:40:59 +0530 1413) 	kfree(opp);
969fceb3c7e6f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:40:59 +0530 1414) }
969fceb3c7e6f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:40:59 +0530 1415) 
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1416) static void _opp_kref_release(struct kref *kref)
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1417) {
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1418) 	struct dev_pm_opp *opp = container_of(kref, struct dev_pm_opp, kref);
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1419) 	struct opp_table *opp_table = opp->opp_table;
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1420) 
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1421) 	list_del(&opp->node);
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1422) 	mutex_unlock(&opp_table->lock);
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1423) 
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1424) 	/*
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1425) 	 * Notify the changes in the availability of the operable
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1426) 	 * frequency/voltage list.
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1427) 	 */
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 1428) 	blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_REMOVE, opp);
da544b61eb554 drivers/opp/core.c            (Viresh Kumar              2018-06-07 14:50:43 +0530 1429) 	_of_opp_free_required_opps(opp_table, opp);
deaa51465105a drivers/base/power/opp/core.c (Viresh Kumar              2015-11-11 07:59:01 +0530 1430) 	opp_debug_remove_one(opp);
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 1431) 	kfree(opp);
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1432) }
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1433) 
a88bd2a51e901 drivers/opp/core.c            (Viresh Kumar              2017-11-29 15:18:36 +0530 1434) void dev_pm_opp_get(struct dev_pm_opp *opp)
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530 1435) {
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530 1436) 	kref_get(&opp->kref);
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530 1437) }
8a31d9d94297b drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:47 +0530 1438) 
7034764a1e4a6 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:46 +0530 1439) void dev_pm_opp_put(struct dev_pm_opp *opp)
7034764a1e4a6 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:46 +0530 1440) {
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1441) 	kref_put_mutex(&opp->kref, _opp_kref_release, &opp->opp_table->lock);
7034764a1e4a6 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:46 +0530 1442) }
7034764a1e4a6 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:46 +0530 1443) EXPORT_SYMBOL_GPL(dev_pm_opp_put);
7034764a1e4a6 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:46 +0530 1444) 
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1445) /**
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1446)  * dev_pm_opp_remove()  - Remove an OPP from OPP table
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1447)  * @dev:	device for which we do this operation
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1448)  * @freq:	OPP to remove with matching 'freq'
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1449)  *
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1450)  * This function removes an opp from the opp table.
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1451)  */
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1452) void dev_pm_opp_remove(struct device *dev, unsigned long freq)
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1453) {
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1454) 	struct dev_pm_opp *opp;
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1455) 	struct opp_table *opp_table;
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1456) 	bool found = false;
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1457) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1458) 	opp_table = _find_opp_table(dev);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1459) 	if (IS_ERR(opp_table))
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 1460) 		return;
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1461) 
37a73ec0c9bbd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:41 +0530 1462) 	mutex_lock(&opp_table->lock);
37a73ec0c9bbd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:41 +0530 1463) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1464) 	list_for_each_entry(opp, &opp_table->opp_list, node) {
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1465) 		if (opp->rate == freq) {
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1466) 			found = true;
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1467) 			break;
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1468) 		}
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1469) 	}
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1470) 
37a73ec0c9bbd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:41 +0530 1471) 	mutex_unlock(&opp_table->lock);
37a73ec0c9bbd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:41 +0530 1472) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 1473) 	if (found) {
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 1474) 		dev_pm_opp_put(opp);
0ad8c623907c2 drivers/opp/core.c            (Viresh Kumar              2018-08-02 14:23:09 +0530 1475) 
0ad8c623907c2 drivers/opp/core.c            (Viresh Kumar              2018-08-02 14:23:09 +0530 1476) 		/* Drop the reference taken by dev_pm_opp_add() */
0ad8c623907c2 drivers/opp/core.c            (Viresh Kumar              2018-08-02 14:23:09 +0530 1477) 		dev_pm_opp_put_opp_table(opp_table);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 1478) 	} else {
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1479) 		dev_warn(dev, "%s: Couldn't find OPP with freq: %lu\n",
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1480) 			 __func__, freq);
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1481) 	}
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1482) 
0ad8c623907c2 drivers/opp/core.c            (Viresh Kumar              2018-08-02 14:23:09 +0530 1483) 	/* Drop the reference taken by _find_opp_table() */
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 1484) 	dev_pm_opp_put_opp_table(opp_table);
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1485) }
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1486) EXPORT_SYMBOL_GPL(dev_pm_opp_remove);
129eec55df6ab drivers/base/power/opp.c      (Viresh Kumar              2014-11-27 08:54:06 +0530 1487) 
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1488) static struct dev_pm_opp *_opp_get_next(struct opp_table *opp_table,
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1489) 					bool dynamic)
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1490) {
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1491) 	struct dev_pm_opp *opp = NULL, *temp;
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1492) 
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1493) 	mutex_lock(&opp_table->lock);
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1494) 	list_for_each_entry(temp, &opp_table->opp_list, node) {
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1495) 		/*
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1496) 		 * Refcount must be dropped only once for each OPP by OPP core,
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1497) 		 * do that with help of "removed" flag.
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1498) 		 */
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1499) 		if (!temp->removed && dynamic == temp->dynamic) {
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1500) 			opp = temp;
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1501) 			break;
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1502) 		}
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1503) 	}
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1504) 
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1505) 	mutex_unlock(&opp_table->lock);
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1506) 	return opp;
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1507) }
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1508) 
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1509) /*
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1510)  * Can't call dev_pm_opp_put() from under the lock as debugfs removal needs to
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1511)  * happen lock less to avoid circular dependency issues. This routine must be
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1512)  * called without the opp_table->lock held.
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1513)  */
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1514) static void _opp_remove_all(struct opp_table *opp_table, bool dynamic)
03758d60265c7 drivers/opp/core.c            (Viresh Kumar              2019-11-11 16:35:03 +0530 1515) {
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1516) 	struct dev_pm_opp *opp;
03758d60265c7 drivers/opp/core.c            (Viresh Kumar              2019-11-11 16:35:03 +0530 1517) 
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1518) 	while ((opp = _opp_get_next(opp_table, dynamic))) {
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1519) 		opp->removed = true;
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1520) 		dev_pm_opp_put(opp);
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1521) 
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1522) 		/* Drop the references taken by dev_pm_opp_add() */
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1523) 		if (dynamic)
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1524) 			dev_pm_opp_put_opp_table(opp_table);
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1525) 	}
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1526) }
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1527) 
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1528) bool _opp_remove_all_static(struct opp_table *opp_table)
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1529) {
03758d60265c7 drivers/opp/core.c            (Viresh Kumar              2019-11-11 16:35:03 +0530 1530) 	mutex_lock(&opp_table->lock);
03758d60265c7 drivers/opp/core.c            (Viresh Kumar              2019-11-11 16:35:03 +0530 1531) 
922ff0759a162 drivers/opp/core.c            (Viresh Kumar              2020-08-31 13:03:06 +0530 1532) 	if (!opp_table->parsed_static_opps) {
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1533) 		mutex_unlock(&opp_table->lock);
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1534) 		return false;
922ff0759a162 drivers/opp/core.c            (Viresh Kumar              2020-08-31 13:03:06 +0530 1535) 	}
922ff0759a162 drivers/opp/core.c            (Viresh Kumar              2020-08-31 13:03:06 +0530 1536) 
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1537) 	if (--opp_table->parsed_static_opps) {
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1538) 		mutex_unlock(&opp_table->lock);
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1539) 		return true;
03758d60265c7 drivers/opp/core.c            (Viresh Kumar              2019-11-11 16:35:03 +0530 1540) 	}
03758d60265c7 drivers/opp/core.c            (Viresh Kumar              2019-11-11 16:35:03 +0530 1541) 
03758d60265c7 drivers/opp/core.c            (Viresh Kumar              2019-11-11 16:35:03 +0530 1542) 	mutex_unlock(&opp_table->lock);
922ff0759a162 drivers/opp/core.c            (Viresh Kumar              2020-08-31 13:03:06 +0530 1543) 
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1544) 	_opp_remove_all(opp_table, false);
cf1fac943c634 drivers/opp/core.c            (Viresh Kumar              2020-11-19 11:24:32 +0530 1545) 	return true;
03758d60265c7 drivers/opp/core.c            (Viresh Kumar              2019-11-11 16:35:03 +0530 1546) }
03758d60265c7 drivers/opp/core.c            (Viresh Kumar              2019-11-11 16:35:03 +0530 1547) 
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1548) /**
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1549)  * dev_pm_opp_remove_all_dynamic() - Remove all dynamically created OPPs
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1550)  * @dev:	device for which we do this operation
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1551)  *
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1552)  * This function removes all dynamically created OPPs from the opp table.
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1553)  */
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1554) void dev_pm_opp_remove_all_dynamic(struct device *dev)
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1555) {
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1556) 	struct opp_table *opp_table;
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1557) 
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1558) 	opp_table = _find_opp_table(dev);
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1559) 	if (IS_ERR(opp_table))
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1560) 		return;
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1561) 
606a5d4227e46 drivers/opp/core.c            (Beata Michalska           2021-03-04 15:07:34 +0000 1562) 	_opp_remove_all(opp_table, true);
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1563) 
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1564) 	/* Drop the reference taken by _find_opp_table() */
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1565) 	dev_pm_opp_put_opp_table(opp_table);
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1566) }
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1567) EXPORT_SYMBOL_GPL(dev_pm_opp_remove_all_dynamic);
1690d8bb91e37 drivers/opp/core.c            (Viresh Kumar              2019-01-04 15:14:33 +0530 1568) 
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 1569) struct dev_pm_opp *_opp_allocate(struct opp_table *table)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 1570) {
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1571) 	struct dev_pm_opp *opp;
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1572) 	int supply_count, supply_size, icc_size;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 1573) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1574) 	/* Allocate space for at least one supply */
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1575) 	supply_count = table->regulator_count > 0 ? table->regulator_count : 1;
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1576) 	supply_size = sizeof(*opp->supplies) * supply_count;
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1577) 	icc_size = sizeof(*opp->bandwidth) * table->path_count;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 1578) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1579) 	/* allocate new OPP node and supplies structures */
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1580) 	opp = kzalloc(sizeof(*opp) + supply_size + icc_size, GFP_KERNEL);
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1581) 
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 1582) 	if (!opp)
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1583) 		return NULL;
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1584) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1585) 	/* Put the supplies at the end of the OPP structure as an empty array */
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1586) 	opp->supplies = (struct dev_pm_opp_supply *)(opp + 1);
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1587) 	if (icc_size)
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1588) 		opp->bandwidth = (struct dev_pm_opp_icc_bw *)(opp->supplies + supply_count);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1589) 	INIT_LIST_HEAD(&opp->node);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1590) 
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1591) 	return opp;
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1592) }
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1593) 
7d34d56ef3349 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:34 +0530 1594) static bool _opp_supported_by_regulators(struct dev_pm_opp *opp,
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1595) 					 struct opp_table *opp_table)
7d34d56ef3349 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:34 +0530 1596) {
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1597) 	struct regulator *reg;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1598) 	int i;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1599) 
90e3577b5feb4 drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:32:47 +0530 1600) 	if (!opp_table->regulators)
90e3577b5feb4 drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:32:47 +0530 1601) 		return true;
90e3577b5feb4 drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:32:47 +0530 1602) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1603) 	for (i = 0; i < opp_table->regulator_count; i++) {
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1604) 		reg = opp_table->regulators[i];
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1605) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1606) 		if (!regulator_is_supported_voltage(reg,
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1607) 					opp->supplies[i].u_volt_min,
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1608) 					opp->supplies[i].u_volt_max)) {
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1609) 			pr_warn("%s: OPP minuV: %lu maxuV: %lu, not supported by regulator\n",
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1610) 				__func__, opp->supplies[i].u_volt_min,
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1611) 				opp->supplies[i].u_volt_max);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1612) 			return false;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1613) 		}
7d34d56ef3349 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:34 +0530 1614) 	}
7d34d56ef3349 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:34 +0530 1615) 
7d34d56ef3349 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:34 +0530 1616) 	return true;
7d34d56ef3349 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:34 +0530 1617) }
7d34d56ef3349 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:34 +0530 1618) 
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1619) int _opp_compare_key(struct dev_pm_opp *opp1, struct dev_pm_opp *opp2)
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1620) {
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1621) 	if (opp1->rate != opp2->rate)
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1622) 		return opp1->rate < opp2->rate ? -1 : 1;
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1623) 	if (opp1->bandwidth && opp2->bandwidth &&
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1624) 	    opp1->bandwidth[0].peak != opp2->bandwidth[0].peak)
6d3f922c46f2e drivers/opp/core.c            (Georgi Djakov             2020-05-12 15:53:21 +0300 1625) 		return opp1->bandwidth[0].peak < opp2->bandwidth[0].peak ? -1 : 1;
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1626) 	if (opp1->level != opp2->level)
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1627) 		return opp1->level < opp2->level ? -1 : 1;
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1628) 	return 0;
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1629) }
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1630) 
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1631) static int _opp_is_duplicate(struct device *dev, struct dev_pm_opp *new_opp,
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1632) 			     struct opp_table *opp_table,
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1633) 			     struct list_head **head)
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1634) {
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1635) 	struct dev_pm_opp *opp;
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1636) 	int opp_cmp;
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1637) 
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1638) 	/*
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1639) 	 * Insert new OPP in order of increasing frequency and discard if
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1640) 	 * already present.
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1641) 	 *
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1642) 	 * Need to use &opp_table->opp_list in the condition part of the 'for'
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1643) 	 * loop, don't replace it with head otherwise it will become an infinite
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1644) 	 * loop.
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1645) 	 */
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 1646) 	list_for_each_entry(opp, &opp_table->opp_list, node) {
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1647) 		opp_cmp = _opp_compare_key(new_opp, opp);
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1648) 		if (opp_cmp > 0) {
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1649) 			*head = &opp->node;
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1650) 			continue;
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1651) 		}
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1652) 
6c591eec67cbb drivers/opp/core.c            (Saravana Kannan           2020-05-12 15:53:19 +0300 1653) 		if (opp_cmp < 0)
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1654) 			return 0;
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1655) 
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1656) 		/* Duplicate OPPs */
064416586190c drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:04 +0530 1657) 		dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %lu, volt: %lu, enabled: %d. New: freq: %lu, volt: %lu, enabled: %d\n",
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1658) 			 __func__, opp->rate, opp->supplies[0].u_volt,
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1659) 			 opp->available, new_opp->rate,
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1660) 			 new_opp->supplies[0].u_volt, new_opp->available);
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1661) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1662) 		/* Should we compare voltages for all regulators here ? */
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1663) 		return opp->available &&
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1664) 		       new_opp->supplies[0].u_volt == opp->supplies[0].u_volt ? -EBUSY : -EEXIST;
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1665) 	}
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1666) 
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1667) 	return 0;
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1668) }
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1669) 
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1670) void _required_opps_available(struct dev_pm_opp *opp, int count)
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1671) {
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1672) 	int i;
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1673) 
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1674) 	for (i = 0; i < count; i++) {
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1675) 		if (opp->required_opps[i]->available)
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1676) 			continue;
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1677) 
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1678) 		opp->available = false;
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1679) 		pr_warn("%s: OPP not supported by required OPP %pOF (%lu)\n",
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1680) 			 __func__, opp->required_opps[i]->np, opp->rate);
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1681) 		return;
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1682) 	}
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1683) }
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1684) 
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1685) /*
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1686)  * Returns:
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1687)  * 0: On success. And appropriate error message for duplicate OPPs.
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1688)  * -EBUSY: For OPP with same freq/volt and is available. The callers of
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1689)  *  _opp_add() must return 0 if they receive -EBUSY from it. This is to make
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1690)  *  sure we don't print error messages unnecessarily if different parts of
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1691)  *  kernel try to initialize the OPP table.
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1692)  * -EEXIST: For OPP with same freq but different volt or is unavailable. This
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1693)  *  should be considered an error by the callers of _opp_add().
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1694)  */
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1695) int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1696) 	     struct opp_table *opp_table, bool rate_not_available)
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1697) {
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1698) 	struct list_head *head;
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1699) 	int ret;
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1700) 
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1701) 	mutex_lock(&opp_table->lock);
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1702) 	head = &opp_table->opp_list;
37a73ec0c9bbd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:41 +0530 1703) 
32715be4fe95f drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:13 +0300 1704) 	ret = _opp_is_duplicate(dev, new_opp, opp_table, &head);
32715be4fe95f drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:13 +0300 1705) 	if (ret) {
32715be4fe95f drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:13 +0300 1706) 		mutex_unlock(&opp_table->lock);
32715be4fe95f drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:13 +0300 1707) 		return ret;
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1708) 	}
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1709) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 1710) 	list_add(&new_opp->node, head);
37a73ec0c9bbd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:41 +0530 1711) 	mutex_unlock(&opp_table->lock);
37a73ec0c9bbd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:41 +0530 1712) 
37a73ec0c9bbd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:41 +0530 1713) 	new_opp->opp_table = opp_table;
7034764a1e4a6 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:46 +0530 1714) 	kref_init(&new_opp->kref);
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1715) 
a2dea4cb90702 drivers/opp/core.c            (Greg Kroah-Hartman        2019-01-22 16:21:17 +0100 1716) 	opp_debug_create_one(new_opp, opp_table);
deaa51465105a drivers/base/power/opp/core.c (Viresh Kumar              2015-11-11 07:59:01 +0530 1717) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1718) 	if (!_opp_supported_by_regulators(new_opp, opp_table)) {
7d34d56ef3349 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:34 +0530 1719) 		new_opp->available = false;
7d34d56ef3349 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:34 +0530 1720) 		dev_warn(dev, "%s: OPP not supported by regulators (%lu)\n",
7d34d56ef3349 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:34 +0530 1721) 			 __func__, new_opp->rate);
7d34d56ef3349 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:34 +0530 1722) 	}
7d34d56ef3349 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:34 +0530 1723) 
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1724) 	/* required-opps not fully initialized yet */
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1725) 	if (lazy_linking_pending(opp_table))
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1726) 		return 0;
cf65948d62c6a drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:14 +0300 1727) 
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 1728) 	_required_opps_available(new_opp, opp_table->required_opp_count);
cf65948d62c6a drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:14 +0300 1729) 
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1730) 	return 0;
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1731) }
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1732) 
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1733) /**
b64b9c3f900a0 drivers/base/power/opp/core.c (Viresh Kumar              2015-10-15 21:42:44 +0530 1734)  * _opp_add_v1() - Allocate a OPP based on v1 bindings.
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 1735)  * @opp_table:	OPP table
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1736)  * @dev:	device for which we do this operation
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1737)  * @freq:	Frequency in Hz for this OPP
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1738)  * @u_volt:	Voltage in uVolts for this OPP
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1739)  * @dynamic:	Dynamically added OPPs.
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1740)  *
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1741)  * This function adds an opp definition to the opp table and returns status.
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1742)  * The opp is made available by default and it can be controlled using
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1743)  * dev_pm_opp_enable/disable functions and may be removed by dev_pm_opp_remove.
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1744)  *
8f8d37b2537a2 drivers/base/power/opp.c      (Viresh Kumar              2015-09-04 13:47:24 +0530 1745)  * NOTE: "dynamic" parameter impacts OPPs added by the dev_pm_opp_of_add_table
8f8d37b2537a2 drivers/base/power/opp.c      (Viresh Kumar              2015-09-04 13:47:24 +0530 1746)  * and freed by dev_pm_opp_of_remove_table.
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1747)  *
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1748)  * Return:
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1749)  * 0		On success OR
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1750)  *		Duplicate OPPs (both freq and volt are same) and opp->available
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1751)  * -EEXIST	Freq are same and volt are different OR
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1752)  *		Duplicate OPPs (both freq and volt are same) and !opp->available
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1753)  * -ENOMEM	Memory allocation failure
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 1754)  */
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 1755) int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 1756) 		unsigned long freq, long u_volt, bool dynamic)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 1757) {
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1758) 	struct dev_pm_opp *new_opp;
50f8cfbd5897c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:37 +0530 1759) 	unsigned long tol;
6ce4184d03088 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:35 +0530 1760) 	int ret;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 1761) 
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 1762) 	new_opp = _opp_allocate(opp_table);
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 1763) 	if (!new_opp)
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 1764) 		return -ENOMEM;
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1765) 
a7470db6fec48 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:17 +0530 1766) 	/* populate the opp table */
a7470db6fec48 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:17 +0530 1767) 	new_opp->rate = freq;
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1768) 	tol = u_volt * opp_table->voltage_tolerance_v1 / 100;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1769) 	new_opp->supplies[0].u_volt = u_volt;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1770) 	new_opp->supplies[0].u_volt_min = u_volt - tol;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1771) 	new_opp->supplies[0].u_volt_max = u_volt + tol;
a7470db6fec48 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:17 +0530 1772) 	new_opp->available = true;
23dacf6d2e993 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:23:01 +0530 1773) 	new_opp->dynamic = dynamic;
a7470db6fec48 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:17 +0530 1774) 
a1e8c13600bfd drivers/opp/core.c            (Viresh Kumar              2018-04-06 14:35:45 +0530 1775) 	ret = _opp_add(dev, new_opp, opp_table, false);
7f8538ebaefc0 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:40:55 +0530 1776) 	if (ret) {
7f8538ebaefc0 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:40:55 +0530 1777) 		/* Don't return error for duplicate OPPs */
7f8538ebaefc0 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:40:55 +0530 1778) 		if (ret == -EBUSY)
7f8538ebaefc0 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:40:55 +0530 1779) 			ret = 0;
6ce4184d03088 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:35 +0530 1780) 		goto free_opp;
7f8538ebaefc0 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:40:55 +0530 1781) 	}
64ce854578de8 drivers/base/power/opp.c      (Chander Kashyap           2014-05-22 10:36:26 +0530 1782) 
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 1783) 	/*
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 1784) 	 * Notify the changes in the availability of the operable
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 1785) 	 * frequency/voltage list.
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 1786) 	 */
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 1787) 	blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 1788) 	return 0;
6ce4184d03088 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:35 +0530 1789) 
6ce4184d03088 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:35 +0530 1790) free_opp:
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 1791) 	_opp_free(new_opp);
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 1792) 
6ce4184d03088 drivers/base/power/opp.c      (Viresh Kumar              2014-12-10 09:45:35 +0530 1793) 	return ret;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 1794) }
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 1795) 
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1796) /**
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1797)  * dev_pm_opp_set_supported_hw() - Set supported platforms
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1798)  * @dev: Device for which supported-hw has to be set.
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1799)  * @versions: Array of hierarchy of versions to match.
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1800)  * @count: Number of elements in the array.
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1801)  *
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1802)  * This is required only for the V2 bindings, and it enables a platform to
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1803)  * specify the hierarchy of versions it supports. OPP layer will then enable
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1804)  * OPPs, which are available for those versions, based on its 'opp-supported-hw'
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1805)  * property.
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1806)  */
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 1807) struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 1808) 			const u32 *versions, unsigned int count)
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1809) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1810) 	struct opp_table *opp_table;
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1811) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1812) 	opp_table = _add_opp_table(dev, false);
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1813) 	if (IS_ERR(opp_table))
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1814) 		return opp_table;
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1815) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1816) 	/* Make sure there are no concurrent readers while updating opp_table */
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1817) 	WARN_ON(!list_empty(&opp_table->opp_list));
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1818) 
25419de1b8dda drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1819) 	/* Another CPU that shares the OPP table has set the property ? */
25419de1b8dda drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1820) 	if (opp_table->supported_hw)
25419de1b8dda drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1821) 		return opp_table;
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1822) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1823) 	opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions),
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1824) 					GFP_KERNEL);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1825) 	if (!opp_table->supported_hw) {
25419de1b8dda drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1826) 		dev_pm_opp_put_opp_table(opp_table);
25419de1b8dda drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1827) 		return ERR_PTR(-ENOMEM);
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1828) 	}
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1829) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1830) 	opp_table->supported_hw_count = count;
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 1831) 
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 1832) 	return opp_table;
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1833) }
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1834) EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw);
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1835) 
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1836) /**
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1837)  * dev_pm_opp_put_supported_hw() - Releases resources blocked for supported hw
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 1838)  * @opp_table: OPP table returned by dev_pm_opp_set_supported_hw().
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1839)  *
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1840)  * This is required only for the V2 bindings, and is called for a matching
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1841)  * dev_pm_opp_set_supported_hw(). Until this is called, the opp_table structure
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1842)  * will not be freed.
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1843)  */
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 1844) void dev_pm_opp_put_supported_hw(struct opp_table *opp_table)
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1845) {
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 1846) 	if (unlikely(!opp_table))
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 1847) 		return;
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 1848) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1849) 	kfree(opp_table->supported_hw);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1850) 	opp_table->supported_hw = NULL;
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1851) 	opp_table->supported_hw_count = 0;
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1852) 
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 1853) 	dev_pm_opp_put_opp_table(opp_table);
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1854) }
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1855) EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw);
7de36b0aa51a5 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:46 +0530 1856) 
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1857) static void devm_pm_opp_supported_hw_release(void *data)
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1858) {
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1859) 	dev_pm_opp_put_supported_hw(data);
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1860) }
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1861) 
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1862) /**
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1863)  * devm_pm_opp_set_supported_hw() - Set supported platforms
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1864)  * @dev: Device for which supported-hw has to be set.
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1865)  * @versions: Array of hierarchy of versions to match.
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1866)  * @count: Number of elements in the array.
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1867)  *
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1868)  * This is a resource-managed variant of dev_pm_opp_set_supported_hw().
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1869)  *
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1870)  * Return: 0 on success and errorno otherwise.
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1871)  */
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1872) int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions,
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1873) 				 unsigned int count)
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1874) {
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1875) 	struct opp_table *opp_table;
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1876) 
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1877) 	opp_table = dev_pm_opp_set_supported_hw(dev, versions, count);
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1878) 	if (IS_ERR(opp_table))
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1879) 		return PTR_ERR(opp_table);
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1880) 
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1881) 	return devm_add_action_or_reset(dev, devm_pm_opp_supported_hw_release,
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1882) 					opp_table);
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1883) }
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1884) EXPORT_SYMBOL_GPL(devm_pm_opp_set_supported_hw);
9c4f220f3dc26 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:56 +0300 1885) 
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1886) /**
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1887)  * dev_pm_opp_set_prop_name() - Set prop-extn name
a5da64477ee79 drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:52 +0530 1888)  * @dev: Device for which the prop-name has to be set.
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1889)  * @name: name to postfix to properties.
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1890)  *
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1891)  * This is required only for the V2 bindings, and it enables a platform to
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1892)  * specify the extn to be used for certain property names. The properties to
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1893)  * which the extension will apply are opp-microvolt and opp-microamp. OPP core
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1894)  * should postfix the property name with -<name> while looking for them.
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1895)  */
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 1896) struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1897) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1898) 	struct opp_table *opp_table;
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1899) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1900) 	opp_table = _add_opp_table(dev, false);
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1901) 	if (IS_ERR(opp_table))
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1902) 		return opp_table;
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1903) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1904) 	/* Make sure there are no concurrent readers while updating opp_table */
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1905) 	WARN_ON(!list_empty(&opp_table->opp_list));
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1906) 
878ec1a9f0e5a drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1907) 	/* Another CPU that shares the OPP table has set the property ? */
878ec1a9f0e5a drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1908) 	if (opp_table->prop_name)
878ec1a9f0e5a drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1909) 		return opp_table;
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1910) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1911) 	opp_table->prop_name = kstrdup(name, GFP_KERNEL);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1912) 	if (!opp_table->prop_name) {
878ec1a9f0e5a drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1913) 		dev_pm_opp_put_opp_table(opp_table);
878ec1a9f0e5a drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1914) 		return ERR_PTR(-ENOMEM);
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1915) 	}
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1916) 
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 1917) 	return opp_table;
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1918) }
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1919) EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name);
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1920) 
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1921) /**
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1922)  * dev_pm_opp_put_prop_name() - Releases resources blocked for prop-name
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 1923)  * @opp_table: OPP table returned by dev_pm_opp_set_prop_name().
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1924)  *
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1925)  * This is required only for the V2 bindings, and is called for a matching
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1926)  * dev_pm_opp_set_prop_name(). Until this is called, the opp_table structure
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1927)  * will not be freed.
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1928)  */
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 1929) void dev_pm_opp_put_prop_name(struct opp_table *opp_table)
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1930) {
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 1931) 	if (unlikely(!opp_table))
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 1932) 		return;
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 1933) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1934) 	kfree(opp_table->prop_name);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1935) 	opp_table->prop_name = NULL;
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1936) 
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 1937) 	dev_pm_opp_put_opp_table(opp_table);
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1938) }
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1939) EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name);
01fb4d3c39d35 drivers/base/power/opp/core.c (Viresh Kumar              2015-12-09 08:01:47 +0530 1940) 
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1941) /**
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1942)  * dev_pm_opp_set_regulators() - Set regulator names for the device
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1943)  * @dev: Device for which regulator name is being set.
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1944)  * @names: Array of pointers to the names of the regulator.
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1945)  * @count: Number of regulators.
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1946)  *
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1947)  * In order to support OPP switching, OPP layer needs to know the name of the
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1948)  * device's regulators, as the core would be required to switch voltages as
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1949)  * well.
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1950)  *
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1951)  * This must be called before any OPPs are initialized for the device.
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1952)  */
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1953) struct opp_table *dev_pm_opp_set_regulators(struct device *dev,
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1954) 					    const char * const names[],
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1955) 					    unsigned int count)
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1956) {
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 1957) 	struct dev_pm_opp_supply *supplies;
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1958) 	struct opp_table *opp_table;
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1959) 	struct regulator *reg;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1960) 	int ret, i;
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1961) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 1962) 	opp_table = _add_opp_table(dev, false);
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1963) 	if (IS_ERR(opp_table))
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 1964) 		return opp_table;
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1965) 
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1966) 	/* This should be called before OPPs are initialized */
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 1967) 	if (WARN_ON(!list_empty(&opp_table->opp_list))) {
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1968) 		ret = -EBUSY;
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1969) 		goto err;
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1970) 	}
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1971) 
779b783cfaa72 drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1972) 	/* Another CPU that shares the OPP table has set the regulators ? */
779b783cfaa72 drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1973) 	if (opp_table->regulators)
779b783cfaa72 drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 1974) 		return opp_table;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1975) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1976) 	opp_table->regulators = kmalloc_array(count,
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1977) 					      sizeof(*opp_table->regulators),
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1978) 					      GFP_KERNEL);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1979) 	if (!opp_table->regulators) {
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1980) 		ret = -ENOMEM;
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1981) 		goto err;
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1982) 	}
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1983) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1984) 	for (i = 0; i < count; i++) {
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1985) 		reg = regulator_get_optional(dev, names[i]);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1986) 		if (IS_ERR(reg)) {
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1987) 			ret = PTR_ERR(reg);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1988) 			if (ret != -EPROBE_DEFER)
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1989) 				dev_err(dev, "%s: no regulator (%s) found: %d\n",
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1990) 					__func__, names[i], ret);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1991) 			goto free_regulators;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1992) 		}
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1993) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1994) 		opp_table->regulators[i] = reg;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1995) 	}
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1996) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 1997) 	opp_table->regulator_count = count;
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 1998) 
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 1999) 	supplies = kmalloc_array(count * 2, sizeof(*supplies), GFP_KERNEL);
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2000) 	if (!supplies) {
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2001) 		ret = -ENOMEM;
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530 2002) 		goto free_regulators;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2003) 	}
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2004) 
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2005) 	mutex_lock(&opp_table->lock);
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2006) 	opp_table->sod_supplies = supplies;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2007) 	if (opp_table->set_opp_data) {
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2008) 		opp_table->set_opp_data->old_opp.supplies = supplies;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2009) 		opp_table->set_opp_data->new_opp.supplies = supplies + count;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2010) 	}
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2011) 	mutex_unlock(&opp_table->lock);
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530 2012) 
91291d9ad92fa drivers/base/power/opp/core.c (Stephen Boyd              2016-11-30 16:21:25 +0530 2013) 	return opp_table;
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 2014) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2015) free_regulators:
24957db100435 drivers/opp/core.c            (Marek Szyprowski          2019-10-17 12:27:58 +0200 2016) 	while (i != 0)
24957db100435 drivers/opp/core.c            (Marek Szyprowski          2019-10-17 12:27:58 +0200 2017) 		regulator_put(opp_table->regulators[--i]);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2018) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2019) 	kfree(opp_table->regulators);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2020) 	opp_table->regulators = NULL;
46f48aca2e5ae drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:39:36 +0530 2021) 	opp_table->regulator_count = -1;
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 2022) err:
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 2023) 	dev_pm_opp_put_opp_table(opp_table);
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 2024) 
91291d9ad92fa drivers/base/power/opp/core.c (Stephen Boyd              2016-11-30 16:21:25 +0530 2025) 	return ERR_PTR(ret);
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 2026) }
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2027) EXPORT_SYMBOL_GPL(dev_pm_opp_set_regulators);
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 2028) 
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 2029) /**
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2030)  * dev_pm_opp_put_regulators() - Releases resources blocked for regulator
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2031)  * @opp_table: OPP table returned from dev_pm_opp_set_regulators().
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 2032)  */
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2033) void dev_pm_opp_put_regulators(struct opp_table *opp_table)
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 2034) {
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2035) 	int i;
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2036) 
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 2037) 	if (unlikely(!opp_table))
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 2038) 		return;
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 2039) 
779b783cfaa72 drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 2040) 	if (!opp_table->regulators)
779b783cfaa72 drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 2041) 		goto put_opp_table;
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 2042) 
72f80ce4ef9b7 drivers/opp/core.c            (Viresh Kumar              2020-08-13 08:38:37 +0530 2043) 	if (opp_table->enabled) {
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200 2044) 		for (i = opp_table->regulator_count - 1; i >= 0; i--)
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200 2045) 			regulator_disable(opp_table->regulators[i]);
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200 2046) 	}
8d45719caaf56 drivers/opp/core.c            (Kamil Konieczny           2019-07-19 17:05:32 +0200 2047) 
24957db100435 drivers/opp/core.c            (Marek Szyprowski          2019-10-17 12:27:58 +0200 2048) 	for (i = opp_table->regulator_count - 1; i >= 0; i--)
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2049) 		regulator_put(opp_table->regulators[i]);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2050) 
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2051) 	mutex_lock(&opp_table->lock);
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2052) 	if (opp_table->set_opp_data) {
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2053) 		opp_table->set_opp_data->old_opp.supplies = NULL;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2054) 		opp_table->set_opp_data->new_opp.supplies = NULL;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2055) 	}
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2056) 
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2057) 	kfree(opp_table->sod_supplies);
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2058) 	opp_table->sod_supplies = NULL;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2059) 	mutex_unlock(&opp_table->lock);
947355850fcb3 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:20 +0530 2060) 
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2061) 	kfree(opp_table->regulators);
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2062) 	opp_table->regulators = NULL;
46f48aca2e5ae drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:39:36 +0530 2063) 	opp_table->regulator_count = -1;
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 2064) 
779b783cfaa72 drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 2065) put_opp_table:
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 2066) 	dev_pm_opp_put_opp_table(opp_table);
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 2067) }
dfbe4678d709e drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:19 +0530 2068) EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulators);
9f8ea969d5cfd drivers/base/power/opp/core.c (Viresh Kumar              2016-02-09 10:30:33 +0530 2069) 
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2070) static void devm_pm_opp_regulators_release(void *data)
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2071) {
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2072) 	dev_pm_opp_put_regulators(data);
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2073) }
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2074) 
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2075) /**
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2076)  * devm_pm_opp_set_regulators() - Set regulator names for the device
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2077)  * @dev: Device for which regulator name is being set.
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2078)  * @names: Array of pointers to the names of the regulator.
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2079)  * @count: Number of regulators.
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2080)  *
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2081)  * This is a resource-managed variant of dev_pm_opp_set_regulators().
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2082)  *
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2083)  * Return: 0 on success and errorno otherwise.
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2084)  */
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2085) int devm_pm_opp_set_regulators(struct device *dev,
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2086) 			       const char * const names[],
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2087) 			       unsigned int count)
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2088) {
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2089) 	struct opp_table *opp_table;
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2090) 
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2091) 	opp_table = dev_pm_opp_set_regulators(dev, names, count);
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2092) 	if (IS_ERR(opp_table))
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2093) 		return PTR_ERR(opp_table);
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2094) 
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2095) 	return devm_add_action_or_reset(dev, devm_pm_opp_regulators_release,
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2096) 					opp_table);
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2097) }
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2098) EXPORT_SYMBOL_GPL(devm_pm_opp_set_regulators);
32aee78bc5184 drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:55 +0300 2099) 
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2100) /**
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2101)  * dev_pm_opp_set_clkname() - Set clk name for the device
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2102)  * @dev: Device for which clk name is being set.
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2103)  * @name: Clk name.
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2104)  *
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2105)  * In order to support OPP switching, OPP layer needs to get pointer to the
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2106)  * clock for the device. Simple cases work fine without using this routine (i.e.
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2107)  * by passing connection-id as NULL), but for a device with multiple clocks
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2108)  * available, the OPP core needs to know the exact name of the clk to use.
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2109)  *
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2110)  * This must be called before any OPPs are initialized for the device.
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2111)  */
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2112) struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name)
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2113) {
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2114) 	struct opp_table *opp_table;
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2115) 	int ret;
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2116) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 2117) 	opp_table = _add_opp_table(dev, false);
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 2118) 	if (IS_ERR(opp_table))
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 2119) 		return opp_table;
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2120) 
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2121) 	/* This should be called before OPPs are initialized */
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2122) 	if (WARN_ON(!list_empty(&opp_table->opp_list))) {
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2123) 		ret = -EBUSY;
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2124) 		goto err;
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2125) 	}
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2126) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 2127) 	/* clk shouldn't be initialized at this point */
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 2128) 	if (WARN_ON(opp_table->clk)) {
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 2129) 		ret = -EBUSY;
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 2130) 		goto err;
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 2131) 	}
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2132) 
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2133) 	/* Find clk for the device */
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2134) 	opp_table->clk = clk_get(dev, name);
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2135) 	if (IS_ERR(opp_table->clk)) {
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2136) 		ret = PTR_ERR(opp_table->clk);
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2137) 		if (ret != -EPROBE_DEFER) {
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2138) 			dev_err(dev, "%s: Couldn't find clock: %d\n", __func__,
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2139) 				ret);
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2140) 		}
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2141) 		goto err;
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2142) 	}
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2143) 
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2144) 	return opp_table;
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2145) 
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2146) err:
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2147) 	dev_pm_opp_put_opp_table(opp_table);
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2148) 
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2149) 	return ERR_PTR(ret);
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2150) }
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2151) EXPORT_SYMBOL_GPL(dev_pm_opp_set_clkname);
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2152) 
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2153) /**
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2154)  * dev_pm_opp_put_clkname() - Releases resources blocked for clk.
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2155)  * @opp_table: OPP table returned from dev_pm_opp_set_clkname().
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2156)  */
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2157) void dev_pm_opp_put_clkname(struct opp_table *opp_table)
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2158) {
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 2159) 	if (unlikely(!opp_table))
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 2160) 		return;
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 2161) 
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2162) 	clk_put(opp_table->clk);
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2163) 	opp_table->clk = ERR_PTR(-EINVAL);
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2164) 
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2165) 	dev_pm_opp_put_opp_table(opp_table);
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2166) }
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2167) EXPORT_SYMBOL_GPL(dev_pm_opp_put_clkname);
829a4e8c0e9aa drivers/base/power/opp/core.c (Viresh Kumar              2017-06-21 10:29:13 +0530 2168) 
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2169) static void devm_pm_opp_clkname_release(void *data)
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2170) {
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2171) 	dev_pm_opp_put_clkname(data);
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2172) }
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2173) 
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2174) /**
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2175)  * devm_pm_opp_set_clkname() - Set clk name for the device
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2176)  * @dev: Device for which clk name is being set.
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2177)  * @name: Clk name.
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2178)  *
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2179)  * This is a resource-managed variant of dev_pm_opp_set_clkname().
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2180)  *
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2181)  * Return: 0 on success and errorno otherwise.
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2182)  */
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2183) int devm_pm_opp_set_clkname(struct device *dev, const char *name)
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2184) {
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2185) 	struct opp_table *opp_table;
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2186) 
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2187) 	opp_table = dev_pm_opp_set_clkname(dev, name);
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2188) 	if (IS_ERR(opp_table))
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2189) 		return PTR_ERR(opp_table);
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2190) 
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2191) 	return devm_add_action_or_reset(dev, devm_pm_opp_clkname_release,
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2192) 					opp_table);
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2193) }
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2194) EXPORT_SYMBOL_GPL(devm_pm_opp_set_clkname);
a74f681c3710b drivers/opp/core.c            (Yangtao Li                2021-03-14 19:33:54 +0300 2195) 
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2196) /**
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2197)  * dev_pm_opp_register_set_opp_helper() - Register custom set OPP helper
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2198)  * @dev: Device for which the helper is getting registered.
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2199)  * @set_opp: Custom set OPP helper.
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2200)  *
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2201)  * This is useful to support complex platforms (like platforms with multiple
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2202)  * regulators per device), instead of the generic OPP set rate helper.
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2203)  *
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2204)  * This must be called before any OPPs are initialized for the device.
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2205)  */
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 2206) struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2207) 			int (*set_opp)(struct dev_pm_set_opp_data *data))
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2208) {
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2209) 	struct dev_pm_set_opp_data *data;
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2210) 	struct opp_table *opp_table;
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2211) 
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2212) 	if (!set_opp)
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 2213) 		return ERR_PTR(-EINVAL);
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2214) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 2215) 	opp_table = _add_opp_table(dev, false);
47efcbcb340cc drivers/opp/core.c            (Viresh Kumar              2020-10-20 16:03:15 +0530 2216) 	if (IS_ERR(opp_table))
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 2217) 		return opp_table;
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2218) 
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2219) 	/* This should be called before OPPs are initialized */
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2220) 	if (WARN_ON(!list_empty(&opp_table->opp_list))) {
5019acc693d31 drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 2221) 		dev_pm_opp_put_opp_table(opp_table);
5019acc693d31 drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 2222) 		return ERR_PTR(-EBUSY);
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2223) 	}
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2224) 
5019acc693d31 drivers/opp/core.c            (Viresh Kumar              2018-05-22 16:38:08 +0530 2225) 	/* Another CPU that shares the OPP table has set the helper ? */
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2226) 	if (opp_table->set_opp)
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2227) 		return opp_table;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2228) 
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2229) 	data = kzalloc(sizeof(*data), GFP_KERNEL);
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2230) 	if (!data)
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2231) 		return ERR_PTR(-ENOMEM);
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2232) 
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2233) 	mutex_lock(&opp_table->lock);
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2234) 	opp_table->set_opp_data = data;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2235) 	if (opp_table->sod_supplies) {
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2236) 		data->old_opp.supplies = opp_table->sod_supplies;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2237) 		data->new_opp.supplies = opp_table->sod_supplies +
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2238) 					 opp_table->regulator_count;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2239) 	}
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2240) 	mutex_unlock(&opp_table->lock);
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2241) 
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2242) 	opp_table->set_opp = set_opp;
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2243) 
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 2244) 	return opp_table;
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2245) }
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2246) EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_opp_helper);
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2247) 
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2248) /**
604a7aeb4325b drivers/opp/core.c            (Viresh Kumar              2017-10-05 17:26:21 +0530 2249)  * dev_pm_opp_unregister_set_opp_helper() - Releases resources blocked for
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2250)  *					   set_opp helper
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 2251)  * @opp_table: OPP table returned from dev_pm_opp_register_set_opp_helper().
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2252)  *
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 2253)  * Release resources blocked for platform specific set_opp helper.
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2254)  */
604a7aeb4325b drivers/opp/core.c            (Viresh Kumar              2017-10-05 17:26:21 +0530 2255) void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table)
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2256) {
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 2257) 	if (unlikely(!opp_table))
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 2258) 		return;
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 2259) 
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2260) 	opp_table->set_opp = NULL;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2261) 
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2262) 	mutex_lock(&opp_table->lock);
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2263) 	kfree(opp_table->set_opp_data);
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2264) 	opp_table->set_opp_data = NULL;
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2265) 	mutex_unlock(&opp_table->lock);
38bb34393804b drivers/opp/core.c            (Viresh Kumar              2021-01-19 11:58:58 +0530 2266) 
fa30184d192ec drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:43 +0530 2267) 	dev_pm_opp_put_opp_table(opp_table);
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2268) }
604a7aeb4325b drivers/opp/core.c            (Viresh Kumar              2017-10-05 17:26:21 +0530 2269) EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_set_opp_helper);
4dab160eb1586 drivers/base/power/opp/core.c (Viresh Kumar              2016-12-01 16:28:21 +0530 2270) 
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2271) static void devm_pm_opp_unregister_set_opp_helper(void *data)
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2272) {
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2273) 	dev_pm_opp_unregister_set_opp_helper(data);
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2274) }
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2275) 
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2276) /**
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2277)  * devm_pm_opp_register_set_opp_helper() - Register custom set OPP helper
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2278)  * @dev: Device for which the helper is getting registered.
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2279)  * @set_opp: Custom set OPP helper.
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2280)  *
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2281)  * This is a resource-managed version of dev_pm_opp_register_set_opp_helper().
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2282)  *
c41c8a3485b0b drivers/opp/core.c            (Dmitry Osipenko           2021-03-14 19:33:58 +0300 2283)  * Return: 0 on success and errorno otherwise.
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2284)  */
c41c8a3485b0b drivers/opp/core.c            (Dmitry Osipenko           2021-03-14 19:33:58 +0300 2285) int devm_pm_opp_register_set_opp_helper(struct device *dev,
c41c8a3485b0b drivers/opp/core.c            (Dmitry Osipenko           2021-03-14 19:33:58 +0300 2286) 					int (*set_opp)(struct dev_pm_set_opp_data *data))
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2287) {
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2288) 	struct opp_table *opp_table;
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2289) 
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2290) 	opp_table = dev_pm_opp_register_set_opp_helper(dev, set_opp);
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2291) 	if (IS_ERR(opp_table))
c41c8a3485b0b drivers/opp/core.c            (Dmitry Osipenko           2021-03-14 19:33:58 +0300 2292) 		return PTR_ERR(opp_table);
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2293) 
c41c8a3485b0b drivers/opp/core.c            (Dmitry Osipenko           2021-03-14 19:33:58 +0300 2294) 	return devm_add_action_or_reset(dev, devm_pm_opp_unregister_set_opp_helper,
c41c8a3485b0b drivers/opp/core.c            (Dmitry Osipenko           2021-03-14 19:33:58 +0300 2295) 					opp_table);
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2296) }
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2297) EXPORT_SYMBOL_GPL(devm_pm_opp_register_set_opp_helper);
a3c47af6942dc drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:20 +0300 2298) 
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2299) static void _opp_detach_genpd(struct opp_table *opp_table)
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2300) {
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2301) 	int index;
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2302) 
cb60e9602cce1 drivers/opp/core.c            (Viresh Kumar              2020-08-31 11:22:37 +0530 2303) 	if (!opp_table->genpd_virt_devs)
cb60e9602cce1 drivers/opp/core.c            (Viresh Kumar              2020-08-31 11:22:37 +0530 2304) 		return;
cb60e9602cce1 drivers/opp/core.c            (Viresh Kumar              2020-08-31 11:22:37 +0530 2305) 
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2306) 	for (index = 0; index < opp_table->required_opp_count; index++) {
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2307) 		if (!opp_table->genpd_virt_devs[index])
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2308) 			continue;
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2309) 
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2310) 		dev_pm_domain_detach(opp_table->genpd_virt_devs[index], false);
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2311) 		opp_table->genpd_virt_devs[index] = NULL;
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2312) 	}
c0ab9e0812da8 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:43:36 +0530 2313) 
c0ab9e0812da8 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:43:36 +0530 2314) 	kfree(opp_table->genpd_virt_devs);
c0ab9e0812da8 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:43:36 +0530 2315) 	opp_table->genpd_virt_devs = NULL;
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2316) }
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2317) 
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2318) /**
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2319)  * dev_pm_opp_attach_genpd - Attach genpd(s) for the device and save virtual device pointer
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2320)  * @dev: Consumer device for which the genpd is getting attached.
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2321)  * @names: Null terminated array of pointers containing names of genpd to attach.
17a8f868ae3e8 drivers/opp/core.c            (Viresh Kumar              2019-07-08 11:24:56 +0530 2322)  * @virt_devs: Pointer to return the array of virtual devices.
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2323)  *
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2324)  * Multiple generic power domains for a device are supported with the help of
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2325)  * virtual genpd devices, which are created for each consumer device - genpd
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2326)  * pair. These are the device structures which are attached to the power domain
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2327)  * and are required by the OPP core to set the performance state of the genpd.
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2328)  * The same API also works for the case where single genpd is available and so
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2329)  * we don't need to support that separately.
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2330)  *
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2331)  * This helper will normally be called by the consumer driver of the device
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2332)  * "dev", as only that has details of the genpd names.
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2333)  *
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2334)  * This helper needs to be called once with a list of all genpd to attach.
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2335)  * Otherwise the original device structure will be used instead by the OPP core.
baea35e4db17a drivers/opp/core.c            (Viresh Kumar              2019-07-17 11:20:17 +0530 2336)  *
baea35e4db17a drivers/opp/core.c            (Viresh Kumar              2019-07-17 11:20:17 +0530 2337)  * The order of entries in the names array must match the order in which
baea35e4db17a drivers/opp/core.c            (Viresh Kumar              2019-07-17 11:20:17 +0530 2338)  * "required-opps" are added in DT.
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2339)  */
17a8f868ae3e8 drivers/opp/core.c            (Viresh Kumar              2019-07-08 11:24:56 +0530 2340) struct opp_table *dev_pm_opp_attach_genpd(struct device *dev,
17a8f868ae3e8 drivers/opp/core.c            (Viresh Kumar              2019-07-08 11:24:56 +0530 2341) 		const char **names, struct device ***virt_devs)
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2342) {
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2343) 	struct opp_table *opp_table;
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2344) 	struct device *virt_dev;
baea35e4db17a drivers/opp/core.c            (Viresh Kumar              2019-07-17 11:20:17 +0530 2345) 	int index = 0, ret = -EINVAL;
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2346) 	const char **name = names;
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2347) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 2348) 	opp_table = _add_opp_table(dev, false);
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 2349) 	if (IS_ERR(opp_table))
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 2350) 		return opp_table;
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2351) 
cb60e9602cce1 drivers/opp/core.c            (Viresh Kumar              2020-08-31 11:22:37 +0530 2352) 	if (opp_table->genpd_virt_devs)
cb60e9602cce1 drivers/opp/core.c            (Viresh Kumar              2020-08-31 11:22:37 +0530 2353) 		return opp_table;
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2354) 
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2355) 	/*
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2356) 	 * If the genpd's OPP table isn't already initialized, parsing of the
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2357) 	 * required-opps fail for dev. We should retry this after genpd's OPP
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2358) 	 * table is added.
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2359) 	 */
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2360) 	if (!opp_table->required_opp_count) {
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2361) 		ret = -EPROBE_DEFER;
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2362) 		goto put_table;
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2363) 	}
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2364) 
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2365) 	mutex_lock(&opp_table->genpd_virt_dev_lock);
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2366) 
c0ab9e0812da8 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:43:36 +0530 2367) 	opp_table->genpd_virt_devs = kcalloc(opp_table->required_opp_count,
c0ab9e0812da8 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:43:36 +0530 2368) 					     sizeof(*opp_table->genpd_virt_devs),
c0ab9e0812da8 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:43:36 +0530 2369) 					     GFP_KERNEL);
c0ab9e0812da8 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:43:36 +0530 2370) 	if (!opp_table->genpd_virt_devs)
c0ab9e0812da8 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:43:36 +0530 2371) 		goto unlock;
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2372) 
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2373) 	while (*name) {
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2374) 		if (index >= opp_table->required_opp_count) {
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2375) 			dev_err(dev, "Index can't be greater than required-opp-count - 1, %s (%d : %d)\n",
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2376) 				*name, opp_table->required_opp_count, index);
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2377) 			goto err;
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2378) 		}
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2379) 
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2380) 		virt_dev = dev_pm_domain_attach_by_name(dev, *name);
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2381) 		if (IS_ERR(virt_dev)) {
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2382) 			ret = PTR_ERR(virt_dev);
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2383) 			dev_err(dev, "Couldn't attach to pm_domain: %d\n", ret);
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2384) 			goto err;
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2385) 		}
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2386) 
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2387) 		opp_table->genpd_virt_devs[index] = virt_dev;
baea35e4db17a drivers/opp/core.c            (Viresh Kumar              2019-07-17 11:20:17 +0530 2388) 		index++;
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2389) 		name++;
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2390) 	}
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2391) 
17a8f868ae3e8 drivers/opp/core.c            (Viresh Kumar              2019-07-08 11:24:56 +0530 2392) 	if (virt_devs)
17a8f868ae3e8 drivers/opp/core.c            (Viresh Kumar              2019-07-08 11:24:56 +0530 2393) 		*virt_devs = opp_table->genpd_virt_devs;
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2394) 	mutex_unlock(&opp_table->genpd_virt_dev_lock);
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2395) 
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2396) 	return opp_table;
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2397) 
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2398) err:
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2399) 	_opp_detach_genpd(opp_table);
c0ab9e0812da8 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:43:36 +0530 2400) unlock:
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2401) 	mutex_unlock(&opp_table->genpd_virt_dev_lock);
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2402) 
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2403) put_table:
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2404) 	dev_pm_opp_put_opp_table(opp_table);
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2405) 
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2406) 	return ERR_PTR(ret);
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2407) }
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2408) EXPORT_SYMBOL_GPL(dev_pm_opp_attach_genpd);
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2409) 
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2410) /**
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2411)  * dev_pm_opp_detach_genpd() - Detach genpd(s) from the device.
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2412)  * @opp_table: OPP table returned by dev_pm_opp_attach_genpd().
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2413)  *
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2414)  * This detaches the genpd(s), resets the virtual device pointers, and puts the
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2415)  * OPP table.
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2416)  */
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2417) void dev_pm_opp_detach_genpd(struct opp_table *opp_table)
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2418) {
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 2419) 	if (unlikely(!opp_table))
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 2420) 		return;
c7bf8758c955e drivers/opp/core.c            (Viresh Kumar              2020-11-06 12:16:52 +0530 2421) 
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2422) 	/*
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2423) 	 * Acquire genpd_virt_dev_lock to make sure virt_dev isn't getting
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2424) 	 * used in parallel.
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2425) 	 */
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2426) 	mutex_lock(&opp_table->genpd_virt_dev_lock);
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2427) 	_opp_detach_genpd(opp_table);
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2428) 	mutex_unlock(&opp_table->genpd_virt_dev_lock);
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2429) 
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2430) 	dev_pm_opp_put_opp_table(opp_table);
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2431) }
6319aee10e530 drivers/opp/core.c            (Viresh Kumar              2019-05-08 15:19:13 +0530 2432) EXPORT_SYMBOL_GPL(dev_pm_opp_detach_genpd);
4f018bc0e1cfd drivers/opp/core.c            (Viresh Kumar              2018-06-26 16:29:34 +0530 2433) 
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2434) static void devm_pm_opp_detach_genpd(void *data)
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2435) {
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2436) 	dev_pm_opp_detach_genpd(data);
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2437) }
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2438) 
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2439) /**
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2440)  * devm_pm_opp_attach_genpd - Attach genpd(s) for the device and save virtual
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2441)  *			      device pointer
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2442)  * @dev: Consumer device for which the genpd is getting attached.
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2443)  * @names: Null terminated array of pointers containing names of genpd to attach.
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2444)  * @virt_devs: Pointer to return the array of virtual devices.
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2445)  *
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2446)  * This is a resource-managed version of dev_pm_opp_attach_genpd().
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2447)  *
9edf48a4bfb75 drivers/opp/core.c            (Dmitry Osipenko           2021-03-14 19:33:59 +0300 2448)  * Return: 0 on success and errorno otherwise.
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2449)  */
9edf48a4bfb75 drivers/opp/core.c            (Dmitry Osipenko           2021-03-14 19:33:59 +0300 2450) int devm_pm_opp_attach_genpd(struct device *dev, const char **names,
9edf48a4bfb75 drivers/opp/core.c            (Dmitry Osipenko           2021-03-14 19:33:59 +0300 2451) 			     struct device ***virt_devs)
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2452) {
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2453) 	struct opp_table *opp_table;
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2454) 
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2455) 	opp_table = dev_pm_opp_attach_genpd(dev, names, virt_devs);
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2456) 	if (IS_ERR(opp_table))
9edf48a4bfb75 drivers/opp/core.c            (Dmitry Osipenko           2021-03-14 19:33:59 +0300 2457) 		return PTR_ERR(opp_table);
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2458) 
9edf48a4bfb75 drivers/opp/core.c            (Dmitry Osipenko           2021-03-14 19:33:59 +0300 2459) 	return devm_add_action_or_reset(dev, devm_pm_opp_detach_genpd,
9edf48a4bfb75 drivers/opp/core.c            (Dmitry Osipenko           2021-03-14 19:33:59 +0300 2460) 					opp_table);
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2461) }
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2462) EXPORT_SYMBOL_GPL(devm_pm_opp_attach_genpd);
b4b9e223eccae drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:21 +0300 2463) 
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2464) /**
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2465)  * dev_pm_opp_xlate_required_opp() - Find required OPP for @src_table OPP.
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2466)  * @src_table: OPP table which has @dst_table as one of its required OPP table.
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2467)  * @dst_table: Required OPP table of the @src_table.
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2468)  * @src_opp: OPP from the @src_table.
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2469)  *
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2470)  * This function returns the OPP (present in @dst_table) pointed out by the
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2471)  * "required-opps" property of the @src_opp (present in @src_table).
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2472)  *
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2473)  * The callers are required to call dev_pm_opp_put() for the returned OPP after
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2474)  * use.
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2475)  *
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2476)  * Return: pointer to 'struct dev_pm_opp' on success and errorno otherwise.
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2477)  */
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2478) struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table,
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2479) 						 struct opp_table *dst_table,
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2480) 						 struct dev_pm_opp *src_opp)
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2481) {
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2482) 	struct dev_pm_opp *opp, *dest_opp = ERR_PTR(-ENODEV);
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2483) 	int i;
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2484) 
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2485) 	if (!src_table || !dst_table || !src_opp ||
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2486) 	    !src_table->required_opp_tables)
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2487) 		return ERR_PTR(-EINVAL);
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2488) 
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2489) 	/* required-opps not fully initialized yet */
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2490) 	if (lazy_linking_pending(src_table))
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2491) 		return ERR_PTR(-EBUSY);
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2492) 
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2493) 	for (i = 0; i < src_table->required_opp_count; i++) {
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2494) 		if (src_table->required_opp_tables[i] == dst_table) {
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2495) 			mutex_lock(&src_table->lock);
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2496) 
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2497) 			list_for_each_entry(opp, &src_table->opp_list, node) {
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2498) 				if (opp == src_opp) {
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2499) 					dest_opp = opp->required_opps[i];
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2500) 					dev_pm_opp_get(dest_opp);
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2501) 					break;
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2502) 				}
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2503) 			}
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2504) 
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2505) 			mutex_unlock(&src_table->lock);
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2506) 			break;
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2507) 		}
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2508) 	}
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2509) 
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2510) 	if (IS_ERR(dest_opp)) {
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2511) 		pr_err("%s: Couldn't find matching OPP (%p: %p)\n", __func__,
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2512) 		       src_table, dst_table);
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2513) 	}
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2514) 
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2515) 	return dest_opp;
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2516) }
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2517) EXPORT_SYMBOL_GPL(dev_pm_opp_xlate_required_opp);
7d8658ef65a4f drivers/opp/core.c            (Saravana Kannan           2021-02-04 16:14:22 +0800 2518) 
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2519) /**
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2520)  * dev_pm_opp_xlate_performance_state() - Find required OPP's pstate for src_table.
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2521)  * @src_table: OPP table which has dst_table as one of its required OPP table.
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2522)  * @dst_table: Required OPP table of the src_table.
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2523)  * @pstate: Current performance state of the src_table.
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2524)  *
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2525)  * This Returns pstate of the OPP (present in @dst_table) pointed out by the
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2526)  * "required-opps" property of the OPP (present in @src_table) which has
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2527)  * performance state set to @pstate.
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2528)  *
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2529)  * Return: Zero or positive performance state on success, otherwise negative
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2530)  * value on errors.
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2531)  */
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2532) int dev_pm_opp_xlate_performance_state(struct opp_table *src_table,
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2533) 				       struct opp_table *dst_table,
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2534) 				       unsigned int pstate)
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2535) {
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2536) 	struct dev_pm_opp *opp;
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2537) 	int dest_pstate = -EINVAL;
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2538) 	int i;
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2539) 
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2540) 	/*
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2541) 	 * Normally the src_table will have the "required_opps" property set to
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2542) 	 * point to one of the OPPs in the dst_table, but in some cases the
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2543) 	 * genpd and its master have one to one mapping of performance states
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2544) 	 * and so none of them have the "required-opps" property set. Return the
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2545) 	 * pstate of the src_table as it is in such cases.
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2546) 	 */
f2f4d2b86f432 drivers/opp/core.c            (Dmitry Osipenko           2021-01-18 03:55:23 +0300 2547) 	if (!src_table || !src_table->required_opp_count)
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2548) 		return pstate;
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2549) 
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 2550) 	/* required-opps not fully initialized yet */
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 2551) 	if (lazy_linking_pending(src_table))
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 2552) 		return -EBUSY;
7eba0c7641b00 drivers/opp/core.c            (Viresh Kumar              2019-11-25 13:57:58 +0530 2553) 
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2554) 	for (i = 0; i < src_table->required_opp_count; i++) {
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2555) 		if (src_table->required_opp_tables[i]->np == dst_table->np)
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2556) 			break;
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2557) 	}
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2558) 
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2559) 	if (unlikely(i == src_table->required_opp_count)) {
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2560) 		pr_err("%s: Couldn't find matching OPP table (%p: %p)\n",
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2561) 		       __func__, src_table, dst_table);
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2562) 		return -EINVAL;
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2563) 	}
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2564) 
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2565) 	mutex_lock(&src_table->lock);
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2566) 
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2567) 	list_for_each_entry(opp, &src_table->opp_list, node) {
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2568) 		if (opp->pstate == pstate) {
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2569) 			dest_pstate = opp->required_opps[i]->pstate;
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2570) 			goto unlock;
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2571) 		}
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2572) 	}
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2573) 
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2574) 	pr_err("%s: Couldn't find matching OPP (%p: %p)\n", __func__, src_table,
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2575) 	       dst_table);
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2576) 
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2577) unlock:
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2578) 	mutex_unlock(&src_table->lock);
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2579) 
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2580) 	return dest_pstate;
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2581) }
c8a59103e22b1 drivers/opp/core.c            (Viresh Kumar              2018-11-02 14:36:42 +0530 2582) 
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2583) /**
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2584)  * dev_pm_opp_add()  - Add an OPP table from a table definitions
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2585)  * @dev:	device for which we do this operation
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2586)  * @freq:	Frequency in Hz for this OPP
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2587)  * @u_volt:	Voltage in uVolts for this OPP
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2588)  *
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 2589)  * This function adds an opp definition to the opp table and returns status.
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2590)  * The opp is made available by default and it can be controlled using
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2591)  * dev_pm_opp_enable/disable functions.
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2592)  *
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2593)  * Return:
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 2594)  * 0		On success OR
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2595)  *		Duplicate OPPs (both freq and volt are same) and opp->available
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 2596)  * -EEXIST	Freq are same and volt are different OR
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2597)  *		Duplicate OPPs (both freq and volt are same) and !opp->available
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 2598)  * -ENOMEM	Memory allocation failure
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2599)  */
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2600) int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt)
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2601) {
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 2602) 	struct opp_table *opp_table;
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 2603) 	int ret;
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 2604) 
32439ac7535a8 drivers/opp/core.c            (Viresh Kumar              2021-01-28 12:05:22 +0530 2605) 	opp_table = _add_opp_table(dev, true);
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 2606) 	if (IS_ERR(opp_table))
dd461cd9183fe drivers/opp/core.c            (Stephan Gerhold           2020-07-27 11:30:46 +0200 2607) 		return PTR_ERR(opp_table);
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 2608) 
46f48aca2e5ae drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:39:36 +0530 2609) 	/* Fix regulator count for dynamic OPPs */
46f48aca2e5ae drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:39:36 +0530 2610) 	opp_table->regulator_count = 1;
46f48aca2e5ae drivers/opp/core.c            (Viresh Kumar              2018-12-11 16:39:36 +0530 2611) 
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 2612) 	ret = _opp_add_v1(opp_table, dev, freq, u_volt, true);
0ad8c623907c2 drivers/opp/core.c            (Viresh Kumar              2018-08-02 14:23:09 +0530 2613) 	if (ret)
0ad8c623907c2 drivers/opp/core.c            (Viresh Kumar              2018-08-02 14:23:09 +0530 2614) 		dev_pm_opp_put_opp_table(opp_table);
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 2615) 
8cd2f6e8f34e7 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:01 +0530 2616) 	return ret;
38393409da345 drivers/base/power/opp.c      (Viresh Kumar              2014-11-25 16:04:18 +0530 2617) }
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500 2618) EXPORT_SYMBOL_GPL(dev_pm_opp_add);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2619) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2620) /**
327854c871178 drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:56 -0600 2621)  * _opp_set_availability() - helper to set the availability of an opp
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2622)  * @dev:		device for which we do this operation
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2623)  * @freq:		OPP frequency to modify availability
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2624)  * @availability_req:	availability status requested for this opp
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2625)  *
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 2626)  * Set the availability of an OPP, opp_{enable,disable} share a common logic
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 2627)  * which is isolated here.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2628)  *
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 2629)  * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the
e1a2d49cd5ef5 drivers/base/power/opp.c      (Stephen Boyd              2015-09-24 12:28:44 -0700 2630)  * copy operation, returns 0 if no modification was done OR modification was
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2631)  * successful.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2632)  */
327854c871178 drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:56 -0600 2633) static int _opp_set_availability(struct device *dev, unsigned long freq,
327854c871178 drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:56 -0600 2634) 				 bool availability_req)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2635) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 2636) 	struct opp_table *opp_table;
a7f3987ea1af0 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:50 +0530 2637) 	struct dev_pm_opp *tmp_opp, *opp = ERR_PTR(-ENODEV);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2638) 	int r = 0;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2639) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 2640) 	/* Find the opp_table */
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 2641) 	opp_table = _find_opp_table(dev);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 2642) 	if (IS_ERR(opp_table)) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 2643) 		r = PTR_ERR(opp_table);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2644) 		dev_warn(dev, "%s: Device OPP not found (%d)\n", __func__, r);
a7f3987ea1af0 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:50 +0530 2645) 		return r;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2646) 	}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2647) 
37a73ec0c9bbd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:41 +0530 2648) 	mutex_lock(&opp_table->lock);
37a73ec0c9bbd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:41 +0530 2649) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2650) 	/* Do we have the frequency? */
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 2651) 	list_for_each_entry(tmp_opp, &opp_table->opp_list, node) {
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2652) 		if (tmp_opp->rate == freq) {
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2653) 			opp = tmp_opp;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2654) 			break;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2655) 		}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2656) 	}
37a73ec0c9bbd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:41 +0530 2657) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2658) 	if (IS_ERR(opp)) {
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2659) 		r = PTR_ERR(opp);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2660) 		goto unlock;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2661) 	}
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2662) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2663) 	/* Is update really needed? */
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2664) 	if (opp->available == availability_req)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2665) 		goto unlock;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2666) 
a7f3987ea1af0 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:50 +0530 2667) 	opp->available = availability_req;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2668) 
e4d8ae00169f7 drivers/base/power/opp/core.c (Viresh Kumar              2017-09-21 10:44:36 -0700 2669) 	dev_pm_opp_get(opp);
e4d8ae00169f7 drivers/base/power/opp/core.c (Viresh Kumar              2017-09-21 10:44:36 -0700 2670) 	mutex_unlock(&opp_table->lock);
e4d8ae00169f7 drivers/base/power/opp/core.c (Viresh Kumar              2017-09-21 10:44:36 -0700 2671) 
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 2672) 	/* Notify the change of the OPP availability */
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 2673) 	if (availability_req)
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 2674) 		blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ENABLE,
a7f3987ea1af0 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:50 +0530 2675) 					     opp);
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 2676) 	else
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 2677) 		blocking_notifier_call_chain(&opp_table->head,
a7f3987ea1af0 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:50 +0530 2678) 					     OPP_EVENT_DISABLE, opp);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2679) 
e4d8ae00169f7 drivers/base/power/opp/core.c (Viresh Kumar              2017-09-21 10:44:36 -0700 2680) 	dev_pm_opp_put(opp);
e4d8ae00169f7 drivers/base/power/opp/core.c (Viresh Kumar              2017-09-21 10:44:36 -0700 2681) 	goto put_table;
e4d8ae00169f7 drivers/base/power/opp/core.c (Viresh Kumar              2017-09-21 10:44:36 -0700 2682) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2683) unlock:
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 2684) 	mutex_unlock(&opp_table->lock);
e4d8ae00169f7 drivers/base/power/opp/core.c (Viresh Kumar              2017-09-21 10:44:36 -0700 2685) put_table:
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 2686) 	dev_pm_opp_put_opp_table(opp_table);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2687) 	return r;
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2688) }
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2689) 
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2690) /**
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2691)  * dev_pm_opp_adjust_voltage() - helper to change the voltage of an OPP
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2692)  * @dev:		device for which we do this operation
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2693)  * @freq:		OPP frequency to adjust voltage of
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2694)  * @u_volt:		new OPP target voltage
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2695)  * @u_volt_min:		new OPP min voltage
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2696)  * @u_volt_max:		new OPP max voltage
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2697)  *
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2698)  * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2699)  * copy operation, returns 0 if no modifcation was done OR modification was
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2700)  * successful.
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2701)  */
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2702) int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2703) 			      unsigned long u_volt, unsigned long u_volt_min,
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2704) 			      unsigned long u_volt_max)
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2705) 
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2706) {
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2707) 	struct opp_table *opp_table;
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2708) 	struct dev_pm_opp *tmp_opp, *opp = ERR_PTR(-ENODEV);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2709) 	int r = 0;
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2710) 
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2711) 	/* Find the opp_table */
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2712) 	opp_table = _find_opp_table(dev);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2713) 	if (IS_ERR(opp_table)) {
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2714) 		r = PTR_ERR(opp_table);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2715) 		dev_warn(dev, "%s: Device OPP not found (%d)\n", __func__, r);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2716) 		return r;
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2717) 	}
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2718) 
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2719) 	mutex_lock(&opp_table->lock);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2720) 
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2721) 	/* Do we have the frequency? */
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2722) 	list_for_each_entry(tmp_opp, &opp_table->opp_list, node) {
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2723) 		if (tmp_opp->rate == freq) {
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2724) 			opp = tmp_opp;
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2725) 			break;
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2726) 		}
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2727) 	}
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2728) 
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2729) 	if (IS_ERR(opp)) {
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2730) 		r = PTR_ERR(opp);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2731) 		goto adjust_unlock;
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2732) 	}
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2733) 
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2734) 	/* Is update really needed? */
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2735) 	if (opp->supplies->u_volt == u_volt)
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2736) 		goto adjust_unlock;
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2737) 
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2738) 	opp->supplies->u_volt = u_volt;
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2739) 	opp->supplies->u_volt_min = u_volt_min;
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2740) 	opp->supplies->u_volt_max = u_volt_max;
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2741) 
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2742) 	dev_pm_opp_get(opp);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2743) 	mutex_unlock(&opp_table->lock);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2744) 
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2745) 	/* Notify the voltage change of the OPP */
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2746) 	blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADJUST_VOLTAGE,
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2747) 				     opp);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2748) 
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2749) 	dev_pm_opp_put(opp);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2750) 	goto adjust_put_table;
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2751) 
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2752) adjust_unlock:
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2753) 	mutex_unlock(&opp_table->lock);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2754) adjust_put_table:
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2755) 	dev_pm_opp_put_opp_table(opp_table);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2756) 	return r;
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2757) }
036491542aa47 drivers/opp/core.c            (Valdis Kletnieks          2020-06-20 13:03:22 -0400 2758) EXPORT_SYMBOL_GPL(dev_pm_opp_adjust_voltage);
25cb20a212a1f drivers/opp/core.c            (Stephen Boyd              2019-10-16 16:57:53 +0200 2759) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2760) /**
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500 2761)  * dev_pm_opp_enable() - Enable a specific OPP
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2762)  * @dev:	device for which we do this operation
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2763)  * @freq:	OPP frequency to enable
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2764)  *
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2765)  * Enables a provided opp. If the operation is valid, this returns 0, else the
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2766)  * corresponding error value. It is meant to be used for users an OPP available
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500 2767)  * after being temporarily made unavailable with dev_pm_opp_disable.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2768)  *
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 2769)  * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the
e1a2d49cd5ef5 drivers/base/power/opp.c      (Stephen Boyd              2015-09-24 12:28:44 -0700 2770)  * copy operation, returns 0 if no modification was done OR modification was
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 2771)  * successful.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2772)  */
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500 2773) int dev_pm_opp_enable(struct device *dev, unsigned long freq)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2774) {
327854c871178 drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:56 -0600 2775) 	return _opp_set_availability(dev, freq, true);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2776) }
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500 2777) EXPORT_SYMBOL_GPL(dev_pm_opp_enable);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2778) 
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2779) /**
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500 2780)  * dev_pm_opp_disable() - Disable a specific OPP
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2781)  * @dev:	device for which we do this operation
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2782)  * @freq:	OPP frequency to disable
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2783)  *
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2784)  * Disables a provided opp. If the operation is valid, this returns
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2785)  * 0, else the corresponding error value. It is meant to be a temporary
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2786)  * control by users to make this OPP not available until the circumstances are
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500 2787)  * right to make it available again (with a call to dev_pm_opp_enable).
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2788)  *
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 2789)  * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the
e1a2d49cd5ef5 drivers/base/power/opp.c      (Stephen Boyd              2015-09-24 12:28:44 -0700 2790)  * copy operation, returns 0 if no modification was done OR modification was
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 2791)  * successful.
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2792)  */
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500 2793) int dev_pm_opp_disable(struct device *dev, unsigned long freq)
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2794) {
327854c871178 drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:56 -0600 2795) 	return _opp_set_availability(dev, freq, false);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2796) }
5d4879cda67b0 drivers/base/power/opp.c      (Nishanth Menon            2013-09-19 16:03:50 -0500 2797) EXPORT_SYMBOL_GPL(dev_pm_opp_disable);
e1f60b292ffd6 drivers/base/power/opp.c      (Nishanth Menon            2010-10-13 00:13:10 +0200 2798) 
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 2799) /**
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2800)  * dev_pm_opp_register_notifier() - Register OPP notifier for the device
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2801)  * @dev:	Device for which notifier needs to be registered
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2802)  * @nb:		Notifier block to be registered
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 2803)  *
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2804)  * Return: 0 on success or a negative error value.
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2805)  */
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2806) int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2807) {
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2808) 	struct opp_table *opp_table;
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2809) 	int ret;
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2810) 
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2811) 	opp_table = _find_opp_table(dev);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 2812) 	if (IS_ERR(opp_table))
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 2813) 		return PTR_ERR(opp_table);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 2814) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 2815) 	ret = blocking_notifier_chain_register(&opp_table->head, nb);
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2816) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 2817) 	dev_pm_opp_put_opp_table(opp_table);
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2818) 
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2819) 	return ret;
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2820) }
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2821) EXPORT_SYMBOL(dev_pm_opp_register_notifier);
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2822) 
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2823) /**
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2824)  * dev_pm_opp_unregister_notifier() - Unregister OPP notifier for the device
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2825)  * @dev:	Device for which notifier needs to be unregistered
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2826)  * @nb:		Notifier block to be unregistered
984f16c8490cb drivers/base/power/opp.c      (Nishanth Menon            2014-12-24 11:22:57 -0600 2827)  *
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2828)  * Return: 0 on success or a negative error value.
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 2829)  */
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2830) int dev_pm_opp_unregister_notifier(struct device *dev,
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2831) 				   struct notifier_block *nb)
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 2832) {
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2833) 	struct opp_table *opp_table;
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2834) 	int ret;
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 2835) 
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2836) 	opp_table = _find_opp_table(dev);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 2837) 	if (IS_ERR(opp_table))
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 2838) 		return PTR_ERR(opp_table);
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2839) 
052c6f19141dd drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:49 +0530 2840) 	ret = blocking_notifier_chain_unregister(&opp_table->head, nb);
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 2841) 
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 2842) 	dev_pm_opp_put_opp_table(opp_table);
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2843) 
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2844) 	return ret;
03ca370fbf7b7 drivers/base/power/opp.c      (MyungJoo Ham              2011-09-30 22:35:12 +0200 2845) }
dc2c9ad52af45 drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:03 +0530 2846) EXPORT_SYMBOL(dev_pm_opp_unregister_notifier);
b496dfbc94ab8 drivers/base/power/opp.c      (Shawn Guo                 2012-09-05 01:09:12 +0200 2847) 
8aaf6264fc7fd drivers/opp/core.c            (Viresh Kumar              2020-08-20 13:18:23 +0530 2848) /**
8aaf6264fc7fd drivers/opp/core.c            (Viresh Kumar              2020-08-20 13:18:23 +0530 2849)  * dev_pm_opp_remove_table() - Free all OPPs associated with the device
8aaf6264fc7fd drivers/opp/core.c            (Viresh Kumar              2020-08-20 13:18:23 +0530 2850)  * @dev:	device pointer used to lookup OPP table.
8aaf6264fc7fd drivers/opp/core.c            (Viresh Kumar              2020-08-20 13:18:23 +0530 2851)  *
8aaf6264fc7fd drivers/opp/core.c            (Viresh Kumar              2020-08-20 13:18:23 +0530 2852)  * Free both OPPs created using static entries present in DT and the
8aaf6264fc7fd drivers/opp/core.c            (Viresh Kumar              2020-08-20 13:18:23 +0530 2853)  * dynamically added entries.
8aaf6264fc7fd drivers/opp/core.c            (Viresh Kumar              2020-08-20 13:18:23 +0530 2854)  */
8aaf6264fc7fd drivers/opp/core.c            (Viresh Kumar              2020-08-20 13:18:23 +0530 2855) void dev_pm_opp_remove_table(struct device *dev)
9274c892430ef drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:00 +0530 2856) {
9274c892430ef drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:00 +0530 2857) 	struct opp_table *opp_table;
9274c892430ef drivers/base/power/opp/core.c (Viresh Kumar              2017-01-02 14:41:00 +0530 2858) 
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 2859) 	/* Check for existing table for 'dev' */
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 2860) 	opp_table = _find_opp_table(dev);
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 2861) 	if (IS_ERR(opp_table)) {
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 2862) 		int error = PTR_ERR(opp_table);
737002b5de3d1 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:22:58 +0530 2863) 
737002b5de3d1 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:22:58 +0530 2864) 		if (error != -ENODEV)
2c2709dc6921c drivers/base/power/opp/core.c (Viresh Kumar              2016-02-16 14:17:53 +0530 2865) 			WARN(1, "%s: opp_table: %d\n",
737002b5de3d1 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:22:58 +0530 2866) 			     IS_ERR_OR_NULL(dev) ?
737002b5de3d1 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:22:58 +0530 2867) 					"Invalid device" : dev_name(dev),
737002b5de3d1 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:22:58 +0530 2868) 			     error);
5b650b388844f drivers/base/power/opp/core.c (Viresh Kumar              2017-01-23 10:11:48 +0530 2869) 		return;
737002b5de3d1 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:22:58 +0530 2870) 	}
737002b5de3d1 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:22:58 +0530 2871) 
922ff0759a162 drivers/opp/core.c            (Viresh Kumar              2020-08-31 13:03:06 +0530 2872) 	/*
922ff0759a162 drivers/opp/core.c            (Viresh Kumar              2020-08-31 13:03:06 +0530 2873) 	 * Drop the extra reference only if the OPP table was successfully added
922ff0759a162 drivers/opp/core.c            (Viresh Kumar              2020-08-31 13:03:06 +0530 2874) 	 * with dev_pm_opp_of_add_table() earlier.
922ff0759a162 drivers/opp/core.c            (Viresh Kumar              2020-08-31 13:03:06 +0530 2875) 	 **/
922ff0759a162 drivers/opp/core.c            (Viresh Kumar              2020-08-31 13:03:06 +0530 2876) 	if (_opp_remove_all_static(opp_table))
922ff0759a162 drivers/opp/core.c            (Viresh Kumar              2020-08-31 13:03:06 +0530 2877) 		dev_pm_opp_put_opp_table(opp_table);
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 2878) 
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 2879) 	/* Drop reference taken by _find_opp_table() */
cdd6ed90cdb6c drivers/opp/core.c            (Viresh Kumar              2018-09-12 12:35:19 +0530 2880) 	dev_pm_opp_put_opp_table(opp_table);
737002b5de3d1 drivers/base/power/opp.c      (Viresh Kumar              2015-07-29 16:22:58 +0530 2881) }
411466c5081d2 drivers/base/power/opp/core.c (Sudeep Holla              2016-05-03 15:05:04 +0100 2882) EXPORT_SYMBOL_GPL(dev_pm_opp_remove_table);
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2883) 
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2884) /**
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2885)  * dev_pm_opp_sync_regulators() - Sync state of voltage regulators
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2886)  * @dev:	device for which we do this operation
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2887)  *
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2888)  * Sync voltage state of the OPP table regulators.
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2889)  *
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2890)  * Return: 0 on success or a negative error value.
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2891)  */
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2892) int dev_pm_opp_sync_regulators(struct device *dev)
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2893) {
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2894) 	struct opp_table *opp_table;
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2895) 	struct regulator *reg;
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2896) 	int i, ret = 0;
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2897) 
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2898) 	/* Device may not have OPP table */
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2899) 	opp_table = _find_opp_table(dev);
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2900) 	if (IS_ERR(opp_table))
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2901) 		return 0;
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2902) 
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2903) 	/* Regulator may not be required for the device */
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2904) 	if (unlikely(!opp_table->regulators))
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2905) 		goto put_table;
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2906) 
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2907) 	/* Nothing to sync if voltage wasn't changed */
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2908) 	if (!opp_table->enabled)
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2909) 		goto put_table;
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2910) 
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2911) 	for (i = 0; i < opp_table->regulator_count; i++) {
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2912) 		reg = opp_table->regulators[i];
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2913) 		ret = regulator_sync_voltage(reg);
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2914) 		if (ret)
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2915) 			break;
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2916) 	}
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2917) put_table:
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2918) 	/* Drop reference taken by _find_opp_table() */
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2919) 	dev_pm_opp_put_opp_table(opp_table);
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2920) 
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2921) 	return ret;
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2922) }
ce8073d83f63a drivers/opp/core.c            (Dmitry Osipenko           2021-01-21 01:26:47 +0300 2923) EXPORT_SYMBOL_GPL(dev_pm_opp_sync_regulators);