All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] mmc: mediatek: add Inline Crypto Engine support
@ 2021-01-29  7:08 Peng Zhou
  2021-01-29 18:59 ` Eric Biggers
  2021-02-10  7:42 ` Eric Biggers
  0 siblings, 2 replies; 3+ messages in thread
From: Peng Zhou @ 2021-01-29  7:08 UTC (permalink / raw
  To: linux-mmc, Chaotian Jing, Eric Biggers, Ulf Hansson
  Cc: Satya Tangirala, Andy Gross, Bjorn Andersson, Adrian Hunter,
	Wulin Li, Peng Zhou, Stanley Chu

- add crypto clock control and ungate it before CQHCI init
- set MMC_CAP2_CRYPTO property of eMMC

Change-Id: I3a28eaa3718eee73259b4d60867cce25525f9bba
Signed-off-by: Peng Zhou <peng.zhou@mediatek.com>
---
 drivers/mmc/host/mtk-sd.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
index de09c6347524..928349284998 100644
--- a/drivers/mmc/host/mtk-sd.c
+++ b/drivers/mmc/host/mtk-sd.c
@@ -441,6 +441,7 @@ struct msdc_host {
 	struct clk *bus_clk;	/* bus clock which used to access register */
 	struct clk *src_clk_cg; /* msdc source clock control gate */
 	struct clk *sys_clk_cg;	/* msdc subsys clock control gate */
+	struct clk *crypto_clk; /* msdc crypto clock */
 	struct clk_bulk_data bulk_clks[MSDC_NR_CLOCKS];
 	u32 mclk;		/* mmc subsystem clock frequency */
 	u32 src_clk_freq;	/* source clock frequency */
@@ -802,6 +803,7 @@ static void msdc_set_busy_timeout(struct msdc_host *host, u64 ns, u64 clks)
 
 static void msdc_gate_clock(struct msdc_host *host)
 {
+	clk_disable_unprepare(host->crypto_clk);
 	clk_bulk_disable_unprepare(MSDC_NR_CLOCKS, host->bulk_clks);
 	clk_disable_unprepare(host->src_clk_cg);
 	clk_disable_unprepare(host->src_clk);
@@ -822,7 +824,7 @@ static void msdc_ungate_clock(struct msdc_host *host)
 		dev_err(host->dev, "Cannot enable pclk/axi/ahb clock gates\n");
 		return;
 	}
-
+	clk_prepare_enable(host->crypto_clk);
 	while (!(readl(host->base + MSDC_CFG) & MSDC_CFG_CKSTB))
 		cpu_relax();
 }
@@ -2510,6 +2512,16 @@ static int msdc_drv_probe(struct platform_device *pdev)
 		goto host_free;
 	}
 
