14 #include <linux/kernel.h>
15 #include <linux/errno.h>
18 #include <linux/slab.h>
20 #include <linux/device.h>
21 #include <linux/list.h>
120 if (
unlikely(IS_ERR_OR_NULL(dev))) {
121 pr_err(
"%s: Invalid parameters\n", __func__);
125 list_for_each_entry_rcu(tmp_dev_opp, &dev_opp_list,
node) {
126 if (tmp_dev_opp->
dev == dev) {
127 dev_opp = tmp_dev_opp;
157 pr_err(
"%s: Invalid parameters\n", __func__);
186 pr_err(
"%s: Invalid parameters\n", __func__);
207 struct opp *temp_opp;
210 dev_opp = find_device_opp(dev);
211 if (IS_ERR(dev_opp)) {
212 int r = PTR_ERR(dev_opp);
213 dev_err(dev,
"%s: device OPP not found (%d)\n", __func__, r);
217 list_for_each_entry_rcu(temp_opp, &dev_opp->
opp_list,
node) {
254 dev_opp = find_device_opp(dev);
255 if (IS_ERR(dev_opp)) {
256 int r = PTR_ERR(dev_opp);
257 dev_err(dev,
"%s: device OPP not found (%d)\n", __func__, r);
261 list_for_each_entry_rcu(temp_opp, &dev_opp->
opp_list,
node) {
263 temp_opp->
rate == freq) {
295 dev_err(dev,
"%s: Invalid argument freq=%p\n", __func__, freq);
299 dev_opp = find_device_opp(dev);
303 list_for_each_entry_rcu(temp_opp, &dev_opp->
opp_list,
node) {
337 dev_err(dev,
"%s: Invalid argument freq=%p\n", __func__, freq);
341 dev_opp = find_device_opp(dev);
345 list_for_each_entry_rcu(temp_opp, &dev_opp->
opp_list,
node) {
348 if (temp_opp->
rate > *freq)
379 struct opp *
opp, *new_opp;
383 new_opp = kzalloc(
sizeof(
struct opp),
GFP_KERNEL);
385 dev_warn(dev,
"%s: Unable to create new OPP node\n", __func__);
393 dev_opp = find_device_opp(dev);
394 if (IS_ERR(dev_opp)) {
405 "%s: Unable to create device OPP structure\n",
415 list_add_rcu(&dev_opp->
node, &dev_opp_list);
426 list_for_each_entry_rcu(opp, &dev_opp->
opp_list,
node) {
433 list_add_rcu(&new_opp->
node, head);
463 static int opp_set_availability(
struct device *dev,
unsigned long freq,
464 bool availability_req)
473 dev_warn(dev,
"%s: Unable to create OPP\n", __func__);
481 if (dev == tmp_dev_opp->
dev) {
482 dev_opp = tmp_dev_opp;
486 if (IS_ERR(dev_opp)) {
487 r = PTR_ERR(dev_opp);
488 dev_warn(dev,
"%s: Device OPP not found (%d)\n", __func__, r);
494 if (tmp_opp->
rate == freq) {
513 list_replace_rcu(&opp->
node, &new_opp->
node);
518 if (availability_req)
553 return opp_set_availability(dev, freq,
true);
574 return opp_set_availability(dev, freq,
false);
577 #ifdef CONFIG_CPU_FREQ
602 int opp_init_cpufreq_table(
struct device *dev,
613 dev_opp = find_device_opp(dev);
614 if (IS_ERR(dev_opp)) {
615 int r = PTR_ERR(dev_opp);
617 dev_err(dev,
"%s: Device OPP not found (%d)\n", __func__, r);
625 dev_warn(dev,
"%s: Unable to allocate frequency table\n",
642 *table = &freq_table[0];
654 void opp_free_cpufreq_table(
struct device *dev,
671 struct device_opp *dev_opp = find_device_opp(dev);
674 return ERR_CAST(dev_opp);
676 return &dev_opp->
head;
686 int of_init_opp_table(
struct device *dev)
704 dev_err(dev,
"%s: Invalid OPP list\n", __func__);
713 if (
opp_add(dev, freq, volt)) {
714 dev_warn(dev,
"%s: Failed to add OPP %ld\n",