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#include <linux/io.h> 18 19/* 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 27 28static inline void musb_writew(void __iomem *addr, unsigned offset, u16 data) 29 { __raw_writew(data, addr + offset); } 30 31static inline void musb_writel(void __iomem *addr, unsigned offset, u32 data) 32 { __raw_writel(data, addr + offset); } 33 34 35#if defined(CONFIG_USB_MUSB_TUSB6010) || defined (CONFIG_USB_MUSB_TUSB6010_MODULE) 36 37/* 38 * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum. 39 */ 40static inline u8 musb_readb(const void __iomem *addr, unsigned offset) 41{ 42 u16 tmp; 43 u8 val; 44 45 tmp = __raw_readw(addr + (offset & ~1)); 46 if (offset & 1) 47 val = (tmp >> 8); 48 else 49 val = tmp & 0xff; 50 51 return val; 52} 53 54static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data) 55{ 56 u16 tmp; 57 58 tmp = __raw_readw(addr + (offset & ~1)); 59 if (offset & 1) 60 tmp = (data << 8) | (tmp & 0xff); 61 else 62 tmp = (tmp & 0xff00) | data; 63 64 __raw_writew(tmp, addr + (offset & ~1)); 65} 66 67#else 68 69static inline u8 musb_readb(const void __iomem *addr, unsigned offset) 70 { return __raw_readb(addr + offset); } 71 72static inline void musb_writeb(void __iomem *addr, unsigned offset, u8 data) 73 { __raw_writeb(data, addr + offset); } 74 75#endif /* CONFIG_USB_MUSB_TUSB6010 */ 76 77#endif 78