From patchwork Mon May 25 22:15:07 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "jonsmirl@gmail.com" X-Patchwork-Id: 27622 Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 768D8B6F34 for ; Tue, 26 May 2009 08:16:48 +1000 (EST) Received: by ozlabs.org (Postfix) id 0C081DE5F6; Tue, 26 May 2009 08:16:01 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 097C2DE5F5 for ; Tue, 26 May 2009 08:16:01 +1000 (EST) X-Original-To: linuxppc-dev@ozlabs.org Delivered-To: linuxppc-dev@ozlabs.org Received: from mail-gx0-f220.google.com (mail-gx0-f220.google.com [209.85.217.220]) by ozlabs.org (Postfix) with ESMTP id 76226DE0B2 for ; Tue, 26 May 2009 08:15:09 +1000 (EST) Received: by gxk20 with SMTP id 20so2168464gxk.9 for ; Mon, 25 May 2009 15:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:subject:to:from:date :message-id:in-reply-to:references:user-agent:mime-version :content-type:content-transfer-encoding; bh=ySFN2jJpZr4o+edLoEzbBOiMko0Eq82VvxTlIzsL/QI=; b=daQSSvzv/dKu7T5WCFa54iOAacGqcrJSkhU/TSI7wDJ+hCjQEvkouFk1/5T/H0L7jS aLokcIvik2Dkhn8bc86FHO9gnRizoDz2dbyCvsVf2vM+DQ11S/qNwgP39sGtfRq1XZOi x9NuZ5rUVsc+15tibqk2o7eqdAhwyF5csWQFQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:to:from:date:message-id:in-reply-to:references:user-agent :mime-version:content-type:content-transfer-encoding; b=Ils0p7bTU598Wx0L2dSJCvaMQM28G6/05lY8Yb4ZsTieSm4aSALl/w1f0JIbf1UvAf GlSoWyLNkpPP3hUMRGU4SGNDnJFIQMrYsBOBrDBTfnG0MV9vBs/AA+1o+XRCywAWtZRV 56LCcxHTBOonLRKxKQlxO4/IUpfX2EKFcPJJ4= Received: by 10.151.137.6 with SMTP id p6mr15212846ybn.214.1243289707400; Mon, 25 May 2009 15:15:07 -0700 (PDT) Received: from terra (c-76-109-159-38.hsd1.fl.comcast.net [76.109.159.38]) by mx.google.com with ESMTPS id 6sm9920818ywc.1.2009.05.25.15.15.06 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 25 May 2009 15:15:07 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=[127.0.1.1]) by terra with esmtp (Exim 4.69) (envelope-from ) id 1M8iRn-0005a7-3t; Mon, 25 May 2009 18:15:07 -0400 Subject: [PATCH V4 1/5] The macro spin_event_timeout() takes a condition and timeout value To: grant.likely@secretlab.ca, linuxppc-dev@ozlabs.org, alsa-devel@alsa-project.org, broonie@sirena.org.uk, timur@freescale.com From: Jon Smirl Date: Mon, 25 May 2009 18:15:07 -0400 Message-ID: <20090525221507.21370.68301.stgit@terra> In-Reply-To: <20090525221406.21370.30326.stgit@terra> References: <20090525221406.21370.30326.stgit@terra> User-Agent: StGit/0.14.3.366.gf979 MIME-Version: 1.0 X-BeenThere: linuxppc-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org (in microseconds) as parameters. It spins until either the condition is true or the timeout expires. It returns the result of the condition when the loop was terminated. This primary purpose of this macro is to poll on a hardware register until a status bit changes. The timeout ensures that the loop still terminates if the bit doesn't change as expected. This macro makes it easier for driver developers to perform this kind of operation properly. Signed-off-by: Timur Tabi --- arch/powerpc/include/asm/delay.h | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/include/asm/delay.h b/arch/powerpc/include/asm/delay.h index f9200a6..fedf037 100644 --- a/arch/powerpc/include/asm/delay.h +++ b/arch/powerpc/include/asm/delay.h @@ -2,8 +2,11 @@ #define _ASM_POWERPC_DELAY_H #ifdef __KERNEL__ +#include + /* * Copyright 1996, Paul Mackerras. + * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -30,5 +33,35 @@ extern void udelay(unsigned long usecs); #define mdelay(n) udelay((n) * 1000) #endif +/** + * spin_event_timeout - spin until a condition gets true or a timeout elapses + * @condition: a C expression to evalate + * @timeout: timeout, in microseconds + * @delay: the number of microseconds to delay between eache evaluation of + * @condition + * @rc: the last value of the condition + * + * The process spins until the condition evaluates to true (non-zero) or the + * timeout elapses. Upon exit, @rc contains the value of the condition. This + * allows you to test the condition without incurring any side effects. + * + * This primary purpose of this macro is to poll on a hardware register + * until a status bit changes. The timeout ensures that the loop still + * terminates even if the bit never changes. The delay is for devices that + * need a delay in between successive reads. + * + * gcc will optimize out the if-statement if @delay is a constant. + */ +#define spin_event_timeout(condition, timeout, delay, rc) \ +{ \ + unsigned long __loops = tb_ticks_per_usec * timeout; \ + unsigned long __start = get_tbl(); \ + while ((rc = (condition)) && (tb_ticks_since(__start) <= __loops)) \ + if (delay) \ + udelay(delay); \ + else \ + cpu_relax(); \ +} + #endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_DELAY_H */