From patchwork Wed Apr 5 18:30:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 96900 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp390208qgd; Wed, 5 Apr 2017 11:30:23 -0700 (PDT) X-Received: by 10.36.218.5 with SMTP id z5mr22121849itg.79.1491417023229; Wed, 05 Apr 2017 11:30:23 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v63si7935035itb.110.2017.04.05.11.30.23; Wed, 05 Apr 2017 11:30:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933869AbdDESaV (ORCPT + 6 others); Wed, 5 Apr 2017 14:30:21 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:36389 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933630AbdDESaJ (ORCPT ); Wed, 5 Apr 2017 14:30:09 -0400 Received: by mail-oi0-f67.google.com with SMTP id b187so3415331oif.3; Wed, 05 Apr 2017 11:30:09 -0700 (PDT) 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=0zvJtolDZYHUiDbn2uZSdLRJPkqTnumwzr07eU0pk1o=; b=Ak1oKvs6p21aUiEebLTI268s+iCllwae4JJ216kbDhP9CBEV3evpn3WPsbLHCKjrW6 SpBv6s/WbW6D3YCeZOF523Cg15yYUwjdJ3LhUghpNH+H3/gn4UG8F5zKW1eYYH0NrdSK HHvYvi0KsoIAQnq4OPymBdZK24IBGgQLF0wVUYA4T5BRuK2zY08hoygjvtje3b/0yeCp at2TWbXD6Viw2ipUeuarzJ6ngSYY+mrkGWCrUVhEP6cbNvHiFIoepMA8JpdJtmxDwakA i+aTKBwbHl27/KOGHsNhcawQfsQ5GO3ZbF+1hDPD7gsYjR+VM7QYo3i+V9T1bnW53Q3h QmWw== X-Gm-Message-State: AFeK/H3AI+Kl/+uSkWCV60ZAnPxQyNzXGEKhHcOEm6xQ0S4BMm1r6oycE+ZQ898DeRP/Ww== X-Received: by 10.157.17.234 with SMTP id y39mr3692742oty.194.1491417008698; Wed, 05 Apr 2017 11:30:08 -0700 (PDT) Received: from rob-hp-laptop.herring.priv (66-90-148-125.dyn.grandenetworks.net. [66.90.148.125]) by smtp.googlemail.com with ESMTPSA id o76sm5334458ota.17.2017.04.05.11.30.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 11:30:08 -0700 (PDT) From: Rob Herring To: Marcel Holtmann , linux-bluetooth@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Gustavo Padovan , Johan Hedberg , Mark Rutland , Wei Xu , Eyal Reizer , Satish Patel , netdev@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 1/4] dt-bindings: net: Add TI WiLink shared transport binding Date: Wed, 5 Apr 2017 13:30:02 -0500 Message-Id: <20170405183005.20570-2-robh@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170405183005.20570-1-robh@kernel.org> References: <20170405183005.20570-1-robh@kernel.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add serial slave device binding for the TI WiLink series of Bluetooth/FM/GPS devices. Signed-off-by: Rob Herring Cc: Mark Rutland Cc: netdev@vger.kernel.org Cc: devicetree@vger.kernel.org --- .../devicetree/bindings/net/ti,wilink-st.txt | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/ti,wilink-st.txt -- 2.10.1 diff --git a/Documentation/devicetree/bindings/net/ti,wilink-st.txt b/Documentation/devicetree/bindings/net/ti,wilink-st.txt new file mode 100644 index 000000000000..cbad73a84ac4 --- /dev/null +++ b/Documentation/devicetree/bindings/net/ti,wilink-st.txt @@ -0,0 +1,35 @@ +TI WiLink 7/8 (wl12xx/wl18xx) Shared Transport BT/FM/GPS devices + +TI WiLink devices have a UART interface for providing Bluetooth, FM radio, +and GPS over what's called "shared transport". The shared transport is +standard BT HCI protocol with additional channels for the other functions. + +These devices also have a separate WiFi interface as described in +wireless/ti,wlcore.txt. + +This bindings follows the UART slave device binding in +../serial/slave-device.txt. + +Required properties: + - compatible: should be one of the following: + "ti,wl1271-st" + "ti,wl1273-st" + "ti,wl1831-st" + "ti,wl1835-st" + "ti,wl1837-st" + +Optional properties: + - enable-gpios : GPIO signal controlling enabling of BT. Active high. + - vio-supply : Vio input supply (1.8V) + - vbat-supply : Vbat input supply (2.9-4.8V) + +Example: + +&serial0 { + compatible = "ns16550a"; + ... + bluetooth { + compatible = "ti,wl1835-st"; + enable-gpios = <&gpio1 7 GPIO_ACTIVE_HIGH>; + }; +}; From patchwork Wed Apr 5 18:30:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 96899 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp390177qgd; Wed, 5 Apr 2017 11:30:20 -0700 (PDT) X-Received: by 10.36.19.206 with SMTP id 197mr23060047itz.23.1491417020460; Wed, 05 Apr 2017 11:30:20 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v63si7935035itb.110.2017.04.05.11.30.20; Wed, 05 Apr 2017 11:30:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933816AbdDESaS (ORCPT + 6 others); Wed, 5 Apr 2017 14:30:18 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:35291 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932546AbdDESaK (ORCPT ); Wed, 5 Apr 2017 14:30:10 -0400 Received: by mail-oi0-f68.google.com with SMTP id d2so3415275oig.2; Wed, 05 Apr 2017 11:30:10 -0700 (PDT) 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=lyRw9s410Lkg0W51l6fQB/9lPKAaneulWHI/pbEI63w=; b=nmhfCvjWe6ky4kmySO0Y4Rtz1XtJXcJ0R4iPs7lJQYuKMtKoDsqh7odlh9ZYr+2geo E4lY+VR4Lzw+Tda1Uc8O07zdOMTU3KlG95sNh5AlRLcQ+m765KSCk49jgsoaRZoVroAN pkd2VV8IcDlCNAYGj8FNqQKCZrW9+im9HtEJjkYAkgaLySNbRt0hcNizR1wk+0DwAFBe DB+LdgCqIBsB/GCkFdk6LwG1TqGonANqVBwD5RAPmhZyZff2gSf2b9cm7zh2b56p1Np0 baITFbG2a2GjmTPosQJke859sUoao+WBJJ01N7moUvdTZ+Ww6TnVlChOSAT+gJLYtv3y EJfw== X-Gm-Message-State: AFeK/H0odbQMD0PcX/DWjjHNEIHOhya8sWKOSCgyDacPc9vevpkWfi3H1RvQ7lIhzCP/ZA== X-Received: by 10.157.9.179 with SMTP id q48mr4860475otd.128.1491417009837; Wed, 05 Apr 2017 11:30:09 -0700 (PDT) Received: from rob-hp-laptop.herring.priv (66-90-148-125.dyn.grandenetworks.net. [66.90.148.125]) by smtp.googlemail.com with ESMTPSA id o76sm5334458ota.17.2017.04.05.11.30.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 11:30:09 -0700 (PDT) From: Rob Herring To: Marcel Holtmann , linux-bluetooth@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Gustavo Padovan , Johan Hedberg , Mark Rutland , Wei Xu , Eyal Reizer , Satish Patel , netdev@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 2/4] bluetooth: hci_uart: remove unused hci_uart_init_tty Date: Wed, 5 Apr 2017 13:30:03 -0500 Message-Id: <20170405183005.20570-3-robh@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170405183005.20570-1-robh@kernel.org> References: <20170405183005.20570-1-robh@kernel.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There are no users of hci_uart_init_tty, so remove it. Signed-off-by: Rob Herring Cc: Marcel Holtmann Cc: Gustavo Padovan Cc: Johan Hedberg Cc: linux-bluetooth@vger.kernel.org --- drivers/bluetooth/hci_ldisc.c | 19 ------------------- drivers/bluetooth/hci_uart.h | 1 - 2 files changed, 20 deletions(-) -- 2.10.1 diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index 17bcbc13623f..cec4438ede01 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c @@ -319,25 +319,6 @@ void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed, hu->oper_speed = oper_speed; } -void hci_uart_init_tty(struct hci_uart *hu) -{ - struct tty_struct *tty = hu->tty; - struct ktermios ktermios; - - /* Bring the UART into a known 8 bits no parity hw fc state */ - ktermios = tty->termios; - ktermios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | - INLCR | IGNCR | ICRNL | IXON); - ktermios.c_oflag &= ~OPOST; - ktermios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); - ktermios.c_cflag &= ~(CSIZE | PARENB); - ktermios.c_cflag |= CS8; - ktermios.c_cflag |= CRTSCTS; - - /* tty_set_termios() return not checked as it is always 0 */ - tty_set_termios(tty, &ktermios); -} - void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed) { struct tty_struct *tty = hu->tty; diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h index 1b41c661bbb8..2b05e557fad0 100644 --- a/drivers/bluetooth/hci_uart.h +++ b/drivers/bluetooth/hci_uart.h @@ -114,7 +114,6 @@ int hci_uart_register_device(struct hci_uart *hu, const struct hci_uart_proto *p int hci_uart_tx_wakeup(struct hci_uart *hu); int hci_uart_init_ready(struct hci_uart *hu); -void hci_uart_init_tty(struct hci_uart *hu); void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed); void hci_uart_set_flow_control(struct hci_uart *hu, bool enable); void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed, From patchwork Wed Apr 5 18:30:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 96902 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp390321qgd; Wed, 5 Apr 2017 11:30:37 -0700 (PDT) X-Received: by 10.107.133.159 with SMTP id p31mr29901347ioi.101.1491417037111; Wed, 05 Apr 2017 11:30:37 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v63si7935035itb.110.2017.04.05.11.30.36; Wed, 05 Apr 2017 11:30:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933891AbdDESaf (ORCPT + 6 others); Wed, 5 Apr 2017 14:30:35 -0400 Received: from mail-oi0-f66.google.com ([209.85.218.66]:33142 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933676AbdDESaM (ORCPT ); Wed, 5 Apr 2017 14:30:12 -0400 Received: by mail-oi0-f66.google.com with SMTP id f193so3418987oib.0; Wed, 05 Apr 2017 11:30:11 -0700 (PDT) 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=B8Yn+wuaNxHNQhQ4JuEC+c7mXRdTG/OhSJ84MBh2Hts=; b=lCJY+cHn7uLv62rSzNgoxJnIaPpJVk+Ykp1BGHz+XYEVNq2H6vzwNvfOTXfJrzPSmP x2/itzJfRz2QypXC6uf6KaC2FWBiReU0XRPFh7dRgwV6sbjgs3YC2zJk21LlbBR2Kmnr k/s4/W2grzXem2WbBgpOeP9oSLQaMGzUX8GX/9COsdITpX+co++iwsxKAOg2wInmEDMJ g4eWbtKWl4Rx+Ynb2y2D8/+mzBD+WGpwrUehecDjaUx6w/s9FWiblnvd5NBPUnxdDtjY ofLhJNMivBa+pObqGqio7NBQyFPYNuTEhnPwzm1Q2anM5kfSwzm6SXyjZz9WhI21BBTC f1UQ== X-Gm-Message-State: AFeK/H2HwMpfo2KPeja4sqwjP/G29tFyAhE6+lkDEnz/WqL5b8RSpVj3hD/tuG6iLVXW6w== X-Received: by 10.157.12.151 with SMTP id b23mr14773828otb.94.1491417010987; Wed, 05 Apr 2017 11:30:10 -0700 (PDT) Received: from rob-hp-laptop.herring.priv (66-90-148-125.dyn.grandenetworks.net. [66.90.148.125]) by smtp.googlemail.com with ESMTPSA id o76sm5334458ota.17.2017.04.05.11.30.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 11:30:10 -0700 (PDT) From: Rob Herring To: Marcel Holtmann , linux-bluetooth@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Gustavo Padovan , Johan Hedberg , Mark Rutland , Wei Xu , Eyal Reizer , Satish Patel , netdev@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH 3/4] bluetooth: hci_uart: add LL protocol serdev driver support Date: Wed, 5 Apr 2017 13:30:04 -0500 Message-Id: <20170405183005.20570-4-robh@kernel.org> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170405183005.20570-1-robh@kernel.org> References: <20170405183005.20570-1-robh@kernel.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Turns out that the LL protocol and the TI-ST are the same thing AFAICT. The TI-ST adds firmware loading, GPIO control, and shared access for NFC, FM radio, etc. For now, we're only implementing what is needed for BT. This mirrors other drivers like BCM and Intel, but uses the new serdev bus. The firmware loading is greatly simplified by using existing infrastructure to send commands. It may be a bit slower than the original code using synchronous functions, but the real bottleneck is likely doing firmware load at 115.2kbps. Signed-off-by: Rob Herring Cc: Marcel Holtmann Cc: Gustavo Padovan Cc: Johan Hedberg Cc: linux-bluetooth@vger.kernel.org --- drivers/bluetooth/hci_ll.c | 261 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 260 insertions(+), 1 deletion(-) -- 2.10.1 diff --git a/drivers/bluetooth/hci_ll.c b/drivers/bluetooth/hci_ll.c index 02692fe30279..9b2054f5502d 100644 --- a/drivers/bluetooth/hci_ll.c +++ b/drivers/bluetooth/hci_ll.c @@ -34,20 +34,23 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include #include +#include #include +#include #include #include +#include #include "hci_uart.h" @@ -76,6 +79,12 @@ struct hcill_cmd { u8 cmd; } __packed; +struct ll_device { + struct hci_uart hu; + struct serdev_device *serdev; + struct gpio_desc *enable_gpio; +}; + struct ll_struct { unsigned long rx_state; unsigned long rx_count; @@ -136,6 +145,9 @@ static int ll_open(struct hci_uart *hu) hu->priv = ll; + if (hu->serdev) + serdev_device_open(hu->serdev); + return 0; } @@ -164,6 +176,13 @@ static int ll_close(struct hci_uart *hu) kfree_skb(ll->rx_skb); + if (hu->serdev) { + struct ll_device *lldev = serdev_device_get_drvdata(hu->serdev); + gpiod_set_value_cansleep(lldev->enable_gpio, 0); + + serdev_device_close(hu->serdev); + } + hu->priv = NULL; kfree(ll); @@ -505,9 +524,245 @@ static struct sk_buff *ll_dequeue(struct hci_uart *hu) return skb_dequeue(&ll->txq); } +#ifdef CONFIG_SERIAL_DEV_BUS +static int read_local_version(struct hci_dev *hdev) +{ + int err = 0; + unsigned short version = 0; + struct sk_buff *skb; + struct hci_rp_read_local_version *ver; + + skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL, HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) { + bt_dev_err(hdev, "Reading TI version information failed (%ld)", + PTR_ERR(skb)); + err = PTR_ERR(skb); + goto out; + } + if (skb->len != sizeof(*ver)) { + err = -EILSEQ; + goto out; + } + + ver = (struct hci_rp_read_local_version *)skb->data; + if (le16_to_cpu(ver->manufacturer) != 13) { + err = -ENODEV; + goto out; + } + + version = le16_to_cpu(ver->lmp_subver); + +out: + if (err) bt_dev_err(hdev, "Failed to read TI version info: %d", err); + kfree_skb(skb); + return err ? err : version; +} + +/** + * download_firmware - + * internal function which parses through the .bts firmware + * script file intreprets SEND, DELAY actions only as of now + */ +static int download_firmware(struct ll_device *lldev) +{ + unsigned short chip, min_ver, maj_ver; + int version, err, len; + unsigned char *ptr, *action_ptr; + unsigned char bts_scr_name[40]; /* 40 char long bts scr name? */ + const struct firmware *fw; + struct sk_buff *skb; + struct hci_command *cmd; + + version = read_local_version(lldev->hu.hdev); + if (version < 0) + return version; + + chip = (version & 0x7C00) >> 10; + min_ver = (version & 0x007F); + maj_ver = (version & 0x0380) >> 7; + if (version & 0x8000) + maj_ver |= 0x0008; + + snprintf(bts_scr_name, sizeof(bts_scr_name), + "ti-connectivity/TIInit_%d.%d.%d.bts", + chip, maj_ver, min_ver); + + err = request_firmware(&fw, bts_scr_name, &lldev->serdev->dev); + if (err || !fw->data || !fw->size) { + bt_dev_err(lldev->hu.hdev, "request_firmware failed(errno %d) for %s", + err, bts_scr_name); + return -EINVAL; + } + ptr = (void *)fw->data; + len = fw->size; + /* bts_header to remove out magic number and + * version + */ + ptr += sizeof(struct bts_header); + len -= sizeof(struct bts_header); + + while (len > 0 && ptr) { + bt_dev_dbg(lldev->hu.hdev, " action size %d, type %d ", + ((struct bts_action *)ptr)->size, + ((struct bts_action *)ptr)->type); + + action_ptr = &(((struct bts_action *)ptr)->data[0]); + + switch (((struct bts_action *)ptr)->type) { + case ACTION_SEND_COMMAND: /* action send */ + bt_dev_dbg(lldev->hu.hdev, "S"); + cmd = (struct hci_command *)action_ptr; + if (cmd->opcode == 0xff36) { + /* ignore remote change + * baud rate HCI VS command */ + bt_dev_warn(lldev->hu.hdev, "change remote baud rate command in firmware"); + break; + } + if (cmd->prefix != 1) + bt_dev_dbg(lldev->hu.hdev, "command type %d\n", cmd->prefix); + + skb = __hci_cmd_sync(lldev->hu.hdev, cmd->opcode, cmd->plen, &cmd->speed, HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) { + bt_dev_err(lldev->hu.hdev, "send command failed\n"); + goto out_rel_fw; + } + kfree_skb(skb); + break; + case ACTION_WAIT_EVENT: /* wait */ + /* no need to wait as command was synchronous */ + bt_dev_dbg(lldev->hu.hdev, "W"); + break; + case ACTION_DELAY: /* sleep */ + bt_dev_info(lldev->hu.hdev, "sleep command in scr"); + mdelay(((struct bts_action_delay *)action_ptr)->msec); + break; + } + len -= (sizeof(struct bts_action) + + ((struct bts_action *)ptr)->size); + ptr += sizeof(struct bts_action) + + ((struct bts_action *)ptr)->size; + } + +out_rel_fw: + /* fw download complete */ + release_firmware(fw); + return err; +} + +static int ll_setup(struct hci_uart *hu) +{ + int err, retry = 3; + struct ll_device *lldev; + struct serdev_device *serdev = hu->serdev; + u32 speed; + + if (!serdev) + return 0; + + lldev = serdev_device_get_drvdata(serdev); + + serdev_device_set_flow_control(serdev, true); + + do { + /* Configure BT_EN to HIGH state */ + gpiod_set_value_cansleep(lldev->enable_gpio, 0); + msleep(5); + gpiod_set_value_cansleep(lldev->enable_gpio, 1); + msleep(100); + + err = download_firmware(lldev); + if (!err) + break; + + /* Toggle BT_EN and retry */ + bt_dev_err(hu->hdev, "download firmware failed, retrying..."); + } while (retry--); + + if (err) + return err; + + /* Operational speed if any */ + if (hu->oper_speed) + speed = hu->oper_speed; + else if (hu->proto->oper_speed) + speed = hu->proto->oper_speed; + else + speed = 0; + + if (speed) { + struct sk_buff *skb = __hci_cmd_sync(hu->hdev, 0xff36, sizeof(speed), &speed, HCI_INIT_TIMEOUT); + if (!IS_ERR(skb)) { + kfree_skb(skb); + serdev_device_set_baudrate(serdev, speed); + } + } + + return 0; +} + +static const struct hci_uart_proto llp; + +static int hci_ti_probe(struct serdev_device *serdev) +{ + struct hci_uart *hu; + struct ll_device *lldev; + u32 max_speed = 3000000; + + lldev = devm_kzalloc(&serdev->dev, sizeof(struct ll_device), GFP_KERNEL); + if (!lldev) + return -ENOMEM; + hu = &lldev->hu; + + serdev_device_set_drvdata(serdev, lldev); + lldev->serdev = hu->serdev = serdev; + + lldev->enable_gpio = devm_gpiod_get_optional(&serdev->dev, "enable", GPIOD_OUT_LOW); + if (IS_ERR(lldev->enable_gpio)) + return PTR_ERR(lldev->enable_gpio); + + of_property_read_u32(serdev->dev.of_node, "max-speed", &max_speed); + hci_uart_set_speeds(hu, 115200, max_speed); + + return hci_uart_register_device(hu, &llp); +} + +static void hci_ti_remove(struct serdev_device *serdev) +{ + struct ll_device *lldev = serdev_device_get_drvdata(serdev); + struct hci_uart *hu = &lldev->hu; + struct hci_dev *hdev = hu->hdev; + + cancel_work_sync(&hu->write_work); + + hci_unregister_dev(hdev); + hci_free_dev(hdev); + hu->proto->close(hu); +} + +static const struct of_device_id hci_ti_of_match[] = { + { .compatible = "ti,wl1831-st" }, + { .compatible = "ti,wl1835-st" }, + { .compatible = "ti,wl1837-st" }, + {}, +}; +MODULE_DEVICE_TABLE(of, hci_ti_of_match); + +static struct serdev_device_driver hci_ti_drv = { + .driver = { + .name = "hci-ti", + .of_match_table = of_match_ptr(hci_ti_of_match), + }, + .probe = hci_ti_probe, + .remove = hci_ti_remove, +}; +#else +#define ll_setup NULL +#endif + static const struct hci_uart_proto llp = { .id = HCI_UART_LL, .name = "LL", + .setup = ll_setup, .open = ll_open, .close = ll_close, .recv = ll_recv, @@ -518,10 +773,14 @@ static const struct hci_uart_proto llp = { int __init ll_init(void) { + serdev_device_driver_register(&hci_ti_drv); + return hci_uart_register_proto(&llp); } int __exit ll_deinit(void) { + serdev_device_driver_unregister(&hci_ti_drv); + return hci_uart_unregister_proto(&llp); }