blob: 83e00324ea54265a83a44d1f44878a2526cb75d4 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001#ifndef _USR_LINE_H
2#define _USR_LINE_H
3
4#include <asm/types.h>
5#include <linux/mutex.h>
6#include "112.h"
7#include "si_adt.h"
8#include "silicon_spi.h"
9#include "si3217x_registers.h"
10
11#define USL_MAJOR 211 /* device num */
12#define USL_NAME "slic" /* device name */
13
14#define MSGMAX 32
15#define SLIC_PORT_TYPE 0
16#define DAA_PORT_TYPE 1
17
18/* if line is ok to be scaned or operated */
19#define LINE_NOTINIT 0
20#define LINE_INITOK 1
21#define LINE_DISABLE 0
22#define LINE_ENABLE 1
23
24#define SLC_SUCCESS (0)
25#define SLC_FAIL (-1)
26
27typedef enum {
28 SLIC_UNKNOWN_CMD = -1, /* unknow cmd */
29
30 /* modified cmd*/
31 SLIC_DEV_INIT = 0, /* ³õʼ»¯SLICоƬ */
32 SLIC_MSG_REV, /* ½ÓÊÕÉϱ¨Ê¼þ*/
33 SLIC_TEST,
34 SLIC_SIGNAL_START, /* ¿ªÊ¼ÕñÁå»ò·ÅÒô */
35 SLIC_SIGNAL_STOP, /* Í£Ö¹ÕñÁå»ò·ÅÒô */
36 SLIC_PCM_OPEN = 5, /* ´ò¿ªPCMͨ· */
37 SLIC_PCM_CLOSE, /* ¹Ø±ÕPCMͨ· */
38 SLIC_PCM_SET_NB, /* ÉèÖÃÕ­´øÒôƵ */
39 SLIC_PCM_SET_WB, /* ÉèÖÃ¿í´øÒôƵ */
40
41 /* original cmd*/
42 /* below cmd is used for ulc or slctool */
43 SLIC_INF_PRECFG = 9, /* */
44 SLIC_NOTUSED, /* for ioctl #define FIGETBSZ _IO(0x00,2) */
45 SLIC_PORT_RESET, /* */
46 SLIC_MSG_CLR, /* */
47 SLIC_DIAL_START, /* */
48 SLIC_DIAL_STOP, /* */
49 SLIC_TIMESLOT_SET, /* */
50 SLIC_TIMESLOT_RELEASE, /* */
51 SLIC_PORT_LOCK, /* */
52 SLIC_PORT_UNLOCK, /* */
53 SLIC_FSK_START, /* */
54 SLIC_FSK_STO, /* */
55 SLIC_POLARITY_REVERSE, /* */
56 SLIC_DTMFCID_START, /* */
57 SLIC_LINE_TEST_START, /* start line test */
58 SLIC_LINE_TEST_ABORT, /* stop line test */
59 SLIC_LINE_TEST_READ, /* read line test result */
60 SLIC_TIMEPARA_CFG, /* config the time para used for hookon¡¢hookoff¡¢pulse dial and flash */
61 SLIC_ELECTRIC_CFG, /* */
62
63 /* below cmd is only used for slctool for debug */
64 SLIC_DEBUG_LEVEL = 28, /* set the message print level */
65 SLIC_CFG_HOOK_LOWLEN, /* config the hookon time */
66 SLIC_CFG_HOOK_HIGLEN, /* */
67 SLIC_CFG_FLASH_LMIN, /* */
68 SLIC_CFG_FLASH_LMAX, /* */
69 SLIC_CFG_FLASH_HFIX, /* */
70 SLIC_CFG_DIAL_HMIN, /* */
71 SLIC_CFG_DIAL_HMAX, /* */
72 SLIC_CFG_DIAL_LMIN, /* */
73 SLIC_CFG_DIAL_LMAX, /* */
74 SLIC_CFG_RINGCEASE, /* */
75 SLIC_CFG_PREHOOK_HIGLEN, /* */
76 SLIC_CFG_QUEUE_DELAY, /* */
77 SLIC_CODEC_GET, /* read the content of reg xxx */
78 SLIC_CODEC_SET, /* wrtie value X to reg xxx */
79 SLIC_RAM_GET = 43, /* read the content of ram xxx */
80 SLIC_RAM_SET, /* wrtie value X to ram xxx */
81 SLIC_MUTE,
82 SLIC_CODEC_GETALL, /* read all the reg */
83 SLIC_RAM_GETALL, /* read all the ram */
84 SLIC_GET_CHIP_NAME, /* */
85
86 SLIC_IOCTL_CMD_MAX,
87} SLIC_IOCTL_CMD;
88
89/* scan report event */
90typedef enum {
91 EV_UNKONWN = -1,
92 EV_FXS_HOOKON, /*¹Ò»úʼþ*/
93 EV_FXS_HOOKOFF, /*Õª»úʼþ*/
94 EV_FXS_COLLECT_DIG, /*¼ì²âµ½°´¼ü£¬ÕýÔڲɼ¯ºÅÂë*/
95 EV_FXS_FLASH, /*ÅIJå»Éʼþ*/
96
97 EV_FXS_FIRST_RING,
98 EV_FXS_SIGNAL_CEASE,
99 EV_FXO_RING_START,
100 EV_FXO_RING_STOP,
101 EV_FXS_PRE_HOOKOFF,
102 EV_FXS_FIRST_TONE,
103 EV_FXS_TEST_DONE,
104 EV_FXS_TEST_ERROR
105} SLIC_EVENT;
106
107/* daa line status */
108#define DAA_STATES 3 /* all daa phone state */
109#define DAA_RING_ON 0 /* ring */
110#define DAA_RING_OFF 1 /* no ring */
111#define DAA_REPORT 2 /* report ring */
112
113
114/* errno define */
115#define MALLOC_ERR 0x60
116#define PORT_NOFOUND 0x61
117#define CODEC_HARDWARE_ERR 0x63
118#define MESSAGE_FULL 0x64
119#define NOT_SUPPORT 0x65
120#define PULSE_ERROR 0x66
121
122
123#define SIGNAL_PLAY_START 1
124#define SIGNAL_PLAY_STOP 0
125
126
127#define USL_RING_SIGNAL RING_SIGNAL
128#define USL_TONE_SIGNAL TONE_SIGNAL
129
130
131#define RING_SIGNAL_INIT 49
132#define RING_SIGNAL_ON 50
133#define RING_SIGNAL_OFF 51
134#define RING_SIGNAL_CLEAN_OFF 52
135#define RING_SIGNAL_CLEAN_ON 53
136#define RING_SIGNAL_OFF_REVERSED 54
137#define TONE_SIGNAL_INIT 60
138#define TONE_SIGNAL_ON 61
139#define TONE_SIGNAL_OFF 62
140#define TONE_SIGNAL_CLEAN 63
141
142#define GET_EV_MASK(x) (1<<x)
143/* conver time format millisecond to system jiffies */
144#define MS2JIFF(num, ms) ((num) * (ms) * HZ / 1000)
145
146#if 0
147#define DIAL_LOW_MAX_NORMAL 0
148#define DIAL_LOW_MAX_BIGGER 1
149#endif
150
151#define EV_DIAL_STOP 0
152#define EV_DIAL_START 1
153
154extern u8 si_usl_debuglvl;
155
156
157#define USLPUT0 printk
158#define USLPUT1 printk
159#define USLPUT2 printk
160#define USLPUT3 printk
161
162
163typedef struct
164{
165 u8 bTx;
166 u8 bRx;
167} TIME_SLOT;
168
169typedef union
170{
171 u16 wTime;
172 u16 wLevel;
173 u16 wImpe;
174 u16 wHighWay;
175 TIME_SLOT stTimeSlot;
176} SLIC_PARA_UNION;
177
178typedef struct
179{
180#if 0
181 u16 port;
182 u8 port_type;
183 SLIC_PARA_UNION unPara;
184#endif
185 void *data;
186 u32 data_size;
187} SLIC_IOCTL_DATA;
188
189typedef struct
190{
191 //u16 port; /* del by zhanghuan */
192 u8 msgid;
193 u32 payload; /* payload only 4 byte */
194} MSG_DATA;
195
196typedef struct
197{
198 MSG_DATA data[MSGMAX];
199 u32 head;
200 u32 tail;
201} USL_MSG;
202
203typedef struct
204{
205 u16 wCadence_rptcnt;
206 u16 cadence_on;
207 u16 cadence_off;
208 u16 freq1;
209 u16 freq2;
210 u16 amp;
211} CANDENCE_ATTR;
212
213#if 0
214typedef struct
215{
216 u16 dura; /* dura time */
217 u16 signal_type; /* tone type */
218 u16 signal_id; /* signal id */
219 u16 tone_num; /* Ring Tone counter */
220 u32 tick_count; /* passed tick */
221 u32 next_time; /* next time of ring tone toggle */
222
223 /* Tone attrible struct */
224 u32 cease_time;
225 u8 cadence_num;
226 u16 cadence_index;
227 u16 wCurrentrptcnt; /* repeat count on current cadence_index */
228 CANDENCE_ATTR cadence[4];
229
230} SIGNAL_DATA;
231#endif
232
233/* add by zhanghuan for new signal struct */
234typedef enum {
235 RING_SIGNAL = 0,
236 TONE_SIGNAL = 1
237} SLIC_SIGNAL_TYPE;
238
239typedef enum
240{
241 TONE_DIAL, /* ²¦ºÅÒô */
242 TONE_BUSY, /* æÒô */
243 TONE_RINGBACK, /* »ØÁåÒô */
244 TONE_CONGESTION, /* ×èÈûÒô*/
245 TONE_CW, /* ºô½ÐµÈ´ýÒô*/
246 TONE_TKY, /* Ð¥½ÐÒô*/
247 TONE_SERVICE_SUCCESS, /* ÉèÖóɹ¦Òô */
248 TONE_SERVICE_FAIL, /* ÉèÖÃʧ°ÜÒô */
249 /* ´ýÀ©Õ¹ */
250 TONE_MAX,
251
252} TONE_TYPE;
253
254typedef struct
255{
256 SLIC_SIGNAL_TYPE signal_type;
257 /* TONE_SIGNAL ±íʾTONEÒô */
258 /* RING_SIGNAL ±íʾÕñÁå */
259 char cid[32]; /* À´µçÏÔʾºÅÂë */
260 TONE_TYPE tone_type; /* toneÒôÀàÐÍ*/
261
262} SIGNAL_DATA;
263/* add by zhanghuan for new signal struct end*/
264
265
266/* used for quene ring */
267typedef struct
268{
269 u32 dwRingStop; /*flag: add for dealingl the stop ringing conflit 0:noaction 1:stop ringing*/
270 u32 dwNeedSort; /*flag: need the sort algorithm 0:no 1:need*/
271 u32 dwOffCountStart; /*during the ringing off time, we will start statistics*/
272 u32 dwOffCount; /*statistics time: ringing off time*/
273 u32 dwOffMaxCount; /*time: cadence_off - cadence_on - data->delay*2 */
274
275 u32 RingQueneDelay;
276} RING_QUENE_PARA;
277
278struct codec_ops;
279
280typedef struct
281{
282 struct codec_ops *codec_ops; /* chip adpter interface func struct pointer */
283
284 u16 port;
285 u8 port_type;
286 u8 flag; /* 0:disable 1:enable */
287 u32 dwInitOK; /* 0:not init 1:init ok*/
288
289 /* daa internal data */
290 u32 ring_on_len;
291 u32 ring_off_len;
292
293 /* used for setting fsk&dtmf transmit mode */
294 u32 dwIsRevPol;
295
296 u16 event_mask; /* event mask flag */
297
298 /* play signal data */
299 u8 signal_flag; /* play signal start or stop */
300 u8 signal_on; /* signal is on or off */
301 SIGNAL_DATA sig_data;
302 RING_QUENE_PARA stRingQuenePara;
303
304 Port_t *pLine; /*Ö¸ÏòоƬ²Ù×÷µÄÖ¸Õë*/
305
306} USL_PORT;
307
308typedef struct
309{
310 s8 (*pIoctlFunc) (USL_PORT *data, SLIC_IOCTL_DATA *pstCmd);
311} USRLINE_IOCTL_FUNC_MAP;
312
313typedef struct codec_ops
314{
315 s8 (*codec_signal_ctrl) (Port_t *pPort, const void *signal_attr, const u8 flag);
316 s8 (*codec_timeslot_set) (Port_t *pPort, const u8 tx, const u8 rx);
317 s8 (*codec_timeslot_release) (Port_t *pPort);
318 s8 (*codec_polarity_reverse) (Port_t *pPort, const u16 port);
319 s8 (*codec_reset) (Port_t *pPort, const u16 port);
320 s8 (*codec_parm_cfg) (Port_t *pPort, u8 *parm, const u8 size);
321 s8 (*codec_parm_get) (Port_t *pPort, u8 *parm, const u8 size);
322 s8 (*codec_ram_cfg) (Port_t *pPort, u8 *parm, const u8 size);
323 s8 (*codec_ram_get) (Port_t *pPort, u8 *parm, const u8 size);
324 s8 (*codec_time_cfg) (Port_t *pPort, const USL_CONFIG *buf);
325 s8 (*codec_slctool_time_cfg) (Port_t *pPort, SLIC_IOCTL_CMD cmd, u16 wTime);
326 s8 (*codec_time_print) (Port_t *pPort);
327 s8 (*codec_dial_set) (Port_t *pPort, u8 bDialEn);
328 s8 (*codec_electric_cfg) (Port_t *pPort, const u16 port, const ELECTRIC_CFG_CUSTOMIZED *buf);
329 s8 (*codec_start_test) (Port_t *pPort, const WriteCmd_t *Cmd);
330 s8 (*codec_stop_test) (Port_t *pPort);
331 s8 (*codec_read_reslult) (Port_t *pPort, TestResult_t *pstResult);
332 s8 (*codec_power_ctrl) (Port_t *pPort, u8 level);
333
334 void (*codec_scan) (USL_PORT *pUslPort);
335} CODEC_OPS;
336
337s8 usrline_report(const u16 port, const u8 event, const u32 payload, u16 mask);
338s8 usrline_port_register( const u16 port, const u8 type, CODEC_OPS *ops, Port_t *pchip);
339#endif /* _USR_LINE_H */