1
0
Fork 0
Commit Graph

18628 Commits (redonkable)

Author SHA1 Message Date
Peter Chen 7d1a94b690 MLK-18319-2 usb: cdns3: gadget: delete the unless code
Confirmed from CDNS, this code is from bare metal, and not needed
for Linux. Below are their response:

This is alternative deferred interrupt.
This is intended to be used in Bare Metal to not block system in
interrupt.
This was not fully checked in Linux, so we do not recommend to use it
there.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 65aed0a45f MLK-18319-1 usb: cdns3: gadget: improvement the handling for non-aligned buffer
If the user buffer is not 8-byte aligned, it needs to use debounce
buffer for DMA transfer, and in this commit, we do below two
improvements:
- Copy back the request buffer when the transfer has completed
- Using Macro for default debounce buffer size

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 535e967839 MLK-18206-5 usb: cdns3: gadget: change maxburst as numbered buffered packet
This value is suggested by CDNS IC engineer.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen cb5d0e8878 MLK-18206-4 usb: cdns3: gadget: fix can't do usbtest for same EP twice
When using usbtest <--> f_sourcesink to do usb test, the current
code can't do test on same EP twice (eg EP1OUT), the DMA engine
can't restarted for the second test, the real reason is unknown.
The workaround for this problem is reset EP at .ep_enable, and
this operation is reasonable since we can reset EP at its
initialized state before using it. The fail cause for current
code like below:
./testusb -a -t 1
/* do it again */
./testusb -a -t 1

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 094e384895 MLK-18206-3 usb: cdns3: gadget: add dflush for both .dequeue and .ep_disable
There are may active transfers when we would like dequeue request
or disable endpoint, so it needs to flush the on-chip buffer before
dequeue software request.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 39dd5f3eae MLK-18206-2 usb: cdns3: gadget: change infinite wait as wait-timeout
Add API pair wait_reg_bit_set/clear to replace infinite wait code.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen e0555bde83 MLK-18206-1 usb: cdns3: gadget: show error message when onchip memory is full
For Cadence USB3 device mode, the onchip buffer size is fixed
(eg: 18KB at this version), and the software needs to judge
if the onchip buffer is full when tries to configure endpoint.
For IN endpoint, each endpoint has its own onchip buffer;
For OUT endpoint, all endpoints share the same onchip buffer.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 976acc53d1 MLK-18200 usb: cdns3: gadget: fix can't wait configurated with USB2
With Linux PC USB2 connection, if L1 enable bit is set during the
initialization, the usbsts.cfgsts can't be 1 (device is in the
configured state) after setting usbconf.cfgset, move L1 enable
after USB configuration done can workaround this issue.

Reviewed-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 1473536864 MLK-17631-7 usb: cdns3: gadget: clear stalled_flag at .ep_enable
When the EP is going to enable, it should not be stalled, and the
software flag needs to be updated. It fixes the mass_storage gadget
can't work after re-plug in.

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 37e1a8b1f7 MLK-17631-6 usb: cdns3: gadget: disable U1 and U2 for reset state
When we receive the bus reset, according to CH 9.4.5, the U1
and U2 should be reset to disabled status.

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 2975d76929 MLK-17631-5 usb: cdns3: gadget: set selfpower flag for usb_gadget
Implement selfpower setting between USB gadget core and
controller driver

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 8be8d50782 MLK-17631-4 usb: cdns3: gadget: support LPM for USB 2.0
Superspeed device should support USB 2.0 LPM feature.

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen bf9a985249 MLK-17631-3 usb: cdns3: gadget: fix NULL pointer deference issue for usbtest
When running usbtest case 9, it meets below oops, the reason for this
issue is the EP2-IN is not enabled, but the related interrupt for it
occurs, the structure usb_request for it is NULL. The software should
make sure there is no oops even the hardware triggers wrong interrupt.

