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