]> Pileus Git - ~andy/linux/blob - arch/arm/plat-samsung/dma-ops.c
ALSA: Add params_width() helpers
[~andy/linux] / 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_req *param,
23                                 struct device *dev, char *ch_name)
24 {
25         dma_cap_mask_t mask;
26
27         dma_cap_zero(mask);
28         dma_cap_set(param->cap, mask);
29
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);
35 }
36
37 static int samsung_dmadev_release(unsigned ch, void *param)
38 {
39         dma_release_channel((struct dma_chan *)ch);
40
41         return 0;
42 }
43
44 static int samsung_dmadev_config(unsigned ch,
45                                 struct samsung_dma_config *param)
46 {
47         struct dma_chan *chan = (struct dma_chan *)ch;
48         struct dma_slave_config slave_config;
49
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;
67         }
68
69         return 0;
70 }
71
72 static int samsung_dmadev_prepare(unsigned ch,
73                         struct samsung_dma_prep *param)
74 {
75         struct scatterlist sg;
76         struct dma_chan *chan = (struct dma_chan *)ch;
77         struct dma_async_tx_descriptor *desc;
78
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;
86
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;
98         }
99
100         if (!desc) {
101                 dev_err(&chan->dev->device, "cannot prepare cyclic dma\n");
102                 return -EFAULT;
103         }
104
105         desc->callback = param->fp;
106         desc->callback_param = param->fp_param;
107
108         dmaengine_submit((struct dma_async_tx_descriptor *)desc);
109
110         return 0;
111 }
112
113 static inline int samsung_dmadev_trigger(unsigned ch)
114 {
115         dma_async_issue_pending((struct dma_chan *)ch);
116
117         return 0;
118 }
119
120 static inline int samsung_dmadev_flush(unsigned ch)
121 {
122         return dmaengine_terminate_all((struct dma_chan *)ch);
123 }
124
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,
134 };
135
136 void *samsung_dmadev_get_ops(void)
137 {
138         return &dmadev_ops;
139 }
140 EXPORT_SYMBOL(samsung_dmadev_get_ops);