Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 1 | /* linux/arch/arm/plat-samsung/dma-ops.c |
| 2 | * |
| 3 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
| 4 | * http://www.samsung.com |
| 5 | * |
| 6 | * Samsung DMA Operations |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/amba/pl330.h> |
| 16 | #include <linux/scatterlist.h> |
Paul Gortmaker | 0c073e3 | 2011-10-08 23:24:48 -0400 | [diff] [blame] | 17 | #include <linux/export.h> |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 18 | |
| 19 | #include <mach/dma.h> |
| 20 | |
Tomasz Figa | 1db0287 | 2013-10-16 21:10:54 +0200 | [diff] [blame] | 21 | #if defined(CONFIG_PL330_DMA) |
| 22 | #define dma_filter pl330_filter |
| 23 | #elif defined(CONFIG_S3C64XX_PL080) |
| 24 | #define dma_filter pl08x_filter_id |
| 25 | #endif |
| 26 | |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 27 | static unsigned samsung_dmadev_request(enum dma_ch dma_ch, |
Padmavathi Venna | e7ba5f1 | 2013-01-18 17:17:02 +0530 | [diff] [blame] | 28 | struct samsung_dma_req *param, |
| 29 | struct device *dev, char *ch_name) |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 30 | { |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 31 | dma_cap_mask_t mask; |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 32 | |
| 33 | dma_cap_zero(mask); |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 34 | dma_cap_set(param->cap, mask); |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 35 | |
Padmavathi Venna | e7ba5f1 | 2013-01-18 17:17:02 +0530 | [diff] [blame] | 36 | if (dev->of_node) |
| 37 | return (unsigned)dma_request_slave_channel(dev, ch_name); |
| 38 | else |
Tomasz Figa | 1db0287 | 2013-10-16 21:10:54 +0200 | [diff] [blame] | 39 | return (unsigned)dma_request_channel(mask, dma_filter, |
Padmavathi Venna | ba7a9a7 | 2013-04-08 21:42:10 +0900 | [diff] [blame] | 40 | (void *)dma_ch); |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 41 | } |
| 42 | |
Sachin Kamat | 3688be4 | 2012-06-27 11:29:54 +0900 | [diff] [blame] | 43 | static int samsung_dmadev_release(unsigned ch, void *param) |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 44 | { |
| 45 | dma_release_channel((struct dma_chan *)ch); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 50 | static int samsung_dmadev_config(unsigned ch, |
| 51 | struct samsung_dma_config *param) |
| 52 | { |
| 53 | struct dma_chan *chan = (struct dma_chan *)ch; |
| 54 | struct dma_slave_config slave_config; |
| 55 | |
| 56 | if (param->direction == DMA_DEV_TO_MEM) { |
| 57 | memset(&slave_config, 0, sizeof(struct dma_slave_config)); |
| 58 | slave_config.direction = param->direction; |
| 59 | slave_config.src_addr = param->fifo; |
| 60 | slave_config.src_addr_width = param->width; |
| 61 | slave_config.src_maxburst = 1; |
| 62 | dmaengine_slave_config(chan, &slave_config); |
| 63 | } else if (param->direction == DMA_MEM_TO_DEV) { |
| 64 | memset(&slave_config, 0, sizeof(struct dma_slave_config)); |
| 65 | slave_config.direction = param->direction; |
| 66 | slave_config.dst_addr = param->fifo; |
| 67 | slave_config.dst_addr_width = param->width; |
| 68 | slave_config.dst_maxburst = 1; |
| 69 | dmaengine_slave_config(chan, &slave_config); |
| 70 | } else { |
| 71 | pr_warn("unsupported direction\n"); |
| 72 | return -EINVAL; |
| 73 | } |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 78 | static int samsung_dmadev_prepare(unsigned ch, |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 79 | struct samsung_dma_prep *param) |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 80 | { |
| 81 | struct scatterlist sg; |
| 82 | struct dma_chan *chan = (struct dma_chan *)ch; |
| 83 | struct dma_async_tx_descriptor *desc; |
| 84 | |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 85 | switch (param->cap) { |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 86 | case DMA_SLAVE: |
| 87 | sg_init_table(&sg, 1); |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 88 | sg_dma_len(&sg) = param->len; |
| 89 | sg_set_page(&sg, pfn_to_page(PFN_DOWN(param->buf)), |
| 90 | param->len, offset_in_page(param->buf)); |
| 91 | sg_dma_address(&sg) = param->buf; |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 92 | |
Alexandre Bounine | 1605282 | 2012-03-08 16:11:18 -0500 | [diff] [blame] | 93 | desc = dmaengine_prep_slave_sg(chan, |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 94 | &sg, 1, param->direction, DMA_PREP_INTERRUPT); |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 95 | break; |
| 96 | case DMA_CYCLIC: |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 97 | desc = dmaengine_prep_dma_cyclic(chan, param->buf, |
Peter Ujfalusi | b7ef37d | 2012-09-24 10:58:05 +0300 | [diff] [blame] | 98 | param->len, param->period, param->direction, |
| 99 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 100 | break; |
| 101 | default: |
| 102 | dev_err(&chan->dev->device, "unsupported format\n"); |
| 103 | return -EFAULT; |
| 104 | } |
| 105 | |
| 106 | if (!desc) { |
| 107 | dev_err(&chan->dev->device, "cannot prepare cyclic dma\n"); |
| 108 | return -EFAULT; |
| 109 | } |
| 110 | |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 111 | desc->callback = param->fp; |
| 112 | desc->callback_param = param->fp_param; |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 113 | |
| 114 | dmaengine_submit((struct dma_async_tx_descriptor *)desc); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static inline int samsung_dmadev_trigger(unsigned ch) |
| 120 | { |
| 121 | dma_async_issue_pending((struct dma_chan *)ch); |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static inline int samsung_dmadev_flush(unsigned ch) |
| 127 | { |
| 128 | return dmaengine_terminate_all((struct dma_chan *)ch); |
| 129 | } |
| 130 | |
Kukjin Kim | 6d259a2 | 2012-01-21 12:00:13 +0900 | [diff] [blame] | 131 | static struct samsung_dma_ops dmadev_ops = { |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 132 | .request = samsung_dmadev_request, |
| 133 | .release = samsung_dmadev_release, |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 134 | .config = samsung_dmadev_config, |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 135 | .prepare = samsung_dmadev_prepare, |
| 136 | .trigger = samsung_dmadev_trigger, |
| 137 | .started = NULL, |
| 138 | .flush = samsung_dmadev_flush, |
| 139 | .stop = samsung_dmadev_flush, |
| 140 | }; |
| 141 | |
| 142 | void *samsung_dmadev_get_ops(void) |
| 143 | { |
| 144 | return &dmadev_ops; |
| 145 | } |
| 146 | EXPORT_SYMBOL(samsung_dmadev_get_ops); |