From patchwork Fri Nov 29 12:19:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 21886 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E9EF923FC4 for ; Fri, 29 Nov 2013 12:20:30 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id i4sf32064544oah.6 for ; Fri, 29 Nov 2013 04:20:30 -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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=edXUH7kd/pI77ElZ7zCnAdQkrjryDfH48N9HViWikZ0=; b=E6eZyeXCROjskiZEun8yR67zz0sl126Rtje5IueFjZkjVDq8A4TfTzDmH9N+yvE6MO 000nQtufyVSSwRK1O5Ad+DPbE/Ti/5oBpHtxdYGcYMIbUyInwT/sCBCccPOrVSz3/tcX dh0WeODD2sTBf+1PzRsl1xBY//bAH16b3K4otrTt1Pkq9ZP6ygu8D4Kfd8i+w25o3OE0 GC/O8mrSda9+ut5YTX2EOS5Fl8S4swCw6zDR2zYCDZNzsJoopwQtlCcgKE74VlzXFxJG NU5GJx9z1JfemGFfAyQHkHvOEGft/TQoI9HRA6eNohQd6EKHmGhCCkXzOZ1Wh3VSJjGm 0XpQ== X-Gm-Message-State: ALoCoQmR02GApVR/UBNH0RZSZ+9nJ8NJtevQdD6j/nWvlptNEdLs+lRT4N4kBI4F0FAGs5Tjhbnp X-Received: by 10.42.84.136 with SMTP id m8mr15383248icl.9.1385727630590; Fri, 29 Nov 2013 04:20:30 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.127.3 with SMTP id nc3ls2206653qeb.9.gmail; Fri, 29 Nov 2013 04:20:30 -0800 (PST) X-Received: by 10.52.35.41 with SMTP id e9mr31546vdj.79.1385727630269; Fri, 29 Nov 2013 04:20:30 -0800 (PST) Received: from mail-vb0-f41.google.com (mail-vb0-f41.google.com [209.85.212.41]) by mx.google.com with ESMTPS id ks3si24777117vec.127.2013.11.29.04.20.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:20:30 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.41 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.41; Received: by mail-vb0-f41.google.com with SMTP id w5so6876560vbf.28 for ; Fri, 29 Nov 2013 04:20:30 -0800 (PST) X-Received: by 10.220.47.10 with SMTP id l10mr1851600vcf.32.1385727630198; Fri, 29 Nov 2013 04:20:30 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp87459vcz; Fri, 29 Nov 2013 04:20:29 -0800 (PST) X-Received: by 10.236.28.162 with SMTP id g22mr2019780yha.52.1385727629745; Fri, 29 Nov 2013 04:20:29 -0800 (PST) Received: from mail-yh0-f54.google.com (mail-yh0-f54.google.com [209.85.213.54]) by mx.google.com with ESMTPS id g15si6565972qej.54.2013.11.29.04.20.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:20:29 -0800 (PST) Received-SPF: neutral (google.com: 209.85.213.54 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.213.54; Received: by mail-yh0-f54.google.com with SMTP id z12so6636082yhz.41 for ; Fri, 29 Nov 2013 04:20:29 -0800 (PST) X-Received: by 10.236.45.102 with SMTP id o66mr43608258yhb.13.1385727629426; Fri, 29 Nov 2013 04:20:29 -0800 (PST) Received: from localhost.localdomain (cpc15-aztw25-2-0-cust493.aztw.cable.virginm.net. [92.233.57.238]) by mx.google.com with ESMTPSA id m29sm101911689yho.14.2013.11.29.04.20.27 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 04:20:29 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dwmw2@infradead.org Cc: linus.walleij@linaro.org, linux-mtd@lists.infradead.org, angus.clark@st.com, Lee Jones Subject: [PATCH v3 28/36] mtd: st_spi_fsm: Supply a busy wait for post-write status Date: Fri, 29 Nov 2013 12:19:17 +0000 Message-Id: <1385727565-25794-29-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1385727565-25794-1-git-send-email-lee.jones@linaro.org> References: <1385727565-25794-1-git-send-email-lee.jones@linaro.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.212.41 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 Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , When we write data to the Serial Flash chip we'll wait a predetermined period of time before giving up. During that period of time we poll the status register until completion. Signed-off-by: Lee Jones --- drivers/mtd/devices/st_spi_fsm.c | 52 ++++++++++++++++++++++++++++++++++++++++ drivers/mtd/devices/st_spi_fsm.h | 10 ++++++++ 2 files changed, 62 insertions(+) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index c08805f..d8fc97b 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -118,6 +118,22 @@ static struct stfsm_seq stfsm_seq_read_jedec = { SEQ_CFG_STARTSEQ), }; +static struct stfsm_seq stfsm_seq_read_status_fifo = { + .data_size = TRANSFER_SIZE(4), + .seq_opc[0] = (SEQ_OPC_PADS_1 | + SEQ_OPC_CYCLES(8) | + SEQ_OPC_OPCODE(FLASH_CMD_RDSR)), + .seq = { + STFSM_INST_CMD1, + STFSM_INST_DATA_READ, + STFSM_INST_STOP, + }, + .seq_cfg = (SEQ_CFG_PADS_1 | + SEQ_CFG_READNOTWRITE | + SEQ_CFG_CSDEASSERT | + SEQ_CFG_STARTSEQ), +}; + static struct stfsm_seq stfsm_seq_erase_sector = { /* 'addr_cfg' configured during initialisation */ .seq_opc = { @@ -292,6 +308,42 @@ static int stfsm_enter_32bit_addr(struct stfsm *fsm, int enter) return 0; } +static uint8_t stfsm_wait_busy(struct stfsm *fsm) +{ + struct stfsm_seq *seq = &stfsm_seq_read_status_fifo; + unsigned long deadline; + uint32_t status; + + /* Use RDRS1 */ + seq->seq_opc[0] = (SEQ_OPC_PADS_1 | + SEQ_OPC_CYCLES(8) | + SEQ_OPC_OPCODE(FLASH_CMD_RDSR)); + + /* Load read_status sequence */ + stfsm_load_seq(fsm, seq); + + /* Repeat until busy bit is deasserted, or timeout */ + deadline = jiffies + FLASH_MAX_BUSY_WAIT; + do { + cond_resched(); + + stfsm_wait_seq(fsm); + + stfsm_read_fifo(fsm, &status, 4); + + if ((status & FLASH_STATUS_BUSY) == 0) + return 0; + + /* Restart */ + writel(seq->seq_cfg, fsm->base + SPI_FAST_SEQ_CFG); + + } while (!time_after_eq(jiffies, deadline)); + + dev_err(fsm->dev, "timeout on wait_busy\n"); + + return -EIO; +} + static int stfsm_wrvcr(struct stfsm *fsm, uint8_t data) { struct stfsm_seq *seq = &stfsm_seq_wrvcr; diff --git a/drivers/mtd/devices/st_spi_fsm.h b/drivers/mtd/devices/st_spi_fsm.h index e168296..5143843 100644 --- a/drivers/mtd/devices/st_spi_fsm.h +++ b/drivers/mtd/devices/st_spi_fsm.h @@ -229,8 +229,18 @@ #define FLASH_CMD_READ4_1_1_4 0x6c #define FLASH_CMD_READ4_1_4_4 0xec +/* Status register */ +#define FLASH_STATUS_BUSY 0x01 +#define FLASH_STATUS_WEL 0x02 +#define FLASH_STATUS_BP0 0x04 +#define FLASH_STATUS_BP1 0x08 +#define FLASH_STATUS_BP2 0x10 +#define FLASH_STATUS_SRWP0 0x80 +#define FLASH_STATUS_TIMEOUT 0xff + #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 */ /* * Flags to tweak operation of default read/write/erase routines