gemini: Add kernel v6.1 patches
[openwrt/staging/stintel.git] / target / linux / gemini / patches-6.1 / 0023-fotg210-udc-Improve-device-initialization.patch
1 From 367747c7813cecf19b46ef7134691f903ab76dc9 Mon Sep 17 00:00:00 2001
2 From: Fabian Vogt <fabian@ritter-vogt.de>
3 Date: Mon, 23 Jan 2023 08:35:08 +0100
4 Subject: [PATCH 23/29] fotg210-udc: Improve device initialization
5
6 Reset the device explicitly to get into a known state and also set the chip
7 enable bit. Additionally, mask interrupts which aren't handled.
8
9 Signed-off-by: Fabian Vogt <fabian@ritter-vogt.de>
10 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
11 Link: https://lore.kernel.org/r/20230123073508.2350402-4-linus.walleij@linaro.org
12 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
13 ---
14 --- a/drivers/usb/fotg210/fotg210-udc.c
15 +++ b/drivers/usb/fotg210/fotg210-udc.c
16 @@ -7,6 +7,7 @@
17 * Author : Yuan-Hsin Chen <yhchen@faraday-tech.com>
18 */
19
20 +#include <linux/delay.h>
21 #include <linux/dma-mapping.h>
22 #include <linux/err.h>
23 #include <linux/interrupt.h>
24 @@ -1022,6 +1023,11 @@ static int fotg210_udc_start(struct usb_
25 dev_err(fotg210->dev, "can't bind to phy\n");
26 }
27
28 + /* chip enable */
29 + value = ioread32(fotg210->reg + FOTG210_DMCR);
30 + value |= DMCR_CHIP_EN;
31 + iowrite32(value, fotg210->reg + FOTG210_DMCR);
32 +
33 /* enable device global interrupt */
34 value = ioread32(fotg210->reg + FOTG210_DMCR);
35 value |= DMCR_GLINT_EN;
36 @@ -1038,6 +1044,15 @@ static void fotg210_init(struct fotg210_
37 iowrite32(GMIR_MHC_INT | GMIR_MOTG_INT | GMIR_INT_POLARITY,
38 fotg210->reg + FOTG210_GMIR);
39
40 + /* mask interrupts for groups other than 0-2 */
41 + iowrite32(~(DMIGR_MINT_G0 | DMIGR_MINT_G1 | DMIGR_MINT_G2),
42 + fotg210->reg + FOTG210_DMIGR);
43 +
44 + /* udc software reset */
45 + iowrite32(DMCR_SFRST, fotg210->reg + FOTG210_DMCR);
46 + /* Better wait a bit, but without a datasheet, no idea how long. */
47 + usleep_range(100, 200);
48 +
49 /* disable device global interrupt */
50 value = ioread32(fotg210->reg + FOTG210_DMCR);
51 value &= ~DMCR_GLINT_EN;
52 --- a/drivers/usb/fotg210/fotg210-udc.h
53 +++ b/drivers/usb/fotg210/fotg210-udc.h
54 @@ -58,6 +58,8 @@
55
56 /* Device Mask of Interrupt Group Register (0x130) */
57 #define FOTG210_DMIGR 0x130
58 +#define DMIGR_MINT_G2 (1 << 2)
59 +#define DMIGR_MINT_G1 (1 << 1)
60 #define DMIGR_MINT_G0 (1 << 0)
61
62 /* Device Mask of Interrupt Source Group 0(0x134) */