[Linux] Introduction to Pinctrl Subsystem

Foreword:

GPIO is very commonly used in our work development. In Linux development, it is necessary to be familiar with and understand it. The corresponding subsystem pinctrl subsystem is also provided in the Linux kernel. This article understands it from a large perspective .

Reference study: Linux note teacher course (Pinctrl subsystem)

https://live.csdn.net/v/219059?spm=1001.2014.3001.5501

https://xuesong.blog.csdn.net/article/details/109522945?spm=1001.2014.3001.5502

https://blog.csdn.net/qq_33487044/article/details/123468166

https://blog.csdn.net/qq_33487044/article/details/110010020

At this stage, learn here first, and the content of this part will be combined with specific examples to practice in-depth study and understanding.

1. Overview of the Pinctrl subsystem 

In addition to being used as an ordinary input and output port, the gpio pin has the function of connecting to other controllers. However, the function assignment and feature configuration of pins is a tedious task. How to solve this problem?

The Pinctrl subsystem is to solve the above problems. There are two types of settings on its main body, one of which is function selection, that is, it can be used as iic, uart or ordinary gpio. The other type is the feature configuration of gpio, that is, the configuration of pull-up, pull-down, drive capability and speed. 

In summary, the functions provided by the Linux Pinctrl subsystem:

  • Manage all controllable pins in the system. When the system is initialized, enumerate all controllable pins and identify these pins.
  • Manage the multiplexing of these pins (Multiplexing). For SOC, in addition to configuring its pins as ordinary GPI0, several pins can also form a pin group with specific functions. pin control subsystem to manage all pin groups.
  • Configure the characteristics of these pins. For example, enable or disable the pull-up and pull-down resistors on the pin, and configure the driver strength of the pin.

Second, the specific framework of Pinctrl

The entire driver module of Pinctrl can be divided into 4 parts:

  • pinctrl api: interface provided to upper-level users
  • pinctrl common framework: an interface provided to upper-level users
  • pinctrl driver: the driver that the platform needs to implement
  • board configuration: device pin configuration information.

  • In the Pinctrl core, you can see that there are three states, default, sleep and idle. When the system is running normally, it will first follow the default configuration or be in the idle state; when the system enters the sleep state, in order to save power consumption, another set of configurations for the device pins is required.
  • Pinctrl framework mainly deals with three functions of pinstate, pinmux and pinconfig, and the mapping relationship is shown in the figure above.

3. Pinctrl dts configuration example

uart0_pins: uart0-pins {
	pins = "18", "19";
	function = "uart0";
};
uart0_sleep_pins: uart0-pins {
	pins = "18", "19";
	function = "gpio";
};
...
&uart0 {
	pinctrl-names = "default","sleep";
	pinctrl-0 = <&uart0_pins>;
	pinctrl-1 = <&uart0_sleep_pins>;
	status = "okay";
};

pinctrl-0 corresponds to the above uart0-pins, where the pin will be configured as a uart function, corresponding to pins 18 and 19. pinctrl-1 corresponds to the above uart0_sleep_pins, when the system enters sleep, the pin here will be configured as gpio function.

Guess you like

Origin blog.csdn.net/weixin_42373086/article/details/130914052