From patchwork Thu Aug 10 19:22:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 13349863 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADDE5C001B0 for ; Thu, 10 Aug 2023 19:22:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234588AbjHJTWW (ORCPT ); Thu, 10 Aug 2023 15:22:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230197AbjHJTWV (ORCPT ); Thu, 10 Aug 2023 15:22:21 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 316EC10D for ; Thu, 10 Aug 2023 12:22:21 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id d75a77b69052e-40f0b412b78so8332151cf.3 for ; Thu, 10 Aug 2023 12:22:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1691695340; x=1692300140; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=CEgLtKuZwL6z4gMGiYUex40eoJKuCviIGVM4TzgBw+Q=; b=hRYe559BzdawyxK0woPTsIRUib35qhmehjQOWXjrB/FV/GpyMCcj1+Ks/NLX6MXLbG PuBQYjy6DHPZafQTuqIaitMhYyhm5Axzz/aTXUYATlqr1lpUkYI8sANhf/xccrH27Tfp /BHle5loyLOk3qAwHV01YyXB2QBkQO/6QbGSQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691695340; x=1692300140; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=CEgLtKuZwL6z4gMGiYUex40eoJKuCviIGVM4TzgBw+Q=; b=HQSablJUlJyok6CTy78GnJh4L8SzPnyJNxVhYyXdgY12fBr2XJpwop5Md6DPwutNBo +06qokI22Td1UKklorvLq03pt7wW6IzZSIWGrxFwaCNON9SHDDyCkf/sqzH49iQlUDwO knmOZtiYbn6CsAP6r+Qk+7EYNzQ3ntKZtaVZYCXuvt7Nu6Bol2dy62VJLjj6ggbn8jqy 7wmmzvHaK5HtGRP1uafU2QmK1mtwYlTWpCMesY6LrfqzWnvAj0IgGn8VJgFlNp/dLP82 CUtquc9NDe6D4hmCOkJ1mC8IRhWA4DkK1oyZvMUuHd8jiX6b4xffmSEEsqmR/R4ijgda PU/w== X-Gm-Message-State: AOJu0Yw14ZkLYGRHZMckTYzPuY/GQPj9GZPA0+Eg05s37NUy5Ww20k/x aQujee+0mkAv3cnBsOBW3nu+FA== X-Google-Smtp-Source: AGHT+IGEO1XfWCPP57s8DrZcRExhCymacAoXn0010yPOwVnSGaZXOb61YS6MN+HNqMXFhiXDWw45/A== X-Received: by 2002:a05:622a:94:b0:403:6ac5:e761 with SMTP id o20-20020a05622a009400b004036ac5e761mr5084457qtw.62.1691695340258; Thu, 10 Aug 2023 12:22:20 -0700 (PDT) Received: from fainelli-desktop.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id jx11-20020a05622a810b00b0040f8ac751a5sm686701qtb.96.2023.08.10.12.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 12:22:19 -0700 (PDT) From: Florian Fainelli To: linux-kernel@vger.kernel.org Cc: Florian Fainelli , Olivia Mackall , Herbert Xu , Ray Jui , Scott Branden , Broadcom internal kernel review list , linux-crypto@vger.kernel.org (open list:HARDWARE RANDOM NUMBER GENERATOR CORE), linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM IPROC ARM ARCHITECTURE) Subject: [PATCH] hwrng: iproc-rng200: Implement suspend and resume calls Date: Thu, 10 Aug 2023 12:22:08 -0700 Message-Id: <20230810192209.2611558-1-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Chips such as BCM7278 support system wide suspend/resume which will cause the HWRNG block to lose its state and reset to its power on reset register values. We need to cleanup and re-initialize the HWRNG for it to be functional coming out of a system suspend cycle. Fixes: c3577f6100ca ("hwrng: iproc-rng200 - Add support for BCM7278") Signed-off-by: Florian Fainelli --- drivers/char/hw_random/iproc-rng200.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/char/hw_random/iproc-rng200.c b/drivers/char/hw_random/iproc-rng200.c index 06bc060534d8..c0df053cbe4b 100644 --- a/drivers/char/hw_random/iproc-rng200.c +++ b/drivers/char/hw_random/iproc-rng200.c @@ -182,6 +182,8 @@ static int iproc_rng200_probe(struct platform_device *pdev) return PTR_ERR(priv->base); } + dev_set_drvdata(dev, priv); + priv->rng.name = "iproc-rng200"; priv->rng.read = iproc_rng200_read; priv->rng.init = iproc_rng200_init; @@ -199,6 +201,28 @@ static int iproc_rng200_probe(struct platform_device *pdev) return 0; } +static int __maybe_unused iproc_rng200_suspend(struct device *dev) +{ + struct iproc_rng200_dev *priv = dev_get_drvdata(dev); + + iproc_rng200_cleanup(&priv->rng); + + return 0; +} + +static int __maybe_unused iproc_rng200_resume(struct device *dev) +{ + struct iproc_rng200_dev *priv = dev_get_drvdata(dev); + + iproc_rng200_init(&priv->rng); + + return 0; +} + +static const struct dev_pm_ops iproc_rng200_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(iproc_rng200_suspend, iproc_rng200_resume) +}; + static const struct of_device_id iproc_rng200_of_match[] = { { .compatible = "brcm,bcm2711-rng200", }, { .compatible = "brcm,bcm7211-rng200", }, @@ -212,6 +236,7 @@ static struct platform_driver iproc_rng200_driver = { .driver = { .name = "iproc-rng200", .of_match_table = iproc_rng200_of_match, + .pm = &iproc_rng200_pm_ops, }, .probe = iproc_rng200_probe, };