Using a GPIO in Linux

Almost all function pins of a SOC are GPIO ( General Purpose Input Output).
They can be configured to serve as a simple input, output or with a special function (i.e. I2C or UART).
Most pins can be configured with additional settings like drive-strength, pull-up or -down, keeper, etc.

Using a GPIO from Command Line

As already mentioned a pin can be configured to serve as GPIO or as a special function.
The following commands only work as expected, when the pin is configured as GPIO!

Path in Sysfs:

/sys/class/gpio

First thing to do, is to export control of a GPIO to userspace by writing its number to 'export':

$ echo 68 > /sys/class/gpio/export

This will create an entry for gpio3.IO[4] = ((bank-1)*32)+pin = ((3-1)*32)+4 = 68 at:

/sys/class/gpio/gpio68

To reverse the effect of exporting GPIO 68 to userspace call:

Configure GPIO as Input

Read GPIO level

Configure GPIO as Output

Instead of using 'out', you can use 'low' and 'high' to ensure glitch free initialization:

Write GPIO level

Set pin low:

Set pin high:

Trizeps VII & Trizeps VIII GPIOs

SODIMM

Name

1

MIC_OUT

 

 

2

AD3

 

 

3

MIC_GND

 

 

4

AD2

 

 

5

LINEIN_L

 

 

6

AD1

 

 

7

LINEIN_R

 

 

8

AD0

 

 

9

AGND

 

 

10

VDDA

 

 

11

AGND

 

 

12

VDDA

 

 

13

HEADPHONE_GND

 

 

14

TSPX

 

 

15

HEADPHONE_L

 

 

16

TSMX

 

 

17

HEADPHONE_R

 

 

18

TSPY

 

 

19

UART3_RXD

gpio4.IO[7]

gpio5.IO[6]

20

TSMY

 

 

21

UART3_TXD

gpio4.IO[6]

gpio5.IO[7]

22

VDD_OTP

 

gpio5.IO[8]

23

UART1_DTR

gpio7.IO[7]

gpio3.IO[19]

24

BATT

 

gpio5.IO[9]

25

UART1_CTS

gpio7.IO[3]

gpio5.IO[27]

26

RESET_IN

gpio2.IO[7]

 

27

UART1_RTS

gpio7.IO[2]

gpio5.IO[26]

28

SPEAKER_P

 

 

29

UART1_DSR

gpio6.IO[14]

gpio3.IO[20]

30

SPEAKER_L

 

 

31

UART1_DCD

gpio6.IO[15]

gpio4.IO[21]

32

UART2_CTS

gpio7.IO[5]

gpio5.IO[29]

33

UART1_RXD

gpio7.IO[1]

gpio5.IO[22]

34

UART2_RTS

gpio7.IO[4]

gpio5.IO[28]

35

UART1_TXD

gpio7.IO[0]

gpio5.IO[23]

36

UART2_RXD

gpio6.IO[18]

gpio5.IO[24]

37

UART1_RI

gpio1.IO[5]

gpio4.IO[22]

38

UART2_TXD

gpio6.IO[17]

gpio5.IO[25]

39

GND

 

 

40

VCC

 

 

41

GND

 

 

42

VCC

 

 

43

IRQ_SP43

gpio2.IO[6]

gpio1.IO[7]

44

LCD_DE

gpio4.IO[17]

 

45

SP45

gpio2.IO[3]

gpio3.IO[4]

46

LCD_D07

gpio4.IO[28]

 

47

SD2_CLK

gpio1.IO[10]

gpio2.IO[13]

48

LCD_D09

gpio4.IO[30]

 

49

CIF_DATA0

gpio5.IO[30]

gpio4.IO[2]

50

LCD_D11

gpio5.IO[5]

 

51

SD2_DATA3

gpio1.IO[12]

gpio2.IO[18]

52

LCD_D12

gpio5.IO[6]

 

53

CIF_DATA1

gpio5.IO[31]

gpio4.IO[3]

54

LCD_D13

gpio5.IO[7]

 

55

SP55

gpio2.IO[5]

gpio3.IO[21]

56

LCD_PCLK

gpio4.IO[16]

 

57

CIF_DATA2

gpio6.IO[0]

gpio4.IO[4]

58

LCD_D03

gpio4.IO[24]

 

59

SD2_CARD_DETECT

gpio1.IO[4]

gpio2.IO[12]

60

LCD_D02

gpio4.IO[23]

 

