xpp: style - Run Lindent
authorOron Peled <oron.peled@xorcom.com>
Wed, 11 Jan 2012 15:22:46 +0000 (15:22 +0000)
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>
Wed, 11 Jan 2012 15:22:46 +0000 (15:22 +0000)
* Here it is:
  KERNEL_STYLE="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1"
  TYPEDEFS='
-T gfp_t
-T __user
-T u_char
-T __u8
-T byte
-T bool
-T charp
-T xusb_t
-T xbus_t
-T xpd_t
-T xproto_table_t
-T xproto_entry_t
-T xframe_t
-T xpacket_t
-T reg_cmd_t
'

  indent $TYPEDEFS $KERNEL_STYLE \
--ignore-newlines \
--indent-label0 \
--no-space-after-function-call-names \
"$@"

Signed-off-by: Oron Peled <oron.peled@xorcom.com>
Acked-By: Tzafrir Cohen <tzafrir.cohen@xorcom.com>

git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@10428 a0bf4364-ded3-4de4-8d8a-66a801d63aff

33 files changed:
drivers/dahdi/xpp/card_bri.c
drivers/dahdi/xpp/card_bri.h
drivers/dahdi/xpp/card_echo.c
drivers/dahdi/xpp/card_echo.h
drivers/dahdi/xpp/card_fxo.c
drivers/dahdi/xpp/card_fxo.h
drivers/dahdi/xpp/card_fxs.c
drivers/dahdi/xpp/card_fxs.h
drivers/dahdi/xpp/card_global.c
drivers/dahdi/xpp/card_global.h
drivers/dahdi/xpp/card_pri.c
drivers/dahdi/xpp/card_pri.h
drivers/dahdi/xpp/dahdi_debug.c
drivers/dahdi/xpp/dahdi_debug.h
drivers/dahdi/xpp/mmapbus.c
drivers/dahdi/xpp/mmapdrv.c
drivers/dahdi/xpp/parport_debug.c
drivers/dahdi/xpp/parport_debug.h
drivers/dahdi/xpp/print_fxo_modes.c
drivers/dahdi/xpp/xbus-core.c
drivers/dahdi/xpp/xbus-core.h
drivers/dahdi/xpp/xbus-pcm.c
drivers/dahdi/xpp/xbus-pcm.h
drivers/dahdi/xpp/xbus-sysfs.c
drivers/dahdi/xpp/xdefs.h
drivers/dahdi/xpp/xframe_queue.c
drivers/dahdi/xpp/xframe_queue.h
drivers/dahdi/xpp/xpd.h
drivers/dahdi/xpp/xpp_dahdi.c
drivers/dahdi/xpp/xpp_dahdi.h
drivers/dahdi/xpp/xpp_usb.c
drivers/dahdi/xpp/xproto.c
drivers/dahdi/xpp/xproto.h

index f4addc3..30598f2 100644 (file)
@@ -40,30 +40,32 @@ static const char rcsid[] = "$Id$";
 #endif
 
 static DEF_PARM(int, debug, 0, 0644, "Print DBG statements");  /* must be before dahdi_debug.h */
