Add sysfs vdd interface

file:3c93426a46ff5f286d8a9cfc13d392ed897ff86a -> file:6d8b975282c4178afc32b15ed99e6000bcb6cad3
--- a/arch/arm/mach-msm/acpuclock-8x60.c
+++ b/arch/arm/mach-msm/acpuclock-8x60.c
@@ -45,6 +45,7 @@
#define L_VAL_SCPLL_CAL_MIN 0x08 /* = 432 MHz with 27MHz source */
#define L_VAL_SCPLL_CAL_MAX 0x22 /* = 1836 MHz with 27MHz source */
+#define MIN_VDD_SC 700000 /* uV */
#define MAX_VDD_SC 1600000 /* uV */
#define MAX_VDD_MEM 1600000 /* uV */
#define MAX_VDD_DIG 1600000 /* uV */
@@ -826,3 +827,36 @@ static int __init acpuclk_8x60_init(stru
struct acpuclk_soc_data acpuclk_8x60_soc_data __initdata = {
.init = acpuclk_8x60_init,
};
+
+#ifdef CONFIG_VDD_USERSPACE
+ssize_t acpuclk_get_vdd_levels_str(char *buf)
+{
+ int i, len = 0;
+ if (buf) {
+ mutex_lock(&drv_state.lock);
+ len += sprintf(buf + len, "Min: %4d\n", MIN_VDD_SC);
+ len += sprintf(buf + len, "Max: %4d\n", MAX_VDD_SC);
+ for (i = 0; acpu_freq_tbl[i].acpuclk_khz; i++) {
+ if (acpu_freq_tbl[i].use_for_scaling[0] || acpu_freq_tbl[i].use_for_scaling[1]) {
+ len += sprintf(buf + len, "%8u: %4d\n", acpu_freq_tbl[i].acpuclk_khz, acpu_freq_tbl[i].vdd_sc);
+ }
+ }
+ mutex_unlock(&drv_state.lock);
+ }
+ return len;
+}
+
+void acpuclk_set_vdd(unsigned int khz, int vdd)
+{
+ int i;
+ vdd = vdd / 25 * 25; //! regulator only accepts multiples of 25 (mV)
+ mutex_lock(&drv_state.lock);
+ for (i = 0; acpu_freq_tbl[i].acpuclk_khz; i++) {
+ if (khz == 0)
+ acpu_freq_tbl[i].vdd_sc = min(max((unsigned int)(acpu_freq_tbl[i].vdd_sc + vdd), (unsigned int)MIN_VDD_SC), (unsigned int)MAX_VDD_SC);
+ else if (acpu_freq_tbl[i].acpuclk_khz == khz)
+ acpu_freq_tbl[i].vdd_sc = min(max((unsigned int)vdd, (unsigned int)MIN_VDD_SC), (unsigned int)MAX_VDD_SC);
+ }
+ mutex_unlock(&drv_state.lock);
+}
+#endif
file:8b2c5fc51f80c324a488ba70b29ca884fcd75f37 -> file:5eabf405bb57e63456419a33fb9a4a9eb05f36f3
--- a/drivers/cpufreq/Kconfig
+++ b/drivers/cpufreq/Kconfig
@@ -290,6 +290,14 @@ config CPU_FREQ_SAMPLING_LATENCY_MULTIPL
Sampling latency rate multiplied by the cpu switch latency.
Affects governor polling.
+config VDD_USERSPACE
+ bool "VDD sysfs interface"
+ default n
+ depends on CPU_FREQ_STAT
+ help
+ exposes the VDD table to userspace
+ allows users to adjust voltages on the fly
+
menu "x86 CPU frequency scaling drivers"
depends on X86
source "drivers/cpufreq/Kconfig.x86"
file:311f3c7ac73c2d050b29e37d3a63a03f6be34614 -> file:8622c2208b2f58fce25ebcea1d7dd8f4ebbd4e4a
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -576,6 +576,59 @@ static ssize_t show_bios_limit(struct cp
return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
}
+#ifdef CONFIG_VDD_USERSPACE
+extern ssize_t acpuclk_get_vdd_levels_str(char *buf);
+static ssize_t show_vdd_levels(struct kobject *a, struct attribute *b, char *buf)
+{
+ return acpuclk_get_vdd_levels_str(buf);
+}
+
+extern void acpuclk_set_vdd(unsigned acpu_khz, int vdd);
+static ssize_t store_vdd_levels(struct kobject *a, struct attribute *b, const char *buf, size_t count)
+{
+ int i = 0, j;
+ int pair[2] = { 0, 0 };
+ int sign = 0;
+ if (count < 1)
+ return 0;
+ if (buf[0] == '-') {
+ sign = -1;
+ i++;
+ }
+ else if (buf[0] == '+') {
+ sign = 1;
+ i++;
+ }
+ for (j = 0; i < count; i++) {
+ char c = buf[i];
+ if ((c >= '0') && (c <= '9')) {
+ pair[j] *= 10;
+ pair[j] += (c - '0');
+ }
+ else if ((c == ' ') || (c == '\t')) {
+ if (pair[j] != 0) {
+ j++;
+ if ((sign != 0) || (j > 1))
+ break;
+ }
+ }
+ else
+ break;
+ }
+ if (sign != 0) {
+ if (pair[0] > 0)
+ acpuclk_set_vdd(0, sign * pair[0]);
+ }
+ else {
+ if ((pair[0] > 0) && (pair[1] > 0))
+ acpuclk_set_vdd((unsigned)pair[0], pair[1]);
+ else
+ return -EINVAL;
+ }
+ return count;
+}
+#endif /* CONFIG_VDD_USERSPACE */
+
cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400);
cpufreq_freq_attr_ro(cpuinfo_min_freq);
cpufreq_freq_attr_ro(cpuinfo_max_freq);
@@ -591,6 +644,10 @@ cpufreq_freq_attr_rw(scaling_max_freq);
cpufreq_freq_attr_rw(scaling_governor);
cpufreq_freq_attr_rw(scaling_setspeed);
+#ifdef CONFIG_VDD_USERSPACE
+define_one_global_rw(vdd_levels);
+#endif
+
static struct attribute *default_attrs[] = {
&cpuinfo_min_freq.attr,
&cpuinfo_max_freq.attr,
@@ -606,6 +663,18 @@ static struct attribute *default_attrs[]
NULL
};
+#ifdef CONFIG_VDD_USERSPACE
+static struct attribute *vddtbl_attrs[] = {
+ &vdd_levels.attr,
+ NULL
+};
+
+static struct attribute_group vddtbl_attr_group = {
+ .attrs = vddtbl_attrs,
+ .name = "vdd_table",
+};
+#endif /* CONFIG_VDD_USERSPACE */
+
struct kobject *cpufreq_global_kobject;
EXPORT_SYMBOL(cpufreq_global_kobject);
@@ -1916,6 +1985,9 @@ EXPORT_SYMBOL_GPL(cpufreq_unregister_dri
static int __init cpufreq_core_init(void)
{
int cpu;
+#ifdef CONFIG_VDD_USERSPACE
+ int rc;
+#endif /* CONFIG_VDD_USERSPACE */
for_each_possible_cpu(cpu) {
per_cpu(cpufreq_policy_cpu, cpu) = -1;
@@ -1927,6 +1999,10 @@ static int __init cpufreq_core_init(void
BUG_ON(!cpufreq_global_kobject);
register_syscore_ops(&cpufreq_syscore_ops);
+#ifdef CONFIG_VDD_USERSPACE
+ rc = sysfs_create_group(cpufreq_global_kobject, &vddtbl_attr_group);
+#endif /* CONFIG_VDD_USERSPACE */
+
return 0;
}
core_initcall(cpufreq_core_init);