Skip to content

Commit da426ed

Browse files
Zhang ZekunBartosz Golaszewski
authored andcommitted
gpio: cadence: Use helper function devm_clk_get_enabled()
devm_clk_get() and clk_prepare_enable() can be replaced by helper function devm_clk_get_enabled(). Let's use devm_clk_get_enabled() to simplify code and avoid calling clk_disable_unprepare(). Signed-off-by: Zhang Zekun <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent f4d08a8 commit da426ed

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

drivers/gpio/gpio-cadence.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
struct cdns_gpio_chip {
3333
struct gpio_chip gc;
34-
struct clk *pclk;
3534
void __iomem *regs;
3635
u32 bypass_orig;
3736
};
@@ -155,6 +154,7 @@ static int cdns_gpio_probe(struct platform_device *pdev)
155154
int ret, irq;
156155
u32 dir_prev;
157156
u32 num_gpios = 32;
157+
struct clk *clk;
158158

159159
cgpio = devm_kzalloc(&pdev->dev, sizeof(*cgpio), GFP_KERNEL);
160160
if (!cgpio)
@@ -203,21 +203,14 @@ static int cdns_gpio_probe(struct platform_device *pdev)
203203
cgpio->gc.request = cdns_gpio_request;
204204
cgpio->gc.free = cdns_gpio_free;
205205

206-
cgpio->pclk = devm_clk_get(&pdev->dev, NULL);
207-
if (IS_ERR(cgpio->pclk)) {
208-
ret = PTR_ERR(cgpio->pclk);
206+
clk = devm_clk_get_enabled(&pdev->dev, NULL);
207+
if (IS_ERR(clk)) {
208+
ret = PTR_ERR(clk);
209209
dev_err(&pdev->dev,
210210
"Failed to retrieve peripheral clock, %d\n", ret);
211211
goto err_revert_dir;
212212
}
213213

214-
ret = clk_prepare_enable(cgpio->pclk);
215-
if (ret) {
216-
dev_err(&pdev->dev,
217-
"Failed to enable the peripheral clock, %d\n", ret);
218-
goto err_revert_dir;
219-
}
220-
221214
/*
222215
* Optional irq_chip support
223216
*/
@@ -234,7 +227,7 @@ static int cdns_gpio_probe(struct platform_device *pdev)
234227
GFP_KERNEL);
235228
if (!girq->parents) {
236229
ret = -ENOMEM;
237-
goto err_disable_clk;
230+
goto err_revert_dir;
238231
}
239232
girq->parents[0] = irq;
240233
girq->default_type = IRQ_TYPE_NONE;
@@ -244,7 +237,7 @@ static int cdns_gpio_probe(struct platform_device *pdev)
244237
ret = devm_gpiochip_add_data(&pdev->dev, &cgpio->gc, cgpio);
245238
if (ret < 0) {
246239
dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
247-
goto err_disable_clk;
240+
goto err_revert_dir;
248241
}
249242

250243
cgpio->bypass_orig = ioread32(cgpio->regs + CDNS_GPIO_BYPASS_MODE);
@@ -259,9 +252,6 @@ static int cdns_gpio_probe(struct platform_device *pdev)
259252
platform_set_drvdata(pdev, cgpio);
260253
return 0;
261254

262-
err_disable_clk:
263-
clk_disable_unprepare(cgpio->pclk);
264-
265255
err_revert_dir:
266256
iowrite32(dir_prev, cgpio->regs + CDNS_GPIO_DIRECTION_MODE);
267257

@@ -273,7 +263,6 @@ static void cdns_gpio_remove(struct platform_device *pdev)
273263
struct cdns_gpio_chip *cgpio = platform_get_drvdata(pdev);
274264

275265
iowrite32(cgpio->bypass_orig, cgpio->regs + CDNS_GPIO_BYPASS_MODE);
276-
clk_disable_unprepare(cgpio->pclk);
277266
}
278267

279268
static const struct of_device_id cdns_of_ids[] = {

0 commit comments

Comments
 (0)