Commit fd811b62 authored by Mark Brown's avatar Mark Brown

spi: Use devm_clk_get_*() helper function to

Merge series from Li Zetao <lizetao1@huawei.com>:

Commit 7ef9651e ("clk: Provide new devm_clk helpers for prepared
and enabled clocks") provides a new helper function for prepared and
enabled clocks when a driver keeps a clock prepared (or enabled) during
the whole lifetime of the driver. So where drivers get clocks and enable
them immediately, it can be combined into a single function
devm_clk_get_*(). Moreover, the unprepare and disable function
has been registered to devm_clk_state, and before devm_clk_state is
released, the clocks will be unprepareed and disable, so it is unnecessary
to unprepare and disable clocks explicitly when remove drivers or in the
error handling path.
parents fffae3af d6c612a3
...@@ -168,27 +168,21 @@ static int ar934x_spi_probe(struct platform_device *pdev) ...@@ -168,27 +168,21 @@ static int ar934x_spi_probe(struct platform_device *pdev)
struct ar934x_spi *sp; struct ar934x_spi *sp;
void __iomem *base; void __iomem *base;
struct clk *clk; struct clk *clk;
int ret;
base = devm_platform_ioremap_resource(pdev, 0); base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(base)) if (IS_ERR(base))
return PTR_ERR(base); return PTR_ERR(base);
clk = devm_clk_get(&pdev->dev, NULL); clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(clk)) { if (IS_ERR(clk)) {
dev_err(&pdev->dev, "failed to get clock\n"); dev_err(&pdev->dev, "failed to get clock\n");
return PTR_ERR(clk); return PTR_ERR(clk);
} }
ret = clk_prepare_enable(clk);
if (ret)
return ret;
ctlr = devm_spi_alloc_host(&pdev->dev, sizeof(*sp)); ctlr = devm_spi_alloc_host(&pdev->dev, sizeof(*sp));
if (!ctlr) { if (!ctlr) {
dev_info(&pdev->dev, "failed to allocate spi controller\n"); dev_info(&pdev->dev, "failed to allocate spi controller\n");
ret = -ENOMEM; return -ENOMEM;
goto err_clk_disable;
} }
/* disable flash mapping and expose spi controller registers */ /* disable flash mapping and expose spi controller registers */
...@@ -212,25 +206,15 @@ static int ar934x_spi_probe(struct platform_device *pdev) ...@@ -212,25 +206,15 @@ static int ar934x_spi_probe(struct platform_device *pdev)
sp->clk_freq = clk_get_rate(clk); sp->clk_freq = clk_get_rate(clk);
sp->ctlr = ctlr; sp->ctlr = ctlr;
ret = spi_register_controller(ctlr); return spi_register_controller(ctlr);
if (!ret)
return 0;
err_clk_disable:
clk_disable_unprepare(clk);
return ret;
} }
static void ar934x_spi_remove(struct platform_device *pdev) static void ar934x_spi_remove(struct platform_device *pdev)
{ {
struct spi_controller *ctlr; struct spi_controller *ctlr;
struct ar934x_spi *sp;
ctlr = dev_get_drvdata(&pdev->dev); ctlr = dev_get_drvdata(&pdev->dev);
sp = spi_controller_get_devdata(ctlr);
spi_unregister_controller(ctlr); spi_unregister_controller(ctlr);
clk_disable_unprepare(sp->clk);
} }
static struct platform_driver ar934x_spi_driver = { static struct platform_driver ar934x_spi_driver = {
......
...@@ -865,18 +865,12 @@ static int a3700_spi_probe(struct platform_device *pdev) ...@@ -865,18 +865,12 @@ static int a3700_spi_probe(struct platform_device *pdev)
init_completion(&spi->done); init_completion(&spi->done);
spi->clk = devm_clk_get(dev, NULL); spi->clk = devm_clk_get_prepared(dev, NULL);
if (IS_ERR(spi->clk)) { if (IS_ERR(spi->clk)) {
dev_err(dev, "could not find clk: %ld\n", PTR_ERR(spi->clk)); dev_err(dev, "could not find clk: %ld\n", PTR_ERR(spi->clk));
goto error; goto error;
} }
ret = clk_prepare(spi->clk);
if (ret) {
dev_err(dev, "could not prepare clk: %d\n", ret);
goto error;
}
host->max_speed_hz = min_t(unsigned long, A3700_SPI_MAX_SPEED_HZ, host->max_speed_hz = min_t(unsigned long, A3700_SPI_MAX_SPEED_HZ,
clk_get_rate(spi->clk)); clk_get_rate(spi->clk));
host->min_speed_hz = DIV_ROUND_UP(clk_get_rate(spi->clk), host->min_speed_hz = DIV_ROUND_UP(clk_get_rate(spi->clk),
...@@ -888,40 +882,29 @@ static int a3700_spi_probe(struct platform_device *pdev) ...@@ -888,40 +882,29 @@ static int a3700_spi_probe(struct platform_device *pdev)
dev_name(dev), host); dev_name(dev), host);
if (ret) { if (ret) {
dev_err(dev, "could not request IRQ: %d\n", ret); dev_err(dev, "could not request IRQ: %d\n", ret);
goto error_clk; goto error;
} }
ret = devm_spi_register_controller(dev, host); ret = devm_spi_register_controller(dev, host);
if (ret) { if (ret) {
dev_err(dev, "Failed to register host\n"); dev_err(dev, "Failed to register host\n");
goto error_clk; goto error;
} }
return 0; return 0;
error_clk:
clk_unprepare(spi->clk);
error: error:
spi_controller_put(host); spi_controller_put(host);
out: out:
return ret; return ret;
} }
static void a3700_spi_remove(struct platform_device *pdev)
{
struct spi_controller *host = platform_get_drvdata(pdev);
struct a3700_spi *spi = spi_controller_get_devdata(host);
clk_unprepare(spi->clk);
}
static struct platform_driver a3700_spi_driver = { static struct platform_driver a3700_spi_driver = {
.driver = { .driver = {
.name = DRIVER_NAME, .name = DRIVER_NAME,
.of_match_table = of_match_ptr(a3700_spi_dt_ids), .of_match_table = of_match_ptr(a3700_spi_dt_ids),
}, },
.probe = a3700_spi_probe, .probe = a3700_spi_probe,
.remove_new = a3700_spi_remove,
}; };
module_platform_driver(a3700_spi_driver); module_platform_driver(a3700_spi_driver);
......
...@@ -748,7 +748,7 @@ static int aspeed_spi_probe(struct platform_device *pdev) ...@@ -748,7 +748,7 @@ static int aspeed_spi_probe(struct platform_device *pdev)
aspi->ahb_window_size = resource_size(res); aspi->ahb_window_size = resource_size(res);
aspi->ahb_base_phy = res->start; aspi->ahb_base_phy = res->start;
aspi->clk = devm_clk_get(&pdev->dev, NULL); aspi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(aspi->clk)) { if (IS_ERR(aspi->clk)) {
dev_err(dev, "missing clock\n"); dev_err(dev, "missing clock\n");
return PTR_ERR(aspi->clk); return PTR_ERR(aspi->clk);
...@@ -760,12 +760,6 @@ static int aspeed_spi_probe(struct platform_device *pdev) ...@@ -760,12 +760,6 @@ static int aspeed_spi_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
ret = clk_prepare_enable(aspi->clk);
if (ret) {
dev_err(dev, "can not enable the clock\n");
return ret;
}
/* IRQ is for DMA, which the driver doesn't support yet */ /* IRQ is for DMA, which the driver doesn't support yet */
ctlr->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | data->mode_bits; ctlr->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | data->mode_bits;
...@@ -777,14 +771,9 @@ static int aspeed_spi_probe(struct platform_device *pdev) ...@@ -777,14 +771,9 @@ static int aspeed_spi_probe(struct platform_device *pdev)
ctlr->dev.of_node = dev->of_node; ctlr->dev.of_node = dev->of_node;
ret = devm_spi_register_controller(dev, ctlr); ret = devm_spi_register_controller(dev, ctlr);
if (ret) { if (ret)
dev_err(&pdev->dev, "spi_register_controller failed\n"); dev_err(&pdev->dev, "spi_register_controller failed\n");
goto disable_clk;
}
return 0;
disable_clk:
clk_disable_unprepare(aspi->clk);
return ret; return ret;
} }
...@@ -793,7 +782,6 @@ static void aspeed_spi_remove(struct platform_device *pdev) ...@@ -793,7 +782,6 @@ static void aspeed_spi_remove(struct platform_device *pdev)
struct aspeed_spi *aspi = platform_get_drvdata(pdev); struct aspeed_spi *aspi = platform_get_drvdata(pdev);
aspeed_spi_enable(aspi, false); aspeed_spi_enable(aspi, false);
clk_disable_unprepare(aspi->clk);
} }
/* /*
......
...@@ -200,20 +200,16 @@ static int ath79_spi_probe(struct platform_device *pdev) ...@@ -200,20 +200,16 @@ static int ath79_spi_probe(struct platform_device *pdev)
goto err_put_host; goto err_put_host;
} }
sp->clk = devm_clk_get(&pdev->dev, "ahb"); sp->clk = devm_clk_get_enabled(&pdev->dev, "ahb");
if (IS_ERR(sp->clk)) { if (IS_ERR(sp->clk)) {
ret = PTR_ERR(sp->clk); ret = PTR_ERR(sp->clk);
goto err_put_host; goto err_put_host;
} }
ret = clk_prepare_enable(sp->clk);
if (ret)
goto err_put_host;
rate = DIV_ROUND_UP(clk_get_rate(sp->clk), MHZ); rate = DIV_ROUND_UP(clk_get_rate(sp->clk), MHZ);
if (!rate) { if (!rate) {
ret = -EINVAL; ret = -EINVAL;
goto err_clk_disable; goto err_put_host;
} }
sp->rrw_delay = ATH79_SPI_RRW_DELAY_FACTOR / rate; sp->rrw_delay = ATH79_SPI_RRW_DELAY_FACTOR / rate;
...@@ -229,8 +225,6 @@ static int ath79_spi_probe(struct platform_device *pdev) ...@@ -229,8 +225,6 @@ static int ath79_spi_probe(struct platform_device *pdev)
err_disable: err_disable:
ath79_spi_disable(sp); ath79_spi_disable(sp);
err_clk_disable:
clk_disable_unprepare(sp->clk);
err_put_host: err_put_host:
spi_controller_put(host); spi_controller_put(host);
...@@ -243,7 +237,6 @@ static void ath79_spi_remove(struct platform_device *pdev) ...@@ -243,7 +237,6 @@ static void ath79_spi_remove(struct platform_device *pdev)
spi_bitbang_stop(&sp->bitbang); spi_bitbang_stop(&sp->bitbang);
ath79_spi_disable(sp); ath79_spi_disable(sp);
clk_disable_unprepare(sp->clk);
spi_controller_put(sp->bitbang.master); spi_controller_put(sp->bitbang.master);
} }
......
...@@ -485,30 +485,22 @@ static int spi_engine_probe(struct platform_device *pdev) ...@@ -485,30 +485,22 @@ 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(&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); ret = PTR_ERR(spi_engine->clk);
goto err_put_host; goto err_put_host;
} }
spi_engine->ref_clk = devm_clk_get(&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); ret = PTR_ERR(spi_engine->ref_clk);
goto err_put_host; goto err_put_host;
} }
ret = clk_prepare_enable(spi_engine->clk);
if (ret)
goto err_put_host;
ret = clk_prepare_enable(spi_engine->ref_clk);
if (ret)
goto err_clk_disable;
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); ret = PTR_ERR(spi_engine->base);
goto err_ref_clk_disable; goto err_put_host;
} }
version = readl(spi_engine->base + SPI_ENGINE_REG_VERSION); version = readl(spi_engine->base + SPI_ENGINE_REG_VERSION);
...@@ -518,7 +510,7 @@ static int spi_engine_probe(struct platform_device *pdev) ...@@ -518,7 +510,7 @@ static int spi_engine_probe(struct platform_device *pdev)
SPI_ENGINE_VERSION_MINOR(version), SPI_ENGINE_VERSION_MINOR(version),
SPI_ENGINE_VERSION_PATCH(version)); SPI_ENGINE_VERSION_PATCH(version));
ret = -ENODEV; ret = -ENODEV;
goto err_ref_clk_disable; goto err_put_host;
} }
writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_RESET); writel_relaxed(0x00, spi_engine->base + SPI_ENGINE_REG_RESET);
...@@ -527,7 +519,7 @@ static int spi_engine_probe(struct platform_device *pdev) ...@@ -527,7 +519,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_ref_clk_disable; goto err_put_host;
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;
...@@ -545,10 +537,6 @@ static int spi_engine_probe(struct platform_device *pdev) ...@@ -545,10 +537,6 @@ 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_ref_clk_disable:
clk_disable_unprepare(spi_engine->ref_clk);
err_clk_disable:
clk_disable_unprepare(spi_engine->clk);
err_put_host: err_put_host:
spi_controller_put(host); spi_controller_put(host);
return ret; return ret;
...@@ -569,9 +557,6 @@ static void spi_engine_remove(struct platform_device *pdev) ...@@ -569,9 +557,6 @@ static void spi_engine_remove(struct platform_device *pdev)
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);
clk_disable_unprepare(spi_engine->ref_clk);
clk_disable_unprepare(spi_engine->clk);
} }
static const struct of_device_id spi_engine_match_table[] = { static const struct of_device_id spi_engine_match_table[] = {
......
...@@ -1352,7 +1352,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev) ...@@ -1352,7 +1352,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
if (IS_ERR(bs->regs)) if (IS_ERR(bs->regs))
return PTR_ERR(bs->regs); return PTR_ERR(bs->regs);
bs->clk = devm_clk_get(&pdev->dev, NULL); bs->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(bs->clk)) if (IS_ERR(bs->clk))
return dev_err_probe(&pdev->dev, PTR_ERR(bs->clk), return dev_err_probe(&pdev->dev, PTR_ERR(bs->clk),
"could not get clk\n"); "could not get clk\n");
...@@ -1363,14 +1363,11 @@ static int bcm2835_spi_probe(struct platform_device *pdev) ...@@ -1363,14 +1363,11 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
if (bs->irq < 0) if (bs->irq < 0)
return bs->irq; return bs->irq;
err = clk_prepare_enable(bs->clk);
if (err)
return err;
bs->clk_hz = clk_get_rate(bs->clk); bs->clk_hz = clk_get_rate(bs->clk);
err = bcm2835_dma_init(ctlr, &pdev->dev, bs); err = bcm2835_dma_init(ctlr, &pdev->dev, bs);
if (err) if (err)
goto out_clk_disable; return err;
/* initialise the hardware with the default polarities */ /* initialise the hardware with the default polarities */
bcm2835_wr(bs, BCM2835_SPI_CS, bcm2835_wr(bs, BCM2835_SPI_CS,
...@@ -1396,8 +1393,6 @@ static int bcm2835_spi_probe(struct platform_device *pdev) ...@@ -1396,8 +1393,6 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
out_dma_release: out_dma_release:
bcm2835_dma_release(ctlr, bs); bcm2835_dma_release(ctlr, bs);
out_clk_disable:
clk_disable_unprepare(bs->clk);
return err; return err;
} }
...@@ -1415,8 +1410,6 @@ static void bcm2835_spi_remove(struct platform_device *pdev) ...@@ -1415,8 +1410,6 @@ static void bcm2835_spi_remove(struct platform_device *pdev)
/* Clear FIFOs, and disable the HW block */ /* Clear FIFOs, and disable the HW block */
bcm2835_wr(bs, BCM2835_SPI_CS, bcm2835_wr(bs, BCM2835_SPI_CS,
BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX); BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX);
clk_disable_unprepare(bs->clk);
} }
static const struct of_device_id bcm2835_spi_match[] = { static const struct of_device_id bcm2835_spi_match[] = {
......
...@@ -512,7 +512,7 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev) ...@@ -512,7 +512,7 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
if (IS_ERR(bs->regs)) if (IS_ERR(bs->regs))
return PTR_ERR(bs->regs); return PTR_ERR(bs->regs);
bs->clk = devm_clk_get(&pdev->dev, NULL); bs->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(bs->clk)) { if (IS_ERR(bs->clk)) {
err = PTR_ERR(bs->clk); err = PTR_ERR(bs->clk);
dev_err(&pdev->dev, "could not get clk: %d\n", err); dev_err(&pdev->dev, "could not get clk: %d\n", err);
...@@ -523,19 +523,11 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev) ...@@ -523,19 +523,11 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
if (bs->irq < 0) if (bs->irq < 0)
return bs->irq; return bs->irq;
/* this also enables the HW block */
err = clk_prepare_enable(bs->clk);
if (err) {
dev_err(&pdev->dev, "could not prepare clock: %d\n", err);
return err;
}
/* just checking if the clock returns a sane value */ /* just checking if the clock returns a sane value */
clk_hz = clk_get_rate(bs->clk); clk_hz = clk_get_rate(bs->clk);
if (!clk_hz) { if (!clk_hz) {
dev_err(&pdev->dev, "clock returns 0 Hz\n"); dev_err(&pdev->dev, "clock returns 0 Hz\n");
err = -ENODEV; return -ENODEV;
goto out_clk_disable;
} }
/* reset SPI-HW block */ /* reset SPI-HW block */
...@@ -547,22 +539,18 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev) ...@@ -547,22 +539,18 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
dev_name(&pdev->dev), host); dev_name(&pdev->dev), host);
if (err) { if (err) {
dev_err(&pdev->dev, "could not request IRQ: %d\n", err); dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
goto out_clk_disable; return err;
} }
err = spi_register_controller(host); err = spi_register_controller(host);
if (err) { if (err) {
dev_err(&pdev->dev, "could not register SPI host: %d\n", err); dev_err(&pdev->dev, "could not register SPI host: %d\n", err);
goto out_clk_disable; return err;
} }
bcm2835aux_debugfs_create(bs, dev_name(&pdev->dev)); bcm2835aux_debugfs_create(bs, dev_name(&pdev->dev));
return 0; return 0;
out_clk_disable:
clk_disable_unprepare(bs->clk);
return err;
} }
static void bcm2835aux_spi_remove(struct platform_device *pdev) static void bcm2835aux_spi_remove(struct platform_device *pdev)
...@@ -575,9 +563,6 @@ static void bcm2835aux_spi_remove(struct platform_device *pdev) ...@@ -575,9 +563,6 @@ static void bcm2835aux_spi_remove(struct platform_device *pdev)
spi_unregister_controller(host); spi_unregister_controller(host);
bcm2835aux_spi_reset_hw(bs); bcm2835aux_spi_reset_hw(bs);
/* disable the HW block by releasing the clock */
clk_disable_unprepare(bs->clk);
} }
static const struct of_device_id bcm2835aux_spi_match[] = { static const struct of_device_id bcm2835aux_spi_match[] = {
......
...@@ -581,31 +581,19 @@ static int cdns_spi_probe(struct platform_device *pdev) ...@@ -581,31 +581,19 @@ static int cdns_spi_probe(struct platform_device *pdev)
goto remove_ctlr; goto remove_ctlr;
} }
xspi->pclk = devm_clk_get(&pdev->dev, "pclk"); xspi->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
if (IS_ERR(xspi->pclk)) { if (IS_ERR(xspi->pclk)) {
dev_err(&pdev->dev, "pclk clock not found.\n"); dev_err(&pdev->dev, "pclk clock not found.\n");
ret = PTR_ERR(xspi->pclk); ret = PTR_ERR(xspi->pclk);
goto remove_ctlr; goto remove_ctlr;
} }
ret = clk_prepare_enable(xspi->pclk);
if (ret) {
dev_err(&pdev->dev, "Unable to enable APB clock.\n");
goto remove_ctlr;
}
if (!spi_controller_is_target(ctlr)) { if (!spi_controller_is_target(ctlr)) {
xspi->ref_clk = devm_clk_get(&pdev->dev, "ref_clk"); xspi->ref_clk = devm_clk_get_enabled(&pdev->dev, "ref_clk");
if (IS_ERR(xspi->ref_clk)) { if (IS_ERR(xspi->ref_clk)) {
dev_err(&pdev->dev, "ref_clk clock not found.\n"); dev_err(&pdev->dev, "ref_clk clock not found.\n");
ret = PTR_ERR(xspi->ref_clk); ret = PTR_ERR(xspi->ref_clk);
goto clk_dis_apb; goto remove_ctlr;
}
ret = clk_prepare_enable(xspi->ref_clk);
if (ret) {
dev_err(&pdev->dev, "Unable to enable device clock.\n");
goto clk_dis_apb;
} }
pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_use_autosuspend(&pdev->dev);
...@@ -679,10 +667,7 @@ static int cdns_spi_probe(struct platform_device *pdev) ...@@ -679,10 +667,7 @@ static int cdns_spi_probe(struct platform_device *pdev)
if (!spi_controller_is_target(ctlr)) { if (!spi_controller_is_target(ctlr)) {
pm_runtime_set_suspended(&pdev->dev); pm_runtime_set_suspended(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
clk_disable_unprepare(xspi->ref_clk);
} }
clk_dis_apb:
clk_disable_unprepare(xspi->pclk);
remove_ctlr: remove_ctlr:
spi_controller_put(ctlr); spi_controller_put(ctlr);
return ret; return ret;
...@@ -703,8 +688,6 @@ static void cdns_spi_remove(struct platform_device *pdev) ...@@ -703,8 +688,6 @@ static void cdns_spi_remove(struct platform_device *pdev)
cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE); cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
clk_disable_unprepare(xspi->ref_clk);
clk_disable_unprepare(xspi->pclk);
pm_runtime_set_suspended(&pdev->dev); pm_runtime_set_suspended(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
......
...@@ -49,16 +49,12 @@ static int thunderx_spi_probe(struct pci_dev *pdev, ...@@ -49,16 +49,12 @@ static int thunderx_spi_probe(struct pci_dev *pdev,
p->regs.tx = 0x1010; p->regs.tx = 0x1010;
p->regs.data = 0x1080; p->regs.data = 0x1080;
p->clk = devm_clk_get(dev, NULL); p->clk = devm_clk_get_enabled(dev, NULL);
if (IS_ERR(p->clk)) { if (IS_ERR(p->clk)) {
ret = PTR_ERR(p->clk); ret = PTR_ERR(p->clk);
goto error; goto error;
} }
ret = clk_prepare_enable(p->clk);
if (ret)
goto error;
p->sys_freq = clk_get_rate(p->clk); p->sys_freq = clk_get_rate(p->clk);
if (!p->sys_freq) if (!p->sys_freq)
p->sys_freq = SYS_FREQ_DEFAULT; p->sys_freq = SYS_FREQ_DEFAULT;
...@@ -82,7 +78,6 @@ static int thunderx_spi_probe(struct pci_dev *pdev, ...@@ -82,7 +78,6 @@ static int thunderx_spi_probe(struct pci_dev *pdev,
return 0; return 0;
error: error:
clk_disable_unprepare(p->clk);
pci_release_regions(pdev); pci_release_regions(pdev);
spi_controller_put(host); spi_controller_put(host);
return ret; return ret;
...@@ -97,7 +92,6 @@ static void thunderx_spi_remove(struct pci_dev *pdev) ...@@ -97,7 +92,6 @@ static void thunderx_spi_remove(struct pci_dev *pdev)
if (!p) if (!p)
return; return;
clk_disable_unprepare(p->clk);
pci_release_regions(pdev); pci_release_regions(pdev);
/* Put everything in a known state. */ /* Put everything in a known state. */
writeq(0, p->register_base + OCTEON_SPI_CFG(p)); writeq(0, p->register_base + OCTEON_SPI_CFG(p));
......
...@@ -915,14 +915,11 @@ static int davinci_spi_probe(struct platform_device *pdev) ...@@ -915,14 +915,11 @@ static int davinci_spi_probe(struct platform_device *pdev)
dspi->bitbang.master = host; dspi->bitbang.master = host;
dspi->clk = devm_clk_get(&pdev->dev, NULL); dspi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(dspi->clk)) { if (IS_ERR(dspi->clk)) {
ret = -ENODEV; ret = -ENODEV;
goto free_host; goto free_host;
} }
ret = clk_prepare_enable(dspi->clk);
if (ret)
goto free_host;
host->use_gpio_descriptors = true; host->use_gpio_descriptors = true;
host->dev.of_node = pdev->dev.of_node; host->dev.of_node = pdev->dev.of_node;
...@@ -947,7 +944,7 @@ static int davinci_spi_probe(struct platform_device *pdev) ...@@ -947,7 +944,7 @@ static int davinci_spi_probe(struct platform_device *pdev)
ret = davinci_spi_request_dma(dspi); ret = davinci_spi_request_dma(dspi);
if (ret == -EPROBE_DEFER) { if (ret == -EPROBE_DEFER) {
goto free_clk; goto free_host;
} else if (ret) { } else if (ret) {
dev_info(&pdev->dev, "DMA is not supported (%d)\n", ret); dev_info(&pdev->dev, "DMA is not supported (%d)\n", ret);
dspi->dma_rx = NULL; dspi->dma_rx = NULL;
...@@ -991,8 +988,6 @@ static int davinci_spi_probe(struct platform_device *pdev) ...@@ -991,8 +988,6 @@ static int davinci_spi_probe(struct platform_device *pdev)
dma_release_channel(dspi->dma_rx); dma_release_channel(dspi->dma_rx);
dma_release_channel(dspi->dma_tx); dma_release_channel(dspi->dma_tx);
} }
free_clk:
clk_disable_unprepare(dspi->clk);
free_host: free_host:
spi_controller_put(host); spi_controller_put(host);
err: err:
...@@ -1018,8 +1013,6 @@ static void davinci_spi_remove(struct platform_device *pdev) ...@@ -1018,8 +1013,6 @@ static void davinci_spi_remove(struct platform_device *pdev)
spi_bitbang_stop(&dspi->bitbang); spi_bitbang_stop(&dspi->bitbang);
clk_disable_unprepare(dspi->clk);
if (dspi->dma_rx) { if (dspi->dma_rx) {
dma_release_channel(dspi->dma_rx); dma_release_channel(dspi->dma_rx);
dma_release_channel(dspi->dma_tx); dma_release_channel(dspi->dma_tx);
......
...@@ -269,43 +269,32 @@ static int dw_spi_bt1_probe(struct platform_device *pdev) ...@@ -269,43 +269,32 @@ static int dw_spi_bt1_probe(struct platform_device *pdev)
dws->paddr = mem->start; dws->paddr = mem->start;
dwsbt1->clk = devm_clk_get(&pdev->dev, NULL); dwsbt1->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(dwsbt1->clk)) if (IS_ERR(dwsbt1->clk))
return PTR_ERR(dwsbt1->clk); return PTR_ERR(dwsbt1->clk);
ret = clk_prepare_enable(dwsbt1->clk);
if (ret)
return ret;
dws->bus_num = pdev->id; dws->bus_num = pdev->id;
dws->reg_io_width = 4; dws->reg_io_width = 4;
dws->max_freq = clk_get_rate(dwsbt1->clk); dws->max_freq = clk_get_rate(dwsbt1->clk);
if (!dws->max_freq) { if (!dws->max_freq)
ret = -EINVAL; return -EINVAL;
goto err_disable_clk;
}
init_func = device_get_match_data(&pdev->dev); init_func = device_get_match_data(&pdev->dev);
ret = init_func(pdev, dwsbt1); ret = init_func(pdev, dwsbt1);
if (ret) if (ret)
goto err_disable_clk; return ret;
pm_runtime_enable(&pdev->dev); pm_runtime_enable(&pdev->dev);
ret = dw_spi_add_host(&pdev->dev, dws); ret = dw_spi_add_host(&pdev->dev, dws);
if (ret) { if (ret) {
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
goto err_disable_clk; return ret;
} }
platform_set_drvdata(pdev, dwsbt1); platform_set_drvdata(pdev, dwsbt1);
return 0; return 0;
err_disable_clk:
clk_disable_unprepare(dwsbt1->clk);
return ret;
} }
static void dw_spi_bt1_remove(struct platform_device *pdev) static void dw_spi_bt1_remove(struct platform_device *pdev)
...@@ -315,8 +304,6 @@ static void dw_spi_bt1_remove(struct platform_device *pdev) ...@@ -315,8 +304,6 @@ static void dw_spi_bt1_remove(struct platform_device *pdev)
dw_spi_remove_host(&dwsbt1->dws); dw_spi_remove_host(&dwsbt1->dws);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
clk_disable_unprepare(dwsbt1->clk);
} }
static const struct of_device_id dw_spi_bt1_of_match[] = { static const struct of_device_id dw_spi_bt1_of_match[] = {
......
...@@ -340,29 +340,20 @@ static int dw_spi_mmio_probe(struct platform_device *pdev) ...@@ -340,29 +340,20 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
if (dws->irq < 0) if (dws->irq < 0)
return dws->irq; /* -ENXIO */ return dws->irq; /* -ENXIO */
dwsmmio->clk = devm_clk_get(&pdev->dev, NULL); dwsmmio->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(dwsmmio->clk)) if (IS_ERR(dwsmmio->clk))
return PTR_ERR(dwsmmio->clk); return PTR_ERR(dwsmmio->clk);
ret = clk_prepare_enable(dwsmmio->clk);
if (ret)
return ret;
/* Optional clock needed to access the registers */ /* Optional clock needed to access the registers */
dwsmmio->pclk = devm_clk_get_optional(&pdev->dev, "pclk"); dwsmmio->pclk = devm_clk_get_optional_enabled(&pdev->dev, "pclk");
if (IS_ERR(dwsmmio->pclk)) { if (IS_ERR(dwsmmio->pclk))
ret = PTR_ERR(dwsmmio->pclk); return PTR_ERR(dwsmmio->pclk);
goto out_clk;
}
ret = clk_prepare_enable(dwsmmio->pclk);
if (ret)
goto out_clk;
/* find an optional reset controller */ /* find an optional reset controller */
dwsmmio->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, "spi"); dwsmmio->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, "spi");
if (IS_ERR(dwsmmio->rstc)) { if (IS_ERR(dwsmmio->rstc))
ret = PTR_ERR(dwsmmio->rstc); return PTR_ERR(dwsmmio->rstc);
goto out_clk;
}
reset_control_deassert(dwsmmio->rstc); reset_control_deassert(dwsmmio->rstc);
dws->bus_num = pdev->id; dws->bus_num = pdev->id;
...@@ -383,7 +374,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev) ...@@ -383,7 +374,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
if (init_func) { if (init_func) {
ret = init_func(pdev, dwsmmio); ret = init_func(pdev, dwsmmio);
if (ret) if (ret)
goto out; goto out_reset;
} }
pm_runtime_enable(&pdev->dev); pm_runtime_enable(&pdev->dev);
...@@ -397,9 +388,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev) ...@@ -397,9 +388,7 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
out: out:
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
clk_disable_unprepare(dwsmmio->pclk); out_reset:
out_clk:
clk_disable_unprepare(dwsmmio->clk);
reset_control_assert(dwsmmio->rstc); reset_control_assert(dwsmmio->rstc);
return ret; return ret;
...@@ -411,8 +400,6 @@ static void dw_spi_mmio_remove(struct platform_device *pdev) ...@@ -411,8 +400,6 @@ static void dw_spi_mmio_remove(struct platform_device *pdev)
dw_spi_remove_host(&dwsmmio->dws); dw_spi_remove_host(&dwsmmio->dws);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
clk_disable_unprepare(dwsmmio->pclk);
clk_disable_unprepare(dwsmmio->clk);
reset_control_assert(dwsmmio->rstc); reset_control_assert(dwsmmio->rstc);
} }
......
...@@ -1372,19 +1372,16 @@ static int dspi_probe(struct platform_device *pdev) ...@@ -1372,19 +1372,16 @@ static int dspi_probe(struct platform_device *pdev)
} }
} }
dspi->clk = devm_clk_get(&pdev->dev, "dspi"); dspi->clk = devm_clk_get_enabled(&pdev->dev, "dspi");
if (IS_ERR(dspi->clk)) { if (IS_ERR(dspi->clk)) {
ret = PTR_ERR(dspi->clk); ret = PTR_ERR(dspi->clk);
dev_err(&pdev->dev, "unable to get clock\n"); dev_err(&pdev->dev, "unable to get clock\n");
goto out_ctlr_put; goto out_ctlr_put;
} }
ret = clk_prepare_enable(dspi->clk);
if (ret)
goto out_ctlr_put;
ret = dspi_init(dspi); ret = dspi_init(dspi);
if (ret) if (ret)
goto out_clk_put; goto out_ctlr_put;
dspi->irq = platform_get_irq(pdev, 0); dspi->irq = platform_get_irq(pdev, 0);
if (dspi->irq <= 0) { if (dspi->irq <= 0) {
...@@ -1400,7 +1397,7 @@ static int dspi_probe(struct platform_device *pdev) ...@@ -1400,7 +1397,7 @@ static int dspi_probe(struct platform_device *pdev)
IRQF_SHARED, pdev->name, dspi); IRQF_SHARED, pdev->name, dspi);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "Unable to attach DSPI interrupt\n"); dev_err(&pdev->dev, "Unable to attach DSPI interrupt\n");
goto out_clk_put; goto out_ctlr_put;
} }
poll_mode: poll_mode:
...@@ -1432,8 +1429,6 @@ static int dspi_probe(struct platform_device *pdev) ...@@ -1432,8 +1429,6 @@ static int dspi_probe(struct platform_device *pdev)
out_free_irq: out_free_irq:
if (dspi->irq) if (dspi->irq)
free_irq(dspi->irq, dspi); free_irq(dspi->irq, dspi);
out_clk_put:
clk_disable_unprepare(dspi->clk);
out_ctlr_put: out_ctlr_put:
spi_controller_put(ctlr); spi_controller_put(ctlr);
...@@ -1458,7 +1453,6 @@ static void dspi_remove(struct platform_device *pdev) ...@@ -1458,7 +1453,6 @@ static void dspi_remove(struct platform_device *pdev)
dspi_release_dma(dspi); dspi_release_dma(dspi);
if (dspi->irq) if (dspi->irq)
free_irq(dspi->irq, dspi); free_irq(dspi->irq, dspi);
clk_disable_unprepare(dspi->clk);
} }
static void dspi_shutdown(struct platform_device *pdev) static void dspi_shutdown(struct platform_device *pdev)
......
...@@ -932,14 +932,11 @@ static int lantiq_ssc_probe(struct platform_device *pdev) ...@@ -932,14 +932,11 @@ static int lantiq_ssc_probe(struct platform_device *pdev)
if (err) if (err)
goto err_host_put; goto err_host_put;
spi->spi_clk = devm_clk_get(dev, "gate"); spi->spi_clk = devm_clk_get_enabled(dev, "gate");
if (IS_ERR(spi->spi_clk)) { if (IS_ERR(spi->spi_clk)) {
err = PTR_ERR(spi->spi_clk); err = PTR_ERR(spi->spi_clk);
goto err_host_put; goto err_host_put;
} }
err = clk_prepare_enable(spi->spi_clk);
if (err)
goto err_host_put;
/* /*
* Use the old clk_get_fpi() function on Lantiq platform, till it * Use the old clk_get_fpi() function on Lantiq platform, till it
...@@ -952,7 +949,7 @@ static int lantiq_ssc_probe(struct platform_device *pdev) ...@@ -952,7 +949,7 @@ static int lantiq_ssc_probe(struct platform_device *pdev)
#endif #endif
if (IS_ERR(spi->fpi_clk)) { if (IS_ERR(spi->fpi_clk)) {
err = PTR_ERR(spi->fpi_clk); err = PTR_ERR(spi->fpi_clk);
goto err_clk_disable; goto err_host_put;
} }
num_cs = 8; num_cs = 8;
...@@ -1010,8 +1007,6 @@ static int lantiq_ssc_probe(struct platform_device *pdev) ...@@ -1010,8 +1007,6 @@ static int lantiq_ssc_probe(struct platform_device *pdev)
destroy_workqueue(spi->wq); destroy_workqueue(spi->wq);
err_clk_put: err_clk_put:
clk_put(spi->fpi_clk); clk_put(spi->fpi_clk);
err_clk_disable:
clk_disable_unprepare(spi->spi_clk);
err_host_put: err_host_put:
spi_controller_put(host); spi_controller_put(host);
...@@ -1029,7 +1024,6 @@ static void lantiq_ssc_remove(struct platform_device *pdev) ...@@ -1029,7 +1024,6 @@ static void lantiq_ssc_remove(struct platform_device *pdev)
hw_enter_config_mode(spi); hw_enter_config_mode(spi);
destroy_workqueue(spi->wq); destroy_workqueue(spi->wq);
clk_disable_unprepare(spi->spi_clk);
clk_put(spi->fpi_clk); clk_put(spi->fpi_clk);
} }
......
...@@ -820,7 +820,7 @@ static int meson_spicc_probe(struct platform_device *pdev) ...@@ -820,7 +820,7 @@ static int meson_spicc_probe(struct platform_device *pdev)
goto out_host; goto out_host;
} }
spicc->core = devm_clk_get(&pdev->dev, "core"); spicc->core = devm_clk_get_enabled(&pdev->dev, "core");
if (IS_ERR(spicc->core)) { if (IS_ERR(spicc->core)) {
dev_err(&pdev->dev, "core clock request failed\n"); dev_err(&pdev->dev, "core clock request failed\n");
ret = PTR_ERR(spicc->core); ret = PTR_ERR(spicc->core);
...@@ -828,7 +828,7 @@ static int meson_spicc_probe(struct platform_device *pdev) ...@@ -828,7 +828,7 @@ static int meson_spicc_probe(struct platform_device *pdev)
} }
if (spicc->data->has_pclk) { if (spicc->data->has_pclk) {
spicc->pclk = devm_clk_get(&pdev->dev, "pclk"); spicc->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
if (IS_ERR(spicc->pclk)) { if (IS_ERR(spicc->pclk)) {
dev_err(&pdev->dev, "pclk clock request failed\n"); dev_err(&pdev->dev, "pclk clock request failed\n");
ret = PTR_ERR(spicc->pclk); ret = PTR_ERR(spicc->pclk);
...@@ -836,22 +836,10 @@ static int meson_spicc_probe(struct platform_device *pdev) ...@@ -836,22 +836,10 @@ static int meson_spicc_probe(struct platform_device *pdev)
} }
} }
ret = clk_prepare_enable(spicc->core);
if (ret) {
dev_err(&pdev->dev, "core clock enable failed\n");
goto out_host;
}
ret = clk_prepare_enable(spicc->pclk);
if (ret) {
dev_err(&pdev->dev, "pclk clock enable failed\n");
goto out_core_clk;
}
spicc->pinctrl = devm_pinctrl_get(&pdev->dev); spicc->pinctrl = devm_pinctrl_get(&pdev->dev);
if (IS_ERR(spicc->pinctrl)) { if (IS_ERR(spicc->pinctrl)) {
ret = PTR_ERR(spicc->pinctrl); ret = PTR_ERR(spicc->pinctrl);
goto out_clk; goto out_host;
} }
device_reset_optional(&pdev->dev); device_reset_optional(&pdev->dev);
...@@ -878,31 +866,25 @@ static int meson_spicc_probe(struct platform_device *pdev) ...@@ -878,31 +866,25 @@ static int meson_spicc_probe(struct platform_device *pdev)
ret = meson_spicc_pow2_clk_init(spicc); ret = meson_spicc_pow2_clk_init(spicc);
if (ret) { if (ret) {
dev_err(&pdev->dev, "pow2 clock registration failed\n"); dev_err(&pdev->dev, "pow2 clock registration failed\n");
goto out_clk; goto out_host;
} }
if (spicc->data->has_enhance_clk_div) { if (spicc->data->has_enhance_clk_div) {
ret = meson_spicc_enh_clk_init(spicc); ret = meson_spicc_enh_clk_init(spicc);
if (ret) { if (ret) {
dev_err(&pdev->dev, "clock registration failed\n"); dev_err(&pdev->dev, "clock registration failed\n");
goto out_clk; goto out_host;
} }
} }
ret = devm_spi_register_controller(&pdev->dev, host); ret = devm_spi_register_controller(&pdev->dev, host);
if (ret) { if (ret) {
dev_err(&pdev->dev, "spi host registration failed\n"); dev_err(&pdev->dev, "spi registration failed\n");
goto out_clk; goto out_host;
} }
return 0; return 0;
out_clk:
clk_disable_unprepare(spicc->pclk);
out_core_clk:
clk_disable_unprepare(spicc->core);
out_host: out_host:
spi_controller_put(host); spi_controller_put(host);
...@@ -916,9 +898,6 @@ static void meson_spicc_remove(struct platform_device *pdev) ...@@ -916,9 +898,6 @@ static void meson_spicc_remove(struct platform_device *pdev)
/* Disable SPI */ /* Disable SPI */
writel(0, spicc->base + SPICC_CONREG); writel(0, spicc->base + SPICC_CONREG);
clk_disable_unprepare(spicc->core);
clk_disable_unprepare(spicc->pclk);
spi_controller_put(spicc->host); spi_controller_put(spicc->host);
} }
......
...@@ -312,19 +312,13 @@ static int meson_spifc_probe(struct platform_device *pdev) ...@@ -312,19 +312,13 @@ static int meson_spifc_probe(struct platform_device *pdev)
goto out_err; goto out_err;
} }
spifc->clk = devm_clk_get(spifc->dev, NULL); spifc->clk = devm_clk_get_enabled(spifc->dev, NULL);
if (IS_ERR(spifc->clk)) { if (IS_ERR(spifc->clk)) {
dev_err(spifc->dev, "missing clock\n"); dev_err(spifc->dev, "missing clock\n");
ret = PTR_ERR(spifc->clk); ret = PTR_ERR(spifc->clk);
goto out_err; goto out_err;
} }
ret = clk_prepare_enable(spifc->clk);
if (ret) {
dev_err(spifc->dev, "can't prepare clock\n");
goto out_err;
}
rate = clk_get_rate(spifc->clk); rate = clk_get_rate(spifc->clk);
host->num_chipselect = 1; host->num_chipselect = 1;
...@@ -343,12 +337,11 @@ static int meson_spifc_probe(struct platform_device *pdev) ...@@ -343,12 +337,11 @@ static int meson_spifc_probe(struct platform_device *pdev)
ret = devm_spi_register_controller(spifc->dev, host); ret = devm_spi_register_controller(spifc->dev, host);
if (ret) { if (ret) {
dev_err(spifc->dev, "failed to register spi host\n"); dev_err(spifc->dev, "failed to register spi host\n");
goto out_clk; goto out_pm;
} }
return 0; return 0;
out_clk: out_pm:
clk_disable_unprepare(spifc->clk);
pm_runtime_disable(spifc->dev); pm_runtime_disable(spifc->dev);
out_err: out_err:
spi_controller_put(host); spi_controller_put(host);
...@@ -357,11 +350,7 @@ static int meson_spifc_probe(struct platform_device *pdev) ...@@ -357,11 +350,7 @@ static int meson_spifc_probe(struct platform_device *pdev)
static void meson_spifc_remove(struct platform_device *pdev) static void meson_spifc_remove(struct platform_device *pdev)
{ {
struct spi_controller *host = platform_get_drvdata(pdev);
struct meson_spifc *spifc = spi_controller_get_devdata(host);
pm_runtime_get_sync(&pdev->dev); pm_runtime_get_sync(&pdev->dev);
clk_disable_unprepare(spifc->clk);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
} }
......
...@@ -518,30 +518,23 @@ static int mchp_coreqspi_probe(struct platform_device *pdev) ...@@ -518,30 +518,23 @@ static int mchp_coreqspi_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, PTR_ERR(qspi->regs), return dev_err_probe(&pdev->dev, PTR_ERR(qspi->regs),
"failed to map registers\n"); "failed to map registers\n");
qspi->clk = devm_clk_get(&pdev->dev, NULL); qspi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(qspi->clk)) if (IS_ERR(qspi->clk))
return dev_err_probe(&pdev->dev, PTR_ERR(qspi->clk), return dev_err_probe(&pdev->dev, PTR_ERR(qspi->clk),
"could not get clock\n"); "could not get clock\n");
ret = clk_prepare_enable(qspi->clk);
if (ret)
return dev_err_probe(&pdev->dev, ret,
"failed to enable clock\n");
init_completion(&qspi->data_completion); init_completion(&qspi->data_completion);
mutex_init(&qspi->op_lock); mutex_init(&qspi->op_lock);
qspi->irq = platform_get_irq(pdev, 0); qspi->irq = platform_get_irq(pdev, 0);
if (qspi->irq < 0) { if (qspi->irq < 0)
ret = qspi->irq; return qspi->irq;
goto out;
}
ret = devm_request_irq(&pdev->dev, qspi->irq, mchp_coreqspi_isr, ret = devm_request_irq(&pdev->dev, qspi->irq, mchp_coreqspi_isr,
IRQF_SHARED, pdev->name, qspi); IRQF_SHARED, pdev->name, qspi);
if (ret) { if (ret) {
dev_err(&pdev->dev, "request_irq failed %d\n", ret); dev_err(&pdev->dev, "request_irq failed %d\n", ret);
goto out; return ret;
} }
ctlr->bits_per_word_mask = SPI_BPW_MASK(8); ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
...@@ -552,18 +545,11 @@ static int mchp_coreqspi_probe(struct platform_device *pdev) ...@@ -552,18 +545,11 @@ static int mchp_coreqspi_probe(struct platform_device *pdev)
ctlr->dev.of_node = np; ctlr->dev.of_node = np;
ret = devm_spi_register_controller(&pdev->dev, ctlr); ret = devm_spi_register_controller(&pdev->dev, ctlr);
if (ret) { if (ret)
dev_err_probe(&pdev->dev, ret, return dev_err_probe(&pdev->dev, ret,
"spi_register_controller failed\n"); "spi_register_controller failed\n");
goto out;
}
return 0; return 0;
out:
clk_disable_unprepare(qspi->clk);
return ret;
} }
static void mchp_coreqspi_remove(struct platform_device *pdev) static void mchp_coreqspi_remove(struct platform_device *pdev)
...@@ -574,7 +560,6 @@ static void mchp_coreqspi_remove(struct platform_device *pdev) ...@@ -574,7 +560,6 @@ static void mchp_coreqspi_remove(struct platform_device *pdev)
mchp_coreqspi_disable_ints(qspi); mchp_coreqspi_disable_ints(qspi);
control &= ~CONTROL_ENABLE; control &= ~CONTROL_ENABLE;
writel_relaxed(control, qspi->regs + REG_CONTROL); writel_relaxed(control, qspi->regs + REG_CONTROL);
clk_disable_unprepare(qspi->clk);
} }
static const struct of_device_id mchp_coreqspi_of_match[] = { static const struct of_device_id mchp_coreqspi_of_match[] = {
......
...@@ -539,22 +539,16 @@ static int mchp_corespi_probe(struct platform_device *pdev) ...@@ -539,22 +539,16 @@ static int mchp_corespi_probe(struct platform_device *pdev)
return dev_err_probe(&pdev->dev, ret, return dev_err_probe(&pdev->dev, ret,
"could not request irq\n"); "could not request irq\n");
spi->clk = devm_clk_get(&pdev->dev, NULL); spi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(spi->clk)) if (IS_ERR(spi->clk))
return dev_err_probe(&pdev->dev, PTR_ERR(spi->clk), return dev_err_probe(&pdev->dev, PTR_ERR(spi->clk),
"could not get clk\n"); "could not get clk\n");
ret = clk_prepare_enable(spi->clk);
if (ret)
return dev_err_probe(&pdev->dev, ret,
"failed to enable clock\n");
mchp_corespi_init(host, spi); mchp_corespi_init(host, spi);
ret = devm_spi_register_controller(&pdev->dev, host); ret = devm_spi_register_controller(&pdev->dev, host);
if (ret) { if (ret) {
mchp_corespi_disable(spi); mchp_corespi_disable(spi);
clk_disable_unprepare(spi->clk);
return dev_err_probe(&pdev->dev, ret, return dev_err_probe(&pdev->dev, ret,
"unable to register host for SPI controller\n"); "unable to register host for SPI controller\n");
} }
...@@ -570,7 +564,6 @@ static void mchp_corespi_remove(struct platform_device *pdev) ...@@ -570,7 +564,6 @@ static void mchp_corespi_remove(struct platform_device *pdev)
struct mchp_corespi *spi = spi_controller_get_devdata(host); struct mchp_corespi *spi = spi_controller_get_devdata(host);
mchp_corespi_disable_ints(spi); mchp_corespi_disable_ints(spi);
clk_disable_unprepare(spi->clk);
mchp_corespi_disable(spi); mchp_corespi_disable(spi);
} }
......
...@@ -1332,42 +1332,6 @@ static const struct of_device_id mtk_snand_ids[] = { ...@@ -1332,42 +1332,6 @@ static const struct of_device_id mtk_snand_ids[] = {
MODULE_DEVICE_TABLE(of, mtk_snand_ids); MODULE_DEVICE_TABLE(of, mtk_snand_ids);
static int mtk_snand_enable_clk(struct mtk_snand *ms)
{
int ret;
ret = clk_prepare_enable(ms->nfi_clk);
if (ret) {
dev_err(ms->dev, "unable to enable nfi clk\n");
return ret;
}
ret = clk_prepare_enable(ms->pad_clk);
if (ret) {
dev_err(ms->dev, "unable to enable pad clk\n");
goto err1;
}
ret = clk_prepare_enable(ms->nfi_hclk);
if (ret) {
dev_err(ms->dev, "unable to enable nfi hclk\n");
goto err2;
}
return 0;
err2:
clk_disable_unprepare(ms->pad_clk);
err1:
clk_disable_unprepare(ms->nfi_clk);
return ret;
}
static void mtk_snand_disable_clk(struct mtk_snand *ms)
{
clk_disable_unprepare(ms->nfi_hclk);
clk_disable_unprepare(ms->pad_clk);
clk_disable_unprepare(ms->nfi_clk);
}
static int mtk_snand_probe(struct platform_device *pdev) static int mtk_snand_probe(struct platform_device *pdev)
{ {
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
...@@ -1406,49 +1370,45 @@ static int mtk_snand_probe(struct platform_device *pdev) ...@@ -1406,49 +1370,45 @@ static int mtk_snand_probe(struct platform_device *pdev)
ms->dev = &pdev->dev; ms->dev = &pdev->dev;
ms->nfi_clk = devm_clk_get(&pdev->dev, "nfi_clk"); ms->nfi_clk = devm_clk_get_enabled(&pdev->dev, "nfi_clk");
if (IS_ERR(ms->nfi_clk)) { if (IS_ERR(ms->nfi_clk)) {
ret = PTR_ERR(ms->nfi_clk); ret = PTR_ERR(ms->nfi_clk);
dev_err(&pdev->dev, "unable to get nfi_clk, err = %d\n", ret); dev_err(&pdev->dev, "unable to get nfi_clk, err = %d\n", ret);
goto release_ecc; goto release_ecc;
} }
ms->pad_clk = devm_clk_get(&pdev->dev, "pad_clk"); ms->pad_clk = devm_clk_get_enabled(&pdev->dev, "pad_clk");
if (IS_ERR(ms->pad_clk)) { if (IS_ERR(ms->pad_clk)) {
ret = PTR_ERR(ms->pad_clk); ret = PTR_ERR(ms->pad_clk);
dev_err(&pdev->dev, "unable to get pad_clk, err = %d\n", ret); dev_err(&pdev->dev, "unable to get pad_clk, err = %d\n", ret);
goto release_ecc; goto release_ecc;
} }
ms->nfi_hclk = devm_clk_get_optional(&pdev->dev, "nfi_hclk"); ms->nfi_hclk = devm_clk_get_optional_enabled(&pdev->dev, "nfi_hclk");
if (IS_ERR(ms->nfi_hclk)) { if (IS_ERR(ms->nfi_hclk)) {
ret = PTR_ERR(ms->nfi_hclk); ret = PTR_ERR(ms->nfi_hclk);
dev_err(&pdev->dev, "unable to get nfi_hclk, err = %d\n", ret); dev_err(&pdev->dev, "unable to get nfi_hclk, err = %d\n", ret);
goto release_ecc; goto release_ecc;
} }
ret = mtk_snand_enable_clk(ms);
if (ret)
goto release_ecc;
init_completion(&ms->op_done); init_completion(&ms->op_done);
ms->irq = platform_get_irq(pdev, 0); ms->irq = platform_get_irq(pdev, 0);
if (ms->irq < 0) { if (ms->irq < 0) {
ret = ms->irq; ret = ms->irq;
goto disable_clk; goto release_ecc;
} }
ret = devm_request_irq(ms->dev, ms->irq, mtk_snand_irq, 0x0, ret = devm_request_irq(ms->dev, ms->irq, mtk_snand_irq, 0x0,
"mtk-snand", ms); "mtk-snand", ms);
if (ret) { if (ret) {
dev_err(ms->dev, "failed to request snfi irq\n"); dev_err(ms->dev, "failed to request snfi irq\n");
goto disable_clk; goto release_ecc;
} }
ret = dma_set_mask(ms->dev, DMA_BIT_MASK(32)); ret = dma_set_mask(ms->dev, DMA_BIT_MASK(32));
if (ret) { if (ret) {
dev_err(ms->dev, "failed to set dma mask\n"); dev_err(ms->dev, "failed to set dma mask\n");
goto disable_clk; goto release_ecc;
} }
// switch to SNFI mode // switch to SNFI mode
...@@ -1472,7 +1432,7 @@ static int mtk_snand_probe(struct platform_device *pdev) ...@@ -1472,7 +1432,7 @@ static int mtk_snand_probe(struct platform_device *pdev)
ret = mtk_snand_setup_pagefmt(ms, SZ_2K, SZ_64); ret = mtk_snand_setup_pagefmt(ms, SZ_2K, SZ_64);
if (ret) { if (ret) {
dev_err(ms->dev, "failed to set initial page format\n"); dev_err(ms->dev, "failed to set initial page format\n");
goto disable_clk; goto release_ecc;
} }
// setup ECC engine // setup ECC engine
...@@ -1484,7 +1444,7 @@ static int mtk_snand_probe(struct platform_device *pdev) ...@@ -1484,7 +1444,7 @@ static int mtk_snand_probe(struct platform_device *pdev)
ret = nand_ecc_register_on_host_hw_engine(&ms->ecc_eng); ret = nand_ecc_register_on_host_hw_engine(&ms->ecc_eng);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to register ecc engine.\n"); dev_err(&pdev->dev, "failed to register ecc engine.\n");
goto disable_clk; goto release_ecc;
} }
ctlr->num_chipselect = 1; ctlr->num_chipselect = 1;
...@@ -1496,12 +1456,10 @@ static int mtk_snand_probe(struct platform_device *pdev) ...@@ -1496,12 +1456,10 @@ static int mtk_snand_probe(struct platform_device *pdev)
ret = spi_register_controller(ctlr); ret = spi_register_controller(ctlr);
if (ret) { if (ret) {
dev_err(&pdev->dev, "spi_register_controller failed.\n"); dev_err(&pdev->dev, "spi_register_controller failed.\n");
goto disable_clk; goto release_ecc;
} }
return 0; return 0;
disable_clk:
mtk_snand_disable_clk(ms);
release_ecc: release_ecc:
mtk_ecc_release(ms->ecc); mtk_ecc_release(ms->ecc);
return ret; return ret;
...@@ -1513,7 +1471,6 @@ static void mtk_snand_remove(struct platform_device *pdev) ...@@ -1513,7 +1471,6 @@ static void mtk_snand_remove(struct platform_device *pdev)
struct mtk_snand *ms = spi_controller_get_devdata(ctlr); struct mtk_snand *ms = spi_controller_get_devdata(ctlr);
spi_unregister_controller(ctlr); spi_unregister_controller(ctlr);
mtk_snand_disable_clk(ms);
mtk_ecc_release(ms->ecc); mtk_ecc_release(ms->ecc);
kfree(ms->buf); kfree(ms->buf);
} }
......
...@@ -699,7 +699,7 @@ static int npcm_fiu_probe(struct platform_device *pdev) ...@@ -699,7 +699,7 @@ static int npcm_fiu_probe(struct platform_device *pdev)
struct spi_controller *ctrl; struct spi_controller *ctrl;
struct npcm_fiu_spi *fiu; struct npcm_fiu_spi *fiu;
void __iomem *regbase; void __iomem *regbase;
int id, ret; int id;
ctrl = devm_spi_alloc_host(dev, sizeof(*fiu)); ctrl = devm_spi_alloc_host(dev, sizeof(*fiu));
if (!ctrl) if (!ctrl)
...@@ -737,7 +737,7 @@ static int npcm_fiu_probe(struct platform_device *pdev) ...@@ -737,7 +737,7 @@ static int npcm_fiu_probe(struct platform_device *pdev)
fiu->res_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, fiu->res_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM,
"memory"); "memory");
fiu->clk = devm_clk_get(dev, NULL); fiu->clk = devm_clk_get_enabled(dev, NULL);
if (IS_ERR(fiu->clk)) if (IS_ERR(fiu->clk))
return PTR_ERR(fiu->clk); return PTR_ERR(fiu->clk);
...@@ -745,7 +745,6 @@ static int npcm_fiu_probe(struct platform_device *pdev) ...@@ -745,7 +745,6 @@ static int npcm_fiu_probe(struct platform_device *pdev)
"nuvoton,spix-mode"); "nuvoton,spix-mode");
platform_set_drvdata(pdev, fiu); platform_set_drvdata(pdev, fiu);
clk_prepare_enable(fiu->clk);
ctrl->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD ctrl->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD
| SPI_TX_DUAL | SPI_TX_QUAD; | SPI_TX_DUAL | SPI_TX_QUAD;
...@@ -755,18 +754,11 @@ static int npcm_fiu_probe(struct platform_device *pdev) ...@@ -755,18 +754,11 @@ static int npcm_fiu_probe(struct platform_device *pdev)
ctrl->num_chipselect = fiu->info->max_cs; ctrl->num_chipselect = fiu->info->max_cs;
ctrl->dev.of_node = dev->of_node; ctrl->dev.of_node = dev->of_node;
ret = devm_spi_register_controller(dev, ctrl); return devm_spi_register_controller(dev, ctrl);
if (ret)
clk_disable_unprepare(fiu->clk);
return ret;
} }
static void npcm_fiu_remove(struct platform_device *pdev) static void npcm_fiu_remove(struct platform_device *pdev)
{ {
struct npcm_fiu_spi *fiu = platform_get_drvdata(pdev);
clk_disable_unprepare(fiu->clk);
} }
MODULE_DEVICE_TABLE(of, npcm_fiu_dt_ids); MODULE_DEVICE_TABLE(of, npcm_fiu_dt_ids);
......
...@@ -688,21 +688,17 @@ static int orion_spi_probe(struct platform_device *pdev) ...@@ -688,21 +688,17 @@ static int orion_spi_probe(struct platform_device *pdev)
devdata = devdata ? devdata : &orion_spi_dev_data; devdata = devdata ? devdata : &orion_spi_dev_data;
spi->devdata = devdata; spi->devdata = devdata;
spi->clk = devm_clk_get(&pdev->dev, NULL); spi->clk = devm_clk_get_enabled(&pdev->dev, NULL);
if (IS_ERR(spi->clk)) { if (IS_ERR(spi->clk)) {
status = PTR_ERR(spi->clk); status = PTR_ERR(spi->clk);
goto out; goto out;
} }
status = clk_prepare_enable(spi->clk);
if (status)
goto out;
/* The following clock is only used by some SoCs */ /* The following clock is only used by some SoCs */
spi->axi_clk = devm_clk_get(&pdev->dev, "axi"); spi->axi_clk = devm_clk_get(&pdev->dev, "axi");
if (PTR_ERR(spi->axi_clk) == -EPROBE_DEFER) { if (PTR_ERR(spi->axi_clk) == -EPROBE_DEFER) {
status = -EPROBE_DEFER; status = -EPROBE_DEFER;
goto out_rel_clk; goto out;
} }
if (!IS_ERR(spi->axi_clk)) if (!IS_ERR(spi->axi_clk))
clk_prepare_enable(spi->axi_clk); clk_prepare_enable(spi->axi_clk);
...@@ -795,8 +791,6 @@ static int orion_spi_probe(struct platform_device *pdev) ...@@ -795,8 +791,6 @@ static int orion_spi_probe(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
out_rel_axi_clk: out_rel_axi_clk:
clk_disable_unprepare(spi->axi_clk); clk_disable_unprepare(spi->axi_clk);
out_rel_clk:
clk_disable_unprepare(spi->clk);
out: out:
spi_controller_put(host); spi_controller_put(host);
return status; return status;
...@@ -810,7 +804,6 @@ static void orion_spi_remove(struct platform_device *pdev) ...@@ -810,7 +804,6 @@ static void orion_spi_remove(struct platform_device *pdev)
pm_runtime_get_sync(&pdev->dev); pm_runtime_get_sync(&pdev->dev);
clk_disable_unprepare(spi->axi_clk); clk_disable_unprepare(spi->axi_clk);
clk_disable_unprepare(spi->clk);
spi_unregister_controller(host); spi_unregister_controller(host);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
......
...@@ -593,33 +593,20 @@ static int pic32_sqi_probe(struct platform_device *pdev) ...@@ -593,33 +593,20 @@ static int pic32_sqi_probe(struct platform_device *pdev)
} }
/* clocks */ /* clocks */
sqi->sys_clk = devm_clk_get(&pdev->dev, "reg_ck"); sqi->sys_clk = devm_clk_get_enabled(&pdev->dev, "reg_ck");
if (IS_ERR(sqi->sys_clk)) { if (IS_ERR(sqi->sys_clk)) {
ret = PTR_ERR(sqi->sys_clk); ret = PTR_ERR(sqi->sys_clk);
dev_err(&pdev->dev, "no sys_clk ?\n"); dev_err(&pdev->dev, "no sys_clk ?\n");
goto err_free_host; goto err_free_host;
} }
sqi->base_clk = devm_clk_get(&pdev->dev, "spi_ck"); sqi->base_clk = devm_clk_get_enabled(&pdev->dev, "spi_ck");
if (IS_ERR(sqi->base_clk)) { if (IS_ERR(sqi->base_clk)) {
ret = PTR_ERR(sqi->base_clk); ret = PTR_ERR(sqi->base_clk);
dev_err(&pdev->dev, "no base clk ?\n"); dev_err(&pdev->dev, "no base clk ?\n");
goto err_free_host; goto err_free_host;
} }
ret = clk_prepare_enable(sqi->sys_clk);
if (ret) {
dev_err(&pdev->dev, "sys clk enable failed\n");
goto err_free_host;
}
ret = clk_prepare_enable(sqi->base_clk);
if (ret) {
dev_err(&pdev->dev, "base clk enable failed\n");
clk_disable_unprepare(sqi->sys_clk);
goto err_free_host;
}
init_completion(&sqi->xfer_done); init_completion(&sqi->xfer_done);
/* initialize hardware */ /* initialize hardware */
...@@ -629,7 +616,7 @@ static int pic32_sqi_probe(struct platform_device *pdev) ...@@ -629,7 +616,7 @@ static int pic32_sqi_probe(struct platform_device *pdev)
ret = ring_desc_ring_alloc(sqi); ret = ring_desc_ring_alloc(sqi);
if (ret) { if (ret) {
dev_err(&pdev->dev, "ring alloc failed\n"); dev_err(&pdev->dev, "ring alloc failed\n");
goto err_disable_clk; goto err_free_host;
} }
/* install irq handlers */ /* install irq handlers */
...@@ -669,10 +656,6 @@ static int pic32_sqi_probe(struct platform_device *pdev) ...@@ -669,10 +656,6 @@ static int pic32_sqi_probe(struct platform_device *pdev)
err_free_ring: err_free_ring:
ring_desc_ring_free(sqi); ring_desc_ring_free(sqi);
err_disable_clk:
clk_disable_unprepare(sqi->base_clk);
clk_disable_unprepare(sqi->sys_clk);
err_free_host: err_free_host:
spi_controller_put(host); spi_controller_put(host);
return ret; return ret;
...@@ -685,10 +668,6 @@ static void pic32_sqi_remove(struct platform_device *pdev) ...@@ -685,10 +668,6 @@ static void pic32_sqi_remove(struct platform_device *pdev)
/* release resources */ /* release resources */
free_irq(sqi->irq, sqi); free_irq(sqi->irq, sqi);
ring_desc_ring_free(sqi); ring_desc_ring_free(sqi);
/* disable clk */
clk_disable_unprepare(sqi->base_clk);
clk_disable_unprepare(sqi->sys_clk);
} }
static const struct of_device_id pic32_sqi_of_ids[] = { static const struct of_device_id pic32_sqi_of_ids[] = {
......
...@@ -730,17 +730,13 @@ static int pic32_spi_hw_probe(struct platform_device *pdev, ...@@ -730,17 +730,13 @@ static int pic32_spi_hw_probe(struct platform_device *pdev,
return pic32s->tx_irq; return pic32s->tx_irq;
/* get clock */ /* get clock */
pic32s->clk = devm_clk_get(&pdev->dev, "mck0"); pic32s->clk = devm_clk_get_enabled(&pdev->dev, "mck0");
if (IS_ERR(pic32s->clk)) { if (IS_ERR(pic32s->clk)) {
dev_err(&pdev->dev, "clk not found\n"); dev_err(&pdev->dev, "clk not found\n");
ret = PTR_ERR(pic32s->clk); ret = PTR_ERR(pic32s->clk);
goto err_unmap_mem; goto err_unmap_mem;
} }
ret = clk_prepare_enable(pic32s->clk);
if (ret)
goto err_unmap_mem;
pic32_spi_hw_init(pic32s); pic32_spi_hw_init(pic32s);
return 0; return 0;
...@@ -837,7 +833,6 @@ static int pic32_spi_probe(struct platform_device *pdev) ...@@ -837,7 +833,6 @@ static int pic32_spi_probe(struct platform_device *pdev)
err_bailout: err_bailout:
pic32_spi_dma_unprep(pic32s); pic32_spi_dma_unprep(pic32s);
clk_disable_unprepare(pic32s->clk);
err_host: err_host:
spi_controller_put(host); spi_controller_put(host);
return ret; return ret;
...@@ -849,7 +844,6 @@ static void pic32_spi_remove(struct platform_device *pdev) ...@@ -849,7 +844,6 @@ static void pic32_spi_remove(struct platform_device *pdev)
pic32s = platform_get_drvdata(pdev); pic32s = platform_get_drvdata(pdev);
pic32_spi_disable(pic32s); pic32_spi_disable(pic32s);
clk_disable_unprepare(pic32s->clk);
pic32_spi_dma_unprep(pic32s); pic32_spi_dma_unprep(pic32s);
} }
......
...@@ -2168,19 +2168,13 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -2168,19 +2168,13 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
dev_info(&adev->dev, "mapped registers from %pa to %p\n", dev_info(&adev->dev, "mapped registers from %pa to %p\n",
&adev->res.start, pl022->virtbase); &adev->res.start, pl022->virtbase);
pl022->clk = devm_clk_get(&adev->dev, NULL); pl022->clk = devm_clk_get_enabled(&adev->dev, NULL);
if (IS_ERR(pl022->clk)) { if (IS_ERR(pl022->clk)) {
status = PTR_ERR(pl022->clk); status = PTR_ERR(pl022->clk);
dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n"); dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n");
goto err_no_clk; goto err_no_clk;
} }
status = clk_prepare_enable(pl022->clk);
if (status) {
dev_err(&adev->dev, "could not enable SSP/SPI bus clock\n");
goto err_no_clk_en;
}
/* Initialize transfer pump */ /* Initialize transfer pump */
tasklet_init(&pl022->pump_transfers, pump_transfers, tasklet_init(&pl022->pump_transfers, pump_transfers,
(unsigned long)pl022); (unsigned long)pl022);
...@@ -2240,8 +2234,6 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id) ...@@ -2240,8 +2234,6 @@ static int pl022_probe(struct amba_device *adev, const struct amba_id *id)
if (platform_info->enable_dma) if (platform_info->enable_dma)
pl022_dma_remove(pl022); pl022_dma_remove(pl022);
err_no_irq: err_no_irq:
clk_disable_unprepare(pl022->clk);
err_no_clk_en:
err_no_clk: err_no_clk:
err_no_ioremap: err_no_ioremap:
amba_release_regions(adev); amba_release_regions(adev);
...@@ -2268,7 +2260,6 @@ pl022_remove(struct amba_device *adev) ...@@ -2268,7 +2260,6 @@ pl022_remove(struct amba_device *adev)
if (pl022->host_info->enable_dma) if (pl022->host_info->enable_dma)
pl022_dma_remove(pl022); pl022_dma_remove(pl022);
clk_disable_unprepare(pl022->clk);
amba_release_regions(adev); amba_release_regions(adev);
tasklet_disable(&pl022->pump_transfers); tasklet_disable(&pl022->pump_transfers);
} }
......
...@@ -782,42 +782,30 @@ static int rockchip_spi_probe(struct platform_device *pdev) ...@@ -782,42 +782,30 @@ static int rockchip_spi_probe(struct platform_device *pdev)
goto err_put_ctlr; goto err_put_ctlr;
} }
rs->apb_pclk = devm_clk_get(&pdev->dev, "apb_pclk"); rs->apb_pclk = devm_clk_get_enabled(&pdev->dev, "apb_pclk");
if (IS_ERR(rs->apb_pclk)) { if (IS_ERR(rs->apb_pclk)) {
dev_err(&pdev->dev, "Failed to get apb_pclk\n"); dev_err(&pdev->dev, "Failed to get apb_pclk\n");
ret = PTR_ERR(rs->apb_pclk); ret = PTR_ERR(rs->apb_pclk);
goto err_put_ctlr; goto err_put_ctlr;
} }
rs->spiclk = devm_clk_get(&pdev->dev, "spiclk"); rs->spiclk = devm_clk_get_enabled(&pdev->dev, "spiclk");
if (IS_ERR(rs->spiclk)) { if (IS_ERR(rs->spiclk)) {
dev_err(&pdev->dev, "Failed to get spi_pclk\n"); dev_err(&pdev->dev, "Failed to get spi_pclk\n");
ret = PTR_ERR(rs->spiclk); ret = PTR_ERR(rs->spiclk);
goto err_put_ctlr; goto err_put_ctlr;
} }
ret = clk_prepare_enable(rs->apb_pclk);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to enable apb_pclk\n");
goto err_put_ctlr;
}
ret = clk_prepare_enable(rs->spiclk);
if (ret < 0) {
dev_err(&pdev->dev, "Failed to enable spi_clk\n");
goto err_disable_apbclk;
}
spi_enable_chip(rs, false); spi_enable_chip(rs, false);
ret = platform_get_irq(pdev, 0); ret = platform_get_irq(pdev, 0);
if (ret < 0) if (ret < 0)
goto err_disable_spiclk; goto err_put_ctlr;
ret = devm_request_threaded_irq(&pdev->dev, ret, rockchip_spi_isr, NULL, ret = devm_request_threaded_irq(&pdev->dev, ret, rockchip_spi_isr, NULL,
IRQF_ONESHOT, dev_name(&pdev->dev), ctlr); IRQF_ONESHOT, dev_name(&pdev->dev), ctlr);
if (ret) if (ret)
goto err_disable_spiclk; goto err_put_ctlr;
rs->dev = &pdev->dev; rs->dev = &pdev->dev;
rs->freq = clk_get_rate(rs->spiclk); rs->freq = clk_get_rate(rs->spiclk);
...@@ -843,7 +831,7 @@ static int rockchip_spi_probe(struct platform_device *pdev) ...@@ -843,7 +831,7 @@ static int rockchip_spi_probe(struct platform_device *pdev)
if (!rs->fifo_len) { if (!rs->fifo_len) {
dev_err(&pdev->dev, "Failed to get fifo length\n"); dev_err(&pdev->dev, "Failed to get fifo length\n");
ret = -EINVAL; ret = -EINVAL;
goto err_disable_spiclk; goto err_put_ctlr;
} }
pm_runtime_set_autosuspend_delay(&pdev->dev, ROCKCHIP_AUTOSUSPEND_TIMEOUT); pm_runtime_set_autosuspend_delay(&pdev->dev, ROCKCHIP_AUTOSUSPEND_TIMEOUT);
...@@ -937,10 +925,6 @@ static int rockchip_spi_probe(struct platform_device *pdev) ...@@ -937,10 +925,6 @@ static int rockchip_spi_probe(struct platform_device *pdev)
dma_release_channel(ctlr->dma_tx); dma_release_channel(ctlr->dma_tx);
err_disable_pm_runtime: err_disable_pm_runtime:
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
err_disable_spiclk:
clk_disable_unprepare(rs->spiclk);
err_disable_apbclk:
clk_disable_unprepare(rs->apb_pclk);
err_put_ctlr: err_put_ctlr:
spi_controller_put(ctlr); spi_controller_put(ctlr);
...@@ -950,13 +934,9 @@ static int rockchip_spi_probe(struct platform_device *pdev) ...@@ -950,13 +934,9 @@ static int rockchip_spi_probe(struct platform_device *pdev)
static void rockchip_spi_remove(struct platform_device *pdev) static void rockchip_spi_remove(struct platform_device *pdev)
{ {
struct spi_controller *ctlr = spi_controller_get(platform_get_drvdata(pdev)); struct spi_controller *ctlr = spi_controller_get(platform_get_drvdata(pdev));
struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
pm_runtime_get_sync(&pdev->dev); pm_runtime_get_sync(&pdev->dev);
clk_disable_unprepare(rs->spiclk);
clk_disable_unprepare(rs->apb_pclk);
pm_runtime_put_noidle(&pdev->dev); pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
pm_runtime_set_suspended(&pdev->dev); pm_runtime_set_suspended(&pdev->dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment