Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/hal/ingenic_padmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ static ipchw_padmux_t pad_row(const ingenic_pad_t *pd, int func) {
.address = IPCHW_PADMUX_ADDR_NONE,
.func_mask = 0,
.func = func,
.func_name = func < 0 ? IPCHW_PADMUX_GPIO : pd->funcs[func],
.gpio_name = pd->name,
.func_name =
func < 0 ? IPCHW_PADMUX_GPIO : padmux_name(pd->funcs[func]),
.gpio_name = padmux_name(pd->name),
.gpio_pad = pd->pad,
.gpio_func = -1,
.flags = func < 0 ? IPCHW_PADMUX_F_GPIO : 0,
Expand All @@ -129,9 +130,9 @@ static int ingenic_walk(padmux_match_fn match, const void *arg, int pad,
}

for (int f = 0; f < 4; f++) {
if (!strcmp(pd->funcs[f], "reserved"))
if (!strcmp(padmux_name(pd->funcs[f]), "reserved"))
continue;
if (match != NULL && !match(pd->funcs[f], arg))
if (match != NULL && !match(padmux_name(pd->funcs[f]), arg))
continue;

if (found < max)
Expand Down Expand Up @@ -182,7 +183,7 @@ static int ingenic_get(int pad, ipchw_padmux_t *out, const padmux_io_t *io) {
}

int func = (int)(code & (FUNC_PAT1 | FUNC_PAT0));
if (!strcmp(pd->funcs[func], "reserved"))
if (!strcmp(padmux_name(pd->funcs[func]), "reserved"))
return 0; /* on a function the spec says this pad does not have */

*out = pad_row(pd, func);
Expand Down Expand Up @@ -232,7 +233,8 @@ static int ingenic_set(int pad, const char *func_name, const padmux_io_t *io) {
if (pd == NULL)
return IPCHW_PADMUX_NO_PAD;

if (!strcmp(func_name, IPCHW_PADMUX_GPIO) || !strcmp(func_name, pd->name)) {
if (!strcmp(func_name, IPCHW_PADMUX_GPIO) ||
!strcmp(func_name, padmux_name(pd->name))) {
/* GPIO direction and level are the same nibble as the mux here, so
* "make it GPIO" has to pick one. A pad that is already GPIO keeps
* the direction and level it has; one coming off a peripheral becomes
Expand All @@ -250,9 +252,9 @@ static int ingenic_set(int pad, const char *func_name, const padmux_io_t *io) {
}

for (int f = 0; f < 4; f++) {
if (strcmp(pd->funcs[f], func_name) != 0)
if (strcmp(padmux_name(pd->funcs[f]), func_name) != 0)
continue;
if (!strcmp(pd->funcs[f], "reserved"))
if (!strcmp(padmux_name(pd->funcs[f]), "reserved"))
break;

return write_code(pad, (unsigned)f, io);
Expand Down
682 changes: 341 additions & 341 deletions src/hal/ingenic_padmux.h

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions src/hal/ingenic_padmux_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@

#include <stdint.h>

#include "padmux_names.h"

/* The shape of the generated table in ingenic_padmux.h. Separate from it so
* the generator emits data and nothing else.
*
* An Ingenic pad has exactly four device functions and no selector field:
* which one is live is spelled by one bit each in the port's INT, MSK, PAT1
* and PAT0 registers, at the pin's own position. So the table is four names
* and a pad number, and every register lives in ingenic_padmux.c. */
* and a pad number, and every register lives in ingenic_padmux.c.
*
* The names are OFFSETS into padmux_names, for the reason reginfo.h gives at
* length: a `const char *` here is a relocation in a position-independent
* consumer, and this table held five of them per pad against 326 distinct
* names shared across 1,706 uses. padmux_name() turns one back into the
* `const char *` every caller speaks. */
typedef const struct {
uint16_t pad; /* port * 32 + pin, the number the kernel uses */
const char *name; /* "PB25", the spelling the datasheet uses */
const char *funcs[4]; /* FUNCTION0..3; "reserved" where there is none */
uint16_t pad; /* port * 32 + pin, the number the kernel uses */
uint16_t name; /* "PB25", the spelling the datasheet uses */
uint16_t funcs[4]; /* FUNCTION0..3; "reserved" where there is none */
} ingenic_pad_t;

typedef const struct {
Expand Down
14 changes: 7 additions & 7 deletions src/hal/sstar_padmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static ipchw_padmux_t gpio_row(const sstar_pad_t *pd, int pad) {
.func_mask = 0,
.func = -1,
.func_name = IPCHW_PADMUX_GPIO,
.gpio_name = pd->name,
.gpio_name = padmux_name(pd->name),
.gpio_pad = pad,
.gpio_func = -1,
.flags = IPCHW_PADMUX_F_GPIO,
Expand All @@ -86,8 +86,8 @@ static ipchw_padmux_t mode_row(const sstar_mode_t *m, const sstar_pad_t *pd,
.address = m->address,
.func_mask = m->mask,
.func = m->val,
.func_name = m->name,
.gpio_name = pd->name,
.func_name = padmux_name(m->name),
.gpio_name = padmux_name(pd->name),
.gpio_pad = pad,
/* No single value hands the pad back: see gpio_row(). */
.gpio_func = -1,
Expand Down Expand Up @@ -120,7 +120,7 @@ static int sstar_walk(padmux_match_fn match, const void *arg, int pad,

for (int k = 0; k < pd->nmodes; k++) {
const sstar_mode_t *m = pad_mode(fam, pd, k);
if (match != NULL && !match(m->name, arg))
if (match != NULL && !match(padmux_name(m->name), arg))
continue;

if (found < max)
Expand Down Expand Up @@ -278,13 +278,13 @@ static int sstar_set(int pad, const char *func_name, const padmux_io_t *io) {
if (pad_is_dark(pd))
return IPCHW_PADMUX_NO_FUNC;

bool to_gpio =
!strcmp(func_name, IPCHW_PADMUX_GPIO) || !strcmp(func_name, pd->name);
bool to_gpio = !strcmp(func_name, IPCHW_PADMUX_GPIO) ||
!strcmp(func_name, padmux_name(pd->name));

int want = -1;
if (!to_gpio) {
for (int k = 0; k < pd->nmodes; k++)
if (!strcmp(pad_mode(fam, pd, k)->name, func_name)) {
if (!strcmp(padmux_name(pad_mode(fam, pd, k)->name), func_name)) {
want = k;
break;
}
Expand Down
Loading