Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: caam - Enable and disable clocks on Freescale i.MX platforms

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>
Tested-by: Horia Geantă <horia.geanta@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Victoria Milhoan and committed by
Herbert Xu
24821c46 509da8fd

+94
+1
drivers/crypto/caam/compat.h
··· 23 23 #include <linux/types.h> 24 24 #include <linux/debugfs.h> 25 25 #include <linux/circ_buf.h> 26 + #include <linux/clk.h> 26 27 #include <net/xfrm.h> 27 28 28 29 #include <crypto/algapi.h>
+88
drivers/crypto/caam/ctrl.c
··· 16 16 #include "error.h" 17 17 18 18 /* 19 + * ARM targets tend to have clock control subsystems that can 20 + * enable/disable clocking to our device. 21 + */ 22 + #ifdef CONFIG_ARM 23 + static inline struct clk *caam_drv_identify_clk(struct device *dev, 24 + char *clk_name) 25 + { 26 + return devm_clk_get(dev, clk_name); 27 + } 28 + #else 29 + static inline struct clk *caam_drv_identify_clk(struct device *dev, 30 + char *clk_name) 31 + { 32 + return NULL; 33 + } 34 + #endif 35 + 36 + /* 19 37 * Descriptor to instantiate RNG State Handle 0 in normal mode and 20 38 * load the JDKEK, TDKEK and TDSK registers 21 39 */ ··· 322 304 /* Unmap controller region */ 323 305 iounmap(ctrl); 324 306 307 + /* shut clocks off before finalizing shutdown */ 308 + clk_disable_unprepare(ctrlpriv->caam_ipg); 309 + clk_disable_unprepare(ctrlpriv->caam_mem); 310 + clk_disable_unprepare(ctrlpriv->caam_aclk); 311 + clk_disable_unprepare(ctrlpriv->caam_emi_slow); 312 + 325 313 return ret; 326 314 } 327 315 ··· 415 391 struct device_node *nprop, *np; 416 392 struct caam_ctrl __iomem *ctrl; 417 393 struct caam_drv_private *ctrlpriv; 394 + struct clk *clk; 418 395 #ifdef CONFIG_DEBUG_FS 419 396 struct caam_perfmon *perfmon; 420 397 #endif ··· 433 408 dev_set_drvdata(dev, ctrlpriv); 434 409 ctrlpriv->pdev = pdev; 435 410 nprop = pdev->dev.of_node; 411 + 412 + /* Enable clocking */ 413 + clk = caam_drv_identify_clk(&pdev->dev, "ipg"); 414 + if (IS_ERR(clk)) { 415 + ret = PTR_ERR(clk); 416 + dev_err(&pdev->dev, 417 + "can't identify CAAM ipg clk: %d\n", ret); 418 + return -ENODEV; 419 + } 420 + ctrlpriv->caam_ipg = clk; 421 + 422 + clk = caam_drv_identify_clk(&pdev->dev, "mem"); 423 + if (IS_ERR(clk)) { 424 + ret = PTR_ERR(clk); 425 + dev_err(&pdev->dev, 426 + "can't identify CAAM mem clk: %d\n", ret); 427 + return -ENODEV; 428 + } 429 + ctrlpriv->caam_mem = clk; 430 + 431 + clk = caam_drv_identify_clk(&pdev->dev, "aclk"); 432 + if (IS_ERR(clk)) { 433 + ret = PTR_ERR(clk); 434 + dev_err(&pdev->dev, 435 + "can't identify CAAM aclk clk: %d\n", ret); 436 + return -ENODEV; 437 + } 438 + ctrlpriv->caam_aclk = clk; 439 + 440 + clk = caam_drv_identify_clk(&pdev->dev, "emi_slow"); 441 + if (IS_ERR(clk)) { 442 + ret = PTR_ERR(clk); 443 + dev_err(&pdev->dev, 444 + "can't identify CAAM emi_slow clk: %d\n", ret); 445 + return -ENODEV; 446 + } 447 + ctrlpriv->caam_emi_slow = clk; 448 + 449 + ret = clk_prepare_enable(ctrlpriv->caam_ipg); 450 + if (ret < 0) { 451 + dev_err(&pdev->dev, "can't enable CAAM ipg clock: %d\n", ret); 452 + return -ENODEV; 453 + } 454 + 455 + ret = clk_prepare_enable(ctrlpriv->caam_mem); 456 + if (ret < 0) { 457 + dev_err(&pdev->dev, "can't enable CAAM secure mem clock: %d\n", 458 + ret); 459 + return -ENODEV; 460 + } 461 + 462 + ret = clk_prepare_enable(ctrlpriv->caam_aclk); 463 + if (ret < 0) { 464 + dev_err(&pdev->dev, "can't enable CAAM aclk clock: %d\n", ret); 465 + return -ENODEV; 466 + } 467 + 468 + ret = clk_prepare_enable(ctrlpriv->caam_emi_slow); 469 + if (ret < 0) { 470 + dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n", 471 + ret); 472 + return -ENODEV; 473 + } 436 474 437 475 /* Get configuration properties from device tree */ 438 476 /* First, get register page */
+5
drivers/crypto/caam/intern.h
··· 91 91 Handles of the RNG4 block are initialized 92 92 by this driver */ 93 93 94 + struct clk *caam_ipg; 95 + struct clk *caam_mem; 96 + struct clk *caam_aclk; 97 + struct clk *caam_emi_slow; 98 + 94 99 /* 95 100 * debugfs entries for developer view into driver/device 96 101 * variables at runtime.