ab8500_btemp.c 32 KB

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