From nobody Wed Jun 24 00:52:21 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0EFEC433F5 for ; Thu, 24 Feb 2022 15:21:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236211AbiBXPWZ (ORCPT ); Thu, 24 Feb 2022 10:22:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236193AbiBXPV7 (ORCPT ); Thu, 24 Feb 2022 10:21:59 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B191B45C9; Thu, 24 Feb 2022 07:21:07 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id bq11so3366512edb.2; Thu, 24 Feb 2022 07:21:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=BenUmI5YlFoZ8y7dkLtbgkF8fzK7mypO7kCBy+ysHLY=; b=a4YpovKaGp3D4sf23/UFKiiJ0qYs/2HZoPFoKGprlMkFvbllwVwZU/Ls6kf6bvHJdK Yz+wVEUHyJvuCn1JAFuUKQSnXFyjQ6IR3ljO4Dmol9Ki7q6NzdZtxUk6OrZL8saE2y8M D50KG1xdcOQ6fwiTDdR5jOP6R3q3N94J0kY1UemWiEUdpK9LMT5CcYxCBt22BkNDO4Bh 3kEE0oFRZRG/fUDztlObehEiM1NcqxLyDz3WdnRv38QWpDMFllY+0/8oldBYwv8BQOc9 AFuXxYSGH/EOb0ubVnYsTPL5KXzOJBjRqGVPDR+08Efl+p6H5gofpRyqOT2nt5rt7dt1 ZRnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BenUmI5YlFoZ8y7dkLtbgkF8fzK7mypO7kCBy+ysHLY=; b=S/49HK6+krpVA30xuD+iHoo+xC6mQC2aLRRPnjT4nheqmW/MQZEvyL6eDxm61la7JV hGQC5B+gh2YaJFn0UFEvFw5RGt8OizK7uCq5RUc9DyL5cfrRy+dmNmAzhjTt4USuPXj9 hpWE7dBSsydKWgS/aiPCpqhMAC9oTcbSPjgP5qXFXrOcGME+qi+Ak7bnuaScxfgMnUsb 7gXI1TT/q0nz4lEglkvWHsucN8c2Ias+5JIX9prFEdZm8Xn6YU7SmXXk+ohW2b/AkJny Luo1y/jtpfRn1TEXSMlSX8/T+D6+sihDEAOOsjBwOajGIvrxES8DeZbuKD1SPngc+rbS lW0Q== X-Gm-Message-State: AOAM533pOupbpc7I4F2SkORd679MkTHBM04+/4WE3k8mJ60v5iLhQpfE g/5NZ71phzCdQaY0Nq96mpQTcqC4RJ4= X-Google-Smtp-Source: ABdhPJz29+csu8N1YY87hVMgulkAFd7SkgNkyf8NP0JgSciPnhGW9ualgEk/g+UskvOTqJ3GHVbVUQ== X-Received: by 2002:a05:6402:5ce:b0:412:be81:a9d6 with SMTP id n14-20020a05640205ce00b00412be81a9d6mr2861662edx.272.1645716065288; Thu, 24 Feb 2022 07:21:05 -0800 (PST) Received: from Ansuel-xps.localdomain ([5.170.108.128]) by smtp.googlemail.com with ESMTPSA id x12sm1501980edv.57.2022.02.24.07.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 07:21:04 -0800 (PST) From: Ansuel Smith To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Ansuel Smith , Manivannan Sadhasivam , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC RFT PATCH v3 1/2] dt-bindings: mtd: partitions: Document new partition-dynamic nodes Date: Thu, 24 Feb 2022 16:20:42 +0100 Message-Id: <20220224152043.27777-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220224152043.27777-1-ansuelsmth@gmail.com> References: <20220224152043.27777-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Document new partition-dynamic nodes used to provide an OF node for partition registred at runtime by parsers. This is required for nvmem system to declare and detect nvmem-cells. With these special partitions, the reg / offset is not required. The node name must be in the form of "partition name"-dynamic. If the partition can't be displayed using the node name, it's possible to use the label binding that will be used instead of the node name. The node name or the label binding is used to match the partition allocated by the parser at runtime and the parser will provide reg and offset of the mtd. NVMEM will use the data from the parser and provide the NVMEM cells declared in the DTS, "connecting" the dynamic partition with a static declaration of cells in them. Signed-off-by: Ansuel Smith --- .../mtd/partitions/partition-dynamic.yaml | 56 +++++++++++++++++++ .../mtd/partitions/qcom,smem-part.yaml | 4 ++ 2 files changed, 60 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/partitions/partit= ion-dynamic.yaml diff --git a/Documentation/devicetree/bindings/mtd/partitions/partition-dyn= amic.yaml b/Documentation/devicetree/bindings/mtd/partitions/partition-dyna= mic.yaml new file mode 100644 index 000000000000..e0efa58e4fac --- /dev/null +++ b/Documentation/devicetree/bindings/mtd/partitions/partition-dynamic.ya= ml @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mtd/partitions/partition-dynamic.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Dynamic Partition + +description: | + This binding describes a single flash partition that is dynamically allo= cated + by a dedicated parser that is not a fixed-partition parser. + + A dynamic partition require the node ending with the "-dynamic" tag and = if the + dynamic partition name can't be displayed using the node name, the label + properties can be used. The node name or the label have to match the dyn= amic + partition allocated by the parser. + + These special partition definition can be used to give a dynamic partiti= on + an OF node to declare NVMEM cells. An example is declaring the partition + label and all the NVMEM cells in it. The parser will detect the correct = reg + and offset and the NVMEM will register the cells in it based on the data + extracted by the parser. + +maintainers: + - Ansuel Smith + +properties: + label: + description: The label / name for the partition assigned by the parser= at + runtime. This is needed for sybsystem like NVMEM to define cells and + register with this OF node. + +additionalProperties: true + +examples: + - | + flash { + partitions { + compatible =3D "qcom,smem-part"; + + art-dynamic { + compatible =3D "nvmem-cells"; + #address-cells =3D <1>; + #size-cells =3D <1>; + label =3D "0:art"; + + macaddr_art_0: macaddr@0 { + reg =3D <0x0 0x6>; + }; + + macaddr_art_6: macaddr@6 { + reg =3D <0x6 0x6>; + }; + }; + }; + }; diff --git a/Documentation/devicetree/bindings/mtd/partitions/qcom,smem-par= t.yaml b/Documentation/devicetree/bindings/mtd/partitions/qcom,smem-part.ya= ml index cf3f8c1e035d..1d7d9b3378c3 100644 --- a/Documentation/devicetree/bindings/mtd/partitions/qcom,smem-part.yaml +++ b/Documentation/devicetree/bindings/mtd/partitions/qcom,smem-part.yaml @@ -19,6 +19,10 @@ properties: compatible: const: qcom,smem-part =20 +patternProperties: + "-dynamic$": + $ref: "partition-dynamic.yaml#" + required: - compatible =20 --=20 2.34.1 From nobody Wed Jun 24 00:52:21 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAC79C433EF for ; Thu, 24 Feb 2022 15:21:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233119AbiBXPW2 (ORCPT ); Thu, 24 Feb 2022 10:22:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236267AbiBXPWC (ORCPT ); Thu, 24 Feb 2022 10:22:02 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E15FD1B1DED; Thu, 24 Feb 2022 07:21:11 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id hw13so5059622ejc.9; Thu, 24 Feb 2022 07:21:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZuVEAxmh+A8QIoKXF28VboWqjl4yi9SC0NLu7C8jv84=; b=n3Q06AMtyRcuxRSJyhB/yrIWuWgxAFi1LbplrUxmyQN/ZgfzcCKvSQHWSmQDJo55nP 8Epr2RLKr0und+LLk1hXJ6zP96VRQsHUKNvtk/cDri3dxKGfBmB8boSYFDQf9nqQY2cm nyEyP6MzXEA1BKod3YjulPtpl+AFqx79fg6JDlUmJTUWetbjJneVGrbxbnCrA96tvvq/ Px8XPs2Pm1iwicZxkoAdO0slJAmhzwIj6zFkOTeNM1Mg5EgUxwQNQps3ACEnpxAdRD6x jcrTeHWKzTtnj8e+QNuBbZ3OwowpwWvQmKPUrnsO2RYIjwqHXgsEpKtbiJM8MuHxjxYh S1Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZuVEAxmh+A8QIoKXF28VboWqjl4yi9SC0NLu7C8jv84=; b=rSO92k7IlvasJ2ltE7WC9iO+RgH3mQah0B3Eowbys+kcVR8+BaMVilcyW2l8JXZB9n tGClhCQHPfpfAJQz5QUQclrTK7xX9NJ/P+hHFu1doW9n66HjmOanQqUcvSfj9kU6rjD0 iBA3ngyNrtqnX3wiuo515fYOzNJUc85FGV9pcovVxA9GmNpihgMgUSCCFo4RbGNDdPxY qHvBXCd55bEpFARquUWL5Av8nv8rz1LqTWvKmEyZxCjicIH7EekkjfieG00CXtY7lEiE AAO8XH1OisDVEkYJ7dLuraHgxTrUAnGveUYtVIo/ZsRbsGMxF3+e8PaBg27hbSZOA7/B 2JiQ== X-Gm-Message-State: AOAM531FH5TMB9+/9rkoHjUO6Epm1p/sDkZ74OEqMN3uiuA7cPHnAImX g/A5odZoxIWShdtuLdhYupU= X-Google-Smtp-Source: ABdhPJzpI29HmPXQ5CbpYZFiGvhNQ9X+Dmm0glvUDWLbhPo43pUwG74L/Lqm4wzWja6thoIHtLgFKQ== X-Received: by 2002:a17:906:360a:b0:6b9:1f8:9cdd with SMTP id q10-20020a170906360a00b006b901f89cddmr2733357ejb.461.1645716067180; Thu, 24 Feb 2022 07:21:07 -0800 (PST) Received: from Ansuel-xps.localdomain ([5.170.108.128]) by smtp.googlemail.com with ESMTPSA id x12sm1501980edv.57.2022.02.24.07.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 07:21:06 -0800 (PST) From: Ansuel Smith To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Ansuel Smith , Manivannan Sadhasivam , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC RFT PATCH v3 2/2] mtd: core: introduce of support for dynamic partitions Date: Thu, 24 Feb 2022 16:20:43 +0100 Message-Id: <20220224152043.27777-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220224152043.27777-1-ansuelsmth@gmail.com> References: <20220224152043.27777-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We have many parser that register mtd partitions at runtime. One example is the cmdlinepart or the smem-part parser where the compatible is defined in the dts and the partitions gets detected and registered by the parser. This is problematic for the NVMEM subsystem that requires an OF node to detect NVMEM cells. To fix this problem, introduce an additional logic that will try to assign an OF node to the MTD if declared. On MTD addition, it will be checked if the MTD has an OF node and if not declared will check if a partition with the same name / label is declared in DTS. If an exact match is found, the partition dynamically allocated by the parser will have a connected OF node. The NVMEM subsystem will detect the OF node and register any NVMEM cells declared statically in the DTS. Signed-off-by: Ansuel Smith --- drivers/mtd/mtdcore.c | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 9186268d361b..80e28a288f65 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -563,6 +563,61 @@ static int mtd_nvmem_add(struct mtd_info *mtd) return 0; } =20 +static void mtd_check_of_node(struct mtd_info *mtd) +{ + struct device_node *partitions, *parent_dn, *mtd_dn =3D NULL; + const char *mtd_name, *suffix =3D "-dynamic"; + int plen, suffix_len =3D 8; + struct mtd_info *parent; + bool found =3D false; + + /* Check if MTD already has a device node */ + if (dev_of_node(&mtd->dev)) + return; + + /* Check if a partitions node exist */ + parent =3D mtd->parent; + parent_dn =3D dev_of_node(&parent->dev); + if (!parent_dn) + return; + + partitions =3D of_get_child_by_name(parent_dn, "partitions"); + if (!partitions) + goto exit_parent; + + /* Search if a partition is defined with the same name */ + for_each_child_of_node(partitions, mtd_dn) { + mtd_name =3D of_get_property(mtd_dn, "label", &plen); + if (!mtd_name) { + mtd_name =3D of_get_property(mtd_dn, "name", &plen); + + /* Check correct suffix */ + if (plen <=3D suffix_len || + strncmp(mtd_name + plen - suffix_len, suffix, suffix_len)) + continue; + + plen =3D plen - suffix_len; + } + + if (!strncmp(mtd->name, mtd_name, plen)) { + found =3D true; + break; + } + } + + if (!found) + goto exit_partitions; + + /* Set of_node only for nvmem */ + if (of_device_is_compatible(mtd_dn, "nvmem-cells")) + mtd_set_of_node(mtd, mtd_dn); + +exit_partitions: + of_node_put(partitions); +exit_parent: + of_node_put(parent_dn); +} + /** * add_mtd_device - register an MTD device * @mtd: pointer to new MTD device info structure @@ -668,6 +723,7 @@ int add_mtd_device(struct mtd_info *mtd) mtd->dev.devt =3D MTD_DEVT(i); dev_set_name(&mtd->dev, "mtd%d", i); dev_set_drvdata(&mtd->dev, mtd); + mtd_check_of_node(mtd); of_node_get(mtd_get_of_node(mtd)); error =3D device_register(&mtd->dev); if (error) --=20 2.34.1