1
0
Fork 0
Commit Graph

154 Commits (55043fe464ceb19197d02ff76b53efbf04af984f)

Author SHA1 Message Date
Alistair Francis 55043fe464 rM2: usb: chipidea: rM2 specific changes
Signed-off-by: Alistair Francis <alistair@alistair23.me>
2021-02-07 14:28:26 -08:00
Peter Chen 2c9b4dafaf
MLK-24475-1 usb: chipidea: udc: delete the WARN_ON for .pullup
The UDC core calls .pullup unconditional during gadget loading
routine (see below dump), if the controller is in low power mode,
it will trigger WARN_ON. It is not easy to change common code
behavior easily, it deletes the WARN_ON now.

[   46.613319] Mass Storage Function, version: 2009/09/11
[   46.618503] LUN: removable file: (no medium)
[   46.662123] ------------[ cut here ]------------
[   46.666765] WARNING: CPU: 3 PID: 741 at drivers/usb/chipidea/udc.c:1720 ci_udc_pullup+0xd4/0xe0
[   46.675470] Modules linked in:
[   46.678534] CPU: 3 PID: 741 Comm: sh Not tainted 5.4.47-00053-gc4f85e73b4dc-dirty #277
[   46.686451] Hardware name: Freescale i.MX8QXP MEK (DT)
[   46.691597] pstate: 80000005 (Nzcv daif -PAN -UAO)
[   46.696391] pc : ci_udc_pullup+0xd4/0xe0
[   46.700320] lr : usb_gadget_disconnect+0x38/0x140
[   46.705024] sp : ffff800012763be0
[   46.708333] x29: ffff800012763be0 x28: ffff000837cd0000
[   46.713649] x27: 0000000000000000 x26: ffff000836dede00
[   46.718966] x25: ffff000837c94000 x24: ffff000837502500
[   46.724282] x23: ffff00083bf98498 x22: ffff0008368a6348
[   46.729599] x21: 0000000000000000 x20: 0000000000000000
[   46.734916] x19: ffff00083bf98498 x18: 0000000000000001
[   46.740233] x17: 0000000000000000 x16: 0000000000000000
[   46.745550] x15: ffff000837cd0470 x14: ffffffffffffffff
[   46.750866] x13: 0000000000000000 x12: ffff8000123b6000
[   46.756183] x11: ffff800012157000 x10: ffff8000123b6328
[   46.761500] x9 : ffff800012242000 x8 : ffff800012242000
[   46.766817] x7 : ffff800012242000 x6 : 0000000000010001
[   46.772133] x5 : ffff8000129b6040 x4 : 0000000000000001
[   46.777450] x3 : 0000000000000040 x2 : ffff800010cc5500
[   46.782767] x1 : ffff00083bf98080 x0 : 0000000000000001
[   46.788086] Call trace:
[   46.790531]  ci_udc_pullup+0xd4/0xe0
[   46.794109]  usb_gadget_disconnect+0x38/0x140
[   46.798470]  usb_udc_vbus_handler+0x44/0x50
[   46.802657]  ci_udc_start+0xbc/0xe0
[   46.806149]  udc_bind_to_driver+0x84/0x140
[   46.810248]  usb_gadget_probe_driver+0xa4/0x158
[   46.814785]  gadget_dev_desc_UDC_store+0xd0/0x118
[   46.819496]  configfs_write_file+0x148/0x1d8
[   46.823769]  __vfs_write+0x48/0x90
[   46.827173]  vfs_write+0xe4/0x1c8
[   46.830493]  ksys_write+0x78/0x100
[   46.833898]  __arm64_sys_write+0x24/0x30
[   46.837825]  el0_svc_common.constprop.0+0x74/0x168
[   46.842617]  el0_svc_handler+0x34/0xa0
[   46.846373]  el0_svc+0x8/0xc
[   46.849255] ---[ end trace 4f72051fa5255b2d ]---
[   46.854090] ------------[ cut here ]------------
[   46.858732] WARNING: CPU: 3 PID: 741 at drivers/usb/chipidea/udc.c:1720 ci_udc_pullup+0xd4/0xe0
[   46.867438] Modules linked in:
[   46.870502] CPU: 3 PID: 741 Comm: sh Tainted: G        W         5.4.47-00053-gc4f85e73b4dc-dirty #277
[   46.879808] Hardware name: Freescale i.MX8QXP MEK (DT)
[   46.884946] pstate: 80000005 (Nzcv daif -PAN -UAO)
[   46.889742] pc : ci_udc_pullup+0xd4/0xe0
[   46.893669] lr : usb_gadget_disconnect+0x38/0x140
[   46.898373] sp : ffff800012763c40
[   46.901682] x29: ffff800012763c40 x28: ffff000837cd0000
[   46.906998] x27: 0000000000000000 x26: ffff000836dede00
[   46.912315] x25: ffff000837c94000 x24: ffff000837502500
[   46.917632] x23: ffff000836c04280 x22: ffff80001223edf0
[   46.922948] x21: 0000000000000000 x20: 0000000000000000
[   46.928265] x19: ffff00083bf98498 x18: 0000000000000001
[   46.933582] x17: 0000000000000000 x16: 0000000000000000
[   46.938899] x15: ffff000837cd0470 x14: ffffffffffffffff
[   46.944215] x13: 0000000000000000 x12: ffff8000123b6000
[   46.949532] x11: ffff800012157000 x10: ffff8000123b6328
[   46.954849] x9 : ffff800012242000 x8 : ffff800012242000
[   46.960166] x7 : ffff800012242000 x6 : 0000000000010001
[   46.965482] x5 : ffff8000129b6040 x4 : 0000000000000001
[   46.970799] x3 : 0000000000000000 x2 : ffff800010cc5500
[   46.976116] x1 : ffff00083bf98080 x0 : 0000000000000001
[   46.981435] Call trace:
[   46.983880]  ci_udc_pullup+0xd4/0xe0
[   46.987456]  usb_gadget_disconnect+0x38/0x140
[   46.991819]  udc_bind_to_driver+0x11c/0x140
[   46.996004]  usb_gadget_probe_driver+0xa4/0x158
[   47.000541]  gadget_dev_desc_UDC_store+0xd0/0x118
[   47.005252]  configfs_write_file+0x148/0x1d8
[   47.009526]  __vfs_write+0x48/0x90
[   47.012930]  vfs_write+0xe4/0x1c8
[   47.016249]  ksys_write+0x78/0x100
[   47.019654]  __arm64_sys_write+0x24/0x30
[   47.023582]  el0_svc_common.constprop.0+0x74/0x168
[   47.028375]  el0_svc_handler+0x34/0xa0
[   47.032129]  el0_svc+0x8/0xc
[   47.035011] ---[ end trace 4f72051fa5255b2e ]---

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2020-08-10 18:02:02 +08:00
Peter Chen c4f85e73b4
MLK-24465-2 usb: chipidea: udc: quit .pullup if the controller is in lpm
If the controller is in low power mode, it needs to skip pullup
operation since it is meaningless, meanwhile, it is not allowed
from current design, show warning message for it.

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2020-08-06 17:22:51 +08:00
Peter Chen 6f91298b54
MLK-24465-1 usb: chipidea: udc: update vbus flag for struct usb_udc correctly
At udc core, it sets vbus flag as true and call usb_gadget_connect by
default. But for chipidea udc driver, it depends on VBUS status to
call usb_gadget_connect, so it needs to set vbus flag according to
VBUS at the .udc_start. With this change, the un-necessary
usb_gadget_connect when load gadget function could be avoided.
It could fix below oops as well:

[   17.175905] BUG: scheduling while atomic: v4l_id/649/0x00000002
[   17.182016] Modules linked in: crct10dif_ce brcmfmac brcmutil synaptics_dsx_i2c fsl_imx8_ddr_perf galcore(O)
[   17.191893] CPU: 1 PID: 649 Comm: v4l_id Tainted: G           O      5.4.3-lts-lf-5.4.y+gf8118585ee3c #1
[   17.201369] Hardware name: FSL i.MX8MM DDR4 EVK RevB board (DT)
[   17.207286] Call trace:
[   17.209739]  dump_backtrace+0x0/0x140
[   17.213401]  show_stack+0x14/0x20
[   17.216717]  dump_stack+0xb4/0xf8
[   17.220033]  __schedule_bug+0x5c/0x70
[   17.223695]  __schedule+0x4b4/0x560
[   17.227181]  schedule+0x40/0xe0
[   17.230321]  schedule_hrtimeout_range_clock+0x9c/0x118
[   17.235455]  schedule_hrtimeout_range+0x10/0x18
[   17.239985]  usleep_range+0x74/0xa0
[   17.243473]  ci_controller_resume+0x90/0xd8
[   17.247652]  ci_runtime_resume+0xc/0x18
[   17.251488]  pm_generic_runtime_resume+0x28/0x40
[   17.256103]  __rpm_callback+0x88/0x140
[   17.259848]  rpm_callback+0x20/0x80
[   17.263334]  rpm_resume+0x39c/0x580
[   17.266819]  __pm_runtime_resume+0x38/0x80
[   17.270914]  ci_udc_pullup+0x40/0xf8
[   17.274489]  usb_gadget_activate+0x48/0x78
[   17.278582]  usb_function_activate+0x68/0xb8
[   17.282851]  uvc_function_connect+0x18/0x50
[   17.287031]  uvc_v4l2_open+0x5c/0x78
[   17.290607]  v4l2_open+0xa0/0x118
[   17.293922]  chrdev_open+0xa0/0x198
[   17.297408]  do_dentry_open+0x110/0x3b0
[   17.301240]  vfs_open+0x28/0x30
[   17.304381]  path_openat+0x4a0/0x1240
[   17.308040]  do_filp_open+0x74/0xf8
[   17.311525]  do_sys_open+0x168/0x218
[   17.315097]  __arm64_sys_openat+0x20/0x28
[   17.319107]  el0_svc_common.constprop.0+0x68/0x160
[   17.323898]  el0_svc_handler+0x20/0x80
[   17.327647]  el0_svc+0x8/0xc

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2020-08-06 17:22:51 +08:00
Peter Chen 809e95fe71
MLK-23677-5 usb: chipidea: udc: use tracepoint
Use tracepoint for adding td and td completion.

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2020-03-27 11:22:00 +08:00
Peter Chen 104a42c649
MLK-23677-3 usb: chipidea: udc: put as many as sg buffers per TD
At most of cases, the system allocated sg buffers for 4KB, but
the TD could contain 5 * 4KB non-contiguous buffers at most. In order
to avoid more chained TDs, we tried to put more sg buffers in one
TD instead of putting only one sg buffer.

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2020-03-27 11:21:59 +08:00
Peter Chen ff01b0f10d
MLK-23349-2 usb: chipidea: udc: add sg list support
For low system memory system (eg, 265M), it may met OOM issue if the
request buffer is large (eg, 64KB). We ran out below OOM issue for f_fs.
Luckily, the f_fs supports sg list now, the OOM issue is fixed with
this patch.