61

CIF_DATA3

gpio6.IO[1]

gpio4.IO[5]

62

LCD_D08

gpio4.IO[29]

 

63

CIF_DATA4

gpio6.IO[2]

gpio4.IO[6]

64

LCD_D15

gpio5.IO[9]

 

65

CIF_DATA5

gpio6.IO[3]

gpio4.IO[7]

66

LCD_D14

gpio5.IO[8]

 

67

CIF_DATA6

gpio6.IO[4]

gpio4.IO[8]

68

LCD_HSYNC

gpio4.IO[18]

 

69

PWM1

gpio6.IO[9]

gpio5.IO[2]

70

LCD_D01

gpio4.IO[22]

 

71

CIF_DATA7

gpio6.IO[5]

gpio4.IO[9]

72

LCD_D05

gpio4.IO[26]

 

73

CIF_DATA8 / Backlight_Enable

gpio4.IO[20]

gpio3.IO[22]

74

LCD_D10

gpio4.IO[31]

 

75

CIF_DATA9 / SP75

gpio5.IO[28]

gpio3.IO[23]

76

LCD_D00

gpio4.IO[21]

 

77

PWM2

gpio1.IO[9]

gpio1.IO[1]

78

LCD_D04

gpio4.IO[25]

 

79

POWERFAIL

gpio2.IO[4]

gpio3.IO[24]

80

LCD_D06

gpio4.IO[27]

 

81

SD2_DATA1

gpio1.IO[14]

gpio2.IO[16]

82

LCD_VSYNC

gpio4.IO[19]

 

83

GND

 

 

84

VCC

 

 

85

SD2_DATA2

gpio1.IO[13]

gpio2.IO[17]

86

CIF_VSYNC / SPI_SS0

gpio4.IO[9] / gpio5.IO[21]

gpio5.IO[13]

87

RESET_OUT

gpio7.IO[12]

gpio1.IO[2] / gpio3.IO[14]

88

CIF_MCLK / SPI_SCLK

gpio4.IO[6] / gpio1.IO[0]

gpio4.IO[20] / gpio5.IO[10]

89

WE / SP89

gpio2.IO[26]

 

90

CIF_PCLK

gpio4.IO[8] / gpio5.IO[18]

gpio4.IO[1] / gpio5.IO[12]

91

OE / SP91

gpio2.IO[25]

 

92

CIF_HSYNC

gpio4.IO[8] / gpio5.IO[19]

gpio4.IO[0] / gpio5.IO[11]

93

RD/WR / SP95

gpio5.IO[29]

gpio3.IO[18]

94

I2C1_SCL / SP94

gpio5.IO[27]

gpio5.IO[14]

95

RDY

gpio5.IO[0]

gpio3.IO[16]

96

I2C1_SDA / SP96

gpio5.IO[26]

gpio5.IO[15]

97

CAN1_RX

gpio1.IO[8]

 

98

SP98

gpio7.IO[6]

gpio1.IO[0]

99

CAN1_TX

gpio1.IO[7]

 

100

LCD_PWR_EN

gpio5.IO[20]

gpio1.IO[5]

101

CAN2_RX

gpio4.IO[15]

gpio4.IO[31]

102

SP102

gpio7.IO[8]

gpio1.IO[8]

103

CAN2_TX

gpio4.IO[14]

gpio5.IO[0]

104

SP104

gpio2.IO[27]

gpio3.IO[11]

105

CS1

 

gpio3.IO[0]

106

CS4

 

gpio3.IO[25]

107

CS3

gpio2.IO[23]

gpio3.IO[1]

108

VCC

 

 

109

GND

 

 

110

A08

gpio3.IO[8]

gpio4.IO[12]

111

A00

gpio3.IO[0]

gpio3.IO[6]

112

A09

gpio3.IO[9]

gpio4.IO[13]

113

A01

gpio3.IO[1]

gpio3.IO[7]

114

A10

gpio3.IO[10]

gpio4.IO[14]

115

A02

gpio3.IO[2]

gpio5.IO[20]

116

A11

gpio3.IO[11]

gpio4.IO[15]

117

A03

gpio3.IO[3]

gpio3.IO[8]

118

A12

gpio3.IO[12]

gpio4.IO[16]

119

A04

gpio3.IO[4]

gpio3.IO[9]

120

A13

gpio3.IO[13]

gpio4.IO[17]

121

A05

gpio3.IO[5]

gpio3.IO[10]

122

A14

gpio3.IO[14]

gpio4.IO[18]

123

A06

gpio3.IO[6]

gpio1.IO[3]

124

A15

gpio3.IO[15]

gpio4.IO[19]

125

A07

gpio3.IO[7]

gpio1.IO[6]

126

DQM0

gpio2.IO[28]

gpio4.IO[10]

127

USB_OTG_PEN

gpio2.IO[0]

gpio1.IO[12]

128

DQM1

gpio2.IO[29]

gpio4.IO[11]

129

USB_HOST_PEN

gpio2.IO[2]

gpio1.IO[14]

130

DQM2

gpio2.IO[30]

 

131

USB_HOST_OC

gpio1.IO[3]

gpio1.IO[15]

132

DQM3

gpio2.IO[31]

gpio3.IO[12]

133

USB_OTG_OC

gpio6.IO[10]

gpio1.IO[13]

134

A25

gpio5.IO[2]

gpio3.IO[3]

135

USB_OTG_VBUS

 

 

136

A24

gpio5.IO[4]

gpio3.IO[15]

137

USB_OTG_ID

gpio1.IO[1]

 

138

A23

gpio6.IO[6]

 

139

USB_OTG_DP

 

 

140

A22

gpio2.IO[16]

 

141

USB_OTG_DN

 

 

142

A21

gpio2.IO[17]

 

143

USB_HOST_DP

 

 

144

A20

gpio2.IO[18]

 

145

USB_HOST_DN

 

 

146

A19 / PCM_IN

gpio2.IO[19]

gpio5.IO[1]

147

GND

 

 

148

VCC

 

 

149

D00 / DDC_SDA

gpio3.IO[16]

 

150

D16 / LCD_D16

gpio5.IO[10]

 

151

D01

gpio3.IO[17]

 

152

D17 / LCD_D17

gpio5.IO[11]

 

153

D02

gpio3.IO[18]

 

154

D18 / PCIE_WAKE

gpio6.IO[7]

gpio3.IO[13]

155

D03

gpio3.IO[19]

 

156

D19 / LDO

 

 

157

D04

gpio3.IO[20]

 

158

D20 / PCIE_CLKN

 

 

159

D05 / SPDIF_IN

gpio3.IO[21]

gpio5.IO[4]

160

D21 / PCIE_CLKP

 

 

161

D06 / SPDIF_OUT

gpio3.IO[22]

gpio5.IO[3]

162

D22 / PCIE_TXP

 

 

163

D07 / SPDIF_EXT_CLK

gpio3.IO[23]

gpio5.IO[5]

164

D23 / PCIE_TXN

 

 

165

D08

gpio3.IO[24]

 

166

D24 / PCIE_RXP

 

 

167

D09

gpio3.IO[25]

 

168

D25 / PCIE_RXN

 

 

169

D10

gpio3.IO[26]

 

170

LCD_D21

gpio5.IO[15]

 

171

D11

gpio3.IO[27]

 

172

LCD_D20

gpio5.IO[14]

 

173

D12

gpio3.IO[28]

 

174

LCD_D19

gpio5.IO[13]

 

175

D13

gpio3.IO[29]

 

176

LCD_D18

gpio5.IO[12]

 

177

D14

gpio3.IO[30]

 

178

LCD_D23

gpio5.IO[17]

 

179

D15

gpio3.IO[31]

 

180

LCD_D22

gpio5.IO[16]

 

181

GND

 

 

182

VCC

 

 

183

ETH_LINK_AKT

 

 

184

A18 / PCM_OUT

gpio2.IO[20]

gpio4.IO[30]

185

ETH_SPEED

 

 

186

A17 / PCM_CLK

gpio2.IO[21]

gpio4.IO[29]

187

ETH_TXN

 

 

188

A16 / PCM_SYNC

gpio2.IO[22]

gpio4.IO[28]

189

ETH_TXP

 

 

190

SD2_CMD

gpio1.IO[11]

gpio2.IO[14]

191

ETH_GND

 

 

192

SD2_DATA0

gpio1.IO[15]

gpio2.IO[15]

193

ETH_RXN

 

 

194

I2C2_SDA

gpio4.IO[13]

gpio5.IO[17]

195

ETH_RXP

 

 

196

I2C2_SCL

gpio4.IO[12]

gpio5.IO[16]

197

GND

 

 

198

VCC

 

 

199

GND

 

 

200

VCC RTC