Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * drivers/usb/musb/ux500_dma.c |
| 3 | * |
Fabio Baltieri | 3ee1f2e | 2013-04-03 10:45:02 +0200 | [diff] [blame] | 4 | * U8500 DMA support code |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 5 | * |
| 6 | * Copyright (C) 2009 STMicroelectronics |
| 7 | * Copyright (C) 2011 ST-Ericsson SA |
| 8 | * Authors: |
| 9 | * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com> |
| 10 | * Praveena Nadahally <praveen.nadahally@stericsson.com> |
| 11 | * Rajaram Regupathy <ragupathy.rajaram@stericsson.com> |
| 12 | * |
| 13 | * This program is free software: you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation, either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 25 | */ |
| 26 | |
| 27 | #include <linux/device.h> |
| 28 | #include <linux/interrupt.h> |
| 29 | #include <linux/platform_device.h> |
| 30 | #include <linux/dma-mapping.h> |
| 31 | #include <linux/dmaengine.h> |
| 32 | #include <linux/pfn.h> |
Felipe Balbi | 0f53e48 | 2013-02-06 09:47:58 +0200 | [diff] [blame] | 33 | #include <linux/sizes.h> |
Arnd Bergmann | db298da | 2012-08-24 15:19:33 +0200 | [diff] [blame] | 34 | #include <linux/platform_data/usb-musb-ux500.h> |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 35 | #include "musb_core.h" |
| 36 | |
| 37 | struct ux500_dma_channel { |
| 38 | struct dma_channel channel; |
| 39 | struct ux500_dma_controller *controller; |
| 40 | struct musb_hw_ep *hw_ep; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 41 | struct dma_chan *dma_chan; |
| 42 | unsigned int cur_len; |
| 43 | dma_cookie_t cookie; |
| 44 | u8 ch_num; |
| 45 | u8 is_tx; |
| 46 | u8 is_allocated; |
| 47 | }; |
| 48 | |
| 49 | struct ux500_dma_controller { |
| 50 | struct dma_controller controller; |
Lee Jones | be2dbb0 | 2013-05-15 10:51:43 +0100 | [diff] [blame^] | 51 | struct ux500_dma_channel rx_channel[UX500_MUSB_DMA_NUM_RX_TX_CHANNELS]; |
| 52 | struct ux500_dma_channel tx_channel[UX500_MUSB_DMA_NUM_RX_TX_CHANNELS]; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 53 | void *private_data; |
| 54 | dma_addr_t phy_base; |
| 55 | }; |
| 56 | |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 57 | /* Work function invoked from DMA callback to handle rx transfers. */ |
Felipe Balbi | 6b0cfc6 | 2013-03-22 17:03:32 +0200 | [diff] [blame] | 58 | static void ux500_dma_callback(void *private_data) |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 59 | { |
Per Forlin | be18a25 | 2011-08-17 11:03:40 +0200 | [diff] [blame] | 60 | struct dma_channel *channel = private_data; |
| 61 | struct ux500_dma_channel *ux500_channel = channel->private_data; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 62 | struct musb_hw_ep *hw_ep = ux500_channel->hw_ep; |
| 63 | struct musb *musb = hw_ep->musb; |
| 64 | unsigned long flags; |
| 65 | |
Per Forlin | afbd074 | 2011-08-03 14:22:17 +0200 | [diff] [blame] | 66 | dev_dbg(musb->controller, "DMA rx transfer done on hw_ep=%d\n", |
| 67 | hw_ep->epnum); |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 68 | |
| 69 | spin_lock_irqsave(&musb->lock, flags); |
| 70 | ux500_channel->channel.actual_len = ux500_channel->cur_len; |
| 71 | ux500_channel->channel.status = MUSB_DMA_STATUS_FREE; |
| 72 | musb_dma_completion(musb, hw_ep->epnum, |
| 73 | ux500_channel->is_tx); |
| 74 | spin_unlock_irqrestore(&musb->lock, flags); |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 75 | |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static bool ux500_configure_channel(struct dma_channel *channel, |
| 79 | u16 packet_sz, u8 mode, |
| 80 | dma_addr_t dma_addr, u32 len) |
| 81 | { |
| 82 | struct ux500_dma_channel *ux500_channel = channel->private_data; |
| 83 | struct musb_hw_ep *hw_ep = ux500_channel->hw_ep; |
| 84 | struct dma_chan *dma_chan = ux500_channel->dma_chan; |
| 85 | struct dma_async_tx_descriptor *dma_desc; |
Vinod Koul | 8341544 | 2011-10-14 21:50:31 +0530 | [diff] [blame] | 86 | enum dma_transfer_direction direction; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 87 | struct scatterlist sg; |
| 88 | struct dma_slave_config slave_conf; |
| 89 | enum dma_slave_buswidth addr_width; |
| 90 | dma_addr_t usb_fifo_addr = (MUSB_FIFO_OFFSET(hw_ep->epnum) + |
| 91 | ux500_channel->controller->phy_base); |
Per Forlin | afbd074 | 2011-08-03 14:22:17 +0200 | [diff] [blame] | 92 | struct musb *musb = ux500_channel->controller->private_data; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 93 | |
Per Forlin | afbd074 | 2011-08-03 14:22:17 +0200 | [diff] [blame] | 94 | dev_dbg(musb->controller, |
Felipe Balbi | 6a3b003 | 2013-02-06 09:53:01 +0200 | [diff] [blame] | 95 | "packet_sz=%d, mode=%d, dma_addr=0x%llu, len=%d is_tx=%d\n", |
| 96 | packet_sz, mode, (unsigned long long) dma_addr, |
| 97 | len, ux500_channel->is_tx); |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 98 | |
| 99 | ux500_channel->cur_len = len; |
| 100 | |
| 101 | sg_init_table(&sg, 1); |
| 102 | sg_set_page(&sg, pfn_to_page(PFN_DOWN(dma_addr)), len, |
| 103 | offset_in_page(dma_addr)); |
| 104 | sg_dma_address(&sg) = dma_addr; |
| 105 | sg_dma_len(&sg) = len; |
| 106 | |
Vinod Koul | 8341544 | 2011-10-14 21:50:31 +0530 | [diff] [blame] | 107 | direction = ux500_channel->is_tx ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 108 | addr_width = (len & 0x3) ? DMA_SLAVE_BUSWIDTH_1_BYTE : |
| 109 | DMA_SLAVE_BUSWIDTH_4_BYTES; |
| 110 | |
| 111 | slave_conf.direction = direction; |
Per Forlin | d366d39b | 2011-08-02 17:33:39 +0200 | [diff] [blame] | 112 | slave_conf.src_addr = usb_fifo_addr; |
| 113 | slave_conf.src_addr_width = addr_width; |
| 114 | slave_conf.src_maxburst = 16; |
| 115 | slave_conf.dst_addr = usb_fifo_addr; |
| 116 | slave_conf.dst_addr_width = addr_width; |
| 117 | slave_conf.dst_maxburst = 16; |
Viresh Kumar | 258aea7 | 2012-02-01 16:12:19 +0530 | [diff] [blame] | 118 | slave_conf.device_fc = false; |
Per Forlin | d366d39b | 2011-08-02 17:33:39 +0200 | [diff] [blame] | 119 | |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 120 | dma_chan->device->device_control(dma_chan, DMA_SLAVE_CONFIG, |
| 121 | (unsigned long) &slave_conf); |
| 122 | |
Alexandre Bounine | 1605282 | 2012-03-08 16:11:18 -0500 | [diff] [blame] | 123 | dma_desc = dmaengine_prep_slave_sg(dma_chan, &sg, 1, direction, |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 124 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 125 | if (!dma_desc) |
| 126 | return false; |
| 127 | |
| 128 | dma_desc->callback = ux500_dma_callback; |
| 129 | dma_desc->callback_param = channel; |
| 130 | ux500_channel->cookie = dma_desc->tx_submit(dma_desc); |
| 131 | |
| 132 | dma_async_issue_pending(dma_chan); |
| 133 | |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | static struct dma_channel *ux500_dma_channel_allocate(struct dma_controller *c, |
| 138 | struct musb_hw_ep *hw_ep, u8 is_tx) |
| 139 | { |
| 140 | struct ux500_dma_controller *controller = container_of(c, |
| 141 | struct ux500_dma_controller, controller); |
| 142 | struct ux500_dma_channel *ux500_channel = NULL; |
Per Forlin | afbd074 | 2011-08-03 14:22:17 +0200 | [diff] [blame] | 143 | struct musb *musb = controller->private_data; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 144 | u8 ch_num = hw_ep->epnum - 1; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 145 | |
Lee Jones | be2dbb0 | 2013-05-15 10:51:43 +0100 | [diff] [blame^] | 146 | /* 8 DMA channels (0 - 7). Each DMA channel can only be allocated |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 147 | * to specified hw_ep. For example DMA channel 0 can only be allocated |
| 148 | * to hw_ep 1 and 9. |
| 149 | */ |
| 150 | if (ch_num > 7) |
| 151 | ch_num -= 8; |
| 152 | |
Lee Jones | be2dbb0 | 2013-05-15 10:51:43 +0100 | [diff] [blame^] | 153 | if (ch_num >= UX500_MUSB_DMA_NUM_RX_TX_CHANNELS) |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 154 | return NULL; |
| 155 | |
| 156 | ux500_channel = is_tx ? &(controller->tx_channel[ch_num]) : |
| 157 | &(controller->rx_channel[ch_num]) ; |
| 158 | |
| 159 | /* Check if channel is already used. */ |
| 160 | if (ux500_channel->is_allocated) |
| 161 | return NULL; |
| 162 | |
| 163 | ux500_channel->hw_ep = hw_ep; |
| 164 | ux500_channel->is_allocated = 1; |
| 165 | |
Per Forlin | afbd074 | 2011-08-03 14:22:17 +0200 | [diff] [blame] | 166 | dev_dbg(musb->controller, "hw_ep=%d, is_tx=0x%x, channel=%d\n", |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 167 | hw_ep->epnum, is_tx, ch_num); |
| 168 | |
| 169 | return &(ux500_channel->channel); |
| 170 | } |
| 171 | |
| 172 | static void ux500_dma_channel_release(struct dma_channel *channel) |
| 173 | { |
| 174 | struct ux500_dma_channel *ux500_channel = channel->private_data; |
Per Forlin | afbd074 | 2011-08-03 14:22:17 +0200 | [diff] [blame] | 175 | struct musb *musb = ux500_channel->controller->private_data; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 176 | |
Per Forlin | afbd074 | 2011-08-03 14:22:17 +0200 | [diff] [blame] | 177 | dev_dbg(musb->controller, "channel=%d\n", ux500_channel->ch_num); |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 178 | |
| 179 | if (ux500_channel->is_allocated) { |
| 180 | ux500_channel->is_allocated = 0; |
| 181 | channel->status = MUSB_DMA_STATUS_FREE; |
| 182 | channel->actual_len = 0; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | static int ux500_dma_is_compatible(struct dma_channel *channel, |
| 187 | u16 maxpacket, void *buf, u32 length) |
| 188 | { |
| 189 | if ((maxpacket & 0x3) || |
Felipe Balbi | 6a3b003 | 2013-02-06 09:53:01 +0200 | [diff] [blame] | 190 | ((unsigned long int) buf & 0x3) || |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 191 | (length < 512) || |
| 192 | (length & 0x3)) |
| 193 | return false; |
| 194 | else |
| 195 | return true; |
| 196 | } |
| 197 | |
| 198 | static int ux500_dma_channel_program(struct dma_channel *channel, |
| 199 | u16 packet_sz, u8 mode, |
| 200 | dma_addr_t dma_addr, u32 len) |
| 201 | { |
| 202 | int ret; |
| 203 | |
| 204 | BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN || |
| 205 | channel->status == MUSB_DMA_STATUS_BUSY); |
| 206 | |
| 207 | if (!ux500_dma_is_compatible(channel, packet_sz, (void *)dma_addr, len)) |
| 208 | return false; |
| 209 | |
| 210 | channel->status = MUSB_DMA_STATUS_BUSY; |
| 211 | channel->actual_len = 0; |
| 212 | ret = ux500_configure_channel(channel, packet_sz, mode, dma_addr, len); |
| 213 | if (!ret) |
| 214 | channel->status = MUSB_DMA_STATUS_FREE; |
| 215 | |
| 216 | return ret; |
| 217 | } |
| 218 | |
| 219 | static int ux500_dma_channel_abort(struct dma_channel *channel) |
| 220 | { |
| 221 | struct ux500_dma_channel *ux500_channel = channel->private_data; |
| 222 | struct ux500_dma_controller *controller = ux500_channel->controller; |
| 223 | struct musb *musb = controller->private_data; |
| 224 | void __iomem *epio = musb->endpoints[ux500_channel->hw_ep->epnum].regs; |
| 225 | u16 csr; |
| 226 | |
Per Forlin | afbd074 | 2011-08-03 14:22:17 +0200 | [diff] [blame] | 227 | dev_dbg(musb->controller, "channel=%d, is_tx=%d\n", |
| 228 | ux500_channel->ch_num, ux500_channel->is_tx); |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 229 | |
| 230 | if (channel->status == MUSB_DMA_STATUS_BUSY) { |
| 231 | if (ux500_channel->is_tx) { |
| 232 | csr = musb_readw(epio, MUSB_TXCSR); |
| 233 | csr &= ~(MUSB_TXCSR_AUTOSET | |
| 234 | MUSB_TXCSR_DMAENAB | |
| 235 | MUSB_TXCSR_DMAMODE); |
| 236 | musb_writew(epio, MUSB_TXCSR, csr); |
| 237 | } else { |
| 238 | csr = musb_readw(epio, MUSB_RXCSR); |
| 239 | csr &= ~(MUSB_RXCSR_AUTOCLEAR | |
| 240 | MUSB_RXCSR_DMAENAB | |
| 241 | MUSB_RXCSR_DMAMODE); |
| 242 | musb_writew(epio, MUSB_RXCSR, csr); |
| 243 | } |
| 244 | |
| 245 | ux500_channel->dma_chan->device-> |
| 246 | device_control(ux500_channel->dma_chan, |
| 247 | DMA_TERMINATE_ALL, 0); |
| 248 | channel->status = MUSB_DMA_STATUS_FREE; |
| 249 | } |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | static int ux500_dma_controller_stop(struct dma_controller *c) |
| 254 | { |
| 255 | struct ux500_dma_controller *controller = container_of(c, |
| 256 | struct ux500_dma_controller, controller); |
| 257 | struct ux500_dma_channel *ux500_channel; |
| 258 | struct dma_channel *channel; |
| 259 | u8 ch_num; |
| 260 | |
Lee Jones | be2dbb0 | 2013-05-15 10:51:43 +0100 | [diff] [blame^] | 261 | for (ch_num = 0; ch_num < UX500_MUSB_DMA_NUM_RX_TX_CHANNELS; ch_num++) { |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 262 | channel = &controller->rx_channel[ch_num].channel; |
| 263 | ux500_channel = channel->private_data; |
| 264 | |
| 265 | ux500_dma_channel_release(channel); |
| 266 | |
| 267 | if (ux500_channel->dma_chan) |
| 268 | dma_release_channel(ux500_channel->dma_chan); |
| 269 | } |
| 270 | |
Lee Jones | be2dbb0 | 2013-05-15 10:51:43 +0100 | [diff] [blame^] | 271 | for (ch_num = 0; ch_num < UX500_MUSB_DMA_NUM_RX_TX_CHANNELS; ch_num++) { |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 272 | channel = &controller->tx_channel[ch_num].channel; |
| 273 | ux500_channel = channel->private_data; |
| 274 | |
| 275 | ux500_dma_channel_release(channel); |
| 276 | |
| 277 | if (ux500_channel->dma_chan) |
| 278 | dma_release_channel(ux500_channel->dma_chan); |
| 279 | } |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | static int ux500_dma_controller_start(struct dma_controller *c) |
| 285 | { |
| 286 | struct ux500_dma_controller *controller = container_of(c, |
| 287 | struct ux500_dma_controller, controller); |
| 288 | struct ux500_dma_channel *ux500_channel = NULL; |
| 289 | struct musb *musb = controller->private_data; |
| 290 | struct device *dev = musb->controller; |
| 291 | struct musb_hdrc_platform_data *plat = dev->platform_data; |
| 292 | struct ux500_musb_board_data *data = plat->board_data; |
| 293 | struct dma_channel *dma_channel = NULL; |
| 294 | u32 ch_num; |
| 295 | u8 dir; |
| 296 | u8 is_tx = 0; |
| 297 | |
| 298 | void **param_array; |
| 299 | struct ux500_dma_channel *channel_array; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 300 | dma_cap_mask_t mask; |
| 301 | |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 302 | |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 303 | |
| 304 | dma_cap_zero(mask); |
| 305 | dma_cap_set(DMA_SLAVE, mask); |
| 306 | |
| 307 | /* Prepare the loop for RX channels */ |
| 308 | channel_array = controller->rx_channel; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 309 | param_array = data->dma_rx_param_array; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 310 | |
| 311 | for (dir = 0; dir < 2; dir++) { |
Lee Jones | be2dbb0 | 2013-05-15 10:51:43 +0100 | [diff] [blame^] | 312 | for (ch_num = 0; |
| 313 | ch_num < UX500_MUSB_DMA_NUM_RX_TX_CHANNELS; |
| 314 | ch_num++) { |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 315 | ux500_channel = &channel_array[ch_num]; |
| 316 | ux500_channel->controller = controller; |
| 317 | ux500_channel->ch_num = ch_num; |
| 318 | ux500_channel->is_tx = is_tx; |
| 319 | |
| 320 | dma_channel = &(ux500_channel->channel); |
| 321 | dma_channel->private_data = ux500_channel; |
| 322 | dma_channel->status = MUSB_DMA_STATUS_FREE; |
| 323 | dma_channel->max_len = SZ_16M; |
| 324 | |
| 325 | ux500_channel->dma_chan = dma_request_channel(mask, |
| 326 | data->dma_filter, |
| 327 | param_array[ch_num]); |
| 328 | if (!ux500_channel->dma_chan) { |
| 329 | ERR("Dma pipe allocation error dir=%d ch=%d\n", |
| 330 | dir, ch_num); |
| 331 | |
| 332 | /* Release already allocated channels */ |
| 333 | ux500_dma_controller_stop(c); |
| 334 | |
| 335 | return -EBUSY; |
| 336 | } |
| 337 | |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /* Prepare the loop for TX channels */ |
| 341 | channel_array = controller->tx_channel; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 342 | param_array = data->dma_tx_param_array; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 343 | is_tx = 1; |
| 344 | } |
| 345 | |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | void dma_controller_destroy(struct dma_controller *c) |
| 350 | { |
| 351 | struct ux500_dma_controller *controller = container_of(c, |
| 352 | struct ux500_dma_controller, controller); |
| 353 | |
| 354 | kfree(controller); |
| 355 | } |
| 356 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 357 | struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *base) |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 358 | { |
| 359 | struct ux500_dma_controller *controller; |
| 360 | struct platform_device *pdev = to_platform_device(musb->controller); |
| 361 | struct resource *iomem; |
| 362 | |
| 363 | controller = kzalloc(sizeof(*controller), GFP_KERNEL); |
| 364 | if (!controller) |
Virupax Sadashivpetimath | 399e0f4 | 2013-03-08 10:27:05 +0800 | [diff] [blame] | 365 | goto kzalloc_fail; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 366 | |
| 367 | controller->private_data = musb; |
| 368 | |
| 369 | /* Save physical address for DMA controller. */ |
| 370 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Virupax Sadashivpetimath | 399e0f4 | 2013-03-08 10:27:05 +0800 | [diff] [blame] | 371 | if (!iomem) { |
| 372 | dev_err(musb->controller, "no memory resource defined\n"); |
| 373 | goto plat_get_fail; |
| 374 | } |
| 375 | |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 376 | controller->phy_base = (dma_addr_t) iomem->start; |
| 377 | |
| 378 | controller->controller.start = ux500_dma_controller_start; |
| 379 | controller->controller.stop = ux500_dma_controller_stop; |
| 380 | controller->controller.channel_alloc = ux500_dma_channel_allocate; |
| 381 | controller->controller.channel_release = ux500_dma_channel_release; |
| 382 | controller->controller.channel_program = ux500_dma_channel_program; |
| 383 | controller->controller.channel_abort = ux500_dma_channel_abort; |
| 384 | controller->controller.is_compatible = ux500_dma_is_compatible; |
| 385 | |
| 386 | return &controller->controller; |
Virupax Sadashivpetimath | 399e0f4 | 2013-03-08 10:27:05 +0800 | [diff] [blame] | 387 | |
| 388 | plat_get_fail: |
| 389 | kfree(controller); |
| 390 | kzalloc_fail: |
| 391 | return NULL; |
Mian Yousaf Kaukab | 8dcc8f7 | 2011-03-22 15:55:58 +0100 | [diff] [blame] | 392 | } |