From 5dc17820ab11c3d99c5f270a04fa644ce8a38907 Mon Sep 17 00:00:00 2001
From: =?utf8?q?=E5=BC=A0=E6=99=B4?= <zhangqing@rock-chips.com>
Date: Thu, 9 Oct 2014 14:42:36 +0800
Subject: [PATCH] rk312x:pmic:rt5036:updata drivers to 1.0.9;support hdmi
 connect to VMID

---
 drivers/power/Kconfig             |  7 +++
 drivers/power/rt5036-charger.c    | 98 +++++++++++++++++++++++++++++--
 include/linux/mfd/rt5036/rt5036.h |  2 +-
 3 files changed, 101 insertions(+), 6 deletions(-)
 mode change 100755 => 100644 drivers/power/Kconfig
 mode change 100755 => 100644 drivers/power/rt5036-charger.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
old mode 100755
new mode 100644
index 4ad577dfa837..4f4ffb692431
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -92,6 +92,13 @@ config CHARGER_RT5036
 	help
 	  Say Y here to enable support for RT5036 chip charger subdevice.
 
+config CHARGER_RT5036_VMID_HDMI
+	bool "RT5036 charger VMID HDMI support"
+	depends on CHARGER_RT5036
+	default n
+	help
+	  Say Y here to enable support for RT5036 charger VMID HDMI Boost.
+
 config RT_POWER
 	bool "RT PMIC cable report"
 	depends on CHARGER_RT5036 || CHARGER_RT5025
diff --git a/drivers/power/rt5036-charger.c b/drivers/power/rt5036-charger.c
old mode 100755
new mode 100644
index 85830781e589..ec0c831e0ab1
--- a/drivers/power/rt5036-charger.c
+++ b/drivers/power/rt5036-charger.c
@@ -44,12 +44,20 @@
 
 static unsigned char chg_init_regval[] = {
 	0xb0,			/*REG 0x01*/
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+	0xDC,			/*REG 0x02*/
+#else
 	0x58,			/*REG 0x02*/
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
 	0x00,			/*REG 0x03*/
 	0xFE,			/*REG 0x04*/
 	0x93,			/*REG 0x05*/
 	0xAD,			/*REG 0x06*/
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+	0x94,			/*REG 0x07*/
+	#else
 	0xB4,			/*REG 0x07*/
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
 	0x01,			/*REG 0x08*/
 	0x0C,			/*REG 0x13*/
 	0x80,			/*REG 0x14*/
@@ -381,9 +389,16 @@ static int rt_charger_set_property(struct power_supply *psy,
 				ci->psy.set_property(&ci->psy,
 					POWER_SUPPLY_PROP_VOLTAGE_NOW,
 					&pval);
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+				dev_info(ci->dev, "set UUG on\n");
+				ret = rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL6, 0x20);
+				rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL1,
+					    RT5036_CHGOPAMODE_MASK);
+#else
 				ret =
 				    rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL1,
 						    RT5036_CHGOPAMODE_MASK);
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
 				/* otg drop fix */
 				mdelay(10);
 				rt5036_clr_bits(ci->i2c, 0x23, 0x3);
@@ -396,23 +411,39 @@ static int rt_charger_set_property(struct power_supply *psy,
 			ci->psy.set_property(&ci->psy,
 					     POWER_SUPPLY_PROP_VOLTAGE_NOW,
 					     &pval);
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+			ret = rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL6, 0x20);
+#else
 			ret =
 			    rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL1,
 					    RT5036_CHGOPAMODE_MASK);
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
 			/* otg drop fix */
 			mdelay(10);
 			rt5036_clr_bits(ci->i2c, 0x23, 0x3);
 #endif /* #ifdef CONFIG_RT_SUPPORT_ACUSB_DUALIN */
 		} else if (val->intval == 0) {
 #ifdef CONFIG_RT_SUPPORT_ACUSB_DUALIN
-			if (ci->charge_cable != POWER_SUPPLY_TYPE_MAINS)
+			if (ci->charge_cable != POWER_SUPPLY_TYPE_MAINS) {
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+				dev_info(ci->dev, "set UUG off\n");
+				ret = rt5036_clr_bits(ci->i2c, RT5036_REG_CHGCTL6, 0x20);
+				rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL1,
+					    RT5036_CHGOPAMODE_MASK);
+#else
 				ret =
 				    rt5036_clr_bits(ci->i2c, RT5036_REG_CHGCTL1,
 						    RT5036_CHGOPAMODE_MASK);
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
+			}
+#else
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+			ret = rt5036_clr_bits(ci->i2c, RT5036_REG_CHGCTL6, 0x20);
 #else
 			ret =
 			    rt5036_clr_bits(ci->i2c, RT5036_REG_CHGCTL1,
 					    RT5036_CHGOPAMODE_MASK);
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
 #endif /* #ifdef CONFIG_RT_SUPPORT_ACUSB_DUALIN */
 			ci->otg_en = 0;
 		} else if (val->intval < 500)
