linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Victoria Milhoan <vicki.milhoan@freescale.com>
Cc: linux-crypto@vger.kernel.org, linux@arm.linux.org.uk,
	herbert@gondor.apana.org.au, ruchika.gupta@freescale.com,
	kernel@pengutronix.de, shawnguo@kernel.org,
	horia.geanta@freescale.com
Subject: Re: [PATCH 03/12] crypto: caam - Enable and disable clocks on Freescale i.MX platforms
Date: Thu, 30 Jul 2015 08:02:14 +0200	[thread overview]
Message-ID: <20150730060214.GI18700@pengutronix.de> (raw)
In-Reply-To: <1438228709-27650-4-git-send-email-vicki.milhoan@freescale.com>

Hi Victoria,

comments inline.

On Wed, Jul 29, 2015 at 08:58:20PM -0700, Victoria Milhoan wrote:
> ARM-based systems may disable clocking to the CAAM device on the
> Freescale i.MX platform for power management purposes.  This patch
> enables the required clocks when the CAAM module is initialized and
> disables the required clocks when the CAAM module is shut down.
> 
> Signed-off-by: Victoria Milhoan <vicki.milhoan@freescale.com>
> ---
>  drivers/crypto/caam/compat.h |   1 +
>  drivers/crypto/caam/ctrl.c   | 191 +++++++++++++++++++++++++++++++++++++++++++
>  drivers/crypto/caam/intern.h |   5 ++
>  3 files changed, 197 insertions(+)
> 
> diff --git a/drivers/crypto/caam/compat.h b/drivers/crypto/caam/compat.h
> index f57f395..b6955ec 100644
> --- a/drivers/crypto/caam/compat.h
> +++ b/drivers/crypto/caam/compat.h
> @@ -23,6 +23,7 @@
>  #include <linux/types.h>
>  #include <linux/debugfs.h>
>  #include <linux/circ_buf.h>
> +#include <linux/clk.h>
>  #include <net/xfrm.h>
>  
>  #include <crypto/algapi.h>
> diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
> index 660cc3e..cfd8c9e 100644
> --- a/drivers/crypto/caam/ctrl.c
> +++ b/drivers/crypto/caam/ctrl.c
> @@ -16,6 +16,121 @@
>  #include "error.h"
>  
>  /*
> + * ARM targets tend to have clock control subsystems that can
> + * enable/disable clocking to our device. Support clocking
> + * with the following functions.
> + */
> +#ifdef CONFIG_ARM
> +static inline struct clk *caam_drv_get_clk_ipg(struct caam_drv_private *drv)
> +{
> +	return drv->caam_ipg;
> +}

You return drv->caam_ipg on ARM and NULL on powerpc. drv->caam_ipg is
NULL on powerpc anyway which makes this different implementations for
ARM and powerpc unnecessary. Just access drv->caam_ipg directly where
needed.

> +
> +static inline struct clk *caam_drv_get_clk_mem(struct caam_drv_private *drv)
> +{
> +	return drv->caam_mem;
> +}
> +
> +static inline struct clk *caam_drv_get_clk_aclk(struct caam_drv_private *drv)
> +{
> +	return drv->caam_aclk;
> +}
> +
> +static inline struct clk *caam_drv_get_clk_emislow(struct caam_drv_private *drv)
> +{
> +	return drv->caam_emi_slow;
> +}
> +
> +static inline void caam_drv_set_clk_ipg(struct caam_drv_private *drv,
> +					struct clk *clk)
> +{
> +	drv->caam_ipg = clk;
> +}

Ditto, just access drv->caam_ipg when needed.

> +
> +static inline void caam_drv_set_clk_mem(struct caam_drv_private *drv,
> +					struct clk *clk)
> +{
> +	drv->caam_mem = clk;
> +}
> +
> +static inline void caam_drv_set_clk_aclk(struct caam_drv_private *drv,
> +					 struct clk *clk)
> +{
> +	drv->caam_aclk = clk;
> +}
> +
> +static inline void caam_drv_set_clk_emislow(struct caam_drv_private *drv,
> +					    struct clk *clk)
> +{
> +	drv->caam_emi_slow = clk;
> +}
> +
> +static inline struct clk *caam_drv_identify_clk(struct device *dev,
> +						char *clk_name)
> +{
> +	return devm_clk_get(dev, clk_name);
> +}

devm_clk_get() returns NULL when the architecture does not have clk
support, so it also seems unnecessary to have architecture specific
implementations for this.

> +
> +static inline void caam_drv_show_clk(struct device *dev, struct clk *clk,
> +				     char *clk_name)
> +{
> +	dev_info(dev, "%s clock:%d\n", clk_name, (int)clk_get_rate(clk));
> +}

The correct format specifier for unsigned long is "%lu", no need to cast
it to int. Besides, this information is not generally interesting, you
can drop this.

> +
> +#else
> +static inline struct clk *caam_drv_get_clk_ipg(struct caam_drv_private *drv)
> +{
> +	return NULL;
> +}
> +
> +static inline struct clk *caam_drv_get_clk_mem(struct caam_drv_private *drv)
> +{
> +	return NULL;
> +}
> +
> +static inline struct clk *caam_drv_get_clk_aclk(struct caam_drv_private *drv)
> +{
> +	return NULL;
> +}
> +
> +static inline struct clk *caam_drv_get_clk_emislow(struct caam_drv_private *drv)
> +{
> +	return NULL;
> +}
> +
> +static inline void caam_drv_set_clk_ipg(struct caam_drv_private *drv,
> +					struct clk *clk)
> +{
> +}
> +
> +static inline void caam_drv_set_clk_mem(struct caam_drv_private *drv,
> +					struct clk *clk)
> +{
> +}
> +
> +static inline void caam_drv_set_clk_aclk(struct caam_drv_private *drv,
> +					 struct clk *clk)
> +{
> +}
> +
> +static inline void caam_drv_set_clk_emislow(struct caam_drv_private *drv,
> +					    struct clk *clk)
> +{
> +}
> +
> +static inline struct clk *caam_drv_identify_clk(struct device *dev,
> +						char *clk_name)
> +{
> +	return 0;
> +}
> +
> +static inline void caam_drv_show_clk(struct device *dev, struct clk *clk,
> +				     char *clk_name)
> +{
> +}
> +#endif
> +
> +/*
>   * Descriptor to instantiate RNG State Handle 0 in normal mode and
>   * load the JDKEK, TDKEK and TDSK registers
>   */
> @@ -304,6 +419,12 @@ static int caam_remove(struct platform_device *pdev)
>  	/* Unmap controller region */
>  	iounmap(ctrl);
>  
> +	/* shut clocks off before finalizing shutdown */
> +	clk_disable_unprepare(caam_drv_get_clk_ipg(ctrlpriv));
> +	clk_disable_unprepare(caam_drv_get_clk_mem(ctrlpriv));
> +	clk_disable_unprepare(caam_drv_get_clk_aclk(ctrlpriv));
> +	clk_disable_unprepare(caam_drv_get_clk_emislow(ctrlpriv));
> +
>  	return ret;
>  }
>  
> @@ -391,6 +512,7 @@ static int caam_probe(struct platform_device *pdev)
>  	struct device_node *nprop, *np;
>  	struct caam_ctrl __iomem *ctrl;
>  	struct caam_drv_private *ctrlpriv;
> +	struct clk *clk;
>  #ifdef CONFIG_DEBUG_FS
>  	struct caam_perfmon *perfmon;
>  #endif
> @@ -409,6 +531,75 @@ static int caam_probe(struct platform_device *pdev)
>  	ctrlpriv->pdev = pdev;
>  	nprop = pdev->dev.of_node;
>  
> +	/* Enable clocking */
> +	clk = caam_drv_identify_clk(&pdev->dev, "caam_ipg");
> +	if (IS_ERR(clk)) {
> +		ret = PTR_ERR(clk);
> +		dev_err(&pdev->dev,
> +			"can't identify CAAM ipg clk: %d\n", ret);
> +		return -ENODEV;
> +	}
> +	caam_drv_set_clk_ipg(ctrlpriv, clk);
> +
> +	clk = caam_drv_identify_clk(&pdev->dev, "caam_mem");
> +	if (IS_ERR(clk)) {
> +		ret = PTR_ERR(clk);
> +		dev_err(&pdev->dev,
> +			"can't identify CAAM mem clk: %d\n", ret);
> +		return -ENODEV;
> +	}
> +	caam_drv_set_clk_mem(ctrlpriv, clk);
> +
> +	clk = caam_drv_identify_clk(&pdev->dev, "caam_aclk");
> +	if (IS_ERR(clk)) {
> +		ret = PTR_ERR(clk);
> +		dev_err(&pdev->dev,
> +			"can't identify CAAM aclk clk: %d\n", ret);
> +		return -ENODEV;
> +	}
> +	caam_drv_set_clk_aclk(ctrlpriv, clk);
> +
> +	clk = caam_drv_identify_clk(&pdev->dev, "caam_emi_slow");
> +	if (IS_ERR(clk)) {
> +		ret = PTR_ERR(clk);
> +		dev_err(&pdev->dev,
> +			"can't identify CAAM emi_slow clk: %d\n", ret);
> +		return -ENODEV;
> +	}
> +	caam_drv_set_clk_emislow(ctrlpriv, clk);
> +
> +	ret = clk_prepare_enable(caam_drv_get_clk_ipg(ctrlpriv));
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "can't enable CAAM ipg clock: %d\n", ret);
> +		return -ENODEV;
> +	}
> +
> +	ret = clk_prepare_enable(caam_drv_get_clk_mem(ctrlpriv));
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "can't enable CAAM secure mem clock: %d\n",
> +			ret);
> +		return -ENODEV;
> +	}
> +
> +	ret = clk_prepare_enable(caam_drv_get_clk_aclk(ctrlpriv));
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "can't enable CAAM aclk clock: %d\n", ret);
> +		return -ENODEV;
> +	}
> +
> +	ret = clk_prepare_enable(caam_drv_get_clk_emislow(ctrlpriv));
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n",
> +			ret);
> +		return -ENODEV;
> +	}
> +
> +	caam_drv_show_clk(dev, caam_drv_get_clk_ipg(ctrlpriv), "caam_ipg");

No. Each clk_get takes a reference to the clk and must be balanced with
clk_put. You can't just take a new reference each time you need that
clk.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

  reply	other threads:[~2015-07-30  6:02 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-30  3:58 [PATCH 00/12] crypto: caam - Add i.MX6 support to the Freescale CAAM driver Victoria Milhoan
2015-07-30  3:58 ` [PATCH 01/12] crypto: caam - Add cache coherency support Victoria Milhoan
2015-07-30  3:58 ` [PATCH 02/12] crypto: caam - Add setbits32/clrbits32/clrsetbits primitives for ARM compatibility Victoria Milhoan
2015-07-30  3:58 ` [PATCH 03/12] crypto: caam - Enable and disable clocks on Freescale i.MX platforms Victoria Milhoan
2015-07-30  6:02   ` Sascha Hauer [this message]
2015-07-31  6:32     ` Victoria Milhoan
2015-07-31  6:40       ` Sascha Hauer
2015-07-30  3:58 ` [PATCH 04/12] crypto: caam - Modify Freescale CAAM driver Scatter Gather entry definition Victoria Milhoan
2015-07-30  3:58 ` [PATCH 05/12] crypto: caam - Change kmalloc to kzalloc to avoid residual data Victoria Milhoan
2015-07-30  3:58 ` [PATCH 06/12] crypto: caam - Correct DMA unmap size in ahash_update_ctx() Victoria Milhoan
2015-07-30  3:58 ` [PATCH 07/12] crypto: caam - Use local sg pointers to walk the scatterlist Victoria Milhoan
2015-07-30  3:58 ` [PATCH 08/12] ARM: clk-imx6q: Add CAAM clock support Victoria Milhoan
2015-07-30  6:14   ` Sascha Hauer
2015-07-31  6:38     ` Victoria Milhoan
2015-07-30  3:58 ` [PATCH 09/12] ARM: dts: mx6qdl: Add CAAM device node Victoria Milhoan
2015-07-30  6:12   ` Sascha Hauer
2015-07-30  3:58 ` [PATCH 10/12] ARM: dts: mx6sx: " Victoria Milhoan
2015-07-30  3:58 ` [PATCH 11/12] crypto: caam - Enable MXC devices to select CAAM driver in Kconfig Victoria Milhoan
2015-07-30  3:58 ` [PATCH 12/12] ARM: imx_v6_v7_defconfig: Select CAAM Victoria Milhoan
2015-07-30 17:53 ` [PATCH 00/12] crypto: caam - Add i.MX6 support to the Freescale CAAM driver Horia Geantă
2015-08-05 18:28 ` [PATCH v2 00/14] " Victoria Milhoan
2015-08-05 18:28   ` [PATCH v2 01/14] crypto: caam - Add cache coherency support Victoria Milhoan
2015-08-05 18:28   ` [PATCH v2 02/14] crypto: caam - Add setbits32/clrbits32/clrsetbits primitives for ARM compatibility Victoria Milhoan
2015-08-05 18:28   ` [PATCH v2 03/14] crypto: caam - Enable and disable clocks on Freescale i.MX platforms Victoria Milhoan
2015-08-05 18:28   ` [PATCH v2 04/14] crypto: caam - Modify Freescale CAAM driver Scatter Gather entry definition Victoria Milhoan
2015-08-05 18:28   ` [PATCH v2 05/14] crypto: caam - Change kmalloc to kzalloc to avoid residual data Victoria Milhoan
2015-08-07  9:59     ` Herbert Xu
2015-08-05 18:28   ` [PATCH v2 06/14] crypto: caam - Correct DMA unmap size in ahash_update_ctx() Victoria Milhoan
2015-08-05 18:28   ` [PATCH v2 07/14] crypto: caam - Use local sg pointers to walk the scatterlist Victoria Milhoan
2015-08-05 18:28   ` [PATCH v2 08/14] crypto: caam - Added clocks and clock-names properties to SEC4.0 device tree binding Victoria Milhoan
2015-08-05 18:28   ` [PATCH v2 09/14] ARM: clk-imx6q: Add CAAM clock support Victoria Milhoan
2015-08-05 18:28   ` [PATCH v2 10/14] ARM: dts: mx6qdl: Add CAAM device node Victoria Milhoan
2015-08-05 18:28   ` [PATCH v2 11/14] ARM: dts: mx6sx: " Victoria Milhoan
2015-08-06  8:59     ` Horia Geantă
2015-08-06 18:37       ` Victoria Milhoan
2015-08-06 18:42       ` [PATCH v3 " Victoria Milhoan
2015-08-07  6:58         ` Horia Geantă
2015-08-05 18:28   ` [PATCH v2 12/14] crypto: caam - Enable MXC devices to select CAAM driver in Kconfig Victoria Milhoan
2015-08-05 18:28   ` [PATCH v2 13/14] ARM: imx_v6_v7_defconfig: Select CAAM Victoria Milhoan
2015-08-05 18:28   ` [PATCH v2 14/14] crypto: caam - Detect hardware features during algorithm registration Victoria Milhoan
2015-08-10 15:40   ` [PATCH v2 00/14] crypto: caam - Add i.MX6 support to the Freescale CAAM driver Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150730060214.GI18700@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@freescale.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=ruchika.gupta@freescale.com \
    --cc=shawnguo@kernel.org \
    --cc=vicki.milhoan@freescale.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).