mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 03:27:30 -04:00
spi: meson-spicc: switch to managed controller allocation
Switch to device managed controller allocation to simplify error handling and to avoid having to take another reference during deregistration. Signed-off-by: Johan Hovold <johan@kernel.org> Link: https://patch.msgid.link/20260429091333.165363-16-johan@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
@@ -982,7 +982,7 @@ static int meson_spicc_probe(struct platform_device *pdev)
|
||||
struct meson_spicc_device *spicc;
|
||||
int ret, irq;
|
||||
|
||||
host = spi_alloc_host(&pdev->dev, sizeof(*spicc));
|
||||
host = devm_spi_alloc_host(&pdev->dev, sizeof(*spicc));
|
||||
if (!host) {
|
||||
dev_err(&pdev->dev, "host allocation failed\n");
|
||||
return -ENOMEM;
|
||||
@@ -993,8 +993,7 @@ static int meson_spicc_probe(struct platform_device *pdev)
|
||||
spicc->data = of_device_get_match_data(&pdev->dev);
|
||||
if (!spicc->data) {
|
||||
dev_err(&pdev->dev, "failed to get match data\n");
|
||||
ret = -EINVAL;
|
||||
goto out_host;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
spicc->pdev = pdev;
|
||||
@@ -1005,8 +1004,7 @@ static int meson_spicc_probe(struct platform_device *pdev)
|
||||
spicc->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(spicc->base)) {
|
||||
dev_err(&pdev->dev, "io resource mapping failed\n");
|
||||
ret = PTR_ERR(spicc->base);
|
||||
goto out_host;
|
||||
return PTR_ERR(spicc->base);
|
||||
}
|
||||
|
||||
/* Set master mode and enable controller */
|
||||
@@ -1017,39 +1015,33 @@ static int meson_spicc_probe(struct platform_device *pdev)
|
||||
writel_relaxed(0, spicc->base + SPICC_INTREG);
|
||||
|
||||
irq = platform_get_irq(pdev, 0);
|
||||
if (irq < 0) {
|
||||
ret = irq;
|
||||
goto out_host;
|
||||
}
|
||||
if (irq < 0)
|
||||
return irq;
|
||||
|
||||
ret = devm_request_irq(&pdev->dev, irq, meson_spicc_irq,
|
||||
0, NULL, spicc);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "irq request failed\n");
|
||||
goto out_host;
|
||||
return ret;
|
||||
}
|
||||
|
||||
spicc->core = devm_clk_get_enabled(&pdev->dev, "core");
|
||||
if (IS_ERR(spicc->core)) {
|
||||
dev_err(&pdev->dev, "core clock request failed\n");
|
||||
ret = PTR_ERR(spicc->core);
|
||||
goto out_host;
|
||||
return PTR_ERR(spicc->core);
|
||||
}
|
||||
|
||||
if (spicc->data->has_pclk) {
|
||||
spicc->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
|
||||
if (IS_ERR(spicc->pclk)) {
|
||||
dev_err(&pdev->dev, "pclk clock request failed\n");
|
||||
ret = PTR_ERR(spicc->pclk);
|
||||
goto out_host;
|
||||
return PTR_ERR(spicc->pclk);
|
||||
}
|
||||
}
|
||||
|
||||
spicc->pinctrl = devm_pinctrl_get(&pdev->dev);
|
||||
if (IS_ERR(spicc->pinctrl)) {
|
||||
ret = PTR_ERR(spicc->pinctrl);
|
||||
goto out_host;
|
||||
}
|
||||
if (IS_ERR(spicc->pinctrl))
|
||||
return PTR_ERR(spicc->pinctrl);
|
||||
|
||||
device_reset_optional(&pdev->dev);
|
||||
|
||||
@@ -1070,43 +1062,34 @@ static int meson_spicc_probe(struct platform_device *pdev)
|
||||
ret = meson_spicc_pow2_clk_init(spicc);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "pow2 clock registration failed\n");
|
||||
goto out_host;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (spicc->data->has_enhance_clk_div) {
|
||||
ret = meson_spicc_enh_clk_init(spicc);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "clock registration failed\n");
|
||||
goto out_host;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
ret = spi_register_controller(host);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "spi registration failed\n");
|
||||
goto out_host;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
out_host:
|
||||
spi_controller_put(host);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void meson_spicc_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct meson_spicc_device *spicc = platform_get_drvdata(pdev);
|
||||
|
||||
spi_controller_get(spicc->host);
|
||||
|
||||
spi_unregister_controller(spicc->host);
|
||||
|
||||
/* Disable SPI */
|
||||
writel(0, spicc->base + SPICC_CONREG);
|
||||
|
||||
spi_controller_put(spicc->host);
|
||||
}
|
||||
|
||||
static const struct meson_spicc_data meson_spicc_gx_data = {
|
||||
|
||||
Reference in New Issue
Block a user