Commit 3fe1e0e2 authored by Hans de Goede's avatar Hans de Goede Committed by Chanwoo Choi

extcon: axp288: Simplify axp288_handle_chrg_det_event

axp288_handle_chrg_det_event only gets called on change interrupts
(so not that often), extcon_set_state_sync() checks itself if there are
any actual changes before notifying listeners, and gpiod_set_value is
not really expensive either.

So we can simply always do both on each interrupt removing a bunch of
somewhat magic looking code from axp288_handle_chrg_det_event.
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Acked-by: default avatarChanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: default avatarChanwoo Choi <cw00.choi@samsung.com>
parent 1490d157
...@@ -154,7 +154,6 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info) ...@@ -154,7 +154,6 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
{ {
static bool notify_otg, notify_charger;
static unsigned int cable; static unsigned int cable;
int ret, stat, cfg, pwr_stat; int ret, stat, cfg, pwr_stat;
u8 chrg_type; u8 chrg_type;
...@@ -168,7 +167,7 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) ...@@ -168,7 +167,7 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
vbus_attach = (pwr_stat & PS_STAT_VBUS_PRESENT); vbus_attach = (pwr_stat & PS_STAT_VBUS_PRESENT);
if (!vbus_attach) if (!vbus_attach)
goto notify_otg; goto no_vbus;
/* Check charger detection completion status */ /* Check charger detection completion status */
ret = regmap_read(info->regmap, AXP288_BC_GLOBAL_REG, &cfg); ret = regmap_read(info->regmap, AXP288_BC_GLOBAL_REG, &cfg);
...@@ -188,19 +187,14 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) ...@@ -188,19 +187,14 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
switch (chrg_type) { switch (chrg_type) {
case DET_STAT_SDP: case DET_STAT_SDP:
dev_dbg(info->dev, "sdp cable is connected\n"); dev_dbg(info->dev, "sdp cable is connected\n");
notify_otg = true;
notify_charger = true;
cable = EXTCON_CHG_USB_SDP; cable = EXTCON_CHG_USB_SDP;
break; break;
case DET_STAT_CDP: case DET_STAT_CDP:
dev_dbg(info->dev, "cdp cable is connected\n"); dev_dbg(info->dev, "cdp cable is connected\n");
notify_otg = true;
notify_charger = true;
cable = EXTCON_CHG_USB_CDP; cable = EXTCON_CHG_USB_CDP;
break; break;
case DET_STAT_DCP: case DET_STAT_DCP:
dev_dbg(info->dev, "dcp cable is connected\n"); dev_dbg(info->dev, "dcp cable is connected\n");
notify_charger = true;
cable = EXTCON_CHG_USB_DCP; cable = EXTCON_CHG_USB_DCP;
break; break;
default: default:
...@@ -208,24 +202,17 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) ...@@ -208,24 +202,17 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
"disconnect or unknown or ID event\n"); "disconnect or unknown or ID event\n");
} }
notify_otg: no_vbus:
if (notify_otg) { /*
/* * If VBUS is absent Connect D+/D- lines to PMIC for BC
* If VBUS is absent Connect D+/D- lines to PMIC for BC * detection. Else connect them to SOC for USB communication.
* detection. Else connect them to SOC for USB communication. */
*/ if (info->gpio_mux_cntl)
if (info->gpio_mux_cntl) gpiod_set_value(info->gpio_mux_cntl,
gpiod_set_value(info->gpio_mux_cntl, vbus_attach ? EXTCON_GPIO_MUX_SEL_SOC
vbus_attach ? EXTCON_GPIO_MUX_SEL_SOC : EXTCON_GPIO_MUX_SEL_PMIC);
: EXTCON_GPIO_MUX_SEL_PMIC);
} extcon_set_state_sync(info->edev, cable, vbus_attach);
if (notify_charger)
extcon_set_state_sync(info->edev, cable, vbus_attach);
/* Clear the flags on disconnect event */
if (!vbus_attach)
notify_otg = notify_charger = false;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment