Add audio gain api.

Change-Id: I4c87104a1d9d92989d986f5f450ba8f203ec4460
diff --git a/mbtk/mbtk_lib/src/mbtk_audio.c b/mbtk/mbtk_lib/src/mbtk_audio.c
index bdf3a77..2b9988a 100755
--- a/mbtk/mbtk_lib/src/mbtk_audio.c
+++ b/mbtk/mbtk_lib/src/mbtk_audio.c
@@ -43,6 +43,8 @@
 #define AUDIO_UBUS_LOOPBACK_EN          "loopback_enable"
 #define AUDIO_UBUS_LOOPBACK_DIS         "loopback_disable"
 #define AUDIO_UBUS_AUDIO_GAIN_SET       "audio_gain_set"
+#define AUDIO_UBUS_AUDIO_REG_SET       "audio_reg_set"
+
 
 // #define DEBUG 1
 
@@ -1010,9 +1012,8 @@
     }
 }
 
-// TX : 0-10; RX : 11
-#define MBTK_AUDIO_GAIN_NUM 12
-void mbtk_audio_ubus_gain_set(uint8 *gain, int gain_num)
+#define MBTK_AUDIO_GAIN_NUM 11
+void mbtk_audio_ubus_gain_set(mbtk_audio_gain_type_enum type, uint16 *gain, int gain_num)
 {
     int rc = 0;
     struct ubus_request *req = NULL;
@@ -1023,24 +1024,33 @@
         printf("leave %s: lack of memory\n", __FUNCTION__);
         return;
     }
-    if(gain_num != MBTK_AUDIO_GAIN_NUM) {
-        printf("gain_num error.\n");
+    if((type == AUDIO_GAIN_TYPE_RX_CODECGAIN || type == AUDIO_GAIN_TYPE_RX_DSPGAIN)
+        && gain_num != MBTK_AUDIO_GAIN_NUM) {
+        printf("gain_num error:type = %d, gain_name = %d.\n", type, gain_num);
+        return;
+    }
+    if((type == AUDIO_GAIN_TYPE_TX_CODECGAIN || type == AUDIO_GAIN_TYPE_TX_DSPGAIN)
+        && gain_num != 1) {
+        printf("gain_num error:type = %d, gain_name = %d.\n", type, gain_num);
         return;
     }
     memset(req, 0, sizeof(struct ubus_request));
     blob_buf_init(&audio_cm_b, 0);
 
-    char name[20];
-    int i = 0;
-    // Set TX
-    for(; i < gain_num - 1; i++) {
-        memset(name, 0x0, 20);
-        sprintf(name, "volume_gain_%d", i);
-        blobmsg_add_u8(&audio_cm_b, name, gain[i]);
-    }
-
     // Set RX
-    blobmsg_add_u8(&audio_cm_b, "volume_gain_rx", gain[i]);
+    blobmsg_add_u16(&audio_cm_b, "volume_gain_type", type);
+    if(type == AUDIO_GAIN_TYPE_TX_CODECGAIN || type == AUDIO_GAIN_TYPE_TX_DSPGAIN) {
+        blobmsg_add_u16(&audio_cm_b, "volume_gain_0", gain[0]);
+    } else {
+        char name[20];
+        int i = 0;
+        // Set TX
+        for(; i < gain_num; i++) {
+            memset(name, 0x0, 20);
+            sprintf(name, "volume_gain_%d", i);
+            blobmsg_add_u16(&audio_cm_b, name, gain[i]);
+        }
+    }
 
 #if 1
     if ((rc = ubus_invoke_async(mbtk_audio_ubus_db->ctx, mbtk_audio_ubus_db->audioif_request_id, AUDIO_UBUS_AUDIO_GAIN_SET, audio_cm_b.head, req)) != UBUS_STATUS_OK)
@@ -1067,6 +1077,47 @@
 #endif
 }
 
+void mbtk_audio_ubus_reg_set(int reg_addr, int reg_value)
+{
+    int rc = 0;
+    struct ubus_request *req = NULL;
+
+    req = (struct ubus_request *)malloc(sizeof(struct ubus_request));
+    if (req == NULL)
+    {
+        printf("leave %s: lack of memory\n", __FUNCTION__);
+        return;
+    }
+
+    memset(req, 0, sizeof(struct ubus_request));
+    blob_buf_init(&audio_cm_b, 0);
+    blobmsg_add_u32(&audio_cm_b, "reg_addr", reg_addr);
+    blobmsg_add_u32(&audio_cm_b, "reg_value", reg_value);
+
+#if 1
+    if ((rc = ubus_invoke_async(mbtk_audio_ubus_db->ctx, mbtk_audio_ubus_db->audioif_request_id, AUDIO_UBUS_AUDIO_REG_SET, audio_cm_b.head, req)) != UBUS_STATUS_OK)
+    {
+        free(req);
+        printf("%s, ubus_invoke_async volume set failed: %s\n", __FUNCTION__,  ubus_strerror(rc));
+    }
+    else
+    {
+        printf("%s: ubus_invoke_async success\n", __FUNCTION__);
+        req->complete_cb = mbtk_ubus_complete_cb;
+        ubus_complete_request_async(mbtk_audio_ubus_db->ctx, req);
+    }
+#else
+    if ((rc = ubus_invoke(APP_ctx, APP_audio_request_id, AUDIO_UBUS_AUDIO_GAIN_SET, audio_cm_b.head, NULL, 0, 0)) != UBUS_STATUS_OK)
+    {
+        printf("%s, ubus_invoke_async volume set failed: %s\n", __FUNCTION__, ubus_strerror(rc));
+    }
+    else
+    {
+        printf("%s: ubus_invoke_async success\n", __FUNCTION__);
+    }
+    free(req);
+#endif
+}
 
 static void audio_volume_get_data_cb (struct ubus_request *req, int type, struct blob_attr *msg)
 {