Skip to content

arch/arm/rtl8721dx: add shared Ameba GPIO driver.#19484

Merged
jerpelea merged 1 commit into
apache:masterfrom
Ameba-AIoT:gpio-upstream
Jul 21, 2026
Merged

arch/arm/rtl8721dx: add shared Ameba GPIO driver.#19484
jerpelea merged 1 commit into
apache:masterfrom
Ameba-AIoT:gpio-upstream

Conversation

@raulcxw

@raulcxw raulcxw commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Add a board-agnostic GPIO driver for Realtek Ameba chips, exposing pins through
the NuttX GPIO (ioexpander) upper half at /dev/gpioN.

  • arch/arm/src/common/ameba/ameba_gpio.{c,h} — the shared driver, sitting
    directly on the SDK fwlib register layer. The fwlib GPIO API it calls
    resolves at link time from the on-chip ROM symbol table, except
    GPIO_INTStatusGet/ClearEdge which are not in ROM and are compiled in from
    the fwlib ram_common/ameba_gpio.c. Pin interrupts are dispatched
    NuttX-natively: the port's NVIC vector is owned by NuttX via irq_attach, and
    the ISR reads/clears status through the fwlib helpers.
  • The driver keeps nothing IC-specific: the port count, per-port NVIC vectors
    and RCC gate bits come from a per-chip <ameba_gpio_chip.h> resolved on the
    include path, so bringing up a new Ameba chip only adds that header, not a
    change to the shared driver.
  • common/ameba/Kconfig — a shared "Ameba Peripheral Support" menu with the
    AMEBA_GPIO option, sourced by each Ameba chip's Kconfig so it is reused
    across ICs (RTL8721Dx, RTL8720F, ...).
  • arch/arm/src/rtl8721dx — provide ameba_gpio_chip.h, wire the driver
    into both the make and CMake builds, and compile the fwlib register layer
    (ameba_gpio.c) into libameba_fwlib for the RTL8721Dx.
  • boards/arm/rtl8721dx/pke8721daf — board pin table (rtl8721dx_gpio.c),
    bring-up registration, and a standalone gpio defconfig.
  • tools/nxstyle — whitelist the Ameba GPIO_ SDK ROM symbol prefix
    (alongside the existing FLASH_/IPC_/... Ameba prefixes) so the vendor GPIO
    API's mixed-case identifiers do not trip nxstyle.
  • Documentation: the gpio configuration and pin encoding.

Impact

Testing

Fork CI on top of current apache/master, all green — the pke8721daf:gpio
config builds under both build systems, and the existing nsh configs for both
boards still build:

pke8721daf:gpio — make and CMake
# make
$ ./tools/configure.sh pke8721daf:gpio && make
-- Found assembler: ~/rtk-toolchain/asdk-10.3.1-4602/linux/newlib/bin/arm-none-eabi-gcc
PACK: wrote nuttx.bin
-rw-r--r-- 1 root root  517728 nuttx.bin

# CMake
$ . tools/ameba/env.sh pke8721daf
$ cmake -B build -DBOARD_CONFIG=pke8721daf:gpio -GNinja && cmake --build build
[1172/1174] Linking C executable nuttx
PACK: wrote build/nuttx.bin
-rw-r--r-- 1 root root  527456 build/nuttx.bin

Hardware-verified on the pke8721daf (RTL8721Dx) with the make build: the driver
was exercised on target through /dev/gpio* (input read, output write and pin
interrupts). The CMake build of the same config is CI-verified (above).

@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Arch: arm Issues related to ARM (32-bit) architecture Size: L The size of the change in this PR is large Board: arm labels Jul 20, 2026
@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

Comment thread arch/arm/src/common/ameba/ameba_gpio.c Outdated
Comment thread arch/arm/src/common/ameba/ameba_gpio.c Outdated
Comment thread arch/arm/src/common/ameba/ameba_gpio.c Outdated
Comment thread boards/arm/rtl8721dx/pke8721daf/src/rtl8721dx_gpio.c Outdated
acassis
acassis previously approved these changes Jul 20, 2026
Add a board-agnostic GPIO driver for Realtek Ameba chips, exposing pins
through the NuttX GPIO (ioexpander) upper half at /dev/gpioN.

- arch/arm/src/common/ameba/ameba_gpio.{c,h}: the shared driver, sitting
  directly on the SDK fwlib register layer.  The fwlib GPIO API it calls
  resolves at link time from the on-chip ROM symbol table, except
  GPIO_INTStatusGet/ClearEdge which are not in ROM and are compiled in
  from fwlib ram_common/ameba_gpio.c (that object also carries GPIO_Init,
  harmlessly overriding the equivalent ROM copy).  Pin interrupts are
  dispatched NuttX-natively: the port's NVIC vector is owned by NuttX
  via irq_attach, and the ISR reads and clears status through the fwlib
  GPIO_INTStatus* helpers.
- The driver keeps nothing IC-specific: the port count, the per-port
  NVIC vectors and the RCC gate bits come from a per-chip
  <ameba_gpio_chip.h> resolved on the include path, so bringing up a new
  Ameba chip only adds that header, not a change to the shared driver.
- arch/arm/src/common/ameba/Kconfig: a shared "Ameba Peripheral Support"
  menu with the AMEBA_GPIO option, sourced by each Ameba chip's Kconfig so
  it is reused across ICs (RTL8721Dx, RTL8720F, ...).
- arch/arm/src/rtl8721dx: provide ameba_gpio_chip.h, wire the driver into
  both the Make/Kconfig and CMake builds, and compile the fwlib
  ameba_gpio.c register layer into libameba_fwlib for the RTL8721Dx.
- boards/arm/rtl8721dx/pke8721daf: board pin table (rtl8721dx_gpio.c),
  bring-up registration, and a standalone gpio defconfig.
- Documentation: describe the gpio configuration and pin encoding.

tools/nxstyle: whitelist the Ameba "GPIO_" SDK ROM symbol prefix (alongside
the existing FLASH_/IPC_/... Ameba prefixes) so the vendor GPIO API's mixed-case
identifiers do not trip nxstyle, matching how the other Ameba SDK prefixes are
handled.

Assisted-by: Claude Code:claude-opus-4-8
Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn>
@github-actions github-actions Bot added Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. and removed Size: L The size of the change in this PR is large labels Jul 21, 2026
@jerpelea
jerpelea merged commit e2ff8be into apache:master Jul 21, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Area: Documentation Improvements or additions to documentation Board: arm Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants