• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012-2017 ARM Limited or its affiliates.
3  *
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.
7  *
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.
12  *
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/>.
15  */
16 
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"
29 #include "ssi_hash.h"
30 #include "ssi_pm.h"
31 
32 #if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
33 
34 #define POWER_DOWN_ENABLE 0x01
35 #define POWER_DOWN_DISABLE 0x00
36 
ssi_power_mgr_runtime_suspend(struct device * dev)37 int ssi_power_mgr_runtime_suspend(struct device *dev)
38 {
39 	struct ssi_drvdata *drvdata =
40 		(struct ssi_drvdata *)dev_get_drvdata(dev);
41 	int rc;
42 
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);
46 	if (rc != 0) {
47 		SSI_LOG_ERR("ssi_request_mgr_runtime_suspend_queue (%x)\n", rc);
48 		return rc;
49 	}
50 	fini_cc_regs(drvdata);
51 	cc_clk_off(drvdata);
52 	return 0;
53 }
54 
ssi_power_mgr_runtime_resume(struct device * dev)55 int ssi_power_mgr_runtime_resume(struct device *dev)
56 {
57 	int rc;
58 	struct ssi_drvdata *drvdata =
59 		(struct ssi_drvdata *)dev_get_drvdata(dev);
60 
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);
63 
64 	rc = cc_clk_on(drvdata);
65 	if (rc) {
66 		SSI_LOG_ERR("failed getting clock back on. We're toast.\n");
67 		return rc;
68 	}
69 
70 	rc = init_cc_regs(drvdata, false);
71 	if (rc != 0) {
72 		SSI_LOG_ERR("init_cc_regs (%x)\n", rc);
73 		return rc;
74 	}
75 
76 	rc = ssi_request_mgr_runtime_resume_queue(drvdata);
77 	if (rc != 0) {
78 		SSI_LOG_ERR("ssi_request_mgr_runtime_resume_queue (%x)\n", rc);
79 		return rc;
80 	}
81 
82 	/* must be after the queue resuming as it uses the HW queue*/
83 	ssi_hash_init_sram_digest_consts(drvdata);
84 
85 	ssi_ivgen_init_sram_pool(drvdata);
86 	return 0;
87 }
88 
ssi_power_mgr_runtime_get(struct device * dev)89 int ssi_power_mgr_runtime_get(struct device *dev)
90 {
91 	int rc = 0;
92 
93 	if (ssi_request_mgr_is_queue_runtime_suspend(
94 				(struct ssi_drvdata *)dev_get_drvdata(dev))) {
95 		rc = pm_runtime_get_sync(dev);
96 	} else {
97 		pm_runtime_get_noresume(dev);
98 	}
99 	return rc;
100 }
101 
ssi_power_mgr_runtime_put_suspend(struct device * dev)102 int ssi_power_mgr_runtime_put_suspend(struct device *dev)
103 {
104 	int rc = 0;
105 
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);
110 	} else {
111 		/* Something wrong happens*/
112 		BUG();
113 	}
114 	return rc;
115 }
116 
117 #endif
118 
ssi_power_mgr_init(struct ssi_drvdata * drvdata)119 int ssi_power_mgr_init(struct ssi_drvdata *drvdata)
120 {
121 	int rc = 0;
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);
129 	if (rc != 0)
130 		return rc;
131 	/* enable the PM module*/
132 	pm_runtime_enable(&plat_dev->dev);
133 #endif
134 	return rc;
135 }
136 
ssi_power_mgr_fini(struct ssi_drvdata * drvdata)137 void ssi_power_mgr_fini(struct ssi_drvdata *drvdata)
138 {
139 #if defined(CONFIG_PM_RUNTIME) || defined(CONFIG_PM_SLEEP)
140 	struct platform_device *plat_dev = drvdata->plat_dev;
141 
142 	pm_runtime_disable(&plat_dev->dev);
143 #endif
144 }
145