]> err.no Git - linux-2.6/blob - arch/powerpc/platforms/cell/cbe_thermal.c
0d486fd424a98319b8943e29effbfdac268ae655
[linux-2.6] / arch / powerpc / platforms / cell / cbe_thermal.c
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 inline u8 reg_to_temp(u8 reg_value)
35 {
36        return ((reg_value & 0x3f) << 1) + 65;
37 }
38
39 static struct cbe_pmd_regs __iomem *get_pmd_regs(struct sys_device *sysdev)
40 {
41         struct spu *spu;
42
43         spu = container_of(sysdev, struct spu, sysdev);
44
45         return cbe_get_pmd_regs(spu_devnode(spu));
46 }
47
48 /* returns the value for a given spu in a given register */
49 static u8 spu_read_register_value(struct sys_device *sysdev, union spe_reg __iomem *reg)
50 {
51         const unsigned int *id;
52         union spe_reg value;
53         struct spu *spu;
54
55         /* getting the id from the reg attribute will not work on future device-tree layouts
56          * in future we should store the id to the spu struct and use it here */
57         spu = container_of(sysdev, struct spu, sysdev);
58         id = of_get_property(spu_devnode(spu), "reg", NULL);
59         value.val = in_be64(&reg->val);
60
61         return value.spe[*id];
62 }
63
64 static ssize_t spu_show_temp(struct sys_device *sysdev, char *buf)
65 {
66         u8 value;
67         struct cbe_pmd_regs __iomem *pmd_regs;
68
69         pmd_regs = get_pmd_regs(sysdev);
70
71         value = spu_read_register_value(sysdev, &pmd_regs->ts_ctsr1);
72
73         return sprintf(buf, "%d\n", reg_to_temp(value));
74 }
75
76 static ssize_t ppe_show_temp(struct sys_device *sysdev, char *buf, int pos)
77 {
78         struct cbe_pmd_regs __iomem *pmd_regs;
79         u64 value;
80
81         pmd_regs = cbe_get_cpu_pmd_regs(sysdev->id);
82         value = in_be64(&pmd_regs->ts_ctsr2);
83
84         value = (value >> pos) & 0x3f;
85
86         return sprintf(buf, "%d\n", reg_to_temp(value));
87 }
88
89
90 /* shows the temperature of the DTS on the PPE,
91  * located near the linear thermal sensor */
92 static ssize_t ppe_show_temp0(struct sys_device *sysdev, char *buf)
93 {
94         return ppe_show_temp(sysdev, buf, 32);
95 }
96
97 /* shows the temperature of the second DTS on the PPE */
98 static ssize_t ppe_show_temp1(struct sys_device *sysdev, char *buf)
99 {
100         return ppe_show_temp(sysdev, buf, 0);
101 }
102
103 static struct sysdev_attribute attr_spu_temperature = {
104         .attr = {.name = "temperature", .mode = 0400 },
105         .show = spu_show_temp,
106 };
107
108 static struct attribute *spu_attributes[] = {
109         &attr_spu_temperature.attr,
110         NULL,
111 };
112
113 static struct attribute_group spu_attribute_group = {
114         .name   = "thermal",
115         .attrs  = spu_attributes,
116 };
117
118 static struct sysdev_attribute attr_ppe_temperature0 = {
119         .attr = {.name = "temperature0", .mode = 0400 },
120         .show = ppe_show_temp0,
121 };
122
123 static struct sysdev_attribute attr_ppe_temperature1 = {
124         .attr = {.name = "temperature1", .mode = 0400 },
125         .show = ppe_show_temp1,
126 };
127
128 static struct attribute *ppe_attributes[] = {
129         &attr_ppe_temperature0.attr,
130         &attr_ppe_temperature1.attr,
131         NULL,
132 };
133
134 static struct attribute_group ppe_attribute_group = {
135         .name   = "thermal",
136         .attrs  = ppe_attributes,
137 };
138
139 /*
140  * initialize throttling with default values
141  */
142 static void __init init_default_values(void)
143 {
144         int cpu;
145         struct cbe_pmd_regs __iomem *pmd_regs;
146         struct sys_device *sysdev;
147         union ppe_spe_reg tpr;
148         union spe_reg str1;
149         u64 str2;
150         union spe_reg cr1;
151         u64 cr2;
152
153         /* TPR defaults */
154         /* ppe
155          *      1F - no full stop
156          *      08 - dynamic throttling starts if over 80 degrees
157          *      03 - dynamic throttling ceases if below 70 degrees */
158         tpr.ppe = 0x1F0803;
159         /* spe
160          *      10 - full stopped when over 96 degrees
161          *      08 - dynamic throttling starts if over 80 degrees
162          *      03 - dynamic throttling ceases if below 70 degrees
163          */
164         tpr.spe = 0x100803;
165
166         /* STR defaults */
167         /* str1
168          *      10 - stop 16 of 32 cycles
169          */
170         str1.val = 0x1010101010101010ull;
171         /* str2
172          *      10 - stop 16 of 32 cycles
173          */
174         str2 = 0x10;
175
176         /* CR defaults */
177         /* cr1
178          *      4 - normal operation
179          */
180         cr1.val = 0x0404040404040404ull;
181         /* cr2
182          *      4 - normal operation
183          */
184         cr2 = 0x04;
185
186         for_each_possible_cpu (cpu) {
187                 pr_debug("processing cpu %d\n", cpu);
188                 sysdev = get_cpu_sysdev(cpu);
189                 pmd_regs = cbe_get_cpu_pmd_regs(sysdev->id);
190
191                 out_be64(&pmd_regs->tm_str2, str2);
192                 out_be64(&pmd_regs->tm_str1.val, str1.val);
193                 out_be64(&pmd_regs->tm_tpr.val, tpr.val);
194                 out_be64(&pmd_regs->tm_cr1.val, cr1.val);
195                 out_be64(&pmd_regs->tm_cr2, cr2);
196         }
197 }
198
199
200 static int __init thermal_init(void)
201 {
202         init_default_values();
203
204         spu_add_sysdev_attr_group(&spu_attribute_group);
205         cpu_add_sysdev_attr_group(&ppe_attribute_group);
206
207         return 0;
208 }
209 module_init(thermal_init);
210
211 static void __exit thermal_exit(void)
212 {
213         spu_remove_sysdev_attr_group(&spu_attribute_group);
214         cpu_remove_sysdev_attr_group(&ppe_attribute_group);
215 }
216 module_exit(thermal_exit);
217
218 MODULE_LICENSE("GPL");
219 MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>");
220