@@ -475,6 +506,11 @@ static void rt5036_stat2alrt_irq_handler(void *info, int eventno)
 			struct power_supply *psy =
 			    power_supply_get_by_name(RT_USB_NAME);
 			if (psy) {
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+				rt5036_clr_bits(ci->i2c, RT5036_REG_CHGCTL1,
+					    RT5036_CHGOPAMODE_MASK);
+				rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL6, 0x20);
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
 				pval.intval = 1;
 				psy->set_property(psy, POWER_SUPPLY_PROP_ONLINE,
 						  &pval);
@@ -494,13 +530,21 @@ static void rt5036_stat2alrt_irq_handler(void *info, int eventno)
 				psy->set_property(psy, POWER_SUPPLY_PROP_ONLINE,
 						  &pval);
 				power_supply_changed(psy);
-			} else {
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+				rt5036_clr_bits(ci->i2c, RT5036_REG_CHGCTL6, 0x20);
+				pval.intval = ci->otg_volt;
+				ci->psy.set_property(&ci->psy,
+						     POWER_SUPPLY_PROP_VOLTAGE_NOW,
+						     &pval);
+				rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL1,
+					    RT5036_CHGOPAMODE_MASK);
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
+			} else
 				dev_err(ci->dev, "couldn't get RT usb\n");
 			}
 #endif /* #ifndef CONFIG_RT_SUPPORT_ACUSB_DUALIN */
 			dev_info(ci->dev, "cable out\n");
 		}
-	}
 	/*jeita status change*/
 	old_stat = new_stat & RT5036_TSEVENT_MASK;
 	if (old_stat & RT5036_TSWC_MASK) {
@@ -752,9 +796,15 @@ static irqreturn_t rt5036_acdet_irq_handler(int irqno, void *param)
 		else
 			irq_set_irq_type(ci->acdet_irq, IRQF_TRIGGER_RISING);
 		if (psy) {
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+			rt5036_clr_bits(ci->i2c, RT5036_REG_CHGCTL1,
+				    RT5036_CHGOPAMODE_MASK);
+			rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL6, 0x20);
+#else
 			if (ci->otg_en)
 				rt5036_clr_bits(ci->i2c, RT5036_REG_CHGCTL1,
 						RT5036_CHGOPAMODE_MASK);
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
 			pval.intval = 1;
 			psy->set_property(psy, POWER_SUPPLY_PROP_ONLINE, &pval);
 			power_supply_changed(psy);
@@ -774,6 +824,20 @@ static irqreturn_t rt5036_acdet_irq_handler(int irqno, void *param)
 			pval.intval = 0;
 			psy->set_property(psy, POWER_SUPPLY_PROP_ONLINE, &pval);
 			power_supply_changed(psy);
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+			if (ci->charge_cable == 0) {
+				if (ci->otg_en)
+					rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL6, 0x20);
+				else
+					rt5036_clr_bits(ci->i2c, RT5036_REG_CHGCTL6, 0x20);
+				pval.intval = ci->otg_volt;
+				ci->psy.set_property(&ci->psy,
+						     POWER_SUPPLY_PROP_VOLTAGE_NOW,
+						     &pval);
+				rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL1,
+					    RT5036_CHGOPAMODE_MASK);
+			}
+#else
 			if (ci->otg_en) {
 				/*set otg voltage*/
 				pval.intval = ci->otg_volt;
@@ -783,7 +847,8 @@ static irqreturn_t rt5036_acdet_irq_handler(int irqno, void *param)
 				rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL1,
 						RT5036_CHGOPAMODE_MASK);
 			}
