2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Written by Oron Peled <oron@actcom.co.il>
|
|
|
|
* Copyright (C) 2004-2006, Xorcom
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include "xpd.h"
|
|
|
|
#include "xproto.h"
|
|
|
|
#include "xpp_dahdi.h"
|
2012-01-12 01:04:36 +08:00
|
|
|
#include "card_fxs.h"
|
2010-08-28 05:59:27 +08:00
|
|
|
#include "dahdi_debug.h"
|
|
|
|
#include "xbus-core.h"
|
|
|
|
|
|
|
|
static const char rcsid[] = "$Id$";
|
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
/* must be before dahdi_debug.h */
|
|
|
|
static DEF_PARM(int, debug, 0, 0644, "Print DBG statements");
|
2010-08-28 05:59:27 +08:00
|
|
|
static DEF_PARM_BOOL(reversepolarity, 0, 0644, "Reverse Line Polarity");
|
|
|
|
static DEF_PARM_BOOL(dtmf_detection, 1, 0644, "Do DTMF detection in hardware");
|
|
|
|
#ifdef POLL_DIGITAL_INPUTS
|
|
|
|
static DEF_PARM(uint, poll_digital_inputs, 1000, 0644, "Poll Digital Inputs");
|
|
|
|
#endif
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
static DEF_PARM_BOOL(vmwi_ioctl, 1, 0644,
|
|
|
|
"Asterisk support VMWI notification via ioctl");
|
2011-07-04 22:05:43 +08:00
|
|
|
static DEF_PARM_BOOL(ring_trapez, 0, 0664, "Use trapezoid ring type");
|
2012-03-22 04:18:26 +08:00
|
|
|
static DEF_PARM_BOOL(lower_ringing_noise, 0, 0664,
|
|
|
|
"Lower ringing noise (may loose CallerID)");
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/* Signaling is opposite (fxo signalling for fxs card) */
|
|
|
|
#if 1
|
2012-01-12 03:56:35 +08:00
|
|
|
#define FXS_DEFAULT_SIGCAP \
|
|
|
|
(DAHDI_SIG_FXOKS | DAHDI_SIG_FXOLS | DAHDI_SIG_FXOGS)
|
2010-08-28 05:59:27 +08:00
|
|
|
#else
|
2012-01-12 03:56:35 +08:00
|
|
|
#define FXS_DEFAULT_SIGCAP \
|
|
|
|
(DAHDI_SIG_SF | DAHDI_SIG_EM)
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define VMWI_TYPE(priv, pos, type) \
|
|
|
|
((priv)->vmwisetting[pos].vmwi_type & DAHDI_VMWI_ ## type)
|
|
|
|
#define VMWI_NEON(priv, pos) VMWI_TYPE(priv, pos, HVAC)
|
|
|
|
|
|
|
|
#define LINES_DIGI_OUT 2
|
|
|
|
#define LINES_DIGI_INP 4
|
|
|
|
|
|
|
|
enum fxs_leds {
|
|
|
|
LED_GREEN,
|
|
|
|
LED_RED,
|
|
|
|
OUTPUT_RELAY,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NUM_LEDS 2
|
|
|
|
|
|
|
|
/* Shortcuts */
|
|
|
|
#define SLIC_WRITE 1
|
|
|
|
#define SLIC_READ 0
|
2012-01-11 23:21:13 +08:00
|
|
|
#define SLIC_DIRECT_REQUEST(xbus, xpd, port, writing, reg, dL) \
|
2012-01-12 03:56:35 +08:00
|
|
|
xpp_register_request((xbus), (xpd), (port), \
|
|
|
|
(writing), (reg), 0, 0, (dL), 0, 0, 0)
|
2012-01-11 23:21:13 +08:00
|
|
|
#define SLIC_INDIRECT_REQUEST(xbus, xpd, port, writing, reg, dL, dH) \
|
2012-01-12 03:56:35 +08:00
|
|
|
xpp_register_request((xbus), (xpd), (port), \
|
|
|
|
(writing), 0x1E, 1, (reg), (dL), 1, (dH), 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
#define VALID_PORT(port) \
|
|
|
|
(((port) >= 0 && (port) <= 7) || (port) == PORT_BROADCAST)
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#define REG_DIGITAL_IOCTRL 0x06 /* LED and RELAY control */
|
|
|
|
|
|
|
|
/* Values of SLIC linefeed control register (0x40) */
|
|
|
|
enum fxs_state {
|
2012-01-11 23:22:46 +08:00
|
|
|
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 */
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
#define FXS_LINE_POL_ACTIVE \
|
|
|
|
((reversepolarity) ? FXS_LINE_REV_ACTIVE : FXS_LINE_ACTIVE)
|
|
|
|
#define FXS_LINE_POL_OHTRANS \
|
|
|
|
((reversepolarity) ? FXS_LINE_REV_OHTRANS : FXS_LINE_OHTRANS)
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DTMF detection
|
|
|
|
*/
|
|
|
|
#define REG_DTMF_DECODE 0x18 /* 24 - DTMF Decode Status */
|
|
|
|
#define REG_BATTERY 0x42 /* 66 - Battery Feed Control */
|
|
|
|
#define REG_BATTERY_BATSL BIT(1) /* Battery Feed Select */
|
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
/* 68 - Loop Closure/Ring Trip Detect Status */
|
|
|
|
#define REG_LOOPCLOSURE 0x44
|
2010-08-28 05:59:27 +08:00
|
|
|
#define REG_LOOPCLOSURE_ZERO 0xF8 /* Loop Closure zero bits. */
|
|
|
|
#define REG_LOOPCLOSURE_LCR BIT(0) /* Loop Closure Detect Indicator. */
|
|
|
|
|
|
|
|
/*---------------- FXS Protocol Commands ----------------------------------*/
|
|
|
|
|
|
|
|
static bool fxs_packet_is_valid(xpacket_t *pack);
|
|
|
|
static void fxs_packet_dump(const char *msg, xpacket_t *pack);
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2012-01-11 23:22:46 +08:00
|
|
|
static int proc_fxs_info_read(char *page, char **start, off_t off, int count,
|
|
|
|
int *eof, void *data);
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef WITH_METERING
|
2012-01-12 03:56:35 +08:00
|
|
|
static int proc_xpd_metering_write(struct file *file,
|
|
|
|
const char __user *buffer, unsigned long count, void *data);
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
static void start_stop_vm_led(xbus_t *xbus, xpd_t *xpd, lineno_t pos);
|
|
|
|
|
|
|
|
#define PROC_REGISTER_FNAME "slics"
|
|
|
|
#define PROC_FXS_INFO_FNAME "fxs_info"
|
|
|
|
#ifdef WITH_METERING
|
|
|
|
#define PROC_METERING_FNAME "metering_gen"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct FXS_priv_data {
|
|
|
|
#ifdef WITH_METERING
|
2012-01-11 23:22:46 +08:00
|
|
|
struct proc_dir_entry *meteringfile;
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
2012-01-11 23:22:46 +08:00
|
|
|
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;
|
2012-03-15 20:52:32 +08:00
|
|
|
xpp_line_t vbat_h; /* High voltage */
|
2012-01-11 23:22:46 +08:00
|
|
|
struct timeval prev_key_time[CHANNELS_PERXPD];
|
|
|
|
int led_counter[NUM_LEDS][CHANNELS_PERXPD];
|
|
|
|
int ohttimer[CHANNELS_PERXPD];
|
2010-08-28 05:59:27 +08:00
|
|
|
#define OHT_TIMER 6000 /* How long after RING to retain OHT */
|
2012-01-12 03:56:35 +08:00
|
|
|
/* IDLE changing hook state */
|
|
|
|
enum fxs_state idletxhookstate[CHANNELS_PERXPD];
|
2012-01-11 23:22:46 +08:00
|
|
|
enum fxs_state lasttxhook[CHANNELS_PERXPD];
|
|
|
|
struct dahdi_vmwi_info vmwisetting[CHANNELS_PERXPD];
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LED counter values:
|
|
|
|
* n>1 : BLINK every n'th tick
|
|
|
|
*/
|
2012-01-11 23:21:13 +08:00
|
|
|
#define LED_COUNTER(priv, pos, color) ((priv)->led_counter[color][pos])
|
|
|
|
#define IS_BLINKING(priv, pos, color) (LED_COUNTER(priv, pos, color) > 0)
|
2012-01-12 03:56:35 +08:00
|
|
|
#define MARK_BLINK(priv, pos, color, t) \
|
|
|
|
((priv)->led_counter[color][pos] = (t))
|
|
|
|
#define MARK_OFF(priv, pos, color) \
|
|
|
|
do { \
|
|
|
|
BIT_CLR((priv)->ledcontrol[color], (pos)); \
|
|
|
|
MARK_BLINK((priv), (pos), (color), 0); \
|
|
|
|
} while (0)
|
|
|
|
#define MARK_ON(priv, pos, color) \
|
|
|
|
do { \
|
|
|
|
BIT_SET((priv)->ledcontrol[color], (pos)); \
|
|
|
|
MARK_BLINK((priv), (pos), (color), 0); \
|
|
|
|
} while (0)
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#define LED_BLINK_RING (1000/8) /* in ticks */
|
|
|
|
|
|
|
|
/*---------------- FXS: Static functions ----------------------------------*/
|
2012-03-15 20:52:32 +08:00
|
|
|
static int do_chan_power(xbus_t *xbus, xpd_t *xpd, lineno_t chan, bool on)
|
|
|
|
{
|
|
|
|
struct FXS_priv_data *priv;
|
2012-03-22 04:17:14 +08:00
|
|
|
unsigned long *p;
|
|
|
|
int was;
|
2012-03-15 20:52:32 +08:00
|
|
|
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
priv = xpd->priv;
|
2012-03-22 04:17:14 +08:00
|
|
|
p = (unsigned long *)&priv->vbat_h;
|
2012-03-15 20:52:32 +08:00
|
|
|
if (on)
|
2012-03-22 04:17:14 +08:00
|
|
|
was = test_and_set_bit(chan, p) != 0;
|
2012-03-15 20:52:32 +08:00
|
|
|
else
|
2012-03-22 04:17:14 +08:00
|
|
|
was = test_and_clear_bit(chan, p) != 0;
|
|
|
|
if (was == on) {
|
|
|
|
LINE_DBG(SIGNAL, xpd, chan,
|
|
|
|
"%s (same, ignored)\n", (on) ? "up" : "down");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LINE_DBG(SIGNAL, xpd, chan, "%s\n", (on) ? "up" : "down");
|
2012-03-15 20:52:32 +08:00
|
|
|
return SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE, REG_BATTERY,
|
|
|
|
(on) ? REG_BATTERY_BATSL : 0x00);
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
static int linefeed_control(xbus_t *xbus, xpd_t *xpd, lineno_t chan,
|
|
|
|
enum fxs_state value)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
2012-03-22 04:18:26 +08:00
|
|
|
bool want_vbat_h;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
priv = xpd->priv;
|
2012-03-22 04:18:26 +08:00
|
|
|
/*
|
|
|
|
* Should we drop vbat_h only during actuall ring?
|
|
|
|
* - It would lower the noise caused to other channels by
|
|
|
|
* group ringing
|
|
|
|
* - But it may also stop CallerID from passing through the SLIC
|
|
|
|
*/
|
|
|
|
want_vbat_h = value == FXS_LINE_RING;
|
|
|
|
if (lower_ringing_noise || want_vbat_h)
|
|
|
|
do_chan_power(xbus, xpd, chan, want_vbat_h);
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, chan, "value=0x%02X\n", value);
|
|
|
|
priv->lasttxhook[chan] = value;
|
|
|
|
return SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE, 0x40, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vmwi_search(xpd_t *xpd, lineno_t pos, bool on)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
if (VMWI_NEON(priv, pos) && on) {
|
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "START\n");
|
|
|
|
BIT_SET(priv->search_fsk_pattern, pos);
|
|
|
|
} else {
|
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "STOP\n");
|
|
|
|
BIT_CLR(priv->search_fsk_pattern, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LED and RELAY control is done via SLIC register 0x06:
|
|
|
|
* 7 6 5 4 3 2 1 0
|
2012-01-12 03:56:35 +08:00
|
|
|
* +-----+-----+-----+-----+-----+-----+-----+-----+
|
|
|
|
* | M2 | M1 | M3 | C2 | O1 | O3 | C1 | C3 |
|
|
|
|
* +-----+-----+-----+-----+-----+-----+-----+-----+
|
2010-08-28 05:59:27 +08:00
|
|
|
*
|
2012-01-12 03:56:35 +08:00
|
|
|
* Cn - Control bit (control one digital line)
|
|
|
|
* On - Output bit (program a digital line for output)
|
|
|
|
* Mn - Mask bit (only the matching output control bit is affected)
|
2010-08-28 05:59:27 +08:00
|
|
|
*
|
2012-01-12 03:56:35 +08:00
|
|
|
* C3 - OUTPUT RELAY (0 - OFF, 1 - ON)
|
|
|
|
* C1 - GREEN LED (0 - OFF, 1 - ON)
|
|
|
|
* O3 - Output RELAY (this line is output)
|
|
|
|
* O1 - Output GREEN (this line is output)
|
|
|
|
* C2 - RED LED (0 - OFF, 1 - ON)
|
|
|
|
* M3 - Mask RELAY. (1 - C3 effect the OUTPUT RELAY)
|
|
|
|
* M2 - Mask RED. (1 - C2 effect the RED LED)
|
|
|
|
* M1 - Mask GREEN. (1 - C1 effect the GREEN LED)
|
2010-08-28 05:59:27 +08:00
|
|
|
*
|
2012-01-12 03:56:35 +08:00
|
|
|
* The OUTPUT RELAY (actually a relay out) is connected to line 0 and 4 only.
|
2010-08-28 05:59:27 +08:00
|
|
|
*/
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
// 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) };
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* pos can be:
|
2012-01-11 23:19:01 +08:00
|
|
|
* - A line number
|
|
|
|
* - ALL_LINES. This is not valid anymore since 8-Jan-2007.
|
2010-08-28 05:59:27 +08:00
|
|
|
*/
|
2012-01-11 23:21:54 +08:00
|
|
|
static int do_led(xpd_t *xpd, lineno_t chan, __u8 which, bool on)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret = 0;
|
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
int value;
|
|
|
|
xbus_t *xbus;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
BUG_ON(chan == ALL_LINES);
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
priv = xpd->priv;
|
|
|
|
which = which % NUM_LEDS;
|
2012-01-11 23:22:46 +08:00
|
|
|
if (IS_SET(PHONEDEV(xpd).digital_outputs, chan)
|
|
|
|
|| IS_SET(PHONEDEV(xpd).digital_inputs, chan))
|
2010-08-28 05:59:27 +08:00
|
|
|
goto out;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (chan == PORT_BROADCAST) {
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->ledstate[which] = (on) ? ~0 : 0;
|
|
|
|
} else {
|
2012-01-13 01:14:15 +08:00
|
|
|
if (on)
|
2010-08-28 05:59:27 +08:00
|
|
|
BIT_SET(priv->ledstate[which], chan);
|
2012-01-13 01:14:15 +08:00
|
|
|
else
|
2010-08-28 05:59:27 +08:00
|
|
|
BIT_CLR(priv->ledstate[which], chan);
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(LEDS, xpd, chan, "LED: which=%d -- %s\n", which,
|
|
|
|
(on) ? "on" : "off");
|
2010-08-28 05:59:27 +08:00
|
|
|
value = BIT(2) | BIT(3);
|
|
|
|
value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[which]);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (on)
|
2010-08-28 05:59:27 +08:00
|
|
|
value |= led_register_vals[which];
|
2012-01-11 23:22:46 +08:00
|
|
|
ret =
|
|
|
|
SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE, REG_DIGITAL_IOCTRL,
|
|
|
|
value);
|
2010-08-28 05:59:27 +08:00
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_fxs_leds(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int i;
|
|
|
|
const enum fxs_leds colors[] = { LED_GREEN, LED_RED };
|
|
|
|
enum fxs_leds color;
|
|
|
|
unsigned int timer_count;
|
|
|
|
struct FXS_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
priv = xpd->priv;
|
|
|
|
timer_count = xpd->timer_count;
|
2012-01-11 23:20:05 +08:00
|
|
|
for (color = 0; color < ARRAY_SIZE(colors); color++) {
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
if (IS_SET
|
|
|
|
(PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).
|
|
|
|
digital_inputs, i))
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
2012-01-12 03:56:35 +08:00
|
|
|
/* Blinking? */
|
|
|
|
if ((xpd->blink_mode & BIT(i)) || IS_BLINKING(priv, i, color)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
int mod_value = LED_COUNTER(priv, i, color);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!mod_value)
|
2012-01-12 03:56:35 +08:00
|
|
|
/* safety value */
|
|
|
|
mod_value = DEFAULT_LED_PERIOD;
|
|
|
|
/* led state is toggled */
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((timer_count % mod_value) == 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(LEDS, xpd, i, "ledstate=%s\n",
|
|
|
|
(IS_SET
|
|
|
|
(priv->ledstate[color],
|
|
|
|
i)) ? "ON" : "OFF");
|
2012-01-13 01:14:15 +08:00
|
|
|
if (!IS_SET(priv->ledstate[color], i))
|
2010-08-28 05:59:27 +08:00
|
|
|
do_led(xpd, i, color, 1);
|
2012-01-13 01:14:15 +08:00
|
|
|
else
|
2010-08-28 05:59:27 +08:00
|
|
|
do_led(xpd, i, color, 0);
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
} 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);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void restore_leds(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
priv = xpd->priv;
|
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_OFFHOOK(xpd, i))
|
2010-08-28 05:59:27 +08:00
|
|
|
MARK_ON(priv, i, LED_GREEN);
|
|
|
|
else
|
|
|
|
MARK_OFF(priv, i, LED_GREEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_METERING
|
|
|
|
static int metering_gen(xpd_t *xpd, lineno_t chan, bool on)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
__u8 value = (on) ? 0x94 : 0x00;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, chan, "METERING Generate: %s\n",
|
|
|
|
(on) ? "ON" : "OFF");
|
|
|
|
return SLIC_DIRECT_REQUEST(xpd->xbus, xpd, chan, SLIC_WRITE, 0x23,
|
|
|
|
value);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*---------------- FXS: Methods -------------------------------------------*/
|
|
|
|
|
|
|
|
static void fxs_proc_remove(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
priv = xpd->priv;
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
#ifdef WITH_METERING
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->meteringfile) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_DBG(PROC, xpd, "Removing xpd metering tone file\n");
|
|
|
|
priv->meteringfile->data = NULL;
|
|
|
|
remove_proc_entry(PROC_METERING_FNAME, xpd->proc_xpd_dir);
|
|
|
|
priv->meteringfile = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->fxs_info) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_DBG(PROC, xpd, "Removing xpd FXS_INFO file\n");
|
|
|
|
remove_proc_entry(PROC_FXS_INFO_FNAME, xpd->proc_xpd_dir);
|
|
|
|
priv->fxs_info = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fxs_proc_create(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
priv = xpd->priv;
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
XPD_DBG(PROC, xpd, "Creating FXS_INFO file\n");
|
2012-01-11 23:22:46 +08:00
|
|
|
priv->fxs_info =
|
|
|
|
create_proc_read_entry(PROC_FXS_INFO_FNAME, 0444, xpd->proc_xpd_dir,
|
|
|
|
proc_fxs_info_read, xpd);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!priv->fxs_info) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "Failed to create proc file '%s'\n",
|
|
|
|
PROC_FXS_INFO_FNAME);
|
2010-08-28 05:59:27 +08:00
|
|
|
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");
|
2012-01-11 23:22:46 +08:00
|
|
|
priv->meteringfile =
|
|
|
|
create_proc_entry(PROC_METERING_FNAME, 0200, xpd->proc_xpd_dir);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!priv->meteringfile) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "Failed to create proc file '%s'\n",
|
|
|
|
PROC_METERING_FNAME);
|
2010-08-28 05:59:27 +08:00
|
|
|
fxs_proc_remove(xbus, xpd);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
SET_PROC_DIRENTRY_OWNER(priv->meteringfile);
|
|
|
|
priv->meteringfile->write_proc = proc_xpd_metering_write;
|
|
|
|
priv->meteringfile->read_proc = NULL;
|
|
|
|
priv->meteringfile->data = xpd;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
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)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd = NULL;
|
|
|
|
int channels;
|
|
|
|
int regular_channels;
|
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
int i;
|
|
|
|
int d_inputs = 0;
|
|
|
|
int d_outputs = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!to_phone) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XBUS_NOTICE(xbus,
|
2012-01-11 23:22:46 +08:00
|
|
|
"XPD=%d%d: try to instanciate FXS with reverse direction\n",
|
|
|
|
unit, subunit);
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (subtype == 2)
|
2010-08-28 05:59:27 +08:00
|
|
|
regular_channels = min(6, subunit_ports);
|
|
|
|
else
|
|
|
|
regular_channels = min(8, subunit_ports);
|
|
|
|
channels = regular_channels;
|
2011-09-23 02:55:44 +08:00
|
|
|
/* Calculate digital inputs/outputs */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (unit == 0 && subtype != 4) {
|
2010-08-28 05:59:27 +08:00
|
|
|
channels += 6; /* 2 DIGITAL OUTPUTS, 4 DIGITAL INPUTS */
|
2011-09-23 02:55:44 +08:00
|
|
|
d_inputs = LINES_DIGI_INP;
|
|
|
|
d_outputs = LINES_DIGI_OUT;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd =
|
|
|
|
xpd_alloc(xbus, unit, subunit, subtype, subunits,
|
|
|
|
sizeof(struct FXS_priv_data), proto_table, channels);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd)
|
2010-08-28 05:59:27 +08:00
|
|
|
return NULL;
|
2011-09-23 02:55:44 +08:00
|
|
|
/* Initialize digital inputs/outputs */
|
|
|
|
if (d_inputs) {
|
|
|
|
XBUS_DBG(GENERAL, xbus, "Initialize %d digital inputs\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
d_inputs);
|
2011-09-23 02:55:44 +08:00
|
|
|
PHONEDEV(xpd).digital_inputs =
|
2012-01-11 23:22:46 +08:00
|
|
|
BITMASK(d_inputs) << (regular_channels + d_outputs);
|
2011-09-23 02:55:44 +08:00
|
|
|
} else
|
|
|
|
XBUS_DBG(GENERAL, xbus, "No digital inputs\n");
|
|
|
|
if (d_outputs) {
|
|
|
|
XBUS_DBG(GENERAL, xbus, "Initialize %d digital outputs\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
d_outputs);
|
2011-09-23 02:55:44 +08:00
|
|
|
PHONEDEV(xpd).digital_outputs =
|
2012-01-11 23:22:46 +08:00
|
|
|
BITMASK(d_outputs) << regular_channels;
|
2011-09-23 02:55:44 +08:00
|
|
|
} else
|
|
|
|
XBUS_DBG(GENERAL, xbus, "No digital outputs\n");
|
2011-01-30 22:11:49 +08:00
|
|
|
PHONEDEV(xpd).direction = TO_PHONE;
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd->type_name = "FXS";
|
2012-01-11 23:20:05 +08:00
|
|
|
if (fxs_proc_create(xbus, xpd) < 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
goto err;
|
|
|
|
priv = xpd->priv;
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
priv->idletxhookstate[i] = FXS_LINE_POL_ACTIVE;
|
|
|
|
}
|
|
|
|
return xpd;
|
|
|
|
err:
|
|
|
|
xpd_free(xpd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXS_card_init(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret = 0;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
/*
|
|
|
|
* Setup ring timers
|
|
|
|
*/
|
|
|
|
/* Software controled ringing (for CID) */
|
2012-01-12 03:56:35 +08:00
|
|
|
/* Ringing Oscilator Control */
|
|
|
|
ret = SLIC_DIRECT_REQUEST(xbus, xpd, PORT_BROADCAST, SLIC_WRITE,
|
|
|
|
0x22, 0x00);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret < 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
goto err;
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
linefeed_control(xbus, xpd, i, FXS_LINE_POL_ACTIVE);
|
|
|
|
}
|
|
|
|
XPD_DBG(GENERAL, xpd, "done\n");
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
do_led(xpd, i, LED_GREEN, 0);
|
|
|
|
do_led(xpd, i, LED_RED, 0);
|
|
|
|
}
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
do_led(xpd, i, LED_GREEN, 1);
|
|
|
|
msleep(50);
|
|
|
|
}
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
do_led(xpd, i, LED_GREEN, 0);
|
|
|
|
msleep(50);
|
|
|
|
}
|
|
|
|
restore_leds(xpd);
|
2011-01-30 22:14:14 +08:00
|
|
|
CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0);
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* We should query our offhook state long enough time after we
|
|
|
|
* set the linefeed_control()
|
|
|
|
* So we do this after the LEDs
|
|
|
|
*/
|
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
if (IS_SET
|
|
|
|
(PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).
|
|
|
|
digital_inputs, i))
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
2012-01-11 23:22:46 +08:00
|
|
|
SLIC_DIRECT_REQUEST(xbus, xpd, i, SLIC_READ, REG_LOOPCLOSURE,
|
|
|
|
0);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
fxs_proc_remove(xbus, xpd);
|
|
|
|
XPD_ERR(xpd, "Failed initializing registers (%d)\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXS_card_remove(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
XPD_DBG(GENERAL, xpd, "\n");
|
|
|
|
fxs_proc_remove(xbus, xpd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXS_card_dahdi_preregistration(xpd_t *xpd, bool on)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus;
|
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off");
|
2012-05-23 20:20:23 +08:00
|
|
|
PHONEDEV(xpd).span.spantype = SPANTYPE_ANALOG_FXS;
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
XPD_DBG(GENERAL, xpd, "setting FXS channel %d\n", i);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_SET(PHONEDEV(xpd).digital_outputs, i)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
snprintf(cur_chan->name, MAX_CHANNAME,
|
|
|
|
"XPP_OUT/%02d/%1d%1d/%d", xbus->num,
|
|
|
|
xpd->addr.unit, xpd->addr.subunit, i);
|
2012-01-11 23:20:05 +08:00
|
|
|
} else if (IS_SET(PHONEDEV(xpd).digital_inputs, i)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
snprintf(cur_chan->name, MAX_CHANNAME,
|
|
|
|
"XPP_IN/%02d/%1d%1d/%d", xbus->num,
|
|
|
|
xpd->addr.unit, xpd->addr.subunit, i);
|
2010-08-28 05:59:27 +08:00
|
|
|
} else {
|
2012-01-11 23:22:46 +08:00
|
|
|
snprintf(cur_chan->name, MAX_CHANNAME,
|
|
|
|
"XPP_FXS/%02d/%1d%1d/%d", xbus->num,
|
|
|
|
xpd->addr.unit, xpd->addr.subunit, i);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
cur_chan->chanpos = i + 1;
|
|
|
|
cur_chan->pvt = xpd;
|
|
|
|
cur_chan->sigcap = FXS_DEFAULT_SIGCAP;
|
|
|
|
if (!vmwi_ioctl) {
|
|
|
|
/* Old asterisk, assume default VMWI type */
|
|
|
|
priv->vmwisetting[i].vmwi_type = DAHDI_VMWI_HVAC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
MARK_ON(priv, i, LED_GREEN);
|
|
|
|
msleep(4);
|
|
|
|
MARK_ON(priv, i, LED_RED);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXS_card_dahdi_postregistration(xpd_t *xpd, bool on)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus;
|
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
|
|
|
MARK_OFF(priv, i, LED_GREEN);
|
|
|
|
msleep(2);
|
|
|
|
MARK_OFF(priv, i, LED_RED);
|
|
|
|
msleep(2);
|
|
|
|
}
|
|
|
|
restore_leds(xpd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called with XPD spinlocked
|
|
|
|
*/
|
|
|
|
static void __do_mute_dtmf(xpd_t *xpd, int pos, bool muteit)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
2011-12-08 03:22:04 +08:00
|
|
|
|
|
|
|
priv = xpd->priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "%s\n", (muteit) ? "MUTE" : "UNMUTE");
|
2012-01-11 23:20:05 +08:00
|
|
|
if (muteit)
|
2011-01-30 22:11:49 +08:00
|
|
|
BIT_SET(PHONEDEV(xpd).mute_dtmf, pos);
|
2010-08-28 05:59:27 +08:00
|
|
|
else
|
2011-01-30 22:11:49 +08:00
|
|
|
BIT_CLR(PHONEDEV(xpd).mute_dtmf, pos);
|
2011-12-08 03:22:04 +08:00
|
|
|
/* already spinlocked */
|
|
|
|
CALL_PHONE_METHOD(card_pcm_recompute, xpd, priv->search_fsk_pattern);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int set_vm_led_mode(xbus_t *xbus, xpd_t *xpd, int pos,
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned int msg_waiting)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret = 0;
|
|
|
|
struct FXS_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
BUG_ON(!xbus);
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
|
|
|
|
priv = xpd->priv;
|
|
|
|
if (VMWI_NEON(priv, pos) && msg_waiting) {
|
|
|
|
/* A write to register 0x40 will now turn on/off the VM led */
|
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "NEON\n");
|
2011-12-08 03:22:04 +08:00
|
|
|
BIT_SET(priv->neon_blinking, pos);
|
2012-01-11 23:22:46 +08:00
|
|
|
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);
|
2011-07-04 22:05:43 +08:00
|
|
|
} else if (ring_trapez) {
|
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "RINGER: Trapez ring\n");
|
2012-01-11 23:22:46 +08:00
|
|
|
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);
|
2010-08-28 05:59:27 +08:00
|
|
|
} else {
|
|
|
|
/* A write to register 0x40 will now turn on/off the ringer */
|
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "RINGER\n");
|
2011-12-08 03:22:04 +08:00
|
|
|
BIT_CLR(priv->neon_blinking, pos);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
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);
|
|
|
|
/* High Vbat~ -82V[Dc] */
|
|
|
|
ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE,
|
|
|
|
0x4A, 0x34);
|
|
|
|
ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE,
|
|
|
|
0x1D, 0x00, 0x36);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
return (ret ? -EPROTO : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void start_stop_vm_led(xbus_t *xbus, xpd_t *xpd, lineno_t pos)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
unsigned int msgs;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
2012-01-11 23:22:46 +08:00
|
|
|
if (IS_SET
|
|
|
|
(PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).digital_inputs, pos))
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
priv = xpd->priv;
|
2011-01-30 22:11:49 +08:00
|
|
|
msgs = PHONEDEV(xpd).msg_waiting[pos];
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "%s\n", (msgs) ? "ON" : "OFF");
|
|
|
|
set_vm_led_mode(xbus, xpd, pos, msgs);
|
2012-03-22 04:18:26 +08:00
|
|
|
do_chan_power(xbus, xpd, pos, msgs > 0);
|
2012-01-11 23:22:46 +08:00
|
|
|
linefeed_control(xbus, xpd, pos,
|
|
|
|
(msgs >
|
|
|
|
0) ? FXS_LINE_RING : priv->idletxhookstate[pos]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int relay_out(xpd_t *xpd, int pos, bool on)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int value;
|
|
|
|
int which = pos;
|
|
|
|
int relay_channels[] = { 0, 4 };
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
/* map logical position to output port number (0/1) */
|
|
|
|
which -= (xpd->subtype == 2) ? 6 : 8;
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "which=%d -- %s\n", which,
|
|
|
|
(on) ? "on" : "off");
|
2010-08-28 05:59:27 +08:00
|
|
|
which = which % ARRAY_SIZE(relay_channels);
|
|
|
|
value = BIT(2) | BIT(3);
|
2012-01-11 23:22:46 +08:00
|
|
|
value |=
|
|
|
|
((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[OUTPUT_RELAY]);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (on)
|
2010-08-28 05:59:27 +08:00
|
|
|
value |= led_register_vals[OUTPUT_RELAY];
|
|
|
|
return SLIC_DIRECT_REQUEST(xpd->xbus, xpd, relay_channels[which],
|
2012-01-11 23:22:46 +08:00
|
|
|
SLIC_WRITE, REG_DIGITAL_IOCTRL, value);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int send_ring(xpd_t *xpd, lineno_t chan, bool on)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret = 0;
|
|
|
|
xbus_t *xbus;
|
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
enum fxs_state value = (on) ? FXS_LINE_RING : FXS_LINE_POL_ACTIVE;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
BUG_ON(!xbus);
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, chan, "%s\n", (on) ? "on" : "off");
|
2010-08-28 05:59:27 +08:00
|
|
|
priv = xpd->priv;
|
|
|
|
set_vm_led_mode(xbus, xpd, chan, 0);
|
2012-03-22 04:18:26 +08:00
|
|
|
do_chan_power(xbus, xpd, chan, on); /* Power up (for ring) */
|
2010-08-28 05:59:27 +08:00
|
|
|
ret = linefeed_control(xbus, xpd, chan, value);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (on) {
|
2010-08-28 05:59:27 +08:00
|
|
|
MARK_BLINK(priv, chan, LED_GREEN, LED_BLINK_RING);
|
|
|
|
} else {
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_BLINKING(priv, chan, LED_GREEN))
|
2010-08-28 05:59:27 +08:00
|
|
|
MARK_BLINK(priv, chan, LED_GREEN, 0);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-01-30 22:14:14 +08:00
|
|
|
static int FXS_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
int ret = 0;
|
|
|
|
struct dahdi_chan *chan = NULL;
|
|
|
|
enum fxs_state txhook;
|
|
|
|
unsigned long flags;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "%s\n", txsig2str(txsig));
|
|
|
|
priv = xpd->priv;
|
2011-01-30 22:11:49 +08:00
|
|
|
BUG_ON(PHONEDEV(xpd).direction != TO_PHONE);
|
|
|
|
if (IS_SET(PHONEDEV(xpd).digital_inputs, pos)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, pos,
|
|
|
|
"Ignoring signal sent to digital input line\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (SPAN_REGISTERED(xpd))
|
2010-08-28 05:59:27 +08:00
|
|
|
chan = XPD_CHAN(xpd, pos);
|
2012-01-11 23:20:05 +08:00
|
|
|
switch (txsig) {
|
2012-01-11 23:22:46 +08:00
|
|
|
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;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
}
|
|
|
|
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;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
}
|
|
|
|
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;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_vmwi(xpd_t *xpd, int pos, unsigned long arg)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
struct dahdi_vmwi_info vmwisetting;
|
|
|
|
const int vmwi_flags =
|
|
|
|
DAHDI_VMWI_LREV | DAHDI_VMWI_HVDC | DAHDI_VMWI_HVAC;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
2012-01-11 23:22:46 +08:00
|
|
|
if (copy_from_user
|
|
|
|
(&vmwisetting, (__user void *)arg, sizeof(vmwisetting)))
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EFAULT;
|
|
|
|
if ((vmwisetting.vmwi_type & ~vmwi_flags) != 0) {
|
|
|
|
LINE_NOTICE(xpd, pos, "Bad DAHDI_VMWI_CONFIG: 0x%X\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
vmwisetting.vmwi_type);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "DAHDI_VMWI_CONFIG: 0x%X\n",
|
|
|
|
vmwisetting.vmwi_type);
|
2010-08-28 05:59:27 +08:00
|
|
|
if (VMWI_TYPE(priv, pos, LREV)) {
|
|
|
|
LINE_NOTICE(xpd, pos,
|
2012-01-11 23:22:46 +08:00
|
|
|
"%s: VMWI(lrev) is not implemented yet. Ignored.\n",
|
|
|
|
__func__);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
if (VMWI_TYPE(priv, pos, HVDC)) {
|
|
|
|
LINE_NOTICE(xpd, pos,
|
2012-01-11 23:22:46 +08:00
|
|
|
"%s: VMWI(hvdc) is not implemented yet. Ignored.\n",
|
|
|
|
__func__);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-13 01:14:15 +08:00
|
|
|
if (VMWI_TYPE(priv, pos, HVAC))
|
2012-01-11 23:22:46 +08:00
|
|
|
; /* VMWI_NEON */
|
2012-01-13 01:14:15 +08:00
|
|
|
if (priv->vmwisetting[pos].vmwi_type == 0)
|
2012-01-11 23:22:46 +08:00
|
|
|
; /* Disable VMWI */
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->vmwisetting[pos] = vmwisetting;
|
2011-01-30 22:11:49 +08:00
|
|
|
set_vm_led_mode(xpd->xbus, xpd, pos, PHONEDEV(xpd).msg_waiting[pos]);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private ioctl()
|
|
|
|
* We don't need it now, since we detect vmwi via FSK patterns
|
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
static int FXS_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
xbus_t *xbus;
|
|
|
|
int val;
|
|
|
|
unsigned long flags;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
BUG_ON(!xbus);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!XBUS_IS(xbus, READY))
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENODEV;
|
2011-01-30 22:11:49 +08:00
|
|
|
if (pos < 0 || pos >= PHONEDEV(xpd).channels) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_NOTICE(xpd, "Bad channel number %d in %s(), cmd=%u\n", pos,
|
|
|
|
__func__, cmd);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-01-11 23:16:34 +08:00
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
switch (cmd) {
|
2012-01-11 23:22:46 +08:00
|
|
|
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) {
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_lock_irqsave(&xpd->lock, flags);
|
2012-01-11 23:22:46 +08:00
|
|
|
if (IS_SET(priv->want_dtmf_events, pos)) {
|
2012-01-12 03:56:35 +08:00
|
|
|
/*
|
|
|
|
* Detection mode changed:
|
|
|
|
* Disable DTMF interrupts
|
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE,
|
|
|
|
0x17, 0);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
BIT_CLR(priv->want_dtmf_events, pos);
|
|
|
|
BIT_CLR(priv->want_dtmf_mute, pos);
|
|
|
|
__do_mute_dtmf(xpd, pos, 0);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_unlock_irqrestore(&xpd->lock, flags);
|
2012-01-11 23:22:46 +08:00
|
|
|
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)) {
|
2012-01-12 03:56:35 +08:00
|
|
|
/*
|
|
|
|
* Detection mode changed:
|
|
|
|
* Enable DTMF interrupts
|
|
|
|
*/
|
2011-11-30 07:36:17 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, pos,
|
2012-01-12 03:56:35 +08:00
|
|
|
"DAHDI_TONEDETECT: "
|
|
|
|
"Enable Hardware DTMF\n");
|
2012-01-11 23:22:46 +08:00
|
|
|
SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE,
|
|
|
|
0x17, 1);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
BIT_SET(priv->want_dtmf_events, pos);
|
|
|
|
} else {
|
|
|
|
if (IS_SET(priv->want_dtmf_events, pos)) {
|
2012-01-12 03:56:35 +08:00
|
|
|
/*
|
|
|
|
* Detection mode changed:
|
|
|
|
* Disable DTMF interrupts
|
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, pos,
|
2012-01-12 03:56:35 +08:00
|
|
|
"DAHDI_TONEDETECT: "
|
|
|
|
"Disable Hardware DTMF\n");
|
2012-01-11 23:22:46 +08:00
|
|
|
SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE,
|
|
|
|
0x17, 0);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
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,
|
2012-01-12 03:56:35 +08:00
|
|
|
"DAHDI_SETPOLARITY: %s Cannot change "
|
|
|
|
"when lasttxhook=0x%X\n",
|
|
|
|
(val) ? "ON" : "OFF", priv->lasttxhook[pos]);
|
2012-01-11 23:22:46 +08:00
|
|
|
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,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Got DAHDI_VMWI notification "
|
|
|
|
"but vmwi_ioctl parameter is off. "
|
|
|
|
"Ignoring.\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
2012-01-11 23:22:46 +08:00
|
|
|
}
|
|
|
|
/* 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);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXS_card_open(xpd_t *xpd, lineno_t chan)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
priv = xpd->priv;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_OFFHOOK(xpd, chan))
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_NOTICE(xpd, chan, "Already offhook during open. OK.\n");
|
|
|
|
else
|
|
|
|
LINE_DBG(SIGNAL, xpd, chan, "is onhook\n");
|
|
|
|
/*
|
|
|
|
* Delegate updating dahdi to FXS_card_tick():
|
|
|
|
* The problem is that dahdi_hooksig() is spinlocking the channel and
|
|
|
|
* we are called by dahdi with the spinlock already held on the
|
|
|
|
* same channel.
|
|
|
|
*/
|
|
|
|
BIT_SET(priv->update_offhook_state, chan);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXS_card_close(xpd_t *xpd, lineno_t chan)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
LINE_DBG(GENERAL, xpd, chan, "\n");
|
|
|
|
priv = xpd->priv;
|
|
|
|
priv->idletxhookstate[chan] = FXS_LINE_POL_ACTIVE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef POLL_DIGITAL_INPUTS
|
|
|
|
/*
|
|
|
|
* INPUT polling is done via SLIC register 0x06 (same as LEDS):
|
|
|
|
* 7 6 5 4 3 2 1 0
|
2012-01-11 23:19:01 +08:00
|
|
|
* +-----+-----+-----+-----+-----+-----+-----+-----+
|
|
|
|
* | I1 | I3 | | | I2 | I4 | | |
|
|
|
|
* +-----+-----+-----+-----+-----+-----+-----+-----+
|
2010-08-28 05:59:27 +08:00
|
|
|
*
|
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
static int input_channels[] = { 6, 7, 2, 3 }; // Slic numbers of input relays
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static void poll_inputs(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(xpd->xbus_idx != 0); // Only unit #0 has digital inputs
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(input_channels); i++) {
|
2012-01-11 23:22:46 +08:00
|
|
|
__u8 pos = input_channels[i];
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
SLIC_DIRECT_REQUEST(xpd->xbus, xpd, pos, SLIC_READ, 0x06, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void handle_linefeed(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
if (priv->lasttxhook[i] == FXS_LINE_RING
|
|
|
|
&& !IS_SET(priv->neon_blinking, i)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/* RINGing, prepare for OHT */
|
|
|
|
priv->ohttimer[i] = OHT_TIMER;
|
|
|
|
priv->idletxhookstate[i] = FXS_LINE_POL_OHTRANS;
|
|
|
|
} else {
|
|
|
|
if (priv->ohttimer[i]) {
|
|
|
|
priv->ohttimer[i]--;
|
|
|
|
if (!priv->ohttimer[i]) {
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, i,
|
|
|
|
"ohttimer expired\n");
|
|
|
|
priv->idletxhookstate[i] =
|
|
|
|
FXS_LINE_POL_ACTIVE;
|
2010-08-28 05:59:27 +08:00
|
|
|
oht_pcm(xpd, i, 0);
|
|
|
|
vmwi_search(xpd, i, 0);
|
2012-01-11 23:22:46 +08:00
|
|
|
if (priv->lasttxhook[i] ==
|
|
|
|
FXS_LINE_POL_OHTRANS) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Apply the change if appropriate */
|
2012-01-11 23:22:46 +08:00
|
|
|
linefeed_control(xpd->xbus, xpd,
|
|
|
|
i,
|
|
|
|
FXS_LINE_POL_ACTIVE);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Optimized memcmp() like function. Only test for equality (true/false).
|
|
|
|
* This optimization reduced the detect_vmwi() runtime by a factor of 3.
|
|
|
|
*/
|
|
|
|
static inline bool mem_equal(const char a[], const char b[], size_t len)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
if (a[i] != b[i])
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detect Voice Mail Waiting Indication
|
|
|
|
*/
|
|
|
|
static void detect_vmwi(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
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;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
ignore_mask =
|
2012-01-12 01:04:36 +08:00
|
|
|
PHONEDEV(xpd).offhook_state |
|
|
|
|
~(PHONEDEV(xpd).oht_pcm_pass) |
|
|
|
|
~(priv->search_fsk_pattern) |
|
|
|
|
PHONEDEV(xpd).digital_inputs |
|
|
|
|
PHONEDEV(xpd).digital_outputs;
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
struct dahdi_chan *chan = XPD_CHAN(xpd, i);
|
|
|
|
__u8 *writechunk = chan->writechunk;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_SET(ignore_mask, i))
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
|
|
|
#if 0
|
2012-01-11 23:20:05 +08:00
|
|
|
if (writechunk[0] != 0x7F && writechunk[0] != 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
int j;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-12 01:04:36 +08:00
|
|
|
LINE_DBG(GENERAL, xpd, i, "MSG:");
|
2012-01-11 23:20:05 +08:00
|
|
|
for (j = 0; j < DAHDI_CHUNKSIZE; j++) {
|
|
|
|
if (debug)
|
2010-08-28 05:59:27 +08:00
|
|
|
printk(" %02X", writechunk[j]);
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (debug)
|
2010-08-28 05:59:27 +08:00
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
#endif
|
2012-01-11 23:22:46 +08:00
|
|
|
if (unlikely
|
|
|
|
(mem_equal
|
|
|
|
(writechunk, FSK_COMMON_PATTERN, DAHDI_CHUNKSIZE))) {
|
|
|
|
LINE_DBG(SIGNAL, xpd, i,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Found common FSK pattern. "
|
|
|
|
"Start looking for ON/OFF patterns.\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
BIT_SET(priv->found_fsk_pattern, i);
|
2012-01-11 23:20:05 +08:00
|
|
|
} else if (unlikely(IS_SET(priv->found_fsk_pattern, i))) {
|
2010-08-28 05:59:27 +08:00
|
|
|
BIT_CLR(priv->found_fsk_pattern, i);
|
|
|
|
oht_pcm(xpd, i, 0);
|
2012-01-11 23:22:46 +08:00
|
|
|
if (unlikely
|
|
|
|
(mem_equal
|
|
|
|
(writechunk, FSK_ON_PATTERN, DAHDI_CHUNKSIZE))) {
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, i, "MSG WAITING ON\n");
|
2011-01-30 22:11:49 +08:00
|
|
|
PHONEDEV(xpd).msg_waiting[i] = 1;
|
2010-08-28 05:59:27 +08:00
|
|
|
start_stop_vm_led(xbus, xpd, i);
|
2012-01-11 23:22:46 +08:00
|
|
|
} else
|
|
|
|
if (unlikely
|
|
|
|
(mem_equal
|
|
|
|
(writechunk, FSK_OFF_PATTERN,
|
|
|
|
DAHDI_CHUNKSIZE))) {
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, i, "MSG WAITING OFF\n");
|
2011-01-30 22:11:49 +08:00
|
|
|
PHONEDEV(xpd).msg_waiting[i] = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
start_stop_vm_led(xbus, xpd, i);
|
|
|
|
} else {
|
2012-01-11 23:22:46 +08:00
|
|
|
int j;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
LINE_NOTICE(xpd, i, "MSG WAITING Unexpected:");
|
2012-01-13 01:14:15 +08:00
|
|
|
for (j = 0; j < DAHDI_CHUNKSIZE; j++)
|
2010-08-28 05:59:27 +08:00
|
|
|
printk(" %02X", writechunk[j]);
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXS_card_tick(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXS_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
#ifdef POLL_DIGITAL_INPUTS
|
2011-09-23 02:55:44 +08:00
|
|
|
if (poll_digital_inputs && PHONEDEV(xpd).digital_inputs) {
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((xpd->timer_count % poll_digital_inputs) == 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
poll_inputs(xpd);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
handle_fxs_leds(xpd);
|
|
|
|
handle_linefeed(xpd);
|
|
|
|
/*
|
|
|
|
* Hack alert (FIXME):
|
|
|
|
* Asterisk did FXS_card_open() and we wanted to report
|
|
|
|
* offhook state. However, the channel is spinlocked by dahdi
|
|
|
|
* so we marked it in the priv->update_offhook_state mask and
|
|
|
|
* now we take care of notification to dahdi and Asterisk
|
|
|
|
*/
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->update_offhook_state) {
|
2012-01-11 23:22:46 +08:00
|
|
|
enum dahdi_rxsig rxsig;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!IS_SET(priv->update_offhook_state, i))
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
2012-01-11 23:22:46 +08:00
|
|
|
rxsig =
|
|
|
|
IS_OFFHOOK(xpd,
|
|
|
|
i) ? DAHDI_RXSIG_OFFHOOK :
|
|
|
|
DAHDI_RXSIG_ONHOOK;
|
2012-01-12 03:56:35 +08:00
|
|
|
/* Notify after open() */
|
|
|
|
notify_rxsig(xpd, i, rxsig);
|
2010-08-28 05:59:27 +08:00
|
|
|
BIT_CLR(priv->update_offhook_state, i);
|
|
|
|
}
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (SPAN_REGISTERED(xpd)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
if (!vmwi_ioctl && priv->search_fsk_pattern)
|
|
|
|
detect_vmwi(xpd); /* Detect via FSK modulation */
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------- FXS: HOST COMMANDS -------------------------------------*/
|
|
|
|
|
|
|
|
/*---------------- FXS: Astribank Reply Handlers --------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Should be called with spinlocked XPD
|
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
static void process_hookstate(xpd_t *xpd, xpp_line_t offhook,
|
|
|
|
xpp_line_t change_mask)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus;
|
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
2011-01-30 22:11:49 +08:00
|
|
|
BUG_ON(PHONEDEV(xpd).direction != TO_PHONE);
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus = xpd->xbus;
|
|
|
|
priv = xpd->priv;
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_DBG(SIGNAL, xpd, "offhook=0x%X change_mask=0x%X\n", offhook,
|
|
|
|
change_mask);
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
if (IS_SET(PHONEDEV(xpd).digital_outputs, i)
|
|
|
|
|| IS_SET(PHONEDEV(xpd).digital_inputs, i))
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_SET(change_mask, i)) {
|
2012-01-11 23:22:46 +08:00
|
|
|
PHONEDEV(xpd).ringing[i] = 0; /* No more ringing... */
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef WITH_METERING
|
|
|
|
metering_gen(xpd, i, 0); /* Stop metering... */
|
|
|
|
#endif
|
|
|
|
MARK_BLINK(priv, i, LED_GREEN, 0);
|
|
|
|
/*
|
|
|
|
* Reset our previous DTMF memories...
|
|
|
|
*/
|
|
|
|
BIT_CLR(priv->prev_key_down, i);
|
2012-01-11 23:22:46 +08:00
|
|
|
priv->prev_key_time[i].tv_sec =
|
|
|
|
priv->prev_key_time[i].tv_usec = 0L;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_SET(offhook, i)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, i, "OFFHOOK\n");
|
|
|
|
MARK_ON(priv, i, LED_GREEN);
|
|
|
|
hookstate_changed(xpd, i, 1);
|
|
|
|
} else {
|
|
|
|
LINE_DBG(SIGNAL, xpd, i, "ONHOOK\n");
|
|
|
|
MARK_OFF(priv, i, LED_GREEN);
|
|
|
|
hookstate_changed(xpd, i, 0);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Must switch to low power. In high power, an ONHOOK
|
|
|
|
* won't be detected.
|
|
|
|
*/
|
|
|
|
do_chan_power(xbus, xpd, i, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLER_DEF(FXS, SIG_CHANGED)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
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;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
2011-01-30 22:11:49 +08:00
|
|
|
BUG_ON(PHONEDEV(xpd).direction != TO_PHONE);
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_DBG(SIGNAL, xpd, "(PHONE) sig_toggles=0x%04X sig_status=0x%04X\n",
|
|
|
|
sig_toggles, sig_status);
|
2010-08-28 05:59:27 +08:00
|
|
|
#if 0
|
2012-01-11 23:22:46 +08:00
|
|
|
Is this needed ? for_each_line(xpd, i) {
|
2012-01-12 03:56:35 +08:00
|
|
|
// Power down (prevent overheating!!!)
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_SET(sig_toggles, i))
|
2012-01-12 03:56:35 +08:00
|
|
|
do_chan_power(xpd->xbus, xpd, BIT(i), 0);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
spin_lock_irqsave(&xpd->lock, flags);
|
|
|
|
process_hookstate(xpd, sig_status, sig_toggles);
|
|
|
|
spin_unlock_irqrestore(&xpd->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef POLL_DIGITAL_INPUTS
|
|
|
|
static void process_digital_inputs(xpd_t *xpd, const reg_cmd_t *info)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int i;
|
|
|
|
bool offhook = (REG_FIELD(info, data_low) & 0x1) == 0;
|
|
|
|
xpp_line_t lines = BIT(info->portnum);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2011-09-23 02:55:44 +08:00
|
|
|
/* Sanity check */
|
|
|
|
if (!PHONEDEV(xpd).digital_inputs) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_NOTICE(xpd, "%s called without digital inputs. Ignored\n",
|
|
|
|
__func__);
|
2011-09-23 02:55:44 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Map SLIC number into line number */
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(input_channels); i++) {
|
2012-01-11 23:22:46 +08:00
|
|
|
int channo = input_channels[i];
|
|
|
|
int newchanno;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_SET(lines, channo)) {
|
2011-01-30 22:11:49 +08:00
|
|
|
newchanno = PHONEDEV(xpd).channels - LINES_DIGI_INP + i;
|
2010-08-28 05:59:27 +08:00
|
|
|
BIT_CLR(lines, channo);
|
|
|
|
BIT_SET(lines, newchanno);
|
2012-01-12 03:56:35 +08:00
|
|
|
/* Stop ringing. No leds for digital inputs. */
|
|
|
|
PHONEDEV(xpd).ringing[newchanno] = 0;
|
|
|
|
if (offhook && !IS_OFFHOOK(xpd, newchanno)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, newchanno, "OFFHOOK\n");
|
|
|
|
hookstate_changed(xpd, newchanno, 1);
|
2012-01-12 03:56:35 +08:00
|
|
|
} else if (!offhook && IS_OFFHOOK(xpd, newchanno)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, newchanno, "ONHOOK\n");
|
|
|
|
hookstate_changed(xpd, newchanno, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const char dtmf_digits[] = {
|
2011-09-28 01:10:48 +08:00
|
|
|
'D', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '*', '#',
|
|
|
|
'A', 'B', 'C'
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called with spinlocked XPD
|
|
|
|
*/
|
2012-01-11 23:21:54 +08:00
|
|
|
static void process_dtmf(xpd_t *xpd, uint portnum, __u8 val)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
__u8 digit;
|
|
|
|
bool key_down = val & 0x10;
|
|
|
|
bool want_mute;
|
|
|
|
bool want_event;
|
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
struct timeval now;
|
|
|
|
int msec = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!dtmf_detection)
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!SPAN_REGISTERED(xpd))
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
priv = xpd->priv;
|
|
|
|
val &= 0xF;
|
|
|
|
digit = dtmf_digits[val];
|
|
|
|
want_mute = IS_SET(priv->want_dtmf_mute, portnum);
|
|
|
|
want_event = IS_SET(priv->want_dtmf_events, portnum);
|
2012-01-13 01:14:15 +08:00
|
|
|
if (!IS_SET(priv->prev_key_down, portnum) && !key_down)
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_NOTICE(xpd, portnum, "DTMF: duplicate UP (%c)\n", digit);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (key_down)
|
2010-08-28 05:59:27 +08:00
|
|
|
BIT_SET(priv->prev_key_down, portnum);
|
|
|
|
else
|
|
|
|
BIT_CLR(priv->prev_key_down, portnum);
|
|
|
|
do_gettimeofday(&now);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->prev_key_time[portnum].tv_sec != 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
msec = usec_diff(&now, &priv->prev_key_time[portnum]) / 1000;
|
|
|
|
priv->prev_key_time[portnum] = now;
|
|
|
|
LINE_DBG(SIGNAL, xpd, portnum,
|
2012-01-12 03:56:35 +08:00
|
|
|
"[%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);
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* FIXME: we currently don't use the want_dtmf_mute until
|
|
|
|
* we are sure about the logic in Asterisk native bridging.
|
|
|
|
* Meanwhile, simply mute it on button press.
|
|
|
|
*/
|
2012-01-11 23:20:05 +08:00
|
|
|
if (key_down && want_mute)
|
2010-08-28 05:59:27 +08:00
|
|
|
__do_mute_dtmf(xpd, portnum, 1);
|
|
|
|
else
|
|
|
|
__do_mute_dtmf(xpd, portnum, 0);
|
2012-01-11 23:22:46 +08:00
|
|
|
if (want_event) {
|
|
|
|
int event =
|
|
|
|
(key_down) ? DAHDI_EVENT_DTMFDOWN : DAHDI_EVENT_DTMFUP;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
dahdi_qevent_lock(XPD_CHAN(xpd, portnum), event | digit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXS_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned long flags;
|
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
__u8 regnum;
|
|
|
|
bool indirect;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&xpd->lock, flags);
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
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",
|
2012-01-11 23:22:46 +08:00
|
|
|
(indirect) ? "I" : "D", regnum, REG_FIELD(info, data_low),
|
|
|
|
REG_FIELD(info, data_high));
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!indirect && regnum == REG_DTMF_DECODE) {
|
2012-01-11 23:22:46 +08:00
|
|
|
__u8 val = REG_FIELD(info, data_low);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
process_dtmf(xpd, info->portnum, val);
|
|
|
|
}
|
|
|
|
#ifdef POLL_DIGITAL_INPUTS
|
|
|
|
/*
|
|
|
|
* Process digital inputs polling results
|
|
|
|
*/
|
2012-01-13 01:14:15 +08:00
|
|
|
else if (!indirect && regnum == REG_DIGITAL_IOCTRL)
|
2010-08-28 05:59:27 +08:00
|
|
|
process_digital_inputs(xpd, info);
|
|
|
|
#endif
|
2012-01-11 23:20:05 +08:00
|
|
|
else if (!indirect && regnum == REG_LOOPCLOSURE) { /* OFFHOOK ? */
|
2012-01-11 23:22:46 +08:00
|
|
|
__u8 val = REG_FIELD(info, data_low);
|
|
|
|
xpp_line_t mask = BIT(info->portnum);
|
|
|
|
xpp_line_t offhook;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate reply. Non-existing/disabled ports
|
|
|
|
* will reply with 0xFF. Ignore these.
|
|
|
|
*/
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((val & REG_LOOPCLOSURE_ZERO) == 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
offhook = (val & REG_LOOPCLOSURE_LCR) ? mask : 0;
|
|
|
|
LINE_DBG(SIGNAL, xpd, info->portnum,
|
2012-01-12 03:56:35 +08:00
|
|
|
"REG_LOOPCLOSURE: dataL=0x%X "
|
|
|
|
"(offhook=0x%X mask=0x%X)\n",
|
|
|
|
val, offhook, mask);
|
2010-08-28 05:59:27 +08:00
|
|
|
process_hookstate(xpd, offhook, mask);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#if 0
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_NOTICE(xpd,
|
2012-01-12 03:56:35 +08:00
|
|
|
"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));
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
}
|
2012-01-12 03:56:35 +08:00
|
|
|
/*
|
|
|
|
* 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)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd->last_reply = *info;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&xpd->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-30 22:14:14 +08:00
|
|
|
static int FXS_card_state(xpd_t *xpd, bool on)
|
|
|
|
{
|
2011-01-31 02:31:35 +08:00
|
|
|
BUG_ON(!xpd);
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off");
|
2011-01-31 02:31:35 +08:00
|
|
|
return 0;
|
2011-01-30 22:14:14 +08:00
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
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,
|
2011-01-30 22:11:49 +08:00
|
|
|
};
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
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,
|
2011-01-30 22:11:49 +08:00
|
|
|
};
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
static xproto_table_t PROTO_TABLE(FXS) = {
|
2012-01-13 01:12:48 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.entries = {
|
2012-01-11 23:22:46 +08:00
|
|
|
/* Prototable Card Opcode */
|
2012-01-13 01:12:48 +08:00
|
|
|
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,
|
|
|
|
};
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static bool fxs_packet_is_valid(xpacket_t *pack)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
const xproto_entry_t *xe;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
// DBG(GENERAL, "\n");
|
|
|
|
xe = xproto_card_entry(&PROTO_TABLE(FXS), XPACKET_OP(pack));
|
|
|
|
return xe != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fxs_packet_dump(const char *msg, xpacket_t *pack)
|
|
|
|
{
|
|
|
|
DBG(GENERAL, "%s\n", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------- SLIC Handling --------------------------*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2012-01-11 23:22:46 +08:00
|
|
|
static int proc_fxs_info_read(char *page, char **start, off_t off, int count,
|
|
|
|
int *eof, void *data)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int len = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
xpd_t *xpd = data;
|
|
|
|
struct FXS_priv_data *priv;
|
|
|
|
int i;
|
|
|
|
int led;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd)
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENODEV;
|
|
|
|
spin_lock_irqsave(&xpd->lock, flags);
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
2012-03-15 20:53:07 +08:00
|
|
|
len += sprintf(page + len, "%-12s", "Channel:");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2012-03-15 20:53:07 +08:00
|
|
|
len += sprintf(page + len, "%4d", i);
|
|
|
|
}
|
|
|
|
len += sprintf(page + len, "\n%-12s", "");
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
char *chan_type;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_SET(PHONEDEV(xpd).digital_outputs, i))
|
2012-03-15 20:53:07 +08:00
|
|
|
chan_type = "out";
|
2012-01-11 23:20:05 +08:00
|
|
|
else if (IS_SET(PHONEDEV(xpd).digital_inputs, i))
|
2012-03-15 20:53:07 +08:00
|
|
|
chan_type = "in";
|
2010-08-28 05:59:27 +08:00
|
|
|
else
|
2012-03-15 20:53:07 +08:00
|
|
|
chan_type = "";
|
|
|
|
len += sprintf(page + len, "%4s", chan_type);
|
|
|
|
}
|
|
|
|
len += sprintf(page + len, "\n%-12s", "idletxhook:");
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
len += sprintf(page + len, "%4d", priv->idletxhookstate[i]);
|
|
|
|
}
|
|
|
|
len += sprintf(page + len, "\n%-12s", "lasttxhook:");
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
len += sprintf(page + len, "%4d", priv->lasttxhook[i]);
|
|
|
|
}
|
|
|
|
len += sprintf(page + len, "\n%-12s", "ohttimer:");
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
len += sprintf(page + len, "%4d", priv->ohttimer[i]);
|
|
|
|
}
|
|
|
|
len += sprintf(page + len, "\n%-12s", "neon_blink:");
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
len += sprintf(page + len, "%4d",
|
|
|
|
IS_SET(priv->neon_blinking, i));
|
|
|
|
}
|
|
|
|
len += sprintf(page + len, "\n%-12s", "search_fsk:");
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
len += sprintf(page + len, "%4d",
|
|
|
|
IS_SET(priv->search_fsk_pattern, i));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-03-15 20:52:32 +08:00
|
|
|
len += sprintf(page + len, "\n%-12s", "vbat_h:");
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
len += sprintf(page + len, "%4d",
|
2012-03-22 04:17:14 +08:00
|
|
|
test_bit(i, (unsigned long *)&priv->vbat_h));
|
2012-03-15 20:52:32 +08:00
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
len += sprintf(page + len, "\n");
|
2012-01-11 23:20:05 +08:00
|
|
|
for (led = 0; led < NUM_LEDS; led++) {
|
2012-03-15 20:53:07 +08:00
|
|
|
len += sprintf(page + len, "\nLED #%d\t%-12s: ",
|
|
|
|
led, "ledstate");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
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));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-03-15 20:53:07 +08:00
|
|
|
len += sprintf(page + len, "\nLED #%d\t%-12s: ",
|
|
|
|
led, "ledcontrol");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
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));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-03-15 20:53:07 +08:00
|
|
|
len += sprintf(page + len, "\nLED #%d\t%-12s: ",
|
|
|
|
led, "led_counter");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
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));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
}
|
2012-03-15 20:53:07 +08:00
|
|
|
len += sprintf(page + len, "\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_unlock_irqrestore(&xpd->lock, flags);
|
2012-01-11 23:22:46 +08:00
|
|
|
if (len <= off + count)
|
2010-08-28 05:59:27 +08:00
|
|
|
*eof = 1;
|
|
|
|
*start = page + off;
|
|
|
|
len -= off;
|
|
|
|
if (len > count)
|
|
|
|
len = count;
|
|
|
|
if (len < 0)
|
|
|
|
len = 0;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_METERING
|
2012-01-12 03:56:35 +08:00
|
|
|
static int proc_xpd_metering_write(struct file *file, const char
|
|
|
|
__user *buffer, unsigned long count, void *data)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd = data;
|
|
|
|
char buf[MAX_PROC_WRITE];
|
|
|
|
lineno_t chan;
|
|
|
|
int num;
|
|
|
|
int ret;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd)
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENODEV;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (count >= MAX_PROC_WRITE - 1) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Metering string too long (%lu)\n", count);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (copy_from_user(&buf, buffer, count))
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EFAULT;
|
|
|
|
buf[count] = '\0';
|
|
|
|
ret = sscanf(buf, "%d", &num);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret != 1) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "Metering value should be number. Got '%s'\n",
|
|
|
|
buf);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
chan = num;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (chan != PORT_BROADCAST && chan > xpd->channels) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Metering tone: bad channel number %d\n", chan);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((ret = metering_gen(xpd, chan, 1)) < 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_ERR(xpd, "Failed sending metering tone\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int fxs_xpd_probe(struct device *dev)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
xpd = dev_to_xpd(dev);
|
|
|
|
/* Is it our device? */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (xpd->type != XPD_TYPE_FXS) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "drop suggestion for %s (%d)\n", dev_name(dev),
|
|
|
|
xpd->type);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
XPD_DBG(DEVICES, xpd, "SYSFS\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fxs_xpd_remove(struct device *dev)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
xpd = dev_to_xpd(dev);
|
|
|
|
XPD_DBG(DEVICES, xpd, "SYSFS\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
static struct xpd_driver fxs_driver = {
|
|
|
|
.type = XPD_TYPE_FXS,
|
|
|
|
.driver = {
|
|
|
|
.name = "fxs",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.probe = fxs_xpd_probe,
|
|
|
|
.remove = fxs_xpd_remove}
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init card_fxs_startup(void)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((ret = xpd_driver_register(&fxs_driver.driver)) < 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
INFO("revision %s\n", XPP_VERSION);
|
|
|
|
#ifdef POLL_DIGITAL_INPUTS
|
|
|
|
INFO("FEATURE: with DIGITAL INPUTS support (polled every %d msec)\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
poll_digital_inputs);
|
2010-08-28 05:59:27 +08:00
|
|
|
#else
|
|
|
|
INFO("FEATURE: without DIGITAL INPUTS support\n");
|
|
|
|
#endif
|
|
|
|
INFO("FEATURE: DAHDI_VMWI (HVAC only)\n");
|
|
|
|
#ifdef WITH_METERING
|
|
|
|
INFO("FEATURE: WITH METERING Generation\n");
|
|
|
|
#else
|
|
|
|
INFO("FEATURE: NO METERING Generation\n");
|
|
|
|
#endif
|
|
|
|
xproto_register(&PROTO_TABLE(FXS));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit card_fxs_cleanup(void)
|
|
|
|
{
|
|
|
|
xproto_unregister(&PROTO_TABLE(FXS));
|
|
|
|
xpd_driver_unregister(&fxs_driver.driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("XPP FXS Card Driver");
|
|
|
|
MODULE_AUTHOR("Oron Peled <oron@actcom.co.il>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_VERSION(XPP_VERSION);
|
|
|
|
MODULE_ALIAS_XPD(XPD_TYPE_FXS);
|
|
|
|
|
|
|
|
module_init(card_fxs_startup);
|
|
|
|
module_exit(card_fxs_cleanup);
|