cbe_thermal.c 5.5 KB

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