Re: How to inject fwnode/oftree/acpi data by platform driver ?

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

 



Hi,

On Tue, Jun 11, 2019 at 09:44:23PM +0300, Andy Shevchenko wrote:
> +Cc: Heikki.
> Heikki, can you help here with swnodes?
> 
> On Sat, Jun 1, 2019 at 5:17 PM Enrico Weigelt, metux IT consult
> <lkml@xxxxxxxxx> wrote:
> >
> > Hi folks,
> >
> >
> > I'm looking for a way to inject fwnode data from a platform driver,
> > in order to initialize generic drivers w/ board specific configuration.
> > The idea is getting rid of passing driver specific pdata structs
> > (which, IIRC, seem to be deprecated).
> >
> > An example usecase is the APUv2/3 board, which have things like gpios
> > wired to buttons and LEDs. The board can only be detected via DMI
> > string, no way to probe the platform devices - have to be initialized
> > explicitly (that's how I'm already doing it now).
> >
> > The nicest way, IMHO, would be if I could just write some piece of DTS
> > and some fancy magic all the rest under the hood. Such thing doesn't
> > seem to exist yet. Does it make sense to implement that ? How could
> > we do it ?
> >
> > Which other options do we have ?
> >
> > Or should we just leave everything as it is and stick w/ pdata structs ?

The software nodes (drivers/base/swnode.c) were designed to supply
fwnodes that describe devices in the same way DT does. The goal I had
with the software nodes was exaclty to get rid of pdata, so they do
sound like the thing you are looking for. If you check Rafael's latest
linux-next branch [1], drivers/platform/x86/intel_cht_int33fe.c can be
used as an example how to use the software nodes.

I think it's time to add documentation for the software nodes to the
kernel, but I'll list here the features the software nodes have:

- The software nodes are created independently from device entries.
- Software nodes support hierarchy. Every software node has a pointer
  to a parent software node.
- Software nodes can have device properties.
- Software nodes can have reference pointers to other software nodes
  (outside of the hierarchy).

Creating the software nodes from static description (struct
software_node - available from Linux kernel v5.3 onwards) is
straightforward. Once you have them, when you create your device
entries (struct device), you can associate a software node with a
device just like like any other fwnode:

        device_initialize(&my_dev);
        my_dev.parent = parent;
        my_dev.fwnode = software_node_fwnode(&my_node);
        ...
        device_add(&my_device);

After that, you can access all the information the software nodes
supply to the device by using fwnode_* APIs from your driver, just
like with ACPI or DT. Basically the entire fwnode_* API is now
supported with softwarw nodes, except the device graph (fwnode_graph*)
API.

One final note. The hardware description must always primarily come
from the system firmware. You only use software nodes if it's too
late to influence what goes to the ACPI tables, or if using DTS is not
an option.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git/log/?h=linux-next

thanks,

-- 
heikki



[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