[Galaxy 3 Android Development] cdesai:
Difference in drivers/cpufreq

diff -crB linux/drivers/cpufreq/cpufreq.c g3/drivers/cpufreq/cpufreq.c
*** linux/drivers/cpufreq/cpufreq.c	2010-02-23 07:38:51.000000000 -0800
--- g3/drivers/cpufreq/cpufreq.c	2011-02-26 04:41:38.000000000 -0800
***************
*** 131,137 ****
pure_initcall(init_cpufreq_transition_notifier_list);

static LIST_HEAD(cpufreq_governor_list);
! static DEFINE_MUTEX(cpufreq_governor_mutex);

struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
{
--- 131,137 ----
pure_initcall(init_cpufreq_transition_notifier_list);

static LIST_HEAD(cpufreq_governor_list);
! static DEFINE_MUTEX (cpufreq_governor_mutex);

struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
{
***************
*** 374,380 ****
struct cpufreq_governor *t;

list_for_each_entry(t, &cpufreq_governor_list, governor_list)
!	if (!strnicmp(str_governor, t->name, CPUFREQ_NAME_LEN))
return t;

return NULL;
--- 374,380 ----
struct cpufreq_governor *t;

list_for_each_entry(t, &cpufreq_governor_list, governor_list)
!	if (!strnicmp(str_governor,t->name,CPUFREQ_NAME_LEN))
return t;

return NULL;
***************
*** 432,438 ****

mutex_unlock(&cpufreq_governor_mutex);
}
! out:
return err;
}

--- 432,438 ----

mutex_unlock(&cpufreq_governor_mutex);
}
! out:
return err;
}

***************
*** 449,455 ****
static ssize_t show_##file_name	\
(struct cpufreq_policy *policy, char *buf)	\
{	\
!	return sprintf(buf, "%u\n", policy->object);	\
}

show_one(cpuinfo_min_freq, cpuinfo.min_freq);
--- 449,455 ----
static ssize_t show_##file_name	\
(struct cpufreq_policy *policy, char *buf)	\
{	\
!	return sprintf (buf, "%u\n", policy->object);	\
}

show_one(cpuinfo_min_freq, cpuinfo.min_freq);
***************
*** 476,482 ****
if (ret)	\
return -EINVAL;	\
\
!	ret = sscanf(buf, "%u", &new_policy.object);	\
if (ret != 1)	\
return -EINVAL;	\
\
--- 476,482 ----
if (ret)	\
return -EINVAL;	\
\
!	ret = sscanf (buf, "%u", &new_policy.object);	\
if (ret != 1)	\
return -EINVAL;	\
\
***************
*** 486,493 ****
return ret ? ret : count;	\
}

! store_one(scaling_min_freq, min);
! store_one(scaling_max_freq, max);

/**
* show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
--- 486,493 ----
return ret ? ret : count;	\
}

! store_one(scaling_min_freq,min);
! store_one(scaling_max_freq,max);

/**
* show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
***************
*** 507,513 ****
*/
static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
{
!	if (policy->policy == CPUFREQ_POLICY_POWERSAVE)
return sprintf(buf, "powersave\n");
else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
return sprintf(buf, "performance\n");
--- 507,513 ----
*/
static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
{
!	if(policy->policy == CPUFREQ_POLICY_POWERSAVE)
return sprintf(buf, "powersave\n");
else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
return sprintf(buf, "performance\n");
***************
*** 532,538 ****
if (ret)
return ret;

!	ret = sscanf(buf, "%15s", str_governor);
if (ret != 1)
return -EINVAL;

--- 532,538 ----
if (ret)
return ret;

!	ret = sscanf (buf, "%15s", str_governor);
if (ret != 1)
return -EINVAL;

***************
*** 596,602 ****
i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
if (i >= (PAGE_SIZE - 5))
!	break;
}
i += sprintf(&buf[i], "\n");
return i;
--- 596,602 ----
i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
if (i >= (PAGE_SIZE - 5))
!	break;
}
i += sprintf(&buf[i], "\n");
return i;
***************
*** 691,700 ****
struct kobject *cpufreq_global_kobject;
EXPORT_SYMBOL(cpufreq_global_kobject);

! #define to_policy(k) container_of(k, struct cpufreq_policy, kobj)
! #define to_attr(a) container_of(a, struct freq_attr, attr)

! static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
{
struct cpufreq_policy *policy = to_policy(kobj);
struct freq_attr *fattr = to_attr(attr);
--- 691,700 ----
struct kobject *cpufreq_global_kobject;
EXPORT_SYMBOL(cpufreq_global_kobject);

! #define to_policy(k) container_of(k,struct cpufreq_policy,kobj)
! #define to_attr(a) container_of(a,struct freq_attr,attr)

! static ssize_t show(struct kobject *kobj, struct attribute *attr ,char *buf)
{
struct cpufreq_policy *policy = to_policy(kobj);
struct freq_attr *fattr = to_attr(attr);
***************
*** 860,866 ****
managed_policy = cpufreq_cpu_get(cpu);
cpu_sys_dev = get_cpu_sysdev(j);
ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj,
!	"cpufreq");
if (ret) {
cpufreq_cpu_put(managed_policy);
return ret;
--- 860,866 ----
managed_policy = cpufreq_cpu_get(cpu);
cpu_sys_dev = get_cpu_sysdev(j);
ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj,
!	"cpufreq");
if (ret) {
cpufreq_cpu_put(managed_policy);
return ret;
***************
*** 913,919 ****
spin_unlock_irqrestore(&cpufreq_driver_lock, flags);

ret = cpufreq_add_dev_symlink(cpu, policy);
!	if (ret)
goto err_out_kobj_put;

memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));
--- 913,919 ----
spin_unlock_irqrestore(&cpufreq_driver_lock, flags);

ret = cpufreq_add_dev_symlink(cpu, policy);
!	if (ret)
goto err_out_kobj_put;

memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));
***************
*** 936,942 ****
kobject_put(&policy->kobj);
wait_for_completion(&policy->kobj_unregister);
return ret;
! }

/**
--- 936,942 ----
kobject_put(&policy->kobj);
wait_for_completion(&policy->kobj_unregister);
return ret;
!	}

/**
***************
*** 1678,1683 ****
--- 1678,1738 ----
}
EXPORT_SYMBOL(cpufreq_get_policy);

+ /**
+ * cpufreq_set_policy - get the current cpufreq_policy
+ * @policy: struct cpufreq_policy into which the current cpufreq_policy is written
+ *
+ * Writes appropriate cpufreq policy per request.
+ *
+ */
+ int cpufreq_set_policy(unsigned int cpu, const char *buf)
+ {
+	unsigned int ret = -EINVAL;
+	char	str_governor[16];
+	struct cpufreq_policy new_policy;
+	struct cpufreq_policy *data = cpufreq_cpu_get(cpu);
+
+	ret = cpufreq_get_policy(&new_policy, cpu);
+	if (ret)
+	return ret;
+
+	ret = sscanf (buf, "%15s", str_governor);
+	if (ret != 1)
+	return -EINVAL;
+
+	if (cpufreq_parse_governor(str_governor, &new_policy.policy,
+	&new_policy.governor))
+	return -EINVAL;
+
+	/* Do not use cpufreq_set_policy here or the user_policy.max
+	will be wrongly overridden */
+	ret = __cpufreq_set_policy(data, &new_policy);
+
+	data->user_policy.policy = data->policy;
+	data->user_policy.governor = data->governor;
+
+	if (ret)
+	return ret;
+	else
+	return 0;
+ }
+ EXPORT_SYMBOL(cpufreq_set_policy);
+
+ /**
+ * cpufreq_get_policy_name - get the current cpufreq_policy name
+ * &policy : struct cpufreq_policy into which the current cpufreq_policy is written
+ *
+ * Writes appropriate cpufreq policy per request.
+ *
+ */
+ char cpufreq_governor_name[CPUFREQ_NAME_LEN];
+ void cpufreq_get_cpufreq_name(unsigned int cpu)
+ {
+	struct cpufreq_policy *data = cpufreq_cpu_get(cpu);
+
+	strcpy (cpufreq_governor_name, data->governor->name);
+ }
+ EXPORT_SYMBOL(cpufreq_get_cpufreq_name);

