From patchwork Thu Jul 23 13:11:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratyush Yadav X-Patchwork-Id: 1334888 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 (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.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=yadavpratyush.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=bki1sQWR; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BCCT024xsz9sRR for ; Thu, 23 Jul 2020 23:13:40 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=7tUy3UvhSvmuY2ePkx6ler4KY5zdnKfE4GNSf+q5am0=; b=bki1sQWR4030eMJRsceP2hX7R TN5f3791Ox8LIhi5jpWTZv+a2T4uDvls5ooHlhFA3OYXzWTpz8xxnL5Sh5u9y6EFpCswk6mnKIlAV VLYH5YvnIAVvXQQR9sdGop6Jrq4oLDc8/PP/4p4h5Yh3aeJ/NgyiEfscSVTlVryDCc4H9BY2Ozc02 uJqVj+UyWq2VqD1/TC6xyI9wfCEbjxha5A2yMNeDThGEtE5Qa1bNbwoBKAIrdGVj4aIjspYVPkxpS OZG3afK0HZsxdbgsdQkx0/VyM0lv1r7AtGjCqv2FIEsAWt0OtTmIOqWENEoVK+890/4yqQBOH43kF 9YsLLCueA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyb1Z-0003Uo-Ti; Thu, 23 Jul 2020 13:12:38 +0000 Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyb1T-0003T0-7M for linux-mtd@lists.infradead.org; Thu, 23 Jul 2020 13:12:34 +0000 X-Originating-IP: 42.109.196.68 Received: from localhost.localdomain (unknown [42.109.196.68]) (Authenticated sender: me@yadavpratyush.com) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 986591C0014; Thu, 23 Jul 2020 13:12:26 +0000 (UTC) From: Pratyush Yadav To: Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v11 01/14] mtd: spi-nor: core: add spi_nor_{read, write}_reg() helpers Date: Thu, 23 Jul 2020 18:41:50 +0530 Message-Id: <20200723131203.40916-2-me@yadavpratyush.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200723131203.40916-1-me@yadavpratyush.com> References: <20200723131203.40916-1-me@yadavpratyush.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200723_091231_476664_0C783367 X-CRM114-Status: GOOD ( 10.56 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [217.70.183.197 listed in wl.mailspike.net] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [217.70.183.197 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pratyush Yadav , Boris Brezillon , Sekhar Nori , Pratyush Yadav Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Pratyush Yadav They are thin wrappers around nor->controller_ops->{read,write}_reg(). In a future commit DTR support will be added. These ops can not be supported by the {read,write}_reg() hooks and these helpers will make it easier to reject those calls. Signed-off-by: Pratyush Yadav --- drivers/mtd/spi-nor/core.c | 110 ++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 63 deletions(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 65eff4ce6ab1..2ccf2c154779 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -82,6 +82,18 @@ static int spi_nor_spimem_exec_op(struct spi_nor *nor, struct spi_mem_op *op) return spi_mem_exec_op(nor->spimem, op); } +static int spi_nor_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, + size_t len) +{ + return nor->controller_ops->read_reg(nor, opcode, buf, len); +} + +static int spi_nor_write_reg(struct spi_nor *nor, u8 opcode, const u8 *buf, + size_t len) +{ + return nor->controller_ops->write_reg(nor, opcode, buf, len); +} + /** * spi_nor_spimem_read_data() - read data from flash's memory region via * spi-mem @@ -228,10 +240,8 @@ int spi_nor_write_enable(struct spi_nor *nor) SPI_MEM_OP_NO_DATA); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->write_reg(nor, SPINOR_OP_WREN, - NULL, 0); - } + } else + ret = spi_nor_write_reg(nor, SPINOR_OP_WREN, NULL, 0); if (ret) dev_dbg(nor->dev, "error %d on Write Enable\n", ret); @@ -257,10 +267,8 @@ int spi_nor_write_disable(struct spi_nor *nor) SPI_MEM_OP_NO_DATA); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->write_reg(nor, SPINOR_OP_WRDI, - NULL, 0); - } + } else + ret = spi_nor_write_reg(nor, SPINOR_OP_WRDI, NULL, 0); if (ret) dev_dbg(nor->dev, "error %d on Write Disable\n", ret); @@ -288,10 +296,8 @@ static int spi_nor_read_sr(struct spi_nor *nor, u8 *sr) SPI_MEM_OP_DATA_IN(1, sr, 1)); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDSR, - sr, 1); - } + } else + ret = spi_nor_read_reg(nor, SPINOR_OP_RDSR, sr, 1); if (ret) dev_dbg(nor->dev, "error %d reading SR\n", ret); @@ -319,10 +325,8 @@ static int spi_nor_read_fsr(struct spi_nor *nor, u8 *fsr) SPI_MEM_OP_DATA_IN(1, fsr, 1)); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDFSR, - fsr, 1); - } + } else + ret = spi_nor_read_reg(nor, SPINOR_OP_RDFSR, fsr, 1); if (ret) dev_dbg(nor->dev, "error %d reading FSR\n", ret); @@ -351,9 +355,8 @@ static int spi_nor_read_cr(struct spi_nor *nor, u8 *cr) SPI_MEM_OP_DATA_IN(1, cr, 1)); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDCR, cr, 1); - } + } else + ret = spi_nor_read_reg(nor, SPINOR_OP_RDCR, cr, 1); if (ret) dev_dbg(nor->dev, "error %d reading CR\n", ret); @@ -384,12 +387,11 @@ int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable) SPI_MEM_OP_NO_DATA); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->write_reg(nor, - enable ? SPINOR_OP_EN4B : - SPINOR_OP_EX4B, - NULL, 0); - } + } else + ret = spi_nor_write_reg(nor, + enable ? SPINOR_OP_EN4B : + SPINOR_OP_EX4B, + NULL, 0); if (ret) dev_dbg(nor->dev, "error %d setting 4-byte mode\n", ret); @@ -420,10 +422,8 @@ static int spansion_set_4byte_addr_mode(struct spi_nor *nor, bool enable) SPI_MEM_OP_DATA_OUT(1, nor->bouncebuf, 1)); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->write_reg(nor, SPINOR_OP_BRWR, - nor->bouncebuf, 1); - } + } else + ret = spi_nor_write_reg(nor, SPINOR_OP_BRWR, nor->bouncebuf, 1); if (ret) dev_dbg(nor->dev, "error %d setting 4-byte mode\n", ret); @@ -452,10 +452,8 @@ int spi_nor_write_ear(struct spi_nor *nor, u8 ear) SPI_MEM_OP_DATA_OUT(1, nor->bouncebuf, 1)); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->write_reg(nor, SPINOR_OP_WREAR, - nor->bouncebuf, 1); - } + } else + ret = spi_nor_write_reg(nor, SPINOR_OP_WREAR, nor->bouncebuf, 1); if (ret) dev_dbg(nor->dev, "error %d writing EAR\n", ret); @@ -483,10 +481,8 @@ int spi_nor_xread_sr(struct spi_nor *nor, u8 *sr) SPI_MEM_OP_DATA_IN(1, sr, 1)); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->read_reg(nor, SPINOR_OP_XRDSR, - sr, 1); - } + } else + ret = spi_nor_read_reg(nor, SPINOR_OP_XRDSR, sr, 1); if (ret) dev_dbg(nor->dev, "error %d reading XRDSR\n", ret); @@ -528,10 +524,8 @@ static void spi_nor_clear_sr(struct spi_nor *nor) SPI_MEM_OP_NO_DATA); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->write_reg(nor, SPINOR_OP_CLSR, - NULL, 0); - } + } else + ret = spi_nor_write_reg(nor, SPINOR_OP_CLSR, NULL, 0); if (ret) dev_dbg(nor->dev, "error %d clearing SR\n", ret); @@ -592,10 +586,8 @@ static void spi_nor_clear_fsr(struct spi_nor *nor) SPI_MEM_OP_NO_DATA); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->write_reg(nor, SPINOR_OP_CLFSR, - NULL, 0); - } + } else + ret = spi_nor_write_reg(nor, SPINOR_OP_CLFSR, NULL, 0); if (ret) dev_dbg(nor->dev, "error %d clearing FSR\n", ret); @@ -736,10 +728,8 @@ static int spi_nor_write_sr(struct spi_nor *nor, const u8 *sr, size_t len) SPI_MEM_OP_DATA_OUT(len, sr, 1)); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->write_reg(nor, SPINOR_OP_WRSR, - sr, len); - } + } else + ret = spi_nor_write_reg(nor, SPINOR_OP_WRSR, sr, len); if (ret) { dev_dbg(nor->dev, "error %d writing SR\n", ret); @@ -938,10 +928,8 @@ static int spi_nor_write_sr2(struct spi_nor *nor, const u8 *sr2) SPI_MEM_OP_DATA_OUT(1, sr2, 1)); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->write_reg(nor, SPINOR_OP_WRSR2, - sr2, 1); - } + } else + ret = spi_nor_write_reg(nor, SPINOR_OP_WRSR2, sr2, 1); if (ret) { dev_dbg(nor->dev, "error %d writing SR2\n", ret); @@ -972,10 +960,8 @@ static int spi_nor_read_sr2(struct spi_nor *nor, u8 *sr2) SPI_MEM_OP_DATA_IN(1, sr2, 1)); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDSR2, - sr2, 1); - } + } else + ret = spi_nor_read_reg(nor, SPINOR_OP_RDSR2, sr2, 1); if (ret) dev_dbg(nor->dev, "error %d reading SR2\n", ret); @@ -1003,10 +989,8 @@ static int spi_nor_erase_chip(struct spi_nor *nor) SPI_MEM_OP_NO_DATA); ret = spi_mem_exec_op(nor->spimem, &op); - } else { - ret = nor->controller_ops->write_reg(nor, SPINOR_OP_CHIP_ERASE, - NULL, 0); - } + } else + ret = spi_nor_write_reg(nor, SPINOR_OP_CHIP_ERASE, NULL, 0); if (ret) dev_dbg(nor->dev, "error %d erasing chip\n", ret); @@ -1158,8 +1142,8 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr) addr >>= 8; } - return nor->controller_ops->write_reg(nor, nor->erase_opcode, - nor->bouncebuf, nor->addr_width); + return spi_nor_write_reg(nor, nor->erase_opcode, nor->bouncebuf, + nor->addr_width); } /**