From ad2a966594065632477ea881331533022bad415a Mon Sep 17 00:00:00 2001 From: Scot Bontrager Date: Thu, 9 Jan 2025 13:12:24 -0600 Subject: [PATCH] Initial support for more current Raspberry Pi models (i.e. 5) (#65) * start work, based on https://github.com/AndrewFromMelbourne/raspberry_pi_revision/blob/master/raspberry_pi_revision.c * this isn't right yet, need to find datasheets, and this switch needs a lot more cases * docmument research --------- Co-authored-by: Bluefooted Boobie --- bcm283x/gpio.go | 18 +++++++++++------- rpi/rpi.go | 12 ++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/bcm283x/gpio.go b/bcm283x/gpio.go index 04e0992..ad7ad8b 100644 --- a/bcm283x/gpio.go +++ b/bcm283x/gpio.go @@ -1338,21 +1338,24 @@ func (d *driverGPIO) Init() (bool, error) { // Let's play safe here. dTCompatible := strings.Join(distro.DTCompatible(), " ") // Reference: https://www.raspberrypi.org/documentation/hardware/raspberrypi/peripheral_addresses.md - if strings.Contains(dTCompatible, "bcm2708") || - strings.Contains(dTCompatible, "bcm2835") { + switch { + case strings.Contains(dTCompatible, "bcm2708"), strings.Contains(dTCompatible, "bcm2835"): // RPi0/1. d.baseAddr = 0x20000000 d.dramBus = 0x40000000 d.useLegacyPull = true - } else if strings.Contains(dTCompatible, "bcm2709") || - strings.Contains(dTCompatible, "bcm2836") || - strings.Contains(dTCompatible, "bcm2710") || - strings.Contains(dTCompatible, "bcm2837") { + case strings.Contains(dTCompatible, "bcm2709"), strings.Contains(dTCompatible, "bcm2836"), strings.Contains(dTCompatible, "bcm2710"), strings.Contains(dTCompatible, "bcm2837"): // RPi2+ d.baseAddr = 0x3F000000 d.dramBus = 0xC0000000 d.useLegacyPull = true - } else { + case strings.Contains(dTCompatible, "bcm2712"): + // RPi5 -- https://github.com/WiringPi/WiringPi/blob/master/wiringPi/wiringPi.c doesn't look optimistic + d.baseAddr = 0xFE000000 + d.dramBus = 0xC0000000 + d.useLegacyPull = false + mapping = mapping2711 + default: // RPi4B+ d.baseAddr = 0xFE000000 d.dramBus = 0xC0000000 @@ -1370,6 +1373,7 @@ func (d *driverGPIO) Init() (bool, error) { // virtual address space starting at address 0xF2000000. Thus a peripheral // advertised here at bus address 0x7Ennnnnn is available in the ARM kenel at // virtual address 0xF2nnnnnn. + d.gpioBaseAddr = d.baseAddr + 0x200000 // Mark the right pins as available even if the memory map fails so they can diff --git a/rpi/rpi.go b/rpi/rpi.go index b149de7..f7cbe18 100644 --- a/rpi/rpi.go +++ b/rpi/rpi.go @@ -385,6 +385,7 @@ const ( memory2GB revisionCode = 3 << memoryShift memory4GB revisionCode = 4 << memoryShift memory8GB revisionCode = 5 << memoryShift + memory16GB revisionCode = 6 << memoryShift sonyUK revisionCode = 0 << manufacturerShift egoman revisionCode = 1 << manufacturerShift @@ -397,6 +398,7 @@ const ( bcm2836 revisionCode = 1 << processorShift bcm2837 revisionCode = 2 << processorShift bcm2711 revisionCode = 3 << processorShift + bcm2712 revisionCode = 4 << processorShift board1A revisionCode = 0x0 << boardShift board1B revisionCode = 0x1 << boardShift @@ -417,6 +419,11 @@ const ( boardZero2W revisionCode = 0x12 << boardShift board400 revisionCode = 0x13 << boardShift boardCM4 revisionCode = 0x14 << boardShift + boardCM4S revisionCode = 0x15 << boardShift + board5 revisionCode = 0x17 << boardShift + boardCM5 revisionCode = 0x18 << boardShift + board500 revisionCode = 0x19 << boardShift + boardCM5Lite revisionCode = 0x20 << boardShift ) // features represents the different features on various Raspberry Pi boards. @@ -514,6 +521,11 @@ func (f *features) init(v uint32) error { f.hdrHDMI = true case boardCM4: // Compute Module does not have a SODIMM header. + case board5: + f.hdrP1P40 = true + f.hdrAudio = true + f.audioLeft41 = true + f.hdrHDMI = true default: return fmt.Errorf("rpi: unknown hardware version: 0x%x", r) }