From mboxrd@z Thu Jan 1 00:00:00 1970 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 7FF05C636D6 for ; Wed, 22 Feb 2023 17:24:25 +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=kOv64sKtbDq2+2WwASvnPt7sdmeOFhuf+fPS9Ty5zjk=; b=NFkBqZPuBVQjkS b0LvaI+BR5QNwasNAthRLyVFfo4G25l09VTL9EiPsVwGwzWnGEVZBD5tBUEJTt2GlAzMcjNy6OXTG bDsZWIcaHI80xIaurZmeCcGf4/a9JtRDBc7bxrVQ/Mloslm3C86CE8n9WFfyzX1k7vUOE9uvx6uYg HCtWtY5nio/Y00bZKLBsiKE1q+0obrPvcW2XLk3Wbsm1gqfMFbnJhI4vSpZzoCCidrfcbfavzg7SL 63EOU9gZGU7xjQtjpbJ1l9GKFERHtt7b2JDqreeCER8g4zf9dxqY5U1HdlPWJO0kmrbvQX/UKel28 IQ3kYY95dYu+lWpmFRsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pUspz-00DCRy-WA; Wed, 22 Feb 2023 17:23:28 +0000 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pUspr-00DCO7-GU for linux-arm-kernel@lists.infradead.org; Wed, 22 Feb 2023 17:23:20 +0000 Received: by mail-lj1-x231.google.com with SMTP id a10so8674213ljq.1 for ; Wed, 22 Feb 2023 09:23:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n3duNGI0HfLu2PQ/Hpn1IXizpNMVGcpGhUax+XUrkwo=; b=Qw2n8KB0aHET9DR0jdhZl6RxgAHDB/IFzEnlmka1iyJ+lBiFBGMzav4Wl5mEAX8NIu UQ5xSppwLtUR2UzSE/DmYGcX34P6FbWPz6IHe7hwRUllahOaNT8/mwk3QEhEfqloTKv+ tHFO0YztbXODEUPXySlJtGt5VAhR6JJmH3E7YfCqmRf/CsukcrBwnsLJxjAo9PI/lQP5 CQEQSh7/FVsKFR3vW/GiZwswpGADkDKDnVlQLTIMCjcTRKRf8pitHw8ErIcBp4O2ZW+z jTjtQGJkYhLWwyMGQrSn/G+x7UKhKtzU0QHnbI1MEBixoBaBICkXzJcL90KJWIGLc2te tUSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n3duNGI0HfLu2PQ/Hpn1IXizpNMVGcpGhUax+XUrkwo=; b=Ct/MqW8bJE9letr48k5E09h6Reg7sSAHjJ0F2LG+sOrIt0dGe50QaK7/SFfVXkh9Sc J4IjKICkn7sXuy1CPpWo1PAFvDtL844vX+AgpNz2zhN5uyV1JGl7pm2EDW/ADDfPIkyy RlZC/2xYCgvFwpwEmFb0zAqeEw1vrmzb6D0kam1yI5F7j9C9aQuX81+mTmXpyyU6f/lG ACmzAtK6FymF32y19puNYB2ee7WH4zuobSJ5JhnrvqbAOFODMkPkoWOgPj3Y1yxUsyIP fDPH3hf+sFQnSx8D757LPckZyjo8jWGX/rcaayk2QYiLKURPQPG0p2mdPbidsK8GfLWk cLPw== X-Gm-Message-State: AO0yUKW8JvOF6N1GJA6WxZiWyPc3F5eoKmTLLkSSisvyi49fQZ/5GvMA BxYwfZ/TqcK/K4Bpj9IPPsk= X-Google-Smtp-Source: AK7set/KJLsv+oD6LfWtc4pxWzpcUiaIY23jTLgt93cV4yoo1N1fURWA5VgfO5rHjBRIYPdvtPraeQ== X-Received: by 2002:a2e:b5ab:0:b0:294:7028:c672 with SMTP id f11-20020a2eb5ab000000b002947028c672mr3147761ljn.44.1677086595638; Wed, 22 Feb 2023 09:23:15 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id p2-20020a2e93c2000000b0029477417d80sm721513ljh.85.2023.02.22.09.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 09:23:15 -0800 (PST) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski Cc: Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Miquel Raynal , Michael Walle , gregkh@linuxfoundation.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, u-boot@lists.denx.de Subject: [PATCH 1/4] nvmem: core: add per-cell post processing Date: Wed, 22 Feb 2023 18:22:42 +0100 Message-Id: <20230222172245.6313-2-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222172245.6313-1-zajec5@gmail.com> References: <20230222172245.6313-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230222_092319_580591_AFFA7B93 X-CRM114-Status: GOOD ( 18.56 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Michael Walle 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: Srinivas Kandagatla --- 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 6783cd8478d7..c5c9a4654241 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 read_post_process; struct device_node *np; struct nvmem_device *nvmem; struct list_head node; @@ -465,6 +466,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->read_post_process = info->read_post_process; cell->bit_offset = info->bit_offset; cell->nbits = info->nbits; @@ -1429,6 +1431,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); @@ -1537,6 +1546,14 @@ 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 read_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 b3c14ce87a65..f87fd64eee8f 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -54,6 +54,8 @@ struct nvmem_keepout { * @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; @@ -62,6 +64,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.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel