arch/bcm2711, boards/raspberry-pi-4b: Add preliminary support for the BCM2711 and Raspberry Pi 4B.

Includes a Mini-UART NSH console for the 4B, tested on the 4GB RAM
model. Part of an I2C driver which can only read, boiler-plate for a SPI
driver, and a GPIO driver with limited pins. Some tools are present for
automatically fetching the boot files and creating the `config.txt` file
based on selected Kconfig options.
This commit is contained in:
Matteo Golin
2024-07-21 11:29:34 -04:00
committed by Xiang Xiao
parent 188a7ce990
commit e96fb6b118
53 changed files with 8100 additions and 2 deletions
@@ -0,0 +1,41 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
if ARCH_BOARD_RASPBERRYPI_4B
choice
prompt "Raspberry Pi 4B RAM size"
default RPI4B_RAM_4GB
config RPI4B_RAM_1GB
bool "1GB RAM"
---help---
Support for the 1GB variant of the Raspberry Pi 4B.
config RPI4B_RAM_2GB
bool "2GB RAM"
---help---
Support for the 2GB variant of the Raspberry Pi 4B.
config RPI4B_RAM_4GB
bool "4GB RAM"
---help---
Support for the 4GB variant of the Raspberry Pi 4B.
config RPI4B_RAM_8GB
bool "8GB RAM"
---help---
Support for the 8GB variant of the Raspberry Pi 4B.
endchoice # Raspberry Pi 4B RAM size
config RPI4B_DEBUG_BOOT
bool "Raspberry Pi 4B bootloader debug output"
default n
---help---
Enables the debug output of the Raspberry Pi 4B bootloader.
endif # ARCH_BOARD_RASPBERRYPI_4B
@@ -0,0 +1,61 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
CONFIG_ARCH="arm64"
CONFIG_ARCH_ARM64=y
CONFIG_ARCH_BOARD="raspberrypi-4b"
CONFIG_ARCH_BOARD_RASPBERRYPI_4B=y
CONFIG_ARCH_CHIP="bcm2711"
CONFIG_ARCH_CHIP_BCM2711=y
CONFIG_ARCH_EARLY_PRINT=y
CONFIG_ARCH_INTERRUPTSTACK=4096
CONFIG_BUILTIN=y
CONFIG_DEBUG_ASSERTIONS=y
CONFIG_DEBUG_FEATURES=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SCHED=y
CONFIG_DEBUG_SCHED_ERROR=y
CONFIG_DEBUG_SCHED_WARN=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEFAULT_TASK_STACKSIZE=8192
CONFIG_DEV_ZERO=y
CONFIG_EXAMPLES_HELLO=y
CONFIG_EXAMPLES_LEDS=y
CONFIG_EXPERIMENTAL=y
CONFIG_FS_PROCFS=y
CONFIG_FS_ROMFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_IDLETHREAD_STACKSIZE=8192
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_PTHREAD_STACK_MIN=8192
CONFIG_RAMLOG=y
CONFIG_RAM_SIZE=4227858432
CONFIG_RAM_START=0x00000000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SPINLOCK=y
CONFIG_STACK_COLORATION=y
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2022
CONFIG_SYMTAB_ORDEREDBYNAME=y
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_SYSTEM=y
CONFIG_SYSTEM_TIME64=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_USEC_PER_TICK=1000
CONFIG_USERLED=y
@@ -0,0 +1,42 @@
/****************************************************************************
* boards/arm64/bcm2711/raspberrypi-4b/include/board.h
*
* Author: Matteo Golin <matteo.golin@gmail.com>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM64_BCM2711_RPI4B_INCLUDE_BOARD_H
#define __BOARDS_ARM64_BCM2711_RPI4B_INCLUDE_BOARD_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* TODO: define all the GPIO pins properly */
#define BOARD_NGPIOOUT 1
#define BOARD_NGPIOIN 1
#define BOARD_NGPIOINT 0
#endif /* __BOARDS_ARM64_BCM2711_RPI4B_INCLUDE_BOARD_H */
@@ -0,0 +1,49 @@
############################################################################
# boards/arm64/bcm2711/raspberrypi-4b/scripts/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/.config
include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/tools/bcm2711/Config.mk
include $(TOPDIR)/arch/arm64/src/Toolchain.defs
LDSCRIPT = dramboot.ld
ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
AFLAGS := $(CFLAGS) -D__ASSEMBLY__
# NXFLAT module definitions
NXFLATLDFLAGS1 = -r -d -warn-common
NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)$(DELIM)binfmt$(DELIM)libnxflat$(DELIM)gnu-nxflat-pcrel.ld -no-check-sections
LDNXFLATFLAGS = -e main -s 2048
# ELF module definitions
CELFFLAGS = $(CFLAGS) -mlong-calls # --target1-abs
CXXELFFLAGS = $(CXXFLAGS) -mlong-calls # --target1-abs
LDELFFLAGS = -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)/binfmt/libelf/gnu-elf.ld)
@@ -0,0 +1,129 @@
/****************************************************************************
* boards/arm64/bcm2711/raspberrypi-4b/scripts/dramboot.ld
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
OUTPUT_ARCH(aarch64) /* Architecture to use */
ENTRY(__start) /* Entry point for the program */
PHDRS
{
text PT_LOAD ;
}
SECTIONS
{
. = 0x480000; /* Kernel load address for aarch64 */
_start = .;
.text : {
_stext = .; /* Text section */
*(.start .start.*) /* Place __start here */
*(.text)
*(.text.cold)
*(.text.unlikely)
*(.fixup)
*(.gnu.warning)
} :text = 0x9090
. = ALIGN(4096);
.init_section : {
_sinit = ABSOLUTE(.);
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP(*(.init_array .ctors))
_einit = ABSOLUTE(.);
}
. = ALIGN(4096);
.vector : {
_vector_start = .;
KEEP(*(.exc_vector_table))
KEEP(*(".exc_vector_table.*"))
KEEP(*(.vectors))
_vector_end = .;
} :text
. = ALIGN(4096);
_etext = .; /* End_1 of .text */
_sztext = _etext - _stext;
. = ALIGN(4096);
.rodata : {
_srodata = .; /* Read-only data */
*(.rodata)
*(.rodata.*)
*(.data.rel.ro)
*(.data.rel.ro.*)
} :text
. = ALIGN(4096);
_erodata = .; /* End of read-only data */
_szrodata = _erodata - _srodata;
_eronly = .; /* End of read-only data */
. = ALIGN(4096);
.data : { /* Data */
_sdata = .;
*(.data.page_aligned)
*(.data)
. = ALIGN(8);
*(.data.rel)
*(.data.rel.*)
CONSTRUCTORS
} :text
_edata = .; /* End+1 of .data */
.bss : { /* BSS */
. = ALIGN(8);
_sbss = .;
*(.bss)
. = ALIGN(8);
} :text
. = ALIGN(4096);
_ebss = .;
_szbss = _ebss - _sbss;
.initstack : { /* INIT STACK */
_s_initstack = .;
*(.initstack)
. = ALIGN(16);
} :text
. = ALIGN(4096);
_e_initstack = . ;
g_idle_topstack = . ;
_szdata = _e_initstack - _sdata;
/* Sections to be discarded */
/DISCARD/ : {
*(.exit.text)
*(.exit.data)
*(.exitcall.exit)
*(.eh_frame)
}
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
}
@@ -0,0 +1,41 @@
############################################################################
# boards/arm64/bcm2711/raspberrypi-4b/src/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/Make.defs
CSRCS += rpi4b_boardinitialize.c rpi4b_bringup.c
ifeq ($(CONFIG_BOARDCTL),y)
CSRCS += rpi4b_appinit.c
endif
ifeq ($(CONFIG_DEV_GPIO),y)
CSRCS += rpi4b_gpio.c
endif
ifeq ($(CONFIG_BCM2711_I2C_DRIVER),y)
CSRCS += bcm2711_i2cdev.c
endif
include $(TOPDIR)/boards/Board.mk
.PHONY: distclean
distclean::
$(call DELFILE, ${TOPDIR}${DELIM}config.txt)
@@ -0,0 +1,75 @@
/****************************************************************************
* boards/arm64/bcm2711/raspberrypi-4b/src/bcm2711_i2cdev.c
*
* Author: Matteo Golin <matteo.golin@gmail.com>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include <errno.h>
#include <stdio.h>
#include "bcm2711_i2c.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_i2cdev_initialize
*
* Description:
* Initialize and register the I2C character driver for the specified I2C
* port/bus number.
* NOTE: Driver will be registered at /dev/i2c[`port`]
*
* Input parameters:
* port - The I2C bus number/port number to register the driver for.
*
****************************************************************************/
int bcm2711_i2cdev_initialize(int port)
{
int ret;
struct i2c_master_s *i2c;
i2cinfo("Initializing /dev/i2c%d..\n", port);
/* Initialize I2C device */
i2c = bcm2711_i2cbus_initialize(port);
if (!i2c)
{
i2cerr("ERROR: Failed to initialize I2C bus %d.\n", port);
return -ENODEV;
}
ret = i2c_register(i2c, port);
if (ret < 0)
{
i2cerr("ERROR: Failed to register /dev/i2c%d: %d\n", port, ret);
}
return ret;
}
@@ -0,0 +1,43 @@
/****************************************************************************
* boards/arm64/bcm2711/raspberrypi-4b/src/bcm2711_i2cdev.h
*
* Author: Matteo Golin <matteo.golin@gmail.com>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM64_BCM2711_RASPBERRYPI_4B_INCLUDE_BCM2711_I2CDEV_H
#define __BOARDS_ARM64_BCM2711_RASPBERRYPI_4B_INCLUDE_BCM2711_I2CDEV_H
/****************************************************************************
* Name: board_i2cdev_initialize
*
* Description:
* Initialize and register the I2C character driver for the specified I2C
* port/bus number.
* NOTE: Driver will be registered at /dev/i2c[`port`]
*
* Input parameters:
* port - The I2C bus number/port number to register the driver for.
*
****************************************************************************/
#if defined(CONFIG_BCM2711_I2C_DRIVER)
int bcm2711_i2cdev_initialize(int port);
#endif /* defined(BCM2711_I2C_DRIVER) */
#endif /* __BOARDS_ARM64_BCM2711_RASPBERRYPI_4B_INCLUDE_BCM2711_I2CDEV_H */
@@ -0,0 +1,52 @@
/****************************************************************************
* boards/arm64/bcm2711/raspberrypi-4b/src/rpi4b.h
*
* Author: Matteo Golin
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_ARM64_BCM2711_RASPBERRYPI_4B_SRC_RPI4B_H
#define __BOARDS_ARM64_BCM2711_RASPBERRYPI_4B_SRC_RPI4B_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Public Functions Definitions
****************************************************************************/
/****************************************************************************
* Name: rpi4b_bringup
*
* Description:
* Bring up board features
*
****************************************************************************/
#if defined(CONFIG_BOARDCTL) || defined(CONFIG_BOARD_LATE_INITIALIZE)
int rpi4b_bringup(void);
#endif
#if defined(CONFIG_DEV_GPIO)
int bcm2711_dev_gpio_init(void);
#endif /* defined(CONFIG_DEV_GPIO) */
#endif /* __BOARDS_ARM64_BCM2711_RASPBERRYPI_4B_SRC_RPI4B_H */
@@ -0,0 +1,89 @@
/****************************************************************************
* boards/arm64/bcm2711/raspberrypi-4b/src/rpi4b_appinit.c
*
* Author: Matteo Golin <matteo.golin@gmail.com>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include "rpi4b.h"
#include <debug.h>
#include <nuttx/board.h>
#include <nuttx/config.h>
#include <nuttx/fs/fs.h>
#include <sys/types.h>
#ifdef CONFIG_BOARDCTL
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_app_initialize
*
* Description:
* Perform application specific initialization. This function is never
* called directly from application code, but only indirectly via the
* (non-standard) boardctl() interface using the command BOARDIOC_INIT.
*
* Input Parameters:
* arg - The boardctl() argument is passed to the board_app_initialize()
* implementation without modification. The argument has no
* meaning to NuttX; the meaning of the argument is a contract
* between the board-specific initialization logic and the
* matching application logic. The value could be such things as a
* mode enumeration value, a set of DIP switch switch settings, a
* pointer to configuration data read from a file or serial FLASH,
* or whatever you would like to do with it. Every implementation
* should accept zero/NULL as a default configuration.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure to indicate the nature of the failure.
*
****************************************************************************/
int board_app_initialize(uintptr_t arg)
{
UNUSED(arg);
int ret = OK;
#ifdef CONFIG_FS_PROCFS
/* Mount the proc file system */
ret = nx_mount(NULL, "/proc", "procfs", 0, NULL);
if (ret < 0)
{
_err("ERROR: Failed to mount procfs at /proc: %d\n", ret);
}
#endif
#ifndef CONFIG_BOARD_LATE_INITIALIZE
/* Perform board initialization */
ret = rpi4b_bringup();
#endif
return ret;
}
#endif /* CONFIG_BOARDCTL */
@@ -0,0 +1,108 @@
/****************************************************************************
* boards/arm64/bcm2711/raspberrypi-4b/src/rpi4b_boardinitialize.c
*
* Author: Matteo Golin
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include "rpi4b.h"
#include <nuttx/board.h>
#include <nuttx/config.h>
#include <stdint.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: bcm2711_memory_initialize
*
* Description:
* All BCM2711 architectures must provide the following entry point. This
* entry point is called early in the initialization before memory has
* been configured. This board-specific function is responsible for
* configuring any on-board memories.
*
* Logic in a64_memory_initialize must be careful to avoid using any
* global variables because those will be uninitialized at the time this
* function is called.
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
****************************************************************************/
void bcm2711_memory_initialize(void)
{
/* TODO */
}
/****************************************************************************
* Name: bcm2711_board_initialize
*
* Description:
* All BCM2711 architectures must provide the following entry point. This
* entry point is called in the initialization phase -- after
* bcm2711_memory_initialize and after all memory has been configured and
* mapped but before any devices have been initialized.
*
* Input Parameters:
* None
*
* Returned Value:
* None
*
****************************************************************************/
void bcm2711_board_initialize(void)
{
#ifdef CONFIG_ARCH_LEDS
/* Configure on-board LEDs if LED support has been selected. */
board_autoled_initialize();
#endif
}
/****************************************************************************
* Name: board_late_initialize
*
* Description:
* If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional
* initialization call will be performed in the boot-up sequence to a
* function called board_late_initialize(). board_late_initialize() will be
* called immediately after up_initialize() is called and just before the
* initial application is started. This additional initialization phase
* may be used, for example, to initialize board-specific device drivers.
*
****************************************************************************/
#ifdef CONFIG_BOARD_LATE_INITIALIZE
void board_late_initialize(void)
{
/* Perform board initialization */
rpi4b_bringup();
}
#endif /* CONFIG_BOARD_LATE_INITIALIZE */
@@ -0,0 +1,123 @@
/****************************************************************************
* boards/arm64/bcm2711/raspberrypi-4b/src/rpi4b_bringup.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include "rpi4b.h"
#include <nuttx/config.h>
#include <sys/types.h>
#include <syslog.h>
#if defined(CONFIG_BCM2711_I2C_DRIVER)
#include "bcm2711_i2cdev.h"
#endif /* defined(CONFIG_BCM2711_I2C) */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: rpi4b_bringup
*
* Description:
* Bring up board features
*
****************************************************************************/
int rpi4b_bringup(void)
{
int ret = OK;
/* Initialize GPIO driver. */
#if defined(CONFIG_DEV_GPIO)
ret = bcm2711_dev_gpio_init();
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize GPIO driver: %d\n.", ret);
}
#endif // defined(CONFIG_DEV_GPIO)
/* Initialize I2C interfaces. */
#if defined(CONFIG_BCM2711_I2C)
#if defined(CONFIG_BCM2711_I2C0)
ret = bcm2711_i2cdev_initialize(0);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2C0: %d\n", ret);
}
#endif /* defined(CONFIG_BCM2711_I2C0) */
#if defined(CONFIG_BCM2711_I2C1)
ret = bcm2711_i2cdev_initialize(1);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2C1: %d\n", ret);
}
#endif /* defined(CONFIG_BCM2711_I2C1) */
#if defined(CONFIG_BCM2711_I2C2)
ret = bcm2711_i2cdev_initialize(2);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2C2: %d\n", ret);
}
#endif /* defined(CONFIG_BCM2711_I2C2) */
#if defined(CONFIG_BCM2711_I2C3)
ret = bcm2711_i2cdev_initialize(3);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2C3: %d\n", ret);
}
#endif /* defined(CONFIG_BCM2711_I2C3) */
#if defined(CONFIG_BCM2711_I2C4)
ret = bcm2711_i2cdev_initialize(4);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2C4: %d\n", ret);
}
#endif /* defined(CONFIG_BCM2711_I2C4) */
#if defined(CONFIG_BCM2711_I2C5)
ret = bcm2711_i2cdev_initialize(5);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2C5: %d\n", ret);
}
#endif /* defined(CONFIG_BCM2711_I2C5) */
#if defined(CONFIG_BCM2711_I2C6)
ret = bcm2711_i2cdev_initialize(6);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2C6: %d\n", ret);
}
#endif /* defined(CONFIG_BCM2711_I2C6) */
#endif /* defined(CONFIG_BCM2711_I2C) */
return ret;
}
@@ -0,0 +1,340 @@
/****************************************************************************
* boards/arm64/bcm2711/raspberrypi-4b/src/rpi4b_gpio.c
*
* Author: Matteo Golin <matteo.golin@gmail.com>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <arch/irq.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/irq.h>
#include <sys/types.h>
#include <syslog.h>
#include <nuttx/ioexpander/gpio.h>
#include <arch/board/board.h>
#include "bcm2711_gpio.h"
#include "chip.h"
#if defined(CONFIG_DEV_GPIO) && !defined(CONFIG_GPIO_LOWER_HALF)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Input pins */
#define GPIO_IN1 16
/* Output pins */
#define GPIO_OUT1 26
/* Interrupt pins */
/* TODO: why can't you select interrupt event type??? */
/****************************************************************************
* Private Types
****************************************************************************/
/* GPIO device on the BCM2711 */
struct bcm2711_gpio_dev_s
{
struct gpio_dev_s gpio; /* Underlying GPIO device */
uint8_t id; /* The index of the pin in its list. */
};
/* GPIO device with interrupt capabilities on the BCM2711 */
struct bcm2711_gpioint_dev_s
{
struct bcm2711_gpio_dev_s bcm2711_gpio; /* BCM2711 GPIO device */
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
#if BOARD_NGPIOOUT > 0
static int gpout_read(struct gpio_dev_s *dev, bool *value);
static int gpout_write(struct gpio_dev_s *dev, bool value);
#endif
#if BOARD_NGPIOIN > 0
static int gpin_read(struct gpio_dev_s *dev, bool *value);
#endif
#if BOARD_NGPIOINT > 0
static int gpint_read(struct gpio_dev_s *dev, bool *value);
static int gpint_attach(struct gpio_dev_s *dev, pin_interrupt_t callback);
static int gpint_enable(struct gpio_dev_s *dev, bool enable);
#endif
/****************************************************************************
* Private Data
****************************************************************************/
#if BOARD_NGPIOOUT > 0
/* GPIO operations for output pins. */
static const struct gpio_operations_s gpout_ops =
{
.go_read = gpout_read,
.go_write = gpout_write,
.go_attach = NULL,
.go_enable = NULL,
};
/* This array maps the GPIO pins used as OUTPUT */
static const uint32_t g_gpiooutputs[BOARD_NGPIOOUT] =
{
GPIO_OUT1,
};
/* GPIO output pin devices */
static struct bcm2711_gpio_dev_s g_gpout[BOARD_NGPIOOUT];
#endif /* BOARD_NGPIOOUT > 0 */
#if BOARD_NGPIOIN > 0
/* GPIO operations for input pins. */
static const struct gpio_operations_s gpin_ops =
{
.go_read = gpin_read,
.go_write = NULL,
.go_attach = NULL,
.go_enable = NULL,
};
/* This array maps the GPIO pins used as INTERRUPT INPUTS */
static const uint32_t g_gpioinputs[BOARD_NGPIOIN] =
{
GPIO_IN1,
};
/* GPIO input pin devices */
static struct bcm2711_gpio_dev_s g_gpin[BOARD_NGPIOIN];
#endif /* BOARD_NGPIOIN > 0 */
#if BOARD_NGPIOINT > 0
#warn "Missing functionality for interrupt GPIO pins."
/* GPIO operations for interrupt pins. */
static const struct gpio_operations_s gpint_ops =
{
.go_read = gpint_read,
.go_write = NULL,
.go_attach = gpint_attach,
.go_enable = gpint_enable,
};
/* This array maps the GPIO pins used as INTERRUPT INPUTS */
static const uint32_t g_gpiointinputs[BOARD_NGPIOINT] =
{
GPIO_IRQPIN1,
};
/* GPIO interrupt pin devices */
static struct bcm2711_gpioint_dev_s g_gpint[BOARD_NGPIOINT];
#endif /* BOARD_NGPIOINT > 0 */
/****************************************************************************
* Private Functions
****************************************************************************/
#if BOARD_NGPIOOUT > 0
/****************************************************************************
* Name: gpout_read
*
* Description:
* Read the output pin's current status (0 or 1).
*
* Input parameters:
* dev - The GPIO device structure.
* value - A pointer to the location to store the pin status.
****************************************************************************/
static int gpout_read(struct gpio_dev_s *dev, bool *value)
{
struct bcm2711_gpio_dev_s *bcm2711gpio =
(struct bcm2711_gpio_dev_s *)(dev);
DEBUGASSERT(bcm2711gpio != NULL);
DEBUGASSERT(value != NULL);
DEBUGASSERT(bcm2711gpio->id < BOARD_NGPIOOUT);
*value = bcm2711_gpio_pin_get(g_gpiooutputs[bcm2711gpio->id]);
return 0;
}
/****************************************************************************
* Name: gpout_write
*
* Description:
* Write a value to a GPIO output pin.
*
* Input parameters:
* dev - The GPIO device struct of the pin to write to.
* value - The value to write to the pin.
****************************************************************************/
static int gpout_write(struct gpio_dev_s *dev, bool value)
{
struct bcm2711_gpio_dev_s *bcm2711gpio =
(struct bcm2711_gpio_dev_s *)(dev);
DEBUGASSERT(bcm2711gpio != NULL);
DEBUGASSERT(bcm2711gpio->id < BOARD_NGPIOOUT);
gpioinfo("Writing %u to pin %u\n", value, g_gpiooutputs[bcm2711gpio->id]);
bcm2711_gpio_pin_set(g_gpiooutputs[bcm2711gpio->id], value);
return 0;
}
#endif /* BOARD_NGPIOOUT > 0 */
#if BOARD_NGPIOIN > 0
/****************************************************************************
* Name: gpin_read
*
* Description:
* Read the input pin's current status (0 or 1).
*
* Input parameters:
* dev - The GPIO device structure.
* value - A pointer to the location to store the pin status.
****************************************************************************/
static int gpin_read(struct gpio_dev_s *dev, bool *value)
{
struct bcm2711_gpio_dev_s *bcm2711gpio =
(struct bcm2711_gpio_dev_s *)(dev);
DEBUGASSERT(bcm2711gpio != NULL);
DEBUGASSERT(value != NULL);
DEBUGASSERT(bcm2711gpio->id < BOARD_NGPIOIN);
*value = bcm2711_gpio_pin_get(g_gpioinputs[bcm2711gpio->id]);
return 0;
}
#endif /* BOARD_NGPIOIN > 0 */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: bcm2711_dev_gpio_init
****************************************************************************/
int bcm2711_dev_gpio_init(void)
{
int i;
int ret = OK;
/* Register output pins. */
#if BOARD_NGPIOOUT > 0
for (i = 0; i < BOARD_NGPIOOUT; i++)
{
/* Setup and register the GPIO pin */
g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN;
g_gpout[i].gpio.gp_ops = &gpout_ops;
g_gpout[i].id = i;
ret = gpio_pin_register(&g_gpout[i].gpio, g_gpiooutputs[i]);
if (ret < 0)
{
gpioerr("Failed to register output pin %d (BCM2711 #%u): %d\n", i,
g_gpiooutputs[i], ret);
return ret;
}
/* Configure the pins that will be used as output.
* They will start low and have no pull-up or pull-down resistors.
*/
bcm2711_gpio_set_pulls(g_gpiooutputs[i], false, false);
bcm2711_gpio_set_func(g_gpiooutputs[i], BCM_GPIO_OUTPUT);
bcm2711_gpio_pin_set(g_gpiooutputs[i], false);
}
#endif
/* Register input pins. */
#if BOARD_NGPIOIN > 0
for (i = 0; i < BOARD_NGPIOIN; i++)
{
/* Setup and register the GPIO pin */
g_gpin[i].gpio.gp_pintype = GPIO_INPUT_PIN;
g_gpin[i].gpio.gp_ops = &gpin_ops;
g_gpin[i].id = i;
ret = gpio_pin_register(&g_gpin[i].gpio, g_gpioinputs[i]);
if (ret < 0)
{
gpioerr("Failed to register input pin %d (BCM2711 #%u): %d\n", i,
g_gpioinputs[i], ret);
return ret;
}
/* Configure the pins that will be used as INPUT.
* They will have pull-up resistors.
*/
bcm2711_gpio_set_func(g_gpioinputs[i], BCM_GPIO_INPUT);
bcm2711_gpio_set_pulls(g_gpioinputs[i], true, false);
/* TODO: pull-up or pull-down should be configurable per pin */
}
#endif
return OK;
}
#endif /* defined(CONFIG_DEV_GPIO) && !defined(CONFIG_GPIO_LOWER_HALF) */