--- /dev/null
+/*
+* sound-plugin-hal-mfld-blackbay
+*
+* Copyright (C) 2013 Intel Corporation. All rights reserved.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*/
+
+#ifndef __LPE_CTRL_H__
+#define __LPE_CTRL_H__
+
+#include <linux/types.h>
+
+#define ENABLE 0x01
+#define DISABLE 0x00
+#define DIFFERENT 0x01
+#define SAME 0x00
+#define SET 0x00
+#define GET 0x01
+#define DONT_CHANGE_MOD_STATE 0x02
+
+#define STREAM_HS 1
+#define STREAM_IHF 2
+#define STREAM_VIBRA1 3
+#define STREAM_VIBRA2 4
+#define STREAM_CAP 5
+
+#define VMIC_HS_LEFT_CHANL 0x00
+#define VMIC_HS_RIGHT_CHANL 0x01
+#define VMIC_IHF_LEFT_CHANL 0x02
+#define VMIC_IHF_RIGHT_CHANL 0x03
+#define VMIC_VIBRA1_CHANL 0x04
+#define VMIC_VIBRA2_CHANL 0x05
+#define VMIC_DISABLED 0x06
+
+/* Device Types used in LPE*/
+typedef enum lpe_dev_types {
+ LPE_DEV_DECODE,
+ LPE_DEV_HS,
+ LPE_DEV_EP,
+ LPE_DEV_IHF,
+ LPE_DEV_VIBRA1,
+ LPE_DEV_VIBRA2,
+ LPE_DEV_MIC1,
+ LPE_DEV_MIC2,
+ LPE_DEV_MIC3,
+ LPE_DEV_MIC4,
+ LPE_MAX_DEV
+} lpe_dev_types_t;
+
+/* LPE Algorithm module IDs*/
+typedef enum lpe_algo_types {
+ LPE_ALGO_TYPE_VOL_CTRL = 0x67,
+ LPE_ALGO_TYPE_MUTE_CTRL = 0x68,
+ LPE_ALGO_TYPE_SIDE_TONE = 0x6A,
+ LPE_ALGO_TYPE_DC_REMOVEL = 0x6B,
+ LPE_ALGO_TYPE_STEREO_EQ = 0x6C,
+ LPE_ALGO_TYPE_SPKR_PROT = 0x6D,
+ LPE_ALGO_TYPE_AV_REMOVAL = 0x70,
+ LPE_ALGO_TYPE_MONO_EQ = 0x71,
+ LPE_ALGO_TYPE_SDRC = 0x72
+}lpe_algo_types_t;
+
+/* Stereo Equalizer module parameters type*/
+typedef enum lpe_param_types_stereo_equalizer {
+ ALGO_PARAM_SEQ_DIFF_SAME_2_CHAN = 0x101,
+ ALGO_PARAM_SEQ_LEFT_CHANNEL_CONF,
+ ALGO_PARAM_SEQ_FIR_COEF_LEFT,
+ ALGO_PARAM_SEQ_IIR_COEF_LEFT,
+ ALGO_PARAM_SEQ_RIGHT_CHANNEL_CONF,
+ ALGO_PARAM_SEQ_FIR_COEF_RIGHT,
+ ALGO_PARAM_SEQ_IIR_COEF_RIGHT
+}lpe_param_types_stereo_equalizer_t;
+
+/* Mono Equalizer module parameters type*/
+typedef enum lpe_param_types_mono_equalizer {
+ ALGO_PARAM_MEQ_CHANNEL_CONF = 0x151,
+ ALGO_PARAM_MEQ_FIR_COEF,
+ ALGO_PARAM_MEQ_IIR_COEF
+}lpe_param_types_mono_equalizer_t;
+
+/* Sidetone module parameters type*/
+typedef enum lpe_param_types_sidetone {
+ ALGO_PARAM_STP_DL_MONO_STEREO_SEL = 0x201,
+ ALGO_PARAM_STP_FIR_ENABLE_DISABLE,
+ ALGO_PARAM_STP_AGC_ENABLE_DISABLE,
+ ALGO_PARAM_STP_FIR_COEF_SIZE,
+ ALGO_PARAM_STP_FIR_COEF,
+ ALGO_PARAM_STP_ADAPTIVE_GAIN,
+ ALGO_PARAM_STP_GAIN
+}lpe_param_types_sidetone_t;
+
+/* DC Removal module parameters type*/
+typedef enum lpe_param_types_dcr {
+ ALGO_PARAM_DCR_IIR_ENABLE_DISABLE = 0x301,
+ ALGO_PARAM_DCR_IIR_COEF,
+}lpe_param_types_dcr_t;
+
+/* Xprot module parameters type*/
+typedef enum lpe_param_types_xprot {
+ ALGO_PARAM_XPORT_PCM_TYPE = 0x401,
+ ALGO_PARAM_XPORT_SFREQ,
+ ALGO_PARAM_XPORT_CHANL_MODE,
+ ALGO_PARAM_XPORT_DISP_LIMIT,
+ ALGO_PARAM_XPORT_TEMP_LIMIT,
+ ALGO_PARAM_XPORT_AMBIENT_TEMP,
+ ALGO_PARAM_XPORT_VOL_LEVEL,
+ ALGO_PARAM_XPORT_FRAME_LENGTH,
+ ALGO_PARAM_XPORT_CONFIG_PARAMS
+}lpe_param_types_xprot_t;
+
+/* Remove Click module parameters type*/
+typedef enum lpe_param_types_RMC {
+ ALGO_PARAM_RMC_PCM_TYPE = 0x501,
+ ALGO_PARAM_RMC_SFREQ,
+ ALGO_PARAM_RMC_EMRGNCY_MODE,
+ ALGO_PARAM_RMC_FRAME_LENGTH,
+ ALGO_PARAM_RMC_CONFIG_PARAMS,
+ ALGO_PARAM_RMC_CHAN_NUM
+}lpe_param_types_RMC_t;
+
+/* volume control module parameters type */
+typedef enum lpe_param_types_vol_ctrl {
+ ALGO_PARAM_VOL_CTRL_STEREO_MONO = 0x601,
+ ALGO_PARAM_VOL_CTRL_GAIN = 0x602
+}lpe_param_types_vol_ctrl_t;
+
+/* mute control module parameters type */
+typedef enum lpe_param_types_mute_ctrl {
+ ALGO_PARAM_MUTE_STEREO_MONO = 0x701,
+ ALGO_PARAM_MUTE_ENABLE_DISABLE = 0x702,
+ ALGO_PARAM_HALF_MUTE_ENABLE_DISABLE = 0x703,
+}lpe_param_types_mute_ctrl_t;
+
+/* SDRC control module parameters type */
+typedef enum lpe_param_types_sdrc_ctrl {
+ ALGO_PARAM_SDRC_NB_BANDS = 0x801,
+ ALGO_PARAM_SDRC_L_A,
+ ALGO_PARAM_SDRC_L_B,
+ ALGO_PARAM_SDRC_L_U,
+ ALGO_PARAM_SDRC_GCOMP_B,
+ ALGO_PARAM_SDRC_SLOPE_LOWERMOST,
+ ALGO_PARAM_SDRC_SLOPE_AB,
+ ALGO_PARAM_SDRC_SLOPE_UPPERMOST,
+ ALGO_PARAM_SDRC_LOUDNESS_ATTACK_TIME,
+ ALGO_PARAM_SDRC_LOUDNESS_RELEASE_TIME,
+ ALGO_PARAM_SDRC_GAIN_ATTACK_TIME,
+ ALGO_PARAM_SDRC_GAIN_RELEASE_TIME
+}lpe_param_types_sdrc_ctrl_t;
+
+typedef enum fw_param_type{
+ LOW_LATENCY=0,
+ NON_LOW_LATENCY,
+ VMIC_CONFIG,
+ DMA_INPUT_BUFFER,
+ DMA_OUTPUT_BUFFER,
+}fw_param_type_t;
+
+typedef struct snd_sst_tuning_params {
+ __u8 type;
+ __u8 str_id;
+ __u8 size;
+ __u8 rsvd;
+ __u64 addr;
+} __attribute__ ((packed)) snd_sst_tuning_params_t;
+
+
+/* Pre and post processing params structure */
+typedef struct snd_ppp_params {
+ __u8 algo_id;/* Post/Pre processing algorithm ID */
+ __u8 str_id; /*Only 5 bits used 0 - 31 are valid*/
+ __u8 enable; /* 0= disable, 1= enable*/
+ __u8 reserved;
+ __u32 size; /*Size of parameters for all blocks*/
+ void *params;
+} __attribute__ ((packed)) snd_ppp_params_t;
+
+/* Parameters block of a module */
+typedef struct ipc_ia_params_block {
+ __u32 type; /*Type of the parameter*/
+ __u32 size; /*size of the parameters in the block*/
+ __u8 params[0]; /*Parameters of the algorithm*/
+}__attribute__ ((packed)) ipc_ia_params_block_t;
+
+/*DSP Ioctls on /dev/intel_sst_ctrl only*/
+#define SNDRV_SST_SET_ALGO _IOW('L', 0x30, struct snd_ppp_params *)
+#define SNDRV_SST_GET_ALGO _IOWR('L', 0x31, struct snd_ppp_params *)
+#define SNDRV_SST_TUNING_PARAMS _IOW('L', 0x32, struct snd_sst_tuning_params *)
+#define SNDRV_SST_SET_RUNTIME_PARAMS _IOW('L', 0x40, struct snd_sst_tuning_params *)
+
+/* Function Declarations */
+int lpe_get_parameter(int str_id, int algo_id, int param_id, int param_length);
+int lpe_set_parameter(int str_id, int algo_id, int param_id, int param_length, char *param_data);
+int change_algo_state(int algo_id, int str_id, int state);
+int check_algo_state(int algo_id, int str_id);
+int lpe_setup_blackbay();
+#endif /* __LPE_CTRL_H__ */
+
--- /dev/null
+/*
+ * sound-plugin-hal-mfld-blackbay
+ *
+ * Copyright (C) 2013 Intel Corporation. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <mm_debug.h>
+#include "lpe_ctl.h"
+#define INTEL_SST_CTRL "/dev/intel_sst_ctrl"
+
+static int prepare_module_header(snd_ppp_params_t *ppp_params, int algo_id, int stream_id, int enable_status)
+{
+ ppp_params->str_id = stream_id;
+ ppp_params->algo_id = algo_id;
+ ppp_params->enable = enable_status;
+ ppp_params->size = 0;
+ ppp_params->params = (unsigned char *)ppp_params + sizeof(snd_ppp_params_t);
+ return 0;
+}
+
+static int add_parameter_blocks(snd_ppp_params_t *ppp_params, int param_type, int param_length, char *param_data)
+{
+ unsigned char *uptr;
+ ipc_ia_params_block_t *pbptr;
+
+ uptr = (unsigned char *)ppp_params->params + ppp_params->size;
+ pbptr = (ipc_ia_params_block_t *)uptr;
+ pbptr->type = param_type;
+ pbptr->size = param_length;
+ memcpy(pbptr->params, param_data, param_length);
+ ppp_params->size += sizeof(ipc_ia_params_block_t) + param_length;
+ return 0;
+}
+
+static int set_parameters(snd_ppp_params_t *ppp_params)
+{
+ int ret, handle;
+
+ handle = open(INTEL_SST_CTRL, O_RDWR);
+ if ( handle < 0) {
+ debug_log("%s open failed: %s", INTEL_SST_CTRL, strerror(errno));
+ return -1;
+ }
+
+ ret = ioctl(handle, SNDRV_SST_SET_ALGO, ppp_params);
+ if (ret != 0) {
+ debug_log("ioctl cmd SET_ALGO failed: %s", strerror(errno));
+ ret = -1;
+ }
+ debug_log("set parameters success");
+ close(handle);
+ return ret;
+
+}
+
+static int get_parameters(snd_ppp_params_t *ppp_params)
+{
+ int ret, handle;
+ unsigned char * charp;
+ unsigned int i, dump_size=0;
+ handle = open(INTEL_SST_CTRL, O_RDWR);
+ if (handle < 0) {
+ debug_log("%s open failed: %s", INTEL_SST_CTRL, strerror(errno));
+ return -1;
+ }
+ ret = ioctl(handle, SNDRV_SST_GET_ALGO, ppp_params);
+ if ( ret != 0) {
+ debug_log("ioctl cmd GET_ALGO failed");
+ ret = -1;
+ }
+ close(handle);
+
+ if (!ret) {
+ debug_log("get parameters success: Algo ID 0x%x Str ID %d, Enable %d, Operation %d, Size %d\n",
+ ppp_params->algo_id, ppp_params->str_id, ppp_params->enable, ppp_params->reserved, ppp_params->size);
+ debug_log("Dump recieved data, size=%d \n", ppp_params->size);
+ dump_size = ppp_params->size;
+ charp = (unsigned char *)ppp_params->params;
+ for (i = 0; i < dump_size; i++, charp++)
+ debug_log("%02x ", *charp);
+ }
+ return ret;
+}
+
+int lpe_get_parameter(int str_id, int algo_id, int param_id, int param_length)
+{
+ unsigned int param_data[64];
+ char acparams[64];
+ snd_ppp_params_t *ppp_params = (snd_ppp_params_t *)acparams;
+
+ debug_log("lpe_get_parameter: str_id=0x%x, algo_id=0x%x, param_id=0x%x, param_length=%d\n",
+ str_id, algo_id, param_id, param_length);
+ // Prepare header and add data to parameter block
+ prepare_module_header(ppp_params, algo_id, str_id, DONT_CHANGE_MOD_STATE);
+ add_parameter_blocks(ppp_params, param_id, param_length, (char*)param_data);
+
+ if (get_parameters(ppp_params) != 0) {
+ debug_log("Unable to get parameter\n");
+ return -1;
+ }
+ return 0;
+}
+
+int lpe_set_parameter(int str_id, int algo_id, int param_id, int param_length, char *param_data)
+{
+ char acparams[32];
+ snd_ppp_params_t *ppp_params = (snd_ppp_params_t *)acparams;
+
+ debug_log("lpe_set_parameter: str_id=0x%x, algo_id=0x%x, param_id=0x%x, param_length=%d\n",
+ str_id, algo_id, param_id, param_length);
+ // Prepare header and add data to parameter block
+ prepare_module_header(ppp_params, algo_id, str_id, DONT_CHANGE_MOD_STATE);
+ add_parameter_blocks(ppp_params, param_id, param_length, param_data);
+
+ if (set_parameters(ppp_params) != 0) {
+ debug_log("Unable to set parameter\n");
+ return -1;
+ }
+ return 0;
+}
+
+int change_algo_state(int str_id, int algo_id, int state)
+{
+ char acparams[64];
+ snd_ppp_params_t *ppp_params = (snd_ppp_params_t *)acparams;
+
+ debug_log("change_algo_state: str_id=0x%x, algo_id=0x%x, state=%d\n", str_id, algo_id, state);
+ prepare_module_header(ppp_params, algo_id, str_id, state);
+ if (set_parameters(ppp_params) != 0) {
+ debug_log("Unable to set parameter\n");
+ return -1;
+ }
+ return 0;
+}
+
+int check_algo_state(int str_id, int algo_id)
+{
+ char acparams[64];
+ snd_ppp_params_t *ppp_params = (snd_ppp_params_t *)acparams;
+
+ debug_log("check_algo_state: str_id=0x%x, algo_id=0x%x\n", str_id, algo_id);
+ prepare_module_header(ppp_params, algo_id, str_id, DONT_CHANGE_MOD_STATE);
+ if (get_parameters(ppp_params) != 0) {
+ debug_log("Unable to get parameter\n");
+ return -1;
+ }
+ if (ppp_params->enable) {
+ debug_log ("State: enable\n");
+ } else {
+ debug_log ("State: disable\n");
+ }
+ return 0;
+}
+
+int lpe_setup_blackbay()
+{
+ unsigned int param_data[32];
+
+ debug_log("MFLD: Enable MIC1_PATH/GAIN_CTRL\n");
+ change_algo_state(0x05, LPE_ALGO_TYPE_VOL_CTRL, ENABLE);
+ debug_log("MFLD: Enable MIC2_PATH/GAIN_CTRL\n");
+ change_algo_state(0x25, LPE_ALGO_TYPE_VOL_CTRL, ENABLE);
+
+ param_data[0]=20;
+ debug_log("Set MIC1_PATH/GAIN_CTRL/GAIN to value 20\n");
+ lpe_set_parameter(0x05, LPE_ALGO_TYPE_VOL_CTRL, ALGO_PARAM_VOL_CTRL_GAIN, 1, (char *)param_data);
+ debug_log("Set MIC2_PATH/GAIN_CTRL/GAIN to value 20\n");
+ lpe_set_parameter(0x25, LPE_ALGO_TYPE_VOL_CTRL, ALGO_PARAM_VOL_CTRL_GAIN, 1, (char *)param_data);
+
+ return 0;
+}