xref: /openbmc/u-boot/drivers/usb/musb-new/musb_io.h (revision d891ab95)
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_MIPS) \
27 	&& !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 /* NOTE:  these offsets are all in bytes */
45 
46 static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
47 	{ return __raw_readw(addr + offset); }
48 
49 static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
50 	{ return __raw_readl(addr + offset); }
51 
52 
53 static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
54 	{ __raw_writew(data, addr + offset); }
55 
56 static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
57 	{ __raw_writel(data, addr + offset); }
58 
59 
60 #if defined(CONFIG_USB_MUSB_TUSB6010) || defined (CONFIG_USB_MUSB_TUSB6010_MODULE)
61 
62 /*
63  * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
64  */
65 static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
66 {
67 	u16 tmp;
68 	u8 val;
69 
70 	tmp = __raw_readw(addr + (offset & ~1));
71 	if (offset & 1)
72 		val = (tmp >> 8);
73 	else
74 		val = tmp & 0xff;
75 
76 	return val;
77 }
78 
79 static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
80 {
81 	u16 tmp;
82 
83 	tmp = __raw_readw(addr + (offset & ~1));
84 	if (offset & 1)
85 		tmp = (data << 8) | (tmp & 0xff);
86 	else
87 		tmp = (tmp & 0xff00) | data;
88 
89 	__raw_writew(tmp, addr + (offset & ~1));
90 }
91 
92 #else
93 
94 static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
95 	{ return __raw_readb(addr + offset); }
96 
97 static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
98 	{ __raw_writeb(data, addr + offset); }
99 
100 #endif	/* CONFIG_USB_MUSB_TUSB6010 */
101 
102 #endif
103