All of lore.kernel.org
 help / color / mirror / Atom feed
From: marex@denx.de (Marek Vasut)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 09/11] MXS: Add USB PHY driver
Date: Mon, 23 Apr 2012 04:17:12 +0200	[thread overview]
Message-ID: <201204230417.13182.marex@denx.de> (raw)
In-Reply-To: <F281D0F91ED19E4D8E63A7504E8A649803B793D9@039-SN2MPN1-023.039d.mgd.msft.net>

Dear Chen Peter-B29397,

> > +
> > +#define HW_USBPHY_PWD				0x00
> > +
> > +#define HW_USBPHY_CTRL				0x30
> > +#define HW_USBPHY_CTRL_SET			0x34
> > +#define HW_USBPHY_CTRL_CLR			0x38
> > +#define HW_USBPHY_CTRL_TOG			0x3c
> > +
> > +#define BM_USBPHY_CTRL_SFTRST			(1 << 31)
> > +#define BM_USBPHY_CTRL_CLKGATE			(1 << 30)
> > +#define BM_USBPHY_CTRL_ENUTMILEVEL3		(1 << 15)
> > +#define BM_USBPHY_CTRL_ENUTMILEVEL2		(1 << 14)
> > +#define BM_USBPHY_CTRL_ENIRQDEVPLUGIN		(1 << 11)
> > +#define BM_USBPHY_CTRL_ENOTGIDDETECT		(1 << 7)
> > +#define BM_USBPHY_CTRL_ENDEVPLUGINDETECT	(1 << 4)
> > +#define BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ	(1 << 3)
> > +#define BM_USBPHY_CTRL_ENHOSTDISCONDETECT	(1 << 1)
> > +
> > +#define HW_USBPHY_STATUS			0x40
> > +
> > +#define BM_USBPHY_STATUS_OTGID_STATUS		(1 << 8)
> > +#define BM_USBPHY_STATUS_DEVPLUGIN_STATUS	(1 << 6)
> > +#define BM_USBPHY_STATUS_HOSTDISCON_STATUS	(1 << 3)
> > +
> > +/* FIXME */
> > +#define M28EVK_USBOTG_ENABLE	MXS_GPIO_NR(3, 12)
> > +
> 
> This is platform code, should not put at driver.
> 
> > +struct mxs_usb_phy {
> > +	struct usb_phy		phy;
> > +
> > +	struct work_struct	work;
> > +
> > +	struct clk		*clk;
> > +	struct resource		*mem_res;
> > +	void __iomem		*mem;
> > +	int			irq;
> > +	int			gpio_vbus;
> > +	int			gpio_vbus_inverted;
> > +
> > +	enum usb_otg_state	new_state;
> > +
> > +	bool			host_mode;
> > +};
> > +
> > +static int mxs_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
> 
> should be at imx-otg.c

I don't understand why. This is clearly specific to this PHY driver.

> 
> > +
> > +static int mxs_usb_set_peripheral(struct usb_otg *otg, struct usb_gadget
> > *gg)
> 
> gg may not a good name, how about just gadget?
> should be at imx-otg.c

DTTO

> > +static void mxs_usb_work(struct work_struct *w)
> 
> It is OTG switch routine, and should be put imx-otg.c. Sascha also
> suggested before.

Fine by me, but until someone can clearly explain to me why PHY specific code 
should be in a shared file (even if it's completely unrelated to it), I see no 
point moving this.

> > +{
> > +	struct mxs_usb_phy *phy = container_of(w, struct mxs_usb_phy, work);
> > +	struct usb_otg *otg = phy->phy.otg;
> > +	struct usb_hcd *hcd;
> > +
> > +	switch (otg->phy->state) {
> > +	case OTG_STATE_A_HOST:
> > +		if (phy->new_state == OTG_STATE_UNDEFINED) {
> > +			hcd = bus_to_hcd(otg->host);
> > +			usb_remove_hcd(hcd);
> > +			otg->phy->state = phy->new_state;
> > +			/* Turn off VBUS */
> > +			gpio_set_value(phy->gpio_vbus,
> > +				phy->gpio_vbus_inverted);
> > +		}
> > +		break;
> > +	case OTG_STATE_B_PERIPHERAL:
> > +		if (phy->new_state == OTG_STATE_UNDEFINED) {
> > +			usb_del_gadget_udc(otg->gadget);
> > +			otg->phy->state = phy->new_state;
> > +		}
> > +		break;
> > +	case OTG_STATE_UNDEFINED:
> > +		/* Check desired state. */
> > +		switch (phy->new_state) {
> > +		case OTG_STATE_A_HOST:
> > +			if (!otg->host)
> > +				break;
> > +			otg->phy->state = phy->new_state;
> > +
> > +			/* Turn on VBUS */
> > +			gpio_set_value(phy->gpio_vbus,
> > +				!phy->gpio_vbus_inverted);
> > +
> > +			hcd = bus_to_hcd(otg->host);
> > +			usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
> > +			break;
> > +		case OTG_STATE_B_PERIPHERAL:
> > +			if (!otg->gadget)
> > +				break;
> > +			otg->phy->state = phy->new_state;
> > +			usb_add_gadget_udc(phy->phy.dev, otg->gadget);
> > +			break;
> > +		default:
> > +			break;
> > +		}
> > +		break;
> > +
> > +	default:
> > +		break;
> > +	}
> > +}
> > +
> 
> Seems you forget one otg state: OTG_STATE_B_IDLE.
> 
> at device mode:
> OTG_STATE_UNDEFINED -> OTG_STATE_B_IDLE (nothing on port)
> OTG_STATE_B_PERIPHERAL -> OTG_STATE_B_IDLE (disconnect with host)

This OTG biz really needs further work. So far, we only support Host/Device.

> 
> > +static int mxs_usb_phy_init(struct usb_phy *x)
> > +{
> > +	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
> > +	uint32_t val;
> > +
> > +	/* Enable clock to the PHY. */
> > +	clk_enable(phy->clk);
> > +
> > +	/* Reset the PHY block. */
> > +	mxs_reset_block(phy->mem + HW_USBPHY_CTRL);
> > +
> > +	/* Power up the PHY. */
> > +	writel(0, phy->mem + HW_USBPHY_PWD);
> > +
> > +	/* Enable FS/LS compatibility. */
> > +	val = BM_USBPHY_CTRL_ENUTMILEVEL2 | BM_USBPHY_CTRL_ENUTMILEVEL3;
> > +
> > +	if (phy->host_mode)
> > +		val |= BM_USBPHY_CTRL_ENHOSTDISCONDETECT;
> > +	else
> > +		val |= BM_USBPHY_CTRL_ENIRQDEVPLUGIN |
> > +			BM_USBPHY_CTRL_ENOTGIDDETECT |
> > +			BM_USBPHY_CTRL_ENDEVPLUGINDETECT;
> 
> Please explain the meaning of above code?
> 
> > +static void mxs_usb_phy_shutdown(struct usb_phy *x)
> > +{
> > +	struct mxs_usb_phy *phy = container_of(x, struct mxs_usb_phy, phy);
> > +
> 
> You need to set portsc.phcd=1 and power down phy using set 0xffffffff to
> HW_USBPHY_PWD.
> 
> > +	/* Gate off the PHY. */
> > +	writel(BM_USBPHY_CTRL_CLKGATE, phy->mem + HW_USBPHY_CTRL_SET);
> > +
> > +	/* Disable clock to the PHY. */
> > +	clk_disable(phy->clk);
> > +}
> > +
> > +static irqreturn_t mxs_phy_irq(int irq, void *data)
> > +{
> > +	struct mxs_usb_phy *phy = data;
> > +	uint32_t status = readl(phy->mem + HW_USBPHY_STATUS);
> > +
> > +	if (status & BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ)
> > +		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
> > +			phy->mem + HW_USBPHY_CTRL_CLR);
> > +	else
> > +		writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
> > +			phy->mem + HW_USBPHY_CTRL_SET);
> > +
> 
> Have you tested several connect/disconnect operation with high speed
> device? - where you clear BM_USBPHY_CTRL_HOSTDISCONDETECT_IRQ?
> - This code will always run at every usb interrupt, in fact, high speed
> detector only needs to be set/clear with connect/disconnect.

I have yet to figure out how to actually detect host connect/disconnect in OTG 
mode while also detect Device connect/disconnect. Can you elaborate on what 
needs to be set in the CTRL register to generate these interrupts?

> > +	return IRQ_NONE;
> > +}
> > +
> > 
> > 
> > +
> > +static int __devexit mxs_phy_remove(struct platform_device *pdev)
> > +{
> > +	struct mxs_usb_phy *phy = platform_get_drvdata(pdev);
> > +
> > +	/* Stop the PHY work. */
> > +	cancel_work_sync(&phy->work);
> > +
> > +	/* Power down the PHY. */
> > +	mxs_usb_phy_shutdown(&phy->phy);
> > +
> > +	/* Remove the transceiver. */
> > +	usb_set_transceiver(NULL);
> > +
> > +	/* Shut off VBUS. */
> > +	gpio_set_value(phy->gpio_vbus, phy->gpio_vbus_inverted);
> > +	gpio_free(phy->gpio_vbus);
> > +
> > +	/* Free the IRQ requested by this device. */
> > +	free_irq(phy->irq, phy);
> > +
> > +	/* Free the IRQ requested by this device. */
> > +	free_irq(phy->irq, phy);
> > +
> 
> Two free_irq???

Rebase issue

> 
> > +	/* Stop the PHY clock. */
> > +	clk_disable_unprepare(phy->clk);
> > +	clk_put(phy->clk);
> > +
> > +	/* Free the rest. */
> > +	platform_set_drvdata(pdev, NULL);
> > +
> > +	return 0;
> > +}
> > +

  reply	other threads:[~2012-04-23  2:17 UTC|newest]

Thread overview: 151+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-17 10:15 [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Marek Vasut
2012-04-17 10:15 ` [PATCH 1/8] MXS: Make clk_disable return integer Marek Vasut
2012-04-17 10:15 ` [PATCH 2/8] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
2012-04-17 18:01   ` Sascha Hauer
2012-04-17 10:15 ` [PATCH 3/8] MXS: Fixup i.MX233 USB base address name Marek Vasut
2012-04-17 10:15 ` [PATCH 4/8] MXS: Add platform registration hooks for USB EHCI Marek Vasut
2012-04-17 10:15 ` [PATCH 5/8] MXS: Add USB PHY driver Marek Vasut
2012-04-17 17:51   ` Sascha Hauer
2012-04-19 11:40   ` Arnd Bergmann
2012-04-17 10:15 ` [PATCH 6/8] MXS: Add separate MXS EHCI HCD driver Marek Vasut
2012-04-17 10:15 ` [PATCH 7/8] MXS: Enable USB on M28EVK Marek Vasut
2012-04-17 17:40   ` Sergei Shtylyov
2012-04-17 10:15 ` [PATCH 8/8] MXS: Enable USB on MX28EVK Marek Vasut
2012-04-17 10:37 ` [RFC PATCH 0/8] MXS: Add i.MX28 USB Host driver Dirk Behme
2012-04-17 11:24   ` Marek Vasut
2012-04-18  1:00     ` Chen Peter-B29397
2012-04-17 11:29 ` Sascha Hauer
2012-04-17 11:45   ` Marek Vasut
2012-04-17 12:18     ` Sascha Hauer
2012-04-17 20:29       ` Marek Vasut
2012-04-18  7:02         ` Sascha Hauer
2012-04-18  8:05           ` Chen Peter-B29397
2012-04-17 12:36   ` Heikki Krogerus
2012-04-18  4:31   ` Chen Peter-B29397
2012-04-18  7:40     ` Sascha Hauer
2012-04-20 13:10       ` 答复: " Liu JunJie-B08287
2012-04-20 16:25         ` Marek Vasut
2012-04-23  2:02           ` Liu JunJie-B08287
2012-04-18  2:07 ` [RFC PATCH 00/10 V2] " Marek Vasut
2012-04-18  2:07   ` [PATCH 01/10] MXS: Make clk_disable return integer Marek Vasut
2012-04-18  2:07   ` [PATCH 02/10] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
2012-04-18  2:07   ` [PATCH 03/10] MXS: Fixup i.MX233 USB base address name Marek Vasut
2012-04-18  2:07   ` [PATCH 04/10] MXS: Add data shared between imx-usb, PHY and EHCI driver Marek Vasut
2012-04-18  2:07   ` [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI Marek Vasut
2012-04-18  2:07   ` [PATCH 06/10] MXS: Add composite imx-usb driver Marek Vasut
2012-04-18  2:07   ` [PATCH 07/10] MXS: Add USB PHY driver Marek Vasut
2012-04-18  2:07   ` [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver Marek Vasut
2012-04-18  7:01     ` Chen Peter-B29397
2012-04-18  8:40       ` Sascha Hauer
2012-04-18  9:18         ` Chen Peter-B29397
2012-04-18  9:45           ` Sascha Hauer
2012-04-19  2:54             ` Chen Peter-B29397
2012-04-19  6:34               ` Sascha Hauer
2012-04-18  2:07   ` [PATCH 09/10] MXS: Enable USB on M28EVK Marek Vasut
2012-04-18 12:08     ` Sergei Shtylyov
2012-04-18 12:24       ` Marek Vasut
2012-04-18  2:07   ` [PATCH 10/10] MXS: Enable USB on MX28EVK Marek Vasut
2012-04-18  2:09   ` [RFC PATCH 00/10 V2] MXS: Add i.MX28 USB Host driver Marek Vasut
2012-04-18  7:52   ` Chen Peter-B29397
2012-04-18 17:49     ` Marek Vasut
2012-04-19  2:37       ` Chen Peter-B29397
2012-04-18 17:46   ` [RFC PATCH 00/10 V3] " Marek Vasut
2012-04-18 17:46     ` [PATCH 01/10] MXS: Make clk_disable return integer Marek Vasut
2012-04-18 17:46     ` [PATCH 02/10] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
2012-04-18 17:46     ` [PATCH 03/10] MXS: Fixup i.MX233 USB base address name Marek Vasut
2012-04-18 17:46     ` [PATCH 04/10] MXS: Add data shared between imx-usb and EHCI driver Marek Vasut
2012-04-18 17:46     ` [PATCH 05/10] MXS: Add platform registration hooks for USB EHCI Marek Vasut
2012-04-19 11:51       ` Arnd Bergmann
2012-04-19 14:24         ` Shawn Guo
2012-04-19 21:32           ` Marek Vasut
2012-04-20  0:40             ` Shawn Guo
2012-04-20  0:56               ` Marek Vasut
2012-04-20  1:34                 ` Shawn Guo
2012-04-20  1:40                   ` Marek Vasut
2012-04-18 17:46     ` [PATCH 06/10] MXS: Add imx-usb driver Marek Vasut
2012-04-18 17:46     ` [PATCH 07/10] MXS: Add USB PHY driver Marek Vasut
2012-04-18 19:36       ` Sascha Hauer
2012-04-18 20:02         ` Marek Vasut
2012-04-18 20:16           ` Sascha Hauer
2012-04-19 22:06             ` Marek Vasut
2012-04-20  2:35               ` Chen Peter-B29397
2012-04-18 17:46     ` [PATCH 08/10] MXS: Add separate MXS EHCI HCD driver Marek Vasut
2012-04-18 19:50       ` Sascha Hauer
2012-04-18 20:07         ` Marek Vasut
2012-04-18 20:43           ` Sascha Hauer
2012-04-18 17:46     ` [PATCH 09/10] MXS: Enable USB on M28EVK Marek Vasut
2012-04-18 17:46     ` [PATCH 10/10] MXS: Enable USB on MX28EVK Marek Vasut
2012-04-20  2:13     ` [RFC PATCH 00/10 V3] MXS: Add i.MX28 USB Host driver Marek Vasut
2012-04-20  9:48       ` Sascha Hauer
2012-04-20 12:26         ` Peter Chen
2012-04-20 12:44           ` Marek Vasut
2012-04-20 13:00             ` Robert Schwebel
2012-04-20 13:26             ` Sascha Hauer
2012-04-20 16:36               ` Michael Grzeschik
2012-04-21  7:42                 ` Peter Chen
2012-04-21  8:17                   ` Sascha Hauer
2012-04-21 13:53     ` Subodh Nijsure
2012-04-21 15:37       ` Marek Vasut
2012-04-22 12:59     ` [RFC PATCH 00/11 V4] " Marek Vasut
2012-04-22 12:59       ` [PATCH 01/11] MXS: Make clk_disable return integer Marek Vasut
2012-04-22 12:59       ` [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
2012-04-22 14:42         ` Shawn Guo
2012-04-22 15:42           ` Marek Vasut
2012-04-22 16:34             ` Shawn Guo
2012-04-22 12:59       ` [PATCH 03/11] MXS: Fixup i.MX233 USB base address name Marek Vasut
2012-04-22 12:59       ` [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
2012-04-22 14:39         ` Shawn Guo
2012-04-22 15:42           ` Marek Vasut
2012-04-22 16:38             ` Shawn Guo
2012-04-22 12:59       ` [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC Marek Vasut
2012-04-22 12:59       ` [PATCH 06/11] MXS: Add small registration glue for ci13xxx_udc Marek Vasut
2012-04-23  1:46         ` Chen Peter-B29397
2012-04-22 12:59       ` [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver Marek Vasut
2012-04-23  1:44         ` Chen Peter-B29397
2012-04-23  2:11           ` Marek Vasut
2012-04-22 12:59       ` [PATCH 08/11] MXS: Add imx-otg driver Marek Vasut
2012-04-23  6:39         ` Sascha Hauer
2012-04-23  9:38           ` Marek Vasut
2012-04-22 12:59       ` [PATCH 09/11] MXS: Add USB PHY driver Marek Vasut
2012-04-23  1:42         ` Chen Peter-B29397
2012-04-23  2:17           ` Marek Vasut [this message]
2012-04-23 12:20             ` Chen Peter-B29397
2012-04-22 12:59       ` [PATCH 10/11] MXS: Add platform registration hooks for USB EHCI Marek Vasut
2012-04-22 12:59       ` [PATCH 11/11] MXS: Enable USB on M28EVK Marek Vasut
2012-04-23  1:57         ` Chen Peter-B29397
2012-04-23  2:18           ` Marek Vasut
2012-04-23  2:01       ` [RFC PATCH 00/11 V4] MXS: Add i.MX28 USB Host driver Chen Peter-B29397
2012-04-23  2:18         ` Marek Vasut
2012-04-23 11:59           ` Chen Peter-B29397
2012-04-23 12:09             ` Marek Vasut
2012-04-23 12:25               ` Chen Peter-B29397
2012-04-23 12:40                 ` Marek Vasut
2012-04-23  2:37         ` Marek Vasut
2012-04-24  3:18       ` [RFC PATCH 00/11 V5] " Marek Vasut
2012-04-24  3:18         ` [PATCH 01/11] MXS: Make clk_disable return integer Marek Vasut
2012-04-24  3:18         ` [PATCH 02/11] MXS: Add USB EHCI and USB PHY clock handling Marek Vasut
2012-04-24  3:18         ` [PATCH 03/11] MXS: Fixup i.MX233 USB base address name Marek Vasut
2012-04-24  3:18         ` [PATCH 04/11] MXS: Add data shared between imx-otg and EHCI driver Marek Vasut
2012-04-24  3:18         ` [PATCH 05/11] MXS: Modify the ci13xxx_udc to avoid adding UDC Marek Vasut
2012-04-29  8:26           ` Chen Peter-B29397
2012-04-24  3:18         ` [PATCH 06/11] MXS: Add small registration glue for ci13xxx_udc Marek Vasut
2012-04-24  3:18         ` [PATCH 07/11] MXS: Add separate MXS EHCI HCD driver Marek Vasut
2012-04-29  8:28           ` Chen Peter-B29397
2012-04-24  3:18         ` [PATCH 08/11] MXS: Add imx-otg driver Marek Vasut
2012-04-24 14:48           ` Lothar Waßmann
2012-04-24 14:50             ` Sascha Hauer
2012-04-24 16:13               ` Lothar Waßmann
2012-04-24 16:47                 ` Sascha Hauer
2012-04-24 17:49                   ` Marek Vasut
2012-04-24 20:49                     ` Sascha Hauer
2012-04-24 20:58                       ` Marek Vasut
2012-04-25  0:17                         ` Chen Peter-B29397
2012-04-24  3:18         ` [PATCH 09/11] MXS: Add USB PHY driver Marek Vasut
2012-04-24  3:18         ` [PATCH 10/11] MXS: Add platform registration hooks for USB EHCI Marek Vasut
2012-04-24  3:18         ` [PATCH 11/11] MXS: Enable USB on M28EVK Marek Vasut
2012-04-24 20:02         ` [RFC PATCH 00/11 V5] MXS: Add i.MX28 USB Host driver Russell King - ARM Linux
2012-04-25 12:27           ` Marek Vasut
2012-04-25 12:41             ` Russell King - ARM Linux
2012-04-25 12:43               ` Marek Vasut
  -- strict thread matches above, loose matches on Subject: below --
2012-04-29 22:34 [RFC PATCH 00/11 V6] " Marek Vasut
2012-04-29 22:34 ` [PATCH 09/11] MXS: Add USB PHY driver Marek Vasut
2012-05-01  1:55 [RFC PATCH 00/11 V7] MXS: Add i.MX28 USB Host driver Marek Vasut
2012-05-01  1:56 ` [PATCH 09/11] MXS: Add USB PHY driver Marek Vasut

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=201204230417.13182.marex@denx.de \
    --to=marex@denx.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.