devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tomeu Vizoso <tomeu.vizoso@collabora.com>
To: Rob Herring <robherring2@gmail.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Stephen Warren <swarren@wwwdotorg.org>,
	Javier Martinez Canillas <javier@osg.samsung.com>,
	Mark Brown <broonie@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
	Arnd Bergmann <arnd@arndb.de>, Rob Herring <robh+dt@kernel.org>,
	Grant Likely <grant.likely@linaro.org>
Subject: Re: [PATCH v2 04/22] of/platform: add of_platform_device_find()
Date: Tue, 28 Jul 2015 15:54:54 +0200	[thread overview]
Message-ID: <CAAObsKBfRLdPc0gs55ARfa+qZJAOEyEgRyTf8krZnQMb6-j03g@mail.gmail.com> (raw)
In-Reply-To: <CAL_JsqJGhFXDKuayuKc2E58X5A7ZGN=uYCVDLnXw_t3_auBg+w@mail.gmail.com>

On 28 July 2015 at 15:39, Rob Herring <robherring2@gmail.com> wrote:
> On Tue, Jul 28, 2015 at 8:19 AM, Tomeu Vizoso
> <tomeu.vizoso@collabora.com> wrote:
>> From an arbitrary node in the tree, find the enclosing node that
>> corresponds to a platform device, as registered by
>> of_platform_populate().
>>
>> This can be used to find out what device needs to be probed so the
>> dependency described by a given node is made available.
>>
>> Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
>> ---
>>
>> Changes in v2:
>> - Move the logic for finding a platform device from its firmware node to
>>   of/platform.c as it's not needed for ACPI nodes.
>>
>>  drivers/of/platform.c       | 60 +++++++++++++++++++++++++++++++++++++++++++++
>>  include/linux/of_platform.h |  1 +
>>  2 files changed, 61 insertions(+)
>>
>> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
>> index ff27494cda8c..89c5cd513027 100644
>> --- a/drivers/of/platform.c
>> +++ b/drivers/of/platform.c
>> @@ -501,6 +501,66 @@ void of_platform_depopulate(struct device *parent)
>>  }
>>  EXPORT_SYMBOL_GPL(of_platform_depopulate);
>>
>> +static bool of_is_platform(struct device_node *np)
>> +{
>> +       int count;
>> +
>> +       count = of_property_count_strings(np, "compatible");
>> +
>> +       /* The node has to have a compatible string */
>> +       if (!count)
>> +               return false;
>> +
>> +       /* But it cannot be just a simple memory-mapped bus */
>> +       if (count == 1 && of_match_node(of_default_bus_match_table, np))
>> +               return false;
>> +
>> +       /* But AMBA devices aren't platform devices */
>> +       if (of_device_is_compatible(np, "arm,primecell"))
>> +               return false;
>> +
>> +       /* Node is immediately below root */
>> +       if (!np->parent || !np->parent->parent)
>> +               return true;
>> +
>> +       /* If it's a node in a simple memory-mapped bus */
>> +       if (of_match_node(of_default_bus_match_table, np->parent))
>> +               return true;
>
> This seems really fragile.

I think this finding logic matches the logic for registering platform
devices in of_platform_populate and also what is documented in
Documentation/devicetree/usage-model.txt.

> What about platform devices which are
> children of MFDs but are not "simple-mfd"?

This code should deal fine with those (the boards I tested with do
have them). It probes the mfd master, and that in turn will call
mfd_add_devices causing the target device to be probed.

> Does of_find_device_by_node not work for you?

Well, the dependencies aren't always platform devices, that's why I
need to go up the tree until I find a node that corresponds to a
platform device that I can query and probe.

If I had a way to get, say, a i2c device from its fwnode then I would
just need to make sure that a device's parent is probed before probing
it and everything would be cleaner in the OF case.

> That is probably not the
> most efficient search, but we could fix that. We could add struct
> device ptr to struct device_node and check without searching for
> example.

That would be great, but I thought there was an issue with a OF node
being able to be related to more than one struct device (but I haven't
found this myself yet).

Thanks,

Tomeu

> Rob
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

  reply	other threads:[~2015-07-28 13:54 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-28 13:19 [PATCH v2 0/22] On-demand device probing Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 01/22] platform: delay device-driver matches until late_initcall Tomeu Vizoso
2015-07-30  3:20   ` Rob Herring
2015-07-31 10:06     ` Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 02/22] of/platform: Set fwnode field for new devices Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 03/22] device property: add fwnode_get_name() Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 04/22] of/platform: add of_platform_device_find() Tomeu Vizoso
2015-07-28 13:39   ` Rob Herring
2015-07-28 13:54     ` Tomeu Vizoso [this message]
2015-07-28 15:31       ` Rob Herring
2015-07-29  6:14         ` Tomeu Vizoso
     [not found]           ` <CAAObsKA+vMsgiC52jReJckeDjXhdd=_NBocFbMapdwFReiY1SQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-29 11:20             ` Tomeu Vizoso
2015-07-29 12:15               ` Tomeu Vizoso
2015-07-29 15:27               ` Rob Herring
2015-07-31 10:32                 ` Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 05/22] ACPI: add acpi_dev_get_device() Tomeu Vizoso
     [not found]   ` <1438089593-7696-6-git-send-email-tomeu.vizoso-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2015-07-30  3:08     ` Rob Herring
2015-07-28 13:19 ` [PATCH v2 06/22] device property: add fwnode_ensure_device() Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 07/22] gpio: Probe GPIO drivers on demand Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 08/22] gpio: Probe pinctrl devices " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 09/22] regulator: core: Reduce critical area in _regulator_get Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 10/22] regulator: core: Probe regulators on demand Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 11/22] drm: Probe panels " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 12/22] drm/tegra: Probe dpaux devices " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 13/22] i2c: core: Probe i2c master " Tomeu Vizoso
2015-08-09 12:34   ` Wolfram Sang
2015-08-09 13:37     ` Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 14/22] pwm: Probe PWM chip " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 15/22] backlight: Probe backlight " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 16/22] usb: phy: Probe phy " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 17/22] clk: Probe clk providers " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 18/22] pinctrl: Probe pinctrl devices " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 19/22] phy: core: Probe phy providers " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 20/22] dma: of: Probe DMA controllers " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 21/22] power-supply: Probe power supplies " Tomeu Vizoso
2015-07-28 13:19 ` [PATCH v2 22/22] ASoC: core: Probe components " Tomeu Vizoso
     [not found] ` <1438089593-7696-1-git-send-email-tomeu.vizoso-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org>
2015-07-29  0:36   ` [PATCH v2 0/22] On-demand device probing Rafael J. Wysocki
2015-07-30  3:06 ` Rob Herring
2015-07-31 10:28   ` Tomeu Vizoso

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=CAAObsKBfRLdPc0gs55ARfa+qZJAOEyEgRyTf8krZnQMb6-j03g@mail.gmail.com \
    --to=tomeu.vizoso@collabora.com \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=grant.likely@linaro.org \
    --cc=javier@osg.samsung.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=robh+dt@kernel.org \
    --cc=robherring2@gmail.com \
    --cc=swarren@wwwdotorg.org \
    --cc=thierry.reding@gmail.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;
as well as URLs for NNTP newsgroup(s).