ti-bandgap.c 32 KB

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