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. /**
  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;
  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 = power_supply_get_drvdata(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->desc->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->desc->num_properties; j++) {
  830. enum power_supply_property prop;
  831. prop = ext->desc->properties[j];
  832. if (power_supply_get_property(ext, prop, &ret))
  833. continue;
  834. switch (prop) {
  835. case POWER_SUPPLY_PROP_PRESENT:
  836. switch (ext->desc->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 = power_supply_get_drvdata(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. return 0;
  926. }
  927. static char *supply_interface[] = {
  928. "ab8500_chargalg",
  929. "ab8500_fg",
  930. };
  931. static const struct power_supply_desc ab8500_btemp_desc = {
  932. .name = "ab8500_btemp",
  933. .type = POWER_SUPPLY_TYPE_BATTERY,
  934. .properties = ab8500_btemp_props,
  935. .num_properties = ARRAY_SIZE(ab8500_btemp_props),
  936. .get_property = ab8500_btemp_get_property,
  937. .external_power_changed = ab8500_btemp_external_power_changed,
  938. };
  939. static int ab8500_btemp_probe(struct platform_device *pdev)
  940. {
  941. struct device_node *np = pdev->dev.of_node;
  942. struct abx500_bm_data *plat = pdev->dev.platform_data;
  943. struct power_supply_config psy_cfg = {};
  944. struct ab8500_btemp *di;
  945. int irq, i, ret = 0;
  946. u8 val;
  947. di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
  948. if (!di) {
  949. dev_err(&pdev->dev, "%s no mem for ab8500_btemp\n", __func__);
  950. return -ENOMEM;
  951. }
  952. if (!plat) {
  953. dev_err(&pdev->dev, "no battery management data supplied\n");
  954. return -EINVAL;
  955. }
  956. di->bm = plat;
  957. if (np) {
  958. ret = ab8500_bm_of_probe(&pdev->dev, np, di->bm);
  959. if (ret) {
  960. dev_err(&pdev->dev, "failed to get battery information\n");
  961. return ret;
  962. }
  963. }
  964. /* get parent data */
  965. di->dev = &pdev->dev;
  966. di->parent = dev_get_drvdata(pdev->dev.parent);
  967. di->gpadc = ab8500_gpadc_get("ab8500-gpadc.0");
  968. di->initialized = false;
  969. psy_cfg.supplied_to = supply_interface;
  970. psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);
  971. psy_cfg.drv_data = di;
  972. /* Create a work queue for the btemp */
  973. di->btemp_wq =
  974. create_singlethread_workqueue("ab8500_btemp_wq");
  975. if (di->btemp_wq == NULL) {
  976. dev_err(di->dev, "failed to create work queue\n");
  977. return -ENOMEM;
  978. }
  979. /* Init work for measuring temperature periodically */
  980. INIT_DEFERRABLE_WORK(&di->btemp_periodic_work,
  981. ab8500_btemp_periodic_work);
  982. /* Set BTEMP thermal limits. Low and Med are fixed */
  983. di->btemp_ranges.btemp_low_limit = BTEMP_THERMAL_LOW_LIMIT;
  984. di->btemp_ranges.btemp_med_limit = BTEMP_THERMAL_MED_LIMIT;
  985. ret = abx500_get_register_interruptible(di->dev, AB8500_CHARGER,
  986. AB8500_BTEMP_HIGH_TH, &val);
  987. if (ret < 0) {
  988. dev_err(di->dev, "%s ab8500 read failed\n", __func__);
  989. goto free_btemp_wq;
  990. }
  991. switch (val) {
  992. case BTEMP_HIGH_TH_57_0:
  993. case BTEMP_HIGH_TH_57_1:
  994. di->btemp_ranges.btemp_high_limit =
  995. BTEMP_THERMAL_HIGH_LIMIT_57;
  996. break;
  997. case BTEMP_HIGH_TH_52:
  998. di->btemp_ranges.btemp_high_limit =
  999. BTEMP_THERMAL_HIGH_LIMIT_52;
  1000. break;
  1001. case BTEMP_HIGH_TH_62:
  1002. di->btemp_ranges.btemp_high_limit =
  1003. BTEMP_THERMAL_HIGH_LIMIT_62;
  1004. break;
  1005. }
  1006. /* Register BTEMP power supply class */
  1007. di->btemp_psy = power_supply_register(di->dev, &ab8500_btemp_desc,
  1008. &psy_cfg);
  1009. if (IS_ERR(di->btemp_psy)) {
  1010. dev_err(di->dev, "failed to register BTEMP psy\n");
  1011. ret = PTR_ERR(di->btemp_psy);
  1012. goto free_btemp_wq;
  1013. }
  1014. /* Register interrupts */
  1015. for (i = 0; i < ARRAY_SIZE(ab8500_btemp_irq); i++) {
  1016. irq = platform_get_irq_byname(pdev, ab8500_btemp_irq[i].name);
  1017. ret = request_threaded_irq(irq, NULL, ab8500_btemp_irq[i].isr,
  1018. IRQF_SHARED | IRQF_NO_SUSPEND,
  1019. ab8500_btemp_irq[i].name, di);
  1020. if (ret) {
  1021. dev_err(di->dev, "failed to request %s IRQ %d: %d\n"
  1022. , ab8500_btemp_irq[i].name, irq, ret);
  1023. goto free_irq;
  1024. }
  1025. dev_dbg(di->dev, "Requested %s IRQ %d: %d\n",
  1026. ab8500_btemp_irq[i].name, irq, ret);
  1027. }
  1028. platform_set_drvdata(pdev, di);
  1029. /* Kick off periodic temperature measurements */
  1030. ab8500_btemp_periodic(di, true);
  1031. list_add_tail(&di->node, &ab8500_btemp_list);
  1032. return ret;
  1033. free_irq:
  1034. power_supply_unregister(di->btemp_psy);
  1035. /* We also have to free all successfully registered irqs */
  1036. for (i = i - 1; i >= 0; i--) {
  1037. irq = platform_get_irq_byname(pdev, ab8500_btemp_irq[i].name);
  1038. free_irq(irq, di);
  1039. }
  1040. free_btemp_wq:
  1041. destroy_workqueue(di->btemp_wq);
  1042. return ret;
  1043. }
  1044. static const struct of_device_id ab8500_btemp_match[] = {
  1045. { .compatible = "stericsson,ab8500-btemp", },
  1046. { },
  1047. };
  1048. static struct platform_driver ab8500_btemp_driver = {
  1049. .probe = ab8500_btemp_probe,
  1050. .remove = ab8500_btemp_remove,
  1051. .suspend = ab8500_btemp_suspend,
  1052. .resume = ab8500_btemp_resume,
  1053. .driver = {
  1054. .name = "ab8500-btemp",
  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");