@@ -27,8 +27,36 @@ static struct jr_driver_data driver_data;
static DEFINE_MUTEX(algs_lock);
static unsigned int active_devs;
-static void register_algs(struct caam_drv_private_jr *jrpriv,
- struct device *dev)
+static void init_misc_func(struct caam_drv_private_jr *jrpriv,
+ struct device *dev)
+{
+ mutex_lock(&algs_lock);
+
+ if (active_devs != 1)
+ goto algs_unlock;
+
+ jrpriv->hwrng = !caam_rng_init(dev);
+
+algs_unlock:
+ mutex_unlock(&algs_lock);
+}
+
+static void exit_misc_func(struct caam_drv_private_jr *jrpriv,
+ struct device *dev)
+{
+ mutex_lock(&algs_lock);
+
+ if (active_devs != 1)
+ goto algs_unlock;
+
+ if (jrpriv->hwrng)
+ caam_rng_exit(dev);
+
+algs_unlock:
+ mutex_unlock(&algs_lock);
+}
+
+static void register_algs(struct device *dev)
{
mutex_lock(&algs_lock);
@@ -38,7 +66,6 @@ static void register_algs(struct caam_drv_private_jr *jrpriv,
caam_algapi_init(dev);
caam_algapi_hash_init(dev);
caam_pkc_init(dev);
- jrpriv->hwrng = !caam_rng_init(dev);
caam_prng_register(dev);
caam_qi_algapi_init(dev);
@@ -136,8 +163,7 @@ static int caam_jr_remove(struct platform_device *pdev)
jrdev = &pdev->dev;
jrpriv = dev_get_drvdata(jrdev);
- if (jrpriv->hwrng)
- caam_rng_exit(jrdev->parent);
+ exit_misc_func(jrpriv, jrdev->parent);
/*
* Return EBUSY if job ring already allocated.
@@ -595,7 +621,8 @@ static int caam_jr_probe(struct platform_device *pdev)
atomic_set(&jrpriv->tfm_count, 0);
- register_algs(jrpriv, jrdev->parent);
+ register_algs(jrdev->parent);
+ init_misc_func(jrpriv, jrdev->parent);
return 0;
}