Merge "target: init: Fix battery detection for PMI632"
diff --git a/dev/pmic/pm8x41/include/pm8x41.h b/dev/pmic/pm8x41/include/pm8x41.h
index 0fc517b..e289623 100644
--- a/dev/pmic/pm8x41/include/pm8x41.h
+++ b/dev/pmic/pm8x41/include/pm8x41.h
@@ -232,6 +232,7 @@
uint8_t pm8x41_get_pon_reason();
uint8_t pm660_get_pon_reason();
uint8_t pm8950_get_pon_reason();
+uint8_t pmi632_get_pon_reason();
uint8_t pm8x41_get_pon_poff_reason1();
uint8_t pm8x41_get_pon_poff_reason2();
uint32_t pm8x41_get_pwrkey_is_pressed();
diff --git a/dev/pmic/pm8x41/include/pm8x41_hw.h b/dev/pmic/pm8x41/include/pm8x41_hw.h
index d213582..d719243 100644
--- a/dev/pmic/pm8x41/include/pm8x41_hw.h
+++ b/dev/pmic/pm8x41/include/pm8x41_hw.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2015, 2017, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012-2015, 2017-2018, The Linux Foundation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -109,6 +109,10 @@
#define USBIN_ACTIVE_PWR_SRC BIT(0)
#define DCIN_ACTIVE_PWR_SRC BIT(1)
+/* USB Status registers */
+#define SCHG_USB_INT_RT_STS 0x1310
+#define USBIN_PLUGIN_RT_STS BIT(4)
+
/* MPP registers */
#define MPP_DIG_VIN_CTL 0x41
#define MPP_MODE_CTL 0x40
diff --git a/dev/pmic/pm8x41/pm8x41.c b/dev/pmic/pm8x41/pm8x41.c
index 442bc35..ba723b4 100644
--- a/dev/pmic/pm8x41/pm8x41.c
+++ b/dev/pmic/pm8x41/pm8x41.c
@@ -637,6 +637,18 @@
return pon_reason;
}
+uint8_t pmi632_get_pon_reason()
+{
+ uint8_t pon_reason = 0;
+
+ pon_reason = REG_READ(SCHG_USB_INT_RT_STS|PMI8950_SLAVE_ID);
+ /* Check USBIN status on PMI and set the corresponding bits for pon */
+ pon_reason = (pon_reason & USBIN_PLUGIN_RT_STS);
+ pon_reason |= REG_READ(PON_PON_REASON1);
+
+ return pon_reason;
+}
+
uint8_t pm8x41_get_pon_poff_reason1()
{
return REG_READ(PON_POFF_REASON1);
diff --git a/target/init.c b/target/init.c
index b842eaf..e8189cc 100644
--- a/target/init.c
+++ b/target/init.c
@@ -435,7 +435,6 @@
}
break;
case PMIC_IS_PM660:
- case PMIC_IS_PMI632:
value = REG_READ(BAT_IF_INT_RT_STS);
/* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4)
are set, battery is not present. */
@@ -444,6 +443,15 @@
else
return true;
break;
+ case PMIC_IS_PMI632:
+ value = REG_READ(PMIC_SLAVE_ID|BAT_IF_INT_RT_STS);
+ /* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4)
+ are set, battery is not present. */
+ if (value & (BIT(5) | BIT(4)))
+ return false;
+ else
+ return true;
+ break;
default:
dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
break;