rt946x: Fix MT6370 charger type detection
add bc12 workaround when bc12 detect SDP
BRANCH=kukui
TEST=boot kukui, slow plug in DCP, check bc12 detect chg type
@@ -1332,12 +1332,30 @@ static int mt6370_irq_handler(void)
}
#endif /* CONFIG_CHARGER_MT6370 */
+static void rt946x_bc12_workaround(void)
+{
+ /*
+ * There is a parasitic capacitance on D+,
+ * which results in pulling D+ up too slow while detecting BC1.2.
+ * So we try to fix this in two steps:
+ * 1. Pull D+ up to a voltage under 0.6V
+ * 2. re-toggling and pull D+ up to 0.6V (again)
+ * and then detect the voltage of D-.
+ */
+ rt946x_toggle_bc12_detection();
+ msleep(10);
+ rt946x_toggle_bc12_detection();
+}
+DECLARE_DEFERRED(rt946x_bc12_workaround);
+
void usb_charger_task(void *u)
{
struct charge_port_info chg;
int bc12_type = CHARGE_SUPPLIER_NONE;
int chg_type;
int reg = 0;
+ int bc12_cnt = 0;
+ const int max_bc12_cnt = 3;
chg.voltage = USB_CHARGER_VOLTAGE_MV;
while (1) {
@@ -1370,6 +1388,16 @@ void usb_charger_task(void *u)
p9221_notify_vbus_change(1);
CPRINTS("WPC ON");
}
+ if (bc12_type == CHARGE_SUPPLIER_BC12_SDP &&
+ ++bc12_cnt < max_bc12_cnt) {
+ /*
+ * defer the workaround and awaiting for
+ * waken up by the interrupt.
+ */
+ hook_call_deferred(
+ &rt946x_bc12_workaround_data, 5);
+ goto wait_event;
+ }
charge_manager_update_charge(bc12_type, 0, &chg);
bc12_none:
@@ -1380,6 +1408,7 @@ bc12_none:
/* VBUS detach event */
if (reg & RT946X_MASK_DPDMIRQ_DETACH) {
CPRINTS("VBUS detached");
+ bc12_cnt = 0;
#ifdef CONFIG_WIRELESS_CHARGER_P9221_R7
p9221_notify_vbus_change(0);
#endif
@@ -1391,6 +1420,7 @@ bc12_none:
hook_notify(HOOK_AC_CHANGE);
}
+wait_event:
task_wait_event(-1);
}
}
