mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-15 21:23:23 +00:00
spi: axi-spi-engine: use devm_spi_alloc_host()
This modifies the AXI SPI Engine driver to use devm_spi_alloc_host() instead of spi_alloc_host() to simplify the code a bit. In addition to simplifying the error paths in the probe function, we can also remove spi_controller_get/put() calls in the remove function since devm_spi_alloc_host() sets a flag to no longer decrement the controller reference count in the spi_unregister_controller() function. Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://lore.kernel.org/r/20231117-axi-spi-engine-series-1-v1-4-cc59db999b87@baylibre.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
9e4ce5220e
commit
e12cd96e8e
@ -473,7 +473,7 @@ static int spi_engine_probe(struct platform_device *pdev)
|
|||||||
if (irq < 0)
|
if (irq < 0)
|
||||||
return irq;
|
return irq;
|
||||||
|
|
||||||
host = spi_alloc_host(&pdev->dev, sizeof(*spi_engine));
|
host = devm_spi_alloc_host(&pdev->dev, sizeof(*spi_engine));
|
||||||
if (!host)
|
if (!host)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -482,22 +482,16 @@ static int spi_engine_probe(struct platform_device *pdev)
|
|||||||
spin_lock_init(&spi_engine->lock);
|
spin_lock_init(&spi_engine->lock);
|
||||||
|
|
||||||
spi_engine->clk = devm_clk_get_enabled(&pdev->dev, "s_axi_aclk");
|
spi_engine->clk = devm_clk_get_enabled(&pdev->dev, "s_axi_aclk");
|
||||||
if (IS_ERR(spi_engine->clk)) {
|
if (IS_ERR(spi_engine->clk))
|
||||||
ret = PTR_ERR(spi_engine->clk);
|
return PTR_ERR(spi_engine->clk);
|
||||||
goto err_put_host;
|
|
||||||
}
|
|
||||||
|
|
||||||
spi_engine->ref_clk = devm_clk_get_enabled(&pdev->dev, "spi_clk");
|
spi_engine->ref_clk = devm_clk_get_enabled(&pdev->dev, "spi_clk");
|
||||||
if (IS_ERR(spi_engine->ref_clk)) {
|
if (IS_ERR(spi_engine->ref_clk))
|
||||||
ret = PTR_ERR(spi_engine->ref_clk);
|
return PTR_ERR(spi_engine->ref_clk);
|
||||||
goto err_put_host;
|
|
||||||
}
|
|
||||||
|
|
||||||
spi_engine->base = devm_platform_ioremap_resource(pdev, 0);
|
spi_engine->base = devm_platform_ioremap_resource(pdev, 0);
|
||||||
if (IS_ERR(spi_engine->base)) {
|
if (IS_ERR(spi_engine->base))
|
||||||
ret = PTR_ERR(spi_engine->base);
|
return PTR_ERR(spi_engine->base);
|
||||||
goto err_put_host;
|
|
||||||
}
|
|
||||||
|
|
||||||
version = readl(spi_engine->base + SPI_ENGINE_REG_VERSION);
|
version = readl(spi_engine->base + SPI_ENGINE_REG_VERSION);
|
||||||
if (SPI_ENGINE_VERSION_MAJOR(version) != 1) {
|
if (SPI_ENGINE_VERSION_MAJOR(version) != 1) {
|
||||||
@ -505,8 +499,7 @@ static int spi_engine_probe(struct platform_device *pdev)
|
|||||||
SPI_ENGINE_VERSION_MAJOR(version),
|
SPI_ENGINE_VERSION_MAJOR(version),
|
||||||
SPI_ENGINE_VERSION_MINOR(version),
|
SPI_ENGINE_VERSION_MINOR(version),
|
||||||
SPI_ENGINE_VERSION_PATCH(version));
|
SPI_ENGINE_VERSION_PATCH(version));
|
||||||
ret = -ENODEV;
|
return -ENODEV;
|
||||||
goto err_put_host;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_RESET);
|
writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_RESET);
|
||||||
@ -515,7 +508,7 @@ static int spi_engine_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
ret = request_irq(irq, spi_engine_irq, 0, pdev->name, host);
|
ret = request_irq(irq, spi_engine_irq, 0, pdev->name, host);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err_put_host;
|
return ret;
|
||||||
|
|
||||||
host->dev.of_node = pdev->dev.of_node;
|
host->dev.of_node = pdev->dev.of_node;
|
||||||
host->mode_bits = SPI_CPOL | SPI_CPHA | SPI_3WIRE;
|
host->mode_bits = SPI_CPOL | SPI_CPHA | SPI_3WIRE;
|
||||||
@ -533,14 +526,12 @@ static int spi_engine_probe(struct platform_device *pdev)
|
|||||||
return 0;
|
return 0;
|
||||||
err_free_irq:
|
err_free_irq:
|
||||||
free_irq(irq, host);
|
free_irq(irq, host);
|
||||||
err_put_host:
|
|
||||||
spi_controller_put(host);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spi_engine_remove(struct platform_device *pdev)
|
static void spi_engine_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct spi_controller *host = spi_controller_get(platform_get_drvdata(pdev));
|
struct spi_controller *host = platform_get_drvdata(pdev);
|
||||||
struct spi_engine *spi_engine = spi_controller_get_devdata(host);
|
struct spi_engine *spi_engine = spi_controller_get_devdata(host);
|
||||||
int irq = platform_get_irq(pdev, 0);
|
int irq = platform_get_irq(pdev, 0);
|
||||||
|
|
||||||
@ -548,8 +539,6 @@ static void spi_engine_remove(struct platform_device *pdev)
|
|||||||
|
|
||||||
free_irq(irq, host);
|
free_irq(irq, host);
|
||||||
|
|
||||||
spi_controller_put(host);
|
|
||||||
|
|
||||||
writel_relaxed(0xff, spi_engine->base + SPI_ENGINE_REG_INT_PENDING);
|
writel_relaxed(0xff, spi_engine->base + SPI_ENGINE_REG_INT_PENDING);
|
||||||
writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_INT_ENABLE);
|
writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_INT_ENABLE);
|
||||||
writel_relaxed(0x01, spi_engine->base + SPI_ENGINE_REG_RESET);
|
writel_relaxed(0x01, spi_engine->base + SPI_ENGINE_REG_RESET);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user