ab8500_btemp.c 32 KB

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