-static DEF_PARM(uint, poll_interval, 500, 0644, "Poll channel state interval in milliseconds (0 - disable)");
-static DEF_PARM_BOOL(nt_keepalive, 1, 0644, "Force BRI_NT to keep trying connection");
+static DEF_PARM(uint, poll_interval, 500, 0644,
+               "Poll channel state interval in milliseconds (0 - disable)");
+static DEF_PARM_BOOL(nt_keepalive, 1, 0644,
+                    "Force BRI_NT to keep trying connection");
 
 enum xhfc_states {
-       ST_RESET                = 0,    /* G/F0 */
+       ST_RESET = 0,           /* G/F0 */
        /* TE */
-       ST_TE_SENSING           = 2,    /* F2   */
-       ST_TE_DEACTIVATED       = 3,    /* F3   */
-       ST_TE_SIGWAIT           = 4,    /* F4   */
-       ST_TE_IDENT             = 5,    /* F5   */
-       ST_TE_SYNCED            = 6,    /* F6   */
-       ST_TE_ACTIVATED         = 7,    /* F7   */
-       ST_TE_LOST_FRAMING      = 8,    /* F8   */
+       ST_TE_SENSING = 2,      /* F2   */
+       ST_TE_DEACTIVATED = 3,  /* F3   */
+       ST_TE_SIGWAIT = 4,      /* F4   */
+       ST_TE_IDENT = 5,        /* F5   */
+       ST_TE_SYNCED = 6,       /* F6   */
+       ST_TE_ACTIVATED = 7,    /* F7   */
+       ST_TE_LOST_FRAMING = 8, /* F8   */
        /* NT */
-       ST_NT_DEACTIVATED       = 1,    /* G1   */
-       ST_NT_ACTIVATING        = 2,    /* G2   */
-       ST_NT_ACTIVATED         = 3,    /* G3   */
-       ST_NT_DEACTIVTING       = 4,    /* G4   */
+       ST_NT_DEACTIVATED = 1,  /* G1   */
+       ST_NT_ACTIVATING = 2,   /* G2   */
+       ST_NT_ACTIVATED = 3,    /* G3   */
+       ST_NT_DEACTIVTING = 4,  /* G4   */
 };
 
 #ifdef CONFIG_PROC_FS
 static const char *xhfc_state_name(bool is_nt, enum xhfc_states state)
 {
-       const char      *p;
+       const char *p;
 
 #define        _E(x)   [ST_ ## x] = #x
        static const char *te_names[] = {
@@ -111,9 +113,9 @@ static const char *xhfc_state_name(bool is_nt, enum xhfc_states state)
 #define        HFC_TIMER_T3            8000    /* 8s activation timer T3 */
 #define        HFC_TIMER_OFF           -1      /* timer disabled */
 
-#define        A_SU_WR_STA             0x30    /* ST/Up state machine register         */
+#define        A_SU_WR_STA             0x30    /* ST/Up state machine register         */
 #define                V_SU_LD_STA     0x10
-#define        V_SU_ACT        0x60    /* start activation/deactivation        */
+#define        V_SU_ACT        0x60    /* start activation/deactivation        */
 #define        STA_DEACTIVATE  0x40    /* start deactivation in A_SU_WR_STA */
 #define        STA_ACTIVATE    0x60    /* start activation   in A_SU_WR_STA */
 #define        V_SU_SET_G2_G3  0x80
@@ -121,13 +123,13 @@ static const char *xhfc_state_name(bool is_nt, enum xhfc_states state)
 #define        A_SU_RD_STA             0x30
 typedef union {
        struct {
-               __u8    v_su_sta:4;
-               __u8    v_su_fr_sync:1;
-               __u8    v_su_t2_exp:1;
-               __u8    v_su_info0:1;
-               __u8    v_g2_g3:1;
+               __u8 v_su_sta:4;
+               __u8 v_su_fr_sync:1;
+               __u8 v_su_t2_exp:1;
+               __u8 v_su_info0:1;
+               __u8 v_g2_g3:1;
        } bits;
-       __u8    reg;
+       __u8 reg;
 } su_rd_sta_t;
 
 #define        REG30_LOST      3       /* in polls */
@@ -149,7 +151,8 @@ static int write_state_register(xpd_t *xpd, __u8 value);
 static bool bri_packet_is_valid(xpacket_t *pack);
 static void bri_packet_dump(const char *msg, xpacket_t *pack);
 #ifdef CONFIG_PROC_FS
-static int proc_bri_info_read(char *page, char **start, off_t off, int count, int *eof, void *data);
+static int proc_bri_info_read(char *page, char **start, off_t off, int count,
+                             int *eof, void *data);
 #endif
 static int bri_spanconfig(struct file *file, struct dahdi_span *span,
                          struct dahdi_lineconfig *lc);
@@ -162,29 +165,28 @@ static int bri_shutdown(struct dahdi_span *span);
 #define        PROC_BRI_INFO_FNAME     "bri_info"
 
 enum led_state {
-       BRI_LED_OFF             = 0x0,
-       BRI_LED_ON              = 0x1,
+       BRI_LED_OFF = 0x0,
+       BRI_LED_ON = 0x1,
        /*
         * We blink by software from driver, so that
         * if the driver malfunction that blink would stop.
         */
-       // BRI_LED_BLINK_SLOW   = 0x2,  /* 1/2 a second blink cycle */
-       // BRI_LED_BLINK_FAST   = 0x3   /* 1/4 a second blink cycle */
+       // BRI_LED_BLINK_SLOW   = 0x2,  /* 1/2 a second blink cycle */
+       // BRI_LED_BLINK_FAST   = 0x3   /* 1/4 a second blink cycle */
 };
 
 enum bri_led_names {
-       GREEN_LED       = 0,
-       RED_LED         = 1
+       GREEN_LED = 0,
+       RED_LED = 1
 };
 
 #define        NUM_LEDS        2
 #define        LED_TICKS       100
 
-
 struct bri_leds {
-       __u8    state:2;
-       __u8    led_sel:1;      /* 0 - GREEN, 1 - RED */
-       __u8    reserved:5;
+       __u8 state:2;
+       __u8 led_sel:1;         /* 0 - GREEN, 1 - RED */
+       __u8 reserved:5;
 };
 
 #ifndef MAX_DFRAME_LEN_L1
@@ -194,42 +196,41 @@ struct bri_leds {
 #define        DCHAN_BUFSIZE   MAX_DFRAME_LEN_L1
 
 struct BRI_priv_data {
-       struct proc_dir_entry           *bri_info;
-       su_rd_sta_t                     state_register;
-       bool                            initialized;
-       int                             t1;     /* timer 1 for NT deactivation */
-       int                             t3;     /* timer 3 for TE activation */
-       ulong                           l1_flags;
-       bool                            reg30_good;
-       uint                            reg30_ticks;
-       bool                            layer1_up;
+       struct proc_dir_entry *bri_info;
+       su_rd_sta_t state_register;
+       bool initialized;
+       int t1;                 /* timer 1 for NT deactivation */
+       int t3;                 /* timer 3 for TE activation */
+       ulong l1_flags;
+       bool reg30_good;
+       uint reg30_ticks;
+       bool layer1_up;
 
        /*
         * D-Chan: buffers + extra state info.
         */
-       atomic_t                        hdlc_pending;
-       bool                            txframe_begin;
-
-       uint                            tick_counter;
-       uint                            poll_counter;
-       uint                            dchan_tx_counter;
-       uint                            dchan_rx_counter;
-       uint                            dchan_rx_drops;
-       bool                            dchan_alive;
-       uint                            dchan_alive_ticks;
-       uint                            dchan_notx_ticks;
-       uint                            dchan_norx_ticks;
-       enum led_state                  ledstate[NUM_LEDS];
+       atomic_t hdlc_pending;
+       bool txframe_begin;
+
+       uint tick_counter;
+       uint poll_counter;
+       uint dchan_tx_counter;
+       uint dchan_rx_counter;
+       uint dchan_rx_drops;
+       bool dchan_alive;
+       uint dchan_alive_ticks;
+       uint dchan_notx_ticks;
+       uint dchan_norx_ticks;
+       enum led_state ledstate[NUM_LEDS];
 };
 
-static xproto_table_t  PROTO_TABLE(BRI);
-
+static xproto_table_t PROTO_TABLE(BRI);
 
 DEF_RPACKET_DATA(BRI, SET_LED, /* Set one of the LED's */
-       struct bri_leds         bri_leds;
-       );
+                struct bri_leds bri_leds;);
 
-static /* 0x33 */ DECLARE_CMD(BRI, SET_LED, enum bri_led_names which_led, enum led_state to_led_state);
+static /* 0x33 */ DECLARE_CMD(BRI, SET_LED, enum bri_led_names which_led,
+                             enum led_state to_led_state);
 
 #define        DO_LED(xpd, which, tostate)     \
                        CALL_PROTO(BRI, SET_LED, (xpd)->xbus, (xpd), (which), (tostate))
@@ -237,24 +238,25 @@ static /* 0x33 */ DECLARE_CMD(BRI, SET_LED, enum bri_led_names which_led, enum l
 #define DEBUG_BUF_SIZE (100)
 static void dump_hex_buf(xpd_t *xpd, char *msg, __u8 *buf, size_t len)
 {
-       char    debug_buf[DEBUG_BUF_SIZE + 1];
-       int     i;
-       int     n = 0;
+       char debug_buf[DEBUG_BUF_SIZE + 1];
+       int i;
+       int n = 0;
 
        debug_buf[0] = '\0';
        for (i = 0; i < len && n < DEBUG_BUF_SIZE; i++)
-               n += snprintf(&debug_buf[n], DEBUG_BUF_SIZE - n, "%02X ", buf[i]);
-       XPD_NOTICE(xpd, "%s[0..%zd]: %s%s\n", msg, len-1, debug_buf,
-                       (n >= DEBUG_BUF_SIZE)?"...":"");
+               n += snprintf(&debug_buf[n], DEBUG_BUF_SIZE - n, "%02X ",
+                             buf[i]);
+       XPD_NOTICE(xpd, "%s[0..%zd]: %s%s\n", msg, len - 1, debug_buf,
+                  (n >= DEBUG_BUF_SIZE) ? "..." : "");
 }
 
 static void dump_dchan_packet(xpd_t *xpd, bool transmit, __u8 *buf, int len)
 {
-       struct BRI_priv_data    *priv;
-       char    msgbuf[MAX_PROC_WRITE];
-       char    ftype = '?';
-       char    *direction;
-       int     frame_begin;
+       struct BRI_priv_data *priv;
+       char msgbuf[MAX_PROC_WRITE];
+       char ftype = '?';
+       char *direction;
+       int frame_begin;
 
        priv = xpd->priv;
        BUG_ON(!priv);
@@ -275,14 +277,16 @@ static void dump_dchan_packet(xpd_t *xpd, bool transmit, __u8 *buf, int len)
                else
                        XPD_NOTICE(xpd, "Unknown frame type 0x%X\n", buf[0]);
 
-               snprintf(msgbuf, MAX_PROC_WRITE, "D-Chan %s = (%c) ", direction, ftype);
+               snprintf(msgbuf, MAX_PROC_WRITE, "D-Chan %s = (%c) ", direction,
+                        ftype);
        } else {
                snprintf(msgbuf, MAX_PROC_WRITE, "D-Chan %s =     ", direction);
        }
        dump_hex_buf(xpd, msgbuf, buf, len);
 }
 
-static void set_bri_timer(xpd_t *xpd, const char *name, int *bri_timer, int value)
+static void set_bri_timer(xpd_t *xpd, const char *name, int *bri_timer,
+                         int value)
 {
        if (value == HFC_TIMER_OFF)
                XPD_DBG(SIGNAL, xpd, "Timer %s DISABLE\n", name);
@@ -293,7 +297,7 @@ static void set_bri_timer(xpd_t *xpd, const char *name, int *bri_timer, int valu
 
 static void dchan_state(xpd_t *xpd, bool up)
 {
-       struct BRI_priv_data    *priv;
+       struct BRI_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -305,7 +309,8 @@ static void dchan_state(xpd_t *xpd, bool up)
                priv->dchan_alive = 1;
        } else {
                XPD_DBG(SIGNAL, xpd, "STATE CHANGE: D-Channel STOPPED\n");
-               priv->dchan_rx_counter = priv->dchan_tx_counter = priv->dchan_rx_drops = 0;
+               priv->dchan_rx_counter = priv->dchan_tx_counter =
+                   priv->dchan_rx_drops = 0;
                priv->dchan_alive = 0;
                priv->dchan_alive_ticks = 0;
        }
@@ -313,7 +318,7 @@ static void dchan_state(xpd_t *xpd, bool up)
 
 static void layer1_state(xpd_t *xpd, bool up)
 {
-       struct BRI_priv_data    *priv;
+       struct BRI_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -321,21 +326,21 @@ static void layer1_state(xpd_t *xpd, bool up)
        if (priv->layer1_up == up)
                return;
        priv->layer1_up = up;
-       XPD_DBG(SIGNAL, xpd, "STATE CHANGE: Layer1 %s\n", (up)?"UP":"DOWN");
+       XPD_DBG(SIGNAL, xpd, "STATE CHANGE: Layer1 %s\n", (up) ? "UP" : "DOWN");
        if (!up)
                dchan_state(xpd, 0);
 }
 
 static void te_activation(xpd_t *xpd, bool on)
 {
-       struct BRI_priv_data    *priv;
-       __u8                    curr_state;
+       struct BRI_priv_data *priv;
+       __u8 curr_state;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
        BUG_ON(!priv);
        curr_state = priv->state_register.bits.v_su_sta;
-       XPD_DBG(SIGNAL, xpd, "%s\n", (on)?"ON":"OFF");
+       XPD_DBG(SIGNAL, xpd, "%s\n", (on) ? "ON" : "OFF");
        if (on) {
                if (curr_state == ST_TE_DEACTIVATED) {
                        XPD_DBG(SIGNAL, xpd, "HFC_L1_ACTIVATE_TE\n");
@@ -347,84 +352,84 @@ static void te_activation(xpd_t *xpd, bool on)
                                "HFC_L1_ACTIVATE_TE (state %d, ignored)\n",
                                curr_state);
                }
-       } else {        /* happen only because of T3 expiry */
+       } else {                /* happen only because of T3 expiry */
                switch (curr_state) {
-                       case ST_TE_DEACTIVATED:         /* F3   */
-                       case ST_TE_SYNCED:              /* F6   */
-                       case ST_TE_ACTIVATED:           /* F7   */
-                               XPD_DBG(SIGNAL, xpd,
-                                       "HFC_L1_FORCE_DEACTIVATE_TE (state %d, ignored)\n",
-                                       curr_state);
-                               break;
-                       case ST_TE_SIGWAIT:             /* F4   */
-                       case ST_TE_IDENT:               /* F5   */
-                       case ST_TE_LOST_FRAMING:        /* F8   */
-                               XPD_DBG(SIGNAL, xpd, "HFC_L1_FORCE_DEACTIVATE_TE\n");
-                               write_state_register(xpd, STA_DEACTIVATE);
-                               break;
-                       default:
-                               XPD_NOTICE(xpd, "Bad TE state: %d\n", curr_state);
-                               break;
+               case ST_TE_DEACTIVATED: /* F3   */
+               case ST_TE_SYNCED:      /* F6   */
+               case ST_TE_ACTIVATED:   /* F7   */
+                       XPD_DBG(SIGNAL, xpd,
+                               "HFC_L1_FORCE_DEACTIVATE_TE (state %d, ignored)\n",
+                               curr_state);
+                       break;
+               case ST_TE_SIGWAIT:     /* F4   */
+               case ST_TE_IDENT:       /* F5   */
+               case ST_TE_LOST_FRAMING:        /* F8   */
+                       XPD_DBG(SIGNAL, xpd, "HFC_L1_FORCE_DEACTIVATE_TE\n");
+                       write_state_register(xpd, STA_DEACTIVATE);
+                       break;
+               default:
+                       XPD_NOTICE(xpd, "Bad TE state: %d\n", curr_state);
+                       break;
                }
        }
 }
 
 static void nt_activation(xpd_t *xpd, bool on)
 {
-       struct BRI_priv_data    *priv;
-       __u8                    curr_state;
+       struct BRI_priv_data *priv;
+       __u8 curr_state;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
        BUG_ON(!priv);
        curr_state = priv->state_register.bits.v_su_sta;
-       XPD_DBG(SIGNAL, xpd, "%s\n", (on)?"ON":"OFF");
+       XPD_DBG(SIGNAL, xpd, "%s\n", (on) ? "ON" : "OFF");
        if (on) {
                switch (curr_state) {
-                       case ST_RESET:                  /* F/G 0 */
-                       case ST_NT_DEACTIVATED:         /* G1 */
-                       case ST_NT_DEACTIVTING:         /* G4 */
-                               XPD_DBG(SIGNAL, xpd, "HFC_L1_ACTIVATE_NT\n");
-                               set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_T1);
-                               set_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
-                               write_state_register(xpd, STA_ACTIVATE);
-                               break;
-                       case ST_NT_ACTIVATING:          /* G2 */
-                       case ST_NT_ACTIVATED:           /* G3 */
-                               XPD_DBG(SIGNAL, xpd,
-                                               "HFC_L1_ACTIVATE_NT (in state %d, ignored)\n",
-                                               curr_state);
-                               break;
+               case ST_RESET:  /* F/G 0 */
+               case ST_NT_DEACTIVATED: /* G1 */
+               case ST_NT_DEACTIVTING: /* G4 */
+                       XPD_DBG(SIGNAL, xpd, "HFC_L1_ACTIVATE_NT\n");
+                       set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_T1);
+                       set_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
+                       write_state_register(xpd, STA_ACTIVATE);
+                       break;
+               case ST_NT_ACTIVATING:  /* G2 */
+               case ST_NT_ACTIVATED:   /* G3 */
+                       XPD_DBG(SIGNAL, xpd,
+                               "HFC_L1_ACTIVATE_NT (in state %d, ignored)\n",
+                               curr_state);
+                       break;
                }
        } else {
                switch (curr_state) {
-                       case ST_RESET:                  /* F/G 0 */
-                       case ST_NT_DEACTIVATED:         /* G1 */
-                       case ST_NT_DEACTIVTING:         /* G4 */
-                               XPD_DBG(SIGNAL, xpd,
-                                               "HFC_L1_DEACTIVATE_NT (in state %d, ignored)\n",
-                                               curr_state);
-                               break;
-                       case ST_NT_ACTIVATING:          /* G2 */
-                       case ST_NT_ACTIVATED:           /* G3 */
-                               XPD_DBG(SIGNAL, xpd, "HFC_L1_DEACTIVATE_NT\n");
-                               write_state_register(xpd, STA_DEACTIVATE);
-                               break;
-                       default:
-                               XPD_NOTICE(xpd, "Bad NT state: %d\n", curr_state);
-                               break;
+               case ST_RESET:  /* F/G 0 */
+               case ST_NT_DEACTIVATED: /* G1 */
+               case ST_NT_DEACTIVTING: /* G4 */
+                       XPD_DBG(SIGNAL, xpd,
+                               "HFC_L1_DEACTIVATE_NT (in state %d, ignored)\n",
+                               curr_state);
+                       break;
+               case ST_NT_ACTIVATING:  /* G2 */
+               case ST_NT_ACTIVATED:   /* G3 */
+                       XPD_DBG(SIGNAL, xpd, "HFC_L1_DEACTIVATE_NT\n");
+                       write_state_register(xpd, STA_DEACTIVATE);
+                       break;
+               default:
+                       XPD_NOTICE(xpd, "Bad NT state: %d\n", curr_state);
+                       break;
                }
        }
 }
 
-
 /*
  * D-Chan receive
  */
-static int bri_check_stat(xpd_t *xpd, struct dahdi_chan *dchan, __u8 *buf, int len)
+static int bri_check_stat(xpd_t *xpd, struct dahdi_chan *dchan, __u8 *buf,
+                         int len)
 {
-       struct BRI_priv_data    *priv;
-       __u8                    status;
+       struct BRI_priv_data *priv;
+       __u8 status;
 
        priv = xpd->priv;
        BUG_ON(!priv);
@@ -433,9 +438,9 @@ static int bri_check_stat(xpd_t *xpd, struct dahdi_chan *dchan, __u8 *buf, int l
                dahdi_hdlc_abort(dchan, DAHDI_EVENT_ABORT);
                return -EPROTO;
        }
-       status = buf[len-1];
+       status = buf[len - 1];
        if (status) {
-               int     event = DAHDI_EVENT_ABORT;
+               int event = DAHDI_EVENT_ABORT;
 
                if (status == 0xFF) {
                        XPD_NOTICE(xpd, "D-Chan RX DROP: ABORT: %d\n", status);
@@ -452,19 +457,19 @@ static int bri_check_stat(xpd_t *xpd, struct dahdi_chan *dchan, __u8 *buf, int l
 
 static int rx_dchan(xpd_t *xpd, reg_cmd_t *regcmd)
 {
-       struct BRI_priv_data    *priv;
-       __u8                    *src;
-       struct dahdi_chan       *dchan;
-       uint                    len;
-       bool                    eoframe;
-       int                     ret = 0;
+       struct BRI_priv_data *priv;
+       __u8 *src;
+       struct dahdi_chan *dchan;
+       uint len;
+       bool eoframe;
+       int ret = 0;
 
        src = REG_XDATA(regcmd);
        len = regcmd->bytes;
        eoframe = regcmd->eoframe;
        if (len <= 0)
                return 0;
-       if (!SPAN_REGISTERED(xpd)) /* Nowhere to copy data */
+       if (!SPAN_REGISTERED(xpd))      /* Nowhere to copy data */
                return 0;
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -501,9 +506,9 @@ out:
 /* DAHDI calls this when it has data it wants to send to the HDLC controller */
 static void bri_hdlc_hard_xmit(struct dahdi_chan *chan)
 {
-       xpd_t                   *xpd = chan->pvt;
-       struct dahdi_chan       *dchan;
-       struct BRI_priv_data    *priv;
+       xpd_t *xpd = chan->pvt;
+       struct dahdi_chan *dchan;
+       struct BRI_priv_data *priv;
 
        priv = xpd->priv;
        BUG_ON(!priv);
@@ -521,8 +526,9 @@ static int send_dchan_frame(xpd_t *xpd, xframe_t *xframe, bool is_eof)
        XPD_DBG(COMMANDS, xpd, "eoframe=%d\n", is_eof);
        priv = xpd->priv;
        if (!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags)
-                       && !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) {
-               XPD_DBG(SIGNAL, xpd, "Want to transmit: Kick D-Channel transmiter\n");
+           && !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) {
+               XPD_DBG(SIGNAL, xpd,
+                       "Want to transmit: Kick D-Channel transmiter\n");
                if (!IS_NT(xpd))
                        te_activation(xpd, 1);
                else
@@ -545,8 +551,8 @@ static int send_dchan_frame(xpd_t *xpd, xframe_t *xframe, bool is_eof)
 /*
  * Fill a single multibyte REGISTER_REQUEST
  */
-static void fill_multibyte(xpd_t *xpd, xpacket_t *pack, bool eoframe,
-               char *buf, int len)
+static void fill_multibyte(xpd_t *xpd, xpacket_t *pack, bool eoframe, char *buf,
+                          int len)
 {
        reg_cmd_t *reg_cmd;
        char *p;
@@ -587,14 +593,14 @@ static int tx_dchan(xpd_t *xpd)
        BUG_ON(!priv);
        if (atomic_read(&priv->hdlc_pending) == 0)
                return 0;
-       if (!SPAN_REGISTERED(xpd) ||
-                       !(PHONEDEV(xpd).span.flags & DAHDI_FLAG_RUNNING))
+       if (!SPAN_REGISTERED(xpd)
+           || !(PHONEDEV(xpd).span.flags & DAHDI_FLAG_RUNNING))
                return 0;
        /* Allocate frame */
        xframe = ALLOC_SEND_XFRAME(xpd->xbus);
        if (!xframe) {
                XPD_NOTICE(xpd, "%s: failed to allocate new xframe\n",
-                       __func__);
+                          __func__);
                return -ENOMEM;
        }
        for (packet_count = 0, eoframe = 0; !eoframe; packet_count++) {
@@ -609,9 +615,8 @@ static int tx_dchan(xpd_t *xpd)
                        /*
                         * A split. Send what we currently have.
                         */
-                       XPD_NOTICE(xpd,
-                               "%s: xframe is full (%d packets)\n",
-                               __func__, packet_count);
+                       XPD_NOTICE(xpd, "%s: xframe is full (%d packets)\n",
+                                  __func__, packet_count);
                        break;
                }
                /* Get data from DAHDI */
@@ -639,7 +644,7 @@ static int tx_dchan(xpd_t *xpd)
 
 static void bri_proc_remove(xbus_t *xbus, xpd_t *xpd)
 {
-       struct BRI_priv_data    *priv;
+       struct BRI_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -654,16 +659,19 @@ static void bri_proc_remove(xbus_t *xbus, xpd_t *xpd)
 
 static int bri_proc_create(xbus_t *xbus, xpd_t *xpd)
 {
-       struct BRI_priv_data    *priv;
+       struct BRI_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
        XPD_DBG(PROC, xpd, "\n");
 #ifdef CONFIG_PROC_FS
        XPD_DBG(PROC, xpd, "Creating '%s'\n", PROC_BRI_INFO_FNAME);
-       priv->bri_info = create_proc_read_entry(PROC_BRI_INFO_FNAME, 0444, xpd->proc_xpd_dir, proc_bri_info_read, xpd);
+       priv->bri_info =
+           create_proc_read_entry(PROC_BRI_INFO_FNAME, 0444, xpd->proc_xpd_dir,
+                                  proc_bri_info_read, xpd);
        if (!priv->bri_info) {
-               XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_BRI_INFO_FNAME);
+               XPD_ERR(xpd, "Failed to create proc file '%s'\n",
+                       PROC_BRI_INFO_FNAME);
                bri_proc_remove(xbus, xpd);
                return -EINVAL;
        }
@@ -672,18 +680,21 @@ static int bri_proc_create(xbus_t *xbus, xpd_t *xpd)
        return 0;
 }
 
-static xpd_t *BRI_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table,
-       __u8 subtype, int subunits, int subunit_ports, bool to_phone)
+static xpd_t *BRI_card_new(xbus_t *xbus, int unit, int subunit,
+                          const xproto_table_t *proto_table, __u8 subtype,
+                          int subunits, int subunit_ports, bool to_phone)
 {
-       xpd_t           *xpd = NULL;
-       int             channels = min(3, CHANNELS_PERXPD);
+       xpd_t *xpd = NULL;
+       int channels = min(3, CHANNELS_PERXPD);
 
        if (subunit_ports != 1) {
                XBUS_ERR(xbus, "Bad subunit_ports=%d\n", subunit_ports);
                return NULL;
        }
        XBUS_DBG(GENERAL, xbus, "\n");
-       xpd = xpd_alloc(xbus, unit, subunit, subtype, subunits, sizeof(struct BRI_priv_data), proto_table, channels);
+       xpd =
+           xpd_alloc(xbus, unit, subunit, subtype, subunits,
+                     sizeof(struct BRI_priv_data), proto_table, channels);
        if (!xpd)
                return NULL;
        PHONEDEV(xpd).direction = (to_phone) ? TO_PHONE : TO_PSTN;
@@ -698,7 +709,7 @@ err:
 
 static int BRI_card_init(xbus_t *xbus, xpd_t *xpd)
 {
-       struct BRI_priv_data    *priv;
+       struct BRI_priv_data *priv;
 
        BUG_ON(!xpd);
        XPD_DBG(GENERAL, xpd, "\n");
@@ -744,15 +755,15 @@ static const struct dahdi_span_ops BRI_span_ops = {
 
 static int BRI_card_dahdi_preregistration(xpd_t *xpd, bool on)
 {
-       xbus_t                  *xbus;
-       struct BRI_priv_data    *priv;
-       int                     i;
+       xbus_t *xbus;
+       struct BRI_priv_data *priv;
+       int i;
 
        BUG_ON(!xpd);
        xbus = xpd->xbus;
        priv = xpd->priv;
        BUG_ON(!xbus);
-       XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off");
+       XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off");
        if (!on) {
                /* Nothing to do yet */
                return 0;
@@ -762,12 +773,12 @@ static int BRI_card_dahdi_preregistration(xpd_t *xpd, bool on)
        PHONEDEV(xpd).span.deflaw = DAHDI_LAW_ALAW;
        BIT_SET(PHONEDEV(xpd).digital_signalling, 2);   /* D-Channel */
        for_each_line(xpd, i) {
-               struct dahdi_chan       *cur_chan = XPD_CHAN(xpd, i);
+               struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i);
 
                XPD_DBG(GENERAL, xpd, "setting BRI channel %d\n", i);
                snprintf(cur_chan->name, MAX_CHANNAME, "XPP_%s/%02d/%1d%1d/%d",
-                               xpd->type_name, xbus->num,
-                               xpd->addr.unit, xpd->addr.subunit, i);
+                        xpd->type_name, xbus->num, xpd->addr.unit,
+                        xpd->addr.subunit, i);
                cur_chan->chanpos = i + 1;
                cur_chan->pvt = xpd;
                if (i == 2) {   /* D-CHAN */
@@ -786,13 +797,13 @@ static int BRI_card_dahdi_preregistration(xpd_t *xpd, bool on)
 
 static int BRI_card_dahdi_postregistration(xpd_t *xpd, bool on)
 {
-       xbus_t                  *xbus;
+       xbus_t *xbus;
 
        BUG_ON(!xpd);
        xbus = xpd->xbus;
        BUG_ON(!xbus);
-       XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off");
-       return(0);
+       XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off");
+       return (0);
 }
 
 static int BRI_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig)
@@ -809,11 +820,11 @@ static int BRI_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig)
  */
 static void handle_leds(xbus_t *xbus, xpd_t *xpd)
 {
-       struct BRI_priv_data    *priv;
-       unsigned int            timer_count;
-       int                     which_led;
-       int                     other_led;
-       int                     mod;
+       struct BRI_priv_data *priv;
+       unsigned int timer_count;
+       int which_led;
+       int other_led;
+       int mod;
 
        BUG_ON(!xpd);
        if (IS_NT(xpd)) {
@@ -844,24 +855,24 @@ static void handle_leds(xbus_t *xbus, xpd_t *xpd)
        if (priv->dchan_alive) {
                mod = timer_count % 1000;
                switch (mod) {
-                       case 0:
-                               DO_LED(xpd, which_led, BRI_LED_ON);
-                               break;
-                       case 500:
-                               DO_LED(xpd, which_led, BRI_LED_OFF);
-                               break;
+               case 0:
+                       DO_LED(xpd, which_led, BRI_LED_ON);
+                       break;
+               case 500:
+                       DO_LED(xpd, which_led, BRI_LED_OFF);
+                       break;
                }
        } else if (priv->layer1_up) {
                mod = timer_count % 1000;
                switch (mod) {
-                       case 0:
-                       case 100:
-                               DO_LED(xpd, which_led, BRI_LED_ON);
-                               break;
-                       case 50:
-                       case 150:
-                               DO_LED(xpd, which_led, BRI_LED_OFF);
-                               break;
+               case 0:
+               case 100:
+                       DO_LED(xpd, which_led, BRI_LED_ON);
+                       break;
+               case 50:
+               case 150:
+                       DO_LED(xpd, which_led, BRI_LED_OFF);
+                       break;
                }
        } else {
                if (priv->ledstate[which_led] != BRI_LED_ON)
@@ -871,7 +882,7 @@ static void handle_leds(xbus_t *xbus, xpd_t *xpd)
 
 static void handle_bri_timers(xpd_t *xpd)
 {
-       struct BRI_priv_data    *priv;
+       struct BRI_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -879,16 +890,20 @@ static void handle_bri_timers(xpd_t *xpd)
        if (IS_NT(xpd)) {
                if (priv->t1 > HFC_TIMER_OFF) {
                        if (--priv->t1 == 0) {
-                               set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF);
+                               set_bri_timer(xpd, "T1", &priv->t1,
+                                             HFC_TIMER_OFF);
                                if (!nt_keepalive) {
                                        if (priv->state_register.bits.v_su_sta == ST_NT_ACTIVATING) {   /* G2 */
-                                               XPD_DBG(SIGNAL, xpd, "T1 Expired. Deactivate NT\n");
-                                               clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
+                                               XPD_DBG(SIGNAL, xpd,
+                                                       "T1 Expired. Deactivate NT\n");
+                                               clear_bit(HFC_L1_ACTIVATING,
+                                                         &priv->l1_flags);
                                                nt_activation(xpd, 0);  /* Deactivate NT */
                                        } else
                                                XPD_DBG(SIGNAL, xpd,
                                                        "T1 Expired. (state %d, ignored)\n",
-                                                       priv->state_register.bits.v_su_sta);
+                                                       priv->state_register.
+                                                       bits.v_su_sta);
                                }
                        }
                }
@@ -896,10 +911,12 @@ static void handle_bri_timers(xpd_t *xpd)
                if (priv->t3 > HFC_TIMER_OFF) {
                        /* timer expired ? */
                        if (--priv->t3 == 0) {
-                               XPD_DBG(SIGNAL, xpd, "T3 expired. Deactivate TE\n");
-                               set_bri_timer(xpd, "T3", &priv->t3, HFC_TIMER_OFF);
+                               XPD_DBG(SIGNAL, xpd,
+                                       "T3 expired. Deactivate TE\n");
+                               set_bri_timer(xpd, "T3", &priv->t3,
+                                             HFC_TIMER_OFF);
                                clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
-                               te_activation(xpd, 0);          /* Deactivate TE */
+                               te_activation(xpd, 0);  /* Deactivate TE */
                        }
                }
        }
@@ -910,7 +927,7 @@ static void handle_bri_timers(xpd_t *xpd)
  */
 static int BRI_card_tick(xbus_t *xbus, xpd_t *xpd)
 {
-       struct BRI_priv_data    *priv;
+       struct BRI_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -920,21 +937,20 @@ static int BRI_card_tick(xbus_t *xbus, xpd_t *xpd)
        if (poll_interval != 0 && (priv->tick_counter % poll_interval) == 0) {
                // XPD_DBG(GENERAL, xpd, "%d\n", priv->tick_counter);
                priv->poll_counter++;
-               xpp_register_request(xbus, xpd,
-                               BRI_PORT(xpd),  /* portno       */
-                               0,              /* writing      */
-                               A_SU_RD_STA,    /* regnum       */
-                               0,              /* do_subreg    */
-                               0,              /* subreg       */
-                               0,              /* data_low     */
-                               0,              /* do_datah     */
-                               0,              /* data_high    */
-                               0               /* should_reply */
-                               );
-
-               if (IS_NT(xpd) && nt_keepalive &&
-                       !test_bit(HFC_L1_ACTIVATED, &priv->l1_flags) &&
-                       !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) {
+               xpp_register_request(xbus, xpd, BRI_PORT(xpd),  /* portno       */
+                                    0, /* writing      */
+                                    A_SU_RD_STA,       /* regnum       */
+                                    0, /* do_subreg    */
+                                    0, /* subreg       */
+                                    0, /* data_low     */
+                                    0, /* do_datah     */
+                                    0, /* data_high    */
+                                    0  /* should_reply */
+                   );
+
+               if (IS_NT(xpd) && nt_keepalive
+                   && !test_bit(HFC_L1_ACTIVATED, &priv->l1_flags)
+                   && !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) {
                        XPD_DBG(SIGNAL, xpd, "Kick NT D-Channel\n");
                        nt_activation(xpd, 1);
                }
@@ -943,20 +959,23 @@ static int BRI_card_tick(xbus_t *xbus, xpd_t *xpd)
        priv->dchan_notx_ticks++;
        priv->dchan_norx_ticks++;
        priv->dchan_alive_ticks++;
-       if (priv->dchan_alive && (priv->dchan_notx_ticks > DCHAN_LOST || priv->dchan_norx_ticks > DCHAN_LOST)) {
+       if (priv->dchan_alive
+           && (priv->dchan_notx_ticks > DCHAN_LOST
+               || priv->dchan_norx_ticks > DCHAN_LOST)) {
                /*
                 * No tx_dchan() or rx_dchan() for many ticks
                 * This D-Channel is probabelly dead.
                 */
                dchan_state(xpd, 0);
-       } else if (priv->dchan_rx_counter > 1 &&  priv->dchan_tx_counter > 1) {
+       } else if (priv->dchan_rx_counter > 1 && priv->dchan_tx_counter > 1) {
                if (!priv->dchan_alive)
                        dchan_state(xpd, 1);
        }
        /* Detect Layer1 disconnect */
        if (priv->reg30_good && priv->reg30_ticks > poll_interval * REG30_LOST) {
                /* No reply for 1/2 a second */
-               XPD_ERR(xpd, "Lost state tracking for %d ticks\n", priv->reg30_ticks);
+               XPD_ERR(xpd, "Lost state tracking for %d ticks\n",
+                       priv->reg30_ticks);
                priv->reg30_good = 0;
                layer1_state(xpd, 0);
        }
@@ -968,22 +987,23 @@ static int BRI_card_tick(xbus_t *xbus, xpd_t *xpd)
        return 0;
 }
 
-static int BRI_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long arg)
+static int BRI_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd,
+                         unsigned long arg)
 {
        BUG_ON(!xpd);
        if (!XBUS_IS(xpd->xbus, READY))
                return -ENODEV;
        switch (cmd) {
-               case DAHDI_TONEDETECT:
-                       /*
-                        * Asterisk call all span types with this (FXS specific)
-                        * call. Silently ignore it.
-                        */
-                       LINE_DBG(SIGNAL, xpd, pos, "BRI: Starting a call\n");
-                       return -ENOTTY;
-               default:
-                       report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd);
-                       return -ENOTTY;
+       case DAHDI_TONEDETECT:
+               /*
+                * Asterisk call all span types with this (FXS specific)
+                * call. Silently ignore it.
+                */
+               LINE_DBG(SIGNAL, xpd, pos, "BRI: Starting a call\n");
+               return -ENOTTY;
+       default:
+               report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd);
+               return -ENOTTY;
        }
        return 0;
 }
@@ -1020,11 +1040,11 @@ static int BRI_card_close(xpd_t *xpd, lineno_t pos)
 static int bri_spanconfig(struct file *file, struct dahdi_span *span,
                          struct dahdi_lineconfig *lc)
 {
-       struct phonedev *phonedev = container_of(span, struct phonedev, span);
-       xpd_t           *xpd = container_of(phonedev, struct xpd, phonedev);
-       const char      *framingstr = "";
-       const char      *codingstr = "";
-       const char      *crcstr = "";
+       struct phonedev *phonedev = container_of(span, struct phonedev, span);
+       xpd_t *xpd = container_of(phonedev, struct xpd, phonedev);
+       const char *framingstr = "";
+       const char *codingstr = "";
+       const char *crcstr = "";
 
        /* framing first */
        if (lc->lineconfig & DAHDI_CONFIG_B8ZS)
@@ -1043,14 +1063,10 @@ static int bri_spanconfig(struct file *file, struct dahdi_span *span,
        /* E1's can enable CRC checking */
        if (lc->lineconfig & DAHDI_CONFIG_CRC4)
                crcstr = "CRC4";
-       XPD_DBG(GENERAL, xpd, "[%s]: span=%d (%s) lbo=%d lineconfig=%s/%s/%s (0x%X) sync=%d\n",
-               IS_NT(xpd)?"NT":"TE",
-               lc->span,
-               lc->name,
-               lc->lbo,
-               framingstr, codingstr, crcstr,
-               lc->lineconfig,
-               lc->sync);
+       XPD_DBG(GENERAL, xpd,
+               "[%s]: span=%d (%s) lbo=%d lineconfig=%s/%s/%s (0x%X) sync=%d\n",
+               IS_NT(xpd) ? "NT" : "TE", lc->span, lc->name, lc->lbo,
+               framingstr, codingstr, crcstr, lc->lineconfig, lc->sync);
        PHONEDEV(xpd).timing_priority = lc->sync;
        elect_syncer("BRI-spanconfig");
        /*
@@ -1068,7 +1084,8 @@ static int bri_spanconfig(struct file *file, struct dahdi_span *span,
 static int bri_chanconfig(struct file *file, struct dahdi_chan *chan,
                          int sigtype)
 {
-       DBG(GENERAL, "channel %d (%s) -> %s\n", chan->channo, chan->name, sig2str(sigtype));
+       DBG(GENERAL, "channel %d (%s) -> %s\n", chan->channo, chan->name,
+           sig2str(sigtype));
        // FIXME: sanity checks:
        // - should be supported (within the sigcap)
        // - should not replace fxs <->fxo ??? (covered by previous?)
@@ -1080,16 +1097,17 @@ static int bri_chanconfig(struct file *file, struct dahdi_chan *chan,
  */
 static int bri_startup(struct file *file, struct dahdi_span *span)
 {
-       struct phonedev *phonedev = container_of(span, struct phonedev, span);
-       xpd_t           *xpd = container_of(phonedev, struct xpd, phonedev);
-       struct BRI_priv_data    *priv;
-       struct dahdi_chan       *dchan;
+       struct phonedev *phonedev = container_of(span, struct phonedev, span);
+       xpd_t *xpd = container_of(phonedev, struct xpd, phonedev);
+       struct BRI_priv_data *priv;
+       struct dahdi_chan *dchan;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
        BUG_ON(!priv);
        if (!XBUS_IS(xpd->xbus, READY)) {
-               XPD_DBG(GENERAL, xpd, "Startup called by dahdi. No Hardware. Ignored\n");
+               XPD_DBG(GENERAL, xpd,
+                       "Startup called by dahdi. No Hardware. Ignored\n");
                return -ENODEV;
        }
        XPD_DBG(GENERAL, xpd, "STARTUP\n");
@@ -1114,15 +1132,16 @@ static int bri_startup(struct file *file, struct dahdi_span *span)
  */
 static int bri_shutdown(struct dahdi_span *span)
 {
-       struct phonedev *phonedev = container_of(span, struct phonedev, span);
-       xpd_t           *xpd = container_of(phonedev, struct xpd, phonedev);
-       struct BRI_priv_data    *priv;
+       struct phonedev *phonedev = container_of(span, struct phonedev, span);
+       xpd_t *xpd = container_of(phonedev, struct xpd, phonedev);
+       struct BRI_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
        BUG_ON(!priv);
        if (!XBUS_IS(xpd->xbus, READY)) {
-               XPD_DBG(GENERAL, xpd, "Shutdown called by dahdi. No Hardware. Ignored\n");
+               XPD_DBG(GENERAL, xpd,
+                       "Shutdown called by dahdi. No Hardware. Ignored\n");
                return -ENODEV;
        }
        XPD_DBG(GENERAL, xpd, "SHUTDOWN\n");
@@ -1131,20 +1150,20 @@ static int bri_shutdown(struct dahdi_span *span)
        return 0;
 }
 
-static void BRI_card_pcm_recompute(xpd_t *xpd,
-               xpp_line_t dont_care)
+static void BRI_card_pcm_recompute(xpd_t *xpd, xpp_line_t dont_care)
 {
-       int             i;
-       int             line_count;
-       xpp_line_t      pcm_mask;
-       uint            pcm_len;
-       xpd_t           *main_xpd;
-       unsigned long   flags;
+       int i;
+       int line_count;
+       xpp_line_t pcm_mask;
+       uint pcm_len;
+       xpd_t *main_xpd;
+       unsigned long flags;
 
        BUG_ON(!xpd);
        main_xpd = xpd_byaddr(xpd->xbus, xpd->addr.unit, 0);
        if (!main_xpd) {
-               XPD_DBG(DEVICES, xpd, "Unit 0 is already gone. Ignore request\n");
+               XPD_DBG(DEVICES, xpd,
+                       "Unit 0 is already gone. Ignore request\n");
                return;
        }
        /*
@@ -1155,11 +1174,13 @@ static void BRI_card_pcm_recompute(xpd_t *xpd,
        line_count = 0;
        pcm_mask = 0;
        for (i = 0; i < MAX_SUBUNIT; i++) {
-               xpd_t           *sub_xpd = xpd_byaddr(xpd->xbus, main_xpd->addr.unit, i);
+               xpd_t *sub_xpd = xpd_byaddr(xpd->xbus, main_xpd->addr.unit, i);
 
                if (sub_xpd) {
-                       xpp_line_t      lines =
-                               PHONEDEV(sub_xpd).offhook_state & ~(PHONEDEV(sub_xpd).digital_signalling);
+                       xpp_line_t lines =
+                           PHONEDEV(sub_xpd).
+                           offhook_state & ~(PHONEDEV(sub_xpd).
+                                             digital_signalling);
 
                        if (lines) {
                                pcm_mask |= PCM_SHIFT(lines, i);
@@ -1183,27 +1204,26 @@ static void BRI_card_pcm_recompute(xpd_t *xpd,
         * The main unit account for all subunits (pcm_len and wanted_pcm_mask).
         */
        pcm_len = (line_count)
-               ? RPACKET_HEADERSIZE + sizeof(xpp_line_t) + line_count * DAHDI_CHUNKSIZE
-               : 0L;
+           ? RPACKET_HEADERSIZE + sizeof(xpp_line_t) +
+           line_count * DAHDI_CHUNKSIZE : 0L;
        update_wanted_pcm_mask(main_xpd, pcm_mask, pcm_len);
        spin_unlock_irqrestore(&PHONEDEV(main_xpd).lock_recompute_pcm, flags);
 }
 
 static void BRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack)
 {
-       __u8            *pcm;
-       unsigned long   flags;
-       int             i;
-       int             subunit;
-       xpp_line_t      pcm_mask = 0;
-       xpp_line_t      wanted_lines;
-
+       __u8 *pcm;
+       unsigned long flags;
+       int i;
+       int subunit;
+       xpp_line_t pcm_mask = 0;
+       xpp_line_t wanted_lines;
 
        BUG_ON(!xpd);
        BUG_ON(!pack);
        pcm = RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, pcm);
        for (subunit = 0; subunit < MAX_SUBUNIT; subunit++) {
-               xpd_t           *tmp_xpd;
+               xpd_t *tmp_xpd;
 
                tmp_xpd = xpd_byaddr(xpd->xbus, xpd->addr.unit, subunit);
                if (!tmp_xpd || !tmp_xpd->card_present)
@@ -1211,20 +1231,24 @@ static void BRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack)
                spin_lock_irqsave(&tmp_xpd->lock, flags);
                wanted_lines = PHONEDEV(tmp_xpd).wanted_pcm_mask;
                for_each_line(tmp_xpd, i) {
-                       struct dahdi_chan       *chan = XPD_CHAN(tmp_xpd, i);
+                       struct dahdi_chan *chan = XPD_CHAN(tmp_xpd, i);
 
                        if (IS_SET(wanted_lines, i)) {
                                if (SPAN_REGISTERED(tmp_xpd)) {
 #ifdef DEBUG_PCMTX
-                                       int     channo = chan->channo;
+                                       int channo = chan->channo;
 
                                        if (pcmtx >= 0 && pcmtx_chan == channo)
-                                               memset((u_char *)pcm, pcmtx, DAHDI_CHUNKSIZE);
+                                               memset((u_char *)pcm, pcmtx,
+                                                      DAHDI_CHUNKSIZE);
                                        else
 #endif
-                                               memcpy((u_char *)pcm, chan->writechunk, DAHDI_CHUNKSIZE);
+                                               memcpy((u_char *)pcm,
+                                                      chan->writechunk,
+                                                      DAHDI_CHUNKSIZE);
                                } else
-                                       memset((u_char *)pcm, 0x7F, DAHDI_CHUNKSIZE);
+                                       memset((u_char *)pcm, 0x7F,
+                                              DAHDI_CHUNKSIZE);
                                pcm += DAHDI_CHUNKSIZE;
                        }
                }
@@ -1237,11 +1261,11 @@ static void BRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack)
 
 static void BRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack)
 {
-       __u8            *pcm;
-       xpp_line_t      pcm_mask;
-       unsigned long   flags;
-       int             subunit;
-       int             i;
+       __u8 *pcm;
+       xpp_line_t pcm_mask;
+       unsigned long flags;
+       int subunit;
+       int i;
 
        /*
         * Subunit 0 handle all other subunits
@@ -1252,22 +1276,24 @@ static void BRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack)
                return;
        pcm = RPACKET_FIELD(pack, GLOBAL, PCM_READ, pcm);
        pcm_mask = RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, lines);
-       for (subunit = 0; subunit < MAX_SUBUNIT; subunit++, pcm_mask >>= SUBUNIT_PCM_SHIFT) {
-               xpd_t           *tmp_xpd;
+       for (subunit = 0; subunit < MAX_SUBUNIT;
+            subunit++, pcm_mask >>= SUBUNIT_PCM_SHIFT) {
+               xpd_t *tmp_xpd;
 
                if (!pcm_mask)
                        break;  /* optimize */
                tmp_xpd = xpd_byaddr(xpd->xbus, xpd->addr.unit, subunit);
-               if (!tmp_xpd || !tmp_xpd->card_present || !SPAN_REGISTERED(tmp_xpd))
+               if (!tmp_xpd || !tmp_xpd->card_present
+                   || !SPAN_REGISTERED(tmp_xpd))
                        continue;
                spin_lock_irqsave(&tmp_xpd->lock, flags);
                for (i = 0; i < 2; i++) {
-                       xpp_line_t      tmp_mask = pcm_mask & (BIT(0) | BIT(1));
-                       volatile u_char *r;
+                       xpp_line_t tmp_mask = pcm_mask & (BIT(0) | BIT(1));
+                       volatile u_char *r;
 
                        if (IS_SET(tmp_mask, i)) {
                                r = XPD_CHAN(tmp_xpd, i)->readchunk;
-                               // memset((u_char *)r, 0x5A, DAHDI_CHUNKSIZE);  // DEBUG
+                               // memset((u_char *)r, 0x5A, DAHDI_CHUNKSIZE);  // DEBUG
                                memcpy((u_char *)r, pcm, DAHDI_CHUNKSIZE);
                                pcm += DAHDI_CHUNKSIZE;
                        }
@@ -1279,7 +1305,7 @@ static void BRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack)
 
 static int BRI_timing_priority(xpd_t *xpd)
 {
-       struct BRI_priv_data    *priv;
+       struct BRI_priv_data *priv;
 
        priv = xpd->priv;
        BUG_ON(!priv);
@@ -1296,7 +1322,7 @@ int BRI_echocancel_timeslot(xpd_t *xpd, int pos)
 
 static int BRI_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask)
 {
-       struct BRI_priv_data    *priv;
+       struct BRI_priv_data *priv;
        int i;
 
        BUG_ON(!xpd);
@@ -1305,11 +1331,11 @@ static int BRI_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask)
        XPD_DBG(GENERAL, xpd, "0x%8X\n", ec_mask);
        if (!ECHOOPS(xpd->xbus)) {
                XPD_DBG(GENERAL, xpd,
-                               "No echo canceller in XBUS: Doing nothing.\n");
+                       "No echo canceller in XBUS: Doing nothing.\n");
                return -EINVAL;
        }
        for (i = 0; i < PHONEDEV(xpd).channels - 1; i++) {
-               int     on = BIT(i) & ec_mask;
+               int on = BIT(i) & ec_mask;
 
                CALL_EC_METHOD(ec_set, xpd->xbus, xpd, i, on);
        }
@@ -1319,19 +1345,19 @@ static int BRI_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask)
 
 /*---------------- BRI: HOST COMMANDS -------------------------------------*/
 
-static /* 0x33 */ HOSTCMD(BRI, SET_LED, enum bri_led_names which_led, enum led_state to_led_state)
+static /* 0x33 */ HOSTCMD(BRI, SET_LED, enum bri_led_names which_led,
+                         enum led_state to_led_state)
 {
-       int                     ret = 0;
-       xframe_t                *xframe;
-       xpacket_t               *pack;
-       struct bri_leds         *bri_leds;
-       struct BRI_priv_data    *priv;
+       int ret = 0;
+       xframe_t *xframe;
+       xpacket_t *pack;
+       struct bri_leds *bri_leds;
+       struct BRI_priv_data *priv;
 
        BUG_ON(!xbus);
        priv = xpd->priv;
        BUG_ON(!priv);
-       XPD_DBG(LEDS, xpd, "%s -> %d\n",
-               (which_led)?"RED":"GREEN",
+       XPD_DBG(LEDS, xpd, "%s -> %d\n", (which_led) ? "RED" : "GREEN",
                to_led_state);
        XFRAME_NEW_CMD(xframe, pack, xbus, BRI, SET_LED, xpd->xbus_idx);
        bri_leds = &RPACKET_FIELD(pack, BRI, SET_LED, bri_leds);
@@ -1345,28 +1371,27 @@ static /* 0x33 */ HOSTCMD(BRI, SET_LED, enum bri_led_names which_led, enum led_s
 
 static int write_state_register(xpd_t *xpd, __u8 value)
 {
-       int     ret;
+       int ret;
 
        XPD_DBG(REGS, xpd, "value = 0x%02X\n", value);
-       ret = xpp_register_request(xpd->xbus, xpd,
-                       BRI_PORT(xpd),  /* portno       */
-                       1,              /* writing      */
-                       A_SU_WR_STA,    /* regnum       */
-                       0,              /* do_subreg    */
-                       0,              /* subreg       */
-                       value,          /* data_low     */
-                       0,              /* do_datah     */
-                       0,              /* data_high    */
-                       0               /* should_reply */
-                       );
+       ret = xpp_register_request(xpd->xbus, xpd, BRI_PORT(xpd),       /* portno       */
+                                  1,   /* writing      */
+                                  A_SU_WR_STA, /* regnum       */
+                                  0,   /* do_subreg    */
+                                  0,   /* subreg       */
+                                  value,       /* data_low     */
+                                  0,   /* do_datah     */
+                                  0,   /* data_high    */
+                                  0    /* should_reply */
+           );
        return ret;
 }
 
 /*---------------- BRI: Astribank Reply Handlers --------------------------*/
 static void su_new_state(xpd_t *xpd, __u8 reg_x30)
 {
-       struct BRI_priv_data    *priv;
-       su_rd_sta_t             new_state;
+       struct BRI_priv_data *priv;
+       su_rd_sta_t new_state;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -1382,79 +1407,78 @@ static void su_new_state(xpd_t *xpd, __u8 reg_x30)
        priv->reg30_ticks = 0;
        priv->reg30_good = 1;
        if (priv->state_register.bits.v_su_sta == new_state.bits.v_su_sta)
-               return; /* same same */
+               return;         /* same same */
        XPD_DBG(SIGNAL, xpd, "%02X ---> %02X (info0=%d) (%s%i)\n",
-               priv->state_register.reg,
-               reg_x30,
-               new_state.bits.v_su_info0,
-               IS_NT(xpd)?"G":"F",
-               new_state.bits.v_su_sta);
+               priv->state_register.reg, reg_x30, new_state.bits.v_su_info0,
+               IS_NT(xpd) ? "G" : "F", new_state.bits.v_su_sta);
        if (!IS_NT(xpd)) {
                switch (new_state.bits.v_su_sta) {
-                       case ST_TE_DEACTIVATED:         /* F3 */
-                               XPD_DBG(SIGNAL, xpd, "State ST_TE_DEACTIVATED (F3)\n");
-                               clear_bit(HFC_L1_ACTIVATED, &priv->l1_flags);
-                               layer1_state(xpd, 0);
-                               break;
-                       case ST_TE_SIGWAIT:             /* F4   */
-                               XPD_DBG(SIGNAL, xpd, "State ST_TE_SIGWAIT (F4)\n");
-                               layer1_state(xpd, 0);
-                               break;
-                       case ST_TE_IDENT:               /* F5   */
-                               XPD_DBG(SIGNAL, xpd, "State ST_TE_IDENT (F5)\n");
-                               layer1_state(xpd, 0);
-                               break;
-                       case ST_TE_SYNCED:              /* F6   */
-                               XPD_DBG(SIGNAL, xpd, "State ST_TE_SYNCED (F6)\n");
-                               layer1_state(xpd, 0);
-                               break;
-                       case ST_TE_ACTIVATED:           /* F7 */
-                               XPD_DBG(SIGNAL, xpd, "State ST_TE_ACTIVATED (F7)\n");
-                               set_bri_timer(xpd, "T3", &priv->t3, HFC_TIMER_OFF);
-                               clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
-                               set_bit(HFC_L1_ACTIVATED, &priv->l1_flags);
-                               layer1_state(xpd, 1);
-                               update_xpd_status(xpd, DAHDI_ALARM_NONE);
-                               break;
-                       case ST_TE_LOST_FRAMING:        /* F8 */
-                               XPD_DBG(SIGNAL, xpd, "State ST_TE_LOST_FRAMING (F8)\n");
-                               layer1_state(xpd, 0);
-                               break;
-                       default:
-                               XPD_NOTICE(xpd, "Bad TE state: %d\n", new_state.bits.v_su_sta);
-                               break;
+               case ST_TE_DEACTIVATED: /* F3 */
+                       XPD_DBG(SIGNAL, xpd, "State ST_TE_DEACTIVATED (F3)\n");
+                       clear_bit(HFC_L1_ACTIVATED, &priv->l1_flags);
+                       layer1_state(xpd, 0);
+                       break;
+               case ST_TE_SIGWAIT:     /* F4   */
+                       XPD_DBG(SIGNAL, xpd, "State ST_TE_SIGWAIT (F4)\n");
+                       layer1_state(xpd, 0);
+                       break;
+               case ST_TE_IDENT:       /* F5   */
+                       XPD_DBG(SIGNAL, xpd, "State ST_TE_IDENT (F5)\n");
+                       layer1_state(xpd, 0);
+                       break;
+               case ST_TE_SYNCED:      /* F6   */
+                       XPD_DBG(SIGNAL, xpd, "State ST_TE_SYNCED (F6)\n");
+                       layer1_state(xpd, 0);
+                       break;
+               case ST_TE_ACTIVATED:   /* F7 */
+                       XPD_DBG(SIGNAL, xpd, "State ST_TE_ACTIVATED (F7)\n");
+                       set_bri_timer(xpd, "T3", &priv->t3, HFC_TIMER_OFF);
+                       clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
+                       set_bit(HFC_L1_ACTIVATED, &priv->l1_flags);
+                       layer1_state(xpd, 1);
+                       update_xpd_status(xpd, DAHDI_ALARM_NONE);
+                       break;
+               case ST_TE_LOST_FRAMING:        /* F8 */
+                       XPD_DBG(SIGNAL, xpd, "State ST_TE_LOST_FRAMING (F8)\n");
+                       layer1_state(xpd, 0);
+                       break;
+               default:
+                       XPD_NOTICE(xpd, "Bad TE state: %d\n",
+                                  new_state.bits.v_su_sta);
+                       break;
                }
 
        } else {
                switch (new_state.bits.v_su_sta) {
-                       case ST_NT_DEACTIVATED:         /* G1 */
-                               XPD_DBG(SIGNAL, xpd, "State ST_NT_DEACTIVATED (G1)\n");
-                               clear_bit(HFC_L1_ACTIVATED, &priv->l1_flags);
-                               set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF);
-                               layer1_state(xpd, 0);
-                               break;
-                       case ST_NT_ACTIVATING:          /* G2 */
-                               XPD_DBG(SIGNAL, xpd, "State ST_NT_ACTIVATING (G2)\n");
-                               layer1_state(xpd, 0);
-                               if (!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags))
-                                       nt_activation(xpd, 1);
-                               break;
-                       case ST_NT_ACTIVATED:           /* G3 */
-                               XPD_DBG(SIGNAL, xpd, "State ST_NT_ACTIVATED (G3)\n");
-                               clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
-                               set_bit(HFC_L1_ACTIVATED, &priv->l1_flags);
-                               set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF);
-                               layer1_state(xpd, 1);
-                               update_xpd_status(xpd, DAHDI_ALARM_NONE);
-                               break;
-                       case ST_NT_DEACTIVTING:         /* G4 */
-                               XPD_DBG(SIGNAL, xpd, "State ST_NT_DEACTIVTING (G4)\n");
-                               set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF);
-                               layer1_state(xpd, 0);
-                               break;
-                       default:
-                               XPD_NOTICE(xpd, "Bad NT state: %d\n", new_state.bits.v_su_sta);
-                               break;
+               case ST_NT_DEACTIVATED: /* G1 */
+                       XPD_DBG(SIGNAL, xpd, "State ST_NT_DEACTIVATED (G1)\n");
+                       clear_bit(HFC_L1_ACTIVATED, &priv->l1_flags);
+                       set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF);
+                       layer1_state(xpd, 0);
+                       break;
+               case ST_NT_ACTIVATING:  /* G2 */
+                       XPD_DBG(SIGNAL, xpd, "State ST_NT_ACTIVATING (G2)\n");
+                       layer1_state(xpd, 0);
+                       if (!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags))
+                               nt_activation(xpd, 1);
+                       break;
+               case ST_NT_ACTIVATED:   /* G3 */
+                       XPD_DBG(SIGNAL, xpd, "State ST_NT_ACTIVATED (G3)\n");
+                       clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
+                       set_bit(HFC_L1_ACTIVATED, &priv->l1_flags);
+                       set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF);
+                       layer1_state(xpd, 1);
+                       update_xpd_status(xpd, DAHDI_ALARM_NONE);
+                       break;
+               case ST_NT_DEACTIVTING: /* G4 */
+                       XPD_DBG(SIGNAL, xpd, "State ST_NT_DEACTIVTING (G4)\n");
+                       set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF);
+                       layer1_state(xpd, 0);
+                       break;
+               default:
+                       XPD_NOTICE(xpd, "Bad NT state: %d\n",
+                                  new_state.bits.v_su_sta);
+                       break;
                }
        }
        priv->state_register.reg = new_state.reg;
@@ -1462,11 +1486,11 @@ static void su_new_state(xpd_t *xpd, __u8 reg_x30)
 
 static int BRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
 {
-       unsigned long           flags;
-       struct BRI_priv_data    *priv;
-       struct xpd_addr         addr;
-       xpd_t                   *orig_xpd;
-       int                     ret;
+       unsigned long flags;
+       struct BRI_priv_data *priv;
+       struct xpd_addr addr;
+       xpd_t *orig_xpd;
+       int ret;
 
        /* Map UNIT + PORTNUM to XPD */
        orig_xpd = xpd;
@@ -1474,10 +1498,10 @@ static int BRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
        addr.subunit = info->portnum;
        xpd = xpd_byaddr(xbus, addr.unit, addr.subunit);
        if (!xpd) {
-               static int      rate_limit;
+               static int rate_limit;
 
                if ((rate_limit++ % 1003) < 5)
-                       notify_bad_xpd(__func__, xbus, addr , orig_xpd->xpdname);
+                       notify_bad_xpd(__func__, xbus, addr, orig_xpd->xpdname);
                return -EPROTO;
        }
        spin_lock_irqsave(&xpd->lock, flags);
@@ -1485,23 +1509,26 @@ static int BRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
        BUG_ON(!priv);
        if (REG_FIELD(info, do_subreg)) {
                XPD_DBG(REGS, xpd, "RI %02X %02X %02X\n",
-                               REG_FIELD(info, regnum), REG_FIELD(info, subreg), REG_FIELD(info, data_low));
+                       REG_FIELD(info, regnum), REG_FIELD(info, subreg),
+                       REG_FIELD(info, data_low));
        } else {
                if (REG_FIELD(info, regnum) != A_SU_RD_STA)
                        XPD_DBG(REGS, xpd, "RD %02X %02X\n",
-                                       REG_FIELD(info, regnum), REG_FIELD(info, data_low));
+                               REG_FIELD(info, regnum), REG_FIELD(info,
+                                                                  data_low));
                else
                        XPD_DBG(REGS, xpd, "Got SU_RD_STA=%02X\n",
-                                       REG_FIELD(info, data_low));
+                               REG_FIELD(info, data_low));
        }
        if (info->is_multibyte) {
                XPD_DBG(REGS, xpd, "Got Multibyte: %d bytes, eoframe: %d\n",
-                               info->bytes, info->eoframe);
+                       info->bytes, info->eoframe);
                ret = rx_dchan(xpd, info);
                if (ret < 0) {
                        priv->dchan_rx_drops++;
                        if (atomic_read(&PHONEDEV(xpd).open_counter) > 0)
-                               XPD_NOTICE(xpd, "Multibyte Drop: errno=%d\n", ret);
+                               XPD_NOTICE(xpd, "Multibyte Drop: errno=%d\n",
+                                          ret);
                }
                goto end;
        }
@@ -1510,10 +1537,11 @@ static int BRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
        }
 
        /* Update /proc info only if reply relate to the last slic read request */
