Skip to contentSkip to conversation

dtoc: Support multiple compatible strings in a node

PATCH New Simon Glass 3 participants 4 messages Jun 14, 2017 – Jun 15, 2017 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 dtoc: Support multiple compatible strings in a node

Sometimes a node will have multiple compatible strings. Drivers may use one or the other so the best approach seems to be to #define them to be equivalent.

Update dtoc to support this.

---

Changes in v2:
- Put the #defines in the header file
- Add the required dtd_ prefix to the #defines

 doc/driver-model/of-plat.txt |  5 +++++
 tools/dtoc/dtoc.py           | 28 +++++++++++++++++++++-------
 2 files changed, 26 insertions(+), 7 deletions(-)
doc/driver-model/of-plat.txt +5 -0
index 0063bfe510..3ed8c759d6 100644
@@ -156,6 +156,11 @@ This avoids the code overhead of converting the device tree data to
 platform data in the driver. The ofdata_to_platdata() method should
 therefore do nothing in such a driver.
 
+Where a node has multiple compatible strings, a #define is used to make them
+equivalent, e.g.:
+
+#define dtd_rockchip_rk3299_dw_mshc dtd_rockchip_rk3288_dw_mshc
+
 
 Converting of-platdata to a useful form
 ---------------------------------------
tools/dtoc/dtoc.py +21 -7
index 08e35f148c..c0ab13ad34 100755
@@ -88,6 +88,7 @@ class DtbPlatdata:
         self._phandle_node = {}
         self._outfile = None
         self._lines = []
+        self._aliases = {}
 
     def SetupOutput(self, fname):
         """Set up the output destination
@@ -159,9 +160,10 @@ class DtbPlatdata:
             C identifier for the first compatible string
         """
         compat = node.props['compatible'].value
+        aliases = []
         if type(compat) == list:
-            compat = compat[0]
-        return Conv_name_to_c(compat)
+            compat, aliases = compat[0], compat[1:]
+        return Conv_name_to_c(compat), [Conv_name_to_c(a) for a in aliases]
 
     def ScanDtb(self):
         """Scan the device tree to obtain a tree of notes and properties
@@ -239,7 +241,7 @@ class DtbPlatdata:
         """
         structs = {}
         for node in self._valid_nodes:
-            node_name = self.GetCompatName(node)
+            node_name, _ = self.GetCompatName(node)
             fields = {}
 
             # Get a list of all the valid properties in this node.
@@ -263,12 +265,17 @@ class DtbPlatdata:
 
         upto = 0
         for node in self._valid_nodes:
-            node_name = self.GetCompatName(node)
+            node_name, _ = self.GetCompatName(node)
             struct = structs[node_name]
             for name, prop in node.props.items():
                 if name not in PROP_IGNORE_LIST and name[0] != '#':
                     prop.Widen(struct[name])
             upto += 1
+
+            struct_name, aliases = self.GetCompatName(node)
+            for alias in aliases:
+                self._aliases[alias] = struct_name
+
         return structs
 
     def ScanPhandles(self):
@@ -327,13 +334,17 @@ class DtbPlatdata:
                 self.Out(';\n')
             self.Out('};\n')
 
+        for alias, struct_name in self._aliases.iteritems():
+            self.Out('#define %s%s %s%s\n'% (STRUCT_PREFIX, alias,
+                                             STRUCT_PREFIX, struct_name))
+
     def OutputNode(self, node):
         """Output the C code for a node
 
         Args:
             node: node to output
         """
-        struct_name = self.GetCompatName(node)
+        struct_name, _ = self.GetCompatName(node)
         var_name = Conv_name_to_c(node.name)
         self.Buf('static struct %s%s %s%s = {\n' %
             (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name))
@@ -384,8 +395,11 @@ class DtbPlatdata:
         """Generate device defintions for the platform data
 
         This writes out C platform data initialisation data and
-        U_BOOT_DEVICE() declarations for each valid node. See the
-        documentation in README.of-plat for more information.
+        U_BOOT_DEVICE() declarations for each valid node. Where a node has
+        multiple compatible strings, a #define is used to make them equivalent.
+
+        See the documentation in doc/driver-model/of-plat.txt for more
+        information.
         """
         self.Out('#include <common.h>\n')
         self.Out('#include <dm.h>\n')
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
#1 lore raw

PATCH v2 2/2 WIP: Test patch for dtoc

This patch is just for testing.

---

Changes in v2: None

 arch/arm/dts/rk3399.dtsi         | 5 ++++-
 configs/firefly-rk3399_defconfig | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)
arch/arm/dts/rk3399.dtsi +4 -1
index 7f1fc50f38..2ee4bd6872 100644
@@ -260,6 +260,7 @@
 	};
 
 	sdmmc: dwmmc at fe320000 {
+		u-boot,dm-pre-reloc;
 		compatible = "rockchip,rk3399-dw-mshc",
 			     "rockchip,rk3288-dw-mshc";
 		reg = <0x0 0xfe320000 0x0 0x4000>;
@@ -272,7 +273,9 @@
 		power-domains = <&power RK3399_PD_SD>;
 		resets = <&cru SRST_SDMMC>;
 		reset-names = "reset";
-		status = "disabled";
+		status = "okay";
+                bus-width = <8>;
+                clock-freq-min-max = <0 0>;
 	};
 
 	sdhci: sdhci at fe330000 {
configs/firefly-rk3399_defconfig +1 -0
index 0a4d005975..d6fae3a02d 100644
@@ -63,3 +63,4 @@ CONFIG_USB_EHCI_GENERIC=y
 CONFIG_USB_STORAGE=y
 CONFIG_USE_TINY_PRINTF=y
 CONFIG_ERRNO_STR=y
+CONFIG_MMC_DW_ROCKCHIP=y
Signature · 1 line
2.13.1.508.gb3defc5cc-goog
#2 lore raw

PATCH v2 1/2 dtoc: Support multiple compatible strings in a node

In reply to Simon Glass

Hi Simon,

Quoted 7 lines · Simon Glass

Sometimes a node will have multiple compatible strings. Drivers may use one or the other so the best approach seems to be to #define them to be equivalent.

Update dtoc to support this.

This patch works on firefly-rk3399 board,

Thanks,
- Kever

Quoted 112 lines

---

Changes in v2:
- Put the #defines in the header file
- Add the required dtd_ prefix to the #defines

  doc/driver-model/of-plat.txt |  5 +++++
  tools/dtoc/dtoc.py           | 28 +++++++++++++++++++++-------
  2 files changed, 26 insertions(+), 7 deletions(-)
doc/driver-model/of-plat.txt +5 -0
index 0063bfe510..3ed8c759d6 100644
@@ -156,6 +156,11 @@ This avoids the code overhead of converting the device tree data to
  platform data in the driver. The ofdata_to_platdata() method should
  therefore do nothing in such a driver.
 
+Where a node has multiple compatible strings, a #define is used to make them
+equivalent, e.g.:
+
+#define dtd_rockchip_rk3299_dw_mshc dtd_rockchip_rk3288_dw_mshc
+
 
  Converting of-platdata to a useful form
  ---------------------------------------
tools/dtoc/dtoc.py +21 -7
index 08e35f148c..c0ab13ad34 100755
@@ -88,6 +88,7 @@ class DtbPlatdata:
          self._phandle_node = {}
          self._outfile = None
          self._lines = []
+        self._aliases = {}
 
      def SetupOutput(self, fname):
          """Set up the output destination
@@ -159,9 +160,10 @@ class DtbPlatdata:
              C identifier for the first compatible string
          """
          compat = node.props['compatible'].value
+        aliases = []
          if type(compat) == list:
-            compat = compat[0]
-        return Conv_name_to_c(compat)
+            compat, aliases = compat[0], compat[1:]
+        return Conv_name_to_c(compat), [Conv_name_to_c(a) for a in aliases]
 
      def ScanDtb(self):
          """Scan the device tree to obtain a tree of notes and properties
@@ -239,7 +241,7 @@ class DtbPlatdata:
          """
          structs = {}
          for node in self._valid_nodes:
-            node_name = self.GetCompatName(node)
+            node_name, _ = self.GetCompatName(node)
              fields = {}
 
              # Get a list of all the valid properties in this node.
@@ -263,12 +265,17 @@ class DtbPlatdata:
 
          upto = 0
          for node in self._valid_nodes:
-            node_name = self.GetCompatName(node)
+            node_name, _ = self.GetCompatName(node)
              struct = structs[node_name]
              for name, prop in node.props.items():
                  if name not in PROP_IGNORE_LIST and name[0] != '#':
                      prop.Widen(struct[name])
              upto += 1
+
+            struct_name, aliases = self.GetCompatName(node)
+            for alias in aliases:
+                self._aliases[alias] = struct_name
+
          return structs
 
      def ScanPhandles(self):
@@ -327,13 +334,17 @@ class DtbPlatdata:
                  self.Out(';\n')
              self.Out('};\n')
 
+        for alias, struct_name in self._aliases.iteritems():
+            self.Out('#define %s%s %s%s\n'% (STRUCT_PREFIX, alias,
+                                             STRUCT_PREFIX, struct_name))
+
      def OutputNode(self, node):
          """Output the C code for a node
 
          Args:
              node: node to output
          """
-        struct_name = self.GetCompatName(node)
+        struct_name, _ = self.GetCompatName(node)
          var_name = Conv_name_to_c(node.name)
          self.Buf('static struct %s%s %s%s = {\n' %
              (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name))
@@ -384,8 +395,11 @@ class DtbPlatdata:
          """Generate device defintions for the platform data
 
          This writes out C platform data initialisation data and
-        U_BOOT_DEVICE() declarations for each valid node. See the
-        documentation in README.of-plat for more information.
+        U_BOOT_DEVICE() declarations for each valid node. Where a node has
+        multiple compatible strings, a #define is used to make them equivalent.
+
+        See the documentation in doc/driver-model/of-plat.txt for more
+        information.
          """
          self.Out('#include <common.h>\n')
          self.Out('#include <dm.h>\n')
#3 lore raw

PATCH v2 1/2 dtoc: Support multiple compatible strings in a node

Hi Simon,

Quoted 7 lines · Simon Glass

Sometimes a node will have multiple compatible strings. Drivers may use one or the other so the best approach seems to be to #define them to be equivalent.

Update dtoc to support this.

This patch works on firefly-rk3399 board,

Thanks,
- Kever

Quoted 10 lines

---

Changes in v2:
- Put the #defines in the header file
- Add the required dtd_ prefix to the #defines

  doc/driver-model/of-plat.txt |  5 +++++
  tools/dtoc/dtoc.py           | 28 +++++++++++++++++++++-------
  2 files changed, 26 insertions(+), 7 deletions(-)

Applied to u-boot-dm, thanks!