Re: [RFC] dt: add of_platform_bus_snoop() which attaches nodes to devices
Hi Grant, On 1 February 2011 03:31, Grant Likely grant.lik...@secretlab.ca wrote: This patch implements an alternate method for using device tree data for populating machine device registration. Traditionally, board support has directly generated and registered devices based on nodes in the device tree. The board support code starts at the root of the tree and begins allocating devices for each device node it finds. Similarly, bus drivers (i2c, spi, etc.) use their child nodes to register child devices. This model can be seen in almost all the powerpc board ports (arch/powerpc/platforms/*). However, for many of the ARM SoCs, there already exists complete board support for many SoCs that have their own code for registering the basic set of platform devices with non-trivial dependencies on clock structure and machine specific platform code. While starting at the base of the tree and working up is certainly possible, it requires modifying a lot of machine support code to get it working. Instead, this patch provides an alternate approach. Instead of starting at the root of the tree and working up, this patch allows the SoC support code to register its standard set of platform devices in the normal way. However, it also registers a platform_bus notifier function which compares platform_device registrations with data in the device tree. Whenever it finds a matching node, it increments the node reference count and assigns it to the device's of_node pointer so that it is available for the device driver to use and bind against. For example, an spi master driver would have access to the spi node which contains information about all the spi slaves on the bus. An example usage of this facility is to allow a single 'devicetree' board support file to support multiple machines all using the same SoC. The common code would register SoC devices unconditionally, and the board support code would depend entirely on device tree data. Note: Board ports using this facility are still required to provide a fully populated device tree blob. It is not a shortcut to providing an accurate device tree model of the machine to the point that it would be reasonably possible to switch to a direct registration model for all devices without change the device tree. ie. The SoC still needs to be correctly identified and there should be nodes for all the discrete devices. I'm not convinced that this is the model to pursue over the long term, but it greatly simplifies the task of getting device tree support up and running, and it provides a migration path to full dt device registration (if it makes sense to do so). Signed-off-by: Grant Likely grant.lik...@secretlab.ca --- I have used this patch for Samsung's smdkv310 board and it works fine. There are 4 uart port nodes in the dts file and the platform devices for the 4 uart ports (which are instantiated in the platform code) get the of_node pointer when the of_platform_bus_snoop function is used. The driver then is able to pick up information from the device node. The tough part, though, is moving the existing platform data into the device tree and having the driver parse that data from the device node. Regards, Thomas. ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [RFC] dt: add of_platform_bus_snoop() which attaches nodes to devices
On Mon, Jan 31, 2011 at 3:01 PM, Grant Likely grant.lik...@secretlab.ca wrote: This patch implements an alternate method for using device tree data for populating machine device registration. Traditionally, board support has directly generated and registered devices based on nodes in the device tree. The board support code starts at the root of the tree and begins allocating devices for each device node it finds. Similarly, bus drivers (i2c, spi, etc.) use their child nodes to register child devices. This model can be seen in almost all the powerpc board ports (arch/powerpc/platforms/*). However, for many of the ARM SoCs, there already exists complete board support for many SoCs that have their own code for registering the basic set of platform devices with non-trivial dependencies on clock structure and machine specific platform code. While starting at the base of the tree and working up is certainly possible, it requires modifying a lot of machine support code to get it working. Instead, this patch provides an alternate approach. Instead of starting at the root of the tree and working up, this patch allows the SoC support code to register its standard set of platform devices in the normal way. However, it also registers a platform_bus notifier function which compares platform_device registrations with data in the device tree. Whenever it finds a matching node, it increments the node reference count and assigns it to the device's of_node pointer so that it is available for the device driver to use and bind against. For example, an spi master driver would have access to the spi node which contains information about all the spi slaves on the bus. One more note. It might also be a good idea to do something like this for the PCI and AMBA buses. I've not yet looked at how much code could be made common for implementing that. g. ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
[RFC] dt: add of_platform_bus_snoop() which attaches nodes to devices
This patch implements an alternate method for using device tree data for populating machine device registration. Traditionally, board support has directly generated and registered devices based on nodes in the device tree. The board support code starts at the root of the tree and begins allocating devices for each device node it finds. Similarly, bus drivers (i2c, spi, etc.) use their child nodes to register child devices. This model can be seen in almost all the powerpc board ports (arch/powerpc/platforms/*). However, for many of the ARM SoCs, there already exists complete board support for many SoCs that have their own code for registering the basic set of platform devices with non-trivial dependencies on clock structure and machine specific platform code. While starting at the base of the tree and working up is certainly possible, it requires modifying a lot of machine support code to get it working. Instead, this patch provides an alternate approach. Instead of starting at the root of the tree and working up, this patch allows the SoC support code to register its standard set of platform devices in the normal way. However, it also registers a platform_bus notifier function which compares platform_device registrations with data in the device tree. Whenever it finds a matching node, it increments the node reference count and assigns it to the device's of_node pointer so that it is available for the device driver to use and bind against. For example, an spi master driver would have access to the spi node which contains information about all the spi slaves on the bus. An example usage of this facility is to allow a single 'devicetree' board support file to support multiple machines all using the same SoC. The common code would register SoC devices unconditionally, and the board support code would depend entirely on device tree data. Note: Board ports using this facility are still required to provide a fully populated device tree blob. It is not a shortcut to providing an accurate device tree model of the machine to the point that it would be reasonably possible to switch to a direct registration model for all devices without change the device tree. ie. The SoC still needs to be correctly identified and there should be nodes for all the discrete devices. I'm not convinced that this is the model to pursue over the long term, but it greatly simplifies the task of getting device tree support up and running, and it provides a migration path to full dt device registration (if it makes sense to do so). Signed-off-by: Grant Likely grant.lik...@secretlab.ca --- This patch can be found in my devicetree/test branch (frequently rebased) git://git.secretlab.ca/git/linux-2.6 devicetree/test I'll move it to devicetree/arm (never rebased) once it is stable. g. arch/arm/mach-versatile/core.c |3 + drivers/of/address.c | 14 ++ drivers/of/base.c |3 + drivers/of/platform.c | 230 include/linux/of_address.h |1 include/linux/of_platform.h|2 6 files changed, 253 insertions(+), 0 deletions(-) diff --git a/arch/arm/mach-versatile/core.c b/arch/arm/mach-versatile/core.c index 136c32e..86ad01d 100644 --- a/arch/arm/mach-versatile/core.c +++ b/arch/arm/mach-versatile/core.c @@ -21,6 +21,7 @@ #include linux/init.h #include linux/device.h #include linux/dma-mapping.h +#include linux/of_platform.h #include linux/platform_device.h #include linux/sysdev.h #include linux/interrupt.h @@ -873,6 +874,8 @@ void __init versatile_init(void) clkdev_add_table(lookups, ARRAY_SIZE(lookups)); + of_platform_bus_snoop(NULL, NULL); + platform_device_register(versatile_flash_device); platform_device_register(versatile_i2c_device); platform_device_register(smc91x_device); diff --git a/drivers/of/address.c b/drivers/of/address.c index b4559c5..b43ff66 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -556,6 +556,20 @@ static int __of_address_to_resource(struct device_node *dev, } /** + * of_address_count - Return the number of entries in the reg property + */ +int of_address_count(struct device_node *np) +{ + struct resource temp_res; + int num_reg = 0; + + while (of_address_to_resource(np, num_reg, temp_res) == 0) + num_reg++; + return num_reg; +} +EXPORT_SYMBOL_GPL(of_address_count); + +/** * of_address_to_resource - Translate device tree address and return as resource * * Note that if your address is a PIO address, the conversion will fail if diff --git a/drivers/of/base.c b/drivers/of/base.c index 710b53b..632ebae 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -496,6 +496,9 @@ EXPORT_SYMBOL(of_find_node_with_property); const struct of_device_id *of_match_node(const struct of_device_id *matches, const struct device_node *node) { + if (!matches) +