public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Frank Rowand <frowand.list@gmail.com>
To: Grant Likely <grant.likely@linaro.org>,
	Rob Herring <robh+dt@kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	Linux Kernel list <linux-kernel@vger.kernel.org>,
	Josh Cartwright <joshc@codeaurora.org>,
	Courtney Cavin <courtney.cavin@sonymobile.com>
Cc: Samuel Ortiz <sameo@linux.intel.com>,
	Lee Jones <lee.jones@linaro.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [RFC PATCH 3/3] devicetree, qcomm PMIC: use new hook to make PMIC device names unique
Date: Tue, 06 May 2014 17:53:51 -0700	[thread overview]
Message-ID: <5369841F.5060805@gmail.com> (raw)
In-Reply-To: <536982E3.10303@gmail.com>

From: Frank Rowand <frank.rowand@sonymobile.com>

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@sonymobile.com>
---
 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);
 }
 

  parent reply	other threads:[~2014-05-07  0:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-07  0:48 [RFC PATCH 0/3] devicetree, qcomm PMIC: fix node name conflict Frank Rowand
2014-05-07  0:51 ` [RFC PATCH 1/3] devicetree: set bus type same as parent Frank Rowand
2014-05-07 15:17   ` Grant Likely
2014-05-07  0:52 ` [RFC PATCH 2/3] devicetree: provide hook to allow setting devicetree device name Frank Rowand
2014-05-07 15:21   ` Grant Likely
2014-05-07  0:53 ` Frank Rowand [this message]
2014-05-07  1:32 ` [RFC PATCH 0/3] devicetree, qcomm PMIC: fix node name conflict Rob Herring
2014-05-07  2:49   ` Frank Rowand
2014-05-07 14:51   ` Grant Likely
2014-05-07 15:12   ` Bjorn Andersson
2014-05-07 16:08     ` Rob Herring

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=5369841F.5060805@gmail.com \
    --to=frowand.list@gmail.com \
    --cc=courtney.cavin@sonymobile.com \
    --cc=devicetree@vger.kernel.org \
    --cc=grant.likely@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=joshc@codeaurora.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sameo@linux.intel.com \
    /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