Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | /* |
2 | * MUSB OTG driver register I/O | |
3 | * | |
4 | * Copyright 2005 Mentor Graphics Corporation | |
5 | * Copyright (C) 2005-2006 by Texas Instruments | |
6 | * Copyright (C) 2006-2007 Nokia Corporation | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public License | |
10 | * version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
20 | * 02110-1301 USA | |
21 | * | |
22 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED | |
23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN | |
25 | * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |
28 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
29 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
32 | * | |
33 | */ | |
34 | ||
35 | #ifndef __MUSB_LINUX_PLATFORM_ARCH_H__ | |
36 | #define __MUSB_LINUX_PLATFORM_ARCH_H__ | |
37 | ||
38 | #include <linux/io.h> | |
39 | #include <linux/spinlock.h> | |
40 | ||
41 | extern bool mtk_usb_power; | |
42 | extern bool usb_enable_clock(bool enable); | |
43 | extern spinlock_t usb_io_lock; | |
44 | ||
45 | static inline u16 musb_readw(const void __iomem *addr, unsigned offset) | |
46 | { | |
47 | u16 rc = 0; | |
48 | ||
49 | if (mtk_usb_power) { | |
50 | rc = readw(addr + offset); | |
51 | } else { | |
52 | unsigned long flags = 0; | |
53 | spin_lock_irqsave(&usb_io_lock, flags); | |
54 | usb_enable_clock(true); | |
55 | DBG(0, "[MUSB]:access %s function when usb clock is off 0x%X\n", __func__, offset); | |
56 | rc = readw(addr + offset); | |
57 | usb_enable_clock(false); | |
58 | spin_unlock_irqrestore(&usb_io_lock, flags); | |
59 | } | |
60 | return rc; | |
61 | } | |
62 | ||
63 | static inline u32 musb_readl(const void __iomem *addr, unsigned offset) | |
64 | { | |
65 | u32 rc = 0; | |
66 | ||
67 | if (mtk_usb_power) { | |
68 | rc = readl(addr + offset); | |
69 | } else { | |
70 | unsigned long flags = 0; | |
71 | spin_lock_irqsave(&usb_io_lock, flags); | |
72 | usb_enable_clock(true); | |
73 | DBG(0, "[MUSB]:access %s function when usb clock is off 0x%X\n", __func__, offset); | |
74 | rc = readl(addr + offset); | |
75 | usb_enable_clock(false); | |
76 | spin_unlock_irqrestore(&usb_io_lock, flags); | |
77 | } | |
78 | return rc; | |
79 | } | |
80 | ||
81 | ||
82 | static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data) | |
83 | { | |
84 | if (mtk_usb_power) { | |
85 | writew(data, addr + offset); | |
86 | } else { | |
87 | unsigned long flags = 0; | |
88 | spin_lock_irqsave(&usb_io_lock, flags); | |
89 | usb_enable_clock(true); | |
90 | DBG(0, "[MUSB]:access %s function when usb clock is off 0x%X\n", __func__, offset); | |
91 | writew(data, addr + offset); | |
92 | usb_enable_clock(false); | |
93 | spin_unlock_irqrestore(&usb_io_lock, flags); | |
94 | } | |
95 | } | |
96 | ||
97 | static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data) | |
98 | { | |
99 | if (mtk_usb_power) { | |
100 | writel(data, addr + offset); | |
101 | } else { | |
102 | unsigned long flags = 0; | |
103 | spin_lock_irqsave(&usb_io_lock, flags); | |
104 | usb_enable_clock(true); | |
105 | DBG(0, "[MUSB]:access %s function when usb clock is off 0x%X\n", __func__, offset); | |
106 | writel(data, addr + offset); | |
107 | usb_enable_clock(false); | |
108 | spin_unlock_irqrestore(&usb_io_lock, flags); | |
109 | } | |
110 | } | |
111 | ||
112 | static inline u8 musb_readb(const void __iomem *addr, unsigned offset) | |
113 | { | |
114 | u8 rc = 0; | |
115 | ||
116 | if (mtk_usb_power) { | |
117 | rc = readb(addr + offset); | |
118 | } else { | |
119 | unsigned long flags = 0; | |
120 | spin_lock_irqsave(&usb_io_lock, flags); | |
121 | usb_enable_clock(true); | |
122 | DBG(0, "[MUSB]:access %s function when usb clock is off 0x%X\n", __func__, offset); | |
123 | rc = readb(addr + offset); | |
124 | usb_enable_clock(false); | |
125 | spin_unlock_irqrestore(&usb_io_lock, flags); | |
126 | } | |
127 | return rc; | |
128 | } | |
129 | ||
130 | static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data) | |
131 | { | |
132 | if (mtk_usb_power) { | |
133 | writeb(data, addr + offset); | |
134 | } else { | |
135 | unsigned long flags = 0; | |
136 | spin_lock_irqsave(&usb_io_lock, flags); | |
137 | usb_enable_clock(true); | |
138 | DBG(0, "[MUSB]:access %s function when usb clock is off 0x%X\n", __func__, offset); | |
139 | writeb(data, addr + offset); | |
140 | usb_enable_clock(false); | |
141 | spin_unlock_irqrestore(&usb_io_lock, flags); | |
142 | } | |
143 | } | |
144 | ||
145 | #if 0 | |
146 | struct musb_reg { | |
147 | u8(*_readb) (u32 addr, u32 offset); | |
148 | u16(*_readw) (u32 addr, u32 offset); | |
149 | u32(*_readl) (u32 addr, u32 offset); | |
150 | void (*_writeb) (u32 addr, u32 offset, u8 data); | |
151 | void (*_writew) (u32 addr, u32 offset, u16 data); | |
152 | void (*_writel) (u32 addr, u32 offset, u32 data); | |
153 | }; | |
154 | /* NOTE: these offsets are all in bytes */ | |
155 | ||
156 | static inline u16 power_on_readw(const void __iomem *addr, unsigned offset) | |
157 | { | |
158 | return __raw_readw(addr + offset); | |
159 | } | |
160 | ||
161 | static inline u32 power_on_readl(const void __iomem *addr, unsigned offset) | |
162 | { | |
163 | return __raw_readl(addr + offset); | |
164 | } | |
165 | ||
166 | ||
167 | static inline void power_on_writew(void __iomem *addr, unsigned offset, u16 data) | |
168 | { | |
169 | __raw_writew(data, addr + offset); | |
170 | } | |
171 | ||
172 | static inline void power_on_writel(void __iomem *addr, unsigned offset, u32 data) | |
173 | { | |
174 | __raw_writel(data, addr + offset); | |
175 | } | |
176 | ||
177 | static inline u8 power_on_readb(const void __iomem *addr, unsigned offset) | |
178 | { | |
179 | return __raw_readb(addr + offset); | |
180 | } | |
181 | ||
182 | static inline void power_on_writeb(void __iomem *addr, unsigned offset, u8 data) | |
183 | { | |
184 | __raw_writeb(data, addr + offset); | |
185 | } | |
186 | ||
187 | ||
188 | static inline u16 power_off_readw(const void __iomem *addr, unsigned offset) | |
189 | { | |
190 | printk("MUSB:access %s function when usb clock is off\n", __func__); | |
191 | return 0; | |
192 | } | |
193 | ||
194 | static inline u32 power_off_readl(const void __iomem *addr, unsigned offset) | |
195 | { | |
196 | printk("MUSB:access %s function when usb clock is off\n", __func__); | |
197 | return 0; | |
198 | } | |
199 | ||
200 | ||
201 | static inline void power_off_writew(void __iomem *addr, unsigned offset, u16 data) | |
202 | { | |
203 | printk("MUSB:access %s function when usb clock is off\n", __func__); | |
204 | } | |
205 | ||
206 | static inline void power_off_writel(void __iomem *addr, unsigned offset, u32 data) | |
207 | { | |
208 | printk("MUSB:access %s function when usb clock is off\n", __func__); | |
209 | } | |
210 | ||
211 | static inline u8 power_off_readb(const void __iomem *addr, unsigned offset) | |
212 | { | |
213 | printk("MUSB:access %s function when usb clock is off\n", __func__); | |
214 | return 0; | |
215 | } | |
216 | ||
217 | static inline void power_off_writeb(void __iomem *addr, unsigned offset, u8 data) | |
218 | { | |
219 | printk("MUSB:access %s function when usb clock is off\n", __func__); | |
220 | } | |
221 | ||
222 | extern struct musb_reg musb_reg; | |
223 | #define musb_readb musb_reg._readb | |
224 | #define musb_readw musb_reg._readl | |
225 | #define musb_readl musb_reg._readw | |
226 | #define musb_writeb musb_reg._writeb | |
227 | #define musb_writew musb_reg._writew | |
228 | #define musb_writel musb_reg._writel | |
229 | #endif | |
230 | ||
231 | #endif |