From patchwork Tue Apr 23 10:46:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 238863 X-Patchwork-Delegate: monstr@monstr.eu 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 129382C016F for ; Tue, 23 Apr 2013 20:46:58 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 335744A190; Tue, 23 Apr 2013 12:46:53 +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 0Eb7gnFGPNXi; Tue, 23 Apr 2013 12:46:52 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D193A4A193; Tue, 23 Apr 2013 12:46:45 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A12D04A186 for ; Tue, 23 Apr 2013 12:46:41 +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 fsjPi4ZnIDBI for ; Tue, 23 Apr 2013 12:46:41 +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-we0-f172.google.com (mail-we0-f172.google.com [74.125.82.172]) by theia.denx.de (Postfix) with ESMTPS id 078E54A185 for ; Tue, 23 Apr 2013 12:46:39 +0200 (CEST) Received: by mail-we0-f172.google.com with SMTP id r3so427558wey.31 for ; Tue, 23 Apr 2013 03:46:39 -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:in-reply-to:references:content-type :x-gm-message-state; bh=/gUVpqy2EH5IuZ+4S3UdeyGfnSx2F5ON4I1LvCHF3D8=; b=OuEQm43r4juwSH5vdTEgVLtN4su+i3hAks0qafP200fNQYJj+PVlP23yQi5dZWZfuO D4isL8zvGHk3x3btEL7WCZb5BF1kqOgvIKp4z4/CvbhmmoX1f0SOr3GuvKY9e/GVpi/q xMbySbblV7vTOSIpBpPaTl35mGK3wWs9i3ZQhk40AQiYxilVNwvsiczgaYzrCzLtN+JC APzVp29hnzAMuowSlSAat3jRcraGgRwhWInC6RIWpE2k0+K1xfYz+3Su938TJag99vq3 9cksdu5A78RG1J6lqefuD0MhO/vswFouwCxs/cb68I1y+1DueuVhopxvJkpHqnz9xPuS ukBg== X-Received: by 10.180.76.230 with SMTP id n6mr12593235wiw.28.1366713998919; Tue, 23 Apr 2013 03:46:38 -0700 (PDT) Received: from localhost (nat-63.starnet.cz. [178.255.168.63]) by mx.google.com with ESMTPS id q20sm15036880wiv.7.2013.04.23.03.46.37 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Tue, 23 Apr 2013 03:46:38 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, Joe Hershberger , Albert Aribaud , Tom Rini Date: Tue, 23 Apr 2013 12:46:00 +0200 Message-Id: <98a6e4d33e61c56c76b9bd78ef5d8e74ebd1510c.1366713845.git.michal.simek@xilinx.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQnUTWp+XdTZM0vuLMgDXHpphz9OHgzo+t8GOxOeKLUcGKKA5loy4Eve0xfy9wGRwDtHueBE Cc: Peter Crosthwaite , Jagannadha Sutradharudu Teki Subject: [U-Boot] [PATCH v2 01/15] 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 --- Changes in v2: None 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 */