From patchwork Tue Dec 19 02:33:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 180720 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1673470dyi; Mon, 18 Dec 2023 18:35:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3ngblfGtL5GF/+xNEgOXuwI/LhZ7MqNx1t2E/pK7OyjWsY1OEs3GDWf5uWa60Vwqpj9Et X-Received: by 2002:a05:6870:3914:b0:203:afea:5b52 with SMTP id b20-20020a056870391400b00203afea5b52mr4507451oap.12.1702953305065; Mon, 18 Dec 2023 18:35:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702953305; cv=none; d=google.com; s=arc-20160816; b=DsTglrD8ONKuJDoDWtBmyfYJfUY2EoY7ZPN6lHwGo66huPXoJGsUvRGLNCOhZTMdwd Wen200t2Wit79TDkkmwabm10efBxODbzh52VZ/D4BD7zvStkHH4mjbGosQW0qEs05xL4 6vDLpNFlePvZX8g8aCvzSWv04+Pz4BKbTP93iRsBeG88aGSMuYYHiQrn1aGm7CjQKJi/ Phd/5risk+pySvV612GQ2u2AAnqVRS2ZZ0n2/K1sOrABRK0I+CDZBw/KFr72c1mWoOkc 7dQLAoMXRq2YRo/vY4v//vYDDPNVmwYs+tSfoBk8+QO01RN4eFwLMsTMfJ6yJ3fTa+qq 6LzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:to :from:date; bh=TFryK93pKSqtFYp6InnEraIpYdiHALWWbxp94Yi5ZZg=; fh=75NJMYqoRo4jeDl32jx04p3D1q0Fgi4sqch+OCznfHk=; b=DDtn+XlRVFPBqWrEXn8qP6R4SenSi4vDfIi5hdVYKyUUCgNkA0rbW4/KLiTSob1kPA Qy0nMQOX1aQZv1M2hpIISCQJovSu+oMDX5xL/j9bU1gqctwupG29PHYb/Qa7CsYuikDI NxLaUHNz7J5EWUDXJa5dvnDBsxRfiLbIY5X0odmI7Ximn+xDbM/2lObKCojhmKB6mY4H NoDKn2MEmCf6JKB0hx4rgPX0guomCnzGUS3nc6LuyizfodO+efB/H1M0A/ySVF55YX+y 2w8XMH0f4AMmuvrq5dACfdGNq8vjZZ2b1GQFicV6ZunAOBJ1kq+qv3RMwlw28hZMiNG3 4O3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-4604-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4604-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id n10-20020a634d4a000000b005c1b2d279f3si18628454pgl.342.2023.12.18.18.35.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 18:35:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4604-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-4604-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4604-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7B0BEB22E77 for ; Tue, 19 Dec 2023 02:34:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7C3879F0; Tue, 19 Dec 2023 02:33:49 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9778749D; Tue, 19 Dec 2023 02:33:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96.2) (envelope-from ) id 1rFPvP-0008Jk-3B; Tue, 19 Dec 2023 02:33:41 +0000 Date: Tue, 19 Dec 2023 02:33:38 +0000 From: Daniel Golle To: 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 v7 6/7] mtd: ubi: populate ubi volume fwnode Message-ID: <688484b386b6d6ce96dfcc2e31b2a03a4bae567c.1702952891.git.daniel@makrotopia.org> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785675964558525793 X-GMAIL-MSGID: 1785675964558525793 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 ee80c04d1d5d0..7824ff069bd62 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 @@ -605,6 +631,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);