Skip to content

Commit

Permalink
usb: musb: Remove ifdefs for TX DMA for musb_host.c
Browse files Browse the repository at this point in the history
We can remove the ifdefs by setting up helper functions for
mentor DMA and cppi/tusb DMA.

Note that I've kept the existing formatting as otherwise this
patch becomes pretty much unreadable.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Tony Lindgren authored and Felipe Balbi committed May 7, 2015
1 parent fb91cdd commit 754fe4a
Showing 1 changed file with 48 additions and 13 deletions.
61 changes: 48 additions & 13 deletions drivers/usb/musb/musb_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,23 +617,22 @@ musb_rx_reinit(struct musb *musb, struct musb_qh *qh, struct musb_hw_ep *ep)
ep->rx_reinit = 0;
}

static bool musb_tx_dma_program(struct dma_controller *dma,
static int musb_tx_dma_set_mode_mentor(struct dma_controller *dma,
struct musb_hw_ep *hw_ep, struct musb_qh *qh,
struct urb *urb, u32 offset, u32 length)
struct urb *urb, u32 offset,
u32 *length, u8 *mode)
{
struct dma_channel *channel = hw_ep->tx_channel;
void __iomem *epio = hw_ep->regs;
u16 pkt_size = qh->maxpacket;
u16 csr;
u8 mode;

#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA)
if (length > channel->max_len)
length = channel->max_len;
if (*length > channel->max_len)
*length = channel->max_len;

csr = musb_readw(epio, MUSB_TXCSR);
if (length > pkt_size) {
mode = 1;
if (*length > pkt_size) {
*mode = 1;
csr |= MUSB_TXCSR_DMAMODE | MUSB_TXCSR_DMAENAB;
/* autoset shouldn't be set in high bandwidth */
/*
Expand All @@ -649,24 +648,57 @@ static bool musb_tx_dma_program(struct dma_controller *dma,
can_bulk_split(hw_ep->musb, qh->type)))
csr |= MUSB_TXCSR_AUTOSET;
} else {
mode = 0;
*mode = 0;
csr &= ~(MUSB_TXCSR_AUTOSET | MUSB_TXCSR_DMAMODE);
csr |= MUSB_TXCSR_DMAENAB; /* against programmer's guide */
}
channel->desired_mode = mode;
musb_writew(epio, MUSB_TXCSR, csr);
#else

return 0;
}

static int musb_tx_dma_set_mode_cppi_tusb(struct dma_controller *dma,
struct musb_hw_ep *hw_ep,
struct musb_qh *qh,
struct urb *urb,
u32 offset,
u32 *length,
u8 *mode)
{
struct dma_channel *channel = hw_ep->tx_channel;

if (!is_cppi_enabled(hw_ep->musb) && !tusb_dma_omap(hw_ep->musb))
return false;
return -ENODEV;

channel->actual_len = 0;

/*
* TX uses "RNDIS" mode automatically but needs help
* to identify the zero-length-final-packet case.
*/
mode = (urb->transfer_flags & URB_ZERO_PACKET) ? 1 : 0;
#endif
*mode = (urb->transfer_flags & URB_ZERO_PACKET) ? 1 : 0;

return 0;
}

static bool musb_tx_dma_program(struct dma_controller *dma,
struct musb_hw_ep *hw_ep, struct musb_qh *qh,
struct urb *urb, u32 offset, u32 length)
{
struct dma_channel *channel = hw_ep->tx_channel;
u16 pkt_size = qh->maxpacket;
u8 mode;
int res;

if (musb_dma_inventra(hw_ep->musb) || musb_dma_ux500(hw_ep->musb))
res = musb_tx_dma_set_mode_mentor(dma, hw_ep, qh, urb,
offset, &length, &mode);
else
res = musb_tx_dma_set_mode_cppi_tusb(dma, hw_ep, qh, urb,
offset, &length, &mode);
if (res)
return false;

qh->segsize = length;

Expand All @@ -678,6 +710,9 @@ static bool musb_tx_dma_program(struct dma_controller *dma,

if (!dma->channel_program(channel, pkt_size, mode,
urb->transfer_dma + offset, length)) {
void __iomem *epio = hw_ep->regs;
u16 csr;

dma->channel_release(channel);
hw_ep->tx_channel = NULL;

Expand Down

0 comments on commit 754fe4a

Please sign in to comment.