|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Microchip |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @file |
| 9 | + * Microchip PIC32CXSG SoC specific helpers for pinctrl driver |
| 10 | + */ |
| 11 | + |
| 12 | +#ifndef ZEPHYR_INCLUDE_DRIVERS_PINCTRL_PINCTRL_SOC_PIC32CXSG_COMMON_H_ |
| 13 | +#define ZEPHYR_INCLUDE_DRIVERS_PINCTRL_PINCTRL_SOC_PIC32CXSG_COMMON_H_ |
| 14 | + |
| 15 | +#include <zephyr/devicetree.h> |
| 16 | +#include <zephyr/types.h> |
| 17 | +#include <dt-bindings/pinctrl/microchip_pic32cxsg_pinctrl.h> |
| 18 | + |
| 19 | +#ifdef __cplusplus |
| 20 | +extern "C" { |
| 21 | +#endif |
| 22 | + |
| 23 | +/** @cond INTERNAL_HIDDEN */ |
| 24 | + |
| 25 | +/** @brief Type for PIC32CXSG pin. |
| 26 | + * |
| 27 | + * Bits: |
| 28 | + * - 0-15: PIC32CXSG pinmux bit field (@ref SAM_PINMUX). |
| 29 | + * - 16-21: Pin flags bit field (@ref PIC32CXSG_PINFLAGS). |
| 30 | + * - 22-31: Reserved. |
| 31 | + */ |
| 32 | +typedef uint32_t pinctrl_soc_pin_t; |
| 33 | + |
| 34 | +/** |
| 35 | + * @brief Utility macro to initialize each pin. |
| 36 | + * |
| 37 | + * @param node_id Node identifier. |
| 38 | + * @param prop Property name. |
| 39 | + * @param idx Property entry index. |
| 40 | + */ |
| 41 | +/* (CONFIG_SOC_FAMILY_MICROCHIP_PIC32CXSG) */ |
| 42 | +#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ |
| 43 | + ((DT_PROP_BY_IDX(node_id, prop, idx) << SAM_PINCTRL_PINMUX_POS) | \ |
| 44 | + (DT_PROP(node_id, bias_pull_up) << SAM_PINCTRL_PULLUP_POS) | \ |
| 45 | + (DT_PROP(node_id, bias_pull_down) << SAM_PINCTRL_PULLDOWN_POS) | \ |
| 46 | + (DT_PROP(node_id, input_enable) << SAM_PINCTRL_INPUTENABLE_POS) | \ |
| 47 | + (DT_PROP(node_id, output_enable) << SAM_PINCTRL_OUTPUTENABLE_POS) | \ |
| 48 | + (DT_ENUM_IDX(node_id, drive_strength) << SAM_PINCTRL_DRIVESTRENGTH_POS)), |
| 49 | + |
| 50 | +/** |
| 51 | + * @brief Utility macro to initialize state pins contained in a given property. |
| 52 | + * |
| 53 | + * @param node_id Node identifier. |
| 54 | + * @param prop Property name describing state pins. |
| 55 | + */ |
| 56 | +#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \ |
| 57 | + {DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux, \ |
| 58 | + Z_PINCTRL_STATE_PIN_INIT)} |
| 59 | + |
| 60 | +/** @endcond */ |
| 61 | + |
| 62 | +/** |
| 63 | + * @brief Pin flags/attributes |
| 64 | + * @anchor PIC32CXSG_PINFLAGS |
| 65 | + * |
| 66 | + * @{ |
| 67 | + */ |
| 68 | + |
| 69 | +#define SAM_PINCTRL_FLAGS_DEFAULT (0U) |
| 70 | +#define SAM_PINCTRL_FLAGS_POS (0U) |
| 71 | +#define SAM_PINCTRL_FLAGS_MASK (0x3F << SAM_PINCTRL_FLAGS_POS) |
| 72 | +#define SAM_PINCTRL_FLAG_MASK (1U) |
| 73 | +#define SAM_PINCTRL_PULLUP_POS (SAM_PINCTRL_FLAGS_POS) |
| 74 | +#define SAM_PINCTRL_PULLUP (1U << SAM_PINCTRL_PULLUP_POS) |
| 75 | +#define SAM_PINCTRL_PULLDOWN_POS (SAM_PINCTRL_PULLUP_POS + 1U) |
| 76 | +#define SAM_PINCTRL_PULLDOWN (1U << SAM_PINCTRL_PULLDOWN_POS) |
| 77 | +#define SAM_PINCTRL_OPENDRAIN_POS (SAM_PINCTRL_PULLDOWN_POS + 1U) |
| 78 | +#define SAM_PINCTRL_OPENDRAIN (1U << SAM_PINCTRL_OPENDRAIN_POS) |
| 79 | +#define SAM_PINCTRL_INPUTENABLE_POS (SAM_PINCTRL_OPENDRAIN_POS + 1U) |
| 80 | +#define SAM_PINCTRL_INPUTENABLE (1U << SAM_PINCTRL_INPUTENABLE_POS) |
| 81 | +#define SAM_PINCTRL_OUTPUTENABLE_POS (SAM_PINCTRL_INPUTENABLE_POS + 1U) |
| 82 | +#define SAM_PINCTRL_OUTPUTENABLE (1U << SAM_PINCTRL_OUTPUTENABLE_POS) |
| 83 | +#define SAM_PINCTRL_DRIVESTRENGTH_POS (SAM_PINCTRL_OUTPUTENABLE_POS + 1U) |
| 84 | +#define SAM_PINCTRL_DRIVESTRENGTH (1U << SAM_PINCTRL_DRIVESTRENGTH_POS) |
| 85 | + |
| 86 | +/** @} */ |
| 87 | + |
| 88 | +/** |
| 89 | + * Obtain Flag value from pinctrl_soc_pin_t configuration. |
| 90 | + * |
| 91 | + * @param pincfg pinctrl_soc_pin_t bit field value. |
| 92 | + * @param pos attribute/flags bit position (@ref PIC32CXSG_PINFLAGS). |
| 93 | + */ |
| 94 | +#define SAM_PINCTRL_FLAG_GET(pincfg, pos) (((pincfg) >> pos) & SAM_PINCTRL_FLAG_MASK) |
| 95 | + |
| 96 | +#define SAM_PINCTRL_FLAGS_GET(pincfg) (((pincfg) >> SAM_PINCTRL_FLAGS_POS) & SAM_PINCTRL_FLAGS_MASK) |
| 97 | + |
| 98 | +#ifdef __cplusplus |
| 99 | +} |
| 100 | +#endif |
| 101 | + |
| 102 | +#endif /* ZEPHYR_INCLUDE_DRIVERS_PINCTRL_PINCTRL_SOC_PIC32CXSG_COMMON_H_ */ |
0 commit comments