Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2221587imw; Wed, 6 Jul 2022 02:08:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sM5ahp+IKjMesjxyB4s6+sL0TEDYPq1sYgWflWtSbx2snFStX+SOQhoCVVRALgiDA/xJWH X-Received: by 2002:a17:907:75c1:b0:72a:430d:b512 with SMTP id jl1-20020a17090775c100b0072a430db512mr37037948ejc.146.1657098535559; Wed, 06 Jul 2022 02:08:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657098535; cv=none; d=google.com; s=arc-20160816; b=mVf8D79VP3+IRYo2NnvCaxDbHaxRO9xKMpjNsII6IiVO8uTPC2tQxM8i363tRD9CBM QgJW3oG4MS8AD5aREcJWTemKt29vJiA7LDrnl8phqhJ7vN7oeoohRFti/joQJI4kdM/u V+glictJWo7vr9uogOqa5awJR2BTJVb5oRLABYipBm0Rr2TqzBpwtQih34f+y5BbfrIh zKvx2SaM8SX4u1Htd5di95hRbU/SQZ+cEjDYaKHJvbSDeTHc8bTHnJ8xzlm+Rzon6BNn N6zE53SAkOK+ne9blCjdiC3U8o1MuG/ji7sr8fdOk7D3jq4z+GEaFnkohnbVTLPnXzzB WqkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ScW8Amy0Gr2Hkf7kzoiIS1O1Eux9N8ylUQeMnxBh6Sw=; b=Xz3sNqQGFaBtwHS+N2Fjv7pV5j38vIt7cHpa2yGg+kDo1I/gCKuYdaWSEzzP7pMOpR 0n+O06djCOVdmmAkQ6+OdHSh5HcaYYiye/kF4Jc/uE51J/IeI6v+eRNRhnHO5kXODp43 w3zjjJ8Fof+n3jZin40LHIzurpsQW9/5FL/YlpQkmZOGOHYmVaYY28izobSH/IOu+n9/ 0SKSufZVlr7B3tcsRbUIgWjVzonMbCIEeVpPZ4PS+s18ZgHEpDY+hC/UEdNjB+gHCINP AbHPSwExwkr2WpR3mAoSzEiPjXV/geWA/uHfoBGmYBLEas5cnNG5SmjWQphDDuDTbWMf RvIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=4A5yy9kQ; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bs1-20020a056402304100b0042e139a8248si18038189edb.311.2022.07.06.02.08.30; Wed, 06 Jul 2022 02:08:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=4A5yy9kQ; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232717AbiGFJHr (ORCPT + 99 others); Wed, 6 Jul 2022 05:07:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232825AbiGFJGf (ORCPT ); Wed, 6 Jul 2022 05:06:35 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 708842528B for ; Wed, 6 Jul 2022 02:05:04 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id v16so9616015wrd.13 for ; Wed, 06 Jul 2022 02:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ScW8Amy0Gr2Hkf7kzoiIS1O1Eux9N8ylUQeMnxBh6Sw=; b=4A5yy9kQGo4ERp7rY2PIggGhwgToU+H7F5Vixchm05HVmWIxMTCm23JSUWwZ4YrvrZ 4rLoYxOtsS5yOzF2LLnviYJiTkDqFM00MxCfLXDLimC+AT1C89H3VSjKftnxCnNU9f+Y ieNBQRYWjpG4TYMYyjmVYUdP1b8zGWiV/6AWO8XeoAap8O+x/aGhv3LsnZSnw6yGow0X FvKQ5d/0dSksvcaRkc+/8PA3wA4ibfYMcq5PXph5q0+ICVmb+jbae9VNDthaU0wces6f LUJmH0XnIiYmKMQ9NEJFrG9uAWSGWeoWvVN3SNlOUWBndCaNUtxjtlg5e1jiQVnJXNHO B+6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ScW8Amy0Gr2Hkf7kzoiIS1O1Eux9N8ylUQeMnxBh6Sw=; b=qMyTySc1qOpcYmo4mmgWu6ysakaLvc4InEsGmFMZxh3gJ6XxDvqlKKM0Fzq1yenOoH IKiZuMi+aNCwLpCjjXn10ZZTEIl/GxieH1wP+jupBN9Mz1qKV7SeIVL1tmY2DVyxhiep Nb57+Upvqkg3U+bKDyoerxj9rKkqmjj8NTyyMwjefN4gC2yGKU9ZONMH6QKUElDaMPv7 /QWQc+qTZuFB8TeJJrY60DyorhAQSwlr1HGCc1+jOjCgs7os7SbD96cazeuNQI4knT5d BOx1b38Xa0HMkc9RJ3YfGWyOq89Sf1j/MsChPjI32kjlqklLRIfH894Od2ZZSFfmvJRD +dRw== X-Gm-Message-State: AJIora+4e+LLXu3V1UcilRZzF79kiA51pjIRPP8q/Ykc68ZE1iEZ9KxG QzJLl2sdNI+0Sn693/TCZGYmlQ== X-Received: by 2002:adf:dc09:0:b0:218:5f6a:f5db with SMTP id t9-20020adfdc09000000b002185f6af5dbmr36469063wri.480.1657098304025; Wed, 06 Jul 2022 02:05:04 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id v11-20020adfe28b000000b0021d6ef34b2asm5230223wri.51.2022.07.06.02.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 02:05:03 -0700 (PDT) From: Corentin Labbe To: heiko@sntech.de, herbert@gondor.apana.org.au, krzysztof.kozlowski+dt@linaro.org, mturquette@baylibre.com, p.zabel@pengutronix.de, robh+dt@kernel.org, sboyd@kernel.org Cc: linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, john@metanate.com, didi.debian@cknow.org, Corentin Labbe Subject: [PATCH v8 30/33] crypto: rockchip: Check for clocks numbers and their frequencies Date: Wed, 6 Jul 2022 09:04:09 +0000 Message-Id: <20220706090412.806101-31-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220706090412.806101-1-clabbe@baylibre.com> References: <20220706090412.806101-1-clabbe@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add the number of clocks needed for each compatible. Rockchip's datasheet give maximum frequencies for some clocks, so add checks for verifying they are within limits. Let's start with rk3288 for clock frequency check, other will came later. Signed-off-by: Corentin Labbe --- drivers/crypto/rockchip/rk3288_crypto.c | 75 +++++++++++++++++++++---- drivers/crypto/rockchip/rk3288_crypto.h | 16 +++++- 2 files changed, 79 insertions(+), 12 deletions(-) diff --git a/drivers/crypto/rockchip/rk3288_crypto.c b/drivers/crypto/rockchip/rk3288_crypto.c index c92559b83f7d..232dc625d6e5 100644 --- a/drivers/crypto/rockchip/rk3288_crypto.c +++ b/drivers/crypto/rockchip/rk3288_crypto.c @@ -14,10 +14,58 @@ #include #include #include +#include #include #include #include +static const struct rk_variant rk3288_variant = { + .num_clks = 4, + .rkclks = { + { "sclk", 150000000}, + } +}; + +static const struct rk_variant rk3328_variant = { + .num_clks = 3, +}; + +static int rk_crypto_get_clks(struct rk_crypto_info *dev) +{ + int i, j, err; + unsigned long cr; + + dev->num_clks = devm_clk_bulk_get_all(dev->dev, &dev->clks); + if (dev->num_clks < dev->variant->num_clks) { + dev_err(dev->dev, "Missing clocks, got %d instead of %d\n", + dev->num_clks, dev->variant->num_clks); + return -EINVAL; + } + + for (i = 0; i < dev->num_clks; i++) { + cr = clk_get_rate(dev->clks[i].clk); + for (j = 0; j < ARRAY_SIZE(dev->variant->rkclks); j++) { + if (dev->variant->rkclks[j].max == 0) + continue; + if (strcmp(dev->variant->rkclks[j].name, dev->clks[i].id)) + continue; + if (cr > dev->variant->rkclks[j].max) { + err = clk_set_rate(dev->clks[i].clk, + dev->variant->rkclks[j].max); + if (err) + dev_err(dev->dev, "Fail downclocking %s from %lu to %lu\n", + dev->variant->rkclks[j].name, cr, + dev->variant->rkclks[j].max); + else + dev_info(dev->dev, "Downclocking %s from %lu to %lu\n", + dev->variant->rkclks[j].name, cr, + dev->variant->rkclks[j].max); + } + } + } + return 0; +} + static int rk_crypto_enable_clk(struct rk_crypto_info *dev) { int err; @@ -201,8 +249,12 @@ static void rk_crypto_unregister(void) } static const struct of_device_id crypto_of_id_table[] = { - { .compatible = "rockchip,rk3288-crypto" }, - { .compatible = "rockchip,rk3328-crypto" }, + { .compatible = "rockchip,rk3288-crypto", + .data = &rk3288_variant, + }, + { .compatible = "rockchip,rk3328-crypto", + .data = &rk3328_variant, + }, {} }; MODULE_DEVICE_TABLE(of, crypto_of_id_table); @@ -220,6 +272,15 @@ static int rk_crypto_probe(struct platform_device *pdev) goto err_crypto; } + crypto_info->dev = &pdev->dev; + platform_set_drvdata(pdev, crypto_info); + + crypto_info->variant = of_device_get_match_data(&pdev->dev); + if (!crypto_info->variant) { + dev_err(&pdev->dev, "Missing variant\n"); + return -EINVAL; + } + crypto_info->rst = devm_reset_control_get(dev, "crypto-rst"); if (IS_ERR(crypto_info->rst)) { err = PTR_ERR(crypto_info->rst); @@ -236,12 +297,9 @@ static int rk_crypto_probe(struct platform_device *pdev) goto err_crypto; } - crypto_info->num_clks = devm_clk_bulk_get_all(&pdev->dev, - &crypto_info->clks); - if (crypto_info->num_clks < 3) { - err = -EINVAL; + err = rk_crypto_get_clks(crypto_info); + if (err) goto err_crypto; - } crypto_info->irq = platform_get_irq(pdev, 0); if (crypto_info->irq < 0) { @@ -259,9 +317,6 @@ static int rk_crypto_probe(struct platform_device *pdev) goto err_crypto; } - crypto_info->dev = &pdev->dev; - platform_set_drvdata(pdev, crypto_info); - crypto_info->engine = crypto_engine_alloc_init(&pdev->dev, true); crypto_engine_start(crypto_info->engine); init_completion(&crypto_info->complete); diff --git a/drivers/crypto/rockchip/rk3288_crypto.h b/drivers/crypto/rockchip/rk3288_crypto.h index ff9fc25972eb..ac979d67ced9 100644 --- a/drivers/crypto/rockchip/rk3288_crypto.h +++ b/drivers/crypto/rockchip/rk3288_crypto.h @@ -188,14 +188,26 @@ #define CRYPTO_WRITE(dev, offset, val) \ writel_relaxed((val), ((dev)->reg + (offset))) +#define RK_MAX_CLKS 4 + +struct rk_clks { + const char *name; + unsigned long max; +}; + +struct rk_variant { + int num_clks; + struct rk_clks rkclks[RK_MAX_CLKS]; +}; + struct rk_crypto_info { struct device *dev; struct clk_bulk_data *clks; - int num_clks; + int num_clks; struct reset_control *rst; void __iomem *reg; int irq; - + const struct rk_variant *variant; struct crypto_engine *engine; struct completion complete; int status; -- 2.35.1