Implementing a driver that listen to a GPIO

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies




[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux