Staging: Panel: panel: Fixed checkpatch line length warnings
[linux/fpc-iii.git] / arch / arm / plat-samsung / dma-ops.c
blobec0d731b0e7b88ed8bc7b2937528545c15f60f6e
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 static unsigned samsung_dmadev_request(enum dma_ch dma_ch,
22 struct samsung_dma_req *param,
23 struct device *dev, char *ch_name)
25 dma_cap_mask_t mask;
27 dma_cap_zero(mask);
28 dma_cap_set(param->cap, mask);
30 if (dev->of_node)
31 return (unsigned)dma_request_slave_channel(dev, ch_name);
32 else
33 return (unsigned)dma_request_channel(mask, pl330_filter,
34 (void *)dma_ch);
37 static int samsung_dmadev_release(unsigned ch, void *param)
39 dma_release_channel((struct dma_chan *)ch);
41 return 0;
44 static int samsung_dmadev_config(unsigned ch,
45 struct samsung_dma_config *param)
47 struct dma_chan *chan = (struct dma_chan *)ch;
48 struct dma_slave_config slave_config;
50 if (param->direction == DMA_DEV_TO_MEM) {
51 memset(&slave_config, 0, sizeof(struct dma_slave_config));
52 slave_config.direction = param->direction;
53 slave_config.src_addr = param->fifo;
54 slave_config.src_addr_width = param->width;
55 slave_config.src_maxburst = 1;
56 dmaengine_slave_config(chan, &slave_config);
57 } else if (param->direction == DMA_MEM_TO_DEV) {
58 memset(&slave_config, 0, sizeof(struct dma_slave_config));
59 slave_config.direction = param->direction;
60 slave_config.dst_addr = param->fifo;
61 slave_config.dst_addr_width = param->width;
62 slave_config.dst_maxburst = 1;
63 dmaengine_slave_config(chan, &slave_config);
64 } else {
65 pr_warn("unsupported direction\n");
66 return -EINVAL;
69 return 0;
72 static int samsung_dmadev_prepare(unsigned ch,
73 struct samsung_dma_prep *param)
75 struct scatterlist sg;
76 struct dma_chan *chan = (struct dma_chan *)ch;
77 struct dma_async_tx_descriptor *desc;
79 switch (param->cap) {
80 case DMA_SLAVE:
81 sg_init_table(&sg, 1);
82 sg_dma_len(&sg) = param->len;
83 sg_set_page(&sg, pfn_to_page(PFN_DOWN(param->buf)),
84 param->len, offset_in_page(param->buf));
85 sg_dma_address(&sg) = param->buf;
87 desc = dmaengine_prep_slave_sg(chan,
88 &sg, 1, param->direction, DMA_PREP_INTERRUPT);
89 break;
90 case DMA_CYCLIC:
91 desc = dmaengine_prep_dma_cyclic(chan, param->buf,
92 param->len, param->period, param->direction,
93 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
94 break;
95 default:
96 dev_err(&chan->dev->device, "unsupported format\n");
97 return -EFAULT;
100 if (!desc) {
101 dev_err(&chan->dev->device, "cannot prepare cyclic dma\n");
102 return -EFAULT;
105 desc->callback = param->fp;
106 desc->callback_param = param->fp_param;
108 dmaengine_submit((struct dma_async_tx_descriptor *)desc);
110 return 0;
113 static inline int samsung_dmadev_trigger(unsigned ch)
115 dma_async_issue_pending((struct dma_chan *)ch);
117 return 0;
120 static inline int samsung_dmadev_flush(unsigned ch)
122 return dmaengine_terminate_all((struct dma_chan *)ch);
125 static struct samsung_dma_ops dmadev_ops = {
126 .request = samsung_dmadev_request,
127 .release = samsung_dmadev_release,
128 .config = samsung_dmadev_config,
129 .prepare = samsung_dmadev_prepare,
130 .trigger = samsung_dmadev_trigger,
131 .started = NULL,
132 .flush = samsung_dmadev_flush,
133 .stop = samsung_dmadev_flush,
136 void *samsung_dmadev_get_ops(void)
138 return &dmadev_ops;
140 EXPORT_SYMBOL(samsung_dmadev_get_ops);