From patchwork Tue Dec 6 20:07:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30484 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3026550wrr; Tue, 6 Dec 2022 12:08:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf6MmFWgbrrIqfbAZI+TCxQGNTJDCo+Hp1ZLszVyzevO53AyHQTbWLCwyIcD7n8JnNXo//b/ X-Received: by 2002:a17:902:bd42:b0:186:9c2b:3a39 with SMTP id b2-20020a170902bd4200b001869c2b3a39mr72669787plx.115.1670357306536; Tue, 06 Dec 2022 12:08:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357306; cv=none; d=google.com; s=arc-20160816; b=ycqIvZBKWHCMR4N03LzqG6kRGslzci+qjuXtBkpGKFIrBB7woWAeiR/agINC+0lHg2 vy2snzDzVsDnUr6y7ojt3gDJwR/mBogYX6rIXoNdM12ZCdiBdH+WDTzDGAbnhZR7ztO8 6CKUutVtad8m+PpxhxSoLW6TXP2aoU9kONfu7CWqNJ//nB0VNUu0sbZT8+EE3/J8Uf9O f5n93xvK0y8ibngYfGHj48yrtkbHGT1EE5K4JXVG+5w6FK6Cr7M/OZbflj6Zfrr4VrOI dkPJ92K+e4zy/Eiw/3tD5WvwlFbTV/0JOCnPnSd6yyyuEJmt+G64R0s23oQ/dnejy+BZ tQLw== 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=ILxP0jW0nBzAhvh7z1J9P1H1PJrtvXTRHQ4DduPRocE=; b=Kvk8iMXPZqO/iiRA8xNlFmOBnhujWr9WBvJ65jGcYwZHAvUgGWf4vwhdcvVrGsa7bG QShT4YYmajMQEGyjygD+8L0NciG6w9x1F64XjPFZu+slJt2vYJUXeWF3/YxyBXaoFs9J y+cHIe7CwGCSF7tG+I7t0+e0B7NOZzmm9RoN6IqCsIGDeE78S9jS+F55JX+n4EnmyUBX bxUUwE6vWgZs8N5zrVyXtqfqz00N9gEvxewnVLas5hCjd1bPWkx4O/3QWbs2cXYUqpj2 9HpPE59EPG/FgBoCy291IWYGFvHPxlCeu2OM9tnuOmbwxewAW95xKb1tLA6fGYIqeapd mpHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b="Q5qPxmm/"; 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 b12-20020a630c0c000000b00422c003b4c9si18719013pgl.46.2022.12.06.12.08.13; Tue, 06 Dec 2022 12:08:26 -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="Q5qPxmm/"; 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 S229699AbiLFUHx (ORCPT + 99 others); Tue, 6 Dec 2022 15:07:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229619AbiLFUHu (ORCPT ); Tue, 6 Dec 2022 15:07:50 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41F62CE05; Tue, 6 Dec 2022 12:07:48 -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 05674256D; Tue, 6 Dec 2022 21:07:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357266; 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=ILxP0jW0nBzAhvh7z1J9P1H1PJrtvXTRHQ4DduPRocE=; b=Q5qPxmm//GWuGUlu28YuGCCZP07ElXzUaoHnPSgrXHcDyHCa2WZcE7jxPiIik1qKI0Iqgh KMJveO7U2Ty0lStusmHGY8dOCKR0XyQpbK29xr/XoAqQafBs7PzHIBduj9TVG2U+Eg5jg2 Z+oF/N7bfk13aGNnL++TvrhJpN/DGKskUQPoUTQM+ycjfETt4ClSZKOeY4NEO64EOOlpVM GhOIx/KDDJieM3CaJ8oVIu6KUambo+SdO58wK1djNdh4qnXZybtKSEYu9LQUQpOfbM+ifc zVjzZ+6aUFnOqOQHlDcJoL7LWM6poTCgv1yIKBVLu/5M9GCmUKijOwkgA3T8SA== 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 , Dan Carpenter , Andrew Lunn , Jakub Kicinski Subject: [PATCH v5 01/21] net: add helper eth_addr_add() Date: Tue, 6 Dec 2022 21:07:20 +0100 Message-Id: <20221206200740.3567551-2-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496583110030751?= X-GMAIL-MSGID: =?utf-8?q?1751496583110030751?= Add a helper to add an offset to a ethernet address. This comes in handy if you have a base ethernet address for multiple interfaces. Signed-off-by: Michael Walle Reviewed-by: Andrew Lunn Acked-by: Jakub Kicinski --- changes since v4: - none changes since v3: - fix typo s/and/an/ changes since v2: - none changes since v1: - none include/linux/etherdevice.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index a541f0c4f146..224645f17c33 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -507,6 +507,20 @@ static inline void eth_addr_inc(u8 *addr) u64_to_ether_addr(u, addr); } +/** + * eth_addr_add() - Add (or subtract) an offset to/from the given MAC address. + * + * @offset: Offset to add. + * @addr: Pointer to a six-byte array containing Ethernet address to increment. + */ +static inline void eth_addr_add(u8 *addr, long offset) +{ + u64 u = ether_addr_to_u64(addr); + + u += offset; + u64_to_ether_addr(u, addr); +} + /** * is_etherdev_addr - Tell if given Ethernet address belongs to the device. * @dev: Pointer to a device structure From patchwork Tue Dec 6 20:07:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30486 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3026769wrr; Tue, 6 Dec 2022 12:08:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf4NUp748uWbycwO7/T1NL8DCvQZN1OqKwhPy4eKPXyLUDmj9E0YAVMI/v1ptVpCKxprg/3p X-Received: by 2002:a63:ff0e:0:b0:434:aa69:bba2 with SMTP id k14-20020a63ff0e000000b00434aa69bba2mr77434988pgi.567.1670357334927; Tue, 06 Dec 2022 12:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357334; cv=none; d=google.com; s=arc-20160816; b=aD3emdcBP63v3rNbr0JBqhtQUtGthDCQEe6YleXPaTd91wilr1jfWxr4zSm4zWVG0s o+akEjwFRWsNFJGOWcN6E7rYaoYGbpq+Q91d2pKkVuTD7PvCMlgp7TvRRrE6eqNrnBCr sfMgEklsD30FolQGzEh9oGa00ZyIi7yWa43OLWL/gciGzmZJ3JKMVkbBUof2p1AxGu56 9HgwSI/etOTLbkZpVuN9Loxnbj4SUMYNjlI1hdx6nGt1DAw/YXZpBvd44JzcEWX/s5JS nSSgDGSaRXRY1Q6uIc7Hw5yyeOVShiilRZkvQVPpdt4ecgEgNc0ldVhT+3Hw72f2iGiK ieBA== 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=+oTAXQpoCidxlLbZC4v2hQz+9CJI63MwuPQoTWNzrSE=; b=P4K1NLbm5z9jz4YgF3z/wiu0o0cQEUHXJMoHJekEmwrWrZHSTcsLE7HbuFfwUSLBnL B92W6IfMZouwzYUwvU2MGmxAoSrLL/ZDGXO9uYTSvPmqnW1cl0i3hPE1ERDZL2/LOvMg p8npEz5lQTBzGgfefYpIu8qmrdMaFRs4OhOUA/ymBqeSL5gQSqgim6rHuMOD/V3WhYW1 aKdpW1mpfmBKux6RmGwZU8uWQoJDrROtrfLZsfKhYrdgWuxZSNsYI1gM1JNv+XGmgj9J 92B0awaPjvwep0Xhc4kbJh/AjTtn1k274iQ3CSpgtt1kx5onLysS9L9Woh298JHojQvW hekQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=G+prJL8e; 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 o19-20020a635a13000000b004639c679346si18127734pgb.837.2022.12.06.12.08.41; Tue, 06 Dec 2022 12:08:54 -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=G+prJL8e; 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 S229748AbiLFUID (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229588AbiLFUHu (ORCPT ); Tue, 6 Dec 2022 15:07:50 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB857D2EA; Tue, 6 Dec 2022 12:07:48 -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 9F6E4278D; Tue, 6 Dec 2022 21:07:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357266; 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=+oTAXQpoCidxlLbZC4v2hQz+9CJI63MwuPQoTWNzrSE=; b=G+prJL8edoMbAGl4YKYXudV+7MCxqku9xax3khiiNxfu8VDY2ki3XT1wQaccu8Y916H7LM NdCdNu9FslNEOxJl4yVAEHDzMcQdhMMOVwBimaF8HEYuL72rmdnAmSqkLpvUy1j26F4PGs 84c1Fz2N6xzHoISyHfjvt8awlS+FhzEww9xN+9l8Rq1IIRZ9M29NSuV88s8ER9WxLICg5c m4/onuOACBjp0dxJvGT6ZSnt9EhmB+ud/nzAhGz8Yw1LKK4rc3SL8d2B4OmN4hcpsFqPnA t9Dmw62NisRHkJztKSO+fmHTFD5nGCLECfxPG9ik6XE9nYUjZ4hK29ovqhWukQ== 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 , Dan Carpenter , Rob Herring Subject: [PATCH v5 02/21] of: base: add of_parse_phandle_with_optional_args() Date: Tue, 6 Dec 2022 21:07:21 +0100 Message-Id: <20221206200740.3567551-3-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496612916645446?= X-GMAIL-MSGID: =?utf-8?q?1751496612916645446?= Add a new variant of the of_parse_phandle_with_args() which treats the cells name as optional. If it's missing, it is assumed that the phandle has no arguments. Up until now, a nvmem node didn't have any arguments, so all the device trees haven't any '#*-cells' property. But there is a need for an additional argument for the phandle, for which we need a '#*-cells' property. Therefore, we need to support nvmem nodes with and without this property. Signed-off-by: Michael Walle Reviewed-by: Rob Herring --- changes since v4: - none changes since v3: - none changes since v2: - none changes since v1: - none include/linux/of.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/linux/of.h b/include/linux/of.h index 8b9f94386dc3..98c252d2d851 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1008,6 +1008,31 @@ static inline int of_parse_phandle_with_fixed_args(const struct device_node *np, index, out_args); } +/** + * of_parse_phandle_with_optional_args() - Find a node pointed by phandle in a list + * @np: pointer to a device tree node containing a list + * @list_name: property name that contains a list + * @cells_name: property name that specifies phandles' arguments count + * @index: index of a phandle to parse out + * @out_args: optional pointer to output arguments structure (will be filled) + * + * Same as of_parse_phandle_with_args() except that if the cells_name property + * is not found, cell_count of 0 is assumed. + * + * This is used to useful, if you have a phandle which didn't have arguments + * before and thus doesn't have a '#*-cells' property but is now migrated to + * having arguments while retaining backwards compatibility. + */ +static inline int of_parse_phandle_with_optional_args(const struct device_node *np, + const char *list_name, + const char *cells_name, + int index, + struct of_phandle_args *out_args) +{ + return __of_parse_phandle_with_args(np, list_name, cells_name, + 0, index, out_args); +} + /** * of_property_count_u8_elems - Count the number of u8 elements in a property * From patchwork Tue Dec 6 20:07:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3026652wrr; Tue, 6 Dec 2022 12:08:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf5W26lvv+u+TpHsZWzX4CLwm6UOJ7IHAVMvQJan2YCFoeGKGbhKXbCEELGv8J1nEoRrmLS/ X-Received: by 2002:a17:902:e94e:b0:186:5613:becf with SMTP id b14-20020a170902e94e00b001865613becfmr60647269pll.46.1670357318029; Tue, 06 Dec 2022 12:08:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357318; cv=none; d=google.com; s=arc-20160816; b=pDLnEbCrscPQvJbErPbCJOzPu/rBEHLtpVWpCI/GhloaXkIAzt4XDY0TY/Ynl+3wIo pP1V8eOGhlGINj4pa3gIhpXegKj0K8gguf3OC5FjB3Rgq9g+EoFnhHPXlSHEMA2V3CRX LJNJF6zeuepqaA6jraRm7JJCIrUpNGrQLEDCLasgXChn19aQXgwy//hArBl799tDsyPv ChhgybZ9mtUvRxKj1Hc4m/1MrJlUVDqZO5xeYG+KdDdfj9o8nP497Pg/ANc/Nw5j8wx/ PQoozsIAvovIfJ6aHaM0b6qdnrlMoB3DjwvUMjrIkO9IWxmKa8Tv+gvdeoiSnGHZ98aK T7KA== 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=jccYpGhRy5gogBWLLHj7E2HN2uMWlo2JC7ssSIFLQtc=; b=oF3SEVkp9KCcA93qBjftlsGJdis59zThb+dzSwujtRKB6qDIrtbm9OYlX3lACoFE3l 5vZ1j8qOg0Pvwd7hMJcJzaess+MYDtQUGTwHTyKB/fD3aMp7TJzCVnD5WfWEQFlSkInC orE0d0kMQfpanqPQpf+C7DfULUR1RyLtwp/w/PbSIpJfN+8L5fxC8t/enkmQVHfhxZVY qKw+o88MH1prxdylXrfiS7OWmljEA5hvr9BHarrOQvrCQ4jP37ZTK3WcSSdE8VrPaOpv 9ILBFP+sTAqq7Nu6LnA5YA98oeFpDI/IxYtI4qn8S9US1HLyjQTWvZfHNC2j2Ern0r19 9kqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=KBD7cnd9; 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 i18-20020a170902cf1200b00189772559afsi18070785plg.191.2022.12.06.12.08.24; Tue, 06 Dec 2022 12:08:38 -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=KBD7cnd9; 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 S229445AbiLFUH7 (ORCPT + 99 others); Tue, 6 Dec 2022 15:07:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbiLFUHv (ORCPT ); Tue, 6 Dec 2022 15:07:51 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5736E12745; Tue, 6 Dec 2022 12:07:49 -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 5D69C27AA; Tue, 6 Dec 2022 21:07:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357267; 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=jccYpGhRy5gogBWLLHj7E2HN2uMWlo2JC7ssSIFLQtc=; b=KBD7cnd9QOSO/57qGehuqF4Cc+qXERoCaSlpkkNU8U3/56TH9CVIMhSNXn3X/SW+LPlt1d YKPbpeU47AaBZvH/Bee9NMJzI7zD/is71U+4YMLqrc2QOzYLkU1eWWBXIrmNTzI5nspuKI vH89q/FjWOSL8MJv8i/mMl/gqmCT9YcHJ4uK/Ufc6LzTH+84QSusG4Pqv0tYnjJ0a88Nqf O8XH7QzR8imcMpibVswnbano7GLtLUqSHkto0cvsRD0npwvxlyzrE6eCq/pFKCdUYKOX2t 9PJ9Y872A6dlBbDzaefu4hiqbZZ5K1febkNV0iFcTK7QD6L86PYiChquMcr1Uw== 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 , Dan Carpenter , Rob Herring Subject: [PATCH v5 03/21] of: property: make #.*-cells optional for simple props Date: Tue, 6 Dec 2022 21:07:22 +0100 Message-Id: <20221206200740.3567551-4-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496595089294005?= X-GMAIL-MSGID: =?utf-8?q?1751496595089294005?= Sometimes, future bindings for phandles will get additional arguments. Thus the target node of the phandle will need a new #.*-cells property. To be backwards compatible, this needs to be optional. Prepare the DEFINE_SIMPLE_PROPS() to handle the cells name as optional. Signed-off-by: Michael Walle Tested-by: Miquel Raynal Reviewed-by: Rob Herring --- changes since v4: - none changes since v3: - new patch drivers/of/property.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/of/property.c b/drivers/of/property.c index 134cfc980b70..3043ca7735db 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -1256,8 +1256,8 @@ static struct device_node *parse_suffix_prop_cells(struct device_node *np, if (strcmp_suffix(prop_name, suffix)) return NULL; - if (of_parse_phandle_with_args(np, prop_name, cells_name, index, - &sup_args)) + if (__of_parse_phandle_with_args(np, prop_name, cells_name, 0, index, + &sup_args)) return NULL; return sup_args.np; From patchwork Tue Dec 6 20:07:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3026819wrr; Tue, 6 Dec 2022 12:09:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf4PvC1sy4Ygj3HPZRJW75zGuX+W1x99ceujZWkqCZPJl9pnX51yA324lp1upVb2W6DUP1Oz X-Received: by 2002:a63:ff0b:0:b0:477:362d:85d3 with SMTP id k11-20020a63ff0b000000b00477362d85d3mr62346653pgi.395.1670357341050; Tue, 06 Dec 2022 12:09:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357341; cv=none; d=google.com; s=arc-20160816; b=gx5ws/f4FiVmU+UM+HeW9u+DJmRi/A2p7hntuq3UijRqdpdBZ142c/gCiyH46hrMvQ X4XYXKohuDlsL3JGN/+zqF8KaqSxQFJx4jZEkdmJLhg9oP48M4xpWkMbG123Pd/Z8RiP sXbyra849Ea0Re+fFNZ+DDakLPJmjZXWJKdo3wivRf667DLnCg/mudiFQb8EPto4TVwx eTcYDJOOVY4Gv3bMCXn+E8phoUHKz52jYA6QrUWaLaBaPuB+uOhnENKYtKafEwq87YMq b4nGKuTjqlfovFOiR+Mp1xTStZXX/069rgoHJFTmNWARhIuGMCUMKpCiUTdWziNCe1J7 F7Ug== 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=GCZpm6/evBFKawi2OWlASxbon9/Fiv+QHvyBCaZrlYo=; b=DiidYP07YsXVcxeeGuu5+zuyABl3Pf4fyrzSZ1TLiXGqhF7onMTxPxZcZhGOqkKCP5 Ll6bKObYkiz1LteReq8ZuUbGOvFluWuT36XqxKNwQwV4DTanaszvu8PoJ2Iw2eNPlbqV nCWXUt8oqXKVOeg5sRfwKP6IytxGFyL9Q0SkSsTVk8hfSnSMCJLYdCehLnMD8uZt+hTi KNlSPHB+7GJs0yE/9hhNytjl6aaPrnT7uG5DZfR5zSEvFhPcv7S3HXH/ff9OC3Mn92yr fpIXTOFj+FaciMiFTjgfcWG9uYB59n/zRpKkDBf//w5fbAiWZrJx8EuH42zZ+ouDeXcc r++A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b="zN68/Bsm"; 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 w8-20020a63f508000000b004776a50bd21si12336369pgh.579.2022.12.06.12.08.46; Tue, 06 Dec 2022 12:09:01 -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="zN68/Bsm"; 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 S229589AbiLFUIG (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229638AbiLFUHv (ORCPT ); Tue, 6 Dec 2022 15:07:51 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58BBB13DEE; Tue, 6 Dec 2022 12:07:50 -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 272073A62; Tue, 6 Dec 2022 21:07:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357268; 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=GCZpm6/evBFKawi2OWlASxbon9/Fiv+QHvyBCaZrlYo=; b=zN68/BsmClkxX9MC259Yv06/STiNDey+57CWO29U78jnq9aDIUuxFBrNCmgZd5vtJymFF6 A4dVUQq701M+CKN1i63HU30QTWwR5o4qS5DluALRTxbZiNZyMb6N+/F8QPdHe5EBJ2r0Nm eO2b6CcZmWCRskk9brQH2VPh1SyhJKwoiB2CyQnccIEv6TLPhXDXpFIb7yNNKjetqDL9WE oBCuuBjSxHK8PSr59M9uXzIuxL8xesCUA/Opr1Udu+EVTsfbb5S3/dSFVcgQ6nn0g8Zuxw fgF5zF/E0gZW1nzqLj5+ETEvDKMgzJhAkyZTPQXvHHr6iYnTXc3S8S7PPrcB1g== 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 , Dan Carpenter , Rob Herring Subject: [PATCH v5 04/21] of: property: add #nvmem-cell-cells property Date: Tue, 6 Dec 2022 21:07:23 +0100 Message-Id: <20221206200740.3567551-5-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496618963802275?= X-GMAIL-MSGID: =?utf-8?q?1751496618963802275?= Bindings describe the new '#nvmem-cell-cells' property. Now that the arguments count property is optional, we just add this property to the nvmem-cells. Signed-off-by: Michael Walle Tested-by: Miquel Raynal Reviewed-by: Rob Herring --- changes since v4: - new patch changes since v3: - new patch drivers/of/property.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/property.c b/drivers/of/property.c index 3043ca7735db..8d9ba20a8f90 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -1307,7 +1307,7 @@ DEFINE_SIMPLE_PROP(dmas, "dmas", "#dma-cells") DEFINE_SIMPLE_PROP(power_domains, "power-domains", "#power-domain-cells") DEFINE_SIMPLE_PROP(hwlocks, "hwlocks", "#hwlock-cells") DEFINE_SIMPLE_PROP(extcon, "extcon", NULL) -DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", NULL) +DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", "#nvmem-cell-cells") DEFINE_SIMPLE_PROP(phys, "phys", "#phy-cells") DEFINE_SIMPLE_PROP(wakeup_parent, "wakeup-parent", NULL) DEFINE_SIMPLE_PROP(pinctrl0, "pinctrl-0", NULL) From patchwork Tue Dec 6 20:07:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30487 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3026784wrr; Tue, 6 Dec 2022 12:08:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf7hgnqCmUCkxhBGVrf5JSpnJbWINp8l5JfdjfZOuC2rF1Vs1ZbJYt94rzihiMnJzqE5CUCd X-Received: by 2002:a17:902:d647:b0:189:cf7a:b564 with SMTP id y7-20020a170902d64700b00189cf7ab564mr13954507plh.8.1670357336370; Tue, 06 Dec 2022 12:08:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357336; cv=none; d=google.com; s=arc-20160816; b=RMdQ2eovrJlOqJxEmt8LyaW0DqBG05FPSngkAdgCUO2HBJYop1hmPJ2/Vln4Dj5duO NkY8x/8GI/hzIvcVBNc5SC5O0WRpEe9X9JsmD+WEb1wvKXJ5nhvVCcvCDN13sZbKC3Uj SWcGaUn9b1MzEJChH9FriKXoVNYKRkFp5F20LqMO2/gZd9j/tvEm+tWPXBEjYn+xZwSg JzY4i7QGuKfS7lRntwcp3jB8nSu8KGn3lBQswxxN1d5oiJ3FMO9JRsgXn0i5BLwF2ju8 Heq5SMIg47j+pWJMqvzQ9H7fa5UUGM37dYnz4/GEotAPsP0jQB7HmMxXvQwPnq5DoURS S/vQ== 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=0p2I5HS7ONU/w4jyInXwMyvq84/GI3/niID7ktTA84g=; b=Js3dDbiUZQNTNTzeor+0NTBN9l32YkgbizxUoUeOrVIKuGxuDC2WUCc0uuzqLoirj6 mAJFX7990c5qrHGwZbZDKgldB5/DfD8q2Cj9SAneCthIXvqoqvSG/XqkjWRp0TChnV86 5gRXLY//nms+JC4BIP6tDn6e4FhPydFhT6EPVjVm9sAL+KtdCoWV5+IjMqITiIEP9aHa Q05HkkT129p7PXCQ53mKaqjfWqckJOvgW13f1sg0ULUAGNjkYa6SpNKpm2eJlK1qfNgk es3txGHly5V2yPRcxoWpDudx02XyYowIi8UK3P2eJVb0JWP6cF1e+qLqmtFhEYeK8ePy Y6jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=iPQL7UZp; 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 h11-20020a056a001a4b00b00547d55a4d3bsi18579580pfv.285.2022.12.06.12.08.43; Tue, 06 Dec 2022 12:08:56 -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=iPQL7UZp; 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 S229564AbiLFUIU (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbiLFUHz (ORCPT ); Tue, 6 Dec 2022 15:07:55 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA9B3D2EA; Tue, 6 Dec 2022 12:07:51 -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 A50803B28; Tue, 6 Dec 2022 21:07:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357268; 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=0p2I5HS7ONU/w4jyInXwMyvq84/GI3/niID7ktTA84g=; b=iPQL7UZpEggmdZC21h8CNYAchb00M7jJP9hFmVO68NH1Aoq6L1DqOPUiUESa3QCM3RxOmS hFlxcjpPHoFyaDpHFiN+wNAOfsTegJ8zaQQFhyOB9GvgXodaEiX45QKf2YE6LN07P/5R7W PABgorR2RdBI9AehiU27bTuCKQvjUjddyoR2sRW0fimRHFOb4lqvg6PQ+UI5XtIDuHhV9t +ai38+f2GCPQfZfL0CDZLWJ6pBGy3PnSon/6XCBZGKDv9q9JaMxIaJSfnZnTqDTH5F+nOt c+VkbXs/fuWNayROQUe+T0OWzhqlOW0+Gi2BKvt8DRCH3WpqXoVbvO3HA5rzZQ== 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 , Dan Carpenter Subject: [PATCH v5 05/21] nvmem: core: fix device node refcounting Date: Tue, 6 Dec 2022 21:07:24 +0100 Message-Id: <20221206200740.3567551-6-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496614223521044?= X-GMAIL-MSGID: =?utf-8?q?1751496614223521044?= In of_nvmem_cell_get(), of_get_next_parent() is used on cell_np. This will decrement the refcount on cell_np, but cell_np is still used later in the code. Use of_get_parent() instead and of_node_put() in the appropriate places. Signed-off-by: Michael Walle --- changes since v4: - none changes since v3: - none changes since v2: - new patch drivers/nvmem/core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 321d7d63e068..205a427f564d 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1242,16 +1242,21 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) if (!cell_np) return ERR_PTR(-ENOENT); - nvmem_np = of_get_next_parent(cell_np); - if (!nvmem_np) + nvmem_np = of_get_parent(cell_np); + if (!nvmem_np) { + of_node_put(cell_np); return ERR_PTR(-EINVAL); + } nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); of_node_put(nvmem_np); - if (IS_ERR(nvmem)) + if (IS_ERR(nvmem)) { + of_node_put(cell_np); return ERR_CAST(nvmem); + } cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np); + of_node_put(cell_np); if (!cell_entry) { __nvmem_device_put(nvmem); return ERR_PTR(-ENOENT); From patchwork Tue Dec 6 20:07:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30493 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027146wrr; Tue, 6 Dec 2022 12:09:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf4V1CydR6Rb9C7yDG1CsZJWJOfNjJ4QaT1X4VlWcX1QMlKsTDJx+DILd2pvQU1XBJlmGm+j X-Received: by 2002:a17:902:f78c:b0:187:a98:7ee5 with SMTP id q12-20020a170902f78c00b001870a987ee5mr73455901pln.142.1670357383634; Tue, 06 Dec 2022 12:09:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357383; cv=none; d=google.com; s=arc-20160816; b=rsYWgYTiQCmbVZGAAKIlPWlNLGyqQ2fwl5TGf+K9j8vA+lLbuDWcaOW9ivQbI3JHH4 BZi23VyxPQPwcT5859fm4U1wFQ/vcdXsVhWnf59f1HT1LgAcMSWe2/hbDzDkasNWRURh LADQKqDySlDSy7xvfyvne23M7XIfEm6Q6Dx6HoVlZ9me3p2MzX8IkROBtPwu/1Sv8+hU bHnaVGTS/smiPJjuVImQ2cAfYZzyw1MR8M1+AL7AgXhRPv1wlJZkkasdLzOQ4XfXN2sx bhaWUiyHndteEc/4fxzuMqKzo14AlUWeCkMVvPRE3PsedDag6q76bHiWCiEMKYEAzu76 15Kg== 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=Oi6mw7eMT741U/IKaok3g4GdHwU7S21KLKm3d4kbCc4=; b=CvVj1wGbAhUjm7oYvnJQBmBvO6MxFuErb+V9tUQBjzMj3SbsDxkEho48sLeHSBrpxv cZBvfyCA96wj97ymDH9na371FLnBemwWSmvCBXdFTwx0Q8jzYVb3B96QtME8ZbrFa85x GTfBaaTelKCVftsAWaBUd/a9fu+oMApfGyV4xHJKo78h70SNXCTNBz4Pxro8XxXlXg9C 0ahJ0whLW6oH1Y4i7y8CqdcSvoDPWuGeP1esQoQIXQf4j7YADg4KhQjbkRvNjNBnd4bR soG6KixBl3fiFCQZ6tnYYcJFCRqxsfS1POCnfNABNenPawoJw53rA9B7En//oklGCHTP k+lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b="XdNFdLF/"; 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 n4-20020a170902d2c400b00189f4d813f8si378748plc.578.2022.12.06.12.09.27; Tue, 06 Dec 2022 12:09:43 -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="XdNFdLF/"; 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 S229665AbiLFUIK (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229677AbiLFUHx (ORCPT ); Tue, 6 Dec 2022 15:07:53 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86FE015832; Tue, 6 Dec 2022 12:07:51 -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 060923B2A; Tue, 6 Dec 2022 21:07:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357269; 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=Oi6mw7eMT741U/IKaok3g4GdHwU7S21KLKm3d4kbCc4=; b=XdNFdLF/W9gu0574b6cxs7QHAlkxybckaWRgx5Q+F+cIAHqT1bmVapWEG/Te10qSUYPo9E DBCsLZetGlQPbKAMmB/z+71xVyvN3FK78WKoRMU6JlcbRXvUsQ4mUz4GanWDLmcDeC4o0+ 7/x3DS1I18OJNZGi9KEUWYZcDvuu7/Vh2MLU8QJueLgVVn2itpj2jO4AU/CjrRVax7chlR LJ0SFeCoMoq7yuKAHXhJzKVcRtv7NNAgZXDJ0jD8fWjr0fnl29QmsALGBYf49dCqUqAZEX wRZ0KTGmlV50Ba07wyiR+jxLoliDdW3xCtiVGJUMWe+QGQVqZzzw/WPR/diftQ== 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 , Dan Carpenter Subject: [PATCH v5 06/21] nvmem: core: add an index parameter to the cell Date: Tue, 6 Dec 2022 21:07:25 +0100 Message-Id: <20221206200740.3567551-7-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496663470772885?= X-GMAIL-MSGID: =?utf-8?q?1751496663470772885?= Sometimes a cell can represend multiple values. For example, a base ethernet address stored in the NVMEM can be expanded into multiple discreet ones by adding an offset. For this use case, introduce an index parameter which is then used to distiguish between values. This parameter will then be passed to the post process hook which can then use it to create different values during reading. At the moment, there is only support for the device tree path. You can add the index to the phandle, e.g. &net { nvmem-cells = <&base_mac_address 2>; nvmem-cell-names = "mac-address"; }; &nvmem_provider { base_mac_address: base-mac-address@0 { #nvmem-cell-cells = <1>; reg = <0 6>; }; }; Signed-off-by: Michael Walle --- changes since v4: - none changes since v3: - none changes since v2: - none changes since v1: - none drivers/nvmem/core.c | 37 ++++++++++++++++++++++++---------- drivers/nvmem/imx-ocotp.c | 4 ++-- include/linux/nvmem-provider.h | 4 ++-- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 205a427f564d..24573e63e5a9 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -60,6 +60,7 @@ struct nvmem_cell_entry { struct nvmem_cell { struct nvmem_cell_entry *entry; const char *id; + int index; }; static DEFINE_MUTEX(nvmem_mutex); @@ -1127,7 +1128,8 @@ struct nvmem_device *devm_nvmem_device_get(struct device *dev, const char *id) } EXPORT_SYMBOL_GPL(devm_nvmem_device_get); -static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry, const char *id) +static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry, + const char *id, int index) { struct nvmem_cell *cell; const char *name = NULL; @@ -1146,6 +1148,7 @@ static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry, cons cell->id = name; cell->entry = entry; + cell->index = index; return cell; } @@ -1184,7 +1187,7 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id) __nvmem_device_put(nvmem); cell = ERR_PTR(-ENOENT); } else { - cell = nvmem_create_cell(cell_entry, con_id); + cell = nvmem_create_cell(cell_entry, con_id, 0); if (IS_ERR(cell)) __nvmem_device_put(nvmem); } @@ -1232,15 +1235,27 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) struct nvmem_device *nvmem; struct nvmem_cell_entry *cell_entry; struct nvmem_cell *cell; + struct of_phandle_args cell_spec; int index = 0; + int cell_index = 0; + int ret; /* if cell name exists, find index to the name */ if (id) index = of_property_match_string(np, "nvmem-cell-names", id); - cell_np = of_parse_phandle(np, "nvmem-cells", index); - if (!cell_np) - return ERR_PTR(-ENOENT); + ret = of_parse_phandle_with_optional_args(np, "nvmem-cells", + "#nvmem-cell-cells", + index, &cell_spec); + if (ret) + return ERR_PTR(ret); + + if (cell_spec.args_count > 1) + return ERR_PTR(-EINVAL); + + cell_np = cell_spec.np; + if (cell_spec.args_count) + cell_index = cell_spec.args[0]; nvmem_np = of_get_parent(cell_np); if (!nvmem_np) { @@ -1262,7 +1277,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) return ERR_PTR(-ENOENT); } - cell = nvmem_create_cell(cell_entry, id); + cell = nvmem_create_cell(cell_entry, id, cell_index); if (IS_ERR(cell)) __nvmem_device_put(nvmem); @@ -1415,8 +1430,8 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void } static int __nvmem_cell_read(struct nvmem_device *nvmem, - struct nvmem_cell_entry *cell, - void *buf, size_t *len, const char *id) + struct nvmem_cell_entry *cell, + void *buf, size_t *len, const char *id, int index) { int rc; @@ -1430,7 +1445,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, nvmem_shift_read_buffer_in_place(cell, buf); if (nvmem->cell_post_process) { - rc = nvmem->cell_post_process(nvmem->priv, id, + rc = nvmem->cell_post_process(nvmem->priv, id, index, cell->offset, buf, cell->bytes); if (rc) return rc; @@ -1465,7 +1480,7 @@ void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) if (!buf) return ERR_PTR(-ENOMEM); - rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id); + rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id, cell->index); if (rc) { kfree(buf); return ERR_PTR(rc); @@ -1778,7 +1793,7 @@ ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, if (rc) return rc; - rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL); + rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL, 0); if (rc) return rc; diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index 14284e866f26..e9b52ecb3f72 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -222,8 +222,8 @@ static int imx_ocotp_read(void *context, unsigned int offset, return ret; } -static int imx_ocotp_cell_pp(void *context, const char *id, unsigned int offset, - void *data, size_t bytes) +static int imx_ocotp_cell_pp(void *context, const char *id, int index, + unsigned int offset, void *data, size_t bytes) { struct ocotp_priv *priv = context; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 50caa117cb62..8f964b394292 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -20,8 +20,8 @@ typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset, typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, void *val, size_t bytes); /* used for vendor specific post processing of cell data */ -typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, unsigned int offset, - void *buf, size_t bytes); +typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index, + unsigned int offset, void *buf, size_t bytes); enum nvmem_type { NVMEM_TYPE_UNKNOWN = 0, From patchwork Tue Dec 6 20:07:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30489 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3026908wrr; Tue, 6 Dec 2022 12:09:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf5b9avAz0jkJi1KiLDAXu+5uuVEHxG1RDp6+9xjo0mRLLRZQQv4zgjil6IwsJp04ZAchK4O X-Received: by 2002:a17:90a:bc48:b0:219:b821:77ad with SMTP id t8-20020a17090abc4800b00219b82177admr15964605pjv.217.1670357353514; Tue, 06 Dec 2022 12:09:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357353; cv=none; d=google.com; s=arc-20160816; b=lLwvslG2QJ3YckvuAf2JYWBCiuvQ6d0WJHA0URbKHuc5UTWIX6f2CoLKdLF1hmWZ6T /XT8fpB4QMFwUV1SF9KRdtWOrPKvd9Yv5Lb8SvkK8TGeETyyralQ/ro2Mn6o8wrtY4gY /kPZafJzOvkqcG/NBqDKr/XprHLdeSLL+axW1wGbzxXIePFnzSMfKKpBUcnK+PulGGNY G5NXNamguLYSHkbzqMLXSIHOAAnvf0ysvT9nuPKxPeNuhWh3AvknAkUqTmquR13wYr2e xJT7NaTxTHFzUiUCuSunRsN6YQiTQsY7Fp5r81ZNIeadfjsWUcJbXrwubN9bUcAbbYYY bEJg== 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=PFEDTEXwsw2qqq6elYOKJxReUTOIeiJ26cX4UKFFZhU=; b=QzvnJGmduZV4QHwF9jXNe17l9zn7f7sgJD/uUBcwvrqxiXuGcmNSmSd0D1OeG6k+u5 8EbZAymlK7jXLcZSQ8HGQPV9ilQa4s//OhY2hdGWUxGEZ9uiYbiwrDKl8jdVLeaCpwRH 31IQtR55CmxiKkyrP973iKido2TibVEin4DjQiJ53TsCFZDa/TlL15tr401J06GNjI8n fOeENBrWx96xMEhx7usvpoVylCTqBVR6aXYG6Dd3fJAZ4r20eke51H8pUcmdy/lBeuO9 KxnHZmsfWgvR/TuygwEQdS/kynyUjCOM9kTHgwGSHwM1sq3YgScsq8Skq1PcHbUfLncD 7A8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=IsIO4ZeT; 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 j16-20020a63cf10000000b00476deba079fsi17958283pgg.507.2022.12.06.12.08.59; Tue, 06 Dec 2022 12:09:13 -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=IsIO4ZeT; 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 S229854AbiLFUI0 (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbiLFUHz (ORCPT ); Tue, 6 Dec 2022 15:07:55 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB59B12745; Tue, 6 Dec 2022 12:07:51 -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 C77293B2D; Tue, 6 Dec 2022 21:07:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357269; 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=PFEDTEXwsw2qqq6elYOKJxReUTOIeiJ26cX4UKFFZhU=; b=IsIO4ZeTGs/giCwkE4n+Iii9BjTI40C8PHHjOY/4aauaDAntY4B7sP8zdOeRbEyv3ZWC5y 5iZgZTeODbK055lb9RNszIdTL4gb1E4k+yPBuyaggp8Etw6eS8cOTOdDu9b2WRXQ3oxPJv k7OhiMYjec85gjmk3h0zXJhiNirIqSbebYti1qVCwrcrwqD98x30norhBJdWGVUDEWuq9B ltxVYomdCj+GS7QuKqagDxklZ6GDT/RsHhmLVOFwezSU0u0IBoQqp+4cbXhNKaGt8o/JTt Lkqn9xkk1SoYZXl39GtaTfKVdDG4kqXJh0Mvu+ANzQKA/uWHNQQKbHj0oJiVsg== 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 , Dan Carpenter Subject: [PATCH v5 07/21] nvmem: core: move struct nvmem_cell_info to nvmem-provider.h Date: Tue, 6 Dec 2022 21:07:26 +0100 Message-Id: <20221206200740.3567551-8-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496632308388161?= X-GMAIL-MSGID: =?utf-8?q?1751496632308388161?= struct nvmem_cell_info is used to describe a cell. Thus this should really be in the nvmem-provider's header. There are two (unused) nvmem access methods which use the nvmem_cell_info to describe the cell to be accesses. One can argue, that they will create a cell before accessing, thus they are both a provider and a consumer. struct nvmem_cell_info will get used more and more by nvmem-providers, don't force them to also include the consumer header, although they are not. Signed-off-by: Michael Walle --- changes since v4: - none changes since v3: - none changes since v2: - none changes since v1: - new patch include/linux/nvmem-consumer.h | 10 +--------- include/linux/nvmem-provider.h | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 980f9c9ac0bc..1f62f7ba71ca 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -18,15 +18,7 @@ struct device_node; /* consumer cookie */ struct nvmem_cell; struct nvmem_device; - -struct nvmem_cell_info { - const char *name; - unsigned int offset; - unsigned int bytes; - unsigned int bit_offset; - unsigned int nbits; - struct device_node *np; -}; +struct nvmem_cell_info; /** * struct nvmem_cell_lookup - cell lookup entry diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 8f964b394292..14a32a1bc249 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -14,7 +14,6 @@ #include struct nvmem_device; -struct nvmem_cell_info; typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset, void *val, size_t bytes); typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, @@ -47,6 +46,24 @@ struct nvmem_keepout { unsigned char value; }; +/** + * struct nvmem_cell_info - NVMEM cell description + * @name: Name. + * @offset: Offset within the NVMEM device. + * @bytes: Length of the cell. + * @bit_offset: Bit offset if cell is smaller than a byte. + * @nbits: Number of bits. + * @np: Optional device_node pointer. + */ +struct nvmem_cell_info { + const char *name; + unsigned int offset; + unsigned int bytes; + unsigned int bit_offset; + unsigned int nbits; + struct device_node *np; +}; + /** * struct nvmem_config - NVMEM device configuration * From patchwork Tue Dec 6 20:07:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30497 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027289wrr; Tue, 6 Dec 2022 12:10:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf7gjWDX6CJ0lYsWIEaUTbw8HJ4N92oNJouTfxvUTzSKsR5xAenVW8BlO82A28EiJbFucZ48 X-Received: by 2002:a63:4605:0:b0:478:80f8:66a6 with SMTP id t5-20020a634605000000b0047880f866a6mr20488668pga.222.1670357403527; Tue, 06 Dec 2022 12:10:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357403; cv=none; d=google.com; s=arc-20160816; b=iR3v/BT9h3l3cQmqI+0nQ8wdc4EU5NU6su6AiNxbMHWQ3W7pmVE7D5+9KSqh6CY3q0 WZBB/mrxITNvZ65rls5Je84M16HiCXsXKnOp9Yjz1FcbzlcjuVZc2GeCyu46c6w2GBxw Ag+POjlC3I+TXgTN9ouDV4cxGZXdLv7syXav8XB0WvRN9/XRpBeYYbbsoeoA7BGXutgx 2gqnvVmHR7e+rM77+eFRhq839vVOTFiClfD+QYLLONer1JuUXMw5pybgzDtx8Q9Zmn37 532V4h/bFaqXlEYtdkNn+CPThB4R4dhA33K59vLEkc8fqKxdGjqOYf1myftNHLiHEj6v C64w== 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=XjEsutPxJcw9ycuwtn1DnBCaMeP1tVgn6MXPS4VZA6I=; b=WElqacir0REFsxG5nx4IWU33I1qlI13mriLWdNk/HtnyKdFM5ArOA190D+M4eRBCvO HDAkxoDfrYzNvsSEeS5WfhUTQ8+QjTPFC/JLYdIXP0jhBeW6Ich0wBNLmgK8om6v7vJF aj2TmPAYyhVR2PlkMInHzGFnnmUyu5D3rlqETNBx/pj2nQWky/rjrJ4cE5CjUJUeJ7Vq Cc/tzmdOhJI23XWZcy53B35WvqAI/8rMEzsPKmSeKoEV9PBFyhWgax5ccIFLfZMJeoDq eaZNYPdRysgQgJUtkg1TkvshmOPtlFTN6uxkFDY/PKiwMXA1Heil39w1+JY/qpwjzPhp 7XPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=QHHe21qR; 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 h14-20020a056a001a4e00b0056b81818621si19896908pfv.157.2022.12.06.12.09.50; Tue, 06 Dec 2022 12:10:03 -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=QHHe21qR; 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 S229818AbiLFUIO (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229619AbiLFUHy (ORCPT ); Tue, 6 Dec 2022 15:07:54 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB6EA165B6; Tue, 6 Dec 2022 12:07:51 -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 110A43B37; Tue, 6 Dec 2022 21:07:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357270; 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=XjEsutPxJcw9ycuwtn1DnBCaMeP1tVgn6MXPS4VZA6I=; b=QHHe21qRSQ4K/jwvw4jcKRSJB8BvJsT+adygn6kWzVp2w0U1HAI0N+2uWwdy5XqCOa59Y9 vTlZZQi5qVkrT/fHfoQa4OPQ+cuiLs5u/ilrxbn5pxtDbkoBRKvsUYPzdBAmib750BBmiM un+nXH6ib5oA9WbkeW82amZuCZt7dzk4QuDr5hQ+R2JeN8qvObxdVvHZpDN83IGqRcISDj j13yv0ejM+RriBdzQiWl3GWrFJ+o5p3cWP1x7ddUDseKNcLG7McJ8zyaWeBKjtgF361vqD 3X3ZloyXqjWzlP+T2W/P08VcbpKNkmAPfTtHrPtJbuz08wT0CrbuNuBFAA6DEg== 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 , Dan Carpenter Subject: [PATCH v5 08/21] nvmem: core: drop the removal of the cells in nvmem_add_cells() Date: Tue, 6 Dec 2022 21:07:27 +0100 Message-Id: <20221206200740.3567551-9-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496684687649876?= X-GMAIL-MSGID: =?utf-8?q?1751496684687649876?= If nvmem_add_cells() fails, the whole nvmem_register() will fail and the cells will then be removed anyway. This is a preparation to introduce a nvmem_add_one_cell() which can then be used by nvmem_add_cells(). This is then the same to what nvmem_add_cells_from_table() and nvmem_add_cells_from_of() do. Signed-off-by: Michael Walle --- changes since v4: - none changes since v3: - fix typo, s/prepartion/preparation/ changes since v2: - none changes since v1: - none drivers/nvmem/core.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 24573e63e5a9..7c76e0e0072e 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -515,7 +515,7 @@ static int nvmem_add_cells(struct nvmem_device *nvmem, int ncells) { struct nvmem_cell_entry **cells; - int i, rval; + int i, rval = 0; cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL); if (!cells) @@ -525,28 +525,22 @@ static int nvmem_add_cells(struct nvmem_device *nvmem, cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL); if (!cells[i]) { rval = -ENOMEM; - goto err; + goto out; } rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, &info[i], cells[i]); if (rval) { kfree(cells[i]); - goto err; + goto out; } nvmem_cell_entry_add(cells[i]); } +out: /* remove tmp array */ kfree(cells); - return 0; -err: - while (i--) - nvmem_cell_entry_drop(cells[i]); - - kfree(cells); - return rval; } From patchwork Tue Dec 6 20:07:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30492 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027123wrr; Tue, 6 Dec 2022 12:09:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf6PdCgcWObAplKSFQ2+lmmsIWamgxi70pCypDZWUgClpdm363zolx8Xd4xd0HOQJZaS03CI X-Received: by 2002:a63:e646:0:b0:470:15cd:d428 with SMTP id p6-20020a63e646000000b0047015cdd428mr81721357pgj.213.1670357379683; Tue, 06 Dec 2022 12:09:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357379; cv=none; d=google.com; s=arc-20160816; b=O/Nlo5aA9k78tD/0IJ7O/gbwL1us4E/2cv5NZAHizlyyXB9dOU5rwhzDi7eLaRwFkm tyX0XUtb6cUBzEx7m9vkjP9skigwmYiIVkM/HV1OviTpP/s2OPMg5mrGkCeRsJVyMvq0 WbQfpoYMSu0QugSS9X/H48ABmat7iZccAA1R6FR0A4flroJNFEH8coK9fRi1pv9xZDL+ ZWfdpJ61IXuEqwbKWz49lrCYe2f6QT2Kg2LxX/7OftOz3vS56RiSnbayXsk7naThqF70 9IOH9aO0c87vtN2W1UAzsp//ak/af0wjh2B2DK4As1YQKPp09cUf5KZCzr6koCkrnhUj JSuQ== 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=mvTkfYS/F5bhxjZrXTlkPXrK+rtGefsDiAak505Ve5I=; b=ZnWCe8wk+uvcMIVlZKfI+demAmtaFgL7Wq/emyJs/q0Nx/1WNQ/k00yucQx6Ijb7DF m3lZ5e1uKcAzmejYgXNso2fo5hzqzSpZ3D703Dn9GtFrt5GwRwcYmxL2DJ1WhqUq3PmY gx3ApCa44hkLu3mZSOW/5IgwGv/e0KeiX9i+PCwEbAxzrwsKZmCZ111dZxdu3I1LIy1w 9BFvA5guPUYNT6sf1qs2L7C5hdXy5CQ/La2RsCgzj2btTjfmSuXXwQR/va8rPCJ4MkMQ oukin7M3SCyxwiOlMrxhlJuULY/H6lVleiIz5DDBC4EiV3vAZg7C23kPhX76ab/h2wHB epxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=opmIFnOx; 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 j193-20020a638bca000000b00477bf2ebf14si18316119pge.266.2022.12.06.12.09.25; Tue, 06 Dec 2022 12:09:39 -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=opmIFnOx; 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 S229875AbiLFUIc (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbiLFUHz (ORCPT ); Tue, 6 Dec 2022 15:07:55 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB66C13DEE; Tue, 6 Dec 2022 12:07:52 -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 63FB43B39; Tue, 6 Dec 2022 21:07:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357270; 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=mvTkfYS/F5bhxjZrXTlkPXrK+rtGefsDiAak505Ve5I=; b=opmIFnOxHWQg0pmLwLLkrxg6RJTvYGzaJg6JawH8Qi4UGjW5MBsazUYQrHZW/DXBTnn2tq kAPYGcC6FhZA/GYC3fT6VL2tg9SkTyQUXn/FvX95xIzu48RfERGNithitZ5pp6rHYnZ1XO dKF/RGFhhjXQpREAv18gyflhb60KHzTe7t4BHMAxK+mLxNdbn2ZRnt26GDqwf1sDpFtLsM srt8hj2Nkhpz1iUxL3TL42Tqbkc80+eMrCA5o2H+smHMnJbqoXgdshfa4CRdatudLUz6+o IllbFKKUaK3GIj9NbN3MdzDzmU8zmOjQsXEzH4DzumDHh4MAFZ4d/qbTh7axQA== 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 , Dan Carpenter Subject: [PATCH v5 09/21] nvmem: core: fix cell removal on error Date: Tue, 6 Dec 2022 21:07:28 +0100 Message-Id: <20221206200740.3567551-10-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496659727709080?= X-GMAIL-MSGID: =?utf-8?q?1751496659727709080?= nvmem_add_cells() could return an error after some cells are already added to the provider. In this case, the added cells are not removed. Remove any registered cells if nvmem_add_cells() fails. Signed-off-by: Michael Walle --- changes since v4: - new patch drivers/nvmem/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 7c76e0e0072e..70c3d0a20d0d 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -851,7 +851,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (config->cells) { rval = nvmem_add_cells(nvmem, config->cells, config->ncells); if (rval) - goto err_teardown_compat; + goto err_remove_cells; } rval = nvmem_add_cells_from_table(nvmem); @@ -868,7 +868,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) err_remove_cells: nvmem_device_remove_all_cells(nvmem); -err_teardown_compat: if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); err_device_del: From patchwork Tue Dec 6 20:07:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027178wrr; Tue, 6 Dec 2022 12:09:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf5GNVfaOxoVMtNxJb05CcIG/LF8j/Zlk5020oZg3vT5mu/0Kee8pUV2GWyejbfaRxXKWXlY X-Received: by 2002:a63:4087:0:b0:477:15c8:ff67 with SMTP id n129-20020a634087000000b0047715c8ff67mr65989297pga.275.1670357388614; Tue, 06 Dec 2022 12:09:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357388; cv=none; d=google.com; s=arc-20160816; b=DMXlX75P9Ibx51nCb7rFyL4FO6Eg0jpRw22RRiVXby6qXAzEkzqpr0ign6OARu/mUe KNWZDGvPgbthScfFKFqq/lWNPdery8I9L9VCVCtkZhC0wqfNfSw7Oz0DlDN1Hh0GGVJX 3ufvIonD48i5/EVJuirZWC5L4n74FK+sJyLE9IsvNstlVKG6xZtyYgN9EM4+YaASG5Uq 0oKVZgIyFDuXmw6ft3mWQMVlsTpa6CJ+T5O9cUCjxnJZcnTKjX1gTtaCHUJ+Mo6bg08A YGQkv+m3usvzk4Zm6OgpTErB/gF120xP13N2NgW950pTN2zfrUx9TQNYr/h5IaPxe6a5 mZeA== 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=fJvYnlOS07so9NTt9eBezqGlHSanr4dGO+tZaJE2fLQ=; b=o+Gtx5syO1mMbhIhDSH/ak7tCEOAbCKsK6VV8dMO0CAVOSGs12YtnP1aPvZdtjrPns Msa0nIDc0kofWnnrFMzmUqGcjnLtUqL5QlDRaSa1ti7AQoYCVjH7C4dFDjT2AO/y0MUN 6X1VL7UIKSiEXlOApz8NuMD9SB4YPqK/bpB9DwupwygV5N3E911weqCJrkHa23w1nMT2 8Rd/x1kv5A9ndJGicCEduXjTmox+WEoZ3cuSAUJauLfpJcCzj4ZvnFafSA7D7OKg3Gjy J3EHOAY6ZH26M/vFAf4f2zZM1ssnHrxTbbWTUUmR7/DCAZSlcPSQmphFFEDla1nT0WG8 ETdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=VNHypZmA; 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 g11-20020a65580b000000b00477cd4f65fasi18211523pgr.197.2022.12.06.12.09.34; Tue, 06 Dec 2022 12:09: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=@walle.cc header.s=mail2022082101 header.b=VNHypZmA; 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 S229769AbiLFUIS (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbiLFUHy (ORCPT ); Tue, 6 Dec 2022 15:07:54 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB82017890; Tue, 6 Dec 2022 12:07:52 -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 F0ED83B3B; Tue, 6 Dec 2022 21:07:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357271; 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=fJvYnlOS07so9NTt9eBezqGlHSanr4dGO+tZaJE2fLQ=; b=VNHypZmAIZx9Lg40BeJsvFXwHpTfxcz/Tzy00fmDxoGRWvoLjn5s7Z0xK9P6UqYeoXPLRj kZlTjnwlYUEa899SDXkCq2D1hFYPCqN2HH5tuGkIfXWRfrTdAHxIWXB5B4mI6Eg8JL2dxv K7mDG09R3Na+tvedP4vuVF5tZoeOFWOh1NGpKflFIYn/4JNaZc1e9x1MJ3Qoww7Nw1kcTE SoXAMl787rd1O5lqrGSmZdx5iZbfs+eXyNJaJxRRQCCfE80+FyknoVyAY3CWVGgx/MUnC8 K5vI9tlHK7syo7D0ZxxyQimWPAcWgQzhpckjd94cC9vsxQCjwlQvcgfNaKxcUQ== 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 , Dan Carpenter Subject: [PATCH v5 10/21] nvmem: core: add nvmem_add_one_cell() Date: Tue, 6 Dec 2022 21:07:29 +0100 Message-Id: <20221206200740.3567551-11-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496669078281422?= X-GMAIL-MSGID: =?utf-8?q?1751496669078281422?= Add a new function to add exactly one cell. This will be used by the nvmem layout drivers to add custom cells. In contrast to the nvmem_add_cells(), this has the advantage that we don't have to assemble a list of cells on runtime. Signed-off-by: Michael Walle --- changes since v4: - none changes since v3: - none changes since v2: - add EXPORT_SYMBOL_GPL() changes since v1: - none drivers/nvmem/core.c | 59 ++++++++++++++++++++-------------- include/linux/nvmem-provider.h | 8 +++++ 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 70c3d0a20d0d..5db169aa7988 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -501,6 +501,36 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem, return 0; } +/** + * nvmem_add_one_cell() - Add one cell information to an nvmem device + * + * @nvmem: nvmem device to add cells to. + * @info: nvmem cell info to add to the device + * + * Return: 0 or negative error code on failure. + */ +int nvmem_add_one_cell(struct nvmem_device *nvmem, + const struct nvmem_cell_info *info) +{ + struct nvmem_cell_entry *cell; + int rval; + + cell = kzalloc(sizeof(*cell), GFP_KERNEL); + if (!cell) + return -ENOMEM; + + rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell); + if (rval) { + kfree(cell); + return rval; + } + + nvmem_cell_entry_add(cell); + + return 0; +} +EXPORT_SYMBOL_GPL(nvmem_add_one_cell); + /** * nvmem_add_cells() - Add cell information to an nvmem device * @@ -514,34 +544,15 @@ static int nvmem_add_cells(struct nvmem_device *nvmem, const struct nvmem_cell_info *info, int ncells) { - struct nvmem_cell_entry **cells; - int i, rval = 0; - - cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL); - if (!cells) - return -ENOMEM; + int i, rval; for (i = 0; i < ncells; i++) { - cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL); - if (!cells[i]) { - rval = -ENOMEM; - goto out; - } - - rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, &info[i], cells[i]); - if (rval) { - kfree(cells[i]); - goto out; - } - - nvmem_cell_entry_add(cells[i]); + rval = nvmem_add_one_cell(nvmem, &info[i]); + if (rval) + return rval; } -out: - /* remove tmp array */ - kfree(cells); - - return rval; + return 0; } /** diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 14a32a1bc249..385d29168008 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -155,6 +155,9 @@ struct nvmem_device *devm_nvmem_register(struct device *dev, void nvmem_add_cell_table(struct nvmem_cell_table *table); void nvmem_del_cell_table(struct nvmem_cell_table *table); +int nvmem_add_one_cell(struct nvmem_device *nvmem, + const struct nvmem_cell_info *info); + #else static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c) @@ -172,6 +175,11 @@ devm_nvmem_register(struct device *dev, const struct nvmem_config *c) static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {} static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {} +static inline int nvmem_add_one_cell(struct nvmem_device *nvmem, + const struct nvmem_cell_info *info) +{ + return -EOPNOTSUPP; +} #endif /* CONFIG_NVMEM */ #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */ From patchwork Tue Dec 6 20:07:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3026978wrr; Tue, 6 Dec 2022 12:09:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf4h9FoxIM4BtMCKcQnnbO9i9XTrbJekuoci3S2Rep0ESJ8OZsBFerpDHNxGTz4pnKbwYO4H X-Received: by 2002:a63:171e:0:b0:476:9983:b395 with SMTP id x30-20020a63171e000000b004769983b395mr63571645pgl.355.1670357361387; Tue, 06 Dec 2022 12:09:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357361; cv=none; d=google.com; s=arc-20160816; b=0JwBRigO64WTsixQ0G/dEIq0MPqFI0Y/vpVjcfW2WMI/0gH3pqgRXgiyX9YOM2tgr2 yFrPiUA1YbIQ7+0ggX6E+705bN7D7HdUA6eGdBpOxK/wraok0x+Q/CDWwX0qz2BMefvB 8OQPpjPkcwnSEp9RT0DFsCeXyygfPH7rN+ems08JjWTezFCwxlgaHmYNGVWRnXoRvwyH iaVAzvfpa/wyjd0V9DGabuPqs6QZ/cGDY3/sP1hC148FTSIzfmxU+rPS8n4ChslGZDYE uiY8Jd7blva2LH0Q3QauqAOAeugOLkr3P248Sbm/rPXh8RxE1ue9dlOeF/cE1ePYVZhO Hmgg== 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=wuDmiAG2lNQr5F+Y/u377Zv6TIAoB3gQ2DuFpKEqzG0=; b=Zf6UKqemsfh8a4VfmtdO0f/PjwCLrX5v813MGHkIp8HcgPH1UhIXZjbQaejt8JL/X0 BdDFsm1CawWYkJGHuFlFZbQHAJRcZAD1eZdEw+YzWLXq0i+nfYRvAP7BWoL//Ci0mUDR pUEuxITbzJeh+yJdaDV1SM3ewnAdBPEeA87l4UjtoeoYh4q6VoCwc0PXdiBw/8GOhEgC /K0x2ge7qI8fXbU8NQjN618tieO8KM9A5+jg5ndhOv6XSotDuu+xQKE4Tdcm3SHdiv0H 0AS0C+r4Sw3vjEvBHXUdqSFG4ggi2acM/bKdBVZJvcBZM0Ds1+1yrX8LDRw3wqBGx9ol MNRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=xXm6zyXM; 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 px17-20020a17090b271100b002132058f474si20210614pjb.178.2022.12.06.12.09.05; Tue, 06 Dec 2022 12:09:21 -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=xXm6zyXM; 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 S229775AbiLFUIg (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229730AbiLFUHz (ORCPT ); Tue, 6 Dec 2022 15:07:55 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4041518356; Tue, 6 Dec 2022 12:07:52 -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 3F3E33B3D; Tue, 6 Dec 2022 21:07:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357271; 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=wuDmiAG2lNQr5F+Y/u377Zv6TIAoB3gQ2DuFpKEqzG0=; b=xXm6zyXMvjwyzHY3/mrx2gMzr/Yk8wiy7PgLg1+wyr6l+zy7dp1fGSdPPQUe1hR1Ca+w7F JyV9OCIHEx7j1thtXOM2aHbyHO5kkbl1doqkl29v95t7IAm06cpp2XFC/9qtFDeqnCy93o Maz4eSKDSKkGAfRbdzxxuZkhJVR4ij8NzhY6Ab3Q6ZS/0Uj4Z7172ZNTYGam+9WtDXvwjH DKEUSXCP/RqM9DGvWE9jt4ZNH+vnKPTDTz11ojXlAgmlpZBnqV0Rimstkx7b6w9LwMeDuW hYMSoaj4izyG5MElD1XZHzGJuyBwJnJ0Eo2jfJLKCwVZw1NPfzNkauYYCiiswA== 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 , Dan Carpenter Subject: [PATCH v5 11/21] nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of() Date: Tue, 6 Dec 2022 21:07:30 +0100 Message-Id: <20221206200740.3567551-12-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496640332902438?= X-GMAIL-MSGID: =?utf-8?q?1751496640332902438?= Convert nvmem_add_cells_from_of() to use the new nvmem_add_one_cell(). This will remove duplicate code and it will make it possible to add a hook to a nvmem layout in between, which can change fields before the cell is finally added. Signed-off-by: Michael Walle --- changes since v4: - drop now unused allocation of nvmem_cell_entrys, thanks Dan changes since v3: - none changes since v2: - none changes since v1: - new patch drivers/nvmem/core.c | 45 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 5db169aa7988..0993e1ebdeaf 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -688,15 +688,14 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem) static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) { - struct device_node *parent, *child; struct device *dev = &nvmem->dev; - struct nvmem_cell_entry *cell; + struct device_node *child; const __be32 *addr; - int len; + int len, ret; - parent = dev->of_node; + for_each_child_of_node(dev->of_node, child) { + struct nvmem_cell_info info = {0}; - for_each_child_of_node(parent, child) { addr = of_get_property(child, "reg", &len); if (!addr) continue; @@ -706,40 +705,24 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) return -EINVAL; } - cell = kzalloc(sizeof(*cell), GFP_KERNEL); - if (!cell) { - of_node_put(child); - return -ENOMEM; - } - - cell->nvmem = nvmem; - cell->offset = be32_to_cpup(addr++); - cell->bytes = be32_to_cpup(addr); - cell->name = kasprintf(GFP_KERNEL, "%pOFn", child); + info.offset = be32_to_cpup(addr++); + info.bytes = be32_to_cpup(addr); + info.name = kasprintf(GFP_KERNEL, "%pOFn", child); addr = of_get_property(child, "bits", &len); if (addr && len == (2 * sizeof(u32))) { - cell->bit_offset = be32_to_cpup(addr++); - cell->nbits = be32_to_cpup(addr); + info.bit_offset = be32_to_cpup(addr++); + info.nbits = be32_to_cpup(addr); } - if (cell->nbits) - cell->bytes = DIV_ROUND_UP( - cell->nbits + cell->bit_offset, - BITS_PER_BYTE); + info.np = of_node_get(child); - if (!IS_ALIGNED(cell->offset, nvmem->stride)) { - dev_err(dev, "cell %s unaligned to nvmem stride %d\n", - cell->name, nvmem->stride); - /* Cells already added will be freed later. */ - kfree_const(cell->name); - kfree(cell); + ret = nvmem_add_one_cell(nvmem, &info); + kfree(info.name); + if (ret) { of_node_put(child); - return -EINVAL; + return ret; } - - cell->np = of_node_get(child); - nvmem_cell_entry_add(cell); } return 0; From patchwork Tue Dec 6 20:07:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30500 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027345wrr; Tue, 6 Dec 2022 12:10:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf6EXCvgfZktpQ7/9Klm0wr+AnSumwAO2h3g+PuP5ULoqb9g5txDAvuN27R4ItWLHOImj1eg X-Received: by 2002:a17:90a:ad46:b0:219:9a95:ac2b with SMTP id w6-20020a17090aad4600b002199a95ac2bmr21036982pjv.228.1670357410699; Tue, 06 Dec 2022 12:10:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357410; cv=none; d=google.com; s=arc-20160816; b=hupXTeqQHnjFuoOPF+TJTBUBr8KVOqcdngPNze84upAdkRlYxN1h/dG3G/+ZUZtph4 7tHCzo6F+131BD0/uDdyCq0S0A9Bjo+A7cTc041P38wOx3BuCThoZ8HOOEhanufJN9wE EmnWPcXMenfAoVQgEAveTxkxp2UDd2+edBUrK/wqwyRYicgo+LywmTyl3+69SAOgqCK9 nPdv/qruHY4ZyCumXOiFFM547Bs4uNOa9+4PJZSQmaSkzx3pdfeJZy/ByJkcJO979lO/ 744nfMludRirg/6N8fzTHPKiFG/iHFIy6WnM8aH1LKUntH7IPENFZP4G8Ws909HRni4h y6Uw== 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=hbnNUSvmfhHi6lTYOiI6oAkGVTiu1RFu39sudHX/mdw=; b=yLEohAjc2wRFz8PtjQkNTTaE8Dh1KgwAuxNw4zKujmvKDPo6m3s/UF3083opv12/q8 Q+WqH6LrFlN2o/wSz4jJ1uivhsaWOIj4XJ0qjhEvKAvL/TeyDTqDG11OSyCBsV6sAfei eRA5v9CjnxhFpYV6ts/g7Ej0Ho414PsVml2D/UHEdVZnVhYMVjsPo/tEHobY3gls0t2P E1pLSjjSVzQv1i+s02RoVWwuxJHwQPknZGABAnmsqqIAvDv0t3iZkIcYXI2CffoqSLrm GkbzYrWTf3hVxbYGMCpgTDR71yzVMpG0H8rps8gUFvVOQ3OsoaH8BhnElm8fKGzUeiTA Cb7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=w+RYT0ZG; 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 on10-20020a17090b1d0a00b002194ca43255si19940194pjb.50.2022.12.06.12.09.57; Tue, 06 Dec 2022 12:10:10 -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=w+RYT0ZG; 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 S229928AbiLFUIw (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbiLFUH6 (ORCPT ); Tue, 6 Dec 2022 15:07:58 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B9C62CE0D; Tue, 6 Dec 2022 12:07:53 -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 988363B90; Tue, 6 Dec 2022 21:07:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357271; 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=hbnNUSvmfhHi6lTYOiI6oAkGVTiu1RFu39sudHX/mdw=; b=w+RYT0ZGcbDlne1msZoKbX3FOaqaYZ/ZBGfdNpwKTha60i0Z6KbOful1kuWjAdamEn6W4e Kve9uhvn33A4rmLo3sXyS/K+hJbokvDzqTXXASVCWEWgj+B01uYRn1EX5oW5CZ1G6rUPhO fa42gD0tloUjoSDNZe5iXHVaXMMbA5hiehPIW9/dc+0lLC/sLrltj57C22U7lkrxjPBvsw 521ZgR3wa0UEvwWEl+qczq2KaUTCO1z6tlcmh8ItkjbjAzi5/ip/zeYAWAm6S6T944Vkpc UhJNkzgnfaklbFr3V80vwXjigyR1y4nOY78i/4GC3qjVPtp1vpdauzCaC2arTA== 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 , Dan Carpenter Subject: [PATCH v5 12/21] nvmem: core: introduce NVMEM layouts Date: Tue, 6 Dec 2022 21:07:31 +0100 Message-Id: <20221206200740.3567551-13-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496586467055806?= X-GMAIL-MSGID: =?utf-8?q?1751496692286150511?= NVMEM layouts are used to generate NVMEM cells during runtime. Think of an EEPROM with a well-defined conent. For now, the content can be described by a device tree or a board file. But this only works if the offsets and lengths are static and don't change. One could also argue that putting the layout of the EEPROM in the device tree is the wrong place. Instead, the device tree should just have a specific compatible string. Right now there are two use cases: (1) The NVMEM cell needs special processing. E.g. if it only specifies a base MAC address offset and you need to add an offset, or it needs to parse a MAC from ASCII format or some proprietary format. (Post processing of cells is added in a later commit). (2) u-boot environment parsing. The cells don't have a particular offset but it needs parsing the content to determine the offsets and length. Co-developed-by: Miquel Raynal Signed-off-by: Miquel Raynal Signed-off-by: Michael Walle --- changes since v4: - none changes since v3: - check return code of .add_cells() changes since v2: - look for "nvmem-layout" node and its compatible - add of_nvmem_layout_get_container() - special handling in of_nvmem_cell_get() changes since v1: - add documentation in nvmem.rst - add nvmem_layout_unregister() + necessary module tracking - make it possible to supply a layout via nvmem_register() - check add_cells, before calling Documentation/driver-api/nvmem.rst | 15 ++++ drivers/nvmem/Kconfig | 4 + drivers/nvmem/Makefile | 1 + drivers/nvmem/core.c | 118 +++++++++++++++++++++++++++++ drivers/nvmem/layouts/Kconfig | 5 ++ drivers/nvmem/layouts/Makefile | 4 + include/linux/nvmem-consumer.h | 7 ++ include/linux/nvmem-provider.h | 51 +++++++++++++ 8 files changed, 205 insertions(+) create mode 100644 drivers/nvmem/layouts/Kconfig create mode 100644 drivers/nvmem/layouts/Makefile diff --git a/Documentation/driver-api/nvmem.rst b/Documentation/driver-api/nvmem.rst index e3366322d46c..de221e91c8e3 100644 --- a/Documentation/driver-api/nvmem.rst +++ b/Documentation/driver-api/nvmem.rst @@ -185,3 +185,18 @@ ex:: ===================== See Documentation/devicetree/bindings/nvmem/nvmem.txt + +8. NVMEM layouts +================ + +NVMEM layouts are yet another mechanism to create cells. With the device +tree binding it is possible to specify simple cells by using an offset +and a length. Sometimes, the cells doesn't have a static offset, but +the content is still well defined, e.g. tag-length-values. In this case, +the NVMEM device content has to be first parsed and the cells need to +be added accordingly. Layouts let you read the content of the NVMEM device +and let you add cells dynamically. + +Another use case for layouts is the post processing of cells. With layouts, +it is possible to associate a custom post processing hook to a cell. It +even possible to add this hook to cells not created by the layout itself. diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 755f551426b5..0e10b5b094b9 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -21,6 +21,10 @@ config NVMEM_SYSFS This interface is mostly used by userspace applications to read/write directly into nvmem. +# Layouts + +source "drivers/nvmem/layouts/Kconfig" + # Devices config NVMEM_APPLE_EFUSES diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index fa80fe17e567..4cf87ef6c24d 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_NVMEM) += nvmem_core.o nvmem_core-y := core.o +obj-y += layouts/ # Devices obj-$(CONFIG_NVMEM_APPLE_EFUSES) += nvmem-apple-efuses.o diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 0993e1ebdeaf..748a850a1960 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -40,6 +40,7 @@ struct nvmem_device { nvmem_reg_write_t reg_write; nvmem_cell_post_process_t cell_post_process; struct gpio_desc *wp_gpio; + struct nvmem_layout *layout; void *priv; }; @@ -74,6 +75,9 @@ static LIST_HEAD(nvmem_lookup_list); static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); +static DEFINE_SPINLOCK(nvmem_layout_lock); +static LIST_HEAD(nvmem_layouts); + static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, void *val, size_t bytes) { @@ -728,6 +732,99 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) return 0; } +int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner) +{ + layout->owner = owner; + + spin_lock(&nvmem_layout_lock); + list_add(&layout->node, &nvmem_layouts); + spin_unlock(&nvmem_layout_lock); + + return 0; +} +EXPORT_SYMBOL_GPL(__nvmem_layout_register); + +void nvmem_layout_unregister(struct nvmem_layout *layout) +{ + spin_lock(&nvmem_layout_lock); + list_del(&layout->node); + spin_unlock(&nvmem_layout_lock); +} +EXPORT_SYMBOL_GPL(nvmem_layout_unregister); + +static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) +{ + struct device_node *layout_np, *np = nvmem->dev.of_node; + struct nvmem_layout *l, *layout = NULL; + + layout_np = of_get_child_by_name(np, "nvmem-layout"); + if (!layout_np) + return NULL; + + spin_lock(&nvmem_layout_lock); + + list_for_each_entry(l, &nvmem_layouts, node) { + if (of_match_node(l->of_match_table, layout_np)) { + if (try_module_get(l->owner)) + layout = l; + + break; + } + } + + spin_unlock(&nvmem_layout_lock); + of_node_put(layout_np); + + return layout; +} + +static void nvmem_layout_put(struct nvmem_layout *layout) +{ + if (layout) + module_put(layout->owner); +} + +static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem) +{ + struct nvmem_layout *layout = nvmem->layout; + int ret; + + if (layout && layout->add_cells) { + ret = layout->add_cells(&nvmem->dev, nvmem, layout); + if (ret) + return ret; + } + + return 0; +} + +#if IS_ENABLED(CONFIG_OF) +/** + * of_nvmem_layout_get_container() - Get OF node to layout container. + * + * @nvmem: nvmem device. + * + * Return: a node pointer with refcount incremented or NULL if no + * container exists. Use of_node_put() on it when done. + */ +struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem) +{ + return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout"); +} +EXPORT_SYMBOL_GPL(of_nvmem_layout_get_container); +#endif + +const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + const struct of_device_id *match; + + match = of_match_node(layout->of_match_table, nvmem->dev.of_node); + + return match ? match->data : NULL; +} +EXPORT_SYMBOL_GPL(nvmem_layout_get_match_data); + /** * nvmem_register() - Register a nvmem device for given nvmem_config. * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem @@ -842,6 +939,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) goto err_device_del; } + /* + * If the driver supplied a layout by config->layout, the module + * pointer will be NULL and nvmem_layout_put() will be a noop. + */ + nvmem->layout = config->layout ?: nvmem_layout_get(nvmem); + if (config->cells) { rval = nvmem_add_cells(nvmem, config->cells, config->ncells); if (rval) @@ -856,6 +959,10 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (rval) goto err_remove_cells; + rval = nvmem_add_cells_from_layout(nvmem); + if (rval) + goto err_remove_cells; + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); return nvmem; @@ -864,6 +971,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem_device_remove_all_cells(nvmem); if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); + nvmem_layout_put(nvmem->layout); err_device_del: device_del(&nvmem->dev); err_put_device: @@ -885,6 +993,7 @@ static void nvmem_device_release(struct kref *kref) device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); nvmem_device_remove_all_cells(nvmem); + nvmem_layout_put(nvmem->layout); device_unregister(&nvmem->dev); } @@ -1250,6 +1359,15 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) return ERR_PTR(-EINVAL); } + /* nvmem layouts produce cells within the nvmem-layout container */ + if (of_node_name_eq(nvmem_np, "nvmem-layout")) { + nvmem_np = of_get_next_parent(nvmem_np); + if (!nvmem_np) { + of_node_put(cell_np); + return ERR_PTR(-EINVAL); + } + } + nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); of_node_put(nvmem_np); if (IS_ERR(nvmem)) { diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig new file mode 100644 index 000000000000..9ad3911d1605 --- /dev/null +++ b/drivers/nvmem/layouts/Kconfig @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +menu "Layout Types" + +endmenu diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile new file mode 100644 index 000000000000..6fdb3c60a4fa --- /dev/null +++ b/drivers/nvmem/layouts/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for nvmem layouts. +# diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 1f62f7ba71ca..fa030d93b768 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -239,6 +239,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id); struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *name); +struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem); #else static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) @@ -251,6 +252,12 @@ static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, { return ERR_PTR(-EOPNOTSUPP); } + +static inline struct device_node * +of_nvmem_layout_get_container(struct nvmem_device *nvmem) +{ + return ERR_PTR(-EOPNOTSUPP); +} #endif /* CONFIG_NVMEM && CONFIG_OF */ #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 385d29168008..4185767c114f 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -89,6 +89,7 @@ struct nvmem_cell_info { * @priv: User context passed to read/write callbacks. * @wp-gpio: Write protect pin * @ignore_wp: Write Protect pin is managed by the provider. + * @layout: Fixed layout associated with this nvmem device. * * Note: A default "nvmem" name will be assigned to the device if * no name is specified in its configuration. In such case "" is @@ -111,6 +112,7 @@ struct nvmem_config { bool read_only; bool root_only; bool ignore_wp; + struct nvmem_layout *layout; struct device_node *of_node; bool no_of_node; nvmem_reg_read_t reg_read; @@ -144,6 +146,33 @@ struct nvmem_cell_table { struct list_head node; }; +/** + * struct nvmem_layout - NVMEM layout definitions + * + * @name: Layout name. + * @of_match_table: Open firmware match table. + * @add_cells: Will be called if a nvmem device is found which + * has this layout. The function will add layout + * specific cells with nvmem_add_one_cell(). + * @owner: Pointer to struct module. + * @node: List node. + * + * A nvmem device can hold a well defined structure which can just be + * evaluated during runtime. For example a TLV list, or a list of "name=val" + * pairs. A nvmem layout can parse the nvmem device and add appropriate + * cells. + */ +struct nvmem_layout { + const char *name; + const struct of_device_id *of_match_table; + int (*add_cells)(struct device *dev, struct nvmem_device *nvmem, + struct nvmem_layout *layout); + + /* private */ + struct module *owner; + struct list_head node; +}; + #if IS_ENABLED(CONFIG_NVMEM) struct nvmem_device *nvmem_register(const struct nvmem_config *cfg); @@ -158,6 +187,14 @@ void nvmem_del_cell_table(struct nvmem_cell_table *table); int nvmem_add_one_cell(struct nvmem_device *nvmem, const struct nvmem_cell_info *info); +int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner); +#define nvmem_layout_register(layout) \ + __nvmem_layout_register(layout, THIS_MODULE) +void nvmem_layout_unregister(struct nvmem_layout *layout); + +const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, + struct nvmem_layout *layout); + #else static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c) @@ -181,5 +218,19 @@ static inline int nvmem_add_one_cell(struct nvmem_device *nvmem, return -EOPNOTSUPP; } +static inline int nvmem_layout_register(struct nvmem_layout *layout) +{ + return -EOPNOTSUPP; +} + +static inline void nvmem_layout_unregister(struct nvmem_layout *layout) {} + +static inline const void * +nvmem_layout_get_match_data(struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + return NULL; +} + #endif /* CONFIG_NVMEM */ #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */ From patchwork Tue Dec 6 20:07:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30496 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027228wrr; Tue, 6 Dec 2022 12:09:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Rfdiz9JUtlVyDVA7e+rPY2N9IFpE4obQ67NQ1G3SgVa+YRAf5Jt3FRqZCsmXbSDaMuCLD X-Received: by 2002:a17:902:ccce:b0:189:d0d5:e75b with SMTP id z14-20020a170902ccce00b00189d0d5e75bmr13320651ple.163.1670357396025; Tue, 06 Dec 2022 12:09:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357396; cv=none; d=google.com; s=arc-20160816; b=W14iX4Jg1QrWnOcbA/N5riiD+sQXUhZLBhAZ/fg1EjwsCszzjWHA/Y3hIab1ofvSdt nyBUOW6EZQHnVkk3MjYFfkF9zlVuYU4L+6mdIZMRfhUx7k2JYagzVffxM/4VmS4n9dBA 6vj74KbfbKcgjFxiqEqlnbbSsFVRxQZ8hFrpuqNMF/gRCy2QEOqWxxfEyydPju1qvC4z TR4jL1O8/IX+9HBQf8/D+lcjHcXfKAKGbbyTYIjyzLZCMugn2tcXCwlP1EwY551efu64 Qr72qOGNoTUTiXQLlHszoWjcbeT4Uqx4JDTBC85gXuOJ9FPjgSjyWczL8ZtVMtXfwqOs 1v0Q== 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=CH55z4SKaqTQIV4BtwPp6ZSR/J9q1HnwI74TrjmDJ04=; b=unb0LDzJlU7Pjtb/Kmcj4flpRkj1R/XZnHuSucg8hQYK9yd6Dru92IFZa2JMyOceqQ ml850cM1CMXT5QB1T48BSvvB2MXVIx2QDswAhss6WH/oqOu06pcucSvDSl1Fghu66gl3 kpoOI6VirQI4kEUaf9ZrzlZPL04Glh/Cd0ciKdr6J0zAME6WKmwSo2QmEWJ4Alr2wCr+ DsQu8rbB0w8jhQNuIfzfqGBKTaUAXZgUPc3kcD2dJ3940vKgx6z+YIkRs32xgg2xl7xo SRMLzSaLkZsAmwR59GN59DbIszPDdIIp/1vMozKk9kWmXQ/W4bHaeg6rNIcOSZEJPtv9 wmwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b="x3tN/vb+"; 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 q17-20020a17090311d100b0018996404dc2si12305646plh.268.2022.12.06.12.09.42; Tue, 06 Dec 2022 12:09:56 -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="x3tN/vb+"; 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 S229867AbiLFUI3 (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229723AbiLFUHz (ORCPT ); Tue, 6 Dec 2022 15:07:55 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 437D72E9DF; Tue, 6 Dec 2022 12:07:53 -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 344473B9B; Tue, 6 Dec 2022 21:07:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357272; 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=CH55z4SKaqTQIV4BtwPp6ZSR/J9q1HnwI74TrjmDJ04=; b=x3tN/vb+zqUPk++3lXTEF088HqUzI1gkAJ4rfDrSRuDJsQyoXB5Fd/omiY6PuY1quHdkIs mwiO2+hvPfxJBD9IxssEN9MDjAmGDwchltUjHb8RXfHfzE+G/2AkfiZaYlzhsfriDqyISf XCLTQujBk70PMta1OYEqQ/456/zlUNeyJPk0uK/njfVXU1IrqAVmYT4XDjWUI4jusGqQl9 kNz2ZNnjidQ6UfZ90mDuDuQj6LdXd9X1aEXGLYjtcLIgCkOkQbizTUbKSZhOgaXFVGIOHV 4dpqcKrwxrEvFzL/hm7TSRdKJ64yiXIng7BAlRKMpahN1hEazVYFybQxKhryAA== 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 , Dan Carpenter Subject: [PATCH v5 13/21] nvmem: core: add per-cell post processing Date: Tue, 6 Dec 2022 21:07:32 +0100 Message-Id: <20221206200740.3567551-14-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496677106977015?= X-GMAIL-MSGID: =?utf-8?q?1751496677106977015?= 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 v4: - none 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 748a850a1960..5afd4818cb34 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; @@ -1549,6 +1551,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); @@ -1657,6 +1666,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; }; /** From patchwork Tue Dec 6 20:07:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30498 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027304wrr; Tue, 6 Dec 2022 12:10:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf4aKmCqBwt+HW4KefIpXN7Nidx5C9hZqPdOFqOjCyIYz27rYtS+KPHyvRRYT5iYROyEnw/V X-Received: by 2002:a63:5511:0:b0:477:ce06:6c94 with SMTP id j17-20020a635511000000b00477ce066c94mr53957145pgb.138.1670357404886; Tue, 06 Dec 2022 12:10:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357404; cv=none; d=google.com; s=arc-20160816; b=vhGFWDuO5aX/T29Iy63Gh1pQGgxE8niK1YK6XWCL97Rnjberv9iss7gv5xH6nW2hPq T8gBH6n4iDgiEtDhAeixCw6ot+WKmPfjB+sO9wMx9xv8tlIeSyrfXre+9JgDjGD8ezfU Afc4ww441+PQF1XH1t98UzeW0Tq5BtTFcoYu8wVLyAR6X1/o+cuCKzlfTC49exyMc/xO +zrMQoBQdG0EpHgLTe9vaWPidi5hQpWCLUYhozJesYfMDxuA2ouIU15rt98g6q56eqiW mwj4gGgn0tAfkyY0Nze+wONdHgeZxbgT4VyTvLtkGufIiJOzrp4iaPrVFrzbGBM2haeE hblQ== 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=FIvGlxXDqA7PdqR3w+bWH+qxGv8mVWV/x4LMDhqSiY0=; b=c0gB5exttl5dcAL14M6QEo+kCOVc+7ksAQaWqKqBJKUwkTnvjo9OiITQRnQ87srcpd 21uDFriJMsiJ142gZYlX+DlriL9A8A4ufAygGaPluW93bCH7UAtU2vhef1UP67pHr88V YLLGGBWdUDiQjX++12N27G4jNHOvgQZ7CLzjM9FBvZJEPDSQBlGArmTj54X90b0HnYny MF+OzqGztj7k+mH0KhsT9HYM/vcg00SsUGTV/Igr4w2T8REVdfcifIdi7HJmjOCuVKZY xjGSoud9AdXMj8i8C3OUybwUBg5YAjm6vMzQKuFtQqaZAWEqGOIglSbAfY/tpn6I+JFQ k2qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=rBi9EfJa; 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 h13-20020a056a00170d00b0056bb0103ea4si19393604pfc.246.2022.12.06.12.09.52; Tue, 06 Dec 2022 12:10:04 -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=rBi9EfJa; 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 S229702AbiLFUIq (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbiLFUHz (ORCPT ); Tue, 6 Dec 2022 15:07:55 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69A632ED49; Tue, 6 Dec 2022 12:07:54 -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 845943BA3; Tue, 6 Dec 2022 21:07:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357272; 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=FIvGlxXDqA7PdqR3w+bWH+qxGv8mVWV/x4LMDhqSiY0=; b=rBi9EfJaMdyOqQUMqPOWwci7D4uff7jojS2lmOnAJkn8bevd5D7mCEtthb9PQuqY3ddgRl wkjzEVI507MuSILbV/+SuzFupdSPRIjSbxOMCyAt2QVGdFquzhhv/X5KnCUhsCKfZmPU+v e6JJ8+UijsfJqi9c4sLkp3qaHFrl3SQ6qhIXDK7UCtLyU8TlLMS8pOmS80vQolkxuNxbUb l7DqCbQgZZCnyOIXolqqhlROkzgQAEJeZcqLDIwMgtzH/QPMZfdrPpREXoPuy3+34y3dEW fUO7WTPA5yOAdzb+5/y6jmvim3lQc6wzOmqONK/TNjLlj3mT3cEzan1/Op6mpQ== 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 , Dan Carpenter Subject: [PATCH v5 14/21] nvmem: core: allow to modify a cell before adding it Date: Tue, 6 Dec 2022 21:07:33 +0100 Message-Id: <20221206200740.3567551-15-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496686109482729?= X-GMAIL-MSGID: =?utf-8?q?1751496686109482729?= Provide a way to modify a cell before it will get added. This is useful to attach a custom post processing hook via a layout. Signed-off-by: Michael Walle --- changes since v4: - none changes since v3: - none changes since v2: - none changes since v1: - new patch drivers/nvmem/core.c | 4 ++++ include/linux/nvmem-provider.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 5afd4818cb34..2706fc5ed494 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -694,6 +694,7 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem) static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) { + struct nvmem_layout *layout = nvmem->layout; struct device *dev = &nvmem->dev; struct device_node *child; const __be32 *addr; @@ -723,6 +724,9 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) info.np = of_node_get(child); + if (layout && layout->fixup_cell_info) + layout->fixup_cell_info(nvmem, layout, &info); + ret = nvmem_add_one_cell(nvmem, &info); kfree(info.name); if (ret) { diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 1930496d8854..bfaba5227ac9 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -157,6 +157,8 @@ struct nvmem_cell_table { * @add_cells: Will be called if a nvmem device is found which * has this layout. The function will add layout * specific cells with nvmem_add_one_cell(). + * @fixup_cell_info: Will be called before a cell is added. Can be + * used to modify the nvmem_cell_info. * @owner: Pointer to struct module. * @node: List node. * @@ -170,6 +172,9 @@ struct nvmem_layout { const struct of_device_id *of_match_table; int (*add_cells)(struct device *dev, struct nvmem_device *nvmem, struct nvmem_layout *layout); + void (*fixup_cell_info)(struct nvmem_device *nvmem, + struct nvmem_layout *layout, + struct nvmem_cell_info *cell); /* private */ struct module *owner; From patchwork Tue Dec 6 20:07:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3026950wrr; Tue, 6 Dec 2022 12:09:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf4V2ErvVgiUJajg6f458OCdDs06W29bURj9OFOxF8S/QsQd/P+f9WpkM2Ti3vvXUHMK974Q X-Received: by 2002:a17:902:e883:b0:188:f4ca:97b1 with SMTP id w3-20020a170902e88300b00188f4ca97b1mr71383984plg.139.1670357358277; Tue, 06 Dec 2022 12:09:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357358; cv=none; d=google.com; s=arc-20160816; b=nZrZ26hjwHmx5WZ4BVQDkDDhlmnaerS3xuNcJk/s1oy4R2KZt4D6DZuczRoYWnSWQe Ct4cQiS3niczPRjch9huH6Iq2MsHDwEfUqOaZ+m3YvZ0ID+KLkyczTZ2WeyuNgn/r1Eq FoFfKEHGSF/FloNBZMn5crC/a/uRq2lk2mWoikd2I5ggsWO8AMQxe8XKBXzuItwaStcp yM0y9Gn7ScIWk/U1gpU59VAclZk+YJpR8emp+Zm+XaSjVjJvRCtJNpOWcc7mEd4Ebcc5 pluvJU8eg9VNZkHWJ0IUn4JeUap0R9RqosOZvP9Git2MBVPCNJpex5FvX79e285/jFh7 r0fg== 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=Nb6EXuiFEkcaGUIQCcGhd7JA9l8VFhOUVGCBWH5KixM=; b=hr9rzWLrFiIwb0/aKTWXigRAruZZNq/Q74N8aXTCqrKBhzmWHSMzY85y9fF3bQ2sz7 82/B7WNXOJ7g0pjIyc8FBPYiInQMR3Eq7oyvJoSfm+cjgFD2j7mU6ICdJAmCaqsO+cLR AHaDXWGyMfCSi0n6dlV+NBbTioVDG5xkhL5njPJTUwvTMbb8bLNux3tGznxVl7uOKW0/ eo3fYQovVMVpqXxH8vxLN963a7ZjFW8fx71Bv2JCgSCtVYFwCTWI6OzN++jTkN/watFf vuHN28190iXjxZgY3hyJ4DgkyhH6+X/cOCLwnHmW5+xrPCkIIqxzfXIVbhfxL5N1dzgP yMLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=2Xhs86JW; 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 v185-20020a6389c2000000b00478ed620d12si588420pgd.777.2022.12.06.12.09.04; Tue, 06 Dec 2022 12:09:18 -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=2Xhs86JW; 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 S229628AbiLFUIk (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229734AbiLFUHz (ORCPT ); Tue, 6 Dec 2022 15:07:55 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95C3E2ED50; Tue, 6 Dec 2022 12:07:54 -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 DAB9B3BAB; Tue, 6 Dec 2022 21:07:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357273; 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=Nb6EXuiFEkcaGUIQCcGhd7JA9l8VFhOUVGCBWH5KixM=; b=2Xhs86JWZ3ESqICZ3UuuApWiRrKbvYXfGZxqAN3wtFYwLK8+6ObZaOQIiMX+jOwvQCO0Vj e/pTFFXkhsj31Rz9wSE4Ddy9njFKFBj7Fi25VPRNU7FKbJDpC13CF+TwyLwi+lcgXH2hd3 +VxCJq0KXQkd3WoO/SsyS/t/BGDjuuCzSGOLeiYHLZmFrngRaBj60V1bdl/A7Pye3EO8Yt BwNkPq1TDd1H+XPQHS84Rm1X/Td07wgEdGnVRBgT8bsOsKZ0oLER3LddxhpkPPE1LDk1bS +zdW0IvUs/thS+iZhUxARRGFuaJ9ZN2FL5IMEtOSPGRFpE+Qk6DzFF28bmh17Q== 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 , Dan Carpenter Subject: [PATCH v5 15/21] nvmem: imx-ocotp: replace global post processing with layouts Date: Tue, 6 Dec 2022 21:07:34 +0100 Message-Id: <20221206200740.3567551-16-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496637279084437?= X-GMAIL-MSGID: =?utf-8?q?1751496637279084437?= In preparation of retiring the global post processing hook change this driver to use layouts. The layout will be supplied during registration and will be used to add the post processing hook to all added cells. Signed-off-by: Michael Walle Tested-by: Michael Walle # on kontron-pitx-imx8m --- changes since v4: - none changes since v3: - none changes since v2: - none changes since v1: - new patch drivers/nvmem/imx-ocotp.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index e9b52ecb3f72..ac0edb6398f1 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -225,18 +225,13 @@ static int imx_ocotp_read(void *context, unsigned int offset, static int imx_ocotp_cell_pp(void *context, const char *id, int index, unsigned int offset, void *data, size_t bytes) { - struct ocotp_priv *priv = context; + u8 *buf = data; + int i; /* Deal with some post processing of nvmem cell data */ - if (id && !strcmp(id, "mac-address")) { - if (priv->params->reverse_mac_address) { - u8 *buf = data; - int i; - - for (i = 0; i < bytes/2; i++) - swap(buf[i], buf[bytes - i - 1]); - } - } + if (id && !strcmp(id, "mac-address")) + for (i = 0; i < bytes / 2; i++) + swap(buf[i], buf[bytes - i - 1]); return 0; } @@ -488,7 +483,6 @@ static struct nvmem_config imx_ocotp_nvmem_config = { .stride = 1, .reg_read = imx_ocotp_read, .reg_write = imx_ocotp_write, - .cell_post_process = imx_ocotp_cell_pp, }; static const struct ocotp_params imx6q_params = { @@ -595,6 +589,17 @@ static const struct of_device_id imx_ocotp_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids); +static void imx_ocotp_fixup_cell_info(struct nvmem_device *nvmem, + struct nvmem_layout *layout, + struct nvmem_cell_info *cell) +{ + cell->read_post_process = imx_ocotp_cell_pp; +} + +struct nvmem_layout imx_ocotp_layout = { + .fixup_cell_info = imx_ocotp_fixup_cell_info, +}; + static int imx_ocotp_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -619,6 +624,9 @@ static int imx_ocotp_probe(struct platform_device *pdev) imx_ocotp_nvmem_config.size = 4 * priv->params->nregs; imx_ocotp_nvmem_config.dev = dev; imx_ocotp_nvmem_config.priv = priv; + if (priv->params->reverse_mac_address) + imx_ocotp_nvmem_config.layout = &imx_ocotp_layout; + priv->config = &imx_ocotp_nvmem_config; clk_prepare_enable(priv->clk); From patchwork Tue Dec 6 20:07:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30499 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027313wrr; Tue, 6 Dec 2022 12:10:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf6NDkffqju9JHlg1Eetg5BgvXvV64PmdXcgRQNjvnRYqgaAaVAg1yKgAWL1phk0KKnLBe+4 X-Received: by 2002:a17:903:40c6:b0:189:ba64:3b4c with SMTP id t6-20020a17090340c600b00189ba643b4cmr22416662pld.20.1670357405717; Tue, 06 Dec 2022 12:10:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357405; cv=none; d=google.com; s=arc-20160816; b=uX+5TMtIzOO+0o6gaVoOH6hNfuSnKai0BfZIpI4EpC5MGvE3z5ghRSLChu6Xz6H0Io IRdm3MDalTJDaTLwxQqGW/ChVT4pozqi9mCKKa+HsMjpI65gGzpLxQCjpkYDZ4RTVy+f avUN/erNxHORIiIjKKGsBMkDjtHPVxXD1X4N3Cp1RBm/N73z0jwLodc0E6mSkpF5DiTH jWynocSMiI/i/hYr+rcrGwpJHI1YekzW7Y1iogiDvvf5PGlOFurChFJtVHFij4Vae2qa 1388JQFTFav2DnT8EwG+eerIj47vSJFn7jVjnKOLWvElw1KaXXJPf5GoQZiuUfwRfMYp +aLg== 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=8h4ZyOcVwYdZNg2eiJM/qO+E46ETwPkWasGJvgepyEc=; b=TNfT8LqZ/VfSh/XfJrc1F9dz+3jJNvlUpwwMoEGAUItd9PdyRX0t3/aPWqEIwoUbUG NtRpVAEm3QUx2xeTN8nJIZMX8PXzGkPC2TdP/c/o9j+FCbgutqkiOcJcJwNeLmTIuh0b EeWuADB4J0ZOfs6CC0k5EJUhF9cJiDu6g4uOuBf0BFPEcbfzTUeb3Yyv69Feyh/GDv0o J7iD8/VtMB53oPcuk7QU2S6hoh59cR9reboYgw9cJWaZ2L9GGg3g3aNMpKhth40kqCUv 3/wrqpSMaTdacVBXIkfXr1KOpBnet8Ra7Ryte4e6Lja+Z+g1D0vNFKRx7CSLMXtWV/TL NZLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=mfdeM4Su; 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 s1-20020a632c01000000b0046eecbac47esi18801999pgs.28.2022.12.06.12.09.52; Tue, 06 Dec 2022 12:10:05 -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=mfdeM4Su; 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 S229923AbiLFUIs (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229744AbiLFUHz (ORCPT ); Tue, 6 Dec 2022 15:07:55 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4B872EF36; Tue, 6 Dec 2022 12:07:54 -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 2125D3BB0; Tue, 6 Dec 2022 21:07:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357273; 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=8h4ZyOcVwYdZNg2eiJM/qO+E46ETwPkWasGJvgepyEc=; b=mfdeM4SuMUwucfWvwVn8tBMXqyAhuU0sutQ5MQdFjz84mbRUuItWVe+zSW5R+dSswmv3wW TnrtY2iyhlWzvpnv3Yn5Oq2l71WpTFFF0CqWA706Quy8sa+KZPwip//2Glg2x/qQhhkZFH WKHiw1hPjRTz52NQx2FHWU2IkMwhoHWOeVKlX8VqSN5rNdkCdyXCWjFI8w8n8AqoAGo/ZK sMaB6QBoC2ZkGbJCwzJgQS0hBIqtHsHOPSxSu7mzZrn9mpyNsQtEEwS5GyXK62IEbjOm2V EFoNkmznskQYBMSbsTeaFtM/J7KwOGhr/WZaaABZHGhPIW2z9ZjTPRkKfhjI4A== 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 , Dan Carpenter Subject: [PATCH v5 16/21] nvmem: cell: drop global cell_post_process Date: Tue, 6 Dec 2022 21:07:35 +0100 Message-Id: <20221206200740.3567551-17-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496687113105182?= X-GMAIL-MSGID: =?utf-8?q?1751496687113105182?= There are no users anymore for the global cell_post_process callback anymore. New users should use proper nvmem layouts. Signed-off-by: Michael Walle --- changes since v4: - none changes since v3: - none changes since v2: - none changes since v1: - new patch drivers/nvmem/core.c | 9 --------- include/linux/nvmem-provider.h | 2 -- 2 files changed, 11 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 2706fc5ed494..dc329daaa350 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -38,7 +38,6 @@ struct nvmem_device { unsigned int nkeepout; nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; - nvmem_cell_post_process_t cell_post_process; struct gpio_desc *wp_gpio; struct nvmem_layout *layout; void *priv; @@ -892,7 +891,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->type = config->type; nvmem->reg_read = config->reg_read; nvmem->reg_write = config->reg_write; - nvmem->cell_post_process = config->cell_post_process; nvmem->keepout = config->keepout; nvmem->nkeepout = config->nkeepout; if (config->of_node) @@ -1562,13 +1560,6 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, return rc; } - if (nvmem->cell_post_process) { - rc = nvmem->cell_post_process(nvmem->priv, id, index, - cell->offset, buf, cell->bytes); - if (rc) - return rc; - } - if (len) *len = cell->bytes; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index bfaba5227ac9..12833fe4eb4d 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -85,7 +85,6 @@ struct nvmem_cell_info { * @no_of_node: Device should not use the parent's of_node even if it's !NULL. * @reg_read: Callback to read data. * @reg_write: Callback to write data. - * @cell_post_process: Callback for vendor specific post processing of cell data * @size: Device size. * @word_size: Minimum read/write access granularity. * @stride: Minimum read/write access stride. @@ -120,7 +119,6 @@ struct nvmem_config { bool no_of_node; nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; - nvmem_cell_post_process_t cell_post_process; int size; int word_size; int stride; From patchwork Tue Dec 6 20:07:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30494 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027177wrr; Tue, 6 Dec 2022 12:09:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf51Ksr2kqkm67Efjv9FLyu1xIA+dOov6Cm6cwVshw2QDPObOPntgoksNYUvRqh6pnHZMgon X-Received: by 2002:aa7:860f:0:b0:574:a8a7:22d with SMTP id p15-20020aa7860f000000b00574a8a7022dmr56904155pfn.78.1670357388501; Tue, 06 Dec 2022 12:09:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357388; cv=none; d=google.com; s=arc-20160816; b=KhFs74Xlijksfrzotrb27bkZWrvee0dBEcOC2hnk9VnhOCwvqsBoP7yhK59gRQePON EiBgp+dij1i9GnjT1DPfD7aCll7r3gJud3VH0sBRU4yT6FA7LIqgOkrJWwTT4nm+eQRE 8jfLO4RBWId77hdm6PH5cuNycUEmHeAb6FwY6pI1YwvLomC4e06krbyHjX6mBZMKvPiL vpT3Gmc7tJ7b2SGESSdDBsfOjvmoRxzVDJDr8lehbxX7umAsT7qa36o+OUax1XWrD6nf qzuKAqOZIvM2XtCxdMI2B+ABiBihPCMqJbBFpzM8hACMJ6RrhSRj4Yh7S/IgzUsKhGOA feQQ== 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=J7SJGsn5PwH3KKasmpxguMiSfB3p2ys1JrTJjwXri5Y=; b=PB5huaM23UVnAsC7Z6iw7YxQyDcSeZ+LwO7Hjlaj+Yh3B1DPdM8pecsqJYszcU0uNd nqwMfERAOCnFQOl+TSyQ2A7DLUuH5vLvy9x6U+wu95v+IHgyZu1RN0BvUG74mE4Lplj3 0NAQtc4WgyfYjMZSYV6w6L+VTatGjERisx0kPIFdO19l1mvN7R3fZLz8xSJGNFXCGUZ0 7JCZEzSTb5+n7DZ6sj+TE4kfcjtBjlS9oaEbIx0Cuz9+PInmuMNIYAlzVZvmJJaEGpA7 wU0VMr/JwH4R4Y1UfVCVq6S2xg13PaHEq35ChBr8FEldTDMzhxPfTxztrdUU3y8xQVc5 uwRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=iIGAW8B5; 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 e20-20020a63e014000000b0046fd05d55e0si18127666pgh.567.2022.12.06.12.09.34; Tue, 06 Dec 2022 12:09: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=@walle.cc header.s=mail2022082101 header.b=iIGAW8B5; 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 S229822AbiLFUJD (ORCPT + 99 others); Tue, 6 Dec 2022 15:09:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229732AbiLFUH6 (ORCPT ); Tue, 6 Dec 2022 15:07:58 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74EF32FC35; Tue, 6 Dec 2022 12:07:56 -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 5AB6A3BC6; Tue, 6 Dec 2022 21:07:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357273; 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=J7SJGsn5PwH3KKasmpxguMiSfB3p2ys1JrTJjwXri5Y=; b=iIGAW8B5O8Xb9pGmDJvfgfkva2BrZ6Fp5OymfEALdVxrOaKft7BeV+3lTMHcsIKd3mZ+/S mXqyuCbRrosZLA6DPHunlK0GMh44qzeYTyk/xkZxCSCQTwh7hQj1mHkqxbihfONU1lE86n kk3zrdADUSxLLLESb0ngvS3U4TcANNTxreJbbxw0r2LYZumsK/6uYlOhCZ6nndaGR8Zj0N aTQqhaYG9IdTMUo5VUq7Xr4pOVlpVmxW/Yyy9BOrvzgsjHilceA2EMSeF8+qoTMOV1hc+S /BzweQ9D+CdVkhLTe+wDZY3WDmxAK6gnNbXYC4Bla+p5CenO9AjEcTPBIlTavg== 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 , Dan Carpenter Subject: [PATCH v5 17/21] nvmem: core: provide own priv pointer in post process callback Date: Tue, 6 Dec 2022 21:07:36 +0100 Message-Id: <20221206200740.3567551-18-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496669270150632?= X-GMAIL-MSGID: =?utf-8?q?1751496669270150632?= It doesn't make any more sense to have a opaque pointer set up by the nvmem device. Usually, the layout isn't associated with a particular nvmem device. Instead, let the caller who set the post process callback provide the priv pointer. Signed-off-by: Michael Walle --- changes since v4: - none changes since v3: - none changes since v2: - don't drop the pointer but let the user specify an opaque pointer changes since v1: - new patch drivers/nvmem/core.c | 4 +++- include/linux/nvmem-provider.h | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index dc329daaa350..2282dc80aa0b 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -53,6 +53,7 @@ struct nvmem_cell_entry { int bit_offset; int nbits; nvmem_cell_post_process_t read_post_process; + void *priv; 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->bytes = info->bytes; cell->name = info->name; cell->read_post_process = info->read_post_process; + cell->priv = info->priv; cell->bit_offset = info->bit_offset; cell->nbits = info->nbits; @@ -1554,7 +1556,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, nvmem_shift_read_buffer_in_place(cell, buf); if (cell->read_post_process) { - rc = cell->read_post_process(nvmem->priv, id, index, + rc = cell->read_post_process(cell->priv, id, index, cell->offset, buf, cell->bytes); if (rc) return rc; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 12833fe4eb4d..cb0814f2ddae 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -20,7 +20,8 @@ typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, void *val, size_t bytes); /* used for vendor specific post processing of cell data */ typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index, - unsigned int offset, void *buf, size_t bytes); + unsigned int offset, void *buf, + size_t bytes); enum nvmem_type { NVMEM_TYPE_UNKNOWN = 0, @@ -56,6 +57,7 @@ struct nvmem_keepout { * @np: Optional device_node pointer. * @read_post_process: Callback for optional post processing of cell data * on reads. + * @priv: Opaque data passed to the read_post_process hook. */ struct nvmem_cell_info { const char *name; @@ -65,6 +67,7 @@ struct nvmem_cell_info { unsigned int nbits; struct device_node *np; nvmem_cell_post_process_t read_post_process; + void *priv; }; /** From patchwork Tue Dec 6 20:07:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30501 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027384wrr; Tue, 6 Dec 2022 12:10:17 -0800 (PST) X-Google-Smtp-Source: AA0mqf602TSZjL8aJjS0vqJM4S8uiEIvo7ay4IZVlUdih9ssjJwi3oGMOOgCG01zWW7h8JXB7IpG X-Received: by 2002:a17:90b:3c4e:b0:219:e628:acf0 with SMTP id pm14-20020a17090b3c4e00b00219e628acf0mr8563369pjb.149.1670357416961; Tue, 06 Dec 2022 12:10:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357416; cv=none; d=google.com; s=arc-20160816; b=QvmBrBr75MnEVqLRzfBQ9nIxJMTFEzEOTSHzfLoHKKYBq6XwTC1489M++9lGXgpzpx Tj5lzOKhfhnhIlVu3lgdl2xVM2M+AVnUGSrAltoXgm38nJaX5Cn7cOqYqV9NiWmNp94j 08uZbTbMiHpBK/YYYW7+p5+ajt6VZSChZYTTFMlC2soUkLwP1HvyPiafKEetUDBbKsHP jHvGAXu1RHIyYXNgWr+hoTHaiktc2Gtlf1NYxo8LGTrH44FV83QLfodfVgiJikrcIgSI Ewwb0thq7DrKgCNzPoaNl/mVkpwq3bLL47rwab/gyBwCNHGr1DbsIXRTfrvbA2rWs5df tToA== 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=PB/NBD6nl2FVxdhufUcH2eKTgfvjlle8iT4ntIbVN0Y=; b=GetjcOaeaaNo+swfR1LbDEUh51PlySK2YR0f1qXctLtOdulI2fWpg+p12douprm1aS W5IhFer0pZxnfzOCCRe8Cfgbse+gxT7QiDhnH4fsnP+YXEzAECVeppyj0m3Y+YqBhC9Q lQtEcKJlkB0eFTQmhM3vJ6xyvndVbb4B83CDAEtomR51SXSA/a/itZaLLGE/GS13MA36 Iq7cjp60s/QpPeNLD9JIV1GHLNMx4TDOBRHR4Y6Q2+h6QhNP7p0XV1F3PRgGX+K4pEU8 NH+JZ1+kuhGUGUny5JkgtNE+5dKRZh2LBvoiI5mjcYpxoyWIlGeN4W6rAIj0zbGzH9VN Y/Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=RwBxKOei; 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 z9-20020a170902834900b00186ae54007dsi17093670pln.499.2022.12.06.12.10.02; Tue, 06 Dec 2022 12:10:16 -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=RwBxKOei; 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 S229936AbiLFUI4 (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229700AbiLFUH6 (ORCPT ); Tue, 6 Dec 2022 15:07:58 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C192FC26; Tue, 6 Dec 2022 12:07:56 -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 C8F6E3BC9; Tue, 6 Dec 2022 21:07:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357274; 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=PB/NBD6nl2FVxdhufUcH2eKTgfvjlle8iT4ntIbVN0Y=; b=RwBxKOeiHvTIYT4ZCIORPh1Gs+CYgNtYxhVfJSZTKRIVb66P6CsWw6ph1HkrFLKtqp/SYc YV9OBFVZM4Ex/t9Fv11+FBeJjGKXTAepws0aQgMYwjTKrxFV1anwV6W6KpIRMF+YPQMvTW oV7Gt03AJFMLFmuzl94GyLLhnYxm97LkPQOwE4pa0J4KgQZco1mTubCdazI6FRaZR7xHJU CqMFmVHZSqqFCrq2kMmsBgc6aysQGpxLBuIieC3ChlqYDf9N5XszW9Gsf7YWP3GJkziVfv aR9deq8Pc2fNyLjS3mLBK2PT/BrLBxAUAaAkkrEuwPhyxOa7jRSb2ZWCRq6yDg== 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 , Dan Carpenter Subject: [PATCH v5 18/21] nvmem: layouts: add sl28vpd layout Date: Tue, 6 Dec 2022 21:07:37 +0100 Message-Id: <20221206200740.3567551-19-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496698815662305?= X-GMAIL-MSGID: =?utf-8?q?1751496698815662305?= This layout applies to the VPD of the Kontron sl28 boards. The VPD only contains a base MAC address. Therefore, we have to add an individual offset to it. This is done by taking the second argument of the nvmem phandle into account. Also this let us checking the VPD version and the checksum. Signed-off-by: Michael Walle --- changes since v4: - none changes since v3: - none changes since v2: - use of_nvmem_layout_get_container() changes since v1: - none drivers/nvmem/layouts/Kconfig | 9 ++ drivers/nvmem/layouts/Makefile | 2 + drivers/nvmem/layouts/sl28vpd.c | 153 ++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 drivers/nvmem/layouts/sl28vpd.c diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index 9ad3911d1605..75082f6b471d 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -2,4 +2,13 @@ menu "Layout Types" +config NVMEM_LAYOUT_SL28_VPD + bool "Kontron sl28 VPD layout support" + select CRC8 + help + Say Y here if you want to support the VPD layout of the Kontron + SMARC-sAL28 boards. + + If unsure, say N. + endmenu diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile index 6fdb3c60a4fa..fc617b9e87d0 100644 --- a/drivers/nvmem/layouts/Makefile +++ b/drivers/nvmem/layouts/Makefile @@ -2,3 +2,5 @@ # # Makefile for nvmem layouts. # + +obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c new file mode 100644 index 000000000000..a36800f201a3 --- /dev/null +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include + +#define SL28VPD_MAGIC 'V' + +struct sl28vpd_header { + u8 magic; + u8 version; +} __packed; + +struct sl28vpd_v1 { + struct sl28vpd_header header; + char serial_number[15]; + u8 base_mac_address[ETH_ALEN]; + u8 crc8; +} __packed; + +static int sl28vpd_mac_address_pp(void *priv, const char *id, int index, + unsigned int offset, void *buf, + size_t bytes) +{ + if (bytes != ETH_ALEN) + return -EINVAL; + + if (index < 0) + return -EINVAL; + + if (!is_valid_ether_addr(buf)) + return -EINVAL; + + eth_addr_add(buf, index); + + return 0; +} + +static const struct nvmem_cell_info sl28vpd_v1_entries[] = { + { + .name = "serial-number", + .offset = offsetof(struct sl28vpd_v1, serial_number), + .bytes = sizeof_field(struct sl28vpd_v1, serial_number), + }, + { + .name = "base-mac-address", + .offset = offsetof(struct sl28vpd_v1, base_mac_address), + .bytes = sizeof_field(struct sl28vpd_v1, base_mac_address), + .read_post_process = sl28vpd_mac_address_pp, + }, +}; + +static int sl28vpd_v1_check_crc(struct device *dev, struct nvmem_device *nvmem) +{ + struct sl28vpd_v1 data_v1; + u8 table[CRC8_TABLE_SIZE]; + int ret; + u8 crc; + + crc8_populate_msb(table, 0x07); + + ret = nvmem_device_read(nvmem, 0, sizeof(data_v1), &data_v1); + if (ret < 0) + return ret; + else if (ret != sizeof(data_v1)) + return -EIO; + + crc = crc8(table, (void *)&data_v1, sizeof(data_v1) - 1, 0); + + if (crc != data_v1.crc8) { + dev_err(dev, + "Checksum is invalid (got %02x, expected %02x).\n", + crc, data_v1.crc8); + return -EINVAL; + } + + return 0; +} + +static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + const struct nvmem_cell_info *pinfo; + struct nvmem_cell_info info = {0}; + struct device_node *layout_np; + struct sl28vpd_header hdr; + int ret, i; + + /* check header */ + ret = nvmem_device_read(nvmem, 0, sizeof(hdr), &hdr); + if (ret < 0) + return ret; + else if (ret != sizeof(hdr)) + return -EIO; + + if (hdr.magic != SL28VPD_MAGIC) { + dev_err(dev, "Invalid magic value (%02x)\n", hdr.magic); + return -EINVAL; + } + + if (hdr.version != 1) { + dev_err(dev, "Version %d is unsupported.\n", hdr.version); + return -EINVAL; + } + + ret = sl28vpd_v1_check_crc(dev, nvmem); + if (ret) + return ret; + + layout_np = of_nvmem_layout_get_container(nvmem); + if (!layout_np) + return -ENOENT; + + for (i = 0; i < ARRAY_SIZE(sl28vpd_v1_entries); i++) { + pinfo = &sl28vpd_v1_entries[i]; + + info.name = pinfo->name; + info.offset = pinfo->offset; + info.bytes = pinfo->bytes; + info.read_post_process = pinfo->read_post_process; + info.np = of_get_child_by_name(layout_np, pinfo->name); + + ret = nvmem_add_one_cell(nvmem, &info); + if (ret) { + of_node_put(layout_np); + return ret; + } + } + + of_node_put(layout_np); + + return 0; +} + +static const struct of_device_id sl28vpd_of_match_table[] = { + { .compatible = "kontron,sl28-vpd" }, + {}, +}; + +struct nvmem_layout sl28vpd_layout = { + .name = "sl28-vpd", + .of_match_table = sl28vpd_of_match_table, + .add_cells = sl28vpd_add_cells, +}; + +static int __init sl28vpd_init(void) +{ + return nvmem_layout_register(&sl28vpd_layout); +} +subsys_initcall(sl28vpd_init); From patchwork Tue Dec 6 20:07:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30502 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027460wrr; Tue, 6 Dec 2022 12:10:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Hgm/BwpqVnJM0o5fSpOTz2W9ofp2r+Mtyeun2UGiL/4xZHGYEUCB12gsJMZzLVo1gsOcN X-Received: by 2002:a17:90a:7b82:b0:219:bd66:1c07 with SMTP id z2-20020a17090a7b8200b00219bd661c07mr15616891pjc.156.1670357428500; Tue, 06 Dec 2022 12:10:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357428; cv=none; d=google.com; s=arc-20160816; b=0rwdyTaGeLKjmKFhsCtjiqfaE5FMSsArE2exdh3MTjTBdcYJZmbXJTZFO3aIcMWpF0 HKwY4geAlT6HwAUNaa3/wiAyDNLjWQ1oivm7euYtRYPXIGgmfNQHNz/aZeTEdJ1AqbT/ OydOzraW+uZaySjBWBXZnas2Arzqq/8/jxck9v4MhQODGPUTV1KimJ91EJoL5xAVZ+MK TYhMBVTcyj6/xaUvRNA28FWuhUPs29L5Rwim80MoXFo+3gJv7MXpOFtsI84/3VVSn8DD ncG66cwf6iLuAatqWfiL625zSbMj+k273Mvso/gJC6lsw2N36fHpJl7sdzK0iOEPCkvs Akfg== 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=OSr1EP0rN/jCyH2mo6XotklYCk18q8zt9OH+MC01vJQ=; b=Vr2A9UDyURRKUbMvsPKcsNjs59kJqqclATagbtCQ5zLs5iOIfPol+BiNQFvgbqg91m ep7kSM90HGRySDjYktjXO9d0rajGxeyZZaltYzvqYZZnjoI6oQj9o41lEhRDtGAMCPZ9 8wplo960QGq6AMefEJUV1KFH1uvCheEjCiJKEtT/tURCl3onXk2cXNYzFDdAHx3U2o9h n3pbQ1tV8P0tIEJ8Vl3HjoUxGVMNCx1x6J1Q3HKnoE0yxDa+8hJVPRHdO0DwOEv5o4ex /78ZK4NTE2aLdGPmvw3RC7X5O6vN0fNaMvi+Lyfv2rq8N51zROSjQHwAyu/U7bLDuHzF 3t4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=latWyCPc; 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 q4-20020a632a04000000b0047704a39c8fsi19150733pgq.636.2022.12.06.12.10.15; Tue, 06 Dec 2022 12:10:28 -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=latWyCPc; 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 S229950AbiLFUJK (ORCPT + 99 others); Tue, 6 Dec 2022 15:09:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbiLFUH7 (ORCPT ); Tue, 6 Dec 2022 15:07:59 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99C4BCE05; Tue, 6 Dec 2022 12:07:56 -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 6619D3BCC; Tue, 6 Dec 2022 21:07:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357274; 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=OSr1EP0rN/jCyH2mo6XotklYCk18q8zt9OH+MC01vJQ=; b=latWyCPcX4HErn8RDM5qU7sKtAcHd001IWsFnRR/zL0YUma1aM9YmVbHwF6I1Zxu44vBOA XQ4lm8JrTj9Ekk3+W5kZHe8HH1+0LRyRbomeOA0w1RZV+ufKh7k2LbYi+tBRDfjq0Erc+f gp+rxtbO65eFwSXjae4uEtdfaAoui+NbnYJTgrCpOnaUDyEw5ona/DcCSxEAuxVjnMficI ghnCN61irRa8ijBS1OvwhjUJv0Q3WLASR8Hmv+Glk9Efeaiur26mckCQvLGsTrapw76Jjh 72k+i4h0N6RbT71PP8GvviQ7/9xP5Uov8UzDnou38SQepWxA3PoEnKnGN81W/A== 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 , Dan Carpenter Subject: [PATCH v5 19/21] MAINTAINERS: add myself as sl28vpd nvmem layout driver Date: Tue, 6 Dec 2022 21:07:38 +0100 Message-Id: <20221206200740.3567551-20-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496711054094982?= X-GMAIL-MSGID: =?utf-8?q?1751496711054094982?= Add myself as a maintainer for the new sl28vpd nvmem layout driver. Signed-off-by: Michael Walle --- changes since v4: - none changes since v3: - none changes since v2: - new patch MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index acb1a249e212..92e90fd7a19c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19134,6 +19134,12 @@ F: drivers/irqchip/irq-sl28cpld.c F: drivers/pwm/pwm-sl28cpld.c F: drivers/watchdog/sl28cpld_wdt.c +SL28 VPD NVMEM LAYOUT DRIVER +M: Michael Walle +S: Maintained +F: Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml +F: drivers/nvmem/layouts/sl28vpd.c + SLAB ALLOCATOR M: Christoph Lameter M: Pekka Enberg From patchwork Tue Dec 6 20:07:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027992wrr; Tue, 6 Dec 2022 12:11:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf6vgfUiz4Rzq8/66ct4ASavkhgeYlE0L0AKkxXNymtq2V43FTaQs5zewHyP/9pfK7FvlxYO X-Received: by 2002:a17:903:1c4:b0:189:e149:a1af with SMTP id e4-20020a17090301c400b00189e149a1afmr8223438plh.18.1670357511864; Tue, 06 Dec 2022 12:11:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357511; cv=none; d=google.com; s=arc-20160816; b=WAWir6IAoo6tojs3cJQwX+BpTEnQ5r4nxliR0I0OWb6taIbm+Kk0k46zMbl7IImQx9 NkT4yYlYg5q79aXpFR3vQN31rps9Atrwgmv/OoC2l9YdShGmrCITpuTMvfwAghxaLKCP Ntea2ZbovczRlk/W+hU0VqMW8GOKRKscjC8ZiyMO2z0eLNcAZCA7pIoyxhLyE2yaqvaF WnATQuAoftg0QIgnzEN0uO3xQTJLlKqFvhneW3Cr/pVeqoi3vzNdKFJARCnhAsEq2onp hZhZfh3KYM9aZFKBc6T1ny0n+q43zAg3OgwxfyuOpOTl7b5HVRC4Kgq4cL8jcx6XuRgJ utQg== 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=WExFGJcqmgTXaKZQqcybDlur7a8O8FUqyOI1ePLZ42s=; b=K3nIpH9ZoU6Md/NGgD2uI1pOe5lHwXJpgH5uE3pOdSCPp121oiNjWDA7wzlqE1rwYn mGFHmTbfBM0s3dQyzxZUlJnSp/spBY/TCv6kigpPrzmkWpCq+W7R6DO3MOoK16kWIqob kxPdvPd2GemIbwzTwCK+xFqscxBed8akKyEiVnzKi9AEPI+FGqOVQ/u47kdjDW88KiAe wYmy6gba7SJdNf97yD02qhMOo0iHWD6qJ69y3OwVAqo3qFtfCelRf8+TZxY+gZrTLUbF 8QYIQ0ocb3CRTz3VYomRAgZ9Qg7RYgPtpEyYsxot++h4WGzaGJwjVSFFiCnmGAQeEWJS wlDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=g962j5kN; 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 c70-20020a621c49000000b005768619bd8esi10942708pfc.177.2022.12.06.12.11.38; Tue, 06 Dec 2022 12:11:51 -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=g962j5kN; 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 S229966AbiLFUJP (ORCPT + 99 others); Tue, 6 Dec 2022 15:09:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbiLFUH7 (ORCPT ); Tue, 6 Dec 2022 15:07:59 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDC932FFC2; Tue, 6 Dec 2022 12:07:56 -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 F34243BD5; Tue, 6 Dec 2022 21:07:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357275; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WExFGJcqmgTXaKZQqcybDlur7a8O8FUqyOI1ePLZ42s=; b=g962j5kNwDUcBv6nuH/d7+257E/HPiojCgHFt4f0eyT9Jw6jjXuWfqJYQfKvw+odJhELVq mOQggCSs8eEnpRL5nLrimM2BQUBS+EaOtsaGqieQj5MJxmYBhfmNB7KjTRLz6pnL2titD9 hLs+z3aZumhrunR1ESRBeyGy+MtECjxERubktG4hBJY0IGC8gyvUovbodMKZz4CeMKXSHf RC1pJ+kIl3TAFtEsIMJgOcc8ZhfeXMyixhKUFT8jAEMzTH0xISnSuWPSLGl8dwAno80YSE 5yBDZFss1cCeYFIwsQya0/73xbH4yH3C6QVev8LkaEzb1NGZX/Fzt0AwS4lGLQ== 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 , Dan Carpenter Subject: [PATCH v5 20/21] nvmem: layouts: Add ONIE tlv layout driver Date: Tue, 6 Dec 2022 21:07:39 +0100 Message-Id: <20221206200740.3567551-21-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-1-michael@walle.cc> 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,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?1751496798644331697?= X-GMAIL-MSGID: =?utf-8?q?1751496798644331697?= From: Miquel Raynal This layout applies on top of any non volatile storage device containing an ONIE table factory flashed. This table follows the tlv (type-length-value) organization described in the link below. We cannot afford using regular parsers because the content of these tables is manufacturer specific and must be dynamically discovered. Link: https://opencomputeproject.github.io/onie/design-spec/hw_requirements.html Signed-off-by: Miquel Raynal --- changes since v4: - none changes since v3: - don't use kfree() - fix typo, s/no/on/ changes since v2: - new patch drivers/nvmem/layouts/Kconfig | 9 ++ drivers/nvmem/layouts/Makefile | 1 + drivers/nvmem/layouts/onie-tlv.c | 244 +++++++++++++++++++++++++++++++ 3 files changed, 254 insertions(+) create mode 100644 drivers/nvmem/layouts/onie-tlv.c diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index 75082f6b471d..9ad50474cb77 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -11,4 +11,13 @@ config NVMEM_LAYOUT_SL28_VPD If unsure, say N. +config NVMEM_LAYOUT_ONIE_TLV + bool "ONIE tlv support" + select CRC32 + help + Say Y here if you want to support the Open Compute Project ONIE + Type-Length-Value standard table. + + If unsure, say N. + endmenu diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile index fc617b9e87d0..2974bd7d33ed 100644 --- a/drivers/nvmem/layouts/Makefile +++ b/drivers/nvmem/layouts/Makefile @@ -4,3 +4,4 @@ # obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o +obj-$(CONFIG_NVMEM_LAYOUT_ONIE_TLV) += onie-tlv.o diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c new file mode 100644 index 000000000000..074c7c700845 --- /dev/null +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -0,0 +1,244 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ONIE tlv NVMEM cells provider + * + * Copyright (C) 2022 Open Compute Group ONIE + * Author: Miquel Raynal + * Based on the nvmem driver written by: Vadym Kochan + * Inspired by the first layout written by: Rafał Miłecki + */ + +#include +#include +#include +#include +#include + +#define ONIE_TLV_MAX_LEN 2048 +#define ONIE_TLV_CRC_FIELD_SZ 6 +#define ONIE_TLV_CRC_SZ 4 +#define ONIE_TLV_HDR_ID "TlvInfo" + +struct onie_tlv_hdr { + u8 id[8]; + u8 version; + __be16 data_len; +} __packed; + +struct onie_tlv { + u8 type; + u8 len; +} __packed; + +static const char *onie_tlv_cell_name(u8 type) +{ + switch (type) { + case 0x21: + return "product-name"; + case 0x22: + return "part-number"; + case 0x23: + return "serial-number"; + case 0x24: + return "mac-address"; + case 0x25: + return "manufacture-date"; + case 0x26: + return "device-version"; + case 0x27: + return "label-revision"; + case 0x28: + return "platforn-name"; + case 0x29: + return "onie-version"; + case 0x2A: + return "num-macs"; + case 0x2B: + return "manufacturer"; + case 0x2C: + return "country-code"; + case 0x2D: + return "vendor"; + case 0x2E: + return "diag-version"; + case 0x2F: + return "service-tag"; + case 0xFD: + return "vendor-extension"; + case 0xFE: + return "crc32"; + default: + break; + } + + return NULL; +} + +static int onie_tlv_mac_read_cb(void *priv, const char *id, int index, + unsigned int offset, void *buf, + size_t bytes) +{ + eth_addr_add(buf, index); + + return 0; +} + +static nvmem_cell_post_process_t onie_tlv_read_cb(u8 type, u8 *buf) +{ + switch (type) { + case 0x24: + return &onie_tlv_mac_read_cb; + default: + break; + } + + return NULL; +} + +static int onie_tlv_add_cells(struct device *dev, struct nvmem_device *nvmem, + size_t data_len, u8 *data) +{ + struct nvmem_cell_info cell = {}; + struct device_node *layout; + struct onie_tlv tlv; + unsigned int hdr_len = sizeof(struct onie_tlv_hdr); + unsigned int offset = 0; + int ret; + + layout = of_nvmem_layout_get_container(nvmem); + if (!layout) + return -ENOENT; + + while (offset < data_len) { + memcpy(&tlv, data + offset, sizeof(tlv)); + if (offset + tlv.len >= data_len) { + dev_err(dev, "Out of bounds field (0x%x bytes at 0x%x)\n", + tlv.len, hdr_len + offset); + break; + } + + cell.name = onie_tlv_cell_name(tlv.type); + if (!cell.name) + continue; + + cell.offset = hdr_len + offset + sizeof(tlv.type) + sizeof(tlv.len); + cell.bytes = tlv.len; + cell.np = of_get_child_by_name(layout, cell.name); + cell.read_post_process = onie_tlv_read_cb(tlv.type, data + offset + sizeof(tlv)); + + ret = nvmem_add_one_cell(nvmem, &cell); + if (ret) { + of_node_put(layout); + return ret; + } + + offset += sizeof(tlv) + tlv.len; + } + + of_node_put(layout); + + return 0; +} + +static bool onie_tlv_hdr_is_valid(struct device *dev, struct onie_tlv_hdr *hdr) +{ + if (memcmp(hdr->id, ONIE_TLV_HDR_ID, sizeof(hdr->id))) { + dev_err(dev, "Invalid header\n"); + return false; + } + + if (hdr->version != 0x1) { + dev_err(dev, "Invalid version number\n"); + return false; + } + + return true; +} + +static bool onie_tlv_crc_is_valid(struct device *dev, size_t table_len, u8 *table) +{ + struct onie_tlv crc_hdr; + u32 read_crc, calc_crc; + __be32 crc_be; + + memcpy(&crc_hdr, table + table_len - ONIE_TLV_CRC_FIELD_SZ, sizeof(crc_hdr)); + if (crc_hdr.type != 0xfe || crc_hdr.len != ONIE_TLV_CRC_SZ) { + dev_err(dev, "Invalid CRC field\n"); + return false; + } + + /* The table contains a JAMCRC, which is XOR'ed compared to the original + * CRC32 implementation as known in the Ethernet world. + */ + memcpy(&crc_be, table + table_len - ONIE_TLV_CRC_SZ, ONIE_TLV_CRC_SZ); + read_crc = be32_to_cpu(crc_be); + calc_crc = crc32(~0, table, table_len - ONIE_TLV_CRC_SZ) ^ 0xFFFFFFFF; + if (read_crc != calc_crc) { + dev_err(dev, "Invalid CRC read: 0x%08x, expected: 0x%08x\n", + read_crc, calc_crc); + return false; + } + + return true; +} + +static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + struct onie_tlv_hdr hdr; + size_t table_len, data_len, hdr_len; + u8 *table, *data; + int ret; + + ret = nvmem_device_read(nvmem, 0, sizeof(hdr), &hdr); + if (ret < 0) + return ret; + + if (!onie_tlv_hdr_is_valid(dev, &hdr)) { + dev_err(dev, "Invalid ONIE TLV header\n"); + return -EINVAL; + } + + hdr_len = sizeof(hdr.id) + sizeof(hdr.version) + sizeof(hdr.data_len); + data_len = be16_to_cpu(hdr.data_len); + table_len = hdr_len + data_len; + if (table_len > ONIE_TLV_MAX_LEN) { + dev_err(dev, "Invalid ONIE TLV data length\n"); + return -EINVAL; + } + + table = devm_kmalloc(dev, table_len, GFP_KERNEL); + if (!table) + return -ENOMEM; + + ret = nvmem_device_read(nvmem, 0, table_len, table); + if (ret != table_len) + return ret; + + if (!onie_tlv_crc_is_valid(dev, table_len, table)) + return -EINVAL; + + data = table + hdr_len; + ret = onie_tlv_add_cells(dev, nvmem, data_len, data); + if (ret) + return ret; + + return 0; +} + +static const struct of_device_id onie_tlv_of_match_table[] = { + { .compatible = "onie,tlv-layout", }, + {}, +}; + +static struct nvmem_layout onie_tlv_layout = { + .name = "ONIE tlv layout", + .of_match_table = onie_tlv_of_match_table, + .add_cells = onie_tlv_parse_table, +}; + +static int __init onie_tlv_init(void) +{ + return nvmem_layout_register(&onie_tlv_layout); +} +subsys_initcall(onie_tlv_init); From patchwork Tue Dec 6 20:07:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30503 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027609wrr; Tue, 6 Dec 2022 12:10:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf5lfx5cZTcs/VG2MS43gJwSHJvgr838kE2MO9AN72VeyxsRkP7ZZwX0eYCuEkAfwZDD1YSV X-Received: by 2002:a63:f056:0:b0:477:a33f:4858 with SMTP id s22-20020a63f056000000b00477a33f4858mr62774284pgj.76.1670357446925; Tue, 06 Dec 2022 12:10:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357446; cv=none; d=google.com; s=arc-20160816; b=PM/j2PAlIb1o9+llBiyZMlkKe+CzEVDOdA7VTR1qqZjO0gVOYQR+xGKurQi4YOV+eW 23oW2rA/JcZtpgrpGKhDFfzNBo9LKIrzcpMW13xVSDm3YiAyT/XspusMMRT7gU5rTVzD PWRc+bgGUwg5h446XAXx0k7IdQopCtDYr8JUL7GEMw97IGl6Fk7bH19WYkKtNioejk4y Gzd6MLAQ7Pqd4kmD625IQZEJSSJnqYlUZM9CpG0rLCOzyRCXxTYO/KcTtzFO8mUFRUae VK1/Lc/OvkwGHFcPlU/o+7roi1I5mbIRvO3GCuyM6XP4LStle0xFJc1CUxHdursdSWjh zr8Q== 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=nAM+HKLY4gwei738koUpxz8j63ybVeXrZ8wbJ288zE4=; b=CEuIQdYNLHcODRmnLSzcevsLnNnQe+RtzSXJf11kXAW6YHcUb68+2MzQKGmSo5asTY zl3Nq+y9B6NazB8JKbuUqpKO4PeSUN8hbJv8QX9McDPKIWLR3ZBH4NaEPMwcLfrX7Y5w q9T67dhE1hlF0896flKHmOJ1+xDhX0bsGcQ0jzmmMCyxt1nZzOz+3gsRu2eA8MpXC8HB CZBvtdJkgNXh9XGLa7CN3nRFMz2pUzI1Cwcm98WnHdlUXksg6JqKH2GmKwCirQmBp+6c XkxpOju3Z4huW2S2rGGe3eOHQ339NzZou0D7lTOQCxL0eDSSQfdXsSMzld1VAr6X1GLl fKmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=AUgFUvzR; 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 bu5-20020a056a00410500b00563ab8e5e83si18230326pfb.370.2022.12.06.12.10.34; Tue, 06 Dec 2022 12:10:46 -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=AUgFUvzR; 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 S229975AbiLFUJS (ORCPT + 99 others); Tue, 6 Dec 2022 15:09:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229768AbiLFUH7 (ORCPT ); Tue, 6 Dec 2022 15:07:59 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B20A02FFD2; Tue, 6 Dec 2022 12:07:57 -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 92BF13BD7; Tue, 6 Dec 2022 21:07:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357275; 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=nAM+HKLY4gwei738koUpxz8j63ybVeXrZ8wbJ288zE4=; b=AUgFUvzRmM1rgG3BIAQ4rpM66D1miFQGVwHZLxV/q8a9tB4ELv1z2vsQTiEh8WmgcvkHYH Y09RaAencibKdSQ/GxvipGorKtG0I8IToLFxwshOAK6r9Pj9TtrCOvD8261mR0M1C3Zjp0 eVJu8nk+OUYBV6zgAs2mvIRzxOJIvdu6xNJwFjjvu7M9YHzb1nYThY1Jr5+l7Gm850Cbkf VTZeFGZd/cFHBh69tdJEHWqIKy3y/0Lm39NgX+FzUCULHDY1bKDFKkshIDyui7/g7CJjJD by1EYO+liyvohzyLeTSlew4KK69w9JpH65cAdiRID3itZAdAxPRRvTt4/9goXg== 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 , Dan Carpenter Subject: [PATCH v5 21/21] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer Date: Tue, 6 Dec 2022 21:07:40 +0100 Message-Id: <20221206200740.3567551-22-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496730420415176?= X-GMAIL-MSGID: =?utf-8?q?1751496730420415176?= From: Miquel Raynal Following the introduction of the bindings for this NVMEM parser and the layout driver, add myself as maintainer. Signed-off-by: Miquel Raynal --- changes since v4: - none changes since v3: - none changes since v2: - new patch MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 92e90fd7a19c..73a5b8d7c2f7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15529,6 +15529,12 @@ L: linux-hwmon@vger.kernel.org S: Maintained F: drivers/hwmon/oxp-sensors.c +ONIE TLV NVMEM LAYOUT DRIVER +M: Miquel Raynal +S: Maintained +F: Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml +F: drivers/nvmem/layouts/onie-tlv.c + ONION OMEGA2+ BOARD M: Harvey Hunt L: linux-mips@vger.kernel.org