Пример #1
0
void mmi_bbm_wread(int argc, char *argv[])
{
    u16  length;
    u16 dest_addr, target_addr;
    u16 data;
    int i;

    if(argc == 2) {
        dest_addr = htoi(argv[1]);
        BBM_WORD_READ(hDevice, dest_addr, &data);
        print_log("[0x%04X] : 0x%04X\n", dest_addr, data);
    } else if(argc == 3) {
        dest_addr = htoi(argv[1]);
        length    = htoi(argv[2]);

        for(i=0; i<length; i+=2)
        {
            target_addr = dest_addr + i;
            if((i % 4) == 0) print_log("\n[0x%04X] : ", target_addr);
            BBM_WORD_READ(hDevice, target_addr, &data);
            print_log("%04X\n", data);
        }
        print_log("\n");
    } else {
        print_log("usage : %s [start addr] [length] ; word read command\n", argv[0]);
    }
}
//static fci_u16 tunerbb_drv_fc8050_rserror_count(void)
static fci_u16 tunerbb_drv_fc8050_rserror_count(fci_u16 *nframe)//for dummy channel.
{
	//fci_u32 rt_esum;
	fci_u16 rt_nframe, rt_rserror;
	fci_u8  rs_ctrl=0;

#ifdef MON_BURST_MODE
	uint8 burst[12];

	rs_ctrl = 0x21;
	BBM_WRITE(0, BBM_RS_CONTROL, rs_ctrl);
	BBM_BULK_READ(0, BBM_RS_RT_BER_PER, &burst[0], 4);
	//BBM_LONG_READ(0, BBM_RS_RT_BER_PER, burst[0]);
	rt_nframe = (uint16)(*(uint16*)burst);
	rt_rserror = (uint16)(*((uint16*)burst+1));

	rs_ctrl = 0x1;
	BBM_WRITE(0, BBM_RS_CONTROL, rs_ctrl);
#else
	BBM_READ(0, BBM_RS_CONTROL, &rs_ctrl);
	rs_ctrl |= 0x20;
	BBM_WRITE(0, BBM_RS_CONTROL, rs_ctrl);

	BBM_WORD_READ(0, BBM_RS_RT_BER_PER, &rt_nframe);	//실시간으로 count 되는 frame 수
	//BBM_LONG_READ(0, BBM_RS_RT_ERR_SUM, &rt_esum);
	BBM_WORD_READ(0, BBM_RS_RT_FAIL_CNT, &rt_rserror);

	rs_ctrl &= ~0x20;
	BBM_WRITE(0, BBM_RS_CONTROL, rs_ctrl);
#endif

	*nframe=rt_nframe; //실시간으로 count 되는 frame 수
	return rt_rserror;
}
Пример #3
0
static void DMBDrv_Check_Overrun(u8 reset)
{
	u16 mfoverStatus;
	u16 veri_val=0;

	BBM_WORD_READ(NULL, BBM_BUF_OVERRUN, &mfoverStatus);		

	if(mfoverStatus & gDmbMode)
	{
		//overrun clear
		BBM_WORD_WRITE(NULL, BBM_BUF_OVERRUN, mfoverStatus);
		BBM_WORD_WRITE(NULL, BBM_BUF_OVERRUN, 0x0000);

		if(reset)
		{
			//buffer restore
			BBM_WORD_READ(NULL, BBM_BUF_ENABLE, &veri_val);
			veri_val &= ~gDmbMode;
			BBM_WORD_WRITE(NULL, BBM_BUF_ENABLE, veri_val);
			veri_val |= gDmbMode; 
			BBM_WORD_WRITE(NULL, BBM_BUF_ENABLE, veri_val);

			//external interrupt restore
			fc8050_isr_interruptclear();
		}
		
		DPRINTK("FC8050 Overrun occured %s MODE , Restoration : %s performed\n", (gDmbMode&0x01)?"DMB":"DAB", (reset)?" ":"Not");          		
	}

}
Пример #4
0
static uint32 tunerbb_drv_fc8050_get_rs_ber(void)	//va_ber
{
	uint16 nframe, rserror;
	uint32 esum;
	uint32 ber;

	BBM_WORD_READ(0, BBM_RS_BER_PERIOD, &nframe);
	BBM_LONG_READ(0, BBM_RS_ERR_SUM, &esum);
	BBM_WORD_READ(0, BBM_RS_FAIL_COUNT, &rserror);

	if(nframe == 0)
	{
		ber = MAX_VA_BER;
	}
	else if((esum == 0) && (rserror == 0))
	{
		ber = 0;
	}
	else
	{
		ber = esum;
		ber += rserror * 9;
		ber /= (nframe + 1) * 204 * 8;
		ber = ber * 100000;
	}

	ber = (ber >= MAX_VA_BER) ? MAX_VA_BER : ber;

	return ber; 	

}
static int8 tunerbb_drv_fc8050_check_overrun(uint8 op_mode)
{
	uint16 mfoverStatus;

	// Patch for BER monitoring 20111115
	//uint16 buf_set=0;

	uint16 veri_val=0;
	uint8 mask;

	if(op_mode == FC8050_DAB)
	{
		mask = 0x08;
	}
	else if(op_mode == FC8050_DMB || op_mode == FC8050_VISUAL)
	{
		mask = 0x01;
	}
	else
	{
		printk("fc8050 invaild op_mode %d\n", op_mode);
		return FC8050_RESULT_ERROR; /* invaild op_mode */
	}
	
	// Patch for BER monitoring 20111115
	//BBM_WORD_READ(NULL, BBM_BUF_ENABLE, &buf_set);

	// Patch for BER monitoring 20111115
	//if(buf_set & mask)
	{	
		BBM_WORD_READ(NULL, BBM_BUF_OVERRUN, &mfoverStatus);		

		if(mfoverStatus & mask)
		{
			BBM_WORD_WRITE(NULL, BBM_BUF_OVERRUN, mfoverStatus);
			BBM_WORD_WRITE(NULL, BBM_BUF_OVERRUN, 0x0000);
			
			BBM_WORD_READ(NULL, BBM_BUF_ENABLE, &veri_val);
			veri_val &= ~mask;
			BBM_WORD_WRITE(NULL, BBM_BUF_ENABLE, veri_val);
			veri_val |= mask; 
			BBM_WORD_WRITE(NULL, BBM_BUF_ENABLE, veri_val);

			fc8050_isr_interruptclear();

			printk("++++++++++++++++++++++ fc8050 overrun occured!!! ++++++++++++++++++++++++++\n");
			printk("fc8050 overrun and buffer reset done!! mask %x, over %x\n", mask, mfoverStatus);
		}
	}

	return FC8050_RESULT_SUCCESS;
}
int8	tunerbb_drv_fc8050_get_fic(uint8* buffer, uint32* buffer_size  /*, uint8 crc_on_off */)
{
	HANDLE hDevice = NULL;
	fci_u16      mfIntStatus = 0;
	fci_u16      size;
		
	if(buffer==NULL)
		return FC8050_RESULT_ERROR;
	
	//BBM_WRITE(hDevice, BBM_COM_INT_ENABLE, 0x00);
	//BBM_WRITE(hDevice, BBM_COM_STATUS_ENABLE, 0x00);
	//tunerbb_drv_fc8050_control_fic(1);
	
	BBM_WORD_READ(hDevice, BBM_BUF_STATUS, &mfIntStatus);

	//printk("tunerbb_drv_fc8050_get_fic (0x%x)\n", mfIntStatus);
	if(mfIntStatus == 0)
	{
		//tunerbb_drv_fc8050_control_fic(0);
		//BBM_WRITE(hDevice, BBM_COM_INT_ENABLE, ENABLE_INT_MASK);
		//BBM_WRITE(hDevice, BBM_COM_STATUS_ENABLE, ENABLE_INT_MASK);
		return FC8050_RESULT_ERROR;
	}

	BBM_WORD_WRITE(hDevice, BBM_BUF_STATUS, mfIntStatus);
	BBM_WORD_WRITE(hDevice, BBM_BUF_STATUS, 0x0000);

	if(mfIntStatus & 0x0100) 
	{
		BBM_WORD_READ(hDevice, BBM_BUF_FIC_THR, &size);
		size += 1;
		if(size-1) 
		{
			BBM_DATA(hDevice, BBM_COM_FIC_DATA, buffer, size);
			*buffer_size=size;
		}

		//printk("FC8050 fic data (0x%x,len : %d)\n", *buffer, size);	
	}
	
	//tunerbb_drv_fc8050_control_fic(0);
	//BBM_WRITE(hDevice, BBM_COM_INT_ENABLE, ENABLE_INT_MASK);
	//BBM_WRITE(hDevice, BBM_COM_STATUS_ENABLE, ENABLE_INT_MASK);
	
	if(mfIntStatus & 0x0100)
		return FC8050_RESULT_SUCCESS;
	else
		return FC8050_RESULT_ERROR;
	
}
static uint32 tunerbb_drv_fc8050_get_rs_ber(void)	//va_ber
{
	uint16 nframe, rserror;
	uint32 esum;
	uint32 ber;

#ifdef MON_BURST_MODE
	uint8 burst[12];

	BBM_BULK_READ(0, BBM_RS_BER_PERIOD, &burst[0], 8);
	nframe = (uint16)(*(uint16*)burst);
	rserror = (uint16)(*((uint16*)burst+1));
	esum = (uint32)(*((uint32*)burst+1));
#else
	BBM_WORD_READ(0, BBM_RS_BER_PERIOD, &nframe);
	BBM_LONG_READ(0, BBM_RS_ERR_SUM, &esum);
	BBM_WORD_READ(0, BBM_RS_FAIL_COUNT, &rserror);
#endif

	if(nframe == 0)
	{
		// LGE_INTG_090217
		ber = MAX_VA_BER;
	}
	else if((esum == 0) && (rserror == 0))
	{
		ber = 0;
	}
	else
	{
		//LGE_INTG_090217
		#if (1)	//include corrected bit 
		ber = esum;
		#else	//not include
		ber = 0;
		#endif
		
		ber += rserror * 9;
		ber /= (nframe + 1) * 204 * 8;
		ber = ber * 100000;
	}

	ber = (ber >= MAX_VA_BER) ? MAX_VA_BER : ber;

	return ber; 	

}
Пример #8
0
static fci_u16 tunerbb_drv_fc8050_rserror_count(void)
{
	fci_u32 rt_esum;
	fci_u16 rt_nframe, rt_rserror;
	fci_u8  rs_ctrl=0;

	BBM_READ(0, BBM_RS_CONTROL, &rs_ctrl);
	rs_ctrl |= 0x20;
	BBM_WRITE(0, BBM_RS_CONTROL, rs_ctrl);

	BBM_WORD_READ(0, BBM_RS_RT_BER_PER, &rt_nframe);
	BBM_LONG_READ(0, BBM_RS_RT_ERR_SUM, &rt_esum);
	BBM_WORD_READ(0, BBM_RS_RT_FAIL_CNT, &rt_rserror);

	rs_ctrl &= ~0x20;
	BBM_WRITE(0, BBM_RS_CONTROL, rs_ctrl);

	return rt_rserror;
}
void tdmb_fc8050_spi_write_read_test(void)
{
	uint16 i;
	uint32 wdata = 0;
	uint32 ldata = 0;
	uint32 data = 0;
	uint32 temp = 0;

#define TEST_CNT    5
	tdmb_fc8050_power_on();

	for(i=0;i<TEST_CNT;i++)
	{
		BBM_WRITE(NULL, 0x05, i & 0xff);
		BBM_READ(NULL, 0x05, (fci_u8*)&data);
		printk("FC8000 byte test (0x%x,0x%x)\n", i & 0xff, data);
		if((i & 0xff) != data)
			printk("FC8000 byte test (0x%x,0x%x)\n", i & 0xff, data);
	}

	for(i=0;i<TEST_CNT;i++)
	{
		BBM_WORD_WRITE(NULL, 0x0210, i & 0xffff);
		BBM_WORD_READ(NULL, 0x0210, (fci_u16*)&wdata);
		printk("FC8000 word test (0x%x,0x%x)\n", i & 0xffff, wdata);
		if((i & 0xffff) != wdata)
			printk("FC8000 word test (0x%x,0x%x)\n", i & 0xffff, wdata);
	}

	for(i=0;i<TEST_CNT;i++)
	{
		BBM_LONG_WRITE(NULL, 0x0210, i & 0xffffffff);
		BBM_LONG_READ(NULL, 0x0210, (fci_u32*)&ldata);
		printk("FC8000 long test (0x%x,0x%x)\n", i & 0xffffffff, ldata);
		if((i & 0xffffffff) != ldata)
			printk("FC8000 long test (0x%x,0x%x)\n", i & 0xffffffff, ldata);
	}

	data = 0;

	for(i=0;i<TEST_CNT;i++)
	{
		temp = i&0xff;
		BBM_TUNER_WRITE(NULL, 0x12, 0x01, (fci_u8*)&temp, 0x01);
		BBM_TUNER_READ(NULL, 0x12, 0x01, (fci_u8*)&data, 0x01);
		printk("FC8000 tuner test (0x%x,0x%x)\n", i & 0xff, data);
		if((i & 0xff) != data)
			printk("FC8000 tuner test (0x%x,0x%x)\n", i & 0xff, data);
	}
	temp = 0x51;
	BBM_TUNER_WRITE(NULL, 0x12, 0x01, (fci_u8*)&temp, 0x01 );
	tdmb_fc8050_power_off();
}
Пример #10
0
static uint32 tunerbb_drv_fc8050_get_rs_ber(void)	//va_ber
{
	uint16 nframe, rserror;
	uint32 esum;
	uint32 ber;

	BBM_WORD_READ(0, BBM_RS_BER_PERIOD, &nframe);
	BBM_LONG_READ(0, BBM_RS_ERR_SUM, &esum);
	BBM_WORD_READ(0, BBM_RS_FAIL_COUNT, &rserror);

	if(nframe == 0)
	{
		// LGE_INTG_090217
		ber = MAX_VA_BER;
	}
	else if((esum == 0) && (rserror == 0))
	{
		ber = 0;
	}
	else
	{
		//LGE_INTG_090217
		#if (1)	//include corrected bit 
		ber = esum;
		#else	//not include
		ber = 0;
		#endif
		
		ber += rserror * 9;
		ber /= (nframe + 1) * 204 * 8;
		ber = ber * 100000;
	}

	ber = (ber >= MAX_VA_BER) ? MAX_VA_BER : ber;

	return ber; 	

}
Пример #11
0
/*--------------------------------------------------------------------------
int8 tunerbb_drv_fc8050_control_fic(void)
    (1)   fic interrupt control on/off
    (2)   Return Value
           Sucess : 1
           Fail : 0 or negative interger (If there is error code)
    (3)   Argument
           enable : on/off
---------------------------------------------------------------------------- */
int8 tunerbb_drv_fc8050_control_fic(uint8 enable)
{
	unsigned short mask;
	
	BBM_WORD_READ(NULL, BBM_BUF_INT, &mask);

	if(enable ==1)
		mask |= 0x100;
	else
		mask &= ~0x100;
	
	BBM_WORD_WRITE(NULL, BBM_BUF_INT, mask);
	
	return FC8050_RESULT_SUCCESS;
}
Пример #12
0
// Modified by somesoo 20100730 for removing green block effect
int8	tunerbb_drv_fc8050_multi_set_channel(int32 freq_num, uint8 subch_cnt, uint8 subch_id[ ], uint8 op_mode[ ])
{
	int8 res = BBM_OK;
	int32 freq = 0;
	uint8 dmb_cnt=0;
	int i;
	fc8050_service_type svcType = FC8050_SERVICE_MAX;
	unsigned short mask;
		
	// Added by somesoo 20100730 for removing green block effect
	fc8050_isr_control(0);
	
	for(i=0;i<subch_cnt;i++)
	{
		serviceType[i] = op_mode[i];

		if(FC8050_ENSQUERY != op_mode[i])
			tunerbb_drv_fc8050_stop();
		else
			svcType = FC8050_ENSQUERY;
	}
	
	tunerbb_drv_fc8050_control_fic(0);
	/* Change freq_num(channel num) to frequency */
	freq = tunerbb_drv_convert_chnum_to_freq(freq_num);

	if(freq == 0)
	{
		return FC8050_RESULT_ERROR;
	}

	res = BBM_TUNER_SET_FREQ(0, freq);
		
	if(res)
	{
		return FC8050_RESULT_ERROR;
	}
	
	if(svcType == FC8050_ENSQUERY)
	{
		if(BBM_SCAN_STATUS(0))
		{
			return FC8050_RESULT_ERROR;
		}
	}
		
	BBM_WORD_READ(NULL, BBM_BUF_ENABLE, &mask);
	mask &= 0x100;
	
	for(i=0;i<subch_cnt;i++)
	{
		switch(serviceType[i])
		{
			case FC8050_DAB:
				mask |= (1<<DAB_SVC_ID);
				BBM_AUDIO_SELECT(0, subch_id[i],DAB_SVC_ID);
#ifdef STREAM_TS_UPLOAD
				fc8050_demux_select_channel(subch_id[i], DAB_SVC_ID);
#else
				g_chinfo[subch_id[i]]=DAB_SVC_ID;
#endif
				break;
			case FC8050_DMB:
			case FC8050_VISUAL:
				mask |= (1<<(DMB_SVC_ID+dmb_cnt));	//LGE_BROADCAST_I
				if(dmb_cnt<2)
				{
					BBM_VIDEO_SELECT(0, subch_id[i], DMB_SVC_ID+dmb_cnt, dmb_cnt);
#ifdef STREAM_TS_UPLOAD
					fc8050_demux_select_video(subch_id[i], DMB_SVC_ID+dmb_cnt);
#else
					g_chinfo[subch_id[i]]=dmb_cnt;
#endif
					dmb_cnt++;
				}
				else
					res=BBM_NOK;
				break;
			case FC8050_DATA:
				mask |= (1<<DAT_SVC_ID);
				BBM_DATA_SELECT(0, subch_id[i], DAT_SVC_ID);
#ifdef STREAM_TS_UPLOAD
				fc8050_demux_select_channel(subch_id[i], DAT_SVC_ID);
#else
				g_chinfo[subch_id[i]]=DAT_SVC_ID;
#endif
				break;
			case FC8050_ENSQUERY:
				tunerbb_drv_fc8050_control_fic(1);
				res = BBM_OK;
				break;
			default:
				res = BBM_NOK;
				break;
		}
	}
	BBM_WORD_WRITE(NULL, BBM_BUF_ENABLE, mask);
	tot_subch_cnt = subch_cnt;

	// Added by somesoo 20100730 for removing green block effect
	if(svcType != FC8050_ENSQUERY)
		fc8050_isr_control(1);
	
	if(res)
		return FC8050_RESULT_ERROR;
	else
		return FC8050_RESULT_SUCCESS;
}
Пример #13
0
/*======================================================= 
    Function 		: tunerbb_drv_fc8050_init
    Description		: Initializing the FC8050 Chip after power on
    Parameter		: VOID
    Return Value	: 
           SUCCESS : 1
           FAIL : 0 or negative interger (If there is error code)

	when		model	who			edit history
  -------------------------------------------------------
	2010/05/17	MOBIT	prajuna		EBI2 configuration
	2010/05/31	MOBIT	prajuna		Removed test code
	2010/06/09	MOBIT	prajuna		TDMB porting(KB3 Rev. A patch)
	2010/07/15	MOBIT	prajuna		TDMB tuning for QSC
	2010/07/16	MOBIT	somesoo		TDMB tuning for QSC with FCI 최규원 과장
	2010/07/17	MOBIT	somesoo		TDMB porting(VG)
	2010/08/19	MOBIT	prajuna		Code review
	2010/09/10	MOBIT	prajuna		TDMB porting(Aloe)
======================================================== */ 
int8	tunerbb_drv_fc8050_init(void)
{
	uint8 res;
	/*test*/

	/*
	uint16 i; 
	uint32 wdata = 0; 
	uint32 ldata = 0; 
	uint32 data = 0;
	uint32 temp = 0;
	*/

	/* Common Code */
#if defined(STREAM_SLAVE_PARALLEL_UPLOAD)
	/* EBI2 Specific Code */
	BBM_HOSTIF_SELECT(NULL, BBM_PPI);
#elif defined(STREAM_TS_UPLOAD)
	/* TSIF Specific Code */
	BBM_HOSTIF_SELECT(NULL, BBM_I2C);
#elif defined(STREAM_SPI_UPLOAD)
	/* SPI Specific. Code */
	BBM_HOSTIF_SELECT(NULL, BBM_SPI);
#else
#error code not present
#endif

	BBM_FIC_CALLBACK_REGISTER((fci_u32)NULL, tunerbb_drv_fc8050_fic_cb);
	BBM_MSC_CALLBACK_REGISTER((fci_u32)NULL, tunerbb_drv_fc8050_msc_cb);
	
	res = BBM_INIT(NULL);
	
	if(res)
		return FC8050_RESULT_ERROR;
	else
	{
#if !defined(STREAM_TS_UPLOAD)
		memset((void*)&g_chinfo, 0xff, sizeof(g_chinfo));
		memset((void*)&msc_buffer, 0x00, sizeof(DATA_BUFFER));
		memset((void*)&fic_buffer, 0x00, sizeof(DATA_BUFFER));
#endif
	}

	res = BBM_TUNER_SELECT(0, FC8050_TUNER, BAND3_TYPE);

//	res = BBM_PROBE(0);
//	printk("tunerbb_drv_fc8050_init probe RES = %d\n", res);
#if 0      //fc8050 <-> Host(MSM) 간의 Interface TEST를 위한 code
/* test */	
	for(i=0;i<5000;i++)
	{
//		dog_kick();
		BBM_WRITE(NULL, 0x05, i & 0xff);
		BBM_READ(NULL, 0x05, &data);
		if((i & 0xff) != data)
			printk("FC8000 byte test (0x%x,0x%x)\n", i & 0xff, data);
	}
	for(i=0;i<5000;i++)
	{
		BBM_WORD_WRITE(NULL, 0x0210, i & 0xffff);
		BBM_WORD_READ(NULL, 0x0210, &wdata);
		if((i & 0xffff) != wdata)
			printk("FC8000 word test (0x%x,0x%x)\n", i & 0xffff, wdata);
	}
	for(i=0;i<5000;i++)
	{
		BBM_LONG_WRITE(NULL, 0x0210, i & 0xffffffff);
		BBM_LONG_READ(NULL, 0x0210, &ldata);
		if((i & 0xffffffff) != ldata)
			printk("FC8000 long test (0x%x,0x%x)\n", i & 0xffffffff, ldata);
	}

	data = 0;
	
	for(i=0;i<5000;i++)
	{
	  temp = i&0xff;
		BBM_TUNER_WRITE(NULL, 0x12, 0x01, &temp, 0x01);
		BBM_TUNER_READ(NULL, 0x12, 0x01, &data, 0x01);
		if((i & 0xff) != data)
			printk("FC8000 tuner test (0x%x,0x%x)\n", i & 0xff, data);
	}
	temp = 0x51;
	BBM_TUNER_WRITE(NULL, 0x12, 0x01, &temp, 0x01 );	
/* test */
#endif

	if(res)
		return FC8050_RESULT_ERROR; 
	else
		return FC8050_RESULT_SUCCESS;
}
Пример #14
0
unsigned char DMBDrv_init(void)
{
	u8 data;
	u16 wdata;
	u32 ldata;	
	int i;
	u8 temp = 0x1e;


#ifdef CONFIG_TDMB_SPI
	if(BBM_HOSTIF_SELECT(NULL, BBM_SPI))
		return TDMB_FAIL;
#elif defined(CONFIG_TDMB_EBI)
	if(BBM_HOSTIF_SELECT(NULL, BBM_PPI))
		return TDMB_FAIL;
#endif

  if(BBM_PROBE(NULL) != BBM_OK)  // check for factory  chip interface test
  {
    return TDMB_FAIL; 
  }
  
	BBM_FIC_CALLBACK_REGISTER(NULL, TDMBDrv_FIC_CALLBACK);
	BBM_MSC_CALLBACK_REGISTER(NULL, TDMBDrv_MSC_CALLBACK);

	BBM_INIT(NULL);
	BBM_TUNER_SELECT(NULL, FC8050_TUNER, BAND3_TYPE);

#if 0
	BBM_WRITE(NULL, 0x05, 0xa7);
	BBM_READ(NULL, 0x05, &data);
	BBM_READ(NULL, 0x12, &data);
	BBM_WORD_READ(NULL, 0x12, &wdata);
	BBM_WORD_WRITE(NULL, 0x310, 0x0b);
	BBM_WORD_READ(NULL, 0x310, &wdata);
	BBM_WRITE(NULL, 0x312, 0xc0);
	BBM_READ(NULL, 0x312, &data);

	BBM_TUNER_READ(NULL, 0x01, 0x01, &data, 0x01);
#endif

#if 0
	for(i=0;i<1000;i++)
	{
//		dog_kick();
		BBM_WRITE(NULL, 0x05, i & 0xff);
		BBM_READ(NULL, 0x05, &data);
		if((i & 0xff) != data)
			DPRINTK("FC8000 byte test (0x%x,0x%x)\r\n", i & 0xff, data);
	}
	for(i=0;i<1000;i++)
	{
		BBM_WORD_WRITE(NULL, 0x0210, i & 0xffff);
		BBM_WORD_READ(NULL, 0x0210, &wdata);
		if((i & 0xffff) != wdata)
			DPRINTK("FC8000 word test (0x%x,0x%x)\r\n", i & 0xffff, wdata);
	}
	for(i=0;i<1000;i++)
	{
		BBM_LONG_WRITE(NULL, 0x0210, i & 0xffffffff);
		BBM_LONG_READ(NULL, 0x0210, &ldata);
		if((i & 0xffffffff) != ldata)
			DPRINTK("FC8000 long test (0x%x,0x%x)\r\n", i & 0xffffffff, ldata);
	}
	for(i=0;i<1000;i++)
	{
	  temp = i&0xff;
		BBM_TUNER_WRITE(NULL, 0x12, 0x01, &temp, 0x01);
		BBM_TUNER_READ(NULL, 0x12, 0x01, &data, 0x01);
		if((i & 0xff) != data)
			DPRINTK("FC8000 tuner test (0x%x,0x%x)\r\n", i & 0xff, data);
	}
	temp = 0x51;
	BBM_TUNER_WRITE(NULL, 0x12, 0x01, &temp, 0x01 );	
	
#endif
	gBer = 3000;
	gInitFlag = 1;

	return TDMB_SUCCESS;
}
/*====================================================================
FUNCTION       fc8150_bb_get_tuner_info
DESCRIPTION 
DEPENDENCIES
RETURN VALUE
SIDE EFFECTS
======================================================================*/
void fc8150_bb_get_tuner_info(tIsdbtTunerInfo* tuner_info)
{
    u8 mode;
	u8 buf_lock;
	s32 i32RSSI;
	u32 ui32BER;
	u32 ui32PER;
	s32 CN;
    static u32 prelvl = 0;
	u32 ui32Antlvl;
    u16 AGC;
    u8 GI;
    u8 TM;
	struct dm_st {
		u8	start;
		s8	rssi;
		u8	wscn;
		u8	reserved;
		u16 main_rxd_rsps;
		u16 main_err_rsps;
		u32 main_err_bits;
		u32 dmp_rxd_bits;
		u32 dmp_err_bits;
		u16 inter_rxd_rsps;
		u16 inter_err_rsps;
		u32 inter_err_bits;
		u8	lna_code;
		u8	rfvga;
		u8	k;
		u8	csf_gain;
		u8	pga_gain;
		u8	extlna;
		u8	high_current_mode_gain;
		u8	extlna_gain;
	} dm;

	BBM_READ(NULL, 0x5053, &buf_lock);
	ISDBT_MSG_FC8150_BB("[%s] Lock = %d\n", __func__, buf_lock);
	if (!buf_lock)
        ui32Antlvl = prelvl = 0;
    tuner_info->rssi = buf_lock;

	BBM_WRITE(NULL, BBM_REQ_BER, 0x0e);
	BBM_BULK_READ(NULL, BBM_DM_DATA, (u8*) &dm + 1, sizeof(dm) - 1);

	ISDBT_MSG_FC8150_BB("[%s] main_rxd_rsps: %d, dmp_rxd_bits: %d, inter_rxd_rsps: %d\n", __func__, dm.main_rxd_rsps, dm.dmp_rxd_bits, dm.inter_rxd_rsps);
		
	if (dm.inter_rxd_rsps)
		ui32PER = ((u32)dm.inter_err_rsps * 10000 / (u32)dm.inter_rxd_rsps);
	else
		ui32PER = 10000;

	if (dm.dmp_rxd_bits)
		ui32BER = ((u32)dm.dmp_err_bits * 10000 / (u32)dm.dmp_rxd_bits);
	else
		ui32BER = 10000;
	
	i32RSSI = dm.rssi;
	CN = dm.wscn;

    BBM_READ(NULL, 0x302a, &mode);
    GI = (mode & 0x70) >> 4;    //	1 : 1/32, 2 : 1/16, 3 : 1/8, 4 : 1/4
    TM = mode & 0x03;           //	1 : mode1, 2 : mode2, 3 : mode3

	BBM_WORD_READ(0, 0x100e, &AGC);

	switch (prelvl) {
    case 0:
		if (ui32BER < 650)
			ui32Antlvl = prelvl = 1;
		else
			ui32Antlvl = prelvl;
	    break;

	case 1:
		if ((ui32BER > 700) || ((ui32BER > 500) && (CN <= 3)))
			ui32Antlvl = prelvl = 0;
		else if ((ui32BER < 300) && (CN > 6))
			ui32Antlvl = prelvl = 2;
		else
			ui32Antlvl = prelvl;
		break;

	case 2:
		if ((ui32BER > 500) || ((ui32BER > 300) && (CN <= 5)))
			ui32Antlvl = prelvl = 1;
		else if ((ui32BER < 100) && (CN >= 9))
			ui32Antlvl = prelvl = 3;
		else
			ui32Antlvl = prelvl;
		break;

	case 3:
		if ((ui32BER > 200) || ((ui32BER > 100) && (CN <= 9)))
			ui32Antlvl = prelvl = 2;
		else if ((ui32BER < 50) && (CN >= 12))
			ui32Antlvl = prelvl = 4;
		else
			ui32Antlvl = prelvl;
		break;

	case 4:
		if ((ui32BER > 100) || (CN <= 14))
			ui32Antlvl = prelvl = 3;
		else
			ui32Antlvl = prelvl;
		break;

	default :
		ui32Antlvl = prelvl = 0;
		break;
	}

    ISDBT_MSG_FC8150_BB("[%s] (PER)%d (BER)%d (RSSI)%d (CN)%d (AGC)%d (Ant)%d\n", __func__, ui32PER, ui32BER, i32RSSI, CN, AGC, ui32Antlvl);
}