From patchwork Fri Aug 11 01:38:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 134276 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp810072vqi; Thu, 10 Aug 2023 19:23:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAqZXg0eKYatidyEQYLMjokutLOEoOzJZF6Z7UT4y+X2BgPSCOWxSdxXekMTbldk5ba07b X-Received: by 2002:a05:6808:1144:b0:3a7:20a9:ae8e with SMTP id u4-20020a056808114400b003a720a9ae8emr793388oiu.21.1691720616867; Thu, 10 Aug 2023 19:23:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691720616; cv=none; d=google.com; s=arc-20160816; b=qbf6mco9l4z27Ii2J6jnHXJKnU/GxF/2GSFz7HrWgGgBzHg8pRHYW0sPma+AhSkfXL CyrvEF06wQWv1Ag+wMtieWX59jd8KIkg7WOtO2EZatzffYUXX1zLPMl7oKolAAdIlfyd zXDJ2YOR+HuwBv+lwK07reLx/OoXTLIUwUR1/AKQV5/HxaCi9EroXkevhTkTPxt2VRq4 QvS2lcCl51ikSv8X4Ohiyc9Udva7LrdbSe3HwmKkUjdOk1uw01U+oUkTfgtYRlekEn5/ 4HHsKl+PhkD0qoQ3YnD4f60i8whhbgSGGjrlLoT8ZoSP4bHN0r8zvWRYIHtuOiem3wlc /ySA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e3-20020a636903000000b005578994f212si2537084pgc.425.2023.08.10.19.23.23; Thu, 10 Aug 2023 19:23:36 -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 S232898AbjHKBik (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-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773897637330726376 X-GMAIL-MSGID: 1773897637330726376 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);