These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / bluetooth / hci_ldisc.c
index 5c9a73f..96bcec5 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/signal.h>
 #include <linux/ioctl.h>
 #include <linux/skbuff.h>
+#include <linux/firmware.h>
 
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
@@ -207,9 +208,6 @@ static int hci_uart_open(struct hci_dev *hdev)
        BT_DBG("%s %p", hdev->name, hdev);
 
        /* Nothing to do for UART driver */
-
-       set_bit(HCI_RUNNING, &hdev->flags);
-
        return 0;
 }
 
@@ -240,9 +238,6 @@ static int hci_uart_close(struct hci_dev *hdev)
 {
        BT_DBG("hdev %p", hdev);
 
-       if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
-               return 0;
-
        hci_uart_flush(hdev);
        hdev->flush = NULL;
        return 0;
@@ -253,9 +248,6 @@ static int hci_uart_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
 {
        struct hci_uart *hu = hci_get_drvdata(hdev);
 
-       if (!test_bit(HCI_RUNNING, &hdev->flags))
-               return -EBUSY;
-
        BT_DBG("%s: type %d len %d", hdev->name, bt_cb(skb)->pkt_type, skb->len);
 
        hu->proto->enqueue(hu, skb);
@@ -265,11 +257,133 @@ static int hci_uart_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
        return 0;
 }
 
+/* Flow control or un-flow control the device */
+void hci_uart_set_flow_control(struct hci_uart *hu, bool enable)
+{
+       struct tty_struct *tty = hu->tty;
+       struct ktermios ktermios;
+       int status;
+       unsigned int set = 0;
+       unsigned int clear = 0;
+
+       if (enable) {
+               /* Disable hardware flow control */
+               ktermios = tty->termios;
+               ktermios.c_cflag &= ~CRTSCTS;
+               status = tty_set_termios(tty, &ktermios);
+               BT_DBG("Disabling hardware flow control: %s",
+                      status ? "failed" : "success");
+
+               /* Clear RTS to prevent the device from sending */
+               /* Most UARTs need OUT2 to enable interrupts */
+               status = tty->driver->ops->tiocmget(tty);
+               BT_DBG("Current tiocm 0x%x", status);
+
+               set &= ~(TIOCM_OUT2 | TIOCM_RTS);
+               clear = ~set;
+               set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
+                      TIOCM_OUT2 | TIOCM_LOOP;
+               clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
+                        TIOCM_OUT2 | TIOCM_LOOP;
+               status = tty->driver->ops->tiocmset(tty, set, clear);
+               BT_DBG("Clearing RTS: %s", status ? "failed" : "success");
+       } else {
+               /* Set RTS to allow the device to send again */
+               status = tty->driver->ops->tiocmget(tty);
+               BT_DBG("Current tiocm 0x%x", status);
+
+               set |= (TIOCM_OUT2 | TIOCM_RTS);
+               clear = ~set;
+               set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
+                      TIOCM_OUT2 | TIOCM_LOOP;
+               clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
+                        TIOCM_OUT2 | TIOCM_LOOP;
+               status = tty->driver->ops->tiocmset(tty, set, clear);
+               BT_DBG("Setting RTS: %s", status ? "failed" : "success");
+
+               /* Re-enable hardware flow control */
+               ktermios = tty->termios;
+               ktermios.c_cflag |= CRTSCTS;
+               status = tty_set_termios(tty, &ktermios);
+               BT_DBG("Enabling hardware flow control: %s",
+                      status ? "failed" : "success");
+       }
+}
+
+void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed,
+                        unsigned int oper_speed)
+{
+       hu->init_speed = 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;
+       struct ktermios ktermios;
+
+       ktermios = tty->termios;
+       ktermios.c_cflag &= ~CBAUD;
+       tty_termios_encode_baud_rate(&ktermios, speed, speed);
+
+       /* tty_set_termios() return not checked as it is always 0 */
+       tty_set_termios(tty, &ktermios);
+
+       BT_DBG("%s: New tty speeds: %d/%d", hu->hdev->name,
+              tty->termios.c_ispeed, tty->termios.c_ospeed);
+}
+
 static int hci_uart_setup(struct hci_dev *hdev)
 {
        struct hci_uart *hu = hci_get_drvdata(hdev);
        struct hci_rp_read_local_version *ver;
        struct sk_buff *skb;
+       unsigned int speed;
+       int err;
+
+       /* Init speed if any */
+       if (hu->init_speed)
+               speed = hu->init_speed;
+       else if (hu->proto->init_speed)
+               speed = hu->proto->init_speed;
+       else
+               speed = 0;
+
+       if (speed)
+               hci_uart_set_baudrate(hu, speed);
+
+       /* 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 (hu->proto->set_baudrate && speed) {
+               err = hu->proto->set_baudrate(hu, speed);
+               if (!err)
+                       hci_uart_set_baudrate(hu, speed);
+       }
 
        if (hu->proto->setup)
                return hu->proto->setup(hu);
@@ -347,8 +461,6 @@ static int hci_uart_tty_open(struct tty_struct *tty)
        INIT_WORK(&hu->init_ready, hci_uart_init_work);
        INIT_WORK(&hu->write_work, hci_uart_write_work);
 
-       spin_lock_init(&hu->rx_lock);
-
        /* Flush any pending characters in the driver and line discipline. */
 
        /* FIXME: why is this needed. Note don't use ldisc_ref here as the
@@ -446,14 +558,14 @@ static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data,
        if (!test_bit(HCI_UART_PROTO_SET, &hu->flags))
                return;
 
-       spin_lock(&hu->rx_lock);
+       /* It does not need a lock here as it is already protected by a mutex in
+        * tty caller
+        */
        hu->proto->recv(hu, data, count);
 
        if (hu->hdev)
                hu->hdev->stat.byte_rx += count;
 
-       spin_unlock(&hu->rx_lock);
-
        tty_unthrottle(tty);
 }
 
