标签 aosp 下的文章

转自: http://cache.baiducontent.com/c?m=n2F9tWNTq3bABpgqBR7Rrnq7eJEBV0b-CYkrdH_ovC7GbC2ir5dWTxjAm4AY0et-bhlTXLonho7jd4FkJf_vKSDR5O3CN4gb4ortWKt2smBJDHXviGRdKNAjHyFI5BQr&p=8d79dc16d9c15fed08e2977f0b5182&newp=8b2a970f86cc42ae5ef6cf211c7a8d231610db2151d6d1126b82c825d7331b001c3bbfb422201104d3c5786103a94a59e9f03171330923a3dda5c91d9fb4c57479c2&s=c4ca4238a0b92382&user=baidu&fm=sc&query=devcfg%2Embn&qid=918dfdf200012565&p1=4

L1

abl.img

aop.img

bluetooth.img

boot.img

cmnlib.img

cmnlib64.img

devcfg.img

dsp.img

dtbo.img

fw_4j1ed.img

fw_4u1ea.img

hyp.img

keymaster.img

LOGO.img

ls.txt

modem.img

oem_stanvbk.img

qupfw.img

storsec.img

system.img

tz.img

vbmeta.img

vendor.img

xbl.img

xbl_config.img

L2

boot:boot 分区包含通过 m****ootimg 组合在一起的内核映像和 RAM 磁盘。为了直接刷写内核而不刷写新的 boot 分区,可以使用虚拟分区:

kernel:kernel 虚拟分区仅覆盖内核(zImage、zImage-dtb、Image.gz-dtb),方法是写入新的映像来覆盖旧的映像。为此,它会确定 eMMC 中现有内核映像的起始位置并将新内核映像复制到该位置。请记住,新内核映像可能会大于现有内核映像。引导加载程序可以通过移动其后的任何数据来腾出空间或放弃出错的操作。如果提供的开发内核不兼容,则可能需要使用相关的内核模块更新 dtb 分区(如果存在)、vendor 分区或 system 分区。

ramdisk:ramdisk 虚拟分区通过将新映像写入旧磁盘来仅覆盖 RAM 磁盘。为此,它会确定 eMMC 中现有 ramdisk.img 的起始位置并将新 RAM 磁盘映像复制到该位置。请记住,新 RAM 磁盘映像可能会大于现有 RAM 磁盘映像。引导加载程序可以通过移动其后的任何数据来腾出空间或放弃出错的操作。

system:system 分区主要包含 Android 框架。

recovery:recovery 分区用于存储在 OTA 过程中启动的恢复映像。如果设备支持 A/B 更新,则恢复映像可以是启动映像中包含的 RAM 磁盘,而不是单独的映像。

cache:cache 分区用于存储临时数据,如果设备使用 A/B 更新,则可以不要此分区。cache 分区不需要可从引导加载程序写入,而只需要可清空。大小取决于设备类型和 userdata 分区的可用空间。目前,50MB 至 100MB 应该没问题。

misc:misc 分区供恢复映像使用,存储空间不能小于 4****。

userdata:userdata 分区包含用户安装的应用和数据,包括自定义数据。

metadata:如果设备被加密,则需要使用 metadata 分区,该分区的存储空间不能小于 16MB。

vendor:vendor 分区包含所有不可分发给 Android 开源项目 (AOSP) 的二进制文件。如果没有专有信息,则可以省略此分区。

radio:radio 分区包含无线装置映像。只有包含无线装置且在专用分区中包含无线装置专用软件的设备才需要此分区。

tos:tos 分区用于存储 Trusty 操作系统的二进制映像文件,仅在设备包含 Trusty 时使用。

L3

sbl1.mbn

烧录命令:fastboot flash sbl1 sbl1.bin

作用:second bootloader1的缩写,是在little kernel(lk)前启动,起到引导lk的作用,如果将该分区擦除,则设备表现为进入紧急下载模式,即,擦除该分区后,插入USB显示QDload端口。

rpm.mbn

烧录命令:fastboot flash rpm rpm.mbn

作用:电源管理器,是高通MSM平台另外加的一块芯片,虽然与AP芯片打包在一起,但其是一个独立的ARM Core。之所以加这个东西,就是要控制整个电源相关的sharedresources,比如ldo,clock。负责与SMP,MPM交互进入睡眠或者唤醒整个系统。

adspso.bin

烧录命令:fastboot flash dsp adspso.bin

作用:Partition for adsp dymanic loaders image

tz.mbn

烧录命令:fastboot flash tz tz.mbn

作用:是ARM TrustZone® 技术是系统范围的安全方法,基于安全需求和引导模式配置XPU,NAND MPU

cmnlib(_30).mbn 括号中的内容可能有,可能没

烧录命令:fastboot flash cmnlib cmnlib_30.mbn

作用: Verified boot feature introduced in M needLK to load cmnlib corresponding partitions

km4.mbn

烧录命令:fastboot flash keymaster km4.mbn

作用:Verified boot feature introduced in M needs LK to load keymaster from corresponding partitions

devcfg.mbn

烧录命令:fastboot flash devcfg devcfg.mbn

作用:Partition needed by TZ for M upgrade

NON-HLOS.bin

烧录命令:fastboot flash modem NON-HLOS.bin

作用:modem image,是负责处理通讯协议相关的基带镜像

emmc_appsboot.mbn

烧录命令:fastboot flash aboot emmc_appsboot.mbn

作用:应用程序启动加载程序的分区

boot.img

烧录命令:fastboot flash boot boot.img

作用:由文件头(2k/4k)+kernel+ramdisk.img(根文件统)+dt.img(devicetree)组成,其中kernel对应于out\target\product\msm8909\obj\KERNEL_OBJ\arch\arm\boot下的zImage文件,和out\target\product\msm8909\kernel是同一个文件,只是被重新命名了,通过file zImage,可知zImage:Linux kernel ARM bootexecutable zImage(little-endian)

system.img

烧录命令:fastboot flash -S 256M system system.img(由于system.img太大,故用-S分段发送)

作用:android系统镜像文件

vendor.img

烧录命令: fastboot flash vendor vendor.img

作用:一般存放的是平台,第三方,非google的库,配置,app等文件

splash.img

烧录命令:fastboot flash splash splash.img

作用:开机动画

userdata.img

烧录命令:fastboot flash userdata userdata.img

作用:用户数据

L4

Label Purpose of this partition

Modem Partition for modem

Fsc Cookie partition to store Modem File System’s cookies.

Ssd Partition for ssd diag module. stores the encrypted RSA keys

