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 3F732ECAAD1 for ; Tue, 30 Aug 2022 13:38:18 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=la8ULNj3tMEBla2410XjI24zQz6HIzfi4jqhdcfGPK8=; b=hT/squwyFHC660 Lz3L0GGB+TCkGbZ5KWO/F+BGkl3I2AzJjYjIgD/9De7OQmKar2C2hJuUSkj+31jL40DNr3NB0+Kze JATpJVXL9rHOwZJRg1oEIiMbscNIbhLV7CAoqfPK7OurpY1PQajgP/0OJtpA4JLaEy3fm3pJOBtkA 8NJHQd3EGwYwIe9Ja86BKhv9U3O8I1mDXG06c+eYmuQdkM92ItWgk5MRJOuDJksKxSVMRGCb2TO7W p+xgFV4l4VLAHy6Z5B4cOP5m0TcvEL+ZQO0kUM2xcYEMiuBiGk774BuNt3+QFU4Xflk88efxvgGB7 BtCLRGNZBE7Z+YeNbPIw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oT1QV-00HOaX-Hj; Tue, 30 Aug 2022 13:37:11 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oT1QR-00HOZA-P4 for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 13:37:10 +0000 Received: by mail-wr1-x436.google.com with SMTP id c7so7600299wrp.11 for ; Tue, 30 Aug 2022 06:37:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=+q3Kcm7Z8JcF1d1hb0GI/ucgVEvk8yb2HItfmD3paZk=; b=NU3/EStJBPHlk7kN6uEG1oz84H5Jcs+QKIu8/T+eB/3agx+f6pCskn8M4SDPWD7Dyq q66EgziiJZ3EdGRB2x0QZF0ph1SxDX7zaqKnqMJne5GdZfQ4wBqEajYGSoos5VbOVBL3 8il6dedrXJzyFPi4QcVDTsG96O8uo174kTXjtGUbnrtRF6npeLqqL8JPIoB41MzzFX86 xwa2w1kVBYdgy8SaK2jnXy+8VdVV5uCkJRk0kIfKeg7t9DnQSmkodAUSrrGpw4wNr9o5 g2nYirYCEjT0UMph0lOxsMILoLFsaOaHCdso/wavDP/Dk2L1u3o8MI6nKX4MW4cQi+R6 sG8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=+q3Kcm7Z8JcF1d1hb0GI/ucgVEvk8yb2HItfmD3paZk=; b=0fWTzbIfOm1GHto7sYPJlpZquUcJjvHfCcdQ9BjNsIYJri1stVBZgPck+IoY6lk2nk fpBWhoNF39Pueg0haDNv1YYNzCUCZlRKT21gpxK5/ZyGYNdotkscskWQYwKiclJun+dp EnTeGWGNL2blbeoYzs09XxZSakZ8R7Fyx3y5+KLnjQNLWKgP4+1UKb2/tXTJxEE1K+Lz SZpukYalVbMAkCWVUpN1HZGp9O4dZijAwGP59GRyb/EnKg+DmUdPO9taVk/QeMoopZsU KUPDFlBJnBPd+ynnsMHx8mSmMNmEDi48EpITREvTXZ4HaVi3A78jgVFbZMiUKcdPb9yw VbrQ== X-Gm-Message-State: ACgBeo2sS89/4QY49e7dXTZ7NGGYOmdlSinxgSqaHK1wxP5gituK21qs RZ58jATQzqEXkaf/mmMcuRXruA== X-Google-Smtp-Source: AA6agR7lWkpWZIi5bIEym5Qu4vx/h9f4HQXzOy/VgIM2LgtlZz93g9irL0WAuwvzH65xnDqgHu1sfw== X-Received: by 2002:a5d:69c5:0:b0:226:e04f:eb2c with SMTP id s5-20020a5d69c5000000b00226e04feb2cmr2813035wrw.523.1661866626547; Tue, 30 Aug 2022 06:37:06 -0700 (PDT) Received: from [192.168.86.238] (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.googlemail.com with ESMTPSA id b17-20020adfde11000000b0021eaf4138aesm11283959wrm.108.2022.08.30.06.37.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Aug 2022 06:37:05 -0700 (PDT) Message-ID: Date: Tue, 30 Aug 2022 14:37:04 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v1 07/14] nvmem: core: add per-cell post processing Content-Language: en-US To: Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Shawn Guo , Li Yang , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Frank Rowand Cc: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, Ahmad Fatoum References: <20220825214423.903672-1-michael@walle.cc> <20220825214423.903672-8-michael@walle.cc> From: Srinivas Kandagatla In-Reply-To: <20220825214423.903672-8-michael@walle.cc> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220830_063708_853246_39452500 X-CRM114-Status: GOOD ( 27.17 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 25/08/2022 22:44, Michael Walle wrote: > 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 > --- > drivers/nvmem/core.c | 16 ++++++++++++++++ > include/linux/nvmem-consumer.h | 5 +++++ > 2 files changed, 21 insertions(+) > > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c > index 5357fc378700..cbfbe6264e6c 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 post_process; two post_processing callbacks for cells is confusing tbh, we could totally move to use of cell->post_process. one idea is to point cell->post_process to nvmem->cell_post_process during cell creation time which should clean this up a bit. Other option is to move to using layouts for every thing. prefixing post_process with read should also make it explicit that this callback is very specific to reads only. > struct device_node *np; > struct nvmem_device *nvmem; > struct list_head node; > @@ -468,6 +469,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->post_process = info->post_process; > > cell->bit_offset = info->bit_offset; > cell->nbits = info->nbits; > @@ -1500,6 +1502,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->post_process) { > + rc = cell->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); > @@ -1608,6 +1617,13 @@ 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 post_process hook are read-only because we > + * cannot reverse the operation and it might affect other cells, too. > + */ > + if (cell->post_process) > + return -EINVAL; Post process was always implicitly for reads only, this check should also tie the loose ends of cell_post_processing callback. --srini > + > 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-consumer.h b/include/linux/nvmem-consumer.h > index 980f9c9ac0bc..761b8ef78adc 100644 > --- a/include/linux/nvmem-consumer.h > +++ b/include/linux/nvmem-consumer.h > @@ -19,6 +19,10 @@ struct device_node; > struct nvmem_cell; > struct nvmem_device; > > +/* duplicated from nvmem-provider.h */ > +typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index, > + unsigned int offset, void *buf, size_t bytes); > + > struct nvmem_cell_info { > const char *name; > unsigned int offset; > @@ -26,6 +30,7 @@ struct nvmem_cell_info { > unsigned int bit_offset; > unsigned int nbits; > struct device_node *np; > + nvmem_cell_post_process_t post_process; > }; > > /** _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel