From patchwork Tue Dec 28 14:25:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12700390 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E89E6C433F5 for ; Tue, 28 Dec 2021 14:28:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JN8ktM2yNc6xrMNaA01ju/m/1Rb4fLnqg9jOrVVnj0E=; b=YXQXl/D1BYvL7d Q46CUuEg8t0w0R0NBMb3SBWKm2m0t/QK4mH6gkDjYvZ4Sx3eY9poj2+NDkE2Pn0BnWgU8Kb64fvhD ebCH45+wVkJr1zxVTpAi6AMgEMtYdYNPU3n1E5ImnF/qBAGoldSGQ7rhqMjbdDUrzNuLF4DXJcxsz sAg+SAtEaJTzihi9a+57JB3zaTuluu6LybGGiuNCGHq7LI+b2CO1ugDQl4SqMehItypL8Ql4gHJy4 N4XN+5VJ98npP9aNXVXMnlpv4ClyNWauUoqM9MSU+FEtBexlEKRcGo6ZATjQ9Z37OJ8WXwKOPCVkd hy1wArw0In0JesowrIYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DQv-001773-Qg; Tue, 28 Dec 2021 14:26:33 +0000 Received: from ssl.serverraum.org ([176.9.125.105]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DQh-0016yM-IK; Tue, 28 Dec 2021 14:26:21 +0000 Received: from mwalle01.kontron.local. (unknown [IPv6:2a02:810b:4340:43bf:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 6FE7A223EA; Tue, 28 Dec 2021 15:26:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1640701574; 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=9V3jjNX+h+SC4H3w7ArRhed6jMoCjU/AbUnBIS3w/EM=; b=LLhbIGksetqq4w9fP6GpIS0VEN7pDz+IZgJ9KsI4qai8ysx1kwMrd4/YF7cwhZYcSSBcrK ZAonKjulneohhOMhH2XUbPNhfnAKdBQ54/RjwWXzwP55OmrwgzpIhYMc//gUFNTSRkaVdC +5oBNdiL6m7B4iMg0FCyoQJm9XV2qIs= From: Michael Walle To: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Srinivas Kandagatla , Shawn Guo , Li Yang , Frank Rowand , "David S . Miller" , Jakub Kicinski , Ansuel Smith , Andrew Lunn , Michael Walle Subject: [PATCH 1/8] of: base: add of_parse_phandle_with_optional_args() Date: Tue, 28 Dec 2021 15:25:42 +0100 Message-Id: <20211228142549.1275412-2-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211228142549.1275412-1-michael@walle.cc> References: <20211228142549.1275412-1-michael@walle.cc> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211228_062619_805155_E655BA25 X-CRM114-Status: GOOD ( 16.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- drivers/of/base.c | 23 +++++++++++++++++++++++ include/linux/of.h | 12 ++++++++++++ 2 files changed, 35 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 5b907600f5b0..fb28bb26276e 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1543,6 +1543,29 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na } EXPORT_SYMBOL(of_parse_phandle_with_args); +/** + * of_parse_phandle_with_optional_args() - Find a node pointed by phandle in a list + * + * Same as of_parse_phandle_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. + */ +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) +{ + if (index < 0) + return -EINVAL; + + return __of_parse_phandle_with_args(np, list_name, cells_name, + 0, index, out_args); +} +EXPORT_SYMBOL(of_parse_phandle_with_optional_args); + /** * of_parse_phandle_with_args_map() - Find a node pointed by phandle in a list and remap it * @np: pointer to a device tree node containing a list diff --git a/include/linux/of.h b/include/linux/of.h index ff143a027abc..ccace453d25f 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -376,6 +376,9 @@ extern int of_parse_phandle_with_args_map(const struct device_node *np, extern int of_parse_phandle_with_fixed_args(const struct device_node *np, const char *list_name, int cells_count, int index, struct of_phandle_args *out_args); +extern 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); extern int of_count_phandle_with_args(const struct device_node *np, const char *list_name, const char *cells_name); @@ -897,6 +900,15 @@ static inline int of_parse_phandle_with_fixed_args(const struct device_node *np, return -ENOSYS; } +static inline int of_parse_phandle_with_optional_args(const struct device_node *np, + char *list_name, + int cells_count, + int index, + struct of_phandle_args *out_args) +{ + return -ENOSYS; +} + static inline int of_count_phandle_with_args(const struct device_node *np, const char *list_name, const char *cells_name) From patchwork Tue Dec 28 14:25:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12700403 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9464C433F5 for ; Tue, 28 Dec 2021 14:37:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9YGFtmwe69khjTvO2PlrQyR8xxBwWrF+kh50enmOsxc=; b=4qj5fJyYqC7A0b 16tgeD3CfOcnOQam+NlQ/TQhxT9jKTeoE7cFZRGzk3PxmKUGZEg0ypcjTN+1NRk6lU0MeOyCEZQuB xhBUINYbFMawTGuiPIQk2vzla4ziWvMAqrmzqvV9R41YdE1DsS6R/yH7NV9GEPUY2Y9j4lS81b9AZ mPvmnm2XHjzP/+Q7TwXWxDrmLvNOaR+HF916fQl0FVG6IHbVLoFjX8AH9VaLf/I6pt3zjp6ZrHhSa CPY1aQ/CgHlbMGkuSshsQvrU192GNuiaQDDy6mCqvSyt37mtMR1AYk7BdcjlKIrOKdzJFQIsjfdtB HVDZKbk8EBDsQoaim7AQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DZZ-001A6G-UQ; Tue, 28 Dec 2021 14:35:30 +0000 Received: from ssl.serverraum.org ([176.9.125.105]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DQh-0016yQ-JH; Tue, 28 Dec 2021 14:26:23 +0000 Received: from mwalle01.kontron.local. (unknown [IPv6:2a02:810b:4340:43bf:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 29F19223ED; Tue, 28 Dec 2021 15:26:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1640701575; 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=02iOmurDIl5gzz8NoU1dQeDN4gDFtGDQPI42B09jExw=; b=S8Qa3rFSfHGbDtfs00//SU0AqVJwqu3c15mjlL9u1qDcnIj8885OuUt4vYGhjJ3kBH48Jz S1XnkMikSYyQW3mkQkx/hIsvmSmvMqQ0WwanA/M1k9eLQaDtdX+xrGa+OKGSTSBo41IZnl E95WFs7BTat/Gez3vTF1RRgml0Ip73g= From: Michael Walle To: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Srinivas Kandagatla , Shawn Guo , Li Yang , Frank Rowand , "David S . Miller" , Jakub Kicinski , Ansuel Smith , Andrew Lunn , Michael Walle Subject: [PATCH 2/8] dt-bindings: nvmem: add transformation bindings Date: Tue, 28 Dec 2021 15:25:43 +0100 Message-Id: <20211228142549.1275412-3-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211228142549.1275412-1-michael@walle.cc> References: <20211228142549.1275412-1-michael@walle.cc> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211228_062619_828996_F4FD92A0 X-CRM114-Status: GOOD ( 13.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Just add a simple list of the supported devices which need a nvmem transformations. Also, since the compatible string is prepended to the actual nvmem compatible string, we need to match using "contains" instead of an exact match. Signed-off-by: Michael Walle --- .../devicetree/bindings/mtd/mtd.yaml | 7 +-- .../bindings/nvmem/nvmem-transformations.yaml | 46 +++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 Documentation/devicetree/bindings/nvmem/nvmem-transformations.yaml diff --git a/Documentation/devicetree/bindings/mtd/mtd.yaml b/Documentation/devicetree/bindings/mtd/mtd.yaml index 376b679cfc70..0291e439b6a6 100644 --- a/Documentation/devicetree/bindings/mtd/mtd.yaml +++ b/Documentation/devicetree/bindings/mtd/mtd.yaml @@ -33,9 +33,10 @@ patternProperties: properties: compatible: - enum: - - user-otp - - factory-otp + contains: + enum: + - user-otp + - factory-otp required: - compatible diff --git a/Documentation/devicetree/bindings/nvmem/nvmem-transformations.yaml b/Documentation/devicetree/bindings/nvmem/nvmem-transformations.yaml new file mode 100644 index 000000000000..8c8d85fd6d27 --- /dev/null +++ b/Documentation/devicetree/bindings/nvmem/nvmem-transformations.yaml @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/nvmem/nvmem-transformations.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: NVMEM transformations Device Tree Bindings + +maintainers: + - Srinivas Kandagatla + +description: | + This is a list NVMEM devices which need transformations. + +properties: + compatible: + oneOf: + - items: + - enum: + - kontron,sl28-vpd + - const: user-otp + - const: user-otp + +required: + - compatible + +additionalProperties: true + +examples: + - | + otp-1 { + compatible = "kontron,sl28-vpd", "user-otp"; + #address-cells = <1>; + #size-cells = <1>; + + serial@2 { + reg = <2 15>; + }; + + base_mac_address: base-mac-address@17 { + #nvmem-cell-cells = <1>; + reg = <17 6>; + }; + }; + +... From patchwork Tue Dec 28 14:25:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12700392 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1C30C433F5 for ; Tue, 28 Dec 2021 14:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dKgCqzhxe/P8AWc5u1vXqqfK080m2EtN96xlRszQOY8=; b=xfColEc5eHWaxV 4AzZuBEDrofUDN68Hx0vybCG4QIgBJkWdahBzQd6hf+QsgsxLX8EdvxCH9z9mSXHX/bDR0nngEjS/ cdu2H4cCbVlDPIBBBfCsEa0EDrZMNTReszlBZTqUQypJ4EYaNw3HyFQwWw6OAwMR6AtxbHo/zQoBt Ld5Ie0s+eLDH8+u/iOVYNd3/T4hMnQ3Nbn0ir8JhaxPOimhfU4V5ub4uXO9JLasUQML2gcGCJO2tn xHOfMOBJ01vhEsOPI9naDSQfivOezkelmrXjBaWIexZSlFYVzbpLMQ5sqR1RwIRv4biE0rFvja2w+ w/Z+nxxRhcNN+BeXx7Bw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DRn-0017JF-NK; Tue, 28 Dec 2021 14:27:27 +0000 Received: from ssl.serverraum.org ([176.9.125.105]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DQi-0016yS-0w; Tue, 28 Dec 2021 14:26:23 +0000 Received: from mwalle01.kontron.local. (unknown [IPv6:2a02:810b:4340:43bf:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id CF426223EF; Tue, 28 Dec 2021 15:26:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1640701576; 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=96bwBhhJsvemv3hprG899e7VbbSGnJ9a5fsV1NHuLZ8=; b=cjPDNl9CsWho/cNnNcIx7E66u4GGGpiOA8DmWZga6NSVOIrebZv636wTVtLBKrxnMDx8+Z dIvQ/2a10IhDjdDBUL1YjtYI4pN+ObSGuhfKMD2UaCSx5mxZqYmNKnDx3luDNlgm2eH60G wfOlxMPDRjealS2isRjs5RmlA+Z7tqo= From: Michael Walle To: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Srinivas Kandagatla , Shawn Guo , Li Yang , Frank Rowand , "David S . Miller" , Jakub Kicinski , Ansuel Smith , Andrew Lunn , Michael Walle Subject: [PATCH 3/8] nvmem: core: add an index parameter to the cell Date: Tue, 28 Dec 2021 15:25:44 +0100 Message-Id: <20211228142549.1275412-4-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211228142549.1275412-1-michael@walle.cc> References: <20211228142549.1275412-1-michael@walle.cc> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211228_062620_419313_DD02A2E7 X-CRM114-Status: GOOD ( 20.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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 23a38dcf0fc4..31d77c51dbe3 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); @@ -1148,7 +1149,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; @@ -1167,6 +1169,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; } @@ -1205,7 +1208,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); } @@ -1253,15 +1256,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_next_parent(cell_np); if (!nvmem_np) @@ -1278,7 +1293,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); @@ -1431,8 +1446,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; @@ -1446,7 +1461,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; @@ -1481,7 +1496,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); @@ -1794,7 +1809,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 98efb7b5660d..8cf8593c8ae7 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 28 14:25:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12700391 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB713C433EF for ; Tue, 28 Dec 2021 14:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YNQNR31y6GPMIzbjqk5H3cSSeQrUP2NRnAlkjm5yG8w=; b=zMplEkPKL9GFXk X6cOQuxyrEBAMW8Rx99+HUjYnZiBg2YJ0D3w/dQ+GTKa1R4WbiRBtm34H6+KWE83ZiqedpLJ6WEiW tiSNq0WLuCF02mU3HQq2GfdKrZR5fxyW+jjQCL7/pWhbd1hzA4VY4z6YGha4UlAZIwKH8W2cltdPp xEDaU2cLi9BeTjJW3m5hx1jw6n2D0z23O7CzKRMVJc0SGJOirj88XPD8l5c2mYsAsmir37is/Y3l5 VxagaWa9kSKlcguQShqRmBajzCH3ZVG1WXFiR7dvS5YV6NOfcAKh9uMg4pYuVaSFE/4ahTOWhAykJ IpVOy1S0rpEQdPEhCQtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DRX-0017Dz-Bk; Tue, 28 Dec 2021 14:27:11 +0000 Received: from ssl.serverraum.org ([176.9.125.105]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DQi-0016yT-Jj; Tue, 28 Dec 2021 14:26:23 +0000 Received: from mwalle01.kontron.local. (unknown [IPv6:2a02:810b:4340:43bf:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 9F525223F0; Tue, 28 Dec 2021 15:26:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1640701577; 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=gO75fbORJwY+TXVhnGrE0yVM6et/4Z8anMHQZ7vRi/A=; b=C2lVNyfqfOq6QNs7YFqSZ+JcQGmswKroPgG6BxNEKUOpMGS0MqodsetivvQyt/ybDoA7rc BUibxaGeLAqcx5TpI5EqsGgcx41tG3PtYWEB6ZAcwW0kV2xNoeOCbkueefWO4RDc5C0Z01 WPzv9X7DeGAAukmDfDvemCDA8uzdHoE= From: Michael Walle To: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Srinivas Kandagatla , Shawn Guo , Li Yang , Frank Rowand , "David S . Miller" , Jakub Kicinski , Ansuel Smith , Andrew Lunn , Michael Walle Subject: [PATCH 4/8] nvmem: core: add transformations support Date: Tue, 28 Dec 2021 15:25:45 +0100 Message-Id: <20211228142549.1275412-5-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211228142549.1275412-1-michael@walle.cc> References: <20211228142549.1275412-1-michael@walle.cc> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211228_062621_001794_300060C2 X-CRM114-Status: GOOD ( 19.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Sometimes the value of an nvmem cell must be transformed. For example, a MAC address might be stored in ASCII representation or we might need to swap bytes. We might also want to expand one value to mutliple ones, for example, the nvmem cell might just store a base MAC address to which we need to add an offset to get an address for different network interfaces. Add initial support to add such transformations based on the device tree compatible string of the NVMEM device. It will reuse the nvmem post process hook. Both are mutually exclusive. Signed-off-by: Michael Walle --- drivers/nvmem/Kconfig | 7 +++++++ drivers/nvmem/Makefile | 1 + drivers/nvmem/core.c | 7 +++++++ drivers/nvmem/transformations.c | 28 ++++++++++++++++++++++++++++ include/linux/nvmem-provider.h | 9 +++++++++ 5 files changed, 52 insertions(+) create mode 100644 drivers/nvmem/transformations.c diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index da414617a54d..94dd60b2654e 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -21,6 +21,13 @@ config NVMEM_SYSFS This interface is mostly used by userspace applications to read/write directly into nvmem. +config NVMEM_TRANSFORMATIONS + bool "Support cell transformations" + help + Say Y to support to expand one NVMEM cell into multiple values. For + example, when the NVMEM cell stores a base MAC address and it should + be expanded to be used for multiple network adapters. + config NVMEM_IMX_IIM tristate "i.MX IC Identification Module support" depends on ARCH_MXC || COMPILE_TEST diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index dcbbde35b6a8..4e6d877fdfaf 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_NVMEM) += nvmem_core.o nvmem_core-y := core.o +nvmem_core-$(CONFIG_NVMEM_TRANSFORMATIONS) += transformations.o # Devices obj-$(CONFIG_NVMEM_BCM_OCOTP) += nvmem-bcm-ocotp.o diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 31d77c51dbe3..30e4b58a6dca 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -838,6 +838,13 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) } } + /* + * Transformations are using the same post process hook, therefore they + * are mutually exclusive. + */ + if (!nvmem->cell_post_process) + nvmem->cell_post_process = nvmem_get_transformations(nvmem->dev.of_node); + dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name); rval = device_register(&nvmem->dev); diff --git a/drivers/nvmem/transformations.c b/drivers/nvmem/transformations.c new file mode 100644 index 000000000000..61642a9feefb --- /dev/null +++ b/drivers/nvmem/transformations.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * nvmem cell transformations + */ + +#include +#include +#include + +struct nvmem_transformations { + const char *compatible; + nvmem_cell_post_process_t pp; +}; + +static const struct nvmem_transformations nvmem_transformations[] = { + {} +}; + +nvmem_cell_post_process_t nvmem_get_transformations(struct device_node *np) +{ + const struct nvmem_transformations *transform = nvmem_transformations; + + for (; transform->compatible; transform++) + if (of_device_is_compatible(np, transform->compatible)) + return transform->pp; + + return NULL; +} diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 8cf8593c8ae7..efc6ffdcb7e0 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -138,6 +138,15 @@ int devm_nvmem_unregister(struct device *dev, struct nvmem_device *nvmem); void nvmem_add_cell_table(struct nvmem_cell_table *table); void nvmem_del_cell_table(struct nvmem_cell_table *table); +#if IS_ENABLED(CONFIG_NVMEM_TRANSFORMATIONS) +nvmem_cell_post_process_t nvmem_get_transformations(struct device_node *np); +#else +static inline nvmem_cell_post_process_t nvmem_get_transformations(struct device_node *np) +{ + return NULL; +} +#endif + #else static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c) From patchwork Tue Dec 28 14:25:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12700404 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 517A8C433EF for ; Tue, 28 Dec 2021 14:38:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sEXaNeYCt14yKF8GemSonm2mDYxQ0rXnfJFkOB0YjVQ=; b=bVRDuNtgqqFZZ1 na2mOkU3HjbeG6KKwbp3Z/QylfjP/1PcxRi0WJD5L/mrh22mRqNqAxRyZiH3NLHayaj4p4NDiD4mH bxlEniZEqzpgiKriOv29Lah0JiOFHv+foN5QUgOvo/bJVTRqiR3x19YganYvd1SKYcsxLBpoMrRZL lOFXGbx1dSpCtWs4mSQCMJQSV6lyAKXIzvM6vQ2bm5Nkxr4lLsX5HnwSD8c03s9IG8RBxpDmBTHQd gkLN6FFDHwXrM30RFi6RcmfzykrF28tRoo2W9PyDr7qWbpXLYSXX4XpGnzSvm5CauibGa4O/5iTGv kCQQXd0AXYmWWqJCONOg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2Daj-001ASz-Om; Tue, 28 Dec 2021 14:36:42 +0000 Received: from ssl.serverraum.org ([2a01:4f8:151:8464::1:2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DQn-00170K-G7; Tue, 28 Dec 2021 14:26:28 +0000 Received: from mwalle01.kontron.local. (unknown [IPv6:2a02:810b:4340:43bf:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 4FBF3223F6; Tue, 28 Dec 2021 15:26:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1640701577; 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=DvU9qr8AVDqwLiuTpAxXwhFvaaqgNiy89x8GquK/9Ww=; b=FrhGUJb9CsrE8BDVdbOUK1k1a21Gt2cjj+pkWleFEwpBSX5l+i5yX+WjELwD2uOPEMlL+z hWFPxMUeDxcnTe5ax+kaqTtpKZaMip88/BZdlMwmIqRk8Zz6VUXBAX/vbWQs6v7EAgcn4s i5vOOtgxg9roeJO3TufPptsun+fo3YI= From: Michael Walle To: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Srinivas Kandagatla , Shawn Guo , Li Yang , Frank Rowand , "David S . Miller" , Jakub Kicinski , Ansuel Smith , Andrew Lunn , Michael Walle Subject: [PATCH 5/8] net: add helper eth_addr_add() Date: Tue, 28 Dec 2021 15:25:46 +0100 Message-Id: <20211228142549.1275412-6-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211228142549.1275412-1-michael@walle.cc> References: <20211228142549.1275412-1-michael@walle.cc> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211228_062625_755508_BFE9C23A X-CRM114-Status: GOOD ( 10.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- include/linux/etherdevice.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h index 2ad71cc90b37..9d621dc85290 100644 --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -486,6 +486,20 @@ static inline void eth_addr_inc(u8 *addr) u64_to_ether_addr(u, addr); } +/** + * eth_addr_add() - Add (or subtract) and 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 28 14:25:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12700395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6171EC433EF for ; Tue, 28 Dec 2021 14:32:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gS4ipZGZstF9GgDyTZTc5K1R/FO/aP/EHhnGmjNDJVk=; b=I4/mb5mICUJCR3 HdFYasX99tE0Wt5bc5QHUq8urW5WWfQVoVh+d5T7cgkYOIe1MPb2Yv/QpdFADFnuw9mt+25TIgJzY KT5bUIw/RD6hJyIqe6o2r1jPfMc64QoBn+Bh0zFFqc5U27yUM72H5nPZO4I+AT/Sh3iun+G0o0CIC ONtoMfN7niwtbJ5gswRAvTj3YhKyqnU6JeTjePAtGWewVR+vnlAHaP+jRi8VNfS+wGgiyDdyFDt6A Fs9EIDIn5FVPdoELMVbq+/2vRS/yQQGPhPZct9ispClcF5I88UHhQOZS4qsxSi9bUugy+P+CLYHk7 O21SzDfjZ/Z5+IZa/KBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DVb-0018sR-H4; Tue, 28 Dec 2021 14:31:24 +0000 Received: from ssl.serverraum.org ([2a01:4f8:151:8464::1:2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DQn-00170I-G6; Tue, 28 Dec 2021 14:26:27 +0000 Received: from mwalle01.kontron.local. (unknown [IPv6:2a02:810b:4340:43bf:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id E1843223F7; Tue, 28 Dec 2021 15:26:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1640701578; 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=8u32QLgP+bx/Avj9/UQOtx/OkwJzp0bCtXU3LJH76Fc=; b=rzSLw3hes1+GfIvB++uAojB1vhiOCMw7vvcHgxa+s1zaJWBQvAiY+q7T+ZMDnLMLWnGGom 6CB6wl8wSGdh6iKpLdafzYSskmGWj0amUyv1546atnOWJRoeOOkoUdgMt/YpMikd8u4S5L /7EWzYL0lSOPqOcNW4K5NZ0x6sYrdGc= From: Michael Walle To: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Srinivas Kandagatla , Shawn Guo , Li Yang , Frank Rowand , "David S . Miller" , Jakub Kicinski , Ansuel Smith , Andrew Lunn , Michael Walle Subject: [PATCH 6/8] nvmem: transformations: ethernet address offset support Date: Tue, 28 Dec 2021 15:25:47 +0100 Message-Id: <20211228142549.1275412-7-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211228142549.1275412-1-michael@walle.cc> References: <20211228142549.1275412-1-michael@walle.cc> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211228_062625_739302_BC8BA3CD X-CRM114-Status: GOOD ( 15.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org An nvmem cell might just contain a base MAC address. To generate a address of a specific interface, add a transformation to add an offset to this base address. Add a generic implementation and the first user of it, namely the sl28 vpd storage. Signed-off-by: Michael Walle --- drivers/nvmem/transformations.c | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/nvmem/transformations.c b/drivers/nvmem/transformations.c index 61642a9feefb..15cd26da1f83 100644 --- a/drivers/nvmem/transformations.c +++ b/drivers/nvmem/transformations.c @@ -12,7 +12,52 @@ struct nvmem_transformations { nvmem_cell_post_process_t pp; }; +/** + * nvmem_transform_mac_address_offset() - Add an offset to a mac address cell + * + * A simple transformation which treats the index argument as an offset and add + * it to a mac address. This is useful, if the nvmem cell stores a base + * ethernet address. + * + * @index: nvmem cell index + * @data: nvmem data + * @bytes: length of the data + * + * Return: 0 or negative error code on failure. + */ +static int nvmem_transform_mac_address_offset(int index, unsigned int offset, + void *data, size_t bytes) +{ + if (bytes != ETH_ALEN) + return -EINVAL; + + if (index < 0) + return -EINVAL; + + if (!is_valid_ether_addr(data)) + return -EINVAL; + + eth_addr_add(data, index); + + return 0; +} + +static int nvmem_kontron_sl28_vpd_pp(void *priv, const char *id, int index, + unsigned int offset, void *data, + size_t bytes) +{ + if (!id) + return 0; + + if (!strcmp(id, "mac-address")) + return nvmem_transform_mac_address_offset(index, offset, data, + bytes); + + return 0; +} + static const struct nvmem_transformations nvmem_transformations[] = { + { .compatible = "kontron,sl28-vpd", .pp = nvmem_kontron_sl28_vpd_pp }, {} }; From patchwork Tue Dec 28 14:25:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12700393 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6AAD8C433F5 for ; Tue, 28 Dec 2021 14:30:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sVblIWsGCfDQYfopKZUT9mz+S1iI2DvRP0s7x8DYFfE=; b=APiu9Dy61b113g bw6IyV0sn8eMZm+dEu36Mpf5MsWjTGcZ2IT6TS0Q4JZ1abSl6KvaiBE4Rw1V0iNOg6kapCfvhZLsI lRvcUTa5TfzokWZVzLbcLy4pUxui8d6u00TNv21AEyb9FwimZnq39rgDFB9B2tOjxGWBERfZg8FPU mL29Bl6uQdgy4O5QpyvpQcGlxrh4dQVkZK6QtYtF/qckxS8ctvLF7SaN3wodPjB4ewJPZlqkf4Xel P31TkL+AInxkY6OsJhpHAE1kfkVLWLgrSlHeSQYmtSXsSSN1yQ4cPX3fDrSTHkG1NfYvaUmLUdrvZ I78ejxChnCa0nC3hol3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DTU-00186v-Dc; Tue, 28 Dec 2021 14:29:13 +0000 Received: from ssl.serverraum.org ([176.9.125.105]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DQl-00170H-2q; Tue, 28 Dec 2021 14:26:25 +0000 Received: from mwalle01.kontron.local. (unknown [IPv6:2a02:810b:4340:43bf:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id DF2472241C; Tue, 28 Dec 2021 15:26:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1640701579; 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=OrseTTWvtyVFTxdghVtaPYrtFfiTNlPYeSkoXqXNEbs=; b=v3r4VrsvSgI43d+5gtBBGUJ2w97Ail9pvJhQUqDDsJtnimXD3TjZLbsLiEQz9zoXX5K9JG dDSUjHPcLxkhM3FW8e6kkASPi+XJDQ9xybP3mOfLRVPRgfsz0eHpTaCgaakD+XdEvkfM10 8/7qTFv/0fAPHL1LsYi+112of85UHMg= From: Michael Walle To: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Srinivas Kandagatla , Shawn Guo , Li Yang , Frank Rowand , "David S . Miller" , Jakub Kicinski , Ansuel Smith , Andrew Lunn , Michael Walle Subject: [PATCH 7/8] arm64: dts: ls1028a: sl28: get MAC addresses from VPD Date: Tue, 28 Dec 2021 15:25:48 +0100 Message-Id: <20211228142549.1275412-8-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211228142549.1275412-1-michael@walle.cc> References: <20211228142549.1275412-1-michael@walle.cc> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211228_062623_490004_968DDA51 X-CRM114-Status: GOOD ( 11.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Now that it is finally possible to get the MAC addresses from the OTP memory, use it to set the addresses of the network devices. There are 8 reserved MAC addresses in total per board. Distribute them as follows: +----------+------+------+------+------+------+ | | var1 | var2 | var3 | var4 | kbox | +----------+------+------+------+------+------+ | enetc #0 | +0 | | | +0 | +0 | | enetc #1 | | | +0 | +1 | +1 | | enetc #2 | rand | rand | rand | rand | rand | | enetc #3 | | | | | | | felix p0 | | +0 | | | +4 | | felix p1 | | +1 | | | +5 | | felix p2 | | | | | +6 | | felix p3 | | | | | +7 | | felix p4 | | | | | | | felix p5 | | | | | | +----------+------+------+------+------+------+ An empty cell means, the port is not available and thus doesn't need an ethernet address. Signed-off-by: Michael Walle --- .../fsl-ls1028a-kontron-kbox-a-230-ls.dts | 8 ++++++++ .../freescale/fsl-ls1028a-kontron-sl28-var1.dts | 2 ++ .../freescale/fsl-ls1028a-kontron-sl28-var2.dts | 4 ++++ .../freescale/fsl-ls1028a-kontron-sl28-var4.dts | 2 ++ .../dts/freescale/fsl-ls1028a-kontron-sl28.dts | 17 +++++++++++++++++ 5 files changed, 33 insertions(+) diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-kbox-a-230-ls.dts b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-kbox-a-230-ls.dts index 0bcf97772995..6f08d3442309 100644 --- a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-kbox-a-230-ls.dts +++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-kbox-a-230-ls.dts @@ -76,6 +76,8 @@ &mscc_felix_port0 { managed = "in-band-status"; phy-handle = <&qsgmii_phy0>; phy-mode = "qsgmii"; + nvmem-cells = <&base_mac_address 4>; + nvmem-cell-names = "mac-address"; status = "okay"; }; @@ -84,6 +86,8 @@ &mscc_felix_port1 { managed = "in-band-status"; phy-handle = <&qsgmii_phy1>; phy-mode = "qsgmii"; + nvmem-cells = <&base_mac_address 5>; + nvmem-cell-names = "mac-address"; status = "okay"; }; @@ -92,6 +96,8 @@ &mscc_felix_port2 { managed = "in-band-status"; phy-handle = <&qsgmii_phy2>; phy-mode = "qsgmii"; + nvmem-cells = <&base_mac_address 6>; + nvmem-cell-names = "mac-address"; status = "okay"; }; @@ -100,6 +106,8 @@ &mscc_felix_port3 { managed = "in-band-status"; phy-handle = <&qsgmii_phy3>; phy-mode = "qsgmii"; + nvmem-cells = <&base_mac_address 7>; + nvmem-cell-names = "mac-address"; status = "okay"; }; diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var1.dts b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var1.dts index 7cd29ab970d9..1f34c7553459 100644 --- a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var1.dts +++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var1.dts @@ -55,5 +55,7 @@ &enetc_port0 { &enetc_port1 { phy-handle = <&phy0>; phy-mode = "rgmii-id"; + nvmem-cells = <&base_mac_address 0>; + nvmem-cell-names = "mac-address"; status = "okay"; }; diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var2.dts b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var2.dts index 330e34f933a3..0ed0d2545922 100644 --- a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var2.dts +++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var2.dts @@ -48,6 +48,8 @@ &mscc_felix_port0 { managed = "in-band-status"; phy-handle = <&phy0>; phy-mode = "sgmii"; + nvmem-cells = <&base_mac_address 0>; + nvmem-cell-names = "mac-address"; status = "okay"; }; @@ -56,6 +58,8 @@ &mscc_felix_port1 { managed = "in-band-status"; phy-handle = <&phy1>; phy-mode = "sgmii"; + nvmem-cells = <&base_mac_address 1>; + nvmem-cell-names = "mac-address"; status = "okay"; }; diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var4.dts b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var4.dts index 9b5e92fb753e..a4421db3784e 100644 --- a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var4.dts +++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var4.dts @@ -43,5 +43,7 @@ vddh: vddh-regulator { &enetc_port1 { phy-handle = <&phy1>; phy-mode = "rgmii-id"; + nvmem-cells = <&base_mac_address 1>; + nvmem-cell-names = "mac-address"; status = "okay"; }; diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts index 63e005dd5aae..81b5f735d22e 100644 --- a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts +++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts @@ -108,6 +108,8 @@ &enetc_port0 { phy-handle = <&phy0>; phy-mode = "sgmii"; managed = "in-band-status"; + nvmem-cells = <&base_mac_address 0>; + nvmem-cell-names = "mac-address"; status = "okay"; }; @@ -170,6 +172,21 @@ partition@3e0000 { label = "bootloader environment"; }; }; + + otp-1 { + compatible = "kontron,sl28-vpd", "user-otp"; + #address-cells = <1>; + #size-cells = <1>; + + serial@2 { + reg = <2 15>; + }; + + base_mac_address: base-mac-address@17 { + #nvmem-cell-cells = <1>; + reg = <17 6>; + }; + }; }; }; From patchwork Tue Dec 28 14:25:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12700394 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E9F77C433EF for ; Tue, 28 Dec 2021 14:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=u8kKeQ1+W+MXIb+8xcV8S/iRceFfRzJW76zUlIbUKic=; b=CmTjc/E/kx+mCC +ST5Hz7ngKcgSUDza6MtUCZeMQXr2OPTq90lO2l7cOOCBM9nUTlhJNE9ShbTiH3pVyZ+O4DBAtVdW UZSWznIlPnYMXmgRkxm3zTJSccfqZnLasiDTTtMVsmkWbVBaN8EY+ESyf3EHcd5XNm5Mkf3ztES4u VEK7I8mzPca2v3Sa2jKOazMOuN8+qRYoDiiIO3bfRxBljdoBL8UWlpJZiLYHeM3QO0UWe4z1Eu/ob fLDq0WHMCvCWdcyKHEdzmVwO3QUXSsegSNFWgofHzM85iPK8x+7bIcBc9pjiLE2MVWO1RdwYMJ/Nx E+n9GrkOFlqhCiYQrP+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DUw-0018ff-L4; Tue, 28 Dec 2021 14:30:43 +0000 Received: from ssl.serverraum.org ([2a01:4f8:151:8464::1:2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2DQn-00170J-GL; Tue, 28 Dec 2021 14:26:26 +0000 Received: from mwalle01.kontron.local. (unknown [IPv6:2a02:810b:4340:43bf:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 98B4222438; Tue, 28 Dec 2021 15:26:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1640701581; 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=z7Jp/9TSBr/YXtTUKHXXv5W5V0V0BzH9Fdgy4wsGzuM=; b=i27Za8Xxp66QNN2GAetc5+ufS54wRS8I3TG4LOZ7r/64y4vaq4SuALrGDc7+bWJ8W6dGPa i6A/Vk+pnzFBMXYfh4c5bF4tGI4oE1zimVTC50EJDE0smC+5+DK/fmeYOJ+Nshn1NVBf9o o4lFfflbRswrsrd9bTZbhl1ZC7KTep0= From: Michael Walle To: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Srinivas Kandagatla , Shawn Guo , Li Yang , Frank Rowand , "David S . Miller" , Jakub Kicinski , Ansuel Smith , Andrew Lunn , Michael Walle Subject: [PATCH 8/8] arm64: defconfig: enable NVMEM transformations Date: Tue, 28 Dec 2021 15:25:49 +0100 Message-Id: <20211228142549.1275412-9-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211228142549.1275412-1-michael@walle.cc> References: <20211228142549.1275412-1-michael@walle.cc> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211228_062625_749692_E92AE180 X-CRM114-Status: UNSURE ( 8.96 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The Kontron sl28 needs the transformation to get the correct ethernet addresses for its onboard NICs. Signed-off-by: Michael Walle --- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig index ee4bd7710a0d..117423e81d15 100644 --- a/arch/arm64/configs/defconfig +++ b/arch/arm64/configs/defconfig @@ -1178,6 +1178,7 @@ CONFIG_FSL_IMX8_DDR_PMU=m CONFIG_HISI_PMU=y CONFIG_QCOM_L2_PMU=y CONFIG_QCOM_L3_PMU=y +CONFIG_NVMEM_TRANSFORMATIONS=y CONFIG_NVMEM_IMX_OCOTP=y CONFIG_NVMEM_IMX_OCOTP_SCU=y CONFIG_QCOM_QFPROM=y