From patchwork Wed Jul 10 10:03:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Li X-Patchwork-Id: 1130318 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="eGYK6bSQ"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45kFC35MdVz9sN4 for ; Wed, 10 Jul 2019 20:03:59 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 64CD8C21E4F; Wed, 10 Jul 2019 10:03:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 97523C21E4F; Wed, 10 Jul 2019 10:03:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 65A36C21E4F; Wed, 10 Jul 2019 10:03:52 +0000 (UTC) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80082.outbound.protection.outlook.com [40.107.8.82]) by lists.denx.de (Postfix) with ESMTPS id CFD74C21DD7 for ; Wed, 10 Jul 2019 10:03:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BwdwDwaZbErzA1V+uIDB54sCzlOzMj0vg1VY+KvByQI=; b=eGYK6bSQWR2mJRRUvHbdoHxw0/F9SwwkiOi2p1xHZuXIAa3K0OqJMV0gexZV+xsAZv7omluIu9IMfsJiAlQtNCyD0ndxahIQnGkAVzh9IYFRxjL/pob3EXrwSXTZdGZiz5g6e5kiVDNg7VsmHg2Y9JZ5GXHDYJ2xzoahzdFpVGM= Received: from VI1PR04MB4414.eurprd04.prod.outlook.com (20.177.55.153) by VI1PR04MB4815.eurprd04.prod.outlook.com (20.177.48.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2052.18; Wed, 10 Jul 2019 10:03:50 +0000 Received: from VI1PR04MB4414.eurprd04.prod.outlook.com ([fe80::6517:7774:1033:6466]) by VI1PR04MB4414.eurprd04.prod.outlook.com ([fe80::6517:7774:1033:6466%7]) with mapi id 15.20.2052.020; Wed, 10 Jul 2019 10:03:50 +0000 From: Ye Li To: "jagan@openedev.com" Thread-Topic: [PATCH] spi: fsl_qspi: Fix flash write issue on i.MX7ULP Thread-Index: AQHVNwbFST02jsMwv0igFJbwEplMjw== Date: Wed, 10 Jul 2019 10:03:49 +0000 Message-ID: <1562753010-44601-1-git-send-email-ye.li@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: HK2PR0401CA0009.apcprd04.prod.outlook.com (2603:1096:202:2::19) To VI1PR04MB4414.eurprd04.prod.outlook.com (2603:10a6:803:6e::25) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ye.li@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.68] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b3776da9-daa9-4cec-a3bc-08d7051de7ba x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:VI1PR04MB4815; x-ms-traffictypediagnostic: VI1PR04MB4815: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6790; x-forefront-prvs: 0094E3478A x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(39860400002)(136003)(396003)(346002)(376002)(366004)(189003)(199004)(2501003)(86362001)(102836004)(36756003)(6916009)(66556008)(64756008)(66476007)(52116002)(486006)(71190400001)(71200400001)(6486002)(5660300002)(4326008)(81156014)(66446008)(81166006)(386003)(6512007)(2906002)(8936002)(44832011)(6116002)(66066001)(14454004)(66946007)(50226002)(53936002)(7736002)(186003)(478600001)(99286004)(5640700003)(26005)(68736007)(8676002)(476003)(2351001)(54906003)(6436002)(25786009)(316002)(2616005)(256004)(305945005)(6506007)(1730700003)(3846002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR04MB4815; H:VI1PR04MB4414.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 6Aip0l0GHfJbzwpp+r9Y/m7i9pI5KQivnYjnbQ+dsJu4zqR6HkjmgEyHu2yXwsVtBkJunPpSm9XgSoZmswGF0MoZPj/rINKMOd4yQ+r1npZTJ3YETWczs8QdCPc+X6KX7ITjqU5BJ7UM68NyYDlzt+bPCOV0OQUI7kf0DUi3d1gNPsDFqd0JF/qEa0SwhVu7ruPR/d/Vw3X7UbON4DV37fLWVNWOikbWiC+oQMSzjXefAykQNdSliAxVdy0Orox7j4H2lpx/wkLxthiBrk+dsCqxXoTHoxp4PgxPGGY7W9X1ceX7SC3S1IXM0U8GVDuhf8sPYfWb8NYElaucwcvcQAS0uBRcs3pSX3DklpGk/pzYiYEL8wZQrmZNLrf3TUQ186IVaboH7PDtPvCYFYGDoiOhpBwc5TxVScMb0mtpV10= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b3776da9-daa9-4cec-a3bc-08d7051de7ba X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Jul 2019 10:03:50.0371 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ye.li@nxp.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4815 Cc: "u-boot@lists.denx.de" , dl-uboot-imx Subject: [U-Boot] [PATCH] spi: fsl_qspi: Fix flash write issue on i.MX7ULP X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The page write sequence in spi-mem is changed with orignal spi-flash. When the max_write_size is set by driver, the orignal sequence is 1. WREN 2. write max_write_size data to flash 3. wait for WIP clean 4. back to #1 if having data remained in a page. The new sequence is: 1. WREN 2. write (max_write_size - command length) data to flash 3. back to #2 if having data remained in a page 4. wait for WIP clean i.MX7ULP has 64 bytes TX buffer (max_write_size), while other iMX chips have 512 bytes (page size is 256). So when adapt qspi with the new sequence, we have to check the WIP before each write on mx7ulp. Otherwise the WIP may set due to previous write is not completed by flash device, then cause current write failed. Signed-off-by: Ye Li --- drivers/spi/fsl_qspi.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/spi/fsl_qspi.c b/drivers/spi/fsl_qspi.c index 1598c4f..e958b6a 100644 --- a/drivers/spi/fsl_qspi.c +++ b/drivers/spi/fsl_qspi.c @@ -29,6 +29,7 @@ DECLARE_GLOBAL_DATA_PTR; #define OFFSET_BITS_MASK GENMASK(23, 0) #define FLASH_STATUS_WEL 0x02 +#define FLASH_STATUS_WIP 0x01 /* SEQID */ #define SEQID_WREN 1 @@ -634,6 +635,27 @@ static void qspi_op_write(struct fsl_qspi_priv *priv, u8 *txbuf, u32 len) QSPI_MCR_RESERVED_MASK | QSPI_MCR_END_CFD_LE); qspi_write32(priv->flags, ®s->rbct, QSPI_RBCT_RXBRD_USEIPS); + if (TX_BUFFER_SIZE <= 256) { + status_reg = 0; + do { + WATCHDOG_RESET(); + + qspi_write32(priv->flags, ®s->ipcr, + (SEQID_RDSR << QSPI_IPCR_SEQID_SHIFT) | 1); + while (qspi_read32(priv->flags, ®s->sr) & QSPI_SR_BUSY_MASK) + ; + + reg = qspi_read32(priv->flags, ®s->rbsr); + if (reg & QSPI_RBSR_RDBFL_MASK) { + status_reg = qspi_read32(priv->flags, ®s->rbdr[0]); + status_reg = qspi_endian_xchg(status_reg); + } + qspi_write32(priv->flags, ®s->mcr, + qspi_read32(priv->flags, ®s->mcr) | + QSPI_MCR_CLR_RXF_MASK); + } while ((status_reg & FLASH_STATUS_WIP) == FLASH_STATUS_WIP); + } + status_reg = 0; while ((status_reg & FLASH_STATUS_WEL) != FLASH_STATUS_WEL) { WATCHDOG_RESET();