Android中Input型输入设备驱动原理分析<一>

本文详细分析了Android系统中输入设备驱动的核心原理,特别是Event事件驱动机制,从驱动架构、注册流程到具体实现,全方位揭示了Android底层输入管理的奥秘。

话说Android中Event输入设备驱动原理分析还不如说Linux输入子系统呢,反正这个是没变的,在android的底层开发中对于Linux的基本驱动程序设计还是没变的,当然Android底层机制也增加几个属于android自己的机制。典型的IPC

Android中的input设备驱动主要包括:游戏杆(joystick)、鼠标(mouse)和事件设备(Event)。

1、Input输入子系统的构架,在网上找到两幅灰常漂亮的图。

下面这幅更漂亮,更直观的能看出input型输入子系统究竟是什么咚咚,更能够体现出,用户空间,内核空间,驱动程序是怎么关联起来的。。。


Input驱动同样也是字符设备,主设备号是13,次设备号是64~95之间自动生成的,这个Input驱动程序那是相当相当的复杂。在android内核中主要需要关注一下几个文件

a)include/linux/input.h(驱动头文件)

b)driver/input/input.c (驱动核心实现,包含大量的操作接口)

c)driver/input/event.c (事件驱动)

d)driver/input/joydev.c(游戏杆驱动)

e)driver/input/mousedev.c(鼠标驱动)

其实上面这些东西都不要我们自己去实现内核已经帮我们实现好了,不过我们在写硬件驱动的时候需要和Inputcore交互,所以需要用到上面这些函数中的接口,也就是说上面这些函数是透明的

2、Event事件驱动原理及其实现

在内核中,用input_dev来描述一个Input设备,该结构的定义如下,

其中内核中使用input_register_device(struct input_dev *dev)来注册一个input设备

这个结构体好长,所以就列了几个。。。。它的定义在input.h当中

struct input_dev {

。。。。。。。。。。。
struct input_id id;/*指向input_id结构*/
bool sync;
struct device dev;/**这些设备都归属总线设备模型*/
struct list_head h_list; //
struct list_head node; //input_handle链表的list节点
};

用input_handler表示input设备的接口,使用input_register_handler(struct input_handler *handler)注册

struct input_handler {

void *private;

。。。。。。。。。。
int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
void (*disconnect)(struct input_handle *handle);
void (*start)(struct input_handle *handle);

const struct file_operations *fops;
int minor;
const char *name;

const struct input_device_id *id_table;

struct list_head h_list;
struct list_head node;
};

饿了写不下去了


