From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Mon, 04 Aug 2025 17:32:15 +0200 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uixAd-006z8x-0R for lore@lore.pengutronix.de; Mon, 04 Aug 2025 17:32:15 +0200 Received: from bombadil.infradead.org ([2607:7c80:54:3::133]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uixAa-0006K0-Fn for lore@pengutronix.de; Mon, 04 Aug 2025 17:32:14 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kvvGyNAyrYGlwe4fzPOfCpROqDMck7qz/0TpJGoikcI=; b=L5YwyQUQhNP6Y2lIlUGTd2cIIz RE0/ayXm5rPLQ1M8lKKiSBbv8DxiduiBTTCSk2atYFAg5EodbadNx1bJ2sIFT2bl5dkoiMrQhunIL 2sHIyf3Aclwhm+qOVKkS27LO0pq3zF7+2TB3bxDpg6Ox58mCyhM11BdQxIhRSJzaBOX2N26TU/lfu TnsKi1Zjcfu/1PpbxI/26eoEvzBVvJEErtvbbsVKt9eZQIIHtsAX6i1KxHNiY4Dmoo9bsN/7eiGwY Br7juS/Cm+coY/2WGEgT/0GamQRNtPjAO806pr9eobMaPnl6/Vqmue/6zLUeXS+3GYphXNzMYao+L Z1BD8Grg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uix9q-0000000Anyg-3acH; Mon, 04 Aug 2025 15:31:26 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uiwJ5-0000000AgmM-30Lw for barebox@lists.infradead.org; Mon, 04 Aug 2025 14:36:57 +0000 Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1uiwIz-0000aW-In; Mon, 04 Aug 2025 16:36:49 +0200 From: Marco Felsch Date: Mon, 04 Aug 2025 16:36:58 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250804-v2025-06-0-topic-nvmem-v1-12-7603eaa4d2b0@pengutronix.de> References: <20250804-v2025-06-0-topic-nvmem-v1-0-7603eaa4d2b0@pengutronix.de> In-Reply-To: <20250804-v2025-06-0-topic-nvmem-v1-0-7603eaa4d2b0@pengutronix.de> To: Sascha Hauer , BAREBOX Cc: Marco Felsch X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250804_073655_793398_5C7B2E81 X-CRM114-Status: GOOD ( 14.80 ) X-BeenThere: barebox@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "barebox" X-SA-Exim-Connect-IP: 2607:7c80:54:3::133 X-SA-Exim-Mail-From: barebox-bounces+lore=pengutronix.de@lists.infradead.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.whiteo.stw.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-5.2 required=4.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Subject: [PATCH 12/15] nvmem: core: add per-cell post processing X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on metis.whiteo.stw.pengutronix.de) To further sync the nvmem code base port Linux commit: | commit 345ec382cd4b736c36e01f155d08c913b225b736 | Author: Michael Walle | Date: Tue Apr 4 18:21:24 2023 +0100 | | nvmem: core: add per-cell post processing | | Instead of relying on the name the consumer is using for the cell, like | it is done for the nvmem .cell_post_process configuration parameter, | provide a per-cell post processing hook. This can then be populated by | the NVMEM provider (or the NVMEM layout) when adding the cell. | | Signed-off-by: Michael Walle | Signed-off-by: Miquel Raynal | Signed-off-by: Srinivas Kandagatla | Link: https://lore.kernel.org/r/20230404172148.82422-17-srinivas.kandagatla@linaro.org | Signed-off-by: Greg Kroah-Hartman Signed-off-by: Marco Felsch --- drivers/nvmem/core.c | 17 +++++++++++++++++ include/linux/nvmem-provider.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index abb576af01ae0f8fc2d1e2f30ec9d0d22cd2a4fa..0c78d61e3c58fbe019a1def08d06e2ecf561a9b1 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -22,6 +22,7 @@ struct nvmem_cell_entry { int bytes; int bit_offset; int nbits; + nvmem_cell_post_process_t read_post_process; struct device_node *np; struct nvmem_device *nvmem; struct list_head node; @@ -242,6 +243,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, cell->raw_len = info->raw_len ?: info->bytes; cell->bytes = info->bytes; cell->name = info->name; + cell->read_post_process = info->read_post_process; cell->bit_offset = info->bit_offset; cell->nbits = info->nbits; @@ -829,6 +831,13 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, if (cell->bit_offset || cell->nbits) nvmem_shift_read_buffer_in_place(cell, buf); + if (cell->read_post_process) { + rc = cell->read_post_process(nvmem->priv, id, index, + cell->offset, buf, cell->bytes); + if (rc) + return rc; + } + if (nvmem->cell_post_process) { rc = nvmem->cell_post_process(nvmem->priv, id, index, cell->offset, buf, cell->bytes); @@ -937,6 +946,14 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, const void *b (cell->bit_offset == 0 && len != cell->bytes)) return -EINVAL; + /* + * Any cells which have a cell_post_process hook are read-only because + * we cannot reverse the operation and it might affect other cells, + * too. + */ + if (cell->read_post_process) + return -EINVAL; + if (cell->bit_offset || cell->nbits) { buf = nvmem_cell_prepare_write_buffer(cell, buf, len); if (IS_ERR(buf)) diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 44c6b76ccc5212a72bffe694308321ce1b27e470..892e3604ef83ef8b616041f5d4dbfdcae1136fc9 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -38,6 +38,8 @@ typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index, * @bit_offset: Bit offset if cell is smaller than a byte. * @nbits: Number of bits. * @np: Optional device_node pointer. + * @read_post_process: Callback for optional post processing of cell data + * on reads. */ struct nvmem_cell_info { const char *name; @@ -47,6 +49,7 @@ struct nvmem_cell_info { unsigned int bit_offset; unsigned int nbits; struct device_node *np; + nvmem_cell_post_process_t read_post_process; }; /** -- 2.39.5