1 /* linux/arch/arm/plat-samsung/dma-ops.c
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
6 * Samsung 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/amba/pl330.h>
16 #include <linux/scatterlist.h>
20 static inline bool pl330_filter(struct dma_chan
*chan
, void *param
)
22 struct dma_pl330_peri
*peri
= chan
->private;
23 return peri
->peri_id
== (unsigned)param
;
26 static unsigned samsung_dmadev_request(enum dma_ch dma_ch
,
27 struct samsung_dma_info
*info
)
29 struct dma_chan
*chan
;
31 struct dma_slave_config slave_config
;
34 dma_cap_set(info
->cap
, mask
);
36 chan
= dma_request_channel(mask
, pl330_filter
, (void *)dma_ch
);
38 if (info
->direction
== DMA_DEV_TO_MEM
) {
39 memset(&slave_config
, 0, sizeof(struct dma_slave_config
));
40 slave_config
.direction
= info
->direction
;
41 slave_config
.src_addr
= info
->fifo
;
42 slave_config
.src_addr_width
= info
->width
;
43 slave_config
.src_maxburst
= 1;
44 dmaengine_slave_config(chan
, &slave_config
);
45 } else if (info
->direction
== DMA_MEM_TO_DEV
) {
46 memset(&slave_config
, 0, sizeof(struct dma_slave_config
));
47 slave_config
.direction
= info
->direction
;
48 slave_config
.dst_addr
= info
->fifo
;
49 slave_config
.dst_addr_width
= info
->width
;
50 slave_config
.dst_maxburst
= 1;
51 dmaengine_slave_config(chan
, &slave_config
);
54 return (unsigned)chan
;
57 static int samsung_dmadev_release(unsigned ch
,
58 struct s3c2410_dma_client
*client
)
60 dma_release_channel((struct dma_chan
*)ch
);
65 static int samsung_dmadev_prepare(unsigned ch
,
66 struct samsung_dma_prep_info
*info
)
68 struct scatterlist sg
;
69 struct dma_chan
*chan
= (struct dma_chan
*)ch
;
70 struct dma_async_tx_descriptor
*desc
;
74 sg_init_table(&sg
, 1);
75 sg_dma_len(&sg
) = info
->len
;
76 sg_set_page(&sg
, pfn_to_page(PFN_DOWN(info
->buf
)),
77 info
->len
, offset_in_page(info
->buf
));
78 sg_dma_address(&sg
) = info
->buf
;
80 desc
= chan
->device
->device_prep_slave_sg(chan
,
81 &sg
, 1, info
->direction
, DMA_PREP_INTERRUPT
);
84 desc
= chan
->device
->device_prep_dma_cyclic(chan
,
85 info
->buf
, info
->len
, info
->period
, info
->direction
);
88 dev_err(&chan
->dev
->device
, "unsupported format\n");
93 dev_err(&chan
->dev
->device
, "cannot prepare cyclic dma\n");
97 desc
->callback
= info
->fp
;
98 desc
->callback_param
= info
->fp_param
;
100 dmaengine_submit((struct dma_async_tx_descriptor
*)desc
);
105 static inline int samsung_dmadev_trigger(unsigned ch
)
107 dma_async_issue_pending((struct dma_chan
*)ch
);
112 static inline int samsung_dmadev_flush(unsigned ch
)
114 return dmaengine_terminate_all((struct dma_chan
*)ch
);
117 struct samsung_dma_ops dmadev_ops
= {
118 .request
= samsung_dmadev_request
,
119 .release
= samsung_dmadev_release
,
120 .prepare
= samsung_dmadev_prepare
,
121 .trigger
= samsung_dmadev_trigger
,
123 .flush
= samsung_dmadev_flush
,
124 .stop
= samsung_dmadev_flush
,
127 void *samsung_dmadev_get_ops(void)
131 EXPORT_SYMBOL(samsung_dmadev_get_ops
);