1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * 4 * Bluetooth HCI UART driver 5 * 6 * Copyright (C) 2000-2001 Qualcomm Incorporated 7 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com> 8 * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org> 9 */ 10 11 #include <net/bluetooth/hci_h4.h> 12 13 #ifndef N_HCI 14 #define N_HCI 15 15 #endif 16 17 /* Ioctls */ 18 #define HCIUARTSETPROTO _IOW('U', 200, int) 19 #define HCIUARTGETPROTO _IOR('U', 201, int) 20 #define HCIUARTGETDEVICE _IOR('U', 202, int) 21 #define HCIUARTSETFLAGS _IOW('U', 203, int) 22 #define HCIUARTGETFLAGS _IOR('U', 204, int) 23 24 /* UART protocols */ 25 #define HCI_UART_MAX_PROTO 13 26 27 #define HCI_UART_H4 0 28 #define HCI_UART_BCSP 1 29 #define HCI_UART_3WIRE 2 30 #define HCI_UART_H4DS 3 31 #define HCI_UART_LL 4 32 #define HCI_UART_ATH3K 5 33 #define HCI_UART_INTEL 6 34 #define HCI_UART_BCM 7 35 #define HCI_UART_QCA 8 36 #define HCI_UART_AG6XX 9 37 #define HCI_UART_NOKIA 10 38 #define HCI_UART_MRVL 11 39 #define HCI_UART_AML 12 40 41 #define HCI_UART_RAW_DEVICE 0 42 #define HCI_UART_RESET_ON_INIT 1 43 #define HCI_UART_INIT_PENDING 3 44 #define HCI_UART_EXT_CONFIG 4 45 #define HCI_UART_VND_DETECT 5 46 47 struct hci_uart; 48 struct serdev_device; 49 50 struct hci_uart_proto { 51 unsigned int id; 52 const char *name; 53 unsigned int manufacturer; 54 unsigned int init_speed; 55 unsigned int oper_speed; 56 int (*open)(struct hci_uart *hu); 57 int (*close)(struct hci_uart *hu); 58 int (*flush)(struct hci_uart *hu); 59 int (*setup)(struct hci_uart *hu); 60 int (*set_baudrate)(struct hci_uart *hu, unsigned int speed); 61 int (*recv)(struct hci_uart *hu, const void *data, int len); 62 int (*enqueue)(struct hci_uart *hu, struct sk_buff *skb); 63 struct sk_buff *(*dequeue)(struct hci_uart *hu); 64 }; 65 66 struct hci_uart { 67 struct tty_struct *tty; 68 struct serdev_device *serdev; 69 struct hci_dev *hdev; 70 unsigned long flags; 71 unsigned long hdev_flags; 72 73 struct work_struct init_ready; 74 struct work_struct write_work; 75 76 const struct hci_uart_proto *proto; 77 struct percpu_rw_semaphore proto_lock; /* Stop work for proto close */ 78 void *priv; 79 80 struct sk_buff *tx_skb; 81 unsigned long tx_state; 82 83 unsigned int init_speed; 84 unsigned int oper_speed; 85 86 u8 alignment; 87 u8 padding; 88 }; 89 90 /* HCI_UART proto flag bits */ 91 #define HCI_UART_PROTO_SET 0 92 #define HCI_UART_REGISTERED 1 93 #define HCI_UART_PROTO_READY 2 94 #define HCI_UART_NO_SUSPEND_NOTIFIER 3 95 #define HCI_UART_PROTO_INIT 4 96 97 /* TX states */ 98 #define HCI_UART_SENDING 1 99 #define HCI_UART_TX_WAKEUP 2 100 101 int hci_uart_register_proto(const struct hci_uart_proto *p); 102 int hci_uart_unregister_proto(const struct hci_uart_proto *p); 103 104 int hci_uart_register_device_priv(struct hci_uart *hu, 105 const struct hci_uart_proto *p, 106 int sizeof_priv); 107 108 static inline int hci_uart_register_device(struct hci_uart *hu, 109 const struct hci_uart_proto *p) 110 { 111 return hci_uart_register_device_priv(hu, p, 0); 112 } 113 114 void hci_uart_unregister_device(struct hci_uart *hu); 115 116 int hci_uart_tx_wakeup(struct hci_uart *hu); 117 int hci_uart_wait_until_sent(struct hci_uart *hu); 118 int hci_uart_init_ready(struct hci_uart *hu); 119 void hci_uart_init_work(struct work_struct *work); 120 void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed); 121 bool hci_uart_has_flow_control(struct hci_uart *hu); 122 void hci_uart_set_flow_control(struct hci_uart *hu, bool enable); 123 void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed, 124 unsigned int oper_speed); 125 126 #ifdef CONFIG_BT_HCIUART_H4 127 int h4_init(void); 128 int h4_deinit(void); 129 130 struct sk_buff *h4_recv_buf(struct hci_uart *hu, struct sk_buff *skb, 131 const unsigned char *buffer, int count, 132 const struct h4_recv_pkt *pkts, int pkts_count); 133 #endif 134 135 #ifdef CONFIG_BT_HCIUART_BCSP 136 int bcsp_init(void); 137 int bcsp_deinit(void); 138 #endif 139 140 #ifdef CONFIG_BT_HCIUART_LL 141 int ll_init(void); 142 int ll_deinit(void); 143 #endif 144 145 #ifdef CONFIG_BT_HCIUART_ATH3K 146 int ath_init(void); 147 int ath_deinit(void); 148 #endif 149 150 #ifdef CONFIG_BT_HCIUART_3WIRE 151 int h5_init(void); 152 int h5_deinit(void); 153 #endif 154 155 #ifdef CONFIG_BT_HCIUART_INTEL 156 int intel_init(void); 157 int intel_deinit(void); 158 #endif 159 160 #ifdef CONFIG_BT_HCIUART_BCM 161 int bcm_init(void); 162 int bcm_deinit(void); 163 #endif 164 165 #ifdef CONFIG_BT_HCIUART_QCA 166 int qca_init(void); 167 int qca_deinit(void); 168 #endif 169 170 #ifdef CONFIG_BT_HCIUART_AG6XX 171 int ag6xx_init(void); 172 int ag6xx_deinit(void); 173 #endif 174 175 #ifdef CONFIG_BT_HCIUART_MRVL 176 int mrvl_init(void); 177 int mrvl_deinit(void); 178 #endif 179 180 #ifdef CONFIG_BT_HCIUART_AML 181 int aml_init(void); 182 int aml_deinit(void); 183 #endif 184