[RFC PATCH 3/3] devicetree, qcomm PMIC: use new hook to make PMIC device names unique

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




From: Frank Rowand <frank.rowand@xxxxxxxxxxxxxx>

The previous patch in the series does:

   Optionally push device naming into a function called dynamically by
   of_device_alloc().

This patch adds an example of using that capability.

Signed-off-by: Frank Rowand <frank.rowand@xxxxxxxxxxxxxx>
---
 drivers/mfd/pm8x41.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

Index: b/drivers/mfd/pm8x41.c
===================================================================
--- a/drivers/mfd/pm8x41.c
+++ b/drivers/mfd/pm8x41.c
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/spmi.h>
 #include <linux/regmap.h>
+#include <linux/of_address.h>
 #include <linux/of_platform.h>
 
 static const struct regmap_config pm8x41_regmap_config = {
@@ -32,6 +33,43 @@ static void pm8x41_remove(struct spmi_de
 	device_for_each_child(&sdev->dev, NULL, pm8x41_remove_child);
 }
 
+static void spmi_of_device_make_bus_id(struct device *dev)
+{
+	struct device_node *node = dev->of_node;
+	const __be32 *reg;
+	u64 addr;
+	const __be32 *addrp;
+	struct spmi_device *sdev;
+
+	sdev = container_of(dev->parent, struct spmi_device, dev);
+
+	/*
+	 * For MMIO, get the physical address
+	 */
+	reg = of_get_property(node, "reg", NULL);
+	if (reg) {
+		if (of_can_translate_address(node)) {
+			addr = of_translate_address(node, reg);
+		} else {
+			addrp = of_get_address(node, 0, NULL, NULL);
+			if (addrp)
+				addr = of_read_number(addrp, 1);
+			else
+				addr = OF_BAD_ADDR;
+		}
+		if (addr != OF_BAD_ADDR) {
+			dev_set_name(dev, "%d-%02x:%llx.%s",
+				     sdev->ctrl->nr, sdev->usid,
+				     (unsigned long long)addr, node->name);
+			return;
+		}
+	}
+
+	dev_set_name(dev, "%d-%02x:%s",
+		     sdev->ctrl->nr, sdev->usid,
+		     node->name);
+}
+
 static int pm8x41_probe(struct spmi_device *sdev)
 {
 	struct regmap *regmap;
@@ -42,6 +80,7 @@ static int pm8x41_probe(struct spmi_devi
 		return PTR_ERR(regmap);
 	}
 
+	sdev->dev.of_node->of_device_make_bus_id = spmi_of_device_make_bus_id;
 	return of_platform_populate(sdev->dev.of_node, NULL, NULL, &sdev->dev);
 }
 
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]
  Powered by Linux