[U-Boot] [PATCH 14/16] pmic:max8997: Support for MAX8997 internal charger control
Lukasz Majewski
l.majewski at samsung.com
Fri Sep 14 17:40:13 CEST 2012
Support for MAX8997 built-in charger.
Signed-off-by: Lukasz Majewski <l.majewski at samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park at samsung.com>
Cc: Stefano Babic <sbabic at denx.de>
---
drivers/misc/pmic_max8997.c | 52 ++++++++++++++++++++++++++++++++++++++++++
include/power/max8997_pmic.h | 3 +-
2 files changed, 54 insertions(+), 1 deletions(-)
diff --git a/drivers/misc/pmic_max8997.c b/drivers/misc/pmic_max8997.c
index a4158e2..5fd2ae8 100644
--- a/drivers/misc/pmic_max8997.c
+++ b/drivers/misc/pmic_max8997.c
@@ -59,3 +59,55 @@ unsigned char max8997_reg_ldo(int uV)
return ret;
}
+int pmic_charger_state(int state, int current)
+{
+ struct pmic *p = pmic_get("MAX8997_PMIC");
+ unsigned char fc;
+ u32 val = 0;
+
+ if (pmic_probe(p))
+ return -1;
+
+ if (state == CHARGER_DISABLE) {
+ puts("Disable the charger.\n");
+ pmic_reg_read(p, MAX8997_REG_MBCCTRL2, &val);
+ val &= ~(MBCHOSTEN | VCHGR_FC);
+ pmic_reg_write(p, MAX8997_REG_MBCCTRL2, val);
+
+ return -1;
+ }
+
+ if (current < CHARGER_MIN_CURRENT || current > CHARGER_MAX_CURRENT) {
+ printf("%s: Wrong charge current: %d [mA]\n",
+ __func__, current);
+ return -1;
+ }
+
+ fc = (current - CHARGER_MIN_CURRENT) / CHARGER_CURRENT_RESOLUTION;
+ fc = fc & 0xf; /* up to 950 mA */
+
+ printf("Enable the charger @ %d [mA]\n", fc * CHARGER_CURRENT_RESOLUTION
+ + CHARGER_MIN_CURRENT);
+
+ val = fc | MBCICHFCSET;
+ pmic_reg_write(p, MAX8997_REG_MBCCTRL4, val);
+
+ pmic_reg_read(p, MAX8997_REG_MBCCTRL2, &val);
+ val = MBCHOSTEN | VCHGR_FC; /* enable charger & fast charge */
+ pmic_reg_write(p, MAX8997_REG_MBCCTRL2, val);
+
+ return 0;
+}
+
+int pmic_charger_bat_present(void)
+{
+ struct pmic *p = pmic_get("MAX8997_PMIC");
+ u32 val;
+
+ if (pmic_probe(p))
+ return -1;
+
+ pmic_reg_read(p, MAX8997_REG_STATUS4, &val);
+
+ return !(val & DETBAT);
+}
diff --git a/include/power/max8997_pmic.h b/include/power/max8997_pmic.h
index b7edee4..b3baada 100644
--- a/include/power/max8997_pmic.h
+++ b/include/power/max8997_pmic.h
@@ -209,6 +209,7 @@ enum {
EN_LDO = (0x3 << 6),
};
+int pmic_charger_state(int state, int current);
unsigned char max8997_reg_ldo(int uV);
-
+int pmic_charger_bat_present(void);
#endif /* __MAX8997_PMIC_H_ */
--
1.7.2.3
More information about the U-Boot
mailing list