Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 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> |
Paul Gortmaker | 0c073e3 | 2011-10-08 23:24:48 -0400 | [diff] [blame] | 17 | #include <linux/export.h> |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 18 | |
| 19 | #include <mach/dma.h> |
| 20 | |
| 21 | struct cb_data { |
| 22 | void (*fp) (void *); |
| 23 | void *fp_param; |
| 24 | unsigned ch; |
| 25 | struct list_head node; |
| 26 | }; |
| 27 | |
| 28 | static LIST_HEAD(dma_list); |
| 29 | |
| 30 | static 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 | |
| 38 | static unsigned s3c_dma_request(enum dma_ch dma_ch, |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 39 | struct samsung_dma_req *param) |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 40 | { |
| 41 | struct cb_data *data; |
| 42 | |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 43 | if (s3c2410_dma_request(dma_ch, param->client, NULL) < 0) { |
| 44 | s3c2410_dma_free(dma_ch, param->client); |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 45 | return 0; |
| 46 | } |
| 47 | |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 48 | if (param->cap == DMA_CYCLIC) |
| 49 | s3c2410_dma_setflags(dma_ch, S3C2410_DMAF_CIRCULAR); |
| 50 | |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 51 | data = kzalloc(sizeof(struct cb_data), GFP_KERNEL); |
| 52 | data->ch = dma_ch; |
| 53 | list_add_tail(&data->node, &dma_list); |
| 54 | |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 55 | return (unsigned)dma_ch; |
| 56 | } |
| 57 | |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 58 | static int s3c_dma_release(unsigned ch, void *param) |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 59 | { |
| 60 | struct cb_data *data; |
| 61 | |
| 62 | list_for_each_entry(data, &dma_list, node) |
| 63 | if (data->ch == ch) |
| 64 | break; |
| 65 | list_del(&data->node); |
| 66 | |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 67 | s3c2410_dma_free(ch, param); |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 68 | kfree(data); |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 73 | static int s3c_dma_config(unsigned ch, struct samsung_dma_config *param) |
| 74 | { |
| 75 | s3c2410_dma_devconfig(ch, param->direction, param->fifo); |
| 76 | s3c2410_dma_config(ch, param->width); |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static int s3c_dma_prepare(unsigned ch, struct samsung_dma_prep *param) |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 82 | { |
| 83 | struct cb_data *data; |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 84 | int len = (param->cap == DMA_CYCLIC) ? param->period : param->len; |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 85 | |
| 86 | list_for_each_entry(data, &dma_list, node) |
| 87 | if (data->ch == ch) |
| 88 | break; |
| 89 | |
| 90 | if (!data->fp) { |
| 91 | s3c2410_dma_set_buffdone_fn(ch, s3c_dma_cb); |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 92 | data->fp = param->fp; |
| 93 | data->fp_param = param->fp_param; |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 94 | } |
| 95 | |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 96 | s3c2410_dma_enqueue(ch, (void *)data, param->buf, len); |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | static inline int s3c_dma_trigger(unsigned ch) |
| 102 | { |
| 103 | return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_START); |
| 104 | } |
| 105 | |
| 106 | static inline int s3c_dma_started(unsigned ch) |
| 107 | { |
| 108 | return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STARTED); |
| 109 | } |
| 110 | |
| 111 | static inline int s3c_dma_flush(unsigned ch) |
| 112 | { |
| 113 | return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_FLUSH); |
| 114 | } |
| 115 | |
| 116 | static inline int s3c_dma_stop(unsigned ch) |
| 117 | { |
| 118 | return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STOP); |
| 119 | } |
| 120 | |
| 121 | static struct samsung_dma_ops s3c_dma_ops = { |
| 122 | .request = s3c_dma_request, |
| 123 | .release = s3c_dma_release, |
Boojin Kim | fbb20e8 | 2012-06-19 13:26:53 +0900 | [diff] [blame] | 124 | .config = s3c_dma_config, |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 125 | .prepare = s3c_dma_prepare, |
| 126 | .trigger = s3c_dma_trigger, |
| 127 | .started = s3c_dma_started, |
| 128 | .flush = s3c_dma_flush, |
| 129 | .stop = s3c_dma_stop, |
| 130 | }; |
| 131 | |
| 132 | void *s3c_dma_get_ops(void) |
| 133 | { |
| 134 | return &s3c_dma_ops; |
| 135 | } |
| 136 | EXPORT_SYMBOL(s3c_dma_get_ops); |