1
2
3
4
5
6
7
8
9
10
11
12
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/io.h>
17#include <linux/hdlc.h>
18#include "pmcc4_sysdep.h"
19#include "sbecom_inline_linux.h"
20#include "libsbew.h"
21#include "pmcc4.h"
22#include "comet.h"
23#include "comet_tables.h"
24
25extern int cxt1e1_log_level;
26
27#define COMET_NUM_SAMPLES 24
28#define COMET_NUM_UNITS 5
29
30
31static void SetPwrLevel(comet_t *comet);
32static void WrtRcvEqualizerTbl(ci_t *ci, comet_t *comet, u_int32_t *table);
33static void WrtXmtWaveformTbl(ci_t *ci, comet_t *comet, u_int8_t table[COMET_NUM_SAMPLES][COMET_NUM_UNITS]);
34
35
36void *TWV_table[12] = {
37 TWVLongHaul0DB, TWVLongHaul7_5DB, TWVLongHaul15DB, TWVLongHaul22_5DB,
38 TWVShortHaul0, TWVShortHaul1, TWVShortHaul2, TWVShortHaul3,
39 TWVShortHaul4, TWVShortHaul5,
40
41 TWV_E1_75Ohm,
42 TWV_E1_120Ohm
43};
44
45
46static int
47lbo_tbl_lkup(int t1, int lbo) {
48
49 if ((lbo < CFG_LBO_LH0) || (lbo > CFG_LBO_E120)) {
50 if (t1)
51
52 lbo = CFG_LBO_LH0;
53 else
54
55 lbo = CFG_LBO_E120;
56 }
57
58 return lbo - 1;
59}
60
61void init_comet(void *ci, comet_t *comet, u_int32_t port_mode, int clockmaster,
62 u_int8_t moreParams)
63{
64 u_int8_t isT1mode;
65
66 u_int8_t tix = CFG_LBO_LH0;
67 isT1mode = IS_FRAME_ANY_T1(port_mode);
68
69 if (isT1mode) {
70
71 pci_write_32((u_int32_t *) &comet->gbl_cfg, 0xa0);
72
73 tix = lbo_tbl_lkup(isT1mode, CFG_LBO_LH0);
74 } else {
75
76 pci_write_32((u_int32_t *) &comet->gbl_cfg, 0x81);
77
78 tix = lbo_tbl_lkup(isT1mode, CFG_LBO_E120);
79 }
80
81 if (moreParams & CFG_LBO_MASK)
82
83 tix = lbo_tbl_lkup(isT1mode, moreParams & CFG_LBO_MASK);
84
85
86 pci_write_32((u_int32_t *) &comet->tx_line_cfg, 0x00);
87
88
89 pci_write_32((u_int32_t *) &comet->mtest, 0x00);
90
91
92 pci_write_32((u_int32_t *) &comet->rjat_cfg, 0x10);
93
94 if (isT1mode) {
95
96 pci_write_32((u_int32_t *) &comet->rjat_n1clk, 0x2F);
97
98 pci_write_32((u_int32_t *) &comet->rjat_n2clk, 0x2F);
99 } else {
100
101 pci_write_32((u_int32_t *) &comet->rjat_n1clk, 0xFF);
102
103 pci_write_32((u_int32_t *) &comet->rjat_n2clk, 0xFF);
104 }
105
106
107
108 pci_write_32((u_int32_t *) &comet->tjat_cfg, 0x10);
109
110
111
112 pci_write_32((u_int32_t *) &comet->rx_opt, 0x00);
113
114
115
116 if (isT1mode) {
117
118 pci_write_32((u_int32_t *) &comet->tjat_n1clk, 0x2F);
119
120 pci_write_32((u_int32_t *) &comet->tjat_n2clk, 0x2F);
121 } else {
122
123 pci_write_32((u_int32_t *) &comet->tjat_n1clk, 0xFF);
124
125 pci_write_32((u_int32_t *) &comet->tjat_n2clk, 0xFF);
126 }
127
128
129
130
131 if (isT1mode) {
132 pci_write_32((u_int32_t *) &comet->rx_elst_cfg, 0x00);
133 pci_write_32((u_int32_t *) &comet->tx_elst_cfg, 0x00);
134 } else {
135
136 pci_write_32((u_int32_t *) &comet->rx_elst_cfg, 0x03);
137 pci_write_32((u_int32_t *) &comet->tx_elst_cfg, 0x03);
138
139 pci_write_32((u_int32_t *) &comet->rxce1_ctl, 0x00);
140
141 pci_write_32((u_int32_t *) &comet->txci1_ctl, 0x00);
142 }
143
144
145
146
147 pci_write_32((u_int32_t *) &comet->t1_rboc_ena, 0x00);
148 if (isT1mode)
149 {
150
151
152
153 pci_write_32((u_int32_t *) &comet->ibcd_cfg, 0x04);
154
155 pci_write_32((u_int32_t *) &comet->ibcd_act, 0x08);
156
157 pci_write_32((u_int32_t *) &comet->ibcd_deact, 0x24);
158 }
159
160
161
162
163
164 switch (port_mode)
165 {
166
167 case CFG_FRAME_SF:
168 pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0);
169 pci_write_32((u_int32_t *) &comet->t1_frmr_cfg, 0);
170 pci_write_32((u_int32_t *) &comet->sigx_cfg, 0);
171
172 pci_write_32((u_int32_t *) &comet->t1_xbas_cfg, 0x20);
173 pci_write_32((u_int32_t *) &comet->t1_almi_cfg, 0);
174 break;
175
176 case CFG_FRAME_ESF:
177 pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0);
178
179 pci_write_32((u_int32_t *) &comet->rxce1_ctl, 0x20);
180
181 pci_write_32((u_int32_t *) &comet->txci1_ctl, 0x20);
182
183 pci_write_32((u_int32_t *) &comet->t1_frmr_cfg, 0x30);
184
185 pci_write_32((u_int32_t *) &comet->sigx_cfg, 0x04);
186
187 pci_write_32((u_int32_t *) &comet->t1_xbas_cfg, 0x30);
188
189 pci_write_32((u_int32_t *) &comet->t1_almi_cfg, 0x10);
190 break;
191
192 case CFG_FRAME_E1PLAIN:
193 pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0);
194 pci_write_32((u_int32_t *) &comet->sigx_cfg, 0);
195 pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0);
196 pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0x40);
197 break;
198
199 case CFG_FRAME_E1CAS:
200 pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0);
201 pci_write_32((u_int32_t *) &comet->sigx_cfg, 0);
202 pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0x60);
203 pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0);
204 break;
205
206 case CFG_FRAME_E1CRC:
207 pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0);
208 pci_write_32((u_int32_t *) &comet->sigx_cfg, 0);
209 pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0x10);
210 pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0xc2);
211 break;
212
213 case CFG_FRAME_E1CRC_CAS:
214 pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0);
215 pci_write_32((u_int32_t *) &comet->sigx_cfg, 0);
216 pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0x70);
217 pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0x82);
218 break;
219
220 case CFG_FRAME_SF_AMI:
221
222 pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0x80);
223 pci_write_32((u_int32_t *) &comet->t1_frmr_cfg, 0);
224 pci_write_32((u_int32_t *) &comet->t1_xbas_cfg, 0);
225 pci_write_32((u_int32_t *) &comet->t1_almi_cfg, 0);
226 pci_write_32((u_int32_t *) &comet->sigx_cfg, 0);
227 break;
228
229 case CFG_FRAME_ESF_AMI:
230
231 pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0x80);
232
233 pci_write_32((u_int32_t *) &comet->rxce1_ctl, 0x20);
234
235 pci_write_32((u_int32_t *) &comet->txci1_ctl, 0x20);
236
237 pci_write_32((u_int32_t *) &comet->t1_frmr_cfg, 0x30);
238
239 pci_write_32((u_int32_t *) &comet->sigx_cfg, 0x04);
240
241 pci_write_32((u_int32_t *) &comet->t1_xbas_cfg, 0x10);
242
243 pci_write_32((u_int32_t *) &comet->t1_almi_cfg, 0x10);
244 break;
245
246 case CFG_FRAME_E1PLAIN_AMI:
247
248 pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0x80);
249 pci_write_32((u_int32_t *) &comet->sigx_cfg, 0);
250 pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0x80);
251 pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0x40);
252 break;
253
254 case CFG_FRAME_E1CAS_AMI:
255
256 pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0x80);
257 pci_write_32((u_int32_t *) &comet->sigx_cfg, 0);
258 pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0xe0);
259 pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0);
260 break;
261
262 case CFG_FRAME_E1CRC_AMI:
263
264 pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0x80);
265 pci_write_32((u_int32_t *) &comet->sigx_cfg, 0);
266 pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0x90);
267 pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0xc2);
268 break;
269
270 case CFG_FRAME_E1CRC_CAS_AMI:
271
272 pci_write_32((u_int32_t *) &comet->cdrc_cfg, 0x80);
273 pci_write_32((u_int32_t *) &comet->sigx_cfg, 0);
274 pci_write_32((u_int32_t *) &comet->e1_tran_cfg, 0xf0);
275 pci_write_32((u_int32_t *) &comet->e1_frmr_aopts, 0x82);
276 break;
277 }
278
279
280
281
282
283
284
285
286
287
288
289
290
291 if (clockmaster)
292 {
293
294
295 if (isT1mode)
296
297 pci_write_32((u_int32_t *) &comet->brif_cfg, 0x00);
298
299 else
300
301 pci_write_32((u_int32_t *) &comet->brif_cfg, 0x01);
302
303
304
305
306 pci_write_32((u_int32_t *) &comet->brif_fpcfg, 0x00);
307 if ((moreParams & CFG_CLK_PORT_MASK) == CFG_CLK_PORT_INTERNAL)
308 {
309 if (cxt1e1_log_level >= LOG_SBEBUG12)
310 pr_info(">> %s: clockmaster internal clock\n", __func__);
311
312 pci_write_32((u_int32_t *) &comet->tx_time, 0x0d);
313 } else {
314
315 if (cxt1e1_log_level >= LOG_SBEBUG12)
316 pr_info(">> %s: clockmaster external clock\n", __func__);
317
318 pci_write_32((u_int32_t *) &comet->tx_time, 0x09);
319 }
320
321 } else {
322
323 if (isT1mode)
324
325 pci_write_32((u_int32_t *) &comet->brif_cfg, 0x20);
326 else
327
328 pci_write_32((u_int32_t *) &comet->brif_cfg, 0x21);
329
330 pci_write_32((u_int32_t *) &comet->brif_fpcfg, 0x20);
331 if (cxt1e1_log_level >= LOG_SBEBUG12)
332 pr_info(">> %s: clockslave internal clock\n", __func__);
333
334 pci_write_32((u_int32_t *) &comet->tx_time, 0x0d);
335 }
336
337
338
339
340 pci_write_32((u_int32_t *) &comet->brif_pfcfg, 0x01);
341
342
343
344 if (isT1mode)
345
346 pci_write_32((u_int32_t *) &comet->rlps_eqvr, 0x2c);
347 else
348
349 pci_write_32((u_int32_t *) &comet->rlps_eqvr, 0x34);
350
351
352
353
354 pci_write_32((u_int32_t *) &comet->rlps_cfgsts, 0x11);
355 if (isT1mode)
356
357 pci_write_32((u_int32_t *) &comet->rlps_alos_thresh, 0x55);
358 else
359
360 pci_write_32((u_int32_t *) &comet->rlps_alos_thresh, 0x22);
361
362
363
364
365
366
367
368
369
370 if (isT1mode)
371
372 pci_write_32((u_int32_t *) &comet->btif_cfg, 0x38);
373 else
374
375 pci_write_32((u_int32_t *) &comet->btif_cfg, 0x39);
376
377 pci_write_32((u_int32_t *) &comet->btif_fpcfg, 0x01);
378
379
380
381
382
383 pci_write_32((u_int32_t *) &comet->mdiag, 0x00);
384
385
386
387
388 WrtXmtWaveformTbl(ci, comet, TWV_table[tix]);
389 if (isT1mode)
390 WrtRcvEqualizerTbl((ci_t *) ci, comet, &T1_Equalizer[0]);
391 else
392 WrtRcvEqualizerTbl((ci_t *) ci, comet, &E1_Equalizer[0]);
393 SetPwrLevel(comet);
394}
395
396
397
398
399
400
401
402
403static void
404WrtXmtWaveform(ci_t *ci, comet_t *comet, u_int32_t sample, u_int32_t unit, u_int8_t data)
405{
406 u_int8_t WaveformAddr;
407
408 WaveformAddr = (sample << 3) + (unit & 7);
409 pci_write_32((u_int32_t *) &comet->xlpg_pwave_addr, WaveformAddr);
410
411 pci_flush_write(ci);
412 pci_write_32((u_int32_t *) &comet->xlpg_pwave_data, 0x7F & data);
413}
414
415
416
417
418
419
420
421static void
422WrtXmtWaveformTbl(ci_t *ci, comet_t *comet,
423 u_int8_t table[COMET_NUM_SAMPLES][COMET_NUM_UNITS])
424{
425 u_int32_t sample, unit;
426
427 for (sample = 0; sample < COMET_NUM_SAMPLES; sample++)
428 {
429 for (unit = 0; unit < COMET_NUM_UNITS; unit++)
430 WrtXmtWaveform(ci, comet, sample, unit, table[sample][unit]);
431 }
432
433
434 pci_write_32((u_int32_t *) &comet->xlpg_cfg, table[COMET_NUM_SAMPLES][0]);
435}
436
437
438
439
440
441
442
443
444
445
446
447
448static void
449WrtRcvEqualizerTbl(ci_t *ci, comet_t *comet, u_int32_t *table)
450{
451 u_int32_t ramaddr;
452 volatile u_int32_t value;
453
454 for (ramaddr = 0; ramaddr < 256; ramaddr++) {
455
456 {
457
458 pci_write_32((u_int32_t *) &comet->rlps_eq_rwsel, 0x80);
459
460 pci_flush_write(ci);
461
462 pci_write_32((u_int32_t *) &comet->rlps_eq_iaddr, (u_int8_t) ramaddr);
463
464 pci_flush_write(ci);
465
466
467
468
469
470
471 OS_uwait(4, "wret");
472 }
473
474 value = *table++;
475 pci_write_32((u_int32_t *) &comet->rlps_idata3, (u_int8_t) (value >> 24));
476 pci_write_32((u_int32_t *) &comet->rlps_idata2, (u_int8_t) (value >> 16));
477 pci_write_32((u_int32_t *) &comet->rlps_idata1, (u_int8_t) (value >> 8));
478 pci_write_32((u_int32_t *) &comet->rlps_idata0, (u_int8_t) value);
479
480 pci_flush_write(ci);
481
482
483
484
485 pci_write_32((u_int32_t *) &comet->rlps_eq_rwsel, 0);
486
487 pci_flush_write(ci);
488
489 pci_write_32((u_int32_t *) &comet->rlps_eq_iaddr, (u_int8_t) ramaddr);
490
491 pci_flush_write(ci);
492
493
494
495
496
497
498 OS_uwait(4, "wret");
499 }
500
501
502 pci_write_32((u_int32_t *) &comet->rlps_eq_cfg, 0xCB);
503}
504
505
506
507
508
509
510
511
512static void
513SetPwrLevel(comet_t *comet)
514{
515 volatile u_int32_t temp;
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530 pci_write_32((u_int32_t *) &comet->xlpg_fdata_sel, 0x00);
531
532 pci_write_32((u_int32_t *) &comet->xlpg_atest_pctl, 0x01);
533 pci_write_32((u_int32_t *) &comet->xlpg_atest_pctl, 0x01);
534 temp = pci_read_32((u_int32_t *) &comet->xlpg_atest_pctl) & 0xfe;
535 pci_write_32((u_int32_t *) &comet->xlpg_atest_pctl, temp);
536 pci_write_32((u_int32_t *) &comet->xlpg_atest_nctl, 0x01);
537 pci_write_32((u_int32_t *) &comet->xlpg_atest_nctl, 0x01);
538
539 temp = pci_read_32((u_int32_t *) &comet->xlpg_atest_nctl) & 0xfe;
540 pci_write_32((u_int32_t *) &comet->xlpg_atest_nctl, temp);
541
542 pci_write_32((u_int32_t *) &comet->xlpg_fdata_sel, 0x01);
543}
544
545
546
547
548
549
550
551
552
553#if 0
554static void
555SetCometOps(comet_t *comet)
556{
557 volatile u_int8_t rd_value;
558
559 if (comet == mConfig.C4Func1Base + (COMET0_OFFSET >> 2))
560 {
561
562 rd_value = (u_int8_t) pci_read_32((u_int32_t *) &comet->brif_cfg);
563 rd_value &= ~0x20;
564 pci_write_32((u_int32_t *) &comet->brif_cfg, (u_int32_t) rd_value);
565
566 rd_value = (u_int8_t) pci_read_32((u_int32_t *) &comet->brif_fpcfg);
567 rd_value &= ~0x20;
568 pci_write_32((u_int32_t *) &comet->brif_fpcfg, (u_int8_t) rd_value);
569 } else {
570
571 rd_value = (u_int8_t) pci_read_32((u_int32_t *) &comet->brif_cfg);
572 rd_value |= 0x20;
573 pci_write_32((u_int32_t *) &comet->brif_cfg, (u_int32_t) rd_value);
574
575 rd_value = (u_int8_t) pci_read_32((u_int32_t *) &comet->brif_fpcfg);
576 rd_value |= 0x20;
577 pci_write_32(u_int32_t *) & comet->brif_fpcfg, (u_int8_t) rd_value);
578 }
579}
580#endif
581
582
583