diff options
author | Bryan Wu <cooloney@kernel.org> | 2008-12-02 14:33:47 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-01-07 13:00:07 -0500 |
commit | 6995eb68aab70e79eedb710d7d6d1f22d8aea4a7 (patch) | |
tree | 6d34a3ee0e6a133010154812cc0170b7fb3a3e2f /drivers/usb/musb | |
parent | 2c557a4a98be67ea54dfd0e8497050a24b7311c6 (diff) |
USB: musb: enable low level DMA operation for Blackfin
- DMA registers in Blackfin have different layout
- DMA interrupt flags need to be cleared by software
Signed-off-by: Bryan Wu <cooloney@kernel.org>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/musb')
-rw-r--r-- | drivers/usb/musb/musbhsdma.c | 82 | ||||
-rw-r--r-- | drivers/usb/musb/musbhsdma.h | 149 |
2 files changed, 162 insertions, 69 deletions
diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c index d193b7849087..8662e9e159c3 100644 --- a/drivers/usb/musb/musbhsdma.c +++ b/drivers/usb/musb/musbhsdma.c | |||
@@ -34,58 +34,7 @@ | |||
34 | #include <linux/interrupt.h> | 34 | #include <linux/interrupt.h> |
35 | #include <linux/platform_device.h> | 35 | #include <linux/platform_device.h> |
36 | #include "musb_core.h" | 36 | #include "musb_core.h" |
37 | 37 | #include "musbhsdma.h" | |
38 | #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430) | ||
39 | #include "omap2430.h" | ||
40 | #endif | ||
41 | |||
42 | #define MUSB_HSDMA_BASE 0x200 | ||
43 | #define MUSB_HSDMA_INTR (MUSB_HSDMA_BASE + 0) | ||
44 | #define MUSB_HSDMA_CONTROL 0x4 | ||
45 | #define MUSB_HSDMA_ADDRESS 0x8 | ||
46 | #define MUSB_HSDMA_COUNT 0xc | ||
47 | |||
48 | #define MUSB_HSDMA_CHANNEL_OFFSET(_bchannel, _offset) \ | ||
49 | (MUSB_HSDMA_BASE + (_bchannel << 4) + _offset) | ||
50 | |||
51 | /* control register (16-bit): */ | ||
52 | #define MUSB_HSDMA_ENABLE_SHIFT 0 | ||
53 | #define MUSB_HSDMA_TRANSMIT_SHIFT 1 | ||
54 | #define MUSB_HSDMA_MODE1_SHIFT 2 | ||
55 | #define MUSB_HSDMA_IRQENABLE_SHIFT 3 | ||
56 | #define MUSB_HSDMA_ENDPOINT_SHIFT 4 | ||
57 | #define MUSB_HSDMA_BUSERROR_SHIFT 8 | ||
58 | #define MUSB_HSDMA_BURSTMODE_SHIFT 9 | ||
59 | #define MUSB_HSDMA_BURSTMODE (3 << MUSB_HSDMA_BURSTMODE_SHIFT) | ||
60 | #define MUSB_HSDMA_BURSTMODE_UNSPEC 0 | ||
61 | #define MUSB_HSDMA_BURSTMODE_INCR4 1 | ||
62 | #define MUSB_HSDMA_BURSTMODE_INCR8 2 | ||
63 | #define MUSB_HSDMA_BURSTMODE_INCR16 3 | ||
64 | |||
65 | #define MUSB_HSDMA_CHANNELS 8 | ||
66 | |||
67 | struct musb_dma_controller; | ||
68 | |||
69 | struct musb_dma_channel { | ||
70 | struct dma_channel channel; | ||
71 | struct musb_dma_controller *controller; | ||
72 | u32 start_addr; | ||
73 | u32 len; | ||
74 | u16 max_packet_sz; | ||
75 | u8 idx; | ||
76 | u8 epnum; | ||
77 | u8 transmit; | ||
78 | }; | ||
79 | |||
80 | struct musb_dma_controller { | ||
81 | struct dma_controller controller; | ||
82 | struct musb_dma_channel channel[MUSB_HSDMA_CHANNELS]; | ||
83 | void *private_data; | ||
84 | void __iomem *base; | ||
85 | u8 channel_count; | ||
86 | u8 used_channels; | ||
87 | u8 irq; | ||
88 | }; | ||
89 | 38 | ||
90 | static int dma_controller_start(struct dma_controller *c) | 39 | static int dma_controller_start(struct dma_controller *c) |
91 | { | 40 | { |
@@ -203,12 +152,8 @@ static void configure_channel(struct dma_channel *channel, | |||
203 | : 0); | 152 | : 0); |
204 | 153 | ||
205 | /* address/count */ | 154 | /* address/count */ |
206 | musb_writel(mbase, | 155 | musb_write_hsdma_addr(mbase, bchannel, dma_addr); |
207 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS), | 156 | musb_write_hsdma_count(mbase, bchannel, len); |
208 | dma_addr); | ||
209 | musb_writel(mbase, | ||
210 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT), | ||
211 | len); | ||
212 | 157 | ||
213 | /* control (this should start things) */ | 158 | /* control (this should start things) */ |
214 | musb_writew(mbase, | 159 | musb_writew(mbase, |
@@ -279,13 +224,8 @@ static int dma_channel_abort(struct dma_channel *channel) | |||
279 | musb_writew(mbase, | 224 | musb_writew(mbase, |
280 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_CONTROL), | 225 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_CONTROL), |
281 | 0); | 226 | 0); |
282 | musb_writel(mbase, | 227 | musb_write_hsdma_addr(mbase, bchannel, 0); |
283 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS), | 228 | musb_write_hsdma_count(mbase, bchannel, 0); |
284 | 0); | ||
285 | musb_writel(mbase, | ||
286 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT), | ||
287 | 0); | ||
288 | |||
289 | channel->status = MUSB_DMA_STATUS_FREE; | 229 | channel->status = MUSB_DMA_STATUS_FREE; |
290 | } | 230 | } |
291 | 231 | ||
@@ -333,10 +273,8 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data) | |||
333 | } else { | 273 | } else { |
334 | u8 devctl; | 274 | u8 devctl; |
335 | 275 | ||
336 | addr = musb_readl(mbase, | 276 | addr = musb_read_hsdma_addr(mbase, |
337 | MUSB_HSDMA_CHANNEL_OFFSET( | 277 | bchannel); |
338 | bchannel, | ||
339 | MUSB_HSDMA_ADDRESS)); | ||
340 | channel->actual_len = addr | 278 | channel->actual_len = addr |
341 | - musb_channel->start_addr; | 279 | - musb_channel->start_addr; |
342 | 280 | ||
@@ -375,6 +313,12 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data) | |||
375 | } | 313 | } |
376 | } | 314 | } |
377 | } | 315 | } |
316 | |||
317 | #ifdef CONFIG_BLACKFIN | ||
318 | /* Clear DMA interrup flags */ | ||
319 | musb_writeb(mbase, MUSB_HSDMA_INTR, int_hsdma); | ||
320 | #endif | ||
321 | |||
378 | retval = IRQ_HANDLED; | 322 | retval = IRQ_HANDLED; |
379 | done: | 323 | done: |
380 | spin_unlock_irqrestore(&musb->lock, flags); | 324 | spin_unlock_irqrestore(&musb->lock, flags); |
diff --git a/drivers/usb/musb/musbhsdma.h b/drivers/usb/musb/musbhsdma.h new file mode 100644 index 000000000000..1299d92dc83f --- /dev/null +++ b/drivers/usb/musb/musbhsdma.h | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | * MUSB OTG driver - support for Mentor's DMA controller | ||
3 | * | ||
4 | * Copyright 2005 Mentor Graphics Corporation | ||
5 | * Copyright (C) 2005-2007 by Texas Instruments | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, but | ||
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
19 | * 02110-1301 USA | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED | ||
22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN | ||
24 | * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
26 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
28 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
30 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
31 | * | ||
32 | */ | ||
33 | |||
34 | #if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430) | ||
35 | #include "omap2430.h" | ||
36 | #endif | ||
37 | |||
38 | #ifndef CONFIG_BLACKFIN | ||
39 | |||
40 | #define MUSB_HSDMA_BASE 0x200 | ||
41 | #define MUSB_HSDMA_INTR (MUSB_HSDMA_BASE + 0) | ||
42 | #define MUSB_HSDMA_CONTROL 0x4 | ||
43 | #define MUSB_HSDMA_ADDRESS 0x8 | ||
44 | #define MUSB_HSDMA_COUNT 0xc | ||
45 | |||
46 | #define MUSB_HSDMA_CHANNEL_OFFSET(_bchannel, _offset) \ | ||
47 | (MUSB_HSDMA_BASE + (_bchannel << 4) + _offset) | ||
48 | |||
49 | #define musb_read_hsdma_addr(mbase, bchannel) \ | ||
50 | musb_readl(mbase, \ | ||
51 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS)) | ||
52 | |||
53 | #define musb_write_hsdma_addr(mbase, bchannel, addr) \ | ||
54 | musb_writel(mbase, \ | ||
55 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS), \ | ||
56 | addr) | ||
57 | |||
58 | #define musb_write_hsdma_count(mbase, bchannel, len) \ | ||
59 | musb_writel(mbase, \ | ||
60 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT), \ | ||
61 | len) | ||
62 | #else | ||
63 | |||
64 | #define MUSB_HSDMA_BASE 0x400 | ||
65 | #define MUSB_HSDMA_INTR (MUSB_HSDMA_BASE + 0) | ||
66 | #define MUSB_HSDMA_CONTROL 0x04 | ||
67 | #define MUSB_HSDMA_ADDR_LOW 0x08 | ||
68 | #define MUSB_HSDMA_ADDR_HIGH 0x0C | ||
69 | #define MUSB_HSDMA_COUNT_LOW 0x10 | ||
70 | #define MUSB_HSDMA_COUNT_HIGH 0x14 | ||
71 | |||
72 | #define MUSB_HSDMA_CHANNEL_OFFSET(_bchannel, _offset) \ | ||
73 | (MUSB_HSDMA_BASE + (_bchannel * 0x20) + _offset) | ||
74 | |||
75 | static inline u32 musb_read_hsdma_addr(void __iomem *mbase, u8 bchannel) | ||
76 | { | ||
77 | u32 addr = musb_readw(mbase, | ||
78 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_HIGH)); | ||
79 | |||
80 | addr = addr << 16; | ||
81 | |||
82 | addr |= musb_readw(mbase, | ||
83 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_LOW)); | ||
84 | |||
85 | return addr; | ||
86 | } | ||
87 | |||
88 | static inline void musb_write_hsdma_addr(void __iomem *mbase, | ||
89 | u8 bchannel, dma_addr_t dma_addr) | ||
90 | { | ||
91 | musb_writew(mbase, | ||
92 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_LOW), | ||
93 | ((u16)((u32) dma_addr & 0xFFFF))); | ||
94 | musb_writew(mbase, | ||
95 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDR_HIGH), | ||
96 | ((u16)(((u32) dma_addr >> 16) & 0xFFFF))); | ||
97 | } | ||
98 | |||
99 | static inline void musb_write_hsdma_count(void __iomem *mbase, | ||
100 | u8 bchannel, u32 len) | ||
101 | { | ||
102 | musb_writew(mbase, | ||
103 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_LOW), | ||
104 | ((u16)((u32) len & 0xFFFF))); | ||
105 | musb_writew(mbase, | ||
106 | MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_HIGH), | ||
107 | ((u16)(((u32) len >> 16) & 0xFFFF))); | ||
108 | } | ||
109 | |||
110 | #endif /* CONFIG_BLACKFIN */ | ||
111 | |||
112 | /* control register (16-bit): */ | ||
113 | #define MUSB_HSDMA_ENABLE_SHIFT 0 | ||
114 | #define MUSB_HSDMA_TRANSMIT_SHIFT 1 | ||
115 | #define MUSB_HSDMA_MODE1_SHIFT 2 | ||
116 | #define MUSB_HSDMA_IRQENABLE_SHIFT 3 | ||
117 | #define MUSB_HSDMA_ENDPOINT_SHIFT 4 | ||
118 | #define MUSB_HSDMA_BUSERROR_SHIFT 8 | ||
119 | #define MUSB_HSDMA_BURSTMODE_SHIFT 9 | ||
120 | #define MUSB_HSDMA_BURSTMODE (3 << MUSB_HSDMA_BURSTMODE_SHIFT) | ||
121 | #define MUSB_HSDMA_BURSTMODE_UNSPEC 0 | ||
122 | #define MUSB_HSDMA_BURSTMODE_INCR4 1 | ||
123 | #define MUSB_HSDMA_BURSTMODE_INCR8 2 | ||
124 | #define MUSB_HSDMA_BURSTMODE_INCR16 3 | ||
125 | |||
126 | #define MUSB_HSDMA_CHANNELS 8 | ||
127 | |||
128 | struct musb_dma_controller; | ||
129 | |||
130 | struct musb_dma_channel { | ||
131 | struct dma_channel channel; | ||
132 | struct musb_dma_controller *controller; | ||
133 | u32 start_addr; | ||
134 | u32 len; | ||
135 | u16 max_packet_sz; | ||
136 | u8 idx; | ||
137 | u8 epnum; | ||
138 | u8 transmit; | ||
139 | }; | ||
140 | |||
141 | struct musb_dma_controller { | ||
142 | struct dma_controller controller; | ||
143 | struct musb_dma_channel channel[MUSB_HSDMA_CHANNELS]; | ||
144 | void *private_data; | ||
145 | void __iomem *base; | ||
146 | u8 channel_count; | ||
147 | u8 used_channels; | ||
148 | u8 irq; | ||
149 | }; | ||