blob: b072345159f56d0ed8987b2daa0f1a007832405c [file] [log] [blame]
Yann Gautierd0ca7f42018-07-13 21:33:09 +02001/*
Yann Gautier2b79c372021-06-11 10:54:56 +02002 * Copyright (c) 2015-2021, STMicroelectronics - All Rights Reserved
Yann Gautierd0ca7f42018-07-13 21:33:09 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef STM32_GPIO_H
8#define STM32_GPIO_H
Yann Gautierd0ca7f42018-07-13 21:33:09 +02009
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <lib/utils_def.h>
Yann Gautierd0ca7f42018-07-13 21:33:09 +020011
Yann Gautierd0ca7f42018-07-13 21:33:09 +020012#define GPIO_MODE_OFFSET U(0x00)
13#define GPIO_TYPE_OFFSET U(0x04)
14#define GPIO_SPEED_OFFSET U(0x08)
15#define GPIO_PUPD_OFFSET U(0x0C)
16#define GPIO_BSRR_OFFSET U(0x18)
17#define GPIO_AFRL_OFFSET U(0x20)
18#define GPIO_AFRH_OFFSET U(0x24)
Yann Gautier038bff22019-01-17 19:17:47 +010019#define GPIO_SECR_OFFSET U(0x30)
Yann Gautierd0ca7f42018-07-13 21:33:09 +020020
21#define GPIO_ALT_LOWER_LIMIT U(0x08)
22
Yann Gautier038bff22019-01-17 19:17:47 +010023#define GPIO_PIN_(_x) U(_x)
24#define GPIO_PIN_MAX GPIO_PIN_(15)
Yann Gautierd0ca7f42018-07-13 21:33:09 +020025
Yann Gautier038bff22019-01-17 19:17:47 +010026#define GPIO_ALTERNATE_(_x) U(_x)
Yann Gautierd0ca7f42018-07-13 21:33:09 +020027#define GPIO_ALTERNATE_MASK U(0x0F)
28
29#define GPIO_MODE_INPUT 0x00
30#define GPIO_MODE_OUTPUT 0x01
31#define GPIO_MODE_ALTERNATE 0x02
32#define GPIO_MODE_ANALOG 0x03
33#define GPIO_MODE_MASK U(0x03)
34
35#define GPIO_OPEN_DRAIN U(0x10)
36
37#define GPIO_SPEED_LOW 0x00
38#define GPIO_SPEED_MEDIUM 0x01
Yann Gautier1a3fc9f2019-01-17 14:35:22 +010039#define GPIO_SPEED_HIGH 0x02
40#define GPIO_SPEED_VERY_HIGH 0x03
Yann Gautierd0ca7f42018-07-13 21:33:09 +020041#define GPIO_SPEED_MASK U(0x03)
42
43#define GPIO_NO_PULL 0x00
44#define GPIO_PULL_UP 0x01
45#define GPIO_PULL_DOWN 0x02
46#define GPIO_PULL_MASK U(0x03)
47
Julius Werner53456fc2019-07-09 13:49:11 -070048#ifndef __ASSEMBLER__
Yann Gautierd0ca7f42018-07-13 21:33:09 +020049#include <stdint.h>
50
Yann Gautier038bff22019-01-17 19:17:47 +010051int dt_set_pinctrl_config(int node);
Yann Gautierd0ca7f42018-07-13 21:33:09 +020052void set_gpio(uint32_t bank, uint32_t pin, uint32_t mode, uint32_t speed,
Yann Gautier038bff22019-01-17 19:17:47 +010053 uint32_t pull, uint32_t alternate, uint8_t status);
54void set_gpio_secure_cfg(uint32_t bank, uint32_t pin, bool secure);
Yann Gautier2b79c372021-06-11 10:54:56 +020055void set_gpio_reset_cfg(uint32_t bank, uint32_t pin);
Julius Werner53456fc2019-07-09 13:49:11 -070056#endif /*__ASSEMBLER__*/
Yann Gautierd0ca7f42018-07-13 21:33:09 +020057
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000058#endif /* STM32_GPIO_H */