ufb: page allocation failure: order:4, mode:0x40cc0(GFP_KERNEL|__GFP_COMP),
nodemask=(null),cpuset=/,mems_allowed=0
CPU: 2 PID: 370 Comm: ufb Not tainted 5.4.3-1.1.0+g54b3750d61fd #1
Hardware name: NXP i.MX8MNano DDR4 EVK board (DT)
Call trace:
 dump_backtrace+0x0/0x140
 show_stack+0x14/0x20
 dump_stack+0xb4/0xf8
 warn_alloc+0xec/0x158
 __alloc_pages_slowpath+0x9cc/0x9f8
 __alloc_pages_nodemask+0x21c/0x280
 alloc_pages_current+0x7c/0xe8
 kmalloc_order+0x1c/0x88
 __kmalloc+0x25c/0x298
 ffs_epfile_io.isra.0+0x20c/0x7d0
 ffs_epfile_read_iter+0xa8/0x188
 new_sync_read+0xe4/0x170
 __vfs_read+0x2c/0x40
 vfs_read+0xc8/0x1a0
 ksys_read+0x68/0xf0
 __arm64_sys_read+0x18/0x20
 el0_svc_common.constprop.0+0x68/0x160
 el0_svc_handler+0x20/0x80
 el0_svc+0x8/0xc
Mem-Info:
active_anon:2856 inactive_anon:5269 isolated_anon:12
 active_file:5238 inactive_file:18803 isolated_file:0
 unevictable:0 dirty:22 writeback:416 unstable:0
 slab_reclaimable:4073 slab_unreclaimable:3408
 mapped:727 shmem:7393 pagetables:37 bounce:0
 free:4104 free_pcp:118 free_cma:0
Node 0 active_anon:11436kB inactive_anon:21076kB active_file:20988kB inactive_file:75216kB unevictable:0kB isolated(ano
Node 0 DMA32 free:16820kB min:1808kB low:2260kB high:2712kB active_anon:11436kB inactive_anon:21076kB active_file:2098B
lowmem_reserve[]: 0 0 0
Node 0 DMA32: 508*4kB (UME) 242*8kB (UME) 730*16kB (UM) 21*32kB (UME) 5*64kB (UME) 2*128kB (M) 0*256kB 0*512kB 0*1024kB
Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=1048576kB
Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=32768kB
Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=2048kB
Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=64kB
31455 total pagecache pages
0 pages in swap cache
Swap cache stats: add 0, delete 0, find 0/0
Free swap  = 0kB
Total swap = 0kB
65536 pages RAM
0 pages HighMem/MovableOnly
10766 pages reserved
0 pages cma reserved
0 pages hwpoisoned

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2020-02-28 11:15:59 +08:00
Peter Chen 1e0b2f7717
LF-705-1 usb: chipidea: udc: delete the redundancy code
Delete the redundancy code

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2020-02-16 21:01:30 +08:00
Peter Chen 55276da7e4 MLK-20343 usb: chipidea: udc: using structure ci_hdrc device for runtime PM
At current code, it doesn't maintain ci->gadget.dev's runtime PM
status well. Eg, after system resume, call pm_runtime_put_sync for
ci->dev will cause ci->dev's runtime suspend is called if its
power.usage is 0 even the power.usage is 1 for its child ci->gadget.dev.
at that time. It causes the oops this ticket describes that visiting
clock without AHB clock.

To fix this issue, we use ci_hdrc device instead of ci->gadget.dev
for runtime PM APIs at udc driver, in the way, we handle runtime
PM APIs for single device structure.

Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2019-11-25 15:56:56 +08:00
Peter Chen b90bd6962c MLK-19850-4 usb: chipidea: udc: using USB PHY charger framework for detection
Some platforms (eg, imx6/imx7ulp/imx8qm) which implements charger
detection at USB PHY driver can use framework directly. Other
platforms (eg, imx7d/imx845) which do not implement charger detection
at their USB PHY driver, just assign the charger detection results
for usb_phy structure.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2019-11-25 15:56:54 +08:00
Peter Chen ae54db9905 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>
2019-11-25 15:56:48 +08:00
Li Jun 43e724eb4e 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 fd49596eceeb4e61267f35fb74bf0c04056f2ed7)
2019-11-25 15:56:47 +08:00
Peter Chen 76d927518e MLK-12247 usb: chipidea: udc: disconnect host if system enters suspend
It is better we disconnect (pulldown dp) host when the system enters
suspend if the host did not suspend bus beforehand, it can avoid
unnecessary udc suspend irq during usb enters suspend. This unexpected
suspend irq occurs due to the udc still pulls up dp, but the host
suspends bus due to it finds the device has disconnected. The device
turns off high speed terminal will be considered a disconnection event
from the host.

