2 * thermal support for the cell processor
4 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
6 * Author: Christian Krafft <krafft@de.ibm.com>
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)
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.
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.
23 #include <linux/module.h>
24 #include <linux/sysdev.h>
25 #include <linux/kernel.h>
26 #include <linux/cpu.h>
33 static struct cbe_pmd_regs __iomem *get_pmd_regs(struct sys_device *sysdev)
37 spu = container_of(sysdev, struct spu, sysdev);
39 return cbe_get_pmd_regs(spu->devnode);
42 /* returns the value for a given spu in a given register */
43 static u8 spu_read_register_value(struct sys_device *sysdev, union spe_reg __iomem *reg)
49 /* getting the id from the reg attribute will not work on future device-tree layouts
50 * in future we should store the id to the spu struct and use it here */
51 spu = container_of(sysdev, struct spu, sysdev);
52 id = (unsigned int *)get_property(spu->devnode, "reg", NULL);
53 value.val = in_be64(®->val);
55 return value.spe[*id];
58 static ssize_t spu_show_temp(struct sys_device *sysdev, char *buf)
61 struct cbe_pmd_regs __iomem *pmd_regs;
63 pmd_regs = get_pmd_regs(sysdev);
65 value = spu_read_register_value(sysdev, &pmd_regs->ts_ctsr1);
66 /* clear all other bits */
68 /* temp is stored in steps of 2 degrees */
70 /* base temp is 65 degrees */
73 return sprintf(buf, "%d\n", (int) value);
76 static ssize_t ppe_show_temp(struct sys_device *sysdev, char *buf, int pos)
78 struct cbe_pmd_regs __iomem *pmd_regs;
81 pmd_regs = cbe_get_cpu_pmd_regs(sysdev->id);
82 value = in_be64(&pmd_regs->ts_ctsr2);
84 /* access the corresponding byte */
86 /* clear all other bits */
88 /* temp is stored in steps of 2 degrees */
90 /* base temp is 65 degrees */
93 return sprintf(buf, "%d\n", (int) value);
97 /* shows the temperature of the DTS on the PPE,
98 * located near the linear thermal sensor */
99 static ssize_t ppe_show_temp0(struct sys_device *sysdev, char *buf)
101 return ppe_show_temp(sysdev, buf, 32);
104 /* shows the temperature of the second DTS on the PPE */
105 static ssize_t ppe_show_temp1(struct sys_device *sysdev, char *buf)
107 return ppe_show_temp(sysdev, buf, 0);
110 static struct sysdev_attribute attr_spu_temperature = {
111 .attr = {.name = "temperature", .mode = 0400 },
112 .show = spu_show_temp,
115 static struct attribute *spu_attributes[] = {
116 &attr_spu_temperature.attr,
119 static struct attribute_group spu_attribute_group = {
121 .attrs = spu_attributes,
124 static struct sysdev_attribute attr_ppe_temperature0 = {
125 .attr = {.name = "temperature0", .mode = 0400 },
126 .show = ppe_show_temp0,
129 static struct sysdev_attribute attr_ppe_temperature1 = {
130 .attr = {.name = "temperature1", .mode = 0400 },
131 .show = ppe_show_temp1,
134 static struct attribute *ppe_attributes[] = {
135 &attr_ppe_temperature0.attr,
136 &attr_ppe_temperature1.attr,
139 static struct attribute_group ppe_attribute_group = {
141 .attrs = ppe_attributes,
145 * initialize throttling with default values
147 static void __init init_default_values(void)
150 struct cbe_pmd_regs __iomem *pmd_regs;
151 struct sys_device *sysdev;
152 union ppe_spe_reg tpr;
161 * 08 - dynamic throttling starts if over 80 degrees
162 * 03 - dynamic throttling ceases if below 70 degrees */
165 * 10 - full stopped when over 96 degrees
166 * 08 - dynamic throttling starts if over 80 degrees
167 * 03 - dynamic throttling ceases if below 70 degrees
173 * 10 - stop 16 of 32 cycles
175 str1.val = 0x1010101010101010ull;
177 * 10 - stop 16 of 32 cycles
183 * 4 - normal operation
185 cr1.val = 0x0404040404040404ull;
187 * 4 - normal operation
191 for_each_possible_cpu (cpu) {
192 pr_debug("processing cpu %d\n", cpu);
193 sysdev = get_cpu_sysdev(cpu);
194 pmd_regs = cbe_get_cpu_pmd_regs(sysdev->id);
196 out_be64(&pmd_regs->tm_str2, str2);
197 out_be64(&pmd_regs->tm_str1.val, str1.val);
198 out_be64(&pmd_regs->tm_tpr.val, tpr.val);
199 out_be64(&pmd_regs->tm_cr1.val, cr1.val);
200 out_be64(&pmd_regs->tm_cr2, cr2);
205 static int __init thermal_init(void)
207 init_default_values();
209 spu_add_sysdev_attr_group(&spu_attribute_group);
210 cpu_add_sysdev_attr_group(&ppe_attribute_group);
214 module_init(thermal_init);
216 static void __exit thermal_exit(void)
218 spu_remove_sysdev_attr_group(&spu_attribute_group);
219 cpu_remove_sysdev_attr_group(&ppe_attribute_group);
221 module_exit(thermal_exit);
223 MODULE_LICENSE("GPL");
224 MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>");