Example #1
0
void __init bsp_timer_init(void)
{
	unsigned int sys_clock_rate;

    sys_clock_rate =  BSP_SYS_CLK_RATE;

   /* Clear Timer IP status */
   if (REG32(BSP_TCIR) & BSP_TC0IP)
      REG32(BSP_TCIR) |= BSP_TC0IP;
            
    /* disable timer */
    REG32(BSP_TCCNR) = 0; /* disable timer before setting CDBR */

    /* initialize timer registers */
	REG32(BSP_CDBR)=(BSP_DIVISOR) << BSP_DIVF_OFFSET;
		REG32(BSP_TC0DATA) = (((sys_clock_rate/BSP_DIVISOR)/HZ)) << 4;
	// extend timer base to 4 times
	//REG32(BSP_CDBR)=(BSP_DIVISOR*4) << BSP_DIVF_OFFSET;
	//REG32(BSP_TC0DATA) = (((sys_clock_rate/(BSP_DIVISOR*4))/HZ)) << BSP_TCD_OFFSET;
#ifdef CONFIG_RTL_TIMER_ADJUSTMENT
   	rtl865x_setupTimer1();
#endif   
#if defined(CONFIG_RTL_WTDOG)
#ifdef CONFIG_RTK_VOIP
	{
		extern void bsp_enable_watchdog( void );
		bsp_enable_watchdog();
	}
#else
	REG32(BSP_WDTCNR) = 0x00600000;
#endif
#endif

    /* hook up timer interrupt handler */
#ifdef CONFIG_CEVT_EXT
	ext_clockevent_init(BSP_TC0_IRQ);
#endif
#ifdef CONFIG_CEVT_RLX
	rlx_clockevent_init(BSP_TC0_IRQ);
#endif
    
    /* enable timer */
	REG32(BSP_TCCNR) = BSP_TC0EN | BSP_TC0MODE_TIMER;
	REG32(BSP_TCIR) = BSP_TC0IE;
}
/* 
** API	  : zarlinkInitDevice()
** Desp	  :	Init Zarlink device
** input  : Realtek device obj pointer
** return : SUCCESS/FAILED
*/
BOOL zarlinkInitDevice( RTKDevObj *pDev )
{
   	int ch;
	BOOL rtn;
	VpProfilePtrType dev_profile;
	VpStatusType status;
	VpTermType term_type;

   	PRINT_MSG("Initializing device 0x%x\n", pDev->dev_id);

	/* Create the API-2 device */
	status = VpMakeDeviceObject( pDev->VpDevType, 
								 (VpDeviceIdType) pDev->dev_id, 
								 pDev->pDevCtx,	
								 pDev->pDevObj	
							  );

	if ( status != VP_STATUS_SUCCESS ) {
	  	PRINT_R("Error: VpMakeDeviceObject (status %d) \n", status);
	  	return FAILED;
	}

	for (ch=0; ch < pDev->max_line; ch++) {

		if (pDev->pLine[ch]->line_type == LINE_FXS ) 
			 term_type = VP_TERM_FXS_GENERIC;
		else term_type = VP_TERM_FXO_GENERIC;

		/* Create line objects */
		status = VpMakeLineObject( term_type, 
							   pDev->pLine[ch]->channelId,	
							   pDev->pLine[ch]->pLineCtx,
							   pDev->pLine[ch]->pLineObj,
							   pDev->pDevCtx		
							);
		if ( status != VP_STATUS_SUCCESS ) {
	  		PRINT_R("Error: VpMakeLineObject ch %d term=%d(status %d) \n", 
				ch, term_type, status);
	  		return FAILED;
		}
	}

	dev_profile = pDev->pDev_profile;

	PRINT_MSG("tick rate %d ms\n", dev_profile[DEVICE_PROFILE_TICK_RATE_IDX]);

	/* Avoid taking to long to init device */
#ifdef CONFIG_RTL865X_WTDOG
	plat_disable_watchdog();
	PRINT_MSG("Disable watchdog\n" );
#elif defined( CONFIG_RTL_WTDOG )
	bsp_disable_watchdog();
	PRINT_MSG("Disable watchdog\n" );
#endif	

	/* Initialize the device */
	status = VpInitDevice(  pDev->pDevCtx,		
						   	pDev->pDev_profile,
						   	pDev->pAC_profile,
						   	pDev->pDC_profile,
						   	pDev->pRing_profile,
						   	pDev->pACFxoLC_profile,
						   	pDev->pFxoDial_profile
						);

	if ( status != VP_STATUS_SUCCESS ) {
		PRINT_R("Error: VpInitDevice (status %d)\n", status );
		goto DONE;
	}

	/* Check if VP_DEV_EVID_DEV_INIT_CMP occurred */
	if( TRUE != zarlinkWaitForEvent( pDev->pDevCtx, 
		VP_EVCAT_RESPONSE, VP_DEV_EVID_DEV_INIT_CMP ) ) {
		PRINT_R("Error: Device %d initialization was not complete\n",pDev->dev_id);
		status = VP_STATUS_FAILURE;
		goto DONE;
	}

	PRINT_MSG("DEV%x initialized OK\n",pDev->dev_id);
	pDev->dev_st = DEV_S_READY;

	/* Initialize API-2 line settings */
	for (ch=0; ch < pDev->max_line; ch++) {
		if (pDev->pLine[ch]->line_type == LINE_FXS)	{
			rtn = RtkInitFxsLine(pDev->pLine[ch]);

		} else if (pDev->pLine[ch]->line_type == LINE_FXO) {
			rtn = RtkInitFxoLine(pDev->pLine[ch]);

		} else {
			PRINT_R("Error: unknow line_type %d\n",pDev->pLine[ch]->line_type);
			goto DONE;
		}
	}

DONE:
#ifdef CONFIG_RTL865X_WTDOG
	plat_enable_watchdog();
	PRINT_MSG("Enable watchdog\n");
#elif defined( CONFIG_RTL_WTDOG )
	bsp_enable_watchdog();
	PRINT_MSG("Enable watchdog\n");
#endif
	if ( status != VP_STATUS_SUCCESS )	return FAILED;

	return SUCCESS;
}