/*
* data : current policy.
diff -crB linux/drivers/cpufreq/cpufreq_conservative.c g3/drivers/cpufreq/cpufreq_conservative.c
*** linux/drivers/cpufreq/cpufreq_conservative.c	2010-02-23 07:38:51.000000000 -0800
--- g3/drivers/cpufreq/cpufreq_conservative.c	2011-02-26 04:41:38.000000000 -0800
***************
*** 29,36 ****
* It helps to keep variable names smaller, simpler
*/

! #define DEF_FREQUENCY_UP_THRESHOLD	(80)
! #define DEF_FREQUENCY_DOWN_THRESHOLD	(20)

/*
* The polling frequency of this governor depends on the capability of
--- 29,45 ----
* It helps to keep variable names smaller, simpler
*/

! #define DEF_FREQUENCY_UP_THRESHOLD	(70)
! #define DEF_FREQUENCY_DOWN_THRESHOLD	(40)
! #ifdef CONFIG_CPU_S5P6442
! #define DEF_MAX_FREQ_TIME_HZ	(15*HZ)
! #define DEF_SAMPLING_FREQ_STEP	20
! extern int dvfs_change_quick;
! static int dvfs_max_freq_cnt = 0;
! extern unsigned int s5p6442_target_frq(unsigned int pred_freq, int flag);
! #else
! #define DEF_SAMPLING_FREQ_STEP 5
! #endif /* CONFIG_CPU_S5P6442 */

/*
* The polling frequency of this governor depends on the capability of
***************
*** 82,88 ****
static DEFINE_MUTEX(dbs_mutex);

static struct workqueue_struct	*kconservative_wq;
!
static struct dbs_tuners {
unsigned int sampling_rate;
unsigned int sampling_down_factor;
--- 91,97 ----
static DEFINE_MUTEX(dbs_mutex);

static struct workqueue_struct	*kconservative_wq;
! int conservative_workqueue_init = 0;
static struct dbs_tuners {
unsigned int sampling_rate;
unsigned int sampling_down_factor;
***************
*** 95,101 ****
--- 104,114 ----
.down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD,
.sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
.ignore_nice = 0,
+ #ifdef CONFIG_CPU_S5P6442
+	.freq_step = DEF_SAMPLING_FREQ_STEP,
+ #else
.freq_step = 5,
+ #endif /* CONFIG_CPU_S5P6442 */
};