-       if (
-                       REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) &&
-                       REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info, do_subreg) &&
-                       REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info, subreg)) {
+       if (REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum)
+           && REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info,
+                                                                       do_subreg)
+           && REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info,
+                                                                    subreg)) {
                xpd->last_reply = *info;
        }
 
@@ -1524,14 +1552,14 @@ end:
 
 static int BRI_card_state(xpd_t *xpd, bool on)
 {
-       struct BRI_priv_data    *priv;
+       struct BRI_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
-       XPD_DBG(GENERAL, xpd, "%s\n", (on)?"ON":"OFF");
+       XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "ON" : "OFF");
        if (on) {
                if (!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags)) {
-                       if ( ! IS_NT(xpd))
+                       if (!IS_NT(xpd))
                                te_activation(xpd, 1);
                        else
                                nt_activation(xpd, 1);
@@ -1541,47 +1569,41 @@ static int BRI_card_state(xpd_t *xpd, bool on)
        return 0;
 }
 
-static const struct xops       bri_xops = {
-       .card_new       = BRI_card_new,
-       .card_init      = BRI_card_init,
-       .card_remove    = BRI_card_remove,
-       .card_tick      = BRI_card_tick,
-       .card_register_reply    = BRI_card_register_reply,
+static const struct xops bri_xops = {
+       .card_new = BRI_card_new,
+       .card_init = BRI_card_init,
+       .card_remove = BRI_card_remove,
+       .card_tick = BRI_card_tick,
+       .card_register_reply = BRI_card_register_reply,
 };
 
-static const struct phoneops   bri_phoneops = {
-       .card_dahdi_preregistration     = BRI_card_dahdi_preregistration,
-       .card_dahdi_postregistration    = BRI_card_dahdi_postregistration,
-       .card_hooksig   = BRI_card_hooksig,
-       .card_pcm_recompute     = BRI_card_pcm_recompute,
-       .card_pcm_fromspan      = BRI_card_pcm_fromspan,
-       .card_pcm_tospan        = BRI_card_pcm_tospan,
-       .card_timing_priority   = BRI_timing_priority,
-       .echocancel_timeslot    = BRI_echocancel_timeslot,
-       .echocancel_setmask     = BRI_echocancel_setmask,
-       .card_ioctl     = BRI_card_ioctl,
-       .card_open      = BRI_card_open,
-       .card_close     = BRI_card_close,
-       .card_state     = BRI_card_state,
+static const struct phoneops bri_phoneops = {
+       .card_dahdi_preregistration = BRI_card_dahdi_preregistration,
+       .card_dahdi_postregistration = BRI_card_dahdi_postregistration,
+       .card_hooksig = BRI_card_hooksig,
+       .card_pcm_recompute = BRI_card_pcm_recompute,
+       .card_pcm_fromspan = BRI_card_pcm_fromspan,
+       .card_pcm_tospan = BRI_card_pcm_tospan,
+       .card_timing_priority = BRI_timing_priority,
+       .echocancel_timeslot = BRI_echocancel_timeslot,
+       .echocancel_setmask = BRI_echocancel_setmask,
+       .card_ioctl = BRI_card_ioctl,
+       .card_open = BRI_card_open,
+       .card_close = BRI_card_close,
+       .card_state = BRI_card_state,
 };
 
 static xproto_table_t PROTO_TABLE(BRI) = {
-       .owner = THIS_MODULE,
-       .entries = {
-               /*      Table   Card    Opcode          */
-       },
-       .name = "BRI",  /* protocol name */
-       .ports_per_subunit = 1,
-       .type = XPD_TYPE_BRI,
-       .xops = &bri_xops,
-       .phoneops = &bri_phoneops,
-       .packet_is_valid = bri_packet_is_valid,
-       .packet_dump = bri_packet_dump,
-};
+       .owner = THIS_MODULE,.entries = {
+               /*      Table   Card    Opcode          */
+       },.name = "BRI",        /* protocol name */
+.ports_per_subunit = 1,.type = XPD_TYPE_BRI,.xops =
+           &bri_xops,.phoneops = &bri_phoneops,.packet_is_valid =
+           bri_packet_is_valid,.packet_dump = bri_packet_dump,};
 
 static bool bri_packet_is_valid(xpacket_t *pack)
 {
-       const xproto_entry_t    *xe = NULL;
+       const xproto_entry_t *xe = NULL;
        // DBG(GENERAL, "\n");
        xe = xproto_card_entry(&PROTO_TABLE(BRI), XPACKET_OP(pack));
        return xe != NULL;
@@ -1591,15 +1613,17 @@ static void bri_packet_dump(const char *msg, xpacket_t *pack)
 {
        DBG(GENERAL, "%s\n", msg);
 }
+
 /*------------------------- REGISTER Handling --------------------------*/
 
 #ifdef CONFIG_PROC_FS
-static int proc_bri_info_read(char *page, char **start, off_t off, int count, int *eof, void *data)
+static int proc_bri_info_read(char *page, char **start, off_t off, int count,
+                             int *eof, void *data)
 {
-       int                     len = 0;
-       unsigned long           flags;
-       xpd_t                   *xpd = data;
-       struct BRI_priv_data    *priv;
+       int len = 0;
+       unsigned long flags;
+       xpd_t *xpd = data;
+       struct BRI_priv_data *priv;
 
        DBG(PROC, "\n");
        if (!xpd)
@@ -1609,15 +1633,20 @@ static int proc_bri_info_read(char *page, char **start, off_t off, int count, in
        BUG_ON(!priv);
        len += sprintf(page + len, "%05d Layer 1: ", priv->poll_counter);
        if (priv->reg30_good) {
-               len += sprintf(page + len, "%-5s ", (priv->layer1_up) ? "UP" : "DOWN");
-               len += sprintf(page + len, "%c%d %-15s -- fr_sync=%d t2_exp=%d info0=%d g2_g3=%d\n",
-                                       IS_NT(xpd)?'G':'F',
-                                       priv->state_register.bits.v_su_sta,
-                                       xhfc_state_name(IS_NT(xpd), priv->state_register.bits.v_su_sta),
-                                       priv->state_register.bits.v_su_fr_sync,
-                                       priv->state_register.bits.v_su_t2_exp,
-                                       priv->state_register.bits.v_su_info0,
-                                       priv->state_register.bits.v_g2_g3);
+               len +=
+                   sprintf(page + len, "%-5s ",
+                           (priv->layer1_up) ? "UP" : "DOWN");
+               len +=
+                   sprintf(page + len,
+                           "%c%d %-15s -- fr_sync=%d t2_exp=%d info0=%d g2_g3=%d\n",
+                           IS_NT(xpd) ? 'G' : 'F',
+                           priv->state_register.bits.v_su_sta,
+                           xhfc_state_name(IS_NT(xpd),
+                                           priv->state_register.bits.v_su_sta),
+                           priv->state_register.bits.v_su_fr_sync,
+                           priv->state_register.bits.v_su_t2_exp,
+                           priv->state_register.bits.v_su_info0,
+                           priv->state_register.bits.v_g2_g3);
        } else
                len += sprintf(page + len, "Unknown\n");
        if (IS_NT(xpd)) {
@@ -1626,24 +1655,37 @@ static int proc_bri_info_read(char *page, char **start, off_t off, int count, in
                len += sprintf(page + len, "T3 Timer: %d\n", priv->t3);
        }
        len += sprintf(page + len, "Tick Counter: %d\n", priv->tick_counter);
-       len += sprintf(page + len, "Last Poll Reply: %d ticks ago\n", priv->reg30_ticks);
+       len +=
+           sprintf(page + len, "Last Poll Reply: %d ticks ago\n",
+                   priv->reg30_ticks);
        len += sprintf(page + len, "reg30_good=%d\n", priv->reg30_good);
-       len += sprintf(page + len, "D-Channel: TX=[%5d]    RX=[%5d]    BAD=[%5d] ",
-                       priv->dchan_tx_counter, priv->dchan_rx_counter, priv->dchan_rx_drops);
+       len +=
+           sprintf(page + len, "D-Channel: TX=[%5d]    RX=[%5d]    BAD=[%5d] ",
+                   priv->dchan_tx_counter, priv->dchan_rx_counter,
+                   priv->dchan_rx_drops);
        if (priv->dchan_alive) {
-               len += sprintf(page + len, "(alive %d K-ticks)\n",
-                       priv->dchan_alive_ticks/1000);
+               len +=
+                   sprintf(page + len, "(alive %d K-ticks)\n",
+                           priv->dchan_alive_ticks / 1000);
        } else {
                len += sprintf(page + len, "(dead)\n");
        }
-       len += sprintf(page + len, "dchan_notx_ticks: %d\n", priv->dchan_notx_ticks);
-       len += sprintf(page + len, "dchan_norx_ticks: %d\n", priv->dchan_norx_ticks);
-       len += sprintf(page + len, "LED: %-10s = %d\n", "GREEN", priv->ledstate[GREEN_LED]);
-       len += sprintf(page + len, "LED: %-10s = %d\n", "RED", priv->ledstate[RED_LED]);
+       len +=
+           sprintf(page + len, "dchan_notx_ticks: %d\n",
+                   priv->dchan_notx_ticks);
+       len +=
+           sprintf(page + len, "dchan_norx_ticks: %d\n",
+                   priv->dchan_norx_ticks);
+       len +=
+           sprintf(page + len, "LED: %-10s = %d\n", "GREEN",
+                   priv->ledstate[GREEN_LED]);
+       len +=
+           sprintf(page + len, "LED: %-10s = %d\n", "RED",
+                   priv->ledstate[RED_LED]);
        len += sprintf(page + len, "\nDCHAN:\n");
        len += sprintf(page + len, "\n");
        spin_unlock_irqrestore(&xpd->lock, flags);
-       if (len <= off+count)
+       if (len <= off + count)
                *eof = 1;
        *start = page + off;
        len -= off;
@@ -1657,13 +1699,13 @@ static int proc_bri_info_read(char *page, char **start, off_t off, int count, in
 
 static int bri_xpd_probe(struct device *dev)
 {
-       xpd_t   *xpd;
+       xpd_t *xpd;
 
        xpd = dev_to_xpd(dev);
        /* Is it our device? */
        if (xpd->type != XPD_TYPE_BRI) {
-               XPD_ERR(xpd, "drop suggestion for %s (%d)\n",
-                       dev_name(dev), xpd->type);
+               XPD_ERR(xpd, "drop suggestion for %s (%d)\n", dev_name(dev),
+                       xpd->type);
                return -EINVAL;
        }
        XPD_DBG(DEVICES, xpd, "SYSFS\n");
@@ -1672,28 +1714,27 @@ static int bri_xpd_probe(struct device *dev)
 
 static int bri_xpd_remove(struct device *dev)
 {
-       xpd_t   *xpd;
+       xpd_t *xpd;
 
        xpd = dev_to_xpd(dev);
        XPD_DBG(DEVICES, xpd, "SYSFS\n");
        return 0;
 }
 
-static struct xpd_driver       bri_driver = {
-       .type           = XPD_TYPE_BRI,
-       .driver         = {
-               .name = "bri",
+static struct xpd_driver bri_driver = {
+       .type = XPD_TYPE_BRI,
+       .driver = {
+                  .name = "bri",
 #ifndef OLD_HOTPLUG_SUPPORT
-               .owner = THIS_MODULE,
+                  .owner = THIS_MODULE,
 #endif
-               .probe = bri_xpd_probe,
-               .remove = bri_xpd_remove
-       }
+                  .probe = bri_xpd_probe,
+                  .remove = bri_xpd_remove}
 };
 
 static int __init card_bri_startup(void)
 {
-       int     ret;
+       int ret;
 
        if ((ret = xpd_driver_register(&bri_driver.driver)) < 0)
                return ret;
index a7b69de..8c49021 100644 (file)
@@ -25,7 +25,7 @@
 #include "xpd.h"
 
 enum bri_opcodes {
-       XPROTO_NAME(BRI, SET_LED)                       = 0x33,
+       XPROTO_NAME(BRI, SET_LED) = 0x33,
 };
 
-#endif /* CARD_BRI_H */
+#endif /* CARD_BRI_H */
index 25d09d9..b70878c 100644 (file)
@@ -42,25 +42,20 @@ static DEF_PARM(int, debug, 0, 0644, "Print DBG statements");
 static bool echo_packet_is_valid(xpacket_t *pack);
 static void echo_packet_dump(const char *msg, xpacket_t *pack);
 
-DEF_RPACKET_DATA(ECHO, SET,
-       __u8 timeslots[ECHO_TIMESLOTS];
-       );
+DEF_RPACKET_DATA(ECHO, SET, __u8 timeslots[ECHO_TIMESLOTS];);
 
-DEF_RPACKET_DATA(ECHO, SET_REPLY,
-       __u8 status;
-       __u8 reserved;
-       );
+DEF_RPACKET_DATA(ECHO, SET_REPLY, __u8 status; __u8 reserved;);
 
 struct ECHO_priv_data {
 };
 
-static xproto_table_t  PROTO_TABLE(ECHO);
+static xproto_table_t PROTO_TABLE(ECHO);
 
 /*---------------- ECHO: Methods -------------------------------------------*/
 
 static xpd_t *ECHO_card_new(xbus_t *xbus, int unit, int subunit,
-               const xproto_table_t *proto_table, __u8 subtype,
-               int subunits, int subunit_ports, bool to_phone)
+                           const xproto_table_t *proto_table, __u8 subtype,
+                           int subunits, int subunit_ports, bool to_phone)
 {
        xpd_t *xpd = NULL;
        int channels = 0;
@@ -70,8 +65,9 @@ static xpd_t *ECHO_card_new(xbus_t *xbus, int unit, int subunit,
                return NULL;
        }
        XBUS_DBG(GENERAL, xbus, "\n");
-       xpd = xpd_alloc(xbus, unit, subunit, subtype, subunits,
-               sizeof(struct ECHO_priv_data), proto_table, channels);
+       xpd =
+           xpd_alloc(xbus, unit, subunit, subtype, subunits,
+                     sizeof(struct ECHO_priv_data), proto_table, channels);
        if (!xpd)
                return NULL;
        xpd->type_name = "ECHO";
@@ -122,19 +118,16 @@ static int ECHO_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
                static int rate_limit;
 
                if ((rate_limit++ % 1003) < 5)
-                       notify_bad_xpd(__func__, xbus, addr,
-                                       orig_xpd->xpdname);
+                       notify_bad_xpd(__func__, xbus, addr, orig_xpd->xpdname);
                return -EPROTO;
        }
        spin_lock_irqsave(&xpd->lock, flags);
        /* Update /proc info only if reply related to last reg read request */
-       if (
-                       REG_FIELD(&xpd->requested_reply, regnum) ==
-                               REG_FIELD(info, regnum) &&
-                       REG_FIELD(&xpd->requested_reply, do_subreg) ==
-                               REG_FIELD(info, do_subreg) &&
-                       REG_FIELD(&xpd->requested_reply, subreg) ==
-                               REG_FIELD(info, subreg)) {
+       if (REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum)
+           && REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info,
+                                                                       do_subreg)
+           && REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info,
+                                                                    subreg)) {
                xpd->last_reply = *info;
        }
        spin_unlock_irqrestore(&xpd->lock, flags);
@@ -198,7 +191,7 @@ static int ECHO_ec_set(xpd_t *xpd, int pos, bool on)
                        ts[ts_number] &= ~ts_mask;
        }
        LINE_DBG(GENERAL, xpd, pos, "%s = %d -- ts_number=%d ts_mask=0x%X\n",
-               __func__, on, ts_number, ts_mask);
+                __func__, on, ts_number, ts_mask);
        return 0;
 }
 
@@ -220,7 +213,7 @@ static int ECHO_ec_get(xpd_t *xpd, int pos)
        }
 #if 0
        LINE_DBG(GENERAL, xpd, pos, "ec_get=%d -- ts_number=%d ts_mask=0x%X\n",
-               is_on, ts_number, ts_mask);
+                is_on, ts_number, ts_mask);
 #endif
        return is_on;
 }
@@ -233,15 +226,14 @@ static void ECHO_ec_dump(xbus_t *xbus)
        ts = xbus->echo_state.timeslots;
        for (i = 0; i + 15 < ECHO_TIMESLOTS; i += 16) {
                XBUS_DBG(GENERAL, xbus,
-                       "EC-DUMP[%03d]: "
-                       "0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X "
-                       "0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
-                       i,
-                       ts[i+0], ts[i+1], ts[i+2], ts[i+3], ts[i+4], ts[i+5],
-                               ts[i+6], ts[i+7],
-                       ts[i+8], ts[i+9], ts[i+10], ts[i+11], ts[i+12],
-                               ts[i+13], ts[i+14], ts[i+15]
-                       );
+                        "EC-DUMP[%03d]: "
+                        "0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X "
+                        "0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
+                        i, ts[i + 0], ts[i + 1], ts[i + 2], ts[i + 3],
+                        ts[i + 4], ts[i + 5], ts[i + 6], ts[i + 7], ts[i + 8],
+                        ts[i + 9], ts[i + 10], ts[i + 11], ts[i + 12],
+                        ts[i + 13], ts[i + 14], ts[i + 15]
+                   );
        }
 }
 
@@ -255,7 +247,7 @@ static int ECHO_ec_update(xbus_t *xbus)
 /*---------------- ECHO: Astribank Reply Handlers --------------------------*/
 HANDLER_DEF(ECHO, SET_REPLY)
 {
-       __u8    status;
+       __u8 status;
 
        BUG_ON(!xpd);
        status = RPACKET_FIELD(pack, ECHO, SET_REPLY, status);
@@ -263,39 +255,32 @@ HANDLER_DEF(ECHO, SET_REPLY)
        return 0;
 }
 
