55d44b0e1011e7092c5b2c7fd6580bec115b486f
[openwrt/openwrt.git] / target / linux / gemini / patches-4.19 / 0016-usb-host-fotg2-add-Gemini-specific-handling.patch
1 From b331ae758123ba20ba41199e007ac33fc0f242e3 Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Fri, 21 Apr 2017 22:19:00 +0200
4 Subject: [PATCH 16/18] usb: host: fotg2: add Gemini-specific handling
5
6 The Cortina Systems Gemini has bolted on a PHY inside the
7 silicon that can be handled by six bits in a MISC register in
8 the system controller.
9
10 If we are running on Gemini, look up a syscon regmap through
11 a phandle and enable VBUS and optionally the Mini-B connector.
12
13 If the device is flagged as "wakeup-source" using the standard
14 DT bindings, we also enable this in the global controller for
15 respective port.
16
17 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
18 ---
19 drivers/usb/host/Kconfig | 1 +
20 drivers/usb/host/fotg210-hcd.c | 76 ++++++++++++++++++++++++++++++++++
21 2 files changed, 77 insertions(+)
22
23 diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
24 index 1a4ea98cac2a..308d514c9a2a 100644
25 --- a/drivers/usb/host/Kconfig
26 +++ b/drivers/usb/host/Kconfig
27 @@ -372,6 +372,7 @@ config USB_ISP1362_HCD
28 config USB_FOTG210_HCD
29 tristate "FOTG210 HCD support"
30 depends on USB && HAS_DMA && HAS_IOMEM
31 + select MFD_SYSCON
32 ---help---
33 Faraday FOTG210 is an OTG controller which can be configured as
34 an USB2.0 host. It is designed to meet USB2.0 EHCI specification
35 diff --git a/drivers/usb/host/fotg210-hcd.c b/drivers/usb/host/fotg210-hcd.c
36 index 6e4b40cd5916..5abb07f4136f 100644
37 --- a/drivers/usb/host/fotg210-hcd.c
38 +++ b/drivers/usb/host/fotg210-hcd.c
39 @@ -33,6 +33,10 @@
40 #include <linux/platform_device.h>
41 #include <linux/io.h>
42 #include <linux/clk.h>
43 +#include <linux/bitops.h>
44 +/* For Cortina Gemini */
45 +#include <linux/mfd/syscon.h>
46 +#include <linux/regmap.h>
47
48 #include <asm/byteorder.h>
49 #include <asm/irq.h>
50 @@ -5554,6 +5558,72 @@ static void fotg210_init(struct fotg210_hcd *fotg210)
51 iowrite32(value, &fotg210->regs->otgcsr);
52 }
53
54 +/*
55 + * Gemini-specific initialization function, only executed on the
56 + * Gemini SoC using the global misc control register.
57 + */
58 +#define GEMINI_GLOBAL_MISC_CTRL 0x30
59 +#define GEMINI_MISC_USB0_WAKEUP BIT(14)
60 +#define GEMINI_MISC_USB1_WAKEUP BIT(15)
61 +#define GEMINI_MISC_USB0_VBUS_ON BIT(22)
62 +#define GEMINI_MISC_USB1_VBUS_ON BIT(23)
63 +#define GEMINI_MISC_USB0_MINI_B BIT(29)
64 +#define GEMINI_MISC_USB1_MINI_B BIT(30)
65 +
66 +static int fotg210_gemini_init(struct device *dev, struct usb_hcd *hcd)
67 +{
68 + struct device_node *np = dev->of_node;
69 + struct regmap *map;
70 + bool mini_b;
71 + bool wakeup;
72 + u32 mask, val;
73 + int ret;
74 +
75 + map = syscon_regmap_lookup_by_phandle(np, "syscon");
76 + if (IS_ERR(map)) {
77 + dev_err(dev, "no syscon\n");
78 + return PTR_ERR(map);
79 + }
80 + mini_b = of_property_read_bool(np, "cortina,gemini-mini-b");
81 + wakeup = of_property_read_bool(np, "wakeup-source");
82 +
83 + /*
84 + * Figure out if this is USB0 or USB1 by simply checking the
85 + * physical base address.
86 + */
87 + mask = 0;
88 + if (hcd->rsrc_start == 0x69000000) {
89 + val = GEMINI_MISC_USB1_VBUS_ON;
90 + if (mini_b)
91 + val |= GEMINI_MISC_USB1_MINI_B;
92 + else
93 + mask |= GEMINI_MISC_USB1_MINI_B;
94 + if (wakeup)
95 + val |= GEMINI_MISC_USB1_WAKEUP;
96 + else
97 + mask |= GEMINI_MISC_USB1_WAKEUP;
98 + } else {
99 + val = GEMINI_MISC_USB0_VBUS_ON;
100 + if (mini_b)
101 + val |= GEMINI_MISC_USB0_MINI_B;
102 + else
103 + mask |= GEMINI_MISC_USB0_MINI_B;
104 + if (wakeup)
105 + val |= GEMINI_MISC_USB0_WAKEUP;
106 + else
107 + mask |= GEMINI_MISC_USB0_WAKEUP;
108 + }
109 +
110 + ret = regmap_update_bits(map, GEMINI_GLOBAL_MISC_CTRL, mask, val);
111 + if (ret) {
112 + dev_err(dev, "failed to initialize Gemini PHY\n");
113 + return ret;
114 + }
115 +
116 + dev_info(dev, "initialized Gemini PHY\n");
117 + return 0;
118 +}
119 +
120 /**
121 * fotg210_hcd_probe - initialize faraday FOTG210 HCDs
122 *
123 @@ -5631,6 +5701,12 @@ static int fotg210_hcd_probe(struct platform_device *pdev)
124
125 fotg210_init(fotg210);
126
127 + if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
128 + retval = fotg210_gemini_init(dev, hcd);
129 + if (retval)
130 + goto failed_dis_clk;
131 + }
132 +
133 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
134 if (retval) {
135 dev_err(dev, "failed to add hcd with err %d\n", retval);
136 --
137 2.19.2
138