#ifdef MTK_GPS_SUPPORT
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/wait.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/poll.h>
#include <linux/device.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/cdev.h>
#include <linux/errno.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <linux/xlog.h>
#include <linux/semaphore.h>
#include <linux/version.h>
#include <mach/devs.h>
#include <mach/mt_typedefs.h>
//#define FAKE_DATA
#define GPS_SUSPEND_RESUME
#define GPS_CONFIGURABLE_RESET_DELAY
#define GPS_DEVNAME "mt3326-gps"
#define GPS_DBG_NONE(fmt, arg...) do {} while (0)
#define GPS_DBG_FUNC(fmt, arg...) xlog_printk(ANDROID_LOG_DEBUG, PFX, "%s: " fmt, __FUNCTION__ ,##arg)
#define GPS_ERR(fmt, arg...) xlog_printk(ANDROID_LOG_ERROR, PFX, "%s: " fmt, __FUNCTION__ ,##arg)
#define GPS_WARN(fmt, arg...) xlog_printk(ANDROID_LOG_WARN, PFX, "%s" fmt, __FUNCTION__ ,##arg)
#define GPS_NOTICE(fmt, arg...) xlog_printk(ANDROID_LOG_INFO, PFX, "%s: " fmt, __FUNCTION__ ,##arg)
#define GPS_INFO(fmt, arg...) xlog_printk(ANDROID_LOG_INFO, PFX, "%s: " fmt, __FUNCTION__ ,##arg)
#define GPS_TRC_FUNC(f) xlog_printk(ANDROID_LOG_INFO, PFX, "<%s>
", __FUNCTION__);
#define GPS_TRC_VERBOSE(fmt, arg...) xlog_printk(ANDROID_LOG_VERBOSE, PFX, "%s: " fmt, __FUNCTION__ ,##arg)
#define PFX "GPS: "
#define GPS_DBG GPS_DBG_FUNC
#define GPS_TRC GPS_DBG_NONE //GPS_TRC_FUNC
#define GPS_VER GPS_DBG_NONE //GPS_TRC_VERBOSE
#define IH_DBG GPS_DBG_NONE
enum {
GPS_PWRCTL_UNSUPPORTED = 0xFF,
GPS_PWRCTL_OFF = 0x00,
GPS_PWRCTL_ON = 0x01,
GPS_PWRCTL_RST = 0x02,
GPS_PWRCTL_OFF_FORCE = 0x03,
GPS_PWRCTL_RST_FORCE = 0x04,
GPS_PWRCTL_MAX = 0x05,
};
enum {
GPS_PWR_UNSUPPORTED = 0xFF,
GPS_PWR_RESUME = 0x00,
GPS_PWR_SUSPEND = 0x01,
GPS_PWR_MAX = 0x02,
};
enum {
GPS_STATE_UNSUPPORTED = 0xFF,
GPS_STATE_OFF = 0x00,
GPS_STATE_INIT = 0x01,
GPS_STATE_START = 0x02,
GPS_STATE_STOP = 0x03,
GPS_STATE_DEC_FREQ = 0x04,
GPS_STATE_SLEEP = 0x05,
GPS_STATE_MAX = 0x06,
};
enum {
GPS_PWRSAVE_UNSUPPORTED = 0xFF,
GPS_PWRSAVE_DEC_FREQ = 0x00,
GPS_PWRSAVE_SLEEP = 0x01,
GPS_PWRSAVE_OFF = 0x02,
GPS_PWRSAVE_MAX = 0x03,
};
struct gps_data{
int dat_len;
int dat_pos;
char dat_buf[4096];
spinlock_t lock;
wait_queue_head_t read_wait;
struct semaphore sem;
};
struct gps_sta_itm {
unsigned char year;
unsigned char month;
unsigned char day;
unsigned char hour;
unsigned char minute;
unsigned char sec;
unsigned char count;
unsigned char reason;
};
struct gps_sta_obj {
int index;
struct gps_sta_itm items[32];
};
struct gps_drv_obj {
unsigned char pwrctl;
unsigned char suspend;
unsigned char state;
unsigned char pwrsave;
int rdelay;
struct kobject *kobj;
struct mutex sem;
struct gps_sta_obj status;
struct mt3326_gps_hardware *hw;
};
struct gps_dev_obj {
struct class *cls;
struct device *dev;
dev_t devno;
struct cdev chdev;
struct mt3326_gps_hardware *hw;
};
static struct gps_data gps_private= {0};
#if defined(FAKE_DATA)
static char fake_data[] = {
"$GPGGA,135036.000,2446.3713,N,12101.3605,E,1,5,1.61,191.1,M,15.1,M,,*51
"
"$GPGSA,A,3,22,18,14,30,31,,,,,,,,1.88,1.61,0.98*09
"
"$GPGSV,2,1,6,18,83,106,32,22,58,324,35,30,45,157,35,14,28,308,32*44
"
"$GPGSV,2,2,6,40,21,254,,31,17,237,29*42
"
"$GPRMC,135036.000,A,2446.37125,N,12101.36054,E,0.243,56.48,140109,,A*46
"
"$GPVTG,56.48,T,,M,0.243,N,0.451,K,A*07
"
};
#endif //FAKE_DATA
static char *str_reason[] = {"none", "init", "monitor", "wakeup", "TTFF", "force", "unknown"};
static inline void mt3326_gps_power(struct mt3326_gps_hardware *hw,
unsigned int on, unsigned int force)
{
static unsigned int power_on = 1;
int err;
GPS_DBG("Switching GPS device %s
", on ? "on" : "off");
if (!hw) {
GPS_ERR("null pointer!!
");
return;
}
if (power_on == on) {
GPS_DBG("ignore power control: %d
", on);
} else if (on) {
if (hw->ext_power_on) {
err = hw->ext_power_on(0);
if (err)
GPS_ERR("ext_power_on fail
");
}
#if 0
#ifndef MTK_MT6620
if (!hwPowerOn(MT6516_POWER_V3GTX, VOL_2800,"MT3326")) {
GPS_ERR("power on fails!!
");
return;
}
#endif
#endif
if (hw->ext_power_on) {
err = hw->ext_power_on(1);
if (err)
GPS_ERR("ext_power_on fail
本文地址:http://www78564.xrbh.cn/news/32539.html
迅博思语 http://www78564.xrbh.cn/ , 查看更多