diff options
Diffstat (limited to 'ANDROID_3.4.5/drivers/devfreq')
-rw-r--r-- | ANDROID_3.4.5/drivers/devfreq/Kconfig | 81 | ||||
-rw-r--r-- | ANDROID_3.4.5/drivers/devfreq/Makefile | 8 | ||||
-rw-r--r-- | ANDROID_3.4.5/drivers/devfreq/devfreq.c | 710 | ||||
-rw-r--r-- | ANDROID_3.4.5/drivers/devfreq/exynos4_bus.c | 1132 | ||||
-rw-r--r-- | ANDROID_3.4.5/drivers/devfreq/governor.h | 24 | ||||
-rw-r--r-- | ANDROID_3.4.5/drivers/devfreq/governor_performance.c | 39 | ||||
-rw-r--r-- | ANDROID_3.4.5/drivers/devfreq/governor_powersave.c | 36 | ||||
-rw-r--r-- | ANDROID_3.4.5/drivers/devfreq/governor_simpleondemand.c | 94 | ||||
-rw-r--r-- | ANDROID_3.4.5/drivers/devfreq/governor_userspace.c | 125 |
9 files changed, 0 insertions, 2249 deletions
diff --git a/ANDROID_3.4.5/drivers/devfreq/Kconfig b/ANDROID_3.4.5/drivers/devfreq/Kconfig deleted file mode 100644 index 464fa214..00000000 --- a/ANDROID_3.4.5/drivers/devfreq/Kconfig +++ /dev/null @@ -1,81 +0,0 @@ -menuconfig PM_DEVFREQ - bool "Generic Dynamic Voltage and Frequency Scaling (DVFS) support" - help - A device may have a list of frequencies and voltages available. - devfreq, a generic DVFS framework can be registered for a device - in order to let the governor provided to devfreq choose an - operating frequency based on the device driver's policy. - - Each device may have its own governor and policy. Devfreq can - reevaluate the device state periodically and/or based on the - notification to "nb", a notifier block, of devfreq. - - Like some CPUs with CPUfreq, a device may have multiple clocks. - However, because the clock frequencies of a single device are - determined by the single device's state, an instance of devfreq - is attached to a single device and returns a "representative" - clock frequency of the device, which is also attached - to a device by 1-to-1. The device registering devfreq takes the - responsiblity to "interpret" the representative frequency and - to set its every clock accordingly with the "target" callback - given to devfreq. - - When OPP is used with the devfreq device, it is recommended to - register devfreq's nb to the OPP's notifier head. If OPP is - used with the devfreq device, you may use OPP helper - functions defined in devfreq.h. - -if PM_DEVFREQ - -comment "DEVFREQ Governors" - -config DEVFREQ_GOV_SIMPLE_ONDEMAND - bool "Simple Ondemand" - help - Chooses frequency based on the recent load on the device. Works - similar as ONDEMAND governor of CPUFREQ does. A device with - Simple-Ondemand should be able to provide busy/total counter - values that imply the usage rate. A device may provide tuned - values to the governor with data field at devfreq_add_device(). - -config DEVFREQ_GOV_PERFORMANCE - bool "Performance" - help - Sets the frequency at the maximum available frequency. - This governor always returns UINT_MAX as frequency so that - the DEVFREQ framework returns the highest frequency available - at any time. - -config DEVFREQ_GOV_POWERSAVE - bool "Powersave" - help - Sets the frequency at the minimum available frequency. - This governor always returns 0 as frequency so that - the DEVFREQ framework returns the lowest frequency available - at any time. - -config DEVFREQ_GOV_USERSPACE - bool "Userspace" - help - Sets the frequency at the user specified one. - This governor returns the user configured frequency if there - has been an input to /sys/devices/.../power/devfreq_set_freq. - Otherwise, the governor does not change the frequnecy - given at the initialization. - -comment "DEVFREQ Drivers" - -config ARM_EXYNOS4_BUS_DEVFREQ - bool "ARM Exynos4210/4212/4412 Memory Bus DEVFREQ Driver" - depends on CPU_EXYNOS4210 || CPU_EXYNOS4212 || CPU_EXYNOS4412 - select ARCH_HAS_OPP - select DEVFREQ_GOV_SIMPLE_ONDEMAND - help - This adds the DEVFREQ driver for Exynos4210 memory bus (vdd_int) - and Exynos4212/4412 memory interface and bus (vdd_mif + vdd_int). - It reads PPMU counters of memory controllers and adjusts - the operating frequencies and voltages with OPP support. - To operate with optimal voltages, ASV support is required - (CONFIG_EXYNOS_ASV). - -endif # PM_DEVFREQ diff --git a/ANDROID_3.4.5/drivers/devfreq/Makefile b/ANDROID_3.4.5/drivers/devfreq/Makefile deleted file mode 100644 index 8c464234..00000000 --- a/ANDROID_3.4.5/drivers/devfreq/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -obj-$(CONFIG_PM_DEVFREQ) += devfreq.o -obj-$(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND) += governor_simpleondemand.o -obj-$(CONFIG_DEVFREQ_GOV_PERFORMANCE) += governor_performance.o -obj-$(CONFIG_DEVFREQ_GOV_POWERSAVE) += governor_powersave.o -obj-$(CONFIG_DEVFREQ_GOV_USERSPACE) += governor_userspace.o - -# DEVFREQ Drivers -obj-$(CONFIG_ARM_EXYNOS4_BUS_DEVFREQ) += exynos4_bus.o diff --git a/ANDROID_3.4.5/drivers/devfreq/devfreq.c b/ANDROID_3.4.5/drivers/devfreq/devfreq.c deleted file mode 100644 index 70c31d43..00000000 --- a/ANDROID_3.4.5/drivers/devfreq/devfreq.c +++ /dev/null @@ -1,710 +0,0 @@ -/* - * devfreq: Generic Dynamic Voltage and Frequency Scaling (DVFS) Framework - * for Non-CPU Devices. - * - * Copyright (C) 2011 Samsung Electronics - * MyungJoo Ham <myungjoo.ham@samsung.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -#include <linux/kernel.h> -#include <linux/sched.h> -#include <linux/errno.h> -#include <linux/err.h> -#include <linux/init.h> -#include <linux/module.h> -#include <linux/slab.h> -#include <linux/stat.h> -#include <linux/opp.h> -#include <linux/devfreq.h> -#include <linux/workqueue.h> -#include <linux/platform_device.h> -#include <linux/list.h> -#include <linux/printk.h> -#include <linux/hrtimer.h> -#include "governor.h" - -struct class *devfreq_class; - -/* - * devfreq_work periodically monitors every registered device. - * The minimum polling interval is one jiffy. The polling interval is - * determined by the minimum polling period among all polling devfreq - * devices. The resolution of polling interval is one jiffy. - */ -static bool polling; -static struct workqueue_struct *devfreq_wq; -static struct delayed_work devfreq_work; - -/* wait removing if this is to be removed */ -static struct devfreq *wait_remove_device; - -/* The list of all device-devfreq */ -static LIST_HEAD(devfreq_list); -static DEFINE_MUTEX(devfreq_list_lock); - -/** - * find_device_devfreq() - find devfreq struct using device pointer - * @dev: device pointer used to lookup device devfreq. - * - * Search the list of device devfreqs and return the matched device's - * devfreq info. devfreq_list_lock should be held by the caller. - */ -static struct devfreq *find_device_devfreq(struct device *dev) -{ - struct devfreq *tmp_devfreq; - - if (unlikely(IS_ERR_OR_NULL(dev))) { - pr_err("DEVFREQ: %s: Invalid parameters\n", __func__); - return ERR_PTR(-EINVAL); - } - WARN(!mutex_is_locked(&devfreq_list_lock), - "devfreq_list_lock must be locked."); - - list_for_each_entry(tmp_devfreq, &devfreq_list, node) { - if (tmp_devfreq->dev.parent == dev) - return tmp_devfreq; - } - - return ERR_PTR(-ENODEV); -} - -/** - * update_devfreq() - Reevaluate the device and configure frequency. - * @devfreq: the devfreq instance. - * - * Note: Lock devfreq->lock before calling update_devfreq - * This function is exported for governors. - */ -int update_devfreq(struct devfreq *devfreq) -{ - unsigned long freq; - int err = 0; - u32 flags = 0; - - if (!mutex_is_locked(&devfreq->lock)) { - WARN(true, "devfreq->lock must be locked by the caller.\n"); - return -EINVAL; - } - - /* Reevaluate the proper frequency */ - err = devfreq->governor->get_target_freq(devfreq, &freq); - if (err) - return err; - - /* - * Adjust the freuqency with user freq and QoS. - * - * List from the highest proiority - * max_freq (probably called by thermal when it's too hot) - * min_freq - */ - - if (devfreq->min_freq && freq < devfreq->min_freq) { - freq = devfreq->min_freq; - flags &= ~DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use GLB */ - } - if (devfreq->max_freq && freq > devfreq->max_freq) { - freq = devfreq->max_freq; - flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */ - } - - err = devfreq->profile->target(devfreq->dev.parent, &freq, flags); - if (err) - return err; - - devfreq->previous_freq = freq; - return err; -} - -/** - * devfreq_notifier_call() - Notify that the device frequency requirements - * has been changed out of devfreq framework. - * @nb the notifier_block (supposed to be devfreq->nb) - * @type not used - * @devp not used - * - * Called by a notifier that uses devfreq->nb. - */ -static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type, - void *devp) -{ - struct devfreq *devfreq = container_of(nb, struct devfreq, nb); - int ret; - - mutex_lock(&devfreq->lock); - ret = update_devfreq(devfreq); - mutex_unlock(&devfreq->lock); - - return ret; -} - -/** - * _remove_devfreq() - Remove devfreq from the device. - * @devfreq: the devfreq struct - * @skip: skip calling device_unregister(). - * - * Note that the caller should lock devfreq->lock before calling - * this. _remove_devfreq() will unlock it and free devfreq - * internally. devfreq_list_lock should be locked by the caller - * as well (not relased at return) - * - * Lock usage: - * devfreq->lock: locked before call. - * unlocked at return (and freed) - * devfreq_list_lock: locked before call. - * kept locked at return. - * if devfreq is centrally polled. - * - * Freed memory: - * devfreq - */ -static void _remove_devfreq(struct devfreq *devfreq, bool skip) -{ - if (!mutex_is_locked(&devfreq->lock)) { - WARN(true, "devfreq->lock must be locked by the caller.\n"); - return; - } - if (!devfreq->governor->no_central_polling && - !mutex_is_locked(&devfreq_list_lock)) { - WARN(true, "devfreq_list_lock must be locked by the caller.\n"); - return; - } - - if (devfreq->being_removed) - return; - - devfreq->being_removed = true; - - if (devfreq->profile->exit) - devfreq->profile->exit(devfreq->dev.parent); - - if (devfreq->governor->exit) - devfreq->governor->exit(devfreq); - - if (!skip && get_device(&devfreq->dev)) { - device_unregister(&devfreq->dev); - put_device(&devfreq->dev); - } - - if (!devfreq->governor->no_central_polling) - list_del(&devfreq->node); - - mutex_unlock(&devfreq->lock); - mutex_destroy(&devfreq->lock); - - 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. - * Note that devfreq_dev_release() could be called by _remove_devfreq() as - * well as by others unregistering the device. - */ -static void devfreq_dev_release(struct device *dev) -{ - struct devfreq *devfreq = to_devfreq(dev); - bool central_polling = !devfreq->governor->no_central_polling; - - /* - * If devfreq_dev_release() was called by device_unregister() of - * _remove_devfreq(), we cannot mutex_lock(&devfreq->lock) and - * being_removed is already set. This also partially checks the case - * where devfreq_dev_release() is called from a thread other than - * the one called _remove_devfreq(); however, this case is - * dealt completely with another following being_removed check. - * - * Because being_removed is never being - * unset, we do not need to worry about race conditions on - * being_removed. - */ - if (devfreq->being_removed) - return; - - if (central_polling) - mutex_lock(&devfreq_list_lock); - - mutex_lock(&devfreq->lock); - - /* - * Check being_removed flag again for the case where - * devfreq_dev_release() was called in a thread other than the one - * possibly called _remove_devfreq(). - */ - if (devfreq->being_removed) { - mutex_unlock(&devfreq->lock); - goto out; - } - - /* devfreq->lock is unlocked and removed in _removed_devfreq() */ - _remove_devfreq(devfreq, true); - -out: - if (central_polling) - mutex_unlock(&devfreq_list_lock); -} - -/** - * devfreq_monitor() - Periodically poll devfreq objects. - * @work: the work struct used to run devfreq_monitor periodically. - * - */ -static void devfreq_monitor(struct work_struct *work) -{ - static unsigned long last_polled_at; - struct devfreq *devfreq, *tmp; - int error; - unsigned long jiffies_passed; - unsigned long next_jiffies = ULONG_MAX, now = jiffies; - struct device *dev; - - /* Initially last_polled_at = 0, polling every device at bootup */ - jiffies_passed = now - last_polled_at; - last_polled_at = now; - if (jiffies_passed == 0) - jiffies_passed = 1; - - mutex_lock(&devfreq_list_lock); - list_for_each_entry_safe(devfreq, tmp, &devfreq_list, node) { - mutex_lock(&devfreq->lock); - dev = devfreq->dev.parent; - - /* Do not remove tmp for a while */ - wait_remove_device = tmp; - - if (devfreq->governor->no_central_polling || - devfreq->next_polling == 0) { - mutex_unlock(&devfreq->lock); - continue; - } - mutex_unlock(&devfreq_list_lock); - - /* - * Reduce more next_polling if devfreq_wq took an extra - * delay. (i.e., CPU has been idled.) - */ - if (devfreq->next_polling <= jiffies_passed) { - error = update_devfreq(devfreq); - - /* Remove a devfreq with an error. */ - if (error && error != -EAGAIN) { - - dev_err(dev, "Due to update_devfreq error(%d), devfreq(%s) is removed from the device\n", - error, devfreq->governor->name); - - /* - * Unlock devfreq before locking the list - * in order to avoid deadlock with - * find_device_devfreq or others - */ - mutex_unlock(&devfreq->lock); - mutex_lock(&devfreq_list_lock); - /* Check if devfreq is already removed */ - if (IS_ERR(find_device_devfreq(dev))) - continue; - mutex_lock(&devfreq->lock); - /* This unlocks devfreq->lock and free it */ - _remove_devfreq(devfreq, false); - continue; - } - devfreq->next_polling = devfreq->polling_jiffies; - } else { - devfreq->next_polling -= jiffies_passed; - } - - if (devfreq->next_polling) - next_jiffies = (next_jiffies > devfreq->next_polling) ? - devfreq->next_polling : next_jiffies; - - mutex_unlock(&devfreq->lock); - mutex_lock(&devfreq_list_lock); - } - wait_remove_device = NULL; - mutex_unlock(&devfreq_list_lock); - - if (next_jiffies > 0 && next_jiffies < ULONG_MAX) { - polling = true; - queue_delayed_work(devfreq_wq, &devfreq_work, next_jiffies); - } else { - polling = false; - } -} - -/** - * devfreq_add_device() - Add devfreq feature to the device - * @dev: the device to add devfreq feature. - * @profile: device-specific profile to run devfreq. - * @governor: the policy to choose frequency. - * @data: private data for the governor. The devfreq framework does not - * touch this value. - */ -struct devfreq *devfreq_add_device(struct device *dev, - struct devfreq_dev_profile *profile, - const struct devfreq_governor *governor, - void *data) -{ - struct devfreq *devfreq; - int err = 0; - - if (!dev || !profile || !governor) { - dev_err(dev, "%s: Invalid parameters.\n", __func__); - return ERR_PTR(-EINVAL); - } - - - if (!governor->no_central_polling) { - mutex_lock(&devfreq_list_lock); - devfreq = find_device_devfreq(dev); - mutex_unlock(&devfreq_list_lock); - if (!IS_ERR(devfreq)) { - dev_err(dev, "%s: Unable to create devfreq for the device. It already has one.\n", __func__); - err = -EINVAL; - goto err_out; - } - } - - devfreq = kzalloc(sizeof(struct devfreq), GFP_KERNEL); - if (!devfreq) { - dev_err(dev, "%s: Unable to create devfreq for the device\n", - __func__); - err = -ENOMEM; - goto err_out; - } - - mutex_init(&devfreq->lock); - mutex_lock(&devfreq->lock); - devfreq->dev.parent = dev; - devfreq->dev.class = devfreq_class; - devfreq->dev.release = devfreq_dev_release; - devfreq->profile = profile; - devfreq->governor = governor; - devfreq->previous_freq = profile->initial_freq; - devfreq->data = data; - devfreq->next_polling = devfreq->polling_jiffies - = msecs_to_jiffies(devfreq->profile->polling_ms); - devfreq->nb.notifier_call = devfreq_notifier_call; - - dev_set_name(&devfreq->dev, dev_name(dev)); - err = device_register(&devfreq->dev); - if (err) { - put_device(&devfreq->dev); - goto err_dev; - } - - if (governor->init) - err = governor->init(devfreq); - if (err) - goto err_init; - - mutex_unlock(&devfreq->lock); - - if (governor->no_central_polling) - goto out; - - mutex_lock(&devfreq_list_lock); - - list_add(&devfreq->node, &devfreq_list); - - if (devfreq_wq && devfreq->next_polling && !polling) { - polling = true; - queue_delayed_work(devfreq_wq, &devfreq_work, - devfreq->next_polling); - } - mutex_unlock(&devfreq_list_lock); -out: - return devfreq; - -err_init: - device_unregister(&devfreq->dev); -err_dev: - mutex_unlock(&devfreq->lock); - kfree(devfreq); -err_out: - return ERR_PTR(err); -} - -/** - * devfreq_remove_device() - Remove devfreq feature from a device. - * @devfreq the devfreq instance to be removed - */ -int devfreq_remove_device(struct devfreq *devfreq) -{ - bool central_polling; - - if (!devfreq) - return -EINVAL; - - central_polling = !devfreq->governor->no_central_polling; - - if (central_polling) { - mutex_lock(&devfreq_list_lock); - while (wait_remove_device == devfreq) { - mutex_unlock(&devfreq_list_lock); - schedule(); - mutex_lock(&devfreq_list_lock); - } - } - - mutex_lock(&devfreq->lock); - _remove_devfreq(devfreq, false); /* it unlocks devfreq->lock */ - - if (central_polling) - mutex_unlock(&devfreq_list_lock); - - return 0; -} - -static ssize_t show_governor(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return sprintf(buf, "%s\n", to_devfreq(dev)->governor->name); -} - -static ssize_t show_freq(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return sprintf(buf, "%lu\n", to_devfreq(dev)->previous_freq); -} - -static ssize_t show_polling_interval(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return sprintf(buf, "%d\n", to_devfreq(dev)->profile->polling_ms); -} - -static ssize_t store_polling_interval(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct devfreq *df = to_devfreq(dev); - unsigned int value; - int ret; - - ret = sscanf(buf, "%u", &value); - if (ret != 1) - goto out; - - mutex_lock(&df->lock); - df->profile->polling_ms = value; - df->next_polling = df->polling_jiffies - = msecs_to_jiffies(value); - mutex_unlock(&df->lock); - - ret = count; - - if (df->governor->no_central_polling) - goto out; - - mutex_lock(&devfreq_list_lock); - if (df->next_polling > 0 && !polling) { - polling = true; - queue_delayed_work(devfreq_wq, &devfreq_work, - df->next_polling); - } - mutex_unlock(&devfreq_list_lock); -out: - return ret; -} - -static ssize_t show_central_polling(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return sprintf(buf, "%d\n", - !to_devfreq(dev)->governor->no_central_polling); -} - -static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct devfreq *df = to_devfreq(dev); - unsigned long value; - int ret; - unsigned long max; - - ret = sscanf(buf, "%lu", &value); - if (ret != 1) - goto out; - - mutex_lock(&df->lock); - max = df->max_freq; - if (value && max && value > max) { - ret = -EINVAL; - goto unlock; - } - - df->min_freq = value; - update_devfreq(df); - ret = count; -unlock: - mutex_unlock(&df->lock); -out: - return ret; -} - -static ssize_t show_min_freq(struct device *dev, struct device_attribute *attr, - char *buf) -{ - return sprintf(buf, "%lu\n", to_devfreq(dev)->min_freq); -} - -static ssize_t store_max_freq(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct devfreq *df = to_devfreq(dev); - unsigned long value; - int ret; - unsigned long min; - - ret = sscanf(buf, "%lu", &value); - if (ret != 1) - goto out; - - mutex_lock(&df->lock); - min = df->min_freq; - if (value && min && value < min) { - ret = -EINVAL; - goto unlock; - } - - df->max_freq = value; - update_devfreq(df); - ret = count; -unlock: - mutex_unlock(&df->lock); -out: - return ret; -} - -static ssize_t show_max_freq(struct device *dev, struct device_attribute *attr, - char *buf) -{ - return sprintf(buf, "%lu\n", to_devfreq(dev)->max_freq); -} - -static struct device_attribute devfreq_attrs[] = { - __ATTR(governor, S_IRUGO, show_governor, NULL), - __ATTR(cur_freq, S_IRUGO, show_freq, NULL), - __ATTR(central_polling, S_IRUGO, show_central_polling, NULL), - __ATTR(polling_interval, S_IRUGO | S_IWUSR, show_polling_interval, - store_polling_interval), - __ATTR(min_freq, S_IRUGO | S_IWUSR, show_min_freq, store_min_freq), - __ATTR(max_freq, S_IRUGO | S_IWUSR, show_max_freq, store_max_freq), - { }, -}; - -/** - * devfreq_start_polling() - Initialize data structure for devfreq framework and - * start polling registered devfreq devices. - */ -static int __init devfreq_start_polling(void) -{ - mutex_lock(&devfreq_list_lock); - polling = false; - devfreq_wq = create_freezable_workqueue("devfreq_wq"); - INIT_DELAYED_WORK_DEFERRABLE(&devfreq_work, devfreq_monitor); - mutex_unlock(&devfreq_list_lock); - - devfreq_monitor(&devfreq_work.work); - return 0; -} -late_initcall(devfreq_start_polling); - -static int __init devfreq_init(void) -{ - devfreq_class = class_create(THIS_MODULE, "devfreq"); - if (IS_ERR(devfreq_class)) { - pr_err("%s: couldn't create class\n", __FILE__); - return PTR_ERR(devfreq_class); - } - devfreq_class->dev_attrs = devfreq_attrs; - return 0; -} -subsys_initcall(devfreq_init); - -static void __exit devfreq_exit(void) -{ - class_destroy(devfreq_class); -} -module_exit(devfreq_exit); - -/* - * The followings are helper functions for devfreq user device drivers with - * OPP framework. - */ - -/** - * devfreq_recommended_opp() - Helper function to get proper OPP for the - * freq value given to target callback. - * @dev The devfreq user device. (parent of devfreq) - * @freq The frequency given to target function - * @flags Flags handed from devfreq framework. - * - */ -struct opp *devfreq_recommended_opp(struct device *dev, unsigned long *freq, - u32 flags) -{ - struct opp *opp; - - if (flags & DEVFREQ_FLAG_LEAST_UPPER_BOUND) { - /* The freq is an upper bound. opp should be lower */ - opp = opp_find_freq_floor(dev, freq); - - /* If not available, use the closest opp */ - if (opp == ERR_PTR(-ENODEV)) - opp = opp_find_freq_ceil(dev, freq); - } else { - /* The freq is an lower bound. opp should be higher */ - opp = opp_find_freq_ceil(dev, freq); - - /* If not available, use the closest opp */ - if (opp == ERR_PTR(-ENODEV)) - opp = opp_find_freq_floor(dev, freq); - } - - return opp; -} - -/** - * devfreq_register_opp_notifier() - Helper function to get devfreq notified - * for any changes in the OPP availability - * changes - * @dev The devfreq user device. (parent of devfreq) - * @devfreq The devfreq object. - */ -int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq) -{ - struct srcu_notifier_head *nh = opp_get_notifier(dev); - - if (IS_ERR(nh)) - return PTR_ERR(nh); - return srcu_notifier_chain_register(nh, &devfreq->nb); -} - -/** - * devfreq_unregister_opp_notifier() - Helper function to stop getting devfreq - * notified for any changes in the OPP - * availability changes anymore. - * @dev The devfreq user device. (parent of devfreq) - * @devfreq The devfreq object. - * - * At exit() callback of devfreq_dev_profile, this must be included if - * devfreq_recommended_opp is used. - */ -int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq) -{ - struct srcu_notifier_head *nh = opp_get_notifier(dev); - - if (IS_ERR(nh)) - return PTR_ERR(nh); - return srcu_notifier_chain_unregister(nh, &devfreq->nb); -} - -MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); -MODULE_DESCRIPTION("devfreq class support"); -MODULE_LICENSE("GPL"); diff --git a/ANDROID_3.4.5/drivers/devfreq/exynos4_bus.c b/ANDROID_3.4.5/drivers/devfreq/exynos4_bus.c deleted file mode 100644 index 88ddc77a..00000000 --- a/ANDROID_3.4.5/drivers/devfreq/exynos4_bus.c +++ /dev/null @@ -1,1132 +0,0 @@ -/* drivers/devfreq/exynos4210_memorybus.c - * - * Copyright (c) 2011 Samsung Electronics Co., Ltd. - * http://www.samsung.com/ - * MyungJoo Ham <myungjoo.ham@samsung.com> - * - * EXYNOS4 - Memory/Bus clock frequency scaling support in DEVFREQ framework - * This version supports EXYNOS4210 only. This changes bus frequencies - * and vddint voltages. Exynos4412/4212 should be able to be supported - * with minor modifications. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - */ - -#include <linux/io.h> -#include <linux/slab.h> -#include <linux/mutex.h> -#include <linux/suspend.h> -#include <linux/opp.h> -#include <linux/devfreq.h> -#include <linux/platform_device.h> -#include <linux/regulator/consumer.h> -#include <linux/module.h> - -/* Exynos4 ASV has been in the mailing list, but not upstreamed, yet. */ -#ifdef CONFIG_EXYNOS_ASV -extern unsigned int exynos_result_of_asv; -#endif - -#include <mach/regs-clock.h> - -#include <plat/map-s5p.h> - -#define MAX_SAFEVOLT 1200000 /* 1.2V */ - -enum exynos4_busf_type { - TYPE_BUSF_EXYNOS4210, - TYPE_BUSF_EXYNOS4x12, -}; - -/* Assume that the bus is saturated if the utilization is 40% */ -#define BUS_SATURATION_RATIO 40 - -enum ppmu_counter { - PPMU_PMNCNT0 = 0, - PPMU_PMCCNT1, - PPMU_PMNCNT2, - PPMU_PMNCNT3, - PPMU_PMNCNT_MAX, -}; -struct exynos4_ppmu { - void __iomem *hw_base; - unsigned int ccnt; - unsigned int event; - unsigned int count[PPMU_PMNCNT_MAX]; - bool ccnt_overflow; - bool count_overflow[PPMU_PMNCNT_MAX]; -}; - -enum busclk_level_idx { - LV_0 = 0, - LV_1, - LV_2, - LV_3, - LV_4, - _LV_END -}; -#define EX4210_LV_MAX LV_2 -#define EX4x12_LV_MAX LV_4 -#define EX4210_LV_NUM (LV_2 + 1) -#define EX4x12_LV_NUM (LV_4 + 1) - -struct busfreq_data { - enum exynos4_busf_type type; - struct device *dev; - struct devfreq *devfreq; - bool disabled; - struct regulator *vdd_int; - struct regulator *vdd_mif; /* Exynos4412/4212 only */ - struct opp *curr_opp; - struct exynos4_ppmu dmc[2]; - - struct notifier_block pm_notifier; - struct mutex lock; - - /* Dividers calculated at boot/probe-time */ - unsigned int dmc_divtable[_LV_END]; /* DMC0 */ - unsigned int top_divtable[_LV_END]; -}; - -struct bus_opp_table { - unsigned int idx; - unsigned long clk; - unsigned long volt; -}; - -/* 4210 controls clock of mif and voltage of int */ -static struct bus_opp_table exynos4210_busclk_table[] = { - {LV_0, 400000, 1150000}, - {LV_1, 267000, 1050000}, - {LV_2, 133000, 1025000}, - {0, 0, 0}, -}; - -/* - * MIF is the main control knob clock for exynox4x12 MIF/INT - * clock and voltage of both mif/int are controlled. - */ -static struct bus_opp_table exynos4x12_mifclk_table[] = { - {LV_0, 400000, 1100000}, - {LV_1, 267000, 1000000}, - {LV_2, 160000, 950000}, - {LV_3, 133000, 950000}, - {LV_4, 100000, 950000}, - {0, 0, 0}, -}; - -/* - * INT is not the control knob of 4x12. LV_x is not meant to represent - * the current performance. (MIF does) - */ -static struct bus_opp_table exynos4x12_intclk_table[] = { - {LV_0, 200000, 1000000}, - {LV_1, 160000, 950000}, - {LV_2, 133000, 925000}, - {LV_3, 100000, 900000}, - {0, 0, 0}, -}; - -/* TODO: asv volt definitions are "__initdata"? */ -/* Some chips have different operating voltages */ -static unsigned int exynos4210_asv_volt[][EX4210_LV_NUM] = { - {1150000, 1050000, 1050000}, - {1125000, 1025000, 1025000}, - {1100000, 1000000, 1000000}, - {1075000, 975000, 975000}, - {1050000, 950000, 950000}, -}; - -static unsigned int exynos4x12_mif_step_50[][EX4x12_LV_NUM] = { - /* 400 267 160 133 100 */ - {1050000, 950000, 900000, 900000, 900000}, /* ASV0 */ - {1050000, 950000, 900000, 900000, 900000}, /* ASV1 */ - {1050000, 950000, 900000, 900000, 900000}, /* ASV2 */ - {1050000, 900000, 900000, 900000, 900000}, /* ASV3 */ - {1050000, 900000, 900000, 900000, 850000}, /* ASV4 */ - {1050000, 900000, 900000, 850000, 850000}, /* ASV5 */ - {1050000, 900000, 850000, 850000, 850000}, /* ASV6 */ - {1050000, 900000, 850000, 850000, 850000}, /* ASV7 */ - {1050000, 900000, 850000, 850000, 850000}, /* ASV8 */ -}; - -static unsigned int exynos4x12_int_volt[][EX4x12_LV_NUM] = { - /* 200 160 133 100 */ - {1000000, 950000, 925000, 900000}, /* ASV0 */ - {975000, 925000, 925000, 900000}, /* ASV1 */ - {950000, 925000, 900000, 875000}, /* ASV2 */ - {950000, 900000, 900000, 875000}, /* ASV3 */ - {925000, 875000, 875000, 875000}, /* ASV4 */ - {900000, 850000, 850000, 850000}, /* ASV5 */ - {900000, 850000, 850000, 850000}, /* ASV6 */ - {900000, 850000, 850000, 850000}, /* ASV7 */ - {900000, 850000, 850000, 850000}, /* ASV8 */ -}; - -/*** Clock Divider Data for Exynos4210 ***/ -static unsigned int exynos4210_clkdiv_dmc0[][8] = { - /* - * Clock divider value for following - * { DIVACP, DIVACP_PCLK, DIVDPHY, DIVDMC, DIVDMCD - * DIVDMCP, DIVCOPY2, DIVCORE_TIMERS } - */ - - /* DMC L0: 400MHz */ - { 3, 1, 1, 1, 1, 1, 3, 1 }, - /* DMC L1: 266.7MHz */ - { 4, 1, 1, 2, 1, 1, 3, 1 }, - /* DMC L2: 133MHz */ - { 5, 1, 1, 5, 1, 1, 3, 1 }, -}; -static unsigned int exynos4210_clkdiv_top[][5] = { - /* - * Clock divider value for following - * { DIVACLK200, DIVACLK100, DIVACLK160, DIVACLK133, DIVONENAND } - */ - /* ACLK200 L0: 200MHz */ - { 3, 7, 4, 5, 1 }, - /* ACLK200 L1: 160MHz */ - { 4, 7, 5, 6, 1 }, - /* ACLK200 L2: 133MHz */ - { 5, 7, 7, 7, 1 }, -}; -static unsigned int exynos4210_clkdiv_lr_bus[][2] = { - /* - * Clock divider value for following - * { DIVGDL/R, DIVGPL/R } - */ - /* ACLK_GDL/R L1: 200MHz */ - { 3, 1 }, - /* ACLK_GDL/R L2: 160MHz */ - { 4, 1 }, - /* ACLK_GDL/R L3: 133MHz */ - { 5, 1 }, -}; - -/*** Clock Divider Data for Exynos4212/4412 ***/ -static unsigned int exynos4x12_clkdiv_dmc0[][6] = { - /* - * Clock divider value for following - * { DIVACP, DIVACP_PCLK, DIVDPHY, DIVDMC, DIVDMCD - * DIVDMCP} - */ - - /* DMC L0: 400MHz */ - {3, 1, 1, 1, 1, 1}, - /* DMC L1: 266.7MHz */ - {4, 1, 1, 2, 1, 1}, - /* DMC L2: 160MHz */ - {5, 1, 1, 4, 1, 1}, - /* DMC L3: 133MHz */ - {5, 1, 1, 5, 1, 1}, - /* DMC L4: 100MHz */ - {7, 1, 1, 7, 1, 1}, -}; -static unsigned int exynos4x12_clkdiv_dmc1[][6] = { - /* - * Clock divider value for following - * { G2DACP, DIVC2C, DIVC2C_ACLK } - */ - - /* DMC L0: 400MHz */ - {3, 1, 1}, - /* DMC L1: 266.7MHz */ - {4, 2, 1}, - /* DMC L2: 160MHz */ - {5, 4, 1}, - /* DMC L3: 133MHz */ - {5, 5, 1}, - /* DMC L4: 100MHz */ - {7, 7, 1}, -}; -static unsigned int exynos4x12_clkdiv_top[][5] = { - /* - * Clock divider value for following - * { DIVACLK266_GPS, DIVACLK100, DIVACLK160, - DIVACLK133, DIVONENAND } - */ - - /* ACLK_GDL/R L0: 200MHz */ - {2, 7, 4, 5, 1}, - /* ACLK_GDL/R L1: 200MHz */ - {2, 7, 4, 5, 1}, - /* ACLK_GDL/R L2: 160MHz */ - {4, 7, 5, 7, 1}, - /* ACLK_GDL/R L3: 133MHz */ - {4, 7, 5, 7, 1}, - /* ACLK_GDL/R L4: 100MHz */ - {7, 7, 7, 7, 1}, -}; -static unsigned int exynos4x12_clkdiv_lr_bus[][2] = { - /* - * Clock divider value for following - * { DIVGDL/R, DIVGPL/R } - */ - - /* ACLK_GDL/R L0: 200MHz */ - {3, 1}, - /* ACLK_GDL/R L1: 200MHz */ - {3, 1}, - /* ACLK_GDL/R L2: 160MHz */ - {4, 1}, - /* ACLK_GDL/R L3: 133MHz */ - {5, 1}, - /* ACLK_GDL/R L4: 100MHz */ - {7, 1}, -}; -static unsigned int exynos4x12_clkdiv_sclkip[][3] = { - /* - * Clock divider value for following - * { DIVMFC, DIVJPEG, DIVFIMC0~3} - */ - - /* SCLK_MFC: 200MHz */ - {3, 3, 4}, - /* SCLK_MFC: 200MHz */ - {3, 3, 4}, - /* SCLK_MFC: 160MHz */ - {4, 4, 5}, - /* SCLK_MFC: 133MHz */ - {5, 5, 5}, - /* SCLK_MFC: 100MHz */ - {7, 7, 7}, -}; - - -static int exynos4210_set_busclk(struct busfreq_data *data, struct opp *opp) -{ - unsigned int index; - unsigned int tmp; - - for (index = LV_0; index < EX4210_LV_NUM; index++) - if (opp_get_freq(opp) == exynos4210_busclk_table[index].clk) - break; - - if (index == EX4210_LV_NUM) - return -EINVAL; - - /* Change Divider - DMC0 */ - tmp = data->dmc_divtable[index]; - - __raw_writel(tmp, EXYNOS4_CLKDIV_DMC0); - - do { - tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_DMC0); - } while (tmp & 0x11111111); - - /* Change Divider - TOP */ - tmp = data->top_divtable[index]; - - __raw_writel(tmp, EXYNOS4_CLKDIV_TOP); - - do { - tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_TOP); - } while (tmp & 0x11111); - - /* Change Divider - LEFTBUS */ - tmp = __raw_readl(EXYNOS4_CLKDIV_LEFTBUS); - - tmp &= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK | EXYNOS4_CLKDIV_BUS_GPLR_MASK); - - tmp |= ((exynos4210_clkdiv_lr_bus[index][0] << - EXYNOS4_CLKDIV_BUS_GDLR_SHIFT) | - (exynos4210_clkdiv_lr_bus[index][1] << - EXYNOS4_CLKDIV_BUS_GPLR_SHIFT)); - - __raw_writel(tmp, EXYNOS4_CLKDIV_LEFTBUS); - - do { - tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_LEFTBUS); - } while (tmp & 0x11); - - /* Change Divider - RIGHTBUS */ - tmp = __raw_readl(EXYNOS4_CLKDIV_RIGHTBUS); - - tmp &= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK | EXYNOS4_CLKDIV_BUS_GPLR_MASK); - - tmp |= ((exynos4210_clkdiv_lr_bus[index][0] << - EXYNOS4_CLKDIV_BUS_GDLR_SHIFT) | - (exynos4210_clkdiv_lr_bus[index][1] << - EXYNOS4_CLKDIV_BUS_GPLR_SHIFT)); - - __raw_writel(tmp, EXYNOS4_CLKDIV_RIGHTBUS); - - do { - tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_RIGHTBUS); - } while (tmp & 0x11); - - return 0; -} - -static int exynos4x12_set_busclk(struct busfreq_data *data, struct opp *opp) -{ - unsigned int index; - unsigned int tmp; - - for (index = LV_0; index < EX4x12_LV_NUM; index++) - if (opp_get_freq(opp) == exynos4x12_mifclk_table[index].clk) - break; - - if (index == EX4x12_LV_NUM) - return -EINVAL; - - /* Change Divider - DMC0 */ - tmp = data->dmc_divtable[index]; - - __raw_writel(tmp, EXYNOS4_CLKDIV_DMC0); - - do { - tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_DMC0); - } while (tmp & 0x11111111); - - /* Change Divider - DMC1 */ - tmp = __raw_readl(EXYNOS4_CLKDIV_DMC1); - - tmp &= ~(EXYNOS4_CLKDIV_DMC1_G2D_ACP_MASK | - EXYNOS4_CLKDIV_DMC1_C2C_MASK | - EXYNOS4_CLKDIV_DMC1_C2CACLK_MASK); - - tmp |= ((exynos4x12_clkdiv_dmc1[index][0] << - EXYNOS4_CLKDIV_DMC1_G2D_ACP_SHIFT) | - (exynos4x12_clkdiv_dmc1[index][1] << - EXYNOS4_CLKDIV_DMC1_C2C_SHIFT) | - (exynos4x12_clkdiv_dmc1[index][2] << - EXYNOS4_CLKDIV_DMC1_C2CACLK_SHIFT)); - - __raw_writel(tmp, EXYNOS4_CLKDIV_DMC1); - - do { - tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_DMC1); - } while (tmp & 0x111111); - - /* Change Divider - TOP */ - tmp = __raw_readl(EXYNOS4_CLKDIV_TOP); - - tmp &= ~(EXYNOS4_CLKDIV_TOP_ACLK266_GPS_MASK | - EXYNOS4_CLKDIV_TOP_ACLK100_MASK | - EXYNOS4_CLKDIV_TOP_ACLK160_MASK | - EXYNOS4_CLKDIV_TOP_ACLK133_MASK | - EXYNOS4_CLKDIV_TOP_ONENAND_MASK); - - tmp |= ((exynos4x12_clkdiv_top[index][0] << - EXYNOS4_CLKDIV_TOP_ACLK266_GPS_SHIFT) | - (exynos4x12_clkdiv_top[index][1] << - EXYNOS4_CLKDIV_TOP_ACLK100_SHIFT) | - (exynos4x12_clkdiv_top[index][2] << - EXYNOS4_CLKDIV_TOP_ACLK160_SHIFT) | - (exynos4x12_clkdiv_top[index][3] << - EXYNOS4_CLKDIV_TOP_ACLK133_SHIFT) | - (exynos4x12_clkdiv_top[index][4] << - EXYNOS4_CLKDIV_TOP_ONENAND_SHIFT)); - - __raw_writel(tmp, EXYNOS4_CLKDIV_TOP); - - do { - tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_TOP); - } while (tmp & 0x11111); - - /* Change Divider - LEFTBUS */ - tmp = __raw_readl(EXYNOS4_CLKDIV_LEFTBUS); - - tmp &= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK | EXYNOS4_CLKDIV_BUS_GPLR_MASK); - - tmp |= ((exynos4x12_clkdiv_lr_bus[index][0] << - EXYNOS4_CLKDIV_BUS_GDLR_SHIFT) | - (exynos4x12_clkdiv_lr_bus[index][1] << - EXYNOS4_CLKDIV_BUS_GPLR_SHIFT)); - - __raw_writel(tmp, EXYNOS4_CLKDIV_LEFTBUS); - - do { - tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_LEFTBUS); - } while (tmp & 0x11); - - /* Change Divider - RIGHTBUS */ - tmp = __raw_readl(EXYNOS4_CLKDIV_RIGHTBUS); - - tmp &= ~(EXYNOS4_CLKDIV_BUS_GDLR_MASK | EXYNOS4_CLKDIV_BUS_GPLR_MASK); - - tmp |= ((exynos4x12_clkdiv_lr_bus[index][0] << - EXYNOS4_CLKDIV_BUS_GDLR_SHIFT) | - (exynos4x12_clkdiv_lr_bus[index][1] << - EXYNOS4_CLKDIV_BUS_GPLR_SHIFT)); - - __raw_writel(tmp, EXYNOS4_CLKDIV_RIGHTBUS); - - do { - tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_RIGHTBUS); - } while (tmp & 0x11); - - /* Change Divider - MFC */ - tmp = __raw_readl(EXYNOS4_CLKDIV_MFC); - - tmp &= ~(EXYNOS4_CLKDIV_MFC_MASK); - - tmp |= ((exynos4x12_clkdiv_sclkip[index][0] << - EXYNOS4_CLKDIV_MFC_SHIFT)); - - __raw_writel(tmp, EXYNOS4_CLKDIV_MFC); - - do { - tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_MFC); - } while (tmp & 0x1); - - /* Change Divider - JPEG */ - tmp = __raw_readl(EXYNOS4_CLKDIV_CAM1); - - tmp &= ~(EXYNOS4_CLKDIV_CAM1_JPEG_MASK); - - tmp |= ((exynos4x12_clkdiv_sclkip[index][1] << - EXYNOS4_CLKDIV_CAM1_JPEG_SHIFT)); - - __raw_writel(tmp, EXYNOS4_CLKDIV_CAM1); - - do { - tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_CAM1); - } while (tmp & 0x1); - - /* Change Divider - FIMC0~3 */ - tmp = __raw_readl(EXYNOS4_CLKDIV_CAM); - - tmp &= ~(EXYNOS4_CLKDIV_CAM_FIMC0_MASK | EXYNOS4_CLKDIV_CAM_FIMC1_MASK | - EXYNOS4_CLKDIV_CAM_FIMC2_MASK | EXYNOS4_CLKDIV_CAM_FIMC3_MASK); - - tmp |= ((exynos4x12_clkdiv_sclkip[index][2] << - EXYNOS4_CLKDIV_CAM_FIMC0_SHIFT) | - (exynos4x12_clkdiv_sclkip[index][2] << - EXYNOS4_CLKDIV_CAM_FIMC1_SHIFT) | - (exynos4x12_clkdiv_sclkip[index][2] << - EXYNOS4_CLKDIV_CAM_FIMC2_SHIFT) | - (exynos4x12_clkdiv_sclkip[index][2] << - EXYNOS4_CLKDIV_CAM_FIMC3_SHIFT)); - - __raw_writel(tmp, EXYNOS4_CLKDIV_CAM); - - do { - tmp = __raw_readl(EXYNOS4_CLKDIV_STAT_CAM1); - } while (tmp & 0x1111); - - return 0; -} - - -static void busfreq_mon_reset(struct busfreq_data *data) -{ - unsigned int i; - - for (i = 0; i < 2; i++) { - void __iomem *ppmu_base = data->dmc[i].hw_base; - - /* Reset PPMU */ - __raw_writel(0x8000000f, ppmu_base + 0xf010); - __raw_writel(0x8000000f, ppmu_base + 0xf050); - __raw_writel(0x6, ppmu_base + 0xf000); - __raw_writel(0x0, ppmu_base + 0xf100); - - /* Set PPMU Event */ - data->dmc[i].event = 0x6; - __raw_writel(((data->dmc[i].event << 12) | 0x1), - ppmu_base + 0xfc); - - /* Start PPMU */ - __raw_writel(0x1, ppmu_base + 0xf000); - } -} - -static void exynos4_read_ppmu(struct busfreq_data *data) -{ - int i, j; - - for (i = 0; i < 2; i++) { - void __iomem *ppmu_base = data->dmc[i].hw_base; - u32 overflow; - - /* Stop PPMU */ - __raw_writel(0x0, ppmu_base + 0xf000); - - /* Update local data from PPMU */ - overflow = __raw_readl(ppmu_base + 0xf050); - - data->dmc[i].ccnt = __raw_readl(ppmu_base + 0xf100); - data->dmc[i].ccnt_overflow = overflow & (1 << 31); - - for (j = 0; j < PPMU_PMNCNT_MAX; j++) { - data->dmc[i].count[j] = __raw_readl( - ppmu_base + (0xf110 + (0x10 * j))); - data->dmc[i].count_overflow[j] = overflow & (1 << j); - } - } - - busfreq_mon_reset(data); -} - -static int exynos4x12_get_intspec(unsigned long mifclk) -{ - int i = 0; - - while (exynos4x12_intclk_table[i].clk) { - if (exynos4x12_intclk_table[i].clk <= mifclk) - return i; - i++; - } - - return -EINVAL; -} - -static int exynos4_bus_setvolt(struct busfreq_data *data, struct opp *opp, - struct opp *oldopp) -{ - int err = 0, tmp; - unsigned long volt = opp_get_voltage(opp); - - switch (data->type) { - case TYPE_BUSF_EXYNOS4210: - /* OPP represents DMC clock + INT voltage */ - err = regulator_set_voltage(data->vdd_int, volt, - MAX_SAFEVOLT); - break; - case TYPE_BUSF_EXYNOS4x12: - /* OPP represents MIF clock + MIF voltage */ - err = regulator_set_voltage(data->vdd_mif, volt, - MAX_SAFEVOLT); - if (err) - break; - - tmp = exynos4x12_get_intspec(opp_get_freq(opp)); - if (tmp < 0) { - err = tmp; - regulator_set_voltage(data->vdd_mif, - opp_get_voltage(oldopp), - MAX_SAFEVOLT); - break; - } - err = regulator_set_voltage(data->vdd_int, - exynos4x12_intclk_table[tmp].volt, - MAX_SAFEVOLT); - /* Try to recover */ - if (err) - regulator_set_voltage(data->vdd_mif, - opp_get_voltage(oldopp), - MAX_SAFEVOLT); - break; - default: - err = -EINVAL; - } - - return err; -} - -static int exynos4_bus_target(struct device *dev, unsigned long *_freq, - u32 flags) -{ - int err = 0; - struct platform_device *pdev = container_of(dev, struct platform_device, - dev); - struct busfreq_data *data = platform_get_drvdata(pdev); - struct opp *opp = devfreq_recommended_opp(dev, _freq, flags); - unsigned long freq = opp_get_freq(opp); - unsigned long old_freq = opp_get_freq(data->curr_opp); - - if (IS_ERR(opp)) - return PTR_ERR(opp); - - if (old_freq == freq) - return 0; - - dev_dbg(dev, "targetting %lukHz %luuV\n", freq, opp_get_voltage(opp)); - - mutex_lock(&data->lock); - - if (data->disabled) - goto out; - - if (old_freq < freq) - err = exynos4_bus_setvolt(data, opp, data->curr_opp); - if (err) - goto out; - - if (old_freq != freq) { - switch (data->type) { - case TYPE_BUSF_EXYNOS4210: - err = exynos4210_set_busclk(data, opp); - break; - case TYPE_BUSF_EXYNOS4x12: - err = exynos4x12_set_busclk(data, opp); - break; - default: - err = -EINVAL; - } - } - if (err) - goto out; - - if (old_freq > freq) - err = exynos4_bus_setvolt(data, opp, data->curr_opp); - if (err) - goto out; - - data->curr_opp = opp; -out: - mutex_unlock(&data->lock); - return err; -} - -static int exynos4_get_busier_dmc(struct busfreq_data *data) -{ - u64 p0 = data->dmc[0].count[0]; - u64 p1 = data->dmc[1].count[0]; - - p0 *= data->dmc[1].ccnt; - p1 *= data->dmc[0].ccnt; - - if (data->dmc[1].ccnt == 0) - return 0; - - if (p0 > p1) - return 0; - return 1; -} - -static int exynos4_bus_get_dev_status(struct device *dev, - struct devfreq_dev_status *stat) -{ - struct busfreq_data *data = dev_get_drvdata(dev); - int busier_dmc; - int cycles_x2 = 2; /* 2 x cycles */ - void __iomem *addr; - u32 timing; - u32 memctrl; - - exynos4_read_ppmu(data); - busier_dmc = exynos4_get_busier_dmc(data); - stat->current_frequency = opp_get_freq(data->curr_opp); - - if (busier_dmc) - addr = S5P_VA_DMC1; - else - addr = S5P_VA_DMC0; - - memctrl = __raw_readl(addr + 0x04); /* one of DDR2/3/LPDDR2 */ - timing = __raw_readl(addr + 0x38); /* CL or WL/RL values */ - - switch ((memctrl >> 8) & 0xf) { - case 0x4: /* DDR2 */ - cycles_x2 = ((timing >> 16) & 0xf) * 2; - break; - case 0x5: /* LPDDR2 */ - case 0x6: /* DDR3 */ - cycles_x2 = ((timing >> 8) & 0xf) + ((timing >> 0) & 0xf); - break; - default: - pr_err("%s: Unknown Memory Type(%d).\n", __func__, - (memctrl >> 8) & 0xf); - return -EINVAL; - } - - /* Number of cycles spent on memory access */ - stat->busy_time = data->dmc[busier_dmc].count[0] / 2 * (cycles_x2 + 2); - stat->busy_time *= 100 / BUS_SATURATION_RATIO; - stat->total_time = data->dmc[busier_dmc].ccnt; - - /* If the counters have overflown, retry */ - if (data->dmc[busier_dmc].ccnt_overflow || - data->dmc[busier_dmc].count_overflow[0]) - return -EAGAIN; - - return 0; -} - -static void exynos4_bus_exit(struct device *dev) -{ - struct busfreq_data *data = dev_get_drvdata(dev); - - devfreq_unregister_opp_notifier(dev, data->devfreq); -} - -static struct devfreq_dev_profile exynos4_devfreq_profile = { - .initial_freq = 400000, - .polling_ms = 50, - .target = exynos4_bus_target, - .get_dev_status = exynos4_bus_get_dev_status, - .exit = exynos4_bus_exit, -}; - -static int exynos4210_init_tables(struct busfreq_data *data) -{ - u32 tmp; - int mgrp; - int i, err = 0; - - tmp = __raw_readl(EXYNOS4_CLKDIV_DMC0); - for (i = LV_0; i < EX4210_LV_NUM; i++) { - tmp &= ~(EXYNOS4_CLKDIV_DMC0_ACP_MASK | - EXYNOS4_CLKDIV_DMC0_ACPPCLK_MASK | - EXYNOS4_CLKDIV_DMC0_DPHY_MASK | - EXYNOS4_CLKDIV_DMC0_DMC_MASK | - EXYNOS4_CLKDIV_DMC0_DMCD_MASK | - EXYNOS4_CLKDIV_DMC0_DMCP_MASK | - EXYNOS4_CLKDIV_DMC0_COPY2_MASK | - EXYNOS4_CLKDIV_DMC0_CORETI_MASK); - - tmp |= ((exynos4210_clkdiv_dmc0[i][0] << - EXYNOS4_CLKDIV_DMC0_ACP_SHIFT) | - (exynos4210_clkdiv_dmc0[i][1] << - EXYNOS4_CLKDIV_DMC0_ACPPCLK_SHIFT) | - (exynos4210_clkdiv_dmc0[i][2] << - EXYNOS4_CLKDIV_DMC0_DPHY_SHIFT) | - (exynos4210_clkdiv_dmc0[i][3] << - EXYNOS4_CLKDIV_DMC0_DMC_SHIFT) | - (exynos4210_clkdiv_dmc0[i][4] << - EXYNOS4_CLKDIV_DMC0_DMCD_SHIFT) | - (exynos4210_clkdiv_dmc0[i][5] << - EXYNOS4_CLKDIV_DMC0_DMCP_SHIFT) | - (exynos4210_clkdiv_dmc0[i][6] << - EXYNOS4_CLKDIV_DMC0_COPY2_SHIFT) | - (exynos4210_clkdiv_dmc0[i][7] << - EXYNOS4_CLKDIV_DMC0_CORETI_SHIFT)); - - data->dmc_divtable[i] = tmp; - } - - tmp = __raw_readl(EXYNOS4_CLKDIV_TOP); - for (i = LV_0; i < EX4210_LV_NUM; i++) { - tmp &= ~(EXYNOS4_CLKDIV_TOP_ACLK200_MASK | - EXYNOS4_CLKDIV_TOP_ACLK100_MASK | - EXYNOS4_CLKDIV_TOP_ACLK160_MASK | - EXYNOS4_CLKDIV_TOP_ACLK133_MASK | - EXYNOS4_CLKDIV_TOP_ONENAND_MASK); - - tmp |= ((exynos4210_clkdiv_top[i][0] << - EXYNOS4_CLKDIV_TOP_ACLK200_SHIFT) | - (exynos4210_clkdiv_top[i][1] << - EXYNOS4_CLKDIV_TOP_ACLK100_SHIFT) | - (exynos4210_clkdiv_top[i][2] << - EXYNOS4_CLKDIV_TOP_ACLK160_SHIFT) | - (exynos4210_clkdiv_top[i][3] << - EXYNOS4_CLKDIV_TOP_ACLK133_SHIFT) | - (exynos4210_clkdiv_top[i][4] << - EXYNOS4_CLKDIV_TOP_ONENAND_SHIFT)); - - data->top_divtable[i] = tmp; - } - -#ifdef CONFIG_EXYNOS_ASV - tmp = exynos4_result_of_asv; -#else - tmp = 0; /* Max voltages for the reliability of the unknown */ -#endif - - pr_debug("ASV Group of Exynos4 is %d\n", tmp); - /* Use merged grouping for voltage */ - switch (tmp) { - case 0: - mgrp = 0; - break; - case 1: - case 2: - mgrp = 1; - break; - case 3: - case 4: - mgrp = 2; - break; - case 5: - case 6: - mgrp = 3; - break; - case 7: - mgrp = 4; - break; - default: - pr_warn("Unknown ASV Group. Use max voltage.\n"); - mgrp = 0; - } - - for (i = LV_0; i < EX4210_LV_NUM; i++) - exynos4210_busclk_table[i].volt = exynos4210_asv_volt[mgrp][i]; - - for (i = LV_0; i < EX4210_LV_NUM; i++) { - err = opp_add(data->dev, exynos4210_busclk_table[i].clk, - exynos4210_busclk_table[i].volt); - if (err) { - dev_err(data->dev, "Cannot add opp entries.\n"); - return err; - } - } - - - return 0; -} - -static int exynos4x12_init_tables(struct busfreq_data *data) -{ - unsigned int i; - unsigned int tmp; - int ret; - - /* Enable pause function for DREX2 DVFS */ - tmp = __raw_readl(EXYNOS4_DMC_PAUSE_CTRL); - tmp |= EXYNOS4_DMC_PAUSE_ENABLE; - __raw_writel(tmp, EXYNOS4_DMC_PAUSE_CTRL); - - tmp = __raw_readl(EXYNOS4_CLKDIV_DMC0); - - for (i = 0; i < EX4x12_LV_NUM; i++) { - tmp &= ~(EXYNOS4_CLKDIV_DMC0_ACP_MASK | - EXYNOS4_CLKDIV_DMC0_ACPPCLK_MASK | - EXYNOS4_CLKDIV_DMC0_DPHY_MASK | - EXYNOS4_CLKDIV_DMC0_DMC_MASK | - EXYNOS4_CLKDIV_DMC0_DMCD_MASK | - EXYNOS4_CLKDIV_DMC0_DMCP_MASK); - - tmp |= ((exynos4x12_clkdiv_dmc0[i][0] << - EXYNOS4_CLKDIV_DMC0_ACP_SHIFT) | - (exynos4x12_clkdiv_dmc0[i][1] << - EXYNOS4_CLKDIV_DMC0_ACPPCLK_SHIFT) | - (exynos4x12_clkdiv_dmc0[i][2] << - EXYNOS4_CLKDIV_DMC0_DPHY_SHIFT) | - (exynos4x12_clkdiv_dmc0[i][3] << - EXYNOS4_CLKDIV_DMC0_DMC_SHIFT) | - (exynos4x12_clkdiv_dmc0[i][4] << - EXYNOS4_CLKDIV_DMC0_DMCD_SHIFT) | - (exynos4x12_clkdiv_dmc0[i][5] << - EXYNOS4_CLKDIV_DMC0_DMCP_SHIFT)); - - data->dmc_divtable[i] = tmp; - } - -#ifdef CONFIG_EXYNOS_ASV - tmp = exynos4_result_of_asv; -#else - tmp = 0; /* Max voltages for the reliability of the unknown */ -#endif - - if (tmp > 8) - tmp = 0; - pr_debug("ASV Group of Exynos4x12 is %d\n", tmp); - - for (i = 0; i < EX4x12_LV_NUM; i++) { - exynos4x12_mifclk_table[i].volt = - exynos4x12_mif_step_50[tmp][i]; - exynos4x12_intclk_table[i].volt = - exynos4x12_int_volt[tmp][i]; - } - - for (i = 0; i < EX4x12_LV_NUM; i++) { - ret = opp_add(data->dev, exynos4x12_mifclk_table[i].clk, - exynos4x12_mifclk_table[i].volt); - if (ret) { - dev_err(data->dev, "Fail to add opp entries.\n"); - return ret; - } - } - - return 0; -} - -static int exynos4_busfreq_pm_notifier_event(struct notifier_block *this, - unsigned long event, void *ptr) -{ - struct busfreq_data *data = container_of(this, struct busfreq_data, - pm_notifier); - struct opp *opp; - unsigned long maxfreq = ULONG_MAX; - int err = 0; - - switch (event) { - case PM_SUSPEND_PREPARE: - /* Set Fastest and Deactivate DVFS */ - mutex_lock(&data->lock); - - data->disabled = true; - - opp = opp_find_freq_floor(data->dev, &maxfreq); - - err = exynos4_bus_setvolt(data, opp, data->curr_opp); - if (err) - goto unlock; - - switch (data->type) { - case TYPE_BUSF_EXYNOS4210: - err = exynos4210_set_busclk(data, opp); - break; - case TYPE_BUSF_EXYNOS4x12: - err = exynos4x12_set_busclk(data, opp); - break; - default: - err = -EINVAL; - } - if (err) - goto unlock; - - data->curr_opp = opp; -unlock: - mutex_unlock(&data->lock); - if (err) - return err; - return NOTIFY_OK; - case PM_POST_RESTORE: - case PM_POST_SUSPEND: - /* Reactivate */ - mutex_lock(&data->lock); - data->disabled = false; - mutex_unlock(&data->lock); - return NOTIFY_OK; - } - - return NOTIFY_DONE; -} - -static __devinit int exynos4_busfreq_probe(struct platform_device *pdev) -{ - struct busfreq_data *data; - struct opp *opp; - struct device *dev = &pdev->dev; - int err = 0; - - data = kzalloc(sizeof(struct busfreq_data), GFP_KERNEL); - if (data == NULL) { - dev_err(dev, "Cannot allocate memory.\n"); - return -ENOMEM; - } - - data->type = pdev->id_entry->driver_data; - data->dmc[0].hw_base = S5P_VA_DMC0; - data->dmc[1].hw_base = S5P_VA_DMC1; - data->pm_notifier.notifier_call = exynos4_busfreq_pm_notifier_event; - data->dev = dev; - mutex_init(&data->lock); - - switch (data->type) { - case TYPE_BUSF_EXYNOS4210: - err = exynos4210_init_tables(data); - break; - case TYPE_BUSF_EXYNOS4x12: - err = exynos4x12_init_tables(data); - break; - default: - dev_err(dev, "Cannot determine the device id %d\n", data->type); - err = -EINVAL; - } - if (err) - goto err_regulator; - - data->vdd_int = regulator_get(dev, "vdd_int"); - if (IS_ERR(data->vdd_int)) { - dev_err(dev, "Cannot get the regulator \"vdd_int\"\n"); - err = PTR_ERR(data->vdd_int); - goto err_regulator; - } - if (data->type == TYPE_BUSF_EXYNOS4x12) { - data->vdd_mif = regulator_get(dev, "vdd_mif"); - if (IS_ERR(data->vdd_mif)) { - dev_err(dev, "Cannot get the regulator \"vdd_mif\"\n"); - err = PTR_ERR(data->vdd_mif); - regulator_put(data->vdd_int); - goto err_regulator; - - } - } - - opp = opp_find_freq_floor(dev, &exynos4_devfreq_profile.initial_freq); - if (IS_ERR(opp)) { - dev_err(dev, "Invalid initial frequency %lu kHz.\n", - exynos4_devfreq_profile.initial_freq); - err = PTR_ERR(opp); - goto err_opp_add; - } - data->curr_opp = opp; - - platform_set_drvdata(pdev, data); - - busfreq_mon_reset(data); - - data->devfreq = devfreq_add_device(dev, &exynos4_devfreq_profile, - &devfreq_simple_ondemand, NULL); - if (IS_ERR(data->devfreq)) { - err = PTR_ERR(data->devfreq); - goto err_opp_add; - } - - devfreq_register_opp_notifier(dev, data->devfreq); - - err = register_pm_notifier(&data->pm_notifier); - if (err) { - dev_err(dev, "Failed to setup pm notifier\n"); - goto err_devfreq_add; - } - - return 0; -err_devfreq_add: - devfreq_remove_device(data->devfreq); -err_opp_add: - if (data->vdd_mif) - regulator_put(data->vdd_mif); - regulator_put(data->vdd_int); -err_regulator: - kfree(data); - return err; -} - -static __devexit int exynos4_busfreq_remove(struct platform_device *pdev) -{ - struct busfreq_data *data = platform_get_drvdata(pdev); - - unregister_pm_notifier(&data->pm_notifier); - devfreq_remove_device(data->devfreq); - regulator_put(data->vdd_int); - if (data->vdd_mif) - regulator_put(data->vdd_mif); - kfree(data); - - return 0; -} - -static int exynos4_busfreq_resume(struct device *dev) -{ - struct busfreq_data *data = dev_get_drvdata(dev); - - busfreq_mon_reset(data); - return 0; -} - -static const struct dev_pm_ops exynos4_busfreq_pm = { - .resume = exynos4_busfreq_resume, -}; - -static const struct platform_device_id exynos4_busfreq_id[] = { - { "exynos4210-busfreq", TYPE_BUSF_EXYNOS4210 }, - { "exynos4412-busfreq", TYPE_BUSF_EXYNOS4x12 }, - { "exynos4212-busfreq", TYPE_BUSF_EXYNOS4x12 }, - { }, -}; - -static struct platform_driver exynos4_busfreq_driver = { - .probe = exynos4_busfreq_probe, - .remove = __devexit_p(exynos4_busfreq_remove), - .id_table = exynos4_busfreq_id, - .driver = { - .name = "exynos4-busfreq", - .owner = THIS_MODULE, - .pm = &exynos4_busfreq_pm, - }, -}; - -static int __init exynos4_busfreq_init(void) -{ - return platform_driver_register(&exynos4_busfreq_driver); -} -late_initcall(exynos4_busfreq_init); - -static void __exit exynos4_busfreq_exit(void) -{ - platform_driver_unregister(&exynos4_busfreq_driver); -} -module_exit(exynos4_busfreq_exit); - -MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("EXYNOS4 busfreq driver with devfreq framework"); -MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); diff --git a/ANDROID_3.4.5/drivers/devfreq/governor.h b/ANDROID_3.4.5/drivers/devfreq/governor.h deleted file mode 100644 index ea7f13c5..00000000 --- a/ANDROID_3.4.5/drivers/devfreq/governor.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * governor.h - internal header for devfreq governors. - * - * Copyright (C) 2011 Samsung Electronics - * MyungJoo Ham <myungjoo.ham@samsung.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This header is for devfreq governors in drivers/devfreq/ - */ - -#ifndef _GOVERNOR_H -#define _GOVERNOR_H - -#include <linux/devfreq.h> - -#define to_devfreq(DEV) container_of((DEV), struct devfreq, dev) - -/* Caution: devfreq->lock must be locked before calling update_devfreq */ -extern int update_devfreq(struct devfreq *devfreq); - -#endif /* _GOVERNOR_H */ diff --git a/ANDROID_3.4.5/drivers/devfreq/governor_performance.c b/ANDROID_3.4.5/drivers/devfreq/governor_performance.c deleted file mode 100644 index af75ddd4..00000000 --- a/ANDROID_3.4.5/drivers/devfreq/governor_performance.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * linux/drivers/devfreq/governor_performance.c - * - * Copyright (C) 2011 Samsung Electronics - * MyungJoo Ham <myungjoo.ham@samsung.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -#include <linux/devfreq.h> -#include "governor.h" - -static int devfreq_performance_func(struct devfreq *df, - unsigned long *freq) -{ - /* - * target callback should be able to get floor value as - * said in devfreq.h - */ - if (!df->max_freq) - *freq = UINT_MAX; - else - *freq = df->max_freq; - return 0; -} - -static int performance_init(struct devfreq *devfreq) -{ - return update_devfreq(devfreq); -} - -const struct devfreq_governor devfreq_performance = { - .name = "performance", - .init = performance_init, - .get_target_freq = devfreq_performance_func, - .no_central_polling = true, -}; diff --git a/ANDROID_3.4.5/drivers/devfreq/governor_powersave.c b/ANDROID_3.4.5/drivers/devfreq/governor_powersave.c deleted file mode 100644 index fec0cdbd..00000000 --- a/ANDROID_3.4.5/drivers/devfreq/governor_powersave.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * linux/drivers/devfreq/governor_powersave.c - * - * Copyright (C) 2011 Samsung Electronics - * MyungJoo Ham <myungjoo.ham@samsung.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -#include <linux/devfreq.h> -#include "governor.h" - -static int devfreq_powersave_func(struct devfreq *df, - unsigned long *freq) -{ - /* - * target callback should be able to get ceiling value as - * said in devfreq.h - */ - *freq = df->min_freq; - return 0; -} - -static int powersave_init(struct devfreq *devfreq) -{ - return update_devfreq(devfreq); -} - -const struct devfreq_governor devfreq_powersave = { - .name = "powersave", - .init = powersave_init, - .get_target_freq = devfreq_powersave_func, - .no_central_polling = true, -}; diff --git a/ANDROID_3.4.5/drivers/devfreq/governor_simpleondemand.c b/ANDROID_3.4.5/drivers/devfreq/governor_simpleondemand.c deleted file mode 100644 index a2e3eae7..00000000 --- a/ANDROID_3.4.5/drivers/devfreq/governor_simpleondemand.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * linux/drivers/devfreq/governor_simpleondemand.c - * - * Copyright (C) 2011 Samsung Electronics - * MyungJoo Ham <myungjoo.ham@samsung.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -#include <linux/errno.h> -#include <linux/devfreq.h> -#include <linux/math64.h> - -/* Default constants for DevFreq-Simple-Ondemand (DFSO) */ -#define DFSO_UPTHRESHOLD (90) -#define DFSO_DOWNDIFFERENCTIAL (5) -static int devfreq_simple_ondemand_func(struct devfreq *df, - unsigned long *freq) -{ - struct devfreq_dev_status stat; - int err = df->profile->get_dev_status(df->dev.parent, &stat); - unsigned long long a, b; - unsigned int dfso_upthreshold = DFSO_UPTHRESHOLD; - unsigned int dfso_downdifferential = DFSO_DOWNDIFFERENCTIAL; - struct devfreq_simple_ondemand_data *data = df->data; - unsigned long max = (df->max_freq) ? df->max_freq : UINT_MAX; - - if (err) - return err; - - if (data) { - if (data->upthreshold) - dfso_upthreshold = data->upthreshold; - if (data->downdifferential) - dfso_downdifferential = data->downdifferential; - } - if (dfso_upthreshold > 100 || - dfso_upthreshold < dfso_downdifferential) - return -EINVAL; - - /* Assume MAX if it is going to be divided by zero */ - if (stat.total_time == 0) { - *freq = max; - return 0; - } - - /* Prevent overflow */ - if (stat.busy_time >= (1 << 24) || stat.total_time >= (1 << 24)) { - stat.busy_time >>= 7; - stat.total_time >>= 7; - } - - /* Set MAX if it's busy enough */ - if (stat.busy_time * 100 > - stat.total_time * dfso_upthreshold) { - *freq = max; - return 0; - } - - /* Set MAX if we do not know the initial frequency */ - if (stat.current_frequency == 0) { - *freq = max; - return 0; - } - - /* Keep the current frequency */ - if (stat.busy_time * 100 > - stat.total_time * (dfso_upthreshold - dfso_downdifferential)) { - *freq = stat.current_frequency; - return 0; - } - - /* Set the desired frequency based on the load */ - a = stat.busy_time; - a *= stat.current_frequency; - b = div_u64(a, stat.total_time); - b *= 100; - b = div_u64(b, (dfso_upthreshold - dfso_downdifferential / 2)); - *freq = (unsigned long) b; - - if (df->min_freq && *freq < df->min_freq) - *freq = df->min_freq; - if (df->max_freq && *freq > df->max_freq) - *freq = df->max_freq; - - return 0; -} - -const struct devfreq_governor devfreq_simple_ondemand = { - .name = "simple_ondemand", - .get_target_freq = devfreq_simple_ondemand_func, -}; diff --git a/ANDROID_3.4.5/drivers/devfreq/governor_userspace.c b/ANDROID_3.4.5/drivers/devfreq/governor_userspace.c deleted file mode 100644 index 0681246f..00000000 --- a/ANDROID_3.4.5/drivers/devfreq/governor_userspace.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * linux/drivers/devfreq/governor_simpleondemand.c - * - * Copyright (C) 2011 Samsung Electronics - * MyungJoo Ham <myungjoo.ham@samsung.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -#include <linux/slab.h> -#include <linux/device.h> -#include <linux/devfreq.h> -#include <linux/pm.h> -#include <linux/mutex.h> -#include "governor.h" - -struct userspace_data { - unsigned long user_frequency; - bool valid; -}; - -static int devfreq_userspace_func(struct devfreq *df, unsigned long *freq) -{ - struct userspace_data *data = df->data; - - if (data->valid) { - unsigned long adjusted_freq = data->user_frequency; - - if (df->max_freq && adjusted_freq > df->max_freq) - adjusted_freq = df->max_freq; - - if (df->min_freq && adjusted_freq < df->min_freq) - adjusted_freq = df->min_freq; - - *freq = adjusted_freq; - } else { - *freq = df->previous_freq; /* No user freq specified yet */ - } - return 0; -} - -static ssize_t store_freq(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) -{ - struct devfreq *devfreq = to_devfreq(dev); - struct userspace_data *data; - unsigned long wanted; - int err = 0; - - - mutex_lock(&devfreq->lock); - data = devfreq->data; - - sscanf(buf, "%lu", &wanted); - data->user_frequency = wanted; - data->valid = true; - err = update_devfreq(devfreq); - if (err == 0) - err = count; - mutex_unlock(&devfreq->lock); - return err; -} - -static ssize_t show_freq(struct device *dev, struct device_attribute *attr, - char *buf) -{ - struct devfreq *devfreq = to_devfreq(dev); - struct userspace_data *data; - int err = 0; - - mutex_lock(&devfreq->lock); - data = devfreq->data; - - if (data->valid) - err = sprintf(buf, "%lu\n", data->user_frequency); - else - err = sprintf(buf, "undefined\n"); - mutex_unlock(&devfreq->lock); - return err; -} - -static DEVICE_ATTR(set_freq, 0644, show_freq, store_freq); -static struct attribute *dev_entries[] = { - &dev_attr_set_freq.attr, - NULL, -}; -static struct attribute_group dev_attr_group = { - .name = "userspace", - .attrs = dev_entries, -}; - -static int userspace_init(struct devfreq *devfreq) -{ - int err = 0; - struct userspace_data *data = kzalloc(sizeof(struct userspace_data), - GFP_KERNEL); - - if (!data) { - err = -ENOMEM; - goto out; - } - data->valid = false; - devfreq->data = data; - - err = sysfs_create_group(&devfreq->dev.kobj, &dev_attr_group); -out: - return err; -} - -static void userspace_exit(struct devfreq *devfreq) -{ - sysfs_remove_group(&devfreq->dev.kobj, &dev_attr_group); - kfree(devfreq->data); - devfreq->data = NULL; -} - -const struct devfreq_governor devfreq_userspace = { - .name = "userspace", - .get_target_freq = devfreq_userspace_func, - .init = userspace_init, - .exit = userspace_exit, - .no_central_polling = true, -}; |