<commit_before>From 6f8787b48256814a7acea71029c50cdbb08cf953 Mon Sep 17 00:00:00 2001
From: <NAME> <<EMAIL>>
Date: Tue, 11 Feb 2014 18:04:40 -0500
Subject: [PATCH] Enable RTC backup battery charging

---
 drivers/rtc/rtc-twl.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index 9277d94..2a9d467 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -163,6 +163,41 @@ static int twl_rtc_write_u8(u8 data, u8 reg)
 	return ret;
 }
 
+#define REG_BBSPOR_CFG	0xE6
+#define VRTC_EN_SLP_STS	(1 << 6)
+#define VRTC_EN_OFF_STS	(1 << 5)
+#define VRTC_PWEN	(1 << 4)
+#define BB_CHG_EN	(1 << 3)
+#define BB_SEL_1	(1 << 2)
+#define BB_SEL_0	(1 << 1)
+
+static int enable_rtc_battery_charging(void)
+{
+	int ret;
+	u8 data;
+
+	ret = twl_i2c_read_u8(TWL6030_MODULE_ID1, &data, REG_BBSPOR_CFG);
+	if (ret < 0) {
+		pr_err("twl_rtc: read bbspor_cfg failed: %d\n", ret);
+		return ret;
+	}
+
+	/* 
+	 * Charge battery to 3.0v 
+	 * TWL6030 Register Map, Table 224, BBSPOR_CFG Register 
+	 */
+	data &= ~(BB_SEL_1 | BB_SEL_0);
+	data |= BB_CHG_EN;
+
+	ret = twl_i2c_write_u8(TWL6030_MODULE_ID1, data, REG_BBSPOR_CFG);
+	if (ret < 0)
+		pr_err("twl_rtc: write bbspor_cfg failed: %d\n", ret);
+	else
+		pr_info("twl_rtc: enabled rtc battery charging\n");
+
+	return ret;
+}	
+
 /*
  * Cache the value for timer/alarm interrupts register; this is
  * only changed by callers holding rtc ops lock (or resume).
@@ -505,6 +540,10 @@ static int __devinit twl_rtc_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto out1;
 
+	ret = enable_rtc_battery_charging();
+	if (ret < 0)
+		dev_err(&pdev->dev, "Failed to enable rtc battery charging)\n");
+
 	rtc = rtc_device_register(pdev->name,
 				  &pdev->dev, &twl_rtc_ops, THIS_MODULE);<commit_msg>kernel: Fix RTC charging patch<commit_after>From 6f8787b48256814a7acea71029c50cdbb08cf953 Mon Sep 17 00:00:00 2001
From: <NAME> <<EMAIL>>
Date: Tue, 11 Feb 2014 18:04:40 -0500
Subject: [PATCH] Enable RTC backup battery charging

---
 drivers/rtc/rtc-twl.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index 9277d94..2a9d467 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -163,6 +163,41 @@ static int twl_rtc_write_u8(u8 data, u8 reg)
 	return ret;
 }
 
+#define REG_BBSPOR_CFG	0xE6
+#define VRTC_EN_SLP_STS	(1 << 6)
+#define VRTC_EN_OFF_STS	(1 << 5)
+#define VRTC_PWEN	(1 << 4)
+#define BB_CHG_EN	(1 << 3)
+#define BB_SEL_1	(1 << 2)
+#define BB_SEL_0	(1 << 1)
+
+static int enable_rtc_battery_charging(void)
+{
+	int ret;
+	u8 data;
+
+	ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, &data, REG_BBSPOR_CFG);
+	if (ret < 0) {
+		pr_err("twl_rtc: read bbspor_cfg failed: %d\n", ret);
+		return ret;
+	}
+
+	/* 
+	 * Charge battery to 3.0v 
+	 * TWL6030 Register Map, Table 224, BBSPOR_CFG Register 
+	 */
+	data &= ~(BB_SEL_1 | BB_SEL_0);
+	data |= BB_CHG_EN;
+
+	ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, data, REG_BBSPOR_CFG);
+	if (ret < 0)
+		pr_err("twl_rtc: write bbspor_cfg failed: %d\n", ret);
+	else
+		pr_info("twl_rtc: enabled rtc battery charging\n");
+
+	return ret;
+}	
+
 /*
  * Cache the value for timer/alarm interrupts register; this is
  * only changed by callers holding rtc ops lock (or resume).
@@ -505,6 +540,10 @@ static int __devinit twl_rtc_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto out1;
 
+	ret = enable_rtc_battery_charging();
+	if (ret < 0)
+		dev_err(&pdev->dev, "Failed to enable rtc battery charging)\n");
+
 	rtc = rtc_device_register(pdev->name,
 				  &pdev->dev, &twl_rtc_ops, THIS_MODULE);
{'fraction_non_alphanumeric': 0.1706919945725916, 'fraction_numerical': 0.07815468113975577, 'mean_word_length': 4.334298118668596, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6544858', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1633, 'n_words': 373}