1 /* 2 * Copyright (c) 2021 Yonatan Schachter 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_SOC_ARM_RPI_PICO_RP2_PINCTRL_SOC_H_ 8 #define ZEPHYR_SOC_ARM_RPI_PICO_RP2_PINCTRL_SOC_H_ 9 10 #include <zephyr/dt-bindings/pinctrl/rpi-pico-rp2040-pinctrl.h> 11 12 /** 13 * @brief Type to hold a pin's pinctrl configuration. 14 */ 15 struct rpi_pinctrl_soc_pin { 16 /** Pin number 0..29 */ 17 uint32_t pin_num : 5; 18 /** Alternative function (UART, SPI, etc.) */ 19 uint32_t alt_func : 4; 20 /** Maximum current used by a pin, in mA */ 21 uint32_t drive_strength : 4; 22 /** Slew rate, may be either false (slow) or true (fast) */ 23 uint32_t slew_rate : 1; 24 /** Enable the internal pull up resistor */ 25 uint32_t pullup : 1; 26 /** Enable the internal pull down resistor */ 27 uint32_t pulldown : 1; 28 /** Enable the pin as an input */ 29 uint32_t input_enable : 1; 30 /** Enable the internal schmitt trigger */ 31 uint32_t schmitt_enable : 1; 32 }; 33 34 typedef struct rpi_pinctrl_soc_pin pinctrl_soc_pin_t; 35 36 /** 37 * @brief Utility macro to initialize each pin. 38 * 39 * @param node_id Node identifier. 40 * @param prop Property name. 41 * @param idx Property entry index. 42 */ 43 #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ 44 { \ 45 RP2_GET_PIN_NUM(DT_PROP_BY_IDX(node_id, prop, idx)), \ 46 RP2_GET_PIN_ALT_FUNC(DT_PROP_BY_IDX(node_id, prop, idx)), \ 47 DT_ENUM_IDX(node_id, drive_strength), \ 48 DT_ENUM_IDX(node_id, slew_rate), \ 49 DT_PROP(node_id, bias_pull_up), \ 50 DT_PROP(node_id, bias_pull_down), \ 51 DT_PROP(node_id, input_enable), \ 52 DT_PROP(node_id, input_schmitt_enable), \ 53 }, 54 55 /** 56 * @brief Utility macro to initialize state pins contained in a given property. 57 * 58 * @param node_id Node identifier. 59 * @param prop Property name describing state pins. 60 */ 61 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \ 62 {DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), \ 63 DT_FOREACH_PROP_ELEM, pinmux, \ 64 Z_PINCTRL_STATE_PIN_INIT)} 65 66 #define RP2_GET_PIN_NUM(pinctrl) \ 67 (((pinctrl) >> RP2_PIN_NUM_POS) & RP2_PIN_NUM_MASK) 68 #define RP2_GET_PIN_ALT_FUNC(pinctrl) \ 69 (((pinctrl) >> RP2_ALT_FUNC_POS) & RP2_ALT_FUNC_MASK) 70 71 #endif /* ZEPHYR_SOC_ARM_RPI_PICO_RP2_PINCTRL_SOC_H_ */ 72