11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds /*
30372a662SMarcel Holtmann *
40372a662SMarcel Holtmann * Bluetooth HCI UART driver
50372a662SMarcel Holtmann *
60372a662SMarcel Holtmann * Copyright (C) 2000-2001 Qualcomm Incorporated
70372a662SMarcel Holtmann * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
80372a662SMarcel Holtmann * Copyright (C) 2004-2005 Marcel Holtmann <marcel@holtmann.org>
91da177e4SLinus Torvalds */
101da177e4SLinus Torvalds
111da177e4SLinus Torvalds #ifndef N_HCI
121da177e4SLinus Torvalds #define N_HCI 15
131da177e4SLinus Torvalds #endif
141da177e4SLinus Torvalds
151da177e4SLinus Torvalds /* Ioctls */
161da177e4SLinus Torvalds #define HCIUARTSETPROTO _IOW('U', 200, int)
171da177e4SLinus Torvalds #define HCIUARTGETPROTO _IOR('U', 201, int)
18d2158744SMarcel Holtmann #define HCIUARTGETDEVICE _IOR('U', 202, int)
1963c7d09cSJohan Hedberg #define HCIUARTSETFLAGS _IOW('U', 203, int)
2063c7d09cSJohan Hedberg #define HCIUARTGETFLAGS _IOR('U', 204, int)
211da177e4SLinus Torvalds
221da177e4SLinus Torvalds /* UART protocols */
23162f812fSLoic Poulain #define HCI_UART_MAX_PROTO 12
241da177e4SLinus Torvalds
251da177e4SLinus Torvalds #define HCI_UART_H4 0
261da177e4SLinus Torvalds #define HCI_UART_BCSP 1
271da177e4SLinus Torvalds #define HCI_UART_3WIRE 2
281da177e4SLinus Torvalds #define HCI_UART_H4DS 3
29166d2f6aSOhad Ben-Cohen #define HCI_UART_LL 4
30b3190df6SSuraj Sumangala #define HCI_UART_ATH3K 5
3116e3887fSMarcel Holtmann #define HCI_UART_INTEL 6
32e9a2dd26SMarcel Holtmann #define HCI_UART_BCM 7
330ff252c1SBen Young Tae Kim #define HCI_UART_QCA 8
34395174bbSLoic Poulain #define HCI_UART_AG6XX 9
359e69130cSLoic Poulain #define HCI_UART_NOKIA 10
36162f812fSLoic Poulain #define HCI_UART_MRVL 11
371da177e4SLinus Torvalds
3863c7d09cSJohan Hedberg #define HCI_UART_RAW_DEVICE 0
39a55e1f38SMarcel Holtmann #define HCI_UART_RESET_ON_INIT 1
409f2aee84SJohan Hedberg #define HCI_UART_INIT_PENDING 3
416afd04adSMarcel Holtmann #define HCI_UART_EXT_CONFIG 4
42fb2ce8d1SMarcel Holtmann #define HCI_UART_VND_DETECT 5
4363c7d09cSJohan Hedberg
441da177e4SLinus Torvalds struct hci_uart;
4582f5169bSRob Herring struct serdev_device;
461da177e4SLinus Torvalds
471da177e4SLinus Torvalds struct hci_uart_proto {
481da177e4SLinus Torvalds unsigned int id;
497c40fb8dSMarcel Holtmann const char *name;
50aee61f7aSMarcel Holtmann unsigned int manufacturer;
517721383fSFrederic Danis unsigned int init_speed;
527721383fSFrederic Danis unsigned int oper_speed;
531da177e4SLinus Torvalds int (*open)(struct hci_uart *hu);
541da177e4SLinus Torvalds int (*close)(struct hci_uart *hu);
551da177e4SLinus Torvalds int (*flush)(struct hci_uart *hu);
566ae4fddfSMarcel Holtmann int (*setup)(struct hci_uart *hu);
577721383fSFrederic Danis int (*set_baudrate)(struct hci_uart *hu, unsigned int speed);
589d1c40ebSMarcel Holtmann int (*recv)(struct hci_uart *hu, const void *data, int len);
591da177e4SLinus Torvalds int (*enqueue)(struct hci_uart *hu, struct sk_buff *skb);
601da177e4SLinus Torvalds struct sk_buff *(*dequeue)(struct hci_uart *hu);
611da177e4SLinus Torvalds };
621da177e4SLinus Torvalds
631da177e4SLinus Torvalds struct hci_uart {
641da177e4SLinus Torvalds struct tty_struct *tty;
6582f5169bSRob Herring struct serdev_device *serdev;
661da177e4SLinus Torvalds struct hci_dev *hdev;
671da177e4SLinus Torvalds unsigned long flags;
6863c7d09cSJohan Hedberg unsigned long hdev_flags;
691da177e4SLinus Torvalds
709f2aee84SJohan Hedberg struct work_struct init_ready;
71da64c27dSFelipe Balbi struct work_struct write_work;
729f2aee84SJohan Hedberg
734ee7ef19SMarcel Holtmann const struct hci_uart_proto *proto;
7467d2f878SRonald Tschalär struct percpu_rw_semaphore proto_lock; /* Stop work for proto close */
751da177e4SLinus Torvalds void *priv;
761da177e4SLinus Torvalds
771da177e4SLinus Torvalds struct sk_buff *tx_skb;
781da177e4SLinus Torvalds unsigned long tx_state;
792a973dfaSIlya Faenson
802a973dfaSIlya Faenson unsigned int init_speed;
812a973dfaSIlya Faenson unsigned int oper_speed;
82aeac3014SSebastian Reichel
83aeac3014SSebastian Reichel u8 alignment;
84aeac3014SSebastian Reichel u8 padding;
851da177e4SLinus Torvalds };
861da177e4SLinus Torvalds
8763c7d09cSJohan Hedberg /* HCI_UART proto flag bits */
881da177e4SLinus Torvalds #define HCI_UART_PROTO_SET 0
899f2aee84SJohan Hedberg #define HCI_UART_REGISTERED 1
9084cb3df0SLoic Poulain #define HCI_UART_PROTO_READY 2
91b4a46996SHans de Goede #define HCI_UART_NO_SUSPEND_NOTIFIER 3
921da177e4SLinus Torvalds
931da177e4SLinus Torvalds /* TX states */
941da177e4SLinus Torvalds #define HCI_UART_SENDING 1
951da177e4SLinus Torvalds #define HCI_UART_TX_WAKEUP 2
961da177e4SLinus Torvalds
974ee7ef19SMarcel Holtmann int hci_uart_register_proto(const struct hci_uart_proto *p);
984ee7ef19SMarcel Holtmann int hci_uart_unregister_proto(const struct hci_uart_proto *p);
99*5939db19SAndrey Skvortsov
100*5939db19SAndrey Skvortsov int hci_uart_register_device_priv(struct hci_uart *hu,
101*5939db19SAndrey Skvortsov const struct hci_uart_proto *p,
102*5939db19SAndrey Skvortsov int sizeof_priv);
103*5939db19SAndrey Skvortsov
hci_uart_register_device(struct hci_uart * hu,const struct hci_uart_proto * p)104*5939db19SAndrey Skvortsov static inline int hci_uart_register_device(struct hci_uart *hu,
105*5939db19SAndrey Skvortsov const struct hci_uart_proto *p)
106*5939db19SAndrey Skvortsov {
107*5939db19SAndrey Skvortsov return hci_uart_register_device_priv(hu, p, 0);
108*5939db19SAndrey Skvortsov }
109*5939db19SAndrey Skvortsov
110c34dc3bfSIan Molton void hci_uart_unregister_device(struct hci_uart *hu);
11182f5169bSRob Herring
1121da177e4SLinus Torvalds int hci_uart_tx_wakeup(struct hci_uart *hu);
11340fbb915SSascha Hauer int hci_uart_wait_until_sent(struct hci_uart *hu);
1149f2aee84SJohan Hedberg int hci_uart_init_ready(struct hci_uart *hu);
115fdee6d8fSHans de Goede void hci_uart_init_work(struct work_struct *work);
1167721383fSFrederic Danis void hci_uart_set_baudrate(struct hci_uart *hu, unsigned int speed);
117b36a1552SVladis Dronov bool hci_uart_has_flow_control(struct hci_uart *hu);
1182a973dfaSIlya Faenson void hci_uart_set_flow_control(struct hci_uart *hu, bool enable);
1192a973dfaSIlya Faenson void hci_uart_set_speeds(struct hci_uart *hu, unsigned int init_speed,
1202a973dfaSIlya Faenson unsigned int oper_speed);
1211da177e4SLinus Torvalds
1220372a662SMarcel Holtmann #ifdef CONFIG_BT_HCIUART_H4
1230372a662SMarcel Holtmann int h4_init(void);
1240372a662SMarcel Holtmann int h4_deinit(void);
125e1a38d70SMarcel Holtmann
12679b8df93SMarcel Holtmann struct h4_recv_pkt {
12779b8df93SMarcel Holtmann u8 type; /* Packet type */
12879b8df93SMarcel Holtmann u8 hlen; /* Header length */
12979b8df93SMarcel Holtmann u8 loff; /* Data length offset in header */
13079b8df93SMarcel Holtmann u8 lsize; /* Data length field size */
13179b8df93SMarcel Holtmann u16 maxlen; /* Max overall packet length */
13279b8df93SMarcel Holtmann int (*recv)(struct hci_dev *hdev, struct sk_buff *skb);
13379b8df93SMarcel Holtmann };
13479b8df93SMarcel Holtmann
13579b8df93SMarcel Holtmann #define H4_RECV_ACL \
13679b8df93SMarcel Holtmann .type = HCI_ACLDATA_PKT, \
13779b8df93SMarcel Holtmann .hlen = HCI_ACL_HDR_SIZE, \
13879b8df93SMarcel Holtmann .loff = 2, \
13979b8df93SMarcel Holtmann .lsize = 2, \
14079b8df93SMarcel Holtmann .maxlen = HCI_MAX_FRAME_SIZE \
14179b8df93SMarcel Holtmann
14279b8df93SMarcel Holtmann #define H4_RECV_SCO \
14379b8df93SMarcel Holtmann .type = HCI_SCODATA_PKT, \
14479b8df93SMarcel Holtmann .hlen = HCI_SCO_HDR_SIZE, \
14579b8df93SMarcel Holtmann .loff = 2, \
14679b8df93SMarcel Holtmann .lsize = 1, \
14779b8df93SMarcel Holtmann .maxlen = HCI_MAX_SCO_SIZE
14879b8df93SMarcel Holtmann
14979b8df93SMarcel Holtmann #define H4_RECV_EVENT \
15079b8df93SMarcel Holtmann .type = HCI_EVENT_PKT, \
15179b8df93SMarcel Holtmann .hlen = HCI_EVENT_HDR_SIZE, \
15279b8df93SMarcel Holtmann .loff = 1, \
15379b8df93SMarcel Holtmann .lsize = 1, \
15479b8df93SMarcel Holtmann .maxlen = HCI_MAX_EVENT_SIZE
15579b8df93SMarcel Holtmann
156ef564119SLuiz Augusto von Dentz #define H4_RECV_ISO \
157ef564119SLuiz Augusto von Dentz .type = HCI_ISODATA_PKT, \
158ef564119SLuiz Augusto von Dentz .hlen = HCI_ISO_HDR_SIZE, \
159ef564119SLuiz Augusto von Dentz .loff = 2, \
160ef564119SLuiz Augusto von Dentz .lsize = 2, \
161ef564119SLuiz Augusto von Dentz .maxlen = HCI_MAX_FRAME_SIZE \
162ef564119SLuiz Augusto von Dentz
163e1a38d70SMarcel Holtmann struct sk_buff *h4_recv_buf(struct hci_dev *hdev, struct sk_buff *skb,
16479b8df93SMarcel Holtmann const unsigned char *buffer, int count,
16579b8df93SMarcel Holtmann const struct h4_recv_pkt *pkts, int pkts_count);
1660372a662SMarcel Holtmann #endif
1670372a662SMarcel Holtmann
1680372a662SMarcel Holtmann #ifdef CONFIG_BT_HCIUART_BCSP
1690372a662SMarcel Holtmann int bcsp_init(void);
1700372a662SMarcel Holtmann int bcsp_deinit(void);
1710372a662SMarcel Holtmann #endif
172166d2f6aSOhad Ben-Cohen
173166d2f6aSOhad Ben-Cohen #ifdef CONFIG_BT_HCIUART_LL
174166d2f6aSOhad Ben-Cohen int ll_init(void);
175166d2f6aSOhad Ben-Cohen int ll_deinit(void);
176166d2f6aSOhad Ben-Cohen #endif
177b3190df6SSuraj Sumangala
178b3190df6SSuraj Sumangala #ifdef CONFIG_BT_HCIUART_ATH3K
179b3190df6SSuraj Sumangala int ath_init(void);
180b3190df6SSuraj Sumangala int ath_deinit(void);
181b3190df6SSuraj Sumangala #endif
1827dec65c8SJohan Hedberg
1837dec65c8SJohan Hedberg #ifdef CONFIG_BT_HCIUART_3WIRE
1847dec65c8SJohan Hedberg int h5_init(void);
1857dec65c8SJohan Hedberg int h5_deinit(void);
1867dec65c8SJohan Hedberg #endif
18716e3887fSMarcel Holtmann
188ca93cee5SLoic Poulain #ifdef CONFIG_BT_HCIUART_INTEL
189ca93cee5SLoic Poulain int intel_init(void);
190ca93cee5SLoic Poulain int intel_deinit(void);
191ca93cee5SLoic Poulain #endif
192ca93cee5SLoic Poulain
193bdd8818eSMarcel Holtmann #ifdef CONFIG_BT_HCIUART_BCM
194bdd8818eSMarcel Holtmann int bcm_init(void);
195bdd8818eSMarcel Holtmann int bcm_deinit(void);
196bdd8818eSMarcel Holtmann #endif
1970ff252c1SBen Young Tae Kim
1980ff252c1SBen Young Tae Kim #ifdef CONFIG_BT_HCIUART_QCA
1990ff252c1SBen Young Tae Kim int qca_init(void);
2000ff252c1SBen Young Tae Kim int qca_deinit(void);
2010ff252c1SBen Young Tae Kim #endif
202395174bbSLoic Poulain
203395174bbSLoic Poulain #ifdef CONFIG_BT_HCIUART_AG6XX
204395174bbSLoic Poulain int ag6xx_init(void);
205395174bbSLoic Poulain int ag6xx_deinit(void);
206395174bbSLoic Poulain #endif
207162f812fSLoic Poulain
208162f812fSLoic Poulain #ifdef CONFIG_BT_HCIUART_MRVL
209162f812fSLoic Poulain int mrvl_init(void);
210162f812fSLoic Poulain int mrvl_deinit(void);
211162f812fSLoic Poulain #endif
212