From patchwork Mon Feb 26 00:23:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 206156 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1796542dyb; Sun, 25 Feb 2024 16:24:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUkYrWC6/d6J1hDLbDukS5vbHFHNwhBoloAe8bNEntGXEdql8QUVPobYI+bPi3zDZ6MxWF5Arg8UZnGO5nLJfmwG/cbMA== X-Google-Smtp-Source: AGHT+IF9h/9/7F82ooFNQtKsfy6RHCZwSSmrrqoFO/8ZCkFDmhWUjs2Mbmiaj98/gCoSzmJll0VD X-Received: by 2002:a05:6a20:e68f:b0:1a0:7f3f:8d5d with SMTP id mz15-20020a056a20e68f00b001a07f3f8d5dmr8311643pzb.39.1708907094843; Sun, 25 Feb 2024 16:24:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708907094; cv=pass; d=google.com; s=arc-20160816; b=eRJKQWrgMhfxvOzkbCPtz99gmAWXu1H5/69z3OyCeFqJ+vAHTj++I2KTF5deQcdfbR 0T22bSHhqwSkH1wMOymYZ1PiWyIaj/sWqQxUpissnsH1aW6fxDj3LduxBsdMhuBhxb+F 8b9zFxpoIyniQomgjcZoY03RqlWXY0NjuJVc24P33dbxpdS06fd4CiCrschyIOYvKIyw rSyF/w/3TzNKI0pN8b/xP71FUm1ruhVjtC7LH33LEFotNmTCxbMzu1teyVgOgtIj5vpC Crfcd7iO1tLhfUrwR5rwxciBXHYHMEB3SmeLKZaNSS7x34flGTPj1tdtJjTi1cf6MIF8 IZYA== ARC-Message-Signature: i=2; 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=gjiGoy/Mov0rgSSFJJmFqafqYd9QeNEUJN3GIfTJa6E=; fh=iCY7pZACTeEM/aV1VSRdKj3GWTB74ZtqN+MwTbm3QUU=; b=zD//yzPW22V9Tu+ixG3B+GF7rE43TExpe9Kqdn7o3wA+yN05L2wUUn9nuxexxAOYFj h5mRNVVPExnzDHNH7IBsDgw+yb5j2boe0d29IMvJni+2qHxOGH/8XWjf4AZ2Mwx2hEi0 hztGNYAMxOJSXB8kBymQF41hOZDNrdGncjyEYcZf3Cdki15t7JpIKoVBy/98Ixiiq8x4 dZcxccdxnmrroKVnOkb/ukLumAGoatMflCZpHz5WwdseuFa8nBBynUW/xByjHxO6kTOt YmPpiYIx216/Ag2GYKm0sUbHZg1SqQZznpVyRM7FOBAPFoBnRd3VlqSEn+e+IrBuKBZn bu2w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-80360-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80360-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y1-20020a17090a474100b0029948fdf5ffsi4642553pjg.19.2024.02.25.16.24.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 16:24:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80360-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-80360-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80360-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 D59D9B20A55 for ; Mon, 26 Feb 2024 00:24:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B9CD1B59D; Mon, 26 Feb 2024 00:23:43 +0000 (UTC) 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 5856B46AF; Mon, 26 Feb 2024 00:23:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708907021; cv=none; b=BiRujBbk24qc5TLmhmOXgdgajXqa7qFNc0mcO1vznTydQWFWqYZ4sWo845cxa5LzELjrHqsSgsX4FI+z3TBvOQJcfVDhhXNmHYqmZxdoT6kCTiO6SuVzGvvfaSxxoSU82nG1AN+eEP13f6FcQgwdlEvy9l2RIAUryW6qDuFsLzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708907021; c=relaxed/simple; bh=8ZN/uqPCf9gZGtjw4nLeVdgvb5J82r/tQ0SJ2C+AHBE=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OpxMTZvB/K9WfWB9w0o2dOXuWzSWbBVta5zoqRX4Sfmf+Tcn7/mb6cSIDsKTEfBjrJnQbJx8PPJHTKGyJMkdpzuuap77oCBcVkFZ+Yn5dXuODNO7T6P46SIAB2u3po7iCXMGiGxhSjrxYS3sdR1FlTNUwJC7LRW+UA2YDEUQbIA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 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 1reOmM-0001qF-1C; Mon, 26 Feb 2024 00:23:34 +0000 Date: Mon, 26 Feb 2024 00:23:31 +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 v8 6/7] mtd: ubi: populate ubi volume fwnode Message-ID: <8097c9d13f92b51145ed747610de0bc9ad26d079.1708906456.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: 1791918965675894703 X-GMAIL-MSGID: 1791918965675894703 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);