From 6656fc810789b929ef1ce0a510b8a2cae93e84c2 Mon Sep 17 00:00:00 2001
From: Gary Bisson <gary.bisson@boundarydevices.com>
Date: Wed, 27 Dec 2017 11:51:23 +0100
Subject: [PATCH] hciattach_rome: force IBS to disabled in NVM

Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com>
---
 tools/hciattach_rome.c | 28 ++++++++++++----------------
 tools/hciattach_rome.h |  3 ++-
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/tools/hciattach_rome.c b/tools/hciattach_rome.c
index 6336bdc6b..b78155b22 100644
--- a/tools/hciattach_rome.c
+++ b/tools/hciattach_rome.c
@@ -957,7 +957,7 @@ int isSpeedValid(int speed, unsigned char *baud_rate)
 	return -1;
 }
 
-int rome_get_tlv_file(char *file_path)
+int rome_get_tlv_file(char *file_path, unsigned char baud_rate)
 {
 	FILE * pFile;
 	long fileSize;
@@ -1084,17 +1084,13 @@ int rome_get_tlv_file(char *file_path)
 #endif
 
 			if (nvm_ptr->tag_id == TAG_NUM_17) {
-				if ((ibs_value =
-				     get_value_from_config(FW_CONFIG_FILE_PATH, "IBS")) >= 0) {
-					if (ibs_value == FWCONF_IBS_DISABLE) {
-						nvm_byte_ptr[FWCONF_IBS_VAL_OFFSET] &=
-							(~(FWCONF_IBS_ENABLE <<
-							   FWCONF_IBS_VAL_BIT));
-					} else if (ibs_value == FWCONF_IBS_ENABLE) {
-						nvm_byte_ptr[FWCONF_IBS_VAL_OFFSET] |=
-							(FWCONF_IBS_ENABLE <<
-							 FWCONF_IBS_VAL_BIT);
-					}
+				PR_DBG("Forcing IBS to be disabled\n");
+				nvm_byte_ptr[FWCONF_IBS_VAL_OFFSET] &=
+					(~(FWCONF_IBS_ENABLE << FWCONF_IBS_VAL_BIT));
+				if (baud_rate != nvm_byte_ptr[FWCONF_BAUD_VAL_OFFSET]) {
+					PR_DBG("Change Vendor Baud from 0x%02x to 0x%02x\n",
+					       nvm_byte_ptr[FWCONF_BAUD_VAL_OFFSET], baud_rate);
+					nvm_byte_ptr[FWCONF_BAUD_VAL_OFFSET] = baud_rate;
 				}
 			}
 
@@ -1286,14 +1282,14 @@ int rome_tlv_dnld_req(int fd, int tlv_size)
 	return err;
 }
 
-int rome_download_tlv_file(int fd)
+int rome_download_tlv_file(int fd, unsigned char baud_rate)
 {
 	int tlv_size, err = -1;
 
 	/* Rampatch TLV file Downloading */
 	pdata_buffer = NULL;
 
-	if ((tlv_size = rome_get_tlv_file(rampatch_file_path)) < 0)
+	if ((tlv_size = rome_get_tlv_file(rampatch_file_path, baud_rate)) < 0)
 		goto error;
 
 	if ((err = rome_tlv_dnld_req(fd, tlv_size)) < 0)
@@ -1305,7 +1301,7 @@ int rome_download_tlv_file(int fd)
 	}
 
 	/* NVM TLV file Downloading */
-	if ((tlv_size = rome_get_tlv_file(nvm_file_path)) < 0)
+	if ((tlv_size = rome_get_tlv_file(nvm_file_path, baud_rate)) < 0)
 		goto error;
 
 	if ((err = rome_tlv_dnld_req(fd, tlv_size)) < 0)
@@ -1836,7 +1832,7 @@ int qca_soc_init(int fd, int speed, char *bdaddr)
 		}
 
 		/* Donwload TLV files (rampatch, NVM) */
-		err = rome_download_tlv_file(fd);
+		err = rome_download_tlv_file(fd, baud_rate);
 		if (err < 0) {
 			fprintf(stderr, "%s: Download TLV file failed!\n", __FUNCTION__);
 			ret = -1;
diff --git a/tools/hciattach_rome.h b/tools/hciattach_rome.h
index 2f5930c99..1ea9d865b 100644
--- a/tools/hciattach_rome.h
+++ b/tools/hciattach_rome.h
@@ -201,11 +201,12 @@ typedef struct
 #define FWCONF_PCM_MASTER           0
 #define FWCONF_PCM_ROLE_BIT_OFFSET  4
 
-/* FW IBS Configuration */
+/* FW HCI Transport Layer Configuration */
 #define FWCONF_IBS_DISABLE          (0)
 #define FWCONF_IBS_ENABLE           (1)
 #define FWCONF_IBS_VAL_BIT          (7)
 #define FWCONF_IBS_VAL_OFFSET       (0)
+#define FWCONF_BAUD_VAL_OFFSET      (2)
 
 /* FW DEEP SLEEP Configuration */
 #define FWCONF_DEEP_SLEEP_DISABLE       0
