AllWinner H5 - Orange Pi PC 2, power button for ACPI

874 views
Skip to first unread message

Menion

unread,
Apr 22, 2017, 3:57:28 AM4/22/17
to linux-sunxi
Hi all
I'm running Ubuntu Xenial from Armbian, running a WIP version of Mainline Kernel 4.10.0 on an Orange PI PC 2.
I am trying to get the power button usable by Ubuntu via ACPI (or something else)
First of all, acpi_listen doesn't show any event when I press the power button, but if I look at /proc/interrupts I see that this interrupt source, increases on CPU0 (by 2) when I press the button:

32: 5 0 0 0 sunxi_pio_edge 3 Edge sw4

So basically the button is working as GPIO and interrupt source in Linux, but apparently it miss of something for generating the acpi event
Can it be some bindings in the DTS? If so, is there any guidance to set it?
Bye

ice...@aosc.io

unread,
Apr 22, 2017, 8:07:54 AM4/22/17
to men...@gmail.com, linux-sunxi
There's no ACPI on Allwinner ARM platforms (except Windows 10 IoT).

I suggest you run evtest command to investigate more about the power
buton.

> Bye
>
> --
> You received this message because you are subscribed to the Google
> Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to linux-sunxi...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Menion

unread,
Apr 22, 2017, 8:34:36 AM4/22/17
to linux-sunxi
That's wrong. I am currently running a Bananapi (A20) with power and reset buttons perfectly working and sending acpi events. Also H3 works (Orange pi pc 1)

Icenowy Zheng

unread,
Apr 23, 2017, 12:56:01 AM4/23/17
to Menion, linux-sunxi


于 2017年4月22日 GMT+08:00 下午8:34:36, Menion <men...@gmail.com> 写到:
>That's wrong. I am currently running a Bananapi (A20) with power and
>reset buttons perfectly working and sending acpi events. Also H3 works
>(Orange pi pc 1)

Banana Pi has PMIC, but Orange Pi PC2 doesn't.

In the default mainline kernel, the power key on OPi PC2 is not mapped to the KEY_POWER, but a BTN_x code.

You may want to alter the device tree for this (The key is a GPIO-connected one, and used the gpio-keys dt binding)

Menion

unread,
Apr 23, 2017, 4:29:40 AM4/23/17
to linux-sunxi, men...@gmail.com, ice...@aosc.io
Hi
I have tried to monitor the button via evtest, but nothing is detected
Can you provide guidance on how modify dts for making this switch generating a key_power event?
Bye

Menion

unread,
Apr 28, 2017, 5:24:05 AM4/28/17
to linux-sunxi, men...@gmail.com, ice...@aosc.io
Hello again
I have modified the sun50i-h5-orangepi-pc2.dts

        r_gpio_keys {
                compatible = "gpio-keys";

                sw4 {
                        label = "sw4";
---                        linux,code = <0x100>;
+++                        linux,code = <0x74>;
                        gpios = <0x24 0x0 0x3 0x1>;
                };
        };

Now, 5sec long press of the power button generate a button/power ACPI event that can be used with acpid to trigger a power off.
Does anyone know why this gpio, that on this specific HW, is used (or shall be used) for power down, is bind to BTN_0?

Michal Suchanek

unread,
Apr 28, 2017, 5:38:16 AM4/28/17
to men...@gmail.com, linux-sunxi, ice...@aosc.io
On 28 April 2017 at 11:24, Menion <men...@gmail.com> wrote:
> Hello again
> I have modified the sun50i-h5-orangepi-pc2.dts
>
> r_gpio_keys {
> compatible = "gpio-keys";
>
> sw4 {
> label = "sw4";
> --- linux,code = <0x100>;
> +++ linux,code = <0x74>;
> gpios = <0x24 0x0 0x3 0x1>;
> };
> };
>
> Now, 5sec long press of the power button generate a button/power ACPI event
> that can be used with acpid to trigger a power off.
> Does anyone know why this gpio, that on this specific HW, is used (or shall
> be used) for power down, is bind to BTN_0?

Because it's a bug.

Just send a patch - there is SubmittingPatches somewhere under
Documentation directory in Linux kernel tree in case you wonder how to
do it.

Thanks

Michal

