Merge branch 'irq-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / drivers / crypto / picoxcell_crypto.c
index 4ffb903..a2b553e 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/io.h>
 #include <linux/list.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm.h>
 #include <linux/rtnetlink.h>
@@ -1241,8 +1242,8 @@ static void spacc_spacc_complete(unsigned long data)
        spin_unlock_irqrestore(&engine->hw_lock, flags);
 
        list_for_each_entry_safe(req, tmp, &completed, list) {
-               req->complete(req);
                list_del(&req->list);
+               req->complete(req);
        }
 }
 
@@ -1657,27 +1658,49 @@ static struct spacc_alg l2_engine_algs[] = {
        },
 };
 
+#ifdef CONFIG_OF
+static const struct of_device_id spacc_of_id_table[] = {
+       { .compatible = "picochip,spacc-ipsec" },
+       { .compatible = "picochip,spacc-l2" },
+       {}
+};
+#else /* CONFIG_OF */
+#define spacc_of_id_table NULL
+#endif /* CONFIG_OF */
+
+static bool spacc_is_compatible(struct platform_device *pdev,
+                               const char *spacc_type)
+{
+       const struct platform_device_id *platid = platform_get_device_id(pdev);
+
+       if (platid && !strcmp(platid->name, spacc_type))
+               return true;
+
+#ifdef CONFIG_OF
+       if (of_device_is_compatible(pdev->dev.of_node, spacc_type))
+               return true;
+#endif /* CONFIG_OF */
+
+       return false;
+}
+
 static int __devinit spacc_probe(struct platform_device *pdev)
 {
        int i, err, ret = -EINVAL;
        struct resource *mem, *irq;
-       const struct platform_device_id *platid = platform_get_device_id(pdev);
        struct spacc_engine *engine = devm_kzalloc(&pdev->dev, sizeof(*engine),
                                                   GFP_KERNEL);
        if (!engine)
                return -ENOMEM;
 
-       if (!platid)
-               return -EINVAL;
-
-       if (!strcmp(platid->name, "picoxcell-ipsec")) {
+       if (spacc_is_compatible(pdev, "picochip,spacc-ipsec")) {
                engine->max_ctxs        = SPACC_CRYPTO_IPSEC_MAX_CTXS;
                engine->cipher_pg_sz    = SPACC_CRYPTO_IPSEC_CIPHER_PG_SZ;
                engine->hash_pg_sz      = SPACC_CRYPTO_IPSEC_HASH_PG_SZ;
                engine->fifo_sz         = SPACC_CRYPTO_IPSEC_FIFO_SZ;
                engine->algs            = ipsec_engine_algs;
                engine->num_algs        = ARRAY_SIZE(ipsec_engine_algs);
-       } else if (!strcmp(platid->name, "picoxcell-l2")) {
+       } else if (spacc_is_compatible(pdev, "picochip,spacc-l2")) {
                engine->max_ctxs        = SPACC_CRYPTO_L2_MAX_CTXS;
                engine->cipher_pg_sz    = SPACC_CRYPTO_L2_CIPHER_PG_SZ;
                engine->hash_pg_sz      = SPACC_CRYPTO_L2_HASH_PG_SZ;
@@ -1724,7 +1747,7 @@ static int __devinit spacc_probe(struct platform_device *pdev)
 
        spin_lock_init(&engine->hw_lock);
 
-       engine->clk = clk_get(&pdev->dev, NULL);
+       engine->clk = clk_get(&pdev->dev, "ref");
        if (IS_ERR(engine->clk)) {
                dev_info(&pdev->dev, "clk unavailable\n");
                device_remove_file(&pdev->dev, &dev_attr_stat_irq_thresh);
@@ -1826,6 +1849,7 @@ static struct platform_driver spacc_driver = {
 #ifdef CONFIG_PM
                .pm     = &spacc_pm_ops,
 #endif /* CONFIG_PM */
+               .of_match_table = spacc_of_id_table,
        },
        .id_table       = spacc_id_table,
 };