History log of /linux-master/drivers/usb/musb/musb_gadget.c
Revision Date Author Comments
# 2e021179 29-Feb-2024 Colin Ian King <colin.i.king@gmail.com>

usb: musb: remove unused variable 'count'

The variable count is being initialized and incremented but it is never
actually referenced in any other way. The variable is redundant and can
be removed.

Cleans up clang scan build warning:
drivers/usb/musb/musb_gadget.c:1747:12: warning: variable 'count' set
but not used [-Wunused-but-set-variable]

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Link: https://lore.kernel.org/r/20240229115548.218713-1-colin.i.king@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 9de17578 04-Aug-2023 Ruan Jinjie <ruanjinjie@huawei.com>

usb: musb: Remove an unnecessary NULL value

The NULL initialization of the pointers assigned by kzalloc() first is
not necessary, because if the kzalloc() failed, the pointers will be
assigned NULL, otherwise it works as usual. so remove it.

Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
Link: https://lore.kernel.org/r/20230804093253.91647-5-ruanjinjie@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# ecec4b20 25-Nov-2022 Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>

usb: musb: remove extra check in musb_gadget_vbus_draw

The checks for musb->xceiv and musb->xceiv->set_power duplicate those in
usb_phy_set_power(), so there is no need of them. Moreover, not calling
usb_phy_set_power() results in usb_phy_set_charger_current() not being
called, so current USB config max current is not propagated through USB
charger framework and charger drivers may try to draw more current than
allowed or possible.

Fix that by removing those extra checks and calling usb_phy_set_power()
directly.

Tested on Motorola Droid4 and Nokia N900

Fixes: a9081a008f84 ("usb: phy: Add USB charger support")
Cc: stable <stable@kernel.org>
Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Link: https://lore.kernel.org/r/1669400475-4762-1-git-send-email-ivo.g.dimitrov.75@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 0afddf1e 26-Oct-2022 Paul Cercueil <paul@crapouillou.net>

usb: musb: Support setting OTG mode using generic PHY

When musb->xceiv is not provided but musb->phy is, support setting the
OTG mode (host, peripheral) using the generic PHY framework.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/20221026182657.146630-5-paul@crapouillou.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# a6d45ea0 26-Oct-2022 Paul Cercueil <paul@crapouillou.net>

usb: musb: Allow running without CONFIG_USB_PHY

Modify the core so that musb->xceiv is never deferenced without being
checked first.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/20221026182657.146630-4-paul@crapouillou.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 285f28bf 26-Oct-2022 Paul Cercueil <paul@crapouillou.net>

usb: musb: Add and use inline function musb_otg_state_string

The musb_otg_state_string() simply calls usb_otg_state_string().
This will make it easier to get rid of the musb->xceiv dependency later.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/20221026182657.146630-3-paul@crapouillou.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 21acc656 26-Oct-2022 Paul Cercueil <paul@crapouillou.net>

usb: musb: Add and use inline functions musb_{get,set}_state

Instead of manipulating musb->xceiv->otg->state directly, use the newly
introduced musb_get_state() and musb_set_state() inline functions.

Later, these inline functions will be modified to get rid of the
musb->xceiv dependency, which prevents the musb code from using the
generic PHY subsystem.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/20221026182657.146630-2-paul@crapouillou.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# eea4c860 05-Sep-2022 Robin Guo <guoweibin@inspur.com>

usb: musb: Fix musb_gadget.c rxstate overflow bug

The usb function device call musb_gadget_queue() adds the passed
request to musb_ep::req_list,If the (request->length > musb_ep->packet_sz)
and (is_buffer_mapped(req) return false),the rxstate() will copy all data
in fifo to request->buf which may cause request->buf out of bounds.

Fix it by add the length check :
fifocnt = min_t(unsigned, request->length - request->actual, fifocnt);

Signed-off-by: Robin Guo <guoweibin@inspur.com>
Link: https://lore.kernel.org/r/20220906102119.1b071d07a8391ff115e6d1ef@inspur.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 757bdf1f 08-Jun-2022 Saurav Girepunje <saurav.girepunje@gmail.com>

usb: musb: remove schedule work called after flush

In musb_remove() cancel_delayed_work_sync(&musb->irq_work)
is called which flush the irq_work work queue.

After cancel delayed work, musb_remove() call
musb_gadget_cleanup->usb_del_gadget_udc->usb_del_gadget
->usb_gadget_remove_driver->usb_gadget_udc_stop->udc
->gadget->ops->udc_stop(udc->gadget);

Where musb_gadget_stop() call "schedule_delayed_work(&musb->irq_work, 0)”
which is already cancel/flush.

So remove the schedule_delayed_work(&musb->irq_work, 0);
from musb_gadget_stop function.

Signed-off-by: Saurav Girepunje <saurav.girepunje@gmail.com>
Link: https://lore.kernel.org/r/YqDnxkWZV2KfZh5q@Sauravs-MacBook-Air.local
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 21b5fcdc 21-Oct-2021 Viraj Shah <viraj.shah@linutronix.de>

usb: musb: Balance list entry in musb_gadget_queue

musb_gadget_queue() adds the passed request to musb_ep::req_list. If the
endpoint is idle and it is the first request then it invokes
musb_queue_resume_work(). If the function returns an error then the
error is passed to the caller without any clean-up and the request
remains enqueued on the list. If the caller enqueues the request again
then the list corrupts.

Remove the request from the list on error.

Fixes: ea2f35c01d5ea ("usb: musb: Fix sleeping function called from invalid context for hdrc glue")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Viraj Shah <viraj.shah@linutronix.de>
Link: https://lore.kernel.org/r/20211021093644.4734-1-viraj.shah@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 0826dae3 07-May-2021 Saurav Girepunje <saurav.girepunje@gmail.com>

usb: musb: Fix spelling mistake "tranfer" -> "transfer"

Fix spelling mistake "tranfer" -> "transfer" in musb_gadget.c file.

Signed-off-by: Saurav Girepunje <saurav.girepunje@gmail.com>
Link: https://lore.kernel.org/r/20210508072156.GA14656@user
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# ae2938c3 23-Jan-2021 Paul Cercueil <paul@crapouillou.net>

usb: musb: Fix NULL check on struct musb_request field

The 'request' variable is a pointer to the 'request' field of the
struct musb_request 'req' pointer. It only worked until now because
the 'request' field is the first one in the musb_request structure, but
as soon as that changes, the check will be invalid.

Fix it preventively by doing the NULL-check on the 'req' pointer
instead.

Suggested-by: Maarten ter Huurne <maarten@treewalker.org>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/20210123142502.16980-2-paul@crapouillou.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# c1aa81da 24-Oct-2019 Geert Uytterhoeven <geert+renesas@glider.be>

usb: Spelling s/enpoint/endpoint/

Fix misspellings of "endpoint".

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Li Yang <leoyang.li@nxp.com>
Acked-by: Minas Harutyunyan <hminas@synopsys.com>
Link: https://lore.kernel.org/r/20191024152833.30698-1-geert+renesas@glider.be
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 29e56c0c 02-Oct-2019 Saurav Girepunje <saurav.girepunje@gmail.com>

usb: musb: musb_gadget.c: Remove unused variable

Remove unused variable status from musb_gadget_disable().

Signed-off-by: Saurav Girepunje <saurav.girepunje@gmail.com>
Link: https://lore.kernel.org/r/20191002143241.GA11615@saurav
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# c418fd6c 30-Jan-2019 Paul Elder <paul.elder@ideasonboard.com>

usb: gadget: musb: fix short isoc packets with inventra dma

Handling short packets (length < max packet size) in the Inventra DMA
engine in the MUSB driver causes the MUSB DMA controller to hang. An
example of a problem that is caused by this problem is when streaming
video out of a UVC gadget, only the first video frame is transferred.

For short packets (mode-0 or mode-1 DMA), MUSB_TXCSR_TXPKTRDY must be
set manually by the driver. This was previously done in musb_g_tx
(musb_gadget.c), but incorrectly (all csr flags were cleared, and only
MUSB_TXCSR_MODE and MUSB_TXCSR_TXPKTRDY were set). Fixing that problem
allows some requests to be transferred correctly, but multiple requests
were often put together in one USB packet, and caused problems if the
packet size was not a multiple of 4. Instead, set MUSB_TXCSR_TXPKTRDY
in dma_controller_irq (musbhsdma.c), just like host mode transfers.

This topic was originally tackled by Nicolas Boichat [0] [1] and is
discussed further at [2] as part of his GSoC project [3].

[0] https://groups.google.com/forum/?hl=en#!topic/beagleboard-gsoc/k8Azwfp75CU
[1] https://gitorious.org/beagleboard-usbsniffer/beagleboard-usbsniffer-kernel/commit/b0be3b6cc195ba732189b04f1d43ec843c3e54c9?p=beagleboard-usbsniffer:beagleboard-usbsniffer-kernel.git;a=patch;h=b0be3b6cc195ba732189b04f1d43ec843c3e54c9
[2] http://beagleboard-usbsniffer.blogspot.com/2010/07/musb-isochronous-transfers-fixed.html
[3] http://elinux.org/BeagleBoard/GSoC/USBSniffer

Fixes: 550a7375fe72 ("USB: Add MUSB and TUSB support")
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Bin Liu <b-liu@ti.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 0a9134bd 21-May-2018 Bin Liu <b-liu@ti.com>

usb: musb: disable otg protocol support

As decided in the discussion [1] we are deleting the otg protocol
support from the musb drivers.

First this patch disables the flags for enabling the otg protocols. We
will later gradually delete the otg protocol code from the musb drivers.

[1] https://www.spinics.net/lists/linux-usb/msg167003.html

Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# d2852f2d 21-May-2018 Bin Liu <b-liu@ti.com>

usb: musb: remove references to default_a of struct usb_otg

musb drivers do not use the otg fsm framework, so referencing to
otg->default_a doesn't have any effect, so remove the references.

But tusb6010 glue driver uses it locally to control the vbus power, so
keep the references in tusb6010 only.

Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 7ad76955 21-May-2018 Bin Liu <b-liu@ti.com>

usb: musb: remove duplicated port mode enum

include/linux/usb/musb.h already defines enum for musb port mode, so
remove the duplicate in musb_core.h and use the definition in musb.h.

Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 9aea9b6c 30-Apr-2018 Bin Liu <b-liu@ti.com>

usb: musb: trace: fix NULL pointer dereference in musb_g_tx()

The usb_request pointer could be NULL in musb_g_tx(), where the
tracepoint call would trigger the NULL pointer dereference failure when
parsing the members of the usb_request pointer.

Move the tracepoint call to where the usb_request pointer is already
checked to solve the issue.

Fixes: fc78003e5345 ("usb: musb: gadget: add usb-request tracepoints")
Cc: stable@vger.kernel.org # v4.8+
Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# a9762b70 09-Mar-2018 Arnd Bergmann <arnd@arndb.de>

usb: musb: remove blackfin port

The blackfin architecture is getting removed, so we can clean up
all the special cases in the musb driver.

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Aaron Wu <aaron.wu@analog.com>
Acked-by: Bin Liu <b-liu@ti.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
[arnd: adding in fixups from Aaron and Stephen]
Signed-off-by: Arnd Bergmann <arnd@arndb.de>


# 21b650c2 06-Nov-2017 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

USB: musb: Remove redundant license text

Now that the SPDX tag is in all USB files, that identifies the license
in a specific and legally-defined manner. So the extra GPL text wording
can be removed as it is no longer needed at all.

This is done on a quest to remove the 700+ different ways that files in
the kernel describe the GPL license text. And there's unneeded stuff
like the address (sometimes incorrect) for the FSF which is never
needed.

No copyright headers or other non-license-description text was removed.

Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
Cc: Chen-Yu Tsai <wens@csie.org>
Acked-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 5fd54ace 03-Nov-2017 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

USB: add SPDX identifiers to all remaining files in drivers/usb/

It's good to have SPDX identifiers in all files to make it easier to
audit the kernel tree for correct licenses.

Update the drivers/usb/ and include/linux/usb* files with the correct
SPDX license identifier based on the license text in the file itself.
The SPDX identifier is a legally binding shorthand, which can be used
instead of the full boiler plate text.

This work is based on a script and data from Thomas Gleixner, Philippe
Ombredanne, and Kate Stewart.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Acked-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 0ccbadaf 24-Aug-2017 Bin Liu <b-liu@ti.com>

usb: musb: add helper function musb_ep_xfertype_string

Add helper function musb_ep_xfertype_string() to return the ep transfer
type string.

Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 2bff3916 16-Nov-2016 Tony Lindgren <tony@atomide.com>

usb: musb: Fix PM for hub disconnect

With a USB hub disconnected, devctl can be 0x19 for about a second
on am335x and will stay forever on at least omap3. And we get no
further interrupts when devctl session bit clears. This keeps
PM runtime active.

Let's fix the issue by polling devctl until the session bit clears
or times out. We can do this by making musb->irq_work into
delayed_work.

And with the polling implemented, we can now also have the quirk
for invalid VBUS it to avoid disconnecting too early while VBUS
is ramping up.

