octeon: disable edgerouter image
[openwrt/openwrt.git] / target / linux / gemini / patches-4.19 / 0013-usb-host-fotg2-add-silicon-clock-handling.patch
1 From e76906e8e9dfaeeb22a37706aca493b86e4367bd Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Fri, 21 Apr 2017 20:46:12 +0200
4 Subject: [PATCH 13/18] usb: host: fotg2: add silicon clock handling
5
6 When used in a system with software-controlled silicon clocks,
7 the FOTG210 needs to grab, prepare and enable the clock.
8
9 This is needed on for example the Cortina Gemini, where the
10 platform will by default gate off the clock unless the
11 peripheral (in this case the USB driver) grabs and enables
12 the clock.
13
14 If there is no clock available on the platform, we live
15 without it. Make sure to percolate probe deferrals.
16
17 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
18 ---
19 ChangeLog v1->v2:
20 - Handle probe deferrals on the clock controller, no matter
21 how unlikely they are.
22 - Send the patch to get Gemini USB rolling and try to get some
23 stuff upstream, this patch should be fine on its own.
24 ---
25 drivers/usb/host/fotg210-hcd.c | 33 +++++++++++++++++++++++++++++----
26 drivers/usb/host/fotg210.h | 3 +++
27 2 files changed, 32 insertions(+), 4 deletions(-)
28
29 --- a/drivers/usb/host/fotg210-hcd.c
30 +++ b/drivers/usb/host/fotg210-hcd.c
31 @@ -31,6 +31,7 @@
32 #include <linux/uaccess.h>
33 #include <linux/platform_device.h>
34 #include <linux/io.h>
35 +#include <linux/clk.h>
36
37 #include <asm/byteorder.h>
38 #include <asm/irq.h>
39 @@ -5600,7 +5601,7 @@ static int fotg210_hcd_probe(struct plat
40 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
41 if (IS_ERR(hcd->regs)) {
42 retval = PTR_ERR(hcd->regs);
43 - goto failed;
44 + goto failed_put_hcd;
45 }
46
47 hcd->rsrc_start = res->start;
48 @@ -5610,22 +5611,42 @@ static int fotg210_hcd_probe(struct plat
49
50 fotg210->caps = hcd->regs;
51
52 + /* It's OK not to supply this clock */
53 + fotg210->pclk = clk_get(dev, "PCLK");
54 + if (!IS_ERR(fotg210->pclk)) {
55 + retval = clk_prepare_enable(fotg210->pclk);
56 + if (retval) {
57 + dev_err(dev, "failed to enable PCLK\n");
58 + goto failed_put_hcd;
59 + }
60 + } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
61 + /*
62 + * Percolate deferrals, for anything else,
63 + * just live without the clocking.
64 + */
65 + retval = PTR_ERR(fotg210->pclk);
66 + goto failed_dis_clk;
67 + }
68 +
69 retval = fotg210_setup(hcd);
70 if (retval)
71 - goto failed;
72 + goto failed_dis_clk;
73
74 fotg210_init(fotg210);
75
76 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
77 if (retval) {
78 dev_err(dev, "failed to add hcd with err %d\n", retval);
79 - goto failed;
80 + goto failed_dis_clk;
81 }
82 device_wakeup_enable(hcd->self.controller);
83
84 return retval;
85
86 -failed:
87 +failed_dis_clk:
88 + if (!IS_ERR(fotg210->pclk))
89 + clk_disable_unprepare(fotg210->pclk);
90 +failed_put_hcd:
91 usb_put_hcd(hcd);
92 fail_create_hcd:
93 dev_err(dev, "init %s fail, %d\n", dev_name(dev), retval);
94 @@ -5641,6 +5662,10 @@ static int fotg210_hcd_remove(struct pla
95 {
96 struct device *dev = &pdev->dev;
97 struct usb_hcd *hcd = dev_get_drvdata(dev);
98 + struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
99 +
100 + if (!IS_ERR(fotg210->pclk))
101 + clk_disable_unprepare(fotg210->pclk);
102
103 if (!hcd)
104 return 0;
105 --- a/drivers/usb/host/fotg210.h
106 +++ b/drivers/usb/host/fotg210.h
107 @@ -182,6 +182,9 @@ struct fotg210_hcd { /* one per contro
108 # define COUNT(x)
109 #endif
110
111 + /* silicon clock */
112 + struct clk *pclk;
113 +
114 /* debug files */
115 struct dentry *debug_dir;
116 };