912-hwmon-lm90-expose-to-thermal-fw-via-DT.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. From: Wei Ni <wni@nvidia.com>
  2. Subject: hwmon: lm90: expose to thermal fw via DT nodes
  3. This patch adds to lm90 temperature sensor the possibility
  4. to expose itself as thermal zone device, registered on the
  5. thermal framework.
  6. The thermal zone is built only if a device tree node
  7. describing a thermal zone for this sensor is present
  8. inside the lm90 DT node. Otherwise, the driver behavior
  9. will be the same.
  10. Discussed in:
  11. http://www.gossamer-threads.com/lists/linux/kernel/1992853
  12. BUG=chrome-os-partner:30834
  13. TEST=Verified. Build and boot up system.
  14. Signed-off-by: Wei Ni <wni@nvidia.com>
  15. Reviewed-on: https://chromium-review.googlesource.com/181447
  16. Reviewed-by: Dylan Reid <dgreid@chromium.org>
  17. Tested-by: Dylan Reid <dgreid@chromium.org>
  18. Commit-Queue: Dylan Reid <dgreid@chromium.org>
  19. Change-Id: Id356b94d7e8f4b49ec15e46b17a1fa2ff0cbf8cf
  20. Reviewed-on: https://chromium-review.googlesource.com/212414
  21. Tested-by: Wei Ni <wni.nvidia@gmail.com>
  22. Reviewed-by: Olof Johansson <olofj@chromium.org>
  23. Commit-Queue: Olof Johansson <olofj@chromium.org>
  24. ---
  25. --- a/drivers/hwmon/lm90.c
  26. +++ b/drivers/hwmon/lm90.c
  27. @@ -96,6 +96,8 @@
  28. #include <linux/sysfs.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/regulator/consumer.h>
  31. +#include <linux/of.h>
  32. +#include <linux/thermal.h>
  33. /*
  34. * Addresses to scan
  35. @@ -119,6 +121,13 @@ static const unsigned short normal_i2c[]
  36. enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680,
  37. max6646, w83l771, max6696, sa56004, g781, tmp451 };
  38. +enum sensor_id {
  39. + LOCAL = 0,
  40. + REMOTE,
  41. + REMOTE2,
  42. + SENSOR_ID_END,
  43. +};
  44. +
  45. /*
  46. * The LM90 registers
  47. */
  48. @@ -368,6 +377,7 @@ struct lm90_data {
  49. struct i2c_client *client;
  50. struct device *hwmon_dev;
  51. const struct attribute_group *groups[6];
  52. + struct thermal_zone_device *tz[SENSOR_ID_END];
  53. struct mutex update_lock;
  54. struct regulator *regulator;
  55. char valid; /* zero until following fields are valid */
  56. @@ -880,6 +890,24 @@ static ssize_t show_temp11(struct device
  57. return sprintf(buf, "%d\n", read_temp11(dev, attr->index));
  58. }
  59. +static int lm90_read_local_temp(void *dev, int *temp)
  60. +{
  61. + *temp = read_temp11(dev, 4);
  62. + return 0;
  63. +}
  64. +
  65. +static int lm90_read_remote_temp(void *dev, int *temp)
  66. +{
  67. + *temp = read_temp11(dev, 0);
  68. + return 0;
  69. +}
  70. +
  71. +static int lm90_read_remote2_temp(void *dev, int *temp)
  72. +{
  73. + *temp = read_temp11(dev, 5);
  74. + return 0;
  75. +}
  76. +
  77. static int write_temp11(struct device *dev, int nr, int index, long val)
  78. {
  79. struct {
  80. @@ -1210,6 +1238,18 @@ static const struct attribute_group lm90
  81. .attrs = lm90_temp3_attributes,
  82. };
  83. +static const struct thermal_zone_of_device_ops local_temp_sensor = {
  84. + .get_temp = lm90_read_local_temp,
  85. +};
  86. +
  87. +static const struct thermal_zone_of_device_ops remote_temp_sensor = {
  88. + .get_temp = lm90_read_remote_temp,
  89. +};
  90. +
  91. +static const struct thermal_zone_of_device_ops remote2_temp_sensor = {
  92. + .get_temp = lm90_read_remote2_temp,
  93. +};
  94. +
  95. /* pec used for ADM1032 only */
  96. static ssize_t show_pec(struct device *dev, struct device_attribute *dummy,
  97. char *buf)
  98. @@ -1659,6 +1699,30 @@ static int lm90_probe(struct i2c_client
  99. }
  100. }
  101. + data->tz[LOCAL] = thermal_zone_of_sensor_register(&client->dev,
  102. + LOCAL,
  103. + &client->dev,
  104. + &local_temp_sensor);
  105. + if (IS_ERR(data->tz[LOCAL]))
  106. + data->tz[LOCAL] = NULL;
  107. +
  108. + data->tz[REMOTE] = thermal_zone_of_sensor_register(&client->dev,
  109. + REMOTE,
  110. + &client->dev,
  111. + &remote_temp_sensor);
  112. + if (IS_ERR(data->tz[REMOTE]))
  113. + data->tz[REMOTE] = NULL;
  114. +
  115. + if (data->flags & LM90_HAVE_TEMP3) {
  116. + data->tz[REMOTE2] = thermal_zone_of_sensor_register(
  117. + &client->dev,
  118. + REMOTE2,
  119. + &client->dev,
  120. + &remote2_temp_sensor);
  121. + if (IS_ERR(data->tz[REMOTE2]))
  122. + data->tz[REMOTE2] = NULL;
  123. + }
  124. +
  125. return 0;
  126. exit_unregister:
  127. @@ -1674,8 +1738,11 @@ exit_restore:
  128. static int lm90_remove(struct i2c_client *client)
  129. {
  130. + int i;
  131. struct lm90_data *data = i2c_get_clientdata(client);
  132. + for (i = 0; i < SENSOR_ID_END; i++)
  133. + thermal_zone_of_sensor_unregister(&client->dev, data->tz[i]);
  134. hwmon_device_unregister(data->hwmon_dev);
  135. device_remove_file(&client->dev, &dev_attr_pec);
  136. lm90_restore_conf(client, data);