General Purpose Input/Output (GPIO) A General Purpose Input/Output (GPIO (General Purpose Input/Output)) is a flexible software-controlled digital signal. They are provided from many kinds of chip, and are familiar to Linux developers working with embedded and custom hardware. Each GPIO (General Purpose Input/Output) represents a bit connected to a particular pin, or “ball” on Ball Grid Array (BGA) packages. Board schematics show which external hardware connects to which GPIOs. Drivers can be written generically, so that board setup code passes such pin configuration data to drivers. Often times, different aspects of the GPIO (General Purpose Input/Output) need to be controlled. This may include things such as: direction: input or output value: set or unset polarity: high or low edge: rising or falling The GPIO (General Purpose Input/Output) framework is not for utilizing GPIOs as interrupt sources. If you need that functionality, please see the interrupts overview document. Blackfin Interface Depending on the Blackfin processor variant you're working with, some of the GPIO (General Purpose Input/Output) pins may be multiplexed with other peripherals which would preclude you from using the pins simultaneously as both GPIO (General Purpose Input/Output) and with a peripheral. For the exact details, please refer to the HRM ((Blackfin) Hardware Reference Manual) for your cpu. Keep in mind that under this mux setup, the HRM ((Blackfin) Hardware Reference Manual) will refer to the actual physical pin of the cpu as a programmable flag (pf) since it may correspond to either a GPIO (General Purpose Input/Output) or a peripheral line. The GPIO (General Purpose Input/Output) framework will handle the port muxing details for you, so we won't cover that any further in this document. GPIO Input Buffers The GPIO (General Purpose Input/Output) input enable registers are used to enable the input buffers on any GPIO (General Purpose Input/Output) that is being used as an input. Leaving the input buffer disabled eliminates the need for pull-ups and pull-downs when a particular pin is not used in the system. GPIO Value Register Pin Interpretation The read value of a GPIO (General Purpose Input/Output) input pin depends on the configuration of the polarity and sensitivity settings. Polar , Edge , Both , Effect of MMR (Memory Mapped Register) Settings 0 , 0 , - , Pin that is high reads as 1; pin that is low reads as 0 0 , 1 , 0 , If rising edge occurred, pin reads as 1; otherwise, pin reads as 0 1 , 0 , - , Pin that is low reads as 1; pin that is high reads as 0 1 , 1 , 0 , If falling edge occurred, pin reads as 1; otherwise, pin reads as 0 - , 1 , 1 , If any edge occurred, pin reads as 1; otherwise, pin reads as 0 Linux Framework All of the relevant prototypes and defines for the GPIO (General Purpose Input/Output) framework can be found in the asm/gpio.h header file. #include GPIO Allocation GPIOs allocation is handled by two functions: int gpio_request(unsigned gpio, const char *label); void gpio_free(unsigned gpio); So if we wanted to allocate GPIO (General Purpose Input/Output)_PG8 in our driver module, we would simply do: static __init int sample_module_init(void) { int ret; ret = gpio_request(GPIO_PG8, "Sample Driver"); if (ret) { printk(KERN_WARNING "sample_driver: unable to request GPIO_PG8\n"); return ret; } return 0; } static __exit void sample_module_exit(void) { gpio_free(GPIO_PG8); } module_init(sample_module_init); module_exit(sample_module_exit); GPIO Modifiers Since you'll need to control all the aspects of the GPIO (General Purpose Input/Output) pin, there are a suite of get/set functions. In the snippet below, we'll set the direction to output and value to 0. ... gpio_direction_output(GPIO_PG8, 1); gpio_set_value(GPIO_PG8, 0); ... Function Reference Here is the full reference of GPIO (General Purpose Input/Output) functions. Hopefully the names should be self-explanatory. int gpio_is_valid(int number); int gpio_request(unsigned gpio, const char *label); void gpio_free(unsigned gpio); int gpio_direction_input(unsigned gpio); int gpio_direction_output(unsigned gpio, int value); void gpio_set_value(unsigned gpio, int value); int gpio_get_value(unsigned gpio); External Resources For the latest and greatest GPIO (General Purpose Input/Output) framework information, please read the following files in the kernel source: linux-2.6.x/Documentation/gpio.txt Much of the information here was taken from that file.