Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp738131rdg; Thu, 10 Aug 2023 19:27:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1gzq27dY5DZQ4jIXf3G0wTxe/tYzMxG4w3jVDzz79iA88Qo9euHNKBmi75L9WpbJMbrLv X-Received: by 2002:a17:903:1249:b0:1bc:2bd:852a with SMTP id u9-20020a170903124900b001bc02bd852amr771478plh.42.1691720873489; Thu, 10 Aug 2023 19:27:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691720873; cv=none; d=google.com; s=arc-20160816; b=jp8N0/6+FCFWJ7G+ZZt1/lNLsB4RkWOHlTKlMwHEXWhwC/9Qu42UWc8SzdLCBEbENI 1u5Hfok6ThXV06r1aV8U/cFwrPSuTUiFce7UHqmB8DS8nA+704jjW46NyvOVFuEHp3Cf 1MBqOvWTpWf/y0SKpKZ++J+iGce++QuS6K+fgCCRo9JbnJP4hqJgOPRGSUiU2rzi0WeY Ey6yEoFQN6ZnDQBZi9NQLq+T5DE0v0AbNl/LAuDXEikgk9td0mAyhAOo+ggYYUyVhavY b7v3YGrGhPjk4OdwWtZ+8qNaEOkLKjhmSdSCEXRTQtrjmE4kx0amabaMAzRls73E97Qv bQ0w== 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=J/nVLXYo3NncRPaPPmeGJWUENvGn6ZHbNlENk8zMnR4=; fh=fqW8oMY9ydixFpWZdFhmrmd4m3lvFBw58fIoJyq/l8o=; b=DszTOeDY+neaRTlK5S8Qs5YFqsOxBR9lM9IhfdifoIe4xeO9su9OYGC2OH0/FUBOOX VzaEjgu9qv0y84OVAaYShNrZZkWTxLo7XgQmegFLXQxD71LMbYvyfRCiQ8V6+9pWUWTd Lodu5MrUh5jyjv2EG2T+kMqIdBpjIa/sQzMZrrRUuVrSdwRSt71yMoUo+YpPgC+nkhRt fSVgXddsQekgeNyiw7+D+DC6yb8Dgys9oqIxUA0HXeG8l97s2dezFvDliJyhT01/oFNv p3F41UYl8oCcs5ofF+mgOCu6Ya37xhIU4Ti8KgRSq3sTtQ+ogL+ByyNcFKZ/6cyYsj8b wgog== 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 q13-20020a170902dacd00b001b50cc75c2dsi2623266plx.611.2023.08.10.19.27.41; Thu, 10 Aug 2023 19:27:53 -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 S232869AbjHKBik (ORCPT + 99 others); Thu, 10 Aug 2023 21:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231285AbjHKBij (ORCPT ); Thu, 10 Aug 2023 21:38:39 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C634010D; Thu, 10 Aug 2023 18:38:38 -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 1qUH6h-000569-34; Fri, 11 Aug 2023 01:38:28 +0000 Date: Fri, 11 Aug 2023 02:38:20 +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 v4 7/8] mtd: ubi: populate ubi volume fwnode Message-ID: <1faf99d4ae75fa9ac2b36e18fb71075469f246e1.1691717480.git.daniel@makrotopia.org> 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..9db845a43ecfc 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, "volume-name", &volname) && + strncmp(volname, vol->name, vol->name_len)) + continue; + + if (!fwnode_property_read_u32(fw_vol, "volume-id", &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