889c2c22325ec43475784773f9d1f200e9da4b6c
[deliverable/linux.git] / arch / arm / plat-samsung / dma-ops.c
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>
17 #include <linux/export.h>
18
19 #include <mach/dma.h>
20
21 static unsigned samsung_dmadev_request(enum dma_ch dma_ch,
22 struct samsung_dma_info *info)
23 {
24 struct dma_chan *chan;
25 dma_cap_mask_t mask;
26 struct dma_slave_config slave_config;
27
28 dma_cap_zero(mask);
29 dma_cap_set(info->cap, mask);
30
31 chan = dma_request_channel(mask, pl330_filter, (void *)dma_ch);
32
33 if (info->direction == DMA_FROM_DEVICE) {
34 memset(&slave_config, 0, sizeof(struct dma_slave_config));
35 slave_config.direction = info->direction;
36 slave_config.src_addr = info->fifo;
37 slave_config.src_addr_width = info->width;
38 slave_config.src_maxburst = 1;
39 dmaengine_slave_config(chan, &slave_config);
40 } else if (info->direction == DMA_TO_DEVICE) {
41 memset(&slave_config, 0, sizeof(struct dma_slave_config));
42 slave_config.direction = info->direction;
43 slave_config.dst_addr = info->fifo;
44 slave_config.dst_addr_width = info->width;
45 slave_config.dst_maxburst = 1;
46 dmaengine_slave_config(chan, &slave_config);
47 }
48
49 return (unsigned)chan;
50 }
51
52 static int samsung_dmadev_release(unsigned ch,
53 struct s3c2410_dma_client *client)
54 {
55 dma_release_channel((struct dma_chan *)ch);
56
57 return 0;
58 }
59
60 static int samsung_dmadev_prepare(unsigned ch,
61 struct samsung_dma_prep_info *info)
62 {
63 struct scatterlist sg;
64 struct dma_chan *chan = (struct dma_chan *)ch;
65 struct dma_async_tx_descriptor *desc;
66
67 switch (info->cap) {
68 case DMA_SLAVE:
69 sg_init_table(&sg, 1);
70 sg_dma_len(&sg) = info->len;
71 sg_set_page(&sg, pfn_to_page(PFN_DOWN(info->buf)),
72 info->len, offset_in_page(info->buf));
73 sg_dma_address(&sg) = info->buf;
74
75 desc = chan->device->device_prep_slave_sg(chan,
76 &sg, 1, info->direction, DMA_PREP_INTERRUPT);
77 break;
78 case DMA_CYCLIC:
79 desc = chan->device->device_prep_dma_cyclic(chan,
80 info->buf, info->len, info->period, info->direction);
81 break;
82 default:
83 dev_err(&chan->dev->device, "unsupported format\n");
84 return -EFAULT;
85 }
86
87 if (!desc) {
88 dev_err(&chan->dev->device, "cannot prepare cyclic dma\n");
89 return -EFAULT;
90 }
91
92 desc->callback = info->fp;
93 desc->callback_param = info->fp_param;
94
95 dmaengine_submit((struct dma_async_tx_descriptor *)desc);
96
97 return 0;
98 }
99
100 static inline int samsung_dmadev_trigger(unsigned ch)
101 {
102 dma_async_issue_pending((struct dma_chan *)ch);
103
104 return 0;
105 }
106
107 static inline int samsung_dmadev_flush(unsigned ch)
108 {
109 return dmaengine_terminate_all((struct dma_chan *)ch);
110 }
111
112 struct samsung_dma_ops dmadev_ops = {
113 .request = samsung_dmadev_request,
114 .release = samsung_dmadev_release,
115 .prepare = samsung_dmadev_prepare,
116 .trigger = samsung_dmadev_trigger,
117 .started = NULL,
118 .flush = samsung_dmadev_flush,
119 .stop = samsung_dmadev_flush,
120 };
121
122 void *samsung_dmadev_get_ops(void)
123 {
124 return &dmadev_ops;
125 }
126 EXPORT_SYMBOL(samsung_dmadev_get_ops);
This page took 0.033533 seconds and 4 git commands to generate.