staging: ccree: use Makefile to include PM code
authorGilad Ben-Yossef <gilad@benyossef.com>
Sun, 7 Jan 2018 12:14:26 +0000 (12:14 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 8 Jan 2018 15:27:23 +0000 (16:27 +0100)
Replace ugly ifdefs with some inline macros and Makefile magic
for optionally including power management related code for
better readability.

Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/ccree/Makefile
drivers/staging/ccree/ssi_pm.c
drivers/staging/ccree/ssi_pm.h
drivers/staging/ccree/ssi_request_mgr.c

index bb471446afce70709a76dd1b30c785927042bf1a..c107e2506717ac362059fcd161f13e8d51707d93 100644 (file)
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_CRYPTO_DEV_CCREE) := ccree.o
-ccree-y := ssi_driver.o ssi_buffer_mgr.o ssi_request_mgr.o ssi_cipher.o ssi_hash.o ssi_aead.o ssi_ivgen.o ssi_sram_mgr.o ssi_pm.o
+ccree-y := ssi_driver.o ssi_buffer_mgr.o ssi_request_mgr.o ssi_cipher.o ssi_hash.o ssi_aead.o ssi_ivgen.o ssi_sram_mgr.o
 ccree-$(CONFIG_CRYPTO_FIPS) += ssi_fips.o
 ccree-$(CONFIG_DEBUG_FS) += cc_debugfs.o
+ccree-$(CONFIG_PM) += ssi_pm.o
index 3d9d00be25b27302be9c9e3d16c0b3be3f8d6a40..3a8d91c4a11b4e53f4096e6df37050a1c8fadfac 100644 (file)
@@ -14,8 +14,6 @@
 #include "ssi_hash.h"
 #include "ssi_pm.h"
 
-#if defined(CONFIG_PM)
-
 #define POWER_DOWN_ENABLE 0x01
 #define POWER_DOWN_DISABLE 0x00
 
@@ -103,12 +101,9 @@ int cc_pm_put_suspend(struct device *dev)
        return rc;
 }
 
-#endif
-
 int cc_pm_init(struct cc_drvdata *drvdata)
 {
        int rc = 0;
-#if defined(CONFIG_PM)
        struct device *dev = drvdata_to_dev(drvdata);
 
        /* must be before the enabling to avoid resdundent suspending */
@@ -120,13 +115,11 @@ int cc_pm_init(struct cc_drvdata *drvdata)
                return rc;
        /* enable the PM module*/
        pm_runtime_enable(dev);
-#endif
+
        return rc;
 }
 
 void cc_pm_fini(struct cc_drvdata *drvdata)
 {
-#if defined(CONFIG_PM)
        pm_runtime_disable(drvdata_to_dev(drvdata));
-#endif
 }
index 87bc389e42a8ba8370e0006924130e038270530e..f603255daed69f73d7055d1c30c5dbd2ec3c11eb 100644 (file)
 
 #define CC_SUSPEND_TIMEOUT 3000
 
-int cc_pm_init(struct cc_drvdata *drvdata);
-
-void cc_pm_fini(struct cc_drvdata *drvdata);
-
 #if defined(CONFIG_PM)
 
 extern const struct dev_pm_ops ccree_pm;
 
+int cc_pm_init(struct cc_drvdata *drvdata);
+void cc_pm_fini(struct cc_drvdata *drvdata);
 int cc_pm_suspend(struct device *dev);
-
 int cc_pm_resume(struct device *dev);
-
 int cc_pm_get(struct device *dev);
-
 int cc_pm_put_suspend(struct device *dev);
