086-0004-thermal-broadcom-add-Northstar-thermal-driver.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. From a94cb7eeecc4104a6874339f90c5d0647359c102 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
  3. Date: Mon, 3 Apr 2017 17:48:29 +0200
  4. Subject: [PATCH] thermal: broadcom: add Northstar thermal driver
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Northstar is a SoC family commonly used in home routers. This commit
  9. adds a driver for checking CPU temperature. As Northstar Plus seems to
  10. also have this IP block this new symbol gets ARCH_BCM_IPROC dependency.
  11. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  12. Signed-off-by: Jon Mason <jon.mason@broadcom.com>
  13. Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
  14. ---
  15. drivers/thermal/Kconfig | 5 ++
  16. drivers/thermal/Makefile | 1 +
  17. drivers/thermal/broadcom/Kconfig | 8 +++
  18. drivers/thermal/broadcom/Makefile | 1 +
  19. drivers/thermal/broadcom/ns-thermal.c | 105 ++++++++++++++++++++++++++++++++++
  20. 5 files changed, 120 insertions(+)
  21. create mode 100644 drivers/thermal/broadcom/Kconfig
  22. create mode 100644 drivers/thermal/broadcom/Makefile
  23. create mode 100644 drivers/thermal/broadcom/ns-thermal.c
  24. --- a/drivers/thermal/Kconfig
  25. +++ b/drivers/thermal/Kconfig
  26. @@ -365,6 +365,11 @@ config INTEL_PCH_THERMAL
  27. Thermal reporting device will provide temperature reading,
  28. programmable trip points and other information.
  29. +menu "Broadcom thermal drivers"
  30. +depends on ARCH_BCM || COMPILE_TEST
  31. +source "drivers/thermal/broadcom/Kconfig"
  32. +endmenu
  33. +
  34. menu "Texas Instruments thermal drivers"
  35. depends on ARCH_HAS_BANDGAP || COMPILE_TEST
  36. source "drivers/thermal/ti-soc-thermal/Kconfig"
  37. --- a/drivers/thermal/Makefile
  38. +++ b/drivers/thermal/Makefile
  39. @@ -26,6 +26,7 @@ thermal_sys-$(CONFIG_CLOCK_THERMAL) += c
  40. thermal_sys-$(CONFIG_DEVFREQ_THERMAL) += devfreq_cooling.o
  41. # platform thermal drivers
  42. +obj-y += broadcom/
  43. obj-$(CONFIG_QCOM_SPMI_TEMP_ALARM) += qcom-spmi-temp-alarm.o
  44. obj-$(CONFIG_SPEAR_THERMAL) += spear_thermal.o
  45. obj-$(CONFIG_ROCKCHIP_THERMAL) += rockchip_thermal.o
  46. --- /dev/null
  47. +++ b/drivers/thermal/broadcom/Kconfig
  48. @@ -0,0 +1,8 @@
  49. +config BCM_NS_THERMAL
  50. + tristate "Northstar thermal driver"
  51. + depends on ARCH_BCM_IPROC || COMPILE_TEST
  52. + help
  53. + Northstar is a family of SoCs that includes e.g. BCM4708, BCM47081,
  54. + BCM4709 and BCM47094. It contains DMU (Device Management Unit) block
  55. + with a thermal sensor that allows checking CPU temperature. This
  56. + driver provides support for it.
  57. --- /dev/null
  58. +++ b/drivers/thermal/broadcom/Makefile
  59. @@ -0,0 +1 @@
  60. +obj-$(CONFIG_BCM_NS_THERMAL) += ns-thermal.o
  61. --- /dev/null
  62. +++ b/drivers/thermal/broadcom/ns-thermal.c
  63. @@ -0,0 +1,105 @@
  64. +/*
  65. + * Copyright (C) 2017 Rafał Miłecki <rafal@milecki.pl>
  66. + *
  67. + * This program is free software; you can redistribute it and/or modify
  68. + * it under the terms of the GNU General Public License version 2 as
  69. + * published by the Free Software Foundation.
  70. + */
  71. +
  72. +#include <linux/module.h>
  73. +#include <linux/of_address.h>
  74. +#include <linux/platform_device.h>
  75. +#include <linux/thermal.h>
  76. +
  77. +#define PVTMON_CONTROL0 0x00
  78. +#define PVTMON_CONTROL0_SEL_MASK 0x0000000e
  79. +#define PVTMON_CONTROL0_SEL_TEMP_MONITOR 0x00000000
  80. +#define PVTMON_CONTROL0_SEL_TEST_MODE 0x0000000e
  81. +#define PVTMON_STATUS 0x08
  82. +
  83. +struct ns_thermal {
  84. + struct thermal_zone_device *tz;
  85. + void __iomem *pvtmon;
  86. +};
  87. +
  88. +static int ns_thermal_get_temp(void *data, int *temp)
  89. +{
  90. + struct ns_thermal *ns_thermal = data;
  91. + int offset = thermal_zone_get_offset(ns_thermal->tz);
  92. + int slope = thermal_zone_get_slope(ns_thermal->tz);
  93. + u32 val;
  94. +
  95. + val = readl(ns_thermal->pvtmon + PVTMON_CONTROL0);
  96. + if ((val & PVTMON_CONTROL0_SEL_MASK) != PVTMON_CONTROL0_SEL_TEMP_MONITOR) {
  97. + /* Clear current mode selection */
  98. + val &= ~PVTMON_CONTROL0_SEL_MASK;
  99. +
  100. + /* Set temp monitor mode (it's the default actually) */
  101. + val |= PVTMON_CONTROL0_SEL_TEMP_MONITOR;
  102. +
  103. + writel(val, ns_thermal->pvtmon + PVTMON_CONTROL0);
  104. + }
  105. +
  106. + val = readl(ns_thermal->pvtmon + PVTMON_STATUS);
  107. + *temp = slope * val + offset;
  108. +
  109. + return 0;
  110. +}
  111. +
  112. +static const struct thermal_zone_of_device_ops ns_thermal_ops = {
  113. + .get_temp = ns_thermal_get_temp,
  114. +};
  115. +
  116. +static int ns_thermal_probe(struct platform_device *pdev)
  117. +{
  118. + struct device *dev = &pdev->dev;
  119. + struct ns_thermal *ns_thermal;
  120. +
  121. + ns_thermal = devm_kzalloc(dev, sizeof(*ns_thermal), GFP_KERNEL);
  122. + if (!ns_thermal)
  123. + return -ENOMEM;
  124. +
  125. + ns_thermal->pvtmon = of_iomap(dev_of_node(dev), 0);
  126. + if (WARN_ON(!ns_thermal->pvtmon))
  127. + return -ENOENT;
  128. +
  129. + ns_thermal->tz = devm_thermal_zone_of_sensor_register(dev, 0,
  130. + ns_thermal,
  131. + &ns_thermal_ops);
  132. + if (IS_ERR(ns_thermal->tz)) {
  133. + iounmap(ns_thermal->pvtmon);
  134. + return PTR_ERR(ns_thermal->tz);
  135. + }
  136. +
  137. + platform_set_drvdata(pdev, ns_thermal);
  138. +
  139. + return 0;
  140. +}
  141. +
  142. +static int ns_thermal_remove(struct platform_device *pdev)
  143. +{
  144. + struct ns_thermal *ns_thermal = platform_get_drvdata(pdev);
  145. +
  146. + iounmap(ns_thermal->pvtmon);
  147. +
  148. + return 0;
  149. +}
  150. +
  151. +static const struct of_device_id ns_thermal_of_match[] = {
  152. + { .compatible = "brcm,ns-thermal", },
  153. + {},
  154. +};
  155. +MODULE_DEVICE_TABLE(of, ns_thermal_of_match);
  156. +
  157. +static struct platform_driver ns_thermal_driver = {
  158. + .probe = ns_thermal_probe,
  159. + .remove = ns_thermal_remove,
  160. + .driver = {
  161. + .name = "ns-thermal",
  162. + .of_match_table = ns_thermal_of_match,
  163. + },
  164. +};
  165. +module_platform_driver(ns_thermal_driver);
  166. +
  167. +MODULE_DESCRIPTION("Northstar thermal driver");
  168. +MODULE_LICENSE("GPL v2");