blob: 76682120f48cba82a756058aae93a4821b616da0 [file] [log] [blame]
Ilya Yanok06bb9202012-11-06 13:48:21 +00001/*
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 *
Tom Rinie2378802016-01-14 22:05:13 -050012 * SPDX-License-Identifier: GPL-2.0
Ilya Yanok06bb9202012-11-06 13:48:21 +000013 */
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) \
Tom Rini210ebce2017-03-14 11:08:10 -040026 && !defined(CONFIG_PPC64) && !defined(CONFIG_MIPS) \
27 && !defined(CONFIG_M68K)
Ilya Yanok06bb9202012-11-06 13:48:21 +000028static inline void readsl(const void __iomem *addr, void *buf, int len)
29 { insl((unsigned long)addr, buf, len); }
30static inline void readsw(const void __iomem *addr, void *buf, int len)
31 { insw((unsigned long)addr, buf, len); }
32static inline void readsb(const void __iomem *addr, void *buf, int len)
33 { insb((unsigned long)addr, buf, len); }
34
35static inline void writesl(const void __iomem *addr, const void *buf, int len)
36 { outsl((unsigned long)addr, buf, len); }
37static inline void writesw(const void __iomem *addr, const void *buf, int len)
38 { outsw((unsigned long)addr, buf, len); }
39static inline void writesb(const void __iomem *addr, const void *buf, int len)
40 { outsb((unsigned long)addr, buf, len); }
41
42#endif
43
Ilya Yanok06bb9202012-11-06 13:48:21 +000044/* NOTE: these offsets are all in bytes */
45
46static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
47 { return __raw_readw(addr + offset); }
48
49static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
50 { return __raw_readl(addr + offset); }
51
52
53static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
54 { __raw_writew(data, addr + offset); }
55
56static 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 */
65static 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
79static 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
94static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
95 { return __raw_readb(addr + offset); }
96
97static 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
Ilya Yanok06bb9202012-11-06 13:48:21 +0000102#endif