0044-Added-hwmon-thermal-driver-for-reporting-core-temper.patch 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. From 9bccd57257d3156887d5bbeadbf35898505cd7f6 Mon Sep 17 00:00:00 2001
  2. From: popcornmix <popcornmix@gmail.com>
  3. Date: Tue, 26 Mar 2013 19:24:24 +0000
  4. Subject: [PATCH 044/381] Added hwmon/thermal driver for reporting core
  5. temperature. Thanks Dorian
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. BCM270x: Move thermal sensor to Device Tree
  10. Add Device Tree support to bcm2835-thermal driver.
  11. Add thermal sensor device to Device Tree.
  12. Don't add platform device when booting in DT mode.
  13. Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
  14. ---
  15. drivers/thermal/Kconfig | 7 ++
  16. drivers/thermal/Makefile | 1 +
  17. drivers/thermal/bcm2835-thermal.c | 141 ++++++++++++++++++++++++++++++++++++++
  18. 3 files changed, 149 insertions(+)
  19. create mode 100644 drivers/thermal/bcm2835-thermal.c
  20. --- a/drivers/thermal/Kconfig
  21. +++ b/drivers/thermal/Kconfig
  22. @@ -285,6 +285,13 @@ config INTEL_POWERCLAMP
  23. enforce idle time which results in more package C-state residency. The
  24. user interface is exposed via generic thermal framework.
  25. +config THERMAL_BCM2835
  26. + depends on RASPBERRYPI_FIRMWARE
  27. + tristate "BCM2835 Thermal Driver"
  28. + help
  29. + This will enable temperature monitoring for the Broadcom BCM2835
  30. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  31. +
  32. config X86_PKG_TEMP_THERMAL
  33. tristate "X86 package temperature thermal driver"
  34. depends on X86_THERMAL_VECTOR
  35. --- a/drivers/thermal/Makefile
  36. +++ b/drivers/thermal/Makefile
  37. @@ -38,6 +38,7 @@ obj-$(CONFIG_ARMADA_THERMAL) += armada_t
  38. obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
  39. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  40. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  41. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  42. obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
  43. obj-$(CONFIG_INTEL_SOC_DTS_IOSF_CORE) += intel_soc_dts_iosf.o
  44. obj-$(CONFIG_INTEL_SOC_DTS_THERMAL) += intel_soc_dts_thermal.o
  45. --- /dev/null
  46. +++ b/drivers/thermal/bcm2835-thermal.c
  47. @@ -0,0 +1,141 @@
  48. +/*****************************************************************************
  49. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  50. +*
  51. +* Unless you and Broadcom execute a separate written software license
  52. +* agreement governing use of this software, this software is licensed to you
  53. +* under the terms of the GNU General Public License version 2, available at
  54. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  55. +*
  56. +* Notwithstanding the above, under no circumstances may you combine this
  57. +* software in any way with any other Broadcom software provided under a
  58. +* license other than the GPL, without Broadcom's express prior written
  59. +* consent.
  60. +*****************************************************************************/
  61. +
  62. +#include <linux/module.h>
  63. +#include <linux/platform_device.h>
  64. +#include <linux/thermal.h>
  65. +#include <soc/bcm2835/raspberrypi-firmware.h>
  66. +
  67. +static int bcm2835_thermal_get_property(struct thermal_zone_device *tz,
  68. + int *temp, u32 tag)
  69. +{
  70. + struct rpi_firmware *fw = tz->devdata;
  71. + struct {
  72. + u32 id;
  73. + u32 val;
  74. + } packet;
  75. + int ret;
  76. +
  77. + *temp = 0;
  78. + packet.id = 0;
  79. + ret = rpi_firmware_property(fw, tag, &packet, sizeof(packet));
  80. + if (ret) {
  81. + dev_err(&tz->device, "Failed to get temperature\n");
  82. + return ret;
  83. + }
  84. +
  85. + *temp = packet.val;
  86. + dev_dbg(&tz->device, "%stemp=%d\n",
  87. + tag == RPI_FIRMWARE_GET_MAX_TEMPERATURE ? "max" : "", *temp);
  88. +
  89. + return 0;
  90. +}
  91. +
  92. +static int bcm2835_thermal_get_temp(struct thermal_zone_device *tz,
  93. + int *temp)
  94. +{
  95. + return bcm2835_thermal_get_property(tz, temp,
  96. + RPI_FIRMWARE_GET_TEMPERATURE);
  97. +}
  98. +
  99. +static int bcm2835_thermal_get_max_temp(struct thermal_zone_device *tz,
  100. + int trip, int *temp)
  101. +{
  102. + /*
  103. + * The maximum safe temperature of the SoC.
  104. + * Overclock may be disabled above this temperature.
  105. + */
  106. + return bcm2835_thermal_get_property(tz, temp,
  107. + RPI_FIRMWARE_GET_MAX_TEMPERATURE);
  108. +}
  109. +
  110. +static int bcm2835_thermal_get_trip_type(struct thermal_zone_device *tz,
  111. + int trip, enum thermal_trip_type *type)
  112. +{
  113. + *type = THERMAL_TRIP_HOT;
  114. +
  115. + return 0;
  116. +}
  117. +
  118. +static int bcm2835_thermal_get_mode(struct thermal_zone_device *tz,
  119. + enum thermal_device_mode *mode)
  120. +{
  121. + *mode = THERMAL_DEVICE_ENABLED;
  122. +
  123. + return 0;
  124. +}
  125. +
  126. +static struct thermal_zone_device_ops ops = {
  127. + .get_temp = bcm2835_thermal_get_temp,
  128. + .get_trip_temp = bcm2835_thermal_get_max_temp,
  129. + .get_trip_type = bcm2835_thermal_get_trip_type,
  130. + .get_mode = bcm2835_thermal_get_mode,
  131. +};
  132. +
  133. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  134. +{
  135. + struct device_node *fw_np;
  136. + struct rpi_firmware *fw;
  137. + struct thermal_zone_device *tz;
  138. +
  139. + fw_np = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
  140. +/* Remove comment when booting without Device Tree is no longer supported
  141. + if (!fw_np) {
  142. + dev_err(&pdev->dev, "Missing firmware node\n");
  143. + return -ENOENT;
  144. + }
  145. +*/
  146. + fw = rpi_firmware_get(fw_np);
  147. + if (!fw)
  148. + return -EPROBE_DEFER;
  149. +
  150. + tz = thermal_zone_device_register("bcm2835_thermal", 1, 0, fw, &ops,
  151. + NULL, 0, 0);
  152. + if (IS_ERR(tz)) {
  153. + dev_err(&pdev->dev, "Failed to register the thermal device\n");
  154. + return PTR_ERR(tz);
  155. + }
  156. +
  157. + platform_set_drvdata(pdev, tz);
  158. +
  159. + return 0;
  160. +}
  161. +
  162. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  163. +{
  164. + thermal_zone_device_unregister(platform_get_drvdata(pdev));
  165. +
  166. + return 0;
  167. +}
  168. +
  169. +static const struct of_device_id bcm2835_thermal_of_match_table[] = {
  170. + { .compatible = "brcm,bcm2835-thermal", },
  171. + {},
  172. +};
  173. +MODULE_DEVICE_TABLE(of, bcm2835_thermal_of_match_table);
  174. +
  175. +static struct platform_driver bcm2835_thermal_driver = {
  176. + .probe = bcm2835_thermal_probe,
  177. + .remove = bcm2835_thermal_remove,
  178. + .driver = {
  179. + .name = "bcm2835_thermal",
  180. + .of_match_table = bcm2835_thermal_of_match_table,
  181. + },
  182. +};
  183. +module_platform_driver(bcm2835_thermal_driver);
  184. +
  185. +MODULE_AUTHOR("Dorian Peake");
  186. +MODULE_AUTHOR("Noralf Trønnes");
  187. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  188. +MODULE_LICENSE("GPL");