1 /* linux/arch/arm/plat-samsung/s3c-dma-ops.c
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
6 * Samsung S3C-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/slab.h>
16 #include <linux/types.h>
17 #include <linux/export.h>
25 struct list_head node
;
28 static LIST_HEAD(dma_list
);
30 static void s3c_dma_cb(struct s3c2410_dma_chan
*channel
, void *param
,
31 int size
, enum s3c2410_dma_buffresult res
)
33 struct cb_data
*data
= param
;
35 data
->fp(data
->fp_param
);
38 static unsigned s3c_dma_request(enum dma_ch dma_ch
,
39 struct samsung_dma_req
*param
,
40 struct device
*dev
, char *ch_name
)
44 if (s3c2410_dma_request(dma_ch
, param
->client
, NULL
) < 0) {
45 s3c2410_dma_free(dma_ch
, param
->client
);
49 if (param
->cap
== DMA_CYCLIC
)
50 s3c2410_dma_setflags(dma_ch
, S3C2410_DMAF_CIRCULAR
);
52 data
= kzalloc(sizeof(struct cb_data
), GFP_KERNEL
);
54 list_add_tail(&data
->node
, &dma_list
);
56 return (unsigned)dma_ch
;
59 static int s3c_dma_release(unsigned ch
, void *param
)
63 list_for_each_entry(data
, &dma_list
, node
)
66 list_del(&data
->node
);
68 s3c2410_dma_free(ch
, param
);
74 static int s3c_dma_config(unsigned ch
, struct samsung_dma_config
*param
)
76 s3c2410_dma_devconfig(ch
, param
->direction
, param
->fifo
);
77 s3c2410_dma_config(ch
, param
->width
);
82 static int s3c_dma_prepare(unsigned ch
, struct samsung_dma_prep
*param
)
85 dma_addr_t pos
= param
->buf
;
86 dma_addr_t end
= param
->buf
+ param
->len
;
88 list_for_each_entry(data
, &dma_list
, node
)
93 s3c2410_dma_set_buffdone_fn(ch
, s3c_dma_cb
);
95 data
->fp_param
= param
->fp_param
;
98 if (param
->cap
!= DMA_CYCLIC
) {
99 s3c2410_dma_enqueue(ch
, (void *)data
, param
->buf
, param
->len
);
104 s3c2410_dma_enqueue(ch
, (void *)data
, pos
, param
->period
);
105 pos
+= param
->period
;
111 static inline int s3c_dma_trigger(unsigned ch
)
113 return s3c2410_dma_ctrl(ch
, S3C2410_DMAOP_START
);
116 static inline int s3c_dma_started(unsigned ch
)
118 return s3c2410_dma_ctrl(ch
, S3C2410_DMAOP_STARTED
);
121 static inline int s3c_dma_flush(unsigned ch
)
123 return s3c2410_dma_ctrl(ch
, S3C2410_DMAOP_FLUSH
);
126 static inline int s3c_dma_stop(unsigned ch
)
128 return s3c2410_dma_ctrl(ch
, S3C2410_DMAOP_STOP
);
131 static struct samsung_dma_ops s3c_dma_ops
= {
132 .request
= s3c_dma_request
,
133 .release
= s3c_dma_release
,
134 .config
= s3c_dma_config
,
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
,
142 void *s3c_dma_get_ops(void)
146 EXPORT_SYMBOL(s3c_dma_get_ops
);