Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8970937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:49:54+00:00 2026-06-15T17:49:54+00:00

If you don’t think this question is constructed properly, please see its original version.

  • 0

If you don’t think this question is constructed properly, please see its original version. I have been asked to reduce this question to its minimal form.

If I’m writing a Linux device driver, how do I get programmatic access to actual GPIO pins? For example:

// Turn a green LED on by sending the GPIO pins 0x11223344
int cmd = encode(Commands.TURN_GREEN_ON);
send_to_gpio_pins(cmd);

Again, if this is unclear, it’s because I’m trying to oblige community rules for keeping it simple, stupid. In that case read my first version of this question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:49:55+00:00Added an answer on June 15, 2026 at 5:49 pm

    A Linux device driver should have access to a set of functions provided by the arch’s gpio module. Since I am familiar with Atmel ARM code and not sure about the Broadcom SoC used by the RPI, here’s some real gpio code.

    I/O devices on ARM SoCs are typically memory mapped (i.e. there is no separate I/O address space). These physical addresses can be mapped into kernel virtual address space. (The addresses of a peripheral’s registers are often mapped by the individual device driver for its exclusive use.)
    Once mapped into virtual memory, registers that contain or control the state of a GPIO pin can simply be accessed by an ordinary read or write memory operation (while conforming to C language requirements). Consult the Broadcom SoC hardware document for the exact assignment/functionality of each bit in these device registers.

    Prior to using a GPIO as either an input pin or an output pin, the GPIO pin must be configured. Often the pin will have multiple uses (it’s “multiplexed”), so one of those specific functionalities has to be selected during early board initilization. These assignments are performed by writing to device configuration registers (which are mapped to memory locations).

    An Atmel function to write the value of a GPIO pin (from arch/arm/mach-at91/gpio.c) :

    /*
     * assuming the pin is muxed as a gpio output, set its value.
     */
    int at91_set_gpio_value(unsigned pin, int value)
    {
            void __iomem    *pio = pin_to_controller(pin);
            unsigned        mask = pin_to_mask(pin);
    
            if (!pio)
                    return -EINVAL;
            __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR));
            return 0;
    }
    EXPORT_SYMBOL(at91_set_gpio_value);
    

    An Atmel function to read the value of a GPIO pin:

    /*
     * read the pin's value (works even if it's not muxed as a gpio).
     */
    int at91_get_gpio_value(unsigned pin)
    {
            void __iomem    *pio = pin_to_controller(pin);
            unsigned        mask = pin_to_mask(pin);
            u32             pdsr;
    
            if (!pio)
                    return -EINVAL;
            pdsr = __raw_readl(pio + PIO_PDSR);
            return (pdsr & mask) != 0;
    }
    EXPORT_SYMBOL(at91_get_gpio_value);
    

    Hopefully you can find similar code in the kernel that you use (e.g. grep the System.map symbol file for “gpio”).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if this has been asked before, so point me to another question
Don't think my virtualhost is working correctly. This is what I have inside of
Don't know if this has been answered before. Have custom routes to users. If
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
Don't overthink this - there's a very commonly used term and I ... have
This could be a duplicate question, but I have no idea what search terms
(Don't know if this is strictly on-topic, but I don't see any better Stack
I don't have much knowledge about the IPv6 protocol, so sorry if the question
Don't know why but I can't find a solution to this. I have 3
Don't think this is a repost, difficult to search for the word between because

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.