2 * MUSB OTG driver register I/O
4 * Copyright 2005 Mentor Graphics Corporation
5 * Copyright (C) 2005-2006 by Texas Instruments
6 * Copyright (C) 2006-2007 Nokia Corporation
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.
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.
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
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.
35 #ifndef __MUSB_LINUX_PLATFORM_ARCH_H__
36 #define __MUSB_LINUX_PLATFORM_ARCH_H__
39 #include <linux/spinlock.h>
41 extern bool mtk_usb_power
;
42 extern bool usb_enable_clock(bool enable
);
43 extern spinlock_t usb_io_lock
;
45 static inline u16
musb_readw(const void __iomem
*addr
, unsigned offset
)
50 rc
= readw(addr
+ offset
);
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
);
63 static inline u32
musb_readl(const void __iomem
*addr
, unsigned offset
)
68 rc
= readl(addr
+ offset
);
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
);
82 static inline void musb_writew(void __iomem
*addr
, unsigned offset
, u16 data
)
85 writew(data
, addr
+ offset
);
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
);
97 static inline void musb_writel(void __iomem
*addr
, unsigned offset
, u32 data
)
100 writel(data
, addr
+ offset
);
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
);
112 static inline u8
musb_readb(const void __iomem
*addr
, unsigned offset
)
117 rc
= readb(addr
+ offset
);
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
);
130 static inline void musb_writeb(void __iomem
*addr
, unsigned offset
, u8 data
)
133 writeb(data
, addr
+ offset
);
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
);
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
);
154 /* NOTE: these offsets are all in bytes */
156 static inline u16
power_on_readw(const void __iomem
*addr
, unsigned offset
)
158 return __raw_readw(addr
+ offset
);
161 static inline u32
power_on_readl(const void __iomem
*addr
, unsigned offset
)
163 return __raw_readl(addr
+ offset
);
167 static inline void power_on_writew(void __iomem
*addr
, unsigned offset
, u16 data
)
169 __raw_writew(data
, addr
+ offset
);
172 static inline void power_on_writel(void __iomem
*addr
, unsigned offset
, u32 data
)
174 __raw_writel(data
, addr
+ offset
);
177 static inline u8
power_on_readb(const void __iomem
*addr
, unsigned offset
)
179 return __raw_readb(addr
+ offset
);
182 static inline void power_on_writeb(void __iomem
*addr
, unsigned offset
, u8 data
)
184 __raw_writeb(data
, addr
+ offset
);
188 static inline u16
power_off_readw(const void __iomem
*addr
, unsigned offset
)
190 printk("MUSB:access %s function when usb clock is off\n", __func__
);
194 static inline u32
power_off_readl(const void __iomem
*addr
, unsigned offset
)
196 printk("MUSB:access %s function when usb clock is off\n", __func__
);
201 static inline void power_off_writew(void __iomem
*addr
, unsigned offset
, u16 data
)
203 printk("MUSB:access %s function when usb clock is off\n", __func__
);
206 static inline void power_off_writel(void __iomem
*addr
, unsigned offset
, u32 data
)
208 printk("MUSB:access %s function when usb clock is off\n", __func__
);
211 static inline u8
power_off_readb(const void __iomem
*addr
, unsigned offset
)
213 printk("MUSB:access %s function when usb clock is off\n", __func__
);
217 static inline void power_off_writeb(void __iomem
*addr
, unsigned offset
, u8 data
)
219 printk("MUSB:access %s function when usb clock is off\n", __func__
);
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