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 62 /** @} */ 63 64 /** 65 * @name Atmel SAM pin function list. 66 * @{ 67 */ 68 69 /** Selects pin to be used as GPIO */ 70 #define SAM_PINMUX_FUNC_gpio 0U 71 /** Selects pin to be used as by some peripheral */ 72 #define SAM_PINMUX_FUNC_periph 1U 73 /** Selects pin to be used as extra function */ 74 #define SAM_PINMUX_FUNC_extra 2U 75 /** Selects pin to be used as system function */ 76 #define SAM_PINMUX_FUNC_system 3U 77 /** Selects and configure pin to be used in Low Power Mode */ 78 #define SAM_PINMUX_FUNC_lpm 4U 79 80 /** @} */ 81 82 /** 83 * @name Atmel SAM pinmux bit field mask and positions. 84 * @{ 85 */ 86 87 /** Pinmux bit field position. */ 88 #define SAM_PINCTRL_PINMUX_POS (16U) 89 /** Pinmux bit field mask. */ 90 #define SAM_PINCTRL_PINMUX_MASK (0xFFFF) 91 92 /** Port field mask. */ 93 #define SAM_PINMUX_PORT_MSK (0xFU) 94 /** Port field position. */ 95 #define SAM_PINMUX_PORT_POS (0U) 96 /** Pin field mask. */ 97 #define SAM_PINMUX_PIN_MSK (0x1FU) 98 /** Pin field position. */ 99 #define SAM_PINMUX_PIN_POS (SAM_PINMUX_PORT_POS + 4U) 100 /** Function field mask. */ 101 #define SAM_PINMUX_FUNC_MSK (0x7U) 102 /** Function field position. */ 103 #define SAM_PINMUX_FUNC_POS (SAM_PINMUX_PIN_POS + 5U) 104 /** Peripheral field mask. */ 105 #define SAM_PINMUX_PERIPH_MSK (0xFU) 106 /** Peripheral field position. */ 107 #define SAM_PINMUX_PERIPH_POS (SAM_PINMUX_FUNC_POS + 3U) 108 109 /** @} */ 110 111 /** 112 * @brief Atmel SAM pinmux bit field. 113 * @anchor SAM_PINMUX 114 * 115 * Fields: 116 * 117 * - 0..3: port 118 * - 4..8: pin_num 119 * - 9..11: func 120 * - 12..15: pin_mux 121 * 122 * @param port Port ('A'..'P') 123 * @param pin Pin (0..31) 124 * @param func Function (GPIO, Peripheral, System, Extra, LPM - 0..4) 125 * @param pin_mux Peripheral based on the Function selected (0..15) 126 */ 127 #define SAM_PINMUX(port, pin_num, pin_mux, func) \ 128 ((((SAM_PINMUX_PORT_##port) & SAM_PINMUX_PORT_MSK) \ 129 << SAM_PINMUX_PORT_POS) | \ 130 (((pin_num) & SAM_PINMUX_PIN_MSK) \ 131 << SAM_PINMUX_PIN_POS) | \ 132 (((SAM_PINMUX_FUNC_##func) & SAM_PINMUX_FUNC_MSK) \ 133 << SAM_PINMUX_FUNC_POS) | \ 134 (((SAM_PINMUX_PERIPH_##pin_mux) & SAM_PINMUX_PERIPH_MSK) \ 135 << SAM_PINMUX_PERIPH_POS)) 136 137 /** 138 * Obtain Pinmux value from pinctrl_soc_pin_t configuration. 139 * 140 * @param pincfg pinctrl_soc_pin_t bit field value. 141 */ 142 #define SAM_PINMUX_GET(pincfg) \ 143 (((pincfg) >> SAM_PINCTRL_PINMUX_POS) & SAM_PINCTRL_PINMUX_MASK) 144 145 #define SAM_PINMUX_PORT_GET(pincfg) \ 146 ((SAM_PINMUX_GET(pincfg) >> SAM_PINMUX_PORT_POS) \ 147 & SAM_PINMUX_PORT_MSK) 148 149 #define SAM_PINMUX_PIN_GET(pincfg) \ 150 ((SAM_PINMUX_GET(pincfg) >> SAM_PINMUX_PIN_POS) \ 151 & SAM_PINMUX_PIN_MSK) 152 153 #define SAM_PINMUX_FUNC_GET(pincfg) \ 154 ((SAM_PINMUX_GET(pincfg) >> SAM_PINMUX_FUNC_POS) \ 155 & SAM_PINMUX_FUNC_MSK) 156 157 #define SAM_PINMUX_PERIPH_GET(pincfg) \ 158 ((SAM_PINMUX_GET(pincfg) >> SAM_PINMUX_PERIPH_POS) \ 159 & SAM_PINMUX_PERIPH_MSK) 160 161 #endif /* DT_BINDINGS_PINCTRL_ATMEL_SAM_H_ */ 162