sbl1 Partition for secondary boot loader

sbl1bak Back up Partition for secondary boot loader

Rpm Partition for rpm image

Rpmbak Back up Partition for rpm image

Tz Partition for tz image

tzbak Back up Partition for tz image

Hyp Partition for hypervisor image

hypbak Back up Partition for hypervisor image

DSP Partition for adsp dymanIC loaders image

modemst1 Copy of Modem File System (Encrypted)

modemst2 Copy of Modem File System (Encrypted)

DDR Partition for DDR.

Fsg Golden copy or backup of Modem File System (Encrypted). Also used to pre-populate the file system.

Sec Sec.dat contains fuse settings, mainly for secure boot and oem setting

splash The splash screen is displayed during the apps bootloader (also called the LK). The display driver in LK will read the splash image data from a separate eMMC partition named

            as ’splash’

aboot Partition for apps boot loader

abootbak Back up Partition for apps boot loader

boot This is the boot partition of your Android device,It includes the android kernel and the ramdisk.

recovery This is specially designed for backup. The recovery partition can be considered as an alternative boot partition

devinfo Device information including:iis_unlocked, is_tampered, is_verified, charger_screen_enabled, display_panel, bootloader_version, radio_version

           All these attirbutes are set based on some specific conditions and written on devinfo partition,.

system This partition contains the entire Android OS, other than the kernel and the ramdisk. This includes the Android GUI and all the system applications that come

           pre-installed on the device

cache This is the partition where Android stores frequently accessed data and app components

persist Partition entry for persist image. which contains data which shouldn’t be changed after the device shipped, for example: calibration data of chips(WIFI, bt, camera, etc.),

           certificates and other security related files. 

misc This partition contains miscellaneous system settings in form of on/off switches. These settings may include CID (Carrier or Region ID), USB configuration and

           certain hardware settings etc

keystore Partition for keystore service.

config Partition needed during display panel initialization. More info at Display_panel_configuration_in_Device_Tree

oem "It is meant for storing OEM specific info. Customer in this case can decide whether he wants to keep this partition or not typically reserved partitions are kept for future use

limits Partition to store LMh params on 8976 target. LMh (Limits management) driver in SBL writes the LMh HW trimmed data into separate partition

          and uses the same data for later reboots

mota Backup partition for M ota upgrade

devcfg Partition needed by TZ for M upgrades.

Dip Partition needed for SafeSwitch, feature (FR26255) designed to allow OEMs and carriers to address new smartphone theft bill issues.

mdtp Partition needed for SafeSwitch, feature (FR26255) designed to allow OEMs and carriers to address new smartphone theft bill issues.

userdata Partition for userdata image

cmnlib Verified boot feature introduced in M needLK to load cmnlib corresponding partitions

keymaster Verified boot feature introduced in M needs LK to load keymaster from corresponding partitions

syscfg Syscfg is internal testing for Vmin and CPR characterization

mcfg All MBNs place holder in flash. Specific MBN would be loaded by mcfg image based on the SIM/Carrier.

msadp used for modem debug policy

apdp used for persisting the debug policy. "Debug policy" is used to better support development and debug on secure/fuse-blown devices One instance of the debug policy

           will be signed for the AP

dpo This partition will store a policy override

转自: https://www.jianshu.com/p/f160209bd64b

内核相关文档

Documentation\devicetree\bindings\pinctrl\pinctrl-bindings.txt
Documentation\gpio\gpio.txt
Documentation\devicetree\bindings\gpio\gpio.txt

背景

随着内核的发展,linux驱动框架在不断的变化。在早期,GPIO子系统存在之前,我们驱动需要在代码中配置寄存器来使用GPIO引脚。

此后,出现了gpio子系统,后来又出现了pinctrl子系统。

有些平台的实现没有使用内核提供的pinctrl子系统,而是继续采用在内核提供pinctrl子系统前自己实现的那套机制来pinmux操作,如Ti的omap平台;

有些平台则基于pinctrl子系统来实现pinmux、pinconf的控制。

介绍

GPIO子系统可以说是Linux中最简单的子系统。

  • GPIO(General Purpose Input Output):负责管理整个系统各gpio输入输出管脚的使用情况,同时通过sys文件系统导出了调试信息和应用层控制接口。
  • Pinctrl(Pin Control):负责管理SOC中各pin的状态,比如输出电流能力、是否有内部上拉或者下拉,是否有功能复用等参数。

要想操作GPIO引脚,需要先把所用引脚配置成GPIO功能,这个通过pinctrl子系统来实现。然后可以根据设置的引脚的方向来读取引脚的值和设置输出值。

在BSP工程师实现好GPIO子系统后,我们就可以在设备树中指定GPIO引脚,在驱动中使用GPIO子系统的标准函数来获取GPIO、设置GPIO方向、读取/设置GPIO的值。这样的驱动代码是于单板无关的。

gpio子系统

gpio子系统内部实现主要提供了两类接口:

  • 一类给bsp工程师,用于注册gpio chip(也就是所谓的gpio控制器驱动)
  • 另一部分给驱动工程师使用,为驱动工程师屏蔽了不同gpio chip之间的区别,驱动工程师调用的api的最终操作流程会导向gpio对应的gpio chip的控制代码,也就是bsp的代码。

核心实现

gpio子系统的实现源码在drivers/gpio文件夹下,主要文件有:

在安卓系统中,实现源码在kernel/drivers/gpio

文件 作用
devres.c 针对gpio api增加的devres机制的支持
gpiolib.c gpio子系统的核心实现
gpiolib-of.c 对设备树的支持
gpiolib-acpi.c 和acpi相关,不分析
gpio-xxx.c 根据平台的不同,所对应的gpio控制

gpio子系统提供了两层接口,一层给上层驱动工程师调用,一层给下层bsp工程师调用。

上层使用前,当然先得bsp工程师完成对应的动作。

- 阅读剩余部分 -

转自: https://blog.csdn.net/qq_28992301/article/details/53321610

设备树详解

在Linux3.x版本后,arch/arm/plat-xxx和arch/arm/mach-xxx中,描述板级细节的代码(比如platform_device、i2c_board_info等)被大量取消,取而代之的是设备树,其目录位于arch/arm/boot/dts

1.设备树的组成

1个dts文件+n个dtsi文件,它们编译而成的dtb文件就是真正的设备树

  • soc厂商会把soc公共的特性和多块开发板公用的特性提炼为dtsi,而dts则负责描述某个具体的产品(开发板)的特性。dts直接或间接的包含多个dtsi(类似于c语言的头文件),就体现了一个完整的产品(开发板)所有的特性。以solidrun公司的hummingboard为例,其组成为
imx6dl-hummingboard.dts
        |_imx6dl.dtsi
        |   |_imx6qdl.dtsi
        |_imx6qdl-microsom.dtsi
        |_imx6qdl-microsom-ar8035.dtsi
  • 此外,dts/dtsi兼容c语言的一些语法,能使用宏定义,也能包含.h文件

2.设备树的结构

下面分别是是imx6dl-hummingboard.dts以及imx6dl.dtsi文件,我们以它们为例来分析,不难发现dts文件内容很少,只有一些板级的特征,大部分公共的硬件描述都在dtsi文件中

  • imx6dl-hummingboard.dts 文件节选
/dts-v1/;
#include "imx6dl.dtsi"
#include "imx6qdl-microsom.dtsi"
#include "imx6qdl-microsom-ar8035.dtsi"

/ {
    model = "SolidRun HummingBoard DL/Solo";
    compatible = "solidrun,hummingboard", "fsl,imx6dl";

    ir_recv: ir-receiver {
        compatible = "gpio-ir-receiver";
        gpios = <&gpio1 2 1>;
        pinctrl-names = "default";
        pinctrl-0 = <&pinctrl_hummingboard_gpio1_2>;
    };

    regulators {
        compatible = "simple-bus";

        reg_3p3v: 3p3v {
            compatible = "regulator-fixed";
            regulator-name = "3P3V";
            regulator-min-microvolt = <3300000>;
            regulator-max-microvolt = <3300000>;
            regulator-always-on;
        };
    }

&i2c1 {
    pinctrl-names = "default";
    pinctrl-0 = <&pinctrl_hummingboard_i2c1>;

    rtc: pcf8523@68 {
        compatible = "nxp,pcf8523";
        reg = <0x68>;
    };
};
  • imx6dl.dtsi文件节选
/ {
    aliases {

    /*省略无关代码*/
    }
    soc {
        #address-cells = <1>;
        #size-cells = <1>;
        compatible = "simple-bus";
        interrupt-parent = <&intc>;
        ranges;

        /*省略无关代码*/

        timer@00a00600 {
            compatible = "arm,cortex-a9-twd-timer";
            reg = <0x00a00600 0x20>;
            interrupts = <1 13 0xf01>;
            clocks = <&clks IMX6QDL_CLK_TWD>;
        };

        aips-bus@02000000 { /* AIPS1 */
            compatible = "fsl,aips-bus", "simple-bus";
            #address-cells = <1>;
            #size-cells = <1>;
            reg = <0x02000000 0x100000>;
            ranges;

            /*省略无关代码*/      

            gpio1: gpio@0209c000 {
                compatible = "fsl,imx6q-gpio", "fsl,imx35-gpio";
                reg = <0x0209c000 0x4000>;
                interrupts = <0 66 IRQ_TYPE_LEVEL_HIGH>,
                         <0 67 IRQ_TYPE_LEVEL_HIGH>;
                gpio-controller;
                #gpio-cells = <2>;
                interrupt-controller;
                #interrupt-cells = <2>;
            };

            /*省略无关代码*/  

            i2c1: i2c@021a0000 {
                #address-cells = <1>;
                #size-cells = <0>;
                compatible = "fsl,imx6q-i2c", "fsl,imx21-i2c";
                reg = <0x021a0000 0x4000>;
                interrupts = <0 36 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&clks IMX6QDL_CLK_I2C1>;
                status = "disabled";
            };

        };
            /*省略无关代码*/  
    };  
};
基本构造
  • {}包围起来的结构称之为节点,dts中最开头的/ {},称为根节点。节点的标准结构是xxx@yyy{…},xxx是节点的名字,yyy则不是必须的,其值为节点的地址(寄存器地址或其他地址),比如i2c1: i2c@021a0000中的就是一个i2c控制器的寄存器基地址,rtc: pcf8523@68中的就是这个rtc设备的i2c地址
属性:地址
  • 有关节点的地址,比如i2c@021a0000,虽然它在名字后面跟了地址,但是正式的设置是在reg属性中设置的比如:reg = <0x021a0000 0x4000>; reg的格式通常为<address length>,0x021a0000是寄存器基地址,0x4000是长度。address 和length的个数是可变的,由父节点的属性#address-cells#size-cells 决定,比如节点i2c@021a0000的父节点是aips-bus@02000000,其#address-cells#size-cells均为1,所以下面的i2c节点的reg属性就有一个address 和length,而i2c节点本身#address-cells#size-cells 分别为1和0,所以其下的rtc: pcf8523@68 的reg属性就只有一个0x68(i2c地址)了
属性:兼容性
  • 如果一个节点是设备节点,那么它一定要有compatible(兼容性),因为这将作为驱动和设备(设备节点)的匹配依据,compatible(兼容性)的值可以有不止一个字符串以满足不同的需求,详见下一节。而根节点的compatible也是非常重要的,也就是"fsl,imx6dl"这个字符串,因为系统启动后,将根据根节点的compatible来判断cpu信息,并由此进行初始化
属性设置的套路

一般来说,每一种设备的节点属性设置都会有一些套路,比如可以设置哪些属性?属性值怎么设置?那怎么知道这些套路呢,有两种思路

  • 第一种是抄类似的dts,比如我们自己项目的平台是4412,那么就可以抄exynos4412-tiny4412.dts、exynos4412-smdk4412.dts这类相近的dts
  • 第二种是查询内核中的文档,比如Documentation/devicetree/bindings/i2c/i2c-imx.txt就描述了imx平台的i2c属性设置方法;Documentation/devicetree/bindings/fb就描述了lcd、lvds这类属性设置方法
节点之间的联系
  • 节点与节点之间的关联,通常通过“标号引用”和“包含”来实现
    • 所谓标号引用,就是在节点名称前加上标号,这样设备树的其他位置就能够通过&符号来调用/访问该节点,比如上面代码ir_recv节点中的gpio属性,就引用了gpio1标号处的节点
    • 包含则是最基本的方式,比如我们要在i2c1接口添加一个i2c外设,那么就必须要在i2c1下面添加一个节点,比如上面代码中的rtc: pcf8523@68 {}
  • 标号引用常常还作为节点的重写方式,比如下面代码是imx6qdl.dtsi中定义的i2c节点,而前面imx6dl-hummingboard.dts中的&i2c1,就是对i2c1标号处节点的一次重写,在其内部添加了一个rtc设备
  • 如果一个节点是属性节点(即仅仅是作为属性被其他节点调用),那么它定义在哪里其实无所谓,重要的是调用的位置,比如lcd屏幕的时序,其实我们完全可以把它定义在其他犄角旮旯,然后在lcd节点下用&来调用它,这也是可以的。这有点类似于函数:在哪定义不重要,重要的是在哪调用

3.内核(驱动)与节点的匹配

首先,内核必须要知道dtb文件的地址,这由U-boot来告诉内核,详见U-boot引导内核流程分析 https://blog.csdn.net/qq_28992301/article/details/51873201 第6节。只要内核知晓了dtb文件的地址,那么驱动就可以通过一些API任意获取设备树的内部信息

  • 对于3.x版本之后的内核,platform、i2c、spi等设备不再需要在mach-xxx中注册,驱动程序将直接和设备树里的设备节点进行配对,是通过设备节点中的compatible(兼容性)来与设备节点进行配对的,这里只做简单介绍,具体的应用详见 基于i2c子系统的驱动分析 https://blog.csdn.net/qq_28992301/article/details/52467766 、 基于platform总线的驱动分析 https://blog.csdn.net/qq_28992301/article/details/52385518
  • 这里以pcf8523驱动为例,只要驱动中的of_match_table 中的compatible 值和设备节点中的compatible 相匹配,那么probe函数就会被触发。不仅i2c是这样,platform、spi等都是这个原理
/*定义的of_match_table*/
static const struct of_device_id pcf8523_of_match[] = {
    { .compatible = "nxp,pcf8523" },
    { }
};

/*driver 结构体中的of_match_table*/
static struct i2c_driver pcf8523_driver = {
    .driver = {
        .name = DRIVER_NAME,
        .owner = THIS_MODULE,
        .of_match_table = of_match_ptr(pcf8523_of_match),
    },
    .probe = pcf8523_probe,
    .id_table = pcf8523_id,
};
  • i2c和spi驱动还支持一种“别名匹配”的机制,就以pcf8523为例,假设某程序员在设备树中的pcf8523设备节点中写了compatible = "pcf8523";,显然相对于驱动id_table中的"nxp,pcf8523",他遗漏了nxp字段,但是驱动却仍然可以匹配上,因为别名匹配对compatible中字符串里第二个字段敏感

4.常见属性的设置与获取

当修改或编写驱动时,常常需要修改gpio、时钟、中断等等参数,以前都是在mach-xxx中的device设置的,现在则要在节点里设置,然后驱动用特殊的API来获取

  • 属性的获取常常在probe函数中进行,但是获取属性之前,最重要的是,确定哪个节点触发了驱动。如果一个驱动对应多个节点,那驱动可以通过int of_device_is_compatible(const struct device_node *device, const char *name)来判断当前节点是否包含指定的compatible(兼容性)
gpio的设置与获取
/*imx6dl.dtsi中gpio1控制器的定义节点*/
gpio1: gpio@0209c000 {
    compatible = "fsl,imx6q-gpio", "fsl,imx35-gpio";
    reg = <0x0209c000 0x4000>;
    interrupts = <0 66 IRQ_TYPE_LEVEL_HIGH>,
             <0 67 IRQ_TYPE_LEVEL_HIGH>;
    gpio-controller;
    #gpio-cells = <2>;
    interrupt-controller;
    #interrupt-cells = <2>;
};

/*imx6qdl-sabreauto.dtsi中某个设备节点*/
max7310_reset: max7310-reset {
    compatible = "gpio-reset";
    reset-gpios = <&gpio1 15 1>;
    reset-delay-us = <1>;
    #reset-cells = <0>;
};
  • 一般来说,我们把gpio属性的名字起为xxx-gpios(xxx我们可以随便起),这样驱动才能通过特定API从识别该属性,并转换成具体的gpio号
  • 该设备节点中设置了reset-gpios = <&gpio1 15 1>;这格式是什么意思呢?&gpio1 15引用了gpio1节点,故此处含义为gpio1_15这个引脚;最后一个参数1则代表低电平有效,0则为高电平有效。至于gpio1_15具体对应哪个引脚,在imx6的手册上都有详细描述
  • 其实最后一个参数(高低电平有效)不是必须的,因为gpio1节点中设置了#gpio-cells = <2>;,所以才有两个参数;某些soc的gpio节点中会设置为#gpio-cells = <1>;,那么可以不写最后一个参数
  • 驱动一般通过以下接口获取上面节点中gpio的属性。该函数第一个参数是节点,一般可以在传入probe的参数中间接获得;第二个参数是gpio属性的名字,一定要和节点属性中的xxx-gpios相同;最后一个是编号index,当节点中有n个同名的xxx-gpios时,可以通过它来获取特定的那个gpio,同一节点中gpio同名情况很少存在,所以我们都把index设为0

    gpio = of_get_named_gpio(node, "reset-gpios", index);
  • 在dts和驱动都不关心gpio名字的情况下,也可直接通过以下接口来获取gpio号,这个时候编号index就十分重要了,可以指定拿取节点的第index个gpio属性
    gpio = of_get_gpio(node, index);
中断的设置与获取

假设某设备节点需要一个gpio中断

/*先确定中断所在的组*/
interrupt-parent = <&gpio6>;

/*表示中断,GPIO6中的第8个IO,2为触发类型,下降沿触发*/
interrupts = <8 2>;
  • 而在驱动中使用 中断号 =irq_of_parse_and_map(node, index)函数返回值来得到中断号
自定义属性的设置与获取

所谓的自定义属性,有点类似于老内核中的platform_data,我们在设备节点中可以随意添加自定义属性,比如下面这个节点里面的属性都是我们自己定义的

reg_3p3v: 3p3v {
    compatible = "regulator-fixed";
    regulator-name = "3P3V";
    regulator-min-microvolt = <3300000>;
    regulator-max-microvolt = <3300000>;
    regulator-always-on;
};
  • 针对32位整形的属性,比如上面的regulator-min-microvolt,可以利用下面这个API来获取属性值,第一个参数是节点,第二个参数是属性名字,第三个是输出型参数(把读出来的值放进去)

    of_property_read_u32(node, "regulator-min-microvolt", &microvolt);
  • 类似的读取数值的API还有:
int of_property_read_u8(const struct device_node *np, const char *propname, u8 *out_value)

int of_property_read_u16(const struct device_node *np, const char *propname, u16 *out_value)
  • 下列API可检查节点中某个属性是否存在,存在则返回true,不存在则返回false
bool of_property_read_bool(const struct device_node *np, const char *propname)
  • 当节点中存在字符串时,可以像下面那样读取,比如我们读取前面reg_3p3v节点中的字符串
of_property_read_string(node, "regulator-name", &string)
  • 当节点中存在数组时,可以像下面那样读取
/*带有数组的某个节点*/
L2: cache-controller@1e00a000 {
    compatible = "arm,pl310-cache";
    arm,data-latency = <1 1 1>;
    arm,tag-latency = <1 1 1>;
};

/*驱动中使用API来读取数组, &data为输出型参数*/
of_property_read_u32_array(node, "arm,pl310-cache", &data, ARRAY_SIZE(data));

配置和定义

        gpio_power_detect {
                compatible = "quectel,gpio_power_detect";
                pinctrl-names = "default";
                pinctrl-0 = <&gpio_power_detect_active>;
                gpio_power_gpio = <&tlmm 95 0x00>;
                //otg-power-gpios = <&tlmm 18 0>;
                usb-sel-gpios = <&tlmm 66 0>;
                debounce = <15>;
                linux,code = <172>;

        };
 struct gpio_power_detect {
        struct device *dev;
        struct input_dev *p_inputdev;

        unsigned int gpio_power_gpio;
        unsigned int gpio_power_irq_num;

//      struct work_struct power_detect;
        struct workqueue_struct *gpio_power_detect_wq;
        struct work_struct      work;

        unsigned int gpio_usb_sel_gpio;
        atomic_t state;
        unsigned int code;

};

driver 和 dts 块之间的绑定

driver 中的 struct of_device_id 中的 compatible 会和 dts 中的 compatible 进行匹配,吻合的情况下, driver 就能从这个 dts 块中读取相应的数据了。 本文的 dts 是 qm215-qrd.dtsi

static struct of_device_id of_device_sc20_gpio_match_table[] =
{
        {.compatible = "quectel,gpio_power_detect"},
        {},
};
        gpio_power_detect {
                compatible = "quectel,gpio_power_detect";
                ...

        };

driver 配置输入引脚

输入引脚一般需要配置: 引脚方向,中断,上下拉。

  1. 获取 gpio, driver 中通过 dts 中的相同名称,获取到 gpio,然后申请相应的结构体
dev_struct->gpio_power_gpio = of_get_named_gpio(dev_struct->dev->of_node, "gpio_power_gpio", 0);
gpio_request(dev_struct->gpio_power_gpio, "gpio_power_gpio");
        gpio_power_detect {
                ...
                gpio_power_gpio = <&tlmm 95 0x00>;
                ...

        };
  1. 获取中断

    dev_struct->gpio_power_irq_num = gpio_to_irq(dev_struct->gpio_power_gpio);
  2. 设置方向

    gpio_direction_input(dev_struct->gpio_power_gpio);
  3. 设置上下拉,是通过 dts 来配置的,本文实在 msm8917-pinctrl.dtsi 中配置的,然后在 qm215-qrd.dtsi 中进行引用。
                tlmm_gpio_power_detect {
                        gpio_power_detect_active: gpio_power_detect_active {
                                mux {
                                        pins = "gpio95";
                                        drive-strength = <2>;
                                        bias-pull-up;
                                };
                        };
                };
        gpio_power_detect {
                ...
                pinctrl-names = "default";
                pinctrl-0 = <&gpio_power_detect_active>;
                ...

        };
···

# 配置输出引脚
输出引脚配置比较简单,只要获取 gpio 后,配置方向和初始值即可。
1. 获取 gpio
    dev_struct->gpio_usb_sel_gpio = of_get_named_gpio(dev_struct->dev->of_node, "usb-sel-gpios", 0);
    if (dev_struct->gpio_usb_sel_gpio < 0){
            pr_err("%s: get usb_sel_gpio failed\n", __func__);
    return -EINVAL;
    }
    ret = gpio_request(dev_struct->gpio_usb_sel_gpio, "usb-sel-gpios");
    if (ret) {
            pr_err("%s: Unable to request usb_sel_spio [%d]\n", __func__, dev_struct->gpio_usb_sel_gpio);
            return ret;
    }
    gpio_power_detect {
            ...
            usb-sel-gpios = <&tlmm 66 0>;
            ...

    };

2. 配置位输出
    ret = gpio_direction_output(dev_struct->gpio_usb_sel_gpio, 1);
    if (ret) {
            pr_err("%s: Unable to set direction for usb-sel-gpios [%d]\n", __func__, dev_struct->gpio_usb_sel_gpio);
            gpio_free(dev_struct->gpio_usb_sel_gpio);
    }

# 配置按键值上报
1. 获取按键值
    if(of_property_read_u32(dev_struct->dev->of_node, "linux,code", &dev_struct->code)) {
            dev_err(dev_struct->dev, "fail to get linux code\n");
            return (-EINVAL);
    }
    printk("gpio_power_detect probe get key code %d\n", dev_struct->code);

    state = gpio_get_value(dev_struct->gpio_power_gpio);
    if(state < 0) {
            dev_err(dev_struct->dev, "fail to init base_detect state %d\n", state);
            return (-EINVAL);
    }
    atomic_set(&dev_struct->state, state);
    gpio_power_detect {
            ...
            linux,code = <172>;

    };

2. 工作时上报键值
    old_state = atomic_read(&dev_struct->state);
    new_state = gpio_get_value(dev_struct->gpio_power_gpio);
    if (new_state < 0) {
            dev_err(dev_struct->dev,
                    "failed to get bd-gpio state: %d\n", new_state);
            return;
    }

    if(new_state != old_state){
            dev_err(dev_struct->dev, "base_detect update state %d", new_state);
            atomic_set(&dev_struct->state, new_state);
            gpio_set_value(dev_struct->gpio_usb_sel_gpio, new_state);
            input_report_key(dev_struct->p_inputdev, dev_struct->code, new_state);
            input_sync(dev_struct->p_inputdev);
    }


# 注意
本文中使用的 `gpio_request` 属于老的 api,新的 api 一般是 `gpiod` 开头,比如:`gpiod_direction_output`.

如果是按键,为了消抖,dts 中需要考虑 `debounce`,driver 中需要考虑 延迟工作 `struct delayed_work` 。

`DEVICE_ATTR` 可以在 `sys fs` 中添加文件,相关可以参考: https://blog.csdn.net/njuitjf/article/details/16849333

# 参考:
设备树详解  
https://blog.csdn.net/qq_28992301/article/details/53321610  
在Linux驱动中使用gpio子系统  
https://www.jianshu.com/p/f160209bd64b  
Linux内核中的GPIO驱动  
https://blog.csdn.net/vincent1995x/article/details/51581711  
1.1. GPIO设置   
http://developer.rokid.com/docs/7-bspguide/pinmuxji_gpio_she_zhi/gpioshe_zhi.html  
LinuxGPIO中文文档  
https://www.cnblogs.com/bforever/p/10528395.html  
一、初识linux输入子系统  
https://www.cnblogs.com/zhaobinyouth/p/6257662.html  
pm_stay_awake()和pm_relax()的意义  
https://blog.csdn.net/chizhang7815/article/details/100800761  
linux gpio_to_irq()源码分析  
https://blog.csdn.net/MACMACip/article/details/105549516  
of_property_read_u32  
https://biscuitos.github.io/blog/DTS-of_property_read_u32/  
如何在一份驱动中上报键值之理解input子系统设备  
https://blog.csdn.net/weixin_44158983/article/details/106872084?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0.no_search_link&spm=1001.2101.3001.4242.1&utm_relevant_index=3  
INPUT子系统学习 evdev  
https://blog.csdn.net/xiaochuan110/article/details/82424237  
高通 gpio控制方式  
https://blog.csdn.net/qq_36781842/article/details/102625088?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.no_search_link  
Android 5.1高通方案增加GPIO按键  
https://blog.csdn.net/tdstds/article/details/50920443?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link  
Qualcomm MSM GPIO-KEY device tree  
https://blog.csdn.net/bolanlst/article/details/51385808?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link  
android7.1 msm8953通过寄存器拉高gpio电平  
https://blog.csdn.net/zjy764219923/article/details/106243794?spm=1001.2101.3001.6650.15&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-15.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-15.no_search_link  
msm8996的gpio和irq  
https://blog.csdn.net/lintwins/article/details/50203173?spm=1001.2101.3001.6650.11&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-11.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-11.no_search_link  
Linux DTS(Device Tree Source)设备树详解之一(背景基础知识篇)  
https://radia.blog.csdn.net/article/details/70800076?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-6.no_search_link  
高通msm8916 gpio笔记(基于设备树)  
https://blog.csdn.net/hm131415/article/details/54377549?spm=1001.2101.3001.6650.18&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-18.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-18.no_search_link  
msm8953 申请gpio失败,查看所有的gpio 申请情况。  
https://blog.csdn.net/jlgcumt/article/details/106614870?spm=1001.2101.3001.6650.14&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-14.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-14.no_search_link  
高通 gpio控制方式  
https://blog.csdn.net/qq_36781842/article/details/102625088?spm=1001.2101.3001.6650.9&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.no_search_link  
高通msm8916 gpio笔记(基于设备树)  
https://blog.csdn.net/hm131415/article/details/54377549?spm=1001.2101.3001.6650.16&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16.no_search_link  
高通 msm平台GPIO相关的device tree设置  
https://blog.csdn.net/viewsky11/article/details/53402536?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link  
配置学习总结高通平台GPIO  
https://blog.csdn.net/Joymine/article/details/48161895?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link  
GPIO中断唤醒系统调试方法  
https://blog.csdn.net/jlgcumt/article/details/110480062?spm=1001.2101.3001.6650.4&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-4.no_search_link  
Linux休眠后开启中断的方法及中断唤醒过程  
https://blog.csdn.net/mike8825/article/details/98473014  
Android系统下如何通过外设实现GPIO中断触发调用Android程序执行  
https://blog.csdn.net/a499957739/article/details/104425753  
配置学习总结高通平台GPIO  
https://blog.csdn.net/Joymine/article/details/48161895  
Android GPIO 控制方案  
https://blog.csdn.net/WXXGoodJob/article/details/90599925  
android 上层如何控制GPIO  
https://blog.csdn.net/prike/article/details/53216954   
[RK3288]LED亮灯GPIO驱动编写及dts文件架构介绍(基于android8.1使用android studio3.6开发)  
https://blog.csdn.net/a812417530/article/details/107004198  

Android(Linux)控制GPIO的方法及实时性分析  
https://www.cnblogs.com/we-hjb/p/5859479.html  
Android(Linux)控制GPIO方法二  
https://www.cnblogs.com/we-hjb/p/5903366.html  
Android 驱动 (一) GPIO  
https://www.cnblogs.com/tlnshuju/p/7028985.html  

查看具体键值

kernel/msm-4.9/include/uapi/linux/input-event-codes.hframeworks/base/data/keyboards/Generic.kl 这个里面都可以看到 home 对应的是 172.

修改 dtsi

vim kernel/msm-4.9/arch/arm64/boot/dts/qcom/sq808-evk/qm215-qrd.dtsi

&soc {
        gpio_keys {

                home {
                        label = "home";
                        gpios = <&tlmm 127 0x1>;
                        linux,input-type = <1>;
                        linux,code = <172>;
                        debounce-interval = <15>;
                        linux,can-disable;
                        gpio-key,wakeup;
                };

        };
}

设置开机唤醒

vim frameworks/base/core/java/android/view/KeyEvent.java

    /** @hide */
    public static final boolean isWakeKey(int keyCode) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
            case KeyEvent.KEYCODE_MENU:
            case KeyEvent.KEYCODE_WAKEUP:
            case KeyEvent.KEYCODE_PAIRING:
            case KeyEvent.KEYCODE_STEM_1:
            case KeyEvent.KEYCODE_STEM_2:
            case KeyEvent.KEYCODE_STEM_3:
            case KeyEvent.KEYCODE_HOME:
                return true;
        }
        return false;
    }