-static const struct xops       echo_xops = {
-       .card_new               = ECHO_card_new,
-       .card_init              = ECHO_card_init,
-       .card_remove            = ECHO_card_remove,
-       .card_tick              = ECHO_card_tick,
-       .card_register_reply    = ECHO_card_register_reply,
+static const struct xops echo_xops = {
+       .card_new = ECHO_card_new,
+       .card_init = ECHO_card_init,
+       .card_remove = ECHO_card_remove,
+       .card_tick = ECHO_card_tick,
+       .card_register_reply = ECHO_card_register_reply,
 };
 
-static const struct echoops    echoops = {
-       .ec_set         = ECHO_ec_set,
-       .ec_get         = ECHO_ec_get,
-       .ec_update      = ECHO_ec_update,
-       .ec_dump        = ECHO_ec_dump,
+static const struct echoops echoops = {
+       .ec_set = ECHO_ec_set,
+       .ec_get = ECHO_ec_get,
+       .ec_update = ECHO_ec_update,
+       .ec_dump = ECHO_ec_dump,
 };
 
 static xproto_table_t PROTO_TABLE(ECHO) = {
-       .owner = THIS_MODULE,
-       .entries = {
-               /*      Table   Card    Opcode          */
-               XENTRY(ECHO,    ECHO,   SET_REPLY),
-       },
-       .name = "ECHO",
-       .ports_per_subunit = 1,
-       .type = XPD_TYPE_ECHO,
-       .xops = &echo_xops,
-       .echoops = &echoops,
-       .packet_is_valid = echo_packet_is_valid,
-       .packet_dump = echo_packet_dump,
-};
+       .owner = THIS_MODULE,.entries = {
+               /*      Table   Card    Opcode          */
+XENTRY(ECHO, ECHO, SET_REPLY),},.name = "ECHO",.ports_per_subunit =
+           1,.type = XPD_TYPE_ECHO,.xops = &echo_xops,.echoops =
+           &echoops,.packet_is_valid =
+           echo_packet_is_valid,.packet_dump = echo_packet_dump,};
 
 static bool echo_packet_is_valid(xpacket_t *pack)
 {
-       const xproto_entry_t    *xe = NULL;
+       const xproto_entry_t *xe = NULL;
        // DBG(GENERAL, "\n");
        xe = xproto_card_entry(&PROTO_TABLE(ECHO), XPACKET_OP(pack));
        return xe != NULL;
@@ -309,14 +294,14 @@ static void echo_packet_dump(const char *msg, xpacket_t *pack)
 /*------------------------- sysfs stuff --------------------------------*/
 static int echo_xpd_probe(struct device *dev)
 {
-       xpd_t   *ec_xpd;
-       int     ret = 0;
+       xpd_t *ec_xpd;
+       int ret = 0;
 
        ec_xpd = dev_to_xpd(dev);
        /* Is it our device? */
        if (ec_xpd->type != XPD_TYPE_ECHO) {
-               XPD_ERR(ec_xpd, "drop suggestion for %s (%d)\n",
-                       dev_name(dev), ec_xpd->type);
+               XPD_ERR(ec_xpd, "drop suggestion for %s (%d)\n", dev_name(dev),
+                       ec_xpd->type);
                return -EINVAL;
        }
        XPD_DBG(DEVICES, ec_xpd, "SYSFS\n");
@@ -325,23 +310,22 @@ static int echo_xpd_probe(struct device *dev)
 
 static int echo_xpd_remove(struct device *dev)
 {
-       xpd_t   *ec_xpd;
+       xpd_t *ec_xpd;
 
        ec_xpd = dev_to_xpd(dev);
        XPD_DBG(DEVICES, ec_xpd, "SYSFS\n");
        return 0;
 }
 
-static struct xpd_driver       echo_driver = {
-       .type           = XPD_TYPE_ECHO,
-       .driver         = {
-               .name = "echo",
+static struct xpd_driver echo_driver = {
+       .type = XPD_TYPE_ECHO,
+       .driver = {
+                  .name = "echo",
 #ifndef OLD_HOTPLUG_SUPPORT
-               .owner = THIS_MODULE,
+                  .owner = THIS_MODULE,
 #endif
-               .probe = echo_xpd_probe,
-               .remove = echo_xpd_remove
-       }
+                  .probe = echo_xpd_probe,
+                  .remove = echo_xpd_remove}
 };
 
 static int __init card_echo_startup(void)
index 81fea05..55c1d73 100644 (file)
@@ -24,8 +24,8 @@
 #include "xpd.h"
 
 enum echo_opcodes {
-       XPROTO_NAME(ECHO, SET)          = 0x39,
-       XPROTO_NAME(ECHO, SET_REPLY)    = 0x3A,
+       XPROTO_NAME(ECHO, SET) = 0x39,
+       XPROTO_NAME(ECHO, SET_REPLY) = 0x3A,
 };
 
-#endif /* CARD_ECHO_H */
+#endif /* CARD_ECHO_H */
index 1eaa215..213aba9 100644 (file)
 static const char rcsid[] = "$Id$";
 
 static DEF_PARM(int, debug, 0, 0644, "Print DBG statements");
-static DEF_PARM(uint, poll_battery_interval, 500, 0644, "Poll battery interval in milliseconds (0 - disable)");
+static DEF_PARM(uint, poll_battery_interval, 500, 0644,
+               "Poll battery interval in milliseconds (0 - disable)");
 #ifdef WITH_METERING
-static DEF_PARM(uint, poll_metering_interval, 500, 0644, "Poll metering interval in milliseconds (0 - disable)");
+static DEF_PARM(uint, poll_metering_interval, 500, 0644,
+               "Poll metering interval in milliseconds (0 - disable)");
 #endif
-static DEF_PARM(int, ring_debounce, 50, 0644, "Number of ticks to debounce a false RING indication");
-static DEF_PARM(int, caller_id_style, 0, 0444, "Caller-Id detection style: 0 - [BELL], 1 - [ETSI_FSK], 2 - [ETSI_DTMF]");
-static DEF_PARM(int, power_denial_safezone, 650, 0644, "msec after offhook to ignore power-denial ( (0 - disable power-denial)");
-static DEF_PARM(int, power_denial_minlen, 80, 0644, "Minimal detected power-denial length (msec) (0 - disable power-denial)");
-static DEF_PARM(uint, battery_threshold, 3, 0644, "Minimum voltage that shows there is battery");
-static DEF_PARM(uint, battery_debounce, 1000, 0644, "Minimum interval (msec) for detection of battery off");
+static DEF_PARM(int, ring_debounce, 50, 0644,
+               "Number of ticks to debounce a false RING indication");
+static DEF_PARM(int, caller_id_style, 0, 0444,
+               "Caller-Id detection style: 0 - [BELL], 1 - [ETSI_FSK], 2 - [ETSI_DTMF]");
+static DEF_PARM(int, power_denial_safezone, 650, 0644,
+               "msec after offhook to ignore power-denial ( (0 - disable power-denial)");
+static DEF_PARM(int, power_denial_minlen, 80, 0644,
+               "Minimal detected power-denial length (msec) (0 - disable power-denial)");
+static DEF_PARM(uint, battery_threshold, 3, 0644,
+               "Minimum voltage that shows there is battery");
+static DEF_PARM(uint, battery_debounce, 1000, 0644,
+               "Minimum interval (msec) for detection of battery off");
 
 enum cid_style {
-       CID_STYLE_BELL          = 0,    /* E.g: US (Bellcore) */
-       CID_STYLE_ETSI_FSK      = 1,    /* E.g: UK (British Telecom) */
-       CID_STYLE_ETSI_DTMF     = 2,    /* E.g: DK, Russia */
+       CID_STYLE_BELL = 0,     /* E.g: US (Bellcore) */
+       CID_STYLE_ETSI_FSK = 1, /* E.g: UK (British Telecom) */
+       CID_STYLE_ETSI_DTMF = 2,        /* E.g: DK, Russia */
 };
 
 /* Signaling is opposite (fxs signalling for fxo card) */
@@ -86,9 +94,11 @@ enum fxo_leds {
 static bool fxo_packet_is_valid(xpacket_t *pack);
 static void fxo_packet_dump(const char *msg, xpacket_t *pack);
 #ifdef CONFIG_PROC_FS
-static int proc_fxo_info_read(char *page, char **start, off_t off, int count, int *eof, void *data);
+static int proc_fxo_info_read(char *page, char **start, off_t off, int count,
+                             int *eof, void *data);
 #ifdef WITH_METERING
-static int proc_xpd_metering_read(char *page, char **start, off_t off, int count, int *eof, void *data);
+static int proc_xpd_metering_read(char *page, char **start, off_t off,
+                                 int count, int *eof, void *data);
 #endif
 #endif
 static void dahdi_report_battery(xpd_t *xpd, lineno_t chan);
@@ -99,57 +109,57 @@ static void dahdi_report_battery(xpd_t *xpd, lineno_t chan);
 #define        PROC_METERING_FNAME     "metering_read"
 #endif
 
-#define        REG_DAA_CONTROL1        0x05    /*  5 -  DAA Control 1  */
-#define        REG_DAA_CONTROL1_OH     BIT(0)  /* Off-Hook.            */
-#define        REG_DAA_CONTROL1_ONHM   BIT(3)  /* On-Hook Line Monitor */
+#define        REG_DAA_CONTROL1        0x05    /*  5 -  DAA Control 1  */
+#define        REG_DAA_CONTROL1_OH     BIT(0)  /* Off-Hook.            */
+#define        REG_DAA_CONTROL1_ONHM   BIT(3)  /* On-Hook Line Monitor */
 
 #define        DAA_REG_METERING        0x11    /* 17 */
 #define        DAA_REG_CURRENT         0x1C    /* 28 */
 #define        DAA_REG_VBAT            0x1D    /* 29 */
 
 enum battery_state {
-       BATTERY_UNKNOWN = 0,
-       BATTERY_ON              = 1,
-       BATTERY_OFF             = -1
+       BATTERY_UNKNOWN = 0,
+       BATTERY_ON = 1,
+       BATTERY_OFF = -1
 };
 
 enum polarity_state {
-       POL_UNKNOWN     = 0,
-       POL_POSITIVE    = 1,
-       POL_NEGATIVE    = -1
+       POL_UNKNOWN = 0,
+       POL_POSITIVE = 1,
+       POL_NEGATIVE = -1
 };
 
 enum power_state {
-       POWER_UNKNOWN   = 0,
-       POWER_ON        = 1,
-       POWER_OFF       = -1
+       POWER_UNKNOWN = 0,
+       POWER_ON = 1,
+       POWER_OFF = -1
 };
 
 struct FXO_priv_data {
 #ifdef WITH_METERING
-       struct proc_dir_entry   *meteringfile;
+       struct proc_dir_entry *meteringfile;
 #endif
-       struct proc_dir_entry   *fxo_info;
-       uint                    poll_counter;
-       signed char             battery_voltage[CHANNELS_PERXPD];
-       signed char             battery_current[CHANNELS_PERXPD];
-       enum battery_state      battery[CHANNELS_PERXPD];
-       ushort                  nobattery_debounce[CHANNELS_PERXPD];
-       enum polarity_state     polarity[CHANNELS_PERXPD];
-       ushort                  polarity_debounce[CHANNELS_PERXPD];
-       enum power_state        power[CHANNELS_PERXPD];
-       ushort                  power_denial_delay[CHANNELS_PERXPD];
-       ushort                  power_denial_length[CHANNELS_PERXPD];
-       ushort                  power_denial_safezone[CHANNELS_PERXPD];
-       xpp_line_t              cidfound;               /* 0 - OFF, 1 - ON */
-       unsigned int            cidtimer[CHANNELS_PERXPD];
-       xpp_line_t              ledstate[NUM_LEDS];     /* 0 - OFF, 1 - ON */
-       xpp_line_t              ledcontrol[NUM_LEDS];   /* 0 - OFF, 1 - ON */
-       int                     led_counter[NUM_LEDS][CHANNELS_PERXPD];
-       atomic_t                ring_debounce[CHANNELS_PERXPD];
+       struct proc_dir_entry *fxo_info;
+       uint poll_counter;
+       signed char battery_voltage[CHANNELS_PERXPD];
+       signed char battery_current[CHANNELS_PERXPD];
+       enum battery_state battery[CHANNELS_PERXPD];
+       ushort nobattery_debounce[CHANNELS_PERXPD];
+       enum polarity_state polarity[CHANNELS_PERXPD];
+       ushort polarity_debounce[CHANNELS_PERXPD];
+       enum power_state power[CHANNELS_PERXPD];
+       ushort power_denial_delay[CHANNELS_PERXPD];
+       ushort power_denial_length[CHANNELS_PERXPD];
+       ushort power_denial_safezone[CHANNELS_PERXPD];
+       xpp_line_t cidfound;    /* 0 - OFF, 1 - ON */
+       unsigned int cidtimer[CHANNELS_PERXPD];
+       xpp_line_t ledstate[NUM_LEDS];  /* 0 - OFF, 1 - ON */
+       xpp_line_t ledcontrol[NUM_LEDS];        /* 0 - OFF, 1 - ON */
+       int led_counter[NUM_LEDS][CHANNELS_PERXPD];
+       atomic_t ring_debounce[CHANNELS_PERXPD];
 #ifdef WITH_METERING
-       uint                    metering_count[CHANNELS_PERXPD];
-       xpp_line_t              metering_tone_state;
+       uint metering_count[CHANNELS_PERXPD];
+       xpp_line_t metering_tone_state;
 #endif
 };
 
@@ -170,50 +180,53 @@ struct FXO_priv_data {
 static const char *power2str(enum power_state pw)
 {
        switch (pw) {
-               case POWER_UNKNOWN:     return "UNKNOWN";
-               case POWER_OFF:         return "OFF";
-               case POWER_ON:          return "ON";
+       case POWER_UNKNOWN:
+               return "UNKNOWN";
+       case POWER_OFF:
+               return "OFF";
+       case POWER_ON:
+               return "ON";
        }
        return NULL;
 }
 
 static void power_change(xpd_t *xpd, int portno, enum power_state pw)
 {
-       struct FXO_priv_data    *priv;
+       struct FXO_priv_data *priv;
 
        priv = xpd->priv;
        LINE_DBG(SIGNAL, xpd, portno, "power: %s -> %s\n",
-                       power2str(priv->power[portno]),
-                       power2str(pw));
+                power2str(priv->power[portno]), power2str(pw));
        priv->power[portno] = pw;
 }
 
 static void reset_battery_readings(xpd_t *xpd, lineno_t pos)
 {
-       struct FXO_priv_data    *priv = xpd->priv;
+       struct FXO_priv_data *priv = xpd->priv;
 
        priv->nobattery_debounce[pos] = 0;
        priv->power_denial_delay[pos] = 0;
        power_change(xpd, pos, POWER_UNKNOWN);
 }
 
-static const int       led_register_mask[] = { BIT(7), BIT(6), BIT(5) };
+static const int led_register_mask[] = { BIT(7), BIT(6), BIT(5) };
 
 /*
  * LED control is done via DAA register 0x20
  */
 static int do_led(xpd_t *xpd, lineno_t chan, __u8 which, bool on)
 {
-       int                     ret = 0;
-       struct FXO_priv_data    *priv;
-       xbus_t                  *xbus;
-       __u8                    value;
+       int ret = 0;
+       struct FXO_priv_data *priv;
+       xbus_t *xbus;
+       __u8 value;
 
        BUG_ON(!xpd);
        xbus = xpd->xbus;
        priv = xpd->priv;
        which = which % NUM_LEDS;
-       if (IS_SET(PHONEDEV(xpd).digital_outputs, chan) || IS_SET(PHONEDEV(xpd).digital_inputs, chan))
+       if (IS_SET(PHONEDEV(xpd).digital_outputs, chan)
+           || IS_SET(PHONEDEV(xpd).digital_inputs, chan))
                goto out;
        if (chan == PORT_BROADCAST) {
                priv->ledstate[which] = (on) ? ~0 : 0;
@@ -228,7 +241,8 @@ static int do_led(xpd_t *xpd, lineno_t chan, __u8 which, bool on)
        value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[which]);
        value |= (on) ? BIT(0) : 0;
        value |= (on) ? BIT(1) : 0;
-       LINE_DBG(LEDS, xpd, chan, "LED: which=%d -- %s\n", which, (on) ? "on" : "off");
+       LINE_DBG(LEDS, xpd, chan, "LED: which=%d -- %s\n", which,
+                (on) ? "on" : "off");
        ret = DAA_DIRECT_REQUEST(xbus, xpd, chan, DAA_WRITE, 0x20, value);
 out:
        return ret;
@@ -236,12 +250,12 @@ out:
 
 static void handle_fxo_leds(xpd_t *xpd)
 {
-       int                     i;
-       unsigned long           flags;
-       const enum fxo_leds     colors[] = { LED_GREEN, LED_RED };
-       enum fxo_leds           color;
-       unsigned int            timer_count;
-       struct FXO_priv_data    *priv;
+       int i;
+       unsigned long flags;
+       const enum fxo_leds colors[] = { LED_GREEN, LED_RED };
+       enum fxo_leds color;
+       unsigned int timer_count;
+       struct FXO_priv_data *priv;
 
        BUG_ON(!xpd);
        spin_lock_irqsave(&xpd->lock, flags);
@@ -249,25 +263,31 @@ static void handle_fxo_leds(xpd_t *xpd)
        timer_count = xpd->timer_count;
        for (color = 0; color < ARRAY_SIZE(colors); color++) {
                for_each_line(xpd, i) {
-                       if (IS_SET(PHONEDEV(xpd).digital_outputs, i) || IS_SET(PHONEDEV(xpd).digital_inputs, i))
+                       if (IS_SET(PHONEDEV(xpd).digital_outputs, i)
+                           || IS_SET(PHONEDEV(xpd).digital_inputs, i))
                                continue;
-                       if ((xpd->blink_mode & BIT(i)) || IS_BLINKING(priv, i, color)) {                // Blinking
-                               int     mod_value = LED_COUNTER(priv, i, color);
+                       if ((xpd->blink_mode & BIT(i)) || IS_BLINKING(priv, i, color)) {        // Blinking
+                               int mod_value = LED_COUNTER(priv, i, color);
 
                                if (!mod_value)
-                                       mod_value = DEFAULT_LED_PERIOD;         /* safety value */
+                                       mod_value = DEFAULT_LED_PERIOD; /* safety value */
                                // led state is toggled
                                if ((timer_count % mod_value) == 0) {
-                                       LINE_DBG(LEDS, xpd, i, "ledstate=%s\n", (IS_SET(priv->ledstate[color], i))?"ON":"OFF");
+                                       LINE_DBG(LEDS, xpd, i, "ledstate=%s\n",
+                                                (IS_SET
+                                                 (priv->ledstate[color],
+                                                  i)) ? "ON" : "OFF");
                                        if (!IS_SET(priv->ledstate[color], i)) {
                                                do_led(xpd, i, color, 1);
                                        } else {
                                                do_led(xpd, i, color, 0);
                                        }
                                }
-                       } else if (IS_SET(priv->ledcontrol[color], i) && !IS_SET(priv->ledstate[color], i)) {
+                       } else if (IS_SET(priv->ledcontrol[color], i)
+                                  && !IS_SET(priv->ledstate[color], i)) {
                                do_led(xpd, i, color, 1);
-                       } else if (!IS_SET(priv->ledcontrol[color], i) && IS_SET(priv->ledstate[color], i)) {
+                       } else if (!IS_SET(priv->ledcontrol[color], i)
+                                  && IS_SET(priv->ledstate[color], i)) {
                                do_led(xpd, i, color, 0);
                        }
                }
@@ -290,7 +310,7 @@ static void update_dahdi_ring(xpd_t *xpd, int pos, bool on)
 
 static void mark_ring(xpd_t *xpd, lineno_t pos, bool on, bool update_dahdi)
 {
-       struct FXO_priv_data    *priv;
+       struct FXO_priv_data *priv;
 
        priv = xpd->priv;
        BUG_ON(!priv);
@@ -320,32 +340,36 @@ static void mark_ring(xpd_t *xpd, lineno_t pos, bool on, bool update_dahdi)
 
 static int do_sethook(xpd_t *xpd, int pos, bool to_offhook)
 {
-       unsigned long           flags;
-       xbus_t                  *xbus;
-       struct FXO_priv_data    *priv;
-       int                     ret = 0;
-       __u8                    value;
+       unsigned long flags;
+       xbus_t *xbus;
+       struct FXO_priv_data *priv;
+       int ret = 0;
+       __u8 value;
 
        BUG_ON(!xpd);
-       BUG_ON(PHONEDEV(xpd).direction == TO_PHONE);            // We can SETHOOK state only on PSTN
+       BUG_ON(PHONEDEV(xpd).direction == TO_PHONE);    // We can SETHOOK state only on PSTN
        xbus = xpd->xbus;
        priv = xpd->priv;
        BUG_ON(!priv);
        if (priv->battery[pos] != BATTERY_ON && to_offhook) {
-               LINE_NOTICE(xpd, pos, "Cannot take offhook while battery is off!\n");
+               LINE_NOTICE(xpd, pos,
+                           "Cannot take offhook while battery is off!\n");
                return -EINVAL;
        }
        spin_lock_irqsave(&xpd->lock, flags);
-       mark_ring(xpd, pos, 0, 0);                              // No more rings
-       value = REG_DAA_CONTROL1_ONHM;                          /* Bit 3 is for CID */
+       mark_ring(xpd, pos, 0, 0);      // No more rings
+       value = REG_DAA_CONTROL1_ONHM;  /* Bit 3 is for CID */
        if (to_offhook)
                value |= REG_DAA_CONTROL1_OH;
-       LINE_DBG(SIGNAL, xpd, pos, "SETHOOK: value=0x%02X %s\n", value, (to_offhook)?"OFFHOOK":"ONHOOK");
+       LINE_DBG(SIGNAL, xpd, pos, "SETHOOK: value=0x%02X %s\n", value,
+                (to_offhook) ? "OFFHOOK" : "ONHOOK");
        if (to_offhook)
                MARK_ON(priv, pos, LED_GREEN);
        else
                MARK_OFF(priv, pos, LED_GREEN);
-       ret = DAA_DIRECT_REQUEST(xbus, xpd, pos, DAA_WRITE, REG_DAA_CONTROL1, value);
+       ret =
+           DAA_DIRECT_REQUEST(xbus, xpd, pos, DAA_WRITE, REG_DAA_CONTROL1,
+                              value);
        mark_offhook(xpd, pos, to_offhook);
        if (caller_id_style != CID_STYLE_ETSI_DTMF)
                oht_pcm(xpd, pos, 0);
@@ -370,7 +394,7 @@ static int do_sethook(xpd_t *xpd, int pos, bool to_offhook)
 
 static void fxo_proc_remove(xbus_t *xbus, xpd_t *xpd)
 {
-       struct FXO_priv_data    *priv;
+       struct FXO_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -394,25 +418,30 @@ static void fxo_proc_remove(xbus_t *xbus, xpd_t *xpd)
 
 static int fxo_proc_create(xbus_t *xbus, xpd_t *xpd)
 {
-       struct FXO_priv_data    *priv;
+       struct FXO_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
 #ifdef CONFIG_PROC_FS
        XPD_DBG(PROC, xpd, "Creating FXO_INFO file\n");
-       priv->fxo_info = create_proc_read_entry(PROC_FXO_INFO_FNAME, 0444, xpd->proc_xpd_dir, proc_fxo_info_read, xpd);
+       priv->fxo_info =
+           create_proc_read_entry(PROC_FXO_INFO_FNAME, 0444, xpd->proc_xpd_dir,
+                                  proc_fxo_info_read, xpd);
        if (!priv->fxo_info) {
-               XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_FXO_INFO_FNAME);
+               XPD_ERR(xpd, "Failed to create proc file '%s'\n",
+                       PROC_FXO_INFO_FNAME);
                fxo_proc_remove(xbus, xpd);
                return -EINVAL;
        }
        SET_PROC_DIRENTRY_OWNER(priv->fxo_info);
 #ifdef WITH_METERING
        XPD_DBG(PROC, xpd, "Creating Metering tone file\n");
-       priv->meteringfile = create_proc_read_entry(PROC_METERING_FNAME, 0444, xpd->proc_xpd_dir,
-                       proc_xpd_metering_read, xpd);
+       priv->meteringfile =
+           create_proc_read_entry(PROC_METERING_FNAME, 0444, xpd->proc_xpd_dir,
+                                  proc_xpd_metering_read, xpd);
        if (!priv->meteringfile) {
-               XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_METERING_FNAME);
+               XPD_ERR(xpd, "Failed to create proc file '%s'\n",
+                       PROC_METERING_FNAME);
                fxo_proc_remove(xbus, xpd);
                return -EINVAL;
        }
@@ -422,23 +451,26 @@ static int fxo_proc_create(xbus_t *xbus, xpd_t *xpd)
        return 0;
 }
 
-static xpd_t *FXO_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table,
-       __u8 subtype, int subunits, int subunit_ports, bool to_phone)
+static xpd_t *FXO_card_new(xbus_t *xbus, int unit, int subunit,
+                          const xproto_table_t *proto_table, __u8 subtype,
+                          int subunits, int subunit_ports, bool to_phone)
 {
-       xpd_t           *xpd = NULL;
-       int             channels;
+       xpd_t *xpd = NULL;
+       int channels;
 
        if (to_phone) {
                XBUS_NOTICE(xbus,
-                       "XPD=%d%d: try to instanciate FXO with reverse direction\n",
-                       unit, subunit);
+                           "XPD=%d%d: try to instanciate FXO with reverse direction\n",
+                           unit, subunit);
                return NULL;
        }
        if (subtype == 2)
                channels = min(2, subunit_ports);
        else
                channels = min(8, subunit_ports);
-       xpd = xpd_alloc(xbus, unit, subunit, subtype, subunits, sizeof(struct FXO_priv_data), proto_table, channels);
+       xpd =
+           xpd_alloc(xbus, unit, subunit, subtype, subunits,
+                     sizeof(struct FXO_priv_data), proto_table, channels);
        if (!xpd)
                return NULL;
        PHONEDEV(xpd).direction = TO_PSTN;
@@ -453,8 +485,8 @@ err:
 
 static int FXO_card_init(xbus_t *xbus, xpd_t *xpd)
 {
-       struct FXO_priv_data    *priv;
-       int                     i;
+       struct FXO_priv_data *priv;
+       int i;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -494,10 +526,10 @@ static int FXO_card_remove(xbus_t *xbus, xpd_t *xpd)
 
 static int FXO_card_dahdi_preregistration(xpd_t *xpd, bool on)
 {
-       xbus_t                  *xbus;
-       struct FXO_priv_data    *priv;
-       int                     i;
-       unsigned int            timer_count;
+       xbus_t *xbus;
+       struct FXO_priv_data *priv;
+       int i;
+       unsigned int timer_count;
 
        BUG_ON(!xpd);
        xbus = xpd->xbus;
@@ -505,14 +537,14 @@ static int FXO_card_dahdi_preregistration(xpd_t *xpd, bool on)
        priv = xpd->priv;
        BUG_ON(!priv);
        timer_count = xpd->timer_count;
-       XPD_DBG(GENERAL, xpd, "%s\n", (on)?"ON":"OFF");
+       XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "ON" : "OFF");
        PHONEDEV(xpd).span.spantype = "FXO";
        for_each_line(xpd, i) {
-               struct dahdi_chan       *cur_chan = XPD_CHAN(xpd, i);
+               struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i);
 
                XPD_DBG(GENERAL, xpd, "setting FXO channel %d\n", i);
                snprintf(cur_chan->name, MAX_CHANNAME, "XPP_FXO/%02d/%1d%1d/%d",
-                       xbus->num, xpd->addr.unit, xpd->addr.subunit, i);
+                        xbus->num, xpd->addr.unit, xpd->addr.subunit, i);
                cur_chan->chanpos = i + 1;
                cur_chan->pvt = xpd;
                cur_chan->sigcap = FXO_DEFAULT_SIGCAP;
@@ -530,16 +562,16 @@ static int FXO_card_dahdi_preregistration(xpd_t *xpd, bool on)
 
 static int FXO_card_dahdi_postregistration(xpd_t *xpd, bool on)
 {
-       xbus_t                  *xbus;
-       struct FXO_priv_data    *priv;
-       int                     i;
+       xbus_t *xbus;
+       struct FXO_priv_data *priv;
+       int i;
 
        BUG_ON(!xpd);
        xbus = xpd->xbus;
        BUG_ON(!xbus);
        priv = xpd->priv;
        BUG_ON(!priv);
-       XPD_DBG(GENERAL, xpd, "%s\n", (on)?"ON":"OFF");
+       XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "ON" : "OFF");
        for_each_line(xpd, i) {
                dahdi_report_battery(xpd, i);
                MARK_OFF(priv, i, LED_GREEN);
@@ -552,8 +584,8 @@ static int FXO_card_dahdi_postregistration(xpd_t *xpd, bool on)
 
 static int FXO_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig)
 {
-       struct FXO_priv_data    *priv;
-       int                     ret = 0;
+       struct FXO_priv_data *priv;
+       int ret = 0;
 
        priv = xpd->priv;
        BUG_ON(!priv);
@@ -561,40 +593,42 @@ static int FXO_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig)
        BUG_ON(PHONEDEV(xpd).direction != TO_PSTN);
        /* XXX Enable hooksig for FXO XXX */
        switch (txsig) {
-               case DAHDI_TXSIG_START:
-               case DAHDI_TXSIG_OFFHOOK:
-                       ret = do_sethook(xpd, pos, 1);
-                       break;
-               case DAHDI_TXSIG_ONHOOK:
-                       ret = do_sethook(xpd, pos, 0);
-                       break;
-               default:
-                       XPD_NOTICE(xpd, "Can't set tx state to %s (%d)\n",
-                               txsig2str(txsig), txsig);
-                       return -EINVAL;
+       case DAHDI_TXSIG_START:
+       case DAHDI_TXSIG_OFFHOOK:
+               ret = do_sethook(xpd, pos, 1);
+               break;
+       case DAHDI_TXSIG_ONHOOK:
+               ret = do_sethook(xpd, pos, 0);
+               break;
+       default:
+               XPD_NOTICE(xpd, "Can't set tx state to %s (%d)\n",
+                          txsig2str(txsig), txsig);
+               return -EINVAL;
        }
        return ret;
 }
 
 static void dahdi_report_battery(xpd_t *xpd, lineno_t chan)
 {
-       struct FXO_priv_data    *priv;
+       struct FXO_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
        if (SPAN_REGISTERED(xpd)) {
                switch (priv->battery[chan]) {
-                       case BATTERY_UNKNOWN:
-                               /* no-op */
-                               break;
-                       case BATTERY_OFF:
-                               LINE_DBG(SIGNAL, xpd, chan, "Send DAHDI_ALARM_RED\n");
-                               dahdi_alarm_channel(XPD_CHAN(xpd, chan), DAHDI_ALARM_RED);
-                               break;
-                       case BATTERY_ON:
-                               LINE_DBG(SIGNAL, xpd, chan, "Send DAHDI_ALARM_NONE\n");
-                               dahdi_alarm_channel(XPD_CHAN(xpd, chan), DAHDI_ALARM_NONE);
-                               break;
+               case BATTERY_UNKNOWN:
+                       /* no-op */
+                       break;
+               case BATTERY_OFF:
+                       LINE_DBG(SIGNAL, xpd, chan, "Send DAHDI_ALARM_RED\n");
+                       dahdi_alarm_channel(XPD_CHAN(xpd, chan),
+                                           DAHDI_ALARM_RED);
+                       break;
+               case BATTERY_ON:
+                       LINE_DBG(SIGNAL, xpd, chan, "Send DAHDI_ALARM_NONE\n");
+                       dahdi_alarm_channel(XPD_CHAN(xpd, chan),
+                                           DAHDI_ALARM_NONE);
+                       break;
                }
        }
 }
@@ -607,7 +641,7 @@ static int FXO_card_open(xpd_t *xpd, lineno_t chan)
 
 static void poll_battery(xbus_t *xbus, xpd_t *xpd)
 {
-       int     i;
+       int i;
 
        for_each_line(xpd, i) {
                DAA_DIRECT_REQUEST(xbus, xpd, i, DAA_READ, DAA_REG_VBAT, 0);
@@ -617,19 +651,20 @@ static void poll_battery(xbus_t *xbus, xpd_t *xpd)
 #ifdef WITH_METERING
 static void poll_metering(xbus_t *xbus, xpd_t *xpd)
 {
-       int     i;
+       int i;
 
        for_each_line(xpd, i) {
                if (IS_OFFHOOK(xpd, i))
-                       DAA_DIRECT_REQUEST(xbus, xpd, i, DAA_READ, DAA_REG_METERING, 0);
+                       DAA_DIRECT_REQUEST(xbus, xpd, i, DAA_READ,
+                                          DAA_REG_METERING, 0);
        }
 }
 #endif
 
 static void handle_fxo_ring(xpd_t *xpd)
 {
-       struct FXO_priv_data    *priv;
-       int                     i;
+       struct FXO_priv_data *priv;
+       int i;
 
        priv = xpd->priv;
        for_each_line(xpd, i) {
@@ -647,8 +682,8 @@ static void handle_fxo_ring(xpd_t *xpd)
 
 static void handle_fxo_power_denial(xpd_t *xpd)
 {
-       struct FXO_priv_data    *priv;
-       int                     i;
+       struct FXO_priv_data *priv;
+       int i;
 
        if (!power_denial_safezone)
                return;         /* Ignore power denials */
@@ -663,7 +698,8 @@ static void handle_fxo_power_denial(xpd_t *xpd)
                                /*
                                 * Poll current, previous answers are meaningless
                                 */
-                               DAA_DIRECT_REQUEST(xpd->xbus, xpd, i, DAA_READ, DAA_REG_CURRENT, 0);
+                               DAA_DIRECT_REQUEST(xpd->xbus, xpd, i, DAA_READ,
+                                                  DAA_REG_CURRENT, 0);
                        }
                        continue;
                }
@@ -675,8 +711,10 @@ static void handle_fxo_power_denial(xpd_t *xpd)
                                 * detected it yet). This would cause false power denials.
                                 * So we just flag it and schedule more ticks to wait.
                                 */
-                               LINE_DBG(SIGNAL, xpd, i, "Possible Power Denial Hangup\n");
-                               priv->power_denial_delay[i] = POWER_DENIAL_DELAY;
+                               LINE_DBG(SIGNAL, xpd, i,
+                                        "Possible Power Denial Hangup\n");
+                               priv->power_denial_delay[i] =
+                                   POWER_DENIAL_DELAY;
                        }
                        continue;
                }
@@ -688,7 +726,8 @@ static void handle_fxo_power_denial(xpd_t *xpd)
                         */
                        priv->power_denial_delay[i]--;
                        if (priv->power_denial_delay[i] <= 0) {
-                               LINE_DBG(SIGNAL, xpd, i, "Power Denial Hangup\n");
+                               LINE_DBG(SIGNAL, xpd, i,
+                                        "Power Denial Hangup\n");
                                priv->power_denial_delay[i] = 0;
                                /*
                                 * Let Asterisk decide what to do
@@ -708,9 +747,9 @@ static void handle_fxo_power_denial(xpd_t *xpd)
  */
 static void check_etsi_dtmf(xpd_t *xpd)
 {
-       struct FXO_priv_data    *priv;
-       int                     portno;
-       unsigned int            timer_count;
+       struct FXO_priv_data *priv;
+       int portno;
+       unsigned int timer_count;
 
        if (!SPAN_REGISTERED(xpd))
                return;
@@ -726,22 +765,25 @@ static void check_etsi_dtmf(xpd_t *xpd)
                                /* reset flags if it's been a while */
                                priv->cidtimer[portno] = timer_count;
                                BIT_CLR(priv->cidfound, portno);
-                               LINE_DBG(SIGNAL, xpd, portno, "Reset CID flag\n");
+                               LINE_DBG(SIGNAL, xpd, portno,
+                                        "Reset CID flag\n");
                        }
                        continue;
                }
                if (timer_count > priv->cidtimer[portno] + 400) {
-                       struct dahdi_chan       *chan = XPD_CHAN(xpd, portno);
-                       int                     sample;
-                       int                     i;
+                       struct dahdi_chan *chan = XPD_CHAN(xpd, portno);
+                       int sample;
+                       int i;
 
                        for (i = 0; i < DAHDI_CHUNKSIZE; i++) {
                                sample = DAHDI_XLAW(chan->readchunk[i], chan);
                                if (sample > 16000 || sample < -16000) {
                                        priv->cidtimer[portno] = timer_count;
                                        BIT_SET(priv->cidfound, portno);
-                                       LINE_DBG(SIGNAL, xpd, portno, "Found DTMF CLIP (%d)\n", i);
-                                       dahdi_qevent_lock(chan, DAHDI_EVENT_POLARITY);
+                                       LINE_DBG(SIGNAL, xpd, portno,
+                                                "Found DTMF CLIP (%d)\n", i);
+                                       dahdi_qevent_lock(chan,
+                                                         DAHDI_EVENT_POLARITY);
                                        break;
                                }
                        }
@@ -751,15 +793,17 @@ static void check_etsi_dtmf(xpd_t *xpd)
 
 static int FXO_card_tick(xbus_t *xbus, xpd_t *xpd)
 {
-       struct FXO_priv_data    *priv;
+       struct FXO_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
        BUG_ON(!priv);
-       if (poll_battery_interval != 0 && (priv->poll_counter % poll_battery_interval) == 0)
+       if (poll_battery_interval != 0
+           && (priv->poll_counter % poll_battery_interval) == 0)
                poll_battery(xbus, xpd);
 #ifdef WITH_METERING
-       if (poll_metering_interval != 0 && (priv->poll_counter % poll_metering_interval) == 0)
+       if (poll_metering_interval != 0
+           && (priv->poll_counter % poll_metering_interval) == 0)
                poll_metering(xbus, xpd);
 #endif
        handle_fxo_leds(xpd);
@@ -777,47 +821,55 @@ static int FXO_card_tick(xbus_t *xbus, xpd_t *xpd)
  * We define the array size explicitly to track possible inconsistencies
  * if the struct is modified.
  */
-static const char echotune_regs[sizeof(struct wctdm_echo_coefs)] = {30, 45, 46, 47, 48, 49, 50, 51, 52};
+static const char echotune_regs[sizeof(struct wctdm_echo_coefs)] =
+    { 30, 45, 46, 47, 48, 49, 50, 51, 52 };
 
-static int FXO_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long arg)
+static int FXO_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd,
+                         unsigned long arg)
 {
-       int                     i, ret;
-       unsigned char           echotune_data[ARRAY_SIZE(echotune_regs)];
+       int i, ret;
+       unsigned char echotune_data[ARRAY_SIZE(echotune_regs)];
 
        BUG_ON(!xpd);
        if (!XBUS_IS(xpd->xbus, READY))
                return -ENODEV;
        switch (cmd) {
-               case WCTDM_SET_ECHOTUNE:
-                       XPD_DBG(GENERAL, xpd, "-- Setting echo registers: \n");
-                       /* first off: check if this span is fxs. If not: -EINVALID */
-                       if (copy_from_user(&echotune_data, (void __user *)arg, sizeof(echotune_data)))
-                               return -EFAULT;
-
-                       for (i = 0; i < ARRAY_SIZE(echotune_regs); i++) {
-                               XPD_DBG(REGS, xpd, "Reg=0x%02X, data=0x%02X\n", echotune_regs[i], echotune_data[i]);
-                               ret = DAA_DIRECT_REQUEST(xpd->xbus, xpd, pos, DAA_WRITE, echotune_regs[i], echotune_data[i]);
-                               if (ret < 0) {
-                                       LINE_NOTICE(xpd, pos, "Couldn't write %0x02X to register %0x02X\n",
-                                                       echotune_data[i], echotune_regs[i]);
-                                       return ret;
-                               }
-                               msleep(1);
+       case WCTDM_SET_ECHOTUNE:
+               XPD_DBG(GENERAL, xpd, "-- Setting echo registers: \n");
+               /* first off: check if this span is fxs. If not: -EINVALID */
+               if (copy_from_user
+                   (&echotune_data, (void __user *)arg, sizeof(echotune_data)))
+                       return -EFAULT;
+
+               for (i = 0; i < ARRAY_SIZE(echotune_regs); i++) {
+                       XPD_DBG(REGS, xpd, "Reg=0x%02X, data=0x%02X\n",
+                               echotune_regs[i], echotune_data[i]);
+                       ret =
+                           DAA_DIRECT_REQUEST(xpd->xbus, xpd, pos, DAA_WRITE,
+                                              echotune_regs[i],
+                                              echotune_data[i]);
+                       if (ret < 0) {
+                               LINE_NOTICE(xpd, pos,
+                                           "Couldn't write %0x02X to register %0x02X\n",
+                                           echotune_data[i], echotune_regs[i]);
+                               return ret;
                        }
+                       msleep(1);
+               }
 
-                       XPD_DBG(GENERAL, xpd, "-- Set echo registers successfully\n");
-                       break;
-               case DAHDI_TONEDETECT:
-                       /*
-                        * Asterisk call all span types with this (FXS specific)
-                        * call. Silently ignore it.
-                        */
-                       LINE_DBG(GENERAL, xpd, pos,
-                               "DAHDI_TONEDETECT (FXO: NOTIMPLEMENTED)\n");
-                       return -ENOTTY;
-               default:
-                       report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd);
-                       return -ENOTTY;
+               XPD_DBG(GENERAL, xpd, "-- Set echo registers successfully\n");
+               break;
+       case DAHDI_TONEDETECT:
+               /*
+                * Asterisk call all span types with this (FXS specific)
+                * call. Silently ignore it.
+                */
+               LINE_DBG(GENERAL, xpd, pos,
+                        "DAHDI_TONEDETECT (FXO: NOTIMPLEMENTED)\n");
+               return -ENOTTY;
+       default:
+               report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd);
+               return -ENOTTY;
        }
        return 0;
 }
@@ -828,11 +880,13 @@ static int FXO_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long a
 
 HANDLER_DEF(FXO, SIG_CHANGED)
 {
-       xpp_line_t      sig_status = RPACKET_FIELD(pack, FXO, SIG_CHANGED, sig_status);
-       xpp_line_t      sig_toggles = RPACKET_FIELD(pack, FXO, SIG_CHANGED, sig_toggles);
-       unsigned long   flags;
-       int             i;
-       struct FXO_priv_data    *priv;
+       xpp_line_t sig_status =
+           RPACKET_FIELD(pack, FXO, SIG_CHANGED, sig_status);
+       xpp_line_t sig_toggles =
+           RPACKET_FIELD(pack, FXO, SIG_CHANGED, sig_toggles);
+       unsigned long flags;
+       int i;
+       struct FXO_priv_data *priv;
 
        if (!xpd) {
                notify_bad_xpd(__func__, xbus, XPACKET_ADDR(pack), cmd->name);
@@ -840,10 +894,11 @@ HANDLER_DEF(FXO, SIG_CHANGED)
        }
        priv = xpd->priv;
        BUG_ON(!priv);
-       XPD_DBG(SIGNAL, xpd, "(PSTN) sig_toggles=0x%04X sig_status=0x%04X\n", sig_toggles, sig_status);
+       XPD_DBG(SIGNAL, xpd, "(PSTN) sig_toggles=0x%04X sig_status=0x%04X\n",
+               sig_toggles, sig_status);
        spin_lock_irqsave(&xpd->lock, flags);
        for_each_line(xpd, i) {
-               int     debounce;
+               int debounce;
 
                if (IS_SET(sig_toggles, i)) {
                        if (priv->battery[i] == BATTERY_OFF) {
@@ -851,18 +906,23 @@ HANDLER_DEF(FXO, SIG_CHANGED)
                                 * With poll_battery_interval==0 we cannot have BATTERY_OFF
                                 * so we won't get here
                                 */
-                               LINE_NOTICE(xpd, i, "SIG_CHANGED while battery is off. Ignored.\n");
+                               LINE_NOTICE(xpd, i,
+                                           "SIG_CHANGED while battery is off. Ignored.\n");
                                continue;
                        }
                        /* First report false ring alarms */
                        debounce = atomic_read(&priv->ring_debounce[i]);
                        if (debounce)
-                               LINE_NOTICE(xpd, i, "debounced false ring (only %d ticks)\n", debounce);
+                               LINE_NOTICE(xpd, i,
+                                           "debounced false ring (only %d ticks)\n",
+                                           debounce);
                        /*
                         * Now set a new ring alarm.
                         * It will be checked in handle_fxo_ring()
                         */
-                       debounce = (IS_SET(sig_status, i)) ? ring_debounce : -ring_debounce;
+                       debounce =
+                           (IS_SET(sig_status, i)) ? ring_debounce :
+                           -ring_debounce;
                        atomic_set(&priv->ring_debounce[i], debounce);
                }
        }
@@ -872,10 +932,10 @@ HANDLER_DEF(FXO, SIG_CHANGED)
 
 static void update_battery_voltage(xpd_t *xpd, __u8 data_low, xportno_t portno)
 {
-       struct FXO_priv_data    *priv;
-       enum polarity_state     pol;
-       int                     msec;
-       signed char             volts = (signed char)data_low;
+       struct FXO_priv_data *priv;
+       enum polarity_state pol;
+       int msec;
+       signed char volts = (signed char)data_low;
 
        priv = xpd->priv;
        BUG_ON(!priv);
@@ -887,12 +947,14 @@ static void update_battery_voltage(xpd_t *xpd, __u8 data_low, xportno_t portno)
                 * Check for battery voltage fluctuations
                 */
                if (priv->battery[portno] != BATTERY_OFF) {
-                       int     milliseconds;
+                       int milliseconds;
 
-                       milliseconds = priv->nobattery_debounce[portno]++ *
-                               poll_battery_interval;
+                       milliseconds =
+                           priv->nobattery_debounce[portno]++ *
+                           poll_battery_interval;
                        if (milliseconds > battery_debounce) {
-                               LINE_DBG(SIGNAL, xpd, portno, "BATTERY OFF voltage=%d\n", volts);
+                               LINE_DBG(SIGNAL, xpd, portno,
+                                        "BATTERY OFF voltage=%d\n", volts);
                                priv->battery[portno] = BATTERY_OFF;
                                dahdi_report_battery(xpd, portno);
                                /* What's the polarity ? */
@@ -910,7 +972,8 @@ static void update_battery_voltage(xpd_t *xpd, __u8 data_low, xportno_t portno)
        } else {
                priv->nobattery_debounce[portno] = 0;
                if (priv->battery[portno] != BATTERY_ON) {
-                       LINE_DBG(SIGNAL, xpd, portno, "BATTERY ON voltage=%d\n", volts);
+                       LINE_DBG(SIGNAL, xpd, portno, "BATTERY ON voltage=%d\n",
+                                volts);
                        priv->battery[portno] = BATTERY_ON;
                        dahdi_report_battery(xpd, portno);
                }
@@ -952,7 +1015,7 @@ static void update_battery_voltage(xpd_t *xpd, __u8 data_low, xportno_t portno)
        if (msec >= POLREV_THRESHOLD) {
                priv->polarity_debounce[portno] = 0;
                if (pol != POL_UNKNOWN && priv->polarity[portno] != POL_UNKNOWN) {
-                       char    *polname = NULL;
+                       char *polname = NULL;
 
                        if (pol == POL_POSITIVE)
                                polname = "Positive";
@@ -961,7 +1024,7 @@ static void update_battery_voltage(xpd_t *xpd, __u8 data_low, xportno_t portno)
                        else
                                BUG();
                        LINE_DBG(SIGNAL, xpd, portno,
-                               "Polarity changed to %s\n", polname);
+                                "Polarity changed to %s\n", polname);
                        /*
                         * Inform dahdi/Asterisk:
                         * 1. Maybe used for hangup detection during offhook
@@ -972,8 +1035,10 @@ static void update_battery_voltage(xpd_t *xpd, __u8 data_low, xportno_t portno)
                                oht_pcm(xpd, portno, 1);        /* will be cleared on ring/offhook */
                        if (SPAN_REGISTERED(xpd)) {
                                LINE_DBG(SIGNAL, xpd, portno,
-                                       "Send DAHDI_EVENT_POLARITY: %s\n", polname);
-                               dahdi_qevent_lock(XPD_CHAN(xpd, portno), DAHDI_EVENT_POLARITY);
+                                        "Send DAHDI_EVENT_POLARITY: %s\n",
+                                        polname);
+                               dahdi_qevent_lock(XPD_CHAN(xpd, portno),
+                                                 DAHDI_EVENT_POLARITY);
                        }
                }
                priv->polarity[portno] = pol;
@@ -988,7 +1053,7 @@ ignore_reading:
 
 static void update_battery_current(xpd_t *xpd, __u8 data_low, xportno_t portno)
 {
-       struct FXO_priv_data    *priv;
+       struct FXO_priv_data *priv;
 
        priv = xpd->priv;
        BUG_ON(!priv);
@@ -1030,16 +1095,16 @@ ignore_it:
 
 static void update_metering_state(xpd_t *xpd, __u8 data_low, lineno_t portno)
 {
-       struct FXO_priv_data    *priv;
-       bool                    metering_tone = data_low & BTD_BIT;
-       bool                    old_metering_tone;
+       struct FXO_priv_data *priv;
+       bool metering_tone = data_low & BTD_BIT;
+       bool old_metering_tone;
 
        priv = xpd->priv;
        BUG_ON(!priv);
        old_metering_tone = IS_SET(priv->metering_tone_state, portno);
        LINE_DBG(SIGNAL, xpd, portno, "METERING: %s [dL=0x%X] (%d)\n",
-               (metering_tone) ? "ON" : "OFF",
-               data_low, priv->metering_count[portno]);
+                (metering_tone) ? "ON" : "OFF", data_low,
+                priv->metering_count[portno]);
        if (metering_tone && !old_metering_tone) {
                /* Rising edge */
                priv->metering_count[portno]++;
@@ -1049,42 +1114,42 @@ static void update_metering_state(xpd_t *xpd, __u8 data_low, lineno_t portno)
        if (metering_tone) {
                /* Clear the BTD bit */
                data_low &= ~BTD_BIT;
-               DAA_DIRECT_REQUEST(xpd->xbus, xpd, portno, DAA_WRITE, DAA_REG_METERING, data_low);
+               DAA_DIRECT_REQUEST(xpd->xbus, xpd, portno, DAA_WRITE,
+                                  DAA_REG_METERING, data_low);
        }
 }
 #endif
 
 static int FXO_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
 {
-       struct FXO_priv_data    *priv;
-       lineno_t                portno;
+       struct FXO_priv_data *priv;
+       lineno_t portno;
 
        priv = xpd->priv;
        BUG_ON(!priv);
        portno = info->portnum;
        switch (REG_FIELD(info, regnum)) {
-               case DAA_REG_VBAT:
-                       update_battery_voltage(xpd, REG_FIELD(info, data_low), portno);
-                       break;
-               case DAA_REG_CURRENT:
-                       update_battery_current(xpd, REG_FIELD(info, data_low), portno);
-                       break;
+       case DAA_REG_VBAT:
+               update_battery_voltage(xpd, REG_FIELD(info, data_low), portno);
+               break;
+       case DAA_REG_CURRENT:
+               update_battery_current(xpd, REG_FIELD(info, data_low), portno);
+               break;
 #ifdef WITH_METERING
-               case DAA_REG_METERING:
-                       update_metering_state(xpd, REG_FIELD(info, data_low), portno);
-                       break;
+       case DAA_REG_METERING:
+               update_metering_state(xpd, REG_FIELD(info, data_low), portno);
+               break;
 #endif
        }
        LINE_DBG(REGS, xpd, portno, "%c reg_num=0x%X, dataL=0x%X dataH=0x%X\n",
-                       ((info->bytes == 3)?'I':'D'),
-                       REG_FIELD(info, regnum),
-                       REG_FIELD(info, data_low),
-                       REG_FIELD(info, data_high));
+                ((info->bytes == 3) ? 'I' : 'D'), REG_FIELD(info, regnum),
+                REG_FIELD(info, data_low), REG_FIELD(info, data_high));
        /* Update /proc info only if reply relate to the last slic read request */
-       if (
-                       REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) &&
-                       REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info, do_subreg) &&
-                       REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info, subreg)) {
+       if (REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum)
+           && REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info,
+                                                                       do_subreg)
+           && REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info,
+                                                                    subreg)) {
                xpd->last_reply = *info;
        }
        return 0;
@@ -1092,8 +1157,8 @@ static int FXO_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
 
 static int FXO_card_state(xpd_t *xpd, bool on)
 {
-       int                     ret = 0;
-       struct FXO_priv_data    *priv;
+       int ret = 0;
+       struct FXO_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -1102,47 +1167,40 @@ static int FXO_card_state(xpd_t *xpd, bool on)
        return ret;
 }
 
-static const struct xops       fxo_xops = {
-       .card_new       = FXO_card_new,
-       .card_init      = FXO_card_init,
-       .card_remove    = FXO_card_remove,
-       .card_tick      = FXO_card_tick,
-       .card_register_reply    = FXO_card_register_reply,
+static const struct xops fxo_xops = {
+       .card_new = FXO_card_new,
+       .card_init = FXO_card_init,
+       .card_remove = FXO_card_remove,
+       .card_tick = FXO_card_tick,
+       .card_register_reply = FXO_card_register_reply,
 };
 
-static const struct phoneops   fxo_phoneops = {
-       .card_dahdi_preregistration     = FXO_card_dahdi_preregistration,
-       .card_dahdi_postregistration    = FXO_card_dahdi_postregistration,
-       .card_hooksig   = FXO_card_hooksig,
-       .card_pcm_recompute     = generic_card_pcm_recompute,
-       .card_pcm_fromspan      = generic_card_pcm_fromspan,
-       .card_pcm_tospan        = generic_card_pcm_tospan,
-       .card_timing_priority   = generic_timing_priority,
-       .echocancel_timeslot    = generic_echocancel_timeslot,
-       .echocancel_setmask     = generic_echocancel_setmask,
-       .card_ioctl     = FXO_card_ioctl,
-       .card_open      = FXO_card_open,
-       .card_state     = FXO_card_state,
+static const struct phoneops fxo_phoneops = {
+       .card_dahdi_preregistration = FXO_card_dahdi_preregistration,
+       .card_dahdi_postregistration = FXO_card_dahdi_postregistration,
+       .card_hooksig = FXO_card_hooksig,
+       .card_pcm_recompute = generic_card_pcm_recompute,
+       .card_pcm_fromspan = generic_card_pcm_fromspan,
+       .card_pcm_tospan = generic_card_pcm_tospan,
+       .card_timing_priority = generic_timing_priority,
+       .echocancel_timeslot = generic_echocancel_timeslot,
+       .echocancel_setmask = generic_echocancel_setmask,
+       .card_ioctl = FXO_card_ioctl,
+       .card_open = FXO_card_open,
+       .card_state = FXO_card_state,
 };
 
 static xproto_table_t PROTO_TABLE(FXO) = {
-       .owner = THIS_MODULE,
-       .entries = {
-               /*      Prototable      Card    Opcode          */
-               XENTRY( FXO,            FXO,    SIG_CHANGED     ),
-       },
-       .name = "FXO",  /* protocol name */
-       .ports_per_subunit = 8,
-       .type = XPD_TYPE_FXO,
-       .xops = &fxo_xops,
-       .phoneops = &fxo_phoneops,
-       .packet_is_valid = fxo_packet_is_valid,
-       .packet_dump = fxo_packet_dump,
-};
+       .owner = THIS_MODULE,.entries = {
+               /*      Prototable      Card    Opcode          */
+       XENTRY(FXO, FXO, SIG_CHANGED),},.name = "FXO",  /* protocol name */
+.ports_per_subunit = 8,.type = XPD_TYPE_FXO,.xops =
+           &fxo_xops,.phoneops = &fxo_phoneops,.packet_is_valid =
+           fxo_packet_is_valid,.packet_dump = fxo_packet_dump,};
 
 static bool fxo_packet_is_valid(xpacket_t *pack)
 {
-       const xproto_entry_t    *xe;
+       const xproto_entry_t *xe;
 
        //DBG(GENERAL, "\n");
        xe = xproto_card_entry(&PROTO_TABLE(FXO), XPACKET_OP(pack));
@@ -1157,13 +1215,14 @@ static void fxo_packet_dump(const char *msg, xpacket_t *pack)
 /*------------------------- DAA Handling --------------------------*/
 
 #ifdef CONFIG_PROC_FS
-static int proc_fxo_info_read(char *page, char **start, off_t off, int count, int *eof, void *data)
+static int proc_fxo_info_read(char *page, char **start, off_t off, int count,
+                             int *eof, void *data)
 {
-       int                     len = 0;
-       unsigned long           flags;
-       xpd_t                   *xpd = data;
-       struct FXO_priv_data    *priv;
-       int                     i;
+       int len = 0;
+       unsigned long flags;
+       xpd_t *xpd = data;
+       struct FXO_priv_data *priv;
+       int i;
 
        if (!xpd)
                return -ENODEV;
@@ -1172,23 +1231,28 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in
        BUG_ON(!priv);
        len += sprintf(page + len, "\t%-17s: ", "Channel");
        for_each_line(xpd, i) {
-               if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) && !IS_SET(PHONEDEV(xpd).digital_inputs, i))
+               if (!IS_SET(PHONEDEV(xpd).digital_outputs, i)
+                   && !IS_SET(PHONEDEV(xpd).digital_inputs, i))
                        len += sprintf(page + len, "%4d ", i % 10);
        }
        len += sprintf(page + len, "\nLeds:");
        len += sprintf(page + len, "\n\t%-17s: ", "state");
        for_each_line(xpd, i) {
-               if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) && !IS_SET(PHONEDEV(xpd).digital_inputs, i))
-                       len += sprintf(page + len, "  %d%d ",
-                               IS_SET(priv->ledstate[LED_GREEN], i),
-                               IS_SET(priv->ledstate[LED_RED], i));
+               if (!IS_SET(PHONEDEV(xpd).digital_outputs, i)
+                   && !IS_SET(PHONEDEV(xpd).digital_inputs, i))
+                       len +=
+                           sprintf(page + len, "  %d%d ",
+                                   IS_SET(priv->ledstate[LED_GREEN], i),
+                                   IS_SET(priv->ledstate[LED_RED], i));
        }
        len += sprintf(page + len, "\n\t%-17s: ", "blinking");
        for_each_line(xpd, i) {
-               if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) && !IS_SET(PHONEDEV(xpd).digital_inputs, i))
-                       len += sprintf(page + len, "  %d%d ",
-                               IS_BLINKING(priv, i, LED_GREEN),
-                               IS_BLINKING(priv, i, LED_RED));
+               if (!IS_SET(PHONEDEV(xpd).digital_outputs, i)
+                   && !IS_SET(PHONEDEV(xpd).digital_inputs, i))
+                       len +=
+                           sprintf(page + len, "  %d%d ",
+                                   IS_BLINKING(priv, i, LED_GREEN),
+                                   IS_BLINKING(priv, i, LED_RED));
        }
        len += sprintf(page + len, "\nBattery-Data:");
        len += sprintf(page + len, "\n\t%-17s: ", "voltage");
@@ -1202,7 +1266,7 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in
        len += sprintf(page + len, "\nBattery:");
        len += sprintf(page + len, "\n\t%-17s: ", "on");
        for_each_line(xpd, i) {
-               char    *bat;
+               char *bat;
 
                if (priv->battery[i] == BATTERY_ON)
                        bat = "+";
@@ -1219,7 +1283,7 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in
        len += sprintf(page + len, "\nPolarity-Reverse:");
        len += sprintf(page + len, "\n\t%-17s: ", "polarity");
        for_each_line(xpd, i) {
-               char    *polname;
+               char *polname;
 
                if (priv->polarity[i] == POL_POSITIVE)
                        polname = "+";
@@ -1236,7 +1300,7 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in
        len += sprintf(page + len, "\nPower-Denial:");
        len += sprintf(page + len, "\n\t%-17s: ", "power");
        for_each_line(xpd, i) {
-               char    *curr;
+               char *curr;
 
                if (priv->power[i] == POWER_ON)
                        curr = "+";
@@ -1248,7 +1312,8 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in
        }
        len += sprintf(page + len, "\n\t%-17s: ", "safezone");
        for_each_line(xpd, i) {
-               len += sprintf(page + len, "%4d ", priv->power_denial_safezone[i]);
+               len +=
+                   sprintf(page + len, "%4d ", priv->power_denial_safezone[i]);
        }
        len += sprintf(page + len, "\n\t%-17s: ", "delay");
        for_each_line(xpd, i) {
@@ -1263,7 +1328,7 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in
 #endif
        len += sprintf(page + len, "\n");
        spin_unlock_irqrestore(&xpd->lock, flags);
-       if (len <= off+count)
+       if (len <= off + count)
                *eof = 1;
        *start = page + off;
        len -= off;
@@ -1276,13 +1341,14 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in
 #endif
 
 #ifdef WITH_METERING
-static int proc_xpd_metering_read(char *page, char **start, off_t off, int count, int *eof, void *data)
+static int proc_xpd_metering_read(char *page, char **start, off_t off,
+                                 int count, int *eof, void *data)
 {
-       int                     len = 0;
-       unsigned long           flags;
-       xpd_t                   *xpd = data;
-       struct FXO_priv_data    *priv;
-       int                     i;
+       int len = 0;
+       unsigned long flags;
+       xpd_t *xpd = data;
+       struct FXO_priv_data *priv;
+       int i;
 
        if (!xpd)
                return -ENODEV;
@@ -1291,11 +1357,11 @@ static int proc_xpd_metering_read(char *page, char **start, off_t off, int count
        spin_lock_irqsave(&xpd->lock, flags);
        len += sprintf(page + len, "# Chan\tMeter (since last read)\n");
        for_each_line(xpd, i) {
-               len += sprintf(page + len, "%d\t%d\n",
-                       i, priv->metering_count[i]);
+               len +=
+                   sprintf(page + len, "%d\t%d\n", i, priv->metering_count[i]);
        }
        spin_unlock_irqrestore(&xpd->lock, flags);
-       if (len <= off+count)
+       if (len <= off + count)
                *eof = 1;
        *start = page + off;
        len -= off;
@@ -1305,18 +1371,18 @@ static int proc_xpd_metering_read(char *page, char **start, off_t off, int count
                len = 0;
        /* Zero meters */
        for_each_line(xpd, i)
-               priv->metering_count[i] = 0;
+           priv->metering_count[i] = 0;
        return len;
 }
 #endif
 
 static DEVICE_ATTR_READER(fxo_battery_show, dev, buf)
 {
-       xpd_t                   *xpd;
-       struct FXO_priv_data    *priv;
-       unsigned long           flags;
-       int                     len = 0;
-       int                     i;
+       xpd_t *xpd;
+       struct FXO_priv_data *priv;
+       unsigned long flags;
+       int len = 0;
+       int i;
 
        BUG_ON(!dev);
        xpd = dev_to_xpd(dev);
@@ -1326,7 +1392,7 @@ static DEVICE_ATTR_READER(fxo_battery_show, dev, buf)
        BUG_ON(!priv);
        spin_lock_irqsave(&xpd->lock, flags);
        for_each_line(xpd, i) {
-               char    bat;
+               char bat;
 
                if (priv->battery[i] == BATTERY_ON)
                        bat = '+';
@@ -1341,25 +1407,25 @@ static DEVICE_ATTR_READER(fxo_battery_show, dev, buf)
        return len;
 }
 
-static DEVICE_ATTR(fxo_battery, S_IRUGO, fxo_battery_show, NULL);
-
+static DEVICE_ATTR(fxo_battery, S_IRUGO, fxo_battery_show, NULL);
 
 static int fxo_xpd_probe(struct device *dev)
 {
-       xpd_t   *xpd;
-       int     ret;
+       xpd_t *xpd;
+       int ret;
 
        xpd = dev_to_xpd(dev);
        /* Is it our device? */
        if (xpd->type != XPD_TYPE_FXO) {
-               XPD_ERR(xpd, "drop suggestion for %s (%d)\n",
-                       dev_name(dev), xpd->type);
+               XPD_ERR(xpd, "drop suggestion for %s (%d)\n", dev_name(dev),
+                       xpd->type);
                return -EINVAL;
        }
        XPD_DBG(DEVICES, xpd, "SYSFS\n");
        ret = device_create_file(dev, &dev_attr_fxo_battery);
        if (ret) {
-               XPD_ERR(xpd, "%s: device_create_file(fxo_battery) failed: %d\n", __func__, ret);
+               XPD_ERR(xpd, "%s: device_create_file(fxo_battery) failed: %d\n",
+                       __func__, ret);
                goto fail_fxo_battery;
        }
        return 0;
@@ -1369,7 +1435,7 @@ fail_fxo_battery:
 
 static int fxo_xpd_remove(struct device *dev)
 {
-       xpd_t   *xpd;
+       xpd_t *xpd;
 
        xpd = dev_to_xpd(dev);
        XPD_DBG(DEVICES, xpd, "SYSFS\n");
@@ -1377,24 +1443,24 @@ static int fxo_xpd_remove(struct device *dev)
        return 0;
 }
 
-static struct xpd_driver       fxo_driver = {
-       .type           = XPD_TYPE_FXO,
-       .driver         = {
-               .name = "fxo",
+static struct xpd_driver fxo_driver = {
+       .type = XPD_TYPE_FXO,
+       .driver = {
+                  .name = "fxo",
 #ifndef OLD_HOTPLUG_SUPPORT
-               .owner = THIS_MODULE,
+                  .owner = THIS_MODULE,
 #endif
-               .probe = fxo_xpd_probe,
-               .remove = fxo_xpd_remove
-       }
+                  .probe = fxo_xpd_probe,
+                  .remove = fxo_xpd_remove}
 };
 
 static int __init card_fxo_startup(void)
 {
-       int     ret;
+       int ret;
 
        if (ring_debounce <= 0) {
-               ERR("ring_debounce=%d. Must be positive number of ticks\n", ring_debounce);
+               ERR("ring_debounce=%d. Must be positive number of ticks\n",
+                   ring_debounce);
                return -EINVAL;
        }
        if ((ret = xpd_driver_register(&fxo_driver.driver)) < 0)
index f6f020f..f7289d3 100644 (file)
 #include "xpd.h"
 
 enum fxo_opcodes {
-       XPROTO_NAME(FXO, SIG_CHANGED)           = 0x06,
-/**/
-       XPROTO_NAME(FXO, DAA_WRITE)             = 0x0F, /* Write to DAA */
-       XPROTO_NAME(FXO, CHAN_CID)              = 0x0F, /* Write to DAA */
-       XPROTO_NAME(FXO, LED)                   = 0x0F, /* Write to DAA */
+       XPROTO_NAME(FXO, SIG_CHANGED) = 0x06,
+        /**/ XPROTO_NAME(FXO, DAA_WRITE) = 0x0F,       /* Write to DAA */
+       XPROTO_NAME(FXO, CHAN_CID) = 0x0F,      /* Write to DAA */
+       XPROTO_NAME(FXO, LED) = 0x0F,   /* Write to DAA */
 };
 
+DEF_RPACKET_DATA(FXO, SIG_CHANGED, xpp_line_t sig_status;      /* channels: lsb=1, msb=8 */
+                xpp_line_t sig_toggles;        /* channels: lsb=1, msb=8 */
+    );
 
-DEF_RPACKET_DATA(FXO, SIG_CHANGED,
-       xpp_line_t      sig_status;     /* channels: lsb=1, msb=8 */
-       xpp_line_t      sig_toggles;    /* channels: lsb=1, msb=8 */
-       );
-
-#endif /* CARD_FXO_H */
+#endif /* CARD_FXO_H */
index 94270ba..f894d6a 100644 (file)
@@ -40,7 +40,8 @@ static DEF_PARM_BOOL(dtmf_detection, 1, 0644, "Do DTMF detection in hardware");
 static DEF_PARM(uint, poll_digital_inputs, 1000, 0644, "Poll Digital Inputs");
 #endif
 
-static DEF_PARM_BOOL(vmwi_ioctl, 1, 0644, "Asterisk support VMWI notification via ioctl");
+static DEF_PARM_BOOL(vmwi_ioctl, 1, 0644,
+                    "Asterisk support VMWI notification via ioctl");
 static DEF_PARM_BOOL(ring_trapez, 0, 0664, "Use trapezoid ring type");
 
 /* Signaling is opposite (fxo signalling for fxs card) */
@@ -79,14 +80,14 @@ enum fxs_leds {
 
 /* Values of SLIC linefeed control register (0x40) */
 enum fxs_state {
-       FXS_LINE_OPEN           = 0x00, /* Open */
-       FXS_LINE_ACTIVE         = 0x01, /* Forward active */
-       FXS_LINE_OHTRANS        = 0x02, /* Forward on-hook transmission */
-       FXS_LINE_TIPOPEN        = 0x03, /* TIP open */
-       FXS_LINE_RING           = 0x04, /* Ringing */
-       FXS_LINE_REV_ACTIVE     = 0x05, /* Reverse active */
-       FXS_LINE_REV_OHTRANS    = 0x06, /* Reverse on-hook transmission */
-       FXS_LINE_RING_OPEN      = 0x07  /* RING open */
+       FXS_LINE_OPEN = 0x00,   /* Open */
+       FXS_LINE_ACTIVE = 0x01, /* Forward active */
+       FXS_LINE_OHTRANS = 0x02,        /* Forward on-hook transmission */
+       FXS_LINE_TIPOPEN = 0x03,        /* TIP open */
+       FXS_LINE_RING = 0x04,   /* Ringing */
+       FXS_LINE_REV_ACTIVE = 0x05,     /* Reverse active */
+       FXS_LINE_REV_OHTRANS = 0x06,    /* Reverse on-hook transmission */
+       FXS_LINE_RING_OPEN = 0x07       /* RING open */
 };
 
 #define        FXS_LINE_POL_ACTIVE     ((reversepolarity) ? FXS_LINE_REV_ACTIVE : FXS_LINE_ACTIVE)
@@ -108,9 +109,11 @@ enum fxs_state {
 static bool fxs_packet_is_valid(xpacket_t *pack);
 static void fxs_packet_dump(const char *msg, xpacket_t *pack);
 #ifdef CONFIG_PROC_FS
-static int proc_fxs_info_read(char *page, char **start, off_t off, int count, int *eof, void *data);
+static int proc_fxs_info_read(char *page, char **start, off_t off, int count,
+                             int *eof, void *data);
 #ifdef WITH_METERING
-static int proc_xpd_metering_write(struct file *file, const char __user *buffer, unsigned long count, void *data);
+static int proc_xpd_metering_write(struct file *file, const char __user *buffer,
+                                  unsigned long count, void *data);
 #endif
 #endif
 static void start_stop_vm_led(xbus_t *xbus, xpd_t *xpd, lineno_t pos);
@@ -123,25 +126,25 @@ static void start_stop_vm_led(xbus_t *xbus, xpd_t *xpd, lineno_t pos);
 
 struct FXS_priv_data {
 #ifdef WITH_METERING
-       struct proc_dir_entry   *meteringfile;
+       struct proc_dir_entry *meteringfile;
 #endif
-       struct proc_dir_entry   *fxs_info;
-       xpp_line_t              ledstate[NUM_LEDS];     /* 0 - OFF, 1 - ON */
-       xpp_line_t              ledcontrol[NUM_LEDS];   /* 0 - OFF, 1 - ON */
-       xpp_line_t              search_fsk_pattern;
-       xpp_line_t              found_fsk_pattern;
-       xpp_line_t              update_offhook_state;
-       xpp_line_t              want_dtmf_events;       /* what dahdi want */
-       xpp_line_t              want_dtmf_mute;         /* what dahdi want */
-       xpp_line_t              prev_key_down;          /* DTMF down sets the bit */
-       xpp_line_t              neon_blinking;
-       struct timeval          prev_key_time[CHANNELS_PERXPD];
-       int                     led_counter[NUM_LEDS][CHANNELS_PERXPD];
-       int                     ohttimer[CHANNELS_PERXPD];
+       struct proc_dir_entry *fxs_info;
+       xpp_line_t ledstate[NUM_LEDS];  /* 0 - OFF, 1 - ON */
+       xpp_line_t ledcontrol[NUM_LEDS];        /* 0 - OFF, 1 - ON */
+       xpp_line_t search_fsk_pattern;
+       xpp_line_t found_fsk_pattern;
+       xpp_line_t update_offhook_state;
+       xpp_line_t want_dtmf_events;    /* what dahdi want */
+       xpp_line_t want_dtmf_mute;      /* what dahdi want */
+       xpp_line_t prev_key_down;       /* DTMF down sets the bit */
+       xpp_line_t neon_blinking;
+       struct timeval prev_key_time[CHANNELS_PERXPD];
+       int led_counter[NUM_LEDS][CHANNELS_PERXPD];
+       int ohttimer[CHANNELS_PERXPD];
 #define OHT_TIMER              6000    /* How long after RING to retain OHT */
-       enum fxs_state          idletxhookstate[CHANNELS_PERXPD];       /* IDLE changing hook state */
-       enum fxs_state          lasttxhook[CHANNELS_PERXPD];
-       struct dahdi_vmwi_info  vmwisetting[CHANNELS_PERXPD];
+       enum fxs_state idletxhookstate[CHANNELS_PERXPD];        /* IDLE changing hook state */
+       enum fxs_state lasttxhook[CHANNELS_PERXPD];
+       struct dahdi_vmwi_info vmwisetting[CHANNELS_PERXPD];
 };
 
 /*
@@ -157,9 +160,10 @@ struct FXS_priv_data {
 #define        LED_BLINK_RING                  (1000/8)        /* in ticks */
 
 /*---------------- FXS: Static functions ----------------------------------*/
-static int linefeed_control(xbus_t *xbus, xpd_t *xpd, lineno_t chan, enum fxs_state value)
+static int linefeed_control(xbus_t *xbus, xpd_t *xpd, lineno_t chan,
+                           enum fxs_state value)
 {
-       struct FXS_priv_data    *priv;
+       struct FXS_priv_data *priv;
 
        priv = xpd->priv;
        LINE_DBG(SIGNAL, xpd, chan, "value=0x%02X\n", value);
@@ -169,17 +173,18 @@ static int linefeed_control(xbus_t *xbus, xpd_t *xpd, lineno_t chan, enum fxs_st
 
 static int do_chan_power(xbus_t *xbus, xpd_t *xpd, lineno_t chan, bool on)
 {
-       int             value = (on) ? REG_BATTERY_BATSL : 0x00;
+       int value = (on) ? REG_BATTERY_BATSL : 0x00;
 
        BUG_ON(!xbus);
        BUG_ON(!xpd);
        LINE_DBG(SIGNAL, xpd, chan, "%s\n", (on) ? "up" : "down");
-       return SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE, REG_BATTERY, value);
+       return SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE, REG_BATTERY,
+                                  value);
 }
 
 static void vmwi_search(xpd_t *xpd, lineno_t pos, bool on)
 {
-       struct FXS_priv_data    *priv;
+       struct FXS_priv_data *priv;
 
        priv = xpd->priv;
        BUG_ON(!xpd);
@@ -215,9 +220,9 @@ static void vmwi_search(xpd_t *xpd, lineno_t pos, bool on)
  *     The OUTPUT RELAY (actually a relay out) is connected to line 0 and 4 only.
  */
 
-//                                             GREEN   RED     OUTPUT RELAY
-static const int       led_register_mask[] = { BIT(7), BIT(6), BIT(5) };
-static const int       led_register_vals[] = { BIT(4), BIT(1), BIT(0) };
+//                                              GREEN   RED     OUTPUT RELAY
+static const int led_register_mask[] = { BIT(7), BIT(6), BIT(5) };
+static const int led_register_vals[] = { BIT(4), BIT(1), BIT(0) };
 
 /*
  * pos can be:
@@ -226,17 +231,18 @@ static const int  led_register_vals[] = { BIT(4), BIT(1), BIT(0) };
  */
 static int do_led(xpd_t *xpd, lineno_t chan, __u8 which, bool on)
 {
-       int                     ret = 0;
-       struct FXS_priv_data    *priv;
-       int                     value;
-       xbus_t                  *xbus;
+       int ret = 0;
+       struct FXS_priv_data *priv;
+       int value;
+       xbus_t *xbus;
 
        BUG_ON(!xpd);
        BUG_ON(chan == ALL_LINES);
        xbus = xpd->xbus;
        priv = xpd->priv;
        which = which % NUM_LEDS;
-       if (IS_SET(PHONEDEV(xpd).digital_outputs, chan) || IS_SET(PHONEDEV(xpd).digital_inputs, chan))
+       if (IS_SET(PHONEDEV(xpd).digital_outputs, chan)
+           || IS_SET(PHONEDEV(xpd).digital_inputs, chan))
                goto out;
        if (chan == PORT_BROADCAST) {
                priv->ledstate[which] = (on) ? ~0 : 0;
@@ -247,50 +253,63 @@ static int do_led(xpd_t *xpd, lineno_t chan, __u8 which, bool on)
                        BIT_CLR(priv->ledstate[which], chan);
                }
        }
-       LINE_DBG(LEDS, xpd, chan, "LED: which=%d -- %s\n", which, (on) ? "on" : "off");
+       LINE_DBG(LEDS, xpd, chan, "LED: which=%d -- %s\n", which,
+                (on) ? "on" : "off");
        value = BIT(2) | BIT(3);
        value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[which]);
        if (on)
                value |= led_register_vals[which];
-       ret = SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE,
-                       REG_DIGITAL_IOCTRL, value);
+       ret =
+           SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE, REG_DIGITAL_IOCTRL,
+                               value);
 out:
        return ret;
 }
 
 static void handle_fxs_leds(xpd_t *xpd)
 {
-       int                     i;
-       const enum fxs_leds     colors[] = { LED_GREEN, LED_RED };
-       enum fxs_leds           color;
-       unsigned int            timer_count;
-       struct FXS_priv_data    *priv;
+       int i;
+       const enum fxs_leds colors[] = { LED_GREEN, LED_RED };
+       enum fxs_leds color;
+       unsigned int timer_count;
+       struct FXS_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
        timer_count = xpd->timer_count;
        for (color = 0; color < ARRAY_SIZE(colors); color++) {
                for_each_line(xpd, i) {
-                       if (IS_SET(PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).digital_inputs, i))
+                       if (IS_SET
+                           (PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).
+                            digital_inputs, i))
                                continue;
-                       if ((xpd->blink_mode & BIT(i)) || IS_BLINKING(priv, i, color)) {                // Blinking
-                               int     mod_value = LED_COUNTER(priv, i, color);
+                       if ((xpd->blink_mode & BIT(i)) || IS_BLINKING(priv, i, color)) {        // Blinking
+                               int mod_value = LED_COUNTER(priv, i, color);
 
                                if (!mod_value)
-                                       mod_value = DEFAULT_LED_PERIOD;         /* safety value */
+                                       mod_value = DEFAULT_LED_PERIOD; /* safety value */
                                // led state is toggled
                                if ((timer_count % mod_value) == 0) {
-                                       LINE_DBG(LEDS, xpd, i, "ledstate=%s\n", (IS_SET(priv->ledstate[color], i))?"ON":"OFF");
+                                       LINE_DBG(LEDS, xpd, i, "ledstate=%s\n",
+                                                (IS_SET
+                                                 (priv->ledstate[color],
+                                                  i)) ? "ON" : "OFF");
                                        if (!IS_SET(priv->ledstate[color], i)) {
                                                do_led(xpd, i, color, 1);
                                        } else {
                                                do_led(xpd, i, color, 0);
                                        }
                                }
-                       } else if (IS_SET(priv->ledcontrol[color] & ~priv->ledstate[color], i)) {
-                                               do_led(xpd, i, color, 1);
-                       } else if (IS_SET(~priv->ledcontrol[color] & priv->ledstate[color], i)) {
-                                               do_led(xpd, i, color, 0);
+                       } else
+                           if (IS_SET
+                               (priv->ledcontrol[color] & ~priv->
+                                ledstate[color], i)) {
+                               do_led(xpd, i, color, 1);
+                       } else
+                           if (IS_SET
+                               (~priv->ledcontrol[color] & priv->
+                                ledstate[color], i)) {
+                               do_led(xpd, i, color, 0);
                        }
 
                }
@@ -299,8 +318,8 @@ static void handle_fxs_leds(xpd_t *xpd)
 
 static void restore_leds(xpd_t *xpd)
 {
-       struct FXS_priv_data    *priv;
-       int                     i;
+       struct FXS_priv_data *priv;
+       int i;
 
        priv = xpd->priv;
        for_each_line(xpd, i) {
@@ -314,10 +333,12 @@ static void restore_leds(xpd_t *xpd)
 #ifdef WITH_METERING
 static int metering_gen(xpd_t *xpd, lineno_t chan, bool on)
 {
-       __u8    value = (on) ? 0x94 : 0x00;
+       __u8 value = (on) ? 0x94 : 0x00;
 
-       LINE_DBG(SIGNAL, xpd, chan, "METERING Generate: %s\n", (on)?"ON":"OFF");
-       return SLIC_DIRECT_REQUEST(xpd->xbus, xpd, chan, SLIC_WRITE, 0x23, value);
+       LINE_DBG(SIGNAL, xpd, chan, "METERING Generate: %s\n",
+                (on) ? "ON" : "OFF");
+       return SLIC_DIRECT_REQUEST(xpd->xbus, xpd, chan, SLIC_WRITE, 0x23,
+                                  value);
 }
 #endif
 
@@ -325,7 +346,7 @@ static int metering_gen(xpd_t *xpd, lineno_t chan, bool on)
 
 static void fxs_proc_remove(xbus_t *xbus, xpd_t *xpd)
 {
-       struct FXS_priv_data    *priv;
+       struct FXS_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -348,25 +369,30 @@ static void fxs_proc_remove(xbus_t *xbus, xpd_t *xpd)
 
 static int fxs_proc_create(xbus_t *xbus, xpd_t *xpd)
 {
-       struct FXS_priv_data    *priv;
+       struct FXS_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
 
 #ifdef CONFIG_PROC_FS
        XPD_DBG(PROC, xpd, "Creating FXS_INFO file\n");
-       priv->fxs_info = create_proc_read_entry(PROC_FXS_INFO_FNAME, 0444, xpd->proc_xpd_dir, proc_fxs_info_read, xpd);
+       priv->fxs_info =
+           create_proc_read_entry(PROC_FXS_INFO_FNAME, 0444, xpd->proc_xpd_dir,
+                                  proc_fxs_info_read, xpd);
        if (!priv->fxs_info) {
-               XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_FXS_INFO_FNAME);
+               XPD_ERR(xpd, "Failed to create proc file '%s'\n",
+                       PROC_FXS_INFO_FNAME);
                fxs_proc_remove(xbus, xpd);
                return -EINVAL;
        }
        SET_PROC_DIRENTRY_OWNER(priv->fxs_info);
 #ifdef WITH_METERING
        XPD_DBG(PROC, xpd, "Creating Metering tone file\n");
-       priv->meteringfile = create_proc_entry(PROC_METERING_FNAME, 0200, xpd->proc_xpd_dir);
+       priv->meteringfile =
+           create_proc_entry(PROC_METERING_FNAME, 0200, xpd->proc_xpd_dir);
        if (!priv->meteringfile) {
-               XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_METERING_FNAME);
+               XPD_ERR(xpd, "Failed to create proc file '%s'\n",
+                       PROC_METERING_FNAME);
                fxs_proc_remove(xbus, xpd);
                return -EINVAL;
        }
@@ -379,21 +405,22 @@ static int fxs_proc_create(xbus_t *xbus, xpd_t *xpd)
        return 0;
 }
 
-static xpd_t *FXS_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table,
-       __u8 subtype, int subunits, int subunit_ports, bool to_phone)
+static xpd_t *FXS_card_new(xbus_t *xbus, int unit, int subunit,
+                          const xproto_table_t *proto_table, __u8 subtype,
+                          int subunits, int subunit_ports, bool to_phone)
 {
-       xpd_t                   *xpd = NULL;
-       int                     channels;
-       int                     regular_channels;
-       struct FXS_priv_data    *priv;
-       int                     i;
-       int                     d_inputs = 0;
-       int                     d_outputs = 0;
+       xpd_t *xpd = NULL;
+       int channels;
+       int regular_channels;
+       struct FXS_priv_data *priv;
+       int i;
+       int d_inputs = 0;
+       int d_outputs = 0;
 
        if (!to_phone) {
                XBUS_NOTICE(xbus,
-                       "XPD=%d%d: try to instanciate FXS with reverse direction\n",
-                       unit, subunit);
+                           "XPD=%d%d: try to instanciate FXS with reverse direction\n",
+                           unit, subunit);
                return NULL;
        }
        if (subtype == 2)
@@ -407,22 +434,24 @@ static xpd_t *FXS_card_new(xbus_t *xbus, int unit, int subunit, const xproto_tab
                d_inputs = LINES_DIGI_INP;
                d_outputs = LINES_DIGI_OUT;
        }
-       xpd = xpd_alloc(xbus, unit, subunit, subtype, subunits, sizeof(struct FXS_priv_data), proto_table, channels);
+       xpd =
+           xpd_alloc(xbus, unit, subunit, subtype, subunits,
+                     sizeof(struct FXS_priv_data), proto_table, channels);
        if (!xpd)
                return NULL;
        /* Initialize digital inputs/outputs */
        if (d_inputs) {
                XBUS_DBG(GENERAL, xbus, "Initialize %d digital inputs\n",
-                       d_inputs);
+                        d_inputs);
                PHONEDEV(xpd).digital_inputs =
-                       BITMASK(d_inputs) << (regular_channels + d_outputs);
+                   BITMASK(d_inputs) << (regular_channels + d_outputs);
        } else
                XBUS_DBG(GENERAL, xbus, "No digital inputs\n");
        if (d_outputs) {
                XBUS_DBG(GENERAL, xbus, "Initialize %d digital outputs\n",
-                       d_outputs);
+                        d_outputs);
                PHONEDEV(xpd).digital_outputs =
-                       BITMASK(d_outputs) << regular_channels;
+                   BITMASK(d_outputs) << regular_channels;
        } else
                XBUS_DBG(GENERAL, xbus, "No digital outputs\n");
        PHONEDEV(xpd).direction = TO_PHONE;
@@ -441,8 +470,8 @@ err:
 
 static int FXS_card_init(xbus_t *xbus, xpd_t *xpd)
 {
-       int                     ret = 0;
-       int                     i;
+       int ret = 0;
+       int i;
 
        BUG_ON(!xpd);
        /*
@@ -476,9 +505,12 @@ static int FXS_card_init(xbus_t *xbus, xpd_t *xpd)
         * So we do this after the LEDs
         */
        for_each_line(xpd, i) {
-               if (IS_SET(PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).digital_inputs, i))
+               if (IS_SET
+                   (PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).
+                    digital_inputs, i))
                        continue;
-               SLIC_DIRECT_REQUEST(xbus, xpd, i, SLIC_READ, REG_LOOPCLOSURE, 0);
+               SLIC_DIRECT_REQUEST(xbus, xpd, i, SLIC_READ, REG_LOOPCLOSURE,
+                                   0);
        }
        return 0;
 err:
@@ -497,30 +529,33 @@ static int FXS_card_remove(xbus_t *xbus, xpd_t *xpd)
 
 static int FXS_card_dahdi_preregistration(xpd_t *xpd, bool on)
 {
-       xbus_t                  *xbus;
-       struct FXS_priv_data    *priv;
-       int                     i;
+       xbus_t *xbus;
+       struct FXS_priv_data *priv;
+       int i;
 
        BUG_ON(!xpd);
        xbus = xpd->xbus;
        BUG_ON(!xbus);
        priv = xpd->priv;
        BUG_ON(!priv);
-       XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off");
+       XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off");
        PHONEDEV(xpd).span.spantype = "FXS";
        for_each_line(xpd, i) {
-               struct dahdi_chan       *cur_chan = XPD_CHAN(xpd, i);
+               struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i);
 
                XPD_DBG(GENERAL, xpd, "setting FXS channel %d\n", i);
                if (IS_SET(PHONEDEV(xpd).digital_outputs, i)) {
-                       snprintf(cur_chan->name, MAX_CHANNAME, "XPP_OUT/%02d/%1d%1d/%d",
-                               xbus->num, xpd->addr.unit, xpd->addr.subunit, i);
+                       snprintf(cur_chan->name, MAX_CHANNAME,
+                                "XPP_OUT/%02d/%1d%1d/%d", xbus->num,
+                                xpd->addr.unit, xpd->addr.subunit, i);
                } else if (IS_SET(PHONEDEV(xpd).digital_inputs, i)) {
-                       snprintf(cur_chan->name, MAX_CHANNAME, "XPP_IN/%02d/%1d%1d/%d",
-                               xbus->num, xpd->addr.unit, xpd->addr.subunit, i);
+                       snprintf(cur_chan->name, MAX_CHANNAME,
+                                "XPP_IN/%02d/%1d%1d/%d", xbus->num,
+                                xpd->addr.unit, xpd->addr.subunit, i);
                } else {
-                       snprintf(cur_chan->name, MAX_CHANNAME, "XPP_FXS/%02d/%1d%1d/%d",
-                               xbus->num, xpd->addr.unit, xpd->addr.subunit, i);
+                       snprintf(cur_chan->name, MAX_CHANNAME,
+                                "XPP_FXS/%02d/%1d%1d/%d", xbus->num,
+                                xpd->addr.unit, xpd->addr.subunit, i);
                }
                cur_chan->chanpos = i + 1;
                cur_chan->pvt = xpd;
@@ -540,16 +575,16 @@ static int FXS_card_dahdi_preregistration(xpd_t *xpd, bool on)
 
 static int FXS_card_dahdi_postregistration(xpd_t *xpd, bool on)
 {
-       xbus_t                  *xbus;
-       struct FXS_priv_data    *priv;
-       int                     i;
+       xbus_t *xbus;
+       struct FXS_priv_data *priv;
+       int i;
 
        BUG_ON(!xpd);
        xbus = xpd->xbus;
        BUG_ON(!xbus);
        priv = xpd->priv;
        BUG_ON(!priv);
-       XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off");
+       XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off");
        for_each_line(xpd, i) {
                MARK_OFF(priv, i, LED_GREEN);
                msleep(2);
@@ -565,7 +600,7 @@ static int FXS_card_dahdi_postregistration(xpd_t *xpd, bool on)
  */
 static void __do_mute_dtmf(xpd_t *xpd, int pos, bool muteit)
 {
-       struct FXS_priv_data    *priv;
+       struct FXS_priv_data *priv;
 
        priv = xpd->priv;
        LINE_DBG(SIGNAL, xpd, pos, "%s\n", (muteit) ? "MUTE" : "UNMUTE");
@@ -578,10 +613,10 @@ static void __do_mute_dtmf(xpd_t *xpd, int pos, bool muteit)
 }
 
 static int set_vm_led_mode(xbus_t *xbus, xpd_t *xpd, int pos,
-               unsigned int msg_waiting)
+                          unsigned int msg_waiting)
 {
-       int     ret = 0;
-       struct FXS_priv_data    *priv;
+       int ret = 0;
+       struct FXS_priv_data *priv;
        BUG_ON(!xbus);
        BUG_ON(!xpd);
 
@@ -590,108 +625,141 @@ static int set_vm_led_mode(xbus_t *xbus, xpd_t *xpd, int pos,
                /* A write to register 0x40 will now turn on/off the VM led */
                LINE_DBG(SIGNAL, xpd, pos, "NEON\n");
                BIT_SET(priv->neon_blinking, pos);
-               ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x16, 0xE8, 0x03);
-               ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x15, 0xEF, 0x7B);
-               ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x14, 0x9F, 0x00);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x22, 0x19);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x30, 0xE0);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x31, 0x01);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x32, 0xF0);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x33, 0x05);
-               ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x1D, 0x00, 0x46);
+               ret +=
+                   SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x16,
+                                         0xE8, 0x03);
+               ret +=
+                   SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x15,
+                                         0xEF, 0x7B);
+               ret +=
+                   SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x14,
+                                         0x9F, 0x00);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x22, 0x19);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x30, 0xE0);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x31, 0x01);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x32, 0xF0);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x33, 0x05);
+               ret +=
+                   SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x1D,
+                                         0x00, 0x46);
        } else if (ring_trapez) {
                LINE_DBG(SIGNAL, xpd, pos, "RINGER: Trapez ring\n");
-               ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos,
-                               SLIC_WRITE, 0x16, 0xC8, 0x00);
-               ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos,
-                               SLIC_WRITE, 0x15, 0xAB, 0x5E);
-               ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos,
-                               SLIC_WRITE, 0x14, 0x8C, 0x01);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos,
-                               SLIC_WRITE, 0x22, 0x01);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos,
-                               SLIC_WRITE, 0x4A, 0x34);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos,
-                               SLIC_WRITE, 0x30, 0x00);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos,
-                               SLIC_WRITE, 0x31, 0x00);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos,
-                               SLIC_WRITE, 0x32, 0x00);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos,
-                               SLIC_WRITE, 0x33, 0x00);
-               ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos,
-                               SLIC_WRITE, 0x1D, 0x00, 0x36);
+               ret +=
+                   SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x16,
+                                         0xC8, 0x00);
+               ret +=
+                   SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x15,
+                                         0xAB, 0x5E);
+               ret +=
+                   SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x14,
+                                         0x8C, 0x01);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x22, 0x01);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x4A, 0x34);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x30, 0x00);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x31, 0x00);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x32, 0x00);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x33, 0x00);
+               ret +=
+                   SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x1D,
+                                         0x00, 0x36);
        } else {
                /* A write to register 0x40 will now turn on/off the ringer */
                LINE_DBG(SIGNAL, xpd, pos, "RINGER\n");
                BIT_CLR(priv->neon_blinking, pos);
 
-               ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x16, 0x00, 0x00);
-               ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x15, 0x77, 0x01);
-               ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x14, 0xFD, 0x7E);
-
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x22, 0x00);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x30, 0x00);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x31, 0x00);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x32, 0x00);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x33, 0x00);
-               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE,
-                               0x4A, 0x34);/* High Vbat~ -82V[Dc] */
-               ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x1D, 0x00, 0x36);
+               ret +=
+                   SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x16,
+                                         0x00, 0x00);
+               ret +=
+                   SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x15,
+                                         0x77, 0x01);
+               ret +=
+                   SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x14,
+                                         0xFD, 0x7E);
+
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x22, 0x00);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x30, 0x00);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x31, 0x00);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x32, 0x00);
+               ret +=
+                   SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x33, 0x00);
+               ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x4A, 0x34);     /* High Vbat~ -82V[Dc] */
+               ret +=
+                   SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x1D,
+                                         0x00, 0x36);
        }
        return (ret ? -EPROTO : 0);
 }
 
 static void start_stop_vm_led(xbus_t *xbus, xpd_t *xpd, lineno_t pos)
 {
-       struct FXS_priv_data    *priv;
-       unsigned int            msgs;
+       struct FXS_priv_data *priv;
+       unsigned int msgs;
 
        BUG_ON(!xpd);
-       if (IS_SET(PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).digital_inputs, pos))
+       if (IS_SET
+           (PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).digital_inputs, pos))
                return;
        priv = xpd->priv;
        msgs = PHONEDEV(xpd).msg_waiting[pos];
        LINE_DBG(SIGNAL, xpd, pos, "%s\n", (msgs) ? "ON" : "OFF");
        set_vm_led_mode(xbus, xpd, pos, msgs);
        do_chan_power(xbus, xpd, pos, msgs > 0);
