| .. | .. |
|---|
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | | -/* Copyright (C) 2012-2018 ARM Limited or its affiliates. */ |
|---|
| 2 | +/* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */ |
|---|
| 3 | 3 | |
|---|
| 4 | 4 | #include <linux/kernel.h> |
|---|
| 5 | 5 | #include <linux/interrupt.h> |
|---|
| .. | .. |
|---|
| 8 | 8 | #include "cc_buffer_mgr.h" |
|---|
| 9 | 9 | #include "cc_request_mgr.h" |
|---|
| 10 | 10 | #include "cc_sram_mgr.h" |
|---|
| 11 | | -#include "cc_ivgen.h" |
|---|
| 12 | 11 | #include "cc_hash.h" |
|---|
| 13 | 12 | #include "cc_pm.h" |
|---|
| 14 | 13 | #include "cc_fips.h" |
|---|
| .. | .. |
|---|
| 16 | 15 | #define POWER_DOWN_ENABLE 0x01 |
|---|
| 17 | 16 | #define POWER_DOWN_DISABLE 0x00 |
|---|
| 18 | 17 | |
|---|
| 19 | | -const struct dev_pm_ops ccree_pm = { |
|---|
| 20 | | - SET_RUNTIME_PM_OPS(cc_pm_suspend, cc_pm_resume, NULL) |
|---|
| 21 | | -}; |
|---|
| 22 | | - |
|---|
| 23 | | -int cc_pm_suspend(struct device *dev) |
|---|
| 18 | +static int cc_pm_suspend(struct device *dev) |
|---|
| 24 | 19 | { |
|---|
| 25 | 20 | struct cc_drvdata *drvdata = dev_get_drvdata(dev); |
|---|
| 26 | 21 | |
|---|
| 27 | 22 | dev_dbg(dev, "set HOST_POWER_DOWN_EN\n"); |
|---|
| 28 | 23 | fini_cc_regs(drvdata); |
|---|
| 29 | 24 | cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_ENABLE); |
|---|
| 30 | | - cc_clk_off(drvdata); |
|---|
| 25 | + clk_disable_unprepare(drvdata->clk); |
|---|
| 31 | 26 | return 0; |
|---|
| 32 | 27 | } |
|---|
| 33 | 28 | |
|---|
| 34 | | -int cc_pm_resume(struct device *dev) |
|---|
| 29 | +static int cc_pm_resume(struct device *dev) |
|---|
| 35 | 30 | { |
|---|
| 36 | 31 | int rc; |
|---|
| 37 | 32 | struct cc_drvdata *drvdata = dev_get_drvdata(dev); |
|---|
| 38 | 33 | |
|---|
| 39 | 34 | dev_dbg(dev, "unset HOST_POWER_DOWN_EN\n"); |
|---|
| 40 | 35 | /* Enables the device source clk */ |
|---|
| 41 | | - rc = cc_clk_on(drvdata); |
|---|
| 36 | + rc = clk_prepare_enable(drvdata->clk); |
|---|
| 42 | 37 | if (rc) { |
|---|
| 43 | 38 | dev_err(dev, "failed getting clock back on. We're toast.\n"); |
|---|
| 44 | 39 | return rc; |
|---|
| 40 | + } |
|---|
| 41 | + /* wait for Cryptocell reset completion */ |
|---|
| 42 | + if (!cc_wait_for_reset_completion(drvdata)) { |
|---|
| 43 | + dev_err(dev, "Cryptocell reset not completed"); |
|---|
| 44 | + return -EBUSY; |
|---|
| 45 | 45 | } |
|---|
| 46 | 46 | |
|---|
| 47 | 47 | cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE); |
|---|
| .. | .. |
|---|
| 55 | 55 | |
|---|
| 56 | 56 | cc_init_hash_sram(drvdata); |
|---|
| 57 | 57 | |
|---|
| 58 | | - cc_init_iv_sram(drvdata); |
|---|
| 59 | 58 | return 0; |
|---|
| 60 | 59 | } |
|---|
| 61 | 60 | |
|---|
| 61 | +const struct dev_pm_ops ccree_pm = { |
|---|
| 62 | + SET_RUNTIME_PM_OPS(cc_pm_suspend, cc_pm_resume, NULL) |
|---|
| 63 | +}; |
|---|
| 64 | + |
|---|
| 62 | 65 | int cc_pm_get(struct device *dev) |
|---|
| 63 | 66 | { |
|---|
| 64 | | - int rc = 0; |
|---|
| 65 | | - struct cc_drvdata *drvdata = dev_get_drvdata(dev); |
|---|
| 66 | | - |
|---|
| 67 | | - if (drvdata->pm_on) |
|---|
| 68 | | - rc = pm_runtime_get_sync(dev); |
|---|
| 69 | | - |
|---|
| 70 | | - return (rc == 1 ? 0 : rc); |
|---|
| 71 | | -} |
|---|
| 72 | | - |
|---|
| 73 | | -int cc_pm_put_suspend(struct device *dev) |
|---|
| 74 | | -{ |
|---|
| 75 | | - int rc = 0; |
|---|
| 76 | | - struct cc_drvdata *drvdata = dev_get_drvdata(dev); |
|---|
| 77 | | - |
|---|
| 78 | | - if (drvdata->pm_on) { |
|---|
| 79 | | - pm_runtime_mark_last_busy(dev); |
|---|
| 80 | | - rc = pm_runtime_put_autosuspend(dev); |
|---|
| 67 | + int rc = pm_runtime_get_sync(dev); |
|---|
| 68 | + if (rc < 0) { |
|---|
| 69 | + pm_runtime_put_noidle(dev); |
|---|
| 70 | + return rc; |
|---|
| 81 | 71 | } |
|---|
| 82 | 72 | |
|---|
| 83 | | - return rc; |
|---|
| 73 | + return 0; |
|---|
| 84 | 74 | } |
|---|
| 85 | 75 | |
|---|
| 86 | | -int cc_pm_init(struct cc_drvdata *drvdata) |
|---|
| 76 | +void cc_pm_put_suspend(struct device *dev) |
|---|
| 87 | 77 | { |
|---|
| 88 | | - struct device *dev = drvdata_to_dev(drvdata); |
|---|
| 89 | | - |
|---|
| 90 | | - /* must be before the enabling to avoid resdundent suspending */ |
|---|
| 91 | | - pm_runtime_set_autosuspend_delay(dev, CC_SUSPEND_TIMEOUT); |
|---|
| 92 | | - pm_runtime_use_autosuspend(dev); |
|---|
| 93 | | - /* set us as active - note we won't do PM ops until cc_pm_go()! */ |
|---|
| 94 | | - return pm_runtime_set_active(dev); |
|---|
| 95 | | -} |
|---|
| 96 | | - |
|---|
| 97 | | -/* enable the PM module*/ |
|---|
| 98 | | -void cc_pm_go(struct cc_drvdata *drvdata) |
|---|
| 99 | | -{ |
|---|
| 100 | | - pm_runtime_enable(drvdata_to_dev(drvdata)); |
|---|
| 101 | | - drvdata->pm_on = true; |
|---|
| 102 | | -} |
|---|
| 103 | | - |
|---|
| 104 | | -void cc_pm_fini(struct cc_drvdata *drvdata) |
|---|
| 105 | | -{ |
|---|
| 106 | | - pm_runtime_disable(drvdata_to_dev(drvdata)); |
|---|
| 107 | | - drvdata->pm_on = false; |
|---|
| 78 | + pm_runtime_mark_last_busy(dev); |
|---|
| 79 | + pm_runtime_put_autosuspend(dev); |
|---|
| 108 | 80 | } |
|---|