summaryrefslogtreecommitdiffstats
path: root/exynos/multimedia/codecs/audio/exynos4/srp/ulp
diff options
context:
space:
mode:
authorcodeworkx <daniel.hillenbrand@codeworkx.de>2012-05-20 12:00:36 +0200
committercodeworkx <daniel.hillenbrand@codeworkx.de>2012-05-20 12:00:36 +0200
commit62f02ba4f4b7b561aa15408ebd9951600bdd71aa (patch)
treeac05dc645945a58edbc26e96df1a78ac16f27706 /exynos/multimedia/codecs/audio/exynos4/srp/ulp
parente54debb12ecdf92d12acab00a261c0c5a6ef1d64 (diff)
downloadandroid_hardware_samsung-62f02ba4f4b7b561aa15408ebd9951600bdd71aa.tar.gz
android_hardware_samsung-62f02ba4f4b7b561aa15408ebd9951600bdd71aa.tar.bz2
android_hardware_samsung-62f02ba4f4b7b561aa15408ebd9951600bdd71aa.zip
exynos: reorganized and updated from insignal
Changes needed on exynos4210 devices: libcsc -> libseccscapi libswconverter -> remove TARGET_HAL_PATH := hardware/samsung/exynos4/hal TARGET_OMX_PATH := hardware/samsung/exynos/multimedia/openmax $(call inherit-product, hardware/samsung/exynos4210.mk) Change-Id: Ic59ef95b85ef37b3f38fb36cf6a364a5414685ee
Diffstat (limited to 'exynos/multimedia/codecs/audio/exynos4/srp/ulp')
-rw-r--r--exynos/multimedia/codecs/audio/exynos4/srp/ulp/Android.mk23
-rw-r--r--exynos/multimedia/codecs/audio/exynos4/srp/ulp/include/srp_api.h55
-rw-r--r--exynos/multimedia/codecs/audio/exynos4/srp/ulp/include/srp_api_ctrl.h25
-rw-r--r--exynos/multimedia/codecs/audio/exynos4/srp/ulp/include/srp_ioctl.h66
-rw-r--r--exynos/multimedia/codecs/audio/exynos4/srp/ulp/src/srp_api.c381
-rw-r--r--exynos/multimedia/codecs/audio/exynos4/srp/ulp/src/srp_api_ctrl.c331
6 files changed, 881 insertions, 0 deletions
diff --git a/exynos/multimedia/codecs/audio/exynos4/srp/ulp/Android.mk b/exynos/multimedia/codecs/audio/exynos4/srp/ulp/Android.mk
new file mode 100644
index 0000000..5b1d397
--- /dev/null
+++ b/exynos/multimedia/codecs/audio/exynos4/srp/ulp/Android.mk
@@ -0,0 +1,23 @@
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ src/srp_api.c \
+ src/srp_api_ctrl.c
+
+LOCAL_MODULE := libsrpapi
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_ARM_MODE := arm
+
+LOCAL_STATIC_LIBRARIES :=
+
+LOCAL_SHARED_LIBRARIES :=
+
+LOCAL_COPY_HEADERS := \
+ include/srp_api.h \
+ include/srp_api_ctrl.h \
+ include/srp_ioctl.h
+
+include $(BUILD_STATIC_LIBRARY)
diff --git a/exynos/multimedia/codecs/audio/exynos4/srp/ulp/include/srp_api.h b/exynos/multimedia/codecs/audio/exynos4/srp/ulp/include/srp_api.h
new file mode 100644
index 0000000..74598e5
--- /dev/null
+++ b/exynos/multimedia/codecs/audio/exynos4/srp/ulp/include/srp_api.h
@@ -0,0 +1,55 @@
+#ifndef __SRP_API_H__
+#define __SRP_API_H__
+
+#include "srp_ioctl.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int SRP_Create(int block_mode);
+int SRP_Init(unsigned int ibuf_size);
+int SRP_Decode(void *buff, int size_byte);
+int SRP_Send_EOS(void);
+int SRP_Resume_EOS(void);
+int SRP_Pause(void);
+int SRP_Stop(void);
+int SRP_Flush(void);
+int SRP_SetParams(int id, unsigned long val);
+int SRP_GetParams(int id, unsigned long *pval);
+int SRP_Deinit(void);
+int SRP_Terminate(void);
+int SRP_IsOpen(void);
+
+#define SRP_DEV_NAME "dev/srp"
+
+#define SRP_INIT_BLOCK_MODE 0
+#define SRP_INIT_NONBLOCK_MODE 1
+
+#define SRP_PENDING_STATE_RUNNING 0
+#define SRP_PENDING_STATE_PENDING 1
+
+#define SRP_ERROR_LOSTSYNC 0x00101
+#define SRP_ERROR_BADLAYER 0x00102
+#define SRP_ERROR_BADBITRATE 0x00103
+#define SRP_ERROR_BADSAMPLERATE 0x00104
+#define SRP_ERROR_BADEMPHASIS 0x00105
+
+#define SRP_ERROR_BADCRC 0x00201
+#define SRP_ERROR_BADBITALLOC 0x00211
+#define SRP_ERROR_BADBADSCALEFACTOR 0x00221
+#define SRP_ERROR_BADFRAMELEN 0x00231
+#define SRP_ERROR_BADBIGVALUES 0x00232
+#define SRP_ERROR_BADBLOCKTYPE 0x00233
+#define SRP_ERROR_BADSCFSI 0x00234
+#define SRP_ERROR_BADDATAPTR 0x00235
+#define SRP_ERROR_BADPART3LEN 0x00236
+#define SRP_ERROR_BADHUFFTABLE 0x00237
+#define SRP_ERROR_BADHUFFDATA 0x00238
+#define SRP_ERROR_BADSTEREO 0x00239
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*__SRP_API_H__ */
diff --git a/exynos/multimedia/codecs/audio/exynos4/srp/ulp/include/srp_api_ctrl.h b/exynos/multimedia/codecs/audio/exynos4/srp/ulp/include/srp_api_ctrl.h
new file mode 100644
index 0000000..3b17acf
--- /dev/null
+++ b/exynos/multimedia/codecs/audio/exynos4/srp/ulp/include/srp_api_ctrl.h
@@ -0,0 +1,25 @@
+#ifndef __SRP_API_CTRL_H__
+#define __SRP_API_CTRL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SRP_CTRL_DEV_NAME "dev/srp_ctrl"
+
+int SRP_Ctrl_Set_Effect(int effect); /* test only */
+int SRP_Ctrl_Enable_Effect(int on);
+int SRP_Ctrl_Set_Effect_Def(unsigned long effect_def);
+int SRP_Ctrl_Set_Effect_EQ_User(unsigned long eq_user);
+int SRP_Ctrl_Set_Pcm_Dump(int on);
+int SRP_Ctrl_Get_Pcm_Dump_State(void);
+int SRP_Ctrl_Set_Gain(float value);
+int SRP_Ctrl_Get_Running_Stat(void);
+int SRP_Ctrl_Get_Open_Stat(void);
+short *SRP_Ctrl_Get_Pcm(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SRP_API_CTRL_H__ */
diff --git a/exynos/multimedia/codecs/audio/exynos4/srp/ulp/include/srp_ioctl.h b/exynos/multimedia/codecs/audio/exynos4/srp/ulp/include/srp_ioctl.h
new file mode 100644
index 0000000..a20b1ac
--- /dev/null
+++ b/exynos/multimedia/codecs/audio/exynos4/srp/ulp/include/srp_ioctl.h
@@ -0,0 +1,66 @@
+#ifndef __SRP_IOCTL_H__
+#define __SRP_IOCTL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* constants for srp device node */
+#define SRP_INIT (0x10000)
+#define SRP_DEINIT (0x10001)
+
+#define SRP_PAUSE (0x20000)
+#define SRP_STOP (0x20001)
+#define SRP_FLUSH (0x20002)
+#define SRP_WAIT_EOS (0x20003)
+#define SRP_EFFECT (0x20004)
+#define SRP_SEND_EOS (0x20005)
+#define SRP_RESUME_EOS (0x20006)
+
+#define SRP_PENDING_STATE (0x30000)
+#define SRP_ERROR_STATE (0x30001)
+#define SRP_DECODED_FRAME_NO (0x30002)
+#define SRP_DECODED_ONE_FRAME_SIZE (0x30003)
+#define SRP_DECODED_FRAME_SIZE (0x30004)
+#define SRP_DECODED_PCM_SIZE (0x30005)
+#define SRP_CHANNEL_COUNT (0x30006)
+#define SRP_STOP_EOS_STATE (0x30007)
+
+/* constants for srp_ctrl device node*/
+#define SRP_CTRL_SET_GAIN (0xFF000)
+#define SRP_CTRL_SET_EFFECT (0xFF001)
+#define SRP_CTRL_GET_PCM_1KFRAME (0xFF002)
+#define SRP_CTRL_PCM_DUMP_OP (0xFF003)
+
+#define SRP_CTRL_EFFECT_ENABLE (0xFF010)
+#define SRP_CTRL_EFFECT_DEF (0xFF011)
+#define SRP_CTRL_EFFECT_EQ_USR (0xFF012)
+#define SRP_CTRL_EFFECT_SPEAKER (0xFF013)
+
+#define SRP_CTRL_IS_RUNNING (0xFF100)
+#define SRP_CTRL_IS_OPENED (0xFF101)
+#define SRP_CTRL_GET_OP_LEVEL (0xFF102)
+#define SRP_CTRL_IS_PCM_DUMP (0xFF103)
+
+#define SRP_CTRL_ALTFW_STATE (0xFF200)
+#define SRP_CTRL_ALTFW_LOAD (0xFF201)
+
+/* constants for SRP firmware */
+#define SRP_FW_CODE1 0
+#define SRP_FW_CODE20 1
+#define SRP_FW_CODE21 2
+#define SRP_FW_CODE22 3
+#define SRP_FW_CODE30 4
+#define SRP_FW_CODE31 5
+
+#define SRP_FW_VLIW 0
+#define SRP_FW_CGA 1
+#define SRP_FW_CGA_SA 2
+#define SRP_FW_DATA 3
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SRP_IOCTL_H__ */
+
diff --git a/exynos/multimedia/codecs/audio/exynos4/srp/ulp/src/srp_api.c b/exynos/multimedia/codecs/audio/exynos4/srp/ulp/src/srp_api.c
new file mode 100644
index 0000000..b0c0e5e
--- /dev/null
+++ b/exynos/multimedia/codecs/audio/exynos4/srp/ulp/src/srp_api.c
@@ -0,0 +1,381 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+#include "srp_api.h"
+
+#define LOG_TAG "libsrpapi"
+#include <cutils/log.h>
+
+/* Disable LOGD message */
+#ifdef LOGD
+#undef LOGD
+#endif
+#define LOGD(...)
+
+//#define _USE_WBUF_ /* Buffering before writing srp-rp device */
+//#define _DUMP_TO_FILE_
+//#define _USE_FW_FROM_DISK_
+
+#ifdef _USE_WBUF_
+#define WBUF_LEN_MUL 2
+#endif
+
+static int srp_dev = -1;
+static int srp_ibuf_size = 0;
+static int srp_block_mode = SRP_INIT_BLOCK_MODE;
+
+static unsigned char *wbuf;
+static int wbuf_size;
+static int wbuf_pos;
+
+#ifdef _DUMP_TO_FILE_
+static FILE *fp_dump = NULL;
+#endif
+
+#ifdef _USE_WBUF_
+static int WriteBuff_Init(void)
+{
+ if (wbuf == NULL) {
+ wbuf_size = srp_ibuf_size * WBUF_LEN_MUL;
+ wbuf_pos = 0;
+ wbuf = (unsigned char *)malloc(wbuf_size);
+ LOGD("%s: WriteBuffer %dbytes allocated", __func__, wbuf_size);
+ return 0;
+ }
+
+ LOGE("%s: WriteBuffer already allocated", __func__);
+ return -1;
+}
+
+static int WriteBuff_Deinit(void)
+{
+ if (wbuf != NULL) {
+ free(wbuf);
+ wbuf = NULL;
+ return 0;
+ }
+
+ LOGE("%s: WriteBuffer is not ready", __func__);
+ return -1;
+}
+
+static int WriteBuff_Write(unsigned char *buff, int size_byte)
+{
+ int write_byte;
+
+ if ((wbuf_pos + size_byte) < wbuf_size) {
+ memcpy(&wbuf[wbuf_pos], buff, size_byte);
+ wbuf_pos += size_byte;
+ } else {
+ LOGE("%s: WriteBuffer is filled [%d], ignoring write [%d]", __func__, wbuf_pos, size_byte);
+ return -1; /* Insufficient buffer */
+ }
+
+ return wbuf_pos;
+}
+
+static void WriteBuff_Consume(void)
+{
+ memcpy(wbuf, &wbuf[srp_ibuf_size], srp_ibuf_size * (WBUF_LEN_MUL - 1));
+ wbuf_pos -= srp_ibuf_size;
+}
+
+static void WriteBuff_Flush(void)
+{
+ wbuf_pos = 0;
+}
+#endif
+
+int SRP_Create(int block_mode)
+{
+ if (srp_dev == -1) {
+#ifdef _USE_FW_FROM_DISK_
+ SRP_Check_AltFirmware();
+#endif
+
+ srp_block_mode = block_mode;
+ srp_dev = open(SRP_DEV_NAME, O_RDWR |
+ ((block_mode == SRP_INIT_NONBLOCK_MODE) ? O_NDELAY : 0));
+
+ return srp_dev;
+ }
+
+ LOGE("%s: Device is not ready", __func__);
+ return -1; /* device alreay opened */
+}
+
+int SRP_Init(unsigned int ibuf_size)
+{
+ int ret;
+
+ if (srp_dev != -1) {
+ srp_ibuf_size = ibuf_size;
+ ret = ioctl(srp_dev, SRP_INIT, srp_ibuf_size); /* Initialize IBUF size (4KB ~ 18KB) */
+
+#ifdef _DUMP_TO_FILE_
+ char outname[256];
+ int cnt = 0;
+
+ while (1) {
+ sprintf(outname, "/data/rp_dump_%04d.mp3", cnt++);
+ if (fp_dump = fopen(outname, "rb")) { /* file exist? */
+ fclose(fp_dump);
+ } else {
+ break;
+ }
+ }
+
+ LOGD("%s: Dump MP3 to %s", __func__, outname);
+ if (fp_dump = fopen(outname, "wb"))
+ LOGD("%s: Success to open %s", __func__, outname);
+ else
+ LOGD("%s: Fail to open %s", __func__, outname);
+#endif
+
+#ifdef _USE_WBUF_
+ if (ret != -1)
+ return WriteBuff_Init();
+#else
+ return ret;
+#endif
+ }
+
+ LOGE("%s: Device is not ready", __func__);
+ return -1; /* device is not created */
+}
+
+#ifdef _USE_WBUF_
+int SRP_Decode(void *buff, int size_byte)
+{
+ int ret;
+ int val;
+ int err_code = 0;
+
+ if (srp_dev != -1) {
+ /* Check wbuf before writing buff */
+ while (wbuf_pos >= srp_ibuf_size) { /* Write_Buffer filled? (IBUF Size)*/
+ LOGD("%s: Write Buffer is full, Send data to RP", __func__);
+
+ ret = write(srp_dev, wbuf, srp_ibuf_size); /* Write Buffer to RP Driver */
+ if (ret == -1) { /* Fail? */
+ ioctl(srp_dev, SRP_ERROR_STATE, &val);
+ if (!val) { /* Write error? */
+ LOGE("%s: IBUF write fail", __func__);
+ return -1;
+ } else { /* Write OK, but RP decode error? */
+ err_code = val;
+ LOGE("%s: RP decode error [0x%05X]", __func__, err_code);
+ }
+ }
+#ifdef _DUMP_TO_FILE_
+ if (fp_dump)
+ fwrite(wbuf, srp_ibuf_size, 1, fp_dump);
+#endif
+ WriteBuff_Consume();
+ }
+
+ ret = WriteBuff_Write((unsigned char *)buff, size_byte);
+ if (ret == -1)
+ return -1; /* Buffering error */
+
+ LOGD("%s: Write Buffer remain [%d]", __func__, wbuf_pos);
+ return err_code; /* Write Success */
+ }
+
+ LOGE("%s: Device is not ready", __func__);
+ return -1; /* device is not created */
+}
+
+int SRP_Send_EOS(void)
+{
+ int ret;
+ int val;
+
+ if (srp_dev != -1) {
+ /* Check wbuf before writing buff */
+ while (wbuf_pos) { /* Write_Buffer ramain?*/
+ if (wbuf_pos < srp_ibuf_size) {
+ memset(wbuf + wbuf_pos, 0xFF, srp_ibuf_size - wbuf_pos); /* Fill dummy data */
+ wbuf_pos = srp_ibuf_size;
+ }
+
+ ret = write(srp_dev, wbuf, srp_ibuf_size); /* Write Buffer to RP Driver */
+ if (ret == -1) { /* Fail? */
+ ret = ioctl(srp_dev, SRP_ERROR_STATE, &val);
+ if (!val) { /* Write error? */
+ LOGE("%s: IBUF write fail", __func__);
+ return -1;
+ } else { /* RP decoe error? */
+ LOGE("%s: RP decode error [0x%05X]", __func__, val);
+ return -1;
+ }
+ } else { /* Success? */
+#ifdef _DUMP_TO_FILE_
+ if (fp_dump)
+ fwrite(wbuf, srp_ibuf_size, 1, fp_dump);
+#endif
+ WriteBuff_Consume();
+ }
+ }
+
+ memset(wbuf, 0xFF, srp_ibuf_size); /* Fill dummy data */
+ write(srp_dev, wbuf, srp_ibuf_size); /* Write Buffer to RP Driver */
+
+ /* Wait until RP decoding over */
+ return ioctl(srp_dev, SRP_WAIT_EOS);
+ }
+
+ return -1; /* device is not created */
+}
+#else /* Without WBUF */
+int SRP_Decode(void *buff, int size_byte)
+{
+ int ret;
+ int val;
+ int err_code = 0;
+
+ if (srp_dev != -1) {
+ LOGD("%s: Send data to RP (%d bytes)", __func__, size_byte);
+
+ ret = write(srp_dev, buff, size_byte); /* Write Buffer to RP Driver */
+ if (ret == -1) { /* Fail? */
+ ioctl(srp_dev, SRP_ERROR_STATE, &val);
+ if (!val) { /* Write error? */
+ LOGE("%s: IBUF write fail", __func__);
+ return -1;
+ } else { /* Write OK, but RP decode error? */
+ err_code = val;
+ LOGE("%s: RP decode error [0x%05X]", __func__, err_code);
+ }
+ }
+#ifdef _DUMP_TO_FILE_
+ if (fp_dump)
+ fwrite(buff, size_byte, 1, fp_dump);
+#endif
+
+ return err_code; /* Write Success */
+ }
+
+ LOGE("%s: Device is not ready", __func__);
+ return -1; /* device is not created */
+}
+
+int SRP_Send_EOS(void)
+{
+ /* Wait until RP decoding over */
+ if (srp_dev != -1)
+ return ioctl(srp_dev, SRP_SEND_EOS);
+
+ return -1; /* device is not created */
+}
+
+int SRP_Resume_EOS(void)
+{
+ if (srp_dev != -1)
+ return ioctl(srp_dev, SRP_RESUME_EOS);
+
+ return -1; /* device is not created */
+}
+#endif
+
+int SRP_Pause(void)
+{
+ if (srp_dev != -1)
+ return ioctl(srp_dev, SRP_PAUSE);
+
+ return -1; /* device is not created */
+}
+
+int SRP_Stop(void)
+{
+ if (srp_dev != -1)
+ return ioctl(srp_dev, SRP_STOP);
+
+ return -1; /* device is not created */
+}
+
+int SRP_Flush(void)
+{
+ if (srp_dev != -1) {
+ if (ioctl(srp_dev, SRP_FLUSH) != -1) {
+#ifdef _USE_WBUF_
+ WriteBuff_Flush();
+#endif
+ return 0;
+ }
+ }
+
+ return -1; /* device is not created */
+}
+
+
+int SRP_SetParams(int id, unsigned long val)
+{
+ if (srp_dev != -1)
+ return 0; /* not yet */
+
+ return -1; /* device is not created */
+}
+
+int SRP_GetParams(int id, unsigned long *pval)
+{
+ if (srp_dev != -1)
+ return ioctl(srp_dev, id, pval);
+
+ return -1; /* device is not created */
+}
+
+int SRP_Deinit(void)
+{
+ if (srp_dev != -1) {
+#ifdef _DUMP_TO_FILE_
+ if (fp_dump)
+ fclose(fp_dump);
+#endif
+
+#ifdef _USE_WBUF_
+ WriteBuff_Deinit();
+#endif
+ return ioctl(srp_dev, SRP_DEINIT); /* Deinialize */
+ }
+
+ LOGE("%s: Device is not ready", __func__);
+ return -1; /* device is not created */
+}
+
+int SRP_Terminate(void)
+{
+ int ret;
+
+ if (srp_dev != -1) {
+ ret = close(srp_dev);
+
+ if (ret == 0) {
+ srp_dev = -1; /* device closed */
+ return 0;
+ }
+ }
+
+ LOGE("%s: Device is not ready", __func__);
+ return -1; /* device is not created or close error*/
+}
+
+int SRP_IsOpen(void)
+{
+ if (srp_dev == -1) {
+ LOGD("%s: Device is not opened", __func__);
+ return 0;
+ }
+
+ LOGD("%s: Device is opened", __func__);
+ return 1;
+}
diff --git a/exynos/multimedia/codecs/audio/exynos4/srp/ulp/src/srp_api_ctrl.c b/exynos/multimedia/codecs/audio/exynos4/srp/ulp/src/srp_api_ctrl.c
new file mode 100644
index 0000000..bdc2310
--- /dev/null
+++ b/exynos/multimedia/codecs/audio/exynos4/srp/ulp/src/srp_api_ctrl.c
@@ -0,0 +1,331 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+#include "srp_api_ctrl.h"
+#include "srp_ioctl.h"
+
+#define LOG_TAG "libsrpapi"
+#include <cutils/log.h>
+
+/* Disable LOGD message */
+#ifdef LOGD
+#undef LOGD
+#endif
+#define LOGD(...)
+
+static int srp_ctrl = -1;
+static int srp_ctrl_cnt = 0;
+static short pcm_buf[2048]; /* 4KBytes data, 1K frames (16bit stereo data) */
+
+#ifdef _USE_FW_FROM_DISK_
+static char srp_alt_fw_name_pre[6][32] = {
+ "sdcard/rp_fw/rp_fw_code1",
+ "sdcard/rp_fw/rp_fw_code20",
+ "sdcard/rp_fw/rp_fw_code21",
+ "sdcard/rp_fw/rp_fw_code22",
+ "sdcard/rp_fw/rp_fw_code30",
+ "sdcard/rp_fw/rp_fw_code31",
+};
+#endif
+
+static int SRP_Ctrl_Open(void)
+{
+ if (srp_ctrl_cnt == 0) {
+ srp_ctrl = open(SRP_CTRL_DEV_NAME, O_RDWR | O_NDELAY);
+ if (srp_ctrl < 0) {
+ LOGE("%s: Failed open device file %d", __func__, srp_ctrl);
+ return -1;
+ }
+ srp_ctrl_cnt++;
+ LOGV("%s: Device is opened[%d]: cnt %d", __func__, srp_ctrl, srp_ctrl_cnt);
+ }
+
+ return srp_ctrl;
+}
+
+static int SRP_Ctrl_Close(void)
+{
+ int ret = 0;
+
+ if (srp_ctrl_cnt == 1) {
+ ret = close(srp_ctrl);
+ if (ret < 0) {
+ LOGE("%s: Failed closen device file %d", __func__, srp_ctrl);
+ return -1;
+ }
+ srp_ctrl_cnt--;
+ LOGV("%s: Device is closed[%d]: cnt %d", __func__, srp_ctrl, srp_ctrl_cnt);
+ srp_ctrl = -1;
+ }
+
+ return ret;
+}
+
+#ifdef _USE_FW_FROM_DISK_
+/* This will check & download alternate firmware */
+static int SRP_Check_AltFirmware(void)
+{
+ unsigned long *temp_buff;
+ FILE *fp = NULL;
+
+ char alt_fw_name[128];
+ unsigned long alt_fw_set;
+ unsigned long alt_fw_loaded = 0;
+ int alt_fw_text_ok,alt_fw_data_ok;
+
+ if ((srp_ctrl = SRP_Ctrl_Open()) >= 0) {
+ ioctl(srp_ctrl, SRP_CTRL_ALTFW_STATE, &alt_fw_loaded);
+
+ if (!alt_fw_loaded) { /* Not loaded yet? */
+ LOGE("Try to download alternate RP firmware");
+ temp_buff = (unsigned long *)malloc(256*1024); /* temp buffer */
+
+ for (alt_fw_set = 0; alt_fw_set < 6; alt_fw_set++) {
+ sprintf(alt_fw_name, "%s_text.bin", srp_alt_fw_name_pre[alt_fw_set]);
+ if (fp = fopen(alt_fw_name, "rb")) {
+ LOGE("RP Alt-Firmware Loading: %s", alt_fw_name);
+ fread(temp_buff, 64*1024, 1, fp);
+ close(fp);
+ alt_fw_text_ok = 1;
+ } else {
+ alt_fw_text_ok = 0;
+ }
+
+ sprintf(alt_fw_name, "%s_data.bin", srp_alt_fw_name_pre[alt_fw_set]);
+ if (fp = fopen(alt_fw_name, "rb")) {
+ LOGE("RP Alt-Firmware Loading: %s", alt_fw_name);
+ fread(&temp_buff[64*1024/4], 96*1024, 1, fp);
+ close(fp);
+ alt_fw_data_ok = 1;
+ } else {
+ alt_fw_data_ok = 0;
+ }
+
+ if (alt_fw_text_ok && alt_fw_data_ok) {
+ temp_buff[160*1024/4] = alt_fw_set;
+ ioctl(srp_ctrl, SRP_CTRL_ALTFW_LOAD, temp_buff);
+ }
+ }
+ free(temp_buff);
+ }
+ SRP_Ctrl_Close();
+ }
+
+ return 0;
+}
+#endif
+
+int SRP_Ctrl_Set_Effect(int effect)
+{
+ int ret;
+ unsigned long effect_mode = (unsigned long)effect;
+
+ ret = SRP_Ctrl_Open();
+ if (ret < 0) {
+ LOGE("%s: SRP_Ctrl_Open error", __func__);
+ return -1;
+ }
+
+ ioctl(srp_ctrl, SRP_CTRL_SET_EFFECT, effect_mode);
+
+ SRP_Ctrl_Close();
+
+ return 0;
+}
+
+int SRP_Ctrl_Enable_Effect(int on)
+{
+ int ret;
+ unsigned long effect_switch = on ? 1 : 0;
+
+ ret = SRP_Ctrl_Open();
+ if (ret < 0) {
+ LOGE("%s: SRP_Ctrl_Open error", __func__);
+ return -1;
+ }
+
+ ioctl(srp_ctrl, SRP_CTRL_EFFECT_ENABLE, effect_switch);
+
+ SRP_Ctrl_Close();
+
+ return 0;
+}
+
+int SRP_Ctrl_Set_Effect_Def(unsigned long effect_def)
+{
+ int ret;
+
+ ret = SRP_Ctrl_Open();
+ if (ret < 0) {
+ LOGE("%s: SRP_Ctrl_Open error", __func__);
+ return -1;
+ }
+
+ ioctl(srp_ctrl, SRP_CTRL_EFFECT_DEF, effect_def);
+
+ SRP_Ctrl_Close();
+
+ return 0;
+}
+
+int SRP_Ctrl_Set_Effect_EQ_User(unsigned long eq_user)
+{
+ int ret;
+
+ ret = SRP_Ctrl_Open();
+ if (ret < 0) {
+ LOGE("%s: SRP_Ctrl_Open error", __func__);
+ return -1;
+ }
+
+ ioctl(srp_ctrl, SRP_CTRL_EFFECT_EQ_USR, eq_user);
+
+ SRP_Ctrl_Close();
+
+ return 0;
+}
+
+int SRP_Ctrl_Set_Pcm_Dump(int on)
+{
+ int ret;
+
+ ret = SRP_Ctrl_Open();
+ if (ret < 0) {
+ LOGE("%s: SRP_Ctrl_Open error", __func__);
+ return -1;
+ }
+
+ ioctl(srp_ctrl, SRP_CTRL_PCM_DUMP_OP, on);
+
+ LOGV("dump_op: %d", on);
+
+ SRP_Ctrl_Close();
+
+ return 0;
+}
+
+int SRP_Ctrl_Get_Pcm_Dump_State(void)
+{
+ int ret;
+ int srp_dump_stat = 0;
+
+ ret = SRP_Ctrl_Open();
+ if (ret < 0) {
+ LOGE("%s: SRP_Ctrl_Open error", __func__);
+ return -1;
+ }
+
+ ioctl(srp_ctrl, SRP_CTRL_IS_PCM_DUMP, &srp_dump_stat);
+
+ LOGV("srp_dump_stat: %d", srp_dump_stat);
+
+ SRP_Ctrl_Close();
+
+ return srp_dump_stat;
+}
+
+int SRP_Ctrl_Set_Gain(float value)
+{
+ int ret;
+ unsigned long gain = 0;
+
+ ret = SRP_Ctrl_Open();
+ if (ret < 0) {
+ LOGE("%s: SRP_Ctrl_Open error", __func__);
+ return -1;
+ }
+
+ gain = (unsigned long)((1 << 24) * value);
+ ioctl(srp_ctrl, SRP_CTRL_SET_GAIN, gain);
+
+ SRP_Ctrl_Close();
+
+ return 0;
+}
+
+int SRP_Ctrl_Get_Running_Stat(void)
+{
+ int ret;
+ int srp_running_stat = 0;
+
+ ret = SRP_Ctrl_Open();
+ if (ret < 0) {
+ LOGE("%s: SRP_Ctrl_Open error", __func__);
+ return -1;
+ }
+
+ ioctl(srp_ctrl, SRP_CTRL_IS_RUNNING, &srp_running_stat);
+
+ LOGV("srp_running_stat: %d", srp_running_stat);
+
+ SRP_Ctrl_Close();
+
+ return srp_running_stat;
+}
+
+int SRP_Ctrl_Get_Open_Stat(void)
+{
+ int ret;
+ int srp_open_stat = 0;
+
+ ret = SRP_Ctrl_Open();
+ if (ret < 0) {
+ LOGE("%s: SRP_Ctrl_Open error", __func__);
+ return -1;
+ }
+
+ ioctl(srp_ctrl, SRP_CTRL_IS_OPENED, &srp_open_stat);
+
+ LOGV("srp_open_stat: %d", srp_open_stat);
+
+ SRP_Ctrl_Close();
+
+ return srp_open_stat;
+}
+
+short *SRP_Ctrl_Get_Pcm(void)
+{
+ int ret;
+ int rp_is_running = 0;
+ int dump_is_on = 0;
+ int rp_is_opened = 0;
+
+ ret = SRP_Ctrl_Open();
+ if (ret < 0) {
+ LOGE("%s: SRP_Ctrl_Open error", __func__);
+ return NULL;
+ }
+
+ ioctl(srp_ctrl, SRP_CTRL_IS_RUNNING, &rp_is_running);
+ if (rp_is_running) {
+ ioctl(srp_ctrl, SRP_CTRL_IS_PCM_DUMP, &dump_is_on);
+ if (dump_is_on == 0) {
+ ioctl(srp_ctrl, SRP_CTRL_PCM_DUMP_OP, 1);
+ dump_is_on = 1;
+ }
+
+ ioctl(srp_ctrl, SRP_CTRL_GET_PCM_1KFRAME, pcm_buf);
+ return pcm_buf;
+ }
+
+ /* SRP is not running */
+ if (srp_ctrl > 0) {
+ if (dump_is_on) {
+ ioctl(srp_ctrl, SRP_CTRL_IS_OPENED, &rp_is_opened);
+ if (rp_is_opened)
+ ioctl(srp_ctrl, SRP_CTRL_PCM_DUMP_OP, 0);
+ }
+ SRP_Ctrl_Close();
+ }
+
+ return NULL;
+}