1 // SPDX-License-Identifier: GPL-2.0-only
3 * axp288_fuel_gauge.c - Xpower AXP288 PMIC Fuel Gauge Driver
5 * Copyright (C) 2020-2021 Andrejus Basovas <xxx@yyy.tld>
6 * Copyright (C) 2016-2021 Hans de Goede <hdegoede@redhat.com>
7 * Copyright (C) 2014 Intel Corporation
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 #include <linux/acpi.h>
13 #include <linux/dmi.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/device.h>
17 #include <linux/regmap.h>
18 #include <linux/jiffies.h>
19 #include <linux/interrupt.h>
20 #include <linux/mfd/axp20x.h>
21 #include <linux/platform_device.h>
22 #include <linux/power_supply.h>
23 #include <linux/iio/consumer.h>
24 #include <linux/unaligned.h>
25 #include <asm/iosf_mbi.h>
27 #define PS_STAT_VBUS_TRIGGER (1 << 0)
28 #define PS_STAT_BAT_CHRG_DIR (1 << 2)
29 #define PS_STAT_VBAT_ABOVE_VHOLD (1 << 3)
30 #define PS_STAT_VBUS_VALID (1 << 4)
31 #define PS_STAT_VBUS_PRESENT (1 << 5)
33 #define CHRG_STAT_BAT_SAFE_MODE (1 << 3)
34 #define CHRG_STAT_BAT_VALID (1 << 4)
35 #define CHRG_STAT_BAT_PRESENT (1 << 5)
36 #define CHRG_STAT_CHARGING (1 << 6)
37 #define CHRG_STAT_PMIC_OTP (1 << 7)
39 #define CHRG_CCCV_CC_MASK 0xf /* 4 bits */
40 #define CHRG_CCCV_CC_BIT_POS 0
41 #define CHRG_CCCV_CC_OFFSET 200 /* 200mA */
42 #define CHRG_CCCV_CC_LSB_RES 200 /* 200mA */
43 #define CHRG_CCCV_ITERM_20P (1 << 4) /* 20% of CC */
44 #define CHRG_CCCV_CV_MASK 0x60 /* 2 bits */
45 #define CHRG_CCCV_CV_BIT_POS 5
46 #define CHRG_CCCV_CV_4100MV 0x0 /* 4.10V */
47 #define CHRG_CCCV_CV_4150MV 0x1 /* 4.15V */
48 #define CHRG_CCCV_CV_4200MV 0x2 /* 4.20V */
49 #define CHRG_CCCV_CV_4350MV 0x3 /* 4.35V */
50 #define CHRG_CCCV_CHG_EN (1 << 7)
52 #define FG_CNTL_OCV_ADJ_STAT (1 << 2)
53 #define FG_CNTL_OCV_ADJ_EN (1 << 3)
54 #define FG_CNTL_CAP_ADJ_STAT (1 << 4)
55 #define FG_CNTL_CAP_ADJ_EN (1 << 5)
56 #define FG_CNTL_CC_EN (1 << 6)
57 #define FG_CNTL_GAUGE_EN (1 << 7)
59 #define FG_15BIT_WORD_VALID (1 << 15)
60 #define FG_15BIT_VAL_MASK 0x7fff
62 #define FG_REP_CAP_VALID (1 << 7)
63 #define FG_REP_CAP_VAL_MASK 0x7F
65 #define FG_DES_CAP1_VALID (1 << 7)
66 #define FG_DES_CAP_RES_LSB 1456 /* 1.456mAhr */
68 #define FG_DES_CC_RES_LSB 1456 /* 1.456mAhr */
70 #define FG_OCV_CAP_VALID (1 << 7)
71 #define FG_OCV_CAP_VAL_MASK 0x7F
72 #define FG_CC_CAP_VALID (1 << 7)
73 #define FG_CC_CAP_VAL_MASK 0x7F
75 #define FG_LOW_CAP_THR1_MASK 0xf0 /* 5% tp 20% */
76 #define FG_LOW_CAP_THR1_VAL 0xa0 /* 15 perc */
77 #define FG_LOW_CAP_THR2_MASK 0x0f /* 0% to 15% */
78 #define FG_LOW_CAP_WARN_THR 14 /* 14 perc */
79 #define FG_LOW_CAP_CRIT_THR 4 /* 4 perc */
80 #define FG_LOW_CAP_SHDN_THR 0 /* 0 perc */
82 #define DEV_NAME "axp288_fuel_gauge"
84 /* 1.1mV per LSB expressed in uV */
85 #define VOLTAGE_FROM_ADC(a) ((a * 11) / 10)
86 /* properties converted to uV, uA */
87 #define PROP_VOLT(a) ((a) * 1000)
88 #define PROP_CURR(a) ((a) * 1000)
90 #define AXP288_REG_UPDATE_INTERVAL (60 * HZ)
91 #define AXP288_FG_INTR_NUM 6
93 #define AXP288_QUIRK_NO_BATTERY BIT(0)
95 static bool no_current_sense_res
;
96 module_param(no_current_sense_res
, bool, 0444);
97 MODULE_PARM_DESC(no_current_sense_res
, "No (or broken) current sense resistor");
115 struct axp288_fg_info
{
117 struct regmap
*regmap
;
118 int irq
[AXP288_FG_INTR_NUM
];
119 struct iio_channel
*iio_channel
[IIO_CHANNEL_NUM
];
120 struct power_supply
*bat
;
126 struct dentry
*debug_file
;
128 char valid
; /* zero until following fields are valid */
129 unsigned long last_updated
; /* in jiffies */
141 static enum power_supply_property fuel_gauge_props
[] = {
142 POWER_SUPPLY_PROP_STATUS
,
143 POWER_SUPPLY_PROP_PRESENT
,
144 POWER_SUPPLY_PROP_HEALTH
,
145 POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN
,
146 POWER_SUPPLY_PROP_VOLTAGE_NOW
,
147 POWER_SUPPLY_PROP_VOLTAGE_OCV
,
148 POWER_SUPPLY_PROP_CAPACITY
,
149 POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN
,
150 POWER_SUPPLY_PROP_TECHNOLOGY
,
151 /* The 3 props below are not used when no_current_sense_res is set */
152 POWER_SUPPLY_PROP_CHARGE_FULL
,
153 POWER_SUPPLY_PROP_CHARGE_NOW
,
154 POWER_SUPPLY_PROP_CURRENT_NOW
,
157 static int fuel_gauge_reg_readb(struct axp288_fg_info
*info
, int reg
)
162 ret
= regmap_read(info
->regmap
, reg
, &val
);
164 dev_err(info
->dev
, "Error reading reg 0x%02x err: %d\n", reg
, ret
);
171 static int fuel_gauge_reg_writeb(struct axp288_fg_info
*info
, int reg
, u8 val
)
175 ret
= regmap_write(info
->regmap
, reg
, (unsigned int)val
);
178 dev_err(info
->dev
, "Error writing reg 0x%02x err: %d\n", reg
, ret
);
183 static int fuel_gauge_read_15bit_word(struct axp288_fg_info
*info
, int reg
)
185 unsigned char buf
[2];
188 ret
= regmap_bulk_read(info
->regmap
, reg
, buf
, 2);
190 dev_err(info
->dev
, "Error reading reg 0x%02x err: %d\n", reg
, ret
);
194 ret
= get_unaligned_be16(buf
);
195 if (!(ret
& FG_15BIT_WORD_VALID
)) {
196 dev_err(info
->dev
, "Error reg 0x%02x contents not valid\n", reg
);
200 return ret
& FG_15BIT_VAL_MASK
;
203 static int fuel_gauge_read_12bit_word(struct axp288_fg_info
*info
, int reg
)
205 unsigned char buf
[2];
208 ret
= regmap_bulk_read(info
->regmap
, reg
, buf
, 2);
210 dev_err(info
->dev
, "Error reading reg 0x%02x err: %d\n", reg
, ret
);
214 /* 12-bit data values have upper 8 bits in buf[0], lower 4 in buf[1] */
215 return (buf
[0] << 4) | ((buf
[1] >> 4) & 0x0f);
218 static int fuel_gauge_update_registers(struct axp288_fg_info
*info
)
222 if (info
->valid
&& time_before(jiffies
, info
->last_updated
+ AXP288_REG_UPDATE_INTERVAL
))
225 dev_dbg(info
->dev
, "Fuel Gauge updating register values...\n");
227 ret
= iosf_mbi_block_punit_i2c_access();
231 ret
= fuel_gauge_reg_readb(info
, AXP20X_PWR_INPUT_STATUS
);
234 info
->pwr_stat
= ret
;
236 if (no_current_sense_res
)
237 ret
= fuel_gauge_reg_readb(info
, AXP288_FG_OCV_CAP_REG
);
239 ret
= fuel_gauge_reg_readb(info
, AXP20X_FG_RES
);
244 ret
= iio_read_channel_raw(info
->iio_channel
[BAT_VOLT
], &info
->bat_volt
);
248 ret
= fuel_gauge_read_12bit_word(info
, AXP288_FG_OCVH_REG
);
253 if (no_current_sense_res
)
254 goto out_no_current_sense_res
;
256 if (info
->pwr_stat
& PS_STAT_BAT_CHRG_DIR
) {
258 ret
= iio_read_channel_raw(info
->iio_channel
[BAT_CHRG_CURR
], &info
->c_curr
);
263 ret
= iio_read_channel_raw(info
->iio_channel
[BAT_D_CURR
], &info
->d_curr
);
268 ret
= fuel_gauge_read_15bit_word(info
, AXP288_FG_CC_MTR1_REG
);
271 info
->fg_cc_mtr1
= ret
;
273 ret
= fuel_gauge_read_15bit_word(info
, AXP288_FG_DES_CAP1_REG
);
276 info
->fg_des_cap1
= ret
;
278 out_no_current_sense_res
:
279 info
->last_updated
= jiffies
;
283 iosf_mbi_unblock_punit_i2c_access();
287 static void fuel_gauge_get_status(struct axp288_fg_info
*info
)
289 int pwr_stat
= info
->pwr_stat
;
290 int fg_res
= info
->fg_res
;
291 int curr
= info
->d_curr
;
293 /* Report full if Vbus is valid and the reported capacity is 100% */
294 if (!(pwr_stat
& PS_STAT_VBUS_VALID
))
297 if (!(fg_res
& FG_REP_CAP_VALID
))
300 fg_res
&= ~FG_REP_CAP_VALID
;
302 info
->status
= POWER_SUPPLY_STATUS_FULL
;
307 * Sometimes the charger turns itself off before fg-res reaches 100%.
308 * When this happens the AXP288 reports a not-charging status and
309 * 0 mA discharge current.
311 if (fg_res
< 90 || (pwr_stat
& PS_STAT_BAT_CHRG_DIR
) || no_current_sense_res
)
315 info
->status
= POWER_SUPPLY_STATUS_FULL
;
320 if (pwr_stat
& PS_STAT_BAT_CHRG_DIR
)
321 info
->status
= POWER_SUPPLY_STATUS_CHARGING
;
323 info
->status
= POWER_SUPPLY_STATUS_DISCHARGING
;
326 static int fuel_gauge_battery_health(struct axp288_fg_info
*info
)
328 int vocv
= VOLTAGE_FROM_ADC(info
->ocv
);
329 int health
= POWER_SUPPLY_HEALTH_UNKNOWN
;
331 if (vocv
> info
->max_volt
)
332 health
= POWER_SUPPLY_HEALTH_OVERVOLTAGE
;
334 health
= POWER_SUPPLY_HEALTH_GOOD
;
339 static int fuel_gauge_get_property(struct power_supply
*ps
,
340 enum power_supply_property prop
,
341 union power_supply_propval
*val
)
343 struct axp288_fg_info
*info
= power_supply_get_drvdata(ps
);
346 mutex_lock(&info
->lock
);
348 ret
= fuel_gauge_update_registers(info
);
353 case POWER_SUPPLY_PROP_STATUS
:
354 fuel_gauge_get_status(info
);
355 val
->intval
= info
->status
;
357 case POWER_SUPPLY_PROP_HEALTH
:
358 val
->intval
= fuel_gauge_battery_health(info
);
360 case POWER_SUPPLY_PROP_VOLTAGE_NOW
:
361 value
= VOLTAGE_FROM_ADC(info
->bat_volt
);
362 val
->intval
= PROP_VOLT(value
);
364 case POWER_SUPPLY_PROP_VOLTAGE_OCV
:
365 value
= VOLTAGE_FROM_ADC(info
->ocv
);
366 val
->intval
= PROP_VOLT(value
);
368 case POWER_SUPPLY_PROP_CURRENT_NOW
:
369 if (info
->d_curr
> 0)
370 value
= -1 * info
->d_curr
;
372 value
= info
->c_curr
;
374 val
->intval
= PROP_CURR(value
);
376 case POWER_SUPPLY_PROP_PRESENT
:
377 if (info
->pwr_op
& CHRG_STAT_BAT_PRESENT
)
382 case POWER_SUPPLY_PROP_CAPACITY
:
383 if (!(info
->fg_res
& FG_REP_CAP_VALID
))
384 dev_err(info
->dev
, "capacity measurement not valid\n");
385 val
->intval
= (info
->fg_res
& FG_REP_CAP_VAL_MASK
);
387 case POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN
:
388 val
->intval
= (info
->low_cap
& 0x0f);
390 case POWER_SUPPLY_PROP_TECHNOLOGY
:
391 val
->intval
= POWER_SUPPLY_TECHNOLOGY_LION
;
393 case POWER_SUPPLY_PROP_CHARGE_NOW
:
394 val
->intval
= info
->fg_cc_mtr1
* FG_DES_CAP_RES_LSB
;
396 case POWER_SUPPLY_PROP_CHARGE_FULL
:
397 val
->intval
= info
->fg_des_cap1
* FG_DES_CAP_RES_LSB
;
399 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN
:
400 val
->intval
= PROP_VOLT(info
->max_volt
);
407 mutex_unlock(&info
->lock
);
411 static int fuel_gauge_set_property(struct power_supply
*ps
,
412 enum power_supply_property prop
,
413 const union power_supply_propval
*val
)
415 struct axp288_fg_info
*info
= power_supply_get_drvdata(ps
);
416 int new_low_cap
, ret
= 0;
418 mutex_lock(&info
->lock
);
420 case POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN
:
421 if ((val
->intval
< 0) || (val
->intval
> 15)) {
425 new_low_cap
= info
->low_cap
;
427 new_low_cap
|= (val
->intval
& 0xf);
428 ret
= fuel_gauge_reg_writeb(info
, AXP288_FG_LOW_CAP_REG
, new_low_cap
);
430 info
->low_cap
= new_low_cap
;
437 mutex_unlock(&info
->lock
);
441 static int fuel_gauge_property_is_writeable(struct power_supply
*psy
,
442 enum power_supply_property psp
)
447 case POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN
:
457 static irqreturn_t
fuel_gauge_thread_handler(int irq
, void *dev
)
459 struct axp288_fg_info
*info
= dev
;
462 for (i
= 0; i
< AXP288_FG_INTR_NUM
; i
++) {
463 if (info
->irq
[i
] == irq
)
467 if (i
>= AXP288_FG_INTR_NUM
) {
468 dev_warn(info
->dev
, "spurious interrupt!!\n");
474 dev_info(info
->dev
, "Quit Battery under temperature in work mode IRQ (QWBTU)\n");
477 dev_info(info
->dev
, "Battery under temperature in work mode IRQ (WBTU)\n");
480 dev_info(info
->dev
, "Quit Battery over temperature in work mode IRQ (QWBTO)\n");
483 dev_info(info
->dev
, "Battery over temperature in work mode IRQ (WBTO)\n");
486 dev_info(info
->dev
, "Low Batt Warning(2) INTR\n");
489 dev_info(info
->dev
, "Low Batt Warning(1) INTR\n");
492 dev_warn(info
->dev
, "Spurious Interrupt!!!\n");
495 mutex_lock(&info
->lock
);
496 info
->valid
= 0; /* Force updating of the cached registers */
497 mutex_unlock(&info
->lock
);
499 power_supply_changed(info
->bat
);
503 static void fuel_gauge_external_power_changed(struct power_supply
*psy
)
505 struct axp288_fg_info
*info
= power_supply_get_drvdata(psy
);
507 mutex_lock(&info
->lock
);
508 info
->valid
= 0; /* Force updating of the cached registers */
509 mutex_unlock(&info
->lock
);
510 power_supply_changed(psy
);
513 static struct power_supply_desc fuel_gauge_desc
= {
515 .type
= POWER_SUPPLY_TYPE_BATTERY
,
516 .properties
= fuel_gauge_props
,
517 .num_properties
= ARRAY_SIZE(fuel_gauge_props
),
518 .get_property
= fuel_gauge_get_property
,
519 .set_property
= fuel_gauge_set_property
,
520 .property_is_writeable
= fuel_gauge_property_is_writeable
,
521 .external_power_changed
= fuel_gauge_external_power_changed
,
525 * Some devices have no battery (HDMI sticks) and the axp288 battery's
526 * detection reports one despite it not being there.
527 * Please keep this listed sorted alphabetically.
529 static const struct dmi_system_id axp288_quirks
[] = {
531 /* ACEPC T8 Cherry Trail Z8350 mini PC */
533 DMI_EXACT_MATCH(DMI_BOARD_VENDOR
, "To be filled by O.E.M."),
534 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "Cherry Trail CR"),
535 DMI_EXACT_MATCH(DMI_PRODUCT_SKU
, "T8"),
536 /* also match on somewhat unique bios-version */
537 DMI_EXACT_MATCH(DMI_BIOS_VERSION
, "1.000"),
539 .driver_data
= (void *)AXP288_QUIRK_NO_BATTERY
,
542 /* ACEPC T11 Cherry Trail Z8350 mini PC */
544 DMI_EXACT_MATCH(DMI_BOARD_VENDOR
, "To be filled by O.E.M."),
545 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "Cherry Trail CR"),
546 DMI_EXACT_MATCH(DMI_PRODUCT_SKU
, "T11"),
547 /* also match on somewhat unique bios-version */
548 DMI_EXACT_MATCH(DMI_BIOS_VERSION
, "1.000"),
550 .driver_data
= (void *)AXP288_QUIRK_NO_BATTERY
,
553 /* Intel Bay Trail Compute Stick */
555 DMI_MATCH(DMI_SYS_VENDOR
, "Intel"),
556 /* Partial match for STCK1A32WFC STCK1A32FC, STCK1A8LFC variants */
557 DMI_MATCH(DMI_PRODUCT_NAME
, "STCK1A"),
559 .driver_data
= (void *)AXP288_QUIRK_NO_BATTERY
,
562 /* Intel Cherry Trail Compute Stick */
564 DMI_MATCH(DMI_SYS_VENDOR
, "Intel"),
565 /* Partial match for STK1AW32SC and STK1A32SC variants */
566 DMI_MATCH(DMI_PRODUCT_NAME
, "STK1A"),
568 .driver_data
= (void *)AXP288_QUIRK_NO_BATTERY
,
573 DMI_MATCH(DMI_PRODUCT_NAME
, "MEEGOPAD T02"),
575 .driver_data
= (void *)AXP288_QUIRK_NO_BATTERY
,
577 { /* Mele PCG03 Mini PC */
579 DMI_EXACT_MATCH(DMI_BOARD_VENDOR
, "Mini PC"),
580 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "Mini PC"),
582 .driver_data
= (void *)AXP288_QUIRK_NO_BATTERY
,
585 /* Minix Neo Z83-4 mini PC */
587 DMI_MATCH(DMI_SYS_VENDOR
, "MINIX"),
588 DMI_MATCH(DMI_PRODUCT_NAME
, "Z83-4"),
590 .driver_data
= (void *)AXP288_QUIRK_NO_BATTERY
,
594 * One Mix 1, this uses the "T3 MRD" boardname used by
595 * generic mini PCs, but it is a mini laptop so it does
596 * actually have a battery!
599 DMI_MATCH(DMI_BOARD_NAME
, "T3 MRD"),
600 DMI_MATCH(DMI_BIOS_DATE
, "06/14/2018"),
605 /* Radxa ROCK Pi X Single Board Computer */
607 DMI_MATCH(DMI_BOARD_NAME
, "ROCK Pi X"),
608 DMI_MATCH(DMI_BOARD_VENDOR
, "Radxa"),
610 .driver_data
= (void *)AXP288_QUIRK_NO_BATTERY
,
614 * Various Ace PC/Meegopad/MinisForum/Wintel Mini-PCs/HDMI-sticks
615 * This entry must be last because it is generic, this allows
616 * adding more specifuc quirks overriding this generic entry.
619 DMI_MATCH(DMI_BOARD_NAME
, "T3 MRD"),
620 DMI_MATCH(DMI_CHASSIS_TYPE
, "3"),
621 DMI_MATCH(DMI_BIOS_VENDOR
, "American Megatrends Inc."),
623 .driver_data
= (void *)AXP288_QUIRK_NO_BATTERY
,
628 static int axp288_fuel_gauge_read_initial_regs(struct axp288_fg_info
*info
)
634 * On some devices the fuelgauge and charger parts of the axp288 are
635 * not used, check that the fuelgauge is enabled (CC_CTRL != 0).
637 ret
= regmap_read(info
->regmap
, AXP20X_CC_CTRL
, &val
);
643 ret
= fuel_gauge_reg_readb(info
, AXP288_FG_DES_CAP1_REG
);
647 if (!(ret
& FG_DES_CAP1_VALID
)) {
648 dev_err(info
->dev
, "axp288 not configured by firmware\n");
652 ret
= fuel_gauge_reg_readb(info
, AXP20X_CHRG_CTRL1
);
655 switch ((ret
& CHRG_CCCV_CV_MASK
) >> CHRG_CCCV_CV_BIT_POS
) {
656 case CHRG_CCCV_CV_4100MV
:
657 info
->max_volt
= 4100;
659 case CHRG_CCCV_CV_4150MV
:
660 info
->max_volt
= 4150;
662 case CHRG_CCCV_CV_4200MV
:
663 info
->max_volt
= 4200;
665 case CHRG_CCCV_CV_4350MV
:
666 info
->max_volt
= 4350;
670 ret
= fuel_gauge_reg_readb(info
, AXP20X_PWR_OP_MODE
);
675 ret
= fuel_gauge_reg_readb(info
, AXP288_FG_LOW_CAP_REG
);
683 static void axp288_fuel_gauge_release_iio_chans(void *data
)
685 struct axp288_fg_info
*info
= data
;
688 for (i
= 0; i
< IIO_CHANNEL_NUM
; i
++)
689 if (!IS_ERR_OR_NULL(info
->iio_channel
[i
]))
690 iio_channel_release(info
->iio_channel
[i
]);
693 static int axp288_fuel_gauge_probe(struct platform_device
*pdev
)
695 struct axp288_fg_info
*info
;
696 struct axp20x_dev
*axp20x
= dev_get_drvdata(pdev
->dev
.parent
);
697 struct power_supply_config psy_cfg
= {};
698 static const char * const iio_chan_name
[] = {
699 [BAT_CHRG_CURR
] = "axp288-chrg-curr",
700 [BAT_D_CURR
] = "axp288-chrg-d-curr",
701 [BAT_VOLT
] = "axp288-batt-volt",
703 const struct dmi_system_id
*dmi_id
;
704 struct device
*dev
= &pdev
->dev
;
705 unsigned long quirks
= 0;
709 * Normally the native AXP288 fg/charger drivers are preferred but
710 * on some devices the ACPI drivers should be used instead.
712 if (!acpi_quirk_skip_acpi_ac_and_battery())
715 dmi_id
= dmi_first_match(axp288_quirks
);
717 quirks
= (unsigned long)dmi_id
->driver_data
;
719 if (quirks
& AXP288_QUIRK_NO_BATTERY
)
722 info
= devm_kzalloc(dev
, sizeof(*info
), GFP_KERNEL
);
727 info
->regmap
= axp20x
->regmap
;
728 info
->status
= POWER_SUPPLY_STATUS_UNKNOWN
;
731 platform_set_drvdata(pdev
, info
);
733 mutex_init(&info
->lock
);
735 for (i
= 0; i
< AXP288_FG_INTR_NUM
; i
++) {
736 pirq
= platform_get_irq(pdev
, i
);
739 ret
= regmap_irq_get_virq(axp20x
->regmap_irqc
, pirq
);
741 return dev_err_probe(dev
, ret
, "getting vIRQ %d\n", pirq
);
746 for (i
= 0; i
< IIO_CHANNEL_NUM
; i
++) {
748 * Note cannot use devm_iio_channel_get because x86 systems
749 * lack the device<->channel maps which iio_channel_get will
750 * try to use when passed a non NULL device pointer.
752 info
->iio_channel
[i
] =
753 iio_channel_get(NULL
, iio_chan_name
[i
]);
754 if (IS_ERR(info
->iio_channel
[i
])) {
755 ret
= PTR_ERR(info
->iio_channel
[i
]);
756 dev_dbg(dev
, "error getting iiochan %s: %d\n", iio_chan_name
[i
], ret
);
757 /* Wait for axp288_adc to load */
761 axp288_fuel_gauge_release_iio_chans(info
);
766 ret
= devm_add_action_or_reset(dev
, axp288_fuel_gauge_release_iio_chans
, info
);
770 ret
= iosf_mbi_block_punit_i2c_access();
774 ret
= axp288_fuel_gauge_read_initial_regs(info
);
775 iosf_mbi_unblock_punit_i2c_access();
779 psy_cfg
.drv_data
= info
;
780 if (no_current_sense_res
)
781 fuel_gauge_desc
.num_properties
= ARRAY_SIZE(fuel_gauge_props
) - 3;
782 info
->bat
= devm_power_supply_register(dev
, &fuel_gauge_desc
, &psy_cfg
);
783 if (IS_ERR(info
->bat
)) {
784 ret
= PTR_ERR(info
->bat
);
785 dev_err(dev
, "failed to register battery: %d\n", ret
);
789 for (i
= 0; i
< AXP288_FG_INTR_NUM
; i
++) {
790 ret
= devm_request_threaded_irq(dev
, info
->irq
[i
], NULL
,
791 fuel_gauge_thread_handler
,
792 IRQF_ONESHOT
, DEV_NAME
, info
);
794 return dev_err_probe(dev
, ret
, "requesting IRQ %d\n", info
->irq
[i
]);
800 static const struct platform_device_id axp288_fg_id_table
[] = {
801 { .name
= DEV_NAME
},
804 MODULE_DEVICE_TABLE(platform
, axp288_fg_id_table
);
806 static struct platform_driver axp288_fuel_gauge_driver
= {
807 .probe
= axp288_fuel_gauge_probe
,
808 .id_table
= axp288_fg_id_table
,
814 module_platform_driver(axp288_fuel_gauge_driver
);
816 MODULE_AUTHOR("Ramakrishna Pallala <ramakrishna.pallala@intel.com>");
817 MODULE_AUTHOR("Todd Brandt <todd.e.brandt@linux.intel.com>");
818 MODULE_DESCRIPTION("Xpower AXP288 Fuel Gauge Driver");
819 MODULE_LICENSE("GPL");