blob: 0ced19919ef1d4cbc6a1ebae0ca55fc391ab9fed [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Ilya Yanok06bb9202012-11-06 13:48:21 +00002/*
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.
Ilya Yanok06bb9202012-11-06 13:48:21 +000012 */
13
14#ifndef __MUSB_LINUX_PLATFORM_ARCH_H__
15#define __MUSB_LINUX_PLATFORM_ARCH_H__
16
Ilya Yanok06bb9202012-11-06 13:48:21 +000017#include <linux/io.h>
Ilya Yanok06bb9202012-11-06 13:48:21 +000018
Ilya Yanok06bb9202012-11-06 13:48:21 +000019/* NOTE: these offsets are all in bytes */
20
21static inline u16 musb_readw(const void __iomem *addr, unsigned offset)
22 { return __raw_readw(addr + offset); }
23
24static inline u32 musb_readl(const void __iomem *addr, unsigned offset)
25 { return __raw_readl(addr + offset); }
26
Ilya Yanok06bb9202012-11-06 13:48:21 +000027static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data)
28 { __raw_writew(data, addr + offset); }
29
30static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data)
31 { __raw_writel(data, addr + offset); }
32
Ilya Yanok06bb9202012-11-06 13:48:21 +000033#if defined(CONFIG_USB_MUSB_TUSB6010) || defined (CONFIG_USB_MUSB_TUSB6010_MODULE)
34
35/*
36 * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
37 */
38static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
39{
40 u16 tmp;
41 u8 val;
42
43 tmp = __raw_readw(addr + (offset & ~1));
44 if (offset & 1)
45 val = (tmp >> 8);
46 else
47 val = tmp & 0xff;
48
49 return val;
50}
51
52static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
53{
54 u16 tmp;
55
56 tmp = __raw_readw(addr + (offset & ~1));
57 if (offset & 1)
58 tmp = (data << 8) | (tmp & 0xff);
59 else
60 tmp = (tmp & 0xff00) | data;
61
62 __raw_writew(tmp, addr + (offset & ~1));
63}
64
65#else
66
67static inline u8 musb_readb(const void __iomem *addr, unsigned offset)
68 { return __raw_readb(addr + offset); }
69
70static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data)
71 { __raw_writeb(data, addr + offset); }
72
73#endif /* CONFIG_USB_MUSB_TUSB6010 */
74
Ilya Yanok06bb9202012-11-06 13:48:21 +000075#endif