Browse Source

btfmcodec: Enable Dynamic logging

This change will enable dynamic logging based on below
flags
Below bit has to be set to enable respective logging.
 * Bit 0: Error message.
 * Bit 1: Warning message.
 * Bit 2: Debug message.
 * Bit 3: Info message.
 * 0x08 is similar to 0x0F.
 * 0x04 is similar to 0x07.
 * 0x02 is similar to 0x03.
 * 0x03 is default log level for BTFM Codec.

Change-Id: Ia986a49f73d6144f2631936b8d02985d3ccf98d0
Signed-off-by: Balakrishna Godavarthi <[email protected]>
Balakrishna Godavarthi 2 years ago
parent
commit
8998587891
3 changed files with 37 additions and 10 deletions
  1. 11 0
      btfmcodec/btfm_codec.c
  2. 16 2
      btfmcodec/include/btfm_codec.h
  3. 10 8
      btfmcodec/include/btfm_codec_pkt.h

+ 11 - 0
btfmcodec/btfm_codec.c

@@ -23,6 +23,7 @@ static dev_t dev_major;
 struct btfmcodec_data *btfmcodec;
 struct device_driver driver = {.name = "btfmcodec-driver", .owner = THIS_MODULE};
 struct btfmcodec_char_device *btfmcodec_dev;
+
 #define cdev_to_btfmchardev(_cdev) container_of(_cdev, struct btfmcodec_char_device, cdev)
 #define MIN_PKT_LEN  0x9
 
@@ -214,6 +215,16 @@ static void btfmcodec_dev_rxwork(struct work_struct *work)
 				status);
 			wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]);
 			break;
+		case BTM_BTFMCODEC_CTRL_LOG_LVL_IND:
+			if (len == BTM_LOG_LVL_IND_LEN) {
+				log_lvl = skb->data[0];
+			} else {
+				BTFMCODEC_ERR("wrong packet format with len:%d", len);
+			}
+			BTFMCODEC_INFO("Rx BTM_BTFMCODEC_CTRL_LOG_LVL_IND status:%d",
+					log_lvl);
+			wake_up_interruptible(&btfmcodec_dev->rsp_wait_q[idx]);
+			break;
 		default:
 			BTFMCODEC_ERR("wrong opcode:%08x", opcode);
 		}

+ 16 - 2
btfmcodec/include/btfm_codec.h

@@ -13,10 +13,24 @@
 #include <linux/skbuff.h>
 #include "btfm_codec_hw_interface.h"
 
-#define BTFMCODEC_DBG(fmt, arg...)  pr_err("%s: " fmt "\n", __func__, ## arg)
-#define BTFMCODEC_INFO(fmt, arg...) pr_err("%s: " fmt "\n", __func__, ## arg)
+#define BTM_BTFMCODEC_DEFAULT_LOG_LVL        0x03
+#define BTM_BTFMCODEC_DEBUG_LOG_LVL          0x04
+#define BTM_BTFMCODEC_INFO_LOG_LVL           0x08
+
+static uint8_t log_lvl = BTM_BTFMCODEC_DEFAULT_LOG_LVL;
+
 #define BTFMCODEC_ERR(fmt, arg...)  pr_err("%s: " fmt "\n", __func__, ## arg)
 #define BTFMCODEC_WARN(fmt, arg...) pr_warn("%s: " fmt "\n", __func__, ## arg)
+#define BTFMCODEC_DBG(fmt, arg...)  { if(log_lvl >= BTM_BTFMCODEC_DEBUG_LOG_LVL) \
+	                                pr_err("%s: " fmt "\n", __func__, ## arg); \
+				      else \
+	                                pr_debug("%s: " fmt "\n", __func__, ## arg); \
+	                            }
+#define BTFMCODEC_INFO(fmt, arg...) { if(log_lvl >= BTM_BTFMCODEC_INFO_LOG_LVL) \
+					pr_err("%s: " fmt "\n", __func__, ## arg);\
+				      else \
+					pr_info("%s: " fmt "\n", __func__, ## arg);\
+				    }
 
 #define DEVICE_NAME_MAX_LEN	64
 

+ 10 - 8
btfmcodec/include/btfm_codec_pkt.h

@@ -32,14 +32,15 @@ struct btm_ctrl_pkt {
 	uint8_t status;
 }__attribute__((packed));
 
-#define	BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_REQ		0x50000000
-#define BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_RSP 		0x50000001
-#define BTM_BTFMCODEC_MASTER_CONFIG_REQ			            0x50000002
-#define BTM_BTFMCODEC_MASTER_CONFIG_RSP			            0x50000003
-#define BTM_BTFMCODEC_MASTER_SHUTDOWN_REQ			        0x50000004
-#define BTM_BTFMCODEC_CTRL_MASTER_SHUTDOWN_RSP			    0x50000005
-#define BTM_BTFMCODEC_BEARER_SWITCH_IND			            0x58000001
-#define BTM_BTFMCODEC_TRANSPORT_SWITCH_FAILED_IND		    0x58000002
+#define BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_REQ           0x50000000
+#define BTM_BTFMCODEC_PREPARE_AUDIO_BEARER_SWITCH_RSP           0x50000001
+#define BTM_BTFMCODEC_MASTER_CONFIG_REQ                         0x50000002
+#define BTM_BTFMCODEC_MASTER_CONFIG_RSP                         0x50000003
+#define BTM_BTFMCODEC_MASTER_SHUTDOWN_REQ                       0x50000004
+#define BTM_BTFMCODEC_CTRL_MASTER_SHUTDOWN_RSP                  0x50000005
+#define BTM_BTFMCODEC_BEARER_SWITCH_IND                         0x58000001
+#define BTM_BTFMCODEC_TRANSPORT_SWITCH_FAILED_IND               0x58000002
+#define BTM_BTFMCODEC_CTRL_LOG_LVL_IND                          0x58000004
 
 #define BTM_MASTER_CONFIG_REQ_LEN			13
 #define BTM_MASTER_CONFIG_RSP_TIMEOUT			5000
@@ -49,6 +50,7 @@ struct btm_ctrl_pkt {
 #define BTM_MASTER_SHUTDOWN_REQ_LEN			1
 #define BTM_PREPARE_AUDIO_BEARER_SWITCH_REQ_LEN		1
 #define BTM_BEARER_SWITCH_IND_LEN			1
+#define BTM_LOG_LVL_IND_LEN                             1
 
 enum rx_status {
 	/* Waiting for response */