1 /* 2 * Copyright (c) 2022 Gerson Fernando Budke 3 * SPDX-License-Identifier: Apache-2.0 4 */ 5 6 #ifndef DT_BINDINGS_PINCTRL_ATMEL_SAM_H_ 7 #define DT_BINDINGS_PINCTRL_ATMEL_SAM_H_ 8 9 /* 10 * @name Atmel SAM gpio port list. 11 * @{ 12 */ 13 14 #define SAM_PINMUX_PORT_a 0U 15 #define SAM_PINMUX_PORT_b 1U 16 #define SAM_PINMUX_PORT_c 2U 17 #define SAM_PINMUX_PORT_d 3U 18 #define SAM_PINMUX_PORT_e 4U 19 #define SAM_PINMUX_PORT_f 5U 20 #define SAM_PINMUX_PORT_g 6U 21 #define SAM_PINMUX_PORT_h 7U 22 #define SAM_PINMUX_PORT_i 8U 23 #define SAM_PINMUX_PORT_j 9U 24 #define SAM_PINMUX_PORT_k 10U 25 #define SAM_PINMUX_PORT_l 11U 26 #define SAM_PINMUX_PORT_m 12U 27 #define SAM_PINMUX_PORT_n 13U 28 #define SAM_PINMUX_PORT_o 14U 29 #define SAM_PINMUX_PORT_p 15U 30 31 /** @} */ 32 33 /** 34 * @name Atmel SAM peripheral list. 35 * @{ 36 */ 37 38 /** GPIO */ 39 #define SAM_PINMUX_PERIPH_gpio 0U 40 /** Peripherals */ 41 #define SAM_PINMUX_PERIPH_a 0U 42 #define SAM_PINMUX_PERIPH_b 1U 43 #define SAM_PINMUX_PERIPH_c 2U 44 #define SAM_PINMUX_PERIPH_d 3U 45 #define SAM_PINMUX_PERIPH_e 4U 46 #define SAM_PINMUX_PERIPH_f 5U 47 #define SAM_PINMUX_PERIPH_g 6U 48 #define SAM_PINMUX_PERIPH_h 7U 49 #define SAM_PINMUX_PERIPH_i 8U 50 #define SAM_PINMUX_PERIPH_j 9U 51 #define SAM_PINMUX_PERIPH_k 10U 52 #define SAM_PINMUX_PERIPH_l 11U 53 #define SAM_PINMUX_PERIPH_m 12U 54 #define SAM_PINMUX_PERIPH_n 13U 55 /** Extra */ 56 #define SAM_PINMUX_PERIPH_x 0U 57 /** System */ 58 #define SAM_PINMUX_PERIPH_s 0U 59 /** LPM */ 60 #define SAM_PINMUX_PERIPH_lpm 0U 61 /** Wake-up pin sources */ 62 #define SAM_PINMUX_PERIPH_wkup0 0U 63 #define SAM_PINMUX_PERIPH_wkup1 1U 64 #define SAM_PINMUX_PERIPH_wkup2 2U 65 #define SAM_PINMUX_PERIPH_wkup3 3U 66 #define SAM_PINMUX_PERIPH_wkup4 4U 67 #define SAM_PINMUX_PERIPH_wkup5 5U 68 #define SAM_PINMUX_PERIPH_wkup6 6U 69 #define SAM_PINMUX_PERIPH_wkup7 7U 70 #define SAM_PINMUX_PERIPH_wkup8 8U 71 #define SAM_PINMUX_PERIPH_wkup9 9U 72 #define SAM_PINMUX_PERIPH_wkup10 10U 73 #define SAM_PINMUX_PERIPH_wkup11 11U 74 #define SAM_PINMUX_PERIPH_wkup12 12U 75 #define SAM_PINMUX_PERIPH_wkup13 13U 76 #define SAM_PINMUX_PERIPH_wkup14 14U 77 #define SAM_PINMUX_PERIPH_wkup15 15U 78 /** @} */ 79 80 /** 81 * @name Atmel SAM pin function list. 82 * @{ 83 */ 84 85 /** Selects pin to be used as GPIO */ 86 #define SAM_PINMUX_FUNC_gpio 0U 87 /** Selects pin to be used as by some peripheral */ 88 #define SAM_PINMUX_FUNC_periph 1U 89 /** Selects pin to be used as extra function */ 90 #define SAM_PINMUX_FUNC_extra 2U 91 /** Selects pin to be used as system function */ 92 #define SAM_PINMUX_FUNC_system 3U 93 /** Selects and configure pin to be used in Low Power Mode */ 94 #define SAM_PINMUX_FUNC_lpm 4U 95 /** Selects and configure wake-up pin sources Low Power Mode */ 96 #define SAM_PINMUX_FUNC_wakeup 5U 97 98 /** @} */ 99 100 /** 101 * @name Atmel SAM pinmux bit field mask and positions. 102 * @{ 103 */ 104 105 /** Pinmux bit field position. */ 106 #define SAM_PINCTRL_PINMUX_POS (16U) 107 /** Pinmux bit field mask. */ 108 #define SAM_PINCTRL_PINMUX_MASK (0xFFFF) 109 110 /** Port field mask. */ 111 #define SAM_PINMUX_PORT_MSK (0xFU) 112 /** Port field position. */ 113 #define SAM_PINMUX_PORT_POS (0U) 114 /** Pin field mask. */ 115 #define SAM_PINMUX_PIN_MSK (0x1FU) 116 /** Pin field position. */ 117 #define SAM_PINMUX_PIN_POS (SAM_PINMUX_PORT_POS + 4U) 118 /** Function field mask. */ 119 #define SAM_PINMUX_FUNC_MSK (0x7U) 120 /** Function field position. */ 121 #define SAM_PINMUX_FUNC_POS (SAM_PINMUX_PIN_POS + 5U) 122 /** Peripheral field mask. */ 123 #define SAM_PINMUX_PERIPH_MSK (0xFU) 124 /** Peripheral field position. */ 125 #define SAM_PINMUX_PERIPH_POS (SAM_PINMUX_FUNC_POS + 3U) 126 127 /** @} */ 128 129 /** 130 * @brief Atmel SAM pinmux bit field. 131 * @anchor SAM_PINMUX 132 * 133 * Fields: 134 * 135 * - 0..3: port 136 * - 4..8: pin_num 137 * - 9..11: func 138 * - 12..15: pin_mux 139 * 140 * @param port Port ('A'..'P') 141 * @param pin Pin (0..31) 142 * @param func Function (GPIO, Peripheral, System, Extra, LPM - 0..4) 143 * @param pin_mux Peripheral based on the Function selected (0..15) 144 */ 145 #define SAM_PINMUX(port, pin_num, pin_mux, func) \ 146 ((((SAM_PINMUX_PORT_##port) & SAM_PINMUX_PORT_MSK) \ 147 << SAM_PINMUX_PORT_POS) | \ 148 (((pin_num) & SAM_PINMUX_PIN_MSK) \ 149 << SAM_PINMUX_PIN_POS) | \ 150 (((SAM_PINMUX_FUNC_##func) & SAM_PINMUX_FUNC_MSK) \ 151 << SAM_PINMUX_FUNC_POS) | \ 152 (((SAM_PINMUX_PERIPH_##pin_mux) & SAM_PINMUX_PERIPH_MSK) \ 153 << SAM_PINMUX_PERIPH_POS)) 154 155 /** 156 * Obtain Pinmux value from pinctrl_soc_pin_t configuration. 157 * 158 * @param pincfg pinctrl_soc_pin_t bit field value. 159 */ 160 #define SAM_PINMUX_GET(pincfg) \ 161 (((pincfg) >> SAM_PINCTRL_PINMUX_POS) & SAM_PINCTRL_PINMUX_MASK) 162 163 #define SAM_PINMUX_PORT_GET(pincfg) \ 164 ((SAM_PINMUX_GET(pincfg) >> SAM_PINMUX_PORT_POS) \ 165 & SAM_PINMUX_PORT_MSK) 166 167 #define SAM_PINMUX_PIN_GET(pincfg) \ 168 ((SAM_PINMUX_GET(pincfg) >> SAM_PINMUX_PIN_POS) \ 169 & SAM_PINMUX_PIN_MSK) 170 171 #define SAM_PINMUX_FUNC_GET(pincfg) \ 172 ((SAM_PINMUX_GET(pincfg) >> SAM_PINMUX_FUNC_POS) \ 173 & SAM_PINMUX_FUNC_MSK) 174 175 #define SAM_PINMUX_PERIPH_GET(pincfg) \ 176 ((SAM_PINMUX_GET(pincfg) >> SAM_PINMUX_PERIPH_POS) \ 177 & SAM_PINMUX_PERIPH_MSK) 178 179 #endif /* DT_BINDINGS_PINCTRL_ATMEL_SAM_H_ */ 180