mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH v2 06/16] of: implement of_alias_from_compatible
Date: Fri,  6 Jun 2025 07:57:38 +0200	[thread overview]
Message-ID: <20250606055748.1990383-7-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250606055748.1990383-1-a.fatoum@barebox.org>

This is going to be used in the incoming MIPI DSI support.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/of/base.c | 31 +++++++++++++++++++++++++++++++
 include/of.h      |  1 +
 2 files changed, 32 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1439e55a0aac..eb1f0b44f22d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -3569,6 +3569,37 @@ int of_graph_port_is_available(struct device_node *node)
 }
 EXPORT_SYMBOL(of_graph_port_is_available);
 
+/**
+ * of_alias_from_compatible - Lookup appropriate alias for a device node
+ *			      depending on compatible
+ * @node:	pointer to a device tree node
+ * @alias:	Pointer to buffer that alias value will be copied into
+ * @len:	Length of alias value
+ *
+ * Based on the value of the compatible property, this routine will attempt
+ * to choose an appropriate alias value for a particular device tree node.
+ * It does this by stripping the manufacturer prefix (as delimited by a ',')
+ * from the first entry in the compatible list property.
+ *
+ * Note: The matching on just the "product" side of the compatible is a relic
+ * from I2C and SPI. Please do not add any new user.
+ *
+ * Return: This routine returns 0 on success, <0 on failure.
+ */
+int of_alias_from_compatible(const struct device_node *node, char *alias, int len)
+{
+	const char *compatible, *p;
+	int cplen;
+
+	compatible = of_get_property(node, "compatible", &cplen);
+	if (!compatible || strlen(compatible) > cplen)
+		return -ENODEV;
+	p = strchr(compatible, ',');
+	strscpy(alias, p ? p + 1 : compatible, len);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_alias_from_compatible);
+
 /**
  * of_get_machine_compatible - get first compatible string from the root node.
  *
diff --git a/include/of.h b/include/of.h
index 2258cd501b72..fa2401fc8ded 100644
--- a/include/of.h
+++ b/include/of.h
@@ -196,6 +196,7 @@ extern struct device_node *of_copy_node(struct device_node *parent,
 extern struct device_node *of_dup(const struct device_node *root);
 extern void of_delete_node(struct device_node *node);
 
+extern int of_alias_from_compatible(const struct device_node *node, char *alias, int len);
 extern const char *of_get_machine_compatible(void);
 extern int of_machine_is_compatible(const char *compat);
 extern int of_device_is_compatible(const struct device_node *device,
-- 
2.39.5




  parent reply	other threads:[~2025-06-06  5:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-06  5:57 [PATCH v2 00/16] ARM: stm32mp: add MIPI DSI support Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 01/16] driver: bus: embed bus driver node into bus Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 02/16] driver: switch busses to device class Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 03/16] driver: factor out bus definitions into separate header Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 04/16] driver: bus: add helpers for finding devices in busses Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 05/16] drive: bus: make use of new bus_find_device helper Ahmad Fatoum
2025-06-06  5:57 ` Ahmad Fatoum [this message]
2025-06-06  5:57 ` [PATCH v2 07/16] video: vpl: fix potential read of uninitialized variable Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 08/16] video: vpl: factor out vpl_for_each Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 09/16] video: vpl: handle missing struct vpl::ioctl gracefully Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 10/16] video: vpl: add vpl_bridge abstraction Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 11/16] video: factor out drm_mode_vrefresh Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 12/16] video: add base MIPI DSI support Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 13/16] video: add Designware MIPI-DSI support Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 14/16] video: add STM32 MIPI DSI video driver Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 15/16] video: add support for Orise Technology otm8009a panel Ahmad Fatoum
2025-06-06  5:57 ` [PATCH v2 16/16] ARM: stm32mp: dk2: enable MIPI-DSI display by default Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250606055748.1990383-7-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox