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