Received: by 2002:a19:651b:0:0:0:0:0 with SMTP id z27csp3654558lfb; Mon, 9 May 2022 00:55:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwQ8cZQimBBMeCkcnned4JFE1GamLkolNJyo5sT7Fjspgn9fSS7dbMQSLBPv9hyY3EtlNM X-Received: by 2002:a17:902:c7cb:b0:15e:e0d0:c020 with SMTP id r11-20020a170902c7cb00b0015ee0d0c020mr15592607pla.51.1652082915073; Mon, 09 May 2022 00:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652082915; cv=none; d=google.com; s=arc-20160816; b=roinS7B9cKevqGKngPT4UFZd+quQkfdQdmQAzHOptn/18hm0ZRf9s87j6pmsG8iad9 LQ0FEbCVXy8CMDoWbvt3e7zPFN2jJZh86bsjbeokcmaXyZ+hYwweniSyWEmZDXKHnEPy g8crToT2V3lPGMLolMbmpdl/2S0WH+3lb7yNi6WepRfnPU1YjpMxCZRGSRsrPZEmmtZ/ ObGdDiwDLgSSu6qvLCRlfYwdjx7NrZ98Kt2CISbh0c2HeR067HrC5A+e1ZGYRvUnizNJ mPcsBJRh5WJ9hmDsMqPyhboSzZs3gpoTE1b8TY1Fn9OAUt54J1QXyT1sHMsVt4wkFiTZ 67Ig== 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=5M1EQ6WsDJDi9glkqW5UPCpOuBDX/AR7k6YyL2ZeXO8=; b=ZH8tw0dDbJzKjccwndfb42uThnVghDvvlqsS18UA8py1/Ke7xttqO/0YKhbi+k6e+M ULQX3SrD8zJt/Wf14LITZ9zY4oVcDWabjPS/WEerG0g2PncjSC/hR4QkKQ4BEdoOpAOy pwJ7Yu5FDS7JD82sHYA+TPfb9ez+dokV/AKOiKb39jstU+a8cA79KTpBDjECgvVXxDHA z/4EVefEeHWQO/Nt++K9LfUK91NdO95RWUQDFjFKd4RmDcYB6kbT1yEtwXRJqylOx/2F vRN+YrZ8MSUH9tMZyXRGv214zfZOb9X+JAgxwCtd0/70UwUvRm01xtEaxTiN6WqpCTOv UMAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=NaUL1fJ9; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x10-20020aa78f0a000000b004fa687c28d4si12913629pfr.86.2022.05.09.00.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 00:55:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=NaUL1fJ9; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3046F1BF1A1; Mon, 9 May 2022 00:47:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230515AbiEHTWj (ORCPT + 99 others); Sun, 8 May 2022 15:22:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237918AbiEHTEl (ORCPT ); Sun, 8 May 2022 15:04:41 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D512BE31 for ; Sun, 8 May 2022 12:00:37 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id e2so16704481wrh.7 for ; Sun, 08 May 2022 12:00:37 -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=5M1EQ6WsDJDi9glkqW5UPCpOuBDX/AR7k6YyL2ZeXO8=; b=NaUL1fJ9dNzuI5Jf455221FYwiHqJbSrUg6Cr8H7njK5wQ1shzFvd4O7NaWTnoRybo +dSY4b6MiPf7kjrtO9BYRvX1xwu726mSLBscd7CEPqHzTC4+3Z/rfTa4iqtLpzhBupTu 1j7NHx1IqVLNSi5+mTgWZt42qw2JS5Q1sZIVnTUzkKHN5U8zZ4MNqlJuSwT6t55wQ4Cn OGoNia1V6EuqZRBJgxvFvbUM9gRTWJ1fcitSo/Ev4ohwZwrJcFnwc7uRRVmgEF2Y5kC8 T21l4yQZ0CDf4MGMaEO8y3ZPnDBAMrGkldh9KXlgWMG/5DIpYF+TwcjvR7A19tc+g7yG ceTw== 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=5M1EQ6WsDJDi9glkqW5UPCpOuBDX/AR7k6YyL2ZeXO8=; b=i03g4xEXHk15n14/Dhlz7dD0tXANQWF/+AtSJWObKqBPe1u5zMQYKuoC9OmROdo/Pt v196rvPf985rmJsR7LZJGqQbeEFeLg9J+pF2KY3tiGKn6p8aTzU/DTnWrAp9PWiZiqq9 K97EnImlyk1s77qFzuuSLPBZ2wNcIDgmU2dS5UMamskrWnlcHw3vfR2s3AUvg2zJEkZ6 ML3dnkCKocPmvEJDOr26mtVx9/WyHmk+RldZLbhRLE1tvKHjOLBUnB9RtPIcm0xWp4TZ i7mPWwi5j6o/EbKH5QRLC6xZdHRMR1L3CqnXESV5s/GcZmbaV59jGhvTKxfgJRQ10nJl +OQw== X-Gm-Message-State: AOAM531GAsmXurpZT2in0QfIRhOvxolrCAHgwieWqUhKvOMPrK7JCkzQ 9AzAulj+Pku60DtyZK2dq6RfOg== X-Received: by 2002:a05:6000:12d1:b0:20a:d901:3828 with SMTP id l17-20020a05600012d100b0020ad9013828mr10663209wrx.313.1652036436834; Sun, 08 May 2022 12:00:36 -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 n16-20020a05600c3b9000b00394699f803dsm10552348wms.46.2022.05.08.12.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 12:00:36 -0700 (PDT) From: Corentin Labbe To: heiko@sntech.de, ardb@kernel.org, herbert@gondor.apana.org.au, krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Corentin Labbe Subject: [PATCH v7 30/33] crypto: rockchip: Check for clocks numbers and their frequencies Date: Sun, 8 May 2022 18:59:54 +0000 Message-Id: <20220508185957.3629088-31-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220508185957.3629088-1-clabbe@baylibre.com> References: <20220508185957.3629088-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,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 6147ce44f757..d6d78b8af57c 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; @@ -196,8 +244,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); @@ -215,6 +267,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); @@ -227,12 +288,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) { @@ -250,9 +308,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