[  476.636715]  gadget-cdns3: EP_STS: 00000804
[  476.636726] Unable to handle kernel NULL pointer dereference at virtual address 00000002
[  476.636729] pgd = ffff0000095f1000
[  476.636736] [00000002] *pgd=00000008bfffe003, *pud=00000008bfffd003, *pmd=0000000000000000
[  476.636741] Internal error: Oops: 96000006 [#1] PREEMPT SMP
[  476.636750] Modules linked in: g_zero vivante ipv6
[  476.636757] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.9.88-04771-g7b3994b #1669
[  476.636759] Hardware name: Freescale i.MX8QXP MEK (DT)
[  476.636762] task: ffff0000093c0780 task.stack: ffff0000093b0000
[  476.636774] PC is at single_td_ep_dequeue+0x50/0x180
[  476.636780] LR is at cdns_irq_handler_thread+0x21c/0x6c0
[  476.636783] pc : [<ffff0000088b6aa8>] lr : [<ffff0000088b6214>] pstate: 600001c5
[  476.636785] sp : ffff80083ff40e40
[  476.636790] x29: ffff80083ff40e40 x28: ffff80083ae0c418
[  476.636795] x27: 0000000000040000 x26: 0000000000000804
[  476.636800] x25: ffff0000095624f8 x24: ffff80083b1047a0
[  476.636804] x23: ffff000009187718 x22: ffff0000095619b8
[  476.636809] x21: ffff80083b104000 x20: ffff80083ae0c418
[  476.636813] x19: 0000000000000000 x18: 0000000000000010
[  476.636818] x17: 0000ffff968c5e30 x16: ffff000008b14998
[  476.636823] x15: 0000000000000008 x14: 00000000fffffff0
[  476.636827] x13: ffff0000095a0068 x12: ffff0000093ce600
[  476.636832] x11: ffff0000093ce000 x10: ffff00000959d6d8
[  476.636837] x9 : 0000000000000001 x8 : ffff80083c8eb43f
[  476.636841] x7 : 0000000000000000 x6 : 000000000811c50d
[  476.636845] x5 : 00ffffffffffffff x4 : 0000000000000000
[  476.636850] x3 : 00000000000001c0 x2 : 0000000000000000
[  476.636854] x1 : 0000000000000000 x0 : ffff80083a607410
[  476.636855]
[  476.636859] Process swapper/0 (pid: 0, stack limit = 0xffff0000093b0020)
[  476.636862] Stack: (0xffff80083ff40e40 to 0xffff0000093b4000)
[  476.636864] Call trace:
[  476.636869] Exception stack(0xffff80083ff40c70 to 0xffff80083ff40da0)
[  476.636874] 0c60:                                   0000000000000000 0000ffffffffffff
[  476.636879] 0c80: ffff80083ff40e40 ffff0000088b6aa8 ffff80083ff40db0 ffff80083ff40db0
[  476.636885] 0ca0: ffff80083ff40d80 00000000ffffffd8 ffff80083bb17500 0000000000000000
[  476.636889] 0cc0: ffff8008344f6a00 0000000000000000 0000000000000000 0000000000000000
[  476.636895] 0ce0: ffff80083ff40cf0 ffff0000088f8b9c ffff80083ff40d20 ffff0000088f9270
[  476.636900] 0d00: ffff80083bb17500 0000000000000000 ffff80083a607410 0000000000000000
[  476.636905] 0d20: 0000000000000000 00000000000001c0 0000000000000000 00ffffffffffffff
[  476.636910] 0d40: 000000000811c50d 0000000000000000 ffff80083c8eb43f 0000000000000001
[  476.636916] 0d60: ffff00000959d6d8 ffff0000093ce000 ffff0000093ce600 ffff0000095a0068
[  476.636921] 0d80: 00000000fffffff0 0000000000000008 ffff000008b14998 0000ffff968c5e30
[  476.636927] [<ffff0000088b6aa8>] single_td_ep_dequeue+0x50/0x180
[  476.636932] [<ffff0000088b6214>] cdns_irq_handler_thread+0x21c/0x6c0
[  476.636937] [<ffff0000088b1f0c>] cdns3_irq+0x44/0x98
[  476.636945] [<ffff00000810b0cc>] __handle_irq_event_percpu+0x9c/0x128
[  476.636950] [<ffff00000810b174>] handle_irq_event_percpu+0x1c/0x58
[  476.636955] [<ffff00000810b1f8>] handle_irq_event+0x48/0x78
[  476.636961] [<ffff00000810eb90>] handle_fasteoi_irq+0xb8/0x1b0
[  476.636967] [<ffff00000810a1b4>] generic_handle_irq+0x24/0x38
[  476.636972] [<ffff00000810a81c>] __handle_domain_irq+0x5c/0xb8
[  476.636978] [<ffff00000808180c>] gic_handle_irq+0xbc/0x168
[  476.636981] Exception stack(0xffff0000093b3de0 to 0xffff0000093b3f10)
[  476.636987] 3de0: 0000000000000000 0000000000000000 0000000000000001 0000000000000000
[  476.636992] 3e00: 00000000000001c0 0100000000000000 00000000eb3aea81 ffff80083ff47b38
[  476.636998] 3e20: ffff0000093c1060 ffff0000093b0000 0000000000000880 000000001469197d
[  476.637003] 3e40: 0000000000000018 0000000059362c44 000c28cb00000000 0000554bf0000000
[  476.637008] 3e60: ffff000008b14998 0000ffff968c5e30 0000000000000000 ffff0000093b72e8
[  476.637013] 3e80: ffff0000093b7258 0000000000000001 0000000000000000 0000000000000000
[  476.637019] 3ea0: ffff0000093b0000 ffff00000936da60 ffff000009506fd4 ffff0000093b7000
[  476.637024] 3ec0: ffff0000093b7000 ffff0000093b3f10 ffff00000808599c ffff0000093b3f10
[  476.637029] 3ee0: ffff0000080859a0 0000000000000145 ffff000008116ec4 0000000040000145
[  476.637033] 3f00: ffffffffffffffff 7fffffffffffffff
[  476.637038] [<ffff000008082eec>] el1_irq+0xac/0x120
[  476.637043] [<ffff0000080859a0>] arch_cpu_idle+0x10/0x18
[  476.637050] [<ffff0000080ff478>] cpu_startup_entry+0x118/0x1d8
[  476.637058] [<ffff000008cd54a0>] rest_init+0x80/0x90
[  476.637067] [<ffff000009290b40>] start_kernel+0x378/0x38c
[  476.637072] [<ffff0000092901d8>] __primary_switched+0x5c/0x64
[  476.637078] Code: d1010273 f9401e82 aa1303e1 f943dea0 (39400842)
[  476.637088] ---[ end trace 21e06658d7988711 ]---
[  476.637091] Kernel panic - not syncing: Fatal exception in interrupt
[  476.637094] SMP: stopping secondary CPUs
[  476.643852] Kernel Offset: disabled
[  476.643854] Memory Limit: none
[  477.339728] ---[ end Kernel panic - not syncing: Fatal exception in interrupt

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 997ccf4804 MLK-17631-2 usb: cdns3: gadget: fix the bug the non-ep0 can't work after disconnection
We add endpoints to ep_match_list when adding gadget module, but
we delete the endpoints from the ep_match_list before set configuration.
When the re-enumeration after the new connection, the ep_match_list
is empty, in that case, the non-ep0s have not configurated, the
transfer on them will be failed.

In this commit, we only delete the endpoints from the list when we
remove the gadget module.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 42a115ca20 MLK-17631-1 usb: cdns3: gadget: fix deadlock during remove gadget module
For mass_storage gadget, when we remove the module after disconnection,
the request->complete at .ep_dequeue can't be executed, then the
wakeup_thread for certain endpoints is not called, the sleep_thread
will be dead lock.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun a249ec86f0 MLK-17887 Revert "usb: dwc3: gadget: skip Set/Clear Halt when invalid"
This reverts commit 3ccf60e1ff
("usb: dwc3: gadget: skip Set/Clear Halt when invalid")
"At least macOS seems to be sending
ClearFeature(ENDPOINT_HALT) to endpoints which
aren't Halted. This makes DWC3's CLEARSTALL command
time out which causes several issues for the driver."

but this change is impacting usb CV compliance test with
windows, which using clear EP halt for other purpose in
this case, as this is not resolved on upstream, so revert
this patch for now.

Acke-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Frank Li 34d67423e4 MLK-17828 mfg: utp device support multi instance
There are two udc devices supported in qxp b0
Change static varible to dynmatic malloc.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen a2d8b03ffe MLK-17323 usb: cdns3: fix the kernel dump during the reboot stress test
During the reboot stress test, there may "nobody cared irq" for CDNS3,
the interrupts are occurred during the controller is entering low power
mode. In fact, we do no expect interrupt during this period, so disable
controller interrupt for it. With this patch, the kernel dump does
not occur again during reboot stress test.

[   18.460516] irq 44: nobody cared (try booting with the "irqpoll" option)
[   18.467222] CPU: 0 PID: 112 Comm: kworker/0:1 Not tainted 4.9.51-04150-ge84b58d-dirty #1198
[   18.475573] Hardware name: Freescale i.MX8QXP MEK (DT)
[   18.480720] Workqueue: pm pm_runtime_work
[   18.484739] Call trace:
[   18.487186] [<ffff0000080884e0>] dump_backtrace+0x0/0x1e0
[   18.492588] [<ffff0000080886d4>] show_stack+0x14/0x20
[   18.497644] [<ffff0000083e571c>] dump_stack+0x94/0xb8
[   18.502701] [<ffff0000081062c0>] __report_bad_irq+0x38/0xe8
[   18.508276] [<ffff000008106644>] note_interrupt+0x20c/0x2e0
[   18.513853] [<ffff00000810386c>] handle_irq_event_percpu+0x44/0x58
[   18.520038] [<ffff0000081038c8>] handle_irq_event+0x48/0x78
[   18.525608] [<ffff000008107260>] handle_fasteoi_irq+0xb8/0x1b0
[   18.531445] [<ffff000008102894>] generic_handle_irq+0x24/0x38
[   18.537187] [<ffff000008102f04>] __handle_domain_irq+0x5c/0xb8
[   18.543017] [<ffff00000808163c>] gic_handle_irq+0xbc/0x168
[   18.548506] Exception stack(0xffff80083ff4ae00 to 0xffff80083ff4af30)
[   18.554946] ae00: ffff80083ff4ae30 0001000000000000 ffff80083ff4af60 ffff0000080c1fec
[   18.562781] ae20: 0000000040000145 ffff80083a474000 0000000000000000 0000000000000000
[   18.570617] ae40: 00000000fffeecc3 ffff000008a2d368 00000000020c49ba 0000000000000020
[   18.578454] ae60: 000000000f78257c 7fffffffffffffff 0000000000000020 ffff80083a403f00
[   18.586290] ae80: ffff80083ff51ab0 ffff000008cb0b68 00000000000003ef 0000000000000000
[   18.594125] aea0: 0000000000000011 00000000000003ef 0000000000000019 0000000000000001
[   18.601962] aec0: 0000000000000007 ffff0000092f9000 ffff0000092f5b08 0000000000000000
[   18.609798] aee0: ffff000009501180 ffff80083a002a80 ffff80083a474000 00000000fffeecc2
[   18.617634] af00: ffff80083ff4b090 ffff000009336000 0000000000000002 ffff80083ff4af60
[   18.625469] af20: ffff0000080c243c ffff80083ff4af60
[   18.630343] [<ffff0000080827b0>] el1_irq+0xb0/0x124
[   18.635220] [<ffff0000080c243c>] irq_exit+0xac/0xf0
[   18.640099] [<ffff000008102f08>] __handle_domain_irq+0x60/0xb8
[   18.645928] [<ffff00000808163c>] gic_handle_irq+0xbc/0x168
[   18.651409] Exception stack(0xffff80083a477ad0 to 0xffff80083a477c00)

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 2a234e670e MLK-17380-7 usb: cdns3: add platform TPL support
The TPL support is used to identify targeted devices during
EH2.0 and EH3.0 certification test.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 556f0d0723 MLK-17380-4 usb: host: xhci: add EH SINGLE_STEP_SET_FEATURE Test for USB2
This function is similar with EHCI's, but implemented using XHCI.
The USB2 host needs to send SETUP packet first, then wait 15
seconds before DATA (IN) + STATUS stage.

It is needed at USB Certification test for Embedded Host 2.0, and
the detail is at CH6.4.1.1 of On-The-Go and Embedded Host Supplement
to the USB Revision 2.0 Specification

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 6285bee2a8 MLK-17380-3 usb: move EH SINGLE_STEP_SET_FEATURE implement to core
Since other USB 2.0 host may need it, like USB2 for XHCI. We move
this design to HCD core.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 0da3954afb MLK-17380-2 usb: host: ehci: always enable interrupt for qtd completion at test mode
At former code, the SETUP stage does not enable interrupt
for qtd completion, it relies on IAA watchdog to complete
interrupt, then the transcation would be considered timeout
if the flag need_io_watchdog is cleared by platform code.

In this commit, we always add enable interrupt for qtd completion,
then the qtd completion can be notified by hardware interrupt.

Acked-by: Jun Li <jun.li@nxp.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen d9f4303aa4 MLK-17366-2 usb: cdns3: decrease autosuspend timeout
Cadence3 low power sequence doesn't allow too much time gap
between xhci bus suspend and controller suspend,
otherwise, the disconnection will be seen between them.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 16ff593e31 MLK-17366-1 usb: cdns3: improve USB PHY operation
Improve USB PHY operation, and keep 32K clock for RX detection
all the time, it can fix SS connection can't be recognition
from U3.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Manu Gautam 1f0a6f8604 usb: dwc3: Don't reinitialize core during host bus-suspend/resume
Driver powers-off PHYs and reinitializes DWC3 core and gadget on
resume. While this works fine for gadget mode but in host
mode there is not re-initialization of host stack. Also, resetting
bus as part of bus_suspend/resume is not correct which could affect
(or disconnect) connected devices.
Fix this by not reinitializing core on suspend/resume in host mode
for HOST only and OTG/drd configurations.

Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
(cherry picked from commit 689bf72c6e)
2018-10-29 11:10:38 +08:00
Peter Chen 81f2e8c85f MLK-17312-5 usb: cdns3: improve the role switch process
Current design tries to switch role no matter it is a dual-role device
or a single-role device. It produces extra switch process, and have an
error message at console when tries to start a non-exist role.

In this commit, we do below changes
- The role switch work queue is only for dual-role or peripheral-only
device.
- For peripheral-only device, we need to switch role to CDNS3_ROLE_END
since we need to close vbus and turn off clocks at this role when the
cable is disconnected from the host; And we do noop when the external
cable indicates we are host.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 3974104571 MLK-17312-4 usb: cdns3: gadget: fix the recognition issue when connection before load module
At imx8qm/imx8qxp A0 chip, there is a vbus toggle issue, so we need to
force the vbus as high before connection, otherwise, there will be endless
connect/disconnect interrupts for USB2 and causes enumeration failure.
The current work flow only cover this during the role switch, but omit
it when the connection has established at module probe routine.

This patch fixes it by moving force vbus operation to cdns_set_role to
cover both static and dynamic recognition issue.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen a66e78d8fc MLK-17312-3 usb: cdns3: gadget: configure all endpoints before set configuration
Cadence IP has one limitation that all endpoints must be configured
(Type & MaxPacketSize) before setting configuration through hardware
register, it means we can't change endpoints configuration after
set_configuration.

In this patch, we add non-control endpoint through usb_ss->ep_match_list,
which is added when the gadget driver uses usb_ep_autoconfig to configure
specific endpoint; When the udc driver receives set_configurion request,
it goes through usb_ss->ep_match_list, and configure all endpoints
accordingly.

At usb_ep_ops.enable/disable, we only enable and disable endpoint through
ep_cfg register which can be changed after set_configuration, and do
some software operation accordingly.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen b4a2ce43a4 MLK-17312-2 usb: cdns3: gadget: improve comments
Fix typos and some error comments

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen bb95435c1d MLK-17312-1 usb: cdns3: gadget: prepare setup packet buffer before receiving it
At current setup packet handling flow, the setup packet buffer
is only prepared after the controller receives the setup packet,
then stores it at its internal buffer, and trigger DESCMIS interrupt
(Transfer descriptor missing) to prepare TRB for it.

The shortcoming of this design is there is an extra DESCMIS interrupt,
and consume more time on enumeration process. As an improvement,
we parepare setup buffer beforehand, it is prepared at below situations:
- After bus reset has finished.
- For non-data stage setup transfers, prepare it before sending ACK for
status stage.
- For data stage setup transfers, prepare it after data stage but
before sending ACK for status stage.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 5e1b455775 MLK-17261-2 usb: chipidea: imx: do not call hsic callback for non-hsic controller
With this judgement, the non-hsic controller will access wrong registers,
and below error message will be showed:
"usbmisc_imx 2184800.usbmisc: index is error for usbmisc"

Fixes: 113be1516160 ("MLK-16715-6 usb: chipidea: imx:
	add HSIC support for controllers from imx7d")
Reported-by: Peng Fan <peng.fan@nxp.com>
Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 683f828fa1 MLK-17261-1 usb: cdns3: gadget: fix the spinlock recursion problem when detach cable
The __cdns3_gadget_stop holds spinlock before calling
usb_ss->gadget_driver->disconnect which calls ep_disable,
and ep_disable tries to hold spinlock too.

To fix it, let spinlock only protect the variable and register access.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 6e4a670135 MLK-17062 usb: cdns3: gadget: add test mode support for USB2
Add USB2 device test mode support for CDNS3 IP

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 979482c70b MLK-17203 usb: host: xhci-plat: fix high bus freq release mismatch
If the xhci platform device is already suspended, we can't
release high bus freq again, fix the high bus count mismatch.

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen a894fedcf7 MLK-16715-7 usb: chipidea: imx: add "ci-disable-lpm" quirk
Some chipidea hardware needs to disable low power mode for controller
due to IC issue or hardware issue, add one quirk for it.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 9f88055220 MLK-16715-6 usb: chipidea: imx: add HSIC support for controllers from imx7d
From imx7d, there is a dedicate non-core register region for
each controller, and HSIC configurations are almost at non-core
register, this commit adds HSIC support for controllers from imx7d,
and the non-core confugrations are different with imx6's.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 30c6a67e7c MLK-16715-5 usb: chipidea: imx: using phy_mode to judge HSIC controller
HSIC controller must use HSIC phy mode, it is more suitable way
to judge HSIC controller.

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 1646aef0c7 MLK-16715-4 usb: chipidea: imx: add imx8qm compatible
It is suitable for imx8qm and imx8qxp currently

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 4113dd8b8a MLK-16715-1 usb: chipidea: imx: replace &pdev->dev with local variable
There are tens of &pdev->dev, replace them with a local
variable

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 44a5052dc7 MLK-16976-4 usb: cdns3: add power management support
This patch set adds both runtime and system-level pm support.
For runtime-pm: both host and device wakeup events are supported.
For system-pm: only host wakeup events are supported, device wakeup
events are from other peripherals, and will support later.

BuildInfo:
- SCFW 245582b, IMX-MKIMAGE 0ad6069a, ATF 6bd98a3
- U-Boot 2017.03-imx_v2017.03+gfa65b0a

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun d57334e28d MLK-16604-1 usb: host: xhci-plat: add XHCI_MISSING_CAS quirk
i.MX8MQ USB3 host needs XHCI_MISSING_CAS quirk to warm reset the port to
enum the USB3 device plugged in while system sleep, as the port state is
stuck in polling mode after resume.

Signed-off-by: Li Jun <jun.li@nxp.com>
Acked-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen f93edd0f08 MLK-16735 usb: host: add XHCI_CDNS_HOST flag
The NXP Cadence XHCI host has the same issue with Intel's,
it is triggered by reboot test, the test case is described
at this jira ticket.

BuildInfo:
- SCFW 8dcff26, IMX-MKIMAGE ea027c4b, ATF
- U-Boot 2017.03-imx_v2017.03_4.9.51_imx8_beta1+g6dc7b0f

Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 3ae6f3e921 MLK-16775-2 usb: xhci: plat: only do high bus freq for runtime pm
Remove xhci_suspend and xhci_resume as i.MX8MQ dwc3 can't support it,
add high bus request and release, and enable runtime pm by default.

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 835da03f13 MLK-16775-1 usb: dwc3: gadget: add high bus freq support
Add high bus request for connection to host in reset handling,
and high bus release for disconnection.

Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun e7bc1ee1c2 MLK-16774 usb: gadget: utp: fix coverity CID 414727 issue
CID 414727: Explicit null dereferenced (FORWARD_NULL)
var_deref_op: Dereferencing null pointer uud.

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 157f65cd5a MLK-16682 usb: cdns3: gadget: delete useless is_iso_flag
Since the runtime endpoint type is decided by device descriptors,
we delete useless is_iso_flag which is decided during the initialization.
It also fixed a bug the max_packet_size is determined wrongly for
high/full speed connection.

BuildInfo:
- SCFW 8dcff26, IMX-MKIMAGE ea027c4b, ATF
- U-Boot 2017.03-imx_v2017.03_4.9.51_imx8_beta1+g6dc7b0f

Acked-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen f78429aa5b MLK-16727-3 usb: cdns3: force vbus status accordingly
Since the controller doesn't know vbus status well due to IC limitation,
it needs to force vbus status for controller when the connection and
disconnection occur.

BuildInfo:
- SCFW 8dcff26, IMX-MKIMAGE ea027c4b, ATF
- U-Boot 2017.03-imx_v2017.03_4.9.51_imx8_beta1+g6dc7b0f

Acked-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 13a9557db0 MLK-16727-1 usb: cdns3: needs to handle disconnection at device mode
The IP has some issues to detect vbus status correctly, we have to
force vbus status accordingly, so we need a status to indicate
vbus disconnection, and add some code to let control know vbus
removal, in that case, the controller's state mechine can be correct.

In this commit, we increase one role 'CDNS3_ROLE_END' to for
this status.

BuildInfo:
- SCFW 8dcff26, IMX-MKIMAGE ea027c4b, ATF
- U-Boot 2017.03-imx_v2017.03_4.9.51_imx8_beta1+g6dc7b0f

Acked-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun d43eee1b89 MLK-16576 usb: phy: mxs: set hold_ring_off for USB2 PLL power up
USB2 PLL use ring VCO, when the PLL power up, the ring VCO’s supply also
ramp up. There is a possibility that the ring VCO start oscillation at
multi nodes in this phase, especially for VCO which has many stages, then
the multiwave will kept until PLL power down. Hold_ring_off(bit11) can
force the VCO in one determined state when VCO supply start ramp up, to
avoid this multiwave issue. Per IC design's suggestion it's better this
bit can be off from 25us after pll power up to 25us before USB TX/RX.

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
(cherry picked from commit a094377f04c9ed2c8e702ee7bfab843caa03eb96)
2018-10-29 11:10:38 +08:00
Peter Chen 6a2e287a6d MLK-16522-3 usb: cdns3: do not disable interrupt during role switch
After "MLK-16522-1 usb: cdns3: change cdns3_role_start work flow", the
software maintained role is current role which is doing role_start, so
it should handle its initialization routine well, just like we only has
one role and the interrupt is enabled at that time.

And disable interrupt causes one timeout problem during remove hcd, the
last command takes about 5 seconds to finish. See below for detail:

[   84.894639]  xhci-cdns3: remove, state 1
[   84.898768]  xhci-cdns3: roothub graceful disconnect
[   84.898784] usb usb2: USB disconnect, device number 1
[   84.904052] usb 2-1: USB disconnect, device number 4
[   84.909195] usb 2-1: unregistering device
[   84.909204] usb 2-1: unregistering interface 2-1:1.0
[   84.931247] usb 2-1: usb_disable_device nuking all URBs
[   84.931264]  xhci-cdns3: xhci_drop_endpoint called for udev ffff80083b755000
[   84.931274]  xhci-cdns3: drop ep 0x81, slot id 3, new drop flags = 0x8, new add flags = 0x0
[   84.931278]  xhci-cdns3: xhci_drop_endpoint called for udev ffff80083b755000
[   84.931283]  xhci-cdns3: drop ep 0x2, slot id 3, new drop flags = 0x18, new add flags = 0x0
[   84.931288]  xhci-cdns3: xhci_check_bandwidth called for udev ffff80083b755000
[   84.931302]  xhci-cdns3: New Input Control Context:
[   84.931309]  xhci-cdns3: @ffff000009aa7000 (virt) @d8288000 (dma) 0x000018 - drop flags
[   84.931314]  xhci-cdns3: @ffff000009aa7004 (virt) @d8288004 (dma) 0x000001 - add flags
[   84.931320]  xhci-cdns3: @ffff000009aa7008 (virt) @d8288008 (dma) 0x000000 - rsvd2[0]
[   84.931325]  xhci-cdns3: @ffff000009aa700c (virt) @d828800c (dma) 0x000000 - rsvd2[1]
[   84.931331]  xhci-cdns3: @ffff000009aa7010 (virt) @d8288010 (dma) 0x000000 - rsvd2[2]
[   84.931336]  xhci-cdns3: @ffff000009aa7014 (virt) @d8288014 (dma) 0x000000 - rsvd2[3]
[   84.931341]  xhci-cdns3: @ffff000009aa7018 (virt) @d8288018 (dma) 0x000000 - rsvd2[4]
[   84.931346]  xhci-cdns3: @ffff000009aa701c (virt) @d828801c (dma) 0x000000 - rsvd2[5]
[   84.931350]  xhci-cdns3: Slot Context:
[   84.931355]  xhci-cdns3: @ffff000009aa7020 (virt) @d8288020 (dma) 0x8400000 - dev_info
[   84.931360]  xhci-cdns3: @ffff000009aa7024 (virt) @d8288024 (dma) 0x020000 - dev_info2
[   84.931365]  xhci-cdns3: @ffff000009aa7028 (virt) @d8288028 (dma) 0x000000 - tt_info
[   84.931371]  xhci-cdns3: @ffff000009aa702c (virt) @d828802c (dma) 0x000000 - dev_state
[   84.931377]  xhci-cdns3: @ffff000009aa7030 (virt) @d8288030 (dma) 0x000000 - rsvd[0]
[   84.931382]  xhci-cdns3: @ffff000009aa7034 (virt) @d8288034 (dma) 0x000000 - rsvd[1]
[   84.931387]  xhci-cdns3: @ffff000009aa7038 (virt) @d8288038 (dma) 0x000000 - rsvd[2]
[   84.931392]  xhci-cdns3: @ffff000009aa703c (virt) @d828803c (dma) 0x000000 - rsvd[3]
[   84.931398]  xhci-cdns3: IN Endpoint 00 Context (ep_index 00):
[   84.931403]  xhci-cdns3: @ffff000009aa7040 (virt) @d8288040 (dma) 0x000000 - ep_info
[   84.931408]  xhci-cdns3: @ffff000009aa7044 (virt) @d8288044 (dma) 0x2000026 - ep_info2
[   84.931414]  xhci-cdns3: @ffff000009aa7048 (virt) @d8288048 (dma) 0xd828f001 - deq
[   84.931419]  xhci-cdns3: @ffff000009aa7050 (virt) @d8288050 (dma) 0x000000 - tx_info
[   84.931424]  xhci-cdns3: @ffff000009aa7054 (virt) @d8288054 (dma) 0x000000 - rsvd[0]
[   84.931429]  xhci-cdns3: @ffff000009aa7058 (virt) @d8288058 (dma) 0x000000 - rsvd[1]
[   84.931434]  xhci-cdns3: @ffff000009aa705c (virt) @d828805c (dma) 0x000000 - rsvd[2]
[   84.931447]  xhci-cdns3: // Ding dong!
[   85.096180] FAT-fs (sda1): FAT read failed (blocknr 32)
[   90.134581]  xhci-cdns3: Command timeout
[   90.134590]  xhci-cdns3: Abort command ring
[   92.150582]  xhci-cdns3: No stop event for abort, ring start fail?
[   92.150606]  xhci-cdns3: Timeout while waiting for configure endpoint command
[   92.158310] usb usb2: unregistering device
[   92.158321] usb usb2: unregistering interface 2-0:1.0
[   92.158447]  xhci-cdns3: shutdown urb ffff80083b8f0700 ep1in-intr
[   92.158704] usb usb2: usb_disable_device nuking all URBs
[   92.158715] xHCI xhci_drop_endpoint called for root hub
[   92.158719] xHCI xhci_check_bandwidth called for root hub
[   92.159067]  xhci-cdns3: // Halt the HC
[   92.159075]  xhci-cdns3: // Reset the HC
[   92.159096]  xhci-cdns3: Wait for controller to be ready for doorbell rings
[   92.159102]  xhci-cdns3: USB bus 2 deregistered
[   92.163789]  xhci-cdns3: remove, state 4
[   92.167772]  xhci-cdns3: roothub graceful disconnect
[   92.167786] usb usb1: USB disconnect, device number 1
[   92.172880] usb usb1: unregistering device
[   92.172894] usb usb1: unregistering interface 1-0:1.0
[   92.173151] usb usb1: usb_disable_device nuking all URBs

BuildInfo:
- SCFW 1f59442e, IMX-MKIMAGE fb52c576, ATF
- U-Boot 2017.03-imx_v2017.03+g34be5a2

Acked-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 29ca6d5bec MLK-16522-2 usb: cdns3: host: change remove sequence for hcd
At probe, the main hcd is added first, then shared_hcd is added later,
so when we tries to remove hcds, the shared_hcd needs to remove first.

BuildInfo:
- SCFW 1f59442e, IMX-MKIMAGE fb52c576, ATF
- U-Boot 2017.03-imx_v2017.03+g34be5a2

Acked-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 015b78a114 MLK-16522-1 usb: cdns3: change cdns3_role_start work flow
When it goes to start new role, the interrupt may be occurred before
role_start returns, but at this time, the cdns->role is still the old
role, so the interrupt handler will make mistake.

In this commit, we set desired role before role_start, if the role_start
has failed and the desired role is different with current one, it tries
to back current role.

BuildInfo:
- SCFW 1f59442e, IMX-MKIMAGE fb52c576, ATF
- U-Boot 2017.03-imx_v2017.03+g34be5a2

Acked-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen e0ccad30e4 MLK-16532 usb: chipidea: do not call WARN_ON if controller is going to suspend twice
At current PM framework, the dev->runtime_suspend may be called after
dev->system_suspend is called, and the dev->runtime_resume may be called
before dev->system_suspend is called. So, we need to delete WARN_ON to
avoid before dump:

[  466.712978] [<ffff200008c49cdc>] ci_hdrc_imx_runtime_suspend+0x2c/0xa8
[  466.719619] [<ffff2000088c29e8>] pm_generic_runtime_suspend+0x48/0x68
[  466.726168] [<ffff2000088d4f04>] genpd_runtime_suspend+0xcc/0x300
[  466.732372] [<ffff2000088c7068>] pm_runtime_force_suspend+0x48/0xa8
[  466.738748] [<ffff2000088d5330>] pm_genpd_suspend_noirq+0xa0/0x118
[  466.745032] [<ffff2000088c86ec>] dpm_run_callback+0x4c/0xc0
[  466.750709] [<ffff2000088c941c>] __device_suspend_noirq+0x194/0x3d0
[  466.757080] [<ffff2000088cb460>] dpm_suspend_noirq+0x188/0x328
[  466.763024] [<ffff200008143218>] suspend_devices_and_enter+0x230/0x650
[  466.769655] [<ffff200008143990>] pm_suspend+0x358/0x3d0
[  466.774984] [<ffff200008141f0c>] state_store+0x8c/0x100
[  466.780321] [<ffff20000857a83c>] kobj_attr_store+0x44/0x60
[  466.785915] [<ffff2000083436a8>] sysfs_kf_write+0x98/0xb0
[  466.791419] [<ffff200008342118>] kernfs_fop_write+0x120/0x288
[  466.797276] [<ffff20000828d518>] __vfs_write+0xc0/0x238
[  466.802604] [<ffff20000828e900>] vfs_write+0xc8/0x248
[  466.807764] [<ffff200008290678>] SyS_write+0xa0/0x110
[  466.812919] [<ffff20000808374c>] __sys_trace_return+0x0/0x4

BuildInfo:
- SCFW 1f59442e, IMX-MKIMAGE fb52c576, ATF
- U-Boot 2017.03-imx_v2017.03+g34be5a2

Cc: Anson Huang <anson.huang@nxp.com>
Acked-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 9e71ef5fb2 MLK-16285-6 usb: cdns3: add more operatons at cdns3_remove
Add PHY shutdown and clock disable operations at cdns3_remove.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
Acked-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen af73fc0bc7 MLK-16285-4 usb: cdns3: change controller role state machine
Since the USB Type-C port only has two data roles, host and device,
the controller driver can only receive above two events, it can't
remain 'disconnection' state alone at controller driver due to there
is no such event from Type-C.

Due to above, we delete the controller state "CDNS3_ROLE_END" which
stands for 'disconnection' state before. Instead, when we use
"CDNS3_ROLE_GADGET" stands for it, and this state is the default
state for controller.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
Acked-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 75f6c64125 MLK-16285-3 usb: cdns3: core: move INIT_WORK before cdns3_register_extcon
At the extcon notifier, it will queue a work item, so we need to
make sure the work is initialized before it is used.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
Acked-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen e3d7296cb7 MLK-16221-6 usb: cdns3: gadget: fix non-initialized spinlock warning
The below warning is showed if we open lockdep debug, fix it by
initializing spinlock before using it.

[  192.159535] INFO: trying to register non-static key.
[  192.164507] the code is fine but needs lockdep annotation.
[  192.169996] turning off the locking correctness validator.
[  192.175485] CPU: 1 PID: 2831 Comm: modprobe Not tainted 4.9.11-03045-g39aab30 #514
[  192.183054] Hardware name: Freescale i.MX8QXP LPDDR4 ARM2 (DT)
[  192.188884] Call trace:
[  192.191348] [<ffff200008089234>] dump_backtrace+0x0/0x1e0
[  192.196751] [<ffff200008089428>] show_stack+0x14/0x1c
[  192.201808] [<ffff2000084046f4>] dump_stack+0xb0/0xec
[  192.206865] [<ffff200008107570>] register_lock_class+0x510/0x538
[  192.212873] [<ffff20000810b7c4>] __lock_acquire+0x84/0x6f0
[  192.218363] [<ffff20000810c34c>] lock_acquire+0x68/0xc8
[  192.223596] [<ffff200008bfe1f4>] _raw_spin_lock_irqsave+0x50/0x68
[  192.229694] [<ffff200008857528>] usb_ss_gadget_udc_start+0x38/0x1b0
[  192.235966] [<ffff20000889da8c>] udc_bind_to_driver+0xcc/0x11c
[  192.241803] [<ffff20000889e0e4>] usb_gadget_probe_driver+0xa4/0x150
[  192.248077] [<ffff2000088983a8>] usb_composite_probe+0xb8/0xd8
[  192.253923] [<ffff200000ce8018>] msg_init+0x18/0x1000 [g_mass_storage]
[  192.260456] [<ffff200008083960>] do_one_initcall+0x38/0x12c
[  192.266033] [<ffff200008187764>] do_init_module+0x98/0x214
[  192.271523] [<ffff2000081465fc>] load_module+0x1014/0x10f0
[  192.277012] [<ffff200008146970>] SyS_finit_module+0xc8/0xd4
[  192.282590] [<ffff20000808374c>] __sys_trace_return+0x0/0x4

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 5b4df01866 MLK-16221-5 usb: cdns3: gadget: fix wMaxPacketSize for ep0
We should set wMaxPacketSize according to connection speed,
and add missing ep0 descriptor.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 69c992051e MLK-16221-4 usb: cdns3: gadget: disable device mode when the gadget is stopped
After USB_CONF.DEVDS is set, the device mode will be disabled, and the
host will set the disconnection, this bit is just like DP pullup bit
at USB2.

And we add disable/enable device mode logic at .pullup function for
UDC core.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 31c9a5ad20 MLK-16221-3 usb: cdns3: gadget: add free memory operation when gadget is stopped
When the UDC core calls ->udc_stop, we need to free related non-ep TRB
memory.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen e9c6c62592 MLK-16221-2 usb: cdns3: gadget: avoid visiting register when detach
When the port does not connect to host, the controller's gadget
mode is enabled, so we need to avoid visiting register at this situation.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 0b0bbf9701 MLK-16221-1 usb: cdns3: add module removal support
We need to destroy both host and gadget roles when removing module.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 3438298d8e MLK-16065-16 usb: cdns3: gadget: fix no one handled interrupt issue
If there are too many interrupts for non-control ep, the
no-one handled interrupt issue will occur due to without
return IRQ_HANDLED for them.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 635bb5bc9b MLK-16065-15 usb: cdns3: gadget: refine the enable endpoint operation
Move non-ep enable operation from set_configuration to ep_enable

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen e6594830db MLK-16065-10 usb: host: xhci-dbg: do not print reseverd registers for imx cdns host
When access reserved registers, the cdns host will trigger
an exception, and the synchronous external abort will occur
at ARM64 platforms.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen f9819cd91a MLK-16065-9 usb: cdns3: host: add quirk for avoid access reverved registers
Add quirk for CDNS USB3 host.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 0ac261373c MLK-16065-8 usb: host: xhci: add XHCI_SKIP_ACCESS_RESERVED_REG quirk
The IMX XHCI host which uses cadence USB3 IP is not compatible with
xHCI spec, the controller will trigger an exception if
visiting reserved registers, but the xHCI spec does not forbid it,
so add one quirk for skipping access reserved registers.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 283a7f0303 MLK-16065-7 usb: cdns3: add Cadence USB3 controller driver
Add Cadence USB3 IP driver, this is the 1st version for this driver,
so wrapper layer and PHY layer are still IP core file (core.c).
Below functions are supported:

- Basic host function
- Limited gadget function, only ACM (old g_seiral) are supported, and
mass_storage support is not very well.
- Role switch between host and device through extcon design
(Eg, Type-C application NXP PTN5150).

Below functions are missing:
- Multi-queue support at gadget function, without this feature, many
gadget function are missing.
- Low power mode support, including system PM and runtime PM
- Wakeup support

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 0c9ed6d19b MLK-16135 usb: gadget: utp: bulk out req amount divisible by 512
As the code comments say, the bulk out req amount should be divisible
by 512, fix this by using set_bulk_out_req_length().

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 62ebe27822 MLK-16013-9 usb: typec: add interface to get port type and role
Add interface to get typec port type and default power role from
dt. To validate a correct setting is specified, add TYPEC_PORT_TYPE_UNKNOWN
and TYPEC_ROLE_UNKNOWN for typec_port_type and typec_role enum.

Reviewed-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>

During 4.14 rebase renamed to typec_port_types_dt to avoid conflict with
sysfs values.

Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun a1d1fa2220 MLK-16013-7 usb: dwc3: gadget: increase timeout count for ep cmd
Increase the timeout value for wait ep command complete, this is temp
solution to workaround it but no harm any good cases.

Reviewed-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun e1f11ee4b3 MLK-16013-4 usb: dwc3: add suspend_clk setting interface
Some dwc3 based USB3 IP may have a wrong default suspend clk
setting, so add an interface to correct it by dts property.

Reviewed-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 9335a95244 MLK-16013-3 usb: dwc3: of-simple: add imx8mq usb support
Add i.mx8mq USB3 phy compatible string for dwc3-of-simple driver.

Reviewed-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 18eb1cda1b MLK-15074-10 usb: gadget: utp: correct the set_fs condition
set_fs() should be done in case:
1. CONFIG_FSL_UTP is not enabled.
2. CONFIG_FSL_UTP is enabled but is_utp_device is false.

Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun daad0fe324 MLK-15074-9 usb: gadget: utp: fix wrong fsg parameter
As common->fsg maybe have not been set correctly while enumration, so
use the correct pointer fsg for utp device check.

Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun c22afb5c3a MLK-14947-5 chipidea: imx: add usb vbus power polarity setting
If the vbus is controlled by ehci port power bit, we need set power
polarity of vbus enable signal according to the vbus power supply
chip on board.

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 79d13a3068 MLK-14947-2 usb: phy: add mxs phy driver dependency for ARM64
Add mxs phy driver dependency on ARCH_MXC_ARM64.

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 89bf9fdf35 MLK-14285-3 usb: phy: mxs: optimize disconnect line condition
We only have below cases to disconnect line when suspend:
1. Device mode without connection to any host/charger(no vbus).
2. Device mode connect to a charger(w/ vbus), usb suspend when
   system is entering suspend.
This patch can fix usb phy wrongly does disconnect line in case
some usb host enters suspend but vbus is off.

Signed-off-by: Li Jun <jun.li@nxp.com>
(cherry picked from commit 2af48913f77cec3658f5863b13f63619d8101279)
2018-10-29 11:10:38 +08:00
Li Jun c57ce3ea52 MLK-14285-2 usb: chipidea: set mode for usb phy driver
After enters one specific role, notify usb phy driver.

Signed-off-by: Li Jun <jun.li@nxp.com>
(cherry picked from commit d3aa2a13f4e47bc7fae7f2eee1e86291d7513312)
2018-10-29 11:10:38 +08:00
Li Jun 4965562f9e MLK-14673 usb: chipidea: imx: enable correct wakeup for imx7d
Enable ID change wakeup for OTG; and VBUS wakeup for OTG and
peripheral only mode.

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen e55e960589 MLK-14396 usb: chipidea: add mutex for concurrent running
The ci_handle_id_switch is called at two places, at very rare situations,
it may be running at the same time. Eg, when the system is back from
the resume, the id event is occurred from extcon driver, as well as
power_lost work item is called due to the controller is poweroff at
the suspend.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen e4afee3fc1 MLK-13851-1 usb: chipidea: otg: delete the workaround code
After commit 4967018428 ("usb: chipidea: otg: change workqueue
ci_otg as freezable"), we have fixed the bug that ID removed
wakeup (ID: 0->1) will lock up system resume, we delete the
workaround code in this commit.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 465bad6ff6 MLK-13638-6 usb: chipidea: add recovery from vbus is off during system suspend
When the vbus is off during the suspend controller is powered off, if we
do not want to see disconnection from USB core, we need to make sure the
device pulls DP up before USB core resume runs. However, several devices
are slow to pull DP up when see vbus (maybe it needs vbus to power up
system), so we need to wait connection at platform code.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 6501172d8e MLK-13638-5 usb: chipidea: usbmisc_imx: add power_lost_check API for imx7ulp
For imx7ulp, the power of USB controller may be lost, add power_lost_check
API for USB recovery.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 5c630c6abe MLK-13570-8 usb: chpidea: usbmisc_imx: add non-burst setting for both imx7d and imx7ulp
For all imx Socs later than imx6 (including imx6), the USB_nSBUSCFG.AHBBRST
will be set as 0 at dtsi file, so the non-burst setting needs to be
set at non-core register, or there will be no burst for USB AHB/AXI
transfer.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 2452f593d2 MLK-13570-5 usb: chipidea: imx: introduce pmqos for imx7ulp
At imx7ulp, if the system enters idle, it will close some clocks and affect
USB transfer. In order to avoid it, we request pmqos to avoid system
entering idle when the USB is in use.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen bee188567a MLK-13570-4 usb: chipidea: usbmisc_imx: add imx7ulp entry
imx7ulp non core register mapping is similar with imx7d, and the
initialization is the same, but lacks of USB charger detection support.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 0d8b0537fd MLK-15032-3 usb: chipidea: core: remove the extcon change for imx_4.1.y
commit 916e43e1d6fb ("MLK-13570-3 usb: chipidea: core: change extcon
usage for imx_4.1.y") is directly cherry-picked from 4.1.y, but which
is not valid anymore on 4.y kernel, so revert most part and only keep
the irq check after resume.

Reviewed-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 250779ccff MLK-13570-3 usb: chipidea: core: change extcon usage for imx_4.1.y
At v4.1 kernel, we can't get cable type at notifier, but at
extcon-usb-gpio.c notifies both VBUS and ID event, we had to
do special handling for ID event, and omit VBUS event. Current
implementation only supports ID extcon event.

If wakeup event occurs by extcon, it needs to call ci_irq again since the
first ci_irq calling at extcon notifier only wakes up controller, but
do noop for event handling.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 9aadcd6717 MLK-13570-2 usb: phy: phy-mxs-usb: add imx7ulp support
At imx7ulp, the USB related analog register is located in PHY register
region too, so we need to control PLL at PHY driver directly.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen d7f201e92c MLK-13308-2 usb: phy: phy-mxs-usb: handle USB PHY event
For mxs PHY, if there is a vbus but the bus is not enumerated,
force the dp/dm as SE0 from the consider side. If not, there
is possible USB wakeup due to unstable dp/dm, since there is
possible no pull on dp/dm, eg, there is a USB charger on the
port. Note, the vbus event is only occurred at device mode,
and sent by udc driver.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen f5e7baeae4 MLK-13308-1 usb: chipidea: udc: add USB PHY event
Add USB PHY event for below situation:
- vbus connect
- vbus disconnect
- gadget driver is enumerated

USB PHY driver can get the last event after above situation
occurs.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 04165166bd MLK-13125 usb: phy: phy-mxs-usb: enable weak 1p1 regulator for imx6ul during suspend
For imx6ul PHY, when the system enters suspend, its 1p1 is off by default,
that may cause the PHY get inaccurate USB DP/DM value. If the USB wakeup
is enabled at this time, the unexpected wakeup may occur when the system
enters suspend.

In this patch, when the vbus is there, we enable weak 1p1 during the PHY
suspend API, in that case, the USB DP/DM will be accurate for USB PHY,
then unexpected usb wakeup will not be occurred, especially for the USB
charger is connected scenario. The user needs to enable PHY wakeup for
USB wakeup function using below setting.

echo enabled > /sys/devices/platform/soc/2000000.aips-bus/20c9000.usbphy
/power/wakeup

Cc: Shaojun Wang <shaojun.wang@nxp.com>
Cc: Anson Huang <anson.huang@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Peter Chen 46fe49a59d MLK-12860-4 usb: chipidea: imx: add HSIC support for imx7d
Add HSIC support for imx7d. We have not supported HSIC as system
wakeup as well as HSIC remote wakeup function at DSM mode, since
the 24M OSC can't be off and the SoC internal regulators can't be
off at this mode, that will keep power consumption much higher.

Signed-off-by: Peter Chen <peter.chen@freescale.com>
2018-10-29 11:10:38 +08:00
Peter Chen 32d206bd13 MLK-12731 usb: chipidea: imx: add missing HSIC initialization for imx6qdl/sl
This piece of code is existed at imx_3.10, but missing at imx_3.14 and
imx_4.1, port it from imx_3.10.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 686be963e4 MLK-12421 usb: chipidea: fix build warning if disable CONFIG_USB_CHIPIDEA_HOST
Fix chipidea usb driver compile warning if CONFIG_USB_CHIPIDEA_HOST
is disabled:
In file included from drivers/usb/chipidea/otg.c:26:0:
drivers/usb/chipidea/host.h:23:13: warning: 'ci_hdrc_host_driver_init'
defined but not used [-Wunused-function]
 static void ci_hdrc_host_driver_init(void)
             ^
  CC      drivers/usb/chipidea/otg_fsm.o
In file included from drivers/usb/chipidea/otg_fsm.c:34:0:
drivers/usb/chipidea/host.h:23:13: warning: 'ci_hdrc_host_driver_init'
defined but not used [-Wunused-function]
 static void ci_hdrc_host_driver_init(void)
             ^

Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00
Li Jun 405d8dba79 MLK-12344-3 usb: chipidea: update power lost handling for gadget
After we put gadget disconnect and connect in id switch handling,
update power lost work accordingly.

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
(cherry picked from commit fd49596ece)
2018-10-29 11:10:38 +08:00
Li Jun 218716b50f MLK-12344-2 usb: chipidea: otg: add vbus disconnect for gadget after sleep
During system sleep, if we switch otg role from gadget to host, and host
vbus is directly controlled by ID signal, we will lose vbus drop event
after resume because the vbus is on both at system suspend and resume, so
we will miss gadget disconnect handling before start host role. This patch
is to fix it by adding gadget disconnect for this case.

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
(cherry picked from commit 79aab6fc3c)
2018-10-29 11:10:38 +08:00
Li Jun 0ab784343c MLK-12344-1 usb: chipidea: otg: add vbus connect for gadget after sleep
During system sleep, if we switch otg role from host to gadget, because
the vbus is on both at system suspend and resume, we will lose vbus
connect event after system resume, thus, no chance to setup vbus session
for gadget so enumeration will not happen. This patch is to fix it by
adding vbus connect handling for this case.

Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
(cherry picked from commit bd54eea0f7)
2018-10-29 11:10:38 +08:00
Li Jun 1f5d1a9ffd MLK-11896-8 usb: phy: mxs: declar variable with initialized value
Fix coverity CID 17601 uninitialized scalar variable: vbus_value.

Signed-off-by: Li Jun <jun.li@nxp.com>
2018-10-29 11:10:38 +08:00