]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/devfreq/devfreq.c
Merge branches 'pm-core', 'pm-qos', 'pm-domains' and 'pm-opp'
[linux.git] / drivers / devfreq / devfreq.c
index 4e86cc0106df7598116f136ad6a55830fe4915b3..551a271353d2a49f98221a03af5c235405d50fe5 100644 (file)
@@ -111,18 +111,16 @@ static void devfreq_set_freq_table(struct devfreq *devfreq)
                return;
        }
 
-       rcu_read_lock();
        for (i = 0, freq = 0; i < profile->max_state; i++, freq++) {
                opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &freq);
                if (IS_ERR(opp)) {
                        devm_kfree(devfreq->dev.parent, profile->freq_table);
                        profile->max_state = 0;
-                       rcu_read_unlock();
                        return;
                }
+               dev_pm_opp_put(opp);
                profile->freq_table[i] = freq;
        }
-       rcu_read_unlock();
 }
 
 /**
@@ -475,11 +473,15 @@ static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type,
 }
 
 /**
- * _remove_devfreq() - Remove devfreq from the list and release its resources.
- * @devfreq:   the devfreq struct
+ * devfreq_dev_release() - Callback for struct device to release the device.
+ * @dev:       the devfreq device
+ *
+ * Remove devfreq from the list and release its resources.
  */
-static void _remove_devfreq(struct devfreq *devfreq)
+static void devfreq_dev_release(struct device *dev)
 {
+       struct devfreq *devfreq = to_devfreq(dev);
+
        mutex_lock(&devfreq_list_lock);
        if (IS_ERR(find_device_devfreq(devfreq->dev.parent))) {
                mutex_unlock(&devfreq_list_lock);
@@ -500,19 +502,6 @@ static void _remove_devfreq(struct devfreq *devfreq)
        kfree(devfreq);
 }
 
-/**
- * devfreq_dev_release() - Callback for struct device to release the device.
- * @dev:       the devfreq device
- *
- * This calls _remove_devfreq() if _remove_devfreq() is not called.
- */
-static void devfreq_dev_release(struct device *dev)
-{
-       struct devfreq *devfreq = to_devfreq(dev);
-
-       _remove_devfreq(devfreq);
-}
-
 /**
  * devfreq_add_device() - Add devfreq feature to the device
  * @dev:       the device to add devfreq feature.
@@ -528,6 +517,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
 {
        struct devfreq *devfreq;
        struct devfreq_governor *governor;
+       static atomic_t devfreq_no = ATOMIC_INIT(-1);
        int err = 0;
 
        if (!dev || !profile || !governor_name) {
@@ -569,7 +559,8 @@ struct devfreq *devfreq_add_device(struct device *dev,
                mutex_lock(&devfreq->lock);
        }
 
-       dev_set_name(&devfreq->dev, "%s", dev_name(dev));
+       dev_set_name(&devfreq->dev, "devfreq%d",
+                               atomic_inc_return(&devfreq_no));
        err = device_register(&devfreq->dev);
        if (err) {
                mutex_unlock(&devfreq->lock);
@@ -1137,17 +1128,16 @@ static ssize_t available_frequencies_show(struct device *d,
        ssize_t count = 0;
        unsigned long freq = 0;
 
-       rcu_read_lock();
        do {
                opp = dev_pm_opp_find_freq_ceil(dev, &freq);
                if (IS_ERR(opp))
                        break;
 
+               dev_pm_opp_put(opp);
                count += scnprintf(&buf[count], (PAGE_SIZE - count - 2),
                                   "%lu ", freq);
                freq++;
        } while (1);
-       rcu_read_unlock();
 
        /* Truncate the trailing space */
        if (count)
@@ -1249,11 +1239,8 @@ subsys_initcall(devfreq_init);
  * @freq:      The frequency given to target function
  * @flags:     Flags handed from devfreq framework.
  *
- * Locking: This function must be called under rcu_read_lock(). opp is a rcu
- * protected pointer. The reason for the same is that the opp pointer which is
- * returned will remain valid for use with opp_get_{voltage, freq} only while
- * under the locked area. The pointer returned must be used prior to unlocking
- * with rcu_read_unlock() to maintain the integrity of the pointer.
+ * The callers are required to call dev_pm_opp_put() for the returned OPP after
+ * use.
  */
 struct dev_pm_opp *devfreq_recommended_opp(struct device *dev,
                                           unsigned long *freq,
@@ -1290,18 +1277,7 @@ EXPORT_SYMBOL(devfreq_recommended_opp);
  */
 int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq)
 {
-       struct srcu_notifier_head *nh;
-       int ret = 0;
-
-       rcu_read_lock();
-       nh = dev_pm_opp_get_notifier(dev);
-       if (IS_ERR(nh))
-               ret = PTR_ERR(nh);
-       rcu_read_unlock();
-       if (!ret)
-               ret = srcu_notifier_chain_register(nh, &devfreq->nb);
-
-       return ret;
+       return dev_pm_opp_register_notifier(dev, &devfreq->nb);
 }
 EXPORT_SYMBOL(devfreq_register_opp_notifier);
 
@@ -1317,18 +1293,7 @@ EXPORT_SYMBOL(devfreq_register_opp_notifier);
  */
 int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq)
 {
-       struct srcu_notifier_head *nh;
-       int ret = 0;
-
-       rcu_read_lock();
-       nh = dev_pm_opp_get_notifier(dev);
-       if (IS_ERR(nh))
-               ret = PTR_ERR(nh);
-       rcu_read_unlock();
-       if (!ret)
-               ret = srcu_notifier_chain_unregister(nh, &devfreq->nb);
-
-       return ret;
+       return dev_pm_opp_unregister_notifier(dev, &devfreq->nb);
 }
 EXPORT_SYMBOL(devfreq_unregister_opp_notifier);