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
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
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.
13 If the device is flagged as "wakeup-source" using the standard
14 DT bindings, we also enable this in the global controller for
17 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
19 drivers/usb/host/Kconfig | 1 +
20 drivers/usb/host/fotg210-hcd.c | 76 ++++++++++++++++++++++++++++++++++
21 2 files changed, 77 insertions(+)
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
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
40 #include <linux/platform_device.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>
48 #include <asm/byteorder.h>
50 @@ -5554,6 +5558,72 @@ static void fotg210_init(struct fotg210_hcd *fotg210)
51 iowrite32(value, &fotg210->regs->otgcsr);
55 + * Gemini-specific initialization function, only executed on the
56 + * Gemini SoC using the global misc control register.
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)
66 +static int fotg210_gemini_init(struct device *dev, struct usb_hcd *hcd)
68 + struct device_node *np = dev->of_node;
75 + map = syscon_regmap_lookup_by_phandle(np, "syscon");
77 + dev_err(dev, "no syscon\n");
78 + return PTR_ERR(map);
80 + mini_b = of_property_read_bool(np, "cortina,gemini-mini-b");
81 + wakeup = of_property_read_bool(np, "wakeup-source");
84 + * Figure out if this is USB0 or USB1 by simply checking the
85 + * physical base address.
88 + if (hcd->rsrc_start == 0x69000000) {
89 + val = GEMINI_MISC_USB1_VBUS_ON;
91 + val |= GEMINI_MISC_USB1_MINI_B;
93 + mask |= GEMINI_MISC_USB1_MINI_B;
95 + val |= GEMINI_MISC_USB1_WAKEUP;
97 + mask |= GEMINI_MISC_USB1_WAKEUP;
99 + val = GEMINI_MISC_USB0_VBUS_ON;
101 + val |= GEMINI_MISC_USB0_MINI_B;
103 + mask |= GEMINI_MISC_USB0_MINI_B;
105 + val |= GEMINI_MISC_USB0_WAKEUP;
107 + mask |= GEMINI_MISC_USB0_WAKEUP;
110 + ret = regmap_update_bits(map, GEMINI_GLOBAL_MISC_CTRL, mask, val);
112 + dev_err(dev, "failed to initialize Gemini PHY\n");
116 + dev_info(dev, "initialized Gemini PHY\n");
121 * fotg210_hcd_probe - initialize faraday FOTG210 HCDs
123 @@ -5631,6 +5701,12 @@ static int fotg210_hcd_probe(struct platform_device *pdev)
125 fotg210_init(fotg210);
127 + if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
128 + retval = fotg210_gemini_init(dev, hcd);
130 + goto failed_dis_clk;
133 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
135 dev_err(dev, "failed to add hcd with err %d\n", retval);