From patchwork Wed Dec 14 19:12:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 705775 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3tf5pr2BnTz9t0G for ; Thu, 15 Dec 2016 06:14:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="V8BYX1Y9"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756419AbcLNTOH (ORCPT ); Wed, 14 Dec 2016 14:14:07 -0500 Received: from mail-pg0-f52.google.com ([74.125.83.52]:35980 "EHLO mail-pg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756183AbcLNTNT (ORCPT ); Wed, 14 Dec 2016 14:13:19 -0500 Received: by mail-pg0-f52.google.com with SMTP id f188so10892412pgc.3 for ; Wed, 14 Dec 2016 11:13:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SvD8EOQY+2gXi5LHNJaeSSshkm7SBp3C0W5Fxpo5Ues=; b=V8BYX1Y9x80BMB3Gk8pGzjKv1K/wJCjA3OEr0eVQwtiiufqa/TviCdUQN9TkhbfWtj JUxjzuiBJ/xE9Q1+SV/w5FAsEmVuMJBM6ZW45hD+aqUwnq2TSuwZlv4k/rae5eZiesHF x0pyFjT9wwnzhLyE7t2gevCsSm/Vyn6hs68VZVz9lOXgmug/sbaB3RLVcPCqUt0ccMjf 0clD2U0Q+cqIk/YluQf2erozlIYdkfnXryNYmu/xHlglocmJ1JSMRXZr3TeKmfT3SgR2 O6+KHHSGEi614mzOZp/gnYT7OgE1wMB8d0Y4IzgK/tV3iFtbNNTFSaZcKihfKJRVYJ70 Pqww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SvD8EOQY+2gXi5LHNJaeSSshkm7SBp3C0W5Fxpo5Ues=; b=jMnkossxP0qsRU+l52nvZXPpHpGIw6oxD6cabTF8arrG2s7d0ONx7bs8P8dheefQNU xJ/g7PHmkjNYMDReRQP8xIeDM/2CXQM/MneMeFR6HWSUIKGIJtN4ldYRHzMmJHY+fLgZ Lj8YX6Xx42svvuTQyJaDdLXj0kyDitegCT7zf421G64K/K3KSfRRbB0T0dZStWxf7VNe CVS5KyyO9JrLEAcl1z+2vaqrPX2t5i33c3zYn13VB6Rg/LsGsJhqGGth7kWwom18ikT5 UK5+T4cHCMD2+g7uIWfEICmNe6Hi8D3b0A2Br33cgdamY4pPdLYTRgRiio96BkUwT3Rk WBdw== X-Gm-Message-State: AKaTC01TxbtVkWeGHFMnuiB9t7CvINXx2jJyhEVOHiPDmObbFFDr7yRNeGFstTDcMajS7MCT X-Received: by 10.99.95.86 with SMTP id t83mr188713833pgb.0.1481742797897; Wed, 14 Dec 2016 11:13:17 -0800 (PST) Received: from rajat.mtv.corp.google.com ([172.22.64.13]) by smtp.gmail.com with ESMTPSA id b12sm88983901pfb.78.2016.12.14.11.13.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Dec 2016 11:13:17 -0800 (PST) From: Rajat Jain To: Rob Herring , Mark Rutland , Marcel Holtmann , Gustavo Padovan , Johan Hedberg , Amitkumar Karwar , Wei-Ning Huang , Xinming Hu , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-bluetooth@vger.kernel.org, Brian Norris Cc: Rajat Jain , rajatxjain@gmail.com Subject: [PATCH 2/3] Bluetooth: btusb: Add out-of-band wakeup support Date: Wed, 14 Dec 2016 11:12:58 -0800 Message-Id: <1481742779-15105-2-git-send-email-rajatja@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1481742779-15105-1-git-send-email-rajatja@google.com> References: <1481742779-15105-1-git-send-email-rajatja@google.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Some BT chips (e.g. Marvell 8997) contain a wakeup pin that can be connected to a gpio on the CPU side, and can be used to wakeup the host out-of-band. This can be useful in situations where the in-band wakeup is not possible or not preferable (e.g. the in-band wakeup may require the USB host controller to remain active, and hence consuming more system power during system sleep). The oob gpio interrupt to be used for wakeup on the CPU side, is read from the device tree node, (using standard interrupt descriptors). A devcie tree binding document is also added for the driver. Signed-off-by: Rajat Jain --- Documentation/devicetree/bindings/net/btusb.txt | 38 ++++++++++++ drivers/bluetooth/btusb.c | 82 +++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/btusb.txt diff --git a/Documentation/devicetree/bindings/net/btusb.txt b/Documentation/devicetree/bindings/net/btusb.txt new file mode 100644 index 0000000..bb27f92 --- /dev/null +++ b/Documentation/devicetree/bindings/net/btusb.txt @@ -0,0 +1,38 @@ +Generic Bluetooth controller over USB (btusb driver) +--------------------------------------------------- + +Required properties: + + - compatible : should comply with the format "usbVID,PID" specified in + Documentation/devicetree/bindings/usb/usb-device.txt + At the time of writing, the only OF supported devices + (more may be added later) are: + + "usb1286,204e" (Marvell 8997) + +Optional properties: + + - interrupt-parent: phandle of the parent interrupt controller + - interrupts : The first interrupt specified is the interrupt that shall be + used for out-of-band wake-on-bt. Driver will request an irq + based on this interrupt number. During system suspend, the irq + will be enabled so that the bluetooth chip can wakeup host + platform out of band. During system resume, the irq will be + disabled to make sure unnecessary interrupt is not received. + +Example: + +Following example uses irq pin number 3 of gpio0 for out of band wake-on-bt: + +&usb_host1_ehci { + status = "okay"; + #address-cells = <1>; + #size-cells = <0>; + + mvl_bt1: bt@1 { + compatible = "usb1286,204e"; + reg = <1>; + interrupt-parent = <&gpio0>; + interrupts = <3 IRQ_TYPE_LEVEL_LOW>; + }; +}; diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index ce22cef..32a6f22 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include @@ -369,6 +371,7 @@ static const struct usb_device_id blacklist_table[] = { #define BTUSB_BOOTING 9 #define BTUSB_RESET_RESUME 10 #define BTUSB_DIAG_RUNNING 11 +#define BTUSB_OOB_WAKE_DISABLED 12 struct btusb_data { struct hci_dev *hdev; @@ -416,6 +419,8 @@ struct btusb_data { int (*recv_bulk)(struct btusb_data *data, void *buffer, int count); int (*setup_on_usb)(struct hci_dev *hdev); + + int oob_wake_irq; /* irq for out-of-band wake-on-bt */ }; static inline void btusb_free_frags(struct btusb_data *data) @@ -2728,6 +2733,65 @@ static int btusb_bcm_set_diag(struct hci_dev *hdev, bool enable) } #endif +#ifdef CONFIG_PM +static irqreturn_t btusb_oob_wake_handler(int irq, void *priv) +{ + struct btusb_data *data = priv; + + /* Disable only if not already disabled (keep it balanced) */ + if (!test_and_set_bit(BTUSB_OOB_WAKE_DISABLED, &data->flags)) { + disable_irq_wake(irq); + disable_irq_nosync(irq); + } + pm_wakeup_event(&data->udev->dev, 0); + return IRQ_HANDLED; +} + +static const struct of_device_id btusb_match_table[] = { + { .compatible = "usb1286,204e" }, + { } +}; +MODULE_DEVICE_TABLE(of, btusb_match_table); + +/* Use an oob wakeup pin? */ +static int btusb_config_oob_wake(struct hci_dev *hdev) +{ + struct btusb_data *data = hci_get_drvdata(hdev); + struct device *dev = &data->udev->dev; + int irq, ret; + + if (!of_match_device(btusb_match_table, dev)) + return 0; + + /* Move on if no IRQ specified */ + irq = irq_of_parse_and_map(dev->of_node, 0); + if (!irq) { + bt_dev_dbg(hdev, "%s: no oob wake irq in DT", __func__); + return 0; + } + + set_bit(BTUSB_OOB_WAKE_DISABLED, &data->flags); + + ret = devm_request_irq(&hdev->dev, irq, btusb_oob_wake_handler, + IRQF_TRIGGER_LOW, "oob wake-on-bt", data); + if (ret) { + bt_dev_err(hdev, "%s: irq request failed", __func__); + return ret; + } + + ret = device_init_wakeup(dev, true); + if (ret) { + bt_dev_err(hdev, "%s: failed to init_wakeup\n", __func__); + return ret; + } + + data->oob_wake_irq = irq; + disable_irq(irq); + bt_dev_info(hdev, "oob wake-on-bt configured at irq %u\n", irq); + return 0; +} +#endif + static int btusb_probe(struct usb_interface *intf, const struct usb_device_id *id) { @@ -2849,6 +2913,11 @@ static int btusb_probe(struct usb_interface *intf, hdev->send = btusb_send_frame; hdev->notify = btusb_notify; +#ifdef CONFIG_PM + err = btusb_config_oob_wake(hdev); + if (err) + goto out_free_dev; +#endif if (id->driver_info & BTUSB_CW6622) set_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks); @@ -3089,6 +3158,12 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message) btusb_stop_traffic(data); usb_kill_anchored_urbs(&data->tx_anchor); + if (data->oob_wake_irq) { + clear_bit(BTUSB_OOB_WAKE_DISABLED, &data->flags); + enable_irq(data->oob_wake_irq); + enable_irq_wake(data->oob_wake_irq); + } + /* Optionally request a device reset on resume, but only when * wakeups are disabled. If wakeups are enabled we assume the * device will stay powered up throughout suspend. @@ -3126,6 +3201,13 @@ static int btusb_resume(struct usb_interface *intf) if (--data->suspend_count) return 0; + /* Disable only if not already disabled (keep it balanced) */ + if (data->oob_wake_irq && + !test_and_set_bit(BTUSB_OOB_WAKE_DISABLED, &data->flags)) { + disable_irq_wake(data->oob_wake_irq); + disable_irq(data->oob_wake_irq); + } + if (!test_bit(HCI_RUNNING, &hdev->flags)) goto done;