It also fixes the bug ENGR00325724 describes.

Signed-off-by: Peter Chen <peter.chen@freescale.com>
(cherry picked from commit 9d9ddd142cdbfb4bcbaae161a452596668441b1a)
2019-11-25 15:56:45 +08:00
Li Jun 731e345e6f MLK-10132-3 usb: chipidea: udc: do not enter low power mode if vbus on
This patch is to prevent usb entering low power mode if vbus is on even gadget
driver is not binded, by holding the PM count of ci->dev.
So, there are 3 pm usage_count status:
- ci->dev: 1 ci->gadget.dev: 1
  Device mode with gadget driver binded and vbus on.
- ci->dev: 1 ci->gadget.dev: 0
  USB vbus on but gadget driver not binded.
- ci->dev: 0 ci->gadget.dev: 1
  USB OTG FSM is in a_peripheral mode.
Above 2 device's pm usage_count hold by ci otg(ci->dev) and usb gadget
(ci->gadget.dev).

Signed-off-by: Li Jun <jun.li@freescale.com>
(cherry picked from commit 673c6bf1b3aa0b1b698569b9259712b0e765be32)
2019-11-25 15:56:38 +08:00
Li Jun ded9d896fa MLK-9831-1 usb: chipidea: udc: refine ci_udc_start
Use ci_hdrc_gadget_connect() API directly if vbus is on.

Acked-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Li Jun <jun.li@freescale.com>
2019-11-25 15:56:37 +08:00
Li Jun 5af3e83f13 MLK-10102-5 usb: chipidea: udc: support resume udc from power lost
This patch implements the suspend and resume routine for udc resume
from power lost.

Acked-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Li Jun <b47624@freescale.com>
(cherry picked from commit a1389afb0c70d4024e07ff9634f10eba559af374)
(cherry picked from commit 733d0547c2cc90299b35b1b0d34073838ffcf6d9)
(cherry picked from commit 458b611c606a428af38952b33dcd088d1d84b39e)
2019-11-25 15:56:32 +08:00
Li Jun 5037438220 MLK-10085-5 usb: chipidea: Add usb charger detect notify
- Change .notify's return value from void to int, update msm notify_event
  return value accordingly.
- Add CI_HDRC_CONTROLLER_VBUS_EVENT and
  CI_HDRC_CONTROLLER_CHARGER_POST_EVENT to finish the USB charger
  detection flow.

Signed-off-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Li Jun <jun.li@freescale.com>
(cherry picked from commit 681ca18061e334beb8a907d05e4405014f47dc07)
2019-11-25 15:56:29 +08:00
Greg Kroah-Hartman 7a81146204 Merge 5.3-rc7 into usb-next
We need the usb fixes in here for testing

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-02 19:31:18 +02:00
Peter Chen cbe85c88ce usb: chipidea: udc: don't do hardware access if gadget has stopped
After _gadget_stop_activity is executed, we can consider the hardware
operation for gadget has finished, and the udc can be stopped and enter
low power mode. So, any later hardware operations (from usb_ep_ops APIs
or usb_gadget_ops APIs) should be considered invalid, any deinitializatons
has been covered at _gadget_stop_activity.

I meet this problem when I plug out usb cable from PC using mass_storage
gadget, my callstack like: vbus interrupt->.vbus_session->
composite_disconnect ->pm_runtime_put_sync(&_gadget->dev),
the composite_disconnect will call fsg_disable, but fsg_disable calls
usb_ep_disable using async way, there are register accesses for
usb_ep_disable. So sometimes, I get system hang due to visit register
without clock, sometimes not.

The Linux Kernel USB maintainer Alan Stern suggests this kinds of solution.
See: http://marc.info/?l=linux-usb&m=138541769810983&w=2.

Cc: <stable@vger.kernel.org> #v4.9+
Signed-off-by: Peter Chen <peter.chen@nxp.com>
Link: https://lore.kernel.org/r/20190820020503.27080-2-peter.chen@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-08-21 09:45:49 -07:00
Colin Ian King ed7fe55157 usb: chipidea: udc: remove redundant assignment to variable retval
The variable retval is being initialized with a value that is never
read and it is being updated later with a new value. The
initialization is redundant and can be removed.  Also remove a blank
line.

Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Link: https://lore.kernel.org/r/20190704150341.759-1-colin.king@canonical.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-07-25 11:10:55 +02:00
Peter Chen c19dffc0a9 usb: chipidea: udc: workaround for endpoint conflict issue
An endpoint conflict occurs when the USB is working in device mode
during an isochronous communication. When the endpointA IN direction
is an isochronous IN endpoint, and the host sends an IN token to
endpointA on another device, then the OUT transaction may be missed
regardless the OUT endpoint number. Generally, this occurs when the
device is connected to the host through a hub and other devices are
connected to the same hub.

