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, |
| 39 | struct samsung_dma_info *info) |
| 40 | { |
| 41 | struct cb_data *data; |
| 42 | |
| 43 | if (s3c2410_dma_request(dma_ch, info->client, NULL) < 0) { |
| 44 | s3c2410_dma_free(dma_ch, info->client); |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | data = kzalloc(sizeof(struct cb_data), GFP_KERNEL); |
| 49 | data->ch = dma_ch; |
| 50 | list_add_tail(&data->node, &dma_list); |
| 51 | |
Boojin Kim | 51ddf31 | 2011-09-02 09:44:44 +0900 | [diff] [blame] | 52 | s3c2410_dma_devconfig(dma_ch, info->direction, info->fifo); |
Boojin Kim | c4e1662 | 2011-09-02 09:44:35 +0900 | [diff] [blame] | 53 | |
| 54 | if (info->cap == DMA_CYCLIC) |
| 55 | s3c2410_dma_setflags(dma_ch, S3C2410_DMAF_CIRCULAR); |
| 56 | |
| 57 | s3c2410_dma_config(dma_ch, info->width); |
| 58 | |
| 59 | return (unsigned)dma_ch; |
| 60 | } |
| 61 | |
| 62 | static int s3c_dma_release(unsigned ch, struct s3c2410_dma_client *client) |
| 63 | { |
| 64 | struct cb_data *data; |
| 65 | |
| 66 | list_for_each_entry(data, &dma_list, node) |
| 67 | if (data->ch == ch) |
| 68 | break; |
| 69 | list_del(&data->node); |
| 70 | |
| 71 | s3c2410_dma_free(ch, client); |
| 72 | kfree(data); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static int s3c_dma_prepare(unsigned ch, struct samsung_dma_prep_info *info) |
| 78 | { |
| 79 | struct cb_data *data; |
| 80 | int len = (info->cap == DMA_CYCLIC) ? info->period : info->len; |
| 81 | |
| 82 | list_for_each_entry(data, &dma_list, node) |
| 83 | if (data->ch == ch) |
| 84 | break; |
| 85 | |
| 86 | if (!data->fp) { |
| 87 | s3c2410_dma_set_buffdone_fn(ch, s3c_dma_cb); |
| 88 | data->fp = info->fp; |
| 89 | data->fp_param = info->fp_param; |
| 90 | } |
| 91 | |
| 92 | s3c2410_dma_enqueue(ch, (void *)data, info->buf, len); |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static inline int s3c_dma_trigger(unsigned ch) |
| 98 | { |
| 99 | return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_START); |
| 100 | } |
| 101 | |
| 102 | static inline int s3c_dma_started(unsigned ch) |
| 103 | { |
| 104 | return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STARTED); |
| 105 | } |
| 106 | |
| 107 | static inline int s3c_dma_flush(unsigned ch) |
| 108 | { |
| 109 | return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_FLUSH); |
| 110 | } |
| 111 | |
| 112 | static inline int s3c_dma_stop(unsigned ch) |
| 113 | { |
| 114 | return s3c2410_dma_ctrl(ch, S3C2410_DMAOP_STOP); |
| 115 | } |
| 116 | |
| 117 | static struct samsung_dma_ops s3c_dma_ops = { |
| 118 | .request = s3c_dma_request, |
| 119 | .release = s3c_dma_release, |
| 120 | .prepare = s3c_dma_prepare, |
| 121 | .trigger = s3c_dma_trigger, |
| 122 | .started = s3c_dma_started, |
| 123 | .flush = s3c_dma_flush, |
| 124 | .stop = s3c_dma_stop, |
| 125 | }; |
| 126 | |
| 127 | void *s3c_dma_get_ops(void) |
| 128 | { |
| 129 | return &s3c_dma_ops; |
| 130 | } |
| 131 | EXPORT_SYMBOL(s3c_dma_get_ops); |