usb: dwc3: gadget: clear stall when disabling endpoint

[ Upstream commit 687ef9817df7ed960d14575b9033dde3d04631fe ]

so it seems like DWC3 IP doesn't clear stalls
automatically when we disable an endpoint, because
of that, we _must_ make sure stalls are cleared
before clearing the proper bit in DALEPENA register.

Cc: <stable@vger.kernel.org> # v3.4+
Reported-by: Johannes Stezenbach <js@sig21.net>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: dwc3: core: refactor PHY initialization

[ Upstream commit 3c9f94aca66aa8c83d531961ea8c7b8bace9433c ]

our probe() routine is too large and we can
easily refactor PHY-related code out to another
function to make it slightly less painful to read.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: phy: mv-u3d: switch over to writel/readl

[ Upstream commit 041832565e405d2e2ea218632b7bcafa87deaece ]

by removing the _relaxed suffix, we can build
this driver in other architectures.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: dwc3: core: refactor mode initialization to its own function

[ Upstream commit 5f94adfeed97a62f31a25d14effc6ac13c847333 ]

Move mode (Host, Peripheral, OTG) initialization
to its own function in order to decrease the size
of our probe() routine.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: gadget: only GPL drivers in the gadget and phy framework

[ Upstream commit 0700faaf736492bd203630d179b639a1f5bbb576 ]

We only support GPL drivers in the USB Gadget Framework,
it sounds correct to make all exported symbols GPL too.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: phy: rename usb_nop_xceiv to usb_phy_generic

[ Upstream commit 4525beeb9aadbb9e1cb3e9e135f4371553f26a70 ]

no functional changes, just renaming the function
in order to make it slightly clearer what it should
be used for, also matching the driver name.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: phy: rename <linux/usb/usb_phy_gen_xceiv.h> to <linux/usb/usb_phy_generic.h>

[ Upstream commit d7078df6be6e9e5e3ac354859f5b8d60114391b4 ]

now that all functions match the driver name,
the only missing piece is to rename the header
file itself.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: musb: move usb_phy_generic_{un,}register calls to probe()/remove()

[ Upstream commit e741e637a85a802a93125dca1ecf324bc414101b ]

This patch is in preparation to supporting
calling those functions multiple times.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: phy: generic: allow multiples calls to usb_phy_generic_register()

[ Upstream commit 2f36ff6915c6c00df8b9962d9c6c7992befcf8ce ]

it's now very easy to return a platform_device pointer
and have the caller pass it as argument when calling
usb_phy_generic_unregister().

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: phy: generic: switch over to IS_ENABLED()

[ Upstream commit dca769bd5a76e9e634cc36987760306846153cac ]

when checking if our generic PHY is enabled,
it's a lot easier to use IS_ENABLED() instead
of manually checking for it. While at that, also
remove the bogus defined(MODULE) at the end of
the line.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: gadget: gr_udc: improve platform_device variable name

[ Upstream commit 22876266de43ec24ae93f635490c40edabaf8278 ]

Rename struct platform_device pointers from ofdev to pdev for clarity,
while at that, also use platform_set/get_drvdata() helpers.

Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: gadget: gr_udc: Expand devicetree documentation

[ Upstream commit d9a6ef1bb27e589ec40f792f3e742c3f54cbdb28 ]

Provide more information on the two different interrupt cases and more
information of endpoint buffer sizes. Suggested by Mark Rutland.

Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: gadget: gr_udc: Use platform_get_irq instead of irq_of_parse_and_map

[ Upstream commit 196800da39a142e2952ad5e1cb58a84838956764 ]

Use platform_get_irq as no mapping needs to be done. No functional difference
for SPARC which is the typical environment for the driver though. Suggested by
Mark Rutland.

Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: gadget: gr_udc: Use of_property_read_u32_index to access arrays

[ Upstream commit 73e1c093e83a421d24d54a94cb87031e7c222cd1 ]

Use an appropriate accessor function for property arrays to make the code nicer
and make the code correct if it would ever run on little endian architectures.
Suggested by Mark Rutland.

Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: gadget: gr_udc: Add ep.maxpacket_limit to debugfs information

[ Upstream commit 5bddbd72c6c02498aba8b48527c86d1398dba3f4 ]

Add information on ep.maxpacket_limit for each endpoint in the debugfs
information.

Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: gadget: gr_udc: Return error code when trying to set ep.maxpacket > ep.maxpacket_limit

[ Upstream commit b38d27e5527c33a2a1f5bb3aee39b755e57dea86 ]

Make gr_ep_enable fail properly when a call requests a larger ep.maxpacket than
ep.maxpacket_limit.

Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: gadget: gr_udc: Use GFP_ATOMIC when allocating under held spinlock

[ Upstream commit 8652bcbfa09ca5ba24423c7c45c28b7d8771e0a8 ]

As gr_ep_init must be called with dev->lock held, GFP_KERNEL must not be used.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: musb: add reset hook to platform ops

[ Upstream commit 1e42d20c88f2f56c0d81363d7b0f1d3762037f53 ]

Babble interrupts require us to reset the DSPS glue layer. In order to
handle all other recovery tasks independently, add a new hook for
platform-specific implementations of the actual reset.

Signed-off-by: Daniel Mack <zonque@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: musb: add a work_struct to recover from babble errors

[ Upstream commit ca88fc2ef0d790a1da37804219102336f7622b97 ]

Handle BABBLE interrupt error conditions from a work struct handler.
This indirection is necessary as we can't be certain that the phy
functions don't sleep.

Platform layer implementation may pass a babble error down to the core
in order to handle it.

Signed-off-by: Daniel Mack <zonque@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
usb: musb: dsps: handle babble interrupts

[ Upstream commit 1d57de306e1f3e73c607811a974f6662162e5df6 ]

When the dsps isr sees a babble error, pass it down to the core for
fixup. Also, provide a .reset hook so the core can call us back.

A babble interrupt error occured when a USB mass storage device
("CHIPSBNK v3.3.9.1", 1e3d:2093) was disconnected from a AM33xx host.

Signed-off-by: Daniel Mack <zonque@gmail.com>
Reported-by: Thomas Mellenthin <mellenthin@teufel.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>