From patchwork Wed Jan 8 13:47:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 22964 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6426A202E2 for ; Wed, 8 Jan 2014 13:49:11 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id p10sf4245095pdj.3 for ; Wed, 08 Jan 2014 05:49:10 -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=78UPgWbPG5qaPR8i6OmcGm7vXS4008ZvUCALhSS77/o=; b=hDRma5YF9BHY6Dfg7jP/fk6D0+AnYJIXesWmXF5HcNQAkIX4QH3vNBe40M1oSI4Aww MA0ES68deN5IvrKfG/r7JArI4JXWHJb+lb8tTij1ikWGh5RwLmnWWk7gzqTjf3SVoXv8 U1dibkkHj/C+P6uT1Mg36Qj7XvnLDNmgIZDc4octeSrFGym/SmyCNYh0ZahRz7OTSSmb s2JpwVgs6p04v4FxBlOXovHFtMQ7piUa+ZQ3a2QIZ+FPd/R9qFkWHVOkGGdASqLLN3ap tBOoDm/xC1Rjs3vieQJ0Rr/t54CP+KLLWXBDlZwF1TBYcmqjAIv2ht1ScwO8J7MQjA1a TCoA== X-Gm-Message-State: ALoCoQlVR9k3NgK4OUk0DdpQ+ANeXqVn6PQGWiVAyl14oV/3oijte6m8EaP/3CO1i0SggwdKbuqN X-Received: by 10.66.136.166 with SMTP id qb6mr4517102pab.44.1389188950720; Wed, 08 Jan 2014 05:49:10 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.24.174 with SMTP id v14ls520261qef.74.gmail; Wed, 08 Jan 2014 05:49:10 -0800 (PST) X-Received: by 10.58.77.236 with SMTP id v12mr1960512vew.77.1389188950604; Wed, 08 Jan 2014 05:49:10 -0800 (PST) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id tc7si620578vdc.9.2014.01.08.05.49.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 05:49:10 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.181 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.181; Received: by mail-ve0-f181.google.com with SMTP id oy12so1256887veb.12 for ; Wed, 08 Jan 2014 05:49:10 -0800 (PST) X-Received: by 10.52.227.233 with SMTP id sd9mr2729639vdc.53.1389188950496; Wed, 08 Jan 2014 05:49:10 -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.59.13.131 with SMTP id ey3csp226646ved; Wed, 8 Jan 2014 05:49:09 -0800 (PST) X-Received: by 10.194.93.3 with SMTP id cq3mr82824573wjb.26.1389188948022; Wed, 08 Jan 2014 05:49:08 -0800 (PST) Received: from mail-wg0-f50.google.com (mail-wg0-f50.google.com [74.125.82.50]) by mx.google.com with ESMTPS id o7si716299wiy.16.2014.01.08.05.49.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 05:49:08 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.50 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.50; Received: by mail-wg0-f50.google.com with SMTP id l18so541277wgh.17 for ; Wed, 08 Jan 2014 05:49:07 -0800 (PST) X-Received: by 10.180.187.229 with SMTP id fv5mr21632784wic.24.1389188947584; Wed, 08 Jan 2014 05:49:07 -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 j9sm48125217wjx.18.2014.01.08.05.49.06 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 08 Jan 2014 05:49:06 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: computersforpeace@gmail.com, angus.clark@st.com, Lee Jones Subject: [PATCH v4 28/37] mtd: st_spi_fsm: Supply a busy wait for post-write status Date: Wed, 8 Jan 2014 13:47:11 +0000 Message-Id: <1389188840-14306-29-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1389188840-14306-1-git-send-email-lee.jones@linaro.org> References: <1389188840-14306-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.128.181 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 | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index c64f741..c2ee7e3 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -236,8 +236,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 @@ -517,6 +527,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 = { @@ -692,6 +718,45 @@ 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)); + + stfsm_read_fifo(fsm, &status, 4); + if ((status & FLASH_STATUS_BUSY) == 0) + return 0; + + 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;