From nobody Sun Feb 8 09:12:07 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 9702EC00528 for ; Mon, 31 Jul 2023 19:14:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbjGaTOF (ORCPT ); Mon, 31 Jul 2023 15:14:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbjGaTOC (ORCPT ); Mon, 31 Jul 2023 15:14:02 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10555184 for ; Mon, 31 Jul 2023 12:14:02 -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 1qQYL8-0001iX-2t; Mon, 31 Jul 2023 19:14:00 +0000 Date: Mon, 31 Jul 2023 20:13:47 +0100 From: Daniel Golle To: Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH 5/6] mtd: ubi: populate ubi volume fwnode Message-ID: <3efb1ac62048dd6818688737e22cdaabb9f65ce3.1690823629.git.daniel@makrotopia.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c index eed4b57c61bda..3b997256cfba7 100644 --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c @@ -124,6 +124,35 @@ static void vol_release(struct device *dev) kfree(vol); } =20 +static struct fwnode_handle *find_volume_fwnode(struct ubi_volume *vol) +{ + struct fwnode_handle *fw_vols, *fw_vol; + const char *volname; + u32 reg; + + fw_vols =3D 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; + + /* + * volume id (reg) in device tree greater than UBI_MAX_VOLUMES + * can be used to match by volname only + */ + if (!fwnode_property_read_u32(fw_vol, "reg", ®) && + reg < UBI_MAX_VOLUMES && vol->vol_id !=3D reg) + continue; + + return fw_vol; + } + + return NULL; +} + /** * ubi_create_volume - create volume. * @ubi: UBI device description object @@ -223,6 +252,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ub= i_mkvol_req *req) vol->name_len =3D req->name_len; memcpy(vol->name, req->name, vol->name_len); vol->ubi =3D ubi; + device_set_node(&vol->dev, find_volume_fwnode(vol)); =20 /* * Finish all pending erases because there may be some LEBs belonging @@ -597,6 +627,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_v= olume *vol) vol->dev.class =3D &ubi_class; vol->dev.groups =3D 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 =3D device_register(&vol->dev); if (err) { cdev_del(&vol->cdev); --=20 2.41.0