ARM: tegra11: clock: Combine DFLL usage controls
[linux-3.10.git] / arch / arm / mach-tegra / dvfs.c
index 0ff6986..3f335ee 100644 (file)
 #include "clock.h"
 #include "dvfs.h"
 
+#define DVFS_RAIL_STATS_BIN    25
+#define DVFS_RAIL_STATS_SCALE  2
+#define DVFS_RAIL_STATS_RANGE   ((DVFS_RAIL_STATS_TOP_BIN - 1) * \
+                                DVFS_RAIL_STATS_BIN / DVFS_RAIL_STATS_SCALE)
+
+struct dvfs_rail *tegra_cpu_rail;
+struct dvfs_rail *tegra_core_rail;
+
 static LIST_HEAD(dvfs_rail_list);
 static DEFINE_MUTEX(dvfs_lock);
+static DEFINE_MUTEX(rail_disable_lock);
 
 static int dvfs_rail_update(struct dvfs_rail *rail);
 
@@ -75,6 +84,11 @@ int tegra_dvfs_init_rails(struct dvfs_rail *rails[], int n)
                        rails[i]->step = rails[i]->max_millivolts;
 
                list_add_tail(&rails[i]->node, &dvfs_rail_list);
+
+               if (!strcmp("vdd_cpu", rails[i]->reg_id))
+                       tegra_cpu_rail = rails[i];
+               else if (!strcmp("vdd_core", rails[i]->reg_id))
+                       tegra_core_rail = rails[i];
        }
 
        mutex_unlock(&dvfs_lock);
@@ -87,6 +101,74 @@ static int dvfs_solve_relationship(struct dvfs_relationship *rel)
        return rel->solve(rel->from, rel->to);
 }
 
+/* rail statistic - called during rail init, or under dfs_lock, or with
+   CPU0 only on-line, and interrupts disabled */
+static void dvfs_rail_stats_init(struct dvfs_rail *rail, int millivolts)
+{
+       rail->stats.last_update = ktime_get();
+       if (millivolts >= rail->min_millivolts) {
+               int i = 1 + (2 * (millivolts - rail->min_millivolts) *
+                       DVFS_RAIL_STATS_SCALE + DVFS_RAIL_STATS_BIN) /
+                       (2 * DVFS_RAIL_STATS_BIN);
+               rail->stats.last_index = min(i, DVFS_RAIL_STATS_TOP_BIN);
+       }
+
+       if (rail->max_millivolts >
+           rail->min_millivolts + DVFS_RAIL_STATS_RANGE)
+               pr_warn("tegra_dvfs: %s: stats above %d mV will be squashed\n",
+                       rail->reg_id,
+                       rail->min_millivolts + DVFS_RAIL_STATS_RANGE);
+}
+
+static void dvfs_rail_stats_update(
+       struct dvfs_rail *rail, int millivolts, ktime_t now)
+{
+       rail->stats.time_at_mv[rail->stats.last_index] = ktime_add(
+               rail->stats.time_at_mv[rail->stats.last_index], ktime_sub(
+                       now, rail->stats.last_update));
+       rail->stats.last_update = now;
+
+       if (rail->stats.off)
+               return;
+
+       if (millivolts >= rail->min_millivolts) {
+               int i = 1 + (2 * (millivolts - rail->min_millivolts) *
+                       DVFS_RAIL_STATS_SCALE + DVFS_RAIL_STATS_BIN) /
+                       (2 * DVFS_RAIL_STATS_BIN);
+               rail->stats.last_index = min(i, DVFS_RAIL_STATS_TOP_BIN);
+       } else if (millivolts == 0)
+                       rail->stats.last_index = 0;
+}
+
+static void dvfs_rail_stats_pause(struct dvfs_rail *rail,
+                                 ktime_t delta, bool on)
+{
+       int i = on ? rail->stats.last_index : 0;
+       rail->stats.time_at_mv[i] = ktime_add(rail->stats.time_at_mv[i], delta);
+}
+
+void tegra_dvfs_rail_off(struct dvfs_rail *rail, ktime_t now)
+{
+       if (rail) {
+               dvfs_rail_stats_update(rail, 0, now);
+               rail->stats.off = true;
+       }
+}
+
+void tegra_dvfs_rail_on(struct dvfs_rail *rail, ktime_t now)
+{
+       if (rail) {
+               rail->stats.off = false;
+               dvfs_rail_stats_update(rail, rail->millivolts, now);
+       }
+}
+
+void tegra_dvfs_rail_pause(struct dvfs_rail *rail, ktime_t delta, bool on)
+{
+       if (rail)
+               dvfs_rail_stats_pause(rail, delta, on);
+}
+
 /* Sets the voltage on a dvfs rail to a specific value, and updates any
  * rails that depend on this rail. */
 static int dvfs_rail_set_voltage(struct dvfs_rail *rail, int millivolts)
@@ -96,6 +178,7 @@ static int dvfs_rail_set_voltage(struct dvfs_rail *rail, int millivolts)
        int step = (millivolts > rail->millivolts) ? rail->step : -rail->step;
        int i;
        int steps;
+       bool jmp_to_zero;
 
        if (!rail->reg) {
                if (millivolts == rail->millivolts)
@@ -104,14 +187,30 @@ static int dvfs_rail_set_voltage(struct dvfs_rail *rail, int millivolts)
                        return -EINVAL;
        }
 
+       /*
+        * DFLL adjusts rail voltage automatically, but not exactly to the
+        * expected level - update stats, anyway, and made sure that recorded
+        * level will not match any target that can be requested when/if we
+        * switch back from DFLL to s/w control
+        */
+       if (rail->dfll_mode) {
+               rail->millivolts = rail->new_millivolts = millivolts - 1;
+               dvfs_rail_stats_update(rail, millivolts, ktime_get());
+               return 0;
+       }
+
        if (rail->disabled)
                return 0;
 
        rail->resolving_to = true;
-       steps = DIV_ROUND_UP(abs(millivolts - rail->millivolts), rail->step);
+       jmp_to_zero = rail->jmp_to_zero &&
+                       ((millivolts == 0) || (rail->millivolts == 0));
+       steps = jmp_to_zero ? 1 :
+               DIV_ROUND_UP(abs(millivolts - rail->millivolts), rail->step);
 
        for (i = 0; i < steps; i++) {
-               if (abs(millivolts - rail->millivolts) > rail->step)
+               if (!jmp_to_zero &&
+                   (abs(millivolts - rail->millivolts) > rail->step))
                        rail->new_millivolts = rail->millivolts + step;
                else
                        rail->new_millivolts = millivolts;
@@ -130,9 +229,12 @@ static int dvfs_rail_set_voltage(struct dvfs_rail *rail, int millivolts)
 
                if (!rail->disabled) {
                        rail->updating = true;
+                       rail->reg_max_millivolts = rail->reg_max_millivolts ==
+                               rail->max_millivolts ?
+                               rail->max_millivolts + 1 : rail->max_millivolts;
                        ret = regulator_set_voltage(rail->reg,
                                rail->new_millivolts * 1000,
-                               rail->max_millivolts * 1000);
+                               rail->reg_max_millivolts * 1000);
                        rail->updating = false;
                }
                if (ret) {
@@ -141,6 +243,7 @@ static int dvfs_rail_set_voltage(struct dvfs_rail *rail, int millivolts)
                }
 
                rail->millivolts = rail->new_millivolts;
+               dvfs_rail_stats_update(rail, rail->millivolts, ktime_get());
 
                /* After changing the voltage, tell each rail that depends
                 * on this rail that the voltage has changed.
@@ -174,6 +277,7 @@ static int dvfs_rail_update(struct dvfs_rail *rail)
        struct dvfs *d;
        struct dvfs_relationship *rel;
        int ret = 0;
+       int steps;
 
        /* if dvfs is suspended, return and handle it during resume */
        if (rail->suspended)
