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
6 When used in a system with software-controlled silicon clocks,
7 the FOTG210 needs to grab, prepare and enable the clock.
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
14 If there is no clock available on the platform, we live
15 without it. Make sure to percolate probe deferrals.
17 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
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.
25 drivers/usb/host/fotg210-hcd.c | 33 +++++++++++++++++++++++++++++----
26 drivers/usb/host/fotg210.h | 3 +++
27 2 files changed, 32 insertions(+), 4 deletions(-)
29 --- a/drivers/usb/host/fotg210-hcd.c
30 +++ b/drivers/usb/host/fotg210-hcd.c
32 #include <linux/uaccess.h>
33 #include <linux/platform_device.h>
35 +#include <linux/clk.h>
37 #include <asm/byteorder.h>
39 @@ -5596,7 +5597,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);
44 + goto failed_put_hcd;
47 hcd->rsrc_start = res->start;
48 @@ -5606,22 +5607,42 @@ static int fotg210_hcd_probe(struct plat
50 fotg210->caps = hcd->regs;
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);
57 + dev_err(dev, "failed to enable PCLK\n");
58 + goto failed_put_hcd;
60 + } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
62 + * Percolate deferrals, for anything else,
63 + * just live without the clocking.
65 + retval = PTR_ERR(fotg210->pclk);
66 + goto failed_dis_clk;
69 retval = fotg210_setup(hcd);
72 + goto failed_dis_clk;
74 fotg210_init(fotg210);
76 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
78 dev_err(dev, "failed to add hcd with err %d\n", retval);
80 + goto failed_dis_clk;
82 device_wakeup_enable(hcd->self.controller);
88 + if (!IS_ERR(fotg210->pclk))
89 + clk_disable_unprepare(fotg210->pclk);
93 dev_err(dev, "init %s fail, %d\n", dev_name(dev), retval);
94 @@ -5637,6 +5658,10 @@ static int fotg210_hcd_remove(struct pla
96 struct device *dev = &pdev->dev;
97 struct usb_hcd *hcd = dev_get_drvdata(dev);
98 + struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
100 + if (!IS_ERR(fotg210->pclk))
101 + clk_disable_unprepare(fotg210->pclk);
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
111 + /* silicon clock */
115 struct dentry *debug_dir;