Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 1 | /* |
| 2 | * TUSB6010 USB 2.0 OTG Dual Role controller OMAP DMA interface |
| 3 | * |
| 4 | * Copyright (C) 2006 Nokia Corporation |
| 5 | * Tony Lindgren <tony@atomide.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/errno.h> |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 14 | #include <linux/usb.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/dma-mapping.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Tony Lindgren | 45c3eb7 | 2012-11-30 08:41:50 -0800 | [diff] [blame] | 18 | #include <linux/omap-dma.h> |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 19 | |
| 20 | #include "musb_core.h" |
Felipe Balbi | 240a16e | 2011-08-05 13:29:49 +0300 | [diff] [blame] | 21 | #include "tusb6010.h" |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 22 | |
| 23 | #define to_chdat(c) ((struct tusb_omap_dma_ch *)(c)->private_data) |
| 24 | |
| 25 | #define MAX_DMAREQ 5 /* REVISIT: Really 6, but req5 not OK */ |
| 26 | |
Lokesh Vutla | d5e7c86 | 2012-10-15 14:03:51 -0700 | [diff] [blame] | 27 | #define OMAP24XX_DMA_EXT_DMAREQ0 2 |
| 28 | #define OMAP24XX_DMA_EXT_DMAREQ1 3 |
| 29 | #define OMAP242X_DMA_EXT_DMAREQ2 14 |
| 30 | #define OMAP242X_DMA_EXT_DMAREQ3 15 |
| 31 | #define OMAP242X_DMA_EXT_DMAREQ4 16 |
| 32 | #define OMAP242X_DMA_EXT_DMAREQ5 64 |
| 33 | |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 34 | struct tusb_dma_data { |
| 35 | int ch; |
| 36 | s8 dmareq; |
| 37 | s8 sync_dev; |
| 38 | }; |
| 39 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 40 | struct tusb_omap_dma_ch { |
| 41 | struct musb *musb; |
| 42 | void __iomem *tbase; |
| 43 | unsigned long phys_offset; |
| 44 | int epnum; |
| 45 | u8 tx; |
| 46 | struct musb_hw_ep *hw_ep; |
| 47 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 48 | struct tusb_dma_data *dma_data; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 49 | |
| 50 | struct tusb_omap_dma *tusb_dma; |
| 51 | |
Tony Lindgren | 1d0f11b | 2010-04-23 17:41:15 -0700 | [diff] [blame] | 52 | dma_addr_t dma_addr; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 53 | |
| 54 | u32 len; |
| 55 | u16 packet_sz; |
| 56 | u16 transfer_packet_sz; |
| 57 | u32 transfer_len; |
| 58 | u32 completed_len; |
| 59 | }; |
| 60 | |
| 61 | struct tusb_omap_dma { |
| 62 | struct dma_controller controller; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 63 | void __iomem *tbase; |
| 64 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 65 | struct tusb_dma_data dma_pool[MAX_DMAREQ]; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 66 | unsigned multichannel:1; |
| 67 | }; |
| 68 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 69 | /* |
| 70 | * Allocate dmareq0 to the current channel unless it's already taken |
| 71 | */ |
| 72 | static inline int tusb_omap_use_shared_dmareq(struct tusb_omap_dma_ch *chdat) |
| 73 | { |
| 74 | u32 reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP); |
| 75 | |
| 76 | if (reg != 0) { |
Sergei Trofimovich | 74c6f3a | 2011-07-17 18:28:00 +0300 | [diff] [blame] | 77 | dev_dbg(chdat->musb->controller, "ep%i dmareq0 is busy for ep%i\n", |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 78 | chdat->epnum, reg & 0xf); |
| 79 | return -EAGAIN; |
| 80 | } |
| 81 | |
| 82 | if (chdat->tx) |
| 83 | reg = (1 << 4) | chdat->epnum; |
| 84 | else |
| 85 | reg = chdat->epnum; |
| 86 | |
| 87 | musb_writel(chdat->tbase, TUSB_DMA_EP_MAP, reg); |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | static inline void tusb_omap_free_shared_dmareq(struct tusb_omap_dma_ch *chdat) |
| 93 | { |
| 94 | u32 reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP); |
| 95 | |
| 96 | if ((reg & 0xf) != chdat->epnum) { |
| 97 | printk(KERN_ERR "ep%i trying to release dmareq0 for ep%i\n", |
| 98 | chdat->epnum, reg & 0xf); |
| 99 | return; |
| 100 | } |
| 101 | musb_writel(chdat->tbase, TUSB_DMA_EP_MAP, 0); |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * See also musb_dma_completion in plat_uds.c and musb_g_[tx|rx]() in |
| 106 | * musb_gadget.c. |
| 107 | */ |
| 108 | static void tusb_omap_dma_cb(int lch, u16 ch_status, void *data) |
| 109 | { |
| 110 | struct dma_channel *channel = (struct dma_channel *)data; |
| 111 | struct tusb_omap_dma_ch *chdat = to_chdat(channel); |
| 112 | struct tusb_omap_dma *tusb_dma = chdat->tusb_dma; |
| 113 | struct musb *musb = chdat->musb; |
Tony Lindgren | 1d0f11b | 2010-04-23 17:41:15 -0700 | [diff] [blame] | 114 | struct device *dev = musb->controller; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 115 | struct musb_hw_ep *hw_ep = chdat->hw_ep; |
| 116 | void __iomem *ep_conf = hw_ep->conf; |
| 117 | void __iomem *mbase = musb->mregs; |
| 118 | unsigned long remaining, flags, pio; |
| 119 | int ch; |
| 120 | |
| 121 | spin_lock_irqsave(&musb->lock, flags); |
| 122 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 123 | ch = chdat->dma_data->ch; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 124 | |
| 125 | if (ch_status != OMAP_DMA_BLOCK_IRQ) |
| 126 | printk(KERN_ERR "TUSB DMA error status: %i\n", ch_status); |
| 127 | |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 128 | dev_dbg(musb->controller, "ep%i %s dma callback ch: %i status: %x\n", |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 129 | chdat->epnum, chdat->tx ? "tx" : "rx", |
| 130 | ch, ch_status); |
| 131 | |
| 132 | if (chdat->tx) |
| 133 | remaining = musb_readl(ep_conf, TUSB_EP_TX_OFFSET); |
| 134 | else |
| 135 | remaining = musb_readl(ep_conf, TUSB_EP_RX_OFFSET); |
| 136 | |
| 137 | remaining = TUSB_EP_CONFIG_XFR_SIZE(remaining); |
| 138 | |
| 139 | /* HW issue #10: XFR_SIZE may get corrupt on DMA (both async & sync) */ |
| 140 | if (unlikely(remaining > chdat->transfer_len)) { |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 141 | dev_dbg(musb->controller, "Corrupt %s dma ch%i XFR_SIZE: 0x%08lx\n", |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 142 | chdat->tx ? "tx" : "rx", ch, remaining); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 143 | remaining = 0; |
| 144 | } |
| 145 | |
| 146 | channel->actual_len = chdat->transfer_len - remaining; |
| 147 | pio = chdat->len - channel->actual_len; |
| 148 | |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 149 | dev_dbg(musb->controller, "DMA remaining %lu/%u\n", remaining, chdat->transfer_len); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 150 | |
| 151 | /* Transfer remaining 1 - 31 bytes */ |
| 152 | if (pio > 0 && pio < 32) { |
| 153 | u8 *buf; |
| 154 | |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 155 | dev_dbg(musb->controller, "Using PIO for remaining %lu bytes\n", pio); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 156 | buf = phys_to_virt((u32)chdat->dma_addr) + chdat->transfer_len; |
| 157 | if (chdat->tx) { |
Tony Lindgren | 1d0f11b | 2010-04-23 17:41:15 -0700 | [diff] [blame] | 158 | dma_unmap_single(dev, chdat->dma_addr, |
| 159 | chdat->transfer_len, |
| 160 | DMA_TO_DEVICE); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 161 | musb_write_fifo(hw_ep, pio, buf); |
| 162 | } else { |
Tony Lindgren | 1d0f11b | 2010-04-23 17:41:15 -0700 | [diff] [blame] | 163 | dma_unmap_single(dev, chdat->dma_addr, |
| 164 | chdat->transfer_len, |
| 165 | DMA_FROM_DEVICE); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 166 | musb_read_fifo(hw_ep, pio, buf); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 167 | } |
| 168 | channel->actual_len += pio; |
| 169 | } |
| 170 | |
| 171 | if (!tusb_dma->multichannel) |
| 172 | tusb_omap_free_shared_dmareq(chdat); |
| 173 | |
| 174 | channel->status = MUSB_DMA_STATUS_FREE; |
| 175 | |
| 176 | /* Handle only RX callbacks here. TX callbacks must be handled based |
| 177 | * on the TUSB DMA status interrupt. |
| 178 | * REVISIT: Use both TUSB DMA status interrupt and OMAP DMA callback |
| 179 | * interrupt for RX and TX. |
| 180 | */ |
| 181 | if (!chdat->tx) |
| 182 | musb_dma_completion(musb, chdat->epnum, chdat->tx); |
| 183 | |
| 184 | /* We must terminate short tx transfers manually by setting TXPKTRDY. |
| 185 | * REVISIT: This same problem may occur with other MUSB dma as well. |
| 186 | * Easy to test with g_ether by pinging the MUSB board with ping -s54. |
| 187 | */ |
| 188 | if ((chdat->transfer_len < chdat->packet_sz) |
| 189 | || (chdat->transfer_len % chdat->packet_sz != 0)) { |
| 190 | u16 csr; |
| 191 | |
| 192 | if (chdat->tx) { |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 193 | dev_dbg(musb->controller, "terminating short tx packet\n"); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 194 | musb_ep_select(mbase, chdat->epnum); |
| 195 | csr = musb_readw(hw_ep->regs, MUSB_TXCSR); |
| 196 | csr |= MUSB_TXCSR_MODE | MUSB_TXCSR_TXPKTRDY |
| 197 | | MUSB_TXCSR_P_WZC_BITS; |
| 198 | musb_writew(hw_ep->regs, MUSB_TXCSR, csr); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | spin_unlock_irqrestore(&musb->lock, flags); |
| 203 | } |
| 204 | |
| 205 | static int tusb_omap_dma_program(struct dma_channel *channel, u16 packet_sz, |
| 206 | u8 rndis_mode, dma_addr_t dma_addr, u32 len) |
| 207 | { |
| 208 | struct tusb_omap_dma_ch *chdat = to_chdat(channel); |
| 209 | struct tusb_omap_dma *tusb_dma = chdat->tusb_dma; |
| 210 | struct musb *musb = chdat->musb; |
Tony Lindgren | 1d0f11b | 2010-04-23 17:41:15 -0700 | [diff] [blame] | 211 | struct device *dev = musb->controller; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 212 | struct musb_hw_ep *hw_ep = chdat->hw_ep; |
| 213 | void __iomem *mbase = musb->mregs; |
| 214 | void __iomem *ep_conf = hw_ep->conf; |
| 215 | dma_addr_t fifo = hw_ep->fifo_sync; |
| 216 | struct omap_dma_channel_params dma_params; |
| 217 | u32 dma_remaining; |
| 218 | int src_burst, dst_burst; |
| 219 | u16 csr; |
Peter Ujfalusi | 6df2b42 | 2017-05-17 11:23:11 -0500 | [diff] [blame] | 220 | u32 psize; |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 221 | struct tusb_dma_data *dma_data; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 222 | |
| 223 | if (unlikely(dma_addr & 0x1) || (len < 32) || (len > packet_sz)) |
| 224 | return false; |
| 225 | |
| 226 | /* |
| 227 | * HW issue #10: Async dma will eventually corrupt the XFR_SIZE |
| 228 | * register which will cause missed DMA interrupt. We could try to |
| 229 | * use a timer for the callback, but it is unsafe as the XFR_SIZE |
| 230 | * register is corrupt, and we won't know if the DMA worked. |
| 231 | */ |
| 232 | if (dma_addr & 0x2) |
| 233 | return false; |
| 234 | |
| 235 | /* |
| 236 | * Because of HW issue #10, it seems like mixing sync DMA and async |
| 237 | * PIO access can confuse the DMA. Make sure XFR_SIZE is reset before |
| 238 | * using the channel for DMA. |
| 239 | */ |
| 240 | if (chdat->tx) |
| 241 | dma_remaining = musb_readl(ep_conf, TUSB_EP_TX_OFFSET); |
| 242 | else |
| 243 | dma_remaining = musb_readl(ep_conf, TUSB_EP_RX_OFFSET); |
| 244 | |
| 245 | dma_remaining = TUSB_EP_CONFIG_XFR_SIZE(dma_remaining); |
| 246 | if (dma_remaining) { |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 247 | dev_dbg(musb->controller, "Busy %s dma ch%i, not using: %08x\n", |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 248 | chdat->tx ? "tx" : "rx", |
| 249 | chdat->dma_data ? chdat->dma_data->ch : -1, |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 250 | dma_remaining); |
| 251 | return false; |
| 252 | } |
| 253 | |
| 254 | chdat->transfer_len = len & ~0x1f; |
| 255 | |
| 256 | if (len < packet_sz) |
| 257 | chdat->transfer_packet_sz = chdat->transfer_len; |
| 258 | else |
| 259 | chdat->transfer_packet_sz = packet_sz; |
| 260 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 261 | dma_data = chdat->dma_data; |
| 262 | if (!tusb_dma->multichannel) { |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 263 | if (tusb_omap_use_shared_dmareq(chdat) != 0) { |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 264 | dev_dbg(musb->controller, "could not get dma for ep%i\n", chdat->epnum); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 265 | return false; |
| 266 | } |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 267 | if (dma_data->ch < 0) { |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 268 | /* REVISIT: This should get blocked earlier, happens |
| 269 | * with MSC ErrorRecoveryTest |
| 270 | */ |
| 271 | WARN_ON(1); |
| 272 | return false; |
| 273 | } |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 274 | } |
| 275 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 276 | omap_set_dma_callback(dma_data->ch, tusb_omap_dma_cb, channel); |
| 277 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 278 | chdat->packet_sz = packet_sz; |
| 279 | chdat->len = len; |
| 280 | channel->actual_len = 0; |
Tony Lindgren | 1d0f11b | 2010-04-23 17:41:15 -0700 | [diff] [blame] | 281 | chdat->dma_addr = dma_addr; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 282 | channel->status = MUSB_DMA_STATUS_BUSY; |
| 283 | |
| 284 | /* Since we're recycling dma areas, we need to clean or invalidate */ |
| 285 | if (chdat->tx) |
Tony Lindgren | 1d0f11b | 2010-04-23 17:41:15 -0700 | [diff] [blame] | 286 | dma_map_single(dev, phys_to_virt(dma_addr), len, |
| 287 | DMA_TO_DEVICE); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 288 | else |
Tony Lindgren | 1d0f11b | 2010-04-23 17:41:15 -0700 | [diff] [blame] | 289 | dma_map_single(dev, phys_to_virt(dma_addr), len, |
| 290 | DMA_FROM_DEVICE); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 291 | |
| 292 | /* Use 16-bit transfer if dma_addr is not 32-bit aligned */ |
| 293 | if ((dma_addr & 0x3) == 0) { |
| 294 | dma_params.data_type = OMAP_DMA_DATA_TYPE_S32; |
| 295 | dma_params.elem_count = 8; /* Elements in frame */ |
| 296 | } else { |
| 297 | dma_params.data_type = OMAP_DMA_DATA_TYPE_S16; |
| 298 | dma_params.elem_count = 16; /* Elements in frame */ |
| 299 | fifo = hw_ep->fifo_async; |
| 300 | } |
| 301 | |
| 302 | dma_params.frame_count = chdat->transfer_len / 32; /* Burst sz frame */ |
| 303 | |
Arnd Bergmann | 3ec08dd | 2016-01-28 17:23:14 +0100 | [diff] [blame] | 304 | dev_dbg(musb->controller, "ep%i %s dma ch%i dma: %pad len: %u(%u) packet_sz: %i(%i)\n", |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 305 | chdat->epnum, chdat->tx ? "tx" : "rx", |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 306 | dma_data->ch, &dma_addr, chdat->transfer_len, len, |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 307 | chdat->transfer_packet_sz, packet_sz); |
| 308 | |
| 309 | /* |
| 310 | * Prepare omap DMA for transfer |
| 311 | */ |
| 312 | if (chdat->tx) { |
| 313 | dma_params.src_amode = OMAP_DMA_AMODE_POST_INC; |
| 314 | dma_params.src_start = (unsigned long)dma_addr; |
| 315 | dma_params.src_ei = 0; |
| 316 | dma_params.src_fi = 0; |
| 317 | |
| 318 | dma_params.dst_amode = OMAP_DMA_AMODE_DOUBLE_IDX; |
| 319 | dma_params.dst_start = (unsigned long)fifo; |
| 320 | dma_params.dst_ei = 1; |
| 321 | dma_params.dst_fi = -31; /* Loop 32 byte window */ |
| 322 | |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 323 | dma_params.trigger = dma_data->sync_dev; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 324 | dma_params.sync_mode = OMAP_DMA_SYNC_FRAME; |
| 325 | dma_params.src_or_dst_synch = 0; /* Dest sync */ |
| 326 | |
| 327 | src_burst = OMAP_DMA_DATA_BURST_16; /* 16x32 read */ |
| 328 | dst_burst = OMAP_DMA_DATA_BURST_8; /* 8x32 write */ |
| 329 | } else { |
| 330 | dma_params.src_amode = OMAP_DMA_AMODE_DOUBLE_IDX; |
| 331 | dma_params.src_start = (unsigned long)fifo; |
| 332 | dma_params.src_ei = 1; |
| 333 | dma_params.src_fi = -31; /* Loop 32 byte window */ |
| 334 | |
| 335 | dma_params.dst_amode = OMAP_DMA_AMODE_POST_INC; |
| 336 | dma_params.dst_start = (unsigned long)dma_addr; |
| 337 | dma_params.dst_ei = 0; |
| 338 | dma_params.dst_fi = 0; |
| 339 | |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 340 | dma_params.trigger = dma_data->sync_dev; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 341 | dma_params.sync_mode = OMAP_DMA_SYNC_FRAME; |
| 342 | dma_params.src_or_dst_synch = 1; /* Source sync */ |
| 343 | |
| 344 | src_burst = OMAP_DMA_DATA_BURST_8; /* 8x32 read */ |
| 345 | dst_burst = OMAP_DMA_DATA_BURST_16; /* 16x32 write */ |
| 346 | } |
| 347 | |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 348 | dev_dbg(musb->controller, "ep%i %s using %i-bit %s dma from 0x%08lx to 0x%08lx\n", |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 349 | chdat->epnum, chdat->tx ? "tx" : "rx", |
| 350 | (dma_params.data_type == OMAP_DMA_DATA_TYPE_S32) ? 32 : 16, |
| 351 | ((dma_addr & 0x3) == 0) ? "sync" : "async", |
| 352 | dma_params.src_start, dma_params.dst_start); |
| 353 | |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 354 | omap_set_dma_params(dma_data->ch, &dma_params); |
| 355 | omap_set_dma_src_burst_mode(dma_data->ch, src_burst); |
| 356 | omap_set_dma_dest_burst_mode(dma_data->ch, dst_burst); |
| 357 | omap_set_dma_write_mode(dma_data->ch, OMAP_DMA_WRITE_LAST_NON_POSTED); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 358 | |
| 359 | /* |
| 360 | * Prepare MUSB for DMA transfer |
| 361 | */ |
Peter Ujfalusi | 3565b78 | 2017-06-16 10:40:58 -0500 | [diff] [blame] | 362 | musb_ep_select(mbase, chdat->epnum); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 363 | if (chdat->tx) { |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 364 | csr = musb_readw(hw_ep->regs, MUSB_TXCSR); |
| 365 | csr |= (MUSB_TXCSR_AUTOSET | MUSB_TXCSR_DMAENAB |
| 366 | | MUSB_TXCSR_DMAMODE | MUSB_TXCSR_MODE); |
| 367 | csr &= ~MUSB_TXCSR_P_UNDERRUN; |
| 368 | musb_writew(hw_ep->regs, MUSB_TXCSR, csr); |
| 369 | } else { |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 370 | csr = musb_readw(hw_ep->regs, MUSB_RXCSR); |
| 371 | csr |= MUSB_RXCSR_DMAENAB; |
| 372 | csr &= ~(MUSB_RXCSR_AUTOCLEAR | MUSB_RXCSR_DMAMODE); |
| 373 | musb_writew(hw_ep->regs, MUSB_RXCSR, |
| 374 | csr | MUSB_RXCSR_P_WZC_BITS); |
| 375 | } |
| 376 | |
| 377 | /* |
| 378 | * Start DMA transfer |
| 379 | */ |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 380 | omap_start_dma(dma_data->ch); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 381 | |
| 382 | if (chdat->tx) { |
| 383 | /* Send transfer_packet_sz packets at a time */ |
Peter Ujfalusi | 6df2b42 | 2017-05-17 11:23:11 -0500 | [diff] [blame] | 384 | psize = musb_readl(ep_conf, TUSB_EP_MAX_PACKET_SIZE_OFFSET); |
| 385 | psize &= ~0x7ff; |
| 386 | psize |= chdat->transfer_packet_sz; |
| 387 | musb_writel(ep_conf, TUSB_EP_MAX_PACKET_SIZE_OFFSET, psize); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 388 | |
| 389 | musb_writel(ep_conf, TUSB_EP_TX_OFFSET, |
| 390 | TUSB_EP_CONFIG_XFR_SIZE(chdat->transfer_len)); |
| 391 | } else { |
| 392 | /* Receive transfer_packet_sz packets at a time */ |
Peter Ujfalusi | 6df2b42 | 2017-05-17 11:23:11 -0500 | [diff] [blame] | 393 | psize = musb_readl(ep_conf, TUSB_EP_MAX_PACKET_SIZE_OFFSET); |
| 394 | psize &= ~(0x7ff << 16); |
| 395 | psize |= (chdat->transfer_packet_sz << 16); |
| 396 | musb_writel(ep_conf, TUSB_EP_MAX_PACKET_SIZE_OFFSET, psize); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 397 | |
| 398 | musb_writel(ep_conf, TUSB_EP_RX_OFFSET, |
| 399 | TUSB_EP_CONFIG_XFR_SIZE(chdat->transfer_len)); |
| 400 | } |
| 401 | |
| 402 | return true; |
| 403 | } |
| 404 | |
| 405 | static int tusb_omap_dma_abort(struct dma_channel *channel) |
| 406 | { |
| 407 | struct tusb_omap_dma_ch *chdat = to_chdat(channel); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 408 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 409 | if (chdat->dma_data) |
| 410 | omap_stop_dma(chdat->dma_data->ch); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 411 | |
| 412 | channel->status = MUSB_DMA_STATUS_FREE; |
| 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | |
| 417 | static inline int tusb_omap_dma_allocate_dmareq(struct tusb_omap_dma_ch *chdat) |
| 418 | { |
| 419 | u32 reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP); |
| 420 | int i, dmareq_nr = -1; |
| 421 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 422 | for (i = 0; i < MAX_DMAREQ; i++) { |
| 423 | int cur = (reg & (0xf << (i * 5))) >> (i * 5); |
| 424 | if (cur == 0) { |
| 425 | dmareq_nr = i; |
| 426 | break; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | if (dmareq_nr == -1) |
| 431 | return -EAGAIN; |
| 432 | |
| 433 | reg |= (chdat->epnum << (dmareq_nr * 5)); |
| 434 | if (chdat->tx) |
| 435 | reg |= ((1 << 4) << (dmareq_nr * 5)); |
| 436 | musb_writel(chdat->tbase, TUSB_DMA_EP_MAP, reg); |
| 437 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 438 | chdat->dma_data = &chdat->tusb_dma->dma_pool[dmareq_nr]; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 439 | |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static inline void tusb_omap_dma_free_dmareq(struct tusb_omap_dma_ch *chdat) |
| 444 | { |
| 445 | u32 reg; |
| 446 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 447 | if (!chdat || !chdat->dma_data || chdat->dma_data->dmareq < 0) |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 448 | return; |
| 449 | |
| 450 | reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP); |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 451 | reg &= ~(0x1f << (chdat->dma_data->dmareq * 5)); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 452 | musb_writel(chdat->tbase, TUSB_DMA_EP_MAP, reg); |
| 453 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 454 | chdat->dma_data = NULL; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static struct dma_channel *dma_channel_pool[MAX_DMAREQ]; |
| 458 | |
| 459 | static struct dma_channel * |
| 460 | tusb_omap_dma_allocate(struct dma_controller *c, |
| 461 | struct musb_hw_ep *hw_ep, |
| 462 | u8 tx) |
| 463 | { |
| 464 | int ret, i; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 465 | struct tusb_omap_dma *tusb_dma; |
| 466 | struct musb *musb; |
| 467 | void __iomem *tbase; |
| 468 | struct dma_channel *channel = NULL; |
| 469 | struct tusb_omap_dma_ch *chdat = NULL; |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 470 | struct tusb_dma_data *dma_data = NULL; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 471 | u32 reg; |
| 472 | |
| 473 | tusb_dma = container_of(c, struct tusb_omap_dma, controller); |
Alexandre Bailon | a96ca0d | 2017-02-06 22:53:55 -0600 | [diff] [blame] | 474 | musb = tusb_dma->controller.musb; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 475 | tbase = musb->ctrl_base; |
| 476 | |
| 477 | reg = musb_readl(tbase, TUSB_DMA_INT_MASK); |
| 478 | if (tx) |
| 479 | reg &= ~(1 << hw_ep->epnum); |
| 480 | else |
| 481 | reg &= ~(1 << (hw_ep->epnum + 15)); |
| 482 | musb_writel(tbase, TUSB_DMA_INT_MASK, reg); |
| 483 | |
| 484 | /* REVISIT: Why does dmareq5 not work? */ |
| 485 | if (hw_ep->epnum == 0) { |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 486 | dev_dbg(musb->controller, "Not allowing DMA for ep0 %s\n", tx ? "tx" : "rx"); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 487 | return NULL; |
| 488 | } |
| 489 | |
| 490 | for (i = 0; i < MAX_DMAREQ; i++) { |
| 491 | struct dma_channel *ch = dma_channel_pool[i]; |
| 492 | if (ch->status == MUSB_DMA_STATUS_UNKNOWN) { |
| 493 | ch->status = MUSB_DMA_STATUS_FREE; |
| 494 | channel = ch; |
| 495 | chdat = ch->private_data; |
| 496 | break; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | if (!channel) |
| 501 | return NULL; |
| 502 | |
Alexandre Bailon | a96ca0d | 2017-02-06 22:53:55 -0600 | [diff] [blame] | 503 | chdat->musb = tusb_dma->controller.musb; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 504 | chdat->tbase = tusb_dma->tbase; |
| 505 | chdat->hw_ep = hw_ep; |
| 506 | chdat->epnum = hw_ep->epnum; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 507 | chdat->completed_len = 0; |
| 508 | chdat->tusb_dma = tusb_dma; |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 509 | if (tx) |
| 510 | chdat->tx = 1; |
| 511 | else |
| 512 | chdat->tx = 0; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 513 | |
| 514 | channel->max_len = 0x7fffffff; |
| 515 | channel->desired_mode = 0; |
| 516 | channel->actual_len = 0; |
| 517 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 518 | if (!chdat->dma_data) { |
| 519 | if (tusb_dma->multichannel) { |
| 520 | ret = tusb_omap_dma_allocate_dmareq(chdat); |
| 521 | if (ret != 0) |
| 522 | goto free_dmareq; |
| 523 | } else { |
| 524 | chdat->dma_data = &tusb_dma->dma_pool[0]; |
| 525 | } |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 526 | } |
| 527 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 528 | dma_data = chdat->dma_data; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 529 | |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 530 | dev_dbg(musb->controller, "ep%i %s dma: %s dma%i dmareq%i sync%i\n", |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 531 | chdat->epnum, |
| 532 | chdat->tx ? "tx" : "rx", |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 533 | tusb_dma->multichannel ? "shared" : "dedicated", |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 534 | dma_data->ch, dma_data->dmareq, dma_data->sync_dev); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 535 | |
| 536 | return channel; |
| 537 | |
| 538 | free_dmareq: |
| 539 | tusb_omap_dma_free_dmareq(chdat); |
| 540 | |
Felipe Balbi | 5c8a86e | 2011-05-11 12:44:08 +0300 | [diff] [blame] | 541 | dev_dbg(musb->controller, "ep%i: Could not get a DMA channel\n", chdat->epnum); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 542 | channel->status = MUSB_DMA_STATUS_UNKNOWN; |
| 543 | |
| 544 | return NULL; |
| 545 | } |
| 546 | |
| 547 | static void tusb_omap_dma_release(struct dma_channel *channel) |
| 548 | { |
| 549 | struct tusb_omap_dma_ch *chdat = to_chdat(channel); |
| 550 | struct musb *musb = chdat->musb; |
| 551 | void __iomem *tbase = musb->ctrl_base; |
| 552 | u32 reg; |
| 553 | |
Peter Ujfalusi | 1df9d9e | 2017-06-16 10:40:59 -0500 | [diff] [blame] | 554 | dev_dbg(musb->controller, "ep%i ch%i\n", chdat->epnum, |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 555 | chdat->dma_data->ch); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 556 | |
| 557 | reg = musb_readl(tbase, TUSB_DMA_INT_MASK); |
| 558 | if (chdat->tx) |
| 559 | reg |= (1 << chdat->epnum); |
| 560 | else |
| 561 | reg |= (1 << (chdat->epnum + 15)); |
| 562 | musb_writel(tbase, TUSB_DMA_INT_MASK, reg); |
| 563 | |
| 564 | reg = musb_readl(tbase, TUSB_DMA_INT_CLEAR); |
| 565 | if (chdat->tx) |
| 566 | reg |= (1 << chdat->epnum); |
| 567 | else |
| 568 | reg |= (1 << (chdat->epnum + 15)); |
| 569 | musb_writel(tbase, TUSB_DMA_INT_CLEAR, reg); |
| 570 | |
| 571 | channel->status = MUSB_DMA_STATUS_UNKNOWN; |
| 572 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 573 | omap_stop_dma(chdat->dma_data->ch); |
| 574 | tusb_omap_dma_free_dmareq(chdat); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 575 | |
| 576 | channel = NULL; |
| 577 | } |
| 578 | |
Tony Lindgren | 7f6283e | 2015-05-01 12:29:28 -0700 | [diff] [blame] | 579 | void tusb_dma_controller_destroy(struct dma_controller *c) |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 580 | { |
| 581 | struct tusb_omap_dma *tusb_dma; |
| 582 | int i; |
| 583 | |
| 584 | tusb_dma = container_of(c, struct tusb_omap_dma, controller); |
| 585 | for (i = 0; i < MAX_DMAREQ; i++) { |
| 586 | struct dma_channel *ch = dma_channel_pool[i]; |
| 587 | if (ch) { |
| 588 | kfree(ch->private_data); |
| 589 | kfree(ch); |
| 590 | } |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 591 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 592 | /* Free up the DMA channels */ |
| 593 | if (tusb_dma && tusb_dma->dma_pool[i].ch >= 0) |
| 594 | omap_free_dma(tusb_dma->dma_pool[i].ch); |
| 595 | } |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 596 | |
| 597 | kfree(tusb_dma); |
| 598 | } |
Tony Lindgren | 7f6283e | 2015-05-01 12:29:28 -0700 | [diff] [blame] | 599 | EXPORT_SYMBOL_GPL(tusb_dma_controller_destroy); |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 600 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 601 | static int tusb_omap_allocate_dma_pool(struct tusb_omap_dma *tusb_dma) |
| 602 | { |
| 603 | int i; |
| 604 | int ret = 0; |
| 605 | const int sync_dev[6] = { |
| 606 | OMAP24XX_DMA_EXT_DMAREQ0, |
| 607 | OMAP24XX_DMA_EXT_DMAREQ1, |
| 608 | OMAP242X_DMA_EXT_DMAREQ2, |
| 609 | OMAP242X_DMA_EXT_DMAREQ3, |
| 610 | OMAP242X_DMA_EXT_DMAREQ4, |
| 611 | OMAP242X_DMA_EXT_DMAREQ5, |
| 612 | }; |
| 613 | |
| 614 | for (i = 0; i < MAX_DMAREQ; i++) { |
| 615 | struct tusb_dma_data *dma_data = &tusb_dma->dma_pool[i]; |
| 616 | |
| 617 | /* |
| 618 | * Request DMA channels: |
| 619 | * - one channel in case of non multichannel mode |
| 620 | * - MAX_DMAREQ number of channels in multichannel mode |
| 621 | */ |
| 622 | if (i == 0 || tusb_dma->multichannel) { |
| 623 | char ch_name[8]; |
| 624 | |
| 625 | sprintf(ch_name, "dmareq%d", i); |
| 626 | dma_data->sync_dev = sync_dev[i]; |
| 627 | dma_data->ch = -1; |
| 628 | /* callback data is ngoing to be set later */ |
| 629 | ret = omap_request_dma(dma_data->sync_dev, ch_name, |
| 630 | tusb_omap_dma_cb, NULL, &dma_data->ch); |
| 631 | if (ret != 0) { |
| 632 | dev_err(tusb_dma->controller.musb->controller, |
| 633 | "Failed to request %s\n", ch_name); |
| 634 | goto dma_error; |
| 635 | } |
| 636 | |
| 637 | dma_data->dmareq = i; |
| 638 | } else { |
| 639 | dma_data->dmareq = -1; |
| 640 | dma_data->sync_dev = -1; |
| 641 | dma_data->ch = -1; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | return 0; |
| 646 | |
| 647 | dma_error: |
| 648 | for (; i >= 0; i--) { |
| 649 | struct tusb_dma_data *dma_data = &tusb_dma->dma_pool[i]; |
| 650 | |
| 651 | if (dma_data->ch >= 0) |
| 652 | omap_free_dma(dma_data->ch); |
| 653 | } |
| 654 | |
| 655 | return ret; |
| 656 | } |
| 657 | |
Tony Lindgren | 7f6283e | 2015-05-01 12:29:28 -0700 | [diff] [blame] | 658 | struct dma_controller * |
| 659 | tusb_dma_controller_create(struct musb *musb, void __iomem *base) |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 660 | { |
| 661 | void __iomem *tbase = musb->ctrl_base; |
| 662 | struct tusb_omap_dma *tusb_dma; |
| 663 | int i; |
| 664 | |
| 665 | /* REVISIT: Get dmareq lines used from board-*.c */ |
| 666 | |
| 667 | musb_writel(musb->ctrl_base, TUSB_DMA_INT_MASK, 0x7fffffff); |
| 668 | musb_writel(musb->ctrl_base, TUSB_DMA_EP_MAP, 0); |
| 669 | |
| 670 | musb_writel(tbase, TUSB_DMA_REQ_CONF, |
| 671 | TUSB_DMA_REQ_CONF_BURST_SIZE(2) |
| 672 | | TUSB_DMA_REQ_CONF_DMA_REQ_EN(0x3f) |
| 673 | | TUSB_DMA_REQ_CONF_DMA_REQ_ASSER(2)); |
| 674 | |
| 675 | tusb_dma = kzalloc(sizeof(struct tusb_omap_dma), GFP_KERNEL); |
| 676 | if (!tusb_dma) |
Huzaifa Sidhpurwala | c88ba39 | 2011-03-01 15:54:22 +0530 | [diff] [blame] | 677 | goto out; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 678 | |
Alexandre Bailon | a96ca0d | 2017-02-06 22:53:55 -0600 | [diff] [blame] | 679 | tusb_dma->controller.musb = musb; |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 680 | tusb_dma->tbase = musb->ctrl_base; |
| 681 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 682 | tusb_dma->controller.channel_alloc = tusb_omap_dma_allocate; |
| 683 | tusb_dma->controller.channel_release = tusb_omap_dma_release; |
| 684 | tusb_dma->controller.channel_program = tusb_omap_dma_program; |
| 685 | tusb_dma->controller.channel_abort = tusb_omap_dma_abort; |
| 686 | |
Matwey V. Kornilov | 7751b6f | 2014-05-16 18:20:52 +0400 | [diff] [blame] | 687 | if (musb->tusb_revision >= TUSB_REV_30) |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 688 | tusb_dma->multichannel = 1; |
| 689 | |
| 690 | for (i = 0; i < MAX_DMAREQ; i++) { |
| 691 | struct dma_channel *ch; |
| 692 | struct tusb_omap_dma_ch *chdat; |
| 693 | |
| 694 | ch = kzalloc(sizeof(struct dma_channel), GFP_KERNEL); |
| 695 | if (!ch) |
| 696 | goto cleanup; |
| 697 | |
| 698 | dma_channel_pool[i] = ch; |
| 699 | |
| 700 | chdat = kzalloc(sizeof(struct tusb_omap_dma_ch), GFP_KERNEL); |
| 701 | if (!chdat) |
| 702 | goto cleanup; |
| 703 | |
| 704 | ch->status = MUSB_DMA_STATUS_UNKNOWN; |
| 705 | ch->private_data = chdat; |
| 706 | } |
| 707 | |
Peter Ujfalusi | 4cadc71 | 2017-06-16 10:41:00 -0500 | [diff] [blame^] | 708 | if (tusb_omap_allocate_dma_pool(tusb_dma)) |
| 709 | goto cleanup; |
| 710 | |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 711 | return &tusb_dma->controller; |
| 712 | |
| 713 | cleanup: |
Tony Lindgren | 7f6283e | 2015-05-01 12:29:28 -0700 | [diff] [blame] | 714 | musb_dma_controller_destroy(&tusb_dma->controller); |
Huzaifa Sidhpurwala | c88ba39 | 2011-03-01 15:54:22 +0530 | [diff] [blame] | 715 | out: |
Felipe Balbi | 550a737 | 2008-07-24 12:27:36 +0300 | [diff] [blame] | 716 | return NULL; |
| 717 | } |
Tony Lindgren | 7f6283e | 2015-05-01 12:29:28 -0700 | [diff] [blame] | 718 | EXPORT_SYMBOL_GPL(tusb_dma_controller_create); |