2 * drivers/video/tegra/host/gr3d/pod_scaling.c
4 * Tegra Graphics Host 3D clock scaling
6 * Copyright (c) 2012-2014, NVIDIA CORPORATION. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * Power-on-demand clock scaling for nvhost devices
24 * devfreq calls nvhost_pod_estimate_freq() for estimating the new
25 * frequency for the device. The clocking is done using two properties:
27 * (1) Usually the governor receives actively throughput hints that indicate
28 * whether scaling up or down is required.
29 * (2) The load of the device is estimated using the busy times from the
30 * device profile. This information indicates if the device frequency
35 #include <linux/devfreq.h>
36 #include <linux/debugfs.h>
37 #include <linux/types.h>
38 #include <linux/clk.h>
39 #include <linux/export.h>
40 #include <linux/slab.h>
41 #include <linux/clk/tegra.h>
42 #include <linux/tegra-soc.h>
44 #include <linux/notifier.h>
45 #include <linux/tegra-throughput.h>
47 #include <linux/notifier.h>
48 #include <linux/tegra-throughput.h>
50 #define CREATE_TRACE_POINTS
51 #include <trace/events/nvhost_podgov.h>
55 #include "nvhost_acm.h"
59 #define GET_TARGET_FREQ_DONTSCALE 1
61 /* time frame for load and hint tracking - when events come in at a larger
62 * interval, this probably indicates the current estimates are stale
64 #define GR3D_TIMEFRAME 1000000 /* 1 sec */
66 /* the number of frames to use in the running average of load estimates and
67 * throughput hints. Choosing 6 frames targets a window of about 100 msec.
68 * Large flucutuations in frame times require a window that's large enough to
69 * prevent spiky scaling behavior, which in turn exacerbates frame rate
73 static void podgov_enable(struct devfreq *df, int enable);
74 static void podgov_set_user_ctl(struct devfreq *df, int enable);
76 static struct devfreq_governor nvhost_podgov;
78 /*******************************************************************************
79 * podgov_info_rec - gr3d scaling governor specific parameters
80 ******************************************************************************/
82 struct podgov_info_rec {
87 ktime_t last_throughput_hint;
90 struct delayed_work idle_timer;
92 unsigned int p_slowdown_delay;
93 unsigned int p_block_window;
94 unsigned int p_use_throughput_hint;
95 unsigned int p_hint_lo_limit;
96 unsigned int p_hint_hi_limit;
97 unsigned int p_scaleup_limit;
98 unsigned int p_scaledown_limit;
99 unsigned int p_smooth;
105 unsigned int p_freq_request;
110 unsigned long adjustment_frequency;
114 struct devfreq *power_manager;
115 struct dentry *debugdir;
117 unsigned long *freqlist;
120 unsigned int idle_avg;
122 unsigned int hint_avg;
124 struct kobj_attribute enable_3d_scaling_attr;
125 struct kobj_attribute user_attr;
126 struct kobj_attribute freq_request_attr;
128 struct notifier_block throughput_hint_notifier;
131 /*******************************************************************************
132 * Adjustment type is used to tell the source that requested frequency re-
133 * estimation. Type ADJUSTMENT_LOCAL indicates that the re-estimation was
134 * initiated by the governor itself. This happens when one of the worker
135 * threads want to adjust the frequency.
137 * ADJUSTMENT_DEVICE_REQ (default value) indicates that the adjustment was
138 * initiated by a device event.
139 ******************************************************************************/
141 enum podgov_adjustment_type {
142 ADJUSTMENT_LOCAL = 0,
143 ADJUSTMENT_DEVICE_REQ = 1
147 static void stop_podgov_workers(struct podgov_info_rec *podgov)
149 /* idle_timer can rearm itself */
151 cancel_delayed_work_sync(&podgov->idle_timer);
152 } while (delayed_work_pending(&podgov->idle_timer));
155 /*******************************************************************************
156 * scaling_limit(df, freq)
158 * Limit the given frequency
159 ******************************************************************************/
161 static void scaling_limit(struct devfreq *df, unsigned long *freq)
163 if (*freq < df->min_freq)
164 *freq = df->min_freq;
165 else if (*freq > df->max_freq)
166 *freq = df->max_freq;
169 /*******************************************************************************
170 * nvhost_pod_suspend(dev)
172 * Prepare the device for suspend
173 ******************************************************************************/
175 static void nvhost_pod_suspend(struct devfreq *df)
177 struct podgov_info_rec *podgov;
179 mutex_lock(&df->lock);
182 if (!(df->governor == &nvhost_podgov &&
183 podgov && podgov->enable)) {
184 mutex_unlock(&df->lock);
187 mutex_unlock(&df->lock);
189 stop_podgov_workers(podgov);
192 /*******************************************************************************
193 * podgov_enable(dev, enable)
195 * This function enables (enable=1) or disables (enable=0) the automatic scaling
196 * of the device. If the device is disabled, the device's clock is set to its
198 ******************************************************************************/
200 static void podgov_enable(struct devfreq *df, int enable)
202 struct device *dev = df->dev.parent;
203 struct podgov_info_rec *podgov;
205 /* make sure the device is alive before doing any scaling */
206 pm_runtime_get_noresume(dev);
208 mutex_lock(&df->lock);
212 trace_podgov_enabled(enable);
214 /* bad configuration. quit. */
215 if (df->min_freq == df->max_freq)
218 /* store the enable information */
219 podgov->enable = enable;
221 /* skip local adjustment if we are enabling or the device is
223 if (enable || !pm_runtime_active(dev))
227 podgov->adjustment_frequency = df->max_freq;
228 podgov->adjustment_type = ADJUSTMENT_LOCAL;
231 mutex_unlock(&df->lock);
235 stop_podgov_workers(podgov);
240 mutex_unlock(&df->lock);
244 /*****************************************************************************
245 * podgov_set_user_ctl(dev, user)
247 * This function enables or disables user control of the gpu. If user control
248 * is enabled, setting the freq_request controls the gpu frequency, and other
249 * gpu scaling mechanisms are disabled.
250 ******************************************************************************/
252 static void podgov_set_user_ctl(struct devfreq *df, int user)
254 struct device *dev = df->dev.parent;
255 struct podgov_info_rec *podgov;
258 /* make sure the device is alive before doing any scaling */
259 pm_runtime_get_noresume(dev);
261 mutex_lock(&df->lock);
264 trace_podgov_set_user_ctl(user);
266 /* store the new user value */
267 old_user = podgov->p_user;
268 podgov->p_user = user;
270 /* skip scaling, if scaling (or the whole device) is turned off
271 * - or the scaling already was in user mode */
272 if (!pm_runtime_active(dev) || !podgov->enable ||
273 !(user && !old_user))
277 podgov->adjustment_frequency = podgov->p_freq_request;
278 podgov->adjustment_type = ADJUSTMENT_LOCAL;
281 mutex_unlock(&df->lock);
284 stop_podgov_workers(podgov);
289 mutex_unlock(&df->lock);
293 /*****************************************************************************
294 * podgov_set_freq_request(dev, user)
296 * Set the current freq request. If scaling is enabled, and podgov user space
297 * control is enabled, this will set the gpu frequency.
298 ******************************************************************************/
300 static void podgov_set_freq_request(struct devfreq *df, int freq_request)
302 struct device *dev = df->dev.parent;
303 struct podgov_info_rec *podgov;
305 /* make sure the device is alive before doing any scaling */
306 pm_runtime_get_noresume(dev);
308 mutex_lock(&df->lock);
312 trace_podgov_set_freq_request(freq_request);
314 podgov->p_freq_request = freq_request;
316 /* update the request only if podgov is enabled, device is turned on
317 * and the scaling is in user mode */
318 if (podgov->enable && podgov->p_user &&
319 pm_runtime_active(dev)) {
320 podgov->adjustment_frequency = freq_request;
321 podgov->adjustment_type = ADJUSTMENT_LOCAL;
325 mutex_unlock(&df->lock);
330 /*******************************************************************************
331 * freq = scaling_state_check(df, time)
333 * This handler is called to adjust the frequency of the device. The function
334 * returns the desired frequency for the clock. If there is no need to tune the
335 * clock immediately, 0 is returned.
336 ******************************************************************************/
338 static unsigned long scaling_state_check(struct devfreq *df, ktime_t time)
340 struct podgov_info_rec *podgov = df->data;
342 long max_boost, load, damp, freq, boost, res;
344 dt = (unsigned long) ktime_us_delta(time, podgov->last_scale);
345 if (dt < podgov->p_block_window || df->previous_freq == 0)
348 /* convert to mhz to avoid overflow */
349 freq = df->previous_freq / 1000000;
350 max_boost = (df->max_freq/3) / 1000000;
352 /* calculate and trace load */
353 load = 1000 - podgov->idle_avg;
354 trace_podgov_busy(load);
355 damp = podgov->p_damp;
357 if ((1000 - podgov->idle) > podgov->p_load_max) {
358 /* if too busy, scale up max/3, do not damp */
363 /* boost = bias * freq * (load - target)/target */
364 boost = (load - podgov->p_load_target);
365 boost *= (podgov->p_bias * freq);
366 boost /= (100 * podgov->p_load_target);
368 /* clamp to max boost */
369 boost = (boost < max_boost) ? boost : max_boost;
372 /* calculate new request */
375 /* Maintain average request */
376 podgov->freq_avg = (podgov->freq_avg * podgov->p_smooth) + res;
377 podgov->freq_avg /= (podgov->p_smooth+1);
379 /* Applying damping to frequencies */
380 res = ((damp * res) + ((10 - damp)*podgov->freq_avg)) / 10;
382 /* Convert to hz, limit, and apply */
384 scaling_limit(df, &res);
385 trace_podgov_scaling_state_check(df->previous_freq, res);
389 /*******************************************************************************
390 * freqlist_up(podgov, target, steps)
392 * This function determines the frequency that is "steps" frequency steps
393 * higher compared to the target frequency.
394 ******************************************************************************/
396 int freqlist_up(struct podgov_info_rec *podgov, unsigned long target, int steps)
400 for (i = 0; i < podgov->freq_count; i++)
401 if (podgov->freqlist[i] >= target)
404 pos = min(podgov->freq_count - 1, i + steps);
405 return podgov->freqlist[pos];
408 /*******************************************************************************
409 * freqlist_down(podgov, target, steps)
411 * This function determines the frequency that is "steps" frequency steps
412 * lower compared to the target frequency.
413 ******************************************************************************/
415 int freqlist_down(struct podgov_info_rec *podgov, unsigned long target, int steps)
419 for (i = podgov->freq_count - 1; i >= 0; i--)
420 if (podgov->freqlist[i] <= target)
423 pos = max(0, i - steps);
424 return podgov->freqlist[pos];
427 /*******************************************************************************
428 * podgov_idle_handler(work)
430 * This handler is called after the device has been idle long enough. This
431 * handler forms a (positive) feedback loop by notifying idle to the device.
432 ******************************************************************************/
434 static void podgov_idle_handler(struct work_struct *work)
436 struct delayed_work *idle_timer =
437 container_of(work, struct delayed_work, work);
438 struct podgov_info_rec *podgov =
439 container_of(idle_timer, struct podgov_info_rec, idle_timer);
440 struct devfreq *df = podgov->power_manager;
442 mutex_lock(&df->lock);
444 if (!podgov->enable) {
445 mutex_unlock(&df->lock);
449 if (!podgov->last_event_type &&
450 df->previous_freq > df->min_freq &&
451 podgov->p_user == false)
454 mutex_unlock(&df->lock);
457 #ifdef CONFIG_TEGRA_THROUGHPUT
458 /*******************************************************************************
459 * nvhost_scale3d_set_throughput_hint(hint)
461 * This function can be used to request scaling up or down based on the
462 * required throughput
463 ******************************************************************************/
465 static int nvhost_scale3d_set_throughput_hint(struct notifier_block *nb,
466 unsigned long action, void *data)
468 struct podgov_info_rec *podgov =
469 container_of(nb, struct podgov_info_rec,
470 throughput_hint_notifier);
471 struct devfreq *df = podgov->power_manager;
472 struct device *dev = df->dev.parent;
473 int hint = tegra_throughput_get_hint();
475 unsigned long curr, target;
476 int avg_idle, avg_hint, scale_score;
479 /* make sure the device is alive before doing any scaling */
480 pm_runtime_get_noresume(dev);
481 if (!pm_runtime_active(dev)) {
486 mutex_lock(&df->lock);
490 if (!podgov->enable ||
491 !podgov->p_use_throughput_hint ||
495 trace_podgov_hint(podgov->idle, hint);
496 podgov->last_throughput_hint = ktime_get();
498 curr = df->previous_freq;
500 avg_idle = podgov->idle_avg;
501 smooth = podgov->p_smooth;
503 /* compute averages usings exponential-moving-average */
504 avg_hint = ((smooth*podgov->hint_avg + hint)/(smooth+1));
505 podgov->hint_avg = avg_hint;
507 /* set the target using avg_hint and avg_idle */
509 if (avg_hint < podgov->p_hint_lo_limit) {
510 target = freqlist_up(podgov, curr, 1);
512 scale_score = avg_idle + avg_hint;
513 if (scale_score > podgov->p_scaledown_limit)
514 target = freqlist_down(podgov, curr, 1);
515 else if (scale_score < podgov->p_scaleup_limit
516 && hint < podgov->p_hint_hi_limit)
517 target = freqlist_up(podgov, curr, 1);
520 /* clamp and apply target */
521 scaling_limit(df, &target);
522 if (target != curr) {
523 podgov->block = podgov->p_smooth;
524 trace_podgov_do_scale(df->previous_freq, target);
525 podgov->adjustment_frequency = target;
526 podgov->adjustment_type = ADJUSTMENT_LOCAL;
530 trace_podgov_print_target(idle, avg_idle, curr / 1000000, target, hint,
534 mutex_unlock(&df->lock);
540 /*******************************************************************************
541 * debugfs interface for controlling 3d clock scaling on the fly
542 ******************************************************************************/
544 #ifdef CONFIG_DEBUG_FS
546 static void nvhost_scale3d_debug_init(struct devfreq *df)
548 struct podgov_info_rec *podgov = df->data;
552 snprintf(dirname, sizeof(dirname), "%s_scaling",
553 to_platform_device(df->dev.parent)->name);
558 podgov->debugdir = debugfs_create_dir(dirname, NULL);
559 if (!podgov->debugdir) {
560 pr_err("podgov: can\'t create debugfs directory\n");
564 #define CREATE_PODGOV_FILE(fname) \
566 f = debugfs_create_u32(#fname, S_IRUGO | S_IWUSR, \
567 podgov->debugdir, &podgov->p_##fname); \
569 pr_err("podgov: can\'t create file " #fname "\n"); \
574 CREATE_PODGOV_FILE(block_window);
575 CREATE_PODGOV_FILE(load_max);
576 CREATE_PODGOV_FILE(load_target);
577 CREATE_PODGOV_FILE(bias);
578 CREATE_PODGOV_FILE(damp);
579 CREATE_PODGOV_FILE(use_throughput_hint);
580 CREATE_PODGOV_FILE(hint_hi_limit);
581 CREATE_PODGOV_FILE(hint_lo_limit);
582 CREATE_PODGOV_FILE(scaleup_limit);
583 CREATE_PODGOV_FILE(scaledown_limit);
584 CREATE_PODGOV_FILE(smooth);
585 CREATE_PODGOV_FILE(slowdown_delay);
586 #undef CREATE_PODGOV_FILE
589 static void nvhost_scale3d_debug_deinit(struct devfreq *df)
591 struct podgov_info_rec *podgov = df->data;
593 debugfs_remove_recursive(podgov->debugdir);
597 static void nvhost_scale3d_debug_init(struct devfreq *df)
602 static void nvhost_scale3d_debug_deinit(struct devfreq *df)
608 /*******************************************************************************
609 * sysfs interface for enabling/disabling 3d scaling
610 ******************************************************************************/
612 static ssize_t enable_3d_scaling_show(struct kobject *kobj,
613 struct kobj_attribute *attr,
616 struct podgov_info_rec *podgov = container_of(attr,
617 struct podgov_info_rec,
618 enable_3d_scaling_attr);
621 res = snprintf(buf, PAGE_SIZE, "%d\n", podgov->enable);
626 static ssize_t enable_3d_scaling_store(struct kobject *kobj,
627 struct kobj_attribute *attr,
628 const char *buf, size_t count)
630 struct podgov_info_rec *podgov = container_of(attr,
631 struct podgov_info_rec,
632 enable_3d_scaling_attr);
633 unsigned long val = 0;
635 if (kstrtoul(buf, 10, &val) < 0)
638 podgov_enable(podgov->power_manager, val);
643 /*******************************************************************************
644 * sysfs interface for user space control
645 * user = [0,1] disables / enabled user space control
646 * freq_request is the sysfs node user space writes frequency requests to
647 ******************************************************************************/
649 static ssize_t user_show(struct kobject *kobj,
650 struct kobj_attribute *attr,
653 struct podgov_info_rec *podgov =
654 container_of(attr, struct podgov_info_rec, user_attr);
657 res = snprintf(buf, PAGE_SIZE, "%d\n", podgov->p_user);
662 static ssize_t user_store(struct kobject *kobj,
663 struct kobj_attribute *attr,
664 const char *buf, size_t count)
666 struct podgov_info_rec *podgov =
667 container_of(attr, struct podgov_info_rec, user_attr);
668 unsigned long val = 0;
670 if (kstrtoul(buf, 10, &val) < 0)
673 podgov_set_user_ctl(podgov->power_manager, val);
678 static ssize_t freq_request_show(struct kobject *kobj,
679 struct kobj_attribute *attr,
682 struct podgov_info_rec *podgov =
683 container_of(attr, struct podgov_info_rec, freq_request_attr);
686 res = snprintf(buf, PAGE_SIZE, "%d\n", podgov->p_freq_request);
691 static ssize_t freq_request_store(struct kobject *kobj,
692 struct kobj_attribute *attr,
693 const char *buf, size_t count)
695 struct podgov_info_rec *podgov =
696 container_of(attr, struct podgov_info_rec, freq_request_attr);
697 unsigned long val = 0;
699 if (kstrtoul(buf, 10, &val) < 0)
702 podgov_set_freq_request(podgov->power_manager, val);
707 /*******************************************************************************
708 * nvhost_pod_estimate_freq(df, freq)
710 * This function is called for re-estimating the frequency. The function is
711 * called in three conditions:
713 * (1) Internal request to change the frequency. In this case a new clock
714 * target is immediately set for the device.
715 * (2) Call from the client (something has happened and re-estimation
717 * (3) Some other reason (i.e. periodic call)
719 ******************************************************************************/
721 static int nvhost_pod_estimate_freq(struct devfreq *df,
724 struct podgov_info_rec *podgov = df->data;
725 struct devfreq_dev_status dev_stat;
729 stat = df->profile->get_dev_status(df->dev.parent, &dev_stat);
733 /* Ensure maximal clock when scaling is disabled */
734 if (!podgov->enable) {
735 *freq = df->max_freq;
739 if (podgov->p_user) {
740 *freq = podgov->p_freq_request;
747 /* Local adjustments (i.e. requests from kernel threads) are
750 if (podgov->adjustment_type == ADJUSTMENT_LOCAL) {
752 podgov->adjustment_type = ADJUSTMENT_DEVICE_REQ;
754 /* Do not do unnecessary scaling */
755 scaling_limit(df, &podgov->adjustment_frequency);
757 /* Round the frequency and check if we're already there */
758 if (freqlist_up(podgov, podgov->adjustment_frequency, 0) ==
759 dev_stat.current_frequency)
760 return GET_TARGET_FREQ_DONTSCALE;
762 trace_podgov_estimate_freq(df->previous_freq,
763 podgov->adjustment_frequency);
765 *freq = podgov->adjustment_frequency;
769 *freq = dev_stat.current_frequency;
771 /* Sustain local variables */
772 podgov->last_event_type = dev_stat.busy;
773 podgov->idle = 1000 * (dev_stat.total_time - dev_stat.busy_time);
774 podgov->idle = podgov->idle / dev_stat.total_time;
775 podgov->idle_avg = (podgov->p_smooth * podgov->idle_avg) +
777 podgov->idle_avg = podgov->idle_avg / (podgov->p_smooth + 1);
779 /* if throughput hint enabled, and last hint is recent enough, return */
780 if (podgov->p_use_throughput_hint &&
781 ktime_us_delta(now, podgov->last_throughput_hint) < 1000000)
782 return GET_TARGET_FREQ_DONTSCALE;
785 cancel_delayed_work(&podgov->idle_timer);
786 *freq = scaling_state_check(df, now);
788 /* Launch a work to slowdown the gpu */
789 *freq = scaling_state_check(df, now);
790 schedule_delayed_work(&podgov->idle_timer,
791 msecs_to_jiffies(podgov->p_slowdown_delay));
795 (freqlist_up(podgov, *freq, 0) == dev_stat.current_frequency))
796 return GET_TARGET_FREQ_DONTSCALE;
798 podgov->last_scale = now;
800 trace_podgov_estimate_freq(df->previous_freq, *freq);
806 /*******************************************************************************
807 * nvhost_pod_init(struct devfreq *df)
809 * Governor initialisation.
810 ******************************************************************************/
812 static int nvhost_pod_init(struct devfreq *df)
814 struct podgov_info_rec *podgov;
815 struct platform_device *d = to_platform_device(df->dev.parent);
816 ktime_t now = ktime_get();
817 enum tegra_chipid cid = tegra_get_chipid();
819 struct devfreq_dev_status dev_stat;
822 struct kobj_attribute *attr = NULL;
824 podgov = kzalloc(sizeof(struct podgov_info_rec), GFP_KERNEL);
826 goto err_alloc_podgov;
827 df->data = (void *)podgov;
829 /* Initialise workers */
830 INIT_DELAYED_WORK(&podgov->idle_timer, podgov_idle_handler);
832 /* Set scaling parameter defaults */
835 podgov->p_use_throughput_hint = 1;
837 if (!strcmp(d->name, "vic03.0")) {
838 podgov->p_load_max = 990;
839 podgov->p_load_target = 100;
841 podgov->p_hint_lo_limit = 500;
842 podgov->p_hint_hi_limit = 997;
843 podgov->p_scaleup_limit = 1100;
844 podgov->p_scaledown_limit = 1300;
845 podgov->p_smooth = 30;
849 case TEGRA_CHIPID_TEGRA14:
850 case TEGRA_CHIPID_TEGRA11:
851 case TEGRA_CHIPID_TEGRA12:
852 case TEGRA_CHIPID_TEGRA13:
853 podgov->p_load_max = 900;
854 podgov->p_load_target = 700;
856 podgov->p_hint_lo_limit = 500;
857 podgov->p_hint_hi_limit = 997;
858 podgov->p_scaleup_limit = 1100;
859 podgov->p_scaledown_limit = 1300;
860 podgov->p_smooth = 10;
862 podgov->p_use_throughput_hint = 0;
865 pr_err("%s: un-supported chip id\n", __func__);
866 goto err_unsupported_chip_id;
871 podgov->p_slowdown_delay = 10;
872 podgov->p_block_window = 50000;
873 podgov->adjustment_type = ADJUSTMENT_DEVICE_REQ;
876 /* Reset clock counters */
877 podgov->last_throughput_hint = now;
878 podgov->last_scale = now;
880 podgov->power_manager = df;
882 /* Get the current status of the device */
883 stat = df->profile->get_dev_status(df->dev.parent, &dev_stat);
885 attr = &podgov->enable_3d_scaling_attr;
886 attr->attr.name = "enable_3d_scaling";
887 attr->attr.mode = S_IWUSR | S_IRUGO;
888 attr->show = enable_3d_scaling_show;
889 attr->store = enable_3d_scaling_store;
890 sysfs_attr_init(&attr->attr);
891 if (sysfs_create_file(&df->dev.parent->kobj, &attr->attr))
892 goto err_create_enable_sysfs_entry;
894 attr = &podgov->freq_request_attr;
895 attr->attr.name = "freq_request";
896 attr->attr.mode = S_IWUSR | S_IRUGO;
897 attr->show = freq_request_show;
898 attr->store = freq_request_store;
899 sysfs_attr_init(&attr->attr);
900 if (sysfs_create_file(&df->dev.parent->kobj, &attr->attr))
901 goto err_create_request_sysfs_entry;
903 attr = &podgov->user_attr;
904 attr->attr.name = "user";
905 attr->attr.mode = S_IWUSR | S_IRUGO;
906 attr->show = user_show;
907 attr->store = user_store;
908 sysfs_attr_init(&attr->attr);
909 if (sysfs_create_file(&df->dev.parent->kobj, &attr->attr))
910 goto err_create_user_sysfs_entry;
912 podgov->freq_count = df->profile->max_state;
913 podgov->freqlist = df->profile->freq_table;
914 if (!podgov->freq_count || !podgov->freqlist)
917 /* store the limits */
918 df->min_freq = podgov->freqlist[0];
919 df->max_freq = podgov->freqlist[podgov->freq_count - 1];
920 podgov->p_freq_request = df->max_freq;
922 podgov->idle_avg = 0;
923 podgov->freq_avg = 0;
924 podgov->hint_avg = 0;
926 nvhost_scale3d_debug_init(df);
928 /* register the governor to throughput hint notifier chain */
929 #ifdef CONFIG_TEGRA_THROUGHPUT
930 podgov->throughput_hint_notifier.notifier_call =
931 &nvhost_scale3d_set_throughput_hint;
932 blocking_notifier_chain_register(&throughput_notifier_list,
933 &podgov->throughput_hint_notifier);
939 sysfs_remove_file(&df->dev.parent->kobj, &podgov->user_attr.attr);
940 err_create_user_sysfs_entry:
941 sysfs_remove_file(&df->dev.parent->kobj,
942 &podgov->freq_request_attr.attr);
943 err_create_request_sysfs_entry:
944 sysfs_remove_file(&df->dev.parent->kobj,
945 &podgov->enable_3d_scaling_attr.attr);
946 err_create_enable_sysfs_entry:
947 dev_err(&d->dev, "failed to create sysfs attributes");
948 err_unsupported_chip_id:
954 /*******************************************************************************
955 * nvhost_pod_exit(struct devfreq *df)
957 * Clean up governor data structures
958 ******************************************************************************/
960 static void nvhost_pod_exit(struct devfreq *df)
962 struct podgov_info_rec *podgov = df->data;
964 #ifdef CONFIG_TEGRA_THROUGHPUT
965 blocking_notifier_chain_unregister(&throughput_notifier_list,
966 &podgov->throughput_hint_notifier);
968 cancel_delayed_work(&podgov->idle_timer);
970 sysfs_remove_file(&df->dev.parent->kobj, &podgov->user_attr.attr);
971 sysfs_remove_file(&df->dev.parent->kobj,
972 &podgov->freq_request_attr.attr);
973 sysfs_remove_file(&df->dev.parent->kobj,
974 &podgov->enable_3d_scaling_attr.attr);
976 nvhost_scale3d_debug_deinit(df);
981 static int nvhost_pod_event_handler(struct devfreq *df,
982 unsigned int event, void *data)
987 case DEVFREQ_GOV_START:
988 ret = nvhost_pod_init(df);
990 case DEVFREQ_GOV_STOP:
993 case DEVFREQ_GOV_SUSPEND:
994 nvhost_pod_suspend(df);
1003 static struct devfreq_governor nvhost_podgov = {
1004 .name = "nvhost_podgov",
1005 .get_target_freq = nvhost_pod_estimate_freq,
1006 .event_handler = nvhost_pod_event_handler,
1010 static int __init podgov_init(void)
1012 return devfreq_add_governor(&nvhost_podgov);
1015 static void __exit podgov_exit(void)
1017 devfreq_remove_governor(&nvhost_podgov);
1020 /* governor must be registered before initialising client devices */
1021 rootfs_initcall(podgov_init);
1022 module_exit(podgov_exit);