@@ -192,14 +296,30 @@ static int dvfs_rail_update(struct dvfs_rail *rail)
        list_for_each_entry(d, &rail->dvfs, reg_node)
                millivolts = max(d->cur_millivolts, millivolts);
 
-       rail->new_millivolts = millivolts;
+       /* Apply offset if any clock is requesting voltage */
+       if (millivolts) {
+               millivolts += rail->offs_millivolts;
+               if (millivolts > rail->max_millivolts)
+                       millivolts = rail->max_millivolts;
+               else if (millivolts < rail->min_millivolts)
+                       millivolts = rail->min_millivolts;
+       }
+
+       /* retry update if limited by from-relationship to account for
+          circular dependencies */
+       steps = DIV_ROUND_UP(abs(millivolts - rail->millivolts), rail->step);
+       for (; steps >= 0; steps--) {
+               rail->new_millivolts = millivolts;
 
-       /* Check any rails that this rail depends on */
-       list_for_each_entry(rel, &rail->relationships_from, from_node)
-               rail->new_millivolts = dvfs_solve_relationship(rel);
+               /* Check any rails that this rail depends on */
+               list_for_each_entry(rel, &rail->relationships_from, from_node)
+                       rail->new_millivolts = dvfs_solve_relationship(rel);
+
+               if (rail->new_millivolts == rail->millivolts)
+                       break;
 
-       if (rail->new_millivolts != rail->millivolts)
                ret = dvfs_rail_set_voltage(rail, rail->new_millivolts);
+       }
 
        return ret;
 }
@@ -211,12 +331,22 @@ static int dvfs_rail_connect_to_regulator(struct dvfs_rail *rail)
 
        if (!rail->reg) {
                reg = regulator_get(NULL, rail->reg_id);
-               if (IS_ERR(reg))
+               if (IS_ERR(reg)) {
+                       pr_err("tegra_dvfs: failed to connect %s rail\n",
+                              rail->reg_id);
                        return -EINVAL;
+               }
+               rail->reg = reg;
+       }
+
+       v = regulator_enable(rail->reg);
+       if (v < 0) {
+               pr_err("tegra_dvfs: failed on enabling regulator %s\n, err %d",
+                       rail->reg_id, v);
+               return v;
        }
-       rail->reg = reg;
 
-       v = regulator_get_voltage(reg);
+       v = regulator_get_voltage(rail->reg);
        if (v < 0) {
                pr_err("tegra_dvfs: failed initial get %s voltage\n",
                       rail->reg_id);
@@ -224,19 +354,35 @@ static int dvfs_rail_connect_to_regulator(struct dvfs_rail *rail)
        }
        rail->millivolts = v / 1000;
        rail->new_millivolts = rail->millivolts;
+       dvfs_rail_stats_init(rail, rail->millivolts);
        return 0;
 }
 
