public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christer Weinigel <wingel@acolyte.hack.org>
To: linux-kernel@vger.kernel.org
Subject: Asking for opinions on GPIO API
Date: Thu, 13 Dec 2001 05:25:53 +0100 (CET)	[thread overview]
Message-ID: <20011213042553.5C6E0F5B@acolyte.hack.org> (raw)

Hi,

I'm working on a small embedded computer based on the National
Semiconductor SC2200 CPU.  This CPU has a lot of GPIO pins and I'm
wondering how to design a good API to control these pins.

Right now I have a few functions looking like this:

/* read the input from the GPIO and return 1/0 */
unsigned sc2200_gpio_get(unsigned index);

/* set and clear the pin */
void sc2200_gpio_set(unsigned index);
void sc2200_gpio_clr(unsigned index);

would it be better to have a function which takes the desired state of
the pin as an argument instead?

void sc2200_gpio_set(unsigned index, unsigned state);

Second, I have a pure implementation question, right now the set
function looks like this:

void sc2200_gpio_set(unsigned index) {
        unsigned flags;
        spin_lock_irqsave(&sc2200_gpio_lock, flags);
        outl(inl(gpio_base) | (1 << (index & 31)), gpio_base);
        spin_unlock_irqrestore(&sc2200_gpio_lock, flags);
}

which is safe, but clearing the interrupts is a rather expensive
operation, so I'd like to avoid it if possible.  Is it possible to do
something like the atomic set_bit function but with outl/inl?  Are
there any tricks that can be done?  Since the SC2200 is an ix86 CPU I
can use assembly language if neccesary and at least for this design, I
know that the system is a uniprocessor system and thus I won't have to
consider possible races between two CPU's.

    /Christer



                 reply	other threads:[~2001-12-13  4:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20011213042553.5C6E0F5B@acolyte.hack.org \
    --to=wingel@acolyte.hack.org \
    --cc=linux-kernel@vger.kernel.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