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: 12751255 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6D7EFC433EF for ; Fri, 18 Feb 2022 10:17:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ytOIDA64cei+9sm4UnwOrBCumaKlpunuMVRl5C7yWMo=; b=iYH3bAm/9jAx9b qHq8X+2RAG0jScAElaowFqA4qVnR/AWvm0HFo7Y62/ObY11E+UrEpz8B7wAytuFDvxWqoqhhd48Js 9hw4rp8CYhXSPH3lWqpECOXCkuOzwq1QgEN501aBOV3VYAcB/XsnC8Mx25kdmvvtxkNaON8HRxZNM ClePChsR3DDUGlyVxaJ/mMzVW1Jdk4U3GViGl9Z7nxyB0i7Du/UXsfDWVnNAzGs7A+P0W1pkfeRua SsJNn+nKejpcw4R5Zp/VNbLmozfnEVQA+y8aIk3m+PktopAL9v07jvrRvbQ3bKeCcOap0A9BjUkdS jh5oYEdyMSXZuR/rkreg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nL0JR-00Dn4v-0h; Fri, 18 Feb 2022 10:16:29 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nL0J8-00Dmvx-HQ for linux-arm-kernel@lists.infradead.org; Fri, 18 Feb 2022 10:16:13 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220218_021610_638889_69852DFA X-CRM114-Status: GOOD ( 15.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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)