From patchwork Tue Mar 7 16:53:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 65731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2543254wrd; Tue, 7 Mar 2023 09:02:48 -0800 (PST) X-Google-Smtp-Source: AK7set+HBJRNFXkQyEYVt3u5RPgD4emk8IADQeeBzF6s/Daw6V7dT0ZOIYfjwpzf9k5hPUeiJCps X-Received: by 2002:a05:6402:14ce:b0:4ac:b528:5727 with SMTP id f14-20020a05640214ce00b004acb5285727mr15805395edx.1.1678208568823; Tue, 07 Mar 2023 09:02:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208568; cv=none; d=google.com; s=arc-20160816; b=TlEmROQiqUVKe8XZXkU9mHwCN3+r61ZexenxRmCDU9yVtTrPPAYeKGsRedwj1ujqPc 0/KUQqVvvI+JFHrObKMiq1UCfhDLxroeKUFtRQ56tJRPTlRExLbpEdLFSYaEQqbiVms+ oQzHzRpJu+v7o1r9manyv71tEmfdlTW+rfHMsG/tP9c4hs0aUyDdSJji+h0Ezg5l7P7H bbsina9snecG3pAz3FWvw1l66nCBkS5PpxxrNwLZfk/qsYcK5M5I2tefCXqjV7namvrS RyVGk4KuTSigPWp2xw0UO562KCIYh0FC0V9FJCr2j14ra+29dKMEoOtWCE8ktqO04rrt at2Q== 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=Qq9KTz3txl7c0YKP2R+SoNEgCca4N7qkHJIQfTnqnB0=; b=wixAtZEfBdkhxmxvcxYq7U+ZhlMsk2l2GpvrkrDwOXxXT6p3egToVoejw7yq4XOVc6 Rzpp5MCdSRZu6ON8j1ZRSXFcYSns4cOz2G/BjzIVJO9J8vF5K+iy5jzcKoc7wJ5llY+d bdY7QsuNGmEDN2zHc9JmH49LQH+GEfh5Zw5yqMW7myYWAJbcOhklA41KDaHYb6AVqeRs JgjqNL+D4zFbWViLafd1JycaeYkPDtj92TO4+xw/YywFYCF6fAURVmN4h28veeLBTYBJ l0hqqbU+uLOO90dU6EaQZxvyfBD9FugOUrPqiRvyezIu4YxEea8PLPlgpoKuxnwGCFSE LsEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=BqUwDEmC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020a05640202d400b004beeaa6bc04si926272edx.97.2023.03.07.09.02.24; Tue, 07 Mar 2023 09:02:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=BqUwDEmC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231341AbjCGQ7y (ORCPT + 99 others); Tue, 7 Mar 2023 11:59:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230493AbjCGQ6M (ORCPT ); Tue, 7 Mar 2023 11:58:12 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F90C50F97; Tue, 7 Mar 2023 08:54:52 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id DC350C0004; Tue, 7 Mar 2023 16:54:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678208091; 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=Qq9KTz3txl7c0YKP2R+SoNEgCca4N7qkHJIQfTnqnB0=; b=BqUwDEmCOmDbtJOXsu6LWwxV7+sGgWmH/YBwjdJshEM0rTlFvpnS8S1iY4jWLnNQYe1V+1 42tZ7bx9/Q1dQbPdaviE8X5JlLNO07rg9pI3Uu6wePkuqvY1IjG5mdtYbh04szYwbDwLuX 0YQ3sgzbo0/CQBkhBFrU8sNDUvWrl8Pca4CaihjKq8RZ8F79NFZaNH0i9TPl6cpHJszDvU lcw1YkA8pfhUK1xHjZOrzf/ntwIG5L+14B6XQZYsntdaQD73lWZWGmUWjb2zkVdD7cKzXX qdesFpTCycQbUf2Law84DErifUhXUOccjB6sYmIKq2rdvmpV4jknrFsGBEr3rA== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v2 13/21] nvmem: core: add per-cell post processing Date: Tue, 7 Mar 2023 17:53:51 +0100 Message-Id: <20230307165359.225361-14-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230307165359.225361-1-miquel.raynal@bootlin.com> References: <20230307165359.225361-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759729228072592811?= X-GMAIL-MSGID: =?utf-8?q?1759729228072592811?= 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: Miquel Raynal --- 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 9ef7617e2718..664d48f0dfa7 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -54,6 +54,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; @@ -470,6 +471,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; @@ -1563,6 +1565,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); @@ -1671,6 +1680,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 535c5f9f3309..3bfc23553a9e 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; }; /**