+	/* only eMMC has crypto property */
+	if ((mmc->caps2 & MMC_CAP2_NO_SD) && (mmc->caps2 & MMC_CAP2_NO_SDIO))
+		mmc->caps2 |= MMC_CAP2_CRYPTO;
+
+	if (mmc->caps2 & MMC_CAP2_CRYPTO) {
+		host->crypto_clk = devm_clk_get(&pdev->dev, "crypto_clk");
+		if (IS_ERR(host->crypto_clk))
+			host->crypto_clk = NULL;
+	}
+
 	host->irq = platform_get_irq(pdev, 0);
 	if (host->irq < 0) {
 		ret = -EINVAL;
@@ -2580,6 +2592,8 @@ static int msdc_drv_probe(struct platform_device *pdev)
 		host->dma_mask = DMA_BIT_MASK(32);
 	mmc_dev(mmc)->dma_mask = &host->dma_mask;
 
+	/* here ungate due to cqhci init will access registers */
+	msdc_ungate_clock(host);
 	if (mmc->caps2 & MMC_CAP2_CQE) {
 		host->cq_host = devm_kzalloc(mmc->parent,
 					     sizeof(*host->cq_host),
@@ -2616,7 +2630,6 @@ static int msdc_drv_probe(struct platform_device *pdev)
 	spin_lock_init(&host->lock);
 
 	platform_set_drvdata(pdev, mmc);
-	msdc_ungate_clock(host);
 	msdc_init_hw(host);
 
 	ret = devm_request_irq(&pdev->dev, host->irq, msdc_irq,
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/2] mmc: mediatek: add Inline Crypto Engine support
  2021-01-29  7:08 [PATCH v2 1/2] mmc: mediatek: add Inline Crypto Engine support Peng Zhou
@ 2021-01-29 18:59 ` Eric Biggers
  2021-02-10  7:42 ` Eric Biggers
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Biggers @ 2021-01-29 18:59 UTC (permalink / raw
  To: Peng Zhou
  Cc: linux-mmc, Chaotian Jing, Ulf Hansson, Satya Tangirala,
	Andy Gross, Bjorn Andersson, Adrian Hunter, Wulin Li, Stanley Chu

On Fri, Jan 29, 2021 at 03:08:25PM +0800, Peng Zhou wrote:
> - add crypto clock control and ungate it before CQHCI init
> - set MMC_CAP2_CRYPTO property of eMMC
> 
> Change-Id: I3a28eaa3718eee73259b4d60867cce25525f9bba
> Signed-off-by: Peng Zhou <peng.zhou@mediatek.com>

Please run scripts/checkpatch.pl on this patch (and the next one) and address
the warnings and errors.

> +	/* only eMMC has crypto property */
> +	if ((mmc->caps2 & MMC_CAP2_NO_SD) && (mmc->caps2 & MMC_CAP2_NO_SDIO))
> +		mmc->caps2 |= MMC_CAP2_CRYPTO;
> +
> +	if (mmc->caps2 & MMC_CAP2_CRYPTO) {
> +		host->crypto_clk = devm_clk_get(&pdev->dev, "crypto_clk");
> +		if (IS_ERR(host->crypto_clk))
> +			host->crypto_clk = NULL;
> +	}

Is this logic correct?  I'm wondering whether you want something more like:

	/* only eMMC has crypto property */
	if ((mmc->caps2 & MMC_CAP2_NO_SD) && (mmc->caps2 & MMC_CAP2_NO_SDIO))
		host->crypto_clk = devm_clk_get(&pdev->dev, "crypto_clk");
		if (IS_ERR(host->crypto_clk))
			host->crypto_clk = NULL;
		else
			mmc->caps2 |= MMC_CAP2_CRYPTO;
	}

I.e., is crypto only supported when crypto_clk is present?  Or can crypto be
supported without crypto_clk being present?

- Eric

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/2] mmc: mediatek: add Inline Crypto Engine support
  2021-01-29  7:08 [PATCH v2 1/2] mmc: mediatek: add Inline Crypto Engine support Peng Zhou
  2021-01-29 18:59 ` Eric Biggers
@ 2021-02-10  7:42 ` Eric Biggers
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Biggers @ 2021-02-10  7:42 UTC (permalink / raw
  To: Peng Zhou
  Cc: linux-mmc, Chaotian Jing, Ulf Hansson, Satya Tangirala,
	Andy Gross, Bjorn Andersson, Adrian Hunter, Wulin Li, Stanley Chu

One more comment:

On Fri, Jan 29, 2021 at 03:08:25PM +0800, Peng Zhou wrote:
> +	if (mmc->caps2 & MMC_CAP2_CRYPTO) {
> +		host->crypto_clk = devm_clk_get(&pdev->dev, "crypto_clk");
> +		if (IS_ERR(host->crypto_clk))
> +			host->crypto_clk = NULL;
> +	}

I think that clock names aren't supposed to end in "_clk", as this is implied.
Just call it "crypto".

- Eric

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-10  7:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-29  7:08 [PATCH v2 1/2] mmc: mediatek: add Inline Crypto Engine support Peng Zhou
2021-01-29 18:59 ` Eric Biggers
2021-02-10  7:42 ` Eric Biggers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.