Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 1 | /* |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 2 | * Copyright (c) 2016-2022, STMicroelectronics - All Rights Reserved |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 7 | #include <assert.h> |
| 8 | #include <errno.h> |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 9 | #include <stdbool.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | |
| 11 | #include <common/bl_common.h> |
| 12 | #include <common/debug.h> |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 13 | #include <drivers/clk.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 14 | #include <drivers/st/stm32_gpio.h> |
Yann Gautier | 4d42947 | 2019-02-14 11:15:20 +0100 | [diff] [blame] | 15 | #include <drivers/st/stm32mp_clkfunc.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 16 | #include <lib/mmio.h> |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 17 | #include <lib/utils_def.h> |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 18 | #include <libfdt.h> |
| 19 | |
| 20 | #include <platform_def.h> |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 21 | |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 22 | #define DT_GPIO_BANK_SHIFT 12 |
| 23 | #define DT_GPIO_BANK_MASK GENMASK(16, 12) |
| 24 | #define DT_GPIO_PIN_SHIFT 8 |
| 25 | #define DT_GPIO_PIN_MASK GENMASK(11, 8) |
| 26 | #define DT_GPIO_MODE_MASK GENMASK(7, 0) |
| 27 | |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 28 | static void set_gpio(uint32_t bank, uint32_t pin, uint32_t mode, uint32_t type, |
Fabien Dessenne | fc51b23 | 2021-09-21 14:18:34 +0200 | [diff] [blame] | 29 | uint32_t speed, uint32_t pull, uint32_t od, |
| 30 | uint32_t alternate, uint8_t status); |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 31 | |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 32 | /******************************************************************************* |
| 33 | * This function gets GPIO bank node in DT. |
| 34 | * Returns node offset if status is okay in DT, else return 0 |
| 35 | ******************************************************************************/ |
| 36 | static int ckeck_gpio_bank(void *fdt, uint32_t bank, int pinctrl_node) |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 37 | { |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 38 | int pinctrl_subnode; |
| 39 | uint32_t bank_offset = stm32_get_gpio_bank_offset(bank); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 40 | |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 41 | fdt_for_each_subnode(pinctrl_subnode, fdt, pinctrl_node) { |
| 42 | const fdt32_t *cuint; |
| 43 | |
| 44 | if (fdt_getprop(fdt, pinctrl_subnode, |
| 45 | "gpio-controller", NULL) == NULL) { |
| 46 | continue; |
| 47 | } |
| 48 | |
| 49 | cuint = fdt_getprop(fdt, pinctrl_subnode, "reg", NULL); |
| 50 | if (cuint == NULL) { |
| 51 | continue; |
| 52 | } |
| 53 | |
| 54 | if ((fdt32_to_cpu(*cuint) == bank_offset) && |
| 55 | (fdt_get_status(pinctrl_subnode) != DT_DISABLED)) { |
| 56 | return pinctrl_subnode; |
| 57 | } |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 58 | } |
| 59 | |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 60 | return 0; |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 61 | } |
| 62 | |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 63 | /******************************************************************************* |
| 64 | * This function gets the pin settings from DT information. |
| 65 | * When analyze and parsing is done, set the GPIO registers. |
| 66 | * Returns 0 on success and a negative FDT error code on failure. |
| 67 | ******************************************************************************/ |
| 68 | static int dt_set_gpio_config(void *fdt, int node, uint8_t status) |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 69 | { |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 70 | const fdt32_t *cuint, *slewrate; |
| 71 | int len; |
| 72 | int pinctrl_node; |
| 73 | uint32_t i; |
| 74 | uint32_t speed = GPIO_SPEED_LOW; |
| 75 | uint32_t pull = GPIO_NO_PULL; |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 76 | |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 77 | cuint = fdt_getprop(fdt, node, "pinmux", &len); |
| 78 | if (cuint == NULL) { |
| 79 | return -FDT_ERR_NOTFOUND; |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 80 | } |
| 81 | |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 82 | pinctrl_node = fdt_parent_offset(fdt, fdt_parent_offset(fdt, node)); |
| 83 | if (pinctrl_node < 0) { |
| 84 | return -FDT_ERR_NOTFOUND; |
| 85 | } |
| 86 | |
| 87 | slewrate = fdt_getprop(fdt, node, "slew-rate", NULL); |
| 88 | if (slewrate != NULL) { |
| 89 | speed = fdt32_to_cpu(*slewrate); |
| 90 | } |
| 91 | |
| 92 | if (fdt_getprop(fdt, node, "bias-pull-up", NULL) != NULL) { |
| 93 | pull = GPIO_PULL_UP; |
| 94 | } else if (fdt_getprop(fdt, node, "bias-pull-down", NULL) != NULL) { |
| 95 | pull = GPIO_PULL_DOWN; |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 96 | } else { |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 97 | VERBOSE("No bias configured in node %d\n", node); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 98 | } |
| 99 | |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 100 | for (i = 0U; i < ((uint32_t)len / sizeof(uint32_t)); i++) { |
| 101 | uint32_t pincfg; |
| 102 | uint32_t bank; |
| 103 | uint32_t pin; |
| 104 | uint32_t mode; |
| 105 | uint32_t alternate = GPIO_ALTERNATE_(0); |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 106 | uint32_t type; |
Fabien Dessenne | fc51b23 | 2021-09-21 14:18:34 +0200 | [diff] [blame] | 107 | uint32_t od = GPIO_OD_OUTPUT_LOW; |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 108 | int bank_node; |
| 109 | int clk; |
| 110 | |
| 111 | pincfg = fdt32_to_cpu(*cuint); |
| 112 | cuint++; |
| 113 | |
| 114 | bank = (pincfg & DT_GPIO_BANK_MASK) >> DT_GPIO_BANK_SHIFT; |
| 115 | |
| 116 | pin = (pincfg & DT_GPIO_PIN_MASK) >> DT_GPIO_PIN_SHIFT; |
| 117 | |
| 118 | mode = pincfg & DT_GPIO_MODE_MASK; |
| 119 | |
| 120 | switch (mode) { |
| 121 | case 0: |
| 122 | mode = GPIO_MODE_INPUT; |
| 123 | break; |
| 124 | case 1 ... 16: |
| 125 | alternate = mode - 1U; |
| 126 | mode = GPIO_MODE_ALTERNATE; |
| 127 | break; |
| 128 | case 17: |
| 129 | mode = GPIO_MODE_ANALOG; |
| 130 | break; |
| 131 | default: |
| 132 | mode = GPIO_MODE_OUTPUT; |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | if (fdt_getprop(fdt, node, "drive-open-drain", NULL) != NULL) { |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 137 | type = GPIO_TYPE_OPEN_DRAIN; |
| 138 | } else { |
| 139 | type = GPIO_TYPE_PUSH_PULL; |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Fabien Dessenne | fc51b23 | 2021-09-21 14:18:34 +0200 | [diff] [blame] | 142 | if (fdt_getprop(fdt, node, "output-high", NULL) != NULL) { |
| 143 | if (mode == GPIO_MODE_INPUT) { |
| 144 | mode = GPIO_MODE_OUTPUT; |
| 145 | od = GPIO_OD_OUTPUT_HIGH; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | if (fdt_getprop(fdt, node, "output-low", NULL) != NULL) { |
| 150 | if (mode == GPIO_MODE_INPUT) { |
| 151 | mode = GPIO_MODE_OUTPUT; |
| 152 | od = GPIO_OD_OUTPUT_LOW; |
| 153 | } |
| 154 | } |
| 155 | |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 156 | bank_node = ckeck_gpio_bank(fdt, bank, pinctrl_node); |
| 157 | if (bank_node == 0) { |
| 158 | ERROR("PINCTRL inconsistent in DT\n"); |
| 159 | panic(); |
| 160 | } |
| 161 | |
| 162 | clk = fdt_get_clock_id(bank_node); |
| 163 | if (clk < 0) { |
| 164 | return -FDT_ERR_NOTFOUND; |
| 165 | } |
| 166 | |
| 167 | /* Platform knows the clock: assert it is okay */ |
| 168 | assert((unsigned long)clk == stm32_get_gpio_bank_clock(bank)); |
| 169 | |
Fabien Dessenne | fc51b23 | 2021-09-21 14:18:34 +0200 | [diff] [blame] | 170 | set_gpio(bank, pin, mode, type, speed, pull, od, alternate, status); |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | /******************************************************************************* |
| 177 | * This function gets the pin settings from DT information. |
| 178 | * When analyze and parsing is done, set the GPIO registers. |
| 179 | * Returns 0 on success and a negative FDT/ERRNO error code on failure. |
| 180 | ******************************************************************************/ |
| 181 | int dt_set_pinctrl_config(int node) |
| 182 | { |
| 183 | const fdt32_t *cuint; |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 184 | int lenp; |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 185 | uint32_t i; |
Yann Gautier | 2e002b0 | 2020-09-04 13:25:27 +0200 | [diff] [blame] | 186 | uint8_t status; |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 187 | void *fdt; |
| 188 | |
| 189 | if (fdt_get_address(&fdt) == 0) { |
Nicolas Le Bayon | c5c6945 | 2019-09-11 15:58:31 +0200 | [diff] [blame] | 190 | return -FDT_ERR_NOTFOUND; |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Yann Gautier | 2e002b0 | 2020-09-04 13:25:27 +0200 | [diff] [blame] | 193 | status = fdt_get_status(node); |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 194 | if (status == DT_DISABLED) { |
| 195 | return -FDT_ERR_NOTFOUND; |
| 196 | } |
| 197 | |
| 198 | cuint = fdt_getprop(fdt, node, "pinctrl-0", &lenp); |
| 199 | if (cuint == NULL) { |
| 200 | return -FDT_ERR_NOTFOUND; |
| 201 | } |
| 202 | |
| 203 | for (i = 0; i < ((uint32_t)lenp / 4U); i++) { |
| 204 | int p_node, p_subnode; |
| 205 | |
| 206 | p_node = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*cuint)); |
| 207 | if (p_node < 0) { |
| 208 | return -FDT_ERR_NOTFOUND; |
| 209 | } |
| 210 | |
| 211 | fdt_for_each_subnode(p_subnode, fdt, p_node) { |
| 212 | int ret = dt_set_gpio_config(fdt, p_subnode, status); |
| 213 | |
| 214 | if (ret < 0) { |
| 215 | return ret; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | cuint++; |
| 220 | } |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 225 | static void set_gpio(uint32_t bank, uint32_t pin, uint32_t mode, uint32_t type, |
Fabien Dessenne | fc51b23 | 2021-09-21 14:18:34 +0200 | [diff] [blame] | 226 | uint32_t speed, uint32_t pull, uint32_t od, |
| 227 | uint32_t alternate, uint8_t status) |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 228 | { |
| 229 | uintptr_t base = stm32_get_gpio_bank_base(bank); |
| 230 | unsigned long clock = stm32_get_gpio_bank_clock(bank); |
| 231 | |
| 232 | assert(pin <= GPIO_PIN_MAX); |
| 233 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 234 | clk_enable(clock); |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 235 | |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 236 | mmio_clrsetbits_32(base + GPIO_MODE_OFFSET, |
Yann Gautier | fca59e0 | 2022-11-25 10:56:25 +0100 | [diff] [blame] | 237 | (uint32_t)GPIO_MODE_MASK << (pin << 1U), |
| 238 | mode << (pin << 1U)); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 239 | |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 240 | mmio_clrsetbits_32(base + GPIO_TYPE_OFFSET, |
| 241 | (uint32_t)GPIO_TYPE_MASK << pin, |
| 242 | type << pin); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 243 | |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 244 | mmio_clrsetbits_32(base + GPIO_SPEED_OFFSET, |
Yann Gautier | fca59e0 | 2022-11-25 10:56:25 +0100 | [diff] [blame] | 245 | (uint32_t)GPIO_SPEED_MASK << (pin << 1U), |
| 246 | speed << (pin << 1U)); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 247 | |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 248 | mmio_clrsetbits_32(base + GPIO_PUPD_OFFSET, |
Yann Gautier | fca59e0 | 2022-11-25 10:56:25 +0100 | [diff] [blame] | 249 | (uint32_t)GPIO_PULL_MASK << (pin << 1U), |
| 250 | pull << (pin << 1U)); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 251 | |
| 252 | if (pin < GPIO_ALT_LOWER_LIMIT) { |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 253 | mmio_clrsetbits_32(base + GPIO_AFRL_OFFSET, |
Yann Gautier | fca59e0 | 2022-11-25 10:56:25 +0100 | [diff] [blame] | 254 | (uint32_t)GPIO_ALTERNATE_MASK << (pin << 2U), |
| 255 | alternate << (pin << 2U)); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 256 | } else { |
Yann Gautier | fca59e0 | 2022-11-25 10:56:25 +0100 | [diff] [blame] | 257 | uint32_t shift = (pin - GPIO_ALT_LOWER_LIMIT) << 2U; |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 258 | |
| 259 | mmio_clrsetbits_32(base + GPIO_AFRH_OFFSET, |
| 260 | (uint32_t)GPIO_ALTERNATE_MASK << shift, |
| 261 | alternate << shift); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 262 | } |
| 263 | |
Fabien Dessenne | fc51b23 | 2021-09-21 14:18:34 +0200 | [diff] [blame] | 264 | mmio_clrsetbits_32(base + GPIO_OD_OFFSET, |
| 265 | (uint32_t)GPIO_OD_MASK << pin, |
| 266 | od << pin); |
| 267 | |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 268 | VERBOSE("GPIO %u mode set to 0x%x\n", bank, |
Yann Gautier | 1a3fc9f | 2019-01-17 14:35:22 +0100 | [diff] [blame] | 269 | mmio_read_32(base + GPIO_MODE_OFFSET)); |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 270 | VERBOSE("GPIO %u type set to 0x%x\n", bank, |
| 271 | mmio_read_32(base + GPIO_TYPE_OFFSET)); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 272 | VERBOSE("GPIO %u speed set to 0x%x\n", bank, |
Yann Gautier | 1a3fc9f | 2019-01-17 14:35:22 +0100 | [diff] [blame] | 273 | mmio_read_32(base + GPIO_SPEED_OFFSET)); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 274 | VERBOSE("GPIO %u mode pull to 0x%x\n", bank, |
Yann Gautier | 1a3fc9f | 2019-01-17 14:35:22 +0100 | [diff] [blame] | 275 | mmio_read_32(base + GPIO_PUPD_OFFSET)); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 276 | VERBOSE("GPIO %u mode alternate low to 0x%x\n", bank, |
Yann Gautier | 1a3fc9f | 2019-01-17 14:35:22 +0100 | [diff] [blame] | 277 | mmio_read_32(base + GPIO_AFRL_OFFSET)); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 278 | VERBOSE("GPIO %u mode alternate high to 0x%x\n", bank, |
Yann Gautier | 1a3fc9f | 2019-01-17 14:35:22 +0100 | [diff] [blame] | 279 | mmio_read_32(base + GPIO_AFRH_OFFSET)); |
Fabien Dessenne | fc51b23 | 2021-09-21 14:18:34 +0200 | [diff] [blame] | 280 | VERBOSE("GPIO %u output data set to 0x%x\n", bank, |
| 281 | mmio_read_32(base + GPIO_OD_OFFSET)); |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 282 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 283 | clk_disable(clock); |
Etienne Carriere | 3018921 | 2019-12-02 10:11:32 +0100 | [diff] [blame] | 284 | |
| 285 | if (status == DT_SECURE) { |
| 286 | stm32mp_register_secure_gpio(bank, pin); |
Yann Gautier | 8b6ed59 | 2020-08-11 14:21:41 +0200 | [diff] [blame] | 287 | #if !IMAGE_BL2 |
Etienne Carriere | 3018921 | 2019-12-02 10:11:32 +0100 | [diff] [blame] | 288 | set_gpio_secure_cfg(bank, pin, true); |
Yann Gautier | 8b6ed59 | 2020-08-11 14:21:41 +0200 | [diff] [blame] | 289 | #endif |
Etienne Carriere | 3018921 | 2019-12-02 10:11:32 +0100 | [diff] [blame] | 290 | |
| 291 | } else { |
| 292 | stm32mp_register_non_secure_gpio(bank, pin); |
Yann Gautier | 8b6ed59 | 2020-08-11 14:21:41 +0200 | [diff] [blame] | 293 | #if !IMAGE_BL2 |
Etienne Carriere | 3018921 | 2019-12-02 10:11:32 +0100 | [diff] [blame] | 294 | set_gpio_secure_cfg(bank, pin, false); |
Yann Gautier | 8b6ed59 | 2020-08-11 14:21:41 +0200 | [diff] [blame] | 295 | #endif |
Etienne Carriere | 3018921 | 2019-12-02 10:11:32 +0100 | [diff] [blame] | 296 | } |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | void set_gpio_secure_cfg(uint32_t bank, uint32_t pin, bool secure) |
| 300 | { |
| 301 | uintptr_t base = stm32_get_gpio_bank_base(bank); |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 302 | unsigned long clock = stm32_get_gpio_bank_clock(bank); |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 303 | |
| 304 | assert(pin <= GPIO_PIN_MAX); |
| 305 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 306 | clk_enable(clock); |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 307 | |
| 308 | if (secure) { |
| 309 | mmio_setbits_32(base + GPIO_SECR_OFFSET, BIT(pin)); |
| 310 | } else { |
| 311 | mmio_clrbits_32(base + GPIO_SECR_OFFSET, BIT(pin)); |
| 312 | } |
| 313 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 314 | clk_disable(clock); |
Yann Gautier | d0ca7f4 | 2018-07-13 21:33:09 +0200 | [diff] [blame] | 315 | } |
Yann Gautier | 2b79c37 | 2021-06-11 10:54:56 +0200 | [diff] [blame] | 316 | |
| 317 | void set_gpio_reset_cfg(uint32_t bank, uint32_t pin) |
| 318 | { |
Fabien Dessenne | 83969cf | 2021-09-21 11:05:06 +0200 | [diff] [blame] | 319 | set_gpio(bank, pin, GPIO_MODE_ANALOG, GPIO_TYPE_PUSH_PULL, |
Fabien Dessenne | fc51b23 | 2021-09-21 14:18:34 +0200 | [diff] [blame] | 320 | GPIO_SPEED_LOW, GPIO_NO_PULL, GPIO_OD_OUTPUT_LOW, |
| 321 | GPIO_ALTERNATE_(0), DT_DISABLED); |
Yann Gautier | 2b79c37 | 2021-06-11 10:54:56 +0200 | [diff] [blame] | 322 | set_gpio_secure_cfg(bank, pin, stm32_gpio_is_secure_at_reset(bank)); |
| 323 | } |