Skip to content

Commit bdd8818

Browse files
committed
Bluetooth: hci_uart: Add protocol support for Broadcom UART devices
This adds the protocol support for Broadcom based UART devices to enable firmware and patchram download procedure. It is a pretty straight forward H:4 driver with the exception of actually having its own setup and address configuration callbacks. Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
1 parent 6ae4fdd commit bdd8818

4 files changed

Lines changed: 127 additions & 0 deletions

File tree

‎drivers/bluetooth/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ config BT_HCIUART_INTEL
122122
config BT_HCIUART_BCM
123123
bool "Broadcom protocol support"
124124
depends on BT_HCIUART
125+
select BT_HCIUART_H4
125126
select BT_BCM
126127
help
127128
The Broadcom protocol support enables Bluetooth HCI over serial

‎drivers/bluetooth/hci_bcm.c‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,119 @@
2828
#include <net/bluetooth/bluetooth.h>
2929
#include <net/bluetooth/hci_core.h>
3030

31+
#include "btbcm.h"
3132
#include "hci_uart.h"
33+
34+
struct bcm_data {
35+
struct sk_buff *rx_skb;
36+
struct sk_buff_head txq;
37+
};
38+
39+
static int bcm_open(struct hci_uart *hu)
40+
{
41+
struct bcm_data *bcm;
42+
43+
BT_DBG("hu %p", hu);
44+
45+
bcm = kzalloc(sizeof(*bcm), GFP_KERNEL);
46+
if (!bcm)
47+
return -ENOMEM;
48+
49+
skb_queue_head_init(&bcm->txq);
50+
51+
hu->priv = bcm;
52+
return 0;
53+
}
54+
55+
static int bcm_close(struct hci_uart *hu)
56+
{
57+
struct bcm_data *bcm = hu->priv;
58+
59+
BT_DBG("hu %p", hu);
60+
61+
skb_queue_purge(&bcm->txq);
62+
kfree_skb(bcm->rx_skb);
63+
kfree(bcm);
64+
65+
hu->priv = NULL;
66+
return 0;
67+
}
68+
69+
static int bcm_flush(struct hci_uart *hu)
70+
{
71+
struct bcm_data *bcm = hu->priv;
72+
73+
BT_DBG("hu %p", hu);
74+
75+
skb_queue_purge(&bcm->txq);
76+
77+
return 0;
78+
}
79+
80+
static int bcm_setup(struct hci_uart *hu)
81+
{
82+
BT_DBG("hu %p", hu);
83+
84+
hu->hdev->set_bdaddr = btbcm_set_bdaddr;
85+
86+
return btbcm_setup_patchram(hu->hdev);
87+
}
88+
89+
static int bcm_recv(struct hci_uart *hu, const void *data, int count)
90+
{
91+
struct bcm_data *bcm = hu->priv;
92+
93+
if (!test_bit(HCI_UART_REGISTERED, &hu->flags))
94+
return -EUNATCH;
95+
96+
bcm->rx_skb = h4_recv_buf(hu->hdev, bcm->rx_skb, data, count);
97+
if (IS_ERR(bcm->rx_skb)) {
98+
int err = PTR_ERR(bcm->rx_skb);
99+
BT_ERR("%s: Frame reassembly failed (%d)", hu->hdev->name, err);
100+
return err;
101+
}
102+
103+
return count;
104+
}
105+
106+
static int bcm_enqueue(struct hci_uart *hu, struct sk_buff *skb)
107+
{
108+
struct bcm_data *bcm = hu->priv;
109+
110+
BT_DBG("hu %p skb %p", hu, skb);
111+
112+
/* Prepend skb with frame type */
113+
memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
114+
skb_queue_tail(&bcm->txq, skb);
115+
116+
return 0;
117+
}
118+
119+
static struct sk_buff *bcm_dequeue(struct hci_uart *hu)
120+
{
121+
struct bcm_data *bcm = hu->priv;
122+
123+
return skb_dequeue(&bcm->txq);
124+
}
125+
126+
static const struct hci_uart_proto bcm_proto = {
127+
.id = HCI_UART_BCM,
128+
.name = "BCM",
129+
.open = bcm_open,
130+
.close = bcm_close,
131+
.flush = bcm_flush,
132+
.setup = bcm_setup,
133+
.recv = bcm_recv,
134+
.enqueue = bcm_enqueue,
135+
.dequeue = bcm_dequeue,
136+
};
137+
138+
int __init bcm_init(void)
139+
{
140+
return hci_uart_register_proto(&bcm_proto);
141+
}
142+
143+
int __exit bcm_deinit(void)
144+
{
145+
return hci_uart_unregister_proto(&bcm_proto);
146+
}

‎drivers/bluetooth/hci_ldisc.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,9 @@ static int __init hci_uart_init(void)
679679
#ifdef CONFIG_BT_HCIUART_3WIRE
680680
h5_init();
681681
#endif
682+
#ifdef CONFIG_BT_HCIUART_BCM
683+
bcm_init();
684+
#endif
682685

683686
return 0;
684687
}
@@ -702,6 +705,9 @@ static void __exit hci_uart_exit(void)
702705
#ifdef CONFIG_BT_HCIUART_3WIRE
703706
h5_deinit();
704707
#endif
708+
#ifdef CONFIG_BT_HCIUART_BCM
709+
bcm_deinit();
710+
#endif
705711

706712
/* Release tty registration of line discipline */
707713
err = tty_unregister_ldisc(N_HCI);

‎drivers/bluetooth/hci_uart.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,8 @@ int h5_deinit(void);
128128
#ifdef CONFIG_BT_HCIUART_INTEL
129129
int intel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
130130
#endif
131+
132+
#ifdef CONFIG_BT_HCIUART_BCM
133+
int bcm_init(void);
134+
int bcm_deinit(void);
135+
#endif

0 commit comments

Comments
 (0)