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
6 This adds optional handling of the peripheral clock PCLK.
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>
12 --- a/drivers/usb/fotg210/fotg210-udc.c
13 +++ b/drivers/usb/fotg210/fotg210-udc.c
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>
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]);
27 + if (!IS_ERR(fotg210->pclk))
28 + clk_disable_unprepare(fotg210->pclk);
33 @@ -1180,17 +1185,34 @@ int fotg210_udc_probe(struct platform_de
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);
42 + dev_err(dev, "failed to enable PCLK\n");
45 + } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
47 + * Percolate deferrals, for anything else,
48 + * just live without the clocking.
50 + ret = -EPROBE_DEFER;
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)
60 dev_info(dev, "no PHY found\n");
63 ret = usb_phy_init(fotg210->phy);
67 dev_info(dev, "found and initialized PHY\n");
70 @@ -1292,6 +1314,10 @@ err_map:
72 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
73 kfree(fotg210->ep[i]);
75 + if (!IS_ERR(fotg210->pclk))
76 + clk_disable_unprepare(fotg210->pclk);
81 --- a/drivers/usb/fotg210/fotg210-udc.h
82 +++ b/drivers/usb/fotg210/fotg210-udc.h
83 @@ -231,6 +231,7 @@ struct fotg210_ep {
85 spinlock_t lock; /* protect the struct */
89 unsigned long irq_trigger;