|
| 1 | +/* |
| 2 | + * Copyright (c) 2021-2025 Gerson Fernando Budke <[email protected]> |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @file |
| 9 | + * Bouffalo Lab SoC specific helpers for pinctrl driver |
| 10 | + */ |
| 11 | + |
| 12 | +#ifndef ZEPHYR_INCLUDE_DRIVERS_PINCTRL_PINCTRL_SOC_BFLB_COMMON_H_ |
| 13 | +#define ZEPHYR_INCLUDE_DRIVERS_PINCTRL_PINCTRL_SOC_BFLB_COMMON_H_ |
| 14 | + |
| 15 | +#include <zephyr/devicetree.h> |
| 16 | +#include <zephyr/types.h> |
| 17 | + |
| 18 | +/* clang-format off */ |
| 19 | + |
| 20 | +#ifdef __cplusplus |
| 21 | +extern "C" { |
| 22 | +#endif |
| 23 | + |
| 24 | +/** @cond INTERNAL_HIDDEN */ |
| 25 | + |
| 26 | +/** |
| 27 | + * @brief BFLB pincfg bit field. |
| 28 | + * @anchor BFLB_PINMUX |
| 29 | + * |
| 30 | + * Fields: |
| 31 | + * |
| 32 | + * - 24..31: pin |
| 33 | + * - 20..23: signal |
| 34 | + * - 18..19: mode |
| 35 | + * - 16..17: instance |
| 36 | + * - 8..15: function |
| 37 | + * - 7: reserved |
| 38 | + * - 6: GPIO Output Enable |
| 39 | + * - 5: Pull Down |
| 40 | + * - 4: Pull Up |
| 41 | + * - 2..3: Driver Strength |
| 42 | + * - 1: Schmitt trigger (SMT) |
| 43 | + * - 0: reserved |
| 44 | + */ |
| 45 | +typedef uint32_t pinctrl_soc_pin_t; |
| 46 | + |
| 47 | +/** |
| 48 | + * @brief Utility macro to initialize each pin. |
| 49 | + * |
| 50 | + * @param node_id Node identifier. |
| 51 | + * @param prop Property name. |
| 52 | + * @param idx Property entry index. |
| 53 | + */ |
| 54 | +#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ |
| 55 | + ((DT_PROP_BY_IDX(node_id, prop, idx)) \ |
| 56 | + | (DT_PROP(node_id, bias_pull_up) << BFLB_PINMUX_PULL_UP_POS) \ |
| 57 | + | (DT_PROP(node_id, bias_pull_down) << BFLB_PINMUX_PULL_DOWN_POS) \ |
| 58 | + | (DT_PROP(node_id, output_enable) << BFLB_PINMUX_OE_POS) \ |
| 59 | + | (DT_PROP(node_id, input_schmitt_enable) << BFLB_PINMUX_SMT_POS) \ |
| 60 | + | (DT_ENUM_IDX(node_id, drive_strength) << BFLB_PINMUX_DRIVER_STRENGTH_POS) \ |
| 61 | + ), |
| 62 | + |
| 63 | +/** |
| 64 | + * @brief Utility macro to initialize state pins contained in a given property. |
| 65 | + * |
| 66 | + * @param node_id Node identifier. |
| 67 | + * @param prop Property name describing state pins. |
| 68 | + */ |
| 69 | +#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \ |
| 70 | + {DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), \ |
| 71 | + DT_FOREACH_PROP_ELEM, pinmux, \ |
| 72 | + Z_PINCTRL_STATE_PIN_INIT)} |
| 73 | + |
| 74 | +/** @endcond */ |
| 75 | + |
| 76 | +#ifdef __cplusplus |
| 77 | +} |
| 78 | +#endif |
| 79 | + |
| 80 | +/* clang-format on */ |
| 81 | + |
| 82 | +#endif /* ZEPHYR_INCLUDE_DRIVERS_PINCTRL_PINCTRL_SOC_BFLB_COMMON_H_ */ |
0 commit comments