How to get the power button to soft power off

Hi,

I managed to get the power button to switch off the cpi. The power button is recognized as an input device (/dev/input/event0). If we press the power key the SO should soft power off the cpi.

The problem is that if you press the key nothing happens, the key is not received by the SO.

I needed to change the file drivers/mfd/axp20x.c from the linux kernel source after applying the cpi patch 52rc4.patch (https://github.com/clockworkpi/Kernel/blob/master/v0.4/52rc4.patch) to get it working as it should.

On the line ~205 I changed:

static const struct resource axp22x_pek_resources[] = {
    DEFINE_RES_IRQ_NAMED(AXP22X_IRQ_PEK_SHORT, "PEK_DBR"),
    DEFINE_RES_IRQ_NAMED(AXP22X_IRQ_PEK_LONG, "PEK_DBF"),
};

to

static const struct resource axp20x_pek_resources[] = {
    DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_PEK_RIS_EDGE, "PEK_DBR"),
    DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_PEK_FAL_EDGE, "PEK_DBF"),
};

and recompile the kernel.

The interesting part is that I needed to revert the code to the original kernel code before the cpi patch to get it working. like we can see in the patch file from cpi sources:

diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
index 2215660dfa05..c85c9a33911a 100644
--- a/drivers/mfd/axp20x.c
+++ b/drivers/mfd/axp20x.c
@@ -205,8 +205,8 @@ static const struct resource axp803_usb_power_supply_resources[] = {
 };

 static const struct resource axp22x_pek_resources[] = {
-	DEFINE_RES_IRQ_NAMED(AXP22X_IRQ_PEK_RIS_EDGE, "PEK_DBR"),
-	DEFINE_RES_IRQ_NAMED(AXP22X_IRQ_PEK_FAL_EDGE, "PEK_DBF"),
+	DEFINE_RES_IRQ_NAMED(AXP22X_IRQ_PEK_SHORT, "PEK_DBR"),
+	DEFINE_RES_IRQ_NAMED(AXP22X_IRQ_PEK_LONG, "PEK_DBF"),
 };
 
 static const struct resource axp288_power_button_resources[] = {

So, maybe in earlier versions of the board, the power key was connected differently.

I think having the power key to switch off is very convenient, but I would like to have it to sleep and wake up the device. I’ll try to work on it and see if it is possible. If someone knows how to do it, let me know.

BR

12 Likes

This is great :), will look into this some time