Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4572613rwb; Tue, 8 Aug 2023 10:18:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHy2fLiHe/7VpxLZf78nF7iO89qut9bzhAPXrPq8ZTjg9Of3VLqrJVWI/LbGImw9X9XaZX9 X-Received: by 2002:a17:90a:ff11:b0:268:1376:d501 with SMTP id ce17-20020a17090aff1100b002681376d501mr233991pjb.5.1691515105888; Tue, 08 Aug 2023 10:18:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691515105; cv=none; d=google.com; s=arc-20160816; b=JGhZf7wboEu2rRB1WV0+9G3qlcUDdicYFxL2I8F8buokBlC4aqciVuNOLV39wA6SDd /2Vynpc5NkFo04dDSIBT59aBC6xhWQVrGH49JlNcHSEONVFh9BLmTPfxNbAK/niopJgK 8/RdgkqvxooZCKdRvN1q4gZ8SAkAyOhk3M5weWOI0Ms01+5vXvvG14ucQAEpsYNu7FMH ihVmTWIVqrd5tcpuHA7Iwon/cXkX5Su4OXGRRuJisMZuaQSeheM65SoupCQjPaf72H/l APAR8CJxg/G8zTkzWaaimMfb6QRz5AyOPOz9MIQZrWpvWX6k/AD6FkptE9kcetOoFt/Y Yq2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date; bh=dWYii6hKzMkd+HedQDz8yVgjqtCLZnyVd9lIFaKLjXA=; fh=fqW8oMY9ydixFpWZdFhmrmd4m3lvFBw58fIoJyq/l8o=; b=HoKwyJMnF9GqkKsePKpvIONUw+5STbG6q4qcUz7FShAZfN4xBkB47rmaDzRYhE9yIj n7G+j18sX9UvdsyqLIP8gUnOEBdoGdGrqMHnttaZRLsDgwux0sZ4ZiMinh/Uu/7lQnJE TrDQcU7zGQKLGwn5ERY03zUdZYwNwcg2RvpYuiH1fy3UJhzU1haZLOtw5UceQOA6xLnv bCSpOjA6lPObi8IImye7EmokZ9FH8q/3OvEVy20uxbWtkWFu46jw4cBK5QKjJIeuuEDi 27mZEEqyHqSEWfJuBqmBkY9Ru/Jr0FUhbLHRvSr7nc55Xkfy/ZAHyDqi7JI0HUqFsc3z PEZA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w22-20020a17090a8a1600b0026934bf746bsi5675844pjn.62.2023.08.08.10.18.13; Tue, 08 Aug 2023 10:18:25 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234163AbjHHRPH (ORCPT + 99 others); Tue, 8 Aug 2023 13:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234189AbjHHROW (ORCPT ); Tue, 8 Aug 2023 13:14:22 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11B626BD3E; Tue, 8 Aug 2023 09:06:01 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qTPD4-0007bf-1p; Tue, 08 Aug 2023 16:05:26 +0000 Date: Tue, 8 Aug 2023 17:05:18 +0100 From: Daniel Golle To: Randy Dunlap , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Daniel Golle , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 7/8] mtd: ubi: populate ubi volume fwnode Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 Look for the 'volumes' subnode of an MTD partition attached to a UBI device and attach matching child nodes to UBI volumes. This allows UBI volumes to be referenced in device tree, e.g. for use as NVMEM providers. Signed-off-by: Daniel Golle --- drivers/mtd/ubi/vmt.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c index eed4b57c61bda..ee756a00a370b 100644 --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c @@ -124,6 +124,31 @@ static void vol_release(struct device *dev) kfree(vol); } +static struct fwnode_handle *find_volume_fwnode(struct ubi_volume *vol) +{ + struct fwnode_handle *fw_vols, *fw_vol; + const char *volname; + u32 volid; + + fw_vols = device_get_named_child_node(vol->dev.parent->parent, "volumes"); + if (!fw_vols) + return NULL; + + fwnode_for_each_child_node(fw_vols, fw_vol) { + if (!fwnode_property_read_string(fw_vol, "volname", &volname) && + strncmp(volname, vol->name, vol->name_len)) + continue; + + if (!fwnode_property_read_u32(fw_vol, "volid", &volid) && + vol->vol_id != volid) + continue; + + return fw_vol; + } + + return NULL; +} + /** * ubi_create_volume - create volume. * @ubi: UBI device description object @@ -223,6 +248,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) vol->name_len = req->name_len; memcpy(vol->name, req->name, vol->name_len); vol->ubi = ubi; + device_set_node(&vol->dev, find_volume_fwnode(vol)); /* * Finish all pending erases because there may be some LEBs belonging @@ -597,6 +623,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) vol->dev.class = &ubi_class; vol->dev.groups = volume_dev_groups; dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); + device_set_node(&vol->dev, find_volume_fwnode(vol)); err = device_register(&vol->dev); if (err) { cdev_del(&vol->cdev); -- 2.41.0