cbe_thermal.c 5.5 KB

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