Virtual GPIO (General Purpose Input / Output) multiplexing method under Linux

By designing a virtual GPIO multiplexing method under Linux, and using Gpiolib to implement a virtual IO operation model, the problem of multiple device drivers busy sharing GPIO resources is solved, and the effective input or output of multiple modules to a single GPIO is realized, satisfying the platform product The need for sharing GPIO saves resources and provides a senseless switching experience.

CN119201786APending Publication Date: 2024-12-27INGENIC SEMICON CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310751214.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-25
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

The existing Gpiolib interface cannot effectively handle the situation where multiple device drivers share a single GPIO, resulting in the problem of GPIO resources being occupied and unable to apply again.

Method used

Design a virtual GPIO (VGPIO) multiplexing method under Linux. By implementing a virtual IO operation model based on Gpiolib, using multi_vgpio structure and encapsulated functions, implementing the input or output of a single GPIO by multiple modules, and immediately when there is an input. Input, output immediately when there is output, solving the problem of busy resources.

Benefits of technology

It realizes effective reuse of a single GPIO by multiple drivers, avoids busy resources, meets the input or output requirements of multiple modules for a single GPIO, saves GPIO resources, and provides a software experience and replicable without sensing switching. standardized design.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201786A_ABST
    Figure CN119201786A_ABST
Patent Text Reader

Abstract

The invention provides a virtual GPIO (General Purpose Input / Output) multiplexing method under Linux, which comprises the following steps of: S1, converting an input instance into a GPIO drive, immediately inputting when input exists, and immediately outputting when output exists; s2, a software level configures independent device tree nodes of GPIOs (General Purpose Input / Output) required to be operated by a plurality of modules and associates the independent device tree nodes to a VGPIO model driver, a USB (Universal Serial Bus) module operates two GPIO switches, one is AUDIOSELN to control the switching of AUDIO and a USB, and the other is CHARGEREN to control the starting of charging, so that the AUDIO and the Charger module can independently configure device tree GPIO resources, and can operate the GPIOs in respective drivers to complete corresponding functions; and S3, switching of a single GPIO between modules is completed in a VGPIO drive, and a multi-vgpio structure is instantiated by the VGPIO on the basis of Gpilib, that is, a VGPIO model achieves the effect that input is immediately input when input exists and output is immediately output when output exists through basic GPIO operations such as input or output conversion, level value reading or setting and the like in the structure through the multi-vgpio structure and a packaged function.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of Linux GPIO subsystem, and in particular relates to a multiplexing method of virtual GPIO under Linux. Background Art

[0002] In order to prevent confusion caused by several drivers sharing a gpio, the Linux kernel abstracted the concept of the Gpiolib library since version 2.6.35. Since then, Gpiolib has existed as the management core of GPIO.

[0003] Gpiolib is used to manage GPIO in the system. Gpiolib summarizes the common operations of GPIO. According to the characteristics of GPIO, Gpiolib provides a unified and universal software interface for operating GPIO to other drivers, shielding the specific implementation of different chips. Gpiolib provides a framework for different chip operations. For different chips, you only need to implement the Specific Chip Driver, and then use the registration function provided by Gpiolib to hang it on Gpiolib, thus completing a set of processes.

[0004] However, the prior art also has the following defects:

[0005] The existing interface provided by Gpiolib cannot handle the situation where multiple device drivers share a single GPIO. In actual use, the GPIO resource may be occupied by one module, making it impossible for another module to apply for it.

[0006] In addition, commonly used technical terms include:

[0007] GPIO (General-purpose input / output): The abbreviation of general-purpose input / output. Its output and input can be controlled by software.

[0008] GPIO subsystem: manages GPIO, which can support both the GPIO of the chip itself and the extended GPIO to provide a unified and convenient access interface to achieve: input, output, and interrupt.

[0009] Gpiolib: used to manage GPIO in the system. Gpiolib summarizes the common operations of GPIO. According to the characteristics of GPIO, Gpiolib provides a set of unified and universal software interfaces for operating GPIO to other drivers, shielding the specific implementation of different chips. Gpiolib provides a set of frameworks for different chip operations. For different chips, you only need to implement the Specific Chip Driver, and then use the registration function provided by Gpiolib to hang it on Gpiolib, so that this set of things is completed.

