且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

I.MX6 Power off register hacking

更新时间:2022-08-12 20:28:19

/***********************************************************************
 *                  I.MX6 Power off register hacking
 * 声明:
 *     本文主要记录I.MX6DL中的Power off按键的注册过程。
 *
 *                                     2016-1-28 深圳 南山平山村 曾剑锋
 **********************************************************************/


一、cat arch/arm/mach-mx6/board-mx6dl_sabresd.h
    ......
    static iomux_v3_cfg_t mx6dl_sabresd_pads[] = {
        ......
        MX6DL_PAD_GPIO_17__GPIO_7_12, /* power off */
        ......
    }
    ......

二、cat arch/arm/mach-mx6/board-mx6q_sabresd.c
    ......
    #define SABRESD_POWER_OFF   IMX_GPIO_NR(7, 12)
    ......
    static struct gpio_keys_button new_sabresd_buttons[] = {
        GPIO_BUTTON(SABRESD_VOLUME_UP, KEY_VOLUMEUP, 1, "volume-up", 0, 1),
        GPIO_BUTTON(SABRESD_VOLUME_DN, KEY_VOLUMEDOWN, 1, "volume-down", 0, 1),
        GPIO_BUTTON(SABRESD_POWER_OFF, KEY_POWER, 1, "power-key", 1, 1),
    };
    
    static struct gpio_keys_platform_data new_sabresd_button_data = {
        .buttons    = new_sabresd_buttons,
        .nbuttons   = ARRAY_SIZE(new_sabresd_buttons),
    };
    
    static struct platform_device sabresd_button_device = {
        .name       = "gpio-keys",
        .id     = -1,
        .num_resources  = 0,
    };
    
    static void __init imx6q_add_device_buttons(void)
    {
        /* fix me */
        /* For new sabresd(RevB4 ane above) change the
         * ONOFF key(SW1) design, the SW1 now connect
         * to GPIO_3_29, it can be use as a general power
         * key that Android reuired. But those old sabresd
         * such as RevB or older could not support this
         * change, so it needs a way to distinguish different
         * boards. Before board id/rev are defined cleary,
         * there is a simple way to achive this, that is using
         * SOC revison to identify differnt board revison.
         *
         * With the new sabresd change and SW mapping the
         * SW1 as power key, below function related to power
         * key are OK on new sabresd board(B4 or above).
         *  1 Act as power button to power on the device when device is power off
         *  2 Act as power button to power on the device(need keep press SW1 >5s)
         *  3 Act as power key to let device suspend/resume
         *  4 Act screenshort(hold power key and volume down key for 2s)
         */
            platform_device_add_data(&sabresd_button_device,
                    &new_sabresd_button_data,
                    sizeof(new_sabresd_button_data));
    
        platform_device_register(&sabresd_button_device);
    }
    ......