summaryrefslogtreecommitdiff
path: root/drivers/bluetooth/hci_bcm.c
diff options
context:
space:
mode:
authorFrederic Danis <frederic.danis@linux.intel.com>2015-08-11 17:35:38 +0300
committerMarcel Holtmann <marcel@holtmann.org>2015-08-11 22:59:38 +0300
commit118612fb91657f041f47d7a29d09e02a86a62ed7 (patch)
tree7ecb5cdfc7c69a94c77ab36f376a319887ad9b44 /drivers/bluetooth/hci_bcm.c
parentae056908862bf1ec8d56bc365280f3dab7941886 (diff)
downloadlinux-118612fb91657f041f47d7a29d09e02a86a62ed7.tar.xz
Bluetooth: hci_bcm: Add suspend/resume PM functions
Add reference to hci_uart structure to bcm_device. This allows suspend/resume callbacks to manage UART flow control. Signed-off-by: Frederic Danis <frederic.danis@linux.intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'drivers/bluetooth/hci_bcm.c')
-rw-r--r--drivers/bluetooth/hci_bcm.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index 12490ebef234..cb7fe837f7d9 100644
--- a/drivers/bluetooth/hci_bcm.c
+++ b/drivers/bluetooth/hci_bcm.c
@@ -51,6 +51,11 @@ struct bcm_device {
bool clk_enabled;
u32 init_speed;
+
+#ifdef CONFIG_PM_SLEEP
+ struct hci_uart *hu;
+ bool is_suspended; /* suspend/resume flag */
+#endif
};
struct bcm_data {
@@ -170,6 +175,9 @@ static int bcm_open(struct hci_uart *hu)
if (hu->tty->dev->parent == dev->pdev->dev.parent) {
bcm->dev = dev;
hu->init_speed = dev->init_speed;
+#ifdef CONFIG_PM_SLEEP
+ dev->hu = hu;
+#endif
break;
}
}
@@ -190,8 +198,12 @@ static int bcm_close(struct hci_uart *hu)
/* Protect bcm->dev against removal of the device or driver */
spin_lock(&bcm_device_list_lock);
- if (bcm_device_exists(bcm->dev))
+ if (bcm_device_exists(bcm->dev)) {
bcm_gpio_set_power(bcm->dev, false);
+#ifdef CONFIG_PM_SLEEP
+ bcm->dev->hu = NULL;
+#endif
+ }
spin_unlock(&bcm_device_list_lock);
skb_queue_purge(&bcm->txq);
@@ -318,6 +330,55 @@ static struct sk_buff *bcm_dequeue(struct hci_uart *hu)
return skb_dequeue(&bcm->txq);
}
+#ifdef CONFIG_PM_SLEEP
+/* Platform suspend callback */
+static int bcm_suspend(struct device *dev)
+{
+ struct bcm_device *bdev = platform_get_drvdata(to_platform_device(dev));
+
+ BT_DBG("suspend (%p): is_suspended %d", bdev, bdev->is_suspended);
+
+ if (!bdev->is_suspended) {
+ hci_uart_set_flow_control(bdev->hu, true);
+
+ /* Once this callback returns, driver suspends BT via GPIO */
+ bdev->is_suspended = true;
+ }
+
+ /* Suspend the device */
+ if (bdev->device_wakeup) {
+ gpiod_set_value(bdev->device_wakeup, false);
+ BT_DBG("suspend, delaying 15 ms");
+ mdelay(15);
+ }
+
+ return 0;
+}
+
+/* Platform resume callback */
+static int bcm_resume(struct device *dev)
+{
+ struct bcm_device *bdev = platform_get_drvdata(to_platform_device(dev));
+
+ BT_DBG("resume (%p): is_suspended %d", bdev, bdev->is_suspended);
+
+ if (bdev->device_wakeup) {
+ gpiod_set_value(bdev->device_wakeup, true);
+ BT_DBG("resume, delaying 15 ms");
+ mdelay(15);
+ }
+
+ /* When this callback executes, the device has woken up already */
+ if (bdev->is_suspended) {
+ bdev->is_suspended = false;
+
+ hci_uart_set_flow_control(bdev->hu, false);
+ }
+
+ return 0;
+}
+#endif
+
static const struct acpi_gpio_params device_wakeup_gpios = { 0, 0, false };
static const struct acpi_gpio_params shutdown_gpios = { 1, 0, false };
@@ -474,12 +535,16 @@ static const struct acpi_device_id bcm_acpi_match[] = {
MODULE_DEVICE_TABLE(acpi, bcm_acpi_match);
#endif
+/* Platform suspend and resume callbacks */
+static SIMPLE_DEV_PM_OPS(bcm_pm_ops, bcm_suspend, bcm_resume);
+
static struct platform_driver bcm_driver = {
.probe = bcm_probe,
.remove = bcm_remove,
.driver = {
.name = "hci_bcm",
.acpi_match_table = ACPI_PTR(bcm_acpi_match),
+ .pm = &bcm_pm_ops,
},
};