Skip to content

Instantly share code, notes, and snippets.

@invisiblek
Created June 10, 2015 17:09
Show Gist options
  • Save invisiblek/89d4294a9ad86d113349 to your computer and use it in GitHub Desktop.
Save invisiblek/89d4294a9ad86d113349 to your computer and use it in GitHub Desktop.
commit eac05152a285b5d9406434f027081fc008f7b943
Author: Richard Ross <[email protected]>
Date: Wed Jun 10 12:07:17 2015 -0500
amplifier: fix tfa9887 amp
diff --git a/libaudioamp/tfa9887.h b/libaudioamp/tfa9887.h
index 23a1d3d..9712bee 100644
--- a/libaudioamp/tfa9887.h
+++ b/libaudioamp/tfa9887.h
@@ -17,6 +17,23 @@
#define TFA9887_DEVICE "/dev/tfa9887"
#define TFA9887L_DEVICE "/dev/tfa9887l"
+#define ACOUSTIC_IOCTL_MAGIC 'p'
+#define ACOUSTIC_SET_Q6_EFFECT _IOW(ACOUSTIC_IOCTL_MAGIC, 43, unsigned)
+#define ACOUSTIC_GET_HTC_REVISION _IOW(ACOUSTIC_IOCTL_MAGIC, 44, unsigned)
+#define ACOUSTIC_GET_HW_COMPONENT _IOW(ACOUSTIC_IOCTL_MAGIC, 45, unsigned)
+#define ACOUSTIC_GET_DMIC_INFO _IOW(ACOUSTIC_IOCTL_MAGIC, 46, unsigned)
+#define ACOUSTIC_UPDATE_BEATS_STATUS _IOW(ACOUSTIC_IOCTL_MAGIC, 47, unsigned)
+#define ACOUSTIC_UPDATE_LISTEN_NOTIFICATION _IOW(ACOUSTIC_IOCTL_MAGIC, 48, unsigned)
+#define ACOUSTIC_GET_HW_REVISION _IOR(ACOUSTIC_IOCTL_MAGIC, 49, struct device_info)
+#define ACOUSTIC_CONTROL_WAKELOCK _IOW(ACOUSTIC_IOCTL_MAGIC, 77, unsigned)
+#define ACOUSTIC_DUMMY_WAKELOCK _IOW(ACOUSTIC_IOCTL_MAGIC, 78, unsigned)
+#define ACOUSTIC_AMP_CTRL _IOR(ACOUSTIC_IOCTL_MAGIC, 50, unsigned)
+#define ACOUSTIC_GET_MID _IOW(ACOUSTIC_IOCTL_MAGIC, 51, unsigned)
+#define ACOUSTIC_RAMDUMP _IOW(ACOUSTIC_IOCTL_MAGIC, 99, unsigned)
+#define ACOUSTIC_KILL_PID _IOW(ACOUSTIC_IOCTL_MAGIC, 88, unsigned)
+#define ACOUSTIC_UPDATE_DQ_STATUS _IOW(ACOUSTIC_IOCTL_MAGIC, 52, unsigned)
+
+
#define TPA9887_IOCTL_MAGIC 'a'
#define TPA9887_WRITE_CONFIG _IOW(TPA9887_IOCTL_MAGIC, 0x01, unsigned int)
#define TPA9887_READ_CONFIG _IOW(TPA9887_IOCTL_MAGIC, 0x02, unsigned int)
@@ -30,36 +47,50 @@
#define MAX_PATCH_SIZE 3072
#define MAX_PARAM_SIZE 768
+#define MASTER_PATCH "/system/etc/tfa/tfa9895.patch"
+
+// legacy?
#define PATCH_R "/system/etc/tfa/tfa9887.patch"
#define PATCH_L "/system/etc/tfa/tfa9887_l.patch"
-#define SPKR_R "/system/etc/tfa/deftcoefA.speaker"
-#define SPKR_L "/system/etc/tfa/deftcoefA_l.speaker"
-#define CONFIG_PLAYBACK_R "/system/etc/tfa/playback.config"
-#define CONFIG_PLAYBACK_L "/system/etc/tfa/playback_l.config"
+#define SPKR_R "/system/etc/tfa/tfa9895.speaker"
+#define SPKR_L "/system/etc/tfa/tfa9895_l.speaker"
+
+#define CONFIG_TFA9887 "/system/etc/tfa/tfa9895.config"
+
+#define CONFIG_PLAYBACK_R "/system/etc/tfa/playbackwoofer.config"
+#define CONFIG_PLAYBACK_L "/system/etc/tfa/playbackwoofer_l.config"
#define CONFIG_RING_R "/system/etc/tfa/ring.config"
#define CONFIG_RING_L "/system/etc/tfa/ring_l.config"
#define CONFIG_VOICE_R "/system/etc/tfa/voice.config"
#define CONFIG_VOICE_L "/system/etc/tfa/voice_l.config"
-#define PRESET_PLAYBACK_R "/system/etc/tfa/playback.preset"
-#define PRESET_PLAYBACK_L "/system/etc/tfa/playback_l.preset"
+#define PRESET_PLAYBACK_R "/system/etc/tfa/playbackwoofer.preset"
+#define PRESET_PLAYBACK_L "/system/etc/tfa/playbackwoofer_l.preset"
#define PRESET_RING_R "/system/etc/tfa/ring.preset"
#define PRESET_RING_L "/system/etc/tfa/ring_l.preset"
#define PRESET_VOICE_R "/system/etc/tfa/voice.preset"
#define PRESET_VOICE_L "/system/etc/tfa/voice_l.preset"
-#define EQ_PLAYBACK_R "/system/etc/tfa/playback.eq"
-#define EQ_PLAYBACK_L "/system/etc/tfa/playback_l.eq"
+#define EQ_PLAYBACK_R "/system/etc/tfa/playbackwoofer.eq"
+#define EQ_PLAYBACK_L "/system/etc/tfa/playbackwoofer_l.eq"
#define EQ_RING_R "/system/etc/tfa/ring.eq"
#define EQ_RING_L "/system/etc/tfa/ring_l.eq"
#define EQ_VOICE_R "/system/etc/tfa/voice.eq"
#define EQ_VOICE_L "/system/etc/tfa/voice_l.eq"
+#define DRC_PLAYBACK_R "/system/etc/tfa/playbackwoofer.drc"
+#define DRC_PLAYBACK_L "/system/etc/tfa/playbackwoofer_l.drc"
+#define DRC_RING_R "/system/etc/tfa/ring.drc"
+#define DRC_RING_L "/system/etc/tfa/ring_l.drc"
+#define DRC_VOICE_R "/system/etc/tfa/voice.drc"
+#define DRC_VOICE_L "/system/etc/tfa/voice_l.drc"
+
struct mode_config {
const char *config;
const char *preset;
const char *eq;
+ const char *drc;
};
typedef enum Tfa9887_Mode {
@@ -71,37 +102,43 @@ typedef enum Tfa9887_Mode {
const struct mode_config Tfa9887_Right_Mode_Configs[Tfa9887_Num_Modes] = {
{ /* Playback */
- .config = CONFIG_PLAYBACK_R,
+ .config = CONFIG_TFA9887,
.preset = PRESET_PLAYBACK_R,
- .eq = EQ_PLAYBACK_R
+ .eq = EQ_PLAYBACK_R,
+ .drc = DRC_PLAYBACK_R
},
{ /* Ring */
- .config = CONFIG_RING_R,
+ .config = CONFIG_TFA9887,
.preset = PRESET_RING_R,
- .eq = EQ_RING_R
+ .eq = EQ_RING_R,
+ .drc = DRC_RING_R
},
{ /* Voice */
- .config = CONFIG_VOICE_R,
+ .config = CONFIG_TFA9887,
.preset = PRESET_VOICE_R,
- .eq = EQ_VOICE_R
+ .eq = EQ_VOICE_R,
+ .drc = DRC_VOICE_R
}
};
const struct mode_config Tfa9887_Left_Mode_Configs[Tfa9887_Num_Modes] = {
{ /* Playback */
- .config = CONFIG_PLAYBACK_L,
+ .config = CONFIG_TFA9887,
.preset = PRESET_PLAYBACK_L,
.eq = EQ_PLAYBACK_L,
+ .drc = DRC_PLAYBACK_L
},
{ /* Ring */
- .config = CONFIG_RING_L,
+ .config = CONFIG_TFA9887,
.preset = PRESET_RING_L,
- .eq = EQ_RING_L
+ .eq = EQ_RING_L,
+ .drc = DRC_RING_L
},
{ /* Voice */
- .config = CONFIG_VOICE_L,
+ .config = CONFIG_TFA9887,
.preset = PRESET_VOICE_L,
- .eq = EQ_VOICE_L
+ .eq = EQ_VOICE_L,
+ .drc = DRC_VOICE_L
}
};
@@ -129,9 +166,13 @@ typedef enum {
/* RPC commands */
#define PARAM_SET_LSMODEL 0x06 // Load a full model into SpeakerBoost.
#define PARAM_SET_LSMODEL_SEL 0x07 // Select one of the default models present in Tfa9887 ROM.
+
#define PARAM_SET_EQ 0x0A // 2 Equaliser Filters.
#define PARAM_SET_PRESET 0x0D // Load a preset
#define PARAM_SET_CONFIG 0x0E // Load a config
+#define PARAM_SET_DRC 0x0F // Load DRC file
+#define SB_PARAM_SET_AGCINS 0x10
+
#define PARAM_GET_RE0 0x85 /* gets the speaker calibration impedance (@25 degrees celsius) */
#define PARAM_GET_LSMODEL 0x86 // Gets current LoudSpeaker Model.
#define PARAM_GET_STATE 0xC0
@@ -192,10 +233,15 @@ typedef enum {
#define TFA9887_STATUS_ACS (1<<11) /* cold started */
#define TFA9887_STATUS_SWS (1<<12) /* amplifier switching */
+#define TFA98XX_STATUSREG_ACS_MSK 0x800
+#define TFA98XX_STATUSREG_MTPB_MSK 0x100
+
/* MTP bits */
#define TFA9887_MTP_MTPOTC (1<<0) /* one time calibration */
#define TFA9887_MTP_MTPEX (1<<1) /* one time calibration done */
+#define TFA98XX_STATUSREG_AREFS_MSK 0x800
+
#define TFA9887_STATUS (0x00)
#define TFA9887_BATTERYVOLTAGE (0x01)
#define TFA9887_TEMPERATURE (0x02)
@@ -223,5 +269,33 @@ typedef enum {
#define TFA9887_CF_STATUS (0x73)
#define TFA9887_MTP (0x80)
+enum ACOU_AMP_CTRL {
+ AMP_READ = 0,
+ AMP_WRITE,
+};
+
+enum AMP_TYPE {
+ AMP_HEADPONE = 0,
+ AMP_SPEAKER,
+ AMP_RECEIVER,
+};
+
+struct amp_ctrl {
+ enum ACOU_AMP_CTRL ctrl;
+ enum AMP_TYPE type;
+ unsigned short slave;
+ unsigned int reg;
+ unsigned int val;
+};
+
+struct speaker_handle {
+ //int in_use;
+ int fd;
+ unsigned char slave_address;
+ unsigned short rev;
+ //enum featureSupport supportDrc;
+ //enum featureSupport supportFramework;
+};
+
int tfa9887_init(void);
int tfa9887_set_mode(audio_mode_t mode);
commit 4010d059346e42aca462b7f7e3887c1f255cbdfb
Author: Richard Ross <[email protected]>
Date: Fri Apr 25 21:55:44 2014 -0400
libaudioamp: import custom HTC amp from m7-common and switch to caf HAL using Legacy ALSA audio
- audio: audio_policy.conf: update policy config file
- audio: snd_soc_msm_Taiko: add legacy config file from CAF and update it with HTC parameters
- rootdir: ueventd.qcom.rc: add some audio devce permissions
Change-Id: Ia2f63fc469f62de7d12320db33a4378093e8b2b7
diff --git a/libaudioamp/tfa9887.h b/libaudioamp/tfa9887.h
new file mode 100644
index 0000000..23a1d3d
--- /dev/null
+++ b/libaudioamp/tfa9887.h
@@ -0,0 +1,227 @@
+/*
+ * Copyright (C) 2013, The CyanogenMod Project
+ *
+ * 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.
+ */
+
+#define TFA9887_DEVICE "/dev/tfa9887"
+#define TFA9887L_DEVICE "/dev/tfa9887l"
+
+#define TPA9887_IOCTL_MAGIC 'a'
+#define TPA9887_WRITE_CONFIG _IOW(TPA9887_IOCTL_MAGIC, 0x01, unsigned int)
+#define TPA9887_READ_CONFIG _IOW(TPA9887_IOCTL_MAGIC, 0x02, unsigned int)
+#define TPA9887_ENABLE_DSP _IOW(TPA9887_IOCTL_MAGIC, 0x03, unsigned int)
+#define TPA9887_WRITE_L_CONFIG _IOW(TPA9887_IOCTL_MAGIC, 0x04, unsigned int)
+#define TPA9887_READ_L_CONFIG _IOW(TPA9887_IOCTL_MAGIC, 0x05, unsigned int)
+#define TPA9887_KERNEL_LOCK _IOW(TPA9887_IOCTL_MAGIC, 0x06, unsigned int)
+
+#define TFA9887_DEFAULT_RATE 48000
+
+#define MAX_PATCH_SIZE 3072
+#define MAX_PARAM_SIZE 768
+
+#define PATCH_R "/system/etc/tfa/tfa9887.patch"
+#define PATCH_L "/system/etc/tfa/tfa9887_l.patch"
+#define SPKR_R "/system/etc/tfa/deftcoefA.speaker"
+#define SPKR_L "/system/etc/tfa/deftcoefA_l.speaker"
+
+#define CONFIG_PLAYBACK_R "/system/etc/tfa/playback.config"
+#define CONFIG_PLAYBACK_L "/system/etc/tfa/playback_l.config"
+#define CONFIG_RING_R "/system/etc/tfa/ring.config"
+#define CONFIG_RING_L "/system/etc/tfa/ring_l.config"
+#define CONFIG_VOICE_R "/system/etc/tfa/voice.config"
+#define CONFIG_VOICE_L "/system/etc/tfa/voice_l.config"
+
+#define PRESET_PLAYBACK_R "/system/etc/tfa/playback.preset"
+#define PRESET_PLAYBACK_L "/system/etc/tfa/playback_l.preset"
+#define PRESET_RING_R "/system/etc/tfa/ring.preset"
+#define PRESET_RING_L "/system/etc/tfa/ring_l.preset"
+#define PRESET_VOICE_R "/system/etc/tfa/voice.preset"
+#define PRESET_VOICE_L "/system/etc/tfa/voice_l.preset"
+
+#define EQ_PLAYBACK_R "/system/etc/tfa/playback.eq"
+#define EQ_PLAYBACK_L "/system/etc/tfa/playback_l.eq"
+#define EQ_RING_R "/system/etc/tfa/ring.eq"
+#define EQ_RING_L "/system/etc/tfa/ring_l.eq"
+#define EQ_VOICE_R "/system/etc/tfa/voice.eq"
+#define EQ_VOICE_L "/system/etc/tfa/voice_l.eq"
+
+struct mode_config {
+ const char *config;
+ const char *preset;
+ const char *eq;
+};
+
+typedef enum Tfa9887_Mode {
+ Tfa9887_Mode_Playback = 0,
+ Tfa9887_Mode_Ring,
+ Tfa9887_Mode_Voice,
+ Tfa9887_Num_Modes,
+} Tfa9887_Mode_t;
+
+const struct mode_config Tfa9887_Right_Mode_Configs[Tfa9887_Num_Modes] = {
+ { /* Playback */
+ .config = CONFIG_PLAYBACK_R,
+ .preset = PRESET_PLAYBACK_R,
+ .eq = EQ_PLAYBACK_R
+ },
+ { /* Ring */
+ .config = CONFIG_RING_R,
+ .preset = PRESET_RING_R,
+ .eq = EQ_RING_R
+ },
+ { /* Voice */
+ .config = CONFIG_VOICE_R,
+ .preset = PRESET_VOICE_R,
+ .eq = EQ_VOICE_R
+ }
+};
+
+const struct mode_config Tfa9887_Left_Mode_Configs[Tfa9887_Num_Modes] = {
+ { /* Playback */
+ .config = CONFIG_PLAYBACK_L,
+ .preset = PRESET_PLAYBACK_L,
+ .eq = EQ_PLAYBACK_L,
+ },
+ { /* Ring */
+ .config = CONFIG_RING_L,
+ .preset = PRESET_RING_L,
+ .eq = EQ_RING_L
+ },
+ { /* Voice */
+ .config = CONFIG_VOICE_L,
+ .preset = PRESET_VOICE_L,
+ .eq = EQ_VOICE_L
+ }
+};
+
+typedef enum Tfa9887_Mute {
+ Tfa9887_Mute_Off,
+ Tfa9887_Mute_Digital,
+ Tfa9887_Mute_Amplifier
+} Tfa9887_Mute_t;
+
+/* possible memory values for DMEM in CF_CONTROLs */
+typedef enum {
+ Tfa9887_DMEM_PMEM = 0,
+ Tfa9887_DMEM_XMEM,
+ Tfa9887_DMEM_YMEM,
+ Tfa9887_DMEM_IOMEM,
+} Tfa9887_DMEM_e;
+
+#define MIN(a,b) ((a)<(b)?(a):(b))
+#define ROUND_DOWN(a,n) (((a)/(n))*(n))
+
+/* modules */
+#define MODULE_SPEAKERBOOST 1
+#define MODULE_BIQUADFILTERBANK 2
+
+/* RPC commands */
+#define PARAM_SET_LSMODEL 0x06 // Load a full model into SpeakerBoost.
+#define PARAM_SET_LSMODEL_SEL 0x07 // Select one of the default models present in Tfa9887 ROM.
+#define PARAM_SET_EQ 0x0A // 2 Equaliser Filters.
+#define PARAM_SET_PRESET 0x0D // Load a preset
+#define PARAM_SET_CONFIG 0x0E // Load a config
+#define PARAM_GET_RE0 0x85 /* gets the speaker calibration impedance (@25 degrees celsius) */
+#define PARAM_GET_LSMODEL 0x86 // Gets current LoudSpeaker Model.
+#define PARAM_GET_STATE 0xC0
+
+/* RPC Status results */
+#define STATUS_OK 0
+#define STATUS_INVALID_MODULE_ID 2
+#define STATUS_INVALID_PARAM_ID 3
+#define STATUS_INVALID_INFO_ID 4
+
+/* maximum number of bytes in 1 I2C write transaction */
+#define MAX_I2C_LENGTH 254
+
+/* REVISION values */
+#define TFA9887_REV_N1C 0x11
+#define TFA9887_REV_N1D 0x12
+
+/* I2S_CONTROL bits */
+#define TFA9887_I2SCTRL_RATE_SHIFT (12)
+#define TFA9887_I2SCTRL_RATE_08000 (0<<TFA9887_I2SCTRL_RATE_SHIFT)
+#define TFA9887_I2SCTRL_RATE_11025 (1<<TFA9887_I2SCTRL_RATE_SHIFT)
+#define TFA9887_I2SCTRL_RATE_12000 (2<<TFA9887_I2SCTRL_RATE_SHIFT)
+#define TFA9887_I2SCTRL_RATE_16000 (3<<TFA9887_I2SCTRL_RATE_SHIFT)
+#define TFA9887_I2SCTRL_RATE_22050 (4<<TFA9887_I2SCTRL_RATE_SHIFT)
+#define TFA9887_I2SCTRL_RATE_24000 (5<<TFA9887_I2SCTRL_RATE_SHIFT)
+#define TFA9887_I2SCTRL_RATE_32000 (6<<TFA9887_I2SCTRL_RATE_SHIFT)
+#define TFA9887_I2SCTRL_RATE_44100 (7<<TFA9887_I2SCTRL_RATE_SHIFT)
+#define TFA9887_I2SCTRL_RATE_48000 (8<<TFA9887_I2SCTRL_RATE_SHIFT)
+
+#define TFA9887_I2SCTRL_CHANSEL_SHIFT 3
+#define TFA9887_I2SCTRL_INPUT_SEL_SHIFT 6
+
+#define TFA9887_I2SCTRL_DATAI2_SHIFT 5
+
+#define TFA9887_I2SSEL_I2SOUT_LEFT_SHIFT 0
+#define TFA9887_I2SSEL_I2SOUT_RIGHT_SHIFT 3
+
+/* SYSTEM CONTROL bits */
+#define TFA9887_SYSCTRL_POWERDOWN (1<<0)
+#define TFA9887_SYSCTRL_RESETI2C (1<<1)
+#define TFA9887_SYSCTRL_ENBL_AMP (1<<3)
+#define TFA9887_SYSCTRL_CONFIGURED (1<<5)
+#define TFA9887_SYSCTRL_SEL_ENBL_AMP (1<<6)
+
+/* Audio control bits */
+#define TFA9887_AUDIOCTRL_MUTE (1<<5)
+
+/* STATUS bits */
+#define TFA9887_STATUS_VDDS (1<<0) /* */
+#define TFA9887_STATUS_PLLS (1<<1) /* plls locked */
+#define TFA9887_STATUS_OTDS (1<<2) /* */
+#define TFA9887_STATUS_OVDS (1<<3) /* */
+#define TFA9887_STATUS_UVDS (1<<4) /* */
+#define TFA9887_STATUS_OCDS (1<<5) /* */
+#define TFA9887_STATUS_CLKS (1<<6) /* clocks stable */
+#define TFA9887_STATUS_MTPB (1<<8) /*MTP busy operation*/
+#define TFA9887_STATUS_DCCS (1<<9) /* */
+#define TFA9887_STATUS_ACS (1<<11) /* cold started */
+#define TFA9887_STATUS_SWS (1<<12) /* amplifier switching */
+
+/* MTP bits */
+#define TFA9887_MTP_MTPOTC (1<<0) /* one time calibration */
+#define TFA9887_MTP_MTPEX (1<<1) /* one time calibration done */
+
+#define TFA9887_STATUS (0x00)
+#define TFA9887_BATTERYVOLTAGE (0x01)
+#define TFA9887_TEMPERATURE (0x02)
+#define TFA9887_REVISIONNUMBER (0x03)
+#define TFA9887_I2S_CONTROL (0x04)
+#define TFA9887_BAT_PROT (0x05)
+#define TFA9887_AUDIO_CONTROL (0x06)
+#define TFA9887_DCDCBOOST (0x07)
+#define TFA9887_SPKR_CALIBRATION (0x08)
+#define TFA9887_SYSTEM_CONTROL (0x09)
+#define TFA9887_I2S_SEL (0x0a)
+#define TFA9887_RESERVE1 (0x0c)
+#define TFA9887_RESERVE2 (0x0d)
+#define TFA9887_HIDE_UNHIDE_KEY (0x40)
+#define TFA9887_PWM_CONTROL (0x41)
+#define TFA9887_CURRENTSENSE1 (0x46)
+#define TFA9887_CURRENTSENSE2 (0x47)
+#define TFA9887_CURRENTSENSE3 (0x48)
+#define TFA9887_CURRENTSENSE4 (0x49)
+#define TFA9887_ABISTTEST (0x4c)
+#define TFA9887_MTP_COPY (0x62)
+#define TFA9887_CF_CONTROLS (0x70)
+#define TFA9887_CF_MAD (0x71)
+#define TFA9887_CF_MEM (0x72)
+#define TFA9887_CF_STATUS (0x73)
+#define TFA9887_MTP (0x80)
+
+int tfa9887_init(void);
+int tfa9887_set_mode(audio_mode_t mode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment