[U-Boot] [PATCH] dm: add of_match_ptr() macro

Masahiro Yamada yamada.m at jp.panasonic.com
Tue Oct 7 07:51:31 CEST 2014


The driver model supports two ways for passing device parameters;
Device Tree and platform_data (board file).
Each driver should generally support both of them because some
popular IPs are used on various platforms.

Assume the following scenario:
  - The driver Foo is used on SoC Bar and SoC Baz
  - The SoC Bar uses Device Tree control (CONFIG_OF_CONTROL=y)
  - The SoC Baz does not support Device Tree; uses a board file

In this situation, the device driver Foo should work with/without
the device tree control.  The driver should have .of_match and
.ofdata_to_platdata members for SoC Bar, while they are meaningless
for SoC Baz; therefore those device-tree control code should go
inside #ifdef CONFIG_OF_CONTROL.

The driver code will be like this:

  #ifdef CONFIG_OF_CONTROL
  static const struct udevice_id foo_of_match = {
          { .compatible = "foo_driver" },
          {},
  }

  static int foo_ofdata_to_platdata(struct udevice *dev)
  {
          ...
  }
  #endif

  U_BOOT_DRIVER(foo_driver) = {
          ...
          .of_match = of_match_ptr(foo_of_match),
          .ofdata_to_platdata = of_match_ptr(foo_ofdata_to_platdata),
          ...
  }

This idea has been borrowed from Linux.
(In Linux, this macro is defined in include/linux/of.h)

Signed-off-by: Masahiro Yamada <yamada.m at jp.panasonic.com>
---

 include/dm/device.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/dm/device.h b/include/dm/device.h
index c8a4072..e08d496 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -96,6 +96,12 @@ struct udevice_id {
 	ulong data;
 };
 
+#ifdef CONFIG_OF_CONTROL
+#define of_match_ptr(_ptr)	(_ptr)
+#else
+#define of_match_ptr(_ptr)	NULL
+#endif /* CONFIG_OF_CONTROL */
+
 /**
  * struct driver - A driver for a feature or peripheral
  *
-- 
1.9.1



More information about the U-Boot mailing list