From patchwork Thu Aug 25 21:44:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12955273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD193ECAAA3 for ; Thu, 25 Aug 2022 21:50:04 +0000 (UTC) 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=MJNIn4KZE6Duk9ZebcCmegOheUnTWbzbKvNAPXf6TS0=; b=tWR31jAA+QKhVD Rx1iqxaK2YpMpMZXPKDOuaUmg3/Ox6XgXeFB/l+twBwM2mtXBuDG0Uvq/aFHQTeJj3jZS9uYJZ4ui HvxvWbFwIvN92BMiMi7F/irZvHL1h0avWVqzrrNXb1zgxlq2ScsdR9q5MmCFmeAW1OxF6ZY1/vbvF wqtyD3XTYRX3KnIXP82x9QQfHOg4uII+Pq7cFCSqImXBm24u4J3gchkdwYsM38bUieRhLnSO7TSDy Qg+e5tFAw6uRA6sQYhoesiKlZDlyduSQCzAANz6JxDOSCqtCmAD9IwgiaeqL3al+Ki7hdoMNUjWdk V9YgLnUNku/+u2rbvSeg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRKie-003ZsM-Ms; Thu, 25 Aug 2022 21:48:57 +0000 Received: from 0001.3ffe.de ([159.69.201.130] helo=mail.3ffe.de) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRKeZ-003XUH-K4; Thu, 25 Aug 2022 21:44:46 +0000 Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id CEF0D831E; Thu, 25 Aug 2022 23:44:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1661463880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NulQog4Ua6qPEeieWoZCqTlKOCTKSY1NYdQPcq6/xPM=; b=0drLSyK7eFBxYhqFpoLJiJmOaKwhJvE1lbTKkxLiiobGwpAY9SicTiJHD012GW5RUJzTtP FIoBkqdU89gcF/by0qzLaQ/G8hHxAOpDc8qFXCuLVlsWwTX2eAPFPIwaE6Szcg4RTfcmhC XAfBwP3hjSpFneF1lr3mUHyRPdEBJlAlOJgQPdRuI1Ly9a0awIo8/W6ZLqy3vhcx+HoHSz yB4e6j9mu0j3nO6Qq9M382Gu5CZZxy2/Eo62boKpUcz4m/Ocjllyw+69KnEMWcf1rWLSio d4ERhdGRxd4hZxGIqf1HAe9avFdEUPKnndE/1Qigsy0lQxU102dZ6jXi2jKbog== From: Michael Walle To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Srinivas Kandagatla , Shawn Guo , Li Yang , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Frank Rowand Cc: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, Ahmad Fatoum , Michael Walle Subject: [PATCH v1 07/14] nvmem: core: add per-cell post processing Date: Thu, 25 Aug 2022 23:44:16 +0200 Message-Id: <20220825214423.903672-8-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220825214423.903672-1-michael@walle.cc> References: <20220825214423.903672-1-michael@walle.cc> MIME-Version: 1.0 X-Spam: Yes X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220825_144443_881991_CBA8CB5C X-CRM114-Status: GOOD ( 15.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- drivers/nvmem/core.c | 16 ++++++++++++++++ include/linux/nvmem-consumer.h | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 5357fc378700..cbfbe6264e6c 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -52,6 +52,7 @@ struct nvmem_cell_entry { int bytes; int bit_offset; int nbits; + nvmem_cell_post_process_t post_process; struct device_node *np; struct nvmem_device *nvmem; struct list_head node; @@ -468,6 +469,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, cell->offset = info->offset; cell->bytes = info->bytes; cell->name = info->name; + cell->post_process = info->post_process; cell->bit_offset = info->bit_offset; cell->nbits = info->nbits; @@ -1500,6 +1502,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->post_process) { + rc = cell->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); @@ -1608,6 +1617,13 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si (cell->bit_offset == 0 && len != cell->bytes)) return -EINVAL; + /* + * Any cells which have a post_process hook are read-only because we + * cannot reverse the operation and it might affect other cells, too. + */ + if (cell->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-consumer.h b/include/linux/nvmem-consumer.h index 980f9c9ac0bc..761b8ef78adc 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -19,6 +19,10 @@ struct device_node; struct nvmem_cell; struct nvmem_device; +/* duplicated from nvmem-provider.h */ +typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index, + unsigned int offset, void *buf, size_t bytes); + struct nvmem_cell_info { const char *name; unsigned int offset; @@ -26,6 +30,7 @@ struct nvmem_cell_info { unsigned int bit_offset; unsigned int nbits; struct device_node *np; + nvmem_cell_post_process_t post_process; }; /**