[0010] Wire AND: In hardware logic gates, wire AND logic is the connection of two (or more) output signals to achieve the AND function. The model diagram in this article maps the hardware logic to the software level to represent the input and output connection method of multiple driver-related GPIOs. Summary of the invention

[0011] In order to solve the above problems, the purpose of this application is to: In order to cope with the situation where multiple drivers share GPIO, the VGPIO model came into being. VGPIO (Virtual general-purpose input / output): handles the input or output of multiple drivers to a single gpio. The design idea of ​​the VGPIO model is to be able to operate the input or output of a single GPIO for multiple modules, and immediately input when there is input, and immediately output when there is output, to solve the current situation where Gpiolib applies for the same GPIO resource for multiple modules, resulting in the dilemma that the resource is busy and cannot be applied again.

[0012] Specifically, the present invention provides a method for multiplexing virtual GPIO under Linux, which implements a set of virtual IO operation models based on Gpiolib, and includes the following steps:

[0013] S1, convert the input instance into a GPIO driver, that is, confirm the GPIO that the software needs to configure through the specific hardware wiring method, and configure the GPIO under the VGPIO device tree node, so that when there is input, it can be input immediately, and when there is output, it can be output immediately;

[0014] S2, at the software level, configure the GPIOs that need to be operated by multiple modules that need to reuse GPIOs as separate device tree nodes and associate them with the VGPIO model driver. The USB module operates two GPIO switches, one is AUDIO_SEL_N to control the switching between AUDIO and USB, and the other is CHARGER_EN to control the start of charging. In this way, the AUDIO and Charger modules can configure the device tree GPIO resources separately, and can operate this GPIO in their respective drivers to complete the corresponding functions. The USB module needs to be powered on first to work normally, as shown:

[0015]

[0016] The AUDIO_SEL_N controls the switching between AUDIO and USB, which is expressed as:

[0017]

[0018]

[0019] The CHARGER_EN controls charging and is expressed as:

[0020]

[0021] S3, the switching of a single IO between USB and AUDIIO modules is completed in the VGPIO driver. VGPIO instantiates a multi_vgpio structure based on Gpiolib, that is, the GPIO model obtains the GPIO direction or configures the input or output of the GPIO direction through the multi_vgpio structure and encapsulated functions, and reads the level value or sets the level value through this structure. Such basic GPIO operations achieve the effect of immediate input when there is input and immediate output when there is output, which is expressed as:

[0022]

[0023] The modules for multiplexing GPIO in step S2 include USB and AUDIO modules.

[0024] In step S3, the VGPIO instantiates a multi_vgpio structure based on gpiolib, and encapsulates various functional functions of multi_vgpio based on the current GPIOLIB, including:

[0025] (1) Get the input and output function of the current multi_vgpio direction:

[0026] static int multi_vgpio_get_direction(struct gpio_chip*gc,unsignedoffset); (2) Get the current multi_vgpio input status function:

[0027] static int multi_vgpio_dir_in(struct gpio_chip*gc,unsigned int gpio)

[0028] (3) Set the current multi_vgpio direction to output function:

[0029] static int multi_vgpio_dir_out(struct gpio_chip*gc,unsigned int gpio,int val)

[0030] (4) Apply for multi_vgpio resource function:

[0031] static int multi_vgpio_request(struct gpio_chip*gc,unsigned int pins)

[0032] (5) Set the multi_vgpio effective value function:

[0033] static void multi_vgpio_set(struct gpio_chip*gc,unsigned pin,intvalue)

[0034] (6) Get multi_vgpio resource function:

[0035] static int multi_vgpio_get(struct gpio_chip*gc,unsigned pin).

[0036] In step S3, the step of obtaining the GPIO direction is:

[0037] (1) Call the container_of macro to obtain the struct multi_vgpio structure pointer from the struct gpio_chip structure pointer;

[0038] (2) Call Gpiolib to get the GPIO direction function gpiod_get_direction to obtain whether the current GPIO is input or output direction;

