From: 蔡枫 Date: Mon, 4 Jul 2011 12:27:38 +0000 (+0800) Subject: add ac detec and gps power control function X-Git-Tag: firefly_0821_release~10145 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=595fa8db39989137f64a26570e6b0e5fc23d0bbe;p=firefly-linux-kernel-4.4.55.git add ac detec and gps power control function --- diff --git a/arch/arm/mach-rk29/board-rk29-newton.c b/arch/arm/mach-rk29/board-rk29-newton.c index 190070164d7a..cfc0a314d53b 100755 --- a/arch/arm/mach-rk29/board-rk29-newton.c +++ b/arch/arm/mach-rk29/board-rk29-newton.c @@ -516,25 +516,6 @@ static struct mma8452_platform_data mma8452_info = { }; #endif -#if defined (CONFIG_BATTERY_BQ27510) -#define DC_CHECK_PIN RK29_PIN4_PA1 -#define LI_LION_BAT_NUM 2 -static int bq27510_init_dc_check_pin(void){ - if(gpio_request(DC_CHECK_PIN,"dc_check") != 0){ - gpio_free(DC_CHECK_PIN); - printk("bq27510 init dc check pin request error\n"); - return -EIO; - } - gpio_direction_input(DC_CHECK_PIN); - return 0; -} - -struct bq27510_platform_data bq27510_info = { - .init_dc_check_pin = bq27510_init_dc_check_pin, - .dc_check_pin = DC_CHECK_PIN, - .bat_num = LI_LION_BAT_NUM, -}; -#endif /***************************************************************************************** @@ -723,14 +704,6 @@ static struct i2c_board_info __initdata board_i2c0_devices[] = { .flags = 0, }, #endif -#if defined (CONFIG_BATTERY_BQ27510) - { - .type = "bq27510", - .addr = 0x55, - .flags = 0, - .platform_data = &bq27510_info, - }, -#endif #if defined (CONFIG_RTC_HYM8563) { .type = "rtc_hym8563", diff --git a/drivers/misc/newton.c b/drivers/misc/newton.c index c8853bbcb64d..a04288d7173c 100755 --- a/drivers/misc/newton.c +++ b/drivers/misc/newton.c @@ -17,18 +17,22 @@ - +#define NEWTON_DEV "newton:" #if 1 -#define DBG(x...) printk(KERN_INFO x) +#define DBG(x...) printk(KERN_INFO NEWTON_DEV x) #else #define DBG(x...) #endif -#define NEWTON_GPIO_R RK29_PIN4_PB0 -#define NEWTON_GPIO_G RK29_PIN4_PB1 -#define NEWTON_GPIO_B RK29_PIN4_PB2 -#define NEWTON_GET_UID 0x6001 +#define NEWTON_GPIO_R RK29_PIN4_PB0 +#define NEWTON_GPIO_G RK29_PIN4_PB1 +#define NEWTON_GPIO_B RK29_PIN4_PB2 +#define NEWTON_GPIO_AC_DETEC RK29_PIN4_PA1 +#define NEWTON_GPIO_GPS_PWR RK29_PIN6_PB2 +#define NEWTON_GET_UID 0x6001 +#define NEWTON_AC_DETEC 0x6002 +#define NEWTON_GPS_CTRL 0x6003 typedef struct{ uint16_t SN_Size; //0-1 char SN[30]; //2-31 @@ -42,7 +46,7 @@ char BlueTooth[6]; //499-504 char Mac_Size; //505 char Mac_Data[6]; //506-511 }IdbSector3; -static int led_state = 0; +int gps_power = 0; char GetSNSectorInfo(char * pbuf); int newton_print_buf(char *buf,int size) @@ -68,8 +72,30 @@ int newton_print_buf(char *buf,int size) printk("0x%02x ",*pbuf); pbuf++; } + return 0; +} + + +int rk29_newton_get_ac_status() +{ + int ac_status = 0; + + gpio_direction_input(NEWTON_GPIO_AC_DETEC); + ac_status = gpio_get_value(NEWTON_GPIO_AC_DETEC); + DBG("%s:NEWTON_GPIO_AC_DETEC = %d\n",__FUNCTION__,ac_status); + return ac_status; +} + + +int rk29_newton_set_gps_power(int value) +{ + DBG("%s:value = %d\n",__FUNCTION__,value); + gpio_direction_output(NEWTON_GPIO_GPS_PWR, 0); + gpio_set_value(NEWTON_GPIO_GPS_PWR,value); + return 0; } + int rk29_newton_open(struct inode *inode, struct file *filp) { DBG("%s\n",__FUNCTION__); @@ -84,26 +110,48 @@ ssize_t rk29_newton_read(struct file *filp, char __user *ptr, size_t size, loff_ ssize_t rk29_newton_write(struct file *filp, char __user *ptr, size_t size, loff_t *pos) { + DBG("%s\n",__FUNCTION__); return sizeof(int); } int rk29_newton_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg) { - int ret = 0; void __user *argp = (void __user *)arg; - DBG("%s\n",__FUNCTION__); + //DBG("%s\n",__FUNCTION__); switch(cmd) { case NEWTON_GET_UID: { IdbSector3 sn; + DBG("%s:NEWTON_GET_UID\n",__FUNCTION__); memset(&sn,0,sizeof(IdbSector3)); - GetSNSectorInfo(&sn); + GetSNSectorInfo((char*)&sn); //newton_print_buf(&sn.UID_Data, sizeof(sn.UID_Data)); if(copy_to_user(argp, &sn.UID_Data, sizeof(sn.UID_Data))) return -EFAULT; } break; + case NEWTON_AC_DETEC: + { + int ac_status = rk29_newton_get_ac_status(); + if(copy_to_user(argp, &ac_status, 4)) return -EFAULT; + } + break; + case NEWTON_GPS_CTRL: + { + int value = 0; + if(copy_from_user(&value, (void*)arg, 4)){ + DBG("%s:NEWTON_GPS_CTRL,copy_from_user error\n",__FUNCTION__); + return -EFAULT; + } + if((value != 0) && (value != 1)){ + DBG("%s:NEWTON_GPS_CTRL,parameter error,value = %d\n",__FUNCTION__,value); + return -EFAULT; + } + gps_power = value; + rk29_newton_set_gps_power(value); + } + break; default: break; } @@ -149,34 +197,18 @@ static int rk29_newton_probe(struct platform_device *pdev) printk("rk29 newton register err!\n"); return ret; } -#if 0 - if(gpio_request(NEWTON_GPIO_R,NULL) != 0){ - gpio_free(NEWTON_GPIO_R); - printk("rk29_newton_probe gpio_request NEWTON_GPIO_R error\n"); - return -EIO; - } - - if(gpio_request(NEWTON_GPIO_G,NULL) != 0){ - gpio_free(NEWTON_GPIO_G); - printk("rk29_newton_probe gpio_request NEWTON_GPIO_G error\n"); - return -EIO; - } - - if(gpio_request(NEWTON_GPIO_B,NULL) != 0){ - gpio_free(NEWTON_GPIO_B); - printk("rk29_newton_probe gpio_request NEWTON_GPIO_B error\n"); - return -EIO; - } - - gpio_direction_output(NEWTON_GPIO_R, 0); - gpio_set_value(NEWTON_GPIO_R,GPIO_LOW); - gpio_direction_output(NEWTON_GPIO_G, 0); - gpio_set_value(NEWTON_GPIO_G,GPIO_LOW); - gpio_direction_output(NEWTON_GPIO_B, 0); - gpio_set_value(NEWTON_GPIO_B,GPIO_LOW); -#endif + if(gpio_request(NEWTON_GPIO_GPS_PWR,NULL) != 0){ + gpio_free(NEWTON_GPIO_GPS_PWR); + printk("gpio_request NEWTON_GPIO_GPS_PWR error\n"); + return -EIO; + } + if(gpio_request(NEWTON_GPIO_AC_DETEC,NULL) != 0){ + gpio_free(NEWTON_GPIO_AC_DETEC); + printk("gpio_request NEWTON_GPIO_AC_DETEC error\n"); + return -EIO; + } + rk29_newton_set_gps_power(GPIO_LOW); DBG("%s:rk29 newton initialized\n",__FUNCTION__); - return ret; } @@ -189,11 +221,15 @@ static int rk29_newton_remove(struct platform_device *pdev) int rk29_newton_suspend(struct platform_device *pdev, pm_message_t state) { + if(gps_power==GPIO_HIGH) + rk29_newton_set_gps_power(GPIO_LOW); return 0; } int rk29_newton_resume(struct platform_device *pdev) { + if(gps_power==GPIO_HIGH) + rk29_newton_set_gps_power(gps_power); return 0; }