Heinrich Schuchardt | 914d4f8 | 2022-08-02 14:20:32 +0200 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+: |
| 2 | |
Heinrich Schuchardt | 1b0c316 | 2024-01-14 14:53:13 +0100 | [diff] [blame] | 3 | .. index:: |
| 4 | single: gpio (command) |
| 5 | |
Heinrich Schuchardt | 914d4f8 | 2022-08-02 14:20:32 +0200 | [diff] [blame] | 6 | gpio command |
| 7 | ============ |
| 8 | |
| 9 | Synopsis |
| 10 | -------- |
| 11 | |
| 12 | :: |
| 13 | |
| 14 | gpio <input|set|clear|toggle> <pin> |
| 15 | gpio read <name> <pin> |
| 16 | gpio status [-a] [<bank>|<pin>] |
| 17 | |
| 18 | The gpio command is used to access General Purpose Inputs/Outputs. |
| 19 | |
| 20 | gpio input |
| 21 | ---------- |
| 22 | |
| 23 | Switch the GPIO *pin* to input mode. |
| 24 | |
| 25 | gpio set |
| 26 | -------- |
| 27 | |
| 28 | Switch the GPIO *pin* to output mode and set the signal to 1. |
| 29 | |
| 30 | gpio clear |
| 31 | ---------- |
| 32 | |
| 33 | Switch the GPIO *pin* to output mode and set the signal to 0. |
| 34 | |
| 35 | gpio toggle |
| 36 | ----------- |
| 37 | |
| 38 | Switch the GPIO *pin* to output mode and reverse the signal state. |
| 39 | |
| 40 | gpio read |
| 41 | --------- |
| 42 | |
| 43 | Read the signal state of the GPIO *pin* and save it in environment variable |
| 44 | *name*. |
| 45 | |
| 46 | gpio status |
| 47 | ----------- |
| 48 | |
| 49 | Display the status of one or multiple GPIOs. By default only claimed GPIOs |
| 50 | are displayed. |
Patrice Chotard | 7bbea7c | 2022-08-30 16:56:28 +0200 | [diff] [blame] | 51 | gpio status command output fields are:: |
| 52 | |
| 53 | <name>: <function>: <value> [x] <label> |
| 54 | |
| 55 | *function* can take the following values: |
| 56 | |
| 57 | output |
| 58 | pin configured in gpio output, *value* indicates the pin's level |
| 59 | |
| 60 | input |
| 61 | pin configured in gpio input, *value* indicates the pin's level |
| 62 | |
| 63 | func |
| 64 | pin configured in alternate function, followed by *label* |
| 65 | which shows pinmuxing label. |
| 66 | |
| 67 | unused |
| 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 | |
| 74 | Parameters |
| 75 | ---------- |
Heinrich Schuchardt | 914d4f8 | 2022-08-02 14:20:32 +0200 | [diff] [blame] | 76 | |
| 77 | -a |
| 78 | Display GPIOs irrespective of being claimed. |
| 79 | |
| 80 | bank |
| 81 | Name of a bank of GPIOs to be displayed. |
| 82 | |
| 83 | pin |
| 84 | Name of a single GPIO to be displayed or manipulated. |
| 85 | |
| 86 | Examples |
| 87 | -------- |
| 88 | |
| 89 | Switch 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 Chotard | 7bbea7c | 2022-08-30 16:56:28 +0200 | [diff] [blame] | 108 | Show 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 Schuchardt | 914d4f8 | 2022-08-02 14:20:32 +0200 | [diff] [blame] | 125 | Configuration |
| 126 | ------------- |
| 127 | |
| 128 | The *gpio* command is only available if CONFIG_CMD_GPIO=y. |
| 129 | The *gpio read* command is only available if CONFIG_CMD_GPIO_READ=y. |
| 130 | |
| 131 | Return value |
| 132 | ------------ |
| 133 | |
| 134 | If the command succeds the return value $? is set to 0. If an error occurs, the |
| 135 | return value $? is set to 1. |