参考:

Android添加一个新的按键
https://blog.csdn.net/ccskyer/article/details/10226807?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-1.no_search_link&spm=1001.2101.3001.4242.2

android添加按键(二) 添加按键流程、出现问题
https://blog.csdn.net/lintao8613/article/details/82378798?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.no_search_link&spm=1001.2101.3001.4242.1

Android 10 新增物理按键
https://blog.csdn.net/a546036242/article/details/121012512?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

新增物理按键处理流程-Android
https://blog.csdn.net/qq_34211365/article/details/103169774?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

android8.1 添加物理按键流程
https://blog.csdn.net/tt11212/article/details/87608373

Android 10.0 framework层KeyEvent按键添加流程
https://blog.csdn.net/baidu_41666295/article/details/120262180?spm=1001.2101.3001.6650.13&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-13.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-13.no_search_link

Linux下的按键驱动
https://blog.csdn.net/mike8825/article/details/51672975?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link

Android Q 按键添加流程详解
https://blog.csdn.net/wjky2014/article/details/111351038?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-8.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EOPENSEARCH%7Edefault-8.no_search_link

Android下添加自定义按键值
https://blog.csdn.net/u012966861/article/details/77969153?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link

Android键值添加和调试
https://blog.csdn.net/u013894427/article/details/78088260?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link

安卓添加按键流程
https://blog.csdn.net/qq_50764711/article/details/111352245?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-4.no_search_link&spm=1001.2101.3001.4242.3

添加按键
https://blog.csdn.net/qq_20395637/article/details/102777378?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

增加或修改(键盘)按键
https://blog.csdn.net/weixin_38451161/article/details/80291106?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

android定制化软件修改或添加按键驱动的核心操作步骤讲解
https://blog.csdn.net/acm2008/article/details/7065546?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

安卓添加按键驱动
https://blog.csdn.net/jaych/article/details/38065497

android添加按键驱动,android按键驱动开发实例2(增加一个新按键)
https://blog.csdn.net/weixin_33379878/article/details/117618160?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link

android系统移植之按键驱动篇
https://blog.csdn.net/armeasy/article/details/6713642?spm=1001.2101.3001.6650.10&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-10.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-10.no_search_link

Android 增加(键盘)按键
https://www.cnblogs.com/dyufei/p/6612790.html

Android系统input按键处理流程(从驱动到framework)
https://blog.csdn.net/jwq2011/article/details/51234811?spm=1001.2101.3001.6650.9&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-9.no_search_link

Android下添加新的自定义键值和按键处理流程
https://blog.csdn.net/tkwxty/article/details/43338921?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.no_search_link

