📄 lmc_media.c
字号:
sc->lmc_gpio &= ~(LMC_GEP_DATA); LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio); /* * set the clock to high */ sc->lmc_gpio |= LMC_GEP_CLK; LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio); /* * set the clock to low again. */ sc->lmc_gpio &= ~(LMC_GEP_CLK); LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio);}static voidwrite_av9110 (lmc_softc_t * sc, u_int32_t n, u_int32_t m, u_int32_t v, u_int32_t x, u_int32_t r){ int i;#if 0 printk (LMC_PRINTF_FMT ": speed %u, %d %d %d %d %d\n", LMC_PRINTF_ARGS, sc->ictl.clock_rate, n, m, v, x, r);#endif sc->lmc_gpio |= LMC_GEP_SSI_GENERATOR; sc->lmc_gpio &= ~(LMC_GEP_DATA | LMC_GEP_CLK); LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio); /* * Set the TXCLOCK, GENERATOR, SERIAL, and SERIALCLK * as outputs. */ lmc_gpio_mkoutput (sc, (LMC_GEP_DATA | LMC_GEP_CLK | LMC_GEP_SSI_GENERATOR)); sc->lmc_gpio &= ~(LMC_GEP_SSI_GENERATOR); LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio); /* * a shifting we will go... */ for (i = 0; i < 7; i++) write_av9110_bit (sc, n >> i); for (i = 0; i < 7; i++) write_av9110_bit (sc, m >> i); for (i = 0; i < 1; i++) write_av9110_bit (sc, v >> i); for (i = 0; i < 2; i++) write_av9110_bit (sc, x >> i); for (i = 0; i < 2; i++) write_av9110_bit (sc, r >> i); for (i = 0; i < 5; i++) write_av9110_bit (sc, 0x17 >> i); /* * stop driving serial-related signals */ lmc_gpio_mkinput (sc, (LMC_GEP_DATA | LMC_GEP_CLK | LMC_GEP_SSI_GENERATOR));}static voidlmc_ssi_watchdog (lmc_softc_t * const sc){ u_int16_t mii17; struct ssicsr2 { unsigned short dtr:1, dsr:1, rts:1, cable:3, crc:1, led0:1, led1:1, led2:1, led3:1, fifo:1, ll:1, rl:1, tm:1, loop:1; }; struct ssicsr2 *ssicsr; mii17 = lmc_mii_readreg (sc, 0, 17); ssicsr = (struct ssicsr2 *) &mii17; if (ssicsr->cable == 7) { lmc_led_off (sc, LMC_MII16_LED2); } else { lmc_led_on (sc, LMC_MII16_LED2); }}/* * T1 methods *//* * The framer regs are multiplexed through MII regs 17 & 18 * write the register address to MII reg 17 and the * data to MII reg 18. */static voidlmc_t1_write (lmc_softc_t * const sc, int a, int d){ lmc_mii_writereg (sc, 0, 17, a); lmc_mii_writereg (sc, 0, 18, d);}/* Save a warningstatic intlmc_t1_read (lmc_softc_t * const sc, int a){ lmc_mii_writereg (sc, 0, 17, a); return lmc_mii_readreg (sc, 0, 18);}*/static voidlmc_t1_init (lmc_softc_t * const sc){ u_int16_t mii16; int i; sc->ictl.cardtype = LMC_CTL_CARDTYPE_LMC1200; mii16 = lmc_mii_readreg (sc, 0, 16); /* reset 8370 */ mii16 &= ~LMC_MII16_T1_RST; lmc_mii_writereg (sc, 0, 16, mii16 | LMC_MII16_T1_RST); lmc_mii_writereg (sc, 0, 16, mii16); /* set T1 or E1 line. Uses sc->lmcmii16 reg in function so update it */ sc->lmc_miireg16 = mii16; lmc_t1_set_circuit_type(sc, LMC_CTL_CIRCUIT_TYPE_T1); mii16 = sc->lmc_miireg16; lmc_t1_write (sc, 0x01, 0x1B); /* CR0 - primary control */ lmc_t1_write (sc, 0x02, 0x42); /* JAT_CR - jitter atten config */ lmc_t1_write (sc, 0x14, 0x00); /* LOOP - loopback config */ lmc_t1_write (sc, 0x15, 0x00); /* DL3_TS - external data link timeslot */ lmc_t1_write (sc, 0x18, 0xFF); /* PIO - programmable I/O */ lmc_t1_write (sc, 0x19, 0x30); /* POE - programmable OE */ lmc_t1_write (sc, 0x1A, 0x0F); /* CMUX - clock input mux */ lmc_t1_write (sc, 0x20, 0x41); /* LIU_CR - RX LIU config */ lmc_t1_write (sc, 0x22, 0x76); /* RLIU_CR - RX LIU config */ lmc_t1_write (sc, 0x40, 0x03); /* RCR0 - RX config */ lmc_t1_write (sc, 0x45, 0x00); /* RALM - RX alarm config */ lmc_t1_write (sc, 0x46, 0x05); /* LATCH - RX alarm/err/cntr latch */ lmc_t1_write (sc, 0x68, 0x40); /* TLIU_CR - TX LIU config */ lmc_t1_write (sc, 0x70, 0x0D); /* TCR0 - TX framer config */ lmc_t1_write (sc, 0x71, 0x05); /* TCR1 - TX config */ lmc_t1_write (sc, 0x72, 0x0B); /* TFRM - TX frame format */ lmc_t1_write (sc, 0x73, 0x00); /* TERROR - TX error insert */ lmc_t1_write (sc, 0x74, 0x00); /* TMAN - TX manual Sa/FEBE config */ lmc_t1_write (sc, 0x75, 0x00); /* TALM - TX alarm signal config */ lmc_t1_write (sc, 0x76, 0x00); /* TPATT - TX test pattern config */ lmc_t1_write (sc, 0x77, 0x00); /* TLB - TX inband loopback config */ lmc_t1_write (sc, 0x90, 0x05); /* CLAD_CR - clock rate adapter config */ lmc_t1_write (sc, 0x91, 0x05); /* CSEL - clad freq sel */ lmc_t1_write (sc, 0xA6, 0x00); /* DL1_CTL - DL1 control */ lmc_t1_write (sc, 0xB1, 0x00); /* DL2_CTL - DL2 control */ lmc_t1_write (sc, 0xD0, 0x47); /* SBI_CR - sys bus iface config */ lmc_t1_write (sc, 0xD1, 0x70); /* RSB_CR - RX sys bus config */ lmc_t1_write (sc, 0xD4, 0x30); /* TSB_CR - TX sys bus config */ for (i = 0; i < 32; i++) { lmc_t1_write (sc, 0x0E0 + i, 0x00); /* SBCn - sys bus per-channel ctl */ lmc_t1_write (sc, 0x100 + i, 0x00); /* TPCn - TX per-channel ctl */ lmc_t1_write (sc, 0x180 + i, 0x00); /* RPCn - RX per-channel ctl */ } for (i = 1; i < 25; i++) { lmc_t1_write (sc, 0x0E0 + i, 0x0D); /* SBCn - sys bus per-channel ctl */ } mii16 |= LMC_MII16_T1_XOE; lmc_mii_writereg (sc, 0, 16, mii16); sc->lmc_miireg16 = mii16;}static voidlmc_t1_default (lmc_softc_t * const sc){ sc->lmc_miireg16 = LMC_MII16_LED_ALL; sc->lmc_media->set_link_status (sc, LMC_LINK_DOWN); sc->lmc_media->set_circuit_type (sc, LMC_CTL_CIRCUIT_TYPE_T1); sc->lmc_media->set_crc_length (sc, LMC_CTL_CRC_LENGTH_16); /* Right now we can only clock from out internal source */ sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT;}/* * Given a user provided state, set ourselves up to match it. This will * always reset the card if needed. */static voidlmc_t1_set_status (lmc_softc_t * const sc, lmc_ctl_t * ctl){ if (ctl == NULL) { sc->lmc_media->set_circuit_type (sc, sc->ictl.circuit_type); lmc_set_protocol (sc, NULL); return; } /* * check for change in circuit type */ if (ctl->circuit_type == LMC_CTL_CIRCUIT_TYPE_T1 && sc->ictl.circuit_type == LMC_CTL_CIRCUIT_TYPE_E1) sc->lmc_media->set_circuit_type (sc, LMC_CTL_CIRCUIT_TYPE_E1); else if (ctl->circuit_type == LMC_CTL_CIRCUIT_TYPE_E1 && sc->ictl.circuit_type == LMC_CTL_CIRCUIT_TYPE_T1) sc->lmc_media->set_circuit_type (sc, LMC_CTL_CIRCUIT_TYPE_T1); lmc_set_protocol (sc, ctl);}/* * return hardware link status. * 0 == link is down, 1 == link is up. */ static intlmc_t1_get_link_status (lmc_softc_t * const sc){ u_int16_t link_status; int ret = 1; /* LMC5245 (DS3) & LMC1200 (DS1) LED definitions * led0 yellow = far-end adapter is in Red alarm condition * led1 blue = received an Alarm Indication signal * (upstream failure) * led2 Green = power to adapter, Gate Array loaded & driver * attached * led3 red = Loss of Signal (LOS) or out of frame (OOF) * conditions detected on T3 receive signal */ lmc_trace(sc->lmc_device, "lmc_t1_get_link_status in"); lmc_led_on(sc, LMC_DS3_LED2); lmc_mii_writereg (sc, 0, 17, T1FRAMER_ALARM1_STATUS); link_status = lmc_mii_readreg (sc, 0, 18); if (link_status & T1F_RAIS) { /* turn on blue LED */ ret = 0; if(sc->last_led_err[1] != 1){ printk(KERN_WARNING "%s: Receive AIS/Blue Alarm. Far end in RED alarm\n", sc->name); } lmc_led_on(sc, LMC_DS3_LED1); sc->last_led_err[1] = 1; } else { if(sc->last_led_err[1] != 0){ printk(KERN_WARNING "%s: End AIS/Blue Alarm\n", sc->name); } lmc_led_off (sc, LMC_DS3_LED1); sc->last_led_err[1] = 0; } /* * Yellow Alarm is nasty evil stuff, looks at data patterns * inside the channel and confuses it with HDLC framing * ignore all yellow alarms. * * Do listen to MultiFrame Yellow alarm which while implemented * different ways isn't in the channel and hence somewhat * more reliable */ if (link_status & T1F_RMYEL) { ret = 0; if(sc->last_led_err[0] != 1){ printk(KERN_WARNING "%s: Receive Yellow AIS Alarm\n", sc->name); } lmc_led_on(sc, LMC_DS3_LED0); sc->last_led_err[0] = 1; } else { if(sc->last_led_err[0] != 0){ printk(KERN_WARNING "%s: End of Yellow AIS Alarm\n", sc->name); } lmc_led_off(sc, LMC_DS3_LED0); sc->last_led_err[0] = 0; } /* * Loss of signal and los of frame * Use the green bit to identify which one lit the led */ if(link_status & T1F_RLOF){ ret = 0; if(sc->last_led_err[3] != 1){ printk(KERN_WARNING "%s: Local Red Alarm: Loss of Framing\n", sc->name); } lmc_led_on(sc, LMC_DS3_LED3); sc->last_led_err[3] = 1; } else { if(sc->last_led_err[3] != 0){ printk(KERN_WARNING "%s: End Red Alarm (LOF)\n", sc->name); } if( ! (link_status & T1F_RLOS)) lmc_led_off(sc, LMC_DS3_LED3); sc->last_led_err[3] = 0; } if(link_status & T1F_RLOS){ ret = 0; if(sc->last_led_err[2] != 1){ printk(KERN_WARNING "%s: Local Red Alarm: Loss of Signal\n", sc->name); } lmc_led_on(sc, LMC_DS3_LED3); sc->last_led_err[2] = 1; } else { if(sc->last_led_err[2] != 0){ printk(KERN_WARNING "%s: End Red Alarm (LOS)\n", sc->name); } if( ! (link_status & T1F_RLOF)) lmc_led_off(sc, LMC_DS3_LED3); sc->last_led_err[2] = 0; } sc->lmc_xinfo.t1_alarm1_status = link_status; lmc_mii_writereg (sc, 0, 17, T1FRAMER_ALARM2_STATUS); sc->lmc_xinfo.t1_alarm2_status = lmc_mii_readreg (sc, 0, 18); lmc_trace(sc->lmc_device, "lmc_t1_get_link_status out"); return ret;}/* * 1 == T1 Circuit Type , 0 == E1 Circuit Type */static voidlmc_t1_set_circuit_type (lmc_softc_t * const sc, int ie){ if (ie == LMC_CTL_CIRCUIT_TYPE_T1) { sc->lmc_miireg16 |= LMC_MII16_T1_Z; sc->ictl.circuit_type = LMC_CTL_CIRCUIT_TYPE_T1; printk(KERN_INFO "%s: In T1 Mode\n", sc->name); } else { sc->lmc_miireg16 &= ~LMC_MII16_T1_Z; sc->ictl.circuit_type = LMC_CTL_CIRCUIT_TYPE_E1; printk(KERN_INFO "%s: In E1 Mode\n", sc->name); } lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16); }/* * 0 == 16bit, 1 == 32bit */static voidlmc_t1_set_crc_length (lmc_softc_t * const sc, int state){ if (state == LMC_CTL_CRC_LENGTH_32) { /* 32 bit */ sc->lmc_miireg16 |= LMC_MII16_T1_CRC; sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_32; sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_4; } else { /* 16 bit */ sc->lmc_miireg16 &= ~LMC_MII16_T1_CRC; sc->ictl.crc_length = LMC_CTL_CRC_LENGTH_16; sc->lmc_crcSize = LMC_CTL_CRC_BYTESIZE_2; } lmc_mii_writereg (sc, 0, 16, sc->lmc_miireg16);}/* * 1 == internal, 0 == external */static voidlmc_t1_set_clock (lmc_softc_t * const sc, int ie){ int old; old = ie; if (ie == LMC_CTL_CLOCK_SOURCE_EXT) { sc->lmc_gpio &= ~(LMC_GEP_SSI_TXCLOCK); LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio); sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_EXT; if(old != ie) printk (LMC_PRINTF_FMT ": clock external\n", LMC_PRINTF_ARGS); } else { sc->lmc_gpio |= LMC_GEP_SSI_TXCLOCK; LMC_CSR_WRITE (sc, csr_gp, sc->lmc_gpio); sc->ictl.clock_source = LMC_CTL_CLOCK_SOURCE_INT; if(old != ie) printk (LMC_PRINTF_FMT ": clock internal\n", LMC_PRINTF_ARGS); }}static voidlmc_t1_watchdog (lmc_softc_t * const sc){}static voidlmc_set_protocol (lmc_softc_t * const sc, lmc_ctl_t * ctl){ if (ctl == 0) { sc->ictl.keepalive_onoff = LMC_CTL_ON; return; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -