kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: lroluk@gmail.com (Luca Ellero)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Implementing a driver that listen to a GPIO
Date: Thu, 02 Oct 2014 10:03:15 +0200	[thread overview]
Message-ID: <542D06C3.2050008@gmail.com> (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

             reply	other threads:[~2014-10-02  8:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-02  8:03 Luca Ellero [this message]
2014-10-02 12:52 ` Implementing a driver that listen to a GPIO Greg KH
2014-10-02 14:39   ` Luca Ellero
  -- strict thread matches above, loose matches on Subject: below --
2014-10-02 17:01 Clemens Gruber
2014-10-03  0:33 ` Jinqiang Zeng
2014-10-03  9:37   ` Luca Ellero

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=542D06C3.2050008@gmail.com \
    --to=lroluk@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).