android gpio-keys 按键驱动分析(一) key layout文件
https://blog.csdn.net/clam_zxf/article/details/73849413?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-5.no_search_link&spm=1001.2101.3001.4242.4

[RK3288][Android6.0] 系统按键驱动流程分析
https://blog.csdn.net/kris_fei/article/details/77894406?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

android 按键 驱动程序,android按键驱动研究.pdf
https://blog.csdn.net/weixin_42551260/article/details/117577179?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

Android System 自定义KEY事件及驱动
https://blog.csdn.net/qq_31829527/article/details/105954489

Android按键消息处理
https://blog.csdn.net/peng_cao/article/details/8627369?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1.no_search_link

android 按键处理流程,Android系统input按键处理流程(从驱动到framework)
https://blog.csdn.net/weixin_30727701/article/details/117601107?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

2021-1-4 Android 添加新的键值并上报从驱动到上层
https://blog.csdn.net/qq_37858386/article/details/112170827

aw9523芯片按键失效问问题分析
https://ciellee.blog.csdn.net/article/details/101553530

Android中对标准内核的按键映射以及按键驱动
https://blog.csdn.net/xiaobaiing/article/details/45565123?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.no_search_link&spm=1001.2101.3001.4242.1

kernel按键上报键值的映射
https://blog.csdn.net/u013986340/article/details/101022488

