From e6baaf14d9f6c2d96bcc720cb1c2e492c658e3a9 Mon Sep 17 00:00:00 2001
From: Gary Bisson <gary.bisson@boundarydevices.com>
Date: Thu, 28 Dec 2017 12:54:05 +0100
Subject: [PATCH] hciattach_rome: display ROM and TLV info by default

Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com>
---
 tools/hciattach_rome.c | 60 ++++++++++++++++++++++++--------------------------
 tools/hciattach_rome.h |  1 +
 2 files changed, 30 insertions(+), 31 deletions(-)

diff --git a/tools/hciattach_rome.c b/tools/hciattach_rome.c
index b78155b22..9a7f222c4 100644
--- a/tools/hciattach_rome.c
+++ b/tools/hciattach_rome.c
@@ -232,21 +232,21 @@ int get_vs_hci_event(unsigned char *rsp)
 		switch(rsp[RSP_TYPE_OFFSET]) {
 		case EDL_PATCH_VER_RES_EVT:
 		case EDL_APP_VER_RES_EVT:
-			PR_DBG("\t Current Product ID\t\t: 0x%08x\n",
+			PR_INFO("Current Product ID\t\t: 0x%08x\n",
 			       (unsigned int)(rsp[PATCH_PROD_ID_OFFSET +3] << 24 |
 					      rsp[PATCH_PROD_ID_OFFSET+2] << 16 |
 					      rsp[PATCH_PROD_ID_OFFSET+1] << 8 |
 					      rsp[PATCH_PROD_ID_OFFSET]  ));
 
 			/* Patch Version indicates FW patch version */
-			PR_DBG("\t Current Patch Version\t\t: 0x%04x\n",
+			PR_INFO("Current Patch Version\t\t: 0x%04x\n",
 			       (unsigned short)(rsp[PATCH_PATCH_VER_OFFSET + 1] << 8 |
 						rsp[PATCH_PATCH_VER_OFFSET] ));
 
 			/* ROM Build Version indicates ROM build version like 1.0/1.1/2.0 */
 			rome_ver = (int)(rsp[PATCH_ROM_BUILD_VER_OFFSET + 1] << 8 |
 					 rsp[PATCH_ROM_BUILD_VER_OFFSET]);
-			PR_DBG("\t Current ROM Build Version\t: 0x%04x\n", rome_ver);
+			PR_INFO("Current ROM Build Version\t: 0x%04x\n", rome_ver);
 
 			/* In case rome 1.0/1.1, there is no SOC ID version available */
 			if (paramlen - 10) {
@@ -254,7 +254,7 @@ int get_vs_hci_event(unsigned char *rsp)
 							rsp[PATCH_SOC_VER_OFFSET+2] << 16 |
 							rsp[PATCH_SOC_VER_OFFSET+1] << 8 |
 							rsp[PATCH_SOC_VER_OFFSET]);
-				PR_DBG("\t Current SOC Version\t\t: 0x%08x\n", soc_id);
+				PR_INFO("Current SOC Version\t\t: 0x%08x\n", soc_id);
 			}
 
 			/* Rome Chipset Version can be decided by Patch version and SOC version,
@@ -1019,30 +1019,31 @@ int rome_get_tlv_file(char *file_path, unsigned char baud_rate)
 	gtlv_dwndcfg = ptlv_header->tlv.patch.dwnd_cfg;
 
 	if (ptlv_header->tlv_type == TLV_TYPE_PATCH) {
-		PR_DBG("====================================================\n");
-		PR_DBG("TLV Type\t\t\t : 0x%x\n", ptlv_header->tlv_type);
-		PR_DBG("Length\t\t\t : %d bytes\n", (ptlv_header->tlv_length1) |
+		PR_INFO("====================================================\n");
+		PR_INFO("TLV Type               : 0x%x\n", ptlv_header->tlv_type);
+		PR_INFO("Length                 : %d bytes\n", (ptlv_header->tlv_length1) |
 		       (ptlv_header->tlv_length2 << 8) |
 		       (ptlv_header->tlv_length3 << 16));
-		PR_DBG("Total Length\t\t\t : %d bytes\n", ptlv_header->tlv.patch.tlv_data_len);
-		PR_DBG("Patch Data Length\t\t\t : %d bytes\n",ptlv_header->tlv.patch.tlv_patch_data_len);
-		PR_DBG("Signing Format Version\t : 0x%x\n", ptlv_header->tlv.patch.sign_ver);
-		PR_DBG("Signature Algorithm\t\t : 0x%x\n", ptlv_header->tlv.patch.sign_algorithm);
-		PR_DBG("Event Handling\t\t\t : 0x%x", ptlv_header->tlv.patch.dwnd_cfg);
-		PR_DBG("Reserved\t\t\t : 0x%x\n", ptlv_header->tlv.patch.reserved1);
-		PR_DBG("Product ID\t\t\t : 0x%04x\n", ptlv_header->tlv.patch.prod_id);
-		PR_DBG("Rom Build Version\t\t : 0x%04x\n", ptlv_header->tlv.patch.build_ver);
-		PR_DBG("Patch Version\t\t : 0x%04x\n", ptlv_header->tlv.patch.patch_ver);
-		PR_DBG("Reserved\t\t\t : 0x%x\n", ptlv_header->tlv.patch.reserved2);
-		PR_DBG("Patch Entry Address\t\t : 0x%x\n", (ptlv_header->tlv.patch.patch_entry_addr));
-		PR_DBG("====================================================\n");
+		PR_INFO("Total Length           : %d bytes\n", ptlv_header->tlv.patch.tlv_data_len);
+		PR_INFO("Patch Data Length      : %d bytes\n",ptlv_header->tlv.patch.tlv_patch_data_len);
+		PR_INFO("Signing Format Version : 0x%x\n", ptlv_header->tlv.patch.sign_ver);
+		PR_INFO("Signature Algorithm    : 0x%x\n", ptlv_header->tlv.patch.sign_algorithm);
+		PR_INFO("Event Handling         : 0x%x\n", ptlv_header->tlv.patch.dwnd_cfg);
+		PR_INFO("Reserved               : 0x%x\n", ptlv_header->tlv.patch.reserved1);
+		PR_INFO("Product ID             : 0x%04x\n", ptlv_header->tlv.patch.prod_id);
+		PR_INFO("Rom Build Version      : 0x%04x\n", ptlv_header->tlv.patch.build_ver);
+		PR_INFO("Patch Version          : 0x%04x\n", ptlv_header->tlv.patch.patch_ver);
+		PR_INFO("Reserved               : 0x%x\n", ptlv_header->tlv.patch.reserved2);
+		PR_INFO("Patch Entry Address    : 0x%x\n", (ptlv_header->tlv.patch.patch_entry_addr));
+		PR_INFO("====================================================\n");
 
 	} else if (ptlv_header->tlv_type == TLV_TYPE_NVM) {
-		PR_DBG("====================================================\n");
-		PR_DBG("TLV Type\t\t\t : 0x%x\n", ptlv_header->tlv_type);
-		PR_DBG("Length\t\t\t : %d bytes\n",  nvm_length = (ptlv_header->tlv_length1) |
-		       (ptlv_header->tlv_length2 << 8) |
-		       (ptlv_header->tlv_length3 << 16));
+		PR_INFO("====================================================\n");
+		PR_INFO("TLV Type               : 0x%x\n", ptlv_header->tlv_type);
+		PR_INFO("Length                 : %d bytes\n",  nvm_length =
+			(ptlv_header->tlv_length1) |
+			(ptlv_header->tlv_length2 << 8) |
+			(ptlv_header->tlv_length3 << 16));
 
 		if (nvm_length <= 0)
 			return readSize;
@@ -1062,7 +1063,7 @@ int rome_get_tlv_file(char *file_path, unsigned char baud_rate)
 			/* Write BD Address */
 			if (nvm_ptr->tag_id == TAG_NUM_2 && read_bd_address(bdaddr) == 0) {
 				memcpy(nvm_byte_ptr, bdaddr, 6);
-				PR_DBG("Overriding default BD ADDR with user"
+				PR_INFO("Overriding default BD ADDR with user"
 				       " programmed BD Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
 				       *nvm_byte_ptr, *(nvm_byte_ptr+1), *(nvm_byte_ptr+2),
 				       *(nvm_byte_ptr+3), *(nvm_byte_ptr+4), *(nvm_byte_ptr+5));
@@ -1071,7 +1072,7 @@ int rome_get_tlv_file(char *file_path, unsigned char baud_rate)
 			/* Remove it from NVM data */
 			if (nvm_ptr->tag_id == TAG_NUM_2) {
 				int nvm_size = nvm_ptr->tag_len + sizeof(tlv_nvm_hdr);
-				PR_DBG("Skip BD Address from NVM\n");
+				PR_INFO("Skip BD Address from NVM\n");
 				nvm_index += nvm_ptr->tag_len;
 				nvm_byte_ptr += nvm_ptr->tag_len;
 				memmove(nvm_ptr, nvm_byte_ptr, nvm_length - nvm_index);
@@ -1088,7 +1089,7 @@ int rome_get_tlv_file(char *file_path, unsigned char baud_rate)
 				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",
+					PR_INFO("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;
 				}
@@ -1144,7 +1145,7 @@ int rome_get_tlv_file(char *file_path, unsigned char baud_rate)
 			nvm_byte_ptr +=nvm_ptr->tag_len;
 		}
 
-		PR_DBG("====================================================\n");
+		PR_INFO("====================================================\n");
 
 	} else {
 		fprintf(stderr, "TLV Header type is unknown (%d) \n", ptlv_header->tlv_type);
@@ -1839,9 +1840,6 @@ int qca_soc_init(int fd, int speed, char *bdaddr)
 			goto error;
 		}
 
-		/* FW download complete, add some delay before updating baudrate */
-		usleep(20000);
-
 		/*
 		 * Overriding the baud rate value in NVM file with the user
 		 * requested baud rate, since default baud rate in NVM file is 3M.
diff --git a/tools/hciattach_rome.h b/tools/hciattach_rome.h
index 1ea9d865b..597743e0b 100644
--- a/tools/hciattach_rome.h
+++ b/tools/hciattach_rome.h
@@ -48,6 +48,7 @@
 #define USERIAL_OP_CLK_OFF     0x5442
 #endif
 
+#define PR_INFO(fmt, arg...) printf(fmt, ## arg)
 #ifdef DEBUG
     #define PR_DBG(fmt, arg...) printf(fmt, ## arg)
 #else
