18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) Maxime Coquelin 2015
48c2ecf20Sopenharmony_ci * Copyright (C) STMicroelectronics 2017
58c2ecf20Sopenharmony_ci * Author:  Maxime Coquelin <mcoquelin.stm32@gmail.com>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#ifndef __PINCTRL_STM32_H
88c2ecf20Sopenharmony_ci#define __PINCTRL_STM32_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/pinctrl/pinctrl.h>
118c2ecf20Sopenharmony_ci#include <linux/pinctrl/pinconf-generic.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define STM32_PIN_NO(x) ((x) << 8)
148c2ecf20Sopenharmony_ci#define STM32_GET_PIN_NO(x) ((x) >> 8)
158c2ecf20Sopenharmony_ci#define STM32_GET_PIN_FUNC(x) ((x) & 0xff)
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define STM32_PIN_GPIO		0
188c2ecf20Sopenharmony_ci#define STM32_PIN_AF(x)		((x) + 1)
198c2ecf20Sopenharmony_ci#define STM32_PIN_ANALOG	(STM32_PIN_AF(15) + 1)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/*  package information */
228c2ecf20Sopenharmony_ci#define STM32MP_PKG_AA		BIT(0)
238c2ecf20Sopenharmony_ci#define STM32MP_PKG_AB		BIT(1)
248c2ecf20Sopenharmony_ci#define STM32MP_PKG_AC		BIT(2)
258c2ecf20Sopenharmony_ci#define STM32MP_PKG_AD		BIT(3)
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistruct stm32_desc_function {
288c2ecf20Sopenharmony_ci	const char *name;
298c2ecf20Sopenharmony_ci	const unsigned char num;
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct stm32_desc_pin {
338c2ecf20Sopenharmony_ci	struct pinctrl_pin_desc pin;
348c2ecf20Sopenharmony_ci	const struct stm32_desc_function *functions;
358c2ecf20Sopenharmony_ci	const unsigned int pkg;
368c2ecf20Sopenharmony_ci};
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define STM32_PIN(_pin, ...)					\
398c2ecf20Sopenharmony_ci	{							\
408c2ecf20Sopenharmony_ci		.pin = _pin,					\
418c2ecf20Sopenharmony_ci		.functions = (struct stm32_desc_function[]){	\
428c2ecf20Sopenharmony_ci			__VA_ARGS__, { } },			\
438c2ecf20Sopenharmony_ci	}
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define STM32_PIN_PKG(_pin, _pkg, ...)					\
468c2ecf20Sopenharmony_ci	{							\
478c2ecf20Sopenharmony_ci		.pin = _pin,					\
488c2ecf20Sopenharmony_ci		.pkg  = _pkg,				\
498c2ecf20Sopenharmony_ci		.functions = (struct stm32_desc_function[]){	\
508c2ecf20Sopenharmony_ci			__VA_ARGS__, { } },			\
518c2ecf20Sopenharmony_ci	}
528c2ecf20Sopenharmony_ci#define STM32_FUNCTION(_num, _name)		\
538c2ecf20Sopenharmony_ci	{							\
548c2ecf20Sopenharmony_ci		.num = _num,					\
558c2ecf20Sopenharmony_ci		.name = _name,					\
568c2ecf20Sopenharmony_ci	}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistruct stm32_pinctrl_match_data {
598c2ecf20Sopenharmony_ci	const struct stm32_desc_pin *pins;
608c2ecf20Sopenharmony_ci	const unsigned int npins;
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistruct stm32_gpio_bank;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciint stm32_pctl_probe(struct platform_device *pdev);
668c2ecf20Sopenharmony_civoid stm32_pmx_get_mode(struct stm32_gpio_bank *bank,
678c2ecf20Sopenharmony_ci			int pin, u32 *mode, u32 *alt);
688c2ecf20Sopenharmony_ciint stm32_pinctrl_resume(struct device *dev);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#endif /* __PINCTRL_STM32_H */
718c2ecf20Sopenharmony_ci
72