Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2694953ybi; Mon, 17 Jun 2019 09:04:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqw2l4XzMV0DuGn+oKo0JS/CUQ9wXXU70U1It7asLXK8rXLq4fk0QZXzdw1F5/GUoJ4d9OT2 X-Received: by 2002:a17:90a:8415:: with SMTP id j21mr26681027pjn.21.1560787471266; Mon, 17 Jun 2019 09:04:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560787471; cv=none; d=google.com; s=arc-20160816; b=PEu2M9ydoP5cKl2A78GiGNZrc/yKyn9lds94p3nfq2yyazy0vIwW7RPYZadqO0XHtf KMlldzT9fVzH6irVPovsGYnWFS12nE2QMSVHG+PaaxZxcO4LVSzfz4cvBpuv0L+b8kCJ p92y1i2V4ndDT8pe0TC0p2U7re0cJxfFh80xtOVBdlqLfSU6StuywFnDs2DR4Gr9xXaE on6Ub6JfO9idUy/DikB3ZR1jdlTapbytRK5rUxaGh19rxMAUdIargdeo21F6B2X2tvpR EhySu/MCgwt7Lf4G3gGQpE1b3kNRQitsX8xta4SxjsNYxVxxaUDXW0sX8NOhiscGyCAS uQbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PDuKbGKAhiAX1HMZyETnUi9VLoZ6KyS/hwRdrr3ylQk=; b=ZAZ4nt9wjr/fCfl7WrYT8/qRhsZRILGaCii05zHhsWMX9nnD5cPJmp6K2BbLGdHCM2 jLT/CQiPhfAsEX1jpJ3qAay43gNtri4a3hIcna9WADDplH3xkc/6cYzJVNDfgWOdSClp Iz5eZJLBSgN7l0uXU5QRDL8i0mq99NoSizj7Bs3NceXJmlxUbz/L9ocO/f2733wxF+CZ NVUAqWn7npnqp7MHuKZTvLkMBDG9q0k6pKqC5CD4H3pe9IpDI4q7quLGR19ihnmtI7Ls b0tRdEejNVrpuoG9g0kaKVv0ZXzOWi0D3h4CaKysJR3flhsGSrnRixz+Eb1LcDoTm8TL KK+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=a+MAAhyf; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z11si10345130pjn.72.2019.06.17.09.04.16; Mon, 17 Jun 2019 09:04:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=a+MAAhyf; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727980AbfFQQED (ORCPT + 99 others); Mon, 17 Jun 2019 12:04:03 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:40448 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727639AbfFQQEC (ORCPT ); Mon, 17 Jun 2019 12:04:02 -0400 Received: by mail-pg1-f196.google.com with SMTP id w10so1426677pgj.7; Mon, 17 Jun 2019 09:04:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PDuKbGKAhiAX1HMZyETnUi9VLoZ6KyS/hwRdrr3ylQk=; b=a+MAAhyfjvHogLAUFE/N6CI87NsA+TEUEAv9d+lIbWHvLFOERRZAWx/cFmJJRdAkjp +Jea4PCt1aQ4d32URH5eGPVBx2XNbLx5Wj4EYXqt66L2IjUfuj05c0kiIUVHcY2AnRyO V8SQFMUYr4jlwfsKsxrxHdacpXHEf54WPieevQBEgN3iNWVUVCJrR/I/C0biK7eMwQ5+ 0waS5kLgJwvCFhVHTUSqGp+uicvfuKdXM1cO8J7JXXmRoZCf9fQTpwgQ6CVvuXVWvvWa qi62MXkVCWIbBCDadlmiAGIKnQOqevU/hDqYI4nzQI5xJWJcnC2RfYZF50H38WS7Qjx7 Nrgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PDuKbGKAhiAX1HMZyETnUi9VLoZ6KyS/hwRdrr3ylQk=; b=j2FfpMT5EdHY2QqIvzYdwMZ3T6Pp080YDfnEBDlmn+P56qDSAlUXyreGGLXigom3qq U+vu1I2cpkAM0b/uPy/BHtnbK6h7qqoG9GFPoQ5R3MVr6WzNmRfPrtd68K4xkd3/8RPY bSEDZYm3ATpXkKlisSUKgzuw4WkeaTTVfomMvKGawSxUjHAudGU5rTwaJH8P1MMTlzMx ehqNzjWEbNb+Wymb4s140XXGdQl8xw4HFrsTbrqeeiM8/vJVlpmom713/GmQc51PS2CN tH0Qb+jkkyE5D2EdYonTtM3QTU1IDJG7KIghk+S8WfctzP7+M+LkZSZ5AQiymtjmkVUi 2krg== X-Gm-Message-State: APjAAAX9Jzq+OnuH2lHNaC8iXj4PWC32X2wS9nInMFhdx724FAAZ+0r+ zqr5FnXgvwGo2ZXByQ1+dlBteDzzUuQ= X-Received: by 2002:a62:8384:: with SMTP id h126mr17112337pfe.212.1560787441599; Mon, 17 Jun 2019 09:04:01 -0700 (PDT) Received: from localhost.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id d187sm12834073pfa.38.2019.06.17.09.04.00 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 17 Jun 2019 09:04:00 -0700 (PDT) From: Andrey Smirnov To: linux-crypto@vger.kernel.org Cc: Andrey Smirnov , Chris Spencer , Cory Tusar , Chris Healy , Lucas Stach , =?UTF-8?q?Horia=20Geant=C4=83?= , Aymen Sghaier , Leonard Crestez , linux-kernel@vger.kernel.org Subject: [PATCH v3 4/5] crypto: caam - simplfy clock initialization Date: Mon, 17 Jun 2019 09:03:38 -0700 Message-Id: <20190617160339.29179-5-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190617160339.29179-1-andrew.smirnov@gmail.com> References: <20190617160339.29179-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Simplify clock initialization code by converting it to use clk-bulk, devres and soc_device_match() match table. No functional change intended. Signed-off-by: Andrey Smirnov Cc: Chris Spencer Cc: Cory Tusar Cc: Chris Healy Cc: Lucas Stach Cc: Horia Geantă Cc: Aymen Sghaier Cc: Leonard Crestez Cc: linux-crypto@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/crypto/caam/ctrl.c | 214 +++++++++++++++++------------------ drivers/crypto/caam/intern.h | 5 - 2 files changed, 107 insertions(+), 112 deletions(-) diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c index e6e2457a573e..b9655957d369 100644 --- a/drivers/crypto/caam/ctrl.c +++ b/drivers/crypto/caam/ctrl.c @@ -25,16 +25,6 @@ EXPORT_SYMBOL(caam_dpaa2); #include "qi.h" #endif -/* - * i.MX targets tend to have clock control subsystems that can - * enable/disable clocking to our device. - */ -static inline struct clk *caam_drv_identify_clk(struct device *dev, - char *clk_name) -{ - return caam_imx ? devm_clk_get(dev, clk_name) : NULL; -} - /* * Descriptor to instantiate RNG State Handle 0 in normal mode and * load the JDKEK, TDKEK and TDSK registers @@ -347,13 +337,6 @@ static int caam_remove(struct platform_device *pdev) /* Unmap controller region */ iounmap(ctrl); - /* shut clocks off before finalizing shutdown */ - clk_disable_unprepare(ctrlpriv->caam_ipg); - if (ctrlpriv->caam_mem) - clk_disable_unprepare(ctrlpriv->caam_mem); - clk_disable_unprepare(ctrlpriv->caam_aclk); - if (ctrlpriv->caam_emi_slow) - clk_disable_unprepare(ctrlpriv->caam_emi_slow); return 0; } @@ -502,20 +485,113 @@ static const struct of_device_id caam_match[] = { }; MODULE_DEVICE_TABLE(of, caam_match); +struct clk_bulk_caam { + const struct clk_bulk_data *clks; + int num_clks; +}; + +static const struct clk_bulk_data caam_imx6_clks[] = { + { .id = "ipg" }, + { .id = "mem" }, + { .id = "aclk" }, + { .id = "emi_slow" }, +}; + +static const struct clk_bulk_caam caam_imx6_clk_data = { + .clks = caam_imx6_clks, + .num_clks = ARRAY_SIZE(caam_imx6_clks), +}; + +static const struct clk_bulk_data caam_imx7_clks[] = { + { .id = "ipg" }, + { .id = "aclk" }, +}; + +static const struct clk_bulk_caam caam_imx7_clk_data = { + .clks = caam_imx7_clks, + .num_clks = ARRAY_SIZE(caam_imx7_clks), +}; + +static const struct clk_bulk_data caam_imx6ul_clks[] = { + { .id = "ipg" }, + { .id = "mem" }, + { .id = "aclk" }, +}; + +static const struct clk_bulk_caam caam_imx6ul_clk_data = { + .clks = caam_imx6ul_clks, + .num_clks = ARRAY_SIZE(caam_imx6ul_clks), +}; + + +static const struct soc_device_attribute imx_soc[] = { + { .soc_id = "i.MX6UL", .data = &caam_imx6ul_clk_data }, + { .soc_id = "i.MX6*", .data = &caam_imx6_clk_data }, + { .soc_id = "i.MX7*", .data = &caam_imx7_clk_data }, + { .family = "Freescale i.MX" }, +}; + +static void disable_clocks(void *private) +{ + struct clk_bulk_caam *context = private; + + clk_bulk_disable_unprepare(context->num_clks, + (struct clk_bulk_data *)context->clks); +} + +static int init_clocks(struct device *dev, + const struct clk_bulk_caam *data) +{ + struct clk_bulk_data *clks; + struct clk_bulk_caam *context; + int num_clks; + int ret; + + num_clks = data->num_clks; + clks = devm_kmemdup(dev, data->clks, + data->num_clks * sizeof(data->clks[0]), + GFP_KERNEL); + if (!clks) + return -ENOMEM; + + ret = devm_clk_bulk_get(dev, num_clks, clks); + if (ret) { + dev_err(dev, + "Failed to request all necessary clocks\n"); + return ret; + } + + ret = clk_bulk_prepare_enable(num_clks, clks); + if (ret) { + dev_err(dev, + "Failed to prepare/enable all necessary clocks\n"); + return ret; + } + + context = devm_kzalloc(dev, sizeof(*context), GFP_KERNEL); + if (!context) + return -ENOMEM; + + context->num_clks = num_clks; + context->clks = clks; + + ret = devm_add_action_or_reset(dev, disable_clocks, context); + if (ret) + return ret; + + return 0; +} + /* Probe routine for CAAM top (controller) level */ static int caam_probe(struct platform_device *pdev) { int ret, ring, gen_sk, ent_delay = RTSDCTL_ENT_DLY_MIN; u64 caam_id; - static const struct soc_device_attribute imx_soc[] = { - {.family = "Freescale i.MX"}, - {}, - }; + const struct soc_device_attribute *soc_attr; struct device *dev; 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 @@ -532,91 +608,25 @@ static int caam_probe(struct platform_device *pdev) dev_set_drvdata(dev, ctrlpriv); nprop = pdev->dev.of_node; - caam_imx = (bool)soc_device_match(imx_soc); - - /* Enable clocking */ - clk = caam_drv_identify_clk(&pdev->dev, "ipg"); - if (IS_ERR(clk)) { - ret = PTR_ERR(clk); - dev_err(&pdev->dev, - "can't identify CAAM ipg clk: %d\n", ret); - return ret; - } - ctrlpriv->caam_ipg = clk; - - if (!of_machine_is_compatible("fsl,imx7d") && - !of_machine_is_compatible("fsl,imx7s") && - !of_machine_is_compatible("fsl,imx7ulp")) { - clk = caam_drv_identify_clk(&pdev->dev, "mem"); - if (IS_ERR(clk)) { - ret = PTR_ERR(clk); - dev_err(&pdev->dev, - "can't identify CAAM mem clk: %d\n", ret); - return ret; + soc_attr = soc_device_match(imx_soc); + if (soc_attr) { + if (!soc_attr->data) { + dev_err(dev, "No clock data provided for i.MX SoC"); + return -EINVAL; } - ctrlpriv->caam_mem = clk; - } - clk = caam_drv_identify_clk(&pdev->dev, "aclk"); - if (IS_ERR(clk)) { - ret = PTR_ERR(clk); - dev_err(&pdev->dev, - "can't identify CAAM aclk clk: %d\n", ret); - return ret; - } - ctrlpriv->caam_aclk = clk; - - if (!of_machine_is_compatible("fsl,imx6ul") && - !of_machine_is_compatible("fsl,imx7d") && - !of_machine_is_compatible("fsl,imx7s") && - !of_machine_is_compatible("fsl,imx7ulp")) { - clk = caam_drv_identify_clk(&pdev->dev, "emi_slow"); - if (IS_ERR(clk)) { - ret = PTR_ERR(clk); - dev_err(&pdev->dev, - "can't identify CAAM emi_slow clk: %d\n", ret); + ret = init_clocks(dev, soc_attr->data); + if (ret) return ret; - } - ctrlpriv->caam_emi_slow = clk; - } - - ret = clk_prepare_enable(ctrlpriv->caam_ipg); - if (ret < 0) { - dev_err(&pdev->dev, "can't enable CAAM ipg clock: %d\n", ret); - return ret; - } - - if (ctrlpriv->caam_mem) { - ret = clk_prepare_enable(ctrlpriv->caam_mem); - if (ret < 0) { - dev_err(&pdev->dev, "can't enable CAAM secure mem clock: %d\n", - ret); - goto disable_caam_ipg; - } - } - - ret = clk_prepare_enable(ctrlpriv->caam_aclk); - if (ret < 0) { - dev_err(&pdev->dev, "can't enable CAAM aclk clock: %d\n", ret); - goto disable_caam_mem; - } - - if (ctrlpriv->caam_emi_slow) { - ret = clk_prepare_enable(ctrlpriv->caam_emi_slow); - if (ret < 0) { - dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n", - ret); - goto disable_caam_aclk; - } } + caam_imx = (bool)soc_attr; /* Get configuration properties from device tree */ /* First, get register page */ ctrl = of_iomap(nprop, 0); if (ctrl == NULL) { dev_err(dev, "caam: of_iomap() failed\n"); - ret = -ENOMEM; - goto disable_caam_emi_slow; + return -ENOMEM; } caam_little_end = !(bool)(rd_reg32(&ctrl->perfmon.status) & @@ -904,16 +914,6 @@ static int caam_probe(struct platform_device *pdev) #endif iounmap_ctrl: iounmap(ctrl); -disable_caam_emi_slow: - if (ctrlpriv->caam_emi_slow) - clk_disable_unprepare(ctrlpriv->caam_emi_slow); -disable_caam_aclk: - clk_disable_unprepare(ctrlpriv->caam_aclk); -disable_caam_mem: - if (ctrlpriv->caam_mem) - clk_disable_unprepare(ctrlpriv->caam_mem); -disable_caam_ipg: - clk_disable_unprepare(ctrlpriv->caam_ipg); return ret; } diff --git a/drivers/crypto/caam/intern.h b/drivers/crypto/caam/intern.h index bf115f8ddb93..81f73d32a9f8 100644 --- a/drivers/crypto/caam/intern.h +++ b/drivers/crypto/caam/intern.h @@ -94,11 +94,6 @@ struct caam_drv_private { Handles of the RNG4 block are initialized by this driver */ - struct clk *caam_ipg; - struct clk *caam_mem; - struct clk *caam_aclk; - struct clk *caam_emi_slow; - /* * debugfs entries for developer view into driver/device * variables at runtime. -- 2.21.0