blob: 0cc40aea3f5adbd9a78ff8557f246f476d1b97e2 [file] [log] [blame]
Boojin Kimc4e16622011-09-02 09:44:35 +09001/* 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>
Paul Gortmaker0c073e32011-10-08 23:24:48 -040017#include <linux/export.h>
Boojin Kimc4e16622011-09-02 09:44:35 +090018
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,
Padmavathi Vennae7ba5f12013-01-18 17:17:02 +053039 struct samsung_dma_req *param,
40 struct device *dev, char *ch_name)
Boojin Kimc4e16622011-09-02 09:44:35 +090041{
42 struct cb_data *data;
43
Boojin Kimfbb20e82012-06-19 13:26:53 +090044 if (s3c2410_dma_request(dma_ch, param->client, NULL) < 0) {
45 s3c2410_dma_free(dma_ch, param->client);
Boojin Kimc4e16622011-09-02 09:44:35 +090046 return 0;
47 }
48
Boojin Kimfbb20e82012-06-19 13:26:53 +090049 if (param->cap == DMA_CYCLIC)
50 s3c2410_dma_setflags(dma_ch, S3C2410_DMAF_CIRCULAR);
51
Boojin Kimc4e16622011-09-02 09:44:35 +090052 data = kzalloc(sizeof(struct cb_data), GFP_KERNEL);
53 data->ch = dma_ch;
54 list_add_tail(&data->node, &dma_list);
55
Boojin Kimc4e16622011-09-02 09:44:35 +090056 return (unsigned)dma_ch;
57}
58
Boojin Kimfbb20e82012-06-19 13:26:53 +090059static int s3c_dma_release(unsigned ch, void *param)
Boojin Kimc4e16622011-09-02 09:44:35 +090060{
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
Boojin Kimfbb20e82012-06-19 13:26:53 +090068 s3c2410_dma_free(ch, param);
Boojin Kimc4e16622011-09-02 09:44:35 +090069 kfree(data);
70
71 return 0;
72}
73
Boojin Kimfbb20e82012-06-19 13:26:53 +090074static 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)
Boojin Kimc4e16622011-09-02 09:44:35 +090083{
84 struct cb_data *data;
Boojin Kimfbb20e82012-06-19 13:26:53 +090085 int len = (param->cap == DMA_CYCLIC) ? param->period : param->len;
Boojin Kimc4e16622011-09-02 09:44:35 +090086
87 list_for_each_entry(data, &dma_list, node)
88 if (data->ch == ch)
89 break;
90
91 if (!data->fp) {
92 s3c2410_dma_set_buffdone_fn(ch, s3c_dma_cb);
Boojin Kimfbb20e82012-06-19 13:26:53 +090093 data->fp = param->fp;
94 data->fp_param = param->fp_param;
Boojin Kimc4e16622011-09-02 09:44:35 +090095 }
96
Boojin Kimfbb20e82012-06-19 13:26:53 +090097 s3c2410_dma_enqueue(ch, (void *)data, param->buf, len);
Boojin Kimc4e16622011-09-02 09:44:35 +090098
99 return 0;
100}
101
102static inline int s3c_dma_trigger(unsigned ch)
103{
104 return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_START);
105}
106
107static inline int s3c_dma_started(unsigned ch)
108{
109 return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STARTED);
110}
111
112static inline int s3c_dma_flush(unsigned ch)
113{
114 return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_FLUSH);
115}
116
117static inline int s3c_dma_stop(unsigned ch)
118{
119 return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STOP);
120}
121
122static struct samsung_dma_ops s3c_dma_ops = {
123 .request = s3c_dma_request,
124 .release = s3c_dma_release,
Boojin Kimfbb20e82012-06-19 13:26:53 +0900125 .config = s3c_dma_config,
Boojin Kimc4e16622011-09-02 09:44:35 +0900126 .prepare = s3c_dma_prepare,
127 .trigger = s3c_dma_trigger,
128 .started = s3c_dma_started,
129 .flush = s3c_dma_flush,
130 .stop = s3c_dma_stop,
131};
132
133void *s3c_dma_get_ops(void)
134{
135 return &s3c_dma_ops;
136}
137EXPORT_SYMBOL(s3c_dma_get_ops);