max17042_battery.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  1. /*
  2. * Fuel gauge driver for Maxim 17042 / 8966 / 8997
  3. * Note that Maxim 8966 and 8997 are mfd and this is its subdevice.
  4. *
  5. * Copyright (C) 2011 Samsung Electronics
  6. * MyungJoo Ham <myungjoo.ham@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * This driver is based on max17040_battery.c
  23. */
  24. #include <linux/acpi.h>
  25. #include <linux/init.h>
  26. #include <linux/module.h>
  27. #include <linux/slab.h>
  28. #include <linux/i2c.h>
  29. #include <linux/delay.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/pm.h>
  32. #include <linux/mod_devicetable.h>
  33. #include <linux/power_supply.h>
  34. #include <linux/power/max17042_battery.h>
  35. #include <linux/of.h>
  36. #include <linux/regmap.h>
  37. /* Status register bits */
  38. #define STATUS_POR_BIT (1 << 1)
  39. #define STATUS_BST_BIT (1 << 3)
  40. #define STATUS_VMN_BIT (1 << 8)
  41. #define STATUS_TMN_BIT (1 << 9)
  42. #define STATUS_SMN_BIT (1 << 10)
  43. #define STATUS_BI_BIT (1 << 11)
  44. #define STATUS_VMX_BIT (1 << 12)
  45. #define STATUS_TMX_BIT (1 << 13)
  46. #define STATUS_SMX_BIT (1 << 14)
  47. #define STATUS_BR_BIT (1 << 15)
  48. /* Interrupt mask bits */
  49. #define CONFIG_ALRT_BIT_ENBL (1 << 2)
  50. #define STATUS_INTR_SOCMIN_BIT (1 << 10)
  51. #define STATUS_INTR_SOCMAX_BIT (1 << 14)
  52. #define VFSOC0_LOCK 0x0000
  53. #define VFSOC0_UNLOCK 0x0080
  54. #define MODEL_UNLOCK1 0X0059
  55. #define MODEL_UNLOCK2 0X00C4
  56. #define MODEL_LOCK1 0X0000
  57. #define MODEL_LOCK2 0X0000
  58. #define dQ_ACC_DIV 0x4
  59. #define dP_ACC_100 0x1900
  60. #define dP_ACC_200 0x3200
  61. #define MAX17042_VMAX_TOLERANCE 50 /* 50 mV */
  62. struct max17042_chip {
  63. struct i2c_client *client;
  64. struct regmap *regmap;
  65. struct power_supply *battery;
  66. enum max170xx_chip_type chip_type;
  67. struct max17042_platform_data *pdata;
  68. struct work_struct work;
  69. int init_complete;
  70. };
  71. static enum power_supply_property max17042_battery_props[] = {
  72. POWER_SUPPLY_PROP_STATUS,
  73. POWER_SUPPLY_PROP_PRESENT,
  74. POWER_SUPPLY_PROP_TECHNOLOGY,
  75. POWER_SUPPLY_PROP_CYCLE_COUNT,
  76. POWER_SUPPLY_PROP_VOLTAGE_MAX,
  77. POWER_SUPPLY_PROP_VOLTAGE_MIN,
  78. POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
  79. POWER_SUPPLY_PROP_VOLTAGE_NOW,
  80. POWER_SUPPLY_PROP_VOLTAGE_AVG,
  81. POWER_SUPPLY_PROP_VOLTAGE_OCV,
  82. POWER_SUPPLY_PROP_CAPACITY,
  83. POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
  84. POWER_SUPPLY_PROP_CHARGE_FULL,
  85. POWER_SUPPLY_PROP_CHARGE_NOW,
  86. POWER_SUPPLY_PROP_CHARGE_COUNTER,
  87. POWER_SUPPLY_PROP_TEMP,
  88. POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
  89. POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
  90. POWER_SUPPLY_PROP_TEMP_MIN,
  91. POWER_SUPPLY_PROP_TEMP_MAX,
  92. POWER_SUPPLY_PROP_HEALTH,
  93. POWER_SUPPLY_PROP_SCOPE,
  94. POWER_SUPPLY_PROP_CURRENT_NOW,
  95. POWER_SUPPLY_PROP_CURRENT_AVG,
  96. };
  97. static int max17042_get_temperature(struct max17042_chip *chip, int *temp)
  98. {
  99. int ret;
  100. u32 data;
  101. struct regmap *map = chip->regmap;
  102. ret = regmap_read(map, MAX17042_TEMP, &data);
  103. if (ret < 0)
  104. return ret;
  105. *temp = sign_extend32(data, 15);
  106. /* The value is converted into deci-centigrade scale */
  107. /* Units of LSB = 1 / 256 degree Celsius */
  108. *temp = *temp * 10 / 256;
  109. return 0;
  110. }
  111. static int max17042_get_status(struct max17042_chip *chip, int *status)
  112. {
  113. int ret, charge_full, charge_now;
  114. int avg_current;
  115. u32 data;
  116. ret = power_supply_am_i_supplied(chip->battery);
  117. if (ret < 0) {
  118. *status = POWER_SUPPLY_STATUS_UNKNOWN;
  119. return 0;
  120. }
  121. if (ret == 0) {
  122. *status = POWER_SUPPLY_STATUS_DISCHARGING;
  123. return 0;
  124. }
  125. /*
  126. * The MAX170xx has builtin end-of-charge detection and will update
  127. * FullCAP to match RepCap when it detects end of charging.
  128. *
  129. * When this cycle the battery gets charged to a higher (calculated)
  130. * capacity then the previous cycle then FullCAP will get updated
  131. * contineously once end-of-charge detection kicks in, so allow the
  132. * 2 to differ a bit.
  133. */
  134. ret = regmap_read(chip->regmap, MAX17042_FullCAP, &charge_full);
  135. if (ret < 0)
  136. return ret;
  137. ret = regmap_read(chip->regmap, MAX17042_RepCap, &charge_now);
  138. if (ret < 0)
  139. return ret;
  140. if ((charge_full - charge_now) <= MAX17042_FULL_THRESHOLD) {
  141. *status = POWER_SUPPLY_STATUS_FULL;
  142. return 0;
  143. }
  144. /*
  145. * Even though we are supplied, we may still be discharging if the
  146. * supply is e.g. only delivering 5V 0.5A. Check current if available.
  147. */
  148. if (!chip->pdata->enable_current_sense) {
  149. *status = POWER_SUPPLY_STATUS_CHARGING;
  150. return 0;
  151. }
  152. ret = regmap_read(chip->regmap, MAX17042_AvgCurrent, &data);
  153. if (ret < 0)
  154. return ret;
  155. avg_current = sign_extend32(data, 15);
  156. avg_current *= 1562500 / chip->pdata->r_sns;
  157. if (avg_current > 0)
  158. *status = POWER_SUPPLY_STATUS_CHARGING;
  159. else
  160. *status = POWER_SUPPLY_STATUS_DISCHARGING;
  161. return 0;
  162. }
  163. static int max17042_get_battery_health(struct max17042_chip *chip, int *health)
  164. {
  165. int temp, vavg, vbatt, ret;
  166. u32 val;
  167. ret = regmap_read(chip->regmap, MAX17042_AvgVCELL, &val);
  168. if (ret < 0)
  169. goto health_error;
  170. /* bits [0-3] unused */
  171. vavg = val * 625 / 8;
  172. /* Convert to millivolts */
  173. vavg /= 1000;
  174. ret = regmap_read(chip->regmap, MAX17042_VCELL, &val);
  175. if (ret < 0)
  176. goto health_error;
  177. /* bits [0-3] unused */
  178. vbatt = val * 625 / 8;
  179. /* Convert to millivolts */
  180. vbatt /= 1000;
  181. if (vavg < chip->pdata->vmin) {
  182. *health = POWER_SUPPLY_HEALTH_DEAD;
  183. goto out;
  184. }
  185. if (vbatt > chip->pdata->vmax + MAX17042_VMAX_TOLERANCE) {
  186. *health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
  187. goto out;
  188. }
  189. ret = max17042_get_temperature(chip, &temp);
  190. if (ret < 0)
  191. goto health_error;
  192. if (temp < chip->pdata->temp_min) {
  193. *health = POWER_SUPPLY_HEALTH_COLD;
  194. goto out;
  195. }
  196. if (temp > chip->pdata->temp_max) {
  197. *health = POWER_SUPPLY_HEALTH_OVERHEAT;
  198. goto out;
  199. }
  200. *health = POWER_SUPPLY_HEALTH_GOOD;
  201. out:
  202. return 0;
  203. health_error:
  204. return ret;
  205. }
  206. static int max17042_get_property(struct power_supply *psy,
  207. enum power_supply_property psp,
  208. union power_supply_propval *val)
  209. {
  210. struct max17042_chip *chip = power_supply_get_drvdata(psy);
  211. struct regmap *map = chip->regmap;
  212. int ret;
  213. u32 data;
  214. u64 data64;
  215. if (!chip->init_complete)
  216. return -EAGAIN;
  217. switch (psp) {
  218. case POWER_SUPPLY_PROP_STATUS:
  219. ret = max17042_get_status(chip, &val->intval);
  220. if (ret < 0)
  221. return ret;
  222. break;
  223. case POWER_SUPPLY_PROP_PRESENT:
  224. ret = regmap_read(map, MAX17042_STATUS, &data);
  225. if (ret < 0)
  226. return ret;
  227. if (data & MAX17042_STATUS_BattAbsent)
  228. val->intval = 0;
  229. else
  230. val->intval = 1;
  231. break;
  232. case POWER_SUPPLY_PROP_TECHNOLOGY:
  233. val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
  234. break;
  235. case POWER_SUPPLY_PROP_CYCLE_COUNT:
  236. ret = regmap_read(map, MAX17042_Cycles, &data);
  237. if (ret < 0)
  238. return ret;
  239. val->intval = data;
  240. break;
  241. case POWER_SUPPLY_PROP_VOLTAGE_MAX:
  242. ret = regmap_read(map, MAX17042_MinMaxVolt, &data);
  243. if (ret < 0)
  244. return ret;
  245. val->intval = data >> 8;
  246. val->intval *= 20000; /* Units of LSB = 20mV */
  247. break;
  248. case POWER_SUPPLY_PROP_VOLTAGE_MIN:
  249. ret = regmap_read(map, MAX17042_MinMaxVolt, &data);
  250. if (ret < 0)
  251. return ret;
  252. val->intval = (data & 0xff) * 20000; /* Units of 20mV */
  253. break;
  254. case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
  255. if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042)
  256. ret = regmap_read(map, MAX17042_V_empty, &data);
  257. else
  258. ret = regmap_read(map, MAX17047_V_empty, &data);
  259. if (ret < 0)
  260. return ret;
  261. val->intval = data >> 7;
  262. val->intval *= 10000; /* Units of LSB = 10mV */
  263. break;
  264. case POWER_SUPPLY_PROP_VOLTAGE_NOW:
  265. ret = regmap_read(map, MAX17042_VCELL, &data);
  266. if (ret < 0)
  267. return ret;
  268. val->intval = data * 625 / 8;
  269. break;
  270. case POWER_SUPPLY_PROP_VOLTAGE_AVG:
  271. ret = regmap_read(map, MAX17042_AvgVCELL, &data);
  272. if (ret < 0)
  273. return ret;
  274. val->intval = data * 625 / 8;
  275. break;
  276. case POWER_SUPPLY_PROP_VOLTAGE_OCV:
  277. ret = regmap_read(map, MAX17042_OCVInternal, &data);
  278. if (ret < 0)
  279. return ret;
  280. val->intval = data * 625 / 8;
  281. break;
  282. case POWER_SUPPLY_PROP_CAPACITY:
  283. ret = regmap_read(map, MAX17042_RepSOC, &data);
  284. if (ret < 0)
  285. return ret;
  286. val->intval = data >> 8;
  287. break;
  288. case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
  289. ret = regmap_read(map, MAX17042_DesignCap, &data);
  290. if (ret < 0)
  291. return ret;
  292. data64 = data * 5000000ll;
  293. do_div(data64, chip->pdata->r_sns);
  294. val->intval = data64;
  295. break;
  296. case POWER_SUPPLY_PROP_CHARGE_FULL:
  297. ret = regmap_read(map, MAX17042_FullCAP, &data);
  298. if (ret < 0)
  299. return ret;
  300. data64 = data * 5000000ll;
  301. do_div(data64, chip->pdata->r_sns);
  302. val->intval = data64;
  303. break;
  304. case POWER_SUPPLY_PROP_CHARGE_NOW:
  305. ret = regmap_read(map, MAX17042_RepCap, &data);
  306. if (ret < 0)
  307. return ret;
  308. data64 = data * 5000000ll;
  309. do_div(data64, chip->pdata->r_sns);
  310. val->intval = data64;
  311. break;
  312. case POWER_SUPPLY_PROP_CHARGE_COUNTER:
  313. ret = regmap_read(map, MAX17042_QH, &data);
  314. if (ret < 0)
  315. return ret;
  316. val->intval = data * 1000 / 2;
  317. break;
  318. case POWER_SUPPLY_PROP_TEMP:
  319. ret = max17042_get_temperature(chip, &val->intval);
  320. if (ret < 0)
  321. return ret;
  322. break;
  323. case POWER_SUPPLY_PROP_TEMP_ALERT_MIN:
  324. ret = regmap_read(map, MAX17042_TALRT_Th, &data);
  325. if (ret < 0)
  326. return ret;
  327. /* LSB is Alert Minimum. In deci-centigrade */
  328. val->intval = sign_extend32(data & 0xff, 7) * 10;
  329. break;
  330. case POWER_SUPPLY_PROP_TEMP_ALERT_MAX:
  331. ret = regmap_read(map, MAX17042_TALRT_Th, &data);
  332. if (ret < 0)
  333. return ret;
  334. /* MSB is Alert Maximum. In deci-centigrade */
  335. val->intval = sign_extend32(data >> 8, 7) * 10;
  336. break;
  337. case POWER_SUPPLY_PROP_TEMP_MIN:
  338. val->intval = chip->pdata->temp_min;
  339. break;
  340. case POWER_SUPPLY_PROP_TEMP_MAX:
  341. val->intval = chip->pdata->temp_max;
  342. break;
  343. case POWER_SUPPLY_PROP_HEALTH:
  344. ret = max17042_get_battery_health(chip, &val->intval);
  345. if (ret < 0)
  346. return ret;
  347. break;
  348. case POWER_SUPPLY_PROP_SCOPE:
  349. val->intval = POWER_SUPPLY_SCOPE_SYSTEM;
  350. break;
  351. case POWER_SUPPLY_PROP_CURRENT_NOW:
  352. if (chip->pdata->enable_current_sense) {
  353. ret = regmap_read(map, MAX17042_Current, &data);
  354. if (ret < 0)
  355. return ret;
  356. val->intval = sign_extend32(data, 15);
  357. val->intval *= 1562500 / chip->pdata->r_sns;
  358. } else {
  359. return -EINVAL;
  360. }
  361. break;
  362. case POWER_SUPPLY_PROP_CURRENT_AVG:
  363. if (chip->pdata->enable_current_sense) {
  364. ret = regmap_read(map, MAX17042_AvgCurrent, &data);
  365. if (ret < 0)
  366. return ret;
  367. val->intval = sign_extend32(data, 15);
  368. val->intval *= 1562500 / chip->pdata->r_sns;
  369. } else {
  370. return -EINVAL;
  371. }
  372. break;
  373. default:
  374. return -EINVAL;
  375. }
  376. return 0;
  377. }
  378. static int max17042_set_property(struct power_supply *psy,
  379. enum power_supply_property psp,
  380. const union power_supply_propval *val)
  381. {
  382. struct max17042_chip *chip = power_supply_get_drvdata(psy);
  383. struct regmap *map = chip->regmap;
  384. int ret = 0;
  385. u32 data;
  386. int8_t temp;
  387. switch (psp) {
  388. case POWER_SUPPLY_PROP_TEMP_ALERT_MIN:
  389. ret = regmap_read(map, MAX17042_TALRT_Th, &data);
  390. if (ret < 0)
  391. return ret;
  392. /* Input in deci-centigrade, convert to centigrade */
  393. temp = val->intval / 10;
  394. /* force min < max */
  395. if (temp >= (int8_t)(data >> 8))
  396. temp = (int8_t)(data >> 8) - 1;
  397. /* Write both MAX and MIN ALERT */
  398. data = (data & 0xff00) + temp;
  399. ret = regmap_write(map, MAX17042_TALRT_Th, data);
  400. break;
  401. case POWER_SUPPLY_PROP_TEMP_ALERT_MAX:
  402. ret = regmap_read(map, MAX17042_TALRT_Th, &data);
  403. if (ret < 0)
  404. return ret;
  405. /* Input in Deci-Centigrade, convert to centigrade */
  406. temp = val->intval / 10;
  407. /* force max > min */
  408. if (temp <= (int8_t)(data & 0xff))
  409. temp = (int8_t)(data & 0xff) + 1;
  410. /* Write both MAX and MIN ALERT */
  411. data = (data & 0xff) + (temp << 8);
  412. ret = regmap_write(map, MAX17042_TALRT_Th, data);
  413. break;
  414. default:
  415. ret = -EINVAL;
  416. }
  417. return ret;
  418. }
  419. static int max17042_property_is_writeable(struct power_supply *psy,
  420. enum power_supply_property psp)
  421. {
  422. int ret;
  423. switch (psp) {
  424. case POWER_SUPPLY_PROP_TEMP_ALERT_MIN:
  425. case POWER_SUPPLY_PROP_TEMP_ALERT_MAX:
  426. ret = 1;
  427. break;
  428. default:
  429. ret = 0;
  430. }
  431. return ret;
  432. }
  433. static void max17042_external_power_changed(struct power_supply *psy)
  434. {
  435. power_supply_changed(psy);
  436. }
  437. static int max17042_write_verify_reg(struct regmap *map, u8 reg, u32 value)
  438. {
  439. int retries = 8;
  440. int ret;
  441. u32 read_value;
  442. do {
  443. ret = regmap_write(map, reg, value);
  444. regmap_read(map, reg, &read_value);
  445. if (read_value != value) {
  446. ret = -EIO;
  447. retries--;
  448. }
  449. } while (retries && read_value != value);
  450. if (ret < 0)
  451. pr_err("%s: err %d\n", __func__, ret);
  452. return ret;
  453. }
  454. static inline void max17042_override_por(struct regmap *map,
  455. u8 reg, u16 value)
  456. {
  457. if (value)
  458. regmap_write(map, reg, value);
  459. }
  460. static inline void max10742_unlock_model(struct max17042_chip *chip)
  461. {
  462. struct regmap *map = chip->regmap;
  463. regmap_write(map, MAX17042_MLOCKReg1, MODEL_UNLOCK1);
  464. regmap_write(map, MAX17042_MLOCKReg2, MODEL_UNLOCK2);
  465. }
  466. static inline void max10742_lock_model(struct max17042_chip *chip)
  467. {
  468. struct regmap *map = chip->regmap;
  469. regmap_write(map, MAX17042_MLOCKReg1, MODEL_LOCK1);
  470. regmap_write(map, MAX17042_MLOCKReg2, MODEL_LOCK2);
  471. }
  472. static inline void max17042_write_model_data(struct max17042_chip *chip,
  473. u8 addr, int size)
  474. {
  475. struct regmap *map = chip->regmap;
  476. int i;
  477. for (i = 0; i < size; i++)
  478. regmap_write(map, addr + i,
  479. chip->pdata->config_data->cell_char_tbl[i]);
  480. }
  481. static inline void max17042_read_model_data(struct max17042_chip *chip,
  482. u8 addr, u16 *data, int size)
  483. {
  484. struct regmap *map = chip->regmap;
  485. int i;
  486. u32 tmp;
  487. for (i = 0; i < size; i++) {
  488. regmap_read(map, addr + i, &tmp);
  489. data[i] = (u16)tmp;
  490. }
  491. }
  492. static inline int max17042_model_data_compare(struct max17042_chip *chip,
  493. u16 *data1, u16 *data2, int size)
  494. {
  495. int i;
  496. if (memcmp(data1, data2, size)) {
  497. dev_err(&chip->client->dev, "%s compare failed\n", __func__);
  498. for (i = 0; i < size; i++)
  499. dev_info(&chip->client->dev, "0x%x, 0x%x",
  500. data1[i], data2[i]);
  501. dev_info(&chip->client->dev, "\n");
  502. return -EINVAL;
  503. }
  504. return 0;
  505. }
  506. static int max17042_init_model(struct max17042_chip *chip)
  507. {
  508. int ret;
  509. int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl);
  510. u16 *temp_data;
  511. temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);
  512. if (!temp_data)
  513. return -ENOMEM;
  514. max10742_unlock_model(chip);
  515. max17042_write_model_data(chip, MAX17042_MODELChrTbl,
  516. table_size);
  517. max17042_read_model_data(chip, MAX17042_MODELChrTbl, temp_data,
  518. table_size);
  519. ret = max17042_model_data_compare(
  520. chip,
  521. chip->pdata->config_data->cell_char_tbl,
  522. temp_data,
  523. table_size);
  524. max10742_lock_model(chip);
  525. kfree(temp_data);
  526. return ret;
  527. }
  528. static int max17042_verify_model_lock(struct max17042_chip *chip)
  529. {
  530. int i;
  531. int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl);
  532. u16 *temp_data;
  533. int ret = 0;
  534. temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL);
  535. if (!temp_data)
  536. return -ENOMEM;
  537. max17042_read_model_data(chip, MAX17042_MODELChrTbl, temp_data,
  538. table_size);
  539. for (i = 0; i < table_size; i++)
  540. if (temp_data[i])
  541. ret = -EINVAL;
  542. kfree(temp_data);
  543. return ret;
  544. }
  545. static void max17042_write_config_regs(struct max17042_chip *chip)
  546. {
  547. struct max17042_config_data *config = chip->pdata->config_data;
  548. struct regmap *map = chip->regmap;
  549. regmap_write(map, MAX17042_CONFIG, config->config);
  550. regmap_write(map, MAX17042_LearnCFG, config->learn_cfg);
  551. regmap_write(map, MAX17042_FilterCFG,
  552. config->filter_cfg);
  553. regmap_write(map, MAX17042_RelaxCFG, config->relax_cfg);
  554. if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17047 ||
  555. chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050)
  556. regmap_write(map, MAX17047_FullSOCThr,
  557. config->full_soc_thresh);
  558. }
  559. static void max17042_write_custom_regs(struct max17042_chip *chip)
  560. {
  561. struct max17042_config_data *config = chip->pdata->config_data;
  562. struct regmap *map = chip->regmap;
  563. max17042_write_verify_reg(map, MAX17042_RCOMP0, config->rcomp0);
  564. max17042_write_verify_reg(map, MAX17042_TempCo, config->tcompc0);
  565. max17042_write_verify_reg(map, MAX17042_ICHGTerm, config->ichgt_term);
  566. if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) {
  567. regmap_write(map, MAX17042_EmptyTempCo, config->empty_tempco);
  568. max17042_write_verify_reg(map, MAX17042_K_empty0,
  569. config->kempty0);
  570. } else {
  571. max17042_write_verify_reg(map, MAX17047_QRTbl00,
  572. config->qrtbl00);
  573. max17042_write_verify_reg(map, MAX17047_QRTbl10,
  574. config->qrtbl10);
  575. max17042_write_verify_reg(map, MAX17047_QRTbl20,
  576. config->qrtbl20);
  577. max17042_write_verify_reg(map, MAX17047_QRTbl30,
  578. config->qrtbl30);
  579. }
  580. }
  581. static void max17042_update_capacity_regs(struct max17042_chip *chip)
  582. {
  583. struct max17042_config_data *config = chip->pdata->config_data;
  584. struct regmap *map = chip->regmap;
  585. max17042_write_verify_reg(map, MAX17042_FullCAP,
  586. config->fullcap);
  587. regmap_write(map, MAX17042_DesignCap, config->design_cap);
  588. max17042_write_verify_reg(map, MAX17042_FullCAPNom,
  589. config->fullcapnom);
  590. }
  591. static void max17042_reset_vfsoc0_reg(struct max17042_chip *chip)
  592. {
  593. unsigned int vfSoc;
  594. struct regmap *map = chip->regmap;
  595. regmap_read(map, MAX17042_VFSOC, &vfSoc);
  596. regmap_write(map, MAX17042_VFSOC0Enable, VFSOC0_UNLOCK);
  597. max17042_write_verify_reg(map, MAX17042_VFSOC0, vfSoc);
  598. regmap_write(map, MAX17042_VFSOC0Enable, VFSOC0_LOCK);
  599. }
  600. static void max17042_load_new_capacity_params(struct max17042_chip *chip)
  601. {
  602. u32 full_cap0, rep_cap, dq_acc, vfSoc;
  603. u32 rem_cap;
  604. struct max17042_config_data *config = chip->pdata->config_data;
  605. struct regmap *map = chip->regmap;
  606. regmap_read(map, MAX17042_FullCAP0, &full_cap0);
  607. regmap_read(map, MAX17042_VFSOC, &vfSoc);
  608. /* fg_vfSoc needs to shifted by 8 bits to get the
  609. * perc in 1% accuracy, to get the right rem_cap multiply
  610. * full_cap0, fg_vfSoc and devide by 100
  611. */
  612. rem_cap = ((vfSoc >> 8) * full_cap0) / 100;
  613. max17042_write_verify_reg(map, MAX17042_RemCap, rem_cap);
  614. rep_cap = rem_cap;
  615. max17042_write_verify_reg(map, MAX17042_RepCap, rep_cap);
  616. /* Write dQ_acc to 200% of Capacity and dP_acc to 200% */
  617. dq_acc = config->fullcap / dQ_ACC_DIV;
  618. max17042_write_verify_reg(map, MAX17042_dQacc, dq_acc);
  619. max17042_write_verify_reg(map, MAX17042_dPacc, dP_ACC_200);
  620. max17042_write_verify_reg(map, MAX17042_FullCAP,
  621. config->fullcap);
  622. regmap_write(map, MAX17042_DesignCap,
  623. config->design_cap);
  624. max17042_write_verify_reg(map, MAX17042_FullCAPNom,
  625. config->fullcapnom);
  626. /* Update SOC register with new SOC */
  627. regmap_write(map, MAX17042_RepSOC, vfSoc);
  628. }
  629. /*
  630. * Block write all the override values coming from platform data.
  631. * This function MUST be called before the POR initialization proceedure
  632. * specified by maxim.
  633. */
  634. static inline void max17042_override_por_values(struct max17042_chip *chip)
  635. {
  636. struct regmap *map = chip->regmap;
  637. struct max17042_config_data *config = chip->pdata->config_data;
  638. max17042_override_por(map, MAX17042_TGAIN, config->tgain);
  639. max17042_override_por(map, MAx17042_TOFF, config->toff);
  640. max17042_override_por(map, MAX17042_CGAIN, config->cgain);
  641. max17042_override_por(map, MAX17042_COFF, config->coff);
  642. max17042_override_por(map, MAX17042_VALRT_Th, config->valrt_thresh);
  643. max17042_override_por(map, MAX17042_TALRT_Th, config->talrt_thresh);
  644. max17042_override_por(map, MAX17042_SALRT_Th,
  645. config->soc_alrt_thresh);
  646. max17042_override_por(map, MAX17042_CONFIG, config->config);
  647. max17042_override_por(map, MAX17042_SHDNTIMER, config->shdntimer);
  648. max17042_override_por(map, MAX17042_DesignCap, config->design_cap);
  649. max17042_override_por(map, MAX17042_ICHGTerm, config->ichgt_term);
  650. max17042_override_por(map, MAX17042_AtRate, config->at_rate);
  651. max17042_override_por(map, MAX17042_LearnCFG, config->learn_cfg);
  652. max17042_override_por(map, MAX17042_FilterCFG, config->filter_cfg);
  653. max17042_override_por(map, MAX17042_RelaxCFG, config->relax_cfg);
  654. max17042_override_por(map, MAX17042_MiscCFG, config->misc_cfg);
  655. max17042_override_por(map, MAX17042_MaskSOC, config->masksoc);
  656. max17042_override_por(map, MAX17042_FullCAP, config->fullcap);
  657. max17042_override_por(map, MAX17042_FullCAPNom, config->fullcapnom);
  658. if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042)
  659. max17042_override_por(map, MAX17042_SOC_empty,
  660. config->socempty);
  661. max17042_override_por(map, MAX17042_LAvg_empty, config->lavg_empty);
  662. max17042_override_por(map, MAX17042_dQacc, config->dqacc);
  663. max17042_override_por(map, MAX17042_dPacc, config->dpacc);
  664. if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042)
  665. max17042_override_por(map, MAX17042_V_empty, config->vempty);
  666. else
  667. max17042_override_por(map, MAX17047_V_empty, config->vempty);
  668. max17042_override_por(map, MAX17042_TempNom, config->temp_nom);
  669. max17042_override_por(map, MAX17042_TempLim, config->temp_lim);
  670. max17042_override_por(map, MAX17042_FCTC, config->fctc);
  671. max17042_override_por(map, MAX17042_RCOMP0, config->rcomp0);
  672. max17042_override_por(map, MAX17042_TempCo, config->tcompc0);
  673. if (chip->chip_type) {
  674. max17042_override_por(map, MAX17042_EmptyTempCo,
  675. config->empty_tempco);
  676. max17042_override_por(map, MAX17042_K_empty0,
  677. config->kempty0);
  678. }
  679. }
  680. static int max17042_init_chip(struct max17042_chip *chip)
  681. {
  682. struct regmap *map = chip->regmap;
  683. int ret;
  684. max17042_override_por_values(chip);
  685. /* After Power up, the MAX17042 requires 500mS in order
  686. * to perform signal debouncing and initial SOC reporting
  687. */
  688. msleep(500);
  689. /* Initialize configaration */
  690. max17042_write_config_regs(chip);
  691. /* write cell characterization data */
  692. ret = max17042_init_model(chip);
  693. if (ret) {
  694. dev_err(&chip->client->dev, "%s init failed\n",
  695. __func__);
  696. return -EIO;
  697. }
  698. ret = max17042_verify_model_lock(chip);
  699. if (ret) {
  700. dev_err(&chip->client->dev, "%s lock verify failed\n",
  701. __func__);
  702. return -EIO;
  703. }
  704. /* write custom parameters */
  705. max17042_write_custom_regs(chip);
  706. /* update capacity params */
  707. max17042_update_capacity_regs(chip);
  708. /* delay must be atleast 350mS to allow VFSOC
  709. * to be calculated from the new configuration
  710. */
  711. msleep(350);
  712. /* reset vfsoc0 reg */
  713. max17042_reset_vfsoc0_reg(chip);
  714. /* load new capacity params */
  715. max17042_load_new_capacity_params(chip);
  716. /* Init complete, Clear the POR bit */
  717. regmap_update_bits(map, MAX17042_STATUS, STATUS_POR_BIT, 0x0);
  718. return 0;
  719. }
  720. static void max17042_set_soc_threshold(struct max17042_chip *chip, u16 off)
  721. {
  722. struct regmap *map = chip->regmap;
  723. u32 soc, soc_tr;
  724. /* program interrupt thesholds such that we should
  725. * get interrupt for every 'off' perc change in the soc
  726. */
  727. regmap_read(map, MAX17042_RepSOC, &soc);
  728. soc >>= 8;
  729. soc_tr = (soc + off) << 8;
  730. soc_tr |= (soc - off);
  731. regmap_write(map, MAX17042_SALRT_Th, soc_tr);
  732. }
  733. static irqreturn_t max17042_thread_handler(int id, void *dev)
  734. {
  735. struct max17042_chip *chip = dev;
  736. u32 val;
  737. regmap_read(chip->regmap, MAX17042_STATUS, &val);
  738. if ((val & STATUS_INTR_SOCMIN_BIT) ||
  739. (val & STATUS_INTR_SOCMAX_BIT)) {
  740. dev_info(&chip->client->dev, "SOC threshold INTR\n");
  741. max17042_set_soc_threshold(chip, 1);
  742. }
  743. power_supply_changed(chip->battery);
  744. return IRQ_HANDLED;
  745. }
  746. static void max17042_init_worker(struct work_struct *work)
  747. {
  748. struct max17042_chip *chip = container_of(work,
  749. struct max17042_chip, work);
  750. int ret;
  751. /* Initialize registers according to values from the platform data */
  752. if (chip->pdata->enable_por_init && chip->pdata->config_data) {
  753. ret = max17042_init_chip(chip);
  754. if (ret)
  755. return;
  756. }
  757. chip->init_complete = 1;
  758. }
  759. #ifdef CONFIG_OF
  760. static struct max17042_platform_data *
  761. max17042_get_of_pdata(struct max17042_chip *chip)
  762. {
  763. struct device *dev = &chip->client->dev;
  764. struct device_node *np = dev->of_node;
  765. u32 prop;
  766. struct max17042_platform_data *pdata;
  767. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  768. if (!pdata)
  769. return NULL;
  770. /*
  771. * Require current sense resistor value to be specified for
  772. * current-sense functionality to be enabled at all.
  773. */
  774. if (of_property_read_u32(np, "maxim,rsns-microohm", &prop) == 0) {
  775. pdata->r_sns = prop;
  776. pdata->enable_current_sense = true;
  777. }
  778. if (of_property_read_s32(np, "maxim,cold-temp", &pdata->temp_min))
  779. pdata->temp_min = INT_MIN;
  780. if (of_property_read_s32(np, "maxim,over-heat-temp", &pdata->temp_max))
  781. pdata->temp_max = INT_MAX;
  782. if (of_property_read_s32(np, "maxim,dead-volt", &pdata->vmin))
  783. pdata->vmin = INT_MIN;
  784. if (of_property_read_s32(np, "maxim,over-volt", &pdata->vmax))
  785. pdata->vmax = INT_MAX;
  786. return pdata;
  787. }
  788. #endif
  789. static struct max17042_reg_data max17047_default_pdata_init_regs[] = {
  790. /*
  791. * Some firmwares do not set FullSOCThr, Enable End-of-Charge Detection
  792. * when the voltage FG reports 95%, as recommended in the datasheet.
  793. */
  794. { MAX17047_FullSOCThr, MAX17042_BATTERY_FULL << 8 },
  795. };
  796. static struct max17042_platform_data *
  797. max17042_get_default_pdata(struct max17042_chip *chip)
  798. {
  799. struct device *dev = &chip->client->dev;
  800. struct max17042_platform_data *pdata;
  801. int ret, misc_cfg;
  802. /*
  803. * The MAX17047 gets used on x86 where we might not have pdata, assume
  804. * the firmware will already have initialized the fuel-gauge and provide
  805. * default values for the non init bits to make things work.
  806. */
  807. pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
  808. if (!pdata)
  809. return pdata;
  810. if (chip->chip_type != MAXIM_DEVICE_TYPE_MAX17042) {
  811. pdata->init_data = max17047_default_pdata_init_regs;
  812. pdata->num_init_data =
  813. ARRAY_SIZE(max17047_default_pdata_init_regs);
  814. }
  815. ret = regmap_read(chip->regmap, MAX17042_MiscCFG, &misc_cfg);
  816. if (ret < 0)
  817. return NULL;
  818. /* If bits 0-1 are set to 3 then only Voltage readings are used */
  819. if ((misc_cfg & 0x3) == 0x3)
  820. pdata->enable_current_sense = false;
  821. else
  822. pdata->enable_current_sense = true;
  823. pdata->vmin = MAX17042_DEFAULT_VMIN;
  824. pdata->vmax = MAX17042_DEFAULT_VMAX;
  825. pdata->temp_min = MAX17042_DEFAULT_TEMP_MIN;
  826. pdata->temp_max = MAX17042_DEFAULT_TEMP_MAX;
  827. return pdata;
  828. }
  829. static struct max17042_platform_data *
  830. max17042_get_pdata(struct max17042_chip *chip)
  831. {
  832. struct device *dev = &chip->client->dev;
  833. #ifdef CONFIG_OF
  834. if (dev->of_node)
  835. return max17042_get_of_pdata(chip);
  836. #endif
  837. if (dev->platform_data)
  838. return dev->platform_data;
  839. return max17042_get_default_pdata(chip);
  840. }
  841. static const struct regmap_config max17042_regmap_config = {
  842. .reg_bits = 8,
  843. .val_bits = 16,
  844. .val_format_endian = REGMAP_ENDIAN_NATIVE,
  845. };
  846. static const struct power_supply_desc max17042_psy_desc = {
  847. .name = "max170xx_battery",
  848. .type = POWER_SUPPLY_TYPE_BATTERY,
  849. .get_property = max17042_get_property,
  850. .set_property = max17042_set_property,
  851. .property_is_writeable = max17042_property_is_writeable,
  852. .external_power_changed = max17042_external_power_changed,
  853. .properties = max17042_battery_props,
  854. .num_properties = ARRAY_SIZE(max17042_battery_props),
  855. };
  856. static const struct power_supply_desc max17042_no_current_sense_psy_desc = {
  857. .name = "max170xx_battery",
  858. .type = POWER_SUPPLY_TYPE_BATTERY,
  859. .get_property = max17042_get_property,
  860. .set_property = max17042_set_property,
  861. .property_is_writeable = max17042_property_is_writeable,
  862. .properties = max17042_battery_props,
  863. .num_properties = ARRAY_SIZE(max17042_battery_props) - 2,
  864. };
  865. static int max17042_probe(struct i2c_client *client,
  866. const struct i2c_device_id *id)
  867. {
  868. struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
  869. const struct power_supply_desc *max17042_desc = &max17042_psy_desc;
  870. struct power_supply_config psy_cfg = {};
  871. const struct acpi_device_id *acpi_id = NULL;
  872. struct device *dev = &client->dev;
  873. struct max17042_chip *chip;
  874. int ret;
  875. int i;
  876. u32 val;
  877. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
  878. return -EIO;
  879. chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
  880. if (!chip)
  881. return -ENOMEM;
  882. chip->client = client;
  883. if (id) {
  884. chip->chip_type = id->driver_data;
  885. } else {
  886. acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev);
  887. if (!acpi_id)
  888. return -ENODEV;
  889. chip->chip_type = acpi_id->driver_data;
  890. }
  891. chip->regmap = devm_regmap_init_i2c(client, &max17042_regmap_config);
  892. if (IS_ERR(chip->regmap)) {
  893. dev_err(&client->dev, "Failed to initialize regmap\n");
  894. return -EINVAL;
  895. }
  896. chip->pdata = max17042_get_pdata(chip);
  897. if (!chip->pdata) {
  898. dev_err(&client->dev, "no platform data provided\n");
  899. return -EINVAL;
  900. }
  901. i2c_set_clientdata(client, chip);
  902. psy_cfg.drv_data = chip;
  903. psy_cfg.of_node = dev->of_node;
  904. /* When current is not measured,
  905. * CURRENT_NOW and CURRENT_AVG properties should be invisible. */
  906. if (!chip->pdata->enable_current_sense)
  907. max17042_desc = &max17042_no_current_sense_psy_desc;
  908. if (chip->pdata->r_sns == 0)
  909. chip->pdata->r_sns = MAX17042_DEFAULT_SNS_RESISTOR;
  910. if (chip->pdata->init_data)
  911. for (i = 0; i < chip->pdata->num_init_data; i++)
  912. regmap_write(chip->regmap,
  913. chip->pdata->init_data[i].addr,
  914. chip->pdata->init_data[i].data);
  915. if (!chip->pdata->enable_current_sense) {
  916. regmap_write(chip->regmap, MAX17042_CGAIN, 0x0000);
  917. regmap_write(chip->regmap, MAX17042_MiscCFG, 0x0003);
  918. regmap_write(chip->regmap, MAX17042_LearnCFG, 0x0007);
  919. }
  920. chip->battery = devm_power_supply_register(&client->dev, max17042_desc,
  921. &psy_cfg);
  922. if (IS_ERR(chip->battery)) {
  923. dev_err(&client->dev, "failed: power supply register\n");
  924. return PTR_ERR(chip->battery);
  925. }
  926. if (client->irq) {
  927. unsigned int flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
  928. /*
  929. * On ACPI systems the IRQ may be handled by ACPI-event code,
  930. * so we need to share (if the ACPI code is willing to share).
  931. */
  932. if (acpi_id)
  933. flags |= IRQF_SHARED | IRQF_PROBE_SHARED;
  934. ret = devm_request_threaded_irq(&client->dev, client->irq,
  935. NULL,
  936. max17042_thread_handler, flags,
  937. chip->battery->desc->name,
  938. chip);
  939. if (!ret) {
  940. regmap_update_bits(chip->regmap, MAX17042_CONFIG,
  941. CONFIG_ALRT_BIT_ENBL,
  942. CONFIG_ALRT_BIT_ENBL);
  943. max17042_set_soc_threshold(chip, 1);
  944. } else {
  945. client->irq = 0;
  946. if (ret != -EBUSY)
  947. dev_err(&client->dev, "Failed to get IRQ\n");
  948. }
  949. }
  950. /* Not able to update the charge threshold when exceeded? -> disable */
  951. if (!client->irq)
  952. regmap_write(chip->regmap, MAX17042_SALRT_Th, 0xff00);
  953. regmap_read(chip->regmap, MAX17042_STATUS, &val);
  954. if (val & STATUS_POR_BIT) {
  955. INIT_WORK(&chip->work, max17042_init_worker);
  956. schedule_work(&chip->work);
  957. } else {
  958. chip->init_complete = 1;
  959. }
  960. return 0;
  961. }
  962. #ifdef CONFIG_PM_SLEEP
  963. static int max17042_suspend(struct device *dev)
  964. {
  965. struct max17042_chip *chip = dev_get_drvdata(dev);
  966. /*
  967. * disable the irq and enable irq_wake
  968. * capability to the interrupt line.
  969. */
  970. if (chip->client->irq) {
  971. disable_irq(chip->client->irq);
  972. enable_irq_wake(chip->client->irq);
  973. }
  974. return 0;
  975. }
  976. static int max17042_resume(struct device *dev)
  977. {
  978. struct max17042_chip *chip = dev_get_drvdata(dev);
  979. if (chip->client->irq) {
  980. disable_irq_wake(chip->client->irq);
  981. enable_irq(chip->client->irq);
  982. /* re-program the SOC thresholds to 1% change */
  983. max17042_set_soc_threshold(chip, 1);
  984. }
  985. return 0;
  986. }
  987. #endif
  988. static SIMPLE_DEV_PM_OPS(max17042_pm_ops, max17042_suspend,
  989. max17042_resume);
  990. #ifdef CONFIG_ACPI
  991. static const struct acpi_device_id max17042_acpi_match[] = {
  992. { "MAX17047", MAXIM_DEVICE_TYPE_MAX17047 },
  993. { }
  994. };
  995. MODULE_DEVICE_TABLE(acpi, max17042_acpi_match);
  996. #endif
  997. #ifdef CONFIG_OF
  998. static const struct of_device_id max17042_dt_match[] = {
  999. { .compatible = "maxim,max17042" },
  1000. { .compatible = "maxim,max17047" },
  1001. { .compatible = "maxim,max17050" },
  1002. { },
  1003. };
  1004. MODULE_DEVICE_TABLE(of, max17042_dt_match);
  1005. #endif
  1006. static const struct i2c_device_id max17042_id[] = {
  1007. { "max17042", MAXIM_DEVICE_TYPE_MAX17042 },
  1008. { "max17047", MAXIM_DEVICE_TYPE_MAX17047 },
  1009. { "max17050", MAXIM_DEVICE_TYPE_MAX17050 },
  1010. { }
  1011. };
  1012. MODULE_DEVICE_TABLE(i2c, max17042_id);
  1013. static struct i2c_driver max17042_i2c_driver = {
  1014. .driver = {
  1015. .name = "max17042",
  1016. .acpi_match_table = ACPI_PTR(max17042_acpi_match),
  1017. .of_match_table = of_match_ptr(max17042_dt_match),
  1018. .pm = &max17042_pm_ops,
  1019. },
  1020. .probe = max17042_probe,
  1021. .id_table = max17042_id,
  1022. };
  1023. module_i2c_driver(max17042_i2c_driver);
  1024. MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");
  1025. MODULE_DESCRIPTION("MAX17042 Fuel Gauge");
  1026. MODULE_LICENSE("GPL");