1 /* 2 * Copyright (c) 2021 Microchip Technology Inc. and its subsidiaries. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _MEC172X_GPIO_H 8 #define _MEC172X_GPIO_H 9 10 #include <stdint.h> 11 #include <stddef.h> 12 13 #if defined(CONFIG_SOC_MEC172X_NSZ) 14 #include "gpio_pkg_sz.h" 15 #elif defined(CONFIG_SOC_MEC172X_NLJ) 16 #include "gpio_pkg_lj.h" 17 #endif 18 19 #define NUM_MCHP_GPIO_PORTS 6u 20 #define MAX_NUM_MCHP_GPIO (NUM_MCHP_GPIO_PORTS * 32u) 21 22 /* GPIO Control register field definitions. */ 23 24 /* bits[1:0] internal pull up/down selection */ 25 #define MCHP_GPIO_CTRL_PUD_POS 0 26 #define MCHP_GPIO_CTRL_PUD_MASK0 0x03u 27 #define MCHP_GPIO_CTRL_PUD_MASK 0x03u 28 #define MCHP_GPIO_CTRL_PUD_NONE 0x00u 29 #define MCHP_GPIO_CTRL_PUD_PU 0x01u 30 #define MCHP_GPIO_CTRL_PUD_PD 0x02u 31 /* Repeater(keeper) mode */ 32 #define MCHP_GPIO_CTRL_PUD_RPT 0x03u 33 34 /* bits[3:2] power gating */ 35 #define MCHP_GPIO_CTRL_PWRG_POS 2 36 #define MCHP_GPIO_CTRL_PWRG_MASK0 0x03u 37 #define MCHP_GPIO_CTRL_PWRG_VTR_IO 0 38 #define MCHP_GPIO_CTRL_PWRG_VCC_IO SHLU32(1, MCHP_GPIO_CTRL_PWRG_POS) 39 #define MCHP_GPIO_CTRL_PWRG_OFF SHLU32(2, MCHP_GPIO_CTRL_PWRG_POS) 40 #define MCHP_GPIO_CTRL_PWRG_RSVD SHLU32(3, MCHP_GPIO_CTRL_PWRG_POS) 41 #define MCHP_GPIO_CTRL_PWRG_MASK SHLU32(3, MCHP_GPIO_CTRL_PWRG_POS) 42 43 /* bits[7:4] interrupt detection mode */ 44 #define MCHP_GPIO_CTRL_IDET_POS 4 45 #define MCHP_GPIO_CTRL_IDET_MASK0 0x0fu 46 #define MCHP_GPIO_CTRL_IDET_LVL_LO 0 47 #define MCHP_GPIO_CTRL_IDET_LVL_HI SHLU32(1, MCHP_GPIO_CTRL_IDET_POS) 48 #define MCHP_GPIO_CTRL_IDET_DISABLE SHLU32(4, MCHP_GPIO_CTRL_IDET_POS) 49 #define MCHP_GPIO_CTRL_IDET_REDGE SHLU32(0xd, MCHP_GPIO_CTRL_IDET_POS) 50 #define MCHP_GPIO_CTRL_IDET_FEDGE SHLU32(0xe, MCHP_GPIO_CTRL_IDET_POS) 51 #define MCHP_GPIO_CTRL_IDET_BEDGE SHLU32(0xf, MCHP_GPIO_CTRL_IDET_POS) 52 #define MCHP_GPIO_CTRL_IDET_MASK SHLU32(0xf, MCHP_GPIO_CTRL_IDET_POS) 53 54 /* bit[8] output buffer type: push-pull or open-drain */ 55 #define MCHP_GPIO_CTRL_BUFT_POS 8 56 #define MCHP_GPIO_CTRL_BUFT_MASK BIT(MCHP_GPIO_CTRL_BUFT_POS) 57 #define MCHP_GPIO_CTRL_BUFT_OPENDRAIN BIT(MCHP_GPIO_CTRL_BUFT_POS) 58 #define MCHP_GPIO_CTRL_BUFT_PUSHPULL 0 59 60 /* bit[9] direction */ 61 #define MCHP_GPIO_CTRL_DIR_POS 9 62 #define MCHP_GPIO_CTRL_DIR_MASK BIT(MCHP_GPIO_CTRL_DIR_POS) 63 #define MCHP_GPIO_CTRL_DIR_OUTPUT BIT(MCHP_GPIO_CTRL_DIR_POS) 64 #define MCHP_GPIO_CTRL_DIR_INPUT 0 65 66 /* 67 * bit[10] Alternate output disable. Default==0(alternate output enabled) 68 * GPIO output value is controlled by bit[16] of this register. 69 * Set bit[10]=1 if you wish to control pin output using the parallel 70 * GPIO output register bit for this pin. 71 */ 72 #define MCHP_GPIO_CTRL_AOD_POS 10 73 #define MCHP_GPIO_CTRL_AOD_MASK BIT(MCHP_GPIO_CTRL_AOD_POS) 74 #define MCHP_GPIO_CTRL_AOD_DIS BIT(MCHP_GPIO_CTRL_AOD_POS) 75 76 /* bit[11] GPIO function output polarity */ 77 #define MCHP_GPIO_CTRL_POL_POS 11 78 #define MCHP_GPIO_CTRL_POL_INVERT BIT(MCHP_GPIO_CTRL_POL_POS) 79 80 /* bits[14:12] pin mux (function) */ 81 #define MCHP_GPIO_CTRL_MUX_POS 12 82 #define MCHP_GPIO_CTRL_MUX_MASK0 0x07u 83 #define MCHP_GPIO_CTRL_MUX_MASK SHLU32(7, MCHP_GPIO_CTRL_MUX_POS) 84 #define MCHP_GPIO_CTRL_MUX_F0 0 85 #define MCHP_GPIO_CTRL_MUX_GPIO MCHP_GPIO_CTRL_MUX_F0 86 #define MCHP_GPIO_CTRL_MUX_F1 SHLU32(1, MCHP_GPIO_CTRL_MUX_POS) 87 #define MCHP_GPIO_CTRL_MUX_F2 SHLU32(2, MCHP_GPIO_CTRL_MUX_POS) 88 #define MCHP_GPIO_CTRL_MUX_F3 SHLU32(3, MCHP_GPIO_CTRL_MUX_POS) 89 #define MCHP_GPIO_CTRL_MUX_F4 SHLU32(4, MCHP_GPIO_CTRL_MUX_POS) 90 #define MCHP_GPIO_CTRL_MUX_F5 SHLU32(5, MCHP_GPIO_CTRL_MUX_POS) 91 #define MCHP_GPIO_CTRL_MUX_F6 SHLU32(6, MCHP_GPIO_CTRL_MUX_POS) 92 #define MCHP_GPIO_CTRL_MUX_F7 SHLU32(7, MCHP_GPIO_CTRL_MUX_POS) 93 #define MCHP_GPIO_CTRL_MUX(n) SHLU32(((n) & 0x7u), MCHP_GPIO_CTRL_MUX_POS) 94 95 /* 96 * bit[15] Disables input pad leaving output pad enabled 97 * Useful for reducing power consumption of output only pins. 98 */ 99 #define MCHP_GPIO_CTRL_INPAD_DIS_POS 15 100 #define MCHP_GPIO_CTRL_INPAD_DIS_MASK BIT(MCHP_GPIO_CTRL_INPAD_DIS_POS) 101 #define MCHP_GPIO_CTRL_INPAD_DIS BIT(MCHP_GPIO_CTRL_INPAD_DIS_POS) 102 103 /* bit[16]: Alternate output pin value. Enabled when bit[10]==0(default) */ 104 #define MCHP_GPIO_CTRL_OUTVAL_POS 16 105 #define MCHP_GPIO_CTRL_OUTV_HI BIT(MCHP_GPIO_CTRL_OUTVAL_POS) 106 107 /* bit[24] Input pad value. Always live unless input pad is powered down */ 108 #define MCHP_GPIO_CTRL_INPAD_VAL_POS 24 109 #define MCHP_GPIO_CTRL_INPAD_VAL_HI BIT(MCHP_GPIO_CTRL_INPAD_VAL_POS) 110 111 #define MCHP_GPIO_CTRL_DRIVE_OD_HI \ 112 (MCHP_GPIO_CTRL_BUFT_OPENDRAIN + MCHP_GPIO_CTRL_DIR_OUTPUT + \ 113 MCHP_GPIO_CTRL_MUX_GPIO + MCHP_GPIO_CTRL_OUTV_HI) 114 115 /* 116 * Each GPIO pin implements a second control register. 117 * GPIO Control 2 register selects pin drive strength and slew rate. 118 * bit[0] = slew rate: 0=slow, 1=fast 119 * bits[5:4] = drive strength 120 * 00b = 2mA (default) 121 * 01b = 4mA 122 * 10b = 8mA 123 * 11b = 12mA 124 */ 125 #define MCHP_GPIO_CTRL2_SLEW_POS 0 126 #define MCHP_GPIO_CTRL2_SLEW_MASK 0x01u 127 #define MCHP_GPIO_CTRL2_SLEW_SLOW 0 128 #define MCHP_GPIO_CTRL2_SLEW_FAST BIT(MCHP_GPIO_CTRL2_SLEW_POS) 129 #define MCHP_GPIO_CTRL2_DRV_STR_POS 4 130 #define MCHP_GPIO_CTRL2_DRV_STR_MASK 0x30u 131 #define MCHP_GPIO_CTRL2_DRV_STR_2MA 0 132 #define MCHP_GPIO_CTRL2_DRV_STR_4MA 0x10u 133 #define MCHP_GPIO_CTRL2_DRV_STR_8MA 0x20u 134 #define MCHP_GPIO_CTRL2_DRV_STR_12MA 0x30u 135 136 /* Interfaces to any C modules */ 137 #ifdef __cplusplus 138 extern "C" { 139 #endif 140 141 #define MCHP_GPIO_PIN2PORT(pin_id) ((uint32_t)(pin_id) >> 5) 142 143 /* Helper functions */ 144 enum mchp_gpio_pud { 145 MCHP_GPIO_NO_PUD = 0, 146 MCHP_GPIO_PU_EN, 147 MCHP_GPIO_PD_EN, 148 MCHP_GPIO_RPT_EN, 149 }; 150 151 enum mchp_gpio_pwrgate { 152 MCHP_GPIO_PWRGT_VTR = 0, 153 MCHP_GPIO_PWRGT_VCC, 154 MCHP_GPIO_PWRGD_OFF, 155 }; 156 157 enum mchp_gpio_idet { 158 MCHP_GPIO_IDET_LO_LVL = 0u, 159 MCHP_GPIO_IDET_HI_LVL = 0x01u, 160 MCHP_GPIO_IDET_DIS = 0x04u, 161 MCHP_GPIO_IDET_RISING_EDGE = 0x0du, 162 MCHP_GPIO_IDET_FALLING_EDGE = 0x0eu, 163 MCHP_GPIO_IDET_BOTH_EDGES = 0x0fu 164 }; 165 166 enum mchp_gpio_outbuf { 167 MCHP_GPIO_PUSH_PULL = 0, 168 MCHP_GPIO_OPEN_DRAIN, 169 }; 170 171 enum mchp_gpio_dir { 172 MCHP_GPIO_DIR_IN = 0, 173 MCHP_GPIO_DIR_OUT, 174 }; 175 176 enum mchp_gpio_parout_en { 177 MCHP_GPIO_PAROUT_DIS = 0, 178 MCHP_GPIO_PAROUT_EN, 179 }; 180 181 enum mchp_gpio_pol { 182 MCHP_GPIO_POL_NORM = 0, 183 MCHP_GPIO_POL_INV, 184 }; 185 186 enum mchp_gpio_mux { 187 MCHP_GPIO_MUX_GPIO = 0u, 188 MCHP_GPIO_MUX_FUNC1, 189 MCHP_GPIO_MUX_FUNC2, 190 MCHP_GPIO_MUX_FUNC3, 191 MCHP_GPIO_MUX_FUNC4, 192 MCHP_GPIO_MUX_FUNC5, 193 MCHP_GPIO_MUX_FUNC6, 194 MCHP_GPIO_MUX_FUNC7, 195 MCHP_GPIO_MUX_MAX 196 }; 197 198 enum mchp_gpio_inpad_ctrl { 199 MCHP_GPIO_INPAD_CTRL_EN = 0, 200 MCHP_GPIO_INPAD_CTRL_DIS, 201 }; 202 203 enum mchp_gpio_alt_out { 204 MCHP_GPIO_ALT_OUT_LO = 0, 205 MCHP_GPIO_ALT_OUT_HI, 206 }; 207 208 enum mchp_gpio_slew { 209 MCHP_GPIO_SLEW_SLOW = 0, 210 MCHP_GPIO_SLEW_FAST, 211 }; 212 213 enum mchp_gpio_drv_str { 214 MCHP_GPIO_DRV_STR_2MA = 0, 215 MCHP_GPIO_DRV_STR_4MA, 216 MCHP_GPIO_DRV_STR_8MA, 217 MCHP_GPIO_DRV_STR_12MA, 218 }; 219 220 #ifdef __cplusplus 221 } 222 #endif 223 224 #endif /* #ifndef _MEC172X_GPIO_H */ 225