diff mbox series

[02/17] dtoc: Use a namedtuple for _links

Message ID 20201003152534.3184504-3-sjg@chromium.org
State Accepted
Commit 97136eb5354c28c475cd2fb72d5cc1029ce9e743
Delegated to: Simon Glass
Headers show
Series dm: test: Add unit tests for SPL | expand

Commit Message

Simon Glass Oct. 3, 2020, 3:25 p.m. UTC
The use of strings to access a dict is a bit ugly. Use a namedtuple for
this instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Simon Glass Oct. 27, 2020, 1:01 a.m. UTC | #1
The use of strings to access a dict is a bit ugly. Use a namedtuple for
this instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/dtoc/dtb_platdata.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index bd1daa4379a..1b52198a943 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -54,6 +54,13 @@  VAL_PREFIX = 'dtv_'
 #     phandles is len(args). This is a list of integers.
 PhandleInfo = collections.namedtuple('PhandleInfo', ['max_args', 'args'])
 
+# Holds a single phandle link, allowing a C struct value to be assigned to point
+# to a device
+#
+# var_node: C variable to assign (e.g. 'dtv_mmc.clocks[0].node')
+# dev_name: Name of device to assign to (e.g. 'clock')
+PhandleLink = collections.namedtuple('PhandleLink', ['var_node', 'dev_name'])
+
 
 def conv_name_to_c(name):
     """Convert a device-tree name to a C identifier
@@ -146,7 +153,8 @@  class DtbPlatdata(object):
             key: Driver alias declared with
                 U_BOOT_DRIVER_ALIAS(driver_alias, driver_name)
             value: Driver name declared with U_BOOT_DRIVER(driver_name)
-        _links: List of links to be included in dm_populate_phandle_data()
+        _links: List of links to be included in dm_populate_phandle_data(),
+            each a PhandleLink
         _drivers_additional: List of additional drivers to use during scanning
     """
     def __init__(self, dtb_fname, include_disabled, warning_disabled,
@@ -593,7 +601,7 @@  class DtbPlatdata(object):
                                 (VAL_PREFIX, var_name, member_name, item)
                     # Save the the link information to be use to define
                     # dm_populate_phandle_data()
-                    self._links.append({'var_node': var_node, 'dev_name': name})
+                    self._links.append(PhandleLink(var_node, name))
                     item += 1
                 for val in vals:
                     self.buf('\n\t\t%s,' % val)
@@ -669,9 +677,9 @@  class DtbPlatdata(object):
         # nodes using DM_GET_DEVICE
         # dtv_dmc_at_xxx.clocks[0].node = DM_GET_DEVICE(clock_controller_at_xxx)
         self.buf('void dm_populate_phandle_data(void) {\n')
-        for l in self._links:
+        for link in self._links:
             self.buf('\t%s = DM_GET_DEVICE(%s);\n' %
-                     (l['var_node'], l['dev_name']))
+                     (link.var_node, link.dev_name))
         self.buf('}\n')
 
         self.out(''.join(self.get_buf()))