blob: 6173fa130000c3808fb7fe5d0c110d288110aede [file] [log] [blame]
rev13@wp.plfec465a2015-03-01 12:44:40 +01001/*
2 * (C) Copyright 2011
3 * Yuri Tikhonov, Emcraft Systems, yur@emcraft.com
4 *
5 * (C) Copyright 2015
Kamil Lulkodecd33b2015-11-29 11:50:53 +01006 * Kamil Lulko, <kamil.lulko@gmail.com>
rev13@wp.plfec465a2015-03-01 12:44:40 +01007 *
8 * SPDX-License-Identifier: GPL-2.0+
9 */
10
11#ifndef _STM32_GPIO_H_
12#define _STM32_GPIO_H_
13
kunhuahuang48482ce2015-04-28 03:01:19 +080014#if (CONFIG_STM32_USART == 1)
15#define STM32_GPIO_PORT_X STM32_GPIO_PORT_A
16#define STM32_GPIO_PIN_TX STM32_GPIO_PIN_9
17#define STM32_GPIO_PIN_RX STM32_GPIO_PIN_10
18#define STM32_GPIO_USART STM32_GPIO_AF7
19
20#elif (CONFIG_STM32_USART == 2)
21#define STM32_GPIO_PORT_X STM32_GPIO_PORT_D
22#define STM32_GPIO_PIN_TX STM32_GPIO_PIN_5
23#define STM32_GPIO_PIN_RX STM32_GPIO_PIN_6
24#define STM32_GPIO_USART STM32_GPIO_AF7
25
26#elif (CONFIG_STM32_USART == 3)
27#define STM32_GPIO_PORT_X STM32_GPIO_PORT_C
28#define STM32_GPIO_PIN_TX STM32_GPIO_PIN_10
29#define STM32_GPIO_PIN_RX STM32_GPIO_PIN_11
30#define STM32_GPIO_USART STM32_GPIO_AF7
31
32#elif (CONFIG_STM32_USART == 6)
33#define STM32_GPIO_PORT_X STM32_GPIO_PORT_G
34#define STM32_GPIO_PIN_TX STM32_GPIO_PIN_14
35#define STM32_GPIO_PIN_RX STM32_GPIO_PIN_9
36#define STM32_GPIO_USART STM32_GPIO_AF8
37
38#else
39#define STM32_GPIO_PORT_X STM32_GPIO_PORT_A
40#define STM32_GPIO_PIN_TX STM32_GPIO_PIN_9
41#define STM32_GPIO_PIN_RX STM32_GPIO_PIN_10
42#define STM32_GPIO_USART STM32_GPIO_AF7
43
44#endif
45
rev13@wp.plfec465a2015-03-01 12:44:40 +010046enum stm32_gpio_port {
47 STM32_GPIO_PORT_A = 0,
48 STM32_GPIO_PORT_B,
49 STM32_GPIO_PORT_C,
50 STM32_GPIO_PORT_D,
51 STM32_GPIO_PORT_E,
52 STM32_GPIO_PORT_F,
53 STM32_GPIO_PORT_G,
54 STM32_GPIO_PORT_H,
55 STM32_GPIO_PORT_I
56};
57
58enum stm32_gpio_pin {
59 STM32_GPIO_PIN_0 = 0,
60 STM32_GPIO_PIN_1,
61 STM32_GPIO_PIN_2,
62 STM32_GPIO_PIN_3,
63 STM32_GPIO_PIN_4,
64 STM32_GPIO_PIN_5,
65 STM32_GPIO_PIN_6,
66 STM32_GPIO_PIN_7,
67 STM32_GPIO_PIN_8,
68 STM32_GPIO_PIN_9,
69 STM32_GPIO_PIN_10,
70 STM32_GPIO_PIN_11,
71 STM32_GPIO_PIN_12,
72 STM32_GPIO_PIN_13,
73 STM32_GPIO_PIN_14,
74 STM32_GPIO_PIN_15
75};
76
77enum stm32_gpio_mode {
78 STM32_GPIO_MODE_IN = 0,
79 STM32_GPIO_MODE_OUT,
80 STM32_GPIO_MODE_AF,
81 STM32_GPIO_MODE_AN
82};
83
84enum stm32_gpio_otype {
85 STM32_GPIO_OTYPE_PP = 0,
86 STM32_GPIO_OTYPE_OD
87};
88
89enum stm32_gpio_speed {
90 STM32_GPIO_SPEED_2M = 0,
91 STM32_GPIO_SPEED_25M,
92 STM32_GPIO_SPEED_50M,
93 STM32_GPIO_SPEED_100M
94};
95
96enum stm32_gpio_pupd {
97 STM32_GPIO_PUPD_NO = 0,
98 STM32_GPIO_PUPD_UP,
99 STM32_GPIO_PUPD_DOWN
100};
101
102enum stm32_gpio_af {
103 STM32_GPIO_AF0 = 0,
104 STM32_GPIO_AF1,
105 STM32_GPIO_AF2,
106 STM32_GPIO_AF3,
107 STM32_GPIO_AF4,
108 STM32_GPIO_AF5,
109 STM32_GPIO_AF6,
110 STM32_GPIO_AF7,
111 STM32_GPIO_AF8,
112 STM32_GPIO_AF9,
113 STM32_GPIO_AF10,
114 STM32_GPIO_AF11,
115 STM32_GPIO_AF12,
116 STM32_GPIO_AF13,
117 STM32_GPIO_AF14,
118 STM32_GPIO_AF15
119};
120
121struct stm32_gpio_dsc {
122 enum stm32_gpio_port port;
123 enum stm32_gpio_pin pin;
124};
125
126struct stm32_gpio_ctl {
127 enum stm32_gpio_mode mode;
128 enum stm32_gpio_otype otype;
129 enum stm32_gpio_speed speed;
130 enum stm32_gpio_pupd pupd;
131 enum stm32_gpio_af af;
132};
133
Patrice Chotard1a4b8de2017-12-12 09:49:40 +0100134struct stm32_gpio_regs {
135 u32 moder; /* GPIO port mode */
136 u32 otyper; /* GPIO port output type */
137 u32 ospeedr; /* GPIO port output speed */
138 u32 pupdr; /* GPIO port pull-up/pull-down */
139 u32 idr; /* GPIO port input data */
140 u32 odr; /* GPIO port output data */
141 u32 bsrr; /* GPIO port bit set/reset */
142 u32 lckr; /* GPIO port configuration lock */
143 u32 afr[2]; /* GPIO alternate function */
144};
145
146struct stm32_gpio_priv {
147 struct stm32_gpio_regs *regs;
148};
149
rev13@wp.plfec465a2015-03-01 12:44:40 +0100150static inline unsigned stm32_gpio_to_port(unsigned gpio)
151{
152 return gpio / 16;
153}
154
155static inline unsigned stm32_gpio_to_pin(unsigned gpio)
156{
157 return gpio % 16;
158}
159
rev13@wp.plfec465a2015-03-01 12:44:40 +0100160#endif /* _STM32_GPIO_H_ */