2 * Bluetooth supports for Qualcomm Atheros chips
4 * Copyright (c) 2015 The Linux Foundation. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/module.h>
21 #include <linux/firmware.h>
23 #include <net/bluetooth/bluetooth.h>
24 #include <net/bluetooth/hci_core.h>
30 static int rome_patch_ver_req(struct hci_dev
*hdev
, u32
*rome_version
)
33 struct edl_event_hdr
*edl
;
34 struct rome_version
*ver
;
38 BT_DBG("%s: ROME Patch Version Request", hdev
->name
);
40 cmd
= EDL_PATCH_VER_REQ_CMD
;
41 skb
= __hci_cmd_sync_ev(hdev
, EDL_PATCH_CMD_OPCODE
, EDL_PATCH_CMD_LEN
,
42 &cmd
, HCI_VENDOR_PKT
, HCI_INIT_TIMEOUT
);
45 BT_ERR("%s: Failed to read version of ROME (%d)", hdev
->name
,
50 if (skb
->len
!= sizeof(*edl
) + sizeof(*ver
)) {
51 BT_ERR("%s: Version size mismatch len %d", hdev
->name
,
57 edl
= (struct edl_event_hdr
*)(skb
->data
);
59 BT_ERR("%s: TLV with no header", hdev
->name
);
64 if (edl
->cresp
!= EDL_CMD_REQ_RES_EVT
||
65 edl
->rtype
!= EDL_APP_VER_RES_EVT
) {
66 BT_ERR("%s: Wrong packet received %d %d", hdev
->name
,
67 edl
->cresp
, edl
->rtype
);
72 ver
= (struct rome_version
*)(edl
->data
);
74 BT_DBG("%s: Product:0x%08x", hdev
->name
, le32_to_cpu(ver
->product_id
));
75 BT_DBG("%s: Patch :0x%08x", hdev
->name
, le16_to_cpu(ver
->patch_ver
));
76 BT_DBG("%s: ROM :0x%08x", hdev
->name
, le16_to_cpu(ver
->rome_ver
));
77 BT_DBG("%s: SOC :0x%08x", hdev
->name
, le32_to_cpu(ver
->soc_id
));
79 /* ROME chipset version can be decided by patch and SoC
80 * version, combination with upper 2 bytes from SoC
81 * and lower 2 bytes from patch will be used.
83 *rome_version
= (le32_to_cpu(ver
->soc_id
) << 16) |
84 (le16_to_cpu(ver
->rome_ver
) & 0x0000ffff);
92 static int rome_reset(struct hci_dev
*hdev
)
97 BT_DBG("%s: ROME HCI_RESET", hdev
->name
);
99 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
102 BT_ERR("%s: Reset failed (%d)", hdev
->name
, err
);
111 static void rome_tlv_check_data(struct rome_config
*config
,
112 const struct firmware
*fw
)
118 struct tlv_type_hdr
*tlv
;
119 struct tlv_type_patch
*tlv_patch
;
120 struct tlv_type_nvm
*tlv_nvm
;
122 tlv
= (struct tlv_type_hdr
*)fw
->data
;
124 type_len
= le32_to_cpu(tlv
->type_len
);
125 length
= (type_len
>> 8) & 0x00ffffff;
127 BT_DBG("TLV Type\t\t : 0x%x", type_len
& 0x000000ff);
128 BT_DBG("Length\t\t : %d bytes", length
);
130 config
->dnld_mode
= ROME_SKIP_EVT_NONE
;
132 switch (config
->type
) {
134 tlv_patch
= (struct tlv_type_patch
*)tlv
->data
;
136 /* For Rome version 1.1 to 3.1, all segment commands
137 * are acked by a vendor specific event (VSE).
138 * For Rome >= 3.2, the download mode field indicates
139 * if VSE is skipped by the controller.
140 * In case VSE is skipped, only the last segment is acked.
142 config
->dnld_mode
= tlv_patch
->download_mode
;
144 BT_DBG("Total Length : %d bytes",
145 le32_to_cpu(tlv_patch
->total_size
));
146 BT_DBG("Patch Data Length : %d bytes",
147 le32_to_cpu(tlv_patch
->data_length
));
148 BT_DBG("Signing Format Version : 0x%x",
149 tlv_patch
->format_version
);
150 BT_DBG("Signature Algorithm : 0x%x",
151 tlv_patch
->signature
);
152 BT_DBG("Download mode : 0x%x",
153 tlv_patch
->download_mode
);
154 BT_DBG("Reserved : 0x%x",
155 tlv_patch
->reserved1
);
156 BT_DBG("Product ID : 0x%04x",
157 le16_to_cpu(tlv_patch
->product_id
));
158 BT_DBG("Rom Build Version : 0x%04x",
159 le16_to_cpu(tlv_patch
->rom_build
));
160 BT_DBG("Patch Version : 0x%04x",
161 le16_to_cpu(tlv_patch
->patch_version
));
162 BT_DBG("Reserved : 0x%x",
163 le16_to_cpu(tlv_patch
->reserved2
));
164 BT_DBG("Patch Entry Address : 0x%x",
165 le32_to_cpu(tlv_patch
->entry
));
171 while (idx
< length
) {
172 tlv_nvm
= (struct tlv_type_nvm
*)(data
+ idx
);
174 tag_id
= le16_to_cpu(tlv_nvm
->tag_id
);
175 tag_len
= le16_to_cpu(tlv_nvm
->tag_len
);
177 /* Update NVM tags as needed */
180 /* HCI transport layer parameters
181 * enabling software inband sleep
182 * onto controller side.
184 tlv_nvm
->data
[0] |= 0x80;
187 tlv_nvm
->data
[2] = config
->user_baud_rate
;
191 case EDL_TAG_ID_DEEP_SLEEP
:
193 * enabling deep sleep feature on controller.
195 tlv_nvm
->data
[0] |= 0x01;
200 idx
+= (sizeof(u16
) + sizeof(u16
) + 8 + tag_len
);
205 BT_ERR("Unknown TLV type %d", config
->type
);
210 static int rome_tlv_send_segment(struct hci_dev
*hdev
, int seg_size
,
211 const u8
*data
, enum rome_tlv_dnld_mode mode
)
214 struct edl_event_hdr
*edl
;
215 struct tlv_seg_resp
*tlv_resp
;
216 u8 cmd
[MAX_SIZE_PER_TLV_SEGMENT
+ 2];
219 cmd
[0] = EDL_PATCH_TLV_REQ_CMD
;
221 memcpy(cmd
+ 2, data
, seg_size
);
223 if (mode
== ROME_SKIP_EVT_VSE_CC
|| mode
== ROME_SKIP_EVT_VSE
)
224 return __hci_cmd_send(hdev
, EDL_PATCH_CMD_OPCODE
, seg_size
+ 2,
227 skb
= __hci_cmd_sync_ev(hdev
, EDL_PATCH_CMD_OPCODE
, seg_size
+ 2, cmd
,
228 HCI_VENDOR_PKT
, HCI_INIT_TIMEOUT
);
231 BT_ERR("%s: Failed to send TLV segment (%d)", hdev
->name
, err
);
235 if (skb
->len
!= sizeof(*edl
) + sizeof(*tlv_resp
)) {
236 BT_ERR("%s: TLV response size mismatch", hdev
->name
);
241 edl
= (struct edl_event_hdr
*)(skb
->data
);
243 BT_ERR("%s: TLV with no header", hdev
->name
);
248 tlv_resp
= (struct tlv_seg_resp
*)(edl
->data
);
250 if (edl
->cresp
!= EDL_CMD_REQ_RES_EVT
||
251 edl
->rtype
!= EDL_TVL_DNLD_RES_EVT
|| tlv_resp
->result
!= 0x00) {
252 BT_ERR("%s: TLV with error stat 0x%x rtype 0x%x (0x%x)",
253 hdev
->name
, edl
->cresp
, edl
->rtype
, tlv_resp
->result
);
263 static int rome_download_firmware(struct hci_dev
*hdev
,
264 struct rome_config
*config
)
266 const struct firmware
*fw
;
268 int ret
, remain
, i
= 0;
270 bt_dev_info(hdev
, "ROME Downloading %s", config
->fwname
);
272 ret
= request_firmware(&fw
, config
->fwname
, &hdev
->dev
);
274 BT_ERR("%s: Failed to request file: %s (%d)", hdev
->name
,
275 config
->fwname
, ret
);
279 rome_tlv_check_data(config
, fw
);
284 int segsize
= min(MAX_SIZE_PER_TLV_SEGMENT
, remain
);
286 bt_dev_dbg(hdev
, "Send segment %d, size %d", i
++, segsize
);
289 /* The last segment is always acked regardless download mode */
290 if (!remain
|| segsize
< MAX_SIZE_PER_TLV_SEGMENT
)
291 config
->dnld_mode
= ROME_SKIP_EVT_NONE
;
293 ret
= rome_tlv_send_segment(hdev
, segsize
, segment
,
301 release_firmware(fw
);
306 int qca_set_bdaddr_rome(struct hci_dev
*hdev
, const bdaddr_t
*bdaddr
)
312 cmd
[0] = EDL_NVM_ACCESS_SET_REQ_CMD
;
313 cmd
[1] = 0x02; /* TAG ID */
314 cmd
[2] = sizeof(bdaddr_t
); /* size */
315 memcpy(cmd
+ 3, bdaddr
, sizeof(bdaddr_t
));
316 skb
= __hci_cmd_sync_ev(hdev
, EDL_NVM_ACCESS_OPCODE
, sizeof(cmd
), cmd
,
317 HCI_VENDOR_PKT
, HCI_INIT_TIMEOUT
);
320 BT_ERR("%s: Change address command failed (%d)",
329 EXPORT_SYMBOL_GPL(qca_set_bdaddr_rome
);
331 int qca_uart_setup_rome(struct hci_dev
*hdev
, uint8_t baudrate
)
334 struct rome_config config
;
337 BT_DBG("%s: ROME setup on UART", hdev
->name
);
339 config
.user_baud_rate
= baudrate
;
341 /* Get ROME version information */
342 err
= rome_patch_ver_req(hdev
, &rome_ver
);
343 if (err
< 0 || rome_ver
== 0) {
344 BT_ERR("%s: Failed to get version 0x%x", hdev
->name
, err
);
348 bt_dev_info(hdev
, "ROME controller version 0x%08x", rome_ver
);
350 /* Download rampatch file */
351 config
.type
= TLV_TYPE_PATCH
;
352 snprintf(config
.fwname
, sizeof(config
.fwname
), "qca/rampatch_%08x.bin",
354 err
= rome_download_firmware(hdev
, &config
);
356 BT_ERR("%s: Failed to download patch (%d)", hdev
->name
, err
);
360 /* Download NVM configuration */
361 config
.type
= TLV_TYPE_NVM
;
362 snprintf(config
.fwname
, sizeof(config
.fwname
), "qca/nvm_%08x.bin",
364 err
= rome_download_firmware(hdev
, &config
);
366 BT_ERR("%s: Failed to download NVM (%d)", hdev
->name
, err
);
370 /* Perform HCI reset */
371 err
= rome_reset(hdev
);
373 BT_ERR("%s: Failed to run HCI_RESET (%d)", hdev
->name
, err
);
377 bt_dev_info(hdev
, "ROME setup on UART is completed");
381 EXPORT_SYMBOL_GPL(qca_uart_setup_rome
);
383 MODULE_AUTHOR("Ben Young Tae Kim <ytkim@qca.qualcomm.com>");
384 MODULE_DESCRIPTION("Bluetooth support for Qualcomm Atheros family ver " VERSION
);
385 MODULE_VERSION(VERSION
);
386 MODULE_LICENSE("GPL");