updated dependencies
This commit is contained in:
1 parent
2729a727dc
commit
fb5f6a0d85
9 files changed
+52
-95
No files matched your search
-4
@@ -5,7 +5,6 @@
|
||||
package allwinner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -42,7 +41,6 @@ func IsA20() bool {
|
||||
// It looks for the string "sun50iw1p1" in /proc/device-tree/compatible.
|
||||
func IsA64() bool {
|
||||
detection.do()
|
||||
fmt.Printf("IsA64? %t\n", detection.isA64)
|
||||
return detection.isA64
|
||||
}
|
||||
|
||||
@@ -98,7 +96,6 @@ func (d *detectionS) do() {
|
||||
d.done = true
|
||||
if isArm {
|
||||
for _, c := range distro.DTCompatible() {
|
||||
fmt.Println("distro >>> " + c)
|
||||
if strings.Contains(c, "sun50iw1p1") {
|
||||
d.isA64 = true
|
||||
}
|
||||
@@ -117,7 +114,6 @@ func (d *detectionS) do() {
|
||||
d.isH5 = true
|
||||
}
|
||||
if strings.Contains(c, "sun50i-h6") {
|
||||
fmt.Println("isH6 detected")
|
||||
d.isH6 = true
|
||||
}
|
||||
}
|
||||
|
||||
+7
-46
@@ -11,7 +11,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -309,10 +308,8 @@ func (p *Pin) Read() gpio.Level {
|
||||
//
|
||||
// This function is very fast.
|
||||
func (p *Pin) FastRead() gpio.Level {
|
||||
|
||||
foo := drvGPIO.gpioMemory.groups[p.group].data
|
||||
fmt.Printf("Group value is: %d", foo)
|
||||
return gpio.Level(foo&(1<<p.offset) != 0)
|
||||
status := drvGPIO.gpioMemory.groups[p.group].data
|
||||
return status&(1<<p.offset) != 0
|
||||
}
|
||||
|
||||
// WaitForEdge implements gpio.PinIn.
|
||||
@@ -483,17 +480,9 @@ func (p *Pin) setFunction(f function) {
|
||||
mask := uint32(disabled) << shift
|
||||
v := (uint32(f) << shift) ^ mask
|
||||
// First disable, then setup. This is concurrent safe.
|
||||
original := drvGPIO.gpioMemory.groups[p.group].cfg[off]
|
||||
drvGPIO.gpioMemory.groups[p.group].cfg[off] |= mask
|
||||
drvGPIO.gpioMemory.groups[p.group].cfg[off] &^= v
|
||||
|
||||
modified := original | mask
|
||||
modified &^= v
|
||||
fmt.Printf("Original: %d\n", original)
|
||||
fmt.Printf("Modified: %d\n", modified)
|
||||
fmt.Printf("Memory mapped value: %d\n", drvGPIO.gpioMemory.groups[p.group].cfg[off])
|
||||
if p.function() != f {
|
||||
fmt.Printf("Pin number %d. Pin name %s.\n Expected %d to equals %d \n", p.Number(), p.Name(), p.function(), f)
|
||||
panic(f)
|
||||
}
|
||||
}
|
||||
@@ -1018,7 +1007,6 @@ func (d *driverGPIO) Init() (bool, error) {
|
||||
|
||||
// Mark the right pins as available even if the memory map fails so they can
|
||||
// callback to sysfs.Pins.
|
||||
fmt.Println("Didier initiating allwinner gpio")
|
||||
switch {
|
||||
case IsA64():
|
||||
if err := mapA64Pins(); err != nil {
|
||||
@@ -1041,18 +1029,19 @@ func (d *driverGPIO) Init() (bool, error) {
|
||||
return true, err
|
||||
}
|
||||
case IsH6():
|
||||
fmt.Println("Is H6 CPU!!!")
|
||||
if err := mapH6Pins(); err != nil {
|
||||
return true, err
|
||||
}
|
||||
default:
|
||||
fmt.Println("error: unknown Allwinner CPU model")
|
||||
return false, errors.New("unknown Allwinner CPU model")
|
||||
}
|
||||
|
||||
// gpioBaseAddr is the physical base address of the GPIO registers.
|
||||
gpioBaseAddr := uint32(getBaseAddressDidier())
|
||||
if err := pmem.MapAsPOD(uint64(gpioBaseAddr), &d.gpioMemory); err != nil {
|
||||
gpioBaseAddr, err := getBaseAddress()
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
if err := pmem.MapAsPOD(gpioBaseAddr, &d.gpioMemory); err != nil {
|
||||
if os.IsPermission(err) {
|
||||
return true, fmt.Errorf("need more access, try as root: %v", err)
|
||||
}
|
||||
@@ -1064,38 +1053,10 @@ func (d *driverGPIO) Init() (bool, error) {
|
||||
|
||||
func init() {
|
||||
if isArm {
|
||||
fmt.Println("Stating to initiate allwinner")
|
||||
driverreg.MustRegister(&drvGPIO)
|
||||
}
|
||||
}
|
||||
|
||||
// getBaseAddress queries the virtual file system to retrieve the base address
|
||||
// of the GPIO registers for GPIO pins in groups PA to PI.
|
||||
//
|
||||
// Defaults to 0x01C20800 as per datasheet if it could not query the file
|
||||
// system.
|
||||
func getBaseAddress() uint64 {
|
||||
base := uint64(0x01C20800)
|
||||
link, err := os.Readlink("/sys/bus/platform/drivers/sun50i-pinctrl/driver")
|
||||
if err != nil {
|
||||
return base
|
||||
}
|
||||
parts := strings.SplitN(path.Base(link), ".", 2)
|
||||
if len(parts) != 2 {
|
||||
return base
|
||||
}
|
||||
base2, err := strconv.ParseUint(parts[0], 16, 64)
|
||||
if err != nil {
|
||||
return base
|
||||
}
|
||||
return base2
|
||||
}
|
||||
|
||||
func getBaseAddressDidier() uint64 {
|
||||
fmt.Println("OK did is insane shit.")
|
||||
return uint64(0x300b000)
|
||||
}
|
||||
|
||||
var drvGPIO driverGPIO
|
||||
|
||||
// Ensure that the various structs implement the interfaces they're supposed to.
|
||||
|
||||
+41
-28
@@ -8,14 +8,14 @@
|
||||
package allwinner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"periph.io/x/conn/v3/pin"
|
||||
"periph.io/x/host/v3/sysfs"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// mappingH6 describes the mapping of the H5 processor gpios to their
|
||||
// mappingH6 describes the mapping of the H6 processor gpios to their
|
||||
// alternate functions.
|
||||
// According to https://linux-sunxi.org/H616 H616 and H618 are the same.
|
||||
// allwinner marketing team seems to disagree.
|
||||
@@ -31,25 +31,36 @@ import (
|
||||
// - SDC means SDCard?
|
||||
// - NAND connects to a NAND flash controller.
|
||||
// - CSI and CCI are for video capture.
|
||||
var mappingH6 = map[string][5]pin.Func{
|
||||
"PC0": {"NAND_WE", "SDC2_DS", "SPI0_CLK", "", "PA_EINT0"},
|
||||
"PC1": {"NAND_ALE", "SDC2_RST", "", "", "PA_EINT1"},
|
||||
"PC2": {"NAND_CLE", "", "SPI0_MOSI", "", "PA_EINT2"},
|
||||
"PC3": {"NAND_CE1", "", "SPI0_CS0", "BOOT_SEL1", "PA_EINT3"},
|
||||
"PC4": {"NAND_CE0", "", "SPI0_MIS0", "BOOT_SEL2", "PA_EINT4"},
|
||||
"PC5": {"NAND_RE", "SDC2_CLK", "", "BOOT_SEL3", "PA_EINT5"},
|
||||
"PC6": {"NAND_RB0", "SDC2_CMD", "", "BOOT_SEL4", "PA_EINT6"},
|
||||
"PC7": {"NAND_RB1", "", "SPI0_CS1", "", "PA_EINT7"},
|
||||
"PC8": {"NAND_DQ7", "SDC2_D3", "", "", "PA_EINT8"},
|
||||
//
|
||||
// The data itself has been extracted from the pdf using
|
||||
// https://ronnywang.github.io/pdf-table-extractor/ and some
|
||||
// scripting. The data has been validated manually.
|
||||
//
|
||||
//go:embed H6_pins.json
|
||||
var h6PinsSpec []byte
|
||||
|
||||
"PC9": {"NAND_DQ6", "SDC2_D4", "", "", "PA_EINT9"},
|
||||
"PC10": {"NAND_DQ5", "SDC2_D0", "", "", "PA_EINT10"},
|
||||
"PC11": {"NAND_DQ4", "SDC2_D5", "", "", "PA_EINT11"},
|
||||
"PC12": {"NAND_DQS", "", "", "", "PA_EINT12"},
|
||||
"PC13": {"NAND_DQ3", "SDC2_D1", "", "", "PA_EINT13"},
|
||||
"PC14": {"NAND_DQ2", "SDC2_D6", "", "", "PA_EINT14"},
|
||||
"PC15": {"NAND_DQ1", "SDC2_D1", "SPI0_WP", "", "PA_EINT15"},
|
||||
"PC16": {"NAND_DQ0", "SDC2_D7", "SPI0_HOLD", "", "PA_EINT16"},
|
||||
type serializedPinSpec struct {
|
||||
Name string
|
||||
Function2 pin.Func
|
||||
Function3 pin.Func
|
||||
Function4 pin.Func
|
||||
Function5 pin.Func
|
||||
Function6 pin.Func
|
||||
}
|
||||
|
||||
func getH6SerializedPinSpecs() ([]serializedPinSpec, error) {
|
||||
var serializedPins []serializedPinSpec
|
||||
err := json.Unmarshal(h6PinsSpec, &serializedPins)
|
||||
return serializedPins, err
|
||||
}
|
||||
|
||||
func getAltFunc(pinSpec serializedPinSpec) [5]pin.Func {
|
||||
return [5]pin.Func{
|
||||
pinSpec.Function2,
|
||||
pinSpec.Function3,
|
||||
pinSpec.Function4,
|
||||
pinSpec.Function5,
|
||||
pinSpec.Function6}
|
||||
}
|
||||
|
||||
// mapH6Pins uses mappingH6 to actually set the altFunc fields of all gpio
|
||||
@@ -57,15 +68,17 @@ var mappingH6 = map[string][5]pin.Func{
|
||||
//
|
||||
// It is called by the generic allwinner processor code if an H6 is detected.
|
||||
func mapH6Pins() error {
|
||||
fmt.Println("Initializing H6 pins.")
|
||||
for name, altFuncs := range mappingH6 {
|
||||
pin := cpupins[name]
|
||||
pin.altFunc = altFuncs
|
||||
serializedPinSpecs, err := getH6SerializedPinSpecs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, pinSpec := range serializedPinSpecs {
|
||||
pin := cpupins[pinSpec.Name]
|
||||
pin.altFunc = getAltFunc(pinSpec)
|
||||
pin.available = true
|
||||
if strings.Contains(string(altFuncs[4]), "_EINT") {
|
||||
if strings.Contains(string(pinSpec.Function6), "_EINT") {
|
||||
pin.supportEdge = true
|
||||
}
|
||||
|
||||
// Initializes the sysfs corresponding pin right away.
|
||||
pin.sysfsPin = sysfs.Pins[pin.Number()]
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user