From 6f63c3f006dff555de5089cf875d52bd4053dfcc Mon Sep 17 00:00:00 2001
From: Devin Kim <dojip.kim@lge.com>
Date: Mon, 14 Jul 2014 15:44:56 -0700
Subject: [PATCH] bluesleep: Read the tx_timer_interval from device tree

TX timer wakelock needs to be configurable. If the timer interval
is defined, the driver will use the value instead of default value.

Change-Id: I9894350bc9a323535010a1c620b5e4fde0726cc6
Signed-off-by: Devin Kim <dojip.kim@lge.com>
---
 drivers/bluetooth/bluesleep.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/bluetooth/bluesleep.c b/drivers/bluetooth/bluesleep.c
index f8bdcf0a62e1..76244f83e44e 100644
--- a/drivers/bluetooth/bluesleep.c
+++ b/drivers/bluetooth/bluesleep.c
@@ -94,6 +94,7 @@ struct bluesleep_info {
 	struct wake_lock wake_lock;
 	int irq_polarity;
 	int has_ext_wake;
+	int tx_timer_interval;
 };
 
 /* work function */
@@ -186,7 +187,7 @@ void bluesleep_sleep_wakeup(void)
 		wake_lock(&bsi->wake_lock);
 
 		/* Start the timer */
-		mod_timer(&tx_timer, jiffies + (TX_TIMER_INTERVAL * HZ));
+		mod_timer(&tx_timer, jiffies + (bsi->tx_timer_interval * HZ));
 
 		if (debug_mask & DEBUG_BTWAKE)
 			pr_info("BT WAKE: set to wake\n");
@@ -230,12 +231,14 @@ static void bluesleep_sleep_work(struct work_struct *work)
 			 */
 			wake_lock_timeout(&bsi->wake_lock, HZ / 8);
 		} else {
-			mod_timer(&tx_timer, jiffies + (TX_TIMER_INTERVAL * HZ));
+			mod_timer(&tx_timer, jiffies +
+					(bsi->tx_timer_interval * HZ));
 			return;
 		}
 	} else if (test_bit(BT_EXT_WAKE, &flags)
 		   && !test_bit(BT_ASLEEP, &flags)) {
-		mod_timer(&tx_timer, jiffies + (TX_TIMER_INTERVAL * HZ));
+		mod_timer(&tx_timer, jiffies +
+				(bsi->tx_timer_interval * HZ));
 
 		if (debug_mask & DEBUG_BTWAKE)
 			pr_info("BT WAKE: set to wake\n");
@@ -320,7 +323,8 @@ static void bluesleep_tx_timer_expire(unsigned long data)
 	} else {
 		if (debug_mask & DEBUG_SUSPEND)
 			pr_info("Tx data during last period\n");
-		mod_timer(&tx_timer, jiffies + (TX_TIMER_INTERVAL * HZ));
+		mod_timer(&tx_timer, jiffies +
+				(bsi->tx_timer_interval * HZ));
 	}
 
 	/* clear the incoming data flag */
@@ -367,7 +371,8 @@ static int bluesleep_start(void)
 	}
 
 	/* start the timer */
-	mod_timer(&tx_timer, jiffies + (TX_TIMER_INTERVAL * HZ));
+	mod_timer(&tx_timer, jiffies +
+			(bsi->tx_timer_interval * HZ));
 
 	/* assert BT_WAKE */
 	if (debug_mask & DEBUG_BTWAKE)
@@ -487,6 +492,10 @@ static int bluesleep_populate_dt_pinfo(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
 	int tmp;
+	u32 val;
+
+	if (!of_property_read_u32(np, "tx-timer-interval", &val))
+		bsi->tx_timer_interval = val;
 
 	tmp = of_get_named_gpio(np, "host-wake-gpio", 0);
 	if (tmp < 0) {
@@ -557,6 +566,9 @@ static int bluesleep_probe(struct platform_device *pdev)
 		}
 	}
 
+	if (!bsi->tx_timer_interval)
+		bsi->tx_timer_interval = TX_TIMER_INTERVAL;
+
 	/* configure host_wake as input */
 	ret = gpio_request_one(bsi->host_wake, GPIOF_IN, "bt_host_wake");
 	if (ret < 0) {
-- 
GitLab