GPIO driver Overview

First, the operation code in the kernel gpio

There are two ways in operation gpio code: one is a single application gpio, the tree through the device, after a successful manipulate the gpio. Another is to use pinctrl subsystem tree provided by the device, a plurality of operation gpio.

 

1. Direct Operation GPIO

Because the platforms are generally GPIO device driver, it is generally mounted device tree nodes in & under soc:

device_node {
    ...
    gpio_name = <&msm_gpio 99 0>; //gpio_99
    ...
}

Driver code:

int gpio_99 = of_get_named_gpio_flags (the dev-> of_node, " gpio_name " , 0 , NULL); // Get the node from the device tree gpio number 
gpio_request (gpio_99, " gpio_name " ); // Application No. gpio by gpio 
gpio_direction_output (gpio_99, . 1 ) ;   // set gpio_99 output initial value. 1 
gpio_set_value (gpio_99, 0 );          // set gpio_99 value 0 
gpio_free (gpio_99);                  // after use should not release gpio_99

gpio applications and settings are possible cases of failure occurs, it should be good exception handling.

 

2. pinctrl subsystem device tree:

  Pin Control Subsystem is abstracted from a Linux kernel subsystem for controlling the hardware of a pin. Many more ways than GPIO configuration above means, such as the current configuration (can be used to wake up sleep function), manage pin pin multiplexing, interface specification and other functions; worm nest of science and technology have a few large cattle write well:

GPIO systems linux kernel (1): software framework http://www.wowotech.net/gpio_subsystem/io-port-control.html

GPIO systems linux kernel (2): pin control subsystem http://www.wowotech.net/gpio_subsystem/pin-control-subsystem.html

GPIO systems (3) Linux kernel: pin controller driver code analysis http://www.wowotech.net/gpio_subsystem/pin-controller-driver.html

(4) GPIO systems linux kernel: pinctrl driven understanding and summary http://www.wowotech.net/gpio_subsystem/pinctrl-driver-summary.html

(5) GPIO linux kernel systems: coupling between gpio subsysem http://www.wowotech.net/gpio_subsystem/pinctrl-and-gpio.html and pinctrl subsystem

Device Tree:

{device_node 
    ... 
    pinctrl -names = " gpio_active " , " gpio_sleep " ; // respectively pinctrl-0. 1-and pinctrl 
    pinctrl- 0 = <& gpio_active>; // reference 
    pinctrl- . 1 = <& gpio_sleep>;   // references 
    ... 
};

Driver code:

struct pinctrl pinctrl * = devm_pinctrl_get (device); // Get pinctrl device at a corresponding node 
struct pinctrl_state pinstate * = pinctrl_lookup_state (pinctrl, " gpio_active " ); // Get pinctrl by a corresponding state name pinctrl 
pinctrl_select_state (pinctrl, pinstate); / / set status to pinctrl 'gpio_active 
devm_pinctrl_put (pinctrl); // use the resources released over

 

Guess you like

Origin www.cnblogs.com/hellokitty2/p/12339891.html