From patchwork Thu Jan 23 10:31:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 23599 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8435E218BD for ; Thu, 23 Jan 2014 10:32:56 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id i4sf6445070oah.3 for ; Thu, 23 Jan 2014 02:32:55 -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=m2HM6MGg5fTgv1R/zua0UCDLj4dlS1L8j3c+iqbzykIBFIw//uGok+kzUqEXiJD3SO WpuI0+A9PQusgbbsHA4ba/3khIq4W/blyFgklXcby8zkBpeGCtbl7lwMRQXockzPDq+3 rOlaHWb1HSblZdEH98Kvhh3afZIHRSStV9QIF5Na0jVMapZE0w1M0JvC/gAuRndvptL4 txghhvHJZIxER0ttMKEoh6e9tN3iXjrKk9UV/ASCTCuAi8/MsNGUrFqBfIJFARgtkoQd ym5kRNKC0VllltAHiG9UEMZTMyhJsW/MFj1wUX/hL4mA+ag7cNTYgxgjV30YVdffxDuG zQPQ== X-Gm-Message-State: ALoCoQk0CA4/8HtGwKIFTUeDbuQO/1J1lS8oADLwjjqQk/t4XknKDyPb1h+TU/LxBafilk5AM3sJ X-Received: by 10.182.151.42 with SMTP id un10mr2764452obb.12.1390473175677; Thu, 23 Jan 2014 02:32:55 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.127.110 with SMTP id nf14ls248484qeb.44.gmail; Thu, 23 Jan 2014 02:32:55 -0800 (PST) X-Received: by 10.220.76.201 with SMTP id d9mr1195984vck.33.1390473175538; Thu, 23 Jan 2014 02:32:55 -0800 (PST) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id x5si6416816veb.149.2014.01.23.02.32.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:32:55 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.171 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.171; Received: by mail-ve0-f171.google.com with SMTP id pa12so985999veb.16 for ; Thu, 23 Jan 2014 02:32:55 -0800 (PST) X-Received: by 10.221.54.65 with SMTP id vt1mr52248vcb.46.1390473175477; Thu, 23 Jan 2014 02:32:55 -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 u4csp16004vcz; Thu, 23 Jan 2014 02:32:54 -0800 (PST) X-Received: by 10.180.85.198 with SMTP id j6mr7323767wiz.40.1390473174504; Thu, 23 Jan 2014 02:32:54 -0800 (PST) Received: from mail-wg0-f49.google.com (mail-wg0-f49.google.com [74.125.82.49]) by mx.google.com with ESMTPS id fw4si8779174wjb.97.2014.01.23.02.32.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:32:54 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.49 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.49; Received: by mail-wg0-f49.google.com with SMTP id a1so1245780wgh.28 for ; Thu, 23 Jan 2014 02:32:53 -0800 (PST) X-Received: by 10.194.142.231 with SMTP id rz7mr397852wjb.89.1390473173546; Thu, 23 Jan 2014 02:32:53 -0800 (PST) Received: from localhost.localdomain ([80.76.198.141]) by mx.google.com with ESMTPSA id ay6sm21257831wjb.23.2014.01.23.02.32.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 23 Jan 2014 02:32:51 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: linus.walleij@linaro.org, dwmw2@infradead.org, linux-mtd@lists.infradead.org, computersforpeace@gmail.com, Angus.Clark@st.com, DCG_UPD_stlinux_kernel@list.st.com, olivier.clergeaud@st.com, Lee Jones Subject: [PATCH RESEND v4 28/37] mtd: st_spi_fsm: Supply a busy wait for post-write status Date: Thu, 23 Jan 2014 10:31:16 +0000 Message-Id: <1390473085-24626-29-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1390473085-24626-1-git-send-email-lee.jones@linaro.org> References: <1390473085-24626-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.171 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;