PM8909 MPP4腳作為外部ADC採用使用

2021-10-14 17:29:36 字數 1624 閱讀 3910

pm8909的adc內部架構如圖所示(參考《80-nn174-58_b_pmic_adc_software_user_guide.pdf》):

mpp configuration就是在裝置樹里配置:

pm8909_mpps: mpps ;

};&pm8909_mpps ;

};採用通道0x13(就是19:p_mux4_1_1通道)註冊,這裡是必須要加的,否則讀這個通道出錯:

//stone added for mpp4 as adc

chan@13 ;

測試時,需要讀取p_mux4_1_1通道:

static int get_battery_voltage(struct qpnp_bms_chip *chip, int *result_uv)

//end: stone added for test

……如果需要測試0-5v的範圍,可以使用35通道,修改的地方只是通道註冊改為0x23,呼叫時用p_mux4_1_3即可。

參考補丁:

diff --git a/kernel/msm-3.18/arch/arm/boot/dts/msm-pm8909.dtsi b/kernel/msm-3.18/arch/arm/boot/dts/msm-pm8909.dtsi

index c3e402802a..12dc08e6fa 100755

--- a/kernel/msm-3.18/arch/arm/boot/dts/msm-pm8909.dtsi

+++ b/kernel/msm-3.18/arch/arm/boot/dts/msm-pm8909.dtsi

@@ -196,13 +196,14 @@

interrupts = <0x0 0x61 0x1>;

};};

-+ //stone added for mpp4 as adc

+ /*

qcom,leds@a300 ;

-+ */

pm8909_chg: qcom,charger ;

++ //stone added for mpp4 as adc

+ chan@23 ;

+ };

&pm8909_adc_tm ;

}; +//stone added for mpp4 as adc

+/* &spmi_bus ;

};};+*/

&sdc2_cd_on ;

- mpp@a300 ;

+*/+ mpp@a300 ;

+ };

&mdss_mdp

+ //end: stone added for debug

+ rc = qpnp_vadc_read(chip->vadc_dev, vbat_sns, &adc_result);

if (rc) {

pr_err("error reading adc channel = %d, rc = %d\n",