Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92
Overview
Rockchip针对有线耳机的驱动单独建了目录, 在kernel/drivers/headset_observe/下
- rockchip_headset_core.c: 读取dts中的配置,根据配置不同决定使用adc还是普通的headset探测。
- rk_headset.c: 普通方式headset驱动
- rk_headset_irq_hook_adc.c: adc方式headset驱动
注册
耳机插拔事件通过switch子系统上报,目录: kernel/drivers/switch/
通过其switch_dev_register()接口把headset注册到switch子系统中
headset->sdev.name = “h2w”;
headset->sdev.print_name = h2w_print_name;
ret = switch_dev_register(&headset->sdev);
这样就能在/sys下看到h2w的子目录
然后,用户空间就能收到uevent事件得知耳机设备状态有变化,从state文件读取状态得知插入还是拔出来做相应处理。
插拔状态的改变是通过switch_set_state()来实现,本质上就是通知上层并改变state文件值。
dts的配置如下
&adc {
status = "okay";
rockchip_headset {
compatible = "rockchip_headset";
headset_gpio = <&gpio7 GPIO_A7 GPIO_ACTIVE_LOW>;
pinctrl-names = "default";
pinctrl-0 = <&gpio7_a7>;
io-channels = <&adc 2>