2019-10-10 13:58:35

by Igor Opaniuk

[permalink] [raw]
Subject: [PATCH v2 1/3] usb: phy: add usb mode for usb_phy

From: Li Jun <[email protected]>

USB phy driver may need to know the current working mode of
the controller, and can provide different settings according to
host mode or device mode.

Signed-off-by: Li Jun <[email protected]>
Signed-off-by: Igor Opaniuk <[email protected]>
---

v2:
- restored original commit author
- fixed build for multi_v7

include/linux/usb/phy.h | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index e4de6bc1f69b..d138703e3688 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -63,6 +63,13 @@ enum usb_otg_state {
OTG_STATE_A_VBUS_ERR,
};

+/* The usb role of phy to be working with */
+enum usb_current_mode {
+ USB_CURRENT_MODE_NONE,
+ USB_CURRENT_MODE_HOST,
+ USB_CURRENT_MODE_DEVICE,
+};
+
struct usb_phy;
struct usb_otg;

@@ -155,6 +162,13 @@ struct usb_phy {
* manually detect the charger type.
*/
enum usb_charger_type (*charger_detect)(struct usb_phy *x);
+
+ /*
+ * Set current working mode of the USB controller
+ * (device, host)
+ */
+ int (*set_mode)(struct usb_phy *x,
+ enum usb_current_mode mode);
};

/* for board-specific init logic */
@@ -213,6 +227,15 @@ usb_phy_vbus_off(struct usb_phy *x)
return x->set_vbus(x, false);
}

+static inline int
+usb_phy_set_mode(struct usb_phy *x, enum usb_current_mode mode)
+{
+ if (!x || !x->set_mode)
+ return 0;
+
+ return x->set_mode(x, mode);
+}
+
/* for usb host and peripheral controller drivers */
#if IS_ENABLED(CONFIG_USB_PHY)
extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
--
2.17.1


2019-10-10 13:59:47

by Igor Opaniuk

[permalink] [raw]
Subject: [PATCH v2 2/3] usb: chipidea: set mode for usb phy driver

From: Li Jun <[email protected]>

After enters one specific role, notify usb phy driver.

Signed-off-by: Li Jun <[email protected]>
Signed-off-by: Igor Opaniuk <[email protected]>
---

v2:
- restored original commit author
- fixed build for multi_v7

drivers/usb/chipidea/ci.h | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index 6911aef500e9..cf9cc9402826 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -275,9 +275,21 @@ static inline int ci_role_start(struct ci_hdrc *ci, enum ci_role role)
return -ENXIO;

ret = ci->roles[role]->start(ci);
- if (!ret)
- ci->role = role;
- return ret;
+ if (ret)
+ return ret;
+
+ ci->role = role;
+
+ if (ci->usb_phy) {
+ if (role == CI_ROLE_HOST)
+ usb_phy_set_mode(ci->usb_phy,
+ USB_CURRENT_MODE_HOST);
+ else
+ usb_phy_set_mode(ci->usb_phy,
+ USB_CURRENT_MODE_DEVICE);
+ }
+
+ return 0;
}

static inline void ci_role_stop(struct ci_hdrc *ci)
@@ -290,6 +302,9 @@ static inline void ci_role_stop(struct ci_hdrc *ci)
ci->role = CI_ROLE_END;

ci->roles[role]->stop(ci);
+
+ if (ci->usb_phy)
+ usb_phy_set_mode(ci->usb_phy, USB_CURRENT_MODE_NONE);
}

static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci)
--
2.17.1

2019-10-11 05:51:28

by Peter Chen

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] usb: chipidea: set mode for usb phy driver

On 19-10-10 16:56:55, Igor Opaniuk wrote:
> From: Li Jun <[email protected]>
>
> After enters one specific role, notify usb phy driver.
>
> Signed-off-by: Li Jun <[email protected]>
> Signed-off-by: Igor Opaniuk <[email protected]>
> ---
>
> v2:
> - restored original commit author
> - fixed build for multi_v7
>
> drivers/usb/chipidea/ci.h | 21 ++++++++++++++++++---
> 1 file changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
> index 6911aef500e9..cf9cc9402826 100644
> --- a/drivers/usb/chipidea/ci.h
> +++ b/drivers/usb/chipidea/ci.h
> @@ -275,9 +275,21 @@ static inline int ci_role_start(struct ci_hdrc *ci, enum ci_role role)
> return -ENXIO;
>
> ret = ci->roles[role]->start(ci);
> - if (!ret)
> - ci->role = role;
> - return ret;
> + if (ret)
> + return ret;
> +
> + ci->role = role;
> +
> + if (ci->usb_phy) {
> + if (role == CI_ROLE_HOST)
> + usb_phy_set_mode(ci->usb_phy,
> + USB_CURRENT_MODE_HOST);
> + else
> + usb_phy_set_mode(ci->usb_phy,
> + USB_CURRENT_MODE_DEVICE);
> + }
> +
> + return 0;
> }
>
> static inline void ci_role_stop(struct ci_hdrc *ci)
> @@ -290,6 +302,9 @@ static inline void ci_role_stop(struct ci_hdrc *ci)
> ci->role = CI_ROLE_END;
>
> ci->roles[role]->stop(ci);
> +
> + if (ci->usb_phy)
> + usb_phy_set_mode(ci->usb_phy, USB_CURRENT_MODE_NONE);
> }
>
> static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci)
> --

For chipidea part:

Acked-by: Peter Chen <[email protected]>

--

Thanks,
Peter Chen