086-0002-thermal-core-export-apis-to-get-slope-and-offset.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. From 4a7069a32c99a81950de035535b0a064dcceaeba Mon Sep 17 00:00:00 2001
  2. From: Rajendra Nayak <rnayak@codeaurora.org>
  3. Date: Thu, 5 May 2016 14:21:42 +0530
  4. Subject: [PATCH] thermal: core: export apis to get slope and offset
  5. Add apis for platform thermal drivers to query for slope and offset
  6. attributes, which might be needed for temperature calculations.
  7. Signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
  8. Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
  9. Signed-off-by: Zhang Rui <rui.zhang@intel.com>
  10. ---
  11. Documentation/thermal/sysfs-api.txt | 12 ++++++++++++
  12. drivers/thermal/thermal_core.c | 30 ++++++++++++++++++++++++++++++
  13. include/linux/thermal.h | 8 ++++++++
  14. 3 files changed, 50 insertions(+)
  15. --- a/Documentation/thermal/sysfs-api.txt
  16. +++ b/Documentation/thermal/sysfs-api.txt
  17. @@ -72,6 +72,18 @@ temperature) and throttle appropriate de
  18. It deletes the corresponding entry form /sys/class/thermal folder and
  19. unbind all the thermal cooling devices it uses.
  20. +1.1.7 int thermal_zone_get_slope(struct thermal_zone_device *tz)
  21. +
  22. + This interface is used to read the slope attribute value
  23. + for the thermal zone device, which might be useful for platform
  24. + drivers for temperature calculations.
  25. +
  26. +1.1.8 int thermal_zone_get_offset(struct thermal_zone_device *tz)
  27. +
  28. + This interface is used to read the offset attribute value
  29. + for the thermal zone device, which might be useful for platform
  30. + drivers for temperature calculations.
  31. +
  32. 1.2 thermal cooling device interface
  33. 1.2.1 struct thermal_cooling_device *thermal_cooling_device_register(char *name,
  34. void *devdata, struct thermal_cooling_device_ops *)
  35. --- a/drivers/thermal/thermal_core.c
  36. +++ b/drivers/thermal/thermal_core.c
  37. @@ -2061,6 +2061,36 @@ exit:
  38. }
  39. EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
  40. +/**
  41. + * thermal_zone_get_slope - return the slope attribute of the thermal zone
  42. + * @tz: thermal zone device with the slope attribute
  43. + *
  44. + * Return: If the thermal zone device has a slope attribute, return it, else
  45. + * return 1.
  46. + */
  47. +int thermal_zone_get_slope(struct thermal_zone_device *tz)
  48. +{
  49. + if (tz && tz->tzp)
  50. + return tz->tzp->slope;
  51. + return 1;
  52. +}
  53. +EXPORT_SYMBOL_GPL(thermal_zone_get_slope);
  54. +
  55. +/**
  56. + * thermal_zone_get_offset - return the offset attribute of the thermal zone
  57. + * @tz: thermal zone device with the offset attribute
  58. + *
  59. + * Return: If the thermal zone device has a offset attribute, return it, else
  60. + * return 0.
  61. + */
  62. +int thermal_zone_get_offset(struct thermal_zone_device *tz)
  63. +{
  64. + if (tz && tz->tzp)
  65. + return tz->tzp->offset;
  66. + return 0;
  67. +}
  68. +EXPORT_SYMBOL_GPL(thermal_zone_get_offset);
  69. +
  70. #ifdef CONFIG_NET
  71. static const struct genl_multicast_group thermal_event_mcgrps[] = {
  72. { .name = THERMAL_GENL_MCAST_GROUP_NAME, },
  73. --- a/include/linux/thermal.h
  74. +++ b/include/linux/thermal.h
  75. @@ -432,6 +432,8 @@ thermal_of_cooling_device_register(struc
  76. void thermal_cooling_device_unregister(struct thermal_cooling_device *);
  77. struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
  78. int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
  79. +int thermal_zone_get_slope(struct thermal_zone_device *tz);
  80. +int thermal_zone_get_offset(struct thermal_zone_device *tz);
  81. int get_tz_trend(struct thermal_zone_device *, int);
  82. struct thermal_instance *get_thermal_instance(struct thermal_zone_device *,
  83. @@ -489,6 +491,12 @@ static inline struct thermal_zone_device
  84. static inline int thermal_zone_get_temp(
  85. struct thermal_zone_device *tz, int *temp)
  86. { return -ENODEV; }
  87. +static inline int thermal_zone_get_slope(
  88. + struct thermal_zone_device *tz)
  89. +{ return -ENODEV; }
  90. +static inline int thermal_zone_get_offset(
  91. + struct thermal_zone_device *tz)
  92. +{ return -ENODEV; }
  93. static inline int get_tz_trend(struct thermal_zone_device *tz, int trip)
  94. { return -ENODEV; }
  95. static inline struct thermal_instance *