ipctool icon indicating copy to clipboard operation
ipctool copied to clipboard

padmux: SigmaStar and Ingenic tables carry no pad-mux data, so ipchw_padmux_* answers nothing on either

Open openipc-ai opened this issue 2 months ago • 0 comments

Summary

ipchw_padmux_* answers usefully on HiSilicon and Goke and answers nothing useful on SigmaStar or Ingenic. The header already admits this:

Only HiSilicon and Goke parts carry real alternatives per pad. The SigmaStar and Ingenic tables name one function per register, so on those gpio_name is NULL, gpio_pad is -1, and a lookup by pad finds nothing.

That sentence describes the data, not a property of the silicon: both families do have per-pad function selection. The result is that anything built on this API — "what is pad N carrying right now", "put pad N back to GPIO", "which pads can carry I2C1" — works on one vendor and is simply absent on the others.

Worth stating up front, because it decides how much of this is code and how much is data: the GPIO side of the API is already derived generically. row_gpio() in src/reginfo.c scans a row's funcs[] for the first entry that parses as GPIO<bank>_<pin> and takes its index as the selector value that restores GPIO. Nothing in padmux_walk() is vendor-specific. A table whose rows are shaped like the HiSilicon ones gets the whole API for free.

The two platforms are broken in different ways, and only one of them is a data fill.


SigmaStar — a data problem

src/hal/sstar_reginfo.h has the right register addresses and the wrong contents. Every row names the pad rather than the functions selectable on it:

MUXCTRL(I6B_reg0,  0x1F207800, "PAD_GPIO0")
MUXCTRL(I6B_reg14, 0x1F207850, "PAD_FUART_RX")
MUXCTRL(I6B_reg18, 0x1F207980, "PAD_I2C0_SCL")

Compare a HiSilicon row, where funcs[] is indexed by the selector value:

MUXCTRL(EV300_iocfg_reg92, 0x120C0020, "JTAG_TDI", "SPI1_CSN1", "GPIO2_0",
        "SDIO0_CARD_POWER_EN_N", "PWM3", "I2S_SD_TX")

So on SigmaStar every row reports func = 0 whatever the register actually holds, no row has a GPIO alternative, and ipchw_padmux_by_pad() returns nothing for every pad.

What it should look like. One register per pad is already the right model for SigmaStar; only the payload changes. Each funcs[] becomes the list of modes that pad's config register selects, indexed by the register value, with the GPIO mode spelled GPIO<bank>_<pin> so row_gpio() finds it:

/* PAD_GPIO0 on Infinity6B: mode 0 is GPIO, 1..n are the peripherals. */
MUXCTRL(I6B_reg0, 0x1F207800, "GPIO0_0", "UART1_RX", "PWM0", ...)

Three things to get right, and they are the whole job:

  1. Index == register value. A mode that does not exist at some value must be "reserved", which padmux_walk() already skips, rather than the list being compacted — otherwise every later mode is off by one.
  2. The GPIO name must be the running pad number, bank*8+pin, because that is what gpio_name_to_pad() parses and what every consumer speaks. If SigmaStar's own numbering does not divide into banks of eight that way, say so on the issue before filling the table — it changes what the mapping has to be.
  3. padmux_func_mask() returns 0xffff for the Infinity6 family. If the mode field is narrower (4 bits is typical), fix the mask at the same time, or a row will match on bits that are not the selector.

Tables to fill: I6B_regs (97 rows), I6C_regs, I6E_regs. Source is the vendor's pad-mux documentation or the padmux node in the vendor kernel's device tree, which lists the modes per pad in selector order.


Ingenic — a model problem, not a data one

src/hal/ingenic_reginfo.h is not a pad-mux table at all. These are the GPIO port control registers:

MUXCTRL(T31_reg0,  0x10010000, "PAPIN")
MUXCTRL(T31_reg1,  0x10010010, "PAINT")
MUXCTRL(T31_reg4,  0x10010020, "PAMSK")
MUXCTRL(T31_reg7,  0x10010030, "PAPAT1")
MUXCTRL(T31_reg10, 0x10010040, "PAPAT0")

PAPIN, PAINT, PAMSK, PAPAT0/1, PAFLG are port A's pin state, interrupt, mask, pattern and flag registers. They are useful for reginfo output and they are not what ipchw_padmux_* is for.

Ingenic selects a pin's function with two bits spread across two registers: INT/MSK choose device-versus-GPIO, and PAT1:PAT0 choose which of four device functions — one bit each, at the pin's own bit position, in two different registers. That cannot be expressed as {one address, one contiguous mask, one value}, which is what both muxctrl_reg_t and the public ipchw_padmux_t assume.

So Ingenic cannot be fixed by filling a table, and I would not encourage bending ipchw_padmux_t into a shape that carries a second address and a bit index — that leaks one vendor's register layout into every consumer of the API, including the ones that only ever wanted to ask a question.

Suggested direction: move the access inside ipctool

The API currently hands out a physical address and a mask and leaves every caller to do its own read-modify-write through its own /dev/mem window. That is what makes Ingenic inexpressible, and it is also a hazard on the platforms that do work — the header already warns that mem_reg() keeps one unsynchronised mapping and that every write must come from a single thread.

Two accessors would close both:

/* What pad `pad` is carrying right now. Returns the row, or IPCHW_PADMUX_*. */
int ipchw_padmux_get(int pad, ipchw_padmux_t *out);

/* Put `func_name` on pad `pad`. */
int ipchw_padmux_set(int pad, const char *func_name);

With those, a consumer never composes a register write, and each vendor's mechanism stays behind the library — a selector field on HiSilicon and SigmaStar, an INT/MSK/PAT1/PAT0 quartet on Ingenic. The existing lookups can stay exactly as they are for the "what could this pad be" question; only the "what is it now / make it so" half needs the new shape.

If that is too large a change to take in one go, the useful order is: SigmaStar tables first (self-contained, no API change, unblocks that family), then the accessors, then Ingenic behind them.


Why it matters

OpenIPC's WebUI has a pin page that draws the chip, says what each pad can be and what it is carrying, and lets an owner assign one — and a scan that hunts the IR-cut wiring by driving pads, which now refuses to drive a pad the chip says is currently the serial console. Both read this API. On a SigmaStar or Ingenic camera the pin page is blank and the scan drives blind, purely because the table is empty.

That is the argument for the table living here rather than in each consumer: one place that knows what a pad is, and every tool that asks gets the same answer.

How to check the result

ipctool reginfo on a board of each family should list the pads with their current function resolved, and for any GPIO-capable pad ipchw_padmux_by_pad(N, ...) should return more than zero rows with gpio_pad == N. Today both are empty on SigmaStar and Ingenic and populated on HiSilicon, which is the difference to close.

openipc-ai avatar Sep 15 '26 17:09 openipc-ai