Merge a backport of the following 82 commits from the 3.2 kernel. commit10f1551c50Author: Yu Xu <yuxu@marvell.com> Date: Sat Dec 10 00:03:33 2011 +0800 usb: gadget: storage: release superspeed descriptors. Release superspeed mass storage descriptors memory when the function is unbind. Signed-off-by: Yu Xu <yuxu@marvell.com> Acked-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/f_mass_storage.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) commit1d6d304680Author: Felipe Balbi <balbi@ti.com> Date: Mon Oct 3 16:39:30 2011 +0300 usb: gadget: core: fix bug when removing gadget drivers usb_gadget_disconnect() is responsible of removing data pullups. Before doing that we must, first, tell gadget driver we're disconnecting (by calling disconnect method on gadget driver structure), unbind the gadget driver and stop the controller. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/udc-core.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) commit145cbade27Author: Felipe Balbi <balbi@ti.com> Date: Wed Aug 3 13:33:27 2011 +0200 usb: gadget: storage: add superspeed support this patch adds superspeed descriptors for the storage gadgets. Acked-by: Michal Nazarewicz <mina86@mina86.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Felipe Balbi <balbi@ti.com> [idos@codeaurora.org: Conflicts: drivers/usb/gadget/storage_common.c] Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/f_mass_storage.c | 22 ++++++ drivers/usb/gadget/file_storage.c | 59 +++++++++++++--- drivers/usb/gadget/mass_storage.c | 2 +- drivers/usb/gadget/storage_common.c | 127 +++++++++++++++++++++++++++++++++++ 4 files changed, 199 insertions(+), 11 deletions(-) commitb0c3e7fb4dAuthor: Felipe Balbi <balbi@ti.com> Date: Mon Oct 10 09:43:44 2011 +0300 usb: gadget: fix typo for default U1/U2 exit latencies s/DEFULT/DEFAULT/, no functional changes. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/composite.c | 4 ++-- include/linux/usb/gadget.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) commit834e066cffAuthor: Paul Zimmerman <Paul.Zimmerman@synopsys.com> Date: Fri Sep 30 15:26:06 2011 -0700 usb: gadget: storage: fix mass storage gadgets to work with Synopsys UDC The Synopsys USB device controller requires all OUT transfer request lengths to be aligned to max packet size. The mass storage gadgets do not meet this requirement for Super Speed. The gadgets already have a function which performs this alignment for CBW packets, so use it for data packets too. The alternative would be to implement bounce buffers in the DWC3 driver, but that could have a significant impact on performance. This version is based upon a more-correct patch written by Alan Stern. Signed-off-by: Paul Zimmerman <paulz@synopsys.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/f_mass_storage.c | 18 +++++++++--------- drivers/usb/gadget/file_storage.c | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) commit7295baf179Author: Alan Stern <stern@rowland.harvard.edu> Date: Thu Aug 18 20:29:00 2011 +0200 USB: gadget: storage: remove alignment assumption This patch (as1481) fixes a problem affecting g_file_storage and g_mass_storage when running at SuperSpeed. The two drivers currently assume that the bulk-out maxpacket size can evenly divide the SCSI block size, which is 512 bytes. But SuperSpeed bulk endpoints have a maxpacket size of 1024, so the assumption is no longer true. This patch removes that assumption from the drivers, by getting rid of a small optimization (they try to align VFS reads and writes on page cache boundaries). If a command's starting logical block address is 512 bytes below the end of a page, it's not okay to issue a USB command for just those 512 bytes when the maxpacket size is 1024 -- it would result in either babble (for an OUT transfer) or a short packet (for an IN transfer). Also, for backward compatibility, the test for writes extending beyond the end of the backing storage has to be changed. If the host tries to do this, we should accept the data that fits in the backing storage and ignore the rest. Because the storage's end may not align with a USB packet boundary, this means we may have to accept a USB OUT transfer that extends beyond the end of the storage and then write out only the part of the data that fits. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Acked-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Felipe Balbi <balbi@ti.com> [idos@codeaurora.org: Conflicts: drivers/usb/gadget/f_mass_storage.c Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/f_mass_storage.c | 64 ++++++++++++--------------------- drivers/usb/gadget/file_storage.c | 67 ++++++++++++++--------------------- 2 files changed, 50 insertions(+), 81 deletions(-) commit9e5eb17594Author: Peiyu Li <peiyu.li@csr.com> Date: Wed Aug 17 22:52:59 2011 -0700 usb: gadget: storage: adapt logic block size to bound block devices Now the mass storage driver has fixed logic block size of 512 bytes. The mass storage gadget read/write bound devices only through VFS, so the bottom level devices actually are just RAW devices to the driver and connected PC. As a RAW, hosts can always format, read and write it right in 512 bytes logic block and don't care about the actual logic block size of devices bound to the gadget. But if we want to share the bound block device partition between target board and PC, in case the logic block size of the bound block device is 4KB, we execute the following steps: 1. connect a board with mass storage gadget to PC(the board has set one partition of on-board block device as file name of the mass storage) 2. PC format the mass storage to VFAT by default logic block size and read/write it 3. disconnect boards from PC 4. target board mount the partition as VFAT Step 4 will fail since kernel on target thinks the logic block size of the bound partition as 4KB. A typical error is "FAT: logical sector size too small for device (logical sector size = 512)" If we execute opposite steps: 1. format the partition to VFAT on target board and read/write this partition 2. connect the board to Windows PC as usb mass storage gadget, windows will think the disk is not formatted So the conclusion is that only as a gadget, the mass storage driver has no any problem. But being shared VFAT or other filesystem on PC and target board, it will fail. This patch adapts logic block size to bound block devices and fix the issue. Cc: Michal Nazarewicz <mina86@mina86.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Peiyu Li <peiyu.li@csr.com> Signed-off-by: Xianglong Du <xianglong.du@csr.com> Signed-off-by: Huayi Li <huayi.li@csr.com> Signed-off-by: Barry Song <Baohua.Song@csr.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/f_mass_storage.c | 63 ++++++++++++++++++++-------------- drivers/usb/gadget/file_storage.c | 50 +++++++++++++-------------- drivers/usb/gadget/storage_common.c | 23 ++++++++++--- 3 files changed, 79 insertions(+), 57 deletions(-) commit26bba694a4Author: Felipe Balbi <balbi@ti.com> Date: Mon Dec 19 13:45:01 2011 +0200 usb: gadget: epautoconf: do not change number of streams We should not change gadget driver's descriptors just because we think it's right to do so. There are several of reasons which would support this statement but it suffices to say that this was probably never tested because it updates bmAttributes without asking the driver if it's ok to do so. This means that e.g. on UASP gadget it would enable stream support even for the command endpoint which must not have stream support enabled. In fact, this change is fixing the bug introduced by commit a59d6b9 (usb: gadget: add streams support to the gadget framework) which was caught when testing UASP gadget with dwc3 driver. Cc: Tatyana Brokhman <tlinder@codeaurora.org> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/epautoconf.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-) commitfb5591ebf5Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Thu Jun 23 14:26:15 2011 +0200 usb: gadget: udc-core: add "new-style" registration interface udc_start() should only trigger the internal state machine and make minimal house keeping. Before that call udc-core calls the bind() callback and after the callback the pullup(). udc_stop() is simillar, udc-core calls pullup(), unbind() and finally udc_stop(). Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/udc-core.c | 75 ++++++++++++++++++++++++++++++++++++++-- include/linux/usb/gadget.h | 6 +++ 2 files changed, 77 insertions(+), 4 deletions(-) commit0d0c240facAuthor: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Thu Jun 23 14:26:11 2011 +0200 usb: gadget: defer setting maxpacket till ->setup() maxpacket is set by the udc driver for ep0 very early. This value is copied by the function gadget used later for the USB_DT_DEVICE and USB_DT_DEVICE_QUALIFIER query. This seems to work fine so far. For USB3 we need set a different value here. In SS speed it is 2^x with x=9 and in HS we set something <= 64. If the UDC starts in SS and continues in HS after the cable has been plugged it will report a too small value. There setting of this value is defered and taken automaticly from the ep0 pointer where the UDC driver can update it according to the speed it detected _after_ a cable has been plugged. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/composite.c | 3 +-- drivers/usb/gadget/dbgp.c | 2 +- drivers/usb/gadget/file_storage.c | 10 ++++++---- drivers/usb/gadget/gmidi.c | 3 +-- drivers/usb/gadget/inode.c | 5 ++--- drivers/usb/gadget/printer.c | 14 +++++++++----- 6 files changed, 20 insertions(+), 17 deletions(-) commitbc2aa11468Author: Tatyana Brokhman <tlinder@codeaurora.org> Date: Wed Jun 29 16:41:50 2011 +0300 usb: gadget: add SuperSpeed support to the Gadget Framework SuperSpeed USB has defined a new descriptor, called the Binary Device Object Store (BOS) Descriptor. It has also changed a bit the definition of SET_FEATURE and GET_STATUS requests to add USB3-specific details. This patch implements both changes to the Composite Gadget Framework. [ balbi@ti.com : slight changes to commit log fixed a compile error on ARM ] Signed-off-by: Tatyana Brokhman <tlinder@codeaurora.org> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/Kconfig | 6 + drivers/usb/gadget/composite.c | 257 ++++++++++++++++++++++++++++++++++++--- drivers/usb/gadget/epautoconf.c | 6 +- include/linux/usb/composite.h | 14 ++ include/linux/usb/gadget.h | 31 +++++ 5 files changed, 293 insertions(+), 21 deletions(-) commit3ba28906aeAuthor: Tatyana Brokhman <tlinder@codeaurora.org> Date: Wed Jun 29 16:41:49 2011 +0300 usb: gadget: add max_speed to usb_composite_driver This field is used by the Gadget drivers to specify the maximum speed they support, meaning: the maximum speed they can provide descriptors for. The driver speed will be set in consideration of this value. [ balbi@ti.com : dropped the ifdeffery ] Signed-off-by: Tatyana Brokhman <tlinder@codeaurora.org> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> [idos@codeaurora.org: added max_speed also to android.c] Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/android.c | 1 + drivers/usb/gadget/audio.c | 1 + drivers/usb/gadget/cdc2.c | 1 + drivers/usb/gadget/composite.c | 2 ++ drivers/usb/gadget/ether.c | 1 + drivers/usb/gadget/g_ffs.c | 1 + drivers/usb/gadget/hid.c | 1 + drivers/usb/gadget/mass_storage.c | 1 + drivers/usb/gadget/multi.c | 1 + drivers/usb/gadget/ncm.c | 1 + drivers/usb/gadget/nokia.c | 1 + drivers/usb/gadget/serial.c | 1 + drivers/usb/gadget/webcam.c | 1 + drivers/usb/gadget/zero.c | 1 + include/linux/usb/composite.h | 2 ++ 15 files changed, 17 insertions(+), 0 deletions(-) commit081412dc44Author: Tatyana Brokhman <tlinder@codeaurora.org> Date: Tue Jun 28 16:33:53 2011 +0300 usb: gadget: add streams support to the gadget framework This patch defines necessary fields to support streaming for USB3.0. It implements a new function, called usb_ep_autoconfig_ss(), to be used instead of the existing usb_ep_autoconfig() when working in SuperSpeed mode and there is a need to search for an endpoint according to the number of required streams. [ balbi@ti.com : slight changes to commit log ] Signed-off-by: Maya Erez <merez@codeaurora.org> Signed-off-by: Tatyana Brokhman <tlinder@codeaurora.org> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/epautoconf.c | 125 +++++++++++++++++++++++++++++++-------- include/linux/usb/gadget.h | 13 ++++ 2 files changed, 113 insertions(+), 25 deletions(-) commit5ef53d97a1Author: Tatyana Brokhman <tlinder@codeaurora.org> Date: Tue Jun 28 16:33:52 2011 +0300 usb: gadget: coding style fix fix the coding style of a few switches on the gadget framework. [ balbi@ti.com : add a commit log ] Signed-off-by: Tatyana Brokhman <tlinder@codeaurora.org> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/composite.c | 16 ++++++++++--- drivers/usb/gadget/dummy_hcd.c | 48 ++++++++++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 16 deletions(-) commit31ac352192Author: Tatyana Brokhman <tlinder@codeaurora.org> Date: Tue Jun 28 15:33:50 2011 +0200 usb: gadget: use config_ep_by_speed() instead of ep_choose() Remove obsolete functions: 1. ep_choose() 2. usb_find_endpoint() Signed-off-by: Tatyana Brokhman <tlinder@codeaurora.org> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> [idos@codeaurora.org: Changed also the following files to comply with this commit: f_accessory.c,f_adb.c,f_diag.c,f_mtp.c, f_rmnet.c,f_rmnet_sdio,f_rmnet_smd,f_rmnet_smd_sdio,f_serial.f_ccid.c. Also merged a patch in f_serial.c for checking return value of config_ep_by_speed, see "usb: gadget: fix g_serial regression". Also fix a bug in ci13xxx_udc. Since f_serial is now checking if the endpoint descriptors are null in the set_alt function, need to set them to null on ep_disable in case of cable disconnect. Since the ep descriptor was inserted to struct usb_ep in "usb: gadget: add usb_endpoint_descriptor to struct usb_ep", also set mEp->ep.desc to NULL. I have upstream this to the community, please see "usb: gadget: Clear usb_endpoint_descriptor inside the struct usb_ep" in the latest linux kernel.] Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/ci13xxx_udc.c | 1 + drivers/usb/gadget/config.c | 26 ------------- drivers/usb/gadget/f_accessory.c | 30 +++++++++++----- drivers/usb/gadget/f_acm.c | 46 +++++++----------------- drivers/usb/gadget/f_adb.c | 30 +++++++++++---- drivers/usb/gadget/f_ccid.c | 54 +++++++++++----------------- drivers/usb/gadget/f_diag.c | 13 ++++--- drivers/usb/gadget/f_ecm.c | 45 +++++++---------------- drivers/usb/gadget/f_eem.c | 32 +++++------------ drivers/usb/gadget/f_hid.c | 19 +++------- drivers/usb/gadget/f_loopback.c | 11 ++++-- drivers/usb/gadget/f_mass_storage.c | 46 ++++++++++-------------- drivers/usb/gadget/f_mtp.c | 30 +++++++++++---- drivers/usb/gadget/f_ncm.c | 49 ++++++++------------------ drivers/usb/gadget/f_obex.c | 32 +++++------------ drivers/usb/gadget/f_phonet.c | 12 +++--- drivers/usb/gadget/f_rmnet.c | 48 ++++++++----------------- drivers/usb/gadget/f_rmnet_sdio.c | 62 ++++++++++++++++++++++++++------ drivers/usb/gadget/f_rmnet_smd.c | 38 +++++++++++++++----- drivers/usb/gadget/f_rmnet_smd_sdio.c | 63 ++++++++++++++++++++++++++------ drivers/usb/gadget/f_rndis.c | 46 +++++++----------------- drivers/usb/gadget/f_serial.c | 53 +++++++++------------------- drivers/usb/gadget/f_sourcesink.c | 8 +++- drivers/usb/gadget/f_subset.c | 29 +++------------ drivers/usb/gadget/file_storage.c | 12 ++++++ drivers/usb/gadget/storage_common.c | 11 ------ include/linux/usb/composite.h | 15 -------- include/linux/usb/gadget.h | 6 --- 28 files changed, 392 insertions(+), 475 deletions(-) commitcf64ce4954Author: Tatyana Brokhman <tlinder@codeaurora.org> Date: Tue Jun 28 16:33:49 2011 +0300 usb: gadget: configure endpoint according to gadget speed Add config_ep_by_speed() to configure the endpoint according to the gadget speed. Using this function will spare the FDs from handling the endpoint chosen descriptor. Signed-off-by: Tatyana Brokhman <tlinder@codeaurora.org> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/composite.c | 85 +++++++++++++++++++++++++++++++++++++++ drivers/usb/gadget/epautoconf.c | 1 + include/linux/usb/composite.h | 3 + include/linux/usb/gadget.h | 3 + 4 files changed, 92 insertions(+), 0 deletions(-) commitcf709c115cAuthor: Tatyana Brokhman <tlinder@codeaurora.org> Date: Tue Jun 28 16:33:48 2011 +0300 usb: gadget: add usb_endpoint_descriptor to struct usb_ep Change usb_ep_enable() prototype to use endpoint descriptor from usb_ep. This optimization spares the FDs from saving the endpoint chosen descriptor. This optimization is not full though. To fully exploit this change, one needs to update all the UDCs as well since in the current implementation each of them saves the endpoint descriptor in it's internal (and extended) endpoint structure. Signed-off-by: Tatyana Brokhman <tlinder@codeaurora.org> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> [idos@codeaurora.org: Added more changes for the following files since API break with msm code tree: ci13xxx_udc.c,f_accessory,f_adb, f_diag,f_mtp,f_rmnet,f_rmnet_sdio,f_rmnet_smd, f_rmnet_smd_sdio,u_bam.c, u_sdio.c,u_rmnet.h,u_sdio.c,u_smd.c,f_ccid.c,u_data_hsic.c] Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/ci13xxx_udc.c | 6 ++++-- drivers/usb/gadget/dbgp.c | 8 +++++--- drivers/usb/gadget/f_accessory.c | 16 ++++++++++------ drivers/usb/gadget/f_acm.c | 9 ++++----- drivers/usb/gadget/f_adb.c | 14 ++++++++------ drivers/usb/gadget/f_audio.c | 5 ++--- drivers/usb/gadget/f_ccid.c | 15 ++++++--------- drivers/usb/gadget/f_diag.c | 12 +++++------- drivers/usb/gadget/f_ecm.c | 17 ++++++++--------- drivers/usb/gadget/f_eem.c | 10 +++++----- drivers/usb/gadget/f_fs.c | 3 ++- drivers/usb/gadget/f_hid.c | 5 ++--- drivers/usb/gadget/f_loopback.c | 14 ++++++-------- drivers/usb/gadget/f_mass_storage.c | 3 ++- drivers/usb/gadget/f_mtp.c | 17 ++++++++++------- drivers/usb/gadget/f_ncm.c | 17 ++++++++--------- drivers/usb/gadget/f_obex.c | 6 +++--- drivers/usb/gadget/f_phonet.c | 9 ++++----- drivers/usb/gadget/f_rmnet.c | 9 ++++----- drivers/usb/gadget/f_rmnet_sdio.c | 15 +++++++++------ drivers/usb/gadget/f_rmnet_smd.c | 15 +++++++++------ drivers/usb/gadget/f_rmnet_smd_sdio.c | 15 +++++++++------ drivers/usb/gadget/f_rndis.c | 15 +++++++-------- drivers/usb/gadget/f_serial.c | 9 ++++----- drivers/usb/gadget/f_sourcesink.c | 10 ++++------ drivers/usb/gadget/f_subset.c | 8 ++++---- drivers/usb/gadget/f_uvc.c | 6 ++++-- drivers/usb/gadget/file_storage.c | 3 ++- drivers/usb/gadget/gmidi.c | 6 ++++-- drivers/usb/gadget/inode.c | 6 ++++-- drivers/usb/gadget/printer.c | 26 ++++++++++++++------------ drivers/usb/gadget/u_bam.c | 8 ++++---- drivers/usb/gadget/u_data_hsic.c | 10 ++-------- drivers/usb/gadget/u_ether.c | 12 ++++++------ drivers/usb/gadget/u_ether.h | 4 ---- drivers/usb/gadget/u_rmnet.h | 2 -- drivers/usb/gadget/u_sdio.c | 4 ++-- drivers/usb/gadget/u_serial.c | 4 ++-- drivers/usb/gadget/u_serial.h | 2 -- drivers/usb/gadget/u_smd.c | 4 ++-- include/linux/usb/gadget.h | 16 +++++++--------- 41 files changed, 197 insertions(+), 198 deletions(-) commitd23607a2ebAuthor: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Tue Jun 28 16:33:47 2011 +0300 usb: gadget: convert all users to the new udc infrastructure peripheral drivers are using usb_add_gadget()/usb_del_gadget() to register/unregister to the udc-core. The udc-core will take the first available gadget driver and attach function driver which is calling usb_gadget_register_driver(). This is the same behaviour we have right now. Only dummy_hcd was tested, the others were compiled tested. Cc: Alan Stern <stern@rowland.harvard.edu> Cc: Anton Tikhomirov <av.tikhomirov@samsung.com> Cc: Ben Dooks <ben-linux@fluff.org> Cc: Dan Carpenter <error27@gmail.com> Cc: Darius Augulis <augulis.darius@gmail.com> Cc: Eric Miao <eric.y.miao@gmail.com> Cc: Jingoo Han <jg1.han@samsung.com> Cc: Kukjin Kim <kgene.kim@samsung.com> Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Cc: Li Yang <leoli@freescale.com> Cc: Michael Hennerich <michael.hennerich@analog.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Cc: Nicolas Ferre <nicolas.ferre@atmel.com> Cc: Pavankumar Kondeti <pkondeti@codeaurora.org> Cc: Roy Huang <roy.huang@analog.com> Cc: Russell King <linux@arm.linux.org.uk> Cc: Toshiharu Okada <toshiharu-linux@dsn.okisemi.com> Cc: Xiaochen Shen <xiaochen.shen@intel.com> Cc: Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> Cc: Yuan-Hsin Chen <yhchen@faraday-tech.com> Cc: cxie4 <cxie4@marvell.com> Cc: linux-geode@lists.infradead.org Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> [idos@codeaurora.org: Conflicts: drivers/usb/gadget/ci13xxx_udc.c msm72k_udc.c: This driver is not exists in Linux community,so fix this one too. cyasgadget.c: combine other patch from the community ("convert cyasgadget to new udc core") into this commit. Removed the #if 0 block that was in the community version and fix the cause problem, because of which it was under #if 0 block] Signed-off-by: Ido Shayevitz <idos@codeaurora.org> .../staging/westbridge/astoria/gadget/cyasgadget.c | 26 ++++++++++++++-- drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/amd5536udc.c | 18 ++++++++--- drivers/usb/gadget/at91_udc.c | 20 +++++++++--- drivers/usb/gadget/atmel_usba_udc.c | 26 ++++++++++++++-- drivers/usb/gadget/ci13xxx_udc.c | 30 ++++++++++++++----- drivers/usb/gadget/dummy_hcd.c | 31 +++++++++++++------ drivers/usb/gadget/fsl_qe_udc.c | 20 ++++++++++-- drivers/usb/gadget/fsl_udc_core.c | 20 ++++++++++-- drivers/usb/gadget/fusb300_udc.c | 15 +++++++-- drivers/usb/gadget/goku_udc.c | 19 +++++++++--- drivers/usb/gadget/imx_udc.c | 20 +++++++++--- drivers/usb/gadget/langwell_udc.c | 20 ++++++++---- drivers/usb/gadget/m66592-udc.c | 17 ++++++++-- drivers/usb/gadget/msm72k_udc.c | 30 ++++++++++++++++--- drivers/usb/gadget/mv_udc_core.c | 19 +++++++---- drivers/usb/gadget/net2280.c | 18 ++++++++--- drivers/usb/gadget/omap_udc.c | 22 +++++++++++--- drivers/usb/gadget/pch_udc.c | 16 +++++++-- drivers/usb/gadget/pxa25x_udc.c | 19 ++++++++---- drivers/usb/gadget/pxa27x_udc.c | 23 ++++++++++---- drivers/usb/gadget/r8a66597-udc.c | 15 +++++++-- drivers/usb/gadget/s3c-hsotg.c | 19 +++++++++-- drivers/usb/gadget/s3c-hsudc.c | 16 +++++++-- drivers/usb/gadget/s3c2410_udc.c | 29 +++++++++++------- drivers/usb/musb/musb_gadget.c | 23 +++++++++++--- drivers/usb/renesas_usbhs/mod_gadget.c | 20 +++++++++--- 27 files changed, 411 insertions(+), 141 deletions(-) commit5177504241Author: Felipe Balbi <balbi@ti.com> Date: Tue Jun 28 16:33:46 2011 +0300 usb: gadget: introduce UDC Class this class will be used to abstract away several of the duplicated operations scattered among the USB gadget controller drivers. Later, we can add an atomic notifier to tell interested drivers about what's happening with the controller. Notifications such as suspend, resume, enumerated, etc. will be useful, at a minimum, for implementing usb charger detection. As part of the converting process usb_gadget_probe_driver() is no longer part of each udc but pushed into the ->stap() callback. The same for his couterpart. The core is currently set explicit to 'n'. It will be changed to 'y' once all users are converted since it provides functions which clash with other drivers. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Acked-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/udc-core.c | 418 +++++++++++++++++++++++++++++++++++++++++ include/linux/usb/gadget.h | 7 + 2 files changed, 425 insertions(+), 0 deletions(-) commit9bcc83f456Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Fri Aug 19 18:10:56 2011 +0300 usb: ch9: add function defines from ch9, USB 3.0 spec not to confuse with Table 9-7 in USB 2.0 spec Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> include/linux/usb/ch9.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) commit0be99a24dbAuthor: Paul Gortmaker <paul.gortmaker@windriver.com> Date: Fri Sep 30 18:08:59 2011 -0400 usb: Add module.h to various dwc3 drivers These files uses the full set of MODULE_ macros and so need to include module.h directly. Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.c | 1 + drivers/usb/dwc3/dwc3-omap.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-) commitf208a8f461Author: Felipe Balbi <balbi@ti.com> Date: Fri Sep 30 10:58:51 2011 +0300 usb: dwc3: convert structures into bitshifts our parameter structures need to be written to HW, so instead of assuming little endian, we convert those into bit shifts. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/ep0.c | 6 +- drivers/usb/dwc3/gadget.c | 40 ++++++------- drivers/usb/dwc3/gadget.h | 139 +++++++++------------------------------------ 3 files changed, 48 insertions(+), 137 deletions(-) commitb141b8cd02Author: Felipe Balbi <balbi@ti.com> Date: Fri Sep 30 10:58:50 2011 +0300 usb: dwc3: gadget: allow clock gating to work The dwc3 core has internal clock gating support. Let's allow that to happen by clearing the disable bit in GCTL register. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 6 ++++++ drivers/usb/dwc3/gadget.c | 8 ++++++++ 2 files changed, 14 insertions(+), 0 deletions(-) commitb333f87fccAuthor: Felipe Balbi <balbi@ti.com> Date: Fri Sep 30 10:58:49 2011 +0300 usb: dwc3: core: cache GHWPARAMS* registers cache the contents of GHWPARAMS* registers in our device structure for easy access. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) commitd8e9f2a2f0Author: Felipe Balbi <balbi@ti.com> Date: Fri Sep 30 10:58:48 2011 +0300 usb: dwc3: add struct dwc3_hwparams That structure will hold a copy of readonly GHWPARAMS* registers for ease accessing by the driver. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) commit2aadc55ef7Author: Felipe Balbi <balbi@ti.com> Date: Fri Sep 30 10:58:47 2011 +0300 usb: dwc3: gadget: implement streams support The following patch adds support for streams to dwc3 driver. While at that, also fix one small issue on endpoint disable where we should clear all flags not only ENABLED. Reviewied-by: Paul Zimmerman <paulz@synopsys.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> Documentation/usb/dwc3.txt | 8 -------- drivers/usb/dwc3/core.h | 6 ++++++ drivers/usb/dwc3/gadget.c | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 12 deletions(-) commit92366a9b25Author: Felipe Balbi <balbi@ti.com> Date: Fri Sep 30 10:58:46 2011 +0300 usb: dwc3: gadget: add support for Bursts We already have the value from gadget drivers, just need to pass it to our controller. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> [idos@codeaurora.org: Integrate in this commit also the change "USB: use usb_endpoint_maxp() instead of le16_to_cpu()" 29cc88979a8818cd8c5019426e945aed118b400e from Linux kernel 3.1. The reason why this change was not cherry-picked separately is because I wanted to reduce impact on msm code tree, and only change dwc3 driver.] Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) commit4f5db5cf5bAuthor: kuninori.morimoto.gx@renesas.com <kuninori.morimoto.gx@renesas.com> Date: Mon Jul 25 00:39:30 2011 -0700 usb: add usb_endpoint_maxp() macro Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> [idos@codeaurora.org: use __le16_to_cpu instead of le16_to_cpu] Signed-off-by: Ido Shayevitz <idos@codeaurora.org> include/linux/usb/ch9.h | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) commitbba939f019Author: Paul Zimmerman <Paul.Zimmerman@synopsys.com> Date: Fri Sep 30 10:58:45 2011 +0300 usb: dwc3: gadget: fix DMA offset calculation Fix offset calculation in dwc3_trb_dma_offset() Signed-off-by: Paul Zimmerman <paulz@synopsys.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) commit4281539e1dAuthor: Paul Zimmerman <Paul.Zimmerman@synopsys.com> Date: Fri Sep 30 10:58:44 2011 +0300 usb: dwc3: gadget: make DWC3_EP_WEDGE do the right thing This makes DWC3_EP_WEDGE do the right thing, which is prevent DWC3_EP_WEDGE from ever being cleared by a ClearFeature(HALT) command. [ balbi@ti.com : allowed set_wedge to send SetHalt command to controller ] Signed-off-by: Paul Zimmerman <paulz@synopsys.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) commitdf7a63dc19Author: Paul Zimmerman <Paul.Zimmerman@synopsys.com> Date: Fri Sep 30 10:58:43 2011 +0300 usb: dwc3: gadget: driver should not wait for RxFIFO to drain An older version of the databook said to wait for the FIFO to drain, but that has been removed from the newer databooks. Waiting for RxFIFO to drain caused problems when testing against one of the host controllers available in the market. After talking to one of the RTL engineers, he stated that we should _not_ wait for RxFIFO to drain. Signed-off-by: Paul Zimmerman <paulz@synopsys.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 19 ------------------- 1 files changed, 0 insertions(+), 19 deletions(-) commita6544d0e1cAuthor: Paul Zimmerman <Paul.Zimmerman@synopsys.com> Date: Fri Sep 30 10:58:42 2011 +0300 usb: dwc3: gadget: fix DEPSTARTCFG for non-EP0 EPs DEPSTARTCFG for non-EP0 EPs must only be sent once per config [ balbi@ti.com : changed config_start to start_config_issued ] Signed-off-by: Paul Zimmerman <paulz@synopsys.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/ep0.c | 1 + drivers/usb/dwc3/gadget.c | 10 +++++++++- 3 files changed, 12 insertions(+), 1 deletions(-) commit9342a6f8b0Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Fri Sep 30 10:58:41 2011 +0300 usb: dwc: remove "All rights reserved" statement. Some people think that this line is not compatible with the GPL. The statement was required due to the Buenos Aires Convention and is now deprecated. I remove it because it is said that it is pointless nowdays. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.c | 1 - drivers/usb/dwc3/core.h | 1 - drivers/usb/dwc3/debug.h | 1 - drivers/usb/dwc3/debugfs.c | 1 - drivers/usb/dwc3/dwc3-omap.c | 1 - drivers/usb/dwc3/dwc3-pci.c | 1 - drivers/usb/dwc3/ep0.c | 1 - drivers/usb/dwc3/gadget.c | 1 - drivers/usb/dwc3/gadget.h | 1 - drivers/usb/dwc3/io.h | 1 - 10 files changed, 0 insertions(+), 10 deletions(-) commitf8336a2d5bAuthor: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Fri Sep 30 10:58:40 2011 +0300 usb: dwc3: ep0: fix debug output Use "ep0in" and "ep0out" instead "ep1in" and "ep0out" which is confusing and not consistent with the remaining output. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/ep0.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) commit9b580c9667Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Fri Sep 30 10:58:39 2011 +0300 usb: dwc3: ep0: remove second giveback in error case We already give requests back in dwc3_ep0_stall_and_restart() so doing it again here will most likely corrupt the list. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/ep0.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) commitb55ee45356Author: Felipe Balbi <balbi@ti.com> Date: Fri Sep 30 10:58:38 2011 +0300 usb: dwc3: ep0: fix debug message The way it was before was really meaningless. Now it looks saner. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/ep0.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) commit0788d7b5e6Author: Felipe Balbi <balbi@ti.com> Date: Fri Sep 30 10:58:37 2011 +0300 usb: dwc3: ep0: ignore direction on 2-stage transfer We don't need to care about direction on a two stage transfer. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/ep0.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) commitb7139d3e59Author: Felipe Balbi <balbi@ti.com> Date: Fri Sep 30 10:58:36 2011 +0300 usb: dwc3: ep0: Make USB30CV happy with SetAddress According to USB 3.0 Specification, a SetAddress() while device is in Configured State has an unspecified behavior (see Section 9.4.6). Still USB30CV wasn't happy with my Stall reply. To make that thing happy, just accept the SetAddress() always. No problems have been observed thus far. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/ep0.c | 31 +++++++++---------------------- 1 files changed, 9 insertions(+), 22 deletions(-) commit6edd5bdb3bAuthor: Felipe Balbi <balbi@ti.com> Date: Thu Sep 8 21:18:47 2011 +0300 usb: dwc3: gadget: improve debug on link state change It's useful to know which states core is going through, as it might help us figure out misbehavior on specific link states. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) commit29561f1886Author: Felipe Balbi <balbi@ti.com> Date: Tue Sep 6 10:56:51 2011 +0300 usb: dwc3: omap: set idle and standby modes For now, let's disable IDLE and STANDBY transitions until we have a real HW to validate against. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/dwc3-omap.c | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) commitecc99439beAuthor: Felipe Balbi <balbi@ti.com> Date: Thu Sep 8 18:27:33 2011 +0300 usb: dwc3: ep0: introduce ep0_expect_in flag This flag will tell us which direction we're expecting on the next (data or status) phase. It will help us catching errors of host going crazy and requesting data of the wrong direction. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/ep0.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-) commit4454f03ef0Author: Felipe Balbi <balbi@ti.com> Date: Thu Sep 8 18:17:12 2011 +0300 usb: dwc3: ep0: giveback requests on stall_and_restart if we don't, the list will be busy forever. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/ep0.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) commitd3ba9a9d63Author: Felipe Balbi <balbi@ti.com> Date: Thu Sep 8 18:16:21 2011 +0300 usb: dwc3: gadget: drop the useless dma_sync_single* calls if req->dma isn't DMA_ADDR_INVALID it means gadget driver mapped the request or allocated from coherent, so it's unnecessary to do anything. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 9 --------- 1 files changed, 0 insertions(+), 9 deletions(-) commitd195b32c82Author: Felipe Balbi <balbi@ti.com> Date: Thu Sep 8 17:42:11 2011 +0300 usb: dwc3: gadget: fix GCTL programming ensure a few bits are cleared before enabling what we need. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 9 +++------ 1 files changed, 3 insertions(+), 6 deletions(-) commite207db6804Author: Felipe Balbi <balbi@ti.com> Date: Thu Sep 8 17:41:00 2011 +0300 usb: dwc3: define ScaleDown macro helper We must ensure that those bits aren't set as they should only be used in simulation. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) commit18b26f81d3Author: Felipe Balbi <balbi@ti.com> Date: Thu Sep 8 17:39:59 2011 +0300 usb: dwc3: Fix definition of DWC3_GCTL_U2RSTECN that should be 1 << 16, not 16. Caused so many problems and we never caught it before. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) commit4ae8e1c5f7Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Wed Aug 31 17:12:02 2011 +0200 usb: dwc3: gadget: do not map/unmap ZLP transfers If the gadget drivers sends a ZLP we are trying to map this this request which does not work on all implementations. So we simply skip mapping it. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) commit5248ed14acAuthor: Felipe Balbi <balbi@ti.com> Date: Tue Sep 6 12:00:39 2011 +0300 usb: dwc3: omap: fix IRQ handling In order to ACK the IRQ we must write back to the same register the bits we read. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/dwc3-omap.c | 39 ++++++++++++--------------------------- 1 files changed, 12 insertions(+), 27 deletions(-) commit6e8585e672Author: Felipe Balbi <balbi@ti.com> Date: Tue Sep 6 10:57:41 2011 +0300 usb: dwc3: omap: change IRQ name to dwc3-omap dwc3-wrapper can be used by any other wrapper, using dwc3-omap makes it clear that we're running on OMAP SoC. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/dwc3-omap.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) commit8ff9be9a57Author: Felipe Balbi <balbi@ti.com> Date: Mon Sep 5 13:37:28 2011 +0300 usb: dwc3: add module.h to dwc3-omap.c and core.c We need that header because of THIS_MODULE. Reported-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.c | 1 + drivers/usb/dwc3/dwc3-omap.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-) commit6f33e1af1aAuthor: Felipe Balbi <balbi@ti.com> Date: Thu Sep 1 22:26:25 2011 +0300 usb: dwc3: omap: distinguish between SW and HW modes The OMAP wrapper allows us to either control internal OTG signals via SW or HW. Different boards might wish to use one or the other mode of operation. Let's have have that information passed via platform_data for now. After DT conversion is finished for OMAP, we can easily convert this to a DT attribute. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/dwc3-omap.c | 22 ++++++++++++++ include/linux/platform_data/dwc3-omap.h | 47 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 0 deletions(-) commit201d9a02eeAuthor: Felipe Balbi <balbi@ti.com> Date: Thu Sep 1 18:33:43 2011 +0300 usb: dwc3: omap: drop DEV_PM_OPS for now We need to have actual HW in order to implement and test that part of the code anyway. Until then it's best to remove it. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/dwc3-omap.c | 41 ----------------------------------------- 1 files changed, 0 insertions(+), 41 deletions(-) commitc6aa9939cbAuthor: Felipe Balbi <balbi@ti.com> Date: Thu Sep 1 18:22:01 2011 +0300 usb: dwc3: omap: use the macro we already have trivial patch, no functional changes. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/dwc3-omap.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) commite4b324671dAuthor: Felipe Balbi <balbi@ti.com> Date: Thu Sep 1 14:52:52 2011 +0300 usb: dwc3: omap: do not enable DMA Disable Clear IRQ Otherwise that IRQ will trigger forever. It's quite unnecessary. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/dwc3-omap.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) commitc93695d156Author: Felipe Balbi <balbi@ti.com> Date: Thu Sep 1 14:46:16 2011 +0300 usb: dwc3: omap: fix dev_dbg() calls dev_dbg() macro expects a device pointer as argument, not a memory base address. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/dwc3-omap.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-) commit665b9c7f97Author: Felipe Balbi <balbi@ti.com> Date: Tue Aug 30 15:52:17 2011 +0300 usb: dwc3: use ep0_next_event field Start tracking the next expected event and act on the error conditions as suggested by databook. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/ep0.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 files changed, 36 insertions(+), 4 deletions(-) commit4f072fa1d0Author: Felipe Balbi <balbi@ti.com> Date: Tue Aug 30 15:50:40 2011 +0300 usb: dwc3: core: add ep0_next_event field this field will hold the next expected event. In certain cases, host might fall into some error condition and ask from us the wrong Control phase. On such situations, we should stall and restart. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) commitaa7b4d0d1fAuthor: Felipe Balbi <balbi@ti.com> Date: Tue Aug 30 15:48:08 2011 +0300 usb: dwc3: drop EP0_STALL state Whenever we issue a Set Stall command on EP0, the state machine will be restarted and Stall is cleared automatically, when core receives the next SETUP packet. There's no need to track that EP0_STALL state. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 1 - drivers/usb/dwc3/ep0.c | 2 -- drivers/usb/dwc3/gadget.c | 10 ++++++++-- 3 files changed, 8 insertions(+), 5 deletions(-) commit0054d1193fAuthor: Felipe Balbi <balbi@ti.com> Date: Tue Aug 30 15:54:53 2011 +0300 usb: dwc3: ep0: clear all EP0 flags when we're going to issue Set Stall command, we should clear DWC3_EP_STALL flag, but also we should clear BUSY, HALTED and all others. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/ep0.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) commitc0478e0f39Author: Felipe Balbi <balbi@ti.com> Date: Wed Aug 31 11:51:43 2011 +0300 usb: dwc3: ep0: fix Get Status handling data was prepared on setup_buf but transfer was started on ctrl_req, fix it. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/ep0.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) commit6062cac8e2Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Mon Aug 29 16:46:38 2011 +0200 usb: dwc3: gadget: replace mdelay with udelay in the busy loop There are two spots where we wait until the HW finishes processing a certain command. Initially we had a few problems and we used 500ms as a limit to be on a the safe side. Paul Zimmerman mentioned this is little too much. After a debugging session, we noticed that we hardly ever go over 20us and didn't pass 30usec so far. Using mdelay() seems way overloaded. Giving the current numbers 500usec as the upper limit is more than enough. Should it ever timeout then something is definitely wrong. While here, also replace the type with u32 since long does not really fit here. Cc: Paul Zimmerman <paul.zimmerman@synopsys.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 12 ++++-------- 1 files changed, 4 insertions(+), 8 deletions(-) commitb55db3bb7eAuthor: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Mon Aug 29 13:56:37 2011 +0200 usb: dwc3: gadget: rework the dequeue on RESET & DISCONNECT - since a while we are disabling an endpoint and purging every requests on RESET and DISCONNECT which leads to a warning since the endpoint was disabled twice (once by the UDC, and second time by the gadget). I think UDC should nuke all requests because all those requests become invalid. It's gadget driver's responsability, though, to disable its used endpoints. This is done by merging dwc3_stop_active_transfer() and dwc3_gadget_nuke_reqs() into dwc3_remove_requests(). - dwc3_stop_active_transfer() is now no longer called unconditionaly. This has the advantage that it is always called to disable an active transfer which means if res_trans_idx 0 than something went wrong and it is an error condition because we can't clean up the requests. - Remove the DWC3_EP_WILL_SHUTDOWN which was introduced while introducing the command complete part for dequeue. All requests on req_queued list should be removed during the dwc3_cleanup_done_reqs() callback so there is no reason to go through the list again. We consider it an error condition if requests are still on this list since we never queue TRB without LST=1 (the last requests has always LST=1, there are no requests with LST=0 behind it). [ balbi@ti.com : reworked commit log a bit, made patch apply ] Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 1 - drivers/usb/dwc3/gadget.c | 31 ++++++++++++------------------- 2 files changed, 12 insertions(+), 20 deletions(-) commitfe2b0910d5Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Mon Aug 29 13:56:36 2011 +0200 usb: dwc3: core: move the core check before soft reset We read the DWC3_GSNPSID register to make sure we got the correct register offset passed. One of the recent commits moved the soft reset before this so in case of the wrong offset we end up with "reset timed out". This patch moves the "id" check before the reset again. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.c | 19 +++++++++---------- 1 files changed, 9 insertions(+), 10 deletions(-) commit9665fdff2cAuthor: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Mon Aug 29 13:56:35 2011 +0200 usb: dwc3: debugfs: remove test mode interface There are some issues around for enabling/disabling this mode and handling it. It does not work perfectly (yet). However we have a few gadgets tested successfuly so far. That means we are quite confident that we won't need this in near future. So I'm for removing it and bringing a working version back once there is a need for it. Thanks to Dan Carpenter who spotted the wrong memory handling here. [ balbi@ti.com : made it actually apply ] Cc: Dan Carpenter <error27@gmail.com> Cc: wharms@bfs.de Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/debugfs.c | 94 -------------------------------------------- 1 files changed, 0 insertions(+), 94 deletions(-) commit32e132e3eaAuthor: Felipe Balbi <balbi@ti.com> Date: Sat Aug 27 22:28:36 2011 +0300 usb: dwc3: ep0: simplify EP0 state machine The DesignWare USB3 core tells us which phase of a control transfer should be started, it also tells us which physical endpoint needs that transfer. With these two informations, we have all we need to simply EP0 handling quite a lot and get rid rid of the SW state machine tracking ep0 states. For achieving this perfectly, we needed to add support for situations where we get XferNotReady while endpoint is still busy and XferNotReady while gadget driver still hasn't queued a request. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 12 +- drivers/usb/dwc3/ep0.c | 363 ++++++++++++++++++++------------------------- drivers/usb/dwc3/gadget.c | 3 +- 3 files changed, 163 insertions(+), 215 deletions(-) commitedb4e77ef4Author: Felipe Balbi <balbi@ti.com> Date: Sat Aug 27 22:26:00 2011 +0300 usb: dwc3: core: add flag for EP0 direction Add a flag to keep track of ep0 direction. This flag will be used on a following patch. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) commit31d1e80389Author: Felipe Balbi <balbi@ti.com> Date: Sat Aug 27 22:18:09 2011 +0300 usb: dwc3: ep0: add handling for unaligned OUT transfers In case we have transfers which aren't aligned to wMaxPacketSize, we need to be careful with how we start the transfer with the HW. OUT transfers _must_ be aligned with wMaxPacketSize and in order to guarantee that, we use a bounce buffer. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/ep0.c | 37 ++++++++++++++++++++++++++++++++----- 1 files changed, 32 insertions(+), 5 deletions(-) commit64e9634b21Author: Felipe Balbi <balbi@ti.com> Date: Sat Aug 27 22:07:53 2011 +0300 usb: dwc3: add a bounce buffer for control endpoints This core cannot handle OUT transfers which aren't aligned to wMaxPacketSize, but that can happen at least on control endpoint with the USB Audio Class. This patch adds a bounce buffer to be used on the case of a non-aligned ep0out request is queued. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 6 ++++++ drivers/usb/dwc3/gadget.c | 29 ++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) commit6cd800e879Author: Felipe Balbi <balbi@ti.com> Date: Sat Aug 27 22:04:32 2011 +0300 usb: dwc3: core: add defines for XferNotReady event on Control EPs The status field of the Transfer Not Read event is different on Control Endpoints. On this patch we are just adding the defines to be used on a later patch which will re-work the control endpoint handling. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) commitc7dbe4f213Author: Felipe Balbi <balbi@ti.com> Date: Sat Aug 27 20:29:58 2011 +0300 usb: dwc3: gadget: improve command completion debug message the previous message had too little meaning. Make it more human readable and use the macro we already had for extracting the command completion status out of DEPCMDn register. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) commit162e128db0Author: Felipe Balbi <balbi@ti.com> Date: Sat Aug 27 15:10:09 2011 +0300 usb: dwc3: gadget: set request dma to invalid when unmapping if we don't set DMA address to invalid when unmapping, we might fall in a situation where request buffer can't be mapped to DMA again. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) commitff4e987bcfAuthor: Felipe Balbi <balbi@ti.com> Date: Sat Aug 27 02:30:33 2011 +0300 usb: dwc3: ep0: fix 'transfered' typo trivial patch. No functional changes. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/ep0.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) commit7a769ecc90Author: Felipe Balbi <balbi@ti.com> Date: Sat Aug 27 01:40:52 2011 +0300 usb: dwc3: core: add missing @ for kerneldoc trivial patch, no functional changes Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/core.h | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) commite918b57dc8Author: Dan Carpenter <error27@gmail.com> Date: Fri Aug 26 12:21:13 2011 +0300 usb: dwc3: debugfs: add a kfree() on error to dwc3_testmode_open() We may as well fix this potential leak so we don't have to listen to the static checkers complain. Signed-off-by: Dan Carpenter <error27@gmail.com> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/debugfs.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) commitb31b612847Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Mon Aug 22 18:29:13 2011 +0200 usb: dwc3: gaget: clear DWC3_EP_WILL_SHUTDOWN bit Without this patch we won't clear that bit and instead will clear all other bits on our endpoint flag. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) commit15623d7087Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Mon Aug 22 17:42:19 2011 +0200 usb: dwc3: gadget: use TRB type 6 for ISOC transfers Type 6 should be used for the first transfer during an interval. This is also what the reference driver is using. Type 7 seems to be for following or additional transfers within the same interval. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) commit4df3977d9fAuthor: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Mon Aug 22 17:42:18 2011 +0200 usb: dwc3: gadget: reset resource index to zero If we collected two requests together (i.e. only the last of them has LST=1) then we only have to stop transfer once: The clean-up code will cleanup everything until first TRB with the LST bit set. After XferComplete this index should be no longer valid since there is no transfer pending. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) commit679dc46637Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Date: Fri Aug 19 19:59:12 2011 +0200 usb: dwc3: gadget: fixing dequeue of TRBs A TRB which is dequeued seems to have its HWO bits set to 1. Therefore we ignore it if we dequeue it after the command is completed. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-) commitd9a09a239eAuthor: Randy Dunlap <rdunlap@xenotime.net> Date: Tue Aug 23 12:52:47 2011 -0700 usb: fix dwc3 build when USB_GADGET_DWC3 is not enabled Fix build error when CONFIG_USB_GADGET_DWC3 is not enabled: ERROR: "dwc3_send_gadget_ep_cmd" [drivers/usb/dwc3/dwc3.ko] undefined! Signed-off-by: Randy Dunlap <rdunlap@xenotime.net> Acked-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/gadget.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) commitfaea001704Author: Stephen Rothwell <sfr@canb.auug.org.au> Date: Tue Aug 23 15:08:54 2011 +1000 usb: include module.h in the DesignWare USB3 DRD driver Fixes this build error: drivers/usb/dwc3/dwc3-pci.c: In function 'dwc3_pci_init': drivers/usb/dwc3/dwc3-pci.c:211:9: error: 'THIS_MODULE' undeclared (first use in this function) Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Acked-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/dwc3/dwc3-pci.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) commit4dc64e52bdAuthor: Felipe Balbi <balbi@ti.com> Date: Fri Aug 19 18:10:58 2011 +0300 usb: dwc3: Introduce DesignWare USB3 DRD Driver The DesignWare USB3 is a highly configurable IP Core which can be instantiated as Dual-Role Device (DRD), Peripheral Only and Host Only (XHCI) configurations. Several other parameters can be configured like amount of FIFO space, amount of TX and RX endpoints, amount of Host Interrupters, etc. The current driver has been validated with a virtual model of version 1.73a of that core and with an FPGA burned with version 1.83a of the DRD core. We have support for PCIe bus, which is used on FPGA prototyping, and for the OMAP5, more adaptation (or glue) layers can be easily added and the driver is half prepared to handle any possible configuration the HW engineer has chosen considering we have the information on one of the GHWPARAMS registers to do runtime checking of certain features. More runtime checks can, and should, be added in order to make this driver even more flexible with regards to number of endpoints, FIFO sizes, transfer types, etc. While this supports only the device side, for now, we will add support for Host side (xHCI - see the updated series Sebastian has sent [1]) and OTG after we have it all stabilized. [1] http://marc.info/?l=linux-usb&m=131341992020339&w=2 Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> [idos@codeaurora.org: gadget_chips.h: Use 'gadget_is_dwc3(g)' only if CONFIG_USB_GADGET_DWC3 is defined.] Signed-off-by: Ido Shayevitz <idos@codeaurora.org> Documentation/usb/dwc3.txt | 53 + drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/dwc3/Kconfig | 25 + drivers/usb/dwc3/Makefile | 36 + drivers/usb/dwc3/core.c | 467 +++++++++ drivers/usb/dwc3/core.h | 709 +++++++++++++ drivers/usb/dwc3/debug.h | 51 + drivers/usb/dwc3/debugfs.c | 534 ++++++++++ drivers/usb/dwc3/dwc3-omap.c | 410 ++++++++ drivers/usb/dwc3/dwc3-pci.c | 219 ++++ drivers/usb/dwc3/ep0.c | 782 ++++++++++++++ drivers/usb/dwc3/gadget.c | 2063 +++++++++++++++++++++++++++++++++++++ drivers/usb/dwc3/gadget.h | 292 ++++++ drivers/usb/dwc3/io.h | 55 + drivers/usb/gadget/Kconfig | 12 + drivers/usb/gadget/gadget_chips.h | 4 + 17 files changed, 5716 insertions(+), 0 deletions(-) commit348a4c2038Author: Felipe Balbi <balbi@ti.com> Date: Fri Aug 19 18:10:57 2011 +0300 usb: gadget: introduce gadget_is_dwc3() ... to check whether we're running on DesignWare USB3 DRD Controller. Signed-off-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> [idos@codeaurora.org: Conflicts: gadget_chips.h] Signed-off-by: Ido Shayevitz <idos@codeaurora.org> drivers/usb/gadget/gadget_chips.h | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) Change-Id: I12d5f2f957d39b2ff8031366994689bcd453f213 Signed-off-by: David Brown <davidb@codeaurora.org>
961 lines
36 KiB
C
961 lines
36 KiB
C
/*
|
|
* <linux/usb/gadget.h>
|
|
*
|
|
* We call the USB code inside a Linux-based peripheral device a "gadget"
|
|
* driver, except for the hardware-specific bus glue. One USB host can
|
|
* master many USB gadgets, but the gadgets are only slaved to one host.
|
|
*
|
|
*
|
|
* (C) Copyright 2002-2004 by David Brownell
|
|
* All Rights Reserved.
|
|
*
|
|
* This software is licensed under the GNU GPL version 2.
|
|
*/
|
|
|
|
#ifndef __LINUX_USB_GADGET_H
|
|
#define __LINUX_USB_GADGET_H
|
|
|
|
#include <linux/slab.h>
|
|
|
|
struct usb_ep;
|
|
|
|
/**
|
|
* struct usb_request - describes one i/o request
|
|
* @buf: Buffer used for data. Always provide this; some controllers
|
|
* only use PIO, or don't use DMA for some endpoints.
|
|
* @dma: DMA address corresponding to 'buf'. If you don't set this
|
|
* field, and the usb controller needs one, it is responsible
|
|
* for mapping and unmapping the buffer.
|
|
* @length: Length of that data
|
|
* @stream_id: The stream id, when USB3.0 bulk streams are being used
|
|
* @no_interrupt: If true, hints that no completion irq is needed.
|
|
* Helpful sometimes with deep request queues that are handled
|
|
* directly by DMA controllers.
|
|
* @zero: If true, when writing data, makes the last packet be "short"
|
|
* by adding a zero length packet as needed;
|
|
* @short_not_ok: When reading data, makes short packets be
|
|
* treated as errors (queue stops advancing till cleanup).
|
|
* @complete: Function called when request completes, so this request and
|
|
* its buffer may be re-used. The function will always be called with
|
|
* interrupts disabled, and it must not sleep.
|
|
* Reads terminate with a short packet, or when the buffer fills,
|
|
* whichever comes first. When writes terminate, some data bytes
|
|
* will usually still be in flight (often in a hardware fifo).
|
|
* Errors (for reads or writes) stop the queue from advancing
|
|
* until the completion function returns, so that any transfers
|
|
* invalidated by the error may first be dequeued.
|
|
* @context: For use by the completion callback
|
|
* @list: For use by the gadget driver.
|
|
* @status: Reports completion code, zero or a negative errno.
|
|
* Normally, faults block the transfer queue from advancing until
|
|
* the completion callback returns.
|
|
* Code "-ESHUTDOWN" indicates completion caused by device disconnect,
|
|
* or when the driver disabled the endpoint.
|
|
* @actual: Reports bytes transferred to/from the buffer. For reads (OUT
|
|
* transfers) this may be less than the requested length. If the
|
|
* short_not_ok flag is set, short reads are treated as errors
|
|
* even when status otherwise indicates successful completion.
|
|
* Note that for writes (IN transfers) some data bytes may still
|
|
* reside in a device-side FIFO when the request is reported as
|
|
* complete.
|
|
*@udc_priv: Vendor private data in usage by the UDC.
|
|
*
|
|
* These are allocated/freed through the endpoint they're used with. The
|
|
* hardware's driver can add extra per-request data to the memory it returns,
|
|
* which often avoids separate memory allocations (potential failures),
|
|
* later when the request is queued.
|
|
*
|
|
* Request flags affect request handling, such as whether a zero length
|
|
* packet is written (the "zero" flag), whether a short read should be
|
|
* treated as an error (blocking request queue advance, the "short_not_ok"
|
|
* flag), or hinting that an interrupt is not required (the "no_interrupt"
|
|
* flag, for use with deep request queues).
|
|
*
|
|
* Bulk endpoints can use any size buffers, and can also be used for interrupt
|
|
* transfers. interrupt-only endpoints can be much less functional.
|
|
*
|
|
* NOTE: this is analogous to 'struct urb' on the host side, except that
|
|
* it's thinner and promotes more pre-allocation.
|
|
*/
|
|
|
|
struct usb_request {
|
|
void *buf;
|
|
unsigned length;
|
|
dma_addr_t dma;
|
|
|
|
unsigned stream_id:16;
|
|
unsigned no_interrupt:1;
|
|
unsigned zero:1;
|
|
unsigned short_not_ok:1;
|
|
|
|
void (*complete)(struct usb_ep *ep,
|
|
struct usb_request *req);
|
|
void *context;
|
|
struct list_head list;
|
|
|
|
int status;
|
|
unsigned actual;
|
|
unsigned udc_priv;
|
|
};
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* endpoint-specific parts of the api to the usb controller hardware.
|
|
* unlike the urb model, (de)multiplexing layers are not required.
|
|
* (so this api could slash overhead if used on the host side...)
|
|
*
|
|
* note that device side usb controllers commonly differ in how many
|
|
* endpoints they support, as well as their capabilities.
|
|
*/
|
|
struct usb_ep_ops {
|
|
int (*enable) (struct usb_ep *ep,
|
|
const struct usb_endpoint_descriptor *desc);
|
|
int (*disable) (struct usb_ep *ep);
|
|
|
|
struct usb_request *(*alloc_request) (struct usb_ep *ep,
|
|
gfp_t gfp_flags);
|
|
void (*free_request) (struct usb_ep *ep, struct usb_request *req);
|
|
int (*queue) (struct usb_ep *ep, struct usb_request *req,
|
|
gfp_t gfp_flags);
|
|
int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
|
|
|
|
int (*set_halt) (struct usb_ep *ep, int value);
|
|
int (*set_wedge) (struct usb_ep *ep);
|
|
|
|
int (*fifo_status) (struct usb_ep *ep);
|
|
void (*fifo_flush) (struct usb_ep *ep);
|
|
};
|
|
|
|
/**
|
|
* struct usb_ep - device side representation of USB endpoint
|
|
* @name:identifier for the endpoint, such as "ep-a" or "ep9in-bulk"
|
|
* @ops: Function pointers used to access hardware-specific operations.
|
|
* @ep_list:the gadget's ep_list holds all of its endpoints
|
|
* @maxpacket:The maximum packet size used on this endpoint. The initial
|
|
* value can sometimes be reduced (hardware allowing), according to
|
|
* the endpoint descriptor used to configure the endpoint.
|
|
* @max_streams: The maximum number of streams supported
|
|
* by this EP (0 - 16, actual number is 2^n)
|
|
* @mult: multiplier, 'mult' value for SS Isoc EPs
|
|
* @maxburst: the maximum number of bursts supported by this EP (for usb3)
|
|
* @driver_data:for use by the gadget driver.
|
|
* @address: used to identify the endpoint when finding descriptor that
|
|
* matches connection speed
|
|
* @desc: endpoint descriptor. This pointer is set before the endpoint is
|
|
* enabled and remains valid until the endpoint is disabled.
|
|
* @comp_desc: In case of SuperSpeed support, this is the endpoint companion
|
|
* descriptor that is used to configure the endpoint
|
|
*
|
|
* the bus controller driver lists all the general purpose endpoints in
|
|
* gadget->ep_list. the control endpoint (gadget->ep0) is not in that list,
|
|
* and is accessed only in response to a driver setup() callback.
|
|
*/
|
|
struct usb_ep {
|
|
void *driver_data;
|
|
|
|
const char *name;
|
|
const struct usb_ep_ops *ops;
|
|
struct list_head ep_list;
|
|
unsigned maxpacket:16;
|
|
unsigned max_streams:16;
|
|
unsigned mult:2;
|
|
unsigned maxburst:4;
|
|
u8 address;
|
|
const struct usb_endpoint_descriptor *desc;
|
|
const struct usb_ss_ep_comp_descriptor *comp_desc;
|
|
};
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
* usb_ep_enable - configure endpoint, making it usable
|
|
* @ep:the endpoint being configured. may not be the endpoint named "ep0".
|
|
* drivers discover endpoints through the ep_list of a usb_gadget.
|
|
*
|
|
* When configurations are set, or when interface settings change, the driver
|
|
* will enable or disable the relevant endpoints. while it is enabled, an
|
|
* endpoint may be used for i/o until the driver receives a disconnect() from
|
|
* the host or until the endpoint is disabled.
|
|
*
|
|
* the ep0 implementation (which calls this routine) must ensure that the
|
|
* hardware capabilities of each endpoint match the descriptor provided
|
|
* for it. for example, an endpoint named "ep2in-bulk" would be usable
|
|
* for interrupt transfers as well as bulk, but it likely couldn't be used
|
|
* for iso transfers or for endpoint 14. some endpoints are fully
|
|
* configurable, with more generic names like "ep-a". (remember that for
|
|
* USB, "in" means "towards the USB master".)
|
|
*
|
|
* returns zero, or a negative error code.
|
|
*/
|
|
static inline int usb_ep_enable(struct usb_ep *ep)
|
|
{
|
|
return ep->ops->enable(ep, ep->desc);
|
|
}
|
|
|
|
/**
|
|
* usb_ep_disable - endpoint is no longer usable
|
|
* @ep:the endpoint being unconfigured. may not be the endpoint named "ep0".
|
|
*
|
|
* no other task may be using this endpoint when this is called.
|
|
* any pending and uncompleted requests will complete with status
|
|
* indicating disconnect (-ESHUTDOWN) before this call returns.
|
|
* gadget drivers must call usb_ep_enable() again before queueing
|
|
* requests to the endpoint.
|
|
*
|
|
* returns zero, or a negative error code.
|
|
*/
|
|
static inline int usb_ep_disable(struct usb_ep *ep)
|
|
{
|
|
return ep->ops->disable(ep);
|
|
}
|
|
|
|
/**
|
|
* usb_ep_alloc_request - allocate a request object to use with this endpoint
|
|
* @ep:the endpoint to be used with with the request
|
|
* @gfp_flags:GFP_* flags to use
|
|
*
|
|
* Request objects must be allocated with this call, since they normally
|
|
* need controller-specific setup and may even need endpoint-specific
|
|
* resources such as allocation of DMA descriptors.
|
|
* Requests may be submitted with usb_ep_queue(), and receive a single
|
|
* completion callback. Free requests with usb_ep_free_request(), when
|
|
* they are no longer needed.
|
|
*
|
|
* Returns the request, or null if one could not be allocated.
|
|
*/
|
|
static inline struct usb_request *usb_ep_alloc_request(struct usb_ep *ep,
|
|
gfp_t gfp_flags)
|
|
{
|
|
return ep->ops->alloc_request(ep, gfp_flags);
|
|
}
|
|
|
|
/**
|
|
* usb_ep_free_request - frees a request object
|
|
* @ep:the endpoint associated with the request
|
|
* @req:the request being freed
|
|
*
|
|
* Reverses the effect of usb_ep_alloc_request().
|
|
* Caller guarantees the request is not queued, and that it will
|
|
* no longer be requeued (or otherwise used).
|
|
*/
|
|
static inline void usb_ep_free_request(struct usb_ep *ep,
|
|
struct usb_request *req)
|
|
{
|
|
ep->ops->free_request(ep, req);
|
|
}
|
|
|
|
/**
|
|
* usb_ep_queue - queues (submits) an I/O request to an endpoint.
|
|
* @ep:the endpoint associated with the request
|
|
* @req:the request being submitted
|
|
* @gfp_flags: GFP_* flags to use in case the lower level driver couldn't
|
|
* pre-allocate all necessary memory with the request.
|
|
*
|
|
* This tells the device controller to perform the specified request through
|
|
* that endpoint (reading or writing a buffer). When the request completes,
|
|
* including being canceled by usb_ep_dequeue(), the request's completion
|
|
* routine is called to return the request to the driver. Any endpoint
|
|
* (except control endpoints like ep0) may have more than one transfer
|
|
* request queued; they complete in FIFO order. Once a gadget driver
|
|
* submits a request, that request may not be examined or modified until it
|
|
* is given back to that driver through the completion callback.
|
|
*
|
|
* Each request is turned into one or more packets. The controller driver
|
|
* never merges adjacent requests into the same packet. OUT transfers
|
|
* will sometimes use data that's already buffered in the hardware.
|
|
* Drivers can rely on the fact that the first byte of the request's buffer
|
|
* always corresponds to the first byte of some USB packet, for both
|
|
* IN and OUT transfers.
|
|
*
|
|
* Bulk endpoints can queue any amount of data; the transfer is packetized
|
|
* automatically. The last packet will be short if the request doesn't fill it
|
|
* out completely. Zero length packets (ZLPs) should be avoided in portable
|
|
* protocols since not all usb hardware can successfully handle zero length
|
|
* packets. (ZLPs may be explicitly written, and may be implicitly written if
|
|
* the request 'zero' flag is set.) Bulk endpoints may also be used
|
|
* for interrupt transfers; but the reverse is not true, and some endpoints
|
|
* won't support every interrupt transfer. (Such as 768 byte packets.)
|
|
*
|
|
* Interrupt-only endpoints are less functional than bulk endpoints, for
|
|
* example by not supporting queueing or not handling buffers that are
|
|
* larger than the endpoint's maxpacket size. They may also treat data
|
|
* toggle differently.
|
|
*
|
|
* Control endpoints ... after getting a setup() callback, the driver queues
|
|
* one response (even if it would be zero length). That enables the
|
|
* status ack, after transferring data as specified in the response. Setup
|
|
* functions may return negative error codes to generate protocol stalls.
|
|
* (Note that some USB device controllers disallow protocol stall responses
|
|
* in some cases.) When control responses are deferred (the response is
|
|
* written after the setup callback returns), then usb_ep_set_halt() may be
|
|
* used on ep0 to trigger protocol stalls. Depending on the controller,
|
|
* it may not be possible to trigger a status-stage protocol stall when the
|
|
* data stage is over, that is, from within the response's completion
|
|
* routine.
|
|
*
|
|
* For periodic endpoints, like interrupt or isochronous ones, the usb host
|
|
* arranges to poll once per interval, and the gadget driver usually will
|
|
* have queued some data to transfer at that time.
|
|
*
|
|
* Returns zero, or a negative error code. Endpoints that are not enabled
|
|
* report errors; errors will also be
|
|
* reported when the usb peripheral is disconnected.
|
|
*/
|
|
static inline int usb_ep_queue(struct usb_ep *ep,
|
|
struct usb_request *req, gfp_t gfp_flags)
|
|
{
|
|
return ep->ops->queue(ep, req, gfp_flags);
|
|
}
|
|
|
|
/**
|
|
* usb_ep_dequeue - dequeues (cancels, unlinks) an I/O request from an endpoint
|
|
* @ep:the endpoint associated with the request
|
|
* @req:the request being canceled
|
|
*
|
|
* if the request is still active on the endpoint, it is dequeued and its
|
|
* completion routine is called (with status -ECONNRESET); else a negative
|
|
* error code is returned.
|
|
*
|
|
* note that some hardware can't clear out write fifos (to unlink the request
|
|
* at the head of the queue) except as part of disconnecting from usb. such
|
|
* restrictions prevent drivers from supporting configuration changes,
|
|
* even to configuration zero (a "chapter 9" requirement).
|
|
*/
|
|
static inline int usb_ep_dequeue(struct usb_ep *ep, struct usb_request *req)
|
|
{
|
|
return ep->ops->dequeue(ep, req);
|
|
}
|
|
|
|
/**
|
|
* usb_ep_set_halt - sets the endpoint halt feature.
|
|
* @ep: the non-isochronous endpoint being stalled
|
|
*
|
|
* Use this to stall an endpoint, perhaps as an error report.
|
|
* Except for control endpoints,
|
|
* the endpoint stays halted (will not stream any data) until the host
|
|
* clears this feature; drivers may need to empty the endpoint's request
|
|
* queue first, to make sure no inappropriate transfers happen.
|
|
*
|
|
* Note that while an endpoint CLEAR_FEATURE will be invisible to the
|
|
* gadget driver, a SET_INTERFACE will not be. To reset endpoints for the
|
|
* current altsetting, see usb_ep_clear_halt(). When switching altsettings,
|
|
* it's simplest to use usb_ep_enable() or usb_ep_disable() for the endpoints.
|
|
*
|
|
* Returns zero, or a negative error code. On success, this call sets
|
|
* underlying hardware state that blocks data transfers.
|
|
* Attempts to halt IN endpoints will fail (returning -EAGAIN) if any
|
|
* transfer requests are still queued, or if the controller hardware
|
|
* (usually a FIFO) still holds bytes that the host hasn't collected.
|
|
*/
|
|
static inline int usb_ep_set_halt(struct usb_ep *ep)
|
|
{
|
|
return ep->ops->set_halt(ep, 1);
|
|
}
|
|
|
|
/**
|
|
* usb_ep_clear_halt - clears endpoint halt, and resets toggle
|
|
* @ep:the bulk or interrupt endpoint being reset
|
|
*
|
|
* Use this when responding to the standard usb "set interface" request,
|
|
* for endpoints that aren't reconfigured, after clearing any other state
|
|
* in the endpoint's i/o queue.
|
|
*
|
|
* Returns zero, or a negative error code. On success, this call clears
|
|
* the underlying hardware state reflecting endpoint halt and data toggle.
|
|
* Note that some hardware can't support this request (like pxa2xx_udc),
|
|
* and accordingly can't correctly implement interface altsettings.
|
|
*/
|
|
static inline int usb_ep_clear_halt(struct usb_ep *ep)
|
|
{
|
|
return ep->ops->set_halt(ep, 0);
|
|
}
|
|
|
|
/**
|
|
* usb_ep_set_wedge - sets the halt feature and ignores clear requests
|
|
* @ep: the endpoint being wedged
|
|
*
|
|
* Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
|
|
* requests. If the gadget driver clears the halt status, it will
|
|
* automatically unwedge the endpoint.
|
|
*
|
|
* Returns zero on success, else negative errno.
|
|
*/
|
|
static inline int
|
|
usb_ep_set_wedge(struct usb_ep *ep)
|
|
{
|
|
if (ep->ops->set_wedge)
|
|
return ep->ops->set_wedge(ep);
|
|
else
|
|
return ep->ops->set_halt(ep, 1);
|
|
}
|
|
|
|
/**
|
|
* usb_ep_fifo_status - returns number of bytes in fifo, or error
|
|
* @ep: the endpoint whose fifo status is being checked.
|
|
*
|
|
* FIFO endpoints may have "unclaimed data" in them in certain cases,
|
|
* such as after aborted transfers. Hosts may not have collected all
|
|
* the IN data written by the gadget driver (and reported by a request
|
|
* completion). The gadget driver may not have collected all the data
|
|
* written OUT to it by the host. Drivers that need precise handling for
|
|
* fault reporting or recovery may need to use this call.
|
|
*
|
|
* This returns the number of such bytes in the fifo, or a negative
|
|
* errno if the endpoint doesn't use a FIFO or doesn't support such
|
|
* precise handling.
|
|
*/
|
|
static inline int usb_ep_fifo_status(struct usb_ep *ep)
|
|
{
|
|
if (ep->ops->fifo_status)
|
|
return ep->ops->fifo_status(ep);
|
|
else
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
/**
|
|
* usb_ep_fifo_flush - flushes contents of a fifo
|
|
* @ep: the endpoint whose fifo is being flushed.
|
|
*
|
|
* This call may be used to flush the "unclaimed data" that may exist in
|
|
* an endpoint fifo after abnormal transaction terminations. The call
|
|
* must never be used except when endpoint is not being used for any
|
|
* protocol translation.
|
|
*/
|
|
static inline void usb_ep_fifo_flush(struct usb_ep *ep)
|
|
{
|
|
if (ep->ops->fifo_flush)
|
|
ep->ops->fifo_flush(ep);
|
|
}
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
struct usb_dcd_config_params {
|
|
__u8 bU1devExitLat; /* U1 Device exit Latency */
|
|
#define USB_DEFAULT_U1_DEV_EXIT_LAT 0x01 /* Less then 1 microsec */
|
|
__le16 bU2DevExitLat; /* U2 Device exit Latency */
|
|
#define USB_DEFAULT_U2_DEV_EXIT_LAT 0x1F4 /* Less then 500 microsec */
|
|
};
|
|
|
|
|
|
struct usb_gadget;
|
|
struct usb_gadget_driver;
|
|
|
|
/* the rest of the api to the controller hardware: device operations,
|
|
* which don't involve endpoints (or i/o).
|
|
*/
|
|
struct usb_gadget_ops {
|
|
int (*get_frame)(struct usb_gadget *);
|
|
int (*wakeup)(struct usb_gadget *);
|
|
int (*set_selfpowered) (struct usb_gadget *, int is_selfpowered);
|
|
int (*vbus_session) (struct usb_gadget *, int is_active);
|
|
int (*vbus_draw) (struct usb_gadget *, unsigned mA);
|
|
int (*pullup) (struct usb_gadget *, int is_on);
|
|
int (*ioctl)(struct usb_gadget *,
|
|
unsigned code, unsigned long param);
|
|
void (*get_config_params)(struct usb_dcd_config_params *);
|
|
int (*udc_start)(struct usb_gadget *,
|
|
struct usb_gadget_driver *);
|
|
int (*udc_stop)(struct usb_gadget *,
|
|
struct usb_gadget_driver *);
|
|
|
|
/* Those two are deprecated */
|
|
int (*start)(struct usb_gadget_driver *,
|
|
int (*bind)(struct usb_gadget *));
|
|
int (*stop)(struct usb_gadget_driver *);
|
|
};
|
|
|
|
/**
|
|
* struct usb_gadget - represents a usb slave device
|
|
* @ops: Function pointers used to access hardware-specific operations.
|
|
* @ep0: Endpoint zero, used when reading or writing responses to
|
|
* driver setup() requests
|
|
* @ep_list: List of other endpoints supported by the device.
|
|
* @speed: Speed of current connection to USB host.
|
|
* @is_dualspeed: True if the controller supports both high and full speed
|
|
* operation. If it does, the gadget driver must also support both.
|
|
* @is_otg: True if the USB device port uses a Mini-AB jack, so that the
|
|
* gadget driver must provide a USB OTG descriptor.
|
|
* @is_a_peripheral: False unless is_otg, the "A" end of a USB cable
|
|
* is in the Mini-AB jack, and HNP has been used to switch roles
|
|
* so that the "A" device currently acts as A-Peripheral, not A-Host.
|
|
* @a_hnp_support: OTG device feature flag, indicating that the A-Host
|
|
* supports HNP at this port.
|
|
* @a_alt_hnp_support: OTG device feature flag, indicating that the A-Host
|
|
* only supports HNP on a different root port.
|
|
* @b_hnp_enable: OTG device feature flag, indicating that the A-Host
|
|
* enabled HNP support.
|
|
* @host_request: A flag set by user when wishes to take up host role.
|
|
* @otg_srp_reqd: OTG test mode feature to initiate SRP after the end of
|
|
* current session.
|
|
* @name: Identifies the controller hardware type. Used in diagnostics
|
|
* and sometimes configuration.
|
|
* @dev: Driver model state for this abstract device.
|
|
*
|
|
* Gadgets have a mostly-portable "gadget driver" implementing device
|
|
* functions, handling all usb configurations and interfaces. Gadget
|
|
* drivers talk to hardware-specific code indirectly, through ops vectors.
|
|
* That insulates the gadget driver from hardware details, and packages
|
|
* the hardware endpoints through generic i/o queues. The "usb_gadget"
|
|
* and "usb_ep" interfaces provide that insulation from the hardware.
|
|
*
|
|
* Except for the driver data, all fields in this structure are
|
|
* read-only to the gadget driver. That driver data is part of the
|
|
* "driver model" infrastructure in 2.6 (and later) kernels, and for
|
|
* earlier systems is grouped in a similar structure that's not known
|
|
* to the rest of the kernel.
|
|
*
|
|
* Values of the three OTG device feature flags are updated before the
|
|
* setup() call corresponding to USB_REQ_SET_CONFIGURATION, and before
|
|
* driver suspend() calls. They are valid only when is_otg, and when the
|
|
* device is acting as a B-Peripheral (so is_a_peripheral is false).
|
|
*/
|
|
struct usb_gadget {
|
|
/* readonly to gadget driver */
|
|
const struct usb_gadget_ops *ops;
|
|
struct usb_ep *ep0;
|
|
struct list_head ep_list; /* of usb_ep */
|
|
enum usb_device_speed speed;
|
|
unsigned is_dualspeed:1;
|
|
unsigned is_otg:1;
|
|
unsigned is_a_peripheral:1;
|
|
unsigned b_hnp_enable:1;
|
|
unsigned a_hnp_support:1;
|
|
unsigned a_alt_hnp_support:1;
|
|
unsigned host_request:1;
|
|
unsigned otg_srp_reqd:1;
|
|
const char *name;
|
|
struct device dev;
|
|
};
|
|
|
|
static inline void set_gadget_data(struct usb_gadget *gadget, void *data)
|
|
{ dev_set_drvdata(&gadget->dev, data); }
|
|
static inline void *get_gadget_data(struct usb_gadget *gadget)
|
|
{ return dev_get_drvdata(&gadget->dev); }
|
|
static inline struct usb_gadget *dev_to_usb_gadget(struct device *dev)
|
|
{
|
|
return container_of(dev, struct usb_gadget, dev);
|
|
}
|
|
|
|
/* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */
|
|
#define gadget_for_each_ep(tmp, gadget) \
|
|
list_for_each_entry(tmp, &(gadget)->ep_list, ep_list)
|
|
|
|
|
|
/**
|
|
* gadget_is_dualspeed - return true iff the hardware handles high speed
|
|
* @g: controller that might support both high and full speeds
|
|
*/
|
|
static inline int gadget_is_dualspeed(struct usb_gadget *g)
|
|
{
|
|
#ifdef CONFIG_USB_GADGET_DUALSPEED
|
|
/* runtime test would check "g->is_dualspeed" ... that might be
|
|
* useful to work around hardware bugs, but is mostly pointless
|
|
*/
|
|
return 1;
|
|
#else
|
|
return 0;
|
|
#endif
|
|
}
|
|
|
|
/**
|
|
* gadget_is_superspeed() - return true if the hardware handles
|
|
* supperspeed
|
|
* @g: controller that might support supper speed
|
|
*/
|
|
static inline int gadget_is_superspeed(struct usb_gadget *g)
|
|
{
|
|
#ifdef CONFIG_USB_GADGET_SUPERSPEED
|
|
/*
|
|
* runtime test would check "g->is_superspeed" ... that might be
|
|
* useful to work around hardware bugs, but is mostly pointless
|
|
*/
|
|
return 1;
|
|
#else
|
|
return 0;
|
|
#endif
|
|
}
|
|
|
|
/**
|
|
* gadget_is_otg - return true iff the hardware is OTG-ready
|
|
* @g: controller that might have a Mini-AB connector
|
|
*
|
|
* This is a runtime test, since kernels with a USB-OTG stack sometimes
|
|
* run on boards which only have a Mini-B (or Mini-A) connector.
|
|
*/
|
|
static inline int gadget_is_otg(struct usb_gadget *g)
|
|
{
|
|
#ifdef CONFIG_USB_OTG
|
|
return g->is_otg;
|
|
#else
|
|
return 0;
|
|
#endif
|
|
}
|
|
|
|
/**
|
|
* usb_gadget_frame_number - returns the current frame number
|
|
* @gadget: controller that reports the frame number
|
|
*
|
|
* Returns the usb frame number, normally eleven bits from a SOF packet,
|
|
* or negative errno if this device doesn't support this capability.
|
|
*/
|
|
static inline int usb_gadget_frame_number(struct usb_gadget *gadget)
|
|
{
|
|
return gadget->ops->get_frame(gadget);
|
|
}
|
|
|
|
/**
|
|
* usb_gadget_wakeup - tries to wake up the host connected to this gadget
|
|
* @gadget: controller used to wake up the host
|
|
*
|
|
* Returns zero on success, else negative error code if the hardware
|
|
* doesn't support such attempts, or its support has not been enabled
|
|
* by the usb host. Drivers must return device descriptors that report
|
|
* their ability to support this, or hosts won't enable it.
|
|
*
|
|
* This may also try to use SRP to wake the host and start enumeration,
|
|
* even if OTG isn't otherwise in use. OTG devices may also start
|
|
* remote wakeup even when hosts don't explicitly enable it.
|
|
*/
|
|
static inline int usb_gadget_wakeup(struct usb_gadget *gadget)
|
|
{
|
|
if (!gadget->ops->wakeup)
|
|
return -EOPNOTSUPP;
|
|
return gadget->ops->wakeup(gadget);
|
|
}
|
|
|
|
/**
|
|
* usb_gadget_set_selfpowered - sets the device selfpowered feature.
|
|
* @gadget:the device being declared as self-powered
|
|
*
|
|
* this affects the device status reported by the hardware driver
|
|
* to reflect that it now has a local power supply.
|
|
*
|
|
* returns zero on success, else negative errno.
|
|
*/
|
|
static inline int usb_gadget_set_selfpowered(struct usb_gadget *gadget)
|
|
{
|
|
if (!gadget->ops->set_selfpowered)
|
|
return -EOPNOTSUPP;
|
|
return gadget->ops->set_selfpowered(gadget, 1);
|
|
}
|
|
|
|
/**
|
|
* usb_gadget_clear_selfpowered - clear the device selfpowered feature.
|
|
* @gadget:the device being declared as bus-powered
|
|
*
|
|
* this affects the device status reported by the hardware driver.
|
|
* some hardware may not support bus-powered operation, in which
|
|
* case this feature's value can never change.
|
|
*
|
|
* returns zero on success, else negative errno.
|
|
*/
|
|
static inline int usb_gadget_clear_selfpowered(struct usb_gadget *gadget)
|
|
{
|
|
if (!gadget->ops->set_selfpowered)
|
|
return -EOPNOTSUPP;
|
|
return gadget->ops->set_selfpowered(gadget, 0);
|
|
}
|
|
|
|
/**
|
|
* usb_gadget_vbus_connect - Notify controller that VBUS is powered
|
|
* @gadget:The device which now has VBUS power.
|
|
* Context: can sleep
|
|
*
|
|
* This call is used by a driver for an external transceiver (or GPIO)
|
|
* that detects a VBUS power session starting. Common responses include
|
|
* resuming the controller, activating the D+ (or D-) pullup to let the
|
|
* host detect that a USB device is attached, and starting to draw power
|
|
* (8mA or possibly more, especially after SET_CONFIGURATION).
|
|
*
|
|
* Returns zero on success, else negative errno.
|
|
*/
|
|
static inline int usb_gadget_vbus_connect(struct usb_gadget *gadget)
|
|
{
|
|
if (!gadget->ops->vbus_session)
|
|
return -EOPNOTSUPP;
|
|
return gadget->ops->vbus_session(gadget, 1);
|
|
}
|
|
|
|
/**
|
|
* usb_gadget_vbus_draw - constrain controller's VBUS power usage
|
|
* @gadget:The device whose VBUS usage is being described
|
|
* @mA:How much current to draw, in milliAmperes. This should be twice
|
|
* the value listed in the configuration descriptor bMaxPower field.
|
|
*
|
|
* This call is used by gadget drivers during SET_CONFIGURATION calls,
|
|
* reporting how much power the device may consume. For example, this
|
|
* could affect how quickly batteries are recharged.
|
|
*
|
|
* Returns zero on success, else negative errno.
|
|
*/
|
|
static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
|
|
{
|
|
if (!gadget->ops->vbus_draw)
|
|
return -EOPNOTSUPP;
|
|
return gadget->ops->vbus_draw(gadget, mA);
|
|
}
|
|
|
|
/**
|
|
* usb_gadget_vbus_disconnect - notify controller about VBUS session end
|
|
* @gadget:the device whose VBUS supply is being described
|
|
* Context: can sleep
|
|
*
|
|
* This call is used by a driver for an external transceiver (or GPIO)
|
|
* that detects a VBUS power session ending. Common responses include
|
|
* reversing everything done in usb_gadget_vbus_connect().
|
|
*
|
|
* Returns zero on success, else negative errno.
|
|
*/
|
|
static inline int usb_gadget_vbus_disconnect(struct usb_gadget *gadget)
|
|
{
|
|
if (!gadget->ops->vbus_session)
|
|
return -EOPNOTSUPP;
|
|
return gadget->ops->vbus_session(gadget, 0);
|
|
}
|
|
|
|
/**
|
|
* usb_gadget_connect - software-controlled connect to USB host
|
|
* @gadget:the peripheral being connected
|
|
*
|
|
* Enables the D+ (or potentially D-) pullup. The host will start
|
|
* enumerating this gadget when the pullup is active and a VBUS session
|
|
* is active (the link is powered). This pullup is always enabled unless
|
|
* usb_gadget_disconnect() has been used to disable it.
|
|
*
|
|
* Returns zero on success, else negative errno.
|
|
*/
|
|
static inline int usb_gadget_connect(struct usb_gadget *gadget)
|
|
{
|
|
if (!gadget->ops->pullup)
|
|
return -EOPNOTSUPP;
|
|
return gadget->ops->pullup(gadget, 1);
|
|
}
|
|
|
|
/**
|
|
* usb_gadget_disconnect - software-controlled disconnect from USB host
|
|
* @gadget:the peripheral being disconnected
|
|
*
|
|
* Disables the D+ (or potentially D-) pullup, which the host may see
|
|
* as a disconnect (when a VBUS session is active). Not all systems
|
|
* support software pullup controls.
|
|
*
|
|
* This routine may be used during the gadget driver bind() call to prevent
|
|
* the peripheral from ever being visible to the USB host, unless later
|
|
* usb_gadget_connect() is called. For example, user mode components may
|
|
* need to be activated before the system can talk to hosts.
|
|
*
|
|
* Returns zero on success, else negative errno.
|
|
*/
|
|
static inline int usb_gadget_disconnect(struct usb_gadget *gadget)
|
|
{
|
|
if (!gadget->ops->pullup)
|
|
return -EOPNOTSUPP;
|
|
return gadget->ops->pullup(gadget, 0);
|
|
}
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
* struct usb_gadget_driver - driver for usb 'slave' devices
|
|
* @function: String describing the gadget's function
|
|
* @speed: Highest speed the driver handles.
|
|
* @setup: Invoked for ep0 control requests that aren't handled by
|
|
* the hardware level driver. Most calls must be handled by
|
|
* the gadget driver, including descriptor and configuration
|
|
* management. The 16 bit members of the setup data are in
|
|
* USB byte order. Called in_interrupt; this may not sleep. Driver
|
|
* queues a response to ep0, or returns negative to stall.
|
|
* @disconnect: Invoked after all transfers have been stopped,
|
|
* when the host is disconnected. May be called in_interrupt; this
|
|
* may not sleep. Some devices can't detect disconnect, so this might
|
|
* not be called except as part of controller shutdown.
|
|
* @unbind: Invoked when the driver is unbound from a gadget,
|
|
* usually from rmmod (after a disconnect is reported).
|
|
* Called in a context that permits sleeping.
|
|
* @suspend: Invoked on USB suspend. May be called in_interrupt.
|
|
* @resume: Invoked on USB resume. May be called in_interrupt.
|
|
* @driver: Driver model state for this driver.
|
|
*
|
|
* Devices are disabled till a gadget driver successfully bind()s, which
|
|
* means the driver will handle setup() requests needed to enumerate (and
|
|
* meet "chapter 9" requirements) then do some useful work.
|
|
*
|
|
* If gadget->is_otg is true, the gadget driver must provide an OTG
|
|
* descriptor during enumeration, or else fail the bind() call. In such
|
|
* cases, no USB traffic may flow until both bind() returns without
|
|
* having called usb_gadget_disconnect(), and the USB host stack has
|
|
* initialized.
|
|
*
|
|
* Drivers use hardware-specific knowledge to configure the usb hardware.
|
|
* endpoint addressing is only one of several hardware characteristics that
|
|
* are in descriptors the ep0 implementation returns from setup() calls.
|
|
*
|
|
* Except for ep0 implementation, most driver code shouldn't need change to
|
|
* run on top of different usb controllers. It'll use endpoints set up by
|
|
* that ep0 implementation.
|
|
*
|
|
* The usb controller driver handles a few standard usb requests. Those
|
|
* include set_address, and feature flags for devices, interfaces, and
|
|
* endpoints (the get_status, set_feature, and clear_feature requests).
|
|
*
|
|
* Accordingly, the driver's setup() callback must always implement all
|
|
* get_descriptor requests, returning at least a device descriptor and
|
|
* a configuration descriptor. Drivers must make sure the endpoint
|
|
* descriptors match any hardware constraints. Some hardware also constrains
|
|
* other descriptors. (The pxa250 allows only configurations 1, 2, or 3).
|
|
*
|
|
* The driver's setup() callback must also implement set_configuration,
|
|
* and should also implement set_interface, get_configuration, and
|
|
* get_interface. Setting a configuration (or interface) is where
|
|
* endpoints should be activated or (config 0) shut down.
|
|
*
|
|
* (Note that only the default control endpoint is supported. Neither
|
|
* hosts nor devices generally support control traffic except to ep0.)
|
|
*
|
|
* Most devices will ignore USB suspend/resume operations, and so will
|
|
* not provide those callbacks. However, some may need to change modes
|
|
* when the host is not longer directing those activities. For example,
|
|
* local controls (buttons, dials, etc) may need to be re-enabled since
|
|
* the (remote) host can't do that any longer; or an error state might
|
|
* be cleared, to make the device behave identically whether or not
|
|
* power is maintained.
|
|
*/
|
|
struct usb_gadget_driver {
|
|
char *function;
|
|
enum usb_device_speed speed;
|
|
void (*unbind)(struct usb_gadget *);
|
|
int (*setup)(struct usb_gadget *,
|
|
const struct usb_ctrlrequest *);
|
|
void (*disconnect)(struct usb_gadget *);
|
|
void (*suspend)(struct usb_gadget *);
|
|
void (*resume)(struct usb_gadget *);
|
|
|
|
/* FIXME support safe rmmod */
|
|
struct device_driver driver;
|
|
};
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* driver modules register and unregister, as usual.
|
|
* these calls must be made in a context that can sleep.
|
|
*
|
|
* these will usually be implemented directly by the hardware-dependent
|
|
* usb bus interface driver, which will only support a single driver.
|
|
*/
|
|
|
|
/**
|
|
* usb_gadget_probe_driver - probe a gadget driver
|
|
* @driver: the driver being registered
|
|
* @bind: the driver's bind callback
|
|
* Context: can sleep
|
|
*
|
|
* Call this in your gadget driver's module initialization function,
|
|
* to tell the underlying usb controller driver about your driver.
|
|
* The @bind() function will be called to bind it to a gadget before this
|
|
* registration call returns. It's expected that the @bind() function will
|
|
* be in init sections.
|
|
*/
|
|
int usb_gadget_probe_driver(struct usb_gadget_driver *driver,
|
|
int (*bind)(struct usb_gadget *));
|
|
|
|
/**
|
|
* usb_gadget_unregister_driver - unregister a gadget driver
|
|
* @driver:the driver being unregistered
|
|
* Context: can sleep
|
|
*
|
|
* Call this in your gadget driver's module cleanup function,
|
|
* to tell the underlying usb controller that your driver is
|
|
* going away. If the controller is connected to a USB host,
|
|
* it will first disconnect(). The driver is also requested
|
|
* to unbind() and clean up any device state, before this procedure
|
|
* finally returns. It's expected that the unbind() functions
|
|
* will in in exit sections, so may not be linked in some kernels.
|
|
*/
|
|
int usb_gadget_unregister_driver(struct usb_gadget_driver *driver);
|
|
|
|
extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget);
|
|
extern void usb_del_gadget_udc(struct usb_gadget *gadget);
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* utility to simplify dealing with string descriptors */
|
|
|
|
/**
|
|
* struct usb_string - wraps a C string and its USB id
|
|
* @id:the (nonzero) ID for this string
|
|
* @s:the string, in UTF-8 encoding
|
|
*
|
|
* If you're using usb_gadget_get_string(), use this to wrap a string
|
|
* together with its ID.
|
|
*/
|
|
struct usb_string {
|
|
u8 id;
|
|
const char *s;
|
|
};
|
|
|
|
/**
|
|
* struct usb_gadget_strings - a set of USB strings in a given language
|
|
* @language:identifies the strings' language (0x0409 for en-us)
|
|
* @strings:array of strings with their ids
|
|
*
|
|
* If you're using usb_gadget_get_string(), use this to wrap all the
|
|
* strings for a given language.
|
|
*/
|
|
struct usb_gadget_strings {
|
|
u16 language; /* 0x0409 for en-us */
|
|
struct usb_string *strings;
|
|
};
|
|
|
|
/* put descriptor for string with that id into buf (buflen >= 256) */
|
|
int usb_gadget_get_string(struct usb_gadget_strings *table, int id, u8 *buf);
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* utility to simplify managing config descriptors */
|
|
|
|
/* Find and fill the requested descriptor into buffer */
|
|
int
|
|
usb_find_descriptor_fillbuf(void *, unsigned,
|
|
const struct usb_descriptor_header **, u8);
|
|
|
|
/* write vector of descriptors into buffer */
|
|
int usb_descriptor_fillbuf(void *, unsigned,
|
|
const struct usb_descriptor_header **);
|
|
|
|
/* build config descriptor from single descriptor vector */
|
|
int usb_gadget_config_buf(const struct usb_config_descriptor *config,
|
|
void *buf, unsigned buflen, const struct usb_descriptor_header **desc);
|
|
|
|
/* copy a NULL-terminated vector of descriptors */
|
|
struct usb_descriptor_header **usb_copy_descriptors(
|
|
struct usb_descriptor_header **);
|
|
|
|
/**
|
|
* usb_free_descriptors - free descriptors returned by usb_copy_descriptors()
|
|
* @v: vector of descriptors
|
|
*/
|
|
static inline void usb_free_descriptors(struct usb_descriptor_header **v)
|
|
{
|
|
kfree(v);
|
|
}
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
/* utility wrapping a simple endpoint selection policy */
|
|
|
|
extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *,
|
|
struct usb_endpoint_descriptor *);
|
|
|
|
|
|
extern struct usb_ep *usb_ep_autoconfig_ss(struct usb_gadget *,
|
|
struct usb_endpoint_descriptor *,
|
|
struct usb_ss_ep_comp_descriptor *);
|
|
|
|
extern void usb_ep_autoconfig_reset(struct usb_gadget *);
|
|
|
|
#endif /* __LINUX_USB_GADGET_H */
|