Merge tag 'locks-v3.16-2' of git://git.samba.org/jlayton/linux
[linux/fpc-iii.git] / arch / arm / plat-samsung / dma-ops.c
blob886326ee6f6c373c36d16fddef48b9ce58d5f7c9
1 /* linux/arch/arm/plat-samsung/dma-ops.c
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
6 * Samsung DMA Operations
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.
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/amba/pl330.h>
16 #include <linux/scatterlist.h>
17 #include <linux/export.h>
19 #include <mach/dma.h>
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
27 static unsigned samsung_dmadev_request(enum dma_ch dma_ch,
28 struct samsung_dma_req *param,
29 struct device *dev, char *ch_name)
31 dma_cap_mask_t mask;
33 dma_cap_zero(mask);
34 dma_cap_set(param->cap, mask);
36 if (dev->of_node)
37 return (unsigned)dma_request_slave_channel(dev, ch_name);
38 else
39 return (unsigned)dma_request_channel(mask, dma_filter,
40 (void *)dma_ch);
43 static int samsung_dmadev_release(unsigned ch, void *param)
45 dma_release_channel((struct dma_chan *)ch);
47 return 0;
50 static int samsung_dmadev_config(unsigned ch,
51 struct samsung_dma_config *param)
53 struct dma_chan *chan = (struct dma_chan *)ch;
54 struct dma_slave_config slave_config;
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;
75 return 0;
78 static int samsung_dmadev_prepare(unsigned ch,
79 struct samsung_dma_prep *param)
81 struct scatterlist sg;
82 struct dma_chan *chan = (struct dma_chan *)ch;
83 struct dma_async_tx_descriptor *desc;
85 switch (param->cap) {
86 case DMA_SLAVE:
87 sg_init_table(&sg, 1);
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;
93 desc = dmaengine_prep_slave_sg(chan,
94 &sg, 1, param->direction, DMA_PREP_INTERRUPT);
95 break;
96 case DMA_CYCLIC:
97 desc = dmaengine_prep_dma_cyclic(chan, param->buf,
98 param->len, param->period, param->direction,
99 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
100 break;
101 default:
102 dev_err(&chan->dev->device, "unsupported format\n");
103 return -EFAULT;
106 if (!desc) {
107 dev_err(&chan->dev->device, "cannot prepare cyclic dma\n");
108 return -EFAULT;
111 desc->callback = param->fp;
112 desc->callback_param = param->fp_param;
114 dmaengine_submit((struct dma_async_tx_descriptor *)desc);
116 return 0;
119 static inline int samsung_dmadev_trigger(unsigned ch)
121 dma_async_issue_pending((struct dma_chan *)ch);
123 return 0;
126 static inline int samsung_dmadev_flush(unsigned ch)
128 return dmaengine_terminate_all((struct dma_chan *)ch);
131 static struct samsung_dma_ops dmadev_ops = {
132 .request = samsung_dmadev_request,
133 .release = samsung_dmadev_release,
134 .config = samsung_dmadev_config,
135 .prepare = samsung_dmadev_prepare,
136 .trigger = samsung_dmadev_trigger,
137 .started = NULL,
138 .flush = samsung_dmadev_flush,
139 .stop = samsung_dmadev_flush,
142 void *samsung_dmadev_get_ops(void)
144 return &dmadev_ops;
146 EXPORT_SYMBOL(samsung_dmadev_get_ops);