Re: [PATCH 3/4] usb: add support to the PHY framework for HCD
From: Vivek Gautam
Date: Mon Jul 14 2014 - 05:08:15 EST
Hi,
CC: Sergei, Yoshihiro
On Wed, Jul 9, 2014 at 3:47 PM, Antoine TÃnart
<antoine.tenart@xxxxxxxxxxxxxxxxxx> wrote:
> This patch adds the support to PHY framework in HCD code while keeping
> the USB PHY compatibility. Changes are done in both the HCD common code
> and in the drivers accessing its PHY. This is done in two steps:
> renaming 'phy' into 'usb_phy' and adding a new 'phy' member into the
> usb_hcd structure.
>
> Signed-off-by: Antoine TÃnart <antoine.tenart@xxxxxxxxxxxxxxxxxx>
> ---
> drivers/usb/chipidea/host.c | 2 +-
> drivers/usb/core/hcd.c | 61 +++++++++++++++++++++++++++++++------------
> drivers/usb/core/hub.c | 8 +++---
> drivers/usb/host/ehci-fsl.c | 16 ++++++------
> drivers/usb/host/ehci-hub.c | 2 +-
> drivers/usb/host/ehci-msm.c | 4 +--
> drivers/usb/host/ehci-tegra.c | 16 ++++++------
> drivers/usb/host/ohci-omap.c | 20 +++++++-------
> include/linux/usb/hcd.h | 5 +++-
> 9 files changed, 82 insertions(+), 52 deletions(-)
>
> diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
> index a93d950e9468..fc7541c906a2 100644
> --- a/drivers/usb/chipidea/host.c
> +++ b/drivers/usb/chipidea/host.c
> @@ -59,7 +59,7 @@ static int host_start(struct ci_hdrc *ci)
> hcd->has_tt = 1;
>
> hcd->power_budget = ci->platdata->power_budget;
> - hcd->phy = ci->transceiver;
> + hcd->usb_phy = ci->transceiver;
>
> ehci = hcd_to_ehci(hcd);
> ehci->caps = ci->hw_bank.cap;
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index bec31e2efb88..b985af5b167c 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -42,6 +42,7 @@
> #include <linux/pm_runtime.h>
> #include <linux/types.h>
>
> +#include <linux/phy/phy.h>
> #include <linux/usb.h>
> #include <linux/usb/hcd.h>
> #include <linux/usb/phy.h>
> @@ -2631,21 +2632,35 @@ int usb_add_hcd(struct usb_hcd *hcd,
> int retval;
> struct usb_device *rhdev;
>
> - if (IS_ENABLED(CONFIG_USB_PHY) && !hcd->phy) {
> - struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller, 0);
> + if (IS_ENABLED(CONFIG_USB_PHY) && !hcd->phy && !hcd->usb_phy) {
> + struct phy *phy = of_phy_get(hcd->self.controller->of_node, 0);
>
> - if (IS_ERR(phy)) {
> - retval = PTR_ERR(phy);
> - if (retval == -EPROBE_DEFER)
> - return retval;
> - } else {
> - retval = usb_phy_init(phy);
> + if (!IS_ERR(phy)) {
> + retval = phy_init(hcd->phy);
> if (retval) {
> - usb_put_phy(phy);
> + phy_exit(hcd->phy);
> return retval;
> }
> + retval = phy_power_on(hcd->phy);
> hcd->phy = phy;
> hcd->remove_phy = 1;
> + } else {
> + struct usb_phy *phy =
> + usb_get_phy_dev(hcd->self.controller, 0);
> +
> + if (IS_ERR(phy)) {
> + retval = PTR_ERR(phy);
> + if (retval == -EPROBE_DEFER)
> + return retval;
> + } else {
> + retval = usb_phy_init(phy);
> + if (retval) {
> + usb_put_phy(phy);
> + return retval;
> + }
> + hcd->usb_phy = phy;
> + hcd->remove_phy = 1;
> + }
> }
> }
Just a note here:
There had already been a patch for adding the generic phy support in
usb/core/hcd.c in 3.16 cycle by
Sergei and Yoshihiro [1], though structurally a bit different, was not
picked since there wasn't any user of the patch
till then. Do you mind modifying on top of that patch
[1] https://www.mail-archive.com/linux-usb@xxxxxxxxxxxxxxx/msg43471.html
>
> @@ -2792,10 +2807,16 @@ err_allocate_root_hub:
> err_register_bus:
> hcd_buffer_destroy(hcd);
> err_remove_phy:
> - if (hcd->remove_phy && hcd->phy) {
> - usb_phy_shutdown(hcd->phy);
> - usb_put_phy(hcd->phy);
> - hcd->phy = NULL;
> + if (hcd->remove_phy) {
> + if (hcd->phy) {
> + phy_power_off(hcd->phy);
> + phy_exit(hcd->phy);
> + hcd->phy = NULL;
> + } else if (hcd->usb_phy) {
> + usb_phy_shutdown(hcd->usb_phy);
> + usb_put_phy(hcd->usb_phy);
> + hcd->usb_phy = NULL;
> + }
> }
> return retval;
> }
> @@ -2868,10 +2889,16 @@ void usb_remove_hcd(struct usb_hcd *hcd)
>
> usb_deregister_bus(&hcd->self);
> hcd_buffer_destroy(hcd);
> - if (hcd->remove_phy && hcd->phy) {
> - usb_phy_shutdown(hcd->phy);
> - usb_put_phy(hcd->phy);
> - hcd->phy = NULL;
> + if (hcd->remove_phy) {
> + if (hcd->phy) {
> + phy_power_off(hcd->phy);
> + phy_exit(hcd->phy);
> + hcd->phy = NULL;
> + } else if (hcd->usb_phy) {
> + usb_phy_shutdown(hcd->usb_phy);
> + usb_put_phy(hcd->usb_phy);
> + hcd->usb_phy = NULL;
> + }
> }
>
> usb_put_invalidate_rhdev(hcd);
[snip]
--
Best Regards
Vivek Gautam
Samsung R&D Institute, Bangalore
India
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/