WIP FPC-III support
[linux/fpc-iii.git] / drivers / crypto / ccree / cc_pm.c
blobd5421b0c6831cea100af9f5d7111352124e064ea
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */
4 #include <linux/kernel.h>
5 #include <linux/interrupt.h>
6 #include <linux/pm_runtime.h>
7 #include "cc_driver.h"
8 #include "cc_buffer_mgr.h"
9 #include "cc_request_mgr.h"
10 #include "cc_sram_mgr.h"
11 #include "cc_hash.h"
12 #include "cc_pm.h"
13 #include "cc_fips.h"
15 #define POWER_DOWN_ENABLE 0x01
16 #define POWER_DOWN_DISABLE 0x00
18 static int cc_pm_suspend(struct device *dev)
20 struct cc_drvdata *drvdata = dev_get_drvdata(dev);
22 dev_dbg(dev, "set HOST_POWER_DOWN_EN\n");
23 fini_cc_regs(drvdata);
24 cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_ENABLE);
25 clk_disable_unprepare(drvdata->clk);
26 return 0;
29 static int cc_pm_resume(struct device *dev)
31 int rc;
32 struct cc_drvdata *drvdata = dev_get_drvdata(dev);
34 dev_dbg(dev, "unset HOST_POWER_DOWN_EN\n");
35 /* Enables the device source clk */
36 rc = clk_prepare_enable(drvdata->clk);
37 if (rc) {
38 dev_err(dev, "failed getting clock back on. We're toast.\n");
39 return rc;
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;
47 cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE);
48 rc = init_cc_regs(drvdata);
49 if (rc) {
50 dev_err(dev, "init_cc_regs (%x)\n", rc);
51 return rc;
53 /* check if tee fips error occurred during power down */
54 cc_tee_handle_fips_error(drvdata);
56 cc_init_hash_sram(drvdata);
58 return 0;
61 const struct dev_pm_ops ccree_pm = {
62 SET_RUNTIME_PM_OPS(cc_pm_suspend, cc_pm_resume, NULL)
65 int cc_pm_get(struct device *dev)
67 int rc = pm_runtime_get_sync(dev);
68 if (rc < 0) {
69 pm_runtime_put_noidle(dev);
70 return rc;
73 return 0;
76 void cc_pm_put_suspend(struct device *dev)
78 pm_runtime_mark_last_busy(dev);
79 pm_runtime_put_autosuspend(dev);