diff options
author | Stephen Warren <swarren@nvidia.com> | 2014-03-06 13:06:31 -0700 |
---|---|---|
committer | Stephen Warren <swarren@nvidia.com> | 2014-04-22 16:18:35 -0600 |
commit | 2577ab08c5a84229580c83a0cd00a03328eba89b (patch) | |
tree | ad04beb34ad4e3f65564316b6a9d8ac585298095 /tegra_pmx_utils.py | |
parent | 16495973b3f18b575ed20773c788be642ffceb63 (diff) | |
download | tegra-pinmux-scripts-2577ab08c5a84229580c83a0cd00a03328eba89b.tar.gz |
Initial set of scripts
A set of scripts to generate Linux kernel and U-Boot pinmux drivers and
board pinmux configuration tables. Also included are scripts to convert
existing Linux kernel pinmux drivers and NV-internal spreadsheets to the
internal data representation.
SoC configuration files are included for Tegra30, Tegra114, and Tegra124.
Board configuration files are included for Jetson TK1 and Venice2.
configs/tegra30.soc
configs/tegra114.soc
configs/tegra124.soc
SoC pin definitions
configs/jetson-tk1.board
configs/venice2.board
Board configurations
soc-to-kernel-pinctrl-driver.py
soc-to-uboot-driver.py
Generate Linux kernel and U-Boot pinmux drivers
board-to-kernel-dt.py
board-to-uboot.py
Generate board configuration tables for the Linux kernel (DT) and
U-Boot.
kernel-pinctrl-driver-to-soc.py
Convert an existing Linux kernel pinmux driver to the internal
representation of an SoC used by this project.
csv-to-board-tegra124-xlsx.py
Convert an NV-internal board configuration spreadsheet to the
internal representation of a board configuration used by this
project.
tegra_pmx_board_parser.py
tegra_pmx_parser_utils.py
tegra_pmx_soc_parser.py
tegra_pmx_utils.py
Internal Python modules used to parse the internal data
representations, and various other utilities.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'tegra_pmx_utils.py')
-rw-r--r-- | tegra_pmx_utils.py | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/tegra_pmx_utils.py b/tegra_pmx_utils.py new file mode 100644 index 0000000..0635ab8 --- /dev/null +++ b/tegra_pmx_utils.py @@ -0,0 +1,126 @@ +# Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +import sys + +def emit_tab_padding_to(curpos, targetpos): + curpos -= 1 + targetpos -= 1 + if (targetpos & 7): + raise Exception(str(targetpos) + ' is not a TAB stop') + left = targetpos - curpos + tabs = (left + 7) // 8 + print('\t' * tabs, end='') + +def emit_padded_field(s, maxl, skip_comma=False, right_justify=False, file=sys.stdout): + pad = (' ' * (maxl - len(s))) + if right_justify: + print(pad, file=file, end='') + print(s, file=file, end='') + if skip_comma: + return + print(', ', file=file, end='') + if not right_justify: + print(pad, file=file, end='') + +def emit_define(define, value, valuecol): + s = '#define ' + define + print(s, end='') + emit_tab_padding_to(len(s) + 1, valuecol) + print(value) + +def yn_to_boolean(s): + return {'N': False, 'Y': True}[s] + +def boolean_to_yn(val): + return {True: 'Y', False: 'N'}[val] + +def dump_table(heading_prefix, heading_suffix, headings, row_prefix, row_suffix, rows, col_widths, file, right_justifies): + num_cols = 0 + if headings: + num_cols = max(num_cols, len(headings)) + if col_widths: + num_cols = max(num_cols, len(col_widths)) + for row in rows: + if type(row) == str: + continue + num_cols = max(num_cols, len(row)) + widths = [0] * num_cols + + if col_widths: + for col, val in enumerate(col_widths): + if not val: + continue + widths[col] = val + + if headings: + for col, val in enumerate(headings): + if col_widths and col_widths[col]: + continue + widths[col] = len(val) + + for row in rows: + if type(row) == str: + continue + for col, val in enumerate(row): + if col_widths and col_widths[col]: + continue + widths[col] = max(widths[col], len(val)) + + if headings: + print(heading_prefix, end='', file=file) + for col, heading in enumerate(headings): + emit_padded_field(heading, widths[col], skip_comma = (col == len(headings) - 1), file=file) + print(heading_suffix, file=file) + + for row in rows: + if type(row) == str: + print(row, file=file) + else: + print(row_prefix, end='', file=file) + force_comma = len(row) == 1 + for col, val in enumerate(row): + if right_justifies: + right_justify = right_justifies[col] + else: + right_justify = False + emit_padded_field(val, widths[col], skip_comma = (col == len(row) - 1) and not force_comma, file=file, right_justify=right_justify) + print(row_suffix, file=file) + +def dump_py_table(headings, rows, col_widths=None, file=sys.stdout, right_justifies=None): + dump_table(' #', '', headings, ' (', '),', rows, col_widths, file, right_justifies) + +def dump_c_table(headings, macro_name, rows, col_widths=None, file=sys.stdout, right_justifies=None, row_indent='\t'): + dump_table(row_indent + '/* ' + ' ' * (len(macro_name) - 2), ' */', headings, row_indent + macro_name + '(', '),', rows, col_widths, file, right_justifies) + +def spreadsheet_col_name_to_num(col): + if len(col) == 2: + return ((ord(col[0]) - ord('A') + 1) * 26) + (ord(col[1]) - ord('A')) + elif len(col) == 1: + return ord(col[0]) - ord('A') + else: + raise Exception('Bad column name ' + col) + +def rsvd_0base_to_1base(f): + if not f.startswith('rsvd'): + return f + n = int(f[4:]) + n += 1 + return 'rsvd' + str(n) |