Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp736064rdg; Wed, 11 Oct 2023 04:16:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqhRfjEM1KB29Ca6fqRX2bODNHDFrcjpElHeXopix3+xmTbbdXxOcscywm+CEYDTCyubZh X-Received: by 2002:a05:6870:1814:b0:1bb:83e9:6277 with SMTP id t20-20020a056870181400b001bb83e96277mr23832541oaf.33.1697023009850; Wed, 11 Oct 2023 04:16:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697023009; cv=none; d=google.com; s=arc-20160816; b=D1/JhiTeaOtzmQe6hW/6vdxASZsjZlNhzD26cj3czJllLxsuh3c4SA3B8l6xPHNOSJ nuBsFUdo8HqQVbKw19DK/rN98Ab3GrIBUXcC4aGMB2E4ZZTjD0m4DbhZU0yLa+QTbrsJ mgp2/1xHBAGEYXdtMy/EJKUW5kizz8WOhyF9+DUBuvaLIQuk8jtD3lbed+N3satFY7Us 6TeYQsqTdWC5JpV9YXz15Ck8aAURu0ME67zn3AfQF9dhmAaRdaaUgTCZqssumEy92Fiz puBxHVm1M1XNiEEjsajVep231u3gCiR4+mcavqClCFdSHQxSdWEyNqwxwbTMjHTSKU6b Vb7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+Y+0xrcG+PHrgnJuqiWYG+NeCnOC11MVS2SUmdfnPks=; fh=ckFishgG1a2IbCp1Px8nbWnyIQBY0wgyVli3fQkpF0I=; b=XnRDyqEox542KUActJ6M7WrkaRs010AgWT4T95Xq2ji/MMYUPe04lLVJQqvoIuw7xn kMMZ5Oysebn3LNsPJi+Ik+H4idWc9LvryzFSlcscPBVgcTLLbdQdfWavs3LH+CEMTd2f f7ktzqWbuIK0HNZK3LeCU0yjh9h47zevBns0HEsoRCAc7GBdy8kpl+8K8ytefzD0DlDS ctPP2vt91O3HRDxUljv7/9dA+0vMBxRfAsjuNjrQdeCcO+ikv42IWkujkCJ1A8ivzbg1 2oUTQW5cK83j5Ly6zpLy5amGtb2Of2sKYbS8YabtBsbHBDvS9vDZBzyuK3M/dciaKWi8 JMrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=dt+RV3+j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id j26-20020a63551a000000b00582f1f73c82si11483428pgb.381.2023.10.11.04.16.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 04:16:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=dt+RV3+j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id A168180D541C; Wed, 11 Oct 2023 04:16:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346020AbjJKLPl (ORCPT + 99 others); Wed, 11 Oct 2023 07:15:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231488AbjJKLPh (ORCPT ); Wed, 11 Oct 2023 07:15:37 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD68594; Wed, 11 Oct 2023 04:15:35 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id ECA831C0007; Wed, 11 Oct 2023 11:15:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1697022934; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Y+0xrcG+PHrgnJuqiWYG+NeCnOC11MVS2SUmdfnPks=; b=dt+RV3+j8VA5R7V6p6P1Z+IwGvlAp9Qr9PXI1Um1/UhyJCxMYvc21rIYN7POHOWSO51PB1 ZgjXNy6glpcuVcONmFqLF5d2oXHelkLJF0m9KSSkrEYApZhVrvq1l/cJl66EpLWNsG0M51 mVeYQGJ4tnZLMShdG4ttffYgziBSfX3Z3cvaLAjzrObI+q1CPNK6IunGaRBfyTLTX7v0Gq uOUJzTYfcSrPMHJDHaVQ/ObXJbvExZ1ON5r3Pbe/fk9Wl/F6e7hJhjFUevxgi+lCdH+AeT Fc46hNXgDFkQgaPVObuKEYywiQobuPDV8yd7Xv1+zQ+QIgi+8CfwsbPijcbbYQ== From: Miquel Raynal To: Srinivas Kandagatla , Greg Kroah-Hartman Cc: Michael Walle , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, , Robert Marko , Thomas Petazzoni , Luka Perkov , Randy Dunlap , Chen-Yu Tsai , Daniel Golle , Miquel Raynal , Rob Herring Subject: [PATCH v13 1/6] of: device: Export of_device_make_bus_id() Date: Wed, 11 Oct 2023 13:15:24 +0200 Message-Id: <20231011111529.86440-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231011111529.86440-1-miquel.raynal@bootlin.com> References: <20231011111529.86440-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: miquel.raynal@bootlin.com X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 11 Oct 2023 04:16:25 -0700 (PDT) X-Spam-Level: ** This helper is really handy to create unique device names based on their device tree path, we may need it outside of the OF core (in the NVMEM subsystem) so let's export it. As this helper has nothing patform specific, let's move it to of/device.c instead of of/platform.c so we can add its prototype to of_device.h. Signed-off-by: Miquel Raynal Acked-by: Rob Herring --- drivers/of/device.c | 41 +++++++++++++++++++++++++++++++++++++++ drivers/of/platform.c | 40 -------------------------------------- include/linux/of_device.h | 6 ++++++ 3 files changed, 47 insertions(+), 40 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 1ca42ad9dd15..6e9572c4af83 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -304,3 +304,44 @@ int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env * return 0; } EXPORT_SYMBOL_GPL(of_device_uevent_modalias); + +/** + * of_device_make_bus_id - Use the device node data to assign a unique name + * @dev: pointer to device structure that is linked to a device tree node + * + * This routine will first try using the translated bus address to + * derive a unique name. If it cannot, then it will prepend names from + * parent nodes until a unique name can be derived. + */ +void of_device_make_bus_id(struct device *dev) +{ + struct device_node *node = dev->of_node; + const __be32 *reg; + u64 addr; + u32 mask; + + /* Construct the name, using parent nodes if necessary to ensure uniqueness */ + while (node->parent) { + /* + * If the address can be translated, then that is as much + * uniqueness as we need. Make it the first component and return + */ + reg = of_get_property(node, "reg", NULL); + if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) { + if (!of_property_read_u32(node, "mask", &mask)) + dev_set_name(dev, dev_name(dev) ? "%llx.%x.%pOFn:%s" : "%llx.%x.%pOFn", + addr, ffs(mask) - 1, node, dev_name(dev)); + + else + dev_set_name(dev, dev_name(dev) ? "%llx.%pOFn:%s" : "%llx.%pOFn", + addr, node, dev_name(dev)); + return; + } + + /* format arguments only used if dev_name() resolves to NULL */ + dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s", + kbasename(node->full_name), dev_name(dev)); + node = node->parent; + } +} +EXPORT_SYMBOL_GPL(of_device_make_bus_id); diff --git a/drivers/of/platform.c b/drivers/of/platform.c index f235ab55b91e..be32e28c6f55 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -97,46 +97,6 @@ static const struct of_device_id of_skipped_node_table[] = { * mechanism for creating devices from device tree nodes. */ -/** - * of_device_make_bus_id - Use the device node data to assign a unique name - * @dev: pointer to device structure that is linked to a device tree node - * - * This routine will first try using the translated bus address to - * derive a unique name. If it cannot, then it will prepend names from - * parent nodes until a unique name can be derived. - */ -static void of_device_make_bus_id(struct device *dev) -{ - struct device_node *node = dev->of_node; - const __be32 *reg; - u64 addr; - u32 mask; - - /* Construct the name, using parent nodes if necessary to ensure uniqueness */ - while (node->parent) { - /* - * If the address can be translated, then that is as much - * uniqueness as we need. Make it the first component and return - */ - reg = of_get_property(node, "reg", NULL); - if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) { - if (!of_property_read_u32(node, "mask", &mask)) - dev_set_name(dev, dev_name(dev) ? "%llx.%x.%pOFn:%s" : "%llx.%x.%pOFn", - addr, ffs(mask) - 1, node, dev_name(dev)); - - else - dev_set_name(dev, dev_name(dev) ? "%llx.%pOFn:%s" : "%llx.%pOFn", - addr, node, dev_name(dev)); - return; - } - - /* format arguments only used if dev_name() resolves to NULL */ - dev_set_name(dev, dev_name(dev) ? "%s:%s" : "%s", - kbasename(node->full_name), dev_name(dev)); - node = node->parent; - } -} - /** * of_device_alloc - Allocate and initialize an of_device * @np: device node to assign to device diff --git a/include/linux/of_device.h b/include/linux/of_device.h index 2c7a3d4bc775..a72661e47faa 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -40,6 +40,9 @@ static inline int of_dma_configure(struct device *dev, { return of_dma_configure_id(dev, np, force_dma, NULL); } + +void of_device_make_bus_id(struct device *dev); + #else /* CONFIG_OF */ static inline int of_driver_match_device(struct device *dev, @@ -82,6 +85,9 @@ static inline int of_dma_configure(struct device *dev, { return 0; } + +static inline void of_device_make_bus_id(struct device *dev) {} + #endif /* CONFIG_OF */ #endif /* _LINUX_OF_DEVICE_H */ -- 2.34.1