power switch event for clean shutdown

Moderators: mdrjr, odroid

power switch event for clean shutdown

Unread postby jit » Mon Mar 30, 2015 4:52 pm

As the device have an hardware power switch, I'm searching a way to make a clean shutdown by pressing the button less than 5 sec when the Odroid-w is running (to avoid unclean shutdown).

On traditional x86 architecture, it's quite easy because of ACPI events... But AFAIK, there is no ACPI on ARM plateforms.

How can I detect a power button usage while running ? I may code if necessary... ;)
jit
 
Posts: 80
Joined: Mon Mar 30, 2015 4:10 pm
languages_spoken: english, french
ODROIDs: odroid-w, 1x C0, 1x C1, 2x C1+, 1x C2, 1x XU4

Re: power switch event for clean shutdown

Unread postby macemoneta » Mon Mar 30, 2015 7:06 pm

Just put a button on a GPIO. You can then shutdown when it's pressed with, for example (GPIO 27):
Code: Select all
#!/bin/bash
gpio wfi 27 rising
# We fall through when triggered
shutdown -h now
macemoneta
 
Posts: 62
Joined: Sun Jan 11, 2015 8:38 am
Location: NJ
languages_spoken: english
ODROIDs: odroid-c1

Re: power switch event for clean shutdown

Unread postby jit » Mon Mar 30, 2015 9:31 pm

Well, you're right... but this makes me realise that my question was not precise enough.

I want to use only one button for both switch on and off. Using a GPIO to trigger to shutdown is not an option for me (I can do that with an onscreen menu).
jit
 
Posts: 80
Joined: Mon Mar 30, 2015 4:10 pm
languages_spoken: english, french
ODROIDs: odroid-w, 1x C0, 1x C1, 2x C1+, 1x C2, 1x XU4

Re: power switch event for clean shutdown

Unread postby macemoneta » Mon Mar 30, 2015 10:34 pm

You could use something like this:

Seachoice Toggle Switch - 3 Pos MOM ON/OFF/MOM ON

Wire one set of contacts to the power switch port contacts (J4), and wire the other set to the GPIO. Toggle up to boot, toggle down to shutdown.
macemoneta
 
Posts: 62
Joined: Sun Jan 11, 2015 8:38 am
Location: NJ
languages_spoken: english
ODROIDs: odroid-c1

Re: power switch event for clean shutdown

Unread postby jit » Mon Mar 30, 2015 10:56 pm

Yes this could be a solution... I would have prefered a "simple" push button easier to integrate, but this could be a solution.

Isn't there any way to get the "power switch" event on OS side ? The PMIC hardware may have something for that. I never wrote a kernel driver, but (for now) I'm not afraid ;)
jit
 
Posts: 80
Joined: Mon Mar 30, 2015 4:10 pm
languages_spoken: english, french
ODROIDs: odroid-w, 1x C0, 1x C1, 2x C1+, 1x C2, 1x XU4

Re: power switch event for clean shutdown

Unread postby macemoneta » Mon Mar 30, 2015 11:06 pm

A power-on event happens before the OS is running. Even a 'wake on interrupt' from sleep would still require a separate switch.
Edit: You could add some additional logic to determine if power is up on the board (e.g., Pin 1) and if so pulse the GPIO, or if power is down pulse J4, if you think it's worth the effort.
macemoneta
 
Posts: 62
Joined: Sun Jan 11, 2015 8:38 am
Location: NJ
languages_spoken: english
ODROIDs: odroid-c1

Re: power switch event for clean shutdown

Unread postby jit » Tue Mar 31, 2015 12:36 am

The problem is not really the "power ON" event, but the "power OFF" one. The main objective is to trigger the OS shutdown command by pressing the on/off switch while the odroid-w is running.
jit
 
Posts: 80
Joined: Mon Mar 30, 2015 4:10 pm
languages_spoken: english, french
ODROIDs: odroid-w, 1x C0, 1x C1, 2x C1+, 1x C2, 1x XU4

Re: power switch event for clean shutdown

Unread postby jit » Tue Mar 31, 2015 4:39 am

The ricoh 5t619 input driver may be a solution : https://github.com/hardkernel/linux/blo ... 9-pwrkey.c
It seems to implement a KEY_POWER event which is registered in /dev/input/event0.

I tested with evtest, but the event seems not to be triggered... does someone know what exatly trigger this event ?
jit
 
Posts: 80
Joined: Mon Mar 30, 2015 4:10 pm
languages_spoken: english, french
ODROIDs: odroid-w, 1x C0, 1x C1, 2x C1+, 1x C2, 1x XU4

Re: power switch event for clean shutdown

Unread postby GHhost » Sat Jun 20, 2015 11:59 pm

it seems input driver is broken or it may be for different pmic model, i try to debug it in low level, it's not see this keypress at all => no any event to OS.
GHhost
 
Posts: 10
Joined: Wed Jan 07, 2015 6:46 pm
languages_spoken: english
ODROIDs: odroid w

Re: power switch event for clean shutdown

Unread postby Soulsavior » Mon May 02, 2016 6:40 pm

Hello!
I know that this is an old topic, but can someone explain me in details How to do Macemoneta's trick on a Odroid C2, using two MOM buttons, one for shutting down and one for waking the device once it has shutdown? I'm a complete newbie concerning these board computers, but am pretty good at soldering on consoles and boards.To make it worse, i also am french so it's hard to follow what you guys says, so please make it simple, with diagrams and line codes (with how to add them) if possible... :lol:
I'd also like to know how to wire an extra activity LED on the GPIO.
Many thanks in advance for your help, guys! ;)
Soulsavior
 
Posts: 10
Joined: Sun May 01, 2016 1:55 am
languages_spoken: english
ODROIDs: Odroid C2

Re: power switch event for clean shutdown

Unread postby Jojo » Mon May 02, 2016 7:16 pm

Soulsavior wrote:Hello!
I know that this is an old topic, but can someone explain me in details How to do Macemoneta's trick on a Odroid C2, using two MOM buttons, one for shutting down and one for waking the device once it has shutdown? I'm a complete newbie concerning these board computers, but am pretty good at soldering on consoles and boards.To make it worse, i also am french so it's hard to follow what you guys says, so please make it simple, with diagrams and line codes (with how to add them) if possible... :lol:
I'd also like to know how to wire an extra activity LED on the GPIO.
Many thanks in advance for your help, guys! ;)


Hi,

maybe you should open an new thread about this in the C2 section. The C2 is... well... "very different" from the W . And it is always a good thing to choose a useful titel for new threads, if you are going to open up a new one ;) .
How to ask questions the smart way:
http://www.catb.org/esr/faqs/smart-questions.html
Jojo
 
Posts: 441
Joined: Mon May 18, 2015 12:13 am
Location: Germany
languages_spoken: english, german
ODROIDs: C1, C1+, C2

Re: power switch event for clean shutdown

Unread postby Soulsavior » Tue May 03, 2016 7:00 am

Jojo wrote:Hi,

maybe you should open an new thread about this in the C2 section. The C2 is... well... "very different" from the W . And it is always a good thing to choose a useful titel for new threads, if you are going to open up a new one ;) .


OK, will do if you think that's better, thanks for the advice ;)
Soulsavior
 
Posts: 10
Joined: Sun May 01, 2016 1:55 am
languages_spoken: english
ODROIDs: Odroid C2


Return to Debian(Raspbian)

Who is online

Users browsing this forum: No registered users and 1 guest