spi: mpc5xxx-psc: Convert probe to use devres functions
Convert the mpc52xx-psc and mpc512x-psc drivers to use the managed devres variants of functions in probe. Also use dev_err_probe() as appropriate. With this, the error handling can be simplified. Signed-off-by: Rob Herring <robh@kernel.org> Link: https://lore.kernel.org/r/20230217-dt-mpc5xxx-spi-v1-2-3be8602fce1e@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Родитель
04725901d9
Коммит
0160233652
|
@ -467,7 +467,7 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr,
|
||||||
void *tempp;
|
void *tempp;
|
||||||
struct clk *clk;
|
struct clk *clk;
|
||||||
|
|
||||||
master = spi_alloc_master(dev, sizeof(*mps));
|
master = devm_spi_alloc_master(dev, sizeof(*mps));
|
||||||
if (master == NULL)
|
if (master == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -486,28 +486,24 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr,
|
||||||
master->dev.of_node = dev->of_node;
|
master->dev.of_node = dev->of_node;
|
||||||
|
|
||||||
tempp = devm_ioremap(dev, regaddr, size);
|
tempp = devm_ioremap(dev, regaddr, size);
|
||||||
if (!tempp) {
|
if (!tempp)
|
||||||
dev_err(dev, "could not ioremap I/O port range\n");
|
return dev_err_probe(dev, -EFAULT, "could not ioremap I/O port range\n");
|
||||||
ret = -EFAULT;
|
|
||||||
goto free_master;
|
|
||||||
}
|
|
||||||
mps->psc = tempp;
|
mps->psc = tempp;
|
||||||
mps->fifo =
|
mps->fifo =
|
||||||
(struct mpc512x_psc_fifo *)(tempp + sizeof(struct mpc52xx_psc));
|
(struct mpc512x_psc_fifo *)(tempp + sizeof(struct mpc52xx_psc));
|
||||||
ret = devm_request_irq(dev, mps->irq, mpc512x_psc_spi_isr, IRQF_SHARED,
|
ret = devm_request_irq(dev, mps->irq, mpc512x_psc_spi_isr, IRQF_SHARED,
|
||||||
"mpc512x-psc-spi", mps);
|
"mpc512x-psc-spi", mps);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto free_master;
|
return ret;
|
||||||
init_completion(&mps->txisrdone);
|
init_completion(&mps->txisrdone);
|
||||||
|
|
||||||
clk = devm_clk_get(dev, "mclk");
|
clk = devm_clk_get(dev, "mclk");
|
||||||
if (IS_ERR(clk)) {
|
if (IS_ERR(clk))
|
||||||
ret = PTR_ERR(clk);
|
return PTR_ERR(clk);
|
||||||
goto free_master;
|
|
||||||
}
|
|
||||||
ret = clk_prepare_enable(clk);
|
ret = clk_prepare_enable(clk);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto free_master;
|
return ret;
|
||||||
mps->clk_mclk = clk;
|
mps->clk_mclk = clk;
|
||||||
mps->mclk_rate = clk_get_rate(clk);
|
mps->mclk_rate = clk_get_rate(clk);
|
||||||
|
|
||||||
|
@ -535,8 +531,6 @@ free_ipg_clock:
|
||||||
clk_disable_unprepare(mps->clk_ipg);
|
clk_disable_unprepare(mps->clk_ipg);
|
||||||
free_mclk_clock:
|
free_mclk_clock:
|
||||||
clk_disable_unprepare(mps->clk_mclk);
|
clk_disable_unprepare(mps->clk_mclk);
|
||||||
free_master:
|
|
||||||
spi_master_put(master);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,7 +300,7 @@ static int mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
|
||||||
struct spi_master *master;
|
struct spi_master *master;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
master = spi_alloc_master(dev, sizeof(*mps));
|
master = devm_spi_alloc_master(dev, sizeof(*mps));
|
||||||
if (master == NULL)
|
if (master == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -318,42 +318,24 @@ static int mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
|
||||||
master->cleanup = mpc52xx_psc_spi_cleanup;
|
master->cleanup = mpc52xx_psc_spi_cleanup;
|
||||||
master->dev.of_node = dev->of_node;
|
master->dev.of_node = dev->of_node;
|
||||||
|
|
||||||
mps->psc = ioremap(regaddr, size);
|
mps->psc = devm_ioremap(dev, regaddr, size);
|
||||||
if (!mps->psc) {
|
if (!mps->psc)
|
||||||
dev_err(dev, "could not ioremap I/O port range\n");
|
return dev_err_probe(dev, -EFAULT, "could not ioremap I/O port range\n");
|
||||||
ret = -EFAULT;
|
|
||||||
goto free_master;
|
|
||||||
}
|
|
||||||
/* On the 5200, fifo regs are immediately ajacent to the psc regs */
|
/* On the 5200, fifo regs are immediately ajacent to the psc regs */
|
||||||
mps->fifo = ((void __iomem *)mps->psc) + sizeof(struct mpc52xx_psc);
|
mps->fifo = ((void __iomem *)mps->psc) + sizeof(struct mpc52xx_psc);
|
||||||
|
|
||||||
ret = request_irq(mps->irq, mpc52xx_psc_spi_isr, 0, "mpc52xx-psc-spi",
|
ret = devm_request_irq(dev, mps->irq, mpc52xx_psc_spi_isr, 0,
|
||||||
mps);
|
"mpc52xx-psc-spi", mps);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto free_master;
|
return ret;
|
||||||
|
|
||||||
ret = mpc52xx_psc_spi_port_config(master->bus_num, mps);
|
ret = mpc52xx_psc_spi_port_config(master->bus_num, mps);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
dev_err(dev, "can't configure PSC! Is it capable of SPI?\n");
|
return dev_err_probe(dev, ret, "can't configure PSC! Is it capable of SPI?\n");
|
||||||
goto free_irq;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_completion(&mps->done);
|
init_completion(&mps->done);
|
||||||
|
|
||||||
ret = spi_register_master(master);
|
return devm_spi_register_master(dev, master);
|
||||||
if (ret < 0)
|
|
||||||
goto free_irq;
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
free_irq:
|
|
||||||
free_irq(mps->irq, mps);
|
|
||||||
free_master:
|
|
||||||
if (mps->psc)
|
|
||||||
iounmap(mps->psc);
|
|
||||||
spi_master_put(master);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mpc52xx_psc_spi_of_probe(struct platform_device *op)
|
static int mpc52xx_psc_spi_of_probe(struct platform_device *op)
|
||||||
|
@ -385,20 +367,6 @@ static int mpc52xx_psc_spi_of_probe(struct platform_device *op)
|
||||||
irq_of_parse_and_map(op->dev.of_node, 0), id);
|
irq_of_parse_and_map(op->dev.of_node, 0), id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mpc52xx_psc_spi_of_remove(struct platform_device *op)
|
|
||||||
{
|
|
||||||
struct spi_master *master = spi_master_get(platform_get_drvdata(op));
|
|
||||||
struct mpc52xx_psc_spi *mps = spi_master_get_devdata(master);
|
|
||||||
|
|
||||||
spi_unregister_master(master);
|
|
||||||
free_irq(mps->irq, mps);
|
|
||||||
if (mps->psc)
|
|
||||||
iounmap(mps->psc);
|
|
||||||
spi_master_put(master);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const struct of_device_id mpc52xx_psc_spi_of_match[] = {
|
static const struct of_device_id mpc52xx_psc_spi_of_match[] = {
|
||||||
{ .compatible = "fsl,mpc5200-psc-spi", },
|
{ .compatible = "fsl,mpc5200-psc-spi", },
|
||||||
{ .compatible = "mpc5200-psc-spi", }, /* old */
|
{ .compatible = "mpc5200-psc-spi", }, /* old */
|
||||||
|
@ -409,7 +377,6 @@ MODULE_DEVICE_TABLE(of, mpc52xx_psc_spi_of_match);
|
||||||
|
|
||||||
static struct platform_driver mpc52xx_psc_spi_of_driver = {
|
static struct platform_driver mpc52xx_psc_spi_of_driver = {
|
||||||
.probe = mpc52xx_psc_spi_of_probe,
|
.probe = mpc52xx_psc_spi_of_probe,
|
||||||
.remove = mpc52xx_psc_spi_of_remove,
|
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = "mpc52xx-psc-spi",
|
.name = "mpc52xx-psc-spi",
|
||||||
.of_match_table = mpc52xx_psc_spi_of_match,
|
.of_match_table = mpc52xx_psc_spi_of_match,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче