Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp1270503rwb; Sat, 5 Aug 2023 10:44:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwhoGP/4wmFfAo4M1Ron5BzoMVpoPGadJXx3nHwGtRd6CDZZmV6U+QwWgdOfQpXxqT6LsG X-Received: by 2002:a17:906:153:b0:98d:5333:79c with SMTP id 19-20020a170906015300b0098d5333079cmr5007773ejh.5.1691257477075; Sat, 05 Aug 2023 10:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691257477; cv=none; d=google.com; s=arc-20160816; b=d5b8qcEJnkwg+ZGFYTxC1n4siKfeWcAIlJOxs5XXTzBEMZvGICA5aQYaORo1XBXGUj cOtZhdFLj1CKlWvATKh6+p7ucnXSgeSTIHZ4ZmgavBNSwNnEFq+8ZkeQjnzCfJyrqXxD QjhAy+zkEQGMLPlvPb82rGy5GzoNcATLmG1O9nFdrb3sVO7EzbpLkiLB/HLTOism8BAC j0VPit/mrPGWrB0KyKOlHU09ILaWzNqTn+irZj2sVXZQ02JvHhxrEwuFktTkNjM5sng7 zFuGD/dw8Cp6KsDXHtujv5zs9CTbxYF+0sMfGAwK3bO7pRFZbj7q85ESUof7scARQFoH e2Nw== 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=o9y8ga7ysIvZ1tA1LAIP7ohY/ZuMF48QFqDAHAq8I6A=; fh=WrF5P4rt5GKLKZXFPrBfHwP5VFIZG8GPN/h4vsvn4l4=; b=lZbdlOKOBgQyqEYmjOyczYkQif5UyagsDFbA8QGmwjSk/TmiiOOUOWl2KUanN/x1n7 ESpqyJuJ2w8MNnOLAxbxxdcPxoFhGmZh0SD9iRphde1x7ix+mj3WXk4gUyA6QQLdB3FW EjgpdC2Aa8kNU94h01m3JwX6F4nTQYXmOsi0ihAhpDUjlI2ciO7haly93uGBmFiHK64q AWaWedl9REBNHEuHj/OehlwdYMLEoPiY3khviOKTgFvY7FmnkaA2UdHCS/mXSElG8SLB daICmbdDJ4HuUKtBeLZnBsX0oF2rip8Ujx4TwamrI43hqGSE+xKwgwY09m8Az+IHCy15 OjDg== 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 kd9-20020a17090798c900b009934b1eb56dsi2432861ejc.11.2023.08.05.10.44.12; Sat, 05 Aug 2023 10:44:37 -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 S229932AbjHEQ0m (ORCPT + 99 others); Sat, 5 Aug 2023 12:26:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjHEQ0l (ORCPT ); Sat, 5 Aug 2023 12:26:41 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 649364204 for ; Sat, 5 Aug 2023 09:26:31 -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 1qSK6l-0000fK-1j; Sat, 05 Aug 2023 16:26:27 +0000 Date: Sat, 5 Aug 2023 17:26:20 +0100 From: Daniel Golle To: Randy Dunlap , Richard Weinberger , Miquel Raynal , Vignesh Raghavendra , linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH v2 6/7] 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, RCVD_IN_DNSWL_BLOCKED,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 | 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); } +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 = 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 != 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 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 +627,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