From patchwork Tue Aug 8 16:05:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 132645 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2294366vqr; Tue, 8 Aug 2023 10:55:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGKoxm0iNhcUTpHTjyjSPCLV/zblnyszXq2scxtNQbv2DYjtuMwdsF0eA3pn4bVl1oEEKaR X-Received: by 2002:a05:6a20:ddaf:b0:133:2974:d31a with SMTP id kw47-20020a056a20ddaf00b001332974d31amr144350pzb.17.1691517320031; Tue, 08 Aug 2023 10:55:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691517320; cv=none; d=google.com; s=arc-20160816; b=B0JKDO796CgrJ2jYoJ0GFm1jbF8WA/98W+RIbYvmLJw6kbCTu8WGH1E7LBwozxkSa7 JR3BaTE4gRcrRw7bZgebDRjqLK0+LFzVgAXD7ZRYVv2HLTHYXEZyT3dmNXKErI/eoC4S DdWrb6BuabNfZxQx5gYUbIQfjqK+Omo5XmrVkVS4mx9BuyKWcLQ7IoXhN6cIOydeWAYv XBZkChJ4kPNkkc4eWkQ8wNUQEYE/VJe3CfZObu0oFJ4LfZLMeHBdFNuyqwbRj121FGfK RLQdPAcP9smXNA7b+rZcdEtlxzGt6Gd4K2CCesPvvGd+XojVF6uszz8S2ZZHOgthLrvo SaOg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e13-20020a65678d000000b005638355e990si7529615pgr.410.2023.08.08.10.55.06; Tue, 08 Aug 2023 10:55:20 -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 S234242AbjHHRPH (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-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: 1773684465048705995 X-GMAIL-MSGID: 1773684465048705995 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);