>
>
> Il giorno domenica 23 aprile 2017 10:29:40 UTC+2, Menion ha scritto:
>>
>> Hi
>> I have tried to monitor the button via evtest, but nothing is detected
>> Can you provide guidance on how modify dts for making this switch
>> generating a key_power event?
>> Bye
>>
>>
>> Il giorno domenica 23 aprile 2017 06:56:01 UTC+2, Icenowy Zheng ha
>> scritto:
>>>
>>>
>>>
>>> 于 2017年4月22日 GMT+08:00 下午8:34:36, Menion <men...@gmail.com> 写到:
>>> >That's wrong. I am currently running a Bananapi (A20) with power and
>>> >reset buttons perfectly working and sending acpi events. Also H3 works
>>> >(Orange pi pc 1)
>>>
>>> Banana Pi has PMIC, but Orange Pi PC2 doesn't.
>>>
>>> In the default mainline kernel, the power key on OPi PC2 is not mapped to
>>> the KEY_POWER, but a BTN_x code.
>>>
>>> You may want to alter the device tree for this (The key is a
>>> GPIO-connected one, and used the gpio-keys dt binding)
>>>

Chen-Yu Tsai

unread,
Apr 28, 2017, 5:44:29 AM4/28/17
to men...@gmail.com, linux-sunxi, Icenowy Zheng
On Fri, Apr 28, 2017 at 5:24 PM, Menion <men...@gmail.com> wrote:
> Hello again
> I have modified the sun50i-h5-orangepi-pc2.dts
>
> r_gpio_keys {
> compatible = "gpio-keys";
>
> sw4 {
> label = "sw4";
> --- linux,code = <0x100>;
> +++ linux,code = <0x74>;
> gpios = <0x24 0x0 0x3 0x1>;
> };
> };
>
> Now, 5sec long press of the power button generate a button/power ACPI event
> that can be used with acpid to trigger a power off.
> Does anyone know why this gpio, that on this specific HW, is used (or shall
> be used) for power down, is bind to BTN_0?
>

IIRC this was done on purpose. The button is a simple GPIO trigger.
It does not have the specific function of a power button, like bringing
it back on, or forceful shutdown.

ChenYu

>
> Il giorno domenica 23 aprile 2017 10:29:40 UTC+2, Menion ha scritto:
>>
>> Hi
>> I have tried to monitor the button via evtest, but nothing is detected
>> Can you provide guidance on how modify dts for making this switch
>> generating a key_power event?
>> Bye
>>
>>
>> Il giorno domenica 23 aprile 2017 06:56:01 UTC+2, Icenowy Zheng ha
>> scritto:
>>>
>>>
>>>
>>> 于 2017年4月22日 GMT+08:00 下午8:34:36, Menion <men...@gmail.com> 写到:
>>> >That's wrong. I am currently running a Bananapi (A20) with power and
>>> >reset buttons perfectly working and sending acpi events. Also H3 works
>>> >(Orange pi pc 1)
>>>
>>> Banana Pi has PMIC, but Orange Pi PC2 doesn't.
>>>
>>> In the default mainline kernel, the power key on OPi PC2 is not mapped to
>>> the KEY_POWER, but a BTN_x code.
>>>
>>> You may want to alter the device tree for this (The key is a
>>> GPIO-connected one, and used the gpio-keys dt binding)
>>>

Menion

unread,
Apr 28, 2017, 5:48:34 AM4/28/17
to linux-sunxi, men...@gmail.com, ice...@aosc.io
Yes, but board-wise, apart that this button is labeled as power button, it is the only way to gracefull shutdown the board, without having to access the linux terminal somehow.
Force shutdown and restart can be achieved by unplug/plug the power supply.
I see only pro, but I have a limited view of course, to map this button to KEY_POWER instead of BTN_0, from an usability perspective
Bye

Icenowy Zheng

unread,
Apr 28, 2017, 7:42:02 AM4/28/17
to Menion, linux-sunxi, men...@gmail.com


于 2017年4月28日 GMT+08:00 下午5:48:33, Menion <men...@gmail.com> 写到:
>Yes, but board-wise, apart that this button is labeled as power button,
>it
>is the only way to gracefull shutdown the board, without having to
>access
>the linux terminal somehow.
>Force shutdown and restart can be achieved by unplug/plug the power
>supply.
>I see only pro, but I have a limited view of course, to map this button
>to
>KEY_POWER instead of BTN_0, from an usability perspective

In fact if you like you can bind it to anything, including KEY_POWER.

Just modify the DT ;-)

If you do not want to modify dt every time you upgrade it, consider usr "fdt" command in u-boot to update it on-the-fly.
Reply all
Reply to author
Forward
0 new messages