Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1628223 > unrolled thread
| Started by | Hans de Goede <hdegoede@redhat.com> |
|---|---|
| First post | 2017-04-21 15:10 +0200 |
| Last post | 2017-04-21 21:00 +0200 |
| 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.
[PATCH 4/5] extcon: intel-cht-wc: Add new cht_wc_extcon_set_state helper Hans de Goede <hdegoede@redhat.com> - 2017-04-21 15:10 +0200
Re: [PATCH 4/5] extcon: intel-cht-wc: Add new cht_wc_extcon_set_state helper Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-04-21 21:00 +0200
| From | Hans de Goede <hdegoede@redhat.com> |
|---|---|
| Date | 2017-04-21 15:10 +0200 |
| Subject | [PATCH 4/5] extcon: intel-cht-wc: Add new cht_wc_extcon_set_state helper |
| Message-ID | <tyGtX-6d0-1@gated-at.bofh.it> |
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 <hdegoede@redhat.com>
---
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
[toc] | [next] | [standalone]
| From | Andy Shevchenko <andy.shevchenko@gmail.com> |
|---|---|
| Date | 2017-04-21 21:00 +0200 |
| Message-ID | <tyLWF-Sq-15@gated-at.bofh.it> |
| In reply to | #1628223 |
+Cc: Heikki.
It looks like you better Cc him with entire series.
On Fri, Apr 21, 2017 at 4:01 PM, Hans de Goede <hdegoede@redhat.com> wrote:
> 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 <hdegoede@redhat.com>
> ---
> 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
>
--
With Best Regards,
Andy Shevchenko
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web