/*******************************************************************************
**
**  onuPonLedInit
**  ____________________________________________________________________________
**
**  DESCRIPTION: The function init led operation
**
**  PARAMETERS:  None
**
**  OUTPUTS:     None
**
**  RETURNS:     MV_OK or MV_ERROR
**
*******************************************************************************/
MV_STATUS onuPonLedInit(void)
{
	MV_STATUS status;
	MV_U32    gpioGroup, gpioMask;

	PON_GPIO_GET(BOARD_GPP_SYS_LED, gpioGroup, gpioMask);
	if (gpioMask != PON_GPIO_NOT_USED) {
		status = mvGppTypeSet(gpioGroup, gpioMask, 0/*output*/);
		if (status != MV_OK)
			return(status);
	}

	PON_GPIO_GET(BOARD_GPP_PON_LED, gpioGroup, gpioMask);
	if (gpioMask != PON_GPIO_NOT_USED) {
		status = mvGppTypeSet(gpioGroup, gpioMask, 0/*output*/);
		if (status != MV_OK)
			return(status);
	}

	status  = asicOntMiscRegWrite(mvAsicReg_PON_LED_BLINK_FREQ_A_ON, 0x30000000, 0);
	if (status != MV_OK)
		return(status);

	status  = asicOntMiscRegWrite(mvAsicReg_PON_LED_BLINK_FREQ_A_OFF, 0x30000000, 0);
	if (status != MV_OK)
		return(status);

	status  = asicOntMiscRegWrite(mvAsicReg_PON_LED_BLINK_FREQ_B_ON, 0x15000000, 0);
	if (status != MV_OK)
		return(status);

	status  = asicOntMiscRegWrite(mvAsicReg_PON_LED_BLINK_FREQ_B_OFF, 0x15000000, 0);

	return(status);
}
/*******************************************************************************
**
**  onuPonPatternBurstTimerHndl
**  ____________________________________________________________________________
**
**  DESCRIPTION: The function is the timer callback when periodic burst is enabled
**
**  PARAMETERS:  when on  == true  transmission is on
**               when off == false transmission is off
**
**  OUTPUTS:     None
**
**  RETURNS:     MV_OK or error
**
*******************************************************************************/
void      onuPonPatternBurstTimerHndl(void)
{
	MV_U32  time_interval;
	MV_BOOL is_transmit_up;
	unsigned long flags;
	MV_STATUS status;

	spin_lock_irqsave(&onuPonIrqLock, flags);

	onuPonResourceTbl_s.onuPonPatternBurstTimerId.onuPonTimerActive = ONU_PON_TIMER_NOT_ACTIVE;

	time_interval  = (transmit_up == MV_TRUE ? time_interval_down : time_interval_up);
	is_transmit_up = (transmit_up == MV_TRUE ? MV_FALSE : MV_TRUE);

	if (onuPonResourceTbl_s.onuPonPatternBurstTimerId.onuPonTimerPeriodic == 0)
		onuPonResourceTbl_s.onuPonPatternBurstTimerId.onuPonTimerPeriodic = 1;

	onuPonPatternBurstTransmit(is_transmit_up);

	/*switch on/off selected pattern*/
	status = asicOntMiscRegWrite(mvAsicReg_PT_PATTERN_ENABLED, is_transmit_up, 0);
	if (status != MV_OK) {
		 mvPonPrint(PON_PRINT_ERROR, PON_ISR_MODULE,
					"ERROR: asicOntMiscRegWrite failed in PON pattern burst timer handler\n\r");
	 }

	onuPonTimerUpdate(&(onuPonResourceTbl_s.onuPonPatternBurstTimerId),0,time_interval,1);

	spin_unlock_irqrestore(&onuPonIrqLock, flags);
}
/*******************************************************************************
**
**  onuPonPatternBurstTransmit
**  ____________________________________________________________________________
**
**  DESCRIPTION: The function turn on or off actuacl burst transmission
**
**  PARAMETERS:  when on  == true  transmission is on
**               when off == false transmission is off
**
**  OUTPUTS:     None
**
**  RETURNS:     MV_OK or error
**
*******************************************************************************/
MV_STATUS onuPonPatternBurstTransmit(MV_BOOL on)
{
	MV_STATUS status;
	MV_U32    gpioGroup, gpioMask;
	MV_U32    trans_value = 0;

	if (mvCtrlRevGet() == ONU_ASIC_REV_Z2) {

		/* ASIC Rev Z2 */
		/* =========== */
		PON_GPIO_GET(BOARD_GPP_PON_XVR_TX, gpioGroup, gpioMask);
		if (gpioMask == PON_GPIO_NOT_USED)
			return(MV_ERROR);

		trans_value = (on == MV_TRUE ? ~gpioMask /*0*/: gpioMask /*1*/);

		status = mvGppTypeSet(gpioGroup, gpioMask, trans_value);
		if (status != MV_OK)
			return(MV_ERROR);

	} else if (mvCtrlRevGet() == ONU_ASIC_REV_A0) {

		/* ASIC Rev A0 */
		/* =========== */
		status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_IO_EN, ONU_PHY_OUTPUT, 0);
		if (status != MV_OK) {
			mvPonPrint(PON_PRINT_ERROR, PON_ISR_MODULE,
				   "ERROR: asicOntMiscRegWrite failed for PON phy ctrl enable - output\n\r");
			return(MV_ERROR);
		}
	}

	transmit_up = on;
	return(MV_OK);
}
/*******************************************************************************
**
**  onuPonPatternBurstOff
**  ____________________________________________________________________________
**
**  DESCRIPTION: The function Turn off  pattern burst and reconnect PON MAC
**
**  PARAMETERS:  None
**
**  OUTPUTS:     None
**
**  RETURNS:     MV_OK or error
**
*******************************************************************************/
MV_STATUS onuPonPatternBurstOff(void)
{
	MV_STATUS  status;

	onuPonPatternBurstTransmit(MV_TRUE);
	onuPonPatternBurstEnable(MV_FALSE);

	status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_INTERNAL_EN_LOOP_TIMING, 0x1, 0);
	if (status != MV_OK)
		return(status);

	/*Set system in MAC mode, meaning connect the PON MAC*/
	status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_INTERNAL_OPEN_TX_DOOR_15, 0x0, 0);
	if (status != MV_OK)
		return(status);

	/*Set serdes power down in phy mode*/
	status = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_POWER_PHY_MODE, 0x8d00,0);
	if (status != MV_OK)
		return(status);


	/* Set the output enable of the GP_BEN IO to Output */
	status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_IO_EN, ONU_PHY_OUTPUT, 0);
	if (status != MV_OK)
		return(status);

	/*turn off selected pattern*/
	status  = asicOntMiscRegWrite(mvAsicReg_PT_PATTERN_ENABLED, 0x0, 0);
	if (status != MV_OK)
		return(status);

	/*stop tranmission */
	status = onuPonPatternBurstTransmit(MV_FALSE);
	if (status != MV_OK)
		return(status);
	/*stop timer operation*/
	onuPonTimerDisable(&(onuPonResourceTbl_s.onuPonPatternBurstTimerId));

	time_interval_up     = 0;
	time_interval_down   = 0;

	return(MV_OK);
}
/*******************************************************************************
**
**  onuEponAsicQueueDisable
**  ____________________________________________________________________________
** 
**  DESCRIPTION: The function disables all queues for the specific mac Id
**               except queue 0
**               
**  PARAMETERS:  MV_U32 macId
**
**  OUTPUTS:     None
**
**  RETURNS:     MV_OK or error
**                   
*******************************************************************************/
MV_STATUS onuEponAsicQueueDisable(MV_U32 macId) 
{
  switch (macId) 
  {
    case 0: asicOntMiscRegWrite(mvAsicReg_GUNIT_LLID0_QUEUES, 0xFE00, 0); break;
    case 1: asicOntMiscRegWrite(mvAsicReg_GUNIT_LLID1_QUEUES, 0xFE00, 0); break;
    case 2: asicOntMiscRegWrite(mvAsicReg_GUNIT_LLID2_QUEUES, 0xFE00, 0); break;
    case 3: asicOntMiscRegWrite(mvAsicReg_GUNIT_LLID3_QUEUES, 0xFE00, 0); break;
    case 4: asicOntMiscRegWrite(mvAsicReg_GUNIT_LLID4_QUEUES, 0xFE00, 0); break;
    case 5: asicOntMiscRegWrite(mvAsicReg_GUNIT_LLID5_QUEUES, 0xFE00, 0); break;
    case 6: asicOntMiscRegWrite(mvAsicReg_GUNIT_LLID6_QUEUES, 0xFE00, 0); break;
    case 7: asicOntMiscRegWrite(mvAsicReg_GUNIT_LLID7_QUEUES, 0xFE00, 0); break;
  }

  return(MV_OK);
}
/*******************************************************************************
**
**  onuPonDyingGaspProcess
**  ____________________________________________________________________________
**
**  DESCRIPTION: The function process dying gasp function, kill VoIP
**
**  PARAMETERS:  None
**
**  OUTPUTS:     None
**
**  RETURNS:     MV_OK or error
**
*******************************************************************************/
MV_STATUS onuPonDyingGaspProcess(void)
{
	MV_STATUS status;
	MV_U32 boardType;

	/* GPON/EPON configuration of Dying Gasp */
	/* ===================================== */
	boardType = mvBoardIdGet();

	switch (boardType) {
	case RD_88F6510_SFU_ID:
	case RD_88F6560_GW_ID:
	case RD_88F6530_MDU_ID:
		status  = asicOntMiscRegWrite(mvAsicReg_PON_MPP_24, 0, 0); /* power down voip */
		break;
	default:
		status = MV_ERROR;
	}

	return(status);
}
/*******************************************************************************
**
**  onuEponOperate
**  ____________________________________________________________________________
** 
**  DESCRIPTION: The function execute onu operate init sequence
**               
**  PARAMETERS:  None
**
**  OUTPUTS:     None
**
**  RETURNS:     MV_OK or error
**           
*******************************************************************************/
MV_STATUS onuEponOperate(void)
{
  MV_STATUS status;
  MV_U32    interruptMask;

  /* enable onu pon interrupt mask */
  interruptMask = (ONU_EPON_INTERRUPTS);
  interruptMask &= ~(ONU_EPON_TIMESTAMP_VALUE_MATCH_MASK);
  status = mvOnuEponMacPonInterruptMaskSet(interruptMask);
  if (status != MV_OK)
  {
    mvPonPrint(PON_PRINT_ERROR, PON_INIT_MODULE,
               "ERROR: (%s:%d) Enable PON interrupt mask\n\r", __FILE_DESC__, __LINE__);
    return(status);
  }


  /* Enable MAC */
  status = mvOnuEponMacOnuRxEnableSet(ONU_RX_EN);
  if (status != MV_OK)
  {
    mvPonPrint(PON_PRINT_ERROR, PON_INIT_MODULE,
               "ERROR: (%s:%d) mvOnuEponMacOnuRxEnableSet\n\r", __FILE_DESC__, __LINE__);
    return(MV_ERROR);
  }
 
  status = mvOnuEponMacOnuTxEnableSet(ONU_TX_EN, 0);
  if (status != MV_OK)
  {
    mvPonPrint(PON_PRINT_ERROR, PON_INIT_MODULE,
               "ERROR: (%s:%d) mvOnuEponMacOnuTxEnableSet\n\r", __FILE_DESC__, __LINE__);
    return(MV_ERROR);
  }

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_IO_EN, ONU_PHY_OUTPUT, 0); 
  if (status != MV_OK)
  {
	mvPonPrint(PON_PRINT_ERROR, PON_INIT_MODULE,
	  		 "ERROR: (%s:%d) mvOnuEponMacOnuIOEnable\n\r", __FILE_DESC__, __LINE__);
	return(MV_ERROR);
  }

  /* start onu pon pon pm timer */
  onuPonTimerEnable(&(onuPonResourceTbl_s.onuPonPmTimerId));

  /* start onu pon pon mpc timer */
  onuPonTimerEnable(&(onuPonResourceTbl_s.onuPonMpcpTimerId));

  if (onuEponDbOnuSwRprtTimerTypeGet() == ONU_EPON_HW_DBA_RPRT_TIMER)
  {
    /* start onu pon pon tx module timer */
    onuPonTimerEnable(&(onuPonResourceTbl_s.onuPonHwRprtTxModTimerId));

    /* Enable DBA Report message handling */
	onuEponIsrTimerHwReportStateSet(MV_TRUE, /* Enable */
									dbaRprtT0StateVal,
									dbaRprtT0StateInterval,
									dbaRprtT1StateVal,
									dbaRprtT1StateInterval);

  }

  return(MV_OK);
}
/*******************************************************************************
**
**  onuPonPatternBurstOn
**  ____________________________________________________________________________
**
**  DESCRIPTION: The function start TX transmissions of a selected pattern as periodic or static burst
**
**  PARAMETERS:
**      MV_U32 pattern      0x1     1T
**                          0x2     2T
**                          0x80    PRBS - 9
**                          0x82    PRBS - 15
**                          0x83    PRBS - 23
**     MV_BOOL isPeriodic   TX burst can be either static (in this case the following parameters has no effect)
**                          and this parameter is FALSE OR periodic in this case this parameters is TRUE
**     MV_U32 period        cycle time - the time in micro seconds between the start of on peak and the other
**                          (must be greater then the duration interval)
**     MV_U32 duration      peak time interval in micro seconds  (must be smaller then the duration interval)

**
**  OUTPUTS:     None
**
**  RETURNS:     MV_OK or error
**
*******************************************************************************/
MV_STATUS onuPonPatternBurstOn(MV_U32 pattern, MV_BOOL isPeriodic, MV_U32 period, MV_U32 duration)
{
	MV_STATUS  status;

	/*pattern validation*/
	if (!((pattern == ONU_PON_TX_PATTERN_TYPE_T1) ||
	      (pattern == ONU_PON_TX_PATTERN_TYPE_T2) ||
	      (pattern == ONU_PON_TX_PATTERN_TYPE_PRBS_9) ||
	      (pattern == ONU_PON_TX_PATTERN_TYPE_PRBS_15) ||
	      (pattern == ONU_PON_TX_PATTERN_TYPE_PRBS_23))) {

		mvPonPrint(PON_PRINT_ERROR, PON_INIT_MODULE, "Wrong pattern type value %d \n", pattern);
		return MV_BAD_VALUE;
	}

	if ((isPeriodic == MV_TRUE) && (duration >= period)) {
		mvPonPrint(PON_PRINT_ERROR, PON_INIT_MODULE,
			   "Period value %d MUST be greater then duration value %d \n", period, duration);
		return MV_BAD_VALUE;
	}

	/*in case of sequential call to onuPonPatternBurstOn*/
	/*stop timer operation and transmissions*/
	onuPonTimerDisable(&(onuPonResourceTbl_s.onuPonPatternBurstTimerId));
	onuPonPatternBurstTransmit(MV_TRUE);
	onuPonPatternBurstEnable(MV_FALSE);
	time_interval_up     = 0;
	time_interval_down   = 0;

	if (mvCtrlRevGet() == ONU_ASIC_REV_Z2) {

		/* ASIC Rev Z2 */
		/* =========== */
		status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_IO_EN, ONU_PHY_INPUT, 0);
		if (status != MV_OK)
			return(status);

	} else if (mvCtrlRevGet() == ONU_ASIC_REV_A0) {

		/* ASIC Rev A0 */
		/* =========== */
		status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_IO_EN, ONU_PHY_OUTPUT, 0);
		if (status != MV_OK)
			return(status);
	}

	status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_INTERNAL_EN_LOOP_TIMING, 0x0, 0);
	if (status != MV_OK)
		return(status);

	/*Set system in PHY mode, meaning disconnect the PON MAC*/
	status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_INTERNAL_OPEN_TX_DOOR_15, 0x1, 0);
	if (status != MV_OK)
		return(status);

	/*Set sedes power up in phy mode*/
	status = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_POWER_PHY_MODE, 0xfd04,0);
	if (status != MV_OK)
		return(status);

	/*set select on pattern*/
	status  = asicOntMiscRegWrite(mvAsicReg_PT_PATTERN_SELECT, 0x7, 0);
	if (status != MV_OK)
		return(status);

	/*set pattern type*/
	status  = asicOntMiscRegWrite(mvAsicReg_PT_PATTERN_DATA, pattern, 0);
	if (status != MV_OK)
		return(status);

	/*turn on selected pattern*/
	status  = asicOntMiscRegWrite(mvAsicReg_PT_PATTERN_ENABLED, 0x1, 0);
	if (status != MV_OK)
		return(status);


	onuPonPatternBurstEnable(MV_TRUE);
	if (isPeriodic == MV_TRUE) {
		/*periosic burst*/
		time_interval_up     = duration;
		time_interval_down   = (period - duration);
		transmit_up          = MV_TRUE;
		onuPonTimerUpdate(&(onuPonResourceTbl_s.onuPonPatternBurstTimerId),0,time_interval_up,1);

	}

	return(MV_OK);
}
/*******************************************************************************
**
**  onuPonPatternBurstEnable
**  ____________________________________________________________________________
**
**  DESCRIPTION:
**
**  PARAMETERS:  bool on
**
**  OUTPUTS:     None
**
**  RETURNS:     MV_OK or error
**
*******************************************************************************/
MV_STATUS onuPonPatternBurstEnable(bool on)
{
	MV_STATUS status;
	MV_U32    gpioGroup, gpioMask;
	MV_U32    trans_value = 0;
	MV_U32    polarity;

	if (MV_6601_DEV_ID == mvCtrlModelGet())
	{
	       /* PHY control register - force enable */
	       status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_SW_FORCE, 1, 0);
	       if (status != MV_OK) {
		       mvPonPrint(PON_PRINT_ERROR, PON_ISR_MODULE,
			     "ERROR: asicOntMiscRegWrite failed for PON phy SW ctrl force\n\r");
		       return(MV_ERROR);
	       }

	       /* PHY control register - force enable value - according to polarity */
	       status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_SW_VALUE, 1, 0);
	       if (status != MV_OK) {
		       mvPonPrint(PON_PRINT_ERROR, PON_ISR_MODULE,
				  "ERROR: asicOntMiscRegWrite failed for PON phy ctrl SW force value %d\n\r",
				  trans_value);
		       return(MV_ERROR);
	       }

	} else if (mvCtrlRevGet() == ONU_ASIC_REV_Z2) {

	    	/* ASIC Rev Z2 */
	    	/* =========== */
		PON_GPIO_GET(BOARD_GPP_PON_XVR_TX, gpioGroup, gpioMask);
		if (gpioMask == PON_GPIO_NOT_USED)
			return MV_ERROR;

		trans_value = ((on == MV_TRUE) ? (gpioMask/*1*/) : (~gpioMask/*0*/));

		status = mvGppValueSet(gpioGroup, gpioMask, trans_value);
		if (status != MV_OK)
			return(MV_ERROR);

	} else if (mvCtrlRevGet() == ONU_ASIC_REV_A0) {

		/* ASIC Rev A0 */
		/* =========== */
		/* PHY control register - force enable */
		status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_FORCE_BEN_IO_EN, 1, 0);
		if (status != MV_OK) {
			mvPonPrint(PON_PRINT_ERROR, PON_ISR_MODULE,
				   "ERROR: asicOntMiscRegWrite failed for PON phy ctrl force\n\r");
			return(MV_ERROR);
		}

        polarity = onuP2PDbXvrBurstEnablePolarityGet();

		/* XVR polarity */
		/* XVR polarity == 0, Active High, transmit 1 to the line  */
		/* XVR polarity == 1, Active Low, transmit 0 to the line  */

		/* P2P mode */
		/* Force Value == 0, transmit 0 to the line  */
		/* Force Value == 1, transmit 1 to the line  */

		/* Setting P2P should be reversed from XVR polarity */
		/* XVR polarity == 0, Active High, write 1 for Force Value */
		/* XVR polarity == 1, Active Low, write 0 for Force Value */

		/* PHY control register - force enable value - according to polarity */
		status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_FORCE_BEN_IO_VAL, polarity, 0);
		if (status != MV_OK) {
			mvPonPrint(PON_PRINT_ERROR, PON_ISR_MODULE,
				   "ERROR: asicOntMiscRegWrite failed for PON phy ctrl force value %d\n\r",
				   trans_value);
			return(MV_ERROR);
		}
	}

	transmit_up = on;
	return(MV_OK);
}
/*******************************************************************************
**
**  mvOnuPonMacBurstEnableInit
**  ____________________________________________________________________________
**
**  DESCRIPTION: The function init Burst Enable MPP
**
**  PARAMETERS:  None
**
**  OUTPUTS:     None
**
**  RETURNS:     MV_OK or error
**
*******************************************************************************/
MV_STATUS mvOnuPonMacBurstEnableInit(void)
{
	MV_U32    gpioGroup, gpioMask;
	MV_STATUS status = MV_OK;

	if (MV_6601_DEV_ID == mvCtrlModelGet())
	{
	       /* PHY control register - output status set */
	       status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_IO_EN, ONU_PHY_OUTPUT, 0);
	       if (status != MV_OK) {
		       mvPonPrint(PON_PRINT_ERROR, PON_ISR_MODULE,
				  "ERROR: asicOntMiscRegWrite failed for PON phy ctrl enable - output\n\r");
		       return(MV_ERROR);
	       }

	       /* Set SW BEN control for MC tranciever */
	       status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_SW_HW_SELECT, 1, 0);
	       if (status != MV_OK) {
		       mvPonPrint(PON_PRINT_ERROR, PON_ISR_MODULE,
			"ERROR: asicOntMiscRegWrite failed for PON phy SW ctrl select\n\r");
		       return(MV_ERROR);
	       }

	       /* PHY control register - force disable */
	       status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_SW_FORCE, 0, 0);
	       if (status != MV_OK) {
		       mvPonPrint(PON_PRINT_ERROR, PON_ISR_MODULE,
			     "ERROR: asicOntMiscRegWrite failed for PON phy SW ctrl not force\n\r");
		       return(MV_ERROR);
	       }
	} else if (mvCtrlRevGet() == ONU_ASIC_REV_Z2) {

		/* KW2 ASIC Rev Z2 */
		/* =============== */
		PON_GPIO_GET(BOARD_GPP_PON_XVR_TX, gpioGroup, gpioMask);
		if (gpioMask == PON_GPIO_NOT_USED)
			return MV_ERROR;

		status = mvGppTypeSet(gpioGroup, gpioMask, ~gpioMask/* 0-output allow transsmit*/);

		if (status == MV_OK)
			status = mvGppValueSet(gpioGroup, gpioMask, ~gpioMask/*0-disable signal*/);
		else
			return(status);

		if (status == MV_OK)
			status = mvGppTypeSet(gpioGroup, gpioMask, gpioMask /* 0-input NOT allow transsmit*/);

	} else if (mvCtrlRevGet() == ONU_ASIC_REV_A0) {

		/* KW2 ASIC Rev A0 */
		/* =============== */
		/* PHY control register - output status set */
		status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_IO_EN, ONU_PHY_OUTPUT, 0);
		if (status != MV_OK) {
			mvPonPrint(PON_PRINT_ERROR, PON_ISR_MODULE,
				   "ERROR: asicOntMiscRegWrite failed for PON phy ctrl enable - output\n\r");
			return(MV_ERROR);
		}

		/* PHY control register - force disable */
		status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_FORCE_BEN_IO_EN, 0, 0);
		if (status != MV_OK) {
			mvPonPrint(PON_PRINT_ERROR, PON_ISR_MODULE,
				   "ERROR: asicOntMiscRegWrite failed for PON phy ctrl not force\n\r");
			return(MV_ERROR);
		}
	}

	return(status);
}
/*******************************************************************************
**
**  onuPonLedHandler
**  ____________________________________________________________________________
**
**  DESCRIPTION: The function handles led operation
**
**  PARAMETERS:  None
**
**  OUTPUTS:     None
**
**  RETURNS:     MV_OK or MV_ERROR
**
*******************************************************************************/
MV_STATUS onuPonLedHandler(MV_U32 led, MV_U32 action)
{
	MV_STATUS status;
	MV_U32    gpioGroup = 0;
	MV_U32    gpioMask = 0;

	if (led == ONU_PON_SYS_LED) {

		PON_GPIO_GET(BOARD_GPP_SYS_LED, gpioGroup, gpioMask);
		if (gpioMask != PON_GPIO_NOT_USED) {
			status = mvGppValueSet(gpioGroup, gpioMask, gpioMask);
			if (status != MV_OK)
				return(status);
		}

	} else if (led == ONU_PON_SYNC_LED) {

		PON_GPIO_GET(BOARD_GPP_PON_LED, gpioGroup, gpioMask);
		if (gpioMask != PON_GPIO_NOT_USED) {
			switch (action) {
			case ACTIVE_LED_OFF:
				status  = mvGppValueSet(gpioGroup, gpioMask, ~gpioMask);
				if (status != MV_OK)
					return(status);
				break;

			case ACTIVE_LED_BLINK_SLOW:
				status  = mvGppValueSet(gpioGroup, gpioMask, gpioMask);
				if (status != MV_OK)
					return(status);
				status  = mvGppBlinkEn(gpioGroup, gpioMask, gpioMask);
				if (status != MV_OK)
					return(status);
				status  = asicOntMiscRegWrite(mvAsicReg_PON_SYNC_LED_BLINK_FREQ, 0, 0);
				if (status != MV_OK)
					return(status);
				break;

			case ACTIVE_LED_BLINK_FAST:
				status  = mvGppValueSet(gpioGroup, gpioMask, gpioMask);
				if (status != MV_OK)
					return(status);
				status  = mvGppBlinkEn(gpioGroup, gpioMask, gpioMask);
				if (status != MV_OK)
					return(status);
				status  = asicOntMiscRegWrite(mvAsicReg_PON_SYNC_LED_BLINK_FREQ, 1, 0);
				if (status != MV_OK)
					return(status);
				break;

			case ACTIVE_LED_ON:
				status  = mvGppValueSet(gpioGroup, gpioMask, gpioMask);
				if (status != MV_OK)
					return(status);
				status  = mvGppBlinkEn(gpioGroup, gpioMask, ~gpioMask);
				if (status != MV_OK)
					return(status);
				break;
			}
		}
	}

	return(MV_OK);
}
Exemple #12
0
/*******************************************************************************
**
**  onuEponSwitchOver
**  ____________________________________________________________________________
** 
**  DESCRIPTION: The function switch between EPON and GPON
**               
**  PARAMETERS:  None
**
**  OUTPUTS:     None    
**
**  RETURNS:     MV_OK or error
**
*******************************************************************************/
MV_STATUS onuEponSwitchOver(void)
{
  MV_STATUS status;

  /* STOP Traffic */


  /* Close TX EN */
  printk("onuPonSwitchOver - Close TX EN\n\r");
  status = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_IO_EN, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  /* Put PON MAC to Reset */
  printk("onuPonSwitchOver - Put PON MAC to Reset\n\r");
  status = asicOntMiscRegWrite(mvAsicReg_PON_MAC_SW_RESET_CTRL, 0x0, 0); 
  if (status != MV_OK) 
    return(status);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_EN, 0x0, 0); 
  if (status != MV_OK) 
   return(status);
  
  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_SEL, 0x0, 0); 
  if (status != MV_OK) 
    return(status);
  
  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_EN, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  /* Switch to new PON MAC */
  printk("onuPonSwitchOver - Switch to new PON MAC - EPON\n\r");
  status = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_XPON_CTRL, 1, 0); 
  if (status != MV_OK) 
    return(status);

  /* Take PON MAC out of Reset */
  printk("onuPonSwitchOver - Take PON MAC out of Reset\n\r");
  status = asicOntMiscRegWrite(mvAsicReg_PON_MAC_SW_RESET_CTRL, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  /* Re-init Serdes */
  printk("onuPonSwitchOver - Re-init Serdes\n\r");

  printk("onuPonSwitchOver - Put PON MAC to Reset\n\r");
  status = asicOntMiscRegWrite(mvAsicReg_PON_MAC_SW_RESET_CTRL, 0x0, 0); 
  if (status != MV_OK) 
    return(status);


  printk("onuPonSerdeSwitchOverInit - Serdes CLK EN\n\r");
  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_EN, 0x0, 0); 
  if (status != MV_OK) 
      return(status);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_SEL, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_EN, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  /* Take PON MAC out of Reset */
  printk("onuPonSwitchOver - Take PON MAC out of Reset\n\r");
  status = asicOntMiscRegWrite(mvAsicReg_PON_MAC_SW_RESET_CTRL, 0x1, 0); 
  if (status != MV_OK) 
	return(status);

  /* Open TX EN */
  printk("onuPonSwitchOver - Open TX EN\n\r");
  status = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_IO_EN, 0x0, 0); 
  if (status != MV_OK) 
    return(status);

  return(MV_OK);
}
Exemple #13
0
/*******************************************************************************
**
**  onuEponSerdesInit
**  ____________________________________________________________________________
** 
**  DESCRIPTION: The function set serdes
**               
**  PARAMETERS:  None
**
**  OUTPUTS:     None    
**
**  RETURNS:     MV_OK or error
**
*******************************************************************************/
MV_STATUS onuEponSerdesInit(void)
{
  MV_STATUS status;
  MV_U32    loop = 0;

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_EN, 0x0, 0); 
  if (status != MV_OK) 
   return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_MAC_GPON_CLK_EN, 0x0, 0); 
  if (status != MV_OK) 
   return(status);

  mvOsDelay(40);

  /* PON MAC init to GPON mode */
  /* ========================= */

  /* Put PON MAC to Reset */
  status = asicOntMiscRegWrite(mvAsicReg_PON_MAC_SW_RESET_CTRL, 0x0, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  /* Switch to new PON MAC */
  status = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_XPON_CTRL, 0, 0);
  if (status != MV_OK)
    return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_SEL, 0x0, 0);
  if (status != MV_OK)
    return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_MAC_GPON_CLK_EN, 0x1, 0);
  if (status != MV_OK)
   return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_EN, 0x1, 0);
  if (status != MV_OK)
    return(status);

  mvOsDelay(40);

  /* Take PON MAC out of Reset */
  status = asicOntMiscRegWrite(mvAsicReg_PON_MAC_SW_RESET_CTRL, 0x1, 0);
  if (status != MV_OK)
    return(status);

  mvOsDelay(40);

  /* PON MAC init to EPON mode */
  /* ========================= */

  /* Put PON MAC to Reset */
  status = asicOntMiscRegWrite(mvAsicReg_PON_MAC_SW_RESET_CTRL, 0x0, 0);
  if (status != MV_OK)
    return(status);

  mvOsDelay(40);

  /* Switch to new PON MAC */
  status = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_XPON_CTRL, 1, 0);
  if (status != MV_OK)
    return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_SEL, 0x0, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_MAC_GPON_CLK_EN, 0x1, 0); 
  if (status != MV_OK) 
   return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_EN, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  /* Take PON MAC out of Reset */
  status = asicOntMiscRegWrite(mvAsicReg_PON_MAC_SW_RESET_CTRL, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  /*    EPON configuration of XVR SD is done by LSP code (mvBoardEnvSpec.h, mvCtrlEnvLib.c) */

  /*    EPON configuration/SerDes power up and init sequence   */
  /* ========================================================= */

  do 
  {
	loop++;

	status = onuEponSerdesPowerUpSeq();
	if      (status == MV_ERROR) return(status);
	else if (status == MV_OK)    break;

  } while (loop < 10);

  if (loop >= 10) 
  {
	mvPonPrint(PON_PRINT_ERROR, PON_INIT_MODULE, "======================================\n");
    mvPonPrint(PON_PRINT_ERROR, PON_INIT_MODULE, "========= Serdes Not Sync !!! ========\n");
	mvPonPrint(PON_PRINT_ERROR, PON_INIT_MODULE, "======================================\n");
  }

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_RST_TX_DOUT, 0x0, 0);  
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_INTERNAL_OPEN_TX_DOOR, 0x0, 0);  
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_EN, 0x0, 0); 
  if (status != MV_OK) 
      return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_SEL, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_CLK_EN, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

 // status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_1_BEN_IO_EN, 0x0, 0); 
 // if (status != MV_OK) 
 //   return(status);
 //
 // mvOsDelay(10);

  return(MV_OK);
}
Exemple #14
0
/*******************************************************************************
**
**  onuEponSerdesPowerUpSeq
**  ____________________________________________________________________________
** 
**  DESCRIPTION: The function set serdes
**               
**  PARAMETERS:  None
**
**  OUTPUTS:     None    
**
**  RETURNS:     MV_OK or error
**
*******************************************************************************/
MV_STATUS onuEponSerdesPowerUpSeq(void)
{
  MV_STATUS status;
  MV_U32    rxReady = 0;
  MV_U32    txReady = 0;
  MV_U32    initDone;
  MV_U32    temp;

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_RST, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_PU_Pll, 0x0, 0);
  if (status != MV_OK)                                                         
    return(status);     

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_PU_RX, 0x0, 0);
  if (status != MV_OK)                                                         
    return(status);                                                            
                                                                              
  mvOsDelay(40);
  
  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_PU_TX, 0x0, 0);
  if (status != MV_OK)                                                         
    return(status);                                                            

  // asicOntMiscRegRead(mvAsicReg_PON_SERDES_PHY_CTRL_0, &temp, 0);
  // temp &= ~(0x7);
  // status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0, temp, 0); 
  // if (status != MV_OK) 
  //   return(status);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_SEL_GEPON, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_REF_CLK_25M, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_RST, 0x0, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  asicOntMiscRegRead(mvAsicReg_PON_SERDES_INTERNAL_PASSWORD, &temp, 0);
  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_INTERNAL_PASSWORD, temp | 0x76, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_INTERNAL_EN_LOOP_TIMING, 0x1, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_INTERNAL_PON_SELECT, 0x3, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  // status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_PU_Pll, 0x1, 0);
  // if (status != MV_OK) 
  //   return(status);
  // 
  // mvOsDelay(40);
  // 
  // status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_PU_RX, 0x1, 0); 
  // if (status != MV_OK) 
  //   return(status);
  // 
  // mvOsDelay(10);
  // 
  // status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_PU_TX, 0x1, 0);  
  // if (status != MV_OK) 
  //   return(status);

  asicOntMiscRegRead(mvAsicReg_PON_SERDES_PHY_CTRL_0, &temp, 0);
  temp |= (0x7);
  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0, temp, 0); 
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  temp = 0;
  do 
  {
	temp++;

	status  = asicOntMiscRegRead(mvAsicReg_PON_SERDES_PHY_CTRL_0_READY_TX, &txReady, 0);  
    if (status != MV_OK) 
      return(status);

    mvOsDelay(40);

    status  = asicOntMiscRegRead(mvAsicReg_PON_SERDES_PHY_CTRL_0_READY_RX, &rxReady, 0);  
    if (status != MV_OK) 
      return(status);

	if ((temp % 10) == 0) 
	{
	  return (MV_FAIL);
	}

  } while ((txReady == 0) || (rxReady == 0));

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_RX_INIT, 0x1, 0);  
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  temp = 0;
  do 
  {
	temp++;

	status  = asicOntMiscRegRead(mvAsicReg_PON_SERDES_PHY_CTRL_0_INIT_DONE, &initDone, 0);  
    if (status != MV_OK) 
      return(status);

	if ((temp % 10) == 0) 
	{
	  return (MV_FAIL);
	}

   mvOsDelay(40);
 
  } while (initDone == 0);

  mvOsDelay(40);

  status  = asicOntMiscRegWrite(mvAsicReg_PON_SERDES_PHY_CTRL_0_RX_INIT, 0x0, 0);  
  if (status != MV_OK) 
    return(status);

  mvOsDelay(40);

  return(MV_OK);
}