kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Implementing a driver that listen to a GPIO
@ 2014-10-02 17:01 Clemens Gruber
  2014-10-03  0:33 ` Jinqiang Zeng
  0 siblings, 1 reply; 6+ messages in thread
From: Clemens Gruber @ 2014-10-02 17:01 UTC (permalink / raw)
  To: kernelnewbies

Hi,

I am just trying to solve a similar problem as Luca described. I have a
TQMa28 board running Linux 3.17-rc7 though.
The capacitors keep the system up for about 1500 more milliseconds after
the power fails. A GPIO line is set to high as soon as the main power is
lost.

So I have not much time to quit an important user space process and to
clean up the ext4 root filesystem before the power fails.

At the moment I pass rootflags=data=journal,commit=1 in the kernel
commandline to lower the risk of data loss.
In the user space application I open important files using the O_SYNC flag.

Is there something else I should do to avoid data loss?

How would you implement the "emergency cleanup on power-failure" logic?
Dedicated driver (similar to the mentioned gpio-event driver?),
implement it with UIO, let a userspace application running as root
select /dev/uioX and cleaning up?

Or should I create a separate partition on my eMMC just for this user
space application data and use a readonly rootfs for the rest?

Thanks for your help!

Best regards,
Clemens

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Implementing a driver that listen to a GPIO
@ 2014-10-02  8:03 Luca Ellero
  2014-10-02 12:52 ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Luca Ellero @ 2014-10-02  8:03 UTC (permalink / raw)
  To: kernelnewbies

Hi,
I'm working on an ARM platform running Linux kernel 2.6.35.
The board is powered by a "micro UPS" that guarantees about 500 ms of 
"self-power" in case of a power failure.
Power failure is reported by a GPIO that can raise an interrupt when 
power is falling.
I would like to implement a mechanism which listen to the GPIO and when 
power is going down it saves some amount of data (about 100 KB) and then 
shutdown the board.

Which is best way to do that?

I'm thinking about 3 ways of doing that:

1) |using |theusermode-helper API:
Implement a driver which use c|all_usermodehelpe|rto launch an user 
space app

2) Using a gpio-event driver, as explained here:

http://wiki.gumstix.org/index.php?title=GPIO_Event_Driver#Detecting_events

3) Implement my own driver using completions. Something like this:

DECLARE_COMPLETION(comp);

interrupt_handler(){
     complete(comp);
}

ups_read (){
     wait_for_completion(&comp);
     copy_to_user(...something...);
     return 0; /* EOF */
}

static const struct file_operations ups_driver_ops = {
     .owner        = THIS_MODULE,
     .read        = ups_read,
};

static struct miscdevice hello_miscdev = {
     .minor        = MISC_DYNAMIC_MINOR,
     .name        = "ups",
     .fops        = &ups_driver_ops
};

init (){
     request_irq(interrupt_handler);
     misc_register(&hello_miscdev);
}

and in userspace a process which execute a read from /dev/ups. When the 
call to readreturns, it means that power is falling.


What do you think? Any suggestion is welcome.

Thanks
Regards
Luca Ellero

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-10-03  9:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-02 17:01 Implementing a driver that listen to a GPIO Clemens Gruber
2014-10-03  0:33 ` Jinqiang Zeng
2014-10-03  9:37   ` Luca Ellero
  -- strict thread matches above, loose matches on Subject: below --
2014-10-02  8:03 Luca Ellero
2014-10-02 12:52 ` Greg KH
2014-10-02 14:39   ` Luca Ellero

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).