@@ -475,6 +587,13 @@ static int hci_uart_register_dev(struct hci_uart *hu)
        hdev->bus = HCI_UART;
        hci_set_drvdata(hdev, hu);
 
+       /* Only when vendor specific setup callback is provided, consider
+        * the manufacturer information valid. This avoids filling in the
+        * value for Ericsson when nothing is specified.
+        */
+       if (hu->proto->setup)
+               hdev->manufacturer = hu->proto->manufacturer;
+
        hdev->open  = hci_uart_open;
        hdev->close = hci_uart_close;
        hdev->flush = hci_uart_flush;
@@ -647,7 +766,7 @@ static int __init hci_uart_init(void)
 
        /* Register the tty discipline */
 
-       memset(&hci_uart_ldisc, 0, sizeof (hci_uart_ldisc));
+       memset(&hci_uart_ldisc, 0, sizeof(hci_uart_ldisc));
        hci_uart_ldisc.magic            = TTY_LDISC_MAGIC;
        hci_uart_ldisc.name             = "n_hci";
        hci_uart_ldisc.open             = hci_uart_tty_open;
@@ -681,9 +800,15 @@ static int __init hci_uart_init(void)
 #ifdef CONFIG_BT_HCIUART_3WIRE
        h5_init();
 #endif
+#ifdef CONFIG_BT_HCIUART_INTEL
+       intel_init();
+#endif
 #ifdef CONFIG_BT_HCIUART_BCM
        bcm_init();
 #endif
+#ifdef CONFIG_BT_HCIUART_QCA
+       qca_init();
+#endif
 
        return 0;
 }
@@ -707,9 +832,15 @@ static void __exit hci_uart_exit(void)
 #ifdef CONFIG_BT_HCIUART_3WIRE
        h5_deinit();
 #endif
+#ifdef CONFIG_BT_HCIUART_INTEL
+       intel_deinit();
+#endif
 #ifdef CONFIG_BT_HCIUART_BCM
        bcm_deinit();
 #endif
+#ifdef CONFIG_BT_HCIUART_QCA
+       qca_deinit();
+#endif
 
        /* Release tty registration of line discipline */
        err = tty_unregister_ldisc(N_HCI);