Skip to content

anyka: pad mux and GPIO for the AK3918AV100 family (AV100, AV100X, EV300L) - #291

Merged
openipc-ai merged 2 commits into
masterfrom
anyka/padmux
Nov 22, 2026
Merged

openipc-ai merged 2 commits into
masterfrom
anyka/padmux

Conversation

@openipc-ai

@openipc-ai openipc-ai commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

ipctool had no Anyka pad-mux backend and no Anyka gpio get/set/scan, so on Anyka cameras gpio mux and gpio scan had nothing to say.

On OpenIPC/majestic#380, an owner hunting the IR-cut pins of an AK3918EV300L through sysfs GPIOs hung the camera on pads 0–11 and 71. Those are the Ethernet MAC's RMII lines and the PHY reset.

Change

The register layout comes from the vendor kernel (OpenIPC/linux anyka-ak3918av100):

  • Each pad's function is a three-bit field in the SYSCTRL share-pin registers at 0x08000178 + 4 * reg, as ak_3918av100_pinctrl.c's pin_set_share() writes it.
  • What each value selects comes from the device-tree binding header's XGPIO_nnn_FUNC_name.

tools/gen_anyka_padmux.py builds src/hal/anyka_padmux.h from ak_sharepin[] and the binding header.

  • It evaluates the driver's #ifdef CONFIG_MACH_* per machine: AK3918AV100 has 93 pads, AK3918EV300L 59.
  • It refuses rather than guesses:
    • a selector past the driver's func_mux_max, or wider than the field;
    • a GPIO function that isn't GPIO<pad> at the driver's gpio_func_no;
    • duplicate selectors;
    • functions for a pad the driver lacks;
    • preprocessor lines it can't evaluate.

src/hal/anyka_padmux.c is the backend.

  • A pad is addressed by its GPIO number.
  • The GPIO function is looked up by name, because it isn't always selector 0: it is selector 3 on pad 22 (CSI0_SCLK) and 1 on pad 98.
  • GPIO37 and GPIO50 have no field, so their rows have no address and writing GPIO to them is a no-op. GPIO80/81 belong to the power-management block and are left out.
  • Only the selector is written.
  • A pad carrying SPI0_* (the NOR flash), RMII_* or OPCLK* (the network) is in_use(), so moving it needs --force.

src/hal/anyka_gpio.c drives the GPIO block at 0x20170000: DIR, OUT and IN at +0x00, +0x14 and +0x28, as the kernel's ak_gpio_get/ak_gpio_set do.

  • gpio get, gpio set, gpio scan and the IR-cut guess use it on AV100 and EV300L.
  • They only touch pads muxed to GPIO. gpio get and gpio set refuse any other pad.
  • anyka_gpio_owner() names the pads the kernel holds. It reads the debugfs pinctrl mux owners, the GPIOs handed to drivers (a user's sysfs export doesn't count), and the *-gpio(s) properties of enabled device-tree nodes.
    • Those pads are in_use(), and gpio set refuses them without --force.
    • gpio scan shows "held by " for them, and the IR-cut guess skips them.
    • On #380's EV300L this covers the PHY reset on GPIO71, the MAC's GPIO23, the SD card's pins and the sensor pins.
  • A pad whose selector the table has no name for isn't moved without --force. This applies to Fullhan too.

Also:

  • The other Anyka generations now get "no table" instead of falling through to the HiSilicon tables.
  • The in-use refusal message now says "its boot flash or network".
  • CMake family anyka, dropped when the Anyka HAL is not selected; padmux_names regenerated; the CI pad-mux sweep now builds anyka on its own.
  • docs/padmux.md has the Anyka section and the regeneration recipe.

Tests

  • reginfo_test:
    • AV100 and EV300L are in the table integrity sweep.
    • test_anyka() uses that EV300L's kernel pinmux-pins values: PWM0 on pad 16 at selector 2, CSI0_SCLK on 22 with GPIO at 3, OPCLK1/RMII on pads 0 and 1 refused unless forced, GPIO37's no-op, and a pad the EV300L doesn't have.
  • The CI native test set: all pass locally.
  • Pad-mux sweep: IPCHW_PADMUX=none, v4, anyka, v4;anyka and all all build and pass.
  • Libraries: an Anyka-only ipchw builds, and so does the trimmed configuration. gen_padmux_names.py --check and gen_anyka_padmux.py --verify pass.
  • qemu-bench ak3918ev300l (OpenIPC kernel, static arm32 build):
    • gpio mux reads OPCLK1 on 0, RMII_RXER on 1, PWM0 on 16, CSI0_SCLK on 22 and SPI0_WP on 42. That matches the kernel's /sys/kernel/debug/pinctrl/*/pinmux-pins.
    • gpio set 25 1 followed by gpio get 25 reads 1.
    • gpio set 0 1, and moving pad 1 to GPIO without --force, are both refused.
    • gpio scan lists only GPIO-muxed pads.

Not yet run on a camera.

…300L)

ipctool had no Anyka pad-mux backend and no Anyka `gpio get/set/scan`, so
`gpio mux` and `gpio scan` on these cameras had nothing to say. An owner
hunting the IR-cut pins on an AK3918EV300L with sysfs GPIOs hung the
camera on pads 0..11 and 71: those are the Ethernet MAC's RMII lines and
the PHY reset (OpenIPC/majestic#380).

The layout is the vendor kernel's: a three-bit field per pad in the
SYSCTRL share-pin registers at 0x08000178 + 4 * reg
(ak_3918av100_pinctrl.c, pin_set_share()), and the function each value
selects is the device-tree binding header's XGPIO_nnn_FUNC_name.

- tools/gen_anyka_padmux.py reads ak_sharepin[] and the binding header
  into src/hal/anyka_padmux.h, one table per machine: it evaluates the
  driver's #ifdef CONFIG_MACH_* for AK3918AV100 (93 pads) and
  AK3918EV300L (59 pads). It refuses a selector past the driver's
  func_mux_max or wider than the field, a pad whose GPIO function is not
  GPIO<pad> at the driver's gpio_func_no, duplicate selectors, functions
  for a pad the driver lacks, and preprocessor lines it cannot evaluate.
  From OpenIPC/linux anyka-ak3918av100@10a8a32b.
- src/hal/anyka_padmux.c is the backend. A pad is its GPIO number. GPIO is
  found by name, since it is selector 3 on pad 22 and 1 on pad 98.
  GPIO37/GPIO50 have no field and their rows no address; GPIO80/81 are
  the PMU's and are left out. Only the selector is written. A pad on
  SPI0_* (the NOR), RMII_* or OPCLK* (the network) is in_use(), so moving
  it takes --force.
- src/hal/anyka_gpio.c drives the GPIO block at 0x20170000 (DIR, OUT, IN
  at +0x00/+0x14/+0x28), as ak_gpio_get/ak_gpio_set do: an output reads
  OUT, an input IN, and a write sets the level before the direction.
  `gpio get/set/scan` and the IR-cut guess use it on AV100 and EV300L, for
  pads muxed to GPIO only; `gpio set` on a pad that is not refuses.
- The other Anyka generations dispatch to the backend and answer
  NO_TABLE rather than falling through to the HiSilicon tables.
- The in-use refusal now says "its boot flash or network".
- CMake family "anyka", dropped when the Anyka HAL is not selected;
  padmux_names regenerated; the CI pad-mux sweep builds "anyka" alone.
- reginfo_test: AV100 and EV300L in the integrity sweep, and test_anyka()
  with the values from that EV300L's pinmux-pins: PWM0 on pad 16 at 2,
  CSI0_SCLK on 22 with GPIO at 3, OPCLK1/RMII on 0 and 1 refused,
  GPIO37's no-op, a pad the EV300L lacks.
- docs/padmux.md: the Anyka section and the regenerate recipe.

On qemu-bench ak3918ev300l (OpenIPC kernel, static arm32 build): `gpio
mux` reads OPCLK1 on 0, RMII_RXER on 1, PWM0 on 16, CSI0_SCLK on 22 and
SPI0_WP on 42, matching the kernel's pinmux-pins; `gpio set 25 1` then
`gpio get 25` reads 1; `gpio set 0 1` and moving pad 1 to GPIO are
refused; `gpio scan` lists only GPIO-muxed pads. Not yet run on a camera.
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add Anyka AK3918AV100-family pad mux and GPIO support

✨ Enhancement 🐞 Bug fix 🧪 Tests 📝 Documentation ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Add machine-specific Anyka pad-mux tables and GPIO commands for AV100, AV100X, and EV300L.
• Refuse unsafe mux changes to boot-flash and network lines unless explicitly forced.
• Add table validation, tests, build coverage, and regeneration instructions.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: Anyka hardware I/O integration.
  • The changed dispatcher, generated tables, selector read-modify-write, and common pad-mux API form one bounded Anyka hardware-I/O feature.
  • The same capability reaches boot-flash, Ethernet, sensor, storage, and GPIO pin functions through the pad-mux register; these are consumers of one pad-routing behavior rather than independent functional scopes.
  • GPIO command dispatch, Anyka GPIO register access, pad-mux GPIO checks, ownership discovery, scanning, and dependent IR-cut candidate detection implement one bounded Anyka hardware-I/O capability.
  • Their consumers are the same board GPIO lines and kernel-owned peripheral controls; they are separate operations from pad-mux selector control but remain within the same integration scope.
Behavioral complexity 🟡 Medium 🧩 Multiple interactions

  • Before: existing vendors used their own pad tables and backend dispatch.
  • After: Anyka adds generated per-machine rows, chip-generation selection, GPIO-selector lookup where GPIO is not always selector 0, fixed GPIO-only pads, unknown-selector refusal, shared-register masking, and unsupported-generation behavior.
  • New correctness conditions are that each vendor row, selector, GPIO function, machine table, and shared-register bit range agree; that AV100 and EV300L omit different pads without accidentally accepting another package's pad; and that protected/unknown states are not overwritten unintentionally.
  • The read-modify-write itself is established infrastructure, but the newly introduced mapping and compatibility interactions are not routine reuse.
Potential damage 🟡 Medium 🩹 Temporary loss

  • A wrong selector can remove a peripheral function from its expected pins, including documented flash or network lines, causing the associated peripheral capability to stop working.
  • The register change is runtime state rather than persistent application data, so reboot or explicit remux can restore the original configuration; however, a peripheral driver may need restart/reinitialization, and a forced change can leave the system inaccessible until local recovery.
  • This supports temporary capability loss rather than a serious integrity or data-loss classification.
  • Revert or correct the command/code and reboot or explicitly restore the pad selector; restart affected peripheral drivers if they do not reinitialize automatically.
  • Recovery of an SSH session may require local access if the network pins were changed.
Sources

src/hal/anyka_padmux.c[216-224]

static bool ak_in_use(int pad, const padmux_io_t *io) {
    ipchw_padmux_t now;
    if (ak_get(pad, &now, io) != 1)
        return false;
    char who[64];
    return !strncmp(now.func_name, "SPI0_", 5) ||
           !strncmp(now.func_name, "RMII_", 5) ||
           !strncmp(now.func_name, "OPCLK", 5) ||
           anyka_gpio_owner(pad, who, sizeof who);
Assessed commit c9c1c72
Diagram

graph TD
  Sources["Vendor pin tables"] --> Generator["Table generator"] --> Tables["Anyka mux tables"] --> Mux["Pad-mux backend"] --> Hardware[("SoC registers")]
  Commands["GPIO commands"] --> Mux
  Commands --> Driver["Anyka GPIO driver"] --> Hardware
  Tables --> Driver
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use kernel GPIO and pinctrl interfaces
  • ➕ Lets kernel drivers arbitrate GPIO access where suitable.
  • ➕ Avoids direct userspace GPIO register writes.
  • ➖ Availability and capabilities vary across the targeted vendor kernels.
  • ➖ Does not provide a dependable replacement for the tool's mux inspection and controlled selector changes.

Recommendation: Keep the table-driven backend: it fits the existing pad-mux API and preserves explicit safeguards for flash and network pins. Kernel interfaces are worth preferring where available for ordinary GPIO use, but are not a complete substitute for this tool's cross-kernel mux functionality. Validate on a physical camera before relying on writes in production.

Files changed (16) +2843 / -288

Enhancement (10) +2676 / -283
anyka_gpio.cAccess AK3918AV100-family GPIO banks +74/-0

Access AK3918AV100-family GPIO banks

• Implements supported-pad checks and direction-aware level reads. Writes output levels before enabling output direction and exposes the controller's mapped window.

src/hal/anyka_gpio.c

anyka_gpio.hDeclare Anyka GPIO registers and operations +37/-0

Declare Anyka GPIO registers and operations

• Defines controller addresses, bank offsets, pad bounds, and the GPIO support, validity, window, read, and write interfaces.

src/hal/anyka_gpio.h

anyka_padmux.cImplement machine-specific Anyka pad-mux backend +252/-0

Implement machine-specific Anyka pad-mux backend

• Selects AV100 or EV300L tables and implements pad parsing, function lookup, selector reads, and selector-only writes. Treats GPIO-only pads as no-ops and requires force to move pads carrying SPI0, RMII, or OPCLK functions.

src/hal/anyka_padmux.c

anyka_padmux.hAdd generated AV100 and EV300L function tables +556/-0

Add generated AV100 and EV300L function tables

• Contains vendor-derived register, field, selector, and function-name rows for 93 AV100 pads and 59 EV300L pads, with source provenance.

src/hal/anyka_padmux.h

anyka_padmux_types.hDefine compact Anyka function rows +24/-0

Define compact Anyka function rows

• Introduces the generated tables' pad, register, shift, selector, and shared-name-offset representation.

src/hal/anyka_padmux_types.h

padmux.hDeclare the optional Anyka mux backend +3/-0

Declare the optional Anyka mux backend

• Exposes the backend operations when the Anyka pad-mux family is compiled in.

src/padmux.h

padmux_names.cAdd Anyka names to the shared string store +426/-93

Add Anyka names to the shared string store

• Regenerates conditionally compiled function strings for Anyka, reusing strings shared with existing families.

src/padmux_names.c

padmux_names.hAdd Anyka shared-name fields and offsets +852/-186

Add Anyka shared-name fields and offsets

• Regenerates conditional string fields and PMX offsets so the Anyka tables can reference function names without per-row pointers.

src/padmux_names.h

reginfo.cRoute GPIO commands through the Anyka controller +170/-4

Route GPIO commands through the Anyka controller

• Adds Anyka get, set, scan, and IR-cut handling restricted to table-backed pads and GPIO-muxed writes. Rejects unsupported Anyka GPIO dumps and clarifies that mux refusal protects boot flash or network lines.

src/reginfo.c

gen_anyka_padmux.pyGenerate and validate Anyka pad-mux tables +282/-0

Generate and validate Anyka pad-mux tables

• Parses machine-conditioned vendor share-pin rows and device-tree function definitions. Refuses inconsistent selectors, GPIO mappings, missing pads, and unsupported preprocessor conditions; supports checking generated output.

tools/gen_anyka_padmux.py

Bug fix (1) +15 / -0
padmux.cDispatch Anyka generations to their mux backend +15/-0

Dispatch Anyka generations to their mux backend

• Routes supported Anyka chips to the new backend. Routes other recognized Anyka generations there as well so they report no table rather than falling through to HiSilicon.

src/padmux.c

Documentation (1) +46 / -0
padmux.mdDocument Anyka pad numbering and regeneration +46/-0

Document Anyka pad numbering and regeneration

• Explains the machine-specific tables, GPIO register layout, fixed-function pads, safety refusal, and command behavior. Provides the vendor-source table regeneration recipe.

docs/padmux.md

Other (4) +106 / -5
pr-build-check.ymlInclude Anyka in the CI pad-mux build sweep +1/-1

Include Anyka in the CI pad-mux build sweep

• Adds an Anyka-only family build to the existing pad-mux configuration sweep.

.github/workflows/pr-build-check.yml

CMakeLists.txtWire optional Anyka mux and GPIO sources +14/-4

Wire optional Anyka mux and GPIO sources

• Registers the Anyka pad-mux family and backend, removes that family when the Anyka HAL is excluded, and includes GPIO sources for Anyka builds.

CMakeLists.txt

reginfo_test.cTest Anyka table integrity and mux safeguards +90/-0

Test Anyka table integrity and mux safeguards

• Adds both machines to the integrity sweep and exercises selector decoding, nonzero GPIO selectors, fixed GPIO pads, unavailable pads, and force-required network functions.

src/reginfo_test.c

gen_padmux_names.pyInclude Anyka tables in name generation +1/-0

Include Anyka tables in name generation

• Registers the generated Anyka header as a source for the shared pad-mux name store.

tools/gen_padmux_names.py

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. A comment line in the Anyka pad-mux backend overruns the column limit ✓ Resolved
Description
The block comment above the GPIO37/GPIO50 rows runs to roughly 120 columns, well past the
80-column limit used by the repository's LLVM-style .clang-format, because the sentence about
GPIO80/81 was appended to the same line. A clang-format pass would reflow this comment, so the
file no longer matches the repository format as submitted. The rest of the new Anyka sources appear
to stay within the limit.

2. GPIO reads misreport peripheral pins ✓ Resolved
Description
anyka_gpio_getset() checks the mux state for set but calls anyka_gpio_read() unconditionally
for get. When a pad carries SPI0, RMII, or another peripheral function, gpio get prints the
controller's GPIO latch or input bit as the pin's level even though that GPIO is not selected.

3. Unknown pad modes can be overwritten ✓ Resolved
Description
ak_get() returns zero for an unrecognized selector, which makes the existing padmux_set() front
door skip its in_use() check and proceed to ak_set(). If a pad holds a selector absent from the
generated binding table, an ordinary gpio mux  GPIO overwrites that state without the --force
required for recognized protected functions.

View review recommended (1)
4. Driving the PHY-reset pad can still drop the network ✓ Resolved
Description
ak_in_use() checks only SPI0_, RMII_ and OPCLK mux functions, while anyka_gpio_getset() permits
writes to GPIO71 whenever it is muxed to GPIO, without checking its board-level role. On the
reported EV300L camera, gpio set 71 0 drives the Ethernet PHY reset without a --force prompt,
and gpio scan and the IR-cut guess also include the pad as a candidate.


Informational

5. Comment lists a network pad the table never protects ✓ Resolved
Description
The header comment in anyka_padmux.c says the Ethernet MAC uses RMII on GPIO0..8, GPIO11 and GPIO23,
but both generated tables give pad 23 only GPIO23 and CSI_D4, and pad 0's network function is
OPCLK1, not RMII. Someone reading the comment would think pad 23 is covered by the in-use refusal,
but ak_in_use() never refuses it.

Grey Divider

Tip of the day
💡 Did you know, you can route each severity your way: inline, summary, both, or drop

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Review of #291:
- A pad the kernel holds is in_use() and `gpio set` refuses it without
  --force. anyka_gpio_owner() reads, once per run, the pinctrl mux owners
  (debugfs pinctrl/*/pinmux-pins), the GPIOs handed to drivers (debugfs
  gpio; a sysfs export by the user does not count) and the *-gpio(s)
  properties of enabled device-tree nodes. On #380's EV300L that is the
  PHY's reset-gpios on GPIO71, the MAC's GPIO23, the SD card's GPIO37 and
  GPIO98, the sensor resets and the MIPI switch select. `gpio scan` says
  "held by <owner>" for those, and the IR-cut guess skips them.
- A pad whose selector the table has no name for is no longer moved by an
  unforced ipchw_padmux_set(), on any backend with an in_use() hook
  (Anyka, Fullhan). reginfo_test's Fullhan sequence now expects that.
- `gpio get` on a pad not muxed to GPIO refuses, as `gpio set` did,
  instead of printing the controller's latch as the pin's level.
- The header comment lists the network pads as the table has them
  (OPCLK1 on 0, RMII_* on 1..8 and 11) and names the held ones; the
  over-long comment line is rewrapped.
- reginfo_test: owners from a fabricated debugfs and device tree (a
  user export, a disabled node and the 0xffff "no pin" are nobody's),
  pad 23 refused, the unknown selector refused and then forced.

On qemu-bench ak3918ev300l: `gpio set 71 0` and `gpio set 18 0` are
refused naming reset-gpios and sensor-reset, `gpio mux 23 CSI_D4` and
`gpio get 0` are refused, and `gpio scan` lists the held pads with their
owners.
@openipc-ai

Copy link
Copy Markdown
Contributor Author

On the Qodo review, all five are addressed in c9c1c72:

  1. Over-long comment line: rewrapped. The new files are within 80 columns.
  2. gpio get on a peripheral pin: it now refuses a pad that isn't muxed to GPIO, as gpio set already did. It no longer prints the controller's latch as the pin's level.
  3. Unknown selectors: a pad whose selector the table has no name for is no longer moved by an unforced ipchw_padmux_set(). This covers every backend with an in_use() hook, so Fullhan too, and the Fullhan test sequence now expects it. ipchw_padmux_set_forced() still moves it.
  4. GPIO71, the PHY reset: fixed without hard-coding a pin.
    • A new anyka_gpio_owner() reads three things once per run:
      • the kernel's pinctrl mux owners (debugfs pinctrl/*/pinmux-pins);
      • the GPIOs handed to drivers (debugfs gpio; the user's own sysfs exports don't count);
      • the *-gpio(s) properties of enabled device-tree nodes.
    • A pad any of those holds is in_use(), so gpio set refuses it without --force, gpio scan shows "held by ", and the IR-cut guess skips it.
    • On #380's EV300L this catches:
      • the PHY's reset-gpios on 71;
      • the MAC's GPIO23;
      • the SD card's 37 and 98;
      • the sensor resets and the MIPI switch select;
      • the audio block's 69.
  5. Pad 23 in the comment: the comment now lists the network pads as the table has them (OPCLK1 on 0, RMII_* on 1–8 and 11). Pad 23 is protected as a kernel-held pad, under point 4.

Re-tested: reginfo_test (with a fabricated debugfs and device tree for the owner lookup), the CI native set, the IPCHW_PADMUX sweep (none, anyka, v4;anyka, fh, all), the trimmed build, and qemu-bench ak3918ev300l. In the emulator, gpio set 71 0 and gpio set 18 0 are refused and name their owners, gpio mux 23 CSI_D4 and gpio get 0 are refused, and gpio scan lists every held pad with its owner.

@openipc-ai
openipc-ai merged commit 3a64ca0 into master Nov 22, 2026
5 checks passed
@openipc-ai
openipc-ai deleted the anyka/padmux branch November 22, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant