From patchwork Wed Nov 23 18:01:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 25111 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2942163wrr; Wed, 23 Nov 2022 10:05:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ginxRbkvb5SOi40Kvh8M8MGdj6wMpDGdRwl1JqWJXDIspUkCWa40GidXCO/6NrvOEpPL0 X-Received: by 2002:aa7:cb4d:0:b0:469:e00a:a297 with SMTP id w13-20020aa7cb4d000000b00469e00aa297mr9110924edt.333.1669226724173; Wed, 23 Nov 2022 10:05:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669226724; cv=none; d=google.com; s=arc-20160816; b=sVbxXWDP1vsnhnqdhL59LML6jJirrwMWWAvbg79oYZewtmtPmnQlVMGPiuAsCt6nFX nESofk4B5uUwPhV33RexfbOqmi2hfvKW+YdM5vwVSYAgTu9HfspQY9toNCaby+ECs4Ui cD9aM2JG7O1BUq2PV5THvgYK0hEIjwWRRM4sfjJntrWBXnGXKACygiQ/9uBb4elakC0k g9Gx/D2LuCwMYP7GTXk0EXdR9mHx64ULqRDMVITSPcnZ+x0kCW6S/JT6OJsy6+7ayQGs rZ1JLkr67QG1t/N7Y7ije7w3PU7FpAiGf734n8vcKuznuo++OeQ8tSPpMK7SkmYa1X+7 5nag== 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=QnWNBJBre5MF1HKaKc5jyQ5wsfU873yuhAWeFwHDAUw=; b=BKcDet4lYZJFdD8SLihTT11yMFC2laT7+mmKhi8CLJ9X83XgdvC/SXpEUDHj2wEJJ7 AVm+uP65dbN8w6A0ztQp5uz7kX3Zh/r+E/c4okIVd2MacCCKSRNbV4RIQ6yGgdfUCVl2 Or+xKcio2oWFbqB/Ry+v9s09VKvteRzZPbOky7E+JDo0qIwrNof5tJeZbXHWnvVSIK+Y cXOq2taw42c/zRBpiQwLQQskBfB4ouv1GydEoTqynWRMVFW4P9VOUVxEsQWzchbYSjGg kD4R3OnszGdGv1Qw1C3dRZqpLH7tXtkw9Zz8juJQVwpaQqUY8LaEcoizff1HvbWipsZ/ 8WZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=11RGxVtE; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga31-20020a1709070c1f00b007878c9d73a2si16079521ejc.426.2022.11.23.10.04.49; Wed, 23 Nov 2022 10:05:24 -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=@walle.cc header.s=mail2022082101 header.b=11RGxVtE; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239078AbiKWSDz (ORCPT + 99 others); Wed, 23 Nov 2022 13:03:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239388AbiKWSC1 (ORCPT ); Wed, 23 Nov 2022 13:02:27 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B18CF97087; Wed, 23 Nov 2022 10:02:25 -0800 (PST) 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 D9EA63B33; Wed, 23 Nov 2022 19:02:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1669226544; 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=QnWNBJBre5MF1HKaKc5jyQ5wsfU873yuhAWeFwHDAUw=; b=11RGxVtEEkh4n2edyM3mYZ90vfHfq0Ss9Lf39FclnHzf1Eg8lX8TpHzkOz+0G/vCO5Xmd+ JBzH6sXy4vc4DlfM9MKYqjme4jF+d4SFj1FrFEZWYoTgdHxD88tBT/iDqRHq+Md1I6eM+f blWHEv99fzIPxvvMcUXVx9C/Cx9ZWBxFy0eVTP1TFqmVY2sXIF3LHLY6hnmcbBNkdx7xW+ TNLw4ZC/QCZoNbKsF8jYm3xeYJjmrHRUtRSjKNKVgD8oVQB+jSXXHY9p6TiYnOIG909ZTo zpXdBS376uuvgLldFwjunkphICoWTZkz7uLl3Zg51ZCTK/1BFRUmHn10fu10SA== From: Michael Walle To: Jonathan Corbet , Srinivas Kandagatla , Miquel Raynal , Rob Herring , Frank Rowand , Sascha Hauer Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Michael Walle Subject: [PATCH v4 12/20] nvmem: core: add per-cell post processing Date: Wed, 23 Nov 2022 19:01:43 +0100 Message-Id: <20221123180151.2160033-13-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221123180151.2160033-1-michael@walle.cc> References: <20221123180151.2160033-1-michael@walle.cc> MIME-Version: 1.0 X-Spam: Yes X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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?1750311081429648037?= X-GMAIL-MSGID: =?utf-8?q?1750311081429648037?= 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 --- changes since v3: - none changes since v2: - none changes since v1: - rename hook to read_post_process 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 87ba1e3a5bd4..e75642a675ae 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -53,6 +53,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; @@ -469,6 +470,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; @@ -1557,6 +1559,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); @@ -1665,6 +1674,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 4185767c114f..1930496d8854 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; }; /**