Add MSM USB Device Controller support
Subsystems (2)
PATCH v2 1/1 Add MSM USB Device Controller support
This patch series adds basic support for USB device controller found in MSM family of SOCs. This driver is already being used in Android devices. This driver is tested with Android(ADB + Mass storage, RNDIS), ethernet, and file storage gadgets. All the USBCV Ch9 Tests and usbtest test cases are passed. Tested against v2.6.37-rc1
This driver is originally authored by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git
Changelog:
V1-->V2
1. Data structure comments are annotated as per kernel-doc
2. Replaced custom macros with dev_info/dev_err/dev_dbg
3. Implemented set_wedge method
4. Implemented "vbus" debugfs file to simulate cable connect and disconnect
5. Fixed a bug in remote wakeup support where remote wakeup condition is not cleared upon reset
Pavankumar Kondeti (5):
USB: Add MSM USB Device Controller driver
USB: msm72k_udc: Add debugfs support
USB: msm72k_udc: Add Remote wakeup support
USB: msm72k_udc: Add Test Mode support
USB: msm72k_udc: Add charging notification support
drivers/usb/gadget/Kconfig | 17 + drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/gadget_chips.h | 8 + drivers/usb/gadget/msm72k_udc.c | 1978 +++++++++++++++++++++++++++++++++++++ include/linux/usb/msm_hsusb.h | 54 + include/linux/usb/msm_hsusb_hw.h | 198 ++++ 6 files changed, 2256 insertions(+), 0 deletions(-) create mode 100644 drivers/usb/gadget/msm72k_udc.c create mode 100644 include/linux/usb/msm_hsusb.h create mode 100644 include/linux/usb/msm_hsusb_hw.h
PATCH v2 1/1 USB: Add MSM USB Device Controller driver
This patch adds the basic support for the USB Device Controller on Qualcomm MSM family of SOCs. The controller supports upto 16 endpoints including the default endpoint (ep0). All the data transfers are driven by DMA.
VBUS line is also connected to PMIC chip. The module controlling PMIC chip notifies about cable connect/disconnect events. Hence, PHY comparators are turned off in low power mode.
This driver was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.
--- drivers/usb/gadget/Kconfig | 17 + drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/gadget_chips.h | 8 + drivers/usb/gadget/msm72k_udc.c | 1685 +++++++++++++++++++++++++++++++++++++ include/linux/usb/msm_hsusb.h | 38 + include/linux/usb/msm_hsusb_hw.h | 184 ++++ 6 files changed, 1933 insertions(+), 0 deletions(-) create mode 100644 drivers/usb/gadget/msm72k_udc.c create mode 100644 include/linux/usb/msm_hsusb.h create mode 100644 include/linux/usb/msm_hsusb_hw.h
drivers/usb/gadget/Kconfig +17 -0
@@ -495,6 +495,23 @@ config USB_LANGWELL default USB_GADGET select USB_GADGET_SELECTED +config USB_GADGET_MSM_72K + boolean "MSM 72K Device Controller" + depends on ARCH_MSM + select USB_GADGET_SELECTED + select USB_GADGET_DUALSPEED + help + USB gadget driver for Qualcomm MSM 72K architecture. + + Say "y" to link the driver statically, or "m" to build a + dynamically linked module called "msm72k" and force all + gadget drivers to also be dynamically linked. + +config USB_MSM_72K + tristate + depends on USB_GADGET_MSM_72K + default USB_GADGET + select USB_GADGET_SELECTED # # LAST -- dummy/emulated controller
drivers/usb/gadget/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_USB_FSL_QE) += fsl_qe_udc.o obj-$(CONFIG_USB_CI13XXX) += ci13xxx_udc.o obj-$(CONFIG_USB_S3C_HSOTG) += s3c-hsotg.o obj-$(CONFIG_USB_LANGWELL) += langwell_udc.o +obj-$(CONFIG_USB_MSM_72K) += msm72k_udc.o # # USB gadget drivers
drivers/usb/gadget/gadget_chips.h +8 -0
@@ -142,6 +142,12 @@#define gadget_is_s3c_hsotg (g) 0#endif +#ifdef CONFIG_USB_GADGET_MSM_72K +#define gadget_is_msm72k (g) (!strcmp("msm72k_udc", (g)->name)) +#else +#define gadget_is_msm72k (g) 0 +#endif +/** * usb_gadget_controller_number - support bcdDevice id convention
@@ -200,6 +206,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)return 0x25 ; else if (gadget_is_s3c_hsotg(gadget)) return 0x26; + else if (gadget_is_msm72k(gadget)) + return 0x27;return -ENOENT ; }
drivers/usb/gadget/msm72k_udc.c new file +1685 -0
1,685 lines not on this page · raw message
include/linux/usb/msm_hsusb.h new file +38 -0
@@ -0,0 +1,38 @@ +/* linux/include/asm-arm/arch-msm/hsusb.h +* +* Copyright (C) 2008 Google, Inc. +* Author: Brian Swetland <[email protected]> +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#ifndef __ASM_ARCH_MSM_HSUSB_H +#define __ASM_ARCH_MSM_HSUSB_H + +#include <linux/types.h> + +/** +* struct msm_hsusb_platform_data - platform device data +* for msm72k_udc driver. +* @phy_reset: assert followed by de-assert of PHY. +* @hw_reset: if enable is true, assert link otherwise +* de-assert link. +* @phy_init_seq: PHY configuration sequence. val, reg pairs +* terminated by -1. +* +*/ +struct msm_hsusb_platform_data { +void (*phy_reset)(void ); +void (*hw_reset)(bool enable); +int *phy_init_seq; +}; + +#endif
include/linux/usb/msm_hsusb_hw.h new file +184 -0
184 lines not on this page · raw message
Signature · 5 lines
1.7.1 -- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Quoted 51 lines · Pavankumar Kondeti
This patch adds the basic support for the USB Device Controller on Qualcomm MSM family of SOCs. The controller supports upto 16 endpoints including the default endpoint (ep0). All the data transfers are driven by DMA.
VBUS line is also connected to PMIC chip. The module controlling PMIC chip notifies about cable connect/disconnect events. Hence, PHY comparators are turned off in low power mode.
This driver was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.include/linux/usb/msm_hsusb_hw.h new file +39
-0+ +#define USB_ID (MSM_USB_BASE + 0x0000) +#define USB_HWGENERAL (MSM_USB_BASE + 0x0004) +#define USB_HWHOST (MSM_USB_BASE + 0x0008) +#define USB_HWDEVICE (MSM_USB_BASE + 0x000C) +#define USB_HWTXBUF (MSM_USB_BASE + 0x0010) +#define USB_HWRXBUF (MSM_USB_BASE + 0x0014) + +#ifdef CONFIG_ARCH_MSM7X00A +#define USB_SBUSCFG (MSM_USB_BASE + 0x0090) +#else +#define USB_AHBBURST (MSM_USB_BASE + 0x0090) +#define USB_AHBMODE (MSM_USB_BASE + 0x0098) +#endif + +#define USB_CAPLENGTH (MSM_USB_BASE + 0x0100)/* 8 bit */ +#define USB_HCIVERSION (MSM_USB_BASE + 0x0102)/* 16 bit */ +#define USB_HCSPARAMS (MSM_USB_BASE + 0x0104) +#define USB_HCCPARAMS (MSM_USB_BASE + 0x0108) +#define USB_DCIVERSION (MSM_USB_BASE + 0x0120)/* 16 bit */ +#define USB_USBCMD (MSM_USB_BASE + 0x0140) +#define USB_USBSTS (MSM_USB_BASE + 0x0144) +#define USB_USBINTR (MSM_USB_BASE + 0x0148) +#define USB_FRINDEX (MSM_USB_BASE + 0x014C) +#define USB_DEVICEADDR (MSM_USB_BASE + 0x0154) +#define USB_ENDPOINTLISTADDR (MSM_USB_BASE + 0x0158) +#define USB_BURSTSIZE (MSM_USB_BASE + 0x0160) +#define USB_TXFILLTUNING (MSM_USB_BASE + 0x0164) +#define USB_ULPI_VIEWPORT (MSM_USB_BASE + 0x0170) +#define USB_ENDPTNAK (MSM_USB_BASE + 0x0178) +#define USB_ENDPTNAKEN (MSM_USB_BASE + 0x017C) +#define USB_PORTSC (MSM_USB_BASE + 0x0184) +#define USB_OTGSC (MSM_USB_BASE + 0x01A4) +#define USB_USBMODE (MSM_USB_BASE + 0x01A8) +#define USB_ENDPTSETUPSTAT (MSM_USB_BASE + 0x01AC) +#define USB_ENDPTPRIME (MSM_USB_BASE + 0x01B0) +#define USB_ENDPTFLUSH (MSM_USB_BASE + 0x01B4) +#define USB_ENDPTSTAT (MSM_USB_BASE + 0x01B8) +#define USB_ENDPTCOMPLETE (MSM_USB_BASE + 0x01BC)
include/linux/usb/msm_hsusb_hw.h line 66
Quoted 10 lines
include/linux/usb/msm_hsusb_hw.h new file +10
-0+#define USB_ENDPTCTRL (n) (MSM_USB_BASE + 0x01C0 + (4 * (n))) + + +#define USBCMD_RESET 2 +#define USBCMD_ATTACH 1 +#define USBCMD_ATDTW (1 << 14) + +#define USBMODE_DEVICE 2 +#define USBMODE_HOST 3 +
This look like the arc/chipidea/mips ehci otg core.
Why can't you reuse the ci13xxx_udc.c driver ?
Or if ci13xxx_udc.c is too bad, rewrite a new generic version for this core.
Matthieu
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
On Tue, Nov 09, 2010 at 12:40:17PM +0100, Matthieu CASTET wrote:
Hi Matthieu,
Quoted 55 lines
Quoted 54 lines · Pavankumar Kondeti
This patch adds the basic support for the USB Device Controller on Qualcomm MSM family of SOCs. The controller supports upto 16 endpoints including the default endpoint (ep0). All the data transfers are driven by DMA.
VBUS line is also connected to PMIC chip. The module controlling PMIC chip notifies about cable connect/disconnect events. Hence, PHY comparators are turned off in low power mode.
This driver was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.include/linux/usb/msm_hsusb_hw.h new file +43
-0+ +#define USB_ID (MSM_USB_BASE + 0x0000) +#define USB_HWGENERAL (MSM_USB_BASE + 0x0004) +#define USB_HWHOST (MSM_USB_BASE + 0x0008) +#define USB_HWDEVICE (MSM_USB_BASE + 0x000C) +#define USB_HWTXBUF (MSM_USB_BASE + 0x0010) +#define USB_HWRXBUF (MSM_USB_BASE + 0x0014) + +#ifdef CONFIG_ARCH_MSM7X00A +#define USB_SBUSCFG (MSM_USB_BASE + 0x0090) +#else +#define USB_AHBBURST (MSM_USB_BASE + 0x0090) +#define USB_AHBMODE (MSM_USB_BASE + 0x0098) +#endif + +#define USB_CAPLENGTH (MSM_USB_BASE + 0x0100)/* 8 bit */ +#define USB_HCIVERSION (MSM_USB_BASE + 0x0102)/* 16 bit */ +#define USB_HCSPARAMS (MSM_USB_BASE + 0x0104) +#define USB_HCCPARAMS (MSM_USB_BASE + 0x0108) +#define USB_DCIVERSION (MSM_USB_BASE + 0x0120)/* 16 bit */ +#define USB_USBCMD (MSM_USB_BASE + 0x0140) +#define USB_USBSTS (MSM_USB_BASE + 0x0144) +#define USB_USBINTR (MSM_USB_BASE + 0x0148) +#define USB_FRINDEX (MSM_USB_BASE + 0x014C) +#define USB_DEVICEADDR (MSM_USB_BASE + 0x0154) +#define USB_ENDPOINTLISTADDR (MSM_USB_BASE + 0x0158) +#define USB_BURSTSIZE (MSM_USB_BASE + 0x0160) +#define USB_TXFILLTUNING (MSM_USB_BASE + 0x0164) +#define USB_ULPI_VIEWPORT (MSM_USB_BASE + 0x0170) +#define USB_ENDPTNAK (MSM_USB_BASE + 0x0178) +#define USB_ENDPTNAKEN (MSM_USB_BASE + 0x017C) +#define USB_PORTSC (MSM_USB_BASE + 0x0184) +#define USB_OTGSC (MSM_USB_BASE + 0x01A4) +#define USB_USBMODE (MSM_USB_BASE + 0x01A8) +#define USB_ENDPTSETUPSTAT (MSM_USB_BASE + 0x01AC) +#define USB_ENDPTPRIME (MSM_USB_BASE + 0x01B0) +#define USB_ENDPTFLUSH (MSM_USB_BASE + 0x01B4) +#define USB_ENDPTSTAT (MSM_USB_BASE + 0x01B8) +#define USB_ENDPTCOMPLETE (MSM_USB_BASE + 0x01BC) +#define USB_ENDPTCTRL (n) (MSM_USB_BASE + 0x01C0 + (4 * (n))) + + +#define USBCMD_RESET 2
Quoted 8 lines
include/linux/usb/msm_hsusb_hw.h line 66
Quoted 7 lines
include/linux/usb/msm_hsusb_hw.h new file +6
-0+#define USBCMD_ATTACH 1 +#define USBCMD_ATDTW (1 << 14) + +#define USBMODE_DEVICE 2 +#define USBMODE_HOST 3 +This look like the arc/chipidea/mips ehci otg core.
Yes. It is chipidea core for ARM.
Quoted 4 lines
Why can't you reuse the
ci13xxx_udc.cdriver ?
Or ifci13xxx_udc.cis too bad, rewrite a new generic version for this core.
ci13xxx_udc.c driver registers with PCI subsytem (ours is a platform subsystem), does not manage clocks. msm72k_udc.c also takes care of initializing the integrated PHY. We also need to program special registers (MSM-ARM specific) upon resetting the hardware.
Thanks,
Pavan
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Hi Pavan,
Quoted 7 lines · Pavan Kondeti
On Tue, Nov 09, 2010 at 12:40:17PM +0100, Matthieu CASTET wrote:
Hi Matthieu,
Quoted 2 lines
Quoted 1 line
This look like the arc/chipidea/mips ehci otg core.
Quoted 8 lines
Yes. It is chipidea core for ARM.
Quoted 3 lines
Why can't you reuse the
ci13xxx_udc.cdriver ?
Or ifci13xxx_udc.cis too bad, rewrite a new generic version for this core.
ci13xxx_udc.cdriver registers with PCI subsytem (ours is a platform subsystem), does not manage clocks.msm72k_udc.calso takes care of initializing the integrated PHY. We also need to program special registers (MSM-ARM specific) upon resetting the hardware.
Yes, but why not adding this to ci13xxx_udc.c instead of doing a new driver. For example adding platform subsystem is less than 150 lines of code.
I am not sure doing n drivers for a same hardware is a good idea.
May be ci13xxx_udc.c isn't enough generic, but in this case don't do the same mistake with the new driver.
Make a generic core, and make the ulpi stuff (or other specific stuff) in a glue around this code.
Look at host ehci : you don't need to rewrite ehci core. You only add a glue around it.
Matthieu
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Quoted 14 lines · Matthieu CASTET
Hi Pavan,
Quoted 11 lines · Pavan Kondeti
On Tue, Nov 09, 2010 at 12:40:17PM +0100, Matthieu CASTET wrote:
Hi Matthieu,
Quoted 2 lines
Quoted 1 line
This look like the arc/chipidea/mips ehci otg core.
Yes. It is chipidea core for ARM.
Quoted 3 lines
Why can't you reuse the
ci13xxx_udc.cdriver ?
Or ifci13xxx_udc.cis too bad, rewrite a new generic version for this core.
Quoted 6 lines
Quoted 4 lines
ci13xxx_udc.cdriver registers with PCI subsytem (ours is a platform subsystem), does not manage clocks.msm72k_udc.calso takes care of initializing the integrated PHY. We also need to program special registers (MSM-ARM specific) upon resetting the hardware.Yes, but why not adding this to
ci13xxx_udc.cinstead of doing a new driver. For example adding platform subsystem is less than 150 lines of code.
I agree.
Quoted 6 lines
I am not sure doing n drivers for a same hardware is a good idea.
May be
ci13xxx_udc.cisn't enough generic, but in this case don't do the same mistake with the new driver.
Sure. Thanks for the advice.
Quoted 3 lines
Make a generic core, and make the ulpi stuff (or other specific stuff) in a glue around this code.
IMHO, generic core should handle the controller stuff (endpoint operations, interrupts processing etc...) and leave the transceiver interaction to the individual device controller driver.
Quoted 3 lines
Look at host ehci : you don't need to rewrite ehci core. You only add a glue around it.
Thanks for pointing to EHCI. ehci-hcd can support PCI/platform/PS3 buses. It takes care of most of the things and yet gives flexibility to HCD to implement their own methods.
I will hack ci13xxx_udc.c (platform bus support) and see how it goes. If it works, I will see how ci13xxx_ stuff can be reused efficiently.
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Quoted 7 lines · Pavan Kondeti
Quoted 3 lines
Quoted 3 lines
Hi Matthieu,
Quoted 1 line
This look like the arc/chipidea/mips ehci otg
core.
Quoted 3 lines
Quoted 3 lines
Yes. It is chipidea core for ARM.
Quoted 1 line
Why can't you reuse the
ci13xxx_udc.cdriver
That basic approach is FAR PREFERABLE. Fix the bugs once, tune once, and so forth, reuse the ULPI support, etc. Work on more platforms, since the silicon IP is reused.
You'll end up with more folk who can help maintain the driver too, since the pool of potential helpers won't be limited to those who have/use MSM hardware.
Just be sure to cleanly factor the bus (PCI vs MSM-s ARM platform flavor and SoC glues (bus-related). That factoring will likely be the hardest part; but there are examples of similar stuff in Linux today.
Quoted 5 lines
?
Quoted 1 line
Quoted 1 line
Quoted 1 line
Or if
ci13xxx_udc.cis too bad, rewrite a newgeneric version for this core.
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Yes, but why not adding this to
ci13xxx_udc.cinstead
Quoted 8 lines
of doing a new driver.
Quoted 1 line
For example adding platform subsystem is less than 150
lines of code.
I agree.
Quoted 2 lines
I am not sure doing n drivers for a same hardware is a
good idea.
I'm pretty sure it is a BAD idea, myself. Same IP/hardware means only bus/SoC glue really needs to differ (including power and reset management).
- Dave
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Quoted 22 lines · David Brownell
Quoted 7 lines · Pavan Kondeti
Quoted 3 lines
Quoted 3 lines
Hi Matthieu,
Quoted 1 line
This look like the arc/chipidea/mips ehci otg
core.
Quoted 3 lines
Quoted 3 lines
Yes. It is chipidea core for ARM.
Quoted 1 line
Why can't you reuse the
ci13xxx_udc.cdriverThat basic approach is FAR PREFERABLE. Fix the bugs once, tune once, and so forth, reuse the ULPI support, etc. Work on more platforms, since the silicon IP is reused.
You'll end up with more folk who can help maintain the driver too, since the pool of potential helpers won't be limited to those who have/use MSM hardware.
Quoted 5 lines
Just be sure to cleanly factor the bus (PCI vs MSM-s ARM platform flavor and SoC glues (bus-related). That factoring will likely be the hardest part; but there are examples of similar stuff in Linux today.
The main headache is that this particular IP has different bugs in different instantiations (I know, for example, it exists in Tegra with a different set of issues around fetching descriptor heads and cache alignment, on MSM7201A after extensive testing we discovered there was no reliable way of adding a descriptor to a list of transactions once that queue was active, etc...), so things that work in one SoC may break another, etc, etc, but that's part of the adventure I suppose. I certainly agree that one unified driver is the way to go if you can make it all work.
Brian
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Hi,
Quoted 26 lines · Brian Swetland
Quoted 19 lines · David Brownell
Quoted 6 lines · Pavan Kondeti
Quoted 3 lines
Quoted 3 lines
Hi Matthieu,
Quoted 1 line
This look like the arc/chipidea/mips ehci otg
core.
Quoted 2 lines
Quoted 2 lines
Yes. It is chipidea core for ARM.
Quoted 1 line
Why can't you reuse the
ci13xxx_udc.cdriverThat basic approach is FAR PREFERABLE. Fix the bugs once, tune once, and so forth, reuse the ULPI support, etc. Work on more platforms, since the silicon IP is reused.
You'll end up with more folk who can help maintain the driver too, since the pool of potential helpers won't be limited to those who have/use MSM hardware.
Quoted 5 lines
Just be sure to cleanly factor the bus (PCI vs MSM-s ARM platform flavor and SoC glues (bus-related). That factoring will likely be the hardest part; but there are examples of similar stuff in Linux today.
Quoted 10 lines
The main headache is that this particular IP has different bugs in different instantiations (I know, for example, it exists in Tegra with a different set of issues around fetching descriptor heads and cache alignment, on MSM7201A after extensive testing we discovered there was no reliable way of adding a descriptor to a list of transactions once that queue was active, etc...), so things that work in one SoC may break another, etc, etc, but that's part of the adventure I suppose. I certainly agree that one unified driver is the way to go if you can make it all work.
The best way to handle this is to introduce flags in the driver. For example look at drivers/mmc/host/sdhci.c (quirk flags).
But for now, let's make work msm version. We can add workaround for other controller later.
Now you should check if it is better to start on ci13xxx_udc or make generic your driver.
I had worked a bit on ci13xxx_udc, and the code is sometimes messy, hard to understand. Also to making work on our core, we need to the attached patch.
Matthieu
drivers/usb/gadget/ci13xxx_udc.c +8 -4
@@ -2140,6 +2140,7 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req, struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req);int retval =0 ;unsigned long flags; +int empty;trace ("%p, %p, %X" , ep, req, gfp_flags);
@@ -2170,15 +2171,18 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,dbg_queue (_usb_addr (mEp), req, retval); + empty =list_empty (&mEp->qh[mEp->dir].queue);/* push request */ mReq->req.status = -EINPROGRESS ; mReq->req.actual =0 ;list_add_tail (&mReq->queue, &mEp->qh[mEp->dir].queue); - retval =_hardware_enqueue (mEp, mReq); -if (retval == -EALREADY || retval == -EBUSY ) { -dbg_event (_usb_addr (mEp),"QUEUE" , retval); - retval =0 ; +if (empty) { + retval =_hardware_enqueue (mEp, mReq); +if (retval == -EALREADY || retval == -EBUSY ) { +dbg_event (_usb_addr (mEp),"QUEUE" , retval); + retval =0 ; + } } done:
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Quoted 40 lines · Matthieu CASTET
Hi,
Quoted 27 lines · Brian Swetland
Quoted 19 lines · David Brownell
Quoted 6 lines · Pavan Kondeti
Quoted 3 lines
Quoted 3 lines
Hi Matthieu,
Quoted 1 line
This look like the arc/chipidea/mips ehci otg
core.
Quoted 2 lines
Quoted 2 lines
Yes. It is chipidea core for ARM.
Quoted 1 line
Why can't you reuse the
ci13xxx_udc.cdriverThat basic approach is FAR PREFERABLE. Fix the bugs once, tune once, and so forth, reuse the ULPI support, etc. Work on more platforms, since the silicon IP is reused.
You'll end up with more folk who can help maintain the driver too, since the pool of potential helpers won't be limited to those who have/use MSM hardware.
Quoted 5 lines
Just be sure to cleanly factor the bus (PCI vs MSM-s ARM platform flavor and SoC glues (bus-related). That factoring will likely be the hardest part; but there are examples of similar stuff in Linux today.
Quoted 10 lines
The main headache is that this particular IP has different bugs in different instantiations (I know, for example, it exists in Tegra with a different set of issues around fetching descriptor heads and cache alignment, on MSM7201A after extensive testing we discovered there was no reliable way of adding a descriptor to a list of transactions once that queue was active, etc...), so things that work in one SoC may break another, etc, etc, but that's part of the adventure I suppose. I certainly agree that one unified driver is the way to go if you can make it all work.
Quoted 6 lines
The best way to handle this is to introduce flags in the driver. For example look at
drivers/mmc/host/sdhci.c(quirk flags).But for now, let's make work msm version. We can add workaround for other controller later.
I am working on separating PCI stuff from ci13xxx_udc driver and implementing specific hooks needed for MSM. I am relying on gadget_is_xxx() macro for MSM specific workarounds.
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Quoted 3 lines
implementing specific hooks needed for MSM. I am relying on
gadget_is_xxx()macro for MSM specific workarounds.
NEVER DO THAT from inside controller drivers.
(If the code isn't specific to the msm silicon, and works on other vendors' implementations too, it'd misbehave anyway.
Those calls are for gadget drivers, e.g. to embed knowledge about controller issues which can't be detected by looking at what's advertised by the gadget controller device. Using them isn't encouraged.
Controller drivers should see what hardware they're talking to by actually talking to the chip and detecting any quirks (be they revision-specific or otherwise). In some cases platform_data will be the way to package such information.
- Dave
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Hi Dave,
Quoted 5 lines · David Brownell
Quoted 3 lines
implementing specific hooks needed for MSM. I am relying on
gadget_is_xxx()macro for MSM specific workarounds.NEVER DO THAT from inside controller drivers.
Here we are using the macro in ci13xxx_udc core which is included by two gadget controller drivers.
Quoted 10 lines
(If the code isn't specific to the msm silicon, and works on other vendors' implementations too, it'd misbehave anyway.
Those calls are for gadget drivers, e.g. to embed knowledge about controller issues which can't be detected by looking at what's advertised by the gadget controller device. Using them isn't encouraged.
Quoted 5 lines
Controller drivers should see what hardware they're talking to by actually talking to the chip and detecting any quirks (be they revision-specific or otherwise). In some cases
platform_datawill be the way to package such information.
We need the following hooks/extension in ci13xxx_udc for MSM SoC.
1. MSM USB device controller depends on OTG driver for clocks, Low power mode, and PHY initialization. So udc_probe() must fail if otg_get_transceiver() fails.
2. By default streaming mode is enabled in ci13xxx controller. It has to be disabled due to some known issues.
3. Currently, pull-up is enabled upon gadget driver registration. But we want to enable only upon VBUS presence. also controller must be reset before enabling the pull-up as the controller was in host mode before.
4. Hardware registers should not be accessed in udc_probe()
I have started with flags to achieve the above and ended up with following:
TRANSCEIVER_IS_REQUIRED: Fail udc_probe() if otg_get_transceiver() == NULLSKIP_RESET_IN_PROBE: avoid resetting the hardware in udc_prob()ENABLE_PULLUP_UPON_VBUS: Enable pull-up upon VBUSRESET_BEFORE_PULLUP: Reset the hardware before pull-upDISABLE_STREAM_MODE: Disable streaming mode
A post reset callback to write into special registers after reset
I thought introducing this many flags may not be a good idea and used gadget_is_xxx() macro to achieve the same. if tomorrow, some gadget controller wants to fail udc_probe() if otg_get_tranceiver(), they can too OR their gadget_is_xxx() macro. If you say using flags is not _bad_, I will take that approach.
Thanks,
Pavan
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
In reply to Matthieu CASTETHi Matthieu,
Quoted 6 lines · Matthieu CASTET
The best way to handle this is to introduce flags in the driver. For example look at
drivers/mmc/host/sdhci.c(quirk flags).But for now, let's make work msm version. We can add workaround for other controller later.
Quoted 8 lines
Now you should check if it is better to start on
ci13xxx_udcor make generic your driver.I had worked a bit on
ci13xxx_udc, and the code is sometimes messy, hard to understand.
Also to making work on our core, we need to the attached patch.
ci13xxx_udc is working fine on MSM SoC without the attached patch. According to hardware doc, When endpoint is in primed state the corresponding bit of either ENDPTRPIME or ENDPTSTAT will be set. The driver is assuming the same. So I don't see a problem.
The current driver, one dTD is given to the hardware at a time. We can improve it by adding hardware queuing functionality or adopt msm72k_udc algorithm.
I have submitted patches to separate PCI stuff out of ci13xxx_udc. I have submitted MSM bus glue driver which makes use of ci13xxx_udc. I have tested it on MSM SoC. But I don't have ci13xxx PCI hardware. Can you help me in testing my patches (5-11 of [PATCH V3 00/11] Add MSM USB controller driver)
Thanks in advance,
Pavan
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
In reply to Pavankumar KondetiQuoted 25 lines · ext Pavankumar Kondeti
This patch adds the basic support for the USB Device Controller on Qualcomm MSM family of SOCs. The controller supports upto 16 endpoints including the default endpoint (ep0). All the data transfers are driven by DMA.
VBUS line is also connected to PMIC chip. The module controlling PMIC chip notifies about cable connect/disconnect events. Hence, PHY comparators are turned off in low power mode.
This driver was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.CC Mike Lockwood <[email protected]>CC Brian Swetland <[email protected]>Signed-off-by Pavankumar Kondeti <[email protected]>--- drivers/usb/gadget/Kconfig | 17 + drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/gadget_chips.h | 8 + drivers/usb/gadget/msm72k_udc.c | 1685 +++++++++++++++++++++++++++++++++++++ include/linux/usb/msm_hsusb.h | 38 + include/linux/usb/msm_hsusb_hw.h | 184 ++++ 6 files changed, 1933 insertions(+), 0 deletions(-) create mode 100644 drivers/usb/gadget/msm72k_udc.c create mode 100644 include/linux/usb/msm_hsusb.h create mode 100644 include/linux/usb/msm_hsusb_hw.h
<snip>
include/linux/usb/msm_hsusb_hw.h line 166
Quoted 5 lines
include/linux/usb/msm_hsusb_hw.h new file +5
-0+#define ULPI_DEBUG_REG (0x15) +#define ULPI_SCRATCH_REG (0x16) + +#define ULPI_FUNC_CTRL_CLR (0x06) +#define ULPI_FUNC_SUSPENDM (1 << 6)
No more redefinitions of ulpi regs. Just include usb/ulpi.h.
Signature · 1 line
heikki
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
In reply to Pavankumar KondetiHi,
Quoted 53 lines · Pavankumar Kondeti
drivers/usb/gadget/msm72k_udc.c new file +47
-0+ +static unsigned ulpi_read (struct usb_info *ui,unsigned reg) +{ +unsigned timeout =100000 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return 0xffffffff ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct usb_info *ui,unsigned val,unsigned reg) +{ +unsigned timeout =10000 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_write: timeout\n" ); +return -1 ; + } + +return 0 ; +} + +static void ulpi_init (struct usb_info *ui) +{ +int *seq = ui->phy_init_seq; + +if (!seq)
drivers/usb/gadget/msm72k_udc.c line 295
Quoted 10 lines
drivers/usb/gadget/msm72k_udc.c new file +10
-0+return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (&ui->pdev->dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (ui, seq[0 ], seq[1 ]); + seq +=2 ; + } +} +
--- /dev/null
+++ b/drivers/usb/otg/msm72k_otg.c
+
+#define ULPI_IO_TIMEOUT_USEC (10 * 1000)
+static int ulpi_read(struct otg_transceiver *otg, u32 reg) +{
+ int cnt = 0;
+
+ /* initiate read operation */
+ writel(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg),
+ USB_ULPI_VIEWPORT);
+
+ /* wait for completion */
+ while (cnt < ULPI_IO_TIMEOUT_USEC) {
+ if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN))
+ break;
+ udelay(1);
+ cnt++;
+ }
+
+ if (cnt >= ULPI_IO_TIMEOUT_USEC) {
+ dev_err(otg->dev, "ulpi_read: timeout %08x\n",
+ readl(USB_ULPI_VIEWPORT));
+ return -ETIMEDOUT;
+ }
+ return ULPI_DATA_READ(readl(USB_ULPI_VIEWPORT));
+}
+
+static int ulpi_write(struct otg_transceiver *otg, u32 val, u32 reg) +{
+ int cnt = 0;
+
+ /* initiate write operation */
+ writel(ULPI_RUN | ULPI_WRITE |
+ ULPI_ADDR(reg) | ULPI_DATA(val),
+ USB_ULPI_VIEWPORT);
+
+ /* wait for completion */
+ while (cnt < ULPI_IO_TIMEOUT_USEC) {
+ if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN))
+ break;
+ udelay(1);
+ cnt++;
+ }
+
+ if (cnt >= ULPI_IO_TIMEOUT_USEC) {
+ dev_err(otg->dev, "ulpi_write: timeout\n");
+ return -ETIMEDOUT;
+ }
+ return 0;
+}
+
+static struct otg_io_access_ops msm_otg_io_ops = {
+ .read = ulpi_read,
+ .write = ulpi_write,
+};
+
+static void ulpi_init(struct msm_otg *motg)
+{
+ struct msm_otg_platform_data *pdata = motg->pdata;
+ int *seq = pdata->phy_init_seq;
+
+ if (!seq)
+ return;
+
+ while (seq[0] >= 0) {
+ dev_vdbg(motg->otg.dev, "ulpi: write 0x%02x to 0x%02x\n",
+ seq[0], seq[1]);
+ ulpi_write(&motg->otg, seq[0], seq[1]);
+ seq += 2;
+ }
+}
can't you share the ulpi fonctions from udc and otg ?
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Quoted 144 lines · Matthieu CASTET
Hi,
Quoted 63 lines · Pavankumar Kondeti
drivers/usb/gadget/msm72k_udc.c new file +57
-0+ +static unsigned ulpi_read (struct usb_info *ui,unsigned reg) +{ +unsigned timeout =100000 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return 0xffffffff ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct usb_info *ui,unsigned val,unsigned reg) +{ +unsigned timeout =10000 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_write: timeout\n" ); +return -1 ; + } + +return 0 ; +} + +static void ulpi_init (struct usb_info *ui) +{ +int *seq = ui->phy_init_seq; + +if (!seq) +return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (&ui->pdev->dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (ui, seq[0 ], seq[1 ]); + seq +=2 ; + } +} +drivers/usb/otg/msm72k_otg.c new file +70
-0+ +#define ULPI_IO_TIMEOUT_USEC (10 * 1000) +static int ulpi_read (struct otg_transceiver *otg,u32 reg) +{ +int cnt =0 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while (cnt <ULPI_IO_TIMEOUT_USEC ) { +if (!(readl (USB_ULPI_VIEWPORT ) &ULPI_RUN )) +break ; +udelay (1 ); + cnt++; + } + +if (cnt >=ULPI_IO_TIMEOUT_USEC ) { +dev_err (otg->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return -ETIMEDOUT ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct otg_transceiver *otg,u32 val,u32 reg) +{ +int cnt =0 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while (cnt <ULPI_IO_TIMEOUT_USEC ) { +if (!(readl (USB_ULPI_VIEWPORT ) &ULPI_RUN )) +break ; +udelay (1 ); + cnt++; + } + +if (cnt >=ULPI_IO_TIMEOUT_USEC ) { +dev_err (otg->dev,"ulpi_write: timeout\n" ); +return -ETIMEDOUT ; + } +return 0 ; +} + +static struct otg_io_access_ops msm_otg_io_ops = { + .read = ulpi_read, + .write = ulpi_write, +}; + +static void ulpi_init (struct msm_otg *motg) +{ +struct msm_otg_platform_data *pdata = motg->pdata; +int *seq = pdata->phy_init_seq; + +if (!seq) +return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (motg->otg.dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (&motg->otg, seq[0 ], seq[1 ]); + seq +=2 ; + } +}
Quoted 1 line
can't you share the ulpi fonctions from udc and otg ?
The best would be to use the usb/otg/ulpi.c driver for the ulpi access.
Signature · 2 lines
Regards, Igor.
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Quoted 147 lines · Igor Grinberg
Quoted 144 lines · Matthieu CASTET
Hi,
Quoted 63 lines · Pavankumar Kondeti
drivers/usb/gadget/msm72k_udc.c new file +57
-0+ +static unsigned ulpi_read (struct usb_info *ui,unsigned reg) +{ +unsigned timeout =100000 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return 0xffffffff ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct usb_info *ui,unsigned val,unsigned reg) +{ +unsigned timeout =10000 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_write: timeout\n" ); +return -1 ; + } + +return 0 ; +} + +static void ulpi_init (struct usb_info *ui) +{ +int *seq = ui->phy_init_seq; + +if (!seq) +return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (&ui->pdev->dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (ui, seq[0 ], seq[1 ]); + seq +=2 ; + } +} +drivers/usb/otg/msm72k_otg.c new file +70
-0+ +#define ULPI_IO_TIMEOUT_USEC (10 * 1000) +static int ulpi_read (struct otg_transceiver *otg,u32 reg) +{ +int cnt =0 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while (cnt <ULPI_IO_TIMEOUT_USEC ) { +if (!(readl (USB_ULPI_VIEWPORT ) &ULPI_RUN )) +break ; +udelay (1 ); + cnt++; + } + +if (cnt >=ULPI_IO_TIMEOUT_USEC ) { +dev_err (otg->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return -ETIMEDOUT ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct otg_transceiver *otg,u32 val,u32 reg) +{ +int cnt =0 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while (cnt <ULPI_IO_TIMEOUT_USEC ) { +if (!(readl (USB_ULPI_VIEWPORT ) &ULPI_RUN )) +break ; +udelay (1 ); + cnt++; + } + +if (cnt >=ULPI_IO_TIMEOUT_USEC ) { +dev_err (otg->dev,"ulpi_write: timeout\n" ); +return -ETIMEDOUT ; + } +return 0 ; +} + +static struct otg_io_access_ops msm_otg_io_ops = { + .read = ulpi_read, + .write = ulpi_write, +}; + +static void ulpi_init (struct msm_otg *motg) +{ +struct msm_otg_platform_data *pdata = motg->pdata; +int *seq = pdata->phy_init_seq; + +if (!seq) +return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (motg->otg.dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (&motg->otg, seq[0 ], seq[1 ]); + seq +=2 ; + } +}
Quoted 4 lines
Quoted 1 line
can't you share the ulpi fonctions from udc and otg ?
The best would be to use the
usb/otg/ulpi.cdriver for the ulpi access.
This driver will eventually use msm72k_otg.c transceiver.
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Quoted 145 lines · Pavan Kondeti
Quoted 144 lines · Igor Grinberg
Quoted 142 lines · Matthieu CASTET
Hi,
Quoted 62 lines · Pavankumar Kondeti
drivers/usb/gadget/msm72k_udc.c new file +57
-0+ +static unsigned ulpi_read (struct usb_info *ui,unsigned reg) +{ +unsigned timeout =100000 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return 0xffffffff ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct usb_info *ui,unsigned val,unsigned reg) +{ +unsigned timeout =10000 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_write: timeout\n" ); +return -1 ; + } + +return 0 ; +} + +static void ulpi_init (struct usb_info *ui) +{ +int *seq = ui->phy_init_seq; + +if (!seq) +return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (&ui->pdev->dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (ui, seq[0 ], seq[1 ]); + seq +=2 ; + } +} +drivers/usb/otg/msm72k_otg.c new file +70
-0+ +#define ULPI_IO_TIMEOUT_USEC (10 * 1000) +static int ulpi_read (struct otg_transceiver *otg,u32 reg) +{ +int cnt =0 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while (cnt <ULPI_IO_TIMEOUT_USEC ) { +if (!(readl (USB_ULPI_VIEWPORT ) &ULPI_RUN )) +break ; +udelay (1 ); + cnt++; + } + +if (cnt >=ULPI_IO_TIMEOUT_USEC ) { +dev_err (otg->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return -ETIMEDOUT ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct otg_transceiver *otg,u32 val,u32 reg) +{ +int cnt =0 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while (cnt <ULPI_IO_TIMEOUT_USEC ) { +if (!(readl (USB_ULPI_VIEWPORT ) &ULPI_RUN )) +break ; +udelay (1 ); + cnt++; + } + +if (cnt >=ULPI_IO_TIMEOUT_USEC ) { +dev_err (otg->dev,"ulpi_write: timeout\n" ); +return -ETIMEDOUT ; + } +return 0 ; +} + +static struct otg_io_access_ops msm_otg_io_ops = { + .read = ulpi_read, + .write = ulpi_write, +}; + +static void ulpi_init (struct msm_otg *motg) +{ +struct msm_otg_platform_data *pdata = motg->pdata; +int *seq = pdata->phy_init_seq; + +if (!seq) +return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (motg->otg.dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (&motg->otg, seq[0 ], seq[1 ]); + seq +=2 ; + } +}
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
can't you share the ulpi fonctions from udc and otg ?
The best would be to use the
usb/otg/ulpi.cdriver for the ulpi access.This driver will eventually use
msm72k_otg.ctransceiver.
Well, I mean, in addition to defining the struct otg_io_access_ops in some place, where both device and host drivers can share the same ops code, you can also use the ulpi generic driver as the protocol driver, instead of writing private code. If the generic driver still lack some functionality, I can try to help you with this.
Signature · 2 lines
Regards, Igor.
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Hi Igor,
Quoted 146 lines · Igor Grinberg
Quoted 145 lines · Pavan Kondeti
Quoted 144 lines · Igor Grinberg
Quoted 142 lines · Matthieu CASTET
Hi,
Quoted 62 lines · Pavankumar Kondeti
drivers/usb/gadget/msm72k_udc.c new file +57
-0+ +static unsigned ulpi_read (struct usb_info *ui,unsigned reg) +{ +unsigned timeout =100000 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return 0xffffffff ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct usb_info *ui,unsigned val,unsigned reg) +{ +unsigned timeout =10000 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_write: timeout\n" ); +return -1 ; + } + +return 0 ; +} + +static void ulpi_init (struct usb_info *ui) +{ +int *seq = ui->phy_init_seq; + +if (!seq) +return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (&ui->pdev->dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (ui, seq[0 ], seq[1 ]); + seq +=2 ; + } +} +drivers/usb/otg/msm72k_otg.c new file +70
-0+ +#define ULPI_IO_TIMEOUT_USEC (10 * 1000) +static int ulpi_read (struct otg_transceiver *otg,u32 reg) +{ +int cnt =0 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while (cnt <ULPI_IO_TIMEOUT_USEC ) { +if (!(readl (USB_ULPI_VIEWPORT ) &ULPI_RUN )) +break ; +udelay (1 ); + cnt++; + } + +if (cnt >=ULPI_IO_TIMEOUT_USEC ) { +dev_err (otg->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return -ETIMEDOUT ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct otg_transceiver *otg,u32 val,u32 reg) +{ +int cnt =0 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while (cnt <ULPI_IO_TIMEOUT_USEC ) { +if (!(readl (USB_ULPI_VIEWPORT ) &ULPI_RUN )) +break ; +udelay (1 ); + cnt++; + } + +if (cnt >=ULPI_IO_TIMEOUT_USEC ) { +dev_err (otg->dev,"ulpi_write: timeout\n" ); +return -ETIMEDOUT ; + } +return 0 ; +} + +static struct otg_io_access_ops msm_otg_io_ops = { + .read = ulpi_read, + .write = ulpi_write, +}; + +static void ulpi_init (struct msm_otg *motg) +{ +struct msm_otg_platform_data *pdata = motg->pdata; +int *seq = pdata->phy_init_seq; + +if (!seq) +return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (motg->otg.dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (&motg->otg, seq[0 ], seq[1 ]); + seq +=2 ; + } +}
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
can't you share the ulpi fonctions from udc and otg ?
The best would be to use the
usb/otg/ulpi.cdriver for the ulpi access.This driver will eventually use
msm72k_otg.ctransceiver.Well, I mean, in addition to defining the struct
otg_io_access_opsin some place, where both device and host drivers can share the same ops code, you can also use the ulpi generic driver as the protocol driver, instead of writing private code.
I have not looked at generic ULPI driver. I will see if we can re-use it in our msm72k_otg.c.
Quoted 2 lines
If the generic driver still lack some functionality, I can try to help you with this.
Sure. Thanks for offering help.
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Hi Igor,
Quoted 152 lines · Pavan Kondeti
Hi Igor,
Quoted 149 lines · Igor Grinberg
Quoted 148 lines · Pavan Kondeti
Quoted 147 lines · Igor Grinberg
Quoted 142 lines · Matthieu CASTET
Hi,
Quoted 62 lines · Pavankumar Kondeti
drivers/usb/gadget/msm72k_udc.c new file +57
-0+ +static unsigned ulpi_read (struct usb_info *ui,unsigned reg) +{ +unsigned timeout =100000 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return 0xffffffff ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct usb_info *ui,unsigned val,unsigned reg) +{ +unsigned timeout =10000 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_write: timeout\n" ); +return -1 ; + } + +return 0 ; +} + +static void ulpi_init (struct usb_info *ui) +{ +int *seq = ui->phy_init_seq; + +if (!seq) +return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (&ui->pdev->dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (ui, seq[0 ], seq[1 ]); + seq +=2 ; + } +} +drivers/usb/otg/msm72k_otg.c new file +70
-0+ +#define ULPI_IO_TIMEOUT_USEC (10 * 1000) +static int ulpi_read (struct otg_transceiver *otg,u32 reg) +{ +int cnt =0 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while (cnt <ULPI_IO_TIMEOUT_USEC ) { +if (!(readl (USB_ULPI_VIEWPORT ) &ULPI_RUN )) +break ; +udelay (1 ); + cnt++; + } + +if (cnt >=ULPI_IO_TIMEOUT_USEC ) { +dev_err (otg->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return -ETIMEDOUT ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct otg_transceiver *otg,u32 val,u32 reg) +{ +int cnt =0 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while (cnt <ULPI_IO_TIMEOUT_USEC ) { +if (!(readl (USB_ULPI_VIEWPORT ) &ULPI_RUN )) +break ; +udelay (1 ); + cnt++; + } + +if (cnt >=ULPI_IO_TIMEOUT_USEC ) { +dev_err (otg->dev,"ulpi_write: timeout\n" ); +return -ETIMEDOUT ; + } +return 0 ; +} + +static struct otg_io_access_ops msm_otg_io_ops = { + .read = ulpi_read, + .write = ulpi_write, +}; + +static void ulpi_init (struct msm_otg *motg) +{ +struct msm_otg_platform_data *pdata = motg->pdata; +int *seq = pdata->phy_init_seq; + +if (!seq) +return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (motg->otg.dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (&motg->otg, seq[0 ], seq[1 ]); + seq +=2 ; + } +}Quoted 1 line
can't you share the ulpi fonctions from udc and otg ?
The best would be to use the
usb/otg/ulpi.cdriver for the ulpi access.
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
This driver will eventually use
msm72k_otg.ctransceiver.Well, I mean, in addition to defining the struct
otg_io_access_opsin some place, where both device and host drivers can share the same ops code, you can also use the ulpi generic driver as the protocol driver, instead of writing private code.I have not looked at generic ULPI driver. I will see if we can re-use it in our
msm72k_otg.c.
The generic ULPI driver seems to be supporting initializing the PHY, configuring the PHY in Host mode and driving VBUS.
The PHY we have in our MSM chips does not have an integrated charge pump. So we depend on external voltage regulators driver VBUS. So can not use ulpi_set_vbus method.
IMO, ulpi_set_host is useful for only Hosts but not OTG (i.e support both gadget and host). We kick OTG state machine only after both gadget and host are registered. So we use our own set_host method and can not use ulpi_set_host.
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
Quoted 28 lines · Pavan Kondeti
Hi Igor,
Quoted 25 lines · Pavan Kondeti
Hi Igor,
Quoted 22 lines · Igor Grinberg
Quoted 21 lines · Pavan Kondeti
Quoted 20 lines · Igor Grinberg
Quoted 17 lines · Matthieu CASTET
(quoted diff) +15
-0+static void ulpi_init(struct msm_otg *motg) +{ + struct msm_otg_platform_data *pdata = motg->pdata; + int *seq = pdata->phy_init_seq; + + if (!seq) + return; + + while (seq[0] >= 0) { + dev_vdbg(motg->otg.dev, "ulpi: write 0x%02x to 0x%02x\n", + seq[0], seq[1]); + ulpi_write(&motg->otg, seq[0], seq[1]); + seq += 2; + } +}Quoted 1 line
can't you share the ulpi fonctions from udc and otg ?
The best would be to use the
usb/otg/ulpi.cdriver for the ulpi access.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
This driver will eventually use
msm72k_otg.ctransceiver.Well, I mean, in addition to defining the struct
otg_io_access_opsin some place, where both device and host drivers can share the same ops code, you can also use the ulpi generic driver as the protocol driver, instead of writing private code.I have not looked at generic ULPI driver. I will see if we can re-use it in our
msm72k_otg.c.The generic ULPI driver seems to be supporting initializing the PHY, configuring the PHY in Host mode and driving VBUS.
Currently, yes, it is correct.
The reason I haven't added some more functionality
(e.g. set_peripheral()) is because I don't have a h/w that supports it.
Quoted 3 lines
The PHY we have in our MSM chips does not have an integrated charge pump. So we depend on external voltage regulators driver VBUS. So can not use
ulpi_set_vbusmethod.
You don't have to...
ulpi driver relies on otg_transceiver, so if you don't call otg_set_vbus(), ulpi_set_vbus() will not be called and instead you can do your own set_vbus().
Quoted 3 lines
IMO,
ulpi_set_hostis useful for only Hosts but not OTG (i.e support both gadget and host). We kick OTG state machine only after both gadget and host are registered. So we use our ownset_hostmethod and can not useulpi_set_host.
IMHO, ULPI driver is not meant to somehow affect the OTG state machine. I think the initial design of the ULPI driver was a mistake.
It should not have implemented the OTG transceiver, but only the communication with the ULPI transceiver and implementation of the ULPI standard. It should be used only for setting up/changing modes of ULPI transceivers.
It already has the ability to detect/check reliability of view port of the ULPI transceiver, supply the wiring information to the ULPI transceiver.
I thought also of giving it the ability to reset the ULPI transceiver, and also add set_peripheral() routine, but the h/w I have does not support peripheral mode and does not need to reset the transceiver.
I can work on adding those, if someone find it useful.
Bottom line, I'd expect the communication with the ULPI transceiver handled by the ULPI driver and the rest by the OTG implementation (core or platform).
Signature · 2 lines
Regards, Igor.
Re: [PATCH v2] USB: Add MSM USB Device Controller driver
In reply to Matthieu CASTETQuoted 144 lines · Matthieu CASTET
Hi,
Quoted 63 lines · Pavankumar Kondeti
drivers/usb/gadget/msm72k_udc.c new file +57
-0+ +static unsigned ulpi_read (struct usb_info *ui,unsigned reg) +{ +unsigned timeout =100000 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return 0xffffffff ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct usb_info *ui,unsigned val,unsigned reg) +{ +unsigned timeout =10000 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while ((readl (USB_ULPI_VIEWPORT ) &ULPI_RUN ) && (--timeout)) + ; + +if (timeout ==0 ) { +dev_err (&ui->pdev->dev,"ulpi_write: timeout\n" ); +return -1 ; + } + +return 0 ; +} + +static void ulpi_init (struct usb_info *ui) +{ +int *seq = ui->phy_init_seq; + +if (!seq) +return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (&ui->pdev->dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (ui, seq[0 ], seq[1 ]); + seq +=2 ; + } +} +drivers/usb/otg/msm72k_otg.c new file +70
-0+ +#define ULPI_IO_TIMEOUT_USEC (10 * 1000) +static int ulpi_read (struct otg_transceiver *otg,u32 reg) +{ +int cnt =0 ; + +/* initiate read operation */ +writel (ULPI_RUN |ULPI_READ |ULPI_ADDR (reg), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while (cnt <ULPI_IO_TIMEOUT_USEC ) { +if (!(readl (USB_ULPI_VIEWPORT ) &ULPI_RUN )) +break ; +udelay (1 ); + cnt++; + } + +if (cnt >=ULPI_IO_TIMEOUT_USEC ) { +dev_err (otg->dev,"ulpi_read: timeout %08x\n" , +readl (USB_ULPI_VIEWPORT )); +return -ETIMEDOUT ; + } +return ULPI_DATA_READ (readl (USB_ULPI_VIEWPORT )); +} + +static int ulpi_write (struct otg_transceiver *otg,u32 val,u32 reg) +{ +int cnt =0 ; + +/* initiate write operation */ +writel (ULPI_RUN |ULPI_WRITE | +ULPI_ADDR (reg) |ULPI_DATA (val), +USB_ULPI_VIEWPORT ); + +/* wait for completion */ +while (cnt <ULPI_IO_TIMEOUT_USEC ) { +if (!(readl (USB_ULPI_VIEWPORT ) &ULPI_RUN )) +break ; +udelay (1 ); + cnt++; + } + +if (cnt >=ULPI_IO_TIMEOUT_USEC ) { +dev_err (otg->dev,"ulpi_write: timeout\n" ); +return -ETIMEDOUT ; + } +return 0 ; +} + +static struct otg_io_access_ops msm_otg_io_ops = { + .read = ulpi_read, + .write = ulpi_write, +}; + +static void ulpi_init (struct msm_otg *motg) +{ +struct msm_otg_platform_data *pdata = motg->pdata; +int *seq = pdata->phy_init_seq; + +if (!seq) +return ; + +while (seq[0 ] >=0 ) { +dev_vdbg (motg->otg.dev,"ulpi: write 0x%02x to 0x%02x\n" , + seq[0 ], seq[1 ]); +ulpi_write (&motg->otg, seq[0 ], seq[1 ]); + seq +=2 ; + } +}
Quoted 1 line
can't you share the ulpi fonctions from udc and otg ?
Yes. udc can use the ulpi ops defined by the otg. But in udc patch series, otg stuff is not integrated. I will post another patch to make udc work with otg. or you want me to add otg integration in the 1st patch series it self?
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH v2 1/1 USB: msm72k_udc: Add debugfs support
In reply to Pavankumar KondetiProvide debugfs files for reading endpoint registers and associated requests info, re-enumeration and resetting the hardware.
This patch was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.
--- drivers/usb/gadget/msm72k_udc.c | 164 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 164 insertions(+), 0 deletions(-)
drivers/usb/gadget/msm72k_udc.c +164 -0
@@ -27,8 +27,10 @@#include <linux/dma-mapping.h> #include <linux/dmapool.h> #include <linux/platform_device.h> +#include <linux/debugfs.h> #include <linux/workqueue.h> #include <linux/clk.h> +#include <linux/uaccess.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h>
@@ -138,6 +140,7 @@ static void usb_do_work(struct work_struct *w);#define USB_FLAG_START 0x0001#define USB_FLAG_VBUS_ONLINE 0x0002#define USB_FLAG_VBUS_OFFLINE 0x0004 +#define USB_FLAG_RESET 0x0008/** * struct usb_info: privated data of this driver.
@@ -155,6 +158,7 @@ static void usb_do_work(struct work_struct *w);* USB_FLAG_START: set upon gadget driver registration. * USB_FLAG_VBUS_ONLINE: set upon VBUS presence. * USB_FLAG_VBUS_OFFLINE: set upon VBUS absence. +* USB_FLAG_RESET: set upon reset request from debug file. * @online: indicates USB configured state. set upon set_config request. * @running: indicates pull-up state. * @pool: DMA pool for allocating endpoint queue items (dTD).
@@ -1216,6 +1220,12 @@ static void usb_do_work(struct work_struct *w)usb_do_work_check_vbus (ui);break ; } +if (flags &USB_FLAG_RESET ) { +dev_info (&ui->pdev->dev,"ONLINE -> RESET\n" ); +usb_reset (ui); +dev_info (&ui->pdev->dev,"RESET -> ONLINE\n" ); +break ; + }break ;case USB_STATE_OFFLINE :/* If we were signaled to go online and vbus is still
@@ -1269,6 +1279,158 @@ void msm_hsusb_set_vbus_state(int online)spin_unlock_irqrestore (&ui->lock, flags); } +#if defined(CONFIG_DEBUG_FS ) +void usb_function_reenumerate (void ) +{ +struct usb_info *ui = the_usb_info; + +/* disable and re-enable the D+ pullup */ +msm72k_pullup (&ui->gadget, false); +usleep_range (10000 ,12000 ); +msm72k_pullup (&ui->gadget, true); +} + +static char debug_buffer[PAGE_SIZE ]; + +static ssize_t debug_read_status (struct file *file,char __user *ubuf, +size_t count,loff_t *ppos) +{ +struct usb_info *ui = file->private_data; +char *buf = debug_buffer; +unsigned long flags; +struct msm_endpoint *ept; +struct msm_request *req; +int n; +int i =0 ; + +spin_lock_irqsave (&ui->lock, flags); + + i +=scnprintf (buf + i,PAGE_SIZE - i, +"regs: setup=%08x prime=%08x stat=%08x done=%08x\n" , +readl (USB_ENDPTSETUPSTAT ), +readl (USB_ENDPTPRIME ), +readl (USB_ENDPTSTAT ), +readl (USB_ENDPTCOMPLETE )); + i +=scnprintf (buf + i,PAGE_SIZE - i, +"regs: cmd=%08x sts=%08x intr=%08x port=%08x\n\n" , +readl (USB_USBCMD ), +readl (USB_USBSTS ), +readl (USB_USBINTR ), +readl (USB_PORTSC )); + + +for (n =0 ; n <32 ; n++) { + ept = ui->ept + n; +if (ept->ep.maxpacket ==0 ) +continue ; + + i +=scnprintf (buf + i,PAGE_SIZE - i, +"ept%d %s cfg=%08x active=%08x next=%08x" +"info=%08x\n" , ept->num, + (ept->flags &EPT_FLAG_IN ) ?"in " :"out" , + ept->head->config, ept->head->active, + ept->head->next, ept->head->info); + +for (req = ept->req; req; req = req->next) + i +=scnprintf (buf + i,PAGE_SIZE - i, +" req @%08x next=%08x info=%08x" +"page0=%08x %c %c\n" , + req->item_dma, req->item->next, + req->item->info, req->item->page0, + req->busy ?'B' :' ' , + req->live ?'L' :' ' + ); + } + +spin_unlock_irqrestore (&ui->lock, flags); + +return simple_read_from_buffer (ubuf, count, ppos, buf, i); +} + +static ssize_t debug_write_reset (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +struct usb_info *ui = file->private_data; +unsigned long flags; + +spin_lock_irqsave (&ui->lock, flags); + ui->flags |=USB_FLAG_RESET ; +schedule_work (&ui->work); +spin_unlock_irqrestore (&ui->lock, flags); + +return count; +} + +static ssize_t debug_write_cycle (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +usb_function_reenumerate (); +return count; +} + +static ssize_t debug_write_vbus (struct file *file,const char __user *buf, +size_t count,loff_t *ppos) +{ +char kbuf[8 ]; +size_t len; + + len =min (count,sizeof (kbuf) -1 ); +if (copy_from_user (kbuf, buf, len)) +return -EFAULT ; + kbuf[len] ='\0' ; + +if (strncmp (kbuf,"on" ,2 ) ==0 ) +msm_hsusb_set_vbus_state (1 ); +else if (strncmp (kbuf,"off" ,3 ) ==0 ) +msm_hsusb_set_vbus_state (0 ); +else +return -EINVAL ; + +return count; +} + +static int debug_open (struct inode *inode,struct file *file) +{ + file->private_data = inode->i_private; +return 0 ; +} + +const struct file_operations debug_stat_ops = { + .open = debug_open, + .read = debug_read_status, +}; + +const struct file_operations debug_reset_ops = { + .open = debug_open, + .write = debug_write_reset, +}; + +const struct file_operations debug_cycle_ops = { + .open = debug_open, + .write = debug_write_cycle, +}; + +const struct file_operations debug_vbus_ops = { + .open = debug_open, + .write = debug_write_vbus, +}; + +static void usb_debugfs_init (struct usb_info *ui) +{ +struct dentry *dent; + dent =debugfs_create_dir (dev_name (&ui->pdev->dev),0 ); +if (IS_ERR (dent)) +return ; + +debugfs_create_file ("status" ,0444 , dent, ui, &debug_stat_ops); +debugfs_create_file ("reset" ,0220 , dent, ui, &debug_reset_ops); +debugfs_create_file ("cycle" ,0220 , dent, ui, &debug_cycle_ops); +debugfs_create_file ("vbus" ,0220 , dent, ui, &debug_vbus_ops); +} +#else +static void usb_debugfs_init (struct usb_info *ui) {} +#endif /* CONFIG_DEBUG_FS */ +static int msm72k_enable (struct usb_ep *_ep,const struct usb_endpoint_descriptor *desc) {
@@ -1576,6 +1738,8 @@ static int msm72k_probe(struct platform_device *pdev) the_usb_info = ui; +usb_debugfs_init (ui); +usb_prepare (ui);return 0 ;
Signature · 5 lines
1.7.1 -- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH v2 1/1 USB: msm72k_udc: Add Remote wakeup support
In reply to Pavankumar KondetiProcess device remote wakeup set/clear feature requests and implement wakeup method of usb_gadget_ops. This patch also provides a sysfs file to initiate remote wakeup from user space. Remote wakeup can be generated by poking into /sys/devices/platform/msm_hsusb/gadget/wakeup file.
--- drivers/usb/gadget/msm72k_udc.c | 62 ++++++++++++++++++++++++++++++++++++++ include/linux/usb/msm_hsusb_hw.h | 3 ++ 2 files changed, 65 insertions(+), 0 deletions(-)
drivers/usb/gadget/msm72k_udc.c +62 -0
@@ -179,6 +179,7 @@ static void usb_do_work(struct work_struct *w);* @clk: clock struct of usb_hs_clk. * @pclk: clock struct of usb_hs_pclk. * @ep0_dir: direction of ep0 setup data transfer. +* @remote_wakeup: indicates remote wakeup capability enabled by host * */ struct usb_info {
@@ -221,6 +222,7 @@ struct usb_info {struct clk *pclk;unsigned int ep0_dir; +u8 remote_wakeup; };static const struct usb_ep_ops msm72k_ep_ops;
@@ -647,6 +649,8 @@ static void handle_setup(struct usb_info *ui)u16 temp =0 ; temp =1 <<USB_DEVICE_SELF_POWERED ; + temp |= (ui->remote_wakeup << +USB_DEVICE_REMOTE_WAKEUP );memcpy (req->buf, &temp,2 );break ; }
@@ -695,6 +699,16 @@ static void handle_setup(struct usb_info *ui)*/ writel ((ctl.wValue <<25 ) | (1 <<24 ),USB_DEVICEADDR ); goto ack; + }else if (ctl.bRequest ==USB_REQ_SET_FEATURE ) { +switch (ctl.wValue) { +case USB_DEVICE_REMOTE_WAKEUP : + ui->remote_wakeup =1 ; + goto ack; + } + }else if ((ctl.bRequest ==USB_REQ_CLEAR_FEATURE ) && + (ctl.wValue ==USB_DEVICE_REMOTE_WAKEUP )) { + ui->remote_wakeup =0 ; + goto ack; } }
@@ -900,6 +914,7 @@ static irqreturn_t usb_interrupt(int irq, void *data)writel (readl (USB_ENDPTCOMPLETE ),USB_ENDPTCOMPLETE );writel (0xffffffff ,USB_ENDPTFLUSH );writel (0 ,USB_ENDPTCTRL (1 )); + ui->remote_wakeup =0 ;if (ui->online !=0 ) {/* marking us offline will cause ept queue attempts
@@ -1660,12 +1675,52 @@ static int msm72k_pullup(struct usb_gadget *_gadget, int is_active)return 0 ; } +static int msm72k_wakeup (struct usb_gadget *_gadget) +{ + struct usb_info *ui = container_of(_gadget, struct usb_info, gadget); +unsigned long flags; + +if (!ui->remote_wakeup) { +dev_err (&ui->pdev->dev,"%s: remote wakeup not supported\n" , + __func__); +return -ENOTSUPP ; + } + +if (!ui->online) { +dev_err (&ui->pdev->dev,"%s: device is not configured\n" , + __func__); +return -ENODEV ; + } + +spin_lock_irqsave (&ui->lock, flags); +if ((readl (USB_PORTSC ) &PORTSC_SUSP ) ==PORTSC_SUSP ) { +dev_info (&ui->pdev->dev,"%s: enabling force resume\n" , + __func__); +writel (readl (USB_PORTSC ) |PORTSC_FPR ,USB_PORTSC ); + } +spin_unlock_irqrestore (&ui->lock, flags); + +return 0 ; +} +static const struct usb_gadget_ops msm72k_ops = { .get_frame = msm72k_get_frame, .vbus_session = msm72k_udc_vbus_session, .pullup = msm72k_pullup, + .wakeup = msm72k_wakeup, }; +static ssize_t usb_remote_wakeup (struct device *dev, +struct device_attribute *attr,const char *buf,size_t count) +{ +struct usb_info *ui = the_usb_info; + +msm72k_wakeup (&ui->gadget); + +return count; +} +static DEVICE_ATTR(wakeup, S_IWUSR, 0, usb_remote_wakeup); +static int msm72k_probe (struct platform_device *pdev) {struct resource *res;
@@ -1795,6 +1850,12 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver,dev_info (&ui->pdev->dev,"registered gadget driver '%s'\n" , driver->driver.name); +/* create sysfs node for remote wakeup */ + retval =device_create_file (&ui->gadget.dev, &dev_attr_wakeup); +if (retval !=0 ) +dev_info (&ui->pdev->dev,"failed to create sysfs entry:" +"(wakeup) error: (%d)\n" , retval); +usb_start (ui);return 0 ;
@@ -1815,6 +1876,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)if (!driver || driver != dev->driver || !driver->unbind)return -EINVAL ; +device_remove_file (&dev->gadget.dev, &dev_attr_wakeup); driver->unbind (&dev->gadget); dev->gadget.dev.driver =NULL ; dev->driver =NULL ;
include/linux/usb/msm_hsusb_hw.h +3 -0
@@ -171,6 +171,9 @@ struct ept_queue_item {#define PORTSC_PSPD_LS (1 << 26)#define PORTSC_PSPD_HS (2 << 26)#define PORTSC_PSPD_MASK (3 << 26) +/* suspend and remote wakeup */ +#define PORTSC_FPR (1 << 6) +#define PORTSC_SUSP (1 << 7)#define PORTSC_PTS_MASK (3 << 30)#define PORTSC_PTS_ULPI (2 << 30)
Signature · 5 lines
1.7.1 -- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH v2 1/1 USB: msm72k_udc: Add Test Mode support
In reply to Pavankumar KondetiImplement the test modes mentioned in 7.1.20 section of USB 2.0 specification. High-speed capable devices must support these test modes to facilitate compliance testing.
--- drivers/usb/gadget/msm72k_udc.c | 52 +++++++++++++++++++++++++++++++++++++- include/linux/usb/msm_hsusb_hw.h | 11 ++++++++ 2 files changed, 62 insertions(+), 1 deletions(-)
drivers/usb/gadget/msm72k_udc.c +51 -1
@@ -180,6 +180,7 @@ static void usb_do_work(struct work_struct *w);* @pclk: clock struct of usb_hs_pclk. * @ep0_dir: direction of ep0 setup data transfer. * @remote_wakeup: indicates remote wakeup capability enabled by host +* @test_mode: electrical test mode set by host * */ struct usb_info {
@@ -223,6 +224,7 @@ struct usb_info {unsigned int ep0_dir;u8 remote_wakeup; +u16 test_mode; };static const struct usb_ep_ops msm72k_ep_ops;
@@ -571,11 +573,49 @@ static void ep0_queue_ack_complete(struct usb_ep *ep, struct usb_request *req)ep0_complete (ep, req); } +static void ep0_setup_ack_complete (struct usb_ep *ep,struct usb_request *req) +{ +struct msm_endpoint *ept =to_msm_endpoint (ep); +struct usb_info *ui = ept->ui; +unsigned int temp; + +if (!ui->test_mode) +return ; + +switch (ui->test_mode) { +case J_TEST : +dev_info (&ui->pdev->dev,"usb electrical test mode: (J)\n" ); + temp =readl (USB_PORTSC ) & (~PORTSC_PTC ); +writel (temp |PORTSC_PTC_J_STATE ,USB_PORTSC ); +break ; + +case K_TEST : +dev_info (&ui->pdev->dev,"usb electrical test mode: (K)\n" ); + temp =readl (USB_PORTSC ) & (~PORTSC_PTC ); +writel (temp |PORTSC_PTC_K_STATE ,USB_PORTSC ); +break ; + +case SE0_NAK_TEST : +dev_info (&ui->pdev->dev,"usb electrical test mode:" +"(SE0-NAK)\n" ); + temp =readl (USB_PORTSC ) & (~PORTSC_PTC ); +writel (temp |PORTSC_PTC_SE0_NAK ,USB_PORTSC ); +break ; + +case TST_PKT_TEST : +dev_info (&ui->pdev->dev,"usb electrical test mode:" +"(TEST_PKT)\n" ); + temp =readl (USB_PORTSC ) & (~PORTSC_PTC ); +writel (temp |PORTSC_PTC_TST_PKT ,USB_PORTSC ); +break ; + } +} +static void ep0_setup_ack (struct usb_info *ui) {struct usb_request *req = ui->setup_req; req->length =0 ; - req->complete =0 ; + req->complete = ep0_setup_ack_complete;usb_ept_queue_xfer (&ui->ep0in, req); }
@@ -701,6 +741,16 @@ static void handle_setup(struct usb_info *ui) goto ack; }else if (ctl.bRequest ==USB_REQ_SET_FEATURE ) {switch (ctl.wValue) { +case USB_DEVICE_TEST_MODE : +switch (ctl.wIndex) { +case J_TEST : +case K_TEST : +case SE0_NAK_TEST : +case TST_PKT_TEST : + ui->test_mode = ctl.wIndex; + goto ack; + } + goto stall;case USB_DEVICE_REMOTE_WAKEUP : ui->remote_wakeup =1 ; goto ack;
include/linux/usb/msm_hsusb_hw.h +11 -0
@@ -175,6 +175,17 @@ struct ept_queue_item {#define PORTSC_FPR (1 << 6)#define PORTSC_SUSP (1 << 7) +/* test mode support */ +#define J_TEST (0x0100) +#define K_TEST (0x0200) +#define SE0_NAK_TEST (0x0300) +#define TST_PKT_TEST (0x0400) +#define PORTSC_PTC (0xf << 16) +#define PORTSC_PTC_J_STATE (0x01 << 16) +#define PORTSC_PTC_K_STATE (0x02 << 16) +#define PORTSC_PTC_SE0_NAK (0x03 << 16) +#define PORTSC_PTC_TST_PKT (0x04 << 16) +#define PORTSC_PTS_MASK (3 << 30)#define PORTSC_PTS_ULPI (2 << 30)#define PORTSC_PTS_SERIAL (3 << 30)
Signature · 5 lines
1.7.1 -- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 1/1 USB: msm72k_udc: Add charging notification support
In reply to Pavankumar KondetiProvide Host PC (after configured), Wall charger notifications. Typically Battery/Charger driver is subscribed to these notifications and responsible for notifying user space and drawing the current.
This patch was originally developed by Google and is available at
http://android.git.kernel.org/?p=kernel/experimental.git.
--- drivers/usb/gadget/msm72k_udc.c | 17 +++++++++++++++++ include/linux/usb/msm_hsusb.h | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-)
drivers/usb/gadget/msm72k_udc.c +17 -0
@@ -173,6 +173,8 @@ static void usb_do_work(struct work_struct *w);* comes from platform data. * @hw_reset: function pointer to assert/de-assert of link. * comes from platform data. +* @usb_connected: callback function registered to receive charger type +* notifications. comes from platform data. * @work: work_struct for state transitions. * @gadget: gadget struct of this driver. * @driver: gadget driver bound to this driver.
@@ -211,6 +213,8 @@ struct usb_info {void (*phy_reset)(void );void (*hw_reset)(bool en); +void (*usb_connected)(int ); +struct work_struct work;struct usb_gadget gadget;
@@ -733,6 +737,8 @@ static void handle_setup(struct usb_info *ui)if (ctl.bRequestType == (USB_DIR_OUT |USB_TYPE_STANDARD )) {if (ctl.bRequest ==USB_REQ_SET_CONFIGURATION ) { ui->online = !!ctl.wValue; +if (ui->online && ui->usb_connected) + ui->usb_connected (USB_CHG_HOST ); }else if (ctl.bRequest ==USB_REQ_SET_ADDRESS ) {/* write address delayed (will take effect ** after the next IN txn)
@@ -1263,6 +1269,9 @@ static void usb_do_work(struct work_struct *w)msm72k_pullup (&ui->gadget,0 );spin_unlock_irqrestore (&ui->lock, iflags); +if (ui->usb_connected) + ui->usb_connected (USB_CHG_NONE ); +/* terminate any transactions, etc */ flush_all_endpoints (ui);
@@ -1302,6 +1311,13 @@ static void usb_do_work(struct work_struct *w)clk_enable (ui->pclk);usb_reset (ui); +/* detect shorted D+/D-, indicating AC power */ +usleep_range (10000 ,12000 ); +if ((readl (USB_PORTSC ) &PORTSC_LS ) == +PORTSC_LS ) +if (ui->usb_connected) + ui->usb_connected (USB_CHG_WALL ); + ui->state =USB_STATE_ONLINE ;usb_do_work_check_vbus (ui); }
@@ -1790,6 +1806,7 @@ static int msm72k_probe(struct platform_device *pdev)struct msm_hsusb_platform_data *pdata = pdev->dev.platform_data; ui->phy_reset = pdata->phy_reset; ui->phy_init_seq = pdata->phy_init_seq; + ui->usb_connected = pdata->usb_connected; } irq =platform_get_irq (pdev,0 );
include/linux/usb/msm_hsusb.h +16 -0
@@ -20,11 +20,26 @@#include <linux/types.h> /** +* USB charger types. +* +* USB_CHG_NONE Charger is not connected. +* USB_CHG_HOST Connected to Host PC. +* USB_CHG_WALL Connected to Wall charger. +* +*/ +enum usb_chg_type { +USB_CHG_NONE =0 , +USB_CHG_HOST , +USB_CHG_WALL , +}; + +/** * struct msm_hsusb_platform_data - platform device data * for msm72k_udc driver. * @phy_reset: assert followed by de-assert of PHY. * @hw_reset: if enable is true, assert link otherwise * de-assert link. +* @usb_connected: callback function to receive usb charger type notifications. * @phy_init_seq: PHY configuration sequence. val, reg pairs * terminated by -1. *
@@ -32,6 +47,7 @@struct msm_hsusb_platform_data {void (*phy_reset)(void );void (*hw_reset)(bool enable); +void (*usb_connected)(int );int *phy_init_seq; };
Signature · 1 line
1.7.1