hikey960: Add hifi dsp audio example of increasing PCM Gain am: efa6b4d462 am: dc8a7c9945 am: 9342fac7e0
am: 6d263b83b0

Change-Id: I1a1491657807833a6358ad3f23bde74d548940ec
diff --git a/audio/audio_hw.c b/audio/audio_hw.c
index 33c569e..87fc4c6 100644
--- a/audio/audio_hw.c
+++ b/audio/audio_hw.c
@@ -40,6 +40,8 @@
 #include <hardware/audio_alsaops.h>
 #include <audio_effects/effect_aec.h>
 
+#include <sys/ioctl.h>
+#include <linux/audio_hifi.h>
 
 #define CARD_OUT 0
 #define PORT_CODEC 0
@@ -69,6 +71,7 @@
     struct alsa_stream_in *active_input;
     struct alsa_stream_out *active_output;
     bool mic_mute;
+    int hifi_dsp_fd;
 };
 
 struct alsa_stream_out {
@@ -249,6 +252,7 @@
     size_t frame_size = audio_stream_out_frame_size(stream);
     size_t out_frames = bytes / frame_size;
     int kernel_frames;
+    struct misc_io_pcm_buf_param pcmbuf;
 
     /* acquiring hw device mutex systematically is useful if a low priority thread is waiting
      * on the output stream mutex - e.g. executing select_mode() while holding the hw device
@@ -267,6 +271,15 @@
 
     pthread_mutex_unlock(&adev->lock);
 
+    if (adev->hifi_dsp_fd >= 0) {
+        pcmbuf.buf = (uint64_t)buffer;
+        pcmbuf.buf_size = bytes;
+        ret = ioctl(adev->hifi_dsp_fd, HIFI_MISC_IOCTL_PCM_GAIN, &pcmbuf);
+        if (ret) {
+            ALOGV("hifi_dsp: Error buffer processing: %d", errno);
+        }
+    }
+
     ret = pcm_mmap_write(out->pcm, buffer, out_frames * frame_size);
     if (ret == 0) {
         out->written += out_frames;
@@ -630,7 +643,11 @@
 
 static int adev_close(hw_device_t *device)
 {
+    struct alsa_audio_device *adev = (struct alsa_audio_device *)device;
+
     ALOGV("adev_close");
+    if (adev->hifi_dsp_fd >= 0)
+        close(adev->hifi_dsp_fd);
     free(device);
     return 0;
 }
@@ -676,6 +693,12 @@
 
     *device = &adev->hw_device.common;
 
+    adev->hifi_dsp_fd = open(HIFI_DSP_MISC_DRIVER, O_WRONLY, 0);
+    if (adev->hifi_dsp_fd < 0) {
+        ALOGW("hifi_dsp: Error opening device %d", errno);
+    } else {
+        ALOGI("hifi_dsp: Open device");
+    }
     return 0;
 }