From 50fa88d4602146c7236176a5952098253f1247cb Mon Sep 17 00:00:00 2001
From: =?utf8?q?=E5=BC=A0=E6=99=B4?= <zhangqing@rock-chips.com>
Date: Mon, 26 May 2014 16:32:01 +0800
Subject: [PATCH] rk3288:pmic:ricoh619:slove reboot i2c error;modify power
 off;slove fg 100%

---
 drivers/mfd/ricoh619.c           | 58 +++++++++++++++++---------------
 drivers/power/ricoh619-battery.c |  7 +++-
 2 files changed, 37 insertions(+), 28 deletions(-)
 mode change 100644 => 100755 drivers/power/ricoh619-battery.c

diff --git a/drivers/mfd/ricoh619.c b/drivers/mfd/ricoh619.c
index cd2a3058a7ed..971dfe0f73d3 100644
--- a/drivers/mfd/ricoh619.c
+++ b/drivers/mfd/ricoh619.c
@@ -43,7 +43,7 @@
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
 #include <linux/regmap.h>
-
+#include <linux/delay.h>
 
 struct ricoh619 *g_ricoh619;
 struct sleep_control_data {
@@ -181,11 +181,11 @@ int ricoh619_write(struct device *dev, u8 reg, uint8_t val)
 	struct ricoh619 *ricoh619 = dev_get_drvdata(dev);
 	int ret = 0;
 
-//	mutex_lock(&ricoh619->io_lock);
+	mutex_lock(&ricoh619->io_lock);
 	ret = set_bank_ricoh619(dev, 0);
 	if( !ret )
 		ret = __ricoh619_write(to_i2c_client(dev), reg, val);
-//	mutex_unlock(&ricoh619->io_lock);
+	mutex_unlock(&ricoh619->io_lock);
 
 	return ret;
 }
@@ -424,38 +424,42 @@ static int ricoh619_device_shutdown(struct i2c_client *client)
 	ret = ricoh619_clr_bits(ricoh619->dev, 0xae, (0x1 <<6)); //disable alam_d
        ret = ricoh619_write(ricoh619->dev, RICOH619_INTC_INTEN, 0); 
 	ret = ricoh619_clr_bits(ricoh619->dev,RICOH619_PWR_REP_CNT,(0x1<<0));//Not repeat power ON after power off(Power Off/N_OE)
+	mutex_lock(&ricoh619->io_lock);
+	msleep(100);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(ricoh619_device_shutdown);
 static int ricoh619_power_off(void)
 {
-	int ret;
+	int ret,i=0;
 	uint8_t val,charge_state;
 	struct i2c_client *client = ricoh619_i2c_client;
-	printk("%s,line=%d\n", __func__,__LINE__);
-#ifdef CONFIG_BATTERY_RICOH619
-	ret = __ricoh619_read(client, 0xBD, &val);
-	if(ret < 0)
-		goto erro;
-	charge_state = (val & 0x1F);
-	if(( charge_state == CHG_STATE_CHG_TRICKLE)||( charge_state == CHG_STATE_CHG_RAPID) ||(charge_state == CHG_STATE_CHG_COMPLETE)){
-		 ret = __ricoh619_read(client, RICOH619_PWR_REP_CNT,&val);//Power OFF
-		 if(ret < 0)
-			goto erro;
-		 ret = __ricoh619_write(client, RICOH619_PWR_REP_CNT,(val |(0x1<<0)));//Power OFF
-		 if(ret < 0)
-			goto erro;
-	}
-#endif  
-	ret = __ricoh619_read(client, RICOH619_PWR_SLP_CNT,&val);//Power OFF
-	 if(ret < 0)
-		goto erro;
-	ret = __ricoh619_write(client, RICOH619_PWR_SLP_CNT,(val |(0x1<<0)));//Power OFF
-	if (ret < 0) {
-		printk("ricoh619 power off error!\n");
-		goto erro;
+
+	for(i=0;i < 10;i++){
+		printk("%s,line=%d\n", __func__,__LINE__);
+		#ifdef CONFIG_BATTERY_RICOH619
+			ret = __ricoh619_read(client, 0xBD, &val);
+			if(ret < 0)
+				continue;
+			charge_state = (val & 0x1F);
+			if(( charge_state == CHG_STATE_CHG_TRICKLE)||( charge_state == CHG_STATE_CHG_RAPID) ||(charge_state == CHG_STATE_CHG_COMPLETE)){
+			 ret = __ricoh619_read(client, RICOH619_PWR_REP_CNT,&val);//Power OFF
+			 if(ret < 0)
+				continue;
+		 	ret = __ricoh619_write(client, RICOH619_PWR_REP_CNT,(val |(0x1<<0)));//Power OFF
+		 	if(ret < 0)
+				continue;
+		}
+		#endif  
+		ret = __ricoh619_read(client, RICOH619_PWR_SLP_CNT,&val);//Power OFF
+		if(ret < 0)
+			continue;
+		ret = __ricoh619_write(client, RICOH619_PWR_SLP_CNT,(val |(0x1<<0)));//Power OFF
+		if (ret < 0) {
+			printk("ricoh619 power off error!\n");
+			continue;
+		}
 	}
-erro:
 	while(1)wfi();
 }
 EXPORT_SYMBOL_GPL(ricoh619_power_off);
diff --git a/drivers/power/ricoh619-battery.c b/drivers/power/ricoh619-battery.c
old mode 100644
new mode 100755
index c5d110184e19..6be578cda222
--- a/drivers/power/ricoh619-battery.c
+++ b/drivers/power/ricoh619-battery.c
@@ -1462,6 +1462,11 @@ static void ricoh619_displayed_work(struct work_struct *work)
 						  }
 					}
 				} else {
+					if(info->soca->displayed_soc >= 9850)
+					{
+						info->soca->displayed_soc = 10000;
+						info->chg_complete_tm_ov_flag = 1;
+					}
 					info->soca->status = RICOH619_SOCA_UNSTABLE;
 				}
 			}
@@ -3206,7 +3211,7 @@ static void charger_irq_work(struct work_struct *work)
 				power_supply_changed(&info->battery);
 				power_supply_changed(&powerac);
 				power_supply_changed(&powerusb);
-				mdelay(100);
+				msleep(100);
 				}
 			#else //support adp and usb chag
 			if (gpio_is_valid(g_ricoh619->dc_det)){
-- 
2.34.1