From patchwork Thu Dec 4 10:21:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 41919 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4544C25E8C for ; Thu, 4 Dec 2014 10:22:39 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf10669817wgh.1 for ; Thu, 04 Dec 2014 02:22:38 -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=dY911bqnNzaF12HW8LxPUtnEBDTNKE+6ZS6hIApKYgA=; b=JOyKUeGgTwtQ1wWvrEaUYvZveUtdD//kP6orgqKxZOKMY1cl9ccDvUpg39Mnd/9KqP +vpdTrKWk53FAOEqdlsTIM1/4BDvMc7wHZKJNV/DwysUDN91Ddldlcl2rgJv+50ggVCa vpQDINRszIoR8hsvgGsXKnffBSiLOKUsmBnGsPPxfv9ubuPexUXAW9qz9xAOo5c9DfCj aCFLCGY48a10j9nHzehs6xzHHWlSP2MxHlp+7O0mzAQQ+ORs3Sw+6xfT/oAl4CCAKw5w KvscWjpbCMDOSA+fPyIpCpJSMPJTwMj87Y1Fvz+KKFcvBrLfZo9G1sKOENAhRapT9GQK aJTg== X-Gm-Message-State: ALoCoQmndbswzihzjTvez69NhdSghghef5miZP78eEk3Tfcejo8+aVLW4W78dwX0TgVSTJnDCMeO X-Received: by 10.112.154.194 with SMTP id vq2mr325748lbb.10.1417688558223; Thu, 04 Dec 2014 02:22:38 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.77 with SMTP id be13ls266803lab.40.gmail; Thu, 04 Dec 2014 02:22:38 -0800 (PST) X-Received: by 10.152.2.74 with SMTP id 10mr8623666las.38.1417688558046; Thu, 04 Dec 2014 02:22:38 -0800 (PST) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id bd9si25451916lab.42.2014.12.04.02.22.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Dec 2014 02:22:38 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by mail-la0-f43.google.com with SMTP id ge10so9513580lab.16 for ; Thu, 04 Dec 2014 02:22:38 -0800 (PST) X-Received: by 10.152.43.12 with SMTP id s12mr8406385lal.67.1417688557939; Thu, 04 Dec 2014 02:22:37 -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.184.201 with SMTP id ew9csp10176lbc; Thu, 4 Dec 2014 02:22:36 -0800 (PST) X-Received: by 10.68.69.109 with SMTP id d13mr24419878pbu.57.1417688556063; Thu, 04 Dec 2014 02:22:36 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id tz1si42507409pab.54.2014.12.04.02.22.33 for ; Thu, 04 Dec 2014 02:22:36 -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 S1754311AbaLDKW2 (ORCPT + 26 others); Thu, 4 Dec 2014 05:22:28 -0500 Received: from mail-yh0-f50.google.com ([209.85.213.50]:56024 "EHLO mail-yh0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753401AbaLDKWX (ORCPT ); Thu, 4 Dec 2014 05:22:23 -0500 Received: by mail-yh0-f50.google.com with SMTP id 29so8627975yhl.23 for ; Thu, 04 Dec 2014 02:22:22 -0800 (PST) X-Received: by 10.170.116.21 with SMTP id i21mr12910750ykb.105.1417688542641; Thu, 04 Dec 2014 02:22:22 -0800 (PST) Received: from localhost.localdomain (host109-148-232-11.range109-148.btcentralplus.com. [109.148.232.11]) by mx.google.com with ESMTPSA id y67sm16089929yhc.11.2014.12.04.02.22.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Dec 2014 02:22:22 -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, computersforpeace@gmail.com, linux-mtd@lists.infradead.org, Angus Clark Subject: [PATCH v2 RESEND 08/11] mtd: st_spi_fsm: Improve busy wait handling Date: Thu, 4 Dec 2014 10:21:49 +0000 Message-Id: <1417688512-7644-9-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1417688512-7644-1-git-send-email-lee.jones@linaro.org> References: <1417688512-7644-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.215.43 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 0501a57..18f6f0b 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -252,7 +252,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 @@ -964,7 +969,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; @@ -982,7 +987,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; @@ -1061,7 +1066,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; } @@ -1458,7 +1463,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) @@ -1761,7 +1766,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); @@ -1833,7 +1838,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); @@ -1863,7 +1868,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); } /*