&twi6 { clock-frequency = <200000>; pinctrl-0 = <&s_twi0_pins_a>; pinctrl-1 = <&s_twi0_pins_b>; no_suspend = <1>; twi_drv_used = <1>; status = "okay"; pmu0: pmu@34 { /* 1. 核心兼容性调整:AXP707 归属 AXP803 驱动系列 */ compatible = "x-powers,axp803"; reg = <0x34>; /* AXP707 I2C 地址 AXP2202 致 */ status = "okay"; interrupts = <0 IRQ_TYPE_LEVEL_LOW>; interrupt-parent = <&nmi_intc>; /* 中断父控制器保持不变 */ x-powers,drive-vbus-en; /* AXP707 支持 VBUS 驱动 */ pmu_reset = <0>; /* 长按16s关机(0=关机,1=重启,AXP803/707 支持) */ pmu_irq_wakeup = <1>; /* 允许 PMIC 中断唤醒 */ pmu_hot_shutdown = <1>; /* 使能过温保护(AXP803/707 支持) */ wakeup-source; /* 2. USB 电源管理:兼容 AXP803 驱动 */ usb_power_supply: usb_power_supply { compatible = "x-powers,axp803-usb-power-supply"; status = "okay"; /* 输入限流限压参数(AXP707 支持范围 AXP2202 致,保留原数值) */ pmu_usbpc_vol = <4600>; /* USB PC 输入电压限制(mV) */ pmu_usbpc_cur = <500>; /* USB PC 输入电流限制(mA) */ pmu_usbad_vol = <4000>; /* USB 适配器输入电压限制(mV) */ pmu_usbad_cur = <2500>; /* USB 适配器输入电流限制(mA) */ pmu_usb_typec_used = <1>; /* 启用 Type-C 功能(AXP707 支持简单 CC 逻辑) */ wakeup_usb_in; /* USB 插入唤醒 */ wakeup_usb_out; /* USB 拔出唤醒 */ }; /* 3. 多口充电配置:AXP707 支持旧式 ACIN 方案 */ gpio_power_supply: gpio_power_supply { compatible = "x-powers,axp803-acin-power-supply"; /* 适配 AXP803 系列 */ status = "disabled"; /* 保持原禁用状态 */ pmu_acin_det_gpio = <&pio PH 14 GPIO_ACTIVE_LOW>; /* 多口检测 GPIO */ pmu_acin_usbid_drv = <&pio PH 12 GPIO_ACTIVE_LOW>; /* USB-ID 替代 GPIO */ pmu_vbus_det_gpio = <&pio PH 13 GPIO_ACTIVE_LOW>; /* VBUS 检测 GPIO */ wakeup_gpio; /* GPIO 唤醒使能 */ }; /* 4. 电池管理:兼容 AXP803 驱动 */ bat_power_supply: bat-power-supply { compatible = "x-powers,axp803-battery-power-supply"; param = <&axp803_parameter>; /* 关联 AXP803 电池参数 */ status = "okay"; pmu_chg_ic_temp = <0>; /* 不读取 PMIC 芯片温度 */ /* 电池基础参数(根据 AXP707 硬件调整,示例值参考原配置) */ pmu_battery_rdc = <119>; /* 电池内阻(mΩ) */ pmu_battery_cap = <5000>; /* 电池容量(mAh) */ pmu_runtime_chgcur = <1100>; /* 运行时充电电流(mA) */ pmu_suspend_chgcur = <1800>; /* 休眠时充电电流(mA) */ pmu_shutdown_chgcur = <1800>; /* 关机时充电电流(mA) */ pmu_init_chgvol = <4350>; /* 电池满充电压(mV,AXP707 支持 4.35V) */ pmu_battery_warning_level1 = <15>; /* 低电警告1(15%) */ pmu_battery_warning_level2 = <0>; /* 低电警告2(0%) */ pmu_chgled_func = <0>; /* 充电指示灯由 PMU 控制 */ pmu_chgled_type = <0>; /* 指示灯模式 A */ /* 电流电量计参数(AXP707 支持 32 段曲线,保留原数值) */ pmu_bat_para1 = <0>; pmu_bat_para2 = <0>; pmu_bat_para3 = <0>; pmu_bat_para4 = <0>; pmu_bat_para5 = <0>; pmu_bat_para6 = <0>; pmu_bat_para7 = <2>; pmu_bat_para8 = <3>; pmu_bat_para9 = <4>; pmu_bat_para10 = <6>; pmu_bat_para11 = <9>; pmu_bat_para12 = <14>; pmu_bat_para13 = <26>; pmu_bat_para14 = <38>; pmu_bat_para15 = <49>; pmu_bat_para16 = <52>; pmu_bat_para17 = <56>; pmu_bat_para18 = <60>; pmu_bat_para19 = <64>; pmu_bat_para20 = <70>; pmu_bat_para21 = <77>; pmu_bat_para22 = <83>; pmu_bat_para23 = <87>; pmu_bat_para24 = <90>; pmu_bat_para25 = <95>; pmu_bat_para26 = <99>; pmu_bat_para27 = <99>; pmu_bat_para28 = <100>; pmu_bat_para29 = <100>; pmu_bat_para30 = <100>; pmu_bat_para31 = <100>; pmu_bat_para32 = <100>; /* NTC 温控配置(AXP707 支持 JEITA,保留原参数) */ pmu_bat_temp_enable = <1>; /* 启用电池温度检测 */ pmu_jetia_en = <1>; /* 启用 JEITA 规范 */ pmu_bat_charge_ltf = <1738>; /* 低温停充阈值(-5℃,mV) */ pmu_bat_charge_htf = <150>; /* 高温停充阈值(60℃,mV) */ pmu_bat_shutdown_ltf = <2125>; /* 低温关机阈值(-10℃,mV) */ pmu_bat_shutdown_htf = <130>; /* 高温关机阈值(65℃,mV) */ pmu_jetia_cool = <1390>; /* 低温限流阈值(0℃,mV) */ pmu_jetia_warm = <206>; /* 高温限流阈值(50℃,mV) */ pmu_jcool_ifall = <2>; /* 低温限流比例(75%) */ pmu_jwarm_ifall = <2>; /* 高温限流比例(75%) */ /* NTC 温度-电压对应参数(AXP707 支持 16 段,保留原数值) */ pmu_bat_temp_para1 = <4592>; /* -25℃ 对应电压(mV) */ pmu_bat_temp_para2 = <2781>; /* -15℃ 对应电压(mV) */ pmu_bat_temp_para3 = <2125>; /* -10℃ 对应电压(mV) */ pmu_bat_temp_para4 = <1738>; /* -5℃ 对应电压(mV) */ pmu_bat_temp_para5 = <1390>; /* 0℃ 对应电压(mV) */ pmu_bat_temp_para6 = <1118>; /* 5℃ 对应电压(mV) */ pmu_bat_temp_para7 = <906>; /* 10℃ 对应电压(mV) */ pmu_bat_temp_para8 = <606>; /* 20℃ 对应电压(mV) */ pmu_bat_temp_para9 = <415>; /* 30℃ 对应电压(mV) */ pmu_bat_temp_para10 = <290>; /* 40℃ 对应电压(mV) */ pmu_bat_temp_para11 = <244>; /* 45℃ 对应电压(mV) */ pmu_bat_temp_para12 = <206>; /* 50℃ 对应电压(mV) */ pmu_bat_temp_para13 = <175>; /* 55℃ 对应电压(mV) */ pmu_bat_temp_para14 = <150>; /* 60℃ 对应电压(mV) */ pmu_bat_temp_para15 = <110>; /* 70℃ 对应电压(mV) */ pmu_bat_temp_para16 = <83>; /* 80℃ 对应电压(mV) */ /* 唤醒源配置(AXP707 支持的唤醒事件) */ wakeup_bat_out; /* 电池拔出唤醒 */ wakeup_new_soc; /* 电量更新唤醒 */ wakeup_bat_untemp_work; /* 电池低温工作唤醒 */ wakeup_bat_ovtemp_work; /* 电池高温工作唤醒 */ /* 注释不使用的唤醒源 */ /* wakeup_bat_in; */ /* wakeup_bat_charging; */ /* wakeup_bat_charge_over; */ /* wakeup_low_warning1; */ /* wakeup_low_warning2; */ /* wakeup_bat_untemp_chg; */ /* wakeup_bat_ovtemp_chg; */ }; /* 5. 电源按键配置:AXP 全系列兼容 axp2101-pek */ powerkey0: powerkey@0 { status = "okay"; compatible = "x-powers,axp2101-pek"; /* 单 PMIC 方案通用兼容名 */ pmu_powkey_off_time = <6000>; /* 长按 6s 触发关机 */ pmu_powkey_off_func = <0>; /* 关机功能(0=关机,1=复位) */ pmu_powkey_off_en = <1>; /* 启用按键关机 */ pmu_powkey_long_time = <1500>; /* 长按判定时间(1.5s) */ pmu_powkey_on_time = <512>; /* 开机按键时间(0.512s) */ wakeup_rising; /* 按键弹起唤醒 */ wakeup_falling; /* 按键按下唤醒 */ }; /* 6. Regulator 配置:AXP707 通道参数调整 */ regulator0: regulators@0 { /* DCDC1:核心供电,电压范围适配 AXP707(800mV~1.8V) */ reg_dcdc1: dcdc1 { regulator-name = "axp803-dcdc1"; regulator-min-microvolt = <800000>; /* AXP707 DCDC1 最小电压 */ regulator-max-microvolt = <1800000>; /* AXP707 DCDC1 最大电压 */ regulator-ramp-delay = <250>; /* 调压延时(us) */ regulator-enable-ramp-delay = <1000>; /* 使能延时(us) */ regulator-boot-on; /* 启动时开启 */ regulator-always-on; /* 保持常开 */ }; /* DCDC2:系统供电,电压范围适配 AXP707(800mV~3.3V) */ reg_dcdc2: dcdc2 { regulator-name = "axp803-dcdc2"; regulator-min-microvolt = <800000>; /* AXP707 DCDC2 最小电压 */ regulator-max-microvolt = <3300000>; /* AXP707 DCDC2 最大电压 */ regulator-ramp-delay = <250>; regulator-enable-ramp-delay = <1000>; regulator-boot-on; regulator-always-on; }; /* DCDC3:外设供电,电压范围适配 AXP707(800mV~1.8V) */ reg_dcdc3: dcdc3 { regulator-name = "axp803-dcdc3"; regulator-min-microvolt = <800000>; regulator-max-microvolt = <1800000>; regulator-ramp-delay = <250>; regulator-enable-ramp-delay = <1000>; regulator-always-on; }; /* DCDC4:可选供电,电压范围适配 AXP707(1.0V~3.7V) */ reg_dcdc4: dcdc4 { regulator-name = "axp803-dcdc4"; regulator-min-microvolt = <1000000>; regulator-max-microvolt = <3700000>; regulator-ramp-delay = <250>; regulator-enable-ramp-delay = <1000>; }; /* RTC LDO:固定 1.8V,AXP707 支持 */ reg_rtcldo: rtcldo { regulator-name = "axp803-rtcldo"; regulator-min-microvolt = <1800000>; regulator-max-microvolt = <1800000>; regulator-boot-on; regulator-always-on; }; /* ALDO1~4:AXP707 支持的低压差线性稳压器 */ reg_aldo1: aldo1 { regulator-name = "axp803-aldo1"; regulator-min-microvolt = <800000>; /* AXP707 ALDO 最小电压 */ regulator-max-microvolt = <3300000>; /* AXP707 ALDO 最大电压 */ regulator-enable-ramp-delay = <1000>; }; reg_aldo2: aldo2 { regulator-name = "axp803-aldo2"; regulator-min-microvolt = <800000>; regulator-max-microvolt = <3300000>; regulator-enable-ramp-delay = <1000>; }; reg_aldo3: aldo3 { regulator-name = "axp803-aldo3"; regulator-min-microvolt = <800000>; regulator-max-microvolt = <3300000>; regulator-enable-ramp-delay = <1000>; regulator-always-on; regulator-boot-on; }; reg_aldo4: aldo4 { regulator-name = "axp803-aldo4"; regulator-min-microvolt = <800000>; regulator-max-microvolt = <3300000>; regulator-enable-ramp-delay = <1000>; regulator-always-on; regulator-boot-on; }; /* BLDO1~4:AXP707 支持的背光 LDO */ reg_bldo1: bldo1 { regulator-name = "axp803-bldo1"; regulator-min-microvolt = <800000>; regulator-max-microvolt = <3300000>; regulator-enable-ramp-delay = <1000>; }; reg_bldo2: bldo2 { regulator-name = "axp803-bldo2"; regulator-min-microvolt = <800000>; regulator-max-microvolt = <3300000>; regulator-enable-ramp-delay = <1000>; regulator-boot-on; regulator-always-on; }; reg_bldo3: bldo3 { regulator-name = "axp803-bldo3"; regulator-min-microvolt = <800000>; regulator-max-microvolt = <3300000>; regulator-enable-ramp-delay = <1000>; }; reg_bldo4: bldo4 { regulator-name = "axp803-bldo4"; regulator-min-microvolt = <800000>; regulator-max-microvolt = <3300000>; regulator-enable-ramp-delay = <1000>; }; /* CPU LDO:AXP707 专用 CPU 供电 */ reg_cpusldo: cpusldo { regulator-name = "axp803-cpusldo"; regulator-min-microvolt = <800000>; /* CPU 最小供电电压 */ regulator-max-microvolt = <1400000>; /* CPU 最大供电电压 */ regulator-boot-on; regulator-always-on; }; /* VMID:AXP707 升压供电,为 VBUS 驱动提供电源 */ reg_vmid: vmid { regulator-name = "axp803-vmid"; regulator-enable-ramp-delay = <1000>; }; /* VBUS 驱动:AXP707 支持,依赖 VMID 供电 */ reg_drivevbus: drivevbus { regulator-name = "axp803-drivevbus"; regulator-enable-ramp-delay = <1000>; drivevbusin-supply = <&reg_vmid>; /* 关联 VMID 电源 */ }; }; /* 7. 虚拟 Regulator:用于调试,适配 AXP803 命名 */ virtual-dcdc1 { compatible = "xpower-vregulator,dcdc1"; dcdc1-supply = <&reg_dcdc1>; }; virtual-dcdc2 { compatible = "xpower-vregulator,dcdc2"; dcdc2-supply = <&reg_dcdc2>; }; virtual-dcdc3 { compatible = "xpower-vregulator,dcdc3"; dcdc3-supply = <&reg_dcdc3>; }; virtual-dcdc4 { compatible = "xpower-vregulator,dcdc4"; dcdc4-supply = <&reg_dcdc4>; }; virtual-rtcldo { compatible = "xpower-vregulator,rtcldo"; rtcldo-supply = <&reg_rtcldo>; }; virtual-aldo1 { compatible = "xpower-vregulator,aldo1"; aldo1-supply = <&reg_aldo1>; }; virtual-aldo2 { compatible = "xpower-vregulator,aldo2"; aldo2-supply = <&reg_aldo2>; }; virtual-aldo3 { compatible = "xpower-vregulator,aldo3"; aldo3-supply = <&reg_aldo3>; }; virtual-aldo4 { compatible = "xpower-vregulator,aldo4"; aldo4-supply = <&reg_aldo4>; }; virtual-bldo1 { compatible = "xpower-vregulator,bldo1"; bldo1-supply = <&reg_bldo1>; }; virtual-bldo2 { compatible = "xpower-vregulator,bldo2"; bldo2-supply = <&reg_bldo2>; }; virtual-bldo3 { compatible = "xpower-vregulator,bldo3"; bldo3-supply = <&reg_bldo3>; }; virtual-bldo4 { compatible = "xpower-vregulator,bldo4"; bldo4-supply = <&reg_bldo4>; }; virtual-cpusldo { compatible = "xpower-vregulator,cpusldo"; cpusldo-supply = <&reg_cpusldo>; }; virtual-drivevbus { compatible = "xpower-vregulator,drivevbus"; drivevbus-supply = <&reg_drivevbus>; }; /* 8. 删除 AXP707 不支持的 PMIC GPIO 节点(文档表1-2:仅 AXP22x 支持) */ }; }; /* 9. 电池参数节点:适配 AXP803/707 */ /{ axp803_parameter: axp803-parameter { select = "battery-model"; /* 选择电池模 */ battery-model { /* 电池参数数组:需根据 AXP707 硬件和实际电池特性调整 */ /* 以下为示例值,实际需参考《X-POWERS 电池参数测试系统使用说明》测量 */ parameter = /bits/ 8 < 0x01 0xf5 0x40 0x00 0x1b 0x1e 0x28 0x0f 0x0c 0x1e 0x32 0x02 0x14 0x05 0x0a 0x04 0x74 0xfc 0x2c 0x0d 0x43 0x10 0xcc 0xfb 0x64 0x01 0xea 0x13 0x5c 0x06 0xcc 0x06 0xad 0x0b 0x73 0x10 0x04 0x0f 0x9c 0x0a 0x4c 0x0f 0xf7 0x0e 0xf0 0x04 0xe1 0x04 0xd3 0x09 0xc8 0x0e 0xb9 0x0e 0xb4 0x09 0xa9 0x0e 0x95 0x0e 0x93 0x04 0x83 0x04 0x6e 0x09 0x69 0x0e 0x5e 0x0e 0x09 0x08 0x03 0x4c 0x25 0x23 0x1b 0x0b 0x13 0x07 0xc5 0x98 0x7e 0x66 0x4e 0x44 0x38 0x1a 0x12 0x0a 0xf6 0x00 0x00 0xf6 0x00 0xf6 0x00 0xfb 0x00 0x00 0xfb 0x00 0x00 0xfb 0x00 0x00 0xf6 0x00 0x00 0xf6 0x00 0xf6 0x00 0xfb 0x00 0x00 0xfb 0x00 0x00 0xfb 0x00 0x00 0xf6 0x00 0x00 0xf6 0x00 0xf6 >; }; }; }; also defined at /media/wx/disk16t/A133/A133-Android14-V1.1/android13/longan/device/config/chips/a133/configs/p25/board.dts:1065.7-1125.3 /media/wx/disk16t/A133/A133-Android14-V1.1/android13/longan/bsp/configs/linux-5.15/sun50iw10p1.dtsi:2132.23-2151.5: ERROR (phandle_references): /soc@2900000/codec@5096000: Reference to non-existent node or label "reg_cldo1" also defined at /media/wx/disk16t/A133/A133-Android14-V1.1/android13/longan/device/config/chips/a133/configs/p25/board.dts:1267.8-1313.3 ERROR: Input tree has errors, aborting (use -f to force output) ERROR: build Failed INFO: build kernel failed #### failed to build some targets (03:36 (mm:ss)) #### 2025-09-22 17:03:53 - _make_wrap - build target file from sdk file, please check! #### failed to build some targets (03:39 (mm:ss)) ####
最新发布
09-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值