From 225e3950a37b33e000ed1dd0b0e25f083e83988a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=93=9D=E6=96=8C=E5=85=83?= Date: Thu, 26 Jul 2012 18:14:24 +0800 Subject: [PATCH] rk2928 add gps support --- arch/arm/mach-rk2928/board-rk2928-fpga.c | 84 ++++ drivers/misc/Makefile | 2 +- drivers/misc/gps/Kconfig | 3 +- drivers/misc/gps/Makefile | 2 +- drivers/misc/gps/hv5820b/Kconfig | 13 + drivers/misc/gps/hv5820b/Makefile | 3 + drivers/misc/gps/hv5820b/PALAPI.c | 421 ++++++++++++++++++ drivers/misc/gps/hv5820b/PALAPI.h | 72 +++ drivers/misc/gps/hv5820b/gpsdriver.c | 529 +++++++++++++++++++++++ drivers/misc/gps/hv5820b/gpsdriver.h | 50 +++ drivers/misc/gps/hv5820b/gpsdrv.h | 53 +++ drivers/misc/gps/hv5820b/hv5820b_gps.h | 25 ++ drivers/misc/gps/hv5820b/lnxdrv.h | 52 +++ 13 files changed, 1306 insertions(+), 3 deletions(-) create mode 100755 drivers/misc/gps/hv5820b/Kconfig create mode 100755 drivers/misc/gps/hv5820b/Makefile create mode 100755 drivers/misc/gps/hv5820b/PALAPI.c create mode 100755 drivers/misc/gps/hv5820b/PALAPI.h create mode 100755 drivers/misc/gps/hv5820b/gpsdriver.c create mode 100755 drivers/misc/gps/hv5820b/gpsdriver.h create mode 100755 drivers/misc/gps/hv5820b/gpsdrv.h create mode 100755 drivers/misc/gps/hv5820b/hv5820b_gps.h create mode 100755 drivers/misc/gps/hv5820b/lnxdrv.h diff --git a/arch/arm/mach-rk2928/board-rk2928-fpga.c b/arch/arm/mach-rk2928/board-rk2928-fpga.c index 7fd99583b24c..07e366c32fb2 100755 --- a/arch/arm/mach-rk2928/board-rk2928-fpga.c +++ b/arch/arm/mach-rk2928/board-rk2928-fpga.c @@ -42,6 +42,9 @@ #include #include #include +#if defined(CONFIG_GPS_HV5820B) +#include "../../../drivers/misc/gps/hv5820b/hv5820b_gps.h" +#endif #ifdef CONFIG_VIDEO_RK29 /*---------------- Camera Sensor Macro Define Begin ------------------------*/ @@ -769,7 +772,85 @@ static struct platform_device device_ion = { }, }; #endif +#if defined(CONFIG_GPS_HV5820B) +int hv5820b_gps_io_init(void) +{ + printk("%s \n", __FUNCTION__); + rk30_mux_api_set(GPIO1B1_SPI_TXD_UART1_SOUT_NAME, GPIO1B_GPIO1B1);//VCC_EN + gpio_request(RK2928_PIN1_PB1, NULL); + gpio_direction_output(RK2928_PIN1_PB1, GPIO_LOW); + + rk30_mux_api_set(GPIO1A2_I2S_LRCKRX_GPS_CLK_NAME, GPIO1A_GPS_CLK);//GPS_CLK + rk30_mux_api_set(GPIO1A4_I2S_SDO_GPS_MAG_NAME, GPIO1A_GPS_MAG);//GPS_MAG + rk30_mux_api_set(GPIO1A5_I2S_SDI_GPS_SIGN_NAME, GPIO1A_GPS_SIGN);//GPS_SIGN + + rk30_mux_api_set(GPIO1B0_SPI_CLK_UART1_CTSN_NAME, GPIO1B_GPIO1B0);//SPI_CLK + gpio_request(RK2928_PIN1_PB0, NULL); + gpio_direction_output(RK2928_PIN1_PB0, GPIO_LOW); + + rk30_mux_api_set(GPIO1B2_SPI_RXD_UART1_SIN_NAME, GPIO1B_GPIO1B2);//SPI_MOSI + gpio_request(RK2928_PIN1_PB2, NULL); + gpio_direction_output(RK2928_PIN1_PB2, GPIO_LOW); + + rk30_mux_api_set(GPIO1B3_SPI_CSN0_UART1_RTSN_NAME, GPIO1B_GPIO1B3);//SPI_CS + gpio_request(RK2928_PIN1_PB3, NULL); + gpio_direction_output(RK2928_PIN1_PB3, GPIO_LOW); + return 0; +} +int hv5820b_gps_power_up(void) +{ + printk("%s \n", __FUNCTION__); + + return 0; +} + +int hv5820b_gps_power_down(void) +{ + printk("%s \n", __FUNCTION__); + + return 0; +} + +int hv5820b_gps_reset_set(int level) +{ + return 0; +} +int hv5820b_enable_hclk_gps(void) +{ + printk("%s \n", __FUNCTION__); + clk_enable(clk_get(NULL, "hclk_gps")); + return 0; +} +int hv5820b_disable_hclk_gps(void) +{ + printk("%s \n", __FUNCTION__); + clk_disable(clk_get(NULL, "hclk_gps")); + return 0; +} +struct hv5820b_gps_data hv5820b_gps_info = { + .io_init = hv5820b_gps_io_init, + .power_up = hv5820b_gps_power_up, + .power_down = hv5820b_gps_power_down, + .reset = hv5820b_gps_reset_set, + .enable_hclk_gps = hv5820b_enable_hclk_gps, + .disable_hclk_gps = hv5820b_disable_hclk_gps, + .GpsSign = RK2928_PIN1_PA4, + .GpsMag = RK2928_PIN1_PB1, //GPIO index + .GpsClk = RK2928_PIN1_PA2, //GPIO index + .GpsVCCEn = RK2928_PIN1_PB1, //GPIO index + .GpsSpi_CSO = RK2928_PIN1_PB3, //GPIO index + .GpsSpiClk = RK2928_PIN1_PB0, //GPIO index + .GpsSpiMOSI = RK2928_PIN1_PB2, //GPIO index +}; +struct platform_device hv5820b_device_gps = { + .name = "gps_hv5820b", + .id = -1, + .dev = { + .platform_data = &hv5820b_gps_info, + } + }; +#endif static struct platform_device *devices[] __initdata = { #ifdef CONFIG_ION &device_ion, @@ -777,6 +858,9 @@ static struct platform_device *devices[] __initdata = { #ifdef CONFIG_FB_ROCKCHIP &device_fb, #endif +#ifdef CONFIG_GPS_HV5820B + &hv5820b_device_gps, +#endif }; static void __init rk2928_board_init(void) diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index e5b97a33c724..5a99f5aaab7c 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -58,7 +58,7 @@ obj-$(CONFIG_MW100) += mw100.o obj-$(CONFIG_MT6229) += mt6229.o obj-$(CONFIG_STE) += ste.o obj-$(CONFIG_RK29_SUPPORT_MODEM) += rk29_modem/ -obj-$(CONFIG_GPS_GNS7560) += gps/ +obj-$(CONFIG_RK29_GPS) += gps/ obj-y += inv_mpu/ obj-$(CONFIG_RK29_NEWTON) += newton.o obj-$(CONFIG_TDSC8800) += tdsc8800.o diff --git a/drivers/misc/gps/Kconfig b/drivers/misc/gps/Kconfig index ae012dbcaefd..7c912b3f74f6 100644 --- a/drivers/misc/gps/Kconfig +++ b/drivers/misc/gps/Kconfig @@ -13,7 +13,8 @@ if RK29_GPS config GPS_GNS7560 bool "gns7560 support" default n - + +source "drivers/misc/gps/hv5820b/Kconfig" endif # RK29_GPS diff --git a/drivers/misc/gps/Makefile b/drivers/misc/gps/Makefile index 6b4bdb6480c2..5488d964d9fd 100644 --- a/drivers/misc/gps/Makefile +++ b/drivers/misc/gps/Makefile @@ -1,3 +1,3 @@ obj-$(CONFIG_GPS_GNS7560) += rk29_gps.o - +obj-$(CONFIG_RK29_GPS) += hv5820b/ diff --git a/drivers/misc/gps/hv5820b/Kconfig b/drivers/misc/gps/hv5820b/Kconfig new file mode 100755 index 000000000000..47365c07ec1e --- /dev/null +++ b/drivers/misc/gps/hv5820b/Kconfig @@ -0,0 +1,13 @@ +# +# gps device configuration +# + + + +config GPS_HV5820B + bool "HV5820B support" + default n + + + + diff --git a/drivers/misc/gps/hv5820b/Makefile b/drivers/misc/gps/hv5820b/Makefile new file mode 100755 index 000000000000..150c55411149 --- /dev/null +++ b/drivers/misc/gps/hv5820b/Makefile @@ -0,0 +1,3 @@ +obj-$(CONFIG_GPS_HV5820B) += gpsdriver.o PALAPI.o gpsdrv.a + + diff --git a/drivers/misc/gps/hv5820b/PALAPI.c b/drivers/misc/gps/hv5820b/PALAPI.c new file mode 100755 index 000000000000..610bfca31752 --- /dev/null +++ b/drivers/misc/gps/hv5820b/PALAPI.c @@ -0,0 +1,421 @@ +/////////////////////////////////////////////////////////////////////////////////// +// +// Filename: PALAPI.c +// Author: sjchen +// Copyright: +// Date: 2010/12/01 +// Description: +// linux system interface +// +// Revision: +// 0.0.1 +// +/////////////////////////////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_AllocMem +// Parameters: +// Description: allocate system memory +// Notes: sjchen 2010/12/01 +// +/////////////////////////////////////////////////////////////////////////////////// +void* PAL_AllocMem(int nBytes) +{ + return kmalloc ( nBytes, GFP_KERNEL); +} + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_FreeMem +// Parameters: +// Description: free system memory +// Notes: sjchen 2010/12/01 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_FreeMem(void* pMem) +{ + if(pMem) + { + kfree(pMem); + } +} + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_CreateMutex +// Parameters: +// Description: Create a semaphore +// Notes: sjchen 2010/12/01 +// +/////////////////////////////////////////////////////////////////////////////////// +int PAL_CreateMutex ( void) +{ + struct semaphore *psem; + + psem = (struct semaphore *)PAL_AllocMem(sizeof(struct semaphore)); + //init_MUTEX_LOCKED(psem); + sema_init(psem, 0); + return (int)psem; + +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_ReleaseMutex +// Parameters: +// Description: Release a semaphore +// Notes: sjchen 2010/12/01 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_ReleaseMutex ( int hMutex ) +{ + if(hMutex) + { + up((struct semaphore *)hMutex); + } + + return ; +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_WaitMutex +// Parameters: +// Description: Wait semaphore to signal +// Notes: sjchen 2010/12/01 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_WaitMutex(int hMutex) +{ + if(hMutex) + { + down((struct semaphore *)hMutex); + } +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_CloseMutes +// Parameters: +// Description: Close a semaphore +// Notes: sjchen 2010/12/01 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_CloseMutes(int hMutex) +{ + if(hMutex) + { + PAL_FreeMem((void *)hMutex); + } +} + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_memset +// Parameters: +// Description: +// Notes: sjchen 2010/12/01 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_memset ( + void* pbuf, + unsigned char nval, + int nsize + ) +{ + memset ( pbuf, nval, nsize ); +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_memcpy +// Parameters: +// Description: +// Notes: sjchen 2010/12/01 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_memcpy ( + void* pDst, + void* pSrc, + int nSize + ) +{ + memcpy ( pDst, pSrc, nSize ); +} + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_GetCurTimer_US +// Parameters: +// Description: Get system time +// Notes: sjchen 2010/11/30 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_GetCurTimer_US( + int *n32Second, + int *n32us + ) +{ + struct timeval tv; + + do_gettimeofday(&tv); + + *n32Second = tv.tv_sec; + *n32us = tv.tv_usec; +} + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_GetCurTimer_US +// Parameters: +// Description: Get system time +// Notes: sjchen 2010/11/30 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_GetSysTimer_US( + int *n32Second, + int *n32us + ) +{ + PAL_GetCurTimer_US(n32Second, n32us); +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_GetKernelFreePage +// Parameters: +// Description: Allocate kernel free page +// Notes: sjchen 2010/11/30 +// +/////////////////////////////////////////////////////////////////////////////////// +int PAL_GetKernelFreePage(int nPageSize) +{ + return __get_free_pages(GFP_KERNEL,get_order(nPageSize)); +} + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_FreeKernelPage +// Parameters: +// Description: Free kernel page +// Notes: sjchen 2010/11/30 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_FreeKernelPage(int nAddr,int nPageSize) +{ + if(nAddr != 0 && nPageSize != 0) + { + free_pages(nAddr,get_order(nPageSize)); + + } +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_GetUser +// Parameters: +// Description: +// Notes: sjchen 2010/11/30 +// +/////////////////////////////////////////////////////////////////////////////////// +int PAL_GetUser(int *p) +{ + int nData = 0; + + __get_user(nData,(int __user *)p); + + return nData; +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_CopyFromUser +// Parameters: +// Description: Copy datas from user space to kernel space +// Notes: sjchen 2010/11/30 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_CopyFromUser(void *pDest,void *pSrc,int nSize) +{ + __copy_from_user(pDest,(void __user *)pSrc,nSize); +} + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_CopyToUser +// Parameters: +// Description: Copy datas from kernel space to user space +// Notes: sjchen 2010/11/30 +// +/////////////////////////////////////////////////////////////////////////////////// +int PAL_CopyToUser(void *pDest,void *pSrc,int nSize) +{ + return copy_to_user((void __user *)pDest, pSrc, nSize); +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_Sprintf +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +int PAL_Sprintf ( + char * pDst, + const char * pFormat, + ... + ) +{ + int nNum = 0; + + va_list ptr; + + va_start ( ptr, pFormat ); + + nNum = vsprintf ( pDst, pFormat, ptr ); + + va_end ( ptr ); + + return nNum; +} +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_Sprintf +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_KDEBUG ( + const char * pFormat, + ... + ) +{ +#if 1 + va_list ptr; + + va_start ( ptr, pFormat ); + + vprintk ( pFormat, ptr ); + + va_end ( ptr ); +#endif + return ; +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_mdelay +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_mdelay(int ms) +{ + mdelay(ms); +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_dma_cache_wback_inv +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_dma_cache_wback_inv(void * pMem, int size ) +{ + //TODO: + //fluch cache + + __cpuc_flush_dcache_area(pMem, size ); +} + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_dma_cache_wback_inv +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_dma_cache_inv(void * pMem, int size ) +{ + //TODO: + //fluch cache + + __cpuc_flush_dcache_area(pMem, size ); +} + + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_Set_GPIO_Pin +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_Set_GPIO_Pin(int gpio) +{ + //TODO: + //Set gpio to high level + + //gpio_write_one_pin_value(gpio, 1); + gpio_set_value(gpio, GPIO_HIGH); +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:PAL_Clr_GPIO_Pin +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +void PAL_Clr_GPIO_Pin(int gpio) +{ + //TODO: + //Set gpio to low level + + //gpio_write_one_pin_value(gpio, 0); + gpio_set_value(gpio, GPIO_LOW); +} + + diff --git a/drivers/misc/gps/hv5820b/PALAPI.h b/drivers/misc/gps/hv5820b/PALAPI.h new file mode 100755 index 000000000000..b45a7a86dd59 --- /dev/null +++ b/drivers/misc/gps/hv5820b/PALAPI.h @@ -0,0 +1,72 @@ +/////////////////////////////////////////////////////////////////////////////////// +// +// Filename: PALAPI.h +// Author: sjchen +// Copyright: +// Date: 2010/12/01 +// Description: +// declare linux driver function +// +// Revision: +// 0.0.1 +// +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef __PALAPI_H___ +#define __PALAPI_H___ + +extern void* PAL_AllocMem(int nBytes); +extern void PAL_FreeMem(void* pMem); +extern int PAL_CreateMutex ( void); +extern void PAL_ReleaseMutex ( int hMutex ); +extern void PAL_WaitMutex(int hMutex); +extern void PAL_CloseMutes(int hMutex); + +extern void PAL_memset ( + void* pbuf, + unsigned char nval, + int nsize + ); + +extern void PAL_memcpy ( + void* pDst, + void* pSrc, + int nSize + ); + +void PAL_GetCurTimer_US( + int *n32Second, + int *n32us + ); + +void PAL_GetSysTimer_US( + int *n32Second, + int *n32us + ); + +int PAL_GetKernelFreePage(int nPageSize); + +void PAL_FreeKernelPage(int nAddr,int nPageSize); + +int PAL_GetUser(int *p); + +void PAL_CopyFromUser(void *pDest,void *pSrc,int nSize); + +int PAL_CopyToUser(void *pDest,void *pSrc,int nSize); + +int PAL_Sprintf ( + char * pDst, + const char * pFormat, + ... + ); + +void PAL_mdelay(int ms); + +void PAL_KDEBUG ( + const char * pFormat, + ... + ); +void PAL_Set_GPIO_Pin(int gpio); +void PAL_Clr_GPIO_Pin(int gpio); + +#endif //__PALAPI_H___ diff --git a/drivers/misc/gps/hv5820b/gpsdriver.c b/drivers/misc/gps/hv5820b/gpsdriver.c new file mode 100755 index 000000000000..97877d3654cc --- /dev/null +++ b/drivers/misc/gps/hv5820b/gpsdriver.c @@ -0,0 +1,529 @@ +/////////////////////////////////////////////////////////////////////////////////// +// +// Filename: gpsdriver.c +// Author: sjchen +// Copyright: +// Date: 2012/07/09 +// Description: +// GPS driver +// +// Revision: +// 0.0.1 +// +/////////////////////////////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#include + + +#include "gpsdrv.h" +#include "gpsdriver.h" +#include "lnxdrv.h" +#include "PALAPI.h" + +#include +#include +#include "hv5820b_gps.h" + +/////////////////////////////////////////////////////////////////////////////////// +// +// macro declaration +// +/////////////////////////////////////////////////////////////////////////////////// +#define GPS_MAJOR ( 61 ) +#define SW_VA_GPS_IO_BASE 0x10400000 +#define GPS_USE_SPI + + +/////////////////////////////////////////////////////////////////////////////////// +// +// static variables declaration +// +/////////////////////////////////////////////////////////////////////////////////// +static char gpsstr[]="gps"; +static struct miscdevice gps_miscdev; +struct hv5820b_gps_data *hv5820b_pdata ; +void *gps_mem =NULL; +unsigned long gps_mem_address; //BSP define for u32MemoryPhyAddr +unsigned long gps_mem_size = 8*0x00100000; //it must be more than 8MB + +/////////////////////////////////////////////////////////////////////////////////// +// +// extern variables declaration +// +/////////////////////////////////////////////////////////////////////////////////// +extern unsigned long gps_mem_address; //BSP define for u32MemoryPhyAddr +extern unsigned long gps_mem_size; //it must be more than 8MB + + +#ifdef GPS_USE_SPI +#include +void VtuneAndSpiCheck_rk(int enable_check); +int AdcValueGet(void); +int GetVtuneAdcValue_rk(void); +void ConfigRfSpi_rk(int Val ); +struct adc_client *adc_gps_cleint; +#define LOW_SCALE_0_65V 600 +#define HIGH_SCALE_0_95V 1000 +void gps_callback(struct adc_client *client, void *callback_param, int result) +{ + return; +} +void VtuneAndSpiCheck_rk(int enable_check) +{ + int VtuneAvg; + int SpiValue = 2; + int cnt = 0; + + if( enable_check == 0) + return; + + VtuneAvg = 0; + while( (VtuneAvg < LOW_SCALE_0_65V) || (VtuneAvg > HIGH_SCALE_0_95V) && cnt < 10) + { + if( (SpiValue >= 8) || (SpiValue <= 0) ) + break; + + VtuneAvg = AdcValueGet(); + + if( VtuneAvg < LOW_SCALE_0_65V) + { + SpiValue++; + ConfigRfSpi_rk( SpiValue); + } + + if( VtuneAvg > HIGH_SCALE_0_95V) + { + SpiValue--; + ConfigRfSpi_rk( SpiValue); + } + cnt ++; + } +} + + +int AdcValueGet() +{ + // Read adc value + int adc_value; + int sampletime = 100; + int AveValue; + int SumValue; + int i; + + + SumValue = 0; + for(i = 0; i < sampletime; i++) + { + adc_value = GetVtuneAdcValue_rk(); + + SumValue += adc_value; + } + AveValue = SumValue / sampletime; + return AveValue; +} + +int GetVtuneAdcValue_rk() +{ + int adc_val = 0; + + adc_val = adc_sync_read(adc_gps_cleint); + if(adc_val < 0) + printk("GetVtuneAdcValue error"); + + return adc_val; +} + +void ConfigRfSpi_rk(int Val ) +{ + int i; + +#define GPS_SCLK hv5820b_pdata->GpsSpiMOSI +#define GPS_MOSI hv5820b_pdata->GpsSpiClk +#define GPS_SCS hv5820b_pdata->GpsSpi_CSO + + + PAL_Clr_GPIO_Pin(GPS_SCLK); + PAL_Clr_GPIO_Pin(GPS_SCS); + + for(i = 0; i < 100000000; i++); + + PAL_Set_GPIO_Pin(GPS_SCLK); + PAL_Set_GPIO_Pin(GPS_MOSI); //b15 + + + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b14 + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b13 + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b12 + PAL_Clr_GPIO_Pin(GPS_MOSI); + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b11 + PAL_Set_GPIO_Pin(GPS_MOSI); + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b10 + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b9 + PAL_Clr_GPIO_Pin(GPS_MOSI); + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b8 + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b7 + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b6 + if ((Val >> 4) & 1) + PAL_Set_GPIO_Pin(GPS_MOSI); + else + PAL_Clr_GPIO_Pin(GPS_MOSI); + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b5 + if ((Val >> 3) & 1) + PAL_Set_GPIO_Pin(GPS_MOSI); + else + PAL_Clr_GPIO_Pin(GPS_MOSI); + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b4 + if ((Val >> 2) & 1) + PAL_Set_GPIO_Pin(GPS_MOSI); + else + PAL_Clr_GPIO_Pin(GPS_MOSI); + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b3 + if ((Val >> 1) & 1) + PAL_Set_GPIO_Pin(GPS_MOSI); + else + PAL_Clr_GPIO_Pin(GPS_MOSI); + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b2 + if ((Val >> 0) & 1) + PAL_Set_GPIO_Pin(GPS_MOSI); + else + PAL_Clr_GPIO_Pin(GPS_MOSI); + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b1 + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCLK); //b0 + for(i = 0; i < 100000000; i++); + PAL_Clr_GPIO_Pin(GPS_SCLK); + for(i = 0; i < 100000000; i++); + for(i = 0; i < 100000000; i++); + PAL_Set_GPIO_Pin(GPS_SCS); +} +#endif +static int hv5820b_gps_probe(struct platform_device *pdev) +{ + int err; + struct hv5820b_gps_data *pdata = pdev->dev.platform_data; + if(!pdata) + return -1; + hv5820b_pdata = pdata; + + printk("Enter GPSDrv_Init\n"); + + err = request_irq ( GPS_BB_INT_MASK, gps_int_handler, IRQF_DISABLED, gpsstr, NULL ); + + if ( err ) + { + printk ( "gps_mod_init: gps request irq failed!\n" ); + + return err; + } + + err = misc_register( &gps_miscdev); + if (err < 0) + { + return err; + } + + gps_mem=kzalloc(gps_mem_size, GFP_KERNEL); + gps_mem_address = (unsigned long)(&gps_mem); + //TODO: + //Set the GPIO (GPS_VCC_EN) to low level in here + // + if(pdata->io_init) + pdata->io_init(); + gpio_direction_output(pdata->GpsVCCEn, GPIO_LOW); + #ifdef GPS_USE_SPI + adc_gps_cleint = adc_register(2, gps_callback, NULL); + #endif + return 0; +} +static int hv5820b_gps_remove(struct platform_device *pdev) +{ +#ifdef GPS_USE_SPI + adc_unregister(adc_gps_cleint); +#endif + return 0; +} +static int hv5820b_gps_suspend(struct platform_device *pdev, pm_message_t state) +{ + return 0; +} +static int hv5820b_gps_resume(struct platform_device *pdev) +{ + return 0; +} +static struct platform_driver hv5820b_gps_driver = { + .probe = hv5820b_gps_probe, + .remove = hv5820b_gps_remove, + .suspend = hv5820b_gps_suspend, + .resume = hv5820b_gps_resume, + .driver = { + .name = "gps_hv5820b", + .owner = THIS_MODULE, + }, +}; + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name: gps_mod_init +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +static int __init gps_mod_init(void) +{ + return platform_driver_register(&hv5820b_gps_driver); +} + + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name: gps_mod_exit +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +static void __exit gps_mod_exit ( void ) +{ + //Disable baseband interrupt + WriteGpsRegisterUlong ( BB_INT_ENA_OFFSET, 0 ); + + free_irq( GPS_BB_INT_MASK, NULL ); + + //unregister_chrdev ( GPS_MAJOR, gpsstr ); + misc_deregister(&gps_miscdev); + platform_driver_unregister(&hv5820b_gps_driver); + printk ( "GPS exit ok!\n"); +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:gps_ioctl +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +long gps_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + int ret = 0; + BB_DRV_VERSION __user * pVersion; + GPS_DRV_INIT GpsInitStruct; + + switch(cmd) + { + + case IOCTL_BB_GPS_START: + //TODO: + // Gps baseband module initialize in here. + // Module power up + if(hv5820b_pdata->enable_hclk_gps) + hv5820b_pdata->enable_hclk_gps(); + + memset(&GpsInitStruct,0,sizeof(GpsInitStruct)); + GpsInitStruct.u32GpsRegBase = SW_VA_GPS_IO_BASE; // GPS Reg Base address + GpsInitStruct.u32MemoryPhyAddr = gps_mem_address; // sample code + GpsInitStruct.u32MemoryVirAddr = __phys_to_virt(gps_mem_address); + GpsInitStruct.u32GpsSign = hv5820b_pdata->GpsSign; //GPIO index + GpsInitStruct.u32GpsMag = hv5820b_pdata->GpsMag; //GPIO index + GpsInitStruct.u32GpsClk = hv5820b_pdata->GpsClk; //GPIO index + GpsInitStruct.u32GpsVCCEn = hv5820b_pdata->GpsVCCEn; //GPIO index + GpsInitStruct.u32GpsSpi_CSO = hv5820b_pdata->GpsSpi_CSO; //GPIO index + GpsInitStruct.u32GpsSpiClk = hv5820b_pdata->GpsSpiClk; //GPIO index + GpsInitStruct.u32GpsSpiMOSI = hv5820b_pdata->GpsSpiMOSI; //GPIO index + //TODO: + //Add other member of struct GpsInitStruct + Gps_Init( arg,&GpsInitStruct); + #ifdef GPS_USE_SPI + VtuneAndSpiCheck_rk(1); + #endif + break; + + case IOCTL_BB_UPDATEDATA: + Gps_UpdateData(arg); + break; + + + case IOCTL_BB_GPS_STOP: + Gps_Stop(); + + //TODO: + // Set the GPIO(GPS_VCC_EN) to low level + // Close the module clk. + gpio_direction_output(hv5820b_pdata->GpsVCCEn, GPIO_LOW); + if(hv5820b_pdata->disable_hclk_gps) + hv5820b_pdata->disable_hclk_gps(); + break; + + case IOCTL_BB_GET_VERSION: + pVersion = ( void __user * ) arg; + + pVersion->u32Major = DRV_MAJOR_VERSION; + pVersion->u32Minor = DRV_MINOR_VERSION; + PAL_Sprintf(pVersion->strCompileTime,"%s,%s",__DATE__,__TIME__); + + break; + + default: + + printk ( "gpsdrv: ioctl number is worng %d\n",cmd); + + break; + }; + + return ret; +} + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:gps_read +// Parameters: +// Description: Read gps data +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +ssize_t gps_read(struct file *file, char __user *buf, size_t size, loff_t *ppos) +{ + ssize_t nsize; + if((nsize = GpsDrv_Read(buf,size))) + { + return nsize; + } + + return -EFAULT; +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:gps_open +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +static int gps_open (struct inode *inode, struct file *filp) +{ + return 0; /* success */ +} + + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name:gps_close +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +static int gps_close (struct inode *inode, struct file *filp) +{ + return 0; +} + +/////////////////////////////////////////////////////////////////////////////////// +// +// Function Name: driver struct +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +static const struct file_operations gps_fops = +{ + . owner = THIS_MODULE, + . open = gps_open, + . release = gps_close, + . unlocked_ioctl = gps_ioctl, + . read = gps_read, +}; + +static struct miscdevice gps_miscdev = +{ + .minor = MISC_DYNAMIC_MINOR, + .name = gpsstr, + .fops = &gps_fops, +}; + + +/////////////////////////////////////////////////////////////////////////////////// +// +// Module Name: +// Parameters: +// Description: +// Notes: sjchen 2010/11/04 +// +/////////////////////////////////////////////////////////////////////////////////// +module_init ( gps_mod_init ); +module_exit ( gps_mod_exit ); + + +MODULE_LICENSE("GPL"); + + diff --git a/drivers/misc/gps/hv5820b/gpsdriver.h b/drivers/misc/gps/hv5820b/gpsdriver.h new file mode 100755 index 000000000000..026ab5a6faea --- /dev/null +++ b/drivers/misc/gps/hv5820b/gpsdriver.h @@ -0,0 +1,50 @@ +/////////////////////////////////////////////////////////////////////////////////// +// +// Filename: gpsdriver.h +// Author: sjchen +// Copyright: +// Date: 2012/07/09 +// Description: +// gps driver function +// +// Revision: +// 0.0.1 +// +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef __GPSDRIVER_H___ +#define __GPSDRIVER_H___ + +#define GPS_BB_INT_MASK 57 + + +typedef struct __tag_GPS_DRV_INIT +{ + unsigned long u32MemoryPhyAddr; //must reserved 8MB memory for GPS + unsigned long u32MemoryVirAddr; + unsigned long u32GpsRegBase; //GPS register base virtual address + unsigned int u32GpsSign; //GPIO index + unsigned int u32GpsMag; //GPIO index + unsigned int u32GpsClk; //GPIO index + unsigned int u32GpsVCCEn; //GPIO index + unsigned int u32GpsSpi_CSO; //GPIO index + unsigned int u32GpsSpiClk; //GPIO index + unsigned int u32GpsSpiMOSI; //GPIO index +}GPS_DRV_INIT,*PGPS_DRV_INIT; + +extern void WriteGpsRegisterUlong ( int reg_offset, int value ); + +extern int ReadGpsRegisterUlong ( int reg_offset ); + +extern irqreturn_t gps_int_handler ( int irq, void * dev_id ); + +extern void Gps_Init(unsigned long arg,PGPS_DRV_INIT pGpsDrvInit); + +extern void Gps_UpdateData(unsigned long arg); + +extern void Gps_Stop(void); + +extern int GpsDrv_Read(char *buf ,int nSize); + +#endif //__GPSDRIVER_H___ + diff --git a/drivers/misc/gps/hv5820b/gpsdrv.h b/drivers/misc/gps/hv5820b/gpsdrv.h new file mode 100755 index 000000000000..cc24b891c4d4 --- /dev/null +++ b/drivers/misc/gps/hv5820b/gpsdrv.h @@ -0,0 +1,53 @@ +/////////////////////////////////////////////////////////////////////////////////// +// +// Filename: gpsdrv.h +// Author: sjchen +// Copyright: +// Date: 2012/07/09 +// Description: +// the struct driver to app +// +// Revision: +// 0.0.1 +// +/////////////////////////////////////////////////////////////////////////////////// +#ifndef __GPSDRV_H__ +#define __GPSDRV_H__ + + +#define DRV_MAJOR_VERSION 1 +#define DRV_MINOR_VERSION 9 + +typedef struct __tag_BB_COMMAND_BUFFER { + int n32BufferA; + int n32BufferB; + int n32NavBuf; +} BB_COMMAND_BUFFER, *PBB_COMMAND_BUFFER; + + +typedef struct __tag_DRV_VERSION { + unsigned int u32Major; + unsigned int u32Minor; + char strCompileTime[32]; + +}BB_DRV_VERSION,*PBB_DRV_VERSION; + +// IOCTL code +enum +{ + // GPS Start + IOCTL_BB_GPS_START = 128, + IOCTL_BB_GPS_STOP, + + //Update gps data + IOCTL_BB_UPDATEDATA, + + //Driver version + IOCTL_BB_GET_VERSION + +}; + +#endif /* __GPSDRV_H__ */ + + + diff --git a/drivers/misc/gps/hv5820b/hv5820b_gps.h b/drivers/misc/gps/hv5820b/hv5820b_gps.h new file mode 100755 index 000000000000..bec227d55104 --- /dev/null +++ b/drivers/misc/gps/hv5820b/hv5820b_gps.h @@ -0,0 +1,25 @@ +/* + 2012.07.25 lby@rock-chips.com +*/ + +#ifndef __HV5820B_GPS_H__ +#define __HV5820B_GPS_H__ + +struct hv5820b_gps_data { + int (*io_init)(void); + int (*power_up)(void); + int (*power_down)(void); + int (*reset)(int); + int (*enable_hclk_gps)(void); + int (*disable_hclk_gps)(void); + int GpsSign; + int GpsMag; //GPIO index + int GpsClk; //GPIO index + int GpsVCCEn; //GPIO index + int GpsSpi_CSO; //GPIO index + int GpsSpiClk; //GPIO index + int GpsSpiMOSI; //GPIO index + +}; + +#endif diff --git a/drivers/misc/gps/hv5820b/lnxdrv.h b/drivers/misc/gps/hv5820b/lnxdrv.h new file mode 100755 index 000000000000..56c6f026fefd --- /dev/null +++ b/drivers/misc/gps/hv5820b/lnxdrv.h @@ -0,0 +1,52 @@ +/////////////////////////////////////////////////////////////////////////////////// +// +// Filename: lnxdrv.h +// Author: sjchen +// Copyright: +// Date: 2012/07/09 +// Description: +// the macor of GPS baseband +// +// Revision: +// 0.0.1 +// +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef __LNXDRV_H__ +#define __LNXDRV_H__ + +/////////////////////////////////////////////////////////////////////////////////// +// +// macro declaration +// +/////////////////////////////////////////////////////////////////////////////////// + +#define MEM_CHECK_BOUNDARY (16) + +//base band control registers offset +#define BB_CTRL_OFFSET 0x0400 +#define BB_START_ADR_OFFSET 0x0404 +#define BB_DS_PAR_OFFSET 0x0408 +#define BB_INT_ENA_OFFSET 0x040c +#define BB_INT_STATUS_OFFSET 0x0410 +#define BB_CHN_STATUS_OFFSET 0x0414 +#define BB_CHN_VALID_OFFSET 0x0418 +#define BB_TIMER_VAL_OFFSET 0x041c +#define BB_RF_WT_ADDR_OFFSET 0x0420 + + + +//the following is bb register bit define +#define BB_RESET 0x4 +#define BB_NXT_BLK 0x2 +#define BB_TRICKLE 0x1 +#define BB_CTRL_CLR 0x0 + +#define TIMEOUT_INT 0x1 +#define ACC_BLK_DONE_INT 0x2 +#define OBUF_RDY_INT 0x4 + +#endif /* __LNXDRV_H__ */ + + + -- 2.34.1