From patchwork Fri Feb 18 10:17:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 543833 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 335CAC433EF for ; Fri, 18 Feb 2022 10:16:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233969AbiBRKQ1 (ORCPT ); Fri, 18 Feb 2022 05:16:27 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232891AbiBRKQ0 (ORCPT ); Fri, 18 Feb 2022 05:16:26 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C41B2AEDA6; Fri, 18 Feb 2022 02:16:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1645179370; x=1676715370; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bqtRma4i+aDRPSPwCrS3g3crpowmv6qvyEHjsN3/F0U=; b=yJAV02lK2Vhh7mjjy/gW5NR0OknWC/ud4GPBDGyrJi86hUHx1/mhBX7+ 0WsvpxuE/sziWptxb5NQ6OJEhbEsBUci8qlZ5e4+//rcw9GJHppKVzatA uLXmSua7m3qnAaankw0viUDQv/lrXN3DBYU1ilvFv5RR2MQRdblp+xke9 EtQ0cSQZVI5fhgzVQJjWrIp8/ogDALE+JyxKBu3FNDzxzhzidvxAO4qHE Fo5HE3VEzoEu10+PzDq7cTwQzK2GIVq5qw4CEOeQmXJI3Q8CxCJO6JprB i3meUACvJ9WgwAt7g2VwqEgrQn0TIk+v7NqmfWPxDNfyZ4ocol9BuOWiy Q==; X-IronPort-AV: E=Sophos;i="5.88,378,1635231600"; d="scan'208";a="149200659" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 18 Feb 2022 03:16:09 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Fri, 18 Feb 2022 03:16:09 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Fri, 18 Feb 2022 03:16:06 -0700 From: Claudiu Beznea To: , , , , CC: , , Claudiu Beznea Subject: [PATCH 1/7] hwrng: atmel - add wait for ready support on read Date: Fri, 18 Feb 2022 12:17:06 +0200 Message-ID: <20220218101712.530576-2-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220218101712.530576-1-claudiu.beznea@microchip.com> References: <20220218101712.530576-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add wait for ready support on read. Signed-off-by: Claudiu Beznea --- drivers/char/hw_random/atmel-rng.c | 43 +++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c index ecb71c4317a5..1a4874668c04 100644 --- a/drivers/char/hw_random/atmel-rng.c +++ b/drivers/char/hw_random/atmel-rng.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,7 @@ #define TRNG_CR 0x00 #define TRNG_MR 0x04 #define TRNG_ISR 0x1c +#define TRNG_ISR_DATRDY BIT(0) #define TRNG_ODATA 0x50 #define TRNG_KEY 0x524e4700 /* RNG */ @@ -36,25 +38,40 @@ struct atmel_trng { struct hwrng rng; }; +static bool atmel_trng_wait_ready(struct atmel_trng *trng, bool wait) +{ + int ready; + + ready = readl(trng->base + TRNG_ISR) & TRNG_ISR_DATRDY; + if (!ready && wait) + readl_poll_timeout(trng->base + TRNG_ISR, ready, + ready & TRNG_ISR_DATRDY, 1000, 20000); + + return !!ready; +} + static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max, bool wait) { struct atmel_trng *trng = container_of(rng, struct atmel_trng, rng); u32 *data = buf; + int ret; + + ret = atmel_trng_wait_ready(trng, wait); + if (!ret) + goto out; - /* data ready? */ - if (readl(trng->base + TRNG_ISR) & 1) { - *data = readl(trng->base + TRNG_ODATA); - /* - ensure data ready is only set again AFTER the next data - word is ready in case it got set between checking ISR - and reading ODATA, so we don't risk re-reading the - same word - */ - readl(trng->base + TRNG_ISR); - return 4; - } else - return 0; + *data = readl(trng->base + TRNG_ODATA); + /* + * ensure data ready is only set again AFTER the next data word is ready + * in case it got set between checking ISR and reading ODATA, so we + * don't risk re-reading the same word + */ + readl(trng->base + TRNG_ISR); + ret = 4; + +out: + return ret; } static void atmel_trng_enable(struct atmel_trng *trng) From patchwork Fri Feb 18 10:17:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 543832 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 90D94C433EF for ; Fri, 18 Feb 2022 10:16:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234024AbiBRKQi (ORCPT ); Fri, 18 Feb 2022 05:16:38 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233998AbiBRKQh (ORCPT ); Fri, 18 Feb 2022 05:16:37 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60FB42AF90F; Fri, 18 Feb 2022 02:16:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1645179375; x=1676715375; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jsWxgS54TLuyrZok7rycmGN8GjwhZu+4iH1IkWMXxMw=; b=gp39X1Kq4bcycgGOZBeXGzBliLJnmD0k1ixLokYSZ7xqSg5VMCLEKIDo cJ9h+0KKMmhublZrUjo4IaCsT3bRw3vPTb7DLD9XaHB5/XgDhcc7LX/+I cE+uFpm9FQ6pZ3aaECUmFooEEBdnN3J0/nt3t3uFjJ7hwu2VMBmQXFZF+ h4Aup1/G5BNcHpx8GXy/PF/l6UZxh3vvVH7jPBeDN4uracG0yq9hdzWa8 yFE3WTEn8/6CELaeC66JkqsMK6CUbbn7a51EY4T0DZio4/6+sdxhmd0wR CsyAICcWU2dOBasWLGRaSipSZ7F0RACBa6V8KFWtn967Wre0ejVpAoQlr w==; X-IronPort-AV: E=Sophos;i="5.88,378,1635231600"; d="scan'208";a="162767779" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 18 Feb 2022 03:16:14 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Fri, 18 Feb 2022 03:16:14 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Fri, 18 Feb 2022 03:16:12 -0700 From: Claudiu Beznea To: , , , , CC: , , Claudiu Beznea Subject: [PATCH 3/7] hwrnd: atmel - rename enable/disable functions to init/cleanup Date: Fri, 18 Feb 2022 12:17:08 +0200 Message-ID: <20220218101712.530576-4-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220218101712.530576-1-claudiu.beznea@microchip.com> References: <20220218101712.530576-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org s/atmel_trng_disable/atmel_trng_cleanup/g and s/atmel_trng_enable/atmel_trng_init/g to cope with struct hwrng::{init, cleanup} members. Signed-off-by: Claudiu Beznea --- drivers/char/hw_random/atmel-rng.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c index b7ef951927fb..17f02049c112 100644 --- a/drivers/char/hw_random/atmel-rng.c +++ b/drivers/char/hw_random/atmel-rng.c @@ -74,12 +74,12 @@ static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max, return ret; } -static void atmel_trng_enable(struct atmel_trng *trng) +static void atmel_trng_init(struct atmel_trng *trng) { writel(TRNG_KEY | 1, trng->base + TRNG_CR); } -static void atmel_trng_disable(struct atmel_trng *trng) +static void atmel_trng_cleanup(struct atmel_trng *trng) { writel(TRNG_KEY, trng->base + TRNG_CR); } @@ -117,7 +117,7 @@ static int atmel_trng_probe(struct platform_device *pdev) if (ret) return ret; - atmel_trng_enable(trng); + atmel_trng_init(trng); trng->rng.name = pdev->name; trng->rng.read = atmel_trng_read; @@ -131,7 +131,7 @@ static int atmel_trng_probe(struct platform_device *pdev) err_register: clk_disable_unprepare(trng->clk); - atmel_trng_disable(trng); + atmel_trng_cleanup(trng); return ret; } @@ -140,7 +140,7 @@ static int atmel_trng_remove(struct platform_device *pdev) struct atmel_trng *trng = platform_get_drvdata(pdev); - atmel_trng_disable(trng); + atmel_trng_cleanup(trng); clk_disable_unprepare(trng->clk); return 0; @@ -151,7 +151,7 @@ static int atmel_trng_suspend(struct device *dev) { struct atmel_trng *trng = dev_get_drvdata(dev); - atmel_trng_disable(trng); + atmel_trng_cleanup(trng); clk_disable_unprepare(trng->clk); return 0; @@ -166,7 +166,7 @@ static int atmel_trng_resume(struct device *dev) if (ret) return ret; - atmel_trng_enable(trng); + atmel_trng_init(trng); return 0; } From patchwork Fri Feb 18 10:17:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 543831 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 2CF2BC4332F for ; Fri, 18 Feb 2022 10:16:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232790AbiBRKQj (ORCPT ); Fri, 18 Feb 2022 05:16:39 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233997AbiBRKQi (ORCPT ); Fri, 18 Feb 2022 05:16:38 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B99D02B0481; Fri, 18 Feb 2022 02:16:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1645179381; x=1676715381; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NZ+azJ3C6NsQmXfKrlNJXfCNh4CtclKSN1p9C0K3pXE=; b=bCrWc8IJYzhLV3LvTdJcc+F3H+tjFkEaXKfpDa2mpo0PFjHPbcFiSGgR +38/l/buROo1lxz2fRZN0JwUC8gPooKFkXKU30hYMTndPNFKbIPlwx0kP 451X2rcJC8MdFxadjC7hnCnBkrndNpPfuga+c/eFAkSHSZ+ghSWuXN/Zk NvnpAVy3MpY+YTFC1CjLRdW51SkC0N2gCs2dlqgwJfuDvmYhYTDsMuVpe 6YVwQQnC0xo7kNfhl99dWI8dPnykQa10CW3yzZu7HGmNbXebcW3TGWqct RsTT6RMrqvphbTAoZKJPInFPuhiMkh9/qQbH9dhsfGBiX4Qip/mhh9nra w==; X-IronPort-AV: E=Sophos;i="5.88,378,1635231600"; d="scan'208";a="146491137" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 18 Feb 2022 03:16:21 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Fri, 18 Feb 2022 03:16:19 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Fri, 18 Feb 2022 03:16:17 -0700 From: Claudiu Beznea To: , , , , CC: , , Claudiu Beznea Subject: [PATCH 5/7] hwrnd: atmel - use __maybe_unused and pm_ptr() for pm ops Date: Fri, 18 Feb 2022 12:17:10 +0200 Message-ID: <20220218101712.530576-6-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220218101712.530576-1-claudiu.beznea@microchip.com> References: <20220218101712.530576-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Use __maybe_unused and pm_ptr() for pm ops. Signed-off-by: Claudiu Beznea --- drivers/char/hw_random/atmel-rng.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c index ef49dbe681cf..0fff74808472 100644 --- a/drivers/char/hw_random/atmel-rng.c +++ b/drivers/char/hw_random/atmel-rng.c @@ -155,8 +155,7 @@ static int atmel_trng_remove(struct platform_device *pdev) return 0; } -#ifdef CONFIG_PM -static int atmel_trng_suspend(struct device *dev) +static int __maybe_unused atmel_trng_suspend(struct device *dev) { struct atmel_trng *trng = dev_get_drvdata(dev); @@ -165,18 +164,17 @@ static int atmel_trng_suspend(struct device *dev) return 0; } -static int atmel_trng_resume(struct device *dev) +static int __maybe_unused atmel_trng_resume(struct device *dev) { struct atmel_trng *trng = dev_get_drvdata(dev); return atmel_trng_init(trng); } -static const struct dev_pm_ops atmel_trng_pm_ops = { +static const struct dev_pm_ops __maybe_unused atmel_trng_pm_ops = { .suspend = atmel_trng_suspend, .resume = atmel_trng_resume, }; -#endif /* CONFIG_PM */ static const struct atmel_trng_data at91sam9g45_config = { .has_half_rate = false, @@ -204,9 +202,7 @@ static struct platform_driver atmel_trng_driver = { .remove = atmel_trng_remove, .driver = { .name = "atmel-trng", -#ifdef CONFIG_PM - .pm = &atmel_trng_pm_ops, -#endif /* CONFIG_PM */ + .pm = pm_ptr(&atmel_trng_pm_ops), .of_match_table = atmel_trng_dt_ids, }, }; From patchwork Fri Feb 18 10:17:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 543830 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 CD19BC433F5 for ; Fri, 18 Feb 2022 10:16:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234015AbiBRKQm (ORCPT ); Fri, 18 Feb 2022 05:16:42 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:52144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233992AbiBRKQj (ORCPT ); Fri, 18 Feb 2022 05:16:39 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25A272AF3D1; Fri, 18 Feb 2022 02:16:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1645179384; x=1676715384; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hXm0Jtwri1nLMNu8938lMqvk/Ro4GDt9J9rutPzfAFk=; b=FVDbL+Q0BBjQ0mPLjUM+ObYMk0/GSi1lREDuhr6Wud3T/6EILPTcfgIY wBaxVJJjk+QDDqdYzLJd+F/uo4ExNZYYHFFZTBHmUWBG1vqOlauarPxHG L6nJKepl2eW4Es549/zOrHl1gdfX0hcLzwhRG4PBho6o3aAs4qdcgCVSY +nD64gr6n6exGK1Jt5EiXSZ4tPZMFZ4lqpLo6KiawxVw9D+3IlULfIv5j Ql74C1AHkjKqfusVyFyWTobElXpGg20azWec+dLrlpkLeukSPH9XQv6Z8 ap+4VN75suk/1gH1WkpQpvNMiFjrjCFSUKe1dYgwME6ogktOCGZIAv8xd w==; X-IronPort-AV: E=Sophos;i="5.88,378,1635231600"; d="scan'208";a="146491146" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 18 Feb 2022 03:16:23 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Fri, 18 Feb 2022 03:16:22 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Fri, 18 Feb 2022 03:16:20 -0700 From: Claudiu Beznea To: , , , , CC: , , Claudiu Beznea Subject: [PATCH 6/7] hwrnd: atmel - add runtime pm support Date: Fri, 18 Feb 2022 12:17:11 +0200 Message-ID: <20220218101712.530576-7-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220218101712.530576-1-claudiu.beznea@microchip.com> References: <20220218101712.530576-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add runtime PM support. Signed-off-by: Claudiu Beznea --- drivers/char/hw_random/atmel-rng.c | 44 ++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/drivers/char/hw_random/atmel-rng.c b/drivers/char/hw_random/atmel-rng.c index 0fff74808472..b662d44a09a6 100644 --- a/drivers/char/hw_random/atmel-rng.c +++ b/drivers/char/hw_random/atmel-rng.c @@ -17,6 +17,7 @@ #include #include #include +#include #define TRNG_CR 0x00 #define TRNG_MR 0x04 @@ -58,6 +59,12 @@ static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max, u32 *data = buf; int ret; + ret = pm_runtime_get_sync((struct device *)trng->rng.priv); + if (ret < 0) { + pm_runtime_put_sync((struct device *)trng->rng.priv); + return ret; + } + ret = atmel_trng_wait_ready(trng, wait); if (!ret) goto out; @@ -72,6 +79,8 @@ static int atmel_trng_read(struct hwrng *rng, void *buf, size_t max, ret = 4; out: + pm_runtime_mark_last_busy((struct device *)trng->rng.priv); + pm_runtime_put_sync_autosuspend((struct device *)trng->rng.priv); return ret; } @@ -127,21 +136,28 @@ static int atmel_trng_probe(struct platform_device *pdev) trng->has_half_rate = data->has_half_rate; trng->rng.name = pdev->name; trng->rng.read = atmel_trng_read; + trng->rng.priv = (unsigned long)&pdev->dev; + platform_set_drvdata(pdev, trng); +#ifndef CONFIG_PM ret = atmel_trng_init(trng); if (ret) return ret; +#endif - ret = devm_hwrng_register(&pdev->dev, &trng->rng); - if (ret) - goto err_register; - - platform_set_drvdata(pdev, trng); + pm_runtime_set_autosuspend_delay(&pdev->dev, 100); + pm_runtime_use_autosuspend(&pdev->dev); + pm_runtime_enable(&pdev->dev); - return 0; + ret = devm_hwrng_register(&pdev->dev, &trng->rng); + if (ret) { + pm_runtime_disable(&pdev->dev); + pm_runtime_set_suspended(&pdev->dev); +#ifndef CONFIG_PM + atmel_trng_cleanup(trng); +#endif + } -err_register: - atmel_trng_cleanup(trng); return ret; } @@ -151,11 +167,13 @@ static int atmel_trng_remove(struct platform_device *pdev) atmel_trng_cleanup(trng); + pm_runtime_disable(&pdev->dev); + pm_runtime_set_suspended(&pdev->dev); return 0; } -static int __maybe_unused atmel_trng_suspend(struct device *dev) +static int __maybe_unused atmel_trng_runtime_suspend(struct device *dev) { struct atmel_trng *trng = dev_get_drvdata(dev); @@ -164,7 +182,7 @@ static int __maybe_unused atmel_trng_suspend(struct device *dev) return 0; } -static int __maybe_unused atmel_trng_resume(struct device *dev) +static int __maybe_unused atmel_trng_runtime_resume(struct device *dev) { struct atmel_trng *trng = dev_get_drvdata(dev); @@ -172,8 +190,10 @@ static int __maybe_unused atmel_trng_resume(struct device *dev) } static const struct dev_pm_ops __maybe_unused atmel_trng_pm_ops = { - .suspend = atmel_trng_suspend, - .resume = atmel_trng_resume, + SET_RUNTIME_PM_OPS(atmel_trng_runtime_suspend, + atmel_trng_runtime_resume, NULL) + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) }; static const struct atmel_trng_data at91sam9g45_config = {