25 #include <linux/module.h>
32 #include <linux/device.h>
39 #define DRIVER_NAME "pmic_battery"
49 #define PMIC_BATT_DRV_INFO_UPDATED 1
50 #define PMIC_BATT_PRESENT 1
51 #define PMIC_BATT_NOT_PRESENT 0
52 #define PMIC_USB_PRESENT PMIC_BATT_PRESENT
53 #define PMIC_USB_NOT_PRESENT PMIC_BATT_NOT_PRESENT
56 #define PMIC_BATT_CHR_SCHRGINT_ADDR 0xD2
57 #define PMIC_BATT_CHR_SBATOVP_MASK (1 << 1)
58 #define PMIC_BATT_CHR_STEMP_MASK (1 << 2)
59 #define PMIC_BATT_CHR_SCOMP_MASK (1 << 3)
60 #define PMIC_BATT_CHR_SUSBDET_MASK (1 << 4)
61 #define PMIC_BATT_CHR_SBATDET_MASK (1 << 5)
62 #define PMIC_BATT_CHR_SDCLMT_MASK (1 << 6)
63 #define PMIC_BATT_CHR_SUSBOVP_MASK (1 << 7)
64 #define PMIC_BATT_CHR_EXCPT_MASK 0x86
66 #define PMIC_BATT_ADC_ACCCHRG_MASK (1 << 31)
67 #define PMIC_BATT_ADC_ACCCHRGVAL_MASK 0x7FFFFFFF
70 #define PMIC_BATT_CHR_IPC_FCHRG_SUBID 0x4
71 #define PMIC_BATT_CHR_IPC_TCHRG_SUBID 0x6
118 static unsigned int delay_time = 2000;
153 #define IPCMSG_BATTERY 0xEF
156 #define IPC_CMD_CC_WR 0
157 #define IPC_CMD_CC_RD 1
158 #define IPC_CMD_BATTERY_PROPERTY 2
170 static int pmic_scu_ipc_battery_cc_read(
u32 *
value)
188 u8 *
p = (
u8 *)&data[1];
209 static int pmic_scu_ipc_set_charger(
int charger)
256 unsigned int update_time_intrvl;
257 unsigned int chrg_val;
261 int batt_present = 0;
263 int batt_exception = 0;
274 if (pmic_scu_ipc_battery_cc_read(&ccval)) {
275 dev_warn(pbi->
dev,
"%s(): ipc config cmd failed\n",
344 if (pmic_scu_ipc_battery_property_get(&batt_prop)) {
345 dev_warn(pbi->
dev,
"%s(): ipc config cmd failed\n",
353 if (batt_present && !batt_exception) {
369 chrg_val) * 1000 * 60) /
385 if (batt_present && !batt_exception)
403 static int pmic_usb_get_property(
struct power_supply *psy,
411 pmic_battery_read_status(pbi);
427 static inline unsigned long mAStouAh(
unsigned long v)
430 return (v * 1000) / 3600;
443 static int pmic_battery_get_property(
struct power_supply *psy,
451 pmic_battery_read_status(pbi);
490 pmic_battery_read_status(pbi);
517 dev_warn(pbi->
dev,
"%s(): out of range usb charger "
518 "charge detected\n", __func__);
539 static irqreturn_t pmic_battery_interrupt_handler(
int id,
void *
dev)
571 if (r8 & PMIC_BATT_CHR_SBATDET_MASK) {
591 if (r8 & PMIC_BATT_CHR_SCOMP_MASK) {
595 if (pmic_scu_ipc_battery_cc_read(&ccval)) {
597 "failed\n", __func__);
605 if (r8 & PMIC_BATT_CHR_SUSBDET_MASK) {
617 retval = langwell_udc_maxpower(&power);
620 "%s(): usb otg power query failed with error code %d\n",
632 if (pmic_battery_set_charger(pbi, chrg)) {
634 "%s(): failed to set up battery charging\n", __func__);
639 "pmic-battery: %s() - setting up battery charger successful\n",
657 dev_dbg(dev,
"pmic-battery: found pmic battery device\n");
661 dev_err(dev,
"%s(): memory allocation failed\n",
676 dev_err(dev,
"%s(): wqueue init failed\n", __func__);
685 dev_err(dev,
"%s(): cannot get IRQ\n", __func__);
686 goto requestirq_failed;
690 pbi->
batt.name =
"pmic-batt";
692 pbi->
batt.properties = pmic_battery_props;
694 pbi->
batt.get_property = pmic_battery_get_property;
698 "%s(): failed to register pmic battery device with power supply subsystem\n",
700 goto power_reg_failed;
703 dev_dbg(dev,
"pmic-battery: %s() - pmic battery device "
704 "registration with power supply subsystem successful\n",
710 pbi->
usb.name =
"pmic-usb";
712 pbi->
usb.properties = pmic_usb_props;
714 pbi->
usb.get_property = pmic_usb_get_property;
718 "%s(): failed to register pmic usb device with power supply subsystem\n",
720 goto power_reg_failed_1;
725 "registration with power supply subsystem successful\n",
744 return probe(pdev->
id, &pdev->
dev);
778 .probe = platform_pmic_battery_probe,
779 .remove =
__devexit_p(platform_pmic_battery_remove),