The affected OUT endpoint can be either control, bulk, isochronous, or
an interrupt endpoint. After the OUT endpoint is primed, if an IN token
to the same endpoint number on another device is received, then the OUT
endpoint may be unprimed (cannot be detected by software), which causes
this endpoint to no longer respond to the host OUT token, and thus, no
corresponding interrupt occurs.

There is no good workaround for this issue, the only thing the software
could do is numbering isochronous IN from the highest endpoint since we
have observed most of device number endpoint from the lowest.

Cc: <stable@vger.kernel.org> #v3.14+
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Cc: Jun Li <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-06-17 15:08:33 +02:00
Loic Poulain 16caf1fa37 usb: chipidea: Add dynamic pinctrl selection
Some hardware implementations require to configure pins differently
according to the USB role (host/device), this can be an update of the
pins routing or a simple GPIO value change.

This patch introduces new optional "host" and "device" pinctrls.
If these pinctrls are defined by the device, they are respectively
selected on host/device role start.

If a default pinctrl exist, it is restored on host/device role stop.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2018-09-20 17:04:21 +08:00
Greg Kroah-Hartman 51b751f112 USB: chipidea: 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: Thierry Reding <thierry.reding@gmail.com>
Cc: Jonathan Hunter <jonathanh@nvidia.com>
Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-07 15:45:01 +01:00
Greg Kroah-Hartman 5fd54ace47 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>
2017-11-04 11:48:02 +01:00
Li Jun fc5b920c3b usb: chipidea: do charger detection in vbus session
In case the usb phy has the capability to detect usb charger type,
do it when vbus is on.

Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2017-09-21 11:15:56 +08:00
Dmitry Osipenko 581821ae7f usb: chipidea: udc: Support SKB alignment quirk
NVIDIA Tegra20 UDC can't cope with unaligned DMA and require a USB gadget
quirk that avoids SKB buffer alignment to be set in order to make Ethernet
Gadget working. Later Tegra generations do not require that quirk. Let's
add a new platform data flag that allows to enable USB gadget quirk for
platforms that require it.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2017-08-24 17:40:42 +08:00
Gustavo A. R. Silva 734c58aefc usb: chipidea: udc: compress return logic into line
Simplify return logic to avoid unnecessary variable assignment.

This issue was detected using Coccinelle and the following
semantic patch:

@@
local idexpression ret;
expression e;
@@

-ret =
+return
     e;
-return ret;

Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2017-07-19 09:49:11 +08:00
Jisheng Zhang aa1f058d7d usb: chipidea: udc: fix NULL pointer dereference if udc_start failed
Fix below NULL pointer dereference. we set ci->roles[CI_ROLE_GADGET]
too early in ci_hdrc_gadget_init(), if udc_start() fails due to some
reason, the ci->roles[CI_ROLE_GADGET] check in  ci_hdrc_gadget_destroy
can't protect us.

We fix this issue by only setting ci->roles[CI_ROLE_GADGET] if
udc_start() succeed.

[    1.398550] Unable to handle kernel NULL pointer dereference at
virtual address 00000000
...
[    1.448600] PC is at dma_pool_free+0xb8/0xf0
[    1.453012] LR is at dma_pool_free+0x28/0xf0
[    2.113369] [<ffffff80081817d8>] dma_pool_free+0xb8/0xf0
[    2.118857] [<ffffff800841209c>] destroy_eps+0x4c/0x68
[    2.124165] [<ffffff8008413770>] ci_hdrc_gadget_destroy+0x28/0x50
[    2.130461] [<ffffff800840fa30>] ci_hdrc_probe+0x588/0x7e8
[    2.136129] [<ffffff8008380fb8>] platform_drv_probe+0x50/0xb8
[    2.142066] [<ffffff800837f494>] driver_probe_device+0x1fc/0x2a8
[    2.148270] [<ffffff800837f68c>] __device_attach_driver+0x9c/0xf8
[    2.154563] [<ffffff800837d570>] bus_for_each_drv+0x58/0x98
[    2.160317] [<ffffff800837f174>] __device_attach+0xc4/0x138
[    2.166072] [<ffffff800837f738>] device_initial_probe+0x10/0x18
[    2.172185] [<ffffff800837e58c>] bus_probe_device+0x94/0xa0
[    2.177940] [<ffffff800837c560>] device_add+0x3f0/0x560
[    2.183337] [<ffffff8008380d20>] platform_device_add+0x180/0x240
[    2.189541] [<ffffff800840f0e8>] ci_hdrc_add_device+0x440/0x4f8
[    2.195654] [<ffffff8008414194>] ci_hdrc_usb2_probe+0x13c/0x2d8
[    2.201769] [<ffffff8008380fb8>] platform_drv_probe+0x50/0xb8
[    2.207705] [<ffffff800837f494>] driver_probe_device+0x1fc/0x2a8
[    2.213910] [<ffffff800837f5ec>] __driver_attach+0xac/0xb0
[    2.219575] [<ffffff800837d4b0>] bus_for_each_dev+0x60/0xa0
[    2.225329] [<ffffff800837ec80>] driver_attach+0x20/0x28
[    2.230816] [<ffffff800837e880>] bus_add_driver+0x1d0/0x238
[    2.236571] [<ffffff800837fdb0>] driver_register+0x60/0xf8
[    2.242237] [<ffffff8008380ef4>] __platform_driver_register+0x44/0x50
[    2.248891] [<ffffff80086fd440>] ci_hdrc_usb2_driver_init+0x18/0x20
[    2.255365] [<ffffff8008082950>] do_one_initcall+0x38/0x128
[    2.261121] [<ffffff80086e0d00>] kernel_init_freeable+0x1ac/0x250
[    2.267414] [<ffffff800852f0b8>] kernel_init+0x10/0x100
[    2.272810] [<ffffff8008082680>] ret_from_fork+0x10/0x50

