From mboxrd@z Thu Jan 1 00:00:00 1970 From: Frank Rowand 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 Message-ID: <5369841F.5060805@gmail.com> References: <536982E3.10303@gmail.com> Reply-To: frowand.list@gmail.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <536982E3.10303@gmail.com> Sender: linux-kernel-owner@vger.kernel.org To: Grant Likely , Rob Herring , "devicetree@vger.kernel.org" , Linux Kernel list , Josh Cartwright , Courtney Cavin Cc: Samuel Ortiz , Lee Jones , Greg Kroah-Hartman List-Id: devicetree@vger.kernel.org From: Frank Rowand 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 --- 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 #include #include +#include #include 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); }