xref: /openbmc/u-boot/drivers/usb/musb-new/musb_io.h (revision 1d2c0506)
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  * SPDX-License-Identifier:	GPL-2.0
13  */
14 
15 #ifndef __MUSB_LINUX_PLATFORM_ARCH_H__
16 #define __MUSB_LINUX_PLATFORM_ARCH_H__
17 
18 #ifndef __UBOOT__
19 #include <linux/io.h>
20 #else
21 #include <asm/io.h>
22 #endif
23 
24 #if !defined(CONFIG_ARM) && !defined(CONFIG_SUPERH) \
25 	&& !defined(CONFIG_AVR32) && !defined(CONFIG_PPC32) \
26 	&& !defined(CONFIG_PPC64) && !defined(CONFIG_BLACKFIN) \
27 	&& !defined(CONFIG_MIPS) && !defined(CONFIG_M68K)
28 static inline void readsl(const void __iomem *addr, void *buf, int len)
29 	{ insl((unsigned long)addr, buf, len); }
30 static inline void readsw(const void __iomem *addr, void *buf, int len)
31 	{ insw((unsigned long)addr, buf, len); }
32 static inline void readsb(const void __iomem *addr, void *buf, int len)
33 	{ insb((unsigned long)addr, buf, len); }
34 
35 static inline void writesl(const void __iomem *addr, const void *buf, int len)
36 	{ outsl((unsigned long)addr, buf, len); }
37 static inline void writesw(const void __iomem *addr, const void *buf, int len)
38 	{ outsw((unsigned long)addr, buf, len); }
39 static inline void writesb(const void __iomem *addr, const void *buf, int len)
40 	{ outsb((unsigned long)addr, buf, len); }
41 
42 #endif
43 
44 #ifndef CONFIG_BLACKFIN
45 
46 /* NOTE:  these offsets are all in bytes */
47 
48 static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
49 	{ return __raw_readw(addr + offset); }
50 
51 static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
52 	{ return __raw_readl(addr + offset); }
53 
54 
55 static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
56 	{ __raw_writew(data, addr + offset); }
57 
58 static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
59 	{ __raw_writel(data, addr + offset); }
60 
61 
62 #if defined(CONFIG_USB_MUSB_TUSB6010) || defined (CONFIG_USB_MUSB_TUSB6010_MODULE)
63 
64 /*
65  * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
66  */
67 static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
68 {
69 	u16 tmp;
70 	u8 val;
71 
72 	tmp = __raw_readw(addr + (offset & ~1));
73 	if (offset & 1)
74 		val = (tmp >> 8);
75 	else
76 		val = tmp & 0xff;
77 
78 	return val;
79 }
80 
81 static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
82 {
83 	u16 tmp;
84 
85 	tmp = __raw_readw(addr + (offset & ~1));
86 	if (offset & 1)
87 		tmp = (data << 8) | (tmp & 0xff);
88 	else
89 		tmp = (tmp & 0xff00) | data;
90 
91 	__raw_writew(tmp, addr + (offset & ~1));
92 }
93 
94 #else
95 
96 static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
97 	{ return __raw_readb(addr + offset); }
98 
99 static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
100 	{ __raw_writeb(data, addr + offset); }
101 
102 #endif	/* CONFIG_USB_MUSB_TUSB6010 */
103 
104 #else
105 
106 static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
107 	{ return (u8) (bfin_read16(addr + offset)); }
108 
109 static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
110 	{ return bfin_read16(addr + offset); }
111 
112 static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
113 	{ return (u32) (bfin_read16(addr + offset)); }
114 
115 static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
116 	{ bfin_write16(addr + offset, (u16) data); }
117 
118 static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
119 	{ bfin_write16(addr + offset, data); }
120 
121 static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
122 	{ bfin_write16(addr + offset, (u16) data); }
123 
124 #endif /* CONFIG_BLACKFIN */
125 
126 #endif
127