mediatek: Add support for Xiaomi Redmi Router AX6S
[openwrt/staging/chunkeey.git] / target / linux / bcm4908 / patches-5.4 / 084-v5.6-0011-phy-usb-bdc-Fix-occasional-failure-with-BDC-on-7211.patch
1 From bed63b636fedf47dbab899a5193ec5ec4539f6fc Mon Sep 17 00:00:00 2001
2 From: Al Cooper <alcooperx@gmail.com>
3 Date: Fri, 3 Jan 2020 13:18:09 -0500
4 Subject: [PATCH] phy: usb: bdc: Fix occasional failure with BDC on 7211
5
6 The BDC "Read Transaction Size" needs to be changed from 1024
7 bytes to 256 bytes to prevent occasional transaction failures.
8
9 Signed-off-by: Al Cooper <alcooperx@gmail.com>
10 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
11 Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
12 ---
13 .../phy/broadcom/phy-brcm-usb-init-synopsys.c | 18 +++++++++++++++
14 drivers/phy/broadcom/phy-brcm-usb-init.h | 1 +
15 drivers/phy/broadcom/phy-brcm-usb.c | 23 +++++++++++++++----
16 3 files changed, 38 insertions(+), 4 deletions(-)
17
18 --- a/drivers/phy/broadcom/phy-brcm-usb-init-synopsys.c
19 +++ b/drivers/phy/broadcom/phy-brcm-usb-init-synopsys.c
20 @@ -70,6 +70,11 @@
21 #define USB_GMDIOCSR 0
22 #define USB_GMDIOGEN 4
23
24 +/* Register definitions for the BDC EC block in 7211b0 */
25 +#define BDC_EC_AXIRDA 0x0c
26 +#define BDC_EC_AXIRDA_RTS_MASK 0xf0000000
27 +#define BDC_EC_AXIRDA_RTS_SHIFT 28
28 +
29
30 static void usb_mdio_write_7211b0(struct brcm_usb_init_params *params,
31 uint8_t addr, uint16_t data)
32 @@ -198,6 +203,7 @@ static void usb_init_common_7211b0(struc
33 {
34 void __iomem *ctrl = params->regs[BRCM_REGS_CTRL];
35 void __iomem *usb_phy = params->regs[BRCM_REGS_USB_PHY];
36 + void __iomem *bdc_ec = params->regs[BRCM_REGS_BDC_EC];
37 int timeout_ms = PHY_LOCK_TIMEOUT_MS;
38 u32 reg;
39
40 @@ -231,6 +237,18 @@ static void usb_init_common_7211b0(struc
41 usb_init_common(params);
42
43 /*
44 + * The BDC controller will get occasional failures with
45 + * the default "Read Transaction Size" of 6 (1024 bytes).
46 + * Set it to 4 (256 bytes).
47 + */
48 + if ((params->mode != USB_CTLR_MODE_HOST) && bdc_ec) {
49 + reg = brcm_usb_readl(bdc_ec + BDC_EC_AXIRDA);
50 + reg &= ~BDC_EC_AXIRDA_RTS_MASK;
51 + reg |= (0x4 << BDC_EC_AXIRDA_RTS_SHIFT);
52 + brcm_usb_writel(reg, bdc_ec + BDC_EC_AXIRDA);
53 + }
54 +
55 + /*
56 * Disable FSM, otherwise the PHY will auto suspend when no
57 * device is connected and will be reset on resume.
58 */
59 --- a/drivers/phy/broadcom/phy-brcm-usb-init.h
60 +++ b/drivers/phy/broadcom/phy-brcm-usb-init.h
61 @@ -19,6 +19,7 @@ enum brcmusb_reg_sel {
62 BRCM_REGS_XHCI_GBL,
63 BRCM_REGS_USB_PHY,
64 BRCM_REGS_USB_MDIO,
65 + BRCM_REGS_BDC_EC,
66 BRCM_REGS_MAX
67 };
68
69 --- a/drivers/phy/broadcom/phy-brcm-usb.c
70 +++ b/drivers/phy/broadcom/phy-brcm-usb.c
71 @@ -36,6 +36,7 @@ struct value_to_name_map {
72 struct match_chip_info {
73 void *init_func;
74 u8 required_regs[BRCM_REGS_MAX + 1];
75 + u8 optional_reg;
76 };
77
78 static struct value_to_name_map brcm_dr_mode_to_name[] = {
79 @@ -71,7 +72,7 @@ struct brcm_usb_phy_data {
80 };
81
82 static s8 *node_reg_names[BRCM_REGS_MAX] = {
83 - "crtl", "xhci_ec", "xhci_gbl", "usb_phy", "usb_mdio"
84 + "crtl", "xhci_ec", "xhci_gbl", "usb_phy", "usb_mdio", "bdc_ec"
85 };
86
87 static irqreturn_t brcm_usb_phy_wake_isr(int irq, void *dev_id)
88 @@ -271,6 +272,7 @@ static struct match_chip_info chip_info_
89 BRCM_REGS_USB_MDIO,
90 -1,
91 },
92 + .optional_reg = BRCM_REGS_BDC_EC,
93 };
94
95 static struct match_chip_info chip_info_7445 = {
96 @@ -300,7 +302,8 @@ static const struct of_device_id brcm_us
97
98 static int brcm_usb_get_regs(struct platform_device *pdev,
99 enum brcmusb_reg_sel regs,
100 - struct brcm_usb_init_params *ini)
101 + struct brcm_usb_init_params *ini,
102 + bool optional)
103 {
104 struct resource *res;
105
106 @@ -317,7 +320,13 @@ static int brcm_usb_get_regs(struct plat
107 return 0;
108 }
109 if (res == NULL) {
110 - dev_err(&pdev->dev, "can't get %s base address\n",
111 + if (optional) {
112 + dev_dbg(&pdev->dev,
113 + "Optional reg %s not found\n",
114 + node_reg_names[regs]);
115 + return 0;
116 + }
117 + dev_err(&pdev->dev, "can't get %s base addr\n",
118 node_reg_names[regs]);
119 return 1;
120 }
121 @@ -460,7 +469,13 @@ static int brcm_usb_phy_probe(struct pla
122 break;
123
124 err = brcm_usb_get_regs(pdev, info->required_regs[x],
125 - &priv->ini);
126 + &priv->ini, false);
127 + if (err)
128 + return -EINVAL;
129 + }
130 + if (info->optional_reg) {
131 + err = brcm_usb_get_regs(pdev, info->optional_reg,
132 + &priv->ini, true);
133 if (err)
134 return -EINVAL;
135 }