axp20x_battery.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  1. /*
  2. * Battery power supply driver for X-Powers AXP20X and AXP22X PMICs
  3. *
  4. * Copyright 2016 Free Electrons NextThing Co.
  5. * Quentin Schulz <quentin.schulz@free-electrons.com>
  6. *
  7. * This driver is based on a previous upstreaming attempt by:
  8. * Bruno Prémont <bonbons@linux-vserver.org>
  9. *
  10. * This file is subject to the terms and conditions of the GNU General
  11. * Public License. See the file "COPYING" in the main directory of this
  12. * archive for more details.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. */
  19. #include <linux/bitfield.h>
  20. #include <linux/err.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/irq.h>
  23. #include <linux/module.h>
  24. #include <linux/of.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/power_supply.h>
  27. #include <linux/regmap.h>
  28. #include <linux/slab.h>
  29. #include <linux/time.h>
  30. #include <linux/iio/iio.h>
  31. #include <linux/iio/consumer.h>
  32. #include <linux/mfd/axp20x.h>
  33. #define AXP20X_PWR_STATUS_BAT_CHARGING BIT(2)
  34. #define AXP717_PWR_STATUS_MASK GENMASK(6, 5)
  35. #define AXP717_PWR_STATUS_BAT_STANDBY 0
  36. #define AXP717_PWR_STATUS_BAT_CHRG 1
  37. #define AXP717_PWR_STATUS_BAT_DISCHRG 2
  38. #define AXP20X_PWR_OP_BATT_PRESENT BIT(5)
  39. #define AXP20X_PWR_OP_BATT_ACTIVATED BIT(3)
  40. #define AXP717_PWR_OP_BATT_PRESENT BIT(3)
  41. #define AXP717_BATT_PMU_FAULT_MASK GENMASK(2, 0)
  42. #define AXP717_BATT_UVLO_2_5V BIT(2)
  43. #define AXP717_BATT_OVER_TEMP BIT(1)
  44. #define AXP717_BATT_UNDER_TEMP BIT(0)
  45. #define AXP209_FG_PERCENT GENMASK(6, 0)
  46. #define AXP22X_FG_VALID BIT(7)
  47. #define AXP20X_CHRG_CTRL1_ENABLE BIT(7)
  48. #define AXP20X_CHRG_CTRL1_TGT_VOLT GENMASK(6, 5)
  49. #define AXP20X_CHRG_CTRL1_TGT_4_1V (0 << 5)
  50. #define AXP20X_CHRG_CTRL1_TGT_4_15V (1 << 5)
  51. #define AXP20X_CHRG_CTRL1_TGT_4_2V (2 << 5)
  52. #define AXP20X_CHRG_CTRL1_TGT_4_36V (3 << 5)
  53. #define AXP22X_CHRG_CTRL1_TGT_4_22V (1 << 5)
  54. #define AXP22X_CHRG_CTRL1_TGT_4_24V (3 << 5)
  55. #define AXP717_CHRG_ENABLE BIT(1)
  56. #define AXP717_CHRG_CV_VOLT_MASK GENMASK(2, 0)
  57. #define AXP717_CHRG_CV_4_0V 0
  58. #define AXP717_CHRG_CV_4_1V 1
  59. #define AXP717_CHRG_CV_4_2V 2
  60. #define AXP717_CHRG_CV_4_35V 3
  61. #define AXP717_CHRG_CV_4_4V 4
  62. /* Values 5 and 6 reserved. */
  63. #define AXP717_CHRG_CV_5_0V 7
  64. #define AXP813_CHRG_CTRL1_TGT_4_35V (3 << 5)
  65. #define AXP20X_CHRG_CTRL1_TGT_CURR GENMASK(3, 0)
  66. #define AXP717_ICC_CHARGER_LIM_MASK GENMASK(5, 0)
  67. #define AXP717_ITERM_CHG_LIM_MASK GENMASK(3, 0)
  68. #define AXP717_ITERM_CC_STEP 64000
  69. #define AXP20X_V_OFF_MASK GENMASK(2, 0)
  70. #define AXP717_V_OFF_MASK GENMASK(6, 4)
  71. #define AXP717_BAT_VMIN_MIN_UV 2600000
  72. #define AXP717_BAT_VMIN_MAX_UV 3300000
  73. #define AXP717_BAT_VMIN_STEP 100000
  74. #define AXP717_BAT_CV_MIN_UV 4000000
  75. #define AXP717_BAT_CV_MAX_UV 5000000
  76. #define AXP717_BAT_CC_MIN_UA 0
  77. #define AXP717_BAT_CC_MAX_UA 3008000
  78. #define AXP717_TS_PIN_DISABLE BIT(4)
  79. struct axp20x_batt_ps;
  80. struct axp_data {
  81. int ccc_scale;
  82. int ccc_offset;
  83. unsigned int ccc_reg;
  84. unsigned int ccc_mask;
  85. bool has_fg_valid;
  86. const struct power_supply_desc *bat_ps_desc;
  87. int (*get_max_voltage)(struct axp20x_batt_ps *batt, int *val);
  88. int (*set_max_voltage)(struct axp20x_batt_ps *batt, int val);
  89. int (*cfg_iio_chan)(struct platform_device *pdev,
  90. struct axp20x_batt_ps *axp_batt);
  91. void (*set_bat_info)(struct platform_device *pdev,
  92. struct axp20x_batt_ps *axp_batt,
  93. struct power_supply_battery_info *info);
  94. };
  95. struct axp20x_batt_ps {
  96. struct regmap *regmap;
  97. struct power_supply *batt;
  98. struct device *dev;
  99. struct iio_channel *batt_chrg_i;
  100. struct iio_channel *batt_dischrg_i;
  101. struct iio_channel *batt_v;
  102. /* Maximum constant charge current */
  103. unsigned int max_ccc;
  104. const struct axp_data *data;
  105. bool ts_disable;
  106. };
  107. static int axp20x_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
  108. int *val)
  109. {
  110. int ret, reg;
  111. ret = regmap_read(axp20x_batt->regmap, AXP20X_CHRG_CTRL1, &reg);
  112. if (ret)
  113. return ret;
  114. switch (reg & AXP20X_CHRG_CTRL1_TGT_VOLT) {
  115. case AXP20X_CHRG_CTRL1_TGT_4_1V:
  116. *val = 4100000;
  117. break;
  118. case AXP20X_CHRG_CTRL1_TGT_4_15V:
  119. *val = 4150000;
  120. break;
  121. case AXP20X_CHRG_CTRL1_TGT_4_2V:
  122. *val = 4200000;
  123. break;
  124. case AXP20X_CHRG_CTRL1_TGT_4_36V:
  125. *val = 4360000;
  126. break;
  127. default:
  128. return -EINVAL;
  129. }
  130. return 0;
  131. }
  132. static int axp22x_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
  133. int *val)
  134. {
  135. int ret, reg;
  136. ret = regmap_read(axp20x_batt->regmap, AXP20X_CHRG_CTRL1, &reg);
  137. if (ret)
  138. return ret;
  139. switch (reg & AXP20X_CHRG_CTRL1_TGT_VOLT) {
  140. case AXP20X_CHRG_CTRL1_TGT_4_1V:
  141. *val = 4100000;
  142. break;
  143. case AXP20X_CHRG_CTRL1_TGT_4_2V:
  144. *val = 4200000;
  145. break;
  146. case AXP22X_CHRG_CTRL1_TGT_4_22V:
  147. *val = 4220000;
  148. break;
  149. case AXP22X_CHRG_CTRL1_TGT_4_24V:
  150. *val = 4240000;
  151. break;
  152. default:
  153. return -EINVAL;
  154. }
  155. return 0;
  156. }
  157. static int axp717_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
  158. int *val)
  159. {
  160. int ret, reg;
  161. ret = regmap_read(axp20x_batt->regmap, AXP717_CV_CHG_SET, &reg);
  162. if (ret)
  163. return ret;
  164. switch (reg & AXP717_CHRG_CV_VOLT_MASK) {
  165. case AXP717_CHRG_CV_4_0V:
  166. *val = 4000000;
  167. return 0;
  168. case AXP717_CHRG_CV_4_1V:
  169. *val = 4100000;
  170. return 0;
  171. case AXP717_CHRG_CV_4_2V:
  172. *val = 4200000;
  173. return 0;
  174. case AXP717_CHRG_CV_4_35V:
  175. *val = 4350000;
  176. return 0;
  177. case AXP717_CHRG_CV_4_4V:
  178. *val = 4400000;
  179. return 0;
  180. case AXP717_CHRG_CV_5_0V:
  181. *val = 5000000;
  182. return 0;
  183. default:
  184. return -EINVAL;
  185. }
  186. }
  187. static int axp813_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
  188. int *val)
  189. {
  190. int ret, reg;
  191. ret = regmap_read(axp20x_batt->regmap, AXP20X_CHRG_CTRL1, &reg);
  192. if (ret)
  193. return ret;
  194. switch (reg & AXP20X_CHRG_CTRL1_TGT_VOLT) {
  195. case AXP20X_CHRG_CTRL1_TGT_4_1V:
  196. *val = 4100000;
  197. break;
  198. case AXP20X_CHRG_CTRL1_TGT_4_15V:
  199. *val = 4150000;
  200. break;
  201. case AXP20X_CHRG_CTRL1_TGT_4_2V:
  202. *val = 4200000;
  203. break;
  204. case AXP813_CHRG_CTRL1_TGT_4_35V:
  205. *val = 4350000;
  206. break;
  207. default:
  208. return -EINVAL;
  209. }
  210. return 0;
  211. }
  212. static int axp20x_get_constant_charge_current(struct axp20x_batt_ps *axp,
  213. int *val)
  214. {
  215. int ret;
  216. ret = regmap_read(axp->regmap, AXP20X_CHRG_CTRL1, val);
  217. if (ret)
  218. return ret;
  219. *val &= AXP20X_CHRG_CTRL1_TGT_CURR;
  220. *val = *val * axp->data->ccc_scale + axp->data->ccc_offset;
  221. return 0;
  222. }
  223. static int axp717_get_constant_charge_current(struct axp20x_batt_ps *axp,
  224. int *val)
  225. {
  226. int ret;
  227. ret = regmap_read(axp->regmap, AXP717_ICC_CHG_SET, val);
  228. if (ret)
  229. return ret;
  230. *val = FIELD_GET(AXP717_ICC_CHARGER_LIM_MASK, *val) *
  231. axp->data->ccc_scale;
  232. return 0;
  233. }
  234. static int axp20x_battery_get_prop(struct power_supply *psy,
  235. enum power_supply_property psp,
  236. union power_supply_propval *val)
  237. {
  238. struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy);
  239. int ret = 0, reg, val1;
  240. switch (psp) {
  241. case POWER_SUPPLY_PROP_PRESENT:
  242. case POWER_SUPPLY_PROP_ONLINE:
  243. ret = regmap_read(axp20x_batt->regmap, AXP20X_PWR_OP_MODE,
  244. &reg);
  245. if (ret)
  246. return ret;
  247. val->intval = !!(reg & AXP20X_PWR_OP_BATT_PRESENT);
  248. break;
  249. case POWER_SUPPLY_PROP_STATUS:
  250. ret = regmap_read(axp20x_batt->regmap, AXP20X_PWR_INPUT_STATUS,
  251. &reg);
  252. if (ret)
  253. return ret;
  254. if (reg & AXP20X_PWR_STATUS_BAT_CHARGING) {
  255. val->intval = POWER_SUPPLY_STATUS_CHARGING;
  256. return 0;
  257. }
  258. ret = iio_read_channel_processed(axp20x_batt->batt_dischrg_i,
  259. &val1);
  260. if (ret)
  261. return ret;
  262. if (val1) {
  263. val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
  264. return 0;
  265. }
  266. ret = regmap_read(axp20x_batt->regmap, AXP20X_FG_RES, &val1);
  267. if (ret)
  268. return ret;
  269. /*
  270. * Fuel Gauge data takes 7 bits but the stored value seems to be
  271. * directly the raw percentage without any scaling to 7 bits.
  272. */
  273. if ((val1 & AXP209_FG_PERCENT) == 100)
  274. val->intval = POWER_SUPPLY_STATUS_FULL;
  275. else
  276. val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
  277. break;
  278. case POWER_SUPPLY_PROP_HEALTH:
  279. ret = regmap_read(axp20x_batt->regmap, AXP20X_PWR_OP_MODE,
  280. &val1);
  281. if (ret)
  282. return ret;
  283. if (val1 & AXP20X_PWR_OP_BATT_ACTIVATED) {
  284. val->intval = POWER_SUPPLY_HEALTH_DEAD;
  285. return 0;
  286. }
  287. val->intval = POWER_SUPPLY_HEALTH_GOOD;
  288. break;
  289. case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
  290. ret = axp20x_get_constant_charge_current(axp20x_batt,
  291. &val->intval);
  292. if (ret)
  293. return ret;
  294. break;
  295. case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
  296. val->intval = axp20x_batt->max_ccc;
  297. break;
  298. case POWER_SUPPLY_PROP_CURRENT_NOW:
  299. ret = regmap_read(axp20x_batt->regmap, AXP20X_PWR_INPUT_STATUS,
  300. &reg);
  301. if (ret)
  302. return ret;
  303. if (reg & AXP20X_PWR_STATUS_BAT_CHARGING) {
  304. ret = iio_read_channel_processed(axp20x_batt->batt_chrg_i, &val->intval);
  305. } else {
  306. ret = iio_read_channel_processed(axp20x_batt->batt_dischrg_i, &val1);
  307. val->intval = -val1;
  308. }
  309. if (ret)
  310. return ret;
  311. /* IIO framework gives mA but Power Supply framework gives uA */
  312. val->intval *= 1000;
  313. break;
  314. case POWER_SUPPLY_PROP_CAPACITY:
  315. /* When no battery is present, return capacity is 100% */
  316. ret = regmap_read(axp20x_batt->regmap, AXP20X_PWR_OP_MODE,
  317. &reg);
  318. if (ret)
  319. return ret;
  320. if (!(reg & AXP20X_PWR_OP_BATT_PRESENT)) {
  321. val->intval = 100;
  322. return 0;
  323. }
  324. ret = regmap_read(axp20x_batt->regmap, AXP20X_FG_RES, &reg);
  325. if (ret)
  326. return ret;
  327. if (axp20x_batt->data->has_fg_valid && !(reg & AXP22X_FG_VALID))
  328. return -EINVAL;
  329. /*
  330. * Fuel Gauge data takes 7 bits but the stored value seems to be
  331. * directly the raw percentage without any scaling to 7 bits.
  332. */
  333. val->intval = reg & AXP209_FG_PERCENT;
  334. break;
  335. case POWER_SUPPLY_PROP_VOLTAGE_MAX:
  336. return axp20x_batt->data->get_max_voltage(axp20x_batt,
  337. &val->intval);
  338. case POWER_SUPPLY_PROP_VOLTAGE_MIN:
  339. ret = regmap_read(axp20x_batt->regmap, AXP20X_V_OFF, &reg);
  340. if (ret)
  341. return ret;
  342. val->intval = 2600000 + 100000 * (reg & AXP20X_V_OFF_MASK);
  343. break;
  344. case POWER_SUPPLY_PROP_VOLTAGE_NOW:
  345. ret = iio_read_channel_processed(axp20x_batt->batt_v,
  346. &val->intval);
  347. if (ret)
  348. return ret;
  349. /* IIO framework gives mV but Power Supply framework gives uV */
  350. val->intval *= 1000;
  351. break;
  352. default:
  353. return -EINVAL;
  354. }
  355. return 0;
  356. }
  357. static int axp717_battery_get_prop(struct power_supply *psy,
  358. enum power_supply_property psp,
  359. union power_supply_propval *val)
  360. {
  361. struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy);
  362. int ret = 0, reg;
  363. switch (psp) {
  364. case POWER_SUPPLY_PROP_PRESENT:
  365. case POWER_SUPPLY_PROP_ONLINE:
  366. ret = regmap_read(axp20x_batt->regmap, AXP717_ON_INDICATE,
  367. &reg);
  368. if (ret)
  369. return ret;
  370. val->intval = FIELD_GET(AXP717_PWR_OP_BATT_PRESENT, reg);
  371. return 0;
  372. case POWER_SUPPLY_PROP_STATUS:
  373. ret = regmap_read(axp20x_batt->regmap, AXP717_PMU_STATUS_2,
  374. &reg);
  375. if (ret)
  376. return ret;
  377. switch (FIELD_GET(AXP717_PWR_STATUS_MASK, reg)) {
  378. case AXP717_PWR_STATUS_BAT_STANDBY:
  379. val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
  380. return 0;
  381. case AXP717_PWR_STATUS_BAT_CHRG:
  382. val->intval = POWER_SUPPLY_STATUS_CHARGING;
  383. return 0;
  384. case AXP717_PWR_STATUS_BAT_DISCHRG:
  385. val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
  386. return 0;
  387. default:
  388. val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
  389. return 0;
  390. }
  391. /*
  392. * If a fault is detected it must also be cleared; if the
  393. * condition persists it should reappear. A restart was not
  394. * sufficient to clear the bit in testing despite the register
  395. * listed as POR.
  396. */
  397. case POWER_SUPPLY_PROP_HEALTH:
  398. ret = regmap_read(axp20x_batt->regmap, AXP717_PMU_FAULT,
  399. &reg);
  400. if (ret)
  401. return ret;
  402. switch (reg & AXP717_BATT_PMU_FAULT_MASK) {
  403. case AXP717_BATT_UVLO_2_5V:
  404. val->intval = POWER_SUPPLY_HEALTH_DEAD;
  405. regmap_write_bits(axp20x_batt->regmap,
  406. AXP717_PMU_FAULT,
  407. AXP717_BATT_UVLO_2_5V,
  408. AXP717_BATT_UVLO_2_5V);
  409. return 0;
  410. case AXP717_BATT_OVER_TEMP:
  411. val->intval = POWER_SUPPLY_HEALTH_HOT;
  412. regmap_write_bits(axp20x_batt->regmap,
  413. AXP717_PMU_FAULT,
  414. AXP717_BATT_OVER_TEMP,
  415. AXP717_BATT_OVER_TEMP);
  416. return 0;
  417. case AXP717_BATT_UNDER_TEMP:
  418. val->intval = POWER_SUPPLY_HEALTH_COLD;
  419. regmap_write_bits(axp20x_batt->regmap,
  420. AXP717_PMU_FAULT,
  421. AXP717_BATT_UNDER_TEMP,
  422. AXP717_BATT_UNDER_TEMP);
  423. return 0;
  424. default:
  425. val->intval = POWER_SUPPLY_HEALTH_GOOD;
  426. return 0;
  427. }
  428. case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
  429. ret = axp717_get_constant_charge_current(axp20x_batt,
  430. &val->intval);
  431. if (ret)
  432. return ret;
  433. return 0;
  434. case POWER_SUPPLY_PROP_CURRENT_NOW:
  435. /*
  436. * The offset of this value is currently unknown and is
  437. * not documented in the datasheet. Based on
  438. * observation it's assumed to be somewhere around
  439. * 450ma. I will leave the value raw for now.
  440. */
  441. ret = iio_read_channel_processed(axp20x_batt->batt_chrg_i, &val->intval);
  442. if (ret)
  443. return ret;
  444. /* IIO framework gives mA but Power Supply framework gives uA */
  445. val->intval *= 1000;
  446. return 0;
  447. case POWER_SUPPLY_PROP_CAPACITY:
  448. ret = regmap_read(axp20x_batt->regmap, AXP717_ON_INDICATE,
  449. &reg);
  450. if (ret)
  451. return ret;
  452. if (!FIELD_GET(AXP717_PWR_OP_BATT_PRESENT, reg))
  453. return -ENODEV;
  454. ret = regmap_read(axp20x_batt->regmap,
  455. AXP717_BATT_PERCENT_DATA, &reg);
  456. if (ret)
  457. return ret;
  458. /*
  459. * Fuel Gauge data takes 7 bits but the stored value seems to be
  460. * directly the raw percentage without any scaling to 7 bits.
  461. */
  462. val->intval = reg & AXP209_FG_PERCENT;
  463. return 0;
  464. case POWER_SUPPLY_PROP_VOLTAGE_MAX:
  465. return axp20x_batt->data->get_max_voltage(axp20x_batt,
  466. &val->intval);
  467. case POWER_SUPPLY_PROP_VOLTAGE_MIN:
  468. ret = regmap_read(axp20x_batt->regmap,
  469. AXP717_VSYS_V_POWEROFF, &reg);
  470. if (ret)
  471. return ret;
  472. val->intval = AXP717_BAT_VMIN_MIN_UV + AXP717_BAT_VMIN_STEP *
  473. (reg & AXP717_V_OFF_MASK);
  474. return 0;
  475. case POWER_SUPPLY_PROP_VOLTAGE_NOW:
  476. ret = iio_read_channel_processed(axp20x_batt->batt_v,
  477. &val->intval);
  478. if (ret)
  479. return ret;
  480. /* IIO framework gives mV but Power Supply framework gives uV */
  481. val->intval *= 1000;
  482. return 0;
  483. case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
  484. ret = regmap_read(axp20x_batt->regmap,
  485. AXP717_ITERM_CHG_SET, &reg);
  486. if (ret)
  487. return ret;
  488. val->intval = (reg & AXP717_ITERM_CHG_LIM_MASK) * AXP717_ITERM_CC_STEP;
  489. return 0;
  490. default:
  491. return -EINVAL;
  492. }
  493. }
  494. static int axp22x_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt,
  495. int val)
  496. {
  497. switch (val) {
  498. case 4100000:
  499. val = AXP20X_CHRG_CTRL1_TGT_4_1V;
  500. break;
  501. case 4200000:
  502. val = AXP20X_CHRG_CTRL1_TGT_4_2V;
  503. break;
  504. default:
  505. /*
  506. * AXP20x max voltage can be set to 4.36V and AXP22X max voltage
  507. * can be set to 4.22V and 4.24V, but these voltages are too
  508. * high for Lithium based batteries (AXP PMICs are supposed to
  509. * be used with these kinds of battery).
  510. */
  511. return -EINVAL;
  512. }
  513. return regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL1,
  514. AXP20X_CHRG_CTRL1_TGT_VOLT, val);
  515. }
  516. static int axp20x_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt,
  517. int val)
  518. {
  519. switch (val) {
  520. case 4100000:
  521. val = AXP20X_CHRG_CTRL1_TGT_4_1V;
  522. break;
  523. case 4150000:
  524. val = AXP20X_CHRG_CTRL1_TGT_4_15V;
  525. break;
  526. case 4200000:
  527. val = AXP20X_CHRG_CTRL1_TGT_4_2V;
  528. break;
  529. default:
  530. /*
  531. * AXP20x max voltage can be set to 4.36V and AXP22X max voltage
  532. * can be set to 4.22V and 4.24V, but these voltages are too
  533. * high for Lithium based batteries (AXP PMICs are supposed to
  534. * be used with these kinds of battery).
  535. */
  536. return -EINVAL;
  537. }
  538. return regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL1,
  539. AXP20X_CHRG_CTRL1_TGT_VOLT, val);
  540. }
  541. static int axp717_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt,
  542. int val)
  543. {
  544. switch (val) {
  545. case 4000000:
  546. val = AXP717_CHRG_CV_4_0V;
  547. break;
  548. case 4100000:
  549. val = AXP717_CHRG_CV_4_1V;
  550. break;
  551. case 4200000:
  552. val = AXP717_CHRG_CV_4_2V;
  553. break;
  554. default:
  555. /*
  556. * AXP717 can go up to 4.35, 4.4, and 5.0 volts which
  557. * seem too high for lithium batteries, so do not allow.
  558. */
  559. return -EINVAL;
  560. }
  561. return regmap_update_bits(axp20x_batt->regmap,
  562. AXP717_CV_CHG_SET,
  563. AXP717_CHRG_CV_VOLT_MASK, val);
  564. }
  565. static int axp20x_set_constant_charge_current(struct axp20x_batt_ps *axp_batt,
  566. int charge_current)
  567. {
  568. if (charge_current > axp_batt->max_ccc)
  569. return -EINVAL;
  570. charge_current = (charge_current - axp_batt->data->ccc_offset) /
  571. axp_batt->data->ccc_scale;
  572. if (charge_current > AXP20X_CHRG_CTRL1_TGT_CURR || charge_current < 0)
  573. return -EINVAL;
  574. return regmap_update_bits(axp_batt->regmap, AXP20X_CHRG_CTRL1,
  575. AXP20X_CHRG_CTRL1_TGT_CURR, charge_current);
  576. }
  577. static int axp717_set_constant_charge_current(struct axp20x_batt_ps *axp,
  578. int charge_current)
  579. {
  580. int val;
  581. if (charge_current > axp->max_ccc)
  582. return -EINVAL;
  583. if (charge_current > AXP717_BAT_CC_MAX_UA || charge_current < 0)
  584. return -EINVAL;
  585. val = (charge_current - axp->data->ccc_offset) /
  586. axp->data->ccc_scale;
  587. return regmap_update_bits(axp->regmap, AXP717_ICC_CHG_SET,
  588. AXP717_ICC_CHARGER_LIM_MASK, val);
  589. }
  590. static int axp20x_set_max_constant_charge_current(struct axp20x_batt_ps *axp,
  591. int charge_current)
  592. {
  593. bool lower_max = false;
  594. charge_current = (charge_current - axp->data->ccc_offset) /
  595. axp->data->ccc_scale;
  596. if (charge_current > AXP20X_CHRG_CTRL1_TGT_CURR || charge_current < 0)
  597. return -EINVAL;
  598. charge_current = charge_current * axp->data->ccc_scale +
  599. axp->data->ccc_offset;
  600. if (charge_current > axp->max_ccc)
  601. dev_warn(axp->dev,
  602. "Setting max constant charge current higher than previously defined. Note that increasing the constant charge current may damage your battery.\n");
  603. else
  604. lower_max = true;
  605. axp->max_ccc = charge_current;
  606. if (lower_max) {
  607. int current_cc;
  608. axp20x_get_constant_charge_current(axp, &current_cc);
  609. if (current_cc > charge_current)
  610. axp20x_set_constant_charge_current(axp, charge_current);
  611. }
  612. return 0;
  613. }
  614. static int axp20x_set_voltage_min_design(struct axp20x_batt_ps *axp_batt,
  615. int min_voltage)
  616. {
  617. int val1 = (min_voltage - 2600000) / 100000;
  618. if (val1 < 0 || val1 > AXP20X_V_OFF_MASK)
  619. return -EINVAL;
  620. return regmap_update_bits(axp_batt->regmap, AXP20X_V_OFF,
  621. AXP20X_V_OFF_MASK, val1);
  622. }
  623. static int axp717_set_voltage_min_design(struct axp20x_batt_ps *axp_batt,
  624. int min_voltage)
  625. {
  626. int val1 = (min_voltage - AXP717_BAT_VMIN_MIN_UV) / AXP717_BAT_VMIN_STEP;
  627. if (val1 < 0 || val1 > AXP717_V_OFF_MASK)
  628. return -EINVAL;
  629. return regmap_update_bits(axp_batt->regmap,
  630. AXP717_VSYS_V_POWEROFF,
  631. AXP717_V_OFF_MASK, val1);
  632. }
  633. static int axp20x_battery_set_prop(struct power_supply *psy,
  634. enum power_supply_property psp,
  635. const union power_supply_propval *val)
  636. {
  637. struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy);
  638. switch (psp) {
  639. case POWER_SUPPLY_PROP_VOLTAGE_MIN:
  640. return axp20x_set_voltage_min_design(axp20x_batt, val->intval);
  641. case POWER_SUPPLY_PROP_VOLTAGE_MAX:
  642. return axp20x_batt->data->set_max_voltage(axp20x_batt, val->intval);
  643. case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
  644. return axp20x_set_constant_charge_current(axp20x_batt,
  645. val->intval);
  646. case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
  647. return axp20x_set_max_constant_charge_current(axp20x_batt,
  648. val->intval);
  649. case POWER_SUPPLY_PROP_STATUS:
  650. switch (val->intval) {
  651. case POWER_SUPPLY_STATUS_CHARGING:
  652. return regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL1,
  653. AXP20X_CHRG_CTRL1_ENABLE, AXP20X_CHRG_CTRL1_ENABLE);
  654. case POWER_SUPPLY_STATUS_DISCHARGING:
  655. case POWER_SUPPLY_STATUS_NOT_CHARGING:
  656. return regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL1,
  657. AXP20X_CHRG_CTRL1_ENABLE, 0);
  658. }
  659. fallthrough;
  660. default:
  661. return -EINVAL;
  662. }
  663. }
  664. static int axp717_battery_set_prop(struct power_supply *psy,
  665. enum power_supply_property psp,
  666. const union power_supply_propval *val)
  667. {
  668. struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy);
  669. switch (psp) {
  670. case POWER_SUPPLY_PROP_VOLTAGE_MIN:
  671. return axp717_set_voltage_min_design(axp20x_batt, val->intval);
  672. case POWER_SUPPLY_PROP_VOLTAGE_MAX:
  673. return axp20x_batt->data->set_max_voltage(axp20x_batt, val->intval);
  674. case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
  675. return axp717_set_constant_charge_current(axp20x_batt,
  676. val->intval);
  677. case POWER_SUPPLY_PROP_STATUS:
  678. switch (val->intval) {
  679. case POWER_SUPPLY_STATUS_CHARGING:
  680. return regmap_update_bits(axp20x_batt->regmap,
  681. AXP717_MODULE_EN_CONTROL_2,
  682. AXP717_CHRG_ENABLE,
  683. AXP717_CHRG_ENABLE);
  684. case POWER_SUPPLY_STATUS_DISCHARGING:
  685. case POWER_SUPPLY_STATUS_NOT_CHARGING:
  686. return regmap_update_bits(axp20x_batt->regmap,
  687. AXP717_MODULE_EN_CONTROL_2,
  688. AXP717_CHRG_ENABLE, 0);
  689. }
  690. return -EINVAL;
  691. default:
  692. return -EINVAL;
  693. }
  694. }
  695. static enum power_supply_property axp20x_battery_props[] = {
  696. POWER_SUPPLY_PROP_PRESENT,
  697. POWER_SUPPLY_PROP_ONLINE,
  698. POWER_SUPPLY_PROP_STATUS,
  699. POWER_SUPPLY_PROP_VOLTAGE_NOW,
  700. POWER_SUPPLY_PROP_CURRENT_NOW,
  701. POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
  702. POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
  703. POWER_SUPPLY_PROP_HEALTH,
  704. POWER_SUPPLY_PROP_VOLTAGE_MAX,
  705. POWER_SUPPLY_PROP_VOLTAGE_MIN,
  706. POWER_SUPPLY_PROP_CAPACITY,
  707. };
  708. static enum power_supply_property axp717_battery_props[] = {
  709. POWER_SUPPLY_PROP_PRESENT,
  710. POWER_SUPPLY_PROP_ONLINE,
  711. POWER_SUPPLY_PROP_STATUS,
  712. POWER_SUPPLY_PROP_VOLTAGE_NOW,
  713. POWER_SUPPLY_PROP_CURRENT_NOW,
  714. POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
  715. POWER_SUPPLY_PROP_HEALTH,
  716. POWER_SUPPLY_PROP_VOLTAGE_MAX,
  717. POWER_SUPPLY_PROP_VOLTAGE_MIN,
  718. POWER_SUPPLY_PROP_CAPACITY,
  719. POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
  720. };
  721. static int axp20x_battery_prop_writeable(struct power_supply *psy,
  722. enum power_supply_property psp)
  723. {
  724. return psp == POWER_SUPPLY_PROP_STATUS ||
  725. psp == POWER_SUPPLY_PROP_VOLTAGE_MIN ||
  726. psp == POWER_SUPPLY_PROP_VOLTAGE_MAX ||
  727. psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT ||
  728. psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX;
  729. }
  730. static int axp717_battery_prop_writeable(struct power_supply *psy,
  731. enum power_supply_property psp)
  732. {
  733. return psp == POWER_SUPPLY_PROP_STATUS ||
  734. psp == POWER_SUPPLY_PROP_VOLTAGE_MIN ||
  735. psp == POWER_SUPPLY_PROP_VOLTAGE_MAX ||
  736. psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX;
  737. }
  738. static const struct power_supply_desc axp209_batt_ps_desc = {
  739. .name = "axp20x-battery",
  740. .type = POWER_SUPPLY_TYPE_BATTERY,
  741. .properties = axp20x_battery_props,
  742. .num_properties = ARRAY_SIZE(axp20x_battery_props),
  743. .property_is_writeable = axp20x_battery_prop_writeable,
  744. .get_property = axp20x_battery_get_prop,
  745. .set_property = axp20x_battery_set_prop,
  746. };
  747. static const struct power_supply_desc axp717_batt_ps_desc = {
  748. .name = "axp20x-battery",
  749. .type = POWER_SUPPLY_TYPE_BATTERY,
  750. .properties = axp717_battery_props,
  751. .num_properties = ARRAY_SIZE(axp717_battery_props),
  752. .property_is_writeable = axp717_battery_prop_writeable,
  753. .get_property = axp717_battery_get_prop,
  754. .set_property = axp717_battery_set_prop,
  755. };
  756. static int axp209_bat_cfg_iio_channels(struct platform_device *pdev,
  757. struct axp20x_batt_ps *axp_batt)
  758. {
  759. axp_batt->batt_v = devm_iio_channel_get(&pdev->dev, "batt_v");
  760. if (IS_ERR(axp_batt->batt_v)) {
  761. if (PTR_ERR(axp_batt->batt_v) == -ENODEV)
  762. return -EPROBE_DEFER;
  763. return PTR_ERR(axp_batt->batt_v);
  764. }
  765. axp_batt->batt_chrg_i = devm_iio_channel_get(&pdev->dev,
  766. "batt_chrg_i");
  767. if (IS_ERR(axp_batt->batt_chrg_i)) {
  768. if (PTR_ERR(axp_batt->batt_chrg_i) == -ENODEV)
  769. return -EPROBE_DEFER;
  770. return PTR_ERR(axp_batt->batt_chrg_i);
  771. }
  772. axp_batt->batt_dischrg_i = devm_iio_channel_get(&pdev->dev,
  773. "batt_dischrg_i");
  774. if (IS_ERR(axp_batt->batt_dischrg_i)) {
  775. if (PTR_ERR(axp_batt->batt_dischrg_i) == -ENODEV)
  776. return -EPROBE_DEFER;
  777. return PTR_ERR(axp_batt->batt_dischrg_i);
  778. }
  779. return 0;
  780. }
  781. static int axp717_bat_cfg_iio_channels(struct platform_device *pdev,
  782. struct axp20x_batt_ps *axp_batt)
  783. {
  784. axp_batt->batt_v = devm_iio_channel_get(&pdev->dev, "batt_v");
  785. if (IS_ERR(axp_batt->batt_v)) {
  786. if (PTR_ERR(axp_batt->batt_v) == -ENODEV)
  787. return -EPROBE_DEFER;
  788. return PTR_ERR(axp_batt->batt_v);
  789. }
  790. axp_batt->batt_chrg_i = devm_iio_channel_get(&pdev->dev,
  791. "batt_chrg_i");
  792. if (IS_ERR(axp_batt->batt_chrg_i)) {
  793. if (PTR_ERR(axp_batt->batt_chrg_i) == -ENODEV)
  794. return -EPROBE_DEFER;
  795. return PTR_ERR(axp_batt->batt_chrg_i);
  796. }
  797. return 0;
  798. }
  799. static void axp209_set_battery_info(struct platform_device *pdev,
  800. struct axp20x_batt_ps *axp_batt,
  801. struct power_supply_battery_info *info)
  802. {
  803. int vmin = info->voltage_min_design_uv;
  804. int ccc = info->constant_charge_current_max_ua;
  805. if (vmin > 0 && axp20x_set_voltage_min_design(axp_batt, vmin))
  806. dev_err(&pdev->dev,
  807. "couldn't set voltage_min_design\n");
  808. /* Set max to unverified value to be able to set CCC */
  809. axp_batt->max_ccc = ccc;
  810. if (ccc <= 0 || axp20x_set_constant_charge_current(axp_batt, ccc)) {
  811. dev_err(&pdev->dev,
  812. "couldn't set ccc from DT: fallback to min value\n");
  813. ccc = 300000;
  814. axp_batt->max_ccc = ccc;
  815. axp20x_set_constant_charge_current(axp_batt, ccc);
  816. }
  817. }
  818. static void axp717_set_battery_info(struct platform_device *pdev,
  819. struct axp20x_batt_ps *axp_batt,
  820. struct power_supply_battery_info *info)
  821. {
  822. int vmin = info->voltage_min_design_uv;
  823. int vmax = info->voltage_max_design_uv;
  824. int ccc = info->constant_charge_current_max_ua;
  825. int val;
  826. axp_batt->ts_disable = (device_property_read_bool(axp_batt->dev,
  827. "x-powers,no-thermistor"));
  828. /*
  829. * Under rare conditions an incorrectly programmed efuse for
  830. * the temp sensor on the PMIC may trigger a fault condition.
  831. * Allow users to hard-code if the ts pin is not used to work
  832. * around this problem. Note that this requires the battery
  833. * be correctly defined in the device tree with a monitored
  834. * battery node.
  835. */
  836. if (axp_batt->ts_disable) {
  837. regmap_update_bits(axp_batt->regmap,
  838. AXP717_TS_PIN_CFG,
  839. AXP717_TS_PIN_DISABLE,
  840. AXP717_TS_PIN_DISABLE);
  841. }
  842. if (vmin > 0 && axp717_set_voltage_min_design(axp_batt, vmin))
  843. dev_err(&pdev->dev,
  844. "couldn't set voltage_min_design\n");
  845. if (vmax > 0 && axp717_battery_set_max_voltage(axp_batt, vmax))
  846. dev_err(&pdev->dev,
  847. "couldn't set voltage_max_design\n");
  848. axp717_get_constant_charge_current(axp_batt, &val);
  849. axp_batt->max_ccc = ccc;
  850. if (ccc <= 0 || axp717_set_constant_charge_current(axp_batt, ccc)) {
  851. dev_err(&pdev->dev,
  852. "couldn't set ccc from DT: current ccc is %d\n",
  853. val);
  854. }
  855. }
  856. static const struct axp_data axp209_data = {
  857. .ccc_scale = 100000,
  858. .ccc_offset = 300000,
  859. .ccc_reg = AXP20X_CHRG_CTRL1,
  860. .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR,
  861. .bat_ps_desc = &axp209_batt_ps_desc,
  862. .get_max_voltage = axp20x_battery_get_max_voltage,
  863. .set_max_voltage = axp20x_battery_set_max_voltage,
  864. .cfg_iio_chan = axp209_bat_cfg_iio_channels,
  865. .set_bat_info = axp209_set_battery_info,
  866. };
  867. static const struct axp_data axp221_data = {
  868. .ccc_scale = 150000,
  869. .ccc_offset = 300000,
  870. .ccc_reg = AXP20X_CHRG_CTRL1,
  871. .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR,
  872. .has_fg_valid = true,
  873. .bat_ps_desc = &axp209_batt_ps_desc,
  874. .get_max_voltage = axp22x_battery_get_max_voltage,
  875. .set_max_voltage = axp22x_battery_set_max_voltage,
  876. .cfg_iio_chan = axp209_bat_cfg_iio_channels,
  877. .set_bat_info = axp209_set_battery_info,
  878. };
  879. static const struct axp_data axp717_data = {
  880. .ccc_scale = 64000,
  881. .ccc_offset = 0,
  882. .ccc_reg = AXP717_ICC_CHG_SET,
  883. .ccc_mask = AXP717_ICC_CHARGER_LIM_MASK,
  884. .bat_ps_desc = &axp717_batt_ps_desc,
  885. .get_max_voltage = axp717_battery_get_max_voltage,
  886. .set_max_voltage = axp717_battery_set_max_voltage,
  887. .cfg_iio_chan = axp717_bat_cfg_iio_channels,
  888. .set_bat_info = axp717_set_battery_info,
  889. };
  890. static const struct axp_data axp813_data = {
  891. .ccc_scale = 200000,
  892. .ccc_offset = 200000,
  893. .ccc_reg = AXP20X_CHRG_CTRL1,
  894. .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR,
  895. .has_fg_valid = true,
  896. .bat_ps_desc = &axp209_batt_ps_desc,
  897. .get_max_voltage = axp813_battery_get_max_voltage,
  898. .set_max_voltage = axp20x_battery_set_max_voltage,
  899. .cfg_iio_chan = axp209_bat_cfg_iio_channels,
  900. .set_bat_info = axp209_set_battery_info,
  901. };
  902. static const struct of_device_id axp20x_battery_ps_id[] = {
  903. {
  904. .compatible = "x-powers,axp209-battery-power-supply",
  905. .data = (void *)&axp209_data,
  906. }, {
  907. .compatible = "x-powers,axp221-battery-power-supply",
  908. .data = (void *)&axp221_data,
  909. }, {
  910. .compatible = "x-powers,axp717-battery-power-supply",
  911. .data = (void *)&axp717_data,
  912. }, {
  913. .compatible = "x-powers,axp813-battery-power-supply",
  914. .data = (void *)&axp813_data,
  915. }, { /* sentinel */ },
  916. };
  917. MODULE_DEVICE_TABLE(of, axp20x_battery_ps_id);
  918. static int axp20x_power_probe(struct platform_device *pdev)
  919. {
  920. struct axp20x_batt_ps *axp20x_batt;
  921. struct power_supply_config psy_cfg = {};
  922. struct power_supply_battery_info *info;
  923. struct device *dev = &pdev->dev;
  924. int ret;
  925. if (!of_device_is_available(pdev->dev.of_node))
  926. return -ENODEV;
  927. axp20x_batt = devm_kzalloc(&pdev->dev, sizeof(*axp20x_batt),
  928. GFP_KERNEL);
  929. if (!axp20x_batt)
  930. return -ENOMEM;
  931. axp20x_batt->dev = &pdev->dev;
  932. axp20x_batt->regmap = dev_get_regmap(pdev->dev.parent, NULL);
  933. platform_set_drvdata(pdev, axp20x_batt);
  934. psy_cfg.drv_data = axp20x_batt;
  935. psy_cfg.of_node = pdev->dev.of_node;
  936. axp20x_batt->data = (struct axp_data *)of_device_get_match_data(dev);
  937. ret = axp20x_batt->data->cfg_iio_chan(pdev, axp20x_batt);
  938. if (ret)
  939. return ret;
  940. axp20x_batt->batt = devm_power_supply_register(&pdev->dev,
  941. axp20x_batt->data->bat_ps_desc,
  942. &psy_cfg);
  943. if (IS_ERR(axp20x_batt->batt)) {
  944. dev_err(&pdev->dev, "failed to register power supply: %ld\n",
  945. PTR_ERR(axp20x_batt->batt));
  946. return PTR_ERR(axp20x_batt->batt);
  947. }
  948. if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) {
  949. axp20x_batt->data->set_bat_info(pdev, axp20x_batt, info);
  950. power_supply_put_battery_info(axp20x_batt->batt, info);
  951. }
  952. /*
  953. * Update max CCC to a valid value if battery info is present or set it
  954. * to current register value by default.
  955. */
  956. axp20x_get_constant_charge_current(axp20x_batt, &axp20x_batt->max_ccc);
  957. return 0;
  958. }
  959. static struct platform_driver axp20x_batt_driver = {
  960. .probe = axp20x_power_probe,
  961. .driver = {
  962. .name = "axp20x-battery-power-supply",
  963. .of_match_table = axp20x_battery_ps_id,
  964. },
  965. };
  966. module_platform_driver(axp20x_batt_driver);
  967. MODULE_DESCRIPTION("Battery power supply driver for AXP20X and AXP22X PMICs");
  968. MODULE_AUTHOR("Quentin Schulz <quentin.schulz@free-electrons.com>");
  969. MODULE_LICENSE("GPL");