From patchwork Wed Jul 10 09:14:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q3PDs2vDoXMgQmVuY2U=?= X-Patchwork-Id: 1958777 Return-Path: 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=VLF9dYap; dkim=fail reason="signature verification failed" (4096-bit key; unprotected) header.d=prolan.hu header.i=@prolan.hu header.a=rsa-sha256 header.s=mail header.b=Z50GdAvE; 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 4WJsf12tk6z1yNy for ; Wed, 10 Jul 2024 19:15:35 +1000 (AEST) 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: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:In-Reply-To:References: List-Owner; bh=JLIkLuvHWs74DuIsf1w+FWrk6Unxpi1ZNNBnonDZ5z8=; b=VLF9dYapI+0vSO tU9Dwc0BD4yl3YqaYcfN4FcMW6qJ/mNFMW/qtJfIf/LsTF1JKE9k5M8owAeL2JyOMtYlMlxMxRoYe eME4BuiGj03neq7ReBmMLbHtI6xE3i9W44hqAjnriyYlyUf7VZtQNO3+K0i9bqgj/9z5xqvYypV2Q I1S/Yi/AlZFkhTTcKBfmfI/TAFZ91JfLYVUqrf6mzbYKPmoJd1KHortq51G/OAbL+1dyJo0nR2m5P dRcdALjbEKwt7R6xcR3OJ9KTL2NHsy5O8jXtOlS4maQFfmKnPcAMwAjxxpxjcfCF15OtCRkRlMD3q UCkKedfQLFR9xtukMnZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRTPt-0000000A2LW-2uhK; Wed, 10 Jul 2024 09:15:13 +0000 Received: from fw2.prolan.hu ([193.68.50.107]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRTPp-0000000A2KU-1ADA for linux-mtd@lists.infradead.org; Wed, 10 Jul 2024 09:15:11 +0000 Received: from proxmox-mailgw.intranet.prolan.hu (localhost.localdomain [127.0.0.1]) by proxmox-mailgw.intranet.prolan.hu (Proxmox) with ESMTP id A98E2A05EC; Wed, 10 Jul 2024 11:14:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prolan.hu; h=cc :cc:content-transfer-encoding:content-type:content-type:date :from:from:message-id:mime-version:reply-to:subject:subject:to :to; s=mail; bh=8i40Vuw+IuYEzl6a9Xr69NauHgXUINvZ77epVTOrtQo=; b= Z50GdAvExkv3NnypvITdQM2xmrzqWeMaOm5QMq3OBtRvAAOEifvmwPoXs2UVXu2Q oOHxpjo+o0qh1c97Pb+C3szrvmWJ998CE6ysvbQCqSSt8R+yQ8h7hGZAOwfyaPOX a/cdZ95LUDQmSabiyUdkciWo49x9vCSqeFn0dBKouMHm1rwqF1Ph31jlj7tLeswy NsMj05ng3hv+aNTT4jrE//wqANKKzaVQte/QMhhxzeSHdqvJGA51FKRLOmRlZpq5 870eCCW6OIMOHk7lbUqpeXMNkIApu+dQ3F+ExLt98g7rDjOwfQCncTZ8kSXkXQl9 5n/LB2MxqKJHJ+nhYnpmyjCSBFbHxo71KTnUVMQ3fNvjxOyAmP8q8RV3XceCoLuD vjfP0y3OU9ZKi6+0qqJ8pQTF8ieDKJ6QA9vw5zO22HvE8IHR+zvec9jD+puNGF8R N4snsRXeLjIoLO61wRQsrwWddJocxZQIIf7DrA7IuoWy2y1GTwtqfp7H6TtBfu8U cyEsFyNXtamzd1MBgnwPsNUGscF7jQ/+E/NcCmRAXlhz44Q4pEbshGFq4MNwIs6L 6eI5UB871+ekkT7GfpZ6ilQ6PhVHOL+9Z2ZuaESYmpYIYpAilQ1LY5syRJVgPpN1 9e2096CcQA9OhUw35rs7Vcf0/AjhnJWkPfiZa1j9DyM= From: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= To: , CC: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= , "Tudor Ambarus" , Pratyush Yadav , Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Subject: [PATCH] mtd: spi-nor: sst: Factor out common write operation to `sst_nor_write_data()` Date: Wed, 10 Jul 2024 11:14:01 +0200 Message-ID: <20240710091401.1282824-1-csokas.bence@prolan.hu> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-ESET-AS: R=OK;S=0;OP=CALC;TIME=1720602896;VERSION=7975;MC=3621083219;ID=61954;TRN=0;CRV=0;IPC=;SP=0;SIPS=0;PI=3;F=0 X-ESET-Antispam: OK X-EsetResult: clean, is OK X-EsetId: 37303A2980D9485464756B X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240710_021509_805476_8350C81D X-CRM114-Status: GOOD ( 14.49 ) X-Spam-Score: -2.1 (--) 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: Writing to the Flash in `sst_nor_write()` is a 3-step process: first an optional one-byte write to get 2-byte-aligned, then the bulk of the data is written out in vendor-specific 2-byte writes. Finall [...] Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Writing to the Flash in `sst_nor_write()` is a 3-step process: first an optional one-byte write to get 2-byte-aligned, then the bulk of the data is written out in vendor-specific 2-byte writes. Finally, if there's a byte left over, another one-byte write. This was implemented 3 times in the body of `sst_nor_write()`. To reduce code duplication, factor out these sub-steps to their own function. Signed-off-by: Csókás, Bence Reviewed-by: Pratyush Yadav --- Notes: RFC: I'm thinking of removing SPINOR_OP_BP in favor of SPINOR_OP_PP (they have the same value). SPINOR_OP_PP is the "standard" name for the elementary unit-sized (1 byte, in the case of NOR) write operation. I find it confusing to have two names for the same operation, so in a followup I plan to remove the vendor-specific name in favor of the standard one. drivers/mtd/spi-nor/sst.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c index 180b7390690c..fec71689e644 100644 --- a/drivers/mtd/spi-nor/sst.c +++ b/drivers/mtd/spi-nor/sst.c @@ -167,6 +167,21 @@ static const struct flash_info sst_nor_parts[] = { } }; +static int sst_nor_write_data(struct spi_nor *nor, loff_t to, size_t len, + const u_char *buf) +{ + u8 op = (len == 1) ? SPINOR_OP_BP : SPINOR_OP_AAI_WP; + int ret; + + nor->program_opcode = op; + ret = spi_nor_write_data(nor, to, 1, buf); + if (ret < 0) + return ret; + WARN(ret != len, "While writing %i byte written %i bytes\n", len, ret); + + return spi_nor_wait_till_ready(nor); +} + static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { @@ -188,16 +203,10 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len, /* Start write from odd address. */ if (to % 2) { - nor->program_opcode = SPINOR_OP_BP; - /* write one byte. */ - ret = spi_nor_write_data(nor, to, 1, buf); + ret = sst_nor_write_data(nor, to, 1, buf); if (ret < 0) goto out; - WARN(ret != 1, "While writing 1 byte written %i bytes\n", ret); - ret = spi_nor_wait_till_ready(nor); - if (ret) - goto out; to++; actual++; @@ -205,16 +214,11 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len, /* Write out most of the data here. */ for (; actual < len - 1; actual += 2) { - nor->program_opcode = SPINOR_OP_AAI_WP; - /* write two bytes. */ - ret = spi_nor_write_data(nor, to, 2, buf + actual); + ret = sst_nor_write_data(nor, to, 2, buf + actual); if (ret < 0) goto out; - WARN(ret != 2, "While writing 2 bytes written %i bytes\n", ret); - ret = spi_nor_wait_till_ready(nor); - if (ret) - goto out; + to += 2; nor->sst_write_second = true; } @@ -234,14 +238,9 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len, if (ret) goto out; - nor->program_opcode = SPINOR_OP_BP; - ret = spi_nor_write_data(nor, to, 1, buf + actual); + ret = sst_nor_write_data(nor, to, 1, buf + actual); if (ret < 0) goto out; - WARN(ret != 1, "While writing 1 byte written %i bytes\n", ret); - ret = spi_nor_wait_till_ready(nor); - if (ret) - goto out; actual += 1;