Skip to contentSkip to conversation

Implementing a driver that listen to a GPIO

DISCUSSION Luca Ellero 2 participants 3 messages Oct 2, 2014

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 2 lines · Luca Ellero

Hi,
I'm working on an ARM platform running Linux kernel 2.6.35.

Wow, you do realize just how old and obsolete that is, right? Please upgrade to a new kernel version, you can not get any help from anyone in the community for something as ancient as that, sorry.

Best of luck,

greg k-h

#2 lore raw
Quoted 11 lines · Greg KH
Quoted 2 lines · Luca Ellero

Hi,
I'm working on an ARM platform running Linux kernel 2.6.35.

Wow, you do realize just how old and obsolete that is, right? Please upgrade to a new kernel version, you can not get any help from anyone in the community for something as ancient as that, sorry.

Best of luck,

greg k-h

Ok, let's suppose I'm running a recent kernel (I plan to do it). My questions are the same.
Thanks
regards
Luca