In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use rk3288 GPIO, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Introduction to GPIO usage
GPIO, whose full name is General-Purpose Input/Output (Universal input and output), is a general pin that can be dynamically configured and controlled during software operation. RK3288 has 9 groups of GPIO bank: GPIO0,GPIO1, … , GPIO8 . Each group is distinguished by A0~A7, B0~B7, C0~C7 and D0~D7 (not all bank have all numbers, for example, GPIO5 has only B0~B7, C0~C3).
In addition to the general input and output function, each GPIO port may have other reuse functions, such as GPIO5_B4, which can be reused into one of the following functions:
Spi0_clk
Ts0_data4
Uart4exp_ctsn
The driving current, pull-up and reset initial state of each GPIO port are different. Please refer to the "RK3288 function IO description" chapter in the RK3288 specification for details.
The GPIO driver for RK3288 is implemented in the following pinctrl files:
Kernel/drivers/pinctrl/pinctrl-rockchip.c
Its core is to populate the methods and parameters of GPIO bank and call gpiochip_add to register in the kernel.
Use
The sunychip-rk3288 development board has two power supply LED lights controlled by the GPIO port, which are:
From the circuit diagram, the GPIO output light is on at low level, while the light at high level is off. In addition, there are several free GPIO ports on the expansion slot, which are:
These GPIO ports can be customized for input and output.
Input and output
Taking the driver of the power supply LED lamp as an example, this paper describes how to write code to control the output of the GPIO port. First of all, you need to add the resource description of the driver to the dts (Device Tree) file firefly-rk3288.dts:
Firefly-led {compatible = "firefly,led"; led-work =; led-power =; status = "okay";}
The GPIO settings for two LED lights are defined here:
Led-work GPIO8_A2 GPIO_ACTIVE_LOWled-power GPIO8_A1 GPIO_ACTIVE_LOW
GPIO_ACTIVE_LOW indicates that the low level is effective (the light is on). If the high level is valid, it needs to be replaced by GPIO_ACTIVE_HIGH. After adding the application and control of GPIO port to the driver, you can:
# ifdef CONFIG_OF#include # include # endif static int firefly_led_probe (struct platform_device * pdev) {int ret =-1 pdev- gpio, flag; struct device_node * led_node = pdev- > dev.of_node; gpio = of_get_named_gpio_flags (led_node, "led-power", 0, & flag); if (! gpio_is_valid (gpio)) {printk ("invalid led-power:% d\ n", gpio) Return-1;} if (gpio_request (gpio, "led_power")) {printk ("gpio% d request failed!\ n", gpio); return ret;} led_info.power_gpio = gpio; led_info.power_enable_value = (flag = = OF_GPIO_ACTIVE_LOW)? 0: 1 Gpio_direction_output (led_info.power_gpio,! (led_info.power_enable_value)); On_error:gpio_free (gpio);}
Of_get_named_gpio_flags reads the GPIO configuration number and flag of led-power from the device tree, gpio_is_valid determines whether the GPIO number is valid, and gpio_request applies to occupy the GPIO. If there is an error in the initialization process, you need to call gpio_free to release the previously requested and successful GPIO. Call gpio_direction_output to set whether the output is high or low, because it is GPIO_ACTIVE_LOW, if you want the light to be on, you need to write 0. In practice, if you want to read GPIO, you need to set it to input mode before reading the value:
Int val;gpio_direction_input (your_gpio); val = gpio_get_value (your_gpio)
Here are the commonly used GPIO API definitions:
# include # include enum of_gpio_flags {OF_GPIO_ACTIVE_LOW = 0x1,}; int of_get_named_gpio_flags (struct device_node * np, const char * propname,int index, enum of_gpio_flags * flags); int gpio_is_valid (int gpio); int gpio_request (unsigned gpio, const char * label); void gpio_free (unsigned gpio); int gpio_direction_input (int gpio); int gpio_direction_output (int gpio, int v) reuse
How do you define what functions of GPIO can be reused and how to switch functions at run time? Take I2C4 as an example to make a brief introduction. According to the specification table, the functional definitions of I2C4_SDA and I2C4_SCL are as follows:
In / kernel/arch/arm/boot/dts/rk3288.dtsi there are:
I2c4: i2c@ff160000 {compatible = "rockchip,rk30-i2c"; reg =; interrupts =; # address-cells =; # size-cells =; pinctrl-names = "default", "gpio"; pinctrl-0 =; pinctrl-1 =; gpios =,; clocks =; rockchip,check-idle =; status = "disabled";}
Here, related to reuse control are the attributes that begin with pinctrl-:
Pinctrl-names defines a list of state names: default (i2C function) and gpio.
Pinctrl-0 defines the pinctrl: i2c4_sda and i2c4_scl to be set when state 0 (that is, default)
Pinctrl-1 defines the pinctrl: i2c4_gpio that needs to be set for state 1 (that is, gpio)
These pinctrl are defined in / kernel/arch/arm/boot/dts/rk3288-pinctrl.dtsi:
/ {pinctrl: pinctrl@ff770000 {compatible = "rockchip,rk3288-pinctrl";... Gpio7_i2c4 {i2c4_sda:i2c4-sda {rockchip,pins =; rockchip,pull =; rockchip,drive =; / / rockchip,tristate =;}; i2c4_scl:i2c4-scl {rockchip,pins =; rockchip,pull = Rockchip,drive =; / / rockchip,tristate =;}; i2c4_gpio: i2c4-gpio {rockchip,pins =,; rockchip,drive =;};};...}}
I2C4TP_SDA, I2C4TP_SCL are defined in / kernel/arch/arm/boot/dts/include/dt-bindings/pinctrl/rockchip-rk3288.h:
# define GPIO7_C1 0x7c10#define I2C4TP_SDA 0x7c11 # define GPIO7_C2 0x7c20#define I2C4TP_SCL 0x7c21
The definition of FUN_TO_GPIO is in / kernel/arch/arm/boot/dts/include/dt-bindings/pinctrl/rockchip.h:
# define FUNC_TO_GPIO (m) ((m) & 0xfff0)
That is, FUNC_TO_GPIO (I2C4TP_SDA) = = GPIO7_C1, FUNC_TO_GPIO (I2C4TP_SCL) = = GPIO7_C2. Values like 0x7c11 have coding rules:
7c11 | | `- func |`-offset`-bank0x7c11 means GPIO7_C1 func1, that is, i2c4tp_sda.
When reusing, if you choose "default" (that is, i2C function), the system will apply the two pinctrl of i2c4_sda and i2c4_scl, and eventually have to switch the two pins of GPIO7_C1 and GPIO7_C2 to the corresponding i2C function; and if you choose "gpio", the system will apply the pinctrl of i2c4_gpio and restore the two pins of GPIO7_C1 and GPIO7_C2 to the GPIO function.
Let's take a look at how i2C's driver / kernel/drivers/i2c/busses/i2c-rockchip.c switches multiplexing functions:
Static int rockchip_i2c_probe (struct platform_device * pdev) {struct rockchip_i2c * i2C = NULL; struct resource * res; struct device_node * np = pdev- > dev.of_node; int ret; / /. I2c-> sda_gpio = of_get_gpio (np, 0); if (! gpio_is_valid (i2c-> sda_gpio)) {dev_err (& pdev- > dev, "sda gpio is invalid\ n"); return-EINVAL;} ret = devm_gpio_request (& pdev- > dev, i2C-> sda_gpio, dev_name (& i2c-> adap.dev)) If (ret) {dev_err (& pdev- > dev, "failed to request sda gpio\ n"); return ret;} i2c-> scl_gpio = of_get_gpio (np, 1); if (! gpio_is_valid (i2c-> scl_gpio)) {dev_err (& pdev- > dev, "scl gpio is invalid\ n"); return-EINVAL } ret = devm_gpio_request (& pdev- > dev, i2c-> scl_gpio, dev_name (& i2c-> adap.dev)); if (ret) {dev_err (& pdev- > dev, "failed to request scl gpio\ n"); return ret;} i2c-> gpio_state = pinctrl_lookup_state (i2c-> dev- > pins- > p, "gpio") If (IS_ERR (i2C-> gpio_state)) {dev_err (& pdev- > dev, "no gpio pinctrl state\ n"); return PTR_ERR (i2C-> gpio_state);} pinctrl_select_state (i2C-> dev- > pins- > p, i2C-> gpio_state); gpio_direction_input (i2C-> sda_gpio); gpio_direction_input (i2C-> scl_gpio) Pinctrl_select_state (i2C-> dev- > pins- > p, i2C-> dev- > pins- > default_state); / /...}
First, call of_get_gpio to fetch the gpios of the i2c4 node in the device tree that belongs to the two defined gpio:
Gpios =,
Then call devm_gpio_request to apply for gpio, then call pinctrl_lookup_state to find the "gpio" state, and the default state "default" has been saved by the framework to i2c-> dev-pins- > default_state. Finally, pinctrl_select_state is called to choose whether it is a "default" or "gpio" function. The following are common reuse API definitions:
# include struct device {/... # ifdef CONFIG_PINCTRLstruct dev_pin_info * pins; # endif / /...}; struct dev_pin_info {struct pinctrl * p; struct pinctrl_state * default_state; # ifdef CONFIG_PMstruct pinctrl_state * sleep_state; struct pinctrl_state * idle_state; # endif}; struct pinctrl_state * pinctrl_lookup_state (struct pinctrl * p, const char * name) Int pinctrl_select_state (struct pinctrl * p, struct pinctrl_state * s); on how to use rk3288 GPIO to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.