]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/device-ti-proprietary-open.git/blob - jacinto6/sgx_src/eurasia_km/services4/system/omap4/sgxfreq_cool.c
proprietary-open: jacinto6: add graphics kernel module sources
[android-sdk/device-ti-proprietary-open.git] / jacinto6 / sgx_src / eurasia_km / services4 / system / omap4 / sgxfreq_cool.c
1 /*
2  * Copyright (C) 2012 Texas Instruments, Inc
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 as published by
6  * the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  *
13  * You should have received a copy of the GNU General Public License along with
14  * this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
17 #include <linux/thermal_framework.h>
19 static int cool_device(struct thermal_dev *dev, int cooling_level);
21 static struct cool_data {
22         int freq_cnt;
23         unsigned long *freq_list;
24 } cd;
26 static struct thermal_dev_ops cool_dev_ops = {
27         .cool_device = cool_device,
28 };
30 static struct thermal_dev cool_dev = {
31         .name = "gpu_cooling.0",
32         .domain_name = "gpu",
33         .dev_ops = &cool_dev_ops,
34 };
36 static struct thermal_dev case_cool_dev = {
37         .name = "gpu_cooling.1",
38         .domain_name = "case",
39         .dev_ops = &cool_dev_ops,
40 };
42 static unsigned int gpu_cooling_level;
43 #if defined(CONFIG_CASE_TEMP_GOVERNOR)
44 static unsigned int case_cooling_level;
45 #endif
47 int cool_init(void)
48 {
49         int ret;
50         cd.freq_cnt = sgxfreq_get_freq_list(&cd.freq_list);
51         if (!cd.freq_cnt || !cd.freq_list)
52                 return -EINVAL;
54         ret = thermal_cooling_dev_register(&cool_dev);
55         if (ret)
56                 return ret;
58         return thermal_cooling_dev_register(&case_cool_dev);
59 }
61 void cool_deinit(void)
62 {
63         thermal_cooling_dev_unregister(&cool_dev);
64         thermal_cooling_dev_unregister(&case_cool_dev);
65 }
67 static int cool_device(struct thermal_dev *dev, int cooling_level)
68 {
69         int freq_max_index, freq_limit_index;
71 #if defined(CONFIG_CASE_TEMP_GOVERNOR)
72         if (!strcmp(dev->domain_name, "case"))
73         {
74                 int tmp = 0;
75                 tmp = cooling_level - case_subzone_number;
76                 if (tmp < 0)
77                         tmp = 0;
78                 case_cooling_level = tmp;
79         }
80         else
81 #endif
82         {
83                gpu_cooling_level = cooling_level;
84         }
86         freq_max_index = cd.freq_cnt - 1;
87 #if defined(CONFIG_CASE_TEMP_GOVERNOR)
88         if (case_cooling_level > gpu_cooling_level)
89         {
90                 freq_limit_index = freq_max_index - case_cooling_level;
91         }
92         else
93 #endif
94         {
95                 freq_limit_index = freq_max_index - gpu_cooling_level;
96         }
98         if (freq_limit_index < 0)
99                 freq_limit_index = 0;
101         sgxfreq_set_freq_limit(cd.freq_list[freq_limit_index]);
103         return 0;