Fixes: 467d5c980709 ("usb: musb: Implement session bit based runtime
PM for musb-core")
Fixes: 65b3f50ed6fa ("usb: musb: Add PM runtime support for MUSB DSPS
Tested-by: Ladislav Michl <ladis@linux-mips.org>
Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# ea2f35c0 16-Nov-2016 Tony Lindgren <tony@atomide.com>

usb: musb: Fix sleeping function called from invalid context for hdrc glue

Commit 65b3f50ed6fa ("usb: musb: Add PM runtime support for MUSB DSPS
glue layer") wrongly added a call for pm_runtime_get_sync to otg_timer
that runs in softirq context. That causes a "BUG: sleeping function called
from invalid context" every time when polling the cable status:

[<c015ebb4>] (__might_sleep) from [<c0413d60>] (__pm_runtime_resume+0x9c/0xa0)
[<c0413d60>] (__pm_runtime_resume) from [<c04d0bc4>] (otg_timer+0x3c/0x254)
[<c04d0bc4>] (otg_timer) from [<c0191180>] (call_timer_fn+0xfc/0x41c)
[<c0191180>] (call_timer_fn) from [<c01915c0>] (expire_timers+0x120/0x210)
[<c01915c0>] (expire_timers) from [<c0191acc>] (run_timer_softirq+0xa4/0xdc)
[<c0191acc>] (run_timer_softirq) from [<c010168c>] (__do_softirq+0x12c/0x594)

I did not notice that as I did not have CONFIG_DEBUG_ATOMIC_SLEEP enabled.
And looks like also musb_gadget_queue() suffers from the same problem.

Let's fix the issue by using a list of delayed work then call it on
resume. Note that we want to do this only when musb core and it's
parent devices are awake, and we need to make sure the DSPS glue
timer is stopped as noted by Johan Hovold <johan@kernel.org>.
Note that we already are re-enabling the timer with mod_timer() in
dsps_musb_enable().

Later on we may be able to remove other delayed work in the musb driver
and just do it from pending_resume_work. But this should be done only
for delayed work that does not have other timing requirements beyond
just being run on resume.

Fixes: 65b3f50ed6fa ("usb: musb: Add PM runtime support for MUSB DSPS
glue layer")
Reported-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Johan Hovold <johan@kernel.org>
Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 6ddcabc2 28-Sep-2016 Felipe Balbi <felipe.balbi@linux.intel.com>

usb: musb: make use of new usb_endpoint_maxp_mult()

We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

Cc: Bin Liu <b-liu@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>


# cacaaf80 18-Oct-2016 Tony Lindgren <tony@atomide.com>

usb: musb: Call pm_runtime from musb_gadget_queue

If we're booting pandaboard using NFSroot over built-in g_ether, we
can get the following after booting once and doing a warm reset:

g_ether gadget: ecm_open
g_ether gadget: notify connect true
...
WARNING: CPU: 0 PID: 1 at drivers/bus/omap_l3_noc.c:147
l3_interrupt_handler+0x220/0x34c
44000000.ocp:L3 Custom Error: MASTER MPU TARGET L4CFG (Read):
Data Access in User mode du ring Functional access
...

Fix the issue by calling pm_runtime functions from
musb_gadget_queue.

Note that in the long run we should be able to queue the pending
transfers if pm_runtime is not active, and flush the queue from
pm_runtime_resume.

Reported-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 4e719183 22-Sep-2016 Tony Lindgren <tony@atomide.com>

usb: musb: Fix PM runtime for disconnect after unconfigure

If we unconfigure musb as a USB peripheral with cable connected,
and then remove the cable, no interrupts will happen. And musb
thinks we're still connected keeping the device active.

Now with the session bit based PM runtime working for musb, we
can fix this issue by calling musb irq_work. That rechecks the
devctl register and reconfigures PM runtime based on the devctl.

Fixes: 467d5c980709 ("usb: musb: Implement session bit based runtime PM for musb-core")
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# fc78003e 29-Jun-2016 Bin Liu <b-liu@ti.com>

usb: musb: gadget: add usb-request tracepoints

Add usb_request tracepoints for gadget mode.

Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# b99d3659 29-Jun-2016 Bin Liu <b-liu@ti.com>

usb: musb: switch dev_dbg to tracepoints

Switch dev_dbg() to tracepoint debug musb_dbg().

Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 517bafff 31-May-2016 Tony Lindgren <tony@atomide.com>

usb: musb: Use delayed for musb_gadget_pullup

We have MUSB setting pm_runtime_irq_safe with the following
commits:

30a70b026b4c ("usb: musb: fix obex in g_nokia.ko causing kernel panic")
3e43a0725637 ("usb: musb: core: add pm_runtime_irq_safe()")

Let's fix things to use delayed work so we can remove the
pm_runtime_irq_safe.

Note that we may want to set this up in a generic way in the
gadget framework eventually.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 30647217 31-May-2016 Tony Lindgren <tony@atomide.com>

usb: musb: Remove conditional PM runtime calls for musb_gadget

The conditional use of PM runtime does not work properly
for musb gadget. On cable disconnect we may not get any
USB_EVENT_NONE leaving the PM runtime call unpaired.

Let's fix the issue by making sure the PM runtime calls are
paired within the functions. The glue layer will take care
of the rest.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 7099dbc5 31-May-2016 Tony Lindgren <tony@atomide.com>

usb: musb: Update to use PM runtime autosuspend

Let's make the PM runtime use the standard autosuspend calls.
Commit 5de85b9d57ab ("PM / runtime: Re-init runtime PM states at probe
error and driver unbind") means we must pair use_autosuspend with
dont_use_autosuspend and then use put_sync to properly idle the
device.

Note that we'll be removing the PM runtime calls from the glue
layer to the MUSB core in the next patch. And we can also remove
the pointless FIXME comment now.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 607fb0f4 25-Apr-2016 Tal Shorer <tal.shorer@gmail.com>

usb: musb: gadget: nuke endpoint before setting its descriptor to NULL

Some functions, such as f_sourcesink, rely on an endpoint's desc
field during their requests' complete() callback, so clear it only
_after_ nuking all requests to avoid NULL pointer dereference.

Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 1a171626 10-Dec-2015 Geyslan G. Bem <geyslan@gmail.com>

usb: musb: gadget: remove redundant condition

This patch removes redundant condition.

(!A || (A && B)) is the same as (!A || B).

Fixes indentation too.

Tested by: compilation only
Caught by: cppcheck

Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 2f3cc24f 07-Aug-2015 Robert Baldyga <r.baldyga@samsung.com>

usb: musb: gadget: fix build break by adding missing 'break'

Add missing break after 'default' label to fix compilation error.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 03840fad 06-Aug-2015 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: remove remaining DMA ifdeferry

Commit fb91cddc54e7 ("usb: musb: Remove DMA
ifdef for musb_gadget.c short_packet") tried
to remove DMA ifdeferry from musb_gadget.c
but ended up leaving some around.

Remove them so that when building kernels with
all DMA engines enabled, we don't end up trying
to allocte channels twice.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 26b8aa45 06-Aug-2015 Robert Baldyga <r.baldyga@samsung.com>

usb: musb: gadget: add musb_match_ep() function

Add 'match_ep' callback to utilize chip-specific knowledge in endpoint matching
process. Function does the same that was done by chip-specific code inside
of epautoconf. Now this code can be removed from there to separate generic code
from platform specific logic.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 8501955e 31-Jul-2015 Robert Baldyga <r.baldyga@samsung.com>

usb: musb: gadget: add ep capabilities support

Convert endpoint configuration to new capabilities model.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# ca1023c8 27-Jul-2015 Robert Baldyga <r.baldyga@samsung.com>

usb: gadget: add 'quirk_zlp_not_supp' to usb_gadget

Due to some UDC controllers may not support zlp, usb gadget layer
needs to provide a generic way to inform gadget functions about non-standard
hardware limitations.

This patch adds 'quirk_zlp_not_supp' field to struct usb_gadget and helper
function gadget_is_zlp_supported(). It also sets 'quirk_zlp_not_supp'
to 1 in musb UDC driver, which has such limitation.

[ balbi@ti.com : make it build ]

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# fb91cddc 01-May-2015 Tony Lindgren <tony@atomide.com>

usb: musb: Remove DMA ifdef for musb_gadget.c short_packet

Let's get rid of the horrible ifdef in middle of the expression.
We can do it by adding a variable for short_packet and testing
it separately for DMA related code.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# f8e9f34f 01-May-2015 Tony Lindgren <tony@atomide.com>

usb: musb: Fix up DMA related macros

Pass struct musb to tusb_dma_omap() and is_cppi_enabled(),
and add macros for the other DMA controllers. Populate the
platform specific quirks with the DMA type and use it during
runtime.

Note that platform glue layers with no custom DMA code are
tagged with MUSB_DMA_INVENTRA which may have a chance of
working. Looks like the defconfigs for these use PIO_ONLY,
so this should not break existing configs.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# d5638fcf 02-Feb-2015 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: get rid of stop_activity()

that function is pretty close to a no-op by now,
all we need is a call to musb_stop().

Signed-off-by: Felipe Balbi <balbi@ti.com>


# dadac986 28-Jan-2015 Peter Chen <peter.chen@freescale.com>

usb: musb: gadget: use common is_selfpowered

Delete private selfpowered variable, and use common one.

Signed-off-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 1189f7f6 05-Nov-2014 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: use udc-core's reset notifier

Replace usb_gadget_driver's disconnect with udc-core's reset notifier at
bus reset handler.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# e47d9254 30-Oct-2014 Antoine Tenart <atenart@kernel.org>

usb: move the OTG state from the USB PHY to the OTG structure

Before using the PHY framework instead of the USB PHY one, we need to
move the OTG state into another place, since it won't be available when
USB PHY isn't used. This patch moves the OTG state into the OTG
structure, and makes all the needed modifications in the drivers
using the OTG state.

[ balbi@ti.com : fix build regressions with phy-tahvo.c, musb_dsps.c,
phy-isp1301-omap, and chipidea's debug.c ]

Acked-by: Kishon Vijay Abraham I <kishon@ti.com>
Acked-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Antoine Tenart <antoine.tenart@free-electrons.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 22835b80 16-Oct-2014 Felipe Balbi <balbi@ti.com>

usb: gadget: remove unnecessary 'driver' argument

now that no UDC driver relies on the extra
'driver' argument to ->udc_stop(), we can
safely remove it.

This commit is based on previous work by
Robert Baldyga <r.baldyga@samsung.com> which
can be found at [1]; however that patch turned
out to have a high probability of regressing
many UDC drivers because of a blind search & replace
s/driver/$udc->driver/ which caused the 'driver'
argument to stop_activity() to be a valid non-NULL
pointer when it should be NULL, thus causing UDCs
to mistakenly call gadget driver's ->disconnect()
callback.

[1] http://markmail.org/message/x5zneg4xea4zntab

Acked-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# fae5afb9 17-Oct-2014 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: remove bind/unbind messages

now that we provide generic register/unregister
debugging messages from udc-core, we can remove
the same messages from this driver.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 69e28882 17-Oct-2014 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: do not rely on 'driver' argument

future patches will remove the extra 'driver'
argument to ->udc_stop(), in order to do that,
we must make sure that our UDC does not rely
on it first.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 304f7e5e 24-Sep-2014 Michal Sojka <sojka@merica.cz>

usb: gadget: Refactor request completion

Use the recently introduced usb_gadget_giveback_request() in favor of
direct invocation of the completion routine.

All places in drivers/usb/ matching "[-.]complete(" were replaced with a
call to usb_gadget_giveback_request(). This was compile-tested with all
ARM drivers enabled and runtime-tested for musb.

Signed-off-by: Michal Sojka <sojka@merica.cz>
Acked-by: Felipe Balbi <balbi@ti.com>
Tested-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 23db9fd2 19-Dec-2013 Apelete Seketeli <apelete@seketeli.net>

usb: musb: fix setting JZ4740 gadget periphal mode on reset

JZ4740 USB Device Controller is not OTG compatible and does not have
DEVCTL register in silicon.

During ethernet-over-usb transactions, on reset, musb driver tries to
read from DEVCTL and consequently sets device as host (A-Device)
instead of peripheral (B-Device), which makes it a composite device to
the USB gadget driver.
This induces a kernel panic during power down where the USB gadget
driver does a null pointer dereference when trying to access the
composite device configuration.

On reset, do not rely on DEVCTL value for setting gadget peripheral
mode. Use is_otg flag instead to set it to B-Device.

Signed-off-by: Apelete Seketeli <apelete@seketeli.net>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# e117e742 12-Dec-2013 Robert Baldyga <r.baldyga@samsung.com>

usb: gadget: add "maxpacket_limit" field to struct usb_ep

This patch adds "maxpacket_limit" to struct usb_ep. This field contains
maximum value of maxpacket supported by driver, and is set in driver probe.
This value should be used by autoconfig() function, because value of field
"maxpacket" is set to value from endpoint descriptor when endpoint becomes
enabled. So when autoconfig() function will be called again for this endpoint,
"maxpacket" value will contain wMaxPacketSize from descriptior instead of
maximum packet size for this endpoint.

For this reason this patch adds new field "maxpacket_limit" which contains
value of maximum packet size (which defines maximum endpoint capabilities).
This value is used in ep_matches() function used by autoconfig().

Value of "maxpacket_limit" should be set in UDC driver probe function, using
usb_ep_set_maxpacket_limit() function, defined in gadget.h. This function
set choosen value to both "maxpacket_limit" and "maxpacket" fields.

This patch modifies UDC drivers by adding support for maxpacket_limit.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# fd3923a9 19-Nov-2013 Apelete Seketeli <apelete@seketeli.net>

usb: fix musb gadget to enable OTG mode conditionally

The musb driver is usable in host, gadget or dual role mode depending
on the kernel configuration.

However, the musb gadget part of the driver is enabling OTG mode
whether the driver is built for dual role or gadget only mode. This
induces a bug for gadget only USB device controllers where the kernel
tries to use Host Negotiation Protocol with such controllers, which
causes a panic.

This behaviour is now fixed by enabling OTG mode only when musb driver
is built for dual role mode.

Signed-off-by: Apelete Seketeli <apelete@seketeli.net>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 43e699ce 14-Oct-2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Revert "usb: musb: gadget: fix otg active status flag"

This reverts commit 9b0a1de3c85d99d881c86a29b3d52da7b9c7bd61.

Aaro writes:
With v3.12-rc4 I can no longer connect to N800 (OMAP2) with USB
(peripheral, g_ether).

According to git bisect this is caused by:

9b0a1de3c85d99d881c86a29b3d52da7b9c7bd61 is the first bad commit

So revert this patch, as Felipe says:
It's unfortunate that tusb6010 is so messed up

Reported-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Acked-by: Felipe Balbi <balbi@ti.com>
Cc: Bin Liu <b-liu@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 2b84f92b 08-Oct-2013 Joe Perches <joe@perches.com>

usb: Remove unnecessary semicolons

These aren't necessary after switch and if blocks.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 001dd84a 11-Oct-2013 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

usb: musb: start musb on the udc side, too

I have am335x-evm with one port running in OTG mode. Since commit
fe4cb09 ("usb: musb: gadget: remove hcd initialization") the loaded
gadget does non pop up on the host. All I see is
|usb 4-5: new high-speed USB device number 52 using ehci-pci
|usb 4-5: device descriptor read/64, error -110

Since a later commit 2cc65fe ("usb: musb: add musb_host_setup() and
musb_host_cleanup()) the gadget shows up on the host again but only
in OTG mode (because we have the host init code running). It does not
work in device only mode.
If running in OTG mode and the gadget is removed and added back (rmmod
followed by modprobe of a gadget) then the same error is pops up on the
host side.

This patch ensures that the gadget side also executes musb_start() which
puts the chip in "connect accept" mode. With this change the device
works in OTG & device mode and the gadget can be added & removed
multiple times.
A device (if musb is in OTG mode acting as a host) is only recognized if
it is attached during module load (musb_hdrc module). After the device
unplugged and plugged again the host does not recognize it. We get a
buch of errors if musb running in OTG mode, attached to a host and no
gadget is loaded. Bah.
This is one step forward. Host & device only mode should work. I will
look at OTG later. I looked at this before commit fe4cb09 and OTG wasn't
working there perfectly so I am not sure that it is a regression :)

Cc: <stable@vger.kernel.org> # v3.11
Cc: Daniel Mack <zonque@gmail.com>
Cc: Peter Korsgaard <jacmet@sunsite.dk>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 9b0a1de3 17-Sep-2013 Bin Liu <b-liu@ti.com>

usb: musb: gadget: fix otg active status flag

In gadget mode, musb->is_active should be set only when connected to the
host. musb_g_reset() already takes care of it.

Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 1374a430 16-Sep-2013 Bin Liu <b-liu@ti.com>

usb: musb: fix otg default state

Right after the musb_hdrc driver is loaded, the otg default state
is a_idle, and Mode=Host, which are set by musb_host_setup().

This causes the following kernel message during musb gadget
enumeration.

CAUTION: musb: Babble Interrupt Occurred

This patch sets the otg default state to b_idle, and its Mode to
Peripheral.

It has been validated on TI AM335x GP EVM USB0 port with g_zero.

Signed-off-by: Bin Liu <b-liu@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 90474288 20-Aug-2013 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

usb: musb: only remove host/udc if it has been added

musb_shutdown() removes always USB host and device.
musb_init_controller() adds host and device depending on port_mode. If
port mode is set to HOST then the removal of UDC leads only to:
|(NULL device *): gadget not registered.
and nothing else happens. If port mode is set to DEVICE and we remove
the host then we oops in usb_remove_hcd().
This patch ensures that we only remove host in OTG/host mode and device
only in OTG/device mode to avoid any trouble.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# b130f03f 19-Aug-2013 Maarten ter Huurne <maarten@treewalker.org>

usb: musb: avoid null pointer dereference in debug logging

Since commit 511f3c53 (usb: gadget: udc-core: fix a regression during
gadget driver unbinding) usb_gadget_remove_driver will pass NULL for
the driver argument.

Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 7b360f42 13-Aug-2013 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

usb: musb: honour the return value of dma_map_single()

Since dma_map_single() may fail it is good to actually check the return
code to see if it succeeded.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# fc525751 13-Aug-2013 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

usb: musb: Use is_cppi_enabled() and tusb_dma_omap() instead of the ifdef

This patch makes use of the two function is_cppi_enabled() and
tusb_dma_omap() instead of the ifdef for the proper DMA implementation
setup code. It basically shifts the code right by one indention level
and adds a few line breaks once the chars are crossed.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 23a53d90 19-Jun-2013 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

usb: musb: unmap reqs in musb_gadget_queue()'s error case

If the descriptor is missing the reqeust is never unmapped. This patch
changes this and renames the cleanup label to unlock since there is no
cleanup done. The cleanup would revert the allocation of ressource (i.e.
this dma mapping) but it does not, it simply unlocks and returns.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# fe4cb091 10-Apr-2013 Daniel Mack <zonque@gmail.com>

usb: musb: gadget: remove hcd initialization

This will be done from a more appropriate location and as it doesn't
work anyway, it can safely be removed before the other changes.

Signed-off-by: Daniel Mack <zonque@gmail.com>
Acked-by: Peter Korsgaard <jacmet@sunsite.dk>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# b65ae0f1 24-Mar-2013 Grazvydas Ignotas <notasas@gmail.com>

usb: musb: gadget: use platform callback to enable vbus

On some platform configurations (like OMAP3+twl4030) it's the platform
code that enables VBUS, not OTG transceiver, so call vbus platform
callback instead, it will then call the transceiver if needed.

This fixes a use case where USB cable is plugged first and gadget
driver is loaded later after that.

Signed-off-by: Grazvydas Ignotas <notasas@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# e21de10c 09-Mar-2013 Grazvydas Ignotas <notasas@gmail.com>

usb: musb: gadget: clear gadget_driver when gadget is stopped

Some musb glue drivers use gadget_driver pointer to know if any gadget
drivers are loaded at some moment and base further decisions on it,
like to do runtime suspend/resume or not. Right now the pointer is
left alone on stop and OMAP musb glue later does wrong runtime_pm
decisions because of it.

Clear the gadget_driver pointer on remove, it's invalid after stop
anyway.

Signed-off-by: Grazvydas Ignotas <notasas@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 42c0bf1c 07-Mar-2013 Felipe Balbi <balbi@ti.com>

usb: otg: prefix otg_state_string with usb_

all other functions under drivers/usb/ start
with usb_, let's do the same thing.

This patch is in preparation for moving otg_state_string
to usb-common.c and deleting otg.c completely.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 07d83168 26-Feb-2013 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: don't assign gadget.dev.release directly

udc-core provides a better way to handle release
methods, let's use it.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 5e6e3d38 26-Feb-2013 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: remove unnecessary initializations

udc-core now sets dma-related and parent fields
for us, we don't need to do it ourselves.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 37730ecc 06-Feb-2013 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: fix compile warning

Fix the following compile warning:

drivers/usb/musb/musb_gadget.c: In function ‘rxstate’:
drivers/usb/musb/musb_gadget.c:714:22: warning: comparison of distinct pointer types lacks a cast [enabled by default]

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 38c5df22 04-Feb-2013 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: delete wrong comment

Those comments haven't been updated for a long
time, so much that they don't make sense anymore.

Best to remove them.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 7bce401c 24-Jan-2013 Felipe Balbi <balbi@ti.com>

usb: gadget: drop now unnecessary flag

We don't need the ->register_my_device flag
anymore because all UDC drivers have been
properly converted.

Let's remove every history of it.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 5ed01c64 24-Jan-2013 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: let udc-core manage gadget-dev

By simply setting a flag, we can delete a little
boilerplate code.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 06d9db72 15-Mar-2013 Kishon Vijay Abraham I <kishon@ti.com>

usb: musb: gadget: do *unmap_dma_buffer* only for valid DMA addr

musb does not use DMA buffer for ep0 but it uses the same giveback
function *musb_g_giveback* for all endpoints (*musb_g_ep0_giveback* calls
*musb_g_giveback*). So for ep0 case request.dma will be '0'
and will result in kernel OOPS if tried to *unmap_dma_buffer* for requests in
ep0. Fixed it by doing *unmap_dma_buffer* only for valid DMA addr and
checking that musb_ep->dma is valid when unmapping.

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# bb3a2ef2 05-Dec-2012 supriya karanth <supriya.karanth@stericsson.com>

usb: musb: set TXMAXP and AUTOSET for full speed bulk in device mode

The TXMAXP register is not set correctly for full speed bulk case
when the can_bulk_split() is used. Without this PIO transfers will
not take place correctly

The "mult" factor needs to be updated correctly for the
can_bulk_split() case

The AUTOSET bit in the TXCSR is not being set if the "mult"
factor is greater than 0 for the High Bandwidth ISO case.
But the "mult" factor is also greater than 0 in case of Full speed
bulk transfers with the packet splitting in TXMAXP register

Without the AUTOSET the DMA transfers will not progress in mode1

[ balbi@ti.com : add braces to both branches ]

Signed-off-by: supriya karanth <supriya.karanth@stericsson.com>
Signed-off-by: Praveena NADAHALLY <praveen.nadahally@stericsson.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 41ac7b3a 19-Nov-2012 Bill Pemberton <wfp5p@virginia.edu>

usb: remove use of __devinit

CONFIG_HOTPLUG is going away as an option so __devinit is no longer
needed.

Signed-off-by: Bill Pemberton <wfp5p@virginia.edu>
Cc: Peter Korsgaard <jacmet@sunsite.dk>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Acked-by: Felipe Balbi <balbi@ti.com>
Cc: Li Yang <leoli@freescale.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Cc: Geoff Levand <geoff@infradead.org>
Cc: Wan ZongShun <mcuos.com@gmail.com>
Cc: Olav Kongas <ok@artecdesign.ee>
Cc: Lennert Buytenhek <kernel@wantstofly.org>
Cc: Ben Dooks <ben-linux@fluff.org>
Cc: Kukjin Kim <kgene.kim@samsung.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# b18d26f6 30-Oct-2012 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

usb: musb: Perform only write access on MUSB_INTRTXE

This is part of the workaround for AM35x advisory Advisory 1.1.20.
The advisory says that the IPSS bridge can't handle 8 & 16 bit read
access. An 16bit read access to MUSB_INTRTXE results in an 32bit read
access which also reads INTRRX and therefore may lose interrupts.
This patch uses a shadow register of MUSB_INTRTXE so we only perform
write access to it.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# af5ec14d 30-Oct-2012 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

usb: musb: Perform only write access on MUSB_INTRRXE

This is part of the workaround for AM35x advisory Advisory 1.1.20.
The advisory says that the IPSS bridge can't handle 8 & 16 bit read
access. An 16bit read access to MUSB_INTRRXE results in an 32bit read
access which also reads INTRUSB and therefore may lose interrupts.
This patch uses a shadow register of MUSB_INTRRXE so we only perform
write access to it.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 515ba29c 30-Oct-2012 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

usb: musb: avoid FADDR read access

This is part of the workaround for AM35x advisory Advisory 1.1.20.
The advisory says that the IPSS bridge can't handle 8 & 16 bit read
access. An 8bit read access to FADDR results in an 32bit read
access which also reads INTRTX and therefore may lose interrupts.
This patch removes any reads to FADDR as they are not really required.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 00a89180 26-Oct-2012 Felipe Balbi <balbi@ti.com>

Revert "usb: musb: use DMA mode 1 whenever possible"

This reverts commit 4f3e8d263d34e52e75b5adfa14811467d3033d8e.

it turns out that current implementation of Mode 1
DMA added a few regressions to some users, so we
need to revert this patch and let author work on
a better version of Mode 1 DMA support.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 660fa886 07-Aug-2012 Roger Quadros <rogerq@ti.com>

usb: musb: Remove redundant if statement

Remove unnecessary if condition. No change in logic.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 032ec49f 24-Nov-2011 Felipe Balbi <balbi@ti.com>

usb: musb: drop useless board_mode usage

we are compiling the driver always with full OTG
capabilities, so that board_mode trick becomes
useless.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 4f3e8d26 07-Aug-2012 Roger Quadros <rogerq@ti.com>

usb: musb: use DMA mode 1 whenever possible

Do not rely on any hints from gadget drivers and use DMA mode 1
whenever we expect data of at least the endpoint's packet size and
have not yet received a short packet.

The last packet if short is always transferred using DMA mode 0.

This patch fixes USB throughput issues in mass storage mode for
host to device transfers.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# d17d535f 19-Jul-2012 Ajay Kumar Gupta <ajay.gupta@ti.com>

usb: musb: gadget: don't program dma for zero byte tx

This is to reduce the overhead of dma programming for zero byte
transmit as same can be done using pio mode.

Signed-off-by: Ajay Kumar Gupta <ajay.gupta@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# f0443afd 16-Jul-2012 Sergei Shtylyov <sshtylyov@ru.mvista.com>

usb: musb: gadget: use variables according to their names in rxstate()

In rxstate(), improper types are given to 'fifo_count' and 'len' variables, and
these variables are not used in accordance to their names (up to the certain
point), i.e. 'len' to hold the size of a packet in the RX FIFO, and 'fifo_count'
to hold a difference between 'request->length' and 'request->actual'...
Interchange the variables up to the point where their use starts to make sense
again.

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 08f75bf1 25-May-2012 Grazvydas Ignotas <notasas@gmail.com>

usb: musb_gadget: fix crash caused by dangling pointer

usb_ep_ops.disable must clear external copy of the endpoint descriptor,
otherwise musb crashes after loading/unloading several gadget modules
in a row:

Unable to handle kernel paging request at virtual address bf013730
pgd = c0004000
[bf013730] *pgd=8f26d811, *pte=00000000, *ppte=00000000
Internal error: Oops: 7 [#1]
Modules linked in: g_cdc [last unloaded: g_file_storage]
CPU: 0 Not tainted (3.2.17 #647)
PC is at musb_gadget_enable+0x4c/0x24c
LR is at _raw_spin_lock_irqsave+0x4c/0x58
[<c027c030>] (musb_gadget_enable+0x4c/0x24c) from [<bf01b760>] (gether_connect+0x3c/0x19c [g_cdc])
[<bf01b760>] (gether_connect+0x3c/0x19c [g_cdc]) from [<bf01ba1c>] (ecm_set_alt+0x15c/0x180 [g_cdc])
[<bf01ba1c>] (ecm_set_alt+0x15c/0x180 [g_cdc]) from [<bf01ecd4>] (composite_setup+0x85c/0xac4 [g_cdc])
[<bf01ecd4>] (composite_setup+0x85c/0xac4 [g_cdc]) from [<c027b744>] (musb_g_ep0_irq+0x844/0x924)
[<c027b744>] (musb_g_ep0_irq+0x844/0x924) from [<c027a97c>] (musb_interrupt+0x79c/0x864)
[<c027a97c>] (musb_interrupt+0x79c/0x864) from [<c027aaa8>] (generic_interrupt+0x64/0x7c)
[<c027aaa8>] (generic_interrupt+0x64/0x7c) from [<c00797cc>] (handle_irq_event_percpu+0x28/0x178)
...

Cc: stable@vger.kernel.org # v3.1+
Signed-off-by: Grazvydas Ignotas <notasas@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# abf710e6 18-May-2012 Vikram Pandita <vikram.pandita@ti.com>

usb: musb: handle nuked ep dma interrupt

User can trigger disabling of gadget at run time while the
transfers are going on.
Eg: 1: rmmod of musb driver while transfers are going on

Eg: 2: On android doing:
echo 0 > /sys/class/android_usb/android0/enable
While a big file transfer is going on via PTP/MTP.

In such a case, musb_gadget_disable() calls nuke()
but the dma interrupt may still happen for an endpoint since hw
would raise the interrupt in anycase.

This can result in a NULL pointer access crash:

[ 314.030426] PC is at txstate+0x74/0x20c
[ 314.034759] LR is at musb_g_tx+0x140/0x204
[ 314.039489] pc : [<c03506f4>] lr : [<c0350bcc>] psr: 20000193
[ 314.039520] sp : c783bc68 ip : 00000002 fp : c783bc9c
[ 314.052429] r10: 00000018 r9 : 00000000 r8 : 00000200
[ 314.058258] r7 : 00000000 r6 : fc0ab130 r5 : c781a410 r4 : c6caf640
[ 314.065643] r3 : 00000000 r2 : 00000000 r1 : 00000000 r0 : c781a000
[ 315.083251] Backtrace:
[ 315.086242] [<c0350680>] (txstate+0x0/0x20c) from [<c0350bcc>] (musb_g_tx+0x140/0x204)
[ 315.095123] [<c0350a8c>] (musb_g_tx+0x0/0x204) from [<c034eb00>] (musb_dma_completion+0x40/0x54)
[ 315.104980] [<c034eac0>] (musb_dma_completion+0x0/0x54) from [<c0351e6c>] (dma_controller_irq+0x118/0x184)
[ 315.115661] [<c0351d54>] (dma_controller_irq+0x0/0x184) from [<c00d86b8>] (handle_irq_event_percpu+0x54/0x188)

So put protection in code to handle possiblity of getting an interrupt for an
endpoint that might have been already nuked.

Reported-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Vikram Pandita <vikram.pandita@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# cd70469d 29-Feb-2012 Felipe Balbi <balbi@ti.com>

usb: core: hcd: make hcd->irq unsigned

There's really no point in having hcd->irq as a
signed integer when we consider the fact that
IRQ 0 means NO_IRQ. In order to avoid confusion,
make hcd->irq unsigned and fix users who were
passing -1 as the IRQ number to usb_add_hcd.

Tested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 6e13c650 13-Feb-2012 Heikki Krogerus <heikki.krogerus@linux.intel.com>

usb: otg: Convert all users to pass struct usb_otg for OTG functions

This changes the otg functions so that they receive struct
otg instead of struct usb_phy as parameter and
converts all users of these functions to pass the otg member
of their usb_phy.

Includes fixes to IMX code from Sascha Hauer.

[ balbi@ti.com : fixed a compile warning on ehci-mv.c ]

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: Sascha Hauer <s.hauer@pengutronix.de>
Acked-by: Igor Grinberg <grinberg@compulab.co.il>
Acked-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Acked-by: Li Yang <leoli@freescale.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Reviewed-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# b96d3b08 13-Feb-2012 Heikki Krogerus <heikki.krogerus@linux.intel.com>

usb: Convert all users to new usb_phy

Use the new usb_phy_* functions with transceiver
operations instead of the old otg functions.

Includes fixes from Sascha Hauer.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: Sascha Hauer <s.hauer@pengutronix.de>
Acked-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Acked-by: Li Yang <leoli@freescale.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Reviewed-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 39287076 17-Feb-2012 Supriya Karanth <supriya.karanth@stericsson.com>

usb: musb: Reselect index reg in interrupt context

musb INDEX register is getting modified/corrupted during temporary
un-locking in a SMP system. Set this register with proper value
after re-acquiring the lock

Scenario:
---------
CPU1 is handling a data transfer completion interrupt received for
the CLASS1 EP
CPU2 is handling a CLASS2 thread which is queuing data to musb for
transfer

Below is the error sequence:

CPU1 | CPU2
--------------------------------------------------------------------
Data transfer completion inter- |
rupt recieved. |
|
musb INDEX reg set to CLASS1 EP |
|
musb LOCK is acquired. |
|
| CLASS2 thread queues data.
|
| CLASS2 thread tries to acquire musb
| LOCK but lock is already taken by
| CLASS1, so CLASS2 thread is
| spinning.
|
From Interrupt Context musb |
giveback function is called |
|
The giveback function releases | CLASS2 thread now acquires LOCK
LOCK |
|
ClASS1 Request's completion cal-| ClASS2 schedules the data transfer and
lback is called | sets the MUSB INDEX to Class2 EP number
|
Interrupt handler for CLASS1 EP |
tries to acquire LOCK and is |
spinning |
|
Interrupt for Class1 EP acquires| Class2 completes the scheduling etc and
the MUSB LOCK | releases the musb LOCK
|
Interrupt for Class1 EP schedul-|
es the next data transfer |
but musb INDEX register is still|
set to CLASS2 EP |

Since the MUSB INDEX register is set to a different endpoint, we
read and modify the wrong registers. Hence data transfer will not
happen properly. This results in unpredictable behavior

So, the MUSB INDEX register is set to proper value again when
interrupt re-acquires the lock

Cc: stable@vger.kernel.org
Signed-off-by: Supriya Karanth <supriya.karanth@stericsson.com>
Signed-off-by: Praveena Nadahally <praveen.nadahally@stericsson.com>
Reviewed-by: srinidhi kasagar <srinidhi.kasagar@stericsson.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# d445b6da 13-Feb-2012 Heikki Krogerus <heikki.krogerus@linux.intel.com>

usb: musb: Start using struct usb_otg

Use struct usb_otg members with OTG specific functions instead
of usb_phy members.

[ balbi@ti.com: added a missing change on musb_gadget.c to avoid
a compile error on a later patch ]

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# e9e8c85e 25-Jan-2012 Felipe Balbi <balbi@ti.com>

usb: musb: make modules behave better

There's really no point in doing all that
initcall trickery when we can safely let
udev handle module probing for us.

Remove all of that trickery, by moving everybody
to module_init() and making proper use of
platform_device_register() rather than
platform_device_probe().

Tested-by: Rajashekhara, Sudhakar <sudhakar.raj@ti.com>
Tested-by: Tasslehoff Kjappfot <tasskjapp@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 7d5b49a2 14-Oct-2011 Felipe Balbi <balbi@ti.com>

usb: musb: headers cleanup

Remove a few unnecessary headers from a
few files.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 7177aed4 19-Nov-2011 Michal Nazarewicz <mina86@mina86.com>

usb: gadget: rename usb_gadget_driver::speed to max_speed

This commit renames the “speed” field of the usb_gadget_driver
structure to “max_speed”. This is so that to make it more
apparent that the field represents the maximum speed gadget
driver can support.

This also make the field look more like fields with the same
name in usb_gadget and usb_composite_driver structures. All
of those represent the *maximal* speed given entity supports.

After this commit, there are the following fields in various
structures:
* usb_gadget::speed - the current connection speed,
* usb_gadget::max_speed - maximal speed UDC supports,
* usb_gadget_driver::max_speed - maximal speed gadget driver
supports, and
* usb_composite_driver::max_speed - maximal speed composite
gadget supports.

Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# d327ab5b 19-Nov-2011 Michal Nazarewicz <mina86@mina86.com>

usb: gadget: replace usb_gadget::is_dualspeed with max_speed

This commit replaces usb_gadget's is_dualspeed field with
a max_speed field.

[ balbi@ti.com : Fixed DWC3 driver ]

Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# bfe0658b 19-Nov-2011 Michal Nazarewicz <mina86@mina86.com>

usb: udc: Fix gadget driver's speed check in various UDC drivers

Several UDC drivers had a gadget driver's speed sanity check of the
form of:

driver->speed != USB_SPEED_HIGH

or:

driver->speed != USB_SPEED_HIGH && driver->speed != USB_SPEED_FULL

As more and more gadget drivers support USB SuperSpeed, driver->speed
may be set to USB_SPEED_SUPER and UDC driver should handle such gadget
correctly. The above checks however fail to recognise USB_SPEED_SUPER
as a valid speed.

This commit changes the two checks to:

driver->speed < USB_SPEED_HIGH

or:

driver->speed < USB_SPEED_FULL

respectively.

Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Reported-by: Alan Stern <stern@rowland.harvard.edu>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 3c2d636a 02-Oct-2011 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: don't call ->disconnect() on exit

that has already being done by udc-core.c. It's
unnecessary and might cause issues with some gadget
drivers.

Tested: Ajay Kumar Gupta <ajay.gupta@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# fb914ebf 23-Jun-2011 Vitaliy Ivanov <vitalivanov@gmail.com>

treewide: typo 'interrrupt' word corrections.

Signed-off-by: Justin P. Mattock <justinmattock@gmail.com>
Signed-off-by: Vitaliy Ivanov <vitalivanov@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>


# 0ae52d54 19-Jul-2011 Anand Gadiyar <gadiyar@ti.com>

usb: musb: Enable DMA mode1 RX for transfers without short packets

This patch enables DMA mode1 for the RX path when we know
there won't be any short packets. We check that by looking
into the short_no_ok flag, if it's true we enable mode1, otherwise
we use mode0 to transfer the data.

This will result in a throughput performance gain of around
40% for USB mass-storage/mtp use cases.

[ balbi@ti.com : updated commit log and code comments slightly ]

Signed-off-by: Anand Gadiyar <gadiyar@ti.com>
Signed-off-by: Moiz Sonasath <m-sonasath@ti.com>
Signed-off-by: Vikram Pandita <vikram.pandita@ti.com>
Tested-by: Vikram Pandita <vikram.pandita@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 29cc8897 23-Aug-2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

USB: use usb_endpoint_maxp() instead of le16_to_cpu()

Now ${LINUX}/drivers/usb/* can use usb_endpoint_maxp(desc) to get maximum packet size
instead of le16_to_cpu(desc->wMaxPacketSize).
This patch fix it up

Cc: Armin Fuerst <fuerst@in.tum.de>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Johannes Erdfelt <johannes@erdfelt.com>
Cc: Vojtech Pavlik <vojtech@suse.cz>
Cc: Oliver Neukum <oliver@neukum.name>
Cc: David Kubicek <dave@awk.cz>
Cc: Johan Hovold <jhovold@gmail.com>
Cc: Brad Hards <bhards@bigpond.net.au>
Acked-by: Felipe Balbi <balbi@ti.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Thomas Dahlmann <dahlmann.thomas@arcor.de>
Cc: David Brownell <david-b@pacbell.net>
Cc: David Lopo <dlopo@chipidea.mips.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Michal Nazarewicz <m.nazarewicz@samsung.com>
Cc: Xie Xiaobo <X.Xie@freescale.com>
Cc: Li Yang <leoli@freescale.com>
Cc: Jiang Bo <tanya.jiang@freescale.com>
Cc: Yuan-hsin Chen <yhchen@faraday-tech.com>
Cc: Darius Augulis <augulis.darius@gmail.com>
Cc: Xiaochen Shen <xiaochen.shen@intel.com>
Cc: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Cc: OKI SEMICONDUCTOR, <toshiharu-linux@dsn.okisemi.com>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: Ben Dooks <ben@simtec.co.uk>
Cc: Thomas Abraham <thomas.ab@samsung.com>
Cc: Herbert Pötzl <herbert@13thfloor.at>
Cc: Arnaud Patard <arnaud.patard@rtp-net.org>
Cc: Roman Weissgaerber <weissg@vienna.at>
Acked-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
Cc: Tony Olech <tony.olech@elandigitalsystems.com>
Cc: Florian Floe Echtler <echtler@fs.tum.de>
Cc: Christian Lucht <lucht@codemercs.com>
Cc: Juergen Stuber <starblue@sourceforge.net>
Cc: Georges Toth <g.toth@e-biz.lu>
Cc: Bill Ryder <bryder@sgi.com>
Cc: Kuba Ober <kuba@mareimbrium.org>
Cc: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 6193d699 10-Aug-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

usb: musb: gadget: fix error path

In case one "forgot" to load the receiver i.e. doing
|modprobe omap2430
|modprobe musb_hdrc

he ends up with:

|musb-hdrc: version 6.0, ?dma?, otg (peripheral+host)
|HS USB OTG: no transceiver configured
|musb-hdrc musb-hdrc: musb_init_controller failed with status -19
|(NULL device *): gadget not registered.
|Unable to handle kernel NULL pointer dereference at virtual address 0000001c
|Internal error: Oops: 17 [#1] SMP
|[<c011383c>] (sysfs_find_dirent+0x4/0x60) from [<c01138c0>] (sysfs_get_dirent+0x28/0x78)
|[<c01138c0>] (sysfs_get_dirent+0x28/0x78) from [<c0115b78>] (sysfs_unmerge_group+0x1c/0x90)
|[<c0115b78>] (sysfs_unmerge_group+0x1c/0x90) from [<c0179ba4>] (dpm_sysfs_remove+0x14/0x3c)
|[<c0179ba4>] (dpm_sysfs_remove+0x14/0x3c) from [<c01742f8>] (device_del+0x40/0x1b4)
|[<c01742f8>] (device_del+0x40/0x1b4) from [<c0174478>] (device_unregister+0xc/0x18)
|[<c0174478>] (device_unregister+0xc/0x18) from [<bf0489b4>] (musb_free+0x24/0x88 [musb_hdrc])
|[<bf0489b4>] (musb_free+0x24/0x88 [musb_hdrc]) from [<bf057d18>] (musb_probe+0xb50/0xe3c [musb_hdrc])
|[<bf057d18>] (musb_probe+0xb50/0xe3c [musb_hdrc]) from [<c01779c4>] (platform_drv_probe+0x1c/0x24)

The problem is that musb_free() tries to figure out what was
initializued and what wasn't and clean up only the initialized part.
This works well for usb_del_gadget_udc() but device_unregister() can't
deal with it. Therefore we rely on the fact the we always have a parent
device and only then remove the device.
I broke this in 0f91349 ("usb: gadget: convert all users to the new udc
infrastructure")

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 93e098a8 20-Jul-2011 John Stultz <john.stultz@linaro.org>

usb: musb: fix oops on musb_gadget_pullup

an 'unhandled fault' is causes when a gadget driver calls
usb_gadget_connect() while the USB cable isn't plugged into
the OTG port.

the fault is caused by an access to MUSB's memory space
while its clock is turned off due to pm_runtime kicking
in.

in order to fix the fault, we enclose musb_gadget_pullup()
with pm_runtime_get_sync() ... pm_runtime_put() calls to
be sure we will always reach that path with clock turned on.

[ balbi@ti.com : simplified commit log; removed few things
which didn't belong there ]

Cc: stable@kernel.org
Reported-by: Zach Pfeffer <zach.pfeffer@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 72c487df 20-Jul-2011 John Stultz <john.stultz@linaro.org>

usb: musb: fix oops on musb_gadget_pullup

an 'unhandled fault' is causes when a gadget driver calls
usb_gadget_connect() while the USB cable isn't plugged into
the OTG port.

the fault is caused by an access to MUSB's memory space
while its clock is turned off due to pm_runtime kicking
in.

in order to fix the fault, we enclose musb_gadget_pullup()
with pm_runtime_get_sync() ... pm_runtime_put() calls to
be sure we will always reach that path with clock turned on.

[ balbi@ti.com : simplified commit log; removed few things
which didn't belong there ]

Cc: stable@kernel.org
Reported-by: Zach Pfeffer <zach.pfeffer@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# e71eb392 23-Jun-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

usb: musb: convert musb to new style bind

udc-core checks for valid callbacks so there is no need for the driver
to do so. Also "can-be-bound-once" is verified by udc-core. The pull-up
callback is called by udc-core afterwords.

[ balbi@ti.com : keep holding gadget_driver pointer for now
remove the stupid check for gadget_driver otherwise
we don't handle IRQs ]

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>


# 62285963 22-Jun-2011 Felipe Balbi <balbi@ti.com>

usb: musb: drop a gigantic amount of ifdeferry

the MUSB IP is always OTG, so there's no point
in adding so many ifdefs on the code. Drop those
and always compile the driver for OTG support.

This also allows us to drop the useless "driver
mode" choice. For doing that, we need to make
musb depend on both Host and Peripheral side.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 0f91349b 28-Jun-2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>

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>


# 4858f06e 08-Jun-2011 Yauheni Kaliuta <yauheni.kaliuta@nokia.com>

usb: musb: gadget: clear TXPKTRDY flag when set FLUSHFIFO

Fixes mis-use of MUSB's hardware feature where it won't
flush FIFOs when TXPKTRDY flag was set before and we are
flushing setting both FLUSHFIFO and TXPKTRDY.

In other words, we need to ensure that when we try to
flush FIFOs, we don't accidentaly set TXPKTRDY bit too
due to a read-back of the register.

The MUSB Programming Guide says "May be set simultaneously
with TxPktRdy to abort the packet that is currently being
loaded into the FIFO". This is a situation where TXPKTRDY
hasn't been set yet, but some data already loaded into the
fifo. It looks, that if TXPKTRDY has been set before, and
there is no loading in progress, but we set FLUSHFIFO with
the TXPKTRDY, controller tries to use the same logic to
abort loading and as the result just does nothing (because
there is no packet been loaded currently)

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@nokia.com>

[ balbi@ti.com : fixed one whitespace git complained about
improved the commit log slightly ]

Signed-off-by: Felipe Balbi <balbi@ti.com>


# a48ff906 22-Mar-2011 Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>

usb: musb: ux500: add ux500 specific code for gadget side

Although U8500 and U5500 platforms use paltform dma, Inventra dma specific code
can work for them for the most part. Only difference is for the Rx path where
this patch is making use of request->short_not_ok to select dma mode.

Signed-off-by: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 8620543e 22-Mar-2011 Hema HK <hemahk@ti.com>

usb: musb: Calling VBUS pulsing API when SRP is initiated.

Call VBUS pulsing API when there is SRP initiation from user space.

Signed-off-by: Hema HK <hemahk@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 5c8a86e1 10-May-2011 Felipe Balbi <balbi@ti.com>

usb: musb: drop unneeded musb_debug trickery

We have a generic way of enabling/disabling
different debug messages on a driver called
DYNAMIC_PRINTK. Anyone interested in enabling
just part of the debug messages, please read
the documentation under:

Documentation/dynamic-debug-howto.txt

for information on how to use that great
infrastructure.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 3df00453 04-May-2011 Anatolij Gustschin <agust@denx.de>

usb: fix building musb drivers

Commit 3dacdf11 "usb: factor out state_string() on otg drivers"
broke building musb drivers since there is already another
otg_state_string() function in musb drivers, but with different
prototype. Fix musb drivers to use common otg_state_string(), too.

Also provide a nop for otg_state_string() if CONFIG_USB_OTG_UTILS
is not defined.

Signed-off-by: Anatolij Gustschin <agust@denx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# cdefce16 29-Apr-2011 Jarkko Nikula <jhnikula@gmail.com>

usb: musb: gadget: Fix out-of-sync runtime pm calls

If cable is not connected to peripheral only board when initializing the
gadget driver, then runtime pm calls are out-of-sync and the musb cannot
idle with omap2430.c. This was noted on Nokia N900 where musb prevented the
CPU to be able to enter deeper retention idle state.

This was working in 2.6.38 before runtime pm conversions but there musb
smart standby/idle modes were configured statically where they are now
updated runtime depending on use and cable status.

Reason for out-of-sync is that runtime pm is activated in function
musb_gadget.c: usb_gadget_probe_driver but suspended only in OTG mode if
cable is not connected when initializing. In peripheral only mode this leads
to out-of-sync runtime pm since runtime pm remain active and is activated
another time in omap2430.c: musb_otg_notifications for VBUS Connect event
and thus cannot suspend for VBUS Disconnect event since the use count remains
active.

Fix this by moving cable status check and pm_runtime_put call in
usb_gadget_probe_driver out of is_otg_enabled block.

Signed-off-by: Jarkko Nikula <jhnikula@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 3d5ad13e 22-Mar-2011 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: check the correct list_head

We are now using our own list_head, so we should
be checking against that, not the gadget driver's
list_head.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 100d4a9d 15-Mar-2011 Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>

usb: musb: clear AUTOSET while clearing DMAENAB

On the completion of tx dma, dma is disabled by clearing MUSB_TXCSR_DMAENAB in
TXCSR. If MUSB_TXCSR_AUTOSET was set in txstate() it will remain set although
it is not needed in PIO mode. Clear it as soon as it is not needed.

Signed-off-by: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 5f1e8ce7 17-Mar-2011 Hema HK <hemahk@ti.com>

usb: musb: Fix for merge issue

There was conflict while merging 2 patches. Enabling vbus code
is wrongly moved to error check if loop.

This is a fix to resolve the merge issue.

Signed-off-by: Hema HK <hemahk@ti.com>
Cc: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 7acc6197 28-Feb-2011 Hema HK <hemahk@ti.com>

usb: musb: Idle path retention and offmode support for OMAP3

This patch supports the retention and offmode support in the idle path for
musb driver using runtime pm APIs.

This is restricted to support offmode and retention only when device not
connected.When device/cable connected with gadget driver loaded,configured
to no idle/standby which will not allow the core transition to retention
or off.

There is no context save/restore done by hardware for musb in OMAP3
and OMAP4,driver has to take care of saving and restoring the context
during offmode.

Musb has a requirement of configuring sysconfig register to force
idle/standby mode and set the ENFORCE bit in module STANDBY register
for retention and offmode support.

Runtime pm and hwmod frameworks will take care of configuring to force
idle/standby when pm_runtime_put_sync is called and back to no
idle/standby when pm_runeime_get_sync is called.

Compile, boot tested and also tested the retention in the idle path on
OMAP3630Zoom3. And tested the global suspend/resume with offmode enabled.
Usb basic functionality tested on OMAP4430SDP.

There is some problem with idle path offmode in mainline, I could not test
with offmode. But I have tested this patch with resetting the controller
in the idle path when wakeup from retention just to make sure that the
context is lost, and restore path is working fine.

Removed .suspend/.resume fnction pointers and functions because there
is no need of having these functions as all required work is done
at runtime in the driver.

There is no need to call the runtime pm api with glue driver device
as glue layer device is the parent of musb core device, when runtime apis
are called for the child, parent device runtime functionality
will be invoked.

Design overview:

pm_runtime_get_sync: When called with musb core device takes care of
enabling the clock, calling runtime callback function of omap2430 glue
layer, runtime call back of musb driver and configure the musb sysconfig
to no idle/standby

pm_runtime_put: Takes care of calling runtime callback function of omap2430
glue layer, runtime call back of musb driver, Configure the musb sysconfig
to force idle/standby and disable the clock.

During musb driver load: Call pm_runtime_get_sync.

End of musb driver load: Call pm_runtime_put

During gadget driver load: Call pm_runtime_get_sync,
End of gadget driver load: Call pm_runtime_put if there is no device
or cable is connected.

During unload of the gadget driver:Call pm_runtime_get_sync if cable/device
is not connected.
End of the gadget driver unload : pm_runtime_put

During unload of musb driver : Call pm_runtime_get_sync
End of unload: Call pm_runtime_put

On connect of usb cable/device -> transceiver notification(VBUS and ID-GND):
pm_runtime_get_sync only if the gadget driver loaded.

On disconnect of the cable/device -> Disconnect Notification:
pm_runtime_put if the gadget driver is loaded.

Signed-off-by: Hema HK <hemahk@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 4cbbf084 28-Feb-2011 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: fix list_head usage

commit ad1adb89a0d9410345d573b6995a1fa9f9b7c74a
(usb: musb: gadget: do not poke with gadget's list_head)
fixed a bug in musb where it was corrupting the list_head
which is supposed to be used by gadget drivers. While
doing that, I forgot to fix the usage in musb_gadget_dequeue()
method. Fix that.

Reported-by: Pavol Kurina <pavol.kurina@emsys.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 0fd857ae 18-Feb-2011 Sergei Shtylyov <sshtylyov@ru.mvista.com>

usb: musb: gadget: DBG() already prints function name

In the gadget code, there are several DBG() macro invocations that explicitly
print the calling function's name while DBG() macro itself does this anyway;
most of these were added by commit f11d893de444965dfd3e55f726533ae1df5c6471
(usb: musb: support ISO high bandwidth for gadget mode). Remove the duplicated
printing, somewhat clarifying the messages at the same time...

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 002eda13 16-Feb-2011 Hema HK <hemahk@ti.com>

usb: musb: OMAP4430: Fix usb device detection if connected during boot

OMAP4430 is embedded with UTMI PHY. This PHY does not support the
OTG features like ID pin detection and VBUS detection. This function
is exported to an external companion chip TWL6030. Software must retrieve
the OTG HNP and SRP status from the TWL6030 and configure the bits inside
the control module that drive the related USBOTGHS UTMI interface signals.
It must also read back the UTMI signals needed to configure the TWL6030
OTG module.

Can find more details in the TRM[1].
[1]:http://focus.ti.com/pdfs/wtbu/OMAP4430_ES2.0_Public_TRM_vJ.pdf

In OMAP4430 musb driver VBUS and ID notifications are received from the
transceiver driver. If the cable/device is connected during boot,
notifications from transceiver driver will be missed till musb driver
is loaded.
Patch to configure the transceiver in the platform_enable/disable
functions and enable the vbus in the gadget driver based on the
last_event of the otg_transceiver.

Signed-off-by: Hema HK <hemahk@ti.com>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Paul Walmsley <paul@pwsan.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# ad1adb89 15-Feb-2011 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: do not poke with gadget's list_head

struct usb_request's list_head is supposed to be
used only by gadget drivers, but musb is abusing
that. Give struct musb_request its own list_head
and prevent musb from poking into other driver's
business.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 63eed2b5 17-Jan-2011 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: beautify usb_gadget_probe_driver()/usb_gadget_unregister_driver

Just a few cosmetic fixes to usb_gadget_probe_driver()
and usb_gadget_unregister_driver().

Decreased a few indentation levels with goto statements.

While at that, also add the missing call to musb_stop().
If we don't have OTG, there's no point of leaving
MUSB prepared for operation if a gadget driver fails
to probe. The same is valid for usb_gadget_unregister_driver(),
since we are removing the gadget driver and we don't have
OTG, we can completely unconfigure MUSB.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 5f5761cb 03-Jan-2011 Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>

usb: musb: introduce api for dma code to check compatibility with usb request

Gadget MUSB driver handles dma mappings in musb_gadget_queue(). Where as it is
possible for dma code to reject the usb request later at ->channel_program()
called from txstate()/rxstate()

For example ->channel_program in tusb6010_omap.c:

static int tusb_omap_dma_program(struct dma_channel *channel, u16 packet_sz,
u8 rndis_mode, dma_addr_t dma_addr, u32 len)
{
...
if (unlikely(dma_addr & 0x1) || (len < 32) || (len > packet_sz))
return false;
...
if (dma_addr & 0x2)
return false;
...
}

In this case, usb request will be handled in PIO mode which renders dma mapping
operations unnecessary.

This patch adds an api to allow dma code to indicate incompatibility with usb
request. Gadget musb driver call this api, if available, before dma mappings to
avoid any unnecessary mapping operations.

Signed-off-by: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# c65bfa62 03-Jan-2011 Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>

usb: musb: maintain three states for buffer mappings instead of two

If dma buffers are mapped by a higher layer, with a boolean musb_request.mapped
it is still possible to call dma_sync_single_for_device() from
musb_g_giveback(), even if txstate()/rxstate() has called unmap_dma_buffer()
before falling back to pio mode.

Moreover, check for musb_ep->dma is moved within map_dma_buffer() so where
applicable checks for it are removed. And where possible, checks for
is_dma_capable() are merged with buffer map state check.

Signed-off-by: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 06624818 20-Jan-2011 Felipe Balbi <balbi@ti.com>

usb: musb: disable double buffering when it's broken

We know that blackfin doesn't support double
buffering feature as of today. So we add a
flag set by musb_platform_init() to forcefully
disable that feature.

Such flag is created and marked as deprecated
to force us to find a solution for the missing
double buffering support on blackfin.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 0607f862 01-Dec-2010 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: prevent a NULL pointer dereference

Case we can't allocate struct musb_request,
prevent a NULL pointer dereference by returning
early.

Signed-off-by: Felipe Balbi <balbi@ti.com>


# 07a8cdd2 18-Nov-2010 Anand Gadiyar <gadiyar@ti.com>

usb: musb: do not use dma for control transfers

The Inventra DMA engine used with the MUSB controller in many
SoCs cannot use DMA for control transfers on EP0, but can use
DMA for all other transfers.

The USB core maps urbs for DMA if hcd->self.uses_dma is true.
(hcd->self.uses_dma is true for MUSB as well).

Split the uses_dma flag into two - one that says if the
controller needs to use PIO for control transfers, and
another which says if the controller uses DMA (for all
other transfers).

Also, populate this flag for all MUSB by default.

(Tested on OMAP3 and OMAP4 boards, with EHCI and MUSB HCDs
simultaneously in use).

Signed-off-by: Maulik Mankad <x0082077@ti.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
Signed-off-by: Anand Gadiyar <gadiyar@ti.com>
Cc: Oliver Neukum <oliver@neukum.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Praveena NADAHALLY <praveen.nadahally@stericsson.com>
Cc: Ajay Kumar Gupta <ajay.gupta@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# bb324b08 22-Nov-2010 Ajay Kumar Gupta <ajay.gupta@ti.com>

usb: musb: gadget: fix compilation warning

Fixes below compilation warning when musb driver is compiled for
PIO mode:

drivers/usb/musb/musb_gadget.c: In function 'musb_g_rx':
drivers/usb/musb/musb_gadget.c:840:
warning: label 'exit' defined but not used

Signed-off-by: Ajay Kumar Gupta <ajay.gupta@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# e75df371 16-Nov-2010 Ming Lei <tom.leiming@gmail.com>

usb: musb: clear RXCSR_AUTOCLEAR before PIO read

If RXCSR_AUTOCLEAR flag is not cleard before PIO reading, one packet
may be recieved by musb fifo, but no chance to notify
software, so cause packet loss, follows the detailed process:

- PIO read one packet
- musb fifo auto clear the MUSB_RXCSR_RXPKTRDY
- musb continue to recieve the next packet, and MUSB_RXCSR_RXPKTRDY
is set
- software clear the MUSB_RXCSR_RXPKTRDY, so there is no chance for
musb to notify software that the 2nd recieved packet.

The patch does fix the g_ether issue below:

- use fifo_mode 3 to enable double buffer
- 'ping -s 1024 IP_OF_BEAGLE_XM'
- one usb packet of 512 byte is lost, so ping failed,
which can be observed by wireshark

note:
Beagle xm takes musb rtl1.8 and may fallback to pio mode
for unaligned buffer.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 92d2711f 15-Nov-2010 Hema Kalliguddi <hemahk@ti.com>

usb: musb: unmap dma buffer when switching to PIO

Buffer is mapped to dma when dma channel is
allocated. If, for some reason, dma channel
programming fails, musb code will fallback
to PIO mode to transfer that request. In
that case, we need to unmap the buffer
back to CPU.

MUSB RTL1.8 and above cannot handle buffers
which are not 32bit aligned. That happens to
every request sent by g_ether gadget
driver. Since the buffer sent was unaligned,
we need to fallback to PIO.

Because of that, g_ether was failing due
to missing buffer unmapping.

With this patch and [1] g_ether works fine
with all MUSB revisions.

Verified with OMAP3630 board, which has
MUSB RTL1.8 using g_ether and g_zero.

[1] http://www.spinics.net/lists/linux-usb/msg38400.html

Signed-off-by: Hema HK <hemahk@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 07397021 24-Sep-2010 Sergei Shtylyov <sshtylyov@ru.mvista.com>

usb: musb: gadget: kill duplicate code in musb_gadget_queue()

musb_gadget_queue() checks for '!req->buf' condition twice:
in the second case the code is both duplicated and unreachable
as the first check returns early.

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 31c9909b 19-Oct-2010 Ming Lei <tom.leiming@gmail.com>

USB: musb: gadget: fix MUSB_TXMAXP and MUSB_RXMAXP configuration

Commit 9f445cb29918dc488b7a9a92ef018599cce33df7[USB: musb: disable
double buffering for older RTL versions] tries to disable double
buffer mode by writing endpoint hw max packet size to TXMAP/RXMAP.

First the approach can break full speed and cause overflow problems.
We should always set those registers with the actual max packet size
from endpoint descriptor.

Second, the problem describe by commit 9f445cb29918dc488b7a9a92ef018599cce33df7
was caused by musb gadget driver; nothing to do with RTL revision as
originaly suspected.

The real fix to the problem is to always use actual max packet
size from endpoint descriptor to config TXMAP/RXMAP registers.

Cc: Cliff Cai <cliff.cai@analog.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Anand Gadiyar <gadiyar@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Cc: stable@kernel.org
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# e2c34045 02-Oct-2010 Rahul Ruikar <rahul.ruikar@gmail.com>

usb: musb: musb_gadget: fix resource leakage in error path

In function musb_gadget_setup() call put_device()
when device_register() fails.

Signed-off-by: Rahul Ruikar <rahul.ruikar@gmail.com>
Acked-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# 9001d80d 25-Sep-2010 Ming Lei <tom.leiming@gmail.com>

usb: musb: gadget: fix dma mode 0 in double buffer Rx case

1, In Rx double buffer case, FIFO may have two packets, so
rxstate should be called to unload fifo if RXPKTRDY is set
even the current request has not been completed.

2, Commit 633ba7876b96ec339ef685357e2f7c60b5a8ce85
introduces autoclear to support double buffer in dma mode 0,
so remove clearing RXPKTRDY manually for dma mode 0.

3, Commit c7af6b29ffeffbeb28caf39e5b2ce29b11807c7d may break
dma mode 1 for non-doublebuffer endpoint, fix it.

With this patch, either usbtest #5 or g_file_storage(writing
file to device in usb host) or g_ether have been tested OK in
double buffer case(using fifo mode 3). Also, this patch has
been verified that single buffer case can't be broken.

Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Anand Gadiyar <gadiyar@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>


# b595076a 01-Nov-2010 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

tree-wide: fix comment/printk typos

"gadget", "through", "command", "maintain", "maintain", "controller", "address",
"between", "initiali[zs]e", "instead", "function", "select", "already",
"equal", "access", "management", "hierarchy", "registration", "interest",
"relative", "memory", "offset", "already",

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>


# e0c43476 24-Sep-2010 Felipe Balbi <balbi@ti.com>

usb: musb: gadget: only enable AUTOCLEAR in double buffered case

commit 633ba7876b96ec339ef685357e2f7c60b5a8ce85 broke
g_file_storage functionality by enabling AUTOCLEAR on
all cases without caring for all gadget drivers.

This patch will only enable AUTOCLEAR if our endpoint's
FIFO was configured with double buffering support. Note
this is not a complete fix, double buffered case still
doesn't work always, but that hasn't been working for
quite some time. Other than reverting the entire commit
and breaking testusb with double buffered case again,
I decided it was better to fix the single buffered case
and spend more time fixing double buffered case properly.

Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# e7379aaa 24-Sep-2010 Ming Lei <tom.leiming@gmail.com>

usb: musb: gadget: fix ZLP sending in musb_g_tx(v1)

This patch fixes the problem reported by Sergei:

>how come? we need to send ZLP before giving back the request.
>Well, look at the code ionce again. We need to send ZLP *after*
>request->actual == request->length, but as the check is inserted
>after the ZLP send, ZLP *may* be sent once the first DMA completes,
>not the last.

The patch also has been discussed on the link below:

http://marc.info/?t=128454814900001&r=1&w=2

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Reported-by: Sergei Shtylyov <sshtylyov@mvista.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Anand Gadiyar <gadiyar@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 43467868 24-Sep-2010 Sergei Shtylyov <sshtylyov@ru.mvista.com>

usb: musb: gadget: kill unreachable code in musb_g_rx()

musb_g_rx() always returns if next_request() call yields NULL, so the DBG()
near the function's end can never be invoked. Remove it along with unneeded
'return'; also remove the duplicate 'request' check...

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# f11d893d 24-Sep-2010 Ming Lei <tom.leiming@gmail.com>

usb: musb: support ISO high bandwidth for gadget mode

This patch has been tested OK on beagle B5 board and
use usbtest #15 and #16 as testcase.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Reviewed-by: Sergei Shtylyov <sshtylyov@mvista.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Anand Gadiyar <gadiyar@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# b0fca50f 12-Aug-2010 Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

usb gadget: don't save bind callback in struct usb_gadget_driver

To accomplish this the function to register a gadget driver takes the bind
function as a second argument. To make things clearer rename the function
to resemble platform_driver_probe.

This fixes many section mismatches like

WARNING: drivers/usb/gadget/g_printer.o(.data+0xc): Section mismatch in
reference from the variable printer_driver to the function
.init.text:printer_bind()
The variable printer_driver references
the function __init printer_bind()

All callers are fixed.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
[m.nazarewicz@samsung.com: added dbgp]
Signed-off-by: Michał Nazarewicz <m.nazarewicz@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# d7eccbba 06-Oct-2010 Jiri Kosina <jkosina@suse.cz>

Revert "drivers/usb: Remove unnecessary return's from void functions" for musb gadget

This is a partial revert of 7f26b3a7533b ("drivers/usb: Remove unnecessary
return's from void functions") as this hunk will vanish in USB tree completely.

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>


# a666e3e6 11-Sep-2010 Sergei Shtylyov <sshtylyov@ru.mvista.com>

usb: musb: gadget: restart request on clearing endpoint halt

Commit 46034dca515bc4ddca0399ae58106d1f5f0d809f (USB: musb_gadget_ep0: stop
abusing musb_gadget_set_halt()) forgot to restart a queued request after
clearing the endpoint halt feature. This results in a couple of USB resets
while enumerating the file-backed storage gadget due to CSW packet not being
sent for the MODE SENSE(10) command.

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Cc: stable@kernel.org
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 66af83dd 20-Sep-2010 Ming Lei <tom.leiming@gmail.com>

usb: musb: gadget: fix dma length in txstate

DMA length should not go beyond the availabe space
of request buffer, so fix it.

Also set max_len of cppi dma channel as max size of
int type, so make musb dma handling happier.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Anand Gadiyar <gadiyar@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# bb27bc2c 20-Sep-2010 Ming Lei <tom.leiming@gmail.com>

usb: musb: gadget: complete request only if data is transfered over

Complete the current request only if the data transfer is over.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Anand Gadiyar <gadiyar@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 1018b4e4 20-Sep-2010 Ming Lei <tom.leiming@gmail.com>

usb: musb: gadget: fix DMA length for OUT transfer

DMA length should not go beyond the availabe space of request buffer,
so fix it.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Acked-by: Anand Gadiyar <gadiyar@ti.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Anand Gadiyar <gadiyar@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 490e5fbe 20-Sep-2010 Ming Lei <tom.leiming@gmail.com>

usb: musb: gadget: enable autoclear for OUT transfer in both DMA 0 and DMA 1

This patch fixes one bugs of OUT transfer in double buffer case:

-the current code only enable autoclear for dma mode 1, and not
for dma mode 0

Without this patch, test #5 of usbtest can't be passed if we
configure musb as g_zero and use fifo mode 3 to enable double
buffer mode.

With this patch and the following patch(fix dma length),
on my beagle B5, test#5(queued bulk out) may go beyond
18Mbyte/s(seems dma mode 0 is quicker in double buffer case)
if musb is configured as g_zero and fifo mode 3 is taken, follows
the test command:

#./testusb -D DEV_NAME -c 1024 -t 5 -s 32768 -g 8 [1]

Also I have tested this patch can't make g_ether broken.

[1],source of testusb : tools/usb/testusb.c under linux kernel;

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Anand Gadiyar <gadiyar@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# eeb1b2a4 20-Sep-2010 Ming Lei <tom.leiming@gmail.com>

usb: musb: gadget: fix bulk IN infinit hangs in double buffer case

This patch fixes one infinite hang of bulk IN transfer in double buffer
case, the hang can be observed easily by test #6 of usbtest if musb is
configured as g_zero and fifo mode 3 is taken to enable double fifo.

In fact, the patch only removes the check for non-empty fifo before
loading data from new request into fifo since the check is not correct:

-in double buffer case, fifo may accommodate more than one packet,
even though it has contained one packet already and is non-empty

-since last DMA is completed before calling musb_g_tx, it is sure
that fifo may accommodate at least one packet

Without applying the patch, new requst enqueued from .complte may not
have a chance to be loaded into fifo, then will never be completed and
cause infinite hangs.

With the patch, on my beagle B5, test#6(queued bulk in) can be passed and
test result may go beyond 33Mbyte/s if musb is configured as g_zero and
fifo mode 3 is taken, follows the test command:

#testusb -D DEV_NAME -c 1024 -t 6 -s 32768 -g 8 [1]

[1],
-source of testusb : tools/usb/testusb.c under linux kernel;

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Acked-by: Anand Gadiyar <gadiyar@ti.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Anand Gadiyar <gadiyar@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# bd2e74d6 20-Sep-2010 Ming Lei <tom.leiming@gmail.com>

usb: musb: gadget: fix kernel panic if using out ep with FIFO_TXRX style

For shared fifo hw endpoint(with FIFO_TXRX style), only ep_in
field of musb_hw_ep is intialized in musb_g_init_endpoints, and
ep_out is not initialized, but musb_g_rx and rxstate may access
ep_out field of musb_hw_ep by the method below:

musb_ep = &musb->endpoints[epnum].ep_out

which can cause the kernel panic[1] below, this patch fixes the issue
by getting 'musb_ep' from '&musb->endpoints[epnum].ep_in' for shared fifo
endpoint.

[1], kernel panic
[root@OMAP3EVM /]# musb_interrupt 1583: ** IRQ peripheral usb0008 tx0000 rx4000
musb_stage0_irq 460: <== Power=f0, DevCtl=99, int_usb=0x8
musb_g_rx 772: <== (null), rxcsr 4007 ffffffe8
musb_g_rx 786: iso overrun on ffffffe8
Unable to handle kernel NULL pointer dereference at virtual address 00000008
pgd = c0004000
[00000008] *pgd=00000000
Internal error: Oops: 17 [#1] PREEMPT
last sysfs file: /sys/devices/platform/musb_hdrc/usb1/usb_device/usbdev1.1/dev
Modules linked in: g_zero
CPU: 0 Tainted: G W (2.6.35-rc6-gkh-wl+ #92)
PC is at musb_g_rx+0xfc/0x2ec
LR is at vprintk+0x3f4/0x458
pc : [<c02c07a4>] lr : [<c006ccb0>] psr: 20000193
sp : c760bd78 ip : c03c9d70 fp : c760bdbc
r10: 00000000 r9 : fa0ab1e0 r8 : 0000000e
r7 : c7e80158 r6 : ffffffe8 r5 : 00000001 r4 : 00004003
r3 : 00010003 r2 : c760bcd8 r1 : c03cd030 r0 : 0000002e
Flags: nzCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment kernel
Control: 10c5387d Table: 8778c019 DAC: 00000017
Process kmemleak (pid: 421, stack limit = 0xc760a2e8)
Stack: (0xc760bd78 to 0xc760c000)
bd60: ffffffe8 c04b1b58
bd80: ffffffe8 c7c01ac0 00000000 c7e80d24 c0084238 00000001 00000001 c7e80158
bda0: 0000000e 00000008 00000099 000000f0 c760be04 c760bdc0 c02bcd68 c02c06b4
bdc0: 00000099 00000008 00004000 c760bdd8 c03cc4f8 00000000 00000002 c7e80158
bde0: c7d2e300 60000193 c760a000 0000005c 00000000 00000000 c760be24 c760be08
be00: c02bcecc c02bc1ac c7d2e300 c7d2e300 0000005c c760a000 c760be54 c760be28
be20: c00ad698 c02bce6c 00000000 c7d2e300 c067c258 0000005c c067c294 00000001
be40: c760a000 00000000 c760be74 c760be58 c00af984 c00ad5fc 0000005c 00000000
be60: 00000000 00000002 c760be8c c760be78 c0039080 c00af8d0 ffffffff fa200000
be80: c760beec c760be90 c0039b6c c003900c 00000001 00000000 c7d1e240 00000000
bea0: 00000000 c068bae8 00000000 60000013 00000001 00000000 00000000 c760beec
bec0: c0064ecc c760bed8 c00ff7d0 c003a0a8 60000013 ffffffff 00000000 c068bae8
bee0: c760bf24 c760bef0 c00ff7d0 c0064ec4 00000001 00000000 c00ff700 00000000
bf00: c0087f00 00000000 60000013 c0d76a70 c0e23795 00000001 c760bf4c c760bf28
bf20: c00ffdd8 c00ff70c c068bb08 c068bae8 60000013 c0100938 c068bb30 00000000
bf40: c760bf84 c760bf50 c010014c c00ffd84 00000001 00000000 c010000c 00012c00
bf60: c7c33f04 00012c00 c7c33f04 00000000 c0100938 00000000 c760bf9c c760bf88
bf80: c01009a8 c0100018 c760bfa8 c7c33f04 c760bff4 c760bfa0 c0088000 c0100944
bfa0: c760bf98 00000000 00000000 00000001 dead4ead ffffffff ffffffff c08ba2bc
bfc0: 00000000 c049e7fa 00000000 c0087f70 c760bfd0 c760bfd0 c7c33f04 c0087f70
bfe0: c006f5e8 00000013 00000000 c760bff8 c006f5e8 c0087f7c 7f0004ff df2000ff
Backtrace:
[<c02c06a8>] (musb_g_rx+0x0/0x2ec) from [<c02bcd68>] (musb_interrupt+0xbc8/0xcc0)
[<c02bc1a0>] (musb_interrupt+0x0/0xcc0) from [<c02bcecc>] (generic_interrupt+0x6c/0x84)
[<c02bce60>] (generic_interrupt+0x0/0x84) from [<c00ad698>] (handle_IRQ_event+0xa8/0x1ec)
r7:c760a000 r6:0000005c r5:c7d2e300 r4:c7d2e300
[<c00ad5f0>] (handle_IRQ_event+0x0/0x1ec) from [<c00af984>] (handle_level_irq+0xc0/0x13c)
[<c00af8c4>] (handle_level_irq+0x0/0x13c) from [<c0039080>] (asm_do_IRQ+0x80/0xa0)
r7:00000002 r6:00000000 r5:00000000 r4:0000005c
[<c0039000>] (asm_do_IRQ+0x0/0xa0) from [<c0039b6c>] (__irq_svc+0x4c/0xb4)
Exception stack(0xc760be90 to 0xc760bed8)
be80: 00000001 00000000 c7d1e240 00000000
bea0: 00000000 c068bae8 00000000 60000013 00000001 00000000 00000000 c760beec
bec0: c0064ecc c760bed8 c00ff7d0 c003a0a8 60000013 ffffffff
r5:fa200000 r4:ffffffff
[<c0064eb8>] (sub_preempt_count+0x0/0x100) from [<c00ff7d0>] (find_and_get_object+0xd0/0x110)
r5:c068bae8 r4:00000000
[<c00ff700>] (find_and_get_object+0x0/0x110) from [<c00ffdd8>] (scan_block+0x60/0x104)
r8:00000001 r7:c0e23795 r6:c0d76a70 r5:60000013 r4:00000000
[<c00ffd78>] (scan_block+0x0/0x104) from [<c010014c>] (kmemleak_scan+0x140/0x484)
[<c010000c>] (kmemleak_scan+0x0/0x484) from [<c01009a8>] (kmemleak_scan_thread+0x70/0xcc)
r8:00000000 r7:c0100938 r6:00000000 r5:c7c33f04 r4:00012c00
[<c0100938>] (kmemleak_scan_thread+0x0/0xcc) from [<c0088000>] (kthread+0x90/0x98)
r5:c7c33f04 r4:c760bfa8
[<c0087f70>] (kthread+0x0/0x98) from [<c006f5e8>] (do_exit+0x0/0x684)
r7:00000013 r6:c006f5e8 r5:c0087f70 r4:c7c33f04
Code: e3002312 e58d6000 e2833e16 eb0422d5 (e5963020)
---[ end trace f3d5e96f75c297b7 ]---

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Reviewed-by: Sergei Shtylyov <sshtylyov@mvista.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Anand Gadiyar <gadiyar@ti.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Cc: stable <stable@kernel.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 7f26b3a7 04-Aug-2010 Joe Perches <joe@perches.com>

drivers/usb: Remove unnecessary return's from void functions

Greg prefers this to go through the trivial tree.
http://lkml.org/lkml/2010/6/24/1

There are about 2500 void functions in drivers/usb
Only a few used return; at end of function.

Standardize them a bit.

Moved a statement down a line in drivers/usb/host/u132-hcd.c

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>


# 5a0e3ad6 24-Mar-2010 Tejun Heo <tj@kernel.org>

include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h

percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.

percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.

http://userweb.kernel.org/~tj/misc/slabh-sweep.py

The script does the followings.

* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.

* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.

* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.

The conversion was done in the following steps.

1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.

2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.

3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.

4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.

5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.

6. percpu.h was updated not to include slab.h.

7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).

* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig

8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.

Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.

Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>


# 08e6c972 02-Feb-2010 Roel Kluin <roel.kluin@gmail.com>

USB: musb: test always evaluates to false

The removed part always evaluates to false.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Cc: Felipe Balbi <felipe.balbi@nokia.com>
Cc: Greg Kroah-Hartman <gregkh@suse.de>
Acked-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>


# 9f445cb2 28-Jan-2010 Cliff Cai <cliff.cai@analog.com>

USB: musb: disable double buffering for older RTL versions

Trying to use double buffer modes in RTL versions <2.0 may result in
infinite hangs or data corruption. So avoid them with older versions.

Signed-off-by: Cliff Cai <cliff.cai@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 0abdc36f 22-Dec-2009 Maulik Mankad <x0082077@ti.com>

USB: musb: Fix null pointer dereference issue

This patch fixes the following NULL pointer dereference issue.

Pointer 'request' returned from call to function 'next_request'
at line 748 may be NULL and may be dereferenced at line 792.

============
Code Snippet
============

748: request = next_request(musb_ep);
785: if (dma && (csr & MUSB_RXCSR_DMAENAB)) {
csr &= ~(MUSB_RXCSR_AUTOCLEAR
| MUSB_RXCSR_DMAENAB
| MUSB_RXCSR_DMAMODE);
musb_writew(epio, MUSB_RXCSR,
MUSB_RXCSR_P_WZC_BITS | csr);

792: request->actual += musb_ep->dma->actual_len;


Signed-off-by: Maulik Mankad <x0082077@ti.com>
Cc: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 796a83fa 21-Dec-2009 Cliff Cai <cliff.cai@analog.com>

USB: musb: correct DMA address for tx

Since a DMA transfer may need to be kicked off several times to complete,
the DMA start must include the length that has already been transferred.

Signed-off-by: Cliff Cai <cliff.cai@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Cc: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# d4c433fe 15-Dec-2009 Arnaud Mandy <ext-arnaud.2.mandy@nokia.com>

USB: musb: gadget: set otg tranceiver to idle when registering gadget

When registering gadget driver, the state of the transceiver
must be set from undefined (no gadget) to b_idle.

Module unload sets the transceiver state to undefined state.
After the first load/unload pair, the reset irq will be lost.

Signed-off-by: Arnaud Mandy <ext-arnaud.2.mandy@nokia.com>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Cc: David Brownell <dbrownell@users.sourceforge.net>
Acked-by: Anand Gadiyar <gadiyar@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# f95c4c01 15-Dec-2009 Cliff Cai <cliff.cai@analog.com>

USB: musb: fix compiling warning with min() macro

Current musb gadget dma code produces the warning:
drivers/usb/musb/musb_gadget.c: In function 'txstate':
drivers/usb/musb/musb_gadget.c:312: warning: comparison of distinct
pointer types lacks a cast

So switch to min_t(size_t, ...).

Signed-off-by: Cliff Cai <cliff.cai@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 95962a77 16-Dec-2009 Sergei Shtylyov <sshtylyov@ru.mvista.com>

USB: musb_gadget: fix kernel oops in txstate()

Commit 7723de7e19b744144975a09c81777ec0f14ac5b3 (USB: musb_gadget: remove
pointless loop) included uncalled for (and incorrect) optimization that
might cause a kernel oops in txstate() -- undo it.

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 1b6c3b0f 04-Dec-2009 Felipe Balbi <felipe.balbi@nokia.com>

USB: musb: musb_gadget: fix sparse warning

Fix the following sparse warnings:

drivers/usb/musb/musb_gadget.c:1161:5: warning: symbol 'musb_gadget_set_halt' was not declared. Should it be static?

drivers/usb/musb/musb_gadget.c:1244:5: warning: symbol 'musb_gadget_set_wedge' was not declared. Should it be static?

Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 7723de7e 18-Nov-2009 Sergei Shtylyov <sshtylyov@ru.mvista.com>

USB: musb_gadget: remove pointless loop

Remove the pointless 'do () while (0)' loop from musb_g_tx() -- it
makes this function symmetric to musb_g_rx()...

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 47e97605 18-Nov-2009 Sergei Shtylyov <sshtylyov@ru.mvista.com>

USB: musb_gadget: implement set_wedge() method

Implement the driver's set_wedge() method by adding the 'wedged' flag
to the 'struct musb_ep'.

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# cea83241 18-Nov-2009 Sergei Shtylyov <sshtylyov@ru.mvista.com>

USB: musb_gadget: fix STALL handling

The driver incorrectly cancels the mass-storage device CSW request
(which leads to device reset) due to giving back URB at the head of
endpoint's queue after sending each STALL handshake; stop doing that
and start checking for the queue being non-empty before stalling an
endpoint and disallowing stall in such case in musb_gadget_set_halt()
like the other gadget drivers do.

Moreover, the driver starts Rx request despite of the endpoint being
halted -- fix this by moving the SendStall bit check from musb_g_rx()
to rxstate(). And we also sometimes get into rxstate() with DMA still
active after clearing an endpoint's halt (not clear why), so bail out
in this case, similarly to what txstate() does...

While at it, also do the following changes :

- in musb_gadget_set_halt(), remove pointless Tx FIFO flushing (the
driver does not allow stalling with non-empty Tx FIFO anyway);

- in rxstate(), stop pointlessly zeroing the 'csr' variable;

- in musb_gadget_set_halt(), move the 'done' label to a more proper
place;

- in musb_g_rx(), eliminate the 'done' label completely...

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Cc: <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# d1043a26 02-Apr-2009 Anand Gadiyar <gadiyar@ti.com>

musb: use dma mode 1 for TX if transfer size equals maxpacket (v2)

Currently, with Inventra DMA, we use Mode 0 if transfer size is less
than or equal to the endpoint's maxpacket size. This requires that
we explicitly set TXPKTRDY for that transfer.

However the musb_g_tx code will not set TXPKTRDY twice if the last
transfer is exactly equal to maxpacket, even if request->zero is set.
Using Mode 1 will solve this; a better fix might be in musb_g_tx().

Without this change, musb will not correctly send out a ZLP if the
last transfer is the maxpacket size and request->zero is set.

Signed-off-by: Anand Gadiyar <gadiyar@ti.com>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# ab983f2a 31-Mar-2009 David Brownell <dbrownell@users.sourceforge.net>

musb: support disconnect after HNP roleswitch

Adjust HNP state machines in MUSB driver so that they handle the
case where the cable is disconnected. The A-side machine was
very wrong (unrecoverable); the B-Side was much less so.

- A_PERIPHERAL ... as usual, the non-observability of the ID
pin through Mentor's registers makes trouble. We can't go
directly to A_WAIT_VFALL to end the session and start the
disconnect processing. We can however sense link suspending,
go to A_WAIT_BCON, and from there use OTG timeouts to finally
trigger that A_WAIT_VFALL transition. (Hoping that nobody
reconnects quickly to that port and notices the wrong state.)

- B_HOST ... actually clear the Host Request (HR) bit as the
messages say, disconnect the peripheral from the root hub,
and don't detour through a suspend state. (In some cases
this would eventually have cleaned up.)

Also adjust the A_SUSPEND transition to respect the A_AIDL_BDIS
timeout, so if HNP doesn't trigger quickly enough the A_WAIT_VFALL
transition happens as it should.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 1de00dae 02-Apr-2009 David Brownell <dbrownell@users.sourceforge.net>

musb: make initial HNP roleswitch work (v2)

Minor HNP bugfixes, so the initial role switch works:

- A-Device:
* disconnect-during-suspend enters A_PERIPHERAL state
* kill OTG timer after reset as A_PERIPHERAL ...
* ... and also pass that reset to the gadget
* once HNP succeeds, clear the "ignore_disconnect" flag
* from A_PERIPHERAL, disconnect transitions to A_WAIT_BCON

- B-Device:
* kill OTG timer on entry to B_HOST state (HNP succeeded)
* once HNP succeeds, clear "ignore_disconnect" flag
* kick the root hub only _after_ the state is adjusted

Other state transitions are left alone. Notably, exit paths from
the "roles have switched" state ... A_PERIPHERAL handling of that
stays seriously broken.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 84e250ff 31-Mar-2009 David Brownell <dbrownell@users.sourceforge.net>

musb: proper hookup to transceiver drivers

Let the otg_transceiver in MUSB be managed by an external driver;
don't assume it's integrated. OMAP3 chips need it to be external,
and there may be ways to interact with the transceiver which add
functionality to the system.

Platform init code is responsible for setting up the transeciver,
probably using the NOP transceiver for integrated transceivers.
External ones will use whatever the board init code provided,
such as twl4030 or something more hands-off.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 37e3ee99 27-Mar-2009 Sergei Shtylyov <sshtylyov@ru.mvista.com>

musb_gadget: suppress "parasitic" TX interrupts with CPPI

Suppress "parasitic" endpoint interrupts in the DMA mode
when using CPPI DMA driver; they're caused by the MUSB gadget
driver using the DMA request mode 0 instead of the mode 1.

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# b6e434a5 26-Mar-2009 Sergei Shtylyov <sshtylyov@ru.mvista.com>

USB: musb: sanitize clearing TXCSR DMA bits (take 2)

The MUSB code clears TXCSR_DMAMODE incorrectly in several
places, either asserting that TXCSR_DMAENAB is clear (when
sometimes it isn't) or clearing both bits together. Recent
versions of the programmer's guide require DMAENAB to be
cleared first, although some older ones didn't.

Fix this and while at it:

- In musb_gadget::txstate(), stop clearing the AUTOSET
and DMAMODE bits for the CPPI case since they never
get set anyway (the former bit is reserved on DaVinci);
but do clear the DMAENAB bit on the DMA error path.

- In musb_host::musb_ep_program(), remove the duplicate
DMA controller specific code code clearing the TXCSR
previous state, add the code to clear TXCSR DMA bits
on the Inventra DMA error path, to replace such code
(executed late) on the PIO path.

- In musbhsdma::dma_channel_abort()/dma_controller_irq(),
add/use the 'offset' variable to avoid MUSB_EP_OFFSET()
invocations on every RXCSR/TXCSR access.

[dbrownell@users.sourceforge.net: don't introduce CamelCase,
shrink diff]

Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# c2c96321 21-Feb-2009 Felipe Balbi <felipe.balbi@nokia.com>

USB: musb: be careful with 64K+ transfer lengths (gadget side)

request->actual is an unsigned and we should use the same
variable type for fifo_count otherwise we might lose some
data if request->length >= 64kbytes.

[ dbrownell@users.sourceforge.net: fix compiler warning ]

Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 96bcd090 24-Jan-2009 Julia Lawall <julia@diku.dk>

USB: musb uses endpoint functions

This set of patches introduces calls to the following set of functions:

usb_endpoint_dir_in(epd)
usb_endpoint_dir_out(epd)
usb_endpoint_is_bulk_in(epd)
usb_endpoint_is_bulk_out(epd)
usb_endpoint_is_int_in(epd)
usb_endpoint_is_int_out(epd)
usb_endpoint_num(epd)
usb_endpoint_type(epd)
usb_endpoint_xfer_bulk(epd)
usb_endpoint_xfer_control(epd)
usb_endpoint_xfer_int(epd)
usb_endpoint_xfer_isoc(epd)

In some cases, introducing one of these functions is not possible, and it
just replaces an explicit integer value by one of the following constants:

USB_ENDPOINT_XFER_BULK
USB_ENDPOINT_XFER_CONTROL
USB_ENDPOINT_XFER_INT
USB_ENDPOINT_XFER_ISOC

An extract of the semantic patch that makes these changes is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@r1@ struct usb_endpoint_descriptor *epd; @@

- ((epd->bmAttributes & \(USB_ENDPOINT_XFERTYPE_MASK\|3\)) ==
- \(USB_ENDPOINT_XFER_CONTROL\|0\))
+ usb_endpoint_xfer_control(epd)

@r5@ struct usb_endpoint_descriptor *epd; @@

- ((epd->bEndpointAddress & \(USB_ENDPOINT_DIR_MASK\|0x80\)) ==
- \(USB_DIR_IN\|0x80\))
+ usb_endpoint_dir_in(epd)

@inc@
@@

#include <linux/usb.h>

@depends on !inc && (r1||r5)@
@@

+ #include <linux/usb.h>
#include <linux/usb/...>
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Acked-by: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 427c4f33 06-Nov-2008 Kay Sievers <kay.sievers@vrfy.org>

usb: struct device - replace bus_id with dev_name(), dev_set_name()

Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# f362a475 04-Aug-2008 Felipe Balbi <felipe.balbi@nokia.com>

usb: musb: fix hanging when rmmod gadget driver

If we try to modprobe a second gadget driver before
rmmoding the first one, the reference for the first
gadget driver would get NULLed avoiding usb to change
gadget drivers later.

Cc: David Brownell <david-b@pacbell.net>
Cc: Tony Lindgren <tony@atomide.com>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>


# 550a7375 23-Jul-2008 Felipe Balbi <felipe.balbi@nokia.com>

USB: Add MUSB and TUSB support

This patch adds support for MUSB and TUSB controllers
integrated into omap2430 and davinci. It also adds support
for external tusb6010 controller.

Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Tony Lindgren <tony@atomide.com>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>