00001
00002
00003
00004 #include <stdio.h>
00005 #include <math.h>
00006
00007 #include <string.h>
00008
00009 #include <stdlib.h>
00010
00011 #include "edtinc.h"
00012
00013 #include <stddef.h>
00014
00015 #include "edt_si5326.h"
00016
00017
00018 #include "edt_threep.h"
00019
00020 #include "edt_ocm.h"
00021
00022 #include "lib_two_wire.h"
00023
00024 static
00025 Edt2WireRegArray threep_15552[EDT_SI5326_NREGS+1] = {
00026
00027 { 0,0x14},
00028 { 1,0xe4},
00029 { 2,0xa2},
00030 { 3,0x5},
00031 { 4,0x92},
00032 { 5,0xed},
00033 { 6,0x2d},
00034 { 7,0x2a},
00035 { 8,0x0},
00036 { 9,0xc0},
00037 { 10,0x8},
00038 { 11,0x48},
00039 { 16,0x0},
00040 { 17,0x80},
00041 { 18,0x0},
00042 { 19,0x29},
00043 { 20,0x3e},
00044 { 21,0xff},
00045 { 22,0xdf},
00046 { 23,0x1f},
00047 { 24,0x3f},
00048 { 25,0x80},
00049 { 31,0x0},
00050 { 32,0x0},
00051 { 33,0x3},
00052 { 34,0x0},
00053 { 35,0x0},
00054 { 36,0x3},
00055 { 40,0x80},
00056 { 41,0x1},
00057 { 42,0x37},
00058 { 43,0x0},
00059 { 44,0x0},
00060 { 45,0x4d},
00061 { 46,0x0},
00062 { 47,0x0},
00063 { 48,0x4d},
00064 { 55,0x0},
00065 {131,0x1f},
00066 {132,0x2},
00067 {136,0x40},
00068 {142,0x0},
00069 {143,0x0},
00070 {256,0}
00071 };
00072
00073 Edt2WireRegArray threep_16113[EDT_SI5326_NREGS+1] = {
00074
00075 { 0,0x14},
00076 { 1,0xe4},
00077 { 2,0xa2},
00078 { 3,0x15},
00079 { 4,0x92},
00080 { 5,0xed},
00081 { 6,0x3e},
00082 { 7,0x2a},
00083 { 8,0x0},
00084 { 9,0xc0},
00085 { 10,0x0},
00086 { 11,0x40},
00087 { 16,0x0},
00088 { 17,0x80},
00089 { 18,0x0},
00090 { 19,0x2c},
00091 { 20,0x3e},
00092 { 21,0xff},
00093 { 22,0xdf},
00094 { 23,0x1f},
00095 { 24,0x3f},
00096 { 25,0x0},
00097 { 31,0x0},
00098 { 32,0x0},
00099 { 33,0x7},
00100 { 34,0x0},
00101 { 35,0x0},
00102 { 36,0x7},
00103 { 40,0x40},
00104 { 41,0x1},
00105 { 42,0xaf},
00106 { 43,0x0},
00107 { 44,0x0},
00108 { 45,0x50},
00109 { 46,0x0},
00110 { 47,0x0},
00111 { 48,0x50},
00112 { 55,0x0},
00113 {131,0x1f},
00114 {132,0x2},
00115 {136,0x40},
00116 {138,0xf},
00117 {139,0xff},
00118 {142,0x0},
00119 {143,0x0},
00120 {256,0}
00121 };
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 unsigned char
00135 edt_threep_amcc_reg_read( EdtDev * edt_p, u_int address)
00136 {
00137 unsigned char byte;
00138 edt_serial_dev_set_bits(edt_p, THREEP_I2C_DEVICE, THREEP_AMCC,
00139 EDT_AMCC_S19250_PAGE, address, 0, EDT_AMCC_S19250_PAGE_MASK);
00140 byte = edt_serial_dev_reg_read(edt_p, THREEP_I2C_DEVICE, THREEP_AMCC,
00141 address & ~EDT_AMCC_S19250_PAGE_MASK);
00142 return(byte);
00143 }
00144
00145 unsigned char
00146 edt_threep_amcc_reg_set_bits( EdtDev * edt_p, u_int address, u_int value, u_int shift, u_int mask)
00147 {
00148 unsigned char byte;
00149
00150
00151 edt_serial_dev_set_bits(edt_p, THREEP_I2C_DEVICE, THREEP_AMCC,
00152 EDT_AMCC_S19250_PAGE, address, 0, EDT_AMCC_S19250_PAGE_MASK);
00153
00154 byte = edt_serial_dev_set_bits(edt_p, THREEP_I2C_DEVICE, THREEP_AMCC,
00155 address & ~EDT_AMCC_S19250_PAGE_MASK, value, shift, mask);
00156 return(byte);
00157 }
00158
00159
00160
00161
00162
00163
00164 void
00165 edt_threep_amcc_config_tx( EdtDev * edt_p, int mode)
00166 {
00167 int byte;
00168 int loop = 0;
00169 int verbose = edt_msg_get_level(edt_msg_default_handle()) &
00170 EDTLIB_MSG_INFO_1;
00171
00172 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_79, 0, 0, EDT_AMCC_S19250_TXREFSEL);
00173 byte = edt_threep_amcc_reg_read( edt_p, EDT_AMCC_S19250_ADDR_79);
00174
00175
00176
00177
00178 switch(mode)
00179 {
00180 case THREEP_MODE_10P3:
00181
00182
00183
00184
00185 case THREEP_MODE_10GBE:
00186
00187
00188 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_81,
00189 EDT_AMCC_S19250_TX_VCO_RNG_10GBER, 0, EDT_AMCC_S19250_TX_VCO_RNG_MASK);
00190
00191 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_98,
00192 EDT_AMCC_S19250_TX_VCO_RES_10GBER, 0, EDT_AMCC_S19250_TX_VCO_RES_MASK);
00193
00194 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_0C,
00195 EDT_AMCC_S19250_TAP2_10GBER, 0, EDT_AMCC_S19250_TAP2_CNTL_MASK);
00196 if (verbose)
00197 printf("Setting AMCC S19520 TX VCO for 10.3125 Gbps range.\n");
00198 break;
00199 case THREEP_MODE_SDH:
00200
00201
00202 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_81,
00203 EDT_AMCC_S19250_TX_VCO_RNG_SDH, 0, EDT_AMCC_S19250_TX_VCO_RNG_MASK);
00204
00205 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_98,
00206 EDT_AMCC_S19250_TX_VCO_RES_SDH, 0, EDT_AMCC_S19250_TX_VCO_RES_MASK);
00207
00208 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_0C,
00209 EDT_AMCC_S19250_TAP2_SDH, 0, EDT_AMCC_S19250_TAP2_CNTL_MASK);
00210 if (verbose)
00211 printf("Setting AMCC S19520 TX VCO for 9.95328 Gbps range.\n");
00212 break;
00213 case THREEP_MODE_G709:
00214
00215
00216 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_81,
00217 EDT_AMCC_S19250_TX_VCO_RNG_G709, 0, EDT_AMCC_S19250_TX_VCO_RNG_MASK);
00218
00219 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_98,
00220 EDT_AMCC_S19250_TX_VCO_RES_G709, 0, EDT_AMCC_S19250_TX_VCO_RES_MASK);
00221
00222 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_0C,
00223 EDT_AMCC_S19250_TAP2_G709, 0, EDT_AMCC_S19250_TAP2_CNTL_MASK);
00224 if (verbose)
00225 printf("Setting AMCC S19520 TX VCO for 10.709 Gbps range.\n");
00226 break;
00227 case THREEP_MODE_OTU2E:
00228
00229 case THREEP_MODE_OTU2F:
00230 case OTU1E_RATE:
00231
00232
00233
00234 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_81,
00235 EDT_AMCC_S19250_TX_VCO_RNG_11P3, 0, EDT_AMCC_S19250_TX_VCO_RNG_MASK);
00236
00237 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_98,
00238 EDT_AMCC_S19250_TX_VCO_RES_11P3, 0, EDT_AMCC_S19250_TX_VCO_RES_MASK);
00239
00240 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_0C,
00241 EDT_AMCC_S19250_TAP2_11P3, 0, EDT_AMCC_S19250_TAP2_CNTL_MASK);
00242 if (verbose)
00243 printf("Setting AMCC S19520 TX VCO for 11.0957 Gbps range.\n");
00244 break;
00245 default:
00246 edt_perror("edt_threep_amcc_config_tx: invalid mode");
00247 }
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_06, 0, 0, EDT_AMCC_S19250_TX_RSTB);
00259 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_06, EDT_AMCC_S19250_TX_RSTB,
00260 0, EDT_AMCC_S19250_TX_RSTB);
00261 byte = edt_reg_read( edt_p, THREEP_P0_LIU_STATUS);
00262
00263
00264
00265 byte = edt_threep_amcc_reg_read( edt_p, EDT_AMCC_S19250_ADDR_06);
00266
00267
00268
00269
00270 while (((byte = edt_reg_read( edt_p, THREEP_P0_LIU_STATUS)) & TX_LOCKDET) == 0)
00271 loop++;
00272
00273
00274
00275 byte = edt_threep_amcc_reg_read( edt_p, EDT_AMCC_S19250_ADDR_82);
00276
00277
00278
00279 byte = edt_threep_amcc_reg_read( edt_p, EDT_AMCC_S19250_ADDR_82);
00280
00281
00282
00283 byte = edt_reg_read( edt_p, THREEP_P0_ENABLE);
00284
00285
00286
00287 edt_reg_write(edt_p, THREEP_P0_ENABLE, byte & ~TXPLL_EN);
00288 byte = edt_reg_read( edt_p, THREEP_P0_ENABLE);
00289
00290
00291
00292 edt_msleep(1);
00293 edt_reg_or( edt_p, THREEP_P0_ENABLE, TXPLL_EN);
00294 byte = edt_reg_read( edt_p, THREEP_P0_ENABLE);
00295
00296
00297
00298
00299 loop = 0;
00300 while (((byte = edt_reg_read( edt_p, THREEP_P0_ENABLE)) & THREEP_TX_LOCKED) == 0)
00301 loop++;
00302
00303
00304
00305 }
00306
00307
00308
00309
00310
00311
00312 void
00313 edt_threep_amcc_config_rx( EdtDev * edt_p, int mode)
00314 {
00315 int verbose = edt_msg_get_level(edt_msg_default_handle()) &
00316 EDTLIB_MSG_INFO_1;
00317
00318 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_05, 0, 0, EDT_AMCC_S19250_RX622SEL);
00319 switch(mode)
00320 {
00321 case THREEP_MODE_10GBE:
00322 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_05, 0, 0, EDT_AMCC_S19250_SONET_RATESEL);
00323 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_02, EDT_AMCC_S19250_GBE_RATE_SEL,
00324 0, EDT_AMCC_S19250_GBE_RATE_SEL);
00325
00326
00327 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_81,
00328 EDT_AMCC_S19250_RX_VCO_RNG_10GBER, 0, EDT_AMCC_S19250_RX_VCO_RNG_MASK);
00329
00330 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_94,
00331 EDT_AMCC_S19250_RX_VCO_RES_10GBER, 0, EDT_AMCC_S19250_RX_VCO_RES_MASK);
00332
00333 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1C,
00334 EDT_AMCC_S19250_PAEQ_LINKOPT1_10GBER , 0, EDT_AMCC_S19250_PAEQ_LINKOPT1_MASK);
00335
00336 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1E,
00337 EDT_AMCC_S19250_PAEQ_LINKOPT2_UPPER_10GBER, 0, EDT_AMCC_S19250_PAEQ_LINKOPT2_UPPER_MASK);
00338 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1F,
00339 EDT_AMCC_S19250_PAEQ_LINKOPT2_LOWER_10GBER, 0, EDT_AMCC_S19250_PAEQ_LINKOPT2_LOWER_MASK);
00340 if (verbose)
00341 {
00342 printf("Setting AMCC S19520 RX for 10.3125 Gbps range.\n");
00343 printf("Setting AMCC S19520 for GBE_RATE_SEL (refclk*66).\n");
00344 }
00345 break;
00346 case THREEP_MODE_SDH:
00347 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_02, 0,
00348 0, EDT_AMCC_S19250_GBE_RATE_SEL);
00349 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_05, EDT_AMCC_S19250_SONET_RATESEL,
00350 0, EDT_AMCC_S19250_SONET_RATESEL);
00351
00352
00353 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_81,
00354 EDT_AMCC_S19250_RX_VCO_RNG_SDH, 0, EDT_AMCC_S19250_RX_VCO_RNG_MASK);
00355
00356 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_94,
00357 EDT_AMCC_S19250_RX_VCO_RES_SDH, 0, EDT_AMCC_S19250_RX_VCO_RES_MASK);
00358
00359 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1C,
00360 EDT_AMCC_S19250_PAEQ_LINKOPT1_SDH, 0, EDT_AMCC_S19250_PAEQ_LINKOPT1_MASK);
00361
00362 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1E,
00363 EDT_AMCC_S19250_PAEQ_LINKOPT2_UPPER_SDH, 0, EDT_AMCC_S19250_PAEQ_LINKOPT2_UPPER_MASK);
00364 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1F,
00365 EDT_AMCC_S19250_PAEQ_LINKOPT2_LOWER_SDH, 0, EDT_AMCC_S19250_PAEQ_LINKOPT2_LOWER_MASK);
00366 if (verbose)
00367 {
00368 printf("Setting AMCC S19520 RX for 9.95328 Gbps range.\n");
00369 printf("Setting AMCC S19520 for SONET_RATE_SEL (refclk*64).\n");
00370 }
00371 break;
00372 case THREEP_MODE_G709:
00373 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_02, 0,
00374 0, EDT_AMCC_S19250_GBE_RATE_SEL);
00375 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_05, EDT_AMCC_S19250_SONET_RATESEL,
00376 0, EDT_AMCC_S19250_SONET_RATESEL);
00377
00378
00379 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_81,
00380 EDT_AMCC_S19250_RX_VCO_RNG_G709, 0, EDT_AMCC_S19250_RX_VCO_RNG_MASK);
00381
00382 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_94,
00383 EDT_AMCC_S19250_RX_VCO_RES_G709, 0, EDT_AMCC_S19250_RX_VCO_RES_MASK);
00384
00385 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1C,
00386 EDT_AMCC_S19250_PAEQ_LINKOPT1_G709, 0, EDT_AMCC_S19250_PAEQ_LINKOPT1_MASK);
00387
00388 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1E,
00389 EDT_AMCC_S19250_PAEQ_LINKOPT2_UPPER_G709, 0, EDT_AMCC_S19250_PAEQ_LINKOPT2_UPPER_MASK);
00390 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1F,
00391 EDT_AMCC_S19250_PAEQ_LINKOPT2_LOWER_G709, 0, EDT_AMCC_S19250_PAEQ_LINKOPT2_LOWER_MASK);
00392 if (verbose)
00393 {
00394 printf("Setting AMCC S19520 RX VCO for 10.709225316 Gbps range.\n");
00395 printf("Setting AMCC S19520 for SONET_RATE_SEL (refclk*64).\n");
00396 }
00397 break;
00398 case THREEP_MODE_10P3:
00399
00400
00401
00402
00403 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_02, 0,
00404 0, EDT_AMCC_S19250_GBE_RATE_SEL);
00405 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_05, EDT_AMCC_S19250_SONET_RATESEL,
00406 0, EDT_AMCC_S19250_SONET_RATESEL);
00407
00408
00409 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_81,
00410 EDT_AMCC_S19250_RX_VCO_RNG_10GBER, 0, EDT_AMCC_S19250_RX_VCO_RNG_MASK);
00411
00412 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_94,
00413 EDT_AMCC_S19250_RX_VCO_RES_10GBER, 0, EDT_AMCC_S19250_RX_VCO_RES_MASK);
00414
00415 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1C,
00416 EDT_AMCC_S19250_PAEQ_LINKOPT1_10GBER , 0, EDT_AMCC_S19250_PAEQ_LINKOPT1_MASK);
00417
00418 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1E,
00419 EDT_AMCC_S19250_PAEQ_LINKOPT2_UPPER_10GBER, 0, EDT_AMCC_S19250_PAEQ_LINKOPT2_UPPER_MASK);
00420 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1F,
00421 EDT_AMCC_S19250_PAEQ_LINKOPT2_LOWER_10GBER, 0, EDT_AMCC_S19250_PAEQ_LINKOPT2_LOWER_MASK);
00422 if (verbose)
00423 {
00424 printf("Setting AMCC S19520 RX for 10.3125 Gbps range.\n");
00425 printf("Setting AMCC S19520 for SONET_RATE_SEL (refclk*64).\n");
00426 }
00427 break;
00428 case THREEP_MODE_OTU2E:
00429 case THREEP_MODE_OTU2F:
00430 case OTU1E_RATE:
00431 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_02, 0,
00432 0, EDT_AMCC_S19250_GBE_RATE_SEL);
00433 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_05, EDT_AMCC_S19250_SONET_RATESEL,
00434 0, EDT_AMCC_S19250_SONET_RATESEL);
00435
00436
00437 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_81,
00438 EDT_AMCC_S19250_RX_VCO_RNG_11P3, 0, EDT_AMCC_S19250_RX_VCO_RNG_MASK);
00439
00440 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_94,
00441 EDT_AMCC_S19250_RX_VCO_RES_11P3, 0, EDT_AMCC_S19250_RX_VCO_RES_MASK);
00442
00443 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1C,
00444 EDT_AMCC_S19250_PAEQ_LINKOPT1_11P3 , 0, EDT_AMCC_S19250_PAEQ_LINKOPT1_MASK);
00445
00446 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1E,
00447 EDT_AMCC_S19250_PAEQ_LINKOPT2_UPPER_11P3, 0, EDT_AMCC_S19250_PAEQ_LINKOPT2_UPPER_MASK);
00448 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_1F,
00449 EDT_AMCC_S19250_PAEQ_LINKOPT2_LOWER_11P3, 0, EDT_AMCC_S19250_PAEQ_LINKOPT2_LOWER_MASK);
00450 if (verbose)
00451 {
00452 printf("Setting AMCC S19520 RX for 11.0957 Gbps range.\n");
00453 printf("Setting AMCC S19520 for SONET_RATE_SEL (refclk*64).\n");
00454 }
00455 break;
00456 default:
00457 edt_perror("edt_threep_amcc_config_rx: invalid mode");
00458 }
00459
00460
00461 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_04, 0, 0, EDT_AMCC_S19250_RX_RSTB);
00462 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_04, EDT_AMCC_S19250_RX_RSTB,
00463 0, EDT_AMCC_S19250_RX_RSTB);
00464 }
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474 void
00475 edt_threep_amcc_chk_enable( EdtDev * edt_p, int mode)
00476 {
00477 unsigned char byte;
00478
00479 byte = edt_reg_read( edt_p, THREEP_P0_ENABLE);
00480
00481 if ((byte & LIU_EN) == 0)
00482 {
00483 edt_reg_write( edt_p, THREEP_P0_ENABLE, byte | LIU_EN );
00484
00485
00486 edt_threep_amcc_config_rx( edt_p, mode);
00487 edt_threep_amcc_config_tx( edt_p, mode);
00488 }
00489 }
00490
00503 int
00504 edt_threep_amcc_clk_mode(double freq)
00505
00506 {
00507
00508 if (freq > 9000000000.0)
00509 freq /= 1000000000.0;
00510
00511 if (freq < 9.7)
00512 return -1;
00513 else if (freq < 10.1)
00514 return THREEP_MODE_SDH;
00515 else if (freq < 10.4)
00516 return THREEP_MODE_10P3;
00517 else if (freq < 10.9)
00518 return THREEP_MODE_G709;
00519 else if (freq <= 11.4)
00520 return THREEP_MODE_OTU2E;
00521 else
00522 return -1;
00523 }
00524
00525
00526
00527
00528 void
00529 edt_threep_amcc_local_loop( EdtDev * edt_p, int set)
00530 {
00531 if (set)
00532 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_01, 0, 0, EDT_AMCC_S19250_NOT_DLEB);
00533 else
00534 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_01, EDT_AMCC_S19250_NOT_DLEB,
00535 0, EDT_AMCC_S19250_NOT_DLEB);
00536 }
00537
00538
00539
00540
00541 void
00542 edt_threep_amcc_remote_loop( EdtDev * edt_p, int set)
00543 {
00544 if (set)
00545 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_02, 0, 0, EDT_AMCC_S19250_NOT_LLEB);
00546 else
00547 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_02, EDT_AMCC_S19250_NOT_LLEB,
00548 0, EDT_AMCC_S19250_NOT_LLEB);
00549 }
00550
00551
00552
00553
00554
00555 void
00556 edt_threep_amcc_set_tx_prbs( EdtDev * edt_p, int code)
00557 {
00558 unsigned char byte;
00559
00560 edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_89, code, 0, EDT_AMCC_S19250_PRBS_MASK);
00561
00562 byte = edt_threep_amcc_reg_set_bits( edt_p, EDT_AMCC_S19250_ADDR_86, EDT_AMCC_S19250_TX_BIST_EN,
00563 0, EDT_AMCC_S19250_TX_BIST_EN);
00564 }
00565
00566
00567 #if 0
00568 static
00569 Edt2WireRegArray threep_15552[EDT_SI5326_NREGS+1] = {
00570 { 0,0x14},
00571 { 1,0xe4},
00572 { 2,0xa2},
00573 { 3,0x5},
00574 { 4,0x92},
00575 { 5,0xed},
00576 { 6,0x2d},
00577 { 7,0x2a},
00578 { 8,0x0},
00579 { 9,0xc0},
00580 { 10,0x8},
00581 { 11,0x48},
00582 { 16,0x0},
00583 { 17,0x80},
00584 { 18,0x0},
00585 { 19,0x29},
00586 { 20,0x3e},
00587 { 21,0xff},
00588 { 22,0xdf},
00589 { 23,0x1f},
00590 { 24,0x3f},
00591 { 25,0x80},
00592 { 31,0x0},
00593 { 32,0x0},
00594 { 33,0x3},
00595 { 34,0x0},
00596 { 35,0x0},
00597 { 36,0x3},
00598 { 40,0x80},
00599 { 41,0x1},
00600 { 42,0x37},
00601 { 43,0x0},
00602 { 44,0x0},
00603 { 45,0x4d},
00604 { 46,0x0},
00605 { 47,0x0},
00606 { 48,0x4d},
00607 { 55,0x0},
00608 {131,0x1f},
00609 {132,0x2},
00610 {136,0x40},
00611 {142,0x0},
00612 {143,0x0},
00613 {256,0}
00614 };
00615 #endif
00616
00617 int
00618 edt_threep_si5326_load_array(EdtDev *edt_p, Edt2WireRegArray *vec, int device)
00619 {
00620 int mapindex;
00621 int r;
00622 for (mapindex = 0; vec[mapindex].offset < 256 && mapindex < EDT_SI5326_NREGS ; mapindex++)
00623 {
00624 if (!vec[mapindex].read_only)
00625 {
00626 edt_serial_dev_reg_write(edt_p, THREEP_I2C_DEVICE, device, vec[mapindex].offset, vec[mapindex].value);
00627 r = edt_serial_dev_reg_read(edt_p, THREEP_I2C_DEVICE, device, vec[mapindex].offset);
00628 #if 0
00629 if (r != vec[mapindex].value)
00630 printf("Unable to write at offset %d value %02x != %02x\n",
00631 vec[mapindex].offset, vec[mapindex].value, r);
00632 #endif
00633
00634
00635 }
00636 }
00637 return 0;
00638 }
00639
00640 int
00641 edt_threep_si5326_dump(EdtDev *edt_p, int device)
00642 {
00643
00644 int mapindex;
00645
00646 for (mapindex = 0; si5326regs_map[mapindex].name != NULL ; mapindex++)
00647 {
00648 u_int v = edt_get_two_wire_value(edt_p,
00649 si5326regs_map + mapindex,
00650 THREEP_I2C_DEVICE,
00651 device);
00652
00653
00654 printf("%-20s: %02x\n", si5326regs_map[mapindex].name, v);
00655
00656
00657 }
00658
00659 return 0;
00660 }
00661
00662 int
00663 edt_threep_configure_clock(EdtDev *edt_p, double frequency, int port,
00664 EdtSI570 * clock_values)
00665
00666 {
00667 int verbose = edt_msg_get_level(edt_msg_default_handle()) &
00668 EDTLIB_MSG_INFO_1;
00669
00670 double clk_value;
00671 u_int dev_address;
00672
00673 switch(port)
00674 {
00675 case 0:
00676 dev_address = THREEP_P0_REF_CLK;
00677 clk_value = THREEP_P0_CLOCK_VALUE;
00678 break;
00679
00680 case 1:
00681 dev_address = THREEP_P1_REF_CLK;
00682 clk_value = THREEP_P1_CLOCK_VALUE;
00683 break;
00684
00685 case 2:
00686 dev_address = THREEP_P2_REF_CLK;
00687 clk_value = THREEP_P2_CLOCK_VALUE;
00688 break;
00689
00690 }
00691
00692
00693 if (verbose > 3)
00694 {
00695 printf("ch0: ref clock\n");
00696 edt_si570_dump(edt_p, THREEP_I2C_DEVICE, dev_address);
00697 }
00698
00699 edt_si570_reset(edt_p,THREEP_I2C_DEVICE, dev_address);
00700
00701 edt_si570_read_values(edt_p, THREEP_I2C_DEVICE, dev_address,
00702 clock_values);
00703
00704 if (verbose > 2)
00705 edt_si570_print(clock_values, clk_value);
00706
00707 edt_vco_si570_compute(clk_value,
00708 frequency,
00709 clock_values);
00710
00711 edt_si570_write_values(edt_p, THREEP_I2C_DEVICE, dev_address,
00712 clock_values);
00713
00714 if (port == 0)
00715 {
00716 edt_msleep(50);
00717 edt_threep_si5326_load_array(edt_p, threep_15552, THREEP_DEV_XMT_CLK);
00718 if (verbose > 3)
00719 edt_threep_si5326_dump(edt_p, THREEP_DEV_XMT_CLK);
00720 edt_msleep(20);
00721 }
00722
00723 return 0;
00724 }
00725
00726 int
00727 edt_threep_configure_clks(EdtDev *edt_p, EdtThreePClocks *clocks)
00728
00729 {
00730
00731 edt_threep_configure_clock(edt_p, clocks->ch0_clock_freq, 0,
00732 &clocks->ch0_clock_values);
00733 edt_threep_configure_clock(edt_p, clocks->ch1_clock_freq, 1,
00734 &clocks->ch1_clock_values);
00735 edt_threep_configure_clock(edt_p, clocks->ch2_clock_freq, 2,
00736 &clocks->ch2_clock_values);
00737
00738 return 0;
00739 }
00740
00741 void
00742 dump_threep_freq_cntrs( EdtDev * edt_p, int en)
00743 {
00744 int mrd = 0;
00745 int sleep = 50;
00746
00747 edt_reg_write(edt_p, THREEP_FREQ_CNT_EN, 0x00);
00748 edt_msleep(100);
00749 if (en & 0x01)
00750 {
00751
00752 mrd = 0;
00753 edt_reg_write(edt_p, THREEP_FREQ_CNT_EN, 0x00 | (THREEP_FREQ_CNT_EN_MSK | en));
00754 edt_msleep(sleep);
00755 mrd = edt_reg_read(edt_p, THREEP_FREQ_CNT);
00756 printf("ch0: rx: 0x%06x = %d;\tfreq=%f Mhz\n", mrd, mrd, mrd/.0099998/1000000);
00757
00758 mrd = 0;
00759 edt_reg_write(edt_p, THREEP_FREQ_CNT_EN, 0x30 | (THREEP_FREQ_CNT_EN_MSK | en));
00760 edt_msleep(10);
00761 mrd = edt_reg_read(edt_p, THREEP_FREQ_CNT);
00762 printf("ch0: tx: 0x%06x = %d;\tfreq=%f Mhz\n", mrd, mrd, mrd/.0099998/1000000);
00763 }
00764 if (en & 0x02)
00765 {
00766
00767 mrd = 0;
00768 edt_reg_write(edt_p, THREEP_FREQ_CNT_EN, 0x10 | (THREEP_FREQ_CNT_EN_MSK | en));
00769 edt_msleep(sleep);
00770 mrd = edt_reg_read(edt_p, THREEP_FREQ_CNT);
00771 printf("ch1: rx: 0x%06x = %d;\tfreq=%f Mhz\n", mrd, mrd, mrd*2/.0099998/1000000);
00772
00773 mrd = 0;
00774 edt_reg_write(edt_p, THREEP_FREQ_CNT_EN, 0x40 | (THREEP_FREQ_CNT_EN_MSK | en));
00775 edt_msleep(10);
00776 mrd = edt_reg_read(edt_p, THREEP_FREQ_CNT);
00777 printf("ch1: tx: 0x%06x = %d;\tfreq=%f Mhz\n", mrd, mrd, mrd*2/.0099998/1000000);
00778 }
00779 if (en & 0x04)
00780 {
00781
00782 mrd = 0;
00783 edt_reg_write(edt_p, THREEP_FREQ_CNT_EN, 0x20 | (THREEP_FREQ_CNT_EN_MSK | en));
00784 edt_msleep(sleep);
00785 mrd = edt_reg_read(edt_p, THREEP_FREQ_CNT);
00786 printf("ch2: rx: 0x%06x = %d;\tfreq=%f Mhz\n", mrd, mrd, mrd*2/.0099998/1000000);
00787
00788 mrd = 0;
00789 edt_reg_write(edt_p, THREEP_FREQ_CNT_EN, 0x50 | (THREEP_FREQ_CNT_EN_MSK | en));
00790 edt_msleep(10);
00791 mrd = edt_reg_read(edt_p, THREEP_FREQ_CNT);
00792 printf("ch2: tx: 0x%06x = %d;\tfreq=%f Mhz\n", mrd, mrd, mrd*2/.0099998/1000000);
00793 }
00794 }
00795
00796 #define EXT_ADDRESS 0
00797 #define BUSY_STAT 0
00798 #define SERIAL_XFER_BSY_MSK 0x80
00799 #define SERIAL_NACK_MSK 0x40
00800 #define READ_ADD_DATA 1
00801 #define WRITE_ADD 2
00802 #define WRITE_DATA 3
00803 #define READ_ADD_DATA2 4
00804
00822 uint_t
00823 edt_3p_mn_ser_dev_reg_write(EdtDev * edt_p,
00824 uint_t base_desc,
00825 uint_t device_id,
00826 uint_t address,
00827 uint_t value)
00828 {
00829
00830
00831
00832
00833
00834
00835 while ( ((edt_reg_read(edt_p, base_desc+BUSY_STAT)) & SERIAL_XFER_BSY_MSK) != 0)
00836 edt_msleep(0);
00837 edt_reg_write(edt_p, base_desc+EXT_ADDRESS, device_id);
00838 edt_reg_write(edt_p, base_desc+WRITE_ADD, address & 0xff);
00839 edt_reg_write(edt_p, base_desc+WRITE_DATA, value);
00840 while ( ((edt_reg_read(edt_p, base_desc+BUSY_STAT)) & SERIAL_XFER_BSY_MSK) != 0)
00841 edt_msleep(0);
00842 if( ((edt_reg_read(edt_p, base_desc+BUSY_STAT)) & SERIAL_NACK_MSK) != 0)
00843 {
00844 printf("!!!!write NACK1!!!\n");
00845 return 1;
00846 }
00847 return 0;
00848 }
00849
00850 uint_t
00851 edt_3p_mn_ser_dev_reg_read(EdtDev * edt_p,
00852 uint_t base_desc,
00853 uint_t device_id,
00854 uint_t address,
00855 uint_t* bytes)
00856 {
00857 uint_t read_val = 0;
00858 uint_t upbyte = 0;
00859 uint_t lowbyte = 0;
00860
00861
00862
00863
00864
00865
00866 while ( ((edt_reg_read(edt_p, base_desc+BUSY_STAT)) & SERIAL_XFER_BSY_MSK) != 0)
00867 edt_msleep(0);
00868 edt_reg_write(edt_p, base_desc+EXT_ADDRESS, device_id);
00869 edt_reg_write(edt_p, base_desc+READ_ADD_DATA, address & 0xff);
00870
00871
00872 if( ((edt_reg_read(edt_p, base_desc+BUSY_STAT)) & SERIAL_NACK_MSK) != 0)
00873 {
00874 printf("----read NACK1---\n");
00875 return(1);
00876 }
00877 while ( ((edt_reg_read(edt_p, base_desc+BUSY_STAT)) & SERIAL_XFER_BSY_MSK) != 0)
00878 edt_msleep(0);
00879 upbyte = edt_reg_read(edt_p, base_desc+READ_ADD_DATA2);
00880 lowbyte = edt_reg_read(edt_p, base_desc+READ_ADD_DATA);
00881
00882 *bytes = (upbyte<<8) | lowbyte;
00883 while ( ((edt_reg_read(edt_p, base_desc+BUSY_STAT)) & SERIAL_XFER_BSY_MSK) != 0)
00884 edt_msleep(0);
00885 if( ((edt_reg_read(edt_p, base_desc+BUSY_STAT)) & SERIAL_NACK_MSK) != 0)
00886 {
00887 printf("----read NACK2---\n");
00888 return(1);
00889 }
00890 return(0);
00891 }
00892
00893 uint_t
00894 edt_3p_adt7461_reg_read(EdtDev * edt_p,
00895 uint_t base_desc,
00896 uint_t device_id,
00897 uint_t address,
00898 uint_t* bytes)
00899 {
00900 int retval = 0;
00901 retval = edt_3p_mn_ser_dev_reg_write(edt_p, base_desc, device_id, address, address );
00902 if(retval)
00903 return retval;
00904
00905 retval = edt_3p_mn_ser_dev_reg_read(edt_p, base_desc, device_id, address, bytes);
00906 *bytes = (*bytes>>8);
00907
00908 return retval;
00909
00910 }
00911
00912 uint_t
00913 edt_3p_adt7461_reg_write(EdtDev * edt_p,
00914 uint_t base_desc,
00915 uint_t device_id,
00916 uint_t address,
00917 uint_t value)
00918 {
00919 int retval = 0;
00920 retval = edt_3p_mn_ser_dev_reg_write(edt_p, base_desc, device_id, address, value);
00921
00922 return retval;
00923 }
00924
00925 double
00926 edt_3p_v6_temp(EdtDev * edt_p)
00927
00928 {
00929 int retry;
00930 int status;
00931 double ext_temp;
00932
00933 uint_t byte;
00934
00935
00936 retry = 5;
00937 do{
00938 retry--;
00939 status = edt_3p_adt7461_reg_read(edt_p, THREEP_ADT7461_BASE, 3, 0x01, &byte);
00940 }while(status && retry != 0);
00941
00942
00943 if(status)
00944 exit(1);
00945 edt_msleep(100);
00946 ext_temp = (double)byte;
00947
00948 retry = 5;
00949 do{
00950 retry--;
00951 status = edt_3p_adt7461_reg_read(edt_p, THREEP_ADT7461_BASE, 3, 0x10, &byte);
00952 }while(status && retry != 0);
00953
00954 if(status)
00955 exit(1);
00956
00957 ext_temp = ext_temp + .25*(double)(byte>>6);
00958
00959 return ext_temp;
00960 }