-       linefeed_control(xbus, xpd, pos, (msgs > 0) ?
-                       FXS_LINE_RING : priv->idletxhookstate[pos]);
+       linefeed_control(xbus, xpd, pos,
+                        (msgs >
+                         0) ? FXS_LINE_RING : priv->idletxhookstate[pos]);
 }
 
 static int relay_out(xpd_t *xpd, int pos, bool on)
 {
-       int             value;
-       int             which = pos;
-       int             relay_channels[] = { 0, 4 };
+       int value;
+       int which = pos;
+       int relay_channels[] = { 0, 4 };
 
        BUG_ON(!xpd);
        /* map logical position to output port number (0/1) */
        which -= (xpd->subtype == 2) ? 6 : 8;
-       LINE_DBG(SIGNAL, xpd, pos, "which=%d -- %s\n", which, (on) ? "on" : "off");
+       LINE_DBG(SIGNAL, xpd, pos, "which=%d -- %s\n", which,
+                (on) ? "on" : "off");
        which = which % ARRAY_SIZE(relay_channels);
        value = BIT(2) | BIT(3);
-       value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[OUTPUT_RELAY]);
+       value |=
+           ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[OUTPUT_RELAY]);
        if (on)
                value |= led_register_vals[OUTPUT_RELAY];
        return SLIC_DIRECT_REQUEST(xpd->xbus, xpd, relay_channels[which],
-                       SLIC_WRITE, REG_DIGITAL_IOCTRL, value);
+                                  SLIC_WRITE, REG_DIGITAL_IOCTRL, value);
 }
 
 static int send_ring(xpd_t *xpd, lineno_t chan, bool on)
 {
-       int                     ret = 0;
-       xbus_t                  *xbus;
-       struct FXS_priv_data    *priv;
-       enum fxs_state          value = (on) ? FXS_LINE_RING : FXS_LINE_POL_ACTIVE;
+       int ret = 0;
+       xbus_t *xbus;
+       struct FXS_priv_data *priv;
+       enum fxs_state value = (on) ? FXS_LINE_RING : FXS_LINE_POL_ACTIVE;
 
        BUG_ON(!xpd);
        xbus = xpd->xbus;
        BUG_ON(!xbus);
-       LINE_DBG(SIGNAL, xpd, chan, "%s\n", (on)?"on":"off");
+       LINE_DBG(SIGNAL, xpd, chan, "%s\n", (on) ? "on" : "off");
        priv = xpd->priv;
        set_vm_led_mode(xbus, xpd, chan, 0);
-       do_chan_power(xbus, xpd, chan, on);             // Power up (for ring)
+       do_chan_power(xbus, xpd, chan, on);     // Power up (for ring)
        ret = linefeed_control(xbus, xpd, chan, value);
        if (on) {
                MARK_BLINK(priv, chan, LED_GREEN, LED_BLINK_RING);
@@ -704,148 +772,155 @@ static int send_ring(xpd_t *xpd, lineno_t chan, bool on)
 
 static int FXS_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig)
 {
-       struct FXS_priv_data    *priv;
-       int                     ret = 0;
-       struct dahdi_chan               *chan = NULL;
-       enum fxs_state          txhook;
-       unsigned long           flags;
+       struct FXS_priv_data *priv;
+       int ret = 0;
+       struct dahdi_chan *chan = NULL;
+       enum fxs_state txhook;
+       unsigned long flags;
 
        LINE_DBG(SIGNAL, xpd, pos, "%s\n", txsig2str(txsig));
        priv = xpd->priv;
        BUG_ON(PHONEDEV(xpd).direction != TO_PHONE);
        if (IS_SET(PHONEDEV(xpd).digital_inputs, pos)) {
-               LINE_DBG(SIGNAL, xpd, pos, "Ignoring signal sent to digital input line\n");
+               LINE_DBG(SIGNAL, xpd, pos,
+                        "Ignoring signal sent to digital input line\n");
                return 0;
        }
        if (SPAN_REGISTERED(xpd))
                chan = XPD_CHAN(xpd, pos);
        switch (txsig) {
-               case DAHDI_TXSIG_ONHOOK:
-                       spin_lock_irqsave(&xpd->lock, flags);
-                       PHONEDEV(xpd).ringing[pos] = 0;
-                       oht_pcm(xpd, pos, 0);
-                       vmwi_search(xpd, pos, 0);
-                       BIT_CLR(priv->want_dtmf_events, pos);
-                       BIT_CLR(priv->want_dtmf_mute, pos);
-                       __do_mute_dtmf(xpd, pos, 0);
-                       spin_unlock_irqrestore(&xpd->lock, flags);
-                       if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) {
-                               LINE_DBG(SIGNAL, xpd, pos, "%s -> digital output OFF\n", txsig2str(txsig));
-                               ret = relay_out(xpd, pos, 0);
-                               return ret;
-                       }
-                       if (priv->lasttxhook[pos] == FXS_LINE_OPEN) {
-                               /*
-                                * Restore state after KEWL hangup.
-                                */
-                               LINE_DBG(SIGNAL, xpd, pos, "KEWL STOP\n");
-                               linefeed_control(xpd->xbus, xpd, pos, FXS_LINE_POL_ACTIVE);
-                               if (IS_OFFHOOK(xpd, pos))
-                                       MARK_ON(priv, pos, LED_GREEN);
-                       }
-                       ret = send_ring(xpd, pos, 0);                   // RING off
-                       if (!IS_OFFHOOK(xpd, pos))
-                               start_stop_vm_led(xpd->xbus, xpd, pos);
-                       txhook = priv->lasttxhook[pos];
-                       if (chan) {
-                               switch (chan->sig) {
-                                       case DAHDI_SIG_EM:
-                                       case DAHDI_SIG_FXOKS:
-                                       case DAHDI_SIG_FXOLS:
-                                               txhook = priv->idletxhookstate[pos];
-                                               break;
-                                       case DAHDI_SIG_FXOGS:
-                                               txhook = FXS_LINE_TIPOPEN;
-                                               break;
-                               }
-                       }
-                       ret = linefeed_control(xpd->xbus, xpd, pos, txhook);
-                       break;
-               case DAHDI_TXSIG_OFFHOOK:
-                       if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) {
-                               LINE_NOTICE(xpd, pos, "%s -> Is digital output. Ignored\n", txsig2str(txsig));
-                               return -EINVAL;
-                       }
-                       txhook = priv->lasttxhook[pos];
-                       if (PHONEDEV(xpd).ringing[pos]) {
-                               oht_pcm(xpd, pos, 1);
-                               txhook = FXS_LINE_OHTRANS;
-                       }
-                       PHONEDEV(xpd).ringing[pos] = 0;
-                       if (chan) {
-                               switch (chan->sig) {
-                                       case DAHDI_SIG_EM:
-                                               txhook = FXS_LINE_POL_ACTIVE;
-                                               break;
-                                       default:
-                                               txhook = priv->idletxhookstate[pos];
-                                               break;
-                               }
-                       }
-                       ret = linefeed_control(xpd->xbus, xpd, pos, txhook);
-                       break;
-               case DAHDI_TXSIG_START:
-                       PHONEDEV(xpd).ringing[pos] = 1;
-                       oht_pcm(xpd, pos, 0);
-                       vmwi_search(xpd, pos, 0);
-                       if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) {
-                               LINE_DBG(SIGNAL, xpd, pos, "%s -> digital output ON\n", txsig2str(txsig));
-                               ret = relay_out(xpd, pos, 1);
-                               return ret;
+       case DAHDI_TXSIG_ONHOOK:
+               spin_lock_irqsave(&xpd->lock, flags);
+               PHONEDEV(xpd).ringing[pos] = 0;
+               oht_pcm(xpd, pos, 0);
+               vmwi_search(xpd, pos, 0);
+               BIT_CLR(priv->want_dtmf_events, pos);
+               BIT_CLR(priv->want_dtmf_mute, pos);
+               __do_mute_dtmf(xpd, pos, 0);
+               spin_unlock_irqrestore(&xpd->lock, flags);
+               if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) {
+                       LINE_DBG(SIGNAL, xpd, pos, "%s -> digital output OFF\n",
+                                txsig2str(txsig));
+                       ret = relay_out(xpd, pos, 0);
+                       return ret;
+               }
+               if (priv->lasttxhook[pos] == FXS_LINE_OPEN) {
+                       /*
+                        * Restore state after KEWL hangup.
+                        */
+                       LINE_DBG(SIGNAL, xpd, pos, "KEWL STOP\n");
+                       linefeed_control(xpd->xbus, xpd, pos,
+                                        FXS_LINE_POL_ACTIVE);
+                       if (IS_OFFHOOK(xpd, pos))
+                               MARK_ON(priv, pos, LED_GREEN);
+               }
+               ret = send_ring(xpd, pos, 0);   // RING off
+               if (!IS_OFFHOOK(xpd, pos))
+                       start_stop_vm_led(xpd->xbus, xpd, pos);
+               txhook = priv->lasttxhook[pos];
+               if (chan) {
+                       switch (chan->sig) {
+                       case DAHDI_SIG_EM:
+                       case DAHDI_SIG_FXOKS:
+                       case DAHDI_SIG_FXOLS:
+                               txhook = priv->idletxhookstate[pos];
+                               break;
+                       case DAHDI_SIG_FXOGS:
+                               txhook = FXS_LINE_TIPOPEN;
+                               break;
                        }
-                       ret = send_ring(xpd, pos, 1);                   // RING on
-                       break;
-               case DAHDI_TXSIG_KEWL:
-                       if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) {
-                               LINE_DBG(SIGNAL, xpd, pos, "%s -> Is digital output. Ignored\n", txsig2str(txsig));
-                               return -EINVAL;
+               }
+               ret = linefeed_control(xpd->xbus, xpd, pos, txhook);
+               break;
+       case DAHDI_TXSIG_OFFHOOK:
+               if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) {
+                       LINE_NOTICE(xpd, pos,
+                                   "%s -> Is digital output. Ignored\n",
+                                   txsig2str(txsig));
+                       return -EINVAL;
+               }
+               txhook = priv->lasttxhook[pos];
+               if (PHONEDEV(xpd).ringing[pos]) {
+                       oht_pcm(xpd, pos, 1);
+                       txhook = FXS_LINE_OHTRANS;
+               }
+               PHONEDEV(xpd).ringing[pos] = 0;
+               if (chan) {
+                       switch (chan->sig) {
+                       case DAHDI_SIG_EM:
+                               txhook = FXS_LINE_POL_ACTIVE;
+                               break;
+                       default:
+                               txhook = priv->idletxhookstate[pos];
+                               break;
                        }
-                       linefeed_control(xpd->xbus, xpd, pos, FXS_LINE_OPEN);
-                       MARK_OFF(priv, pos, LED_GREEN);
-                       break;
-               default:
-                       XPD_NOTICE(xpd, "%s: Can't set tx state to %s (%d)\n",
-                               __func__, txsig2str(txsig), txsig);
-                       ret = -EINVAL;
+               }
+               ret = linefeed_control(xpd->xbus, xpd, pos, txhook);
+               break;
+       case DAHDI_TXSIG_START:
+               PHONEDEV(xpd).ringing[pos] = 1;
+               oht_pcm(xpd, pos, 0);
+               vmwi_search(xpd, pos, 0);
+               if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) {
+                       LINE_DBG(SIGNAL, xpd, pos, "%s -> digital output ON\n",
+                                txsig2str(txsig));
+                       ret = relay_out(xpd, pos, 1);
+                       return ret;
+               }
+               ret = send_ring(xpd, pos, 1);   // RING on
+               break;
+       case DAHDI_TXSIG_KEWL:
+               if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) {
+                       LINE_DBG(SIGNAL, xpd, pos,
+                                "%s -> Is digital output. Ignored\n",
+                                txsig2str(txsig));
+                       return -EINVAL;
+               }
+               linefeed_control(xpd->xbus, xpd, pos, FXS_LINE_OPEN);
+               MARK_OFF(priv, pos, LED_GREEN);
+               break;
+       default:
+               XPD_NOTICE(xpd, "%s: Can't set tx state to %s (%d)\n", __func__,
+                          txsig2str(txsig), txsig);
+               ret = -EINVAL;
        }
        return ret;
 }
 
 static int set_vmwi(xpd_t *xpd, int pos, unsigned long arg)
 {
-       struct FXS_priv_data    *priv;
-       struct dahdi_vmwi_info  vmwisetting;
-       const int vmwi_flags = DAHDI_VMWI_LREV | DAHDI_VMWI_HVDC
-               | DAHDI_VMWI_HVAC;
+       struct FXS_priv_data *priv;
+       struct dahdi_vmwi_info vmwisetting;
+       const int vmwi_flags =
+           DAHDI_VMWI_LREV | DAHDI_VMWI_HVDC | DAHDI_VMWI_HVAC;
 
        priv = xpd->priv;
        BUG_ON(!priv);
-       if (copy_from_user(&vmwisetting, (__user void *)arg,
-                               sizeof(vmwisetting)))
+       if (copy_from_user
+           (&vmwisetting, (__user void *)arg, sizeof(vmwisetting)))
                return -EFAULT;
        if ((vmwisetting.vmwi_type & ~vmwi_flags) != 0) {
                LINE_NOTICE(xpd, pos, "Bad DAHDI_VMWI_CONFIG: 0x%X\n",
-                       vmwisetting.vmwi_type);
+                           vmwisetting.vmwi_type);
                return -EINVAL;
        }
