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