Loading...
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
10#ifndef __MUSB_LINUX_PLATFORM_ARCH_H__
11#define __MUSB_LINUX_PLATFORM_ARCH_H__
12
13#include <linux/io.h>
14
15#define musb_ep_select(_mbase, _epnum) musb->io.ep_select((_mbase), (_epnum))
16
17/**
18 * struct musb_io - IO functions for MUSB
19 * @ep_offset: platform specific function to get end point offset
20 * @ep_select: platform specific function to select end point
21 * @fifo_offset: platform specific function to get fifo offset
22 * @read_fifo: platform specific function to read fifo
23 * @write_fifo: platform specific function to write fifo
24 * @busctl_offset: platform specific function to get busctl offset
25 * @get_toggle: platform specific function to get toggle
26 * @set_toggle: platform specific function to set toggle
27 */
28struct musb_io {
29 u32 (*ep_offset)(u8 epnum, u16 offset);
30 void (*ep_select)(void __iomem *mbase, u8 epnum);
31 u32 (*fifo_offset)(u8 epnum);
32 void (*read_fifo)(struct musb_hw_ep *hw_ep, u16 len, u8 *buf);
33 void (*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf);
34 u32 (*busctl_offset)(u8 epnum, u16 offset);
35 u16 (*get_toggle)(struct musb_qh *qh, int is_out);
36 u16 (*set_toggle)(struct musb_qh *qh, int is_out, struct urb *urb);
37};
38
39/* Do not add new entries here, add them the struct musb_io instead */
40extern u8 (*musb_readb)(void __iomem *addr, u32 offset);
41extern void (*musb_writeb)(void __iomem *addr, u32 offset, u8 data);
42extern u8 (*musb_clearb)(void __iomem *addr, u32 offset);
43extern u16 (*musb_readw)(void __iomem *addr, u32 offset);
44extern void (*musb_writew)(void __iomem *addr, u32 offset, u16 data);
45extern u16 (*musb_clearw)(void __iomem *addr, u32 offset);
46extern u32 musb_readl(void __iomem *addr, u32 offset);
47extern void musb_writel(void __iomem *addr, u32 offset, u32 data);
48
49#endif
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 * 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.
16 *
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
21 *
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.
32 *
33 */
34
35#ifndef __MUSB_LINUX_PLATFORM_ARCH_H__
36#define __MUSB_LINUX_PLATFORM_ARCH_H__
37
38#include <linux/io.h>
39
40#ifndef CONFIG_BLACKFIN
41
42/* NOTE: these offsets are all in bytes */
43
44static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
45 { return __raw_readw(addr + offset); }
46
47static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
48 { return __raw_readl(addr + offset); }
49
50
51static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
52 { __raw_writew(data, addr + offset); }
53
54static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
55 { __raw_writel(data, addr + offset); }
56
57
58#if defined(CONFIG_USB_MUSB_TUSB6010) || defined (CONFIG_USB_MUSB_TUSB6010_MODULE)
59
60/*
61 * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
62 */
63static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
64{
65 u16 tmp;
66 u8 val;
67
68 tmp = __raw_readw(addr + (offset & ~1));
69 if (offset & 1)
70 val = (tmp >> 8);
71 else
72 val = tmp & 0xff;
73
74 return val;
75}
76
77static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
78{
79 u16 tmp;
80
81 tmp = __raw_readw(addr + (offset & ~1));
82 if (offset & 1)
83 tmp = (data << 8) | (tmp & 0xff);
84 else
85 tmp = (tmp & 0xff00) | data;
86
87 __raw_writew(tmp, addr + (offset & ~1));
88}
89
90#else
91
92static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
93 { return __raw_readb(addr + offset); }
94
95static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
96 { __raw_writeb(data, addr + offset); }
97
98#endif /* CONFIG_USB_MUSB_TUSB6010 */
99
100#else
101
102static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
103 { return (u8) (bfin_read16(addr + offset)); }
104
105static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
106 { return bfin_read16(addr + offset); }
107
108static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
109 { return (u32) (bfin_read16(addr + offset)); }
110
111static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
112 { bfin_write16(addr + offset, (u16) data); }
113
114static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
115 { bfin_write16(addr + offset, data); }
116
117static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
118 { bfin_write16(addr + offset, (u16) data); }
119
120#endif /* CONFIG_BLACKFIN */
121
122#endif