Android系统按键上报流程及其转化
https://blog.csdn.net/weixin_44008788/article/details/118755916

AndroidR Input子系统(5)解析“.kl“文件
https://blog.csdn.net/qq_34211365/article/details/109687690

Android记录输入事件研究
https://blog.csdn.net/infsafe/article/details/6120280?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

Android 按键流程分析笔记
https://blog.csdn.net/luozirong/article/details/52799745?spm=1001.2101.3001.6650.17&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-17.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-17.no_search_link

Android按键事件处理流程 KeyEvent
https://blog.csdn.net/pengjin1985/article/details/39233011?spm=1001.2101.3001.6650.16&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-16.no_search_link

Android返回键处理、任务和home键处理
https://blog.csdn.net/HUandroid/article/details/72733494?spm=1001.2101.3001.6650.15&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-15.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-15.no_search_link

Android平台Home键处理机制
https://blog.csdn.net/galensphang/article/details/9821355?spm=1001.2101.3001.6650.13&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-13.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-13.no_search_link

Android8.0 按键事件处理流程
https://blog.csdn.net/w1070216393/article/details/84261996?spm=1001.2101.3001.6650.14&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-14.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-14.no_search_link

android长按home键流程
https://blog.csdn.net/harhy/article/details/8724779?spm=1001.2101.3001.6650.10&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-10.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-10.no_search_link

Android源码解析(二十七)-->HOME事件流程
https://blog.csdn.net/qq_23547831/article/details/51475929?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link

Android源码解析(二十八)-->电源开关机按键事件流程
https://blog.csdn.net/qq_23547831/article/details/51487978?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.no_search_link&spm=1001.2101.3001.4242.1

Android源码基础解析之电源开关机按键事件流程
https://blog.csdn.net/qq_35559358/article/details/78647031?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-5.no_search_link&spm=1001.2101.3001.4242.4

android 捕获home键
https://blog.csdn.net/zhzhyang0313/article/details/6995553?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

Android捕获home按键 以及实体键捕获
https://blog.csdn.net/qwertyuiop159158/article/details/52900065?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-1.no_search_link&spm=1001.2101.3001.4242.2

Android 底层按键获取
https://blog.csdn.net/linan_nwu/article/details/8222011?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1.no_search_link

Android 读取按键及Touch Panel
https://blog.csdn.net/hgl868/article/details/6860116

高通驱动实现 GPIO 中断上报键值
https://ciellee.blog.csdn.net/article/details/101312350?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-3.no_search_link

AndroidQ 打通应用层到HAL层---(HAL模块实现)
https://blog.csdn.net/qq_34211365/article/details/105492973

Android源码解析(三十)-->触摸事件分发流程
https://blog.csdn.net/qq_23547831/article/details/51530671?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-12.no_search_link&spm=1001.2101.3001.4242.7

android实现home键功能
https://blog.csdn.net/twtje0304_01/article/details/77914161#:~:text=Android%20%E7%9A%84%20Home%20%E6%8C%89%20%E9%94%AE%E5%8A%9F%E8%83%BD%20%E6%98%AF%E5%B0%86%E6%A1%8C%E9%9D%A2Activity%E6%8B%89%E5%88%B0Activity%E6%A0%88%E9%A1%B6%EF%BC%8C%20%E6%98%BE%E7%A4%BA%20%E7%B3%BB%E7%BB%9F%E6%A1%8C%E9%9D%A2%EF%BC%8C%E4%BB%A5%E6%AD%A4%E6%9D%A5,%28%29%3B%20intent.addCategory%20%28Intent.CATEGORY_%20HOME%29%3B%20intent.setAction%20%28Intent.ACTION_MAIN%29%3B%20startActivity%20%28in