[0039] The steps for configuring GPIO direction are:

[0040] (1) Call the container_of macro to obtain the struct multi_vgpio structure pointer from the struct gpio_chip structure pointer;

[0041] (2) Call Gpiolib to obtain the GPIO output direction setting function gpiod_direction_output, configure the current GPIO as the output direction and configure the output level value;

[0042] The step of reading the level value:

[0043] (1) Call the container_of macro to obtain the struct multi_vgpio structure pointer from the struct gpio_chip structure pointer;

[0044] (2) Call Gpiolib to read the GPIO level value function gpiod_get_value to read the current GPIO level value;

[0045] The steps of setting the level value are:

[0046] (1) Call the container_of macro to obtain the struct multi_vgpio structure pointer from the struct gpio_chip structure pointer;

[0047] (2) Call Gpiolib to set the GPIO level value function gpiod_set_value to set the current GPIO level value.

[0048] The method is applied in the following scenarios: the USB module needs to control the general purpose input and output GPIO, from AUDIO to USB, the USB module needs to control the start of charging, and the Charger module also needs to obtain the charging start state.

[0049] Therefore, the advantage of the present application is that the VGPIO model can handle the situation where multiple drivers need to control a single GPIO input or output, and input is input immediately when there is input, and output is output immediately when there is output. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] The drawings described herein are used to provide a further understanding of the present invention, constitute a part of this application, and do not constitute a limitation of the present invention.

[0051] Figure 1 It is a schematic diagram of the input of multiple drivers in the existing method.

[0052] Figure 2 It is a schematic diagram of a situation in which multiple drivers need to jointly operate a certain GPIO in the method of the present application.

[0053] Figure 3 This is a schematic diagram of the USB module in this application method needing to control GPIO from AUDIO to USB.

[0054] Figure 4 In the present application method, the USB module needs to control the start of charging, and the Charger module also needs to obtain a schematic diagram of the charging start state.

[0055] Figure 5 It is a flowchart of the application method. DETAILED DESCRIPTION

[0056] In order to more clearly understand the technical content and advantages of the present invention, the present invention is now further described in detail in conjunction with the accompanying drawings.

[0057] This application proposes a virtual GPIO multiplexing method under Linux. Gpiolib can multiplex the inputs of multiple drivers (such as Figure 1 As shown in the figure) is converted to GPIO Chip Driver through the internal Gpiolib-core, and finally operates the GPIOChip corresponding to the hardware. However, in the X2500 KNOT scanning pen project of Beijing Ingenic Integrated Circuit Co., Ltd. (hereinafter referred to as Beijing Ingenic), multiple drivers need to jointly operate a GPIO (such as Figure 2 The specific design is as follows: The USB module needs to control GPIO, from AUDIO to USB (such as Figure 3 As shown in the figure), USB needs to control the start of charging, and the Charger module also needs to obtain the charging start status (as shown in the figure). Figure 4 See attached figure for details.

[0058] Based on the above application scenarios, VGPIO implements a set of virtual IO operation models based on Gpiolib, and instantiates input into GPIO drivers. When there is input, it can be input immediately, and when there is output, it can be output immediately. At the software level, the GPIOs that need to be operated by multiple modules are configured with separate device tree nodes and associated with the VGPIO model driver. The USB module operates two IO switches, one is AUDIO_SEL_N to control the switching between AUDIO and USB, and the other is CHARGER_EN to control the start of charging. In this way, the AUDIO and Charger modules can configure device tree IO resources separately, and operate this IO in their respective drivers to complete the corresponding functions.

[0059] In summary, if Figure 5 As shown, the method includes:

[0060] S1, convert the input instance into a GPIO driver, that is, confirm the GPIO that the software needs to configure through the specific hardware wiring method, and configure the GPIO under the VGPIO device tree node, so that when there is input, it can be input immediately, and when there is output, it can be output immediately;

[0061] S2, at the software level, multiple modules that need to reuse GPIO (including USB and AUDIO modules) configure separate device tree nodes for the GPIOs that need to be operated and associate them with the VGPIO model driver. The USB module operates two GPIO switches, one is AUDIO_SEL_N to control the switching between AUDIO and USB, and the other is CHARGER_EN to control the start of charging. In this way, the AUDIO and Charger modules can configure the device tree GPIO resources separately, and can operate this GPIO in their respective drivers to complete the corresponding functions. The USB module needs to be powered on first for normal operation, which is expressed as:

[0062]

[0063] The AUDIO_SEL_N controls the switching between AUDIO and USB, which is expressed as:

[0064]

[0065]

[0066] The CHARGER_EN controls charging and is expressed as:

[0067]

[0068] S3, the switching of a single IO between USB and AUDIIO modules is completed in the VGPIO driver. VGPIO instantiates a multi_vgpio structure based on Gpiolib, and encapsulates various multi_vgpio functions based on the current GPIOLIB, including:

[0069] (1) Get the current multi_vgpio direction (input and output) function:

[0070] static int multi_vgpio_get_direction(struct gpio_chip*gc,unsignedoffset);

[0071] (2) Get the current multi_vgpio input status function:

[0072] static int multi_vgpio_dir_in(struct gpio_chip*gc,unsigned int gpio)

[0073] (3) Set the current multi_vgpio direction to output function:

[0074] static int multi_vgpio_dir_out(struct gpio_chip*gc,unsigned int gpio,int val)

[0075] (4) Apply for multi_vgpio resource function:

[0076] static int multi_vgpio_request(struct gpio_chip*gc,unsigned int pins)

[0077] (5) Set the multi_vgpio effective value function:

[0078] static void multi_vgpio_set(struct gpio_chip*gc,unsigned pin,intvalue)

[0079] (6) Get multi_vgpio resource function:

[0080] static int multi_vgpio_get(struct gpio_chip*gc,unsigned pin);

[0081] That is, the GPIO model uses the multi_vgpio structure and encapsulated functions to obtain the GPIO direction or configure the input or output of the GPIO direction, read the level value or set the level value, and other basic GPIO operations to achieve the effect of immediate input when there is input and immediate output when there is output, which is expressed as:

[0082]

[0083] The steps for obtaining the GPIO direction are:

[0084] (1) Call the container_of macro to obtain the struct multi_vgpio structure pointer from the struct gpio_chip structure pointer;

[0085] (2) Call Gpiolib to get the GPIO direction function gpiod_get_direction to obtain whether the current GPIO is input or output direction;

[0086] The steps for configuring GPIO direction are:

[0087] (1) Call the container_of macro to obtain the struct multi_vgpio structure pointer from the struct gpio_chip structure pointer;

[0088] (2) Call Gpiolib to obtain the GPIO output direction setting function gpiod_direction_output, configure the current GPIO as the output direction and configure the output level value;

[0089] The step of reading the level value:

[0090] (1) Call the container_of macro to obtain the struct multi_vgpio structure pointer from the struct gpio_chip structure pointer;

[0091] (2) Call Gpiolib to read the GPIO level value function gpiod_get_value to read the current GPIO level value;

[0092] The steps of setting the level value are:

[0093] (1) Call the container_of macro to obtain the struct multi_vgpio structure pointer from the struct gpio_chip structure pointer;

[0094] (2) Call Gpiolib to set the GPIO level value function gpiod_set_value to set the current GPIO level value.

[0095] Therefore, the present method is to:

[0096] The VGPIO model can handle situations where multiple drivers need to control a single GPIO input or output. When there is an input, it is input immediately, and when there is an output, it is output immediately to meet the platform product design requirements for a certain GPIO. The design concept of VGPIO has the following advantages:

[0097] (1) The hardware design can save GPIO resources.

[0098] (2) For users, a seamless switching experience can also be achieved at the software level.

[0099] (3) After the model is standardized, it is replicable (other modules can also be used according to the standard process) and has more universal characteristics.

[0100] (4) The design concept is simple and easy to understand. Users can quickly understand the concept and get started quickly.

[0101] (5) Multiple chip platforms can be transplanted and reused.

[0102] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the embodiments of the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for multiplexing virtual GPIO under Linux, characterized in that: The method implements a set of virtual IO operation models based on Gpiolib, including the following steps: S1, convert the input instance into a GPIO driver, that is, confirm the GPIO that the software needs to configure through the specific hardware wiring method, and configure the GPIO under the VGPIO device tree node, so that when there is input, it can be input immediately, and when there is output, it can be output immediately; S2, at the software level, configure the GPIOs that need to be operated by multiple modules that need to reuse GPIOs as separate device tree nodes and associate them with the VGPIO model driver. The USB module operates two GPIO switches, one is AUDIO_SEL_N to control the switching between AUDIO and USB, and the other is CHARGER_EN to control the start of charging. In this way, the AUDIO and Charger modules can configure the device tree GPIO resources separately, and can operate this GPIO in their respective drivers to complete the corresponding functions. The USB module needs to be powered on first for normal operation, which is expressed as: The AUDIO_SEL_N controls the switching between AUDIO and USB, which is expressed as: The CHARGER_EN controls charging and is expressed as: S3, the switching of a single IO between USB and AUDIIO modules is completed in the VGPIO driver. VGPIO instantiates a multi_vgpio structure based on Gpiolib, that is, the GPIO model obtains the GPIO direction or configures the input or output of the GPIO direction through the multi_vgpio structure and encapsulated functions, and reads the level value or sets the level value through this structure. Such basic GPIO operations achieve the effect of immediate input when there is input and immediate output when there is output, which is expressed as:

2. A method for multiplexing virtual GPIO under Linux according to claim 1, characterized in that: The modules for multiplexing GPIO in step S2 include USB and AUDIO modules.

3. A method for multiplexing virtual GPIO under Linux according to claim 1, characterized in that: In step S3, the VGPIO instantiates a multi_vgpio structure based on gpiolib, and encapsulates various functional functions of multi_vgpio based on the current GPIOLIB, including: (1) Get the input and output function of the current multi_vgpio direction: staticint multi_vgpio_get_direction(struct gpio_chip*gc,unsigned offset); (2) Get the current multi_vgpio input status function: staticint multi_vgpio_dir_in(struct gpio_chip*gc,unsignedint gpio) (3) Set the current multi_vgpio direction to output function: static int multi_vgpio_dir_out(struct gpio_chip*gc,unsigned int gpio,intval) (4) Apply for multi_vgpio resource function: staticint multi_vgpio_request(struct gpio_chip*gc,unsignedint pins) (5) Set the multi_vgpio effective value function: static void multi_vgpio_set(struct gpio_chip*gc,unsigned pin,int value) (6) Get multi_vgpio resource function: staticint multi_vgpio_get(struct gpio_chip*gc,unsigned pin).

4. A method for multiplexing virtual GPIO under Linux according to claim 1, characterized in that: In the step S3, The steps for obtaining the GPIO direction are: (1) Call the container_of macro to obtain the struct multi_vgpio structure pointer from the struct gpio_chip structure pointer; (2) Call Gpiolib to get the GPIO direction function gpiod_get_direction to obtain whether the current GPIO is input or output direction; The steps for configuring GPIO direction are: (1) Call the container_of macro to obtain the struct multi_vgpio structure pointer from the struct gpio_chip structure pointer; (2) Call Gpiolib to obtain the GPIO output direction setting function gpiod_direction_output, configure the current GPIO as the output direction and configure the output level value; The step of reading the level value: (1) Call the container_of macro to obtain the struct multi_vgpio structure pointer from the struct gpio_chip structure pointer; (2) Call Gpiolib to read the GPIO level value function gpiod_get_value to read the current GPIO level value; The steps for setting the level value are: (1) Call the container_of macro to obtain the struct multi_vgpio structure pointer from the struct gpio_chip structure pointer; (2) Call Gpiolib to set the GPIO level value function gpiod_set_value to set the current GPIO level value.

5. A method for multiplexing virtual GPIO under Linux according to claim 1, characterized in that: The method is applied in the following scenarios: the USB module needs to control the general purpose input and output GPIO, from AUDIO to USB, the USB module needs to control the start of charging, and the Charger module also needs to obtain the charging start state.