From patchwork Mon Dec 15 11:59:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 42255 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CEC4B21772 for ; Mon, 15 Dec 2014 12:02:10 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id p9sf7131352lbv.1 for ; Mon, 15 Dec 2014 04:02:09 -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=SQSqPm3m0qs886mu2MM8KgHmviTztIojaIDny3W4jtk=; b=Y93D6AR1Y71MPGG65gfj9PpRrK34MtuoYAvYQnImtwrj24Fq42ziqSj3XtpgZbRc+L teiVRLo7Ikryhs3dJUo//yvbQKb2GovEswB75V6pGVVN03k8Jg9fyUZdGKYWx6hfixUG 8TN1J9QHfevBYO00sIwWevaIWQnB0IpDQKSdsfYl+sxeEFlzfd2ZKt6wHvkq0132ilT+ MbQRnJbatSqL3cUOA4LYDwr0h2dNkHkS5tNbA+fzsKSStCiPc9MJ1xJgqBdQKklxMeFP 4CqVSYg6Gs+oUm2FmvzcJGWLiNDCwxtnOr/tjzRNSq8jedIG/emwr/gBdawwL/GrDY6S Bc4A== X-Gm-Message-State: ALoCoQljSgNZArYprR91lwkwty1JPp58ruDkjQsQ2vp0QG983NVBpcsxd9PxggfmxvKGUqMT50v+ X-Received: by 10.152.10.233 with SMTP id l9mr4649582lab.0.1418644929785; Mon, 15 Dec 2014 04:02:09 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.100 with SMTP id m4ls155757lae.49.gmail; Mon, 15 Dec 2014 04:02:09 -0800 (PST) X-Received: by 10.112.138.9 with SMTP id qm9mr30025185lbb.62.1418644929379; Mon, 15 Dec 2014 04:02:09 -0800 (PST) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id iy10si10215464lbc.71.2014.12.15.04.02.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 15 Dec 2014 04:02:09 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by mail-la0-f54.google.com with SMTP id pv20so9299101lab.13 for ; Mon, 15 Dec 2014 04:02:09 -0800 (PST) X-Received: by 10.112.130.132 with SMTP id oe4mr29604785lbb.82.1418644929284; Mon, 15 Dec 2014 04:02:09 -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.142.69 with SMTP id ru5csp692490lbb; Mon, 15 Dec 2014 04:02:07 -0800 (PST) X-Received: by 10.70.36.236 with SMTP id t12mr50353101pdj.143.1418644925693; Mon, 15 Dec 2014 04:02:05 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id lw5si7840537pdb.42.2014.12.15.04.02.04 for ; Mon, 15 Dec 2014 04:02:05 -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 S1752068AbaLOMCD (ORCPT + 27 others); Mon, 15 Dec 2014 07:02:03 -0500 Received: from mail-yh0-f52.google.com ([209.85.213.52]:48511 "EHLO mail-yh0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751230AbaLOL7o (ORCPT ); Mon, 15 Dec 2014 06:59:44 -0500 Received: by mail-yh0-f52.google.com with SMTP id z6so4977681yhz.39 for ; Mon, 15 Dec 2014 03:59:43 -0800 (PST) X-Received: by 10.236.24.161 with SMTP id x21mr21270391yhx.96.1418644783796; Mon, 15 Dec 2014 03:59:43 -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 d91sm5783468yhq.53.2014.12.15.03.59.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Dec 2014 03:59:43 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, computersforpeace@gmail.com, linux-mtd@lists.infradead.org Cc: lee.jones@linaro.org, kernel@stlinux.com, Angus Clark , Carmelo Amoroso Subject: [PATCH v3 07/13] mtd: st_spi_fsm: Add support for N25Q512 and N25Q00A devices Date: Mon, 15 Dec 2014 11:59:14 +0000 Message-Id: <1418644760-18773-8-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418644760-18773-1-git-send-email-lee.jones@linaro.org> References: <1418644760-18773-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.54 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 This patch adds support for the Micron N25Q512 and N25Q00A Serial Flash devices. Unlike previous Micron devices, it is now mandatory to check the Flags Status Register following a Write or Erase operation. The N25Q512A device presents a further complication in that different variants of the device use different opcodes for the WRITE_1_4_4 operation. Since there is no easy way to determine at runtime which variant is being used, FLASH_CAPS_WRITE_1_4_4 support is removed for N25Q512 devices, resulting in WRITE_1_1_4 being used instead. The following devices have been tested: b2000C + N25Q512A13GSF40G b2000C + N25Q00AA13GSF40G b2147A + N25Q512A83GSF40X Signed-off-by: Angus Clark Signed-off-by: Carmelo Amoroso Signed-off-by: Lee Jones --- drivers/mtd/devices/st_spi_fsm.c | 96 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index 7e6cd26..4fac169 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c @@ -240,12 +240,25 @@ #define S25FL_STATUS_E_ERR 0x20 #define S25FL_STATUS_P_ERR 0x40 +/* N25Q - READ/WRITE/CLEAR NON/VOLATILE STATUS/CONFIG Registers */ +#define N25Q_CMD_RFSR 0x70 +#define N25Q_CMD_CLFSR 0x50 #define N25Q_CMD_WRVCR 0x81 #define N25Q_CMD_RDVCR 0x85 #define N25Q_CMD_RDVECR 0x65 #define N25Q_CMD_RDNVCR 0xb5 #define N25Q_CMD_WRNVCR 0xb1 +/* N25Q Flags Status Register: Error Flags */ +#define N25Q_FLAGS_ERR_ERASE BIT(5) +#define N25Q_FLAGS_ERR_PROG BIT(4) +#define N25Q_FLAGS_ERR_VPP BIT(3) +#define N25Q_FLAGS_ERR_PROT BIT(1) +#define N25Q_FLAGS_ERROR (N25Q_FLAGS_ERR_ERASE | \ + N25Q_FLAGS_ERR_PROG | \ + N25Q_FLAGS_ERR_VPP | \ + N25Q_FLAGS_ERR_PROT) + #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 */ @@ -257,6 +270,7 @@ #define CFG_WRITE_TOGGLE_32BIT_ADDR 0x00000002 #define CFG_ERASESEC_TOGGLE_32BIT_ADDR 0x00000008 #define CFG_S25FL_CHECK_ERROR_FLAGS 0x00000010 +#define CFG_N25Q_CHECK_ERROR_FLAGS 0x00000020 struct stfsm_seq { uint32_t data_size; @@ -399,6 +413,7 @@ static struct flash_info flash_types[] = { (MX25_FLAG | FLASH_FLAG_32BIT_ADDR | FLASH_FLAG_RESET), 70, stfsm_mx25_config}, + /* Micron N25Qxxx */ #define N25Q_FLAG (FLASH_FLAG_READ_WRITE | \ FLASH_FLAG_READ_FAST | \ FLASH_FLAG_READ_1_1_2 | \ @@ -411,10 +426,29 @@ static struct flash_info flash_types[] = { FLASH_FLAG_WRITE_1_4_4) { "n25q128", 0x20ba18, 0, 64 * 1024, 256, N25Q_FLAG, 108, stfsm_n25q_config }, - { "n25q256", 0x20ba19, 0, 64 * 1024, 512, - N25Q_FLAG | FLASH_FLAG_32BIT_ADDR, 108, stfsm_n25q_config }, - { "n25q512", 0x20ba20, 0, 64 * 1024, 1024, - N25Q_FLAG | FLASH_FLAG_32BIT_ADDR, 108, stfsm_n25q_config}, + + /* Micron N25Q256/N25Q512/N25Q00A (32-bit ADDR devices) + * + * Versions are available with or without a dedicated RESET# pin + * (e.g. N25Q512A83GSF40G vs. N25Q512A13GSF40G). To complicate matters, + * the versions that include a RESET# pin (Feature Set = 8) require a + * different opcode for the FLASH_CMD_WRITE_1_4_4 command. + * Unfortunately it is not possible to determine easily at run-time + * which version is being used. We therefore remove support for + * FLASH_FLAG_WRITE_1_4_4 (falling back to FLASH_FLAG_WRITE_1_1_4), and + * defer overall support for RESET# to the board-level platform/Device + * Tree property "reset-signal". + */ +#define N25Q_32BIT_ADDR_FLAG ((N25Q_FLAG | \ + FLASH_FLAG_32BIT_ADDR | \ + FLASH_FLAG_RESET) & \ + ~FLASH_FLAG_WRITE_1_4_4) + { "n25q256", 0x20ba19, 0, 64 * 1024, 512, + N25Q_32BIT_ADDR_FLAG, 108, stfsm_n25q_config}, + { "n25q512", 0x20ba20, 0x1000, 64 * 1024, 1024, + N25Q_32BIT_ADDR_FLAG, 108, stfsm_n25q_config}, + { "n25q00a", 0x20ba21, 0x1000, 64 * 1024, 2048, + N25Q_32BIT_ADDR_FLAG, 108, stfsm_n25q_config}, /* * Spansion S25FLxxxP @@ -892,6 +926,30 @@ static int stfsm_write_fifo(struct stfsm *fsm, const uint32_t *buf, return size; } +static int n25q_clear_flags(struct stfsm *fsm) +{ + struct stfsm_seq seq = { + .seq_opc[0] = (SEQ_OPC_PADS_1 | + SEQ_OPC_CYCLES(8) | + SEQ_OPC_OPCODE(N25Q_CMD_CLFSR) | + SEQ_OPC_CSDEASSERT), + .seq = { + STFSM_INST_CMD1, + STFSM_INST_STOP, + }, + .seq_cfg = (SEQ_CFG_PADS_1 | + SEQ_CFG_READNOTWRITE | + SEQ_CFG_CSDEASSERT | + SEQ_CFG_STARTSEQ), + }; + + stfsm_load_seq(fsm, &seq); + + stfsm_wait_seq(fsm); + + return 0; +} + static int stfsm_enter_32bit_addr(struct stfsm *fsm, int enter) { struct stfsm_seq *seq = &fsm->stfsm_seq_en_32bit_addr; @@ -1252,10 +1310,18 @@ static int stfsm_mx25_config(struct stfsm *fsm) static int stfsm_n25q_config(struct stfsm *fsm) { uint32_t flags = fsm->info->flags; - uint8_t vcr; + uint8_t vcr, sta; int ret = 0; bool soc_reset; + /* + * Check/Clear Error Flags + */ + fsm->configuration |= CFG_N25Q_CHECK_ERROR_FLAGS; + stfsm_read_status(fsm, N25Q_CMD_RFSR, &sta, 1); + if (sta & N25Q_FLAGS_ERROR) + n25q_clear_flags(fsm); + /* Configure 'READ' sequence */ if (flags & FLASH_FLAG_32BIT_ADDR) ret = stfsm_search_prepare_rw_seq(fsm, &fsm->stfsm_seq_read, @@ -1631,6 +1697,7 @@ static int stfsm_write(struct stfsm *fsm, const uint8_t *buf, uint32_t page_buf[FLASH_PAGESIZE_32]; uint8_t *t = (uint8_t *)&tmp; const uint8_t *p; + uint8_t sta; int ret; dev_dbg(fsm->dev, "writing %d bytes to 0x%08x\n", size, offset); @@ -1701,6 +1768,15 @@ static int stfsm_write(struct stfsm *fsm, const uint8_t *buf, if (ret && fsm->configuration & CFG_S25FL_CHECK_ERROR_FLAGS) stfsm_s25fl_clear_status_reg(fsm); + /* N25Q: Check/Clear Error Flags */ + if (fsm->configuration & CFG_N25Q_CHECK_ERROR_FLAGS) { + stfsm_read_status(fsm, N25Q_CMD_RFSR, &sta, 1); + if (sta & N25Q_FLAGS_ERROR) { + n25q_clear_flags(fsm); + ret = -EPROTO; + } + } + /* Exit 32-bit address mode, if required */ if (fsm->configuration & CFG_WRITE_TOGGLE_32BIT_ADDR) stfsm_enter_32bit_addr(fsm, 0); @@ -1743,6 +1819,7 @@ static int stfsm_mtd_read(struct mtd_info *mtd, loff_t from, size_t len, static int stfsm_erase_sector(struct stfsm *fsm, uint32_t offset) { struct stfsm_seq *seq = &stfsm_seq_erase_sector; + uint8_t sta; int ret; dev_dbg(fsm->dev, "erasing sector at 0x%08x\n", offset); @@ -1763,6 +1840,15 @@ static int stfsm_erase_sector(struct stfsm *fsm, uint32_t offset) if (ret && fsm->configuration & CFG_S25FL_CHECK_ERROR_FLAGS) stfsm_s25fl_clear_status_reg(fsm); + /* N25Q: Check/Clear Error Flags */ + if (fsm->configuration & CFG_N25Q_CHECK_ERROR_FLAGS) { + stfsm_read_status(fsm, N25Q_CMD_RFSR, &sta, 1); + if (sta & N25Q_FLAGS_ERROR) { + n25q_clear_flags(fsm); + ret = -EPROTO; + } + } + /* Exit 32-bit address mode, if required */ if (fsm->configuration & CFG_ERASESEC_TOGGLE_32BIT_ADDR) stfsm_enter_32bit_addr(fsm, 0);