From patchwork Wed Jan 21 15:24:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 43468 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 13A50218DB for ; Wed, 21 Jan 2015 15:26:59 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id b57sf9295012eek.0 for ; Wed, 21 Jan 2015 07:26:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=JY55lepxXQoNrWZ0FdLL5+4oj1D5+/Y9aybsBxx3ux4=; b=CzhmPwfzSvUm9ItChdNtNiQEwuJvBs1aYXhG7X87WdNeE6M/7a4jvcVQ2NJ/d6IRcR f3VFATpei2WRvwpQHbZe4zmVq+wRDQkB2aSzMValD7d59kbZx6zTfyv0lI5kvqVabUQ7 ufX6L7xSbhPCyBN1+HFgUutykDifPtootHLGQZeSQFNRs2d6r+rKWhCcTgErPBY160Ep akp3QHYqU+ig47mZDPwhC2UQmNPetAcCRtuHh8398ZDKwdwHOPksafvsjYitvHg2xjes VGzhZE6mhrps2M2LeofS+1e1k+XodeplPX0nAGq9xJPkjaH8FrERwsd728Lp0VHbePMq 4wMA== X-Gm-Message-State: ALoCoQluHVVeRWQKNtJNEgkySN2mwg3GY8DEHrZGPNqWnI5nxA11pktj8f0s9MKm7myKiUU3G0ea X-Received: by 10.112.154.232 with SMTP id vr8mr399524lbb.10.1421854018098; Wed, 21 Jan 2015 07:26:58 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.168 with SMTP id an8ls51293lac.62.gmail; Wed, 21 Jan 2015 07:26:57 -0800 (PST) X-Received: by 10.152.45.65 with SMTP id k1mr45339376lam.14.1421854017926; Wed, 21 Jan 2015 07:26:57 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id kg2si18271231lbc.4.2015.01.21.07.26.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 21 Jan 2015 07:26:57 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id l4so14381495lbv.13 for ; Wed, 21 Jan 2015 07:26:57 -0800 (PST) X-Received: by 10.152.26.201 with SMTP id n9mr45289087lag.50.1421854017795; Wed, 21 Jan 2015 07:26:57 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.9.200 with SMTP id c8csp1813053lbb; Wed, 21 Jan 2015 07:26:56 -0800 (PST) X-Received: by 10.66.121.230 with SMTP id ln6mr63126955pab.82.1421854015891; Wed, 21 Jan 2015 07:26:55 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id de3si4154646pdb.148.2015.01.21.07.26.54; Wed, 21 Jan 2015 07:26:55 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754525AbbAUP0o (ORCPT + 28 others); Wed, 21 Jan 2015 10:26:44 -0500 Received: from mail-ie0-f174.google.com ([209.85.223.174]:41807 "EHLO mail-ie0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754149AbbAUPY6 (ORCPT ); Wed, 21 Jan 2015 10:24:58 -0500 Received: by mail-ie0-f174.google.com with SMTP id at20so40713627iec.5 for ; Wed, 21 Jan 2015 07:24:57 -0800 (PST) X-Received: by 10.42.54.5 with SMTP id p5mr41193495icg.37.1421853897541; Wed, 21 Jan 2015 07:24:57 -0800 (PST) Received: from localhost.localdomain (host86-181-29-86.range86-181.btcentralplus.com. [86.181.29.86]) by mx.google.com with ESMTPSA id y5sm1411873ign.7.2015.01.21.07.24.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jan 2015 07:24:57 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: lee.jones@linaro.org, kernel@stlinux.com, linux-mtd@lists.infradead.org, computersforpeace@gmail.com, Angus Clark Subject: [PATCH v4 07/10] mtd: st_spi_fsm: Improve busy wait handling Date: Wed, 21 Jan 2015 15:24:25 +0000 Message-Id: <1421853868-8262-8-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1421853868-8262-1-git-send-email-lee.jones@linaro.org> References: <1421853868-8262-1-git-send-email-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Angus Clark In this patch, the fsm_wait_busy() function is updated to a take a timeout parameter. This allows us to specify different timeout delays depending on the operation being performed. Previously, a fixed, worst-case delay (corresponding to the Chip Erase operation, ~300s!) was used. For the moment, we have defined conservative delays for each relevant operation, which should accommodate all existing devices. In principle, one could set the delays according the device probed, but there is probably little to be gained. Signed-off-by: Angus Clark Signed-off-by: Lee Jones --- drivers/mtd/devices/st_spi_fsm.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index f452276e..5e365ef 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -267,7 +267,12 @@ #define FLASH_PAGESIZE 256 /* In Bytes */ #define FLASH_PAGESIZE_32 (FLASH_PAGESIZE / 4) /* In uint32_t */ -#define FLASH_MAX_BUSY_WAIT (300 * HZ) /* Maximum 'CHIPERASE' time */ +/* Maximum operation times (in ms) */ +#define FLASH_MAX_CHIP_ERASE_MS 500000 /* Chip Erase time */ +#define FLASH_MAX_SEC_ERASE_MS 30000 /* Sector Erase time */ +#define FLASH_MAX_PAGE_WRITE_MS 100 /* Write Page time */ +#define FLASH_MAX_STA_WRITE_MS 4000 /* Write status reg time */ +#define FSM_MAX_WAIT_SEQ_MS 1000 /* FSM execution time */ /* * Flags to tweak operation of default read/write/erase routines @@ -1003,7 +1008,7 @@ static int stfsm_enter_32bit_addr(struct stfsm *fsm, int enter) return 0; } -static uint8_t stfsm_wait_busy(struct stfsm *fsm) +static uint8_t stfsm_wait_busy(struct stfsm *fsm, unsigned int max_time_ms) { struct stfsm_seq *seq = &stfsm_seq_read_status_fifo; unsigned long deadline; @@ -1021,7 +1026,7 @@ static uint8_t stfsm_wait_busy(struct stfsm *fsm) /* * Repeat until busy bit is deasserted, or timeout, or error (S25FLxxxS) */ - deadline = jiffies + FLASH_MAX_BUSY_WAIT; + deadline = jiffies + msecs_to_jiffies(max_time_ms); while (!timeout) { if (time_after_eq(jiffies, deadline)) timeout = 1; @@ -1100,7 +1105,7 @@ static int stfsm_write_status(struct stfsm *fsm, uint8_t cmd, stfsm_wait_seq(fsm); if (wait_busy) - stfsm_wait_busy(fsm); + stfsm_wait_busy(fsm, FLASH_MAX_STA_WRITE_MS); return 0; } @@ -1497,7 +1502,7 @@ static void stfsm_s25fl_write_dyb(struct stfsm *fsm, uint32_t offs, uint8_t dby) stfsm_load_seq(fsm, &seq); stfsm_wait_seq(fsm); - stfsm_wait_busy(fsm); + stfsm_wait_busy(fsm, FLASH_MAX_STA_WRITE_MS); } static int stfsm_s25fl_clear_status_reg(struct stfsm *fsm) @@ -1800,7 +1805,7 @@ static int stfsm_write(struct stfsm *fsm, const uint8_t *buf, stfsm_wait_seq(fsm); /* Wait for completion */ - ret = stfsm_wait_busy(fsm); + ret = stfsm_wait_busy(fsm, FLASH_MAX_PAGE_WRITE_MS); if (ret && fsm->configuration & CFG_S25FL_CHECK_ERROR_FLAGS) stfsm_s25fl_clear_status_reg(fsm); @@ -1872,7 +1877,7 @@ static int stfsm_erase_sector(struct stfsm *fsm, uint32_t offset) stfsm_wait_seq(fsm); /* Wait for completion */ - ret = stfsm_wait_busy(fsm); + ret = stfsm_wait_busy(fsm, FLASH_MAX_SEC_ERASE_MS); if (ret && fsm->configuration & CFG_S25FL_CHECK_ERROR_FLAGS) stfsm_s25fl_clear_status_reg(fsm); @@ -1902,7 +1907,7 @@ static int stfsm_erase_chip(struct stfsm *fsm) stfsm_wait_seq(fsm); - return stfsm_wait_busy(fsm); + return stfsm_wait_busy(fsm, FLASH_MAX_CHIP_ERASE_MS); } /*