u32 cs_bits, max_bits_per_word;
struct spi_controller *host;
- host = spi_alloc_host(&pdev->dev, sizeof(struct sifive_spi));
+ host = devm_spi_alloc_host(&pdev->dev, sizeof(struct sifive_spi));
if (!host) {
dev_err(&pdev->dev, "out of memory\n");
return -ENOMEM;
platform_set_drvdata(pdev, host);
spi->regs = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(spi->regs)) {
- ret = PTR_ERR(spi->regs);
- goto put_host;
- }
+ if (IS_ERR(spi->regs))
+ return PTR_ERR(spi->regs);
/* Spin up the bus clock before hitting registers */
spi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(spi->clk)) {
dev_err(&pdev->dev, "Unable to find bus clock\n");
- ret = PTR_ERR(spi->clk);
- goto put_host;
+ return PTR_ERR(spi->clk);
}
irq = platform_get_irq(pdev, 0);
- if (irq < 0) {
- ret = irq;
- goto put_host;
- }
+ if (irq < 0)
+ return irq;
/* Optional parameters */
ret =
if (!ret && max_bits_per_word < 8) {
dev_err(&pdev->dev, "Only 8bit SPI words supported by the driver\n");
- ret = -EINVAL;
- goto put_host;
+ return -EINVAL;
}
/* probe the number of CS lines */
sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, spi->cs_inactive);
if (!cs_bits) {
dev_err(&pdev->dev, "Could not auto probe CS lines\n");
- ret = -EINVAL;
- goto put_host;
+ return -EINVAL;
}
num_cs = ilog2(cs_bits) + 1;
if (num_cs > SIFIVE_SPI_MAX_CS) {
dev_err(&pdev->dev, "Invalid number of spi targets\n");
- ret = -EINVAL;
- goto put_host;
+ return -EINVAL;
}
/* Define our host */
dev_name(&pdev->dev), spi);
if (ret) {
dev_err(&pdev->dev, "Unable to bind to interrupt\n");
- goto put_host;
+ return ret;
}
dev_info(&pdev->dev, "mapped; irq=%d, cs=%d\n",
ret = spi_register_controller(host);
if (ret < 0) {
dev_err(&pdev->dev, "spi_register_host failed\n");
- goto put_host;
+ return ret;
}
return 0;
-
-put_host:
- spi_controller_put(host);
-
- return ret;
}
static void sifive_spi_remove(struct platform_device *pdev)
struct spi_controller *host = platform_get_drvdata(pdev);
struct sifive_spi *spi = spi_controller_get_devdata(host);
- spi_controller_get(host);
-
spi_unregister_controller(host);
/* Disable all the interrupts just in case */
sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0);
-
- spi_controller_put(host);
}
static int sifive_spi_suspend(struct device *dev)