aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Griffis2016-12-08 11:01:50 -0600
committerBrad Griffis2016-12-08 11:01:50 -0600
commit91f308a3df7281d1969ee7faad2ebdfee8c57979 (patch)
tree1a771b92297b73fca345c3d7901dfb17a584909e /am57xx_generate_pin_config_data.pl
downloadam57xx_uboot_pin_config-91f308a3df7281d1969ee7faad2ebdfee8c57979.tar.gz
am57xx_uboot_pin_config-91f308a3df7281d1969ee7faad2ebdfee8c57979.tar.xz
am57xx_uboot_pin_config-91f308a3df7281d1969ee7faad2ebdfee8c57979.zip
From Steve K
Diffstat (limited to 'am57xx_generate_pin_config_data.pl')
-rwxr-xr-xam57xx_generate_pin_config_data.pl325
1 files changed, 325 insertions, 0 deletions
diff --git a/am57xx_generate_pin_config_data.pl b/am57xx_generate_pin_config_data.pl
new file mode 100755
index 0000000..859142c
--- /dev/null
+++ b/am57xx_generate_pin_config_data.pl
@@ -0,0 +1,325 @@
1#!/usr/bin/perl -w
2#
3# Copyright (c) 2015, Texas Instruments
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11#
12# * Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15#
16# * Neither the name of Texas Instruments Incorporated nor the names of
17# its contributors may be used to endorse or promote products derived
18# from this software without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32
33#Format with perltidy -et=4 -ce -bar -sbl
34
35use strict;
36use warnings;
37use Getopt::Std;
38
39#---------------------------------------- Data
40my %options = ();
41my $iodelay_file;
42my $padconf_file;
43my $output_format;
44my %iodelay_array;
45my %iopad_array;
46
47# For New operations: update the two arrays
48my %operations_help = (
49 ti_u_boot_2014_07_iopad =>
50 "Generate IO Pad header data for ti-u-boot-2014.07",
51 ti_u_boot_2014_07_iodelay =>
52 "Generate IO Delay header data for ti-u-boot-2014.07",
53);
54my %operations_array = (
55 ti_u_boot_2014_07_iopad => \&operation_tiuboot2014_iopad,
56 ti_u_boot_2014_07_iodelay => \&operation_tiuboot2014_iodelay,
57);
58
59#---------------------------------------- Main flow
60getopts( "hp:d:o:", \%options );
61
62if ( $options{h} ) {
63 do_help("Usage:");
64}
65
66$iodelay_file = $options{d} if defined $options{d};
67$padconf_file = $options{p} if defined $options{p};
68$output_format = $options{o} if defined $options{o};
69
70# check for sanity
71do_help("Error: Missing file parameters!")
72 if !defined $iodelay_file && !defined $padconf_file;
73do_help("Error: Missing output format!") if !defined $output_format;
74do_help("Error: iodelay file '$iodelay_file' is not readable")
75 if defined $iodelay_file && !-r "$iodelay_file";
76do_help("Error: padconf file '$padconf_file' is not readable")
77 if defined $padconf_file && !-r "$padconf_file";
78do_help("Error: Unknown Output format '$output_format'")
79 if !exists( $operations_array{$output_format} );
80
81# read input files
82do_read_iopad($padconf_file) if defined $padconf_file;
83do_read_iodelay($iodelay_file) if defined $iodelay_file;
84
85# Now, execute the corresponding operation
86$operations_array{$output_format}->();
87
88exit 0;
89
90#---------------------------------------- Subroutines
91
92# Help subroutine.. uses the argument of some error or print message..
93sub do_help
94{
95 my $operation;
96
97 print "@_\n";
98 print "$0 [-h] [-p padconf_file | -d iodelay_file] -o output_format\n";
99 print "Where";
100 print "\t-h provides this help text\n";
101 print
102"\t-p padconf_file is the padconf output file provided by PCT(Pad Configuration Tool)\n";
103 print
104"\t-d iodelay_file is the iodelay output file provided by PCT(Pad Configuration Tool)\n";
105 print "\t-o output_format , where output_format is one of:\n";
106
107 foreach $operation ( keys %operations_array ) {
108 print "\t\t $operation - $operations_help{$operation}\n";
109 }
110 exit 0;
111}
112
113# read into an associative array of array indexed by register address
114# allows us to do operations and offsets and sorts. unfortunately with ballname,
115# we dont have exactly an unique key considering that multiple idoelay registers
116# have the same ballname
117sub do_read_file
118{
119 my $file = $_[0];
120 my $iopad = $_[1];
121 my $fh;
122 my $row;
123 my @iopad_row;
124 my $register;
125 my $skip = 0;
126
127 open( $fh, '<', $file )
128 or do_help("Error: unable to open IOPAD $file for read");
129
130 while ( $row = <$fh> ) {
131
132 chomp($row);
133
134 # get rid of commented lines including single line and multiline
135 next if $skip == 1;
136 if ( $row =~ /\/\*/ ) { $skip = 1 if !$row =~ /\*\//; next; }
137 if ( $row =~ /\*\// ) { $skip = 0; next; }
138
139 # get rid of Empty lines
140 next if $row =~ /^$/;
141
142 # Now, Human readable to CSV
143 $row =~ s/\s\s*/,/g;
144 @iopad_row = split( ',', $row );
145 $register = $iopad_row[0];
146 @iopad_row = splice @iopad_row, 1, $#iopad_row;
147 if ($iopad) {
148 $iopad_array{$register} = [@iopad_row];
149 } else {
150 $iodelay_array{$register} = [@iopad_row];
151 }
152 }
153
154 close($fh);
155}
156
157# tiny lil wrapper
158sub do_read_iopad
159{
160 do_read_file( $_[0], 1 );
161}
162
163# tiny lil wrapper
164sub do_read_iodelay
165{
166 do_read_file( $_[0], 0 );
167}
168
169#---- the various operations----
170sub operation_tiuboot2014_iopad()
171{
172 my $register;
173
174 do_help("Error: I need iodelay file for this option")
175 if !defined $iodelay_file;
176 do_help("Error: I need padconf file for this option")
177 if !defined $padconf_file;
178
179 foreach $register ( sort keys %iopad_array ) {
180 my @val;
181 my $reg_val;
182 my $reg_name;
183 my $ball_name;
184 my $mux0;
185 my $mux;
186 my $reg_dec;
187 my $slew_control;
188 my $input_en;
189 my $pull_active;
190 my $pull_up;
191 my $compare_val;
192 my $compare_hex;
193 my $val_mux0_name;
194 my $val_mux_mode;
195 my $val_pull;
196 my $val_delay_mode;
197 my $val_virtual_mode;
198 my $val_manual_mode;
199
200 @val = @{ $iopad_array{$register} };
201
202# register_address(hex) register_value(hex) ball_name(string) register_name(string) mux_mode0_name(string) muxed_mode_name(string)
203 ( $reg_val, $ball_name, $reg_name, $mux0, $mux ) = @val;
204
205 $reg_dec = hex($reg_val);
206
207 #pulls and mux mode
208 $slew_control = $reg_dec & ( 1 << 19 );
209 $input_en = $reg_dec & ( 1 << 18 );
210 $pull_up = $reg_dec & ( 1 << 17 );
211 $pull_active = $reg_dec & ( 1 << 16 );
212 $compare_val = $slew_control | $input_en | $pull_up | $pull_active;
213 $compare_hex = sprintf( "0x%08x", $compare_val );
214 if ( $compare_hex =~ /0x00010000/ ) { $val_pull = "PIN_OUTPUT"; }
215 elsif ( $compare_hex =~ /0x00030000/ ) {
216 $val_pull = "PIN_OUTPUT";
217 } elsif ( $compare_hex =~ /0x00020000/ ) {
218 $val_pull = "PIN_OUTPUT_PULLUP";
219 } elsif ( $compare_hex =~ /0x00000000/ ) {
220 $val_pull = "PIN_OUTPUT_PULLDOWN";
221 } elsif ( $compare_hex =~ /0x00080000/ ) {
222 $val_pull = "PIN_OUTPUT_PULLDOWN | SLEWCONTROL";
223 } elsif ( $compare_hex =~ /0x00050000/ ) {
224 $val_pull = "PIN_INPUT";
225 } elsif ( $compare_hex =~ /0x000c0000/ ) {
226 $val_pull = "PIN_INPUT_SLEW";
227 } elsif ( $compare_hex =~ /0x00060000/ ) {
228 $val_pull = "PIN_INPUT_PULLUP";
229 } elsif ( $compare_hex =~ /0x00040000/ ) {
230 $val_pull = "PIN_INPUT_PULLDOWN";
231 } elsif ( $compare_hex =~ /0x000e0000/ ) {
232 $val_pull = "PIN_INPUT_PULLUP | SLEWCONTROL";
233 }
234
235 # Uggh.. unknown definition?
236 else { $val_pull = $compare_hex; }
237
238 # virtual mode definition
239 $val_virtual_mode = ( $reg_dec >> 4 ) & 15;
240 $val_delay_mode = "MODESELECT" if $reg_dec & ( 1 << 8 );
241
242 # Am i Manual mode with VIRTUAL_MODE0 ?
243 if ( defined $val_delay_mode && $val_virtual_mode == 0 ) {
244 my $iodr;
245
246 #This could be manual mode!
247 foreach $iodr ( keys %iodelay_array ) {
248 my @iodv;
249 my $iod_a_delay;
250 my $iod_g_delay;
251 my $iod_reg_name;
252 my $iod_ball;
253 my $na = "N/A";
254
255 @iodv = @{ $iodelay_array{$iodr} };
256 ( $iod_a_delay, $iod_g_delay, $iod_reg_name, $iod_ball ) =
257 @iodv;
258 if ( !$ball_name =~ /$iod_ball/ ) { next; }
259 if ( $iod_a_delay =~ /$na/ && $iod_g_delay =~ /$na/ ) { next; }
260
261 # if either one is defined, we are manual mode
262 $val_manual_mode = "MANUAL_MODE";
263 }
264
265 }
266
267 # mux mode
268 $val_mux_mode = $reg_dec & 15;
269
270 # register defines is mux_mode0 name
271 # CTRL_CORE_PAD_GPMC_AD0 -> is GPMC_AD0
272 $val_mux0_name = substr $reg_name, 14;
273 print "\{$val_mux0_name, (M$val_mux_mode | $val_pull";
274 if ( defined $val_delay_mode ) {
275 if ( defined $val_manual_mode ) {
276 print " | $val_manual_mode";
277 } else {
278 printf " | VIRTUAL_MODE$val_virtual_mode";
279 }
280 }
281 printf(")},\t/* $mux0.$mux */\n");
282 }
283}
284
285sub operation_tiuboot2014_iodelay()
286{
287 my $register;
288 my @val;
289
290 do_help("Error: I need iodelay file for this option")
291 if !defined $iodelay_file;
292
293 foreach $register ( sort keys %iodelay_array ) {
294 my @iodv;
295 my $iodelay_base = 0x4844A000;
296 my $reg_dec;
297 my $offset;
298 my $iod_a_delay;
299 my $iod_g_delay;
300 my $iod_reg_name;
301 my $iod_ball;
302 my $na = "N/A";
303 my $val_a;
304 my $val_g;
305 my $val_offset;
306
307 @iodv = @{ $iodelay_array{$register} };
308 ( $iod_a_delay, $iod_g_delay, $iod_reg_name, $iod_ball ) = @iodv;
309 next if $iod_a_delay =~ /$na/ && $iod_g_delay =~ /$na/;
310 if ( $iod_a_delay =~ /$na/ ) {
311 $val_a = 0;
312 } else {
313 $val_a = $iod_a_delay;
314 }
315 if ( $iod_g_delay =~ /$na/ ) {
316 $val_g = 0;
317 } else {
318 $val_g = $iod_g_delay;
319 }
320 $reg_dec = hex($register);
321 $offset = $reg_dec - $iodelay_base;
322 $val_offset = sprintf( "0x%04X", $offset );
323 print "{$val_offset, $val_a, $val_g},\t/* $iod_reg_name */\n";
324 }
325}