xref: /openbmc/u-boot/drivers/usb/dwc3/io.h (revision b7bf4a95)
185d5e707SKishon Vijay Abraham I /**
285d5e707SKishon Vijay Abraham I  * io.h - DesignWare USB3 DRD IO Header
385d5e707SKishon Vijay Abraham I  *
430c31d58SKishon Vijay Abraham I  * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
585d5e707SKishon Vijay Abraham I  *
685d5e707SKishon Vijay Abraham I  * Authors: Felipe Balbi <balbi@ti.com>,
785d5e707SKishon Vijay Abraham I  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
885d5e707SKishon Vijay Abraham I  *
930c31d58SKishon Vijay Abraham I  * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/io.h) and ported
1030c31d58SKishon Vijay Abraham I  * to uboot.
1185d5e707SKishon Vijay Abraham I  *
1230c31d58SKishon Vijay Abraham I  * commit 2c4cbe6e5a : usb: dwc3: add tracepoints to aid debugging
1330c31d58SKishon Vijay Abraham I  *
1430c31d58SKishon Vijay Abraham I  * SPDX-License-Identifier:     GPL-2.0
1530c31d58SKishon Vijay Abraham I  *
1685d5e707SKishon Vijay Abraham I  */
1785d5e707SKishon Vijay Abraham I 
1885d5e707SKishon Vijay Abraham I #ifndef __DRIVERS_USB_DWC3_IO_H
1985d5e707SKishon Vijay Abraham I #define __DRIVERS_USB_DWC3_IO_H
2085d5e707SKishon Vijay Abraham I 
219848e574SKishon Vijay Abraham I #include <asm/io.h>
2285d5e707SKishon Vijay Abraham I 
23526a50f8SKishon Vijay Abraham I #define	CACHELINE_SIZE		CONFIG_SYS_CACHELINE_SIZE
2485d5e707SKishon Vijay Abraham I static inline u32 dwc3_readl(void __iomem *base, u32 offset)
2585d5e707SKishon Vijay Abraham I {
2601c94c4aSMichal Simek 	unsigned long offs = offset - DWC3_GLOBALS_REGS_START;
2785d5e707SKishon Vijay Abraham I 	u32 value;
2885d5e707SKishon Vijay Abraham I 
2985d5e707SKishon Vijay Abraham I 	/*
3085d5e707SKishon Vijay Abraham I 	 * We requested the mem region starting from the Globals address
3185d5e707SKishon Vijay Abraham I 	 * space, see dwc3_probe in core.c.
3285d5e707SKishon Vijay Abraham I 	 * However, the offsets are given starting from xHCI address space.
3385d5e707SKishon Vijay Abraham I 	 */
3485d5e707SKishon Vijay Abraham I 	value = readl(base + offs);
3585d5e707SKishon Vijay Abraham I 
3685d5e707SKishon Vijay Abraham I 	return value;
3785d5e707SKishon Vijay Abraham I }
3885d5e707SKishon Vijay Abraham I 
3985d5e707SKishon Vijay Abraham I static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value)
4085d5e707SKishon Vijay Abraham I {
4101c94c4aSMichal Simek 	unsigned long offs = offset - DWC3_GLOBALS_REGS_START;
4285d5e707SKishon Vijay Abraham I 
4385d5e707SKishon Vijay Abraham I 	/*
4485d5e707SKishon Vijay Abraham I 	 * We requested the mem region starting from the Globals address
4585d5e707SKishon Vijay Abraham I 	 * space, see dwc3_probe in core.c.
4685d5e707SKishon Vijay Abraham I 	 * However, the offsets are given starting from xHCI address space.
4785d5e707SKishon Vijay Abraham I 	 */
4885d5e707SKishon Vijay Abraham I 	writel(value, base + offs);
4985d5e707SKishon Vijay Abraham I }
5085d5e707SKishon Vijay Abraham I 
51*b7bf4a95SPhilipp Tomsich static inline void dwc3_flush_cache(uintptr_t addr, int length)
52526a50f8SKishon Vijay Abraham I {
53526a50f8SKishon Vijay Abraham I 	flush_dcache_range(addr, addr + ROUND(length, CACHELINE_SIZE));
54526a50f8SKishon Vijay Abraham I }
5585d5e707SKishon Vijay Abraham I #endif /* __DRIVERS_USB_DWC3_IO_H */
56