Implementing a driver that listen to a GPIO
Luca Ellero
lroluk at gmail.com
Thu Oct 2 04:03:15 EDT 2014
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
More information about the Kernelnewbies
mailing list