brcm47xx: add missing config symbol
[openwrt/openwrt.git] / target / linux / apm821xx / patches-4.4 / 030-usb-dwc2-endian-fix.patch
1 From: Arnd Bergmann <arnd@arndb.de>
2 Subject: [PATCH v4] usb: dwc2: fix regression on big-endian PowerPC/ARM systems
3 Date: Fri, 13 May 2016 15:52:27 +0200
4 Message-Id: <1463147559-544140-1-git-send-email-arnd@arndb.de>
5
6 A patch that went into Linux-4.4 to fix big-endian mode on a Lantiq
7 MIPS system unfortunately broke big-endian operation on PowerPC
8 APM82181 as reported by Christian Lamparter, and likely other
9 systems.
10
11 It actually introduced multiple issues:
12
13 - it broke big-endian ARM kernels: any machine that was working
14 correctly with a little-endian kernel is no longer using byteswaps
15 on big-endian kernels, which clearly breaks them.
16 - On PowerPC the same thing must be true: if it was working before,
17 using big-endian kernels is now broken. Unlike ARM, 32-bit PowerPC
18 usually uses big-endian kernels, so they are likely all broken.
19 - The barrier for dwc2_writel is on the wrong side of the __raw_writel(),
20 so the MMIO no longer synchronizes with DMA operations.
21 - On architectures that require specific CPU instructions for MMIO
22 access, using the __raw_ variant may turn this into a pointer
23 dereference that does not have the same effect as the readl/writel.
24
25 This patch is a simple revert for all architectures other than MIPS,
26 in the hope that we can more easily backport it to fix the regression
27 on PowerPC and ARM systems without breaking the Lantiq system again.
28
29 We should follow this up with a more elaborate change to add runtime
30 detection of endianness, to make sure it also works on all other
31 combinations of architectures and implementations of the usb-dwc2
32 device. That patch however will be fairly large and not appropriate
33 for backports to stable kernels.
34
35 Felipe suggested a different approach, using an endianness switching
36 register to always put the device into LE mode, but unfortunately
37 the dwc2 hardware does not provide a generic way to do that. Also,
38 I see no practical way of addressing the problem more generally by
39 patching architecture specific code on MIPS.
40
41 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
42 Fixes: 95c8bc360944 ("usb: dwc2: Use platform endianness when accessing registers")
43 ---
44 drivers/usb/dwc2/core.h | 27 +++++++++++++++++++++++++++
45 1 file changed, 27 insertions(+)
46
47 diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
48 index 3c58d633ce80..dec0b21fc626 100644
49 --- a/drivers/usb/dwc2/core.h
50 +++ b/drivers/usb/dwc2/core.h
51 @@ -64,6 +64,17 @@
52 DWC2_TRACE_SCHEDULER_VB(pr_fmt("%s: SCH: " fmt), \
53 dev_name(hsotg->dev), ##__VA_ARGS__)
54
55 +#ifdef CONFIG_MIPS
56 +/*
57 + * There are some MIPS machines that can run in either big-endian
58 + * or little-endian mode and that use the dwc2 register without
59 + * a byteswap in both ways.
60 + * Unlike other architectures, MIPS apparently does not require a
61 + * barrier before the __raw_writel() to synchronize with DMA but does
62 + * require the barrier after the __raw_writel() to serialize a set of
63 + * writes. This set of operations was added specifically for MIPS and
64 + * should only be used there.
65 + */
66 static inline u32 dwc2_readl(const void __iomem *addr)
67 {
68 u32 value = __raw_readl(addr);
69 @@ -90,6 +101,22 @@ static inline void dwc2_writel(u32 value, void __iomem *addr)
70 pr_info("INFO:: wrote %08x to %p\n", value, addr);
71 #endif
72 }
73 +#else
74 +/* Normal architectures just use readl/write */
75 +static inline u32 dwc2_readl(const void __iomem *addr)
76 +{
77 + return readl(addr);
78 +}
79 +
80 +static inline void dwc2_writel(u32 value, void __iomem *addr)
81 +{
82 + writel(value, addr);
83 +
84 +#ifdef DWC2_LOG_WRITES
85 + pr_info("info:: wrote %08x to %p\n", value, addr);
86 +#endif
87 +}
88 +#endif
89
90 /* Maximum number of Endpoints/HostChannels */
91 #define MAX_EPS_CHANNELS 16
92 --
93 2.7.0
94
95