hisi_thermal.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * Hisilicon thermal sensor driver
  3. *
  4. * Copyright (c) 2014-2015 Hisilicon Limited.
  5. * Copyright (c) 2014-2015 Linaro Limited.
  6. *
  7. * Xinwei Kong <kong.kongxinwei@hisilicon.com>
  8. * Leo Yan <leo.yan@linaro.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  15. * kind, whether express or implied; without even the implied warranty
  16. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #include <linux/cpufreq.h>
  20. #include <linux/delay.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/module.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/io.h>
  25. #include <linux/of_device.h>
  26. #include "thermal_core.h"
  27. #define HI6220_TEMP0_LAG (0x0)
  28. #define HI6220_TEMP0_TH (0x4)
  29. #define HI6220_TEMP0_RST_TH (0x8)
  30. #define HI6220_TEMP0_CFG (0xC)
  31. #define HI6220_TEMP0_CFG_SS_MSK (0xF000)
  32. #define HI6220_TEMP0_CFG_HDAK_MSK (0x30)
  33. #define HI6220_TEMP0_EN (0x10)
  34. #define HI6220_TEMP0_INT_EN (0x14)
  35. #define HI6220_TEMP0_INT_CLR (0x18)
  36. #define HI6220_TEMP0_RST_MSK (0x1C)
  37. #define HI6220_TEMP0_VALUE (0x28)
  38. #define HI3660_OFFSET(chan) ((chan) * 0x40)
  39. #define HI3660_TEMP(chan) (HI3660_OFFSET(chan) + 0x1C)
  40. #define HI3660_TH(chan) (HI3660_OFFSET(chan) + 0x20)
  41. #define HI3660_LAG(chan) (HI3660_OFFSET(chan) + 0x28)
  42. #define HI3660_INT_EN(chan) (HI3660_OFFSET(chan) + 0x2C)
  43. #define HI3660_INT_CLR(chan) (HI3660_OFFSET(chan) + 0x30)
  44. #define HI6220_TEMP_BASE (-60000)
  45. #define HI6220_TEMP_RESET (100000)
  46. #define HI6220_TEMP_STEP (785)
  47. #define HI6220_TEMP_LAG (3500)
  48. #define HI3660_TEMP_BASE (-63780)
  49. #define HI3660_TEMP_STEP (205)
  50. #define HI3660_TEMP_LAG (4000)
  51. #define HI6220_CLUSTER0_SENSOR 2
  52. #define HI6220_CLUSTER1_SENSOR 1
  53. #define HI3660_LITTLE_SENSOR 0
  54. #define HI3660_BIG_SENSOR 1
  55. #define HI3660_G3D_SENSOR 2
  56. #define HI3660_MODEM_SENSOR 3
  57. struct hisi_thermal_data;
  58. struct hisi_thermal_sensor {
  59. struct hisi_thermal_data *data;
  60. struct thermal_zone_device *tzd;
  61. const char *irq_name;
  62. uint32_t id;
  63. uint32_t thres_temp;
  64. };
  65. struct hisi_thermal_ops {
  66. int (*get_temp)(struct hisi_thermal_sensor *sensor);
  67. int (*enable_sensor)(struct hisi_thermal_sensor *sensor);
  68. int (*disable_sensor)(struct hisi_thermal_sensor *sensor);
  69. int (*irq_handler)(struct hisi_thermal_sensor *sensor);
  70. int (*probe)(struct hisi_thermal_data *data);
  71. };
  72. struct hisi_thermal_data {
  73. const struct hisi_thermal_ops *ops;
  74. struct hisi_thermal_sensor *sensor;
  75. struct platform_device *pdev;
  76. struct clk *clk;
  77. void __iomem *regs;
  78. int nr_sensors;
  79. };
  80. /*
  81. * The temperature computation on the tsensor is as follow:
  82. * Unit: millidegree Celsius
  83. * Step: 200/255 (0.7843)
  84. * Temperature base: -60°C
  85. *
  86. * The register is programmed in temperature steps, every step is 785
  87. * millidegree and begins at -60 000 m°C
  88. *
  89. * The temperature from the steps:
  90. *
  91. * Temp = TempBase + (steps x 785)
  92. *
  93. * and the steps from the temperature:
  94. *
  95. * steps = (Temp - TempBase) / 785
  96. *
  97. */
  98. static inline int hi6220_thermal_step_to_temp(int step)
  99. {
  100. return HI6220_TEMP_BASE + (step * HI6220_TEMP_STEP);
  101. }
  102. static inline int hi6220_thermal_temp_to_step(int temp)
  103. {
  104. return DIV_ROUND_UP(temp - HI6220_TEMP_BASE, HI6220_TEMP_STEP);
  105. }
  106. /*
  107. * for Hi3660,
  108. * Step: 189/922 (0.205)
  109. * Temperature base: -63.780°C
  110. *
  111. * The register is programmed in temperature steps, every step is 205
  112. * millidegree and begins at -63 780 m°C
  113. */
  114. static inline int hi3660_thermal_step_to_temp(int step)
  115. {
  116. return HI3660_TEMP_BASE + step * HI3660_TEMP_STEP;
  117. }
  118. static inline int hi3660_thermal_temp_to_step(int temp)
  119. {
  120. return DIV_ROUND_UP(temp - HI3660_TEMP_BASE, HI3660_TEMP_STEP);
  121. }
  122. /*
  123. * The lag register contains 5 bits encoding the temperature in steps.
  124. *
  125. * Each time the temperature crosses the threshold boundary, an
  126. * interrupt is raised. It could be when the temperature is going
  127. * above the threshold or below. However, if the temperature is
  128. * fluctuating around this value due to the load, we can receive
  129. * several interrupts which may not desired.
  130. *
  131. * We can setup a temperature representing the delta between the
  132. * threshold and the current temperature when the temperature is
  133. * decreasing.
  134. *
  135. * For instance: the lag register is 5°C, the threshold is 65°C, when
  136. * the temperature reaches 65°C an interrupt is raised and when the
  137. * temperature decrease to 65°C - 5°C another interrupt is raised.
  138. *
  139. * A very short lag can lead to an interrupt storm, a long lag
  140. * increase the latency to react to the temperature changes. In our
  141. * case, that is not really a problem as we are polling the
  142. * temperature.
  143. *
  144. * [0:4] : lag register
  145. *
  146. * The temperature is coded in steps, cf. HI6220_TEMP_STEP.
  147. *
  148. * Min : 0x00 : 0.0 °C
  149. * Max : 0x1F : 24.3 °C
  150. *
  151. * The 'value' parameter is in milliCelsius.
  152. */
  153. static inline void hi6220_thermal_set_lag(void __iomem *addr, int value)
  154. {
  155. writel(DIV_ROUND_UP(value, HI6220_TEMP_STEP) & 0x1F,
  156. addr + HI6220_TEMP0_LAG);
  157. }
  158. static inline void hi6220_thermal_alarm_clear(void __iomem *addr, int value)
  159. {
  160. writel(value, addr + HI6220_TEMP0_INT_CLR);
  161. }
  162. static inline void hi6220_thermal_alarm_enable(void __iomem *addr, int value)
  163. {
  164. writel(value, addr + HI6220_TEMP0_INT_EN);
  165. }
  166. static inline void hi6220_thermal_alarm_set(void __iomem *addr, int temp)
  167. {
  168. writel(hi6220_thermal_temp_to_step(temp) | 0x0FFFFFF00,
  169. addr + HI6220_TEMP0_TH);
  170. }
  171. static inline void hi6220_thermal_reset_set(void __iomem *addr, int temp)
  172. {
  173. writel(hi6220_thermal_temp_to_step(temp), addr + HI6220_TEMP0_RST_TH);
  174. }
  175. static inline void hi6220_thermal_reset_enable(void __iomem *addr, int value)
  176. {
  177. writel(value, addr + HI6220_TEMP0_RST_MSK);
  178. }
  179. static inline void hi6220_thermal_enable(void __iomem *addr, int value)
  180. {
  181. writel(value, addr + HI6220_TEMP0_EN);
  182. }
  183. static inline int hi6220_thermal_get_temperature(void __iomem *addr)
  184. {
  185. return hi6220_thermal_step_to_temp(readl(addr + HI6220_TEMP0_VALUE));
  186. }
  187. /*
  188. * [0:6] lag register
  189. *
  190. * The temperature is coded in steps, cf. HI3660_TEMP_STEP.
  191. *
  192. * Min : 0x00 : 0.0 °C
  193. * Max : 0x7F : 26.0 °C
  194. *
  195. */
  196. static inline void hi3660_thermal_set_lag(void __iomem *addr,
  197. int id, int value)
  198. {
  199. writel(DIV_ROUND_UP(value, HI3660_TEMP_STEP) & 0x7F,
  200. addr + HI3660_LAG(id));
  201. }
  202. static inline void hi3660_thermal_alarm_clear(void __iomem *addr,
  203. int id, int value)
  204. {
  205. writel(value, addr + HI3660_INT_CLR(id));
  206. }
  207. static inline void hi3660_thermal_alarm_enable(void __iomem *addr,
  208. int id, int value)
  209. {
  210. writel(value, addr + HI3660_INT_EN(id));
  211. }
  212. static inline void hi3660_thermal_alarm_set(void __iomem *addr,
  213. int id, int value)
  214. {
  215. writel(value, addr + HI3660_TH(id));
  216. }
  217. static inline int hi3660_thermal_get_temperature(void __iomem *addr, int id)
  218. {
  219. return hi3660_thermal_step_to_temp(readl(addr + HI3660_TEMP(id)));
  220. }
  221. /*
  222. * Temperature configuration register - Sensor selection
  223. *
  224. * Bits [19:12]
  225. *
  226. * 0x0: local sensor (default)
  227. * 0x1: remote sensor 1 (ACPU cluster 1)
  228. * 0x2: remote sensor 2 (ACPU cluster 0)
  229. * 0x3: remote sensor 3 (G3D)
  230. */
  231. static inline void hi6220_thermal_sensor_select(void __iomem *addr, int sensor)
  232. {
  233. writel((readl(addr + HI6220_TEMP0_CFG) & ~HI6220_TEMP0_CFG_SS_MSK) |
  234. (sensor << 12), addr + HI6220_TEMP0_CFG);
  235. }
  236. /*
  237. * Temperature configuration register - Hdak conversion polling interval
  238. *
  239. * Bits [5:4]
  240. *
  241. * 0x0 : 0.768 ms
  242. * 0x1 : 6.144 ms
  243. * 0x2 : 49.152 ms
  244. * 0x3 : 393.216 ms
  245. */
  246. static inline void hi6220_thermal_hdak_set(void __iomem *addr, int value)
  247. {
  248. writel((readl(addr + HI6220_TEMP0_CFG) & ~HI6220_TEMP0_CFG_HDAK_MSK) |
  249. (value << 4), addr + HI6220_TEMP0_CFG);
  250. }
  251. static int hi6220_thermal_irq_handler(struct hisi_thermal_sensor *sensor)
  252. {
  253. struct hisi_thermal_data *data = sensor->data;
  254. hi6220_thermal_alarm_clear(data->regs, 1);
  255. return 0;
  256. }
  257. static int hi3660_thermal_irq_handler(struct hisi_thermal_sensor *sensor)
  258. {
  259. struct hisi_thermal_data *data = sensor->data;
  260. hi3660_thermal_alarm_clear(data->regs, sensor->id, 1);
  261. return 0;
  262. }
  263. static int hi6220_thermal_get_temp(struct hisi_thermal_sensor *sensor)
  264. {
  265. struct hisi_thermal_data *data = sensor->data;
  266. return hi6220_thermal_get_temperature(data->regs);
  267. }
  268. static int hi3660_thermal_get_temp(struct hisi_thermal_sensor *sensor)
  269. {
  270. struct hisi_thermal_data *data = sensor->data;
  271. return hi3660_thermal_get_temperature(data->regs, sensor->id);
  272. }
  273. static int hi6220_thermal_disable_sensor(struct hisi_thermal_sensor *sensor)
  274. {
  275. struct hisi_thermal_data *data = sensor->data;
  276. /* disable sensor module */
  277. hi6220_thermal_enable(data->regs, 0);
  278. hi6220_thermal_alarm_enable(data->regs, 0);
  279. hi6220_thermal_reset_enable(data->regs, 0);
  280. clk_disable_unprepare(data->clk);
  281. return 0;
  282. }
  283. static int hi3660_thermal_disable_sensor(struct hisi_thermal_sensor *sensor)
  284. {
  285. struct hisi_thermal_data *data = sensor->data;
  286. /* disable sensor module */
  287. hi3660_thermal_alarm_enable(data->regs, sensor->id, 0);
  288. return 0;
  289. }
  290. static int hi6220_thermal_enable_sensor(struct hisi_thermal_sensor *sensor)
  291. {
  292. struct hisi_thermal_data *data = sensor->data;
  293. int ret;
  294. /* enable clock for tsensor */
  295. ret = clk_prepare_enable(data->clk);
  296. if (ret)
  297. return ret;
  298. /* disable module firstly */
  299. hi6220_thermal_reset_enable(data->regs, 0);
  300. hi6220_thermal_enable(data->regs, 0);
  301. /* select sensor id */
  302. hi6220_thermal_sensor_select(data->regs, sensor->id);
  303. /* setting the hdak time */
  304. hi6220_thermal_hdak_set(data->regs, 0);
  305. /* setting lag value between current temp and the threshold */
  306. hi6220_thermal_set_lag(data->regs, HI6220_TEMP_LAG);
  307. /* enable for interrupt */
  308. hi6220_thermal_alarm_set(data->regs, sensor->thres_temp);
  309. hi6220_thermal_reset_set(data->regs, HI6220_TEMP_RESET);
  310. /* enable module */
  311. hi6220_thermal_reset_enable(data->regs, 1);
  312. hi6220_thermal_enable(data->regs, 1);
  313. hi6220_thermal_alarm_clear(data->regs, 0);
  314. hi6220_thermal_alarm_enable(data->regs, 1);
  315. return 0;
  316. }
  317. static int hi3660_thermal_enable_sensor(struct hisi_thermal_sensor *sensor)
  318. {
  319. unsigned int value;
  320. struct hisi_thermal_data *data = sensor->data;
  321. /* disable interrupt */
  322. hi3660_thermal_alarm_enable(data->regs, sensor->id, 0);
  323. /* setting lag value between current temp and the threshold */
  324. hi3660_thermal_set_lag(data->regs, sensor->id, HI3660_TEMP_LAG);
  325. /* set interrupt threshold */
  326. value = hi3660_thermal_temp_to_step(sensor->thres_temp);
  327. hi3660_thermal_alarm_set(data->regs, sensor->id, value);
  328. /* enable interrupt */
  329. hi3660_thermal_alarm_clear(data->regs, sensor->id, 1);
  330. hi3660_thermal_alarm_enable(data->regs, sensor->id, 1);
  331. return 0;
  332. }
  333. static int hi6220_thermal_probe(struct hisi_thermal_data *data)
  334. {
  335. struct platform_device *pdev = data->pdev;
  336. struct device *dev = &pdev->dev;
  337. int ret;
  338. data->clk = devm_clk_get(dev, "thermal_clk");
  339. if (IS_ERR(data->clk)) {
  340. ret = PTR_ERR(data->clk);
  341. if (ret != -EPROBE_DEFER)
  342. dev_err(dev, "failed to get thermal clk: %d\n", ret);
  343. return ret;
  344. }
  345. data->sensor = devm_kzalloc(dev, sizeof(*data->sensor), GFP_KERNEL);
  346. if (!data->sensor)
  347. return -ENOMEM;
  348. data->sensor[0].id = HI6220_CLUSTER0_SENSOR;
  349. data->sensor[0].irq_name = "tsensor_intr";
  350. data->sensor[0].data = data;
  351. data->nr_sensors = 1;
  352. return 0;
  353. }
  354. static int hi3660_thermal_probe(struct hisi_thermal_data *data)
  355. {
  356. struct platform_device *pdev = data->pdev;
  357. struct device *dev = &pdev->dev;
  358. data->nr_sensors = 1;
  359. data->sensor = devm_kzalloc(dev, sizeof(*data->sensor) *
  360. data->nr_sensors, GFP_KERNEL);
  361. if (!data->sensor)
  362. return -ENOMEM;
  363. data->sensor[0].id = HI3660_BIG_SENSOR;
  364. data->sensor[0].irq_name = "tsensor_a73";
  365. data->sensor[0].data = data;
  366. data->sensor[1].id = HI3660_LITTLE_SENSOR;
  367. data->sensor[1].irq_name = "tsensor_a53";
  368. data->sensor[1].data = data;
  369. return 0;
  370. }
  371. static int hisi_thermal_get_temp(void *__data, int *temp)
  372. {
  373. struct hisi_thermal_sensor *sensor = __data;
  374. struct hisi_thermal_data *data = sensor->data;
  375. *temp = data->ops->get_temp(sensor);
  376. dev_dbg(&data->pdev->dev, "tzd=%p, id=%d, temp=%d, thres=%d\n",
  377. sensor->tzd, sensor->id, *temp, sensor->thres_temp);
  378. return 0;
  379. }
  380. static const struct thermal_zone_of_device_ops hisi_of_thermal_ops = {
  381. .get_temp = hisi_thermal_get_temp,
  382. };
  383. static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev)
  384. {
  385. struct hisi_thermal_sensor *sensor = dev;
  386. struct hisi_thermal_data *data = sensor->data;
  387. int temp = 0;
  388. data->ops->irq_handler(sensor);
  389. hisi_thermal_get_temp(sensor, &temp);
  390. if (temp >= sensor->thres_temp) {
  391. dev_crit(&data->pdev->dev,
  392. "sensor <%d> THERMAL ALARM: %d > %d\n",
  393. sensor->id, temp, sensor->thres_temp);
  394. thermal_zone_device_update(sensor->tzd,
  395. THERMAL_EVENT_UNSPECIFIED);
  396. } else {
  397. dev_crit(&data->pdev->dev,
  398. "sensor <%d> THERMAL ALARM stopped: %d < %d\n",
  399. sensor->id, temp, sensor->thres_temp);
  400. }
  401. return IRQ_HANDLED;
  402. }
  403. static int hisi_thermal_register_sensor(struct platform_device *pdev,
  404. struct hisi_thermal_sensor *sensor)
  405. {
  406. int ret, i;
  407. const struct thermal_trip *trip;
  408. sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev,
  409. sensor->id, sensor,
  410. &hisi_of_thermal_ops);
  411. if (IS_ERR(sensor->tzd)) {
  412. ret = PTR_ERR(sensor->tzd);
  413. sensor->tzd = NULL;
  414. dev_err(&pdev->dev, "failed to register sensor id %d: %d\n",
  415. sensor->id, ret);
  416. return ret;
  417. }
  418. trip = of_thermal_get_trip_points(sensor->tzd);
  419. for (i = 0; i < of_thermal_get_ntrips(sensor->tzd); i++) {
  420. if (trip[i].type == THERMAL_TRIP_PASSIVE) {
  421. sensor->thres_temp = trip[i].temperature;
  422. break;
  423. }
  424. }
  425. return 0;
  426. }
  427. static const struct hisi_thermal_ops hi6220_ops = {
  428. .get_temp = hi6220_thermal_get_temp,
  429. .enable_sensor = hi6220_thermal_enable_sensor,
  430. .disable_sensor = hi6220_thermal_disable_sensor,
  431. .irq_handler = hi6220_thermal_irq_handler,
  432. .probe = hi6220_thermal_probe,
  433. };
  434. static const struct hisi_thermal_ops hi3660_ops = {
  435. .get_temp = hi3660_thermal_get_temp,
  436. .enable_sensor = hi3660_thermal_enable_sensor,
  437. .disable_sensor = hi3660_thermal_disable_sensor,
  438. .irq_handler = hi3660_thermal_irq_handler,
  439. .probe = hi3660_thermal_probe,
  440. };
  441. static const struct of_device_id of_hisi_thermal_match[] = {
  442. {
  443. .compatible = "hisilicon,tsensor",
  444. .data = &hi6220_ops,
  445. },
  446. {
  447. .compatible = "hisilicon,hi3660-tsensor",
  448. .data = &hi3660_ops,
  449. },
  450. { /* end */ }
  451. };
  452. MODULE_DEVICE_TABLE(of, of_hisi_thermal_match);
  453. static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor,
  454. bool on)
  455. {
  456. struct thermal_zone_device *tzd = sensor->tzd;
  457. tzd->ops->set_mode(tzd,
  458. on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED);
  459. }
  460. static int hisi_thermal_probe(struct platform_device *pdev)
  461. {
  462. struct hisi_thermal_data *data;
  463. struct device *dev = &pdev->dev;
  464. struct resource *res;
  465. int i, ret;
  466. data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
  467. if (!data)
  468. return -ENOMEM;
  469. data->pdev = pdev;
  470. platform_set_drvdata(pdev, data);
  471. data->ops = of_device_get_match_data(dev);
  472. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  473. data->regs = devm_ioremap_resource(dev, res);
  474. if (IS_ERR(data->regs)) {
  475. dev_err(dev, "failed to get io address\n");
  476. return PTR_ERR(data->regs);
  477. }
  478. ret = data->ops->probe(data);
  479. if (ret)
  480. return ret;
  481. for (i = 0; i < data->nr_sensors; i++) {
  482. struct hisi_thermal_sensor *sensor = &data->sensor[i];
  483. ret = hisi_thermal_register_sensor(pdev, sensor);
  484. if (ret) {
  485. dev_err(dev, "failed to register thermal sensor: %d\n",
  486. ret);
  487. return ret;
  488. }
  489. ret = platform_get_irq(pdev, 0);
  490. if (ret < 0)
  491. return ret;
  492. ret = devm_request_threaded_irq(dev, ret, NULL,
  493. hisi_thermal_alarm_irq_thread,
  494. IRQF_ONESHOT, sensor->irq_name,
  495. sensor);
  496. if (ret < 0) {
  497. dev_err(dev, "Failed to request alarm irq: %d\n", ret);
  498. return ret;
  499. }
  500. ret = data->ops->enable_sensor(sensor);
  501. if (ret) {
  502. dev_err(dev, "Failed to setup the sensor: %d\n", ret);
  503. return ret;
  504. }
  505. hisi_thermal_toggle_sensor(sensor, true);
  506. }
  507. return 0;
  508. }
  509. static int hisi_thermal_remove(struct platform_device *pdev)
  510. {
  511. struct hisi_thermal_data *data = platform_get_drvdata(pdev);
  512. int i;
  513. for (i = 0; i < data->nr_sensors; i++) {
  514. struct hisi_thermal_sensor *sensor = &data->sensor[i];
  515. hisi_thermal_toggle_sensor(sensor, false);
  516. data->ops->disable_sensor(sensor);
  517. }
  518. return 0;
  519. }
  520. #ifdef CONFIG_PM_SLEEP
  521. static int hisi_thermal_suspend(struct device *dev)
  522. {
  523. struct hisi_thermal_data *data = dev_get_drvdata(dev);
  524. int i;
  525. for (i = 0; i < data->nr_sensors; i++)
  526. data->ops->disable_sensor(&data->sensor[i]);
  527. return 0;
  528. }
  529. static int hisi_thermal_resume(struct device *dev)
  530. {
  531. struct hisi_thermal_data *data = dev_get_drvdata(dev);
  532. int i, ret = 0;
  533. for (i = 0; i < data->nr_sensors; i++)
  534. ret |= data->ops->enable_sensor(&data->sensor[i]);
  535. return ret;
  536. }
  537. #endif
  538. static SIMPLE_DEV_PM_OPS(hisi_thermal_pm_ops,
  539. hisi_thermal_suspend, hisi_thermal_resume);
  540. static struct platform_driver hisi_thermal_driver = {
  541. .driver = {
  542. .name = "hisi_thermal",
  543. .pm = &hisi_thermal_pm_ops,
  544. .of_match_table = of_hisi_thermal_match,
  545. },
  546. .probe = hisi_thermal_probe,
  547. .remove = hisi_thermal_remove,
  548. };
  549. module_platform_driver(hisi_thermal_driver);
  550. MODULE_AUTHOR("Xinwei Kong <kong.kongxinwei@hisilicon.com>");
  551. MODULE_AUTHOR("Leo Yan <leo.yan@linaro.org>");
  552. MODULE_DESCRIPTION("Hisilicon thermal driver");
  553. MODULE_LICENSE("GPL v2");