Merge branch 'next'
[u-boot/qq2440-u-boot.git] / drivers / usb / musb-new / musb_io.h
blob51730aee5215512bf6b4db495d71ed3fe2751f4b
1 /*
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
20 * 02110-1301 USA
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__
38 #ifndef __UBOOT__
39 #include <linux/io.h>
40 #else
41 #include <asm/io.h>
42 #endif
44 #if !defined(CONFIG_ARM) && !defined(CONFIG_SUPERH) \
45 && !defined(CONFIG_AVR32) && !defined(CONFIG_PPC32) \
46 && !defined(CONFIG_PPC64) && !defined(CONFIG_BLACKFIN) \
47 && !defined(CONFIG_MIPS) && !defined(CONFIG_M68K)
48 static inline void readsl(const void __iomem *addr, void *buf, int len)
49 { insl((unsigned long)addr, buf, len); }
50 static inline void readsw(const void __iomem *addr, void *buf, int len)
51 { insw((unsigned long)addr, buf, len); }
52 static inline void readsb(const void __iomem *addr, void *buf, int len)
53 { insb((unsigned long)addr, buf, len); }
55 static inline void writesl(const void __iomem *addr, const void *buf, int len)
56 { outsl((unsigned long)addr, buf, len); }
57 static inline void writesw(const void __iomem *addr, const void *buf, int len)
58 { outsw((unsigned long)addr, buf, len); }
59 static inline void writesb(const void __iomem *addr, const void *buf, int len)
60 { outsb((unsigned long)addr, buf, len); }
62 #endif
64 #ifndef CONFIG_BLACKFIN
66 /* NOTE: these offsets are all in bytes */
68 static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
69 { return __raw_readw(addr + offset); }
71 static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
72 { return __raw_readl(addr + offset); }
75 static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
76 { __raw_writew(data, addr + offset); }
78 static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
79 { __raw_writel(data, addr + offset); }
82 #if defined(CONFIG_USB_MUSB_TUSB6010) || defined (CONFIG_USB_MUSB_TUSB6010_MODULE)
85 * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
87 static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
89 u16 tmp;
90 u8 val;
92 tmp = __raw_readw(addr + (offset & ~1));
93 if (offset & 1)
94 val = (tmp >> 8);
95 else
96 val = tmp & 0xff;
98 return val;
101 static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
103 u16 tmp;
105 tmp = __raw_readw(addr + (offset & ~1));
106 if (offset & 1)
107 tmp = (data << 8) | (tmp & 0xff);
108 else
109 tmp = (tmp & 0xff00) | data;
111 __raw_writew(tmp, addr + (offset & ~1));
114 #else
116 static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
117 { return __raw_readb(addr + offset); }
119 static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
120 { __raw_writeb(data, addr + offset); }
122 #endif /* CONFIG_USB_MUSB_TUSB6010 */
124 #else
126 static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
127 { return (u8) (bfin_read16(addr + offset)); }
129 static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
130 { return bfin_read16(addr + offset); }
132 static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
133 { return (u32) (bfin_read16(addr + offset)); }
135 static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
136 { bfin_write16(addr + offset, (u16) data); }
138 static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
139 { bfin_write16(addr + offset, data); }
141 static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
142 { bfin_write16(addr + offset, (u16) data); }
144 #endif /* CONFIG_BLACKFIN */
146 #endif