tsens.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __QCOM_TSENS_H__
  6. #define __QCOM_TSENS_H__
  7. #define NO_PT_CALIB 0x0
  8. #define ONE_PT_CALIB 0x1
  9. #define ONE_PT_CALIB2 0x2
  10. #define TWO_PT_CALIB 0x3
  11. #define ONE_PT_CALIB2_NO_OFFSET 0x6
  12. #define TWO_PT_CALIB_NO_OFFSET 0x7
  13. #define CAL_DEGC_PT1 30
  14. #define CAL_DEGC_PT2 120
  15. #define SLOPE_FACTOR 1000
  16. #define SLOPE_DEFAULT 3200
  17. #define TIMEOUT_US 100
  18. #define THRESHOLD_MAX_ADC_CODE 0x3ff
  19. #define THRESHOLD_MIN_ADC_CODE 0x0
  20. #define MAX_SENSORS 16
  21. #include <linux/interrupt.h>
  22. #include <linux/thermal.h>
  23. #include <linux/regmap.h>
  24. #include <linux/slab.h>
  25. struct tsens_priv;
  26. /* IP version numbers in ascending order */
  27. enum tsens_ver {
  28. VER_0 = 0,
  29. VER_0_1,
  30. VER_1_X,
  31. VER_1_X_NO_RPM,
  32. VER_2_X,
  33. VER_2_X_NO_RPM,
  34. };
  35. enum tsens_irq_type {
  36. LOWER,
  37. UPPER,
  38. CRITICAL,
  39. };
  40. /**
  41. * struct tsens_sensor - data for each sensor connected to the tsens device
  42. * @priv: tsens device instance that this sensor is connected to
  43. * @tzd: pointer to the thermal zone that this sensor is in
  44. * @offset: offset of temperature adjustment curve
  45. * @hw_id: HW ID can be used in case of platform-specific IDs
  46. * @slope: slope of temperature adjustment curve
  47. * @status: 8960-specific variable to track 8960 and 8660 status register offset
  48. */
  49. struct tsens_sensor {
  50. struct tsens_priv *priv;
  51. struct thermal_zone_device *tzd;
  52. int offset;
  53. unsigned int hw_id;
  54. int slope;
  55. u32 status;
  56. int p1_calib_offset;
  57. int p2_calib_offset;
  58. };
  59. /**
  60. * struct tsens_ops - operations as supported by the tsens device
  61. * @init: Function to initialize the tsens device
  62. * @calibrate: Function to calibrate the tsens device
  63. * @get_temp: Function which returns the temp in millidegC
  64. * @enable: Function to enable (clocks/power) tsens device
  65. * @disable: Function to disable the tsens device
  66. * @suspend: Function to suspend the tsens device
  67. * @resume: Function to resume the tsens device
  68. */
  69. struct tsens_ops {
  70. /* mandatory callbacks */
  71. int (*init)(struct tsens_priv *priv);
  72. int (*calibrate)(struct tsens_priv *priv);
  73. int (*get_temp)(const struct tsens_sensor *s, int *temp);
  74. /* optional callbacks */
  75. int (*enable)(struct tsens_priv *priv, int i);
  76. void (*disable)(struct tsens_priv *priv);
  77. int (*suspend)(struct tsens_priv *priv);
  78. int (*resume)(struct tsens_priv *priv);
  79. };
  80. #define REG_FIELD_FOR_EACH_SENSOR11(_name, _offset, _startbit, _stopbit) \
  81. [_name##_##0] = REG_FIELD(_offset, _startbit, _stopbit), \
  82. [_name##_##1] = REG_FIELD(_offset + 4, _startbit, _stopbit), \
  83. [_name##_##2] = REG_FIELD(_offset + 8, _startbit, _stopbit), \
  84. [_name##_##3] = REG_FIELD(_offset + 12, _startbit, _stopbit), \
  85. [_name##_##4] = REG_FIELD(_offset + 16, _startbit, _stopbit), \
  86. [_name##_##5] = REG_FIELD(_offset + 20, _startbit, _stopbit), \
  87. [_name##_##6] = REG_FIELD(_offset + 24, _startbit, _stopbit), \
  88. [_name##_##7] = REG_FIELD(_offset + 28, _startbit, _stopbit), \
  89. [_name##_##8] = REG_FIELD(_offset + 32, _startbit, _stopbit), \
  90. [_name##_##9] = REG_FIELD(_offset + 36, _startbit, _stopbit), \
  91. [_name##_##10] = REG_FIELD(_offset + 40, _startbit, _stopbit)
  92. #define REG_FIELD_FOR_EACH_SENSOR16(_name, _offset, _startbit, _stopbit) \
  93. [_name##_##0] = REG_FIELD(_offset, _startbit, _stopbit), \
  94. [_name##_##1] = REG_FIELD(_offset + 4, _startbit, _stopbit), \
  95. [_name##_##2] = REG_FIELD(_offset + 8, _startbit, _stopbit), \
  96. [_name##_##3] = REG_FIELD(_offset + 12, _startbit, _stopbit), \
  97. [_name##_##4] = REG_FIELD(_offset + 16, _startbit, _stopbit), \
  98. [_name##_##5] = REG_FIELD(_offset + 20, _startbit, _stopbit), \
  99. [_name##_##6] = REG_FIELD(_offset + 24, _startbit, _stopbit), \
  100. [_name##_##7] = REG_FIELD(_offset + 28, _startbit, _stopbit), \
  101. [_name##_##8] = REG_FIELD(_offset + 32, _startbit, _stopbit), \
  102. [_name##_##9] = REG_FIELD(_offset + 36, _startbit, _stopbit), \
  103. [_name##_##10] = REG_FIELD(_offset + 40, _startbit, _stopbit), \
  104. [_name##_##11] = REG_FIELD(_offset + 44, _startbit, _stopbit), \
  105. [_name##_##12] = REG_FIELD(_offset + 48, _startbit, _stopbit), \
  106. [_name##_##13] = REG_FIELD(_offset + 52, _startbit, _stopbit), \
  107. [_name##_##14] = REG_FIELD(_offset + 56, _startbit, _stopbit), \
  108. [_name##_##15] = REG_FIELD(_offset + 60, _startbit, _stopbit)
  109. #define REG_FIELD_SPLIT_BITS_0_15(_name, _offset) \
  110. [_name##_##0] = REG_FIELD(_offset, 0, 0), \
  111. [_name##_##1] = REG_FIELD(_offset, 1, 1), \
  112. [_name##_##2] = REG_FIELD(_offset, 2, 2), \
  113. [_name##_##3] = REG_FIELD(_offset, 3, 3), \
  114. [_name##_##4] = REG_FIELD(_offset, 4, 4), \
  115. [_name##_##5] = REG_FIELD(_offset, 5, 5), \
  116. [_name##_##6] = REG_FIELD(_offset, 6, 6), \
  117. [_name##_##7] = REG_FIELD(_offset, 7, 7), \
  118. [_name##_##8] = REG_FIELD(_offset, 8, 8), \
  119. [_name##_##9] = REG_FIELD(_offset, 9, 9), \
  120. [_name##_##10] = REG_FIELD(_offset, 10, 10), \
  121. [_name##_##11] = REG_FIELD(_offset, 11, 11), \
  122. [_name##_##12] = REG_FIELD(_offset, 12, 12), \
  123. [_name##_##13] = REG_FIELD(_offset, 13, 13), \
  124. [_name##_##14] = REG_FIELD(_offset, 14, 14), \
  125. [_name##_##15] = REG_FIELD(_offset, 15, 15)
  126. #define REG_FIELD_SPLIT_BITS_16_31(_name, _offset) \
  127. [_name##_##0] = REG_FIELD(_offset, 16, 16), \
  128. [_name##_##1] = REG_FIELD(_offset, 17, 17), \
  129. [_name##_##2] = REG_FIELD(_offset, 18, 18), \
  130. [_name##_##3] = REG_FIELD(_offset, 19, 19), \
  131. [_name##_##4] = REG_FIELD(_offset, 20, 20), \
  132. [_name##_##5] = REG_FIELD(_offset, 21, 21), \
  133. [_name##_##6] = REG_FIELD(_offset, 22, 22), \
  134. [_name##_##7] = REG_FIELD(_offset, 23, 23), \
  135. [_name##_##8] = REG_FIELD(_offset, 24, 24), \
  136. [_name##_##9] = REG_FIELD(_offset, 25, 25), \
  137. [_name##_##10] = REG_FIELD(_offset, 26, 26), \
  138. [_name##_##11] = REG_FIELD(_offset, 27, 27), \
  139. [_name##_##12] = REG_FIELD(_offset, 28, 28), \
  140. [_name##_##13] = REG_FIELD(_offset, 29, 29), \
  141. [_name##_##14] = REG_FIELD(_offset, 30, 30), \
  142. [_name##_##15] = REG_FIELD(_offset, 31, 31)
  143. /*
  144. * reg_field IDs to use as an index into an array
  145. * If you change the order of the entries, check the devm_regmap_field_alloc()
  146. * calls in init_common()
  147. */
  148. enum regfield_ids {
  149. /* ----- SROT ------ */
  150. /* HW_VER */
  151. VER_MAJOR,
  152. VER_MINOR,
  153. VER_STEP,
  154. /* CTRL_OFFSET */
  155. TSENS_EN,
  156. TSENS_SW_RST,
  157. SENSOR_EN,
  158. CODE_OR_TEMP,
  159. MAIN_MEASURE_PERIOD,
  160. /* ----- TM ------ */
  161. /* TRDY */
  162. TRDY,
  163. /* INTERRUPT ENABLE */
  164. INT_EN, /* v2+ has separate enables for crit, upper and lower irq */
  165. /* STATUS */
  166. LAST_TEMP_0, /* Last temperature reading */
  167. LAST_TEMP_1,
  168. LAST_TEMP_2,
  169. LAST_TEMP_3,
  170. LAST_TEMP_4,
  171. LAST_TEMP_5,
  172. LAST_TEMP_6,
  173. LAST_TEMP_7,
  174. LAST_TEMP_8,
  175. LAST_TEMP_9,
  176. LAST_TEMP_10,
  177. LAST_TEMP_11,
  178. LAST_TEMP_12,
  179. LAST_TEMP_13,
  180. LAST_TEMP_14,
  181. LAST_TEMP_15,
  182. VALID_0, /* VALID reading or not */
  183. VALID_1,
  184. VALID_2,
  185. VALID_3,
  186. VALID_4,
  187. VALID_5,
  188. VALID_6,
  189. VALID_7,
  190. VALID_8,
  191. VALID_9,
  192. VALID_10,
  193. VALID_11,
  194. VALID_12,
  195. VALID_13,
  196. VALID_14,
  197. VALID_15,
  198. LOWER_STATUS_0, /* LOWER threshold violated */
  199. LOWER_STATUS_1,
  200. LOWER_STATUS_2,
  201. LOWER_STATUS_3,
  202. LOWER_STATUS_4,
  203. LOWER_STATUS_5,
  204. LOWER_STATUS_6,
  205. LOWER_STATUS_7,
  206. LOWER_STATUS_8,
  207. LOWER_STATUS_9,
  208. LOWER_STATUS_10,
  209. LOWER_STATUS_11,
  210. LOWER_STATUS_12,
  211. LOWER_STATUS_13,
  212. LOWER_STATUS_14,
  213. LOWER_STATUS_15,
  214. LOW_INT_STATUS_0, /* LOWER interrupt status */
  215. LOW_INT_STATUS_1,
  216. LOW_INT_STATUS_2,
  217. LOW_INT_STATUS_3,
  218. LOW_INT_STATUS_4,
  219. LOW_INT_STATUS_5,
  220. LOW_INT_STATUS_6,
  221. LOW_INT_STATUS_7,
  222. LOW_INT_STATUS_8,
  223. LOW_INT_STATUS_9,
  224. LOW_INT_STATUS_10,
  225. LOW_INT_STATUS_11,
  226. LOW_INT_STATUS_12,
  227. LOW_INT_STATUS_13,
  228. LOW_INT_STATUS_14,
  229. LOW_INT_STATUS_15,
  230. LOW_INT_CLEAR_0, /* LOWER interrupt clear */
  231. LOW_INT_CLEAR_1,
  232. LOW_INT_CLEAR_2,
  233. LOW_INT_CLEAR_3,
  234. LOW_INT_CLEAR_4,
  235. LOW_INT_CLEAR_5,
  236. LOW_INT_CLEAR_6,
  237. LOW_INT_CLEAR_7,
  238. LOW_INT_CLEAR_8,
  239. LOW_INT_CLEAR_9,
  240. LOW_INT_CLEAR_10,
  241. LOW_INT_CLEAR_11,
  242. LOW_INT_CLEAR_12,
  243. LOW_INT_CLEAR_13,
  244. LOW_INT_CLEAR_14,
  245. LOW_INT_CLEAR_15,
  246. LOW_INT_MASK_0, /* LOWER interrupt mask */
  247. LOW_INT_MASK_1,
  248. LOW_INT_MASK_2,
  249. LOW_INT_MASK_3,
  250. LOW_INT_MASK_4,
  251. LOW_INT_MASK_5,
  252. LOW_INT_MASK_6,
  253. LOW_INT_MASK_7,
  254. LOW_INT_MASK_8,
  255. LOW_INT_MASK_9,
  256. LOW_INT_MASK_10,
  257. LOW_INT_MASK_11,
  258. LOW_INT_MASK_12,
  259. LOW_INT_MASK_13,
  260. LOW_INT_MASK_14,
  261. LOW_INT_MASK_15,
  262. LOW_THRESH_0, /* LOWER threshold values */
  263. LOW_THRESH_1,
  264. LOW_THRESH_2,
  265. LOW_THRESH_3,
  266. LOW_THRESH_4,
  267. LOW_THRESH_5,
  268. LOW_THRESH_6,
  269. LOW_THRESH_7,
  270. LOW_THRESH_8,
  271. LOW_THRESH_9,
  272. LOW_THRESH_10,
  273. LOW_THRESH_11,
  274. LOW_THRESH_12,
  275. LOW_THRESH_13,
  276. LOW_THRESH_14,
  277. LOW_THRESH_15,
  278. UPPER_STATUS_0, /* UPPER threshold violated */
  279. UPPER_STATUS_1,
  280. UPPER_STATUS_2,
  281. UPPER_STATUS_3,
  282. UPPER_STATUS_4,
  283. UPPER_STATUS_5,
  284. UPPER_STATUS_6,
  285. UPPER_STATUS_7,
  286. UPPER_STATUS_8,
  287. UPPER_STATUS_9,
  288. UPPER_STATUS_10,
  289. UPPER_STATUS_11,
  290. UPPER_STATUS_12,
  291. UPPER_STATUS_13,
  292. UPPER_STATUS_14,
  293. UPPER_STATUS_15,
  294. UP_INT_STATUS_0, /* UPPER interrupt status */
  295. UP_INT_STATUS_1,
  296. UP_INT_STATUS_2,
  297. UP_INT_STATUS_3,
  298. UP_INT_STATUS_4,
  299. UP_INT_STATUS_5,
  300. UP_INT_STATUS_6,
  301. UP_INT_STATUS_7,
  302. UP_INT_STATUS_8,
  303. UP_INT_STATUS_9,
  304. UP_INT_STATUS_10,
  305. UP_INT_STATUS_11,
  306. UP_INT_STATUS_12,
  307. UP_INT_STATUS_13,
  308. UP_INT_STATUS_14,
  309. UP_INT_STATUS_15,
  310. UP_INT_CLEAR_0, /* UPPER interrupt clear */
  311. UP_INT_CLEAR_1,
  312. UP_INT_CLEAR_2,
  313. UP_INT_CLEAR_3,
  314. UP_INT_CLEAR_4,
  315. UP_INT_CLEAR_5,
  316. UP_INT_CLEAR_6,
  317. UP_INT_CLEAR_7,
  318. UP_INT_CLEAR_8,
  319. UP_INT_CLEAR_9,
  320. UP_INT_CLEAR_10,
  321. UP_INT_CLEAR_11,
  322. UP_INT_CLEAR_12,
  323. UP_INT_CLEAR_13,
  324. UP_INT_CLEAR_14,
  325. UP_INT_CLEAR_15,
  326. UP_INT_MASK_0, /* UPPER interrupt mask */
  327. UP_INT_MASK_1,
  328. UP_INT_MASK_2,
  329. UP_INT_MASK_3,
  330. UP_INT_MASK_4,
  331. UP_INT_MASK_5,
  332. UP_INT_MASK_6,
  333. UP_INT_MASK_7,
  334. UP_INT_MASK_8,
  335. UP_INT_MASK_9,
  336. UP_INT_MASK_10,
  337. UP_INT_MASK_11,
  338. UP_INT_MASK_12,
  339. UP_INT_MASK_13,
  340. UP_INT_MASK_14,
  341. UP_INT_MASK_15,
  342. UP_THRESH_0, /* UPPER threshold values */
  343. UP_THRESH_1,
  344. UP_THRESH_2,
  345. UP_THRESH_3,
  346. UP_THRESH_4,
  347. UP_THRESH_5,
  348. UP_THRESH_6,
  349. UP_THRESH_7,
  350. UP_THRESH_8,
  351. UP_THRESH_9,
  352. UP_THRESH_10,
  353. UP_THRESH_11,
  354. UP_THRESH_12,
  355. UP_THRESH_13,
  356. UP_THRESH_14,
  357. UP_THRESH_15,
  358. CRITICAL_STATUS_0, /* CRITICAL threshold violated */
  359. CRITICAL_STATUS_1,
  360. CRITICAL_STATUS_2,
  361. CRITICAL_STATUS_3,
  362. CRITICAL_STATUS_4,
  363. CRITICAL_STATUS_5,
  364. CRITICAL_STATUS_6,
  365. CRITICAL_STATUS_7,
  366. CRITICAL_STATUS_8,
  367. CRITICAL_STATUS_9,
  368. CRITICAL_STATUS_10,
  369. CRITICAL_STATUS_11,
  370. CRITICAL_STATUS_12,
  371. CRITICAL_STATUS_13,
  372. CRITICAL_STATUS_14,
  373. CRITICAL_STATUS_15,
  374. CRIT_INT_STATUS_0, /* CRITICAL interrupt status */
  375. CRIT_INT_STATUS_1,
  376. CRIT_INT_STATUS_2,
  377. CRIT_INT_STATUS_3,
  378. CRIT_INT_STATUS_4,
  379. CRIT_INT_STATUS_5,
  380. CRIT_INT_STATUS_6,
  381. CRIT_INT_STATUS_7,
  382. CRIT_INT_STATUS_8,
  383. CRIT_INT_STATUS_9,
  384. CRIT_INT_STATUS_10,
  385. CRIT_INT_STATUS_11,
  386. CRIT_INT_STATUS_12,
  387. CRIT_INT_STATUS_13,
  388. CRIT_INT_STATUS_14,
  389. CRIT_INT_STATUS_15,
  390. CRIT_INT_CLEAR_0, /* CRITICAL interrupt clear */
  391. CRIT_INT_CLEAR_1,
  392. CRIT_INT_CLEAR_2,
  393. CRIT_INT_CLEAR_3,
  394. CRIT_INT_CLEAR_4,
  395. CRIT_INT_CLEAR_5,
  396. CRIT_INT_CLEAR_6,
  397. CRIT_INT_CLEAR_7,
  398. CRIT_INT_CLEAR_8,
  399. CRIT_INT_CLEAR_9,
  400. CRIT_INT_CLEAR_10,
  401. CRIT_INT_CLEAR_11,
  402. CRIT_INT_CLEAR_12,
  403. CRIT_INT_CLEAR_13,
  404. CRIT_INT_CLEAR_14,
  405. CRIT_INT_CLEAR_15,
  406. CRIT_INT_MASK_0, /* CRITICAL interrupt mask */
  407. CRIT_INT_MASK_1,
  408. CRIT_INT_MASK_2,
  409. CRIT_INT_MASK_3,
  410. CRIT_INT_MASK_4,
  411. CRIT_INT_MASK_5,
  412. CRIT_INT_MASK_6,
  413. CRIT_INT_MASK_7,
  414. CRIT_INT_MASK_8,
  415. CRIT_INT_MASK_9,
  416. CRIT_INT_MASK_10,
  417. CRIT_INT_MASK_11,
  418. CRIT_INT_MASK_12,
  419. CRIT_INT_MASK_13,
  420. CRIT_INT_MASK_14,
  421. CRIT_INT_MASK_15,
  422. CRIT_THRESH_0, /* CRITICAL threshold values */
  423. CRIT_THRESH_1,
  424. CRIT_THRESH_2,
  425. CRIT_THRESH_3,
  426. CRIT_THRESH_4,
  427. CRIT_THRESH_5,
  428. CRIT_THRESH_6,
  429. CRIT_THRESH_7,
  430. CRIT_THRESH_8,
  431. CRIT_THRESH_9,
  432. CRIT_THRESH_10,
  433. CRIT_THRESH_11,
  434. CRIT_THRESH_12,
  435. CRIT_THRESH_13,
  436. CRIT_THRESH_14,
  437. CRIT_THRESH_15,
  438. /* WATCHDOG */
  439. WDOG_BARK_STATUS,
  440. WDOG_BARK_CLEAR,
  441. WDOG_BARK_MASK,
  442. WDOG_BARK_COUNT,
  443. /* CYCLE COMPLETION MONITOR */
  444. CC_MON_STATUS,
  445. CC_MON_CLEAR,
  446. CC_MON_MASK,
  447. MIN_STATUS_0, /* MIN threshold violated */
  448. MIN_STATUS_1,
  449. MIN_STATUS_2,
  450. MIN_STATUS_3,
  451. MIN_STATUS_4,
  452. MIN_STATUS_5,
  453. MIN_STATUS_6,
  454. MIN_STATUS_7,
  455. MIN_STATUS_8,
  456. MIN_STATUS_9,
  457. MIN_STATUS_10,
  458. MIN_STATUS_11,
  459. MIN_STATUS_12,
  460. MIN_STATUS_13,
  461. MIN_STATUS_14,
  462. MIN_STATUS_15,
  463. MAX_STATUS_0, /* MAX threshold violated */
  464. MAX_STATUS_1,
  465. MAX_STATUS_2,
  466. MAX_STATUS_3,
  467. MAX_STATUS_4,
  468. MAX_STATUS_5,
  469. MAX_STATUS_6,
  470. MAX_STATUS_7,
  471. MAX_STATUS_8,
  472. MAX_STATUS_9,
  473. MAX_STATUS_10,
  474. MAX_STATUS_11,
  475. MAX_STATUS_12,
  476. MAX_STATUS_13,
  477. MAX_STATUS_14,
  478. MAX_STATUS_15,
  479. /* Keep last */
  480. MAX_REGFIELDS
  481. };
  482. /**
  483. * struct tsens_features - Features supported by the IP
  484. * @ver_major: Major number of IP version
  485. * @crit_int: does the IP support critical interrupts?
  486. * @combo_int: does the IP use one IRQ for up, low and critical thresholds?
  487. * @adc: do the sensors only output adc code (instead of temperature)?
  488. * @srot_split: does the IP neatly splits the register space into SROT and TM,
  489. * with SROT only being available to secure boot firmware?
  490. * @has_watchdog: does this IP support watchdog functionality?
  491. * @max_sensors: maximum sensors supported by this version of the IP
  492. * @trip_min_temp: minimum trip temperature supported by this version of the IP
  493. * @trip_max_temp: maximum trip temperature supported by this version of the IP
  494. */
  495. struct tsens_features {
  496. unsigned int ver_major;
  497. unsigned int crit_int:1;
  498. unsigned int combo_int:1;
  499. unsigned int adc:1;
  500. unsigned int srot_split:1;
  501. unsigned int has_watchdog:1;
  502. unsigned int max_sensors;
  503. int trip_min_temp;
  504. int trip_max_temp;
  505. };
  506. /**
  507. * struct tsens_plat_data - tsens compile-time platform data
  508. * @num_sensors: Number of sensors supported by platform
  509. * @ops: operations the tsens instance supports
  510. * @hw_ids: Subset of sensors ids supported by platform, if not the first n
  511. * @feat: features of the IP
  512. * @fields: bitfield locations
  513. */
  514. struct tsens_plat_data {
  515. const u32 num_sensors;
  516. const struct tsens_ops *ops;
  517. unsigned int *hw_ids;
  518. struct tsens_features *feat;
  519. const struct reg_field *fields;
  520. };
  521. /**
  522. * struct tsens_context - Registers to be saved/restored across a context loss
  523. * @threshold: Threshold register value
  524. * @control: Control register value
  525. */
  526. struct tsens_context {
  527. int threshold;
  528. int control;
  529. };
  530. /**
  531. * struct tsens_priv - private data for each instance of the tsens IP
  532. * @dev: pointer to struct device
  533. * @num_sensors: number of sensors enabled on this device
  534. * @tm_map: pointer to TM register address space
  535. * @srot_map: pointer to SROT register address space
  536. * @tm_offset: deal with old device trees that don't address TM and SROT
  537. * address space separately
  538. * @ul_lock: lock while processing upper/lower threshold interrupts
  539. * @crit_lock: lock while processing critical threshold interrupts
  540. * @rf: array of regmap_fields used to store value of the field
  541. * @ctx: registers to be saved and restored during suspend/resume
  542. * @feat: features of the IP
  543. * @fields: bitfield locations
  544. * @ops: pointer to list of callbacks supported by this device
  545. * @debug_root: pointer to debugfs dentry for all tsens
  546. * @debug: pointer to debugfs dentry for tsens controller
  547. * @sensor: list of sensors attached to this device
  548. */
  549. struct tsens_priv {
  550. struct device *dev;
  551. u32 num_sensors;
  552. struct regmap *tm_map;
  553. struct regmap *srot_map;
  554. u32 tm_offset;
  555. /* lock for upper/lower threshold interrupts */
  556. spinlock_t ul_lock;
  557. struct regmap_field *rf[MAX_REGFIELDS];
  558. struct tsens_context ctx;
  559. struct tsens_features *feat;
  560. const struct reg_field *fields;
  561. const struct tsens_ops *ops;
  562. struct dentry *debug_root;
  563. struct dentry *debug;
  564. struct tsens_sensor sensor[] __counted_by(num_sensors);
  565. };
  566. /**
  567. * struct tsens_single_value - internal representation of a single field inside nvmem calibration data
  568. * @idx: index into the u32 data array
  569. * @shift: the shift of the first bit in the value
  570. * @blob: index of the data blob to use for this cell
  571. */
  572. struct tsens_single_value {
  573. u8 idx;
  574. u8 shift;
  575. u8 blob;
  576. };
  577. /**
  578. * struct tsens_legacy_calibration_format - description of calibration data used when parsing the legacy nvmem blob
  579. * @base_len: the length of the base fields inside calibration data
  580. * @base_shift: the shift to be applied to base data
  581. * @sp_len: the length of the sN_pM fields inside calibration data
  582. * @mode: descriptor of the calibration mode field
  583. * @invalid: descriptor of the calibration mode invalid field
  584. * @base: descriptors of the base0 and base1 fields
  585. * @sp: descriptors of the sN_pM fields
  586. */
  587. struct tsens_legacy_calibration_format {
  588. unsigned int base_len;
  589. unsigned int base_shift;
  590. unsigned int sp_len;
  591. /* just two bits */
  592. struct tsens_single_value mode;
  593. /* on all platforms except 8974 invalid is the third bit of what downstream calls 'mode' */
  594. struct tsens_single_value invalid;
  595. struct tsens_single_value base[2];
  596. struct tsens_single_value sp[][2];
  597. };
  598. char *qfprom_read(struct device *dev, const char *cname);
  599. int tsens_read_calibration_legacy(struct tsens_priv *priv,
  600. const struct tsens_legacy_calibration_format *format,
  601. u32 *p1, u32 *p2,
  602. u32 *cdata, u32 *csel);
  603. int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2, bool backup);
  604. int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift);
  605. int tsens_calibrate_common(struct tsens_priv *priv);
  606. void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode);
  607. int init_common(struct tsens_priv *priv);
  608. int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp);
  609. int get_temp_common(const struct tsens_sensor *s, int *temp);
  610. #ifdef CONFIG_SUSPEND
  611. int tsens_resume_common(struct tsens_priv *priv);
  612. #else
  613. #define tsens_resume_common NULL
  614. #endif
  615. /* TSENS target */
  616. extern struct tsens_plat_data data_8960;
  617. /* TSENS v0.1 targets */
  618. extern struct tsens_plat_data data_8226, data_8909, data_8916, data_8939, data_8974, data_9607;
  619. /* TSENS v1 targets */
  620. extern struct tsens_plat_data data_tsens_v1, data_8937, data_8976, data_8956;
  621. /* TSENS v1 with no RPM targets */
  622. extern const struct tsens_plat_data data_ipq5018;
  623. /* TSENS v2 targets */
  624. extern struct tsens_plat_data data_8996, data_ipq8074, data_tsens_v2;
  625. extern const struct tsens_plat_data data_ipq5332, data_ipq5424;
  626. #endif /* __QCOM_TSENS_H__ */