Skip to content

Commit 339d73c

Browse files
authored
allwinner: Support for H2+ and H3 (OrangePiZero) (#23)
* Support for Allwinner H2+ and H3 (OrangePiSZero) Add support for the Allwinner H2+ and H3 CPUs, which are almost identical. The H2+ has no GBit MAC and no 4h HDMI, but the rest is completely identical. For this library tho, it is not relevant, so we can combine these two CPU types into one single H3 and detect the H2+ as a H3 CPU. Support for detecting Orange Pi Zero boards are added, which uses the H3 SOC. The Pinouts are from the Orange Pi manual. Fixes #1
1 parent de9a57f commit 339d73c

File tree

10 files changed

+389
-4
lines changed

10 files changed

+389
-4
lines changed

AUTHORS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# This does not necessarily list everyone who has contributed code, since in
44
# some cases, their employer may be the copyright holder. To see the full list
55
# of contributors, see the revision history in source control.
6+
7+
# Please keep the list sorted.
8+
9+
Aaron Fischer <[email protected]>
610
Cássio Botaro <[email protected]>
711
Fractal Industries, Inc
812
Google Inc.
@@ -12,4 +16,3 @@ Max Ekman <[email protected]>
1216
Rifiniti, Inc
1317
Stephan Sperber
1418
Thorsten von Eicken <[email protected]>
15-

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
# Please keep the list sorted.
2828

29+
Aaron Fischer <[email protected]>
2930
Cássio Botaro <[email protected]>
3031
Eugene Dzhurynsky <[email protected]>
3132
Hidetoshi Shimokawa <[email protected]>

allwinner/detect.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Periph Authors. All rights reserved.
1+
// Copyright 2022 The Periph Authors. All rights reserved.
22
// Use of this source code is governed under the Apache License, Version 2.0
33
// that can be found in the LICENSE file.
44

@@ -44,6 +44,14 @@ func IsA64() bool {
4444
return detection.isA64
4545
}
4646

47+
// IsH3 detects whether the host CPU is an Allwinner H3/H2+ Plus CPU.
48+
//
49+
// It looks for the string "sun8i-h2-plus" or "sun8i-h3" in /proc/device-tree/compatible.
50+
func IsH3() bool {
51+
detection.do()
52+
return detection.isH3
53+
}
54+
4755
// IsH5 detects whether the host CPU is an Allwinner H5 CPU.
4856
//
4957
// It looks for the string "sun50i-h5" in /proc/device-tree/compatible.
@@ -61,6 +69,7 @@ type detectionS struct {
6169
isR8 bool
6270
isA20 bool
6371
isA64 bool
72+
isH3 bool
6473
isH5 bool
6574
}
6675

@@ -87,11 +96,16 @@ func (d *detectionS) do() {
8796
if strings.Contains(c, "sun7i-a20") {
8897
d.isA20 = true
8998
}
99+
// H2+ is a subtype of H3 and nearly compatible (only lacks GBit MAC and
100+
// 4k HDMI Output), so it is safe to map H2+ as an H3.
101+
if strings.Contains(c, "sun8i-h2-plus") || strings.Contains(c, "sun8i-h3") {
102+
d.isH3 = true
103+
}
90104
if strings.Contains(c, "sun50i-h5") {
91105
d.isH5 = true
92106
}
93107
}
94-
d.isAllwinner = d.isA64 || d.isR8 || d.isA20 || d.isH5
108+
d.isAllwinner = d.isA64 || d.isR8 || d.isA20 || d.isH3 || d.isH5
95109

96110
if !d.isAllwinner {
97111
// The kernel in the image that comes pre-installed on the pcDuino3 Nano

allwinner/gpio.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 The Periph Authors. All rights reserved.
1+
// Copyright 2022 The Periph Authors. All rights reserved.
22
// Use of this source code is governed under the Apache License, Version 2.0
33
// that can be found in the LICENSE file.
44

@@ -1020,6 +1020,10 @@ func (d *driverGPIO) Init() (bool, error) {
10201020
if err := mapA20Pins(); err != nil {
10211021
return true, err
10221022
}
1023+
case IsH3():
1024+
if err := mapH3Pins(); err != nil {
1025+
return true, err
1026+
}
10231027
case IsH5():
10241028
if err := mapH5Pins(); err != nil {
10251029
return true, err

allwinner/h3.go

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// Copyright 2022 The Periph Authors. All rights reserved.
2+
// Use of this source code is governed under the Apache License, Version 2.0
3+
// that can be found in the LICENSE file.
4+
5+
// This file contains pin mapping information that is specific to the Allwinner
6+
// H2+ and H3 model.
7+
8+
package allwinner
9+
10+
import (
11+
"strings"
12+
13+
"periph.io/x/conn/v3/pin"
14+
"periph.io/x/host/v3/sysfs"
15+
)
16+
17+
// mappingH3 describes the mapping of the H3 processor GPIO pins to their
18+
// functions. The mappings source is the official H3 Datasheet, version 1.0,
19+
// page 74 (chapter 3.2 GPIO Multiplexing Functions).
20+
// http://dl.linux-sunxi.org/H3/Allwinner_H3_Datasheet_V1.0.pdf
21+
var mappingH3 = map[string][5]pin.Func{
22+
"PA0": {"UART2_TX", "JTAG_MS", "", "", "PA_EINT0"},
23+
"PA1": {"UART2_RX", "JTAG_CK", "", "", "PA_EINT1"},
24+
"PA2": {"UART2_RTS", "JTAG_DO", "", "", "PA_EINT2"},
25+
"PA3": {"UART2_CTS", "JTAG_DI", "", "", "PA_EINT3"},
26+
"PA4": {"UART0_TX", "", "", "", "PA_EINT4"},
27+
"PA5": {"UART0_RX", "PWM0", "", "", "PA_EINT5"},
28+
"PA6": {"SIM_PWREN", "PWM1", "", "", "PA_EINT6"},
29+
"PA7": {"SIM_CK", "", "", "", "PA_EINT7"},
30+
"PA8": {"SIM_DATA", "", "", "", "PA_EINT8"},
31+
"PA9": {"SIM_RST", "", "", "", "PA_EINT9"},
32+
"PA10": {"SIM_DET", "", "", "", "PA_EINT10"},
33+
"PA11": {"TWI0_SCK", "DI_TX", "", "", "PA_EINT11"},
34+
"PA12": {"TWI0_SDA", "DI_RX", "", "", "PA_EINT12"},
35+
"PA13": {"SPI1_CS", "UART3_TX", "", "", "PA_EINT13"},
36+
"PA14": {"SPI1_CLK", "UART3_RX", "", "", "PA_EINT14"},
37+
"PA15": {"SPI1_MOSI", "UART3_RTS", "", "", "PA_EINT15"},
38+
"PA16": {"SPI1_MOSI", "UART3_CTS", "", "", "PA_EINT16"},
39+
"PA17": {"OWA_OUT", "", "", "", "PA_EINT17"},
40+
"PA18": {"PCM0_SYNC", "TWI1_SCK", "", "", "PA_EINT18"},
41+
"PA19": {"PCM0_CLK", "TWI1_SDA", "", "", "PA_EINT19"},
42+
"PA20": {"PCM0_DOUT", "SIM_VPPEN", "", "", "PA_EINT20"},
43+
"PA21": {"PCM0_DIN", "SIM_VPPPP", "", "", "PA_EINT21"},
44+
45+
"PC0": {"NAND_WE", "SPI0_MOSI"},
46+
"PC1": {"NAND_ALE", "SPI0_MISO"},
47+
"PC2": {"NAND_CLE", "SPI0_CLK"},
48+
"PC3": {"NAND_CE1", "SPI0_CS"},
49+
"PC4": {"NAND_CE0"},
50+
"PC5": {"NAND_RE", "SDC2_CLK"},
51+
"PC6": {"NAND_RB0", "SDC2_CMD"},
52+
"PC7": {"NAND_RB1"},
53+
"PC8": {"NAND_DQ0", "SDC2_D0"},
54+
"PC9": {"NAND_DQ1", "SDC2_D1"},
55+
"PC10": {"NAND_DQ2", "SDC2_D2"},
56+
"PC11": {"NAND_DQ3", "SDC2_D3"},
57+
"PC12": {"NAND_DQ4", "SDC2_D4"},
58+
"PC13": {"NAND_DQ5", "SDC2_D5"},
59+
"PC14": {"NAND_DQ6", "SDC2_D6"},
60+
"PC15": {"NAND_DQ7", "SDC2_D7"},
61+
"PC16": {"NAND_DQS", "SDC2_RST"},
62+
63+
"PD0": {"RGMII_RXD3"},
64+
"PD1": {"RGMII_RXD2"},
65+
"PD2": {"RGMII_RXD1"},
66+
"PD3": {"RGMII_RXD0"},
67+
"PD4": {"RGMII_RXCK"},
68+
"PD5": {"RGMII_RXCTL"},
69+
"PD6": {"RGMII_NULL"},
70+
"PD7": {"RGMII_TXD3"},
71+
"PD8": {"RGMII_TXD2"},
72+
"PD9": {"RGMII_TXD1"},
73+
"PD10": {"RGMII_TXD0"},
74+
"PD11": {"RGMII_NULL"},
75+
"PD12": {"RGMII_TXCK"},
76+
"PD13": {"RGMII_TXCTL"},
77+
"PD14": {"RGMII_NULL"},
78+
"PD15": {"RGMII_CLKIN"},
79+
"PD16": {"MDC"},
80+
"PD17": {"MDIO"},
81+
82+
"PE0": {"CSI_PCLK", "TS_CLK"},
83+
"PE1": {"CSI_MCLK", "TS_ERR"},
84+
"PE2": {"CSI_HSYNC", "TS_SYNC"},
85+
"PE3": {"CSI_VSYNC", "TS_DVLD"},
86+
"PE4": {"CSI_D0", "TS_D0"},
87+
"PE5": {"CSI_D1", "TS_D1"},
88+
"PE6": {"CSI_D2", "TS_D2"},
89+
"PE7": {"CSI_D3", "TS_D3"},
90+
"PE8": {"CSI_D4", "TS_D4"},
91+
"PE9": {"CSI_D5", "TS_D5"},
92+
"PE10": {"CSI_D6", "TS_D6"},
93+
"PE11": {"CSI_D7", "TS_D7"},
94+
"PE12": {"CSI_SCK", "TWI2_SCK"},
95+
"PE13": {"CSI_SDA", "TWI2_SDA"},
96+
"PE14": {""},
97+
"PE15": {""},
98+
99+
"PF0": {"SDC0_D1", "JTAG_MS"},
100+
"PF1": {"SDC0_D0", "JTAG_DI"},
101+
"PF2": {"SDC0_CLK", "UART0_TX"},
102+
"PF3": {"SDC0_CMD", "JTAG_DO"},
103+
"PF4": {"SDC0_D3", "UART0_RX"},
104+
"PF5": {"SDC0_D2", "JTAG_CK"},
105+
"PF6": {"SDC0_DET"},
106+
107+
"PG0": {"SDC1_CLK", "", "", "", "PG_EINT0"},
108+
"PG1": {"SDC1_CMD", "", "", "", "PG_EINT1"},
109+
"PG2": {"SDC1_D0", "", "", "", "PG_EINT2"},
110+
"PG3": {"SDC1_D1", "", "", "", "PG_EINT3"},
111+
"PG4": {"SDC1_D2", "", "", "", "PG_EINT4"},
112+
"PG5": {"SDC1_D3", "", "", "", "PG_EINT5"},
113+
"PG6": {"UART1_TX", "", "", "", "PG_EINT6"},
114+
"PG7": {"UART1_RX", "", "", "", "PG_EINT7"},
115+
"PG8": {"UART1_RTS", "", "", "", "PG_EINT8"},
116+
"PG9": {"UART1_CTS", "", "", "", "PG_EINT9"},
117+
"PG10": {"PCM1_SYNC", "", "", "", "PG_EINT10"},
118+
"PG11": {"PCM1_CLK", "", "", "", "PG_EINT11"},
119+
"PG12": {"PCM1_DOUT", "", "", "", "PG_EINT12"},
120+
"PG13": {"PCM1_DIN", "", "", "", "PG_EINT13"},
121+
122+
"PL0": {"S_TWI_SCK", "", "", "", "S_PL_EINT0"},
123+
"PL1": {"S_TWI_SDA", "", "", "", "S_PL_EINT1"},
124+
"PL2": {"S_UART_TX", "", "", "", "S_PL_EINT2"},
125+
"PL3": {"S_UART_RX", "", "", "", "S_PL_EINT3"},
126+
"PL4": {"S_JTAG_MS", "", "", "", "S_PL_EINT4"},
127+
"PL5": {"S_JTAG_CK", "", "", "", "S_PL_EINT5"},
128+
"PL6": {"S_JTAG_DO", "", "", "", "S_PL_EINT6"},
129+
"PL7": {"S_JTAG_DI", "", "", "", "S_PL_EINT7"},
130+
"PL8": {"", "", "", "", "S_PL_EINT8"},
131+
"PL9": {"", "", "", "", "S_PL_EINT9"},
132+
"PL10": {"S_PWM", "", "", "", "S_PL_EINT10"},
133+
"PL11": {"S_CIR_RX", "", "", "", "S_PL_EINT12"},
134+
}
135+
136+
// mapH3Pins uses mappingH3 to set the altFunc fields of all the GPIO pings and
137+
// mark them as available. This is called if the generic allwinner processor
138+
// code detects a H2+ or H3 processor.
139+
func mapH3Pins() error {
140+
for name, altFuncs := range mappingH3 {
141+
pin := cpupins[name]
142+
pin.altFunc = altFuncs
143+
pin.available = true
144+
if strings.Contains(string(altFuncs[4]), "_EINT") ||
145+
strings.Contains(string(altFuncs[3]), "_EINT") {
146+
pin.supportEdge = true
147+
}
148+
149+
// Initializes the sysfs corresponding pin right away.
150+
pin.sysfsPin = sysfs.Pins[pin.Number()]
151+
}
152+
return nil
153+
}

orangepi/doc.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2022 The Periph Authors. All rights reserved.
2+
// Use of this source code is governed under the Apache License, Version 2.0
3+
// that can be found in the LICENSE file.
4+
5+
// Package orangepi contains Orange Pi hardware logic.
6+
//
7+
// Requires armbian jessie server.
8+
//
9+
// # Physical
10+
//
11+
// http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/index.html
12+
package orangepi

0 commit comments

Comments
 (0)