Cc: stable <stable@vger.kernel.org>
Fixes: 3f124d233e ("usb: chipidea: add role init and destroy APIs")
Signed-off-by: Jisheng Zhang <jszhang@marvell.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2017-05-18 09:07:14 +08:00
Greg Kroah-Hartman ac9d947683 Two changes for this v4.12-rc1:
- Add sysfs entry for role switch
 - Update gadget state after gadget back from suspend
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQEcBAABAgAGBQJY9XecAAoJEEhZKYFQ1nG7PuQH+wR+qFiaswoJA3q+2sdqQDdD
 vN1FLT93o3ObgnmYwbZZDxdGeB6e+AJ/K8tQCOVqm8AnaNOzDwCYJoBTa5nPaS5k
 c+E4JlciG2NJG1s+eGVhZUPTQD3qS47vkgHymgtlTbQPDJDZy7k5nu7H1GSI7mvM
 7AH4uavzMIqsZcQTAln6BvIr2FQHh996LnUHDvYSZ6Y+8cws9IPMbSIiao3s3SiZ
 fULYJbVfDOd0LuxHOn7AdKrmlDJ/Gi2vmR4xQLlwvXEYk5/NUcSc1Yo5lVZcDUBR
 MzX4bLvhLi4SNLXLJhfqYjXcPXddXxawL/TRGDmT0B/1N8CCtBWJkNpIgx9q6dk=
 =opDd
 -----END PGP SIGNATURE-----

Merge tag 'usb-ci-v4.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb into usb-next

Peter writes:

Two changes for this v4.12-rc1:
- Add sysfs entry for role switch
- Update gadget state after gadget back from suspend
2017-04-18 16:52:20 +02:00
Peter Chen a932a8041f usb: chipidea: core: add sysfs group
Sometimes, the user needs to adjust some properties for controllers, eg
the role for controller, we add sysfs group for them.

The attribute 'role' is used to switch host/gadget role dynamically, the
uewr can read the current role, and write the other role compare to
current one to finish the switch.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
2017-04-14 09:26:37 +08:00
Arnd Bergmann aeb78cda51 usb: chipidea: use bus->sysdev for DMA configuration
Set the dma for chipidea from sysdev. This is inherited from its
parent node. Also, do not set dma mask for child as it is not required
now.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sriram Dash <sriram.dash@nxp.com>
Acked-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-03-23 08:20:21 +01:00
Li Jun 4f4555cfe7 usb: chipidea: udc: update gadget state after bus resume
Gadget state is set to be suspended when bus suspened, but not updated
after resume, this patch saves the gadget state before suspend and
restores it after resume.

Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2017-03-15 11:30:43 +08:00
Stephen Boyd afff6067b3 usb: chipidea: Drop lock across event_notify during gadget stop
The CI_HDRC_CONTROLLER_STOPPED_EVENT may want to call sleeping
APIs similar to how _gadget_stop_activity() may. Let's drop the
lock across the event so that glue drivers can make sleeping
calls.

Cc: Peter Chen <peter.chen@nxp.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2017-01-20 15:27:43 +08:00
Stephen Boyd 732a4af85e usb: chipidea: Remove locking in ci_udc_start()
We don't call hw_device_reset() with the ci->lock held, so it
doesn't seem like this lock here is protecting anything. Let's
just remove it. This allows us to call sleeping functions like
phy_init() from within the CI_HDRC_CONTROLLER_RESET_EVENT hook.

Acked-by: Peter Chen <peter.chen@nxp.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2017-01-20 11:25:10 +08:00
Greg Kroah-Hartman 9dd649c639 - Adding ULPI PHY support for imx53
- Properly mark little endian descriptors for udc
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQEcBAABAgAGBQJYO4X5AAoJEEhZKYFQ1nG78yYH/A8GJ6a3pBwvgF3XUhZusp75
 w1yg7TnP4aPXDFdS2dpS0buFrBji/0MxTZm3aKNKIHL2jF6ZRW5TvhapA9xv7ezY
 BhJOMXMUQAQSG/hnnu8QBJcrd0de3+EUhK6jYKInhvtNQUWl1jW073VAudlp2u4L
 lVeHg49+u/10KlZ1Y6yipOH/KzfrOM1oGYBwyl7KMA48R2EASJ0FATcwUM/tRUX3
 n6suCg/Z0VVFRdeYkiJdgnjxIbI+QR6TPMV+MWT1O32EniWm3pQT4G3WODooVqO9
 oLc+4xgMoPkoiN5XwkYRNZ3wqhDp7xk2v10XJ7zTP1Xrqt2YFBk8K+Ls2/eQmGU=
 =uOYb
 -----END PGP SIGNATURE-----

