xref: /linux/drivers/usb/dwc3/io.h (revision ca220141fa8ebae09765a242076b2b77338106b0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * io.h - DesignWare USB3 DRD IO Header
4  *
5  * Copyright (C) 2010-2011 Texas Instruments Incorporated - https://www.ti.com
6  *
7  * Authors: Felipe Balbi <balbi@ti.com>,
8  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
9  */
10 
11 #ifndef __DRIVERS_USB_DWC3_IO_H
12 #define __DRIVERS_USB_DWC3_IO_H
13 
14 #include <linux/io.h>
15 #include "trace.h"
16 #include "debug.h"
17 #include "core.h"
18 
19 static inline u32 dwc3_readl(struct dwc3 *dwc, u32 offset)
20 {
21 	u32 value;
22 	void __iomem *base = dwc->regs;
23 
24 	/*
25 	 * We requested the mem region starting from the Globals address
26 	 * space, see dwc3_probe in core.c.
27 	 * However, the offsets are given starting from xHCI address space.
28 	 */
29 	value = readl(base + offset - DWC3_GLOBALS_REGS_START);
30 
31 	/*
32 	 * When tracing we want to make it easy to find the correct address on
33 	 * documentation, so we revert it back to the proper addresses, the
34 	 * same way they are described on SNPS documentation
35 	 */
36 	trace_dwc3_readl(dwc, base - DWC3_GLOBALS_REGS_START, offset, value);
37 
38 	return value;
39 }
40 
41 static inline void dwc3_writel(struct dwc3 *dwc, u32 offset, u32 value)
42 {
43 	void __iomem *base = dwc->regs;
44 
45 	/*
46 	 * We requested the mem region starting from the Globals address
47 	 * space, see dwc3_probe in core.c.
48 	 * However, the offsets are given starting from xHCI address space.
49 	 */
50 	writel(value, base + offset - DWC3_GLOBALS_REGS_START);
51 
52 	/*
53 	 * When tracing we want to make it easy to find the correct address on
54 	 * documentation, so we revert it back to the proper addresses, the
55 	 * same way they are described on SNPS documentation
56 	 */
57 	trace_dwc3_writel(dwc, base - DWC3_GLOBALS_REGS_START, offset, value);
58 }
59 
60 #endif /* __DRIVERS_USB_DWC3_IO_H */
61