SI4703API.c
资源名称:fmradio.zip [点击查看]
上传用户:ledjyj
上传日期:2014-08-27
资源大小:2639k
文件大小:32k
源码类别:
驱动编程
开发平台:
Unix_Linux
- /* SI4703 Radio Card API
- * *Author: Beck.He@quantcn.com
- * 2007.9.1
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
- //#if defined (QCI_L1_UPGRADE_SILICON_FM_MODULE)
- /***************************************************************************
- * Include Files
- ***************************************************************************/
- #include <linux/sched.h>
- #include <linux/wait.h>
- #include <linux/delay.h>
- #include <asm/hardware.h>
- #include <asm/arch/pxa-regs.h>
- #include <asm/irq.h>
- #include <asm/arch/gpio.h>
- #include "SI4703API.h"
- /***************************************************************************
- * Macros
- ***************************************************************************/
- /***************************************************************************
- * Variables
- ***************************************************************************/
- const u16 FM_SI47XX_DEVICE_ADDR=0x20;
- const u16 FM_SI47XX_WRITE=0x00;
- const u16 FM_SI47XX_READ=0x01;
- /*** For writing ***/
- /*** REG 0x02 POWERCFG ***/
- const u16 SI_DMUTE =0x4000;
- const u16 SI_MUTE =0x0000;
- const u16 SI_MONO =0x2000;
- /* Quanta modify by Brian 20051111-00001100-02083-G80 */
- const u16 SI_SKMODE=0x0400;
- /* End of modification by Brian 20051111-00001100-02083-G80 */
- const u16 SI_SEEKUP=0x0200;
- const u16 SI_SEEKDOWN=0x0000;
- const u16 SI_SEEK =0x0100;
- const u16 SI_DISABLE=0x0040;
- const u16 SI_ENABLE=0x0001;
- const u16 SI_DSOFTMUTE=0x8000;
- /*** REG 0x03 CHANNEL ***/
- const u16 SI_TUNE=0x8000;
- /*** REG 0x04 SYSCONFIG1 ***/
- const u16 SI_RDSIEN=0x8000;
- const u16 SI_STCIEN=0x4000;
- const u16 SI_RDS=0x1000;
- /* Quanta modify by Brian 20051111-00001100-02083-G80 */
- const u16 SI_DE_50US=0x0800; // 50us for Europe and Australia
- const u16 SI_GPIO3_INTERRUPT=0x0010;
- /* End of modification by Brian 20051111-00001100-02083-G80 */
- const u16 SI_AGCD_DIS=0x0400;
- const u16 SI_GPIO2_INTERRUPT=0x0004;
- /* Quanta modify by Brian 20051111-00001100-02083-G80 */
- const u16 SI_GPIO2_HIGH=0x000B;
- const u16 SI_GPIO2_LOW =0x0008;
- /* End of modification by Brian 20051111-00001100-02083-G80 */
- /*** REG 0x05 SYSCONFIG2 ***/
- const u16 SI_RECOMMENDED_SEEKTH=0x0a00;//0x1900;
- /* Quanta modify by Beck.He 20051129-00001100-02083-G80 */
- const u16 SI_BAND =0x00C0;
- /* End of modification by Beck.He 20051129-00001100-02083-G80 */
- const u16 SI_BAND_US =0x0000; //87.5-108MHz
- /* Quanta modify by Brian 20051111-00001100-02083-G80 */
- const u16 SI_WIDEBAND_JAPAN=0x0040;//76-108MHZ
- /* End of modification by Brian 20051111-00001100-02083-G80 */
- const u16 SI_BAND_JAPAN =0x0080; //76-90MHz
- const u16 SI_SPACE =0x0030;
- const u16 SI_SPACE_200KHZ=0x0000;
- const u16 SI_SPACE_100KHZ=0x0010;
- const u16 SI_SPACE_50KHZ =0x0020;
- const u16 SI_VOLUME =0x000F;
- /*** For reading ***/
- /*** REG 0x0A STATUSRSSI ***/
- const u16 SI_RDSR=0x8000;
- const u16 SI_STC=0x4000;
- const u16 SI_SF=0x2000;
- /* Quanta modify by Brian 20051111-00001100-02083-G80 */
- const u16 SI_AFCRL=0x1000;
- const u16 SI_RDSE=0x0E00;
- /* End of modification by Brian 20051111-00001100-02083-G80 */
- const u16 SI_ST=0x0100;
- const u16 SI_RSSI=0x00FF;
- /*** REG 0x0B READCHAN ***/
- const u16 SI_READCHAN=0x03FF;
- /*** REG 0x00 DEVICEID ***/
- const u16 SI_PN=0xF000;
- const u16 SI_MFGID=0x0FFF;
- /*** REG 0x01 CHIPID ***/
- const u16 REV=0xFC00;
- const u16 DEV=0x0200;
- const u16 FIRMWARE=0x01FF;
- /*** User defined Variables ***/
- static u16 AUTOSEEK=FALSE;
- static u8 WriteRegArray[9];
- static u8 ReadRegArray[25];
- const u16 SI_BottomOfChannel=0x0000;
- u8 VolumeCtrl;
- const u8 NORVOL=0x08;
- const u8 MAXVOL=0x0F;
- const u8 MINVOL=0x00;
- static u16 SeekedChannels[40];
- static u8 MaxSeekedChannels=40;
- //static Boolean AUTOSEEK=FALSE;
- static u8 MaxTuneIndex=0;
- static u8 TuneIndex=0;
- static u16 BandSelect;
- static u16 SpacingSelect;
- const u8 SEEKTH_TO_VALUE_LIST[]=
- {
- 0x19, 0x1A, 0x1B, 0x1C,
- 0x1D, 0x1E, 0x1F, 0x20
- };
- /***************************************************************************
- * Declarations & Prototypes
- ***************************************************************************/
- #define si4703_debug 1
- static DECLARE_WAIT_QUEUE_HEAD(fm_wq);
- /***************************************************************************
- * Local Functions
- ***************************************************************************/
- /***************************************************************************
- * Global Functions
- ***************************************************************************/
- /*******************************************************************************
- * Function: FM_SI47XX_WriteReg
- *
- * Parameters: RegAddr, representing address of register of FM_SI47XX from 02h to 05h
- *
- * u16 InputData, content of register for writing in FM_SI47XX
- *
- * Returns: none
- *
- * Description: Routine to write content into registers in FM_SI47XX
- ******************************************************************************/
- void
- FM_SI47XX_WriteReg(
- WRITE_REG_ADDR RegAddr,
- u16 InputData
- )
- {
- u8 NumOfBytesToWrite;
- NumOfBytesToWrite=RegAddr*2;
- WriteRegArray[RegAddr*2-1]=(InputData & 0xFF00)>>8;
- WriteRegArray[RegAddr*2]=InputData & 0x00FF;
- SI4703_I2C_Write(&WriteRegArray[1],NumOfBytesToWrite);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_ReadReg
- *
- * Parameters: RegAddr, representing address of register of FM_SI47XX from 00h to 0Ah
- *
- * Returns: none
- *
- * Description: Routine to read content into registers in FM_SI47XX
- ******************************************************************************/
- u16
- FM_SI47XX_ReadReg(
- READ_REG_ADDR RegAddr
- )
- {
- u8 NumOfBytesToRead;
- NumOfBytesToRead=RegAddr*2; SI4703_I2C_Read(&ReadRegArray[1],NumOfBytesToRead);
- return ((ReadRegArray[NumOfBytesToRead-1]<<8) | ReadRegArray[NumOfBytesToRead]);
- }
- /*******************************************************************************
- * Function: ReadSTC
- *
- * Parameters: none
- *
- * Returns: u8
- *
- * Description: Routine to return STC bit in FM_SI47XX
- ******************************************************************************/
- u8
- ReadSTC(
- void
- )
- {
- if(FM_SI47XX_ReadReg(R0Ah) & SI_STC)
- return 1;
- else
- return 0;
- }
- /*******************************************************************************
- * Function: ReadSF
- *
- * Parameters: none
- *
- * Returns: u8
- *
- * Description: Routine to return SF bit in FM_SI47XX
- ******************************************************************************/
- u8
- ReadSF(
- void
- )
- {
- if(FM_SI47XX_ReadReg(R0Ah) & SI_SF)
- return 1;
- else
- return 0;
- }
- /*******************************************************************************
- * Function: ReadST
- *
- * Parameters: none
- *
- * Returns: u8
- *
- * Description: Routine to return ST(stereo) bit in FM_SI47XX/01
- ******************************************************************************/
- u8
- ReadST(
- void
- )
- {
- if(FM_SI47XX_ReadReg(R0Ah) & SI_ST){
- return 1;
- }
- else{
- return 0;
- }
- }
- /*******************************************************************************
- * Function: ReadGpio2
- *
- * Parameters: none
- *
- * Returns: u8
- *
- * Description: Routine to return status of interrupt pin GPIO2 in FM_SI47XX
- ******************************************************************************/
- u8
- ReadGpio2(
- void
- )
- {
- return 0;
- }
- /*******************************************************************************
- * Function: WaitGpio2
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to wait interrupt pin GPIO2 on FM_SI47XX until its value is 0
- ******************************************************************************/
- void
- WaitGpio2(
- void
- )
- {
- while(ReadGpio2() !=0);
- return;
- }
- /*******************************************************************************
- * Function: CfgFM_SI47XXRstAsOutput
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to configure GPIO53 on AD6527
- ******************************************************************************/
- void
- CfgFM_SI47XXRstAsOutput(
- void
- )
- {
- }
- /*******************************************************************************
- * Function: WaitSTC
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to wait until STC bit =1 on FM_SI47XX/01
- ******************************************************************************/
- void
- WaitSTC(
- void
- )
- {
- return;
- }
- /*******************************************************************************
- * Function: ReadRDS
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to read RDS bit on FM_SI47XX/01
- ******************************************************************************/
- u8
- ReadRDS(
- void
- )
- {
- if(FM_SI47XX_ReadReg(R04h) & SI_RDS){
- return 1;
- }
- else{
- return 0;
- }
- }
- /*******************************************************************************
- * Function: ReadRDSR
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to read RDSR bit on FM_SI47XX/01
- ******************************************************************************/
- u8
- ReadRDSR(
- void
- )
- {
- if(FM_SI47XX_ReadReg(R0Ah) & SI_RDSR){
- return 1;
- }
- else{
- return 0;
- }
- }
- /*******************************************************************************
- * Function: ReadRDSE
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to read RDSE bits on FM_SI47XX/01
- ******************************************************************************/
- u8
- ReadRDSE(
- void
- )
- {
- return ( (FM_SI47XX_ReadReg(R0Ah) & SI_RDSE)>>9 );
- }
- /*******************************************************************************
- * Function: ReadRDS_BLOCK
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to read RDSA, RDSB, RDSC and RDSD on FM_SI47XX/01
- ******************************************************************************/
- u16
- ReadRDS_BLOCK(
- RDS_STATUS RDS_ID
- )
- {
- switch(RDS_ID)
- {
- case RDSA:
- return FM_SI47XX_ReadReg(R0Ch);
- break;
- case RDSB:
- return FM_SI47XX_ReadReg(R0Dh);
- break;
- case RDSC:
- return FM_SI47XX_ReadReg(R0Eh);
- break;
- case RDSD:
- return FM_SI47XX_ReadReg(R0Fh);
- break;
- default:
- return 0;
- break;
- }
- }
- /*******************************************************************************
- * Function: FM_SI47XX_ReadRSSI
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to read RSSI bits on FM_SI47XX/01
- ******************************************************************************/
- u8
- FM_SI47XX_ReadRSSI(
- void
- )
- {
- return ( (FM_SI47XX_ReadReg(R0Ah) & SI_RSSI) );
- }
- /*******************************************************************************
- * Function: FM_SI47XX_RST_LOW
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to set GPIO53 on AD6527 as low voltage
- ******************************************************************************/
- void
- FM_SI47XX_RST_LOW(
- void
- )
- {
- }
- /*******************************************************************************
- * Function: FM_SI47XX_RST_HIGH
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to set GPIO53 on AD6527 as high voltage
- ******************************************************************************/
- void
- FM_SI47XX_RST_HIGH(
- void
- )
- {
- }
- /*******************************************************************************
- * Function: FM_SI47XX_2Wire
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to configure FM_SI47XX to operate in 2-wire mode
- ******************************************************************************/
- void
- FM_SI47XX_2Wire(
- void
- )
- {
- }
- /*******************************************************************************
- * Function: FM_SI47XX_Reset
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to reset FM_SI47XX
- ******************************************************************************/
- void
- FM_SI47XX_Reset(
- void
- )
- {
- }
- /*******************************************************************************
- * Function: FM_SI47XX_Init
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to initialize FM_SI47XX
- ******************************************************************************/
- /*** Initialization of FM_SI47XX module ***/
- void FM_SI47XX_Init(void)
- {
- #ifdef si4703_debug
- printk(KERN_ERR "API-si4703: Init,n");
- #endif
- #define TOUT_EN 1<<2
- OSCC |= TOUT_EN; //clk
- /* pxa272 setting pxa_gpio_mode(123 |GPIO_OUT | GPIO_DFLT_LOW);//reset
- udelay(200);
- pxa_gpio_mode(123 |GPIO_OUT | GPIO_DFLT_HIGH);
- pxa_gpio_mode(122 | GPIO_IN); // irq setting
- set_irq_type(IRQ_GPIO(122), IRQT_FALLING);*/
- enable_gpio_fm_pins();
- mhn_gpio_set_level(MFP_PIN_GPIO123,GPIO_LEVEL_LOW);//pull FM_RST high
- msleep(200);
- mhn_gpio_set_level(MFP_PIN_GPIO123,GPIO_LEVEL_HIGH);//pull FM_RST high
- set_irq_type(IRQ_GPIO(MFP2GPIO(MFP_PIN_GPIO122)), IRQT_FALLING);
- WriteRegArray[0]=FM_SI47XX_DEVICE_ADDR | FM_SI47XX_WRITE;
- ReadRegArray[0] =FM_SI47XX_DEVICE_ADDR | FM_SI47XX_READ;
- VolumeCtrl=MAXVOL;
- BandSelect=SI_BAND_US;
- SpacingSelect=SI_SPACE_100KHZ;
- }
- /*******************************************************************************
- * Function: FM_SI47XX_PowerUp
- *
- * Parameters: Boolean bRDSEnable, enable RDS function
- *
- * Returns: none
- *
- * Description: Routine to turn on FM_SI47XX
- ******************************************************************************/
- void FM_SI47XX_PowerUp()
- {
- #ifdef si4703_debug
- char buf[24];
- int i;
- printk(KERN_ERR "API-si4703: power up,n");
- #endif
- FM_SI47XX_WriteReg(W02h,SI_DMUTE | SI_ENABLE | SI_DSOFTMUTE);
- FM_SI47XX_WriteReg(W03h,SI_BottomOfChannel);
- //FM_SI47XX_WriteReg(W04h,SI_RDSIEN | SI_STCIEN | SI_GPIO2_INTERRUPT);
- FM_SI47XX_WriteReg(W04h,SI_RDSIEN | SI_STCIEN | SI_RDS | SI_GPIO2_INTERRUPT);
- FM_SI47XX_WriteReg(W05h,SI_RECOMMENDED_SEEKTH | BandSelect | SpacingSelect | VolumeCtrl);
- si4703_fm_wait_timeout();
- if( ReadSTC() !=1)
- printk(KERN_ERR "API-si4703: tune failn");
- FM_SI47XX_WriteReg(W03h,FM_SI47XX_ReadChannel());
- #ifdef si4703_debug
- SI4703_I2C_Read( buf, 24);
- for(i=0;i<24;i++)
- printk("I2C: SI4703 register contents=%xn", buf[i]);
- #endif
- }
- /* End of modification by Jacky.Sun 20051202-00000100-*****-G80 */
- /* Quanta modify by Brian 20051111-00001100-02083-G80 */
- /*******************************************************************************
- * Function: FM_SI47XX_OpenRDS
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to turn on RDS function of SI4701
- ******************************************************************************/
- void
- FM_SI47XX_OpenRDS(
- void
- )
- {
- FM_SI47XX_WriteReg(W04h,FM_SI47XX_ReadReg(R04h) | SI_RDS);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_CloseRDS
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to turn off RDS function of SI4701
- ******************************************************************************/
- void
- FM_SI47XX_CloseRDS(
- void
- )
- {
- FM_SI47XX_WriteReg(W04h,FM_SI47XX_ReadReg(R04h) & 0xCC3F);
- }
- /* End of modification by Brian 20051111-00001100-02083-G80 */
- /*******************************************************************************
- * Function: FM_SI47XX_SetBand
- *
- * Parameters: band- set 0 for changing band to USA,EUROPE
- *
- * set 1 for changing band to JAPAN
- *
- * Returns: none
- *
- * Description: Routine to set FM band
- ******************************************************************************/
- void
- FM_SI47XX_SetBand(
- u8 band
- )
- {
- if(band==1)
- BandSelect=SI_BAND_US;
- else
- BandSelect=SI_BAND_JAPAN;
- FM_SI47XX_WriteReg(W05h,SI_RECOMMENDED_SEEKTH | BandSelect | SpacingSelect | VolumeCtrl);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_SetSpacing
- *
- * Parameters: spacing- set 0 for changing channel spacing to 200KHZ
- *
- * set 1 for changing channel spacing to 100KHZ
- *
- * set 2 for changing channel spacing to 50KHZ
- *
- * Returns: none
- *
- * Description: Routine to set FM band
- ******************************************************************************/
- void
- FM_SI47XX_SetSpacing(
- u8 spacing
- )
- {
- switch(spacing){
- case 0:
- SpacingSelect=SI_SPACE_200KHZ;
- break;
- case 1:
- SpacingSelect=SI_SPACE_100KHZ;
- break;
- case 2:
- SpacingSelect=SI_SPACE_50KHZ;
- break;
- default:
- break;
- }
- FM_SI47XX_WriteReg(W05h,SI_RECOMMENDED_SEEKTH | BandSelect | SpacingSelect | VolumeCtrl);
- }
- /* Quanta modify by Brian 20051111-00001100-02083-G80 */
- /*******************************************************************************
- * Function: FM_SI47XX_SetSeekDepth
- *
- * Parameters: SeekDepth
- *
- * set 1 for changing band to JAPAN
- *
- * Returns: none
- *
- * Description: Routine to set seeking depth of FM channel
- ******************************************************************************/
- void
- FM_SI47XX_SetSeekDepth(
- u8 SeekDepth
- )
- {
- FM_SI47XX_WriteReg(W05h,(SeekDepth<<8) | BandSelect | SpacingSelect | VolumeCtrl);
- }
- /* End of modification by Brian 20051111-00001100-02083-G80 */
- /*******************************************************************************
- * Function: FM_SI47XX_PowerDown
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to turn off FM_SI47XX
- ******************************************************************************/
- void
- FM_SI47XX_PowerDown(
- void
- )
- {
- #ifdef si4703_debug
- printk(KERN_ERR "API-si4703: power down,n");
- #endif
- /*** Set DISABLE bit=1, perform internal power-down sequence and set ENABLE bit=0 later by device itself ***/
- FM_SI47XX_WriteReg(W02h,SI_ENABLE | SI_DISABLE);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_Tune
- *
- * Parameters: Channel- channel on FM radio, its unit value is 100Khz such as
- *
- * if we want to tune 101.5Mhz radio, we must set variable Channel
- *
- * =1015
- *
- * Returns: none
- *
- * Description: Routine to turn off FM_SI47XX
- ******************************************************************************/
- void
- FM_SI47XX_Tune(
- u16 Freq
- )
- {
- #ifdef si4703_debug
- printk(KERN_ERR "API-si4703: tune ,n");
- #endif
- /* Write address 0x03 to set channel and TUNE bit */
- FM_SI47XX_WriteReg(W03h,FM_SI47XX_FreqToChan(Freq) | SI_TUNE);
- si4703_fm_wait_timeout();
- if( ReadSTC() !=1)
- printk(KERN_ERR "API-si4703: tune failn");
- FM_SI47XX_WriteReg(W03h,FM_SI47XX_ReadChannel());
- }
- /*******************************************************************************
- * Function: FM_SI47XX_TuneNextChan
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to tune next channel from current channel
- ******************************************************************************/
- void
- FM_SI47XX_TuneNextChan(
- void
- )
- {
- /* Write address 0x03 to set channel and TUNE bit */
- FM_SI47XX_WriteReg(W03h, SI_TUNE | ((FM_SI47XX_ReadChannel()+0x0001) &0x03FF));
- si4703_fm_wait_timeout();
- if( ReadSTC() !=1)
- printk(KERN_ERR "API-si4703: tune failn");
- FM_SI47XX_WriteReg(W03h,FM_SI47XX_ReadChannel());
- }
- /*******************************************************************************
- * Function: FM_SI47XX_TunePrevChan
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to tune previous channel from current channel
- ******************************************************************************/
- void
- FM_SI47XX_TunePrevChan(
- void
- )
- {
- /* Write address 0x03 to set channel and TUNE bit */
- FM_SI47XX_WriteReg(W03h, SI_TUNE | ((FM_SI47XX_ReadChannel()-0x0001) &0x03FF));
- si4703_fm_wait_timeout();
- if( ReadSTC() !=1)
- printk(KERN_ERR "API-si4703: tune failn");
- FM_SI47XX_WriteReg(W03h,FM_SI47XX_ReadChannel());
- }
- /*******************************************************************************
- * Function: FM_SI47XX_Seek
- *
- * Parameters: SeekDirection, determine the direction of seeking on FM radio module
- *
- * Returns: SEEK_STATUS
- *
- * Description: Routine to seek available channel on FM_SI47XX
- ******************************************************************************/
- void
- FM_SI47XX_Seek(
- u16 SeekDirection, u16 *channel, u16 *scanok
- )
- {
- #ifdef si4703_debug
- printk(KERN_ERR "API-si4703: seek,n");
- #endif
- /*** Write address 0x02 to set SEEK and SEEKUP bit ***/
- if(SeekDirection==SEEKUP)
- FM_SI47XX_WriteReg(W02h,SI_DMUTE | SI_SEEK | SI_SEEKUP | SI_ENABLE | SI_DSOFTMUTE);
- else
- FM_SI47XX_WriteReg(W02h,SI_DMUTE | SI_SEEK | SI_SEEKDOWN | SI_ENABLE | SI_DSOFTMUTE);
- si4703_fm_wait_timeout();
- if( ReadSTC() !=1)
- printk(KERN_ERR "API-si4703: STC not set when seekingn");
- /*** Read SF status after seeking at address 0x0A ***/
- if(ReadSF()==1){
- *scanok = FALSE;
- #ifdef si4703_debug
- printk(KERN_ERR "API-si4703: seek fail,n");
- #endif
- }
- else{
- /*** Clear STC and SF bit by setting SEEK bit to low ***/
- *scanok = TRUE;
- #ifdef si4703_debug
- printk(KERN_ERR "API-si4703: seek success,n");
- #endif
- }
- *channel = FM_SI47XX_ReadChannel();
- FM_SI47XX_WriteReg(W02h,SI_DMUTE | SI_ENABLE | SI_DSOFTMUTE);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_SeekUp
- *
- * Parameters: none
- *
- * Returns: SEEK_STATUS
- *
- * Description: Routine to seek up available channel on FM_SI47XX
- ******************************************************************************/
- SEEK_STATUS
- FM_SI47XX_SeekUp(
- void
- )
- {
- return 0;
- //return FM_SI47XX_Seek(SEEKUP);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_SeekDown
- *
- * Parameters: none
- *
- * Returns: SEEK_STATUS
- *
- * Description: Routine to seek down available channel on FM_SI47XX
- ******************************************************************************/
- SEEK_STATUS
- FM_SI47XX_SeekDown(
- void
- )
- {
- return 0;
- //return FM_SI47XX_Seek(SEEKDOWN);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_AutoSeek
- *
- * Parameters: none
- *
- * Returns: u8
- *
- * Description: Routine to seek all channels on full band automatically and return
- *
- * the number of channels seeked before
- ******************************************************************************/
- u8
- FM_SI47XX_AutoSeek(
- void
- )
- {
- u8 ChannelIndex=0;
- u16 DoneSeeking=FALSE;
- FM_SI47XX_EraseAllSeekedChannels();
- /*** Seek through all FM band automatically ***/
- while((DoneSeeking !=TRUE)){
- /* DoneSeeking if SF=1 */
- if(FM_SI47XX_SeekUp()==SEEKFAILURE) {
- DoneSeeking=TRUE;
- }
- else if( (ChannelIndex !=0) && (SeekedChannels[ChannelIndex-1]>FM_SI47XX_ReadChannel()) ){
- /* at least one channel in SeekedChannels list and current seeked channel is lower than previous seeked channel */
- DoneSeeking=TRUE;
- }
- else{
- /* Store channel and keep seeking */
- SeekedChannels[ChannelIndex]=FM_SI47XX_ReadChannel();
- FM_SI47XX_WriteReg(W03h,SeekedChannels[ChannelIndex]);
- ChannelIndex++;
- if(ChannelIndex==MaxSeekedChannels)
- DoneSeeking=TRUE;
- }
- }
- if(ChannelIndex>0){
- AUTOSEEK=TRUE;
- TuneIndex=0;
- MaxTuneIndex=ChannelIndex;
- /** Set default frequency after seeking automatically **/
- FM_SI47XX_Tune(FM_SI47XX_ChanToFreq(SeekedChannels[0]));
- }
- return ChannelIndex; /* Return NumOfChannels seeked by AutoSeek function */
- }
- /*******************************************************************************
- * Function: FM_SI47XX_TuneUp
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to tune next seeked channel after seeking automatically
- ******************************************************************************/
- void
- FM_SI47XX_TuneUp(
- void
- )
- {
- if(AUTOSEEK == TRUE){
- if(TuneIndex==(MaxTuneIndex-1))
- TuneIndex=0;
- else
- TuneIndex++;
- FM_SI47XX_Tune(FM_SI47XX_ChanToFreq(SeekedChannels[TuneIndex]));
- }
- }
- /*******************************************************************************
- * Function: FM_SI47XX_TuneDown
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to tune previous seeked channel after seeking automatically
- ******************************************************************************/
- void
- FM_SI47XX_TuneDown(
- void
- )
- {
- if(AUTOSEEK == TRUE){
- if(TuneIndex==0)
- TuneIndex=MaxTuneIndex-1;
- else
- TuneIndex--;
- FM_SI47XX_Tune(FM_SI47XX_ChanToFreq(SeekedChannels[TuneIndex]));
- }
- }
- /*******************************************************************************
- * Function: FM_SI47XX_EraseAllSeekedChannels
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to erase all seeked channels after seeking automatically
- ******************************************************************************/
- void
- FM_SI47XX_EraseAllSeekedChannels(
- void
- )
- {
- u8 ChannelIndex;
- for(ChannelIndex=0;ChannelIndex<MaxSeekedChannels;ChannelIndex++)
- SeekedChannels[ChannelIndex]=0x0000;
- AUTOSEEK=FALSE;
- MaxTuneIndex=0;
- TuneIndex=0;
- /*** Tune to the bottom of FM band ***/
- FM_SI47XX_Tune(FM_SI47XX_ChanToFreq(SI_BottomOfChannel));
- }
- /*******************************************************************************
- * Function: FM_SI47XX_ReadChannel
- *
- * Parameters: none
- *
- * Returns: u16
- *
- * Description: Routine to return current available channel on FM_SI47XX
- ******************************************************************************/
- u16
- FM_SI47XX_ReadChannel(
- void
- )
- {
- return FM_SI47XX_ReadReg(R0Bh);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_ChanToFreq
- *
- * Parameters: Channel- channel on FM radio, its value starts at 0x0000
- *
- * Returns: u16
- *
- * Description: Routine to translate channel to frequency value
- ******************************************************************************/
- u16
- FM_SI47XX_ChanToFreq(
- u16 Channel
- )
- {
- u16 Info;
- u16 BottomOfFreq;
- Info=WriteRegArray[W05h*2];
- /* 100KHZ as one unit */
- /* Quanta modify by Beck.He 20051129-00001100-02083-G80 */
- if((Info & SI_BAND)==SI_BAND_US)
- {
- BottomOfFreq=875;
- }
- else
- {
- BottomOfFreq=760;
- }
- /* End of modification by Beck.He 20051129-00001100-02083-G80 */
- if((Info & SI_SPACE)==SI_SPACE_200KHZ){
- return (BottomOfFreq + (Channel <<1 ) );
- }
- else if((Info & SI_SPACE)==SI_SPACE_100KHZ){
- return (BottomOfFreq + Channel);
- }
- else{
- return (BottomOfFreq + ( Channel >>1 ) );
- }
- }
- /*******************************************************************************
- * Function: FM_SI47XX_FreqToChan
- *
- * Parameters: Frequency- operating frequency of FM radio
- *
- * Returns: u16
- *
- * Description: Routine to translate frequency to channel value
- ******************************************************************************/
- u16
- FM_SI47XX_FreqToChan(
- u16 Frequency
- )
- {
- u16 Info;
- u16 BottomOfFreq;
- Info=WriteRegArray[W05h*2];
- /* Quanta modify by Beck.He 20051129-00001100-02083-G80 */
- if((Info & SI_BAND)==SI_BAND_US)
- {
- BottomOfFreq=875;
- }
- else
- {
- BottomOfFreq=760;
- }
- /* End of modification by Beck.He 20051129-00001100-02083-G80 */
- if((Info & SI_SPACE)==SI_SPACE_200KHZ){
- return ((Frequency - BottomOfFreq) >>1);
- }
- else if((Info & SI_SPACE)==SI_SPACE_100KHZ){
- return (Frequency - BottomOfFreq) ;
- }
- else{
- return ((Frequency - BottomOfFreq) <<1) ;
- }
- }
- /*******************************************************************************
- * Function: FM_SI47XX_Volume
- *
- * Parameters: Direction- determine to increase volume(TURNUP) or to decrease volume(TURNDOWN)
- *
- * Returns: none
- *
- * Description: Routine to control volume of FM_SI47XX
- ******************************************************************************/
- void
- FM_SI47XX_Volume(
- u8 vol
- )
- {
- #ifdef si4703_debug
- printk(KERN_ERR "API-si4703: set volume,n");
- #endif
- VolumeCtrl = vol/10+5;
- FM_SI47XX_WriteReg(W05h,SI_RECOMMENDED_SEEKTH | BandSelect | SpacingSelect | VolumeCtrl);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_IncVolume
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to increase volume of FM_SI47XX
- ******************************************************************************/
- void
- FM_SI47XX_IncVolume(
- void
- )
- {
- FM_SI47XX_Volume(TURNUP);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_DecVolume
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to decrease volume of FM_SI47XX
- ******************************************************************************/
- void
- FM_SI47XX_DecVolume(
- void
- )
- {
- FM_SI47XX_Volume(TURNDOWN);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_MuteVolumeexport PATH=/proj/oe/build_mnh/cross/bin:/proj/oe/build_mnh/staging/i686-linux/bin:$PATH
- export ARCH=arm
- export CROSS_COMPILE=arm-angstrom-linux-gnueabi-
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to mute volume of FM_SI47XX
- ******************************************************************************/
- void
- FM_SI47XX_MuteVolume(
- void
- )
- {
- #ifdef si4703_debug
- printk(KERN_ERR "API-si4703: mute,n");
- #endif
- FM_SI47XX_WriteReg(W02h,SI_MUTE | SI_ENABLE | SI_DSOFTMUTE);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_DMuteVolume
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to unmute volume of FM_SI47XX
- ******************************************************************************/
- void
- FM_SI47XX_DMuteVolume(
- void
- )
- {
- #ifdef si4703_debug
- printk(KERN_ERR "API-si4703: unmute,n");
- #endif
- FM_SI47XX_WriteReg(W02h,SI_DMUTE | SI_ENABLE | SI_DSOFTMUTE);
- }