@@ -523,9 +523,50 @@ def write_pinctrl_nodes(self, outputfile):
523523 soc_dtsi .write ("};\n \n " )
524524 soc_dtsi .close ()
525525
526+ def write_pinctrl_header (self , outfile ):
527+ """
528+ Write pinctrl header to disk in a format suitable for inclusion into
529+ DTSI file
530+ @param outfile: output file destination
531+ """
532+ try :
533+ soc_header = open (outfile , "w" , encoding = 'utf8' )
534+ except IOError :
535+ print (f"Could not write to file { outfile } " )
536+ return
537+ # Start by writing header
538+ soc_header .write (self ._header )
539+ # Write documentation block
540+ soc_header .write ("/*\n "
541+ " * SOC level pinctrl defintions\n "
542+ " * These definitions define SOC level defaults for each pin,\n "
543+ " * and select the pinmux for the pin. Pinmux entries are a tuple of:\n "
544+ " * <mux_register mux_mode input_register input_daisy config_register>\n "
545+ " * the mux_register and input_daisy reside in the IOMUXC peripheral, and\n "
546+ " * the pinctrl driver will write the mux_mode and input_daisy values into\n "
547+ " * each register, respectively. The config_register is used to configure\n "
548+ " * the pin based on the devicetree properties set\n "
549+ " */\n \n " )
550+ for pin in sorted (self ._signal_map .values ()):
551+ for iomux_opt in sorted (pin .get_mux_options ()):
552+ # Get iomuxc constant values
553+ iomuxc_name = iomux_opt .get_name ()
554+ register = iomux_opt .get_mux_reg ()
555+ mode = iomux_opt .get_mux_val ()
556+ input_reg = iomux_opt .get_daisy_reg ()
557+ input_daisy = iomux_opt .get_daisy_val ()
558+ config_reg = iomux_opt .get_cfg_reg ()
559+ header_line = (f"#define { iomuxc_name } 0x{ register :x} { mode :d} "
560+ f" 0x{ input_reg :x} { input_daisy :d} 0x{ config_reg :x} \n " )
561+ soc_header .write (header_line )
562+ soc_header .write ("\n " )
563+ soc_header .close ()
564+
565+
526566 def write_pinctrl_overrides (self , mexfile , outputfile ):
527567 """
528- Write pinctrl overrides to disk as a parsed DTS file
568+ Write pinctrl overrides to disk as a parsed DTS file. Intended for use
569+ with the output of @ref write_pinctrl_nodes
529570 @param mexfile: mex file to parse for pin configuration
530571 @param outputfile: file to write dts to
531572 """
@@ -564,6 +605,54 @@ def write_pinctrl_overrides(self, mexfile, outputfile):
564605 dts_file .write (dts_entry )
565606 # DTS file write is done, close it
566607 dts_file .close ()
608+
609+ def write_pinctrl_groups (self , mexfile , outputfile ):
610+ """
611+ Write pinctrl groups to disk as a parsed DTS file. Intended for use
612+ with the output of @ref write_pinctrl_header
613+ """
614+ if self ._signal_map is None :
615+ print ("Cannot write pinctrl groups without a signal map" )
616+ try :
617+ config_tree = ET .parse (mexfile )
618+ except ET .ParseError :
619+ print (f"Malformed XML tree { mexfile } " )
620+ return
621+ except IOError :
622+ print (f"File { mexfile } could not be opened" )
623+ return
624+ try :
625+ dts_file = open (outputfile , "w" , encoding = 'utf8' )
626+ except IOError :
627+ print (f"Could not write to file { outputfile } " )
628+ return
629+ # Parse the mex file
630+ pin_groups = self ._parse_mex_cfg (config_tree , self ._signal_map )
631+ # Start by writing header
632+ dts_file .write (self ._header )
633+ dts_file .write (f"#include <nxp/nxp_imx/rt/{ self .get_soc ().lower ()} -iomuxc.h>\n \n " )
634+ dts_file .write ("&pinctrl {\n " )
635+ for pin_group in sorted (pin_groups .keys ()):
636+ pins = pin_groups [pin_group ]
637+ # Write pin group name
638+ dts_file .write (f"\t { pin_group } : { pin_group } {{\n " )
639+ for pin in sorted (pins .keys ()):
640+ props = pins [pin ]
641+ iomux = props ['mux' ]
642+ overrides = props ['overrides' ]
643+ defaults = props ['defaults' ]
644+ dts_entry = f"\t \t { pin } : { pin } {{\n "
645+ dts_entry += f"\t \t \t pinmux = <{ iomux .get_name ()} >;\n "
646+ dts_strings = self ._props_to_dts (overrides , defaults )
647+ for entry in sorted (dts_strings ):
648+ dts_entry += f"\t \t \t { entry } ;\n "
649+ dts_entry += "\t \t };\n \n "
650+ dts_file .write (dts_entry )
651+ # Write closing brace of pin group
652+ dts_file .write ("\t };\n \n " )
653+ # Write closing brace of pinctrl node
654+ dts_file .write ("};\n \n " )
655+
567656
568657 """
569658 Private class methods
0 commit comments