From patchwork Mon Apr 22 14:51:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 238549 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 961572C00E8 for ; Tue, 23 Apr 2013 00:52:30 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4D26D4A16E; Mon, 22 Apr 2013 16:52:29 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id v2mQRWHerneS; Mon, 22 Apr 2013 16:52:28 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A748B4A246; Mon, 22 Apr 2013 16:52:27 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 13E794A22E for ; Mon, 22 Apr 2013 16:52:26 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 51ZGPT9npCrQ for ; Mon, 22 Apr 2013 16:52:25 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by theia.denx.de (Postfix) with ESMTPS id 16E124A210 for ; Mon, 22 Apr 2013 16:52:24 +0200 (CEST) Received: by mail-wi0-f178.google.com with SMTP id hm14so1350641wib.5 for ; Mon, 22 Apr 2013 07:52:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:content-type:x-gm-message-state; bh=vX4AvQ5K4y4Ui6Yl5md/qLvo3OU0yrziDdK36w/VZYs=; b=aYBo5QNQ/rVJ3DU6uI3xIaZEgTeQp4aN0jhNlAP7pHSRTdIoV/6TMxdYZ6CzEaMw+E qRv0L8UNCWxZAtOiHbJVrGyaHG9a4OExpUQdiXZ0YnztjAhix8E5lcwUvyQesvCzouGI 9Hg1muTLyR/0L2E9aFbk+yTTtkZxg0erQBe7iYbBEckwWGwTdB9OOseArhlYtR0TvFeX mrDprf3gn9UL6EsprN3U4vtWqNvfi6dctSUTyazniOV8Q1w5qlhtqpnNZWNTVsccMBYQ UrmiPFxQZRgBSbhKtZQbycvTKWonARlm4u3SRClcmiJwXuktl2x3nnVucTrbkzqJCvqj PfMA== X-Received: by 10.194.93.133 with SMTP id cu5mr53319159wjb.56.1366642343835; Mon, 22 Apr 2013 07:52:23 -0700 (PDT) Received: from localhost (nat-63.starnet.cz. [178.255.168.63]) by mx.google.com with ESMTPSA id t14sm21190569wib.0.2013.04.22.07.52.22 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Mon, 22 Apr 2013 07:52:23 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, Albert Aribaud Date: Mon, 22 Apr 2013 16:51:59 +0200 Message-Id: <98a6e4d33e61c56c76b9bd78ef5d8e74ebd1510c.1366641836.git.michal.simek@xilinx.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1366642332-11185-1-git-send-email-michal.simek@xilinx.com> References: <1366642332-11185-1-git-send-email-michal.simek@xilinx.com> X-Gm-Message-State: ALoCoQntYY2Bv8IIahc5SaumZvoE29PEQEHvFsKVf3oKllW6WMnmprKf+17nKzo16DKU96awqAEM Cc: Peter Crosthwaite , Jagannadha Sutradharudu Teki Subject: [U-Boot] [PATCH 01/14] arm: zynq: U-Boot udelay < 1000 FIX X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: David Andrey Rework the __udelay function of U-Boot Zynq Arch to handle delay < 1000 usec Signed-off-by: David Andrey Signed-off-by: Michal Simek --- arch/arm/cpu/armv7/zynq/timer.c | 46 +++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) -- 1.8.2.1 diff --git a/arch/arm/cpu/armv7/zynq/timer.c b/arch/arm/cpu/armv7/zynq/timer.c index 45b405a..5d8bb24 100644 --- a/arch/arm/cpu/armv7/zynq/timer.c +++ b/arch/arm/cpu/armv7/zynq/timer.c @@ -114,15 +114,43 @@ ulong get_timer_masked(void) void __udelay(unsigned long usec) { - unsigned long long tmp; - ulong tmo; - - tmo = usec / (1000000 / CONFIG_SYS_HZ); - tmp = get_ticks() + tmo; /* Get current timestamp */ - - while (get_ticks() < tmp) { /* Loop till event */ - /* NOP */; - } + u32 countticks; + u32 timeend; + u32 timediff; + u32 timenow; + + if (usec == 0) + return; + + countticks = (u32) (((unsigned long long) TIMER_TICK_HZ * usec) / + 1000000); + + /* decrementing timer */ + timeend = readl(&timer_base->counter) - countticks; + +#if TIMER_LOAD_VAL != 0xFFFFFFFF + /* do not manage multiple overflow */ + if (countticks >= TIMER_LOAD_VAL) + countticks = TIMER_LOAD_VAL - 1; +#endif + + do { + timenow = readl(&timer_base->counter); + + if (timenow >= timeend) { + /* normal case */ + timediff = timenow - timeend; + } else { + if ((TIMER_LOAD_VAL - timeend + timenow) <= + countticks) { + /* overflow */ + timediff = TIMER_LOAD_VAL - timeend + timenow; + } else { + /* missed the exact match */ + break; + } + } + } while (timediff > 0); } /* Timer without interrupts */