015-3-thermal-qcom-tsens-8974-Add-support-for-8974-family-of-SoCs.patch 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. From 5e6703bd2d83548998848865cb9a9a795f31a311 Mon Sep 17 00:00:00 2001
  2. From: Rajendra Nayak <rnayak@codeaurora.org>
  3. Date: Thu, 5 May 2016 14:21:41 +0530
  4. Subject: thermal: qcom: tsens-8974: Add support for 8974 family of SoCs
  5. Add .calibrate support for 8974 family as part of tsens_ops.
  6. Based on the original code by Siddartha Mohanadoss and Stephen Boyd.
  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. drivers/thermal/qcom/Makefile | 2 +-
  12. drivers/thermal/qcom/tsens-8974.c | 244 ++++++++++++++++++++++++++++++++++++++
  13. drivers/thermal/qcom/tsens.c | 1 +
  14. drivers/thermal/qcom/tsens.h | 2 +-
  15. 4 files changed, 247 insertions(+), 2 deletions(-)
  16. create mode 100644 drivers/thermal/qcom/tsens-8974.c
  17. --- a/drivers/thermal/qcom/Makefile
  18. +++ b/drivers/thermal/qcom/Makefile
  19. @@ -1,2 +1,2 @@
  20. obj-$(CONFIG_QCOM_TSENS) += qcom_tsens.o
  21. -qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o
  22. +qcom_tsens-y += tsens.o tsens-common.o tsens-8916.o tsens-8974.o
  23. --- /dev/null
  24. +++ b/drivers/thermal/qcom/tsens-8974.c
  25. @@ -0,0 +1,244 @@
  26. +/*
  27. + * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  28. + *
  29. + * This program is free software; you can redistribute it and/or modify
  30. + * it under the terms of the GNU General Public License version 2 and
  31. + * only version 2 as published by the Free Software Foundation.
  32. + *
  33. + * This program is distributed in the hope that it will be useful,
  34. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  36. + * GNU General Public License for more details.
  37. + *
  38. + */
  39. +
  40. +#include <linux/platform_device.h>
  41. +#include "tsens.h"
  42. +
  43. +/* eeprom layout data for 8974 */
  44. +#define BASE1_MASK 0xff
  45. +#define S0_P1_MASK 0x3f00
  46. +#define S1_P1_MASK 0xfc000
  47. +#define S2_P1_MASK 0x3f00000
  48. +#define S3_P1_MASK 0xfc000000
  49. +#define S4_P1_MASK 0x3f
  50. +#define S5_P1_MASK 0xfc0
  51. +#define S6_P1_MASK 0x3f000
  52. +#define S7_P1_MASK 0xfc0000
  53. +#define S8_P1_MASK 0x3f000000
  54. +#define S8_P1_MASK_BKP 0x3f
  55. +#define S9_P1_MASK 0x3f
  56. +#define S9_P1_MASK_BKP 0xfc0
  57. +#define S10_P1_MASK 0xfc0
  58. +#define S10_P1_MASK_BKP 0x3f000
  59. +#define CAL_SEL_0_1 0xc0000000
  60. +#define CAL_SEL_2 0x40000000
  61. +#define CAL_SEL_SHIFT 30
  62. +#define CAL_SEL_SHIFT_2 28
  63. +
  64. +#define S0_P1_SHIFT 8
  65. +#define S1_P1_SHIFT 14
  66. +#define S2_P1_SHIFT 20
  67. +#define S3_P1_SHIFT 26
  68. +#define S5_P1_SHIFT 6
  69. +#define S6_P1_SHIFT 12
  70. +#define S7_P1_SHIFT 18
  71. +#define S8_P1_SHIFT 24
  72. +#define S9_P1_BKP_SHIFT 6
  73. +#define S10_P1_SHIFT 6
  74. +#define S10_P1_BKP_SHIFT 12
  75. +
  76. +#define BASE2_SHIFT 12
  77. +#define BASE2_BKP_SHIFT 18
  78. +#define S0_P2_SHIFT 20
  79. +#define S0_P2_BKP_SHIFT 26
  80. +#define S1_P2_SHIFT 26
  81. +#define S2_P2_BKP_SHIFT 6
  82. +#define S3_P2_SHIFT 6
  83. +#define S3_P2_BKP_SHIFT 12
  84. +#define S4_P2_SHIFT 12
  85. +#define S4_P2_BKP_SHIFT 18
  86. +#define S5_P2_SHIFT 18
  87. +#define S5_P2_BKP_SHIFT 24
  88. +#define S6_P2_SHIFT 24
  89. +#define S7_P2_BKP_SHIFT 6
  90. +#define S8_P2_SHIFT 6
  91. +#define S8_P2_BKP_SHIFT 12
  92. +#define S9_P2_SHIFT 12
  93. +#define S9_P2_BKP_SHIFT 18
  94. +#define S10_P2_SHIFT 18
  95. +#define S10_P2_BKP_SHIFT 24
  96. +
  97. +#define BASE2_MASK 0xff000
  98. +#define BASE2_BKP_MASK 0xfc0000
  99. +#define S0_P2_MASK 0x3f00000
  100. +#define S0_P2_BKP_MASK 0xfc000000
  101. +#define S1_P2_MASK 0xfc000000
  102. +#define S1_P2_BKP_MASK 0x3f
  103. +#define S2_P2_MASK 0x3f
  104. +#define S2_P2_BKP_MASK 0xfc0
  105. +#define S3_P2_MASK 0xfc0
  106. +#define S3_P2_BKP_MASK 0x3f000
  107. +#define S4_P2_MASK 0x3f000
  108. +#define S4_P2_BKP_MASK 0xfc0000
  109. +#define S5_P2_MASK 0xfc0000
  110. +#define S5_P2_BKP_MASK 0x3f000000
  111. +#define S6_P2_MASK 0x3f000000
  112. +#define S6_P2_BKP_MASK 0x3f
  113. +#define S7_P2_MASK 0x3f
  114. +#define S7_P2_BKP_MASK 0xfc0
  115. +#define S8_P2_MASK 0xfc0
  116. +#define S8_P2_BKP_MASK 0x3f000
  117. +#define S9_P2_MASK 0x3f000
  118. +#define S9_P2_BKP_MASK 0xfc0000
  119. +#define S10_P2_MASK 0xfc0000
  120. +#define S10_P2_BKP_MASK 0x3f000000
  121. +
  122. +#define BKP_SEL 0x3
  123. +#define BKP_REDUN_SEL 0xe0000000
  124. +#define BKP_REDUN_SHIFT 29
  125. +
  126. +#define BIT_APPEND 0x3
  127. +
  128. +static int calibrate_8974(struct tsens_device *tmdev)
  129. +{
  130. + int base1 = 0, base2 = 0, i;
  131. + u32 p1[11], p2[11];
  132. + int mode = 0;
  133. + u32 *calib, *bkp;
  134. + u32 calib_redun_sel;
  135. +
  136. + calib = (u32 *)qfprom_read(tmdev->dev, "calib");
  137. + if (IS_ERR(calib))
  138. + return PTR_ERR(calib);
  139. +
  140. + bkp = (u32 *)qfprom_read(tmdev->dev, "calib_backup");
  141. + if (IS_ERR(bkp))
  142. + return PTR_ERR(bkp);
  143. +
  144. + calib_redun_sel = bkp[1] & BKP_REDUN_SEL;
  145. + calib_redun_sel >>= BKP_REDUN_SHIFT;
  146. +
  147. + if (calib_redun_sel == BKP_SEL) {
  148. + mode = (calib[4] & CAL_SEL_0_1) >> CAL_SEL_SHIFT;
  149. + mode |= (calib[5] & CAL_SEL_2) >> CAL_SEL_SHIFT_2;
  150. +
  151. + switch (mode) {
  152. + case TWO_PT_CALIB:
  153. + base2 = (bkp[2] & BASE2_BKP_MASK) >> BASE2_BKP_SHIFT;
  154. + p2[0] = (bkp[2] & S0_P2_BKP_MASK) >> S0_P2_BKP_SHIFT;
  155. + p2[1] = (bkp[3] & S1_P2_BKP_MASK);
  156. + p2[2] = (bkp[3] & S2_P2_BKP_MASK) >> S2_P2_BKP_SHIFT;
  157. + p2[3] = (bkp[3] & S3_P2_BKP_MASK) >> S3_P2_BKP_SHIFT;
  158. + p2[4] = (bkp[3] & S4_P2_BKP_MASK) >> S4_P2_BKP_SHIFT;
  159. + p2[5] = (calib[4] & S5_P2_BKP_MASK) >> S5_P2_BKP_SHIFT;
  160. + p2[6] = (calib[5] & S6_P2_BKP_MASK);
  161. + p2[7] = (calib[5] & S7_P2_BKP_MASK) >> S7_P2_BKP_SHIFT;
  162. + p2[8] = (calib[5] & S8_P2_BKP_MASK) >> S8_P2_BKP_SHIFT;
  163. + p2[9] = (calib[5] & S9_P2_BKP_MASK) >> S9_P2_BKP_SHIFT;
  164. + p2[10] = (calib[5] & S10_P2_BKP_MASK) >> S10_P2_BKP_SHIFT;
  165. + /* Fall through */
  166. + case ONE_PT_CALIB:
  167. + case ONE_PT_CALIB2:
  168. + base1 = bkp[0] & BASE1_MASK;
  169. + p1[0] = (bkp[0] & S0_P1_MASK) >> S0_P1_SHIFT;
  170. + p1[1] = (bkp[0] & S1_P1_MASK) >> S1_P1_SHIFT;
  171. + p1[2] = (bkp[0] & S2_P1_MASK) >> S2_P1_SHIFT;
  172. + p1[3] = (bkp[0] & S3_P1_MASK) >> S3_P1_SHIFT;
  173. + p1[4] = (bkp[1] & S4_P1_MASK);
  174. + p1[5] = (bkp[1] & S5_P1_MASK) >> S5_P1_SHIFT;
  175. + p1[6] = (bkp[1] & S6_P1_MASK) >> S6_P1_SHIFT;
  176. + p1[7] = (bkp[1] & S7_P1_MASK) >> S7_P1_SHIFT;
  177. + p1[8] = (bkp[2] & S8_P1_MASK_BKP) >> S8_P1_SHIFT;
  178. + p1[9] = (bkp[2] & S9_P1_MASK_BKP) >> S9_P1_BKP_SHIFT;
  179. + p1[10] = (bkp[2] & S10_P1_MASK_BKP) >> S10_P1_BKP_SHIFT;
  180. + break;
  181. + }
  182. + } else {
  183. + mode = (calib[1] & CAL_SEL_0_1) >> CAL_SEL_SHIFT;
  184. + mode |= (calib[3] & CAL_SEL_2) >> CAL_SEL_SHIFT_2;
  185. +
  186. + switch (mode) {
  187. + case TWO_PT_CALIB:
  188. + base2 = (calib[2] & BASE2_MASK) >> BASE2_SHIFT;
  189. + p2[0] = (calib[2] & S0_P2_MASK) >> S0_P2_SHIFT;
  190. + p2[1] = (calib[2] & S1_P2_MASK) >> S1_P2_SHIFT;
  191. + p2[2] = (calib[3] & S2_P2_MASK);
  192. + p2[3] = (calib[3] & S3_P2_MASK) >> S3_P2_SHIFT;
  193. + p2[4] = (calib[3] & S4_P2_MASK) >> S4_P2_SHIFT;
  194. + p2[5] = (calib[3] & S5_P2_MASK) >> S5_P2_SHIFT;
  195. + p2[6] = (calib[3] & S6_P2_MASK) >> S6_P2_SHIFT;
  196. + p2[7] = (calib[4] & S7_P2_MASK);
  197. + p2[8] = (calib[4] & S8_P2_MASK) >> S8_P2_SHIFT;
  198. + p2[9] = (calib[4] & S9_P2_MASK) >> S9_P2_SHIFT;
  199. + p2[10] = (calib[4] & S10_P2_MASK) >> S10_P2_SHIFT;
  200. + /* Fall through */
  201. + case ONE_PT_CALIB:
  202. + case ONE_PT_CALIB2:
  203. + base1 = calib[0] & BASE1_MASK;
  204. + p1[0] = (calib[0] & S0_P1_MASK) >> S0_P1_SHIFT;
  205. + p1[1] = (calib[0] & S1_P1_MASK) >> S1_P1_SHIFT;
  206. + p1[2] = (calib[0] & S2_P1_MASK) >> S2_P1_SHIFT;
  207. + p1[3] = (calib[0] & S3_P1_MASK) >> S3_P1_SHIFT;
  208. + p1[4] = (calib[1] & S4_P1_MASK);
  209. + p1[5] = (calib[1] & S5_P1_MASK) >> S5_P1_SHIFT;
  210. + p1[6] = (calib[1] & S6_P1_MASK) >> S6_P1_SHIFT;
  211. + p1[7] = (calib[1] & S7_P1_MASK) >> S7_P1_SHIFT;
  212. + p1[8] = (calib[1] & S8_P1_MASK) >> S8_P1_SHIFT;
  213. + p1[9] = (calib[2] & S9_P1_MASK);
  214. + p1[10] = (calib[2] & S10_P1_MASK) >> S10_P1_SHIFT;
  215. + break;
  216. + }
  217. + }
  218. +
  219. + switch (mode) {
  220. + case ONE_PT_CALIB:
  221. + for (i = 0; i < tmdev->num_sensors; i++)
  222. + p1[i] += (base1 << 2) | BIT_APPEND;
  223. + break;
  224. + case TWO_PT_CALIB:
  225. + for (i = 0; i < tmdev->num_sensors; i++) {
  226. + p2[i] += base2;
  227. + p2[i] <<= 2;
  228. + p2[i] |= BIT_APPEND;
  229. + }
  230. + /* Fall through */
  231. + case ONE_PT_CALIB2:
  232. + for (i = 0; i < tmdev->num_sensors; i++) {
  233. + p1[i] += base1;
  234. + p1[i] <<= 2;
  235. + p1[i] |= BIT_APPEND;
  236. + }
  237. + break;
  238. + default:
  239. + for (i = 0; i < tmdev->num_sensors; i++)
  240. + p2[i] = 780;
  241. + p1[0] = 502;
  242. + p1[1] = 509;
  243. + p1[2] = 503;
  244. + p1[3] = 509;
  245. + p1[4] = 505;
  246. + p1[5] = 509;
  247. + p1[6] = 507;
  248. + p1[7] = 510;
  249. + p1[8] = 508;
  250. + p1[9] = 509;
  251. + p1[10] = 508;
  252. + break;
  253. + }
  254. +
  255. + compute_intercept_slope(tmdev, p1, p2, mode);
  256. +
  257. + return 0;
  258. +}
  259. +
  260. +const struct tsens_ops ops_8974 = {
  261. + .init = init_common,
  262. + .calibrate = calibrate_8974,
  263. + .get_temp = get_temp_common,
  264. +};
  265. +
  266. +const struct tsens_data data_8974 = {
  267. + .num_sensors = 11,
  268. + .ops = &ops_8974,
  269. +};
  270. --- a/drivers/thermal/qcom/tsens.c
  271. +++ b/drivers/thermal/qcom/tsens.c
  272. @@ -68,6 +68,7 @@ static const struct of_device_id tsens_t
  273. .data = &data_8916,
  274. }, {
  275. .compatible = "qcom,msm8974-tsens",
  276. + .data = &data_8974,
  277. },
  278. {}
  279. };
  280. --- a/drivers/thermal/qcom/tsens.h
  281. +++ b/drivers/thermal/qcom/tsens.h
  282. @@ -87,6 +87,6 @@ void compute_intercept_slope(struct tsen
  283. int init_common(struct tsens_device *);
  284. int get_temp_common(struct tsens_device *, int, int *);
  285. -extern const struct tsens_data data_8916;
  286. +extern const struct tsens_data data_8916, data_8974;
  287. #endif /* __QCOM_TSENS_H__ */