From patchwork Fri Oct 12 08:48:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 982920 X-Patchwork-Delegate: tudor.ambarus@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.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="smnxJbdD"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42WhXH1Bw2z9s3T for ; Fri, 12 Oct 2018 19:56:31 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=2aFskyR19TQf+vOmTUGu+/ueG2ZDScHZBZJVsFPW+qk=; b=smnxJbdDkYj82AtzqclIXk1vE7 dSzbRK5wnWsD6UJhzHPTxVcgOH/G0aY48Mvzz0WEW32BKBRxfCzYqQKApEGArLWnCJk3e7y5cQ3AG Frim29rKiU7cECfmj0eskAwP96QqQ6x5lv4+mxfSR0jYT4BuYjeWHPB5yO27PaO1IXaIGwu9D+MuP kxHHHRmnTj+L1LugI4tV1lgnQsaVlUBoKbQxfAauEpZuar4h3FJMqzAzHsVX7TsVWGSCSAz3sJpCC 95PCEVz5ei4FGTdgjO468jxXJyDrvvcFXO9fn69hVUhRb7d9pyXcYBDrsndsYxgEPOBD+xBEU+Zd7 1f9Tin1A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gAtF5-0007fi-TM; Fri, 12 Oct 2018 08:56:19 +0000 Received: from mail.bootlin.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gAt82-0001ky-Vx for linux-mtd@lists.infradead.org; Fri, 12 Oct 2018 08:49:47 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 104CD208F4; Fri, 12 Oct 2018 10:48:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost.localdomain (AAubervilliers-681-1-7-245.w90-88.abo.wanadoo.fr [90.88.129.245]) by mail.bootlin.com (Postfix) with ESMTPSA id 6A64720DBD; Fri, 12 Oct 2018 10:48:30 +0200 (CEST) From: Boris Brezillon To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , linux-mtd@lists.infradead.org, Yogesh Gaur , Vignesh R , Cyrille Pitchen Subject: [PATCH RFC 09/18] mtd: spi-nor: Add spi_nor_{read, write}_reg() helpers Date: Fri, 12 Oct 2018 10:48:16 +0200 Message-Id: <20181012084825.23697-10-boris.brezillon@bootlin.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20181012084825.23697-1-boris.brezillon@bootlin.com> References: <20181012084825.23697-1-boris.brezillon@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181012_014903_421995_089AE076 X-CRM114-Status: GOOD ( 13.20 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Julien Su , Mark Brown , Mason Yang , linux-spi@vger.kernel.org, zhengxunli@mxic.com.tw MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add the spi_nor_{read,write}_reg() helpers (which are just thin wrappers around ->{read,write}_reg()) in order to prepare things for X-X-X modes support. The idea is to reject calls to ->{read,write}_reg() when the chip has entered such a mode, because SPI NOR controller drivers are not ready for that. Signed-off-by: Boris Brezillon --- drivers/mtd/spi-nor/spi-nor.c | 48 ++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 7fad94588c55..42f299a0b76f 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -148,6 +148,16 @@ static int spi_nor_nodata_op(struct spi_nor *nor, struct spi_mem_op *op) return spi_nor_exec_op(nor, op, NULL, NULL, 0); } +static int spi_nor_read_reg(struct spi_nor *nor, u8 opcode, u8 *val, int len) +{ + return nor->read_reg(nor, opcode, val, len); +} + +static int spi_nor_write_reg(struct spi_nor *nor, u8 opcode, u8 *val, int len) +{ + return nor->write_reg(nor, opcode, val, len); +} + static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t ofs, size_t len, u8 *buf) { @@ -283,7 +293,7 @@ static int read_sr(struct spi_nor *nor) ret = spi_nor_data_op(nor, &op, &val, 1); } else { - ret = nor->read_reg(nor, SPINOR_OP_RDSR, &val, 1); + ret = spi_nor_read_reg(nor, SPINOR_OP_RDSR, &val, 1); } if (ret < 0) { @@ -313,7 +323,7 @@ static int read_fsr(struct spi_nor *nor) ret = spi_nor_data_op(nor, &op, &val, 1); } else { - ret = nor->read_reg(nor, SPINOR_OP_RDFSR, &val, 1); + ret = spi_nor_read_reg(nor, SPINOR_OP_RDFSR, &val, 1); } if (ret < 0) { @@ -343,7 +353,7 @@ static int read_cr(struct spi_nor *nor) ret = spi_nor_data_op(nor, &op, &val, 1); } else { - ret = nor->read_reg(nor, SPINOR_OP_RDCR, &val, 1); + ret = spi_nor_read_reg(nor, SPINOR_OP_RDCR, &val, 1); } if (ret < 0) { @@ -371,7 +381,7 @@ static int write_sr(struct spi_nor *nor, u8 val) } nor->cmd_buf[0] = val; - return nor->write_reg(nor, SPINOR_OP_WRSR, nor->cmd_buf, 1); + return spi_nor_write_reg(nor, SPINOR_OP_WRSR, nor->cmd_buf, 1); } @@ -391,7 +401,7 @@ static int write_enable(struct spi_nor *nor) return spi_nor_nodata_op(nor, &op); } - return nor->write_reg(nor, SPINOR_OP_WREN, NULL, 0); + return spi_nor_write_reg(nor, SPINOR_OP_WREN, NULL, 0); } /* @@ -409,7 +419,7 @@ static int write_disable(struct spi_nor *nor) return spi_nor_nodata_op(nor, &op); } - return nor->write_reg(nor, SPINOR_OP_WRDI, NULL, 0); + return spi_nor_write_reg(nor, SPINOR_OP_WRDI, NULL, 0); } static struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd) @@ -515,7 +525,7 @@ static int set_4byte(struct spi_nor *nor, bool enable) return spi_nor_data_op(nor, &op, nor->cmd_buf, 1); } - return nor->write_reg(nor, SPINOR_OP_BRWR, nor->cmd_buf, 1); + return spi_nor_write_reg(nor, SPINOR_OP_BRWR, nor->cmd_buf, 1); } static int xread_sr(struct spi_nor *nor, u8 *sr) @@ -530,7 +540,7 @@ static int xread_sr(struct spi_nor *nor, u8 *sr) return spi_nor_data_op(nor, &op, sr, 1); } - return nor->read_reg(nor, SPINOR_OP_XRDSR, sr, 1); + return spi_nor_read_reg(nor, SPINOR_OP_XRDSR, sr, 1); } static int s3an_sr_ready(struct spi_nor *nor) @@ -560,7 +570,7 @@ static int clear_sr(struct spi_nor *nor) return spi_nor_nodata_op(nor, &op); } - return nor->write_reg(nor, SPINOR_OP_CLSR, NULL, 0); + return spi_nor_write_reg(nor, SPINOR_OP_CLSR, NULL, 0); } static int spi_nor_sr_ready(struct spi_nor *nor) @@ -594,7 +604,7 @@ static int clear_fsr(struct spi_nor *nor) return spi_nor_nodata_op(nor, &op); } - return nor->write_reg(nor, SPINOR_OP_CLFSR, NULL, 0); + return spi_nor_write_reg(nor, SPINOR_OP_CLFSR, NULL, 0); } static int spi_nor_fsr_ready(struct spi_nor *nor) @@ -692,7 +702,7 @@ static int erase_chip(struct spi_nor *nor) return spi_nor_nodata_op(nor, &op); } - return nor->write_reg(nor, SPINOR_OP_CHIP_ERASE, NULL, 0); + return spi_nor_write_reg(nor, SPINOR_OP_CHIP_ERASE, NULL, 0); } static int spi_nor_lock_and_prep(struct spi_nor *nor, enum spi_nor_ops ops) @@ -774,7 +784,7 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr) addr >>= 8; } - return nor->write_reg(nor, nor->erase_opcode, buf, nor->addr_width); + return spi_nor_write_reg(nor, nor->erase_opcode, buf, nor->addr_width); } /** @@ -1873,7 +1883,7 @@ static int read_id(struct spi_nor *nor, u8 *id) return spi_nor_data_op(nor, &op, id, SPI_NOR_MAX_ID_LEN); } - return nor->read_reg(nor, SPINOR_OP_RDID, id, SPI_NOR_MAX_ID_LEN); + return spi_nor_read_reg(nor, SPINOR_OP_RDID, id, SPI_NOR_MAX_ID_LEN); } static const struct flash_info *spi_nor_read_id(struct spi_nor *nor) @@ -2102,7 +2112,7 @@ static int write_sr_cr(struct spi_nor *nor, u8 *sr_cr) ret = spi_nor_data_op(nor, &op, sr_cr, 2); } else { - ret = nor->write_reg(nor, SPINOR_OP_WRSR, sr_cr, 2); + ret = spi_nor_write_reg(nor, SPINOR_OP_WRSR, sr_cr, 2); } if (ret < 0) { @@ -2258,7 +2268,7 @@ static int write_sr2(struct spi_nor *nor, u8 sr2) return spi_nor_data_op(nor, &op, &sr2, 1); } - return nor->write_reg(nor, SPINOR_OP_WRSR2, &sr2, 1); + return spi_nor_write_reg(nor, SPINOR_OP_WRSR2, &sr2, 1); } static int read_sr2(struct spi_nor *nor, u8 *sr2) @@ -2273,7 +2283,7 @@ static int read_sr2(struct spi_nor *nor, u8 *sr2) return spi_nor_data_op(nor, &op, sr2, 1); } - return nor->read_reg(nor, SPINOR_OP_RDSR2, sr2, 1); + return spi_nor_read_reg(nor, SPINOR_OP_RDSR2, sr2, 1); } /** @@ -4024,8 +4034,8 @@ static int macronix_set_4byte(struct spi_nor *nor, bool enable) return spi_nor_nodata_op(nor, &op); } - return nor->write_reg(nor, enable ? SPINOR_OP_EN4B : SPINOR_OP_EX4B, - NULL, 0); + return spi_nor_write_reg(nor, enable ? SPINOR_OP_EN4B : SPINOR_OP_EX4B, + NULL, 0); } static int micron_set_4byte(struct spi_nor *nor, bool enable) @@ -4052,7 +4062,7 @@ static int write_ear(struct spi_nor *nor, u8 ear) } nor->cmd_buf[0] = ear; - return nor->write_reg(nor, SPINOR_OP_WREAR, nor->cmd_buf, 1); + return spi_nor_write_reg(nor, SPINOR_OP_WREAR, nor->cmd_buf, 1); } static int winbond_set_4byte(struct spi_nor *nor, bool enable)