+From patchwork Wed Nov 20 09:15:04 2024
+Content-Type: text/plain; charset="utf-8"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+X-Patchwork-Submitter: Md Sadre Alam <quic_mdalam@quicinc.com>
+X-Patchwork-Id: 2013501
+Return-Path:
+ <linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>
+X-Original-To: incoming@patchwork.ozlabs.org
+Delivered-To: patchwork-incoming@legolas.ozlabs.org
+Authentication-Results: legolas.ozlabs.org;
+ dkim=pass (2048-bit key;
+ secure) header.d=lists.infradead.org header.i=@lists.infradead.org
+ header.a=rsa-sha256 header.s=bombadil.20210309 header.b=EI114Wyi;
+ dkim=fail reason="signature verification failed" (2048-bit key;
+ unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256
+ header.s=qcppdkim1 header.b=WgJ5on5Q;
+ dkim-atps=neutral
+Authentication-Results: legolas.ozlabs.org;
+ spf=none (no SPF record) smtp.mailfrom=lists.infradead.org
+ (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org;
+ envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;
+ receiver=patchwork.ozlabs.org)
+Received: from bombadil.infradead.org (bombadil.infradead.org
+ [IPv6:2607:7c80:54:3::133])
+ (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
+ key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384)
+ (No client certificate requested)
+ by legolas.ozlabs.org (Postfix) with ESMTPS id 4XtbMW1JfFz1xyG
+ for <incoming@patchwork.ozlabs.org>; Wed, 20 Nov 2024 20:16:23 +1100 (AEDT)
+DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
+ d=lists.infradead.org; s=bombadil.20210309; h=Sender:
+ Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:
+ List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:
+ Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description:
+ Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:
+ List-Owner; bh=HhmgnJkVgny0u3hKiTd0ZM4cwdwqDHQn7f5raP0Z97Q=; b=EI114WyiL0woYU
+ WPjsi5XhHUI2CGLrmf8w0ScC9Pq7PFPwTPGxLYcoSh0JNv/FIax+J93VC5zYRp68aD4mTdTjU6bra
+ kTYGxoBj28Lwiy1jmYm0SWp8dPzX2hCg1lNWr9mP+JjnhuZpyt26qUJnshLyQbVgv8uoEiYGpJjIv
+ GBwOKIvs0vkaJy2E1MBvCO2/+qlNpOlz83wg1tF8uS4MJF+fjWgmVHBrXfRoTlEk6CJumTvpluqNx
+ nzaRMXONO/wYP03WjutalMhZJsQpInGIZhhKL8TOksrLF2q2b4gzF1JAucwPq78p0bWAcgS2ih8vP
+ 564SGleqnhz8GQTtUxog==;
+Received: from localhost ([::1] helo=bombadil.infradead.org)
+ by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux))
+ id 1tDgom-0000000Esn9-19FP;
+ Wed, 20 Nov 2024 09:16:12 +0000
+Received: from mx0b-0031df01.pphosted.com ([205.220.180.131])
+ by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux))
+ id 1tDgoi-0000000EsiZ-1EXE
+ for linux-mtd@lists.infradead.org;
+ Wed, 20 Nov 2024 09:16:10 +0000
+Received: from pps.filterd (m0279873.ppops.net [127.0.0.1])
+ by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id
+ 4AK9FRJU010557;
+ Wed, 20 Nov 2024 09:16:00 GMT
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=
+ cc:content-transfer-encoding:content-type:date:from:in-reply-to
+ :message-id:mime-version:references:subject:to; s=qcppdkim1; bh=
+ 5iRCp4ZP77j9GA9UB1rMArUv8juFZCi6KdJ0Pw/qPiM=; b=WgJ5on5QibUuTZPB
+ Ps89rgba/1Sz4aAyNPfSD9p3o4Lkpefh8wQBsnNvyMAqm6bP9GqT4GsoLIWzh2iL
+ f+NE+/ukvlaLa7P7MQHd14J0blNY2tD9ooc8NodYJJNu1Ul84oegXRuGSTvqh5h7
+ Xm2jOZDpHs7GIB/opkfbaLyFkMdDmMo8zBjL338260tHaKQf5vc62PNv6I5roF2O
+ QictV4vxOJvogxIcNrtAtGwkgsY8+UKYiK0Kf5J7JV7QpK1ejDCqv1NcNPu/87tp
+ u1a5iWy5iFKPldKgO0B/sAvGc2y8tw3Td8lnu2+CQAdyNMVUnBcB71XGvkrINO+y
+ vVURBw==
+Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com
+ [199.106.103.254])
+ by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 43091mda79-1
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);
+ Wed, 20 Nov 2024 09:15:59 +0000 (GMT)
+Received: from nasanex01a.na.qualcomm.com (nasanex01a.na.qualcomm.com
+ [10.52.223.231])
+ by NASANPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id
+ 4AK9FwXk025630
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT);
+ Wed, 20 Nov 2024 09:15:58 GMT
+Received: from hu-mdalam-blr.qualcomm.com (10.80.80.8) by
+ nasanex01a.na.qualcomm.com (10.52.223.231) with Microsoft SMTP Server
+ (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
+ 15.2.1544.9; Wed, 20 Nov 2024 01:15:53 -0800
From: Md Sadre Alam <quic_mdalam@quicinc.com>
-Date: Sun, 22 Sep 2024 17:03:49 +0530
-Subject: [PATCH] spi: spi-qpic: add driver for QCOM SPI NAND flash Interface
+To: <broonie@kernel.org>, <robh@kernel.org>, <krzk+dt@kernel.org>,
+ <conor+dt@kernel.org>, <andersson@kernel.org>,
+ <konradybcio@kernel.org>, <miquel.raynal@bootlin.com>,
+ <richard@nod.at>, <vigneshr@ti.com>,
+ <manivannan.sadhasivam@linaro.org>, <linux-arm-msm@vger.kernel.org>,
+ <linux-spi@vger.kernel.org>, <devicetree@vger.kernel.org>,
+ <linux-kernel@vger.kernel.org>, <linux-mtd@lists.infradead.org>
+CC: <quic_srichara@quicinc.com>, <quic_varada@quicinc.com>,
+ <quic_mdalam@quicinc.com>
+Subject: [PATCH v14 6/8] spi: spi-qpic: add driver for QCOM SPI NAND flash
+ Interface
+Date: Wed, 20 Nov 2024 14:45:04 +0530
+Message-ID: <20241120091507.1404368-7-quic_mdalam@quicinc.com>
+X-Mailer: git-send-email 2.34.1
+In-Reply-To: <20241120091507.1404368-1-quic_mdalam@quicinc.com>
+References: <20241120091507.1404368-1-quic_mdalam@quicinc.com>
+MIME-Version: 1.0
+X-Originating-IP: [10.80.80.8]
+X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To
+ nasanex01a.na.qualcomm.com (10.52.223.231)
+X-QCInternal: smtphost
+X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800
+ signatures=585085
+X-Proofpoint-ORIG-GUID: Ma2z9oeQxcw35J8DzEJ64cF8a3mxAzPO
+X-Proofpoint-GUID: Ma2z9oeQxcw35J8DzEJ64cF8a3mxAzPO
+X-Proofpoint-Virus-Version: vendor=baseguard
+ engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29
+ definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01
+X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0
+ suspectscore=0
+ impostorscore=0 spamscore=0 priorityscore=1501 phishscore=0 malwarescore=0
+ clxscore=1015 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 adultscore=0
+ mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1
+ engine=8.19.0-2409260000 definitions=main-2411200063
+X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3
+X-CRM114-CacheID: sfid-20241120_011608_535555_EC8A73C5
+X-CRM114-Status: GOOD ( 24.86 )
+X-Spam-Score: -2.8 (--)
+X-Spam-Report: Spam detection software,
+ running on the system "bombadil.infradead.org",
+ has NOT identified this incoming email as spam. The original
+ message has been attached to this so you can view it or label
+ similar future email. If you have any questions, see
+ the administrator of that system for details.
+ Content preview: This driver implements support for the SPI-NAND mode of
+ QCOM
+ NAND Flash Interface as a SPI-MEM controller with pipelined ECC
+ capability.
+ Co-developed-by: Sricharan Ramabadhran <quic_srichara@quicinc.com>
+ Signed-off-by:
+ Sricharan Ramabadhran <quic_srichara@quicinc.com> Co-developed-by:
+ Varadarajan
+ Narayanan <quic_varada@quicinc.com> Sig [...]
+ Content analysis details: (-2.8 points, 5.0 required)
+ pts rule name description
+ ---- ----------------------
+ --------------------------------------------------
+ 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to
+ Validity was blocked. See
+ https://knowledge.validity.com/hc/en-us/articles/20961730681243
+ for more information.
+ [205.220.180.131 listed in
+ bl.score.senderscore.com]
+ 0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to
+ Validity was blocked. See
+ https://knowledge.validity.com/hc/en-us/articles/20961730681243
+ for more information.
+ [205.220.180.131 listed in
+ sa-accredit.habeas.com]
+ -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low
+ trust
+ [205.220.180.131 listed in list.dnswl.org]
+ 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The
+ query to Validity was blocked. See
+ https://knowledge.validity.com/hc/en-us/articles/20961730681243
+ for more information.
+ [205.220.180.131 listed in
+ sa-trusted.bondedsender.org]
+ -0.0 SPF_PASS SPF: sender matches SPF record
+ 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record
+ -0.1 DKIM_VALID Message has at least one valid DKIM or DK
+ signature
+ -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from
+ envelope-from domain
+ -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from
+ author's
+ domain
+ 0.1 DKIM_SIGNED Message has a DKIM or DK signature,
+ not necessarily valid
+ -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1%
+ [score: 0.0000]
+X-BeenThere: linux-mtd@lists.infradead.org
+X-Mailman-Version: 2.1.34
+Precedence: list
+List-Id: Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>
+List-Unsubscribe: <http://lists.infradead.org/mailman/options/linux-mtd>,
+ <mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>
+List-Archive: <http://lists.infradead.org/pipermail/linux-mtd/>
+List-Post: <mailto:linux-mtd@lists.infradead.org>
+List-Help: <mailto:linux-mtd-request@lists.infradead.org?subject=help>
+List-Subscribe: <http://lists.infradead.org/mailman/listinfo/linux-mtd>,
+ <mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>
+Sender: "linux-mtd" <linux-mtd-bounces@lists.infradead.org>
+Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org
This driver implements support for the SPI-NAND mode of QCOM NAND Flash
Interface as a SPI-MEM controller with pipelined ECC capability.
Signed-off-by: Varadarajan Narayanan <quic_varada@quicinc.com>
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
---
+
+Change in [v14]
+
+* No Change
+
+Change in [v13]
+
+* Changed return type of qcom_spi_cmd_mapping() from u32 to
+ int to fix the kernel test bot warning
+* Changed type of variable cmd in qcom_spi_write_page() from u32
+ to int
+* Removed unused variable s_op from qcom_spi_write_page()
+* Updated return value variable type from u32 to int in
+ qcom_spi_send_cmdaddr()
+
+Change in [v12]
+
+* Added obj-$(CONFIG_SPI_QPIC_SNAND) += qpic_common.o in Makefile
+ to build qpic_common.c based on CONFIG_SPI_QPIC_SNAND
+
+Change in [v11]
+
+* Fixed build error reported by kernel test bot
+* Changed "depends on MTD" to "select MTD" in
+ drivers/spi/Kconfig file
+
+Change in [v10]
+
+* Fixed compilation warnings reported by kernel test robot.
+* Added depends on CONFIG_MTD
+* removed extra bracket from statement if (i == (num_cw - 1)) in
+ qcom_spi_program_raw() api.
+
+Change in [v9]
+
+* Changed data type of addr1, addr2, cmd, to __le32 in qpic_spi_nand
+ structure
+* In qcom_spi_set_read_loc_first() api added cpu_to_le32() macro to fix
+ compilation warning
+* In qcom_spi_set_read_loc_last() api added cpu_to_le32() macro to fix
+ compilation warning
+* In qcom_spi_init() api added cpu_to_le32() macro to fix compilation
+ warning
+* In qcom_spi_ecc_init_ctx_pipelined() api removed unused variables
+ reqs, user, step_size, strength and added cpu_to_le32() macro as well
+ to fix compilation warning
+* In qcom_spi_read_last_cw() api added cpu_to_le32() macro to fix compilation
+ warning
+* In qcom_spi_check_error() api added cpu_to_le32() macro to fix compilation
+ warning
+* In qcom_spi_read_page_ecc() api added cpu_to_le32() macro to fix compilation
+ warning
+* In qcom_spi_read_page_oob() api added cpu_to_le32() macro to fix compilation
+ warning
+* In qcom_spi_program_raw() api added cpu_to_le32() macro to fix compilation
+ warning
+* In qcom_spi_program_ecc() api added cpu_to_le32() macro to fix compilation
+ warning
+* In qcom_spi_program_oob() api added cpu_to_le32() macro to fix compilation
+ warning
+* In qcom_spi_send_cmdaddr() api added cpu_to_le32() macro to fix compilation
+ warning
+* In qcom_spi_io_op() api added cpu_to_le32() macro to fix compilation
+ warning
+
+Change in [v8]
+
+* Included "bitfield.h" file to /spi-qpic-snand.c
+ to fix compilation warning reported by kernel test robot
+* Removed unused variable "steps" in
+ qcom_spi_ecc_init_ctx_pipelined() to fix compilation warning
+
+Change in [v7]
+
+* Added read_oob() and write_oob() api
+
+* Handled offset value for oob layout
+
+* Made CONFIG_SPI_QPIC_SNAND as bool
+
+* Added macro ecceng_to_qspi()
+
+* Added FIELD_PREP() Macro in spi init
+
+* Added else condition in
+ qcom_spi_ecc_finish_io_req_pipelined()
+ for corrected ecc
+
+* Handled multiple error condition for api
+ qcom_spi_cmd_mapping()
+
+* Fix typo for printing debug message
+
+Change in [v6]
+
+* Added separate qpic_spi_nand{...} struct
+
+* moved qpic_ecc and qcom_ecc_stats struct to
+ spi-qpic-snand.c file, since its spi nand
+ specific
+
+* Added FIELD_PREP() and GENMASK() macro
+
+* Removed rawnand.h and partition.h from
+ spi-qpic-snand.c
+
+* Removed oob_buff assignment form
+ qcom_spi_write_page_cache
+
+* Added qcom_nand_unalloc() in remove() path
+
+* Fixes all all comments
+
+Change in [v5]
+
+* Added raw_read() and raw_write() api
+
+* Updated commit message
+
+* Removed register indirection
+
+* Added qcom_spi_ prefix to all the api
+
+* Removed snand_set_reg() api.
+
+* Fixed nandbiterr issue
+
+* Removed hardcoded num_cw and made it variable
+
+* Removed hardcoded value for mtd pagesize
+
+* Added -ENOSUPPORT in cmd mapping for unsupported
+ commands
+
+* Replace if..else with switch..case statement
+
+Change in [v4]
+
+* No change
+
+Change in [v3]
+
+* Set SPI_QPIC_SNAND to n and added COMPILE_TEST in Kconfig
+
+* Made driver name sorted in Make file
+
+* Made comment like c++
+
+* Changed macro to functions, snandc_set_read_loc_last()
+ and snandc_set_read_loc_first()
+
+* Added error handling in snandc_set_reg()
+
+* Changed into normal conditional statement for
+ return snandc->ecc_stats.failed ? -EBADMSG :
+ snandc->ecc_stats.bitflips;
+
+* Remove cast of wbuf in qpic_snand_program_execute()
+ function
+
+* Made num_cw variable instead hardcoded value
+
+* changed if..else condition of function qpic_snand_io_op()
+ to switch..case statement
+
+* Added __devm_spi_alloc_controller() api instead of
+ devm_spi_alloc_master()
+
+* Disabling clock in remove path
+
+Change in [v2]
+
+* Added initial support for SPI-NAND driver
+
+Change in [v1]
+
+* Added RFC patch for design review
+
+ drivers/mtd/nand/Makefile | 4 +
+ drivers/spi/Kconfig | 9 +
+ drivers/spi/Makefile | 1 +
+ drivers/spi/spi-qpic-snand.c | 1633 ++++++++++++++++++++++++++
+ include/linux/mtd/nand-qpic-common.h | 7 +
+ 5 files changed, 1654 insertions(+)
+ create mode 100644 drivers/spi/spi-qpic-snand.c
+
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -4,7 +4,11 @@ nandcore-objs := core.o bbt.o
obj-y += spi/
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
-@@ -870,6 +870,14 @@ config SPI_QCOM_QSPI
+@@ -870,6 +870,15 @@ config SPI_QCOM_QSPI
help
QSPI(Quad SPI) driver for Qualcomm QSPI controller.
+config SPI_QPIC_SNAND
+ bool "QPIC SNAND controller"
+ depends on ARCH_QCOM || COMPILE_TEST
++ select MTD
+ help
+ QPIC_SNAND (QPIC SPI NAND) driver for Qualcomm QPIC controller.
+ QPIC controller supports both parallel nand and serial nand.
obj-$(CONFIG_SPI_ROCKCHIP_SFC) += spi-rockchip-sfc.o
--- /dev/null
+++ b/drivers/spi/spi-qpic-snand.c
-@@ -0,0 +1,1634 @@
+@@ -0,0 +1,1633 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ *
+ data_size1 = mtd->writesize - ecc_cfg->cw_size * (num_cw - 1);
+ oob_size1 = ecc_cfg->bbm_size;
+
-+ if ((i == (num_cw - 1))) {
++ if (i == (num_cw - 1)) {
+ data_size2 = NANDC_STEP_SIZE - data_size1 -
+ ((num_cw - 1) << 2);
+ oob_size2 = (num_cw << 2) + ecc_cfg->ecc_bytes_hw +
+ return 0;
+}
+
-+static u32 qcom_spi_cmd_mapping(struct qcom_nand_controller *snandc, u32 opcode)
++static int qcom_spi_cmd_mapping(struct qcom_nand_controller *snandc, u32 opcode)
+{
-+ u32 cmd = 0x0;
++ int cmd = 0x0;
+
+ switch (opcode) {
+ case SPINAND_RESET:
+static int qcom_spi_write_page(struct qcom_nand_controller *snandc,
+ const struct spi_mem_op *op)
+{
-+ struct qpic_snand_op s_op = {};
-+ u32 cmd;
++ int cmd;
+
+ cmd = qcom_spi_cmd_mapping(snandc, op->cmd.opcode);
+ if (cmd < 0)
+ return cmd;
+
-+ s_op.cmd_reg = cmd;
-+
+ if (op->cmd.opcode == SPINAND_PROGRAM_LOAD)
+ snandc->qspi->data_buf = (u8 *)op->data.buf.out;
+
+ u32 cmd;
+ int ret, opcode;
+
-+ cmd = qcom_spi_cmd_mapping(snandc, op->cmd.opcode);
-+ if (cmd < 0)
-+ return cmd;
++ ret = qcom_spi_cmd_mapping(snandc, op->cmd.opcode);
++ if (ret < 0)
++ return ret;
++
++ cmd = ret;
+
+ s_op.cmd_reg = cmd;
+ s_op.addr1_reg = op->addr.val;
+
+static const struct of_device_id qcom_snandc_of_match[] = {
+ {
-+ .compatible = "qcom,spi-qpic-snand",
++ .compatible = "qcom,ipq9574-snand",
+ .data = &ipq9574_snandc_props,
+ },
+ {}
+ .of_match_table = qcom_snandc_of_match,
+ },
+ .probe = qcom_spi_probe,
-+ .remove = qcom_spi_remove,
++ .remove_new = qcom_spi_remove,
+};
+module_platform_driver(qcom_spi_driver);
+
--- /dev/null
+From 8716f3c03d9f71ed0bd12a26f6e9d1e85cff0d12 Mon Sep 17 00:00:00 2001
+From: Christian Marangi <ansuelsmth@gmail.com>
+Date: Thu, 30 Jan 2025 00:27:22 +0100
+Subject: [PATCH 1/2] spi: spi-qpic: fix broken driver with SPINAND_SET_FEATURE
+ command
+
+The driver always return probe error with SPINAND_SET_FEATURE command:
+
+spi-nand: probe of spi0.0 failed with error -1207959538
+
+The error doesn't match any expected negative error but instead seems to
+be an u32 converted to an int. Investigating the entire codeflow I
+reached the culprit: qcom_spi_cmd_mapping.
+
+Such function can return -EOPNOTSUPP or the cmd to run. Problem is that
+in the specific context of SPINAND_SET_FEATURE, BIT(31) is set that in
+the context of an integer, it gets treated as a negative value.
+
+To correctly handle this, rework the function to return 0 or a "correct"
+negative error and pass a pointer to store the cmd.
+
+Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
+---
+ drivers/spi/spi-qpic-snand.c | 40 +++++++++++++++++-------------------
+ 1 file changed, 19 insertions(+), 21 deletions(-)
+
+--- a/drivers/spi/spi-qpic-snand.c
++++ b/drivers/spi/spi-qpic-snand.c
+@@ -1200,64 +1200,64 @@ static int qcom_spi_program_execute(stru
+ return 0;
+ }
+
+-static int qcom_spi_cmd_mapping(struct qcom_nand_controller *snandc, u32 opcode)
++static int qcom_spi_cmd_mapping(struct qcom_nand_controller *snandc, u32 opcode,
++ u32 *cmd)
+ {
+- int cmd = 0x0;
+-
+ switch (opcode) {
+ case SPINAND_RESET:
+- cmd = (SPI_WP | SPI_HOLD | SPI_TRANSFER_MODE_x1 | OP_RESET_DEVICE);
++ *cmd = (SPI_WP | SPI_HOLD | SPI_TRANSFER_MODE_x1 | OP_RESET_DEVICE);
+ break;
+ case SPINAND_READID:
+- cmd = (SPI_WP | SPI_HOLD | SPI_TRANSFER_MODE_x1 | OP_FETCH_ID);
++ *cmd = (SPI_WP | SPI_HOLD | SPI_TRANSFER_MODE_x1 | OP_FETCH_ID);
+ break;
+ case SPINAND_GET_FEATURE:
+- cmd = (SPI_TRANSFER_MODE_x1 | SPI_WP | SPI_HOLD | ACC_FEATURE);
++ *cmd = (SPI_TRANSFER_MODE_x1 | SPI_WP | SPI_HOLD | ACC_FEATURE);
+ break;
+ case SPINAND_SET_FEATURE:
+- cmd = (SPI_TRANSFER_MODE_x1 | SPI_WP | SPI_HOLD | ACC_FEATURE |
++ *cmd = (SPI_TRANSFER_MODE_x1 | SPI_WP | SPI_HOLD | ACC_FEATURE |
+ QPIC_SET_FEATURE);
+ break;
+ case SPINAND_READ:
+ if (snandc->qspi->raw_rw) {
+- cmd = (PAGE_ACC | LAST_PAGE | SPI_TRANSFER_MODE_x1 |
++ *cmd = (PAGE_ACC | LAST_PAGE | SPI_TRANSFER_MODE_x1 |
+ SPI_WP | SPI_HOLD | OP_PAGE_READ);
+ } else {
+- cmd = (PAGE_ACC | LAST_PAGE | SPI_TRANSFER_MODE_x1 |
++ *cmd = (PAGE_ACC | LAST_PAGE | SPI_TRANSFER_MODE_x1 |
+ SPI_WP | SPI_HOLD | OP_PAGE_READ_WITH_ECC);
+ }
+
+ break;
+ case SPINAND_ERASE:
+- cmd = OP_BLOCK_ERASE | PAGE_ACC | LAST_PAGE | SPI_WP |
++ *cmd = OP_BLOCK_ERASE | PAGE_ACC | LAST_PAGE | SPI_WP |
+ SPI_HOLD | SPI_TRANSFER_MODE_x1;
+ break;
+ case SPINAND_WRITE_EN:
+- cmd = SPINAND_WRITE_EN;
++ *cmd = SPINAND_WRITE_EN;
+ break;
+ case SPINAND_PROGRAM_EXECUTE:
+- cmd = (PAGE_ACC | LAST_PAGE | SPI_TRANSFER_MODE_x1 |
++ *cmd = (PAGE_ACC | LAST_PAGE | SPI_TRANSFER_MODE_x1 |
+ SPI_WP | SPI_HOLD | OP_PROGRAM_PAGE);
+ break;
+ case SPINAND_PROGRAM_LOAD:
+- cmd = SPINAND_PROGRAM_LOAD;
++ *cmd = SPINAND_PROGRAM_LOAD;
+ break;
+ default:
+ dev_err(snandc->dev, "Opcode not supported: %u\n", opcode);
+ return -EOPNOTSUPP;
+ }
+
+- return cmd;
++ return 0;
+ }
+
+ static int qcom_spi_write_page(struct qcom_nand_controller *snandc,
+ const struct spi_mem_op *op)
+ {
+- int cmd;
++ u32 cmd;
++ int ret;
+
+- cmd = qcom_spi_cmd_mapping(snandc, op->cmd.opcode);
+- if (cmd < 0)
+- return cmd;
++ ret = qcom_spi_cmd_mapping(snandc, op->cmd.opcode, &cmd);
++ if (ret < 0)
++ return ret;
+
+ if (op->cmd.opcode == SPINAND_PROGRAM_LOAD)
+ snandc->qspi->data_buf = (u8 *)op->data.buf.out;
+@@ -1272,12 +1272,10 @@ static int qcom_spi_send_cmdaddr(struct
+ u32 cmd;
+ int ret, opcode;
+
+- ret = qcom_spi_cmd_mapping(snandc, op->cmd.opcode);
++ ret = qcom_spi_cmd_mapping(snandc, op->cmd.opcode, &cmd);
+ if (ret < 0)
+ return ret;
+
+- cmd = ret;
+-
+ s_op.cmd_reg = cmd;
+ s_op.addr1_reg = op->addr.val;
+ s_op.addr2_reg = 0;