diff options
Diffstat (limited to 'arch/powerpc/platforms/cell/cbe_thermal.c')
-rw-r--r-- | arch/powerpc/platforms/cell/cbe_thermal.c | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/arch/powerpc/platforms/cell/cbe_thermal.c b/arch/powerpc/platforms/cell/cbe_thermal.c new file mode 100644 index 00000000000..616a0a3fd0e --- /dev/null +++ b/arch/powerpc/platforms/cell/cbe_thermal.c | |||
@@ -0,0 +1,226 @@ | |||
1 | /* | ||
2 | * thermal support for the cell processor | ||
3 | * | ||
4 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 | ||
5 | * | ||
6 | * Author: Christian Krafft <krafft@de.ibm.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2, or (at your option) | ||
11 | * any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | */ | ||
22 | |||
23 | #include <linux/module.h> | ||
24 | #include <linux/sysdev.h> | ||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/cpu.h> | ||
27 | #include <asm/spu.h> | ||
28 | #include <asm/io.h> | ||
29 | #include <asm/prom.h> | ||
30 | |||
31 | #include "cbe_regs.h" | ||
32 | #include "spu_priv1_mmio.h" | ||
33 | |||
34 | static struct cbe_pmd_regs __iomem *get_pmd_regs(struct sys_device *sysdev) | ||
35 | { | ||
36 | struct spu *spu; | ||
37 | |||
38 | spu = container_of(sysdev, struct spu, sysdev); | ||
39 | |||
40 | return cbe_get_pmd_regs(spu_devnode(spu)); | ||
41 | } | ||
42 | |||
43 | /* returns the value for a given spu in a given register */ | ||
44 | static u8 spu_read_register_value(struct sys_device *sysdev, union spe_reg __iomem *reg) | ||
45 | { | ||
46 | unsigned int *id; | ||
47 | union spe_reg value; | ||
48 | struct spu *spu; | ||
49 | |||
50 | /* getting the id from the reg attribute will not work on future device-tree layouts | ||
51 | * in future we should store the id to the spu struct and use it here */ | ||
52 | spu = container_of(sysdev, struct spu, sysdev); | ||
53 | id = (unsigned int *)get_property(spu_devnode(spu), "reg", NULL); | ||
54 | value.val = in_be64(®->val); | ||
55 | |||
56 | return value.spe[*id]; | ||
57 | } | ||
58 | |||
59 | static ssize_t spu_show_temp(struct sys_device *sysdev, char *buf) | ||
60 | { | ||
61 | int value; | ||
62 | struct cbe_pmd_regs __iomem *pmd_regs; | ||
63 | |||
64 | pmd_regs = get_pmd_regs(sysdev); | ||
65 | |||
66 | value = spu_read_register_value(sysdev, &pmd_regs->ts_ctsr1); | ||
67 | /* clear all other bits */ | ||
68 | value &= 0x3F; | ||
69 | /* temp is stored in steps of 2 degrees */ | ||
70 | value *= 2; | ||
71 | /* base temp is 65 degrees */ | ||
72 | value += 65; | ||
73 | |||
74 | return sprintf(buf, "%d\n", (int) value); | ||
75 | } | ||
76 | |||
77 | static ssize_t ppe_show_temp(struct sys_device *sysdev, char *buf, int pos) | ||
78 | { | ||
79 | struct cbe_pmd_regs __iomem *pmd_regs; | ||
80 | u64 value; | ||
81 | |||
82 | pmd_regs = cbe_get_cpu_pmd_regs(sysdev->id); | ||
83 | value = in_be64(&pmd_regs->ts_ctsr2); | ||
84 | |||
85 | /* access the corresponding byte */ | ||
86 | value >>= pos; | ||
87 | /* clear all other bits */ | ||
88 | value &= 0x3F; | ||
89 | /* temp is stored in steps of 2 degrees */ | ||
90 | value *= 2; | ||
91 | /* base temp is 65 degrees */ | ||
92 | value += 65; | ||
93 | |||
94 | return sprintf(buf, "%d\n", (int) value); | ||
95 | } | ||
96 | |||
97 | |||
98 | /* shows the temperature of the DTS on the PPE, | ||
99 | * located near the linear thermal sensor */ | ||
100 | static ssize_t ppe_show_temp0(struct sys_device *sysdev, char *buf) | ||
101 | { | ||
102 | return ppe_show_temp(sysdev, buf, 32); | ||
103 | } | ||
104 | |||
105 | /* shows the temperature of the second DTS on the PPE */ | ||
106 | static ssize_t ppe_show_temp1(struct sys_device *sysdev, char *buf) | ||
107 | { | ||
108 | return ppe_show_temp(sysdev, buf, 0); | ||
109 | } | ||
110 | |||
111 | static struct sysdev_attribute attr_spu_temperature = { | ||
112 | .attr = {.name = "temperature", .mode = 0400 }, | ||
113 | .show = spu_show_temp, | ||
114 | }; | ||
115 | |||
116 | static struct attribute *spu_attributes[] = { | ||
117 | &attr_spu_temperature.attr, | ||
118 | }; | ||
119 | |||
120 | static struct attribute_group spu_attribute_group = { | ||
121 | .name = "thermal", | ||
122 | .attrs = spu_attributes, | ||
123 | }; | ||
124 | |||
125 | static struct sysdev_attribute attr_ppe_temperature0 = { | ||
126 | .attr = {.name = "temperature0", .mode = 0400 }, | ||
127 | .show = ppe_show_temp0, | ||
128 | }; | ||
129 | |||
130 | static struct sysdev_attribute attr_ppe_temperature1 = { | ||
131 | .attr = {.name = "temperature1", .mode = 0400 }, | ||
132 | .show = ppe_show_temp1, | ||
133 | }; | ||
134 | |||
135 | static struct attribute *ppe_attributes[] = { | ||
136 | &attr_ppe_temperature0.attr, | ||
137 | &attr_ppe_temperature1.attr, | ||
138 | }; | ||
139 | |||
140 | static struct attribute_group ppe_attribute_group = { | ||
141 | .name = "thermal", | ||
142 | .attrs = ppe_attributes, | ||
143 | }; | ||
144 | |||
145 | /* | ||
146 | * initialize throttling with default values | ||
147 | */ | ||
148 | static void __init init_default_values(void) | ||
149 | { | ||
150 | int cpu; | ||
151 | struct cbe_pmd_regs __iomem *pmd_regs; | ||
152 | struct sys_device *sysdev; | ||
153 | union ppe_spe_reg tpr; | ||
154 | union spe_reg str1; | ||
155 | u64 str2; | ||
156 | union spe_reg cr1; | ||
157 | u64 cr2; | ||
158 | |||
159 | /* TPR defaults */ | ||
160 | /* ppe | ||
161 | * 1F - no full stop | ||
162 | * 08 - dynamic throttling starts if over 80 degrees | ||
163 | * 03 - dynamic throttling ceases if below 70 degrees */ | ||
164 | tpr.ppe = 0x1F0803; | ||
165 | /* spe | ||
166 | * 10 - full stopped when over 96 degrees | ||
167 | * 08 - dynamic throttling starts if over 80 degrees | ||
168 | * 03 - dynamic throttling ceases if below 70 degrees | ||
169 | */ | ||
170 | tpr.spe = 0x100803; | ||
171 | |||
172 | /* STR defaults */ | ||
173 | /* str1 | ||
174 | * 10 - stop 16 of 32 cycles | ||
175 | */ | ||
176 | str1.val = 0x1010101010101010ull; | ||
177 | /* str2 | ||
178 | * 10 - stop 16 of 32 cycles | ||
179 | */ | ||
180 | str2 = 0x10; | ||
181 | |||
182 | /* CR defaults */ | ||
183 | /* cr1 | ||
184 | * 4 - normal operation | ||
185 | */ | ||
186 | cr1.val = 0x0404040404040404ull; | ||
187 | /* cr2 | ||
188 | * 4 - normal operation | ||
189 | */ | ||
190 | cr2 = 0x04; | ||
191 | |||
192 | for_each_possible_cpu (cpu) { | ||
193 | pr_debug("processing cpu %d\n", cpu); | ||
194 | sysdev = get_cpu_sysdev(cpu); | ||
195 | pmd_regs = cbe_get_cpu_pmd_regs(sysdev->id); | ||
196 | |||
197 | out_be64(&pmd_regs->tm_str2, str2); | ||
198 | out_be64(&pmd_regs->tm_str1.val, str1.val); | ||
199 | out_be64(&pmd_regs->tm_tpr.val, tpr.val); | ||
200 | out_be64(&pmd_regs->tm_cr1.val, cr1.val); | ||
201 | out_be64(&pmd_regs->tm_cr2, cr2); | ||
202 | } | ||
203 | } | ||
204 | |||
205 | |||
206 | static int __init thermal_init(void) | ||
207 | { | ||
208 | init_default_values(); | ||
209 | |||
210 | spu_add_sysdev_attr_group(&spu_attribute_group); | ||
211 | cpu_add_sysdev_attr_group(&ppe_attribute_group); | ||
212 | |||
213 | return 0; | ||
214 | } | ||
215 | module_init(thermal_init); | ||
216 | |||
217 | static void __exit thermal_exit(void) | ||
218 | { | ||
219 | spu_remove_sysdev_attr_group(&spu_attribute_group); | ||
220 | cpu_remove_sysdev_attr_group(&ppe_attribute_group); | ||
221 | } | ||
222 | module_exit(thermal_exit); | ||
223 | |||
224 | MODULE_LICENSE("GPL"); | ||
225 | MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>"); | ||
226 | |||