i.MX8MQ USB support
Subsystems (10)
cover i.MX8MQ USB support
Everyone:
This series contains changes I made while working on adding USB support for ZII i.MX8MQ boards. There are several distinct parts in this series:
1. xHCI fixes, features and improvements
2. PHY driver deferral support
3. i.MX8MQ USB PHY driver
4. DWC3 USB support and related patches
5. USB251x USB hub and related patches
First four are neccessary for i.MX8MQ in general and last part is ZII specific only. Hopefully all patches are self explanatory.
Tested on ZII i.MX8MQ boards.
Feedback is welcome!
Thanks,
Andrey Smirnov
Andrey Smirnov (25):
usb: xhci-hcd: Tabify the file
usb: xhci-hcd: Do not zero out DMA coherent memory
usb: xhci-hcd: Cast ~XHCI_IRQS to u32
usb: xhci-hcd: Make sure to initialize xhci->rings_list
usb: xhci-hcd: Drop pointless bitwise or
usb: xhci-hcd: Add support for 64-byte context size
usb: xhci-hcd: Don't try to DMA sync if buffer is NULL
usb: xhci-hcd: Always wait for "Response Data" completion
usb: xhci-hcd: Convert xhci_submit_normal() to use dma_map_single()
usb: xhci-hcd: Convert xhci_submit_control() to use dma_map_single()
usb: xhci-hcd: Simplify TRB initialization code
usb: xhci-hcd: Drop 'dma' field from struct xhci_hcd
usb: xhci-hcd: Check usb_pipein(pipe) only once in
xhci_submit_normal()
usb: xhci-hcd: Initialize TRT flag for xHCI >= 1.0
usb: xhci-hcd: Simplify route string building loop
usb: xhci-hcd: Make use of lo_hi_readq/writeq()
phy: core: Assume EPROBE_DEFER in of_phy_provider_lookup()
phy: Port i.MX8MQ USB PHY driver from Linux
clk: Drop separate definitions of clk_put()
include/usb: Import USB_SPEED_SUPER_PLUS from Linux
clk: Import a subset of clk_bulk API from Linux
usb: Import DWC3 USB controller driver from Linux
lib: Port basic Linux kernel NLS functions
usb: Port Microchip USB251x USB hub driver from Linux
usb: usb251xb: add usb data lane port swap feature
drivers/clk/Makefile | 3 +- drivers/clk/clk-bulk.c | 102 ++ drivers/clk/clkdev.c | 5 - drivers/phy/Kconfig | 2 + drivers/phy/Makefile | 1 + drivers/phy/freescale/Kconfig | 4 + drivers/phy/freescale/Makefile | 1 + drivers/phy/freescale/phy-fsl-imx8mq-usb.c | 130 ++ drivers/phy/phy-core.c | 4 +- drivers/usb/Kconfig | 4 + drivers/usb/Makefile | 2 + drivers/usb/dwc3/Kconfig | 22 + drivers/usb/dwc3/Makefile | 10 + drivers/usb/dwc3/core.c | 740 ++++++++++++ drivers/usb/dwc3/core.h | 1267 ++++++++++++++++++++ drivers/usb/dwc3/debug.h | 664 ++++++++++ drivers/usb/dwc3/host.c | 36 + drivers/usb/dwc3/io.h | 41 + drivers/usb/host/xhci-hcd.c | 549 +++++---- drivers/usb/host/xhci.h | 51 +- drivers/usb/misc/Kconfig | 14 + drivers/usb/misc/Makefile | 6 + drivers/usb/misc/usb251xb.c | 683 +++++++++++ include/linux/clk.h | 107 +- include/linux/nls.h | 40 + include/usb/ch9.h | 1 + lib/Kconfig | 3 + lib/Makefile | 1 + lib/nls_base.c | 131 ++ 29 files changed, 4377 insertions(+), 247 deletions(-) create mode 100644 drivers/clk/clk-bulk.c create mode 100644 drivers/phy/freescale/Kconfig create mode 100644 drivers/phy/freescale/Makefile create mode 100644 drivers/phy/freescale/phy-fsl-imx8mq-usb.c create mode 100644 drivers/usb/dwc3/Kconfig create mode 100644 drivers/usb/dwc3/Makefile create mode 100644 drivers/usb/dwc3/core.c create mode 100644 drivers/usb/dwc3/core.h create mode 100644 drivers/usb/dwc3/debug.h create mode 100644 drivers/usb/dwc3/host.c create mode 100644 drivers/usb/dwc3/io.h create mode 100644 drivers/usb/misc/Kconfig create mode 100644 drivers/usb/misc/Makefile create mode 100644 drivers/usb/misc/usb251xb.c create mode 100644 include/linux/nls.h create mode 100644 lib/nls_base.c
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/25 usb: xhci-hcd: Tabify the file
Replace occasional all-whiltespace indentation with tabs for consistency.
--- drivers/usb/host/xhci-hcd.c | 136 ++++++++++++++++++------------------ 1 file changed, 68 insertions(+), 68 deletions(-)
drivers/usb/host/xhci-hcd.c +68 -68
@@ -29,10 +29,10 @@static int xhci_ring_is_last_trb (struct xhci_ring *ring,union xhci_trb *trb) { -if (ring->type ==TYPE_EVENT ) -return trb == &ring->trbs[NUM_EVENT_TRBS ]; -else -return TRB_TYPE_LINK (le32_to_cpu (trb->link.control)); +if (ring->type ==TYPE_EVENT ) +return trb == &ring->trbs[NUM_EVENT_TRBS ]; +else +return TRB_TYPE_LINK (le32_to_cpu (trb->link.control)); }static int xhci_ring_increment (struct xhci_ring *ring,bool enqueue)
@@ -41,7 +41,7 @@ static int xhci_ring_increment(struct xhci_ring *ring, bool enqueue) (*queue)++; -if (!xhci_ring_is_last_trb (ring, *queue)) +if (!xhci_ring_is_last_trb (ring, *queue))return 0 ;if (ring->type ==TYPE_EVENT ) {
@@ -139,15 +139,15 @@ static unsigned int xhci_get_endpoint_index(u8 epaddress, u8 epattributes) {u8 epnum = epaddress &USB_ENDPOINT_NUMBER_MASK ;u8 xfer = epattributes &USB_ENDPOINT_XFERTYPE_MASK ; -unsigned int index; +unsigned int index; -if (xfer ==USB_ENDPOINT_XFER_CONTROL ) - index = (unsigned int )(epnum *2 ); -else - index = (unsigned int )(epnum *2 ) + - ((epaddress &USB_DIR_IN ) ?1 :0 ) -1 ; +if (xfer ==USB_ENDPOINT_XFER_CONTROL ) + index = (unsigned int )(epnum *2 ); +else + index = (unsigned int )(epnum *2 ) + + ((epaddress &USB_DIR_IN ) ?1 :0 ) -1 ; -return index; +return index; }static u8 xhci_get_endpoint_type (u8 epaddress,u8 epattributes)
@@ -341,15 +341,15 @@ int xhci_issue_command(struct xhci_hcd *xhci, union xhci_trb *trb)static void xhci_set_event_dequeue (struct xhci_hcd *xhci) { -u64 reg64; +u64 reg64; - reg64 =xhci_read_64 (&xhci->ir_set->erst_dequeue); - reg64 &=ERST_PTR_MASK ; -/* + reg64 =xhci_read_64 (&xhci->ir_set->erst_dequeue); + reg64 &=ERST_PTR_MASK ; +/* * Don't clear the EHB bit (which is RW1C) because -* there might be more events to service. -*/ - reg64 &= ~ERST_EHB ; +* there might be more events to service. +*/ + reg64 &= ~ERST_EHB ; reg64 |= (dma_addr_t )xhci->event_ring.dequeue & ~(dma_addr_t )ERST_PTR_MASK ;
@@ -489,16 +489,16 @@ static void xhci_virtdev_zero_in_ctx(struct xhci_virtual_device *vdev) {int i; -/* When a device's add flag and drop flag are zero, any subsequent -* configure endpoint command will leave that endpoint's state -* untouched. Make sure we don't leave any old state in the input -* endpoint contexts. -*/ - vdev->in_ctx->icc.drop_flags =0 ; - vdev->in_ctx->icc.add_flags =0 ; - vdev->in_ctx->slot.dev_info &=cpu_to_le32 (~LAST_CTX_MASK ); -/* Endpoint 0 is always valid */ - vdev->in_ctx->slot.dev_info |=cpu_to_le32 (LAST_CTX (1 )); +/* When a device's add flag and drop flag are zero, any subsequent +* configure endpoint command will leave that endpoint's state +* untouched. Make sure we don't leave any old state in the input +* endpoint contexts. +*/ + vdev->in_ctx->icc.drop_flags =0 ; + vdev->in_ctx->icc.add_flags =0 ; + vdev->in_ctx->slot.dev_info &=cpu_to_le32 (~LAST_CTX_MASK ); +/* Endpoint 0 is always valid */ + vdev->in_ctx->slot.dev_info |=cpu_to_le32 (LAST_CTX (1 ));for (i =1 ; i <31 ; i++) { vdev->in_ctx->ep[i].ep_info =0 ; vdev->in_ctx->ep[i].ep_info2 =0 ;
@@ -522,7 +522,7 @@ static int xhci_virtdev_disable_slot(struct xhci_virtual_device *vdev) ret =xhci_wait_for_event (xhci,TRB_COMPLETION , &trb);xhci_print_trb (xhci, &trb,"Response DisableSlot" ); -/* Clear Device Context Base Address Array */ +/* Clear Device Context Base Address Array */ xhci->dcbaa[vdev->slot_id] =0 ;return ret;
@@ -565,7 +565,7 @@ int xhci_virtdev_reset(struct xhci_virtual_device *vdev)/* If device is not setup, there is no point in resetting it */ if (GET_SLOT_STATE (le32_to_cpu (vdev->out_ctx->slot.dev_state)) ==SLOT_STATE_DISABLED ) -return 0 ; +return 0 ;memset (&trb,0 ,sizeof (union xhci_trb )); trb.event_cmd.flags = TRB_TYPE(TRB_RESET_DEV) |
@@ -575,26 +575,26 @@ int xhci_virtdev_reset(struct xhci_virtual_device *vdev) ret =xhci_wait_for_event (xhci,TRB_COMPLETION , &trb);xhci_print_trb (xhci, &trb,"Response Reset" ); -/* +/* * The Reset Device command can't fail, according to the 0.95/0.96 spec, -* unless we tried to reset a slot ID that wasn't enabled, -* or the device wasn't in the addressed or configured state. -*/ -switch (GET_COMP_CODE (trb.event_cmd.status)) { -case COMP_CMD_ABORT : -case COMP_CMD_STOP : -dev_warn (xhci->dev,"Timeout waiting for reset device command\n" ); - ret = -ETIMEDOUT ; +* unless we tried to reset a slot ID that wasn't enabled, +* or the device wasn't in the addressed or configured state. +*/ +switch (GET_COMP_CODE (trb.event_cmd.status)) { +case COMP_CMD_ABORT : +case COMP_CMD_STOP : +dev_warn (xhci->dev,"Timeout waiting for reset device command\n" ); + ret = -ETIMEDOUT ; +break ; +case COMP_EBADSLT :/* 0.95 completion code for bad slot ID */ +case COMP_CTX_STATE :/* 0.96 completion code for same thing */ +/* Don't treat this as an error. May change my mind later. */ + ret =0 ; +case COMP_SUCCESS :break ; -case COMP_EBADSLT :/* 0.95 completion code for bad slot ID */ -case COMP_CTX_STATE :/* 0.96 completion code for same thing */ -/* Don't treat this as an error. May change my mind later. */ - ret =0 ; -case COMP_SUCCESS : -break ; -default : - ret = -EINVAL ; - } +default : + ret = -EINVAL ; + }return ret; }
@@ -651,14 +651,14 @@ static int xhci_virtdev_update_hub_device(struct xhci_virtual_device *vdev,if (xhci->hci_version <0x100 || vdev->udev->speed ==USB_SPEED_HIGH ) {u32 think_time = (hubchar &HUB_CHAR_TTTT ) >>5 ; - tt_info |=TT_THINK_TIME (think_time); + tt_info |=TT_THINK_TIME (think_time); } - } + } vdev->in_ctx->slot.dev_info =cpu_to_le32 (dev_info); vdev->in_ctx->slot.dev_info2 =cpu_to_le32 (dev_info2); vdev->in_ctx->slot.tt_info =cpu_to_le32 (tt_info); -/* Issue Configure Endpoint or Evaluate Context Command */ +/* Issue Configure Endpoint or Evaluate Context Command */ memset (&trb,0 ,sizeof (union xhci_trb ));xhci_write_64 ((dma_addr_t )vdev->in_ctx, &trb.event_cmd.cmd_trb); trb.event_cmd.flags =SLOT_ID_FOR_TRB (vdev->slot_id);
@@ -782,21 +782,21 @@ static int xhci_virtdev_configure(struct xhci_virtual_device *vdev, int config) last_ctx =fls (add_flags) -1 ; -/* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ +/* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ vdev->in_ctx->icc.add_flags =cpu_to_le32 (add_flags); - vdev->in_ctx->icc.add_flags |=cpu_to_le32 (SLOT_FLAG ); - vdev->in_ctx->icc.add_flags &=cpu_to_le32 (~EP0_FLAG ); - vdev->in_ctx->icc.drop_flags &=cpu_to_le32 (~(SLOT_FLAG |EP0_FLAG )); + vdev->in_ctx->icc.add_flags |=cpu_to_le32 (SLOT_FLAG ); + vdev->in_ctx->icc.add_flags &=cpu_to_le32 (~EP0_FLAG ); + vdev->in_ctx->icc.drop_flags &=cpu_to_le32 (~(SLOT_FLAG |EP0_FLAG ));/* Don't issue the command if there's no endpoints to update. */ -if (vdev->in_ctx->icc.add_flags ==cpu_to_le32 (SLOT_FLAG ) && - vdev->in_ctx->icc.drop_flags ==0 ) +if (vdev->in_ctx->icc.add_flags ==cpu_to_le32 (SLOT_FLAG ) && + vdev->in_ctx->icc.drop_flags ==0 )return 0 ; vdev->in_ctx->slot.dev_info &=cpu_to_le32 (~LAST_CTX_MASK ); vdev->in_ctx->slot.dev_info |=cpu_to_le32 (LAST_CTX (last_ctx)); -/* Issue Configure Endpoint Command */ +/* Issue Configure Endpoint Command */ memset (&trb,0 ,sizeof (union xhci_trb ));xhci_write_64 ((dma_addr_t )vdev->in_ctx, &trb.event_cmd.cmd_trb); trb.event_cmd.flags = TRB_TYPE(TRB_CONFIG_EP) |
@@ -816,7 +816,7 @@ static int xhci_virtdev_deconfigure(struct xhci_virtual_device *vdev)union xhci_trb trb;int ret; -/* Issue Deconfigure Endpoint Command */ +/* Issue Deconfigure Endpoint Command */ memset (&trb,0 ,sizeof (union xhci_trb ));xhci_write_64 ((dma_addr_t )vdev->in_ctx, &trb.event_cmd.cmd_trb); trb.event_cmd.flags = TRB_TYPE(TRB_CONFIG_EP) | TRB_DC |
@@ -912,7 +912,7 @@ static int xhci_virtdev_init(struct xhci_virtual_device *vdev) vdev->in_ctx->ep[0 ].deq =cpu_to_le64 ((dma_addr_t )vdev->ep[0 ]->enqueue | vdev->ep[0 ]->cycle_state); -/* 4.3.3 6+7) Initalize and Set Device Context Base Address Array */ +/* 4.3.3 6+7) Initalize and Set Device Context Base Address Array */ xhci->dcbaa[vdev->slot_id] =cpu_to_le64 ((dma_addr_t )vdev->out_ctx);return 0 ;
@@ -952,7 +952,7 @@ static int xhci_virtdev_setup(struct xhci_virtual_device *vdev, vdev->in_ctx->icc.add_flags =cpu_to_le32 (SLOT_FLAG |EP0_FLAG ); vdev->in_ctx->icc.drop_flags =0 ; -/* Issue Address Device Command */ +/* Issue Address Device Command */ memset (&trb,0 ,sizeof (union xhci_trb ));xhci_write_64 ((dma_addr_t )vdev->in_ctx, &trb.event_cmd.cmd_trb); trb.event_cmd.flags = TRB_TYPE(TRB_ADDR_DEV) |
@@ -970,12 +970,12 @@ static int xhci_virtdev_setup(struct xhci_virtual_device *vdev,static int xhci_virtdev_set_address (struct xhci_virtual_device *vdev) { -return xhci_virtdev_setup (vdev,SETUP_CONTEXT_ADDRESS ); +return xhci_virtdev_setup (vdev,SETUP_CONTEXT_ADDRESS ); }static int xhci_virtdev_enable (struct xhci_virtual_device *vdev) { -return xhci_virtdev_setup (vdev,SETUP_CONTEXT_ONLY ); +return xhci_virtdev_setup (vdev,SETUP_CONTEXT_ONLY ); }static int xhci_virtdev_attach (struct xhci_hcd *xhci,struct usb_device *udev)
@@ -1291,7 +1291,7 @@ static int xhci_reset(struct xhci_hcd *xhci)return ret; } -return 0 ; +return 0 ; }static int xhci_start (struct xhci_hcd *xhci)
@@ -1305,8 +1305,8 @@ static int xhci_start(struct xhci_hcd *xhci) ret =xhci_handshake (&xhci->op_regs->status,STS_HALT ,0 ,XHCI_MAX_HALT_USEC ); -if (ret) { -dev_err (xhci->dev,"failed to start\n" ); +if (ret) { +dev_err (xhci->dev,"failed to start\n" );return ret; }
@@ -1314,7 +1314,7 @@ static int xhci_start(struct xhci_hcd *xhci)for (i =0 ; i < xhci->num_usb_ports; i++)xhci_hub_port_power (xhci, i, false); -return 0 ; +return 0 ; }static int xhci_init (struct usb_host *host)
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/25 usb: xhci-hcd: Do not zero out DMA coherent memory
In reply to Andrey SmirnovMemory returned by dma_alloc_coherent() should already be zeroed out, so there's no need to do this explicitly.
--- drivers/usb/host/xhci-hcd.c | 2 -- 1 file changed, 2 deletions(-)
drivers/usb/host/xhci-hcd.c +0 -2
@@ -445,7 +445,6 @@ static struct xhci_virtual_device *xhci_alloc_virtdev(struct xhci_hcd *xhci, vdev->dma_size = sz_ictx + sz_dctx; p = vdev->dma =dma_alloc_coherent (vdev->dma_size,DMA_ADDRESS_BROKEN ); -memset (vdev->dma,0 , vdev->dma_size); vdev->out_ctx = p; p += sz_dctx; vdev->in_ctx = p; p += sz_ictx;
@@ -1225,7 +1224,6 @@ static void xhci_dma_alloc(struct xhci_hcd *xhci) xhci->dma_size += num_ep * sz_ep; p = xhci->dma =dma_alloc_coherent (xhci->dma_size,DMA_ADDRESS_BROKEN ); -memset (xhci->dma,0 , xhci->dma_size); xhci->sp = p; p += sz_sp; xhci->dcbaa = p; p += sz_dca;
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 02/25] usb: xhci-hcd: Do not zero out DMA coherent memory
I'm not sure dma_alloc_coherent() should return zeroed out memory.
I'm pretty sure it does not.
mips arch seems to memset it to 0, but not all arch do that.
Quoted 21 lines · Andrey Smirnov
Memory returned by
dma_alloc_coherent()should already be zeroed out, so there's no need to do this explicitly.Signed-off-by Andrey Smirnov <[email protected]>--- drivers/usb/host/xhci-hcd.c | 2 -- 1 file changed, 2 deletions(-)drivers/usb/host/xhci-hcd.c +0
-1@@ -445,7 +445,6 @@ static struct xhci_virtual_device *xhci_alloc_virtdev(struct xhci_hcd *xhci, vdev->dma_size = sz_ictx + sz_dctx; p = vdev->dma =dma_alloc_coherent (vdev->dma_size,DMA_ADDRESS_BROKEN ); -memset (vdev->dma,0 , vdev->dma_size); vdev->out_ctx = p; p += sz_dctx; vdev->in_ctx = p; p += sz_ictx;
drivers/usb/host/xhci-hcd.c static void xhci_dma_alloc(struct xhci_hcd *xhci) · line 1229
Quoted 7 lines
drivers/usb/host/xhci-hcd.c +0
-1@@ -1225,7 +1224,6 @@ static void xhci_dma_alloc(struct xhci_hcd *xhci) xhci->dma_size += num_ep * sz_ep; p = xhci->dma =dma_alloc_coherent (xhci->dma_size,DMA_ADDRESS_BROKEN ); -memset (xhci->dma,0 , xhci->dma_size); xhci->sp = p; p += sz_sp; xhci->dcbaa = p; p += sz_dca;
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 02/25] usb: xhci-hcd: Do not zero out DMA coherent memory
Quoted 7 lines · Yann Sionneau
I'm not sure
dma_alloc_coherent()should return zeroed out memory.I'm pretty sure it does not.
mips arch seems to memset it to 0, but not all arch do that.
It is definitely the semantics in latest kernel code, see e.g. here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.0-rc7&id=dfd32cad146e3624970eee9329e99d2c6ef751b3
As for Barebox, currently there are three architectures that select HAS_DMA to indicate that they implement said DMA functions: MIPS, ARM and ARM64. As you mentioned before MIPS already does the right thing and a series to do the same on ARM/ARM64 was recently merged into "next" as well, specifically this patch:
I think this should cover all of the bases as far as xHCI is concerned.
Having looked at it againg, the only two "non-zeroing" cases that I can see in the codebase are:
1. Nios II which, AFAICT, only uses DMA functions in drivers/net/altera_tse.c. Since it doesn't select HAS_DMA and is pretty self-contained, I don't think there's any reason to worry about leaving it as it is.
2. No MMU case on ARM/ARM64, I doubt there are many users of that combination, but it is definitely something that should be fixed. I'll submit a separate series for that.
Thanks,
Andrey Smirnov
Quoted 24 lines · Andrey Smirnov
Quoted 23 lines
Memory returned by
dma_alloc_coherent()should already be zeroed out, so there's no need to do this explicitly.Signed-off-by Andrey Smirnov <[email protected]>--- drivers/usb/host/xhci-hcd.c | 2 -- 1 file changed, 2 deletions(-)drivers/usb/host/xhci-hcd.c +0
-1@@ -445,7 +445,6 @@ static struct xhci_virtual_device *xhci_alloc_virtdev(struct xhci_hcd *xhci, vdev->dma_size = sz_ictx + sz_dctx; p = vdev->dma =dma_alloc_coherent (vdev->dma_size,DMA_ADDRESS_BROKEN ); -memset (vdev->dma,0 , vdev->dma_size); vdev->out_ctx = p; p += sz_dctx; vdev->in_ctx = p; p += sz_ictx;@@ -1225,7 +1224,6 @@ static void xhci_dma_alloc(struct xhci_hcd *xhci) xhci->dma_size += num_ep * sz_ep;
Quoted 5 lines
drivers/usb/host/xhci-hcd.c static void xhci_dma_alloc(struct xhci_hcd *xhci) · line 1229
Quoted 5 lines
drivers/usb/host/xhci-hcd.c +0
-1p = xhci->dma =dma_alloc_coherent (xhci->dma_size,DMA_ADDRESS_BROKEN ); -memset (xhci->dma,0 , xhci->dma_size); xhci->sp = p; p += sz_sp; xhci->dcbaa = p; p += sz_dca;
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 02/25] usb: xhci-hcd: Do not zero out DMA coherent memory
In reply to Yann SionneauQuoted 5 lines · Yann Sionneau
I'm not sure
dma_alloc_coherent()should return zeroed out memory.I'm pretty sure it does not.
mips arch seems to memset it to 0, but not all arch do that.
Christoph Hellwig had a patch series that zeroed memory for all archs on dma_alloc_coherent() and friends.
https://lkml.org/lkml/2018/12/14/103
barebox should do the same as I see it.
I recall the patch series is applied but I did not check.
Sam
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/25 usb: xhci-hcd: Cast ~XHCI_IRQS to u32
In reply to Andrey SmirnovCast ~XHCI_IRQS to u32 to avoid getting a warning on 64-bit builds.
--- drivers/usb/host/xhci-hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-hcd.c +1 -1
@@ -1259,7 +1259,7 @@ static void xhci_dma_alloc(struct xhci_hcd *xhci)static int xhci_halt (struct xhci_hcd *xhci) {u32 reg =readl (&xhci->op_regs->status); -u32 mask = ~XHCI_IRQS ; +u32 mask = (u32 )~XHCI_IRQS ;if (!(reg &STS_HALT )) mask &= ~CMD_RUN ;
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 4/25 usb: xhci-hcd: Make sure to initialize xhci->rings_list
In reply to Andrey SmirnovMake sure to initialize xhci->rings_list, otherwise any use of the driver will result in a crash.
--- drivers/usb/host/xhci-hcd.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/host/xhci-hcd.c +1 -0
@@ -1470,6 +1470,7 @@ int xhci_register(struct device_d *dev, struct xhci_data *data) xhci =xzalloc (sizeof (*xhci)); host = &xhci->host;INIT_LIST_HEAD (&xhci->vdev_list); +INIT_LIST_HEAD (&xhci->rings_list); xhci->dev = dev; xhci->cap_regs = data->regs; xhci->op_regs = (void __iomem *)xhci->cap_regs +
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 5/25 usb: xhci-hcd: Drop pointless bitwise or
In reply to Andrey SmirnovOn_hs_hub is a boolean, not a bitfiled, so usage of bitwise or is unnecessary. Replace it with a regular assignement operator.
--- drivers/usb/host/xhci-hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-hcd.c +1 -1
@@ -849,7 +849,7 @@ static int xhci_virtdev_init(struct xhci_virtual_device *vdev)if (top_dev->parent->descriptor->bDeviceClass ==USB_CLASS_HUB && top_dev->parent->speed !=USB_SPEED_LOW && top_dev->parent->speed !=USB_SPEED_FULL ) { - on_hs_hub |= true; + on_hs_hub = true;if (!hs_slot_id) {struct xhci_virtual_device *vhub =xhci_find_virtdev (xhci, top_dev->parent);
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 6/25 usb: xhci-hcd: Add support for 64-byte context size
In reply to Andrey SmirnovxHCI spec allows for various context to be either 32 or 64 bytes in size, so we can't rely on struct definitions to correctly reflect data layout. Port varios context accessors from Linux kernel and convert the rest of the code to use them in order to be able to support both context sizes.
--- drivers/usb/host/xhci-hcd.c | 233 +++++++++++++++++++++++++----------- drivers/usb/host/xhci.h | 36 ++++-- 2 files changed, 188 insertions(+), 81 deletions(-)
drivers/usb/host/xhci-hcd.c +165 -68
@@ -23,6 +23,39 @@#include "xhci.h" + +static struct xhci_input_control_ctx * +xhci_get_input_control_ctx (struct xhci_container_ctx *ctx) +{ +if (ctx->type !=XHCI_CTX_TYPE_INPUT ) +return NULL ; + +return (struct xhci_input_control_ctx *)ctx->bytes; +} + +static struct xhci_slot_ctx *xhci_get_slot_ctx (struct xhci_hcd *xhci, +struct xhci_container_ctx *ctx) +{ +if (ctx->type ==XHCI_CTX_TYPE_DEVICE ) +return (struct xhci_slot_ctx *)ctx->bytes; + +return (struct xhci_slot_ctx *) + (ctx->bytes +HCC_CTX_SIZE (xhci->hcc_params)); +} + +static struct xhci_ep_ctx *xhci_get_ep_ctx (struct xhci_hcd *xhci, +struct xhci_container_ctx *ctx, +unsigned int ep_index) +{ +/* increment ep index by offset of start of ep ctx array */ + ep_index++; +if (ctx->type ==XHCI_CTX_TYPE_INPUT ) + ep_index++; + +return (struct xhci_ep_ctx *) + (ctx->bytes + (ep_index *HCC_CTX_SIZE (xhci->hcc_params))); +} +/* * xHCI ring handling */
@@ -426,28 +459,48 @@ static struct xhci_virtual_device *xhci_find_virtdev(struct xhci_hcd *xhci,return NULL ; } +static struct xhci_container_ctx * +xhci_alloc_container_ctx (struct xhci_hcd *xhci,int type) +{ +struct xhci_container_ctx *ctx; + +if ((type !=XHCI_CTX_TYPE_DEVICE ) && (type !=XHCI_CTX_TYPE_INPUT )) +return NULL ; + + ctx =xzalloc (sizeof (*ctx)); + ctx->type = type; + ctx->size =HCC_64BYTE_CONTEXT (xhci->hcc_params) ?2048 :1024 ; +if (type ==XHCI_CTX_TYPE_INPUT ) + ctx->size +=HCC_CTX_SIZE (xhci->hcc_params); + + ctx->bytes =dma_alloc_coherent (ctx->size, &ctx->dma); +if (WARN_ON (!ctx->bytes)) { +kfree (ctx); +return NULL ; + } +return ctx; +} + +static void xhci_free_container_ctx (struct xhci_hcd *xhci, +struct xhci_container_ctx *ctx) +{ +if (!ctx) +return ; +dma_free_coherent (ctx->bytes, ctx->dma, ctx->size); +kfree (ctx); +} +static struct xhci_virtual_device *xhci_alloc_virtdev (struct xhci_hcd *xhci,struct usb_device *udev) {struct xhci_virtual_device *vdev; -size_t sz_ctx, sz_ictx, sz_dctx; -void *p; vdev =xzalloc (sizeof (*vdev)); vdev->udev = udev;list_add_tail (&vdev->list, &xhci->vdev_list); - sz_ctx =HCC_64BYTE_CONTEXT (xhci->hcc_params) ?2048 :1024 ; -/* Device Context: 64B aligned */ - sz_dctx =ALIGN (sz_ctx,64 ); -/* Input Control Context: 64B aligned */ - sz_ictx =ALIGN (sz_ctx +HCC_CTX_SIZE (xhci->hcc_params),64 ); - - vdev->dma_size = sz_ictx + sz_dctx; - p = vdev->dma =dma_alloc_coherent (vdev->dma_size,DMA_ADDRESS_BROKEN ); - - vdev->out_ctx = p; p += sz_dctx; - vdev->in_ctx = p; p += sz_ictx; + vdev->out_ctx =xhci_alloc_container_ctx (xhci,XHCI_CTX_TYPE_DEVICE ); + vdev->in_ctx =xhci_alloc_container_ctx (xhci,XHCI_CTX_TYPE_INPUT );return vdev; }
@@ -462,7 +515,8 @@ static void xhci_free_virtdev(struct xhci_virtual_device *vdev)xhci_put_endpoint_ring (xhci, vdev->ep[i]);list_del (&vdev->list); -dma_free_coherent (vdev->dma,0 , vdev->dma_size); +xhci_free_container_ctx (xhci, vdev->out_ctx); +xhci_free_container_ctx (xhci, vdev->in_ctx);free (vdev); }
@@ -486,23 +540,32 @@ static int xhci_virtdev_issue_transfer(struct xhci_virtual_device *vdev,static void xhci_virtdev_zero_in_ctx (struct xhci_virtual_device *vdev) { +struct xhci_hcd *xhci =to_xhci_hcd (vdev->udev->host); +struct xhci_input_control_ctx *in_icc; +struct xhci_slot_ctx *in_slot; +struct xhci_ep_ctx *in_ep;int i; + in_icc =xhci_get_input_control_ctx (vdev->in_ctx); + in_slot =xhci_get_slot_ctx (xhci, vdev->in_ctx); +/* When a device's add flag and drop flag are zero, any subsequent * configure endpoint command will leave that endpoint's state * untouched. Make sure we don't leave any old state in the input * endpoint contexts. */ - vdev->in_ctx->icc.drop_flags =0 ; - vdev->in_ctx->icc.add_flags =0 ; - vdev->in_ctx->slot.dev_info &=cpu_to_le32 (~LAST_CTX_MASK ); + in_icc->drop_flags =0 ; + in_icc->add_flags =0 ; + in_slot->dev_info &=cpu_to_le32 (~LAST_CTX_MASK );/* Endpoint 0 is always valid */ - vdev->in_ctx->slot.dev_info |=cpu_to_le32 (LAST_CTX (1 )); + in_slot->dev_info |=cpu_to_le32 (LAST_CTX (1 ));for (i =1 ; i <31 ; i++) { - vdev->in_ctx->ep[i].ep_info =0 ; - vdev->in_ctx->ep[i].ep_info2 =0 ; - vdev->in_ctx->ep[i].deq =0 ; - vdev->in_ctx->ep[i].tx_info =0 ; + in_ep =xhci_get_ep_ctx (xhci, vdev->in_ctx, i); + + in_ep->ep_info =0 ; + in_ep->ep_info2 =0 ; + in_ep->deq =0 ; + in_ep->tx_info =0 ; } }
@@ -558,11 +621,14 @@ static int xhci_virtdev_enable_slot(struct xhci_virtual_device *vdev)int xhci_virtdev_reset (struct xhci_virtual_device *vdev) {struct xhci_hcd *xhci =to_xhci_hcd (vdev->udev->host); +struct xhci_slot_ctx *out_slot;union xhci_trb trb;int ret; + out_slot =xhci_get_slot_ctx (xhci, vdev->out_ctx); +/* If device is not setup, there is no point in resetting it */ -if (GET_SLOT_STATE (le32_to_cpu (vdev->out_ctx->slot.dev_state)) == +if (GET_SLOT_STATE (le32_to_cpu (out_slot->dev_state)) ==SLOT_STATE_DISABLED )return 0 ;
@@ -607,31 +673,37 @@ static int xhci_virtdev_update_hub_device(struct xhci_virtual_device *vdev, {struct xhci_hcd *xhci =to_xhci_hcd (vdev->udev->host);struct usb_hub_descriptor *desc = buffer; +struct xhci_input_control_ctx *in_icc; +struct xhci_slot_ctx *in_slot, *out_slot;union xhci_trb trb;u32 dev_info, dev_info2, tt_info;u8 maxchild;u16 hubchar;int ret; + out_slot =xhci_get_slot_ctx (xhci, vdev->out_ctx); +/* Need at least first byte of wHubCharacteristics */ if (length <4 )return 0 ;/* Skip already configured hub device */ -if (vdev->out_ctx->slot.dev_info &DEV_HUB ) +if (out_slot->dev_info &DEV_HUB )return 0 ; maxchild = desc->bNbrPorts; hubchar =le16_to_cpu (desc->wHubCharacteristics); + in_slot =xhci_get_slot_ctx (xhci, vdev->in_ctx); + in_icc =xhci_get_input_control_ctx (vdev->in_ctx); +/* update slot context */ -memcpy (&vdev->in_ctx->slot, &vdev->out_ctx->slot, -sizeof (struct xhci_slot_ctx )); - vdev->in_ctx->icc.add_flags |=cpu_to_le32 (SLOT_FLAG ); - vdev->in_ctx->icc.drop_flags =0 ; - vdev->in_ctx->slot.dev_state =0 ; - dev_info =le32_to_cpu (vdev->in_ctx->slot.dev_info); - dev_info2 =le32_to_cpu (vdev->in_ctx->slot.dev_info2); - tt_info =le32_to_cpu (vdev->in_ctx->slot.tt_info); +memcpy (in_slot, out_slot,sizeof (struct xhci_slot_ctx )); + in_icc->add_flags |=cpu_to_le32 (SLOT_FLAG ); + in_icc->drop_flags =0 ; + in_slot->dev_state =0 ; + dev_info =le32_to_cpu (in_slot->dev_info); + dev_info2 =le32_to_cpu (in_slot->dev_info2); + tt_info =le32_to_cpu (in_slot->tt_info); dev_info |=DEV_HUB ;/* HS Multi-TT in bDeviceProtocol */
@@ -653,13 +725,13 @@ static int xhci_virtdev_update_hub_device(struct xhci_virtual_device *vdev, tt_info |=TT_THINK_TIME (think_time); } } - vdev->in_ctx->slot.dev_info =cpu_to_le32 (dev_info); - vdev->in_ctx->slot.dev_info2 =cpu_to_le32 (dev_info2); - vdev->in_ctx->slot.tt_info =cpu_to_le32 (tt_info); + in_slot->dev_info =cpu_to_le32 (dev_info); + in_slot->dev_info2 =cpu_to_le32 (dev_info2); + in_slot->tt_info =cpu_to_le32 (tt_info);/* Issue Configure Endpoint or Evaluate Context Command */ memset (&trb,0 ,sizeof (union xhci_trb )); -xhci_write_64 ((dma_addr_t )vdev->in_ctx, &trb.event_cmd.cmd_trb); +xhci_write_64 (vdev->in_ctx->dma, &trb.event_cmd.cmd_trb); trb.event_cmd.flags =SLOT_ID_FOR_TRB (vdev->slot_id);if (xhci->hci_version >0x95 ) trb.event_cmd.flags |=TRB_TYPE (TRB_CONFIG_EP );
@@ -695,6 +767,8 @@ static int xhci_virtdev_update_hub_status(struct xhci_virtual_device *vhub,static int xhci_virtdev_configure (struct xhci_virtual_device *vdev,int config) {struct xhci_hcd *xhci =to_xhci_hcd (vdev->udev->host); +struct xhci_input_control_ctx *in_icc; +struct xhci_slot_ctx *in_slot;struct usb_device *udev = vdev->udev;union xhci_trb trb;u32 add_flags =0 , last_ctx;
@@ -711,10 +785,12 @@ static int xhci_virtdev_configure(struct xhci_virtual_device *vdev, int config) ep->bmAttributes);u8 epi =xhci_get_endpoint_index (ep->bEndpointAddress, ep->bmAttributes); -struct xhci_ep_ctx *ctx = &vdev->in_ctx->ep[epi]; +struct xhci_ep_ctx *ctx;u32 mps, interval, mult, esit, max_packet, max_burst;u32 ep_info, ep_info2, tx_info; + ctx =xhci_get_ep_ctx (xhci, vdev->in_ctx, epi); + vdev->ep[epi] =xhci_get_endpoint_ring (xhci);if (!vdev->ep[epi])return -ENOMEM ;
@@ -781,23 +857,26 @@ static int xhci_virtdev_configure(struct xhci_virtual_device *vdev, int config) last_ctx =fls (add_flags) -1 ; + in_slot =xhci_get_slot_ctx (xhci, vdev->in_ctx); + in_icc =xhci_get_input_control_ctx (vdev->in_ctx); +/* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ - vdev->in_ctx->icc.add_flags =cpu_to_le32 (add_flags); - vdev->in_ctx->icc.add_flags |=cpu_to_le32 (SLOT_FLAG ); - vdev->in_ctx->icc.add_flags &=cpu_to_le32 (~EP0_FLAG ); - vdev->in_ctx->icc.drop_flags &=cpu_to_le32 (~(SLOT_FLAG |EP0_FLAG )); + in_icc->add_flags =cpu_to_le32 (add_flags); + in_icc->add_flags |=cpu_to_le32 (SLOT_FLAG ); + in_icc->add_flags &=cpu_to_le32 (~EP0_FLAG ); + in_icc->drop_flags &=cpu_to_le32 (~(SLOT_FLAG |EP0_FLAG ));/* Don't issue the command if there's no endpoints to update. */ -if (vdev->in_ctx->icc.add_flags ==cpu_to_le32 (SLOT_FLAG ) && - vdev->in_ctx->icc.drop_flags ==0 ) +if (in_icc->add_flags ==cpu_to_le32 (SLOT_FLAG ) && + in_icc->drop_flags ==0 )return 0 ; - vdev->in_ctx->slot.dev_info &=cpu_to_le32 (~LAST_CTX_MASK ); - vdev->in_ctx->slot.dev_info |=cpu_to_le32 (LAST_CTX (last_ctx)); + in_slot->dev_info &=cpu_to_le32 (~LAST_CTX_MASK ); + in_slot->dev_info |=cpu_to_le32 (LAST_CTX (last_ctx));/* Issue Configure Endpoint Command */ memset (&trb,0 ,sizeof (union xhci_trb )); -xhci_write_64 ((dma_addr_t )vdev->in_ctx, &trb.event_cmd.cmd_trb); +xhci_write_64 (vdev->in_ctx->dma, &trb.event_cmd.cmd_trb); trb.event_cmd.flags =TRB_TYPE (TRB_CONFIG_EP ) |SLOT_ID_FOR_TRB (vdev->slot_id);xhci_print_trb (xhci, &trb,"Request ConfigureEndpoint" );
@@ -817,7 +896,7 @@ static int xhci_virtdev_deconfigure(struct xhci_virtual_device *vdev)/* Issue Deconfigure Endpoint Command */ memset (&trb,0 ,sizeof (union xhci_trb )); -xhci_write_64 ((dma_addr_t )vdev->in_ctx, &trb.event_cmd.cmd_trb); +xhci_write_64 (vdev->in_ctx->dma, &trb.event_cmd.cmd_trb); trb.event_cmd.flags =TRB_TYPE (TRB_CONFIG_EP ) |TRB_DC |SLOT_ID_FOR_TRB (vdev->slot_id);xhci_print_trb (xhci, &trb,"Request DeconfigureEndpoint" );
@@ -833,11 +912,16 @@ static int xhci_virtdev_init(struct xhci_virtual_device *vdev) {struct xhci_hcd *xhci =to_xhci_hcd (vdev->udev->host);struct usb_device *top_dev; +struct xhci_slot_ctx *in_slot; +struct xhci_ep_ctx *in_ep;int max_packets;u32 route =0 , dev_info, dev_info2, tt_info, ep_info2, tx_info;bool on_hs_hub = false;int hs_slot_id =0 ; + in_ep =xhci_get_ep_ctx (xhci, vdev->in_ctx,0 ); + in_slot =xhci_get_slot_ctx (xhci, vdev->in_ctx); +/* * Find the root hub port this device is under, also determine SlotID * of possible external HS hub a LS/FS device could be connected to.
@@ -892,9 +976,9 @@ static int xhci_virtdev_init(struct xhci_virtual_device *vdev) tt_info |= (top_dev->portnr <<8 ) | hs_slot_id; } - vdev->in_ctx->slot.dev_info =cpu_to_le32 (dev_info); - vdev->in_ctx->slot.dev_info2 =cpu_to_le32 (dev_info2); - vdev->in_ctx->slot.tt_info =cpu_to_le32 (tt_info); + in_slot->dev_info =cpu_to_le32 (dev_info); + in_slot->dev_info2 =cpu_to_le32 (dev_info2); + in_slot->tt_info =cpu_to_le32 (tt_info);/* 4.3.3 4) Initalize Transfer Ring */ vdev->ep[0 ] =xhci_get_endpoint_ring (xhci);
@@ -906,13 +990,13 @@ static int xhci_virtdev_init(struct xhci_virtual_device *vdev) ep_info2 =EP_TYPE (CTRL_EP ) |MAX_BURST (0 ) |ERROR_COUNT (3 ); ep_info2 |=MAX_PACKET (max_packets); tx_info =AVG_TRB_LENGTH_FOR_EP (8 ); - vdev->in_ctx->ep[0 ].ep_info2 =cpu_to_le32 (ep_info2); - vdev->in_ctx->ep[0 ].tx_info =cpu_to_le32 (tx_info); - vdev->in_ctx->ep[0 ].deq =cpu_to_le64 ((dma_addr_t )vdev->ep[0 ]->enqueue | - vdev->ep[0 ]->cycle_state); + in_ep->ep_info2 =cpu_to_le32 (ep_info2); + in_ep->tx_info =cpu_to_le32 (tx_info); + in_ep->deq =cpu_to_le64 ((dma_addr_t )vdev->ep[0 ]->enqueue | + vdev->ep[0 ]->cycle_state);/* 4.3.3 6+7) Initalize and Set Device Context Base Address Array */ - xhci->dcbaa[vdev->slot_id] =cpu_to_le64 ((dma_addr_t )vdev->out_ctx); + xhci->dcbaa[vdev->slot_id] =cpu_to_le64 (vdev->out_ctx->dma);return 0 ; }
@@ -921,39 +1005,46 @@ static int xhci_virtdev_setup(struct xhci_virtual_device *vdev, enum xhci_setup_dev setup) {struct xhci_hcd *xhci =to_xhci_hcd (vdev->udev->host); +static struct xhci_input_control_ctx *in_icc; +struct xhci_slot_ctx *in_slot; +struct xhci_ep_ctx *in_ep;union xhci_trb trb;int ret; + in_slot =xhci_get_slot_ctx (xhci, vdev->in_ctx); + in_icc =xhci_get_input_control_ctx (vdev->in_ctx); +/* * If this is the first Set Address since device * plug-in then initialize Slot Context */ -if (!vdev->in_ctx->slot.dev_info) +if (!in_slot->dev_info)xhci_virtdev_init (vdev);else { + in_ep =xhci_get_ep_ctx (xhci, vdev->in_ctx,0 ); +/* Otherwise, update Control Ring Dequeue pointer */ - vdev->in_ctx->ep[0 ].deq = -cpu_to_le64 ((dma_addr_t )vdev->ep[0 ]->enqueue | - vdev->ep[0 ]->cycle_state); + in_ep->deq =cpu_to_le64 ((dma_addr_t )vdev->ep[0 ]->enqueue | + vdev->ep[0 ]->cycle_state);/* * FS devices have MaxPacketSize0 of 8 or 64, we start * with 64. If assumtion was wrong, fix it up here. */ if (vdev->udev->speed ==USB_SPEED_FULL && vdev->udev->maxpacketsize ==PACKET_SIZE_8 ) { -u32 info =le32_to_cpu (vdev->in_ctx->ep[0 ].ep_info2); +u32 info =le32_to_cpu (in_ep->ep_info2); info &= ~MAX_PACKET_MASK ; info |=MAX_PACKET (8 ); - vdev->in_ctx->ep[0 ].ep_info2 =cpu_to_le32 (info); + in_ep->ep_info2 =cpu_to_le32 (info); } } - vdev->in_ctx->icc.add_flags =cpu_to_le32 (SLOT_FLAG |EP0_FLAG ); - vdev->in_ctx->icc.drop_flags =0 ; + in_icc->add_flags =cpu_to_le32 (SLOT_FLAG |EP0_FLAG ); + in_icc->drop_flags =0 ;/* Issue Address Device Command */ memset (&trb,0 ,sizeof (union xhci_trb )); -xhci_write_64 ((dma_addr_t )vdev->in_ctx, &trb.event_cmd.cmd_trb); +xhci_write_64 (vdev->in_ctx->dma, &trb.event_cmd.cmd_trb); trb.event_cmd.flags =TRB_TYPE (TRB_ADDR_DEV ) |SLOT_ID_FOR_TRB (vdev->slot_id);if (setup ==SETUP_CONTEXT_ONLY )
@@ -1008,6 +1099,7 @@ static int xhci_submit_normal(struct usb_device *udev, unsigned long pipe,struct usb_host *host = udev->host;struct xhci_hcd *xhci =to_xhci_hcd (host);struct xhci_virtual_device *vdev; +struct xhci_slot_ctx *out_slot;union xhci_trb trb;u8 epaddr = (usb_pipein (pipe) ?USB_DIR_IN :USB_DIR_OUT ) |usb_pipeendpoint (pipe);
@@ -1018,10 +1110,12 @@ static int xhci_submit_normal(struct usb_device *udev, unsigned long pipe,if (!vdev)return -ENODEV ; + out_slot =xhci_get_slot_ctx (xhci, vdev->out_ctx); +dev_dbg (xhci->dev,"%s udev %p vdev %p slot %u state %u epi %u in_ctx %p out_ctx %p\n" , __func__, udev, vdev, vdev->slot_id, -GET_SLOT_STATE (le32_to_cpu (vdev->out_ctx->slot.dev_state)), epi, - vdev->in_ctx, vdev->out_ctx); +GET_SLOT_STATE (le32_to_cpu (out_slot->dev_state)), epi, + vdev->in_ctx->bytes, vdev->out_ctx->bytes);/* pass ownership of data buffer to device */ dma_sync_single_for_device((unsigned long)buffer, length,
@@ -1069,6 +1163,7 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe,struct usb_host *host = udev->host;struct xhci_hcd *xhci =to_xhci_hcd (host);struct xhci_virtual_device *vdev; +struct xhci_slot_ctx *out_slot;union xhci_trb trb;u16 typeReq = (req->requesttype <<8 ) | req->request;int ret;
@@ -1090,10 +1185,12 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe,if (!vdev)return -ENODEV ; + out_slot =xhci_get_slot_ctx (xhci, vdev->out_ctx); +dev_dbg (xhci->dev,"%s udev %p vdev %p slot %u state %u epi %u in_ctx %p out_ctx %p\n" , __func__, udev, vdev, vdev->slot_id, -GET_SLOT_STATE (le32_to_cpu (vdev->out_ctx->slot.dev_state)),0 , - vdev->in_ctx, vdev->out_ctx); +GET_SLOT_STATE (le32_to_cpu (out_slot->dev_state)),0 , + vdev->in_ctx->bytes, vdev->out_ctx->bytes);if (req->request ==USB_REQ_SET_ADDRESS )return xhci_virtdev_set_address (vdev);
drivers/usb/host/xhci.h +23 -13
@@ -503,6 +503,27 @@ struct xhci_doorbell_array {#define DB_VALUE (ep, stream) ((((ep) + 1) & 0xff) | ((stream) << 16))#define DB_VALUE_HOST 0x00000000 +/** +* struct xhci_container_ctx +* @type: Type of context. Used to calculated offsets to contained contexts. +* @size: Size of the context data +* @bytes: The raw context data given to HW +* @dma: dma address of the bytes +* +* Represents either a Device or Input context. Holds a pointer to the raw +* memory used for the context (bytes) and dma address of it (dma). +*/ +struct xhci_container_ctx { +unsigned type; +#define XHCI_CTX_TYPE_DEVICE 0x1 +#define XHCI_CTX_TYPE_INPUT 0x2 + +int size; + +u8 *bytes; +dma_addr_t dma; +}; +/** * struct xhci_slot_ctx * @dev_info: Route string, device speed, hub info, and last valid endpoint
@@ -1183,17 +1204,6 @@ struct xhci_ring {int cycle_state; }; -struct xhci_device_context { -struct xhci_slot_ctx slot; -struct xhci_ep_ctx ep[31 ]; -}; - -struct xhci_input_context { -struct xhci_input_control_ctx icc; -struct xhci_slot_ctx slot; -struct xhci_ep_ctx ep[31 ]; -}; -struct xhci_virtual_device {struct list_head list;struct usb_device *udev;
@@ -1201,8 +1211,8 @@ struct xhci_virtual_device {size_t dma_size;int slot_id;struct xhci_ring *ep[USB_MAXENDPOINTS ]; -struct xhci_input_context *in_ctx; -struct xhci_device_context *out_ctx; +struct xhci_container_ctx *in_ctx; +struct xhci_container_ctx *out_ctx; };struct usb_root_hub_info {
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 7/25 usb: xhci-hcd: Don't try to DMA sync if buffer is NULL
In reply to Andrey SmirnovDriver's .submit_control() callback can and will be called with buffer set to NULL (and length set to 0), so we need to make sure that we don't try to DMA sync the buffer in that case. Add appropriate gurads to make sure that doesn't happen.
--- drivers/usb/host/xhci-hcd.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/usb/host/xhci-hcd.c +13 -8
@@ -1200,10 +1200,12 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe,return ret; } -/* Pass ownership of data buffer to device */ -dma_sync_single_for_device ((unsigned long )buffer, length, - (req->requesttype &USB_DIR_IN ) ? -DMA_FROM_DEVICE :DMA_TO_DEVICE ); +if (length >0 ) { +/* Pass ownership of data buffer to device */ +dma_sync_single_for_device ((unsigned long )buffer, length, + (req->requesttype &USB_DIR_IN ) ? +DMA_FROM_DEVICE :DMA_TO_DEVICE ); + }/* Setup TRB */ memset (&trb,0 ,sizeof (union xhci_trb ));
@@ -1259,10 +1261,13 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe,xhci_print_trb (xhci, &trb,"Response Status" ); dma_regain: -/* Regain ownership of data buffer from device */ -dma_sync_single_for_cpu ((unsigned long )buffer, length, - (req->requesttype &USB_DIR_IN ) ? -DMA_FROM_DEVICE :DMA_TO_DEVICE ); +if (length >0 ) { +/* Regain ownership of data buffer from device */ +dma_sync_single_for_cpu ((unsigned long )buffer, length, + (req->requesttype &USB_DIR_IN ) ? +DMA_FROM_DEVICE :DMA_TO_DEVICE ); + } +if (ret <0 )return ret;
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 8/25 usb: xhci-hcd: Always wait for "Response Data" completion
In reply to Andrey SmirnovXhci_submit_control() submits TRB_DATA with TRB_IOC flag regardless of the vlaue of req->requesttype, so we shouldn't gate waiting for the event that will result from it with "req->requesttype & USB_DIR_IN". Failing to do this will result in unstable USB performance and will eventually cause the controller to fail completely.
--- drivers/usb/host/xhci-hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-hcd.c +1 -1
@@ -1248,7 +1248,7 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe,xhci_print_trb (xhci, &trb,"Request Status" );xhci_virtdev_issue_transfer (vdev,0 , &trb, true); -if (length >0 && req->requesttype &USB_DIR_IN ) { +if (length >0 ) { ret =xhci_wait_for_event (xhci,TRB_TRANSFER , &trb);xhci_print_trb (xhci, &trb,"Response Data " );if (ret == -COMP_SHORT_TX )
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 9/25 usb: xhci-hcd: Convert xhci_submit_normal() to use dma_map_single()
In reply to Andrey SmirnovConvert xhci_submit_normal() to use dma_(un)map_single(). These functions both allow us to handle potential physical/virtual address differences as well as allowing to drop a number of typecasts.
--- drivers/usb/host/xhci-hcd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/usb/host/xhci-hcd.c +10 -7
@@ -1100,6 +1100,7 @@ static int xhci_submit_normal(struct usb_device *udev, unsigned long pipe,struct xhci_hcd *xhci =to_xhci_hcd (host);struct xhci_virtual_device *vdev;struct xhci_slot_ctx *out_slot; +dma_addr_t buffer_dma;union xhci_trb trb;u8 epaddr = (usb_pipein (pipe) ?USB_DIR_IN :USB_DIR_OUT ) |usb_pipeendpoint (pipe);
@@ -1118,13 +1119,15 @@ static int xhci_submit_normal(struct usb_device *udev, unsigned long pipe, vdev->in_ctx->bytes, vdev->out_ctx->bytes);/* pass ownership of data buffer to device */ -dma_sync_single_for_device ((unsigned long )buffer, length, -usb_pipein (pipe) ? -DMA_FROM_DEVICE :DMA_TO_DEVICE ); + buffer_dma =dma_map_single (xhci->dev, buffer, length, +usb_pipein (pipe) ? +DMA_FROM_DEVICE :DMA_TO_DEVICE ); +if (dma_mapping_error (xhci->dev, buffer_dma)) +return -EFAULT ;/* Normal TRB */ memset (&trb,0 ,sizeof (union xhci_trb )); - trb.event_cmd.cmd_trb =cpu_to_le64 ((dma_addr_t )buffer); + trb.event_cmd.cmd_trb =cpu_to_le64 (buffer_dma);/* FIXME: TD remainder */ trb.event_cmd.status =TRB_LEN (length) |TRB_INTR_TARGET (0 ); trb.event_cmd.flags =TRB_TYPE (TRB_NORMAL ) |TRB_IOC ;
@@ -1136,9 +1139,9 @@ static int xhci_submit_normal(struct usb_device *udev, unsigned long pipe,xhci_print_trb (xhci, &trb,"Response Normal" );/* Regain ownership of data buffer from device */ -dma_sync_single_for_cpu ((unsigned long )buffer, length, -usb_pipein (pipe) ? -DMA_FROM_DEVICE :DMA_TO_DEVICE ); +dma_unmap_single (xhci->dev, buffer_dma, length, +usb_pipein (pipe) ? +DMA_FROM_DEVICE :DMA_TO_DEVICE );switch (ret) {case -COMP_SHORT_TX :
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 10/25 usb: xhci-hcd: Convert xhci_submit_control() to use dma_map_single()
In reply to Andrey SmirnovConvert xhci_submit_control() to use dma_(un)map_single(). These functions both allow us to handle potential physical/virtual address differences as well as allowing to drop a number of typecasts.
--- drivers/usb/host/xhci-hcd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/usb/host/xhci-hcd.c +10 -7
@@ -1167,6 +1167,7 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe,struct xhci_hcd *xhci =to_xhci_hcd (host);struct xhci_virtual_device *vdev;struct xhci_slot_ctx *out_slot; +dma_addr_t buffer_dma =0 ;union xhci_trb trb;u16 typeReq = (req->requesttype <<8 ) | req->request;int ret;
@@ -1205,9 +1206,11 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe,if (length >0 ) {/* Pass ownership of data buffer to device */ -dma_sync_single_for_device ((unsigned long )buffer, length, - (req->requesttype &USB_DIR_IN ) ? -DMA_FROM_DEVICE :DMA_TO_DEVICE ); + buffer_dma =dma_map_single (xhci->dev, buffer, length, + (req->requesttype &USB_DIR_IN ) ? +DMA_FROM_DEVICE :DMA_TO_DEVICE ); +if (dma_mapping_error (xhci->dev, buffer_dma)) +return -EFAULT ; }/* Setup TRB */
@@ -1230,7 +1233,7 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe,/* Data TRB */ if (length >0 ) {memset (&trb,0 ,sizeof (union xhci_trb )); - trb.event_cmd.cmd_trb =cpu_to_le64 ((dma_addr_t )buffer); + trb.event_cmd.cmd_trb =cpu_to_le64 (buffer_dma);/* FIXME: TD remainder */ trb.event_cmd.status =TRB_LEN (length) |TRB_INTR_TARGET (0 ); trb.event_cmd.flags =TRB_TYPE (TRB_DATA ) |TRB_IOC ;
@@ -1266,9 +1269,9 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe, dma_regain:if (length >0 ) {/* Regain ownership of data buffer from device */ -dma_sync_single_for_cpu ((unsigned long )buffer, length, - (req->requesttype &USB_DIR_IN ) ? -DMA_FROM_DEVICE :DMA_TO_DEVICE ); +dma_unmap_single (xhci->dev, buffer_dma, length, + (req->requesttype &USB_DIR_IN ) ? +DMA_FROM_DEVICE :DMA_TO_DEVICE ); }if (ret <0 )
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 11/25 usb: xhci-hcd: Simplify TRB initialization code
In reply to Andrey SmirnovCurrent TRB initialization code in xHCI driver is:
a) Somewhat inconsistent in endianness correctness: LE is insured in some places whereas in some places it isn't
b) Somewhat inconsistent in how DMA buffer address is being
written: some places utilize xhci_write_64, whereas others just assing cmd_trb field directly
c) A bit wasetful since in a number of codepaths where TRB is used it is memset to zero first only to have 80+% of its fields changed to something else right after.
To fix all of the above introduce xhci_init_event_cmd_trb(), that will initialize all of the fileds to desired values only once as well as taking care of endianness.
--- drivers/usb/host/xhci-hcd.c | 128 ++++++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 50 deletions(-)
drivers/usb/host/xhci-hcd.c +78 -50
@@ -569,6 +569,14 @@ static void xhci_virtdev_zero_in_ctx(struct xhci_virtual_device *vdev) } } +static void xhci_init_event_cmd_trb (union xhci_trb *trb, +u64 cmd_trb,u32 status,u32 flags) +{ +xhci_write_64 (cmd_trb, &trb->event_cmd.cmd_trb); +writel (status, &trb->event_cmd.status); +writel (flags, &trb->event_cmd.flags); +} +static int xhci_virtdev_disable_slot (struct xhci_virtual_device *vdev) {struct xhci_hcd *xhci =to_xhci_hcd (vdev->udev->host);
@@ -576,9 +584,11 @@ static int xhci_virtdev_disable_slot(struct xhci_virtual_device *vdev)int ret;/* Issue Disable Slot Command */ -memset (&trb,0 ,sizeof (union xhci_trb )); - trb.event_cmd.flags =TRB_TYPE (TRB_DISABLE_SLOT ) | -SLOT_ID_FOR_TRB (vdev->slot_id); +xhci_init_event_cmd_trb (&trb, +0 , +0 , +TRB_TYPE (TRB_DISABLE_SLOT ) | +SLOT_ID_FOR_TRB (vdev->slot_id));xhci_print_trb (xhci, &trb,"Request DisableSlot" );xhci_issue_command (xhci, &trb); ret =xhci_wait_for_event (xhci,TRB_COMPLETION , &trb);
@@ -598,8 +608,10 @@ static int xhci_virtdev_enable_slot(struct xhci_virtual_device *vdev)int ret;/* Issue Enable Slot Command */ -memset (&trb,0 ,sizeof (union xhci_trb )); - trb.event_cmd.flags =TRB_TYPE (TRB_ENABLE_SLOT ); +xhci_init_event_cmd_trb (&trb, +0 , +0 , +TRB_TYPE (TRB_ENABLE_SLOT ));xhci_print_trb (xhci, &trb,"Request EnableSlot" );xhci_issue_command (xhci, &trb); ret =xhci_wait_for_event (xhci,TRB_COMPLETION , &trb);
@@ -632,9 +644,11 @@ int xhci_virtdev_reset(struct xhci_virtual_device *vdev) SLOT_STATE_DISABLED)return 0 ; -memset (&trb,0 ,sizeof (union xhci_trb )); - trb.event_cmd.flags =TRB_TYPE (TRB_RESET_DEV ) | -SLOT_ID_FOR_TRB (vdev->slot_id); +xhci_init_event_cmd_trb (&trb, +0 , +0 , +TRB_TYPE (TRB_RESET_DEV ) | +SLOT_ID_FOR_TRB (vdev->slot_id));xhci_print_trb (xhci, &trb,"Request Reset" );xhci_issue_command (xhci, &trb); ret =xhci_wait_for_event (xhci,TRB_COMPLETION , &trb);
@@ -679,6 +693,7 @@ static int xhci_virtdev_update_hub_device(struct xhci_virtual_device *vdev,u32 dev_info, dev_info2, tt_info;u8 maxchild;u16 hubchar; +u32 flags;int ret; out_slot =xhci_get_slot_ctx (xhci, vdev->out_ctx);
@@ -730,13 +745,15 @@ static int xhci_virtdev_update_hub_device(struct xhci_virtual_device *vdev, in_slot->tt_info =cpu_to_le32 (tt_info);/* Issue Configure Endpoint or Evaluate Context Command */ -memset (&trb,0 ,sizeof (union xhci_trb )); -xhci_write_64 (vdev->in_ctx->dma, &trb.event_cmd.cmd_trb); - trb.event_cmd.flags =SLOT_ID_FOR_TRB (vdev->slot_id); + flags =SLOT_ID_FOR_TRB (vdev->slot_id);if (xhci->hci_version >0x95 ) - trb.event_cmd.flags |=TRB_TYPE (TRB_CONFIG_EP ); + flags |=TRB_TYPE (TRB_CONFIG_EP );else - trb.event_cmd.flags |=TRB_TYPE (TRB_EVAL_CONTEXT ); + flags |=TRB_TYPE (TRB_EVAL_CONTEXT ); +xhci_init_event_cmd_trb (&trb, + vdev->in_ctx->dma, +0 , + flags);xhci_print_trb (xhci, &trb,"Request ConfigureEndpoint" );xhci_issue_command (xhci, &trb); ret =xhci_wait_for_event (xhci,TRB_COMPLETION , &trb);
@@ -875,10 +892,11 @@ static int xhci_virtdev_configure(struct xhci_virtual_device *vdev, int config) in_slot->dev_info |=cpu_to_le32 (LAST_CTX (last_ctx));/* Issue Configure Endpoint Command */ -memset (&trb,0 ,sizeof (union xhci_trb )); -xhci_write_64 (vdev->in_ctx->dma, &trb.event_cmd.cmd_trb); - trb.event_cmd.flags =TRB_TYPE (TRB_CONFIG_EP ) | -SLOT_ID_FOR_TRB (vdev->slot_id); +xhci_init_event_cmd_trb (&trb, + vdev->in_ctx->dma, +0 , +TRB_TYPE (TRB_CONFIG_EP ) | +SLOT_ID_FOR_TRB (vdev->slot_id));xhci_print_trb (xhci, &trb,"Request ConfigureEndpoint" );xhci_issue_command (xhci, &trb); ret =xhci_wait_for_event (xhci,TRB_COMPLETION , &trb);
@@ -895,10 +913,11 @@ static int xhci_virtdev_deconfigure(struct xhci_virtual_device *vdev)int ret;/* Issue Deconfigure Endpoint Command */ -memset (&trb,0 ,sizeof (union xhci_trb )); -xhci_write_64 (vdev->in_ctx->dma, &trb.event_cmd.cmd_trb); - trb.event_cmd.flags =TRB_TYPE (TRB_CONFIG_EP ) |TRB_DC | -SLOT_ID_FOR_TRB (vdev->slot_id); +xhci_init_event_cmd_trb (&trb, + vdev->in_ctx->dma, +0 , +TRB_TYPE (TRB_CONFIG_EP ) |TRB_DC | +SLOT_ID_FOR_TRB (vdev->slot_id));xhci_print_trb (xhci, &trb,"Request DeconfigureEndpoint" );xhci_issue_command (xhci, &trb); ret =xhci_wait_for_event (xhci,TRB_COMPLETION , &trb);
@@ -1009,6 +1028,7 @@ static int xhci_virtdev_setup(struct xhci_virtual_device *vdev,struct xhci_slot_ctx *in_slot;struct xhci_ep_ctx *in_ep;union xhci_trb trb; +u32 flags;int ret; in_slot =xhci_get_slot_ctx (xhci, vdev->in_ctx);
@@ -1043,12 +1063,14 @@ static int xhci_virtdev_setup(struct xhci_virtual_device *vdev, in_icc->drop_flags =0 ;/* Issue Address Device Command */ -memset (&trb,0 ,sizeof (union xhci_trb )); -xhci_write_64 (vdev->in_ctx->dma, &trb.event_cmd.cmd_trb); - trb.event_cmd.flags =TRB_TYPE (TRB_ADDR_DEV ) | + flags =TRB_TYPE (TRB_ADDR_DEV ) |SLOT_ID_FOR_TRB (vdev->slot_id);if (setup ==SETUP_CONTEXT_ONLY ) - trb.event_cmd.flags |=TRB_BSR ; + flags |=TRB_BSR ; +xhci_init_event_cmd_trb (&trb, + vdev->in_ctx->dma, +0 , + flags);xhci_print_trb (xhci, &trb,"Request AddressDevice" );xhci_issue_command (xhci, &trb); ret =xhci_wait_for_event (xhci,TRB_COMPLETION , &trb);
@@ -1105,6 +1127,7 @@ static int xhci_submit_normal(struct usb_device *udev, unsigned long pipe,u8 epaddr = (usb_pipein (pipe) ?USB_DIR_IN :USB_DIR_OUT ) |usb_pipeendpoint (pipe);u8 epi =xhci_get_endpoint_index (epaddr,usb_pipetype (pipe)); +u32 flags;int ret; vdev =xhci_find_virtdev (xhci, udev);
@@ -1126,13 +1149,14 @@ static int xhci_submit_normal(struct usb_device *udev, unsigned long pipe,return -EFAULT ;/* Normal TRB */ -memset (&trb,0 ,sizeof (union xhci_trb )); - trb.event_cmd.cmd_trb =cpu_to_le64 (buffer_dma);/* FIXME: TD remainder */ - trb.event_cmd.status =TRB_LEN (length) |TRB_INTR_TARGET (0 ); - trb.event_cmd.flags =TRB_TYPE (TRB_NORMAL ) |TRB_IOC ; + flags =TRB_TYPE (TRB_NORMAL ) |TRB_IOC ;if (usb_pipein (pipe)) - trb.event_cmd.flags |=TRB_ISP ; + flags |=TRB_ISP ; +xhci_init_event_cmd_trb (&trb, + buffer_dma, +TRB_LEN (length) |TRB_INTR_TARGET (0 ), + flags);xhci_print_trb (xhci, &trb,"Request Normal" );xhci_virtdev_issue_transfer (vdev, epi, &trb, true); ret =xhci_wait_for_event (xhci,TRB_TRANSFER , &trb);
@@ -1170,6 +1194,8 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe,dma_addr_t buffer_dma =0 ;union xhci_trb trb;u16 typeReq = (req->requesttype <<8 ) | req->request; +u64 field[2 ]; +u32 flags;int ret; dev_dbg(xhci->dev, "%s req %u (%#x), type %u (%#x), value %u (%#x), index %u (%#x), length %u (%#x)\n",
@@ -1212,45 +1238,47 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe,if (dma_mapping_error (xhci->dev, buffer_dma))return -EFAULT ; } -/* Setup TRB */ -memset (&trb,0 ,sizeof (union xhci_trb )); - trb.generic.field[0 ] =le16_to_cpu (req->value) <<16 | + field[0 ] =le16_to_cpu (req->value) <<16 | req->request <<8 | req->requesttype; - trb.generic.field[1 ] =le16_to_cpu (req->length) <<16 | + field[1 ] =le16_to_cpu (req->length) <<16 |le16_to_cpu (req->index); - trb.event_cmd.status =TRB_LEN (8 ) |TRB_INTR_TARGET (0 ); - trb.event_cmd.flags =TRB_TYPE (TRB_SETUP ) |TRB_IDT ; + flags =TRB_TYPE (TRB_SETUP ) |TRB_IDT ;if (xhci->hci_version ==0x100 && length >0 ) {if (req->requesttype &USB_DIR_IN ) - trb.event_cmd.flags |=TRB_TX_TYPE (TRB_DATA_IN ); + flags |=TRB_TX_TYPE (TRB_DATA_IN );else - trb.event_cmd.flags |=TRB_TX_TYPE (TRB_DATA_OUT ); + flags |=TRB_TX_TYPE (TRB_DATA_OUT ); } +xhci_init_event_cmd_trb (&trb, + field[1 ] <<32 | field[0 ], +TRB_LEN (8 ) |TRB_INTR_TARGET (0 ), + flags);xhci_print_trb (xhci, &trb,"Request Setup " );xhci_virtdev_issue_transfer (vdev,0 , &trb, false);/* Data TRB */ if (length >0 ) { -memset (&trb,0 ,sizeof (union xhci_trb )); - trb.event_cmd.cmd_trb =cpu_to_le64 (buffer_dma);/* FIXME: TD remainder */ - trb.event_cmd.status =TRB_LEN (length) |TRB_INTR_TARGET (0 ); - trb.event_cmd.flags =TRB_TYPE (TRB_DATA ) |TRB_IOC ; + flags =TRB_TYPE (TRB_DATA ) |TRB_IOC ;if (req->requesttype &USB_DIR_IN ) - trb.event_cmd.flags |=TRB_ISP |TRB_DIR_IN ; + flags |=TRB_ISP |TRB_DIR_IN ; +xhci_init_event_cmd_trb (&trb, + buffer_dma, +TRB_LEN (length) |TRB_INTR_TARGET (0 ), + flags);xhci_print_trb (xhci, &trb,"Request Data " );xhci_virtdev_issue_transfer (vdev,0 , &trb, false); }/* Status TRB */ -memset (&trb,0 ,sizeof (union xhci_trb )); - trb.event_cmd.status =TRB_INTR_TARGET (0 ); -if (length >0 && req->requesttype &USB_DIR_IN ) - trb.event_cmd.flags =0 ; -else - trb.event_cmd.flags =TRB_DIR_IN ; - trb.event_cmd.flags |=TRB_TYPE (TRB_STATUS ) |TRB_IOC ; + flags =TRB_TYPE (TRB_STATUS ) |TRB_IOC ; +if (!(length >0 && req->requesttype &USB_DIR_IN )) + flags |=TRB_DIR_IN ; +xhci_init_event_cmd_trb (&trb, +0 , +TRB_INTR_TARGET (0 ), + flags);xhci_print_trb (xhci, &trb,"Request Status" );xhci_virtdev_issue_transfer (vdev,0 , &trb, true);
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 12/25 usb: xhci-hcd: Drop 'dma' field from struct xhci_hcd
In reply to Andrey SmirnovDrop 'dma' field from struct xhci_hcd since it is not really used anywhere.
--- drivers/usb/host/xhci-hcd.c | 2 +- drivers/usb/host/xhci.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
drivers/usb/host/xhci-hcd.c +1 -1
@@ -1359,7 +1359,7 @@ static void xhci_dma_alloc(struct xhci_hcd *xhci) num_ep =max (MAX_EP_RINGS ,MIN_EP_RINGS + num_ep); xhci->dma_size += num_ep * sz_ep; - p = xhci->dma =dma_alloc_coherent (xhci->dma_size,DMA_ADDRESS_BROKEN ); + p =dma_alloc_coherent (xhci->dma_size,DMA_ADDRESS_BROKEN ); xhci->sp = p; p += sz_sp; xhci->dcbaa = p; p += sz_dca;
drivers/usb/host/xhci.h +0 -1
@@ -1242,7 +1242,6 @@ struct xhci_hcd {int num_sp;int page_size;int page_shift; -void *dma;size_t dma_size;__le64 *dcbaa;void *sp;
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 13/25 usb: xhci-hcd: Check usb_pipein(pipe) only once in xhci_submit_normal()
In reply to Andrey SmirnovSimplfy xhci_submit_normal()'s logic a bit by using helper variables and making sure that usb_pipein(pipe) is only called once.
--- drivers/usb/host/xhci-hcd.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
drivers/usb/host/xhci-hcd.c +16 -12
@@ -1120,16 +1120,26 @@ static int xhci_submit_normal(struct usb_device *udev, unsigned long pipe, {struct usb_host *host = udev->host;struct xhci_hcd *xhci =to_xhci_hcd (host); +enum dma_data_direction dma_direction;struct xhci_virtual_device *vdev;struct xhci_slot_ctx *out_slot;dma_addr_t buffer_dma;union xhci_trb trb; -u8 epaddr = (usb_pipein (pipe) ?USB_DIR_IN :USB_DIR_OUT ) | -usb_pipeendpoint (pipe); -u8 epi =xhci_get_endpoint_index (epaddr,usb_pipetype (pipe)); -u32 flags; +u8 epaddr =usb_pipeendpoint (pipe); +u8 epi; +u32 flags =TRB_TYPE (TRB_NORMAL ) |TRB_IOC ;int ret; +if (usb_pipein (pipe)) { + epaddr |=USB_DIR_IN ; + flags |=TRB_ISP ; + dma_direction =DMA_FROM_DEVICE ; + }else { + epaddr |=USB_DIR_OUT ; + dma_direction =DMA_TO_DEVICE ; + } + + epi =xhci_get_endpoint_index (epaddr,usb_pipetype (pipe)); vdev =xhci_find_virtdev (xhci, udev);if (!vdev)return -ENODEV ;
@@ -1143,16 +1153,12 @@ static int xhci_submit_normal(struct usb_device *udev, unsigned long pipe,/* pass ownership of data buffer to device */ buffer_dma =dma_map_single (xhci->dev, buffer, length, -usb_pipein (pipe) ? -DMA_FROM_DEVICE :DMA_TO_DEVICE ); + dma_direction);if (dma_mapping_error (xhci->dev, buffer_dma))return -EFAULT ;/* Normal TRB */ /* FIXME: TD remainder */ - flags =TRB_TYPE (TRB_NORMAL ) |TRB_IOC ; -if (usb_pipein (pipe)) - flags |=TRB_ISP ; xhci_init_event_cmd_trb(&trb, buffer_dma, TRB_LEN(length) | TRB_INTR_TARGET(0),
@@ -1164,9 +1170,7 @@ static int xhci_submit_normal(struct usb_device *udev, unsigned long pipe,/* Regain ownership of data buffer from device */ dma_unmap_single (xhci->dev, buffer_dma, length, -usb_pipein (pipe) ? -DMA_FROM_DEVICE :DMA_TO_DEVICE ); - + dma_direction);switch (ret) {case -COMP_SHORT_TX : udev->status =0 ;
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 14/25 usb: xhci-hcd: Initialize TRT flag for xHCI >= 1.0
In reply to Andrey SmirnovInitialize TRT flag for xHCI >= 1.0, not just == 1.0. This is what Linux xHCI driver does.
--- drivers/usb/host/xhci-hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-hcd.c +1 -1
@@ -1248,7 +1248,7 @@ static int xhci_submit_control(struct usb_device *udev, unsigned long pipe, field[1 ] =le16_to_cpu (req->length) <<16 |le16_to_cpu (req->index); flags =TRB_TYPE (TRB_SETUP ) |TRB_IDT ; -if (xhci->hci_version ==0x100 && length >0 ) { +if (xhci->hci_version >=0x100 && length >0 ) {if (req->requesttype &USB_DIR_IN ) flags |=TRB_TX_TYPE (TRB_DATA_IN );else
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 15/25 usb: xhci-hcd: Simplify route string building loop
In reply to Andrey SmirnovSimplify route string building loop by avoiding checking top_dev->parent->descriptor->bDeviceClass twice.
--- drivers/usb/host/xhci-hcd.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/usb/host/xhci-hcd.c +6 -4
@@ -947,10 +947,12 @@ static int xhci_virtdev_init(struct xhci_virtual_device *vdev)*/ for (top_dev = vdev->udev; top_dev->parent && top_dev->parent->parent; top_dev = top_dev->parent) { -if (top_dev->parent->descriptor->bDeviceClass ==USB_CLASS_HUB ) - route = (route <<4 ) | (top_dev->portnr &0xf ); -if (top_dev->parent->descriptor->bDeviceClass ==USB_CLASS_HUB && - top_dev->parent->speed !=USB_SPEED_LOW && +if (top_dev->parent->descriptor->bDeviceClass !=USB_CLASS_HUB ) +continue ; + + route = (route <<4 ) | (top_dev->portnr &0xf ); + +if (top_dev->parent->speed !=USB_SPEED_LOW && top_dev->parent->speed !=USB_SPEED_FULL ) { on_hs_hub = true;if (!hs_slot_id) {
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 16/25 usb: xhci-hcd: Make use of lo_hi_readq/writeq()
In reply to Andrey SmirnovMake use of lo_hi_readq/writeq() to implement xhci_read/write_64() helpers, same as it is done in the Linux kernel.
--- drivers/usb/host/xhci.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/usb/host/xhci.h +4 -10
@@ -24,6 +24,8 @@#ifndef __XHCI_H#define __XHCI_H +#include <io-64-nonatomic-lo-hi.h> +#define NUM_COMMAND_TRBS 8#define NUM_TRANSFER_TRBS 8#define NUM_EVENT_SEGM 1/* only one supported */
@@ -1165,19 +1167,11 @@ struct xhci_erst_entry {*/ static inline u64 xhci_read_64 (__le64 __iomem *regs) { -__u32 __iomem *ptr = (__u32 __iomem *)regs; -u64 val_lo =readl (ptr); -u64 val_hi =readl (ptr +1 ); -return val_lo + (val_hi <<32 ); +return lo_hi_readq (regs); }static inline void xhci_write_64 (const u64 val,__le64 __iomem *regs) { -__u32 __iomem *ptr = (__u32 __iomem *)regs; -u32 val_lo =lower_32_bits (val); -u32 val_hi =upper_32_bits (val); - -writel (val_lo, ptr); -writel (val_hi, ptr +1 ); +lo_hi_writeq (val, regs); }/*
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 17/25 phy: core: Assume EPROBE_DEFER in of_phy_provider_lookup()
In reply to Andrey SmirnovIn order to support PHY driver probe deferral change the code to assume EPROBE_DEFER instead of ENODEV when requested PHY is missing from phy_provider_list.
--- drivers/phy/phy-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/phy/phy-core.c +2 -2
@@ -227,7 +227,7 @@ static struct phy_provider *of_phy_provider_lookup(struct device_node *node)return phy_provider; } -return ERR_PTR (-ENODEV ); +return ERR_PTR (-EPROBE_DEFER ); }/**
@@ -254,7 +254,7 @@ static struct phy *_of_phy_get(struct device_node *np, int index) phy_provider =of_phy_provider_lookup (args.np);if (IS_ERR (phy_provider)) { -return ERR_PTR (-ENODEV ); +return ERR_CAST (phy_provider); }return phy_provider->of_xlate (phy_provider->dev, &args);
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 18/25 phy: Port i.MX8MQ USB PHY driver from Linux
In reply to Andrey SmirnovPort i.MX8MQ USB PHY driver from Linux.
--- drivers/phy/Kconfig | 2 + drivers/phy/Makefile | 1 + drivers/phy/freescale/Kconfig | 4 + drivers/phy/freescale/Makefile | 1 + drivers/phy/freescale/phy-fsl-imx8mq-usb.c | 130 +++++++++++++++++++++ 5 files changed, 138 insertions(+) create mode 100644 drivers/phy/freescale/Kconfig create mode 100644 drivers/phy/freescale/Makefile create mode 100644 drivers/phy/freescale/phy-fsl-imx8mq-usb.c
drivers/phy/Kconfig +2 -0
@@ -22,4 +22,6 @@ config USB_NOP_XCEIV built-in with usb ip or which are autonomous and doesn't require any phy programming such as ISP1x04 etc. +source "drivers/phy/freescale/Kconfig" + endif
drivers/phy/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_GENERIC_PHY) += phy-core.o obj-$(CONFIG_USB_NOP_XCEIV) += usb-nop-xceiv.o +obj-y += freescale/
drivers/phy/freescale/Kconfig new file +4 -0
@@ -0,0 +1,4 @@ +config PHY_FSL_IMX8MQ_USB + bool "Freescale i.MX8M USB3 PHY" + default SOC_IMX8MQ +
drivers/phy/freescale/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_PHY_FSL_IMX8MQ_USB) += phy-fsl-imx8mq-usb.o
drivers/phy/freescale/phy-fsl-imx8mq-usb.c new file +130 -0
130 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 19/25 clk: Drop separate definitions of clk_put()
In reply to Andrey SmirnovRegardless of the value of CONFIG_HAVE_CLK, clk_put() implementation is always a no-op. Move the definition to linux/clk.h and drop the rest of the code implementing it.
--- drivers/clk/clkdev.c | 5 ----- include/linux/clk.h | 21 ++++----------------- 2 files changed, 4 insertions(+), 22 deletions(-)
drivers/clk/clkdev.c +0 -5
@@ -189,11 +189,6 @@ struct clk *clk_get(struct device_d *dev, const char *con_id) }EXPORT_SYMBOL (clk_get); -void clk_put (struct clk *clk) -{ -} -EXPORT_SYMBOL (clk_put); -void clkdev_add (struct clk_lookup *cl) {if (cl->dev_id)
include/linux/clk.h +4 -17
@@ -75,19 +75,6 @@ void clk_disable(struct clk *clk);*/ unsigned long clk_get_rate (struct clk *clk); -/** -* clk_put - "free" the clock source -* @clk: clock source -* -* Note: drivers must ensure that all clk_enable calls made on this -* clock source are balanced by clk_disable calls prior to calling -* this function. -* -* clk_put should not be called from within interrupt context. -*/ -void clk_put (struct clk *clk); - -/* * The remaining APIs are optional for machine class support. */
@@ -180,10 +167,6 @@ static inline unsigned long clk_get_rate(struct clk *clk)return 0 ; } -static inline void clk_put (struct clk *clk) -{ -} -static inline long clk_round_rate (struct clk *clk,unsigned long rate) {return 0 ;
@@ -195,6 +178,10 @@ static inline int clk_set_rate(struct clk *clk, unsigned long rate) }#endif +static inline void clk_put (struct clk *clk) +{ +} +#ifdef CONFIG_COMMON_CLK #include <linux/list.h>
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 20/25 include/usb: Import USB_SPEED_SUPER_PLUS from Linux
In reply to Andrey SmirnovImport USB_SPEED_SUPER_PLUS constant from Linux to support porting kernel code that uses it.
--- include/usb/ch9.h | 1 + 1 file changed, 1 insertion(+)
include/usb/ch9.h +1 -0
@@ -913,6 +913,7 @@ enum usb_device_speed {USB_SPEED_HIGH ,/* usb 2.0 */ USB_SPEED_WIRELESS ,/* wireless (usb 2.5) */ USB_SPEED_SUPER ,/* usb 3.0 */ + USB_SPEED_SUPER_PLUS, /* usb 3.1 */ };
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 21/25 clk: Import a subset of clk_bulk API from Linux
In reply to Andrey SmirnovImport a subset of clk_bulk API from Linux to support porting kernel code that uses it.
--- drivers/clk/Makefile | 3 +- drivers/clk/clk-bulk.c | 102 +++++++++++++++++++++++++++++++++++++++++ include/linux/clk.h | 98 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 drivers/clk/clk-bulk.c
drivers/clk/Makefile +2 -1
@@ -1,7 +1,8 @@ obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed.o clk-divider.o clk-fixed-factor.o \ clk-mux.o clk-gate.o clk-composite.o \ clk-fractional-divider.o clk-conf.o \ - clk-gate-shared.o clk-gpio.o + clk-gate-shared.o clk-gpio.o \ + clk-bulk.o obj-$(CONFIG_CLKDEV_LOOKUP) += clkdev.o obj-$(CONFIG_ARCH_MVEBU) += mvebu/
drivers/clk/clk-bulk.c new file +102 -0
102 lines not on this page · raw message
include/linux/clk.h +98 -0
143 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 22/25 usb: Import DWC3 USB controller driver from Linux
In reply to Andrey SmirnovImport DWC3 USB controller driver from Linux. This is a bare minimum port of the code needed to support USB host functionality on i.MX8MQ. No other use-case is explicitly supported.
--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 1 + drivers/usb/dwc3/Kconfig | 22 + drivers/usb/dwc3/Makefile | 10 + drivers/usb/dwc3/core.c | 740 ++++++++++++++++++++++ drivers/usb/dwc3/core.h | 1267 +++++++++++++++++++++++++++++++++++++ drivers/usb/dwc3/debug.h | 664 +++++++++++++++++++ drivers/usb/dwc3/host.c | 36 ++ drivers/usb/dwc3/io.h | 41 ++ 9 files changed, 2783 insertions(+) create mode 100644 drivers/usb/dwc3/Kconfig create mode 100644 drivers/usb/dwc3/Makefile create mode 100644 drivers/usb/dwc3/core.c create mode 100644 drivers/usb/dwc3/core.h create mode 100644 drivers/usb/dwc3/debug.h create mode 100644 drivers/usb/dwc3/host.c create mode 100644 drivers/usb/dwc3/io.h
drivers/usb/Kconfig +2 -0
@@ -9,6 +9,8 @@ if USB_HOST source drivers/usb/imx/Kconfig +source "drivers/usb/dwc3/Kconfig" + source drivers/usb/host/Kconfig source drivers/usb/otg/Kconfig
drivers/usb/Makefile +1 -0
@@ -1,5 +1,6 @@ obj-$(CONFIG_USB) += core/ obj-$(CONFIG_USB_IMX_CHIPIDEA) += imx/ +obj-$(CONFIG_USB_DWC3) += dwc3/ obj-$(CONFIG_USB_MUSB) += musb/ obj-$(CONFIG_USB_GADGET) += gadget/ obj-$(CONFIG_USB_STORAGE) += storage/
drivers/usb/dwc3/Kconfig new file +22 -0
@@ -0,0 +1,22 @@ +config USB_DWC3 + tristate "DesignWare USB3 DRD Core Support" + depends on USB && HAS_DMA + select USB_XHCI + select USB_DWC3_HOST # Remove this once we support more + # than USB host + help + Say Y or M here if your system has a Dual Role SuperSpeed + USB controller based on the DesignWare USB3 IP Core. + + If you choose to build this driver is a dynamically linked + module, the module will be called dwc3.ko. + +if USB_DWC3 + +config USB_DWC3_HOST + bool "Host only mode" + help + Select this when you want to use DWC3 in host mode only, + thereby the gadget feature will be regressed. + +endif
drivers/usb/dwc3/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_USB_DWC3) += dwc3.o + +dwc3-y := core.o + +ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST)),) + dwc3-y += host.o +endif +
drivers/usb/dwc3/core.c new file +740 -0
740 lines not on this page · raw message
drivers/usb/dwc3/core.h new file +1267 -0
1,267 lines not on this page · raw message
drivers/usb/dwc3/debug.h new file +664 -0
664 lines not on this page · raw message
drivers/usb/dwc3/host.c new file +36 -0
@@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0 +/** +* host.c - DesignWare USB3 DRD Controller Host Glue +* +* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com +* +* Authors: Felipe Balbi <[email protected]>, +*/ + +#include <common.h> +#include <driver.h> +#include <init.h> + +#include "core.h" + +int dwc3_host_init (struct dwc3 *dwc) +{ +struct resource *io; +struct device_d *dev = dwc->dev; + + io =dev_get_resource (dev,IORESOURCE_MEM ,0 ); +if (IS_ERR (io)) { +dev_err (dev,"Failed to get IORESOURCE_MEM\n" ); +return PTR_ERR (io); + } + + dwc->xhci =add_generic_device ("xHCI" ,DEVICE_ID_DYNAMIC ,NULL , + io->start,resource_size (io), +IORESOURCE_MEM ,NULL ); +if (!dwc->xhci) { +dev_err (dev,"Failed to register xHCI deivce\n" ); +return -ENODEV ; + } + +return 0 ; +}
drivers/usb/dwc3/io.h new file +41 -0
41 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 23/25 lib: Port basic Linux kernel NLS functions
In reply to Andrey SmirnovPort basic Linux kernel NLS functions: utf8_to_utf32() and utf8s_to_utf16s() in order to support porting kernel code that uses them.
--- include/linux/nls.h | 40 ++++++++++++++ lib/Kconfig | 3 + lib/Makefile | 1 + lib/nls_base.c | 131 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 175 insertions(+) create mode 100644 include/linux/nls.h create mode 100644 lib/nls_base.c
include/linux/nls.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_NLS_H +#define _LINUX_NLS_H + +/* Unicode has changed over the years. Unicode code points no longer +* fit into 16 bits; as of Unicode 5 valid code points range from 0 +* to 0x10ffff (17 planes, where each plane holds 65536 code points). +* +* The original decision to represent Unicode characters as 16-bit +* wchar_t values is now outdated. But plane 0 still includes the +* most commonly used characters, so we will retain it. The newer +* 32-bit unicode_t type can be used when it is necessary to +* represent the full Unicode character set. +*/ + +/* Plane-0 Unicode character */ +typedef u16 wchar_t ; +#define MAX_WCHAR_T 0xffff + +/* Arbitrary Unicode character */ +typedef u32 unicode_t ; + +/* this value hold the maximum octet of charset */ +#define NLS_MAX_CHARSET_SIZE 6/* for UTF-8 */ + +/* Byte order for UTF-16 strings */ +enum utf16_endian { +UTF16_HOST_ENDIAN , +UTF16_LITTLE_ENDIAN , +UTF16_BIG_ENDIAN +}; + +/* nls_base.c */ + +extern int utf8_to_utf32 (const u8 *s,int len,unicode_t *pu); +extern int utf8s_to_utf16s (const u8 *s,int len, +enum utf16_endian endian,wchar_t *pwcs,int maxlen); + +#endif /* _LINUX_NLS_H */ +
lib/Kconfig +3 -0
@@ -148,4 +148,7 @@ config GENERIC_LIB_LSHRDI3 config GENERIC_LIB_MULDI3 bool +config NLS + bool "Native language support" + endmenu
lib/Makefile +1 -0
@@ -67,6 +67,7 @@ obj-y += parseopt.o obj-y += clz_ctz.o obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o obj-$(CONFIG_CRC8) += crc8.o +obj-$(CONFIG_NLS) += nls_base.o # GCC library routines obj-$(CONFIG_GENERIC_LIB_ASHLDI3) += ashldi3.o
lib/nls_base.c new file +131 -0
131 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 24/25 usb: Port Microchip USB251x USB hub driver from Linux
In reply to Andrey SmirnovPort Microchip USB251x USB hub driver from Linux. Needed by ZII's i.MX8MQ boards.
--- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 1 + drivers/usb/misc/Kconfig | 14 + drivers/usb/misc/Makefile | 6 + drivers/usb/misc/usb251xb.c | 672 ++++++++++++++++++++++++++++++++++++ 5 files changed, 695 insertions(+) create mode 100644 drivers/usb/misc/Kconfig create mode 100644 drivers/usb/misc/Makefile create mode 100644 drivers/usb/misc/usb251xb.c
drivers/usb/Kconfig +2 -0
@@ -17,6 +17,8 @@ source drivers/usb/otg/Kconfig source drivers/usb/storage/Kconfig +source "drivers/usb/misc/Kconfig" + endif source drivers/usb/gadget/Kconfig
drivers/usb/Makefile +1 -0
@@ -6,4 +6,5 @@ obj-$(CONFIG_USB_GADGET) += gadget/ obj-$(CONFIG_USB_STORAGE) += storage/ obj-y += host/ obj-y += otg/ +obj-$(CONFIG_USB) += misc/
drivers/usb/misc/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +# +# USB Miscellaneous driver configuration +# +comment "USB Miscellaneous drivers" + +config USB_HUB_USB251XB + bool "USB251XB Hub Controller Configuration Driver" + depends on I2C + select NLS + help + This option enables support for configuration via SMBus of the + Microchip USB251x/xBi USB 2.0 Hub Controller series. Configuration + parameters may be set in devicetree or platform data. + Say Y or M here if you need to configure such a device via SMBus.
drivers/usb/misc/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the rest of the USB drivers +# (the ones that don't fit into any other categories) +# +obj-$(CONFIG_USB_HUB_USB251XB) += usb251xb.o
drivers/usb/misc/usb251xb.c new file +672 -0
672 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 25/25 usb: usb251xb: add usb data lane port swap feature
In reply to Andrey SmirnovPort of Linux patch https://patchwork.kernel.org/patch/10766235/
The HW can swap the USB differential-pair (D+/D-) for each port separately. So the USB signals can be re-aligned with a misplaced USB connector on the PCB.
--- drivers/usb/misc/usb251xb.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/usb/misc/usb251xb.c +13 -2
@@ -340,12 +340,14 @@ static int usb251xb_get_ofdata(struct usb251xb *hub,struct device_d *dev = hub->dev;struct device_node *np = dev->device_node;int len, err, i; -u32 property_u32 =0 ; +u32 port, property_u32 =0 ;const u32 *cproperty_u32;const char *cproperty_char;enum of_gpio_flags of_flags;unsigned long flags =GPIOF_OUT_INIT_ACTIVE ;char str[USB251XB_STRING_BUFSIZE /2 ]; +struct property *prop; +const __be32 *p;if (!np) {dev_err (dev,"failed to get ofdata\n" );
@@ -556,6 +558,16 @@ static int usb251xb_get_ofdata(struct usb251xb *hub, (wchar_t *)hub->serial, USB251XB_STRING_BUFSIZE); +/* +* The datasheet documents the register as 'Port Swap' but the register +* controls the USB DP/DM signal swapping +*/ + hub->port_swap =USB251XB_DEF_PORT_SWAP ; +of_property_for_each_u32 (np,"swap-dx-lanes" , prop, p, port) { +if ((port >=0 ) && (port <= data->port_cnt)) + hub->port_swap |=BIT (port); + } +/* The following parameters are currently not exposed to devicetree, but * may be as soon as needed. */
@@ -563,7 +575,6 @@ static int usb251xb_get_ofdata(struct usb251xb *hub, hub->boost_up =USB251XB_DEF_BOOST_UP ; hub->boost_57 =USB251XB_DEF_BOOST_57 ; hub->boost_14 =USB251XB_DEF_BOOST_14 ; - hub->port_swap =USB251XB_DEF_PORT_SWAP ; hub->port_map12 =USB251XB_DEF_PORT_MAP_12 ; hub->port_map34 =USB251XB_DEF_PORT_MAP_34 ; hub->port_map56 =USB251XB_DEF_PORT_MAP_56 ;
Signature · 7 lines
2.20.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 12 lines · Andrey Smirnov
Everyone:
This series contains changes I made while working on adding USB support for ZII i.MX8MQ boards. There are several distinct parts in this series:
1. xHCI fixes, features and improvements
2. PHY driver deferral support
3. i.MX8MQ USB PHY driver
4. DWC3 USB support and related patches
5. USB251x USB hub and related patches
Quoted 6 lines
First four are neccessary for i.MX8MQ in general and last part is ZII specific only. Hopefully all patches are self explanatory.
Tested on ZII i.MX8MQ boards.
Feedback is welcome!
Nice work. That'll safe me some time when adding USB support for Layerscape ;)
Applied, thanks
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox