diff options
author | Guennadi Liakhovetski <g.liakhovetski@gmx.de> | 2012-05-09 11:09:13 -0400 |
---|---|---|
committer | Vinod Koul <vinod.koul@linux.intel.com> | 2012-07-12 23:43:07 -0400 |
commit | 9a7b8e002e331d0599127f16613c32f425a14f2c (patch) | |
tree | 722718857a73296fea79a7960f46d22abcd30a06 /include/linux/shdma-base.h | |
parent | e95be94b8c25220aca09ed78c176f9b55a1482c8 (diff) |
dmaengine: add an shdma-base library
This patch extracts code from shdma.c, that does not directly deal with
hardware implementation details and can be re-used with diverse DMA
controller variants, found on SH-based SoCs.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Vinod Koul <vinod.koul@linux.intel.com>
Diffstat (limited to 'include/linux/shdma-base.h')
-rw-r--r-- | include/linux/shdma-base.h | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/include/linux/shdma-base.h b/include/linux/shdma-base.h new file mode 100644 index 000000000000..83efd1332b39 --- /dev/null +++ b/include/linux/shdma-base.h | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | * Dmaengine driver base library for DMA controllers, found on SH-based SoCs | ||
3 | * | ||
4 | * extracted from shdma.c and headers | ||
5 | * | ||
6 | * Copyright (C) 2011-2012 Guennadi Liakhovetski <g.liakhovetski@gmx.de> | ||
7 | * Copyright (C) 2009 Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com> | ||
8 | * Copyright (C) 2009 Renesas Solutions, Inc. All rights reserved. | ||
9 | * Copyright (C) 2007 Freescale Semiconductor, Inc. All rights reserved. | ||
10 | * | ||
11 | * This is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of version 2 of the GNU General Public License as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #ifndef SHDMA_BASE_H | ||
17 | #define SHDMA_BASE_H | ||
18 | |||
19 | #include <linux/dmaengine.h> | ||
20 | #include <linux/interrupt.h> | ||
21 | #include <linux/list.h> | ||
22 | #include <linux/types.h> | ||
23 | |||
24 | /** | ||
25 | * shdma_pm_state - DMA channel PM state | ||
26 | * SHDMA_PM_ESTABLISHED: either idle or during data transfer | ||
27 | * SHDMA_PM_BUSY: during the transfer preparation, when we have to | ||
28 | * drop the lock temporarily | ||
29 | * SHDMA_PM_PENDING: transfers pending | ||
30 | */ | ||
31 | enum shdma_pm_state { | ||
32 | SHDMA_PM_ESTABLISHED, | ||
33 | SHDMA_PM_BUSY, | ||
34 | SHDMA_PM_PENDING, | ||
35 | }; | ||
36 | |||
37 | struct device; | ||
38 | |||
39 | /* | ||
40 | * Drivers, using this library are expected to embed struct shdma_dev, | ||
41 | * struct shdma_chan, struct shdma_desc, and struct shdma_slave | ||
42 | * in their respective device, channel, descriptor and slave objects. | ||
43 | */ | ||
44 | |||
45 | struct shdma_slave { | ||
46 | unsigned int slave_id; | ||
47 | }; | ||
48 | |||
49 | struct shdma_desc { | ||
50 | struct list_head node; | ||
51 | struct dma_async_tx_descriptor async_tx; | ||
52 | enum dma_transfer_direction direction; | ||
53 | dma_cookie_t cookie; | ||
54 | int chunks; | ||
55 | int mark; | ||
56 | }; | ||
57 | |||
58 | struct shdma_chan { | ||
59 | spinlock_t chan_lock; /* Channel operation lock */ | ||
60 | struct list_head ld_queue; /* Link descriptors queue */ | ||
61 | struct list_head ld_free; /* Free link descriptors */ | ||
62 | struct dma_chan dma_chan; /* DMA channel */ | ||
63 | struct device *dev; /* Channel device */ | ||
64 | void *desc; /* buffer for descriptor array */ | ||
65 | int desc_num; /* desc count */ | ||
66 | size_t max_xfer_len; /* max transfer length */ | ||
67 | int id; /* Raw id of this channel */ | ||
68 | int irq; /* Channel IRQ */ | ||
69 | enum shdma_pm_state pm_state; | ||
70 | }; | ||
71 | |||
72 | /** | ||
73 | * struct shdma_ops - simple DMA driver operations | ||
74 | * desc_completed: return true, if this is the descriptor, that just has | ||
75 | * completed (atomic) | ||
76 | * halt_channel: stop DMA channel operation (atomic) | ||
77 | * channel_busy: return true, if the channel is busy (atomic) | ||
78 | * slave_addr: return slave DMA address | ||
79 | * desc_setup: set up the hardware specific descriptor portion (atomic) | ||
80 | * set_slave: bind channel to a slave | ||
81 | * setup_xfer: configure channel hardware for operation (atomic) | ||
82 | * start_xfer: start the DMA transfer (atomic) | ||
83 | * embedded_desc: return Nth struct shdma_desc pointer from the | ||
84 | * descriptor array | ||
85 | * chan_irq: process channel IRQ, return true if a transfer has | ||
86 | * completed (atomic) | ||
87 | */ | ||
88 | struct shdma_ops { | ||
89 | bool (*desc_completed)(struct shdma_chan *, struct shdma_desc *); | ||
90 | void (*halt_channel)(struct shdma_chan *); | ||
91 | bool (*channel_busy)(struct shdma_chan *); | ||
92 | dma_addr_t (*slave_addr)(struct shdma_chan *); | ||
93 | int (*desc_setup)(struct shdma_chan *, struct shdma_desc *, | ||
94 | dma_addr_t, dma_addr_t, size_t *); | ||
95 | int (*set_slave)(struct shdma_chan *, struct shdma_slave *); | ||
96 | void (*setup_xfer)(struct shdma_chan *, struct shdma_slave *); | ||
97 | void (*start_xfer)(struct shdma_chan *, struct shdma_desc *); | ||
98 | struct shdma_desc *(*embedded_desc)(void *, int); | ||
99 | bool (*chan_irq)(struct shdma_chan *, int); | ||
100 | }; | ||
101 | |||
102 | struct shdma_dev { | ||
103 | struct dma_device dma_dev; | ||
104 | struct shdma_chan **schan; | ||
105 | const struct shdma_ops *ops; | ||
106 | size_t desc_size; | ||
107 | }; | ||
108 | |||
109 | #define shdma_for_each_chan(c, d, i) for (i = 0, c = (d)->schan[0]; \ | ||
110 | i < (d)->dma_dev.chancnt; c = (d)->schan[++i]) | ||
111 | |||
112 | int shdma_request_irq(struct shdma_chan *, int, | ||
113 | unsigned long, const char *); | ||
114 | void shdma_free_irq(struct shdma_chan *); | ||
115 | bool shdma_reset(struct shdma_dev *sdev); | ||
116 | void shdma_chan_probe(struct shdma_dev *sdev, | ||
117 | struct shdma_chan *schan, int id); | ||
118 | void shdma_chan_remove(struct shdma_chan *schan); | ||
119 | int shdma_init(struct device *dev, struct shdma_dev *sdev, | ||
120 | int chan_num); | ||
121 | void shdma_cleanup(struct shdma_dev *sdev); | ||
122 | |||
123 | #endif | ||