blob: ef4eb04a22e489dcec39b22186cacb5b35c1e100 [file] [log] [blame]
Yann Gautierd0ca7f42018-07-13 21:33:09 +02001/*
Pascal Paillet28346412022-02-17 17:22:04 +01002 * Copyright (c) 2015-2024, 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)
Pascal Paillet28346412022-02-17 17:22:04 +010016#define GPIO_IDR_OFFSET U(0x10)
Fabien Dessennefc51b232021-09-21 14:18:34 +020017#define GPIO_OD_OFFSET U(0x14)
Yann Gautierd0ca7f42018-07-13 21:33:09 +020018#define GPIO_BSRR_OFFSET U(0x18)
19#define GPIO_AFRL_OFFSET U(0x20)
20#define GPIO_AFRH_OFFSET U(0x24)
Yann Gautier038bff22019-01-17 19:17:47 +010021#define GPIO_SECR_OFFSET U(0x30)
Yann Gautierd0ca7f42018-07-13 21:33:09 +020022
23#define GPIO_ALT_LOWER_LIMIT U(0x08)
24
Yann Gautier038bff22019-01-17 19:17:47 +010025#define GPIO_PIN_(_x) U(_x)
26#define GPIO_PIN_MAX GPIO_PIN_(15)
Yann Gautierd0ca7f42018-07-13 21:33:09 +020027
Yann Gautier038bff22019-01-17 19:17:47 +010028#define GPIO_ALTERNATE_(_x) U(_x)
Yann Gautierd0ca7f42018-07-13 21:33:09 +020029#define GPIO_ALTERNATE_MASK U(0x0F)
30
Fabien Dessenne83969cf2021-09-21 11:05:06 +020031#define GPIO_MODE_INPUT U(0x00)
32#define GPIO_MODE_OUTPUT U(0x01)
33#define GPIO_MODE_ALTERNATE U(0x02)
34#define GPIO_MODE_ANALOG U(0x03)
Yann Gautierd0ca7f42018-07-13 21:33:09 +020035#define GPIO_MODE_MASK U(0x03)
36
Fabien Dessenne83969cf2021-09-21 11:05:06 +020037#define GPIO_TYPE_PUSH_PULL U(0x00)
38#define GPIO_TYPE_OPEN_DRAIN U(0x01)
39#define GPIO_TYPE_MASK U(0x01)
Yann Gautierd0ca7f42018-07-13 21:33:09 +020040
Fabien Dessenne83969cf2021-09-21 11:05:06 +020041#define GPIO_SPEED_LOW U(0x00)
42#define GPIO_SPEED_MEDIUM U(0x01)
43#define GPIO_SPEED_HIGH U(0x02)
44#define GPIO_SPEED_VERY_HIGH U(0x03)
Yann Gautierd0ca7f42018-07-13 21:33:09 +020045#define GPIO_SPEED_MASK U(0x03)
46
Fabien Dessenne83969cf2021-09-21 11:05:06 +020047#define GPIO_NO_PULL U(0x00)
48#define GPIO_PULL_UP U(0x01)
49#define GPIO_PULL_DOWN U(0x02)
Yann Gautierd0ca7f42018-07-13 21:33:09 +020050#define GPIO_PULL_MASK U(0x03)
51
Fabien Dessennefc51b232021-09-21 14:18:34 +020052#define GPIO_OD_OUTPUT_LOW U(0x00)
53#define GPIO_OD_OUTPUT_HIGH U(0x01)
54#define GPIO_OD_MASK U(0x01)
55
Julius Werner53456fc2019-07-09 13:49:11 -070056#ifndef __ASSEMBLER__
Yann Gautierd0ca7f42018-07-13 21:33:09 +020057#include <stdint.h>
58
Yann Gautier038bff22019-01-17 19:17:47 +010059int dt_set_pinctrl_config(int node);
Yann Gautier038bff22019-01-17 19:17:47 +010060void set_gpio_secure_cfg(uint32_t bank, uint32_t pin, bool secure);
Yann Gautier2b79c372021-06-11 10:54:56 +020061void set_gpio_reset_cfg(uint32_t bank, uint32_t pin);
Pascal Paillet28346412022-02-17 17:22:04 +010062
63enum gpio_level {
64 GPIO_LEVEL_LOW,
65 GPIO_LEVEL_HIGH
66};
67
68void set_gpio_level(uint32_t bank, uint32_t pin, enum gpio_level level);
69enum gpio_level get_gpio_level(uint32_t bank, uint32_t pin);
70
71void set_gpio_config(uint32_t bank, uint32_t pin, uint32_t config, uint8_t status);
Julius Werner53456fc2019-07-09 13:49:11 -070072#endif /*__ASSEMBLER__*/
Yann Gautierd0ca7f42018-07-13 21:33:09 +020073
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000074#endif /* STM32_GPIO_H */