From: Frederic Danis <frederic.danis@linux.intel.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v4 4/4] Bluetooth: hci_bcm: Add suspend/resume PM functions
Date: Tue, 11 Aug 2015 12:12:13 +0200 [thread overview]
Message-ID: <1439287933-21069-5-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1439287933-21069-1-git-send-email-frederic.danis@linux.intel.com>
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>
---
drivers/bluetooth/hci_bcm.c | 61 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
index 12490eb..11782fa 100644
--- a/drivers/bluetooth/hci_bcm.c
+++ b/drivers/bluetooth/hci_bcm.c
@@ -51,6 +51,9 @@ struct bcm_device {
bool clk_enabled;
u32 init_speed;
+
+ struct hci_uart *hu;
+ bool is_suspended; /* suspend/resume flag */
};
struct bcm_data {
@@ -170,6 +173,7 @@ 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;
+ dev->hu = hu;
break;
}
}
@@ -190,8 +194,10 @@ 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);
+ bcm->dev->hu = NULL;
+ }
spin_unlock(&bcm_device_list_lock);
skb_queue_purge(&bcm->txq);
@@ -318,6 +324,53 @@ static struct sk_buff *bcm_dequeue(struct hci_uart *hu)
return skb_dequeue(&bcm->txq);
}
+/* Platform suspend callback */
+static int bcm_suspend(struct device *pdev)
+{
+ struct bcm_device *dev = platform_get_drvdata(to_platform_device(pdev));
+
+ BT_DBG("suspend (%p): is_suspended %d", dev, dev->is_suspended);
+
+ if (!dev->is_suspended) {
+ hci_uart_set_flow_control(dev->hu, true);
+
+ /* Once this callback returns, driver suspends BT via GPIO */
+ dev->is_suspended = true;
+ }
+
+ /* Suspend the device */
+ if (dev->device_wakeup) {
+ gpiod_set_value(dev->device_wakeup, false);
+ BT_DBG("suspend, delaying 15 ms");
+ mdelay(15);
+ }
+
+ return 0;
+}
+
+/* Platform resume callback */
+static int bcm_resume(struct device *pdev)
+{
+ struct bcm_device *dev = platform_get_drvdata(to_platform_device(pdev));
+
+ BT_DBG("resume (%p): is_suspended %d", dev, dev->is_suspended);
+
+ if (dev->device_wakeup) {
+ gpiod_set_value(dev->device_wakeup, true);
+ BT_DBG("resume, delaying 15 ms");
+ mdelay(15);
+ }
+
+ /* When this callback executes, the device has woken up already */
+ if (dev->is_suspended) {
+ dev->is_suspended = false;
+
+ hci_uart_set_flow_control(dev->hu, false);
+ }
+
+ return 0;
+}
+
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 +527,18 @@ static const struct acpi_device_id bcm_acpi_match[] = {
MODULE_DEVICE_TABLE(acpi, bcm_acpi_match);
#endif
+/* Platform suspend and resume callbacks */
+static const struct dev_pm_ops bcm_pm_ops = {
+ SET_SYSTEM_SLEEP_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,
},
};
--
1.9.1
prev parent reply other threads:[~2015-08-11 10:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-11 10:12 [PATCH v4 0/4] Bluetooth: hci_bcm: Add ACPI and PM support Frederic Danis
2015-08-11 10:12 ` [PATCH v4 1/4] Bluetooth: hci_bcm: Add PM for BCM devices Frederic Danis
2015-08-11 10:12 ` [PATCH v4 2/4] net: rfkill: gpio: Remove BCM2E39 support Frederic Danis
2015-08-11 10:12 ` [PATCH v4 3/4] Bluetooth: hci_bcm: Retrieve UART speed from ACPI Frederic Danis
2015-08-11 10:12 ` Frederic Danis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1439287933-21069-5-git-send-email-frederic.danis@linux.intel.com \
--to=frederic.danis@linux.intel.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.