-       LINE_DBG(SIGNAL, xpd, pos,
-                       "DAHDI_VMWI_CONFIG: 0x%X\n",
-                       vmwisetting.vmwi_type);
+       LINE_DBG(SIGNAL, xpd, pos, "DAHDI_VMWI_CONFIG: 0x%X\n",
+                vmwisetting.vmwi_type);
        if (VMWI_TYPE(priv, pos, LREV)) {
                LINE_NOTICE(xpd, pos,
-                       "%s: VMWI(lrev) is not implemented yet. Ignored.\n",
-                       __func__);
+                           "%s: VMWI(lrev) is not implemented yet. Ignored.\n",
+                           __func__);
        }
        if (VMWI_TYPE(priv, pos, HVDC)) {
                LINE_NOTICE(xpd, pos,
-                       "%s: VMWI(hvdc) is not implemented yet. Ignored.\n",
-                       __func__);
+                           "%s: VMWI(hvdc) is not implemented yet. Ignored.\n",
+                           __func__);
        }
        if (VMWI_TYPE(priv, pos, HVAC)) {
-               ;       /* VMWI_NEON */
+               ;               /* VMWI_NEON */
        }
        if (priv->vmwisetting[pos].vmwi_type == 0) {
-               ;       /* Disable VMWI */
+               ;               /* Disable VMWI */
        }
        priv->vmwisetting[pos] = vmwisetting;
        set_vm_led_mode(xpd->xbus, xpd, pos, PHONEDEV(xpd).msg_waiting[pos]);
@@ -856,12 +931,13 @@ static int set_vmwi(xpd_t *xpd, int pos, unsigned long arg)
  * Private ioctl()
  * We don't need it now, since we detect vmwi via FSK patterns
  */
