Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3882204pxv; Tue, 13 Jul 2021 06:07:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8OTFk/J5am2yMdnVXw4etqtzLXfQHMBpsZV+82AUaLnYw9yMF4Eh5kvBOKEtV+POCwIex X-Received: by 2002:a92:b111:: with SMTP id t17mr3027512ilh.208.1626181645014; Tue, 13 Jul 2021 06:07:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626181645; cv=none; d=google.com; s=arc-20160816; b=ZLVqAq0Pr1HpV/8hQYpbUHX4+GzjpSclLtw7aUXAusPCzPHCj1KY+3mUS5/FDPIHqs tJxJ1yVA+NQcF72DTRdcXgsduZk1dcdJJtJTSRptcVldZ5QrTPxKHLeZ3v8DKLppCccq g7rvpl5b/nbl4HBdf9mn4wpiTBJIoZjmSqypnRiTkgxcg3VMWHZ+49h26yFZ1jm2PZLi iFAtxbt9XpacwuWrh1tdtF3HVZvx6QHZOFXn54EzhF/ICl7kKv5xmeQo+IHbLfAeEe+y vB6g+5pU/CVJskwxhGFm/g6mDXxkqgj9Yr78Utr/URvRat3wdyYm4n2X2YHw8kgiMXjp zNQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1k4ivvZ3xXy03Q4E8raaV+ou93EXAdzBGlKPdFnNSkw=; b=ATmSdsvqC1Yi+3OR1DlVs2g9WUaQeHdZZJZwsNZo3Os7BUsR5Z05i24thpmJEXIEU8 PVanOVQRsnyCaKFufQyHmJPh3YLS1shYyBpYeS72BrLVJD2WP8aq8adkLdeXLz2yGvOA 0WDsui0aMRvqQ9ZTZ0Om9kFMM9ApvI532Rx2PtdgUVNatJI8zONPZ8Mk6MTlSeEnGonw fx9G6v2hvEOOkVbIDXurgQVnqWWu5ruTUEuwGIeKt+q59Xw6ayPbhbGCWeOAo5c0Tjmb 5M0CvtLMXmj9jtCo+g5rNVlEzT0sIv7p3E/mvKyzjPj7BZ+lr5OXHC2fWXApmF5po+Ix RqaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=LPhI6E8V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si23423127iol.91.2021.07.13.06.07.08; Tue, 13 Jul 2021 06:07:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=LPhI6E8V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236603AbhGMNJI (ORCPT + 99 others); Tue, 13 Jul 2021 09:09:08 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:51974 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236591AbhGMNJG (ORCPT ); Tue, 13 Jul 2021 09:09:06 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 16DD644V073299; Tue, 13 Jul 2021 08:06:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1626181564; bh=1k4ivvZ3xXy03Q4E8raaV+ou93EXAdzBGlKPdFnNSkw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=LPhI6E8Vkm3LJSfa8HpdGxV+WiA5bLMh5wjpMvwxCQlJQhiktKNs8vSrtb43yASIt WlB0tUxQkdppes4njA6l6ddvjPkRFIutoourP5oYct4T2BcQiM9WnvjIC/sYVUEv4N /koF7j5K1EdEFM676rWq2g2o1Hnm74eLIXQoQfck= Received: from DFLE112.ent.ti.com (dfle112.ent.ti.com [10.64.6.33]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 16DD64cl091370 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 13 Jul 2021 08:06:04 -0500 Received: from DFLE109.ent.ti.com (10.64.6.30) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Tue, 13 Jul 2021 08:06:04 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2 via Frontend Transport; Tue, 13 Jul 2021 08:06:04 -0500 Received: from LT5CD112GSQZ.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 16DD5daE109825; Tue, 13 Jul 2021 08:05:59 -0500 From: Apurva Nandan To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mark Brown , Patrice Chotard , Boris Brezillon , , , CC: Apurva Nandan , Pratyush Yadav Subject: [PATCH 04/13] mtd: spinand: Fix odd byte addr and data phase in read/write reg op and write VCR op for Octal DTR mode Date: Tue, 13 Jul 2021 13:05:29 +0000 Message-ID: <20210713130538.646-5-a-nandan@ti.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20210713130538.646-1-a-nandan@ti.com> References: <20210713130538.646-1-a-nandan@ti.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In Octal DTR SPI mode, 2 bytes of data gets transmitted over one clock cycle, and half-cycle instruction phases aren't supported yet. So, every DTR spi_mem_op needs to have even nbytes in all phases for non-erratic behaviour from the SPI controller. The odd length cmd and dummy phases get handled by spimem_setup_op() but the odd length address and data phases need to be handled according to the use case. For example in Octal DTR mode, read register operation has one byte long address and data phase. So it needs to extend it by adding a suitable extra byte in addr and reading 2 bytes of data, discarding the second byte. Handle address and data phases for Octal DTR mode in read/write register and write volatile configuration register operations by adding a suitable extra byte in the address and data phase. Create spimem_setup_reg_op() helper function to ease setting up read/write register operations in other functions, e.g. wait(). Signed-off-by: Apurva Nandan --- drivers/mtd/nand/spi/core.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 2e59faecc8f5..a5334ad34f96 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -65,12 +65,27 @@ static void spinand_setup_op(const struct spinand_device *spinand, } } +static void spinand_setup_reg_op(const struct spinand_device *spinand, + struct spi_mem_op *op) +{ + if (spinand->reg_proto == SPINAND_OCTAL_DTR) { + /* + * Assigning same first and second byte will result in constant + * bits on ths SPI bus between positive and negative clock edges + */ + op->addr.val = (op->addr.val << 8) | op->addr.val; + op->addr.nbytes = 2; + op->data.nbytes = 2; + } + spinand_setup_op(spinand, op); +} + static int spinand_read_reg_op(struct spinand_device *spinand, u8 reg, u8 *val) { - struct spi_mem_op op = SPINAND_GET_FEATURE_OP(reg, - spinand->scratchbuf); + struct spi_mem_op op = SPINAND_GET_FEATURE_OP(reg, spinand->scratchbuf); int ret; + spinand_setup_reg_op(spinand, &op); ret = spi_mem_exec_op(spinand->spimem, &op); if (ret) return ret; @@ -81,10 +96,10 @@ static int spinand_read_reg_op(struct spinand_device *spinand, u8 reg, u8 *val) static int spinand_write_reg_op(struct spinand_device *spinand, u8 reg, u8 val) { - struct spi_mem_op op = SPINAND_SET_FEATURE_OP(reg, - spinand->scratchbuf); + struct spi_mem_op op = SPINAND_SET_FEATURE_OP(reg, spinand->scratchbuf); - *spinand->scratchbuf = val; + spinand_setup_reg_op(spinand, &op); + memset(spinand->scratchbuf, val, op.data.nbytes); return spi_mem_exec_op(spinand->spimem, &op); } @@ -547,6 +562,7 @@ static int spinand_wait(struct spinand_device *spinand, u8 status; int ret; + spinand_setup_reg_op(spinand, &op); ret = spi_mem_poll_status(spinand->spimem, &op, STATUS_BUSY, 0, initial_delay_us, poll_delay_us, -- 2.17.1