基于高通MSM8953平台的android系统SGM41511充电IC驱动开发
4.1、修改msm8953-no-pmi.dts:
修改/kernel/msm-4.9/arch/arm64/boot/dts/qcom/msm8953-no-pmi.dts,增加:
+&tlmm {
+ sgm41511_int_active: sgm41511_int_active {
+ mux {
+ pins = "gpio42";
+ function = "gpio";
+ };
+
+ config {
+ pins = "gpio42";
+ drive-strength = <2>;
+ bias-pull-up;
+ };
+ };
+};
+
+&i2c_3 {
+ status = "ok";
+ sgm41511@6b {
+ compatible = "sgm41511";
+ reg = <0x6b>;
+ sgm,charge-enable-gpio = <&tlmm 44 0x00>;
+ sgm,interrupt-gpio = <&tlmm 42 0x00>;
+ pinctrl-names = "default";
+ pinctrl-0 = <&sgm41511_int_active>;
+ };
+};
4.2、修改sdm450-no-pmi.dts:
修改/kernel/msm-4.9/arch/arm64/boot/dts/qcom/sdm450-no-pmi.dts,增加:
+&tlmm {
+ sgm41511_int_active: sgm41511_int_active {
+ mux {
+ pins = "gpio42";
+ function = "gpio";
+ };
+
+ config {
+ pins = "gpio42";
+ drive-strength = <2>;
+ bias-pull-up;
+ };
+ };
+};
+
+&i2c_3 {
+ status = "ok";
+ qcom,clk-freq-out = <100000>;
+ sgm41511@6b {
+ compatible = "sgm41511";
+ reg = <0x6b>;
+ sgm,charge-enable-gpio = <&tlmm 44 0x00>;
+ sgm,interrupt-gpio = <&tlmm 42 0x00>;
+ pinctrl-names = "default";
+ pinctrl-0 = <&sgm41511_int_active>;
+ };
+};
4.3、修改Makefile:
修改/kernel/msm-4.9/drivers/power/supply/Makefile,增加:
+obj-y += sgm41511_charger.o
4.4、创建文件sgm41511_charger.c:
创建/kernel/msm-4.9/drivers/power/supply/sgm41511_charger.c
+#define pr_fmt(fmt) "%s: " fmt, __func__
+
+#include <linux/version.h>
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/power_supply.h>
+#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/delay.h>
+#include <linux/of_gpio.h>
+#include <linux/of.h>
+#include <linux/err.h>
+#include <linux/extcon.h>
+#include <linux/gpio.h>
+#include <linux/workqueue.h>
+
+#define SGM41511_REG_00 0x00
+#define SGM41511_REG_01 0x01
+#define SGM41511_REG_02 0x02
+#define SGM41511_REG_03 0x03
+#define SGM41511_REG_04 0x04
+#define SGM41511_REG_05 0x05
+#define SGM41511_REG_06 0x06
+#define SGM41511_REG_07 0x07
+#define SGM41511_REG_0B 0x0B
+
+#define SGM41511_WDT_MASK 0x30
+#define SGM41511_WDT_SHIFT 4
+#define SGM41511_WDT_DISABLE 0
+
+#define SGM41511_CHG_CONFIG_MASK 0x10
+#define SGM41511_CHG_CONFIG_SHIFT 4
+#define SGM41511_CHG_ENABLE 1
+#define SGM41511_CHG_DISABLE 0
+
+#define SGM41511_OTG_CONFIG_MASK 0x20
+#define SGM41511_OTG_CONFIG_SHIFT 5
+#define SGM41511_OTG_ENABLE 1
+#define SGM41511_OTG_DISABLE 0
+
+#define SGM41511_PN_MASK 0x78
+#define SGM41511_PN_SHIFT 3
+
+#define SGM41511_WDT_RESET_MASK 0x40
+#define SGM41511_WDT_RESET_SHIFT 6
+#define SGM41511_WDT_RESET 1
+
+#define SGM41511_FORCE_IINDPM_MASK 0x80
+#define SGM41511_FORCE_IINDPM_SHIFT 7
+#define SGM41511_FORCE_IINDPM_ENABLE 1
+#define SGM41511_FORCE_IINDPM_DISABLE 0
+
+#define SGM41511_VINDPM_MASK 0x0F
+#define SGM41511_VINDPM_SHIFT 0
+#define SGM41511_VINDPM_BASE 3900
+#define SGM41511_VINDPM_LSB 100
+
+#define SGM41511_IINLIM_MASK 0x1F
+#define SGM41511_IINLIM_SHIFT 0
+#define SGM41511_IINLIM_BASE 100
+#define SGM41511_IINLIM_LSB 100
+
+#define SGM41511_VREG_MASK 0xF1
+#define SGM41511_VREG_SHIFT 3
+#define SGM41511_VREG_BASE 3856
+#define SGM41511_VREG_LSB 32
+
+#define SGM41511_ICHG_MASK 0x3F
+#define SGM41511_ICHG_SHIFT 0
+#define SGM41511_ICHG_BASE 0
+#define SGM41511_ICHG_LSB 60
+
+#define SGM41511_ITERM_MASK 0x0F
+#define SGM41511_ITERM_SHIFT 0
+#define SGM41511_ITERM_BASE 60
+#define SGM41511_ITERM_LSB 60
+
+struct sgm41511 {
+ int part_no;
+ int usb_vbus_gpio;
+ int usb_vbus_irq;
+ int enable_gpio;
+ int charge_online;
+ bool otg_enabled;
+ bool charge_enabled;
+
+ struct device *dev;
+ struct i2c_client *client;
+ struct mutex i2c_rw_lock;
+ struct extcon_dev *extcon_dev;
+ struct notifier_block id_nb;
+ struct delayed_work otg_work;
+ struct delayed_work irq_work;
+ struct power_supply *usb_psy;
+};
+
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!