48 #include <linux/module.h>
49 #include <linux/device.h>
50 #include <linux/kernel.h>
62 #define DEVICE_PREFIX_ATTR(_prefix,_name,_mode) \
63 struct device_attribute attr_ ## _prefix ## _ ## _name = { \
64 .attr = { .name = __stringify(_name), .mode = _mode }, \
65 .show = _prefix ## _show_ ## _name, \
66 .store = _prefix ## _store_ ## _name, \
69 static inline u8 reg_to_temp(
u8 reg_value)
71 return ((reg_value & 0x3f) << 1) +
TEMP_MIN;
74 static inline u8 temp_to_reg(
u8 temp)
76 return ((temp -
TEMP_MIN) >> 1) & 0x3f;
95 value.val = in_be64(®->val);
97 return value.spe[spu->spe_id];
106 pmd_regs = get_pmd_regs(dev);
108 value = spu_read_register_value(dev, &pmd_regs->
ts_ctsr1);
110 return sprintf(buf,
"%d\n", reg_to_temp(value));
117 value = in_be64(&pmd_regs->tm_tpr.val);
122 return sprintf(buf,
"%d\n", reg_to_temp(value));
132 ret =
sscanf(buf,
"%u", &temp);
134 if (ret != 1 || temp < TEMP_MIN || temp >
TEMP_MAX)
137 new_value = temp_to_reg(temp);
139 reg_value = in_be64(&pmd_regs->tm_tpr.val);
142 reg_value &= ~(0xffull <<
pos);
144 reg_value |= new_value <<
pos;
146 out_be64(&pmd_regs->tm_tpr.val, reg_value);
153 return show_throttle(get_pmd_regs(dev), buf, 0);
159 return show_throttle(get_pmd_regs(dev), buf, 8);
162 static ssize_t spu_show_throttle_full_stop(
struct device *dev,
165 return show_throttle(get_pmd_regs(dev), buf, 16);
171 return store_throttle(get_pmd_regs(dev), buf, size, 0);
177 return store_throttle(get_pmd_regs(dev), buf, size, 8);
180 static ssize_t spu_store_throttle_full_stop(
struct device *dev,
183 return store_throttle(get_pmd_regs(dev), buf, size, 16);
186 static ssize_t ppe_show_temp(
struct device *dev,
char *buf,
int pos)
192 value = in_be64(&pmd_regs->
ts_ctsr2);
194 value = (value >>
pos) & 0x3f;
196 return sprintf(buf,
"%d\n", reg_to_temp(value));
205 return ppe_show_temp(dev, buf, 32);
212 return ppe_show_temp(dev, buf, 0);
227 static ssize_t ppe_show_throttle_full_stop(
struct device *dev,
245 static ssize_t ppe_store_throttle_full_stop(
struct device *dev,
253 .attr = {.name =
"temperature", .mode = 0400 },
254 .show = spu_show_temp,
262 static struct attribute *spu_attributes[] = {
263 &attr_spu_temperature.
attr,
264 &attr_spu_throttle_end.attr,
265 &attr_spu_throttle_begin.attr,
266 &attr_spu_throttle_full_stop.attr,
272 .attrs = spu_attributes,
276 .attr = {.name =
"temperature0", .mode = 0400 },
277 .show = ppe_show_temp0,
281 .attr = {.name =
"temperature1", .mode = 0400 },
282 .show = ppe_show_temp1,
289 static struct attribute *ppe_attributes[] = {
290 &attr_ppe_temperature0.
attr,
291 &attr_ppe_temperature1.
attr,
292 &attr_ppe_throttle_end.attr,
293 &attr_ppe_throttle_begin.attr,
294 &attr_ppe_throttle_full_stop.attr,
300 .attrs = ppe_attributes,
306 static int __init init_default_values(
void)
334 str1.val = 0x1010101010101010ull;
344 cr1.val = 0x0404040404040404ull;
351 pr_debug(
"processing cpu %d\n", cpu);
355 pr_info(
"invalid dev pointer for cbe_thermal\n");
362 pr_info(
"invalid CBE regs pointer for cbe_thermal\n");
366 out_be64(&pmd_regs->
tm_str2, str2);
370 out_be64(&pmd_regs->
tm_cr2, cr2);
377 static int __init thermal_init(
void)
379 int rc = init_default_values();
390 static void __exit thermal_exit(
void)