📄 tunsdrv.c
字号:
/* ----------------------------------------------------------------------------
File Name: tunsdrv.c
Description: external tuner drivers.
Copyright (C) 1999-2001 STMicroelectronics
History:
date: 3-July-2001
version: 3.1.0
author: GJP
comment: write for multi-instance.
date: 17-August-2001
version: 3.1.1
author: GJP
comment: update SubAddr to U16
Reference:
ST API Definition "TUNER Driver API" DVD-API-06
---------------------------------------------------------------------------- */
/* Includes ---------------------------------------------------------------- */
/* C libs */
#ifndef STTUNER_MINIDRIVER
#ifdef ST_OSLINUX
#include "stos.h"
#else
#include <string.h>
#include "stlite.h" /* Standard includes */
/* STAPI */
#include "sttbx.h"
#endif
#include "stevt.h"
#include "sttuner.h"
/* local to sttuner */
#include "util.h" /* generic utility functions for sttuner */
#include "dbtypes.h" /* data types for databases */
#include "sysdbase.h" /* functions to accesss system data */
#include "ioarch.h" /* I/O for this driver */
#include "ioreg.h" /* I/O for this driver */
#include "sdrv.h" /* utilities */
#include "sioctl.h" /* data structure typedefs for all the the sat ioctl functions */
#include "tunsdrv.h" /* header for this file */
#define TUNSDRV_IO_TIMEOUT 10
#ifdef STTUNER_BASIC
#if defined(STTUNER_DRV_SAT_TUN_MAX2118) || defined(STTUNER_DRV_SAT_TUN_MAX2116)
static U32 MAX2116_LOOKUP[10][4]= { /* low high vco div/2 */
850000, 931600, 4, 0,
931600, 1037000, 5, 0,
1037000, 1126000, 6, 0,
1126000, 1217000, 0, 1,
1217000, 1356000, 1, 1,
1356000, 1513000, 2, 1,
1513000, 1671000, 3, 1,
1671000, 1864000, 4, 1,
1864000, 2072000, 5, 1,
2072000, 2247000, 6, 1
};
#endif
#if defined(STTUNER_DRV_SAT_TUN_STB6000)
#ifndef STTUNER_DRV_SAT_TUN_STB6100
static U32 STB6K_LOOKUP[11][3]= { /* low high osm */
950000, 1000000, 0xA,
1000000, 1075000, 0xC,
1075000, 1200000, 0x0,
1200000, 1300000, 0x1,
1300000, 1370000, 0x2,
1370000, 1470000, 0x4,
1470000, 1530000, 0x5,
1530000, 1650000, 0x6,
1650000, 1800000, 0x8,
1800000, 1950000, 0xA,
1950000, 2150000, 0xC
};
#endif
#endif
#ifdef STTUNER_DRV_SAT_TUN_IX2476
static U32 IX2476_LOOKUP[8][4]= {/* low high vco div/2 */
950000, 1065000, 6, 1,
1065000, 1170000, 7, 1,
1170000, 1300000, 1, 0,
1300000, 1445000, 2, 0,
1445000, 1607000, 3, 0,
1607000, 1778000, 4, 0,
1778000, 1942000, 5, 0,
1942000, 2150000, 6, 0
};
#endif
#ifdef STTUNER_DRV_SAT_TUN_VG0011
static U32 TUNERSAT_LOOKUP[4][5]= {/* low high div4 rdiv presc32 */
950000, 992000, 1, 1, 0,
992000, 1300000, 1, 1, 1,
1300000, 1984000, 0, 2, 0,
1984000, 2150000, 0, 2, 1
};
#endif
#ifdef STTUNER_DRV_SAT_TUN_STB6000
#ifndef STTUNER_DRV_SAT_5188
/* reference divider is set to 4 */
U8 DefSTB6000Val[STB6000_NBREGS]={0x01,0x7a,0x3c,0x6c,0x04,0x07,0x9e,0xdf,0xd0,0x50,0xfb,0x4f,0x81};
#else
/* reference divider is set to 30 to keep 1Mhz tuner step */
U8 DefSTB6000Val[STB6000_NBREGS]={0x01,0x7a,0x3c,0x6c,0x1e,0x07,0x9e,0xdf,0xd0,0x50,0xfb,0xcf,0x81};
#endif
U16 STB6000_AddressArray[STB6000_NBREGS] ={0x00,0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,0x0c};
#endif
#ifdef STTUNER_DRV_SAT_TUN_IX2476
/* Default values for Sharp IX2476 tuner registers */
U8 DefIX2476Val[IX2476_NBREGS]= {0x09,0x60,0xf5,0x2c,0x00};
U16 IX2476_AddressArray[HZ1184_NBREGS]={0x01,0x02,0x03,0x04,0x05};
#endif
#ifdef STTUNER_DRV_SAT_TUN_VG0011
/* Default values for tuner sat */
U8 DefTUNERSATVal[TUNERSAT_NBREGS]= {0x07,0xa3,0x92,0x37,0x05,0x00,0x00,0x05};
U16 TUNERSAT_AddressArray[TUNERSAT_NBREGS] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
#endif
#ifdef STTUNER_DRV_SAT_TUN_MAX2116
U8 DefTUNERMAX2116Val[MAX2116_NBREGS]= {0x00,0x04,0x77,0x3e,0x4f,0x43,0x0c,0x14,0x4f};
U16 MAX2116_AddressArray[MAX2116_NBREGS]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
#endif
#ifdef STTUNER_DRV_SAT_TUN_HZ1184
U8 DefTUNERHZ1184Val[HZ1184_NBREGS]= { 0x22,0x10,0x86,0x8a,0x00};
U16 HZ1184_AddressArray[HZ1184_NBREGS]={0x01,0x02,0x03,0x04,0x05};
#endif
#endif
#if (STTUNER_DRV_SAT_TUN_STB6100)
static U32 STB6K_LOOKUP[11][3]= { /* low high osm */
950000, 1000000, 0xA,
1000000, 1075000, 0xC,
1075000, 1200000, 0x0,
1200000, 1300000, 0x1,
1300000, 1370000, 0x2,
1370000, 1470000, 0x4,
1470000, 1530000, 0x5,
1530000, 1650000, 0x6,
1650000, 1800000, 0x8,
1800000, 1950000, 0xA,
1950000, 2150000, 0xC
};
#endif
#ifdef STTUNER_DRV_SAT_TUN_STB6100
U16 STB6100_AddressArray[STB6100_NBREGS] ={0x00,0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b};
U8 STB6100_DefVal[STB6100_NBREGS] = { 0x81,0x66,0x39,0xd0,0x3c,0x3c,0xd4,0xdc,0x8f,0x0d,0xfb,0xde};
/*U32 STB6100_DefVal[STB6100_NBREGS] = { 0x81, 0x60, 0x58, 0xc7, 0x39, 0x3b, 0xcd, 0xdc, 0x8f, 0xd, 0xfb, 0xde }; */
#endif
/* private variables ------------------------------------------------------- */
#if defined(ST_OS21) || defined(ST_OSLINUX)
static semaphore_t *Lock_InitTermOpenClose; /* guard calls to the functions */
#else
static semaphore_t Lock_InitTermOpenClose; /* guard calls to the functions */
#endif
static BOOL Installed = FALSE;
#ifdef STTUNER_BASIC
static BOOL Installed_VG1011 = FALSE;
static BOOL Installed_S68G21 = FALSE;
static BOOL Installed_TUA6100 = FALSE;
static BOOL Installed_EVALMAX = FALSE;
static BOOL Installed_VG0011 = FALSE;
static BOOL Installed_HZ1184 = FALSE;
static BOOL Installed_MAX2116 = FALSE;
static BOOL Installed_DSF8910 = FALSE;
static BOOL Installed_STB6000 = FALSE;
static BOOL Installed_IX2476 = FALSE;
#endif
static BOOL Installed_STB6100 = FALSE;
/* instance chain, the default boot value is invalid, to catch errors */
static TUNSDRV_InstanceData_t *InstanceChainTop = (TUNSDRV_InstanceData_t *)0x7fffffff;
/* functions --------------------------------------------------------------- */
/* API */
ST_ErrorCode_t tuner_tunsdrv_Init(ST_DeviceName_t *DeviceName, TUNER_InitParams_t *InitParams);
ST_ErrorCode_t tuner_tunsdrv_Term(ST_DeviceName_t *DeviceName, TUNER_TermParams_t *TermParams);
ST_ErrorCode_t tuner_tunsdrv_Open(ST_DeviceName_t *DeviceName, TUNER_OpenParams_t *OpenParams, TUNER_Handle_t *Handle);
#ifdef STTUNER_BASIC
#ifdef STTUNER_DRV_SAT_TUN_VG1011
ST_ErrorCode_t tuner_tunsdrv_Open_VG1011 (ST_DeviceName_t *DeviceName, TUNER_OpenParams_t *OpenParams, TUNER_Capability_t *Capability, TUNER_Handle_t *Handle);
#endif
#ifdef STTUNER_DRV_SAT_TUN_S68G21
ST_ErrorCode_t tuner_tunsdrv_Open_S68G21 (ST_DeviceName_t *DeviceName, TUNER_OpenParams_t *OpenParams, TUNER_Capability_t *Capability, TUNER_Handle_t *Handle);
#endif
#ifdef STTUNER_DRV_SAT_TUN_TUA6100
ST_ErrorCode_t tuner_tunsdrv_Open_TUA6100(ST_DeviceName_t *DeviceName, TUNER_OpenParams_t *OpenParams, TUNER_Capability_t *Capability, TUNER_Handle_t *Handle);
#endif
#ifdef STTUNER_DRV_SAT_TUN_EVALMAX
ST_ErrorCode_t tuner_tunsdrv_Open_EVALMAX(ST_DeviceName_t *DeviceName, TUNER_OpenParams_t *OpenParams, TUNER_Capability_t *Capability, TUNER_Handle_t *Handle);
#endif
#ifdef STTUNER_DRV_SAT_TUN_VG0011
ST_ErrorCode_t tuner_tunsdrv_Open_VG0011(ST_DeviceName_t *DeviceName, TUNER_OpenParams_t *OpenParams, TUNER_Capability_t *Capability, TUNER_Handle_t *Handle);
#endif
#ifdef STTUNER_DRV_SAT_TUN_HZ1184
ST_ErrorCode_t tuner_tunsdrv_Open_HZ1184(ST_DeviceName_t *DeviceName, TUNER_OpenParams_t *OpenParams, TUNER_Capability_t *Capability, TUNER_Handle_t *Handle);
#endif
#ifdef STTUNER_DRV_SAT_TUN_MAX2116
ST_ErrorCode_t tuner_tunsdrv_Open_MAX2116(ST_DeviceName_t *DeviceName, TUNER_OpenParams_t *OpenParams, TUNER_Capability_t *Capability, TUNER_Handle_t *Handle);
#endif
#ifdef STTUNER_DRV_SAT_TUN_DSF8910
ST_ErrorCode_t tuner_tunsdrv_Open_DSF8910(ST_DeviceName_t *DeviceName, TUNER_OpenParams_t *OpenParams, TUNER_Capability_t *Capability, TUNER_Handle_t *Handle);
#endif
#ifdef STTUNER_DRV_SAT_TUN_STB6000
ST_ErrorCode_t tuner_tunsdrv_Open_STB6000(ST_DeviceName_t *DeviceName, TUNER_OpenParams_t *OpenParams, TUNER_Capability_t *Capability, TUNER_Handle_t *Handle);
#endif
#ifdef STTUNER_DRV_SAT_TUN_IX2476
ST_ErrorCode_t tuner_tunsdrv_Open_IX2476(ST_DeviceName_t *DeviceName, TUNER_OpenParams_t *OpenParams, TUNER_Capability_t *Capability, TUNER_Handle_t *Handle);
#endif
#endif
#ifdef STTUNER_DRV_SAT_TUN_STB6100
ST_ErrorCode_t tuner_tunsdrv_Open_STB6100(ST_DeviceName_t *DeviceName, TUNER_OpenParams_t *OpenParams, TUNER_Capability_t *Capability, TUNER_Handle_t *Handle);
#endif
ST_ErrorCode_t tuner_tunsdrv_Close(TUNER_Handle_t Handle, TUNER_CloseParams_t *CloseParams);
ST_ErrorCode_t tuner_tunsdrv_SetFrequency (TUNER_Handle_t Handle, U32 Frequency, U32 *NewFrequency);
ST_ErrorCode_t tuner_tunsdrv_GetStatus (TUNER_Handle_t Handle, TUNER_Status_t *Status);
ST_ErrorCode_t tuner_tunsdrv_IsTunerLocked(TUNER_Handle_t Handle, BOOL *Locked);
ST_ErrorCode_t tuner_tunsdrv_SetBandWidth (TUNER_Handle_t Handle, U32 BandWidth, U32 *NewBandWidth);
/* I/O API */
ST_ErrorCode_t tuner_tunsdrv_ioaccess(TUNER_Handle_t Handle, IOARCH_Handle_t IOHandle,
STTUNER_IOARCH_Operation_t Operation, U16 SubAddr, U8 *Data, U32 TransferSize, U32 Timeout);
/* access device specific low-level functions */
ST_ErrorCode_t tuner_tunsdrv_ioctl(TUNER_Handle_t Handle, U32 Function, void *InParams, void *OutParams, STTUNER_Da_Status_t *Status);
/* local functions --------------------------------------------------------- */
ST_ErrorCode_t STTUNER_DRV_TUNER_TUNSDRV_Install( STTUNER_tuner_dbase_t *Tuner, STTUNER_TunerType_t TunerType);
ST_ErrorCode_t STTUNER_DRV_TUNER_TUNSDRV_UnInstall(STTUNER_tuner_dbase_t *Tuner, STTUNER_TunerType_t TunerType);
BOOL Tuner_GetStatus(TUNSDRV_InstanceData_t *Instance);
ST_ErrorCode_t Tuner_Read(TUNSDRV_InstanceData_t *Instance);
int checkrange(long freqstart,long frequency,long freqend);
static __inline U32 CalculateSteps (TUNSDRV_InstanceData_t *Instance);
static __inline U32 CalculateFrequency(TUNSDRV_InstanceData_t *Instance);
TUNSDRV_InstanceData_t *TUNSDRV_GetInstFromHandle(TUNER_Handle_t Handle);
/*****************************************************
**FUNCTION :: TUNER_PowOf2
**ACTION :: Compute 2^n (where n is an integer)
**PARAMS IN :: number -> n
**PARAMS OUT:: NONE
**RETURN :: 2^n
*****************************************************/
static U32 TUNER_PowOf2(U32 number)
{
U32 i;
U32 result=1;
for(i=0;i<number;i++)
result*=2;
return result;
}
/*****************************************************
**FUNCTION :: Tuner_GetStatus
**ACTION :: To Get the Lock status of PLL.
*****************************************************/
BOOL Tuner_GetStatus(TUNSDRV_InstanceData_t *Instance)
{
BOOL locked = FALSE;
#ifdef STTUNER_DRV_SAT_TUN_MAX2116
U8 u8;
#endif
if(&(Instance->DeviceMap))
{
Instance->DeviceMap.Error = Tuner_Read(Instance);
switch(Instance->TunerType)
{
#ifdef STTUNER_BASIC
#ifdef STTUNER_DRV_SAT_TUN_VG0011
case STTUNER_TUNER_VG0011:
if(!(Instance->DeviceMap.Error))
locked = STTUNER_IOREG_GetFieldVal(&(Instance->DeviceMap),FTUNERSAT_LOCK,Instance->TunerRegVal);
break;
#endif
#ifdef STTUNER_DRV_SAT_TUN_HZ1184
case STTUNER_TUNER_HZ1184:
if(!(Instance->DeviceMap.Error))
locked = STTUNER_IOREG_GetFieldVal(&(Instance->DeviceMap),FHZ1184_LOCK,Instance->TunerRegVal);
break;
#endif
#ifdef STTUNER_DRV_SAT_TUN_MAX2116
case STTUNER_TUNER_MAX2116:
if(!Instance->DeviceMap.Error)
{
u8 = STTUNER_IOREG_GetFieldVal(&(Instance->DeviceMap),FMAX2116_ADC,Instance->TunerRegVal);
locked = ((u8>0) && (u8<7)) ? TRUE : FALSE;
}
break;
#endif
#ifdef STTUNER_DRV_SAT_TUN_STB6000
case STTUNER_TUNER_STB6000:
if(!Instance->DeviceMap.Error)
locked = STTUNER_IOREG_GetFieldVal(&(Instance->DeviceMap),FSTB6000_LD,Instance->TunerRegVal);
break;
#endif
#ifdef STTUNER_DRV_SAT_TUN_IX2476
case STTUNER_TUNER_IX2476:
if(!Instance->DeviceMap.Error)
locked = STTUNER_IOREG_GetFieldVal(&(Instance->DeviceMap),FIX2476_FL,Instance->TunerRegVal);
break;
#endif
#endif
#ifdef STTUNER_DRV_SAT_TUN_STB6100
case STTUNER_TUNER_STB6100:
if(!Instance->DeviceMap.Error)
locked = STTUNER_IOREG_GetFieldVal(&(Instance->DeviceMap),FSTB6100_LD,Instance->TunerRegVal);
break;
#endif
default:
/* nothing to do here */
break;
}
}
return locked;
}
/*****************************************************
**FUNCTION :: Tuner_Read()
**ACTION :: To read "read only" registers of tuner
*****************************************************/
ST_ErrorCode_t Tuner_Read(TUNSDRV_InstanceData_t *Instance)
{
ST_ErrorCode_t Error = ST_NO_ERROR;
if(&(Instance->DeviceMap))
{
switch(Instance->TunerType)
{
#ifdef STTUNER_BASIC
#ifdef STTUNER_DRV_SAT_TUN_VG0011
case STTUNER_TUNER_VG0011:
Error = STTUNER_IOREG_GetContigousRegisters(&(Instance->DeviceMap), Instance->IOHandle, RTUNERSAT_TUNING_LSB,8, Instance->TunerRegVal);
break;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -