0302-xrx200-add-sensors-driver.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. --- a/drivers/hwmon/Makefile
  2. +++ b/drivers/hwmon/Makefile
  3. @@ -107,6 +107,7 @@ obj-$(CONFIG_SENSORS_LTC4222) += ltc4222
  4. obj-$(CONFIG_SENSORS_LTC4245) += ltc4245.o
  5. obj-$(CONFIG_SENSORS_LTC4260) += ltc4260.o
  6. obj-$(CONFIG_SENSORS_LTC4261) += ltc4261.o
  7. +obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o
  8. obj-$(CONFIG_SENSORS_MAX1111) += max1111.o
  9. obj-$(CONFIG_SENSORS_MAX16065) += max16065.o
  10. obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
  11. --- a/drivers/hwmon/Kconfig
  12. +++ b/drivers/hwmon/Kconfig
  13. @@ -753,6 +753,14 @@ config SENSORS_LTC4261
  14. This driver can also be built as a module. If so, the module will
  15. be called ltc4261.
  16. +config SENSORS_LTQ_CPUTEMP
  17. + bool "Lantiq CPU temperature sensor"
  18. + depends on LANTIQ
  19. + default n
  20. + help
  21. + If you say yes here you get support for the temperature
  22. + sensor inside your CPU.
  23. +
  24. config SENSORS_MAX1111
  25. tristate "Maxim MAX1111 Serial 8-bit ADC chip and compatibles"
  26. depends on SPI_MASTER
  27. --- /dev/null
  28. +++ b/drivers/hwmon/ltq-cputemp.c
  29. @@ -0,0 +1,154 @@
  30. +/* Lantiq CPU Temperatur sensor driver for xrx200
  31. + *
  32. + * Copyright (C) 2016 Florian Eckert <feckert@tdt.de>
  33. + *
  34. + * This program is free software; you can redistribute it and/or modify
  35. + * it under the terms of the GNU General Public License as published by
  36. + * the Free Software Foundation; either version 2 of the License, or
  37. + * (at your option) any later version
  38. + *
  39. + * This program is distributed in the hope that it will be useful
  40. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  41. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  42. + * GNU General Public License for more details
  43. + *
  44. + * You should have received a copy of the GNU General Public License
  45. + * along with this program; if not, see <http://www.gnu.org/licenses/>
  46. + */
  47. +
  48. +#include <linux/module.h>
  49. +#include <linux/init.h>
  50. +#include <linux/delay.h>
  51. +#include <linux/of_device.h>
  52. +#include <linux/hwmon.h>
  53. +#include <linux/hwmon-sysfs.h>
  54. +
  55. +#include <lantiq_soc.h>
  56. +
  57. +/* gphy1 configuration register contains cpu temperature */
  58. +#define CGU_GPHY1_CR 0x0040
  59. +#define CGU_TEMP_PD BIT(19)
  60. +
  61. +static void ltq_cputemp_enable(void)
  62. +{
  63. + ltq_cgu_w32(ltq_cgu_r32(CGU_GPHY1_CR) | CGU_TEMP_PD, CGU_GPHY1_CR);
  64. +
  65. + /* wait a short moment to let the SoC get the first temperatur value */
  66. + mdelay(100);
  67. +}
  68. +
  69. +static void ltq_cputemp_disable(void)
  70. +{
  71. + ltq_cgu_w32(ltq_cgu_r32(CGU_GPHY1_CR) & ~CGU_TEMP_PD, CGU_GPHY1_CR);
  72. +}
  73. +
  74. +static int ltq_cputemp_read(void)
  75. +{
  76. + int value;
  77. +
  78. + /* get the temperature including one decimal place */
  79. + value = (ltq_cgu_r32(CGU_GPHY1_CR) >> 9) & 0x01FF;
  80. + value = (value << 2 ) + value;
  81. +
  82. + /* range -38 to +154 °C, register value zero is -38.0 °C */
  83. + value -= 380;
  84. +
  85. + return value;
  86. +}
  87. +
  88. +static ssize_t show_cputemp(struct device *dev,
  89. + struct device_attribute *attr, char *buf)
  90. +{
  91. + int value;
  92. +
  93. + value = ltq_cputemp_read();
  94. + /* scale temp to millidegree */
  95. + value = value * 100;
  96. +
  97. + return sprintf(buf, "%d\n", value);
  98. +}
  99. +
  100. +static DEVICE_ATTR(temp1_input, S_IRUGO, show_cputemp, NULL);
  101. +
  102. +static struct attribute *ltq_cputemp_attrs[] = {
  103. + &dev_attr_temp1_input.attr,
  104. + NULL
  105. +};
  106. +
  107. +ATTRIBUTE_GROUPS(ltq_cputemp);
  108. +
  109. +static int ltq_cputemp_probe(struct platform_device *pdev)
  110. +{
  111. + int value = 0;
  112. + int ret;
  113. + struct device *hwmon_dev;
  114. +
  115. + /* available on vr9 v1.2 SoCs only */
  116. + if (ltq_soc_type() != SOC_TYPE_VR9_2)
  117. + return -ENODEV;
  118. +
  119. + hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
  120. + "CPU0",
  121. + NULL,
  122. + ltq_cputemp_groups);
  123. +
  124. + if (IS_ERR(hwmon_dev)) {
  125. + dev_err(&pdev->dev, "Failed to register as hwmon device");
  126. + ret = PTR_ERR(hwmon_dev);
  127. + goto error_hwmon;
  128. + }
  129. +
  130. + ltq_cputemp_enable();
  131. + value = ltq_cputemp_read();
  132. + dev_info(&pdev->dev, "Current CPU die temperature: %d.%d °C", value / 10, value % 10);
  133. +
  134. + return 0;
  135. +
  136. +error_hwmon:
  137. + return ret;
  138. +}
  139. +
  140. +static int ltq_cputemp_release(struct platform_device *pdev)
  141. +{
  142. + hwmon_device_unregister(&pdev->dev);
  143. + ltq_cputemp_disable();
  144. + return 0;
  145. +}
  146. +
  147. +const struct of_device_id ltq_cputemp_match[] = {
  148. + { .compatible = "lantiq,cputemp" },
  149. + {},
  150. +};
  151. +MODULE_DEVICE_TABLE(of, ltq_cputemp_match);
  152. +
  153. +static struct platform_driver ltq_cputemp_driver = {
  154. + .probe = ltq_cputemp_probe,
  155. + .remove = ltq_cputemp_release,
  156. + .driver = {
  157. + .name = "ltq-cputemp",
  158. + .owner = THIS_MODULE,
  159. + .of_match_table = ltq_cputemp_match,
  160. + },
  161. +};
  162. +
  163. +int __init init_ltq_cputemp(void)
  164. +{
  165. + int ret;
  166. +
  167. + ret = platform_driver_register(&ltq_cputemp_driver);
  168. + return ret;
  169. +}
  170. +
  171. +void clean_ltq_cputemp(void)
  172. +{
  173. + platform_driver_unregister(&ltq_cputemp_driver);
  174. + return;
  175. +}
  176. +
  177. +module_init(init_ltq_cputemp);
  178. +module_exit(clean_ltq_cputemp);
  179. +
  180. +MODULE_AUTHOR("Florian Eckert <feckert@tdt.de>");
  181. +
  182. +MODULE_DESCRIPTION("Lantiq Temperature Sensor");
  183. +MODULE_LICENSE("GPL");