8da3de3b47674a856964c5b9c872aa28920edb7f
[openwrt/openwrt.git] / target / linux / gemini / patches-6.1 / 0010-fotg210-udc-Handle-PCLK.patch
1 From 772ea3ec2b9363b45ef9a4768ea205f758c3debc Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Mon, 14 Nov 2022 12:52:00 +0100
4 Subject: [PATCH 10/29] fotg210-udc: Handle PCLK
5
6 This adds optional handling of the peripheral clock PCLK.
7
8 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
9 Link: https://lore.kernel.org/r/20221114115201.302887-3-linus.walleij@linaro.org
10 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
11 ---
12 --- a/drivers/usb/fotg210/fotg210-udc.c
13 +++ b/drivers/usb/fotg210/fotg210-udc.c
14 @@ -15,6 +15,7 @@
15 #include <linux/platform_device.h>
16 #include <linux/usb/ch9.h>
17 #include <linux/usb/gadget.h>
18 +#include <linux/clk.h>
19 #include <linux/usb/otg.h>
20 #include <linux/usb/phy.h>
21
22 @@ -1145,6 +1146,10 @@ int fotg210_udc_remove(struct platform_d
23 fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req);
24 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
25 kfree(fotg210->ep[i]);
26 +
27 + if (!IS_ERR(fotg210->pclk))
28 + clk_disable_unprepare(fotg210->pclk);
29 +
30 kfree(fotg210);
31
32 return 0;
33 @@ -1180,17 +1185,34 @@ int fotg210_udc_probe(struct platform_de
34
35 fotg210->dev = dev;
36
37 + /* It's OK not to supply this clock */
38 + fotg210->pclk = devm_clk_get(dev, "PCLK");
39 + if (!IS_ERR(fotg210->pclk)) {
40 + ret = clk_prepare_enable(fotg210->pclk);
41 + if (ret) {
42 + dev_err(dev, "failed to enable PCLK\n");
43 + return ret;
44 + }
45 + } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
46 + /*
47 + * Percolate deferrals, for anything else,
48 + * just live without the clocking.
49 + */
50 + ret = -EPROBE_DEFER;
51 + goto err;
52 + }
53 +
54 fotg210->phy = devm_usb_get_phy_by_phandle(dev->parent, "usb-phy", 0);
55 if (IS_ERR(fotg210->phy)) {
56 ret = PTR_ERR(fotg210->phy);
57 if (ret == -EPROBE_DEFER)
58 - goto err;
59 + goto err_pclk;
60 dev_info(dev, "no PHY found\n");
61 fotg210->phy = NULL;
62 } else {
63 ret = usb_phy_init(fotg210->phy);
64 if (ret)
65 - goto err;
66 + goto err_pclk;
67 dev_info(dev, "found and initialized PHY\n");
68 }
69
70 @@ -1292,6 +1314,10 @@ err_map:
71 err_alloc:
72 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
73 kfree(fotg210->ep[i]);
74 +err_pclk:
75 + if (!IS_ERR(fotg210->pclk))
76 + clk_disable_unprepare(fotg210->pclk);
77 +
78 kfree(fotg210);
79
80 err:
81 --- a/drivers/usb/fotg210/fotg210-udc.h
82 +++ b/drivers/usb/fotg210/fotg210-udc.h
83 @@ -231,6 +231,7 @@ struct fotg210_ep {
84 struct fotg210_udc {
85 spinlock_t lock; /* protect the struct */
86 void __iomem *reg;
87 + struct clk *pclk;
88
89 unsigned long irq_trigger;
90