0. 背景
平台: android_9\LA.UM.7.2.r1\ ,SDM660
LA.UM.7.2.r1\kernel\msm-4.4\sound\soc\codecs\sdm660_cdc\msm-analog-cdc.c
高通代码默认打开了Boost模式,这玩意会影响功耗,如下:
static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1);
static struct snd_soc_dai_driver msm_anlg_cdc_i2s_dai[];
/* By default enable the internal speaker boost */
static bool spkr_boost_en = true;
C:\Users\Administrator>adb shell
sdm660_64:/ # tinymix | grep Boost
tinymix | grep Boost
75 ENUM 1 Boost Option BOOST_SWITCH
76 ENUM 1 EAR PA Boost DISABLE
78 ENUM 1 Speaker Boost ENABLE
79 ENUM 1 Ext Spk Boost DISABLE
但是你用tinyalsa命令把这个控件关闭,设备喇叭就直接没声音了-_- ||:
sdm660_64:/ # tinymix "Speaker Boost" "DISABLE"
tinymix "Speaker Boost" "DISABLE"
sdm660_64:/ #
sdm660_64:/ # tinymix | grep Boost
tinymix | grep Boost
75 ENUM 1 Boost Option BOOST_SWITCH
76 ENUM 1 EAR PA Boost DISABLE
78 ENUM 1 Speaker Boost DISABLE
79 ENUM 1 Ext Spk Boost DISABLE
1. 修改方案
对比其他默认关闭Boost的平台,发现了这个寄存器差异:
检索这个宏,发现定义,第三个参数是偏移位,SND_SOC_NOPM默认值是 -1
./kernel/msm-4.4/include/sound/soc-dapm.h
struct device;
/* widget has no PM register bit */
#define SND_SOC_NOPM -1
/*
* SoC dynamic audio power management
*
* We can have up to 4 power domains
* 1. Codec domain - VREF, VMID
$ grep -nr "SND_SOC_DAPM_PGA_E" ./kernel/msm-4.9/
./kernel/msm-4.9/include/sound/soc-dapm.h:139:#define SND_SOC_DAPM_PGA_E
(wname, wreg, wshift, winvert, wcontrols, \
$ vim ./kernel/msm-4.9/include/sound/soc-dapm.h +139
/* path domain with event - event handler must return 0 for success */
#define SND_SOC_DAPM_PGA_E(wname, wreg, wshift, winvert, wcontrols, \
wncontrols, wevent, wflags) \
{ .id = snd_soc_dapm_pga, .name = wname, \
SND_SOC_DAPM_INIT_REG_VAL(wreg, wshift, winvert), \
.kcontrol_news = wcontrols, .num_kcontrols = wncontrols, \
.event = wevent, .event_flags = wflags}
MSM89XX_PMIC_ANALOG_SPKR_DRV_CTL的高通寄存器介绍如下:
2. 偏移7位对应Bits7,最终修改patch如下
diff --git a/kernel/msm-4.4/sound/soc/codecs/sdm660_cdc/msm-analog-cdc.c
b/kernel/msm-4.4/sound/soc/codecs/sdm660_cdc/msm-analog-cdc.c
index dcf1e9f..a6ade34 100755
--- a/kernel/msm-4.4/sound/soc/codecs/sdm660_cdc/msm-analog-cdc.c
+++ b/kernel/msm-4.4/sound/soc/codecs/sdm660_cdc/msm-analog-cdc.c
@@ -3423,10 +3423,10 @@
msm_anlg_cdc_hph_pa_event, SND_SOC_DAPM_PRE_PMU |
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
SND_SOC_DAPM_POST_PMD),
- SND_SOC_DAPM_PGA_E("SPK PA", SND_SOC_NOPM,
- 0, 0, NULL, 0, msm_anlg_cdc_codec_enable_spk_pa,
- SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
- SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
+ SND_SOC_DAPM_PGA_E("SPK PA", MSM89XX_PMIC_ANALOG_SPKR_DRV_CTL,
+ 7, 0, NULL, 0, msm_anlg_cdc_codec_enable_spk_pa,
+ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
+ SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
SND_SOC_DAPM_PGA_E("LINEOUT PA", MSM89XX_PMIC_ANALOG_RX_LO_EN_CTL,
5, 0, NULL, 0, msm_anlg_cdc_codec_enable_lo_pa,
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
diff --git a/kernel/msm-4.4/sound/soc/msm/sdm660-internal.c
b/kernel/msm-4.4/sound/soc/msm/sdm660-internal.c
old mode 100644
new mode 100755
index 4e2a403..69b1f03
--- a/kernel/msm-4.4/sound/soc/msm/sdm660-internal.c
+++ b/kernel/msm-4.4/sound/soc/msm/sdm660-internal.c
@@ -32,6 +32,8 @@
#define WSA8810_NAME_1 "wsa881x.20170211"
#define WSA8810_NAME_2 "wsa881x.20170212"
+extern void msm_anlg_cdc_update_int_spk_boost(bool enable);
+
enum {
INT0_MI2S = 0,
INT1_MI2S,
@@ -495,6 +497,7 @@
if (pdata->spk_ext_pa_gpio < 0) {
dev_dbg(&pdev->dev,
"%s: missing %s in dt node\n", __func__, spk_ext_pa);
+ return -EINVAL;
} else {
if (!gpio_is_valid(pdata->spk_ext_pa_gpio)) {
pr_err("%s: Invalid external speaker gpio: %d",
@@ -3170,11 +3173,12 @@
int ret;
ret = is_ext_spk_gpio_support(pdev, pdata);
- if (ret < 0)
+ if (ret < 0){
+ msm_anlg_cdc_update_int_spk_boost(false);
dev_dbg(&pdev->dev,
"%s: doesn't support external speaker pa\n",
__func__);
-
+ }
ret = of_property_read_string(pdev->dev.of_node,
hs_micbias_type, &type);
if (ret) {
@@ -3243,7 +3247,7 @@
struct wcd_mbhc_config *mbhc_cfg)
{
mbhc_cfg_ptr = mbhc_cfg;
-
+
*card = msm_int_populate_sndcard_dailinks(&pdev->dev);
msm_internal_init(pdev, pdata, *card);
return 0;
3. 作者注
/******
@article{Linux Audio Driver,
Author = { 1byte ≠ 8bit},
Year = { 2020},
}
******/