nios2: Build infrastructure
[deliverable/linux.git] / arch / arm / plat-samsung / s3c-dma-ops.c
CommitLineData
c4e16625
BK
1/* linux/arch/arm/plat-samsung/s3c-dma-ops.c
2 *
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Samsung S3C-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/slab.h>
16#include <linux/types.h>
0c073e35 17#include <linux/export.h>
c4e16625
BK
18
19#include <mach/dma.h>
20
21struct cb_data {
22 void (*fp) (void *);
23 void *fp_param;
24 unsigned ch;
25 struct list_head node;
26};
27
28static LIST_HEAD(dma_list);
29
30static void s3c_dma_cb(struct s3c2410_dma_chan *channel, void *param,
31 int size, enum s3c2410_dma_buffresult res)
32{
33 struct cb_data *data = param;
34
35 data->fp(data->fp_param);
36}
37
38static unsigned s3c_dma_request(enum dma_ch dma_ch,
e7ba5f1d
PV
39 struct samsung_dma_req *param,
40 struct device *dev, char *ch_name)
c4e16625
BK
41{
42 struct cb_data *data;
43
fbb20e81
BK
44 if (s3c2410_dma_request(dma_ch, param->client, NULL) < 0) {
45 s3c2410_dma_free(dma_ch, param->client);
c4e16625
BK
46 return 0;
47 }
48
fbb20e81
BK
49 if (param->cap == DMA_CYCLIC)
50 s3c2410_dma_setflags(dma_ch, S3C2410_DMAF_CIRCULAR);
51
c4e16625
BK
52 data = kzalloc(sizeof(struct cb_data), GFP_KERNEL);
53 data->ch = dma_ch;
54 list_add_tail(&data->node, &dma_list);
55
c4e16625
BK
56 return (unsigned)dma_ch;
57}
58
fbb20e81 59static int s3c_dma_release(unsigned ch, void *param)
c4e16625
BK
60{
61 struct cb_data *data;
62
63 list_for_each_entry(data, &dma_list, node)
64 if (data->ch == ch)
65 break;
66 list_del(&data->node);
67
fbb20e81 68 s3c2410_dma_free(ch, param);
c4e16625
BK
69 kfree(data);
70
71 return 0;
72}
73
fbb20e81
BK
74static int s3c_dma_config(unsigned ch, struct samsung_dma_config *param)
75{
76 s3c2410_dma_devconfig(ch, param->direction, param->fifo);
77 s3c2410_dma_config(ch, param->width);
78
79 return 0;
80}
81
82static int s3c_dma_prepare(unsigned ch, struct samsung_dma_prep *param)
c4e16625
BK
83{
84 struct cb_data *data;
9b9ae16a
TF
85 dma_addr_t pos = param->buf;
86 dma_addr_t end = param->buf + param->len;
c4e16625
BK
87
88 list_for_each_entry(data, &dma_list, node)
89 if (data->ch == ch)
90 break;
91
92 if (!data->fp) {
93 s3c2410_dma_set_buffdone_fn(ch, s3c_dma_cb);
fbb20e81
BK
94 data->fp = param->fp;
95 data->fp_param = param->fp_param;
c4e16625
BK
96 }
97
9b9ae16a
TF
98 if (param->cap != DMA_CYCLIC) {
99 s3c2410_dma_enqueue(ch, (void *)data, param->buf, param->len);
100 return 0;
101 }
102
103 while (pos < end) {
104 s3c2410_dma_enqueue(ch, (void *)data, pos, param->period);
105 pos += param->period;
106 }
c4e16625
BK
107
108 return 0;
109}
110
111static inline int s3c_dma_trigger(unsigned ch)
112{
113 return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_START);
114}
115
116static inline int s3c_dma_started(unsigned ch)
117{
118 return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STARTED);
119}
120
121static inline int s3c_dma_flush(unsigned ch)
122{
123 return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_FLUSH);
124}
125
126static inline int s3c_dma_stop(unsigned ch)
127{
128 return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STOP);
129}
130
131static struct samsung_dma_ops s3c_dma_ops = {
132 .request = s3c_dma_request,
133 .release = s3c_dma_release,
fbb20e81 134 .config = s3c_dma_config,
c4e16625
BK
135 .prepare = s3c_dma_prepare,
136 .trigger = s3c_dma_trigger,
137 .started = s3c_dma_started,
138 .flush = s3c_dma_flush,
139 .stop = s3c_dma_stop,
140};
141
142void *s3c_dma_get_ops(void)
143{
144 return &s3c_dma_ops;
145}
146EXPORT_SYMBOL(s3c_dma_get_ops);
This page took 0.198441 seconds and 5 git commands to generate.