[zaptel-commits] tzafrir: branch 1.4 r1557 - in /branches/1.4/xpp: ./ firmwares/ utils/

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Mon Nov 6 11:12:17 MST 2006


Author: tzafrir
Date: Mon Nov  6 12:12:16 2006
New Revision: 1557

URL: http://svn.digium.com/view/zaptel?rev=1557&view=rev
Log:
Merging xpp driver release 1.2 (rev. 2569), originally team/tzafrir/xpp_1.2
 * Should build well. Almost final.
 * genzaptelconf: Also work when zap_autoreg=0
 * README.Astribank updated for rev. 1.2.
 * xpp/utils/Makefile: Use $< with cc -c
 * Get xpp/utils configuration from autoconf (without changesin top dir)

Added:
    branches/1.4/xpp/firmwares/
    branches/1.4/xpp/firmwares/FPGA_1151.hex   (with props)
    branches/1.4/xpp/firmwares/FPGA_FXS.hex   (with props)
    branches/1.4/xpp/firmwares/LICENSE.firmware   (with props)
    branches/1.4/xpp/firmwares/README   (with props)
    branches/1.4/xpp/firmwares/USB_1130.hex   (with props)
    branches/1.4/xpp/firmwares/USB_1150.hex   (with props)
    branches/1.4/xpp/init_card_3_23   (with props)
    branches/1.4/xpp/init_card_4_23   (with props)
    branches/1.4/xpp/utils/adj_clock.8   (with props)
    branches/1.4/xpp/utils/adj_clock.c   (with props)
Removed:
    branches/1.4/xpp/LICENSE.firmware
    branches/1.4/xpp/init_data_3_19.cmd
    branches/1.4/xpp/init_data_3_20.cmd
    branches/1.4/xpp/init_data_4_19.cmd
    branches/1.4/xpp/init_data_4_20.cmd
    branches/1.4/xpp/initialize_registers
    branches/1.4/xpp/slic.c
    branches/1.4/xpp/slic.h
    branches/1.4/xpp/utils/FPGA_FXS.hex
    branches/1.4/xpp/utils/USB_1130.hex
    branches/1.4/xpp/utils/USB_8613.hex
Modified:
    branches/1.4/xpp/   (props changed)
    branches/1.4/xpp/Makefile
    branches/1.4/xpp/README.Astribank
    branches/1.4/xpp/calibrate_slics   (contents, props changed)
    branches/1.4/xpp/card_fxo.c
    branches/1.4/xpp/card_fxo.h
    branches/1.4/xpp/card_fxs.c
    branches/1.4/xpp/card_fxs.h
    branches/1.4/xpp/card_global.c
    branches/1.4/xpp/card_global.h
    branches/1.4/xpp/utils/   (props changed)
    branches/1.4/xpp/utils/Makefile
    branches/1.4/xpp/utils/genzaptelconf
    branches/1.4/xpp/utils/genzaptelconf.8
    branches/1.4/xpp/utils/print_modes.c   (props changed)
    branches/1.4/xpp/utils/xpp_fxloader
    branches/1.4/xpp/utils/xpp_fxloader.usermap
    branches/1.4/xpp/xbus-core.c
    branches/1.4/xpp/xbus-core.h
    branches/1.4/xpp/xdefs.h
    branches/1.4/xpp/xpd.h
    branches/1.4/xpp/xpp_usb.c
    branches/1.4/xpp/xpp_zap.c
    branches/1.4/xpp/xpp_zap.h
    branches/1.4/xpp/xproto.c
    branches/1.4/xpp/xproto.h

Propchange: branches/1.4/xpp/
------------------------------------------------------------------------------
--- svk:merge (added)
+++ svk:merge Mon Nov  6 12:12:16 2006
@@ -1,0 +1,2 @@
+283159da-0705-0410-b60c-f2062b4bb6ad:/components/xpp-zaptel/trunk/xpp:2600
+f558416c-6c06-0410-9f27-dde2687782d0:/team/tzafrir/xpp_1.2/xpp:1554

Propchange: branches/1.4/xpp/
------------------------------------------------------------------------------
    svn:executable = calibrate_slics

Modified: branches/1.4/xpp/Makefile
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/Makefile?rev=1557&r1=1556&r2=1557&view=diff
==============================================================================
--- branches/1.4/xpp/Makefile (original)
+++ branches/1.4/xpp/Makefile Mon Nov  6 12:12:16 2006
@@ -1,9 +1,15 @@
-EXTRA_CFLAGS	= -I$(SUBDIRS) -DDEBUG -DPOLL_DIGITAL_INPUTS -DWITH_ECHO_SUPPRESSION # -DSOFT_RING
+EXTRA_CFLAGS	= -g3 -I$(SUBDIRS) -DDEBUG -DPOLL_DIGITAL_INPUTS -DWITH_ECHO_SUPPRESSION # -DSOFT_RING
 
-obj-m			= xpp.o xpp_usb.o xpd_fxs.o xpd_fxo.o
-xpp-y			+= xbus-core.o xpp_zap.o xproto.o card_global.o
-xpd_fxs-y		+= card_fxs.o slic.o
-xpd_fxo-y		+= card_fxo.o slic.o
+obj-m		+= xpp.o xpd_fxs.o xpd_fxo.o
+
+# Build only supported modules
+ifneq	(,$(filter y m,$(CONFIG_USB)))
+obj-m		+= xpp_usb.o
+endif
+
+xpp-y		+= xbus-core.o xpp_zap.o xproto.o card_global.o
+xpd_fxs-y	+= card_fxs.o
+xpd_fxo-y	+= card_fxo.o
 
 ctags:
 	ctags *.[ch]

Modified: branches/1.4/xpp/README.Astribank
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/README.Astribank?rev=1557&r1=1556&r2=1557&view=diff
==============================================================================
--- branches/1.4/xpp/README.Astribank (original)
+++ branches/1.4/xpp/README.Astribank Mon Nov  6 12:12:16 2006
@@ -9,30 +9,20 @@
 
 Building drivers:
 """"""""""""""""
-From the toplevel zaptel directory run a command similar to (I used line
-continuation to prevent line wrapping):
-
- $ make \
-        KSRC=/usr/src/kernel-headers-2.6.12-1-386       \
-        KVERS=2.6.12-1-386                              \
-        XPPMOD=xpp/                                     \
-        EC_TYPE=CAN_KB1
-
- - The KSRC= points to a configured kernel source tree.
- - The KVERS= should match the relevant tree version.
- - The XPPMOD= instructs the Zaptel Makefile to descend into the xpp/
-   subdirectory. The slash (/) in the end is mandatory.
- - The EC_TYPE= select the echo canceler.
-
-Building firmware utilities:
-"""""""""""""""""""""""""""
-Then you should compile the firmware loading utilities. Simply go
-to the zaptel/xpp/utils and run make.
-
-Those who don't use prepackaged drivers should make sure they also
-install the (externally available) fxload utility.
-
-Installation:
+Unlike earlier versions, the Astribank driver (xpp) will now build 
+automatically. To build the drivers follow the usual Zaptel
+documentation. E.g: run:
+
+  make
+
+in the top-level directory.
+
+Next you will need to build the user-space tools needed for loading the
+firmware and initialization files for the Astribank:
+
+  make -C xpp/utils
+
+INSTALLATION:
 """"""""""""
 
 apart from the standard 'make install' in the zaptel directory, 
