18c0984e5SSebastian Reichel /*
28c0984e5SSebastian Reichel  * BQ27xxx battery driver
38c0984e5SSebastian Reichel  *
48c0984e5SSebastian Reichel  * Copyright (C) 2008 Rodolfo Giometti <giometti@linux.it>
58c0984e5SSebastian Reichel  * Copyright (C) 2008 Eurotech S.p.A. <info@eurotech.it>
68c0984e5SSebastian Reichel  * Copyright (C) 2010-2011 Lars-Peter Clausen <lars@metafoo.de>
78c0984e5SSebastian Reichel  * Copyright (C) 2011 Pali Rohár <pali.rohar@gmail.com>
88c0984e5SSebastian Reichel  *
98c0984e5SSebastian Reichel  * Based on a previous work by Copyright (C) 2008 Texas Instruments, Inc.
108c0984e5SSebastian Reichel  *
118c0984e5SSebastian Reichel  * This package is free software; you can redistribute it and/or modify
128c0984e5SSebastian Reichel  * it under the terms of the GNU General Public License version 2 as
138c0984e5SSebastian Reichel  * published by the Free Software Foundation.
148c0984e5SSebastian Reichel  *
158c0984e5SSebastian Reichel  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
168c0984e5SSebastian Reichel  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
178c0984e5SSebastian Reichel  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
188c0984e5SSebastian Reichel  *
198c0984e5SSebastian Reichel  * Datasheets:
208c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27000
218c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27200
228c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27010
238c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27210
248c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27500
25bd28177fSChris Lapa  * http://www.ti.com/product/bq27510-g1
26698a2bf5SChris Lapa  * http://www.ti.com/product/bq27510-g2
278c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27510-g3
288c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27520-g4
2968f2a813SChris Lapa  * http://www.ti.com/product/bq27520-g1
30a5deb9a9SChris Lapa  * http://www.ti.com/product/bq27520-g2
31825e915bSChris Lapa  * http://www.ti.com/product/bq27520-g3
328c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27530-g1
338c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27531-g1
348c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27541-g1
358c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27542-g1
368c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27546-g1
378c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27742-g1
388c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27545-g1
398c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27421-g1
408c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27425-g1
418c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27411-g1
428c0984e5SSebastian Reichel  * http://www.ti.com/product/bq27621-g1
438c0984e5SSebastian Reichel  */
448c0984e5SSebastian Reichel 
458c0984e5SSebastian Reichel #include <linux/device.h>
468c0984e5SSebastian Reichel #include <linux/module.h>
471d72706fSMatt Ranostay #include <linux/mutex.h>
488c0984e5SSebastian Reichel #include <linux/param.h>
498c0984e5SSebastian Reichel #include <linux/jiffies.h>
508c0984e5SSebastian Reichel #include <linux/workqueue.h>
518c0984e5SSebastian Reichel #include <linux/delay.h>
528c0984e5SSebastian Reichel #include <linux/platform_device.h>
538c0984e5SSebastian Reichel #include <linux/power_supply.h>
548c0984e5SSebastian Reichel #include <linux/slab.h>
558c0984e5SSebastian Reichel #include <linux/of.h>
568c0984e5SSebastian Reichel 
578c0984e5SSebastian Reichel #include <linux/power/bq27xxx_battery.h>
588c0984e5SSebastian Reichel 
598c0984e5SSebastian Reichel #define DRIVER_VERSION		"1.2.0"
608c0984e5SSebastian Reichel 
618c0984e5SSebastian Reichel #define BQ27XXX_MANUFACTURER	"Texas Instruments"
628c0984e5SSebastian Reichel 
638c0984e5SSebastian Reichel /* BQ27XXX Flags */
648c0984e5SSebastian Reichel #define BQ27XXX_FLAG_DSC	BIT(0)
658c0984e5SSebastian Reichel #define BQ27XXX_FLAG_SOCF	BIT(1) /* State-of-Charge threshold final */
668c0984e5SSebastian Reichel #define BQ27XXX_FLAG_SOC1	BIT(2) /* State-of-Charge threshold 1 */
678c0984e5SSebastian Reichel #define BQ27XXX_FLAG_FC		BIT(9)
688c0984e5SSebastian Reichel #define BQ27XXX_FLAG_OTD	BIT(14)
698c0984e5SSebastian Reichel #define BQ27XXX_FLAG_OTC	BIT(15)
708c0984e5SSebastian Reichel #define BQ27XXX_FLAG_UT		BIT(14)
718c0984e5SSebastian Reichel #define BQ27XXX_FLAG_OT		BIT(15)
728c0984e5SSebastian Reichel 
738c0984e5SSebastian Reichel /* BQ27000 has different layout for Flags register */
748c0984e5SSebastian Reichel #define BQ27000_FLAG_EDVF	BIT(0) /* Final End-of-Discharge-Voltage flag */
758c0984e5SSebastian Reichel #define BQ27000_FLAG_EDV1	BIT(1) /* First End-of-Discharge-Voltage flag */
768c0984e5SSebastian Reichel #define BQ27000_FLAG_CI		BIT(4) /* Capacity Inaccurate flag */
778c0984e5SSebastian Reichel #define BQ27000_FLAG_FC		BIT(5)
788c0984e5SSebastian Reichel #define BQ27000_FLAG_CHGS	BIT(7) /* Charge state flag */
798c0984e5SSebastian Reichel 
808c0984e5SSebastian Reichel #define BQ27XXX_RS			(20) /* Resistor sense mOhm */
818c0984e5SSebastian Reichel #define BQ27XXX_POWER_CONSTANT		(29200) /* 29.2 µV^2 * 1000 */
828c0984e5SSebastian Reichel #define BQ27XXX_CURRENT_CONSTANT	(3570) /* 3.57 µV * 1000 */
838c0984e5SSebastian Reichel 
848c0984e5SSebastian Reichel #define INVALID_REG_ADDR	0xff
858c0984e5SSebastian Reichel 
868c0984e5SSebastian Reichel /*
878c0984e5SSebastian Reichel  * bq27xxx_reg_index - Register names
888c0984e5SSebastian Reichel  *
898c0984e5SSebastian Reichel  * These are indexes into a device's register mapping array.
908c0984e5SSebastian Reichel  */
918c0984e5SSebastian Reichel 
928c0984e5SSebastian Reichel enum bq27xxx_reg_index {
938c0984e5SSebastian Reichel 	BQ27XXX_REG_CTRL = 0,	/* Control */
948c0984e5SSebastian Reichel 	BQ27XXX_REG_TEMP,	/* Temperature */
958c0984e5SSebastian Reichel 	BQ27XXX_REG_INT_TEMP,	/* Internal Temperature */
968c0984e5SSebastian Reichel 	BQ27XXX_REG_VOLT,	/* Voltage */
978c0984e5SSebastian Reichel 	BQ27XXX_REG_AI,		/* Average Current */
988c0984e5SSebastian Reichel 	BQ27XXX_REG_FLAGS,	/* Flags */
998c0984e5SSebastian Reichel 	BQ27XXX_REG_TTE,	/* Time-to-Empty */
1008c0984e5SSebastian Reichel 	BQ27XXX_REG_TTF,	/* Time-to-Full */
1018c0984e5SSebastian Reichel 	BQ27XXX_REG_TTES,	/* Time-to-Empty Standby */
1028c0984e5SSebastian Reichel 	BQ27XXX_REG_TTECP,	/* Time-to-Empty at Constant Power */
1038c0984e5SSebastian Reichel 	BQ27XXX_REG_NAC,	/* Nominal Available Capacity */
1048c0984e5SSebastian Reichel 	BQ27XXX_REG_FCC,	/* Full Charge Capacity */
1058c0984e5SSebastian Reichel 	BQ27XXX_REG_CYCT,	/* Cycle Count */
1068c0984e5SSebastian Reichel 	BQ27XXX_REG_AE,		/* Available Energy */
1078c0984e5SSebastian Reichel 	BQ27XXX_REG_SOC,	/* State-of-Charge */
1088c0984e5SSebastian Reichel 	BQ27XXX_REG_DCAP,	/* Design Capacity */
1098c0984e5SSebastian Reichel 	BQ27XXX_REG_AP,		/* Average Power */
1108c0984e5SSebastian Reichel 	BQ27XXX_REG_MAX,	/* sentinel */
1118c0984e5SSebastian Reichel };
1128c0984e5SSebastian Reichel 
1138c0984e5SSebastian Reichel /* Register mappings */
1148c0984e5SSebastian Reichel static u8 bq27xxx_regs[][BQ27XXX_REG_MAX] = {
1158c0984e5SSebastian Reichel 	[BQ27000] = {
1168c0984e5SSebastian Reichel 		[BQ27XXX_REG_CTRL] = 0x00,
1178c0984e5SSebastian Reichel 		[BQ27XXX_REG_TEMP] = 0x06,
1188c0984e5SSebastian Reichel 		[BQ27XXX_REG_INT_TEMP] = INVALID_REG_ADDR,
1198c0984e5SSebastian Reichel 		[BQ27XXX_REG_VOLT] = 0x08,
1208c0984e5SSebastian Reichel 		[BQ27XXX_REG_AI] = 0x14,
1218c0984e5SSebastian Reichel 		[BQ27XXX_REG_FLAGS] = 0x0a,
1228c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTE] = 0x16,
1238c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTF] = 0x18,
1248c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTES] = 0x1c,
1258c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTECP] = 0x26,
1268c0984e5SSebastian Reichel 		[BQ27XXX_REG_NAC] = 0x0c,
1278c0984e5SSebastian Reichel 		[BQ27XXX_REG_FCC] = 0x12,
1288c0984e5SSebastian Reichel 		[BQ27XXX_REG_CYCT] = 0x2a,
1298c0984e5SSebastian Reichel 		[BQ27XXX_REG_AE] = 0x22,
1308c0984e5SSebastian Reichel 		[BQ27XXX_REG_SOC] = 0x0b,
1318c0984e5SSebastian Reichel 		[BQ27XXX_REG_DCAP] = 0x76,
1328c0984e5SSebastian Reichel 		[BQ27XXX_REG_AP] = 0x24,
1338c0984e5SSebastian Reichel 	},
1348c0984e5SSebastian Reichel 	[BQ27010] = {
1358c0984e5SSebastian Reichel 		[BQ27XXX_REG_CTRL] = 0x00,
1368c0984e5SSebastian Reichel 		[BQ27XXX_REG_TEMP] = 0x06,
1378c0984e5SSebastian Reichel 		[BQ27XXX_REG_INT_TEMP] = INVALID_REG_ADDR,
1388c0984e5SSebastian Reichel 		[BQ27XXX_REG_VOLT] = 0x08,
1398c0984e5SSebastian Reichel 		[BQ27XXX_REG_AI] = 0x14,
1408c0984e5SSebastian Reichel 		[BQ27XXX_REG_FLAGS] = 0x0a,
1418c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTE] = 0x16,
1428c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTF] = 0x18,
1438c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTES] = 0x1c,
1448c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTECP] = 0x26,
1458c0984e5SSebastian Reichel 		[BQ27XXX_REG_NAC] = 0x0c,
1468c0984e5SSebastian Reichel 		[BQ27XXX_REG_FCC] = 0x12,
1478c0984e5SSebastian Reichel 		[BQ27XXX_REG_CYCT] = 0x2a,
1488c0984e5SSebastian Reichel 		[BQ27XXX_REG_AE] = INVALID_REG_ADDR,
1498c0984e5SSebastian Reichel 		[BQ27XXX_REG_SOC] = 0x0b,
1508c0984e5SSebastian Reichel 		[BQ27XXX_REG_DCAP] = 0x76,
1518c0984e5SSebastian Reichel 		[BQ27XXX_REG_AP] = INVALID_REG_ADDR,
1528c0984e5SSebastian Reichel 	},
153818e3012SChris Lapa 	[BQ2750X] = {
1548c0984e5SSebastian Reichel 		[BQ27XXX_REG_CTRL] = 0x00,
1558c0984e5SSebastian Reichel 		[BQ27XXX_REG_TEMP] = 0x06,
1568c0984e5SSebastian Reichel 		[BQ27XXX_REG_INT_TEMP] = 0x28,
1578c0984e5SSebastian Reichel 		[BQ27XXX_REG_VOLT] = 0x08,
1588c0984e5SSebastian Reichel 		[BQ27XXX_REG_AI] = 0x14,
1598c0984e5SSebastian Reichel 		[BQ27XXX_REG_FLAGS] = 0x0a,
1608c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTE] = 0x16,
1618c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
1628c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTES] = 0x1a,
1638c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
1648c0984e5SSebastian Reichel 		[BQ27XXX_REG_NAC] = 0x0c,
1658c0984e5SSebastian Reichel 		[BQ27XXX_REG_FCC] = 0x12,
1668c0984e5SSebastian Reichel 		[BQ27XXX_REG_CYCT] = 0x2a,
1678c0984e5SSebastian Reichel 		[BQ27XXX_REG_AE] = INVALID_REG_ADDR,
1688c0984e5SSebastian Reichel 		[BQ27XXX_REG_SOC] = 0x2c,
1698c0984e5SSebastian Reichel 		[BQ27XXX_REG_DCAP] = 0x3c,
1708c0984e5SSebastian Reichel 		[BQ27XXX_REG_AP] = INVALID_REG_ADDR,
1718c0984e5SSebastian Reichel 	},
1726da6e4bdSChris Lapa 	[BQ2751X] = {
1733bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_CTRL] = 0x00,
1743bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_TEMP] = 0x06,
1753bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_INT_TEMP] = 0x28,
1763bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_VOLT] = 0x08,
1773bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_AI] = 0x14,
1783bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_FLAGS] = 0x0a,
1793bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_TTE] = 0x16,
1803bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
1813bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_TTES] = 0x1a,
1823bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
1833bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_NAC] = 0x0c,
1843bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_FCC] = 0x12,
1853bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_CYCT] = 0x1e,
1863bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_AE] = INVALID_REG_ADDR,
1873bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_SOC] = 0x20,
1883bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_DCAP] = 0x2e,
1893bee9ea1SAndrew F. Davis 		[BQ27XXX_REG_AP] = INVALID_REG_ADDR,
1903bee9ea1SAndrew F. Davis 	},
19132833635SChris Lapa 	[BQ27500] = {
19232833635SChris Lapa 		[BQ27XXX_REG_CTRL] = 0x00,
19332833635SChris Lapa 		[BQ27XXX_REG_TEMP] = 0x06,
19432833635SChris Lapa 		[BQ27XXX_REG_INT_TEMP] = INVALID_REG_ADDR,
19532833635SChris Lapa 		[BQ27XXX_REG_VOLT] = 0x08,
19632833635SChris Lapa 		[BQ27XXX_REG_AI] = 0x14,
19732833635SChris Lapa 		[BQ27XXX_REG_FLAGS] = 0x0a,
19832833635SChris Lapa 		[BQ27XXX_REG_TTE] = 0x16,
19932833635SChris Lapa 		[BQ27XXX_REG_TTF] = 0x18,
20032833635SChris Lapa 		[BQ27XXX_REG_TTES] = 0x1c,
20132833635SChris Lapa 		[BQ27XXX_REG_TTECP] = 0x26,
20232833635SChris Lapa 		[BQ27XXX_REG_NAC] = 0x0c,
20332833635SChris Lapa 		[BQ27XXX_REG_FCC] = 0x12,
20432833635SChris Lapa 		[BQ27XXX_REG_CYCT] = 0x2a,
20532833635SChris Lapa 		[BQ27XXX_REG_AE] = 0x22,
20632833635SChris Lapa 		[BQ27XXX_REG_SOC] = 0x2c,
20732833635SChris Lapa 		[BQ27XXX_REG_DCAP] = 0x3c,
20832833635SChris Lapa 		[BQ27XXX_REG_AP] = 0x24,
20932833635SChris Lapa 	},
210bd28177fSChris Lapa 	[BQ27510G1] = {
211bd28177fSChris Lapa 		[BQ27XXX_REG_CTRL] = 0x00,
212bd28177fSChris Lapa 		[BQ27XXX_REG_TEMP] = 0x06,
213bd28177fSChris Lapa 		[BQ27XXX_REG_INT_TEMP] = INVALID_REG_ADDR,
214bd28177fSChris Lapa 		[BQ27XXX_REG_VOLT] = 0x08,
215bd28177fSChris Lapa 		[BQ27XXX_REG_AI] = 0x14,
216bd28177fSChris Lapa 		[BQ27XXX_REG_FLAGS] = 0x0a,
217bd28177fSChris Lapa 		[BQ27XXX_REG_TTE] = 0x16,
218bd28177fSChris Lapa 		[BQ27XXX_REG_TTF] = 0x18,
219bd28177fSChris Lapa 		[BQ27XXX_REG_TTES] = 0x1c,
220bd28177fSChris Lapa 		[BQ27XXX_REG_TTECP] = 0x26,
221bd28177fSChris Lapa 		[BQ27XXX_REG_NAC] = 0x0c,
222bd28177fSChris Lapa 		[BQ27XXX_REG_FCC] = 0x12,
223bd28177fSChris Lapa 		[BQ27XXX_REG_CYCT] = 0x2a,
224bd28177fSChris Lapa 		[BQ27XXX_REG_AE] = 0x22,
225bd28177fSChris Lapa 		[BQ27XXX_REG_SOC] = 0x2c,
226bd28177fSChris Lapa 		[BQ27XXX_REG_DCAP] = 0x3c,
227bd28177fSChris Lapa 		[BQ27XXX_REG_AP] = 0x24,
228bd28177fSChris Lapa 	},
229698a2bf5SChris Lapa 	[BQ27510G2] = {
230698a2bf5SChris Lapa 		[BQ27XXX_REG_CTRL] = 0x00,
231698a2bf5SChris Lapa 		[BQ27XXX_REG_TEMP] = 0x06,
232698a2bf5SChris Lapa 		[BQ27XXX_REG_INT_TEMP] = INVALID_REG_ADDR,
233698a2bf5SChris Lapa 		[BQ27XXX_REG_VOLT] = 0x08,
234698a2bf5SChris Lapa 		[BQ27XXX_REG_AI] = 0x14,
235698a2bf5SChris Lapa 		[BQ27XXX_REG_FLAGS] = 0x0a,
236698a2bf5SChris Lapa 		[BQ27XXX_REG_TTE] = 0x16,
237698a2bf5SChris Lapa 		[BQ27XXX_REG_TTF] = 0x18,
238698a2bf5SChris Lapa 		[BQ27XXX_REG_TTES] = 0x1c,
239698a2bf5SChris Lapa 		[BQ27XXX_REG_TTECP] = 0x26,
240698a2bf5SChris Lapa 		[BQ27XXX_REG_NAC] = 0x0c,
241698a2bf5SChris Lapa 		[BQ27XXX_REG_FCC] = 0x12,
242698a2bf5SChris Lapa 		[BQ27XXX_REG_CYCT] = 0x2a,
243698a2bf5SChris Lapa 		[BQ27XXX_REG_AE] = 0x22,
244698a2bf5SChris Lapa 		[BQ27XXX_REG_SOC] = 0x2c,
245698a2bf5SChris Lapa 		[BQ27XXX_REG_DCAP] = 0x3c,
246698a2bf5SChris Lapa 		[BQ27XXX_REG_AP] = 0x24,
247698a2bf5SChris Lapa 	},
24871375aa7SChris Lapa 	[BQ27510G3] = {
24971375aa7SChris Lapa 		[BQ27XXX_REG_CTRL] = 0x00,
25071375aa7SChris Lapa 		[BQ27XXX_REG_TEMP] = 0x06,
25171375aa7SChris Lapa 		[BQ27XXX_REG_INT_TEMP] = 0x28,
25271375aa7SChris Lapa 		[BQ27XXX_REG_VOLT] = 0x08,
25371375aa7SChris Lapa 		[BQ27XXX_REG_AI] = 0x14,
25471375aa7SChris Lapa 		[BQ27XXX_REG_FLAGS] = 0x0a,
25571375aa7SChris Lapa 		[BQ27XXX_REG_TTE] = 0x16,
25671375aa7SChris Lapa 		[BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
25771375aa7SChris Lapa 		[BQ27XXX_REG_TTES] = 0x1a,
25871375aa7SChris Lapa 		[BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
25971375aa7SChris Lapa 		[BQ27XXX_REG_NAC] = 0x0c,
26071375aa7SChris Lapa 		[BQ27XXX_REG_FCC] = 0x12,
26171375aa7SChris Lapa 		[BQ27XXX_REG_CYCT] = 0x1e,
26271375aa7SChris Lapa 		[BQ27XXX_REG_AE] = INVALID_REG_ADDR,
26371375aa7SChris Lapa 		[BQ27XXX_REG_SOC] = 0x20,
26471375aa7SChris Lapa 		[BQ27XXX_REG_DCAP] = 0x2e,
26571375aa7SChris Lapa 		[BQ27XXX_REG_AP] = INVALID_REG_ADDR,
26671375aa7SChris Lapa 	},
26768f2a813SChris Lapa 	[BQ27520G1] = {
26868f2a813SChris Lapa 		[BQ27XXX_REG_CTRL] = 0x00,
26968f2a813SChris Lapa 		[BQ27XXX_REG_TEMP] = 0x06,
27068f2a813SChris Lapa 		[BQ27XXX_REG_INT_TEMP] = INVALID_REG_ADDR,
27168f2a813SChris Lapa 		[BQ27XXX_REG_VOLT] = 0x08,
27268f2a813SChris Lapa 		[BQ27XXX_REG_AI] = 0x14,
27368f2a813SChris Lapa 		[BQ27XXX_REG_FLAGS] = 0x0a,
27468f2a813SChris Lapa 		[BQ27XXX_REG_TTE] = 0x16,
27568f2a813SChris Lapa 		[BQ27XXX_REG_TTF] = 0x18,
27668f2a813SChris Lapa 		[BQ27XXX_REG_TTES] = 0x1c,
27768f2a813SChris Lapa 		[BQ27XXX_REG_TTECP] = 0x26,
27868f2a813SChris Lapa 		[BQ27XXX_REG_NAC] = 0x0c,
27968f2a813SChris Lapa 		[BQ27XXX_REG_FCC] = 0x12,
28068f2a813SChris Lapa 		[BQ27XXX_REG_CYCT] = INVALID_REG_ADDR,
28168f2a813SChris Lapa 		[BQ27XXX_REG_AE] = 0x22,
28268f2a813SChris Lapa 		[BQ27XXX_REG_SOC] = 0x2c,
28368f2a813SChris Lapa 		[BQ27XXX_REG_DCAP] = 0x3c,
28468f2a813SChris Lapa 		[BQ27XXX_REG_AP] = 0x24,
28568f2a813SChris Lapa 	},
286a5deb9a9SChris Lapa 	[BQ27520G2] = {
287a5deb9a9SChris Lapa 		[BQ27XXX_REG_CTRL] = 0x00,
288a5deb9a9SChris Lapa 		[BQ27XXX_REG_TEMP] = 0x06,
289a5deb9a9SChris Lapa 		[BQ27XXX_REG_INT_TEMP] = 0x36,
290a5deb9a9SChris Lapa 		[BQ27XXX_REG_VOLT] = 0x08,
291a5deb9a9SChris Lapa 		[BQ27XXX_REG_AI] = 0x14,
292a5deb9a9SChris Lapa 		[BQ27XXX_REG_FLAGS] = 0x0a,
293a5deb9a9SChris Lapa 		[BQ27XXX_REG_TTE] = 0x16,
294a5deb9a9SChris Lapa 		[BQ27XXX_REG_TTF] = 0x18,
295a5deb9a9SChris Lapa 		[BQ27XXX_REG_TTES] = 0x1c,
296a5deb9a9SChris Lapa 		[BQ27XXX_REG_TTECP] = 0x26,
297a5deb9a9SChris Lapa 		[BQ27XXX_REG_NAC] = 0x0c,
298a5deb9a9SChris Lapa 		[BQ27XXX_REG_FCC] = 0x12,
299a5deb9a9SChris Lapa 		[BQ27XXX_REG_CYCT] = 0x2a,
300a5deb9a9SChris Lapa 		[BQ27XXX_REG_AE] = 0x22,
301a5deb9a9SChris Lapa 		[BQ27XXX_REG_SOC] = 0x2c,
302a5deb9a9SChris Lapa 		[BQ27XXX_REG_DCAP] = 0x3c,
303a5deb9a9SChris Lapa 		[BQ27XXX_REG_AP] = 0x24,
304a5deb9a9SChris Lapa 	},
305825e915bSChris Lapa 	[BQ27520G3] = {
306825e915bSChris Lapa 		[BQ27XXX_REG_CTRL] = 0x00,
307825e915bSChris Lapa 		[BQ27XXX_REG_TEMP] = 0x06,
308825e915bSChris Lapa 		[BQ27XXX_REG_INT_TEMP] = 0x36,
309825e915bSChris Lapa 		[BQ27XXX_REG_VOLT] = 0x08,
310825e915bSChris Lapa 		[BQ27XXX_REG_AI] = 0x14,
311825e915bSChris Lapa 		[BQ27XXX_REG_FLAGS] = 0x0a,
312825e915bSChris Lapa 		[BQ27XXX_REG_TTE] = 0x16,
313825e915bSChris Lapa 		[BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
314825e915bSChris Lapa 		[BQ27XXX_REG_TTES] = 0x1c,
315825e915bSChris Lapa 		[BQ27XXX_REG_TTECP] = 0x26,
316825e915bSChris Lapa 		[BQ27XXX_REG_NAC] = 0x0c,
317825e915bSChris Lapa 		[BQ27XXX_REG_FCC] = 0x12,
318825e915bSChris Lapa 		[BQ27XXX_REG_CYCT] = 0x2a,
319825e915bSChris Lapa 		[BQ27XXX_REG_AE] = 0x22,
320825e915bSChris Lapa 		[BQ27XXX_REG_SOC] = 0x2c,
321825e915bSChris Lapa 		[BQ27XXX_REG_DCAP] = 0x3c,
322825e915bSChris Lapa 		[BQ27XXX_REG_AP] = 0x24,
323825e915bSChris Lapa 	},
3248c0984e5SSebastian Reichel 	[BQ27530] = {
3258c0984e5SSebastian Reichel 		[BQ27XXX_REG_CTRL] = 0x00,
3268c0984e5SSebastian Reichel 		[BQ27XXX_REG_TEMP] = 0x06,
3278c0984e5SSebastian Reichel 		[BQ27XXX_REG_INT_TEMP] = 0x32,
3288c0984e5SSebastian Reichel 		[BQ27XXX_REG_VOLT] = 0x08,
3298c0984e5SSebastian Reichel 		[BQ27XXX_REG_AI] = 0x14,
3308c0984e5SSebastian Reichel 		[BQ27XXX_REG_FLAGS] = 0x0a,
3318c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTE] = 0x16,
3328c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
3338c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTES] = INVALID_REG_ADDR,
3348c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
3358c0984e5SSebastian Reichel 		[BQ27XXX_REG_NAC] = 0x0c,
3368c0984e5SSebastian Reichel 		[BQ27XXX_REG_FCC] = 0x12,
3378c0984e5SSebastian Reichel 		[BQ27XXX_REG_CYCT] = 0x2a,
3388c0984e5SSebastian Reichel 		[BQ27XXX_REG_AE] = INVALID_REG_ADDR,
3398c0984e5SSebastian Reichel 		[BQ27XXX_REG_SOC] = 0x2c,
3408c0984e5SSebastian Reichel 		[BQ27XXX_REG_DCAP] = INVALID_REG_ADDR,
3418c0984e5SSebastian Reichel 		[BQ27XXX_REG_AP] = 0x24,
3428c0984e5SSebastian Reichel 	},
3438c0984e5SSebastian Reichel 	[BQ27541] = {
3448c0984e5SSebastian Reichel 		[BQ27XXX_REG_CTRL] = 0x00,
3458c0984e5SSebastian Reichel 		[BQ27XXX_REG_TEMP] = 0x06,
3468c0984e5SSebastian Reichel 		[BQ27XXX_REG_INT_TEMP] = 0x28,
3478c0984e5SSebastian Reichel 		[BQ27XXX_REG_VOLT] = 0x08,
3488c0984e5SSebastian Reichel 		[BQ27XXX_REG_AI] = 0x14,
3498c0984e5SSebastian Reichel 		[BQ27XXX_REG_FLAGS] = 0x0a,
3508c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTE] = 0x16,
3518c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
3528c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTES] = INVALID_REG_ADDR,
3538c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
3548c0984e5SSebastian Reichel 		[BQ27XXX_REG_NAC] = 0x0c,
3558c0984e5SSebastian Reichel 		[BQ27XXX_REG_FCC] = 0x12,
3568c0984e5SSebastian Reichel 		[BQ27XXX_REG_CYCT] = 0x2a,
3578c0984e5SSebastian Reichel 		[BQ27XXX_REG_AE] = INVALID_REG_ADDR,
3588c0984e5SSebastian Reichel 		[BQ27XXX_REG_SOC] = 0x2c,
3598c0984e5SSebastian Reichel 		[BQ27XXX_REG_DCAP] = 0x3c,
3608c0984e5SSebastian Reichel 		[BQ27XXX_REG_AP] = 0x24,
3618c0984e5SSebastian Reichel 	},
3628c0984e5SSebastian Reichel 	[BQ27545] = {
3638c0984e5SSebastian Reichel 		[BQ27XXX_REG_CTRL] = 0x00,
3648c0984e5SSebastian Reichel 		[BQ27XXX_REG_TEMP] = 0x06,
3658c0984e5SSebastian Reichel 		[BQ27XXX_REG_INT_TEMP] = 0x28,
3668c0984e5SSebastian Reichel 		[BQ27XXX_REG_VOLT] = 0x08,
3678c0984e5SSebastian Reichel 		[BQ27XXX_REG_AI] = 0x14,
3688c0984e5SSebastian Reichel 		[BQ27XXX_REG_FLAGS] = 0x0a,
3698c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTE] = 0x16,
3708c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
3718c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTES] = INVALID_REG_ADDR,
3728c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
3738c0984e5SSebastian Reichel 		[BQ27XXX_REG_NAC] = 0x0c,
3748c0984e5SSebastian Reichel 		[BQ27XXX_REG_FCC] = 0x12,
3758c0984e5SSebastian Reichel 		[BQ27XXX_REG_CYCT] = 0x2a,
3768c0984e5SSebastian Reichel 		[BQ27XXX_REG_AE] = INVALID_REG_ADDR,
3778c0984e5SSebastian Reichel 		[BQ27XXX_REG_SOC] = 0x2c,
3788c0984e5SSebastian Reichel 		[BQ27XXX_REG_DCAP] = INVALID_REG_ADDR,
3798c0984e5SSebastian Reichel 		[BQ27XXX_REG_AP] = 0x24,
3808c0984e5SSebastian Reichel 	},
3818c0984e5SSebastian Reichel 	[BQ27421] = {
3828c0984e5SSebastian Reichel 		[BQ27XXX_REG_CTRL] = 0x00,
3838c0984e5SSebastian Reichel 		[BQ27XXX_REG_TEMP] = 0x02,
3848c0984e5SSebastian Reichel 		[BQ27XXX_REG_INT_TEMP] = 0x1e,
3858c0984e5SSebastian Reichel 		[BQ27XXX_REG_VOLT] = 0x04,
3868c0984e5SSebastian Reichel 		[BQ27XXX_REG_AI] = 0x10,
3878c0984e5SSebastian Reichel 		[BQ27XXX_REG_FLAGS] = 0x06,
3888c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTE] = INVALID_REG_ADDR,
3898c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTF] = INVALID_REG_ADDR,
3908c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTES] = INVALID_REG_ADDR,
3918c0984e5SSebastian Reichel 		[BQ27XXX_REG_TTECP] = INVALID_REG_ADDR,
3928c0984e5SSebastian Reichel 		[BQ27XXX_REG_NAC] = 0x08,
3938c0984e5SSebastian Reichel 		[BQ27XXX_REG_FCC] = 0x0e,
3948c0984e5SSebastian Reichel 		[BQ27XXX_REG_CYCT] = INVALID_REG_ADDR,
3958c0984e5SSebastian Reichel 		[BQ27XXX_REG_AE] = INVALID_REG_ADDR,
3968c0984e5SSebastian Reichel 		[BQ27XXX_REG_SOC] = 0x1c,
3978c0984e5SSebastian Reichel 		[BQ27XXX_REG_DCAP] = 0x3c,
3988c0984e5SSebastian Reichel 		[BQ27XXX_REG_AP] = 0x18,
3998c0984e5SSebastian Reichel 	},
4008c0984e5SSebastian Reichel };
4018c0984e5SSebastian Reichel 
4028c0984e5SSebastian Reichel static enum power_supply_property bq27000_battery_props[] = {
4038c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_STATUS,
4048c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_PRESENT,
4058c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
4068c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CURRENT_NOW,
4078c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY,
4088c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
4098c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TEMP,
4108c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
4118c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
4128c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
4138c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TECHNOLOGY,
4148c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_FULL,
4158c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_NOW,
4168c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
4178c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CYCLE_COUNT,
4188c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_ENERGY_NOW,
4198c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_POWER_AVG,
4208c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_HEALTH,
4218c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_MANUFACTURER,
4228c0984e5SSebastian Reichel };
4238c0984e5SSebastian Reichel 
4248c0984e5SSebastian Reichel static enum power_supply_property bq27010_battery_props[] = {
4258c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_STATUS,
4268c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_PRESENT,
4278c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
4288c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CURRENT_NOW,
4298c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY,
4308c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
4318c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TEMP,
4328c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
4338c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
4348c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
4358c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TECHNOLOGY,
4368c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_FULL,
4378c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_NOW,
4388c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
4398c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CYCLE_COUNT,
4408c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_HEALTH,
4418c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_MANUFACTURER,
4428c0984e5SSebastian Reichel };
4438c0984e5SSebastian Reichel 
444818e3012SChris Lapa static enum power_supply_property bq2750x_battery_props[] = {
4458c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_STATUS,
4468c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_PRESENT,
4478c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
4488c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CURRENT_NOW,
4498c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY,
4508c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
4518c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TEMP,
4528c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
4538c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TECHNOLOGY,
4548c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_FULL,
4558c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_NOW,
4568c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
4578c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CYCLE_COUNT,
4588c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_HEALTH,
4598c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_MANUFACTURER,
4608c0984e5SSebastian Reichel };
4618c0984e5SSebastian Reichel 
4626da6e4bdSChris Lapa static enum power_supply_property bq2751x_battery_props[] = {
4633bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_STATUS,
4643bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_PRESENT,
4653bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
4663bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_CURRENT_NOW,
4673bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_CAPACITY,
4683bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
4693bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_TEMP,
4703bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
4713bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_TECHNOLOGY,
4723bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_CHARGE_FULL,
4733bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_CHARGE_NOW,
4743bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
4753bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_CYCLE_COUNT,
4763bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_HEALTH,
4773bee9ea1SAndrew F. Davis 	POWER_SUPPLY_PROP_MANUFACTURER,
4783bee9ea1SAndrew F. Davis };
4793bee9ea1SAndrew F. Davis 
48032833635SChris Lapa static enum power_supply_property bq27500_battery_props[] = {
48132833635SChris Lapa 	POWER_SUPPLY_PROP_STATUS,
48232833635SChris Lapa 	POWER_SUPPLY_PROP_PRESENT,
48332833635SChris Lapa 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
48432833635SChris Lapa 	POWER_SUPPLY_PROP_CURRENT_NOW,
48532833635SChris Lapa 	POWER_SUPPLY_PROP_CAPACITY,
48632833635SChris Lapa 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
48732833635SChris Lapa 	POWER_SUPPLY_PROP_TEMP,
48832833635SChris Lapa 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
48932833635SChris Lapa 	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
49032833635SChris Lapa 	POWER_SUPPLY_PROP_TECHNOLOGY,
49132833635SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL,
49232833635SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_NOW,
49332833635SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
49432833635SChris Lapa 	POWER_SUPPLY_PROP_CYCLE_COUNT,
49532833635SChris Lapa 	POWER_SUPPLY_PROP_ENERGY_NOW,
49632833635SChris Lapa 	POWER_SUPPLY_PROP_POWER_AVG,
49732833635SChris Lapa 	POWER_SUPPLY_PROP_HEALTH,
49832833635SChris Lapa 	POWER_SUPPLY_PROP_MANUFACTURER,
49932833635SChris Lapa };
50032833635SChris Lapa 
501bd28177fSChris Lapa static enum power_supply_property bq27510g1_battery_props[] = {
502bd28177fSChris Lapa 	POWER_SUPPLY_PROP_STATUS,
503bd28177fSChris Lapa 	POWER_SUPPLY_PROP_PRESENT,
504bd28177fSChris Lapa 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
505bd28177fSChris Lapa 	POWER_SUPPLY_PROP_CURRENT_NOW,
506bd28177fSChris Lapa 	POWER_SUPPLY_PROP_CAPACITY,
507bd28177fSChris Lapa 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
508bd28177fSChris Lapa 	POWER_SUPPLY_PROP_TEMP,
509bd28177fSChris Lapa 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
510bd28177fSChris Lapa 	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
511bd28177fSChris Lapa 	POWER_SUPPLY_PROP_TECHNOLOGY,
512bd28177fSChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL,
513bd28177fSChris Lapa 	POWER_SUPPLY_PROP_CHARGE_NOW,
514bd28177fSChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
515bd28177fSChris Lapa 	POWER_SUPPLY_PROP_CYCLE_COUNT,
516bd28177fSChris Lapa 	POWER_SUPPLY_PROP_ENERGY_NOW,
517bd28177fSChris Lapa 	POWER_SUPPLY_PROP_POWER_AVG,
518bd28177fSChris Lapa 	POWER_SUPPLY_PROP_HEALTH,
519bd28177fSChris Lapa 	POWER_SUPPLY_PROP_MANUFACTURER,
520bd28177fSChris Lapa };
521bd28177fSChris Lapa 
522698a2bf5SChris Lapa static enum power_supply_property bq27510g2_battery_props[] = {
523698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_STATUS,
524698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_PRESENT,
525698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
526698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_CURRENT_NOW,
527698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_CAPACITY,
528698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
529698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_TEMP,
530698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
531698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
532698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_TECHNOLOGY,
533698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL,
534698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_NOW,
535698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
536698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_CYCLE_COUNT,
537698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_ENERGY_NOW,
538698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_POWER_AVG,
539698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_HEALTH,
540698a2bf5SChris Lapa 	POWER_SUPPLY_PROP_MANUFACTURER,
541698a2bf5SChris Lapa };
542698a2bf5SChris Lapa 
54371375aa7SChris Lapa static enum power_supply_property bq27510g3_battery_props[] = {
54471375aa7SChris Lapa 	POWER_SUPPLY_PROP_STATUS,
54571375aa7SChris Lapa 	POWER_SUPPLY_PROP_PRESENT,
54671375aa7SChris Lapa 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
54771375aa7SChris Lapa 	POWER_SUPPLY_PROP_CURRENT_NOW,
54871375aa7SChris Lapa 	POWER_SUPPLY_PROP_CAPACITY,
54971375aa7SChris Lapa 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
55071375aa7SChris Lapa 	POWER_SUPPLY_PROP_TEMP,
55171375aa7SChris Lapa 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
55271375aa7SChris Lapa 	POWER_SUPPLY_PROP_TECHNOLOGY,
55371375aa7SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL,
55471375aa7SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_NOW,
55571375aa7SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
55671375aa7SChris Lapa 	POWER_SUPPLY_PROP_CYCLE_COUNT,
55771375aa7SChris Lapa 	POWER_SUPPLY_PROP_HEALTH,
55871375aa7SChris Lapa 	POWER_SUPPLY_PROP_MANUFACTURER,
55971375aa7SChris Lapa };
56071375aa7SChris Lapa 
56168f2a813SChris Lapa static enum power_supply_property bq27520g1_battery_props[] = {
56268f2a813SChris Lapa 	POWER_SUPPLY_PROP_STATUS,
56368f2a813SChris Lapa 	POWER_SUPPLY_PROP_PRESENT,
56468f2a813SChris Lapa 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
56568f2a813SChris Lapa 	POWER_SUPPLY_PROP_CURRENT_NOW,
56668f2a813SChris Lapa 	POWER_SUPPLY_PROP_CAPACITY,
56768f2a813SChris Lapa 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
56868f2a813SChris Lapa 	POWER_SUPPLY_PROP_TEMP,
56968f2a813SChris Lapa 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
57068f2a813SChris Lapa 	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
57168f2a813SChris Lapa 	POWER_SUPPLY_PROP_TECHNOLOGY,
57268f2a813SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL,
57368f2a813SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_NOW,
57468f2a813SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
57568f2a813SChris Lapa 	POWER_SUPPLY_PROP_ENERGY_NOW,
57668f2a813SChris Lapa 	POWER_SUPPLY_PROP_POWER_AVG,
57768f2a813SChris Lapa 	POWER_SUPPLY_PROP_HEALTH,
57868f2a813SChris Lapa 	POWER_SUPPLY_PROP_MANUFACTURER,
57968f2a813SChris Lapa };
58068f2a813SChris Lapa 
581a5deb9a9SChris Lapa static enum power_supply_property bq27520g2_battery_props[] = {
582a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_STATUS,
583a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_PRESENT,
584a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
585a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_CURRENT_NOW,
586a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_CAPACITY,
587a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
588a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_TEMP,
589a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
590a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
591a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_TECHNOLOGY,
592a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL,
593a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_NOW,
594a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
595a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_CYCLE_COUNT,
596a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_ENERGY_NOW,
597a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_POWER_AVG,
598a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_HEALTH,
599a5deb9a9SChris Lapa 	POWER_SUPPLY_PROP_MANUFACTURER,
600a5deb9a9SChris Lapa };
601a5deb9a9SChris Lapa 
602825e915bSChris Lapa static enum power_supply_property bq27520g3_battery_props[] = {
603825e915bSChris Lapa 	POWER_SUPPLY_PROP_STATUS,
604825e915bSChris Lapa 	POWER_SUPPLY_PROP_PRESENT,
605825e915bSChris Lapa 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
606825e915bSChris Lapa 	POWER_SUPPLY_PROP_CURRENT_NOW,
607825e915bSChris Lapa 	POWER_SUPPLY_PROP_CAPACITY,
608825e915bSChris Lapa 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
609825e915bSChris Lapa 	POWER_SUPPLY_PROP_TEMP,
610825e915bSChris Lapa 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
611825e915bSChris Lapa 	POWER_SUPPLY_PROP_TECHNOLOGY,
612825e915bSChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL,
613825e915bSChris Lapa 	POWER_SUPPLY_PROP_CHARGE_NOW,
614825e915bSChris Lapa 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
615825e915bSChris Lapa 	POWER_SUPPLY_PROP_CYCLE_COUNT,
616825e915bSChris Lapa 	POWER_SUPPLY_PROP_ENERGY_NOW,
617825e915bSChris Lapa 	POWER_SUPPLY_PROP_POWER_AVG,
618825e915bSChris Lapa 	POWER_SUPPLY_PROP_HEALTH,
619825e915bSChris Lapa 	POWER_SUPPLY_PROP_MANUFACTURER,
620825e915bSChris Lapa };
621825e915bSChris Lapa 
6228c0984e5SSebastian Reichel static enum power_supply_property bq27530_battery_props[] = {
6238c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_STATUS,
6248c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_PRESENT,
6258c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
6268c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CURRENT_NOW,
6278c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY,
6288c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
6298c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TEMP,
6308c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
6318c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TECHNOLOGY,
6328c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_FULL,
6338c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_NOW,
6348c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_POWER_AVG,
6358c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_HEALTH,
6368c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CYCLE_COUNT,
6378c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_MANUFACTURER,
6388c0984e5SSebastian Reichel };
6398c0984e5SSebastian Reichel 
6408c0984e5SSebastian Reichel static enum power_supply_property bq27541_battery_props[] = {
6418c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_STATUS,
6428c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_PRESENT,
6438c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
6448c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CURRENT_NOW,
6458c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY,
6468c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
6478c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TEMP,
6488c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
6498c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TECHNOLOGY,
6508c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_FULL,
6518c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_NOW,
6528c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
6538c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CYCLE_COUNT,
6548c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_POWER_AVG,
6558c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_HEALTH,
6568c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_MANUFACTURER,
6578c0984e5SSebastian Reichel };
6588c0984e5SSebastian Reichel 
6598c0984e5SSebastian Reichel static enum power_supply_property bq27545_battery_props[] = {
6608c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_STATUS,
6618c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_PRESENT,
6628c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
6638c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CURRENT_NOW,
6648c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY,
6658c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
6668c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TEMP,
6678c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
6688c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TECHNOLOGY,
6698c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_FULL,
6708c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_NOW,
6718c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_HEALTH,
6728c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CYCLE_COUNT,
6738c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_POWER_AVG,
6748c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_MANUFACTURER,
6758c0984e5SSebastian Reichel };
6768c0984e5SSebastian Reichel 
6778c0984e5SSebastian Reichel static enum power_supply_property bq27421_battery_props[] = {
6788c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_STATUS,
6798c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_PRESENT,
6808c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
6818c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CURRENT_NOW,
6828c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY,
6838c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
6848c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TEMP,
6858c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_TECHNOLOGY,
6868c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_FULL,
6878c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_NOW,
6888c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
6898c0984e5SSebastian Reichel 	POWER_SUPPLY_PROP_MANUFACTURER,
6908c0984e5SSebastian Reichel };
6918c0984e5SSebastian Reichel 
6928c0984e5SSebastian Reichel #define BQ27XXX_PROP(_id, _prop)		\
6938c0984e5SSebastian Reichel 	[_id] = {				\
6948c0984e5SSebastian Reichel 		.props = _prop,			\
6958c0984e5SSebastian Reichel 		.size = ARRAY_SIZE(_prop),	\
6968c0984e5SSebastian Reichel 	}
6978c0984e5SSebastian Reichel 
6988c0984e5SSebastian Reichel static struct {
6998c0984e5SSebastian Reichel 	enum power_supply_property *props;
7008c0984e5SSebastian Reichel 	size_t size;
7018c0984e5SSebastian Reichel } bq27xxx_battery_props[] = {
7028c0984e5SSebastian Reichel 	BQ27XXX_PROP(BQ27000, bq27000_battery_props),
7038c0984e5SSebastian Reichel 	BQ27XXX_PROP(BQ27010, bq27010_battery_props),
704818e3012SChris Lapa 	BQ27XXX_PROP(BQ2750X, bq2750x_battery_props),
7056da6e4bdSChris Lapa 	BQ27XXX_PROP(BQ2751X, bq2751x_battery_props),
70632833635SChris Lapa 	BQ27XXX_PROP(BQ27500, bq27500_battery_props),
707bd28177fSChris Lapa 	BQ27XXX_PROP(BQ27510G1, bq27510g1_battery_props),
708698a2bf5SChris Lapa 	BQ27XXX_PROP(BQ27510G2, bq27510g2_battery_props),
70971375aa7SChris Lapa 	BQ27XXX_PROP(BQ27510G3, bq27510g3_battery_props),
71068f2a813SChris Lapa 	BQ27XXX_PROP(BQ27520G1, bq27520g1_battery_props),
711a5deb9a9SChris Lapa 	BQ27XXX_PROP(BQ27520G2, bq27520g2_battery_props),
712825e915bSChris Lapa 	BQ27XXX_PROP(BQ27520G3, bq27520g3_battery_props),
7138c0984e5SSebastian Reichel 	BQ27XXX_PROP(BQ27530, bq27530_battery_props),
7148c0984e5SSebastian Reichel 	BQ27XXX_PROP(BQ27541, bq27541_battery_props),
7158c0984e5SSebastian Reichel 	BQ27XXX_PROP(BQ27545, bq27545_battery_props),
7168c0984e5SSebastian Reichel 	BQ27XXX_PROP(BQ27421, bq27421_battery_props),
7178c0984e5SSebastian Reichel };
7188c0984e5SSebastian Reichel 
7191d72706fSMatt Ranostay static DEFINE_MUTEX(bq27xxx_list_lock);
7201d72706fSMatt Ranostay static LIST_HEAD(bq27xxx_battery_devices);
7211d72706fSMatt Ranostay 
7221d72706fSMatt Ranostay static int poll_interval_param_set(const char *val, const struct kernel_param *kp)
7231d72706fSMatt Ranostay {
7241d72706fSMatt Ranostay 	struct bq27xxx_device_info *di;
725950b6c2dSMatt Ranostay 	unsigned int prev_val = *(unsigned int *) kp->arg;
7261d72706fSMatt Ranostay 	int ret;
7271d72706fSMatt Ranostay 
7281d72706fSMatt Ranostay 	ret = param_set_uint(val, kp);
729950b6c2dSMatt Ranostay 	if (ret < 0 || prev_val == *(unsigned int *) kp->arg)
7301d72706fSMatt Ranostay 		return ret;
7311d72706fSMatt Ranostay 
7321d72706fSMatt Ranostay 	mutex_lock(&bq27xxx_list_lock);
7331d72706fSMatt Ranostay 	list_for_each_entry(di, &bq27xxx_battery_devices, list) {
7341d72706fSMatt Ranostay 		cancel_delayed_work_sync(&di->work);
7351d72706fSMatt Ranostay 		schedule_delayed_work(&di->work, 0);
7361d72706fSMatt Ranostay 	}
7371d72706fSMatt Ranostay 	mutex_unlock(&bq27xxx_list_lock);
7381d72706fSMatt Ranostay 
7391d72706fSMatt Ranostay 	return ret;
7401d72706fSMatt Ranostay }
7411d72706fSMatt Ranostay 
7421d72706fSMatt Ranostay static const struct kernel_param_ops param_ops_poll_interval = {
7431d72706fSMatt Ranostay 	.get = param_get_uint,
7441d72706fSMatt Ranostay 	.set = poll_interval_param_set,
7451d72706fSMatt Ranostay };
7461d72706fSMatt Ranostay 
7478c0984e5SSebastian Reichel static unsigned int poll_interval = 360;
7481d72706fSMatt Ranostay module_param_cb(poll_interval, &param_ops_poll_interval, &poll_interval, 0644);
7498c0984e5SSebastian Reichel MODULE_PARM_DESC(poll_interval,
7508c0984e5SSebastian Reichel 		 "battery poll interval in seconds - 0 disables polling");
7518c0984e5SSebastian Reichel 
7528c0984e5SSebastian Reichel /*
7538c0984e5SSebastian Reichel  * Common code for BQ27xxx devices
7548c0984e5SSebastian Reichel  */
7558c0984e5SSebastian Reichel 
7568c0984e5SSebastian Reichel static inline int bq27xxx_read(struct bq27xxx_device_info *di, int reg_index,
7578c0984e5SSebastian Reichel 			       bool single)
7588c0984e5SSebastian Reichel {
7598c0984e5SSebastian Reichel 	/* Reports EINVAL for invalid/missing registers */
7608c0984e5SSebastian Reichel 	if (!di || di->regs[reg_index] == INVALID_REG_ADDR)
7618c0984e5SSebastian Reichel 		return -EINVAL;
7628c0984e5SSebastian Reichel 
7638c0984e5SSebastian Reichel 	return di->bus.read(di, di->regs[reg_index], single);
7648c0984e5SSebastian Reichel }
7658c0984e5SSebastian Reichel 
7668c0984e5SSebastian Reichel /*
7678c0984e5SSebastian Reichel  * Return the battery State-of-Charge
7688c0984e5SSebastian Reichel  * Or < 0 if something fails.
7698c0984e5SSebastian Reichel  */
7708c0984e5SSebastian Reichel static int bq27xxx_battery_read_soc(struct bq27xxx_device_info *di)
7718c0984e5SSebastian Reichel {
7728c0984e5SSebastian Reichel 	int soc;
7738c0984e5SSebastian Reichel 
7748c0984e5SSebastian Reichel 	if (di->chip == BQ27000 || di->chip == BQ27010)
7758c0984e5SSebastian Reichel 		soc = bq27xxx_read(di, BQ27XXX_REG_SOC, true);
7768c0984e5SSebastian Reichel 	else
7778c0984e5SSebastian Reichel 		soc = bq27xxx_read(di, BQ27XXX_REG_SOC, false);
7788c0984e5SSebastian Reichel 
7798c0984e5SSebastian Reichel 	if (soc < 0)
7808c0984e5SSebastian Reichel 		dev_dbg(di->dev, "error reading State-of-Charge\n");
7818c0984e5SSebastian Reichel 
7828c0984e5SSebastian Reichel 	return soc;
7838c0984e5SSebastian Reichel }
7848c0984e5SSebastian Reichel 
7858c0984e5SSebastian Reichel /*
7868c0984e5SSebastian Reichel  * Return a battery charge value in µAh
7878c0984e5SSebastian Reichel  * Or < 0 if something fails.
7888c0984e5SSebastian Reichel  */
7898c0984e5SSebastian Reichel static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg)
7908c0984e5SSebastian Reichel {
7918c0984e5SSebastian Reichel 	int charge;
7928c0984e5SSebastian Reichel 
7938c0984e5SSebastian Reichel 	charge = bq27xxx_read(di, reg, false);
7948c0984e5SSebastian Reichel 	if (charge < 0) {
7958c0984e5SSebastian Reichel 		dev_dbg(di->dev, "error reading charge register %02x: %d\n",
7968c0984e5SSebastian Reichel 			reg, charge);
7978c0984e5SSebastian Reichel 		return charge;
7988c0984e5SSebastian Reichel 	}
7998c0984e5SSebastian Reichel 
8008c0984e5SSebastian Reichel 	if (di->chip == BQ27000 || di->chip == BQ27010)
8018c0984e5SSebastian Reichel 		charge *= BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS;
8028c0984e5SSebastian Reichel 	else
8038c0984e5SSebastian Reichel 		charge *= 1000;
8048c0984e5SSebastian Reichel 
8058c0984e5SSebastian Reichel 	return charge;
8068c0984e5SSebastian Reichel }
8078c0984e5SSebastian Reichel 
8088c0984e5SSebastian Reichel /*
8098c0984e5SSebastian Reichel  * Return the battery Nominal available capacity in µAh
8108c0984e5SSebastian Reichel  * Or < 0 if something fails.
8118c0984e5SSebastian Reichel  */
8128c0984e5SSebastian Reichel static inline int bq27xxx_battery_read_nac(struct bq27xxx_device_info *di)
8138c0984e5SSebastian Reichel {
8148c0984e5SSebastian Reichel 	int flags;
8158c0984e5SSebastian Reichel 
8168c0984e5SSebastian Reichel 	if (di->chip == BQ27000 || di->chip == BQ27010) {
8178c0984e5SSebastian Reichel 		flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, true);
8188c0984e5SSebastian Reichel 		if (flags >= 0 && (flags & BQ27000_FLAG_CI))
8198c0984e5SSebastian Reichel 			return -ENODATA;
8208c0984e5SSebastian Reichel 	}
8218c0984e5SSebastian Reichel 
8228c0984e5SSebastian Reichel 	return bq27xxx_battery_read_charge(di, BQ27XXX_REG_NAC);
8238c0984e5SSebastian Reichel }
8248c0984e5SSebastian Reichel 
8258c0984e5SSebastian Reichel /*
8268c0984e5SSebastian Reichel  * Return the battery Full Charge Capacity in µAh
8278c0984e5SSebastian Reichel  * Or < 0 if something fails.
8288c0984e5SSebastian Reichel  */
8298c0984e5SSebastian Reichel static inline int bq27xxx_battery_read_fcc(struct bq27xxx_device_info *di)
8308c0984e5SSebastian Reichel {
8318c0984e5SSebastian Reichel 	return bq27xxx_battery_read_charge(di, BQ27XXX_REG_FCC);
8328c0984e5SSebastian Reichel }
8338c0984e5SSebastian Reichel 
8348c0984e5SSebastian Reichel /*
8358c0984e5SSebastian Reichel  * Return the Design Capacity in µAh
8368c0984e5SSebastian Reichel  * Or < 0 if something fails.
8378c0984e5SSebastian Reichel  */
8388c0984e5SSebastian Reichel static int bq27xxx_battery_read_dcap(struct bq27xxx_device_info *di)
8398c0984e5SSebastian Reichel {
8408c0984e5SSebastian Reichel 	int dcap;
8418c0984e5SSebastian Reichel 
8428c0984e5SSebastian Reichel 	if (di->chip == BQ27000 || di->chip == BQ27010)
8438c0984e5SSebastian Reichel 		dcap = bq27xxx_read(di, BQ27XXX_REG_DCAP, true);
8448c0984e5SSebastian Reichel 	else
8458c0984e5SSebastian Reichel 		dcap = bq27xxx_read(di, BQ27XXX_REG_DCAP, false);
8468c0984e5SSebastian Reichel 
8478c0984e5SSebastian Reichel 	if (dcap < 0) {
8488c0984e5SSebastian Reichel 		dev_dbg(di->dev, "error reading initial last measured discharge\n");
8498c0984e5SSebastian Reichel 		return dcap;
8508c0984e5SSebastian Reichel 	}
8518c0984e5SSebastian Reichel 
8528c0984e5SSebastian Reichel 	if (di->chip == BQ27000 || di->chip == BQ27010)
8538c0984e5SSebastian Reichel 		dcap = (dcap << 8) * BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS;
8548c0984e5SSebastian Reichel 	else
8558c0984e5SSebastian Reichel 		dcap *= 1000;
8568c0984e5SSebastian Reichel 
8578c0984e5SSebastian Reichel 	return dcap;
8588c0984e5SSebastian Reichel }
8598c0984e5SSebastian Reichel 
8608c0984e5SSebastian Reichel /*
8618c0984e5SSebastian Reichel  * Return the battery Available energy in µWh
8628c0984e5SSebastian Reichel  * Or < 0 if something fails.
8638c0984e5SSebastian Reichel  */
8648c0984e5SSebastian Reichel static int bq27xxx_battery_read_energy(struct bq27xxx_device_info *di)
8658c0984e5SSebastian Reichel {
8668c0984e5SSebastian Reichel 	int ae;
8678c0984e5SSebastian Reichel 
8688c0984e5SSebastian Reichel 	ae = bq27xxx_read(di, BQ27XXX_REG_AE, false);
8698c0984e5SSebastian Reichel 	if (ae < 0) {
8708c0984e5SSebastian Reichel 		dev_dbg(di->dev, "error reading available energy\n");
8718c0984e5SSebastian Reichel 		return ae;
8728c0984e5SSebastian Reichel 	}
8738c0984e5SSebastian Reichel 
8748c0984e5SSebastian Reichel 	if (di->chip == BQ27000 || di->chip == BQ27010)
8758c0984e5SSebastian Reichel 		ae *= BQ27XXX_POWER_CONSTANT / BQ27XXX_RS;
8768c0984e5SSebastian Reichel 	else
8778c0984e5SSebastian Reichel 		ae *= 1000;
8788c0984e5SSebastian Reichel 
8798c0984e5SSebastian Reichel 	return ae;
8808c0984e5SSebastian Reichel }
8818c0984e5SSebastian Reichel 
8828c0984e5SSebastian Reichel /*
8838c0984e5SSebastian Reichel  * Return the battery temperature in tenths of degree Kelvin
8848c0984e5SSebastian Reichel  * Or < 0 if something fails.
8858c0984e5SSebastian Reichel  */
8868c0984e5SSebastian Reichel static int bq27xxx_battery_read_temperature(struct bq27xxx_device_info *di)
8878c0984e5SSebastian Reichel {
8888c0984e5SSebastian Reichel 	int temp;
8898c0984e5SSebastian Reichel 
8908c0984e5SSebastian Reichel 	temp = bq27xxx_read(di, BQ27XXX_REG_TEMP, false);
8918c0984e5SSebastian Reichel 	if (temp < 0) {
8928c0984e5SSebastian Reichel 		dev_err(di->dev, "error reading temperature\n");
8938c0984e5SSebastian Reichel 		return temp;
8948c0984e5SSebastian Reichel 	}
8958c0984e5SSebastian Reichel 
8968c0984e5SSebastian Reichel 	if (di->chip == BQ27000 || di->chip == BQ27010)
8978c0984e5SSebastian Reichel 		temp = 5 * temp / 2;
8988c0984e5SSebastian Reichel 
8998c0984e5SSebastian Reichel 	return temp;
9008c0984e5SSebastian Reichel }
9018c0984e5SSebastian Reichel 
9028c0984e5SSebastian Reichel /*
9038c0984e5SSebastian Reichel  * Return the battery Cycle count total
9048c0984e5SSebastian Reichel  * Or < 0 if something fails.
9058c0984e5SSebastian Reichel  */
9068c0984e5SSebastian Reichel static int bq27xxx_battery_read_cyct(struct bq27xxx_device_info *di)
9078c0984e5SSebastian Reichel {
9088c0984e5SSebastian Reichel 	int cyct;
9098c0984e5SSebastian Reichel 
9108c0984e5SSebastian Reichel 	cyct = bq27xxx_read(di, BQ27XXX_REG_CYCT, false);
9118c0984e5SSebastian Reichel 	if (cyct < 0)
9128c0984e5SSebastian Reichel 		dev_err(di->dev, "error reading cycle count total\n");
9138c0984e5SSebastian Reichel 
9148c0984e5SSebastian Reichel 	return cyct;
9158c0984e5SSebastian Reichel }
9168c0984e5SSebastian Reichel 
9178c0984e5SSebastian Reichel /*
9188c0984e5SSebastian Reichel  * Read a time register.
9198c0984e5SSebastian Reichel  * Return < 0 if something fails.
9208c0984e5SSebastian Reichel  */
9218c0984e5SSebastian Reichel static int bq27xxx_battery_read_time(struct bq27xxx_device_info *di, u8 reg)
9228c0984e5SSebastian Reichel {
9238c0984e5SSebastian Reichel 	int tval;
9248c0984e5SSebastian Reichel 
9258c0984e5SSebastian Reichel 	tval = bq27xxx_read(di, reg, false);
9268c0984e5SSebastian Reichel 	if (tval < 0) {
9278c0984e5SSebastian Reichel 		dev_dbg(di->dev, "error reading time register %02x: %d\n",
9288c0984e5SSebastian Reichel 			reg, tval);
9298c0984e5SSebastian Reichel 		return tval;
9308c0984e5SSebastian Reichel 	}
9318c0984e5SSebastian Reichel 
9328c0984e5SSebastian Reichel 	if (tval == 65535)
9338c0984e5SSebastian Reichel 		return -ENODATA;
9348c0984e5SSebastian Reichel 
9358c0984e5SSebastian Reichel 	return tval * 60;
9368c0984e5SSebastian Reichel }
9378c0984e5SSebastian Reichel 
9388c0984e5SSebastian Reichel /*
9398c0984e5SSebastian Reichel  * Read an average power register.
9408c0984e5SSebastian Reichel  * Return < 0 if something fails.
9418c0984e5SSebastian Reichel  */
9428c0984e5SSebastian Reichel static int bq27xxx_battery_read_pwr_avg(struct bq27xxx_device_info *di)
9438c0984e5SSebastian Reichel {
9448c0984e5SSebastian Reichel 	int tval;
9458c0984e5SSebastian Reichel 
9468c0984e5SSebastian Reichel 	tval = bq27xxx_read(di, BQ27XXX_REG_AP, false);
9478c0984e5SSebastian Reichel 	if (tval < 0) {
9488c0984e5SSebastian Reichel 		dev_err(di->dev, "error reading average power register  %02x: %d\n",
9498c0984e5SSebastian Reichel 			BQ27XXX_REG_AP, tval);
9508c0984e5SSebastian Reichel 		return tval;
9518c0984e5SSebastian Reichel 	}
9528c0984e5SSebastian Reichel 
9538c0984e5SSebastian Reichel 	if (di->chip == BQ27000 || di->chip == BQ27010)
9548c0984e5SSebastian Reichel 		return (tval * BQ27XXX_POWER_CONSTANT) / BQ27XXX_RS;
9558c0984e5SSebastian Reichel 	else
9568c0984e5SSebastian Reichel 		return tval;
9578c0984e5SSebastian Reichel }
9588c0984e5SSebastian Reichel 
9598c0984e5SSebastian Reichel /*
9608c0984e5SSebastian Reichel  * Returns true if a battery over temperature condition is detected
9618c0984e5SSebastian Reichel  */
9628c0984e5SSebastian Reichel static bool bq27xxx_battery_overtemp(struct bq27xxx_device_info *di, u16 flags)
9638c0984e5SSebastian Reichel {
964e839a448SChris Lapa 	switch (di->chip) {
965818e3012SChris Lapa 	case BQ2750X:
9666da6e4bdSChris Lapa 	case BQ2751X:
96732833635SChris Lapa 	case BQ27500:
968bd28177fSChris Lapa 	case BQ27510G1:
969698a2bf5SChris Lapa 	case BQ27510G2:
97071375aa7SChris Lapa 	case BQ27510G3:
97168f2a813SChris Lapa 	case BQ27520G1:
972a5deb9a9SChris Lapa 	case BQ27520G2:
973825e915bSChris Lapa 	case BQ27520G3:
974e839a448SChris Lapa 	case BQ27541:
975e839a448SChris Lapa 	case BQ27545:
9768c0984e5SSebastian Reichel 		return flags & (BQ27XXX_FLAG_OTC | BQ27XXX_FLAG_OTD);
977e839a448SChris Lapa 	case BQ27530:
978e839a448SChris Lapa 	case BQ27421:
9798c0984e5SSebastian Reichel 		return flags & BQ27XXX_FLAG_OT;
980e839a448SChris Lapa 	default:
9818c0984e5SSebastian Reichel 		return false;
9828c0984e5SSebastian Reichel 	}
983e839a448SChris Lapa }
9848c0984e5SSebastian Reichel 
9858c0984e5SSebastian Reichel /*
9868c0984e5SSebastian Reichel  * Returns true if a battery under temperature condition is detected
9878c0984e5SSebastian Reichel  */
9888c0984e5SSebastian Reichel static bool bq27xxx_battery_undertemp(struct bq27xxx_device_info *di, u16 flags)
9898c0984e5SSebastian Reichel {
9908c0984e5SSebastian Reichel 	if (di->chip == BQ27530 || di->chip == BQ27421)
9918c0984e5SSebastian Reichel 		return flags & BQ27XXX_FLAG_UT;
9928c0984e5SSebastian Reichel 
9938c0984e5SSebastian Reichel 	return false;
9948c0984e5SSebastian Reichel }
9958c0984e5SSebastian Reichel 
9968c0984e5SSebastian Reichel /*
9978c0984e5SSebastian Reichel  * Returns true if a low state of charge condition is detected
9988c0984e5SSebastian Reichel  */
9998c0984e5SSebastian Reichel static bool bq27xxx_battery_dead(struct bq27xxx_device_info *di, u16 flags)
10008c0984e5SSebastian Reichel {
10018c0984e5SSebastian Reichel 	if (di->chip == BQ27000 || di->chip == BQ27010)
10028c0984e5SSebastian Reichel 		return flags & (BQ27000_FLAG_EDV1 | BQ27000_FLAG_EDVF);
10038c0984e5SSebastian Reichel 	else
10048c0984e5SSebastian Reichel 		return flags & (BQ27XXX_FLAG_SOC1 | BQ27XXX_FLAG_SOCF);
10058c0984e5SSebastian Reichel }
10068c0984e5SSebastian Reichel 
10078c0984e5SSebastian Reichel /*
10088c0984e5SSebastian Reichel  * Read flag register.
10098c0984e5SSebastian Reichel  * Return < 0 if something fails.
10108c0984e5SSebastian Reichel  */
10118c0984e5SSebastian Reichel static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)
10128c0984e5SSebastian Reichel {
10138c0984e5SSebastian Reichel 	int flags;
1014e4a404a0SH. Nikolaus Schaller 	bool has_singe_flag = di->chip == BQ27000 || di->chip == BQ27010;
10158c0984e5SSebastian Reichel 
1016e4a404a0SH. Nikolaus Schaller 	flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag);
10178c0984e5SSebastian Reichel 	if (flags < 0) {
10188c0984e5SSebastian Reichel 		dev_err(di->dev, "error reading flag register:%d\n", flags);
10198c0984e5SSebastian Reichel 		return flags;
10208c0984e5SSebastian Reichel 	}
10218c0984e5SSebastian Reichel 
10228c0984e5SSebastian Reichel 	/* Unlikely but important to return first */
10238c0984e5SSebastian Reichel 	if (unlikely(bq27xxx_battery_overtemp(di, flags)))
10248c0984e5SSebastian Reichel 		return POWER_SUPPLY_HEALTH_OVERHEAT;
10258c0984e5SSebastian Reichel 	if (unlikely(bq27xxx_battery_undertemp(di, flags)))
10268c0984e5SSebastian Reichel 		return POWER_SUPPLY_HEALTH_COLD;
10278c0984e5SSebastian Reichel 	if (unlikely(bq27xxx_battery_dead(di, flags)))
10288c0984e5SSebastian Reichel 		return POWER_SUPPLY_HEALTH_DEAD;
10298c0984e5SSebastian Reichel 
10308c0984e5SSebastian Reichel 	return POWER_SUPPLY_HEALTH_GOOD;
10318c0984e5SSebastian Reichel }
10328c0984e5SSebastian Reichel 
10338c0984e5SSebastian Reichel void bq27xxx_battery_update(struct bq27xxx_device_info *di)
10348c0984e5SSebastian Reichel {
10358c0984e5SSebastian Reichel 	struct bq27xxx_reg_cache cache = {0, };
10368c0984e5SSebastian Reichel 	bool has_ci_flag = di->chip == BQ27000 || di->chip == BQ27010;
10378c0984e5SSebastian Reichel 	bool has_singe_flag = di->chip == BQ27000 || di->chip == BQ27010;
10388c0984e5SSebastian Reichel 
10398c0984e5SSebastian Reichel 	cache.flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag);
10408c0984e5SSebastian Reichel 	if ((cache.flags & 0xff) == 0xff)
10418c0984e5SSebastian Reichel 		cache.flags = -1; /* read error */
10428c0984e5SSebastian Reichel 	if (cache.flags >= 0) {
10438c0984e5SSebastian Reichel 		cache.temperature = bq27xxx_battery_read_temperature(di);
10448c0984e5SSebastian Reichel 		if (has_ci_flag && (cache.flags & BQ27000_FLAG_CI)) {
10458c0984e5SSebastian Reichel 			dev_info_once(di->dev, "battery is not calibrated! ignoring capacity values\n");
10468c0984e5SSebastian Reichel 			cache.capacity = -ENODATA;
10478c0984e5SSebastian Reichel 			cache.energy = -ENODATA;
10488c0984e5SSebastian Reichel 			cache.time_to_empty = -ENODATA;
10498c0984e5SSebastian Reichel 			cache.time_to_empty_avg = -ENODATA;
10508c0984e5SSebastian Reichel 			cache.time_to_full = -ENODATA;
10518c0984e5SSebastian Reichel 			cache.charge_full = -ENODATA;
10528c0984e5SSebastian Reichel 			cache.health = -ENODATA;
10538c0984e5SSebastian Reichel 		} else {
10548c0984e5SSebastian Reichel 			if (di->regs[BQ27XXX_REG_TTE] != INVALID_REG_ADDR)
10558c0984e5SSebastian Reichel 				cache.time_to_empty = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTE);
10568c0984e5SSebastian Reichel 			if (di->regs[BQ27XXX_REG_TTECP] != INVALID_REG_ADDR)
10578c0984e5SSebastian Reichel 				cache.time_to_empty_avg = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTECP);
10588c0984e5SSebastian Reichel 			if (di->regs[BQ27XXX_REG_TTF] != INVALID_REG_ADDR)
10598c0984e5SSebastian Reichel 				cache.time_to_full = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTF);
10608c0984e5SSebastian Reichel 			cache.charge_full = bq27xxx_battery_read_fcc(di);
10618c0984e5SSebastian Reichel 			cache.capacity = bq27xxx_battery_read_soc(di);
10628c0984e5SSebastian Reichel 			if (di->regs[BQ27XXX_REG_AE] != INVALID_REG_ADDR)
10638c0984e5SSebastian Reichel 				cache.energy = bq27xxx_battery_read_energy(di);
10648c0984e5SSebastian Reichel 			cache.health = bq27xxx_battery_read_health(di);
10658c0984e5SSebastian Reichel 		}
10668c0984e5SSebastian Reichel 		if (di->regs[BQ27XXX_REG_CYCT] != INVALID_REG_ADDR)
10678c0984e5SSebastian Reichel 			cache.cycle_count = bq27xxx_battery_read_cyct(di);
10688c0984e5SSebastian Reichel 		if (di->regs[BQ27XXX_REG_AP] != INVALID_REG_ADDR)
10698c0984e5SSebastian Reichel 			cache.power_avg = bq27xxx_battery_read_pwr_avg(di);
10708c0984e5SSebastian Reichel 
10718c0984e5SSebastian Reichel 		/* We only have to read charge design full once */
10728c0984e5SSebastian Reichel 		if (di->charge_design_full <= 0)
10738c0984e5SSebastian Reichel 			di->charge_design_full = bq27xxx_battery_read_dcap(di);
10748c0984e5SSebastian Reichel 	}
10758c0984e5SSebastian Reichel 
10768c0984e5SSebastian Reichel 	if (di->cache.capacity != cache.capacity)
10778c0984e5SSebastian Reichel 		power_supply_changed(di->bat);
10788c0984e5SSebastian Reichel 
10798c0984e5SSebastian Reichel 	if (memcmp(&di->cache, &cache, sizeof(cache)) != 0)
10808c0984e5SSebastian Reichel 		di->cache = cache;
10818c0984e5SSebastian Reichel 
10828c0984e5SSebastian Reichel 	di->last_update = jiffies;
10838c0984e5SSebastian Reichel }
10848c0984e5SSebastian Reichel EXPORT_SYMBOL_GPL(bq27xxx_battery_update);
10858c0984e5SSebastian Reichel 
10868c0984e5SSebastian Reichel static void bq27xxx_battery_poll(struct work_struct *work)
10878c0984e5SSebastian Reichel {
10888c0984e5SSebastian Reichel 	struct bq27xxx_device_info *di =
10898c0984e5SSebastian Reichel 			container_of(work, struct bq27xxx_device_info,
10908c0984e5SSebastian Reichel 				     work.work);
10918c0984e5SSebastian Reichel 
10928c0984e5SSebastian Reichel 	bq27xxx_battery_update(di);
10938c0984e5SSebastian Reichel 
10948c0984e5SSebastian Reichel 	if (poll_interval > 0)
10958c0984e5SSebastian Reichel 		schedule_delayed_work(&di->work, poll_interval * HZ);
10968c0984e5SSebastian Reichel }
10978c0984e5SSebastian Reichel 
10988c0984e5SSebastian Reichel /*
10998c0984e5SSebastian Reichel  * Return the battery average current in µA
11008c0984e5SSebastian Reichel  * Note that current can be negative signed as well
11018c0984e5SSebastian Reichel  * Or 0 if something fails.
11028c0984e5SSebastian Reichel  */
11038c0984e5SSebastian Reichel static int bq27xxx_battery_current(struct bq27xxx_device_info *di,
11048c0984e5SSebastian Reichel 				   union power_supply_propval *val)
11058c0984e5SSebastian Reichel {
11068c0984e5SSebastian Reichel 	int curr;
11078c0984e5SSebastian Reichel 	int flags;
11088c0984e5SSebastian Reichel 
11098c0984e5SSebastian Reichel 	curr = bq27xxx_read(di, BQ27XXX_REG_AI, false);
11108c0984e5SSebastian Reichel 	if (curr < 0) {
11118c0984e5SSebastian Reichel 		dev_err(di->dev, "error reading current\n");
11128c0984e5SSebastian Reichel 		return curr;
11138c0984e5SSebastian Reichel 	}
11148c0984e5SSebastian Reichel 
11158c0984e5SSebastian Reichel 	if (di->chip == BQ27000 || di->chip == BQ27010) {
1116e4a404a0SH. Nikolaus Schaller 		flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, true);
11178c0984e5SSebastian Reichel 		if (flags & BQ27000_FLAG_CHGS) {
11188c0984e5SSebastian Reichel 			dev_dbg(di->dev, "negative current!\n");
11198c0984e5SSebastian Reichel 			curr = -curr;
11208c0984e5SSebastian Reichel 		}
11218c0984e5SSebastian Reichel 
11228c0984e5SSebastian Reichel 		val->intval = curr * BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS;
11238c0984e5SSebastian Reichel 	} else {
11248c0984e5SSebastian Reichel 		/* Other gauges return signed value */
11258c0984e5SSebastian Reichel 		val->intval = (int)((s16)curr) * 1000;
11268c0984e5SSebastian Reichel 	}
11278c0984e5SSebastian Reichel 
11288c0984e5SSebastian Reichel 	return 0;
11298c0984e5SSebastian Reichel }
11308c0984e5SSebastian Reichel 
11318c0984e5SSebastian Reichel static int bq27xxx_battery_status(struct bq27xxx_device_info *di,
11328c0984e5SSebastian Reichel 				  union power_supply_propval *val)
11338c0984e5SSebastian Reichel {
11348c0984e5SSebastian Reichel 	int status;
11358c0984e5SSebastian Reichel 
11368c0984e5SSebastian Reichel 	if (di->chip == BQ27000 || di->chip == BQ27010) {
11378c0984e5SSebastian Reichel 		if (di->cache.flags & BQ27000_FLAG_FC)
11388c0984e5SSebastian Reichel 			status = POWER_SUPPLY_STATUS_FULL;
11398c0984e5SSebastian Reichel 		else if (di->cache.flags & BQ27000_FLAG_CHGS)
11408c0984e5SSebastian Reichel 			status = POWER_SUPPLY_STATUS_CHARGING;
11418c0984e5SSebastian Reichel 		else if (power_supply_am_i_supplied(di->bat))
11428c0984e5SSebastian Reichel 			status = POWER_SUPPLY_STATUS_NOT_CHARGING;
11438c0984e5SSebastian Reichel 		else
11448c0984e5SSebastian Reichel 			status = POWER_SUPPLY_STATUS_DISCHARGING;
11458c0984e5SSebastian Reichel 	} else {
11468c0984e5SSebastian Reichel 		if (di->cache.flags & BQ27XXX_FLAG_FC)
11478c0984e5SSebastian Reichel 			status = POWER_SUPPLY_STATUS_FULL;
11488c0984e5SSebastian Reichel 		else if (di->cache.flags & BQ27XXX_FLAG_DSC)
11498c0984e5SSebastian Reichel 			status = POWER_SUPPLY_STATUS_DISCHARGING;
11508c0984e5SSebastian Reichel 		else
11518c0984e5SSebastian Reichel 			status = POWER_SUPPLY_STATUS_CHARGING;
11528c0984e5SSebastian Reichel 	}
11538c0984e5SSebastian Reichel 
11548c0984e5SSebastian Reichel 	val->intval = status;
11558c0984e5SSebastian Reichel 
11568c0984e5SSebastian Reichel 	return 0;
11578c0984e5SSebastian Reichel }
11588c0984e5SSebastian Reichel 
11598c0984e5SSebastian Reichel static int bq27xxx_battery_capacity_level(struct bq27xxx_device_info *di,
11608c0984e5SSebastian Reichel 					  union power_supply_propval *val)
11618c0984e5SSebastian Reichel {
11628c0984e5SSebastian Reichel 	int level;
11638c0984e5SSebastian Reichel 
11648c0984e5SSebastian Reichel 	if (di->chip == BQ27000 || di->chip == BQ27010) {
11658c0984e5SSebastian Reichel 		if (di->cache.flags & BQ27000_FLAG_FC)
11668c0984e5SSebastian Reichel 			level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
11678c0984e5SSebastian Reichel 		else if (di->cache.flags & BQ27000_FLAG_EDV1)
11688c0984e5SSebastian Reichel 			level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
11698c0984e5SSebastian Reichel 		else if (di->cache.flags & BQ27000_FLAG_EDVF)
11708c0984e5SSebastian Reichel 			level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
11718c0984e5SSebastian Reichel 		else
11728c0984e5SSebastian Reichel 			level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
11738c0984e5SSebastian Reichel 	} else {
11748c0984e5SSebastian Reichel 		if (di->cache.flags & BQ27XXX_FLAG_FC)
11758c0984e5SSebastian Reichel 			level = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
11768c0984e5SSebastian Reichel 		else if (di->cache.flags & BQ27XXX_FLAG_SOC1)
11778c0984e5SSebastian Reichel 			level = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
11788c0984e5SSebastian Reichel 		else if (di->cache.flags & BQ27XXX_FLAG_SOCF)
11798c0984e5SSebastian Reichel 			level = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
11808c0984e5SSebastian Reichel 		else
11818c0984e5SSebastian Reichel 			level = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
11828c0984e5SSebastian Reichel 	}
11838c0984e5SSebastian Reichel 
11848c0984e5SSebastian Reichel 	val->intval = level;
11858c0984e5SSebastian Reichel 
11868c0984e5SSebastian Reichel 	return 0;
11878c0984e5SSebastian Reichel }
11888c0984e5SSebastian Reichel 
11898c0984e5SSebastian Reichel /*
11908c0984e5SSebastian Reichel  * Return the battery Voltage in millivolts
11918c0984e5SSebastian Reichel  * Or < 0 if something fails.
11928c0984e5SSebastian Reichel  */
11938c0984e5SSebastian Reichel static int bq27xxx_battery_voltage(struct bq27xxx_device_info *di,
11948c0984e5SSebastian Reichel 				   union power_supply_propval *val)
11958c0984e5SSebastian Reichel {
11968c0984e5SSebastian Reichel 	int volt;
11978c0984e5SSebastian Reichel 
11988c0984e5SSebastian Reichel 	volt = bq27xxx_read(di, BQ27XXX_REG_VOLT, false);
11998c0984e5SSebastian Reichel 	if (volt < 0) {
12008c0984e5SSebastian Reichel 		dev_err(di->dev, "error reading voltage\n");
12018c0984e5SSebastian Reichel 		return volt;
12028c0984e5SSebastian Reichel 	}
12038c0984e5SSebastian Reichel 
12048c0984e5SSebastian Reichel 	val->intval = volt * 1000;
12058c0984e5SSebastian Reichel 
12068c0984e5SSebastian Reichel 	return 0;
12078c0984e5SSebastian Reichel }
12088c0984e5SSebastian Reichel 
12098c0984e5SSebastian Reichel static int bq27xxx_simple_value(int value,
12108c0984e5SSebastian Reichel 				union power_supply_propval *val)
12118c0984e5SSebastian Reichel {
12128c0984e5SSebastian Reichel 	if (value < 0)
12138c0984e5SSebastian Reichel 		return value;
12148c0984e5SSebastian Reichel 
12158c0984e5SSebastian Reichel 	val->intval = value;
12168c0984e5SSebastian Reichel 
12178c0984e5SSebastian Reichel 	return 0;
12188c0984e5SSebastian Reichel }
12198c0984e5SSebastian Reichel 
12208c0984e5SSebastian Reichel static int bq27xxx_battery_get_property(struct power_supply *psy,
12218c0984e5SSebastian Reichel 					enum power_supply_property psp,
12228c0984e5SSebastian Reichel 					union power_supply_propval *val)
12238c0984e5SSebastian Reichel {
12248c0984e5SSebastian Reichel 	int ret = 0;
12258c0984e5SSebastian Reichel 	struct bq27xxx_device_info *di = power_supply_get_drvdata(psy);
12268c0984e5SSebastian Reichel 
12278c0984e5SSebastian Reichel 	mutex_lock(&di->lock);
12288c0984e5SSebastian Reichel 	if (time_is_before_jiffies(di->last_update + 5 * HZ)) {
12298c0984e5SSebastian Reichel 		cancel_delayed_work_sync(&di->work);
12308c0984e5SSebastian Reichel 		bq27xxx_battery_poll(&di->work.work);
12318c0984e5SSebastian Reichel 	}
12328c0984e5SSebastian Reichel 	mutex_unlock(&di->lock);
12338c0984e5SSebastian Reichel 
12348c0984e5SSebastian Reichel 	if (psp != POWER_SUPPLY_PROP_PRESENT && di->cache.flags < 0)
12358c0984e5SSebastian Reichel 		return -ENODEV;
12368c0984e5SSebastian Reichel 
12378c0984e5SSebastian Reichel 	switch (psp) {
12388c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_STATUS:
12398c0984e5SSebastian Reichel 		ret = bq27xxx_battery_status(di, val);
12408c0984e5SSebastian Reichel 		break;
12418c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
12428c0984e5SSebastian Reichel 		ret = bq27xxx_battery_voltage(di, val);
12438c0984e5SSebastian Reichel 		break;
12448c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_PRESENT:
12458c0984e5SSebastian Reichel 		val->intval = di->cache.flags < 0 ? 0 : 1;
12468c0984e5SSebastian Reichel 		break;
12478c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_CURRENT_NOW:
12488c0984e5SSebastian Reichel 		ret = bq27xxx_battery_current(di, val);
12498c0984e5SSebastian Reichel 		break;
12508c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_CAPACITY:
12518c0984e5SSebastian Reichel 		ret = bq27xxx_simple_value(di->cache.capacity, val);
12528c0984e5SSebastian Reichel 		break;
12538c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
12548c0984e5SSebastian Reichel 		ret = bq27xxx_battery_capacity_level(di, val);
12558c0984e5SSebastian Reichel 		break;
12568c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_TEMP:
12578c0984e5SSebastian Reichel 		ret = bq27xxx_simple_value(di->cache.temperature, val);
12588c0984e5SSebastian Reichel 		if (ret == 0)
12598c0984e5SSebastian Reichel 			val->intval -= 2731; /* convert decidegree k to c */
12608c0984e5SSebastian Reichel 		break;
12618c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
12628c0984e5SSebastian Reichel 		ret = bq27xxx_simple_value(di->cache.time_to_empty, val);
12638c0984e5SSebastian Reichel 		break;
12648c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
12658c0984e5SSebastian Reichel 		ret = bq27xxx_simple_value(di->cache.time_to_empty_avg, val);
12668c0984e5SSebastian Reichel 		break;
12678c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
12688c0984e5SSebastian Reichel 		ret = bq27xxx_simple_value(di->cache.time_to_full, val);
12698c0984e5SSebastian Reichel 		break;
12708c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_TECHNOLOGY:
12718c0984e5SSebastian Reichel 		val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
12728c0984e5SSebastian Reichel 		break;
12738c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_CHARGE_NOW:
12748c0984e5SSebastian Reichel 		ret = bq27xxx_simple_value(bq27xxx_battery_read_nac(di), val);
12758c0984e5SSebastian Reichel 		break;
12768c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_CHARGE_FULL:
12778c0984e5SSebastian Reichel 		ret = bq27xxx_simple_value(di->cache.charge_full, val);
12788c0984e5SSebastian Reichel 		break;
12798c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
12808c0984e5SSebastian Reichel 		ret = bq27xxx_simple_value(di->charge_design_full, val);
12818c0984e5SSebastian Reichel 		break;
12828c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_CYCLE_COUNT:
12838c0984e5SSebastian Reichel 		ret = bq27xxx_simple_value(di->cache.cycle_count, val);
12848c0984e5SSebastian Reichel 		break;
12858c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_ENERGY_NOW:
12868c0984e5SSebastian Reichel 		ret = bq27xxx_simple_value(di->cache.energy, val);
12878c0984e5SSebastian Reichel 		break;
12888c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_POWER_AVG:
12898c0984e5SSebastian Reichel 		ret = bq27xxx_simple_value(di->cache.power_avg, val);
12908c0984e5SSebastian Reichel 		break;
12918c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_HEALTH:
12928c0984e5SSebastian Reichel 		ret = bq27xxx_simple_value(di->cache.health, val);
12938c0984e5SSebastian Reichel 		break;
12948c0984e5SSebastian Reichel 	case POWER_SUPPLY_PROP_MANUFACTURER:
12958c0984e5SSebastian Reichel 		val->strval = BQ27XXX_MANUFACTURER;
12968c0984e5SSebastian Reichel 		break;
12978c0984e5SSebastian Reichel 	default:
12988c0984e5SSebastian Reichel 		return -EINVAL;
12998c0984e5SSebastian Reichel 	}
13008c0984e5SSebastian Reichel 
13018c0984e5SSebastian Reichel 	return ret;
13028c0984e5SSebastian Reichel }
13038c0984e5SSebastian Reichel 
13048c0984e5SSebastian Reichel static void bq27xxx_external_power_changed(struct power_supply *psy)
13058c0984e5SSebastian Reichel {
13068c0984e5SSebastian Reichel 	struct bq27xxx_device_info *di = power_supply_get_drvdata(psy);
13078c0984e5SSebastian Reichel 
13088c0984e5SSebastian Reichel 	cancel_delayed_work_sync(&di->work);
13098c0984e5SSebastian Reichel 	schedule_delayed_work(&di->work, 0);
13108c0984e5SSebastian Reichel }
13118c0984e5SSebastian Reichel 
13128c0984e5SSebastian Reichel int bq27xxx_battery_setup(struct bq27xxx_device_info *di)
13138c0984e5SSebastian Reichel {
13148c0984e5SSebastian Reichel 	struct power_supply_desc *psy_desc;
13158c0984e5SSebastian Reichel 	struct power_supply_config psy_cfg = { .drv_data = di, };
13168c0984e5SSebastian Reichel 
13178c0984e5SSebastian Reichel 	INIT_DELAYED_WORK(&di->work, bq27xxx_battery_poll);
13188c0984e5SSebastian Reichel 	mutex_init(&di->lock);
13198c0984e5SSebastian Reichel 	di->regs = bq27xxx_regs[di->chip];
13208c0984e5SSebastian Reichel 
13218c0984e5SSebastian Reichel 	psy_desc = devm_kzalloc(di->dev, sizeof(*psy_desc), GFP_KERNEL);
13228c0984e5SSebastian Reichel 	if (!psy_desc)
13238c0984e5SSebastian Reichel 		return -ENOMEM;
13248c0984e5SSebastian Reichel 
13258c0984e5SSebastian Reichel 	psy_desc->name = di->name;
13268c0984e5SSebastian Reichel 	psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
13278c0984e5SSebastian Reichel 	psy_desc->properties = bq27xxx_battery_props[di->chip].props;
13288c0984e5SSebastian Reichel 	psy_desc->num_properties = bq27xxx_battery_props[di->chip].size;
13298c0984e5SSebastian Reichel 	psy_desc->get_property = bq27xxx_battery_get_property;
13308c0984e5SSebastian Reichel 	psy_desc->external_power_changed = bq27xxx_external_power_changed;
13318c0984e5SSebastian Reichel 
13328c0984e5SSebastian Reichel 	di->bat = power_supply_register_no_ws(di->dev, psy_desc, &psy_cfg);
13338c0984e5SSebastian Reichel 	if (IS_ERR(di->bat)) {
13348c0984e5SSebastian Reichel 		dev_err(di->dev, "failed to register battery\n");
13358c0984e5SSebastian Reichel 		return PTR_ERR(di->bat);
13368c0984e5SSebastian Reichel 	}
13378c0984e5SSebastian Reichel 
13388c0984e5SSebastian Reichel 	dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION);
13398c0984e5SSebastian Reichel 
13408c0984e5SSebastian Reichel 	bq27xxx_battery_update(di);
13418c0984e5SSebastian Reichel 
13421d72706fSMatt Ranostay 	mutex_lock(&bq27xxx_list_lock);
13431d72706fSMatt Ranostay 	list_add(&di->list, &bq27xxx_battery_devices);
13441d72706fSMatt Ranostay 	mutex_unlock(&bq27xxx_list_lock);
13451d72706fSMatt Ranostay 
13468c0984e5SSebastian Reichel 	return 0;
13478c0984e5SSebastian Reichel }
13488c0984e5SSebastian Reichel EXPORT_SYMBOL_GPL(bq27xxx_battery_setup);
13498c0984e5SSebastian Reichel 
13508c0984e5SSebastian Reichel void bq27xxx_battery_teardown(struct bq27xxx_device_info *di)
13518c0984e5SSebastian Reichel {
13528c0984e5SSebastian Reichel 	/*
13538c0984e5SSebastian Reichel 	 * power_supply_unregister call bq27xxx_battery_get_property which
13548c0984e5SSebastian Reichel 	 * call bq27xxx_battery_poll.
13558c0984e5SSebastian Reichel 	 * Make sure that bq27xxx_battery_poll will not call
13568c0984e5SSebastian Reichel 	 * schedule_delayed_work again after unregister (which cause OOPS).
13578c0984e5SSebastian Reichel 	 */
13588c0984e5SSebastian Reichel 	poll_interval = 0;
13598c0984e5SSebastian Reichel 
13608c0984e5SSebastian Reichel 	cancel_delayed_work_sync(&di->work);
13618c0984e5SSebastian Reichel 
13628c0984e5SSebastian Reichel 	power_supply_unregister(di->bat);
13638c0984e5SSebastian Reichel 
13641d72706fSMatt Ranostay 	mutex_lock(&bq27xxx_list_lock);
13651d72706fSMatt Ranostay 	list_del(&di->list);
13661d72706fSMatt Ranostay 	mutex_unlock(&bq27xxx_list_lock);
13671d72706fSMatt Ranostay 
13688c0984e5SSebastian Reichel 	mutex_destroy(&di->lock);
13698c0984e5SSebastian Reichel }
13708c0984e5SSebastian Reichel EXPORT_SYMBOL_GPL(bq27xxx_battery_teardown);
13718c0984e5SSebastian Reichel 
13728c0984e5SSebastian Reichel static int bq27xxx_battery_platform_read(struct bq27xxx_device_info *di, u8 reg,
13738c0984e5SSebastian Reichel 					 bool single)
13748c0984e5SSebastian Reichel {
13758c0984e5SSebastian Reichel 	struct device *dev = di->dev;
13768c0984e5SSebastian Reichel 	struct bq27xxx_platform_data *pdata = dev->platform_data;
13778c0984e5SSebastian Reichel 	unsigned int timeout = 3;
13788c0984e5SSebastian Reichel 	int upper, lower;
13798c0984e5SSebastian Reichel 	int temp;
13808c0984e5SSebastian Reichel 
13818c0984e5SSebastian Reichel 	if (!single) {
13828c0984e5SSebastian Reichel 		/* Make sure the value has not changed in between reading the
13838c0984e5SSebastian Reichel 		 * lower and the upper part */
13848c0984e5SSebastian Reichel 		upper = pdata->read(dev, reg + 1);
13858c0984e5SSebastian Reichel 		do {
13868c0984e5SSebastian Reichel 			temp = upper;
13878c0984e5SSebastian Reichel 			if (upper < 0)
13888c0984e5SSebastian Reichel 				return upper;
13898c0984e5SSebastian Reichel 
13908c0984e5SSebastian Reichel 			lower = pdata->read(dev, reg);
13918c0984e5SSebastian Reichel 			if (lower < 0)
13928c0984e5SSebastian Reichel 				return lower;
13938c0984e5SSebastian Reichel 
13948c0984e5SSebastian Reichel 			upper = pdata->read(dev, reg + 1);
13958c0984e5SSebastian Reichel 		} while (temp != upper && --timeout);
13968c0984e5SSebastian Reichel 
13978c0984e5SSebastian Reichel 		if (timeout == 0)
13988c0984e5SSebastian Reichel 			return -EIO;
13998c0984e5SSebastian Reichel 
14008c0984e5SSebastian Reichel 		return (upper << 8) | lower;
14018c0984e5SSebastian Reichel 	}
14028c0984e5SSebastian Reichel 
14038c0984e5SSebastian Reichel 	return pdata->read(dev, reg);
14048c0984e5SSebastian Reichel }
14058c0984e5SSebastian Reichel 
14068c0984e5SSebastian Reichel static int bq27xxx_battery_platform_probe(struct platform_device *pdev)
14078c0984e5SSebastian Reichel {
14088c0984e5SSebastian Reichel 	struct bq27xxx_device_info *di;
14098c0984e5SSebastian Reichel 	struct bq27xxx_platform_data *pdata = pdev->dev.platform_data;
14108c0984e5SSebastian Reichel 
14118c0984e5SSebastian Reichel 	if (!pdata) {
14128c0984e5SSebastian Reichel 		dev_err(&pdev->dev, "no platform_data supplied\n");
14138c0984e5SSebastian Reichel 		return -EINVAL;
14148c0984e5SSebastian Reichel 	}
14158c0984e5SSebastian Reichel 
14168c0984e5SSebastian Reichel 	if (!pdata->read) {
14178c0984e5SSebastian Reichel 		dev_err(&pdev->dev, "no hdq read callback supplied\n");
14188c0984e5SSebastian Reichel 		return -EINVAL;
14198c0984e5SSebastian Reichel 	}
14208c0984e5SSebastian Reichel 
14218c0984e5SSebastian Reichel 	if (!pdata->chip) {
14228c0984e5SSebastian Reichel 		dev_err(&pdev->dev, "no device supplied\n");
14238c0984e5SSebastian Reichel 		return -EINVAL;
14248c0984e5SSebastian Reichel 	}
14258c0984e5SSebastian Reichel 
14268c0984e5SSebastian Reichel 	di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
14278c0984e5SSebastian Reichel 	if (!di)
14288c0984e5SSebastian Reichel 		return -ENOMEM;
14298c0984e5SSebastian Reichel 
14308c0984e5SSebastian Reichel 	platform_set_drvdata(pdev, di);
14318c0984e5SSebastian Reichel 
14328c0984e5SSebastian Reichel 	di->dev = &pdev->dev;
14338c0984e5SSebastian Reichel 	di->chip = pdata->chip;
14348c0984e5SSebastian Reichel 	di->name = pdata->name ?: dev_name(&pdev->dev);
14358c0984e5SSebastian Reichel 	di->bus.read = bq27xxx_battery_platform_read;
14368c0984e5SSebastian Reichel 
14378c0984e5SSebastian Reichel 	return bq27xxx_battery_setup(di);
14388c0984e5SSebastian Reichel }
14398c0984e5SSebastian Reichel 
14408c0984e5SSebastian Reichel static int bq27xxx_battery_platform_remove(struct platform_device *pdev)
14418c0984e5SSebastian Reichel {
14428c0984e5SSebastian Reichel 	struct bq27xxx_device_info *di = platform_get_drvdata(pdev);
14438c0984e5SSebastian Reichel 
14448c0984e5SSebastian Reichel 	bq27xxx_battery_teardown(di);
14458c0984e5SSebastian Reichel 
14468c0984e5SSebastian Reichel 	return 0;
14478c0984e5SSebastian Reichel }
14488c0984e5SSebastian Reichel 
14498c0984e5SSebastian Reichel static const struct platform_device_id bq27xxx_battery_platform_id_table[] = {
14508c0984e5SSebastian Reichel 	{ "bq27000-battery", },
14518c0984e5SSebastian Reichel 	{ /* sentinel */ }
14528c0984e5SSebastian Reichel };
14538c0984e5SSebastian Reichel MODULE_DEVICE_TABLE(platform, bq27xxx_battery_platform_id_table);
14548c0984e5SSebastian Reichel 
14558c0984e5SSebastian Reichel #ifdef CONFIG_OF
14568c0984e5SSebastian Reichel static const struct of_device_id bq27xxx_battery_platform_of_match_table[] = {
14578c0984e5SSebastian Reichel 	{ .compatible = "ti,bq27000" },
14588c0984e5SSebastian Reichel 	{},
14598c0984e5SSebastian Reichel };
14608c0984e5SSebastian Reichel MODULE_DEVICE_TABLE(of, bq27xxx_battery_platform_of_match_table);
14618c0984e5SSebastian Reichel #endif
14628c0984e5SSebastian Reichel 
14638c0984e5SSebastian Reichel static struct platform_driver bq27xxx_battery_platform_driver = {
14648c0984e5SSebastian Reichel 	.probe	= bq27xxx_battery_platform_probe,
14658c0984e5SSebastian Reichel 	.remove = bq27xxx_battery_platform_remove,
14668c0984e5SSebastian Reichel 	.driver = {
14678c0984e5SSebastian Reichel 		.name = "bq27000-battery",
14688c0984e5SSebastian Reichel 		.of_match_table = of_match_ptr(bq27xxx_battery_platform_of_match_table),
14698c0984e5SSebastian Reichel 	},
14708c0984e5SSebastian Reichel 	.id_table = bq27xxx_battery_platform_id_table,
14718c0984e5SSebastian Reichel };
14728c0984e5SSebastian Reichel module_platform_driver(bq27xxx_battery_platform_driver);
14738c0984e5SSebastian Reichel 
14748c0984e5SSebastian Reichel MODULE_ALIAS("platform:bq27000-battery");
14758c0984e5SSebastian Reichel 
14768c0984e5SSebastian Reichel MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
14778c0984e5SSebastian Reichel MODULE_DESCRIPTION("BQ27xxx battery monitor driver");
14788c0984e5SSebastian Reichel MODULE_LICENSE("GPL");
1479