Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 1 | /* |
| 2 | * thermal support for the cell processor |
| 3 | * |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 4 | * This module adds some sysfs attributes to cpu and spu nodes. |
| 5 | * Base for measurements are the digital thermal sensors (DTS) |
| 6 | * located on the chip. |
| 7 | * The accuracy is 2 degrees, starting from 65 up to 125 degrees celsius |
| 8 | * The attributes can be found under |
| 9 | * /sys/devices/system/cpu/cpuX/thermal |
| 10 | * /sys/devices/system/spu/spuX/thermal |
| 11 | * |
| 12 | * The following attributes are added for each node: |
| 13 | * temperature: |
| 14 | * contains the current temperature measured by the DTS |
| 15 | * throttle_begin: |
| 16 | * throttling begins when temperature is greater or equal to |
| 17 | * throttle_begin. Setting this value to 125 prevents throttling. |
| 18 | * throttle_end: |
| 19 | * throttling is being ceased, if the temperature is lower than |
| 20 | * throttle_end. Due to a delay between applying throttling and |
| 21 | * a reduced temperature this value should be less than throttle_begin. |
| 22 | * A value equal to throttle_begin provides only a very little hysteresis. |
| 23 | * throttle_full_stop: |
| 24 | * If the temperatrue is greater or equal to throttle_full_stop, |
| 25 | * full throttling is applied to the cpu or spu. This value should be |
| 26 | * greater than throttle_begin and throttle_end. Setting this value to |
| 27 | * 65 prevents the unit from running code at all. |
| 28 | * |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 29 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 |
| 30 | * |
| 31 | * Author: Christian Krafft <krafft@de.ibm.com> |
| 32 | * |
| 33 | * This program is free software; you can redistribute it and/or modify |
| 34 | * it under the terms of the GNU General Public License as published by |
| 35 | * the Free Software Foundation; either version 2, or (at your option) |
| 36 | * any later version. |
| 37 | * |
| 38 | * This program is distributed in the hope that it will be useful, |
| 39 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 40 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 41 | * GNU General Public License for more details. |
| 42 | * |
| 43 | * You should have received a copy of the GNU General Public License |
| 44 | * along with this program; if not, write to the Free Software |
| 45 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 46 | */ |
| 47 | |
| 48 | #include <linux/module.h> |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 49 | #include <linux/device.h> |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 50 | #include <linux/kernel.h> |
| 51 | #include <linux/cpu.h> |
| 52 | #include <asm/spu.h> |
| 53 | #include <asm/io.h> |
| 54 | #include <asm/prom.h> |
Benjamin Herrenschmidt | eef686a0 | 2007-10-04 15:40:42 +1000 | [diff] [blame] | 55 | #include <asm/cell-regs.h> |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 56 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 57 | #include "spu_priv1_mmio.h" |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 58 | |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 59 | #define TEMP_MIN 65 |
| 60 | #define TEMP_MAX 125 |
| 61 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 62 | #define DEVICE_PREFIX_ATTR(_prefix,_name,_mode) \ |
| 63 | struct device_attribute attr_ ## _prefix ## _ ## _name = { \ |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 64 | .attr = { .name = __stringify(_name), .mode = _mode }, \ |
| 65 | .show = _prefix ## _show_ ## _name, \ |
| 66 | .store = _prefix ## _store_ ## _name, \ |
| 67 | }; |
| 68 | |
Christian Krafft | 24d560d | 2007-04-23 21:35:40 +0200 | [diff] [blame] | 69 | static inline u8 reg_to_temp(u8 reg_value) |
| 70 | { |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 71 | return ((reg_value & 0x3f) << 1) + TEMP_MIN; |
| 72 | } |
| 73 | |
| 74 | static inline u8 temp_to_reg(u8 temp) |
| 75 | { |
| 76 | return ((temp - TEMP_MIN) >> 1) & 0x3f; |
Christian Krafft | 24d560d | 2007-04-23 21:35:40 +0200 | [diff] [blame] | 77 | } |
| 78 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 79 | static struct cbe_pmd_regs __iomem *get_pmd_regs(struct device *dev) |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 80 | { |
| 81 | struct spu *spu; |
| 82 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 83 | spu = container_of(dev, struct spu, dev); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 84 | |
Geoff Levand | e28b003 | 2006-11-23 00:46:49 +0100 | [diff] [blame] | 85 | return cbe_get_pmd_regs(spu_devnode(spu)); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /* returns the value for a given spu in a given register */ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 89 | static u8 spu_read_register_value(struct device *dev, union spe_reg __iomem *reg) |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 90 | { |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 91 | union spe_reg value; |
| 92 | struct spu *spu; |
| 93 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 94 | spu = container_of(dev, struct spu, dev); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 95 | value.val = in_be64(®->val); |
| 96 | |
Christian Krafft | fa7f374 | 2007-08-23 03:01:25 +1000 | [diff] [blame] | 97 | return value.spe[spu->spe_id]; |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 98 | } |
| 99 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 100 | static ssize_t spu_show_temp(struct device *dev, struct device_attribute *attr, |
Andi Kleen | 4a0b2b4 | 2008-07-01 18:48:41 +0200 | [diff] [blame] | 101 | char *buf) |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 102 | { |
Christian Krafft | 24d560d | 2007-04-23 21:35:40 +0200 | [diff] [blame] | 103 | u8 value; |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 104 | struct cbe_pmd_regs __iomem *pmd_regs; |
| 105 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 106 | pmd_regs = get_pmd_regs(dev); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 107 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 108 | value = spu_read_register_value(dev, &pmd_regs->ts_ctsr1); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 109 | |
Christian Krafft | 24d560d | 2007-04-23 21:35:40 +0200 | [diff] [blame] | 110 | return sprintf(buf, "%d\n", reg_to_temp(value)); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 111 | } |
| 112 | |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 113 | static ssize_t show_throttle(struct cbe_pmd_regs __iomem *pmd_regs, char *buf, int pos) |
| 114 | { |
| 115 | u64 value; |
| 116 | |
| 117 | value = in_be64(&pmd_regs->tm_tpr.val); |
| 118 | /* access the corresponding byte */ |
| 119 | value >>= pos; |
| 120 | value &= 0x3F; |
| 121 | |
| 122 | return sprintf(buf, "%d\n", reg_to_temp(value)); |
| 123 | } |
| 124 | |
| 125 | static ssize_t store_throttle(struct cbe_pmd_regs __iomem *pmd_regs, const char *buf, size_t size, int pos) |
| 126 | { |
| 127 | u64 reg_value; |
Rickard Strandqvist | f5fc822 | 2014-06-14 18:25:11 +0200 | [diff] [blame] | 128 | unsigned int temp; |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 129 | u64 new_value; |
| 130 | int ret; |
| 131 | |
| 132 | ret = sscanf(buf, "%u", &temp); |
| 133 | |
| 134 | if (ret != 1 || temp < TEMP_MIN || temp > TEMP_MAX) |
| 135 | return -EINVAL; |
| 136 | |
| 137 | new_value = temp_to_reg(temp); |
| 138 | |
| 139 | reg_value = in_be64(&pmd_regs->tm_tpr.val); |
| 140 | |
| 141 | /* zero out bits for new value */ |
| 142 | reg_value &= ~(0xffull << pos); |
| 143 | /* set bits to new value */ |
| 144 | reg_value |= new_value << pos; |
| 145 | |
| 146 | out_be64(&pmd_regs->tm_tpr.val, reg_value); |
| 147 | return size; |
| 148 | } |
| 149 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 150 | static ssize_t spu_show_throttle_end(struct device *dev, |
| 151 | struct device_attribute *attr, char *buf) |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 152 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 153 | return show_throttle(get_pmd_regs(dev), buf, 0); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 154 | } |
| 155 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 156 | static ssize_t spu_show_throttle_begin(struct device *dev, |
| 157 | struct device_attribute *attr, char *buf) |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 158 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 159 | return show_throttle(get_pmd_regs(dev), buf, 8); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 160 | } |
| 161 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 162 | static ssize_t spu_show_throttle_full_stop(struct device *dev, |
| 163 | struct device_attribute *attr, char *buf) |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 164 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 165 | return show_throttle(get_pmd_regs(dev), buf, 16); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 166 | } |
| 167 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 168 | static ssize_t spu_store_throttle_end(struct device *dev, |
| 169 | struct device_attribute *attr, const char *buf, size_t size) |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 170 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 171 | return store_throttle(get_pmd_regs(dev), buf, size, 0); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 174 | static ssize_t spu_store_throttle_begin(struct device *dev, |
| 175 | struct device_attribute *attr, const char *buf, size_t size) |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 176 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 177 | return store_throttle(get_pmd_regs(dev), buf, size, 8); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 180 | static ssize_t spu_store_throttle_full_stop(struct device *dev, |
| 181 | struct device_attribute *attr, const char *buf, size_t size) |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 182 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 183 | return store_throttle(get_pmd_regs(dev), buf, size, 16); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 184 | } |
| 185 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 186 | static ssize_t ppe_show_temp(struct device *dev, char *buf, int pos) |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 187 | { |
| 188 | struct cbe_pmd_regs __iomem *pmd_regs; |
| 189 | u64 value; |
| 190 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 191 | pmd_regs = cbe_get_cpu_pmd_regs(dev->id); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 192 | value = in_be64(&pmd_regs->ts_ctsr2); |
| 193 | |
Christian Krafft | 24d560d | 2007-04-23 21:35:40 +0200 | [diff] [blame] | 194 | value = (value >> pos) & 0x3f; |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 195 | |
Christian Krafft | 24d560d | 2007-04-23 21:35:40 +0200 | [diff] [blame] | 196 | return sprintf(buf, "%d\n", reg_to_temp(value)); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | |
| 200 | /* shows the temperature of the DTS on the PPE, |
| 201 | * located near the linear thermal sensor */ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 202 | static ssize_t ppe_show_temp0(struct device *dev, |
| 203 | struct device_attribute *attr, char *buf) |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 204 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 205 | return ppe_show_temp(dev, buf, 32); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /* shows the temperature of the second DTS on the PPE */ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 209 | static ssize_t ppe_show_temp1(struct device *dev, |
| 210 | struct device_attribute *attr, char *buf) |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 211 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 212 | return ppe_show_temp(dev, buf, 0); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 213 | } |
| 214 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 215 | static ssize_t ppe_show_throttle_end(struct device *dev, |
| 216 | struct device_attribute *attr, char *buf) |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 217 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 218 | return show_throttle(cbe_get_cpu_pmd_regs(dev->id), buf, 32); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 221 | static ssize_t ppe_show_throttle_begin(struct device *dev, |
| 222 | struct device_attribute *attr, char *buf) |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 223 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 224 | return show_throttle(cbe_get_cpu_pmd_regs(dev->id), buf, 40); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 227 | static ssize_t ppe_show_throttle_full_stop(struct device *dev, |
| 228 | struct device_attribute *attr, char *buf) |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 229 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 230 | return show_throttle(cbe_get_cpu_pmd_regs(dev->id), buf, 48); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 231 | } |
| 232 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 233 | static ssize_t ppe_store_throttle_end(struct device *dev, |
| 234 | struct device_attribute *attr, const char *buf, size_t size) |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 235 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 236 | return store_throttle(cbe_get_cpu_pmd_regs(dev->id), buf, size, 32); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 237 | } |
| 238 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 239 | static ssize_t ppe_store_throttle_begin(struct device *dev, |
| 240 | struct device_attribute *attr, const char *buf, size_t size) |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 241 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 242 | return store_throttle(cbe_get_cpu_pmd_regs(dev->id), buf, size, 40); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 245 | static ssize_t ppe_store_throttle_full_stop(struct device *dev, |
| 246 | struct device_attribute *attr, const char *buf, size_t size) |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 247 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 248 | return store_throttle(cbe_get_cpu_pmd_regs(dev->id), buf, size, 48); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 252 | static struct device_attribute attr_spu_temperature = { |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 253 | .attr = {.name = "temperature", .mode = 0400 }, |
| 254 | .show = spu_show_temp, |
| 255 | }; |
| 256 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 257 | static DEVICE_PREFIX_ATTR(spu, throttle_end, 0600); |
| 258 | static DEVICE_PREFIX_ATTR(spu, throttle_begin, 0600); |
| 259 | static DEVICE_PREFIX_ATTR(spu, throttle_full_stop, 0600); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 260 | |
| 261 | |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 262 | static struct attribute *spu_attributes[] = { |
| 263 | &attr_spu_temperature.attr, |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 264 | &attr_spu_throttle_end.attr, |
| 265 | &attr_spu_throttle_begin.attr, |
| 266 | &attr_spu_throttle_full_stop.attr, |
Christian Krafft | 22b6e59 | 2006-12-07 19:01:16 +0100 | [diff] [blame] | 267 | NULL, |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 268 | }; |
| 269 | |
| 270 | static struct attribute_group spu_attribute_group = { |
| 271 | .name = "thermal", |
| 272 | .attrs = spu_attributes, |
| 273 | }; |
| 274 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 275 | static struct device_attribute attr_ppe_temperature0 = { |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 276 | .attr = {.name = "temperature0", .mode = 0400 }, |
| 277 | .show = ppe_show_temp0, |
| 278 | }; |
| 279 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 280 | static struct device_attribute attr_ppe_temperature1 = { |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 281 | .attr = {.name = "temperature1", .mode = 0400 }, |
| 282 | .show = ppe_show_temp1, |
| 283 | }; |
| 284 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 285 | static DEVICE_PREFIX_ATTR(ppe, throttle_end, 0600); |
| 286 | static DEVICE_PREFIX_ATTR(ppe, throttle_begin, 0600); |
| 287 | static DEVICE_PREFIX_ATTR(ppe, throttle_full_stop, 0600); |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 288 | |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 289 | static struct attribute *ppe_attributes[] = { |
| 290 | &attr_ppe_temperature0.attr, |
| 291 | &attr_ppe_temperature1.attr, |
Christian Krafft | 5f7bdae | 2007-04-23 21:35:41 +0200 | [diff] [blame] | 292 | &attr_ppe_throttle_end.attr, |
| 293 | &attr_ppe_throttle_begin.attr, |
| 294 | &attr_ppe_throttle_full_stop.attr, |
Christian Krafft | 22b6e59 | 2006-12-07 19:01:16 +0100 | [diff] [blame] | 295 | NULL, |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | static struct attribute_group ppe_attribute_group = { |
| 299 | .name = "thermal", |
| 300 | .attrs = ppe_attributes, |
| 301 | }; |
| 302 | |
| 303 | /* |
| 304 | * initialize throttling with default values |
| 305 | */ |
Jean-Christophe DUBOIS | 827e364 | 2007-07-20 21:39:24 +0200 | [diff] [blame] | 306 | static int __init init_default_values(void) |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 307 | { |
| 308 | int cpu; |
| 309 | struct cbe_pmd_regs __iomem *pmd_regs; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 310 | struct device *dev; |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 311 | union ppe_spe_reg tpr; |
| 312 | union spe_reg str1; |
| 313 | u64 str2; |
| 314 | union spe_reg cr1; |
| 315 | u64 cr2; |
| 316 | |
| 317 | /* TPR defaults */ |
| 318 | /* ppe |
| 319 | * 1F - no full stop |
| 320 | * 08 - dynamic throttling starts if over 80 degrees |
| 321 | * 03 - dynamic throttling ceases if below 70 degrees */ |
| 322 | tpr.ppe = 0x1F0803; |
| 323 | /* spe |
| 324 | * 10 - full stopped when over 96 degrees |
| 325 | * 08 - dynamic throttling starts if over 80 degrees |
| 326 | * 03 - dynamic throttling ceases if below 70 degrees |
| 327 | */ |
| 328 | tpr.spe = 0x100803; |
| 329 | |
| 330 | /* STR defaults */ |
| 331 | /* str1 |
| 332 | * 10 - stop 16 of 32 cycles |
| 333 | */ |
| 334 | str1.val = 0x1010101010101010ull; |
| 335 | /* str2 |
| 336 | * 10 - stop 16 of 32 cycles |
| 337 | */ |
| 338 | str2 = 0x10; |
| 339 | |
| 340 | /* CR defaults */ |
| 341 | /* cr1 |
| 342 | * 4 - normal operation |
| 343 | */ |
| 344 | cr1.val = 0x0404040404040404ull; |
| 345 | /* cr2 |
| 346 | * 4 - normal operation |
| 347 | */ |
| 348 | cr2 = 0x04; |
| 349 | |
| 350 | for_each_possible_cpu (cpu) { |
| 351 | pr_debug("processing cpu %d\n", cpu); |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 352 | dev = get_cpu_device(cpu); |
Jean-Christophe DUBOIS | 827e364 | 2007-07-20 21:39:24 +0200 | [diff] [blame] | 353 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 354 | if (!dev) { |
| 355 | pr_info("invalid dev pointer for cbe_thermal\n"); |
Jean-Christophe DUBOIS | 827e364 | 2007-07-20 21:39:24 +0200 | [diff] [blame] | 356 | return -EINVAL; |
| 357 | } |
| 358 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 359 | pmd_regs = cbe_get_cpu_pmd_regs(dev->id); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 360 | |
Jean-Christophe DUBOIS | 827e364 | 2007-07-20 21:39:24 +0200 | [diff] [blame] | 361 | if (!pmd_regs) { |
| 362 | pr_info("invalid CBE regs pointer for cbe_thermal\n"); |
| 363 | return -EINVAL; |
| 364 | } |
| 365 | |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 366 | out_be64(&pmd_regs->tm_str2, str2); |
| 367 | out_be64(&pmd_regs->tm_str1.val, str1.val); |
| 368 | out_be64(&pmd_regs->tm_tpr.val, tpr.val); |
| 369 | out_be64(&pmd_regs->tm_cr1.val, cr1.val); |
| 370 | out_be64(&pmd_regs->tm_cr2, cr2); |
| 371 | } |
Jean-Christophe DUBOIS | 827e364 | 2007-07-20 21:39:24 +0200 | [diff] [blame] | 372 | |
| 373 | return 0; |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | |
| 377 | static int __init thermal_init(void) |
| 378 | { |
Jean-Christophe DUBOIS | 827e364 | 2007-07-20 21:39:24 +0200 | [diff] [blame] | 379 | int rc = init_default_values(); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 380 | |
Jean-Christophe DUBOIS | 827e364 | 2007-07-20 21:39:24 +0200 | [diff] [blame] | 381 | if (rc == 0) { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 382 | spu_add_dev_attr_group(&spu_attribute_group); |
| 383 | cpu_add_dev_attr_group(&ppe_attribute_group); |
Jean-Christophe DUBOIS | 827e364 | 2007-07-20 21:39:24 +0200 | [diff] [blame] | 384 | } |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 385 | |
Jean-Christophe DUBOIS | 827e364 | 2007-07-20 21:39:24 +0200 | [diff] [blame] | 386 | return rc; |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 387 | } |
| 388 | module_init(thermal_init); |
| 389 | |
| 390 | static void __exit thermal_exit(void) |
| 391 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 392 | spu_remove_dev_attr_group(&spu_attribute_group); |
| 393 | cpu_remove_dev_attr_group(&ppe_attribute_group); |
Christian Krafft | b3d7dc1 | 2006-10-24 18:31:25 +0200 | [diff] [blame] | 394 | } |
| 395 | module_exit(thermal_exit); |
| 396 | |
| 397 | MODULE_LICENSE("GPL"); |
| 398 | MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>"); |
| 399 | |