Skip to content

Commit 300034f

Browse files
geertugregkh
authored andcommitted
usb: phy: generic: Convert to devm_clk_get_optional()
The generic USB PHY driver uses the existence of the "clocks" property to see if a clock is optional or not. Use devm_clk_get_optional() instead, which exists for this purpose. As usb_phy_generic.clk is now either a valid clock pointer or NULL, and all clock operations handle NULL pointers gracefully, several IS_ERR() checks can be removed, simplifying the code. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> ... Link: https://patch.msgid.link/5cc21d821edf5d40f56a74cd251bb1b982876b72.1769004444.git.geert+renesas@glider.be Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 62b718d commit 300034f

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

drivers/usb/phy/phy-generic.c

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,13 @@ static int nop_set_suspend(struct usb_phy *x, int suspend)
4949
int ret = 0;
5050

5151
if (suspend) {
52-
if (!IS_ERR(nop->clk))
53-
clk_disable_unprepare(nop->clk);
52+
clk_disable_unprepare(nop->clk);
5453
if (!IS_ERR(nop->vcc) && !device_may_wakeup(x->dev))
5554
ret = regulator_disable(nop->vcc);
5655
} else {
5756
if (!IS_ERR(nop->vcc) && !device_may_wakeup(x->dev))
5857
ret = regulator_enable(nop->vcc);
59-
if (!IS_ERR(nop->clk))
60-
clk_prepare_enable(nop->clk);
58+
clk_prepare_enable(nop->clk);
6159
}
6260

6361
return ret;
@@ -137,11 +135,9 @@ int usb_gen_phy_init(struct usb_phy *phy)
137135
dev_err(phy->dev, "Failed to enable power\n");
138136
}
139137

140-
if (!IS_ERR(nop->clk)) {
141-
ret = clk_prepare_enable(nop->clk);
142-
if (ret)
143-
return ret;
144-
}
138+
ret = clk_prepare_enable(nop->clk);
139+
if (ret)
140+
return ret;
145141

146142
nop_reset(nop);
147143

@@ -155,8 +151,7 @@ void usb_gen_phy_shutdown(struct usb_phy *phy)
155151

156152
gpiod_set_value_cansleep(nop->gpiod_reset, 1);
157153

158-
if (!IS_ERR(nop->clk))
159-
clk_disable_unprepare(nop->clk);
154+
clk_disable_unprepare(nop->clk);
160155

161156
if (!IS_ERR(nop->vcc)) {
162157
if (regulator_disable(nop->vcc))
@@ -202,17 +197,13 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop)
202197
{
203198
enum usb_phy_type type = USB_PHY_TYPE_USB2;
204199
int err = 0;
205-
206200
u32 clk_rate = 0;
207-
bool needs_clk = false;
208201

209202
if (dev->of_node) {
210203
struct device_node *node = dev->of_node;
211204

212205
if (of_property_read_u32(node, "clock-frequency", &clk_rate))
213206
clk_rate = 0;
214-
215-
needs_clk = of_property_present(node, "clocks");
216207
}
217208
nop->gpiod_reset = devm_gpiod_get_optional(dev, "reset",
218209
GPIOD_ASIS);
@@ -235,15 +226,14 @@ int usb_phy_gen_create_phy(struct device *dev, struct usb_phy_generic *nop)
235226
if (!nop->phy.otg)
236227
return -ENOMEM;
237228

238-
nop->clk = devm_clk_get(dev, "main_clk");
229+
nop->clk = devm_clk_get_optional(dev, "main_clk");
239230
if (IS_ERR(nop->clk)) {
240231
dev_dbg(dev, "Can't get phy clock: %ld\n",
241232
PTR_ERR(nop->clk));
242-
if (needs_clk)
243-
return PTR_ERR(nop->clk);
233+
return PTR_ERR(nop->clk);
244234
}
245235

246-
if (!IS_ERR(nop->clk) && clk_rate) {
236+
if (clk_rate) {
247237
err = clk_set_rate(nop->clk, clk_rate);
248238
if (err) {
249239
dev_err(dev, "Error setting clock rate\n");

0 commit comments

Comments
 (0)