Android HOME键那些事
https://blog.csdn.net/imyfriend/article/details/8293399
Android 按下Home键
https://blog.csdn.net/greatdaocaoren/article/details/75009580
Android 监听Home键
https://www.jianshu.com/p/d215bc8e1b3d
【Android】Android处理Home键方法小结
https://www.cnblogs.com/rayray/p/3408179.html

问题现象

  • 未插耳机右上角有耳机图标
  • 设置内调节 mediacall volume 没有声音输出,但是拉动其他 ringalarm 有声音输出;确定音源文件也是有的。

原因

可以了解设置内的每个音量条的策略都是不一样的,ringalarm 都是默认强制从喇叭输出,但是 media 的插入耳机后则是由耳机输出,因此就出现以上问题了。

解决方法

所以该问题的实际原因就是不插耳机出现耳机图标的问题,只要让正常情况下使用扬声器输出,而不是耳机输出即可。

kernel/msm-4.9/arch/arm64/boot/dts/qcom/sq808-evk/qm215-audio.dtsi

qcom,msm-mbhc-hphl-swh = <1>;
qcom,msm-mbhc-gnd-swh = <0>;

packages/apps/Settings/res/values-zh-rCN/arrays.xml

@@ -37,6 +37,7 @@
     <item msgid="2693197579676214668">"5 分钟"</item>
     <item msgid="1955784331962974678">"10 分钟"</item>
     <item msgid="5578717731965793584">"30 分钟"</item>
+    <item msgid="1781492122915870416">"永不休眠"</item>
   </string-array>
   <string-array name="dream_timeout_entries">
     <item msgid="1999412608953538363">"永不"</item>

packages/apps/Settings/res/values/arrays.xml

@@ -48,6 +48,7 @@
         <item>5 minutes</item>
         <item>10 minutes</item>
         <item>30 minutes</item>
+        <item>Never</item>
     </string-array>

     <!-- Do not translate. -->
@@ -66,6 +67,8 @@
         <item>600000</item>
         <!-- Do not translate. -->
         <item>1800000</item>
+        <!-- Do not translate. -->
+        <item>2147483647</item>
     </string-array>

     <!-- Display settings.  The delay in inactivity before the dream is shown. These are shown in a list dialog. -->

packages/apps/Settings/src/com/android/settings/display/TimeoutPreferenceController.java

@@ -85,8 +85,10 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         try {
-            int value = Integer.parseInt((String) newValue);
-            Settings.System.putInt(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, value);
+            //+Begin mantis-66494 Modified for never goto sleep by james.zheng 2020-12-24
+            long value = Integer.parseInt((String) newValue);
+            Settings.System.putLong(mContext.getContentResolver(), SCREEN_OFF_TIMEOUT, value);
+            //-End mantis-66494 Modified for never goto sleep by james.zheng 2020-12-24
             updateTimeoutPreferenceDescription((TimeoutListPreference) preference, value);
         } catch (NumberFormatException e) {
             Log.e(TAG, "could not persist screen timeout setting", e);
@@ -120,9 +122,15 @@ public class TimeoutPreferenceController extends AbstractPreferenceController im
         } else {
             final CharSequence timeoutDescription = getTimeoutDescription(
                     currentTimeout, entries, values);
+            //+Begin mantis-66494 Modified for never goto sleep by james.zheng 2020-12-24
+            if(currentTimeout == 2147483647){
+                summary = timeoutDescription.toString();
+            } else {
+            //-End mantis-66494 Modified for never goto sleep by james.zheng 2020-12-24
             summary = timeoutDescription == null
                     ? ""
                     : mContext.getString(R.string.screen_timeout_summary, timeoutDescription);
+            }
         }
         preference.setSummary(summary);
     }

准备好开机 logo 的 png 图片。

最好是同分辨率的图片,否则可能背景色会变为白色。

制作 splash.img

  1. 把 png 放到 device/qcom/common/display/logo 里面。
  2. python ./logo_gen.py logo_xyz.png 生成 splash.img

烧录 开机 logo

  1. adb root
  2. adb reboot bootloader
  3. fastboot flash splash .\splash.img
  4. fastboot reboot

参考:

https://blog.csdn.net/u014296677/article/details/78423137
https://blog.csdn.net/csdnxialei/article/details/87461635
https://blog.csdn.net/qq_27061049/article/details/117752715
https://blog.csdn.net/yandongqiangZHRJ/article/details/8585273
https://www.cnblogs.com/zzb-Dream-90Time/p/7403098.html

转自: https://blog.csdn.net/qq_37858386/article/details/103834675

Android APP:检测实体按键事件

一、检测点击按键事件一般不对手机上的输入按键进行处理,直接由系统按照默认情况操作。

当然有时为了改善用户体验,需要让应用拦截按键事件,并进行额外处理。 要想监控按键事件,首先得知道每个按键的编码,这样才能根据不同的编码值进行相应的处理。监听器OnKeyListener只会检测控制键,不会检测文本键。实际测试发现HOME、SWICH、POWER普通的app是接收不到事件的,这几个事件在framew里面处理了。

二、部分控制键KEYCODE

三、测试代码

1、android_studio_app\keyeventdemo\app\src\main\java\com\example\keyeventdemo\MainActivity.java

    package com.example.keyeventdemo;

    import android.os.Bundle;
    import android.os.Handler;
    import android.support.v7.app.AppCompatActivity;
    import android.view.KeyEvent;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.TextView;
    public class MainActivity extends AppCompatActivity {
        private TextView key_result;
        private String desc = "";
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            key_result = (TextView) findViewById(R.id.key_result);
        }
      @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            key_result = (TextView) findViewById(R.id.key_result);
        }

       @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            desc = String.format("%sphysical key coce is %d", desc, keyCode);
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                desc = String.format("%s, KEYCODE_BACK", desc);
            } else if (keyCode == KeyEvent.KEYCODE_MENU) {
                desc = String.format("%s, KEYCODE_MENU", desc);
            } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                desc = String.format("%s, KEYCODE_VOLUME_UP", desc);
            } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                desc = String.format("%s, KEYCODE_VOLUME_DOWN", desc);
            }else  {
                desc = String.format("%s, KEYCODE_VOLUME is unknown", desc);
            }
            desc = desc + "\n";
            key_result.setText(desc);
            //返回true表示不再响应系统动作,返回false表示继续响应系统动作
            return true;
          // return  false;
        }
    }

2、布局文件 activity_main.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="5dp">

        <TextView
            android:id="@+id/tv_hard"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:gravity="center"
            android:text="please press the physics button"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/key_result"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="16sp" />

    </LinearLayout>

- 阅读剩余部分 -