3 * Bluetooth HCI UART driver for Broadcom devices
5 * Copyright (C) 2015 Intel Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/kernel.h>
25 #include <linux/errno.h>
26 #include <linux/skbuff.h>
28 #include <net/bluetooth/bluetooth.h>
29 #include <net/bluetooth/hci_core.h>
35 struct sk_buff
*rx_skb
;
36 struct sk_buff_head txq
;
39 static int bcm_open(struct hci_uart
*hu
)
45 bcm
= kzalloc(sizeof(*bcm
), GFP_KERNEL
);
49 skb_queue_head_init(&bcm
->txq
);
55 static int bcm_close(struct hci_uart
*hu
)
57 struct bcm_data
*bcm
= hu
->priv
;
61 skb_queue_purge(&bcm
->txq
);
62 kfree_skb(bcm
->rx_skb
);
69 static int bcm_flush(struct hci_uart
*hu
)
71 struct bcm_data
*bcm
= hu
->priv
;
75 skb_queue_purge(&bcm
->txq
);
80 static int bcm_setup(struct hci_uart
*hu
)
84 hu
->hdev
->set_bdaddr
= btbcm_set_bdaddr
;
86 return btbcm_setup_patchram(hu
->hdev
);
89 static const struct h4_recv_pkt bcm_recv_pkts
[] = {
90 { H4_RECV_ACL
, .recv
= hci_recv_frame
},
91 { H4_RECV_SCO
, .recv
= hci_recv_frame
},
92 { H4_RECV_EVENT
, .recv
= hci_recv_frame
},
95 static int bcm_recv(struct hci_uart
*hu
, const void *data
, int count
)
97 struct bcm_data
*bcm
= hu
->priv
;
99 if (!test_bit(HCI_UART_REGISTERED
, &hu
->flags
))
102 bcm
->rx_skb
= h4_recv_buf(hu
->hdev
, bcm
->rx_skb
, data
, count
,
103 bcm_recv_pkts
, ARRAY_SIZE(bcm_recv_pkts
));
104 if (IS_ERR(bcm
->rx_skb
)) {
105 int err
= PTR_ERR(bcm
->rx_skb
);
106 BT_ERR("%s: Frame reassembly failed (%d)", hu
->hdev
->name
, err
);
113 static int bcm_enqueue(struct hci_uart
*hu
, struct sk_buff
*skb
)
115 struct bcm_data
*bcm
= hu
->priv
;
117 BT_DBG("hu %p skb %p", hu
, skb
);
119 /* Prepend skb with frame type */
120 memcpy(skb_push(skb
, 1), &bt_cb(skb
)->pkt_type
, 1);
121 skb_queue_tail(&bcm
->txq
, skb
);
126 static struct sk_buff
*bcm_dequeue(struct hci_uart
*hu
)
128 struct bcm_data
*bcm
= hu
->priv
;
130 return skb_dequeue(&bcm
->txq
);
133 static const struct hci_uart_proto bcm_proto
= {
141 .enqueue
= bcm_enqueue
,
142 .dequeue
= bcm_dequeue
,
145 int __init
bcm_init(void)
147 return hci_uart_register_proto(&bcm_proto
);
150 int __exit
bcm_deinit(void)
152 return hci_uart_unregister_proto(&bcm_proto
);