summaryrefslogtreecommitdiff
path: root/drivers/staging/cg2900/bluetooth/cg2900_uart.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/cg2900/bluetooth/cg2900_uart.c')
-rw-r--r--drivers/staging/cg2900/bluetooth/cg2900_uart.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/drivers/staging/cg2900/bluetooth/cg2900_uart.c b/drivers/staging/cg2900/bluetooth/cg2900_uart.c
index 61194e0b25e..07030c024c7 100644
--- a/drivers/staging/cg2900/bluetooth/cg2900_uart.c
+++ b/drivers/staging/cg2900/bluetooth/cg2900_uart.c
@@ -33,6 +33,7 @@
#include <linux/tty.h>
#include <linux/tty_ldisc.h>
#include <linux/types.h>
+#include <linux/wakelock.h>
#include <linux/workqueue.h>
#include <net/bluetooth/bluetooth.h>
#include <net/bluetooth/hci.h>
@@ -272,6 +273,7 @@ struct uart_delayed_work_struct {
* @rx_count: Number of bytes left to receive.
* @rx_skb: SK_buffer to store the received data into.
* @tx_queue: TX queue for sending data to chip.
+ * @rx_skb_lock Spin lock to protect rx_skb.
* @hu: Hci uart structure.
* @wq: UART work queue.
* @baud_rate_state: UART baud rate change state.
@@ -291,6 +293,7 @@ struct uart_delayed_work_struct {
* @chip_dev: Chip device for current UART transport.
* @cts_irq: CTS interrupt for this UART.
* @cts_gpio: CTS GPIO for this UART.
+ * @wake_lock: Wake lock for keeping user space awake (for Android).
* @suspend_blocked: True if suspend operation is blocked in the framework.
* @pm_qos_latency: PM QoS structure.
*/
@@ -299,6 +302,7 @@ struct uart_info {
unsigned long rx_count;
struct sk_buff *rx_skb;
struct sk_buff_head tx_queue;
+ spinlock_t rx_skb_lock;
struct hci_uart *hu;
@@ -320,6 +324,7 @@ struct uart_info {
struct cg2900_chip_dev chip_dev;
int cts_irq;
int cts_gpio;
+ struct wake_lock wake_lock;
bool suspend_blocked;
struct pm_qos_request_list pm_qos_latency;
};
@@ -446,6 +451,10 @@ static irqreturn_t cts_interrupt(int irq, void *dev_id)
disable_irq_wake(irq);
#endif
disable_irq_nosync(irq);
+ if (!uart_info->suspend_blocked) {
+ wake_lock(&uart_info->wake_lock);
+ uart_info->suspend_blocked = true;
+ }
/* Create work and leave IRQ context. */
(void)create_work_item(uart_info, handle_cts_irq);
@@ -606,6 +615,7 @@ static void wake_up_chip(struct uart_info *uart_info)
goto finished;
if (!uart_info->suspend_blocked) {
+ wake_lock(&uart_info->wake_lock);
uart_info->suspend_blocked = true;
pm_qos_update_request(&uart_info->pm_qos_latency,
CG2900_PM_QOS_LATENCY);
@@ -690,7 +700,7 @@ static void set_chip_sleep_mode(struct work_struct *work)
switch (uart_info->sleep_state) {
case CHIP_FALLING_ASLEEP:
if (!is_chip_flow_off(uart_info)) {
- dev_dbg(MAIN_DEV, "Chip flow is on, it's not ready to"
+ dev_dbg(MAIN_DEV, "Chip flow is on, it's not ready to "
"sleep yet\n");
goto schedule_sleep_work;
}
@@ -728,6 +738,7 @@ static void set_chip_sleep_mode(struct work_struct *work)
dev_dbg(MAIN_DEV, "New sleep_state: CHIP_ASLEEP\n");
uart_info->sleep_state = CHIP_ASLEEP;
if (uart_info->suspend_blocked) {
+ wake_unlock(&uart_info->wake_lock);
uart_info->suspend_blocked = false;
pm_qos_update_request(&uart_info->pm_qos_latency,
PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE);
@@ -1380,6 +1391,7 @@ static void uart_set_chip_power(struct cg2900_chip_dev *dev, bool chip_on)
if (chip_on) {
if (!uart_info->suspend_blocked) {
+ wake_lock(&uart_info->wake_lock);
uart_info->suspend_blocked = true;
pm_qos_update_request(&uart_info->pm_qos_latency,
CG2900_PM_QOS_LATENCY);
@@ -1421,6 +1433,7 @@ static void uart_set_chip_power(struct cg2900_chip_dev *dev, bool chip_on)
}
if (uart_info->suspend_blocked) {
+ wake_unlock(&uart_info->wake_lock);
uart_info->suspend_blocked = false;
pm_qos_update_request(&uart_info->pm_qos_latency,
PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE);
@@ -1448,6 +1461,22 @@ static void uart_set_chip_power(struct cg2900_chip_dev *dev, bool chip_on)
* clocks.
*/
(void)hci_uart_set_baudrate(uart_info->hu, ZERO_BAUD_RATE);
+
+ spin_lock_bh(&uart_info->rx_skb_lock);
+ if (uart_info->rx_skb) {
+ /*
+ * Reset the uart_info state so that
+ * next packet can be handled
+ * correctly by driver.
+ */
+ dev_dbg(MAIN_DEV, "Power off in the middle of data receiving?"
+ "Reseting state machine.\n");
+ kfree_skb(uart_info->rx_skb);
+ uart_info->rx_skb = NULL;
+ uart_info->rx_state = W4_PACKET_TYPE;
+ uart_info->rx_count = 0;
+ }
+ spin_unlock_bh(&uart_info->rx_skb_lock);
}
unlock:
@@ -1687,6 +1716,8 @@ static int cg2900_hu_receive(struct hci_uart *hu,
print_hex_dump_bytes(NAME " RX:\t", DUMP_PREFIX_NONE,
data, count);
+ spin_lock_bh(&uart_info->rx_skb_lock);
+
/* Continue while there is data left to handle */
while (count) {
/*
@@ -1792,6 +1823,8 @@ check_h4_header:
spin_lock_bh(&(uart_info->transmission_lock));
uart_info->rx_in_progress = false;
spin_unlock_bh(&(uart_info->transmission_lock));
+
+ spin_unlock_bh(&uart_info->rx_skb_lock);
return 0;
}
@@ -1806,6 +1839,7 @@ check_h4_header:
(void)queue_work(uart_info->wq, &uart_info->restart_sleep_work.work);
+ spin_unlock_bh(&uart_info->rx_skb_lock);
return count;
}
@@ -1866,10 +1900,13 @@ static int cg2900_hu_close(struct hci_uart *hu)
/* Purge any stored sk_buffers */
skb_queue_purge(&uart_info->tx_queue);
+
+ spin_lock_bh(&uart_info->rx_skb_lock);
if (uart_info->rx_skb) {
kfree_skb(uart_info->rx_skb);
uart_info->rx_skb = NULL;
}
+ spin_unlock_bh(&uart_info->rx_skb_lock);
dev_info(MAIN_DEV, "UART closed\n");
err = create_work_item(uart_info, work_hw_deregistered);
@@ -1977,6 +2014,7 @@ static int __devinit cg2900_uart_probe(struct platform_device *pdev)
mutex_init(&(uart_info->sleep_state_lock));
spin_lock_init(&(uart_info->transmission_lock));
+ spin_lock_init(&(uart_info->rx_skb_lock));
uart_info->chip_dev.t_cb.open = uart_open;
uart_info->chip_dev.t_cb.close = uart_close;
@@ -1987,6 +2025,7 @@ static int __devinit cg2900_uart_probe(struct platform_device *pdev)
uart_info->chip_dev.pdev = pdev;
uart_info->chip_dev.dev = &pdev->dev;
uart_info->chip_dev.t_data = uart_info;
+ wake_lock_init(&uart_info->wake_lock, WAKE_LOCK_SUSPEND, NAME);
pm_qos_add_request(&uart_info->pm_qos_latency, PM_QOS_CPU_DMA_LATENCY,
PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE);
@@ -2087,6 +2126,7 @@ static int __devexit cg2900_uart_remove(struct platform_device *pdev)
hci_uart_unregister_proto(uart_info->hu->proto);
pm_qos_remove_request(&uart_info->pm_qos_latency);
+ wake_lock_destroy(&uart_info->wake_lock);
destroy_workqueue(uart_info->wq);
dev_info(MAIN_DEV, "CG2900 UART removed\n");