ti-bandgap.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * TI Bandgap temperature sensor driver
  4. *
  5. * Copyright (C) 2011-2012 Texas Instruments Incorporated - http://www.ti.com/
  6. * Author: J Keerthy <[email protected]>
  7. * Author: Moiz Sonasath <[email protected]>
  8. * Couple of fixes, DT and MFD adaptation:
  9. * Eduardo Valentin <[email protected]>
  10. */
  11. #include <linux/clk.h>
  12. #include <linux/cpu_pm.h>
  13. #include <linux/device.h>
  14. #include <linux/err.h>
  15. #include <linux/export.h>
  16. #include <linux/gpio/consumer.h>
  17. #include <linux/init.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/io.h>
  20. #include <linux/iopoll.h>
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/of.h>
  24. #include <linux/of_device.h>
  25. #include <linux/of_irq.h>
  26. #include <linux/of_platform.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/pm.h>
  29. #include <linux/pm_runtime.h>
  30. #include <linux/reboot.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/sys_soc.h>
  33. #include <linux/types.h>
  34. #include "ti-bandgap.h"
  35. static int ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id);
  36. #ifdef CONFIG_PM_SLEEP
  37. static int bandgap_omap_cpu_notifier(struct notifier_block *nb,
  38. unsigned long cmd, void *v);
  39. #endif
  40. /*** Helper functions to access registers and their bitfields ***/
  41. /**
  42. * ti_bandgap_readl() - simple read helper function
  43. * @bgp: pointer to ti_bandgap structure
  44. * @reg: desired register (offset) to be read
  45. *
  46. * Helper function to read bandgap registers. It uses the io remapped area.
  47. * Return: the register value.
  48. */
  49. static u32 ti_bandgap_readl(struct ti_bandgap *bgp, u32 reg)
  50. {
  51. return readl(bgp->base + reg);
  52. }
  53. /**
  54. * ti_bandgap_writel() - simple write helper function
  55. * @bgp: pointer to ti_bandgap structure
  56. * @val: desired register value to be written
  57. * @reg: desired register (offset) to be written
  58. *
  59. * Helper function to write bandgap registers. It uses the io remapped area.
  60. */
  61. static void ti_bandgap_writel(struct ti_bandgap *bgp, u32 val, u32 reg)
  62. {
  63. writel(val, bgp->base + reg);
  64. }
  65. /**
  66. * DOC: macro to update bits.
  67. *
  68. * RMW_BITS() - used to read, modify and update bandgap bitfields.
  69. * The value passed will be shifted.
  70. */
  71. #define RMW_BITS(bgp, id, reg, mask, val) \
  72. do { \
  73. struct temp_sensor_registers *t; \
  74. u32 r; \
  75. \
  76. t = bgp->conf->sensors[(id)].registers; \
  77. r = ti_bandgap_readl(bgp, t->reg); \
  78. r &= ~t->mask; \
  79. r |= (val) << __ffs(t->mask); \
  80. ti_bandgap_writel(bgp, r, t->reg); \
  81. } while (0)
  82. /*** Basic helper functions ***/
  83. /**
  84. * ti_bandgap_power() - controls the power state of a bandgap device
  85. * @bgp: pointer to ti_bandgap structure
  86. * @on: desired power state (1 - on, 0 - off)
  87. *
  88. * Used to power on/off a bandgap device instance. Only used on those
  89. * that features tempsoff bit.
  90. *
  91. * Return: 0 on success, -ENOTSUPP if tempsoff is not supported.
  92. */
  93. static int ti_bandgap_power(struct ti_bandgap *bgp, bool on)
  94. {
  95. int i;
  96. if (!TI_BANDGAP_HAS(bgp, POWER_SWITCH))
  97. return -ENOTSUPP;
  98. for (i = 0; i < bgp->conf->sensor_count; i++)
  99. /* active on 0 */
  100. RMW_BITS(bgp, i, temp_sensor_ctrl, bgap_tempsoff_mask, !on);
  101. return 0;
  102. }
  103. /**
  104. * ti_errata814_bandgap_read_temp() - helper function to read dra7 sensor temperature
  105. * @bgp: pointer to ti_bandgap structure
  106. * @reg: desired register (offset) to be read
  107. *
  108. * Function to read dra7 bandgap sensor temperature. This is done separately
  109. * so as to workaround the errata "Bandgap Temperature read Dtemp can be
  110. * corrupted" - Errata ID: i814".
  111. * Read accesses to registers listed below can be corrupted due to incorrect
  112. * resynchronization between clock domains.
  113. * Read access to registers below can be corrupted :
  114. * CTRL_CORE_DTEMP_MPU/GPU/CORE/DSPEVE/IVA_n (n = 0 to 4)
  115. * CTRL_CORE_TEMP_SENSOR_MPU/GPU/CORE/DSPEVE/IVA_n
  116. *
  117. * Return: the register value.
  118. */
  119. static u32 ti_errata814_bandgap_read_temp(struct ti_bandgap *bgp, u32 reg)
  120. {
  121. u32 val1, val2;
  122. val1 = ti_bandgap_readl(bgp, reg);
  123. val2 = ti_bandgap_readl(bgp, reg);
  124. /* If both times we read the same value then that is right */
  125. if (val1 == val2)
  126. return val1;
  127. /* if val1 and val2 are different read it third time */
  128. return ti_bandgap_readl(bgp, reg);
  129. }
  130. /**
  131. * ti_bandgap_read_temp() - helper function to read sensor temperature
  132. * @bgp: pointer to ti_bandgap structure
  133. * @id: bandgap sensor id
  134. *
  135. * Function to concentrate the steps to read sensor temperature register.
  136. * This function is desired because, depending on bandgap device version,
  137. * it might be needed to freeze the bandgap state machine, before fetching
  138. * the register value.
  139. *
  140. * Return: temperature in ADC values.
  141. */
  142. static u32 ti_bandgap_read_temp(struct ti_bandgap *bgp, int id)
  143. {
  144. struct temp_sensor_registers *tsr;
  145. u32 temp, reg;
  146. tsr = bgp->conf->sensors[id].registers;
  147. reg = tsr->temp_sensor_ctrl;
  148. if (TI_BANDGAP_HAS(bgp, FREEZE_BIT)) {
  149. RMW_BITS(bgp, id, bgap_mask_ctrl, mask_freeze_mask, 1);
  150. /*
  151. * In case we cannot read from cur_dtemp / dtemp_0,
  152. * then we read from the last valid temp read
  153. */
  154. reg = tsr->ctrl_dtemp_1;
  155. }
  156. /* read temperature */
  157. if (TI_BANDGAP_HAS(bgp, ERRATA_814))
  158. temp = ti_errata814_bandgap_read_temp(bgp, reg);
  159. else
  160. temp = ti_bandgap_readl(bgp, reg);
  161. temp &= tsr->bgap_dtemp_mask;
  162. if (TI_BANDGAP_HAS(bgp, FREEZE_BIT))
  163. RMW_BITS(bgp, id, bgap_mask_ctrl, mask_freeze_mask, 0);
  164. return temp;
  165. }
  166. /*** IRQ handlers ***/
  167. /**
  168. * ti_bandgap_talert_irq_handler() - handles Temperature alert IRQs
  169. * @irq: IRQ number
  170. * @data: private data (struct ti_bandgap *)
  171. *
  172. * This is the Talert handler. Use it only if bandgap device features
  173. * HAS(TALERT). This handler goes over all sensors and checks their
  174. * conditions and acts accordingly. In case there are events pending,
  175. * it will reset the event mask to wait for the opposite event (next event).
  176. * Every time there is a new event, it will be reported to thermal layer.
  177. *
  178. * Return: IRQ_HANDLED
  179. */
  180. static irqreturn_t ti_bandgap_talert_irq_handler(int irq, void *data)
  181. {
  182. struct ti_bandgap *bgp = data;
  183. struct temp_sensor_registers *tsr;
  184. u32 t_hot = 0, t_cold = 0, ctrl;
  185. int i;
  186. spin_lock(&bgp->lock);
  187. for (i = 0; i < bgp->conf->sensor_count; i++) {
  188. tsr = bgp->conf->sensors[i].registers;
  189. ctrl = ti_bandgap_readl(bgp, tsr->bgap_status);
  190. /* Read the status of t_hot */
  191. t_hot = ctrl & tsr->status_hot_mask;
  192. /* Read the status of t_cold */
  193. t_cold = ctrl & tsr->status_cold_mask;
  194. if (!t_cold && !t_hot)
  195. continue;
  196. ctrl = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl);
  197. /*
  198. * One TALERT interrupt: Two sources
  199. * If the interrupt is due to t_hot then mask t_hot and
  200. * unmask t_cold else mask t_cold and unmask t_hot
  201. */
  202. if (t_hot) {
  203. ctrl &= ~tsr->mask_hot_mask;
  204. ctrl |= tsr->mask_cold_mask;
  205. } else if (t_cold) {
  206. ctrl &= ~tsr->mask_cold_mask;
  207. ctrl |= tsr->mask_hot_mask;
  208. }
  209. ti_bandgap_writel(bgp, ctrl, tsr->bgap_mask_ctrl);
  210. dev_dbg(bgp->dev,
  211. "%s: IRQ from %s sensor: hotevent %d coldevent %d\n",
  212. __func__, bgp->conf->sensors[i].domain,
  213. t_hot, t_cold);
  214. /* report temperature to whom may concern */
  215. if (bgp->conf->report_temperature)
  216. bgp->conf->report_temperature(bgp, i);
  217. }
  218. spin_unlock(&bgp->lock);
  219. return IRQ_HANDLED;
  220. }
  221. /**
  222. * ti_bandgap_tshut_irq_handler() - handles Temperature shutdown signal
  223. * @irq: IRQ number
  224. * @data: private data (unused)
  225. *
  226. * This is the Tshut handler. Use it only if bandgap device features
  227. * HAS(TSHUT). If any sensor fires the Tshut signal, we simply shutdown
  228. * the system.
  229. *
  230. * Return: IRQ_HANDLED
  231. */
  232. static irqreturn_t ti_bandgap_tshut_irq_handler(int irq, void *data)
  233. {
  234. pr_emerg("%s: TSHUT temperature reached. Needs shut down...\n",
  235. __func__);
  236. orderly_poweroff(true);
  237. return IRQ_HANDLED;
  238. }
  239. /*** Helper functions which manipulate conversion ADC <-> mi Celsius ***/
  240. /**
  241. * ti_bandgap_adc_to_mcelsius() - converts an ADC value to mCelsius scale
  242. * @bgp: struct ti_bandgap pointer
  243. * @adc_val: value in ADC representation
  244. * @t: address where to write the resulting temperature in mCelsius
  245. *
  246. * Simple conversion from ADC representation to mCelsius. In case the ADC value
  247. * is out of the ADC conv table range, it returns -ERANGE, 0 on success.
  248. * The conversion table is indexed by the ADC values.
  249. *
  250. * Return: 0 if conversion was successful, else -ERANGE in case the @adc_val
  251. * argument is out of the ADC conv table range.
  252. */
  253. static
  254. int ti_bandgap_adc_to_mcelsius(struct ti_bandgap *bgp, int adc_val, int *t)
  255. {
  256. const struct ti_bandgap_data *conf = bgp->conf;
  257. /* look up for temperature in the table and return the temperature */
  258. if (adc_val < conf->adc_start_val || adc_val > conf->adc_end_val)
  259. return -ERANGE;
  260. *t = bgp->conf->conv_table[adc_val - conf->adc_start_val];
  261. return 0;
  262. }
  263. /**
  264. * ti_bandgap_validate() - helper to check the sanity of a struct ti_bandgap
  265. * @bgp: struct ti_bandgap pointer
  266. * @id: bandgap sensor id
  267. *
  268. * Checks if the bandgap pointer is valid and if the sensor id is also
  269. * applicable.
  270. *
  271. * Return: 0 if no errors, -EINVAL for invalid @bgp pointer or -ERANGE if
  272. * @id cannot index @bgp sensors.
  273. */
  274. static inline int ti_bandgap_validate(struct ti_bandgap *bgp, int id)
  275. {
  276. if (!bgp || IS_ERR(bgp)) {
  277. pr_err("%s: invalid bandgap pointer\n", __func__);
  278. return -EINVAL;
  279. }
  280. if ((id < 0) || (id >= bgp->conf->sensor_count)) {
  281. dev_err(bgp->dev, "%s: sensor id out of range (%d)\n",
  282. __func__, id);
  283. return -ERANGE;
  284. }
  285. return 0;
  286. }
  287. /**
  288. * ti_bandgap_read_counter() - read the sensor counter
  289. * @bgp: pointer to bandgap instance
  290. * @id: sensor id
  291. * @interval: resulting update interval in miliseconds
  292. */
  293. static void ti_bandgap_read_counter(struct ti_bandgap *bgp, int id,
  294. int *interval)
  295. {
  296. struct temp_sensor_registers *tsr;
  297. int time;
  298. tsr = bgp->conf->sensors[id].registers;
  299. time = ti_bandgap_readl(bgp, tsr->bgap_counter);
  300. time = (time & tsr->counter_mask) >>
  301. __ffs(tsr->counter_mask);
  302. time = time * 1000 / bgp->clk_rate;
  303. *interval = time;
  304. }
  305. /**
  306. * ti_bandgap_read_counter_delay() - read the sensor counter delay
  307. * @bgp: pointer to bandgap instance
  308. * @id: sensor id
  309. * @interval: resulting update interval in miliseconds
  310. */
  311. static void ti_bandgap_read_counter_delay(struct ti_bandgap *bgp, int id,
  312. int *interval)
  313. {
  314. struct temp_sensor_registers *tsr;
  315. int reg_val;
  316. tsr = bgp->conf->sensors[id].registers;
  317. reg_val = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl);
  318. reg_val = (reg_val & tsr->mask_counter_delay_mask) >>
  319. __ffs(tsr->mask_counter_delay_mask);
  320. switch (reg_val) {
  321. case 0:
  322. *interval = 0;
  323. break;
  324. case 1:
  325. *interval = 1;
  326. break;
  327. case 2:
  328. *interval = 10;
  329. break;
  330. case 3:
  331. *interval = 100;
  332. break;
  333. case 4:
  334. *interval = 250;
  335. break;
  336. case 5:
  337. *interval = 500;
  338. break;
  339. default:
  340. dev_warn(bgp->dev, "Wrong counter delay value read from register %X",
  341. reg_val);
  342. }
  343. }
  344. /**
  345. * ti_bandgap_read_update_interval() - read the sensor update interval
  346. * @bgp: pointer to bandgap instance
  347. * @id: sensor id
  348. * @interval: resulting update interval in miliseconds
  349. *
  350. * Return: 0 on success or the proper error code
  351. */
  352. int ti_bandgap_read_update_interval(struct ti_bandgap *bgp, int id,
  353. int *interval)
  354. {
  355. int ret = 0;
  356. ret = ti_bandgap_validate(bgp, id);
  357. if (ret)
  358. goto exit;
  359. if (!TI_BANDGAP_HAS(bgp, COUNTER) &&
  360. !TI_BANDGAP_HAS(bgp, COUNTER_DELAY)) {
  361. ret = -ENOTSUPP;
  362. goto exit;
  363. }
  364. if (TI_BANDGAP_HAS(bgp, COUNTER)) {
  365. ti_bandgap_read_counter(bgp, id, interval);
  366. goto exit;
  367. }
  368. ti_bandgap_read_counter_delay(bgp, id, interval);
  369. exit:
  370. return ret;
  371. }
  372. /**
  373. * ti_bandgap_write_counter_delay() - set the counter_delay
  374. * @bgp: pointer to bandgap instance
  375. * @id: sensor id
  376. * @interval: desired update interval in miliseconds
  377. *
  378. * Return: 0 on success or the proper error code
  379. */
  380. static int ti_bandgap_write_counter_delay(struct ti_bandgap *bgp, int id,
  381. u32 interval)
  382. {
  383. int rval;
  384. switch (interval) {
  385. case 0: /* Immediate conversion */
  386. rval = 0x0;
  387. break;
  388. case 1: /* Conversion after ever 1ms */
  389. rval = 0x1;
  390. break;
  391. case 10: /* Conversion after ever 10ms */
  392. rval = 0x2;
  393. break;
  394. case 100: /* Conversion after ever 100ms */
  395. rval = 0x3;
  396. break;
  397. case 250: /* Conversion after ever 250ms */
  398. rval = 0x4;
  399. break;
  400. case 500: /* Conversion after ever 500ms */
  401. rval = 0x5;
  402. break;
  403. default:
  404. dev_warn(bgp->dev, "Delay %d ms is not supported\n", interval);
  405. return -EINVAL;
  406. }
  407. spin_lock(&bgp->lock);
  408. RMW_BITS(bgp, id, bgap_mask_ctrl, mask_counter_delay_mask, rval);
  409. spin_unlock(&bgp->lock);
  410. return 0;
  411. }
  412. /**
  413. * ti_bandgap_write_counter() - set the bandgap sensor counter
  414. * @bgp: pointer to bandgap instance
  415. * @id: sensor id
  416. * @interval: desired update interval in miliseconds
  417. */
  418. static void ti_bandgap_write_counter(struct ti_bandgap *bgp, int id,
  419. u32 interval)
  420. {
  421. interval = interval * bgp->clk_rate / 1000;
  422. spin_lock(&bgp->lock);
  423. RMW_BITS(bgp, id, bgap_counter, counter_mask, interval);
  424. spin_unlock(&bgp->lock);
  425. }
  426. /**
  427. * ti_bandgap_write_update_interval() - set the update interval
  428. * @bgp: pointer to bandgap instance
  429. * @id: sensor id
  430. * @interval: desired update interval in miliseconds
  431. *
  432. * Return: 0 on success or the proper error code
  433. */
  434. int ti_bandgap_write_update_interval(struct ti_bandgap *bgp,
  435. int id, u32 interval)
  436. {
  437. int ret = ti_bandgap_validate(bgp, id);
  438. if (ret)
  439. goto exit;
  440. if (!TI_BANDGAP_HAS(bgp, COUNTER) &&
  441. !TI_BANDGAP_HAS(bgp, COUNTER_DELAY)) {
  442. ret = -ENOTSUPP;
  443. goto exit;
  444. }
  445. if (TI_BANDGAP_HAS(bgp, COUNTER)) {
  446. ti_bandgap_write_counter(bgp, id, interval);
  447. goto exit;
  448. }
  449. ret = ti_bandgap_write_counter_delay(bgp, id, interval);
  450. exit:
  451. return ret;
  452. }
  453. /**
  454. * ti_bandgap_read_temperature() - report current temperature
  455. * @bgp: pointer to bandgap instance
  456. * @id: sensor id
  457. * @temperature: resulting temperature
  458. *
  459. * Return: 0 on success or the proper error code
  460. */
  461. int ti_bandgap_read_temperature(struct ti_bandgap *bgp, int id,
  462. int *temperature)
  463. {
  464. u32 temp;
  465. int ret;
  466. ret = ti_bandgap_validate(bgp, id);
  467. if (ret)
  468. return ret;
  469. if (!TI_BANDGAP_HAS(bgp, MODE_CONFIG)) {
  470. ret = ti_bandgap_force_single_read(bgp, id);
  471. if (ret)
  472. return ret;
  473. }
  474. spin_lock(&bgp->lock);
  475. temp = ti_bandgap_read_temp(bgp, id);
  476. spin_unlock(&bgp->lock);
  477. ret = ti_bandgap_adc_to_mcelsius(bgp, temp, &temp);
  478. if (ret)
  479. return -EIO;
  480. *temperature = temp;
  481. return 0;
  482. }
  483. /**
  484. * ti_bandgap_set_sensor_data() - helper function to store thermal
  485. * framework related data.
  486. * @bgp: pointer to bandgap instance
  487. * @id: sensor id
  488. * @data: thermal framework related data to be stored
  489. *
  490. * Return: 0 on success or the proper error code
  491. */
  492. int ti_bandgap_set_sensor_data(struct ti_bandgap *bgp, int id, void *data)
  493. {
  494. int ret = ti_bandgap_validate(bgp, id);
  495. if (ret)
  496. return ret;
  497. bgp->regval[id].data = data;
  498. return 0;
  499. }
  500. /**
  501. * ti_bandgap_get_sensor_data() - helper function to get thermal
  502. * framework related data.
  503. * @bgp: pointer to bandgap instance
  504. * @id: sensor id
  505. *
  506. * Return: data stored by set function with sensor id on success or NULL
  507. */
  508. void *ti_bandgap_get_sensor_data(struct ti_bandgap *bgp, int id)
  509. {
  510. int ret = ti_bandgap_validate(bgp, id);
  511. if (ret)
  512. return ERR_PTR(ret);
  513. return bgp->regval[id].data;
  514. }
  515. /*** Helper functions used during device initialization ***/
  516. /**
  517. * ti_bandgap_force_single_read() - executes 1 single ADC conversion
  518. * @bgp: pointer to struct ti_bandgap
  519. * @id: sensor id which it is desired to read 1 temperature
  520. *
  521. * Used to initialize the conversion state machine and set it to a valid
  522. * state. Called during device initialization and context restore events.
  523. *
  524. * Return: 0
  525. */
  526. static int
  527. ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id)
  528. {
  529. struct temp_sensor_registers *tsr = bgp->conf->sensors[id].registers;
  530. void __iomem *temp_sensor_ctrl = bgp->base + tsr->temp_sensor_ctrl;
  531. int error;
  532. u32 val;
  533. /* Select continuous or single conversion mode */
  534. if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) {
  535. if (TI_BANDGAP_HAS(bgp, CONT_MODE_ONLY))
  536. RMW_BITS(bgp, id, bgap_mode_ctrl, mode_ctrl_mask, 1);
  537. else
  538. RMW_BITS(bgp, id, bgap_mode_ctrl, mode_ctrl_mask, 0);
  539. }
  540. /* Set Start of Conversion if available */
  541. if (tsr->bgap_soc_mask) {
  542. RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 1);
  543. /* Wait for EOCZ going up */
  544. error = readl_poll_timeout_atomic(temp_sensor_ctrl, val,
  545. val & tsr->bgap_eocz_mask,
  546. 1, 1000);
  547. if (error)
  548. dev_warn(bgp->dev, "eocz timed out waiting high\n");
  549. /* Clear Start of Conversion if available */
  550. RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 0);
  551. }
  552. /* Wait for EOCZ going down, always needed even if no bgap_soc_mask */
  553. error = readl_poll_timeout_atomic(temp_sensor_ctrl, val,
  554. !(val & tsr->bgap_eocz_mask),
  555. 1, 1500);
  556. if (error)
  557. dev_warn(bgp->dev, "eocz timed out waiting low\n");
  558. return 0;
  559. }
  560. /**
  561. * ti_bandgap_set_continuous_mode() - One time enabling of continuous mode
  562. * @bgp: pointer to struct ti_bandgap
  563. *
  564. * Call this function only if HAS(MODE_CONFIG) is set. As this driver may
  565. * be used for junction temperature monitoring, it is desirable that the
  566. * sensors are operational all the time, so that alerts are generated
  567. * properly.
  568. *
  569. * Return: 0
  570. */
  571. static int ti_bandgap_set_continuous_mode(struct ti_bandgap *bgp)
  572. {
  573. int i;
  574. for (i = 0; i < bgp->conf->sensor_count; i++) {
  575. /* Perform a single read just before enabling continuous */
  576. ti_bandgap_force_single_read(bgp, i);
  577. RMW_BITS(bgp, i, bgap_mode_ctrl, mode_ctrl_mask, 1);
  578. }
  579. return 0;
  580. }
  581. /**
  582. * ti_bandgap_get_trend() - To fetch the temperature trend of a sensor
  583. * @bgp: pointer to struct ti_bandgap
  584. * @id: id of the individual sensor
  585. * @trend: Pointer to trend.
  586. *
  587. * This function needs to be called to fetch the temperature trend of a
  588. * Particular sensor. The function computes the difference in temperature
  589. * w.r.t time. For the bandgaps with built in history buffer the temperatures
  590. * are read from the buffer and for those without the Buffer -ENOTSUPP is
  591. * returned.
  592. *
  593. * Return: 0 if no error, else return corresponding error. If no
  594. * error then the trend value is passed on to trend parameter
  595. */
  596. int ti_bandgap_get_trend(struct ti_bandgap *bgp, int id, int *trend)
  597. {
  598. struct temp_sensor_registers *tsr;
  599. u32 temp1, temp2, reg1, reg2;
  600. int t1, t2, interval, ret = 0;
  601. ret = ti_bandgap_validate(bgp, id);
  602. if (ret)
  603. goto exit;
  604. if (!TI_BANDGAP_HAS(bgp, HISTORY_BUFFER) ||
  605. !TI_BANDGAP_HAS(bgp, FREEZE_BIT)) {
  606. ret = -ENOTSUPP;
  607. goto exit;
  608. }
  609. spin_lock(&bgp->lock);
  610. tsr = bgp->conf->sensors[id].registers;
  611. /* Freeze and read the last 2 valid readings */
  612. RMW_BITS(bgp, id, bgap_mask_ctrl, mask_freeze_mask, 1);
  613. reg1 = tsr->ctrl_dtemp_1;
  614. reg2 = tsr->ctrl_dtemp_2;
  615. /* read temperature from history buffer */
  616. temp1 = ti_bandgap_readl(bgp, reg1);
  617. temp1 &= tsr->bgap_dtemp_mask;
  618. temp2 = ti_bandgap_readl(bgp, reg2);
  619. temp2 &= tsr->bgap_dtemp_mask;
  620. /* Convert from adc values to mCelsius temperature */
  621. ret = ti_bandgap_adc_to_mcelsius(bgp, temp1, &t1);
  622. if (ret)
  623. goto unfreeze;
  624. ret = ti_bandgap_adc_to_mcelsius(bgp, temp2, &t2);
  625. if (ret)
  626. goto unfreeze;
  627. /* Fetch the update interval */
  628. ret = ti_bandgap_read_update_interval(bgp, id, &interval);
  629. if (ret)
  630. goto unfreeze;
  631. /* Set the interval to 1 ms if bandgap counter delay is not set */
  632. if (interval == 0)
  633. interval = 1;
  634. *trend = (t1 - t2) / interval;
  635. dev_dbg(bgp->dev, "The temperatures are t1 = %d and t2 = %d and trend =%d\n",
  636. t1, t2, *trend);
  637. unfreeze:
  638. RMW_BITS(bgp, id, bgap_mask_ctrl, mask_freeze_mask, 0);
  639. spin_unlock(&bgp->lock);
  640. exit:
  641. return ret;
  642. }
  643. /**
  644. * ti_bandgap_tshut_init() - setup and initialize tshut handling
  645. * @bgp: pointer to struct ti_bandgap
  646. * @pdev: pointer to device struct platform_device
  647. *
  648. * Call this function only in case the bandgap features HAS(TSHUT).
  649. * In this case, the driver needs to handle the TSHUT signal as an IRQ.
  650. * The IRQ is wired as a GPIO, and for this purpose, it is required
  651. * to specify which GPIO line is used. TSHUT IRQ is fired anytime
  652. * one of the bandgap sensors violates the TSHUT high/hot threshold.
  653. * And in that case, the system must go off.
  654. *
  655. * Return: 0 if no error, else error status
  656. */
  657. static int ti_bandgap_tshut_init(struct ti_bandgap *bgp,
  658. struct platform_device *pdev)
  659. {
  660. int status;
  661. status = request_irq(gpiod_to_irq(bgp->tshut_gpiod),
  662. ti_bandgap_tshut_irq_handler,
  663. IRQF_TRIGGER_RISING, "tshut", NULL);
  664. if (status)
  665. dev_err(bgp->dev, "request irq failed for TSHUT");
  666. return 0;
  667. }
  668. /**
  669. * ti_bandgap_talert_init() - setup and initialize talert handling
  670. * @bgp: pointer to struct ti_bandgap
  671. * @pdev: pointer to device struct platform_device
  672. *
  673. * Call this function only in case the bandgap features HAS(TALERT).
  674. * In this case, the driver needs to handle the TALERT signals as an IRQs.
  675. * TALERT is a normal IRQ and it is fired any time thresholds (hot or cold)
  676. * are violated. In these situation, the driver must reprogram the thresholds,
  677. * accordingly to specified policy.
  678. *
  679. * Return: 0 if no error, else return corresponding error.
  680. */
  681. static int ti_bandgap_talert_init(struct ti_bandgap *bgp,
  682. struct platform_device *pdev)
  683. {
  684. int ret;
  685. bgp->irq = platform_get_irq(pdev, 0);
  686. if (bgp->irq < 0)
  687. return bgp->irq;
  688. ret = request_threaded_irq(bgp->irq, NULL,
  689. ti_bandgap_talert_irq_handler,
  690. IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
  691. "talert", bgp);
  692. if (ret) {
  693. dev_err(&pdev->dev, "Request threaded irq failed.\n");
  694. return ret;
  695. }
  696. return 0;
  697. }
  698. static const struct of_device_id of_ti_bandgap_match[];
  699. /**
  700. * ti_bandgap_build() - parse DT and setup a struct ti_bandgap
  701. * @pdev: pointer to device struct platform_device
  702. *
  703. * Used to read the device tree properties accordingly to the bandgap
  704. * matching version. Based on bandgap version and its capabilities it
  705. * will build a struct ti_bandgap out of the required DT entries.
  706. *
  707. * Return: valid bandgap structure if successful, else returns ERR_PTR
  708. * return value must be verified with IS_ERR.
  709. */
  710. static struct ti_bandgap *ti_bandgap_build(struct platform_device *pdev)
  711. {
  712. struct device_node *node = pdev->dev.of_node;
  713. const struct of_device_id *of_id;
  714. struct ti_bandgap *bgp;
  715. struct resource *res;
  716. int i;
  717. /* just for the sake */
  718. if (!node) {
  719. dev_err(&pdev->dev, "no platform information available\n");
  720. return ERR_PTR(-EINVAL);
  721. }
  722. bgp = devm_kzalloc(&pdev->dev, sizeof(*bgp), GFP_KERNEL);
  723. if (!bgp)
  724. return ERR_PTR(-ENOMEM);
  725. of_id = of_match_device(of_ti_bandgap_match, &pdev->dev);
  726. if (of_id)
  727. bgp->conf = of_id->data;
  728. /* register shadow for context save and restore */
  729. bgp->regval = devm_kcalloc(&pdev->dev, bgp->conf->sensor_count,
  730. sizeof(*bgp->regval), GFP_KERNEL);
  731. if (!bgp->regval)
  732. return ERR_PTR(-ENOMEM);
  733. i = 0;
  734. do {
  735. void __iomem *chunk;
  736. res = platform_get_resource(pdev, IORESOURCE_MEM, i);
  737. if (!res)
  738. break;
  739. chunk = devm_ioremap_resource(&pdev->dev, res);
  740. if (i == 0)
  741. bgp->base = chunk;
  742. if (IS_ERR(chunk))
  743. return ERR_CAST(chunk);
  744. i++;
  745. } while (res);
  746. if (TI_BANDGAP_HAS(bgp, TSHUT)) {
  747. bgp->tshut_gpiod = devm_gpiod_get(&pdev->dev, NULL, GPIOD_IN);
  748. if (IS_ERR(bgp->tshut_gpiod)) {
  749. dev_err(&pdev->dev, "invalid gpio for tshut\n");
  750. return ERR_CAST(bgp->tshut_gpiod);
  751. }
  752. }
  753. return bgp;
  754. }
  755. /*
  756. * List of SoCs on which the CPU PM notifier can cause erros on the DTEMP
  757. * readout.
  758. * Enabled notifier on these machines results in erroneous, random values which
  759. * could trigger unexpected thermal shutdown.
  760. */
  761. static const struct soc_device_attribute soc_no_cpu_notifier[] = {
  762. { .machine = "OMAP4430" },
  763. { /* sentinel */ },
  764. };
  765. /*** Device driver call backs ***/
  766. static
  767. int ti_bandgap_probe(struct platform_device *pdev)
  768. {
  769. struct ti_bandgap *bgp;
  770. int clk_rate, ret, i;
  771. bgp = ti_bandgap_build(pdev);
  772. if (IS_ERR(bgp)) {
  773. dev_err(&pdev->dev, "failed to fetch platform data\n");
  774. return PTR_ERR(bgp);
  775. }
  776. bgp->dev = &pdev->dev;
  777. if (TI_BANDGAP_HAS(bgp, UNRELIABLE))
  778. dev_warn(&pdev->dev,
  779. "This OMAP thermal sensor is unreliable. You've been warned\n");
  780. if (TI_BANDGAP_HAS(bgp, TSHUT)) {
  781. ret = ti_bandgap_tshut_init(bgp, pdev);
  782. if (ret) {
  783. dev_err(&pdev->dev,
  784. "failed to initialize system tshut IRQ\n");
  785. return ret;
  786. }
  787. }
  788. bgp->fclock = clk_get(NULL, bgp->conf->fclock_name);
  789. if (IS_ERR(bgp->fclock)) {
  790. dev_err(&pdev->dev, "failed to request fclock reference\n");
  791. ret = PTR_ERR(bgp->fclock);
  792. goto free_irqs;
  793. }
  794. bgp->div_clk = clk_get(NULL, bgp->conf->div_ck_name);
  795. if (IS_ERR(bgp->div_clk)) {
  796. dev_err(&pdev->dev, "failed to request div_ts_ck clock ref\n");
  797. ret = PTR_ERR(bgp->div_clk);
  798. goto put_fclock;
  799. }
  800. for (i = 0; i < bgp->conf->sensor_count; i++) {
  801. struct temp_sensor_registers *tsr;
  802. u32 val;
  803. tsr = bgp->conf->sensors[i].registers;
  804. /*
  805. * check if the efuse has a non-zero value if not
  806. * it is an untrimmed sample and the temperatures
  807. * may not be accurate
  808. */
  809. val = ti_bandgap_readl(bgp, tsr->bgap_efuse);
  810. if (!val)
  811. dev_info(&pdev->dev,
  812. "Non-trimmed BGAP, Temp not accurate\n");
  813. }
  814. clk_rate = clk_round_rate(bgp->div_clk,
  815. bgp->conf->sensors[0].ts_data->max_freq);
  816. if (clk_rate < bgp->conf->sensors[0].ts_data->min_freq ||
  817. clk_rate <= 0) {
  818. ret = -ENODEV;
  819. dev_err(&pdev->dev, "wrong clock rate (%d)\n", clk_rate);
  820. goto put_clks;
  821. }
  822. ret = clk_set_rate(bgp->div_clk, clk_rate);
  823. if (ret)
  824. dev_err(&pdev->dev, "Cannot re-set clock rate. Continuing\n");
  825. bgp->clk_rate = clk_rate;
  826. if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
  827. clk_prepare_enable(bgp->fclock);
  828. spin_lock_init(&bgp->lock);
  829. bgp->dev = &pdev->dev;
  830. platform_set_drvdata(pdev, bgp);
  831. ti_bandgap_power(bgp, true);
  832. /* Set default counter to 1 for now */
  833. if (TI_BANDGAP_HAS(bgp, COUNTER))
  834. for (i = 0; i < bgp->conf->sensor_count; i++)
  835. RMW_BITS(bgp, i, bgap_counter, counter_mask, 1);
  836. /* Set default thresholds for alert and shutdown */
  837. for (i = 0; i < bgp->conf->sensor_count; i++) {
  838. struct temp_sensor_data *ts_data;
  839. ts_data = bgp->conf->sensors[i].ts_data;
  840. if (TI_BANDGAP_HAS(bgp, TALERT)) {
  841. /* Set initial Talert thresholds */
  842. RMW_BITS(bgp, i, bgap_threshold,
  843. threshold_tcold_mask, ts_data->t_cold);
  844. RMW_BITS(bgp, i, bgap_threshold,
  845. threshold_thot_mask, ts_data->t_hot);
  846. /* Enable the alert events */
  847. RMW_BITS(bgp, i, bgap_mask_ctrl, mask_hot_mask, 1);
  848. RMW_BITS(bgp, i, bgap_mask_ctrl, mask_cold_mask, 1);
  849. }
  850. if (TI_BANDGAP_HAS(bgp, TSHUT_CONFIG)) {
  851. /* Set initial Tshut thresholds */
  852. RMW_BITS(bgp, i, tshut_threshold,
  853. tshut_hot_mask, ts_data->tshut_hot);
  854. RMW_BITS(bgp, i, tshut_threshold,
  855. tshut_cold_mask, ts_data->tshut_cold);
  856. }
  857. }
  858. if (TI_BANDGAP_HAS(bgp, MODE_CONFIG))
  859. ti_bandgap_set_continuous_mode(bgp);
  860. /* Set .250 seconds time as default counter */
  861. if (TI_BANDGAP_HAS(bgp, COUNTER))
  862. for (i = 0; i < bgp->conf->sensor_count; i++)
  863. RMW_BITS(bgp, i, bgap_counter, counter_mask,
  864. bgp->clk_rate / 4);
  865. /* Every thing is good? Then expose the sensors */
  866. for (i = 0; i < bgp->conf->sensor_count; i++) {
  867. char *domain;
  868. if (bgp->conf->sensors[i].register_cooling) {
  869. ret = bgp->conf->sensors[i].register_cooling(bgp, i);
  870. if (ret)
  871. goto remove_sensors;
  872. }
  873. if (bgp->conf->expose_sensor) {
  874. domain = bgp->conf->sensors[i].domain;
  875. ret = bgp->conf->expose_sensor(bgp, i, domain);
  876. if (ret)
  877. goto remove_last_cooling;
  878. }
  879. }
  880. /*
  881. * Enable the Interrupts once everything is set. Otherwise irq handler
  882. * might be called as soon as it is enabled where as rest of framework
  883. * is still getting initialised.
  884. */
  885. if (TI_BANDGAP_HAS(bgp, TALERT)) {
  886. ret = ti_bandgap_talert_init(bgp, pdev);
  887. if (ret) {
  888. dev_err(&pdev->dev, "failed to initialize Talert IRQ\n");
  889. i = bgp->conf->sensor_count;
  890. goto disable_clk;
  891. }
  892. }
  893. #ifdef CONFIG_PM_SLEEP
  894. bgp->nb.notifier_call = bandgap_omap_cpu_notifier;
  895. if (!soc_device_match(soc_no_cpu_notifier))
  896. cpu_pm_register_notifier(&bgp->nb);
  897. #endif
  898. return 0;
  899. remove_last_cooling:
  900. if (bgp->conf->sensors[i].unregister_cooling)
  901. bgp->conf->sensors[i].unregister_cooling(bgp, i);
  902. remove_sensors:
  903. for (i--; i >= 0; i--) {
  904. if (bgp->conf->sensors[i].unregister_cooling)
  905. bgp->conf->sensors[i].unregister_cooling(bgp, i);
  906. if (bgp->conf->remove_sensor)
  907. bgp->conf->remove_sensor(bgp, i);
  908. }
  909. ti_bandgap_power(bgp, false);
  910. disable_clk:
  911. if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
  912. clk_disable_unprepare(bgp->fclock);
  913. put_clks:
  914. clk_put(bgp->div_clk);
  915. put_fclock:
  916. clk_put(bgp->fclock);
  917. free_irqs:
  918. if (TI_BANDGAP_HAS(bgp, TSHUT))
  919. free_irq(gpiod_to_irq(bgp->tshut_gpiod), NULL);
  920. return ret;
  921. }
  922. static
  923. int ti_bandgap_remove(struct platform_device *pdev)
  924. {
  925. struct ti_bandgap *bgp = platform_get_drvdata(pdev);
  926. int i;
  927. if (!soc_device_match(soc_no_cpu_notifier))
  928. cpu_pm_unregister_notifier(&bgp->nb);
  929. /* Remove sensor interfaces */
  930. for (i = 0; i < bgp->conf->sensor_count; i++) {
  931. if (bgp->conf->sensors[i].unregister_cooling)
  932. bgp->conf->sensors[i].unregister_cooling(bgp, i);
  933. if (bgp->conf->remove_sensor)
  934. bgp->conf->remove_sensor(bgp, i);
  935. }
  936. ti_bandgap_power(bgp, false);
  937. if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
  938. clk_disable_unprepare(bgp->fclock);
  939. clk_put(bgp->fclock);
  940. clk_put(bgp->div_clk);
  941. if (TI_BANDGAP_HAS(bgp, TALERT))
  942. free_irq(bgp->irq, bgp);
  943. if (TI_BANDGAP_HAS(bgp, TSHUT))
  944. free_irq(gpiod_to_irq(bgp->tshut_gpiod), NULL);
  945. return 0;
  946. }
  947. #ifdef CONFIG_PM_SLEEP
  948. static int ti_bandgap_save_ctxt(struct ti_bandgap *bgp)
  949. {
  950. int i;
  951. for (i = 0; i < bgp->conf->sensor_count; i++) {
  952. struct temp_sensor_registers *tsr;
  953. struct temp_sensor_regval *rval;
  954. rval = &bgp->regval[i];
  955. tsr = bgp->conf->sensors[i].registers;
  956. if (TI_BANDGAP_HAS(bgp, MODE_CONFIG))
  957. rval->bg_mode_ctrl = ti_bandgap_readl(bgp,
  958. tsr->bgap_mode_ctrl);
  959. if (TI_BANDGAP_HAS(bgp, COUNTER))
  960. rval->bg_counter = ti_bandgap_readl(bgp,
  961. tsr->bgap_counter);
  962. if (TI_BANDGAP_HAS(bgp, TALERT)) {
  963. rval->bg_threshold = ti_bandgap_readl(bgp,
  964. tsr->bgap_threshold);
  965. rval->bg_ctrl = ti_bandgap_readl(bgp,
  966. tsr->bgap_mask_ctrl);
  967. }
  968. if (TI_BANDGAP_HAS(bgp, TSHUT_CONFIG))
  969. rval->tshut_threshold = ti_bandgap_readl(bgp,
  970. tsr->tshut_threshold);
  971. }
  972. return 0;
  973. }
  974. static int ti_bandgap_restore_ctxt(struct ti_bandgap *bgp)
  975. {
  976. int i;
  977. for (i = 0; i < bgp->conf->sensor_count; i++) {
  978. struct temp_sensor_registers *tsr;
  979. struct temp_sensor_regval *rval;
  980. rval = &bgp->regval[i];
  981. tsr = bgp->conf->sensors[i].registers;
  982. if (TI_BANDGAP_HAS(bgp, TSHUT_CONFIG))
  983. ti_bandgap_writel(bgp, rval->tshut_threshold,
  984. tsr->tshut_threshold);
  985. /* Force immediate temperature measurement and update
  986. * of the DTEMP field
  987. */
  988. ti_bandgap_force_single_read(bgp, i);
  989. if (TI_BANDGAP_HAS(bgp, COUNTER))
  990. ti_bandgap_writel(bgp, rval->bg_counter,
  991. tsr->bgap_counter);
  992. if (TI_BANDGAP_HAS(bgp, MODE_CONFIG))
  993. ti_bandgap_writel(bgp, rval->bg_mode_ctrl,
  994. tsr->bgap_mode_ctrl);
  995. if (TI_BANDGAP_HAS(bgp, TALERT)) {
  996. ti_bandgap_writel(bgp, rval->bg_threshold,
  997. tsr->bgap_threshold);
  998. ti_bandgap_writel(bgp, rval->bg_ctrl,
  999. tsr->bgap_mask_ctrl);
  1000. }
  1001. }
  1002. return 0;
  1003. }
  1004. static int ti_bandgap_suspend(struct device *dev)
  1005. {
  1006. struct ti_bandgap *bgp = dev_get_drvdata(dev);
  1007. int err;
  1008. err = ti_bandgap_save_ctxt(bgp);
  1009. ti_bandgap_power(bgp, false);
  1010. if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
  1011. clk_disable_unprepare(bgp->fclock);
  1012. bgp->is_suspended = true;
  1013. return err;
  1014. }
  1015. static int bandgap_omap_cpu_notifier(struct notifier_block *nb,
  1016. unsigned long cmd, void *v)
  1017. {
  1018. struct ti_bandgap *bgp;
  1019. bgp = container_of(nb, struct ti_bandgap, nb);
  1020. spin_lock(&bgp->lock);
  1021. switch (cmd) {
  1022. case CPU_CLUSTER_PM_ENTER:
  1023. if (bgp->is_suspended)
  1024. break;
  1025. ti_bandgap_save_ctxt(bgp);
  1026. ti_bandgap_power(bgp, false);
  1027. if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
  1028. clk_disable(bgp->fclock);
  1029. break;
  1030. case CPU_CLUSTER_PM_ENTER_FAILED:
  1031. case CPU_CLUSTER_PM_EXIT:
  1032. if (bgp->is_suspended)
  1033. break;
  1034. if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
  1035. clk_enable(bgp->fclock);
  1036. ti_bandgap_power(bgp, true);
  1037. ti_bandgap_restore_ctxt(bgp);
  1038. break;
  1039. }
  1040. spin_unlock(&bgp->lock);
  1041. return NOTIFY_OK;
  1042. }
  1043. static int ti_bandgap_resume(struct device *dev)
  1044. {
  1045. struct ti_bandgap *bgp = dev_get_drvdata(dev);
  1046. if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
  1047. clk_prepare_enable(bgp->fclock);
  1048. ti_bandgap_power(bgp, true);
  1049. bgp->is_suspended = false;
  1050. return ti_bandgap_restore_ctxt(bgp);
  1051. }
  1052. static SIMPLE_DEV_PM_OPS(ti_bandgap_dev_pm_ops, ti_bandgap_suspend,
  1053. ti_bandgap_resume);
  1054. #define DEV_PM_OPS (&ti_bandgap_dev_pm_ops)
  1055. #else
  1056. #define DEV_PM_OPS NULL
  1057. #endif
  1058. static const struct of_device_id of_ti_bandgap_match[] = {
  1059. #ifdef CONFIG_OMAP3_THERMAL
  1060. {
  1061. .compatible = "ti,omap34xx-bandgap",
  1062. .data = (void *)&omap34xx_data,
  1063. },
  1064. {
  1065. .compatible = "ti,omap36xx-bandgap",
  1066. .data = (void *)&omap36xx_data,
  1067. },
  1068. #endif
  1069. #ifdef CONFIG_OMAP4_THERMAL
  1070. {
  1071. .compatible = "ti,omap4430-bandgap",
  1072. .data = (void *)&omap4430_data,
  1073. },
  1074. {
  1075. .compatible = "ti,omap4460-bandgap",
  1076. .data = (void *)&omap4460_data,
  1077. },
  1078. {
  1079. .compatible = "ti,omap4470-bandgap",
  1080. .data = (void *)&omap4470_data,
  1081. },
  1082. #endif
  1083. #ifdef CONFIG_OMAP5_THERMAL
  1084. {
  1085. .compatible = "ti,omap5430-bandgap",
  1086. .data = (void *)&omap5430_data,
  1087. },
  1088. #endif
  1089. #ifdef CONFIG_DRA752_THERMAL
  1090. {
  1091. .compatible = "ti,dra752-bandgap",
  1092. .data = (void *)&dra752_data,
  1093. },
  1094. #endif
  1095. /* Sentinel */
  1096. { },
  1097. };
  1098. MODULE_DEVICE_TABLE(of, of_ti_bandgap_match);
  1099. static struct platform_driver ti_bandgap_sensor_driver = {
  1100. .probe = ti_bandgap_probe,
  1101. .remove = ti_bandgap_remove,
  1102. .driver = {
  1103. .name = "ti-soc-thermal",
  1104. .pm = DEV_PM_OPS,
  1105. .of_match_table = of_ti_bandgap_match,
  1106. },
  1107. };
  1108. module_platform_driver(ti_bandgap_sensor_driver);
  1109. MODULE_DESCRIPTION("OMAP4+ bandgap temperature sensor driver");
  1110. MODULE_LICENSE("GPL v2");
  1111. MODULE_ALIAS("platform:ti-soc-thermal");
  1112. MODULE_AUTHOR("Texas Instrument Inc.");