Refer to self linux-2.6.32.61 \ Documentation \ 1, Introduction
The full name of GPIO is General Purpose Input/Output, which is associated with a pin on the SOC. The Platform allocates relevant GPIO and peripheral associations, such as audio codec peripherals, GPIO and strong platform relevance.
GPIO can be input and output configured by the platform. The output can be written. The high level is 1, and the low level is 0. The input can be read. In addition to reading data, the input can also be used as an interruption signal.
Ii. GPIO ID
The valid range of gpio ids is 0 .. MAX_INT. A negative number indicates that this platform is not supported (can be initialized ).
The Platform defines how they use these interfaces, and generally uses the # define macro definition symbol for each GPIO line, so that the startup code of the Board can be directly consistent with the relevant design. In contrast, the driver should only use the GPIO number passed to them from the setup code, and use platform_data to save the specific pin configuration data of the Board (together with the specific data of other required boards ). This avoids the porting problem.
For example, one platform uses 32-159, and the other platform uses 0-64.
Int gpio_is_valid (int number );
Use this function to determine whether the gpio line is valid.
Iii. GPIO usage
/* Request GPIO, returning 0 or negative errno.
* Non-null labels may be useful for diagnostics.
*/
Int gpio_request (unsigned gpio, const char * label );
/* Release previusly-claimed GPIO */
Void gpio_free (unsigned gpio );
This function achieves two purposes:
Note that requesting a GPIO does NOT cause it to be configured in any way; it just marks that GPIO as in use. separate code must handle any pin setup (e.g. controlling which pin the GPIO uses, pullup/pulldown ).
Also note that it's your responsibility to have stopped using a GPIO before you free it.
- Marking the direction of gpio
/* Set as input or output, returning 0 or negative errno */
Int gpio_direction_input (unsigned gpio );
Int gpio_direction_output (unsigned gpio, int value );
- Spinlock-Safe GPIO access
/* Gpio input: return zero or nonzero */
Int gpio_get_value (unsigned gpio );
/* Gpio output */
Void gpio_set_value (unsigned gpio, int value );
Int gpio_cansleep (unsigned gpio );
/* Gpio input: return zero or nonzero, might sleep */
Int gpio_get_value_cansleep (unsigned gpio );
/* Gpio output, might sleep */
Void gpio_set_value_cansleep (unsigned gpio, int value );
Other than the fact that these CILS might sleep, and will not be ignored for GPIOs that can't be accessed from IRQ handlers, these callact the same as the spinlock-safe CILS.
- Gpio input as interrupt signal
/* Map GPIO numbers to IRQ numbers */
Int gpio_to_irq (unsigned gpio );
/* Map IRQ numbers to GPIO numbers (avoid using this )*/
Int irq_to_gpio (unsigned irq );
Gpio and neutral disconnection are identified by an integer. In two name spaces, these two functions establish the gpiing between gpio and neutral disconnection.