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