Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1253571rwe; Thu, 1 Sep 2022 15:24:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR63r2PFgdTkgfPe95QbH8jBZrh1yxWq/7kw+B9SbRp2AlLOcEXROOEjmF58Pjzq29ftQMS0 X-Received: by 2002:a17:907:d8d:b0:741:4d1a:5954 with SMTP id go13-20020a1709070d8d00b007414d1a5954mr18131638ejc.307.1662071042532; Thu, 01 Sep 2022 15:24:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662071042; cv=none; d=google.com; s=arc-20160816; b=vrawgc0E7fqztODYXCSRJONoTssiVFP/g6KqLJ5ZEpOVRX8rKoaWY4c0KPQwMClbD8 KwWvmzxfow+/eH8P3+NQsF1IUAH6r0HYgzyWny2AfVvcCv6j00ZFU8WSEOdbT3/vPgXu xFyV4urRYSRnLqyqNkcwnE35WeI8UOu0kaVCuxG6apAxt58YQdfWVT5fl8Fl2zn/sdBp TUiDsUzjarAC25MQfi88la05VdscbF7y/q+nkhaJpmmNsjlFEno202MyFt6VrLNNyWmb taaM5FAAUfYuvAVKw6ploZkJm+yPrO3odvPHlGJfrrwew1W/XwIVPz+08o7p8ey6EBOz u+8A== 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=o6nUWzhiHul3Yl3P+SzBVLQQvDpfFym6h8RUoqsPj3s=; b=IxlO1ojs4Cqv9xjQL4b6bftmXFHcujk2Y6TnSUpnDXIwPhjY7wsrkLno8gdUBmpBuD apqSf6DpMR2PAv6LmFSOQNdX+eGw6PV5M5Nl3qLt6XNVMBQvmP5lg9qRDFtNsqWGZ9qk 87Io6cCVgDwrIlT0WPyoQu2I7SWewR9vuWlSftdKvkkIwg1qJIzNAeYDCNckgBJWT/gn w+I+2596kh1hX05Xa+AAIPQNMhpsIQ1vr9V8b8Qek47Jq3U+m/JBaQJbIJ+aGKSqQ2f0 EaPs2L5wgCcXVHRYIImhXbxcg7et1OVNdUz1Zwif6v6sD84AsSkxm5JN+TQi9c2438t1 aeCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=SZQhEhbi; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f22-20020a17090631d600b0073dd946b66asi291598ejf.444.2022.09.01.15.23.37; Thu, 01 Sep 2022 15:24:02 -0700 (PDT) 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=SZQhEhbi; 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 S234697AbiIAWWL (ORCPT + 99 others); Thu, 1 Sep 2022 18:22:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233595AbiIAWVA (ORCPT ); Thu, 1 Sep 2022 18:21:00 -0400 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83434A223C; Thu, 1 Sep 2022 15:19:20 -0700 (PDT) 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 3B54521E3; Fri, 2 Sep 2022 00:19:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1662070752; 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=o6nUWzhiHul3Yl3P+SzBVLQQvDpfFym6h8RUoqsPj3s=; b=SZQhEhbipmMITMgUhTVe545bwxcZh/DyTDxWygIomnzQVd96tq143zfNzLjqj1dA0BXY0K iytCGY1kMiezU0W2o/uIusmnNV7dbNznYIHL7N7E9sYfEqHvZpzH2isJ56X27lDIZRSu+v yFkBSjg6ClPof0WBkmlmnUQ+5QVIZncwTd/+BCwacjJfDxVexHXhU4mezPyAkvhI9TAfVv HV+EuocuCsPkLp/4HS8mngZapjb3A9az0oj6fgVEj8rDuwm71VTM5C9eq5nntGY8T/Mp/Y AyOFjqiDdCBRJuqwjeaV+7IvBfYZbwMd5gDQJNTnfPP83IG8IrnA+VmsPNIZYQ== From: Michael Walle To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Srinivas Kandagatla , Shawn Guo , Li Yang , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Frank Rowand Cc: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ahmad Fatoum , Philipp Zabel , Michael Walle Subject: [PATCH v2 09/20] nvmem: core: add per-cell post processing Date: Fri, 2 Sep 2022 00:18:46 +0200 Message-Id: <20220901221857.2600340-10-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220901221857.2600340-1-michael@walle.cc> References: <20220901221857.2600340-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, T_SCC_BODY_TEXT_LINE 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 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 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 164511537082..02d0a7099d9a 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; @@ -1518,6 +1520,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); @@ -1626,6 +1635,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 8a41bb30fc87..cb488b338d6f 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.30.2