From nobody Mon Apr 20 05:55:36 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 7ADF3C433EF for ; Wed, 22 Jun 2022 01:11:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355328AbiFVBLJ (ORCPT ); Tue, 21 Jun 2022 21:11:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229917AbiFVBLE (ORCPT ); Tue, 21 Jun 2022 21:11:04 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 439393191B; Tue, 21 Jun 2022 18:11:03 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id i10so17445118wrc.0; Tue, 21 Jun 2022 18:11:03 -0700 (PDT) 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=K6qKElTJRH1xqsuMI22agJPVydPpDeCDPF+3KJh55+w=; b=AXviIowkwnwirSoG8qaa9h+NDYTQ9tN16Nn3dLJ8JdzE2ao2zmkrL4JUz27+qnsRgb yLdqaqX6RCty27iZJUdPlTqnWPdmtlS2jPxk6aoA9jcbsKfe97425ioKLF7GGB29HVyg nqNUnSbaXdXFB/Ps5UkUA6Nysug8Mr5Pqb1UdvsVrJCi+vHl69WfRjHfTmfx6AsfPfei oy/oWx7zIUXWiQrjGovYUp7Jz/OevNQktwxw4RPAQQqW6CaeYo+4by9dD2aG1QVqBL9p LbFHkupeQ0Sh07KCOAFAaYdBtkbvhSULg9tPGgP5h5Y0lj0Ap5WumkWS8D1Trk0BGHuB Bx6g== 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=K6qKElTJRH1xqsuMI22agJPVydPpDeCDPF+3KJh55+w=; b=6zzmabQoii3orz1BRwEA/mxOmFqZhsMsf9VdqOtL8OOoZmH0xYjgsKsbhhmaWCQn3l mJRri39jgKhh1a15bQbtbWAtuxRN3Nc78MqdUy2fSNbHVEmhQkbGbsKGX+CFTgVaHT8c Alln6iDw/8Npv4WazseaAPA4zVlIfDw/hCbSrqyYKwzKSZ/qKGe3ZNG/mu2QxBc2HGsi W1cuuEEegSD2J8KvXRz23CKYk+yEUcZ1Ypua73Ah4kMQyc8AMSnlQUy233SyvdVkXjgp V8ruMgkoKzMZ4X8o270tqZrvDOSvnoS2SmceyEMLgBOU4B8Nvs/XyqNfB43zs5A/+Ibj VmvA== X-Gm-Message-State: AJIora9KcivvZkmD98WOp+gRvF1i6b3lpzP+WkNNGCkZpAsAFX1WqMdB wei68/CjoL3TYLMm78w5U1g= X-Google-Smtp-Source: AGRyM1tPWwN6F6KomkQo6rqcXzv6P/7t0b4jDz7Bg0/MyPftF12VjIvqZBCSTVVjBbxBkxss/OtHYg== X-Received: by 2002:a5d:6d09:0:b0:21a:1321:55b6 with SMTP id e9-20020a5d6d09000000b0021a132155b6mr640978wrq.117.1655860261401; Tue, 21 Jun 2022 18:11:01 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id x13-20020adfdd8d000000b0021b81855c1csm16560086wrl.27.2022.06.21.18.10.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 18:11:00 -0700 (PDT) From: Christian Marangi To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Jens Axboe , Stephen Boyd , Greg Kroah-Hartman , Christian Marangi , =?UTF-8?q?=EF=BF=BDecki?= , Manivannan Sadhasivam , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 1/3] dt-bindings: mtd: partitions: support label/name only partition Date: Wed, 22 Jun 2022 03:06:26 +0200 Message-Id: <20220622010628.30414-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220622010628.30414-1-ansuelsmth@gmail.com> References: <20220622010628.30414-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Document new partition nodes that declare only the label/name instead of the reg 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 and a 'partition-' prefix is needed. The node name with the 'partition-' prefix stripped, is used to match the partition allocated by the parser at runtime and the parser will provide reg and offset of the mtd. If the partition to match contains invalid char for a node name, the label binding can be used to declare the partition name. 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: Christian Marangi Reviewed-by: Rob Herring --- .../bindings/mtd/partitions/partition.yaml | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/mtd/partitions/partition.yam= l b/Documentation/devicetree/bindings/mtd/partitions/partition.yaml index e1ac08064425..f1a02d840b12 100644 --- a/Documentation/devicetree/bindings/mtd/partitions/partition.yaml +++ b/Documentation/devicetree/bindings/mtd/partitions/partition.yaml @@ -11,6 +11,17 @@ description: | relative offset and size specified. Depending on partition function extra properties can be used. =20 + A partition may be dynamically allocated by a specific parser at runtime. + In this specific case, a specific suffix is required to the node name. + Everything after 'partition-' will be used as the partition name to comp= are + with the one dynamically allocated by the specific parser. + If the partition contains invalid char a label can be provided that will + be used instead of the node name to make the comparison. + This is used to assign an OF node to the dynamiccally allocated partition + so that subsystem like NVMEM can provide an OF node and declare NVMEM ce= lls. + The OF node will be assigned only if the partition label declared match = the + one assigned by the parser at runtime. + maintainers: - Rafa=C5=82 Mi=C5=82ecki =20 @@ -41,7 +52,12 @@ properties: immune to paired-pages corruptions type: boolean =20 -required: - - reg +if: + not: + required: [ reg ] +then: + properties: + $nodename: + pattern: '^partition-.*$' =20 additionalProperties: true --=20 2.36.1 From nobody Mon Apr 20 05:55:36 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 5F565C433EF for ; Wed, 22 Jun 2022 01:11:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236380AbiFVBLN (ORCPT ); Tue, 21 Jun 2022 21:11:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354552AbiFVBLG (ORCPT ); Tue, 21 Jun 2022 21:11:06 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AADD3151F; Tue, 21 Jun 2022 18:11:05 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id w17so21183350wrg.7; Tue, 21 Jun 2022 18:11:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YC/BC0ut4zFCpXZBrPnkhMqs1FiO6H+QzVtgFYbz5nU=; b=GvYFWsppXKJZ2uIo+QFSC7fjqDtt18IMKsg0aScb6ff04JS2hKbjmefTxEgOGHM9OL sRnrg7Ks8/0zgG4fiH/iC0j6FhVoDi+rI0CpD5L3stBpqsIvoZw/vX49Tw6NGPYvry2z EUlh0DgLtjSehF+050c5bG/0QsXwphOaZOi+0lRC0cs/khAm1XkV2SE5jOphomRJ47FW sUFJebvmlWt3zIOkHaGYoaxvKuJEtLV8fGS9VYNCpHR6BwYQAhU6Y/iGUVWlX9C/OE0C JBmTEFBznGUbYTQyWwBLRSsffCOECWJfgYNSnt/hYcVnCDHP9+bLNRRZ7h9RABTWl2W1 AiWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YC/BC0ut4zFCpXZBrPnkhMqs1FiO6H+QzVtgFYbz5nU=; b=sH4YUSZXKXsj3qCb1EuKH0T62F74Z/H15C5A6LeU8wVcIAgQ6FF0VMR1HSUSSeNae7 FY+88dXXDWEvzuRF9tP/JMJ6P64a+2QxHD5i2Bg4UFD3SP6WH4Kearmf2NjGYYKzog0x SA+FYaDh2Twr9ELooGOY6t7GVoXSaWSoElvYfH9J2+Uz6wddQ1KrSCDFUkjMHOYPqNyq tt16OR6/d1fl/F0/AybrPRLOOMC2ug4pG+zZ3/cJ1MBh4m0Y3tOLwRNIM6ojujubuW1I 14oQz6wCCMOH6GJ5WKZwU8Bmw60Yr+3ZbKPEFtwyR1Ir4Efc3Q588wOAqYyDfn0CMUy4 mxGQ== X-Gm-Message-State: AJIora9Yu1UXt4DY8FofgweU8zwBg5auAlhnhUcIqd42wcR5Fr3aIDxv eug/ZTPq1kQqNlPA2uSYfh4= X-Google-Smtp-Source: AGRyM1tyijALZnxpm5d/xI5wzVlJ8yVf04+msGCD9rlWW03RO2oTzb/ITlZlh57VeVaFdApA4JYt0g== X-Received: by 2002:adf:e6d2:0:b0:21b:9580:8d8b with SMTP id y18-20020adfe6d2000000b0021b95808d8bmr670736wrm.120.1655860263863; Tue, 21 Jun 2022 18:11:03 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id x13-20020adfdd8d000000b0021b81855c1csm16560086wrl.27.2022.06.21.18.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 18:11:02 -0700 (PDT) From: Christian Marangi To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Jens Axboe , Stephen Boyd , Greg Kroah-Hartman , Christian Marangi , =?UTF-8?q?=EF=BF=BDecki?= , Manivannan Sadhasivam , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Rob Herring Subject: [PATCH v6 2/3] dt-bindings: mtd: partitions: add additional example for qcom,smem-part Date: Wed, 22 Jun 2022 03:06:27 +0200 Message-Id: <20220622010628.30414-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220622010628.30414-1-ansuelsmth@gmail.com> References: <20220622010628.30414-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" Add additional example for qcom,smem-part to declare a dynamic partition to provide NVMEM cells for the commonly ART partition provided by this parser. Signed-off-by: Christian Marangi Reviewed-by: Rob Herring --- .../mtd/partitions/qcom,smem-part.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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..dc07909af023 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: + "^partition-[0-9a-z]+$": + $ref: partition.yaml# + required: - compatible =20 @@ -31,3 +35,26 @@ examples: compatible =3D "qcom,smem-part"; }; }; + + - | + /* Example declaring dynamic partition */ + flash { + partitions { + compatible =3D "qcom,smem-part"; + + partition-art { + 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>; + }; + }; + }; + }; --=20 2.36.1 From nobody Mon Apr 20 05:55:36 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 D742FC433EF for ; Wed, 22 Jun 2022 01:11:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355537AbiFVBLQ (ORCPT ); Tue, 21 Jun 2022 21:11:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354643AbiFVBLH (ORCPT ); Tue, 21 Jun 2022 21:11:07 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A33E23191B; Tue, 21 Jun 2022 18:11:06 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id w17so21183390wrg.7; Tue, 21 Jun 2022 18:11:06 -0700 (PDT) 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=zIg/BRRxdkYhUPWpTwl1+aMNGlh1YT/9AIwW2tFGVlk=; b=AXrxQDkmAUcOCh+UdnnNbIqZOiuzmon7wk7L3jQI2qCCZA8YVEcXCRkl6ttkGrC+uD 1oZfkW48SVoSfGaftqyfa1tYqP/kAuYxDfxuL0aEGxXysRyavyrhehp174XmhMPMTFkl oFDJZWSoO+PmgKaEn1KCuJP1n8oeaEB75I6zvTSqmlKyVJCeXTI/1p3fdqUBJN/mDKsm AueMlVSrR4rqimpS6LVne+TzC1yGsf1Z/RM20Pp7utN889Niyi6efKIXQqYU5CxnNhyy T3k9UtoDMSAWLWjsinDxlci6KqXUVoTycCR1v3FKsCVh2QyqqJ4JCwBfG2tQo4JSqfiG Nrzw== 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=zIg/BRRxdkYhUPWpTwl1+aMNGlh1YT/9AIwW2tFGVlk=; b=o66zqGCokQUGN9vzbJTN6zeZoG9e6W3Jy+YmTV/B0mFNO5k/Y1Js4CwMiAMuAyZnwN hpVQctX69RSt3H2MPvgpAbiR1osKk9hBrmkPKrbIVLToZZXlJr8xUObGWbmlo3js7zPc Iv3DKln6qqOOrK5Ki7i6f/zDtgV1fRXUqaZUKXsFvgcuITmODb/s5SbwJbMAr9F9dgbP CjmJYNu7zgNkz1pVULWGN8D3Zil4brdiBMvd7S+q5Fr2wBPaSg5MW13HIUzI5X1Lyjyk Jv4b14Bet1stEF8XhEHmJYjxICuZbWt9NkNg5DHO8zrZaFhjIfZpnEvRFU9bQfgAnip5 V/1g== X-Gm-Message-State: AJIora8FoXtgIbEbrbqN+LN52Q7aEZB/SFX0HPRQy+jkMTp+VWL66tyU cguPp9/MpthnVhAE/669XAE= X-Google-Smtp-Source: AGRyM1v/u5MWPXIFPc5OhGTADPYHN20NOfalAr5VlbRCN6NuUJstWYLreXzWuGpBBOaxhXwWMUMwHQ== X-Received: by 2002:a05:6000:50:b0:21a:3d97:14fd with SMTP id k16-20020a056000005000b0021a3d9714fdmr618139wrx.685.1655860265052; Tue, 21 Jun 2022 18:11:05 -0700 (PDT) Received: from localhost.localdomain (93-42-70-190.ip85.fastwebnet.it. [93.42.70.190]) by smtp.googlemail.com with ESMTPSA id x13-20020adfdd8d000000b0021b81855c1csm16560086wrl.27.2022.06.21.18.11.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 18:11:04 -0700 (PDT) From: Christian Marangi To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Jens Axboe , Stephen Boyd , Greg Kroah-Hartman , Christian Marangi , =?UTF-8?q?=EF=BF=BDecki?= , Manivannan Sadhasivam , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 3/3] mtd: core: introduce of support for dynamic partitions Date: Wed, 22 Jun 2022 03:06:28 +0200 Message-Id: <20220622010628.30414-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220622010628.30414-1-ansuelsmth@gmail.com> References: <20220622010628.30414-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 label / node name 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: Christian Marangi --- drivers/mtd/mtdcore.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 7731796024e0..e9d534b9971d 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -546,6 +546,66 @@ 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 *pname, *prefix =3D "partition-"; + int plen, mtd_name_len, offset, prefix_len; + 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; + + prefix_len =3D strlen(prefix); + mtd_name_len =3D strlen(mtd->name); + + /* Search if a partition is defined with the same name */ + for_each_child_of_node(partitions, mtd_dn) { + offset =3D 0; + + /* Skip partition with no/wrong prefix */ + if (!of_node_name_prefix(mtd_dn, "partition-")) + continue; + + /* Label have priority. Check that first */ + if (of_property_read_string(mtd_dn, "label", &pname)) { + of_property_read_string(mtd_dn, "name", &pname); + offset =3D prefix_len; + } + + plen =3D strlen(pname) - offset; + if (plen =3D=3D mtd_name_len && + !strncmp(mtd->name, pname + offset, 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 @@ -651,6 +711,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.36.1