diff options
author | Loic Poulain <loic.poulain@intel.com> | 2016-02-22 04:48:03 -0500 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2016-02-24 10:34:23 -0500 |
commit | 395174bb07c1dce58fbf2baa3a01bb69f5103c59 (patch) | |
tree | 6e262109fbaa63e8cf42711a51d08037ca926554 /drivers/bluetooth | |
parent | 4c23d8745731b1b54bb8eadfc42070d7f9893b46 (diff) |
Bluetooth: hci_uart: Add Intel/AG6xx support
This driver implements support for iBT2.1 Bluetooth controller embedded
in the AG620 communication combo. The controller needs to be configured
with bddata and can be patched with a binary patch file (pbn).
These operations are performed in manufacturing mode.
Signed-off-by: Loic Poulain <loic.poulain@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'drivers/bluetooth')
-rw-r--r-- | drivers/bluetooth/Kconfig | 11 | ||||
-rw-r--r-- | drivers/bluetooth/Makefile | 1 | ||||
-rw-r--r-- | drivers/bluetooth/hci_ag6xx.c | 326 | ||||
-rw-r--r-- | drivers/bluetooth/hci_ldisc.c | 6 | ||||
-rw-r--r-- | drivers/bluetooth/hci_uart.h | 8 |
5 files changed, 351 insertions, 1 deletions
diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index ec6af1595062..cf50fd2e96df 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig | |||
@@ -169,6 +169,17 @@ config BT_HCIUART_QCA | |||
169 | 169 | ||
170 | Say Y here to compile support for QCA protocol. | 170 | Say Y here to compile support for QCA protocol. |
171 | 171 | ||
172 | config BT_HCIUART_AG6XX | ||
173 | bool "Intel AG6XX protocol support" | ||
174 | depends on BT_HCIUART | ||
175 | select BT_HCIUART_H4 | ||
176 | select BT_INTEL | ||
177 | help | ||
178 | The Intel/AG6XX protocol support enables Bluetooth HCI over serial | ||
179 | port interface for Intel ibt 2.1 Bluetooth controllers. | ||
180 | |||
181 | Say Y here to compile support for Intel AG6XX protocol. | ||
182 | |||
172 | config BT_HCIBCM203X | 183 | config BT_HCIBCM203X |
173 | tristate "HCI BCM203x USB driver" | 184 | tristate "HCI BCM203x USB driver" |
174 | depends on USB | 185 | depends on USB |
diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile index 07c9cf381e5a..9c18939fc5c9 100644 --- a/drivers/bluetooth/Makefile +++ b/drivers/bluetooth/Makefile | |||
@@ -36,6 +36,7 @@ hci_uart-$(CONFIG_BT_HCIUART_3WIRE) += hci_h5.o | |||
36 | hci_uart-$(CONFIG_BT_HCIUART_INTEL) += hci_intel.o | 36 | hci_uart-$(CONFIG_BT_HCIUART_INTEL) += hci_intel.o |
37 | hci_uart-$(CONFIG_BT_HCIUART_BCM) += hci_bcm.o | 37 | hci_uart-$(CONFIG_BT_HCIUART_BCM) += hci_bcm.o |
38 | hci_uart-$(CONFIG_BT_HCIUART_QCA) += hci_qca.o | 38 | hci_uart-$(CONFIG_BT_HCIUART_QCA) += hci_qca.o |
39 | hci_uart-$(CONFIG_BT_HCIUART_AG6XX) += hci_ag6xx.o | ||
39 | hci_uart-objs := $(hci_uart-y) | 40 | hci_uart-objs := $(hci_uart-y) |
40 | 41 | ||
41 | ccflags-y += -D__CHECK_ENDIAN__ | 42 | ccflags-y += -D__CHECK_ENDIAN__ |
diff --git a/drivers/bluetooth/hci_ag6xx.c b/drivers/bluetooth/hci_ag6xx.c new file mode 100644 index 000000000000..ea65c2d089ed --- /dev/null +++ b/drivers/bluetooth/hci_ag6xx.c | |||
@@ -0,0 +1,326 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Bluetooth HCI UART driver for Intel/AG6xx devices | ||
4 | * | ||
5 | * Copyright (C) 2016 Intel Corporation | ||
6 | * | ||
7 | * | ||
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. | ||
12 | * | ||
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. | ||
17 | * | ||
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 | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/errno.h> | ||
26 | #include <linux/skbuff.h> | ||
27 | #include <linux/firmware.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/tty.h> | ||
30 | |||
31 | #include <net/bluetooth/bluetooth.h> | ||
32 | #include <net/bluetooth/hci_core.h> | ||
33 | |||
34 | #include "hci_uart.h" | ||
35 | #include "btintel.h" | ||
36 | |||
37 | struct ag6xx_data { | ||
38 | struct sk_buff *rx_skb; | ||
39 | struct sk_buff_head txq; | ||
40 | }; | ||
41 | |||
42 | struct pbn_entry { | ||
43 | __le32 addr; | ||
44 | __le32 plen; | ||
45 | __u8 data[0]; | ||
46 | } __packed; | ||
47 | |||
48 | static int ag6xx_open(struct hci_uart *hu) | ||
49 | { | ||
50 | struct ag6xx_data *ag6xx; | ||
51 | |||
52 | BT_DBG("hu %p", hu); | ||
53 | |||
54 | ag6xx = kzalloc(sizeof(*ag6xx), GFP_KERNEL); | ||
55 | if (!ag6xx) | ||
56 | return -ENOMEM; | ||
57 | |||
58 | skb_queue_head_init(&ag6xx->txq); | ||
59 | |||
60 | hu->priv = ag6xx; | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | static int ag6xx_close(struct hci_uart *hu) | ||
65 | { | ||
66 | struct ag6xx_data *ag6xx = hu->priv; | ||
67 | |||
68 | BT_DBG("hu %p", hu); | ||
69 | |||
70 | skb_queue_purge(&ag6xx->txq); | ||
71 | kfree_skb(ag6xx->rx_skb); | ||
72 | kfree(ag6xx); | ||
73 | |||
74 | hu->priv = NULL; | ||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | static int ag6xx_flush(struct hci_uart *hu) | ||
79 | { | ||
80 | struct ag6xx_data *ag6xx = hu->priv; | ||
81 | |||
82 | BT_DBG("hu %p", hu); | ||
83 | |||
84 | skb_queue_purge(&ag6xx->txq); | ||
85 | return 0; | ||
86 | } | ||
87 | |||
88 | static struct sk_buff *ag6xx_dequeue(struct hci_uart *hu) | ||
89 | { | ||
90 | struct ag6xx_data *ag6xx = hu->priv; | ||
91 | struct sk_buff *skb; | ||
92 | |||
93 | skb = skb_dequeue(&ag6xx->txq); | ||
94 | if (!skb) | ||
95 | return skb; | ||
96 | |||
97 | /* Prepend skb with frame type */ | ||
98 | memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); | ||
99 | return skb; | ||
100 | } | ||
101 | |||
102 | static int ag6xx_enqueue(struct hci_uart *hu, struct sk_buff *skb) | ||
103 | { | ||
104 | struct ag6xx_data *ag6xx = hu->priv; | ||
105 | |||
106 | skb_queue_tail(&ag6xx->txq, skb); | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | static const struct h4_recv_pkt ag6xx_recv_pkts[] = { | ||
111 | { H4_RECV_ACL, .recv = hci_recv_frame }, | ||
112 | { H4_RECV_SCO, .recv = hci_recv_frame }, | ||
113 | { H4_RECV_EVENT, .recv = hci_recv_frame }, | ||
114 | }; | ||
115 | |||
116 | static int ag6xx_recv(struct hci_uart *hu, const void *data, int count) | ||
117 | { | ||
118 | struct ag6xx_data *ag6xx = hu->priv; | ||
119 | |||
120 | if (!test_bit(HCI_UART_REGISTERED, &hu->flags)) | ||
121 | return -EUNATCH; | ||
122 | |||
123 | ag6xx->rx_skb = h4_recv_buf(hu->hdev, ag6xx->rx_skb, data, count, | ||
124 | ag6xx_recv_pkts, | ||
125 | ARRAY_SIZE(ag6xx_recv_pkts)); | ||
126 | if (IS_ERR(ag6xx->rx_skb)) { | ||
127 | int err = PTR_ERR(ag6xx->rx_skb); | ||
128 | bt_dev_err(hu->hdev, "Frame reassembly failed (%d)", err); | ||
129 | ag6xx->rx_skb = NULL; | ||
130 | return err; | ||
131 | } | ||
132 | |||
133 | return count; | ||
134 | } | ||
135 | |||
136 | static int intel_mem_write(struct hci_dev *hdev, u32 addr, u32 plen, | ||
137 | const void *data) | ||
138 | { | ||
139 | /* Can write a maximum of 247 bytes per HCI command. | ||
140 | * HCI cmd Header (3), Intel mem write header (6), data (247). | ||
141 | */ | ||
142 | while (plen > 0) { | ||
143 | struct sk_buff *skb; | ||
144 | u8 cmd_param[253], fragment_len = (plen > 247) ? 247 : plen; | ||
145 | __le32 leaddr = cpu_to_le32(addr); | ||
146 | |||
147 | memcpy(cmd_param, &leaddr, 4); | ||
148 | cmd_param[4] = 0; | ||
149 | cmd_param[5] = fragment_len; | ||
150 | memcpy(cmd_param + 6, data, fragment_len); | ||
151 | |||
152 | skb = __hci_cmd_sync(hdev, 0xfc8e, fragment_len + 6, cmd_param, | ||
153 | HCI_INIT_TIMEOUT); | ||
154 | if (IS_ERR(skb)) | ||
155 | return PTR_ERR(skb); | ||
156 | kfree_skb(skb); | ||
157 | |||
158 | plen -= fragment_len; | ||
159 | data += fragment_len; | ||
160 | addr += fragment_len; | ||
161 | } | ||
162 | |||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | static int ag6xx_setup(struct hci_uart *hu) | ||
167 | { | ||
168 | struct hci_dev *hdev = hu->hdev; | ||
169 | struct sk_buff *skb; | ||
170 | struct intel_version ver; | ||
171 | const struct firmware *fw; | ||
172 | const u8 *fw_ptr; | ||
173 | char fwname[64]; | ||
174 | bool patched = false; | ||
175 | int err; | ||
176 | |||
177 | err = btintel_enter_mfg(hdev); | ||
178 | if (err) | ||
179 | return err; | ||
180 | |||
181 | err = btintel_read_version(hdev, &ver); | ||
182 | if (err) | ||
183 | return err; | ||
184 | |||
185 | btintel_version_info(hdev, &ver); | ||
186 | |||
187 | /* The hardware platform number has a fixed value of 0x37 and | ||
188 | * for now only accept this single value. | ||
189 | */ | ||
190 | if (ver.hw_platform != 0x37) { | ||
191 | bt_dev_err(hdev, "Unsupported Intel hardware platform: 0x%X", | ||
192 | ver.hw_platform); | ||
193 | return -EINVAL; | ||
194 | } | ||
195 | |||
196 | /* Only the hardware variant iBT 2.1 (AG6XX) is supported by this | ||
197 | * firmware setup method. | ||
198 | */ | ||
199 | if (ver.hw_variant != 0x0a) { | ||
200 | bt_dev_err(hdev, "Unsupported Intel hardware variant: 0x%x", | ||
201 | ver.hw_variant); | ||
202 | return -EINVAL; | ||
203 | } | ||
204 | |||
205 | snprintf(fwname, sizeof(fwname), "intel/ibt-hw-%x.%x.bddata", | ||
206 | ver.hw_platform, ver.hw_variant); | ||
207 | |||
208 | err = request_firmware(&fw, fwname, &hdev->dev); | ||
209 | if (err < 0) { | ||
210 | bt_dev_err(hdev, "Failed to open Intel bddata file: %s (%d)", | ||
211 | fwname, err); | ||
212 | goto patch; | ||
213 | } | ||
214 | fw_ptr = fw->data; | ||
215 | |||
216 | bt_dev_info(hdev, "Applying bddata (%s)", fwname); | ||
217 | |||
218 | skb = __hci_cmd_sync_ev(hdev, 0xfc2f, fw->size, fw->data, | ||
219 | HCI_EV_CMD_STATUS, HCI_CMD_TIMEOUT); | ||
220 | if (IS_ERR(skb)) { | ||
221 | bt_dev_err(hdev, "Applying bddata failed (%ld)", PTR_ERR(skb)); | ||
222 | release_firmware(fw); | ||
223 | return PTR_ERR(skb); | ||
224 | } | ||
225 | kfree_skb(skb); | ||
226 | |||
227 | release_firmware(fw); | ||
228 | |||
229 | patch: | ||
230 | /* If there is no applied patch, fw_patch_num is always 0x00. In other | ||
231 | * cases, current firmware is already patched. No need to patch it. | ||
232 | */ | ||
233 | if (ver.fw_patch_num) { | ||
234 | bt_dev_info(hdev, "Device is already patched. patch num: %02x", | ||
235 | ver.fw_patch_num); | ||
236 | patched = true; | ||
237 | goto complete; | ||
238 | } | ||
239 | |||
240 | snprintf(fwname, sizeof(fwname), | ||
241 | "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.pbn", | ||
242 | ver.hw_platform, ver.hw_variant, ver.hw_revision, | ||
243 | ver.fw_variant, ver.fw_revision, ver.fw_build_num, | ||
244 | ver.fw_build_ww, ver.fw_build_yy); | ||
245 | |||
246 | err = request_firmware(&fw, fwname, &hdev->dev); | ||
247 | if (err < 0) { | ||
248 | bt_dev_err(hdev, "Failed to open Intel patch file: %s(%d)", | ||
249 | fwname, err); | ||
250 | goto complete; | ||
251 | } | ||
252 | fw_ptr = fw->data; | ||
253 | |||
254 | bt_dev_info(hdev, "Patching firmware file (%s)", fwname); | ||
255 | |||
256 | /* PBN patch file contains a list of binary patches to be applied on top | ||
257 | * of the embedded firmware. Each patch entry header contains the target | ||
258 | * address and patch size. | ||
259 | * | ||
260 | * Patch entry: | ||
261 | * | addr(le) | patch_len(le) | patch_data | | ||
262 | * | 4 Bytes | 4 Bytes | n Bytes | | ||
263 | * | ||
264 | * PBN file is terminated by a patch entry whose address is 0xffffffff. | ||
265 | */ | ||
266 | while (fw->size > fw_ptr - fw->data) { | ||
267 | struct pbn_entry *pbn = (void *)fw_ptr; | ||
268 | u32 addr, plen; | ||
269 | |||
270 | if (pbn->addr == 0xffffffff) { | ||
271 | bt_dev_info(hdev, "Patching complete"); | ||
272 | patched = true; | ||
273 | break; | ||
274 | } | ||
275 | |||
276 | addr = le32_to_cpu(pbn->addr); | ||
277 | plen = le32_to_cpu(pbn->plen); | ||
278 | |||
279 | if (fw->data + fw->size <= pbn->data + plen) { | ||
280 | bt_dev_info(hdev, "Invalid patch len (%d)", plen); | ||
281 | break; | ||
282 | } | ||
283 | |||
284 | bt_dev_info(hdev, "Patching %td/%zu", (fw_ptr - fw->data), | ||
285 | fw->size); | ||
286 | |||
287 | err = intel_mem_write(hdev, addr, plen, pbn->data); | ||
288 | if (err) { | ||
289 | bt_dev_err(hdev, "Patching failed"); | ||
290 | break; | ||
291 | } | ||
292 | |||
293 | fw_ptr = pbn->data + plen; | ||
294 | } | ||
295 | |||
296 | release_firmware(fw); | ||
297 | |||
298 | complete: | ||
299 | /* Exit manufacturing mode and reset */ | ||
300 | err = btintel_exit_mfg(hdev, true, patched); | ||
301 | |||
302 | return err; | ||
303 | } | ||
304 | |||
305 | static const struct hci_uart_proto ag6xx_proto = { | ||
306 | .id = HCI_UART_AG6XX, | ||
307 | .name = "AG6XX", | ||
308 | .manufacturer = 2, | ||
309 | .open = ag6xx_open, | ||
310 | .close = ag6xx_close, | ||
311 | .flush = ag6xx_flush, | ||
312 | .setup = ag6xx_setup, | ||
313 | .recv = ag6xx_recv, | ||
314 | .enqueue = ag6xx_enqueue, | ||
315 | .dequeue = ag6xx_dequeue, | ||
316 | }; | ||
317 | |||
318 | int __init ag6xx_init(void) | ||
319 | { | ||
320 | return hci_uart_register_proto(&ag6xx_proto); | ||
321 | } | ||
322 | |||
323 | int __exit ag6xx_deinit(void) | ||
324 | { | ||
325 | return hci_uart_unregister_proto(&ag6xx_proto); | ||
326 | } | ||
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index 73202624133b..c00168a5bb80 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c | |||
@@ -804,6 +804,9 @@ static int __init hci_uart_init(void) | |||
804 | #ifdef CONFIG_BT_HCIUART_QCA | 804 | #ifdef CONFIG_BT_HCIUART_QCA |
805 | qca_init(); | 805 | qca_init(); |
806 | #endif | 806 | #endif |
807 | #ifdef CONFIG_BT_HCIUART_AG6XX | ||
808 | ag6xx_init(); | ||
809 | #endif | ||
807 | 810 | ||
808 | return 0; | 811 | return 0; |
809 | } | 812 | } |
@@ -836,6 +839,9 @@ static void __exit hci_uart_exit(void) | |||
836 | #ifdef CONFIG_BT_HCIUART_QCA | 839 | #ifdef CONFIG_BT_HCIUART_QCA |
837 | qca_deinit(); | 840 | qca_deinit(); |
838 | #endif | 841 | #endif |
842 | #ifdef CONFIG_BT_HCIUART_AG6XX | ||
843 | ag6xx_deinit(); | ||
844 | #endif | ||
839 | 845 | ||
840 | /* Release tty registration of line discipline */ | 846 | /* Release tty registration of line discipline */ |
841 | err = tty_unregister_ldisc(N_HCI); | 847 | err = tty_unregister_ldisc(N_HCI); |
diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h index 82c92f1b65b4..4814ff08f427 100644 --- a/drivers/bluetooth/hci_uart.h +++ b/drivers/bluetooth/hci_uart.h | |||
@@ -35,7 +35,7 @@ | |||
35 | #define HCIUARTGETFLAGS _IOR('U', 204, int) | 35 | #define HCIUARTGETFLAGS _IOR('U', 204, int) |
36 | 36 | ||
37 | /* UART protocols */ | 37 | /* UART protocols */ |
38 | #define HCI_UART_MAX_PROTO 9 | 38 | #define HCI_UART_MAX_PROTO 10 |
39 | 39 | ||
40 | #define HCI_UART_H4 0 | 40 | #define HCI_UART_H4 0 |
41 | #define HCI_UART_BCSP 1 | 41 | #define HCI_UART_BCSP 1 |
@@ -46,6 +46,7 @@ | |||
46 | #define HCI_UART_INTEL 6 | 46 | #define HCI_UART_INTEL 6 |
47 | #define HCI_UART_BCM 7 | 47 | #define HCI_UART_BCM 7 |
48 | #define HCI_UART_QCA 8 | 48 | #define HCI_UART_QCA 8 |
49 | #define HCI_UART_AG6XX 9 | ||
49 | 50 | ||
50 | #define HCI_UART_RAW_DEVICE 0 | 51 | #define HCI_UART_RAW_DEVICE 0 |
51 | #define HCI_UART_RESET_ON_INIT 1 | 52 | #define HCI_UART_RESET_ON_INIT 1 |
@@ -182,3 +183,8 @@ int bcm_deinit(void); | |||
182 | int qca_init(void); | 183 | int qca_init(void); |
183 | int qca_deinit(void); | 184 | int qca_deinit(void); |
184 | #endif | 185 | #endif |
186 | |||
187 | #ifdef CONFIG_BT_HCIUART_AG6XX | ||
188 | int ag6xx_init(void); | ||
189 | int ag6xx_deinit(void); | ||
190 | #endif | ||