linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roger Quadros <rogerq@ti.com>
To: Chao Xie <chao.xie@marvell.com>
Cc: <stern@rowland.harvard.edu>, <balbi@ti.com>,
	<gregkh@linuxfoundation.org>, <linux-usb@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>, <xiechao.mail@gmail.com>
Subject: Re: [PATCH V2] USB: initialize or shutdown PHY when add or remove host controller
Date: Wed, 19 Jun 2013 10:51:21 +0300	[thread overview]
Message-ID: <51C162F9.9020705@ti.com> (raw)
In-Reply-To: <1371609080-30595-1-git-send-email-chao.xie@marvell.com>

Hi Chao,

On 06/19/2013 05:31 AM, Chao Xie wrote:
> Some controller need software to initialize PHY before add
> host controller, and shut down PHY after remove host controller.
> Add the generic code for these controllers so they do not need
> do it in its own host controller driver.
> 
> Signed-off-by: Chao Xie <chao.xie@marvell.com>
> ---
>  drivers/usb/core/hcd.c |   24 +++++++++++++++++++++++-
>  1 files changed, 23 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index d53547d..301c639 100644
> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -40,9 +40,11 @@
>  #include <linux/platform_device.h>
>  #include <linux/workqueue.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/err.h>
>  
>  #include <linux/usb.h>
>  #include <linux/usb/hcd.h>
> +#include <linux/usb/phy.h>
>  
>  #include "usb.h"
>  
> @@ -2531,12 +2533,26 @@ int usb_add_hcd(struct usb_hcd *hcd,
>  	 */
>  	set_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
>  
> +	/* In case hcd->phy contains the error code. */
> +	if (IS_ERR(hcd->phy))
> +		hcd->phy = NULL;
> +
> +	/* Initialize the PHY before other hardware operation. */
> +	if (hcd->phy) {
> +		retval = usb_phy_init(hcd->phy);
> +		if (retval) {
> +			dev_err(hcd->self.controller,
> +				"can't initialize phy\n");
> +			goto err_hcd_driver_setup;
> +		}
> +	}
> +
>  	/* "reset" is misnamed; its role is now one-time init. the controller
>  	 * should already have been reset (and boot firmware kicked off etc).
>  	 */
>  	if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) {
>  		dev_err(hcd->self.controller, "can't setup\n");
> -		goto err_hcd_driver_setup;
> +		goto err_hcd_driver_init_phy;
>  	}
>  	hcd->rh_pollable = 1;
>  
> @@ -2608,6 +2624,9 @@ err_hcd_driver_start:
>  	if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0)
>  		free_irq(irqnum, hcd);
>  err_request_irq:
> +err_hcd_driver_init_phy:
> +	if (hcd->phy)
> +		usb_phy_shutdown(hcd->phy);
>  err_hcd_driver_setup:
>  err_set_rh_speed:
>  	usb_put_dev(hcd->self.root_hub);
> @@ -2674,6 +2693,9 @@ void usb_remove_hcd(struct usb_hcd *hcd)
>  			free_irq(hcd->irq, hcd);
>  	}
>  
> +	if (hcd->phy)
> +		usb_phy_shutdown(hcd->phy);
> +
>  	usb_put_dev(hcd->self.root_hub);
>  	usb_deregister_bus(&hcd->self);
>  	hcd_buffer_destroy(hcd);
> 

I still think that we shouldn't do this because it adds more confusion and is not
still a generic enough solution.

1) It is better for the piece of code that does usb_phy_get() to do usb_phy_init/shutdown,
else there will be lot of confusion. (Felipe pointed this out earlier).

2) There is no standard way of getting phy for different controllers. It is mostly platform
dependent and it is best to leave this to the controller drivers. (Pointed out by Alan).

3) Controllers can have multiple PHYs. e.g. ehci-omap has one PHY per port and it supports
3 ports. This is also platform specific and difficult to handle generically.

4) Controllers can have specific timing requirements as to when the PHY is initialized relative
to the controller being initialized. I've pointed OMAP specific stuff in the earlier patch.

Considering all these points, I think we should leave things as they are. It isn't that hard
for controllers to manage phy_init() and phy_shutdown(), and there is not much code space saved
when compared to the complexity it creates if we move them to HCD layer.

cheers,
-roger

  parent reply	other threads:[~2013-06-19  7:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-19  2:31 [PATCH V2] USB: initialize or shutdown PHY when add or remove host controller Chao Xie
2013-06-19  2:48 ` Greg KH
2013-06-19  3:23   ` Chao Xie
2013-06-19  7:51 ` Roger Quadros [this message]
2013-06-20  0:53   ` Chao Xie
2013-06-20 12:17     ` Felipe Balbi
2013-06-20 17:25       ` Alan Stern
2013-06-21  1:07         ` Chao Xie
2013-06-21  1:27           ` Chao Xie
2013-06-24 19:45           ` Felipe Balbi
2013-06-25  1:25             ` Chao Xie
2013-06-25  3:33               ` Felipe Balbi
2013-06-24 19:36         ` Felipe Balbi
2013-06-25 13:37           ` Roger Quadros
2013-06-25 13:43             ` Felipe Balbi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51C162F9.9020705@ti.com \
    --to=rogerq@ti.com \
    --cc=balbi@ti.com \
    --cc=chao.xie@marvell.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=xiechao.mail@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).