2 * drivers/video/tegra/host/gr3d/pod_scaling.c
4 * Tegra Graphics Host 3D clock scaling
6 * Copyright (c) 2012-2015, 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(df->dev.parent, 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(df->dev.parent, 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(df->dev.parent, 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(df->dev.parent, 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->dev.parent,
386 df->previous_freq, res);
390 /*******************************************************************************
391 * freqlist_up(podgov, target, steps)
393 * This function determines the frequency that is "steps" frequency steps
394 * higher compared to the target frequency.
395 ******************************************************************************/
397 int freqlist_up(struct podgov_info_rec *podgov, unsigned long target, int steps)
401 for (i = 0; i < podgov->freq_count; i++)
402 if (podgov->freqlist[i] >= target)
405 pos = min(podgov->freq_count - 1, i + steps);
406 return podgov->freqlist[pos];
409 /*******************************************************************************
410 * freqlist_down(podgov, target, steps)
412 * This function determines the frequency that is "steps" frequency steps
413 * lower compared to the target frequency.
414 ******************************************************************************/
416 int freqlist_down(struct podgov_info_rec *podgov, unsigned long target,
421 for (i = podgov->freq_count - 1; i >= 0; i--)
422 if (podgov->freqlist[i] <= target)
425 pos = max(0, i - steps);
426 return podgov->freqlist[pos];
429 /*******************************************************************************
430 * podgov_idle_handler(work)
432 * This handler is called after the device has been idle long enough. This
433 * handler forms a (positive) feedback loop by notifying idle to the device.
434 ******************************************************************************/
436 static void podgov_idle_handler(struct work_struct *work)
438 struct delayed_work *idle_timer =
439 container_of(work, struct delayed_work, work);
440 struct podgov_info_rec *podgov =
441 container_of(idle_timer, struct podgov_info_rec, idle_timer);
442 struct devfreq *df = podgov->power_manager;
444 mutex_lock(&df->lock);
446 if (!podgov->enable) {
447 mutex_unlock(&df->lock);
451 if (!podgov->last_event_type &&
452 df->previous_freq > df->min_freq &&
453 podgov->p_user == false)
456 mutex_unlock(&df->lock);
459 #ifdef CONFIG_TEGRA_THROUGHPUT
460 /*******************************************************************************
461 * nvhost_scale3d_set_throughput_hint(hint)
463 * This function can be used to request scaling up or down based on the
464 * required throughput
465 ******************************************************************************/
467 static int nvhost_scale3d_set_throughput_hint(struct notifier_block *nb,
468 unsigned long action, void *data)
470 struct podgov_info_rec *podgov =
471 container_of(nb, struct podgov_info_rec,
472 throughput_hint_notifier);
473 struct devfreq *df = podgov->power_manager;
474 struct device *dev = df->dev.parent;
475 int hint = tegra_throughput_get_hint();
477 unsigned long curr, target;
478 int avg_idle, avg_hint, scale_score;
481 /* make sure the device is alive before doing any scaling */
482 pm_runtime_get_noresume(dev);
483 if (!pm_runtime_active(dev)) {
488 mutex_lock(&df->lock);
492 if (!podgov->enable ||
493 !podgov->p_use_throughput_hint ||
497 trace_podgov_hint(df->dev.parent, podgov->idle, hint);
498 podgov->last_throughput_hint = ktime_get();
500 curr = df->previous_freq;
502 avg_idle = podgov->idle_avg;
503 smooth = podgov->p_smooth;
505 /* compute averages usings exponential-moving-average */
506 avg_hint = ((smooth*podgov->hint_avg + hint)/(smooth+1));
507 podgov->hint_avg = avg_hint;
509 /* set the target using avg_hint and avg_idle */
511 if (avg_hint < podgov->p_hint_lo_limit) {
512 target = freqlist_up(podgov, curr, 1);
514 scale_score = avg_idle + avg_hint;
515 if (scale_score > podgov->p_scaledown_limit)
516 target = freqlist_down(podgov, curr, 1);
517 else if (scale_score < podgov->p_scaleup_limit
518 && hint < podgov->p_hint_hi_limit)
519 target = freqlist_up(podgov, curr, 1);
522 /* clamp and apply target */
523 scaling_limit(df, &target);
524 if (target != curr) {
525 podgov->block = podgov->p_smooth;
526 trace_podgov_do_scale(df->dev.parent,
527 df->previous_freq, target);
528 podgov->adjustment_frequency = target;
529 podgov->adjustment_type = ADJUSTMENT_LOCAL;
533 trace_podgov_print_target(df->dev.parent, idle, avg_idle,
534 curr / 1000000, target, hint, avg_hint);
537 mutex_unlock(&df->lock);
543 /*******************************************************************************
544 * debugfs interface for controlling 3d clock scaling on the fly
545 ******************************************************************************/
547 #ifdef CONFIG_DEBUG_FS
549 static void nvhost_scale3d_debug_init(struct devfreq *df)
551 struct podgov_info_rec *podgov = df->data;
555 snprintf(dirname, sizeof(dirname), "%s_scaling",
556 to_platform_device(df->dev.parent)->name);
561 podgov->debugdir = debugfs_create_dir(dirname, NULL);
562 if (!podgov->debugdir) {
563 pr_err("podgov: can\'t create debugfs directory\n");
567 #define CREATE_PODGOV_FILE(fname) \
569 f = debugfs_create_u32(#fname, S_IRUGO | S_IWUSR, \
570 podgov->debugdir, &podgov->p_##fname); \
572 pr_err("podgov: can\'t create file " #fname "\n"); \
577 CREATE_PODGOV_FILE(block_window);
578 CREATE_PODGOV_FILE(load_max);
579 CREATE_PODGOV_FILE(load_target);
580 CREATE_PODGOV_FILE(bias);
581 CREATE_PODGOV_FILE(damp);
582 CREATE_PODGOV_FILE(use_throughput_hint);
583 CREATE_PODGOV_FILE(hint_hi_limit);
584 CREATE_PODGOV_FILE(hint_lo_limit);
585 CREATE_PODGOV_FILE(scaleup_limit);
586 CREATE_PODGOV_FILE(scaledown_limit);
587 CREATE_PODGOV_FILE(smooth);
588 CREATE_PODGOV_FILE(slowdown_delay);
589 #undef CREATE_PODGOV_FILE
592 static void nvhost_scale3d_debug_deinit(struct devfreq *df)
594 struct podgov_info_rec *podgov = df->data;
596 debugfs_remove_recursive(podgov->debugdir);
600 static void nvhost_scale3d_debug_init(struct devfreq *df)
605 static void nvhost_scale3d_debug_deinit(struct devfreq *df)
611 /*******************************************************************************
612 * sysfs interface for enabling/disabling 3d scaling
613 ******************************************************************************/
615 static ssize_t enable_3d_scaling_show(struct kobject *kobj,
616 struct kobj_attribute *attr,
619 struct podgov_info_rec *podgov = container_of(attr,
620 struct podgov_info_rec,
621 enable_3d_scaling_attr);
624 res = snprintf(buf, PAGE_SIZE, "%d\n", podgov->enable);
629 static ssize_t enable_3d_scaling_store(struct kobject *kobj,
630 struct kobj_attribute *attr,
631 const char *buf, size_t count)
633 struct podgov_info_rec *podgov = container_of(attr,
634 struct podgov_info_rec,
635 enable_3d_scaling_attr);
636 unsigned long val = 0;
638 if (kstrtoul(buf, 10, &val) < 0)
641 podgov_enable(podgov->power_manager, val);
646 /*******************************************************************************
647 * sysfs interface for user space control
648 * user = [0,1] disables / enabled user space control
649 * freq_request is the sysfs node user space writes frequency requests to
650 ******************************************************************************/
652 static ssize_t user_show(struct kobject *kobj,
653 struct kobj_attribute *attr,
656 struct podgov_info_rec *podgov =
657 container_of(attr, struct podgov_info_rec, user_attr);
660 res = snprintf(buf, PAGE_SIZE, "%d\n", podgov->p_user);
665 static ssize_t user_store(struct kobject *kobj,
666 struct kobj_attribute *attr,
667 const char *buf, size_t count)
669 struct podgov_info_rec *podgov =
670 container_of(attr, struct podgov_info_rec, user_attr);
671 unsigned long val = 0;
673 if (kstrtoul(buf, 10, &val) < 0)
676 podgov_set_user_ctl(podgov->power_manager, val);
681 static ssize_t freq_request_show(struct kobject *kobj,
682 struct kobj_attribute *attr,
685 struct podgov_info_rec *podgov =
686 container_of(attr, struct podgov_info_rec, freq_request_attr);
689 res = snprintf(buf, PAGE_SIZE, "%d\n", podgov->p_freq_request);
694 static ssize_t freq_request_store(struct kobject *kobj,
695 struct kobj_attribute *attr,
696 const char *buf, size_t count)
698 struct podgov_info_rec *podgov =
699 container_of(attr, struct podgov_info_rec, freq_request_attr);
700 unsigned long val = 0;
702 if (kstrtoul(buf, 10, &val) < 0)
705 podgov_set_freq_request(podgov->power_manager, val);
710 /*******************************************************************************
711 * nvhost_pod_estimate_freq(df, freq)
713 * This function is called for re-estimating the frequency. The function is
714 * called in three conditions:
716 * (1) Internal request to change the frequency. In this case a new clock
717 * target is immediately set for the device.
718 * (2) Call from the client (something has happened and re-estimation
720 * (3) Some other reason (i.e. periodic call)
722 ******************************************************************************/
724 static int nvhost_pod_estimate_freq(struct devfreq *df,
727 struct podgov_info_rec *podgov = df->data;
728 struct devfreq_dev_status dev_stat;
732 stat = df->profile->get_dev_status(df->dev.parent, &dev_stat);
736 /* Ensure maximal clock when scaling is disabled */
737 if (!podgov->enable) {
738 *freq = df->max_freq;
742 if (podgov->p_user) {
743 *freq = podgov->p_freq_request;
750 /* Local adjustments (i.e. requests from kernel threads) are
753 if (podgov->adjustment_type == ADJUSTMENT_LOCAL) {
755 podgov->adjustment_type = ADJUSTMENT_DEVICE_REQ;
757 /* Do not do unnecessary scaling */
758 scaling_limit(df, &podgov->adjustment_frequency);
760 /* Round the frequency and check if we're already there */
761 if (freqlist_up(podgov, podgov->adjustment_frequency, 0) ==
762 dev_stat.current_frequency)
763 return GET_TARGET_FREQ_DONTSCALE;
765 trace_podgov_estimate_freq(df->dev.parent,
767 podgov->adjustment_frequency);
769 *freq = podgov->adjustment_frequency;
773 *freq = dev_stat.current_frequency;
775 /* Sustain local variables */
776 podgov->last_event_type = dev_stat.busy;
777 podgov->idle = 1000 * (dev_stat.total_time - dev_stat.busy_time);
778 podgov->idle = podgov->idle / dev_stat.total_time;
779 podgov->idle_avg = (podgov->p_smooth * podgov->idle_avg) +
781 podgov->idle_avg = podgov->idle_avg / (podgov->p_smooth + 1);
783 /* if throughput hint enabled, and last hint is recent enough, return */
784 if (podgov->p_use_throughput_hint &&
785 ktime_us_delta(now, podgov->last_throughput_hint) < 1000000)
786 return GET_TARGET_FREQ_DONTSCALE;
789 cancel_delayed_work(&podgov->idle_timer);
790 *freq = scaling_state_check(df, now);
792 /* Launch a work to slowdown the gpu */
793 *freq = scaling_state_check(df, now);
794 schedule_delayed_work(&podgov->idle_timer,
795 msecs_to_jiffies(podgov->p_slowdown_delay));
799 (freqlist_up(podgov, *freq, 0) == dev_stat.current_frequency))
800 return GET_TARGET_FREQ_DONTSCALE;
802 podgov->last_scale = now;
804 trace_podgov_estimate_freq(df->dev.parent, df->previous_freq, *freq);
810 /*******************************************************************************
811 * nvhost_pod_init(struct devfreq *df)
813 * Governor initialisation.
814 ******************************************************************************/
816 static int nvhost_pod_init(struct devfreq *df)
818 struct podgov_info_rec *podgov;
819 struct platform_device *d = to_platform_device(df->dev.parent);
820 ktime_t now = ktime_get();
821 enum tegra_chipid cid = tegra_get_chipid();
823 struct devfreq_dev_status dev_stat;
826 struct kobj_attribute *attr = NULL;
828 podgov = kzalloc(sizeof(struct podgov_info_rec), GFP_KERNEL);
830 goto err_alloc_podgov;
831 df->data = (void *)podgov;
833 /* Initialise workers */
834 INIT_DELAYED_WORK(&podgov->idle_timer, podgov_idle_handler);
836 /* Set scaling parameter defaults */
839 podgov->p_use_throughput_hint = 1;
841 if (!strcmp(d->name, "vic03.0")) {
842 podgov->p_load_max = 100;
843 podgov->p_load_target = 10;
845 podgov->p_hint_lo_limit = 500;
846 podgov->p_hint_hi_limit = 997;
847 podgov->p_scaleup_limit = 1100;
848 podgov->p_scaledown_limit = 1300;
849 podgov->p_smooth = 30;
853 case TEGRA_CHIPID_TEGRA14:
854 case TEGRA_CHIPID_TEGRA11:
855 case TEGRA_CHIPID_TEGRA12:
856 case TEGRA_CHIPID_TEGRA13:
857 podgov->p_load_max = 900;
858 podgov->p_load_target = 700;
860 podgov->p_hint_lo_limit = 500;
861 podgov->p_hint_hi_limit = 997;
862 podgov->p_scaleup_limit = 1100;
863 podgov->p_scaledown_limit = 1300;
864 podgov->p_smooth = 10;
866 podgov->p_use_throughput_hint = 0;
869 pr_err("%s: un-supported chip id\n", __func__);
870 goto err_unsupported_chip_id;
875 podgov->p_slowdown_delay = 10;
876 podgov->p_block_window = 50000;
877 podgov->adjustment_type = ADJUSTMENT_DEVICE_REQ;
880 /* Reset clock counters */
881 podgov->last_throughput_hint = now;
882 podgov->last_scale = now;
884 podgov->power_manager = df;
886 /* Get the current status of the device */
887 stat = df->profile->get_dev_status(df->dev.parent, &dev_stat);
889 attr = &podgov->enable_3d_scaling_attr;
890 attr->attr.name = "enable_3d_scaling";
891 attr->attr.mode = S_IWUSR | S_IRUGO;
892 attr->show = enable_3d_scaling_show;
893 attr->store = enable_3d_scaling_store;
894 sysfs_attr_init(&attr->attr);
895 if (sysfs_create_file(&df->dev.parent->kobj, &attr->attr))
896 goto err_create_enable_sysfs_entry;
898 attr = &podgov->freq_request_attr;
899 attr->attr.name = "freq_request";
900 attr->attr.mode = S_IWUSR | S_IRUGO;
901 attr->show = freq_request_show;
902 attr->store = freq_request_store;
903 sysfs_attr_init(&attr->attr);
904 if (sysfs_create_file(&df->dev.parent->kobj, &attr->attr))
905 goto err_create_request_sysfs_entry;
907 attr = &podgov->user_attr;
908 attr->attr.name = "user";
909 attr->attr.mode = S_IWUSR | S_IRUGO;
910 attr->show = user_show;
911 attr->store = user_store;
912 sysfs_attr_init(&attr->attr);
913 if (sysfs_create_file(&df->dev.parent->kobj, &attr->attr))
914 goto err_create_user_sysfs_entry;
916 podgov->freq_count = df->profile->max_state;
917 podgov->freqlist = df->profile->freq_table;
918 if (!podgov->freq_count || !podgov->freqlist)
921 /* store the limits */
922 df->min_freq = podgov->freqlist[0];
923 df->max_freq = podgov->freqlist[podgov->freq_count - 1];
924 podgov->p_freq_request = df->max_freq;
926 podgov->idle_avg = 0;
927 podgov->freq_avg = 0;
928 podgov->hint_avg = 0;
930 nvhost_scale3d_debug_init(df);
932 /* register the governor to throughput hint notifier chain */
933 #ifdef CONFIG_TEGRA_THROUGHPUT
934 podgov->throughput_hint_notifier.notifier_call =
935 &nvhost_scale3d_set_throughput_hint;
936 blocking_notifier_chain_register(&throughput_notifier_list,
937 &podgov->throughput_hint_notifier);
943 sysfs_remove_file(&df->dev.parent->kobj, &podgov->user_attr.attr);
944 err_create_user_sysfs_entry:
945 sysfs_remove_file(&df->dev.parent->kobj,
946 &podgov->freq_request_attr.attr);
947 err_create_request_sysfs_entry:
948 sysfs_remove_file(&df->dev.parent->kobj,
949 &podgov->enable_3d_scaling_attr.attr);
950 err_create_enable_sysfs_entry:
951 dev_err(&d->dev, "failed to create sysfs attributes");
952 err_unsupported_chip_id:
958 /*******************************************************************************
959 * nvhost_pod_exit(struct devfreq *df)
961 * Clean up governor data structures
962 ******************************************************************************/
964 static void nvhost_pod_exit(struct devfreq *df)
966 struct podgov_info_rec *podgov = df->data;
968 #ifdef CONFIG_TEGRA_THROUGHPUT
969 blocking_notifier_chain_unregister(&throughput_notifier_list,
970 &podgov->throughput_hint_notifier);
972 cancel_delayed_work(&podgov->idle_timer);
974 sysfs_remove_file(&df->dev.parent->kobj, &podgov->user_attr.attr);
975 sysfs_remove_file(&df->dev.parent->kobj,
976 &podgov->freq_request_attr.attr);
977 sysfs_remove_file(&df->dev.parent->kobj,
978 &podgov->enable_3d_scaling_attr.attr);
980 nvhost_scale3d_debug_deinit(df);
985 static int nvhost_pod_event_handler(struct devfreq *df,
986 unsigned int event, void *data)
991 case DEVFREQ_GOV_START:
992 ret = nvhost_pod_init(df);
994 case DEVFREQ_GOV_STOP:
997 case DEVFREQ_GOV_SUSPEND:
998 nvhost_pod_suspend(df);
1007 static struct devfreq_governor nvhost_podgov = {
1008 .name = "nvhost_podgov",
1009 .get_target_freq = nvhost_pod_estimate_freq,
1010 .event_handler = nvhost_pod_event_handler,
1014 static int __init podgov_init(void)
1016 return devfreq_add_governor(&nvhost_podgov);
1019 static void __exit podgov_exit(void)
1021 devfreq_remove_governor(&nvhost_podgov);
1024 /* governor must be registered before initialising client devices */
1025 rootfs_initcall(podgov_init);
1026 module_exit(podgov_exit);