Lines Matching refs:opp

23 #include "opp.h"
26 * The root of the list of all opp-tables. All opp_table structures branch off
32 /* Lock to allow exclusive modification to the device and opp lists */
110 * dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp
111 * @opp: opp for which voltage has to be returned for
113 * Return: voltage in micro volt corresponding to the opp, else
118 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
120 if (IS_ERR_OR_NULL(opp)) {
125 return opp->supplies[0].u_volt;
130 * dev_pm_opp_get_supplies() - Gets the supply information corresponding to an opp
131 * @opp: opp for which voltage has to be returned for
140 int dev_pm_opp_get_supplies(struct dev_pm_opp *opp,
143 if (IS_ERR_OR_NULL(opp) || !supplies) {
148 memcpy(supplies, opp->supplies,
149 sizeof(*supplies) * opp->opp_table->regulator_count);
155 * dev_pm_opp_get_power() - Gets the power corresponding to an opp
156 * @opp: opp for which power has to be returned for
158 * Return: power in micro watt corresponding to the opp, else
163 unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp)
168 if (IS_ERR_OR_NULL(opp)) {
172 for (i = 0; i < opp->opp_table->regulator_count; i++)
173 opp_power += opp->supplies[i].u_watt;
181 * available opp with specified index
182 * @opp: opp for which frequency has to be returned for
183 * @index: index of the frequency within the required opp
185 * Return: frequency in hertz corresponding to the opp with specified index,
188 unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index)
190 if (IS_ERR_OR_NULL(opp) || index >= opp->opp_table->clk_count) {
195 return opp->rates[index];
200 * dev_pm_opp_get_level() - Gets the level corresponding to an available opp
201 * @opp: opp for which level value has to be returned for
203 * Return: level read from device tree corresponding to the opp, else
206 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
208 if (IS_ERR_OR_NULL(opp) || !opp->available) {
213 return opp->level;
219 * corresponding to an available opp
220 * @opp: opp for which performance state has to be returned for
221 * @index: index of the required opp
224 * required opp, else return 0.
226 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
229 if (IS_ERR_OR_NULL(opp) || !opp->available ||
230 index >= opp->opp_table->required_opp_count) {
236 if (lazy_linking_pending(opp->opp_table))
240 if (unlikely(!opp->opp_table->required_opp_tables[index]->is_genpd)) {
245 return opp->required_opps[index]->level;
250 * dev_pm_opp_is_turbo() - Returns if opp is turbo OPP or not
251 * @opp: opp for which turbo mode is being verified
257 * Return: true if opp is turbo opp, else false.
259 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
261 if (IS_ERR_OR_NULL(opp) || !opp->available) {
266 return opp->turbo;
302 struct dev_pm_opp *opp;
331 list_for_each_entry(opp, &opp_table->opp_list, node) {
332 if (!opp->available)
335 if (opp->supplies[i].u_volt_min < uV[i].min)
336 uV[i].min = opp->supplies[i].u_volt_min;
337 if (opp->supplies[i].u_volt_max > uV[i].max)
338 uV[i].max = opp->supplies[i].u_volt_max;
379 * dev_pm_opp_get_suspend_opp_freq() - Get frequency of suspend opp in Hz
405 struct dev_pm_opp *opp;
410 list_for_each_entry(opp, &opp_table->opp_list, node) {
411 if (opp->available)
421 * dev_pm_opp_get_opp_count() - Get number of opps available in the opp table
448 static unsigned long _read_freq(struct dev_pm_opp *opp, int index)
450 return opp->rates[index];
453 static unsigned long _read_level(struct dev_pm_opp *opp, int index)
455 return opp->level;
458 static unsigned long _read_bw(struct dev_pm_opp *opp, int index)
460 return opp->bandwidth[index].peak;
464 static bool _compare_exact(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp,
468 *opp = temp_opp;
475 static bool _compare_ceil(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp,
479 *opp = temp_opp;
486 static bool _compare_floor(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp,
492 *opp = temp_opp;
499 unsigned long (*read)(struct dev_pm_opp *opp, int index),
500 bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp,
504 struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
514 if (compare(&opp, temp_opp, read(temp_opp, index), *key))
520 if (!IS_ERR(opp)) {
521 *key = read(opp, index);
522 dev_pm_opp_get(opp);
527 return opp;
532 unsigned long (*read)(struct dev_pm_opp *opp, int index),
533 bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp,
538 struct dev_pm_opp *opp;
547 opp = _opp_table_find_key(opp_table, key, index, available, read,
552 return opp;
557 unsigned long (*read)(struct dev_pm_opp *opp, int index),
570 unsigned long (*read)(struct dev_pm_opp *opp, int index),
579 unsigned long (*read)(struct dev_pm_opp *opp, int index),
588 unsigned long (*read)(struct dev_pm_opp *opp, int index),
599 * @available: true/false - match for available opp
601 * Return: Searches for exact match in the opp table and returns pointer to the
602 * matching opp if found, else returns ERR_PTR in case of error and should
612 * This provides a mechanism to enable an opp which is not available currently
632 * @available: true/false - match for available opp
637 * Return: matching *opp , else returns ERR_PTR in case of error and should be
669 * Return: matching *opp and refreshes *freq accordingly, else returns
696 * Return: matching *opp and refreshes *freq accordingly, else returns
722 * Return: matching *opp and refreshes *freq accordingly, else returns
749 * Return: matching *opp and refreshes *freq accordingly, else returns
772 * Return: Searches for exact match in the opp table and returns pointer to the
773 * matching opp if found, else returns ERR_PTR in case of error and should
794 * Return: Searches for rounded up match in the opp table and returns pointer
795 * to the matching opp if found, else returns ERR_PTR in case of error and
808 struct dev_pm_opp *opp;
810 opp = _find_key_ceil(dev, &temp, 0, true, _read_level, NULL);
812 return opp;
825 * Return: matching *opp and refreshes *bw accordingly, else returns
839 struct dev_pm_opp *opp;
841 opp = _find_key_ceil(dev, &temp, index, true, _read_bw, NULL);
843 return opp;
856 * Return: matching *opp and refreshes *bw accordingly, else returns
870 struct dev_pm_opp *opp;
872 opp = _find_key_floor(dev, &temp, index, true, _read_bw, NULL);
874 return opp;
905 struct dev_pm_opp *opp, void *data, bool scaling_down)
911 /* One of target and opp must be available */
914 } else if (opp) {
915 freq = opp->rates[0];
937 struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
944 ret = clk_set_rate(opp_table->clks[i], opp->rates[i]);
953 ret = clk_set_rate(opp_table->clks[i], opp->rates[i]);
997 struct dev_pm_opp *opp, struct device *dev)
1006 if (!opp) {
1010 avg = opp->bandwidth[i].avg;
1011 peak = opp->bandwidth[i].peak;
1016 opp ? "set" : "remove", i, ret);
1025 struct dev_pm_opp *opp, int i)
1027 unsigned int pstate = likely(opp) ? opp->required_opps[i]->level: 0;
1043 struct opp_table *opp_table, struct dev_pm_opp *opp, bool scaling_down)
1050 struct opp_table *opp_table, struct dev_pm_opp *opp, bool scaling_down)
1065 ret = _set_performance_state(dev, genpd_virt_devs[i], opp, i);
1071 ret = _set_performance_state(dev, genpd_virt_devs[i], opp, i);
1084 struct dev_pm_opp *opp, bool up)
1091 return opp_table->set_required_opps(dev, opp_table, opp, up);
1112 struct dev_pm_opp *opp = ERR_PTR(-ENODEV);
1117 opp = _find_freq_ceil(opp_table, &freq);
1125 if (IS_ERR(opp)) {
1127 opp = list_first_entry(&opp_table->opp_list, struct dev_pm_opp, node);
1128 dev_pm_opp_get(opp);
1132 opp_table->current_opp = opp;
1164 struct dev_pm_opp *opp, void *clk_data, bool forced)
1169 if (unlikely(!opp))
1179 if (!forced && old_opp == opp && opp_table->enabled) {
1185 __func__, old_opp->rates[0], opp->rates[0], old_opp->level,
1186 opp->level, old_opp->bandwidth ? old_opp->bandwidth[0].peak : 0,
1187 opp->bandwidth ? opp->bandwidth[0].peak : 0);
1189 scaling_down = _opp_compare_key(opp_table, old_opp, opp);
1195 ret = _set_required_opps(dev, opp_table, opp, true);
1201 ret = _set_opp_bw(opp_table, opp, dev);
1208 ret = opp_table->config_regulators(dev, old_opp, opp,
1220 ret = opp_table->config_clks(dev, opp_table, opp, clk_data, scaling_down);
1228 ret = opp_table->config_regulators(dev, old_opp, opp,
1238 ret = _set_opp_bw(opp_table, opp, dev);
1244 ret = _set_required_opps(dev, opp_table, opp, false);
1255 dev_pm_opp_get(opp);
1256 opp_table->current_opp = opp;
1269 * provided by the opp, should have already rounded to the target OPP's
1276 struct dev_pm_opp *opp = NULL;
1282 dev_err(dev, "%s: device's opp table doesn't exist\n", __func__);
1310 opp = _find_freq_ceil(opp_table, &temp_freq);
1311 if (IS_ERR(opp)) {
1312 ret = PTR_ERR(opp);
1328 ret = _set_opp(dev, opp_table, opp, &freq, forced);
1331 dev_pm_opp_put(opp);
1342 * @opp: OPP to set to
1349 int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp)
1356 dev_err(dev, "%s: device opp doesn't exist\n", __func__);
1360 ret = _set_opp(dev, opp_table, opp, NULL, false);
1385 /* Initialize opp-dev */
1491 * contain "opp-hz" property though, which we need to parse and
1496 * frequency in opp->rates and also parse the entries in DT.
1629 void _opp_free(struct dev_pm_opp *opp)
1631 kfree(opp);
1636 struct dev_pm_opp *opp = container_of(kref, struct dev_pm_opp, kref);
1637 struct opp_table *opp_table = opp->opp_table;
1639 list_del(&opp->node);
1646 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_REMOVE, opp);
1647 _of_clear_opp(opp_table, opp);
1648 opp_debug_remove_one(opp);
1649 kfree(opp);
1652 void dev_pm_opp_get(struct dev_pm_opp *opp)
1654 kref_get(&opp->kref);
1657 void dev_pm_opp_put(struct dev_pm_opp *opp)
1659 kref_put_mutex(&opp->kref, _opp_kref_release, &opp->opp_table->lock);
1668 * This function removes an opp from the opp table.
1672 struct dev_pm_opp *opp = NULL, *iter;
1686 opp = iter;
1693 if (opp) {
1694 dev_pm_opp_put(opp);
1712 struct dev_pm_opp *opp = NULL, *temp;
1721 opp = temp;
1727 return opp;
1737 struct dev_pm_opp *opp;
1739 while ((opp = _opp_get_next(opp_table, dynamic))) {
1740 opp->removed = true;
1741 dev_pm_opp_put(opp);
1773 * This function removes all dynamically created OPPs from the opp table.
1792 struct dev_pm_opp *opp;
1798 supply_size = sizeof(*opp->supplies) * supply_count;
1799 clk_size = sizeof(*opp->rates) * opp_table->clk_count;
1800 icc_size = sizeof(*opp->bandwidth) * opp_table->path_count;
1803 opp = kzalloc(sizeof(*opp) + supply_size + clk_size + icc_size, GFP_KERNEL);
1804 if (!opp)
1808 opp->supplies = (struct dev_pm_opp_supply *)(opp + 1);
1810 opp->rates = (unsigned long *)(opp->supplies + supply_count);
1813 opp->bandwidth = (struct dev_pm_opp_icc_bw *)(opp->rates + opp_table->clk_count);
1815 INIT_LIST_HEAD(&opp->node);
1817 return opp;
1820 static bool _opp_supported_by_regulators(struct dev_pm_opp *opp,
1833 opp->supplies[i].u_volt_min,
1834 opp->supplies[i].u_volt_max)) {
1836 __func__, opp->supplies[i].u_volt_min,
1837 opp->supplies[i].u_volt_max);
1903 struct dev_pm_opp *opp;
1914 list_for_each_entry(opp, &opp_table->opp_list, node) {
1915 opp_cmp = _opp_compare_key(opp_table, new_opp, opp);
1917 *head = &opp->node;
1926 __func__, opp->rates[0], opp->supplies[0].u_volt,
1927 opp->available, new_opp->rates[0],
1931 return opp->available &&
1932 new_opp->supplies[0].u_volt == opp->supplies[0].u_volt ? -EBUSY : -EEXIST;
1938 void _required_opps_available(struct dev_pm_opp *opp, int count)
1943 if (opp->required_opps[i]->available)
1946 opp->available = false;
1948 __func__, opp->required_opps[i]->np, opp->rates[0]);
2009 * This function adds an opp definition to the opp table and returns status.
2010 * The opp is made available by default and it can be controlled using
2018 * Duplicate OPPs (both freq and volt are same) and opp->available
2020 * Duplicate OPPs (both freq and volt are same) and !opp->available
2037 /* populate the opp table */
2075 * OPPs, which are available for those versions, based on its 'opp-supported-hw'
2119 * which the extension will apply are opp-microvolt and opp-microamp. OPP core
2456 dev_err(dev, "Index can't be greater than required-opp-count - 1, %s (%d : %d)\n",
2720 struct dev_pm_opp *opp, *dest_opp = ERR_PTR(-ENODEV);
2735 list_for_each_entry(opp, &src_table->opp_list, node) {
2736 if (opp == src_opp) {
2737 dest_opp = opp->required_opps[i];
2774 struct dev_pm_opp *opp;
2811 list_for_each_entry(opp, &src_table->opp_list, node) {
2812 if (opp->level == pstate) {
2813 dest_pstate = opp->required_opps[i]->level;
2833 * This function adds an opp definition to the opp table and returns status.
2834 * The opp is made available by default and it can be controlled using
2839 * Duplicate OPPs (both freq and volt are same) and opp->available
2841 * Duplicate OPPs (both freq and volt are same) and !opp->available
2865 * _opp_set_availability() - helper to set the availability of an opp
2868 * @availability_req: availability status requested for this opp
2881 struct dev_pm_opp *tmp_opp, *opp = ERR_PTR(-ENODEV);
2902 opp = tmp_opp;
2907 if (IS_ERR(opp)) {
2908 r = PTR_ERR(opp);
2913 if (opp->available == availability_req)
2916 opp->available = availability_req;
2918 dev_pm_opp_get(opp);
2924 opp);
2927 OPP_EVENT_DISABLE, opp);
2929 dev_pm_opp_put(opp);
2957 struct dev_pm_opp *tmp_opp, *opp = ERR_PTR(-ENODEV);
2978 opp = tmp_opp;
2983 if (IS_ERR(opp)) {
2984 r = PTR_ERR(opp);
2989 if (opp->supplies->u_volt == u_volt)
2992 opp->supplies->u_volt = u_volt;
2993 opp->supplies->u_volt_min = u_volt_min;
2994 opp->supplies->u_volt_max = u_volt_max;
2996 dev_pm_opp_get(opp);
3001 opp);
3003 dev_pm_opp_put(opp);
3019 * Enables a provided opp. If the operation is valid, this returns 0, else the
3038 * Disables a provided opp. If the operation is valid, this returns