1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) Maxime Coquelin 2015
4  * Copyright (C) STMicroelectronics 2017
5  * Author:  Maxime Coquelin <mcoquelin.stm32@gmail.com>
6  */
7 #ifndef __PINCTRL_STM32_H
8 #define __PINCTRL_STM32_H
9 
10 #include <linux/pinctrl/pinctrl.h>
11 #include <linux/pinctrl/pinconf-generic.h>
12 
13 #define STM32_PIN_NO(x) ((x) << 8)
14 #define STM32_GET_PIN_NO(x) ((x) >> 8)
15 #define STM32_GET_PIN_FUNC(x) ((x) & 0xff)
16 
17 #define STM32_PIN_GPIO		0
18 #define STM32_PIN_AF(x)		((x) + 1)
19 #define STM32_PIN_ANALOG	(STM32_PIN_AF(15) + 1)
20 #define STM32_CONFIG_NUM	(STM32_PIN_ANALOG + 1)
21 
22 /*  package information */
23 #define STM32MP_PKG_AA		BIT(0)
24 #define STM32MP_PKG_AB		BIT(1)
25 #define STM32MP_PKG_AC		BIT(2)
26 #define STM32MP_PKG_AD		BIT(3)
27 #define STM32MP_PKG_AI		BIT(8)
28 #define STM32MP_PKG_AK		BIT(10)
29 #define STM32MP_PKG_AL		BIT(11)
30 
31 struct stm32_desc_function {
32 	const char *name;
33 	const unsigned char num;
34 };
35 
36 struct stm32_desc_pin {
37 	struct pinctrl_pin_desc pin;
38 	const struct stm32_desc_function functions[STM32_CONFIG_NUM];
39 	const unsigned int pkg;
40 };
41 
42 #define STM32_PIN(_pin, ...)					\
43 	{							\
44 		.pin = _pin,					\
45 		.functions = {	\
46 			__VA_ARGS__},			\
47 	}
48 
49 #define STM32_PIN_PKG(_pin, _pkg, ...)					\
50 	{							\
51 		.pin = _pin,					\
52 		.pkg  = _pkg,				\
53 		.functions = {	\
54 			__VA_ARGS__},			\
55 	}
56 #define STM32_FUNCTION(_num, _name)		\
57 	[_num] = {						\
58 		.num = _num,					\
59 		.name = _name,					\
60 	}
61 
62 struct stm32_pinctrl_match_data {
63 	const struct stm32_desc_pin *pins;
64 	const unsigned int npins;
65 	bool secure_control;
66 };
67 
68 struct stm32_gpio_bank;
69 
70 int stm32_pctl_probe(struct platform_device *pdev);
71 void stm32_pmx_get_mode(struct stm32_gpio_bank *bank,
72 			int pin, u32 *mode, u32 *alt);
73 int stm32_pinctrl_suspend(struct device *dev);
74 int stm32_pinctrl_resume(struct device *dev);
75 
76 #endif /* __PINCTRL_STM32_H */
77 
78