1550a7375SFelipe Balbi /* 2550a7375SFelipe Balbi * TUSB6010 USB 2.0 OTG Dual Role controller OMAP DMA interface 3550a7375SFelipe Balbi * 4550a7375SFelipe Balbi * Copyright (C) 2006 Nokia Corporation 5550a7375SFelipe Balbi * Tony Lindgren <tony@atomide.com> 6550a7375SFelipe Balbi * 7550a7375SFelipe Balbi * This program is free software; you can redistribute it and/or modify 8550a7375SFelipe Balbi * it under the terms of the GNU General Public License version 2 as 9550a7375SFelipe Balbi * published by the Free Software Foundation. 10550a7375SFelipe Balbi */ 11550a7375SFelipe Balbi #include <linux/module.h> 12550a7375SFelipe Balbi #include <linux/kernel.h> 13550a7375SFelipe Balbi #include <linux/errno.h> 14550a7375SFelipe Balbi #include <linux/init.h> 15550a7375SFelipe Balbi #include <linux/usb.h> 16550a7375SFelipe Balbi #include <linux/platform_device.h> 17550a7375SFelipe Balbi #include <linux/dma-mapping.h> 185a0e3ad6STejun Heo #include <linux/slab.h> 19*45c3eb7dSTony Lindgren #include <linux/omap-dma.h> 20550a7375SFelipe Balbi 21550a7375SFelipe Balbi #include "musb_core.h" 22240a16e2SFelipe Balbi #include "tusb6010.h" 23550a7375SFelipe Balbi 24550a7375SFelipe Balbi #define to_chdat(c) ((struct tusb_omap_dma_ch *)(c)->private_data) 25550a7375SFelipe Balbi 26550a7375SFelipe Balbi #define MAX_DMAREQ 5 /* REVISIT: Really 6, but req5 not OK */ 27550a7375SFelipe Balbi 28d5e7c864SLokesh Vutla #define OMAP24XX_DMA_EXT_DMAREQ0 2 29d5e7c864SLokesh Vutla #define OMAP24XX_DMA_EXT_DMAREQ1 3 30d5e7c864SLokesh Vutla #define OMAP242X_DMA_EXT_DMAREQ2 14 31d5e7c864SLokesh Vutla #define OMAP242X_DMA_EXT_DMAREQ3 15 32d5e7c864SLokesh Vutla #define OMAP242X_DMA_EXT_DMAREQ4 16 33d5e7c864SLokesh Vutla #define OMAP242X_DMA_EXT_DMAREQ5 64 34d5e7c864SLokesh Vutla 35550a7375SFelipe Balbi struct tusb_omap_dma_ch { 36550a7375SFelipe Balbi struct musb *musb; 37550a7375SFelipe Balbi void __iomem *tbase; 38550a7375SFelipe Balbi unsigned long phys_offset; 39550a7375SFelipe Balbi int epnum; 40550a7375SFelipe Balbi u8 tx; 41550a7375SFelipe Balbi struct musb_hw_ep *hw_ep; 42550a7375SFelipe Balbi 43550a7375SFelipe Balbi int ch; 44550a7375SFelipe Balbi s8 dmareq; 45550a7375SFelipe Balbi s8 sync_dev; 46550a7375SFelipe Balbi 47550a7375SFelipe Balbi struct tusb_omap_dma *tusb_dma; 48550a7375SFelipe Balbi 491d0f11b3STony Lindgren dma_addr_t dma_addr; 50550a7375SFelipe Balbi 51550a7375SFelipe Balbi u32 len; 52550a7375SFelipe Balbi u16 packet_sz; 53550a7375SFelipe Balbi u16 transfer_packet_sz; 54550a7375SFelipe Balbi u32 transfer_len; 55550a7375SFelipe Balbi u32 completed_len; 56550a7375SFelipe Balbi }; 57550a7375SFelipe Balbi 58550a7375SFelipe Balbi struct tusb_omap_dma { 59550a7375SFelipe Balbi struct dma_controller controller; 60550a7375SFelipe Balbi struct musb *musb; 61550a7375SFelipe Balbi void __iomem *tbase; 62550a7375SFelipe Balbi 63550a7375SFelipe Balbi int ch; 64550a7375SFelipe Balbi s8 dmareq; 65550a7375SFelipe Balbi s8 sync_dev; 66550a7375SFelipe Balbi unsigned multichannel:1; 67550a7375SFelipe Balbi }; 68550a7375SFelipe Balbi 69550a7375SFelipe Balbi static int tusb_omap_dma_start(struct dma_controller *c) 70550a7375SFelipe Balbi { 71550a7375SFelipe Balbi struct tusb_omap_dma *tusb_dma; 72550a7375SFelipe Balbi 73550a7375SFelipe Balbi tusb_dma = container_of(c, struct tusb_omap_dma, controller); 74550a7375SFelipe Balbi 755c8a86e1SFelipe Balbi /* dev_dbg(musb->controller, "ep%i ch: %i\n", chdat->epnum, chdat->ch); */ 76550a7375SFelipe Balbi 77550a7375SFelipe Balbi return 0; 78550a7375SFelipe Balbi } 79550a7375SFelipe Balbi 80550a7375SFelipe Balbi static int tusb_omap_dma_stop(struct dma_controller *c) 81550a7375SFelipe Balbi { 82550a7375SFelipe Balbi struct tusb_omap_dma *tusb_dma; 83550a7375SFelipe Balbi 84550a7375SFelipe Balbi tusb_dma = container_of(c, struct tusb_omap_dma, controller); 85550a7375SFelipe Balbi 865c8a86e1SFelipe Balbi /* dev_dbg(musb->controller, "ep%i ch: %i\n", chdat->epnum, chdat->ch); */ 87550a7375SFelipe Balbi 88550a7375SFelipe Balbi return 0; 89550a7375SFelipe Balbi } 90550a7375SFelipe Balbi 91550a7375SFelipe Balbi /* 92550a7375SFelipe Balbi * Allocate dmareq0 to the current channel unless it's already taken 93550a7375SFelipe Balbi */ 94550a7375SFelipe Balbi static inline int tusb_omap_use_shared_dmareq(struct tusb_omap_dma_ch *chdat) 95550a7375SFelipe Balbi { 96550a7375SFelipe Balbi u32 reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP); 97550a7375SFelipe Balbi 98550a7375SFelipe Balbi if (reg != 0) { 9974c6f3a4SSergei Trofimovich dev_dbg(chdat->musb->controller, "ep%i dmareq0 is busy for ep%i\n", 100550a7375SFelipe Balbi chdat->epnum, reg & 0xf); 101550a7375SFelipe Balbi return -EAGAIN; 102550a7375SFelipe Balbi } 103550a7375SFelipe Balbi 104550a7375SFelipe Balbi if (chdat->tx) 105550a7375SFelipe Balbi reg = (1 << 4) | chdat->epnum; 106550a7375SFelipe Balbi else 107550a7375SFelipe Balbi reg = chdat->epnum; 108550a7375SFelipe Balbi 109550a7375SFelipe Balbi musb_writel(chdat->tbase, TUSB_DMA_EP_MAP, reg); 110550a7375SFelipe Balbi 111550a7375SFelipe Balbi return 0; 112550a7375SFelipe Balbi } 113550a7375SFelipe Balbi 114550a7375SFelipe Balbi static inline void tusb_omap_free_shared_dmareq(struct tusb_omap_dma_ch *chdat) 115550a7375SFelipe Balbi { 116550a7375SFelipe Balbi u32 reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP); 117550a7375SFelipe Balbi 118550a7375SFelipe Balbi if ((reg & 0xf) != chdat->epnum) { 119550a7375SFelipe Balbi printk(KERN_ERR "ep%i trying to release dmareq0 for ep%i\n", 120550a7375SFelipe Balbi chdat->epnum, reg & 0xf); 121550a7375SFelipe Balbi return; 122550a7375SFelipe Balbi } 123550a7375SFelipe Balbi musb_writel(chdat->tbase, TUSB_DMA_EP_MAP, 0); 124550a7375SFelipe Balbi } 125550a7375SFelipe Balbi 126550a7375SFelipe Balbi /* 127550a7375SFelipe Balbi * See also musb_dma_completion in plat_uds.c and musb_g_[tx|rx]() in 128550a7375SFelipe Balbi * musb_gadget.c. 129550a7375SFelipe Balbi */ 130550a7375SFelipe Balbi static void tusb_omap_dma_cb(int lch, u16 ch_status, void *data) 131550a7375SFelipe Balbi { 132550a7375SFelipe Balbi struct dma_channel *channel = (struct dma_channel *)data; 133550a7375SFelipe Balbi struct tusb_omap_dma_ch *chdat = to_chdat(channel); 134550a7375SFelipe Balbi struct tusb_omap_dma *tusb_dma = chdat->tusb_dma; 135550a7375SFelipe Balbi struct musb *musb = chdat->musb; 1361d0f11b3STony Lindgren struct device *dev = musb->controller; 137550a7375SFelipe Balbi struct musb_hw_ep *hw_ep = chdat->hw_ep; 138550a7375SFelipe Balbi void __iomem *ep_conf = hw_ep->conf; 139550a7375SFelipe Balbi void __iomem *mbase = musb->mregs; 140550a7375SFelipe Balbi unsigned long remaining, flags, pio; 141550a7375SFelipe Balbi int ch; 142550a7375SFelipe Balbi 143550a7375SFelipe Balbi spin_lock_irqsave(&musb->lock, flags); 144550a7375SFelipe Balbi 145550a7375SFelipe Balbi if (tusb_dma->multichannel) 146550a7375SFelipe Balbi ch = chdat->ch; 147550a7375SFelipe Balbi else 148550a7375SFelipe Balbi ch = tusb_dma->ch; 149550a7375SFelipe Balbi 150550a7375SFelipe Balbi if (ch_status != OMAP_DMA_BLOCK_IRQ) 151550a7375SFelipe Balbi printk(KERN_ERR "TUSB DMA error status: %i\n", ch_status); 152550a7375SFelipe Balbi 1535c8a86e1SFelipe Balbi dev_dbg(musb->controller, "ep%i %s dma callback ch: %i status: %x\n", 154550a7375SFelipe Balbi chdat->epnum, chdat->tx ? "tx" : "rx", 155550a7375SFelipe Balbi ch, ch_status); 156550a7375SFelipe Balbi 157550a7375SFelipe Balbi if (chdat->tx) 158550a7375SFelipe Balbi remaining = musb_readl(ep_conf, TUSB_EP_TX_OFFSET); 159550a7375SFelipe Balbi else 160550a7375SFelipe Balbi remaining = musb_readl(ep_conf, TUSB_EP_RX_OFFSET); 161550a7375SFelipe Balbi 162550a7375SFelipe Balbi remaining = TUSB_EP_CONFIG_XFR_SIZE(remaining); 163550a7375SFelipe Balbi 164550a7375SFelipe Balbi /* HW issue #10: XFR_SIZE may get corrupt on DMA (both async & sync) */ 165550a7375SFelipe Balbi if (unlikely(remaining > chdat->transfer_len)) { 1665c8a86e1SFelipe Balbi dev_dbg(musb->controller, "Corrupt %s dma ch%i XFR_SIZE: 0x%08lx\n", 167550a7375SFelipe Balbi chdat->tx ? "tx" : "rx", chdat->ch, 168550a7375SFelipe Balbi remaining); 169550a7375SFelipe Balbi remaining = 0; 170550a7375SFelipe Balbi } 171550a7375SFelipe Balbi 172550a7375SFelipe Balbi channel->actual_len = chdat->transfer_len - remaining; 173550a7375SFelipe Balbi pio = chdat->len - channel->actual_len; 174550a7375SFelipe Balbi 1755c8a86e1SFelipe Balbi dev_dbg(musb->controller, "DMA remaining %lu/%u\n", remaining, chdat->transfer_len); 176550a7375SFelipe Balbi 177550a7375SFelipe Balbi /* Transfer remaining 1 - 31 bytes */ 178550a7375SFelipe Balbi if (pio > 0 && pio < 32) { 179550a7375SFelipe Balbi u8 *buf; 180550a7375SFelipe Balbi 1815c8a86e1SFelipe Balbi dev_dbg(musb->controller, "Using PIO for remaining %lu bytes\n", pio); 182550a7375SFelipe Balbi buf = phys_to_virt((u32)chdat->dma_addr) + chdat->transfer_len; 183550a7375SFelipe Balbi if (chdat->tx) { 1841d0f11b3STony Lindgren dma_unmap_single(dev, chdat->dma_addr, 1851d0f11b3STony Lindgren chdat->transfer_len, 1861d0f11b3STony Lindgren DMA_TO_DEVICE); 187550a7375SFelipe Balbi musb_write_fifo(hw_ep, pio, buf); 188550a7375SFelipe Balbi } else { 1891d0f11b3STony Lindgren dma_unmap_single(dev, chdat->dma_addr, 1901d0f11b3STony Lindgren chdat->transfer_len, 1911d0f11b3STony Lindgren DMA_FROM_DEVICE); 192550a7375SFelipe Balbi musb_read_fifo(hw_ep, pio, buf); 193550a7375SFelipe Balbi } 194550a7375SFelipe Balbi channel->actual_len += pio; 195550a7375SFelipe Balbi } 196550a7375SFelipe Balbi 197550a7375SFelipe Balbi if (!tusb_dma->multichannel) 198550a7375SFelipe Balbi tusb_omap_free_shared_dmareq(chdat); 199550a7375SFelipe Balbi 200550a7375SFelipe Balbi channel->status = MUSB_DMA_STATUS_FREE; 201550a7375SFelipe Balbi 202550a7375SFelipe Balbi /* Handle only RX callbacks here. TX callbacks must be handled based 203550a7375SFelipe Balbi * on the TUSB DMA status interrupt. 204550a7375SFelipe Balbi * REVISIT: Use both TUSB DMA status interrupt and OMAP DMA callback 205550a7375SFelipe Balbi * interrupt for RX and TX. 206550a7375SFelipe Balbi */ 207550a7375SFelipe Balbi if (!chdat->tx) 208550a7375SFelipe Balbi musb_dma_completion(musb, chdat->epnum, chdat->tx); 209550a7375SFelipe Balbi 210550a7375SFelipe Balbi /* We must terminate short tx transfers manually by setting TXPKTRDY. 211550a7375SFelipe Balbi * REVISIT: This same problem may occur with other MUSB dma as well. 212550a7375SFelipe Balbi * Easy to test with g_ether by pinging the MUSB board with ping -s54. 213550a7375SFelipe Balbi */ 214550a7375SFelipe Balbi if ((chdat->transfer_len < chdat->packet_sz) 215550a7375SFelipe Balbi || (chdat->transfer_len % chdat->packet_sz != 0)) { 216550a7375SFelipe Balbi u16 csr; 217550a7375SFelipe Balbi 218550a7375SFelipe Balbi if (chdat->tx) { 2195c8a86e1SFelipe Balbi dev_dbg(musb->controller, "terminating short tx packet\n"); 220550a7375SFelipe Balbi musb_ep_select(mbase, chdat->epnum); 221550a7375SFelipe Balbi csr = musb_readw(hw_ep->regs, MUSB_TXCSR); 222550a7375SFelipe Balbi csr |= MUSB_TXCSR_MODE | MUSB_TXCSR_TXPKTRDY 223550a7375SFelipe Balbi | MUSB_TXCSR_P_WZC_BITS; 224550a7375SFelipe Balbi musb_writew(hw_ep->regs, MUSB_TXCSR, csr); 225550a7375SFelipe Balbi } 226550a7375SFelipe Balbi } 227550a7375SFelipe Balbi 228550a7375SFelipe Balbi spin_unlock_irqrestore(&musb->lock, flags); 229550a7375SFelipe Balbi } 230550a7375SFelipe Balbi 231550a7375SFelipe Balbi static int tusb_omap_dma_program(struct dma_channel *channel, u16 packet_sz, 232550a7375SFelipe Balbi u8 rndis_mode, dma_addr_t dma_addr, u32 len) 233550a7375SFelipe Balbi { 234550a7375SFelipe Balbi struct tusb_omap_dma_ch *chdat = to_chdat(channel); 235550a7375SFelipe Balbi struct tusb_omap_dma *tusb_dma = chdat->tusb_dma; 236550a7375SFelipe Balbi struct musb *musb = chdat->musb; 2371d0f11b3STony Lindgren struct device *dev = musb->controller; 238550a7375SFelipe Balbi struct musb_hw_ep *hw_ep = chdat->hw_ep; 239550a7375SFelipe Balbi void __iomem *mbase = musb->mregs; 240550a7375SFelipe Balbi void __iomem *ep_conf = hw_ep->conf; 241550a7375SFelipe Balbi dma_addr_t fifo = hw_ep->fifo_sync; 242550a7375SFelipe Balbi struct omap_dma_channel_params dma_params; 243550a7375SFelipe Balbi u32 dma_remaining; 244550a7375SFelipe Balbi int src_burst, dst_burst; 245550a7375SFelipe Balbi u16 csr; 246550a7375SFelipe Balbi int ch; 247550a7375SFelipe Balbi s8 dmareq; 248550a7375SFelipe Balbi s8 sync_dev; 249550a7375SFelipe Balbi 250550a7375SFelipe Balbi if (unlikely(dma_addr & 0x1) || (len < 32) || (len > packet_sz)) 251550a7375SFelipe Balbi return false; 252550a7375SFelipe Balbi 253550a7375SFelipe Balbi /* 254550a7375SFelipe Balbi * HW issue #10: Async dma will eventually corrupt the XFR_SIZE 255550a7375SFelipe Balbi * register which will cause missed DMA interrupt. We could try to 256550a7375SFelipe Balbi * use a timer for the callback, but it is unsafe as the XFR_SIZE 257550a7375SFelipe Balbi * register is corrupt, and we won't know if the DMA worked. 258550a7375SFelipe Balbi */ 259550a7375SFelipe Balbi if (dma_addr & 0x2) 260550a7375SFelipe Balbi return false; 261550a7375SFelipe Balbi 262550a7375SFelipe Balbi /* 263550a7375SFelipe Balbi * Because of HW issue #10, it seems like mixing sync DMA and async 264550a7375SFelipe Balbi * PIO access can confuse the DMA. Make sure XFR_SIZE is reset before 265550a7375SFelipe Balbi * using the channel for DMA. 266550a7375SFelipe Balbi */ 267550a7375SFelipe Balbi if (chdat->tx) 268550a7375SFelipe Balbi dma_remaining = musb_readl(ep_conf, TUSB_EP_TX_OFFSET); 269550a7375SFelipe Balbi else 270550a7375SFelipe Balbi dma_remaining = musb_readl(ep_conf, TUSB_EP_RX_OFFSET); 271550a7375SFelipe Balbi 272550a7375SFelipe Balbi dma_remaining = TUSB_EP_CONFIG_XFR_SIZE(dma_remaining); 273550a7375SFelipe Balbi if (dma_remaining) { 2745c8a86e1SFelipe Balbi dev_dbg(musb->controller, "Busy %s dma ch%i, not using: %08x\n", 275550a7375SFelipe Balbi chdat->tx ? "tx" : "rx", chdat->ch, 276550a7375SFelipe Balbi dma_remaining); 277550a7375SFelipe Balbi return false; 278550a7375SFelipe Balbi } 279550a7375SFelipe Balbi 280550a7375SFelipe Balbi chdat->transfer_len = len & ~0x1f; 281550a7375SFelipe Balbi 282550a7375SFelipe Balbi if (len < packet_sz) 283550a7375SFelipe Balbi chdat->transfer_packet_sz = chdat->transfer_len; 284550a7375SFelipe Balbi else 285550a7375SFelipe Balbi chdat->transfer_packet_sz = packet_sz; 286550a7375SFelipe Balbi 287550a7375SFelipe Balbi if (tusb_dma->multichannel) { 288550a7375SFelipe Balbi ch = chdat->ch; 289550a7375SFelipe Balbi dmareq = chdat->dmareq; 290550a7375SFelipe Balbi sync_dev = chdat->sync_dev; 291550a7375SFelipe Balbi } else { 292550a7375SFelipe Balbi if (tusb_omap_use_shared_dmareq(chdat) != 0) { 2935c8a86e1SFelipe Balbi dev_dbg(musb->controller, "could not get dma for ep%i\n", chdat->epnum); 294550a7375SFelipe Balbi return false; 295550a7375SFelipe Balbi } 296550a7375SFelipe Balbi if (tusb_dma->ch < 0) { 297550a7375SFelipe Balbi /* REVISIT: This should get blocked earlier, happens 298550a7375SFelipe Balbi * with MSC ErrorRecoveryTest 299550a7375SFelipe Balbi */ 300550a7375SFelipe Balbi WARN_ON(1); 301550a7375SFelipe Balbi return false; 302550a7375SFelipe Balbi } 303550a7375SFelipe Balbi 304550a7375SFelipe Balbi ch = tusb_dma->ch; 305550a7375SFelipe Balbi dmareq = tusb_dma->dmareq; 306550a7375SFelipe Balbi sync_dev = tusb_dma->sync_dev; 307550a7375SFelipe Balbi omap_set_dma_callback(ch, tusb_omap_dma_cb, channel); 308550a7375SFelipe Balbi } 309550a7375SFelipe Balbi 310550a7375SFelipe Balbi chdat->packet_sz = packet_sz; 311550a7375SFelipe Balbi chdat->len = len; 312550a7375SFelipe Balbi channel->actual_len = 0; 3131d0f11b3STony Lindgren chdat->dma_addr = dma_addr; 314550a7375SFelipe Balbi channel->status = MUSB_DMA_STATUS_BUSY; 315550a7375SFelipe Balbi 316550a7375SFelipe Balbi /* Since we're recycling dma areas, we need to clean or invalidate */ 317550a7375SFelipe Balbi if (chdat->tx) 3181d0f11b3STony Lindgren dma_map_single(dev, phys_to_virt(dma_addr), len, 3191d0f11b3STony Lindgren DMA_TO_DEVICE); 320550a7375SFelipe Balbi else 3211d0f11b3STony Lindgren dma_map_single(dev, phys_to_virt(dma_addr), len, 3221d0f11b3STony Lindgren DMA_FROM_DEVICE); 323550a7375SFelipe Balbi 324550a7375SFelipe Balbi /* Use 16-bit transfer if dma_addr is not 32-bit aligned */ 325550a7375SFelipe Balbi if ((dma_addr & 0x3) == 0) { 326550a7375SFelipe Balbi dma_params.data_type = OMAP_DMA_DATA_TYPE_S32; 327550a7375SFelipe Balbi dma_params.elem_count = 8; /* Elements in frame */ 328550a7375SFelipe Balbi } else { 329550a7375SFelipe Balbi dma_params.data_type = OMAP_DMA_DATA_TYPE_S16; 330550a7375SFelipe Balbi dma_params.elem_count = 16; /* Elements in frame */ 331550a7375SFelipe Balbi fifo = hw_ep->fifo_async; 332550a7375SFelipe Balbi } 333550a7375SFelipe Balbi 334550a7375SFelipe Balbi dma_params.frame_count = chdat->transfer_len / 32; /* Burst sz frame */ 335550a7375SFelipe Balbi 3365c8a86e1SFelipe Balbi dev_dbg(musb->controller, "ep%i %s dma ch%i dma: %08x len: %u(%u) packet_sz: %i(%i)\n", 337550a7375SFelipe Balbi chdat->epnum, chdat->tx ? "tx" : "rx", 338550a7375SFelipe Balbi ch, dma_addr, chdat->transfer_len, len, 339550a7375SFelipe Balbi chdat->transfer_packet_sz, packet_sz); 340550a7375SFelipe Balbi 341550a7375SFelipe Balbi /* 342550a7375SFelipe Balbi * Prepare omap DMA for transfer 343550a7375SFelipe Balbi */ 344550a7375SFelipe Balbi if (chdat->tx) { 345550a7375SFelipe Balbi dma_params.src_amode = OMAP_DMA_AMODE_POST_INC; 346550a7375SFelipe Balbi dma_params.src_start = (unsigned long)dma_addr; 347550a7375SFelipe Balbi dma_params.src_ei = 0; 348550a7375SFelipe Balbi dma_params.src_fi = 0; 349550a7375SFelipe Balbi 350550a7375SFelipe Balbi dma_params.dst_amode = OMAP_DMA_AMODE_DOUBLE_IDX; 351550a7375SFelipe Balbi dma_params.dst_start = (unsigned long)fifo; 352550a7375SFelipe Balbi dma_params.dst_ei = 1; 353550a7375SFelipe Balbi dma_params.dst_fi = -31; /* Loop 32 byte window */ 354550a7375SFelipe Balbi 355550a7375SFelipe Balbi dma_params.trigger = sync_dev; 356550a7375SFelipe Balbi dma_params.sync_mode = OMAP_DMA_SYNC_FRAME; 357550a7375SFelipe Balbi dma_params.src_or_dst_synch = 0; /* Dest sync */ 358550a7375SFelipe Balbi 359550a7375SFelipe Balbi src_burst = OMAP_DMA_DATA_BURST_16; /* 16x32 read */ 360550a7375SFelipe Balbi dst_burst = OMAP_DMA_DATA_BURST_8; /* 8x32 write */ 361550a7375SFelipe Balbi } else { 362550a7375SFelipe Balbi dma_params.src_amode = OMAP_DMA_AMODE_DOUBLE_IDX; 363550a7375SFelipe Balbi dma_params.src_start = (unsigned long)fifo; 364550a7375SFelipe Balbi dma_params.src_ei = 1; 365550a7375SFelipe Balbi dma_params.src_fi = -31; /* Loop 32 byte window */ 366550a7375SFelipe Balbi 367550a7375SFelipe Balbi dma_params.dst_amode = OMAP_DMA_AMODE_POST_INC; 368550a7375SFelipe Balbi dma_params.dst_start = (unsigned long)dma_addr; 369550a7375SFelipe Balbi dma_params.dst_ei = 0; 370550a7375SFelipe Balbi dma_params.dst_fi = 0; 371550a7375SFelipe Balbi 372550a7375SFelipe Balbi dma_params.trigger = sync_dev; 373550a7375SFelipe Balbi dma_params.sync_mode = OMAP_DMA_SYNC_FRAME; 374550a7375SFelipe Balbi dma_params.src_or_dst_synch = 1; /* Source sync */ 375550a7375SFelipe Balbi 376550a7375SFelipe Balbi src_burst = OMAP_DMA_DATA_BURST_8; /* 8x32 read */ 377550a7375SFelipe Balbi dst_burst = OMAP_DMA_DATA_BURST_16; /* 16x32 write */ 378550a7375SFelipe Balbi } 379550a7375SFelipe Balbi 3805c8a86e1SFelipe Balbi dev_dbg(musb->controller, "ep%i %s using %i-bit %s dma from 0x%08lx to 0x%08lx\n", 381550a7375SFelipe Balbi chdat->epnum, chdat->tx ? "tx" : "rx", 382550a7375SFelipe Balbi (dma_params.data_type == OMAP_DMA_DATA_TYPE_S32) ? 32 : 16, 383550a7375SFelipe Balbi ((dma_addr & 0x3) == 0) ? "sync" : "async", 384550a7375SFelipe Balbi dma_params.src_start, dma_params.dst_start); 385550a7375SFelipe Balbi 386550a7375SFelipe Balbi omap_set_dma_params(ch, &dma_params); 387550a7375SFelipe Balbi omap_set_dma_src_burst_mode(ch, src_burst); 388550a7375SFelipe Balbi omap_set_dma_dest_burst_mode(ch, dst_burst); 389550a7375SFelipe Balbi omap_set_dma_write_mode(ch, OMAP_DMA_WRITE_LAST_NON_POSTED); 390550a7375SFelipe Balbi 391550a7375SFelipe Balbi /* 392550a7375SFelipe Balbi * Prepare MUSB for DMA transfer 393550a7375SFelipe Balbi */ 394550a7375SFelipe Balbi if (chdat->tx) { 395550a7375SFelipe Balbi musb_ep_select(mbase, chdat->epnum); 396550a7375SFelipe Balbi csr = musb_readw(hw_ep->regs, MUSB_TXCSR); 397550a7375SFelipe Balbi csr |= (MUSB_TXCSR_AUTOSET | MUSB_TXCSR_DMAENAB 398550a7375SFelipe Balbi | MUSB_TXCSR_DMAMODE | MUSB_TXCSR_MODE); 399550a7375SFelipe Balbi csr &= ~MUSB_TXCSR_P_UNDERRUN; 400550a7375SFelipe Balbi musb_writew(hw_ep->regs, MUSB_TXCSR, csr); 401550a7375SFelipe Balbi } else { 402550a7375SFelipe Balbi musb_ep_select(mbase, chdat->epnum); 403550a7375SFelipe Balbi csr = musb_readw(hw_ep->regs, MUSB_RXCSR); 404550a7375SFelipe Balbi csr |= MUSB_RXCSR_DMAENAB; 405550a7375SFelipe Balbi csr &= ~(MUSB_RXCSR_AUTOCLEAR | MUSB_RXCSR_DMAMODE); 406550a7375SFelipe Balbi musb_writew(hw_ep->regs, MUSB_RXCSR, 407550a7375SFelipe Balbi csr | MUSB_RXCSR_P_WZC_BITS); 408550a7375SFelipe Balbi } 409550a7375SFelipe Balbi 410550a7375SFelipe Balbi /* 411550a7375SFelipe Balbi * Start DMA transfer 412550a7375SFelipe Balbi */ 413550a7375SFelipe Balbi omap_start_dma(ch); 414550a7375SFelipe Balbi 415550a7375SFelipe Balbi if (chdat->tx) { 416550a7375SFelipe Balbi /* Send transfer_packet_sz packets at a time */ 417550a7375SFelipe Balbi musb_writel(ep_conf, TUSB_EP_MAX_PACKET_SIZE_OFFSET, 418550a7375SFelipe Balbi chdat->transfer_packet_sz); 419550a7375SFelipe Balbi 420550a7375SFelipe Balbi musb_writel(ep_conf, TUSB_EP_TX_OFFSET, 421550a7375SFelipe Balbi TUSB_EP_CONFIG_XFR_SIZE(chdat->transfer_len)); 422550a7375SFelipe Balbi } else { 423550a7375SFelipe Balbi /* Receive transfer_packet_sz packets at a time */ 424550a7375SFelipe Balbi musb_writel(ep_conf, TUSB_EP_MAX_PACKET_SIZE_OFFSET, 425550a7375SFelipe Balbi chdat->transfer_packet_sz << 16); 426550a7375SFelipe Balbi 427550a7375SFelipe Balbi musb_writel(ep_conf, TUSB_EP_RX_OFFSET, 428550a7375SFelipe Balbi TUSB_EP_CONFIG_XFR_SIZE(chdat->transfer_len)); 429550a7375SFelipe Balbi } 430550a7375SFelipe Balbi 431550a7375SFelipe Balbi return true; 432550a7375SFelipe Balbi } 433550a7375SFelipe Balbi 434550a7375SFelipe Balbi static int tusb_omap_dma_abort(struct dma_channel *channel) 435550a7375SFelipe Balbi { 436550a7375SFelipe Balbi struct tusb_omap_dma_ch *chdat = to_chdat(channel); 437550a7375SFelipe Balbi struct tusb_omap_dma *tusb_dma = chdat->tusb_dma; 438550a7375SFelipe Balbi 439550a7375SFelipe Balbi if (!tusb_dma->multichannel) { 440550a7375SFelipe Balbi if (tusb_dma->ch >= 0) { 441550a7375SFelipe Balbi omap_stop_dma(tusb_dma->ch); 442550a7375SFelipe Balbi omap_free_dma(tusb_dma->ch); 443550a7375SFelipe Balbi tusb_dma->ch = -1; 444550a7375SFelipe Balbi } 445550a7375SFelipe Balbi 446550a7375SFelipe Balbi tusb_dma->dmareq = -1; 447550a7375SFelipe Balbi tusb_dma->sync_dev = -1; 448550a7375SFelipe Balbi } 449550a7375SFelipe Balbi 450550a7375SFelipe Balbi channel->status = MUSB_DMA_STATUS_FREE; 451550a7375SFelipe Balbi 452550a7375SFelipe Balbi return 0; 453550a7375SFelipe Balbi } 454550a7375SFelipe Balbi 455550a7375SFelipe Balbi static inline int tusb_omap_dma_allocate_dmareq(struct tusb_omap_dma_ch *chdat) 456550a7375SFelipe Balbi { 457550a7375SFelipe Balbi u32 reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP); 458550a7375SFelipe Balbi int i, dmareq_nr = -1; 459550a7375SFelipe Balbi 460550a7375SFelipe Balbi const int sync_dev[6] = { 461550a7375SFelipe Balbi OMAP24XX_DMA_EXT_DMAREQ0, 462550a7375SFelipe Balbi OMAP24XX_DMA_EXT_DMAREQ1, 463550a7375SFelipe Balbi OMAP242X_DMA_EXT_DMAREQ2, 464550a7375SFelipe Balbi OMAP242X_DMA_EXT_DMAREQ3, 465550a7375SFelipe Balbi OMAP242X_DMA_EXT_DMAREQ4, 466550a7375SFelipe Balbi OMAP242X_DMA_EXT_DMAREQ5, 467550a7375SFelipe Balbi }; 468550a7375SFelipe Balbi 469550a7375SFelipe Balbi for (i = 0; i < MAX_DMAREQ; i++) { 470550a7375SFelipe Balbi int cur = (reg & (0xf << (i * 5))) >> (i * 5); 471550a7375SFelipe Balbi if (cur == 0) { 472550a7375SFelipe Balbi dmareq_nr = i; 473550a7375SFelipe Balbi break; 474550a7375SFelipe Balbi } 475550a7375SFelipe Balbi } 476550a7375SFelipe Balbi 477550a7375SFelipe Balbi if (dmareq_nr == -1) 478550a7375SFelipe Balbi return -EAGAIN; 479550a7375SFelipe Balbi 480550a7375SFelipe Balbi reg |= (chdat->epnum << (dmareq_nr * 5)); 481550a7375SFelipe Balbi if (chdat->tx) 482550a7375SFelipe Balbi reg |= ((1 << 4) << (dmareq_nr * 5)); 483550a7375SFelipe Balbi musb_writel(chdat->tbase, TUSB_DMA_EP_MAP, reg); 484550a7375SFelipe Balbi 485550a7375SFelipe Balbi chdat->dmareq = dmareq_nr; 486550a7375SFelipe Balbi chdat->sync_dev = sync_dev[chdat->dmareq]; 487550a7375SFelipe Balbi 488550a7375SFelipe Balbi return 0; 489550a7375SFelipe Balbi } 490550a7375SFelipe Balbi 491550a7375SFelipe Balbi static inline void tusb_omap_dma_free_dmareq(struct tusb_omap_dma_ch *chdat) 492550a7375SFelipe Balbi { 493550a7375SFelipe Balbi u32 reg; 494550a7375SFelipe Balbi 495550a7375SFelipe Balbi if (!chdat || chdat->dmareq < 0) 496550a7375SFelipe Balbi return; 497550a7375SFelipe Balbi 498550a7375SFelipe Balbi reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP); 499550a7375SFelipe Balbi reg &= ~(0x1f << (chdat->dmareq * 5)); 500550a7375SFelipe Balbi musb_writel(chdat->tbase, TUSB_DMA_EP_MAP, reg); 501550a7375SFelipe Balbi 502550a7375SFelipe Balbi chdat->dmareq = -1; 503550a7375SFelipe Balbi chdat->sync_dev = -1; 504550a7375SFelipe Balbi } 505550a7375SFelipe Balbi 506550a7375SFelipe Balbi static struct dma_channel *dma_channel_pool[MAX_DMAREQ]; 507550a7375SFelipe Balbi 508550a7375SFelipe Balbi static struct dma_channel * 509550a7375SFelipe Balbi tusb_omap_dma_allocate(struct dma_controller *c, 510550a7375SFelipe Balbi struct musb_hw_ep *hw_ep, 511550a7375SFelipe Balbi u8 tx) 512550a7375SFelipe Balbi { 513550a7375SFelipe Balbi int ret, i; 514550a7375SFelipe Balbi const char *dev_name; 515550a7375SFelipe Balbi struct tusb_omap_dma *tusb_dma; 516550a7375SFelipe Balbi struct musb *musb; 517550a7375SFelipe Balbi void __iomem *tbase; 518550a7375SFelipe Balbi struct dma_channel *channel = NULL; 519550a7375SFelipe Balbi struct tusb_omap_dma_ch *chdat = NULL; 520550a7375SFelipe Balbi u32 reg; 521550a7375SFelipe Balbi 522550a7375SFelipe Balbi tusb_dma = container_of(c, struct tusb_omap_dma, controller); 523550a7375SFelipe Balbi musb = tusb_dma->musb; 524550a7375SFelipe Balbi tbase = musb->ctrl_base; 525550a7375SFelipe Balbi 526550a7375SFelipe Balbi reg = musb_readl(tbase, TUSB_DMA_INT_MASK); 527550a7375SFelipe Balbi if (tx) 528550a7375SFelipe Balbi reg &= ~(1 << hw_ep->epnum); 529550a7375SFelipe Balbi else 530550a7375SFelipe Balbi reg &= ~(1 << (hw_ep->epnum + 15)); 531550a7375SFelipe Balbi musb_writel(tbase, TUSB_DMA_INT_MASK, reg); 532550a7375SFelipe Balbi 533550a7375SFelipe Balbi /* REVISIT: Why does dmareq5 not work? */ 534550a7375SFelipe Balbi if (hw_ep->epnum == 0) { 5355c8a86e1SFelipe Balbi dev_dbg(musb->controller, "Not allowing DMA for ep0 %s\n", tx ? "tx" : "rx"); 536550a7375SFelipe Balbi return NULL; 537550a7375SFelipe Balbi } 538550a7375SFelipe Balbi 539550a7375SFelipe Balbi for (i = 0; i < MAX_DMAREQ; i++) { 540550a7375SFelipe Balbi struct dma_channel *ch = dma_channel_pool[i]; 541550a7375SFelipe Balbi if (ch->status == MUSB_DMA_STATUS_UNKNOWN) { 542550a7375SFelipe Balbi ch->status = MUSB_DMA_STATUS_FREE; 543550a7375SFelipe Balbi channel = ch; 544550a7375SFelipe Balbi chdat = ch->private_data; 545550a7375SFelipe Balbi break; 546550a7375SFelipe Balbi } 547550a7375SFelipe Balbi } 548550a7375SFelipe Balbi 549550a7375SFelipe Balbi if (!channel) 550550a7375SFelipe Balbi return NULL; 551550a7375SFelipe Balbi 552550a7375SFelipe Balbi if (tx) { 553550a7375SFelipe Balbi chdat->tx = 1; 554550a7375SFelipe Balbi dev_name = "TUSB transmit"; 555550a7375SFelipe Balbi } else { 556550a7375SFelipe Balbi chdat->tx = 0; 557550a7375SFelipe Balbi dev_name = "TUSB receive"; 558550a7375SFelipe Balbi } 559550a7375SFelipe Balbi 560550a7375SFelipe Balbi chdat->musb = tusb_dma->musb; 561550a7375SFelipe Balbi chdat->tbase = tusb_dma->tbase; 562550a7375SFelipe Balbi chdat->hw_ep = hw_ep; 563550a7375SFelipe Balbi chdat->epnum = hw_ep->epnum; 564550a7375SFelipe Balbi chdat->dmareq = -1; 565550a7375SFelipe Balbi chdat->completed_len = 0; 566550a7375SFelipe Balbi chdat->tusb_dma = tusb_dma; 567550a7375SFelipe Balbi 568550a7375SFelipe Balbi channel->max_len = 0x7fffffff; 569550a7375SFelipe Balbi channel->desired_mode = 0; 570550a7375SFelipe Balbi channel->actual_len = 0; 571550a7375SFelipe Balbi 572550a7375SFelipe Balbi if (tusb_dma->multichannel) { 573550a7375SFelipe Balbi ret = tusb_omap_dma_allocate_dmareq(chdat); 574550a7375SFelipe Balbi if (ret != 0) 575550a7375SFelipe Balbi goto free_dmareq; 576550a7375SFelipe Balbi 577550a7375SFelipe Balbi ret = omap_request_dma(chdat->sync_dev, dev_name, 578550a7375SFelipe Balbi tusb_omap_dma_cb, channel, &chdat->ch); 579550a7375SFelipe Balbi if (ret != 0) 580550a7375SFelipe Balbi goto free_dmareq; 581550a7375SFelipe Balbi } else if (tusb_dma->ch == -1) { 582550a7375SFelipe Balbi tusb_dma->dmareq = 0; 583550a7375SFelipe Balbi tusb_dma->sync_dev = OMAP24XX_DMA_EXT_DMAREQ0; 584550a7375SFelipe Balbi 585550a7375SFelipe Balbi /* Callback data gets set later in the shared dmareq case */ 586550a7375SFelipe Balbi ret = omap_request_dma(tusb_dma->sync_dev, "TUSB shared", 587550a7375SFelipe Balbi tusb_omap_dma_cb, NULL, &tusb_dma->ch); 588550a7375SFelipe Balbi if (ret != 0) 589550a7375SFelipe Balbi goto free_dmareq; 590550a7375SFelipe Balbi 591550a7375SFelipe Balbi chdat->dmareq = -1; 592550a7375SFelipe Balbi chdat->ch = -1; 593550a7375SFelipe Balbi } 594550a7375SFelipe Balbi 5955c8a86e1SFelipe Balbi dev_dbg(musb->controller, "ep%i %s dma: %s dma%i dmareq%i sync%i\n", 596550a7375SFelipe Balbi chdat->epnum, 597550a7375SFelipe Balbi chdat->tx ? "tx" : "rx", 598550a7375SFelipe Balbi chdat->ch >= 0 ? "dedicated" : "shared", 599550a7375SFelipe Balbi chdat->ch >= 0 ? chdat->ch : tusb_dma->ch, 600550a7375SFelipe Balbi chdat->dmareq >= 0 ? chdat->dmareq : tusb_dma->dmareq, 601550a7375SFelipe Balbi chdat->sync_dev >= 0 ? chdat->sync_dev : tusb_dma->sync_dev); 602550a7375SFelipe Balbi 603550a7375SFelipe Balbi return channel; 604550a7375SFelipe Balbi 605550a7375SFelipe Balbi free_dmareq: 606550a7375SFelipe Balbi tusb_omap_dma_free_dmareq(chdat); 607550a7375SFelipe Balbi 6085c8a86e1SFelipe Balbi dev_dbg(musb->controller, "ep%i: Could not get a DMA channel\n", chdat->epnum); 609550a7375SFelipe Balbi channel->status = MUSB_DMA_STATUS_UNKNOWN; 610550a7375SFelipe Balbi 611550a7375SFelipe Balbi return NULL; 612550a7375SFelipe Balbi } 613550a7375SFelipe Balbi 614550a7375SFelipe Balbi static void tusb_omap_dma_release(struct dma_channel *channel) 615550a7375SFelipe Balbi { 616550a7375SFelipe Balbi struct tusb_omap_dma_ch *chdat = to_chdat(channel); 617550a7375SFelipe Balbi struct musb *musb = chdat->musb; 618550a7375SFelipe Balbi void __iomem *tbase = musb->ctrl_base; 619550a7375SFelipe Balbi u32 reg; 620550a7375SFelipe Balbi 6215c8a86e1SFelipe Balbi dev_dbg(musb->controller, "ep%i ch%i\n", chdat->epnum, chdat->ch); 622550a7375SFelipe Balbi 623550a7375SFelipe Balbi reg = musb_readl(tbase, TUSB_DMA_INT_MASK); 624550a7375SFelipe Balbi if (chdat->tx) 625550a7375SFelipe Balbi reg |= (1 << chdat->epnum); 626550a7375SFelipe Balbi else 627550a7375SFelipe Balbi reg |= (1 << (chdat->epnum + 15)); 628550a7375SFelipe Balbi musb_writel(tbase, TUSB_DMA_INT_MASK, reg); 629550a7375SFelipe Balbi 630550a7375SFelipe Balbi reg = musb_readl(tbase, TUSB_DMA_INT_CLEAR); 631550a7375SFelipe Balbi if (chdat->tx) 632550a7375SFelipe Balbi reg |= (1 << chdat->epnum); 633550a7375SFelipe Balbi else 634550a7375SFelipe Balbi reg |= (1 << (chdat->epnum + 15)); 635550a7375SFelipe Balbi musb_writel(tbase, TUSB_DMA_INT_CLEAR, reg); 636550a7375SFelipe Balbi 637550a7375SFelipe Balbi channel->status = MUSB_DMA_STATUS_UNKNOWN; 638550a7375SFelipe Balbi 639550a7375SFelipe Balbi if (chdat->ch >= 0) { 640550a7375SFelipe Balbi omap_stop_dma(chdat->ch); 641550a7375SFelipe Balbi omap_free_dma(chdat->ch); 642550a7375SFelipe Balbi chdat->ch = -1; 643550a7375SFelipe Balbi } 644550a7375SFelipe Balbi 645550a7375SFelipe Balbi if (chdat->dmareq >= 0) 646550a7375SFelipe Balbi tusb_omap_dma_free_dmareq(chdat); 647550a7375SFelipe Balbi 648550a7375SFelipe Balbi channel = NULL; 649550a7375SFelipe Balbi } 650550a7375SFelipe Balbi 651550a7375SFelipe Balbi void dma_controller_destroy(struct dma_controller *c) 652550a7375SFelipe Balbi { 653550a7375SFelipe Balbi struct tusb_omap_dma *tusb_dma; 654550a7375SFelipe Balbi int i; 655550a7375SFelipe Balbi 656550a7375SFelipe Balbi tusb_dma = container_of(c, struct tusb_omap_dma, controller); 657550a7375SFelipe Balbi for (i = 0; i < MAX_DMAREQ; i++) { 658550a7375SFelipe Balbi struct dma_channel *ch = dma_channel_pool[i]; 659550a7375SFelipe Balbi if (ch) { 660550a7375SFelipe Balbi kfree(ch->private_data); 661550a7375SFelipe Balbi kfree(ch); 662550a7375SFelipe Balbi } 663550a7375SFelipe Balbi } 664550a7375SFelipe Balbi 66594089d56SRoel Kluin if (tusb_dma && !tusb_dma->multichannel && tusb_dma->ch >= 0) 666550a7375SFelipe Balbi omap_free_dma(tusb_dma->ch); 667550a7375SFelipe Balbi 668550a7375SFelipe Balbi kfree(tusb_dma); 669550a7375SFelipe Balbi } 670550a7375SFelipe Balbi 67107a67bbbSShubhrajyoti D struct dma_controller *__devinit 672550a7375SFelipe Balbi dma_controller_create(struct musb *musb, void __iomem *base) 673550a7375SFelipe Balbi { 674550a7375SFelipe Balbi void __iomem *tbase = musb->ctrl_base; 675550a7375SFelipe Balbi struct tusb_omap_dma *tusb_dma; 676550a7375SFelipe Balbi int i; 677550a7375SFelipe Balbi 678550a7375SFelipe Balbi /* REVISIT: Get dmareq lines used from board-*.c */ 679550a7375SFelipe Balbi 680550a7375SFelipe Balbi musb_writel(musb->ctrl_base, TUSB_DMA_INT_MASK, 0x7fffffff); 681550a7375SFelipe Balbi musb_writel(musb->ctrl_base, TUSB_DMA_EP_MAP, 0); 682550a7375SFelipe Balbi 683550a7375SFelipe Balbi musb_writel(tbase, TUSB_DMA_REQ_CONF, 684550a7375SFelipe Balbi TUSB_DMA_REQ_CONF_BURST_SIZE(2) 685550a7375SFelipe Balbi | TUSB_DMA_REQ_CONF_DMA_REQ_EN(0x3f) 686550a7375SFelipe Balbi | TUSB_DMA_REQ_CONF_DMA_REQ_ASSER(2)); 687550a7375SFelipe Balbi 688550a7375SFelipe Balbi tusb_dma = kzalloc(sizeof(struct tusb_omap_dma), GFP_KERNEL); 689550a7375SFelipe Balbi if (!tusb_dma) 690c88ba39cSHuzaifa Sidhpurwala goto out; 691550a7375SFelipe Balbi 692550a7375SFelipe Balbi tusb_dma->musb = musb; 693550a7375SFelipe Balbi tusb_dma->tbase = musb->ctrl_base; 694550a7375SFelipe Balbi 695550a7375SFelipe Balbi tusb_dma->ch = -1; 696550a7375SFelipe Balbi tusb_dma->dmareq = -1; 697550a7375SFelipe Balbi tusb_dma->sync_dev = -1; 698550a7375SFelipe Balbi 699550a7375SFelipe Balbi tusb_dma->controller.start = tusb_omap_dma_start; 700550a7375SFelipe Balbi tusb_dma->controller.stop = tusb_omap_dma_stop; 701550a7375SFelipe Balbi tusb_dma->controller.channel_alloc = tusb_omap_dma_allocate; 702550a7375SFelipe Balbi tusb_dma->controller.channel_release = tusb_omap_dma_release; 703550a7375SFelipe Balbi tusb_dma->controller.channel_program = tusb_omap_dma_program; 704550a7375SFelipe Balbi tusb_dma->controller.channel_abort = tusb_omap_dma_abort; 705550a7375SFelipe Balbi 706550a7375SFelipe Balbi if (tusb_get_revision(musb) >= TUSB_REV_30) 707550a7375SFelipe Balbi tusb_dma->multichannel = 1; 708550a7375SFelipe Balbi 709550a7375SFelipe Balbi for (i = 0; i < MAX_DMAREQ; i++) { 710550a7375SFelipe Balbi struct dma_channel *ch; 711550a7375SFelipe Balbi struct tusb_omap_dma_ch *chdat; 712550a7375SFelipe Balbi 713550a7375SFelipe Balbi ch = kzalloc(sizeof(struct dma_channel), GFP_KERNEL); 714550a7375SFelipe Balbi if (!ch) 715550a7375SFelipe Balbi goto cleanup; 716550a7375SFelipe Balbi 717550a7375SFelipe Balbi dma_channel_pool[i] = ch; 718550a7375SFelipe Balbi 719550a7375SFelipe Balbi chdat = kzalloc(sizeof(struct tusb_omap_dma_ch), GFP_KERNEL); 720550a7375SFelipe Balbi if (!chdat) 721550a7375SFelipe Balbi goto cleanup; 722550a7375SFelipe Balbi 723550a7375SFelipe Balbi ch->status = MUSB_DMA_STATUS_UNKNOWN; 724550a7375SFelipe Balbi ch->private_data = chdat; 725550a7375SFelipe Balbi } 726550a7375SFelipe Balbi 727550a7375SFelipe Balbi return &tusb_dma->controller; 728550a7375SFelipe Balbi 729550a7375SFelipe Balbi cleanup: 730550a7375SFelipe Balbi dma_controller_destroy(&tusb_dma->controller); 731c88ba39cSHuzaifa Sidhpurwala out: 732550a7375SFelipe Balbi return NULL; 733550a7375SFelipe Balbi } 734