Skip to content

Commit

Permalink
Initial support for more current Raspberry Pi models (i.e. 5) (#65)
Browse files Browse the repository at this point in the history
* 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 <scot@birdhouse>
  • Loading branch information
cloudkucooland and Bluefooted Boobie authored Jan 9, 2025
1 parent 63e6b8c commit ad2a966
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
18 changes: 11 additions & 7 deletions bcm283x/gpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions rpi/rpi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit ad2a966

Please sign in to comment.