blob: 4b0dc2716e57f02080febb878d302529bcd01c94 [file] [log] [blame]
Heinrich Schuchardt914d4f82022-08-02 14:20:32 +02001.. SPDX-License-Identifier: GPL-2.0+:
2
Heinrich Schuchardt1b0c3162024-01-14 14:53:13 +01003.. index::
4 single: gpio (command)
5
Heinrich Schuchardt914d4f82022-08-02 14:20:32 +02006gpio command
7============
8
9Synopsis
10--------
11
12::
13
14 gpio <input|set|clear|toggle> <pin>
15 gpio read <name> <pin>
16 gpio status [-a] [<bank>|<pin>]
17
18The gpio command is used to access General Purpose Inputs/Outputs.
19
20gpio input
21----------
22
23Switch the GPIO *pin* to input mode.
24
25gpio set
26--------
27
28Switch the GPIO *pin* to output mode and set the signal to 1.
29
30gpio clear
31----------
32
33Switch the GPIO *pin* to output mode and set the signal to 0.
34
35gpio toggle
36-----------
37
38Switch the GPIO *pin* to output mode and reverse the signal state.
39
40gpio read
41---------
42
43Read the signal state of the GPIO *pin* and save it in environment variable
44*name*.
45
46gpio status
47-----------
48
49Display the status of one or multiple GPIOs. By default only claimed GPIOs
50are displayed.
Patrice Chotard7bbea7c2022-08-30 16:56:28 +020051gpio status command output fields are::
52
53 <name>: <function>: <value> [x] <label>
54
55*function* can take the following values:
56
57output
58 pin configured in gpio output, *value* indicates the pin's level
59
60input
61 pin configured in gpio input, *value* indicates the pin's level
62
63func
64 pin configured in alternate function, followed by *label*
65 which shows pinmuxing label.
66
67unused
68 pin not configured
69
70*[x]* or *[ ]* indicate respectively if the gpio is used or not.
71
72*label* shows the gpio label.
73
74Parameters
75----------
Heinrich Schuchardt914d4f82022-08-02 14:20:32 +020076
77-a
78 Display GPIOs irrespective of being claimed.
79
80bank
81 Name of a bank of GPIOs to be displayed.
82
83pin
84 Name of a single GPIO to be displayed or manipulated.
85
86Examples
87--------
88
89Switch the status of a GPIO::
90
91 => gpio set a5
92 gpio: pin a5 (gpio 133) value is 1
93 => gpio clear a5
94 gpio: pin a5 (gpio 133) value is 0
95 => gpio toggle a5
96 gpio: pin a5 (gpio 133) value is 1
97 => gpio read myvar a5
98 gpio: pin a5 (gpio 133) value is 1
99 => echo $myvar
100 1
101 => gpio toggle a5
102 gpio: pin a5 (gpio 133) value is 0
103 => gpio read myvar a5
104 gpio: pin a5 (gpio 133) value is 0
105 => echo $myvar
106 0
107
Patrice Chotard7bbea7c2022-08-30 16:56:28 +0200108Show the GPIO status::
109
110 => gpio status
111 Bank GPIOA:
112 GPIOA1: func rgmii-0
113 GPIOA2: func rgmii-0
114 GPIOA7: func rgmii-0
115 GPIOA10: output: 0 [x] hdmi-transmitter@39.reset-gpios
116 GPIOA13: output: 1 [x] red.gpios
117
118 Bank GPIOB:
119 GPIOB0: func rgmii-0
120 GPIOB1: func rgmii-0
121 GPIOB2: func uart4-0
122 GPIOB7: input: 0 [x] mmc@58005000.cd-gpios
123 GPIOB11: func rgmii-0
124
Heinrich Schuchardt914d4f82022-08-02 14:20:32 +0200125Configuration
126-------------
127
128The *gpio* command is only available if CONFIG_CMD_GPIO=y.
129The *gpio read* command is only available if CONFIG_CMD_GPIO_READ=y.
130
131Return value
132------------
133
134If the command succeds the return value $? is set to 0. If an error occurs, the
135return value $? is set to 1.