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 SSI_LOG_DEBUG("set HOST_POWER_DOWN_EN\n");
44 WRITE_REGISTER(drvdata->cc_base + CC_REG_OFFSET(HOST_RGF, HOST_POWER_DOWN_EN), POWER_DOWN_ENABLE);
45 rc = ssi_request_mgr_runtime_suspend_queue(drvdata);
47 SSI_LOG_ERR("ssi_request_mgr_runtime_suspend_queue (%x)\n", rc);
50 fini_cc_regs(drvdata);
55 int ssi_power_mgr_runtime_resume(struct device *dev)
58 struct ssi_drvdata *drvdata =
59 (struct ssi_drvdata *)dev_get_drvdata(dev);
61 SSI_LOG_DEBUG("unset HOST_POWER_DOWN_EN\n");
62 WRITE_REGISTER(drvdata->cc_base + CC_REG_OFFSET(HOST_RGF, HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE);
64 rc = cc_clk_on(drvdata);
66 SSI_LOG_ERR("failed getting clock back on. We're toast.\n");
70 rc = init_cc_regs(drvdata, false);
72 SSI_LOG_ERR("init_cc_regs (%x)\n", rc);
76 rc = ssi_request_mgr_runtime_resume_queue(drvdata);
78 SSI_LOG_ERR("ssi_request_mgr_runtime_resume_queue (%x)\n", rc);
82 /* must be after the queue resuming as it uses the HW queue*/
83 ssi_hash_init_sram_digest_consts(drvdata);
85 ssi_ivgen_init_sram_pool(drvdata);
89 int ssi_power_mgr_runtime_get(struct device *dev)
93 if (ssi_request_mgr_is_queue_runtime_suspend(
94 (struct ssi_drvdata *)dev_get_drvdata(dev))) {
95 rc = pm_runtime_get_sync(dev);
97 pm_runtime_get_noresume(dev);
102 int ssi_power_mgr_runtime_put_suspend(struct device *dev)
106 if (!ssi_request_mgr_is_queue_runtime_suspend(
107 (struct ssi_drvdata *)dev_get_drvdata(dev))) {
108 pm_runtime_mark_last_busy(dev);
109 rc = pm_runtime_put_autosuspend(dev);
111 /* Something wrong happens*/
119 int ssi_power_mgr_init(struct ssi_drvdata *drvdata)
122 #if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
123 struct platform_device *plat_dev = drvdata->plat_dev;
124 /* must be before the enabling to avoid resdundent suspending */
125 pm_runtime_set_autosuspend_delay(&plat_dev->dev, SSI_SUSPEND_TIMEOUT);
126 pm_runtime_use_autosuspend(&plat_dev->dev);
127 /* activate the PM module */
128 rc = pm_runtime_set_active(&plat_dev->dev);
131 /* enable the PM module*/
132 pm_runtime_enable(&plat_dev->dev);
137 void ssi_power_mgr_fini(struct ssi_drvdata *drvdata)
139 #if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
140 struct platform_device *plat_dev = drvdata->plat_dev;
142 pm_runtime_disable(&plat_dev->dev);