10 /***********************************************/
14 #define NUM_CHANNELS 2
15 #define MAX_SLICS (MAX_DUSLIC * NUM_CHANNELS)
17 /***********************************************/
19 #define SOP_READ_CH_0 0xC4 /* Read SOP Register for Channel A */
20 #define SOP_READ_CH_1 0xCC /* Read SOP Register for Channel B */
21 #define SOP_WRITE_CH_0 0x44 /* Write SOP Register for Channel A */
22 #define SOP_WRITE_CH_1 0x4C /* Write SOP Register for Channel B */
24 #define COP_READ_CH_0 0xC5
25 #define COP_READ_CH_1 0xCD
26 #define COP_WRITE_CH_0 0x45
27 #define COP_WRITE_CH_1 0x4D
29 #define POP_READ_CH_0 0xC6
30 #define POP_READ_CH_1 0xCE
31 #define POP_WRITE_CH_0 0x46
32 #define POP_WRITE_CH_1 0x4E
34 #define RST_CMD_DUSLIC_CHIP 0x40 /* OR 0x48 */
35 #define RST_CMD_DUSLIC_CH_A 0x41
36 #define RST_CMD_DUSLIC_CH_B 0x49
38 #define PCM_RESYNC_CMD_CH_A 0x42
39 #define PCM_RESYNC_CMD_CH_B 0x4A
41 #define ACTIVE_HOOK_LEV_4 0
42 #define ACTIVE_HOOK_LEV_12 1
44 #define SLIC_P_NORMAL 0x01
46 /************************************************/
51 #define CODSP_ADR(x) (((unsigned char)(x) & 7) << 3)
52 #define CODSP_M(x) ((unsigned char)(x) & 7)
53 #define CODSP_CMD(x) ((unsigned char)(x) & 7)
55 /************************************************/
57 /* command indication ops */
58 #define CODSP_M_SLEEP_PWRDN 7
59 #define CODSP_M_PWRDN_HIZ 0
60 #define CODSP_M_ANY_ACT 2
61 #define CODSP_M_RING 5
62 #define CODSP_M_ACT_MET 6
63 #define CODSP_M_GND_START 4
64 #define CODSP_M_RING_PAUSE 1
66 /* single byte commands */
67 #define CODSP_CMD_SOFT_RESET CODSP_CMD(0)
68 #define CODSP_CMD_RESET_CH CODSP_CMD(1)
69 #define CODSP_CMD_RESYNC CODSP_CMD(2)
71 /* two byte commands */
72 #define CODSP_CMD_SOP CODSP_CMD(4)
73 #define CODSP_CMD_COP CODSP_CMD(5)
74 #define CODSP_CMD_POP CODSP_CMD(6)
76 /************************************************/
79 #define CODSP_INTREG_INT_CH 0x80000000
80 #define CODSP_INTREG_HOOK 0x40000000
81 #define CODSP_INTREG_GNDK 0x20000000
82 #define CODSP_INTREG_GNDP 0x10000000
83 #define CODSP_INTREG_ICON 0x08000000
84 #define CODSP_INTREG_VRTLIM 0x04000000
85 #define CODSP_INTREG_OTEMP 0x02000000
86 #define CODSP_INTREG_SYNC_FAIL 0x01000000
87 #define CODSP_INTREG_LM_THRES 0x00800000
88 #define CODSP_INTREG_READY 0x00400000
89 #define CODSP_INTREG_RSTAT 0x00200000
90 #define CODSP_INTREG_LM_OK 0x00100000
91 #define CODSP_INTREG_IO4_DU 0x00080000
92 #define CODSP_INTREG_IO3_DU 0x00040000
93 #define CODSP_INTREG_IO2_DU 0x00020000
94 #define CODSP_INTREG_IO1_DU 0x00010000
95 #define CODSP_INTREG_DTMF_OK 0x00008000
96 #define CODSP_INTREG_DTMF_KEY4 0x00004000
97 #define CODSP_INTREG_DTMF_KEY3 0x00002000
98 #define CODSP_INTREG_DTMF_KEY2 0x00001000
99 #define CODSP_INTREG_DTMF_KEY1 0x00000800
100 #define CODSP_INTREG_DTMF_KEY0 0x00000400
101 #define CODSP_INTREG_UTDR_OK 0x00000200
102 #define CODSP_INTREG_UTDX_OK 0x00000100
103 #define CODSP_INTREG_EDSP_FAIL 0x00000080
104 #define CODSP_INTREG_CIS_BOF 0x00000008
105 #define CODSP_INTREG_CIS_BUF 0x00000004
106 #define CODSP_INTREG_CIS_REQ 0x00000002
107 #define CODSP_INTREG_CIS_ACT 0x00000001
109 /************************************************/
111 /* ======== SOP REG ADDRESSES =======*/
113 #define REVISION_ADDR 0x00
114 #define PCMC1_ADDR 0x05
115 #define XCR_ADDR 0x06
116 #define INTREG1_ADDR 0x07
117 #define INTREG2_ADDR 0x08
118 #define INTREG3_ADDR 0x09
119 #define INTREG4_ADDR 0x0A
120 #define LMRES1_ADDR 0x0D
121 #define MASK_ADDR 0x11
122 #define IOCTL3_ADDR 0x14
123 #define BCR1_ADDR 0x15
124 #define BCR2_ADDR 0x16
125 #define BCR3_ADDR 0x17
126 #define BCR4_ADDR 0x18
127 #define BCR5_ADDR 0x19
128 #define DSCR_ADDR 0x1A
129 #define LMCR1_ADDR 0x1C
130 #define LMCR2_ADDR 0x1D
131 #define LMCR3_ADDR 0x1E
132 #define OFR1_ADDR 0x1F
133 #define PCMR1_ADDR 0x21
134 #define PCMX1_ADDR 0x25
135 #define TSTR3_ADDR 0x2B
136 #define TSTR4_ADDR 0x2C
137 #define TSTR5_ADDR 0x2D
139 /* ========= POP REG ADDRESSES ========*/
141 #define CIS_DAT_ADDR 0x00
143 #define LEC_LEN_ADDR 0x3A
144 #define LEC_POWR_ADDR 0x3B
145 #define LEC_DELP_ADDR 0x3C
146 #define LEC_DELQ_ADDR 0x3D
147 #define LEC_GAIN_XI_ADDR 0x3E
148 #define LEC_GAIN_RI_ADDR 0x3F
149 #define LEC_GAIN_XO_ADDR 0x40
150 #define LEC_RES_1_ADDR 0x41
151 #define LEC_RES_2_ADDR 0x42
153 #define NLP_POW_LPF_ADDR 0x30
154 #define NLP_POW_LPS_ADDR 0x31
155 #define NLP_BN_LEV_X_ADDR 0x32
156 #define NLP_BN_LEV_R_ADDR 0x33
157 #define NLP_BN_INC_ADDR 0x34
158 #define NLP_BN_DEC_ADDR 0x35
159 #define NLP_BN_MAX_ADDR 0x36
160 #define NLP_BN_ADJ_ADDR 0x37
161 #define NLP_RE_MIN_ERLL_ADDR 0x38
162 #define NLP_RE_EST_ERLL_ADDR 0x39
163 #define NLP_SD_LEV_X_ADDR 0x3A
164 #define NLP_SD_LEV_R_ADDR 0x3B
165 #define NLP_SD_LEV_BN_ADDR 0x3C
166 #define NLP_SD_LEV_RE_ADDR 0x3D
167 #define NLP_SD_OT_DT_ADDR 0x3E
168 #define NLP_ERL_LIN_LP_ADDR 0x3F
169 #define NLP_ERL_LEC_LP_ADDR 0x40
170 #define NLP_CT_LEV_RE_ADDR 0x41
171 #define NLP_CTRL_ADDR 0x42
173 #define UTD_CF_H_ADDR 0x4B
174 #define UTD_CF_L_ADDR 0x4C
175 #define UTD_BW_H_ADDR 0x4D
176 #define UTD_BW_L_ADDR 0x4E
177 #define UTD_NLEV_ADDR 0x4F
178 #define UTD_SLEV_H_ADDR 0x50
179 #define UTD_SLEV_L_ADDR 0x51
180 #define UTD_DELT_ADDR 0x52
181 #define UTD_RBRK_ADDR 0x53
182 #define UTD_RTIME_ADDR 0x54
183 #define UTD_EBRK_ADDR 0x55
184 #define UTD_ETIME_ADDR 0x56
186 #define DTMF_LEV_ADDR 0x30
187 #define DTMF_TWI_ADDR 0x31
188 #define DTMF_NCF_H_ADDR 0x32
189 #define DTMF_NCF_L_ADDR 0x33
190 #define DTMF_NBW_H_ADDR 0x34
191 #define DTMF_NBW_L_ADDR 0x35
192 #define DTMF_GAIN_ADDR 0x36
193 #define DTMF_RES1_ADDR 0x37
194 #define DTMF_RES2_ADDR 0x38
195 #define DTMF_RES3_ADDR 0x39
197 #define CIS_LEV_H_ADDR 0x43
198 #define CIS_LEV_L_ADDR 0x44
199 #define CIS_BRS_ADDR 0x45
200 #define CIS_SEIZ_H_ADDR 0x46
201 #define CIS_SEIZ_L_ADDR 0x47
202 #define CIS_MARK_H_ADDR 0x48
203 #define CIS_MARK_L_ADDR 0x49
204 #define CIS_LEC_MODE_ADDR 0x4A
206 /*=====================================*/
208 #define HOOK_LEV_ACT_START_ADDR 0x89
209 #define RO1_START_ADDR 0x70
210 #define RO2_START_ADDR 0x95
211 #define RO3_START_ADDR 0x96
213 #define TG1_FREQ_START_ADDR 0x38
214 #define TG1_GAIN_START_ADDR 0x39
215 #define TG1_BANDPASS_START_ADDR 0x3B
216 #define TG1_BANDPASS_END_ADDR 0x3D
218 #define TG2_FREQ_START_ADDR 0x40
219 #define TG2_GAIN_START_ADDR 0x41
220 #define TG2_BANDPASS_START_ADDR 0x43
221 #define TG2_BANDPASS_END_ADDR 0x45
223 /*====================================*/
225 #define PCM_HW_B 0x80
226 #define PCM_HW_A 0x00
227 #define PCM_TIME_SLOT_0 0x00 /* Byte 0 of PCM Frame (by default is assigned to channel A ) */
228 #define PCM_TIME_SLOT_1 0x01 /* Byte 1 of PCM Frame (by default is assigned to channel B ) */
229 #define PCM_TIME_SLOT_4 0x04 /* Byte 4 of PCM Frame (Corresponds to B1 of the Second GCI ) */
231 #define RX_LEV_ADDR 0x28
232 #define TX_LEV_ADDR 0x30
233 #define Ik1_ADDR 0x83
235 #define AR_ROW 3 /* Is the row (AR Params) of the ac_Coeff array in SMS_CODEC_Defaults struct */
236 #define AX_ROW 6 /* Is the row (AX Params) of the ac_Coeff array in SMS_CODEC_Defaults struct */
237 #define DCF_ROW 0 /* Is the row (DCF Params) of the dc_Coeff array in SMS_CODEC_Defaults struct */
239 /* Mark the start byte of Duslic parameters that we use with configurator */
240 #define Ik1_START_BYTE 3
241 #define RX_LEV_START_BYTE 0
242 #define TX_LEV_START_BYTE 0
244 /************************************************/
246 #define INTREG4_CIS_ACT (1 << 0)
248 #define BCR1_SLEEP 0x20
249 #define BCR1_REVPOL 0x10
250 #define BCR1_ACTR 0x08
251 #define BCR1_ACTL 0x04
252 #define BCR1_SLIC_MASK 0x03
254 #define BCR2_HARD_POL_REV 0x40
255 #define BCR2_TTX 0x20
256 #define BCR2_TTX_12K 0x10
257 #define BCR2_HIMAN 0x08
258 #define BCR2_PDOT 0x01
260 #define BCR3_PCMX_EN (1 << 4)
262 #define BCR5_DTMF_EN (1 << 0)
263 #define BCR5_DTMF_SRC (1 << 1)
264 #define BCR5_LEC_EN (1 << 2)
265 #define BCR5_LEC_OUT (1 << 3)
266 #define BCR5_CIS_EN (1 << 4)
267 #define BCR5_CIS_AUTO (1 << 5)
268 #define BCR5_UTDX_EN (1 << 6)
269 #define BCR5_UTDR_EN (1 << 7)
271 #define DSCR_TG1_EN (1 << 0)
272 #define DSCR_TG2_EN (1 << 1)
273 #define DSCR_PTG (1 << 2)
274 #define DSCR_COR8 (1 << 3)
275 #define DSCR_DG_KEY(x) (((x) & 0x0F) << 4)
277 #define CIS_LEC_MODE_CIS_V23 (1 << 0)
278 #define CIS_LEC_MODE_CIS_FRM (1 << 1)
279 #define CIS_LEC_MODE_NLP_EN (1 << 2)
280 #define CIS_LEC_MODE_UTDR_SUM (1 << 4)
281 #define CIS_LEC_MODE_UTDX_SUM (1 << 5)
282 #define CIS_LEC_MODE_LEC_FREEZE (1 << 6)
283 #define CIS_LEC_MODE_LEC_ADAPT (1 << 7)
285 #define TSTR4_COR_64 (1 << 5)
287 #define TSTR3_AC_DLB_8K (1 << 2)
288 #define TSTR3_AC_DLB_32K (1 << 3)
289 #define TSTR3_AC_DLB_4M (1 << 5)
292 #define LMCR1_TEST_EN (1 << 7)
293 #define LMCR1_LM_EN (1 << 6)
294 #define LMCR1_LM_THM (1 << 5)
295 #define LMCR1_LM_ONCE (1 << 2)
296 #define LMCR1_LM_MASK (1 << 1)
298 #define LMCR2_LM_RECT (1 << 5)
299 #define LMCR2_LM_SEL_VDD 0x0D
300 #define LMCR2_LM_SEL_IO3 0x0A
301 #define LMCR2_LM_SEL_IO4 0x0B
302 #define LMCR2_LM_SEL_IO4_MINUS_IO3 0x0F
304 #define LMCR3_RTR_SEL (1 << 6)
306 #define LMCR3_RNG_OFFSET_NONE 0x00
307 #define LMCR3_RNG_OFFSET_1 0x01
308 #define LMCR3_RNG_OFFSET_2 0x02
309 #define LMCR3_RNG_OFFSET_3 0x03
311 #define TSTR5_DC_HOLD (1 << 3)
313 /************************************************/
315 #define TARGET_ONHOOK_BATH_x100 4600 /* 46.0 Volt */
316 #define TARGET_ONHOOK_BATL_x100 2500 /* 25.0 Volt */
317 #define TARGET_V_DIVIDER_RATIO_x100 21376L /* (R1+R2)/R2 = 213.76 */
318 #define DIVIDER_RATIO_ACCURx100 (22 * 100)
319 #define V_AD_x10000 10834L /* VAD = 1.0834 */
320 #define TARGET_VDDx100 330 /* VDD = 3.3 * 10 */
321 #define VDD_MAX_DIFFx100 20 /* VDD Accur = 0.2*100 */
323 #define RMS_MULTIPLIERx100 111 /* pi/(2xsqrt(2)) = 1.11*/
324 #define K_INTDC_RECT_ON 4 /* When Rectifier is ON this value is necessary(2^4) */
325 #define K_INTDC_RECT_OFF 2 /* 2^2 */
327 #define SAMPLING_FREQ (2000L)
328 #define N_SAMPLES (SAMPLING_FREQ/RNG_FREQ) /* for Ring Freq =25Hz (40ms Integration Period)[Sampling rate 2KHz -->1 Sample every 500us] */
329 #define HOOK_THRESH_RING_START_ADDR 0x8B
330 #define RING_PARAMS_START_ADDR 0x70
332 #define V_OUT_BATH_MAX_DIFFx100 300 /* 3.0 x100 */
333 #define V_OUT_BATL_MAX_DIFFx100 400 /* 4.0 x100 */
334 #define MAX_V_RING_MEANx100 50
335 #define TARGET_V_RING_RMSx100 2720
336 #define V_RMS_RING_MAX_DIFFx100 250
338 #define LM_OK_SRC_IRG_2 (1 << 4)
340 /************************************************/
342 #define PORTB (((volatile immap_t *)CFG_IMMR)->im_cpm.cp_pbdat)
343 #define PORTC (((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pcdat)
344 #define PORTD (((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pddat)
346 #define _PORTD_SET(mask, state) \
354 #define _PORTB_SET(mask, state) \
362 #define _PORTB_TGL(mask) do { PORTB ^= mask; } while (0)
363 #define _PORTB_GET(mask) (!!(PORTB & mask))
365 #define _PORTC_GET(mask) (!!(PORTC & mask))
368 #define SPI_RXD (1 << (31 - 28))
369 #define SPI_TXD (1 << (31 - 29))
370 #define SPI_CLK (1 << (31 - 30))
373 #define COM_HOOK1 (1 << (15 - 9))
374 #define COM_HOOK2 (1 << (15 - 10))
376 #ifndef CONFIG_NETTA_SWAPHOOK
378 #define COM_HOOK3 (1 << (15 - 11))
379 #define COM_HOOK4 (1 << (15 - 12))
383 #define COM_HOOK3 (1 << (15 - 12))
384 #define COM_HOOK4 (1 << (15 - 11))
389 #define SPIENC1 (1 << (15 - 9))
390 #define SPIENC2 (1 << (15 - 10))
391 #define SPIENC3 (1 << (15 - 11))
392 #define SPIENC4 (1 << (15 - 14))
394 #define SPI_DELAY() udelay(1)
396 static inline unsigned int __SPI_Transfer(unsigned int tx
)
403 _PORTB_SET(SPI_TXD
, tx
& 0x80);
408 rx
|= _PORTB_GET(SPI_RXD
);
416 static const char *codsp_dtmf_map
= "D1234567890*#ABC";
418 static const int spienc_mask_tab
[4] = { SPIENC1
, SPIENC2
, SPIENC3
, SPIENC4
};
419 static const int com_hook_mask_tab
[4] = { COM_HOOK1
, COM_HOOK2
, COM_HOOK3
, COM_HOOK4
};
421 static unsigned int codsp_send(int duslic_id
, const unsigned char *cmd
, int cmdlen
, unsigned char *res
, int reslen
)
426 /* just some sanity checks */
427 if (cmd
== 0 || cmdlen
< 0)
430 _PORTD_SET(spienc_mask_tab
[duslic_id
], 0);
432 /* first 2 bytes are without response */
434 while (i
-- > 0 && cmdlen
-- > 0)
435 __SPI_Transfer(*cmd
++);
437 while (cmdlen
-- > 0) {
438 rx
= __SPI_Transfer(*cmd
++);
439 if (res
!= 0 && reslen
-- > 0)
440 *res
++ = (unsigned char)rx
;
444 *res
++ = __SPI_Transfer(0xFF);
447 _PORTD_SET(spienc_mask_tab
[duslic_id
], 1);
452 /****************************************************************************/
454 void codsp_set_ciop_m(int duslic_id
, int channel
, unsigned char m
)
456 unsigned char cmd
= CODSP_WR
| CODSP_ADR(channel
) | CODSP_M(m
);
457 codsp_send(duslic_id
, &cmd
, 1, 0, 0);
460 void codsp_reset_chip(int duslic_id
)
462 static const unsigned char cmd
= CODSP_WR
| CODSP_OP
| CODSP_CMD_SOFT_RESET
;
463 codsp_send(duslic_id
, &cmd
, 1, 0, 0);
466 void codsp_reset_channel(int duslic_id
, int channel
)
468 unsigned char cmd
= CODSP_WR
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_RESET_CH
;
469 codsp_send(duslic_id
, &cmd
, 1, 0, 0);
472 void codsp_resync_channel(int duslic_id
, int channel
)
474 unsigned char cmd
= CODSP_WR
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_RESYNC
;
475 codsp_send(duslic_id
, &cmd
, 1, 0, 0);
478 /****************************************************************************/
480 void codsp_write_sop_char(int duslic_id
, int channel
, unsigned char regno
, unsigned char val
)
482 unsigned char cmd
[3];
484 cmd
[0] = CODSP_WR
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_SOP
;
488 codsp_send(duslic_id
, cmd
, 3, 0, 0);
491 void codsp_write_sop_short(int duslic_id
, int channel
, unsigned char regno
, unsigned short val
)
493 unsigned char cmd
[4];
495 cmd
[0] = CODSP_WR
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_SOP
;
497 cmd
[2] = (unsigned char)(val
>> 8);
498 cmd
[3] = (unsigned char)val
;
500 codsp_send(duslic_id
, cmd
, 4, 0, 0);
503 void codsp_write_sop_int(int duslic_id
, int channel
, unsigned char regno
, unsigned int val
)
505 unsigned char cmd
[5];
507 cmd
[0] = CODSP_WR
| CODSP_ADR(channel
) | CODSP_CMD_SOP
;
509 cmd
[2] = (unsigned char)(val
>> 24);
510 cmd
[3] = (unsigned char)(val
>> 16);
511 cmd
[4] = (unsigned char)(val
>> 8);
512 cmd
[5] = (unsigned char)val
;
514 codsp_send(duslic_id
, cmd
, 6, 0, 0);
517 unsigned char codsp_read_sop_char(int duslic_id
, int channel
, unsigned char regno
)
519 unsigned char cmd
[3];
520 unsigned char res
[2];
522 cmd
[0] = CODSP_RD
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_SOP
;
525 codsp_send(duslic_id
, cmd
, 2, res
, 2);
530 unsigned short codsp_read_sop_short(int duslic_id
, int channel
, unsigned char regno
)
532 unsigned char cmd
[2];
533 unsigned char res
[3];
535 cmd
[0] = CODSP_RD
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_SOP
;
538 codsp_send(duslic_id
, cmd
, 2, res
, 3);
540 return ((unsigned short)res
[1] << 8) | res
[2];
543 unsigned int codsp_read_sop_int(int duslic_id
, int channel
, unsigned char regno
)
545 unsigned char cmd
[2];
546 unsigned char res
[5];
548 cmd
[0] = CODSP_RD
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_SOP
;
551 codsp_send(duslic_id
, cmd
, 2, res
, 5);
553 return ((unsigned int)res
[1] << 24) | ((unsigned int)res
[2] << 16) | ((unsigned int)res
[3] << 8) | res
[4];
556 /****************************************************************************/
558 void codsp_write_cop_block(int duslic_id
, int channel
, unsigned char addr
, const unsigned char *block
)
560 unsigned char cmd
[10];
562 cmd
[0] = CODSP_WR
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_COP
;
564 memcpy(cmd
+ 2, block
, 8);
565 codsp_send(duslic_id
, cmd
, 10, 0, 0);
568 void codsp_write_cop_char(int duslic_id
, int channel
, unsigned char addr
, unsigned char val
)
570 unsigned char cmd
[3];
572 cmd
[0] = CODSP_WR
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_COP
;
575 codsp_send(duslic_id
, cmd
, 3, 0, 0);
578 void codsp_write_cop_short(int duslic_id
, int channel
, unsigned char addr
, unsigned short val
)
580 unsigned char cmd
[3];
582 cmd
[0] = CODSP_WR
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_COP
;
584 cmd
[2] = (unsigned char)(val
>> 8);
585 cmd
[3] = (unsigned char)val
;
587 codsp_send(duslic_id
, cmd
, 4, 0, 0);
590 void codsp_read_cop_block(int duslic_id
, int channel
, unsigned char addr
, unsigned char *block
)
592 unsigned char cmd
[2];
593 unsigned char res
[9];
595 cmd
[0] = CODSP_RD
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_COP
;
597 codsp_send(duslic_id
, cmd
, 2, res
, 9);
598 memcpy(block
, res
+ 1, 8);
601 unsigned char codsp_read_cop_char(int duslic_id
, int channel
, unsigned char addr
)
603 unsigned char cmd
[2];
604 unsigned char res
[2];
606 cmd
[0] = CODSP_RD
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_COP
;
608 codsp_send(duslic_id
, cmd
, 2, res
, 2);
612 unsigned short codsp_read_cop_short(int duslic_id
, int channel
, unsigned char addr
)
614 unsigned char cmd
[2];
615 unsigned char res
[3];
617 cmd
[0] = CODSP_RD
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_COP
;
620 codsp_send(duslic_id
, cmd
, 2, res
, 3);
622 return ((unsigned short)res
[1] << 8) | res
[2];
625 /****************************************************************************/
627 #define MAX_POP_BLOCK 50
629 void codsp_write_pop_block(int duslic_id
, int channel
, unsigned char addr
, const unsigned char *block
, int len
)
631 unsigned char cmd
[2 + MAX_POP_BLOCK
];
633 if (len
> MAX_POP_BLOCK
) /* truncate */
636 cmd
[0] = CODSP_WR
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_POP
;
638 memcpy(cmd
+ 2, block
, len
);
639 codsp_send(duslic_id
, cmd
, 2 + len
, 0, 0);
642 void codsp_write_pop_char(int duslic_id
, int channel
, unsigned char regno
, unsigned char val
)
644 unsigned char cmd
[3];
646 cmd
[0] = CODSP_WR
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_POP
;
650 codsp_send(duslic_id
, cmd
, 3, 0, 0);
653 void codsp_write_pop_short(int duslic_id
, int channel
, unsigned char regno
, unsigned short val
)
655 unsigned char cmd
[4];
657 cmd
[0] = CODSP_WR
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_POP
;
659 cmd
[2] = (unsigned char)(val
>> 8);
660 cmd
[3] = (unsigned char)val
;
662 codsp_send(duslic_id
, cmd
, 4, 0, 0);
665 void codsp_write_pop_int(int duslic_id
, int channel
, unsigned char regno
, unsigned int val
)
667 unsigned char cmd
[5];
669 cmd
[0] = CODSP_WR
| CODSP_ADR(channel
) | CODSP_CMD_POP
;
671 cmd
[2] = (unsigned char)(val
>> 24);
672 cmd
[3] = (unsigned char)(val
>> 16);
673 cmd
[4] = (unsigned char)(val
>> 8);
674 cmd
[5] = (unsigned char)val
;
676 codsp_send(duslic_id
, cmd
, 6, 0, 0);
679 unsigned char codsp_read_pop_char(int duslic_id
, int channel
, unsigned char regno
)
681 unsigned char cmd
[3];
682 unsigned char res
[2];
684 cmd
[0] = CODSP_RD
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_POP
;
687 codsp_send(duslic_id
, cmd
, 2, res
, 2);
692 unsigned short codsp_read_pop_short(int duslic_id
, int channel
, unsigned char regno
)
694 unsigned char cmd
[2];
695 unsigned char res
[3];
697 cmd
[0] = CODSP_RD
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_POP
;
700 codsp_send(duslic_id
, cmd
, 2, res
, 3);
702 return ((unsigned short)res
[1] << 8) | res
[2];
705 unsigned int codsp_read_pop_int(int duslic_id
, int channel
, unsigned char regno
)
707 unsigned char cmd
[2];
708 unsigned char res
[5];
710 cmd
[0] = CODSP_RD
| CODSP_OP
| CODSP_ADR(channel
) | CODSP_CMD_POP
;
713 codsp_send(duslic_id
, cmd
, 2, res
, 5);
715 return ((unsigned int)res
[1] << 24) | ((unsigned int)res
[2] << 16) | ((unsigned int)res
[3] << 8) | res
[4];
718 /****************************************************************************/
722 unsigned char values
[8];
725 struct _coeffs ac_coeffs
[11] = {
726 { 0x60, {0xAD,0xDA,0xB5,0x9B,0xC7,0x2A,0x9D,0x00} }, /* 0x60 IM-Filter part 1 */
727 { 0x68, {0x10,0x00,0xA9,0x82,0x0D,0x77,0x0A,0x00} }, /* 0x68 IM-Filter part 2 */
728 { 0x18, {0x08,0xC0,0xD2,0xAB,0xA5,0xE2,0xAB,0x07} }, /* 0x18 FRR-Filter */
729 { 0x28, {0x44,0x93,0xF5,0x92,0x88,0x00,0x00,0x00} }, /* 0x28 AR-Filter */
730 { 0x48, {0x96,0x38,0x29,0x96,0xC9,0x2B,0x8B,0x00} }, /* 0x48 LPR-Filter */
731 { 0x20, {0x08,0xB0,0xDA,0x9D,0xA7,0xFA,0x93,0x06} }, /* 0x20 FRX-Filter */
732 { 0x30, {0xBA,0xAC,0x00,0x01,0x85,0x50,0xC0,0x1A} }, /* 0x30 AX-Filter */
733 { 0x50, {0x96,0x38,0x29,0xF5,0xFA,0x2B,0x8B,0x00} }, /* 0x50 LPX-Filter */
734 { 0x00, {0x00,0x08,0x08,0x81,0x00,0x80,0x00,0x08} }, /* 0x00 TH-Filter part 1 */
735 { 0x08, {0x81,0x00,0x80,0x00,0xD7,0x33,0xBA,0x01} }, /* 0x08 TH-Filter part 2 */
736 { 0x10, {0xB3,0x6C,0xDC,0xA3,0xA4,0xE5,0x88,0x00} } /* 0x10 TH-Filter part 3 */
739 struct _coeffs ac_coeffs_0dB
[11] = {
740 { 0x60, {0xAC,0x2A,0xB5,0x9A,0xB7,0x2A,0x9D,0x00} },
741 { 0x68, {0x10,0x00,0xA9,0x82,0x0D,0x83,0x0A,0x00} },
742 { 0x18, {0x08,0x20,0xD4,0xA4,0x65,0xEE,0x92,0x07} },
743 { 0x28, {0x2B,0xAB,0x36,0xA5,0x88,0x00,0x00,0x00} },
744 { 0x48, {0xAB,0xE9,0x4E,0x32,0xAB,0x25,0xA5,0x03} },
745 { 0x20, {0x08,0x20,0xDB,0x9C,0xA7,0xFA,0xB4,0x07} },
746 { 0x30, {0xF3,0x10,0x07,0x60,0x85,0x40,0xC0,0x1A} },
747 { 0x50, {0x96,0x38,0x29,0x97,0x39,0x19,0x8B,0x00} },
748 { 0x00, {0x00,0x08,0x08,0x81,0x00,0x80,0x00,0x08} },
749 { 0x08, {0x81,0x00,0x80,0x00,0x47,0x3C,0xD2,0x01} },
750 { 0x10, {0x62,0xDB,0x4A,0x87,0x73,0x28,0x88,0x00} }
753 struct _coeffs dc_coeffs
[9] = {
754 { 0x80, {0x25,0x59,0x9C,0x23,0x24,0x23,0x32,0x1C} }, /* 0x80 DC-Parameter */
755 { 0x70, {0x90,0x30,0x1B,0xC0,0x33,0x43,0xAC,0x02} }, /* 0x70 Ringing */
756 { 0x90, {0x3F,0xC3,0x2E,0x3A,0x80,0x90,0x00,0x09} }, /* 0x90 LP-Filters */
757 { 0x88, {0xAF,0x80,0x27,0x7B,0x01,0x4C,0x7B,0x02} }, /* 0x88 Hook Levels */
758 { 0x78, {0x00,0xC0,0x6D,0x7A,0xB3,0x78,0x89,0x00} }, /* 0x78 Ramp Generator */
759 { 0x58, {0xA5,0x44,0x34,0xDB,0x0E,0xA2,0x2A,0x00} }, /* 0x58 TTX */
760 { 0x38, {0x33,0x49,0x9A,0x65,0xBB,0x00,0x00,0x00} }, /* 0x38 TG1 */
761 { 0x40, {0x33,0x49,0x9A,0x65,0xBB,0x00,0x00,0x00} }, /* 0x40 TG2 */
762 { 0x98, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} } /* 0x98 Reserved */
765 void program_coeffs(int duslic_id
, int channel
, struct _coeffs
*coeffs
, int tab_size
)
769 for (i
= 0; i
< tab_size
; i
++)
770 codsp_write_cop_block(duslic_id
, channel
, coeffs
[i
].addr
, coeffs
[i
].values
);
773 #define SS_OPEN_CIRCUIT 0
774 #define SS_RING_PAUSE 1
776 #define SS_ACTIVE_HIGH 3
777 #define SS_ACTIVE_RING 4
779 #define SS_ACTIVE_WITH_METERING 6
780 #define SS_ONHOOKTRNSM 7
784 static void codsp_set_slic(int duslic_id
, int channel
, int state
)
788 v
= codsp_read_sop_char(duslic_id
, channel
, BCR1_ADDR
);
793 codsp_write_sop_char(duslic_id
, channel
, BCR1_ADDR
, (v
& ~BCR1_ACTR
) | BCR1_ACTL
);
794 codsp_set_ciop_m(duslic_id
, channel
, CODSP_M_ANY_ACT
);
798 codsp_write_sop_char(duslic_id
, channel
, BCR1_ADDR
, v
& ~(BCR1_ACTR
| BCR1_ACTL
));
799 codsp_set_ciop_m(duslic_id
, channel
, CODSP_M_ANY_ACT
);
804 codsp_write_sop_char(duslic_id
, channel
, BCR1_ADDR
, (v
& ~BCR1_ACTL
) | BCR1_ACTR
);
805 codsp_set_ciop_m(duslic_id
, channel
, CODSP_M_ANY_ACT
);
809 codsp_write_sop_char(duslic_id
, channel
, BCR1_ADDR
, v
& ~(BCR1_ACTL
| BCR1_ACTR
));
810 codsp_set_ciop_m(duslic_id
, channel
, CODSP_M_SLEEP_PWRDN
);
813 case SS_OPEN_CIRCUIT
:
814 codsp_set_ciop_m(duslic_id
, channel
, CODSP_M_PWRDN_HIZ
);
818 codsp_set_ciop_m(duslic_id
, channel
, CODSP_M_RING
);
822 codsp_set_ciop_m(duslic_id
, channel
, CODSP_M_RING_PAUSE
);
827 const unsigned char Ring_Sin_28Vrms_25Hz
[8] = { 0x90, 0x30, 0x1B, 0xC0, 0xC3, 0x9C, 0x88, 0x00 };
828 const unsigned char Max_HookRingTh
[3] = { 0x7B, 0x41, 0x62 };
830 void retrieve_slic_state(int slic_id
)
832 int duslic_id
= slic_id
>> 1;
833 int channel
= slic_id
& 1;
835 /* Retrieve the state of the SLICs */
836 codsp_write_sop_char(duslic_id
, channel
, LMCR2_ADDR
, 0x00);
838 /* wait at least 1000us to clear the LM_OK and 500us to set the LM_OK ==> for the LM to make the first Measurement */
841 codsp_write_sop_char(duslic_id
, channel
, LMCR1_ADDR
, LMCR1_LM_THM
| LMCR1_LM_MASK
);
842 codsp_set_slic(duslic_id
, channel
, SS_ACTIVE_HIGH
);
843 codsp_write_sop_char(duslic_id
, channel
, LMCR3_ADDR
, 0x40);
845 /* Program Default Hook Ring thresholds */
846 codsp_write_cop_block(duslic_id
, channel
, dc_coeffs
[1].addr
, dc_coeffs
[1].values
);
848 /* Now program Hook Threshold while Ring and ac RingTrip to max values */
849 codsp_write_cop_block(duslic_id
, channel
, dc_coeffs
[3].addr
, dc_coeffs
[3].values
);
851 codsp_write_sop_short(duslic_id
, channel
, OFR1_ADDR
, 0x0000);
856 int wait_level_metering_finish(int duslic_id
, int channel
)
860 for (cnt
= 0; cnt
< 1000 &&
861 (codsp_read_sop_char(duslic_id
, channel
, INTREG2_ADDR
) & LM_OK_SRC_IRG_2
) == 0; cnt
++) { }
866 int measure_on_hook_voltages(int slic_id
, long *vdd
,
867 long *v_oh_H
, long *v_oh_L
, long *ring_mean_v
, long *ring_rms_v
)
869 short LM_Result
, Offset_Compensation
; /* Signed 16 bit */
870 long int VDD
, VDD_diff
, V_in
, V_out
, Divider_Ratio
, Vout_diff
;
871 unsigned char err_mask
= 0;
872 int duslic_id
= slic_id
>> 1;
873 int channel
= slic_id
& 1;
877 /* Now select the VDD level Measurement (but first of all Hold the DC characteristic) */
878 codsp_write_sop_char(duslic_id
, channel
, TSTR5_ADDR
, TSTR5_DC_HOLD
);
880 /* Activate Test Mode ==> To Enable DC Hold !!! */
881 /* (else the LMRES is treated as Feeding Current and the Feeding voltage changes */
882 /* imediatelly (after 500us when the LMRES Registers is updated for the first time after selection of (IO4-IO3) measurement !!!!))*/
883 codsp_write_sop_char(duslic_id
, channel
, LMCR1_ADDR
, LMCR1_TEST_EN
| LMCR1_LM_THM
| LMCR1_LM_MASK
);
887 /* Now I Can select what to measure by DC Level Meter (select IO4-IO3) */
888 codsp_write_sop_char(duslic_id
, channel
, LMCR2_ADDR
, LMCR2_LM_SEL_VDD
);
890 /* wait at least 1000us to clear the LM_OK and 500us to set the LM_OK ==> for the LM to make the first Measurement */
893 /* Now Read the LM Result Registers */
894 LM_Result
= codsp_read_sop_short(duslic_id
, channel
, LMRES1_ADDR
);
895 VDD
= (-1)*((((long int)LM_Result
) * 390L ) >> 15) ; /* VDDx100 */
899 VDD_diff
= VDD
- TARGET_VDDx100
;
902 VDD_diff
= -VDD_diff
;
904 if (VDD_diff
> VDD_MAX_DIFFx100
)
907 Divider_Ratio
= TARGET_V_DIVIDER_RATIO_x100
;
909 codsp_write_sop_char(duslic_id
, channel
, LMCR2_ADDR
, 0x00);
910 codsp_write_sop_char(duslic_id
, channel
, LMCR1_ADDR
, LMCR1_LM_THM
| LMCR1_LM_MASK
);
912 codsp_set_slic(duslic_id
, channel
, SS_ACTIVE_HIGH
); /* Go back to ONHOOK Voltage */
916 codsp_write_sop_char(duslic_id
, channel
,
917 LMCR1_ADDR
, LMCR1_TEST_EN
| LMCR1_LM_THM
| LMCR1_LM_MASK
);
921 /* Now I Can select what to measure by DC Level Meter (select IO4-IO3) */
922 codsp_write_sop_char(duslic_id
, channel
, LMCR2_ADDR
, LMCR2_LM_SEL_IO4_MINUS_IO3
);
924 /* wait at least 1000us to clear the LM_OK and 500us to set the LM_OK ==> for the LM to make the first Measurement */
927 /* Now Read the LM Result Registers */
928 LM_Result
= codsp_read_sop_short(duslic_id
, channel
, LMRES1_ADDR
);
929 V_in
= (-1)* ((((long int)LM_Result
) * V_AD_x10000
) >> 15) ; /* Vin x 10000*/
931 V_out
= (V_in
* Divider_Ratio
) / 10000L ; /* Vout x100 */
935 Vout_diff
= V_out
- TARGET_ONHOOK_BATH_x100
;
938 Vout_diff
= -Vout_diff
;
940 if (Vout_diff
> V_OUT_BATH_MAX_DIFFx100
)
943 codsp_set_slic(duslic_id
, channel
, SS_ACTIVE
); /* Go back to ONHOOK Voltage */
947 /* Now Read the LM Result Registers */
948 LM_Result
= codsp_read_sop_short(duslic_id
, channel
, LMRES1_ADDR
);
950 V_in
= (-1)* ((((long int)LM_Result
) * V_AD_x10000
) >> 15) ; /* Vin x 10000*/
952 V_out
= (V_in
* Divider_Ratio
) / 10000L ; /* Vout x100 */
956 Vout_diff
= V_out
- TARGET_ONHOOK_BATL_x100
;
959 Vout_diff
= -Vout_diff
;
961 if (Vout_diff
> V_OUT_BATL_MAX_DIFFx100
)
964 /* perform ring tests */
966 codsp_write_sop_char(duslic_id
, channel
, LMCR2_ADDR
, 0x00);
967 codsp_write_sop_char(duslic_id
, channel
, LMCR1_ADDR
, LMCR1_LM_THM
| LMCR1_LM_MASK
);
971 codsp_write_sop_char(duslic_id
, channel
, LMCR3_ADDR
, LMCR3_RTR_SEL
| LMCR3_RNG_OFFSET_NONE
);
973 /* Now program RO1 =0V , Ring Amplitude and frequency and shift factor K = 1 (LMDC=0x0088)*/
974 codsp_write_cop_block(duslic_id
, channel
, RING_PARAMS_START_ADDR
, Ring_Sin_28Vrms_25Hz
);
976 /* By Default RO1 is selected when ringing RNG-OFFSET = 00 */
978 /* Now program Hook Threshold while Ring and ac RingTrip to max values */
979 for(i
= 0; i
< sizeof(Max_HookRingTh
); i
++)
980 codsp_write_cop_char(duslic_id
, channel
, HOOK_THRESH_RING_START_ADDR
+ i
, Max_HookRingTh
[i
]);
982 codsp_write_sop_short(duslic_id
, channel
, OFR1_ADDR
, 0x0000);
984 codsp_set_slic(duslic_id
, channel
, SS_RING_PAUSE
); /* Start Ringing */
986 /* select source for the levelmeter to be IO4-IO3 */
987 codsp_write_sop_char(duslic_id
, channel
, LMCR2_ADDR
, LMCR2_LM_SEL_IO4_MINUS_IO3
);
991 /* Before Enabling Level Meter Programm the apropriate shift factor K_INTDC=(4 if Rectifier Enabled and 2 if Rectifier Disabled) */
992 codsp_write_cop_char(duslic_id
, channel
, RING_PARAMS_START_ADDR
+ 7, K_INTDC_RECT_OFF
);
996 /* Enable LevelMeter to Integrate only once (Rectifier Disabled) */
997 codsp_write_sop_char(duslic_id
, channel
,
998 LMCR1_ADDR
, LMCR1_LM_THM
| LMCR1_LM_MASK
| LMCR1_LM_EN
| LMCR1_LM_ONCE
);
1000 udelay(40000); /* Integration Period == Ring Period = 40ms (for 25Hz Ring) */
1002 if (wait_level_metering_finish(duslic_id
, channel
)) {
1004 udelay(10000); /* To be sure that Integration Results are Valid wait at least 500us !!! */
1006 /* Now Read the LM Result Registers (Will be valid until LM_EN becomes zero again( after that the Result is updated every 500us) ) */
1007 Offset_Compensation
= codsp_read_sop_short(duslic_id
, channel
, LMRES1_ADDR
);
1008 Offset_Compensation
= (-1) * ((Offset_Compensation
* (1 << K_INTDC_RECT_OFF
)) / N_SAMPLES
);
1010 /* Disable LevelMeter ==> In order to be able to restart Integrator again (for the next integration) */
1011 codsp_write_sop_char(duslic_id
, channel
, LMCR1_ADDR
, LMCR1_LM_THM
| LMCR1_LM_MASK
| LMCR1_LM_ONCE
);
1013 /* Now programm Integrator Offset Registers !!! */
1014 codsp_write_sop_short(duslic_id
, channel
, OFR1_ADDR
, Offset_Compensation
);
1016 codsp_set_slic(duslic_id
, channel
, SS_RINGING
); /* Start Ringing */
1020 /* Reenable Level Meter Integrator (The Result will be valid after Integration Period=Ring Period and until LN_EN become zero again) */
1021 codsp_write_sop_char(duslic_id
, channel
,
1022 LMCR1_ADDR
, LMCR1_LM_THM
| LMCR1_LM_MASK
| LMCR1_LM_EN
| LMCR1_LM_ONCE
);
1024 udelay(40000); /* Integration Period == Ring Period = 40ms (for 25Hz Ring) */
1026 /* Poll the LM_OK bit to see when Integration Result is Ready */
1027 if (wait_level_metering_finish(duslic_id
, channel
)) {
1029 udelay(10000); /* wait at least 500us to be sure that the Integration Result are valid !!! */
1031 /* Now Read the LM Result Registers (They will hold their value until LM_EN become zero again */
1032 /* ==>After that Result Regs will be updated every 500us !!!) */
1033 LM_Result
= codsp_read_sop_short(duslic_id
, channel
, LMRES1_ADDR
);
1034 V_in
= (-1) * ( ( (((long int)LM_Result
) * V_AD_x10000
) / N_SAMPLES
) >> (15 - K_INTDC_RECT_OFF
)) ; /* Vin x 10000*/
1036 V_out
= (V_in
* Divider_Ratio
) / 10000L ; /* Vout x100 */
1041 if (V_out
> MAX_V_RING_MEANx100
)
1044 *ring_mean_v
= V_out
;
1054 /* Disable LevelMeter ==> In order to be able to restart Integrator again (for the next integration) */
1055 codsp_write_sop_char(duslic_id
, channel
, LMCR1_ADDR
,
1056 LMCR1_LM_THM
| LMCR1_LM_MASK
| LMCR1_LM_ONCE
);
1057 codsp_write_sop_short(duslic_id
, channel
, OFR1_ADDR
, 0x0000);
1059 codsp_set_slic(duslic_id
, channel
, SS_RING_PAUSE
); /* Start Ringing */
1061 /* Now Enable Rectifier */
1062 /* select source for the levelmeter to be IO4-IO3 */
1063 codsp_write_sop_char(duslic_id
, channel
, LMCR2_ADDR
,
1064 LMCR2_LM_SEL_IO4_MINUS_IO3
| LMCR2_LM_RECT
);
1066 /* Program the apropriate shift factor K_INTDC (in order to avoid Overflow at Integtation Result !!!) */
1067 codsp_write_cop_char(duslic_id
, channel
, RING_PARAMS_START_ADDR
+ 7, K_INTDC_RECT_ON
);
1071 /* Reenable Level Meter Integrator (The Result will be valid after Integration Period=Ring Period and until LN_EN become zero again) */
1072 codsp_write_sop_char(duslic_id
, channel
, LMCR1_ADDR
,
1073 LMCR1_LM_THM
| LMCR1_LM_MASK
| LMCR1_LM_EN
| LMCR1_LM_ONCE
);
1077 /* Poll the LM_OK bit to see when Integration Result is Ready */
1078 if (wait_level_metering_finish(duslic_id
, channel
)) {
1082 /* Now Read the LM Result Registers (They will hold their value until LM_EN become zero again */
1083 /* ==>After that Result Regs will be updated every 500us !!!) */
1084 Offset_Compensation
= codsp_read_sop_short(duslic_id
, channel
, LMRES1_ADDR
);
1085 Offset_Compensation
= (-1) * ((Offset_Compensation
* (1 << K_INTDC_RECT_ON
)) / N_SAMPLES
);
1087 /* Disable LevelMeter ==> In order to be able to restart Integrator again (for the next integration) */
1088 codsp_write_sop_char(duslic_id
, channel
, LMCR1_ADDR
, LMCR1_LM_THM
| LMCR1_LM_MASK
| LMCR1_LM_ONCE
);
1090 /* Now programm Integrator Offset Registers !!! */
1091 codsp_write_sop_short(duslic_id
, channel
, OFR1_ADDR
, Offset_Compensation
);
1093 /* Be sure that a Ring is generated !!!! */
1094 codsp_set_slic(duslic_id
, channel
, SS_RINGING
); /* Start Ringing again */
1098 /* Reenable Level Meter Integrator (The Result will be valid after Integration Period=Ring Period and until LN_EN become zero again) */
1099 codsp_write_sop_char(duslic_id
, channel
, LMCR1_ADDR
,
1100 LMCR1_LM_THM
| LMCR1_LM_MASK
| LMCR1_LM_EN
| LMCR1_LM_ONCE
);
1104 /* Poll the LM_OK bit to see when Integration Result is Ready */
1105 if (wait_level_metering_finish(duslic_id
, channel
)) {
1109 /* Now Read the LM Result Registers (They will hold their value until LM_EN become zero again */
1110 /* ==>After that Result Regs will be updated every 500us !!!) */
1111 LM_Result
= codsp_read_sop_short(duslic_id
, channel
, LMRES1_ADDR
);
1112 V_in
= (-1) * ( ( (((long int)LM_Result
) * V_AD_x10000
) / N_SAMPLES
) >> (15 - K_INTDC_RECT_ON
) ) ; /* Vin x 10000*/
1114 V_out
= (((V_in
* Divider_Ratio
) / 10000L) * RMS_MULTIPLIERx100
) / 100 ; /* Vout_RMS x100 */
1118 Vout_diff
= (V_out
- TARGET_V_RING_RMSx100
);
1121 Vout_diff
= -Vout_diff
;
1123 if (Vout_diff
> V_RMS_RING_MAX_DIFFx100
)
1126 *ring_rms_v
= V_out
;
1135 /* Disable LevelMeter ==> In order to be able to restart Integrator again (for the next integration) */
1136 codsp_write_sop_char(duslic_id
, channel
, LMCR1_ADDR
, LMCR1_LM_THM
| LMCR1_LM_MASK
);
1138 retrieve_slic_state(slic_id
);
1143 int test_dtmf(int slic_id
)
1147 unsigned int intreg
;
1148 int duslic_id
= slic_id
>> 1;
1149 int channel
= slic_id
& 1;
1151 for (code
= 0; code
< 16; code
++) {
1152 b
= codsp_read_sop_char(duslic_id
, channel
, DSCR_ADDR
);
1153 codsp_write_sop_char(duslic_id
, channel
, DSCR_ADDR
,
1154 (b
& ~(DSCR_PTG
| DSCR_DG_KEY(15))) | DSCR_DG_KEY(code
) | DSCR_TG1_EN
| DSCR_TG2_EN
);
1157 intreg
= codsp_read_sop_int(duslic_id
, channel
, INTREG1_ADDR
);
1158 if ((intreg
& CODSP_INTREG_INT_CH
) == 0)
1161 if ((intreg
& CODSP_INTREG_DTMF_OK
) == 0 ||
1162 codsp_dtmf_map
[(intreg
>> 10) & 15] != codsp_dtmf_map
[code
])
1165 b
= codsp_read_sop_char(duslic_id
, channel
, DSCR_ADDR
);
1166 codsp_write_sop_char(duslic_id
, channel
, DSCR_ADDR
,
1167 b
& ~(DSCR_COR8
| DSCR_TG1_EN
| DSCR_TG2_EN
));
1171 intreg
= codsp_read_sop_int(duslic_id
, channel
, INTREG1_ADDR
); /* for dtmf_pause irq */
1175 b
= codsp_read_sop_char(duslic_id
, channel
, DSCR_ADDR
); /* stop dtmf */
1176 codsp_write_sop_char(duslic_id
, channel
, DSCR_ADDR
,
1177 b
& ~(DSCR_COR8
| DSCR_TG1_EN
| DSCR_TG2_EN
));
1184 void data_up_persist_time(int duslic_id
, int channel
, int time_ms
)
1188 b
= codsp_read_sop_char(duslic_id
, channel
, IOCTL3_ADDR
);
1189 b
= (b
& 0x0F) | ((time_ms
& 0x0F) << 4);
1190 codsp_write_sop_char(duslic_id
, channel
, IOCTL3_ADDR
, b
);
1193 static void program_dtmf_params(int duslic_id
, int channel
)
1197 codsp_write_pop_char(duslic_id
, channel
, DTMF_LEV_ADDR
, 0x10);
1198 codsp_write_pop_char(duslic_id
, channel
, DTMF_TWI_ADDR
, 0x0C);
1199 codsp_write_pop_char(duslic_id
, channel
, DTMF_NCF_H_ADDR
, 0x79);
1200 codsp_write_pop_char(duslic_id
, channel
, DTMF_NCF_L_ADDR
, 0x10);
1201 codsp_write_pop_char(duslic_id
, channel
, DTMF_NBW_H_ADDR
, 0x02);
1202 codsp_write_pop_char(duslic_id
, channel
, DTMF_NBW_L_ADDR
, 0xFB);
1203 codsp_write_pop_char(duslic_id
, channel
, DTMF_GAIN_ADDR
, 0x91);
1204 codsp_write_pop_char(duslic_id
, channel
, DTMF_RES1_ADDR
, 0x00);
1205 codsp_write_pop_char(duslic_id
, channel
, DTMF_RES2_ADDR
, 0x00);
1206 codsp_write_pop_char(duslic_id
, channel
, DTMF_RES3_ADDR
, 0x00);
1208 b
= codsp_read_sop_char(duslic_id
, channel
, BCR5_ADDR
);
1209 codsp_write_sop_char(duslic_id
, channel
, BCR5_ADDR
, b
| BCR5_DTMF_EN
);
1212 static void codsp_channel_full_reset(int duslic_id
, int channel
)
1215 program_coeffs(duslic_id
, channel
, ac_coeffs
, sizeof(ac_coeffs
) / sizeof(struct _coeffs
));
1216 program_coeffs(duslic_id
, channel
, dc_coeffs
, sizeof(dc_coeffs
) / sizeof(struct _coeffs
));
1218 /* program basic configuration registers */
1219 codsp_write_sop_char(duslic_id
, channel
, BCR1_ADDR
, 0x01);
1220 codsp_write_sop_char(duslic_id
, channel
, BCR2_ADDR
, 0x41);
1221 codsp_write_sop_char(duslic_id
, channel
, BCR3_ADDR
, 0x43);
1222 codsp_write_sop_char(duslic_id
, channel
, BCR4_ADDR
, 0x00);
1223 codsp_write_sop_char(duslic_id
, channel
, BCR5_ADDR
, 0x00);
1225 codsp_write_sop_char(duslic_id
, channel
, DSCR_ADDR
, 0x04); /* PG */
1227 program_dtmf_params(duslic_id
, channel
);
1229 codsp_write_sop_char(duslic_id
, channel
, LMCR3_ADDR
, 0x40); /* RingTRip_SEL */
1231 data_up_persist_time(duslic_id
, channel
, 4);
1233 codsp_write_sop_char(duslic_id
, channel
, MASK_ADDR
, 0xFF); /* All interrupts masked */
1235 codsp_set_slic(duslic_id
, channel
, SS_ACTIVE_HIGH
);
1238 static int codsp_chip_full_reset(int duslic_id
)
1241 int intreg
[NUM_CHANNELS
];
1242 unsigned char pcm_resync
;
1243 unsigned char revision
;
1245 codsp_reset_chip(duslic_id
);
1249 for (i
= 0; i
< NUM_CHANNELS
; i
++)
1250 intreg
[i
] = codsp_read_sop_int(duslic_id
, i
, INTREG1_ADDR
);
1254 if (_PORTC_GET(com_hook_mask_tab
[duslic_id
]) == 0) {
1255 printf("_HOOK(%d) stayed low\n", duslic_id
);
1259 for (pcm_resync
= 0, i
= 0; i
< NUM_CHANNELS
; i
++) {
1260 if (intreg
[i
] & CODSP_INTREG_SYNC_FAIL
)
1261 pcm_resync
|= 1 << i
;
1264 for (cnt
= 0; cnt
< 5 && pcm_resync
; cnt
++) {
1265 for (i
= 0; i
< NUM_CHANNELS
; i
++)
1266 codsp_resync_channel(duslic_id
, i
);
1272 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
1273 if (codsp_read_sop_int(duslic_id
, i
, INTREG1_ADDR
) & CODSP_INTREG_SYNC_FAIL
)
1274 pcm_resync
|= 1 << i
;
1279 printf("PCM_Resync(%u) not completed\n", duslic_id
);
1283 revision
= codsp_read_sop_char(duslic_id
, 0, REVISION_ADDR
);
1284 printf("DuSLIC#%d hardware version %d.%d\r\n", duslic_id
, (revision
& 0xF0) >> 4, revision
& 0x0F);
1286 codsp_write_sop_char(duslic_id
, 0, XCR_ADDR
, 0x80); /* EDSP_EN */
1288 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
1289 codsp_write_sop_char(duslic_id
, i
, PCMC1_ADDR
, 0x01);
1290 codsp_channel_full_reset(duslic_id
, i
);
1296 int slic_self_test(int duslic_mask
)
1301 long vdd
, v_oh_H
, v_oh_L
, ring_mean_v
, ring_rms_v
;
1302 const char *err_txt
[] = { "VDD", "V_OH_H", "V_OH_L", "V_RING_MEAN", "V_RING_RMS" };
1305 for (slic
= 0; slic
< MAX_SLICS
; slic
++) { /* voltages self test */
1306 if (duslic_mask
& (1 << (slic
>> 1))) {
1307 r
= measure_on_hook_voltages(slic
, &vdd
,
1308 &v_oh_H
, &v_oh_L
, &ring_mean_v
, &ring_rms_v
);
1310 printf("SLIC %u measured voltages (x100):\n\t"
1311 "VDD = %ld\tV_OH_H = %ld\tV_OH_L = %ld\tV_RING_MEAN = %ld\tV_RING_RMS = %ld\n",
1312 slic
, vdd
, v_oh_H
, v_oh_L
, ring_mean_v
, ring_rms_v
);
1317 for (i
= 0; i
< 5; i
++)
1319 printf("\t%s out of range\n", err_txt
[i
]);
1323 for (slic
= 0; slic
< MAX_SLICS
; slic
++) { /* voice path self test */
1324 if (duslic_mask
& (1 << (slic
>> 1))) {
1325 printf("SLIC %u VOICE PATH...CHECKING", slic
);
1326 printf("\rSLIC %u VOICE PATH...%s\n", slic
,
1327 (r
= test_dtmf(slic
)) != 0 ? "FAILED " : "PASSED ");
1337 #if defined(CONFIG_NETTA_ISDN)
1339 #define SPIENS1 (1 << (31 - 15))
1340 #define SPIENS2 (1 << (31 - 19))
1342 static const int spiens_mask_tab
[2] = { SPIENS1
, SPIENS2
};
1343 int s_initialized
= 0;
1345 static inline unsigned int s_transfer_internal(int s_id
, unsigned int address
, unsigned int value
)
1349 _PORTB_SET(spiens_mask_tab
[s_id
], 0);
1351 rx
= __SPI_Transfer(address
);
1353 switch (address
& 0xF0) {
1354 case 0x60: /* write byte register */
1356 rx
= __SPI_Transfer(value
);
1359 case 0xE0: /* read R6 register */
1360 v
= __SPI_Transfer(0);
1366 case 0xF0: /* read byte register */
1367 rx
= __SPI_Transfer(0);
1372 _PORTB_SET(spiens_mask_tab
[s_id
], 1);
1377 static void s_write_BR(int s_id
, unsigned int regno
, unsigned int val
)
1379 unsigned int address
;
1382 address
= 0x70 | (regno
& 15);
1385 v
= s_transfer_internal(s_id
, address
, val
);
1388 static void s_write_OR(int s_id
, unsigned int regno
, unsigned int val
)
1390 unsigned int address
;
1393 address
= 0x70 | (regno
& 15);
1396 v
= s_transfer_internal(s_id
, address
, val
);
1399 static void s_write_NR(int s_id
, unsigned int regno
, unsigned int val
)
1401 unsigned int address
;
1404 address
= (regno
& 7) << 4;
1407 v
= s_transfer_internal(s_id
, address
| val
, 0x00);
1410 #define BR7_IFR 0x08 /* IDL2 free run */
1411 #define BR7_ICSLSB 0x04 /* IDL2 clock speed LSB */
1413 #define BR15_OVRL_REG_EN 0x80
1414 #define OR7_D3VR 0x80 /* disable 3V regulator */
1416 #define OR8_TEME 0x10 /* TE mode enable */
1417 #define OR8_MME 0x08 /* master mode enable */
1419 void s_initialize(void)
1423 for (s_id
= 0; s_id
< 2; s_id
++) {
1424 s_write_BR(s_id
, 7, BR7_IFR
| BR7_ICSLSB
);
1425 s_write_BR(s_id
, 15, BR15_OVRL_REG_EN
);
1426 s_write_OR(s_id
, 8, OR8_TEME
| OR8_MME
);
1427 s_write_OR(s_id
, 7, OR7_D3VR
);
1428 s_write_OR(s_id
, 6, 0);
1429 s_write_BR(s_id
, 15, 0);
1430 s_write_NR(s_id
, 3, 0);
1436 int board_post_codec(int flags
)
1442 printf("board_post_dsp\n");
1444 #if defined(CONFIG_NETTA_ISDN)
1445 if (s_initialized
== 0) {
1449 printf("s_initialized\n");
1456 for (j
= 0; j
< MAX_DUSLIC
; j
++) {
1457 if (codsp_chip_full_reset(j
) < 0)
1458 printf("Error initializing DuSLIC#%d\n", j
);
1460 duslic_mask
|= 1 << j
;
1463 if (duslic_mask
!= 0) {
1464 printf("Testing SLICs...\n");
1466 r
= slic_self_test(duslic_mask
);
1467 for (j
= 0; j
< MAX_SLICS
; j
++) {
1468 if (duslic_mask
& (1 << (j
>> 1)))
1469 printf("SLIC %u...%s\n", j
, r
& (1 << j
) ? "FAULTY" : "OK");
1472 printf("DuSLIC self test finished\n");
1474 return 0; /* return -1 on error */