xref: /openbmc/u-boot/drivers/usb/musb-new/musb_io.h (revision f77d4410)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * MUSB OTG driver register I/O
4  *
5  * Copyright 2005 Mentor Graphics Corporation
6  * Copyright (C) 2005-2006 by Texas Instruments
7  * Copyright (C) 2006-2007 Nokia Corporation
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * version 2 as published by the Free Software Foundation.
12  */
13 
14 #ifndef __MUSB_LINUX_PLATFORM_ARCH_H__
15 #define __MUSB_LINUX_PLATFORM_ARCH_H__
16 
17 #ifndef __UBOOT__
18 #include <linux/io.h>
19 #else
20 #include <asm/io.h>
21 #endif
22 
23 #if !defined(CONFIG_ARM) && !defined(CONFIG_SUPERH) \
24 	&& !defined(CONFIG_PPC32) \
25 	&& !defined(CONFIG_PPC64) && !defined(CONFIG_MIPS) \
26 	&& !defined(CONFIG_M68K)
27 static inline void readsl(const void __iomem *addr, void *buf, int len)
28 	{ insl((unsigned long)addr, buf, len); }
29 static inline void readsw(const void __iomem *addr, void *buf, int len)
30 	{ insw((unsigned long)addr, buf, len); }
31 static inline void readsb(const void __iomem *addr, void *buf, int len)
32 	{ insb((unsigned long)addr, buf, len); }
33 
34 static inline void writesl(const void __iomem *addr, const void *buf, int len)
35 	{ outsl((unsigned long)addr, buf, len); }
36 static inline void writesw(const void __iomem *addr, const void *buf, int len)
37 	{ outsw((unsigned long)addr, buf, len); }
38 static inline void writesb(const void __iomem *addr, const void *buf, int len)
39 	{ outsb((unsigned long)addr, buf, len); }
40 
41 #endif
42 
43 /* NOTE:  these offsets are all in bytes */
44 
45 static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
46 	{ return __raw_readw(addr + offset); }
47 
48 static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
49 	{ return __raw_readl(addr + offset); }
50 
51 
52 static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
53 	{ __raw_writew(data, addr + offset); }
54 
55 static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
56 	{ __raw_writel(data, addr + offset); }
57 
58 
59 #if defined(CONFIG_USB_MUSB_TUSB6010) || defined (CONFIG_USB_MUSB_TUSB6010_MODULE)
60 
61 /*
62  * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
63  */
64 static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
65 {
66 	u16 tmp;
67 	u8 val;
68 
69 	tmp = __raw_readw(addr + (offset & ~1));
70 	if (offset & 1)
71 		val = (tmp >> 8);
72 	else
73 		val = tmp & 0xff;
74 
75 	return val;
76 }
77 
78 static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
79 {
80 	u16 tmp;
81 
82 	tmp = __raw_readw(addr + (offset & ~1));
83 	if (offset & 1)
84 		tmp = (data << 8) | (tmp & 0xff);
85 	else
86 		tmp = (tmp & 0xff00) | data;
87 
88 	__raw_writew(tmp, addr + (offset & ~1));
89 }
90 
91 #else
92 
93 static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
94 	{ return __raw_readb(addr + offset); }
95 
96 static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
97 	{ __raw_writeb(data, addr + offset); }
98 
99 #endif	/* CONFIG_USB_MUSB_TUSB6010 */
100 
101 #endif
102