static inline cputime64_t get_cpu_idle_time_jiffy(unsigned int cpu,
***************
*** 363,369 ****
--- 376,384 ----
static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
{
unsigned int load = 0;
+ #ifndef CONFIG_CPU_S5P6442
unsigned int freq_target;
+ #endif /* CONFIG_CPU_S5P6442 */

struct cpufreq_policy *policy;
unsigned int j;
***************
*** 430,442 ****
return;

/* Check for frequency increase */
!	if (load > dbs_tuners_ins.up_threshold) {
this_dbs_info->down_skip = 0;

/* if we are already at full speed then break out early */
if (this_dbs_info->requested_freq == policy->max)
return;
!
freq_target = (dbs_tuners_ins.freq_step * policy->max) / 100;

/* max freq cannot be less than 100. But who knows.... */
--- 445,468 ----
return;

/* Check for frequency increase */
! #ifdef CONFIG_CPU_S5P6442
!	if ((load > dbs_tuners_ins.up_threshold)|| (dvfs_change_quick) || (dvfs_max_freq_cnt > 0)) {
!	if(dvfs_change_quick){
!	dvfs_change_quick = 0;
!	dvfs_max_freq_cnt = ((DEF_MAX_FREQ_TIME_HZ * 5.654)/HZ);
!	}
!	dvfs_max_freq_cnt = (dvfs_max_freq_cnt > 0)?(dvfs_max_freq_cnt - 1):0;
! #else
! if (load > dbs_tuners_ins.up_threshold) {
! #endif
this_dbs_info->down_skip = 0;

/* if we are already at full speed then break out early */
if (this_dbs_info->requested_freq == policy->max)
return;
! #ifdef CONFIG_CPU_S5P6442
!	this_dbs_info->requested_freq = s5p6442_target_frq(this_dbs_info->requested_freq, 1);
! #else
freq_target = (dbs_tuners_ins.freq_step * policy->max) / 100;

/* max freq cannot be less than 100. But who knows.... */
***************
*** 444,449 ****
--- 470,477 ----
freq_target = 5;

this_dbs_info->requested_freq += freq_target;
+ #endif /* CONFIG_CPU_S5P6442 */
+
if (this_dbs_info->requested_freq > policy->max)
this_dbs_info->requested_freq = policy->max;

***************
*** 458,466 ****
--- 486,498 ----
* policy. To be safe, we focus 10 points under the threshold.
*/
if (load < (dbs_tuners_ins.down_threshold - 10)) {
+ #ifdef CONFIG_CPU_S5P6442
+	this_dbs_info->requested_freq = s5p6442_target_frq(this_dbs_info->requested_freq, -1);
+ #else
freq_target = (dbs_tuners_ins.freq_step * policy->max) / 100;

this_dbs_info->requested_freq -= freq_target;
+ #endif /* CONFIG_CPU_S5P6442 */
if (this_dbs_info->requested_freq < policy->min)
this_dbs_info->requested_freq = policy->min;

***************
*** 495,510 ****
--- 527,559 ----
mutex_unlock(&dbs_info->timer_mutex);
}

+ static int dbs_timer_count = 0;
static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info)
{
/* We want all CPUs to do sampling nearly on same jiffy */
int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
delay -= jiffies % delay;
+
+	if(conservative_workqueue_init == 0){
+	kconservative_wq = create_workqueue("kconservative");
+	if (!kconservative_wq) {
+	printk(KERN_ERR "Creation of kconservative failed\n");
+	return ;
+	}
+	conservative_workqueue_init = 1;
+ }

dbs_info->enable = 1;
INIT_DELAYED_WORK_DEFERRABLE(&dbs_info->work, do_dbs_timer);
+ if (dbs_timer_count == 0) {
+ queue_delayed_work_on(dbs_info->cpu, kconservative_wq, &dbs_info->work,
+	100 * HZ);
+	dbs_timer_count++;
+	}
+	else {
queue_delayed_work_on(dbs_info->cpu, kconservative_wq, &dbs_info->work,
delay);
+ }
}

static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info)
***************
*** 520,526 ****
struct cpu_dbs_info_s *this_dbs_info;
unsigned int j;
int rc;
!
this_dbs_info = &per_cpu(cs_cpu_dbs_info, cpu);

switch (event) {
--- 569,575 ----
struct cpu_dbs_info_s *this_dbs_info;
unsigned int j;
int rc;
!
this_dbs_info = &per_cpu(cs_cpu_dbs_info, cpu);

switch (event) {
***************
*** 638,654 ****
static int __init cpufreq_gov_dbs_init(void)
{
int err;
!
kconservative_wq = create_workqueue("kconservative");
if (!kconservative_wq) {
printk(KERN_ERR "Creation of kconservative failed\n");
return -EFAULT;
}

err = cpufreq_register_governor(&cpufreq_gov_conservative);
if (err)
destroy_workqueue(kconservative_wq);
!
return err;
}

--- 687,705 ----
static int __init cpufreq_gov_dbs_init(void)
{
int err;
!	if(conservative_workqueue_init == 0){
kconservative_wq = create_workqueue("kconservative");
if (!kconservative_wq) {
printk(KERN_ERR "Creation of kconservative failed\n");
return -EFAULT;
}
+	conservative_workqueue_init = 1;
+	}

err = cpufreq_register_governor(&cpufreq_gov_conservative);
if (err)
destroy_workqueue(kconservative_wq);
!
return err;
}

***************
*** 656,661 ****
--- 707,713 ----
{
cpufreq_unregister_governor(&cpufreq_gov_conservative);
destroy_workqueue(kconservative_wq);
+	conservative_workqueue_init = 0;
}