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>
|
2013-05-22 04:33:18 +08:00
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/seq_file.h>
|
2010-08-28 05:59:27 +08:00
|
|
|
#include "xpd.h"
|
|
|
|
#include "xproto.h"
|
|
|
|
#include "xpp_dahdi.h"
|
|
|
|
#include "card_fxo.h"
|
|
|
|
#include "dahdi_debug.h"
|
|
|
|
#include "xbus-core.h"
|
|
|
|
|
|
|
|
static const char rcsid[] = "$Id$";
|
|
|
|
|
|
|
|
static DEF_PARM(int, debug, 0, 0644, "Print DBG statements");
|
2012-01-11 23:22:46 +08:00
|
|
|
static DEF_PARM(uint, poll_battery_interval, 500, 0644,
|
|
|
|
"Poll battery interval in milliseconds (0 - disable)");
|
2013-03-01 00:40:28 +08:00
|
|
|
static DEF_PARM_BOOL(use_polrev_firmware, 1, 0444,
|
|
|
|
"Use firmware reports of polarity reversal");
|
2013-04-12 01:04:07 +08:00
|
|
|
static DEF_PARM_BOOL(squelch_polrev, 0, 0644,
|
|
|
|
"Never report polarity reversal");
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef WITH_METERING
|
2012-01-11 23:22:46 +08:00
|
|
|
static DEF_PARM(uint, poll_metering_interval, 500, 0644,
|
|
|
|
"Poll metering interval in milliseconds (0 - disable)");
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
2012-01-11 23:22:46 +08:00
|
|
|
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,
|
2013-03-14 23:01:32 +08:00
|
|
|
"Caller-Id detection style: "
|
|
|
|
"0 - [BELL], "
|
|
|
|
"1 - [ETSI_FSK], "
|
|
|
|
"2 - [ETSI_DTMF], "
|
|
|
|
"3 - [PASSTHROUGH]");
|
2012-01-11 23:22:46 +08:00
|
|
|
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");
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
enum cid_style {
|
2012-01-11 23:22:46 +08:00
|
|
|
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 */
|
2013-03-14 23:01:32 +08:00
|
|
|
CID_STYLE_PASSTHROUGH = 3, /* No change: Let asterisk */
|
|
|
|
/* (>= 1.8) DSP handle this */
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Signaling is opposite (fxs signalling for fxo card) */
|
|
|
|
#if 1
|
|
|
|
#define FXO_DEFAULT_SIGCAP (DAHDI_SIG_FXSKS | DAHDI_SIG_FXSLS)
|
|
|
|
#else
|
|
|
|
#define FXO_DEFAULT_SIGCAP (DAHDI_SIG_SF)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum fxo_leds {
|
|
|
|
LED_GREEN,
|
|
|
|
LED_RED,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NUM_LEDS 2
|
|
|
|
#define DELAY_UNTIL_DIALTONE 3000
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Minimum duration for polarity reversal detection (in ticks)
|
|
|
|
* Should be longer than the time to detect a ring, so voltage
|
|
|
|
* fluctuation during ring won't trigger false detection.
|
|
|
|
*/
|
|
|
|
#define POLREV_THRESHOLD 200
|
|
|
|
#define POWER_DENIAL_CURRENT 3
|
|
|
|
#define POWER_DENIAL_DELAY 2500 /* ticks */
|
|
|
|
|
|
|
|
/* Shortcuts */
|
|
|
|
#define DAA_WRITE 1
|
|
|
|
#define DAA_READ 0
|
2012-01-11 23:21:13 +08:00
|
|
|
#define DAA_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)
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*---------------- FXO Protocol Commands ----------------------------------*/
|
|
|
|
|
|
|
|
static bool fxo_packet_is_valid(xpacket_t *pack);
|
|
|
|
static void fxo_packet_dump(const char *msg, xpacket_t *pack);
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2013-05-22 04:33:18 +08:00
|
|
|
static const struct file_operations proc_fxo_info_ops;
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef WITH_METERING
|
2013-05-22 04:33:18 +08:00
|
|
|
static const struct file_operations proc_xpd_metering_ops;
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
static void dahdi_report_battery(xpd_t *xpd, lineno_t chan);
|
2013-04-12 01:03:22 +08:00
|
|
|
static void report_polarity_reversal(xpd_t *xpd, xportno_t portno, char *msg);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#define PROC_FXO_INFO_FNAME "fxo_info"
|
|
|
|
#ifdef WITH_METERING
|
|
|
|
#define PROC_METERING_FNAME "metering_read"
|
|
|
|
#endif
|
|
|
|
|
2013-03-01 00:40:28 +08:00
|
|
|
#define REG_INTERRUPT_SRC 0x04 /* 4 - Interrupt Source */
|
|
|
|
#define REG_INTERRUPT_SRC_POLI BIT(0) /* Polarity Reversal Detect Interrupt*/
|
|
|
|
#define REG_INTERRUPT_SRC_RING BIT(7) /* Ring Detect Interrupt */
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
#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 */
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#define DAA_REG_METERING 0x11 /* 17 */
|
|
|
|
#define DAA_REG_CURRENT 0x1C /* 28 */
|
|
|
|
#define DAA_REG_VBAT 0x1D /* 29 */
|
|
|
|
|
|
|
|
enum battery_state {
|
2012-01-11 23:22:46 +08:00
|
|
|
BATTERY_UNKNOWN = 0,
|
|
|
|
BATTERY_ON = 1,
|
|
|
|
BATTERY_OFF = -1
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum polarity_state {
|
2012-01-11 23:22:46 +08:00
|
|
|
POL_UNKNOWN = 0,
|
|
|
|
POL_POSITIVE = 1,
|
|
|
|
POL_NEGATIVE = -1
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum power_state {
|
2012-01-11 23:22:46 +08:00
|
|
|
POWER_UNKNOWN = 0,
|
|
|
|
POWER_ON = 1,
|
|
|
|
POWER_OFF = -1
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct FXO_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 *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];
|
2013-03-01 00:40:28 +08:00
|
|
|
int polarity_last_interval[CHANNELS_PERXPD];
|
|
|
|
#define POLARITY_LAST_INTERVAL_NONE (-1)
|
|
|
|
#define POLARITY_LAST_INTERVAL_MAX 40
|
2012-01-11 23:22:46 +08:00
|
|
|
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];
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef WITH_METERING
|
2012-01-11 23:22:46 +08:00
|
|
|
uint metering_count[CHANNELS_PERXPD];
|
|
|
|
xpp_line_t metering_tone_state;
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 */
|
|
|
|
|
|
|
|
/*---------------- FXO: Static functions ----------------------------------*/
|
|
|
|
|
|
|
|
static const char *power2str(enum power_state pw)
|
|
|
|
{
|
2012-01-11 23:20:05 +08:00
|
|
|
switch (pw) {
|
2012-01-11 23:22:46 +08:00
|
|
|
case POWER_UNKNOWN:
|
|
|
|
return "UNKNOWN";
|
|
|
|
case POWER_OFF:
|
|
|
|
return "OFF";
|
|
|
|
case POWER_ON:
|
|
|
|
return "ON";
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void power_change(xpd_t *xpd, int portno, enum power_state pw)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
priv = xpd->priv;
|
|
|
|
LINE_DBG(SIGNAL, xpd, portno, "power: %s -> %s\n",
|
2012-01-11 23:22:46 +08:00
|
|
|
power2str(priv->power[portno]), power2str(pw));
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->power[portno] = pw;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reset_battery_readings(xpd_t *xpd, lineno_t pos)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv = xpd->priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
priv->nobattery_debounce[pos] = 0;
|
|
|
|
priv->power_denial_delay[pos] = 0;
|
|
|
|
power_change(xpd, pos, POWER_UNKNOWN);
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
static const int led_register_mask[] = { BIT(7), BIT(6), BIT(5) };
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LED control is done via DAA register 0x20
|
|
|
|
*/
|
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 FXO_priv_data *priv;
|
|
|
|
xbus_t *xbus;
|
|
|
|
__u8 value;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
value = 0;
|
|
|
|
value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[which]);
|
|
|
|
value |= (on) ? BIT(0) : 0;
|
|
|
|
value |= (on) ? BIT(1) : 0;
|
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
|
|
|
ret = DAA_DIRECT_REQUEST(xbus, xpd, chan, DAA_WRITE, 0x20, value);
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_fxo_leds(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
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;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
spin_lock_irqsave(&xpd->lock, flags);
|
|
|
|
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, i)
|
|
|
|
|| IS_SET(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;
|
2010-08-28 05:59:27 +08:00
|
|
|
// 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], i)
|
|
|
|
&& !IS_SET(priv->ledstate[color], i)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
do_led(xpd, i, color, 1);
|
2012-01-11 23:22:46 +08:00
|
|
|
} else if (!IS_SET(priv->ledcontrol[color], i)
|
|
|
|
&& IS_SET(priv->ledstate[color], i)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
do_led(xpd, i, color, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&xpd->lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_dahdi_ring(xpd_t *xpd, int pos, bool on)
|
|
|
|
{
|
|
|
|
BUG_ON(!xpd);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (caller_id_style == CID_STYLE_BELL)
|
2010-08-28 05:59:27 +08:00
|
|
|
oht_pcm(xpd, pos, !on);
|
|
|
|
/*
|
|
|
|
* We should not spinlock before calling dahdi_hooksig() as
|
|
|
|
* it may call back into our xpp_hooksig() and cause
|
|
|
|
* a nested spinlock scenario
|
|
|
|
*/
|
|
|
|
notify_rxsig(xpd, pos, (on) ? DAHDI_RXSIG_RING : DAHDI_RXSIG_OFFHOOK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mark_ring(xpd_t *xpd, lineno_t pos, bool on, bool update_dahdi)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
atomic_set(&priv->ring_debounce[pos], 0); /* Stop debouncing */
|
|
|
|
/*
|
|
|
|
* We don't want to check battery during ringing
|
|
|
|
* due to voltage fluctuations.
|
|
|
|
*/
|
|
|
|
reset_battery_readings(xpd, pos);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (on && !PHONEDEV(xpd).ringing[pos]) {
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "START\n");
|
2011-01-30 22:11:49 +08:00
|
|
|
PHONEDEV(xpd).ringing[pos] = 1;
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->cidtimer[pos] = xpd->timer_count;
|
|
|
|
MARK_BLINK(priv, pos, LED_GREEN, LED_BLINK_RING);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (update_dahdi)
|
2010-08-28 05:59:27 +08:00
|
|
|
update_dahdi_ring(xpd, pos, on);
|
2012-01-11 23:20:05 +08:00
|
|
|
} else if (!on && PHONEDEV(xpd).ringing[pos]) {
|
2010-08-28 05:59:27 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "STOP\n");
|
2011-01-30 22:11:49 +08:00
|
|
|
PHONEDEV(xpd).ringing[pos] = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->cidtimer[pos] = xpd->timer_count;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_BLINKING(priv, pos, LED_GREEN))
|
2010-08-28 05:59:27 +08:00
|
|
|
MARK_BLINK(priv, pos, LED_GREEN, 0);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (update_dahdi)
|
2010-08-28 05:59:27 +08:00
|
|
|
update_dahdi_ring(xpd, pos, on);
|
2013-03-01 00:40:28 +08:00
|
|
|
priv->polarity_last_interval[pos] = POLARITY_LAST_INTERVAL_NONE;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_sethook(xpd_t *xpd, int pos, bool to_offhook)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned long flags;
|
|
|
|
xbus_t *xbus;
|
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
int ret = 0;
|
|
|
|
__u8 value;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
2012-01-12 03:56:35 +08:00
|
|
|
/* We can SETHOOK state only on PSTN */
|
|
|
|
BUG_ON(PHONEDEV(xpd).direction == TO_PHONE);
|
2010-08-28 05:59:27 +08:00
|
|
|
xbus = xpd->xbus;
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->battery[pos] != BATTERY_ON && to_offhook) {
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_NOTICE(xpd, pos,
|
|
|
|
"Cannot take offhook while battery is off!\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
spin_lock_irqsave(&xpd->lock, flags);
|
2012-01-11 23:22:46 +08:00
|
|
|
mark_ring(xpd, pos, 0, 0); // No more rings
|
|
|
|
value = REG_DAA_CONTROL1_ONHM; /* Bit 3 is for CID */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (to_offhook)
|
2010-08-28 05:59:27 +08:00
|
|
|
value |= REG_DAA_CONTROL1_OH;
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "SETHOOK: value=0x%02X %s\n", value,
|
|
|
|
(to_offhook) ? "OFFHOOK" : "ONHOOK");
|
2012-01-11 23:20:05 +08:00
|
|
|
if (to_offhook)
|
2010-08-28 05:59:27 +08:00
|
|
|
MARK_ON(priv, pos, LED_GREEN);
|
|
|
|
else
|
|
|
|
MARK_OFF(priv, pos, LED_GREEN);
|
2012-01-11 23:22:46 +08:00
|
|
|
ret =
|
|
|
|
DAA_DIRECT_REQUEST(xbus, xpd, pos, DAA_WRITE, REG_DAA_CONTROL1,
|
|
|
|
value);
|
2010-08-28 05:59:27 +08:00
|
|
|
mark_offhook(xpd, pos, to_offhook);
|
2013-03-14 23:01:32 +08:00
|
|
|
switch (caller_id_style) {
|
|
|
|
case CID_STYLE_ETSI_DTMF:
|
|
|
|
case CID_STYLE_PASSTHROUGH:
|
|
|
|
break;
|
|
|
|
default:
|
2010-08-28 05:59:27 +08:00
|
|
|
oht_pcm(xpd, pos, 0);
|
2013-03-14 23:01:32 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef WITH_METERING
|
|
|
|
priv->metering_count[pos] = 0;
|
|
|
|
priv->metering_tone_state = 0L;
|
|
|
|
DAA_DIRECT_REQUEST(xbus, xpd, pos, DAA_WRITE, DAA_REG_METERING, 0x2D);
|
|
|
|
#endif
|
2012-01-12 03:56:35 +08:00
|
|
|
/* unstable during hook changes */
|
|
|
|
reset_battery_readings(xpd, pos);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (to_offhook) {
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->power_denial_safezone[pos] = power_denial_safezone;
|
|
|
|
} else {
|
|
|
|
priv->power_denial_length[pos] = 0;
|
|
|
|
priv->power_denial_safezone[pos] = 0;
|
|
|
|
}
|
|
|
|
priv->cidtimer[pos] = xpd->timer_count;
|
|
|
|
spin_unlock_irqrestore(&xpd->lock, flags);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------- FXO: Methods -------------------------------------------*/
|
|
|
|
|
|
|
|
static void fxo_proc_remove(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
priv = xpd->priv;
|
|
|
|
XPD_DBG(PROC, xpd, "\n");
|
|
|
|
#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");
|
|
|
|
remove_proc_entry(PROC_METERING_FNAME, xpd->proc_xpd_dir);
|
|
|
|
priv->meteringfile = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->fxo_info) {
|
2010-08-28 05:59:27 +08:00
|
|
|
XPD_DBG(PROC, xpd, "Removing xpd FXO_INFO file\n");
|
|
|
|
remove_proc_entry(PROC_FXO_INFO_FNAME, xpd->proc_xpd_dir);
|
|
|
|
priv->fxo_info = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fxo_proc_create(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_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 FXO_INFO file\n");
|
2013-05-22 04:33:18 +08:00
|
|
|
priv->fxo_info = proc_create_data(PROC_FXO_INFO_FNAME, 0444,
|
|
|
|
xpd->proc_xpd_dir,
|
|
|
|
&proc_fxo_info_ops, xpd);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!priv->fxo_info) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "Failed to create proc file '%s'\n",
|
|
|
|
PROC_FXO_INFO_FNAME);
|
2010-08-28 05:59:27 +08:00
|
|
|
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");
|
2013-05-22 04:33:18 +08:00
|
|
|
priv->meteringfile = proc_create_data(PROC_METERING_FNAME, 0444,
|
|
|
|
xpd->proc_xpd_dir,
|
|
|
|
&proc_xpd_metering_ops, xpd);
|
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
|
|
|
fxo_proc_remove(xbus, xpd);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
SET_PROC_DIRENTRY_OWNER(priv->meteringfile);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
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)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd = NULL;
|
|
|
|
int channels;
|
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-12 03:56:35 +08:00
|
|
|
"XPD=%d%d: try to instanciate FXO 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
|
|
|
channels = min(2, subunit_ports);
|
|
|
|
else
|
|
|
|
channels = min(8, subunit_ports);
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd =
|
|
|
|
xpd_alloc(xbus, unit, subunit, subtype, subunits,
|
|
|
|
sizeof(struct FXO_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-01-30 22:11:49 +08:00
|
|
|
PHONEDEV(xpd).direction = TO_PSTN;
|
2010-08-28 05:59:27 +08:00
|
|
|
xpd->type_name = "FXO";
|
2012-01-11 23:20:05 +08:00
|
|
|
if (fxo_proc_create(xbus, xpd) < 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
goto err;
|
|
|
|
return xpd;
|
|
|
|
err:
|
|
|
|
xpd_free(xpd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXO_card_init(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
priv = xpd->priv;
|
|
|
|
// Hanghup all lines
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
do_sethook(xpd, i, 0);
|
2012-01-12 03:56:35 +08:00
|
|
|
/* will be updated on next battery sample */
|
|
|
|
priv->polarity[i] = POL_UNKNOWN;
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->polarity_debounce[i] = 0;
|
2012-01-12 03:56:35 +08:00
|
|
|
/* will be updated on next battery sample */
|
|
|
|
priv->battery[i] = BATTERY_UNKNOWN;
|
|
|
|
/* will be updated on next battery sample */
|
|
|
|
priv->power[i] = POWER_UNKNOWN;
|
2013-03-14 23:01:32 +08:00
|
|
|
switch (caller_id_style) {
|
|
|
|
case CID_STYLE_ETSI_DTMF:
|
|
|
|
case CID_STYLE_PASSTHROUGH:
|
2010-08-28 05:59:27 +08:00
|
|
|
oht_pcm(xpd, i, 1);
|
2013-03-14 23:01:32 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-03-01 00:40:28 +08:00
|
|
|
priv->polarity_last_interval[i] = POLARITY_LAST_INTERVAL_NONE;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
XPD_DBG(GENERAL, xpd, "done\n");
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
do_led(xpd, i, LED_GREEN, 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);
|
|
|
|
}
|
2011-01-30 22:14:14 +08:00
|
|
|
CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0);
|
2010-08-28 05:59:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXO_card_remove(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
XPD_DBG(GENERAL, xpd, "\n");
|
|
|
|
fxo_proc_remove(xbus, xpd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXO_card_dahdi_preregistration(xpd_t *xpd, bool on)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus;
|
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
int i;
|
|
|
|
unsigned int timer_count;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
xbus = xpd->xbus;
|
|
|
|
BUG_ON(!xbus);
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
timer_count = xpd->timer_count;
|
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_FXO;
|
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 FXO channel %d\n", i);
|
|
|
|
snprintf(cur_chan->name, MAX_CHANNAME, "XPP_FXO/%02d/%1d%1d/%d",
|
2012-01-11 23:22:46 +08:00
|
|
|
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 = FXO_DEFAULT_SIGCAP;
|
|
|
|
}
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
MARK_ON(priv, i, LED_GREEN);
|
|
|
|
msleep(4);
|
|
|
|
MARK_ON(priv, i, LED_RED);
|
|
|
|
}
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
priv->cidtimer[i] = timer_count;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXO_card_dahdi_postregistration(xpd_t *xpd, bool on)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xbus_t *xbus;
|
|
|
|
struct FXO_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) {
|
|
|
|
dahdi_report_battery(xpd, i);
|
|
|
|
MARK_OFF(priv, i, LED_GREEN);
|
|
|
|
msleep(2);
|
|
|
|
MARK_OFF(priv, i, LED_RED);
|
|
|
|
msleep(2);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-30 22:14:14 +08:00
|
|
|
static int FXO_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 FXO_priv_data *priv;
|
|
|
|
int ret = 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
LINE_DBG(SIGNAL, xpd, pos, "%s\n", txsig2str(txsig));
|
2011-01-30 22:11:49 +08:00
|
|
|
BUG_ON(PHONEDEV(xpd).direction != TO_PSTN);
|
2010-08-28 05:59:27 +08:00
|
|
|
/* XXX Enable hooksig for FXO XXX */
|
2012-01-11 23:20:05 +08:00
|
|
|
switch (txsig) {
|
2012-01-11 23:22:46 +08:00
|
|
|
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;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dahdi_report_battery(xpd_t *xpd, lineno_t chan)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_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 (SPAN_REGISTERED(xpd)) {
|
|
|
|
switch (priv->battery[chan]) {
|
2012-01-11 23:22:46 +08:00
|
|
|
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;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXO_card_open(xpd_t *xpd, lineno_t chan)
|
|
|
|
{
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void poll_battery(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
DAA_DIRECT_REQUEST(xbus, xpd, i, DAA_READ, DAA_REG_VBAT, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_METERING
|
|
|
|
static void poll_metering(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
for_each_line(xpd, i) {
|
|
|
|
if (IS_OFFHOOK(xpd, i))
|
2012-01-11 23:22:46 +08:00
|
|
|
DAA_DIRECT_REQUEST(xbus, xpd, i, DAA_READ,
|
|
|
|
DAA_REG_METERING, 0);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void handle_fxo_ring(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
priv = xpd->priv;
|
|
|
|
for_each_line(xpd, i) {
|
2013-04-12 01:03:22 +08:00
|
|
|
if (likely(use_polrev_firmware)) {
|
2013-03-01 00:40:28 +08:00
|
|
|
int *t = &priv->polarity_last_interval[i];
|
|
|
|
if (*t != POLARITY_LAST_INTERVAL_NONE) {
|
|
|
|
(*t)++;
|
|
|
|
if (*t > POLARITY_LAST_INTERVAL_MAX) {
|
|
|
|
LINE_DBG(SIGNAL, xpd, i,
|
|
|
|
"polrev(GOOD): %d msec\n", *t);
|
|
|
|
*t = POLARITY_LAST_INTERVAL_NONE;
|
2013-04-12 01:03:22 +08:00
|
|
|
report_polarity_reversal(xpd,
|
|
|
|
i, "firmware");
|
2013-03-01 00:40:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (atomic_read(&priv->ring_debounce[i]) > 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Maybe start ring */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (atomic_dec_and_test(&priv->ring_debounce[i]))
|
2010-08-28 05:59:27 +08:00
|
|
|
mark_ring(xpd, i, 1, 1);
|
|
|
|
} else if (atomic_read(&priv->ring_debounce[i]) < 0) {
|
|
|
|
/* Maybe stop ring */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (atomic_inc_and_test(&priv->ring_debounce[i]))
|
2010-08-28 05:59:27 +08:00
|
|
|
mark_ring(xpd, i, 0, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_fxo_power_denial(xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!power_denial_safezone)
|
2010-08-28 05:59:27 +08:00
|
|
|
return; /* Ignore power denials */
|
|
|
|
priv = xpd->priv;
|
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:20:05 +08:00
|
|
|
if (PHONEDEV(xpd).ringing[i] || !IS_OFFHOOK(xpd, i)) {
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->power_denial_delay[i] = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->power_denial_safezone[i] > 0) {
|
|
|
|
if (--priv->power_denial_safezone[i] == 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
2012-01-12 03:56:35 +08:00
|
|
|
* Poll current, prev answers are meaningless
|
2010-08-28 05:59:27 +08:00
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
DAA_DIRECT_REQUEST(xpd->xbus, xpd, i, DAA_READ,
|
|
|
|
DAA_REG_CURRENT, 0);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->power_denial_length[i] > 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->power_denial_length[i]--;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->power_denial_length[i] <= 0) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
2012-01-12 03:56:35 +08:00
|
|
|
* But maybe the FXS started to ring (and
|
|
|
|
* the firmware haven't detected it yet).
|
|
|
|
* This would cause false power denials so
|
|
|
|
* we just flag it and schedule more ticks
|
|
|
|
* to wait.
|
2010-08-28 05:59:27 +08:00
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, i,
|
|
|
|
"Possible Power Denial Hangup\n");
|
|
|
|
priv->power_denial_delay[i] =
|
|
|
|
POWER_DENIAL_DELAY;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (priv->power_denial_delay[i] > 0) {
|
|
|
|
/*
|
|
|
|
* Ring detection by the firmware takes some time.
|
|
|
|
* Therefore we delay our decision until we are
|
|
|
|
* sure that no ring has started during this time.
|
|
|
|
*/
|
|
|
|
priv->power_denial_delay[i]--;
|
|
|
|
if (priv->power_denial_delay[i] <= 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, i,
|
|
|
|
"Power Denial Hangup\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->power_denial_delay[i] = 0;
|
|
|
|
/*
|
|
|
|
* Let Asterisk decide what to do
|
|
|
|
*/
|
|
|
|
notify_rxsig(xpd, i, DAHDI_RXSIG_ONHOOK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For caller-id CID_STYLE_ETSI_DTMF:
|
|
|
|
* - No indication is passed before the CID
|
|
|
|
* - We try to detect it and send "fake" polarity reversal.
|
|
|
|
* - The chan_dahdi.conf should have cidstart=polarity
|
|
|
|
* - Based on an idea in http://bugs.digium.com/view.php?id=9096
|
|
|
|
*/
|
2012-01-11 23:16:34 +08:00
|
|
|
static void check_etsi_dtmf(xpd_t *xpd)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
int portno;
|
|
|
|
unsigned int timer_count;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!SPAN_REGISTERED(xpd))
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
timer_count = xpd->timer_count;
|
|
|
|
for_each_line(xpd, portno) {
|
|
|
|
/* Skip offhook and ringing ports */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_OFFHOOK(xpd, portno) || PHONEDEV(xpd).ringing[portno])
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_SET(priv->cidfound, portno)) {
|
|
|
|
if (timer_count > priv->cidtimer[portno] + 4000) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/* reset flags if it's been a while */
|
|
|
|
priv->cidtimer[portno] = timer_count;
|
|
|
|
BIT_CLR(priv->cidfound, portno);
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, portno,
|
|
|
|
"Reset CID flag\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if (timer_count > priv->cidtimer[portno] + 400) {
|
2012-01-11 23:22:46 +08:00
|
|
|
struct dahdi_chan *chan = XPD_CHAN(xpd, portno);
|
|
|
|
int sample;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
for (i = 0; i < DAHDI_CHUNKSIZE; i++) {
|
2010-08-28 05:59:27 +08:00
|
|
|
sample = DAHDI_XLAW(chan->readchunk[i], chan);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (sample > 16000 || sample < -16000) {
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->cidtimer[portno] = timer_count;
|
|
|
|
BIT_SET(priv->cidfound, portno);
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, portno,
|
2013-04-12 01:03:22 +08:00
|
|
|
"Found DTMF CLIP (%d)\n", i);
|
|
|
|
report_polarity_reversal(xpd, portno,
|
|
|
|
"fake");
|
2010-08-28 05:59:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int FXO_card_tick(xbus_t *xbus, xpd_t *xpd)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
2012-01-11 23:22:46 +08:00
|
|
|
if (poll_battery_interval != 0
|
|
|
|
&& (priv->poll_counter % poll_battery_interval) == 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
poll_battery(xbus, xpd);
|
|
|
|
#ifdef WITH_METERING
|
2012-01-11 23:22:46 +08:00
|
|
|
if (poll_metering_interval != 0
|
|
|
|
&& (priv->poll_counter % poll_metering_interval) == 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
poll_metering(xbus, xpd);
|
|
|
|
#endif
|
|
|
|
handle_fxo_leds(xpd);
|
|
|
|
handle_fxo_ring(xpd);
|
|
|
|
handle_fxo_power_denial(xpd);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (caller_id_style == CID_STYLE_ETSI_DTMF && likely(xpd->card_present))
|
2010-08-28 05:59:27 +08:00
|
|
|
check_etsi_dtmf(xpd);
|
|
|
|
priv->poll_counter++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <dahdi/wctdm_user.h>
|
|
|
|
/*
|
|
|
|
* The first register is the ACIM, the other are coefficient registers.
|
|
|
|
* We define the array size explicitly to track possible inconsistencies
|
|
|
|
* if the struct is modified.
|
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
static const char echotune_regs[sizeof(struct wctdm_echo_coefs)] =
|
|
|
|
{ 30, 45, 46, 47, 48, 49, 50, 51, 52 };
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
static int FXO_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
|
|
|
int i, ret;
|
|
|
|
unsigned char echotune_data[ARRAY_SIZE(echotune_regs)];
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!XBUS_IS(xpd->xbus, READY))
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENODEV;
|
|
|
|
switch (cmd) {
|
2012-01-11 23:22:46 +08:00
|
|
|
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,
|
2012-01-12 03:56:35 +08:00
|
|
|
"Couldn't write %0x02X to "
|
|
|
|
"register %0x02X\n",
|
|
|
|
echotune_data[i], echotune_regs[i]);
|
2012-01-11 23:22:46 +08:00
|
|
|
return ret;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2012-01-11 23:22:46 +08:00
|
|
|
msleep(1);
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
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;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------- FXO: HOST COMMANDS -------------------------------------*/
|
|
|
|
|
|
|
|
/*---------------- FXO: Astribank Reply Handlers --------------------------*/
|
|
|
|
|
|
|
|
HANDLER_DEF(FXO, SIG_CHANGED)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
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;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd) {
|
2012-01-11 23:17:09 +08:00
|
|
|
notify_bad_xpd(__func__, xbus, XPACKET_ADDR(pack), cmd->name);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EPROTO;
|
|
|
|
}
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_DBG(SIGNAL, xpd, "(PSTN) sig_toggles=0x%04X sig_status=0x%04X\n",
|
|
|
|
sig_toggles, sig_status);
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_lock_irqsave(&xpd->lock, flags);
|
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
int debounce;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (IS_SET(sig_toggles, i)) {
|
|
|
|
if (priv->battery[i] == BATTERY_OFF) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
2012-01-12 03:56:35 +08:00
|
|
|
* With poll_battery_interval==0 we cannot
|
|
|
|
* have BATTERY_OFF so we won't get here
|
2010-08-28 05:59:27 +08:00
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_NOTICE(xpd, i,
|
2012-01-12 03:56:35 +08:00
|
|
|
"SIG_CHANGED while battery is off. "
|
|
|
|
"Ignored.\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* First report false ring alarms */
|
|
|
|
debounce = atomic_read(&priv->ring_debounce[i]);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (debounce)
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_NOTICE(xpd, i,
|
2012-01-26 06:02:08 +08:00
|
|
|
"Ignored a false short ring "
|
|
|
|
"(lasted only %dms)\n",
|
|
|
|
ring_debounce - debounce);
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Now set a new ring alarm.
|
|
|
|
* It will be checked in handle_fxo_ring()
|
|
|
|
*/
|
2012-01-11 23:22:46 +08:00
|
|
|
debounce =
|
|
|
|
(IS_SET(sig_status, i)) ? ring_debounce :
|
|
|
|
-ring_debounce;
|
2010-08-28 05:59:27 +08:00
|
|
|
atomic_set(&priv->ring_debounce[i], debounce);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&xpd->lock, flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-12 01:03:22 +08:00
|
|
|
static void report_polarity_reversal(xpd_t *xpd, xportno_t portno, char *msg)
|
2013-03-01 00:40:28 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Inform dahdi/Asterisk:
|
|
|
|
* 1. Maybe used for hangup detection during offhook
|
|
|
|
* 2. In some countries used to report caller-id
|
|
|
|
* during onhook but before first ring.
|
|
|
|
*/
|
|
|
|
if (caller_id_style == CID_STYLE_ETSI_FSK)
|
|
|
|
/* will be cleared on ring/offhook */
|
|
|
|
oht_pcm(xpd, portno, 1);
|
|
|
|
if (SPAN_REGISTERED(xpd)) {
|
2013-04-12 01:03:22 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, portno,
|
2013-04-12 01:04:07 +08:00
|
|
|
"%s DAHDI_EVENT_POLARITY (%s)\n",
|
|
|
|
(squelch_polrev) ? "Squelch" : "Send",
|
|
|
|
msg);
|
|
|
|
if (!squelch_polrev)
|
|
|
|
dahdi_qevent_lock(XPD_CHAN(xpd, portno),
|
|
|
|
DAHDI_EVENT_POLARITY);
|
2013-03-01 00:40:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
static void update_battery_voltage(xpd_t *xpd, __u8 data_low,
|
|
|
|
xportno_t portno)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
enum polarity_state pol;
|
|
|
|
int msec;
|
|
|
|
signed char volts = (signed char)data_low;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
priv->battery_voltage[portno] = volts;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (PHONEDEV(xpd).ringing[portno])
|
2010-08-28 05:59:27 +08:00
|
|
|
goto ignore_reading; /* ring voltage create false alarms */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (abs(volts) < battery_threshold) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Check for battery voltage fluctuations
|
|
|
|
*/
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->battery[portno] != BATTERY_OFF) {
|
2012-01-11 23:22:46 +08:00
|
|
|
int milliseconds;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
milliseconds =
|
|
|
|
priv->nobattery_debounce[portno]++ *
|
|
|
|
poll_battery_interval;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (milliseconds > battery_debounce) {
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, portno,
|
|
|
|
"BATTERY OFF voltage=%d\n", volts);
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->battery[portno] = BATTERY_OFF;
|
|
|
|
dahdi_report_battery(xpd, portno);
|
|
|
|
/* What's the polarity ? */
|
|
|
|
priv->polarity[portno] = POL_UNKNOWN;
|
|
|
|
priv->polarity_debounce[portno] = 0;
|
|
|
|
/* What's the current ? */
|
|
|
|
power_change(xpd, portno, POWER_UNKNOWN);
|
|
|
|
/*
|
|
|
|
* Stop further processing for now
|
|
|
|
*/
|
|
|
|
goto ignore_reading;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
priv->nobattery_debounce[portno] = 0;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->battery[portno] != BATTERY_ON) {
|
2012-01-11 23:22:46 +08:00
|
|
|
LINE_DBG(SIGNAL, xpd, portno, "BATTERY ON voltage=%d\n",
|
|
|
|
volts);
|
2010-08-28 05:59:27 +08:00
|
|
|
priv->battery[portno] = BATTERY_ON;
|
|
|
|
dahdi_report_battery(xpd, portno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Mark FXO ports without battery!
|
|
|
|
*/
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->battery[portno] != BATTERY_ON)
|
2010-08-28 05:59:27 +08:00
|
|
|
MARK_ON(priv, portno, LED_RED);
|
|
|
|
else
|
|
|
|
MARK_OFF(priv, portno, LED_RED);
|
|
|
|
#endif
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->battery[portno] != BATTERY_ON) {
|
2012-01-12 03:56:35 +08:00
|
|
|
/* What's the polarity ? */
|
|
|
|
priv->polarity[portno] = POL_UNKNOWN;
|
2010-08-28 05:59:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Handle reverse polarity
|
|
|
|
*/
|
2012-01-11 23:20:05 +08:00
|
|
|
if (volts == 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
pol = POL_UNKNOWN;
|
2012-01-11 23:20:05 +08:00
|
|
|
else if (volts < 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
pol = POL_NEGATIVE;
|
|
|
|
else
|
|
|
|
pol = POL_POSITIVE;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->polarity[portno] == pol) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/*
|
|
|
|
* Same polarity, reset debounce counter
|
|
|
|
*/
|
|
|
|
priv->polarity_debounce[portno] = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Track polarity reversals and debounce spikes.
|
|
|
|
* Only reversals with long duration count.
|
|
|
|
*/
|
|
|
|
msec = priv->polarity_debounce[portno]++ * poll_battery_interval;
|
|
|
|
if (msec >= POLREV_THRESHOLD) {
|
|
|
|
priv->polarity_debounce[portno] = 0;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (pol != POL_UNKNOWN && priv->polarity[portno] != POL_UNKNOWN) {
|
2012-01-11 23:22:46 +08:00
|
|
|
char *polname = NULL;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (pol == POL_POSITIVE)
|
2010-08-28 05:59:27 +08:00
|
|
|
polname = "Positive";
|
2012-01-11 23:20:05 +08:00
|
|
|
else if (pol == POL_NEGATIVE)
|
2010-08-28 05:59:27 +08:00
|
|
|
polname = "Negative";
|
|
|
|
else
|
|
|
|
BUG();
|
|
|
|
LINE_DBG(SIGNAL, xpd, portno,
|
2012-01-11 23:22:46 +08:00
|
|
|
"Polarity changed to %s\n", polname);
|
2013-03-01 00:40:28 +08:00
|
|
|
if (!use_polrev_firmware)
|
2013-04-12 01:03:22 +08:00
|
|
|
report_polarity_reversal(xpd, portno, polname);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
priv->polarity[portno] = pol;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
ignore_reading:
|
|
|
|
/*
|
|
|
|
* Reset debounce counters to prevent false alarms
|
|
|
|
*/
|
2012-01-12 03:56:35 +08:00
|
|
|
/* unstable during hook changes */
|
|
|
|
reset_battery_readings(xpd, portno);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
|
2012-01-12 03:56:35 +08:00
|
|
|
static void update_battery_current(xpd_t *xpd, __u8 data_low,
|
|
|
|
xportno_t portno)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
priv->battery_current[portno] = data_low;
|
|
|
|
/*
|
|
|
|
* During ringing, current is not stable.
|
|
|
|
* During onhook there should not be current anyway.
|
|
|
|
*/
|
2012-01-11 23:20:05 +08:00
|
|
|
if (PHONEDEV(xpd).ringing[portno] || !IS_OFFHOOK(xpd, portno))
|
2010-08-28 05:59:27 +08:00
|
|
|
goto ignore_it;
|
|
|
|
/*
|
|
|
|
* Power denial with no battery voltage is meaningless
|
|
|
|
*/
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->battery[portno] != BATTERY_ON)
|
2010-08-28 05:59:27 +08:00
|
|
|
goto ignore_it;
|
|
|
|
/* Safe zone after offhook */
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->power_denial_safezone[portno] > 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
goto ignore_it;
|
2012-01-11 23:20:05 +08:00
|
|
|
if (data_low < POWER_DENIAL_CURRENT) {
|
|
|
|
if (priv->power[portno] == POWER_ON) {
|
2010-08-28 05:59:27 +08:00
|
|
|
power_change(xpd, portno, POWER_OFF);
|
|
|
|
priv->power_denial_length[portno] = power_denial_minlen;
|
|
|
|
}
|
|
|
|
} else {
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->power[portno] != POWER_ON) {
|
2010-08-28 05:59:27 +08:00
|
|
|
power_change(xpd, portno, POWER_ON);
|
|
|
|
priv->power_denial_length[portno] = 0;
|
|
|
|
/* We are now OFFHOOK */
|
|
|
|
hookstate_changed(xpd, portno, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
ignore_it:
|
|
|
|
priv->power_denial_delay[portno] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_METERING
|
|
|
|
#define BTD_BIT BIT(0)
|
|
|
|
|
2012-01-11 23:21:54 +08:00
|
|
|
static void update_metering_state(xpd_t *xpd, __u8 data_low, lineno_t portno)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
bool metering_tone = data_low & BTD_BIT;
|
|
|
|
bool old_metering_tone;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
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",
|
2012-01-11 23:22:46 +08:00
|
|
|
(metering_tone) ? "ON" : "OFF", data_low,
|
|
|
|
priv->metering_count[portno]);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (metering_tone && !old_metering_tone) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Rising edge */
|
|
|
|
priv->metering_count[portno]++;
|
|
|
|
BIT_SET(priv->metering_tone_state, portno);
|
2012-01-11 23:20:05 +08:00
|
|
|
} else if (!metering_tone && old_metering_tone)
|
2010-08-28 05:59:27 +08:00
|
|
|
BIT_CLR(priv->metering_tone_state, portno);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (metering_tone) {
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Clear the BTD bit */
|
|
|
|
data_low &= ~BTD_BIT;
|
2012-01-11 23:22:46 +08:00
|
|
|
DAA_DIRECT_REQUEST(xpd->xbus, xpd, portno, DAA_WRITE,
|
|
|
|
DAA_REG_METERING, data_low);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-01 00:40:28 +08:00
|
|
|
static void got_chip_interrupt(xpd_t *xpd, __u8 data_low,
|
|
|
|
xportno_t portno)
|
|
|
|
{
|
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
int t;
|
|
|
|
|
|
|
|
if (!use_polrev_firmware)
|
|
|
|
return;
|
|
|
|
priv = xpd->priv;
|
|
|
|
LINE_DBG(SIGNAL, xpd, portno, "mask=0x%X\n", data_low);
|
|
|
|
if (!(data_low & REG_INTERRUPT_SRC_POLI))
|
|
|
|
return;
|
|
|
|
t = priv->polarity_last_interval[portno];
|
|
|
|
if (PHONEDEV(xpd).ringing[portno]) {
|
|
|
|
priv->polarity_last_interval[portno] =
|
|
|
|
POLARITY_LAST_INTERVAL_NONE;
|
|
|
|
LINE_DBG(SIGNAL, xpd, portno,
|
|
|
|
"polrev(false): %d msec (while ringing)\n", t);
|
|
|
|
} else if (data_low & REG_INTERRUPT_SRC_RING) {
|
|
|
|
priv->polarity_last_interval[portno] =
|
|
|
|
POLARITY_LAST_INTERVAL_NONE;
|
|
|
|
LINE_DBG(SIGNAL, xpd, portno,
|
|
|
|
"polrev(false): %d msec (with chip-interrupt ring)\n",
|
|
|
|
t);
|
|
|
|
} else if (t == POLARITY_LAST_INTERVAL_NONE) {
|
|
|
|
priv->polarity_last_interval[portno] = 0;
|
|
|
|
LINE_DBG(SIGNAL, xpd, portno,
|
|
|
|
"polrev(start)\n");
|
|
|
|
} else if (t < POLARITY_LAST_INTERVAL_MAX) {
|
|
|
|
/*
|
|
|
|
* Start counting upward from -POLARITY_LAST_INTERVAL_MAX
|
|
|
|
* Until we reach POLARITY_LAST_INTERVAL_NONE.
|
|
|
|
* This way we filter bursts of false reports we get
|
|
|
|
* during ringing.
|
|
|
|
*/
|
|
|
|
priv->polarity_last_interval[portno] =
|
|
|
|
POLARITY_LAST_INTERVAL_NONE -
|
|
|
|
POLARITY_LAST_INTERVAL_MAX;
|
|
|
|
LINE_DBG(SIGNAL, xpd, portno,
|
|
|
|
"polrev(false): %d msec (interval shorter than %d)\n",
|
|
|
|
t, POLARITY_LAST_INTERVAL_MAX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-28 05:59:27 +08:00
|
|
|
static int FXO_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
lineno_t portno;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
2015-11-17 04:42:21 +08:00
|
|
|
portno = info->h.portnum;
|
2012-01-11 23:20:05 +08:00
|
|
|
switch (REG_FIELD(info, regnum)) {
|
2013-03-01 00:40:28 +08:00
|
|
|
case REG_INTERRUPT_SRC:
|
|
|
|
got_chip_interrupt(xpd, REG_FIELD(info, data_low), portno);
|
|
|
|
break;
|
2012-01-11 23:22:46 +08:00
|
|
|
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;
|
2010-08-28 05:59:27 +08:00
|
|
|
#ifdef WITH_METERING
|
2012-01-11 23:22:46 +08:00
|
|
|
case DAA_REG_METERING:
|
|
|
|
update_metering_state(xpd, REG_FIELD(info, data_low), portno);
|
|
|
|
break;
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
LINE_DBG(REGS, xpd, portno, "%c reg_num=0x%X, dataL=0x%X dataH=0x%X\n",
|
2015-11-17 04:42:21 +08:00
|
|
|
((info->h.bytes == 3) ? 'I' : 'D'), REG_FIELD(info, regnum),
|
2012-01-11 23:22:46 +08:00
|
|
|
REG_FIELD(info, data_low), REG_FIELD(info, data_high));
|
2010-08-28 05:59:27 +08:00
|
|
|
/* Update /proc info only if reply relate to the last slic read request */
|
2012-01-12 03:56:35 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-30 22:14:14 +08:00
|
|
|
static int FXO_card_state(xpd_t *xpd, bool on)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
int ret = 0;
|
|
|
|
struct FXO_priv_data *priv;
|
2011-01-31 02:31:35 +08:00
|
|
|
|
|
|
|
BUG_ON(!xpd);
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off");
|
|
|
|
return ret;
|
2011-01-30 22:14:14 +08:00
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
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,
|
2011-01-30 22:11:49 +08:00
|
|
|
};
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
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,
|
2011-01-30 22:11:49 +08:00
|
|
|
};
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static xproto_table_t PROTO_TABLE(FXO) = {
|
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( 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,
|
|
|
|
};
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static bool fxo_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(FXO), XPACKET_OP(pack));
|
|
|
|
return xe != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fxo_packet_dump(const char *msg, xpacket_t *pack)
|
|
|
|
{
|
|
|
|
DBG(GENERAL, "%s\n", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------- DAA Handling --------------------------*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2013-05-22 04:33:18 +08:00
|
|
|
static int proc_fxo_info_show(struct seq_file *sfile, void *not_used)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned long flags;
|
2013-05-22 04:33:18 +08:00
|
|
|
xpd_t *xpd = sfile->private;
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
int i;
|
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);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\t%-17s: ", "Channel");
|
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)
|
2013-05-22 04:33:18 +08:00
|
|
|
&& !IS_SET(PHONEDEV(xpd).digital_inputs, i)) {
|
|
|
|
seq_printf(sfile, "%4d ", i % 10);
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\nLeds:");
|
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "state");
|
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)
|
2013-05-22 04:33:18 +08:00
|
|
|
&& !IS_SET(PHONEDEV(xpd).digital_inputs, i)) {
|
|
|
|
seq_printf(sfile, " %d%d ",
|
|
|
|
IS_SET(priv->ledstate[LED_GREEN], i),
|
|
|
|
IS_SET(priv->ledstate[LED_RED], i));
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "blinking");
|
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)
|
2013-05-22 04:33:18 +08:00
|
|
|
&& !IS_SET(PHONEDEV(xpd).digital_inputs, i)) {
|
|
|
|
seq_printf(sfile, " %d%d ",
|
|
|
|
IS_BLINKING(priv, i, LED_GREEN),
|
|
|
|
IS_BLINKING(priv, i, LED_RED));
|
|
|
|
}
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\nBattery-Data:");
|
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "voltage");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%4d ", priv->battery_voltage[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "current");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%4d ", priv->battery_current[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\nBattery:");
|
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "on");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
char *bat;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->battery[i] == BATTERY_ON)
|
2010-08-28 05:59:27 +08:00
|
|
|
bat = "+";
|
2012-01-11 23:20:05 +08:00
|
|
|
else if (priv->battery[i] == BATTERY_OFF)
|
2010-08-28 05:59:27 +08:00
|
|
|
bat = "-";
|
|
|
|
else
|
|
|
|
bat = ".";
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%4s ", bat);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "debounce");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%4d ", priv->nobattery_debounce[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\nPolarity-Reverse:");
|
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "polarity");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
char *polname;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->polarity[i] == POL_POSITIVE)
|
2010-08-28 05:59:27 +08:00
|
|
|
polname = "+";
|
2012-01-11 23:20:05 +08:00
|
|
|
else if (priv->polarity[i] == POL_NEGATIVE)
|
2010-08-28 05:59:27 +08:00
|
|
|
polname = "-";
|
|
|
|
else
|
|
|
|
polname = ".";
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%4s ", polname);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "debounce");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%4d ", priv->polarity_debounce[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\nPower-Denial:");
|
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "power");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
char *curr;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->power[i] == POWER_ON)
|
2010-08-28 05:59:27 +08:00
|
|
|
curr = "+";
|
2012-01-11 23:20:05 +08:00
|
|
|
else if (priv->power[i] == POWER_OFF)
|
2010-08-28 05:59:27 +08:00
|
|
|
curr = "-";
|
|
|
|
else
|
|
|
|
curr = ".";
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%4s ", curr);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "safezone");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%4d ", priv->power_denial_safezone[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "delay");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%4d ", priv->power_denial_delay[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
#ifdef WITH_METERING
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\nMetering:");
|
|
|
|
seq_printf(sfile, "\n\t%-17s: ", "count");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%4d ", priv->metering_count[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
#endif
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
spin_unlock_irqrestore(&xpd->lock, flags);
|
2013-05-22 04:33:18 +08:00
|
|
|
return 0;
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
|
|
|
|
static int proc_fxo_info_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, proc_fxo_info_show, PDE_DATA(inode));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations proc_fxo_info_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = proc_fxo_info_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
#ifdef WITH_METERING
|
2013-05-22 04:33:18 +08:00
|
|
|
static int proc_xpd_metering_show(struct seq_file *sfile, void *not_used)
|
2010-08-28 05:59:27 +08:00
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
unsigned long flags;
|
2013-05-22 04:33:18 +08:00
|
|
|
xpd_t *xpd = sfile->private;
|
2012-01-11 23:22:46 +08:00
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
int i;
|
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;
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
spin_lock_irqsave(&xpd->lock, flags);
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "# Chan\tMeter (since last read)\n");
|
2010-08-28 05:59:27 +08:00
|
|
|
for_each_line(xpd, i) {
|
2013-05-22 04:33:18 +08:00
|
|
|
seq_printf(sfile, "%d\t%d\n", i, priv->metering_count[i]);
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&xpd->lock, flags);
|
|
|
|
/* Zero meters */
|
|
|
|
for_each_line(xpd, i)
|
2012-01-11 23:22:46 +08:00
|
|
|
priv->metering_count[i] = 0;
|
2013-05-22 04:33:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int proc_xpd_metering_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, proc_xpd_metering_show, PDE_DATA(inode));
|
2010-08-28 05:59:27 +08:00
|
|
|
}
|
2013-05-22 04:33:18 +08:00
|
|
|
|
|
|
|
static const struct file_operations proc_xpd_metering_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = proc_xpd_metering_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2010-08-28 05:59:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static DEVICE_ATTR_READER(fxo_battery_show, dev, buf)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd;
|
|
|
|
struct FXO_priv_data *priv;
|
|
|
|
unsigned long flags;
|
|
|
|
int len = 0;
|
|
|
|
int i;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
BUG_ON(!dev);
|
|
|
|
xpd = dev_to_xpd(dev);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (!xpd)
|
2010-08-28 05:59:27 +08:00
|
|
|
return -ENODEV;
|
|
|
|
priv = xpd->priv;
|
|
|
|
BUG_ON(!priv);
|
|
|
|
spin_lock_irqsave(&xpd->lock, flags);
|
|
|
|
for_each_line(xpd, i) {
|
2012-01-11 23:22:46 +08:00
|
|
|
char bat;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
2012-01-11 23:20:05 +08:00
|
|
|
if (priv->battery[i] == BATTERY_ON)
|
2010-08-28 05:59:27 +08:00
|
|
|
bat = '+';
|
2012-01-11 23:20:05 +08:00
|
|
|
else if (priv->battery[i] == BATTERY_OFF)
|
2010-08-28 05:59:27 +08:00
|
|
|
bat = '-';
|
|
|
|
else
|
|
|
|
bat = '.';
|
|
|
|
len += sprintf(buf + len, "%c ", bat);
|
|
|
|
}
|
|
|
|
len += sprintf(buf + len, "\n");
|
|
|
|
spin_unlock_irqrestore(&xpd->lock, flags);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
static DEVICE_ATTR(fxo_battery, S_IRUGO, fxo_battery_show, NULL);
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
static int fxo_xpd_probe(struct device *dev)
|
|
|
|
{
|
2012-01-11 23:22:46 +08:00
|
|
|
xpd_t *xpd;
|
|
|
|
int ret;
|
2010-08-28 05:59:27 +08:00
|
|
|
|
|
|
|
xpd = dev_to_xpd(dev);
|
|
|
|
/* Is it our device? */
|
2015-11-17 04:42:21 +08:00
|
|
|
if (xpd->xpd_type != XPD_TYPE_FXO) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "drop suggestion for %s (%d)\n", dev_name(dev),
|
2015-11-17 04:42:21 +08:00
|
|
|
xpd->xpd_type);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
XPD_DBG(DEVICES, xpd, "SYSFS\n");
|
|
|
|
ret = device_create_file(dev, &dev_attr_fxo_battery);
|
2012-01-11 23:20:05 +08:00
|
|
|
if (ret) {
|
2012-01-11 23:22:46 +08:00
|
|
|
XPD_ERR(xpd, "%s: device_create_file(fxo_battery) failed: %d\n",
|
|
|
|
__func__, ret);
|
2010-08-28 05:59:27 +08:00
|
|
|
goto fail_fxo_battery;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
fail_fxo_battery:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fxo_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");
|
|
|
|
device_remove_file(dev, &dev_attr_fxo_battery);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-11 23:22:46 +08:00
|
|
|
static struct xpd_driver fxo_driver = {
|
2015-11-17 04:42:21 +08:00
|
|
|
.xpd_type = XPD_TYPE_FXO,
|
2012-01-11 23:22:46 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "fxo",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.probe = fxo_xpd_probe,
|
|
|
|
.remove = fxo_xpd_remove}
|
2010-08-28 05:59:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init card_fxo_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 (ring_debounce <= 0) {
|
2012-01-11 23:22:46 +08:00
|
|
|
ERR("ring_debounce=%d. Must be positive number of ticks\n",
|
|
|
|
ring_debounce);
|
2010-08-28 05:59:27 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-01-11 23:20:05 +08:00
|
|
|
if ((ret = xpd_driver_register(&fxo_driver.driver)) < 0)
|
2010-08-28 05:59:27 +08:00
|
|
|
return ret;
|
|
|
|
INFO("revision %s\n", XPP_VERSION);
|
|
|
|
#ifdef WITH_METERING
|
|
|
|
INFO("FEATURE: WITH METERING Detection\n");
|
|
|
|
#else
|
|
|
|
INFO("FEATURE: NO METERING Detection\n");
|
|
|
|
#endif
|
|
|
|
xproto_register(&PROTO_TABLE(FXO));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit card_fxo_cleanup(void)
|
|
|
|
{
|
|
|
|
xproto_unregister(&PROTO_TABLE(FXO));
|
|
|
|
xpd_driver_unregister(&fxo_driver.driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("XPP FXO Card Driver");
|
|
|
|
MODULE_AUTHOR("Oron Peled <oron@actcom.co.il>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_VERSION(XPP_VERSION);
|
|
|
|
MODULE_ALIAS_XPD(XPD_TYPE_FXO);
|
|
|
|
|
|
|
|
module_init(card_fxo_startup);
|
|
|
|
module_exit(card_fxo_cleanup);
|