From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1039548AbdDUNBk (ORCPT ); Fri, 21 Apr 2017 09:01:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47246 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1039518AbdDUNB1 (ORCPT ); Fri, 21 Apr 2017 09:01:27 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CC6FB9159A Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=hdegoede@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CC6FB9159A From: Hans de Goede To: MyungJoo Ham , Chanwoo Choi Cc: Hans de Goede , linux-kernel@vger.kernel.org Subject: [PATCH 4/5] extcon: intel-cht-wc: Add new cht_wc_extcon_set_state helper Date: Fri, 21 Apr 2017 15:01:18 +0200 Message-Id: <20170421130119.6187-4-hdegoede@redhat.com> In-Reply-To: <20170421130119.6187-1-hdegoede@redhat.com> References: <20170421130119.6187-1-hdegoede@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 21 Apr 2017 13:01:27 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This allows a nice cleanup of cht_wc_extcon_pwrsrc_event, getting rid of all the gotos in there. This also is a preparation patch for adding USB Type-C controller monitoring. Signed-off-by: Hans de Goede --- drivers/extcon/extcon-intel-cht-wc.c | 54 ++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/drivers/extcon/extcon-intel-cht-wc.c b/drivers/extcon/extcon-intel-cht-wc.c index 8806427e..684f6b2 100644 --- a/drivers/extcon/extcon-intel-cht-wc.c +++ b/drivers/extcon/extcon-intel-cht-wc.c @@ -196,20 +196,40 @@ static void cht_wc_extcon_set_5v_boost(struct cht_wc_extcon_data *ext, } /* Small helper to sync EXTCON_CHG_USB_SDP and EXTCON_USB state */ -static void cht_wc_extcon_set_state(struct cht_wc_extcon_data *ext, - unsigned int cable, bool state) +static void cht_wc_extcon_set_cable_state(struct cht_wc_extcon_data *ext, + unsigned int cable, bool state) { extcon_set_state_sync(ext->edev, cable, state); if (cable == EXTCON_CHG_USB_SDP) extcon_set_state_sync(ext->edev, EXTCON_USB, state); } +static void cht_wc_extcon_set_state(struct cht_wc_extcon_data *ext, + unsigned int new_cable) +{ + if (new_cable == EXTCON_NONE && !ext->usb_host) { + /* Route D+ and D- to PMIC for future charger detection */ + cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC); + } else { + /* Route D+ and D- to SoC for the host or gadget controller */ + cht_wc_extcon_set_phymux(ext, MUX_SEL_SOC); + } + + if (new_cable != ext->previous_cable) { + cht_wc_extcon_set_cable_state(ext, new_cable, true); + cht_wc_extcon_set_cable_state(ext, ext->previous_cable, false); + ext->previous_cable = new_cable; + } + + extcon_set_state_sync(ext->edev, EXTCON_USB_HOST, ext->usb_host); +} + static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext) { int ret, pwrsrc_sts, id; unsigned int cable = EXTCON_NONE; /* Ignore errors in host mode, as the 5v boost converter is on then */ - bool ignore_get_charger_errors = ext->usb_host; + bool ignore_get_charger_err = ext->usb_host; ret = regmap_read(ext->regmap, CHT_WC_PWRSRC_STS, &pwrsrc_sts); if (ret) { @@ -218,33 +238,13 @@ static void cht_wc_extcon_pwrsrc_event(struct cht_wc_extcon_data *ext) } id = cht_wc_extcon_get_id(ext, pwrsrc_sts); - if (id == USB_ID_GND) { - /* The 5v boost causes a false VBUS / SDP detect, skip */ - goto charger_det_done; - } - - /* Plugged into a host/charger or not connected? */ - if (!(pwrsrc_sts & CHT_WC_PWRSRC_VBUS)) { - /* Route D+ and D- to PMIC for future charger detection */ - cht_wc_extcon_set_phymux(ext, MUX_SEL_PMIC); - goto set_state; - } - - cable = cht_wc_extcon_get_charger(ext, ignore_get_charger_errors); -charger_det_done: - /* Route D+ and D- to SoC for the host or gadget controller */ - cht_wc_extcon_set_phymux(ext, MUX_SEL_SOC); - -set_state: - if (cable != ext->previous_cable) { - cht_wc_extcon_set_state(ext, cable, true); - cht_wc_extcon_set_state(ext, ext->previous_cable, false); - ext->previous_cable = cable; - } + /* When id == gnd the 5v boost causes a false VBUS detect */ + if (id != USB_ID_GND && (pwrsrc_sts & CHT_WC_PWRSRC_VBUS)) + cable = cht_wc_extcon_get_charger(ext, ignore_get_charger_err); ext->usb_host = ((id == USB_ID_GND) || (id == USB_RID_A)); - extcon_set_state_sync(ext->edev, EXTCON_USB_HOST, ext->usb_host); + cht_wc_extcon_set_state(ext, cable); } static irqreturn_t cht_wc_extcon_isr(int irq, void *data) -- 2.9.3