当前位置:网站首页>Simple operation and debugging of GPIO in Qualcomm platform

Simple operation and debugging of GPIO in Qualcomm platform

2022-06-10 08:36:00 bobuddy

One 、gpio Debugging method of

        stay Linux Next , adopt sysfs, obtain gpio state , It can also be operated gpio.

1、 obtain gpio state

        cd /sys/kernel/debug/
        cat gpio

2、 operation gpio( With gpio99 For example )

        cd /sys/class/gpio/
        echo 99 > export
        cd gpio99
        echo in/out > direction    // Set up gpio Input or output
        cat direction                    // obtain gpio I / O status
        echo 'value' > value        // Set up gpio Register values
        cat value                        // obtain gpio Register value

Two 、 stay kernel Code operation gpio

        There is... In the code Two ways to operate gpio, One is to apply for one at a time gpio, Manipulate the after success gpio, The other is to use pinctrl, Set through the device tree , Operate more than one at a time gpio.

1、 Method 1

        Add... In the device node of the device tree gpio    // Optional
        device_node {
                ...
                gpio_name = <&tlmm 99 0>;    //gpio_99
                ...
        }
        Driver code :
  
        int gpio_99 = of_get_named_gpio_flags(dev->of_node, "gpio_name", 0, NULL);    // Number of slave devices node , Optional
        gpio_request(gpio_99, "gpio_name");        // adopt gpio Application No gpio
        gpio_direction_output(gpio_99, 1);            // Set up gpio_99 Output , The initial value is 1
        gpio_set_value(gpio_99, 0);                    // Set up gpio_99 The value is 0
        gpio_free(gpio_99);                                //gpio_99 It should be released after it is no longer used
        notes :
        gpio The application and setting of may fail , Exception handling should be done well

2、 Method 2

        Device tree code :
        platform pinctrl Add... Under the node Add sub nodes :
        For details of relevant documents and equipment tree configuration, see kernel/Document/pinctrl.txt and Documentation/devicetree/bindings/pinctrl/ Next multiple files

        gpio_group {
                gpio_active: gpio_active {

                       mux {
                                pins = "gpio99", "gpio98";    // Multiplexing pins 99 and 98
                                functions = "gpio";            // The pin function is configured as normal gpio

                        };
                        config {
                                pins = "gpio99", "gpio98";
                                drive-strength = <8>;    // The maximum current limit is 8mA
                                bias-pull-up;                // Configure pull-up
                                output-high;                // Output high level
                         };

                };
                gpio_sleep: gpio_sleep {

                       mux {
                                pins = "gpio99", "gpio98";    // Multiplexing pins 99 and 98
                                functions = "gpio";            // The pin function is configured as normal gpio

                        };
                        config {
                                pins = "gpio99", "gpio98";
                                drive-strength = <2>;    // The maximum current limit is 2mA
                                bias-no-pull;                // No pull-up or pull-down
                                output-low;                // Output low level
                         }; 
        };

        Reference... In the device node pinctrl:
        device_node {
                    ...
                    pinctrl-names = "gpio_active", "gpio_sleep";    // Use separately pinctrl-0 and pinctrl-1
                    pinctrl-0 = <&gpio_active>;                               // quote
                    pinctrl-1 = <&gpio_sleep>;                                // quote
                    ...
        };

        Kernel driver code :

  
        struct pinctrl *pinctrl = devm_pinctrl_get(device);    // obtain device Under the corresponding node pinctrl
        struct pinctrl_state = pinctrl_lookup_state(pinctrl, "gpio_active");    // adopt pinctrl Name acquisition pinctrl Corresponding state
        pinctrl_select_state(pinctrl, pinctrl_state);        // Set up pinctrl The status of is 'gpio_active
        devm_pinctrl_put(pinctrl);          // Release resources after use

        Method 1 and method 2 can also be used at the same time , Method 1 is easy to operate , But it can only be pulled up or down , Method 2 can be fully configured GPIO. Using both method 1 and method 2 in a device driver can ensure that resources are not operated by other modules .
 

原网站

版权声明
本文为[bobuddy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206100825376925.html