Skip to content

Commit 27fcf3d

Browse files
Pei Xiaogregkh
authored andcommitted
spi: sifive: Simplify clock handling with devm_clk_get_enabled()
[ Upstream commit 140039c ] Replace devm_clk_get() followed by clk_prepare_enable() with devm_clk_get_enabled() for the bus clock. This reduces boilerplate code and error handling, as the managed API automatically disables the clock when the device is removed or if probe fails. Remove the now-unnecessary clk_disable_unprepare() calls from the probe error path and the remove callback. Adjust the error handling to use the existing put_host label. Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn> Link: https://patch.msgid.link/73d0d8ecb4e1af5a558d6a7866c0f886d94fe3d1.1773885292.git.xiaopei01@kylinos.cn Signed-off-by: Mark Brown <broonie@kernel.org> Stable-dep-of: 0f25236 ("spi: sifive: fix controller deregistration") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fac9cfa commit 27fcf3d

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

drivers/spi/spi-sifive.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ static int sifive_spi_probe(struct platform_device *pdev)
312312
goto put_host;
313313
}
314314

315-
spi->clk = devm_clk_get(&pdev->dev, NULL);
315+
/* Spin up the bus clock before hitting registers */
316+
spi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
316317
if (IS_ERR(spi->clk)) {
317318
dev_err(&pdev->dev, "Unable to find bus clock\n");
318319
ret = PTR_ERR(spi->clk);
@@ -342,13 +343,6 @@ static int sifive_spi_probe(struct platform_device *pdev)
342343
goto put_host;
343344
}
344345

345-
/* Spin up the bus clock before hitting registers */
346-
ret = clk_prepare_enable(spi->clk);
347-
if (ret) {
348-
dev_err(&pdev->dev, "Unable to enable bus clock\n");
349-
goto put_host;
350-
}
351-
352346
/* probe the number of CS lines */
353347
spi->cs_inactive = sifive_spi_read(spi, SIFIVE_SPI_REG_CSDEF);
354348
sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, 0xffffffffU);
@@ -357,14 +351,14 @@ static int sifive_spi_probe(struct platform_device *pdev)
357351
if (!cs_bits) {
358352
dev_err(&pdev->dev, "Could not auto probe CS lines\n");
359353
ret = -EINVAL;
360-
goto disable_clk;
354+
goto put_host;
361355
}
362356

363357
num_cs = ilog2(cs_bits) + 1;
364358
if (num_cs > SIFIVE_SPI_MAX_CS) {
365359
dev_err(&pdev->dev, "Invalid number of spi targets\n");
366360
ret = -EINVAL;
367-
goto disable_clk;
361+
goto put_host;
368362
}
369363

370364
/* Define our host */
@@ -393,7 +387,7 @@ static int sifive_spi_probe(struct platform_device *pdev)
393387
dev_name(&pdev->dev), spi);
394388
if (ret) {
395389
dev_err(&pdev->dev, "Unable to bind to interrupt\n");
396-
goto disable_clk;
390+
goto put_host;
397391
}
398392

399393
dev_info(&pdev->dev, "mapped; irq=%d, cs=%d\n",
@@ -402,13 +396,11 @@ static int sifive_spi_probe(struct platform_device *pdev)
402396
ret = devm_spi_register_controller(&pdev->dev, host);
403397
if (ret < 0) {
404398
dev_err(&pdev->dev, "spi_register_host failed\n");
405-
goto disable_clk;
399+
goto put_host;
406400
}
407401

408402
return 0;
409403

410-
disable_clk:
411-
clk_disable_unprepare(spi->clk);
412404
put_host:
413405
spi_controller_put(host);
414406

@@ -422,7 +414,6 @@ static void sifive_spi_remove(struct platform_device *pdev)
422414

423415
/* Disable all the interrupts just in case */
424416
sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0);
425-
clk_disable_unprepare(spi->clk);
426417
}
427418

428419
static int sifive_spi_suspend(struct device *dev)

0 commit comments

Comments
 (0)