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-pinctrl-common.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 : 5; 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 /** Output-enable override */ 33 uint32_t oe_override : 2; 34 }; 35 36 typedef struct rpi_pinctrl_soc_pin pinctrl_soc_pin_t; 37 38 /** 39 * @brief Utility macro to initialize each pin. 40 * 41 * @param node_id Node identifier. 42 * @param prop Property name. 43 * @param idx Property entry index. 44 */ 45 #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ 46 { \ 47 RP2_GET_PIN_NUM(DT_PROP_BY_IDX(node_id, prop, idx)), \ 48 RP2_GET_PIN_ALT_FUNC(DT_PROP_BY_IDX(node_id, prop, idx)), \ 49 DT_ENUM_IDX(node_id, drive_strength), \ 50 DT_ENUM_IDX(node_id, slew_rate), \ 51 DT_PROP(node_id, bias_pull_up), \ 52 DT_PROP(node_id, bias_pull_down), \ 53 DT_PROP(node_id, input_enable), \ 54 DT_PROP(node_id, input_schmitt_enable), \ 55 DT_PROP(node_id, raspberrypi_oe_override), \ 56 }, 57 58 /** 59 * @brief Utility macro to initialize state pins contained in a given property. 60 * 61 * @param node_id Node identifier. 62 * @param prop Property name describing state pins. 63 */ 64 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \ 65 {DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), \ 66 DT_FOREACH_PROP_ELEM, pinmux, \ 67 Z_PINCTRL_STATE_PIN_INIT)} 68 69 #define RP2_GET_PIN_NUM(pinctrl) \ 70 (((pinctrl) >> RP2_PIN_NUM_POS) & RP2_PIN_NUM_MASK) 71 #define RP2_GET_PIN_ALT_FUNC(pinctrl) \ 72 (((pinctrl) >> RP2_ALT_FUNC_POS) & RP2_ALT_FUNC_MASK) 73 74 #endif /* ZEPHYR_SOC_ARM_RPI_PICO_RP2_PINCTRL_SOC_H_ */ 75