Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1544250 > unrolled thread

[PATCH 3/8] extcon: axp288: Simplify axp288_handle_chrg_det_event

Started byHans de Goede <hdegoede@redhat.com>
First post2016-12-19 01:20 +0100
Last post2016-12-19 07:20 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 3/8] extcon: axp288: Simplify axp288_handle_chrg_det_event Hans de Goede <hdegoede@redhat.com> - 2016-12-19 01:20 +0100
    Re: [PATCH 3/8] extcon: axp288: Simplify axp288_handle_chrg_det_event Chanwoo Choi <cw00.choi@samsung.com> - 2016-12-19 07:20 +0100

#1544250 — [PATCH 3/8] extcon: axp288: Simplify axp288_handle_chrg_det_event

FromHans de Goede <hdegoede@redhat.com>
Date2016-12-19 01:20 +0100
Subject[PATCH 3/8] extcon: axp288: Simplify axp288_handle_chrg_det_event
Message-ID<sPTQl-tj-11@gated-at.bofh.it>
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: Hans de Goede <hdegoede@redhat.com>
---
 drivers/extcon/extcon-axp288.c | 37 ++++++++++++-------------------------
 1 file changed, 12 insertions(+), 25 deletions(-)

diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
index 3d5e84e..43b3637 100644
--- a/drivers/extcon/extcon-axp288.c
+++ b/drivers/extcon/extcon-axp288.c
@@ -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 bool notify_otg, notify_charger;
 	static unsigned int cable;
 	int ret, stat, cfg, pwr_stat;
 	u8 chrg_type;
@@ -168,7 +167,7 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
 
 	vbus_attach = (pwr_stat & PS_STAT_VBUS_PRESENT);
 	if (!vbus_attach)
-		goto notify_otg;
+		goto no_vbus;
 
 	/* Check charger detection completion status */
 	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)
 	switch (chrg_type) {
 	case DET_STAT_SDP:
 		dev_dbg(info->dev, "sdp cable is connected\n");
-		notify_otg = true;
-		notify_charger = true;
 		cable = EXTCON_CHG_USB_SDP;
 		break;
 	case DET_STAT_CDP:
 		dev_dbg(info->dev, "cdp cable is connected\n");
-		notify_otg = true;
-		notify_charger = true;
 		cable = EXTCON_CHG_USB_CDP;
 		break;
 	case DET_STAT_DCP:
 		dev_dbg(info->dev, "dcp cable is connected\n");
-		notify_charger = true;
 		cable = EXTCON_CHG_USB_DCP;
 		break;
 	default:
@@ -208,24 +202,17 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
 			"disconnect or unknown or ID event\n");
 	}
 
-notify_otg:
-	if (notify_otg) {
-		/*
-		 * If VBUS is absent Connect D+/D- lines to PMIC for BC
-		 * detection. Else connect them to SOC for USB communication.
-		 */
-		if (info->gpio_mux_cntl)
-			gpiod_set_value(info->gpio_mux_cntl,
-				vbus_attach ? EXTCON_GPIO_MUX_SEL_SOC
-						: EXTCON_GPIO_MUX_SEL_PMIC);
-	}
-
-	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;
+no_vbus:
+	/*
+	 * If VBUS is absent Connect D+/D- lines to PMIC for BC
+	 * detection. Else connect them to SOC for USB communication.
+	 */
+	if (info->gpio_mux_cntl)
+		gpiod_set_value(info->gpio_mux_cntl,
+			vbus_attach ? EXTCON_GPIO_MUX_SEL_SOC
+					: EXTCON_GPIO_MUX_SEL_PMIC);
+
+	extcon_set_state_sync(info->edev, cable, vbus_attach);
 
 	return 0;
 
-- 
2.9.3

[toc] | [next] | [standalone]


#1544328

FromChanwoo Choi <cw00.choi@samsung.com>
Date2016-12-19 07:20 +0100
Message-ID<sPZsJ-46s-17@gated-at.bofh.it>
In reply to#1544250
Hi Hans,

On 2016년 12월 19일 09:13, Hans de Goede wrote:
> 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: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/extcon/extcon-axp288.c | 37 ++++++++++++-------------------------
>  1 file changed, 12 insertions(+), 25 deletions(-)

Looks good to me.
Acked-by: Chanwoo Choi <cw00.choi@samsung.com>

-- 
Regards,
Chanwoo Choi

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web