SI4703API.c
资源名称:fmradio.zip [点击查看]
上传用户:ledjyj
上传日期:2014-08-27
资源大小:2639k
文件大小:36k
源码类别:
驱动编程
开发平台:
Unix_Linux
- /***************************************************************************
- *
- * QCI GSM/GPRS Phase 2 Software
- *
- * Copyright (c) 2005 Quanta Computer Inc.
- *
- *****************************************************************************
- *
- * $Workfile: l1alfmradio.c
- * $Revision: 1.0
- * $Author : Eric Yang
- * $Date : 2005.08.19
- *
- *****************************************************************************
- *
- * File Description : This file includes all the function about silicon FM module FM_SI47XX/01
- *
- * Definition by project
- *
- *****************************************************************************
- *
- * Revision Details
- * ----------------
- * $Log: l1alfmradio.c,v $
- * Revision 1.5 2005/12/08 08:29:31 05063078
- * 1. add power down function in file dlau6535.c ,l1alfmradio.c
- * 2. when powering on FM, MMI will set a default frequency, but FM Module can’t tune successfully
- * 3. Wolfson change path fail by using Wolfson Power on Req
- *
- * Revision 1.4 2005/12/01 01:24:22 05063078
- * the way set band change and return channel change when seek complete
- *
- * Revision 1.3 2005/11/11 03:43:09 QUANTA92101320
- * 1.Modify DlAu6535OutputSelect() and L1FrSendPowerOnWolfsonCommand() to play soft midi
- * 2.Add signal-base control of WM8976 I2S audio path
- * 3.Open default audio path(Headphone) for FM
- * 4.Add ReadST(),WaitSTC(),ReadRDS(),ReadRDSR(),ReadRDSE(),ReadRDS_Block(), FM_SI47XX_ReadRSSI(), FM_SI47XX_OpenRDS(), FM_SI47XX_SetSeekDepth() and FM_SI47XX_CloseRDS() for FM RDS/RBDS function
- * 5.Add signal-base control of power down WM8976
- *
- * Revision 1.2 2005/11/02 06:37:36 QUANTA92101320
- * Update I2S and DAC
- *
- * Revision 1.1 2005/09/29 02:49:32 QUANTA91080103
- * no message
- *
- *
- ***************************************************************************/
- /* This file is created and include in the serial number 20050922-00000100-01962-G80 */
- //#if defined (QCI_L1_UPGRADE_SILICON_FM_MODULE)
- /***************************************************************************
- * Include Files
- ***************************************************************************/
- //#include <system.h>
- //#include <kernel.h>
- #include <linux/wait.h>
- #include <linux/delay.h>
- #include <asm/hardware.h>
- #include <asm/arch/pxa-regs.h>
- #include <asm/irq.h>
- #include "SI4703API.h"
- //#include <dlmmicfg.h>
- //#include <l1debug.h>
- /* Quanta modify by Beck.He 20051206-00001100-02083-G80 */
- //#include <l1al_typ.h>
- /* End of modification by Beck.He 20051129-00000100-*****-G80 */
- /* Quanta modify by Beck.He 20051129-00000100-*****-G80 */
- //#include <bbcfg.h>
- /* End of modification by Beck.He 20051206-00001100-02083-G80 */
- /***************************************************************************
- * Manifest Constants
- ***************************************************************************/
- /***************************************************************************
- * Type Definitions
- ***************************************************************************/
- /***************************************************************************
- * Variables
- ***************************************************************************/
- /* Quanta modify by Beck.He 20051206-00001100-02083-G80 */
- /*move the define to bbcfg.h*/
- /* End of modification by Beck.He 20051206-00001100-02083-G80 */
- /***************************************************************************
- * 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;
- /*** 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=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
- /***************************************************************************
- * 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);
- //I2C_2Wire_Operation(WRITE,WriteRegArray,NumOfBytesToWrite+1);
- }
- /*******************************************************************************
- * 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);
- //I2C_2Wire_Operation(READ,ReadRegArray,NumOfBytesToRead+1);
- 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;
- }
- /* Quanta modify by Brian 20051111-00001100-02083-G80 */
- /*******************************************************************************
- * 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;
- }
- }
- /* End of modification by Brian 20051111-00001100-02083-G80 */
- /*******************************************************************************
- * 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
- )
- {
- //DlGpioConfigure(FM_RST); // pull to high
- }
- /* Quanta modify by Brian 20051111-00001100-02083-G80 */
- /*******************************************************************************
- * Function: WaitSTC
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to wait until STC bit =1 on FM_SI47XX/01
- ******************************************************************************/
- void
- WaitSTC(
- void
- )
- {
- //StartOfFrame=l1FrameNumber;
- while( (ReadSTC() !=1) ); //&& ((l1FrameNumber-StartOfFrame)<20) );
- //StopOfFrame=l1FrameNumber;
- //gplog4(2212,StartOfFrame,StopOfFrame,StopOfFrame-StartOfFrame,FM_SI47XX_ReadReg(R05h) & SI_SPACE);
- 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:
- /* Quanta modify by BECK.HE 20051129-00001100-02083-G80 */
- return 0;
- /* End of modification by BECK.HE 20051129-00001100-02083-G80 */
- 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) );
- }
- /* End of modification by Brian 20051111-00001100-02083-G80 */
- /*******************************************************************************
- * 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
- )
- {
- //M_DLGpioAssertLine(M_DLGpioLine(FM_RST));
- }
- /*******************************************************************************
- * 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
- )
- {
- //M_DLGpioDeassertLine(M_DLGpioLine(FM_RST));
- }
- /*******************************************************************************
- * 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
- )
- {
- //DlGpioConfigure(FM_SEN); // pull to high
- //M_DLGpioDeassertLine(M_DLGpioLine(FM_SEN)); // pull to high
- }
- /*******************************************************************************
- * Function: FM_SI47XX_Reset
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to reset FM_SI47XX
- ******************************************************************************/
- void
- FM_SI47XX_Reset(
- void
- )
- {
- //CfgFM_SI47XXRstAsOutput(); //pull to high
- //TWS_TransmitData (TWS_TC_START, 0);
- //TWS_TransmitData (TWS_TC_DATA, (TWS_DATA)0x00);
- //TWS_TransmitData (TWS_TC_DATA, (TWS_DATA)0x00);
- //TWS_TransmitData (TWS_TC_DATA, (TWS_DATA)0x00);
- // FM_SI47XX_RST_LOW();
- // FM_SI47XX_RST_HIGH();
- // TWS_TransmitData (TWS_TC_STOP, 0);
- }
- /*******************************************************************************
- * Function: FM_SI47XX_Init
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to initialize FM_SI47XX
- ******************************************************************************/
- /*** Initialization of FM_SI47XX module ***/
- void FM_SI47XX_Init(void)
- {
- //WM8976_LDO_POWERON();
- //CfgGpio6As32KHZ();
- //CfgFM_SI47XXGpio2AsInput(); //pull to high
- #ifdef si4703_debug
- printk(KERN_ERR "radio-si4703: Init,n");
- #endif
- #define TOUT_EN 1<<2
- OSCC |= TOUT_EN; //clk
- 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);
- 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;
- }
- /* Quanta modify by Jacky.Sun 20051202-00000100-*****-G80 */
- /*******************************************************************************
- * Function: FM_SI47XX_PowerUp
- *
- * Parameters: Boolean bRDSEnable, enable RDS function
- *
- * Returns: none
- *
- * Description: Routine to turn on FM_SI47XX
- ******************************************************************************/
- void FM_SI47XX_PowerUp()
- {
- /* Quanta modify by Beck.He 20051206-00001100-02083-G80 */
- //M_DLGpioAssertLine(M_DLGpioLine(FM_PWR_ON)); // pull to high
- /* End of modification by Beck.He 20051206-00001100-02083-G80 */
- //FM_SI47XX_Init();
- //FM_SI47XX_2Wire(); /* 2wire setting must be done before reset operation */
- //FM_SI47XX_Reset();
- #ifdef si4703_debug
- printk(KERN_ERR "radio-si4703: power up,n");
- #endif
- FM_SI47XX_WriteReg(W02h,SI_DMUTE | SI_ENABLE);
- 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);
- /* Quanta modify by Beck.He 20051206-00001100-02083-G80 */
- while(ReadSTC() !=1);
- /* End of modification by Beck.He 20051206-00001100-02083-G80 */
- /* Quanta modify by Brian 20051111-00001100-02083-G80 */
- FM_SI47XX_WriteReg(W03h,FM_SI47XX_ReadChannel());
- /* End of modification by Brian 20051111-00001100-02083-G80 */
- }
- /* 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 "radio-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 "radio-si4703: tune ,n");
- #endif
- /* Write address 0x03 to set channel and TUNE bit */
- FM_SI47XX_WriteReg(W03h,FM_SI47XX_FreqToChan(Freq) | SI_TUNE);
- /*** Wait for STC interrupt ***/
- WaitGpio2();
- /*** Write address 0x03 to clear TUNE bit ***/
- while(ReadSTC() !=1);
- 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));
- /*** Wait for STC interrupt ***/
- WaitGpio2();
- /*** Write address 0x03 to clear TUNE bit ***/
- while(ReadSTC() !=1);
- 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));
- /*** Wait for STC interrupt ***/
- WaitGpio2();
- /*** Write address 0x03 to clear TUNE bit ***/
- while(ReadSTC() !=1);
- 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 "radio-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);
- else
- FM_SI47XX_WriteReg(W02h,SI_DMUTE | SI_SEEK | SI_SEEKDOWN | SI_ENABLE);
- /*** Wait for STC interrupt ***/
- WaitGpio2();
- /*** Read channel status after seeking at address 0x0B and clear ***/
- while(ReadSTC()!=1);
- /*** Read SF status after seeking at address 0x0A ***/
- if(ReadSF()==1){
- *scanok = FALSE;
- }
- else{
- /*** Clear STC and SF bit by setting SEEK bit to low ***/
- *scanok = TRUE;
- }
- *channel = FM_SI47XX_ReadChannel();
- FM_SI47XX_WriteReg(W02h,SI_DMUTE | SI_ENABLE);
- }
- /*******************************************************************************
- * 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 "radio-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_MuteVolume
- *
- * Parameters: none
- *
- * Returns: none
- *
- * Description: Routine to mute volume of FM_SI47XX
- ******************************************************************************/
- void
- FM_SI47XX_MuteVolume(
- void
- )
- {
- #ifdef si4703_debug
- printk(KERN_ERR "radio-si4703: mute,n");
- #endif
- FM_SI47XX_WriteReg(W02h,SI_MUTE | SI_ENABLE);
- }
- /*******************************************************************************
- * 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 "radio-si4703: unmute,n");
- #endif
- FM_SI47XX_WriteReg(W02h,SI_DMUTE | SI_ENABLE);
- }