From 5f56e1d486aaef9bcfaa57129c493a95185043fd Mon Sep 17 00:00:00 2001 From: "Mark A. Greer" Date: Tue, 11 Dec 2012 21:00:13 -0700 Subject: [PATCH 06/10] crypto: omap4-aes: User finer-grained PM management Currently, the pm_runtime calls in omap4-aes enable things when the driver is probed and leave them enabled until the driver is removed. To fix this, move the pm_runtime calls to only enable the aes module when its actually in use. Signed-off-by: Mark A. Greer --- drivers/crypto/omap4-aes.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/drivers/crypto/omap4-aes.c b/drivers/crypto/omap4-aes.c index dec2de4..a957709 100644 --- a/drivers/crypto/omap4-aes.c +++ b/drivers/crypto/omap4-aes.c @@ -80,7 +80,6 @@ struct omap4_aes_dev { struct list_head list; unsigned long phys_base; void __iomem *io_base; - struct clk *iclk; struct omap4_aes_ctx *ctx; struct device *dev; unsigned long flags; @@ -146,7 +145,7 @@ static void omap4_aes_write_n(struct omap4_aes_dev *dd, u32 offset, static int omap4_aes_hw_init(struct omap4_aes_dev *dd) { - omap4_aes_write(dd, AES_REG_SYSCFG, 0); + pm_runtime_get_sync(dd->dev); if (!(dd->flags & FLAGS_INIT)) { dd->flags |= FLAGS_INIT; @@ -489,11 +488,17 @@ static void omap4_aes_finish_req(struct omap4_aes_dev *dd, int err) pr_debug("err: %d\n", err); + pm_runtime_put_sync(dd->dev); dd->flags &= ~FLAGS_BUSY; req->base.complete(&req->base, err); } +static void omap4_aes_dma_stop(struct omap4_aes_dev *dd) +{ + omap4_aes_write_mask(dd, AES_REG_SYSCFG, 0, AES_REG_SYSCFG_DREQ_MASK); +} + static int omap4_aes_crypt_dma_stop(struct omap4_aes_dev *dd) { int err = 0; @@ -501,7 +506,7 @@ static int omap4_aes_crypt_dma_stop(struct omap4_aes_dev *dd) pr_debug("total: %d\n", dd->total); - omap4_aes_write_mask(dd, AES_REG_SYSCFG, 0, AES_REG_SYSCFG_DREQ_MASK); + omap4_aes_dma_stop(dd); edma_stop(dd->dma_lch_in); edma_clean_channel(dd->dma_lch_in); @@ -819,21 +824,22 @@ static int omap4_aes_probe(struct platform_device *pdev) else dd->dma_in = res->start; - pm_runtime_enable(dev); - udelay(1); - pm_runtime_get_sync(dev); - udelay(1); - dd->io_base = ioremap(dd->phys_base, SZ_4K); if (!dd->io_base) { dev_err(dev, "can't ioremap\n"); err = -ENOMEM; - goto err_io; + goto err_data; } - omap4_aes_hw_init(dd); + pm_runtime_enable(dev); + pm_runtime_get_sync(dev); + + omap4_aes_dma_stop(dd); + reg = omap4_aes_read(dd, AES_REG_REV); + pm_runtime_put_sync(dev); + dev_info(dev, "AM33X AES hw accel rev: %u.%02u\n", ((reg & AES_REG_REV_X_MAJOR_MASK) >> 8), (reg & AES_REG_REV_Y_MINOR_MASK)); @@ -870,17 +876,8 @@ err_dma: tasklet_kill(&dd->done_task); tasklet_kill(&dd->queue_task); iounmap(dd->io_base); - -err_io: - pm_runtime_put_sync(dev); - udelay(1); pm_runtime_disable(dev); - udelay(1); - -//err_res: - //kfree(dd); - //dd = NULL; err_data: dev_err(dev, "initialization failed.\n"); return err; @@ -905,11 +902,7 @@ static int omap4_aes_remove(struct platform_device *pdev) tasklet_kill(&dd->queue_task); omap4_aes_dma_cleanup(dd); iounmap(dd->io_base); - pm_runtime_put_sync(&pdev->dev); - udelay(1); pm_runtime_disable(&pdev->dev); - udelay(1); - kfree(dd); dd = NULL; -- 1.7.12