+static inline unsigned long *dvfs_get_freqs(struct dvfs *d)
+{
+       return d->alt_freqs ? : &d->freqs[0];
+}
+
+static inline const int *dvfs_get_millivolts(struct dvfs *d, unsigned long rate)
+{
+       if (tegra_dvfs_is_dfll_scale(d, rate))
+               return d->dfll_millivolts;
+
+       return d->millivolts;
+}
+
 static int
 __tegra_dvfs_set_rate(struct dvfs *d, unsigned long rate)
 {
        int i = 0;
        int ret;
+       unsigned long *freqs = dvfs_get_freqs(d);
+       const int *millivolts = dvfs_get_millivolts(d, rate);
 
-       if (d->freqs == NULL || d->millivolts == NULL)
+       if (freqs == NULL || millivolts == NULL)
                return -ENODEV;
 
-       if (rate > d->freqs[d->num_freqs - 1]) {
+       if (rate > freqs[d->num_freqs - 1]) {
                pr_warn("tegra_dvfs: rate %lu too high for dvfs on %s\n", rate,
                        d->clk_name);
                return -EINVAL;
@@ -245,16 +391,16 @@ __tegra_dvfs_set_rate(struct dvfs *d, unsigned long rate)
        if (rate == 0) {
                d->cur_millivolts = 0;
        } else {
-               while (i < d->num_freqs && rate > d->freqs[i])
+               while (i < d->num_freqs && rate > freqs[i])
                        i++;
 
-               d->cur_millivolts = d->millivolts[i];
                if ((d->max_millivolts) &&
-                   (d->cur_millivolts > d->max_millivolts)) {
+                   (millivolts[i] > d->max_millivolts)) {
                        pr_warn("tegra_dvfs: voltage %d too high for dvfs on"
-                               " %s\n", d->cur_millivolts, d->clk_name);
+                               " %s\n", millivolts[i], d->clk_name);
                        return -EINVAL;
                }
+               d->cur_millivolts = millivolts[i];
        }
 
        d->cur_rate = rate;
@@ -267,6 +413,52 @@ __tegra_dvfs_set_rate(struct dvfs *d, unsigned long rate)
        return ret;
 }
 
+int tegra_dvfs_alt_freqs_set(struct dvfs *d, unsigned long *alt_freqs)
+{
+       int ret = 0;
+
+       mutex_lock(&dvfs_lock);
+
+       if (d->alt_freqs != alt_freqs) {
+               d->alt_freqs = alt_freqs;
+               ret = __tegra_dvfs_set_rate(d, d->cur_rate);
+       }
+
+       mutex_unlock(&dvfs_lock);
+       return ret;
+}
+
+int tegra_dvfs_predict_millivolts(struct clk *c, unsigned long rate)
+{
+       int i;
+       const int *millivolts;
+
+       if (!rate || !c->dvfs)
+               return 0;
+
+       millivolts = dvfs_get_millivolts(c->dvfs, rate);
+       if (!millivolts)
+               return -ENODEV;
+
+       /*
+        * Predicted voltage can not be used across the switch to alternative
+        * frequency limits. For now, just fail the call for clock that has
+        * alternative limits initialized.
+        */
+       if (c->dvfs->alt_freqs)
+               return -ENOSYS;
+
+       for (i = 0; i < c->dvfs->num_freqs; i++) {
+               if (rate <= c->dvfs->freqs[i])
+                       break;
+       }
+
+       if (i == c->dvfs->num_freqs)
+               return -EINVAL;
+
+       return millivolts[i];
+}
+
 int tegra_dvfs_set_rate(struct clk *c, unsigned long rate)
 {
        int ret;
@@ -443,57 +635,90 @@ static void __tegra_dvfs_rail_disable(struct dvfs_rail *rail)
 {
        int ret;
 
-       if (!rail->disabled) {
-               ret = dvfs_rail_set_voltage(rail, rail->nominal_millivolts);
-               if (ret)
-                       pr_info("dvfs: failed to set regulator %s to disable "
-                               "voltage %d\n", rail->reg_id,
-                               rail->nominal_millivolts);
+       /* don't set voltage in DFLL mode - won't work, but break stats */
+       if (rail->dfll_mode) {
                rail->disabled = true;
+               return;
        }
+
+       ret = dvfs_rail_set_voltage(rail, rail->nominal_millivolts);
+       if (ret) {
+               pr_info("dvfs: failed to set regulator %s to disable "
+                       "voltage %d\n", rail->reg_id,
+                       rail->nominal_millivolts);
+               return;
+       }
+       rail->disabled = true;
 }
 
 /* must be called with dvfs lock held */
 static void __tegra_dvfs_rail_enable(struct dvfs_rail *rail)
 {
-       if (rail->disabled) {
-               rail->disabled = false;
-               dvfs_rail_update(rail);
-       }
+       rail->disabled = false;
+       dvfs_rail_update(rail);
 }
 
 void tegra_dvfs_rail_enable(struct dvfs_rail *rail)
 {
-       mutex_lock(&dvfs_lock);
-       __tegra_dvfs_rail_enable(rail);
-       mutex_unlock(&dvfs_lock);
+       mutex_lock(&rail_disable_lock);
+
+       if (rail->disabled) {
+               mutex_lock(&dvfs_lock);
+               __tegra_dvfs_rail_enable(rail);
+               mutex_unlock(&dvfs_lock);
+
+               tegra_dvfs_rail_post_enable(rail);
+       }
+       mutex_unlock(&rail_disable_lock);
+
 }
 
 void tegra_dvfs_rail_disable(struct dvfs_rail *rail)
 {
+       mutex_lock(&rail_disable_lock);
+       if (rail->disabled)
+               goto out;
+
+       /* rail disable will set it to nominal voltage underneath clock
+          framework - need to re-configure clock rates that are not safe
+          at nominal (yes, unsafe at nominal is ugly, but possible). Rate
+          change must be done outside of dvfs lock. */
+       if (tegra_dvfs_rail_disable_prepare(rail)) {
+               pr_info("dvfs: failed to prepare regulator %s to disable\n",
+                       rail->reg_id);
+               goto out;
+       }
+
        mutex_lock(&dvfs_lock);
        __tegra_dvfs_rail_disable(rail);
        mutex_unlock(&dvfs_lock);
+out:
+       mutex_unlock(&rail_disable_lock);
 }
 
 int tegra_dvfs_rail_disable_by_name(const char *reg_id)
 {
+       struct dvfs_rail *rail = tegra_dvfs_get_rail_by_name(reg_id);
+       if (!rail)
+               return -EINVAL;
+
+       tegra_dvfs_rail_disable(rail);
+       return 0;
+}
+
+struct dvfs_rail *tegra_dvfs_get_rail_by_name(const char *reg_id)
+{
        struct dvfs_rail *rail;
-       int ret = 0;
 
        mutex_lock(&dvfs_lock);
        list_for_each_entry(rail, &dvfs_rail_list, node) {
                if (!strcmp(reg_id, rail->reg_id)) {
-                       __tegra_dvfs_rail_disable(rail);
-                       goto out;
+                       mutex_unlock(&dvfs_lock);
+                       return rail;
                }
        }
-
-       ret = -EINVAL;
-
-out:
        mutex_unlock(&dvfs_lock);
-       return ret;
+       return NULL;
 }
 
 bool tegra_dvfs_rail_updating(struct clk *clk)
@@ -504,6 +729,53 @@ bool tegra_dvfs_rail_updating(struct clk *clk)
                  (clk->dvfs->dvfs_rail->updating))));
 }
 
+#ifdef CONFIG_OF
+int __init of_tegra_dvfs_init(const struct of_device_id *matches)
+{
+       int ret;
+       struct device_node *np;
+
+       for_each_matching_node(np, matches) {
+               const struct of_device_id *match = of_match_node(matches, np);
+               of_tegra_dvfs_init_cb_t dvfs_init_cb = match->data;
+               ret = dvfs_init_cb(np);
+               if (ret) {
+                       pr_err("dt: Failed to read %s tables from DT\n",
+                                                       match->compatible);
+                       return ret;
+               }
+       }
+       return 0;
+}
+#endif
+int tegra_dvfs_dfll_mode_set(struct dvfs *d, unsigned long rate)
+{
+       mutex_lock(&dvfs_lock);
+       if (!d->dvfs_rail->dfll_mode) {
+               d->dvfs_rail->dfll_mode = true;
+               __tegra_dvfs_set_rate(d, rate);
+       }
+       mutex_unlock(&dvfs_lock);
+       return 0;
+}
+
+int tegra_dvfs_dfll_mode_clear(struct dvfs *d, unsigned long rate)
+{
+       int ret = 0;
+
+       mutex_lock(&dvfs_lock);
+       if (d->dvfs_rail->dfll_mode) {
+               d->dvfs_rail->dfll_mode = false;
+               if (d->dvfs_rail->disabled) {
+                       d->dvfs_rail->disabled = false;
+                       __tegra_dvfs_rail_disable(d->dvfs_rail);
+               }
+               ret = __tegra_dvfs_set_rate(d, rate);
+       }
+       mutex_unlock(&dvfs_lock);
+       return ret;
+}
+
 /*
  * Iterate through all the dvfs regulators, finding the regulator exported
  * by the regulator api for each one.  Must be called in late init, after
@@ -511,24 +783,32 @@ bool tegra_dvfs_rail_updating(struct clk *clk)
  */
 int __init tegra_dvfs_late_init(void)
 {
+       bool connected = true;
        struct dvfs_rail *rail;
 
        mutex_lock(&dvfs_lock);
 
        list_for_each_entry(rail, &dvfs_rail_list, node)
-               dvfs_rail_connect_to_regulator(rail);
+               if (dvfs_rail_connect_to_regulator(rail))
+                       connected = false;
 
        list_for_each_entry(rail, &dvfs_rail_list, node)
-               dvfs_rail_update(rail);
+               if (connected)
+                       dvfs_rail_update(rail);
+               else
+                       __tegra_dvfs_rail_disable(rail);
 
        mutex_unlock(&dvfs_lock);
 
+#ifdef CONFIG_TEGRA_SILICON_PLATFORM
+       if (!connected)
+               return -ENODEV;
+#endif
        register_pm_notifier(&tegra_dvfs_nb);
        register_reboot_notifier(&tegra_dvfs_reboot_nb);
 
        return 0;
 }
