From patchwork Mon Feb 6 10:27:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 53166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2158998wrn; Mon, 6 Feb 2023 02:34:49 -0800 (PST) X-Google-Smtp-Source: AK7set9MZk+763EWhYTb2VgVm64EDmHJxq3IXDbLEHIkFHvkvH9l0kIgD8pmhRrbiGA4N8duhN7r X-Received: by 2002:a17:907:3fa4:b0:889:1480:d908 with SMTP id hr36-20020a1709073fa400b008891480d908mr13390672ejc.17.1675679689555; Mon, 06 Feb 2023 02:34:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675679689; cv=none; d=google.com; s=arc-20160816; b=iBQXcO8YjM2S3JcjQVanl7rlWRN4MC5rHzFMsOeJDxIwxc/XeJV8rZVvKYN9JHhyMo 0nt1R7KBnxOrtILG6B13swx8VHnzIxgsEwwi7Iien+Ma/9zXYFeeRHQab3BA24uIj3zv aESPZbTRdX0vwnMRV8A4swcOrPgYEQXkd+0Frc2cTpq0O3+sg95BI5Djh1NUJrCh469I EvZbfbLv0b33QLFExVoYkdIcUvXUh8FT5oKxVDcYPz/CLlZ6ftCpY/jwYVaQPUmhzDdb y30FLyefoZJZeAOunt5t+L620TQ8oLftrc8vJd94SAs4uJnsPKRqKHfVZ2WuNwIty2qw 7YpQ== 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=FiSe+GBuFOro9IU25G1dPaAB4qi2H5ERUtgYWOzK1rc=; b=d4BHdCkzEXCbnN4d4kv9hf5o29ZAwn8hTcr987ULDfPmDOnzM6dkvOW+sG13GsM3Bg NeoMP6DfBPjhNqFDWxQExm4zWDHk/E21+mcigSBp05iX1OL2ctKvWHzEykIxcK2sv0KP 7zIpiOAS4E/KKuFL+sZKyhVoj7TpM3jWalmCtyQd3vmD33/kB4GqzLuhQGh90GcVd17E D+nOCrVOpTy1o8gKEFTpOzIzGZTsuJIvxdf9Almy8MT42yD0oPz+JIfI9G/eG+Xt3rHF o8M/O11/ZnJPy8kV6EsAS8TjGNhLLe2Hq2ujSisl7u8pkF055uBcucyZgcE+X69dtYD5 jWOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=trqOQmZb; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 22-20020a170906025600b0087766403eb3si15333303ejl.893.2023.02.06.02.34.26; Mon, 06 Feb 2023 02:34:49 -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=@linaro.org header.s=google header.b=trqOQmZb; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231173AbjBFK3P (ORCPT + 99 others); Mon, 6 Feb 2023 05:29:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230454AbjBFK2m (ORCPT ); Mon, 6 Feb 2023 05:28:42 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77F631EBEC for ; Mon, 6 Feb 2023 02:28:37 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id k8-20020a05600c1c8800b003dc57ea0dfeso10413337wms.0 for ; Mon, 06 Feb 2023 02:28:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=FiSe+GBuFOro9IU25G1dPaAB4qi2H5ERUtgYWOzK1rc=; b=trqOQmZboMzCVT6US8AA0xejQw3vI04MF20TX6/Kun5Wpt+WrwvHc/tKYY5mkmf2TR prhxOdHZmeKeGWcGz4SLbzXTM1EYK2U8GRm7fIqbNjebZ8OO+l25hNfhBYissXwMRkfh qEIiXzvX75dIZV35Ne+6XMZN0tPE5IlPyjzl6z9knrzhQpQxxn1uyRGX5xC1jrxzo0z6 lEA49lISeqpZ26DyqAm0hVE2vhQPYgMp5Ugv3Jki7s9Atq190I7ybef5EcdYae2e36PE vb4f+wlYGaRyPbwsdb2rkDjoy6/dkmayGkmZU0u7oylFmjWaOC8d/jt29IooFtVOoTy8 ta1w== 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=FiSe+GBuFOro9IU25G1dPaAB4qi2H5ERUtgYWOzK1rc=; b=sosjMxOfkTeiDrk4cDc4uC0CMBw9racL3fvT8Rojs6k0QDU7sH2tNn37PN7RiEXQJy rPuZSDbteWo2u0/g6+OyvfmdjKT9hprPiz0yWaVn0+XKoBHWe+QdFQGwYfQFsLZmRu/g TM+qVDEU3dauCJZlSG2PeNMzmnN7DT1flGWrCGCxqOt+EQLwAglecbQgtTGHQ0niVBmD Lzuy2EfJAThT8Bjb17MsA1Uad2nx+Mjg0jWTOjrD7DDmqzjcTWpCyVFMlALPrtEqrin7 sIGXMeoqHXXeLUc8zuNyUHjR1OKry09Fi6c+TEPZHWrXVlTFBagnho/xnFzrYOAyB4mN rmXg== X-Gm-Message-State: AO0yUKV2OOXxSDZJL+R7PAHcEZmylrge5JfSBQ6sq/YkY/Il4N6dDVRH hoo+md6hs9smK07RAGUJ68xeumcDXshgvNvq X-Received: by 2002:a05:600c:314a:b0:3df:eeaa:816d with SMTP id h10-20020a05600c314a00b003dfeeaa816dmr6273008wmo.28.1675679316081; Mon, 06 Feb 2023 02:28:36 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id g10-20020a05600c310a00b003de77597f16sm11002446wmo.21.2023.02.06.02.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 02:28:35 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Michael Walle , Srinivas Kandagatla Subject: [RESEND PATCH 18/37] nvmem: core: add per-cell post processing Date: Mon, 6 Feb 2023 10:27:40 +0000 Message-Id: <20230206102759.669838-19-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230206102759.669838-1-srinivas.kandagatla@linaro.org> References: <20230206102759.669838-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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?1757077506191736990?= X-GMAIL-MSGID: =?utf-8?q?1757077506191736990?= 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 d2c427c5ebc6..80051726b064 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; @@ -1545,6 +1547,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); @@ -1653,6 +1662,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; }; /**