Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Bluetooth HCI UART driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2000-2001  Qualcomm Incorporated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Copyright (C) 2004-2005  Marcel Holtmann <marcel@holtmann.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/serdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <net/bluetooth/bluetooth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <net/bluetooth/hci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include "btintel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include "btbcm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include "hci_uart.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define VERSION "2.3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static const struct hci_uart_proto *hup[HCI_UART_MAX_PROTO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) int hci_uart_register_proto(const struct hci_uart_proto *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (p->id >= HCI_UART_MAX_PROTO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (hup[p->id])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	hup[p->id] = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	BT_INFO("HCI UART protocol %s registered", p->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) int hci_uart_unregister_proto(const struct hci_uart_proto *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (p->id >= HCI_UART_MAX_PROTO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (!hup[p->id])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	hup[p->id] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static const struct hci_uart_proto *hci_uart_get_proto(unsigned int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (id >= HCI_UART_MAX_PROTO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	return hup[id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static inline void hci_uart_tx_complete(struct hci_uart *hu, int pkt_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct hci_dev *hdev = hu->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	/* Update HCI stat counters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	switch (pkt_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	case HCI_COMMAND_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		hdev->stat.cmd_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	case HCI_ACLDATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		hdev->stat.acl_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	case HCI_SCODATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		hdev->stat.sco_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static inline struct sk_buff *hci_uart_dequeue(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct sk_buff *skb = hu->tx_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		percpu_down_read(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		if (test_bit(HCI_UART_PROTO_READY, &hu->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			skb = hu->proto->dequeue(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		percpu_up_read(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		hu->tx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int hci_uart_tx_wakeup(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	/* This may be called in an IRQ context, so we can't sleep. Therefore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	 * we try to acquire the lock only, and if that fails we assume the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	 * tty is being closed because that is the only time the write lock is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 * acquired. If, however, at some point in the future the write lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 * is also acquired in other situations, then this must be revisited.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (!percpu_down_read_trylock(&hu->proto_lock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (!test_bit(HCI_UART_PROTO_READY, &hu->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		goto no_schedule;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		goto no_schedule;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	BT_DBG("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	schedule_work(&hu->write_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) no_schedule:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	percpu_up_read(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) EXPORT_SYMBOL_GPL(hci_uart_tx_wakeup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static void hci_uart_write_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct hci_uart *hu = container_of(work, struct hci_uart, write_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct tty_struct *tty = hu->tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct hci_dev *hdev = hu->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		clear_bit(HCI_UART_SENDING, &hu->tx_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/* REVISIT: should we cope with bad skbs or ->write() returning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 * and error value ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	clear_bit(HCI_UART_TX_WAKEUP, &hu->tx_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	while ((skb = hci_uart_dequeue(hu))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		len = tty->ops->write(tty, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		hdev->stat.byte_tx += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		skb_pull(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		if (skb->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			hu->tx_skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		hci_uart_tx_complete(hu, hci_skb_pkt_type(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	clear_bit(HCI_UART_SENDING, &hu->tx_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (test_bit(HCI_UART_TX_WAKEUP, &hu->tx_state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	wake_up_bit(&hu->tx_state, HCI_UART_SENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) void hci_uart_init_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	struct hci_uart *hu = container_of(work, struct hci_uart, init_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (!test_and_clear_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	err = hci_register_dev(hu->hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		BT_ERR("Can't register HCI device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		clear_bit(HCI_UART_PROTO_READY, &hu->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		hu->proto->close(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		hdev = hu->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		hu->hdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	set_bit(HCI_UART_REGISTERED, &hu->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int hci_uart_init_ready(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (!test_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		return -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	schedule_work(&hu->init_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int hci_uart_wait_until_sent(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	return wait_on_bit_timeout(&hu->tx_state, HCI_UART_SENDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				   TASK_INTERRUPTIBLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 				   msecs_to_jiffies(2000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* ------- Interface to HCI layer ------ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /* Reset device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static int hci_uart_flush(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	struct hci_uart *hu  = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct tty_struct *tty = hu->tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	BT_DBG("hdev %p tty %p", hdev, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (hu->tx_skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		kfree_skb(hu->tx_skb); hu->tx_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	/* Flush any pending characters in the driver and discipline. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	tty_ldisc_flush(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	tty_driver_flush_buffer(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	percpu_down_read(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (test_bit(HCI_UART_PROTO_READY, &hu->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		hu->proto->flush(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	percpu_up_read(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /* Initialize device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static int hci_uart_open(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	BT_DBG("%s %p", hdev->name, hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	/* Undo clearing this from hci_uart_close() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	hdev->flush = hci_uart_flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* Close device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static int hci_uart_close(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	BT_DBG("hdev %p", hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	hci_uart_flush(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	hdev->flush = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* Send frames from HCI layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static int hci_uart_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct hci_uart *hu = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	BT_DBG("%s: type %d len %d", hdev->name, hci_skb_pkt_type(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	       skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	percpu_down_read(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		percpu_up_read(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		return -EUNATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	hu->proto->enqueue(hu, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	percpu_up_read(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	hci_uart_tx_wakeup(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /* Check the underlying device or tty has flow control support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) bool hci_uart_has_flow_control(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	/* serdev nodes check if the needed operations are present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if (hu->serdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (hu->tty->driver->ops->tiocmget && hu->tty->driver->ops->tiocmset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /* Flow control or un-flow control the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) void hci_uart_set_flow_control(struct hci_uart *hu, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	struct tty_struct *tty = hu->tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct ktermios ktermios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	unsigned int set = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	unsigned int clear = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (hu->serdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		serdev_device_set_flow_control(hu->serdev, !enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		serdev_device_set_rts(hu->serdev, !enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if (enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		/* Disable hardware flow control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		ktermios = tty->termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		ktermios.c_cflag &= ~CRTSCTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		status = tty_set_termios(tty, &ktermios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		BT_DBG("Disabling hardware flow control: %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		       status ? "failed" : "success");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		/* Clear RTS to prevent the device from sending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		/* Most UARTs need OUT2 to enable interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		status = tty->driver->ops->tiocmget(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		BT_DBG("Current tiocm 0x%x", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		set &= ~(TIOCM_OUT2 | TIOCM_RTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		clear = ~set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		       TIOCM_OUT2 | TIOCM_LOOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			 TIOCM_OUT2 | TIOCM_LOOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		status = tty->driver->ops->tiocmset(tty, set, clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		BT_DBG("Clearing RTS: %s", status ? "failed" : "success");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		/* Set RTS to allow the device to send again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		status = tty->driver->ops->tiocmget(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		BT_DBG("Current tiocm 0x%x", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		set |= (TIOCM_OUT2 | TIOCM_RTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		clear = ~set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		set &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		       TIOCM_OUT2 | TIOCM_LOOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		clear &= TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 			 TIOCM_OUT2 | TIOCM_LOOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		status = tty->driver->ops->tiocmset(tty, set, clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		BT_DBG("Setting RTS: %s", status ? "failed" : "success");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		/* Re-enable hardware flow control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		ktermios = tty->termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		ktermios.c_cflag |= CRTSCTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		status = tty_set_termios(tty, &ktermios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		BT_DBG("Enabling hardware flow control: %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		       status ? "failed" : "success");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			 unsigned int oper_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	hu->init_speed = init_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	hu->oper_speed = oper_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	struct tty_struct *tty = hu->tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	struct ktermios ktermios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	ktermios = tty->termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	ktermios.c_cflag &= ~CBAUD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	tty_termios_encode_baud_rate(&ktermios, speed, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	/* tty_set_termios() return not checked as it is always 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	tty_set_termios(tty, &ktermios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	BT_DBG("%s: New tty speeds: %d/%d", hu->hdev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	       tty->termios.c_ispeed, tty->termios.c_ospeed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static int hci_uart_setup(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	struct hci_uart *hu = hci_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	struct hci_rp_read_local_version *ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	unsigned int speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	/* Init speed if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	if (hu->init_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		speed = hu->init_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	else if (hu->proto->init_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		speed = hu->proto->init_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	if (speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		hci_uart_set_baudrate(hu, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	/* Operational speed if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	if (hu->oper_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		speed = hu->oper_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	else if (hu->proto->oper_speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		speed = hu->proto->oper_speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (hu->proto->set_baudrate && speed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		err = hu->proto->set_baudrate(hu, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			hci_uart_set_baudrate(hu, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	if (hu->proto->setup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		return hu->proto->setup(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	if (!test_bit(HCI_UART_VND_DETECT, &hu->hdev_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			     HCI_INIT_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	if (IS_ERR(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		BT_ERR("%s: Reading local version information failed (%ld)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		       hdev->name, PTR_ERR(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	if (skb->len != sizeof(*ver)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		BT_ERR("%s: Event length mismatch for version information",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		       hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	ver = (struct hci_rp_read_local_version *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	switch (le16_to_cpu(ver->manufacturer)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) #ifdef CONFIG_BT_HCIUART_INTEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		hdev->set_bdaddr = btintel_set_bdaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		btintel_check_bdaddr(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) #ifdef CONFIG_BT_HCIUART_BCM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	case 15:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		hdev->set_bdaddr = btbcm_set_bdaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		btbcm_check_bdaddr(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /* ------ LDISC part ------ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) /* hci_uart_tty_open
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)  *     Called when line discipline changed to HCI_UART.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)  * Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  *     tty    pointer to tty info structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  * Return Value:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)  *     0 if success, otherwise error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static int hci_uart_tty_open(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	struct hci_uart *hu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	BT_DBG("tty %p", tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	/* Error if the tty has no write op instead of leaving an exploitable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	 * hole
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	if (tty->ops->write == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	if (!hu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		BT_ERR("Can't allocate control structure");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		return -ENFILE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	tty->disc_data = hu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	hu->tty = tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	tty->receive_room = 65536;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	/* disable alignment support by default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	hu->alignment = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	hu->padding = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	INIT_WORK(&hu->init_ready, hci_uart_init_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	INIT_WORK(&hu->write_work, hci_uart_write_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	percpu_init_rwsem(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	/* Flush any pending characters in the driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	tty_driver_flush_buffer(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) /* hci_uart_tty_close()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)  *    Called when the line discipline is changed to something
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)  *    else, the tty is closed, or the tty detects a hangup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static void hci_uart_tty_close(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	struct hci_uart *hu = tty->disc_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	BT_DBG("tty %p", tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	/* Detach from the tty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	tty->disc_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	if (!hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	hdev = hu->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	if (hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		hci_uart_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	if (test_bit(HCI_UART_PROTO_READY, &hu->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		percpu_down_write(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		clear_bit(HCI_UART_PROTO_READY, &hu->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 		percpu_up_write(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		cancel_work_sync(&hu->init_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		cancel_work_sync(&hu->write_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		if (hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 			if (test_bit(HCI_UART_REGISTERED, &hu->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 				hci_unregister_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 			hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		hu->proto->close(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	clear_bit(HCI_UART_PROTO_SET, &hu->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	percpu_free_rwsem(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	kfree(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) /* hci_uart_tty_wakeup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)  *    Callback for transmit wakeup. Called when low level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)  *    device driver can accept more send data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)  * Arguments:        tty    pointer to associated tty instance data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)  * Return Value:    None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) static void hci_uart_tty_wakeup(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	struct hci_uart *hu = tty->disc_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	BT_DBG("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	if (!hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	if (tty != hu->tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	if (test_bit(HCI_UART_PROTO_READY, &hu->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		hci_uart_tx_wakeup(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) /* hci_uart_tty_receive()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)  *     Called by tty low level driver when receive data is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)  *     available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)  * Arguments:  tty          pointer to tty isntance data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)  *             data         pointer to received data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)  *             flags        pointer to flags for data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)  *             count        count of received data in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)  * Return Value:    None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 				 char *flags, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	struct hci_uart *hu = tty->disc_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	if (!hu || tty != hu->tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	percpu_down_read(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 		percpu_up_read(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	/* It does not need a lock here as it is already protected by a mutex in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	 * tty caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	hu->proto->recv(hu, data, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	percpu_up_read(&hu->proto_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	if (hu->hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 		hu->hdev->stat.byte_rx += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	tty_unthrottle(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) static int hci_uart_register_dev(struct hci_uart *hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	BT_DBG("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	/* Initialize and register HCI device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	hdev = hci_alloc_dev();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	if (!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 		BT_ERR("Can't allocate HCI device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	hu->hdev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	hdev->bus = HCI_UART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	hci_set_drvdata(hdev, hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	/* Only when vendor specific setup callback is provided, consider
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	 * the manufacturer information valid. This avoids filling in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	 * value for Ericsson when nothing is specified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	if (hu->proto->setup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		hdev->manufacturer = hu->proto->manufacturer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	hdev->open  = hci_uart_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	hdev->close = hci_uart_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	hdev->flush = hci_uart_flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	hdev->send  = hci_uart_send_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	hdev->setup = hci_uart_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	SET_HCIDEV_DEV(hdev, hu->tty->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	if (test_bit(HCI_UART_RAW_DEVICE, &hu->hdev_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	if (test_bit(HCI_UART_EXT_CONFIG, &hu->hdev_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		set_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	if (!test_bit(HCI_UART_RESET_ON_INIT, &hu->hdev_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 		set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	if (test_bit(HCI_UART_CREATE_AMP, &hu->hdev_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 		hdev->dev_type = HCI_AMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		hdev->dev_type = HCI_PRIMARY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	/* Only call open() for the protocol after hdev is fully initialized as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	 * open() (or a timer/workqueue it starts) may attempt to reference it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	err = hu->proto->open(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		hu->hdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	if (test_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	if (hci_register_dev(hdev) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 		BT_ERR("Can't register HCI device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 		hu->proto->close(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		hu->hdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 		hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	set_bit(HCI_UART_REGISTERED, &hu->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static int hci_uart_set_proto(struct hci_uart *hu, int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	const struct hci_uart_proto *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	p = hci_uart_get_proto(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 		return -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	hu->proto = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	err = hci_uart_register_dev(hu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	set_bit(HCI_UART_PROTO_READY, &hu->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static int hci_uart_set_flags(struct hci_uart *hu, unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	unsigned long valid_flags = BIT(HCI_UART_RAW_DEVICE) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 				    BIT(HCI_UART_RESET_ON_INIT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 				    BIT(HCI_UART_CREATE_AMP) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 				    BIT(HCI_UART_INIT_PENDING) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 				    BIT(HCI_UART_EXT_CONFIG) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 				    BIT(HCI_UART_VND_DETECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	if (flags & ~valid_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	hu->hdev_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) /* hci_uart_tty_ioctl()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)  *    Process IOCTL system call for the tty device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)  * Arguments:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)  *    tty        pointer to tty instance data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)  *    file       pointer to open file object for device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)  *    cmd        IOCTL command code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)  *    arg        argument for IOCTL call (cmd dependent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)  * Return Value:    Command dependent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 			      unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	struct hci_uart *hu = tty->disc_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	BT_DBG("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	/* Verify the status of the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 	if (!hu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 		return -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	case HCIUARTSETPROTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 		if (!test_and_set_bit(HCI_UART_PROTO_SET, &hu->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 			err = hci_uart_set_proto(hu, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 				clear_bit(HCI_UART_PROTO_SET, &hu->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 			err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	case HCIUARTGETPROTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 		if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 			err = hu->proto->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 			err = -EUNATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	case HCIUARTGETDEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 		if (test_bit(HCI_UART_REGISTERED, &hu->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 			err = hu->hdev->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 			err = -EUNATCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	case HCIUARTSETFLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 		if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 			err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 			err = hci_uart_set_flags(hu, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 	case HCIUARTGETFLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 		err = hu->hdev_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 		err = n_tty_ioctl_helper(tty, file, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)  * We don't provide read/write/poll interface for user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 				 unsigned char *buf, size_t nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 				 void **cookie, unsigned long offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 				  const unsigned char *data, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) static __poll_t hci_uart_tty_poll(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 				      struct file *filp, poll_table *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) static struct tty_ldisc_ops hci_uart_ldisc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 	.magic		= TTY_LDISC_MAGIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	.name		= "n_hci",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 	.open		= hci_uart_tty_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	.close		= hci_uart_tty_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 	.read		= hci_uart_tty_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 	.write		= hci_uart_tty_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 	.ioctl		= hci_uart_tty_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 	.compat_ioctl	= hci_uart_tty_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	.poll		= hci_uart_tty_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 	.receive_buf	= hci_uart_tty_receive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	.write_wakeup	= hci_uart_tty_wakeup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) static int __init hci_uart_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 	BT_INFO("HCI UART driver ver %s", VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	/* Register the tty discipline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 	err = tty_register_ldisc(N_HCI, &hci_uart_ldisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 		BT_ERR("HCI line discipline registration failed. (%d)", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) #ifdef CONFIG_BT_HCIUART_H4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) 	h4_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) #ifdef CONFIG_BT_HCIUART_BCSP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) 	bcsp_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) #ifdef CONFIG_BT_HCIUART_LL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 	ll_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) #ifdef CONFIG_BT_HCIUART_ATH3K
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 	ath_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) #ifdef CONFIG_BT_HCIUART_3WIRE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 	h5_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) #ifdef CONFIG_BT_HCIUART_INTEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 	intel_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) #ifdef CONFIG_BT_HCIUART_BCM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 	bcm_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) #ifdef CONFIG_BT_HCIUART_QCA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 	qca_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) #ifdef CONFIG_BT_HCIUART_AG6XX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 	ag6xx_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) #ifdef CONFIG_BT_HCIUART_MRVL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 	mrvl_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) static void __exit hci_uart_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) #ifdef CONFIG_BT_HCIUART_H4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 	h4_deinit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) #ifdef CONFIG_BT_HCIUART_BCSP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 	bcsp_deinit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) #ifdef CONFIG_BT_HCIUART_LL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) 	ll_deinit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) #ifdef CONFIG_BT_HCIUART_ATH3K
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) 	ath_deinit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) #ifdef CONFIG_BT_HCIUART_3WIRE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) 	h5_deinit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) #ifdef CONFIG_BT_HCIUART_INTEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 	intel_deinit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) #ifdef CONFIG_BT_HCIUART_BCM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) 	bcm_deinit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) #ifdef CONFIG_BT_HCIUART_QCA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 	qca_deinit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) #ifdef CONFIG_BT_HCIUART_AG6XX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) 	ag6xx_deinit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) #ifdef CONFIG_BT_HCIUART_MRVL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) 	mrvl_deinit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) 	/* Release tty registration of line discipline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) 	err = tty_unregister_ldisc(N_HCI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) 		BT_ERR("Can't unregister HCI line discipline (%d)", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) module_init(hci_uart_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) module_exit(hci_uart_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) MODULE_DESCRIPTION("Bluetooth HCI UART driver ver " VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) MODULE_VERSION(VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) MODULE_ALIAS_LDISC(N_HCI);