-late_initcall(tegra_dvfs_late_init);
 
 #ifdef CONFIG_DEBUG_FS
 static int dvfs_tree_sort_cmp(void *p, struct list_head *a, struct list_head *b)
@@ -561,14 +841,16 @@ static int dvfs_tree_show(struct seq_file *s, void *data)
        mutex_lock(&dvfs_lock);
 
        list_for_each_entry(rail, &dvfs_rail_list, node) {
-               seq_printf(s, "%s %d mV%s:\n", rail->reg_id,
-                       rail->millivolts, rail->disabled ? " disabled" : "");
+               seq_printf(s, "%s %d mV%s:\n", rail->reg_id, rail->millivolts,
+                          rail->dfll_mode ? " dfll mode" :
+                               rail->disabled ? " disabled" : "");
                list_for_each_entry(rel, &rail->relationships_from, from_node) {
                        seq_printf(s, "   %-10s %-7d mV %-4d mV\n",
                                rel->from->reg_id,
                                rel->from->millivolts,
                                dvfs_solve_relationship(rel));
                }
+               seq_printf(s, "   offset     %-7d mV\n", rail->offs_millivolts);
 
                list_sort(NULL, &rail->dvfs, dvfs_tree_sort_cmp);
 
@@ -595,6 +877,97 @@ static const struct file_operations dvfs_tree_fops = {
        .release        = single_release,
 };
 
+static int rail_stats_show(struct seq_file *s, void *data)
+{
+       int i;
+       struct dvfs_rail *rail;
+
+       seq_printf(s, "%-12s %-10s (bin: %d.%dmV)\n", "millivolts", "time",
+                  DVFS_RAIL_STATS_BIN / DVFS_RAIL_STATS_SCALE,
+                  ((DVFS_RAIL_STATS_BIN * 100) / DVFS_RAIL_STATS_SCALE) % 100);
+
+       mutex_lock(&dvfs_lock);
+
+       list_for_each_entry(rail, &dvfs_rail_list, node) {
+               seq_printf(s, "%s\n", rail->reg_id);
+               dvfs_rail_stats_update(rail, -1, ktime_get());
+
+               seq_printf(s, "%-12d %-10llu\n", 0,
+                       cputime64_to_clock_t(msecs_to_jiffies(
+                               ktime_to_ms(rail->stats.time_at_mv[0]))));
+
+               for (i = 1; i <= DVFS_RAIL_STATS_TOP_BIN; i++) {
+                       ktime_t ktime_zero = ktime_set(0, 0);
+                       if (ktime_equal(rail->stats.time_at_mv[i], ktime_zero))
+                               continue;
+                       seq_printf(s, "%-12d %-10llu\n",
+                                  rail->min_millivolts + (i - 1) *
+                                  DVFS_RAIL_STATS_BIN / DVFS_RAIL_STATS_SCALE,
+                               cputime64_to_clock_t(msecs_to_jiffies(
+                                       ktime_to_ms(rail->stats.time_at_mv[i])))
+                       );
+               }
+       }
+       mutex_unlock(&dvfs_lock);
+       return 0;
+}
+
+static int rail_stats_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, rail_stats_show, inode->i_private);
+}
+
+static const struct file_operations rail_stats_fops = {
+       .open           = rail_stats_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int cpu_offs_get(void *data, u64 *val)
+{
+       if (tegra_cpu_rail) {
+               *val = (u64)tegra_cpu_rail->offs_millivolts;
+               return 0;
+       }
+       *val = 0;
+       return -ENOENT;
+}
+static int cpu_offs_set(void *data, u64 val)
+{
+       if (tegra_cpu_rail) {
+               mutex_lock(&dvfs_lock);
+               tegra_cpu_rail->offs_millivolts = (int)val;
+               dvfs_rail_update(tegra_cpu_rail);
+               mutex_unlock(&dvfs_lock);
+               return 0;
+       }
+       return -ENOENT;
+}
+DEFINE_SIMPLE_ATTRIBUTE(cpu_offs_fops, cpu_offs_get, cpu_offs_set, "%lld\n");
+
+static int core_offs_get(void *data, u64 *val)
+{
+       if (tegra_core_rail) {
+               *val = (u64)tegra_core_rail->offs_millivolts;
+               return 0;
+       }
+       *val = 0;
+       return -ENOENT;
+}
+static int core_offs_set(void *data, u64 val)
+{
+       if (tegra_core_rail) {
+               mutex_lock(&dvfs_lock);
+               tegra_core_rail->offs_millivolts = (int)val;
+               dvfs_rail_update(tegra_core_rail);
+               mutex_unlock(&dvfs_lock);
+               return 0;
+       }
+       return -ENOENT;
+}
+DEFINE_SIMPLE_ATTRIBUTE(core_offs_fops, core_offs_get, core_offs_set, "%lld\n");
+
 int __init dvfs_debugfs_init(struct dentry *clk_debugfs_root)
 {
        struct dentry *d;
@@ -604,6 +977,21 @@ int __init dvfs_debugfs_init(struct dentry *clk_debugfs_root)
        if (!d)
                return -ENOMEM;
 
+       d = debugfs_create_file("rails", S_IRUGO, clk_debugfs_root, NULL,
+               &rail_stats_fops);
+       if (!d)
+               return -ENOMEM;
+
+       d = debugfs_create_file("vdd_cpu_offs", S_IRUGO | S_IWUSR,
+               clk_debugfs_root, NULL, &cpu_offs_fops);
+       if (!d)
+               return -ENOMEM;
+
+       d = debugfs_create_file("vdd_core_offs", S_IRUGO | S_IWUSR,
+               clk_debugfs_root, NULL, &core_offs_fops);
+       if (!d)
+               return -ENOMEM;
+
        return 0;
 }