Merge tag 'usb-ci-v4.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb into usb-next

Peter writes:

- Adding ULPI PHY support for imx53
- Properly mark little endian descriptors for udc
2016-11-28 08:47:56 +01:00
Greg Kroah-Hartman 0edbf9e552 Merge 4.9-rc7 into usb-next
We want the USB fixes in here as well.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-11-28 08:34:10 +01:00
Peter Chen a5d906bb26 usb: chipidea: move the lock initialization to core file
This can fix below dump when the lock is accessed at host
mode due to it is not initialized.

[   46.119638] INFO: trying to register non-static key.
[   46.124643] the code is fine but needs lockdep annotation.
[   46.130144] turning off the locking correctness validator.
[   46.135659] CPU: 0 PID: 690 Comm: cat Not tainted 4.9.0-rc3-00079-g4b75f1d #1210
[   46.143075] Hardware name: Freescale i.MX6 SoloX (Device Tree)
[   46.148923] Backtrace:
[   46.151448] [<c010c460>] (dump_backtrace) from [<c010c658>] (show_stack+0x18/0x1c)
[   46.159038]  r7:edf52000
[   46.161412]  r6:60000193
[   46.163967]  r5:00000000
[   46.165035]  r4:c0e25c2c

[   46.169109] [<c010c640>] (show_stack) from [<c03f58a4>] (dump_stack+0xb4/0xe8)
[   46.176362] [<c03f57f0>] (dump_stack) from [<c016d690>] (register_lock_class+0x4fc/0x56c)
[   46.184554]  r10:c0e25d24
[   46.187014]  r9:edf53e70
[   46.189569]  r8:c1642444
[   46.190637]  r7:ee9da024
[   46.193191]  r6:00000000
[   46.194258]  r5:00000000
[   46.196812]  r4:00000000
[   46.199185]  r3:00000001

[   46.203259] [<c016d194>] (register_lock_class) from [<c0171294>] (__lock_acquire+0x80/0x10f0)
[   46.211797]  r10:c0e25d24
[   46.214257]  r9:edf53e70
[   46.216813]  r8:ee9da024
[   46.217880]  r7:c1642444
[   46.220435]  r6:edcd1800
[   46.221502]  r5:60000193
[   46.224057]  r4:00000000

[   46.227953] [<c0171214>] (__lock_acquire) from [<c01726c0>] (lock_acquire+0x74/0x94)
[   46.235710]  r10:00000001
[   46.238169]  r9:edf53e70
[   46.240723]  r8:edf53f80
[   46.241790]  r7:00000001
[   46.244344]  r6:00000001
[   46.245412]  r5:60000193
[   46.247966]  r4:00000000

[   46.251866] [<c017264c>] (lock_acquire) from [<c096c8fc>] (_raw_spin_lock_irqsave+0x40/0x54)
[   46.260319]  r7:ee1c6a00
[   46.262691]  r6:c062a570
[   46.265247]  r5:20000113
[   46.266314]  r4:ee9da014

[   46.270393] [<c096c8bc>] (_raw_spin_lock_irqsave) from [<c062a570>] (ci_port_test_show+0x2c/0x70)
[   46.279280]  r6:eebd2000
[   46.281652]  r5:ee9da010
[   46.284207]  r4:ee9da014

[   46.286810] [<c062a544>] (ci_port_test_show) from [<c0248d04>] (seq_read+0x1ac/0x4f8)
[   46.294655]  r9:edf53e70
[   46.297028]  r8:edf53f80
[   46.299583]  r7:ee1c6a00
[   46.300650]  r6:00000001
[   46.303205]  r5:00000000
[   46.304273]  r4:eebd2000
[   46.306850] [<c0248b58>] (seq_read) from [<c039e864>] (full_proxy_read+0x54/0x6c)
[   46.314348]  r10:00000000
[   46.316808]  r9:c0a6ad30
[   46.319363]  r8:edf53f80
[   46.320430]  r7:00020000
[   46.322986]  r6:b6de3000
[   46.324053]  r5:ee1c6a00
[   46.326607]  r4:c0248b58

[   46.330505] [<c039e810>] (full_proxy_read) from [<c021ec98>] (__vfs_read+0x34/0x118)
[   46.338262]  r9:edf52000
[   46.340635]  r8:c0107fc4
[   46.343190]  r7:00020000
[   46.344257]  r6:edf53f80
[   46.346812]  r5:c039e810
[   46.347879]  r4:ee1c6a00
[   46.350447] [<c021ec64>] (__vfs_read) from [<c021fbd0>] (vfs_read+0x8c/0x11c)
[   46.357597]  r9:edf52000
[   46.359969]  r8:c0107fc4
[   46.362524]  r7:edf53f80
[   46.363592]  r6:b6de3000
[   46.366147]  r5:ee1c6a00
[   46.367214]  r4:00020000
[   46.369782] [<c021fb44>] (vfs_read) from [<c0220a4c>] (SyS_read+0x4c/0xa8)
[   46.376672]  r8:c0107fc4
[   46.379045]  r7:00020000
[   46.381600]  r6:b6de3000
[   46.382667]  r5:ee1c6a00
[   46.385222]  r4:ee1c6a00

