1 From fb8e1e8dbc47e7aff7624b47adaa0a84d2983802 Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Wed, 18 Jan 2023 08:09:18 +0100
4 Subject: [PATCH 18/29] usb: fotg210: Move clock handling to core
6 Grab the optional silicon block clock, prepare and enable it in
7 the core before proceeding to prepare the host or peripheral
8 driver. This saves duplicate code and also uses the simple
9 devm_clk_get_optional_enabled() to do everything we really
12 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
13 Link: https://lore.kernel.org/r/20230103-gemini-fotg210-usb-v2-4-100388af9810@linaro.org
14 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 --- a/drivers/usb/fotg210/fotg210-core.c
17 +++ b/drivers/usb/fotg210/fotg210-core.c
21 #include <linux/bitops.h>
22 +#include <linux/clk.h>
23 #include <linux/device.h>
24 #include <linux/mfd/syscon.h>
25 #include <linux/module.h>
26 @@ -109,6 +110,10 @@ static int fotg210_probe(struct platform
30 + fotg->pclk = devm_clk_get_optional_enabled(dev, "PCLK");
31 + if (IS_ERR(fotg->pclk))
32 + return PTR_ERR(fotg->pclk);
34 mode = usb_get_dr_mode(dev);
36 if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
37 --- a/drivers/usb/fotg210/fotg210-hcd.c
38 +++ b/drivers/usb/fotg210/fotg210-hcd.c
40 #include <linux/platform_device.h>
42 #include <linux/iopoll.h>
43 -#include <linux/clk.h>
45 #include <asm/byteorder.h>
47 @@ -5594,44 +5593,22 @@ int fotg210_hcd_probe(struct platform_de
49 fotg210->caps = hcd->regs;
51 - /* It's OK not to supply this clock */
52 - fotg210->pclk = clk_get(dev, "PCLK");
53 - if (!IS_ERR(fotg210->pclk)) {
54 - retval = clk_prepare_enable(fotg210->pclk);
56 - dev_err(dev, "failed to enable PCLK\n");
57 - goto failed_put_hcd;
59 - } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
61 - * Percolate deferrals, for anything else,
62 - * just live without the clocking.
64 - retval = PTR_ERR(fotg210->pclk);
65 - goto failed_dis_clk;
68 retval = fotg210_setup(hcd);
70 - goto failed_dis_clk;
71 + goto failed_put_hcd;
73 fotg210_init(fotg210);
75 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
77 dev_err(dev, "failed to add hcd with err %d\n", retval);
78 - goto failed_dis_clk;
79 + goto failed_put_hcd;
81 device_wakeup_enable(hcd->self.controller);
82 platform_set_drvdata(pdev, hcd);
87 - if (!IS_ERR(fotg210->pclk)) {
88 - clk_disable_unprepare(fotg210->pclk);
89 - clk_put(fotg210->pclk);
94 @@ -5647,12 +5624,6 @@ fail_create_hcd:
95 int fotg210_hcd_remove(struct platform_device *pdev)
97 struct usb_hcd *hcd = platform_get_drvdata(pdev);
98 - struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
100 - if (!IS_ERR(fotg210->pclk)) {
101 - clk_disable_unprepare(fotg210->pclk);
102 - clk_put(fotg210->pclk);
107 --- a/drivers/usb/fotg210/fotg210-udc.c
108 +++ b/drivers/usb/fotg210/fotg210-udc.c
110 #include <linux/platform_device.h>
111 #include <linux/usb/ch9.h>
112 #include <linux/usb/gadget.h>
113 -#include <linux/clk.h>
114 #include <linux/usb/otg.h>
115 #include <linux/usb/phy.h>
117 @@ -1147,9 +1146,6 @@ int fotg210_udc_remove(struct platform_d
118 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
119 kfree(fotg210->ep[i]);
121 - if (!IS_ERR(fotg210->pclk))
122 - clk_disable_unprepare(fotg210->pclk);
127 @@ -1177,34 +1173,17 @@ int fotg210_udc_probe(struct platform_de
129 fotg210->fotg = fotg;
131 - /* It's OK not to supply this clock */
132 - fotg210->pclk = devm_clk_get(dev, "PCLK");
133 - if (!IS_ERR(fotg210->pclk)) {
134 - ret = clk_prepare_enable(fotg210->pclk);
136 - dev_err(dev, "failed to enable PCLK\n");
139 - } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
141 - * Percolate deferrals, for anything else,
142 - * just live without the clocking.
144 - ret = -EPROBE_DEFER;
148 fotg210->phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
149 if (IS_ERR(fotg210->phy)) {
150 ret = PTR_ERR(fotg210->phy);
151 if (ret == -EPROBE_DEFER)
154 dev_info(dev, "no PHY found\n");
157 ret = usb_phy_init(fotg210->phy);
161 dev_info(dev, "found and initialized PHY\n");
164 @@ -1303,11 +1282,8 @@ err_map:
166 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
167 kfree(fotg210->ep[i]);
169 - if (!IS_ERR(fotg210->pclk))
170 - clk_disable_unprepare(fotg210->pclk);
177 --- a/drivers/usb/fotg210/fotg210-udc.h
178 +++ b/drivers/usb/fotg210/fotg210-udc.h
179 @@ -231,7 +231,6 @@ struct fotg210_ep {
181 spinlock_t lock; /* protect the struct */
185 unsigned long irq_trigger;
187 --- a/drivers/usb/fotg210/fotg210.h
188 +++ b/drivers/usb/fotg210/fotg210.h
189 @@ -12,6 +12,7 @@ struct fotg210 {
191 struct resource *res;
195 enum gemini_port port;