From patchwork Wed Mar 26 16:39:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 27149 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 239A920369 for ; Wed, 26 Mar 2014 16:42:32 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id b6sf5388541yha.8 for ; Wed, 26 Mar 2014 09:42:32 -0700 (PDT) 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=Yv1Cz0jm9ZHXk36SW9J+gv8k9icvs64Yn12mscuQxPo=; b=BYXOuqd0CfkOCYJmaOcOnWFmYU67n/AWKHySzztkl06zlmMZFMqvrCoZ1HpRcmxS/+ 7dPBd71PBw98a1+nu8WYqaV/nmjFm1udde6p3JSNsM8tp0neDPP4VPTGc6qb4nsZegy5 0nbXp15N80BdmjHSgq04K04Zu0RA3EIiUk3VhZpkBj6oci+DMUBsH9ttKrsylpsBOhaY hjTMbCos3jPOqpRXbXs1ENcvQk7KotiLy6fFHLccO91fvSzC/3pZKcMZJ/dxm21I38l8 1zBvNYeHjjGsOd7c8r2zKsIJhx9RaszblQwN/x/+fy60VsV2Z509yg4sUamwms8PjpCX 2dmg== X-Gm-Message-State: ALoCoQlMITwkhvJ4Xk42qMZp/HM5T8E9gUN95QkWbWzwCO0iBGQom81Fwzc5hPQkrYrNDGLFspHl X-Received: by 10.58.168.137 with SMTP id zw9mr23805169veb.15.1395852152754; Wed, 26 Mar 2014 09:42:32 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.31.230 with SMTP id f93ls676871qgf.67.gmail; Wed, 26 Mar 2014 09:42:32 -0700 (PDT) X-Received: by 10.220.237.146 with SMTP id ko18mr266250vcb.49.1395852152624; Wed, 26 Mar 2014 09:42:32 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id tx7si4591570vcb.8.2014.03.26.09.42.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 26 Mar 2014 09:42:32 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id sa20so2621587veb.36 for ; Wed, 26 Mar 2014 09:42:32 -0700 (PDT) X-Received: by 10.58.55.170 with SMTP id t10mr1068764vep.29.1395852152532; Wed, 26 Mar 2014 09:42:32 -0700 (PDT) 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.220.78.9 with SMTP id i9csp61275vck; Wed, 26 Mar 2014 09:42:31 -0700 (PDT) X-Received: by 10.68.179.98 with SMTP id df2mr86787620pbc.51.1395852151599; Wed, 26 Mar 2014 09:42:31 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a8si13958813pbs.285.2014.03.26.09.42.30; Wed, 26 Mar 2014 09:42:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932208AbaCZQmV (ORCPT + 26 others); Wed, 26 Mar 2014 12:42:21 -0400 Received: from mail-we0-f172.google.com ([74.125.82.172]:34355 "EHLO mail-we0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932069AbaCZQkR (ORCPT ); Wed, 26 Mar 2014 12:40:17 -0400 Received: by mail-we0-f172.google.com with SMTP id t61so1323951wes.3 for ; Wed, 26 Mar 2014 09:40:16 -0700 (PDT) X-Received: by 10.180.108.199 with SMTP id hm7mr33343973wib.1.1395852016373; Wed, 26 Mar 2014 09:40:16 -0700 (PDT) Received: from lee--X1.home (host109-148-113-193.range109-148.btcentralplus.com. [109.148.113.193]) by mx.google.com with ESMTPSA id gp10sm3913806wib.13.2014.03.26.09.40.14 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 26 Mar 2014 09:40:15 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: lee.jones@linaro.org, kernel@stlinux.com, computersforpeace@gmail.com, linux-mtd@lists.infradead.org, angus.clark@st.com Subject: [PATCH 13/15] mtd: st_spi_fsm: Improve busy wait handling Date: Wed, 26 Mar 2014 16:39:27 +0000 Message-Id: <1395851969-13520-14-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1395851969-13520-1-git-send-email-lee.jones@linaro.org> References: <1395851969-13520-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=neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 a223d8a..9e00173 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -287,7 +287,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 @@ -1000,7 +1005,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; @@ -1018,7 +1023,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; @@ -1097,7 +1102,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; } @@ -1494,7 +1499,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) @@ -1797,7 +1802,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); @@ -1869,7 +1874,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); @@ -1899,7 +1904,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); } /*