[   46.387817] [<c0220a00>] (SyS_read) from [<c0107e20>] (ret_fast_syscall+0x0/0x1c)
[   46.395314]  r7:00000003
[   46.397687]  r6:b6de3000
[   46.400243]  r5:00020000
[   46.401310]  r4:00020000

Cc: <stable@vger.kernel.org>
Fixes: 26c696c678 ("USB: Chipidea: rename struct
	       	ci13xxx variables from udc to ci")
Signed-off-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-11-15 19:25:25 +01:00
Stephen Boyd 34445fb433 usb: chipidea: Properly mark little endian descriptors
The DMA descriptors are little endian, and we do a pretty good
job of handling them with the proper le32_to_cpu() markings, but
we don't actually mark them as __le32. This means checkers like
sparse can't easily find new bugs. Let's mark the members of
structures properly and fix the few places where we're missing
conversions.

Cc: Peter Chen <peter.chen@nxp.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2016-11-14 10:03:40 +08:00
Felipe Balbi 63b9e901e4 usb: chipidea: udc: remove unnecessary & operation
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

Cc: Peter Chen <Peter.Chen@nxp.com>
Cc: <linux-usb@vger.kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:23 +02:00
Felipe Balbi a98e25e71d usb: chipidea: udc: make use of new usb_endpoint_maxp_mult()
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

Acked-by: Peter Chen <Peter.Chen@nxp.com>
Cc: <linux-usb@vger.kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
2016-11-03 10:38:12 +02:00
Fabio Estevam e74e837248 usb: chipidea: udc: Use the preferred form for passing a size of a struct
According to Documentation/CodingStyle:

"The preferred form for passing a size of a struct is the following:

	p = kmalloc(sizeof(*p), ...);
"
, so do as suggested to improve readability.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2016-09-14 10:58:13 +08:00
Fabio Estevam 58001effe1 usb: chipidea: udc: Fit into a single line
No need to split the dma_pool_zalloc() line into two as it can
perfectly fit into a single line.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2016-09-14 10:58:13 +08:00
Fabio Estevam 382c1b38d8 usb: chipidea: udc: Use dma_pool_zalloc()
We can make the code simpler by using dma_pool_zalloc() instead
of calling dma_pool_alloc() and then a memset().

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2016-09-14 10:58:13 +08:00
Stefan Wahren c6ee9f2345 usb: chipidea: udc: Use direction flags consequently
This driver make assumptions about the value of the direction flags.
So better use them in comparisons to improve the readability.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2016-09-14 10:58:13 +08:00
Stefan Wahren 8007eb4e18 usb: chipidea: udc: Don't flush endpoint fifo twice
The endpoint fifo is already flushed in _ep_nuke so there
is no need to flush it twice.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2016-09-14 10:58:13 +08:00
Stefan Wahren 66b76dbe37 usb: chipidea: udc: move write barrier into hw_ep_prime
Since there should be a write barrier before every call of
hw_ep_prime we could move it into hw_ep_prime.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2016-09-14 10:58:13 +08:00
Clemens Gruber 6f3c4fb6d0 usb: chipidea: udc: fix NULL ptr dereference in isr_setup_status_phase
Problems with the signal integrity of the high speed USB data lines or
noise on reference ground lines can cause the i.MX6 USB controller to
violate USB specs and exhibit unexpected behavior.

It was observed that USBi_UI interrupts were triggered first and when
isr_setup_status_phase was called, ci->status was NULL, which lead to a
NULL pointer dereference kernel panic.

This patch fixes the kernel panic, emits a warning once and returns
-EPIPE to halt the device and let the host get stalled.
It also adds a comment to point people, who are experiencing this issue,
to their USB hardware design.

Cc: <stable@vger.kernel.org> #4.1+
Signed-off-by: Clemens Gruber <clemens.gruber@pqgruber.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2016-09-09 17:19:57 +08:00
Li Jun c4e9417498 usb: chipidea: udc: don't touch DP when controller is in host mode
When the controller is configured to be dual role and it's in host mode,
if bind udc and gadgt driver, those gadget operations will do gadget
disconnect and finally pull down DP line, which will break host function.

Cc: <stable@vger.kernel.org> # 4.1+
Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2016-08-19 09:27:07 +08:00
Li Jun d6da40af0e usb: chipidea: udc: bypass otg status selector handling to gadget driver
Since gadget driver will handle this request, so controller driver bypass
it.

Acked-by: Peter Chen <peter.chen@freescale.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
2016-03-04 15:14:36 +02:00
Li Jun 34d5732dd6 usb: chipidea: udc: remove unused value assignment
retval is assigned to be -EOVERFLOW but is overwritten later before
it's used, remove this unused value assignment.

Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Peter Chen <peter.chen@nxp.com>
2016-02-29 13:37:50 +08:00