2 * Copyright (C) 2012-2017 ARM Limited or its affiliates.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 #include "ssi_config.h"
18 #include <linux/kernel.h>
19 #include <linux/platform_device.h>
20 #include <linux/interrupt.h>
21 #include <crypto/ctr.h>
22 #include <linux/pm_runtime.h>
23 #include "ssi_driver.h"
24 #include "ssi_buffer_mgr.h"
25 #include "ssi_request_mgr.h"
26 #include "ssi_sram_mgr.h"
27 #include "ssi_sysfs.h"
28 #include "ssi_ivgen.h"
32 #if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
34 #define POWER_DOWN_ENABLE 0x01
35 #define POWER_DOWN_DISABLE 0x00
37 int ssi_power_mgr_runtime_suspend(struct device *dev)
39 struct ssi_drvdata *drvdata =
40 (struct ssi_drvdata *)dev_get_drvdata(dev);
43 dev_dbg(dev, "set HOST_POWER_DOWN_EN\n");
44 cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_ENABLE);
45 rc = ssi_request_mgr_runtime_suspend_queue(drvdata);
47 dev_err(dev, "ssi_request_mgr_runtime_suspend_queue (%x)\n",
51 fini_cc_regs(drvdata);
56 int ssi_power_mgr_runtime_resume(struct device *dev)
59 struct ssi_drvdata *drvdata =
60 (struct ssi_drvdata *)dev_get_drvdata(dev);
62 dev_dbg(dev, "unset HOST_POWER_DOWN_EN\n");
63 cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE);
65 rc = cc_clk_on(drvdata);
67 dev_err(dev, "failed getting clock back on. We're toast.\n");
71 rc = init_cc_regs(drvdata, false);
73 dev_err(dev, "init_cc_regs (%x)\n", rc);
77 rc = ssi_request_mgr_runtime_resume_queue(drvdata);
79 dev_err(dev, "ssi_request_mgr_runtime_resume_queue (%x)\n", rc);
83 /* must be after the queue resuming as it uses the HW queue*/
84 ssi_hash_init_sram_digest_consts(drvdata);
86 ssi_ivgen_init_sram_pool(drvdata);
90 int ssi_power_mgr_runtime_get(struct device *dev)
94 if (ssi_request_mgr_is_queue_runtime_suspend(
95 (struct ssi_drvdata *)dev_get_drvdata(dev))) {
96 rc = pm_runtime_get_sync(dev);
98 pm_runtime_get_noresume(dev);
103 int ssi_power_mgr_runtime_put_suspend(struct device *dev)
107 if (!ssi_request_mgr_is_queue_runtime_suspend(
108 (struct ssi_drvdata *)dev_get_drvdata(dev))) {
109 pm_runtime_mark_last_busy(dev);
110 rc = pm_runtime_put_autosuspend(dev);
112 /* Something wrong happens*/
113 dev_err(dev, "request to suspend already suspended queue");
121 int ssi_power_mgr_init(struct ssi_drvdata *drvdata)
124 #if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
125 struct device *dev = drvdata_to_dev(drvdata);
127 /* must be before the enabling to avoid resdundent suspending */
128 pm_runtime_set_autosuspend_delay(dev, SSI_SUSPEND_TIMEOUT);
129 pm_runtime_use_autosuspend(dev);
130 /* activate the PM module */
131 rc = pm_runtime_set_active(dev);
134 /* enable the PM module*/
135 pm_runtime_enable(dev);
140 void ssi_power_mgr_fini(struct ssi_drvdata *drvdata)
142 #if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
143 pm_runtime_disable(drvdata_to_dev(drvdata));