From patchwork Tue Sep 18 18:21:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1474161 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 6A3F33FCFC for ; Tue, 18 Sep 2012 18:27:30 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TE2UE-0007aL-8K; Tue, 18 Sep 2012 18:25:30 +0000 Received: from mail-lpp01m010-f73.google.com ([209.85.215.73]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TE2TN-0007KE-4M for linux-arm-kernel@lists.infradead.org; Tue, 18 Sep 2012 18:24:39 +0000 Received: by lahi5 with SMTP id i5so6186lah.0 for ; Tue, 18 Sep 2012 11:24:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=XMu7oFxslYkbOnItNFnkSadubjFr72aGk3uXrjMWRjM=; b=ZrkLjSbdDYCezOvISABnmJ4fRo4WYTgfbHhuh/PKTvcKuJsRbKUxjwIsgelTRgAd9Z /oWyhKPAP3UFzM6o5cBWp3+5iONojsgh/GOdMvMFN0mqE2vhp/bEUqQGbzq3B1P4vw5F VAiJeOLebLPx4TQa7TZKfCqFmZuInrvA3xng7yXhCIFbXVNZx2Ao/e0D7dSkRn0DuCFU FoG/04ePHTCSY4xXfzgiekB4fv1jGj2X4QBkA0G0LIDJlM3YT8S2Jyt+fb+wlob7lrgW 8dEMK5FXiMNCtYMM5lOzF4AWuvUQHtztrrjxMwp0p8gxeqJpNDI7RAkcE/vhX4auGdMI C2UQ== Received: by 10.180.73.173 with SMTP id m13mr180810wiv.4.1347992673814; Tue, 18 Sep 2012 11:24:33 -0700 (PDT) Received: from hpza9.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id fa8si2286434wid.1.2012.09.18.11.24.33 (version=TLSv1/SSLv3 cipher=AES128-SHA); Tue, 18 Sep 2012 11:24:33 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by hpza9.eem.corp.google.com (Postfix) with ESMTP id 8A09B5C0050; Tue, 18 Sep 2012 11:24:33 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id DCCAF161E72; Tue, 18 Sep 2012 11:24:32 -0700 (PDT) From: Simon Glass To: LKML , linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/7] spi: s3c64xx: Use jiffies instead of loops for timeout Date: Tue, 18 Sep 2012 11:21:56 -0700 Message-Id: <1347992519-6904-5-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1347992519-6904-1-git-send-email-sjg@chromium.org> References: <1347992519-6904-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQm4c62Y/K5N4iS62+u7saoTOjNTC1HITW6d6MC6+dMoTBhiJir184WS/+iVOY55pvHK43p/jX1qIRYO4oF5Ag+Q12gZr84tRRpgX3HLxwtx72a66F6FfjhQkQBYpJRBYRxaWwjXSEnnV9RvSxbNfDjMywRoKPCXY29j3Y6C/Ph2s3YKtpl5U1TpB37n8DVEUSl7szAqVSNTbCmGdDIzi0jt8jDC7A== X-Spam-Note: CRM114 invocation failed X-Spam-Score: -3.1 (---) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-3.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.215.73 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Simon Glass , "kgene.kim" , Ben Dooks , Srinivas KANDAGATLA X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The current timeout uses loops, but does not actually use an empty loop. In fact it checks SPI registers which are pretty slow to read. As a result the timeout ends up being several seconds most of the time. Change this to use jiffies instead. Signed-off-by: Simon Glass --- drivers/spi/spi-s3c64xx.c | 37 ++++++++++++++++++++++--------------- 1 files changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 95a1bfc..db79d87 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -427,6 +427,7 @@ static inline void enable_cs(struct s3c64xx_spi_driver_data *sdd, static int wait_for_xfer(struct s3c64xx_spi_driver_data *sdd, struct spi_transfer *xfer, int dma_mode) { + struct device *dev = &sdd->pdev->dev; void __iomem *regs = sdd->regs; unsigned long val; int ms; @@ -439,16 +440,21 @@ static int wait_for_xfer(struct s3c64xx_spi_driver_data *sdd, val = msecs_to_jiffies(ms) + 10; val = wait_for_completion_timeout(&sdd->xfer_completion, val); } else { + ulong deadline; u32 status; - val = msecs_to_loops(ms); + + deadline = jiffies + msecs_to_jiffies(ms); do { status = readl(regs + S3C64XX_SPI_STATUS); - } while (RX_FIFO_LVL(status, sdd) < xfer->len && --val); + if (time_after(jiffies, deadline)) { + dev_warn(dev, "RX timeout level=%d, need=%d\n", + RX_FIFO_LVL(status, sdd), xfer->len); + return -EIO; + } + cpu_relax(); + } while (RX_FIFO_LVL(status, sdd) < xfer->len); } - if (!val) - return -EIO; - if (dma_mode) { u32 status; @@ -460,17 +466,18 @@ static int wait_for_xfer(struct s3c64xx_spi_driver_data *sdd, * Xfer involved Rx(with or without Tx). */ if (xfer->rx_buf == NULL) { - val = msecs_to_loops(10); - status = readl(regs + S3C64XX_SPI_STATUS); - while ((TX_FIFO_LVL(status, sdd) - || !S3C64XX_SPI_ST_TX_DONE(status, sdd)) - && --val) { - cpu_relax(); - status = readl(regs + S3C64XX_SPI_STATUS); - } + ulong deadline; - if (!val) - return -EIO; + deadline = jiffies + msecs_to_jiffies(10); + do { + status = readl(regs + S3C64XX_SPI_STATUS); + if (time_after(jiffies, deadline)) { + dev_warn(dev, "TX timeout level=%d\n", + TX_FIFO_LVL(status, sdd)); + return -EIO; + } + } while (TX_FIFO_LVL(status, sdd) || + !S3C64XX_SPI_ST_TX_DONE(status, sdd)); } } else { /* If it was only Tx */