From: Frederic Danis <frederic.danis@linux.intel.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2 4/4] Bluetooth: hci_bcm: Add suspend/resume PM functions
Date: Fri, 7 Aug 2015 17:00:40 +0200 [thread overview]
Message-ID: <1438959640-15476-5-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1438959640-15476-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 8e1eacd..8d8f21c 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 {
@@ -152,6 +155,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;
}
}
@@ -169,8 +173,10 @@ static int bcm_close(struct hci_uart *hu)
BT_DBG("hu %p", hu);
- if (bcm->dev)
+ if (bcm->dev) {
bcm_gpio_set_power(bcm->dev, false);
+ bcm->dev->hu = NULL;
+ }
skb_queue_purge(&bcm->txq);
kfree_skb(bcm->rx_skb);
@@ -296,6 +302,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 };
@@ -450,12 +503,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
next prev parent reply other threads:[~2015-08-07 15:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-07 15:00 [PATCH v2 0/4] Bluetooth: hci_bcm: Add ACPI and PM support Frederic Danis
2015-08-07 15:00 ` [PATCH v2 1/4] Bluetooth: hci_bcm: Add PM for BCM devices Frederic Danis
2015-08-07 16:41 ` Marcel Holtmann
2015-08-10 15:59 ` Frederic Danis
2015-08-10 8:00 ` Luka Karinja
2015-08-10 14:57 ` Frederic Danis
2015-08-23 10:44 ` Luka Karinja
2015-09-04 14:08 ` Frederic Danis
2015-08-07 15:00 ` [PATCH v2 2/4] net: rfkill: gpio: Make BCM2E39 support optional Frederic Danis
2015-08-07 16:42 ` Marcel Holtmann
2015-08-07 15:00 ` [PATCH v2 3/4] Bluetooth: hci_bcm: Retrieve UART speed from ACPI Frederic Danis
2015-08-07 15:00 ` Frederic Danis [this message]
2015-08-07 16:45 ` [PATCH v2 0/4] Bluetooth: hci_bcm: Add ACPI and PM support Marcel Holtmann
2015-08-10 15:50 ` Frederic Danis
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=1438959640-15476-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).