blob: 7a0f2935190dcbfccfd76f6c4d5ae86b6abb28af [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Patrick Delaunay85b53972018-03-12 10:46:10 +01002/*
3 * (C) Copyright 2016
4 * Vikas Manocha, <vikas.manocha@st.com>
Patrick Delaunay85b53972018-03-12 10:46:10 +01005 */
6
7#ifndef _STM32_GPIO_H_
8#define _STM32_GPIO_H_
9#include <asm/gpio.h>
10
Patrick Delaunay85b53972018-03-12 10:46:10 +010011enum stm32_gpio_mode {
12 STM32_GPIO_MODE_IN = 0,
13 STM32_GPIO_MODE_OUT,
14 STM32_GPIO_MODE_AF,
15 STM32_GPIO_MODE_AN
16};
17
18enum stm32_gpio_otype {
19 STM32_GPIO_OTYPE_PP = 0,
20 STM32_GPIO_OTYPE_OD
21};
22
23enum stm32_gpio_speed {
24 STM32_GPIO_SPEED_2M = 0,
25 STM32_GPIO_SPEED_25M,
26 STM32_GPIO_SPEED_50M,
27 STM32_GPIO_SPEED_100M
28};
29
30enum stm32_gpio_pupd {
31 STM32_GPIO_PUPD_NO = 0,
32 STM32_GPIO_PUPD_UP,
33 STM32_GPIO_PUPD_DOWN
34};
35
36enum stm32_gpio_af {
37 STM32_GPIO_AF0 = 0,
38 STM32_GPIO_AF1,
39 STM32_GPIO_AF2,
40 STM32_GPIO_AF3,
41 STM32_GPIO_AF4,
42 STM32_GPIO_AF5,
43 STM32_GPIO_AF6,
44 STM32_GPIO_AF7,
45 STM32_GPIO_AF8,
46 STM32_GPIO_AF9,
47 STM32_GPIO_AF10,
48 STM32_GPIO_AF11,
49 STM32_GPIO_AF12,
50 STM32_GPIO_AF13,
51 STM32_GPIO_AF14,
52 STM32_GPIO_AF15
53};
54
55struct stm32_gpio_dsc {
Patrick Delaunaycf6da852020-10-02 14:08:54 +020056 u8 port;
57 u8 pin;
Patrick Delaunay85b53972018-03-12 10:46:10 +010058};
59
60struct stm32_gpio_ctl {
61 enum stm32_gpio_mode mode;
62 enum stm32_gpio_otype otype;
63 enum stm32_gpio_speed speed;
64 enum stm32_gpio_pupd pupd;
65 enum stm32_gpio_af af;
66};
67
68struct stm32_gpio_regs {
69 u32 moder; /* GPIO port mode */
70 u32 otyper; /* GPIO port output type */
71 u32 ospeedr; /* GPIO port output speed */
72 u32 pupdr; /* GPIO port pull-up/pull-down */
73 u32 idr; /* GPIO port input data */
74 u32 odr; /* GPIO port output data */
75 u32 bsrr; /* GPIO port bit set/reset */
76 u32 lckr; /* GPIO port configuration lock */
77 u32 afr[2]; /* GPIO alternate function */
78};
79
80struct stm32_gpio_priv {
81 struct stm32_gpio_regs *regs;
Patrice Chotard0099c1e2018-12-03 10:52:51 +010082 unsigned int gpio_range;
Patrick Delaunay85b53972018-03-12 10:46:10 +010083};
Patrice Chotard0099c1e2018-12-03 10:52:51 +010084
85int stm32_offset_to_index(struct udevice *dev, unsigned int offset);
86
Patrick Delaunay85b53972018-03-12 10:46:10 +010087#endif /* _STM32_GPIO_H_ */