ab8500_btemp.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2012
  3. *
  4. * Battery temperature driver for AB8500
  5. *
  6. * License Terms: GNU General Public License v2
  7. * Author:
  8. * Johan Palsson <johan.palsson@stericsson.com>
  9. * Karl Komierowski <karl.komierowski@stericsson.com>
  10. * Arun R Murthy <arun.murthy@stericsson.com>
  11. */
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/device.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/delay.h>
  17. #include <linux/slab.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/power_supply.h>
  20. #include <linux/completion.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/jiffies.h>
  23. #include <linux/of.h>
  24. #include <linux/mfd/core.h>
  25. #include <linux/mfd/abx500.h>
  26. #include <linux/mfd/abx500/ab8500.h>
  27. #include <linux/mfd/abx500/ab8500-bm.h>
  28. #include <linux/mfd/abx500/ab8500-gpadc.h>
  29. #define VTVOUT_V 1800
  30. #define BTEMP_THERMAL_LOW_LIMIT -10
  31. #define BTEMP_THERMAL_MED_LIMIT 0
  32. #define BTEMP_THERMAL_HIGH_LIMIT_52 52
  33. #define BTEMP_THERMAL_HIGH_LIMIT_57 57
  34. #define BTEMP_THERMAL_HIGH_LIMIT_62 62
  35. #define BTEMP_BATCTRL_CURR_SRC_7UA 7
  36. #define BTEMP_BATCTRL_CURR_SRC_20UA 20
  37. #define BTEMP_BATCTRL_CURR_SRC_16UA 16
  38. #define BTEMP_BATCTRL_CURR_SRC_18UA 18
  39. #define BTEMP_BATCTRL_CURR_SRC_60UA 60
  40. #define BTEMP_BATCTRL_CURR_SRC_120UA 120
  41. #define to_ab8500_btemp_device_info(x) container_of((x), \
  42. struct ab8500_btemp, btemp_psy);
  43. /**
  44. * struct ab8500_btemp_interrupts - ab8500 interrupts
  45. * @name: name of the interrupt
  46. * @isr function pointer to the isr
  47. */
  48. struct ab8500_btemp_interrupts {
  49. char *name;
  50. irqreturn_t (*isr)(int irq, void *data);
  51. };
  52. struct ab8500_btemp_events {
  53. bool batt_rem;
  54. bool btemp_high;
  55. bool btemp_medhigh;
  56. bool btemp_lowmed;
  57. bool btemp_low;
  58. bool ac_conn;
  59. bool usb_conn;
  60. };
  61. struct ab8500_btemp_ranges {
  62. int btemp_high_limit;
  63. int btemp_med_limit;
  64. int btemp_low_limit;
  65. };
  66. /**
  67. * struct ab8500_btemp - ab8500 BTEMP device information
  68. * @dev: Pointer to the structure device
  69. * @node: List of AB8500 BTEMPs, hence prepared for reentrance
  70. * @curr_source: What current source we use, in uA
  71. * @bat_temp: Dispatched battery temperature in degree Celcius
  72. * @prev_bat_temp Last measured battery temperature in degree Celcius
  73. * @parent: Pointer to the struct ab8500
  74. * @gpadc: Pointer to the struct gpadc
  75. * @fg: Pointer to the struct fg
  76. * @bm: Platform specific battery management information
  77. * @btemp_psy: Structure for BTEMP specific battery properties
  78. * @events: Structure for information about events triggered
  79. * @btemp_ranges: Battery temperature range structure
  80. * @btemp_wq: Work queue for measuring the temperature periodically
  81. * @btemp_periodic_work: Work for measuring the temperature periodically
  82. * @initialized: True if battery id read.
  83. */
  84. struct ab8500_btemp {
  85. struct device *dev;
  86. struct list_head node;
  87. int curr_source;
  88. int bat_temp;
  89. int prev_bat_temp;
  90. struct ab8500 *parent;
  91. struct ab8500_gpadc *gpadc;
  92. struct ab8500_fg *fg;
  93. struct abx500_bm_data *bm;
  94. struct power_supply btemp_psy;
  95. struct ab8500_btemp_events events;
  96. struct ab8500_btemp_ranges btemp_ranges;
  97. struct workqueue_struct *btemp_wq;
  98. struct delayed_work btemp_periodic_work;
  99. bool initialized;
  100. };
  101. /* BTEMP power supply properties */
  102. static enum power_supply_property ab8500_btemp_props[] = {
  103. POWER_SUPPLY_PROP_PRESENT,
  104. POWER_SUPPLY_PROP_ONLINE,
  105. POWER_SUPPLY_PROP_TECHNOLOGY,
  106. POWER_SUPPLY_PROP_TEMP,
  107. };
  108. static LIST_HEAD(ab8500_btemp_list);
  109. /**
  110. * ab8500_btemp_get() - returns a reference to the primary AB8500 BTEMP
  111. * (i.e. the first BTEMP in the instance list)
  112. */
  113. struct ab8500_btemp *ab8500_btemp_get(void)
  114. {
  115. struct ab8500_btemp *btemp;
  116. btemp = list_first_entry(&ab8500_btemp_list, struct ab8500_btemp, node);
  117. return btemp;
  118. }
  119. EXPORT_SYMBOL(ab8500_btemp_get);
  120. /**
  121. * ab8500_btemp_batctrl_volt_to_res() - convert batctrl voltage to resistance
  122. * @di: pointer to the ab8500_btemp structure
  123. * @v_batctrl: measured batctrl voltage
  124. * @inst_curr: measured instant current
  125. *
  126. * This function returns the battery resistance that is
  127. * derived from the BATCTRL voltage.
  128. * Returns value in Ohms.
  129. */
  130. static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di,
  131. int v_batctrl, int inst_curr)
  132. {
  133. int rbs;
  134. if (is_ab8500_1p1_or_earlier(di->parent)) {
  135. /*
  136. * For ABB cut1.0 and 1.1 BAT_CTRL is internally
  137. * connected to 1.8V through a 450k resistor
  138. */
  139. return (450000 * (v_batctrl)) / (1800 - v_batctrl);
  140. }
  141. if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL) {
  142. /*
  143. * If the battery has internal NTC, we use the current
  144. * source to calculate the resistance.
  145. */
  146. rbs = (v_batctrl * 1000
  147. - di->bm->gnd_lift_resistance * inst_curr)
  148. / di->curr_source;
  149. } else {
  150. /*
  151. * BAT_CTRL is internally
  152. * connected to 1.8V through a 80k resistor
  153. */
  154. rbs = (80000 * (v_batctrl)) / (1800 - v_batctrl);
  155. }
  156. return rbs;
  157. }
  158. /**
  159. * ab8500_btemp_read_batctrl_voltage() - measure batctrl voltage
  160. * @di: pointer to the ab8500_btemp structure
  161. *
  162. * This function returns the voltage on BATCTRL. Returns value in mV.
  163. */
  164. static int ab8500_btemp_read_batctrl_voltage(struct ab8500_btemp *di)
  165. {
  166. int vbtemp;
  167. static int prev;
  168. vbtemp = ab8500_gpadc_convert(di->gpadc, BAT_CTRL);
  169. if (vbtemp < 0) {
  170. dev_err(di->dev,
  171. "%s gpadc conversion failed, using previous value",
  172. __func__);
  173. return prev;
  174. }
  175. prev = vbtemp;
  176. return vbtemp;
  177. }
  178. /**
  179. * ab8500_btemp_curr_source_enable() - enable/disable batctrl current source
  180. * @di: pointer to the ab8500_btemp structure
  181. * @enable: enable or disable the current source
  182. *
  183. * Enable or disable the current sources for the BatCtrl AD channel
  184. */
  185. static int ab8500_btemp_curr_source_enable(struct ab8500_btemp *di,
  186. bool enable)
  187. {
  188. int curr;
  189. int ret = 0;
  190. /*
  191. * BATCTRL current sources are included on AB8500 cut2.0
  192. * and future versions
  193. */
  194. if (is_ab8500_1p1_or_earlier(di->parent))
  195. return 0;
  196. /* Only do this for batteries with internal NTC */
  197. if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL && enable) {
  198. if (is_ab8540(di->parent)) {
  199. if (di->curr_source == BTEMP_BATCTRL_CURR_SRC_60UA)
  200. curr = BAT_CTRL_60U_ENA;
  201. else
  202. curr = BAT_CTRL_120U_ENA;
  203. } else if (is_ab9540(di->parent) || is_ab8505(di->parent)) {
  204. if (di->curr_source == BTEMP_BATCTRL_CURR_SRC_16UA)
  205. curr = BAT_CTRL_16U_ENA;
  206. else
  207. curr = BAT_CTRL_18U_ENA;
  208. } else {
  209. if (di->curr_source == BTEMP_BATCTRL_CURR_SRC_7UA)
  210. curr = BAT_CTRL_7U_ENA;
  211. else
  212. curr = BAT_CTRL_20U_ENA;
  213. }
  214. dev_dbg(di->dev, "Set BATCTRL %duA\n", di->curr_source);
  215. ret = abx500_mask_and_set_register_interruptible(di->dev,
  216. AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
  217. FORCE_BAT_CTRL_CMP_HIGH, FORCE_BAT_CTRL_CMP_HIGH);
  218. if (ret) {
  219. dev_err(di->dev, "%s failed setting cmp_force\n",
  220. __func__);
  221. return ret;
  222. }
  223. /*
  224. * We have to wait one 32kHz cycle before enabling
  225. * the current source, since ForceBatCtrlCmpHigh needs
  226. * to be written in a separate cycle
  227. */
  228. udelay(32);
  229. ret = abx500_set_register_interruptible(di->dev,
  230. AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
  231. FORCE_BAT_CTRL_CMP_HIGH | curr);
  232. if (ret) {
  233. dev_err(di->dev, "%s failed enabling current source\n",
  234. __func__);
  235. goto disable_curr_source;
  236. }
  237. } else if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL && !enable) {
  238. dev_dbg(di->dev, "Disable BATCTRL curr source\n");
  239. if (is_ab8540(di->parent)) {
  240. /* Write 0 to the curr bits */
  241. ret = abx500_mask_and_set_register_interruptible(
  242. di->dev,
  243. AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
  244. BAT_CTRL_60U_ENA | BAT_CTRL_120U_ENA,
  245. ~(BAT_CTRL_60U_ENA | BAT_CTRL_120U_ENA));
  246. } else if (is_ab9540(di->parent) || is_ab8505(di->parent)) {
  247. /* Write 0 to the curr bits */
  248. ret = abx500_mask_and_set_register_interruptible(
  249. di->dev,
  250. AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
  251. BAT_CTRL_16U_ENA | BAT_CTRL_18U_ENA,
  252. ~(BAT_CTRL_16U_ENA | BAT_CTRL_18U_ENA));
  253. } else {
  254. /* Write 0 to the curr bits */
  255. ret = abx500_mask_and_set_register_interruptible(
  256. di->dev,
  257. AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
  258. BAT_CTRL_7U_ENA | BAT_CTRL_20U_ENA,
  259. ~(BAT_CTRL_7U_ENA | BAT_CTRL_20U_ENA));
  260. }
  261. if (ret) {
  262. dev_err(di->dev, "%s failed disabling current source\n",
  263. __func__);
  264. goto disable_curr_source;
  265. }
  266. /* Enable Pull-Up and comparator */
  267. ret = abx500_mask_and_set_register_interruptible(di->dev,
  268. AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
  269. BAT_CTRL_PULL_UP_ENA | BAT_CTRL_CMP_ENA,
  270. BAT_CTRL_PULL_UP_ENA | BAT_CTRL_CMP_ENA);
  271. if (ret) {
  272. dev_err(di->dev, "%s failed enabling PU and comp\n",
  273. __func__);
  274. goto enable_pu_comp;
  275. }
  276. /*
  277. * We have to wait one 32kHz cycle before disabling
  278. * ForceBatCtrlCmpHigh since this needs to be written
  279. * in a separate cycle
  280. */
  281. udelay(32);
  282. /* Disable 'force comparator' */
  283. ret = abx500_mask_and_set_register_interruptible(di->dev,
  284. AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
  285. FORCE_BAT_CTRL_CMP_HIGH, ~FORCE_BAT_CTRL_CMP_HIGH);
  286. if (ret) {
  287. dev_err(di->dev, "%s failed disabling force comp\n",
  288. __func__);
  289. goto disable_force_comp;
  290. }
  291. }
  292. return ret;
  293. /*
  294. * We have to try unsetting FORCE_BAT_CTRL_CMP_HIGH one more time
  295. * if we got an error above
  296. */
  297. disable_curr_source:
  298. if (is_ab8540(di->parent)) {
  299. /* Write 0 to the curr bits */
  300. ret = abx500_mask_and_set_register_interruptible(di->dev,
  301. AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
  302. BAT_CTRL_60U_ENA | BAT_CTRL_120U_ENA,
  303. ~(BAT_CTRL_60U_ENA | BAT_CTRL_120U_ENA));
  304. } else if (is_ab9540(di->parent) || is_ab8505(di->parent)) {
  305. /* Write 0 to the curr bits */
  306. ret = abx500_mask_and_set_register_interruptible(di->dev,
  307. AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
  308. BAT_CTRL_16U_ENA | BAT_CTRL_18U_ENA,
  309. ~(BAT_CTRL_16U_ENA | BAT_CTRL_18U_ENA));
  310. } else {
  311. /* Write 0 to the curr bits */
  312. ret = abx500_mask_and_set_register_interruptible(di->dev,
  313. AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
  314. BAT_CTRL_7U_ENA | BAT_CTRL_20U_ENA,
  315. ~(BAT_CTRL_7U_ENA | BAT_CTRL_20U_ENA));
  316. }
  317. if (ret) {
  318. dev_err(di->dev, "%s failed disabling current source\n",
  319. __func__);
  320. return ret;
  321. }
  322. enable_pu_comp:
  323. /* Enable Pull-Up and comparator */
  324. ret = abx500_mask_and_set_register_interruptible(di->dev,
  325. AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
  326. BAT_CTRL_PULL_UP_ENA | BAT_CTRL_CMP_ENA,
  327. BAT_CTRL_PULL_UP_ENA | BAT_CTRL_CMP_ENA);
  328. if (ret) {
  329. dev_err(di->dev, "%s failed enabling PU and comp\n",
  330. __func__);
  331. return ret;
  332. }
  333. disable_force_comp:
  334. /*
  335. * We have to wait one 32kHz cycle before disabling
  336. * ForceBatCtrlCmpHigh since this needs to be written
  337. * in a separate cycle
  338. */
  339. udelay(32);
  340. /* Disable 'force comparator' */
  341. ret = abx500_mask_and_set_register_interruptible(di->dev,
  342. AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE,
  343. FORCE_BAT_CTRL_CMP_HIGH, ~FORCE_BAT_CTRL_CMP_HIGH);
  344. if (ret) {
  345. dev_err(di->dev, "%s failed disabling force comp\n",
  346. __func__);
  347. return ret;
  348. }
  349. return ret;
  350. }
  351. /**
  352. * ab8500_btemp_get_batctrl_res() - get battery resistance
  353. * @di: pointer to the ab8500_btemp structure
  354. *
  355. * This function returns the battery pack identification resistance.
  356. * Returns value in Ohms.
  357. */
  358. static int ab8500_btemp_get_batctrl_res(struct ab8500_btemp *di)
  359. {
  360. int ret;
  361. int batctrl = 0;
  362. int res;
  363. int inst_curr;
  364. int i;
  365. /*
  366. * BATCTRL current sources are included on AB8500 cut2.0
  367. * and future versions
  368. */
  369. ret = ab8500_btemp_curr_source_enable(di, true);
  370. if (ret) {
  371. dev_err(di->dev, "%s curr source enabled failed\n", __func__);
  372. return ret;
  373. }
  374. if (!di->fg)
  375. di->fg = ab8500_fg_get();
  376. if (!di->fg) {
  377. dev_err(di->dev, "No fg found\n");
  378. return -EINVAL;
  379. }
  380. ret = ab8500_fg_inst_curr_start(di->fg);
  381. if (ret) {
  382. dev_err(di->dev, "Failed to start current measurement\n");
  383. return ret;
  384. }
  385. do {
  386. msleep(20);
  387. } while (!ab8500_fg_inst_curr_started(di->fg));
  388. i = 0;
  389. do {
  390. batctrl += ab8500_btemp_read_batctrl_voltage(di);
  391. i++;
  392. msleep(20);
  393. } while (!ab8500_fg_inst_curr_done(di->fg));
  394. batctrl /= i;
  395. ret = ab8500_fg_inst_curr_finalize(di->fg, &inst_curr);
  396. if (ret) {
  397. dev_err(di->dev, "Failed to finalize current measurement\n");
  398. return ret;
  399. }
  400. res = ab8500_btemp_batctrl_volt_to_res(di, batctrl, inst_curr);
  401. ret = ab8500_btemp_curr_source_enable(di, false);
  402. if (ret) {
  403. dev_err(di->dev, "%s curr source disable failed\n", __func__);
  404. return ret;
  405. }
  406. dev_dbg(di->dev, "%s batctrl: %d res: %d inst_curr: %d samples: %d\n",
  407. __func__, batctrl, res, inst_curr, i);
  408. return res;
  409. }
  410. /**
  411. * ab8500_btemp_res_to_temp() - resistance to temperature
  412. * @di: pointer to the ab8500_btemp structure
  413. * @tbl: pointer to the resiatance to temperature table
  414. * @tbl_size: size of the resistance to temperature table
  415. * @res: resistance to calculate the temperature from
  416. *
  417. * This function returns the battery temperature in degrees Celcius
  418. * based on the NTC resistance.
  419. */
  420. static int ab8500_btemp_res_to_temp(struct ab8500_btemp *di,
  421. const struct abx500_res_to_temp *tbl, int tbl_size, int res)
  422. {
  423. int i, temp;
  424. /*
  425. * Calculate the formula for the straight line
  426. * Simple interpolation if we are within
  427. * the resistance table limits, extrapolate
  428. * if resistance is outside the limits.
  429. */
  430. if (res > tbl[0].resist)
  431. i = 0;
  432. else if (res <= tbl[tbl_size - 1].resist)
  433. i = tbl_size - 2;
  434. else {
  435. i = 0;
  436. while (!(res <= tbl[i].resist &&
  437. res > tbl[i + 1].resist))
  438. i++;
  439. }
  440. temp = tbl[i].temp + ((tbl[i + 1].temp - tbl[i].temp) *
  441. (res - tbl[i].resist)) / (tbl[i + 1].resist - tbl[i].resist);
  442. return temp;
  443. }
  444. /**
  445. * ab8500_btemp_measure_temp() - measure battery temperature
  446. * @di: pointer to the ab8500_btemp structure
  447. *
  448. * Returns battery temperature (on success) else the previous temperature
  449. */
  450. static int ab8500_btemp_measure_temp(struct ab8500_btemp *di)
  451. {
  452. int temp;
  453. static int prev;
  454. int rbat, rntc, vntc;
  455. u8 id;
  456. id = di->bm->batt_id;
  457. if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL &&
  458. id != BATTERY_UNKNOWN) {
  459. rbat = ab8500_btemp_get_batctrl_res(di);
  460. if (rbat < 0) {
  461. dev_err(di->dev, "%s get batctrl res failed\n",
  462. __func__);
  463. /*
  464. * Return out-of-range temperature so that
  465. * charging is stopped
  466. */
  467. return BTEMP_THERMAL_LOW_LIMIT;
  468. }
  469. temp = ab8500_btemp_res_to_temp(di,
  470. di->bm->bat_type[id].r_to_t_tbl,
  471. di->bm->bat_type[id].n_temp_tbl_elements, rbat);
  472. } else {
  473. vntc = ab8500_gpadc_convert(di->gpadc, BTEMP_BALL);
  474. if (vntc < 0) {
  475. dev_err(di->dev,
  476. "%s gpadc conversion failed,"
  477. " using previous value\n", __func__);
  478. return prev;
  479. }
  480. /*
  481. * The PCB NTC is sourced from VTVOUT via a 230kOhm
  482. * resistor.
  483. */
  484. rntc = 230000 * vntc / (VTVOUT_V - vntc);
  485. temp = ab8500_btemp_res_to_temp(di,
  486. di->bm->bat_type[id].r_to_t_tbl,
  487. di->bm->bat_type[id].n_temp_tbl_elements, rntc);
  488. prev = temp;
  489. }
  490. dev_dbg(di->dev, "Battery temperature is %d\n", temp);
  491. return temp;
  492. }
  493. /**
  494. * ab8500_btemp_id() - Identify the connected battery
  495. * @di: pointer to the ab8500_btemp structure
  496. *
  497. * This function will try to identify the battery by reading the ID
  498. * resistor. Some brands use a combined ID resistor with a NTC resistor to
  499. * both be able to identify and to read the temperature of it.
  500. */
  501. static int ab8500_btemp_id(struct ab8500_btemp *di)
  502. {
  503. int res;
  504. u8 i;
  505. if (is_ab8540(di->parent))
  506. di->curr_source = BTEMP_BATCTRL_CURR_SRC_60UA;
  507. else if (is_ab9540(di->parent) || is_ab8505(di->parent))
  508. di->curr_source = BTEMP_BATCTRL_CURR_SRC_16UA;
  509. else
  510. di->curr_source = BTEMP_BATCTRL_CURR_SRC_7UA;
  511. di->bm->batt_id = BATTERY_UNKNOWN;
  512. res = ab8500_btemp_get_batctrl_res(di);
  513. if (res < 0) {
  514. dev_err(di->dev, "%s get batctrl res failed\n", __func__);
  515. return -ENXIO;
  516. }
  517. /* BATTERY_UNKNOWN is defined on position 0, skip it! */
  518. for (i = BATTERY_UNKNOWN + 1; i < di->bm->n_btypes; i++) {
  519. if ((res <= di->bm->bat_type[i].resis_high) &&
  520. (res >= di->bm->bat_type[i].resis_low)) {
  521. dev_dbg(di->dev, "Battery detected on %s"
  522. " low %d < res %d < high: %d"
  523. " index: %d\n",
  524. di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL ?
  525. "BATCTRL" : "BATTEMP",
  526. di->bm->bat_type[i].resis_low, res,
  527. di->bm->bat_type[i].resis_high, i);
  528. di->bm->batt_id = i;
  529. break;
  530. }
  531. }
  532. if (di->bm->batt_id == BATTERY_UNKNOWN) {
  533. dev_warn(di->dev, "Battery identified as unknown"
  534. ", resistance %d Ohm\n", res);
  535. return -ENXIO;
  536. }
  537. /*
  538. * We only have to change current source if the
  539. * detected type is Type 1.
  540. */
  541. if (di->bm->adc_therm == ABx500_ADC_THERM_BATCTRL &&
  542. di->bm->batt_id == 1) {
  543. if (is_ab8540(di->parent)) {
  544. dev_dbg(di->dev,
  545. "Set BATCTRL current source to 60uA\n");
  546. di->curr_source = BTEMP_BATCTRL_CURR_SRC_60UA;
  547. } else if (is_ab9540(di->parent) || is_ab8505(di->parent)) {
  548. dev_dbg(di->dev,
  549. "Set BATCTRL current source to 16uA\n");
  550. di->curr_source = BTEMP_BATCTRL_CURR_SRC_16UA;
  551. } else {
  552. dev_dbg(di->dev, "Set BATCTRL current source to 20uA\n");
  553. di->curr_source = BTEMP_BATCTRL_CURR_SRC_20UA;
  554. }
  555. }
  556. return di->bm->batt_id;
  557. }
  558. /**
  559. * ab8500_btemp_periodic_work() - Measuring the temperature periodically
  560. * @work: pointer to the work_struct structure
  561. *
  562. * Work function for measuring the temperature periodically
  563. */
  564. static void ab8500_btemp_periodic_work(struct work_struct *work)
  565. {
  566. int interval;
  567. int bat_temp;
  568. struct ab8500_btemp *di = container_of(work,
  569. struct ab8500_btemp, btemp_periodic_work.work);
  570. if (!di->initialized) {
  571. /* Identify the battery */
  572. if (ab8500_btemp_id(di) < 0)
  573. dev_warn(di->dev, "failed to identify the battery\n");
  574. }
  575. bat_temp = ab8500_btemp_measure_temp(di);
  576. /*
  577. * Filter battery temperature.
  578. * Allow direct updates on temperature only if two samples result in
  579. * same temperature. Else only allow 1 degree change from previous
  580. * reported value in the direction of the new measurement.
  581. */
  582. if ((bat_temp == di->prev_bat_temp) || !di->initialized) {
  583. if ((di->bat_temp != di->prev_bat_temp) || !di->initialized) {
  584. di->initialized = true;
  585. di->bat_temp = bat_temp;
  586. power_supply_changed(&di->btemp_psy);
  587. }
  588. } else if (bat_temp < di->prev_bat_temp) {
  589. di->bat_temp--;
  590. power_supply_changed(&di->btemp_psy);
  591. } else if (bat_temp > di->prev_bat_temp) {
  592. di->bat_temp++;
  593. power_supply_changed(&di->btemp_psy);
  594. }
  595. di->prev_bat_temp = bat_temp;
  596. if (di->events.ac_conn || di->events.usb_conn)
  597. interval = di->bm->temp_interval_chg;
  598. else
  599. interval = di->bm->temp_interval_nochg;
  600. /* Schedule a new measurement */
  601. queue_delayed_work(di->btemp_wq,
  602. &di->btemp_periodic_work,
  603. round_jiffies(interval * HZ));
  604. }
  605. /**
  606. * ab8500_btemp_batctrlindb_handler() - battery removal detected
  607. * @irq: interrupt number
  608. * @_di: void pointer that has to address of ab8500_btemp
  609. *
  610. * Returns IRQ status(IRQ_HANDLED)
  611. */
  612. static irqreturn_t ab8500_btemp_batctrlindb_handler(int irq, void *_di)
  613. {
  614. struct ab8500_btemp *di = _di;
  615. dev_err(di->dev, "Battery removal detected!\n");
  616. di->events.batt_rem = true;
  617. power_supply_changed(&di->btemp_psy);
  618. return IRQ_HANDLED;
  619. }
  620. /**
  621. * ab8500_btemp_templow_handler() - battery temp lower than 10 degrees
  622. * @irq: interrupt number
  623. * @_di: void pointer that has to address of ab8500_btemp
  624. *
  625. * Returns IRQ status(IRQ_HANDLED)
  626. */
  627. static irqreturn_t ab8500_btemp_templow_handler(int irq, void *_di)
  628. {
  629. struct ab8500_btemp *di = _di;
  630. if (is_ab8500_3p3_or_earlier(di->parent)) {
  631. dev_dbg(di->dev, "Ignore false btemp low irq"
  632. " for ABB cut 1.0, 1.1, 2.0 and 3.3\n");
  633. } else {
  634. dev_crit(di->dev, "Battery temperature lower than -10deg c\n");
  635. di->events.btemp_low = true;
  636. di->events.btemp_high = false;
  637. di->events.btemp_medhigh = false;
  638. di->events.btemp_lowmed = false;
  639. power_supply_changed(&di->btemp_psy);
  640. }
  641. return IRQ_HANDLED;
  642. }
  643. /**
  644. * ab8500_btemp_temphigh_handler() - battery temp higher than max temp
  645. * @irq: interrupt number
  646. * @_di: void pointer that has to address of ab8500_btemp
  647. *
  648. * Returns IRQ status(IRQ_HANDLED)
  649. */
  650. static irqreturn_t ab8500_btemp_temphigh_handler(int irq, void *_di)
  651. {
  652. struct ab8500_btemp *di = _di;
  653. dev_crit(di->dev, "Battery temperature is higher than MAX temp\n");
  654. di->events.btemp_high = true;
  655. di->events.btemp_medhigh = false;
  656. di->events.btemp_lowmed = false;
  657. di->events.btemp_low = false;
  658. power_supply_changed(&di->btemp_psy);
  659. return IRQ_HANDLED;
  660. }
  661. /**
  662. * ab8500_btemp_lowmed_handler() - battery temp between low and medium
  663. * @irq: interrupt number
  664. * @_di: void pointer that has to address of ab8500_btemp
  665. *
  666. * Returns IRQ status(IRQ_HANDLED)
  667. */
  668. static irqreturn_t ab8500_btemp_lowmed_handler(int irq, void *_di)
  669. {
  670. struct ab8500_btemp *di = _di;
  671. dev_dbg(di->dev, "Battery temperature is between low and medium\n");
  672. di->events.btemp_lowmed = true;
  673. di->events.btemp_medhigh = false;
  674. di->events.btemp_high = false;
  675. di->events.btemp_low = false;
  676. power_supply_changed(&di->btemp_psy);
  677. return IRQ_HANDLED;
  678. }
  679. /**
  680. * ab8500_btemp_medhigh_handler() - battery temp between medium and high
  681. * @irq: interrupt number
  682. * @_di: void pointer that has to address of ab8500_btemp
  683. *
  684. * Returns IRQ status(IRQ_HANDLED)
  685. */
  686. static irqreturn_t ab8500_btemp_medhigh_handler(int irq, void *_di)
  687. {
  688. struct ab8500_btemp *di = _di;
  689. dev_dbg(di->dev, "Battery temperature is between medium and high\n");
  690. di->events.btemp_medhigh = true;
  691. di->events.btemp_lowmed = false;
  692. di->events.btemp_high = false;
  693. di->events.btemp_low = false;
  694. power_supply_changed(&di->btemp_psy);
  695. return IRQ_HANDLED;
  696. }
  697. /**
  698. * ab8500_btemp_periodic() - Periodic temperature measurements
  699. * @di: pointer to the ab8500_btemp structure
  700. * @enable: enable or disable periodic temperature measurements
  701. *
  702. * Starts of stops periodic temperature measurements. Periodic measurements
  703. * should only be done when a charger is connected.
  704. */
  705. static void ab8500_btemp_periodic(struct ab8500_btemp *di,
  706. bool enable)
  707. {
  708. dev_dbg(di->dev, "Enable periodic temperature measurements: %d\n",
  709. enable);
  710. /*
  711. * Make sure a new measurement is done directly by cancelling
  712. * any pending work
  713. */
  714. cancel_delayed_work_sync(&di->btemp_periodic_work);
  715. if (enable)
  716. queue_delayed_work(di->btemp_wq, &di->btemp_periodic_work, 0);
  717. }
  718. /**
  719. * ab8500_btemp_get_temp() - get battery temperature
  720. * @di: pointer to the ab8500_btemp structure
  721. *
  722. * Returns battery temperature
  723. */
  724. int ab8500_btemp_get_temp(struct ab8500_btemp *di)
  725. {
  726. int temp = 0;
  727. /*
  728. * The BTEMP events are not reliabe on AB8500 cut3.3
  729. * and prior versions
  730. */
  731. if (is_ab8500_3p3_or_earlier(di->parent)) {
  732. temp = di->bat_temp * 10;
  733. } else {
  734. if (di->events.btemp_low) {
  735. if (temp > di->btemp_ranges.btemp_low_limit)
  736. temp = di->btemp_ranges.btemp_low_limit * 10;
  737. else
  738. temp = di->bat_temp * 10;
  739. } else if (di->events.btemp_high) {
  740. if (temp < di->btemp_ranges.btemp_high_limit)
  741. temp = di->btemp_ranges.btemp_high_limit * 10;
  742. else
  743. temp = di->bat_temp * 10;
  744. } else if (di->events.btemp_lowmed) {
  745. if (temp > di->btemp_ranges.btemp_med_limit)
  746. temp = di->btemp_ranges.btemp_med_limit * 10;
  747. else
  748. temp = di->bat_temp * 10;
  749. } else if (di->events.btemp_medhigh) {
  750. if (temp < di->btemp_ranges.btemp_med_limit)
  751. temp = di->btemp_ranges.btemp_med_limit * 10;
  752. else
  753. temp = di->bat_temp * 10;
  754. } else
  755. temp = di->bat_temp * 10;
  756. }
  757. return temp;
  758. }
  759. EXPORT_SYMBOL(ab8500_btemp_get_temp);
  760. /**
  761. * ab8500_btemp_get_batctrl_temp() - get the temperature
  762. * @btemp: pointer to the btemp structure
  763. *
  764. * Returns the batctrl temperature in millidegrees
  765. */
  766. int ab8500_btemp_get_batctrl_temp(struct ab8500_btemp *btemp)
  767. {
  768. return btemp->bat_temp * 1000;
  769. }
  770. EXPORT_SYMBOL(ab8500_btemp_get_batctrl_temp);
  771. /**
  772. * ab8500_btemp_get_property() - get the btemp properties
  773. * @psy: pointer to the power_supply structure
  774. * @psp: pointer to the power_supply_property structure
  775. * @val: pointer to the power_supply_propval union
  776. *
  777. * This function gets called when an application tries to get the btemp
  778. * properties by reading the sysfs files.
  779. * online: presence of the battery
  780. * present: presence of the battery
  781. * technology: battery technology
  782. * temp: battery temperature
  783. * Returns error code in case of failure else 0(on success)
  784. */
  785. static int ab8500_btemp_get_property(struct power_supply *psy,
  786. enum power_supply_property psp,
  787. union power_supply_propval *val)
  788. {
  789. struct ab8500_btemp *di;
  790. di = to_ab8500_btemp_device_info(psy);
  791. switch (psp) {
  792. case POWER_SUPPLY_PROP_PRESENT:
  793. case POWER_SUPPLY_PROP_ONLINE:
  794. if (di->events.batt_rem)
  795. val->intval = 0;
  796. else
  797. val->intval = 1;
  798. break;
  799. case POWER_SUPPLY_PROP_TECHNOLOGY:
  800. val->intval = di->bm->bat_type[di->bm->batt_id].name;
  801. break;
  802. case POWER_SUPPLY_PROP_TEMP:
  803. val->intval = ab8500_btemp_get_temp(di);
  804. break;
  805. default:
  806. return -EINVAL;
  807. }
  808. return 0;
  809. }
  810. static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)
  811. {
  812. struct power_supply *psy;
  813. struct power_supply *ext;
  814. struct ab8500_btemp *di;
  815. union power_supply_propval ret;
  816. int i, j;
  817. bool psy_found = false;
  818. psy = (struct power_supply *)data;
  819. ext = dev_get_drvdata(dev);
  820. di = to_ab8500_btemp_device_info(psy);
  821. /*
  822. * For all psy where the name of your driver
  823. * appears in any supplied_to
  824. */
  825. for (i = 0; i < ext->num_supplicants; i++) {
  826. if (!strcmp(ext->supplied_to[i], psy->name))
  827. psy_found = true;
  828. }
  829. if (!psy_found)
  830. return 0;
  831. /* Go through all properties for the psy */
  832. for (j = 0; j < ext->num_properties; j++) {
  833. enum power_supply_property prop;
  834. prop = ext->properties[j];
  835. if (ext->get_property(ext, prop, &ret))
  836. continue;
  837. switch (prop) {
  838. case POWER_SUPPLY_PROP_PRESENT:
  839. switch (ext->type) {
  840. case POWER_SUPPLY_TYPE_MAINS:
  841. /* AC disconnected */
  842. if (!ret.intval && di->events.ac_conn) {
  843. di->events.ac_conn = false;
  844. }
  845. /* AC connected */
  846. else if (ret.intval && !di->events.ac_conn) {
  847. di->events.ac_conn = true;
  848. if (!di->events.usb_conn)
  849. ab8500_btemp_periodic(di, true);
  850. }
  851. break;
  852. case POWER_SUPPLY_TYPE_USB:
  853. /* USB disconnected */
  854. if (!ret.intval && di->events.usb_conn) {
  855. di->events.usb_conn = false;
  856. }
  857. /* USB connected */
  858. else if (ret.intval && !di->events.usb_conn) {
  859. di->events.usb_conn = true;
  860. if (!di->events.ac_conn)
  861. ab8500_btemp_periodic(di, true);
  862. }
  863. break;
  864. default:
  865. break;
  866. }
  867. break;
  868. default:
  869. break;
  870. }
  871. }
  872. return 0;
  873. }
  874. /**
  875. * ab8500_btemp_external_power_changed() - callback for power supply changes
  876. * @psy: pointer to the structure power_supply
  877. *
  878. * This function is pointing to the function pointer external_power_changed
  879. * of the structure power_supply.
  880. * This function gets executed when there is a change in the external power
  881. * supply to the btemp.
  882. */
  883. static void ab8500_btemp_external_power_changed(struct power_supply *psy)
  884. {
  885. struct ab8500_btemp *di = to_ab8500_btemp_device_info(psy);
  886. class_for_each_device(power_supply_class, NULL,
  887. &di->btemp_psy, ab8500_btemp_get_ext_psy_data);
  888. }
  889. /* ab8500 btemp driver interrupts and their respective isr */
  890. static struct ab8500_btemp_interrupts ab8500_btemp_irq[] = {
  891. {"BAT_CTRL_INDB", ab8500_btemp_batctrlindb_handler},
  892. {"BTEMP_LOW", ab8500_btemp_templow_handler},
  893. {"BTEMP_HIGH", ab8500_btemp_temphigh_handler},
  894. {"BTEMP_LOW_MEDIUM", ab8500_btemp_lowmed_handler},
  895. {"BTEMP_MEDIUM_HIGH", ab8500_btemp_medhigh_handler},
  896. };
  897. #if defined(CONFIG_PM)
  898. static int ab8500_btemp_resume(struct platform_device *pdev)
  899. {
  900. struct ab8500_btemp *di = platform_get_drvdata(pdev);
  901. ab8500_btemp_periodic(di, true);
  902. return 0;
  903. }
  904. static int ab8500_btemp_suspend(struct platform_device *pdev,
  905. pm_message_t state)
  906. {
  907. struct ab8500_btemp *di = platform_get_drvdata(pdev);
  908. ab8500_btemp_periodic(di, false);
  909. return 0;
  910. }
  911. #else
  912. #define ab8500_btemp_suspend NULL
  913. #define ab8500_btemp_resume NULL
  914. #endif
  915. static int ab8500_btemp_remove(struct platform_device *pdev)
  916. {
  917. struct ab8500_btemp *di = platform_get_drvdata(pdev);
  918. int i, irq;
  919. /* Disable interrupts */
  920. for (i = 0; i < ARRAY_SIZE(ab8500_btemp_irq); i++) {
  921. irq = platform_get_irq_byname(pdev, ab8500_btemp_irq[i].name);
  922. free_irq(irq, di);
  923. }
  924. /* Delete the work queue */
  925. destroy_workqueue(di->btemp_wq);
  926. flush_scheduled_work();
  927. power_supply_unregister(&di->btemp_psy);
  928. return 0;
  929. }
  930. static char *supply_interface[] = {
  931. "ab8500_chargalg",
  932. "ab8500_fg",
  933. };
  934. static int ab8500_btemp_probe(struct platform_device *pdev)
  935. {
  936. struct device_node *np = pdev->dev.of_node;
  937. struct abx500_bm_data *plat = pdev->dev.platform_data;
  938. struct ab8500_btemp *di;
  939. int irq, i, ret = 0;
  940. u8 val;
  941. di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
  942. if (!di) {
  943. dev_err(&pdev->dev, "%s no mem for ab8500_btemp\n", __func__);
  944. return -ENOMEM;
  945. }
  946. if (!plat) {
  947. dev_err(&pdev->dev, "no battery management data supplied\n");
  948. return -EINVAL;
  949. }
  950. di->bm = plat;
  951. if (np) {
  952. ret = ab8500_bm_of_probe(&pdev->dev, np, di->bm);
  953. if (ret) {
  954. dev_err(&pdev->dev, "failed to get battery information\n");
  955. return ret;
  956. }
  957. }
  958. /* get parent data */
  959. di->dev = &pdev->dev;
  960. di->parent = dev_get_drvdata(pdev->dev.parent);
  961. di->gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  962. di->initialized = false;
  963. /* BTEMP supply */
  964. di->btemp_psy.name = "ab8500_btemp";
  965. di->btemp_psy.type = POWER_SUPPLY_TYPE_BATTERY;
  966. di->btemp_psy.properties = ab8500_btemp_props;
  967. di->btemp_psy.num_properties = ARRAY_SIZE(ab8500_btemp_props);
  968. di->btemp_psy.get_property = ab8500_btemp_get_property;
  969. di->btemp_psy.supplied_to = supply_interface;
  970. di->btemp_psy.num_supplicants = ARRAY_SIZE(supply_interface);
  971. di->btemp_psy.external_power_changed =
  972. ab8500_btemp_external_power_changed;
  973. /* Create a work queue for the btemp */
  974. di->btemp_wq =
  975. create_singlethread_workqueue("ab8500_btemp_wq");
  976. if (di->btemp_wq == NULL) {
  977. dev_err(di->dev, "failed to create work queue\n");
  978. return -ENOMEM;
  979. }
  980. /* Init work for measuring temperature periodically */
  981. INIT_DEFERRABLE_WORK(&di->btemp_periodic_work,
  982. ab8500_btemp_periodic_work);
  983. /* Set BTEMP thermal limits. Low and Med are fixed */
  984. di->btemp_ranges.btemp_low_limit = BTEMP_THERMAL_LOW_LIMIT;
  985. di->btemp_ranges.btemp_med_limit = BTEMP_THERMAL_MED_LIMIT;
  986. ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
  987. AB8500_BTEMP_HIGH_TH, &val);
  988. if (ret < 0) {
  989. dev_err(di->dev, "%s ab8500 read failed\n", __func__);
  990. goto free_btemp_wq;
  991. }
  992. switch (val) {
  993. case BTEMP_HIGH_TH_57_0:
  994. case BTEMP_HIGH_TH_57_1:
  995. di->btemp_ranges.btemp_high_limit =
  996. BTEMP_THERMAL_HIGH_LIMIT_57;
  997. break;
  998. case BTEMP_HIGH_TH_52:
  999. di->btemp_ranges.btemp_high_limit =
  1000. BTEMP_THERMAL_HIGH_LIMIT_52;
  1001. break;
  1002. case BTEMP_HIGH_TH_62:
  1003. di->btemp_ranges.btemp_high_limit =
  1004. BTEMP_THERMAL_HIGH_LIMIT_62;
  1005. break;
  1006. }
  1007. /* Register BTEMP power supply class */
  1008. ret = power_supply_register(di->dev, &di->btemp_psy);
  1009. if (ret) {
  1010. dev_err(di->dev, "failed to register BTEMP psy\n");
  1011. goto free_btemp_wq;
  1012. }
  1013. /* Register interrupts */
  1014. for (i = 0; i < ARRAY_SIZE(ab8500_btemp_irq); i++) {
  1015. irq = platform_get_irq_byname(pdev, ab8500_btemp_irq[i].name);
  1016. ret = request_threaded_irq(irq, NULL, ab8500_btemp_irq[i].isr,
  1017. IRQF_SHARED | IRQF_NO_SUSPEND,
  1018. ab8500_btemp_irq[i].name, di);
  1019. if (ret) {
  1020. dev_err(di->dev, "failed to request %s IRQ %d: %d\n"
  1021. , ab8500_btemp_irq[i].name, irq, ret);
  1022. goto free_irq;
  1023. }
  1024. dev_dbg(di->dev, "Requested %s IRQ %d: %d\n",
  1025. ab8500_btemp_irq[i].name, irq, ret);
  1026. }
  1027. platform_set_drvdata(pdev, di);
  1028. /* Kick off periodic temperature measurements */
  1029. ab8500_btemp_periodic(di, true);
  1030. list_add_tail(&di->node, &ab8500_btemp_list);
  1031. return ret;
  1032. free_irq:
  1033. power_supply_unregister(&di->btemp_psy);
  1034. /* We also have to free all successfully registered irqs */
  1035. for (i = i - 1; i >= 0; i--) {
  1036. irq = platform_get_irq_byname(pdev, ab8500_btemp_irq[i].name);
  1037. free_irq(irq, di);
  1038. }
  1039. free_btemp_wq:
  1040. destroy_workqueue(di->btemp_wq);
  1041. return ret;
  1042. }
  1043. static const struct of_device_id ab8500_btemp_match[] = {
  1044. { .compatible = "stericsson,ab8500-btemp", },
  1045. { },
  1046. };
  1047. static struct platform_driver ab8500_btemp_driver = {
  1048. .probe = ab8500_btemp_probe,
  1049. .remove = ab8500_btemp_remove,
  1050. .suspend = ab8500_btemp_suspend,
  1051. .resume = ab8500_btemp_resume,
  1052. .driver = {
  1053. .name = "ab8500-btemp",
  1054. .owner = THIS_MODULE,
  1055. .of_match_table = ab8500_btemp_match,
  1056. },
  1057. };
  1058. static int __init ab8500_btemp_init(void)
  1059. {
  1060. return platform_driver_register(&ab8500_btemp_driver);
  1061. }
  1062. static void __exit ab8500_btemp_exit(void)
  1063. {
  1064. platform_driver_unregister(&ab8500_btemp_driver);
  1065. }
  1066. device_initcall(ab8500_btemp_init);
  1067. module_exit(ab8500_btemp_exit);
  1068. MODULE_LICENSE("GPL v2");
  1069. MODULE_AUTHOR("Johan Palsson, Karl Komierowski, Arun R Murthy");
  1070. MODULE_ALIAS("platform:ab8500-btemp");
  1071. MODULE_DESCRIPTION("AB8500 battery temperature driver");