-		} else {
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
+		} else
 			dev_err(ci->dev, "couldn't get RT ac\n");
 			}
 		dev_info(ci->dev, "ac out\n");
@@ -808,6 +873,11 @@ static irqreturn_t rt5036_usbdet_irq_handler(int irqno, void *param)
 		else
 			irq_set_irq_type(ci->usbdet_irq, IRQF_TRIGGER_RISING);
 		if (psy) {
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+			rt5036_clr_bits(ci->i2c, RT5036_REG_CHGCTL1,
+				    RT5036_CHGOPAMODE_MASK);
+			rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL6, 0x20);
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
 			pval.intval = 1;
 			psy->set_property(psy, POWER_SUPPLY_PROP_ONLINE, &pval);
 			power_supply_changed(psy);
@@ -827,7 +897,18 @@ static irqreturn_t rt5036_usbdet_irq_handler(int irqno, void *param)
 			pval.intval = 0;
 			psy->set_property(psy, POWER_SUPPLY_PROP_ONLINE, &pval);
 			power_supply_changed(psy);
-		} else {
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+			if (ci->charge_cable == 0) {
+				rt5036_clr_bits(ci->i2c, RT5036_REG_CHGCTL6, 0x20);
+				pval.intval = ci->otg_volt;
+				ci->psy.set_property(&ci->psy,
+						     POWER_SUPPLY_PROP_VOLTAGE_NOW,
+						     &pval);
+				rt5036_set_bits(ci->i2c, RT5036_REG_CHGCTL1,
+					    RT5036_CHGOPAMODE_MASK);
+			}
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
+		} else
 			dev_err(ci->dev, "couldn't get RT usb\n");
 			}
 		dev_info(ci->dev, "usb out\n");
@@ -910,7 +991,11 @@ static int rt5036_charger_reginit(struct i2c_client *client)
 	/*thermal HGM*/
 	rt5036_set_bits(client, 0x20, 0x40);
 	/*charger fix in rev D IC*/
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+	rt5036_reg_write(client, 0x22, 0x60);
+#else
 	rt5036_reg_write(client, 0x22, 0xE0);
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
 	/*write charger init val*/
 	rt5036_reg_block_write(client, RT5036_REG_CHGCTL1, 8, chg_init_regval);
 	rt5036_reg_block_write(client, RT5036_REG_CHGIRQMASK1, 3,
@@ -922,6 +1007,9 @@ static int rt5036_charger_reginit(struct i2c_client *client)
 	rt5036_reg_read(client, RT5036_REG_CHGIRQ3);
 	rt5036_set_bits(client, 0x20, RT5036_TERST_MASK);
 	rt5036_clr_bits(client, 0x20, RT5036_TERST_MASK);
+#ifdef CONFIG_CHARGER_RT5036_VMID_HDMI
+	rt5036_set_bits(client, RT5036_REG_CHGCTL1, RT5036_CHGOPAMODE_MASK);
+#endif /* #ifdef CONFIG_CHARGER_RT5036_VMID_HDMI */
 	RTINFO("\n");
 	return 0;
 }
diff --git a/include/linux/mfd/rt5036/rt5036.h b/include/linux/mfd/rt5036/rt5036.h
index 2b56d411a1c8..92dfc885aa9d 100644
--- a/include/linux/mfd/rt5036/rt5036.h
+++ b/include/linux/mfd/rt5036/rt5036.h
@@ -16,7 +16,7 @@
 #include <linux/power_supply.h>
 
 #define RT5036_DEV_NAME		"rt5036"
-#define RT5036_DRV_VER		"1.0.8_R"
+#define RT5036_DRV_VER		"1.0.9_R"
 
 enum {
 	RT5036_ID_DCDC1,
-- 
2.34.1