Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
soburi committed Sep 25, 2024
1 parent e0cbdf6 commit 1aabdb7
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions soc/raspberrypi/rpi_pico/common/binary_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
#include <zephyr/kernel.h>
#include <zephyr/devicetree.h>

#if defined(CONFIG_SOC_RP2040)
#include <zephyr/dt-bindings/pinctrl/rpi-pico-rp2040.h>
#elif defined(CONFIG_SOC_RP2350A)
#include <zephyr/dt-bindings/pinctrl/rpi-pico-rp2350a.h>
#elif defined(CONFIG_SOC_RP2350B)
#include <zephyr/dt-bindings/pinctrl/rpi-pico-rp2350b.h>
#endif
#include <zephyr/dt-bindings/pinctrl/rpi-pico-pinctrl-common.h>

#include <soc.h>

Expand Down Expand Up @@ -232,6 +226,8 @@

#define EXPR_EQ(n, m) UTIL_CAT(UTIL_CAT(UTIL_CAT(EXPR_EQ_, n), _), m)

/* utils for pin encoding calcluation */

#ifdef CONFIG_SOC_RP2040
#define PIN_ENCODE(n, idx, offset) ((uint32_t)PIN_NUM(n, idx) << (2 + (idx + offset + 1) * 5))
#define MAX_PIN_ENTRY 4
Expand All @@ -243,6 +239,8 @@
#define PIN_NUM(n, idx) ((DT_PROP_BY_IDX(n, pinmux, idx) >> RP2_PIN_NUM_POS) & RP2_PIN_NUM_MASK)
#define PIN_FUNC(n, idx) (DT_PROP_BY_IDX(n, pinmux, idx) & RP2_ALT_FUNC_MASK)

/* Recurrence formula for calculating pin offsets for each group */

#define OFFSET_TO_GROUP_IDX_N(n, i, x) \
EXPR_ADD(COND_CODE_1(DT_NODE_HAS_PROP(DT_CHILD_BY_IDX(n, i), pinmux), \
(DT_PROP_LEN(DT_CHILD_BY_IDX(n, i), pinmux)), (0)), x)
Expand All @@ -260,11 +258,15 @@
#define OFFSET_TO_GROUP_IDX(n, i) UTIL_CAT(OFFSET_TO_GROUP_IDX_, i)(n)
#define COUNT_ALL_PINS(n) OFFSET_TO_GROUP_IDX_8(n)

/* Iterate groups and subgroups */

#define EACH_PINCTRL_SUBGROUP(n, fn, sep, ...) \
DT_FOREACH_PROP_ELEM_SEP_VARGS(n, pinmux, fn, sep, __VA_ARGS__)
#define EACH_PINCTRL_GROUP(n, sep, fn, ...) \
DT_FOREACH_CHILD_SEP_VARGS(n, EACH_PINCTRL_SUBGROUP, sep, fn, sep, __VA_ARGS__)

/* Encode the pins in a group */

#define IS_LAST_PIN(end, idx, off) EXPR_EQ(end, EXPR_ADD(1, EXPR_ADD(idx, off)))
#define PIN_ENTRY(n, p, i, offset) \
COND_CODE_1(DT_PROP_HAS_IDX(n, p, i), (PIN_ENCODE(n, i, offset)), (0))
Expand All @@ -276,9 +278,13 @@
end)
#define ENCODE_GROUP_PINS(n) (EACH_PINCTRL_GROUP(n, (|), ENCODE_EACH_PIN, COUNT_ALL_PINS(n)))

/* Get group-wide pin functions */

#define EACH_PIN_FUNC(n, p, i, _) PIN_FUNC(n, i)
#define GROUP_PIN_FUNC(n) (EACH_PINCTRL_GROUP(n, (|), EACH_PIN_FUNC))

/* Check if pin functions are all equal within a group */

#define EACH_PIN_FUNC_IS(n, p, i, func) (PIN_FUNC(n, i) == func)
#define ALL_PIN_FUNC_IS(n, pinfunc) (EACH_PINCTRL_GROUP(n, (&&), EACH_PIN_FUNC_IS, pinfunc))

Expand Down Expand Up @@ -373,7 +379,7 @@ bi_decl(bi_string(BINARY_INFO_TAG_RASPBERRY_PI, BINARY_INFO_ID_RP_BOOT2_NAME,
(uint32_t)PICO_BOOT_STAGE2_NAME));
#endif

#ifndef NDEBUG
#ifdef CONFIG_DEBUG
bi_decl(bi_program_build_attribute((uint32_t) "Debug"));
#else
bi_decl(bi_program_build_attribute((uint32_t) "Release"));
Expand Down

0 comments on commit 1aabdb7

Please sign in to comment.