From patchwork Mon Oct 19 04:37:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 7432951 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DEF69BEEA4 for ; Mon, 19 Oct 2015 04:40:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0A0692074E for ; Mon, 19 Oct 2015 04:40:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E043E20741 for ; Mon, 19 Oct 2015 04:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752671AbbJSEiq (ORCPT ); Mon, 19 Oct 2015 00:38:46 -0400 Received: from mailout4.w1.samsung.com ([210.118.77.14]:33614 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752395AbbJSEiE (ORCPT ); Mon, 19 Oct 2015 00:38:04 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NWG009PUA7ET450@mailout4.w1.samsung.com>; Mon, 19 Oct 2015 05:38:02 +0100 (BST) X-AuditID: cbfec7f5-f794b6d000001495-d6-562473aacd9b Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 1A.D3.05269.AA374265; Mon, 19 Oct 2015 05:38:02 +0100 (BST) Received: from localhost.localdomain ([10.252.80.64]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NWG00GZTA6Y7Q50@eusync3.samsung.com>; Mon, 19 Oct 2015 05:38:02 +0100 (BST) From: Krzysztof Kozlowski To: Kukjin Kim , Krzysztof Kozlowski , Matt Mackall , Herbert Xu , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org Cc: Heiner Kallweit Subject: [PATCH 3/4] hwrng: exynos - Fix missing configuration after suspend to RAM Date: Mon, 19 Oct 2015 13:37:41 +0900 Message-id: <1445229462-32395-4-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1445229462-32395-1-git-send-email-k.kozlowski@samsung.com> References: <1445229462-32395-1-git-send-email-k.kozlowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJLMWRmVeSWpSXmKPExsVy+t/xq7qrilXCDA5uEbaYf+Qcq0X3KxmL Re9nsFq8fmFo0f/4NbPFpsfXWC3u3/vJZHF51xw2ixnn9zFZLNjWx+jA5bFz1l12j20HVD02 repk89i8pN6jb8sqRo++lxsYPT5vkgtgj+KySUnNySxLLdK3S+DKmHGkmaVgjWjF9KMrGRsY bwl2MXJySAiYSCy9+J0VwhaTuHBvPVsXIxeHkMBSRolp874wQzj/GSV2HW9iAqliEzCW2Lx8 CViViMBhJolt8w6zgCSYBbQkHn2eAjSKg0NYIFTi+I4okDCLgKrEtZuPwXp5Bdwlmv//YIfY Jidx8thksM2cAh4SM3uPsIHYQkA1d5f8ZZ7AyLuAkWEVo2hqaXJBcVJ6rpFecWJucWleul5y fu4mRkgAft3BuPSY1SFGAQ5GJR7eB0eUwoRYE8uKK3MPMUpwMCuJ8GYfVg4T4k1JrKxKLcqP LyrNSS0+xCjNwaIkzjtz1/sQIYH0xJLU7NTUgtQimCwTB6dUA+O+ApOjufsfv/5RZ9rYMP/7 woDGhVujEvxO/330um9Z2ZeLVuy31zHE/lJsW/l18e4Qg+lr102xZ3Q2uvthQpjEVo+gonL5 x4s+/t/vbn/hiGCNcHXZlxUfz4tv4k7XSHZdfvd85cJm4ZrCKaV8Llc+JiqdOfiic+tf/k9O cQzMMXMeHOZIsHZVYinOSDTUYi4qTgQAxhMR3DwCAAA= Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After suspend to RAM the device stopped to work with ETIMEDOUT error: $ dd if=/dev/hwrng of=/dev/null bs=1 count=16 dd: reading `/dev/hwrng': Connection timed out In the STATUS register the bits #5 (PRNG_DONE) and #1 (SEED_SETTING_DONE) were not set. Instead PRNG_ERROR (seventh bit) was high. After each system suspend initialize the seed to fix the error. Signed-off-by: Krzysztof Kozlowski --- drivers/char/hw_random/exynos-rng.c | 42 ++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/drivers/char/hw_random/exynos-rng.c b/drivers/char/hw_random/exynos-rng.c index dfaaaafb8ddd..162adbda1b70 100644 --- a/drivers/char/hw_random/exynos-rng.c +++ b/drivers/char/hw_random/exynos-rng.c @@ -53,15 +53,11 @@ static void exynos_rng_writel(struct exynos_rng *rng, u32 val, u32 offset) __raw_writel(val, rng->mem + offset); } -static int exynos_init(struct hwrng *rng) +static int exynos_rng_configure(struct exynos_rng *exynos_rng) { - struct exynos_rng *exynos_rng = container_of(rng, - struct exynos_rng, rng); int i; int ret = 0; - pm_runtime_get_sync(exynos_rng->dev); - for (i = 0 ; i < 5 ; i++) exynos_rng_writel(exynos_rng, jiffies, EXYNOS_PRNG_SEED_OFFSET + 4*i); @@ -70,6 +66,17 @@ static int exynos_init(struct hwrng *rng) & SEED_SETTING_DONE)) ret = -EIO; + return ret; +} + +static int exynos_init(struct hwrng *rng) +{ + struct exynos_rng *exynos_rng = container_of(rng, + struct exynos_rng, rng); + int ret = 0; + + pm_runtime_get_sync(exynos_rng->dev); + ret = exynos_rng_configure(exynos_rng); pm_runtime_put_noidle(exynos_rng->dev); return ret; @@ -155,10 +162,31 @@ static int exynos_rng_runtime_resume(struct device *dev) return clk_prepare_enable(exynos_rng->clk); } + +static int exynos_rng_suspend(struct device *dev) +{ + return pm_runtime_force_suspend(dev); +} + +static int exynos_rng_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct exynos_rng *exynos_rng = platform_get_drvdata(pdev); + int ret; + + ret = pm_runtime_force_resume(dev); + if (ret) + return ret; + + return exynos_rng_configure(exynos_rng); +} #endif -static UNIVERSAL_DEV_PM_OPS(exynos_rng_pm_ops, exynos_rng_runtime_suspend, - exynos_rng_runtime_resume, NULL); +static const struct dev_pm_ops exynos_rng_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(exynos_rng_suspend, exynos_rng_resume) + SET_RUNTIME_PM_OPS(exynos_rng_runtime_suspend, + exynos_rng_runtime_resume, NULL) +}; static struct platform_driver exynos_rng_driver = { .driver = {