-static int FXS_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long arg)
+static int FXS_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd,
+                         unsigned long arg)
 {
-       struct FXS_priv_data    *priv;
-       xbus_t                  *xbus;
-       int                     val;
-       unsigned long           flags;
+       struct FXS_priv_data *priv;
+       xbus_t *xbus;
+       int val;
+       unsigned long flags;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -871,142 +947,156 @@ static int FXS_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long a
        if (!XBUS_IS(xbus, READY))
                return -ENODEV;
        if (pos < 0 || pos >= PHONEDEV(xpd).channels) {
-               XPD_NOTICE(xpd, "Bad channel number %d in %s(), cmd=%u\n",
-                       pos, __func__, cmd);
+               XPD_NOTICE(xpd, "Bad channel number %d in %s(), cmd=%u\n", pos,
+                          __func__, cmd);
                return -EINVAL;
        }
 
        switch (cmd) {
-               case DAHDI_ONHOOKTRANSFER:
-                       if (get_user(val, (int __user *)arg))
-                               return -EFAULT;
-                       LINE_DBG(SIGNAL, xpd, pos, "DAHDI_ONHOOKTRANSFER (%d millis)\n", val);
-                       if (IS_SET(PHONEDEV(xpd).digital_inputs | PHONEDEV(xpd).digital_outputs, pos))
-                               return 0;       /* Nothing to do */
-                       oht_pcm(xpd, pos, 1);   /* Get ready of VMWI FSK tones */
-                       if (priv->lasttxhook[pos] == FXS_LINE_POL_ACTIVE ||
-                                       IS_SET(priv->neon_blinking, pos)) {
-                               priv->ohttimer[pos] = val;
-                               priv->idletxhookstate[pos] = FXS_LINE_POL_OHTRANS;
-                               vmwi_search(xpd, pos, 1);
-                               CALL_PHONE_METHOD(card_pcm_recompute, xpd, priv->search_fsk_pattern);
-                               LINE_DBG(SIGNAL, xpd, pos, "Start OHT_TIMER. wanted_pcm_mask=0x%X\n", PHONEDEV(xpd).wanted_pcm_mask);
-                       }
-                       if (VMWI_NEON(priv, pos) && !IS_OFFHOOK(xpd, pos))
-                               start_stop_vm_led(xbus, xpd, pos);
-                       return 0;
-               case DAHDI_TONEDETECT:
-                       if (get_user(val, (int __user *)arg))
-                               return -EFAULT;
-                       LINE_DBG(SIGNAL, xpd, pos, "DAHDI_TONEDETECT: %s %s (dtmf_detection=%s)\n",
-                                       (val & DAHDI_TONEDETECT_ON) ? "ON" : "OFF",
-                                       (val & DAHDI_TONEDETECT_MUTE) ? "MUTE" : "NO-MUTE",
-                                       (dtmf_detection ? "YES" : "NO"));
-                       if (!dtmf_detection) {
-                               spin_lock_irqsave(&xpd->lock, flags);
-                               if (IS_SET(priv->want_dtmf_events, pos)) {
-                                       /* Detection mode changed: Disable DTMF interrupts */
-                                       SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x17, 0);
-                               }
-                               BIT_CLR(priv->want_dtmf_events, pos);
-                               BIT_CLR(priv->want_dtmf_mute, pos);
-                               __do_mute_dtmf(xpd, pos, 0);
-                               spin_unlock_irqrestore(&xpd->lock, flags);
-                               return -ENOTTY;
-                       }
-                       /*
-                        * During natively bridged calls, Asterisk
-                        * will request one of the sides to stop sending
-                        * dtmf events. Check the requested state.
-                        */
+       case DAHDI_ONHOOKTRANSFER:
+               if (get_user(val, (int __user *)arg))
+                       return -EFAULT;
+               LINE_DBG(SIGNAL, xpd, pos, "DAHDI_ONHOOKTRANSFER (%d millis)\n",
+                        val);
+               if (IS_SET
+                   (PHONEDEV(xpd).digital_inputs | PHONEDEV(xpd).
+                    digital_outputs, pos))
+                       return 0;       /* Nothing to do */
+               oht_pcm(xpd, pos, 1);   /* Get ready of VMWI FSK tones */
+               if (priv->lasttxhook[pos] == FXS_LINE_POL_ACTIVE
+                   || IS_SET(priv->neon_blinking, pos)) {
+                       priv->ohttimer[pos] = val;
+                       priv->idletxhookstate[pos] = FXS_LINE_POL_OHTRANS;
+                       vmwi_search(xpd, pos, 1);
+                       CALL_PHONE_METHOD(card_pcm_recompute, xpd,
+                                         priv->search_fsk_pattern);
+                       LINE_DBG(SIGNAL, xpd, pos,
+                                "Start OHT_TIMER. wanted_pcm_mask=0x%X\n",
+                                PHONEDEV(xpd).wanted_pcm_mask);
+               }
+               if (VMWI_NEON(priv, pos) && !IS_OFFHOOK(xpd, pos))
+                       start_stop_vm_led(xbus, xpd, pos);
+               return 0;
+       case DAHDI_TONEDETECT:
+               if (get_user(val, (int __user *)arg))
+                       return -EFAULT;
+               LINE_DBG(SIGNAL, xpd, pos,
+                        "DAHDI_TONEDETECT: %s %s (dtmf_detection=%s)\n",
+                        (val & DAHDI_TONEDETECT_ON) ? "ON" : "OFF",
+                        (val & DAHDI_TONEDETECT_MUTE) ? "MUTE" : "NO-MUTE",
+                        (dtmf_detection ? "YES" : "NO"));
+               if (!dtmf_detection) {
                        spin_lock_irqsave(&xpd->lock, flags);
-                       if (val & DAHDI_TONEDETECT_ON) {
-                               if (!IS_SET(priv->want_dtmf_events, pos)) {
-                                       /* Detection mode changed: Enable DTMF interrupts */
-                                       LINE_DBG(SIGNAL, xpd, pos,
-                                               "DAHDI_TONEDETECT: Enable Hardware DTMF\n");
-                                       SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x17, 1);
-                               }
-                               BIT_SET(priv->want_dtmf_events, pos);
-                       } else {
-                               if (IS_SET(priv->want_dtmf_events, pos)) {
-                                       /* Detection mode changed: Disable DTMF interrupts */
-                                       LINE_DBG(SIGNAL, xpd, pos,
-                                               "DAHDI_TONEDETECT: Disable Hardware DTMF\n");
-                                       SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x17, 0);
-                               }
-                               BIT_CLR(priv->want_dtmf_events, pos);
-                       }
-                       if (val & DAHDI_TONEDETECT_MUTE) {
-                               BIT_SET(priv->want_dtmf_mute, pos);
-                       } else {
-                               BIT_CLR(priv->want_dtmf_mute, pos);
-                               __do_mute_dtmf(xpd, pos, 0);
+                       if (IS_SET(priv->want_dtmf_events, pos)) {
+                               /* Detection mode changed: Disable DTMF interrupts */
+                               SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE,
+                                                   0x17, 0);
                        }
+                       BIT_CLR(priv->want_dtmf_events, pos);
+                       BIT_CLR(priv->want_dtmf_mute, pos);
+                       __do_mute_dtmf(xpd, pos, 0);
                        spin_unlock_irqrestore(&xpd->lock, flags);
-                       return 0;
-               case DAHDI_SETPOLARITY:
-                       if (get_user(val, (int __user *)arg))
-                               return -EFAULT;
-                       /*
-                        * Asterisk may send us this if chan_dahdi config
-                        * has "hanguponpolarityswitch=yes" to notify
-                        * that the other side has hanged up.
-                        *
-                        * This has no effect on normal phone (but we may
-                        * be connected to another FXO equipment).
-                        * note that this chan_dahdi settings has different
-                        * meaning for FXO, where it signals polarity
-                        * reversal *detection* logic.
-                        *
-                        * It seems that sometimes we get this from
-                        * asterisk in wrong state (e.g: while ringing).
-                        * In these cases, silently ignore it.
-                        */
-                       if (priv->lasttxhook[pos] == FXS_LINE_RING || priv->lasttxhook[pos] == FXS_LINE_OPEN) {
+                       return -ENOTTY;
+               }
+               /*
+                * During natively bridged calls, Asterisk
+                * will request one of the sides to stop sending
+                * dtmf events. Check the requested state.
+                */
+               spin_lock_irqsave(&xpd->lock, flags);
+               if (val & DAHDI_TONEDETECT_ON) {
+                       if (!IS_SET(priv->want_dtmf_events, pos)) {
+                               /* Detection mode changed: Enable DTMF interrupts */
                                LINE_DBG(SIGNAL, xpd, pos,
-                                       "DAHDI_SETPOLARITY: %s Cannot change when lasttxhook=0x%X\n",
-                                       (val)?"ON":"OFF", priv->lasttxhook[pos]);
-                               return -EINVAL;
+                                        "DAHDI_TONEDETECT: Enable Hardware DTMF\n");
+                               SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE,
+                                                   0x17, 1);
                        }
-                       LINE_DBG(SIGNAL, xpd, pos, "DAHDI_SETPOLARITY: %s\n", (val)?"ON":"OFF");
-                       if ((val && !reversepolarity) || (!val && reversepolarity))
-                               priv->lasttxhook[pos] |= FXS_LINE_RING;
-                       else
-                               priv->lasttxhook[pos] &= ~FXS_LINE_RING;
-                       linefeed_control(xbus, xpd, pos, priv->lasttxhook[pos]);
-                       return 0;
-               case DAHDI_VMWI_CONFIG:
-                       if (set_vmwi(xpd, pos, arg) < 0)
-                               return -EINVAL;
-                       return 0;
-               case DAHDI_VMWI:                /* message-waiting led control */
-                       if (get_user(val, (int __user *)arg))
-                               return -EFAULT;
-                       if (!vmwi_ioctl) {
-                               static bool     notified;
-
-                               if (!notified++)
-                                       LINE_NOTICE(xpd, pos,
-                                               "Got DAHDI_VMWI notification but vmwi_ioctl parameter is off. Ignoring.\n");
-                               return 0;
+                       BIT_SET(priv->want_dtmf_events, pos);
+               } else {
+                       if (IS_SET(priv->want_dtmf_events, pos)) {
+                               /* Detection mode changed: Disable DTMF interrupts */
+                               LINE_DBG(SIGNAL, xpd, pos,
+                                        "DAHDI_TONEDETECT: Disable Hardware DTMF\n");
+                               SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE,
+                                                   0x17, 0);
                        }
-                       /* Digital inputs/outputs don't have VM leds */
-                       if (IS_SET(PHONEDEV(xpd).digital_inputs | PHONEDEV(xpd).digital_outputs, pos))
-                               return 0;
-                       PHONEDEV(xpd).msg_waiting[pos] = val;
-                       LINE_DBG(SIGNAL, xpd, pos, "DAHDI_VMWI: %s\n",
-                                       (val) ? "yes" : "no");
+                       BIT_CLR(priv->want_dtmf_events, pos);
+               }
+               if (val & DAHDI_TONEDETECT_MUTE) {
+                       BIT_SET(priv->want_dtmf_mute, pos);
+               } else {
+                       BIT_CLR(priv->want_dtmf_mute, pos);
+                       __do_mute_dtmf(xpd, pos, 0);
+               }
+               spin_unlock_irqrestore(&xpd->lock, flags);
+               return 0;
+       case DAHDI_SETPOLARITY:
+               if (get_user(val, (int __user *)arg))
+                       return -EFAULT;
+               /*
+                * Asterisk may send us this if chan_dahdi config
+                * has "hanguponpolarityswitch=yes" to notify
+                * that the other side has hanged up.
+                *
+                * This has no effect on normal phone (but we may
+                * be connected to another FXO equipment).
+                * note that this chan_dahdi settings has different
+                * meaning for FXO, where it signals polarity
+                * reversal *detection* logic.
+                *
+                * It seems that sometimes we get this from
+                * asterisk in wrong state (e.g: while ringing).
+                * In these cases, silently ignore it.
+                */
+               if (priv->lasttxhook[pos] == FXS_LINE_RING
+                   || priv->lasttxhook[pos] == FXS_LINE_OPEN) {
+                       LINE_DBG(SIGNAL, xpd, pos,
+                                "DAHDI_SETPOLARITY: %s Cannot change when lasttxhook=0x%X\n",
+                                (val) ? "ON" : "OFF", priv->lasttxhook[pos]);
+                       return -EINVAL;
+               }
+               LINE_DBG(SIGNAL, xpd, pos, "DAHDI_SETPOLARITY: %s\n",
+                        (val) ? "ON" : "OFF");
+               if ((val && !reversepolarity) || (!val && reversepolarity))
+                       priv->lasttxhook[pos] |= FXS_LINE_RING;
+               else
+                       priv->lasttxhook[pos] &= ~FXS_LINE_RING;
+               linefeed_control(xbus, xpd, pos, priv->lasttxhook[pos]);
+               return 0;
+       case DAHDI_VMWI_CONFIG:
+               if (set_vmwi(xpd, pos, arg) < 0)
+                       return -EINVAL;
+               return 0;
+       case DAHDI_VMWI:        /* message-waiting led control */
+               if (get_user(val, (int __user *)arg))
+                       return -EFAULT;
+               if (!vmwi_ioctl) {
+                       static bool notified;
+
+                       if (!notified++)
+                               LINE_NOTICE(xpd, pos,
+                                           "Got DAHDI_VMWI notification but vmwi_ioctl parameter is off. Ignoring.\n");
                        return 0;
-               default:
-                       report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd);
+               }
+               /* Digital inputs/outputs don't have VM leds */
+               if (IS_SET
+                   (PHONEDEV(xpd).digital_inputs | PHONEDEV(xpd).
+                    digital_outputs, pos))
+                       return 0;
+               PHONEDEV(xpd).msg_waiting[pos] = val;
+               LINE_DBG(SIGNAL, xpd, pos, "DAHDI_VMWI: %s\n",
+                        (val) ? "yes" : "no");
+               return 0;
+       default:
+               report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd);
        }
        return -ENOTTY;
 }
 
 static int FXS_card_open(xpd_t *xpd, lineno_t chan)
 {
-       struct FXS_priv_data    *priv;
+       struct FXS_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -1026,7 +1116,7 @@ static int FXS_card_open(xpd_t *xpd, lineno_t chan)
 
 static int FXS_card_close(xpd_t *xpd, lineno_t chan)
 {
-       struct FXS_priv_data    *priv;
+       struct FXS_priv_data *priv;
 
        BUG_ON(!xpd);
        LINE_DBG(GENERAL, xpd, chan, "\n");
@@ -1044,15 +1134,15 @@ static int FXS_card_close(xpd_t *xpd, lineno_t chan)
  *     +-----+-----+-----+-----+-----+-----+-----+-----+
  *
  */
-static int     input_channels[] = { 6, 7, 2, 3 };      // Slic numbers of input relays
+static int input_channels[] = { 6, 7, 2, 3 };  // Slic numbers of input relays
 
 static void poll_inputs(xpd_t *xpd)
 {
-       int     i;
+       int i;
 
        BUG_ON(xpd->xbus_idx != 0);     // Only unit #0 has digital inputs
        for (i = 0; i < ARRAY_SIZE(input_channels); i++) {
-               __u8    pos = input_channels[i];
+               __u8 pos = input_channels[i];
 
                SLIC_DIRECT_REQUEST(xpd->xbus, xpd, pos, SLIC_READ, 0x06, 0);
        }
@@ -1061,15 +1151,15 @@ static void poll_inputs(xpd_t *xpd)
 
 static void handle_linefeed(xpd_t *xpd)
 {
-       struct FXS_priv_data    *priv;
-       int                     i;
+       struct FXS_priv_data *priv;
+       int i;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
        BUG_ON(!priv);
        for_each_line(xpd, i) {
-               if (priv->lasttxhook[i] == FXS_LINE_RING &&
-                               !IS_SET(priv->neon_blinking, i)) {
+               if (priv->lasttxhook[i] == FXS_LINE_RING
+                   && !IS_SET(priv->neon_blinking, i)) {
                        /* RINGing, prepare for OHT */
                        priv->ohttimer[i] = OHT_TIMER;
                        priv->idletxhookstate[i] = FXS_LINE_POL_OHTRANS;
@@ -1077,13 +1167,18 @@ static void handle_linefeed(xpd_t *xpd)
                        if (priv->ohttimer[i]) {
                                priv->ohttimer[i]--;
                                if (!priv->ohttimer[i]) {
-                                       LINE_DBG(SIGNAL, xpd, i, "ohttimer expired\n");
-                                       priv->idletxhookstate[i] = FXS_LINE_POL_ACTIVE;
+                                       LINE_DBG(SIGNAL, xpd, i,
+                                                "ohttimer expired\n");
+                                       priv->idletxhookstate[i] =
+                                           FXS_LINE_POL_ACTIVE;
                                        oht_pcm(xpd, i, 0);
                                        vmwi_search(xpd, i, 0);
-                                       if (priv->lasttxhook[i] == FXS_LINE_POL_OHTRANS) {
+                                       if (priv->lasttxhook[i] ==
+                                           FXS_LINE_POL_OHTRANS) {
                                                /* Apply the change if appropriate */
-                                               linefeed_control(xpd->xbus, xpd, i, FXS_LINE_POL_ACTIVE);
+                                               linefeed_control(xpd->xbus, xpd,
+                                                                i,
+                                                                FXS_LINE_POL_ACTIVE);
                                        }
                                }
                        }
@@ -1097,7 +1192,7 @@ static void handle_linefeed(xpd_t *xpd)
  */
 static inline bool mem_equal(const char a[], const char b[], size_t len)
 {
-       int     i;
+       int i;
 
        for (i = 0; i < len; i++)
                if (a[i] != b[i])
@@ -1110,33 +1205,35 @@ static inline bool mem_equal(const char a[], const char b[], size_t len)
  */
 static void detect_vmwi(xpd_t *xpd)
 {
-       struct FXS_priv_data    *priv;
-       xbus_t                  *xbus;
-       static const __u8       FSK_COMMON_PATTERN[] = { 0xA8, 0x49, 0x22, 0x3B, 0x9F, 0xFF, 0x1F, 0xBB };
-       static const __u8       FSK_ON_PATTERN[] = { 0xA2, 0x2C, 0x1F, 0x2C, 0xBB, 0xA1, 0xA5, 0xFF };
-       static const __u8       FSK_OFF_PATTERN[] = { 0xA2, 0x2C, 0x28, 0xA5, 0xB1, 0x21, 0x49, 0x9F };
-       int                     i;
-       xpp_line_t              ignore_mask;
+       struct FXS_priv_data *priv;
+       xbus_t *xbus;
+       static const __u8 FSK_COMMON_PATTERN[] =
+           { 0xA8, 0x49, 0x22, 0x3B, 0x9F, 0xFF, 0x1F, 0xBB };
+       static const __u8 FSK_ON_PATTERN[] =
+           { 0xA2, 0x2C, 0x1F, 0x2C, 0xBB, 0xA1, 0xA5, 0xFF };
+       static const __u8 FSK_OFF_PATTERN[] =
+           { 0xA2, 0x2C, 0x28, 0xA5, 0xB1, 0x21, 0x49, 0x9F };
+       int i;
+       xpp_line_t ignore_mask;
 
        BUG_ON(!xpd);
        xbus = xpd->xbus;
        priv = xpd->priv;
        BUG_ON(!priv);
        ignore_mask =
-               PHONEDEV(xpd).offhook_state |
-               ~(PHONEDEV(xpd).oht_pcm_pass) |
-               ~(priv->search_fsk_pattern) |
-               PHONEDEV(xpd).digital_inputs |
-               PHONEDEV(xpd).digital_outputs;
+           PHONEDEV(xpd).offhook_state | ~(PHONEDEV(xpd).
+                                           oht_pcm_pass) | ~(priv->
+                                                             search_fsk_pattern)
+           | PHONEDEV(xpd).digital_inputs | PHONEDEV(xpd).digital_outputs;
        for_each_line(xpd, i) {
-               struct dahdi_chan       *chan = XPD_CHAN(xpd, i);
-               __u8            *writechunk = chan->writechunk;
+               struct dahdi_chan *chan = XPD_CHAN(xpd, i);
+               __u8 *writechunk = chan->writechunk;
 
                if (IS_SET(ignore_mask, i))
                        continue;
 #if 0
                if (writechunk[0] != 0x7F && writechunk[0] != 0) {
-                       int     j;
+                       int j;
 
                        LINE_DBG(GENERAL, xpd, pos, "MSG:");
                        for (j = 0; j < DAHDI_CHUNKSIZE; j++) {
@@ -1147,22 +1244,31 @@ static void detect_vmwi(xpd_t *xpd)
                                printk("\n");
                }
 #endif
-               if (unlikely(mem_equal(writechunk, FSK_COMMON_PATTERN, DAHDI_CHUNKSIZE))) {
-                       LINE_DBG(SIGNAL, xpd, i, "Found common FSK pattern. Start looking for ON/OFF patterns.\n");
+               if (unlikely
+                   (mem_equal
+                    (writechunk, FSK_COMMON_PATTERN, DAHDI_CHUNKSIZE))) {
+                       LINE_DBG(SIGNAL, xpd, i,
+                                "Found common FSK pattern. Start looking for ON/OFF patterns.\n");
                        BIT_SET(priv->found_fsk_pattern, i);
                } else if (unlikely(IS_SET(priv->found_fsk_pattern, i))) {
                        BIT_CLR(priv->found_fsk_pattern, i);
                        oht_pcm(xpd, i, 0);
-                       if (unlikely(mem_equal(writechunk, FSK_ON_PATTERN, DAHDI_CHUNKSIZE))) {
+                       if (unlikely
+                           (mem_equal
+                            (writechunk, FSK_ON_PATTERN, DAHDI_CHUNKSIZE))) {
                                LINE_DBG(SIGNAL, xpd, i, "MSG WAITING ON\n");
                                PHONEDEV(xpd).msg_waiting[i] = 1;
                                start_stop_vm_led(xbus, xpd, i);
-                       } else if (unlikely(mem_equal(writechunk, FSK_OFF_PATTERN, DAHDI_CHUNKSIZE))) {
+                       } else
+                           if (unlikely
+                               (mem_equal
+                                (writechunk, FSK_OFF_PATTERN,
+                                 DAHDI_CHUNKSIZE))) {
                                LINE_DBG(SIGNAL, xpd, i, "MSG WAITING OFF\n");
                                PHONEDEV(xpd).msg_waiting[i] = 0;
                                start_stop_vm_led(xbus, xpd, i);
                        } else {
-                               int     j;
+                               int j;
 
                                LINE_NOTICE(xpd, i, "MSG WAITING Unexpected:");
                                for (j = 0; j < DAHDI_CHUNKSIZE; j++) {
@@ -1176,7 +1282,7 @@ static void detect_vmwi(xpd_t *xpd)
 
 static int FXS_card_tick(xbus_t *xbus, xpd_t *xpd)
 {
-       struct FXS_priv_data    *priv;
+       struct FXS_priv_data *priv;
 
        BUG_ON(!xpd);
        priv = xpd->priv;
@@ -1197,13 +1303,16 @@ static int FXS_card_tick(xbus_t *xbus, xpd_t *xpd)
         *   now we take care of notification to dahdi and Asterisk
         */
        if (priv->update_offhook_state) {
-               enum dahdi_rxsig        rxsig;
-               int             i;
+               enum dahdi_rxsig rxsig;
+               int i;
 
                for_each_line(xpd, i) {
                        if (!IS_SET(priv->update_offhook_state, i))
                                continue;
-                       rxsig = IS_OFFHOOK(xpd, i) ? DAHDI_RXSIG_OFFHOOK : DAHDI_RXSIG_ONHOOK;
+                       rxsig =
+                           IS_OFFHOOK(xpd,
+                                      i) ? DAHDI_RXSIG_OFFHOOK :
+                           DAHDI_RXSIG_ONHOOK;
                        notify_rxsig(xpd, i, rxsig);    /* Notify after open() */
                        BIT_CLR(priv->update_offhook_state, i);
                }
@@ -1222,22 +1331,25 @@ static int FXS_card_tick(xbus_t *xbus, xpd_t *xpd)
 /*
  * Should be called with spinlocked XPD
  */
-static void process_hookstate(xpd_t *xpd, xpp_line_t offhook, xpp_line_t change_mask)
+static void process_hookstate(xpd_t *xpd, xpp_line_t offhook,
+                             xpp_line_t change_mask)
 {
-       xbus_t                  *xbus;
-       struct FXS_priv_data    *priv;
-       int                     i;
+       xbus_t *xbus;
+       struct FXS_priv_data *priv;
+       int i;
 
        BUG_ON(!xpd);
        BUG_ON(PHONEDEV(xpd).direction != TO_PHONE);
        xbus = xpd->xbus;
        priv = xpd->priv;
-       XPD_DBG(SIGNAL, xpd, "offhook=0x%X change_mask=0x%X\n", offhook, change_mask);
+       XPD_DBG(SIGNAL, xpd, "offhook=0x%X change_mask=0x%X\n", offhook,
+               change_mask);
        for_each_line(xpd, i) {
-               if (IS_SET(PHONEDEV(xpd).digital_outputs, i) || IS_SET(PHONEDEV(xpd).digital_inputs, i))
+               if (IS_SET(PHONEDEV(xpd).digital_outputs, i)
+                   || IS_SET(PHONEDEV(xpd).digital_inputs, i))
                        continue;
                if (IS_SET(change_mask, i)) {
-                       PHONEDEV(xpd).ringing[i] = 0;           /* No more ringing... */
+                       PHONEDEV(xpd).ringing[i] = 0;   /* No more ringing... */
 #ifdef WITH_METERING
                        metering_gen(xpd, i, 0);        /* Stop metering... */
 #endif
@@ -1246,7 +1358,8 @@ static void process_hookstate(xpd_t *xpd, xpp_line_t offhook, xpp_line_t change_
                         * Reset our previous DTMF memories...
                         */
                        BIT_CLR(priv->prev_key_down, i);
-                       priv->prev_key_time[i].tv_sec = priv->prev_key_time[i].tv_usec = 0L;
+                       priv->prev_key_time[i].tv_sec =
+                           priv->prev_key_time[i].tv_usec = 0L;
                        if (IS_SET(offhook, i)) {
                                LINE_DBG(SIGNAL, xpd, i, "OFFHOOK\n");
                                MARK_ON(priv, i, LED_GREEN);
@@ -1267,18 +1380,20 @@ static void process_hookstate(xpd_t *xpd, xpp_line_t offhook, xpp_line_t change_
 
 HANDLER_DEF(FXS, SIG_CHANGED)
 {
-       xpp_line_t              sig_status = RPACKET_FIELD(pack, FXS, SIG_CHANGED, sig_status);
-       xpp_line_t              sig_toggles = RPACKET_FIELD(pack, FXS, SIG_CHANGED, sig_toggles);
-       unsigned long           flags;
+       xpp_line_t sig_status =
+           RPACKET_FIELD(pack, FXS, SIG_CHANGED, sig_status);
+       xpp_line_t sig_toggles =
+           RPACKET_FIELD(pack, FXS, SIG_CHANGED, sig_toggles);
+       unsigned long flags;
 
        BUG_ON(!xpd);
        BUG_ON(PHONEDEV(xpd).direction != TO_PHONE);
-       XPD_DBG(SIGNAL, xpd, "(PHONE) sig_toggles=0x%04X sig_status=0x%04X\n", sig_toggles, sig_status);
+       XPD_DBG(SIGNAL, xpd, "(PHONE) sig_toggles=0x%04X sig_status=0x%04X\n",
+               sig_toggles, sig_status);
 #if 0
-       Is this needed?
-       for_each_line(xpd, i) {
+       Is this needed ? for_each_line(xpd, i) {
                if (IS_SET(sig_toggles, i))
-                       do_chan_power(xpd->xbus, xpd, BIT(i), 0);               // Power down (prevent overheating!!!)
+                       do_chan_power(xpd->xbus, xpd, BIT(i), 0);       // Power down (prevent overheating!!!)
        }
 #endif
        spin_lock_irqsave(&xpd->lock, flags);
@@ -1290,28 +1405,27 @@ HANDLER_DEF(FXS, SIG_CHANGED)
 #ifdef POLL_DIGITAL_INPUTS
 static void process_digital_inputs(xpd_t *xpd, const reg_cmd_t *info)
 {
-       int             i;
-       bool            offhook = (REG_FIELD(info, data_low) & 0x1) == 0;
-       xpp_line_t      lines = BIT(info->portnum);
+       int i;
+       bool offhook = (REG_FIELD(info, data_low) & 0x1) == 0;
+       xpp_line_t lines = BIT(info->portnum);
 
        /* Sanity check */
        if (!PHONEDEV(xpd).digital_inputs) {
-               XPD_NOTICE(xpd,
-                       "%s called without digital inputs. Ignored\n",
-                       __func__);
+               XPD_NOTICE(xpd, "%s called without digital inputs. Ignored\n",
+                          __func__);
                return;
        }
        /* Map SLIC number into line number */
        for (i = 0; i < ARRAY_SIZE(input_channels); i++) {
-               int             channo = input_channels[i];
-               int             newchanno;
+               int channo = input_channels[i];
+               int newchanno;
 
                if (IS_SET(lines, channo)) {
                        newchanno = PHONEDEV(xpd).channels - LINES_DIGI_INP + i;
                        BIT_CLR(lines, channo);
                        BIT_SET(lines, newchanno);
-                       PHONEDEV(xpd).ringing[newchanno] = 0;                   // Stop ringing. No leds for digital inputs.
-                       if (offhook && !IS_OFFHOOK(xpd, newchanno)) {           // OFFHOOK
+                       PHONEDEV(xpd).ringing[newchanno] = 0;   // Stop ringing. No leds for digital inputs.
+                       if (offhook && !IS_OFFHOOK(xpd, newchanno)) {   // OFFHOOK
                                LINE_DBG(SIGNAL, xpd, newchanno, "OFFHOOK\n");
                                hookstate_changed(xpd, newchanno, 1);
                        } else if (!offhook && IS_OFFHOOK(xpd, newchanno)) {    // ONHOOK
@@ -1333,13 +1447,13 @@ static const char dtmf_digits[] = {
  */
 static void process_dtmf(xpd_t *xpd, uint portnum, __u8 val)
 {
-       __u8                    digit;
-       bool                    key_down = val & 0x10;
-       bool                    want_mute;
-       bool                    want_event;
-       struct FXS_priv_data    *priv;
-       struct timeval          now;
-       int                     msec = 0;
+       __u8 digit;
+       bool key_down = val & 0x10;
+       bool want_mute;
+       bool want_event;
+       struct FXS_priv_data *priv;
+       struct timeval now;
+       int msec = 0;
 
        if (!dtmf_detection)
                return;
@@ -1362,12 +1476,10 @@ static void process_dtmf(xpd_t *xpd, uint portnum, __u8 val)
                msec = usec_diff(&now, &priv->prev_key_time[portnum]) / 1000;
        priv->prev_key_time[portnum] = now;
        LINE_DBG(SIGNAL, xpd, portnum,
-                       "[%lu.%06lu] DTMF digit %-4s '%c' (val=%d, want_mute=%s want_event=%s, delta=%d msec)\n",
-                       now.tv_sec, now.tv_usec,
-                       (key_down)?"DOWN":"UP", digit, val,
-                       (want_mute) ? "yes" : "no",
-                       (want_event) ? "yes" : "no",
-                       msec);
+                "[%lu.%06lu] DTMF digit %-4s '%c' (val=%d, want_mute=%s want_event=%s, delta=%d msec)\n",
+                now.tv_sec, now.tv_usec, (key_down) ? "DOWN" : "UP", digit,
+                val, (want_mute) ? "yes" : "no", (want_event) ? "yes" : "no",
+                msec);
        /*
         * FIXME: we currently don't use the want_dtmf_mute until
         * we are sure about the logic in Asterisk native bridging.
@@ -1377,8 +1489,9 @@ static void process_dtmf(xpd_t *xpd, uint portnum, __u8 val)
                __do_mute_dtmf(xpd, portnum, 1);
        else
                __do_mute_dtmf(xpd, portnum, 0);
-       if (want_event)  {
-               int     event = (key_down) ? DAHDI_EVENT_DTMFDOWN : DAHDI_EVENT_DTMFUP;
+       if (want_event) {
+               int event =
+                   (key_down) ? DAHDI_EVENT_DTMFDOWN : DAHDI_EVENT_DTMFUP;
 
                dahdi_qevent_lock(XPD_CHAN(xpd, portnum), event | digit);
        }
@@ -1386,10 +1499,10 @@ static void process_dtmf(xpd_t *xpd, uint portnum, __u8 val)
 
 static int FXS_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
 {
-       unsigned long           flags;
-       struct FXS_priv_data    *priv;
-       __u8                    regnum;
-       bool                    indirect;
+       unsigned long flags;
+       struct FXS_priv_data *priv;
+       __u8 regnum;
+       bool indirect;
 
        spin_lock_irqsave(&xpd->lock, flags);
        priv = xpd->priv;
@@ -1397,10 +1510,10 @@ static int FXS_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
        indirect = (REG_FIELD(info, regnum) == 0x1E);
        regnum = (indirect) ? REG_FIELD(info, subreg) : REG_FIELD(info, regnum);
        XPD_DBG(REGS, xpd, "%s reg_num=0x%X, dataL=0x%X dataH=0x%X\n",
-                       (indirect)?"I":"D",
-                       regnum, REG_FIELD(info, data_low), REG_FIELD(info, data_high));
+               (indirect) ? "I" : "D", regnum, REG_FIELD(info, data_low),
+               REG_FIELD(info, data_high));
        if (!indirect && regnum == REG_DTMF_DECODE) {
-               __u8            val = REG_FIELD(info, data_low);
+               __u8 val = REG_FIELD(info, data_low);
 
                process_dtmf(xpd, info->portnum, val);
        }
@@ -1413,9 +1526,9 @@ static int FXS_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
        }
 #endif
        else if (!indirect && regnum == REG_LOOPCLOSURE) {      /* OFFHOOK ? */
-               __u8            val = REG_FIELD(info, data_low);
-               xpp_line_t      mask = BIT(info->portnum);
-               xpp_line_t      offhook;
+               __u8 val = REG_FIELD(info, data_low);
+               xpp_line_t mask = BIT(info->portnum);
+               xpp_line_t offhook;
 
                /*
                 * Validate reply. Non-existing/disabled ports
@@ -1424,22 +1537,25 @@ static int FXS_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
                if ((val & REG_LOOPCLOSURE_ZERO) == 0) {
                        offhook = (val & REG_LOOPCLOSURE_LCR) ? mask : 0;
                        LINE_DBG(SIGNAL, xpd, info->portnum,
-                               "REG_LOOPCLOSURE: dataL=0x%X (offhook=0x%X mask=0x%X\n",
-                               val, offhook, mask);
+                                "REG_LOOPCLOSURE: dataL=0x%X (offhook=0x%X mask=0x%X\n",
+                                val, offhook, mask);
                        process_hookstate(xpd, offhook, mask);
                }
        } else {
 #if 0
-               XPD_NOTICE(xpd, "Spurious register reply(ignored): %s reg_num=0x%X, dataL=0x%X dataH=0x%X\n",
-                               (indirect)?"I":"D",
-                               regnum, REG_FIELD(info, data_low), REG_FIELD(info, data_high));
+               XPD_NOTICE(xpd,
+                          "Spurious register reply(ignored): %s reg_num=0x%X, dataL=0x%X dataH=0x%X\n",
+                          (indirect) ? "I" : "D", regnum, REG_FIELD(info,
+                                                                    data_low),
+                          REG_FIELD(info, data_high));
 #endif
        }
        /* Update /proc info only if reply relate to the last slic read request */
-       if (
-                       REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) &&
-                       REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info, do_subreg) &&
-                       REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info, subreg)) {
+       if (REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum)
+           && REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info,
+                                                                       do_subreg)
+           && REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info,
+                                                                    subreg)) {
                xpd->last_reply = *info;
        }
        spin_unlock_irqrestore(&xpd->lock, flags);
@@ -1449,52 +1565,45 @@ static int FXS_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
 static int FXS_card_state(xpd_t *xpd, bool on)
 {
        BUG_ON(!xpd);
-       XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off");
+       XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off");
        return 0;
 }
 
-static const struct xops       fxs_xops = {
-       .card_new       = FXS_card_new,
-       .card_init      = FXS_card_init,
-       .card_remove    = FXS_card_remove,
-       .card_tick      = FXS_card_tick,
-       .card_register_reply    = FXS_card_register_reply,
+static const struct xops fxs_xops = {
+       .card_new = FXS_card_new,
+       .card_init = FXS_card_init,
+       .card_remove = FXS_card_remove,
+       .card_tick = FXS_card_tick,
+       .card_register_reply = FXS_card_register_reply,
 };
 
-static const struct phoneops   fxs_phoneops = {
-       .card_dahdi_preregistration     = FXS_card_dahdi_preregistration,
-       .card_dahdi_postregistration    = FXS_card_dahdi_postregistration,
-       .card_hooksig   = FXS_card_hooksig,
-       .card_pcm_recompute     = generic_card_pcm_recompute,
-       .card_pcm_fromspan      = generic_card_pcm_fromspan,
-       .card_pcm_tospan        = generic_card_pcm_tospan,
-       .card_timing_priority   = generic_timing_priority,
-       .echocancel_timeslot    = generic_echocancel_timeslot,
-       .echocancel_setmask     = generic_echocancel_setmask,
-       .card_open      = FXS_card_open,
-       .card_close     = FXS_card_close,
-       .card_ioctl     = FXS_card_ioctl,
-       .card_state     = FXS_card_state,
+static const struct phoneops fxs_phoneops = {
+       .card_dahdi_preregistration = FXS_card_dahdi_preregistration,
+       .card_dahdi_postregistration = FXS_card_dahdi_postregistration,
+       .card_hooksig = FXS_card_hooksig,
+       .card_pcm_recompute = generic_card_pcm_recompute,
+       .card_pcm_fromspan = generic_card_pcm_fromspan,
+       .card_pcm_tospan = generic_card_pcm_tospan,
+       .card_timing_priority = generic_timing_priority,
+       .echocancel_timeslot = generic_echocancel_timeslot,
+       .echocancel_setmask = generic_echocancel_setmask,
+       .card_open = FXS_card_open,
+       .card_close = FXS_card_close,
+       .card_ioctl = FXS_card_ioctl,
+       .card_state = FXS_card_state,
 };
 
 static xproto_table_t PROTO_TABLE(FXS) = {
-       .owner = THIS_MODULE,
-       .entries = {
-               /*      Prototable      Card    Opcode          */
-               XENTRY( FXS,            FXS,    SIG_CHANGED     ),
-       },
-       .name = "FXS",  /* protocol name */
-       .ports_per_subunit = 8,
-       .type = XPD_TYPE_FXS,
-       .xops = &fxs_xops,
-       .phoneops = &fxs_phoneops,
-       .packet_is_valid = fxs_packet_is_valid,
-       .packet_dump = fxs_packet_dump,
-};
+       .owner = THIS_MODULE,.entries = {
+               /*      Prototable      Card    Opcode          */
+       XENTRY(FXS, FXS, SIG_CHANGED),},.name = "FXS",  /* protocol name */
+.ports_per_subunit = 8,.type = XPD_TYPE_FXS,.xops =
+           &fxs_xops,.phoneops = &fxs_phoneops,.packet_is_valid =
+           fxs_packet_is_valid,.packet_dump = fxs_packet_dump,};
 
 static bool fxs_packet_is_valid(xpacket_t *pack)
 {
-       const xproto_entry_t    *xe;
+       const xproto_entry_t *xe;
 
        // DBG(GENERAL, "\n");
        xe = xproto_card_entry(&PROTO_TABLE(FXS), XPACKET_OP(pack));
@@ -1509,30 +1618,27 @@ static void fxs_packet_dump(const char *msg, xpacket_t *pack)
 /*------------------------- SLIC Handling --------------------------*/
 
 #ifdef CONFIG_PROC_FS
-static int proc_fxs_info_read(char *page, char **start, off_t off, int count, int *eof, void *data)
+static int proc_fxs_info_read(char *page, char **start, off_t off, int count,
+                             int *eof, void *data)
 {
-       int                     len = 0;
-       unsigned long           flags;
-       xpd_t                   *xpd = data;
-       struct FXS_priv_data    *priv;
-       int                     i;
-       int                     led;
+       int len = 0;
+       unsigned long flags;
+       xpd_t *xpd = data;
+       struct FXS_priv_data *priv;
+       int i;
+       int led;
 
        if (!xpd)
                return -ENODEV;
        spin_lock_irqsave(&xpd->lock, flags);
        priv = xpd->priv;
        BUG_ON(!priv);
-       len += sprintf(page + len, "%-8s %-10s %-10s %-10s %-10s %-10s\n",
-                       "Channel",
-                       "idletxhookstate",
-                       "lasttxhook",
-                       "ohttimer",
-                       "neon_blinking",
-                       "search_fsk_pattern"
-                       );
+       len +=
+           sprintf(page + len, "%-8s %-10s %-10s %-10s %-10s %-10s\n",
+                   "Channel", "idletxhookstate", "lasttxhook", "ohttimer",
+                   "neon_blinking", "search_fsk_pattern");
        for_each_line(xpd, i) {
-               char    pref;
+               char pref;
 
                if (IS_SET(PHONEDEV(xpd).digital_outputs, i))
                        pref = 'O';
@@ -1540,38 +1646,45 @@ static int proc_fxs_info_read(char *page, char **start, off_t off, int count, in
                        pref = 'I';
                else
                        pref = ' ';
-               len += sprintf(page + len, "%c%7d %10d %10d %10d %10d %10d\n",
-                               pref,
-                               i,
-                               priv->idletxhookstate[i],
-                               priv->lasttxhook[i],
-                               priv->ohttimer[i],
-                               IS_SET(priv->neon_blinking, i),
-                               IS_SET(priv->search_fsk_pattern, i)
-                             );
+               len +=
+                   sprintf(page + len, "%c%7d %10d %10d %10d %10d %10d\n",
+                           pref, i, priv->idletxhookstate[i],
+                           priv->lasttxhook[i], priv->ohttimer[i],
+                           IS_SET(priv->neon_blinking, i),
+                           IS_SET(priv->search_fsk_pattern, i)
+                   );
        }
        len += sprintf(page + len, "\n");
        for (led = 0; led < NUM_LEDS; led++) {
                len += sprintf(page + len, "LED #%d", led);
                len += sprintf(page + len, "\n\t%-17s: ", "ledstate");
                for_each_line(xpd, i) {
-                       if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) && !IS_SET(PHONEDEV(xpd).digital_inputs, i))
-                               len += sprintf(page + len, "%d ", IS_SET(priv->ledstate[led], i));
+                       if (!IS_SET(PHONEDEV(xpd).digital_outputs, i)
+                           && !IS_SET(PHONEDEV(xpd).digital_inputs, i))
+                               len +=
+                                   sprintf(page + len, "%d ",
+                                           IS_SET(priv->ledstate[led], i));
                }
                len += sprintf(page + len, "\n\t%-17s: ", "ledcontrol");
                for_each_line(xpd, i) {
-                       if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) && !IS_SET(PHONEDEV(xpd).digital_inputs, i))
-                               len += sprintf(page + len, "%d ", IS_SET(priv->ledcontrol[led], i));
+                       if (!IS_SET(PHONEDEV(xpd).digital_outputs, i)
+                           && !IS_SET(PHONEDEV(xpd).digital_inputs, i))
+                               len +=
+                                   sprintf(page + len, "%d ",
+                                           IS_SET(priv->ledcontrol[led], i));
                }
                len += sprintf(page + len, "\n\t%-17s: ", "led_counter");
                for_each_line(xpd, i) {
-                       if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) && !IS_SET(PHONEDEV(xpd).digital_inputs, i))
-                               len += sprintf(page + len, "%d ", LED_COUNTER(priv,i,led));
+                       if (!IS_SET(PHONEDEV(xpd).digital_outputs, i)
+                           && !IS_SET(PHONEDEV(xpd).digital_inputs, i))
+                               len +=
+                                   sprintf(page + len, "%d ",
+                                           LED_COUNTER(priv, i, led));
                }
                len += sprintf(page + len, "\n");
        }
        spin_unlock_irqrestore(&xpd->lock, flags);
-       if (len <= off+count)
+       if (len <= off + count)
                *eof = 1;
        *start = page + off;
        len -= off;
@@ -1584,13 +1697,14 @@ static int proc_fxs_info_read(char *page, char **start, off_t off, int count, in
 #endif
 
 #ifdef WITH_METERING
-static int proc_xpd_metering_write(struct file *file, const char __user *buffer, unsigned long count, void *data)
+static int proc_xpd_metering_write(struct file *file, const char __user *buffer,
+                                  unsigned long count, void *data)
 {
-       xpd_t           *xpd = data;
-       char            buf[MAX_PROC_WRITE];
-       lineno_t        chan;
-       int             num;
-       int             ret;
+       xpd_t *xpd = data;
+       char buf[MAX_PROC_WRITE];
+       lineno_t chan;
+       int num;
+       int ret;
 
        if (!xpd)
                return -ENODEV;
@@ -1603,7 +1717,8 @@ static int proc_xpd_metering_write(struct file *file, const char __user *buffer,
        buf[count] = '\0';
        ret = sscanf(buf, "%d", &num);
        if (ret != 1) {
-               XPD_ERR(xpd, "Metering value should be number. Got '%s'\n", buf);
+               XPD_ERR(xpd, "Metering value should be number. Got '%s'\n",
+                       buf);
                return -EINVAL;
        }
        chan = num;
@@ -1621,13 +1736,13 @@ static int proc_xpd_metering_write(struct file *file, const char __user *buffer,
 
 static int fxs_xpd_probe(struct device *dev)
 {
-       xpd_t   *xpd;
+       xpd_t *xpd;
 
        xpd = dev_to_xpd(dev);
        /* Is it our device? */
        if (xpd->type != XPD_TYPE_FXS) {
-               XPD_ERR(xpd, "drop suggestion for %s (%d)\n",
-                       dev_name(dev), xpd->type);
+               XPD_ERR(xpd, "drop suggestion for %s (%d)\n", dev_name(dev),
+                       xpd->type);
                return -EINVAL;
        }
        XPD_DBG(DEVICES, xpd, "SYSFS\n");
@@ -1636,28 +1751,27 @@ static int fxs_xpd_probe(struct device *dev)
 
 static int fxs_xpd_remove(struct device *dev)
 {
-       xpd_t   *xpd;
+       xpd_t *xpd;
 
        xpd = dev_to_xpd(dev);
        XPD_DBG(DEVICES, xpd, "SYSFS\n");
        return 0;
 }
 
-static struct xpd_driver       fxs_driver = {
-       .type           = XPD_TYPE_FXS,
-       .driver         = {
-               .name = "fxs",
+static struct xpd_driver fxs_driver = {
+       .type = XPD_TYPE_FXS,
+       .driver = {
+                  .name = "fxs",
 #ifndef OLD_HOTPLUG_SUPPORT
-               .owner = THIS_MODULE,
+                  .owner = THIS_MODULE,
 #endif
-               .probe = fxs_xpd_probe,
-               .remove = fxs_xpd_remove
-       }
+                  .probe = fxs_xpd_probe,
+                  .remove = fxs_xpd_remove}
 };
 
 static int __init card_fxs_startup(void)
 {
-       int     ret;
+       int ret;
 
        if ((ret = xpd_driver_register(&fxs_driver.driver)) < 0)
                return ret;
@@ -1665,7 +1779,7 @@ static int __init card_fxs_startup(void)
        INFO("revision %s\n", XPP_VERSION);
 #ifdef POLL_DIGITAL_INPUTS
        INFO("FEATURE: with DIGITAL INPUTS support (polled every %d msec)\n",
-                       poll_digital_inputs);
+            poll_digital_inputs);
 #else
        INFO("FEATURE: without DIGITAL INPUTS support\n");
 #endif
index 44c8fb0..2b6e267 100644 (file)
 #include "xpd.h"
 
 enum fxs_opcodes {
-       XPROTO_NAME(FXS, SIG_CHANGED)           = 0x06,
-/**/
-       XPROTO_NAME(FXS, CHAN_POWER)            = 0x0F, /* Write to SLIC */
-       XPROTO_NAME(FXS, CHAN_CID)              = 0x0F, /* Write to SLIC */
-       XPROTO_NAME(FXS, LED)                   = 0x0F, /* Write to SLIC */
+       XPROTO_NAME(FXS, SIG_CHANGED) = 0x06,
+        /**/ XPROTO_NAME(FXS, CHAN_POWER) = 0x0F,      /* Write to SLIC */
+       XPROTO_NAME(FXS, CHAN_CID) = 0x0F,      /* Write to SLIC */
+       XPROTO_NAME(FXS, LED) = 0x0F,   /* Write to SLIC */
 };
 
+DEF_RPACKET_DATA(FXS, SIG_CHANGED, xpp_line_t sig_status;      /* channels: lsb=1, msb=8 */
+                xpp_line_t sig_toggles;        /* channels: lsb=1, msb=8 */
+    );
 
-DEF_RPACKET_DATA(FXS, SIG_CHANGED,
-       xpp_line_t      sig_status;     /* channels: lsb=1, msb=8 */
-       xpp_line_t      sig_toggles;    /* channels: lsb=1, msb=8 */
-       );
-
-#endif /* CARD_FXS_H */
+#endif /* CARD_FXS_H */
index b786f31..8918e5c 100644 (file)
 
 static const char rcsid[] = "$Id$";
 
-DEF_PARM(charp,initdir, "/usr/share/dahdi", 0644, "The directory of card initialization scripts");
+DEF_PARM(charp, initdir, "/usr/share/dahdi", 0644,
+        "The directory of card initialization scripts");
 
 #define        CHIP_REGISTERS  "chipregs"
 
-extern int debug;
+extern int debug;
 
 /*---------------- GLOBAL PROC handling -----------------------------------*/
 
-static int send_magic_request(xbus_t *xbus,
-       unsigned unit, xportno_t portno, bool eoftx)
+static int send_magic_request(xbus_t *xbus, unsigned unit, xportno_t portno,
+                             bool eoftx)
 {
-       xframe_t        *xframe;
-       xpacket_t       *pack;
-       reg_cmd_t       *reg_cmd;
-       int             ret;
+       xframe_t *xframe;
+       xpacket_t *pack;
+       reg_cmd_t *reg_cmd;
+       int ret;
 
        /*
         * Zero length multibyte is legal and has special meaning for the
@@ -65,15 +66,15 @@ static int send_magic_request(xbus_t *xbus,
                dump_xframe(__func__, xbus, xframe, debug);
        ret = send_cmd_frame(xbus, xframe);
        if (ret < 0)
-               PORT_ERR(xbus, unit, portno,
-                       "%s: failed sending xframe\n", __func__);
+               PORT_ERR(xbus, unit, portno, "%s: failed sending xframe\n",
+                        __func__);
        return ret;
 }
 
 static int parse_hexbyte(const char *buf)
 {
-       char            *endp;
-       unsigned        val;
+       char *endp;
+       unsigned val;
 
        val = simple_strtoul(buf, &endp, 16);
        if (*endp != '\0' || val > 0xFF)
@@ -83,26 +84,26 @@ static int parse_hexbyte(const char *buf)
 
 static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[])
 {
-       int                     argno;
-       char                    num_args;
-       int                     portno;
-       bool                    writing;
-       int                     op;             /* [W]rite, [R]ead */
-       int                     addr_mode;      /* [D]irect, [I]ndirect, [Mm]ulti */
-       bool                    do_subreg = 0;
-       int                     regnum;
-       int                     subreg;
-       int                     data_low;
-       bool                    do_datah;
-       int                     data_high;
-       int                     ret = -EBADR;
-
-       num_args = 2;   /* port + operation */
+       int argno;
+       char num_args;
+       int portno;
+       bool writing;
+       int op;                 /* [W]rite, [R]ead */
+       int addr_mode;          /* [D]irect, [I]ndirect, [Mm]ulti */
+       bool do_subreg = 0;
+       int regnum;
+       int subreg;
+       int data_low;
+       bool do_datah;
+       int data_high;
+       int ret = -EBADR;
+
+       num_args = 2;           /* port + operation */
        if (argc < num_args) {
                XPD_ERR(xpd, "Not enough arguments (%d)\n", argc);
                XPD_ERR(xpd,
-                               "Any Command is composed of at least %d words (got only %d)\n",
-                               num_args, argc);
+                       "Any Command is composed of at least %d words (got only %d)\n",
+                       num_args, argc);
                goto out;
        }
        /* Process the arguments */
@@ -125,47 +126,49 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[])
        }
        op = argv[argno][0];
        switch (op) {
-               case 'W':
-                       writing = 1;
-                       num_args++;     /* data low */
-                       //XPD_DBG(REGS, xpd, "WRITING\n");
-                       break;
-               case 'R':
-                       writing = 0;
-                       //XPD_DBG(REGS, xpd, "READING\n");
-                       break;
-               default:
-                       XPD_ERR(xpd, "Unknown operation type '%c'\n", op);
-                       goto out;
+       case 'W':
+               writing = 1;
+               num_args++;     /* data low */
+               //XPD_DBG(REGS, xpd, "WRITING\n");
+               break;
+       case 'R':
+               writing = 0;
+               //XPD_DBG(REGS, xpd, "READING\n");
+               break;
+       default:
+               XPD_ERR(xpd, "Unknown operation type '%c'\n", op);
+               goto out;
        }
        addr_mode = argv[argno][1];
        switch (addr_mode) {
-               case 'I':
-                       XPD_NOTICE(xpd, "'I' is deprecated in register commands. Use 'S' instead.\n");
-                       /* fall through */
-               case 'S':
-                       do_subreg = 1;
-                       num_args += 2;  /* register + subreg */
-                       //XPD_DBG(REGS, xpd, "SUBREG\n");
-                       break;
-               case 'D':
-                       do_subreg = 0;
-                       num_args++;     /* register */
-                       //XPD_DBG(REGS, xpd, "DIRECT\n");
-                       break;
-               case 'M':
-               case 'm':
-                       if (op != 'W') {
-                               XPD_ERR(xpd,
-                                               "Can use Multibyte (%c) only with op 'W'\n", addr_mode);
-                               goto out;
-                       }
-                       num_args--;     /* No data low */
-                       //XPD_DBG(REGS, xpd, "Multibyte (%c)\n", addr_mode);
-                       break;
-               default:
-                       XPD_ERR(xpd, "Unknown addressing type '%c'\n", addr_mode);
+       case 'I':
+               XPD_NOTICE(xpd,
+                          "'I' is deprecated in register commands. Use 'S' instead.\n");
+               /* fall through */
+       case 'S':
+               do_subreg = 1;
+               num_args += 2;  /* register + subreg */
+               //XPD_DBG(REGS, xpd, "SUBREG\n");
+               break;
+       case 'D':
+               do_subreg = 0;
+               num_args++;     /* register */
+               //XPD_DBG(REGS, xpd, "DIRECT\n");
+               break;
+       case 'M':
+       case 'm':
+               if (op != 'W') {
+                       XPD_ERR(xpd,
+                               "Can use Multibyte (%c) only with op 'W'\n",
+                               addr_mode);
                        goto out;
+               }
+               num_args--;     /* No data low */
+               //XPD_DBG(REGS, xpd, "Multibyte (%c)\n", addr_mode);
+               break;
+       default:
+               XPD_ERR(xpd, "Unknown addressing type '%c'\n", addr_mode);
+               goto out;
        }
        if (argv[argno][2] != '\0') {
                XPD_ERR(xpd, "Bad operation field '%s'\n", argv[argno]);
@@ -173,20 +176,21 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[])
        }
        if (argc < num_args) {
                XPD_ERR(xpd,
-                               "Command \"%s\" is composed of at least %d words (got only %d)\n",
-                               argv[argno], num_args, argc);
+                       "Command \"%s\" is composed of at least %d words (got only %d)\n",
+                       argv[argno], num_args, argc);
                goto out;
        }
        argno++;
        if (addr_mode == 'M' || addr_mode == 'm') {
                if (argno < argc) {
                        XPD_ERR(xpd,
-                                       "Magic-Multibyte(%c) with %d extra arguments\n",
-                                       addr_mode, argc - argno);
+                               "Magic-Multibyte(%c) with %d extra arguments\n",
+                               addr_mode, argc - argno);
                        goto out;
                }
-               ret = send_magic_request(xpd->xbus, xpd->addr.unit, portno,
-                       addr_mode == 'm');
+               ret =
+                   send_magic_request(xpd->xbus, xpd->addr.unit, portno,
+                                      addr_mode == 'm');
                goto out;
        }
        /* Normal (non-Magic) register commands */
@@ -209,7 +213,8 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[])
                }
                subreg = parse_hexbyte(argv[argno]);
                if (subreg < 0) {
-                       XPD_ERR(xpd, "Illegal subregister number '%s'\n", argv[argno]);
+                       XPD_ERR(xpd, "Illegal subregister number '%s'\n",
+                               argv[argno]);
                        goto out;
                }
                //XPD_DBG(REGS, xpd, "Subreg is %X\n", subreg);
@@ -223,7 +228,8 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[])
                }
                data_low = parse_hexbyte(argv[argno]);
                if (data_low < 0) {
-                       XPD_ERR(xpd, "Illegal data_low number '%s'\n", argv[argno]);
+                       XPD_ERR(xpd, "Illegal data_low number '%s'\n",
+                               argv[argno]);
                        goto out;
                }
                //XPD_DBG(REGS, xpd, "Data Low is %X\n", data_low);
@@ -238,7 +244,8 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[])
                }
                data_high = parse_hexbyte(argv[argno]);
                if (data_high < 0) {
-                       XPD_ERR(xpd, "Illegal data_high number '%s'\n", argv[argno]);
+                       XPD_ERR(xpd, "Illegal data_high number '%s'\n",
+                               argv[argno]);
                        goto out;
                }
                //XPD_DBG(REGS, xpd, "Data High is %X\n", data_high);
@@ -246,41 +253,37 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[])
        } else
                data_high = 0;
        if (argno < argc) {
-               XPD_ERR(xpd,
-                               "Command contains an extra %d argument\n",
-                               argc - argno);
+               XPD_ERR(xpd, "Command contains an extra %d argument\n",
+                       argc - argno);
                goto out;
        }
 #if 0
-       XPD_DBG(REGS, xpd,
-                       "portno=%d writing=%d regnum=%d do_subreg=%d subreg=%d dataL=%d do_datah=%d dataH=%d\n",
-                       portno,         /* portno       */
-                       writing,        /* writing      */
-                       regnum,
-                       do_subreg,      /* use subreg   */
-                       subreg, /* subreg       */
-                       data_low,
-                       do_datah,       /* use data_high*/
-                       data_high);
+       XPD_DBG(REGS, xpd, "portno=%d writing=%d regnum=%d do_subreg=%d subreg=%d dataL=%d do_datah=%d dataH=%d\n", portno,     /* portno       */
+               writing,        /* writing      */
+               regnum, do_subreg,      /* use subreg   */
+               subreg,         /* subreg       */
+               data_low, do_datah,     /* use data_high */
+               data_high);
 #endif
-       ret = xpp_register_request(xpd->xbus, xpd, portno,
-               writing, regnum, do_subreg, subreg,
-               data_low, do_datah, data_high, 1);
+       ret =
+           xpp_register_request(xpd->xbus, xpd, portno, writing, regnum,
+                                do_subreg, subreg, data_low, do_datah,
+                                data_high, 1);
 out:
        return ret;
 }
 
 int parse_chip_command(xpd_t *xpd, char *cmdline)
 {
-       xbus_t                  *xbus;
-       int                     ret = -EBADR;
-       __u8                    buf[MAX_PROC_WRITE];
-       char                    *str;
-       char                    *p;
-       static const int        MAX_ARGS = 10;
-       char                    *argv[MAX_ARGS + 1];
-       int                     argc;
-       int                     i;
+       xbus_t *xbus;
+       int ret = -EBADR;
+       __u8 buf[MAX_PROC_WRITE];
+       char *str;
+       char *p;
+       static const int MAX_ARGS = 10;
+       char *argv[MAX_ARGS + 1];
+       int argc;
+       int i;
 
        BUG_ON(!xpd);
        xbus = xpd->xbus;
@@ -295,10 +298,10 @@ int parse_chip_command(xpd_t *xpd, char *cmdline)
                *p = '\0';
        if ((p = strchr(buf, ';')) != NULL)     /* Truncate comments */
                *p = '\0';
-       for (p = buf; *p && (*p == ' ' || *p == '\t'); p++) /* Trim leading whitespace */
+       for (p = buf; *p && (*p == ' ' || *p == '\t'); p++)     /* Trim leading whitespace */
                ;
        str = p;
-       for (i = 0; (p = strsep(&str, " \t")) != NULL && i < MAX_ARGS; ) {
+       for (i = 0; (p = strsep(&str, " \t")) != NULL && i < MAX_ARGS;) {
                if (*p != '\0') {
                        argv[i] = p;
                        // XPD_DBG(REGS, xpd, "ARG %d = '%s'\n", i, p);
@@ -308,7 +311,8 @@ int parse_chip_command(xpd_t *xpd, char *cmdline)
        argv[i] = NULL;
        argc = i;
        if (p) {
-               XPD_ERR(xpd, "Too many words (%d) to process. Last was '%s'\n", i, p);
+               XPD_ERR(xpd, "Too many words (%d) to process. Last was '%s'\n",
+                       i, p);
                goto out;
        }
        if (argc)
@@ -328,9 +332,9 @@ static void global_packet_dump(const char *msg, xpacket_t *pack);
 
 /* 0x07 */ HOSTCMD(GLOBAL, AB_REQUEST)
 {
-       int             ret = -ENODEV;
-       xframe_t        *xframe;
-       xpacket_t       *pack;
+       int ret = -ENODEV;
+       xframe_t *xframe;
+       xpacket_t *pack;
 
        if (!xbus) {
                DBG(DEVICES, "NO XBUS\n");
@@ -348,23 +352,24 @@ static void global_packet_dump(const char *msg, xpacket_t *pack);
 }
 
 int xpp_register_request(xbus_t *xbus, xpd_t *xpd, xportno_t portno,
-       bool writing, __u8 regnum, bool do_subreg, __u8 subreg,
-       __u8 data_low, bool do_datah, __u8 data_high, bool should_reply)
+                        bool writing, __u8 regnum, bool do_subreg, __u8 subreg,
+                        __u8 data_low, bool do_datah, __u8 data_high,
+                        bool should_reply)
 {
-       int             ret = 0;
-       xframe_t        *xframe;
-       xpacket_t       *pack;
-       reg_cmd_t       *reg_cmd;
+       int ret = 0;
+       xframe_t *xframe;
+       xpacket_t *pack;
+       reg_cmd_t *reg_cmd;
 
        if (!xbus) {
                DBG(REGS, "NO XBUS\n");
                return -EINVAL;
        }
-       XFRAME_NEW_CMD(xframe, pack, xbus, GLOBAL, REGISTER_REQUEST, xpd->xbus_idx);
+       XFRAME_NEW_CMD(xframe, pack, xbus, GLOBAL, REGISTER_REQUEST,
+                      xpd->xbus_idx);
        LINE_DBG(REGS, xpd, portno, "%c%c %02X %02X %02X %02X\n",
-                       (writing)?'W':'R',
-                       (do_subreg)?'S':'D',
-                       regnum, subreg, data_low, data_high);
+                (writing) ? 'W' : 'R', (do_subreg) ? 'S' : 'D', regnum, subreg,
+                data_low, data_high);
        reg_cmd = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REQUEST, reg_cmd);
        reg_cmd->bytes = sizeof(*reg_cmd) - 1;  // do not count the 'bytes' field
        reg_cmd->is_multibyte = 0;
@@ -387,7 +392,8 @@ int xpp_register_request(xbus_t *xbus, xpd_t *xpd, xportno_t portno,
        if (should_reply)
                xpd->requested_reply = *reg_cmd;
        if (debug & DBG_REGS) {
-               dump_reg_cmd("REG_REQ", 1, xbus, xpd->addr.unit, reg_cmd->portnum, reg_cmd);
+               dump_reg_cmd("REG_REQ", 1, xbus, xpd->addr.unit,
+                            reg_cmd->portnum, reg_cmd);
                dump_packet("REG_REQ", pack, 1);
        }
        if (!xframe->usec_towait) {     /* default processing time of SPI */
@@ -405,9 +411,9 @@ int xpp_register_request(xbus_t *xbus, xpd_t *xpd, xportno_t portno,
  */
 /* 0x19 */ HOSTCMD(GLOBAL, SYNC_SOURCE, enum sync_mode mode, int drift)
 {
-       xframe_t        *xframe;
-       xpacket_t       *pack;
-       const char      *mode_name;
+       xframe_t *xframe;
+       xpacket_t *pack;
+       const char *mode_name;
 
        BUG_ON(!xbus);
        if ((mode_name = sync_mode_name(mode)) == NULL) {
@@ -424,8 +430,8 @@ int xpp_register_request(xbus_t *xbus, xpd_t *xpd, xportno_t portno,
 
 /* 0x23 */ HOSTCMD(GLOBAL, RESET_SYNC_COUNTERS)
 {
-       xframe_t        *xframe;
-       xpacket_t       *pack;
+       xframe_t *xframe;
+       xpacket_t *pack;
 
        BUG_ON(!xbus);
        //XBUS_DBG(SYNC, xbus, "\n");
@@ -443,14 +449,14 @@ HANDLER_DEF(GLOBAL, NULL_REPLY)
        return 0;
 }
 
-HANDLER_DEF(GLOBAL, AB_DESCRIPTION)    /* 0x08 */
-{
-       struct xbus_workqueue   *worker;
-       __u8                    rev;
-       struct unit_descriptor  *units;
-       int                     count_units;
-       int                     i;
-       int                     ret = 0;
+HANDLER_DEF(GLOBAL, AB_DESCRIPTION)
+{                              /* 0x08 */
+       struct xbus_workqueue *worker;
+       __u8 rev;
+       struct unit_descriptor *units;
+       int count_units;
+       int i;
+       int ret = 0;
 
        if (!xbus) {
                NOTICE("%s: xbus is gone!!!\n", __func__);
@@ -462,19 +468,18 @@ HANDLER_DEF(GLOBAL, AB_DESCRIPTION)       /* 0x08 */
        count_units /= sizeof(*units);
        if (rev != XPP_PROTOCOL_VERSION) {
                XBUS_NOTICE(xbus, "Bad protocol version %d (should be %d)\n",
-                       rev, XPP_PROTOCOL_VERSION);
+                           rev, XPP_PROTOCOL_VERSION);
                ret = -EPROTO;
                goto proto_err;
        }
        if (count_units > NUM_UNITS) {
                XBUS_NOTICE(xbus, "Too many units %d (should be %d)\n",
-                       count_units, NUM_UNITS);
+                           count_units, NUM_UNITS);
                ret = -EPROTO;
                goto proto_err;
        }
        if (count_units <= 0) {
-               XBUS_NOTICE(xbus, "Empty astribank? (%d units)\n",
-                       count_units);
+               XBUS_NOTICE(xbus, "Empty astribank? (%d units)\n", count_units);
                ret = -EPROTO;
                goto proto_err;
        }
@@ -482,7 +487,8 @@ HANDLER_DEF(GLOBAL, AB_DESCRIPTION) /* 0x08 */
                ret = -EPROTO;
                goto proto_err;
        }
-       XBUS_INFO(xbus, "DESCRIPTOR: %d cards, protocol revision %d\n", count_units, rev);
+       XBUS_INFO(xbus, "DESCRIPTOR: %d cards, protocol revision %d\n",
+                 count_units, rev);
        if (xbus_check_unique(xbus))
                return -EBUSY;
        xbus->revision = rev;
@@ -493,11 +499,13 @@ HANDLER_DEF(GLOBAL, AB_DESCRIPTION)       /* 0x08 */
                goto out;
        }
        for (i = 0; i < count_units; i++) {
-               struct unit_descriptor  *this_unit = &units[i];
-               struct card_desc_struct *card_desc;
-               unsigned long           flags;
+               struct unit_descriptor *this_unit = &units[i];
+               struct card_desc_struct *card_desc;
+               unsigned long flags;
 
-               if ((card_desc = KZALLOC(sizeof(struct card_desc_struct), GFP_ATOMIC)) == NULL) {
+               if ((card_desc =
+                    KZALLOC(sizeof(struct card_desc_struct),
+                            GFP_ATOMIC)) == NULL) {
                        XBUS_ERR(xbus, "Card description allocation failed.\n");
                        ret = -ENOMEM;
                        goto out;
@@ -510,16 +518,14 @@ HANDLER_DEF(GLOBAL, AB_DESCRIPTION)       /* 0