|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Microchip Technology Inc. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <zephyr/devicetree.h> |
| 8 | +#include <zephyr/types.h> |
| 9 | +#include <dt-bindings/pic32c/pic32cm_jh/common/mchp_pinctrl_pinmux_pic32c.h> |
| 10 | + |
| 11 | +#ifdef __cplusplus |
| 12 | +extern "C" { |
| 13 | +#endif |
| 14 | + |
| 15 | +/** @cond INTERNAL_HIDDEN */ |
| 16 | + |
| 17 | +/** |
| 18 | + * @brief Structure representing the pin control settings for a SOC pin. |
| 19 | + * |
| 20 | + * This structure is used to define the pinmux and pin configuration settings |
| 21 | + * for a specific pin on the SOC. It includes information about the port, pin, |
| 22 | + * function, bias, drive, and other configuration options. |
| 23 | + */ |
| 24 | +typedef struct pinctrl_soc_pin { |
| 25 | + /** Pinmux settings (port, pin and function). */ |
| 26 | + uint16_t pinmux; |
| 27 | + /** Pin configuration (bias, drive etc). */ |
| 28 | + uint16_t pinflag; |
| 29 | +} pinctrl_soc_pin_t; |
| 30 | + |
| 31 | +/** |
| 32 | + * @brief Utility macro to initialize pinmux field. |
| 33 | + * |
| 34 | + * @param node_id Node identifier. |
| 35 | + * @param prop Property name. |
| 36 | + * @param idx Property entry index. |
| 37 | + */ |
| 38 | +#define Z_PINCTRL_MCHP_PINMUX_INIT(node_id, prop, idx) DT_PROP_BY_IDX(node_id, prop, idx) |
| 39 | + |
| 40 | +/** |
| 41 | + * @brief Utility macro to initialize each pin flag. |
| 42 | + * |
| 43 | + * @param node_id Node identifier. |
| 44 | + * @param prop Property name. |
| 45 | + * @param idx Property entry index. |
| 46 | + */ |
| 47 | +#define Z_PINCTRL_MCHP_PINFLAG_INIT(node_id, prop, idx) \ |
| 48 | + ((DT_PROP(node_id, bias_pull_up) << MCHP_PINCTRL_PULLUP_POS) | \ |
| 49 | + (DT_PROP(node_id, bias_pull_down) << MCHP_PINCTRL_PULLDOWN_POS) | \ |
| 50 | + (DT_PROP(node_id, input_enable) << MCHP_PINCTRL_INPUTENABLE_POS) | \ |
| 51 | + (DT_PROP(node_id, output_enable) << MCHP_PINCTRL_OUTPUTENABLE_POS) | \ |
| 52 | + (DT_ENUM_IDX(node_id, drive_strength) << MCHP_PINCTRL_DRIVESTRENGTH_POS)), |
| 53 | + |
| 54 | +/** |
| 55 | + * @brief Utility macro to initialize each pin. |
| 56 | + * |
| 57 | + * @param node_id Node identifier. |
| 58 | + * @param prop Property name. |
| 59 | + * @param idx Property entry index. |
| 60 | + */ |
| 61 | +#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ |
| 62 | + {.pinmux = Z_PINCTRL_MCHP_PINMUX_INIT(node_id, prop, idx), \ |
| 63 | + .pinflag = Z_PINCTRL_MCHP_PINFLAG_INIT(node_id, prop, idx)}, |
| 64 | + |
| 65 | +/** |
| 66 | + * @brief Utility macro to initialize state pins contained in a given property. |
| 67 | + * |
| 68 | + * @param node_id Node identifier. |
| 69 | + * @param prop Property name describing state pins. |
| 70 | + */ |
| 71 | +#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \ |
| 72 | + {DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux, \ |
| 73 | + Z_PINCTRL_STATE_PIN_INIT)} |
| 74 | + |
| 75 | +/** @endcond */ |
| 76 | + |
| 77 | +/** |
| 78 | + * @brief Pin flags/attributes |
| 79 | + * @anchor MCHP_PINFLAGS |
| 80 | + * |
| 81 | + * @{ |
| 82 | + */ |
| 83 | + |
| 84 | +#define MCHP_PINCTRL_FLAGS_DEFAULT (0U) |
| 85 | +#define MCHP_PINCTRL_FLAGS_POS (0U) |
| 86 | +#define MCHP_PINCTRL_FLAGS_MASK (0x3F << MCHP_PINCTRL_FLAGS_POS) |
| 87 | +#define MCHP_PINCTRL_FLAG_MASK (1U) |
| 88 | +#define MCHP_PINCTRL_PULLUP_POS (MCHP_PINCTRL_FLAGS_POS) |
| 89 | +#define MCHP_PINCTRL_PULLUP (1U << MCHP_PINCTRL_PULLUP_POS) |
| 90 | +#define MCHP_PINCTRL_PULLDOWN_POS (MCHP_PINCTRL_PULLUP_POS + 1U) |
| 91 | +#define MCHP_PINCTRL_PULLDOWN (1U << MCHP_PINCTRL_PULLDOWN_POS) |
| 92 | +#define MCHP_PINCTRL_OPENDRAIN_POS (MCHP_PINCTRL_PULLDOWN_POS + 1U) |
| 93 | +#define MCHP_PINCTRL_OPENDRAIN (1U << MCHP_PINCTRL_OPENDRAIN_POS) |
| 94 | +#define MCHP_PINCTRL_INPUTENABLE_POS (MCHP_PINCTRL_OPENDRAIN_POS + 1U) |
| 95 | +#define MCHP_PINCTRL_INPUTENABLE (1U << MCHP_PINCTRL_INPUTENABLE_POS) |
| 96 | +#define MCHP_PINCTRL_OUTPUTENABLE_POS (MCHP_PINCTRL_INPUTENABLE_POS + 1U) |
| 97 | +#define MCHP_PINCTRL_OUTPUTENABLE (1U << MCHP_PINCTRL_OUTPUTENABLE_POS) |
| 98 | +#define MCHP_PINCTRL_DRIVESTRENGTH_POS (MCHP_PINCTRL_OUTPUTENABLE_POS + 1U) |
| 99 | +#define MCHP_PINCTRL_DRIVESTRENGTH (1U << MCHP_PINCTRL_DRIVESTRENGTH_POS) |
| 100 | + |
| 101 | +/** @} */ |
| 102 | + |
| 103 | +#ifdef __cplusplus |
| 104 | +} |
| 105 | +#endif |
0 commit comments