@@ -45,7 +35,7 @@
 All firmware files should be copied to a new directory:
   /usr/share/zaptel/
 
-The xpp_fxloader and xpp_fxloader.usbmap should be copied to:
+The xpp_fxloader and xpp_fxloader.usermap should be copied to:
  /etc/hotplug/usb/
 
 In addition, the file xpp/xpp_modprobe contains optional modprobe settings.
@@ -55,48 +45,242 @@
 
 Note that loading through udev is not yet provided. Run 
 
-  /etc/hotplug/usb/xpp_fxloader xppdetect
+  /etc/hotplug/usb/xpp_fxloader load
 
 to load firmware.
 
-
-Loading Firmware Details:
-""""""""""""""""""""""""
+The FXS calibration script requires the perl module Time::HiRes. This
+modules is already packaged for most distributions including Debian, Fedora,
+RedHat and CentOS. To test for the existance of this module run:
+  perl -MTime::HiRes -e ''
+
+This should run cleanly (without output) if the module exists and issue
+a long error message otherwise. At least in RedHat, CentOS and Fedora-2
+until Fedora-5 it is in a package named perl-Time-HiRes. In Debian and
+Fedora-6 it is bundled with perl.
+
+
+DEVICE STARTUP:
+""""""""""""""
+
+Terminology:
+"""""""""""
+Some technical terms that are used throughout the document and in the
+driver / zaptel . Only used in the technical parts.
+
+span:
+Zaptel breaks the channels it knows bout to logical units called
+"spans". A port in a E1/T1/ISDN card is usually a span. So is a complete
+analog card. You can see the list of spans as the list of files under
+/proc/zaptel or the list in zttool.
+
+XBUS:
+A funny way to call an Astribank device.
+
+XPD:
+This is basically a logical unit of the Astribank. It will be registered to
+Zaptel as a single span. This will basically be 8 analog channels.
+
+
+Loading Firmware:
+""""""""""""""""
+Normally this is done using the script xpp_fxloader.If it works fine,
+you don't need to bother reading this section. 
+Once the firmware is loaded the USB ID of the Astribank changes to e4e4
+1132, and the driver can pick it up. You'll also see the top led lit.
+
+First and foremost: the simplest and most useful tool to debug problems
+here is lsusb. The output of lsusb should show exactly if the device is
+connected and if its firmware is loaded. 
+
+The firmware files are named *.hex. The are in the Intel hex format 
+(read: plain text, but not readable) that is copied at install time from 
+xpp/utils to /usr/share/zaptel .
+
 The Astribank needs a firmware loaded into it. Without the firmware, 
