added /sys/kernel/debug/gpio info (leds for example)
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 11 Dec 2017 16:54:37 +0000 (17:54 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 11 Dec 2017 16:54:37 +0000 (17:54 +0100)
gpio.pl

diff --git a/gpio.pl b/gpio.pl
index c2af8ac..f653c3f 100755 (executable)
--- a/gpio.pl
+++ b/gpio.pl
@@ -160,6 +160,39 @@ while(<$fh>) {
 
 warn "# pin_function = ",dump($pin_function);
 
+
+# insert kernel gpio info
+my $linux_gpio_name;
+open(my $pins_fh, '<', (glob "/sys/kernel/debug/pinctrl/*/pins")[0]);
+while(<$pins_fh>) {
+       if ( m/^pin (\d+) \(([^\)]+)\)/ ) {
+               $linux_gpio_name->{$1} = $2;
+       }
+}
+warn "# linux_gpio_name = ",dump( $linux_gpio_name );
+
+
+my $gpio_debug;
+open(my $gpio_fh, '<', '/sys/kernel/debug/gpio');
+while(<$gpio_fh>) {
+       if (m/|/ ) {
+               s/^\s+//;
+               s/\s+$//;
+               my @l = split(/\s*[\(\|\)]\s*/, $_);
+               warn "XXX ", dump( \@l );
+               if ( $l[0] =~ m/gpio-(\d+)/ ) {
+                       my $pin = $linux_gpio_name->{$1} || die "can't find $1 in ",dump( $linux_gpio_name );
+                       $gpio_debug->{ $pin } = $l[2];
+                       $l[3] =~ s/\s\s+/ /g;
+                       annotate_pin $pin, qq{"$l[2]" $l[3]};
+               }
+       }
+
+}
+warn "# gpio_debug = ",dump( $gpio_debug );
+
+
+
 my $have_sunxi_pio = `which sunxi-pio`;
 if ( $have_sunxi_pio ) {