exynos_tmu.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. * exynos_tmu.c - Samsung EXYNOS TMU (Thermal Management Unit)
  3. *
  4. * Copyright (C) 2011 Samsung Electronics
  5. * Donggeun Kim <dg77.kim@samsung.com>
  6. * Amit Daniel Kachhap <amit.kachhap@linaro.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <linux/clk.h>
  24. #include <linux/io.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/module.h>
  27. #include <linux/of.h>
  28. #include <linux/of_address.h>
  29. #include <linux/of_irq.h>
  30. #include <linux/platform_device.h>
  31. #include "exynos_thermal_common.h"
  32. #include "exynos_tmu.h"
  33. #include "exynos_tmu_data.h"
  34. /**
  35. * struct exynos_tmu_data : A structure to hold the private data of the TMU
  36. driver
  37. * @id: identifier of the one instance of the TMU controller.
  38. * @pdata: pointer to the tmu platform/configuration data
  39. * @base: base address of the single instance of the TMU controller.
  40. * @base_common: base address of the common registers of the TMU controller.
  41. * @irq: irq number of the TMU controller.
  42. * @soc: id of the SOC type.
  43. * @irq_work: pointer to the irq work structure.
  44. * @lock: lock to implement synchronization.
  45. * @clk: pointer to the clock structure.
  46. * @temp_error1: fused value of the first point trim.
  47. * @temp_error2: fused value of the second point trim.
  48. * @reg_conf: pointer to structure to register with core thermal.
  49. */
  50. struct exynos_tmu_data {
  51. int id;
  52. struct exynos_tmu_platform_data *pdata;
  53. void __iomem *base;
  54. void __iomem *base_common;
  55. int irq;
  56. enum soc_type soc;
  57. struct work_struct irq_work;
  58. struct mutex lock;
  59. struct clk *clk;
  60. u8 temp_error1, temp_error2;
  61. struct thermal_sensor_conf *reg_conf;
  62. };
  63. /*
  64. * TMU treats temperature as a mapped temperature code.
  65. * The temperature is converted differently depending on the calibration type.
  66. */
  67. static int temp_to_code(struct exynos_tmu_data *data, u8 temp)
  68. {
  69. struct exynos_tmu_platform_data *pdata = data->pdata;
  70. int temp_code;
  71. if (data->soc == SOC_ARCH_EXYNOS4210)
  72. /* temp should range between 25 and 125 */
  73. if (temp < 25 || temp > 125) {
  74. temp_code = -EINVAL;
  75. goto out;
  76. }
  77. switch (pdata->cal_type) {
  78. case TYPE_TWO_POINT_TRIMMING:
  79. temp_code = (temp - pdata->first_point_trim) *
  80. (data->temp_error2 - data->temp_error1) /
  81. (pdata->second_point_trim - pdata->first_point_trim) +
  82. data->temp_error1;
  83. break;
  84. case TYPE_ONE_POINT_TRIMMING:
  85. temp_code = temp + data->temp_error1 - pdata->first_point_trim;
  86. break;
  87. default:
  88. temp_code = temp + pdata->default_temp_offset;
  89. break;
  90. }
  91. out:
  92. return temp_code;
  93. }
  94. /*
  95. * Calculate a temperature value from a temperature code.
  96. * The unit of the temperature is degree Celsius.
  97. */
  98. static int code_to_temp(struct exynos_tmu_data *data, u8 temp_code)
  99. {
  100. struct exynos_tmu_platform_data *pdata = data->pdata;
  101. int temp;
  102. if (data->soc == SOC_ARCH_EXYNOS4210)
  103. /* temp_code should range between 75 and 175 */
  104. if (temp_code < 75 || temp_code > 175) {
  105. temp = -ENODATA;
  106. goto out;
  107. }
  108. switch (pdata->cal_type) {
  109. case TYPE_TWO_POINT_TRIMMING:
  110. temp = (temp_code - data->temp_error1) *
  111. (pdata->second_point_trim - pdata->first_point_trim) /
  112. (data->temp_error2 - data->temp_error1) +
  113. pdata->first_point_trim;
  114. break;
  115. case TYPE_ONE_POINT_TRIMMING:
  116. temp = temp_code - data->temp_error1 + pdata->first_point_trim;
  117. break;
  118. default:
  119. temp = temp_code - pdata->default_temp_offset;
  120. break;
  121. }
  122. out:
  123. return temp;
  124. }
  125. static int exynos_tmu_initialize(struct platform_device *pdev)
  126. {
  127. struct exynos_tmu_data *data = platform_get_drvdata(pdev);
  128. struct exynos_tmu_platform_data *pdata = data->pdata;
  129. const struct exynos_tmu_registers *reg = pdata->registers;
  130. unsigned int status, trim_info = 0, con;
  131. unsigned int rising_threshold = 0, falling_threshold = 0;
  132. int ret = 0, threshold_code, i, trigger_levs = 0;
  133. mutex_lock(&data->lock);
  134. clk_enable(data->clk);
  135. if (TMU_SUPPORTS(pdata, READY_STATUS)) {
  136. status = readb(data->base + reg->tmu_status);
  137. if (!status) {
  138. ret = -EBUSY;
  139. goto out;
  140. }
  141. }
  142. if (TMU_SUPPORTS(pdata, TRIM_RELOAD))
  143. __raw_writel(1, data->base + reg->triminfo_ctrl);
  144. /* Save trimming info in order to perform calibration */
  145. trim_info = readl(data->base + reg->triminfo_data);
  146. data->temp_error1 = trim_info & EXYNOS_TMU_TEMP_MASK;
  147. data->temp_error2 = ((trim_info >> reg->triminfo_85_shift) &
  148. EXYNOS_TMU_TEMP_MASK);
  149. if ((pdata->min_efuse_value > data->temp_error1) ||
  150. (data->temp_error1 > pdata->max_efuse_value) ||
  151. (data->temp_error2 != 0))
  152. data->temp_error1 = pdata->efuse_value;
  153. if (pdata->max_trigger_level > MAX_THRESHOLD_LEVS) {
  154. dev_err(&pdev->dev, "Invalid max trigger level\n");
  155. goto out;
  156. }
  157. for (i = 0; i < pdata->max_trigger_level; i++) {
  158. if (!pdata->trigger_levels[i])
  159. continue;
  160. if ((pdata->trigger_type[i] == HW_TRIP) &&
  161. (!pdata->trigger_levels[pdata->max_trigger_level - 1])) {
  162. dev_err(&pdev->dev, "Invalid hw trigger level\n");
  163. ret = -EINVAL;
  164. goto out;
  165. }
  166. /* Count trigger levels except the HW trip*/
  167. if (!(pdata->trigger_type[i] == HW_TRIP))
  168. trigger_levs++;
  169. }
  170. if (data->soc == SOC_ARCH_EXYNOS4210) {
  171. /* Write temperature code for threshold */
  172. threshold_code = temp_to_code(data, pdata->threshold);
  173. if (threshold_code < 0) {
  174. ret = threshold_code;
  175. goto out;
  176. }
  177. writeb(threshold_code,
  178. data->base + reg->threshold_temp);
  179. for (i = 0; i < trigger_levs; i++)
  180. writeb(pdata->trigger_levels[i], data->base +
  181. reg->threshold_th0 + i * sizeof(reg->threshold_th0));
  182. writel(reg->inten_rise_mask, data->base + reg->tmu_intclear);
  183. } else if (data->soc == SOC_ARCH_EXYNOS) {
  184. /* Write temperature code for rising and falling threshold */
  185. for (i = 0;
  186. i < trigger_levs && i < EXYNOS_MAX_TRIGGER_PER_REG; i++) {
  187. threshold_code = temp_to_code(data,
  188. pdata->trigger_levels[i]);
  189. if (threshold_code < 0) {
  190. ret = threshold_code;
  191. goto out;
  192. }
  193. rising_threshold |= threshold_code << 8 * i;
  194. if (pdata->threshold_falling) {
  195. threshold_code = temp_to_code(data,
  196. pdata->trigger_levels[i] -
  197. pdata->threshold_falling);
  198. if (threshold_code > 0)
  199. falling_threshold |=
  200. threshold_code << 8 * i;
  201. }
  202. }
  203. writel(rising_threshold,
  204. data->base + reg->threshold_th0);
  205. writel(falling_threshold,
  206. data->base + reg->threshold_th1);
  207. writel((reg->inten_rise_mask << reg->inten_rise_shift) |
  208. (reg->inten_fall_mask << reg->inten_fall_shift),
  209. data->base + reg->tmu_intclear);
  210. /* if last threshold limit is also present */
  211. i = pdata->max_trigger_level - 1;
  212. if (pdata->trigger_levels[i] &&
  213. (pdata->trigger_type[i] == HW_TRIP)) {
  214. threshold_code = temp_to_code(data,
  215. pdata->trigger_levels[i]);
  216. if (threshold_code < 0) {
  217. ret = threshold_code;
  218. goto out;
  219. }
  220. rising_threshold |= threshold_code << 8 * i;
  221. writel(rising_threshold,
  222. data->base + reg->threshold_th0);
  223. con = readl(data->base + reg->tmu_ctrl);
  224. con |= (1 << reg->therm_trip_en_shift);
  225. writel(con, data->base + reg->tmu_ctrl);
  226. }
  227. }
  228. out:
  229. clk_disable(data->clk);
  230. mutex_unlock(&data->lock);
  231. return ret;
  232. }
  233. static void exynos_tmu_control(struct platform_device *pdev, bool on)
  234. {
  235. struct exynos_tmu_data *data = platform_get_drvdata(pdev);
  236. struct exynos_tmu_platform_data *pdata = data->pdata;
  237. const struct exynos_tmu_registers *reg = pdata->registers;
  238. unsigned int con, interrupt_en;
  239. mutex_lock(&data->lock);
  240. clk_enable(data->clk);
  241. con = readl(data->base + reg->tmu_ctrl);
  242. if (pdata->reference_voltage) {
  243. con &= ~(reg->buf_vref_sel_mask << reg->buf_vref_sel_shift);
  244. con |= pdata->reference_voltage << reg->buf_vref_sel_shift;
  245. }
  246. if (pdata->gain) {
  247. con &= ~(reg->buf_slope_sel_mask << reg->buf_slope_sel_shift);
  248. con |= (pdata->gain << reg->buf_slope_sel_shift);
  249. }
  250. if (pdata->noise_cancel_mode) {
  251. con &= ~(reg->therm_trip_mode_mask <<
  252. reg->therm_trip_mode_shift);
  253. con |= (pdata->noise_cancel_mode << reg->therm_trip_mode_shift);
  254. }
  255. if (on) {
  256. con |= (1 << reg->core_en_shift);
  257. interrupt_en =
  258. pdata->trigger_enable[3] << reg->inten_rise3_shift |
  259. pdata->trigger_enable[2] << reg->inten_rise2_shift |
  260. pdata->trigger_enable[1] << reg->inten_rise1_shift |
  261. pdata->trigger_enable[0] << reg->inten_rise0_shift;
  262. if (TMU_SUPPORTS(pdata, FALLING_TRIP))
  263. interrupt_en |=
  264. interrupt_en << reg->inten_fall0_shift;
  265. } else {
  266. con &= ~(1 << reg->core_en_shift);
  267. interrupt_en = 0; /* Disable all interrupts */
  268. }
  269. writel(interrupt_en, data->base + reg->tmu_inten);
  270. writel(con, data->base + reg->tmu_ctrl);
  271. clk_disable(data->clk);
  272. mutex_unlock(&data->lock);
  273. }
  274. static int exynos_tmu_read(struct exynos_tmu_data *data)
  275. {
  276. struct exynos_tmu_platform_data *pdata = data->pdata;
  277. const struct exynos_tmu_registers *reg = pdata->registers;
  278. u8 temp_code;
  279. int temp;
  280. mutex_lock(&data->lock);
  281. clk_enable(data->clk);
  282. temp_code = readb(data->base + reg->tmu_cur_temp);
  283. temp = code_to_temp(data, temp_code);
  284. clk_disable(data->clk);
  285. mutex_unlock(&data->lock);
  286. return temp;
  287. }
  288. #ifdef CONFIG_THERMAL_EMULATION
  289. static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp)
  290. {
  291. struct exynos_tmu_data *data = drv_data;
  292. struct exynos_tmu_platform_data *pdata = data->pdata;
  293. const struct exynos_tmu_registers *reg = pdata->registers;
  294. unsigned int val;
  295. int ret = -EINVAL;
  296. if (!TMU_SUPPORTS(pdata, EMULATION))
  297. goto out;
  298. if (temp && temp < MCELSIUS)
  299. goto out;
  300. mutex_lock(&data->lock);
  301. clk_enable(data->clk);
  302. val = readl(data->base + reg->emul_con);
  303. if (temp) {
  304. temp /= MCELSIUS;
  305. if (TMU_SUPPORTS(pdata, EMUL_TIME)) {
  306. val &= ~(EXYNOS_EMUL_TIME_MASK << reg->emul_time_shift);
  307. val |= (EXYNOS_EMUL_TIME << reg->emul_time_shift);
  308. }
  309. val &= ~(EXYNOS_EMUL_DATA_MASK << reg->emul_temp_shift);
  310. val |= (temp_to_code(data, temp) << reg->emul_temp_shift) |
  311. EXYNOS_EMUL_ENABLE;
  312. } else {
  313. val &= ~EXYNOS_EMUL_ENABLE;
  314. }
  315. writel(val, data->base + reg->emul_con);
  316. clk_disable(data->clk);
  317. mutex_unlock(&data->lock);
  318. return 0;
  319. out:
  320. return ret;
  321. }
  322. #else
  323. static int exynos_tmu_set_emulation(void *drv_data, unsigned long temp)
  324. { return -EINVAL; }
  325. #endif/*CONFIG_THERMAL_EMULATION*/
  326. static void exynos_tmu_work(struct work_struct *work)
  327. {
  328. struct exynos_tmu_data *data = container_of(work,
  329. struct exynos_tmu_data, irq_work);
  330. struct exynos_tmu_platform_data *pdata = data->pdata;
  331. const struct exynos_tmu_registers *reg = pdata->registers;
  332. unsigned int val_irq;
  333. exynos_report_trigger(data->reg_conf);
  334. mutex_lock(&data->lock);
  335. clk_enable(data->clk);
  336. /* TODO: take action based on particular interrupt */
  337. val_irq = readl(data->base + reg->tmu_intstat);
  338. /* clear the interrupts */
  339. writel(val_irq, data->base + reg->tmu_intclear);
  340. clk_disable(data->clk);
  341. mutex_unlock(&data->lock);
  342. enable_irq(data->irq);
  343. }
  344. static irqreturn_t exynos_tmu_irq(int irq, void *id)
  345. {
  346. struct exynos_tmu_data *data = id;
  347. disable_irq_nosync(irq);
  348. schedule_work(&data->irq_work);
  349. return IRQ_HANDLED;
  350. }
  351. #ifdef CONFIG_OF
  352. static const struct of_device_id exynos_tmu_match[] = {
  353. {
  354. .compatible = "samsung,exynos4210-tmu",
  355. .data = (void *)EXYNOS4210_TMU_DRV_DATA,
  356. },
  357. {
  358. .compatible = "samsung,exynos4412-tmu",
  359. .data = (void *)EXYNOS5250_TMU_DRV_DATA,
  360. },
  361. {
  362. .compatible = "samsung,exynos5250-tmu",
  363. .data = (void *)EXYNOS5250_TMU_DRV_DATA,
  364. },
  365. {},
  366. };
  367. MODULE_DEVICE_TABLE(of, exynos_tmu_match);
  368. #endif
  369. static inline struct exynos_tmu_platform_data *exynos_get_driver_data(
  370. struct platform_device *pdev, int id)
  371. {
  372. #ifdef CONFIG_OF
  373. struct exynos_tmu_init_data *data_table;
  374. struct exynos_tmu_platform_data *tmu_data;
  375. if (pdev->dev.of_node) {
  376. const struct of_device_id *match;
  377. match = of_match_node(exynos_tmu_match, pdev->dev.of_node);
  378. if (!match)
  379. return NULL;
  380. data_table = (struct exynos_tmu_init_data *) match->data;
  381. if (!data_table || id >= data_table->tmu_count)
  382. return NULL;
  383. tmu_data = data_table->tmu_data;
  384. return (struct exynos_tmu_platform_data *) (tmu_data + id);
  385. }
  386. #endif
  387. return NULL;
  388. }
  389. static int exynos_map_dt_data(struct platform_device *pdev)
  390. {
  391. struct exynos_tmu_data *data = platform_get_drvdata(pdev);
  392. struct exynos_tmu_platform_data *pdata;
  393. struct resource res;
  394. if (!data)
  395. return -ENODEV;
  396. data->id = of_alias_get_id(pdev->dev.of_node, "tmuctrl");
  397. if (data->id < 0)
  398. data->id = 0;
  399. data->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
  400. if (data->irq <= 0) {
  401. dev_err(&pdev->dev, "failed to get IRQ\n");
  402. return -ENODEV;
  403. }
  404. if (of_address_to_resource(pdev->dev.of_node, 0, &res)) {
  405. dev_err(&pdev->dev, "failed to get Resource 0\n");
  406. return -ENODEV;
  407. }
  408. data->base = devm_ioremap(&pdev->dev, res.start, resource_size(&res));
  409. if (!data->base) {
  410. dev_err(&pdev->dev, "Failed to ioremap memory\n");
  411. return -EADDRNOTAVAIL;
  412. }
  413. pdata = exynos_get_driver_data(pdev, data->id);
  414. if (!pdata) {
  415. dev_err(&pdev->dev, "No platform init data supplied.\n");
  416. return -ENODEV;
  417. }
  418. data->pdata = pdata;
  419. /*
  420. * Check if the TMU shares some registers and then try to map the
  421. * memory of common registers.
  422. */
  423. if (!TMU_SUPPORTS(pdata, SHARED_MEMORY))
  424. return 0;
  425. if (of_address_to_resource(pdev->dev.of_node, 1, &res)) {
  426. dev_err(&pdev->dev, "failed to get Resource 1\n");
  427. return -ENODEV;
  428. }
  429. data->base_common = devm_ioremap(&pdev->dev, res.start,
  430. resource_size(&res));
  431. if (!data->base) {
  432. dev_err(&pdev->dev, "Failed to ioremap memory\n");
  433. return -ENOMEM;
  434. }
  435. return 0;
  436. }
  437. static int exynos_tmu_probe(struct platform_device *pdev)
  438. {
  439. struct exynos_tmu_data *data;
  440. struct exynos_tmu_platform_data *pdata;
  441. struct thermal_sensor_conf *sensor_conf;
  442. int ret, i;
  443. data = devm_kzalloc(&pdev->dev, sizeof(struct exynos_tmu_data),
  444. GFP_KERNEL);
  445. if (!data) {
  446. dev_err(&pdev->dev, "Failed to allocate driver structure\n");
  447. return -ENOMEM;
  448. }
  449. platform_set_drvdata(pdev, data);
  450. mutex_init(&data->lock);
  451. ret = exynos_map_dt_data(pdev);
  452. if (ret)
  453. return ret;
  454. pdata = data->pdata;
  455. INIT_WORK(&data->irq_work, exynos_tmu_work);
  456. data->clk = devm_clk_get(&pdev->dev, "tmu_apbif");
  457. if (IS_ERR(data->clk)) {
  458. dev_err(&pdev->dev, "Failed to get clock\n");
  459. return PTR_ERR(data->clk);
  460. }
  461. ret = clk_prepare(data->clk);
  462. if (ret)
  463. return ret;
  464. if (pdata->type == SOC_ARCH_EXYNOS ||
  465. pdata->type == SOC_ARCH_EXYNOS4210)
  466. data->soc = pdata->type;
  467. else {
  468. ret = -EINVAL;
  469. dev_err(&pdev->dev, "Platform not supported\n");
  470. goto err_clk;
  471. }
  472. ret = exynos_tmu_initialize(pdev);
  473. if (ret) {
  474. dev_err(&pdev->dev, "Failed to initialize TMU\n");
  475. goto err_clk;
  476. }
  477. exynos_tmu_control(pdev, true);
  478. /* Allocate a structure to register with the exynos core thermal */
  479. sensor_conf = devm_kzalloc(&pdev->dev,
  480. sizeof(struct thermal_sensor_conf), GFP_KERNEL);
  481. if (!sensor_conf) {
  482. dev_err(&pdev->dev, "Failed to allocate registration struct\n");
  483. ret = -ENOMEM;
  484. goto err_clk;
  485. }
  486. sprintf(sensor_conf->name, "therm_zone%d", data->id);
  487. sensor_conf->read_temperature = (int (*)(void *))exynos_tmu_read;
  488. sensor_conf->write_emul_temp =
  489. (int (*)(void *, unsigned long))exynos_tmu_set_emulation;
  490. sensor_conf->driver_data = data;
  491. sensor_conf->trip_data.trip_count = pdata->trigger_enable[0] +
  492. pdata->trigger_enable[1] + pdata->trigger_enable[2]+
  493. pdata->trigger_enable[3];
  494. for (i = 0; i < sensor_conf->trip_data.trip_count; i++) {
  495. sensor_conf->trip_data.trip_val[i] =
  496. pdata->threshold + pdata->trigger_levels[i];
  497. sensor_conf->trip_data.trip_type[i] =
  498. pdata->trigger_type[i];
  499. }
  500. sensor_conf->trip_data.trigger_falling = pdata->threshold_falling;
  501. sensor_conf->cooling_data.freq_clip_count = pdata->freq_tab_count;
  502. for (i = 0; i < pdata->freq_tab_count; i++) {
  503. sensor_conf->cooling_data.freq_data[i].freq_clip_max =
  504. pdata->freq_tab[i].freq_clip_max;
  505. sensor_conf->cooling_data.freq_data[i].temp_level =
  506. pdata->freq_tab[i].temp_level;
  507. }
  508. sensor_conf->dev = &pdev->dev;
  509. /* Register the sensor with thermal management interface */
  510. ret = exynos_register_thermal(sensor_conf);
  511. if (ret) {
  512. dev_err(&pdev->dev, "Failed to register thermal interface\n");
  513. goto err_clk;
  514. }
  515. data->reg_conf = sensor_conf;
  516. ret = devm_request_irq(&pdev->dev, data->irq, exynos_tmu_irq,
  517. IRQF_TRIGGER_RISING | IRQF_SHARED, dev_name(&pdev->dev), data);
  518. if (ret) {
  519. dev_err(&pdev->dev, "Failed to request irq: %d\n", data->irq);
  520. goto err_clk;
  521. }
  522. return 0;
  523. err_clk:
  524. clk_unprepare(data->clk);
  525. return ret;
  526. }
  527. static int exynos_tmu_remove(struct platform_device *pdev)
  528. {
  529. struct exynos_tmu_data *data = platform_get_drvdata(pdev);
  530. exynos_tmu_control(pdev, false);
  531. exynos_unregister_thermal(data->reg_conf);
  532. clk_unprepare(data->clk);
  533. return 0;
  534. }
  535. #ifdef CONFIG_PM_SLEEP
  536. static int exynos_tmu_suspend(struct device *dev)
  537. {
  538. exynos_tmu_control(to_platform_device(dev), false);
  539. return 0;
  540. }
  541. static int exynos_tmu_resume(struct device *dev)
  542. {
  543. struct platform_device *pdev = to_platform_device(dev);
  544. exynos_tmu_initialize(pdev);
  545. exynos_tmu_control(pdev, true);
  546. return 0;
  547. }
  548. static SIMPLE_DEV_PM_OPS(exynos_tmu_pm,
  549. exynos_tmu_suspend, exynos_tmu_resume);
  550. #define EXYNOS_TMU_PM (&exynos_tmu_pm)
  551. #else
  552. #define EXYNOS_TMU_PM NULL
  553. #endif
  554. static struct platform_driver exynos_tmu_driver = {
  555. .driver = {
  556. .name = "exynos-tmu",
  557. .owner = THIS_MODULE,
  558. .pm = EXYNOS_TMU_PM,
  559. .of_match_table = of_match_ptr(exynos_tmu_match),
  560. },
  561. .probe = exynos_tmu_probe,
  562. .remove = exynos_tmu_remove,
  563. };
  564. module_platform_driver(exynos_tmu_driver);
  565. MODULE_DESCRIPTION("EXYNOS TMU Driver");
  566. MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>");
  567. MODULE_LICENSE("GPL");
  568. MODULE_ALIAS("platform:exynos-tmu");