diff options
| author | Mark A. Greer <mgreer@animalcreek.com> | 2013-08-23 22:21:03 -0400 |
|---|---|---|
| committer | Anton Vorontsov <anton@enomsg.org> | 2013-08-27 21:17:54 -0400 |
| commit | d7bf353fd0aa3e12060ce64c8a7b4aaf4336145c (patch) | |
| tree | 2c2464a7b173e3f8b387cd618b3f235dc31c8e77 | |
| parent | ed5243f8ab2470e988dce0e416eaaddb4d7d2ccc (diff) | |
bq24190_charger: Add support for TI BQ24190 Battery Charger
Add driver support for the Texas Instruments BQ24190 battery charger.
Some of the information provided by the device is about the charger and
other information is about the battery so create two power_supply objects
(one for each) and provide the appropriate information for each one.
The device has many fields that go beyond what is reasonable to report or
modify using the existing 'POWER_SUPPLY_PROP_*' properties so the driver
exports the register fields via sysfs. They are prefixed by 'f_' (for
'field') to make it easier to distinguish between a register field and a
"normal" sysfs file exported by the power_supply infrastructure.
Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
Signed-off-by: Anton Vorontsov <anton@enomsg.org>
| -rw-r--r-- | drivers/power/Kconfig | 6 | ||||
| -rw-r--r-- | drivers/power/Makefile | 1 | ||||
| -rw-r--r-- | drivers/power/bq24190_charger.c | 1546 | ||||
| -rw-r--r-- | include/linux/power/bq24190_charger.h | 16 |
4 files changed, 1569 insertions, 0 deletions
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index dcc0d9e5817d..e8970a65ba52 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig | |||
| @@ -334,6 +334,12 @@ config CHARGER_BQ2415X | |||
| 334 | You'll need this driver to charge batteries on e.g. Nokia | 334 | You'll need this driver to charge batteries on e.g. Nokia |
| 335 | RX-51/N900. | 335 | RX-51/N900. |
| 336 | 336 | ||
| 337 | config CHARGER_BQ24190 | ||
| 338 | tristate "TI BQ24190 battery charger driver" | ||
| 339 | depends on I2C && GPIOLIB | ||
| 340 | help | ||
| 341 | Say Y to enable support for the TI BQ24190 battery charger. | ||
| 342 | |||
| 337 | config CHARGER_SMB347 | 343 | config CHARGER_SMB347 |
| 338 | tristate "Summit Microelectronics SMB347 Battery Charger" | 344 | tristate "Summit Microelectronics SMB347 Battery Charger" |
| 339 | depends on I2C | 345 | depends on I2C |
diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 653bf6ceff30..4ae45339e32c 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile | |||
| @@ -50,6 +50,7 @@ obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o | |||
| 50 | obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o | 50 | obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o |
| 51 | obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o | 51 | obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o |
| 52 | obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o | 52 | obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o |
| 53 | obj-$(CONFIG_CHARGER_BQ24190) += bq24190_charger.o | ||
| 53 | obj-$(CONFIG_POWER_AVS) += avs/ | 54 | obj-$(CONFIG_POWER_AVS) += avs/ |
| 54 | obj-$(CONFIG_CHARGER_SMB347) += smb347-charger.o | 55 | obj-$(CONFIG_CHARGER_SMB347) += smb347-charger.o |
| 55 | obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o | 56 | obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o |
diff --git a/drivers/power/bq24190_charger.c b/drivers/power/bq24190_charger.c new file mode 100644 index 000000000000..2b0f0e0b58a2 --- /dev/null +++ b/drivers/power/bq24190_charger.c | |||
| @@ -0,0 +1,1546 @@ | |||
| 1 | /* | ||
| 2 | * Driver for the TI bq24190 battery charger. | ||
| 3 | * | ||
| 4 | * Author: Mark A. Greer <mgreer@animalcreek.com> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License version 2 as | ||
| 8 | * published by the Free Software Foundation. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/module.h> | ||
| 12 | #include <linux/interrupt.h> | ||
| 13 | #include <linux/delay.h> | ||
| 14 | #include <linux/of_irq.h> | ||
| 15 | #include <linux/of_device.h> | ||
| 16 | #include <linux/pm_runtime.h> | ||
| 17 | #include <linux/power_supply.h> | ||
| 18 | #include <linux/gpio.h> | ||
| 19 | #include <linux/i2c.h> | ||
| 20 | |||
| 21 | #include <linux/power/bq24190_charger.h> | ||
| 22 | |||
| 23 | |||
| 24 | #define BQ24190_MANUFACTURER "Texas Instruments" | ||
| 25 | |||
| 26 | #define BQ24190_REG_ISC 0x00 /* Input Source Control */ | ||
| 27 | #define BQ24190_REG_ISC_EN_HIZ_MASK BIT(7) | ||
| 28 | #define BQ24190_REG_ISC_EN_HIZ_SHIFT 7 | ||
| 29 | #define BQ24190_REG_ISC_VINDPM_MASK (BIT(6) | BIT(5) | BIT(4) | \ | ||
| 30 | BIT(3)) | ||
| 31 | #define BQ24190_REG_ISC_VINDPM_SHIFT 3 | ||
| 32 | #define BQ24190_REG_ISC_IINLIM_MASK (BIT(2) | BIT(1) | BIT(0)) | ||
| 33 | #define BQ24190_REG_ISC_IINLIM_SHIFT 0 | ||
| 34 | |||
| 35 | #define BQ24190_REG_POC 0x01 /* Power-On Configuration */ | ||
| 36 | #define BQ24190_REG_POC_RESET_MASK BIT(7) | ||
| 37 | #define BQ24190_REG_POC_RESET_SHIFT 7 | ||
| 38 | #define BQ24190_REG_POC_WDT_RESET_MASK BIT(6) | ||
| 39 | #define BQ24190_REG_POC_WDT_RESET_SHIFT 6 | ||
| 40 | #define BQ24190_REG_POC_CHG_CONFIG_MASK (BIT(5) | BIT(4)) | ||
| 41 | #define BQ24190_REG_POC_CHG_CONFIG_SHIFT 4 | ||
| 42 | #define BQ24190_REG_POC_SYS_MIN_MASK (BIT(3) | BIT(2) | BIT(1)) | ||
| 43 | #define BQ24190_REG_POC_SYS_MIN_SHIFT 1 | ||
| 44 | #define BQ24190_REG_POC_BOOST_LIM_MASK BIT(0) | ||
| 45 | #define BQ24190_REG_POC_BOOST_LIM_SHIFT 0 | ||
| 46 | |||
| 47 | #define BQ24190_REG_CCC 0x02 /* Charge Current Control */ | ||
| 48 | #define BQ24190_REG_CCC_ICHG_MASK (BIT(7) | BIT(6) | BIT(5) | \ | ||
| 49 | BIT(4) | BIT(3) | BIT(2)) | ||
| 50 | #define BQ24190_REG_CCC_ICHG_SHIFT 2 | ||
| 51 | #define BQ24190_REG_CCC_FORCE_20PCT_MASK BIT(0) | ||
| 52 | #define BQ24190_REG_CCC_FORCE_20PCT_SHIFT 0 | ||
| 53 | |||
| 54 | #define BQ24190_REG_PCTCC 0x03 /* Pre-charge/Termination Current Cntl */ | ||
| 55 | #define BQ24190_REG_PCTCC_IPRECHG_MASK (BIT(7) | BIT(6) | BIT(5) | \ | ||
| 56 | BIT(4)) | ||
| 57 | #define BQ24190_REG_PCTCC_IPRECHG_SHIFT 4 | ||
| 58 | #define BQ24190_REG_PCTCC_ITERM_MASK (BIT(3) | BIT(2) | BIT(1) | \ | ||
| 59 | BIT(0)) | ||
| 60 | #define BQ24190_REG_PCTCC_ITERM_SHIFT 0 | ||
| 61 | |||
| 62 | #define BQ24190_REG_CVC 0x04 /* Charge Voltage Control */ | ||
| 63 | #define BQ24190_REG_CVC_VREG_MASK (BIT(7) | BIT(6) | BIT(5) | \ | ||
| 64 | BIT(4) | BIT(3) | BIT(2)) | ||
| 65 | #define BQ24190_REG_CVC_VREG_SHIFT 2 | ||
| 66 | #define BQ24190_REG_CVC_BATLOWV_MASK BIT(1) | ||
| 67 | #define BQ24190_REG_CVC_BATLOWV_SHIFT 1 | ||
| 68 | #define BQ24190_REG_CVC_VRECHG_MASK BIT(0) | ||
| 69 | #define BQ24190_REG_CVC_VRECHG_SHIFT 0 | ||
| 70 | |||
| 71 | #define BQ24190_REG_CTTC 0x05 /* Charge Term/Timer Control */ | ||
| 72 | #define BQ24190_REG_CTTC_EN_TERM_MASK BIT(7) | ||
| 73 | #define BQ24190_REG_CTTC_EN_TERM_SHIFT 7 | ||
| 74 | #define BQ24190_REG_CTTC_TERM_STAT_MASK BIT(6) | ||
| 75 | #define BQ24190_REG_CTTC_TERM_STAT_SHIFT 6 | ||
| 76 | #define BQ24190_REG_CTTC_WATCHDOG_MASK (BIT(5) | BIT(4)) | ||
| 77 | #define BQ24190_REG_CTTC_WATCHDOG_SHIFT 4 | ||
| 78 | #define BQ24190_REG_CTTC_EN_TIMER_MASK BIT(3) | ||
| 79 | #define BQ24190_REG_CTTC_EN_TIMER_SHIFT 3 | ||
| 80 | #define BQ24190_REG_CTTC_CHG_TIMER_MASK (BIT(2) | BIT(1)) | ||
| 81 | #define BQ24190_REG_CTTC_CHG_TIMER_SHIFT 1 | ||
| 82 | #define BQ24190_REG_CTTC_JEITA_ISET_MASK BIT(0) | ||
| 83 | #define BQ24190_REG_CTTC_JEITA_ISET_SHIFT 0 | ||
| 84 | |||
| 85 | #define BQ24190_REG_ICTRC 0x06 /* IR Comp/Thermal Regulation Control */ | ||
| 86 | #define BQ24190_REG_ICTRC_BAT_COMP_MASK (BIT(7) | BIT(6) | BIT(5)) | ||
| 87 | #define BQ24190_REG_ICTRC_BAT_COMP_SHIFT 5 | ||
| 88 | #define BQ24190_REG_ICTRC_VCLAMP_MASK (BIT(4) | BIT(3) | BIT(2)) | ||
| 89 | #define BQ24190_REG_ICTRC_VCLAMP_SHIFT 2 | ||
| 90 | #define BQ24190_REG_ICTRC_TREG_MASK (BIT(1) | BIT(0)) | ||
| 91 | #define BQ24190_REG_ICTRC_TREG_SHIFT 0 | ||
| 92 | |||
| 93 | #define BQ24190_REG_MOC 0x07 /* Misc. Operation Control */ | ||
| 94 | #define BQ24190_REG_MOC_DPDM_EN_MASK BIT(7) | ||
| 95 | #define BQ24190_REG_MOC_DPDM_EN_SHIFT 7 | ||
| 96 | #define BQ24190_REG_MOC_TMR2X_EN_MASK BIT(6) | ||
| 97 | #define BQ24190_REG_MOC_TMR2X_EN_SHIFT 6 | ||
| 98 | #define BQ24190_REG_MOC_BATFET_DISABLE_MASK BIT(5) | ||
| 99 | #define BQ24190_REG_MOC_BATFET_DISABLE_SHIFT 5 | ||
| 100 | #define BQ24190_REG_MOC_JEITA_VSET_MASK BIT(4) | ||
| 101 | #define BQ24190_REG_MOC_JEITA_VSET_SHIFT 4 | ||
| 102 | #define BQ24190_REG_MOC_INT_MASK_MASK (BIT(1) | BIT(0)) | ||
| 103 | #define BQ24190_REG_MOC_INT_MASK_SHIFT 0 | ||
| 104 | |||
| 105 | #define BQ24190_REG_SS 0x08 /* System Status */ | ||
| 106 | #define BQ24190_REG_SS_VBUS_STAT_MASK (BIT(7) | BIT(6)) | ||
| 107 | #define BQ24190_REG_SS_VBUS_STAT_SHIFT 6 | ||
| 108 | #define BQ24190_REG_SS_CHRG_STAT_MASK (BIT(5) | BIT(4)) | ||
| 109 | #define BQ24190_REG_SS_CHRG_STAT_SHIFT 4 | ||
| 110 | #define BQ24190_REG_SS_DPM_STAT_MASK BIT(3) | ||
| 111 | #define BQ24190_REG_SS_DPM_STAT_SHIFT 3 | ||
| 112 | #define BQ24190_REG_SS_PG_STAT_MASK BIT(2) | ||
| 113 | #define BQ24190_REG_SS_PG_STAT_SHIFT 2 | ||
| 114 | #define BQ24190_REG_SS_THERM_STAT_MASK BIT(1) | ||
| 115 | #define BQ24190_REG_SS_THERM_STAT_SHIFT 1 | ||
| 116 | #define BQ24190_REG_SS_VSYS_STAT_MASK BIT(0) | ||
| 117 | #define BQ24190_REG_SS_VSYS_STAT_SHIFT 0 | ||
| 118 | |||
| 119 | #define BQ24190_REG_F 0x09 /* Fault */ | ||
| 120 | #define BQ24190_REG_F_WATCHDOG_FAULT_MASK BIT(7) | ||
| 121 | #define BQ24190_REG_F_WATCHDOG_FAULT_SHIFT 7 | ||
| 122 | #define BQ24190_REG_F_BOOST_FAULT_MASK BIT(6) | ||
| 123 | #define BQ24190_REG_F_BOOST_FAULT_SHIFT 6 | ||
| 124 | #define BQ24190_REG_F_CHRG_FAULT_MASK (BIT(5) | BIT(4)) | ||
| 125 | #define BQ24190_REG_F_CHRG_FAULT_SHIFT 4 | ||
| 126 | #define BQ24190_REG_F_BAT_FAULT_MASK BIT(3) | ||
| 127 | #define BQ24190_REG_F_BAT_FAULT_SHIFT 3 | ||
| 128 | #define BQ24190_REG_F_NTC_FAULT_MASK (BIT(2) | BIT(1) | BIT(0)) | ||
| 129 | #define BQ24190_REG_F_NTC_FAULT_SHIFT 0 | ||
| 130 | |||
| 131 | #define BQ24190_REG_VPRS 0x0A /* Vendor/Part/Revision Status */ | ||
| 132 | #define BQ24190_REG_VPRS_PN_MASK (BIT(5) | BIT(4) | BIT(3)) | ||
| 133 | #define BQ24190_REG_VPRS_PN_SHIFT 3 | ||
| 134 | #define BQ24190_REG_VPRS_PN_24190 0x4 | ||
| 135 | #define BQ24190_REG_VPRS_PN_24192 0x5 /* Also 24193 */ | ||
| 136 | #define BQ24190_REG_VPRS_PN_24192I 0x3 | ||
| 137 | #define BQ24190_REG_VPRS_TS_PROFILE_MASK BIT(2) | ||
| 138 | #define BQ24190_REG_VPRS_TS_PROFILE_SHIFT 2 | ||
| 139 | #define BQ24190_REG_VPRS_DEV_REG_MASK (BIT(1) | BIT(0)) | ||
| 140 | #define BQ24190_REG_VPRS_DEV_REG_SHIFT 0 | ||
| 141 | |||
| 142 | /* | ||
| 143 | * The FAULT register is latched by the bq24190 (except for NTC_FAULT) | ||
| 144 | * so the first read after a fault returns the latched value and subsequent | ||
| 145 | * reads return the current value. In order to return the fault status | ||
| 146 | * to the user, have the interrupt handler save the reg's value and retrieve | ||
| 147 | * it in the appropriate health/status routine. Each routine has its own | ||
| 148 | * flag indicating whether it should use the value stored by the last run | ||
| 149 | * of the interrupt handler or do an actual reg read. That way each routine | ||
