015-2-thermal-qcom-tsens-8916-Add-support-for-8916-family-of-SoCs.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. From 840a5bd3ed3fdd62456d4d26c3128ec10496555b Mon Sep 17 00:00:00 2001
  2. From: Rajendra Nayak <rnayak@codeaurora.org>
  3. Date: Thu, 5 May 2016 14:21:40 +0530
  4. Subject: thermal: qcom: tsens-8916: Add support for 8916 family of SoCs
  5. Add support to calibrate sensors on 8916 family and also add common
  6. functions to read temperature from sensors (This can be reused on
  7. other SoCs having similar TSENS device)
  8. The calibration data is read from eeprom using the generic nvmem
  9. framework apis.
  10. Based on the original code by Siddartha Mohanadoss and Stephen Boyd.
  11. Signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
  12. Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
  13. Signed-off-by: Zhang Rui <rui.zhang@intel.com>
  14. ---
  15. drivers/thermal/qcom/Makefile | 2 +-
  16. drivers/thermal/qcom/tsens-8916.c | 113 ++++++++++++++++++++++++++++++++++++++
  17. drivers/thermal/qcom/tsens.c | 1 +
  18. drivers/thermal/qcom/tsens.h | 2 +
  19. 4 files changed, 117 insertions(+), 1 deletion(-)
  20. create mode 100644 drivers/thermal/qcom/tsens-8916.c
  21. --- a/drivers/thermal/qcom/Makefile
  22. +++ b/drivers/thermal/qcom/Makefile
  23. @@ -1,2 +1,2 @@
  24. obj-$(CONFIG_QCOM_TSENS) += qcom_tsens.o
  25. -qcom_tsens-y += tsens.o tsens-common.o
  26. +qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o
  27. --- /dev/null
  28. +++ b/drivers/thermal/qcom/tsens-8916.c
  29. @@ -0,0 +1,113 @@
  30. +/*
  31. + * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  32. + *
  33. + * This program is free software; you can redistribute it and/or modify
  34. + * it under the terms of the GNU General Public License version 2 and
  35. + * only version 2 as published by the Free Software Foundation.
  36. + *
  37. + * This program is distributed in the hope that it will be useful,
  38. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  39. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  40. + * GNU General Public License for more details.
  41. + *
  42. + */
  43. +
  44. +#include <linux/platform_device.h>
  45. +#include "tsens.h"
  46. +
  47. +/* eeprom layout data for 8916 */
  48. +#define BASE0_MASK 0x0000007f
  49. +#define BASE1_MASK 0xfe000000
  50. +#define BASE0_SHIFT 0
  51. +#define BASE1_SHIFT 25
  52. +
  53. +#define S0_P1_MASK 0x00000f80
  54. +#define S1_P1_MASK 0x003e0000
  55. +#define S2_P1_MASK 0xf8000000
  56. +#define S3_P1_MASK 0x000003e0
  57. +#define S4_P1_MASK 0x000f8000
  58. +
  59. +#define S0_P2_MASK 0x0001f000
  60. +#define S1_P2_MASK 0x07c00000
  61. +#define S2_P2_MASK 0x0000001f
  62. +#define S3_P2_MASK 0x00007c00
  63. +#define S4_P2_MASK 0x01f00000
  64. +
  65. +#define S0_P1_SHIFT 7
  66. +#define S1_P1_SHIFT 17
  67. +#define S2_P1_SHIFT 27
  68. +#define S3_P1_SHIFT 5
  69. +#define S4_P1_SHIFT 15
  70. +
  71. +#define S0_P2_SHIFT 12
  72. +#define S1_P2_SHIFT 22
  73. +#define S2_P2_SHIFT 0
  74. +#define S3_P2_SHIFT 10
  75. +#define S4_P2_SHIFT 20
  76. +
  77. +#define CAL_SEL_MASK 0xe0000000
  78. +#define CAL_SEL_SHIFT 29
  79. +
  80. +static int calibrate_8916(struct tsens_device *tmdev)
  81. +{
  82. + int base0 = 0, base1 = 0, i;
  83. + u32 p1[5], p2[5];
  84. + int mode = 0;
  85. + u32 *qfprom_cdata, *qfprom_csel;
  86. +
  87. + qfprom_cdata = (u32 *)qfprom_read(tmdev->dev, "calib");
  88. + if (IS_ERR(qfprom_cdata))
  89. + return PTR_ERR(qfprom_cdata);
  90. +
  91. + qfprom_csel = (u32 *)qfprom_read(tmdev->dev, "calib_sel");
  92. + if (IS_ERR(qfprom_csel))
  93. + return PTR_ERR(qfprom_csel);
  94. +
  95. + mode = (qfprom_csel[0] & CAL_SEL_MASK) >> CAL_SEL_SHIFT;
  96. + dev_dbg(tmdev->dev, "calibration mode is %d\n", mode);
  97. +
  98. + switch (mode) {
  99. + case TWO_PT_CALIB:
  100. + base1 = (qfprom_cdata[1] & BASE1_MASK) >> BASE1_SHIFT;
  101. + p2[0] = (qfprom_cdata[0] & S0_P2_MASK) >> S0_P2_SHIFT;
  102. + p2[1] = (qfprom_cdata[0] & S1_P2_MASK) >> S1_P2_SHIFT;
  103. + p2[2] = (qfprom_cdata[1] & S2_P2_MASK) >> S2_P2_SHIFT;
  104. + p2[3] = (qfprom_cdata[1] & S3_P2_MASK) >> S3_P2_SHIFT;
  105. + p2[4] = (qfprom_cdata[1] & S4_P2_MASK) >> S4_P2_SHIFT;
  106. + for (i = 0; i < tmdev->num_sensors; i++)
  107. + p2[i] = ((base1 + p2[i]) << 3);
  108. + /* Fall through */
  109. + case ONE_PT_CALIB2:
  110. + base0 = (qfprom_cdata[0] & BASE0_MASK);
  111. + p1[0] = (qfprom_cdata[0] & S0_P1_MASK) >> S0_P1_SHIFT;
  112. + p1[1] = (qfprom_cdata[0] & S1_P1_MASK) >> S1_P1_SHIFT;
  113. + p1[2] = (qfprom_cdata[0] & S2_P1_MASK) >> S2_P1_SHIFT;
  114. + p1[3] = (qfprom_cdata[1] & S3_P1_MASK) >> S3_P1_SHIFT;
  115. + p1[4] = (qfprom_cdata[1] & S4_P1_MASK) >> S4_P1_SHIFT;
  116. + for (i = 0; i < tmdev->num_sensors; i++)
  117. + p1[i] = (((base0) + p1[i]) << 3);
  118. + break;
  119. + default:
  120. + for (i = 0; i < tmdev->num_sensors; i++) {
  121. + p1[i] = 500;
  122. + p2[i] = 780;
  123. + }
  124. + break;
  125. + }
  126. +
  127. + compute_intercept_slope(tmdev, p1, p2, mode);
  128. +
  129. + return 0;
  130. +}
  131. +
  132. +const struct tsens_ops ops_8916 = {
  133. + .init = init_common,
  134. + .calibrate = calibrate_8916,
  135. + .get_temp = get_temp_common,
  136. +};
  137. +
  138. +const struct tsens_data data_8916 = {
  139. + .num_sensors = 5,
  140. + .ops = &ops_8916,
  141. + .hw_ids = (unsigned int []){0, 1, 2, 4, 5 },
  142. +};
  143. --- a/drivers/thermal/qcom/tsens.c
  144. +++ b/drivers/thermal/qcom/tsens.c
  145. @@ -65,6 +65,7 @@ static SIMPLE_DEV_PM_OPS(tsens_pm_ops, t
  146. static const struct of_device_id tsens_table[] = {
  147. {
  148. .compatible = "qcom,msm8916-tsens",
  149. + .data = &data_8916,
  150. }, {
  151. .compatible = "qcom,msm8974-tsens",
  152. },
  153. --- a/drivers/thermal/qcom/tsens.h
  154. +++ b/drivers/thermal/qcom/tsens.h
  155. @@ -87,4 +87,6 @@ void compute_intercept_slope(struct tsen
  156. int init_common(struct tsens_device *);
  157. int get_temp_common(struct tsens_device *, int, int *);
  158. +extern const struct tsens_data data_8916;
  159. +
  160. #endif /* __QCOM_TSENS_H__ */