+
+#else
+
+static inline int cc_pm_init(struct cc_drvdata *drvdata)
+{
+       return 0;
+}
+
+static inline void cc_pm_fini(struct cc_drvdata *drvdata) {}
+
+static inline int cc_pm_suspend(struct device *dev)
+{
+       return 0;
+}
+
+static inline int cc_pm_resume(struct device *dev)
+{
+       return 0;
+}
+
+static inline int cc_pm_get(struct device *dev)
+{
+       return 0;
+}
+
+static inline int cc_pm_put_suspend(struct device *dev)
+{
+       return 0;
+}
+
 #endif
 
 #endif /*__POWER_MGR_H__*/
index ff751d300ff3140c607e472b93ea2b057fcc8bca..78f25e58c9f5f24453b0c14bc933e4a05dcfe53c 100644 (file)
@@ -46,9 +46,7 @@ struct cc_req_mgr_handle {
 #else
        struct tasklet_struct comptask;
 #endif
-#if defined(CONFIG_PM)
        bool is_runtime_suspended;
-#endif
 };
 
 struct cc_bl_item {
@@ -404,9 +402,7 @@ static void cc_proc_backlog(struct cc_drvdata *drvdata)
                spin_unlock(&mgr->hw_lock);
 
                if (rc != -EINPROGRESS) {
-#if defined(CONFIG_PM)
                        cc_pm_put_suspend(dev);
-#endif
                        creq->user_cb(dev, req, rc);
                }
 
@@ -432,13 +428,12 @@ int cc_send_request(struct cc_drvdata *drvdata, struct cc_crypto_req *cc_req,
        gfp_t flags = cc_gfp_flags(req);
        struct cc_bl_item *bli;
 
-#if defined(CONFIG_PM)
        rc = cc_pm_get(dev);
        if (rc) {
                dev_err(dev, "ssi_power_mgr_runtime_get returned %x\n", rc);
                return rc;
        }
-#endif
+
        spin_lock_bh(&mgr->hw_lock);
        rc = cc_queues_status(drvdata, mgr, total_len);
 
@@ -452,9 +447,7 @@ int cc_send_request(struct cc_drvdata *drvdata, struct cc_crypto_req *cc_req,
 
                bli = kmalloc(sizeof(*bli), flags);
                if (!bli) {
-#if defined(CONFIG_PM)
                        cc_pm_put_suspend(dev);
-#endif
                        return -ENOMEM;
                }
 
@@ -486,13 +479,12 @@ int cc_send_sync_request(struct cc_drvdata *drvdata,
        cc_req->user_cb = request_mgr_complete;
        cc_req->user_arg = &cc_req->seq_compl;
 
-#if defined(CONFIG_PM)
        rc = cc_pm_get(dev);
        if (rc) {
                dev_err(dev, "ssi_power_mgr_runtime_get returned %x\n", rc);
                return rc;
        }
-#endif
+
        while (true) {
                spin_lock_bh(&mgr->hw_lock);
                rc = cc_queues_status(drvdata, mgr, len + 1);
@@ -502,9 +494,7 @@ int cc_send_sync_request(struct cc_drvdata *drvdata,
 
                spin_unlock_bh(&mgr->hw_lock);
                if (rc != -EAGAIN) {
-#if defined(CONFIG_PM)
                        cc_pm_put_suspend(dev);
-#endif
                        return rc;
                }
                wait_for_completion_interruptible(&drvdata->hw_queue_avail);
@@ -515,9 +505,7 @@ int cc_send_sync_request(struct cc_drvdata *drvdata,
        spin_unlock_bh(&mgr->hw_lock);
 
        if (rc != -EINPROGRESS) {
-#if defined(CONFIG_PM)
                cc_pm_put_suspend(dev);
-#endif
                return rc;
        }
 
@@ -621,9 +609,7 @@ static void proc_completions(struct cc_drvdata *drvdata)
                dev_dbg(dev, "Dequeue request tail=%u\n", *tail);
                dev_dbg(dev, "Request completed. axi_completed=%d\n",
                        request_mgr_handle->axi_completed);
-#if defined(CONFIG_PM)
                cc_pm_put_suspend(dev);
-#endif
        }
 }