blob: 45999b4d2e34761083ae094fa5e0680053f9cb46 [file] [log] [blame]
Vikas Manocha1b51c932016-02-11 15:47:20 -08001/*
2 * (C) Copyright 2016
3 * Vikas Manocha, <vikas.manocha@st.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#ifndef _STM32_GPIO_H_
9#define _STM32_GPIO_H_
10
11enum stm32_gpio_port {
12 STM32_GPIO_PORT_A = 0,
13 STM32_GPIO_PORT_B,
14 STM32_GPIO_PORT_C,
15 STM32_GPIO_PORT_D,
16 STM32_GPIO_PORT_E,
17 STM32_GPIO_PORT_F,
18 STM32_GPIO_PORT_G,
19 STM32_GPIO_PORT_H,
20 STM32_GPIO_PORT_I
21};
22
23enum stm32_gpio_pin {
24 STM32_GPIO_PIN_0 = 0,
25 STM32_GPIO_PIN_1,
26 STM32_GPIO_PIN_2,
27 STM32_GPIO_PIN_3,
28 STM32_GPIO_PIN_4,
29 STM32_GPIO_PIN_5,
30 STM32_GPIO_PIN_6,
31 STM32_GPIO_PIN_7,
32 STM32_GPIO_PIN_8,
33 STM32_GPIO_PIN_9,
34 STM32_GPIO_PIN_10,
35 STM32_GPIO_PIN_11,
36 STM32_GPIO_PIN_12,
37 STM32_GPIO_PIN_13,
38 STM32_GPIO_PIN_14,
39 STM32_GPIO_PIN_15
40};
41
42enum stm32_gpio_mode {
43 STM32_GPIO_MODE_IN = 0,
44 STM32_GPIO_MODE_OUT,
45 STM32_GPIO_MODE_AF,
46 STM32_GPIO_MODE_AN
47};
48
49enum stm32_gpio_otype {
50 STM32_GPIO_OTYPE_PP = 0,
51 STM32_GPIO_OTYPE_OD
52};
53
54enum stm32_gpio_speed {
55 STM32_GPIO_SPEED_2M = 0,
56 STM32_GPIO_SPEED_25M,
57 STM32_GPIO_SPEED_50M,
58 STM32_GPIO_SPEED_100M
59};
60
61enum stm32_gpio_pupd {
62 STM32_GPIO_PUPD_NO = 0,
63 STM32_GPIO_PUPD_UP,
64 STM32_GPIO_PUPD_DOWN
65};
66
67enum stm32_gpio_af {
68 STM32_GPIO_AF0 = 0,
69 STM32_GPIO_AF1,
70 STM32_GPIO_AF2,
71 STM32_GPIO_AF3,
72 STM32_GPIO_AF4,
73 STM32_GPIO_AF5,
74 STM32_GPIO_AF6,
75 STM32_GPIO_AF7,
76 STM32_GPIO_AF8,
77 STM32_GPIO_AF9,
78 STM32_GPIO_AF10,
79 STM32_GPIO_AF11,
80 STM32_GPIO_AF12,
81 STM32_GPIO_AF13,
82 STM32_GPIO_AF14,
83 STM32_GPIO_AF15
84};
85
86struct stm32_gpio_dsc {
87 enum stm32_gpio_port port;
88 enum stm32_gpio_pin pin;
89};
90
91struct stm32_gpio_ctl {
92 enum stm32_gpio_mode mode;
93 enum stm32_gpio_otype otype;
94 enum stm32_gpio_speed speed;
95 enum stm32_gpio_pupd pupd;
96 enum stm32_gpio_af af;
97};
98
Vikas Manochaec8630a2017-04-10 15:02:57 -070099struct stm32_gpio_regs {
100 u32 moder; /* GPIO port mode */
101 u32 otyper; /* GPIO port output type */
102 u32 ospeedr; /* GPIO port output speed */
103 u32 pupdr; /* GPIO port pull-up/pull-down */
104 u32 idr; /* GPIO port input data */
105 u32 odr; /* GPIO port output data */
106 u32 bsrr; /* GPIO port bit set/reset */
107 u32 lckr; /* GPIO port configuration lock */
108 u32 afr[2]; /* GPIO alternate function */
109};
110
111struct stm32_gpio_priv {
112 struct stm32_gpio_regs *regs;
113};
114
Vikas Manocha1b51c932016-02-11 15:47:20 -0800115static inline unsigned stm32_gpio_to_port(unsigned gpio)
116{
117 return gpio / 16;
118}
119
120static inline unsigned stm32_gpio_to_pin(unsigned gpio)
121{
122 return gpio % 16;
123}
124
Vikas Manocha1b51c932016-02-11 15:47:20 -0800125#endif /* _STM32_GPIO_H_ */