-the device will appear in lsusb with vendor ID 04b4 and product ID 8613
-The firmware is provided in the Intel hex format. It can be loaded using 
-the program fxload, which is typically part of the package 'fxload' or 
-'hotplug-utils' . 
-
-To load the firmware automatically using the standard hotplug script, 
-place xpp/utils/xpp_fxloader and xpp/utils/xpp_fxloader.usermap in 
-/etc/hotplug/usb and place xpp/utils/*.hex in /usr/share/zaptel .
-
-Alternatively, xpp_fxloader when given the parameter 'xppdetect' will load 
-the firmwares from /usr/share/zaptel/ . You can use it to load the 
-firmware manually.
-
-You should then get in lsusb the vendor ID e4e4 and device ID 2121
-(those IDs are temporary and likely to change in upcoming versions). 
-Once there is such a device, the xpp_usb driver should load
-automatically on hot-plugging. In fact, you may find it simpler to
-disconnect and reconnect the device than running 'modprobe xpp_usb'.
-
-
-The driver has been separated into several modules: xpp.ko, xpd_fxs.ko and 
-xpp_usb.ko . Generally you only need to modprobe xpp_usb, and it should also
-be loaded by hotplug when you connect the Astribank. However in order for it
-to load xpd_fks.ko correctly
-
-Refer to the instructions for Zaptel. After our small patches were applies, 
-you get xpp.ko which is basically yet another zaptel driver, like wcfxo
-and wctdm.
+the device will appear in lsusb with vendor ID e4e4 and product ID 1130.
+The firmware is loaded in two stages. In the first stage we load the
+"USB" firmware using the program fxload. After the first stage the USB
+ID is e4e4 1131. In the second stage we load the "FPGA" firmware.
+
+The first is done using the the program fxload. To load it manually, use
+the command:
+
+  fxload -t fx2 -D /proc/bus/usb/MMM/NNN -I /usr/share/zaptel/USB_1130.hex
+
+fxload is standard program that is typically part of the package 'fxload' 
+or 'hotplug-utils' . /proc/bus/usb is the mount point of the USB
+file-system (usbfs). MMM is the first number (bus number) and NNN is the
+second number (device number) you see for the device in lsusb, with full
+3 digits. If the load is successful, the device disconnects and
+reconnects with USB product ID 1131 (and a new device number).
+
+The second-stage loader is done using the program fpga_load, which is
+built in the directory xpp/utils and installed to /usr/sbin/fpga_load .
+Its syntax is based on fxload. To load with it manually, use:
+  
+  fpga_load -D /proc/bus/usb/MMM/NNN -I /usr/share/zaptel/FPGA_FXS.hex
+
+Note that as the device has reconnected, it now has a new device
+number. So you need to re-check the value of NNN with lsusb. Typically
+this will be the old value + 1.
+
+
+Firmware Loading with UDEV:
+""""""""""""""""""""""""""
+Firmware loading with udev should work but is not installed 
+automatically, yet. See the comments in the beginning of the script
+/etc/hotplug/usb/xpp_fxloader .
+
+Loading The Modules:
+"""""""""""""""""""
+Here is what should happen:
+In short: you should plug it or have it plugged at boot time, and all
+the modules should load. You will see xpp_usb , xpd_fxs and possibly
+xpd_fxo in the modules list (the output of lsmod).
+
+After the module xpp is loaded, you'll also be able to see the directory
+/proc/xpp . For any Astribank discovered there you will see a directory
+/prc/xpp/XBUS-n (where n is a number: typically 0). Once a unit have
+been discovered you'll see subdirectories: /proc/xpp/XBUS-n/XPD-m (where
+m may be another number: 0, 1 ,etc).
+
+Now to the ugly details:
+
+The driver of the Astribank is composed of several modules: xpp is the
+basic one, that contains the functionality to connect to Zaptel and other
+common functions. xpd_fxs is the module for controlling FXS spans.
+xpd_fxo is the module for controlling FXO spans. xpd_usb is the module
+that holds the functionality needed to connect to the USB bus.
+
+All modules depend on xpp, and modprobing them will install xpp as well.
+However the xpd_* modules are only installed on-demand: no need to
+install xpd_fxo if you only have FXS Astribank.
+
+You either plug in the Astribank , or start the hotplug/udev system 
+while an Astribank is connected, after the firmware is loaded. The 
+Vendor-ID/Product-ID of the device is e4e4/1132 . The handler for that
+combination is listed as the kernel module xpp_usb . Thus the system
+runs 'modprobe xpp_usb' if that module is not already loaded.
+
+The module xpp_usb depends on the modules zaptel and xpp . Both of which 
+are loaded before xpp_usb is loaded. As usual, parameters and rules form
+/etc/modprobe.conf and/or /etc/modprobe.d/* will apply to the module, as
+modprobe is used.
+
+The modules to handle the specific span types (xpd_fxs, xpd_fxo) may or
+may not have been loaded yet at this stage (when the command 'modprobe
+xpp_usb' returns).
+
+At this point the xpp driver asks the box what logical units it has.
+According to the answers it gets, it will figure what xpd_* modules it will
+need, and modprobe for them. At some earlier version of the driver this has
+required some special modprobe.conf setup, but this is no longer
+the case.
+
+
+Device Initializations Scripts:
+""""""""""""""""""""""""""""""
+The chips in the device need to be initialized. This involves sending a
+bunch of values to certain registers in those chips. We decided that
+hardwiring those values in the driver itself would not be a good idea.
+
+before registering a XPD as a span in Zaptel, we run an initialization
+script: /usr/share/zaptel/initialize_registers . If this fails (e.g:
+because the script is not there, or is not executable), you will get an
+error message in the logs [FIXME: quote error message] that the
+invocation has failed. The XPD will then be removed (you won't see that
+a directory for that XPD under the relevant /proc/xpp/XBUS-* directory)
+and not be registered with Zaptel.
+
+Registering With Zaptel:
+"""""""""""""""""""""""
+Now we finally got to the "lights party" part: the lights in a unit
+(XPD) get lit before it registers with Zaptel and are turned off after
+that.
+
+You may choose not to register the XPDs to Zaptel automatically, to
+allow finer control of the process. This is done using the module
+parameter zap_autoreg. Set in the modprobe configuration file (e.g:
+/etc/modprobe.conf ) the line:
+
+  options xpp zap_autoreg=0
+
+to disable automatic registration at startup. You will then need to
+register the spans manually. 
+
+
+SAMPLE CONFIGURATIONS:
+""""""""""""""""""""""
+
+/etc/zaptel.conf:
+
+  Astribank 8:
+
+    fxoks=1-14
+
+  Astribank 16: 8FXS/8FXO
+
+    fxoks=1-14
+    fksks=15-22
+
+/etc/asterisk/zapata.conf
+
+  Astribank 8:
+   
+    [channels]
+    signalling=fxo_ks
+    ; The real analog ports:
+    context=from-internal
+    ; echocancel=yes
+    ; echocancelwhenbriged=yes
+    ; echotraining=9
+    channel => 1-8
+
+    ; output ports:
+    context=astribank-outputs
+    channel => 9-10
+    ; input ports:
+    immediate=yes
+    context=astribank-inputs
+    channel => 11-14
+    immediate=no
+  
+  Astribank 16: 8FXS/8FXO
+   
+    [channels]
+    signalling=fxo_ks
+    ; The real analog ports:
+    context=from-internal
+    ; echocancel=yes
+    ; echocancelwhenbriged=yes
+    ; echotraining=9
+    channel => 1-8
+
+    ; output ports:
+    context=astribank-outputs
+    channel => 9-10
+    ; input ports:
+    immediate=yes
+    context=astribank-inputs
+    channel => 11-14
+    immediate=no
+
+    ; FXO ports
+    signalling=fxs_ks
+    context=from-pstn
+    callerid=asreceived
+    channel => 15-22
+
+See also the output of genzaptelconf for examples of mailbox and 
+callerid, and for channel numbers that will match your specific settings.
+For that reason I only give the above two sample configurations.
 
 When loaded, you should get one span, of 8 extensions, 2 output ports and 
 4 input ports:
 
   root at rapid:~# cat /proc/zaptel/2 
-  Span 1: XBUS-0/XPD-0 "Xorcom XPD #0/0: FXS" NOTOPEN 
+  Span 1: XBUS-0/XPD-0 "Xorcom XPD #0/0: FXS"
 
            1 XPP_FXS/0-0 FXOKS (In use) 
            2 XPP_FXS/0-1 FXOKS (In use) 
@@ -113,36 +297,6 @@
           13 XPP_IN/0-12 FXOKS (In use) 
           14 XPP_IN/0-13 FXOKS (In use) 
 
-For such a simple case you could use:
-
-/etc/zaptel.conf:
-
-fxoks=1-14
-loadzone=us
-tonezone=us
-
-/etc/asterisk/zapata.conf:
-
-[channels]
-group=1
-signalling=fxo_ks
-immediate=no
-
-context=from-internal
-channels => 1-8
-
-; actually they will never generate calls, so the context 
-; here is irrelevant
-;context=outputs
-channels => 9-10
-
-; input ports should get an answer:
-immediate=yes
-context=inputs
-channels => 11-14
-
-;;;;;; end of zapata.conf
-
 
 /proc Interface
 """""""""""""""
@@ -183,10 +337,10 @@
 want to set their registration order manually using zt_registration in 
 the /proc interface.
 
-initialize_registers (xpd_fxs)
-The script that is run to initilize registers of the device. The default is 
-/usr/share/zaptel/initialize_registers . 
-Setting this value could be useful if that location is inconvient for you.
+initdir: (xpp)
+This is the directory containing the initialization scripts.
+The default is /usr/share/zaptel .
+Setting this value could be useful if that location is inconvenient for you.
 
 print_dbg: (all modules)
 It will make the driver print tons of debugging messages. Can be sometime 

Modified: branches/1.4/xpp/calibrate_slics
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/calibrate_slics?rev=1557&r1=1556&r2=1557&view=diff
==============================================================================
--- branches/1.4/xpp/calibrate_slics (original)
+++ branches/1.4/xpp/calibrate_slics Mon Nov  6 12:12:16 2006
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 #
-# $Id:$
+# $Id$
 #
 
 use strict;
@@ -22,7 +22,6 @@
 
 sub write_to_slic_file($) {
 	my $write_str = shift;
-	#print STDERR "[Writing string]\n".$write_str."[End String]\n";
 
 	open(SLICS,">$SlicsFile") or 
 		die("Failed writing to slics file $SlicsFile");
@@ -38,19 +37,19 @@
 	my $direct = shift;
 	
 	write_to_slic_file(
-		sprintf("%02x 00 00 00 R%s %02X", 
-			1<<$read_slic, $direct, $read_reg));
+		sprintf("%d R%s %02X", $read_slic, $direct, $read_reg));
 	sleep(0.001);
 	open(SLICS,$SlicsFile) or 
 		die("Failed reading from slics file $SlicsFile");
+	#awk '/^SLIC_REPLY:/{print $5}' $SLICS | cut -dx -f2
 	my @reply = ();
 	while(<SLICS>){
-		#if (/^[^#]/) {
+		#if (/^ /) {
 		#	print STDERR "answer line: $_";
 		#}
-		if (/^SLIC_REPLY:\s+[DI]\s+reg_num=0x[[:xdigit:]]+,\s+dataH=0x([[:xdigit:]]+)\s+dataL=0x([[:xdigit:]]+)/){
+		if (/^ \d*\s+[RW][DIS]\s+[[:xdigit:]]+\s+([[:xdigit:]]+)\s+([[:xdigit:]]+)/){
 			@reply = (hex($1), hex($2)); 
-			#print STDERR "got [@reply]\n";
+			#print STDERR "got [$reply]\n";
 			last;
 		}
 	}
@@ -58,7 +57,7 @@
 	if ($direct eq 'I') {
 		return @reply;
 	} else {
-		return $reply[1];
+		return $reply[0];
 	}
 }
 
@@ -70,28 +69,11 @@
 	my $reg_val_low = shift;
 	my $reg_val_hi = shift;
 	
-	my $str  = sprintf "%02x 00 00 00 W%s %02X %02X", 
-		1<<$read_slic, $direct, $read_reg, $reg_val_low;
+	my $str  = sprintf "%d W%s %02X %02X", 
+		$read_slic, $direct, $read_reg, $reg_val_low;
 	if ($direct eq 'I') {
 		$str .= sprintf " %02X", $reg_val_hi;
 	}
-	#printf STDERR "Writing: $str\n";
-	write_to_slic_file($str);
-}
-
-# TODO: rearange arguments
-sub write_reg_all_slics{#($$$$) {
-	my $read_reg = shift;
-	my $direct = shift;
-	my $reg_val_low = shift;
-	my $reg_val_hi = shift;
-	
-	my $str  = sprintf "FF FF 00 00 W%s %02X %02X", 
-		$direct, $read_reg, $reg_val_low;
-	if ($direct eq 'I') {
-		$str .= sprintf " %02X", $reg_val_hi;
-	}
-	printf STDERR "Writing: $str\n";
 	write_to_slic_file($str);
 }
 
@@ -107,81 +89,81 @@
 
 sub init_indirect_registers() {
 	return write_to_slic_file("#
-FF FF 00 00	WI	00	C2	55
-FF FF 00 00	WI	01	E6	51
-FF FF 00 00	WI	02	85	4B
-FF FF 00 00	WI	03	37	49
-                          
-FF FF 00 00	WI	04	33	33
-FF FF 00 00	WI	05	02	02
-FF FF 00 00	WI	06	02	02
-FF FF 00 00	WI	07	98	01
-                          
-FF FF 00 00	WI	08	98	01
-FF FF 00 00	WI	09	11	06
-FF FF 00 00	WI	0A	02	02
-FF FF 00 00	WI	0B	E5	00
-                          
-FF FF 00 00	WI	0C	1C	0A
-FF FF 00 00	WI	0D	30	7B
-FF FF 00 00	WI	0E	63	00
-FF FF 00 00	WI	0F	00	00
-                          
-FF FF 00 00	WI	10	70	78
-FF FF 00 00	WI	11	7D	00
-FF FF 00 00	WI	12	00	00
-FF FF 00 00	WI	13	00	00
-                          
-FF FF 00 00	WI	14	F0	7E
-FF FF 00 00	WI	15	60	01
-FF FF 00 00	WI	16	00	00
-FF FF 00 00	WI	17	00	20
-                          
-FF FF 00 00	WI	18	00	20
-FF FF 00 00	WI	19	00	00
-FF FF 00 00	WI	1A	00	20
-FF FF 00 00	WI	1B	00	40
-                          
-FF FF 00 00	WI	1C	00	10
-FF FF 00 00	WI	1D	00	36
-FF FF 00 00	WI	1E	00	10
-FF FF 00 00	WI	1F	00	02
-                          
-FF FF 00 00	WI	20	C0	07
-FF FF 00 00	WI	21	00	26
-FF FF 00 00	WI	22	F4	0F
-FF FF 00 00	WI	23	00	80
-
-#FF FF 00 00	WI	24	20	03
-#FF FF 00 00	WI	25	8C	08
-#FF FF 00 00	WI	26	00	01
-#FF FF 00 00	WI	27	10	00
-                          
-FF FF 00 00	WI	24	00	08
-FF FF 00 00	WI	25	00	08
-FF FF 00 00	WI	26	00	08
-FF FF 00 00	WI	27	00	08
-                          
-FF FF 00 00	WI	28	00	0C
-FF FF 00 00	WI	29	00	0C
-FF FF 00 00	WI	2B	00	01
-                          
-FF FF 00 00	WI	63	DA	00
-FF FF 00 00	WI	64	60	6B
-FF FF 00 00	WI	65	74	00
-FF FF 00 00	WI	66	C0	79
-                          
-FF FF 00 00	WI	67	20	11
-FF FF 00 00	WI	68	E0	3B	
+31	WI	00	C2	55
+31	WI	01	E6	51
+31	WI	02	85	4B
+31	WI	03	37	49
+                          
+31	WI	04	33	33
+31	WI	05	02	02
+31	WI	06	02	02
+31	WI	07	98	01
+                          
+31	WI	08	98	01
+31	WI	09	11	06
+31	WI	0A	02	02
+31	WI	0B	E5	00
+                          
+31	WI	0C	1C	0A
+31	WI	0D	30	7B
+31	WI	0E	63	00
+31	WI	0F	00	00
+                          
+31	WI	10	70	78
+31	WI	11	7D	00
+31	WI	12	00	00
+31	WI	13	00	00
+                          
+31	WI	14	F0	7E
+31	WI	15	60	01
+31	WI	16	00	00
+31	WI	17	00	20
+                          
+31	WI	18	00	20
+31	WI	19	00	00
+31	WI	1A	00	20
+31	WI	1B	00	40
+                          
+31	WI	1C	00	10
+31	WI	1D	00	36
+31	WI	1E	00	10
+31	WI	1F	00	02
+                          
+31	WI	20	C0	07
+31	WI	21	00	26
+31	WI	22	F4	0F
+31	WI	23	00	80
+
+#31	WI	24	20	03
+#31	WI	25	8C	08
+#31	WI	26	00	01
+#31	WI	27	10	00
+                          
+31	WI	24	00	08
+31	WI	25	00	08
+31	WI	26	00	08
+31	WI	27	00	08
+                          
+31	WI	28	00	0C
+31	WI	29	00	0C
+31	WI	2B	00	01
+                          
+31	WI	63	DA	00
+31	WI	64	60	6B
+31	WI	65	74	00
+31	WI	66	C0	79
+                          
+31	WI	67	20	11
+31	WI	68	E0	3B	
 #");
 }
 
 sub init_early_direct_regs() {
 	return write_to_slic_file("#
-FF FF 00 00	WD	08 00
-FF FF 00 00	WD	4A 34
-FF FF 00 00	WD	4B 10
-FF FF 00 00	WD	40 00
+31	WD	08 00
+31	WD	4A 34
+31	WD	4B 10
+31	WD	40	00
 #")
 }
 
@@ -221,7 +203,7 @@
 	
 	# start calibration:
 	my $calibration_in_progress = 1;
-	write_reg_all_slics($write_reg, 'D', 0x1F);
+	write_reg(31, $write_reg, 'D', 0x1F);
 	sleep $ManualCalibrationSleepTime;
 	
 	# wait until all slics have finished calibration, or for timeout
@@ -256,9 +238,9 @@
 	# start calibration:
 	write_to_slic_file(
 		sprintf
-			"FF FF 00 00	WD 61 %02X\n".
-			"FF FF 00 00	WD 60 %02X\n".
-			"", $calib_97, $calib_96
+			"31 WD 61 %02X\n".
+			"31 WD 60 %02X\n".
+			"", $calib_96, $calib_97
 			
 	);
 	# wait until all slics have finished calibration, or for timeout
@@ -267,19 +249,16 @@
 	CALIB_LOOP: for my $slic (@SlicNums) {
 		logger("checking slic $slic");
 		while(1) {
-			my $reply;
-			if (($reply=read_reg($slic, 96, 'D')) == 0) {
+			if ((read_reg($slic, 60, 'D')) == 0) {
 				# move to next register
 				logger("slic $slic calibrated");
 				last;
 			}
-			print STDERR "reply: $reply\n";
 			my $time=time();
 			if ( $time > $end_time) {
 				$timeout=1;
-				logger("Exiting on timeout: $time is after timeout $end_time .");
-				exit 1;
-				#last CALIB_LOOP;
+				logger("Exiting on timeout: $end_time < $time.");
+				last CALIB_LOOP;
 			}
 			logger("auto_calibrate not done yet: slic #$slic\n");
 			sleep(0.1);

Propchange: branches/1.4/xpp/calibrate_slics
------------------------------------------------------------------------------
--- svn:executable (original)
+++ svn:executable Mon Nov  6 12:12:16 2006
@@ -1,1 +1,1 @@
-*
+Y

Propchange: branches/1.4/xpp/calibrate_slics
------------------------------------------------------------------------------
    (empty)

Modified: branches/1.4/xpp/card_fxo.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/xpp/card_fxo.c?rev=1557&r1=1556&r2=1557&view=diff
==============================================================================
--- branches/1.4/xpp/card_fxo.c (original)
+++ branches/1.4/xpp/card_fxo.c Mon Nov  6 12:12:16 2006
@@ -33,8 +33,8 @@
 
 static const char rcsid[] = "$Id$";
 
-DEF_PARM(int, print_dbg, 0, "Print DBG statements");	/* must be before zap_debug.h */
-DEF_PARM(uint, poll_battery_interval, 100, "Poll battery interval in milliseconds");
+DEF_PARM(int, print_dbg, 0, "Print DBG statements");
+DEF_PARM(uint, poll_battery_interval, 100, "Poll battery interval in milliseconds (0 - disable)");
 DEF_PARM(bool, report_battery, 0, "Report battery status to zaptel");
 
 /* Signaling is opposite (fxs signalling for fxo card) */
@@ -54,22 +54,30 @@
 #define	BAT_THRESHOLD		3
 #define	BAT_DEBOUNCE		3	/* compensate for battery voltage fluctuation (in poll_battery_interval's) */
 
+static /* 0x0F */ DECLARE_CMD(FXO, REGISTER_REQUEST, byte chipsel, bool writing, bool do_subreg, byte regnum, byte subreg, byte data_low, byte data_high);
+/* Shortcuts */
+#define	DAA_WRITE	1
+#define	DAA_READ	0
+#define	DAA_DIRECT_REQUEST(xbus,xpd,chipsel,writing,reg,dL)	\
+	CALL_PROTO(FXO, REGISTER_REQUEST, (xbus), (xpd), (chipsel), (writing), 0, (reg), 0, (dL), 0)
+
+#define	VALID_CHIPSEL(x)	(((chipsel) >= 0 && (chipsel) <= 7) || (chipsel) == ALL_CHANS)
+
 /*---------------- FXO Protocol Commands ----------------------------------*/
 
-static /* 0x0F */ DECLARE_CMD(FXO, CHAN_ENABLE, xpp_line_t lines, bool on);
-static /* 0x0F */ DECLARE_CMD(FXO, CHAN_CID, int pos);
-static /* 0x0F */ DECLARE_CMD(FXO, RING, int pos, bool on);
+static /* 0x0F */ DECLARE_CMD(FXO, XPD_STATE, bool on);
+static /* 0x0F */ DECLARE_CMD(FXO, CHAN_CID, lineno_t chan);
+static /* 0x0F */ DECLARE_CMD(FXO, RING, lineno_t chan, bool on);
 static /* 0x0F */ DECLARE_CMD(FXO, RELAY_OUT, byte which, bool on);
-static /* 0x0F */ DECLARE_CMD(FXO, DAA_QUERY, int pos, byte reg_num);
 
 static bool fxo_packet_is_valid(xpacket_t *pack);
-static void fxo_packet_dump(xpacket_t *pack);
+static void fxo_packet_dump(const char *msg, xpacket_t *pack);
 static int proc_fxo_info_read(char *page, char **start, off_t off, int count, int *eof, void *data);
-static int proc_xpd_slic_read(char *page, char **start, off_t off, int count, int *eof, void *data);
-static int proc_xpd_slic_write(struct file *file, const char __user *buffer, unsigned long count, void *data);
-static int process_slic_cmdline(xpd_t *xpd, char *cmdline);
-
-#define	PROC_DAA_FNAME		"slics"
+static int proc_xpd_register_read(char *page, char **start, off_t off, int count, int *eof, void *data);
+static int proc_xpd_register_write(struct file *file, const char __user *buffer, unsigned long count, void *data);
+static int handle_register_command(xpd_t *xpd, char *cmdline);
+
+#define	PROC_REGISTER_FNAME	"slics"
 #define	PROC_FXO_INFO_FNAME	"fxo_info"
 
 #ifdef SOFT_RING
@@ -80,11 +88,9 @@
 #define	DAA_RING_REGISTER	0x05
 
 struct FXO_priv_data {
-	struct proc_dir_entry		*xpd_slic;
+	struct proc_dir_entry		*regfile;
 	struct proc_dir_entry		*fxo_info;
 	uint				poll_counter;
-	slic_reply_t			requested_reply;
-	slic_reply_t			last_reply;
 	xpp_line_t			battery;
 	ushort				battery_debounce[CHANNELS_PERXPD];
 	xpp_line_t			ledstate[NUM_LEDS];	/* 0 - OFF, 1 - ON */
@@ -119,42 +125,29 @@
 /*
  * LED control is done via DAA register 0x20
  */
-static int do_led(xpd_t *xpd, lineno_t pos, byte which, bool on)
+static int do_led(xpd_t *xpd, lineno_t chan, byte which, bool on)
 {
 	int			ret = 0;
-	xpacket_t		*pack;
-	slic_cmd_t		*sc;
-	int			len;
-	struct FXO_priv_data	*priv;
-	xpp_line_t		lines;
+	struct FXO_priv_data	*priv;
 	xbus_t			*xbus;
 
 	BUG_ON(!xpd);
 	xbus = xpd->xbus;
 	priv = xpd->priv;
 	which = which % NUM_LEDS;
-	if(IS_SET(xpd->digital_outputs, pos) || IS_SET(xpd->digital_inputs, pos))
+	if(IS_SET(xpd->digital_outputs, chan) || IS_SET(xpd->digital_inputs, chan))
 		goto out;
-	if(pos == ALL_LINES) {
-		lines = ~0;
+	if(chan == ALL_CHANS) {
 		priv->ledstate[which] = (on) ? ~0 : 0;
 	} else {
-		lines = BIT(pos);
 		if(on) {
-			BIT_SET(priv->ledstate[which], pos);
+			BIT_SET(priv->ledstate[which], chan);
 		} else {
-			BIT_CLR(priv->ledstate[which], pos);
+			BIT_CLR(priv->ledstate[which], chan);
 		}
 	}
-	if(!lines)	// Nothing to do
-		goto out;
-	DBG("%s/%s: LED: lines=0x%04X which=%d -- %s\n", xbus->busname, xpd->xpdname, lines, which, (on) ? "on" : "off");
-	XPACKET_NEW(pack, xbus, FXO, DAA_WRITE, xpd->id);
-	sc = &RPACKET_FIELD(pack, FXO, DAA_WRITE, slic_cmd);
-	len = slic_cmd_direct_write(sc, lines, 0x20, on);
-	// DBG("LED pack: line=%d %s\n", i, (on)?"on":"off");
-	pack->datalen = len;
-	packet_send(xbus, pack);
+	DBG("%s/%s/%d: LED: which=%d -- %s\n", xbus->busname, xpd->xpdname, chan, which, (on) ? "on" : "off");
+	ret = DAA_DIRECT_REQUEST(xbus, xpd, chan, DAA_WRITE, 0x20, on);
 out:
 	return ret;
 }
@@ -221,9 +214,6 @@
 	struct FXO_priv_data	*priv;
 	int			ret = 0;
 	bool			value;
-	xpacket_t		*pack;
-	slic_cmd_t		*sc;
-	int			len;
 
 	BUG_ON(!xpd);
 	BUG_ON(xpd->direction == TO_PHONE);		// We can SETHOOK state only on PSTN
@@ -238,11 +228,7 @@
 	value = (to_offhook) ? 0x09 : 0x08;	/* Bit 3 is for CID */
 	DBG("%s/%s/%d: SETHOOK: value=0x%02X %s\n", xbus->busname, xpd->xpdname, pos, value, (to_offhook)?"OFFHOOK":"ONHOOK");
 	MARK_LED(xpd, pos, LED_GREEN, (to_offhook)?LED_ON:LED_OFF);
-	XPACKET_NEW(pack, xbus, FXO, DAA_WRITE, xpd->id);
-	sc = &RPACKET_FIELD(pack, FXO, DAA_WRITE, slic_cmd);
-	len = slic_cmd_direct_write(sc, BIT(pos), DAA_RING_REGISTER, value);
-	pack->datalen = len;
-	packet_send(xbus, pack);
+	ret = DAA_DIRECT_REQUEST(xbus, xpd, pos, DAA_WRITE, DAA_RING_REGISTER, value);
 #ifdef	SOFT_RING
 	priv->ring_sig[pos] = 0;
 #endif
@@ -282,10 +268,10 @@
 	priv = xpd->priv;
 	DBG("%s/%s\n", xbus->busname, xpd->xpdname);
 #ifdef	CONFIG_PROC_FS
-	if(priv->xpd_slic) {
+	if(priv->regfile) {
 		DBG("Removing xpd DAA file %s/%s\n", xbus->busname, xpd->xpdname);
-		remove_proc_entry(PROC_DAA_FNAME, xpd->proc_xpd_dir);
-		priv->xpd_slic = NULL;
+		remove_proc_entry(PROC_REGISTER_FNAME, xpd->proc_xpd_dir);
+		priv->regfile->data = NULL;
 	}
 	if(priv->fxo_info) {
 		DBG("Removing xpd FXO_INFO file %s/%s\n", xbus->busname, xpd->xpdname);
@@ -313,16 +299,16 @@
 	}
 	priv->fxo_info->owner = THIS_MODULE;
 	DBG("Creating DAAs file for %s/%s\n", xbus->busname, xpd->xpdname);
-	priv->xpd_slic = create_proc_entry(PROC_DAA_FNAME, 0644, xpd->proc_xpd_dir);
-	if(!priv->xpd_slic) {
+	priv->regfile = create_proc_entry(PROC_REGISTER_FNAME, 0644, xpd->proc_xpd_dir);
+	if(!priv->regfile) {
 		ERR("Failed to create proc file for DAAs of %s/%s\n", xbus->busname, xpd->xpdname);
 		ret = -ENOENT;
 		goto err;
 	}
-	priv->xpd_slic->owner = THIS_MODULE;
-	priv->xpd_slic->write_proc = proc_xpd_slic_write;
-	priv->xpd_slic->read_proc = proc_xpd_slic_read;
-	priv->xpd_slic->data = xpd;
+	priv->regfile->owner = THIS_MODULE;
+	priv->regfile->write_proc = proc_xpd_register_write;
+	priv->regfile->read_proc = proc_xpd_register_read;
+	priv->regfile->data = xpd;
 #endif
 	ret = run_initialize_registers(xpd);
 	if(ret < 0)
@@ -430,7 +416,7 @@
 	int	i;
 
 	for_each_line(xpd, i) {
-		CALL_PROTO(FXO, DAA_QUERY, xbus, xpd, i, DAA_VBAT_REGISTER);
+		DAA_DIRECT_REQUEST(xbus, xpd, i, DAA_READ, DAA_VBAT_REGISTER, 0);
 	}
 }
 
@@ -444,7 +430,7 @@
 	BUG_ON(!priv);
 	for_each_line(xpd, i) {
 		if(priv->ring_sig[i])
-			CALL_PROTO(FXO, DAA_QUERY, xbus, xpd, i, DAA_RING_REGISTER);
+			DAA_DIRECT_REQUEST(xbus, xpd, i, DAA_READ, DAA_RING_REGISTER, 0);
 	}
 }
 #endif
@@ -496,16 +482,11 @@
 			/* quick and dirty registers writing: */
 			for (i=0; i<sizeof(echotune_reg); i++) {
 				char buf[22];
-				xpp_line_t	lines = BIT(pos);
-				sprintf(buf, "%02X %02X %02X %02X WD %2X %2X",
-					(lines & 0xFF),
-					((lines >> 8) & 0xFF),
-					((lines >> 16) & 0xFF),
-					((lines >> 24) & 0xFF),
-					echotune_reg[i],echoregs.coeff[i]
+				sprintf(buf, "%d WD %2X %2X",
+					pos,echotune_reg[i],echoregs.coeff[i]
 				);
 				/* FIXME: code duplicated from proc_xpd_register_write */
-				ret = process_slic_cmdline(xpd, buf);
+				ret = handle_register_command(xpd, buf);
 				if(ret < 0)
 					return ret;
 				mdelay(1);
@@ -522,17 +503,46 @@
 
 /*---------------- FXO: HOST COMMANDS -------------------------------------*/
 
-static /* 0x0F */ HOSTCMD(FXO, CHAN_ENABLE, xpp_line_t lines, bool on)
+/* 0x0F */ HOSTCMD(FXO, REGISTER_REQUEST, byte chipsel, bool writing, bool do_subreg, byte regnum, byte subreg, byte data_low, byte data_high)
+{
+	int		ret = 0;
+	xpacket_t	*pack;
+	reg_cmd_t	*reg_cmd;
+
+	if(!xbus) {
+		DBG("NO XBUS\n");
+		return -EINVAL;
+	}
+	XPACKET_NEW(pack, xbus, GLOBAL, REGISTER_REQUEST, xpd->id);
+#if 0
+	DBG("%s/%s/%d: %c%c R%02X S%02X %02X %02X\n",
+			xbus->busname, xpd->xpdname, chipsel,
+			(writing)?'W':'R',
+			(do_subreg)?'S':'D',
+			regnum, subreg, data_low, data_high);
+#endif
+	reg_cmd = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REQUEST, reg_cmd);
+	pack->datalen = sizeof(*reg_cmd);
+	reg_cmd->bytes = sizeof(*reg_cmd) - 1;	// do not count the 'bytes' field
+	REG_FIELD(reg_cmd, chipsel) = chipsel;
+	REG_FIELD(reg_cmd, read_request) = (writing) ? 0 : 1;
+	REG_FIELD(reg_cmd, do_subreg) = do_subreg;
+	REG_FIELD(reg_cmd, regnum) = regnum;
+	REG_FIELD(reg_cmd, subreg) = subreg;
+	REG_FIELD(reg_cmd, data_low) = data_low;
+	REG_FIELD(reg_cmd, data_high) = data_high;
+	ret = packet_send(xbus, pack);
+	return ret;
+}
+
+static /* 0x0F */ HOSTCMD(FXO, XPD_STATE, bool on)
 {
 	int	ret = 0;
 	int	i;
 
 	BUG_ON(!xbus);
 	BUG_ON(!xpd);
-	if(!lines) {
-		return 0;
-	}
-	DBG("Channel Activation: 0x%4X %s\n", lines, (on) ? "on" : "off");
+	DBG("%s/%s: %s\n", xbus->busname, xpd->xpdname, (on) ? "on" : "off");
 	if(on) {
 		for_each_line(xpd, i) {
 			MARK_LED(xpd, i, LED_GREEN, LED_ON);
@@ -546,67 +556,28 @@
 	return ret;
 }
 
-static /* 0x0F */ HOSTCMD(FXO, CHAN_CID, int pos)
+static /* 0x0F */ HOSTCMD(FXO, CHAN_CID, lineno_t chan)
 {
 	int		ret = 0;
-	xpp_line_t	lines = BIT(pos);
 
 	BUG_ON(!xbus);
 	BUG_ON(!xpd);
-	if(!lines) {
-		return 0;
-	}
-	DBG("%s/%s/%d:\n", xbus->busname, xpd->xpdname, pos);
+	DBG("%s/%s/%d:\n", xbus->busname, xpd->xpdname, chan);
 	return ret;
 }
 
 
-static /* 0x0F */ HOSTCMD(FXO, RING, int pos, bool on)
-{
-	int		ret = 0;
-	xpacket_t	*pack;
-	slic_cmd_t	*sc;
-	xpp_line_t	mask = BIT(pos);
-	int		len;
-
+static /* 0x0F */ HOSTCMD(FXO, RING, lineno_t chan, bool on)
+{
 	BUG_ON(!xbus);
 	BUG_ON(!xpd);
-	if(!mask) {
-		return 0;
-	}
-	DBG("%s/%s/%d %s\n", xpd->xbus->busname, xpd->xpdname, pos, (on) ? "on" : "off");
-	XPACKET_NEW(pack, xbus, FXO, DAA_WRITE, xpd->id);
-	sc = &RPACKET_FIELD(pack, FXO, DAA_WRITE, slic_cmd);
-	len = slic_cmd_direct_write(sc, mask, 0x40, (on)?0x04:0x01);
-	pack->datalen = len;
-
-	packet_send(xbus, pack);
-	return ret;
+	DBG("%s/%s/%d: %s\n", xbus->busname, xpd->xpdname, chan, (on) ? "on" : "off");
+	return DAA_DIRECT_REQUEST(xbus, xpd, chan, DAA_WRITE, 0x40, (on)?0x04:0x01);
 }
 
 static /* 0x0F */ HOSTCMD(FXO, RELAY_OUT, byte which, bool on)
 {
 	return -ENOSYS;
-}
-
-static /* 0x0F */ HOSTCMD(FXO, DAA_QUERY, int pos, byte reg_num)
-{
-	int	ret = 0;
-	xpacket_t	*pack;
-	slic_cmd_t	*sc;
-	int		len;
-
-	BUG_ON(!xbus);
-	BUG_ON(!xpd);
-	// DBG("\n");
-	XPACKET_NEW(pack, xbus, FXO, DAA_WRITE, xpd->id);
-	sc = &RPACKET_FIELD(pack, FXO, DAA_WRITE, slic_cmd);
-	len = slic_cmd_direct_read(sc, BIT(pos), reg_num);
-
-	pack->datalen = len;
-
-	packet_send(xbus, pack);
-	return ret;
 }
 
 /*---------------- FXO: Astribank Reply Handlers --------------------------*/
@@ -658,10 +629,10 @@
 
 HANDLER_DEF(FXO, DAA_REPLY)
 {
-	slic_reply_t		*info = &RPACKET_FIELD(pack, FXO, DAA_REPLY, info);
-	xpp_line_t		lines = RPACKET_FIELD(pack, FXO, DAA_REPLY, lines);
+	reg_cmd_t		*info = &RPACKET_FIELD(pack, FXO, DAA_REPLY, regcmd);
 	unsigned long		flags;
 	struct FXO_priv_data	*priv;
+	lineno_t		chipsel;
 
 	if(!xpd) {
 		NOTICE("%s: received %s for non-existing xpd: %d\n",
@@ -671,68 +642,62 @@
 	spin_lock_irqsave(&xpd->lock, flags);
 	priv = xpd->priv;
 	BUG_ON(!priv);
-	if(!info->indirect && info->reg_num == DAA_VBAT_REGISTER) {
-		byte		bat = abs((signed char)info->data_low);
-		int		i;
-
-		for_each_line(xpd, i) {
-			if(!IS_SET(lines, i))
-				continue;
-			if(bat < BAT_THRESHOLD) {
-				/*
-				 * Check for battery voltage fluctuations
-				 */
-				if(IS_SET(priv->battery, i) && priv->battery_debounce[i]++ > BAT_DEBOUNCE) {
-					DBG("%s/%s: BATTERY OFF (%04X) voltage=%d\n", xpd->xbus->busname, xpd->xpdname, lines, bat);
-					BIT_CLR(priv->battery, i);
-					update_line_status(xpd, i, 0);
-				}
-			} else {
-				priv->battery_debounce[i] = 0;
-				if(!IS_SET(priv->battery, i)) {
-					DBG("%s/%s: BATTERY ON (%04X) voltage=%d\n", xpd->xbus->busname, xpd->xpdname, lines, bat);
-					BIT_SET(priv->battery, i);
-				}
+	chipsel = REG_FIELD(info, chipsel);
+
+	/*
+	 * Update battery status
+	 */
+	if(REG_FIELD(info, regnum) == DAA_VBAT_REGISTER) {
+		byte		bat = abs((signed char)REG_FIELD(info, data_low));
+
+		if(bat < BAT_THRESHOLD) {
+			/*
+			 * Check for battery voltage fluctuations
+			 */
+			if(IS_SET(priv->battery, chipsel) && priv->battery_debounce[chipsel]++ > BAT_DEBOUNCE) {
+				DBG("%s/%s/%d: BATTERY OFF voltage=%d\n", xpd->xbus->busname, xpd->xpdname, chipsel, bat);
+				BIT_CLR(priv->battery, chipsel);
+				update_line_status(xpd, chipsel, 0);
+			}
+		} else {
+			priv->battery_debounce[chipsel] = 0;
+			if(!IS_SET(priv->battery, chipsel)) {
+				DBG("%s/%s/%d: BATTERY ON voltage=%d\n", xpd->xbus->busname, xpd->xpdname, chipsel, bat);
+				BIT_SET(priv->battery, chipsel);
 			}
 		}
 	}
 #ifdef	SOFT_RING
-	if(!info->indirect && info->reg_num == DAA_RING_REGISTER) {
-		bool		ringit = (info->data_low & (0x20 | 0x40)) ? 1 : 0;	/* Ring positive | Ring negative */
-		int		i;
-
-		for_each_line(xpd, i) {
-			if(!IS_SET(lines, i))
-				continue;
-			if (!priv->ring_sig[i])
-				continue;
-			if(ringit) {
-				if(priv->ring_thresh[i] > RING_THRESHOLD) {
-					mark_ring(xpd, i, 1);
-					priv->noring_thresh[i] = 0;
-				} else
-					priv->ring_thresh[i]++;
-			} else {
-				if(priv->noring_thresh[i] > NORING_THRESHOLD) {
-					mark_ring(xpd, i, 0);
-					priv->ring_thresh[i] = 0;
-				} else
-					priv->noring_thresh[i]++;
-			}
+	if(REG_FIELD(info, regnum) == DAA_RING_REGISTER && priv->ring_sig[chipsel]) {
+		bool		ringit = (REG_FIELD(info, data_low) & (0x20 | 0x40)) ? 1 : 0;	/* Ring positive | Ring negative */
+
+		if(ringit) {
+			if(priv->ring_thresh[chipsel] > RING_THRESHOLD) {
+				mark_ring(xpd, chipsel, 1);
+				priv->noring_thresh[chipsel] = 0;
+			} else
+				priv->ring_thresh[chipsel]++;
+		} else {
+			if(priv->noring_thresh[chipsel] > NORING_THRESHOLD) {
+				mark_ring(xpd, chipsel, 0);
+				priv->ring_thresh[chipsel] = 0;
+			} else
+				priv->noring_thresh[chipsel]++;
 		}
 	}
 #endif
 #if 0
-	if (info->reg_num != 29) 
 	DBG("DAA_REPLY: xpd #%d %s reg_num=0x%X, dataL=0x%X dataH=0x%X\n",
-			xpd->id, (info->indirect)?"I":"D",
+			xpd->id, (info->size == 3)?"I":"D",
 			info->reg_num, info->data_low, info->data_high);
 #endif
 
 	/* Update /proc info only if reply relate to the last slic read request */

[... 6247 lines stripped ...]


More information about the zaptel-commits mailing list