diff options
author | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2008-10-16 18:03:47 +0000 |
---|---|---|
committer | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2008-10-16 18:03:47 +0000 |
commit | f48e3505473b9be26fa6d71c8437a87abde608f1 (patch) | |
tree | 5de89f01c6b0882b780447501327cd052cf6da31 | |
parent | eb21b700dd088304d1d9da2a657d4665ca655e23 (diff) |
xpp: userspace support for sysfx migration.
The userspace side of dahdi-linux r5097.
* Perl modules default to using xpp sysfs but will fallback (with warning)
to procfs interface.
* An additional /usr/share/dahdi/waitfor_xpds to replace the line in the
init.d script.
git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@5099 a0bf4364-ded3-4de4-8d8a-66a801d63aff
-rwxr-xr-x | dahdi.init | 5 | ||||
-rw-r--r-- | xpp/Makefile | 1 | ||||
-rw-r--r-- | xpp/perl_modules/Dahdi/Xpp.pm | 32 | ||||
-rw-r--r-- | xpp/perl_modules/Dahdi/Xpp/Line.pm | 24 | ||||
-rw-r--r-- | xpp/perl_modules/Dahdi/Xpp/Xpd.pm | 20 | ||||
-rwxr-xr-x | xpp/waitfor_xpds | 31 |
6 files changed, 90 insertions, 23 deletions
@@ -76,9 +76,8 @@ xpp_startup() { # do nothing if there are no astribank devices: if ! grep -q connected /proc/xpp/xbuses 2>/dev/null; then return 0; fi - echo "Waiting for Astribank devices to initialize:" - cat /proc/xpp/XBUS-[0-9]*/waitfor_xpds 2>/dev/null || true - + if ! /usr/share/dahdi/waitfor_xpds; then return 0; fi + # overriding locales for the above two, as perl can be noisy # when locales are missing. # No register all the devices if they didn't auto-register: diff --git a/xpp/Makefile b/xpp/Makefile index 398f17c..087bc4b 100644 --- a/xpp/Makefile +++ b/xpp/Makefile @@ -75,6 +75,7 @@ install: all $(INSTALL) $(PROG_INSTALL) $(DESTDIR)$(SBINDIR)/ $(INSTALL) -d $(DESTDIR)$(DATADIR) $(INSTALL) xpp_fxloader $(DESTDIR)$(DATADIR)/ + $(INSTALL) waitfor_xpds $(DESTDIR)$(DATADIR)/ $(INSTALL) -d $(DESTDIR)$(MANDIR) $(INSTALL_DATA) $(MAN_INSTALL) $(DESTDIR)$(MANDIR)/ $(INSTALL) -d $(DESTDIR)$(HOTPLUG_USB_DIR) diff --git a/xpp/perl_modules/Dahdi/Xpp.pm b/xpp/perl_modules/Dahdi/Xpp.pm index 919df30..f2811aa 100644 --- a/xpp/perl_modules/Dahdi/Xpp.pm +++ b/xpp/perl_modules/Dahdi/Xpp.pm @@ -32,6 +32,38 @@ Dahdi::Xpp - Perl interface to the Xorcom Astribank drivers. my $proc_base = "/proc/xpp"; +sub xpd_attr_path($$$@) { + my ($busnum, $unitnum, $subunitnum, @attr) = @_; + foreach my $attr (@attr) { + my $file = sprintf "/sys/bus/xpds/devices/%02d:%1d:%1d/$attr", + $busnum, $unitnum, $subunitnum; + unless(-f $file) { + my $procfile = sprintf "/proc/xpp/XBUS-%02d/XPD-%1d%1d/$attr", + $busnum, $unitnum, $subunitnum; + warn "$0: OLD DRIVER: missing '$file'. Fall back to '$procfile'\n"; + $file = $procfile; + } + next unless -f $file; + return $file; + } + return undef; +} + +sub xbus_attr_path($$) { + my ($busnum, @attr) = @_; + foreach my $attr (@attr) { + my $file = sprintf "/sys/bus/astribanks/devices/xbus-%02d/$attr", $busnum; + unless(-f $file) { + my $procfile = sprintf "/proc/xpp/XBUS-%02d/$attr", $busnum; + warn "$0: OLD DRIVER: missing '$file'. Fall back to '$procfile'\n"; + $file = $procfile; + } + next unless -f $file; + return $file; + } + return undef; +} + # Nominal sorters for xbuses sub by_name { return $a->name cmp $b->name; diff --git a/xpp/perl_modules/Dahdi/Xpp/Line.pm b/xpp/perl_modules/Dahdi/Xpp/Line.pm index d627ea4..2320bc7 100644 --- a/xpp/perl_modules/Dahdi/Xpp/Line.pm +++ b/xpp/perl_modules/Dahdi/Xpp/Line.pm @@ -10,8 +10,6 @@ package Dahdi::Xpp::Line; use strict; use Dahdi::Utils; -my $proc_base = "/proc/xpp"; - sub new($$$) { my $pack = shift or die "Wasn't called as a class method\n"; my $xpd = shift or die; @@ -29,14 +27,17 @@ sub blink($$) { my $on = shift; my $xpd = $self->xpd; my $result; - - my $file = "$proc_base/" . $xpd->fqn . "/blink"; + my $file = Dahdi::Xpp::xpd_attr_path( + $xpd->xbus->num, + $xpd->unit, + $xpd->subunit, "blink"); die "$file is missing" unless -f $file; # First query open(F, "$file") or die "Failed to open $file for reading: $!"; $result = <F>; chomp $result; close F; + $result = hex($result); if(defined($on)) { # Now change my $onbitmask = 1 << $self->index; my $offbitmask = $result & ~$onbitmask; @@ -67,14 +68,13 @@ sub create_all($$) { push(@lines, $line); } $xpd->{LINES} = \@lines; - my ($infofile) = glob "$procdir/*_info"; - die "Failed globbing '$procdir/*_info'" unless defined $infofile; - my $type = $xpd->type; - open(F, "$infofile") || die "Failed opening '$infofile': $!"; - my $battery_info = 0; - while (<F>) { - chomp; - if($type eq 'FXO') { + if($xpd->type eq 'FXO') { + my ($infofile) = glob "$procdir/*_info"; + die "Failed globbing '$procdir/*_info'" unless defined $infofile; + open(F, "$infofile") || die "Failed opening '$infofile': $!"; + my $battery_info = 0; + while (<F>) { + chomp; $battery_info = 1 if /^Battery:/; if($battery_info && s/^\s*on\s*:\s*//) { my @batt = split; diff --git a/xpp/perl_modules/Dahdi/Xpp/Xpd.pm b/xpp/perl_modules/Dahdi/Xpp/Xpd.pm index d85ae68..591c52f 100644 --- a/xpp/perl_modules/Dahdi/Xpp/Xpd.pm +++ b/xpp/perl_modules/Dahdi/Xpp/Xpd.pm @@ -12,14 +12,14 @@ use Dahdi::Utils; use Dahdi::Xpp; use Dahdi::Xpp::Line; -my $proc_base = "/proc/xpp"; - sub blink($$) { my $self = shift; my $on = shift; my $result; - - my $file = "$proc_base/" . $self->fqn . "/blink"; + my $file = Dahdi::Xpp::xpd_attr_path( + $self->xbus->num, + $self->unit, + $self->subunit, "blink"); die "$file is missing" unless -f $file; # First query open(F, "$file") or die "Failed to open $file for reading: $!"; @@ -44,8 +44,10 @@ sub dahdi_registration($$) { my $self = shift; my $on = shift; my $result; - - my $file = "$proc_base/" . $self->fqn . "/dahdi_registration"; + my $file = Dahdi::Xpp::xpd_attr_path( + $self->xbus->num, + $self->unit, + $self->subunit, "span", "dahdi_registration"); die "$file is missing" unless -f $file; # First query open(F, "$file") or die "Failed to open $file for reading: $!"; @@ -101,8 +103,10 @@ sub new($$) { } } close F; - $head =~ s/^(XPD-(\d\d))\s+// || die; - $self->{ID} = $2; + $head =~ s/^(XPD-(\d)(\d))\s+// || die; + $self->{ID} = "$2$3"; + $self->{UNIT} = "$2"; + $self->{SUBUNIT} = "$3"; $self->{FQN} = $xbus->name . "/" . $1; $head =~ s/^.*\(// || die; $head =~ s/\) */, / || die; diff --git a/xpp/waitfor_xpds b/xpp/waitfor_xpds new file mode 100755 index 0000000..0108b1b --- /dev/null +++ b/xpp/waitfor_xpds @@ -0,0 +1,31 @@ +#! /bin/sh + +set -e + +ab_list() { + ab=`find /sys/bus/astribanks/devices/xbus-*/ -name waitfor_xpds 2> /dev/null || :` + if [ "$ab" = "" ]; then + ab=`find /proc/xpp/XBUS-[0-9]*/ -name waitfor_xpds 2> /dev/null || :` + procfiles=1 + fi + if [ "$ab" = "" ]; then + echo 1>&2 "$0: No XBUSES to wait for. Aborting..." + exit 1 + fi + if [ -n "$procfiles" ]; then + echo 1>&2 "$0: No /sys attributes, fallback to /proc interface..." + fi + echo $ab +} + + +while + if ! ab=`ab_list`; then + exit 1 + fi + test "$oldab" != "$ab" +do + oldab="$ab" + echo 1>&2 "Waiting for XPDS" + cat $ab +done |